Dotclear

Changeset 851:0993f64c4809 for inc/core


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

sexy step 2 : no more cats.

Location:
inc/core
Files:
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • 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      
Note: See TracChangeset for help on using the changeset viewer.

Sites map