Dotclear

source: plugins/blogroll/index.php @ 3707:3a350757c847

Revision 3707:3a350757c847, 11.6 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

Use array form of optionnal parameters for form::checkbox() where is relevant, code formatting (PSR-2)

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
14$blogroll = new dcBlogroll($core->blog);
15
16if (!empty($_REQUEST['edit']) && !empty($_REQUEST['id'])) {
17    include dirname(__FILE__) . '/edit.php';
18    return;
19}
20
21$default_tab = '';
22$link_title  = $link_href  = $link_desc  = $link_lang  = '';
23$cat_title   = '';
24
25# Import links
26if (!empty($_POST['import_links']) && !empty($_FILES['links_file'])) {
27    $default_tab = 'import-links';
28
29    try
30    {
31        files::uploadStatus($_FILES['links_file']);
32        $ifile = DC_TPL_CACHE . '/' . md5(uniqid());
33        if (!move_uploaded_file($_FILES['links_file']['tmp_name'], $ifile)) {
34            throw new Exception(__('Unable to move uploaded file.'));
35        }
36
37        require_once dirname(__FILE__) . '/class.dc.importblogroll.php';
38        try {
39            $imported = dcImportBlogroll::loadFile($ifile);
40            @unlink($ifile);
41        } catch (Exception $e) {
42            @unlink($ifile);
43            throw $e;
44        }
45
46        if (empty($imported)) {
47            unset($imported);
48            throw new Exception(__('Nothing to import'));
49        }
50    } catch (Exception $e) {
51        $core->error->add($e->getMessage());
52    }
53}
54
55if (!empty($_POST['import_links_do'])) {
56    foreach ($_POST['entries'] as $idx) {
57        $link_title = html::escapeHTML($_POST['title'][$idx]);
58        $link_href  = html::escapeHTML($_POST['url'][$idx]);
59        $link_desc  = html::escapeHTML($_POST['desc'][$idx]);
60        try {
61            $blogroll->addLink($link_title, $link_href, $link_desc, '');
62        } catch (Exception $e) {
63            $core->error->add($e->getMessage());
64            $default_tab = 'import-links';
65        }
66    }
67
68    dcPage::addSuccessNotice(__('links have been successfully imported.'));
69    http::redirect($p_url);
70}
71
72if (!empty($_POST['cancel_import'])) {
73    $core->error->add(__('Import operation cancelled.'));
74    $default_tab = 'import-links';
75}
76
77# Add link
78if (!empty($_POST['add_link'])) {
79    $link_title = html::escapeHTML($_POST['link_title']);
80    $link_href  = html::escapeHTML($_POST['link_href']);
81    $link_desc  = html::escapeHTML($_POST['link_desc']);
82    $link_lang  = html::escapeHTML($_POST['link_lang']);
83
84    try {
85        $blogroll->addLink($link_title, $link_href, $link_desc, $link_lang);
86
87        dcPage::addSuccessNotice(__('Link has been successfully created.'));
88        http::redirect($p_url);
89    } catch (Exception $e) {
90        $core->error->add($e->getMessage());
91        $default_tab = 'add-link';
92    }
93}
94
95# Add category
96if (!empty($_POST['add_cat'])) {
97    $cat_title = html::escapeHTML($_POST['cat_title']);
98
99    try {
100        $blogroll->addCategory($cat_title);
101        dcPage::addSuccessNotice(__('category has been successfully created.'));
102        http::redirect($p_url);
103    } catch (Exception $e) {
104        $core->error->add($e->getMessage());
105        $default_tab = 'add-cat';
106    }
107}
108
109# Delete link
110if (!empty($_POST['removeaction']) && !empty($_POST['remove'])) {
111    foreach ($_POST['remove'] as $k => $v) {
112        try {
113            $blogroll->delItem($v);
114        } catch (Exception $e) {
115            $core->error->add($e->getMessage());
116            break;
117        }
118    }
119
120    if (!$core->error->flag()) {
121        dcPage::addSuccessNotice(__('Items have been successfully removed.'));
122        http::redirect($p_url);
123    }
124}
125
126# Order links
127$order = array();
128if (empty($_POST['links_order']) && !empty($_POST['order'])) {
129    $order = $_POST['order'];
130    asort($order);
131    $order = array_keys($order);
132} elseif (!empty($_POST['links_order'])) {
133    $order = explode(',', $_POST['links_order']);
134}
135
136if (!empty($_POST['saveorder']) && !empty($order)) {
137    foreach ($order as $pos => $l) {
138        $pos = ((integer) $pos) + 1;
139
140        try {
141            $blogroll->updateOrder($l, $pos);
142        } catch (Exception $e) {
143            $core->error->add($e->getMessage());
144        }
145    }
146
147    if (!$core->error->flag()) {
148        dcPage::addSuccessNotice(__('Items order has been successfully updated'));
149        http::redirect($p_url);
150    }
151}
152
153# Get links
154try {
155    $rs = $blogroll->getLinks();
156} catch (Exception $e) {
157    $core->error->add($e->getMessage());
158}
159
160?>
161<html>
162<head>
163  <title><?php echo __('Blogroll'); ?></title>
164  <?php echo dcPage::jsConfirmClose('links-form', 'add-link-form', 'add-category-form'); ?>
165  <?php
166$core->auth->user_prefs->addWorkspace('accessibility');
167if (!$core->auth->user_prefs->accessibility->nodragdrop) {
168    echo
169    dcPage::jsLoad('js/jquery/jquery-ui.custom.js') .
170    dcPage::jsLoad('js/jquery/jquery.ui.touch-punch.js') .
171    dcPage::jsLoad(dcPage::getPF('blogroll/blogroll.js'));
172}
173?>
174  <?php echo dcPage::jsPageTabs($default_tab); ?>
175</head>
176
177<body>
178<?php
179echo dcPage::breadcrumb(
180    array(
181        html::escapeHTML($core->blog->name) => '',
182        __('Blogroll')                      => ''
183    )) .
184dcPage::notices();
185?>
186
187<div class="multi-part" id="main-list" title="<?php echo __('Blogroll'); ?>">
188
189<?php if (!$rs->isEmpty()) {
190    ?>
191
192<form action="<?php echo $core->adminurl->get('admin.plugin'); ?>" method="post" id="links-form">
193<div class="table-outer">
194<table class="dragable">
195<thead>
196<tr>
197  <th colspan="3"><?php echo __('Title'); ?></th>
198  <th><?php echo __('Description'); ?></th>
199  <th><?php echo __('URL'); ?></th>
200  <th><?php echo __('Lang'); ?></th>
201</tr>
202</thead>
203<tbody id="links-list">
204<?php
205while ($rs->fetch()) {
206        $position = (string) $rs->index() + 1;
207
208        echo
209        '<tr class="line" id="l_' . $rs->link_id . '">' .
210        '<td class="handle minimal">' . form::field(array('order[' . $rs->link_id . ']'), 2, 5, $position, 'position', '', false, 'title="' . __('position') . '"') . '</td>' .
211        '<td class="minimal">' . form::checkbox(array('remove[]'), $rs->link_id,
212            array(
213                'extra_html' => 'title="' . __('select this link') . '"'
214            )
215        ) . '</td>';
216
217        if ($rs->is_cat) {
218            echo
219            '<td colspan="5"><strong><a href="' . $p_url . '&amp;edit=1&amp;id=' . $rs->link_id . '">' .
220            html::escapeHTML($rs->link_desc) . '</a></strong></td>';
221        } else {
222            echo
223            '<td><a href="' . $p_url . '&amp;edit=1&amp;id=' . $rs->link_id . '">' .
224            html::escapeHTML($rs->link_title) . '</a></td>' .
225            '<td>' . html::escapeHTML($rs->link_desc) . '</td>' .
226            '<td>' . html::escapeHTML($rs->link_href) . '</td>' .
227            '<td>' . html::escapeHTML($rs->link_lang) . '</td>';
228        }
229
230        echo '</tr>';
231    }
232    ?>
233</tbody>
234</table></div>
235
236<div class="two-cols">
237<p class="col">
238<?php
239echo
240    form::hidden('links_order', '') .
241    form::hidden(array('p'), 'blogroll') .
242    $core->formNonce();
243    ?>
244<input type="submit" name="saveorder" value="<?php echo __('Save order'); ?>" /></p>
245<p class="col right"><input id="remove-action" type="submit" class="delete" name="removeaction"
246     value="<?php echo __('Delete selected links'); ?>"
247     onclick="return window.confirm(<?php echo html::escapeJS(__('Are you sure you want to delete selected links?')); ?>');" /></p>
248</div>
249</form>
250
251<?php
252} else {
253    echo '<div><p>' . __('The link list is empty.') . '</p></div>';
254}
255?>
256
257</div>
258
259<?php
260echo
261'<div class="multi-part clear" id="add-link" title="' . __('Add a link') . '">' .
262'<form action="' . $core->adminurl->get('admin.plugin') . '" method="post" id="add-link-form">' .
263'<h3>' . __('Add a new link') . '</h3>' .
264'<p class="col"><label for="link_title" class="required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Title:') . '</label> ' .
265form::field('link_title', 30, 255, $link_title, '', '', false, 'required placeholder="' . __('Title') . '"') .
266'</p>' .
267
268'<p class="col"><label for="link_href" class="required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('URL:') . '</label> ' .
269form::field('link_href', 30, 255, $link_href, '', '', false, 'required placeholder="' . __('URL') . '"') .
270'</p>' .
271
272'<p class="col"><label for="link_desc">' . __('Description:') . '</label> ' .
273form::field('link_desc', 30, 255, $link_desc) .
274'</p>' .
275
276'<p class="col"><label for="link_lang">' . __('Language:') . '</label> ' .
277form::field('link_lang', 5, 5, $link_lang) .
278'</p>' .
279'<p>' . form::hidden(array('p'), 'blogroll') .
280$core->formNonce() .
281'<input type="submit" name="add_link" value="' . __('Save') . '" /></p>' .
282    '</form>' .
283    '</div>';
284
285echo
286'<div class="multi-part" id="add-cat" title="' . __('Add a category') . '">' .
287'<form action="' . $core->adminurl->get('admin.plugin') . '" method="post" id="add-category-form">' .
288'<h3>' . __('Add a new category') . '</h3>' .
289'<p><label for="cat_title" class=" classic required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Title:') . '</label> ' .
290form::field('cat_title', 30, 255, $cat_title, '', '', false, 'required placeholder="' . __('Title') . '"') . ' ' .
291form::hidden(array('p'), 'blogroll') .
292$core->formNonce() .
293'<input type="submit" name="add_cat" value="' . __('Save') . '" /></p>' .
294    '</form>' .
295    '</div>';
296
297echo
298'<div class="multi-part" id="import-links" title="' . __('Import links') . '">';
299if (!isset($imported)) {
300    echo
301    '<form action="' . $core->adminurl->get('admin.plugin') . '" method="post" id="import-links-form" enctype="multipart/form-data">' .
302    '<h3>' . __('Import links') . '</h3>' .
303    '<p><label for="links_file" class=" classic required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('OPML or XBEL File:') . '</label> ' .
304    '<input type="file" id="links_file" name="links_file" required /></p>' .
305    '<p>' . form::hidden(array('p'), 'blogroll') .
306    $core->formNonce() .
307    '<input type="submit" name="import_links" value="' . __('Import') . '" /></p>' .
308        '</form>';
309} else {
310    echo
311    '<form action="' . $core->adminurl->get('admin.plugin') . '" method="post" id="import-links-form">' .
312    '<h3>' . __('Import links') . '</h3>';
313    if (empty($imported)) {
314        echo '<p>' . __('Nothing to import') . '</p>';
315    } else {
316        echo
317        '<table class="clear maximal"><tr>' .
318        '<th colspan="2">' . __('Title') . '</th>' .
319        '<th>' . __('Description') . '</th>' .
320            '</tr>';
321
322        $i = 0;
323        foreach ($imported as $entry) {
324            $url   = html::escapeHTML($entry->link);
325            $title = html::escapeHTML($entry->title);
326            $desc  = html::escapeHTML($entry->desc);
327
328            echo
329            '<tr><td>' . form::checkbox(array('entries[]'), $i) . '</td>' .
330            '<td nowrap><a href="' . $url . '">' . $title . '</a>' .
331            '<input type="hidden" name="url[' . $i . ']" value="' . $url . '" />' .
332            '<input type="hidden" name="title[' . $i . ']" value="' . $title . '" />' .
333            '</td>' .
334            '<td>' . $desc .
335            '<input type="hidden" name="desc[' . $i . ']" value="' . $desc . '" />' .
336            '</td></tr>' . "\n";
337            $i++;
338        }
339        echo
340        '</table>' .
341        '<div class="two-cols">' .
342        '<p class="col checkboxes-helpers"></p>' .
343
344        '<p class="col right">' .
345        form::hidden(array('p'), 'blogroll') .
346        $core->formNonce() .
347        '<input type="submit" name="cancel_import" value="' . __('Cancel') . '" />&nbsp;' .
348        '<input type="submit" name="import_links_do" value="' . __('Import') . '" /></p>' .
349            '</div>';
350    }
351    echo
352        '</form>';
353}
354echo '</div>';
355
356dcPage::helpBlock('blogroll');
357?>
358
359</body>
360</html>
Note: See TracBrowser for help on using the repository browser.

Sites map