Dotclear

Changeset 2609:c26642f775e2 for inc/core


Ignore:
Timestamp:
12/10/13 09:00:09 (12 years ago)
Author:
Dsls
Branch:
twig
Parents:
2468:d7fda5a0bd39 (diff), 2608:3365c9df16a6 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge with default

Location:
inc/core
Files:
4 edited

Legend:

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

    r2468 r2609  
    44# This file is part of Dotclear 2. 
    55# 
    6 # Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear 
     6# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear 
    77# Licensed under the GPL version 2.0 license. 
    88# See LICENSE file or 
     
    8181               $this->desc = $b->blog_desc; 
    8282               $this->url = $b->blog_url; 
    83                $this->host = preg_replace('|^([a-z]{3,}://)(.*?)/.*$|','$1$2',$this->url); 
     83               $this->host = http::getHostFromURL($this->url); 
    8484               $this->creadt = strtotime($b->blog_creadt); 
    8585               $this->upddt = strtotime($b->blog_upddt); 
     
    963963                    $strReq .= 'ORDER BY post_dt DESC '; 
    964964               } 
    965                if (!empty($params['limit'])) { 
     965          } 
     966 
     967          if (!$count_only && !empty($params['limit'])) { 
    966968                    $strReq .= $this->con->limit($params['limit']); 
    967969               } 
    968           } 
    969970           
    970971          if (!empty($params['sql_only'])) { 
     
    18931894     - post_id: (integer) Get comments belonging to given post_id 
    18941895     - cat_id: (integer or array) Get comments belonging to entries of given category ID 
    1895      - comment_id: (integer) Get comment with given ID 
     1896     - comment_id: (integer or array) Get comment with given ID (or IDs) 
    18961897     - comment_site: (string) Get comments with given comment_site 
    18971898     - comment_status: (integer) Get comments with given comment_status 
     
    19831984           
    19841985          if (isset($params['comment_id']) && $params['comment_id'] !== '') { 
    1985                $strReq .= 'AND comment_id = '.(integer) $params['comment_id'].' '; 
     1986               if (is_array($params['comment_id'])) { 
     1987                    array_walk($params['comment_id'],create_function('&$v,$k','if($v!==null){$v=(integer)$v;}')); 
     1988               } else { 
     1989                    $params['comment_id'] = array((integer) $params['comment_id']); 
     1990               } 
     1991               $strReq .= 'AND comment_id '.$this->con->in($params['comment_id']); 
    19861992          } 
    19871993           
     
    23792385     //@} 
    23802386} 
    2381 ?> 
  • inc/core/class.dc.blog.php

    r2567 r2609  
    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->escape($params['user_id'])."' "; 
    868           } 
    869  
     867               $strReq .= "AND U.user_id ".$this->con->in($params['user_id'])." "; 
     868          } 
     869           
    870870          if (isset($params['cat_id']) && $params['cat_id'] !== '') 
    871871          { 
     
    888888               $strReq .= 'AND '.$this->getPostsCategoryFilter($params['cat_url'],'cat_url').' '; 
    889889          } 
    890  
     890           
    891891          /* Other filters */ 
    892892          if (isset($params['post_status'])) { 
    893893               $strReq .= 'AND post_status = '.(integer) $params['post_status'].' '; 
    894894          } 
    895  
     895           
    896896          if (isset($params['post_selected'])) { 
    897897               $strReq .= 'AND post_selected = '.(integer) $params['post_selected'].' '; 
    898898          } 
    899  
     899           
    900900          if (!empty($params['post_year'])) { 
    901901               $strReq .= 'AND '.$this->con->dateFormat('post_dt','%Y').' = '. 
    902902               "'".sprintf('%04d',$params['post_year'])."' "; 
    903903          } 
    904  
     904           
    905905          if (!empty($params['post_month'])) { 
    906906               $strReq .= 'AND '.$this->con->dateFormat('post_dt','%m').' = '. 
    907907               "'".sprintf('%02d',$params['post_month'])."' "; 
    908908          } 
    909  
     909           
    910910          if (!empty($params['post_day'])) { 
    911911               $strReq .= 'AND '.$this->con->dateFormat('post_dt','%d').' = '. 
    912912               "'".sprintf('%02d',$params['post_day'])."' "; 
    913913          } 
    914  
     914           
    915915          if (!empty($params['post_lang'])) { 
    916916               $strReq .= "AND P.post_lang = '".$this->con->escape($params['post_lang'])."' "; 
    917917          } 
    918  
     918           
    919919          if (!empty($params['search'])) 
    920920          { 
    921921               $words = text::splitWords($params['search']); 
    922  
     922                
    923923               if (!empty($words)) 
    924924               { 
     
    927927                         $this->core->callBehavior('corePostSearch',$this->core,array(&$words,&$strReq,&$params)); 
    928928                    } 
    929  
     929                     
    930930                    if ($words) 
    931931                    { 
     
    937937               } 
    938938          } 
    939  
     939           
    940940          if (isset($params['media'])) { 
    941941               if ($params['media'] == '0') { 
    942942                    $strReq .= 'AND NOT '; 
    943943               } else { 
    944                     $strReq .= 'AND '; 
     944                    $strReq .= 'AND ';                  
    945945               } 
    946946               $strReq .= 'EXISTS (SELECT M.post_id FROM '.$this->prefix.'post_media M '. 
     
    966966 
    967967          if (!$count_only && !empty($params['limit'])) { 
    968                $strReq .= $this->con->limit($params['limit']); 
    969           } 
    970  
     968                    $strReq .= $this->con->limit($params['limit']); 
     969               } 
     970           
    971971          if (!empty($params['sql_only'])) { 
    972972               return $strReq; 
     
    977977          $rs->_nb_media = array(); 
    978978          $rs->extend('rsExtPost'); 
    979  
     979           
    980980          # --BEHAVIOR-- coreBlogGetPosts 
    981981          $this->core->callBehavior('coreBlogGetPosts',$rs); 
    982  
     982           
    983983          return $rs; 
    984984     } 
    985  
     985      
    986986     /** 
    987987     Returns a record with post id, title and date for next or previous post 
    988988     according to the post ID. 
    989989     $dir could be 1 (next post) or -1 (previous post). 
    990  
     990      
    991991     @param    post_id                  <b>integer</b>      Post ID 
    992992     @param    dir                      <b>integer</b>      Search direction 
     
    999999          $dt = $post->post_dt; 
    10001000          $post_id = (integer) $post->post_id; 
    1001  
     1001           
    10021002          if($dir > 0) { 
    10031003               $sign = '>'; 
     
    10081008               $order = 'DESC'; 
    10091009          } 
    1010  
     1010           
    10111011          $params['post_type'] = $post->post_type; 
    10121012          $params['limit'] = 1; 
     
    10171017          "    OR post_dt ".$sign." '".$this->con->escape($dt)."' ". 
    10181018          ') '; 
    1019  
     1019           
    10201020          if ($restrict_to_category) { 
    10211021               $params['sql'] .= $post->cat_id ? 'AND P.cat_id = '.(integer) $post->cat_id.' ' : 'AND P.cat_id IS NULL '; 
    10221022          } 
    1023  
     1023           
    10241024          if ($restrict_to_lang) { 
    10251025               $params['sql'] .= $post->post_lang ? 'AND P.post_lang = \''. $this->con->escape($post->post_lang) .'\' ': 'AND P.post_lang IS NULL '; 
    10261026          } 
    1027  
     1027           
    10281028          $rs = $this->getPosts($params); 
    1029  
     1029           
    10301030          if ($rs->isEmpty()) { 
    10311031               return null; 
    10321032          } 
    1033  
     1033           
    10341034          return $rs; 
    10351035     } 
    1036  
     1036      
    10371037     /** 
    10381038     Retrieves different languages and post count on blog, based on post_lang 
    10391039     field. <var>$params</var> is an array taking the following optionnal 
    10401040     parameters: 
    1041  
     1041      
    10421042     - post_type: Get only entries with given type (default "post", '' for no type) 
    10431043     - lang: retrieve post count for selected lang 
    10441044     - order: order statement (default post_lang DESC) 
    1045  
     1045      
    10461046     @param    params    <b>array</b>        Parameters 
    10471047     @return   record 
     
    10541054                    "AND post_lang <> '' ". 
    10551055                    "AND post_lang IS NOT NULL "; 
    1056  
     1056           
    10571057          if (!$this->core->auth->check('contentadmin',$this->id)) { 
    10581058               $strReq .= 'AND ((post_status = 1 '; 
    1059  
     1059                
    10601060               if ($this->without_password) { 
    10611061                    $strReq .= 'AND post_password IS NULL '; 
    10621062               } 
    10631063               $strReq .= ') '; 
    1064  
     1064                
    10651065               if ($this->core->auth->userID()) { 
    10661066                    $strReq .= "OR user_id = '".$this->con->escape($this->core->auth->userID())."')"; 
     
    10691069               } 
    10701070          } 
    1071  
     1071           
    10721072          if (isset($params['post_type'])) { 
    10731073               if ($params['post_type'] != '') { 
     
    10771077               $strReq .= "AND post_type = 'post' "; 
    10781078          } 
    1079  
     1079           
    10801080          if (isset($params['lang'])) { 
    10811081               $strReq .= "AND post_lang = '".$this->con->escape($params['lang'])."' "; 
    10821082          } 
    1083  
     1083           
    10841084          $strReq .= 'GROUP BY post_lang '; 
    1085  
     1085           
    10861086          $order = 'desc'; 
    10871087          if (!empty($params['order']) && preg_match('/^(desc|asc)$/i',$params['order'])) { 
     
    10891089          } 
    10901090          $strReq .= 'ORDER BY post_lang '.$order.' '; 
    1091  
     1091           
    10921092          return $this->con->select($strReq); 
    10931093     } 
    1094  
     1094      
    10951095     /** 
    10961096     Returns a record with all distinct blog dates and post count. 
    10971097     <var>$params</var> is an array taking the following optionnal parameters: 
    1098  
     1098      
    10991099     - type: (day|month|year) Get days, months or years 
    11001100     - year: (integer) Get dates for given year 
     
    11071107     - previous: Get date before match 
    11081108     - order: Sort by date "ASC" or "DESC" 
    1109  
     1109      
    11101110     @param    params    <b>array</b>        Parameters array 
    11111111     @return   record 
     
    11261126          $dt_f .= ' 00:00:00'; 
    11271127          $dt_fc .= '000000'; 
    1128  
     1128           
    11291129          $cat_field = $catReq = $limit = ''; 
    1130  
     1130           
    11311131          if (isset($params['cat_id']) && $params['cat_id'] !== '') { 
    11321132               $catReq = 'AND P.cat_id = '.(integer) $params['cat_id'].' '; 
     
    11391139               $catReq = 'AND P.post_lang = \''. $params['post_lang'].'\' '; 
    11401140          } 
    1141  
     1141           
    11421142          $strReq = 'SELECT DISTINCT('.$this->con->dateFormat('post_dt',$dt_f).') AS dt '. 
    11431143                    $cat_field. 
     
    11471147                    "WHERE P.blog_id = '".$this->con->escape($this->id)."' ". 
    11481148                    $catReq; 
    1149  
     1149           
    11501150          if (!$this->core->auth->check('contentadmin',$this->id)) { 
    11511151               $strReq .= 'AND ((post_status = 1 '; 
    1152  
     1152                
    11531153               if ($this->without_password) { 
    11541154                    $strReq .= 'AND post_password IS NULL '; 
    11551155               } 
    11561156               $strReq .= ') '; 
    1157  
     1157                
    11581158               if ($this->core->auth->userID()) { 
    11591159                    $strReq .= "OR P.user_id = '".$this->con->escape($this->core->auth->userID())."')"; 
     
    11621162               } 
    11631163          } 
    1164  
     1164           
    11651165          if (!empty($params['post_type'])) { 
    11661166               $strReq .= "AND post_type ".$this->con->in($params['post_type'])." "; 
     
    11681168               $strReq .= "AND post_type = 'post' "; 
    11691169          } 
    1170  
     1170           
    11711171          if (!empty($params['year'])) { 
    11721172               $strReq .= 'AND '.$this->con->dateFormat('post_dt','%Y')." = '".sprintf('%04d',$params['year'])."' "; 
    11731173          } 
    1174  
     1174           
    11751175          if (!empty($params['month'])) { 
    11761176               $strReq .= 'AND '.$this->con->dateFormat('post_dt','%m')." = '".sprintf('%02d',$params['month'])."' "; 
    11771177          } 
    1178  
     1178           
    11791179          if (!empty($params['day'])) { 
    11801180               $strReq .= 'AND '.$this->con->dateFormat('post_dt','%d')." = '".sprintf('%02d',$params['day'])."' "; 
    11811181          } 
    1182  
     1182           
    11831183          # Get next or previous date 
    11841184          if (!empty($params['next']) || !empty($params['previous'])) 
     
    11931193                    $dt = $params['previous']; 
    11941194               } 
    1195  
     1195                
    11961196               $dt = date('YmdHis',strtotime($dt)); 
    1197  
     1197                
    11981198               $strReq .= 'AND '.$this->con->dateFormat('post_dt',$dt_fc).$pdir."'".$dt."' "; 
    11991199               $limit = $this->con->limit(1); 
    12001200          } 
    1201  
     1201           
    12021202          $strReq .= 'GROUP BY dt '.$cat_field; 
    1203  
     1203           
    12041204          $order = 'desc'; 
    12051205          if (!empty($params['order']) && preg_match('/^(desc|asc)$/i',$params['order'])) { 
    12061206               $order = $params['order']; 
    12071207          } 
    1208  
     1208           
    12091209          $strReq .= 
    12101210          'ORDER BY dt '.$order.' '. 
    12111211          $limit; 
    1212  
     1212           
    12131213          $rs = $this->con->select($strReq); 
    12141214          $rs->extend('rsExtDates'); 
    12151215          return $rs; 
    12161216     } 
    1217  
     1217      
    12181218     /** 
    12191219     Creates a new entry. Takes a cursor as input and returns the new entry 
    12201220     ID. 
    1221  
     1221      
    12221222     @param    cur       <b>cursor</b>       Post cursor 
    12231223     @return   <b>integer</b>      New post ID 
     
    12281228               throw new Exception(__('You are not allowed to create an entry')); 
    12291229          } 
    1230  
     1230           
    12311231          $this->con->writeLock($this->prefix.'post'); 
    12321232          try 
     
    12351235               $rs = $this->con->select( 
    12361236                    'SELECT MAX(post_id) '. 
    1237                     'FROM '.$this->prefix.'post ' 
     1237                    'FROM '.$this->prefix.'post '  
    12381238                    ); 
    1239  
     1239                
    12401240               $cur->post_id = (integer) $rs->f(0) + 1; 
    12411241               $cur->blog_id = (string) $this->id; 
     
    12431243               $cur->post_upddt = date('Y-m-d H:i:s'); 
    12441244               $cur->post_tz = $this->core->auth->getInfo('user_tz'); 
    1245  
     1245                
    12461246               # Post excerpt and content 
    12471247               $this->getPostContent($cur,$cur->post_id); 
    1248  
     1248                
    12491249               $this->getPostCursor($cur); 
    1250  
     1250                
    12511251               $cur->post_url = $this->getPostURL($cur->post_url,$cur->post_dt,$cur->post_title,$cur->post_id); 
    1252  
     1252                
    12531253               if (!$this->core->auth->check('publish,contentadmin',$this->id)) { 
    12541254                    $cur->post_status = -2; 
    12551255               } 
    1256  
     1256                
    12571257               # --BEHAVIOR-- coreBeforePostCreate 
    12581258               $this->core->callBehavior('coreBeforePostCreate',$this,$cur); 
    1259  
     1259                
    12601260               $cur->insert(); 
    12611261               $this->con->unlock(); 
     
    12661266               throw $e; 
    12671267          } 
    1268  
     1268           
    12691269          # --BEHAVIOR-- coreAfterPostCreate 
    12701270          $this->core->callBehavior('coreAfterPostCreate',$this,$cur); 
    1271  
     1271           
    12721272          $this->triggerBlog(); 
    1273  
     1273           
    12741274          return $cur->post_id; 
    12751275     } 
    1276  
     1276      
    12771277     /** 
    12781278     Updates an existing post. 
    1279  
     1279      
    12801280     @param    id        <b>integer</b>      Post ID 
    12811281     @param    cur       <b>cursor</b>       Post cursor 
     
    12861286               throw new Exception(__('You are not allowed to update entries')); 
    12871287          } 
    1288  
     1288           
    12891289          $id = (integer) $id; 
    1290  
     1290           
    12911291          if (empty($id)) { 
    12921292               throw new Exception(__('No such entry ID')); 
    12931293          } 
    1294  
     1294           
    12951295          # Post excerpt and content 
    12961296          $this->getPostContent($cur,$id); 
    1297  
     1297           
    12981298          $this->getPostCursor($cur); 
    1299  
     1299           
    13001300          if ($cur->post_url !== null) { 
    13011301               $cur->post_url = $this->getPostURL($cur->post_url,$cur->post_dt,$cur->post_title,$id); 
    13021302          } 
    1303  
     1303           
    13041304          if (!$this->core->auth->check('publish,contentadmin',$this->id)) { 
    13051305               $cur->unsetField('post_status'); 
    13061306          } 
    1307  
     1307           
    13081308          $cur->post_upddt = date('Y-m-d H:i:s'); 
    1309  
     1309           
    13101310          #If user is only "usage", we need to check the post's owner 
    13111311          if (!$this->core->auth->check('contentadmin',$this->id)) 
     
    13151315                         'WHERE post_id = '.$id.' '. 
    13161316                         "AND user_id = '".$this->con->escape($this->core->auth->userID())."' "; 
    1317  
     1317                
    13181318               $rs = $this->con->select($strReq); 
    1319  
     1319                
    13201320               if ($rs->isEmpty()) { 
    13211321                    throw new Exception(__('You are not allowed to edit this entry')); 
    13221322               } 
    13231323          } 
    1324  
     1324           
    13251325          # --BEHAVIOR-- coreBeforePostUpdate 
    13261326          $this->core->callBehavior('coreBeforePostUpdate',$this,$cur); 
    1327  
     1327           
    13281328          $cur->update('WHERE post_id = '.$id.' '); 
    1329  
     1329           
    13301330          # --BEHAVIOR-- coreAfterPostUpdate 
    13311331          $this->core->callBehavior('coreAfterPostUpdate',$this,$cur); 
    1332  
     1332           
    13331333          $this->triggerBlog(); 
    13341334     } 
    1335  
     1335      
    13361336     /** 
    13371337     Updates post status. 
    1338  
     1338      
    13391339     @param    id        <b>integer</b>      Post ID 
    13401340     @param    status    <b>integer</b>      Post status 
     
    13441344          $this->updPostsStatus($id,$status); 
    13451345     } 
    1346  
     1346      
    13471347     /** 
    13481348     Updates posts status. 
    1349  
     1349      
    13501350     @param    ids       <b>mixed</b>        Post(s) ID(s) 
    13511351     @param    status    <b>integer</b>      Post status 
     
    13561356               throw new Exception(__('You are not allowed to change this entry status')); 
    13571357          } 
    1358  
     1358           
    13591359          $posts_ids = dcUtils::cleanIds($ids); 
    13601360          $status = (integer) $status; 
    1361  
     1361           
    13621362          $strReq = "WHERE blog_id = '".$this->con->escape($this->id)."' ". 
    13631363                    "AND post_id ".$this->con->in($posts_ids); 
    1364  
     1364           
    13651365          #If user can only publish, we need to check the post's owner 
    13661366          if (!$this->core->auth->check('contentadmin',$this->id)) 
     
    13681368               $strReq .= "AND user_id = '".$this->con->escape($this->core->auth->userID())."' "; 
    13691369          } 
    1370  
     1370           
    13711371          $cur = $this->con->openCursor($this->prefix.'post'); 
    1372  
     1372           
    13731373          $cur->post_status = $status; 
    13741374          $cur->post_upddt = date('Y-m-d H:i:s'); 
    1375  
     1375           
    13761376          $cur->update($strReq); 
    13771377          $this->triggerBlog(); 
    13781378     } 
    1379  
     1379      
    13801380     /** 
    13811381     Updates post selection. 
    1382  
     1382      
    13831383     @param    id        <b>integer</b>      Post ID 
    13841384     @param    selected  <b>integer</b>      Is selected post 
     
    13881388          $this->updPostsSelected($id,$selected); 
    13891389     } 
    1390  
     1390      
    13911391     /** 
    13921392     Updates posts selection. 
    1393  
     1393      
    13941394     @param    ids       <b>mixed</b>        Post(s) ID(s) 
    13951395     @param    selected  <b>integer</b>      Is selected post(s) 
     
    14001400               throw new Exception(__('You are not allowed to change this entry category')); 
    14011401          } 
    1402  
     1402           
    14031403          $posts_ids = dcUtils::cleanIds($ids); 
    14041404          $selected = (boolean) $selected; 
    1405  
     1405           
    14061406          $strReq = "WHERE blog_id = '".$this->con->escape($this->id)."' ". 
    14071407                    "AND post_id ".$this->con->in($posts_ids); 
    1408  
     1408           
    14091409          # If user is only usage, we need to check the post's owner 
    14101410          if (!$this->core->auth->check('contentadmin',$this->id)) 
     
    14121412               $strReq .= "AND user_id = '".$this->con->escape($this->core->auth->userID())."' "; 
    14131413          } 
    1414  
     1414           
    14151415          $cur = $this->con->openCursor($this->prefix.'post'); 
    1416  
     1416           
    14171417          $cur->post_selected = (integer) $selected; 
    14181418          $cur->post_upddt = date('Y-m-d H:i:s'); 
    1419  
     1419           
    14201420          $cur->update($strReq); 
    14211421          $this->triggerBlog(); 
    14221422     } 
    1423  
     1423      
    14241424     /** 
    14251425     Updates post category. <var>$cat_id</var> can be null. 
    1426  
     1426      
    14271427     @param    id        <b>integer</b>      Post ID 
    14281428     @param    cat_id    <b>integer</b>      Category ID 
     
    14321432          $this->updPostsCategory($id,$cat_id); 
    14331433     } 
    1434  
     1434      
    14351435     /** 
    14361436     Updates posts category. <var>$cat_id</var> can be null. 
    1437  
     1437      
    14381438     @param    ids       <b>mixed</b>        Post(s) ID(s) 
    14391439     @param    cat_id    <b>integer</b>      Category ID 
     
    14441444               throw new Exception(__('You are not allowed to change this entry category')); 
    14451445          } 
    1446  
     1446           
    14471447          $posts_ids = dcUtils::cleanIds($ids); 
    14481448          $cat_id = (integer) $cat_id; 
    1449  
     1449           
    14501450          $strReq = "WHERE blog_id = '".$this->con->escape($this->id)."' ". 
    14511451                    "AND post_id ".$this->con->in($posts_ids); 
    1452  
     1452           
    14531453          # If user is only usage, we need to check the post's owner 
    14541454          if (!$this->core->auth->check('contentadmin',$this->id)) 
     
    14561456               $strReq .= "AND user_id = '".$this->con->escape($this->core->auth->userID())."' "; 
    14571457          } 
    1458  
     1458           
    14591459          $cur = $this->con->openCursor($this->prefix.'post'); 
    1460  
     1460           
    14611461          $cur->cat_id = ($cat_id ? $cat_id : null); 
    14621462          $cur->post_upddt = date('Y-m-d H:i:s'); 
    1463  
     1463           
    14641464          $cur->update($strReq); 
    14651465          $this->triggerBlog(); 
    14661466     } 
    1467  
     1467      
    14681468     /** 
    14691469     Updates posts category. <var>$new_cat_id</var> can be null. 
    1470  
     1470      
    14711471     @param    old_cat_id     <b>integer</b>      Old category ID 
    14721472     @param    new_cat_id     <b>integer</b>      New category ID 
     
    14771477               throw new Exception(__('You are not allowed to change entries category')); 
    14781478          } 
    1479  
     1479           
    14801480          $old_cat_id = (integer) $old_cat_id; 
    14811481          $new_cat_id = (integer) $new_cat_id; 
    1482  
     1482           
    14831483          $cur = $this->con->openCursor($this->prefix.'post'); 
    1484  
     1484           
    14851485          $cur->cat_id = ($new_cat_id ? $new_cat_id : null); 
    14861486          $cur->post_upddt = date('Y-m-d H:i:s'); 
    1487  
     1487           
    14881488          $cur->update( 
    14891489               'WHERE cat_id = '.$old_cat_id.' '. 
     
    14921492          $this->triggerBlog(); 
    14931493     } 
    1494  
     1494      
    14951495     /** 
    14961496     Deletes a post. 
    1497  
     1497      
    14981498     @param    id        <b>integer</b>      Post ID 
    14991499     */ 
     
    15021502          $this->delPosts($id); 
    15031503     } 
    1504  
     1504      
    15051505     /** 
    15061506     Deletes multiple posts. 
    1507  
     1507      
    15081508     @param    ids       <b>mixed</b>        Post(s) ID(s) 
    15091509     */ 
     
    15131513               throw new Exception(__('You are not allowed to delete entries')); 
    15141514          } 
    1515  
     1515           
    15161516          $posts_ids = dcUtils::cleanIds($ids); 
    1517  
     1517           
    15181518          if (empty($posts_ids)) { 
    15191519               throw new Exception(__('No such entry ID')); 
    15201520          } 
    1521  
     1521           
    15221522          $strReq = 'DELETE FROM '.$this->prefix.'post '. 
    15231523                    "WHERE blog_id = '".$this->con->escape($this->id)."' ". 
    15241524                    "AND post_id ".$this->con->in($posts_ids); 
    1525  
     1525           
    15261526          #If user can only delete, we need to check the post's owner 
    15271527          if (!$this->core->auth->check('contentadmin',$this->id)) 
     
    15291529               $strReq .= "AND user_id = '".$this->con->escape($this->core->auth->userID())."' "; 
    15301530          } 
    1531  
     1531           
    15321532          $this->con->execute($strReq); 
    15331533          $this->triggerBlog(); 
    15341534     } 
    1535  
     1535      
    15361536     /** 
    15371537     Publishes all entries flaged as "scheduled". 
     
    15431543                    'WHERE post_status = -1 '. 
    15441544                    "AND blog_id = '".$this->con->escape($this->id)."' "; 
    1545  
     1545           
    15461546          $rs = $this->con->select($strReq); 
    1547  
     1547           
    15481548          $now = dt::toUTC(time()); 
    15491549          $to_change = new ArrayObject(); 
     
    15521552               return; 
    15531553          } 
    1554  
     1554           
    15551555          while ($rs->fetch()) 
    15561556          { 
    15571557               # Now timestamp with post timezone 
    15581558               $now_tz = $now + dt::getTimeOffset($rs->post_tz,$now); 
    1559  
     1559                
    15601560               # Post timestamp 
    15611561               $post_ts = strtotime($rs->post_dt); 
    1562  
     1562                
    15631563               # If now_tz >= post_ts, we publish the entry 
    15641564               if ($now_tz >= $post_ts) { 
     
    15821582               $this->core->callBehavior('coreAfterScheduledEntriesPublish',$this,$to_change); 
    15831583          } 
    1584  
    1585      } 
    1586  
     1584           
     1585     } 
     1586      
    15871587     /** 
    15881588     Retrieves all users having posts on current blog. 
    1589  
     1589      
    15901590     @param    post_type      <b>string</b>       post_type filter (post) 
    15911591     @return   record 
     
    15981598                    'WHERE P.user_id = U.user_id '. 
    15991599                    "AND blog_id = '".$this->con->escape($this->id)."' "; 
    1600  
     1600           
    16011601          if ($post_type) { 
    16021602               $strReq .= "AND post_type = '".$this->con->escape($post_type)."' "; 
    16031603          } 
    1604  
     1604           
    16051605          $strReq .= 'GROUP BY P.user_id, user_name, user_firstname, user_displayname, user_email '; 
    1606  
     1606           
    16071607          return $this->con->select($strReq); 
    16081608     } 
    1609  
     1609      
    16101610     private function getPostsCategoryFilter($arr,$field='cat_id') 
    16111611     { 
    16121612          $field = $field == 'cat_id' ? 'cat_id' : 'cat_url'; 
    1613  
     1613           
    16141614          $sub = array(); 
    16151615          $not = array(); 
    16161616          $queries = array(); 
    1617  
     1617           
    16181618          foreach ($arr as $v) 
    16191619          { 
     
    16221622               $id = array_shift($args); 
    16231623               $args = array_flip($args); 
    1624  
     1624                
    16251625               if (isset($args['not'])) { $not[$id] = 1; } 
    16261626               if (isset($args['sub'])) { $sub[$id] = 1; } 
     
    16361636               } 
    16371637          } 
    1638  
     1638           
    16391639          if (!empty($sub)) { 
    16401640               $rs = $this->con->select( 
     
    16431643                    'AND '.$field.' '.$this->con->in(array_keys($sub)) 
    16441644               ); 
    1645  
     1645                
    16461646               while ($rs->fetch()) { 
    16471647                    $queries[$rs->f($field)] = '(C.cat_lft BETWEEN '.$rs->cat_lft.' AND '.$rs->cat_rgt.')'; 
    16481648               } 
    16491649          } 
    1650  
     1650           
    16511651          # Create queries 
    16521652          $sql = array( 
     
    16541654               1 => array()  # excluded categories 
    16551655          ); 
    1656  
     1656           
    16571657          foreach ($queries as $id => $q) { 
    16581658               $sql[(integer) isset($not[$id])][] = $q; 
    16591659          } 
    1660  
     1660           
    16611661          $sql[0] = implode(' OR ',$sql[0]); 
    16621662          $sql[1] = implode(' OR ',$sql[1]); 
    1663  
     1663           
    16641664          if ($sql[0]) { 
    16651665               $sql[0] = '('.$sql[0].')'; 
     
    16671667               unset($sql[0]); 
    16681668          } 
    1669  
     1669           
    16701670          if ($sql[1]) { 
    16711671               $sql[1] = '(P.cat_id IS NULL OR NOT('.$sql[1].'))'; 
     
    16731673               unset($sql[1]); 
    16741674          } 
    1675  
     1675           
    16761676          return implode(' AND ',$sql); 
    16771677     } 
    1678  
     1678      
    16791679     private function getPostCursor($cur,$post_id=null) 
    16801680     { 
     
    16821682               throw new Exception(__('No entry title')); 
    16831683          } 
    1684  
     1684           
    16851685          if ($cur->post_content == '') { 
    16861686               throw new Exception(__('No entry content')); 
    16871687          } 
    1688  
     1688           
    16891689          if ($cur->post_password === '') { 
    16901690               $cur->post_password = null; 
    16911691          } 
    1692  
     1692           
    16931693          if ($cur->post_dt == '') { 
    16941694               $offset = dt::getTimeOffset($this->core->auth->getInfo('user_tz')); 
     
    16961696               $cur->post_dt = date('Y-m-d H:i:00',$now); 
    16971697          } 
    1698  
     1698           
    16991699          $post_id = is_int($post_id) ? $post_id : $cur->post_id; 
    1700  
     1700           
    17011701          if ($cur->post_content_xhtml == '') { 
    17021702               throw new Exception(__('No entry content')); 
    17031703          } 
    1704  
     1704           
    17051705          # Words list 
    17061706          if ($cur->post_title !== null && $cur->post_excerpt_xhtml !== null 
     
    17111711               $cur->post_excerpt_xhtml.' '. 
    17121712               $cur->post_content_xhtml; 
    1713  
     1713                
    17141714               $cur->post_words = implode(' ',text::splitWords($words)); 
    17151715          } 
    17161716     } 
    1717  
     1717      
    17181718     private function getPostContent($cur,$post_id) 
    17191719     { 
     
    17221722          $post_content = $cur->post_content; 
    17231723          $post_content_xhtml = $cur->post_content_xhtml; 
    1724  
     1724           
    17251725          $this->setPostContent( 
    17261726               $post_id,$cur->post_format,$cur->post_lang, 
     
    17281728               $post_content,$post_content_xhtml 
    17291729          ); 
    1730  
     1730           
    17311731          $cur->post_excerpt = $post_excerpt; 
    17321732          $cur->post_excerpt_xhtml = $post_excerpt_xhtml; 
     
    17341734          $cur->post_content_xhtml = $post_content_xhtml; 
    17351735     } 
    1736  
     1736      
    17371737     /** 
    17381738     Creates post HTML content, taking format and lang into account. 
    1739  
     1739      
    17401740     @param         post_id        <b>integer</b>      Post ID 
    17411741     @param         format         <b>string</b>       Post format 
     
    17711771               } 
    17721772          } 
    1773  
     1773           
    17741774          if ($excerpt) { 
    17751775               $excerpt_xhtml = $this->core->callFormater($format,$excerpt); 
     
    17781778               $excerpt_xhtml = ''; 
    17791779          } 
    1780  
     1780           
    17811781          if ($content) { 
    17821782               $content_xhtml = $this->core->callFormater($format,$content); 
     
    17851785               $content_xhtml = ''; 
    17861786          } 
    1787  
     1787           
    17881788          # --BEHAVIOR-- coreAfterPostContentFormat 
    17891789          $this->core->callBehavior('coreAfterPostContentFormat',array( 
     
    17941794          )); 
    17951795     } 
    1796  
     1796      
    17971797     /** 
    17981798     Returns URL for a post according to blog setting <var>post_url_format</var>. 
    17991799     It will try to guess URL and append some figures if needed. 
    1800  
     1800      
    18011801     @param    url            <b>string</b>       Origin URL, could be empty 
    18021802     @param    post_dt        <b>string</b>       Post date (in YYYY-MM-DD HH:mm:ss) 
     
    18081808     { 
    18091809          $url = trim($url); 
    1810  
     1810           
    18111811          $url_patterns = array( 
    18121812          '{y}' => date('Y',strtotime($post_dt)), 
     
    18161816          '{id}' => (integer) $post_id 
    18171817          ); 
    1818  
     1818           
    18191819          # If URL is empty, we create a new one 
    18201820          if ($url == '') 
     
    18311831               $url = text::tidyURL($url); 
    18321832          } 
    1833  
     1833           
    18341834          # Let's check if URL is taken... 
    18351835          $strReq = 'SELECT post_url FROM '.$this->prefix.'post '. 
     
    18381838                    "AND blog_id = '".$this->con->escape($this->id)."' ". 
    18391839                    'ORDER BY post_url DESC'; 
    1840  
     1840           
    18411841          $rs = $this->con->select($strReq); 
    1842  
     1842           
    18431843          if (!$rs->isEmpty()) 
    18441844          { 
     
    18551855                         "AND blog_id = '".$this->con->escape($this->id)."' ". 
    18561856                         'ORDER BY post_url DESC '; 
    1857  
     1857                
    18581858               $rs = $this->con->select($strReq); 
    18591859               $a = array(); 
     
    18611861                    $a[] = $rs->post_url; 
    18621862               } 
    1863  
     1863                
    18641864               natsort($a); 
    18651865               $t_url = end($a); 
    1866  
     1866                
    18671867               if (preg_match('/(.*?)([0-9]+)$/',$t_url,$m)) { 
    18681868                    $i = (integer) $m[2]; 
     
    18711871                    $i = 1; 
    18721872               } 
    1873  
     1873                
    18741874               return $url.($i+1); 
    18751875          } 
    1876  
     1876           
    18771877          # URL is empty? 
    18781878          if ($url == '') { 
    18791879               throw new Exception(__('Empty entry URL')); 
    18801880          } 
    1881  
     1881           
    18821882          return $url; 
    18831883     } 
    18841884     //@} 
    1885  
     1885      
    18861886     /// @name Comments management methods 
    18871887     //@{ 
     
    18891889     Retrieves comments. <b>$params</b> is an array taking the following 
    18901890     optionnal parameters: 
    1891  
     1891      
    18921892     - no_content: Don't retrieve comment content 
    1893      - post_type: Get only entries with given type (default no type, array for many types) 
     1893     - post_type: Get only entries with given type (default no type, array for many types)  
    18941894     - post_id: (integer) Get comments belonging to given post_id 
    18951895     - cat_id: (integer or array) Get comments belonging to entries of given category ID 
     
    19071907     - limit: Limit parameter 
    19081908     - sql_only : return the sql request instead of results. Only ids are selected 
    1909  
     1909      
    19101910     @param    params         <b>array</b>        Parameters 
    19111911     @param    count_only     <b>boolean</b>      Only counts results 
     
    19181918               $strReq = 'SELECT count(comment_id) '; 
    19191919          } 
    1920           elseif (!empty($params['sql_only'])) 
     1920          elseif (!empty($params['sql_only']))  
    19211921          { 
    19221922               $strReq = 'SELECT P.post_id '; 
     
    19291929                    $content_req = 'comment_content, '; 
    19301930               } 
    1931  
     1931                
    19321932               if (!empty($params['columns']) && is_array($params['columns'])) { 
    19331933                    $content_req .= implode(', ',$params['columns']).', '; 
    19341934               } 
    1935  
     1935                
    19361936               $strReq = 
    19371937               'SELECT C.comment_id, comment_dt, comment_tz, comment_upddt, '. 
     
    19421942               'P.post_dt, P.user_id, U.user_email, U.user_url '; 
    19431943          } 
    1944  
     1944           
    19451945          $strReq .= 
    19461946          'FROM '.$this->prefix.'comment C '. 
    19471947          'INNER JOIN '.$this->prefix.'post P ON C.post_id = P.post_id '. 
    19481948          'INNER JOIN '.$this->prefix.'user U ON P.user_id = U.user_id '; 
    1949  
     1949           
    19501950          if (!empty($params['from'])) { 
    19511951               $strReq .= $params['from'].' '; 
    19521952          } 
    1953  
     1953           
    19541954          $strReq .= 
    19551955          "WHERE P.blog_id = '".$this->con->escape($this->id)."' "; 
    1956  
     1956           
    19571957          if (!$this->core->auth->check('contentadmin',$this->id)) { 
    19581958               $strReq .= 'AND ((comment_status = 1 AND P.post_status = 1 '; 
    1959  
     1959                
    19601960               if ($this->without_password) { 
    19611961                    $strReq .= 'AND post_password IS NULL '; 
    19621962               } 
    19631963               $strReq .= ') '; 
    1964  
     1964                
    19651965               if ($this->core->auth->userID()) { 
    19661966                    $strReq .= "OR P.user_id = '".$this->con->escape($this->core->auth->userID())."')"; 
     
    19691969               } 
    19701970          } 
    1971  
     1971           
    19721972          if (!empty($params['post_type'])) 
    19731973          { 
    19741974               $strReq .= 'AND post_type '.$this->con->in($params['post_type']); 
    19751975          } 
    1976  
     1976           
    19771977          if (isset($params['post_id']) && $params['post_id'] !== '') { 
    19781978               $strReq .= 'AND P.post_id = '.(integer) $params['post_id'].' '; 
    19791979          } 
    1980  
     1980           
    19811981          if (isset($params['cat_id']) && $params['cat_id'] !== '') { 
    19821982               $strReq .= 'AND P.cat_id = '.(integer) $params['cat_id'].' '; 
    19831983          } 
    1984  
     1984           
    19851985          if (isset($params['comment_id']) && $params['comment_id'] !== '') { 
    19861986               if (is_array($params['comment_id'])) { 
     
    19911991               $strReq .= 'AND comment_id '.$this->con->in($params['comment_id']); 
    19921992          } 
    1993  
     1993           
    19941994          if (isset($params['comment_site'])) { 
    19951995               $comment_site = $this->con->escape(str_replace('*','%',$params['comment_site'])); 
    19961996               $strReq .= "AND comment_site LIKE '".$comment_site."' "; 
    19971997          } 
    1998  
     1998           
    19991999          if (isset($params['comment_status'])) { 
    20002000               $strReq .= 'AND comment_status = '.(integer) $params['comment_status'].' '; 
    20012001          } 
    2002  
     2002           
    20032003          if (!empty($params['comment_status_not'])) 
    20042004          { 
    20052005               $strReq .= 'AND comment_status <> '.(integer) $params['comment_status_not'].' '; 
    20062006          } 
    2007  
     2007           
    20082008          if (isset($params['comment_trackback'])) { 
    20092009               $strReq .= 'AND comment_trackback = '.(integer) (boolean) $params['comment_trackback'].' '; 
    20102010          } 
    2011  
     2011           
    20122012          if (isset($params['comment_ip'])) { 
    20132013               $comment_ip = $this->con->escape(str_replace('*','%',$params['comment_ip'])); 
    20142014               $strReq .= "AND comment_ip LIKE '".$comment_ip."' "; 
    20152015          } 
    2016  
     2016           
    20172017          if (isset($params['q_author'])) { 
    20182018               $q_author = $this->con->escape(str_replace('*','%',strtolower($params['q_author']))); 
    20192019               $strReq .= "AND LOWER(comment_author) LIKE '".$q_author."' "; 
    20202020          } 
    2021  
     2021           
    20222022          if (!empty($params['search'])) 
    20232023          { 
    20242024               $words = text::splitWords($params['search']); 
    2025  
     2025                
    20262026               if (!empty($words)) 
    20272027               { 
     
    20302030                         $this->core->callBehavior('coreCommentSearch',$this->core,array(&$words,&$strReq,&$params)); 
    20312031                    } 
    2032  
     2032                     
    20332033                    if ($words) 
    20342034                    { 
     
    20402040               } 
    20412041          } 
    2042  
     2042           
    20432043          if (!empty($params['sql'])) { 
    20442044               $strReq .= $params['sql'].' '; 
    20452045          } 
    2046  
     2046           
    20472047          if (!$count_only) 
    20482048          { 
     
    20532053               } 
    20542054          } 
    2055  
     2055           
    20562056          if (!$count_only && !empty($params['limit'])) { 
    20572057               $strReq .= $this->con->limit($params['limit']); 
     
    20612061               return $strReq; 
    20622062          } 
    2063  
     2063           
    20642064          $rs = $this->con->select($strReq); 
    20652065          $rs->core = $this->core; 
    20662066          $rs->extend('rsExtComment'); 
    2067  
     2067           
    20682068          # --BEHAVIOR-- coreBlogGetComments 
    20692069          $this->core->callBehavior('coreBlogGetComments',$rs); 
    2070  
     2070           
    20712071          return $rs; 
    20722072     } 
    2073  
     2073      
    20742074     /** 
    20752075     Creates a new comment. Takes a cursor as input and returns the new comment 
    20762076     ID. 
    2077  
     2077      
    20782078     @param    cur       <b>cursor</b>       Comment cursor 
    20792079     @return   <b>integer</b>      New comment ID 
     
    20872087               $rs = $this->con->select( 
    20882088                    'SELECT MAX(comment_id) '. 
    2089                     'FROM '.$this->prefix.'comment ' 
     2089                    'FROM '.$this->prefix.'comment '  
    20902090               ); 
    2091  
     2091                
    20922092               $cur->comment_id = (integer) $rs->f(0) + 1; 
    20932093               $cur->comment_upddt = date('Y-m-d H:i:s'); 
    2094  
     2094                
    20952095               $offset = dt::getTimeOffset($this->settings->system->blog_timezone); 
    20962096               $cur->comment_dt = date('Y-m-d H:i:s',time() + $offset); 
    20972097               $cur->comment_tz = $this->settings->system->blog_timezone; 
    2098  
     2098                
    20992099               $this->getCommentCursor($cur); 
    2100  
     2100                
    21012101               if ($cur->comment_ip === null) { 
    21022102                    $cur->comment_ip = http::realIP(); 
    21032103               } 
    2104  
     2104                
    21052105               # --BEHAVIOR-- coreBeforeCommentCreate 
    21062106               $this->core->callBehavior('coreBeforeCommentCreate',$this,$cur); 
    2107  
     2107                
    21082108               $cur->insert(); 
    21092109               $this->con->unlock(); 
     
    21142114               throw $e; 
    21152115          } 
    2116  
     2116           
    21172117          # --BEHAVIOR-- coreAfterCommentCreate 
    21182118          $this->core->callBehavior('coreAfterCommentCreate',$this,$cur); 
    2119  
     2119           
    21202120          $this->triggerComment($cur->comment_id); 
    21212121          if ($cur->comment_status != -2) { 
    21222122               $this->triggerBlog(); 
    2123           } 
     2123          }     
    21242124          return $cur->comment_id; 
    21252125     } 
    2126  
     2126      
    21272127     /** 
    21282128     Updates an existing comment. 
    2129  
     2129      
    21302130     @param    id        <b>integer</b>      Comment ID 
    21312131     @param    cur       <b>cursor</b>       Comment cursor 
     
    21362136               throw new Exception(__('You are not allowed to update comments')); 
    21372137          } 
    2138  
     2138           
    21392139          $id = (integer) $id; 
    2140  
     2140           
    21412141          if (empty($id)) { 
    21422142               throw new Exception(__('No such comment ID')); 
    21432143          } 
    2144  
     2144           
    21452145          $rs = $this->getComments(array('comment_id' => $id)); 
    2146  
     2146           
    21472147          if ($rs->isEmpty()) { 
    21482148               throw new Exception(__('No such comment ID')); 
    21492149          } 
    2150  
     2150           
    21512151          #If user is only usage, we need to check the post's owner 
    21522152          if (!$this->core->auth->check('contentadmin',$this->id)) 
     
    21562156               } 
    21572157          } 
    2158  
     2158           
    21592159          $this->getCommentCursor($cur); 
    2160  
     2160           
    21612161          $cur->comment_upddt = date('Y-m-d H:i:s'); 
    2162  
     2162           
    21632163          if (!$this->core->auth->check('publish,contentadmin',$this->id)) { 
    21642164               $cur->unsetField('comment_status'); 
    21652165          } 
    2166  
     2166           
    21672167          # --BEHAVIOR-- coreBeforeCommentUpdate 
    21682168          $this->core->callBehavior('coreBeforeCommentUpdate',$this,$cur,$rs); 
    2169  
     2169           
    21702170          $cur->update('WHERE comment_id = '.$id.' '); 
    2171  
     2171           
    21722172          # --BEHAVIOR-- coreAfterCommentUpdate 
    21732173          $this->core->callBehavior('coreAfterCommentUpdate',$this,$cur,$rs); 
    2174  
     2174           
    21752175          $this->triggerComment($id); 
    21762176          $this->triggerBlog(); 
    21772177     } 
    2178  
     2178      
    21792179     /** 
    21802180     Updates comment status. 
    2181  
     2181      
    21822182     @param    id        <b>integer</b>      Comment ID 
    21832183     @param    status    <b>integer</b>      Comment status 
     
    21872187          $this->updCommentsStatus($id,$status); 
    21882188     } 
    2189  
     2189      
    21902190     /** 
    21912191     Updates comments status. 
    2192  
     2192      
    21932193     @param    ids       <b>mixed</b>        Comment(s) ID(s) 
    21942194     @param    status    <b>integer</b>      Comment status 
     
    21992199               throw new Exception(__("You are not allowed to change this comment's status")); 
    22002200          } 
    2201  
     2201           
    22022202          $co_ids = dcUtils::cleanIds($ids); 
    22032203          $status = (integer) $status; 
    2204  
    2205           $strReq = 
     2204           
     2205          $strReq =  
    22062206               'UPDATE '.$this->prefix.'comment tc '; 
    2207  
     2207           
    22082208          # mySQL uses "JOIN" synthax 
    22092209          if ($this->con->driver() == 'mysql' || $this->con->driver() == 'mysqli') { 
    2210                $strReq .= 
     2210               $strReq .=  
    22112211                    'JOIN '.$this->prefix.'post tp ON tc.post_id = tp.post_id '; 
    22122212          } 
    2213  
    2214           $strReq .= 
     2213           
     2214          $strReq .=  
    22152215               'SET comment_status = '.$status.' '; 
    2216  
     2216           
    22172217          # pgSQL uses "FROM" synthax 
    22182218          if ($this->con->driver() != 'mysql' && $this->con->driver() != 'mysqli') { 
    2219                $strReq .= 
     2219               $strReq .=  
    22202220                    'FROM '.$this->prefix.'post tp '; 
    22212221          } 
    2222  
     2222           
    22232223          $strReq .= 
    22242224               "WHERE blog_id = '".$this->con->escape($this->id)."' ". 
    22252225               'AND comment_id'.$this->con->in($co_ids); 
    2226  
     2226           
    22272227          # add pgSQL "WHERE" clause 
    22282228          if ($this->con->driver() != 'mysql' && $this->con->driver() != 'mysqli') { 
    2229                $strReq .= 
     2229               $strReq .=  
    22302230                    'AND tc.post_id = tp.post_id '; 
    22312231          } 
    2232  
     2232           
    22332233          #If user is only usage, we need to check the post's owner 
    22342234          if (!$this->core->auth->check('contentadmin',$this->id)) 
    22352235          { 
    2236                $strReq .= 
     2236               $strReq .=  
    22372237                    "AND user_id = '".$this->con->escape($this->core->auth->userID())."' "; 
    22382238          } 
    2239  
     2239           
    22402240          $this->con->execute($strReq); 
    22412241          $this->triggerComments($co_ids); 
    22422242          $this->triggerBlog(); 
    22432243     } 
    2244  
     2244      
    22452245     /** 
    22462246     Delete a comment 
    2247  
     2247      
    22482248     @param    id        <b>integer</b>      Comment ID 
    22492249     */ 
     
    22522252          $this->delComments($id); 
    22532253     } 
    2254  
     2254      
    22552255     /** 
    22562256     Delete comments 
    2257  
     2257      
    22582258     @param    ids       <b>mixed</b>        Comment(s) ID(s) 
    22592259     */ 
     
    22632263               throw new Exception(__('You are not allowed to delete comments')); 
    22642264          } 
    2265  
     2265           
    22662266          $co_ids = dcUtils::cleanIds($ids); 
    2267  
     2267           
    22682268          if (empty($co_ids)) { 
    22692269               throw new Exception(__('No such comment ID')); 
    22702270          } 
    2271  
     2271           
    22722272          # Retrieve posts affected by comments edition 
    22732273          $affected_posts = array(); 
     
    22772277               'WHERE comment_id'.$this->con->in($co_ids). 
    22782278               'GROUP BY post_id'; 
    2279  
     2279           
    22802280          $rs = $this->con->select($strReq); 
    2281  
     2281           
    22822282          while ($rs->fetch()) { 
    22832283               $affected_posts[] = (integer) $rs->post_id; 
    22842284          } 
    2285  
     2285           
    22862286          # mySQL uses "INNER JOIN" synthax 
    22872287          if ($this->con->driver() == 'mysql' || $this->con->driver() == 'mysqli') { 
    2288                $strReq = 
     2288               $strReq =  
    22892289                    'DELETE FROM tc '. 
    22902290                    'USING '.$this->prefix.'comment tc '. 
     
    22932293          # pgSQL uses nothing special 
    22942294          else { 
    2295                $strReq = 
     2295               $strReq =  
    22962296                    'DELETE FROM '.$this->prefix.'comment tc '. 
    22972297                    'USING '.$this->prefix.'post tp '; 
    22982298          } 
    2299  
    2300           $strReq .= 
     2299           
     2300          $strReq .=  
    23012301               'WHERE tc.post_id = tp.post_id '. 
    23022302               "AND tp.blog_id = '".$this->con->escape($this->id)."' ". 
    23032303               'AND comment_id'.$this->con->in($co_ids); 
    2304  
     2304           
    23052305          #If user can only delete, we need to check the post's owner 
    23062306          if (!$this->core->auth->check('contentadmin',$this->id)) 
    23072307          { 
    2308                $strReq .= 
     2308               $strReq .=  
    23092309                    "AND user_id = '".$this->con->escape($this->core->auth->userID())."' "; 
    23102310          } 
    2311  
     2311           
    23122312          $this->con->execute($strReq); 
    23132313          $this->triggerComments($co_ids, true, $affected_posts); 
     
    23202320               throw new Exception(__('You are not allowed to delete comments')); 
    23212321          } 
    2322  
     2322           
    23232323          # mySQL uses "INNER JOIN" synthax 
    23242324          if ($this->con->driver() == 'mysql' || $this->con->driver() == 'mysqli') { 
    2325                $strReq = 
     2325               $strReq =  
    23262326                    'DELETE FROM tc '. 
    23272327                    'USING '.$this->prefix.'comment tc '. 
     
    23302330          # pgSQL uses nothing special 
    23312331          else { 
    2332                $strReq = 
     2332               $strReq =  
    23332333                    'DELETE FROM '.$this->prefix.'comment tc '. 
    23342334                    'USING '.$this->prefix.'post tp '; 
    23352335          } 
    2336  
    2337           $strReq .= 
     2336           
     2337          $strReq .=  
    23382338               'WHERE tc.post_id = tp.post_id '. 
    23392339               "AND tp.blog_id = '".$this->con->escape($this->id)."' ". 
    23402340               'AND comment_status = -2'; 
    2341  
     2341           
    23422342          #If user can only delete, we need to check the post's owner 
    23432343          if (!$this->core->auth->check('contentadmin',$this->id)) 
    23442344          { 
    2345                $strReq .= 
     2345               $strReq .=  
    23462346                    "AND user_id = '".$this->con->escape($this->core->auth->userID())."' "; 
    23472347          } 
    2348  
     2348           
    23492349          $this->con->execute($strReq); 
    23502350          $this->triggerBlog(); 
    23512351     } 
    2352  
     2352      
    23532353     private function getCommentCursor($cur) 
    23542354     { 
     
    23562356               throw new Exception(__('You must provide a comment')); 
    23572357          } 
    2358  
     2358           
    23592359          if ($cur->comment_author !== null && $cur->comment_author == '') { 
    23602360               throw new Exception(__('You must provide an author name')); 
    23612361          } 
    2362  
     2362           
    23632363          if ($cur->comment_email != '' && !text::isEmail($cur->comment_email)) { 
    23642364               throw new Exception(__('Email address is not valid.')); 
    23652365          } 
    2366  
     2366           
    23672367          if ($cur->comment_site !== null && $cur->comment_site != '') { 
    23682368               if (!preg_match('|^http(s?)://|i',$cur->comment_site, $matches)) { 
     
    23722372               } 
    23732373          } 
    2374  
     2374           
    23752375          if ($cur->comment_status === null) { 
    23762376               $cur->comment_status = (integer) $this->settings->system->comments_pub; 
    23772377          } 
    2378  
     2378           
    23792379          # Words list 
    23802380          if ($cur->comment_content !== null) 
  • inc/core/class.dc.core.php

    r2313 r2609  
    44# This file is part of Dotclear 2. 
    55# 
    6 # Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear 
     6# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear 
    77# Licensed under the GPL version 2.0 license. 
    88# See LICENSE file or 
     
    4040     public $log;        ///< <b>dcLog</b>             dcLog object 
    4141     public $tpl;        ///< <b>Twig_Environment</b>  Twig_Environment object 
     42     public $stime;      ///< <b>float</b>             starting time 
    4243      
    4344     private $versions = null; 
     
    6061     public function __construct($driver, $host, $db, $user, $password, $prefix, $persist) 
    6162     { 
     63          if (defined('DC_START_TIME')) { 
     64               $this->stime=DC_START_TIME; 
     65          } else { 
     66               $this->stime = microtime(true); 
     67          } 
     68 
    6269          $this->con = dbLayer::init($driver,$host,$db,$user,$password,$persist); 
    6370           
     
    8895          $this->url = new dcUrlHandlers(); 
    8996           
    90           $this->plugins = new dcModules($this); 
     97          $this->plugins = new dcPlugins($this); 
    9198           
    9299          $this->rest = new dcRestServer($this); 
     
    10191026     private function getBlogCursor($cur) 
    10201027     { 
    1021           if ($cur->blog_id !== null 
    1022           && !preg_match('/^[A-Za-z0-9._-]{2,}$/',$cur->blog_id)) { 
     1028          if (($cur->blog_id !== null 
     1029               && !preg_match('/^[A-Za-z0-9._-]{2,}$/',$cur->blog_id)) || 
     1030               (!$cur->blog_id)) { 
    10231031               throw new Exception(__('Blog ID must contain at least 2 characters using letters, numbers or symbols.'));  
    10241032          } 
    10251033           
    1026           if ($cur->blog_name !== null && $cur->blog_name == '') { 
     1034          if (($cur->blog_name !== null && $cur->blog_name == '') || 
     1035               (!$cur->blog_name)) { 
    10271036               throw new Exception(__('No blog name')); 
    10281037          } 
    10291038           
    1030           if ($cur->blog_url !== null && $cur->blog_url == '') { 
     1039          if (($cur->blog_url !== null && $cur->blog_url == '') || 
     1040               (!$cur->blog_url)) { 
    10311041               throw new Exception(__('No blog URL')); 
    10321042          } 
     
    13431353                    array('media_img_title_pattern','string','Title ;; Date(%b %Y) ;; separator(, )', 
    13441354                    'Pattern to set image title when you insert it in a post'), 
     1355                    array('nb_post_for_home','integer',20, 
     1356                    'Number of entries on first home page'), 
    13451357                    array('nb_post_per_page','integer',20, 
    1346                     'Number of entries on home page and category pages'), 
     1358                    'Number of entries on home pages and category pages'), 
    13471359                    array('nb_post_per_feed','integer',20, 
    13481360                    'Number of entries on feeds'), 
     
    15061518          } 
    15071519     } 
     1520 
     1521     /** 
     1522      Return elapsed time since script has been started 
     1523      @param   $mtime <b>float</b> timestamp (microtime format) to evaluate delta from 
     1524                                     current time is taken if null 
     1525      @return <b>float</b>        elapsed time 
     1526      */ 
     1527     public function getElapsedTime ($mtime=null) { 
     1528          if ($mtime !== null) { 
     1529               return $mtime-$this->stime; 
     1530          } else { 
     1531               return microtime(true)-$this->stime; 
     1532          } 
     1533     } 
    15081534     //@} 
     1535 
     1536 
     1537 
    15091538} 
    1510 ?> 
  • inc/core/class.dc.core.php

    r2596 r2609  
    3939     public $rest;       ///< <b>dcRestServer</b> dcRestServer object 
    4040     public $log;        ///< <b>dcLog</b>             dcLog object 
     41     public $tpl;        ///< <b>Twig_Environment</b>  Twig_Environment object 
    4142     public $stime;      ///< <b>float</b>             starting time 
    42  
     43      
    4344     private $versions = null; 
    4445     private $formaters = array(); 
    4546     private $behaviors = array(); 
    4647     private $post_types = array(); 
    47  
     48      
    4849     /** 
    4950     dcCore constructor inits everything related to Dotclear. It takes arguments 
    5051     to init database connection. 
    51  
     52      
    5253     @param    driver    <b>string</b>  Database driver name 
    5354     @param    host      <b>string</b>  Database hostname 
     
    6768 
    6869          $this->con = dbLayer::init($driver,$host,$db,$user,$password,$persist); 
    69  
     70           
    7071          # define weak_locks for mysql 
    7172          if ($this->con instanceof mysqlConnection) { 
     
    7475               mysqliConnection::$weak_locks = true; 
    7576          } 
    76  
     77           
    7778          # define searchpath for postgresql 
    7879          if ($this->con instanceof pgsqlConnection) 
     
    8687               } 
    8788          } 
    88  
     89           
    8990          $this->prefix = $prefix; 
    90  
     91           
    9192          $this->error = new dcError(); 
    9293          $this->auth = $this->authInstance(); 
    9394          $this->session = new sessionDB($this->con,$this->prefix.'session',DC_SESSION_NAME,'',null,DC_ADMIN_SSL); 
    9495          $this->url = new dcUrlHandlers(); 
    95  
     96           
    9697          $this->plugins = new dcPlugins($this); 
    97  
     98           
    9899          $this->rest = new dcRestServer($this); 
    99  
     100           
    100101          $this->meta = new dcMeta($this); 
    101  
     102           
    102103          $this->log = new dcLog($this); 
    103  
     104           
    104105          $this->addFormater('xhtml', create_function('$s','return $s;')); 
    105106          $this->addFormater('wiki', array($this,'wikiTransform')); 
    106      } 
    107  
     107          $this->loadTemplateEnvironment(); 
     108     } 
     109      
    108110     private function authInstance() 
    109111     { 
     
    115117               $c = DC_AUTH_CLASS; 
    116118          } 
    117  
     119           
    118120          if (!class_exists($c)) { 
    119121               throw new Exception('Authentication class '.$c.' does not exist.'); 
    120122          } 
    121  
     123           
    122124          if ($c != 'dcAuth' && !is_subclass_of($c,'dcAuth')) { 
    123125               throw new Exception('Authentication class '.$c.' does not inherit dcAuth.'); 
    124126          } 
    125  
     127           
    126128          return new $c($this); 
    127129     } 
    128  
    129  
     130      
     131     /** 
     132     Create template environment (Twig_Environment instance) 
     133      
     134     default-templates path must be added from admin|public/prepend.php with: 
     135     $core->tpl->getLoader()->addPath('PATH_TO/default-templates'); 
     136     Selected theme path must be added with: 
     137     $core->tpl->getLoader()->prependPath('PATH_TO/MY_THEME'); 
     138     */ 
     139     public function loadTemplateEnvironment() 
     140     { 
     141          $cache_dir = path::real(DC_TPL_CACHE.'/twtpl',false); 
     142          if (!is_dir($cache_dir)) { 
     143               try { 
     144                    files::makeDir($cache_dir); 
     145               } catch (Exception $e) { 
     146                    $cache_dir = false; 
     147               } 
     148          } 
     149           
     150          $this->tpl = new Twig_Environment( 
     151               new Twig_Loader_Filesystem(dirname(__FILE__).'/../swf'), 
     152               array( 
     153                    'auto_reload' => true, 
     154                    'autoescape' => false, 
     155                    'base_template_class' => 'Twig_Template', 
     156                    'cache' => $cache_dir,  
     157                    'charset' => 'UTF-8', 
     158                    'debug' => DC_DEBUG, 
     159                    'optimizations' => -1, 
     160                    'strict_variables' => 0 //DC_DEBUG // Please fix undefined variables! 
     161               ) 
     162          ); 
     163          $this->tpl->addExtension(new dcFormExtension($this)); 
     164          $this->tpl->addExtension(new dcTabExtension($this)); 
     165     } 
     166      
    130167     /// @name Blog init methods 
    131168     //@{ 
    132169     /** 
    133170     Sets a blog to use in <var>blog</var> property. 
    134  
     171      
    135172     @param    id        <b>string</b>       Blog ID 
    136173     */ 
     
    139176          $this->blog = new dcBlog($this, $id); 
    140177     } 
    141  
     178      
    142179     /** 
    143180     Unsets <var>blog</var> property. 
     
    148185     } 
    149186     //@} 
    150  
    151  
     187      
     188      
    152189     /// @name Blog status methods 
    153190     //@{ 
    154191     /** 
    155192     Returns an array of available blog status codes and names. 
    156  
     193      
    157194     @return   <b>array</b> Simple array with codes in keys and names in value 
    158195     */ 
     
    165202          ); 
    166203     } 
    167  
     204      
    168205     /** 
    169206     Returns a blog status name given to a code. This is intended to be 
    170207     human-readable and will be translated, so never use it for tests. 
    171208     If status code does not exist, returns <i>offline</i>. 
    172  
     209      
    173210     @param    s    <b>integer</b> Status code 
    174211     @return   <b>string</b> Blog status name 
     
    183220     } 
    184221     //@} 
    185  
     222      
    186223     /// @name Admin nonce secret methods 
    187224     //@{ 
    188  
     225      
    189226     public function getNonce() 
    190227     { 
    191228          return crypt::hmac(DC_MASTER_KEY,session_id()); 
    192229     } 
    193  
     230      
    194231     public function checkNonce($secret) 
    195232     { 
     
    197234               return false; 
    198235          } 
    199  
     236           
    200237          return $secret == crypt::hmac(DC_MASTER_KEY,session_id()); 
    201238     } 
    202  
     239      
    203240     public function formNonce() 
    204241     { 
     
    206243               return; 
    207244          } 
    208  
     245           
    209246          return form::hidden(array('xd_check'),$this->getNonce()); 
    210247     } 
    211248     //@} 
    212  
    213  
     249      
     250      
    214251     /// @name Text Formatters methods 
    215252     //@{ 
     
    218255     transform text. The function must be a valid callback and takes one 
    219256     argument: the string to transform. It returns the transformed string. 
    220  
     257      
    221258     @param    name      <b>string</b>       Formater name 
    222259     @param    func      <b>callback</b>     Function to use, must be a valid and callable callback 
     
    228265          } 
    229266     } 
    230  
     267      
    231268     /** 
    232269     Returns formaters list. 
    233  
     270      
    234271     @return   <b>array</b> An array of formaters names in values. 
    235272     */ 
     
    238275          return array_keys($this->formaters); 
    239276     } 
    240  
     277      
    241278     /** 
    242279     If <var>$name</var> is a valid formater, it returns <var>$str</var> 
    243280     transformed using that formater. 
    244  
     281      
    245282     @param    name      <b>string</b>       Formater name 
    246283     @param    str       <b>string</b>       String to transform 
     
    252289               return call_user_func($this->formaters[$name],$str); 
    253290          } 
    254  
     291           
    255292          return $str; 
    256293     } 
    257294     //@} 
    258  
    259  
     295      
     296      
    260297     /// @name Behaviors methods 
    261298     //@{ 
     
    263300     Adds a new behavior to behaviors stack. <var>$func</var> must be a valid 
    264301     and callable callback. 
    265  
     302      
    266303     @param    behavior  <b>string</b>       Behavior name 
    267304     @param    func      <b>callback</b>     Function to call 
     
    273310          } 
    274311     } 
    275  
     312      
    276313     /** 
    277314     Tests if a particular behavior exists in behaviors stack. 
    278  
     315      
    279316     @param    behavior  <b>string</b>  Behavior name 
    280317     @return   <b>boolean</b> 
     
    284321          return isset($this->behaviors[$behavior]); 
    285322     } 
    286  
     323      
    287324     /** 
    288325     Get behaviors stack (or part of). 
    289  
     326      
    290327     @param    behavior  <b>string</b>       Behavior name 
    291328     @return   <b>array</b> 
     
    294331     { 
    295332          if (empty($this->behaviors)) return null; 
    296  
     333           
    297334          if ($behavior == '') { 
    298335               return $this->behaviors; 
     
    300337               return $this->behaviors[$behavior]; 
    301338          } 
    302  
     339           
    303340          return array(); 
    304341     } 
    305  
     342      
    306343     /** 
    307344     Calls every function in behaviors stack for a given behavior and returns 
    308345     concatened result of each function. 
    309  
     346      
    310347     Every parameters added after <var>$behavior</var> will be pass to 
    311348     behavior calls. 
    312  
     349      
    313350     @param    behavior  <b>string</b>  Behavior name 
    314351     @return   <b>string</b> Behavior concatened result 
     
    320357               $args = func_get_args(); 
    321358               array_shift($args); 
    322  
     359                
    323360               $res = ''; 
    324  
     361                
    325362               foreach ($this->behaviors[$behavior] as $f) { 
    326363                    $res .= call_user_func_array($f,$args); 
    327364               } 
    328  
     365                
    329366               return $res; 
    330367          } 
    331368     } 
    332369     //@} 
    333  
     370      
    334371     /// @name Post types URLs management 
    335372     //@{ 
     
    339376               $type = 'post'; 
    340377          } 
    341  
     378           
    342379          $url = sprintf($this->post_types[$type]['admin_url'],$post_id); 
    343380          return $escaped ? html::escapeURL($url) : $url; 
    344381     } 
    345  
     382      
    346383     public function getPostPublicURL($type,$post_url,$escaped=true) 
    347384     { 
     
    349386               $type = 'post'; 
    350387          } 
    351  
     388           
    352389          $url = sprintf($this->post_types[$type]['public_url'],$post_url); 
    353390          return $escaped ? html::escapeURL($url) : $url; 
    354391     } 
    355  
     392      
    356393     public function setPostType($type,$admin_url,$public_url,$label='') 
    357394     { 
     
    362399          ); 
    363400     } 
    364  
     401      
    365402     public function getPostTypes() 
    366403     { 
     
    368405     } 
    369406     //@} 
    370  
     407      
    371408     /// @name Versions management methods 
    372409     //@{ 
    373410     /** 
    374411     Returns a given $module version. 
    375  
     412      
    376413     @param    module    <b>string</b>  Module name 
    377414     @return   <b>string</b>  Module version 
     
    384421               $strReq = 'SELECT module, version FROM '.$this->prefix.'version'; 
    385422               $rs = $this->con->select($strReq); 
    386  
     423                
    387424               while ($rs->fetch()) { 
    388425                    $this->versions[$rs->module] = $rs->version; 
    389426               } 
    390427          } 
    391  
     428           
    392429          if (isset($this->versions[$module])) { 
    393430               return $this->versions[$module]; 
     
    396433          } 
    397434     } 
    398  
     435      
    399436     /** 
    400437     Sets $version to given $module. 
    401  
     438      
    402439     @param    module    <b>string</b>  Module name 
    403440     @param    version   <b>string</b>  Module version 
     
    406443     { 
    407444          $cur_version = $this->getVersion($module); 
    408  
     445           
    409446          $cur = $this->con->openCursor($this->prefix.'version'); 
    410447          $cur->module = (string) $module; 
    411448          $cur->version = (string) $version; 
    412  
     449           
    413450          if ($cur_version === null) { 
    414451               $cur->insert(); 
     
    416453               $cur->update("WHERE module='".$this->con->escape($module)."'"); 
    417454          } 
    418  
     455           
    419456          $this->versions[$module] = $version; 
    420457     } 
    421  
     458      
    422459     /** 
    423460     Removes given $module version entry. 
    424  
     461      
    425462     @param    module    <b>string</b>  Module name 
    426463     */ 
     
    430467          'DELETE FROM '.$this->prefix.'version '. 
    431468          "WHERE module = '".$this->con->escape($module)."' "; 
    432  
     469           
    433470          $this->con->execute($strReq); 
    434  
     471           
    435472          if (is_array($this->versions)) { 
    436473               unset($this->versions[$module]); 
    437474          } 
    438475     } 
    439  
     476      
    440477     //@} 
    441  
     478      
    442479     /// @name Users management methods 
    443480     //@{ 
    444481     /** 
    445482     Returns a user by its ID. 
    446  
     483      
    447484     @param    id        <b>string</b>       User ID 
    448485     @return   <b>record</b> 
     
    451488     { 
    452489          $params['user_id'] = $id; 
    453  
     490           
    454491          return $this->getUsers($params); 
    455492     } 
    456  
     493      
    457494     /** 
    458495     Returns a users list. <b>$params</b> is an array with the following 
    459496     optionnal parameters: 
    460  
     497      
    461498      - <var>q</var>: search string (on user_id, user_name, user_firstname) 
    462499      - <var>user_id</var>: user ID 
    463500      - <var>order</var>: ORDER BY clause (default: user_id ASC) 
    464501      - <var>limit</var>: LIMIT clause (should be an array ![limit,offset]) 
    465  
     502      
    466503     @param    params         <b>array</b>        Parameters 
    467504     @param    count_only     <b>boolean</b>      Only counts results 
     
    488525               'WHERE NULL IS NULL '; 
    489526          } 
    490  
     527           
    491528          if (!empty($params['q'])) { 
    492529               $q = $this->con->escape(str_replace('*','%',strtolower($params['q']))); 
     
    497534                    ') '; 
    498535          } 
    499  
     536           
    500537          if (!empty($params['user_id'])) { 
    501538               $strReq .= "AND U.user_id = '".$this->con->escape($params['user_id'])."' "; 
    502539          } 
    503  
     540           
    504541          if (!$count_only) { 
    505542               $strReq .= 'GROUP BY U.user_id,user_super,user_status,user_pwd,user_change_pwd,'. 
    506543               'user_name,user_firstname,user_displayname,user_email,user_url,'. 
    507544               'user_desc, user_lang,user_tz,user_post_status,user_options '; 
    508  
     545                
    509546               if (!empty($params['order']) && !$count_only) { 
    510547                    $strReq .= 'ORDER BY '.$this->con->escape($params['order']).' '; 
     
    513550               } 
    514551          } 
    515  
     552           
    516553          if (!$count_only && !empty($params['limit'])) { 
    517554               $strReq .= $this->con->limit($params['limit']); 
    518555          } 
    519  
     556           
    520557          $rs = $this->con->select($strReq); 
    521558          $rs->extend('rsExtUser'); 
    522559          return $rs; 
    523560     } 
    524  
     561      
    525562     /** 
    526563     Create a new user. Takes a cursor as input and returns the new user ID. 
    527  
     564      
    528565     @param    cur       <b>cursor</b>       User cursor 
    529566     @return   <b>string</b> 
     
    534571               throw new Exception(__('You are not an administrator')); 
    535572          } 
    536  
     573           
    537574          if ($cur->user_id == '') { 
    538575               throw new Exception(__('No user ID given')); 
    539576          } 
    540  
     577           
    541578          if ($cur->user_pwd == '') { 
    542579               throw new Exception(__('No password given')); 
    543580          } 
    544  
     581           
    545582          $this->getUserCursor($cur); 
    546  
     583           
    547584          if ($cur->user_creadt === null) { 
    548585               $cur->user_creadt = date('Y-m-d H:i:s'); 
    549586          } 
    550  
     587           
    551588          $cur->insert(); 
    552  
     589           
    553590          $this->auth->afterAddUser($cur); 
    554  
     591           
    555592          return $cur->user_id; 
    556593     } 
    557  
     594      
    558595     /** 
    559596     Updates an existing user. Returns the user ID. 
    560  
     597      
    561598     @param    id        <b>string</b>       User ID 
    562599     @param    cur       <b>cursor</b>       User cursor 
     
    566603     { 
    567604          $this->getUserCursor($cur); 
    568  
     605           
    569606          if (($cur->user_id !== null || $id != $this->auth->userID()) && 
    570607          !$this->auth->isSuperAdmin()) { 
    571608               throw new Exception(__('You are not an administrator')); 
    572609          } 
    573  
     610           
    574611          $cur->update("WHERE user_id = '".$this->con->escape($id)."' "); 
    575  
     612           
    576613          $this->auth->afterUpdUser($id,$cur); 
    577  
     614           
    578615          if ($cur->user_id !== null) { 
    579616               $id = $cur->user_id; 
    580617          } 
    581  
     618           
    582619          # Updating all user's blogs 
    583620          $rs = $this->con->select( 
     
    585622               "WHERE user_id = '".$this->con->escape($id)."' " 
    586623               ); 
    587  
     624           
    588625          while ($rs->fetch()) { 
    589626               $b = new dcBlog($this,$rs->blog_id); 
     
    591628               unset($b); 
    592629          } 
    593  
     630           
    594631          return $id; 
    595632     } 
    596  
     633      
    597634     /** 
    598635     Deletes a user. 
    599  
     636      
    600637     @param    id        <b>string</b>       User ID 
    601638     */ 
     
    605642               throw new Exception(__('You are not an administrator')); 
    606643          } 
    607  
     644           
    608645          if ($id == $this->auth->userID()) { 
    609646               return; 
    610647          } 
    611  
     648           
    612649          $rs = $this->getUser($id); 
    613  
     650           
    614651          if ($rs->nb_post > 0) { 
    615652               return; 
    616653          } 
    617  
     654           
    618655          $strReq = 'DELETE FROM '.$this->prefix.'user '. 
    619656                    "WHERE user_id = '".$this->con->escape($id)."' "; 
    620  
     657           
    621658          $this->con->execute($strReq); 
    622  
     659           
    623660          $this->auth->afterDelUser($id); 
    624661     } 
    625  
     662      
    626663     /** 
    627664     Checks whether a user exists. 
    628  
     665      
    629666     @param    id        <b>string</b>       User ID 
    630667     @return   <b>boolean</b> 
     
    635672                    'FROM '.$this->prefix.'user '. 
    636673                    "WHERE user_id = '".$this->con->escape($id)."' "; 
    637  
     674           
    638675          $rs = $this->con->select($strReq); 
    639  
     676           
    640677          return !$rs->isEmpty(); 
    641678     } 
    642  
     679      
    643680     /** 
    644681     Returns all user permissions as an array which looks like: 
    645  
     682      
    646683      - [blog_id] 
    647684        - [name] => Blog name 
     
    650687          - [permission] => true 
    651688          - ... 
    652  
     689      
    653690     @param    id        <b>string</b>       User ID 
    654691     @return   <b>array</b> 
     
    660697                    'INNER JOIN '.$this->prefix.'blog B ON P.blog_id = B.blog_id '. 
    661698                    "WHERE user_id = '".$this->con->escape($id)."' "; 
    662  
     699           
    663700          $rs = $this->con->select($strReq); 
    664  
     701           
    665702          $res = array(); 
    666  
     703           
    667704          while ($rs->fetch()) 
    668705          { 
     
    673710               ); 
    674711          } 
    675  
     712           
    676713          return $res; 
    677714     } 
    678  
     715      
    679716     /** 
    680717     Sets user permissions. The <var>$perms</var> array looks like: 
    681  
     718      
    682719      - [blog_id] => '|perm1|perm2|' 
    683720      - ... 
    684  
     721      
    685722     @param    id        <b>string</b>       User ID 
    686723     @param    perms     <b>array</b>        Permissions array 
     
    691728               throw new Exception(__('You are not an administrator')); 
    692729          } 
    693  
     730           
    694731          $strReq = 'DELETE FROM '.$this->prefix.'permissions '. 
    695732                    "WHERE user_id = '".$this->con->escape($id)."' "; 
    696  
     733           
    697734          $this->con->execute($strReq); 
    698  
     735           
    699736          foreach ($perms as $blog_id => $p) { 
    700737               $this->setUserBlogPermissions($id, $blog_id, $p, false); 
    701738          } 
    702739     } 
    703  
     740      
    704741     /** 
    705742     Sets user permissions for a given blog. <var>$perms</var> is an array with 
    706743     permissions in values 
    707  
     744      
    708745     @param    id             <b>string</b>       User ID 
    709746     @param    blog_id        <b>string</b>       Blog ID 
     
    716753               throw new Exception(__('You are not an administrator')); 
    717754          } 
    718  
     755           
    719756          $no_perm = empty($perms); 
    720  
     757           
    721758          $perms = '|'.implode('|',array_keys($perms)).'|'; 
    722  
     759           
    723760          $cur = $this->con->openCursor($this->prefix.'permissions'); 
    724  
     761           
    725762          $cur->user_id = (string) $id; 
    726763          $cur->blog_id = (string) $blog_id; 
    727764          $cur->permissions = $perms; 
    728  
     765           
    729766          if ($delete_first || $no_perm) 
    730767          { 
     
    732769                         "WHERE blog_id = '".$this->con->escape($blog_id)."' ". 
    733770                         "AND user_id = '".$this->con->escape($id)."' "; 
    734  
     771                
    735772               $this->con->execute($strReq); 
    736773          } 
    737  
     774           
    738775          if (!$no_perm) { 
    739776               $cur->insert(); 
    740777          } 
    741778     } 
    742  
     779      
    743780     /** 
    744781     Sets a user default blog. This blog will be selected when user log in. 
    745  
     782      
    746783     @param    id             <b>string</b>       User ID 
    747784     @param    blog_id        <b>string</b>       Blog ID 
     
    750787     { 
    751788          $cur = $this->con->openCursor($this->prefix.'user'); 
    752  
     789           
    753790          $cur->user_default_blog = (string) $blog_id; 
    754  
     791           
    755792          $cur->update("WHERE user_id = '".$this->con->escape($id)."'"); 
    756793     } 
    757  
     794      
    758795     private function getUserCursor($cur) 
    759796     { 
     
    762799               throw new Exception(__('User ID must contain at least 2 characters using letters, numbers or symbols.')); 
    763800          } 
    764  
     801           
    765802          if ($cur->user_url !== null && $cur->user_url != '') { 
    766803               if (!preg_match('|^http(s?)://|',$cur->user_url)) { 
     
    768805               } 
    769806          } 
    770  
     807           
    771808          if ($cur->isField('user_pwd')) { 
    772809               if (strlen($cur->user_pwd) < 6) { 
     
    775812               $cur->user_pwd = crypt::hmac(DC_MASTER_KEY,$cur->user_pwd); 
    776813          } 
    777  
     814           
    778815          if ($cur->user_lang !== null && !preg_match('/^[a-z]{2}(-[a-z]{2})?$/',$cur->user_lang)) { 
    779816               throw new Exception(__('Invalid user language code')); 
    780817          } 
    781  
     818           
    782819          if ($cur->user_upddt === null) { 
    783820               $cur->user_upddt = date('Y-m-d H:i:s'); 
    784821          } 
    785  
     822           
    786823          if ($cur->user_options !== null) { 
    787824               $cur->user_options = serialize((array) $cur->user_options); 
    788825          } 
    789826     } 
    790  
     827      
    791828     /** 
    792829     Returns user default settings in an associative array with setting names in 
    793830     keys. 
    794  
     831      
    795832     @return   <b>array</b> 
    796833     */ 
     
    804841     } 
    805842     //@} 
    806  
     843      
    807844     /// @name Blog management methods 
    808845     //@{ 
    809846     /** 
    810847     Returns all blog permissions (users) as an array which looks like: 
    811  
     848      
    812849      - [user_id] 
    813850        - [name] => User name 
     
    818855          - [permission] => true 
    819856          - ... 
    820  
     857      
    821858     @param    id             <b>string</b>       Blog ID 
    822859     @param    with_super     <b>boolean</b>      Includes super admins in result 
     
    831868          'JOIN '.$this->prefix.'permissions P ON U.user_id = P.user_id '. 
    832869          "WHERE blog_id = '".$this->con->escape($id)."' "; 
    833  
     870           
    834871          if ($with_super) { 
    835872               $strReq .= 
     
    840877               'WHERE user_super = 1 '; 
    841878          } 
    842  
     879           
    843880          $rs = $this->con->select($strReq); 
    844  
     881           
    845882          $res = array(); 
    846  
     883           
    847884          while ($rs->fetch()) 
    848885          { 
     
    856893               ); 
    857894          } 
    858  
     895           
    859896          return $res; 
    860897     } 
    861  
     898      
    862899     /** 
    863900     Returns a blog of given ID. 
    864  
     901      
    865902     @param    id        <b>string</b>       Blog ID 
    866903     @return   <b>record</b> 
     
    869906     { 
    870907          $blog = $this->getBlogs(array('blog_id'=>$id)); 
    871  
     908           
    872909          if ($blog->isEmpty()) { 
    873910               return false; 
    874911          } 
    875  
     912           
    876913          return $blog; 
    877914     } 
    878  
     915      
    879916     /** 
    880917     Returns a record of blogs. <b>$params</b> is an array with the following 
    881918     optionnal parameters: 
    882  
     919      
    883920      - <var>blog_id</var>: Blog ID 
    884921      - <var>q</var>: Search string on blog_id, blog_name and blog_url 
    885922      - <var>limit</var>: limit results 
    886  
     923      
    887924     @param    params         <b>array</b>        Parameters 
    888925     @param    count_only     <b>boolean</b>      Count only results 
     
    893930          $join = '';    // %1$s 
    894931          $where = '';   // %2$s 
    895  
     932           
    896933          if ($count_only) 
    897934          { 
     
    911948               'WHERE NULL IS NULL '. 
    912949               '%2$s '; 
    913  
     950                
    914951               if (!empty($params['order'])) { 
    915952                    $strReq .= 'ORDER BY '.$this->con->escape($params['order']).' '; 
     
    917954                    $strReq .= 'ORDER BY B.blog_id ASC '; 
    918955               } 
    919  
     956                
    920957               if (!empty($params['limit'])) { 
    921958                    $strReq .= $this->con->limit($params['limit']); 
    922959               } 
    923960          } 
    924  
     961           
    925962          if ($this->auth->userID() && !$this->auth->isSuperAdmin()) 
    926963          { 
     
    933970               $where = 'AND blog_status IN (1,0) '; 
    934971          } 
    935  
     972           
    936973          if (!empty($params['blog_id'])) { 
    937974               $where .= "AND B.blog_id = '".$this->con->escape($params['blog_id'])."' "; 
    938975          } 
    939  
     976           
    940977          if (!empty($params['q'])) { 
    941978               $params['q'] = strtolower(str_replace('*','%',$params['q'])); 
     
    947984               ') '; 
    948985          } 
    949  
     986           
    950987          $strReq = sprintf($strReq,$join,$where); 
    951988          return $this->con->select($strReq); 
    952989     } 
    953  
     990      
    954991     /** 
    955992     Creates a new blog. 
    956  
     993      
    957994     @param    cur            <b>cursor</b>       Blog cursor 
    958995     */ 
     
    962999               throw new Exception(__('You are not an administrator')); 
    9631000          } 
    964  
     1001           
    9651002          $this->getBlogCursor($cur); 
    966  
     1003           
    9671004          $cur->blog_creadt = date('Y-m-d H:i:s'); 
    9681005          $cur->blog_upddt = date('Y-m-d H:i:s'); 
    9691006          $cur->blog_uid = md5(uniqid()); 
    970  
     1007           
    9711008          $cur->insert(); 
    9721009     } 
    973  
     1010      
    9741011     /** 
    9751012     Updates a given blog. 
    976  
     1013      
    9771014     @param    id        <b>string</b>       Blog ID 
    9781015     @param    cur       <b>cursor</b>       Blog cursor 
     
    9811018     { 
    9821019          $this->getBlogCursor($cur); 
    983  
     1020           
    9841021          $cur->blog_upddt = date('Y-m-d H:i:s'); 
    985  
     1022           
    9861023          $cur->update("WHERE blog_id = '".$this->con->escape($id)."'"); 
    9871024     } 
    988  
     1025      
    9891026     private function getBlogCursor($cur) 
    9901027     { 
     
    9921029               && !preg_match('/^[A-Za-z0-9._-]{2,}$/',$cur->blog_id)) || 
    9931030               (!$cur->blog_id)) { 
    994                throw new Exception(__('Blog ID must contain at least 2 characters using letters, numbers or symbols.')); 
    995           } 
    996  
     1031               throw new Exception(__('Blog ID must contain at least 2 characters using letters, numbers or symbols.'));  
     1032          } 
     1033           
    9971034          if (($cur->blog_name !== null && $cur->blog_name == '') || 
    9981035               (!$cur->blog_name)) { 
    9991036               throw new Exception(__('No blog name')); 
    10001037          } 
    1001  
     1038           
    10021039          if (($cur->blog_url !== null && $cur->blog_url == '') || 
    10031040               (!$cur->blog_url)) { 
    10041041               throw new Exception(__('No blog URL')); 
    10051042          } 
    1006  
     1043           
    10071044          if ($cur->blog_desc !== null) { 
    10081045               $cur->blog_desc = html::clean($cur->blog_desc); 
    10091046          } 
    10101047     } 
    1011  
     1048      
    10121049     /** 
    10131050     Removes a given blog. 
    10141051     @warning This will remove everything related to the blog (posts, 
    10151052     categories, comments, links...) 
    1016  
     1053      
    10171054     @param    id        <b>string</b>       Blog ID 
    10181055     */ 
     
    10221059               throw new Exception(__('You are not an administrator')); 
    10231060          } 
    1024  
     1061           
    10251062          $strReq = 'DELETE FROM '.$this->prefix.'blog '. 
    10261063                    "WHERE blog_id = '".$this->con->escape($id)."' "; 
    1027  
     1064           
    10281065          $this->con->execute($strReq); 
    10291066     } 
    1030  
     1067      
    10311068     /** 
    10321069     Checks if a blog exist. 
    1033  
     1070      
    10341071     @param    id        <b>string</b>       Blog ID 
    10351072     @return   <b>boolean</b> 
     
    10401077                    'FROM '.$this->prefix.'blog '. 
    10411078                    "WHERE blog_id = '".$this->con->escape($id)."' "; 
    1042  
     1079           
    10431080          $rs = $this->con->select($strReq); 
    1044  
     1081           
    10451082          return !$rs->isEmpty(); 
    10461083     } 
    1047  
     1084      
    10481085     /** 
    10491086     Count posts on a blog 
    1050  
     1087      
    10511088     @param    id        <b>string</b>       Blog ID 
    10521089     @param    type      <b>string</b>       Post type 
     
    10581095                    'FROM '.$this->prefix.'post '. 
    10591096                    "WHERE blog_id = '".$this->con->escape($id)."' "; 
    1060  
     1097           
    10611098          if ($type) { 
    10621099               $strReq .= "AND post_type = '".$this->con->escape($type)."' "; 
    10631100          } 
    1064  
     1101           
    10651102          return $this->con->select($strReq)->f(0); 
    10661103     } 
    10671104     //@} 
    1068  
     1105      
    10691106     /// @name HTML Filter methods 
    10701107     //@{ 
     
    10731110     tidy extension is present). If <b>enable_html_filter</b> blog setting is 
    10741111     false, returns not filtered string. 
    1075  
     1112      
    10761113     @param    str  <b>string</b>       String to filter 
    10771114     @return   <b>string</b> Filtered string. 
     
    10821119               return $str; 
    10831120          } 
    1084  
     1121           
    10851122          $filter = new htmlFilter; 
    10861123          $str = trim($filter->apply($str)); 
     
    10881125     } 
    10891126     //@} 
    1090  
     1127      
    10911128     /// @name wiki2xhtml methods 
    10921129     //@{ 
     
    10951132          $this->wiki2xhtml = new wiki2xhtml; 
    10961133     } 
    1097  
     1134      
    10981135     /** 
    10991136     Returns a transformed string with wiki2xhtml. 
    1100  
     1137      
    11011138     @param    str       <b>string</b>       String to transform 
    11021139     @return   <b>string</b>  Transformed string 
     
    11091146          return $this->wiki2xhtml->transform($str); 
    11101147     } 
    1111  
     1148      
    11121149     /** 
    11131150     Inits <var>wiki2xhtml</var> property for blog post. 
     
    11161153     { 
    11171154          $this->initWiki(); 
    1118  
     1155           
    11191156          $this->wiki2xhtml->setOpts(array( 
    11201157               'active_title' => 1, 
     
    11481185               'note_str' => '<div class="footnotes"><h4>Notes</h4>%s</div>' 
    11491186          )); 
    1150  
     1187           
    11511188          $this->wiki2xhtml->registerFunction('url:post',array($this,'wikiPostLink')); 
    1152  
     1189           
    11531190          # --BEHAVIOR-- coreWikiPostInit 
    11541191          $this->callBehavior('coreInitWikiPost',$this->wiki2xhtml); 
    11551192     } 
    1156  
     1193      
    11571194     /** 
    11581195     Inits <var>wiki2xhtml</var> property for simple blog comment (basic syntax). 
     
    11611198     { 
    11621199          $this->initWiki(); 
    1163  
     1200           
    11641201          $this->wiki2xhtml->setOpts(array( 
    11651202               'active_title' => 0, 
     
    11901227               'active_fr_syntax' => 0 
    11911228          )); 
    1192  
     1229           
    11931230          # --BEHAVIOR-- coreInitWikiSimpleComment 
    11941231          $this->callBehavior('coreInitWikiSimpleComment',$this->wiki2xhtml); 
    11951232     } 
    1196  
     1233      
    11971234     /** 
    11981235     Inits <var>wiki2xhtml</var> property for blog comment. 
     
    12011238     { 
    12021239          $this->initWiki(); 
    1203  
     1240           
    12041241          $this->wiki2xhtml->setOpts(array( 
    12051242               'active_title' => 0, 
     
    12301267               'active_fr_syntax' => 0 
    12311268          )); 
    1232  
     1269           
    12331270          # --BEHAVIOR-- coreInitWikiComment 
    12341271          $this->callBehavior('coreInitWikiComment',$this->wiki2xhtml); 
    12351272     } 
    1236  
     1273      
    12371274     public function wikiPostLink($url,$content) 
    12381275     { 
    1239           if (!($this->blog instanceof dcBlog)) { 
     1276          if (!($this->blog instanceof dcBlog)) {  
    12401277               return array(); 
    12411278          } 
    1242  
     1279           
    12431280          $post_id = abs((integer) substr($url,5)); 
    12441281          if (!$post_id) { 
    12451282               return array(); 
    12461283          } 
    1247  
     1284           
    12481285          $post = $this->blog->getPosts(array('post_id'=>$post_id)); 
    12491286          if ($post->isEmpty()) { 
    12501287               return array(); 
    12511288          } 
    1252  
     1289           
    12531290          $res = array('url' => $post->getURL()); 
    12541291          $post_title = $post->post_title; 
    1255  
     1292           
    12561293          if ($content != $url) { 
    12571294               $res['title'] = html::escapeHTML($post->post_title); 
    12581295          } 
    1259  
     1296           
    12601297          if ($content == '' || $content == $url) { 
    12611298               $res['content'] = html::escapeHTML($post->post_title); 
    12621299          } 
    1263  
     1300           
    12641301          if ($post->post_lang) { 
    12651302               $res['lang'] = $post->post_lang; 
    12661303          } 
    1267  
     1304           
    12681305          return $res; 
    12691306     } 
    12701307     //@} 
    1271  
     1308      
    12721309     /// @name Maintenance methods 
    12731310     //@{ 
     
    12751312     Creates default settings for active blog. Optionnal parameter 
    12761313     <var>defaults</var> replaces default params while needed. 
    1277  
     1314      
    12781315     @param    defaults       <b>array</b>   Default parameters 
    12791316     */ 
     
    13601397               ); 
    13611398          } 
    1362  
     1399           
    13631400          $settings = new dcSettings($this,null); 
    13641401          $settings->addNamespace('system'); 
    1365  
     1402           
    13661403          foreach ($defaults as $v) { 
    13671404               $settings->system->put($v[0],$v[2],$v[1],$v[3],false,true); 
    13681405          } 
    13691406     } 
    1370  
     1407      
    13711408     /** 
    13721409     Recreates entries search engine index. 
    1373  
     1410      
    13741411     @param    start     <b>integer</b>      Start entry index 
    13751412     @param    limit     <b>integer</b>      Number of entry to index 
    1376  
     1413      
    13771414     @return   <b>integer</b>      <var>$start</var> and <var>$limit</var> sum 
    13781415     */ 
     
    13831420          $rs = $this->con->select($strReq); 
    13841421          $count = $rs->f(0); 
    1385  
     1422           
    13861423          $strReq = 'SELECT post_id, post_title, post_excerpt_xhtml, post_content_xhtml '. 
    13871424                    'FROM '.$this->prefix.'post '; 
    1388  
     1425           
    13891426          if ($start !== null && $limit !== null) { 
    13901427               $strReq .= $this->con->limit($start,$limit); 
    13911428          } 
    1392  
     1429           
    13931430          $rs = $this->con->select($strReq,true); 
    1394  
     1431           
    13951432          $cur = $this->con->openCursor($this->prefix.'post'); 
    1396  
     1433           
    13971434          while ($rs->fetch()) 
    13981435          { 
    13991436               $words = $rs->post_title.' '. $rs->post_excerpt_xhtml.' '. 
    14001437               $rs->post_content_xhtml; 
    1401  
     1438                
    14021439               $cur->post_words = implode(' ',text::splitWords($words)); 
    14031440               $cur->update('WHERE post_id = '.(integer) $rs->post_id); 
    14041441               $cur->clean(); 
    14051442          } 
    1406  
     1443           
    14071444          if ($start+$limit > $count) { 
    14081445               return null; 
     
    14101447          return $start+$limit; 
    14111448     } 
    1412  
     1449      
    14131450     /** 
    14141451     Recreates comments search engine index. 
    1415  
     1452      
    14161453     @param    start     <b>integer</b>      Start comment index 
    14171454     @param    limit     <b>integer</b>      Number of comments to index 
    1418  
     1455      
    14191456     @return   <b>integer</b>      <var>$start</var> and <var>$limit</var> sum 
    14201457     */ 
     
    14251462          $rs = $this->con->select($strReq); 
    14261463          $count = $rs->f(0); 
    1427  
     1464           
    14281465          $strReq = 'SELECT comment_id, comment_content '. 
    14291466                    'FROM '.$this->prefix.'comment '; 
    1430  
     1467           
    14311468          if ($start !== null && $limit !== null) { 
    14321469               $strReq .= $this->con->limit($start,$limit); 
    14331470          } 
    1434  
     1471           
    14351472          $rs = $this->con->select($strReq); 
    1436  
     1473           
    14371474          $cur = $this->con->openCursor($this->prefix.'comment'); 
    1438  
     1475           
    14391476          while ($rs->fetch()) 
    14401477          { 
     
    14431480               $cur->clean(); 
    14441481          } 
    1445  
     1482           
    14461483          if ($start+$limit > $count) { 
    14471484               return null; 
     
    14491486          return $start+$limit; 
    14501487     } 
    1451  
     1488      
    14521489     /** 
    14531490     Reinits nb_comment and nb_trackback in post table. 
     
    14551492     public function countAllComments() 
    14561493     { 
    1457  
     1494      
    14581495          $updCommentReq = 'UPDATE '.$this->prefix.'post P '. 
    14591496               'SET nb_comment = ('. 
     
    14711508          $this->con->execute($updTrackbackReq); 
    14721509     } 
    1473  
     1510      
    14741511     /** 
    14751512     Empty templates cache directory 
Note: See TracChangeset for help on using the changeset viewer.

Sites map