Dotclear

source: plugins/blogroll/index.php @ 2256:d3c3fa1723ab

Revision 2256:d3c3fa1723ab, 9.7 KB checked in by Dsls, 12 years ago (diff)

updated most of notices to new format, should fix #1710 (maintenance and daInstaller still to be updated)

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

Sites map