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

Source for file BitBoardTopic.php

Documentation is available at BitBoardTopic.php

  1. <?php
  2. /**
  3.  * $Header$
  4.  * $Id$
  5.  *
  6.  * Messageboards class to illustrate best practices when creating a new bitweaver package that
  7.  * builds on core bitweaver functionality, such as the Liberty CMS engine
  8.  *
  9.  * @author spider <spider@steelsun.com>
  10.  * @version $Revision$
  11.  * @package boards
  12.  */
  13.  
  14. /**
  15.  * required setup
  16.  */
  17. require_onceLIBERTY_PKG_PATH.'LibertyComment.php' );
  18. require_onceBOARDS_PKG_PATH.'BitBoardPost.php' );
  19.  
  20. /**
  21. * This is used to uniquely identify the object
  22. */
  23. define'BITBOARDTOPIC_CONTENT_TYPE_GUID''bitboardtopic' );
  24.  
  25. /**
  26.  * Class that handles topics for a board
  27.  *
  28.  * expunge is handled explicitly in LibertyComment::expunge
  29.  *
  30.  * @package boards
  31.  */
  32. class BitBoardTopic extends LibertyMime {
  33.     /**
  34.     * Primary key for our mythical Messageboards class object & table
  35.     * @public
  36.     */
  37.     var $mRootId;
  38.  
  39.     /**
  40.      * the content id of the topic comment object
  41.      * this is really the contentId, but mContentId houses the parent board content_id currently
  42.      **/
  43.  
  44.     var $mCommentContentId;
  45.  
  46.     /**
  47.     * During initialisation, be sure to call our base constructors
  48.     **/
  49.  
  50.     function BitBoardTopic$pRootId=NULL {
  51.         parent::__construct();
  52.         $this->mRootId = $pRootId;
  53.  
  54.         // Permission setup
  55.         $this->mViewContentPerm  = 'p_boards_read';
  56.         $this->mUpdateContentPerm  = 'p_boards_update';
  57.         $this->mAdminContentPerm = 'p_boards_admin';
  58.  
  59.         $this->mRootObj NULL;  //a reference to the root obj
  60.     }
  61.  
  62.     /**
  63.     * Load the data from the database
  64.     * @param pParamHash be sure to pass by reference in case we need to make modifcations to the hash
  65.     ***/
  66.     function load$pContentId NULL$pPluginParams NULL {
  67.         global $gBitUser$gBitSystem;
  68.         if$this->verifyId$this->mRootId || $this->verifyId$this->mContentId ) ) {
  69.             // This is a significant performance optimization
  70.             $lookupColumn $this->verifyId$this->mRootId 'lcom.`comment_id`' 'lc.`content_id`';
  71.             $bindVars array();
  72.             $selectSql $joinSql $whereSql '';
  73.             array_push$bindVars$lookupId @BitBase::verifyId$this->mRootId $this->mRootId : $this->mContentId );
  74.             $paramHash arrayarray'include_comments' => TRUE ) );
  75.             $this->getServicesSql'content_load_sql_function'$selectSql$joinSql$whereSql$bindVars$this$paramHash );
  76.  
  77.             if (!($gBitUser->hasPermission('p_boards_update'|| $gBitUser->hasPermission('p_boards_posts_update'))) {
  78.                 //$whereSql .= " AND ((first.`is_approved` = 1) OR (flc.`user_id` >= 0))";
  79.             }
  80.  
  81.             BitBoardTopic::loadTrack($selectSql$joinSql);
  82.  
  83.             $BIT_DB_PREFIX BIT_DB_PREFIX;
  84.             $query ="
  85.                 SELECT
  86.                     lc.`user_id` AS flc_user_id,
  87.                     lc.`created` AS flc_created,
  88.                     lc.`last_modified` AS flc_last_modified,
  89.                     lc.`title` AS title,
  90.                     lc.`content_id` AS flc_content_id,
  91.  
  92.                     COALESCE(post.`is_approved`,0) AS first_approved,
  93.                     lcom.`anon_name`,
  94.  
  95.                     th.`parent_id` AS th_first_id,
  96.                     COALESCE(th.`is_locked`,0) AS th_is_locked,
  97.                     COALESCE(th.`is_moved`,0) AS th_is_moved,
  98.                     COALESCE(th.`is_sticky`,0) AS th_is_sticky,
  99.  
  100.                     lcom.`comment_id` AS th_thread_id,
  101.                     lcom.`root_id` AS th_root_id,
  102.                     lcom.`root_id` AS content_id,
  103.                     lc.`content_type_guid` AS content_type_guid,
  104.  
  105.                     rlc.content_id AS root_content_id, rlc.title AS root_title, rlc.content_type_guid AS `root_content_type_guid`,
  106.  
  107.                     map.`board_content_id` AS board_content_id, b.`board_id`
  108.  
  109.                 $selectSql
  110.                 FROM `".BIT_DB_PREFIX."liberty_comments` lcom
  111.                     INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON( lc.`content_id` = lcom.`content_id` )
  112.                     INNER JOIN `".BIT_DB_PREFIX."boards_map` map ON (map.`topic_content_id`=lcom.`root_id` )
  113.                     INNER JOIN `".BIT_DB_PREFIX."boards` b ON (map.`board_content_id`=b.`content_id` )
  114.                     INNER JOIN `".BIT_DB_PREFIX."liberty_content` rlc ON (rlc.`content_id` = lcom.`root_id`)
  115.                 $joinSql
  116.                     LEFT JOIN `".BIT_DB_PREFIX."boards_topics` th ON (th.`parent_id`=lcom.`content_id`)
  117.                     LEFT JOIN `".BIT_DB_PREFIX."boards_posts` post ON(post.`comment_id`=lcom.`comment_id`)
  118.                 WHERE
  119.                     lcom.`root_id`=lcom.`parent_id` AND    $lookupColumn=?
  120.                 $whereSql";
  121.  
  122.             $result $this->mDb->query$query$bindVars );
  123.  
  124.             if$result && $result->numRows() ) {
  125.                 $this->mInfo = $result->fields;
  126.                 $this->mContentId = $this->getField'content_id' );
  127.                 $this->mCommentContentId = $this->getField('flc_content_id');
  128.                 $llc_data BitBoardTopic::getLastPost($this->mInfo);
  129.                 $this->mInfo = array_merge($this->mInfo,$llc_data);
  130.                 $this->mRootId = $result->fields['th_thread_id'];
  131.                 // @TODO this would make more sense if this were assigned to mRootId - but that is currently in use as top comment id
  132.                 $this->mInfo['root_id'$result->fields['th_root_id'];
  133.                 BitBoardTopic::track($this->mInfo);
  134.                 $this->mInfo['display_url'$this->getDisplayUrl();
  135.  
  136.                 if (empty($this->mInfo['anon_name'])) {
  137.                     $this->mInfo['anon_name'"Anonymous";
  138.                 }
  139.  
  140.                 parent::load()// assumes you have joined already, and will not execute any sql!
  141.             }
  142.         }
  143.         returncount$this->mInfo ) );
  144.     }
  145.  
  146.     function lookupByMigratePost$pMigratePostId {
  147.         global $gBitDb;
  148.         $ret NULL;
  149.         ifBitBase::verifyId$pMigratePostId ) ) {
  150.             $path $gBitDb->getOne"SELECT lcom.`thread_forward_sequence`  FROM `".BIT_DB_PREFIX."boards_posts` bp INNER JOIN `".BIT_DB_PREFIX."liberty_comments` lcom ON(bp.`comment_id`=lcom.`comment_id`) WHERE bp.`migrate_post_id`=?"array$pMigratePostId ) );
  151.             if$path {
  152.                 $ret boards_get_topic_comment$path  );
  153.             }
  154.         }
  155.         return $ret;
  156.     }
  157.  
  158.     function lookupByMigrateTopic$pMigrateTopicId {
  159.         global $gBitDb;
  160.         $ret NULL;
  161.         ifBitBase::verifyId$pMigrateTopicId ) ) {
  162.             $ret $gBitDb->getOne"SELECT lcom.`comment_id`  FROM `".BIT_DB_PREFIX."boards_topics` bt INNER JOIN `".BIT_DB_PREFIX."liberty_comments` lcom ON(bt.`parent_id`=lcom.`content_id`) WHERE `migrate_topic_id`=?"array$pMigrateTopicId ) );
  163.         }
  164.         return $ret;
  165.     }
  166.  
  167.     function verify&$pParamHash {
  168.         ifisset$pParamHash['is_locked') ) {
  169.             if!is_numeric$pParamHash['is_locked'|| $pParamHash['is_locked'|| $pParamHash['is_locked'{
  170.                 $this->mErrors[]=("Invalid topic state");
  171.             else {
  172.                 $pParamHash['topic_store']['is_locked'$pParamHash['is_locked'];
  173.             }
  174.         }
  175.         ifisset$pParamHash['is_moved') ) {
  176.             if!is_numeric$pParamHash['is_moved'|| $pParamHash['is_moved'|| $pParamHash['is_moved'{
  177.                 $this->mErrors[]=("Invalid move state");
  178.             else {
  179.                 $pParamHash['topic_store']['is_moved'$pParamHash['is_moved'];
  180.             }
  181.         }
  182.         if!empty$pParamHash['is_sticky') ) {
  183.             if!is_numeric$pParamHash['is_sticky'|| $pParamHash['is_sticky'|| $pParamHash['is_sticky'{
  184.                 $this->mErrors[]=("Invalid sticky state");
  185.             else {
  186.                 $pParamHash['topic_store']['is_sticky'$pParamHash['is_sticky'];
  187.             }
  188.         }
  189.         if!empty$pParamHash['migrate_topic_id') ) {
  190.             $pParamHash['topic_store']['migrate_topic_id'$pParamHash['migrate_topic_id'];
  191.         }
  192.  
  193.         returncount$this->mErrors == && !empty$pParamHash['topic_store') );
  194.     }
  195.  
  196.     /**
  197.      * This function stickies a topic
  198.      */
  199.     function store&$pParamHash {
  200.         global $gBitSystem;
  201.         $ret FALSE;
  202.         if$this->mCommentContentId && $this->verify$pParamHash ) ) {
  203.             //$pParamHash = (($pParamHash + 1)%2);
  204.             $query_sel "SELECT * FROM `".BIT_DB_PREFIX."boards_topics` WHERE `parent_id` = ?";
  205.             $isStored $this->mDb->getOne$query_selarray$this->mCommentContentId ) );
  206.             if$isStored {
  207.                 $result $this->mDb->associateUpdate'boards_topics'$pParamHash['topic_store']array'parent_id' => $this->mCommentContentId ) );
  208.             else {
  209.                 $pParamHash['topic_store']['parent_id'$this->mCommentContentId;
  210.                 $result $this->mDb->associateInsert'boards_topics'$pParamHash['topic_store');
  211.             }
  212.             $ret TRUE;
  213.         }
  214.         return $ret;
  215.     }
  216.  
  217.     /**
  218.      * This function locks a topic
  219.      */
  220.     function lock($state{
  221.         global $gBitSystem;
  222.         $ret FALSE;
  223.         if ($state==null || !is_numeric($state|| $state || $state<0{
  224.             $this->mErrors[]=("Invalid current state");
  225.         else {
  226.             $state (($state+1)%2);
  227.             $query_sel "SELECT * FROM `".BIT_DB_PREFIX."boards_topics` WHERE `parent_id` = ?";
  228.             $result $this->mDb->query$query_selarray$this->mCommentContentId ) );
  229.             if($result->RowCount()==0{
  230.                 $query_ins "INSERT INTO `".BIT_DB_PREFIX."boards_topics` (`parent_id`,`is_locked`) VALUES ( ?, ?)";
  231.                 $result $this->mDb->query$query_insarray$this->mCommentContentId$state ) );
  232.             else {
  233.                 $query_up "UPDATE `".BIT_DB_PREFIX."boards_topics` SET `is_locked` = ? WHERE `parent_id` = ?";
  234.                 $result $this->mDb->query$query_uparray$state$this->mCommentContentId ) );
  235.             }
  236.             $ret true;
  237.         }
  238.         return $ret;
  239.     }
  240.  
  241.     /**
  242.      * This function stickies a topic
  243.      */
  244.     function sticky($state{
  245.         global $gBitSystem;
  246.         $ret FALSE;
  247.         if ($state==null || !is_numeric($state|| $state || $state<0{
  248.             $this->mErrors[]=("Invalid current state");
  249.         else {
  250.             $state (($state+1)%2);
  251.             $query_sel "SELECT * FROM `".BIT_DB_PREFIX."boards_topics` WHERE `parent_id` = ?";
  252.             $result $this->mDb->query$query_selarray$this->mCommentContentId ) );
  253.             if($result->RowCount()==0{
  254.                 $query_ins "INSERT INTO `".BIT_DB_PREFIX."boards_topics` (`parent_id`,`is_sticky`) VALUES ( ?, ? )";
  255.                 $result $this->mDb->query$query_insarray$this->mCommentContentId$state ) );
  256.             else {
  257.                 $query_up "UPDATE `".BIT_DB_PREFIX."boards_topics` SET `is_sticky` = ? WHERE `parent_id` = ?";
  258.                 $result $this->mDb->query$query_uparray$state$this->mCommentContentId) );
  259.             }
  260.             $ret TRUE;
  261.         }
  262.         return $ret;
  263.     }
  264.  
  265.     /**
  266.      * This function moves a topic to a new messageboard
  267.      */
  268.     function moveTo($board_id{
  269.  
  270.         // start transaction
  271.         $this->mDb->StartTrans();
  272.  
  273.         // create a new comment letting people know it has beem moved
  274.         $lcom new LibertyComment();
  275.         $lcom_hash['edit']="The comments from: {$this->mInfo['title']} ({$this->mRootId}) have been is_moved to $board_id";
  276.         $lcom_hash['title']=$this->mInfo['title'];
  277.         $lcom_hash['parent_id']=$this->mInfo['th_root_id'];
  278.         $lcom_hash['root_id']=$this->mInfo['th_root_id'];
  279.         $lcom_hash['created']=$this->mInfo['flc_created'];
  280.         $lcom_hash['last_modified']=$this->mInfo['flc_last_modified'];
  281.         $lcom->storeComment($lcom_hash);
  282.  
  283.         // map the move to the topic table
  284.         $data array();
  285.         $data['parent_id']=$lcom->mContentId;
  286.         $data['is_moved']=$this->mRootId;
  287.         $this->mDb->associateInsertBIT_DB_PREFIX."boards_topics"$data );
  288.  
  289.         // move the comment we want to move to the target board
  290.         $query "UPDATE `".BIT_DB_PREFIX."liberty_comments` SET `root_id` = ?, `parent_id` = ?
  291.                   WHERE `thread_forward_sequence` LIKE '".sprintf("%09d."$this->mRootId)."%' AND `root_id`=`parent_id`";
  292.         $result $this->mDb->query$queryarray$board_id$board_id ) );
  293.  
  294.         $query "UPDATE `".BIT_DB_PREFIX."liberty_comments` SET `root_id` = ?
  295.                   WHERE `thread_forward_sequence` LIKE '".sprintf("%09d."$this->mRootId)."%'";
  296.         $result $this->mDb->query$queryarray$board_id ) );
  297.  
  298.         // end transaction
  299.         $this->mDb->CompleteTrans();
  300.  
  301.         return TRUE;
  302.     }
  303.  
  304.     /**
  305.      * This function generates a list of records from the liberty_content database for use in a list page
  306.      */
  307.     function getList( &$pParamHash ) {
  308.         global $gBitSystem, $gBitUser;
  309.         $BIT_DB_PREFIX = BIT_DB_PREFIX;
  310.         // this makes sure parameters used later on are set
  311.         LibertyMime::prepGetList( $pParamHash );
  312.  
  313.         $selectSql = $joinSql = $whereSql = '';
  314.         $bindVars = array();
  315.         $pParamHash['include_comments'] = 'y';
  316.         $this->getServicesSql'content_list_sql_function'$selectSql$joinSql$whereSql$bindVarsNULL$pParamHash );
  317.  
  318.         // this will set $find, $sort_mode, $max_records and $offset
  319.         extract$pParamHash );
  320.  
  321.         if(empty($find)) {
  322.         } elseif( is_array( $find ) ) {
  323.             // you can use an array of pages
  324.             $whereSql .= " AND flc.`title` IN( ".implode( ',',array_fill( 0,count( $find ),'?' ) )." )";
  325.             $bindVars = array_merge ( $bindVars, $find );
  326.         } elseif( is_string( $find ) ) {
  327.             // or a string
  328.             $bindVars[] = '%'strtoupper( $find ).'%';
  329.             $whereSql .= " AND UPPER( lc.`title` ) LIKE ?";
  330.         }
  331.  
  332.         // if we have the board's board_id (b) we use that, or if we have its content_id we can use that
  333.         if( (!empty( $pParamHash['b'] ) && $this->verifyId$pParamHash['b'))
  334.             || (!empty$pParamHash['content_id'&& $this->verifyId$pParamHash['content_id')) ) {
  335.             $joinSql .= " INNER JOIN `${BIT_DB_PREFIX}boards_map` map ON (map.`topic_content_id` = lcom.`root_id`)";
  336.             $joinSql .= " INNER JOIN `${BIT_DB_PREFIX}boards` b ON (b.`content_id` = map.`board_content_id`)";
  337.             if(!empty($pParamHash['b'])) {
  338.                 $whereSql .= " AND b.`board_id` = ?";
  339.                 $bindVars[] = (int)$pParamHash['b'];
  340.             }else{
  341.                 $whereSql .= " AND b.`content_id` = ?";
  342.                 $bindVars[] = (int)$pParamHash['content_id'];
  343.             }
  344.         }
  345.  
  346.         BitBoardTopic::loadTrack($selectSql,$joinSql);
  347.  
  348.         // use adodb's substr property
  349.         $substr = $this->mDb->substr();
  350.  
  351.         if $this->mDb->mType == 'firebird' {
  352.             $substrSql = "SUBSTRING(s_lcom.`thread_forward_sequence` FROM 1 FOR 10) LIKE SUBSTRING(lcom.`thread_forward_sequence` FROM 1 FOR 10)";
  353.         } else {
  354.             $substrSql = "$substr(s_lcom.`thread_forward_sequence`, 1, 10) LIKE $substr(lcom.`thread_forward_sequence`, 1, 10)";
  355.         }
  356.  
  357.         if ($gBitSystem->isFeatureActive('boards_posts_anon_moderation'&& !($gBitUser->hasPermission('p_boards_update'|| $gBitUser->hasPermission('p_boards_post_update'))) {
  358.             $whereSql .= " AND ((post.`is_approved` = 1) OR (lc.`user_id` >= 0))";
  359.         }
  360.         if ($gBitSystem->isFeatureActive('boards_posts_anon_moderation'&& ($gBitUser->hasPermission('p_boards_update'|| $gBitUser->hasPermission('p_boards_post_update'))) {
  361.             $selectSql .= ", ( SELECT COUNT(*)
  362.                                 FROM `${BIT_DB_PREFIX}liberty_comments` AS s_lcom
  363.                                     INNER JOIN `".BIT_DB_PREFIX."liberty_content` s_lc ON (s_lcom.`content_id` = s_lc.`content_id`)
  364.                                     LEFT JOIN  `${BIT_DB_PREFIX}boards_posts` s ON( s_lcom.`comment_id` = s.`comment_id` )
  365.                                 WHERE (".$substrSql.") AND ((s_lc.`user_id` < 0) AND (s.`is_approved` = 0 OR s.`is_approved` IS NULL))) AS unreg";
  366.             } else {
  367.                 $selectSql .= ", 0 AS unreg";
  368.             }
  369.  
  370.             $sort_sql = "flc.".$this->mDb->convertSortmode$sort_mode );
  371.  
  372.             $query "SELECT
  373.                         lc.`user_id` AS flc_user_id,
  374.                         lc.`created` AS flc_created,
  375.                         lc.`last_modified` AS flc_last_modified,
  376.                         lc.`title` AS title,
  377.                         lc.`content_id` AS flc_content_id,
  378.  
  379.                         COALESCE(post.`is_approved`,0) AS first_approved,
  380.                         lcom.`anon_name`,
  381.  
  382.                         th.`parent_id` AS th_first_id,
  383.                         COALESCE(th.`is_locked`,0) AS th_is_locked,
  384.                         COALESCE(th.`is_moved`,0) AS th_is_moved,
  385.                         COALESCE(th.`is_sticky`,0) AS th_is_sticky,
  386.  
  387.                         lcom.`comment_id` AS th_thread_id,
  388.                         lcom.`root_id` AS th_root_id,
  389.  
  390.                         lcom.`root_id` AS content_id,
  391.                         lc.`content_type_guid` AS content_type_guid,
  392.                         lc.`content_status_id` AS content_status_id,
  393.  
  394.                         (
  395.                             SELECT COUNT(*)
  396.                             FROM `".BIT_DB_PREFIX."liberty_comments` s_lcom
  397.                             INNER JOIN `".BIT_DB_PREFIX."liberty_content` s_lc ON (s_lcom.`content_id` = s_lc.`content_id`)
  398.                             WHERE (".$substrSql.")
  399.                         ) AS post_count,
  400.  
  401.                         (
  402.                             SELECT MAX(s_lc.created)
  403.                             FROM `".BIT_DB_PREFIX."liberty_comments` s_lcom
  404.                             INNER JOIN `".BIT_DB_PREFIX."liberty_content` s_lc ON (s_lcom.`content_id` = s_lc.`content_id`)
  405.                             WHERE (".$substrSql.")
  406.                         ) AS last_post
  407.  
  408.                         $selectSql
  409.                             FROM `${BIT_DB_PREFIX}liberty_comments` lcom
  410.                             INNER JOIN `${BIT_DB_PREFIX}liberty_content` lc ON( lc.`content_id` = lcom.`content_id` )
  411.                             LEFT JOIN `${BIT_DB_PREFIX}boards_topics` th ON (th.`parent_id`=lcom.`content_id`)
  412.                             LEFT JOIN `${BIT_DB_PREFIX}boards_posts` post ON (post.`comment_id` = lcom.`comment_id`)
  413.                             $joinSql
  414.                         WHERE
  415.                             lcom.`root_id`=lcom.`parent_id`
  416.                             $whereSql
  417.                         ORDER BY
  418.                             11 DESC,
  419.                             10 ASC,
  420.                             last_post DESC,
  421.                             lc.created DESC
  422.                         ";
  423.  
  424.         $query_cant  = "SELECT count(*)
  425.                         FROM `${BIT_DB_PREFIX}liberty_comments` lcom
  426.                             INNER JOIN `${BIT_DB_PREFIX}liberty_content` lc ON( lc.`content_id` = lcom.`content_id` )
  427.                             LEFT JOIN `${BIT_DB_PREFIX}boards_topics` th ON (th.`parent_id`=lcom.`content_id`)
  428.                             LEFT JOIN `${BIT_DB_PREFIX}boards_posts` post ON (post.`comment_id` = lcom.`comment_id`)
  429.                             $joinSql
  430.                         WHERE
  431.                             lcom.`root_id`=lcom.`parent_id`
  432.                             $whereSql";
  433.  
  434.         $result = $this->mDb->query$query$bindVars$max_records$offset );
  435.         $ret array();
  436.         while$res $result->fetchRow() ) {
  437.             if (empty($res['anon_name'])) $res['anon_name'] = "Anonymous";
  438.             if ($res['th_is_moved']>0) {
  439.                 $res['url']=BOARDS_PKG_URL."index.php?t=".$res['th_is_moved'];
  440.             } else {
  441.                 $res['url']=BOARDS_PKG_URL."index.php?t=".$res['th_thread_id'];
  442.             }
  443.             $llc_data = BitBoardTopic::getLastPost($res);
  444.             $res = array_merge($res,$llc_data);
  445.             BitBoardTopic::track($res);
  446.             $res['flip']=BitBoardTopic::getFlipFlop($res);
  447.             if (empty($res['title'])) {
  448.                 $res['title']="[Thread ".$res['th_thread_id']."]";
  449.             }
  450.             $ret[] = $res;
  451.         }
  452.         $pParamHash["cant"] = $this->mDb->getOne$query_cant$bindVars );
  453.         // add all pagination info to pParamHash
  454.         LibertyMime::postGetList$pParamHash );
  455.         return $ret;
  456.     }
  457.  
  458.     function getLastPost($data) {
  459.         global $gBitSystem;
  460.         if ( $this->mDb->mType == 'firebird' {
  461.             $substrSql = "SUBSTRING(lcom.`thread_forward_sequence` FROM 1 FOR 10)";
  462.         } else {
  463.             $substrSql = "".$this->mDb->substr()."(lcom.`thread_forward_sequence`, 1, 10)";
  464.         }
  465.         $whereSql = '';
  466.         if ($gBitSystem->isFeatureActive('boards_posts_anon_moderation')) {
  467.             $whereSql = " AND ((post.`is_approved` = 1) OR (lc.`user_id` >= 0))";
  468.         }
  469.         $BIT_DB_PREFIX = BIT_DB_PREFIX;
  470.         $query="SELECT lc.`last_modified` AS llc_last_modified, lc.`user_id` AS llc_user_id, lc.`content_id` AS llc_content_id,  lcom.`anon_name` AS l_anon_name
  471.                 FROM `".BIT_DB_PREFIX."liberty_comments` lcom
  472.                     INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON (lcom.`content_id` = lc.`content_id`)
  473.                     LEFT JOIN `${BIT_DB_PREFIX}boards_posts` post ON (post.`comment_id` = lcom.`comment_id`)
  474.                 WHERE (".$substrSql.") LIKE '".sprintf("%09d.",$data['th_thread_id'])."%' $whereSql
  475.                 ORDER BY lc.`last_modified` DESC
  476.         ";
  477.         $result = $this->mDb->getRow$query);
  478.         if (empty($result['l_anon_name'])) $result['l_anon_name'"Anonymous";
  479.         return $result;
  480.     }
  481.  
  482.     /**
  483.      * Generates the URL to the bitboard page
  484.      * @return the link to display the page.
  485.      */
  486.     public static function getDisplayUrlFromHash( &$pParamHash ) {
  487.         global $gBitSystem;
  488.         $ret = NULL;
  489.  
  490.         if( !empty( $pParamHash['topic_id'] ) && static::verifyId( $pParamHash['topic_id'] ) ) {
  491.             $topicId = $pParamHash['topic_id'];
  492.         } elseif( !empty( $pParamHash['th_thread_id'] ) && static::verifyId( $pParamHash['th_thread_id'] ) ) {
  493.             $topicId = $pParamHash['th_thread_id'];
  494.         }
  495.  
  496.         if( !empty( $topicId ) ) {
  497.             if( $gBitSystem->isFeatureActive'pretty_urls' || $gBitSystem->isFeatureActive'pretty_urls_extended' ) ) {
  498.                 $rewrite_tag = $gBitSystem->isFeatureActive'pretty_urls_extended' 'view/' '';
  499.                 $ret BOARDS_PKG_URL.$rewrite_tag."topic/".$topicId;
  500.             } else {
  501.                 $ret = BOARDS_PKG_URL."index.php?t=".$topicId;
  502.             }
  503.         }
  504.         return $ret;
  505.     }
  506.  
  507.     function isLocked($pThreadId=false) {
  508.         global $gBitSystem;
  509.         if (!$pThreadId) {
  510.             $pThreadId = $this->mCommentContentId;
  511.         } else {
  512.             $pThreadId=intval($pThreadId);
  513.         }
  514.         $ret = $gBitSystem->mDb->getOne("SELECT `is_locked` FROM `".BIT_DB_PREFIX."boards_topics` WHERE `parent_id` = ?"array$pThreadId ) );
  515.         return !empty($ret);
  516.     }
  517.  
  518.     function isLockedMsg($parent_id) {
  519.         // $parentComment = new LibertyComment(NULL,$parent_id);
  520.         // $topicId = $parentComment->mInfo['thread_forward_sequence'];
  521.         if (!empty($parent_id)) {
  522.             return BitBoardTopic::isLocked($parent_id);
  523.         }
  524.         return false;
  525.     }
  526.  
  527.     function isNotificationOn($pThreadId=false) {
  528.         global $gBitSystem, $gBitUser;
  529.         if ($gBitSystem->isPackageActive('boards'&& $gBitSystem->isFeatureActive('boards_thread_track')) {
  530.             if (!$pThreadId) {
  531.                 $pThreadId = $this->mRootId;
  532.             }
  533.             if (is_numeric($pThreadId)) {
  534.                 $topicId = sprintf("%09d.",$pThreadId);
  535.             }
  536.             return $gBitSystem->mDb->getOne("SELECT SUM(`notify`) FROM `".BIT_DB_PREFIX."boards_tracking` WHERE topic_id='$topicId'");
  537.         }
  538.         return false;
  539.     }
  540.  
  541.     function getNotificationData($pThreadId) {
  542.         global $gBitSystem, $gBitUser;
  543.         if ($gBitSystem->isPackageActive('boards'&& $gBitSystem->isFeatureActive('boards_thread_track')) {
  544.             if (!$pThreadId) {
  545.                 $pThreadId = $this->mRootId;
  546.             }
  547.             if (is_numeric($pThreadId)) {
  548.                 $topicId = sprintf("%09d.",$pThreadId);
  549.             }
  550.             $query = "SELECT uu.user_id, uu.email, uu.login, uu.real_name, trk.`track_date`, trk.`notify` AS track_notify, trk.`notify_date` AS track_notify_date
  551.                         FROM `".BIT_DB_PREFIX."boards_tracking` trk
  552.                             LEFT JOIN `".BIT_DB_PREFIX."users_users` uu ON( uu.`user_id` = trk.`user_id` )
  553.                         WHERE topic_id=?";
  554.  
  555.             $result = $gBitSystem->mDb->query$queryarray$topicId ) );
  556.             $ret array();
  557.             $ret['users']=array();
  558.             while$res $result->fetchRow() ) {
  559.                 $res['user'] =( isset( $res['real_name'] )$res['real_name'] : $res['login'] );
  560.                 $ret['users'][$res['login']] = $res;
  561.             }
  562.             $ret['topic'] = new BitBoardTopic(intval($topicId));
  563.             $ret['topic']->load();
  564.             return $ret;
  565.         }
  566.  
  567.         return array();
  568.     }
  569.  
  570.     function sendNotification($user) {
  571.         global $gBitSystem;
  572.         //return;
  573.         $mail_subject"Topic Reply Notification - ".$this->mInfo['title'];
  574.         $host 'http://'.$_SERVER['HTTP_HOST'];
  575.         //TODO: use a template for this
  576.         $mail_message "Hello ".$user['user'].",
  577.  
  578.             You are receiving this email because you are watching the topic, \"".$this->mInfo['title']."\" at ".$gBitSystem->getConfig('site_title',"[Bitweaver Site]").".
  579.             This topic has received a reply since your last visit.
  580.             You can use the following link to view the replies made, no more notifications will be sent until you visit the topic.
  581.  
  582.             ".$host.$this->getDisplayUrl()."
  583.  
  584.             If you no longer wish to watch this topic you can either click the \"Stop watching this topic link\" found at the topic of the topic above, or by clicking the following link after logging on:
  585.  
  586.             ".$host.$this->getDisplayUrl()."&notify=1";
  587.  
  588.         @mail($user['email']$mail_subject $mail_message"From: ".$gBitSystem->getConfig'site_sender_email' )."\r\nContent-type: text/plain;charset=utf-8\r\n");
  589.  
  590.         $data array(
  591.             'notify_date'=>time(),
  592.         );
  593.  
  594.         $key array(
  595.             'user_id' =>$user['user_id'],
  596.             'topic_id' =>sprintf("%09d.",$this->mRootId),
  597.         );
  598.  
  599.         $this->mDb->associateUpdate(BIT_DB_PREFIX."boards_tracking",$data,$key);
  600.     }
  601.  
  602.     function getFlipFlop($arr=false) {
  603.         if(! $arr) {
  604.             $arr = $this->mInfo;
  605.         }
  606.         global $gBitSmarty, $gBitSystem, $gBitUser;
  607.  
  608.         $flip['is_locked']['state']=$arr['th_is_locked'];
  609.         $flip['is_locked']['req']=2;
  610.         $flip['is_locked']['id']=$arr['th_thread_id'];
  611.         $flip['is_locked']['idname']='t';
  612.         $flip['is_locked']['up']='icon-lock';
  613.         $flip['is_locked']['upname']=tra('Thread Locked');
  614.         $flip['is_locked']['down']='icon-unlock';
  615.         $flip['is_locked']['downname']=tra('Thread Unlocked');
  616.         $flip['is_locked']['perm']='p_boards_update';
  617.  
  618.         $flip['is_sticky']['state']=$arr['th_is_sticky'];
  619.         $flip['is_sticky']['req'] = 3;
  620.         $flip['is_sticky']['id']=$arr['th_thread_id'];
  621.         $flip['is_sticky']['idname']='t';
  622.         $flip['is_sticky']['up']='icon-exclamation-sign';
  623.         $flip['is_sticky']['upname']=tra('Sticky Thread');
  624.         $flip['is_sticky']['down']='icon-list';
  625.         $flip['is_sticky']['downname']=tra('Non Sticky Thread');
  626.         $flip['is_sticky']['perm']='p_boards_update';
  627.  
  628.         if ($gBitSystem->isFeatureActive('boards_thread_notification'&& $gBitUser->isRegistered()) {
  629.             $flip['notify']['state']=($arr['notify']['on'])*1;
  630.             $flip['notify']['req']=5;
  631.             $flip['notify']['id']=$arr['th_thread_id'];
  632.             $flip['notify']['idname']='t';
  633.             $flip['notify']['up']='icon-bell-alt';
  634.             $flip['notify']['upname']=tra('Reply Notification');
  635.             $flip['notify']['down']='icon-bell';
  636.             $flip['notify']['downname']=tra('Reply Notification Disabled');
  637.             $flip['notify']['perm']='p_boards_read';
  638.         }
  639.         if ($gBitSystem->isFeatureActive('boards_thread_track'&& $gBitUser->isRegistered()) {
  640.             $flip['new']['state']=($arr['track']['on']&&$arr['track']['mod'])*1;
  641.             $flip['new']['req']=4;
  642.             $flip['new']['id']=$arr['th_thread_id'];
  643.             $flip['new']['idname']='t';
  644.             $flip['new']['up']='icon-asterisk';
  645.             $flip['new']['upname']=tra('New Posts');
  646. //            $flip['new']['down']='icon-comment-alt';
  647. //            $flip['new']['downname']=tra('No new posts');
  648.             $flip['new']['perm']='p_boards_read';
  649.         }
  650.  
  651.         return $flip;
  652.     }
  653.  
  654.     function readTopic() {
  655.         global $gBitUser, $gBitSystem;
  656.         if ($gBitSystem->isFeatureActive('boards_thread_track'&& $gBitUser->isRegistered()) {
  657.             $topicId = sprintf("%09d.",$this->mRootId);
  658.             $BIT_DB_PREFIX BIT_DB_PREFIX;
  659.             $c $this->mDb->getOne("SELECT COUNT(*) FROM `".BIT_DB_PREFIX."boards_tracking` WHERE user_id=? AND topic_id='$topicId'",array($gBitUser->mUserId));
  660.  
  661.             $data array(
  662.             'user_id' =>$gBitUser->mUserId,
  663.             'topic_id' =>$topicId,
  664.             'track_date'=>time(),
  665.             );
  666.  
  667.             if ($c == 0{
  668.                 $this->mDb->associateInsert(BIT_DB_PREFIX."boards_tracking",$data);
  669.             } else {
  670.                 $key = array(
  671.                 'user_id' =>$gBitUser->mUserId,
  672.                 'topic_id' =>$topicId,
  673.                 );
  674.                 $this->mDb->associateUpdate(BIT_DB_PREFIX."boards_tracking",$data,$key);
  675.             }
  676.             $this->mInfo['track']['mod']=false;
  677.         }
  678.     }
  679.  
  680.     function readTopicSet($pState) {
  681.         global $gBitUser, $gBitSystem;
  682.         if ($gBitSystem->isFeatureActive('boards_thread_track'&& $gBitUser->isRegistered()) {
  683.             $topicId = sprintf("%09d.",$this->mRootId);
  684.             $ret FALSE;
  685.             if ($pState==null || !is_numeric($pState|| $pState || $pState<0{
  686.                 $this->mErrors[]=("Invalid current state");
  687.             } else {
  688.                 $pState = (($pState+1)%2);
  689.                 if ($pState == 0) {
  690.                     $this->readTopic();
  691.                 } else {
  692.                     $this->mDb->query("DELETE FROM `".BIT_DB_PREFIX."boards_tracking` WHERE user_id=$gBitUser->mUserId AND topic_id='$topicId'");
  693.                 }
  694.                 $ret = true;
  695.             }
  696.             return $ret;
  697.         }
  698.     }
  699.  
  700.     function notify($pState) {
  701.         global $gBitUser, $gBitSystem;
  702.         if ($gBitSystem->isFeatureActive('boards_thread_track'&& $gBitUser->isRegistered()) {
  703.             $topicId = sprintf("%09d.",$this->mRootId);
  704.             $ret FALSE;
  705.             if ($pState==null || !is_numeric($pState|| $pState || $pState<0{
  706.                 $this->mErrors[]=("Invalid current state");
  707.             } else {
  708.                 $pState = (($pState+1)%2);
  709.                 $query_sel = "SELECT * FROM `".BIT_DB_PREFIX."boards_tracking` WHERE user_id=$gBitUser->mUserId AND topic_id='$topicId'";
  710.                 $data = array(
  711.                 'user_id' =>$gBitUser->mUserId,
  712.                 'topic_id' =>$topicId,
  713.                 'notify'=>$pState,
  714.                 );
  715.                 $c $this->mDb->getOne$query_sel );
  716.                 if ($c == 0{
  717.                     $this->mDb->associateInsert(BIT_DB_PREFIX."boards_tracking",$data);
  718.                 } else {
  719.                     $key = array(
  720.                     'user_id' =>$gBitUser->mUserId,
  721.                     'topic_id' =>$topicId,
  722.                     );
  723.                     $this->mDb->associateUpdate(BIT_DB_PREFIX."boards_tracking",$data,$key);
  724.                 }
  725.                 $ret = true;
  726.             }
  727.             return $ret;
  728.         }
  729.     }
  730.  
  731.     function loadTrack(&$selectSql,&$joinSql) {
  732.         global $gBitUser, $gBitSystem;
  733.         if($gBitUser->isRegistered(&& ($gBitSystem->isFeatureActive('boards_thread_track'|| $gBitSystem->isFeatureActive('boards_thread_notify'))) {
  734.             $selectSql .= ", trk.`track_date`,  trk.`notify` AS track_notify, trk.`notify_date` AS track_notify_date ";
  735.             $joinSql .= " LEFT JOIN `".BIT_DB_PREFIX."boards_tracking` trk ON (trk.`topic_id`=lcom.`thread_forward_sequence` AND ( trk.`user_id` = ".$gBitUser->mUserId." OR trk.`user_id` IS NULL ) ) ";
  736.         }
  737.     }
  738.  
  739.     function track(&$res) {
  740.         global $gBitUser, $gBitSystem;
  741.         if($gBitUser->isRegistered(&& $gBitSystem->isFeatureActive('boards_thread_track'&& $res['th_is_moved']<=0{
  742.             $res['track']['on'] = true;
  743.             $res['track']['date'] = $res['track_date'];
  744.             if (empty($res['llc_last_modified'])) {
  745.                 $res['llc_last_modified']=0;
  746.             }
  747.             if ($res['llc_last_modified']>$res['track_date']) {
  748.                 $res['track']['mod'] = true;
  749.             } else {
  750.                 $res['track']['mod'] = false;
  751.             }
  752.         }  else {
  753.             $res['track']['on'] = false;
  754.         }
  755.         unset($res['track_date']);
  756.         if($gBitUser->isRegistered(&& $gBitSystem->isFeatureActive('boards_thread_notification'&& $res['th_is_moved']<=0{
  757.             $res['notify']['on'] = (!empty($res['track_notify']));
  758.             if ($res['notify']['on']) {
  759.                 $res['notify']['date']=$res['track_notify_date'];
  760.             }
  761.         } else {
  762.             $res['notify']['on'] = false;
  763.         }
  764.         unset($res['track_notify_date']);
  765.         unset($res['track_notify']);
  766.     }
  767.  
  768.     function getRootObj(){
  769.         if ( !is_object( $this->mRootObj && !empty$this->mInfo['root_id') ){
  770.             if ( $obj = LibertyBase::getLibertyObject( $this->mInfo['root_id') ) {
  771.                 $this->mRootObj $obj;
  772.             }
  773.         }
  774.         return $this->mRootObj;
  775.     }
  776. }

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