Dotclear

source: plugins/myHandlers/index.php @ 443

Revision 443, 3.2 KB checked in by sacha, 16 years ago (diff)

Moving myHandlers to myUrlHandlers (first step)

Line 
1<?php /* -*- tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */
2/***************************************************************\
3 *  This is 'My URL handlers', a plugin for Dotclear 2         *
4 *                                                             *
5 *  Copyright (c) 2007-2008                                    *
6 *  Oleksandr Syenchuk and contributors.                       *
7 *                                                             *
8 *  This is an open source software, distributed under the GNU *
9 *  General Public License (version 2) terms and  conditions.  *
10 *                                                             *
11 *  You should have received a copy of the GNU General Public  *
12 *  License along with 'My URL handlers' (see COPYING.txt);    *
13 *  if not, write to the Free Software Foundation, Inc.,       *
14 *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA    *
15\***************************************************************/
16
17try
18{
19     $handlers = myUrlHandlers::getDefaults();
20     
21     if (($settings = @unserialize($core->blog->settings->url_handlers))
22     && is_array($settings)) {
23          foreach ($settings as $name=>$url)
24          {
25               if (isset($handlers[$name])) {
26                    $handlers[$name] = $url;
27               }
28          }
29     }
30     
31     
32     if (!empty($_POST['handlers']) && is_array($_POST['handlers'])) {
33          foreach ($_POST['handlers'] as $name=>$url)
34          {
35               $url = strtolower(text::str2url($url,false));
36               
37               if (empty($handlers[$name])) {
38                    throw new Exception(sprintf(
39                    __('"%s" URL handler does not exist.'),html::escapeHTML($name)));
40               }
41               
42               if (empty($url)) {
43                    throw new Exception(sprintf(
44                    __('Invalid URL for handler "%s".'),html::escapeHTML($name)));
45               }
46               
47               $handlers[$name] = $url;
48          }
49         
50          if ($keys = array_keys(array_diff_key($handlers,array_unique($handlers)))) {
51               throw new Exception(sprintf(count($keys) > 1
52                    ? __('Duplicate URL in handlers "%s".')
53                    : __('Duplicate URL in handler "%s".'),implode('", "',$keys)));
54          }
55     }
56     
57     
58     if (isset($_POST['act_save'])) {
59          $core->blog->settings->setNamespace('myurlhandlers');
60          $core->blog->settings->put('url_handlers',serialize($handlers));
61          $core->blog->triggerBlog();
62          $msg = __('URL handlers have been succefully updated.');
63     }
64}
65catch (Exception $e)
66{
67     $core->error->add($e->getMessage());
68}
69
70/* DISPLAY
71--------------------------------------------------- */
72
73echo '
74<html><head>
75<title>'.__('URL handlers').'</title>'.
76dcPage::jsToolMan().'
77</head><body>
78<h2>'.html::escapeHTML($core->blog->name).' &gt; '.
79     __('Personalize default URL handlers').'</h2>';
80
81if (!empty($msg)) {
82     echo '<p class="message">'.html::escapeHTML($msg).'</p>';
83}
84
85?>
86
87<?php if (empty($handlers)): ?>
88<p class="message"><?php echo __('No URL handlers to define.'); ?></p>
89<?php else: ?>
90<p><?php echo __('You can write your own URL for each handler in this list.'); ?></p>
91<form action="<?php echo $p_url; ?>" method="post">
92<table>
93  <thead>
94    <tr><th>Type</th><th>URL</th></tr>
95  </thead>
96  <tbody>
97<?php
98foreach ($handlers as $name=>$url)
99{
100     echo '    <tr><td>'.$name.'</td><td>'.
101          form::field(array('handlers['.$name.']'),20,255,$url).'</td></tr>';
102}
103?>
104  </tbody>
105</table>
106<p><input type="submit" name="act_save" value="<?php echo __('save'); ?>" />
107  <?php echo $core->formNonce(); ?></p>
108</form>
109<?php endif; ?>
110</body></html>
Note: See TracBrowser for help on using the repository browser.

Sites map