[ Index ]
 

Code source de Dotclear 1.2.5

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/ecrire/tools/blogroll/ -> index.php (source)

   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  
  23  /* Small note on design:
  24   * 
  25   * Both links and categories are stored in the same database table.
  26   * The difference is that 'label' and 'href' fields are empty for categories.
  27   *
  28   * This is quite hacky but perfectly fits a simple two level design.
  29   *
  30   */ 
  31  
  32  require dirname(__FILE__).'/class.blogroll.php';
  33  
  34  $url = 'tools.php?p=blogroll';
  35  $icon = 'tools/blogroll/icon_small.png';
  36  
  37  $PLUGIN_HEAD =
  38  '<style type="text/css">'."\n".
  39  '.sort img.status {float: right; margin: 2px 0 0 4px; position: relative;}'."\n".
  40  '</style>'."\n".
  41  '<script type="text/javascript" src="js/drag.js"></script>'.
  42  '<script type="text/javascript" src="js/dragsort.js"></script>'.
  43  '<script type="text/javascript">'."\n".
  44  '  if (document.getElementById) { '."\n".
  45  '    window.onload = function() { '."\n".
  46  '    dragSort.dest = document.getElementById(\'dndSort\');'."\n".
  47  '    dragSort.makeElementSortable(document.getElementById(\'sortlinks\'));'."\n".
  48  '    };'."\n".
  49  '  }'."\n".
  50  '</script>';
  51  
  52  $blogroll = new blogroll($blog,DB_PREFIX);
  53  
  54  $action = !empty($_REQUEST['action']) ? $_REQUEST['action'] : NULL;
  55  $page = !empty($_REQUEST['page']) ? $_REQUEST['page'] : NULL;
  56  $err = '';
  57  
  58  if ($page == 'edit_link' && !empty($_REQUEST['id']))
  59  {
  60      include dirname(__FILE__).'/edit_link.php';
  61  }
  62  elseif ($page == 'edit_cat' && !empty($_REQUEST['id']))
  63  {
  64      include dirname(__FILE__).'/edit_cat.php';
  65  }
  66  else
  67  {
  68      $l_label = $l_title = $l_href = $l_lang = '';
  69      $c_title = '';
  70      
  71      # Ajout d'un lien
  72      if ($action == 'add_link')
  73      {
  74          $l_label = trim($_POST['l_label']);
  75          $l_title = trim($_POST['l_title']);
  76          $l_href = trim($_POST['l_href']);
  77          $l_lang = trim($_POST['l_lang']);
  78          
  79          if (!$l_label || !$l_href)
  80          {
  81              $err = __('You must provide at least a label and an URL');
  82          }
  83          else
  84          {
  85              if ($blogroll->addLink($l_label,$l_href,$l_title,$l_lang) == false) {
  86                  $err = $blogroll->con->error();
  87              } else {
  88                  header('Location: '.$url);
  89                  exit;
  90              }
  91          }
  92      }
  93      # Ajout d'un catégorie
  94      elseif ($action == 'add_cat')
  95      {
  96          $c_title = trim($_POST['c_title']);
  97          
  98          if ($c_title)
  99          {
 100              if ($blogroll->addCat($c_title) == false) {
 101                  $err = $blogroll->con->error();
 102              } else {
 103                  header('Location: '.$url);
 104                  exit;
 105              }
 106          }
 107      }
 108      # Suppression
 109      elseif ($action == 'delete' && !empty($_GET['id']))
 110      {
 111          if ($blogroll->delEntry($_GET['id']) == false) {
 112              $err = $blogroll->con->error();
 113          } else {
 114              header('Location: '.$url);
 115              exit;
 116          }
 117      }
 118      # Classic ord
 119      if (isset($_POST['linkOrd']) && is_array($_POST['linkOrd']))
 120      {
 121          if ($blogroll->ordEntries($_POST['linkOrd']) === false) {
 122              $err = $blogroll->con->error();
 123          } else {
 124              header('Location: '.$url);
 125              exit;
 126          }
 127      }
 128      # DragNdrop
 129      if (!empty($_POST['dndSort']))
 130      {
 131          $linkOrd = array();
 132          foreach (explode(';',$_POST['dndSort']) as $k => $v) {
 133              $linkOrd[substr($v,3)] = $k;
 134          }
 135          
 136          if ($blogroll->ordEntries($linkOrd) === false) {
 137              $err = $blogroll->con->error();
 138          } else {
 139              header('Location: '.$url);
 140              exit;
 141          }
 142      }
 143      
 144      
 145      # Affichage ---
 146      buffer::str('<h2>'.__('Links manager').'</h2>');
 147      
 148      if ($err != '') {
 149          buffer::str(
 150          '<div class="erreur"><p><strong>'.__('Error(s)').' :</strong></p>'.
 151          '<p>'.$err.'</p>'.
 152          '</div>'
 153          );
 154      }
 155      
 156      $strReq = 'SELECT link_id, label, href, title, lang, position '.
 157              'FROM '.$blogroll->table.' '.
 158              'ORDER BY position ';
 159      
 160      $rs = $con->select($strReq);
 161      
 162      buffer::str(
 163      '<p>'.__('Drag items to change their positions.').'</p>'.
 164      '<form action="'.$url.'" method="post">'.
 165      '<div id="sortlinks">'
 166      );
 167      while ($rs->fetch())
 168      {
 169          $link_id = $rs->f('link_id');
 170          $link_ord = $rs->f('position');
 171          
 172          $is_cat = !$rs->f('label') && !$rs->f('href');
 173          
 174          $i_label = ($is_cat) ? $rs->f('title') : $rs->f('label');
 175          
 176          if ($is_cat) {
 177              $del_msg = __('Are you sure you want to delete this category?');
 178          } else {
 179              $del_msg = sprintf(__('Are you sure you want to delete this %s?'),__('link'));
 180          }
 181          
 182          buffer::str('<div class="sort" id="dnd'.$link_id.'">');
 183          
 184          buffer::str(
 185          '<p>'.($is_cat ? '<strong>' : '').
 186          '<a href="'.$url.'&amp;action=delete&amp;id='.$link_id.'" '.
 187          'onclick="return window.confirm(\''.addslashes($del_msg).'\')">'.
 188          '<img src="images/delete.png" alt="'.__('delete').'" '.
 189          'title="'.__('delete').'" class="status" /></a>'
 190          );
 191          
 192          
 193          if ($is_cat) {
 194              buffer::str('<a href="'.$url.'&amp;id='.$link_id.'&amp;page=edit_cat">'.
 195              $i_label.'</a>');
 196          } else {
 197              buffer::str('<a href="'.$url.'&amp;id='.$link_id.'&amp;page=edit_link">'.
 198              $i_label.'</a>');
 199          }
 200          
 201          buffer::str(($is_cat ? '</strong>' : '').'</p>');
 202          
 203          if (!$is_cat)
 204          {
 205              buffer::str(
 206              '<p>'.
 207              htmlspecialchars($rs->f('href')).
 208              ' - '.$rs->f('title').
 209              ' ('.$rs->f('lang').')'.
 210              '</p>'
 211              );
 212          }
 213          
 214          buffer::str(
 215          '<p class="nojsfield"><label for="linkOrd'.$link_id.'" class="inline">'.__('Position').' : </label>'.
 216          form::field(array('linkOrd['.$link_id.']','linkOrd'.$link_id),3,3,$link_ord).'</p>'
 217          );
 218          
 219          buffer::str('</div>');
 220      }
 221      buffer::str(
 222      '</div>'.
 223      '<p><input type="hidden" id="dndSort" name="dndSort" value="" />'.
 224      '<input type="submit" class="submit" value="'.__('save order').'" /></p>'.
 225      '</form>'
 226      );
 227      
 228      buffer::str(
 229      '<form action="'.$url.'" method="post">'.
 230      '<fieldset><legend>'.__('New link').'</legend>'.
 231      '<p class="field"><strong>'.
 232      '<label for="l_label" class="float">'.__('Label').' : </label></strong>'.
 233      form::field('l_label',40,255,htmlspecialchars($l_label)).'</p>'.
 234      
 235      '<p class="field"><strong>'.
 236      '<label for="l_href" class="float">'.__('URL').' : </label></strong>'.
 237      form::field('l_href',40,255,htmlspecialchars($l_href)).'</p>'.
 238      
 239      '<p class="field">'.
 240      '<label for="l_title" class="float">'.__('Description').' ('.__('optional').') : </label>'.
 241      form::field('l_title',40,255,htmlspecialchars($l_title)).'</p>'.
 242      
 243      '<p class="field">'.
 244      '<label for="l_lang" class="float">'.__('Language').' ('.__('optional').') : </label>'.
 245      form::field('l_lang',2,2,htmlspecialchars($l_lang)) . '</p>'.
 246      
 247      '<p>'.form::hidden('action','add_link').
 248      '<input type="submit" class="submit" value="'.__('save').'"/></p>'.
 249      '</fieldset>'.
 250      '</form>'
 251      );
 252      
 253      buffer::str(
 254      '<form action="'.$url.'" method="post">'.
 255      '<fieldset><legend>'.__('New rubric').'</legend>'.
 256      '<p class="field"><strong>'.
 257      '<label for="c_title" class="float">'.__('Title').' : </label></strong>'.
 258      form::field('c_title',40,255,htmlspecialchars($c_title)).'</p>'.
 259      
 260      '<p>'.form::hidden('action','add_cat').
 261      '<input type="submit" class="submit" value="'.__('save').'"/></p>'.
 262      '</fieldset>'.
 263      '</form>'
 264      );
 265      
 266      buffer::str(
 267      '<h3>'.__('Usage').'</h3>'.
 268      '<p>'.__('To replace your static blogroll by this one, just put the '.
 269      'following code in your template:').'</p>'.
 270      '<pre>&lt;?php dcBlogroll::linkList(); ?&gt;</pre>'
 271      );
 272  }
 273  ?>


Généré le : Fri Feb 23 21:40:15 2007 par Balluche grâce à PHPXref 0.7