Dotclear

Changeset 2655:a568d9e7d732 for inc/core


Ignore:
Timestamp:
02/13/14 14:12:09 (12 years ago)
Author:
Dsls
Branch:
twig
Message:

composer locked on CB 0.9.0, restored favorites

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inc/core/class.dc.blog.php

    r2650 r2655  
    2727     /** @var string Database table prefix */ 
    2828     public $prefix; 
    29       
     29 
    3030     /** @var string Blog ID */ 
    3131     public $id; 
     
    4646     /** @var string Blog status */ 
    4747     public $status; 
    48       
     48 
    4949     /** @var dcSettings dcSettings object */ 
    5050     public $settings; 
     
    5353     /** @var string Blog public path */ 
    5454     public $public_path; 
    55       
     55 
    5656     private $post_status = array(); 
    5757     private $comment_status = array(); 
    58       
     58 
    5959     private $categories; 
    60       
     60 
    6161     /** @var boolean Disallow entries password protection */ 
    6262     public $without_password = true; 
    63       
     63 
    6464     /** 
    6565     Inits dcBlog object 
    66       
     66 
    6767     @param    core      <b>dcCore</b>       Dotclear core reference 
    6868     @param    id        <b>string</b>       Blog ID 
     
    7373          $this->prefix = $core->prefix; 
    7474          $this->core =& $core; 
    75            
     75 
    7676          if (($b = $this->core->getBlog($id)) !== false) 
    7777          { 
     
    8585               $this->upddt = strtotime($b->blog_upddt); 
    8686               $this->status = $b->blog_status; 
    87                 
     87 
    8888               $this->settings = new dcSettings($this->core,$this->id); 
    89                 
     89 
    9090               $this->themes_path = path::fullFromRoot($this->settings->system->themes_path,DC_ROOT); 
    9191               $this->public_path = path::fullFromRoot($this->settings->system->public_path,DC_ROOT); 
    92                 
     92 
    9393               $this->post_status['-2'] = __('Pending'); 
    9494               $this->post_status['-1'] = __('Scheduled'); 
    9595               $this->post_status['0'] = __('Unpublished'); 
    9696               $this->post_status['1'] = __('Published'); 
    97                 
     97 
    9898               $this->comment_status['-2'] = __('Junk'); 
    9999               $this->comment_status['-1'] = __('Pending'); 
    100100               $this->comment_status['0'] = __('Unpublished'); 
    101101               $this->comment_status['1'] = __('Published'); 
    102                 
     102 
    103103               # --BEHAVIOR-- coreBlogConstruct 
    104104               $this->core->callBehavior('coreBlogConstruct',$this); 
    105105          } 
    106106     } 
    107       
     107 
    108108     /// @name Common public methods 
    109109     //@{ 
     
    116116               return $this->url.'?'; 
    117117          } 
    118            
     118 
    119119          return $this->url; 
    120120     } 
    121       
     121 
    122122     /** 
    123123     Returns an entry status name given to a code. Status are translated, never 
    124124     use it for tests. If status code does not exist, returns <i>unpublished</i>. 
    125       
     125 
    126126     @param    s    <b>integer</b> Status code 
    127127     @return   <b>string</b> Blog status name 
     
    134134          return $this->post_status['0']; 
    135135     } 
    136       
     136 
    137137     /** 
    138138     Returns an array of available entry status codes and names. 
    139       
     139 
    140140     @return   <b>array</b> Simple array with codes in keys and names in value 
    141141     */ 
     
    144144          return $this->post_status; 
    145145     } 
    146       
     146 
    147147     /** 
    148148     Returns an array of available comment status codes and names. 
    149       
     149 
    150150     @return   <b>array</b> Simple array with codes in keys and names in value 
    151151     */ 
     
    154154          return $this->comment_status; 
    155155     } 
    156       
     156 
    157157     /** 
    158158     Disallows entries password protection. You need to set it to 
    159159     <var>false</var> while serving a public blog. 
    160       
     160 
    161161     @param    v         <b>boolean</b> 
    162162     */ 
     
    166166     } 
    167167     //@} 
    168       
     168 
    169169     /// @name Triggers methods 
    170170     //@{ 
     
    176176     { 
    177177          $cur = $this->con->openCursor($this->prefix.'blog'); 
    178            
     178 
    179179          $cur->blog_upddt = date('Y-m-d H:i:s'); 
    180            
     180 
    181181          $cur->update("WHERE blog_id = '".$this->con->escape($this->id)."' "); 
    182            
     182 
    183183          # --BEHAVIOR-- coreBlogAfterTriggerBlog 
    184184          $this->core->callBehavior('coreBlogAfterTriggerBlog',$cur); 
    185185     } 
    186       
     186 
    187187     /** 
    188188     Updates comment and trackback counters in post table. Should be called 
    189189     every time a comment or trackback is added, removed or changed its status. 
    190       
     190 
    191191     @param    id        <b>integer</b>      Comment ID 
    192192     @param    del       <b>boolean</b>      If comment is delete, set this to true 
     
    196196          $this->triggerComments($id,$del); 
    197197     } 
    198       
     198 
    199199     /** 
    200200     Updates comments and trackbacks counters in post table. Should be called 
    201201     every time comments or trackbacks are added, removed or changed their status. 
    202       
     202 
    203203     @param    ids       <b>mixed</b>        Comment(s) ID(s) 
    204204     @param    del       <b>boolean</b>      If comment is delete, set this to true 
     
    208208     { 
    209209          $comments_ids = dcUtils::cleanIds($ids); 
    210            
     210 
    211211          # Get posts affected by comments edition 
    212212          if (empty($affected_posts)) { 
    213                $strReq =  
     213               $strReq = 
    214214                    'SELECT post_id '. 
    215215                    'FROM '.$this->prefix.'comment '. 
    216216                    'WHERE comment_id'.$this->con->in($comments_ids). 
    217217                    'GROUP BY post_id'; 
    218                 
     218 
    219219               $rs = $this->con->select($strReq); 
    220                 
     220 
    221221               $affected_posts = array(); 
    222222               while ($rs->fetch()) { 
     
    224224               } 
    225225          } 
    226            
     226 
    227227          if (!is_array($affected_posts) || empty($affected_posts)) { 
    228228               return; 
    229229          } 
    230            
     230 
    231231          # Count number of comments if exists for affected posts 
    232           $strReq =  
     232          $strReq = 
    233233               'SELECT post_id, COUNT(post_id) AS nb_comment, comment_trackback '. 
    234234               'FROM '.$this->prefix.'comment '. 
     
    236236               'AND post_id'.$this->con->in($affected_posts). 
    237237               'GROUP BY post_id,comment_trackback'; 
    238            
     238 
    239239          $rs = $this->con->select($strReq); 
    240            
     240 
    241241          $posts = array(); 
    242242          while ($rs->fetch()) { 
     
    247247               } 
    248248          } 
    249            
     249 
    250250          # Update number of comments on affected posts 
    251251          $cur = $this->con->openCursor($this->prefix.'post'); 
     
    253253          { 
    254254               $cur->clean(); 
    255                 
     255 
    256256               if (!array_key_exists($post_id,$posts)) { 
    257257                    $cur->nb_trackback = 0; 
     
    261261                    $cur->nb_comment = empty($posts[$post_id]['comment']) ? 0 : $posts[$post_id]['comment']; 
    262262               } 
    263                 
     263 
    264264               $cur->update('WHERE post_id = '.$post_id); 
    265265          } 
    266266     } 
    267267     //@} 
    268       
     268 
    269269     /// @name Categories management methods 
    270270     //@{ 
     
    274274               $this->categories = new dcCategories($this->core); 
    275275          } 
    276            
     276 
    277277          return $this->categories; 
    278278     } 
    279       
     279 
    280280     /** 
    281281     Retrieves categories. <var>$params</var> is an associative array which can 
    282282     take the following parameters: 
    283       
     283 
    284284     - post_type: Get only entries with given type (default "post") 
    285285     - cat_url: filter on cat_url field 
     
    287287     - start: start with a given category 
    288288     - level: categories level to retrieve 
    289       
     289 
    290290     @param    params    <b>array</b>        Parameters 
    291291     @return   <b>record</b> 
     
    299299          } 
    300300          $counter = $this->getCategoriesCounter($c_params); 
    301            
     301 
    302302          if (isset($params['without_empty']) && ($params['without_empty'] == false)) { 
    303303               $without_empty = false; 
     
    305305               $without_empty = $this->core->auth->userID() == false; # Get all categories if in admin display 
    306306          } 
    307            
     307 
    308308          $start = isset($params['start']) ? (integer) $params['start'] : 0; 
    309309          $l = isset($params['level']) ? (integer) $params['level'] : 0; 
    310            
     310 
    311311          $rs = $this->categories()->getChildren($start,null,'desc'); 
    312            
     312 
    313313          # Get each categories total posts count 
    314314          $data = array(); 
     
    319319          { 
    320320               $nb_post = isset($counter[$rs->cat_id]) ? (integer) $counter[$rs->cat_id] : 0; 
    321                 
     321 
    322322               if ($rs->level > $level) { 
    323323                    $nb_total = $nb_post; 
     
    335335                    unset($stack[$rs->level+1]); 
    336336               } 
    337                 
     337 
    338338               if ($nb_total == 0 && $without_empty) { 
    339339                    continue; 
    340340               } 
    341                 
     341 
    342342               $level = $rs->level; 
    343                 
     343 
    344344               $t = array(); 
    345345               foreach ($cols as $c) { 
     
    348348               $t['nb_post'] = $nb_post; 
    349349               $t['nb_total'] = $nb_total; 
    350                 
     350 
    351351               if ($l == 0 || ($l > 0 && $l == $rs->level)) { 
    352352                    array_unshift($data,$t); 
    353353               } 
    354354          } 
    355            
     355 
    356356          # We need to apply filter after counting 
    357357          if (isset($params['cat_id']) && $params['cat_id'] !== '') 
     
    369369               } 
    370370          } 
    371            
    372           if (isset($params['cat_url']) && ($params['cat_url'] !== '')  
     371 
     372          if (isset($params['cat_url']) && ($params['cat_url'] !== '') 
    373373               && !isset($params['cat_id'])) 
    374374          { 
     
    385385               } 
    386386          } 
    387            
     387 
    388388          return staticRecord::newFromArray($data); 
    389389     } 
    390       
     390 
    391391     /** 
    392392     Retrieves a category by its ID. 
    393       
     393 
    394394     @param    id        <b>integer</b>      Category ID 
    395395     @return   <b>record</b> 
     
    399399          return $this->getCategories(array('cat_id' => $id)); 
    400400     } 
    401       
     401 
    402402     /** 
    403403     Retrieves parents of a given category. 
    404       
     404 
    405405     @param    id        <b>integer</b>      Category ID 
    406406     @return   <b>record</b> 
     
    410410          return $this->categories()->getParents($id); 
    411411     } 
    412       
     412 
    413413     /** 
    414414     Retrieves first parent of a given category. 
    415       
     415 
    416416     @param    id        <b>integer</b>      Category ID 
    417417     @return   <b>record</b> 
     
    421421          return $this->categories()->getParent($id); 
    422422     } 
    423       
     423 
    424424     /** 
    425425     Retrieves all category's first children 
    426       
     426 
    427427     @param    id        <b>integer</b>      Category ID 
    428428     @return   <b>record</b> 
     
    432432          return $this->getCategories(array('start' => $id,'level' => $id == 0 ? 1 : 2)); 
    433433     } 
    434       
     434 
    435435     private function getCategoriesCounter($params=array()) 
    436436     { 
     
    440440          'JOIN '.$this->prefix."post P ON (C.cat_id = P.cat_id AND P.blog_id = '".$this->con->escape($this->id)."' ) ". 
    441441          "WHERE C.blog_id = '".$this->con->escape($this->id)."' "; 
    442            
     442 
    443443          if (!$this->core->auth->userID()) { 
    444444               $strReq .= 'AND P.post_status = 1 '; 
    445445          } 
    446            
     446 
    447447          if (!empty($params['post_type'])) { 
    448448               $strReq .= 'AND P.post_type '.$this->con->in($params['post_type']); 
    449449          } 
    450            
     450 
    451451          $strReq .= 'GROUP BY C.cat_id '; 
    452            
     452 
    453453          $rs = $this->con->select($strReq); 
    454454          $counters = array(); 
     
    456456               $counters[$rs->cat_id] = $rs->nb_post; 
    457457          } 
    458            
     458 
    459459          return $counters; 
    460460     } 
    461       
     461 
    462462     /** 
    463463     Creates a new category. Takes a cursor as input and returns the new category 
    464464     ID. 
    465       
     465 
    466466     @param    cur       <b>cursor</b>       Category cursor 
    467467     @return   <b>integer</b>      New category ID 
     
    472472               throw new Exception(__('You are not allowed to add categories')); 
    473473          } 
    474            
     474 
    475475          $url = array(); 
    476476          if ($parent != 0) 
     
    483483               } 
    484484          } 
    485            
     485 
    486486          if ($cur->cat_url == '') { 
    487487               $url[] = text::tidyURL($cur->cat_title,false); 
     
    489489               $url[] = $cur->cat_url; 
    490490          } 
    491            
     491 
    492492          $cur->cat_url = implode('/',$url); 
    493            
     493 
    494494          $this->getCategoryCursor($cur); 
    495495          $cur->blog_id = (string) $this->id; 
    496            
     496 
    497497          # --BEHAVIOR-- coreBeforeCategoryCreate 
    498498          $this->core->callBehavior('coreBeforeCategoryCreate',$this,$cur); 
    499            
     499 
    500500          $id = $this->categories()->addNode($cur,$parent); 
    501501          # Update category's cursor 
     
    505505               $cur->cat_rgt = $rs->cat_rgt; 
    506506          } 
    507            
     507 
    508508          # --BEHAVIOR-- coreAfterCategoryCreate 
    509509          $this->core->callBehavior('coreAfterCategoryCreate',$this,$cur); 
    510510          $this->triggerBlog(); 
    511            
     511 
    512512          return $cur->cat_id; 
    513513     } 
    514       
     514 
    515515     /** 
    516516     Updates an existing category. 
    517       
     517 
    518518     @param    id        <b>integer</b>      Category ID 
    519519     @param    cur       <b>cursor</b>       Category cursor 
     
    524524               throw new Exception(__('You are not allowed to update categories')); 
    525525          } 
    526            
     526 
    527527          if ($cur->cat_url == '') 
    528528          { 
     
    534534                    } 
    535535               } 
    536                 
    537                 
     536 
     537 
    538538               $url[] = text::tidyURL($cur->cat_title,false); 
    539539               $cur->cat_url = implode('/',$url); 
    540540          } 
    541            
     541 
    542542          $this->getCategoryCursor($cur,$id); 
    543            
     543 
    544544          # --BEHAVIOR-- coreBeforeCategoryUpdate 
    545545          $this->core->callBehavior('coreBeforeCategoryUpdate',$this,$cur); 
    546            
     546 
    547547          $cur->update( 
    548548          'WHERE cat_id = '.(integer) $id.' '. 
    549549          "AND blog_id = '".$this->con->escape($this->id)."' "); 
    550            
     550 
    551551          # --BEHAVIOR-- coreAfterCategoryUpdate 
    552552          $this->core->callBehavior('coreAfterCategoryUpdate',$this,$cur); 
    553            
     553 
    554554          $this->triggerBlog(); 
    555555     } 
     
    567567                $this->triggerBlog(); 
    568568        } 
    569       
     569 
    570570     /** 
    571571     DEPRECATED METHOD. Use dcBlog::setCategoryParent and dcBlog::moveCategory 
    572572     instead. 
    573       
     573 
    574574     @param    id        <b>integer</b>      Category ID 
    575575     @param    order     <b>integer</b>      Category position 
     
    579579          return; 
    580580     } 
    581       
     581 
    582582     /** 
    583583     Set a category parent 
    584       
     584 
    585585     @param    id        <b>integer</b>      Category ID 
    586586     @param    parent    <b>integer</b>      Parent Category ID 
     
    591591          $this->triggerBlog(); 
    592592     } 
    593       
     593 
    594594     /** 
    595595     Set category position 
    596       
     596 
    597597     @param    id        <b>integer</b>      Category ID 
    598598     @param    sibling   <b>integer</b>      Sibling Category ID 
     
    604604          $this->triggerBlog(); 
    605605     } 
    606       
     606 
    607607     /** 
    608608     Deletes a category. 
    609       
     609 
    610610     @param    id        <b>integer</b>      Category ID 
    611611     */ 
     
    615615               throw new Exception(__('You are not allowed to delete categories')); 
    616616          } 
    617            
     617 
    618618          $strReq = 'SELECT COUNT(post_id) AS nb_post '. 
    619619                    'FROM '.$this->prefix.'post '. 
    620620                    'WHERE cat_id = '.(integer) $id.' '. 
    621621                    "AND blog_id = '".$this->con->escape($this->id)."' "; 
    622            
     622 
    623623          $rs = $this->con->select($strReq); 
    624            
     624 
    625625          if ($rs->nb_post > 0) { 
    626626               throw new Exception(__('This category is not empty.')); 
    627627          } 
    628            
     628 
    629629          $this->categories()->deleteNode($id,true); 
    630630          $this->triggerBlog(); 
    631631     } 
    632       
     632 
    633633     /** 
    634634     Reset categories order and relocate them to first level 
     
    639639               throw new Exception(__('You are not allowed to reset categories order')); 
    640640          } 
    641            
     641 
    642642          $this->categories()->resetOrder(); 
    643643          $this->triggerBlog(); 
    644644     } 
    645       
     645 
    646646     private function checkCategory($title,$url,$id=null) 
    647647     { 
    648648          # Let's check if URL is taken... 
    649           $strReq =  
     649          $strReq = 
    650650               'SELECT cat_url FROM '.$this->prefix.'category '. 
    651651               "WHERE cat_url = '".$this->con->escape($url)."' ". 
     
    653653               "AND blog_id = '".$this->con->escape($this->id)."' ". 
    654654               'ORDER BY cat_url DESC'; 
    655            
     655 
    656656          $rs = $this->con->select($strReq); 
    657            
     657 
    658658          if (!$rs->isEmpty()) 
    659659          { 
     
    665665                    $clause = "LIKE '".$this->con->escape($url)."%'"; 
    666666               } 
    667                $strReq =  
     667               $strReq = 
    668668                    'SELECT cat_url FROM '.$this->prefix.'category '. 
    669669                    "WHERE cat_url ".$clause.' '. 
     
    671671                    "AND blog_id = '".$this->con->escape($this->id)."' ". 
    672672                    'ORDER BY cat_url DESC '; 
    673                 
     673 
    674674               $rs = $this->con->select($strReq); 
    675675               $a = array(); 
     
    677677                    $a[] = $rs->cat_url; 
    678678               } 
    679                 
     679 
    680680               natsort($a); 
    681681               $t_url = end($a); 
    682                 
     682 
    683683               if (preg_match('/(.*?)([0-9]+)$/',$t_url,$m)) { 
    684684                    $i = (integer) $m[2]; 
     
    687687                    $i = 1; 
    688688               } 
    689                 
     689 
    690690               return $url.($i+1); 
    691691          } 
    692            
     692 
    693693          # URL is empty? 
    694694          if ($url == '') { 
    695695               throw new Exception(__('Empty category URL')); 
    696696          } 
    697            
     697 
    698698          return $url; 
    699699     } 
    700       
     700 
    701701     private function getCategoryCursor($cur,$id=null) 
    702702     { 
     
    704704               throw new Exception(__('You must provide a category title')); 
    705705          } 
    706            
     706 
    707707          # If we don't have any cat_url, let's do one 
    708708          if ($cur->cat_url == '') { 
    709709               $cur->cat_url = text::tidyURL($cur->cat_title,false); 
    710710          } 
    711            
     711 
    712712          # Still empty ? 
    713713          if ($cur->cat_url == '') { 
     
    716716               $cur->cat_url = text::tidyURL($cur->cat_url,true); 
    717717          } 
    718            
     718 
    719719          # Check if title or url are unique 
    720720          $cur->cat_url = $this->checkCategory($cur->cat_title,$cur->cat_url,$id); 
    721            
     721 
    722722          if ($cur->cat_desc !== null) { 
    723723               $cur->cat_desc = $this->core->HTMLfilter($cur->cat_desc); 
     
    725725     } 
    726726     //@} 
    727       
     727 
    728728     /// @name Entries management methods 
    729729     //@{ 
     
    731731     Retrieves entries. <b>$params</b> is an array taking the following 
    732732     optionnal parameters: 
    733       
     733 
    734734     - no_content: Don't retrieve entry content (excerpt and content) 
    735735     - post_type: Get only entries with given type (default "post", array for many types and '' for no type) 
     
    755755     - sql_only : return the sql request instead of results. Only ids are selected 
    756756     - exclude_post_id : (integer or array) Exclude entries with given post_id 
    757       
     757 
    758758     Please note that on every cat_id or cat_url, you can add ?not to exclude 
    759759     the category and ?sub to get subcategories. 
    760       
     760 
    761761     @param    params         <b>array</b>        Parameters 
    762762     @param    count_only     <b>boolean</b>      Only counts results 
     
    773773               $strReq = 'SELECT count(DISTINCT P.post_id) '; 
    774774          } 
    775           elseif (!empty($params['sql_only']))  
     775          elseif (!empty($params['sql_only'])) 
    776776          { 
    777777               $strReq = 'SELECT P.post_id '; 
     
    786786                    'post_content, post_content_xhtml, post_notes, '; 
    787787               } 
    788                 
     788 
    789789               if (!empty($params['columns']) && is_array($params['columns'])) { 
    790790                    $content_req .= implode(', ',$params['columns']).', '; 
    791791               } 
    792                 
     792 
    793793 
    794794               $strReq = 
     
    802802               'C.cat_title, C.cat_url, C.cat_desc '; 
    803803          } 
    804            
     804 
    805805          $strReq .= 
    806806          'FROM '.$this->prefix.'post P '. 
     
    811811               $strReq .= $params['from'].' '; 
    812812          } 
    813            
     813 
    814814          $strReq .= 
    815815          "WHERE P.blog_id = '".$this->con->escape($this->id)."' "; 
    816            
     816 
    817817          if (!$this->core->auth->check('contentadmin',$this->id)) { 
    818818               $strReq .= 'AND ((post_status = 1 '; 
    819                 
     819 
    820820               if ($this->without_password) { 
    821821                    $strReq .= 'AND post_password IS NULL '; 
    822822               } 
    823823               $strReq .= ') '; 
    824                 
     824 
    825825               if ($this->core->auth->userID()) { 
    826826                    $strReq .= "OR P.user_id = '".$this->con->escape($this->core->auth->userID())."')"; 
     
    829829               } 
    830830          } 
    831            
     831 
    832832          #Adding parameters 
    833833          if (isset($params['post_type'])) 
     
    841841               $strReq .= "AND post_type = 'post' "; 
    842842          } 
    843            
     843 
    844844          if (isset($params['post_id']) && $params['post_id'] !== '') { 
    845845               if (is_array($params['post_id'])) { 
     
    850850               $strReq .= 'AND P.post_id '.$this->con->in($params['post_id']); 
    851851          } 
    852            
     852 
    853853          if (isset($params['exclude_post_id']) && $params['exclude_post_id'] !== '') { 
    854854               if (is_array($params['exclude_post_id'])) { 
     
    859859               $strReq .= 'AND P.post_id NOT '.$this->con->in($params['exclude_post_id']); 
    860860          } 
    861            
     861 
    862862          if (isset($params['post_url']) && $params['post_url'] !== '') { 
    863863               $strReq .= "AND post_url = '".$this->con->escape($params['post_url'])."' "; 
    864864          } 
    865            
     865 
    866866          if (!empty($params['user_id'])) { 
    867                $strReq .= "AND U.user_id ".$this->con->in($params['user_id'])." "; 
    868           } 
    869            
     867               $not=""; 
     868               if (!empty($params['user_id_not'])) { 
     869                    $not=" not"; 
     870               } 
     871               $strReq .= "AND U.user_id ".$not.$this->con->in($params['user_id'])." "; 
     872          } 
     873 
    870874          if (isset($params['cat_id']) && $params['cat_id'] !== '') 
    871875          { 
     
    888892               $strReq .= 'AND '.$this->getPostsCategoryFilter($params['cat_url'],'cat_url').' '; 
    889893          } 
    890            
     894 
    891895          /* Other filters */ 
    892896          if (isset($params['post_status'])) { 
    893897               $strReq .= 'AND post_status = '.(integer) $params['post_status'].' '; 
    894898          } 
    895            
     899 
    896900          if (isset($params['post_selected'])) { 
    897901               $strReq .= 'AND post_selected = '.(integer) $params['post_selected'].' '; 
    898902          } 
    899            
     903 
    900904          if (!empty($params['post_year'])) { 
    901905               $strReq .= 'AND '.$this->con->dateFormat('post_dt','%Y').' = '. 
    902906               "'".sprintf('%04d',$params['post_year'])."' "; 
    903907          } 
    904            
     908 
    905909          if (!empty($params['post_month'])) { 
    906910               $strReq .= 'AND '.$this->con->dateFormat('post_dt','%m').' = '. 
    907911               "'".sprintf('%02d',$params['post_month'])."' "; 
    908912          } 
    909            
     913 
    910914          if (!empty($params['post_day'])) { 
    911915               $strReq .= 'AND '.$this->con->dateFormat('post_dt','%d').' = '. 
    912916               "'".sprintf('%02d',$params['post_day'])."' "; 
    913917          } 
    914            
     918 
    915919          if (!empty($params['post_lang'])) { 
    916920               $strReq .= "AND P.post_lang = '".$this->con->escape($params['post_lang'])."' "; 
    917921          } 
    918            
     922 
    919923          if (!empty($params['search'])) 
    920924          { 
    921925               $words = text::splitWords($params['search']); 
    922                 
     926 
    923927               if (!empty($words)) 
    924928               { 
     
    927931                         $this->core->callBehavior('corePostSearch',$this->core,array(&$words,&$strReq,&$params)); 
    928932                    } 
    929                      
     933 
    930934                    if ($words) 
    931935                    { 
     
    937941               } 
    938942          } 
    939            
     943 
    940944          if (isset($params['media'])) { 
    941945               if ($params['media'] == '0') { 
    942946                    $strReq .= 'AND NOT '; 
    943947               } else { 
    944                     $strReq .= 'AND ';                  
     948                    $strReq .= 'AND '; 
    945949               } 
    946950               $strReq .= 'EXISTS (SELECT M.post_id FROM '.$this->prefix.'post_media M '. 
     
    968972                    $strReq .= $this->con->limit($params['limit']); 
    969973               } 
    970            
     974 
    971975          if (!empty($params['sql_only'])) { 
    972976               return $strReq; 
     
    977981          $rs->_nb_media = array(); 
    978982          $rs->extend('rsExtPost'); 
    979            
     983 
    980984          # --BEHAVIOR-- coreBlogGetPosts 
    981985          $this->core->callBehavior('coreBlogGetPosts',$rs); 
    982            
     986 
    983987          return $rs; 
    984988     } 
    985       
     989 
    986990     /** 
    987991     Returns a record with post id, title and date for next or previous post 
    988992     according to the post ID. 
    989993     $dir could be 1 (next post) or -1 (previous post). 
    990       
     994 
    991995     @param    post_id                  <b>integer</b>      Post ID 
    992996     @param    dir                      <b>integer</b>      Search direction 
     
    9991003          $dt = $post->post_dt; 
    10001004          $post_id = (integer) $post->post_id; 
    1001            
     1005 
    10021006          if($dir > 0) { 
    10031007               $sign = '>'; 
     
    10081012               $order = 'DESC'; 
    10091013          } 
    1010            
     1014 
    10111015          $params['post_type'] = $post->post_type; 
    10121016          $params['limit'] = 1; 
     
    10171021          "    OR post_dt ".$sign." '".$this->con->escape($dt)."' ". 
    10181022          ') '; 
    1019            
     1023 
    10201024          if ($restrict_to_category) { 
    10211025               $params['sql'] .= $post->cat_id ? 'AND P.cat_id = '.(integer) $post->cat_id.' ' : 'AND P.cat_id IS NULL '; 
    10221026          } 
    1023            
     1027 
    10241028          if ($restrict_to_lang) { 
    10251029               $params['sql'] .= $post->post_lang ? 'AND P.post_lang = \''. $this->con->escape($post->post_lang) .'\' ': 'AND P.post_lang IS NULL '; 
    10261030          } 
    1027            
     1031 
    10281032          $rs = $this->getPosts($params); 
    1029            
     1033 
    10301034          if ($rs->isEmpty()) { 
    10311035               return null; 
    10321036          } 
    1033            
     1037 
    10341038          return $rs; 
    10351039     } 
    1036       
     1040 
    10371041     /** 
    10381042     Retrieves different languages and post count on blog, based on post_lang 
    10391043     field. <var>$params</var> is an array taking the following optionnal 
    10401044     parameters: 
    1041       
     1045 
    10421046     - post_type: Get only entries with given type (default "post", '' for no type) 
    10431047     - lang: retrieve post count for selected lang 
    10441048     - order: order statement (default post_lang DESC) 
    1045       
     1049 
    10461050     @param    params    <b>array</b>        Parameters 
    10471051     @return   record 
     
    10541058                    "AND post_lang <> '' ". 
    10551059                    "AND post_lang IS NOT NULL "; 
    1056            
     1060 
    10571061          if (!$this->core->auth->check('contentadmin',$this->id)) { 
    10581062               $strReq .= 'AND ((post_status = 1 '; 
    1059                 
     1063 
    10601064               if ($this->without_password) { 
    10611065                    $strReq .= 'AND post_password IS NULL '; 
    10621066               } 
    10631067               $strReq .= ') '; 
    1064                 
     1068 
    10651069               if ($this->core->auth->userID()) { 
    10661070                    $strReq .= "OR user_id = '".$this->con->escape($this->core->auth->userID())."')"; 
     
    10691073               } 
    10701074          } 
    1071            
     1075 
    10721076          if (isset($params['post_type'])) { 
    10731077               if ($params['post_type'] != '') { 
     
    10771081               $strReq .= "AND post_type = 'post' "; 
    10781082          } 
    1079            
     1083 
    10801084          if (isset($params['lang'])) { 
    10811085               $strReq .= "AND post_lang = '".$this->con->escape($params['lang'])."' "; 
    10821086          } 
    1083            
     1087 
    10841088          $strReq .= 'GROUP BY post_lang '; 
    1085            
     1089 
    10861090          $order = 'desc'; 
    10871091          if (!empty($params['order']) && preg_match('/^(desc|asc)$/i',$params['order'])) { 
     
    10891093          } 
    10901094          $strReq .= 'ORDER BY post_lang '.$order.' '; 
    1091            
     1095 
    10921096          return $this->con->select($strReq); 
    10931097     } 
    1094       
     1098 
    10951099     /** 
    10961100     Returns a record with all distinct blog dates and post count. 
    10971101     <var>$params</var> is an array taking the following optionnal parameters: 
    1098       
     1102 
    10991103     - type: (day|month|year) Get days, months or years 
    11001104     - year: (integer) Get dates for given year 
     
    11071111     - previous: Get date before match 
    11081112     - order: Sort by date "ASC" or "DESC" 
    1109       
     1113 
    11101114     @param    params    <b>array</b>        Parameters array 
    11111115     @return   record 
     
    11261130          $dt_f .= ' 00:00:00'; 
    11271131          $dt_fc .= '000000'; 
    1128            
     1132 
    11291133          $cat_field = $catReq = $limit = ''; 
    1130            
     1134 
    11311135          if (isset($params['cat_id']) && $params['cat_id'] !== '') { 
    11321136               $catReq = 'AND P.cat_id = '.(integer) $params['cat_id'].' '; 
     
    11391143               $catReq = 'AND P.post_lang = \''. $params['post_lang'].'\' '; 
    11401144          } 
    1141            
     1145 
    11421146          $strReq = 'SELECT DISTINCT('.$this->con->dateFormat('post_dt',$dt_f).') AS dt '. 
    11431147                    $cat_field. 
     
    11471151                    "WHERE P.blog_id = '".$this->con->escape($this->id)."' ". 
    11481152                    $catReq; 
    1149            
     1153 
    11501154          if (!$this->core->auth->check('contentadmin',$this->id)) { 
    11511155               $strReq .= 'AND ((post_status = 1 '; 
    1152                 
     1156 
    11531157               if ($this->without_password) { 
    11541158                    $strReq .= 'AND post_password IS NULL '; 
    11551159               } 
    11561160               $strReq .= ') '; 
    1157                 
     1161 
    11581162               if ($this->core->auth->userID()) { 
    11591163                    $strReq .= "OR P.user_id = '".$this->con->escape($this->core->auth->userID())."')"; 
     
    11621166               } 
    11631167          } 
    1164            
     1168 
    11651169          if (!empty($params['post_type'])) { 
    11661170               $strReq .= "AND post_type ".$this->con->in($params['post_type'])." "; 
     
    11681172               $strReq .= "AND post_type = 'post' "; 
    11691173          } 
    1170            
     1174 
    11711175          if (!empty($params['year'])) { 
    11721176               $strReq .= 'AND '.$this->con->dateFormat('post_dt','%Y')." = '".sprintf('%04d',$params['year'])."' "; 
    11731177          } 
    1174            
     1178 
    11751179          if (!empty($params['month'])) { 
    11761180               $strReq .= 'AND '.$this->con->dateFormat('post_dt','%m')." = '".sprintf('%02d',$params['month'])."' "; 
    11771181          } 
    1178            
     1182 
    11791183          if (!empty($params['day'])) { 
    11801184               $strReq .= 'AND '.$this->con->dateFormat('post_dt','%d')." = '".sprintf('%02d',$params['day'])."' "; 
    11811185          } 
    1182            
     1186 
    11831187          # Get next or previous date 
    11841188          if (!empty($params['next']) || !empty($params['previous'])) 
     
    11931197                    $dt = $params['previous']; 
    11941198               } 
    1195                 
     1199 
    11961200               $dt = date('YmdHis',strtotime($dt)); 
    1197                 
     1201 
    11981202               $strReq .= 'AND '.$this->con->dateFormat('post_dt',$dt_fc).$pdir."'".$dt."' "; 
    11991203               $limit = $this->con->limit(1); 
    12001204          } 
    1201            
     1205 
    12021206          $strReq .= 'GROUP BY dt '.$cat_field; 
    1203            
     1207 
    12041208          $order = 'desc'; 
    12051209          if (!empty($params['order']) && preg_match('/^(desc|asc)$/i',$params['order'])) { 
    12061210               $order = $params['order']; 
    12071211          } 
    1208            
     1212 
    12091213          $strReq .= 
    12101214          'ORDER BY dt '.$order.' '. 
    12111215          $limit; 
    1212            
     1216 
    12131217          $rs = $this->con->select($strReq); 
    12141218          $rs->extend('rsExtDates'); 
    12151219          return $rs; 
    12161220     } 
    1217       
     1221 
    12181222     /** 
    12191223     Creates a new entry. Takes a cursor as input and returns the new entry 
    12201224     ID. 
    1221       
     1225 
    12221226     @param    cur       <b>cursor</b>       Post cursor 
    12231227     @return   <b>integer</b>      New post ID 
     
    12281232               throw new Exception(__('You are not allowed to create an entry')); 
    12291233          } 
    1230            
     1234 
    12311235          $this->con->writeLock($this->prefix.'post'); 
    12321236          try 
     
    12351239               $rs = $this->con->select( 
    12361240                    'SELECT MAX(post_id) '. 
    1237                     'FROM '.$this->prefix.'post '  
     1241                    'FROM '.$this->prefix.'post ' 
    12381242                    ); 
    1239                 
     1243 
    12401244               $cur->post_id = (integer) $rs->f(0) + 1; 
    12411245               $cur->blog_id = (string) $this->id; 
     
    12431247               $cur->post_upddt = date('Y-m-d H:i:s'); 
    12441248               $cur->post_tz = $this->core->auth->getInfo('user_tz'); 
    1245                 
     1249 
    12461250               # Post excerpt and content 
    12471251               $this->getPostContent($cur,$cur->post_id); 
    1248                 
     1252 
    12491253               $this->getPostCursor($cur); 
    1250                 
     1254 
    12511255               $cur->post_url = $this->getPostURL($cur->post_url,$cur->post_dt,$cur->post_title,$cur->post_id); 
    1252                 
     1256 
    12531257               if (!$this->core->auth->check('publish,contentadmin',$this->id)) { 
    12541258                    $cur->post_status = -2; 
    12551259               } 
    1256                 
     1260 
    12571261               # --BEHAVIOR-- coreBeforePostCreate 
    12581262               $this->core->callBehavior('coreBeforePostCreate',$this,$cur); 
    1259                 
     1263 
    12601264               $cur->insert(); 
    12611265               $this->con->unlock(); 
     
    12661270               throw $e; 
    12671271          } 
    1268            
     1272 
    12691273          # --BEHAVIOR-- coreAfterPostCreate 
    12701274          $this->core->callBehavior('coreAfterPostCreate',$this,$cur); 
    1271            
     1275 
    12721276          $this->triggerBlog(); 
    1273            
     1277 
    12741278          return $cur->post_id; 
    12751279     } 
    1276       
     1280 
    12771281     /** 
    12781282     Updates an existing post. 
    1279       
     1283 
    12801284     @param    id        <b>integer</b>      Post ID 
    12811285     @param    cur       <b>cursor</b>       Post cursor 
     
    12861290               throw new Exception(__('You are not allowed to update entries')); 
    12871291          } 
    1288            
     1292 
    12891293          $id = (integer) $id; 
    1290            
     1294 
    12911295          if (empty($id)) { 
    12921296               throw new Exception(__('No such entry ID')); 
    12931297          } 
    1294            
     1298 
    12951299          # Post excerpt and content 
    12961300          $this->getPostContent($cur,$id); 
    1297            
     1301 
    12981302          $this->getPostCursor($cur); 
    1299            
     1303 
    13001304          if ($cur->post_url !== null) { 
    13011305               $cur->post_url = $this->getPostURL($cur->post_url,$cur->post_dt,$cur->post_title,$id); 
    13021306          } 
    1303            
     1307 
    13041308          if (!$this->core->auth->check('publish,contentadmin',$this->id)) { 
    13051309               $cur->unsetField('post_status'); 
    13061310          } 
    1307            
     1311 
    13081312          $cur->post_upddt = date('Y-m-d H:i:s'); 
    1309            
     1313 
    13101314          #If user is only "usage", we need to check the post's owner 
    13111315          if (!$this->core->auth->check('contentadmin',$this->id)) 
     
    13151319                         'WHERE post_id = '.$id.' '. 
    13161320                         "AND user_id = '".$this->con->escape($this->core->auth->userID())."' "; 
    1317                 
     1321 
    13181322               $rs = $this->con->select($strReq); 
    1319                 
     1323 
    13201324               if ($rs->isEmpty()) { 
    13211325                    throw new Exception(__('You are not allowed to edit this entry')); 
    13221326               } 
    13231327          } 
    1324            
     1328 
    13251329          # --BEHAVIOR-- coreBeforePostUpdate 
    13261330          $this->core->callBehavior('coreBeforePostUpdate',$this,$cur); 
    1327            
     1331 
    13281332          $cur->update('WHERE post_id = '.$id.' '); 
    1329            
     1333 
    13301334          # --BEHAVIOR-- coreAfterPostUpdate 
    13311335          $this->core->callBehavior('coreAfterPostUpdate',$this,$cur); 
    1332            
     1336 
    13331337          $this->triggerBlog(); 
    13341338     } 
    1335       
     1339 
    13361340     /** 
    13371341     Updates post status. 
    1338       
     1342 
    13391343     @param    id        <b>integer</b>      Post ID 
    13401344     @param    status    <b>integer</b>      Post status 
     
    13441348          $this->updPostsStatus($id,$status); 
    13451349     } 
    1346       
     1350 
    13471351     /** 
    13481352     Updates posts status. 
    1349       
     1353 
    13501354     @param    ids       <b>mixed</b>        Post(s) ID(s) 
    13511355     @param    status    <b>integer</b>      Post status 
     
    13561360               throw new Exception(__('You are not allowed to change this entry status')); 
    13571361          } 
    1358            
     1362 
    13591363          $posts_ids = dcUtils::cleanIds($ids); 
    13601364          $status = (integer) $status; 
    1361            
     1365 
    13621366          $strReq = "WHERE blog_id = '".$this->con->escape($this->id)."' ". 
    13631367                    "AND post_id ".$this->con->in($posts_ids); 
    1364            
     1368 
    13651369          #If user can only publish, we need to check the post's owner 
    13661370          if (!$this->core->auth->check('contentadmin',$this->id)) 
     
    13681372               $strReq .= "AND user_id = '".$this->con->escape($this->core->auth->userID())."' "; 
    13691373          } 
    1370            
     1374 
    13711375          $cur = $this->con->openCursor($this->prefix.'post'); 
    1372            
     1376 
    13731377          $cur->post_status = $status; 
    13741378          $cur->post_upddt = date('Y-m-d H:i:s'); 
    1375            
     1379 
    13761380          $cur->update($strReq); 
    13771381          $this->triggerBlog(); 
    13781382     } 
    1379       
     1383 
    13801384     /** 
    13811385     Updates post selection. 
    1382       
     1386 
    13831387     @param    id        <b>integer</b>      Post ID 
    13841388     @param    selected  <b>integer</b>      Is selected post 
     
    13881392          $this->updPostsSelected($id,$selected); 
    13891393     } 
    1390       
     1394 
    13911395     /** 
    13921396     Updates posts selection. 
    1393       
     1397 
    13941398     @param    ids       <b>mixed</b>        Post(s) ID(s) 
    13951399     @param    selected  <b>integer</b>      Is selected post(s) 
     
    14001404               throw new Exception(__('You are not allowed to change this entry category')); 
    14011405          } 
    1402            
     1406 
    14031407          $posts_ids = dcUtils::cleanIds($ids); 
    14041408          $selected = (boolean) $selected; 
    1405            
     1409 
    14061410          $strReq = "WHERE blog_id = '".$this->con->escape($this->id)."' ". 
    14071411                    "AND post_id ".$this->con->in($posts_ids); 
    1408            
     1412 
    14091413          # If user is only usage, we need to check the post's owner 
    14101414          if (!$this->core->auth->check('contentadmin',$this->id)) 
     
    14121416               $strReq .= "AND user_id = '".$this->con->escape($this->core->auth->userID())."' "; 
    14131417          } 
    1414            
     1418 
    14151419          $cur = $this->con->openCursor($this->prefix.'post'); 
    1416            
     1420 
    14171421          $cur->post_selected = (integer) $selected; 
    14181422          $cur->post_upddt = date('Y-m-d H:i:s'); 
    1419            
     1423 
    14201424          $cur->update($strReq); 
    14211425          $this->triggerBlog(); 
    14221426     } 
    1423       
     1427 
    14241428     /** 
    14251429     Updates post category. <var>$cat_id</var> can be null. 
    1426       
     1430 
    14271431     @param    id        <b>integer</b>      Post ID 
    14281432     @param    cat_id    <b>integer</b>      Category ID 
     
    14321436          $this->updPostsCategory($id,$cat_id); 
    14331437     } 
    1434       
     1438 
    14351439     /** 
    14361440     Updates posts category. <var>$cat_id</var> can be null. 
    1437       
     1441 
    14381442     @param    ids       <b>mixed</b>        Post(s) ID(s) 
    14391443     @param    cat_id    <b>integer</b>      Category ID 
     
    14441448               throw new Exception(__('You are not allowed to change this entry category')); 
    14451449          } 
    1446            
     1450 
    14471451          $posts_ids = dcUtils::cleanIds($ids); 
    14481452          $cat_id = (integer) $cat_id; 
    1449            
     1453 
    14501454          $strReq = "WHERE blog_id = '".$this->con->escape($this->id)."' ". 
    14511455                    "AND post_id ".$this->con->in($posts_ids); 
    1452            
     1456 
    14531457          # If user is only usage, we need to check the post's owner 
    14541458          if (!$this->core->auth->check('contentadmin',$this->id)) 
     
    14561460               $strReq .= "AND user_id = '".$this->con->escape($this->core->auth->userID())."' "; 
    14571461          } 
    1458            
     1462 
    14591463          $cur = $this->con->openCursor($this->prefix.'post'); 
    1460            
     1464 
    14611465          $cur->cat_id = ($cat_id ? $cat_id : null); 
    14621466          $cur->post_upddt = date('Y-m-d H:i:s'); 
    1463            
     1467 
    14641468          $cur->update($strReq); 
    14651469          $this->triggerBlog(); 
    14661470     } 
    1467       
     1471 
    14681472     /** 
    14691473     Updates posts category. <var>$new_cat_id</var> can be null. 
    1470       
     1474 
    14711475     @param    old_cat_id     <b>integer</b>      Old category ID 
    14721476     @param    new_cat_id     <b>integer</b>      New category ID 
     
    14771481               throw new Exception(__('You are not allowed to change entries category')); 
    14781482          } 
    1479            
     1483 
    14801484          $old_cat_id = (integer) $old_cat_id; 
    14811485          $new_cat_id = (integer) $new_cat_id; 
    1482            
     1486 
    14831487          $cur = $this->con->openCursor($this->prefix.'post'); 
    1484            
     1488 
    14851489          $cur->cat_id = ($new_cat_id ? $new_cat_id : null); 
    14861490          $cur->post_upddt = date('Y-m-d H:i:s'); 
    1487            
     1491 
    14881492          $cur->update( 
    14891493               'WHERE cat_id = '.$old_cat_id.' '. 
     
    14921496          $this->triggerBlog(); 
    14931497     } 
    1494       
     1498 
    14951499     /** 
    14961500     Deletes a post. 
    1497       
     1501 
    14981502     @param    id        <b>integer</b>      Post ID 
    14991503     */ 
     
    15021506          $this->delPosts($id); 
    15031507     } 
    1504       
     1508 
    15051509     /** 
    15061510     Deletes multiple posts. 
    1507       
     1511 
    15081512     @param    ids       <b>mixed</b>        Post(s) ID(s) 
    15091513     */ 
     
    15131517               throw new Exception(__('You are not allowed to delete entries')); 
    15141518          } 
    1515            
     1519 
    15161520          $posts_ids = dcUtils::cleanIds($ids); 
    1517            
     1521 
    15181522          if (empty($posts_ids)) { 
    15191523               throw new Exception(__('No such entry ID')); 
    15201524          } 
    1521            
     1525 
    15221526          $strReq = 'DELETE FROM '.$this->prefix.'post '. 
    15231527                    "WHERE blog_id = '".$this->con->escape($this->id)."' ". 
    15241528                    "AND post_id ".$this->con->in($posts_ids); 
    1525            
     1529 
    15261530          #If user can only delete, we need to check the post's owner 
    15271531          if (!$this->core->auth->check('contentadmin',$this->id)) 
     
    15291533               $strReq .= "AND user_id = '".$this->con->escape($this->core->auth->userID())."' "; 
    15301534          } 
    1531            
     1535 
    15321536          $this->con->execute($strReq); 
    15331537          $this->triggerBlog(); 
    15341538     } 
    1535       
     1539 
    15361540     /** 
    15371541     Publishes all entries flaged as "scheduled". 
     
    15431547                    'WHERE post_status = -1 '. 
    15441548                    "AND blog_id = '".$this->con->escape($this->id)."' "; 
    1545            
     1549 
    15461550          $rs = $this->con->select($strReq); 
    1547            
     1551 
    15481552          $now = dt::toUTC(time()); 
    15491553          $to_change = new ArrayObject(); 
     
    15521556               return; 
    15531557          } 
    1554            
     1558 
    15551559          while ($rs->fetch()) 
    15561560          { 
    15571561               # Now timestamp with post timezone 
    15581562               $now_tz = $now + dt::getTimeOffset($rs->post_tz,$now); 
    1559                 
     1563 
    15601564               # Post timestamp 
    15611565               $post_ts = strtotime($rs->post_dt); 
    1562                 
     1566 
    15631567               # If now_tz >= post_ts, we publish the entry 
    15641568               if ($now_tz >= $post_ts) { 
     
    15821586               $this->core->callBehavior('coreAfterScheduledEntriesPublish',$this,$to_change); 
    15831587          } 
    1584            
    1585      } 
    1586       
     1588 
     1589     } 
     1590 
    15871591     /** 
    15881592     Retrieves all users having posts on current blog. 
    1589       
     1593 
    15901594     @param    post_type      <b>string</b>       post_type filter (post) 
    15911595     @return   record 
     
    15981602                    'WHERE P.user_id = U.user_id '. 
    15991603                    "AND blog_id = '".$this->con->escape($this->id)."' "; 
    1600            
     1604 
    16011605          if ($post_type) { 
    16021606               $strReq .= "AND post_type = '".$this->con->escape($post_type)."' "; 
    16031607          } 
    1604            
     1608 
    16051609          $strReq .= 'GROUP BY P.user_id, user_name, user_firstname, user_displayname, user_email '; 
    1606            
     1610 
    16071611          return $this->con->select($strReq); 
    16081612     } 
    1609       
     1613 
    16101614     private function getPostsCategoryFilter($arr,$field='cat_id') 
    16111615     { 
    16121616          $field = $field == 'cat_id' ? 'cat_id' : 'cat_url'; 
    1613            
     1617 
    16141618          $sub = array(); 
    16151619          $not = array(); 
    16161620          $queries = array(); 
    1617            
     1621 
    16181622          foreach ($arr as $v) 
    16191623          { 
     
    16221626               $id = array_shift($args); 
    16231627               $args = array_flip($args); 
    1624                 
     1628 
    16251629               if (isset($args['not'])) { $not[$id] = 1; } 
    16261630               if (isset($args['sub'])) { $sub[$id] = 1; } 
     
    16361640               } 
    16371641          } 
    1638            
     1642 
    16391643          if (!empty($sub)) { 
    16401644               $rs = $this->con->select( 
     
    16431647                    'AND '.$field.' '.$this->con->in(array_keys($sub)) 
    16441648               ); 
    1645                 
     1649 
    16461650               while ($rs->fetch()) { 
    16471651                    $queries[$rs->f($field)] = '(C.cat_lft BETWEEN '.$rs->cat_lft.' AND '.$rs->cat_rgt.')'; 
    16481652               } 
    16491653          } 
    1650            
     1654 
    16511655          # Create queries 
    16521656          $sql = array( 
     
    16541658               1 => array()  # excluded categories 
    16551659          ); 
    1656            
     1660 
    16571661          foreach ($queries as $id => $q) { 
    16581662               $sql[(integer) isset($not[$id])][] = $q; 
    16591663          } 
    1660            
     1664 
    16611665          $sql[0] = implode(' OR ',$sql[0]); 
    16621666          $sql[1] = implode(' OR ',$sql[1]); 
    1663            
     1667 
    16641668          if ($sql[0]) { 
    16651669               $sql[0] = '('.$sql[0].')'; 
     
    16671671               unset($sql[0]); 
    16681672          } 
    1669            
     1673 
    16701674          if ($sql[1]) { 
    16711675               $sql[1] = '(P.cat_id IS NULL OR NOT('.$sql[1].'))'; 
     
    16731677               unset($sql[1]); 
    16741678          } 
    1675            
     1679 
    16761680          return implode(' AND ',$sql); 
    16771681     } 
    1678       
     1682 
    16791683     private function getPostCursor($cur,$post_id=null) 
    16801684     { 
     
    16821686               throw new Exception(__('No entry title')); 
    16831687          } 
    1684            
     1688 
    16851689          if ($cur->post_content == '') { 
    16861690               throw new Exception(__('No entry content')); 
    16871691          } 
    1688            
     1692 
    16891693          if ($cur->post_password === '') { 
    16901694               $cur->post_password = null; 
    16911695          } 
    1692            
     1696 
    16931697          if ($cur->post_dt == '') { 
    16941698               $offset = dt::getTimeOffset($this->core->auth->getInfo('user_tz')); 
     
    16961700               $cur->post_dt = date('Y-m-d H:i:00',$now); 
    16971701          } 
    1698            
     1702 
    16991703          $post_id = is_int($post_id) ? $post_id : $cur->post_id; 
    1700            
     1704 
    17011705          if ($cur->post_content_xhtml == '') { 
    17021706               throw new Exception(__('No entry content')); 
    17031707          } 
    1704            
     1708 
    17051709          # Words list 
    17061710          if ($cur->post_title !== null && $cur->post_excerpt_xhtml !== null 
     
    17111715               $cur->post_excerpt_xhtml.' '. 
    17121716               $cur->post_content_xhtml; 
    1713                 
     1717 
    17141718               $cur->post_words = implode(' ',text::splitWords($words)); 
    17151719          } 
    17161720     } 
    1717       
     1721 
    17181722     private function getPostContent($cur,$post_id) 
    17191723     { 
     
    17221726          $post_content = $cur->post_content; 
    17231727          $post_content_xhtml = $cur->post_content_xhtml; 
    1724            
     1728 
    17251729          $this->setPostContent( 
    17261730               $post_id,$cur->post_format,$cur->post_lang, 
     
    17281732               $post_content,$post_content_xhtml 
    17291733          ); 
    1730            
     1734 
    17311735          $cur->post_excerpt = $post_excerpt; 
    17321736          $cur->post_excerpt_xhtml = $post_excerpt_xhtml; 
     
    17341738          $cur->post_content_xhtml = $post_content_xhtml; 
    17351739     } 
    1736       
     1740 
    17371741     /** 
    17381742     Creates post HTML content, taking format and lang into account. 
    1739       
     1743 
    17401744     @param         post_id        <b>integer</b>      Post ID 
    17411745     @param         format         <b>string</b>       Post format 
     
    17711775               } 
    17721776          } 
    1773            
     1777 
    17741778          if ($excerpt) { 
    17751779               $excerpt_xhtml = $this->core->callFormater($format,$excerpt); 
     
    17781782               $excerpt_xhtml = ''; 
    17791783          } 
    1780            
     1784 
    17811785          if ($content) { 
    17821786               $content_xhtml = $this->core->callFormater($format,$content); 
     
    17851789               $content_xhtml = ''; 
    17861790          } 
    1787            
     1791 
    17881792          # --BEHAVIOR-- coreAfterPostContentFormat 
    17891793          $this->core->callBehavior('coreAfterPostContentFormat',array( 
     
    17941798          )); 
    17951799     } 
    1796       
     1800 
    17971801     /** 
    17981802     Returns URL for a post according to blog setting <var>post_url_format</var>. 
    17991803     It will try to guess URL and append some figures if needed. 
    1800       
     1804 
    18011805     @param    url            <b>string</b>       Origin URL, could be empty 
    18021806     @param    post_dt        <b>string</b>       Post date (in YYYY-MM-DD HH:mm:ss) 
     
    18081812     { 
    18091813          $url = trim($url); 
    1810            
     1814 
    18111815          $url_patterns = array( 
    18121816          '{y}' => date('Y',strtotime($post_dt)), 
     
    18161820          '{id}' => (integer) $post_id 
    18171821          ); 
    1818            
     1822 
    18191823          # If URL is empty, we create a new one 
    18201824          if ($url == '') 
     
    18311835               $url = text::tidyURL($url); 
    18321836          } 
    1833            
     1837 
    18341838          # Let's check if URL is taken... 
    18351839          $strReq = 'SELECT post_url FROM '.$this->prefix.'post '. 
     
    18381842                    "AND blog_id = '".$this->con->escape($this->id)."' ". 
    18391843                    'ORDER BY post_url DESC'; 
    1840            
     1844 
    18411845          $rs = $this->con->select($strReq); 
    1842            
     1846 
    18431847          if (!$rs->isEmpty()) 
    18441848          { 
     
    18551859                         "AND blog_id = '".$this->con->escape($this->id)."' ". 
    18561860                         'ORDER BY post_url DESC '; 
    1857                 
     1861 
    18581862               $rs = $this->con->select($strReq); 
    18591863               $a = array(); 
     
    18611865                    $a[] = $rs->post_url; 
    18621866               } 
    1863                 
     1867 
    18641868               natsort($a); 
    18651869               $t_url = end($a); 
    1866                 
     1870 
    18671871               if (preg_match('/(.*?)([0-9]+)$/',$t_url,$m)) { 
    18681872                    $i = (integer) $m[2]; 
     
    18711875                    $i = 1; 
    18721876               } 
    1873                 
     1877 
    18741878               return $url.($i+1); 
    18751879          } 
    1876            
     1880 
    18771881          # URL is empty? 
    18781882          if ($url == '') { 
    18791883               throw new Exception(__('Empty entry URL')); 
    18801884          } 
    1881            
     1885 
    18821886          return $url; 
    18831887     } 
    18841888     //@} 
    1885       
     1889 
    18861890     /// @name Comments management methods 
    18871891     //@{ 
     
    18891893     Retrieves comments. <b>$params</b> is an array taking the following 
    18901894     optionnal parameters: 
    1891       
     1895 
    18921896     - no_content: Don't retrieve comment content 
    1893      - post_type: Get only entries with given type (default no type, array for many types)  
     1897     - post_type: Get only entries with given type (default no type, array for many types) 
    18941898     - post_id: (integer) Get comments belonging to given post_id 
    18951899     - cat_id: (integer or array) Get comments belonging to entries of given category ID 
     
    19071911     - limit: Limit parameter 
    19081912     - sql_only : return the sql request instead of results. Only ids are selected 
    1909       
     1913 
    19101914     @param    params         <b>array</b>        Parameters 
    19111915     @param    count_only     <b>boolean</b>      Only counts results 
     
    19181922               $strReq = 'SELECT count(comment_id) '; 
    19191923          } 
    1920           elseif (!empty($params['sql_only']))  
     1924          elseif (!empty($params['sql_only'])) 
    19211925          { 
    19221926               $strReq = 'SELECT P.post_id '; 
     
    19291933                    $content_req = 'comment_content, '; 
    19301934               } 
    1931                 
     1935 
    19321936               if (!empty($params['columns']) && is_array($params['columns'])) { 
    19331937                    $content_req .= implode(', ',$params['columns']).', '; 
    19341938               } 
    1935                 
     1939 
    19361940               $strReq = 
    19371941               'SELECT C.comment_id, comment_dt, comment_tz, comment_upddt, '. 
     
    19421946               'P.post_dt, P.user_id, U.user_email, U.user_url '; 
    19431947          } 
    1944            
     1948 
    19451949          $strReq .= 
    19461950          'FROM '.$this->prefix.'comment C '. 
    19471951          'INNER JOIN '.$this->prefix.'post P ON C.post_id = P.post_id '. 
    19481952          'INNER JOIN '.$this->prefix.'user U ON P.user_id = U.user_id '; 
    1949            
     1953 
    19501954          if (!empty($params['from'])) { 
    19511955               $strReq .= $params['from'].' '; 
    19521956          } 
    1953            
     1957 
    19541958          $strReq .= 
    19551959          "WHERE P.blog_id = '".$this->con->escape($this->id)."' "; 
    1956            
     1960 
    19571961          if (!$this->core->auth->check('contentadmin',$this->id)) { 
    19581962               $strReq .= 'AND ((comment_status = 1 AND P.post_status = 1 '; 
    1959                 
     1963 
    19601964               if ($this->without_password) { 
    19611965                    $strReq .= 'AND post_password IS NULL '; 
    19621966               } 
    19631967               $strReq .= ') '; 
    1964                 
     1968 
    19651969               if ($this->core->auth->userID()) { 
    19661970                    $strReq .= "OR P.user_id = '".$this->con->escape($this->core->auth->userID())."')"; 
     
    19691973               } 
    19701974          } 
    1971            
     1975 
    19721976          if (!empty($params['post_type'])) 
    19731977          { 
    19741978               $strReq .= 'AND post_type '.$this->con->in($params['post_type']); 
    19751979          } 
    1976            
     1980 
    19771981          if (isset($params['post_id']) && $params['post_id'] !== '') { 
    19781982               $strReq .= 'AND P.post_id = '.(integer) $params['post_id'].' '; 
    19791983          } 
    1980            
     1984 
    19811985          if (isset($params['cat_id']) && $params['cat_id'] !== '') { 
    19821986               $strReq .= 'AND P.cat_id = '.(integer) $params['cat_id'].' '; 
    19831987          } 
    1984            
     1988 
    19851989          if (isset($params['comment_id']) && $params['comment_id'] !== '') { 
    19861990               if (is_array($params['comment_id'])) { 
     
    19911995               $strReq .= 'AND comment_id '.$this->con->in($params['comment_id']); 
    19921996          } 
    1993            
     1997 
    19941998          if (isset($params['comment_site'])) { 
    19951999               $comment_site = $this->con->escape(str_replace('*','%',$params['comment_site'])); 
    19962000               $strReq .= "AND comment_site LIKE '".$comment_site."' "; 
    19972001          } 
    1998            
     2002 
    19992003          if (isset($params['comment_status'])) { 
    20002004               $strReq .= 'AND comment_status = '.(integer) $params['comment_status'].' '; 
    20012005          } 
    2002            
     2006 
    20032007          if (!empty($params['comment_status_not'])) 
    20042008          { 
    20052009               $strReq .= 'AND comment_status <> '.(integer) $params['comment_status_not'].' '; 
    20062010          } 
    2007            
     2011 
    20082012          if (isset($params['comment_trackback'])) { 
    20092013               $strReq .= 'AND comment_trackback = '.(integer) (boolean) $params['comment_trackback'].' '; 
    20102014          } 
    2011            
     2015 
    20122016          if (isset($params['comment_ip'])) { 
    20132017               $comment_ip = $this->con->escape(str_replace('*','%',$params['comment_ip'])); 
    20142018               $strReq .= "AND comment_ip LIKE '".$comment_ip."' "; 
    20152019          } 
    2016            
     2020 
    20172021          if (isset($params['q_author'])) { 
    20182022               $q_author = $this->con->escape(str_replace('*','%',strtolower($params['q_author']))); 
    20192023               $strReq .= "AND LOWER(comment_author) LIKE '".$q_author."' "; 
    20202024          } 
    2021            
     2025 
    20222026          if (!empty($params['search'])) 
    20232027          { 
    20242028               $words = text::splitWords($params['search']); 
    2025                 
     2029 
    20262030               if (!empty($words)) 
    20272031               { 
     
    20302034                         $this->core->callBehavior('coreCommentSearch',$this->core,array(&$words,&$strReq,&$params)); 
    20312035                    } 
    2032                      
     2036 
    20332037                    if ($words) 
    20342038                    { 
     
    20402044               } 
    20412045          } 
    2042            
     2046 
    20432047          if (!empty($params['sql'])) { 
    20442048               $strReq .= $params['sql'].' '; 
    20452049          } 
    2046            
     2050 
    20472051          if (!$count_only) 
    20482052          { 
     
    20532057               } 
    20542058          } 
    2055            
     2059 
    20562060          if (!$count_only && !empty($params['limit'])) { 
    20572061               $strReq .= $this->con->limit($params['limit']); 
     
    20612065               return $strReq; 
    20622066          } 
    2063            
     2067 
    20642068          $rs = $this->con->select($strReq); 
    20652069          $rs->core = $this->core; 
    20662070          $rs->extend('rsExtComment'); 
    2067            
     2071 
    20682072          # --BEHAVIOR-- coreBlogGetComments 
    20692073          $this->core->callBehavior('coreBlogGetComments',$rs); 
    2070            
     2074 
    20712075          return $rs; 
    20722076     } 
    2073       
     2077 
    20742078     /** 
    20752079     Creates a new comment. Takes a cursor as input and returns the new comment 
    20762080     ID. 
    2077       
     2081 
    20782082     @param    cur       <b>cursor</b>       Comment cursor 
    20792083     @return   <b>integer</b>      New comment ID 
     
    20872091               $rs = $this->con->select( 
    20882092                    'SELECT MAX(comment_id) '. 
    2089                     'FROM '.$this->prefix.'comment '  
     2093                    'FROM '.$this->prefix.'comment ' 
    20902094               ); 
    2091                 
     2095 
    20922096               $cur->comment_id = (integer) $rs->f(0) + 1; 
    20932097               $cur->comment_upddt = date('Y-m-d H:i:s'); 
    2094                 
     2098 
    20952099               $offset = dt::getTimeOffset($this->settings->system->blog_timezone); 
    20962100               $cur->comment_dt = date('Y-m-d H:i:s',time() + $offset); 
    20972101               $cur->comment_tz = $this->settings->system->blog_timezone; 
    2098                 
     2102 
    20992103               $this->getCommentCursor($cur); 
    2100                 
     2104 
    21012105               if ($cur->comment_ip === null) { 
    21022106                    $cur->comment_ip = http::realIP(); 
    21032107               } 
    2104                 
     2108 
    21052109               # --BEHAVIOR-- coreBeforeCommentCreate 
    21062110               $this->core->callBehavior('coreBeforeCommentCreate',$this,$cur); 
    2107                 
     2111 
    21082112               $cur->insert(); 
    21092113               $this->con->unlock(); 
     
    21142118               throw $e; 
    21152119          } 
    2116            
     2120 
    21172121          # --BEHAVIOR-- coreAfterCommentCreate 
    21182122          $this->core->callBehavior('coreAfterCommentCreate',$this,$cur); 
    2119            
     2123 
    21202124          $this->triggerComment($cur->comment_id); 
    21212125          if ($cur->comment_status != -2) { 
    21222126               $this->triggerBlog(); 
    2123           }     
     2127          } 
    21242128          return $cur->comment_id; 
    21252129     } 
    2126       
     2130 
    21272131     /** 
    21282132     Updates an existing comment. 
    2129       
     2133 
    21302134     @param    id        <b>integer</b>      Comment ID 
    21312135     @param    cur       <b>cursor</b>       Comment cursor 
     
    21362140               throw new Exception(__('You are not allowed to update comments')); 
    21372141          } 
    2138            
     2142 
    21392143          $id = (integer) $id; 
    2140            
     2144 
    21412145          if (empty($id)) { 
    21422146               throw new Exception(__('No such comment ID')); 
    21432147          } 
    2144            
     2148 
    21452149          $rs = $this->getComments(array('comment_id' => $id)); 
    2146            
     2150 
    21472151          if ($rs->isEmpty()) { 
    21482152               throw new Exception(__('No such comment ID')); 
    21492153          } 
    2150            
     2154 
    21512155          #If user is only usage, we need to check the post's owner 
    21522156          if (!$this->core->auth->check('contentadmin',$this->id)) 
     
    21562160               } 
    21572161          } 
    2158            
     2162 
    21592163          $this->getCommentCursor($cur); 
    2160            
     2164 
    21612165          $cur->comment_upddt = date('Y-m-d H:i:s'); 
    2162            
     2166 
    21632167          if (!$this->core->auth->check('publish,contentadmin',$this->id)) { 
    21642168               $cur->unsetField('comment_status'); 
    21652169          } 
    2166            
     2170 
    21672171          # --BEHAVIOR-- coreBeforeCommentUpdate 
    21682172          $this->core->callBehavior('coreBeforeCommentUpdate',$this,$cur,$rs); 
    2169            
     2173 
    21702174          $cur->update('WHERE comment_id = '.$id.' '); 
    2171            
     2175 
    21722176          # --BEHAVIOR-- coreAfterCommentUpdate 
    21732177          $this->core->callBehavior('coreAfterCommentUpdate',$this,$cur,$rs); 
    2174            
     2178 
    21752179          $this->triggerComment($id); 
    21762180          $this->triggerBlog(); 
    21772181     } 
    2178       
     2182 
    21792183     /** 
    21802184     Updates comment status. 
    2181       
     2185 
    21822186     @param    id        <b>integer</b>      Comment ID 
    21832187     @param    status    <b>integer</b>      Comment status 
     
    21872191          $this->updCommentsStatus($id,$status); 
    21882192     } 
    2189       
     2193 
    21902194     /** 
    21912195     Updates comments status. 
    2192       
     2196 
    21932197     @param    ids       <b>mixed</b>        Comment(s) ID(s) 
    21942198     @param    status    <b>integer</b>      Comment status 
     
    21992203               throw new Exception(__("You are not allowed to change this comment's status")); 
    22002204          } 
    2201            
     2205 
    22022206          $co_ids = dcUtils::cleanIds($ids); 
    22032207          $status = (integer) $status; 
    2204            
    2205           $strReq =  
     2208 
     2209          $strReq = 
    22062210               'UPDATE '.$this->prefix.'comment '. 
    22072211               'SET comment_status = '.$status.' '; 
    2208                $strReq .=  
     2212               $strReq .= 
    22092213               'WHERE comment_id'.$this->con->in($co_ids). 
    22102214               'AND post_id in (SELECT tp.post_id '. 
     
    22132217          if (!$this->core->auth->check('contentadmin',$this->id)) 
    22142218          { 
    2215                $strReq .=  
     2219               $strReq .= 
    22162220                    "AND user_id = '".$this->con->escape($this->core->auth->userID())."' "; 
    22172221          } 
     
    22212225          $this->triggerBlog(); 
    22222226     } 
    2223       
     2227 
    22242228     /** 
    22252229     Delete a comment 
    2226       
     2230 
    22272231     @param    id        <b>integer</b>      Comment ID 
    22282232     */ 
     
    22312235          $this->delComments($id); 
    22322236     } 
    2233       
     2237 
    22342238     /** 
    22352239     Delete comments 
    2236       
     2240 
    22372241     @param    ids       <b>mixed</b>        Comment(s) ID(s) 
    22382242     */ 
     
    22422246               throw new Exception(__('You are not allowed to delete comments')); 
    22432247          } 
    2244            
     2248 
    22452249          $co_ids = dcUtils::cleanIds($ids); 
    2246            
     2250 
    22472251          if (empty($co_ids)) { 
    22482252               throw new Exception(__('No such comment ID')); 
    22492253          } 
    2250            
     2254 
    22512255          # Retrieve posts affected by comments edition 
    22522256          $affected_posts = array(); 
     
    22562260               'WHERE comment_id'.$this->con->in($co_ids). 
    22572261               'GROUP BY post_id'; 
    2258            
     2262 
    22592263          $rs = $this->con->select($strReq); 
    2260            
     2264 
    22612265          while ($rs->fetch()) { 
    22622266               $affected_posts[] = (integer) $rs->post_id; 
    22632267          } 
    2264            
    2265                $strReq =  
     2268 
     2269               $strReq = 
    22662270               'DELETE FROM '.$this->prefix.'comment '. 
    22672271               'WHERE comment_id'.$this->con->in($co_ids).' '. 
     
    22722276          if (!$this->core->auth->check('contentadmin',$this->id)) 
    22732277          { 
    2274                $strReq .=  
     2278               $strReq .= 
    22752279                    "AND tp.user_id = '".$this->con->escape($this->core->auth->userID())."' "; 
    22762280          } 
     
    22862290               throw new Exception(__('You are not allowed to delete comments')); 
    22872291          } 
    2288            
    2289                $strReq =  
     2292 
     2293               $strReq = 
    22902294               'DELETE FROM '.$this->prefix.'comment '. 
    22912295               'WHERE comment_status = -2 '. 
     
    22962300          if (!$this->core->auth->check('contentadmin',$this->id)) 
    22972301          { 
    2298                $strReq .=  
     2302               $strReq .= 
    22992303                    "AND tp.user_id = '".$this->con->escape($this->core->auth->userID())."' "; 
    23002304          } 
     
    23032307          $this->triggerBlog(); 
    23042308     } 
    2305       
     2309 
    23062310     private function getCommentCursor($cur) 
    23072311     { 
     
    23092313               throw new Exception(__('You must provide a comment')); 
    23102314          } 
    2311            
     2315 
    23122316          if ($cur->comment_author !== null && $cur->comment_author == '') { 
    23132317               throw new Exception(__('You must provide an author name')); 
    23142318          } 
    2315            
     2319 
    23162320          if ($cur->comment_email != '' && !text::isEmail($cur->comment_email)) { 
    23172321               throw new Exception(__('Email address is not valid.')); 
    23182322          } 
    2319            
     2323 
    23202324          if ($cur->comment_site !== null && $cur->comment_site != '') { 
    23212325               if (!preg_match('|^http(s?)://|i',$cur->comment_site, $matches)) { 
     
    23252329               } 
    23262330          } 
    2327            
     2331 
    23282332          if ($cur->comment_status === null) { 
    23292333               $cur->comment_status = (integer) $this->settings->system->comments_pub; 
    23302334          } 
    2331            
     2335 
    23322336          # Words list 
    23332337          if ($cur->comment_content !== null) 
Note: See TracChangeset for help on using the changeset viewer.

Sites map