Dotclear

source: plugins/blogroll/index.php @ 3874:ab8368569446

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

short notation for array (array() → [])

Line 
1<?php
2/**
3 * @brief blogroll, a plugin for Dotclear 2
4 *
5 * @package Dotclear
6 * @subpackage Plugins
7 *
8 * @copyright Olivier Meunier & Association Dotclear
9 * @copyright GPL-2.0-only
10 */
11
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 = [];
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/js/blogroll.js'));
172}
173?>
174  <?php echo dcPage::jsPageTabs($default_tab); ?>
175</head>
176
177<body>
178<?php
179echo dcPage::breadcrumb(
180    [
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(['order[' . $rs->link_id . ']'], 2, 5, [
211            'default'    => $position,
212            'class'      => 'position',
213            'extra_html' => 'title="' . __('position') . '"'
214        ]) .
215        '</td>' .
216        '<td class="minimal">' . form::checkbox(['remove[]'], $rs->link_id,
217            [
218                'extra_html' => 'title="' . __('select this link') . '"'
219            ]
220        ) . '</td>';
221
222        if ($rs->is_cat) {
223            echo
224            '<td colspan="5"><strong><a href="' . $p_url . '&amp;edit=1&amp;id=' . $rs->link_id . '">' .
225            html::escapeHTML($rs->link_desc) . '</a></strong></td>';
226        } else {
227            echo
228            '<td><a href="' . $p_url . '&amp;edit=1&amp;id=' . $rs->link_id . '">' .
229            html::escapeHTML($rs->link_title) . '</a></td>' .
230            '<td>' . html::escapeHTML($rs->link_desc) . '</td>' .
231            '<td>' . html::escapeHTML($rs->link_href) . '</td>' .
232            '<td>' . html::escapeHTML($rs->link_lang) . '</td>';
233        }
234
235        echo '</tr>';
236    }
237    ?>
238</tbody>
239</table></div>
240
241<div class="two-cols">
242<p class="col">
243<?php
244echo
245    form::hidden('links_order', '') .
246    form::hidden(['p'], 'blogroll') .
247    $core->formNonce();
248    ?>
249<input type="submit" name="saveorder" value="<?php echo __('Save order'); ?>" /></p>
250<p class="col right"><input id="remove-action" type="submit" class="delete" name="removeaction"
251     value="<?php echo __('Delete selected links'); ?>"
252     onclick="return window.confirm(<?php echo html::escapeJS(__('Are you sure you want to delete selected links?')); ?>');" /></p>
253</div>
254</form>
255
256<?php
257} else {
258    echo '<div><p>' . __('The link list is empty.') . '</p></div>';
259}
260?>
261
262</div>
263
264<?php
265echo
266'<div class="multi-part clear" id="add-link" title="' . __('Add a link') . '">' .
267'<form action="' . $core->adminurl->get('admin.plugin') . '" method="post" id="add-link-form">' .
268'<h3>' . __('Add a new link') . '</h3>' .
269'<p class="col"><label for="link_title" class="required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Title:') . '</label> ' .
270form::field('link_title', 30, 255, [
271    'default'    => $link_title,
272    'extra_html' => 'required placeholder="' . __('Title') . '"'
273]) .
274'</p>' .
275
276'<p class="col"><label for="link_href" class="required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('URL:') . '</label> ' .
277form::field('link_href', 30, 255, [
278    'default'    => $link_href,
279    'extra_html' => 'required placeholder="' . __('URL') . '"'
280]) .
281'</p>' .
282
283'<p class="col"><label for="link_desc">' . __('Description:') . '</label> ' .
284form::field('link_desc', 30, 255, $link_desc) .
285'</p>' .
286
287'<p class="col"><label for="link_lang">' . __('Language:') . '</label> ' .
288form::field('link_lang', 5, 5, $link_lang) .
289'</p>' .
290'<p>' . form::hidden(['p'], 'blogroll') .
291$core->formNonce() .
292'<input type="submit" name="add_link" value="' . __('Save') . '" /></p>' .
293    '</form>' .
294    '</div>';
295
296echo
297'<div class="multi-part" id="add-cat" title="' . __('Add a category') . '">' .
298'<form action="' . $core->adminurl->get('admin.plugin') . '" method="post" id="add-category-form">' .
299'<h3>' . __('Add a new category') . '</h3>' .
300'<p><label for="cat_title" class=" classic required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('Title:') . '</label> ' .
301form::field('cat_title', 30, 255, [
302    'default'    => $cat_title,
303    'extra_html' => 'required placeholder="' . __('Title') . '"'
304]) .
305' ' .
306form::hidden(['p'], 'blogroll') .
307$core->formNonce() .
308'<input type="submit" name="add_cat" value="' . __('Save') . '" /></p>' .
309    '</form>' .
310    '</div>';
311
312echo
313'<div class="multi-part" id="import-links" title="' . __('Import links') . '">';
314if (!isset($imported)) {
315    echo
316    '<form action="' . $core->adminurl->get('admin.plugin') . '" method="post" id="import-links-form" enctype="multipart/form-data">' .
317    '<h3>' . __('Import links') . '</h3>' .
318    '<p><label for="links_file" class=" classic required"><abbr title="' . __('Required field') . '">*</abbr> ' . __('OPML or XBEL File:') . '</label> ' .
319    '<input type="file" id="links_file" name="links_file" required /></p>' .
320    '<p>' . form::hidden(['p'], 'blogroll') .
321    $core->formNonce() .
322    '<input type="submit" name="import_links" value="' . __('Import') . '" /></p>' .
323        '</form>';
324} else {
325    echo
326    '<form action="' . $core->adminurl->get('admin.plugin') . '" method="post" id="import-links-form">' .
327    '<h3>' . __('Import links') . '</h3>';
328    if (empty($imported)) {
329        echo '<p>' . __('Nothing to import') . '</p>';
330    } else {
331        echo
332        '<table class="clear maximal"><tr>' .
333        '<th colspan="2">' . __('Title') . '</th>' .
334        '<th>' . __('Description') . '</th>' .
335            '</tr>';
336
337        $i = 0;
338        foreach ($imported as $entry) {
339            $url   = html::escapeHTML($entry->link);
340            $title = html::escapeHTML($entry->title);
341            $desc  = html::escapeHTML($entry->desc);
342
343            echo
344            '<tr><td>' . form::checkbox(['entries[]'], $i) . '</td>' .
345                '<td nowrap><a href="' . $url . '">' . $title . '</a>' .
346                '<input type="hidden" name="url[' . $i . ']" value="' . $url . '" />' .
347                '<input type="hidden" name="title[' . $i . ']" value="' . $title . '" />' .
348                '</td>' .
349                '<td>' . $desc .
350                '<input type="hidden" name="desc[' . $i . ']" value="' . $desc . '" />' .
351                '</td></tr>' . "\n";
352            $i++;
353        }
354        echo
355        '</table>' .
356        '<div class="two-cols">' .
357        '<p class="col checkboxes-helpers"></p>' .
358
359        '<p class="col right">' .
360        form::hidden(['p'], 'blogroll') .
361        $core->formNonce() .
362        '<input type="submit" name="cancel_import" value="' . __('Cancel') . '" />&nbsp;' .
363        '<input type="submit" name="import_links_do" value="' . __('Import') . '" /></p>' .
364            '</div>';
365    }
366    echo
367        '</form>';
368}
369echo '</div>';
370
371dcPage::helpBlock('blogroll');
372?>
373
374</body>
375</html>
Note: See TracBrowser for help on using the repository browser.

Sites map