Changeset 782:01efbf050a8a for inc/core
- Timestamp:
- 12/06/11 11:43:14 (14 years ago)
- 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. - Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/core/class.dc.blog.php
r778 r782 106 106 } 107 107 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 108 126 /// @name Common public methods 109 127 //@{ … … 755 773 756 774 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'); 758 776 } 759 777 … … 781 799 /* Other filters */ 782 800 if (isset($params['post_status'])) { 783 $strReq .= 'AND post_status = '.(integer) $params['post_status'].' ';801 $strReq .= 'AND '.$this->getInParamStr($params,'post_status','post_status'); 784 802 } 785 803 … … 804 822 805 823 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'); 807 825 } 808 826 … … 1447 1465 { 1448 1466 $field = $field == 'cat_id' ? 'cat_id' : 'cat_url'; 1449 1450 1467 $sub = array(); 1451 1468 $not = array(); … … 1461 1478 if (isset($args['not'])) { $not[$id] = 1; } 1462 1479 if (isset($args['sub'])) { $sub[$id] = 1; } 1480 $nullExcluded = false; 1463 1481 if ($field == 'cat_id') { 1464 1482 if (preg_match('/^null$/i',$id)) { 1465 1483 $queries[$id] = 'P.cat_id IS NULL'; 1484 if (isset($not[$id]) && ($not[$id] == 1)) { 1485 $nullExcluded = true; 1486 } 1466 1487 } 1467 1488 else { … … 1505 1526 1506 1527 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 } 1508 1533 } else { 1509 1534 unset($sql[1]); 1510 1535 } 1511 1512 1536 return implode(' AND ',$sql); 1513 1537 } … … 1808 1832 1809 1833 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 1814 1837 { 1815 1838 $strReq .= 'AND comment_status <> '.(integer) $params['comment_status_not'].' '; … … 1827 1850 $q_author = $this->con->escape(str_replace('*','%',strtolower($params['q_author']))); 1828 1851 $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']).' '; 1829 1855 } 1830 1856 -
inc/core/class.dc.blog.php
r764 r782 4 4 # This file is part of Dotclear 2. 5 5 # 6 # Copyright (c) 2003-201 0Olivier Meunier & Association Dotclear6 # Copyright (c) 2003-2011 Olivier Meunier & Association Dotclear 7 7 # Licensed under the GPL version 2.0 license. 8 8 # See LICENSE file or … … 21 21 class dcBlog 22 22 { 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; 40 55 41 56 private $post_status = array(); … … 44 59 private $categories; 45 60 46 public $without_password = true; ///< <b>boolean</b> Disallow entries password protection 61 /** @var boolean Disallow entries password protection */ 62 public $without_password = true; 47 63 48 64 /** … … 409 425 410 426 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']); 412 428 } 413 429 … … 585 601 586 602 $this->categories()->resetOrder(); 603 $this->triggerBlog(); 587 604 } 588 605 … … 659 676 - order: Order of results (default "ORDER BY post_dt DES") 660 677 - limit: Limit parameter 678 - sql_only : return the sql request instead of results. Only ids are selected 661 679 662 680 Please note that on every cat_id or cat_url, you can add ?not to exclude … … 665 683 @param params <b>array</b> Parameters 666 684 @param count_only <b>boolean</b> Only counts results 667 @param sql_only <b>boolean</b> Only return SQL request668 685 @return <b>record</b> A record with some more capabilities or the SQL request 669 686 */ 670 public function getPosts($params=array(),$count_only=false ,$sql_only=false)687 public function getPosts($params=array(),$count_only=false) 671 688 { 672 689 if ($count_only) 673 690 { 674 691 $strReq = 'SELECT count(P.post_id) '; 692 } 693 elseif (!empty($params['sql_only'])) 694 { 695 $strReq = 'SELECT P.post_id '; 675 696 } 676 697 else … … 729 750 if (isset($params['post_type'])) 730 751 { 731 if (is_array($params['post_type']) && !empty($params['post_type'])) {752 if (is_array($params['post_type']) || $params['post_type'] != '') { 732 753 $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'])."' ";735 754 } 736 755 } … … 844 863 } 845 864 846 if ( $sql_only) {865 if (!empty($params['sql_only'])) { 847 866 return $strReq; 848 867 } … … 876 895 877 896 if($dir > 0) { 878 879 880 881 882 883 884 897 $sign = '>'; 898 $order = 'ASC'; 899 } 900 else { 901 $sign = '<'; 902 $order = 'DESC'; 903 } 885 904 886 905 $params['post_type'] = $post->post_type; … … 1043 1062 $strReq .= "AND post_type = 'post' "; 1044 1063 } 1045 1064 1046 1065 if (!empty($params['year'])) { 1047 1066 $strReq .= 'AND '.$this->con->dateFormat('post_dt','%Y')." = '".sprintf('%04d',$params['year'])."' "; … … 1183 1202 $cur->post_upddt = date('Y-m-d H:i:s'); 1184 1203 1185 # �If user is only "usage", we need to check the post's owner1204 #If user is only "usage", we need to check the post's owner 1186 1205 if (!$this->core->auth->check('contentadmin',$this->id)) 1187 1206 { … … 1731 1750 - order: Order of results (default "ORDER BY comment_dt DES") 1732 1751 - limit: Limit parameter 1752 - sql_only : return the sql request instead of results. Only ids are selected 1733 1753 1734 1754 @param params <b>array</b> Parameters … … 1741 1761 { 1742 1762 $strReq = 'SELECT count(comment_id) '; 1763 } 1764 elseif (!empty($params['sql_only'])) 1765 { 1766 $strReq = 'SELECT P.post_id '; 1743 1767 } 1744 1768 else … … 1792 1816 if (!empty($params['post_type'])) 1793 1817 { 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']); 1799 1819 } 1800 1820 … … 1872 1892 $strReq .= $this->con->limit($params['limit']); 1873 1893 } 1894 1895 if (!empty($params['sql_only'])) { 1896 return $strReq; 1897 } 1874 1898 1875 1899 $rs = $this->con->select($strReq);
Note: See TracChangeset
for help on using the changeset viewer.