PageRenderTime 45ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/plugins/blogroll/index.php

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