Dotclear

Changeset 851:0993f64c4809


Ignore:
Timestamp:
07/31/12 13:52:11 (13 years ago)
Author:
Dsls <dsls@…>
Branch:
sexy
Message:

sexy step 2 : no more cats.

Files:
3 deleted
20 edited

Legend:

Unmodified
Added
Removed
  • admin/index.php

    r848 r851  
    294294     if ($core->auth->check('usage,contentadmin',$core->blog->id)) 
    295295     { 
    296           $categories_combo = array('&nbsp;' => ''); 
    297           try { 
    298                $categories = $core->blog->getCategories(array('post_type'=>'post')); 
    299                while ($categories->fetch()) { 
    300                     $categories_combo[] = new formSelectOption( 
    301                          str_repeat('&nbsp;&nbsp;',$categories->level-1). 
    302                          ($categories->level-1 == 0 ? '' : '&bull; ').html::escapeHTML($categories->cat_title), 
    303                          $categories->cat_id 
    304                     ); 
    305                } 
    306           } catch (Exception $e) { } 
    307       
    308296          echo 
    309297          '<div id="quick">'. 
     
    318306          form::textarea('post_content',50,7). 
    319307          '</p>'. 
    320           '<p><label for="cat_id" class="classic">'.__('Category:').' '. 
    321           form::combo('cat_id',$categories_combo).'</label></p>'. 
    322308          '<p><input type="submit" value="'.__('Save').'" name="save" /> '. 
    323309          ($core->auth->check('publish',$core->blog->id) 
  • admin/post.php

    r848 r851  
    1616 
    1717$post_id = ''; 
    18 $cat_id = ''; 
    1918$post_dt = ''; 
    2019$post_format = $core->auth->getOption('post_format'); 
     
    4847} 
    4948 
    50 # Getting categories 
    51 $categories_combo = array('&nbsp;' => ''); 
    52 try { 
    53      $categories = $core->blog->getCategories(array('post_type'=>'post')); 
    54      while ($categories->fetch()) { 
    55           $categories_combo[] = new formSelectOption( 
    56                str_repeat('&nbsp;&nbsp;',$categories->level-1).($categories->level-1 == 0 ? '' : '&bull; ').html::escapeHTML($categories->cat_title), 
    57                $categories->cat_id 
    58           ); 
    59      } 
    60 } catch (Exception $e) { } 
    61  
    6249# Status combo 
    6350foreach ($core->blog->getAllPostStatus() as $k => $v) { 
     
    10188     { 
    10289          $post_id = $post->post_id; 
    103           $cat_id = $post->cat_id; 
    10490          $post_dt = date('Y-m-d H:i',strtotime($post->post_dt)); 
    10591          $post_format = $post->post_format; 
     
    153139     $post_title = $_POST['post_title']; 
    154140      
    155      $cat_id = (integer) $_POST['cat_id']; 
    156       
    157141     if (isset($_POST['post_status'])) { 
    158142          $post_status = (integer) $_POST['post_status']; 
     
    188172      
    189173     $cur->post_title = $post_title; 
    190      $cur->cat_id = ($cat_id ? $cat_id : null); 
    191174     $cur->post_dt = $post_dt ? date('Y-m-d H:i:00',strtotime($post_dt)) : ''; 
    192175     $cur->post_format = $post_format; 
     
    389372      
    390373     echo 
    391      '<p><label for="cat_id">'.__('Category:'). 
    392      form::combo('cat_id',$categories_combo,$cat_id,'maximal'). 
    393      '</label></p>'. 
    394       
    395374     '<p><label for="post_status">'.__('Entry status:'). 
    396375     form::combo('post_status',$status_combo,$post_status,'','',!$can_publish). 
  • admin/posts.php

    r796 r851  
    1515dcPage::check('usage,contentadmin'); 
    1616 
    17 # Getting categories 
    18 try { 
    19      $categories = $core->blog->getCategories(array('post_type'=>'post')); 
    20 } catch (Exception $e) { 
    21      $core->error->add($e->getMessage()); 
    22 } 
    23  
    2417# Getting authors 
    2518try { 
     
    4740{ 
    4841     # Filter form we'll put in html_block 
    49      $users_combo = $categories_combo = array(); 
    50      $users_combo['-'] = $categories_combo['-'] = ''; 
     42     $users_combo = array(); 
     43     $users_combo['-'] = ''; 
    5144     while ($users->fetch()) 
    5245     { 
     
    6154     } 
    6255      
    63      $categories_combo[__('None')] = 'NULL'; 
    64      while ($categories->fetch()) { 
    65           $categories_combo[str_repeat('&nbsp;&nbsp;',$categories->level-1).($categories->level-1 == 0 ? '' : '&bull; '). 
    66                html::escapeHTML($categories->cat_title). 
    67                ' ('.$categories->nb_post.')'] = $categories->cat_id; 
    68      } 
    69       
    7056     $status_combo = array( 
    7157     '-' => '' 
     
    9581     __('Date') => 'post_dt', 
    9682     __('Title') => 'post_title', 
    97      __('Category') => 'cat_title', 
    9883     __('Author') => 'user_id', 
    9984     __('Status') => 'post_status', 
     
    122107     __('Mark as unselected') => 'unselected' 
    123108); 
    124 $combo_action[__('Change')] = array(__('Change category') => 'category'); 
     109$combo_action[__('Change')] = array(); 
    125110if ($core->auth->check('admin',$core->blog->id)) 
    126111{ 
     
    139124-------------------------------------------------------- */ 
    140125$user_id = !empty($_GET['user_id']) ?   $_GET['user_id'] : ''; 
    141 $cat_id = !empty($_GET['cat_id']) ?     $_GET['cat_id'] : ''; 
    142126$status = isset($_GET['status']) ? $_GET['status'] : ''; 
    143127$selected = isset($_GET['selected']) ?  $_GET['selected'] : ''; 
     
    168152} else { 
    169153     $user_id=''; 
    170 } 
    171  
    172 # - Categories filter 
    173 if ($cat_id !== '' && in_array($cat_id,$categories_combo)) { 
    174      $params['cat_id'] = $cat_id; 
    175      $show_filters = true; 
    176 } else { 
    177      $cat_id=''; 
    178154} 
    179155 
     
    263239     '<label for="user_id">'.__('Author:'). 
    264240     form::combo('user_id',$users_combo,$user_id).'</label> '. 
    265      '<label for="cat_id">'.__('Category:'). 
    266      form::combo('cat_id',$categories_combo,$cat_id).'</label> '. 
    267241     '<label for="status">'.__('Status:'). 
    268242     form::combo('status',$status_combo,$status).'</label> '. 
     
    305279     '<input type="submit" value="'.__('ok').'" /></p>'. 
    306280     form::hidden(array('user_id'),$user_id). 
    307      form::hidden(array('cat_id'),$cat_id). 
    308281     form::hidden(array('status'),$status). 
    309282     form::hidden(array('selected'),$selected). 
  • admin/posts_actions.php

    r500 r851  
    3232          $redir = 
    3333          'posts.php?user_id='.$_POST['user_id']. 
    34           '&cat_id='.$_POST['cat_id']. 
    3534          '&status='.$_POST['status']. 
    3635          '&selected='.$_POST['selected']. 
     
    117116           
    118117     } 
    119      elseif ($action == 'category' && isset($_POST['new_cat_id'])) 
    120      { 
    121           try 
    122           { 
    123                while ($posts->fetch()) 
    124                { 
    125                     $new_cat_id = (integer) $_POST['new_cat_id']; 
    126                     $core->blog->updPostCategory($posts->post_id,$new_cat_id); 
    127                } 
    128                http::redirect($redir); 
    129           } 
    130           catch (Exception $e) 
    131           { 
    132                $core->error->add($e->getMessage()); 
    133           } 
    134      } 
    135118     elseif ($action == 'author' && isset($_POST['new_auth_id']) 
    136119     && $core->auth->check('admin',$core->blog->id)) 
     
    187170     $hidden_fields .= 
    188171     form::hidden(array('user_id'),$_POST['user_id']). 
    189      form::hidden(array('cat_id'),$_POST['cat_id']). 
    190172     form::hidden(array('status'),$_POST['status']). 
    191173     form::hidden(array('selected'),$_POST['selected']). 
     
    205187$core->callBehavior('adminPostsActionsContent',$core,$action,$hidden_fields); 
    206188 
    207 if ($action == 'category') 
    208 { 
    209      echo '<h2 class="page-title">'.__('Change category for entries').'</h2>'; 
    210       
    211      # categories list 
    212      # Getting categories 
    213      $categories_combo = array('&nbsp;' => ''); 
    214      try { 
    215           $categories = $core->blog->getCategories(array('post_type'=>'post')); 
    216           while ($categories->fetch()) { 
    217                $categories_combo[] = new formSelectOption( 
    218                     str_repeat('&nbsp;&nbsp;',$categories->level-1). 
    219                     ($categories->level-1 == 0 ? '' : '&bull; ').html::escapeHTML($categories->cat_title), 
    220                     $categories->cat_id 
    221                ); 
    222           } 
    223      } catch (Exception $e) { } 
    224       
    225      echo 
    226      '<form action="posts_actions.php" method="post">'. 
    227      '<p><label for="new_cat_id" class="classic">'.__('Category:').' '. 
    228      form::combo('new_cat_id',$categories_combo,''). 
    229      '</label> '; 
    230       
    231      echo 
    232      $hidden_fields. 
    233      $core->formNonce(). 
    234      form::hidden(array('action'),'category'). 
    235      '<input type="submit" value="'.__('Save').'" /></p>'. 
    236      '</form>'; 
    237 } 
    238 elseif ($action == 'author' && $core->auth->check('admin',$core->blog->id)) 
     189if ($action == 'author' && $core->auth->check('admin',$core->blog->id)) 
    239190{ 
    240191     echo '<h2 class="page-title">'.__('Change author for entries').'</h2>'; 
  • admin/search.php

    r848 r851  
    8181               $combo_action[__('mark as pending')] = 'pending'; 
    8282          } 
    83           $combo_action[__('change category')] = 'category'; 
    84           if ($core->auth->check('admin',$core->blog->id)) { 
    85                $combo_action[__('change author')] = 'author'; 
    86           } 
    8783          if ($core->auth->check('delete,contentadmin',$core->blog->id)) 
    8884          { 
  • inc/admin/lib.dc.page.php

    r848 r851  
    414414          self::jsVar('dotclear.msg.confirm_delete_user', 
    415415               __('Are you sure you want to delete selected users (%s)?')). 
    416           self::jsVar('dotclear.msg.confirm_delete_category', 
    417                __('Are you sure you want to delete category "%s"?')). 
    418           self::jsVar('dotclear.msg.confirm_reorder_categories', 
    419                __('Are you sure you want to reorder all categories?')). 
    420416          self::jsVar('dotclear.msg.confirm_delete_media', 
    421417               __('Are you sure you want to remove media "%s"?')). 
  • inc/admin/lib.pager.php

    r848 r851  
    4747               '<th colspan="2">'.__('Title').'</th>'. 
    4848               '<th>'.__('Date').'</th>'. 
    49                '<th>'.__('Category').'</th>'. 
    5049               '<th>'.__('Author').'</th>'. 
    5150               '<th>'.__('Status').'</th>'. 
     
    7574     private function postLine() 
    7675     { 
    77           if ($this->core->auth->check('categories',$this->core->blog->id)) { 
    78                $cat_link = '<a href="category.php?id=%s">%s</a>'; 
    79           } else { 
    80                $cat_link = '%2$s'; 
    81           } 
    82            
    83           if ($this->rs->cat_title) { 
    84                $cat_title = sprintf($cat_link,$this->rs->cat_id, 
    85                html::escapeHTML($this->rs->cat_title)); 
    86           } else { 
    87                $cat_title = __('None'); 
    88           } 
    89            
    9076          $img = '<img alt="%1$s" title="%1$s" src="images/%2$s" />'; 
    9177          switch ($this->rs->post_status) { 
     
    130116          html::escapeHTML($this->rs->post_title).'</a></td>'. 
    131117          '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$this->rs->post_dt).'</td>'. 
    132           '<td class="nowrap">'.$cat_title.'</td>'. 
    133118          '<td class="nowrap">'.$this->rs->user_id.'</td>'. 
    134119          '<td class="nowrap status">'.$img_status.' '.$selected.' '.$protected.' '.$attach.'</td>'. 
  • inc/admin/prepend.php

    r848 r851  
    238238          'images/menu/search.png','images/menu/search-b.png', 
    239239          'usage,contentadmin',null,null)); 
    240      $_fav['categories'] = new ArrayObject(array('categories','Categories','categories.php', 
    241           'images/menu/categories.png','images/menu/categories-b.png', 
    242           'categories',null,null)); 
    243240     $_fav['media'] = new ArrayObject(array('media','Media manager','media.php', 
    244241          'images/menu/media.png','images/menu/media-b.png', 
     
    302299          preg_match('/media(_item)?.php(\?.*)?$/',$_SERVER['REQUEST_URI']), 
    303300          $core->auth->check('media,media_admin',$core->blog->id)); 
    304      $_menu['Blog']->prependItem(__('Categories'),'categories.php','images/menu/categories.png', 
    305           preg_match('/categories.php(\?.*)?$/',$_SERVER['REQUEST_URI']), 
    306           $core->auth->check('categories',$core->blog->id)); 
    307301     $_menu['Blog']->prependItem(__('Search'),'search.php','images/menu/search.png', 
    308302          preg_match('/search.php(\?.*)?$/',$_SERVER['REQUEST_URI']), 
  • inc/core/class.dc.auth.php

    r527 r851  
    7676               'delete' => __('delete entries and comments'), 
    7777               'contentadmin' => __('manage all entries and comments'), 
    78                'categories' => __('manage categories'), 
    7978               'media' => __('manage their own media items'), 
    8079               'media_admin' => __('manage all media items') 
  • inc/core/class.dc.blog.php

    r848 r851  
    5656     private $post_status = array(); 
    5757      
    58      private $categories; 
    59       
    6058     /** @var boolean Disallow entries password protection */ 
    6159     public $without_password = true; 
     
    169167          $this->core->callBehavior('coreBlogAfterTriggerBlog',$cur); 
    170168     } 
    171            
    172      /// @name Categories management methods 
    173      //@{ 
    174      public function categories() 
    175      { 
    176           if (!($this->categories instanceof dcCategories)) { 
    177                $this->categories = new dcCategories($this->core); 
    178           } 
    179            
    180           return $this->categories; 
    181      } 
    182       
    183      /** 
    184      Retrieves categories. <var>$params</var> is an associative array which can 
    185      take the following parameters: 
    186       
    187      - post_type: Get only entries with given type (default "post") 
    188      - cat_url: filter on cat_url field 
    189      - cat_id: filter on cat_id field 
    190      - start: start with a given category 
    191      - level: categories level to retrieve 
    192       
    193      @param    params    <b>array</b>        Parameters 
    194      @return   <b>record</b> 
    195      */ 
    196      public function getCategories($params=array()) 
    197      { 
    198           $c_params = array(); 
    199           if (isset($params['post_type'])) { 
    200                $c_params['post_type'] = $params['post_type']; 
    201                unset($params['post_type']); 
    202           } 
    203           $counter = $this->getCategoriesCounter($c_params); 
    204            
    205           $without_empty = $this->core->auth->userID() == false; # For public display 
    206            
    207           $start = isset($params['start']) ? (integer) $params['start'] : 0; 
    208           $l = isset($params['level']) ? (integer) $params['level'] : 0; 
    209            
    210           $rs = $this->categories()->getChildren($start,null,'desc'); 
    211            
    212           # Get each categories total posts count 
    213           $data = array(); 
    214           $stack = array(); 
    215           $level = 0; 
    216           $cols = $rs->columns(); 
    217           while ($rs->fetch()) 
    218           { 
    219                $nb_post = isset($counter[$rs->cat_id]) ? (integer) $counter[$rs->cat_id] : 0; 
    220                 
    221                if ($rs->level > $level) { 
    222                     $nb_total = $nb_post; 
    223                     $stack[$rs->level] = (integer) $nb_post; 
    224                } elseif ($rs->level == $level) { 
    225                     $nb_total = $nb_post; 
    226                     $stack[$rs->level] += $nb_post; 
    227                } else { 
    228                     $nb_total = $stack[$rs->level+1] + $nb_post; 
    229                     if (isset($stack[$rs->level])) { 
    230                          $stack[$rs->level] += $nb_total; 
    231                     } else { 
    232                          $stack[$rs->level] = $nb_total; 
    233                     } 
    234                     unset($stack[$rs->level+1]); 
    235                } 
    236                 
    237                if ($nb_total == 0 && $without_empty) { 
    238                     continue; 
    239                } 
    240                 
    241                $level = $rs->level; 
    242                 
    243                $t = array(); 
    244                foreach ($cols as $c) { 
    245                     $t[$c] = $rs->f($c); 
    246                } 
    247                $t['nb_post'] = $nb_post; 
    248                $t['nb_total'] = $nb_total; 
    249                 
    250                if ($l == 0 || ($l > 0 && $l == $rs->level)) { 
    251                     array_unshift($data,$t); 
    252                } 
    253           } 
    254            
    255           # We need to apply filter after counting 
    256           if (isset($params['cat_id']) && $params['cat_id'] !== '') 
    257           { 
    258                $found = false; 
    259                foreach ($data as $v) { 
    260                     if ($v['cat_id'] == $params['cat_id']) { 
    261                          $found = true; 
    262                          $data = array($v); 
    263                          break; 
    264                     } 
    265                } 
    266                if (!$found) { 
    267                     $data = array(); 
    268                } 
    269           } 
    270            
    271           if (isset($params['cat_url']) && ($params['cat_url'] !== '')  
    272                && !isset($params['cat_id'])) 
    273           { 
    274                $found = false; 
    275                foreach ($data as $v) { 
    276                     if ($v['cat_url'] == $params['cat_url']) { 
    277                          $found = true; 
    278                          $data = array($v); 
    279                          break; 
    280                     } 
    281                } 
    282                if (!$found) { 
    283                     $data = array(); 
    284                } 
    285           } 
    286            
    287           return staticRecord::newFromArray($data); 
    288      } 
    289       
    290      /** 
    291      Retrieves a category by its ID. 
    292       
    293      @param    id        <b>integer</b>      Category ID 
    294      @return   <b>record</b> 
    295      */ 
    296      public function getCategory($id) 
    297      { 
    298           return $this->getCategories(array('cat_id' => $id)); 
    299      } 
    300       
    301      /** 
    302      Retrieves parents of a given category. 
    303       
    304      @param    id        <b>integer</b>      Category ID 
    305      @return   <b>record</b> 
    306      */ 
    307      public function getCategoryParents($id) 
    308      { 
    309           return $this->categories()->getParents($id); 
    310      } 
    311       
    312      /** 
    313      Retrieves first parent of a given category. 
    314       
    315      @param    id        <b>integer</b>      Category ID 
    316      @return   <b>record</b> 
    317      */ 
    318      public function getCategoryParent($id) 
    319      { 
    320           return $this->categories()->getParent($id); 
    321      } 
    322       
    323      /** 
    324      Retrieves all category's first children 
    325       
    326      @param    id        <b>integer</b>      Category ID 
    327      @return   <b>record</b> 
    328      */ 
    329      public function getCategoryFirstChildren($id) 
    330      { 
    331           return $this->getCategories(array('start' => $id,'level' => $id == 0 ? 1 : 2)); 
    332      } 
    333       
    334      private function getCategoriesCounter($params=array()) 
    335      { 
    336           $strReq = 
    337           'SELECT  C.cat_id, COUNT(P.post_id) AS nb_post '. 
    338           'FROM '.$this->prefix.'category AS C '. 
    339           'JOIN '.$this->prefix."post P ON (C.cat_id = P.cat_id AND P.blog_id = '".$this->con->escape($this->id)."' ) ". 
    340           "WHERE C.blog_id = '".$this->con->escape($this->id)."' "; 
    341            
    342           if (!$this->core->auth->userID()) { 
    343                $strReq .= 'AND P.post_status = 1 '; 
    344           } 
    345            
    346           if (!empty($params['post_type'])) { 
    347                $strReq .= 'AND P.post_type '.$this->con->in($params['post_type']); 
    348           } 
    349            
    350           $strReq .= 'GROUP BY C.cat_id '; 
    351            
    352           $rs = $this->con->select($strReq); 
    353           $counters = array(); 
    354           while ($rs->fetch()) { 
    355                $counters[$rs->cat_id] = $rs->nb_post; 
    356           } 
    357            
    358           return $counters; 
    359      } 
    360       
    361      /** 
    362      Creates a new category. Takes a cursor as input and returns the new category 
    363      ID. 
    364       
    365      @param    cur       <b>cursor</b>       Category cursor 
    366      @return   <b>integer</b>      New category ID 
    367      */ 
    368      public function addCategory($cur,$parent=0) 
    369      { 
    370           if (!$this->core->auth->check('categories',$this->id)) { 
    371                throw new Exception(__('You are not allowed to add categories')); 
    372           } 
    373            
    374           $url = array(); 
    375           if ($parent != 0) 
    376           { 
    377                $rs = $this->getCategory($parent); 
    378                if ($rs->isEmpty()) { 
    379                     $url = array(); 
    380                } else { 
    381                     $url[] = $rs->cat_url; 
    382                } 
    383           } 
    384            
    385           if ($cur->cat_url == '') { 
    386                $url[] = text::tidyURL($cur->cat_title,false); 
    387           } else { 
    388                $url[] = $cur->cat_url; 
    389           } 
    390            
    391           $cur->cat_url = implode('/',$url); 
    392            
    393           $this->getCategoryCursor($cur); 
    394           $cur->blog_id = (string) $this->id; 
    395            
    396           # --BEHAVIOR-- coreBeforeCategoryCreate 
    397           $this->core->callBehavior('coreBeforeCategoryCreate',$this,$cur); 
    398            
    399           $this->categories()->addNode($cur,$parent); 
    400            
    401           # --BEHAVIOR-- coreAfterCategoryCreate 
    402           $this->core->callBehavior('coreAfterCategoryCreate',$this,$cur); 
    403           $this->triggerBlog(); 
    404            
    405           return $cur->cat_id; 
    406      } 
    407       
    408      /** 
    409      Updates an existing category. 
    410       
    411      @param    id        <b>integer</b>      Category ID 
    412      @param    cur       <b>cursor</b>       Category cursor 
    413      */ 
    414      public function updCategory($id,$cur) 
    415      { 
    416           if (!$this->core->auth->check('categories',$this->id)) { 
    417                throw new Exception(__('You are not allowed to update categories')); 
    418           } 
    419            
    420           if ($cur->cat_url == '') 
    421           { 
    422                $url = array(); 
    423                $rs = $this->categories()->getParents($id); 
    424                while ($rs->fetch()) { 
    425                     if ($rs->index() == $rs->count()-1) { 
    426                          $url[] = $rs->cat_url; 
    427                     } 
    428                } 
    429                 
    430                 
    431                $url[] = text::tidyURL($cur->cat_title,false); 
    432                $cur->cat_url = implode('/',$url); 
    433           } 
    434            
    435           $this->getCategoryCursor($cur,$id); 
    436            
    437           # --BEHAVIOR-- coreBeforeCategoryUpdate 
    438           $this->core->callBehavior('coreBeforeCategoryUpdate',$this,$cur); 
    439            
    440           $cur->update( 
    441           'WHERE cat_id = '.(integer) $id.' '. 
    442           "AND blog_id = '".$this->con->escape($this->id)."' "); 
    443            
    444           # --BEHAVIOR-- coreAfterCategoryUpdate 
    445           $this->core->callBehavior('coreAfterCategoryUpdate',$this,$cur); 
    446            
    447           $this->triggerBlog(); 
    448      } 
    449       
    450      /** 
    451      DEPRECATED METHOD. Use dcBlog::setCategoryParent and dcBlog::moveCategory 
    452      instead. 
    453       
    454      @param    id        <b>integer</b>      Category ID 
    455      @param    order     <b>integer</b>      Category position 
    456      */ 
    457      public function updCategoryOrder($id,$order) 
    458      { 
    459           return; 
    460      } 
    461       
    462      /** 
    463      Set a category parent 
    464       
    465      @param    id        <b>integer</b>      Category ID 
    466      @param    parent    <b>integer</b>      Parent Category ID 
    467      */ 
    468      public function setCategoryParent($id,$parent) 
    469      { 
    470           $this->categories()->setNodeParent($id,$parent); 
    471           $this->triggerBlog(); 
    472      } 
    473       
    474      /** 
    475      Set category position 
    476       
    477      @param    id        <b>integer</b>      Category ID 
    478      @param    sibling   <b>integer</b>      Sibling Category ID 
    479      @param    move      <b>integer</b>      Order (before|after) 
    480      */ 
    481      public function setCategoryPosition($id,$sibling,$move) 
    482      { 
    483           $this->categories()->setNodePosition($id,$sibling,$move); 
    484           $this->triggerBlog(); 
    485      } 
    486       
    487      /** 
    488      Deletes a category. 
    489       
    490      @param    id        <b>integer</b>      Category ID 
    491      */ 
    492      public function delCategory($id) 
    493      { 
    494           if (!$this->core->auth->check('categories',$this->id)) { 
    495                throw new Exception(__('You are not allowed to delete categories')); 
    496           } 
    497            
    498           $strReq = 'SELECT COUNT(post_id) AS nb_post '. 
    499                     'FROM '.$this->prefix.'post '. 
    500                     'WHERE cat_id = '.(integer) $id.' '. 
    501                     "AND blog_id = '".$this->con->escape($this->id)."' "; 
    502            
    503           $rs = $this->con->select($strReq); 
    504            
    505           if ($rs->nb_post > 0) { 
    506                throw new Exception(__('This category is not empty.')); 
    507           } 
    508            
    509           $this->categories()->deleteNode($id,true); 
    510           $this->triggerBlog(); 
    511      } 
    512       
    513      /** 
    514      Reset categories order and relocate them to first level 
    515      */ 
    516      public function resetCategoriesOrder() 
    517      { 
    518           if (!$this->core->auth->check('categories',$this->id)) { 
    519                throw new Exception(__('You are not allowed to reset categories order')); 
    520           } 
    521            
    522           $this->categories()->resetOrder(); 
    523           $this->triggerBlog(); 
    524      } 
    525       
    526      private function checkCategory($title,$url,$id=null) 
    527      { 
    528           $strReq = 'SELECT cat_id '. 
    529                     'FROM '.$this->prefix.'category '. 
    530                     "WHERE cat_url = '".$this->con->escape($url)."' ". 
    531                     "AND blog_id = '".$this->con->escape($this->id)."' "; 
    532            
    533           if ($id !== null) { 
    534                $strReq .= 'AND cat_id <> '.(integer) $id.' '; 
    535           } 
    536            
    537           $rs = $this->con->select($strReq); 
    538            
    539           if (!$rs->isEmpty()) { 
    540                throw new Exception(__('Category URL must be unique.')); 
    541           } 
    542      } 
    543       
    544      private function getCategoryCursor($cur,$id=null) 
    545      { 
    546           if ($cur->cat_title == '') { 
    547                throw new Exception(__('You must provide a category title')); 
    548           } 
    549            
    550           # If we don't have any cat_url, let's do one 
    551           if ($cur->cat_url == '') { 
    552                $cur->cat_url = text::tidyURL($cur->cat_title,false); 
    553           } 
    554            
    555           # Still empty ? 
    556           if ($cur->cat_url == '') { 
    557                throw new Exception(__('You must provide a category URL')); 
    558           } else { 
    559                $cur->cat_url = text::tidyURL($cur->cat_url,true); 
    560           } 
    561            
    562           # Check if title or url are unique 
    563           $this->checkCategory($cur->cat_title,$cur->cat_url,$id); 
    564            
    565           if ($cur->cat_desc !== null) { 
    566                $cur->cat_desc = $this->core->HTMLfilter($cur->cat_desc); 
    567           } 
    568      } 
    569      //@} 
    570169      
    571170     /// @name Entries management methods 
     
    580179     - post_url: Get entry with given post_url field 
    581180     - user_id: (integer) Get entries belonging to given user ID 
    582      - cat_id: (string or array) Get entries belonging to given category ID 
    583      - cat_id_not: deprecated (use cat_id with "id ?not" instead) 
    584      - cat_url: (string or array) Get entries belonging to given category URL 
    585      - cat_url_not: deprecated (use cat_url with "url ?not" instead) 
    586181     - post_status: (integer) Get entries with given post_status 
    587182     - post_selected: (boolean) Get select flaged entries 
     
    598193     - sql_only : return the sql request instead of results. Only ids are selected 
    599194      
    600      Please note that on every cat_id or cat_url, you can add ?not to exclude 
    601      the category and ?sub to get subcategories. 
    602       
    603195     @param    params         <b>array</b>        Parameters 
    604196     @param    count_only     <b>boolean</b>      Only counts results 
     
    634226                
    635227               $strReq = 
    636                'SELECT P.post_id, P.blog_id, P.user_id, P.cat_id, post_dt, '. 
     228               'SELECT P.post_id, P.blog_id, P.user_id, post_dt, '. 
    637229               'post_tz, post_creadt, post_upddt, post_format, post_password, '. 
    638230               'post_url, post_lang, post_title, '.$content_req. 
    639231               'post_type, post_meta, post_status, post_selected, post_position, '. 
    640232               'U.user_name, U.user_firstname, U.user_displayname, U.user_email, '. 
    641                'U.user_url, '. 
    642                'C.cat_title, C.cat_url, C.cat_desc '; 
     233               'U.user_url '; 
    643234          } 
    644235           
    645236          $strReq .= 
    646237          'FROM '.$this->prefix.'post P '. 
    647           'INNER JOIN '.$this->prefix.'user U ON U.user_id = P.user_id '. 
    648           'LEFT OUTER JOIN '.$this->prefix.'category C ON P.cat_id = C.cat_id '; 
     238          'INNER JOIN '.$this->prefix.'user U ON U.user_id = P.user_id '; 
    649239           
    650240          if (!empty($params['from'])) { 
     
    697287          if (!empty($params['user_id'])) { 
    698288               $strReq .= "AND U.user_id = '".$this->con->escape($params['user_id'])."' "; 
    699           } 
    700            
    701           if (isset($params['cat_id']) && $params['cat_id'] !== '') 
    702           { 
    703                if (!is_array($params['cat_id'])) { 
    704                     $params['cat_id'] = array($params['cat_id']); 
    705                } 
    706                if (!empty($params['cat_id_not'])) { 
    707                     array_walk($params['cat_id'],create_function('&$v,$k','$v=$v." ?not";')); 
    708                } 
    709                $strReq .= 'AND '.$this->getPostsCategoryFilter($params['cat_id'],'cat_id').' '; 
    710           } 
    711           elseif (isset($params['cat_url']) && $params['cat_url'] !== '') 
    712           { 
    713                if (!is_array($params['cat_url'])) { 
    714                     $params['cat_url'] = array($params['cat_url']); 
    715                } 
    716                if (!empty($params['cat_url_not'])) { 
    717                     array_walk($params['cat_url'],create_function('&$v,$k','$v=$v." ?not";')); 
    718                } 
    719                $strReq .= 'AND '.$this->getPostsCategoryFilter($params['cat_url'],'cat_url').' '; 
    720289          } 
    721290           
     
    808377     @param    post_id                  <b>integer</b>      Post ID 
    809378     @param    dir                      <b>integer</b>      Search direction 
    810      @param    restrict_to_category     <b>boolean</b>      Restrict to post with same category 
    811379     @param    restrict_to_lang         <b>boolean</b>      Restrict to post with same lang 
    812380     @return   record 
    813381     */ 
    814      public function getNextPost($post,$dir,$restrict_to_category=false, $restrict_to_lang=false) 
     382     public function getNextPost($post, $dir, $restrict_to_lang=false) 
    815383     { 
    816384          $dt = $post->post_dt; 
     
    835403          ') '; 
    836404           
    837           if ($restrict_to_category) { 
    838                $params['sql'] .= $post->cat_id ? 'AND P.cat_id = '.(integer) $post->cat_id.' ' : 'AND P.cat_id IS NULL '; 
    839           } 
    840            
    841405          if ($restrict_to_lang) { 
    842406               $params['sql'] .= $post->post_lang ? 'AND P.post_lang = \''. $this->con->escape($post->post_lang) .'\' ': 'AND P.post_lang IS NULL '; 
     
    918482     - month: (integer) Get dates for given month 
    919483     - day: (integer) Get dates for given day 
    920      - cat_id: (integer) Category ID filter 
    921      - cat_url: Category URL filter 
    922484     - post_lang: lang of the posts 
    923485     - next: Get date following match 
     
    946508          $cat_field = $catReq = $limit = ''; 
    947509           
    948           if (isset($params['cat_id']) && $params['cat_id'] !== '') { 
    949                $catReq = 'AND P.cat_id = '.(integer) $params['cat_id'].' '; 
    950                $cat_field = ', C.cat_url '; 
    951           } elseif (isset($params['cat_url']) && $params['cat_url'] !== '') { 
    952                $catReq = "AND C.cat_url = '".$this->con->escape($params['cat_url'])."' "; 
    953                $cat_field = ', C.cat_url '; 
    954           } 
    955510          if (!empty($params['post_lang'])) { 
    956511               $catReq = 'AND P.post_lang = \''. $params['post_lang'].'\' '; 
     
    958513           
    959514          $strReq = 'SELECT DISTINCT('.$this->con->dateFormat('post_dt',$dt_f).') AS dt '. 
    960                     $cat_field. 
    961515                    ',COUNT(P.post_id) AS nb_post '. 
    962                     'FROM '.$this->prefix.'post P LEFT JOIN '.$this->prefix.'category C '. 
    963                     'ON P.cat_id = C.cat_id '. 
     516                    'FROM '.$this->prefix.'post P '. 
    964517                    "WHERE P.blog_id = '".$this->con->escape($this->id)."' ". 
    965518                    $catReq; 
     
    1017570          } 
    1018571           
    1019           $strReq .= 'GROUP BY dt '.$cat_field; 
    1020            
    1021572          $order = 'desc'; 
    1022573          if (!empty($params['order']) && preg_match('/^(desc|asc)$/i',$params['order'])) { 
     
    1196747     public function updPostSelected($id,$selected) 
    1197748     { 
    1198           if (!$this->core->auth->check('usage,contentadmin',$this->id)) { 
    1199                throw new Exception(__('You are not allowed to change this entry category')); 
    1200           } 
    1201            
    1202749          $id = (integer) $id; 
    1203750          $selected = (boolean) $selected; 
     
    1222769           
    1223770          $cur->post_selected = (integer) $selected; 
    1224           $cur->post_upddt = date('Y-m-d H:i:s'); 
    1225            
    1226           $cur->update( 
    1227                'WHERE post_id = '.$id.' '. 
    1228                "AND blog_id = '".$this->con->escape($this->id)."' " 
    1229           ); 
    1230           $this->triggerBlog(); 
    1231      } 
    1232       
    1233      /** 
    1234      Updates post category. <var>$cat_id</var> can be null. 
    1235       
    1236      @param    id        <b>integer</b>      Post ID 
    1237      @param    cat_id    <b>integer</b>      Category ID 
    1238      */ 
    1239      public function updPostCategory($id,$cat_id) 
    1240      { 
    1241           if (!$this->core->auth->check('usage,contentadmin',$this->id)) { 
    1242                throw new Exception(__('You are not allowed to change this entry category')); 
    1243           } 
    1244            
    1245           $id = (integer) $id; 
    1246           $cat_id = (integer) $cat_id; 
    1247            
    1248           # If user is only usage, we need to check the post's owner 
    1249           if (!$this->core->auth->check('contentadmin',$this->id)) 
    1250           { 
    1251                $strReq = 'SELECT post_id '. 
    1252                          'FROM '.$this->prefix.'post '. 
    1253                          'WHERE post_id = '.$id.' '. 
    1254                          "AND blog_id = '".$this->con->escape($this->id)."' ". 
    1255                          "AND user_id = '".$this->con->escape($this->core->auth->userID())."' "; 
    1256                 
    1257                $rs = $this->con->select($strReq); 
    1258                 
    1259                if ($rs->isEmpty()) { 
    1260                     throw new Exception(__('You are not allowed to change this entry category')); 
    1261                } 
    1262           } 
    1263            
    1264           $cur = $this->con->openCursor($this->prefix.'post'); 
    1265            
    1266           $cur->cat_id = ($cat_id ? $cat_id : null); 
    1267771          $cur->post_upddt = date('Y-m-d H:i:s'); 
    1268772           
     
    1390894     } 
    1391895      
    1392      private function getPostsCategoryFilter($arr,$field='cat_id') 
    1393      { 
    1394           $field = $field == 'cat_id' ? 'cat_id' : 'cat_url'; 
    1395            
    1396           $sub = array(); 
    1397           $not = array(); 
    1398           $queries = array(); 
    1399            
    1400           foreach ($arr as $v) 
    1401           { 
    1402                $v = trim($v); 
    1403                $args = preg_split('/\s*[?]\s*/',$v,-1,PREG_SPLIT_NO_EMPTY); 
    1404                $id = array_shift($args); 
    1405                $args = array_flip($args); 
    1406                 
    1407                if (isset($args['not'])) { $not[$id] = 1; } 
    1408                if (isset($args['sub'])) { $sub[$id] = 1; } 
    1409                if ($field == 'cat_id') { 
    1410                     if (preg_match('/^null$/i',$id)) { 
    1411                          $queries[$id] = 'P.cat_id IS NULL'; 
    1412                     } 
    1413                     else { 
    1414                          $queries[$id] = 'P.cat_id = '.(integer) $id; 
    1415                     } 
    1416                } else { 
    1417                     $queries[$id] = "C.cat_url = '".$this->con->escape($id)."' "; 
    1418                } 
    1419           } 
    1420            
    1421           if (!empty($sub)) { 
    1422                $rs = $this->con->select( 
    1423                     'SELECT cat_id, cat_url, cat_lft, cat_rgt FROM '.$this->prefix.'category '. 
    1424                     "WHERE blog_id = '".$this->con->escape($this->id)."' ". 
    1425                     'AND '.$field.' '.$this->con->in(array_keys($sub)) 
    1426                ); 
    1427                 
    1428                while ($rs->fetch()) { 
    1429                     $queries[$rs->f($field)] = '(C.cat_lft BETWEEN '.$rs->cat_lft.' AND '.$rs->cat_rgt.')'; 
    1430                } 
    1431           } 
    1432            
    1433           # Create queries 
    1434           $sql = array( 
    1435                0 => array(), # wanted categories 
    1436                1 => array()  # excluded categories 
    1437           ); 
    1438            
    1439           foreach ($queries as $id => $q) { 
    1440                $sql[(integer) isset($not[$id])][] = $q; 
    1441           } 
    1442            
    1443           $sql[0] = implode(' OR ',$sql[0]); 
    1444           $sql[1] = implode(' OR ',$sql[1]); 
    1445            
    1446           if ($sql[0]) { 
    1447                $sql[0] = '('.$sql[0].')'; 
    1448           } else { 
    1449                unset($sql[0]); 
    1450           } 
    1451            
    1452           if ($sql[1]) { 
    1453                $sql[1] = '(P.cat_id IS NULL OR NOT('.$sql[1].'))'; 
    1454           } else { 
    1455                unset($sql[1]); 
    1456           } 
    1457            
    1458           return implode(' AND ',$sql); 
    1459      } 
    1460       
    1461896     private function getPostCursor($cur,$post_id=null) 
    1462897     { 
  • inc/core/class.dc.rs.extensions.php

    r848 r851  
    130130      
    131131     /** 
    132      Returns full post category URL. 
    133       
    134      @param    rs   Invisible parameter 
    135      @return   <b>string</b> 
    136      */ 
    137      public static function getCategoryURL($rs) 
    138      { 
    139           return $rs->core->blog->url.$rs->core->url->getURLFor('category',html::sanitizeURL($rs->cat_url)); 
    140      } 
    141       
    142      /** 
    143132     Returns whether post has an excerpt. 
    144133      
  • inc/core/class.dc.xmlrpc.php

    r848 r851  
    7575               'List of most recent posts in the system'); 
    7676           
    77           $this->addCallback('metaWeblog.getCategories',array($this,'mw_getCategories'), 
    78                array('array','string','string','string'), 
    79                'List of all categories defined in the weblog'); 
    80            
    8177          $this->addCallback('metaWeblog.newMediaObject',array($this,'mw_newMediaObject'), 
    8278               array('struct','string','string','string','struct'), 
     
    8884               'List of most recent posts in the system'); 
    8985           
    90           $this->addCallback('mt.getCategoryList',array($this,'mt_getCategoryList'), 
    91                array('array','string','string','string'), 
    92                'List of all categories defined in the weblog'); 
    93            
    94           $this->addCallback('mt.getPostCategories',array($this,'mt_getPostCategories'), 
    95                array('array','string','string','string'), 
    96                'List of all categories to which the post is assigned'); 
    97            
    98           $this->addCallback('mt.setPostCategories',array($this,'mt_setPostCategories'), 
    99                array('boolean','string','string','string','array'), 
    100                'Sets the categories for a post'); 
    101            
    10286          $this->addCallback('mt.publishPost',array($this,'mt_publishPost'), 
    10387               array('boolean','string','string','string'), 
     
    143127               'Get an array of users for the blog.'); 
    144128           
    145           $this->addCallback('wp.getCategories',array($this,'wp_getCategories'), 
    146                array('array','integer','string','string'), 
    147                'Get an array of available categories on a blog.'); 
    148            
    149129          $this->addCallback('wp.getTags',array($this,'wp_getTags'), 
    150130               array('array','integer','string','string'), 
    151131               'Get list of all tags for the blog.'); 
    152            
    153           $this->addCallback('wp.newCategory',array($this,'wp_newCategory'), 
    154                array('integer','integer','string','string','struct'), 
    155                'Create a new category.'); 
    156            
    157           $this->addCallback('wp.deleteCategory',array($this,'wp_deleteCategory'), 
    158                array('boolean','integer','string','string','integer'), 
    159                'Delete a category with a given ID.'); 
    160            
    161           $this->addCallback('wp.suggestCategories',array($this,'wp_suggestCategories'), 
    162                array('array','integer','string','string','string','integer'), 
    163                'Get an array of categories that start with a given string.'); 
    164132           
    165133          $this->addCallback('wp.uploadFile',array($this,'wp_uploadFile'), 
     
    288256           
    289257          return $rs; 
    290      } 
    291       
    292      private function getCatID($cat_url) 
    293      { 
    294           $rs = $this->core->blog->getCategories(array('cat_url' => $cat_url)); 
    295            
    296           return $rs->isEmpty() ? null : $rs->cat_id; 
    297258     } 
    298259      
     
    344305          } 
    345306           
    346           # Categories in an array 
    347           if (isset($struct['categories']) && is_array($struct['categories'])) 
    348           { 
    349                $categories = $struct['categories']; 
    350                $cat_id = !empty($categories[0]) ? $categories[0] : null; 
    351                 
    352                $cur->cat_id = $this->getCatID($cat_id); 
    353           } 
    354            
    355307          if (isset($struct['wp_slug'])) { 
    356308               $cur->post_url = $struct['wp_slug']; 
     
    448400          } 
    449401           
    450           # Categories in an array 
    451           if (isset($struct['categories']) && is_array($struct['categories'])) 
    452           { 
    453                $categories = $struct['categories']; 
    454                $cat_id = !empty($categories[0]) ? $categories[0] : null; 
    455                 
    456                $cur->cat_id = $this->getCatID($cat_id); 
    457           } 
    458            
    459402          if (isset($struct['wp_slug'])) { 
    460403               $cur->post_url = $struct['wp_slug']; 
     
    504447          $res['userid'] = $post->user_id; 
    505448          $res['postid'] = $post->post_id; 
    506            
    507           if ($post->cat_id) { 
    508                $res['categories'] = array($post->cat_url); 
    509           } 
    510449           
    511450          if ($type == 'blogger') { 
     
    566505               $tres['userid'] = $posts->user_id; 
    567506               $tres['postid'] = $posts->post_id; 
    568                 
    569                if ($posts->cat_id) { 
    570                     $tres['categories'] = array($posts->cat_url); 
    571                } 
    572507                
    573508               if ($type == 'blogger') { 
     
    621556               'url' => $this->core->auth->getInfo('user_url') 
    622557          ); 
    623      } 
    624       
    625      private function getCategories($blog_id,$user,$pwd) 
    626      { 
    627           $this->setUser($user,$pwd); 
    628           $this->setBlog(); 
    629           $rs = $this->core->blog->getCategories(); 
    630            
    631           $res = array(); 
    632            
    633           $l = $rs->level; 
    634           $stack = array('',$rs->cat_url); 
    635            
    636           while ($rs->fetch()) 
    637           { 
    638                $d = $rs->level - $l; 
    639                if ($d == 0) { 
    640                     array_pop($stack); 
    641                     $parent = end($stack); 
    642                } elseif ($d > 0) { 
    643                     $parent = end($stack); 
    644                } elseif ($d < 0) { 
    645                     $D = abs($d); 
    646                     for ($i=0; $i<=$D; $i++) { 
    647                          array_pop($stack); 
    648                     } 
    649                     $parent = end($stack); 
    650                } 
    651                 
    652                $res[] = array( 
    653                     'categoryId' => $rs->cat_url, 
    654                     'parentId' => $parent, 
    655                     'description' => $rs->cat_title, 
    656                     'categoryName' => $rs->cat_url, 
    657                     'htmlUrl' => $this->core->blog->url. 
    658                          $this->core->url->getURLFor('category',$rs->cat_url), 
    659                     'rssUrl' => $this->core->blog->url. 
    660                          $this->core->url->getURLFor('feed','category/'.$rs->cat_url.'/rss2') 
    661                ); 
    662                 
    663                $stack[] = $rs->cat_url; 
    664                $l = $rs->level; 
    665           } 
    666            
    667           return $res; 
    668      } 
    669       
    670      private function getPostCategories($post_id,$user,$pwd) 
    671      { 
    672           $post_id = (integer) $post_id; 
    673            
    674           $post = $this->getPostRS($post_id,$user,$pwd); 
    675            
    676           return array( 
    677                array( 
    678                'categoryName' => $post->cat_url, 
    679                'categoryId' => (string) $post->cat_url, 
    680                'isPrimary' => true 
    681                ) 
    682           ); 
    683      } 
    684       
    685      private function setPostCategories($post_id,$user,$pwd,$categories) 
    686      { 
    687           $post_id = (integer) $post_id; 
    688            
    689           $post = $this->getPostRS($post_id,$user,$pwd); 
    690            
    691           $cat_id = (!empty($categories[0]['categoryId'])) ? $categories[0]['categoryId'] : null; 
    692            
    693           foreach($categories as $v) 
    694           { 
    695                if (isset($v['isPrimary']) && $v['isPrimary']) { 
    696                     $cat_id = $v['categoryId']; 
    697                     break; 
    698                } 
    699           } 
    700            
    701           # w.bloggar sends -1 for no category. 
    702           if ($cat_id == -1) { 
    703                $cat_id = null; 
    704           } 
    705            
    706           if ($cat_id) { 
    707                $cat_id = $this->getCatID($cat_id); 
    708           } 
    709            
    710           $this->core->blog->updPostCategory($post_id,(integer) $cat_id); 
    711            
    712           return true; 
    713558     } 
    714559      
     
    929774                    "link"                   => $posts->getURL(), 
    930775                    "permaLink"              => $posts->getURL(), 
    931                     "categories"             => array(), 
    932776                    "excerpt"                => $posts->post_excerpt_xhtml, 
    933777                    "text_more"              => '', 
     
    1036880     } 
    1037881      
    1038      private function newCategory($user,$pwd,$struct) 
    1039      { 
    1040           $this->setUser($user,$pwd); 
    1041           $this->setBlog(); 
    1042            
    1043           if (empty($struct['name'])) { 
    1044                throw new Exception('You mus give a category name.'); 
    1045           } 
    1046            
    1047           $cur = $this->core->con->openCursor($this->core->prefix.'category'); 
    1048           $cur->cat_title = $struct['name']; 
    1049            
    1050           if (!empty($struct['slug'])) { 
    1051                $cur->cat_url = $struct['slug']; 
    1052           } 
    1053           if (!empty($struct['category_description'])) { 
    1054                $cur->cat_desc = $struct['category_description']; 
    1055                if (html::clean($cur->cat_desc) == $cur->cat_desc) { 
    1056                     $cur->cat_desc = '<p>'.$cur->cat_desc.'</p>'; 
    1057                } 
    1058           } 
    1059            
    1060           $parent = !empty($struct['category_parent']) ? (integer) $struct['category_parent'] : 0; 
    1061            
    1062           $id = $this->core->blog->addCategory($cur,$parent); 
    1063           $rs = $this->core->blog->getCategory($id); 
    1064           return $rs->cat_url; 
    1065      } 
    1066       
    1067      private function deleteCategory($user,$pwd,$cat_id) 
    1068      { 
    1069           $this->setUser($user,$pwd); 
    1070           $this->setBlog(); 
    1071            
    1072           $c = $this->core->blog->getCategories(array('cat_url' => $cat_id)); 
    1073           if ($c->isEmpty()) { 
    1074                throw new Exception(__('This category does not exist.')); 
    1075           } 
    1076           $cat_id = $c->cat_id; 
    1077           unset($c); 
    1078            
    1079           $this->core->blog->delCategory((integer) $cat_id); 
    1080           return true; 
    1081      } 
    1082       
    1083      private function searchCategories($user,$pwd,$category,$limit) 
    1084      { 
    1085           $this->setUser($user,$pwd); 
    1086           $this->setBlog(); 
    1087            
    1088           $strReq = 'SELECT cat_id, cat_title, cat_url '. 
    1089                     'FROM '.$this->core->prefix.'category '. 
    1090                     "WHERE blog_id = '".$this->core->con->escape($this->core->blog->id)."' ". 
    1091                     "AND LOWER(cat_title) LIKE LOWER('%".$this->core->con->escape($category)."%') ". 
    1092                     ($limit > 0 ? $this->core->con->limit($limit) : ''); 
    1093            
    1094           $rs = $this->core->con->select($strReq); 
    1095            
    1096           $res = array(); 
    1097           while ($rs->fetch()) 
    1098           { 
    1099                $res[] = array( 
    1100                     'category_id' => $rs->cat_url, 
    1101                     'category_name' => $rs->cat_url 
    1102                ); 
    1103           } 
    1104           return $res; 
    1105      } 
    1106       
    1107882     /* Blogger methods 
    1108883     --------------------------------------------------- */ 
     
    1165940     } 
    1166941      
    1167      public function mw_getCategories($blogid,$username,$password) 
    1168      { 
    1169           return $this->getCategories($blogid,$username,$password); 
    1170      } 
    1171       
    1172942     public function mw_newMediaObject($blogid,$username,$password,$file) 
    1173943     { 
     
    1180950     { 
    1181951          return $this->getRecentPosts($blogid,$username,$password,$numberOfPosts,'mt'); 
    1182      } 
    1183       
    1184      public function mt_getCategoryList($blogid,$username,$password) 
    1185      { 
    1186           return $this->getCategories($blogid,$username,$password); 
    1187      } 
    1188       
    1189      public function mt_getPostCategories($postid,$username,$password) 
    1190      { 
    1191           return $this->getPostCategories($postid,$username,$password); 
    1192      } 
    1193       
    1194      public function mt_setPostCategories($postid,$username,$password,$categories) 
    1195      { 
    1196           return $this->setPostCategories($postid,$username,$password,$categories); 
    1197952     } 
    1198953      
     
    12661021     } 
    12671022      
    1268      public function wp_getCategories($blogid,$username,$password) 
    1269      { 
    1270           return $this->getCategories($blogid,$username,$password); 
    1271      } 
    1272       
    12731023     public function wp_getTags($blogid,$username,$password) 
    12741024     { 
    12751025          return $this->getTags($username,$password); 
    1276      } 
    1277       
    1278      public function wp_newCategory($blogid,$username,$password,$content) 
    1279      { 
    1280           return $this->newCategory($username,$password,$content); 
    1281      } 
    1282       
    1283      public function wp_deleteCategory($blogid,$username,$password,$categoryid) 
    1284      { 
    1285           return $this->deleteCategory($username,$password,$categoryid); 
    1286      } 
    1287       
    1288      public function wp_suggestCategories($blogid,$username,$password,$category,$max_results=0) 
    1289      { 
    1290           return $this->searchCategories($username,$password,$category,$max_results); 
    12911026     } 
    12921027      
  • inc/dbschema/db-schema.php

    r848 r851  
    2929      
    3030     ->primary('pk_blog','blog_id') 
    31      ; 
    32  
    33 $_s->category 
    34      ->cat_id       ('bigint',     0,   false) 
    35      ->blog_id      ('varchar',    32,  false) 
    36      ->cat_title    ('varchar',    255, false) 
    37      ->cat_url      ('varchar',    255, false) 
    38      ->cat_desc     ('text',       0,   true) 
    39      ->cat_position ('integer',    0,   true,     0) 
    40      ->cat_lft      ('integer',    0,   true) 
    41      ->cat_rgt      ('integer',    0,   true) 
    42       
    43      ->primary('pk_category','cat_id') 
    44       
    45      ->unique('uk_cat_url','cat_url','blog_id') 
    4631     ; 
    4732 
     
    10287     ->blog_id                ('varchar',    32,  false) 
    10388     ->user_id                ('varchar',    32,  false) 
    104      ->cat_id                 ('bigint',     0,   true) 
    10589     ->post_dt                ('timestamp',  0,   false,    'now()') 
    10690     ->post_tz                ('varchar',    128, false,    "'UTC'") 
     
    192176/* References indexes 
    193177-------------------------------------------------------- */ 
    194 $_s->category->index     ('idx_category_blog_id',           'btree',  'blog_id'); 
    195 $_s->category->index     ('idx_category_cat_lft_blog_id',   'btree',  'blog_id', 'cat_lft'); 
    196 $_s->category->index     ('idx_category_cat_rgt_blog_id',   'btree',  'blog_id', 'cat_rgt'); 
    197178$_s->setting->index      ('idx_setting_blog_id',            'btree',  'blog_id'); 
    198179$_s->user->index         ('idx_user_user_default_blog',     'btree',  'user_default_blog'); 
    199180$_s->permissions->index  ('idx_permissions_blog_id',        'btree',  'blog_id'); 
    200 $_s->post->index         ('idx_post_cat_id',                'btree',  'cat_id'); 
    201181$_s->post->index         ('idx_post_user_id',               'btree',  'user_id'); 
    202182$_s->post->index         ('idx_post_blog_id',               'btree',  'blog_id'); 
     
    220200/* Foreign keys 
    221201-------------------------------------------------------- */ 
    222 $_s->category->reference('fk_category_blog','blog_id','blog','blog_id','cascade','cascade'); 
    223202$_s->setting->reference('fk_setting_blog','blog_id','blog','blog_id','cascade','cascade'); 
    224203$_s->user->reference('fk_user_default_blog','user_default_blog','blog','blog_id','cascade','set null'); 
    225204$_s->permissions->reference('fk_permissions_blog','blog_id','blog','blog_id','cascade','cascade'); 
    226205$_s->permissions->reference('fk_permissions_user','user_id','user','user_id','cascade','cascade'); 
    227 $_s->post->reference('fk_post_category','cat_id','category','cat_id','cascade','set null'); 
    228206$_s->post->reference('fk_post_user','user_id','user','user_id','cascade','cascade'); 
    229207$_s->post->reference('fk_post_blog','blog_id','blog','blog_id','cascade','cascade'); 
  • inc/prepend.php

    r848 r851  
    2929$__autoload['dcAuth']                   = dirname(__FILE__).'/core/class.dc.auth.php'; 
    3030$__autoload['dcBlog']                   = dirname(__FILE__).'/core/class.dc.blog.php'; 
    31 $__autoload['dcCategories']             = dirname(__FILE__).'/core/class.dc.categories.php'; 
    3231$__autoload['dcError']                  = dirname(__FILE__).'/core/class.dc.error.php'; 
    3332$__autoload['dcMeta']                   = dirname(__FILE__).'/core/class.dc.meta.php'; 
     
    202201$core->url->register('post','post','^post/(.+)$',array('dcUrlHandlers','post')); 
    203202$core->url->register('preview','preview','^preview/(.+)$',array('dcUrlHandlers','preview')); 
    204 $core->url->register('category','category','^category/(.+)$',array('dcUrlHandlers','category')); 
    205203$core->url->register('archive','archive','^archive(/.+)?$',array('dcUrlHandlers','archive')); 
    206204 
  • inc/public/class.dc.template.php

    r848 r851  
    6868          $this->addValue('BlogMetaRobots',array($this,'BlogMetaRobots')); 
    6969           
    70           # Categories 
    71           $this->addBlock('Categories',array($this,'Categories')); 
    72           $this->addBlock('CategoriesHeader',array($this,'CategoriesHeader')); 
    73           $this->addBlock('CategoriesFooter',array($this,'CategoriesFooter')); 
    74           $this->addBlock('CategoryIf',array($this,'CategoryIf')); 
    75           $this->addBlock('CategoryFirstChildren',array($this,'CategoryFirstChildren')); 
    76           $this->addBlock('CategoryParents',array($this,'CategoryParents')); 
    77           $this->addValue('CategoryFeedURL',array($this,'CategoryFeedURL')); 
    78           $this->addValue('CategoryURL',array($this,'CategoryURL')); 
    79           $this->addValue('CategoryShortURL',array($this,'CategoryShortURL')); 
    80           $this->addValue('CategoryDescription',array($this,'CategoryDescription')); 
    81           $this->addValue('CategoryTitle',array($this,'CategoryTitle')); 
    82            
    8370          # Entries 
    8471          $this->addBlock('DateFooter',array($this,'DateFooter')); 
     
    9582          $this->addValue('EntryAuthorURL',array($this,'EntryAuthorURL')); 
    9683          $this->addValue('EntryBasename',array($this,'EntryBasename')); 
    97           $this->addValue('EntryCategory',array($this,'EntryCategory')); 
    98           $this->addBlock('EntryCategoriesBreadcrumb',array($this,'EntryCategoriesBreadcrumb')); 
    99           $this->addValue('EntryCategoryID',array($this,'EntryCategoryID')); 
    100           $this->addValue('EntryCategoryURL',array($this,'EntryCategoryURL')); 
    101           $this->addValue('EntryCategoryShortURL',array($this,'EntryCategoryShortURL')); 
    10284          $this->addValue('EntryContent',array($this,'EntryContent')); 
    10385          $this->addValue('EntryDate',array($this,'EntryDate')); 
     
    458440     <!ATTLIST tpl:Archives 
    459441     type      (day|month|year)    #IMPLIED  -- Get days, months or years, default to month -- 
    460      category  CDATA               #IMPLIED  -- Get dates of given category -- 
    461442     no_context (1|0)              #IMPLIED  -- Override context information 
    462443     order     (asc|desc)          #IMPLIED  -- Sort asc or desc -- 
     
    473454          } 
    474455           
    475           if (isset($attr['category'])) { 
    476                $p .= "\$params['cat_url'] = '".addslashes($attr['category'])."';\n"; 
    477           } 
    478          
    479456          if (isset($attr['post_type'])) { 
    480457               $p .= "\$params['post_type'] = '".addslashes($attr['post_type'])."';\n"; 
     
    483460          if (isset($attr['post_lang'])) { 
    484461               $p .= "\$params['post_lang'] = '".addslashes($attr['post_lang'])."';\n"; 
    485           } 
    486            
    487           if (empty($attr['no_context']) && !isset($attr['category'])) 
    488           { 
    489                $p .= 
    490                'if ($_ctx->exists("categories")) { '. 
    491                     "\$params['cat_id'] = \$_ctx->categories->cat_id; ". 
    492                "}\n"; 
    493462          } 
    494463           
     
    851820     } 
    852821      
    853      /* Categories ----------------------------------------- */ 
    854       
    855      /*dtd 
    856      <!ELEMENT tpl:Categories - - -- Categories loop --> 
    857      */ 
    858      public function Categories($attr,$content) 
    859      { 
    860           $p = "if (!isset(\$params)) \$params = array();\n"; 
    861            
    862           if (isset($attr['url'])) { 
    863                $p .= "\$params['cat_url'] = '".addslashes($attr['url'])."';\n"; 
    864           } 
    865            
    866           if (!empty($attr['post_type'])) { 
    867                $p .= "\$params['post_type'] = '".addslashes($attr['post_type'])."';\n"; 
    868           } 
    869            
    870           if (!empty($attr['level'])) { 
    871                $p .= "\$params['level'] = ".(integer) $attr['level'].";\n"; 
    872           } 
    873            
    874           $res = "<?php\n"; 
    875           $res .= $p; 
    876           $res .= $this->core->callBehavior("templatePrepareParams",  
    877                array("tag" => "Categories","method" => "blog::getCategories"),  
    878                $attr,$content); 
    879           $res .= '$_ctx->categories = $core->blog->getCategories($params);'."\n"; 
    880           $res .= "?>\n"; 
    881           $res .= '<?php while ($_ctx->categories->fetch()) : ?>'.$content.'<?php endwhile; $_ctx->categories = null; unset($params); ?>'; 
    882            
    883           return $res; 
    884      } 
    885       
    886      /*dtd 
    887      <!ELEMENT tpl:CategoriesHeader - - -- First Categories result container --> 
    888      */ 
    889      public function CategoriesHeader($attr,$content) 
    890      { 
    891           return 
    892           "<?php if (\$_ctx->categories->isStart()) : ?>". 
    893           $content. 
    894           "<?php endif; ?>"; 
    895      } 
    896       
    897      /*dtd 
    898      <!ELEMENT tpl:CategoriesFooter - - -- Last Categories result container --> 
    899      */ 
    900      public function CategoriesFooter($attr,$content) 
    901      { 
    902           return 
    903           "<?php if (\$_ctx->categories->isEnd()) : ?>". 
    904           $content. 
    905           "<?php endif; ?>"; 
    906      } 
    907       
    908      /*dtd 
    909      <!ELEMENT tpl:CategoryIf - - -- tests on current entry --> 
    910      <!ATTLIST tpl:CategoryIf 
    911      url       CDATA     #IMPLIED  -- category has given url 
    912      has_entries    (0|1)     #IMPLIED  -- post is the first post from list (value : 1) or not (value : 0) 
    913      has_description     (0|1)     #IMPLIED  -- category has description (value : 1) or not (value : 0)  
    914      > 
    915      */ 
    916      public function CategoryIf($attr,$content) 
    917      { 
    918           $if = new ArrayObject(); 
    919           $operator = isset($attr['operator']) ? $this->getOperator($attr['operator']) : '&&'; 
    920            
    921           if (isset($attr['url'])) { 
    922                $url = addslashes(trim($attr['url'])); 
    923                if (substr($url,0,1) == '!') { 
    924                     $url = substr($url,1); 
    925                     $if[] = '($_ctx->categories->cat_url != "'.$url.'")'; 
    926                } else { 
    927                     $if[] = '($_ctx->categories->cat_url == "'.$url.'")'; 
    928                } 
    929           } 
    930            
    931           if (isset($attr['has_entries'])) { 
    932                $sign = (boolean) $attr['has_entries'] ? '>' : '=='; 
    933                $if[] = '$_ctx->categories->nb_post '.$sign.' 0'; 
    934           } 
    935            
    936           if (isset($attr['has_description'])) {  
    937                $sign = (boolean) $attr['has_description'] ? '!=' : '==';  
    938                $if[] = '$_ctx->categories->cat_desc '.$sign.' ""';  
    939           }  
    940            
    941           $this->core->callBehavior('tplIfConditions','CategoryIf',$attr,$content,$if); 
    942            
    943           if (count($if) != 0) { 
    944                return '<?php if('.implode(' '.$operator.' ', (array) $if).') : ?>'.$content.'<?php endif; ?>'; 
    945           } else { 
    946                return $content; 
    947           } 
    948      } 
    949       
    950      /*dtd 
    951      <!ELEMENT tpl:CategoryFirstChildren - - -- Current category first children loop --> 
    952      */ 
    953      public function CategoryFirstChildren($attr,$content) 
    954      { 
    955           return 
    956           "<?php\n". 
    957           '$_ctx->categories = $core->blog->getCategoryFirstChildren($_ctx->categories->cat_id);'."\n". 
    958           'while ($_ctx->categories->fetch()) : ?>'.$content.'<?php endwhile; $_ctx->categories = null; ?>'; 
    959      } 
    960       
    961      /*dtd 
    962      <!ELEMENT tpl:CategoryParents - - -- Current category parents loop --> 
    963      */ 
    964      public function CategoryParents($attr,$content) 
    965      { 
    966           return 
    967           "<?php\n". 
    968           '$_ctx->categories = $core->blog->getCategoryParents($_ctx->categories->cat_id);'."\n". 
    969           'while ($_ctx->categories->fetch()) : ?>'.$content.'<?php endwhile; $_ctx->categories = null; ?>'; 
    970      } 
    971       
    972      /*dtd 
    973      <!ELEMENT tpl:CategoryFeedURL - O -- Category feed URL --> 
    974      <!ATTLIST tpl:CategoryFeedURL 
    975      type (rss2|atom)    #IMPLIED  -- feed type (default : rss2) 
    976      > 
    977      */ 
    978      public function CategoryFeedURL($attr) 
    979      { 
    980           $type = !empty($attr['type']) ? $attr['type'] : 'atom'; 
    981            
    982           if (!preg_match('#^(rss2|atom)$#',$type)) { 
    983                $type = 'atom'; 
    984           } 
    985            
    986           $f = $this->getFilters($attr); 
    987           return '<?php echo '.sprintf($f,'$core->blog->url.$core->url->getURLFor("feed","category/".'. 
    988           '$_ctx->categories->cat_url."/'.$type.'")').'; ?>'; 
    989      } 
    990       
    991      /*dtd 
    992      <!ELEMENT tpl:CategoryURL - O -- Category URL (complete iabsolute URL, including blog URL) --> 
    993      */ 
    994      public function CategoryURL($attr) 
    995      { 
    996           $f = $this->getFilters($attr); 
    997           return '<?php echo '.sprintf($f,'$core->blog->url.$core->url->getURLFor("category",'. 
    998                '$_ctx->categories->cat_url)').'; ?>'; 
    999      } 
    1000       
    1001      /*dtd 
    1002      <!ELEMENT tpl:CategoryShortURL - O -- Category short URL (relative URL, from /category/) --> 
    1003      */ 
    1004      public function CategoryShortURL($attr) 
    1005      { 
    1006           $f = $this->getFilters($attr); 
    1007           return '<?php echo '.sprintf($f,'$_ctx->categories->cat_url').'; ?>'; 
    1008      } 
    1009       
    1010      /*dtd 
    1011      <!ELEMENT tpl:CategoryDescription - O -- Category description --> 
    1012      */ 
    1013      public function CategoryDescription($attr) 
    1014      { 
    1015           $f = $this->getFilters($attr); 
    1016           return '<?php echo '.sprintf($f,'$_ctx->categories->cat_desc').'; ?>'; 
    1017      } 
    1018       
    1019      /*dtd 
    1020      <!ELEMENT tpl:CategoryTitle - O -- Category title --> 
    1021      */ 
    1022      public function CategoryTitle($attr) 
    1023      { 
    1024           $f = $this->getFilters($attr); 
    1025           return '<?php echo '.sprintf($f,'$_ctx->categories->cat_title').'; ?>'; 
    1026      } 
    1027       
    1028822     /* Entries -------------------------------------------- */ 
    1029823     /*dtd 
     
    1032826     lastn     CDATA     #IMPLIED  -- limit number of results to specified value 
    1033827     author    CDATA     #IMPLIED  -- get entries for a given user id 
    1034      category  CDATA     #IMPLIED  -- get entries for specific categories only (multiple comma-separated categories can be specified. Use "!" as prefix to exclude a category) 
    1035      no_category    CDATA     #IMPLIED  -- get entries without category 
    1036828     no_context (1|0)    #IMPLIED  -- Override context information 
    1037829     sortby    (title|selected|author|date|id)    #IMPLIED  -- specify entries sort criteria (default : date) (multiple comma-separated sortby can be specified. Use "?asc" or "?desc" as suffix to provide an order for each sorby) 
     
    1072864          } 
    1073865           
    1074           if (isset($attr['category'])) { 
    1075                $p .= "\$params['cat_url'] = '".addslashes($attr['category'])."';\n"; 
    1076                $p .= "context::categoryPostParam(\$params);\n"; 
    1077           } 
    1078            
    1079           if (isset($attr['no_category']) && $attr['no_category']) { 
    1080                $p .= "@\$params['sql'] .= ' AND P.cat_id IS NULL ';\n"; 
    1081                $p .= "unset(\$params['cat_url']);\n"; 
    1082           } 
    1083            
    1084866          if (!empty($attr['type'])) { 
    1085867               $p .= "\$params['post_type'] = preg_split('/\s*,\s*/','".addslashes($attr['type'])."',-1,PREG_SPLIT_NO_EMPTY);\n"; 
     
    1097879                    'if ($_ctx->exists("users")) { '. 
    1098880                         "\$params['user_id'] = \$_ctx->users->user_id; ". 
    1099                     "}\n"; 
    1100                } 
    1101                 
    1102                if (!isset($attr['category']) && (!isset($attr['no_category']) || !$attr['no_category'])) 
    1103                { 
    1104                     $p .= 
    1105                     'if ($_ctx->exists("categories")) { '. 
    1106                          "\$params['cat_id'] = \$_ctx->categories->cat_id; ". 
    1107881                    "}\n"; 
    1108882               } 
     
    1185959     <!ATTLIST tpl:EntryIf 
    1186960     type CDATA     #IMPLIED  -- post has a given type (default: "post") 
    1187      category  CDATA     #IMPLIED  -- post has a given category 
    1188961     first     (0|1)     #IMPLIED  -- post is the first post from list (value : 1) or not (value : 0) 
    1189962     odd  (0|1)     #IMPLIED  -- post is in an odd position (value : 1) or not (value : 0) 
     
    1191964     extended  (0|1)     #IMPLIED  -- post has an excerpt (value : 1) or not (value : 0) 
    1192965     selected  (0|1)     #IMPLIED  -- post is selected (value : 1) or not (value : 0) 
    1193      has_category   (0|1)     #IMPLIED  -- post has a category (value : 1) or not (value : 0) 
    1194966     has_attachment (0|1)     #IMPLIED  -- post has attachments (value : 1) or not (value : 0) (see Attachment plugin for code) 
    1195967     operator  (and|or)  #IMPLIED  -- combination of conditions, if more than 1 specifiec (default: and) 
     
    1201973          $if = new ArrayObject(); 
    1202974          $extended = null; 
    1203           $hascategory = null; 
    1204975           
    1205976          $operator = isset($attr['operator']) ? $this->getOperator($attr['operator']) : '&&'; 
     
    1221992          } 
    1222993           
    1223           if (isset($attr['category'])) { 
    1224                $category = addslashes(trim($attr['category'])); 
    1225                if (substr($category,0,1) == '!') { 
    1226                     $category = substr($category,1); 
    1227                     $if[] = '($_ctx->posts->cat_url != "'.$category.'")'; 
    1228                } else { 
    1229                     $if[] = '($_ctx->posts->cat_url == "'.$category.'")'; 
    1230                } 
    1231           } 
    1232            
    1233994          if (isset($attr['first'])) { 
    1234995               $sign = (boolean) $attr['first'] ? '=' : '!'; 
     
    12491010               $sign = (boolean) $attr['selected'] ? '' : '!'; 
    12501011               $if[] = $sign.'(boolean)$_ctx->posts->post_selected'; 
    1251           } 
    1252            
    1253           if (isset($attr['has_category'])) { 
    1254                $sign = (boolean) $attr['has_category'] ? '' : '!'; 
    1255                $if[] = $sign.'$_ctx->posts->cat_id'; 
    12561012          } 
    12571013           
     
    14301186      
    14311187     /*dtd 
    1432      <!ELEMENT tpl:EntryCategory - O -- Entry category (full name) --> 
    1433      */ 
    1434      public function EntryCategory($attr) 
    1435      { 
    1436           $f = $this->getFilters($attr); 
    1437           return '<?php echo '.sprintf($f,'$_ctx->posts->cat_title').'; ?>'; 
    1438      } 
    1439       
    1440      /*dtd 
    1441      <!ELEMENT tpl:EntryCategoriesBreadcrumb - - -- Current entry parents loop (without last one) --> 
    1442      */ 
    1443      public function EntryCategoriesBreadcrumb($attr,$content) 
    1444      { 
    1445           return 
    1446           "<?php\n". 
    1447           '$_ctx->categories = $core->blog->getCategoryParents($_ctx->posts->cat_id);'."\n". 
    1448           'while ($_ctx->categories->fetch()) : ?>'.$content.'<?php endwhile; $_ctx->categories = null; ?>'; 
    1449      } 
    1450       
    1451      /*dtd 
    1452      <!ELEMENT tpl:EntryCategoryID - O -- Entry category ID --> 
    1453      */ 
    1454      public function EntryCategoryID($attr) 
    1455      { 
    1456           $f = $this->getFilters($attr); 
    1457           return '<?php echo '.sprintf($f,'$_ctx->posts->cat_id').'; ?>'; 
    1458      } 
    1459       
    1460      /*dtd 
    1461      <!ELEMENT tpl:EntryCategoryURL - O -- Entry category URL --> 
    1462      */ 
    1463      public function EntryCategoryURL($attr) 
    1464      { 
    1465           $f = $this->getFilters($attr); 
    1466           return '<?php echo '.sprintf($f,'$_ctx->posts->getCategoryURL()').'; ?>'; 
    1467      } 
    1468       
    1469      /*dtd 
    1470      <!ELEMENT tpl:EntryCategoryShortURL - O -- Entry category short URL (relative URL, from /category/) --> 
    1471      */ 
    1472      public function EntryCategoryShortURL($attr) 
    1473      { 
    1474           $f = $this->getFilters($attr); 
    1475           return '<?php echo '.sprintf($f,'$_ctx->posts->cat_url').'; ?>'; 
    1476      } 
    1477       
    1478       
    1479      /*dtd 
    14801188     <!ELEMENT tpl:EntryFeedID - O -- Entry feed ID --> 
    14811189     */ 
     
    14911199     size           (sq|t|s|m|o)   #IMPLIED  -- Image size to extract 
    14921200     class          CDATA          #IMPLIED  -- Class to add on image tag 
    1493      with_category  (1|0)          #IMPLIED  -- Search in entry category description if present (default 0) 
    14941201     > 
    14951202     */ 
     
    15001207          $with_category = !empty($attr['with_category']) ? 'true' : 'false'; 
    15011208           
    1502           return "<?php echo context::EntryFirstImageHelper('".addslashes($size)."',".$with_category.",'".addslashes($class)."'); ?>"; 
     1209          return "<?php echo context::EntryFirstImageHelper('".addslashes($size)."','".addslashes($class)."'); ?>"; 
    15031210     } 
    15041211      
     
    15291236     <!ELEMENT tpl:EntryNext - - -- Next entry block --> 
    15301237     <!ATTLIST tpl:EntryNext 
    1531      restrict_to_category     (0|1)     #IMPLIED  -- find next post in the same category (default: 0) 
    15321238     restrict_to_lang         (0|1)     #IMPLIED  -- find next post in the same language (default: 0) 
    15331239     > 
     
    18771583     <!ELEMENT tpl:SysIf - - -- System settings tester container --> 
    18781584     <!ATTLIST tpl:SysIf 
    1879      categories          (0|1)     #IMPLIED  -- test if categories are set in current context (value : 1) or not (value : 0) 
    18801585     posts               (0|1)     #IMPLIED  -- test if posts are set in current context (value : 1) or not (value : 0) 
    18811586     blog_lang           CDATA     #IMPLIED  -- tests if blog language is the one given in parameter 
     
    18941599           
    18951600          $operator = isset($attr['operator']) ? $this->getOperator($attr['operator']) : '&&'; 
    1896            
    1897           if (isset($attr['categories'])) { 
    1898                $sign = (boolean) $attr['categories'] ? '!' : '='; 
    1899                $if[] = '$_ctx->categories '.$sign.'== null'; 
    1900           } 
    19011601           
    19021602          if (isset($attr['posts'])) { 
  • inc/public/lib.tpl.context.php

    r839 r851  
    162162     } 
    163163      
    164      public static function categoryPostParam(&$p) 
    165      { 
    166           $not = substr($p['cat_url'],0,1) == '!'; 
    167           if ($not) { 
    168                $p['cat_url'] = substr($p['cat_url'],1); 
    169           } 
    170            
    171           $p['cat_url'] = preg_split('/\s*,\s*/',$p['cat_url'],-1,PREG_SPLIT_NO_EMPTY); 
    172            
    173           foreach ($p['cat_url'] as &$v) 
    174           { 
    175                if ($not) { 
    176                     $v .= ' ?not'; 
    177                } 
    178                if ($GLOBALS['_ctx']->exists('categories') && preg_match('/#self/',$v)) { 
    179                     $v = preg_replace('/#self/',$GLOBALS['_ctx']->categories->cat_url,$v); 
    180                } elseif ($GLOBALS['_ctx']->exists('posts') && preg_match('/#self/',$v)) { 
    181                     $v = preg_replace('/#self/',$GLOBALS['_ctx']->posts->cat_url,$v); 
    182                } 
    183           } 
    184      } 
    185       
    186164     # Static methods for pagination 
    187165     public static function PaginationNbPages() 
     
    341319      
    342320     # First post image helpers 
    343      public static function EntryFirstImageHelper($size,$with_category,$class="") 
     321     public static function EntryFirstImageHelper($size,$class="") 
    344322     { 
    345323          global $core, $_ctx; 
     
    378356          } 
    379357           
    380           # No src, look in category description if available 
    381           if (!$src && $with_category && $_ctx->categories) 
    382           { 
    383                if (preg_match_all($pattern,$_ctx->categories->cat_desc,$m) > 0) 
    384                { 
    385                     foreach ($m[1] as $i => $img) { 
    386                          if (($src = self::ContentFirstImageLookup($p_root,$img,$size)) !== false) { 
    387                               $src = $p_url.(dirname($img) != '/' ? dirname($img) : '').'/'.$src; 
    388                               if (preg_match('/alt="([^"]+)"/',$m[0][$i],$malt)) { 
    389                                    $alt = $malt[1]; 
    390                               } 
    391                               break; 
    392                          } 
    393                     } 
    394                }; 
    395           } 
    396            
    397358          if ($src) { 
    398359               return '<img alt="'.$alt.'" src="'.$src.'" class="'.$class.'" />'; 
  • inc/public/lib.urlhandlers.php

    r848 r851  
    245245               $_ctx->cur_lang = $args; 
    246246               self::home(null); 
    247           } 
    248      } 
    249       
    250      public static function category($args) 
    251      { 
    252           $_ctx =& $GLOBALS['_ctx']; 
    253           $core =& $GLOBALS['core']; 
    254            
    255           $n = self::getPageNumber($args); 
    256            
    257           if ($args == '' && !$n) { 
    258                # No category was specified. 
    259                self::p404(); 
    260           } 
    261           else 
    262           { 
    263                $params = new ArrayObject(array( 
    264                     'cat_url' => $args, 
    265                     'post_type' => 'post')); 
    266                 
    267                $core->callBehavior('publicCategoryBeforeGetCategories',$params,$args); 
    268                 
    269                $_ctx->categories = $core->blog->getCategories($params); 
    270                 
    271                if ($_ctx->categories->isEmpty()) { 
    272                     # The specified category does no exist. 
    273                     self::p404(); 
    274                } 
    275                else 
    276                { 
    277                     if ($n) { 
    278                          $GLOBALS['_page_number'] = $n; 
    279                     } 
    280                     self::serveDocument('category.html'); 
    281                } 
    282247          } 
    283248     } 
  • locales/en/resources.php

    r848 r851  
    2424$__resources['help'] = array( 
    2525     'core_blog_pref' => dirname(__FILE__).'/help/blog_pref.html', 
    26      'core_categories' => dirname(__FILE__).'/help/categories.html', 
    2726     'core_media' => dirname(__FILE__).'/help/media.html', 
    2827     'core_post' => dirname(__FILE__).'/help/post.html', 
  • plugins/widgets/_default_widgets.php

    r665 r851  
    3333$__widgets->langs->setting('homeonly',__('Home page only'),1,'check'); 
    3434 
    35 $__widgets->create('categories',__('Categories list'),array('defaultWidgets','categories')); 
    36 $__widgets->categories->setting('title',__('Title:'),__('Categories')); 
    37 $__widgets->categories->setting('postcount',__('With entries counts'),0,'check'); 
    38  
    3935$__widgets->create('subscribe',__('Subscribe links'),array('defaultWidgets','subscribe')); 
    4036$__widgets->subscribe->setting('title',__('Title:'),__('Subscribe')); 
     
    5551$__widgets->create('lastposts',__('Last entries'),array('defaultWidgets','lastposts')); 
    5652$__widgets->lastposts->setting('title',__('Title:'),__('Last entries')); 
    57 $rs = $core->blog->getCategories(array('post_type'=>'post')); 
    58 $categories = array('' => '', __('Uncategorized') => 'null'); 
    59 while ($rs->fetch()) { 
    60      $categories[str_repeat('&nbsp;&nbsp;',$rs->level-1).($rs->level-1 == 0 ? '' : '&bull; ').html::escapeHTML($rs->cat_title)] = $rs->cat_id; 
    61 } 
    62 $__widgets->lastposts->setting('category',__('Category:'),'','combo',$categories); 
    63 unset($rs,$categories); 
    6453if ($core->plugins->moduleExists('tags')) { 
    6554     $__widgets->lastposts->setting('tag',__('Tag:'),''); 
     
    8473$__default_widgets['nav']->append($__widgets->navigation); 
    8574$__default_widgets['nav']->append($__widgets->bestof); 
    86 $__default_widgets['nav']->append($__widgets->categories); 
    8775$__default_widgets['extra']->append($__widgets->subscribe); 
    8876 
  • plugins/widgets/_widgets_functions.php

    r776 r851  
    5858     } 
    5959      
    60      public static function categories($w) 
    61      { 
    62           global $core, $_ctx; 
    63            
    64           $rs = $core->blog->getCategories(array('post_type'=>'post')); 
    65           if ($rs->isEmpty()) { 
    66                return; 
    67           } 
    68            
    69           $res = 
    70           '<div class="categories">'. 
    71           ($w->title ? '<h2>'.html::escapeHTML($w->title).'</h2>' : ''); 
    72            
    73           $ref_level = $level = $rs->level-1; 
    74           while ($rs->fetch()) 
    75           { 
    76                $class = ''; 
    77                if (($core->url->type == 'category' && $_ctx->categories instanceof record && $_ctx->categories->cat_id == $rs->cat_id) 
    78                || ($core->url->type == 'post' && $_ctx->posts instanceof record && $_ctx->posts->cat_id == $rs->cat_id)) { 
    79                     $class = ' class="category-current"'; 
    80                } 
    81                 
    82                if ($rs->level > $level) { 
    83                     $res .= str_repeat('<ul><li'.$class.'>',$rs->level - $level); 
    84                } elseif ($rs->level < $level) { 
    85                     $res .= str_repeat('</li></ul>',-($rs->level - $level)); 
    86                } 
    87                 
    88                if ($rs->level <= $level) { 
    89                     $res .= '</li><li'.$class.'>'; 
    90                } 
    91                 
    92                $res .= 
    93                '<a href="'.$core->blog->url.$core->url->getURLFor('category', $rs->cat_url).'">'. 
    94                html::escapeHTML($rs->cat_title).'</a>'. 
    95                ($w->postcount ? ' <span>('.$rs->nb_post.')</span>' : ''); 
    96                 
    97                 
    98                $level = $rs->level; 
    99           } 
    100            
    101           if ($ref_level - $level < 0) { 
    102                $res .= str_repeat('</li></ul>',-($ref_level - $level)); 
    103           } 
    104           $res .= '</div>'; 
    105            
    106           return $res; 
    107      } 
    108       
    10960     public static function bestof($w) 
    11061     { 
     
    292243          $params['no_content'] = true; 
    293244           
    294           if ($w->category) 
    295           { 
    296                if ($w->category == 'null') { 
    297                     $params['sql'] = ' AND P.cat_id IS NULL '; 
    298                } elseif (is_numeric($w->category)) { 
    299                     $params['cat_id'] = (integer) $w->category; 
    300                } else { 
    301                     $params['cat_url'] = $w->category; 
    302                } 
    303           } 
    304            
    305245          if ($w->tag) 
    306246          { 
Note: See TracChangeset for help on using the changeset viewer.

Sites map