Dotclear

Changeset 782:01efbf050a8a for inc/core


Ignore:
Timestamp:
12/06/11 11:43:14 (14 years ago)
Author:
Dsls <dsls@…>
Branch:
formfilters
Parents:
781:b509ac00bf4a (diff), 779:58c45f1b96e5 (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:

Merged last default changes with formfilter branch

Files:
2 edited

Legend:

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

    r778 r782  
    106106     } 
    107107      
     108     /** 
     109     Returns sql statement for a given parameter.  
     110     Computes in() or not_in lists in parameter 
     111 
     112     @param    params    <b>array</b> query parameters 
     113     @param    param_name     <b>array</b> parameter to check 
     114     @param    sql column     <b>array</b> sql column matching parameter name 
     115      
     116     @return   <b>string</b> the generated SQL statement 
     117     */ 
     118     protected function getInParamStr($params, $param_name, $sql_column) { 
     119          $not=''; 
     120          if (isset($params[$param_name.'_not'])) { 
     121               $not = "NOT "; 
     122          } 
     123          return $sql_column.' '.$not.$this->con->in($params[$param_name]).' '; 
     124     } 
     125      
    108126     /// @name Common public methods 
    109127     //@{ 
     
    755773           
    756774          if (!empty($params['user_id'])) { 
    757                $strReq .= "AND U.user_id = '".$this->con->escape($params['user_id'])."' "; 
     775               $strReq .= 'AND '.$this->getInParamStr($params,'user_id','U.user_id'); 
    758776          } 
    759777           
     
    781799          /* Other filters */ 
    782800          if (isset($params['post_status'])) { 
    783                $strReq .= 'AND post_status = '.(integer) $params['post_status'].' '; 
     801               $strReq .= 'AND '.$this->getInParamStr($params,'post_status','post_status'); 
    784802          } 
    785803           
     
    804822           
    805823          if (!empty($params['post_lang'])) { 
    806                $strReq .= "AND P.post_lang = '".$this->con->escape($params['post_lang'])."' "; 
     824               $strReq .= 'AND '.$this->getInParamStr($params,'post_lang','P.post_lang'); 
    807825          } 
    808826           
     
    14471465     { 
    14481466          $field = $field == 'cat_id' ? 'cat_id' : 'cat_url'; 
    1449            
    14501467          $sub = array(); 
    14511468          $not = array(); 
     
    14611478               if (isset($args['not'])) { $not[$id] = 1; } 
    14621479               if (isset($args['sub'])) { $sub[$id] = 1; } 
     1480               $nullExcluded = false; 
    14631481               if ($field == 'cat_id') { 
    14641482                    if (preg_match('/^null$/i',$id)) { 
    14651483                         $queries[$id] = 'P.cat_id IS NULL'; 
     1484                         if (isset($not[$id]) && ($not[$id] == 1)) { 
     1485                              $nullExcluded = true; 
     1486                         } 
    14661487                    } 
    14671488                    else { 
     
    15051526           
    15061527          if ($sql[1]) { 
    1507                $sql[1] = '(P.cat_id IS NULL OR NOT('.$sql[1].'))'; 
     1528               if ($nullExcluded) { 
     1529                    $sql[1] = 'NOT('.$sql[1].')'; 
     1530               } else { 
     1531                    $sql[1] = '(P.cat_id IS NULL OR NOT('.$sql[1].'))'; 
     1532               } 
    15081533          } else { 
    15091534               unset($sql[1]); 
    15101535          } 
    1511            
    15121536          return implode(' AND ',$sql); 
    15131537     } 
     
    18081832           
    18091833          if (isset($params['comment_status'])) { 
    1810                $strReq .= 'AND comment_status = '.(integer) $params['comment_status'].' '; 
    1811           } 
    1812            
    1813           if (!empty($params['comment_status_not'])) 
     1834               $strReq .= 'AND '.$this->getInParamStr($params,'comment_status','comment_status'); 
     1835          }  
     1836          elseif (!empty($params['comment_status_not'])) // older method, deprecated 
    18141837          { 
    18151838               $strReq .= 'AND comment_status <> '.(integer) $params['comment_status_not'].' '; 
     
    18271850               $q_author = $this->con->escape(str_replace('*','%',strtolower($params['q_author']))); 
    18281851               $strReq .= "AND LOWER(comment_author) LIKE '".$q_author."' "; 
     1852          } 
     1853          if (isset($params['comment_author'])) { 
     1854               $strReq .= "AND comment_author ".$this->con->in($params['comment_author']).' '; 
    18291855          } 
    18301856           
  • inc/core/class.dc.blog.php

    r764 r782  
    44# This file is part of Dotclear 2. 
    55# 
    6 # Copyright (c) 2003-2010 Olivier Meunier & Association Dotclear 
     6# Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear 
    77# Licensed under the GPL version 2.0 license. 
    88# See LICENSE file or 
     
    2121class dcBlog 
    2222{ 
    23      protected $core;    ///< <b>dcCore</b> dcCore instance 
    24      public $con;        ///< <b>connection</b>   Database connection object 
    25      public $prefix;     ///< <b>string</b>       Database table prefix 
    26       
    27      public $id;         ///< <b>string</b>       Blog ID 
    28      public $uid;        ///< <b>string</b>       Blog unique ID 
    29      public $name;       ///< <b>string</b>       Blog name 
    30      public $desc;       ///< <b>string</b>       Blog description 
    31      public $url;        ///< <b>string</b>       Blog URL 
    32      public $host;       ///< <b>string</b>       Blog host 
    33      public $creadt;     ///< <b>string</b>       Blog creation date 
    34      public $upddt;      ///< <b>string</b>       Blog last update date 
    35      public $status;     ///< <b>string</b>       Blog status 
    36       
    37      public $settings;        ///< <b>dcSettings</b>   dcSettings object 
    38      public $themes_path;     ///< <b>string</b>       Blog theme path 
    39      public $public_path;     ///< <b>string</b>       Blog public path 
     23     /** @var dcCore dcCore instance */ 
     24     protected $core; 
     25     /** @var connection Database connection object */ 
     26     public $con; 
     27     /** @var string Database table prefix */ 
     28     public $prefix; 
     29      
     30     /** @var string Blog ID */ 
     31     public $id; 
     32     /** @var string Blog unique ID */ 
     33     public $uid; 
     34     /** @var string Blog name */ 
     35     public $name; 
     36     /** @var string Blog description */ 
     37     public $desc; 
     38     /** @var string Blog URL */ 
     39     public $url; 
     40     /** @var string Blog host */ 
     41     public $host; 
     42     /** @var string Blog creation date */ 
     43     public $creadt; 
     44     /** @var string Blog last update date */ 
     45     public $upddt; 
     46     /** @var string Blog status */ 
     47     public $status; 
     48      
     49     /** @var dcSettings dcSettings object */ 
     50     public $settings; 
     51     /** @var string Blog theme path */ 
     52     public $themes_path; 
     53     /** @var string Blog public path */ 
     54     public $public_path; 
    4055      
    4156     private $post_status = array(); 
     
    4459     private $categories; 
    4560      
    46      public $without_password = true;   ///< <b>boolean</b> Disallow entries password protection 
     61     /** @var boolean Disallow entries password protection */ 
     62     public $without_password = true; 
    4763      
    4864     /** 
     
    409425           
    410426          if (!empty($params['post_type'])) { 
    411                $strReq .= "AND post_type = '".$this->con->escape($params['post_type'])."' "; 
     427               $strReq .= 'AND P.post_type '.$this->con->in($params['post_type']); 
    412428          } 
    413429           
     
    585601           
    586602          $this->categories()->resetOrder(); 
     603          $this->triggerBlog(); 
    587604     } 
    588605      
     
    659676     - order: Order of results (default "ORDER BY post_dt DES") 
    660677     - limit: Limit parameter 
     678     - sql_only : return the sql request instead of results. Only ids are selected 
    661679      
    662680     Please note that on every cat_id or cat_url, you can add ?not to exclude 
     
    665683     @param    params         <b>array</b>        Parameters 
    666684     @param    count_only     <b>boolean</b>      Only counts results 
    667      @param    sql_only  <b>boolean</b>      Only return SQL request 
    668685     @return   <b>record</b>  A record with some more capabilities or the SQL request 
    669686     */ 
    670      public function getPosts($params=array(),$count_only=false,$sql_only=false) 
     687     public function getPosts($params=array(),$count_only=false) 
    671688     { 
    672689          if ($count_only) 
    673690          { 
    674691               $strReq = 'SELECT count(P.post_id) '; 
     692          } 
     693          elseif (!empty($params['sql_only']))  
     694          { 
     695               $strReq = 'SELECT P.post_id '; 
    675696          } 
    676697          else 
     
    729750          if (isset($params['post_type'])) 
    730751          { 
    731                if (is_array($params['post_type']) && !empty($params['post_type'])) { 
     752               if (is_array($params['post_type']) || $params['post_type'] != '') { 
    732753                    $strReq .= 'AND post_type '.$this->con->in($params['post_type']); 
    733                } elseif ($params['post_type'] != '') { 
    734                     $strReq .= "AND post_type = '".$this->con->escape($params['post_type'])."' "; 
    735754               } 
    736755          } 
     
    844863          } 
    845864           
    846           if ($sql_only) { 
     865          if (!empty($params['sql_only'])) { 
    847866               return $strReq; 
    848867          } 
     
    876895           
    877896          if($dir > 0) { 
    878                $sign = '>'; 
    879                $order = 'ASC'; 
    880           } 
    881           else { 
    882                $sign = '<'; 
    883                $order = 'DESC'; 
    884           } 
     897               $sign = '>'; 
     898               $order = 'ASC'; 
     899          } 
     900          else { 
     901               $sign = '<'; 
     902               $order = 'DESC'; 
     903          } 
    885904           
    886905          $params['post_type'] = $post->post_type; 
     
    10431062               $strReq .= "AND post_type = 'post' "; 
    10441063          } 
    1045                      
     1064           
    10461065          if (!empty($params['year'])) { 
    10471066               $strReq .= 'AND '.$this->con->dateFormat('post_dt','%Y')." = '".sprintf('%04d',$params['year'])."' "; 
     
    11831202          $cur->post_upddt = date('Y-m-d H:i:s'); 
    11841203           
    1185           #If user is only "usage", we need to check the post's owner 
     1204          #If user is only "usage", we need to check the post's owner 
    11861205          if (!$this->core->auth->check('contentadmin',$this->id)) 
    11871206          { 
     
    17311750     - order: Order of results (default "ORDER BY comment_dt DES") 
    17321751     - limit: Limit parameter 
     1752     - sql_only : return the sql request instead of results. Only ids are selected 
    17331753      
    17341754     @param    params         <b>array</b>        Parameters 
     
    17411761          { 
    17421762               $strReq = 'SELECT count(comment_id) '; 
     1763          } 
     1764          elseif (!empty($params['sql_only']))  
     1765          { 
     1766               $strReq = 'SELECT P.post_id '; 
    17431767          } 
    17441768          else 
     
    17921816          if (!empty($params['post_type'])) 
    17931817          { 
    1794                if (is_array($params['post_type']) && !empty($params['post_type'])) { 
    1795                     $strReq .= 'AND post_type '.$this->con->in($params['post_type']); 
    1796                } else { 
    1797                     $strReq .= "AND post_type = '".$this->con->escape($params['post_type'])."' "; 
    1798                } 
     1818               $strReq .= 'AND post_type '.$this->con->in($params['post_type']); 
    17991819          } 
    18001820           
     
    18721892               $strReq .= $this->con->limit($params['limit']); 
    18731893          } 
     1894 
     1895          if (!empty($params['sql_only'])) { 
     1896               return $strReq; 
     1897          } 
    18741898           
    18751899          $rs = $this->con->select($strReq); 
Note: See TracChangeset for help on using the changeset viewer.

Sites map