index.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <?php
  2. # ***** BEGIN LICENSE BLOCK *****
  3. # This file is part of DotClear.
  4. # Copyright (c) 2004 Olivier Meunier and contributors. All rights
  5. # reserved.
  6. #
  7. # DotClear is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # DotClear is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with DotClear; if not, write to the Free Software
  19. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. #
  21. # ***** END LICENSE BLOCK *****
  22. /* Small note on design:
  23. *
  24. * Both links and categories are stored in the same database table.
  25. * The difference is that 'label' and 'href' fields are empty for categories.
  26. *
  27. * This is quite hacky but perfectly fits a simple two level design.
  28. *
  29. */
  30. require dirname(__FILE__).'/class.blogroll.php';
  31. $url = 'tools.php?p=blogroll';
  32. $icon = 'tools/blogroll/icon_small.png';
  33. $PLUGIN_HEAD =
  34. '<style type="text/css">'."\n".
  35. '.sort img.status {float: right; margin: 2px 0 0 4px; position: relative;}'."\n".
  36. '</style>'."\n".
  37. '<script type="text/javascript" src="js/drag.js"></script>'.
  38. '<script type="text/javascript" src="js/dragsort.js"></script>'.
  39. '<script type="text/javascript">'."\n".
  40. ' if (document.getElementById) { '."\n".
  41. ' window.onload = function() { '."\n".
  42. ' dragSort.dest = document.getElementById(\'dndSort\');'."\n".
  43. ' dragSort.makeElementSortable(document.getElementById(\'sortlinks\'));'."\n".
  44. ' };'."\n".
  45. ' }'."\n".
  46. '</script>';
  47. $blogroll = new blogroll($blog,DB_PREFIX);
  48. $action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : NULL;
  49. $page = !empty($_REQUEST['page']) ? $_REQUEST['page'] : NULL;
  50. $err = '';
  51. if ($page == 'edit_link' && !empty($_REQUEST['id']))
  52. {
  53. include dirname(__FILE__).'/edit_link.php';
  54. }
  55. elseif ($page == 'edit_cat' && !empty($_REQUEST['id']))
  56. {
  57. include dirname(__FILE__).'/edit_cat.php';
  58. }
  59. else
  60. {
  61. $l_label = $l_title = $l_href = $l_lang = '';
  62. $c_title = '';
  63. # Ajout d'un lien
  64. if ($action == 'add_link')
  65. {
  66. $l_label = trim($_POST['l_label']);
  67. $l_title = trim($_POST['l_title']);
  68. $l_href = trim($_POST['l_href']);
  69. $l_lang = trim($_POST['l_lang']);
  70. if (!$l_label || !$l_href)
  71. {
  72. $err = __('You must provide at least a label and an URL');
  73. }
  74. else
  75. {
  76. if ($blogroll->addLink($l_label,$l_href,$l_title,$l_lang) == false) {
  77. $err = $blogroll->con->error();
  78. } else {
  79. header('Location: '.$url);
  80. exit;
  81. }
  82. }
  83. }
  84. # Ajout d'un catégorie
  85. elseif ($action == 'add_cat')
  86. {
  87. $c_title = trim($_POST['c_title']);
  88. if ($c_title)
  89. {
  90. if ($blogroll->addCat($c_title) == false) {
  91. $err = $blogroll->con->error();
  92. } else {
  93. header('Location: '.$url);
  94. exit;
  95. }
  96. }
  97. }
  98. # Suppression
  99. elseif ($action == 'delete' && !empty($_GET['id']))
  100. {
  101. if ($blogroll->delEntry($_GET['id']) == false) {
  102. $err = $blogroll->con->error();
  103. } else {
  104. header('Location: '.$url);
  105. exit;
  106. }
  107. }
  108. # Classic ord
  109. if (isset($_POST['linkOrd']) && is_array($_POST['linkOrd']))
  110. {
  111. if ($blogroll->ordEntries($_POST['linkOrd']) === false) {
  112. $err = $blogroll->con->error();
  113. } else {
  114. header('Location: '.$url);
  115. exit;
  116. }
  117. }
  118. # DragNdrop
  119. if (!empty($_POST['dndSort']))
  120. {
  121. $linkOrd = array();
  122. foreach (explode(';',$_POST['dndSort']) as $k => $v) {
  123. $linkOrd[substr($v,3)] = $k;
  124. }
  125. if ($blogroll->ordEntries($linkOrd) === false) {
  126. $err = $blogroll->con->error();
  127. } else {
  128. header('Location: '.$url);
  129. exit;
  130. }
  131. }
  132. # Affichage ---
  133. buffer::str('<h2>'.__('Links manager').'</h2>');
  134. if ($err != '') {
  135. buffer::str(
  136. '<div class="erreur"><p><strong>'.__('Error(s)').' :</strong></p>'.
  137. '<p>'.$err.'</p>'.
  138. '</div>'
  139. );
  140. }
  141. $strReq = 'SELECT link_id, label, href, title, lang, position '.
  142. 'FROM '.$blogroll->table.' '.
  143. 'ORDER BY position ';
  144. $rs = $con->select($strReq);
  145. buffer::str(
  146. '<p>'.__('Drag items to change their positions.').'</p>'.
  147. '<form action="'.$url.'" method="post">'.
  148. '<div id="sortlinks">'
  149. );
  150. while ($rs->fetch())
  151. {
  152. $link_id = $rs->f('link_id');
  153. $link_ord = $rs->f('position');
  154. $is_cat = !$rs->f('label') && !$rs->f('href');
  155. $i_label = ($is_cat) ? $rs->f('title') : $rs->f('label');
  156. if ($is_cat) {
  157. $del_msg = __('Are you sure you want to delete this category?');
  158. } else {
  159. $del_msg = sprintf(__('Are you sure you want to delete this %s?'),__('link'));
  160. }
  161. buffer::str('<div class="sort" id="dnd'.$link_id.'">');
  162. buffer::str(
  163. '<p>'.($is_cat ? '<strong>' : '').
  164. '<a href="'.$url.'&amp;action=delete&amp;id='.$link_id.'" '.
  165. 'onclick="return window.confirm(\''.addslashes($del_msg).'\')">'.
  166. '<img src="images/delete.png" alt="'.__('delete').'" '.
  167. 'title="'.__('delete').'" class="status" /></a>'
  168. );
  169. if ($is_cat) {
  170. buffer::str('<a href="'.$url.'&amp;id='.$link_id.'&amp;page=edit_cat">'.
  171. $i_label.'</a>');
  172. } else {
  173. buffer::str('<a href="'.$url.'&amp;id='.$link_id.'&amp;page=edit_link">'.
  174. $i_label.'</a>');
  175. }
  176. buffer::str(($is_cat ? '</strong>' : '').'</p>');
  177. if (!$is_cat)
  178. {
  179. buffer::str(
  180. '<p>'.
  181. htmlspecialchars($rs->f('href')).
  182. ' - '.$rs->f('title').
  183. ' ('.$rs->f('lang').')'.
  184. '</p>'
  185. );
  186. }
  187. buffer::str(
  188. '<p class="nojsfield"><label for="linkOrd'.$link_id.'" class="inline">'.__('Position').' : </label>'.
  189. form::field(array('linkOrd['.$link_id.']','linkOrd'.$link_id),3,3,$link_ord).'</p>'
  190. );
  191. buffer::str('</div>');
  192. }
  193. buffer::str(
  194. '</div>'.
  195. '<p><input type="hidden" id="dndSort" name="dndSort" value="" />'.
  196. '<input type="submit" class="submit" value="'.__('save order').'" /></p>'.
  197. '</form>'
  198. );
  199. buffer::str(
  200. '<form action="'.$url.'" method="post">'.
  201. '<fieldset><legend>'.__('New link').'</legend>'.
  202. '<p class="field"><strong>'.
  203. '<label for="l_label" class="float">'.__('Label').' : </label></strong>'.
  204. form::field('l_label',40,255,htmlspecialchars($l_label)).'</p>'.
  205. '<p class="field"><strong>'.
  206. '<label for="l_href" class="float">'.__('URL').' : </label></strong>'.
  207. form::field('l_href',40,255,htmlspecialchars($l_href)).'</p>'.
  208. '<p class="field">'.
  209. '<label for="l_title" class="float">'.__('Description').' ('.__('optional').') : </label>'.
  210. form::field('l_title',40,255,htmlspecialchars($l_title)).'</p>'.
  211. '<p class="field">'.
  212. '<label for="l_lang" class="float">'.__('Language').' ('.__('optional').') : </label>'.
  213. form::field('l_lang',2,2,htmlspecialchars($l_lang)) . '</p>'.
  214. '<p>'.form::hidden('action','add_link').
  215. '<input type="submit" class="submit" value="'.__('save').'"/></p>'.
  216. '</fieldset>'.
  217. '</form>'
  218. );
  219. buffer::str(
  220. '<form action="'.$url.'" method="post">'.
  221. '<fieldset><legend>'.__('New rubric').'</legend>'.
  222. '<p class="field"><strong>'.
  223. '<label for="c_title" class="float">'.__('Title').' : </label></strong>'.
  224. form::field('c_title',40,255,htmlspecialchars($c_title)).'</p>'.
  225. '<p>'.form::hidden('action','add_cat').
  226. '<input type="submit" class="submit" value="'.__('save').'"/></p>'.
  227. '</fieldset>'.
  228. '</form>'
  229. );
  230. buffer::str(
  231. '<h3>'.__('Usage').'</h3>'.
  232. '<p>'.__('To replace your static blogroll by this one, just put the '.
  233. 'following code in your template:').'</p>'.
  234. '<pre>&lt;?php dcBlogroll::linkList(); ?&gt;</pre>'
  235. );
  236. }
  237. ?>