[ Index ]
 

Code source de Dotclear 2.0-beta6

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

title

Body

[fermer]

/plugins/metadata/ -> _admin.php (source)

   1  <?php
   2  # ***** BEGIN LICENSE BLOCK *****
   3  # This file is part of DotClear.
   4  # Copyright (c) 2005 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  $_menu['Blog']->addItem('Tags','plugin.php?p=metadata&amp;m=tags','index.php?pf=metadata/tags.png',
  24          preg_match('/plugin.php\?p=metadata&m=tag(s|_posts)?(&.*)?$/',$_SERVER['REQUEST_URI']),
  25          $core->auth->check('usage,contentadmin',$core->blog->id));
  26  
  27  require dirname(__FILE__).'/_widgets.php';
  28  
  29  $core->addBehavior('adminPostFormSidebar',array('metaBehaviors','tagsField'));
  30  
  31  $core->addBehavior('adminAfterPostCreate',array('metaBehaviors','setTags'));
  32  $core->addBehavior('adminAfterPostUpdate',array('metaBehaviors','setTags'));
  33  
  34  $core->addBehavior('adminPostHeaders',array('metaBehaviors','postHeaders'));
  35  
  36  $core->addBehavior('adminPostsActionsCombo',array('metaBehaviors','adminPostsActionsCombo'));
  37  $core->addBehavior('adminPostsActions',array('metaBehaviors','adminPostsActions'));
  38  $core->addBehavior('adminPostsActionsContent',array('metaBehaviors','adminPostsActionsContent'));
  39  
  40  $core->addBehavior('coreInitWikiPost',array('metaBehaviors','coreInitWikiPost'));
  41  
  42  $core->addBehavior('exportFull',array('metaBehaviors','exportFull'));
  43  $core->addBehavior('exportSingle',array('metaBehaviors','exportSingle'));
  44  $core->addBehavior('importInit',array('metaBehaviors','importInit'));
  45  $core->addBehavior('importSingle',array('metaBehaviors','importSingle'));
  46  $core->addBehavior('importFull',array('metaBehaviors','importFull'));
  47  $core->addBehavior('importPrepareDC12',array('metaBehaviors','importPrepareDC12'));
  48  
  49  $core->rest->addFunction('getMeta',array('metaRest','getMeta'));
  50  $core->rest->addFunction('delMeta',array('metaRest','delMeta'));
  51  $core->rest->addFunction('setPostMeta',array('metaRest','setPostMeta'));
  52  
  53  # BEHAVIORS
  54  class metaBehaviors
  55  {
  56  	public static function coreInitWikiPost(&$wiki2xhtml)
  57      {
  58          $wiki2xhtml->registerFunction('url:tag',array('metaBehaviors','wiki2xhtmlTag'));
  59      }
  60      
  61  	public static function wiki2xhtmlTag($url,$content)
  62      {
  63          $url = substr($url,4);
  64          if (strpos($content,'tag:') === 0) {
  65              $content = substr($content,4);
  66          }
  67          
  68          
  69          $tag_url = html::stripHostURL($GLOBALS['core']->blog->url.$GLOBALS['core']->url->getBase('tag'));
  70          $res['url'] = $tag_url.'/'.rawurlencode(dcMeta::sanitizeMetaID($url));
  71          $res['content'] = $content;
  72          
  73          return $res;
  74      }
  75      
  76  	public static function tagsField(&$post)
  77      {
  78          $meta = new dcMeta($GLOBALS['core']);
  79          
  80          if (!empty($_POST['post_tags'])) {
  81              $value = $_POST['post_tags'];
  82          } else {
  83              $value = ($post) ? $meta->getMetaStr($post->post_meta,'tag') : '';
  84          }
  85          
  86          echo
  87          '<h3><label for="post_tags">'.__('Tags:').'</label></h3>'.
  88          '<div class="p" id="meta-edit-tags">'.form::textarea('post_tags',20,3,$value,'maximal',3).'</div>';
  89      }
  90      
  91  	public static function setTags(&$cur,&$post_id)
  92      {
  93          $post_id = (integer) $post_id;
  94          
  95          if (isset($_POST['post_tags'])) {
  96              $tags = $_POST['post_tags'];
  97              
  98              $meta = new dcMeta($GLOBALS['core']);
  99              
 100              $meta->delPostMeta($post_id,'tag');
 101              
 102              foreach ($meta->splitMetaValues($tags) as $tag) {
 103                  $meta->setPostMeta($post_id,'tag',$tag);
 104              }
 105          }
 106      }
 107      
 108  	public static function postHeaders()
 109      {
 110          $tag_url = $GLOBALS['core']->blog->url.$GLOBALS['core']->url->getBase('tag');
 111          
 112          return 
 113          '<script type="text/javascript" src="index.php?pf=metadata/post.js"></script>'.
 114          '<script type="text/javascript">'."\n".
 115          "//<![CDATA[\n".
 116          "metaEditor.prototype.text_confirm_remove = '".html::escapeJS(__('Are you sure you want to remove this %s?'))."';\n".
 117          "metaEditor.prototype.text_add_meta = '".html::escapeJS(__('Add a %s to this entry'))."';\n".
 118          "metaEditor.prototype.text_choose = '".html::escapeJS(__('Choose from list'))."';\n".
 119          "metaEditor.prototype.text_more = '".html::escapeJS(__('more'))."';\n".
 120          "metaEditor.prototype.text_all = '".html::escapeJS(__('all'))."';\n".
 121          "jsToolBar.prototype.elements.tag.title = '".html::escapeJS(__('Tag'))."';\n".
 122          "jsToolBar.prototype.elements.tag.url = '".html::escapeJS($tag_url)."';\n".
 123          "\n//]]>\n".
 124          "</script>\n".
 125          '<link rel="stylesheet" type="text/css" href="index.php?pf=metadata/style.css" />';
 126      }
 127      
 128  	public static function adminPostsActionsCombo(&$args)
 129      {
 130          $args[0][__('add tags')] = 'tags';
 131      }
 132      
 133  	public static function adminPostsActions(&$core,$posts,$action,$redir)
 134      {
 135          if ($action == 'tags' && !empty($_POST['new_tags']))
 136          {
 137              try
 138              {
 139                  $meta = new dcMeta($core);
 140                  $tags = $meta->splitMetaValues($_POST['new_tags']);
 141                  
 142                  while ($posts->fetch())
 143                  {
 144                      # Get tags for post
 145                      $post_meta = $meta->getMeta('tag',null,null,$posts->post_id);
 146                      $pm = array();
 147                      while ($post_meta->fetch()) {
 148                          $pm[] = $post_meta->meta_id;
 149                      }
 150                      
 151                      foreach ($tags as $t) {
 152                          if (!in_array($t,$pm)) {
 153                              $meta->setPostMeta($posts->post_id,'tag',$t);
 154                          }
 155                      }
 156                  }
 157                  
 158                  http::redirect($redir);
 159              }
 160              catch (Exception $e)
 161              {
 162                  $core->error->add($e->getMessage());
 163              }
 164          }
 165      }
 166      
 167  	public static function adminPostsActionsContent($core,$action,$hidden_fields)
 168      {
 169          if ($action == 'tags')
 170          {
 171              echo
 172              '<h2>'.__('Add tags to entries').'</h2>'.
 173              '<form action="posts_actions.php" method="post">'.
 174              '<p><label class="area">'.__('Tags to add:').' '.
 175              form::textarea('new_tags',60,3).
 176              '</label> '.
 177              
 178              $hidden_fields.
 179              form::hidden(array('action'),'tags').
 180              '<input type="submit" value="'.__('save').'" /></p>'.
 181              '</form>';
 182          }
 183      }
 184      
 185  	public static function exportFull(&$core,&$exp)
 186      {
 187          $exp->exportTable('meta');
 188      }
 189      
 190  	public static function exportSingle(&$core,&$exp,$blog_id)
 191      {
 192          $exp->export('meta',
 193              'SELECT meta_id, meta_type, M.post_id '.
 194              'FROM '.$core->prefix.'meta M, '.$core->prefix.'post P '.
 195              'WHERE P.post_id = M.post_id '.
 196              "AND P.blog_id = '".$blog_id."'"
 197          );
 198      }
 199      
 200  	public static function importInit(&$bk,&$core)
 201      {
 202          $bk->cur_meta = $core->con->openCursor($core->prefix.'meta');
 203          $bk->meta = new dcMeta($core);
 204      }
 205      
 206  	public static function importFull(&$line,&$bk,&$core)
 207      {
 208          if ($line->__name == 'meta')
 209          {
 210              $bk->cur_meta->clean();
 211              
 212              $bk->cur_meta->meta_id   = (string) $line->meta_id;
 213              $bk->cur_meta->meta_type = (string) $line->meta_type;
 214              $bk->cur_meta->post_id   = (integer) $line->post_id;
 215              
 216              $bk->cur_meta->insert();
 217          }
 218      }
 219      
 220  	public static function importSingle(&$line,&$bk,&$core)
 221      {
 222          if ($line->__name == 'meta' && isset($bk->old_ids['post'][(integer) $line->post_id]))
 223          {
 224              $line->post_id = $bk->old_ids['post'][(integer) $line->post_id];
 225              $bk->meta->setPostMeta($line->post_id,$line->meta_type,$line->meta_id);
 226          }
 227      }
 228      
 229  	public static function importPrepareDC12(&$line,&$bk,&$core)
 230      {
 231          if ($line->__name == 'post_meta')
 232          {
 233              $line->drop('meta_id');
 234              $line->substitute('meta_key','meta_type');
 235              $line->substitute('meta_value','meta_id');
 236              $line->__name = 'meta';
 237              $line->blog_id = 'default';
 238          }
 239      }
 240  }
 241  
 242  # REST
 243  class metaRest
 244  {
 245  	public static function getMeta(&$core,$get)
 246      {
 247          $meta = new dcMeta($core);
 248          
 249          $postid = !empty($get['postId']) ? $get['postId'] : null;
 250          $limit = !empty($get['limit']) ? $get['limit'] : null;
 251          $metaId = !empty($get['metaId']) ? $get['metaId'] : null;
 252          $metaType = !empty($get['metaType']) ? $get['metaType'] : null;
 253          
 254          $sortby = !empty($get['sortby']) ? $get['sortby'] : 'meta_type,asc';
 255          
 256          $rs = $meta->getMeta($metaType,$limit,$metaId,$postid);
 257          
 258          $sortby = explode(',',$sortby);
 259          $sort = $sortby[0];
 260          $order = isset($sortby[1]) ? $sortby[1] : 'asc';
 261          
 262          switch ($sort) {
 263              case 'metaId':
 264                  $sort = 'meta_id_lower';
 265                  break;
 266              case 'count':
 267                  $sort = 'count';
 268                  break;
 269              case 'metaType':
 270                  $sort = 'meta_type';
 271                  break;
 272              default:
 273                  $sort = 'meta_type';
 274          }
 275          
 276          $rs->sort($sort,$order);
 277          
 278          $rsp = new xmlTag();
 279          
 280          while ($rs->fetch())
 281          {
 282              $metaTag = new xmlTag('meta');
 283              $metaTag->type = $rs->meta_type;
 284              $metaTag->uri = rawurlencode($rs->meta_id);
 285              $metaTag->count = $rs->count;
 286              $metaTag->percent = $rs->percent;
 287              $metaTag->roundpercent = $rs->roundpercent;
 288              $metaTag->CDATA($rs->meta_id);
 289              
 290              $rsp->insertNode($metaTag);
 291          }
 292          
 293          return $rsp;
 294      }
 295      
 296  	public static function setPostMeta(&$core,$get,$post)
 297      {
 298          if (empty($post['postId'])) {
 299              throw new Exception('No post ID');
 300          }
 301          
 302          if (empty($post['meta'])) {
 303              throw new Exception('No meta');
 304          }
 305          
 306          if (empty($post['metaType'])) {
 307              throw new Exception('No meta type');
 308          }
 309          
 310          $meta = new dcMeta($core);
 311          
 312          # Get previous meta for post
 313          $post_meta = $meta->getMeta($post['metaType'],null,null,$post['postId']);
 314          $pm = array();
 315          while ($post_meta->fetch()) {
 316              $pm[] = $post_meta->meta_id;
 317          }
 318          
 319          foreach ($meta->splitMetaValues($post['meta']) as $m)
 320          {
 321              if (!in_array($m,$pm)) {
 322                  $meta->setPostMeta($post['postId'],$post['metaType'],$m);
 323              }
 324          }
 325          
 326          return true;
 327      }
 328      
 329  	public static function delMeta(&$core,$get,$post)
 330      {
 331          if (empty($post['postId'])) {
 332              throw new Exception('No post ID');
 333          }
 334          
 335          if (empty($post['metaId'])) {
 336              throw new Exception('No meta ID');
 337          }
 338          
 339          if (empty($post['metaType'])) {
 340              throw new Exception('No meta type');
 341          }
 342          
 343          $meta = new dcMeta($core);
 344          
 345          $meta->delPostMeta($post['postId'],$post['metaType'],$post['metaId']);
 346          
 347          return true;
 348      }
 349  }
 350  ?>


Généré le : Fri Feb 23 22:16:06 2007 par Balluche grâce à PHPXref 0.7