Dotclear

Changeset 848:ad18a33a3cef for inc/core


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

sexy step 1 : no more comments ...

Location:
inc/core
Files:
1 deleted
5 edited

Legend:

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

    r836 r848  
    5555      
    5656     private $post_status = array(); 
    57      private $comment_status = array(); 
    5857      
    5958     private $categories; 
     
    9594               $this->post_status['0'] = __('unpublished'); 
    9695               $this->post_status['1'] = __('published'); 
    97                 
    98                $this->comment_status['-2'] = __('junk'); 
    99                $this->comment_status['-1'] = __('pending'); 
    100                $this->comment_status['0'] = __('unpublished'); 
    101                $this->comment_status['1'] = __('published'); 
    102                 
     96                               
    10397               # --BEHAVIOR-- coreBlogConstruct 
    10498               $this->core->callBehavior('coreBlogConstruct',$this); 
     
    145139     } 
    146140      
    147      /** 
    148      Returns an array of available comment status codes and names. 
    149       
    150      @return   <b>array</b> Simple array with codes in keys and names in value 
    151      */ 
    152      public function getAllCommentStatus() 
    153      { 
    154           return $this->comment_status; 
    155      } 
    156141      
    157142     /** 
     
    184169          $this->core->callBehavior('coreBlogAfterTriggerBlog',$cur); 
    185170     } 
    186       
    187      /** 
    188      Updates comment and trackback counters in post table. Should be called 
    189      every time a comment or trackback is added, removed or changed its status. 
    190       
    191      @param    id        <b>integer</b>      Comment ID 
    192      @param    del       <b>boolean</b>      If comment is delete, set this to true 
    193      */ 
    194      public function triggerComment($id,$del=false) 
    195      { 
    196           $id = (integer) $id; 
    197            
    198           $strReq = 'SELECT post_id, comment_trackback '. 
    199                     'FROM '.$this->prefix.'comment '. 
    200                     'WHERE comment_id = '.$id.' '; 
    201            
    202           $rs = $this->con->select($strReq); 
    203            
    204           $post_id = $rs->post_id; 
    205           $tb = (boolean) $rs->comment_trackback; 
    206            
    207           $strReq = 'SELECT COUNT(post_id) '. 
    208                     'FROM '.$this->prefix.'comment '. 
    209                     'WHERE post_id = '.(integer) $post_id.' '. 
    210                     'AND comment_trackback = '.(integer) $tb.' '. 
    211                     'AND comment_status = 1 '; 
    212            
    213           if ($del) { 
    214                $strReq .= 'AND comment_id <> '.$id.' '; 
    215           } 
    216            
    217           $rs = $this->con->select($strReq); 
    218            
    219           $cur = $this->con->openCursor($this->prefix.'post'); 
    220            
    221           if ($rs->isEmpty()) { 
    222                return; 
    223           } 
    224            
    225           if ($tb) { 
    226                $cur->nb_trackback = (integer) $rs->f(0); 
    227           } else { 
    228                $cur->nb_comment = (integer) $rs->f(0); 
    229           } 
    230            
    231           $cur->update('WHERE post_id = '.(integer) $post_id); 
    232      } 
    233      //@} 
    234       
     171           
    235172     /// @name Categories management methods 
    236173     //@{ 
     
    701638               'post_url, post_lang, post_title, '.$content_req. 
    702639               'post_type, post_meta, post_status, post_selected, post_position, '. 
    703                'post_open_comment, post_open_tb, nb_comment, nb_trackback, '. 
    704640               'U.user_name, U.user_firstname, U.user_displayname, U.user_email, '. 
    705641               'U.user_url, '. 
     
    17141650     } 
    17151651     //@} 
    1716       
    1717      /// @name Comments management methods 
    1718      //@{ 
    1719      /** 
    1720      Retrieves comments. <b>$params</b> is an array taking the following 
    1721      optionnal parameters: 
    1722       
    1723      - no_content: Don't retrieve comment content 
    1724      - post_type: Get only entries with given type (default no type, array for many types)  
    1725      - post_id: (integer) Get comments belonging to given post_id 
    1726      - cat_id: (integer or array) Get comments belonging to entries of given category ID 
    1727      - comment_id: (integer) Get comment with given ID 
    1728      - comment_status: (integer) Get comments with given comment_status 
    1729      - comment_trackback: (integer) Get only comments (0) or trackbacks (1) 
    1730      - comment_ip: (string) Get comments with given IP address 
    1731      - post_url: Get entry with given post_url field 
    1732      - user_id: (integer) Get entries belonging to given user ID 
    1733      - q_author: Search comments by author 
    1734      - sql: Append SQL string at the end of the query 
    1735      - from: Append SQL string after "FROM" statement in query 
    1736      - order: Order of results (default "ORDER BY comment_dt DES") 
    1737      - limit: Limit parameter 
    1738      - sql_only : return the sql request instead of results. Only ids are selected 
    1739       
    1740      @param    params         <b>array</b>        Parameters 
    1741      @param    count_only     <b>boolean</b>      Only counts results 
    1742      @return   <b>record</b>  A record with some more capabilities 
    1743      */ 
    1744      public function getComments($params=array(),$count_only=false) 
    1745      { 
    1746           if ($count_only) 
    1747           { 
    1748                $strReq = 'SELECT count(comment_id) '; 
    1749           } 
    1750           elseif (!empty($params['sql_only']))  
    1751           { 
    1752                $strReq = 'SELECT P.post_id '; 
    1753           } 
    1754           else 
    1755           { 
    1756                if (!empty($params['no_content'])) { 
    1757                     $content_req = ''; 
    1758                } else { 
    1759                     $content_req = 'comment_content, '; 
    1760                } 
    1761                 
    1762                if (!empty($params['columns']) && is_array($params['columns'])) { 
    1763                     $content_req .= implode(', ',$params['columns']).', '; 
    1764                } 
    1765                 
    1766                $strReq = 
    1767                'SELECT C.comment_id, comment_dt, comment_tz, comment_upddt, '. 
    1768                'comment_author, comment_email, comment_site, '. 
    1769                $content_req.' comment_trackback, comment_status, '. 
    1770                'comment_spam_status, comment_spam_filter, comment_ip, '. 
    1771                'P.post_title, P.post_url, P.post_id, P.post_password, P.post_type, '. 
    1772                'P.post_dt, P.user_id, U.user_email, U.user_url '; 
    1773           } 
    1774            
    1775           $strReq .= 
    1776           'FROM '.$this->prefix.'comment C '. 
    1777           'INNER JOIN '.$this->prefix.'post P ON C.post_id = P.post_id '. 
    1778           'INNER JOIN '.$this->prefix.'user U ON P.user_id = U.user_id '; 
    1779            
    1780           if (!empty($params['from'])) { 
    1781                $strReq .= $params['from'].' '; 
    1782           } 
    1783            
    1784           $strReq .= 
    1785           "WHERE P.blog_id = '".$this->con->escape($this->id)."' "; 
    1786            
    1787           if (!$this->core->auth->check('contentadmin',$this->id)) { 
    1788                $strReq .= 'AND ((comment_status = 1 AND P.post_status = 1 '; 
    1789                 
    1790                if ($this->without_password) { 
    1791                     $strReq .= 'AND post_password IS NULL '; 
    1792                } 
    1793                $strReq .= ') '; 
    1794                 
    1795                if ($this->core->auth->userID()) { 
    1796                     $strReq .= "OR P.user_id = '".$this->con->escape($this->core->auth->userID())."')"; 
    1797                } else { 
    1798                     $strReq .= ') '; 
    1799                } 
    1800           } 
    1801            
    1802           if (!empty($params['post_type'])) 
    1803           { 
    1804                $strReq .= 'AND post_type '.$this->con->in($params['post_type']); 
    1805           } 
    1806            
    1807           if (isset($params['post_id']) && $params['post_id'] !== '') { 
    1808                $strReq .= 'AND P.post_id = '.(integer) $params['post_id'].' '; 
    1809           } 
    1810            
    1811           if (isset($params['cat_id']) && $params['cat_id'] !== '') { 
    1812                $strReq .= 'AND P.cat_id = '.(integer) $params['cat_id'].' '; 
    1813           } 
    1814            
    1815           if (isset($params['comment_id']) && $params['comment_id'] !== '') { 
    1816                $strReq .= 'AND comment_id = '.(integer) $params['comment_id'].' '; 
    1817           } 
    1818            
    1819           if (isset($params['comment_status'])) { 
    1820                $strReq .= 'AND comment_status = '.(integer) $params['comment_status'].' '; 
    1821           } 
    1822            
    1823           if (!empty($params['comment_status_not'])) 
    1824           { 
    1825                $strReq .= 'AND comment_status <> '.(integer) $params['comment_status_not'].' '; 
    1826           } 
    1827            
    1828           if (isset($params['comment_trackback'])) { 
    1829                $strReq .= 'AND comment_trackback = '.(integer) (boolean) $params['comment_trackback'].' '; 
    1830           } 
    1831            
    1832           if (isset($params['comment_ip'])) { 
    1833                $strReq .= "AND comment_ip = '".$this->con->escape($params['comment_ip'])."' "; 
    1834           } 
    1835            
    1836           if (isset($params['q_author'])) { 
    1837                $q_author = $this->con->escape(str_replace('*','%',strtolower($params['q_author']))); 
    1838                $strReq .= "AND LOWER(comment_author) LIKE '".$q_author."' "; 
    1839           } 
    1840            
    1841           if (!empty($params['search'])) 
    1842           { 
    1843                $words = text::splitWords($params['search']); 
    1844                 
    1845                if (!empty($words)) 
    1846                { 
    1847                     # --BEHAVIOR coreCommentSearch 
    1848                     if ($this->core->hasBehavior('coreCommentSearch')) { 
    1849                          $this->core->callBehavior('coreCommentSearch',$this->core,array(&$words,&$strReq,&$params)); 
    1850                     } 
    1851                      
    1852                     if ($words) 
    1853                     { 
    1854                          foreach ($words as $i => $w) { 
    1855                               $words[$i] = "comment_words LIKE '%".$this->con->escape($w)."%'"; 
    1856                          } 
    1857                          $strReq .= 'AND '.implode(' AND ',$words).' '; 
    1858                     } 
    1859                } 
    1860           } 
    1861            
    1862           if (!empty($params['sql'])) { 
    1863                $strReq .= $params['sql'].' '; 
    1864           } 
    1865            
    1866           if (!$count_only) 
    1867           { 
    1868                if (!empty($params['order'])) { 
    1869                     $strReq .= 'ORDER BY '.$this->con->escape($params['order']).' '; 
    1870                } else { 
    1871                     $strReq .= 'ORDER BY comment_dt DESC '; 
    1872                } 
    1873           } 
    1874            
    1875           if (!$count_only && !empty($params['limit'])) { 
    1876                $strReq .= $this->con->limit($params['limit']); 
    1877           } 
    1878  
    1879           if (!empty($params['sql_only'])) { 
    1880                return $strReq; 
    1881           } 
    1882            
    1883           $rs = $this->con->select($strReq); 
    1884           $rs->core = $this->core; 
    1885           $rs->extend('rsExtComment'); 
    1886            
    1887           # --BEHAVIOR-- coreBlogGetComments 
    1888           $this->core->callBehavior('coreBlogGetComments',$rs); 
    1889            
    1890           return $rs; 
    1891      } 
    1892       
    1893      /** 
    1894      Creates a new comment. Takes a cursor as input and returns the new comment 
    1895      ID. 
    1896       
    1897      @param    cur       <b>cursor</b>       Comment cursor 
    1898      @return   <b>integer</b>      New comment ID 
    1899      */ 
    1900      public function addComment($cur) 
    1901      { 
    1902           $this->con->writeLock($this->prefix.'comment'); 
    1903           try 
    1904           { 
    1905                # Get ID 
    1906                $rs = $this->con->select( 
    1907                     'SELECT MAX(comment_id) '. 
    1908                     'FROM '.$this->prefix.'comment '  
    1909                ); 
    1910                 
    1911                $cur->comment_id = (integer) $rs->f(0) + 1; 
    1912                $cur->comment_upddt = date('Y-m-d H:i:s'); 
    1913                 
    1914                $offset = dt::getTimeOffset($this->settings->system->blog_timezone); 
    1915                $cur->comment_dt = date('Y-m-d H:i:s',time() + $offset); 
    1916                $cur->comment_tz = $this->settings->system->blog_timezone; 
    1917                 
    1918                $this->getCommentCursor($cur); 
    1919                 
    1920                if ($cur->comment_ip === null) { 
    1921                     $cur->comment_ip = http::realIP(); 
    1922                } 
    1923                 
    1924                # --BEHAVIOR-- coreBeforeCommentCreate 
    1925                $this->core->callBehavior('coreBeforeCommentCreate',$this,$cur); 
    1926                 
    1927                $cur->insert(); 
    1928                $this->con->unlock(); 
    1929           } 
    1930           catch (Exception $e) 
    1931           { 
    1932                $this->con->unlock(); 
    1933                throw $e; 
    1934           } 
    1935            
    1936           # --BEHAVIOR-- coreAfterCommentCreate 
    1937           $this->core->callBehavior('coreAfterCommentCreate',$this,$cur); 
    1938            
    1939           $this->triggerComment($cur->comment_id); 
    1940           if ($cur->comment_status != -2) { 
    1941                $this->triggerBlog(); 
    1942           }     
    1943           return $cur->comment_id; 
    1944      } 
    1945       
    1946      /** 
    1947      Updates an existing comment. 
    1948       
    1949      @param    id        <b>integer</b>      Comment ID 
    1950      @param    cur       <b>cursor</b>       Comment cursor 
    1951      */ 
    1952      public function updComment($id,$cur) 
    1953      { 
    1954           if (!$this->core->auth->check('usage,contentadmin',$this->id)) { 
    1955                throw new Exception(__('You are not allowed to update comments')); 
    1956           } 
    1957            
    1958           $id = (integer) $id; 
    1959            
    1960           if (empty($id)) { 
    1961                throw new Exception(__('No such comment ID')); 
    1962           } 
    1963            
    1964           $rs = $this->getComments(array('comment_id' => $id)); 
    1965            
    1966           if ($rs->isEmpty()) { 
    1967                throw new Exception(__('No such comment ID')); 
    1968           } 
    1969            
    1970           #If user is only usage, we need to check the post's owner 
    1971           if (!$this->core->auth->check('contentadmin',$this->id)) 
    1972           { 
    1973                if ($rs->user_id != $this->core->auth->userID()) { 
    1974                     throw new Exception(__('You are not allowed to update this comment')); 
    1975                } 
    1976           } 
    1977            
    1978           $this->getCommentCursor($cur); 
    1979            
    1980           $cur->comment_upddt = date('Y-m-d H:i:s'); 
    1981            
    1982           if (!$this->core->auth->check('publish,contentadmin',$this->id)) { 
    1983                $cur->unsetField('comment_status'); 
    1984           } 
    1985            
    1986           # --BEHAVIOR-- coreBeforeCommentUpdate 
    1987           $this->core->callBehavior('coreBeforeCommentUpdate',$this,$cur,$rs); 
    1988            
    1989           $cur->update('WHERE comment_id = '.$id.' '); 
    1990            
    1991           # --BEHAVIOR-- coreAfterCommentUpdate 
    1992           $this->core->callBehavior('coreAfterCommentUpdate',$this,$cur,$rs); 
    1993            
    1994           $this->triggerComment($id); 
    1995           $this->triggerBlog(); 
    1996      } 
    1997       
    1998      /** 
    1999      Updates comment status. 
    2000       
    2001      @param    id        <b>integer</b>      Comment ID 
    2002      @param    status    <b>integer</b>      Comment status 
    2003      */ 
    2004      public function updCommentStatus($id,$status) 
    2005      { 
    2006           if (!$this->core->auth->check('publish,contentadmin',$this->id)) { 
    2007                throw new Exception(__("You are not allowed to change this comment's status")); 
    2008           } 
    2009            
    2010           $cur = $this->con->openCursor($this->prefix.'comment'); 
    2011           $cur->comment_status = (integer) $status; 
    2012           $this->updComment($id,$cur); 
    2013      } 
    2014       
    2015      /** 
    2016      Delete a comment 
    2017       
    2018      @param    id        <b>integer</b>      Comment ID 
    2019      */ 
    2020      public function delComment($id) 
    2021      { 
    2022           if (!$this->core->auth->check('delete,contentadmin',$this->id)) { 
    2023                throw new Exception(__('You are not allowed to delete comments')); 
    2024           } 
    2025            
    2026           $id = (integer) $id; 
    2027            
    2028           if (empty($id)) { 
    2029                throw new Exception(__('No such comment ID')); 
    2030           } 
    2031            
    2032           #If user can only delete, we need to check the post's owner 
    2033           if (!$this->core->auth->check('contentadmin',$this->id)) 
    2034           { 
    2035                $strReq = 'SELECT P.post_id '. 
    2036                          'FROM '.$this->prefix.'post P, '.$this->prefix.'comment C '. 
    2037                          'WHERE P.post_id = C.post_id '. 
    2038                          "AND P.blog_id = '".$this->con->escape($this->id)."' ". 
    2039                          'AND comment_id = '.$id.' '. 
    2040                          "AND user_id = '".$this->con->escape($this->core->auth->userID())."' "; 
    2041                 
    2042                $rs = $this->con->select($strReq); 
    2043                 
    2044                if ($rs->isEmpty()) { 
    2045                     throw new Exception(__('You are not allowed to delete this comment')); 
    2046                } 
    2047           } 
    2048            
    2049           $strReq = 'DELETE FROM '.$this->prefix.'comment '. 
    2050                     'WHERE comment_id = '.$id.' '; 
    2051            
    2052           $this->triggerComment($id,true); 
    2053           $this->con->execute($strReq); 
    2054           $this->triggerBlog(); 
    2055      } 
    2056       
    2057      private function getCommentCursor($cur) 
    2058      { 
    2059           if ($cur->comment_content !== null && $cur->comment_content == '') { 
    2060                throw new Exception(__('You must provide a comment')); 
    2061           } 
    2062            
    2063           if ($cur->comment_author !== null && $cur->comment_author == '') { 
    2064                throw new Exception(__('You must provide an author name')); 
    2065           } 
    2066            
    2067           if ($cur->comment_email != '' && !text::isEmail($cur->comment_email)) { 
    2068                throw new Exception(__('Email address is not valid.')); 
    2069           } 
    2070            
    2071           if ($cur->comment_site !== null && $cur->comment_site != '') { 
    2072                if (!preg_match('|^http(s?)://|',$cur->comment_site)) { 
    2073                     $cur->comment_site = 'http://'.$cur->comment_site; 
    2074                } 
    2075           } 
    2076            
    2077           if ($cur->comment_status === null) { 
    2078                $cur->comment_status = (integer) $this->settings->system->comments_pub; 
    2079           } 
    2080            
    2081           # Words list 
    2082           if ($cur->comment_content !== null) 
    2083           { 
    2084                $cur->comment_words = implode(' ',text::splitWords($cur->comment_content)); 
    2085           } 
    2086      } 
    2087      //@} 
    20881652} 
    20891653?> 
  • inc/core/class.dc.core.php

    r706 r848  
    11411141     } 
    11421142      
    1143      /** 
    1144      Inits <var>wiki2xhtml</var> property for simple blog comment (basic syntax). 
    1145      */ 
    1146      public function initWikiSimpleComment() 
    1147      { 
    1148           $this->initWiki(); 
    1149            
    1150           $this->wiki2xhtml->setOpts(array( 
    1151                'active_title' => 0, 
    1152                'active_setext_title' => 0, 
    1153                'active_hr' => 0, 
    1154                'active_lists' => 0, 
    1155                'active_quote' => 0, 
    1156                'active_pre' => 0, 
    1157                'active_empty' => 0, 
    1158                'active_auto_br' => 1, 
    1159                'active_auto_urls' => 1, 
    1160                'active_urls' => 0, 
    1161                'active_auto_img' => 0, 
    1162                'active_img' => 0, 
    1163                'active_anchor' => 0, 
    1164                'active_em' => 0, 
    1165                'active_strong' => 0, 
    1166                'active_br' => 0, 
    1167                'active_q' => 0, 
    1168                'active_code' => 0, 
    1169                'active_acronym' => 0, 
    1170                'active_ins' => 0, 
    1171                'active_del' => 0, 
    1172                'active_footnotes' => 0, 
    1173                'active_wikiwords' => 0, 
    1174                'active_macros' => 0, 
    1175                'parse_pre' => 0, 
    1176                'active_fr_syntax' => 0 
    1177           )); 
    1178            
    1179           # --BEHAVIOR-- coreInitWikiSimpleComment 
    1180           $this->callBehavior('coreInitWikiSimpleComment',$this->wiki2xhtml); 
    1181      } 
    1182       
    1183      /** 
    1184      Inits <var>wiki2xhtml</var> property for blog comment. 
    1185      */ 
    1186      public function initWikiComment() 
    1187      { 
    1188           $this->initWiki(); 
    1189            
    1190           $this->wiki2xhtml->setOpts(array( 
    1191                'active_title' => 0, 
    1192                'active_setext_title' => 0, 
    1193                'active_hr' => 0, 
    1194                'active_lists' => 1, 
    1195                'active_quote' => 0, 
    1196                'active_pre' => 1, 
    1197                'active_empty' => 0, 
    1198                'active_auto_br' => 1, 
    1199                'active_auto_urls' => 1, 
    1200                'active_urls' => 1, 
    1201                'active_auto_img' => 0, 
    1202                'active_img' => 0, 
    1203                'active_anchor' => 0, 
    1204                'active_em' => 1, 
    1205                'active_strong' => 1, 
    1206                'active_br' => 1, 
    1207                'active_q' => 1, 
    1208                'active_code' => 1, 
    1209                'active_acronym' => 1, 
    1210                'active_ins' => 1, 
    1211                'active_del' => 1, 
    1212                'active_footnotes' => 0, 
    1213                'active_wikiwords' => 0, 
    1214                'active_macros' => 0, 
    1215                'parse_pre' => 0, 
    1216                'active_fr_syntax' => 0 
    1217           )); 
    1218            
    1219           # --BEHAVIOR-- coreInitWikiComment 
    1220           $this->callBehavior('coreInitWikiComment',$this->wiki2xhtml); 
    1221      } 
    1222       
    12231143     public function wikiPostLink($url,$content) 
    12241144     { 
     
    12691189          { 
    12701190               $defaults = array( 
    1271                     array('allow_comments','boolean',true, 
    1272                     'Allow comments on blog'), 
    1273                     array('allow_trackbacks','boolean',true, 
    1274                     'Allow trackbacks on blog'), 
    12751191                    array('blog_timezone','string','Europe/London', 
    12761192                    'Blog timezone'), 
    1277                     array('comments_nofollow','boolean',true, 
    1278                     'Add rel="nofollow" to comments URLs'), 
    1279                     array('comments_pub','boolean',true, 
    1280                     'Publish comments immediately'), 
    1281                     array('comments_ttl','integer',0, 
    1282                     'Number of days to keep comments open (0 means no ttl)'), 
    12831193                    array('copyright_notice','string','','Copyright notice (simple text)'), 
    12841194                    array('date_format','string','%A, %B %e %Y', 
     
    13061216                    array('nb_post_per_feed','integer',20, 
    13071217                    'Number of entries on feeds'), 
    1308                     array('nb_comment_per_feed','integer',20, 
    1309                     'Number of comments on feeds'), 
    13101218                    array('post_url_format','string','{y}/{m}/{d}/{t}', 
    13111219                    'Post URL format. {y}: year, {m}: month, {d}: day, {id}: post id, {t}: entry title'), 
     
    13301238                    array('tpl_use_cache','boolean',true, 
    13311239                    'Use template caching'), 
    1332                     array('trackbacks_pub','boolean',true, 
    1333                     'Publish trackbacks immediately'), 
    1334                     array('trackbacks_ttl','integer',0, 
    1335                     'Number of days to keep trackbacks open (0 means no ttl)'), 
    13361240                    array('url_scan','string','query_string', 
    13371241                    'URL handle mode (path_info or query_string)'), 
    13381242                    array('use_smilies','boolean',false, 
    13391243                    'Show smilies on entries and comments'), 
    1340                     array('wiki_comments','boolean',false, 
    1341                     'Allow commenters to use a subset of wiki syntax') 
    13421244               ); 
    13431245          } 
     
    13941296      
    13951297     /** 
    1396      Recreates comments search engine index. 
    1397       
    1398      @param    start     <b>integer</b>      Start comment index 
    1399      @param    limit     <b>integer</b>      Number of comments to index 
    1400       
    1401      @return   <b>integer</b>      <var>$start</var> and <var>$limit</var> sum 
    1402      */ 
    1403      public function indexAllComments($start=null,$limit=null) 
    1404      { 
    1405           $strReq = 'SELECT COUNT(comment_id) '. 
    1406                     'FROM '.$this->prefix.'comment'; 
    1407           $rs = $this->con->select($strReq); 
    1408           $count = $rs->f(0); 
    1409            
    1410           $strReq = 'SELECT comment_id, comment_content '. 
    1411                     'FROM '.$this->prefix.'comment '; 
    1412            
    1413           if ($start !== null && $limit !== null) { 
    1414                $strReq .= $this->con->limit($start,$limit); 
    1415           } 
    1416            
    1417           $rs = $this->con->select($strReq); 
    1418            
    1419           $cur = $this->con->openCursor($this->prefix.'comment'); 
    1420            
    1421           while ($rs->fetch()) 
    1422           { 
    1423                $cur->comment_words = implode(' ',text::splitWords($rs->comment_content)); 
    1424                $cur->update('WHERE comment_id = '.(integer) $rs->comment_id); 
    1425                $cur->clean(); 
    1426           } 
    1427            
    1428           if ($start+$limit > $count) { 
    1429                return null; 
    1430           } 
    1431           return $start+$limit; 
    1432      } 
    1433       
    1434      /** 
    1435      Reinits nb_comment and nb_trackback in post table. 
    1436      */ 
    1437      public function countAllComments() 
    1438      { 
    1439       
    1440           $updCommentReq = 'UPDATE '.$this->prefix.'post P '. 
    1441                'SET nb_comment = ('. 
    1442                     'SELECT COUNT(C.comment_id) from '.$this->prefix.'comment C '. 
    1443                     'WHERE C.post_id = P.post_id AND C.comment_trackback <> 1 '. 
    1444                     'AND C.comment_status = 1 '. 
    1445                ')'; 
    1446           $updTrackbackReq = 'UPDATE '.$this->prefix.'post P '. 
    1447                'SET nb_trackback = ('. 
    1448                     'SELECT COUNT(C.comment_id) from '.$this->prefix.'comment C '. 
    1449                     'WHERE C.post_id = P.post_id AND C.comment_trackback = 1 '. 
    1450                     'AND C.comment_status = 1 '. 
    1451                ')'; 
    1452           $this->con->execute($updCommentReq); 
    1453           $this->con->execute($updTrackbackReq); 
    1454      } 
    1455       
    1456      /** 
    14571298     Empty templates cache directory 
    14581299     */ 
  • inc/core/class.dc.meta.php

    r270 r848  
    247247      
    248248     /** 
    249      Retrieves comments to posts corresponding to given meta criteria. 
    250      <b>$params</b> is an array taking the following optional parameters: 
    251      - meta_id : get comments to posts having meta id  
    252      - meta_type : get comments to posts having meta type 
    253       
    254      @param    params    <b>array</b>   Parameters 
    255      @param    count_only     <b>boolean</b>      Only counts results 
    256       
    257      @return   <b>record</b>  the resulting comments record 
    258      */ 
    259      public function getCommentsByMeta($params=array(),$count_only=false) 
    260      { 
    261           if (!isset($params['meta_id'])) { 
    262                return null; 
    263           } 
    264            
    265           $params['from'] = ', '.$this->table.' META '; 
    266           $params['sql'] = 'AND META.post_id = P.post_id '; 
    267           $params['sql'] .= "AND META.meta_id = '".$this->con->escape($params['meta_id'])."' "; 
    268            
    269           if (!empty($params['meta_type'])) { 
    270                $params['sql'] .= "AND META.meta_type = '".$this->con->escape($params['meta_type'])."' "; 
    271                unset($params['meta_type']); 
    272           } 
    273            
    274           return $this->core->blog->getComments($params,$count_only); 
    275      } 
    276       
    277      /** 
    278249     @deprecated since 2.2. Use getMetadata and computeMetaStats instead. 
    279250     Generic-purpose metadata retrieval : gets metadatas according to given 
  • inc/core/class.dc.rs.extensions.php

    r776 r848  
    117117      
    118118     /** 
    119      Returns whether comments are enabled on post. 
    120       
    121      @param    rs   Invisible parameter 
    122      @return   <b>boolean</b> 
    123      */ 
    124      public static function commentsActive($rs) 
    125      { 
    126           return 
    127           $rs->core->blog->settings->system->allow_comments 
    128           && $rs->post_open_comment 
    129           && ($rs->core->blog->settings->system->comments_ttl == 0 || 
    130           time()-($rs->core->blog->settings->system->comments_ttl*86400) < $rs->getTS()); 
    131      } 
    132       
    133      /** 
    134      Returns whether trackbacks are enabled on post. 
    135       
    136      @param    rs   Invisible parameter 
    137      @return   <b>boolean</b> 
    138      */ 
    139      public static function trackbacksActive($rs) 
    140      { 
    141           return 
    142           $rs->core->blog->settings->system->allow_trackbacks 
    143           && $rs->post_open_tb 
    144           && ($rs->core->blog->settings->system->trackbacks_ttl == 0 || 
    145           time()-($rs->core->blog->settings->system->trackbacks_ttl*86400) < $rs->getTS()); 
    146      } 
    147       
    148      /** 
    149      Returns whether post has at least one comment. 
    150       
    151      @param    rs   Invisible parameter 
    152      @return   <b>boolean</b> 
    153      */ 
    154      public static function hasComments($rs) 
    155      { 
    156           return $rs->nb_comment > 0; 
    157      } 
    158       
    159      /** 
    160      Returns whether post has at least one trackbacks. 
    161       
    162      @return   <b>boolean</b> 
    163      */ 
    164      public static function hasTrackbacks($rs) 
    165      { 
    166           return $rs->nb_trackback > 0; 
    167      } 
    168       
    169      /** 
    170119     Returns full post URL. 
    171120      
     
    361310           
    362311          return 'tag:'.$url['host'].','.$date_part.':'.$rs->post_id; 
    363      } 
    364       
    365      /** 
    366      Returns trackback RDF information block in HTML comment. 
    367       
    368      @param    rs   Invisible parameter 
    369      @return   <b>string</b> 
    370      */ 
    371      public static function getTrackbackData($rs) 
    372      { 
    373           return 
    374           "<![CDATA[>\n". 
    375           "<!--[\n". 
    376           '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"'."\n". 
    377           '  xmlns:dc="http://purl.org/dc/elements/1.1/"'."\n". 
    378           '  xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">'."\n". 
    379           "<rdf:Description\n". 
    380           '  rdf:about="'.$rs->getURL().'"'."\n". 
    381           '  dc:identifier="'.$rs->getURL().'"'."\n". 
    382           '  dc:title="'.htmlspecialchars($rs->post_title,ENT_COMPAT,'UTF-8').'"'."\n". 
    383           '  trackback:ping="'.$rs->getTrackbackLink().'" />'."\n". 
    384           "</rdf:RDF>\n". 
    385           "<!]]><!---->\n"; 
    386      } 
    387       
    388      /** 
    389      Returns post trackback full URL. 
    390       
    391      @param    rs   Invisible parameter 
    392      @return   <b>string</b> 
    393      */ 
    394      public static function getTrackbackLink($rs) 
    395      { 
    396           return $rs->core->blog->url.$rs->core->url->getURLFor('trackback',$rs->post_id); 
    397312     } 
    398313      
     
    459374/** 
    460375@ingroup DC_CORE 
    461 @brief Dotclear comment record helpers. 
    462  
    463 This class adds new methods to database comment results. 
    464 You can call them on every record comming from dcBlog::getComments and similar 
    465 methods. 
    466  
    467 @warning You should not give the first argument (usualy $rs) of every described 
    468 function. 
    469 */ 
    470 class rsExtComment 
    471 { 
    472      /** 
    473      Returns comment date with <var>$format</var> as formatting pattern. If 
    474      format is empty, uses <var>date_format</var> blog setting. 
    475       
    476      @param    rs   Invisible parameter 
    477      @param    format    <b>string</b>       Date format pattern 
    478      @param    type <b>string</b>       (dt|upddt) defaults to comment_dt 
    479      @return   <b>string</b> 
    480      */ 
    481      public static function getDate($rs,$format,$type='') 
    482      { 
    483           if (!$format) { 
    484                $format = $rs->core->blog->settings->system->date_format; 
    485           } 
    486            
    487           if ($type == 'upddt') { 
    488                return dt::dt2str($format,$rs->comment_upddt,$rs->comment_tz); 
    489           } else { 
    490                return dt::dt2str($format,$rs->comment_dt); 
    491           } 
    492      } 
    493       
    494      /** 
    495      Returns comment time with <var>$format</var> as formatting pattern. If 
    496      format is empty, uses <var>time_format</var> blog setting. 
    497       
    498      @param    rs   Invisible parameter 
    499      @param    format    <b>string</b>       Date format pattern 
    500      @param    type <b>string</b>       (dt|upddt) defaults to comment_dt 
    501      @return   <b>string</b> 
    502      */ 
    503      public static function getTime($rs,$format,$type='') 
    504      { 
    505           if (!$format) { 
    506                $format = $rs->core->blog->settings->system->time_format; 
    507           } 
    508            
    509           if ($type == 'upddt') { 
    510                return dt::dt2str($format,$rs->comment_updt,$rs->comment_tz); 
    511           } else { 
    512                return dt::dt2str($format,$rs->comment_dt); 
    513           } 
    514      } 
    515       
    516      /** 
    517      Returns comment timestamp. 
    518       
    519      @param    rs   Invisible parameter 
    520      @param    type <b>string</b>       (dt|upddt) defaults to comment_dt 
    521      @return   <b>integer</b> 
    522      */ 
    523      public static function getTS($rs,$type='') 
    524      { 
    525           if ($type == 'upddt') { 
    526                return strtotime($rs->comment_upddt); 
    527           } else { 
    528                return strtotime($rs->comment_dt); 
    529           } 
    530      } 
    531       
    532      /** 
    533      Returns comment date formating according to the ISO 8601 standard. 
    534       
    535      @param    rs   Invisible parameter 
    536      @param    type <b>string</b>       (dt|upddt) defaults to comment_dt 
    537      @return   <b>string</b> 
    538      */ 
    539      public static function getISO8601Date($rs,$type='') 
    540      { 
    541           if ($type == 'upddt') { 
    542                return dt::iso8601($rs->getTS($type)+dt::getTimeOffset($rs->comment_tz),$rs->comment_tz); 
    543           } else { 
    544                return dt::iso8601($rs->getTS(),$rs->comment_tz); 
    545           } 
    546      } 
    547       
    548      /** 
    549      Returns comment date formating according to RFC 822. 
    550       
    551      @param    rs   Invisible parameter 
    552      @param    type <b>string</b>       (dt|upddt) defaults to comment_dt 
    553      @return   <b>string</b> 
    554      */ 
    555      public static function getRFC822Date($rs,$type='') 
    556      { 
    557           if ($type == 'upddt') { 
    558                return dt::rfc822($rs->getTS($type)+dt::getTimeOffset($rs->comment_tz),$rs->comment_tz); 
    559           } else { 
    560                return dt::rfc822($rs->getTS(),$rs->comment_tz); 
    561           } 
    562      } 
    563       
    564      /** 
    565      Returns comment content. If <var>$absolute_urls</var> is true, appends full 
    566      blog URL to each relative post URLs. 
    567       
    568      @param    rs   Invisible parameter 
    569      @param    absolute_urls  <b>boolean</b>      With absolute URLs 
    570      @return   <b>string</b> 
    571      */ 
    572      public static function getContent($rs,$absolute_urls=false) 
    573      { 
    574           $res = $rs->comment_content; 
    575            
    576           if ($rs->core->blog->settings->system->comments_nofollow) { 
    577                $res = preg_replace_callback('#<a(.*?href=".*?".*?)>#ms',array('self','noFollowURL'),$res); 
    578           } 
    579            
    580           if ($absolute_urls) { 
    581                $res = html::absoluteURLs($res,$rs->getPostURL()); 
    582           } 
    583            
    584           return $res; 
    585      } 
    586       
    587      private static function noFollowURL($m) 
    588      { 
    589           if (preg_match('/rel="nofollow"/',$m[1])) { 
    590                return $m[0]; 
    591           } 
    592            
    593           return '<a'.$m[1].' rel="nofollow">'; 
    594      } 
    595       
    596      /** 
    597      Returns comment author link to his website if he specified one. 
    598       
    599      @param    rs   Invisible parameter 
    600      @return   <b>string</b> 
    601      */ 
    602      public static function getAuthorURL($rs) 
    603      { 
    604           if (trim($rs->comment_site)) { 
    605                return trim($rs->comment_site); 
    606           } 
    607      } 
    608       
    609      /** 
    610      Returns comment post full URL. 
    611       
    612      @param    rs   Invisible parameter 
    613      @return   <b>string</b> 
    614      */ 
    615      public static function getPostURL($rs) 
    616      { 
    617           return $rs->core->blog->url.$rs->core->getPostPublicURL( 
    618                     $rs->post_type,html::sanitizeURL($rs->post_url) 
    619                ); 
    620      } 
    621       
    622      /** 
    623      Returns comment author name in a link to his website if he specified one. 
    624       
    625      @param    rs   Invisible parameter 
    626      @return   <b>string</b> 
    627      */ 
    628      public static function getAuthorLink($rs) 
    629      { 
    630           $res = '%1$s'; 
    631           $url = $rs->getAuthorURL(); 
    632           if ($url) { 
    633                $res = '<a href="%2$s"%3$s>%1$s</a>'; 
    634           } 
    635            
    636           $nofollow = ''; 
    637           if ($rs->core->blog->settings->system->comments_nofollow) { 
    638                $nofollow = ' rel="nofollow"'; 
    639           } 
    640            
    641           return sprintf($res,html::escapeHTML($rs->comment_author),html::escapeHTML($url),$nofollow); 
    642      } 
    643       
    644      /** 
    645      Returns comment author e-mail address. If <var>$encoded</var> is true, 
    646      "@" sign is replaced by "%40" and "." by "%2e". 
    647       
    648      @param    rs   Invisible parameter 
    649      @param    encoded   <b>boolean</b>      Encode address. 
    650      @return   <b>string</b> 
    651      */ 
    652      public static function getEmail($rs,$encoded=true) 
    653      { 
    654           if ($encoded) { 
    655                return strtr($rs->comment_email,array('@'=>'%40','.'=>'%2e')); 
    656           } 
    657           return $rs->comment_email; 
    658      } 
    659       
    660      /** 
    661      Returns trackback site title if comment is a trackback. 
    662       
    663      @param    rs   Invisible parameter 
    664      @return   <b>string</b> 
    665      */ 
    666      public static function getTrackbackTitle($rs) 
    667      { 
    668           if ($rs->comment_trackback == 1 && 
    669           preg_match('|<p><strong>(.*?)</strong></p>|msU',$rs->comment_content, 
    670           $match)) { 
    671                return html::decodeEntities($match[1]); 
    672           } 
    673      } 
    674       
    675      /** 
    676      Returns trackback content if comment is a trackback. 
    677       
    678      @param    rs   Invisible parameter 
    679      @return   <b>string</b> 
    680      */ 
    681      public static function getTrackbackContent($rs) 
    682      { 
    683           if ($rs->comment_trackback == 1) { 
    684                return preg_replace('|<p><strong>.*?</strong></p>|msU','', 
    685                $rs->comment_content); 
    686           } 
    687      } 
    688       
    689      /** 
    690      Returns comment feed unique ID. 
    691       
    692      @param    rs   Invisible parameter 
    693      @return   <b>string</b> 
    694      */ 
    695      public static function getFeedID($rs) 
    696      { 
    697           return 'urn:md5:'.md5($rs->core->blog->uid.$rs->comment_id); 
    698            
    699           $url = parse_url($rs->core->blog->url); 
    700           $date_part = date('Y-m-d',strtotime($rs->comment_dt)); 
    701            
    702           return 'tag:'.$url['host'].','.$date_part.':'.$rs->comment_id; 
    703      } 
    704       
    705      /** 
    706      Returns whether comment is from the post author. 
    707       
    708      @param    rs   Invisible parameter 
    709      @return   <b>boolean</b> 
    710      */ 
    711      public static function isMe($rs) 
    712      { 
    713           return 
    714           $rs->comment_email && $rs->comment_site && 
    715           $rs->comment_email == $rs->user_email && 
    716           $rs->comment_site == $rs->user_url; 
    717      } 
    718 } 
    719  
    720 /** 
    721 @ingroup DC_CORE 
    722376@brief Dotclear dates record helpers. 
    723377 
  • inc/core/class.dc.xmlrpc.php

    r776 r848  
    187187               'Update blog options'); 
    188188           
    189           $this->addCallback('wp.getComment',array($this,'wp_getComment'), 
    190                array('struct','integer','string','string','integer'), 
    191                "Gets a comment, given it's comment ID."); 
    192            
    193           $this->addCallback('wp.getCommentCount',array($this,'wp_getCommentCount'), 
    194                array('array','integer','string','string','integer'), 
    195                'Retrieve comment count.'); 
    196            
    197           $this->addCallback('wp.getComments',array($this,'wp_getComments'), 
    198                array('array','integer','string','string','struct'), 
    199                'Gets a set of comments for a given post.'); 
    200            
    201           $this->addCallback('wp.deleteComment',array($this,'wp_deleteComment'), 
    202                array('boolean','integer','string','string','integer'), 
    203                'Delete a comment with given ID.'); 
    204            
    205           $this->addCallback('wp.editComment',array($this,'wp_editComment'), 
    206                array('boolean','integer','string','string','integer','struct'), 
    207                'Edit a comment with given ID.'); 
    208            
    209           $this->addCallback('wp.newComment',array($this,'wp_newComment'), 
    210                array('integer','integer','string','string','integer','struct'), 
    211                'Create a new comment for a given post ID.'); 
    212            
    213           $this->addCallback('wp.getCommentStatusList',array($this,'wp_getCommentStatusList'), 
    214                array('array','integer','string','string'), 
    215                'Retrieve all of the comment statuses.'); 
    216189     } 
    217190      
     
    335308          $description = !empty($struct['description']) ? $struct['description'] : null; 
    336309          $dateCreated = !empty($struct['dateCreated']) ? $struct['dateCreated'] : null; 
    337           $open_comment = isset($struct['mt_allow_comments']) ? $struct['mt_allow_comments'] : 1; 
    338           $open_tb = isset($struct['mt_allow_pings']) ? $struct['mt_allow_pings'] : 1; 
    339310           
    340311          if ($description !== null) { 
     
    362333          $cur->post_content_xhtml = $content_xhtml; 
    363334          $cur->post_excerpt_xhtml = $excerpt_xhtml; 
    364           $cur->post_open_comment = (integer) ($open_comment == 1); 
    365           $cur->post_open_tb = (integer) ($open_tb == 1); 
    366335          $cur->post_status = (integer) $publish; 
    367336          $cur->post_format = 'xhtml'; 
     
    440409          $description = (!empty($struct['description'])) ? $struct['description'] : null; 
    441410          $dateCreated = !empty($struct['dateCreated']) ? $struct['dateCreated'] : null; 
    442           $open_comment = (isset($struct['mt_allow_comments'])) ? $struct['mt_allow_comments'] : 1; 
    443           $open_tb = (isset($struct['mt_allow_pings'])) ? $struct['mt_allow_pings'] : 1; 
    444411           
    445412          if ($description !== null) { 
     
    466433          $cur->post_content_xhtml = $content_xhtml; 
    467434          $cur->post_excerpt_xhtml = $excerpt_xhtml; 
    468           $cur->post_open_comment = (integer) ($open_comment == 1); 
    469           $cur->post_open_tb = (integer) ($open_tb == 1); 
    470435          $cur->post_status = (integer) $publish; 
    471436          $cur->post_format = 'xhtml'; 
     
    557522               $res['mt_excerpt'] = $post->post_excerpt_xhtml; 
    558523               $res['mt_text_more'] = ''; 
    559                $res['mt_allow_comments'] = (integer) $post->post_open_comment; 
    560                $res['mt_allow_pings'] = (integer) $post->post_open_tb; 
    561524               $res['mt_convert_breaks'] = ''; 
    562525               $res['mt_keywords'] = ''; 
     
    621584                    $tres['mt_excerpt'] = $posts->post_excerpt_xhtml; 
    622585                    $tres['mt_text_more'] = ''; 
    623                     $tres['mt_allow_comments'] = (integer) $posts->post_open_comment; 
    624                     $tres['mt_allow_pings'] = (integer) $posts->post_open_tb; 
    625586                    $tres['mt_convert_breaks'] = ''; 
    626587                    $tres['mt_keywords'] = ''; 
     
    832793     } 
    833794      
    834      private function translateWpCommentstatus($s) 
    835      { 
    836           $status = array( 
    837                'hold' => -1, 
    838                'approve' => 0, 
    839                'spam' => -2 
    840           ); 
    841            
    842           if (is_int($s)) { 
    843                $status = array_flip($status); 
    844                return isset($status[$s]) ? $status[$s] : $status[0]; 
    845           } else { 
    846                return isset($status[$s]) ? $status[$s] : $status['approve']; 
    847           } 
    848      } 
    849795      
    850796     private function translateWpOptions($options=array()) 
     
    986932                    "excerpt"                => $posts->post_excerpt_xhtml, 
    987933                    "text_more"              => '', 
    988                     "mt_allow_comments"      => (integer) $posts->post_open_comment, 
    989                     "mt_allow_pings"         => (integer) $posts->post_open_tb, 
    990934                    "wp_slug"                => $posts->post_url, 
    991935                    "wp_password"            => $posts->post_password, 
     
    11591103          } 
    11601104          return $res; 
    1161      } 
    1162       
    1163      private function countComments($user,$pwd,$post_id) 
    1164      { 
    1165           $this->setUser($user,$pwd); 
    1166           $this->setBlog(); 
    1167            
    1168           $res = array( 
    1169                'approved' => 0, 
    1170                'awaiting_moderation' => 0, 
    1171                'spam' => 0, 
    1172                'total' => 0 
    1173           ); 
    1174           $rs = $this->core->blog->getComments(array('post_id' => $post_id)); 
    1175            
    1176           while ($rs->fetch()) { 
    1177                $res['total']++; 
    1178                if ($rs->comment_status == 1) { 
    1179                     $res['approved']++; 
    1180                } elseif ($rs->comment_status == -2) { 
    1181                     $res['spam']++; 
    1182                } else { 
    1183                     $res['awaiting_moderation']++; 
    1184                } 
    1185           } 
    1186           return $res; 
    1187      } 
    1188       
    1189      private function getComments($user,$pwd,$struct,$id=null) 
    1190      { 
    1191           $this->setUser($user,$pwd); 
    1192           $this->setBlog(); 
    1193            
    1194           $params = array(); 
    1195            
    1196           if (!empty($struct['status'])) { 
    1197                $params['comment_status'] = $this->translateWpCommentstatus($struct['status']); 
    1198           } 
    1199            
    1200           if (!empty($struct['post_id'])) { 
    1201                $params['post_id'] = (integer) $struct['post_id']; 
    1202           } 
    1203            
    1204           if (isset($id)) { 
    1205                $params['comment_id'] = $id; 
    1206           } 
    1207            
    1208           $offset = !empty($struct['offset']) ? (integer) $struct['offset'] : 0; 
    1209           $limit = !empty($struct['number']) ? (integer) $struct['number'] : 10; 
    1210           $params['limit'] = array($offset,$limit); 
    1211            
    1212           $rs = $this->core->blog->getComments($params); 
    1213           $res = array(); 
    1214           while ($rs->fetch()) 
    1215           { 
    1216                $res[] = array( 
    1217                     'date_created_gmt'       => new xmlrpcDate($rs->getTS()), 
    1218                     'user_id'                => $rs->user_id, 
    1219                     'comment_id'             => $rs->comment_id, 
    1220                     'parent'                 => 0, 
    1221                     'status'                 => $this->translateWpCommentstatus((integer) $rs->comment_status), 
    1222                     'content'                => $rs->comment_content, 
    1223                     'link'                   => $rs->getPostURL().'#c'.$rs->comment_id, 
    1224                     'post_id'                => $rs->post_id, 
    1225                     'post_title'             => $rs->post_title, 
    1226                     'author'                 => $rs->comment_author, 
    1227                     'author_url'             => $rs->comment_site, 
    1228                     'author_email'           => $rs->comment_email, 
    1229                     'author_ip'              => $rs->comment_ip 
    1230                ); 
    1231           } 
    1232           return $res; 
    1233      } 
    1234       
    1235      private function addComment($user,$pwd,$post_id,$struct) 
    1236      { 
    1237           $this->setUser($user,$pwd); 
    1238           $this->setBlog(); 
    1239            
    1240           if (empty($struct['content'])) { 
    1241                throw new Exception('Sorry, you cannot post an empty comment',401); 
    1242           } 
    1243            
    1244           if (is_numeric($post_id)) { 
    1245                $p['post_id'] = $post_id; 
    1246           } else { 
    1247                $p['post_url'] = $post_id; 
    1248           } 
    1249           $rs = $this->core->blog->getPosts($p); 
    1250           if ($rs->isEmpty()) { 
    1251                throw new Exception('Sorry, no such post.',404); 
    1252           } 
    1253            
    1254           $cur = $this->core->con->openCursor($this->core->prefix.'comment'); 
    1255            
    1256           $cur->comment_author = $this->core->auth->getInfo('user_cn'); 
    1257           $cur->comment_email = $this->core->auth->getInfo('user_email'); 
    1258           $cur->comment_site = $this->core->auth->getInfo('user_url'); 
    1259            
    1260           $cur->comment_content = $struct['content']; 
    1261           $cur->post_id = (integer) $post_id; 
    1262            
    1263           $id = $this->core->blog->addComment($cur); 
    1264           return $id; 
    1265      } 
    1266       
    1267      private function updComment($user,$pwd,$comment_id,$struct) 
    1268      { 
    1269           $this->setUser($user,$pwd); 
    1270           $this->setBlog(); 
    1271            
    1272           $cur = $this->core->con->openCursor($this->core->prefix.'comment'); 
    1273            
    1274           if (isset($struct['status'])) { 
    1275                $cur->comment_status = $this->translateWpCommentstatus($struct['status']); 
    1276           } 
    1277            
    1278           if (isset($struct['date_created_gmt'])) { 
    1279                if ($struct['date_created_gmt'] instanceof xmlrpcDate) { 
    1280                     $cur->comment_dt = date('Y-m-d H:i:00',$struct['date_created_gmt']->getTimestamp()); 
    1281                } elseif (is_string($struct['date_created_gmt']) && @strtotime($struct['date_created_gmt'])) { 
    1282                     $cur->comment_dt = date('Y-m-d H:i:00',strtotime($struct['date_created_gmt'])); 
    1283                } 
    1284                $cur->comment_dt = $struct['date_created_gmt']; 
    1285           } 
    1286            
    1287           if (isset($struct['content'])) { 
    1288                $cur->comment_content = $struct['content']; 
    1289           } 
    1290            
    1291           if (isset($struct['author'])) { 
    1292                $cur->comment_author = $struct['author']; 
    1293           } 
    1294            
    1295           if (isset($struct['author_url'])) { 
    1296                $cur->comment_site = $struct['author_url']; 
    1297           } 
    1298            
    1299           if (isset($struct['author_email'])) { 
    1300                $cur->comment_email = $struct['author_email']; 
    1301           } 
    1302            
    1303           $this->core->blog->updComment($comment_id,$cur); 
    1304           return true; 
    1305      } 
    1306       
    1307      private function delComment($user,$pwd,$comment_id) 
    1308      { 
    1309           $this->setUser($user,$pwd); 
    1310           $this->setBlog(); 
    1311            
    1312           $this->core->blog->delComment($comment_id); 
    1313           return true; 
    13141105     } 
    13151106      
     
    15821373     } 
    15831374      
    1584      public function wp_getComment($blogid,$username,$password,$commentid) 
    1585      { 
    1586           $res = $this->getComments($username,$password,array(),$commentid); 
    1587            
    1588           if (empty($res)) { 
    1589                throw new Exception('Sorry, no such comment',404); 
    1590           } 
    1591            
    1592           return $res[0]; 
    1593      } 
    1594       
    1595      public function wp_getCommentCount($blogid,$username,$password,$postid) 
    1596      { 
    1597           return $this->countComments($username,$password,$postid); 
    1598      } 
    1599       
    1600      public function wp_getComments($blogid,$username,$password,$struct) 
    1601      { 
    1602           return $this->getComments($username,$password,$struct); 
    1603      } 
    1604       
    1605      public function wp_deleteComment($blogid,$username,$password,$commentid) 
    1606      { 
    1607           return $this->delComment($username,$password,$commentid); 
    1608      } 
    1609       
    1610      public function wp_editComment($blogid,$username,$password,$commentid,$content) 
    1611      { 
    1612           return $this->updComment($username,$password,$commentid,$content); 
    1613      } 
    1614       
    1615      public function wp_newComment($blogid,$username,$password,$postid,$content) 
    1616      { 
    1617           return $this->addComment($username,$password,$postid,$content); 
    1618      } 
    1619       
    1620      public function wp_getCommentStatusList($blogid,$username,$password) 
    1621      { 
    1622           $this->setUser($username,$password); 
    1623           $this->setBlog(); 
    1624            
    1625           return array( 
    1626                'hold' => 'Unapproved', 
    1627                'approve' => 'Approved', 
    1628                'spam' => 'Spam' 
    1629           ); 
    1630      } 
    16311375} 
    16321376?> 
Note: See TracChangeset for help on using the changeset viewer.

Sites map