Dotclear

source: plugins/pings/index.php @ 3159:a7553434ee4c

Revision 3159:a7553434ee4c, 3.0 KB checked in by franck <carnet.franck.paul@…>, 9 years ago (diff)

Use new setting type 'array' for some settings, addresses #1833

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ---------------------------------------
3#
4# This file is part of Dotclear 2.
5#
6# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear
7# Licensed under the GPL version 2.0 license.
8# See LICENSE file or
9# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10#
11# -- END LICENSE BLOCK -----------------------------------------
12if (!defined('DC_CONTEXT_ADMIN')) { return; }
13
14dcPage::checkSuper();
15
16try
17{
18     $pings_uris = $core->blog->settings->pings->pings_uris;
19     if (!$pings_uris) {
20          $pings_uris = array();
21     }
22
23     if (isset($_POST['pings_srv_name']))
24     {
25          $pings_srv_name = is_array($_POST['pings_srv_name']) ? $_POST['pings_srv_name'] : array();
26          $pings_srv_uri = is_array($_POST['pings_srv_uri']) ? $_POST['pings_srv_uri'] : array();
27          $pings_uris = array();
28
29          foreach ($pings_srv_name as $k => $v) {
30               if (trim($v) && trim($pings_srv_uri[$k])) {
31                    $pings_uris[trim($v)] = trim($pings_srv_uri[$k]);
32               }
33          }
34
35          $core->blog->settings->addNamespace('pings');
36          $core->blog->settings->pings->put('pings_active',!empty($_POST['pings_active']),null,null,true,true);
37          $core->blog->settings->pings->put('pings_uris',$pings_uris,null,null,true,true);
38          dcPage::addSuccessNotice(__('Settings have been successfully updated.'));
39          http::redirect($p_url);
40     }
41}
42catch (Exception $e)
43{
44     $core->error->add($e->getMessage());
45}
46?>
47<html>
48<head>
49  <title><?php echo __('Pings'); ?></title>
50</head>
51
52<body>
53<?php
54
55echo dcPage::breadcrumb(
56     array(
57          __('Plugins') => '',
58          __('Pings configuration') => ''
59     ));
60
61echo
62'<form action="'.$p_url.'" method="post">'.
63'<p><label for="pings_active" class="classic">'.form::checkbox('pings_active',1,$core->blog->settings->pings->pings_active).
64__('Activate pings extension').'</label></p>';
65
66$i = 0;
67foreach ($pings_uris as $n => $u)
68{
69     echo
70     '<p><label for="pings_srv_name-'.$i.'" class="classic">'.__('Service name:').'</label> '.
71     form::field(array('pings_srv_name[]','pings_srv_name-'.$i),20,128,html::escapeHTML($n)).' '.
72     '<label for="pings_srv_uri-'.$i.'" class="classic">'.__('Service URI:').'</label> '.
73     form::field(array('pings_srv_uri[]','pings_srv_uri-'.$i),40,255,html::escapeHTML($u));
74
75     if (!empty($_GET['test']))
76     {
77          try {
78               pingsAPI::doPings($u,'Example site','http://example.com');
79               echo ' <img src="images/check-on.png" alt="OK" />';
80          } catch (Exception $e) {
81               echo ' <img src="images/check-off.png" alt="'.__('Error').'" /> '.$e->getMessage();
82          }
83     }
84
85     echo '</p>';
86     $i++;
87}
88
89echo
90'<p><label for="pings_srv_name2" class="classic">'.__('Service name:').'</label> '.
91form::field(array('pings_srv_name[]','pings_srv_name2'),20,128).' '.
92'<label for="pings_srv_uri2" class="classic">'.__('Service URI:').'</label> '.
93form::field(array('pings_srv_uri[]','pings_srv_uri2'),40,255).
94'</p>'.
95
96'<p><input type="submit" value="'.__('Save').'" />'.
97$core->formNonce().'</p>'.
98'</form>';
99
100echo '<p><a class="button" href="'.$p_url.'&amp;test=1">'.__('Test ping services').'</a></p>';
101?>
102
103<?php dcPage::helpBlock('pings'); ?>
104
105</body>
106</html>
Note: See TracBrowser for help on using the repository browser.

Sites map