liberty
[ class tree: liberty ] [ index: liberty ] [ all elements ]

Source for file LibertyComment.php

Documentation is available at LibertyComment.php

  1. <?php
  2. /**
  3.  * Management of Liberty Content
  4.  *
  5.  * @package  liberty
  6.  * @version  $Header$
  7.  * @author   spider <spider@steelsun.com>
  8.  */
  9.  
  10. /**
  11.  * required setup
  12.  */
  13. require_onceLIBERTY_PKG_PATH.'LibertyMime.php' );
  14.  
  15. define'BITCOMMENT_CONTENT_TYPE_GUID''bitcomment' );
  16.  
  17. /**
  18.  * Handles all comments which are actual content objects
  19.  *
  20.  * @package liberty
  21.  */
  22.  
  23. class LibertyComment extends LibertyMime {
  24.     var $mCommentId;
  25.  
  26.     function LibertyComment($pCommentId NULL$pContentId NULL$pInfo NULL{
  27.         parent::__construct();
  28.         $this->registerContentTypeBITCOMMENT_CONTENT_TYPE_GUIDarray(
  29.                 'content_type_guid' => BITCOMMENT_CONTENT_TYPE_GUID,
  30.                 'content_name' => 'Comment',
  31.                 'handler_class' => 'LibertyComment',
  32.                 'handler_package' => 'liberty',
  33.                 'handler_file' => 'LibertyComment.php',
  34.                 'maintainer_url' => 'http://www.bitweaver.org'
  35.             ) );
  36.         $this->mCommentId = $pCommentId;
  37.         $this->mContentId = $pContentId;
  38.         $this->mInfo = $pInfo;
  39.         $this->mAdminContentPerm = 'p_liberty_admin_comments';
  40.         $this->mRootObj NULL;
  41.  
  42.         if ($this->mCommentId || $this->mContentId{
  43.             $this->loadComment();
  44.         }
  45.     }
  46.  
  47.  
  48.     function loadComment({
  49.         global $gBitSystem$gBitUser;
  50.         if (!$this->verifyId($this->mCommentId&& !$this->verifyId($this->mContentId)) {
  51.             return NULL;
  52.         }
  53.  
  54.         if ($this->mCommentId{
  55.             $mid 'WHERE lcom.`comment_id` = ?';
  56.             $bindVars array($this->mCommentId);
  57.         else {
  58.             $mid 'WHERE lc.`content_id` = ?';
  59.             $bindVars array($this->mContentId);
  60.         }
  61.  
  62.         $joinSql $selectSql $whereSql '';
  63.         $this->getServicesSql'content_load_sql_function'$selectSql$joinSql$whereSql$bindVars$this );
  64.  
  65.         $sql "SELECT lcom.*, lc.*, uu.`email`, uu.`real_name`, uu.`login` $selectSql
  66.                 FROM `".BIT_DB_PREFIX."liberty_comments` lcom
  67.                     LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON (lcom.`content_id` = lc.`content_id`)
  68.                     LEFT OUTER JOIN `".BIT_DB_PREFIX."users_users` uu ON (lc.`user_id` = uu.`user_id`) $joinSql
  69.                 $mid $whereSql";
  70.         if$row $this->mDb->getRow$sql$bindVars ) ) {
  71.             $this->mInfo = $row;
  72.             $this->mContentId = $row['content_id'];
  73.             $this->mCommentId = $row['comment_id'];
  74.  
  75.             // call parent load for attachment data like other Mime derived classes, only need it if feature is active or admin
  76.             if$gBitSystem->isFeatureActive'comments_allow_attachments' || $gBitUser->isAdmin() ){
  77.                 LibertyMime::load();
  78.             }
  79.         }
  80.         return count($this->mInfo);
  81.     }
  82.  
  83.     function verifyComment(&$pParamHash{
  84.         global $gBitUser$gBitSystem;
  85.  
  86.         /* should be unnecessary
  87.         if( !empty( $_REQUEST['format_guid'] )) {
  88.             $storeRow['format_guid'] = $_REQUEST['format_guid'];
  89.         }
  90.         */
  91.  
  92.         $pParamHash['content_id'(@BitBase::verifyId($this->mContentId$this->mContentId : NULL);
  93.  
  94.         ifempty$pParamHash['root_id'&& !empty$pParamHash['comments_parent_id') ) {
  95.              $pParamHash['root_id'$pParamHash['comments_parent_id'];
  96.         }
  97.  
  98.         if (!$pParamHash['root_id']{
  99.             $this->mErrors['root_id'"Missing root id for comment";
  100.         }
  101.  
  102.         ifempty$pParamHash['parent_id') ){
  103.             $pParamHash['parent_id'(@BitBase::verifyId($this->mInfo['parent_id']$this->mInfo['parent_id'(!@BitBase::verifyId($pParamHash['post_comment_reply_id']$pParamHash['comments_parent_id'$pParamHash['post_comment_reply_id']));
  104.         }
  105.  
  106.         if (!$pParamHash['parent_id']{
  107.             $this->mErrors['parent_id'"Missing parent id for comment";
  108.         }
  109.  
  110.         if (empty($pParamHash['anon_name'])) {
  111.             $pParamHash['anon_name']=null;
  112.         }
  113.  
  114.         if!@$gBitUser->verifyCaptcha$pParamHash['captcha') ) {
  115.             $this->mErrors['store'tra'Incorrect validation code' );
  116.         }
  117.  
  118.         if!empty$pParamHash['comment_title') ){
  119.             $pParamHash['title'$pParamHash['comment_title'];
  120.         }
  121.  
  122.         if!empty$pParamHash['comment_data') ){
  123.             $pParamHash['edit'$pParamHash['comment_data'];
  124.         }
  125.  
  126.         ifempty$pParamHash['edit') ) {
  127.             $this->mErrors['store'tra'Your comment was empty.' );
  128.         elseif!$gBitUser->hasPermission'p_liberty_trusted_editor' && ($linkCount preg_match_all'/http\:\/\//'$pParamHash['edit']$links )) $gBitSystem->getConfig'liberty_unstrusted_max_http_in_content') ) {
  129.             $this->mErrors['store'tra'Links are not allowed.' );
  130.         else {
  131.             $dupeQuery "SELECT `data` FROM `".BIT_DB_PREFIX."liberty_content` lc INNER JOIN `".BIT_DB_PREFIX."liberty_comments` lcom ON (lc.`content_id`=lcom.`content_id`) WHERE `user_id`=? AND `content_type_guid`='".BITCOMMENT_CONTENT_TYPE_GUID."' AND `ip`=? AND lcom.`root_id`=? ORDER BY `created` DESC";
  132.             if$lastPostData $this->mDb->getOne$dupeQueryarray$gBitUser->mUserId$_SERVER['REMOTE_ADDR']$pParamHash['root_id') ) ) {
  133.                 ifempty$this->mCommentId && trim$lastPostData == trim$pParamHash['edit') ) {
  134.                     $this->mErrors['store'tra'Duplicate comment.' );
  135.                 }
  136.             }
  137.         }
  138.  
  139.         // verify attachments are allowed on comments
  140.         if( ( isset$pParamHash['_files_override'|| !empty$_FILES ) ) && !$gBitSystem->isFeatureActive'comments_allow_attachments' ) ) {
  141.             $this->mErrors['comment_attachments'tra'Files can not be uploaded with comments.' );
  142.         }
  143.  
  144.         // if we have an error we get them all by checking parent classes for additional errors
  145.         ifcount$this->mErrors ){
  146.             parent::verify$pParamHash );
  147.         }
  148.  
  149.         return (count($this->mErrors== 0);
  150.     }
  151.  
  152.     function storeComment&$pParamHash {
  153.         $this->mDb->StartTrans();
  154.         if$this->verifyComment($pParamHash&& LibertyMime::store$pParamHash ) ) {
  155.             if (!$this->mCommentId{
  156.                 $this->mCommentId = $this->mDb->GenID'liberty_comment_id_seq');
  157.  
  158.                 if (!empty($pParamHash['parent_id'])) {
  159.                     $parentComment new LibertyComment(NULL,$pParamHash['parent_id']);
  160.                 }
  161.                 $parent_sequence_forward '';
  162.                 $parent_sequence_reverse '';
  163.                 if (!empty($parentComment->mInfo['thread_forward_sequence'])) {
  164.                     $parent_sequence_forward $parentComment->mInfo['thread_forward_sequence'];
  165.                     $parent_sequence_reverse $parentComment->mInfo['thread_reverse_sequence'];
  166.                 }
  167.                 // if nesting level > 25 deep, put it on level 25
  168.                 if (strlen($parent_sequence_forward10*24{
  169.                     $parent_sequence_forward substr($parent_sequence_forward,0,10*24);
  170.                 }
  171.  
  172.                 $this->mInfo['thread_forward_sequence'$parent_sequence_forward sprintf("%09d.",$this->mCommentId);
  173.                 $this->mInfo['thread_reverse_sequence'strtr($parent_sequence_forward sprintf("%09d.",$this->mCommentId),
  174.                         '0123456789''9876543210');
  175.  
  176.                 $sql "INSERT INTO `".BIT_DB_PREFIX."liberty_comments` (`comment_id`, `content_id`, `parent_id`, `root_id`, `anon_name`, `thread_forward_sequence`, `thread_reverse_sequence`) VALUES (?,?,?,?,?,?,?)";
  177.  
  178.                 $this->mDb->query($sqlarray($this->mCommentId$pParamHash['content_id']$pParamHash['parent_id'],
  179.                     $pParamHash['root_id']$pParamHash['anon_name'],
  180.                     $this->mInfo['thread_forward_sequence']$this->mInfo['thread_reverse_sequence']));
  181.                 $this->mInfo['parent_id'$pParamHash['parent_id'];
  182.                 $this->mInfo['content_id'$pParamHash['content_id'];
  183.                 $this->mInfo['root_id'$pParamHash['root_id'];
  184.                 $this->mContentId = $pParamHash['content_id'];
  185.             else {
  186.                 $sql "UPDATE `".BIT_DB_PREFIX."liberty_comments` SET `parent_id` = ?, `content_id`= ? WHERE `comment_id` = ?";
  187.                 $this->mDb->query($sqlarray($pParamHash['parent_id']$pParamHash['content_id']$this->mCommentId));
  188.                 $this->mInfo['parent_id'$pParamHash['parent_id'];
  189.                 $this->mInfo['content_id'$pParamHash['content_id'];
  190.                 $this->mContentId = $pParamHash['content_id'];
  191.             }
  192.             $this->invokeServices'comment_store_function'$pParamHash );
  193.  
  194.         }
  195.  
  196.         $this->mDb->CompleteTrans();
  197.         return (count($this->mErrors== 0);
  198.     }
  199.  
  200.  
  201.     // This is a highly specialized method only used for emailing list synchronization. If you don't know anything about this, just move along and live in bliss
  202.     // (Hint: see mailing list integreation in boards)
  203.     function storeMessageId$pMessageId {
  204.         if$this->isValid() ) {
  205.             $this->mDb->query"UPDATE `".BIT_DB_PREFIX."liberty_comments` SET `message_guid`=? WHERE `content_id`=?"array$pMessageId$this->mContentId ) );
  206.         }
  207.     }
  208.  
  209.     // delete a single comment
  210.     function deleteComment({
  211.         global $gBitSystem;
  212.         $ret FALSE;
  213.         if$this->isValid() ) {
  214.             $this->mDb->StartTrans();
  215.  
  216.             if$gBitSystem->isPackageActive'boards' ) ) {
  217.                 // due to foreign key constraints, this has to go in the base class of BitBoardPost
  218.                 $sql "DELETE FROM `".BIT_DB_PREFIX."boards_posts` WHERE `comment_id` = ?";
  219.                 $rs $this->mDb->query($sqlarray($this->mCommentId ) );
  220. //                $query = "DELETE FROM `".BIT_DB_PREFIX."boards_topics` WHERE `parent_id` = ?";
  221. //                $result = $this->mDb->query( $query, array( $this->getField( 'content_id' ) ) );
  222.             }
  223.  
  224.  
  225.             $sql "DELETE FROM `".BIT_DB_PREFIX."liberty_comments` WHERE `comment_id` = ?";
  226.             $rs $this->mDb->query($sqlarray($this->mCommentId));
  227.  
  228.             /*
  229.              * TODO: figureout why this is even here. Mime should handle this and it needs to pass in mandatory attachmentId
  230.              * Slated to delete for now  - wjames5
  231.              */
  232.             /*
  233.             if (method_exists($this,'expungeMetaData')) {
  234.                 $this->expungeMetaData();
  235.             }
  236.             */
  237.  
  238.             ifLibertyMime::expunge() ) {
  239.                 $ret TRUE;
  240.                 $this->mDb->CompleteTrans();
  241.             else {
  242.                 $this->mDb->RollbackTrans();
  243.             }
  244.         }
  245.         return $ret;
  246.     }
  247.  
  248.     //delete the comment and all of its children
  249.     //it should be possible to do this in a single query using the materialized path
  250.     //this is the code from the old function which needs to be revised
  251.     // 1) change name
  252.     // 2) use materialized path to cut query count and eliminate recursion
  253.  
  254.     function expunge({
  255.         global $gBitSystem;
  256.         $ret FALSE;
  257.         if$this->isValid() ) {
  258.             $this->mDb->StartTrans();
  259.             $sql "SELECT `comment_id` FROM `".BIT_DB_PREFIX."liberty_comments` WHERE `parent_id` = ?";
  260.             $rows $this->mDb->getAll($sqlarray($this->mContentId));
  261.  
  262.             foreach ($rows as $row{
  263.                 $comment new LibertyComment($row['comment_id']);
  264.                 $comment->expunge();
  265.             }
  266.  
  267.             if$gBitSystem->isPackageActive'boards' ) ) {
  268.                 // due to foreign key constraints, this has to go in the base class of BitBoardPost
  269.                 $sql "DELETE FROM `".BIT_DB_PREFIX."boards_posts` WHERE `comment_id` = ?";
  270.                 $rs $this->mDb->query($sqlarray($this->mCommentId ) );
  271.                 $query "DELETE FROM `".BIT_DB_PREFIX."boards_topics` WHERE `parent_id` = ?";
  272.                 $result $this->mDb->query$queryarray$this->getField'content_id' ) ) );
  273.             }
  274.  
  275.             $sql "DELETE FROM `".BIT_DB_PREFIX."liberty_comments` WHERE `comment_id` = ?";
  276.             $rs $this->mDb->query($sqlarray($this->mCommentId));
  277.  
  278.             /*
  279.              * TODO: figureout why this is even here. Mime should handle this and it needs to pass in mandatory attachmentId
  280.              * Slated to delete for now  - wjames5
  281.              */
  282.             /*
  283.             if (method_exists($this,'expungeMetaData')) {
  284.                 $this->expungeMetaData();
  285.             }
  286.             */
  287.  
  288.             ifLibertyMime::expunge() ) {
  289.                 $ret TRUE;
  290.                 $this->mDb->CompleteTrans();
  291.             else {
  292.                 $this->mDb->RollbackTrans();
  293.             }
  294.         }
  295.         return $ret;
  296.     }
  297.  
  298.     function userCanEdit({
  299.         global $gBitUser$gBitSystem;
  300.         $ret FALSE;
  301.  
  302.         // check the allowed edit time limit - we'll use it later
  303.         $withinEditTime FALSE;
  304.         if $gBitSystem->getConfig'comments_edit_minutes'60 60 $this->getField'created' time() ) {
  305.             $withinEditTime TRUE;
  306.         }
  307.         if$gBitUser->isRegistered() ) {
  308.             /* get the hash of the users perms rather than call hasUserPermission which
  309.              * always returns true for owner which interferes with trying to time limit editing
  310.              */
  311.             $checkPerms $this->getUserPermissions();
  312.             $ret !empty$checkPerms['p_liberty_edit_comments'||
  313.                      !empty$checkPerms['p_liberty_admin_comments'||
  314.                      $gBitUser->hasPermission'p_liberty_admin_comments' ||
  315.                      $gBitUser->mUserId == $this->mInfo['user_id'&& $withinEditTime )
  316.                     );
  317.         elseif$this->mInfo['user_id'== ANONYMOUS_USER_ID {
  318.             $ret (($_SERVER['REMOTE_ADDR']==$this->mInfo['ip']&& $withinEditTime );
  319.         }
  320.         return $ret;
  321.     }
  322.  
  323.     function userCanUpdate$pRootContent=NULL {
  324.         return$this->userCanEdit(|| ($pRootContent && ($pRootContent->hasUserPermission'p_liberty_edit_comments' || $pRootContent->hasUserPermission'p_liberty_admin_comments' ))) );
  325.     }
  326.  
  327.     /**
  328.     * @param pLinkText name of
  329.     * @param pParamHash different possibilities depending on derived class
  330.     * @return the link to display the page.
  331.     */
  332.     public static function getDisplayUrlFromHash&$pParamHash {
  333.         $ret NULL;
  334.         if@BitBase::verifyId$pParamHash['root_id'&& $viewContent LibertyBase::getLibertyObject$pParamHash['root_id') ) {
  335.             // pass in cooment hash to the url func incase the root package needs to do something fancy
  336.             $viewContent->mInfo['comment'$pParamHash;
  337.             $ret $viewContent->getDisplayUrl().@static::verifyId$pParamHash['content_id'"#comment_".$pParamHash['content_id''' );
  338.         elseif@BitBase::verifyId$pParamHash['content_id') ) {
  339.             $ret parent::getDisplayUrlFromHash$pParamHash );
  340.             $ret .= "#comment_{$pParamHash['content_id']}";
  341.         }
  342.  
  343.         return$ret );
  344.     }
  345.  
  346.     //generate a URL to directly access and display a single comment and the associated root content
  347.     public static function getDirectUrlFromHash$pParamHash=NULL {
  348.             ifempty$pParamHash ) ) {
  349.                     $pParamHash &$this->mInfo;
  350.             }
  351.             $ret NULL;
  352.             if!empty$pParamHash['root_id'&& $viewContent LibertyBase::getLibertyObject$pParamHash['root_id') ) {
  353.                     $ret $viewContent->getDisplayUrl();
  354.                     if strstr($ret'?') ) {
  355.                         $ret .= "&";
  356.                     }
  357.                     else {
  358.                         $ret .= "?";
  359.                     }
  360.                     $ret .= "view_comment_id=" $pParamHash['content_id'.  "#comment_".$pParamHash['content_id'];
  361.             }
  362.             return $ret );
  363.     }
  364.  
  365.     function getDisplayLink$pLinkText=NULL$pMixed=NULL$pAnchor=NULL {
  366.         $anchor '';
  367.         // Override default title with something comment centric
  368.         ifempty$pLinkText ) ) {
  369.             $pLinkText tra'Comment' );
  370.         }
  371.         if@BitBase::verifyId$pMixed['content_id')) {
  372.             $anchor "&view_comment_id=".$pMixed['content_id']."#comment_{$pMixed['content_id']}";
  373.         }
  374.         return parent::getDisplayLink$pLinkText$pMixed$anchor );
  375.     }
  376.  
  377.     function getList&$pParamHash {
  378.         global $gBitSystem$gLibertySystem;
  379.         if !isset$pParamHash['sort_mode']or $pParamHash['sort_mode'== '' ){
  380.             $pParamHash['sort_mode''created_desc';
  381.         }
  382.         ifempty$pParamHash['max_records') ) {
  383.             $pParamHash['max_records'$gBitSystem->getConfig'max_records' );
  384.         }
  385.         LibertyContent::prepGetList$pParamHash );
  386.         $sort_mode $this->mDb->convertSortmode($pParamHash['sort_mode']);
  387.  
  388.         $joinSql $whereSql $selectSql '';
  389.         $bindVars $ret array();
  390.  
  391.         $pParamHash['include_comments'TRUE;
  392.         $this->getServicesSql'content_list_sql_function'$selectSql$joinSql$whereSql$bindVarsNULL$pParamHash );
  393.  
  394.         if !empty$pParamHash['root_content_type_guid') ) {
  395.             ifis_string$pParamHash['root_content_type_guid') ) {
  396.                 $pParamHash['root_content_type_guid'array$pParamHash['root_content_type_guid');
  397.             elseifis_array$pParamHash['root_content_type_guid') ) {
  398.                 $contentTypes array_keys$gLibertySystem->mContentTypes );
  399.                 $max count$pParamHash['root_content_type_guid');
  400.                 $guidSql '';
  401.                 for$i 0$i $max$i++ {
  402.                     ifin_array$pParamHash['root_content_type_guid'][$i]$contentTypes ) ) {
  403.                         ifstrlen$guidSql ) ) {
  404.                             $guidSql .= ' OR ';
  405.                         }
  406.                         $guidSql .= " rlc.`content_type_guid`=? ";
  407.                         $bindVars[$pParamHash['root_content_type_guid'][$i];
  408.                     }
  409.                 }
  410.                 $whereSql .= " AND ( $guidSql )";
  411.             }
  412.         }
  413.  
  414.         if !empty$pParamHash['content_type_guid') ) {
  415.             $whereSql .= " AND rlc.`content_type_guid`=? ";
  416.             $bindVars[$pParamHash['content_type_guid'];
  417.         }
  418.  
  419.         if !empty$pParamHash['user_id') ) {
  420.             $whereSql .= " AND ptc.`user_id`=? ";
  421.             $bindVars[$pParamHash['user_id'];
  422.         }
  423.  
  424.         if !empty$pParamHash['created_ge') ) {
  425.             $whereSql .= " AND lc.`created`>=? ";
  426.             $bindVars[$pParamHash['created_ge'];
  427.         }
  428.  
  429.         // left outer join on root so updater works
  430.  
  431.         $query "SELECT
  432.                     lcom.`comment_id`,
  433.                     lc.`content_id`,
  434.                     lcom.`parent_id`,
  435.                     lcom.`anon_name`,
  436.                     lcom.`root_id`,
  437.                     lc.`title` AS `content_title`,
  438.                     rlc.`title` AS `root_content_title`,
  439.                     lc.`created`,
  440.                     lc.`data`,
  441.                     lc.`last_modified` as `last_modified`,
  442.                     lc.`title` as `title`,
  443.                     ptc.`content_type_guid` as `parent_content_type_guid`,
  444.                     rlc.`content_type_guid` as `root_content_type_guid`,
  445.                     lc.`content_type_guid`,
  446.                     uu.`login` AS `creator_user`,
  447.                     uu.`login`,
  448.                     uu.`real_name`,
  449.                     uu.`user_id`
  450.                     $selectSql
  451.                   FROM `".BIT_DB_PREFIX."liberty_comments` lcom
  452.                           INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON( lcom.`content_id`=lc.`content_id` )
  453.                           INNER JOIN `".BIT_DB_PREFIX."users_users` uu ON( uu.`user_id`=lc.`user_id`)
  454.                         LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_content` rlc ON( rlc.`content_id`=lcom.`root_id` )
  455.                         $joinSql, `".BIT_DB_PREFIX."liberty_content` ptc
  456.                   WHERE lcom.`parent_id`=ptc.`content_id` $whereSql
  457.                   ORDER BY $sort_mode";
  458.         if$result $this->mDb->query$query$bindVars$pParamHash['max_records']$pParamHash['offset')) {
  459.             while$row $result->FetchRow() ) {
  460.                 $row['display_link'$this->getDisplayLink$row['content_title']$row );
  461.                 $row['display_url'static::getDisplayUrlFromHash$row );
  462.                 $row['direct_url'static::getDirectUrlFromHash$row );
  463.                 if (!empty($pParamHash['parse'])) {
  464.                     $row['parsed_data'$this->parseData($row);
  465.                 }
  466.                 $ret[$row;
  467.             }
  468.         }
  469.  
  470.         return $ret;
  471.     }
  472.  
  473.     /**
  474.     * Fill title with date if available
  475.     *
  476.     * This will normally be overwriten by extended classes to provide
  477.     * an appropriate title title string
  478.     * @param array mInfo type hash of data to be used to provide base data
  479.     * @return string Descriptive title for the object
  480.     */
  481.     public static function getTitleFromHash$pHash$pDefault=TRUE {
  482.         global $gBitSmarty;
  483.         $ret NULL;
  484.         if!empty$pHash['title') ) {
  485.             $ret $pHash['title'];
  486.         elseif!empty$pHash['created') ) {
  487.             $gBitSmarty->loadPlugin'smarty_modifier_bit_short_date' );
  488.             $ret smarty_modifier_bit_short_date$pHash['created');
  489.         elseif!empty$pHash['content_name') ) {
  490.             $ret $pHash['content_name'];
  491.         }
  492.         return $ret;
  493.     }
  494.  
  495.  
  496.     function getNumComments($pContentId NULL{
  497.         $bindVars NULL;
  498.         if (!$pContentId && $this->mContentId{
  499.             $mid '=?';
  500.             $bindVars array($this->mContentId);
  501.         elseif (is_array($pContentId)) {
  502.             $mid 'in ('.implode(','array_fill(0count$pContentId )'?')).')';
  503.             $bindVars $pContentId;
  504.         elseif ($pContentId{
  505.             $mid '=?';
  506.             $bindVars array($pContentId);
  507.         }
  508.         $commentCount 0;
  509.  
  510.         $joinSql $selectSql $whereSql '';
  511.  
  512.         /* brute force call to liberty_content_list_sql
  513.          * for status enforcement
  514.          *
  515.          * here we call liberty_content_list_sql which has a
  516.          * restriction to enforce content_status_id. we could
  517.          * have called the full list_sql service, but that
  518.          * would be overkill for just getting a count.
  519.          */
  520.         if !is_array($pContentId) ){
  521.             $sqlHash liberty_content_list_sql$thisNULL );
  522.             if!empty$sqlHash['select_sql') ) {
  523.                 $selectSql .= $sqlHash['select_sql'];
  524.             }
  525.             if!empty$sqlHash['join_sql') ) {
  526.                 $joinSql .= $sqlHash['join_sql'];
  527.             }
  528.             if!empty$sqlHash['where_sql') ) {
  529.                 $whereSql .= $sqlHash['where_sql'];
  530.             }
  531.             if!empty$sqlHash['bind_vars') ) {
  532.                 if is_array$bindVars ) ) {
  533.                     $bindVars array_merge$bindVars$sqlHash['bind_vars');
  534.                 else {
  535.                     $bindVars $sqlHash['bind_vars'];
  536.                 }
  537.             }
  538.         }
  539.  
  540.         if ($bindVars{
  541.             $sql "SELECT count(*) as comment_count $selectSql
  542.                     FROM `".BIT_DB_PREFIX."liberty_comments` lcom
  543.                         INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON (lcom.`content_id` = lc.`content_id`) $joinSql
  544.                     WHERE lcom.`root_id` $mid $whereSql";
  545.             $commentCount $this->mDb->getOne($sql$bindVars);
  546.         }
  547.         return $commentCount;
  548.      }
  549.  
  550.  
  551.     // used for direct access to view a single comment
  552.     // see usage in: liberty/comments_inc.php
  553.     // there ought to be a better way to do this...
  554.     function getNumComments_upto($pCommentId NULL$pContentId NULL{
  555.  
  556.         $comment new LibertyComment($pCommentId$pContentId);
  557.  
  558.         #assume flat mode
  559.         $comment_fields $comment->mInfo;
  560.         $created $comment_fields['created'];
  561.         $contentId $comment_fields['root_id'];
  562.  
  563.         $commentCount 0;
  564.         if ($contentId{
  565.             $sql "SELECT count(*)
  566.                     FROM `".BIT_DB_PREFIX."liberty_comments` tc LEFT OUTER JOIN
  567.                      `".BIT_DB_PREFIX."liberty_content` tcn
  568.                      ON (tc.`content_id` = tcn.`content_id`)
  569.                     where tc.`root_id` =? and `created` < ?";
  570.             $commentCount $this->mDb->getOne($sqlarray($contentId$created));
  571.         }
  572.         return $commentCount;
  573.     }
  574.  
  575.     // Returns a hash containing the comment tree of comments related to this content
  576.     function getComments$pContentId NULL$pMaxComments NULL$pOffset NULL$pSortOrder NULL$pDisplayMode NULL {
  577.         if$pDisplayMode != "flat" {
  578.             if ($pSortOrder == "commentDate_asc"{
  579.                 $pSortOrder 'thread_asc';
  580.             else {
  581.                 $pSortOrder 'thread_desc';
  582.             }
  583.         }
  584.  
  585.         $contentId NULL;
  586.         $ret array();
  587.         if (!$pContentId && $this->mContentId{
  588.             $contentId $this->mContentId;
  589.         elseif ($pContentId{
  590.             $contentId $pContentId;
  591.         }
  592.  
  593.         $mid "";
  594.  
  595.         $sort_order "ASC";
  596.         $mid 'created ASC';
  597.         if (!empty($pSortOrder)) {
  598.             if ($pSortOrder == 'commentDate_desc'{
  599.                 $mid 'created DESC';
  600.             else if ($pSortOrder == 'commentDate_asc'{
  601.                 $mid 'created ASC';
  602.             elseif ($pSortOrder == 'thread_asc'{
  603.                 $mid 'thread_forward_sequence  ASC';
  604.             // thread newest first is harder...
  605.             elseif ($pSortOrder == 'thread_desc'{
  606.                 $mid 'thread_reverse_sequence  ASC';
  607.             else {
  608.                 $mid $this->mDb->convertSortmode$pSortOrder );
  609.             }
  610.         }
  611.         $mid 'order by ' $mid;
  612.  
  613.         $bindVars array();
  614.         if (is_array$pContentId ) ) {
  615.             $mid2 'in ('.implode(','array_fill(0count$pContentId )'?')).')';
  616.             $bindVars $pContentId;
  617.             $select1 ', lcp.`content_type_guid` as parent_content_type_guid, lcp.`title` as parent_title ';
  618.             $join1 " LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_content` lcp ON (lcp.`content_id` = lcom.`parent_id`) ";
  619.         elseif ($pContentId{
  620.             $mid2 '=?';
  621.             $bindVars array$pContentId );
  622.             $select1 '';
  623.             $join1 '';
  624.         }
  625.  
  626.         $joinSql $selectSql $whereSql '';
  627.         $pListHash array'content_id' => $contentId'max_records' => $pMaxComments'offset'=>$pOffset'sort_mode'=> $pSortOrder'display_mode' => $pDisplayMode'has_comment_view_perm' => TRUE );
  628.         $this->getServicesSql'content_list_sql_function'$selectSql$joinSql$whereSql$bindVars$this$pListHash );
  629.  
  630.         if ($pContentId{
  631.             $sql "SELECT lcom.`comment_id`, lcom.`parent_id`, lcom.`root_id`, lcom.`thread_forward_sequence`, lcom.`thread_reverse_sequence`, lcom.`anon_name`, lc.*, uu.`email`, uu.`real_name`, uu.`login` $selectSql $select1
  632.                     FROM `".BIT_DB_PREFIX."liberty_comments` lcom
  633.                         LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON (lcom.`content_id` = lc.`content_id`)
  634.                         LEFT OUTER JOIN `".BIT_DB_PREFIX."users_users` uu ON (lc.`user_id` = uu.`user_id`) $joinSql $join1
  635.                     WHERE lcom.root_id $mid2 $whereSql $mid";
  636.             $flat_comments array();
  637.             if$result $this->mDb->query$sql$bindVars$pMaxComments$pOffset ) ) {
  638.                 while$row $result->FetchRow() ) {
  639.                     $row['parsed_data'$this->parseData$row );
  640.                     $row['level'substr_count $row['thread_forward_sequence']'.' 1;
  641.                     $c new LibertyComment();
  642.                     $c->mInfo=$row;
  643.                     $c->mRootObj $this->getRootObj();
  644.                     $row['is_editable'$c->userCanUpdate$c->mRootObj );
  645.  
  646.                     global $gBitSystem;
  647.                     if$gBitSystem->isFeatureActive'comments_allow_attachments' ) ){
  648.                         // get attachments for each comment
  649.                         global $gLibertySystem;
  650.                         $query "SELECT * FROM `".BIT_DB_PREFIX."liberty_attachments` la WHERE la.`content_id`=? ORDER BY la.`pos` ASC, la.`attachment_id` ASC";
  651.                         if$result2 $this->mDb->query$query,array(int)$row['content_id'))) {
  652.                             while$row2 $result2->fetchRow() ) {
  653.                                 if$func $gLibertySystem->getPluginFunction$row2['attachment_plugin_guid']'load_function''mime' )) {
  654.                                     // we will pass the preferences by reference that the plugin can easily update them
  655.                                     ifempty$row['storage'][$row2['attachment_id']] )) {
  656.                                         $row['storage'][$row2['attachment_id']] array();
  657.                                     }
  658.                                     $row['storage'][$row2['attachment_id']] $func$row2$row['storage'][$row2['attachment_id']] );
  659.                                 else {
  660.                                     print "No load_function for ".$row2['attachment_plugin_guid'];
  661.                                 }
  662.                             }
  663.                         }
  664.                         // end get attachements for each comment
  665.                     }
  666.  
  667.                     $flat_comments[$row['content_id']] $row;
  668.                 }
  669.             }
  670.  
  671.             # now select comments wanted
  672.             $ret $flat_comments;
  673.  
  674.             }
  675.         return $ret;
  676.     }
  677.  
  678.     function getQuoted({
  679.         $data $this->mInfo['data'];
  680.         $pattern '/\{quote .*\}(.*)\{\/quote\}/i';
  681.         $replacement '';
  682.         $data preg_replace($pattern$replacement$data);
  683.         return '{quote format_guid="'.$this->mInfo['format_guid'].'" comment_id="'.$this->mCommentId.'" user="'.$this->mInfo['login'].'"}'.trim($data).'{/quote}';
  684.     }
  685.  
  686.      // Basic formatting for quoting comments
  687.      function quoteComment($commentData{
  688.         $ret '> '.$commentData;
  689.         $ret eregi_replace("\n""\n>"$ret);
  690.         return $ret;
  691.     }
  692.  
  693.     function getRootObj(){
  694.         if !is_object$this->mRootObj && !empty$this->mInfo['root_id') ){
  695.             if $obj LibertyBase::getLibertyObject$this->mInfo['root_id') ) {
  696.                 $this->mRootObj $obj;
  697.             }
  698.         }
  699.         return $this->mRootObj;
  700.     }
  701. }
  702.  
  703. ?>

Documentation generated on Wed, 29 Jul 2015 13:56:48 +0000 by phpDocumentor 1.5.0-lsces