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

Source for file BitBoard.php

Documentation is available at BitBoard.php

  1. <?php
  2. /**
  3.  * $Header$
  4.  * $Id$
  5.  *
  6.  * BitBoard 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.'LibertyMime.php' );
  18.  
  19. /**
  20. * This is used to uniquely identify the object
  21. */
  22. define'BITBOARD_CONTENT_TYPE_GUID''bitboard' );
  23.  
  24. /**
  25.  * @package boards
  26.  */
  27. class BitBoard extends LibertyMime {
  28.     /**
  29.     * Primary key for our mythical BitBoard class object & table
  30.     * @public
  31.     */
  32.     var $mBitBoardId;
  33.  
  34.     /**
  35.     * During initialisation, be sure to call our base constructors
  36.     **/
  37.  
  38.     function BitBoard$pBitBoardId=NULL$pContentId=NULL {
  39.         parent::__construct();
  40.         $this->mBitBoardId = $pBitBoardId;
  41.         $this->mContentId = $pContentId;
  42.         $this->mContentTypeGuid = BITBOARD_CONTENT_TYPE_GUID;
  43.         $this->registerContentTypeBITBOARD_CONTENT_TYPE_GUIDarray(
  44.                 'content_type_guid' => BITBOARD_CONTENT_TYPE_GUID,
  45.                 'content_name' => 'Message Board',
  46.                 'handler_class' => 'BitBoard',
  47.                 'handler_package' => 'boards',
  48.                 'handler_file' => 'BitBoard.php',
  49.                 'maintainer_url' => 'http://www.bitweaver.org'
  50.         ));
  51.  
  52.         // Permission setup
  53.         $this->mViewContentPerm  = 'p_boards_read';
  54.         $this->mCreateContentPerm  = 'p_boards_create';
  55.         $this->mUpdateContentPerm  = 'p_boards_update';
  56.         $this->mAdminContentPerm = 'p_boards_admin';
  57.         $this->mExpungeContentPerm = 'p_boards_remove';
  58.     }
  59.  
  60.     /**
  61.     * Load the data from the database
  62.     * @param pParamHash be sure to pass by reference in case we need to make modifcations to the hash
  63.     ***/
  64.     function load$pContentId NULL$pPluginParams NULL {
  65.         if$this->verifyId$this->mBitBoardId || $this->verifyId$this->mContentId ) ) {
  66.             // LibertyContent::load()assumes you have joined already, and will not execute any sql!
  67.             // This is a significant performance optimization
  68.             $lookupColumn $this->verifyId$this->mBitBoardId 'board_id' 'content_id';
  69.             $bindVars array();
  70.             $selectSql $joinSql $whereSql '';
  71.             array_push$bindVars$lookupId @BitBase::verifyId$this->mBitBoardId $this->mBitBoardId : $this->mContentId );
  72.             $this->getServicesSql'content_load_sql_function'$selectSql$joinSql$whereSql$bindVars );
  73.  
  74.             $query "SELECT s.*, lc.*, " .
  75.             "uue.`login` AS modifier_user, uue.`real_name` AS modifier_real_name, " .
  76.             "uuc.`login` AS creator_user, uuc.`real_name` AS creator_real_name " .
  77.             "$selectSql .
  78.             "FROM `".BIT_DB_PREFIX."boards` s " .
  79.             "INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON( lc.`content_id` = s.`content_id` ) $joinSql.
  80.             "LEFT JOIN `".BIT_DB_PREFIX."users_users` uue ON( uue.`user_id` = lc.`modifier_user_id` )" .
  81.             "LEFT JOIN `".BIT_DB_PREFIX."users_users` uuc ON( uuc.`user_id` = lc.`user_id` )" .
  82.             "WHERE s.`$lookupColumn`=? $whereSql";
  83.             $result $this->mDb->query$query$bindVars );
  84.  
  85.             if$result && $result->numRows() ) {
  86.                 $this->mInfo = $result->fields;
  87.                 $this->mContentId = $result->fields['content_id'];
  88.                 $this->mBitBoardId = $result->fields['board_id'];
  89.  
  90.                 $this->mInfo['creator'=isset$result->fields['creator_real_name')$result->fields['creator_real_name'$result->fields['creator_user');
  91.                 $this->mInfo['editor'=isset$result->fields['modifier_real_name')$result->fields['modifier_real_name'$result->fields['modifier_user');
  92.                 $this->mInfo['display_url'$this->getDisplayUrl();
  93.                 $this->mInfo['parsed_data'$this->parseData();
  94.  
  95.                 LibertyMime::load();
  96.             }
  97.         }
  98.         returncount$this->mInfo ) );
  99.     }
  100.  
  101.     function lookupByMigrateBoard$pMigrateBoardId {
  102.         global $gBitDb;
  103.         $ret NULL;
  104.         ifBitBase::verifyId$pMigrateBoardId ) ) {
  105.             $ret $gBitDb->getOne"SELECT `board_id` FROM `".BIT_DB_PREFIX."boards` bb WHERE `migrate_board_id`=?"array$pMigrateBoardId ) );
  106.         }
  107.         return $ret;
  108.     }
  109.  
  110.     /**
  111.     * Any method named Store inherently implies data will be written to the database
  112.     * @param pParamHash be sure to pass by reference in case we need to make modifcations to the hash
  113.     *  This is the ONLY method that should be called in order to store( create or update )an bitboard!
  114.     *  It is very smart and will figure out what to do for you. It should be considered a black box.
  115.     *
  116.     * @param array pParams hash of values that will be used to store the page
  117.     *
  118.     * @return bool TRUE on success, FALSE if store could not occur. If FALSE, $this->mErrors will have reason why
  119.     *
  120.     * @access public
  121.     ***/
  122.     function store&$pParamHash {
  123.         if$this->verify$pParamHash )&& LibertyMime::store$pParamHash ) ) {
  124.             $table BIT_DB_PREFIX."boards";
  125.             $this->mDb->StartTrans();
  126.             if$this->mBitBoardId {
  127.                 $locId array"board_id" => $pParamHash['board_id');
  128.                 $result $this->mDb->associateUpdate$table$pParamHash['board_store']$locId );
  129.             else {
  130.                 $pParamHash['board_store']['content_id'$pParamHash['content_id'];
  131.                 if@$this->verifyId$pParamHash['board_id') ) {
  132.                     // if pParamHash['board_id'] is set, some is requesting a particular board_id. Use with caution!
  133.                     $pParamHash['board_store']['board_id'$pParamHash['board_id'];
  134.                 else {
  135.                     $pParamHash['board_store']['board_id'$this->mDb->GenID'boards_board_id_seq' );
  136.                 }
  137.                 $this->mBitBoardId = $pParamHash['board_store']['board_id'];
  138.  
  139.                 $result $this->mDb->associateInsert$table$pParamHash['board_store');
  140.                 $result $this->mDb->associateInsertBIT_DB_PREFIX."boards_map",array('board_content_id'=>$pParamHash['board_store']['content_id'],'topic_content_id'=>$pParamHash['board_store']['content_id']));
  141.                 if!empty$pParamHash['boards_mailing_list') ) {
  142.                     global $gBitSystem$gBitUser;
  143.                     require_onceUTIL_PKG_PATH.'mailman_lib.php' );
  144.                     if$gBitSystem->getConfig'boards_sync_mail_server' ) ) {
  145.                         if!($error mailman_newlistarray'listname' => $pParamHash['boards_mailing_list']'listhost' => $gBitSystem->getConfig'boards_email_host'$gBitSystem->getConfig'kernel_server_name' ) )'admin-password'=>$pParamHash['boards_mailing_list_password']'listadmin-addr'=>$gBitUser->getField'email' ) ) )) ) {
  146.                             $this->storePreference'boards_mailing_list'!empty$pParamHash['boards_mailing_list'$pParamHash['boards_mailing_list'NULL );
  147.                             $this->storePreference'boards_mailing_list_password'$pParamHash['boards_mailing_list_password');
  148.                             // Subscribe the owner
  149.                             mailman_addmember$this->getPreference'boards_mailing_list')$gBitUser->getField('email') );
  150.                             // If we have an inbox then subscribe it as a moderator
  151.                             if$this->getBoardSyncInbox() ) {
  152.                                 mailman_addmember$this->getPreference'boards_mailing_list' )$this->getBoardSyncInbox() );
  153.                                 mailman_setmoderator$this->getPreference'boards_mailing_list' )$this->getBoardSyncInbox() );
  154.                             }
  155.                             $this->storePreference'board_sync_list_address'$this->getBoardMailingList() );
  156.                         else {
  157.                             $this->mErrors['mailing_list'$error;
  158.                         }
  159.                     }
  160.                 }
  161.             }
  162.  
  163.             ifcount$this->mErrors == {
  164.                 $this->mDb->CompleteTrans();
  165.                 $this->load();
  166.             else {
  167.                 $this->mDb->RollbackTrans();
  168.                 $this->mContentId = NULL;
  169.                 $this->mBitBoardId = NULL;
  170.             }
  171.         }
  172.         returncount$this->mErrors )== );
  173.     }
  174.  
  175.     /**
  176.     * Make sure the data is safe to store
  177.     * @param pParamHash be sure to pass by reference in case we need to make modifcations to the hash
  178.     *  This function is responsible for data integrity and validation before any operations are performed with the $pParamHash
  179.     *  NOTE: This is a PRIVATE METHOD!!!! do not call outside this class, under penalty of death!
  180.     *
  181.     * @param array pParams reference to hash of values that will be used to store the page, they will be modified where necessary
  182.     *
  183.     * @return bool TRUE on success, FALSE if verify failed. If FALSE, $this->mErrors will have reason why
  184.     *
  185.     * @access private
  186.     ***/
  187.     function verify&$pParamHash {
  188.         // make sure we're all loaded up of we have a mBitBoardId
  189.         if$this->verifyId$this->mBitBoardId && empty$this->mInfo ) ) {
  190.             $this->load();
  191.         }
  192.  
  193.         if@$this->verifyId$this->mInfo['content_id') ) {
  194.             $pParamHash['content_id'$this->mInfo['content_id'];
  195.         }
  196.  
  197.         // It is possible a derived class set this to something different
  198.         ifempty$pParamHash['content_type_guid') ) {
  199.             $pParamHash['content_type_guid'$this->mContentTypeGuid;
  200.         }
  201.  
  202.         if@$this->verifyId$pParamHash['content_id') ) {
  203.             $pParamHash['board_store']['content_id'$pParamHash['content_id'];
  204.         }
  205.  
  206.         if@$this->verifyId$pParamHash['migrate_board_id') ) {
  207.             $pParamHash['board_store']['migrate_board_id'$pParamHash['migrate_board_id'];
  208.         }
  209. /* board description seems to have been removed in favor of liberty_content data
  210.         // check some lengths, if too long, then truncate
  211.         if( $this->isValid() && !empty( $this->mInfo['description'] ) && empty( $pParamHash['description'] ) ) {
  212.             // someone has deleted the description, we need to null it out
  213.             $pParamHash['board_store']['description'] = '';
  214.         } else if( empty( $pParamHash['description'] ) ) {
  215.             unset( $pParamHash['description'] );
  216.         } else {
  217.             $pParamHash['board_store']['description'] = substr( $pParamHash['description'], 0, 200 );
  218.         }
  219. */
  220.         if!empty$pParamHash['data') ) {
  221.             $pParamHash['edit'$pParamHash['data'];
  222.         }
  223.  
  224.         // check for name issues, first truncate length if too long
  225.         if!empty$pParamHash['title') ) {
  226.             ifempty$this->mBitBoardId ) ) {
  227.                 ifempty$pParamHash['title') ) {
  228.                     $this->mErrors['title''You must enter a name for this page.';
  229.                 else {
  230.                     $pParamHash['content_store']['title'substr$pParamHash['title']0160 );
  231.                 }
  232.             else {
  233.                 $pParamHash['content_store']['title'=isset$pParamHash['title') )substr$pParamHash['title']0160 )'';
  234.             }
  235.         else ifempty$pParamHash['title') ) {
  236.             // no name specified
  237.             $this->mErrors['title''You must specify a name';
  238.         }
  239.  
  240.         returncount$this->mErrors )== );
  241.     }
  242.  
  243.  
  244.     /**
  245.      * Prepare data for preview
  246.      */
  247.     function preparePreview$pParamHash {
  248.         global $gBitSystem$gBitUser;
  249.  
  250.         ifempty$pParamHash['user_id') ) {
  251.             $pParamHash['user_id'$gBitUser->mUserId;
  252.         }
  253.  
  254.         ifisset$pParamHash["title") ) {
  255.             $this->mInfo["title"$pParamHash["title"];
  256.         }
  257.  
  258.         ifisset$pParamHash["description") ) {
  259.             $this->mInfo["description"$pParamHash["description"];
  260.         }
  261.  
  262.         ifisset$pParamHash["format_guid") ) {
  263.             $this->mInfo['format_guid'$pParamHash["format_guid"];
  264.         }
  265.  
  266.         ifisset$pParamHash["edit") ) {
  267.             $this->mInfo["data"$pParamHash["edit"];
  268.             $this->mInfo['parsed_data'$this->parseData();
  269.         }
  270.     }
  271.  
  272.  
  273.     /**
  274.     * This function removes a bitboard entry
  275.     **/
  276.  
  277.     function expunge({
  278.         $ret FALSE;
  279.         if$this->isValid() ) {
  280.             $this->mDb->StartTrans();
  281.             $mailingList $this->getPreference'boards_mailing_list' );
  282.             $query "DELETE FROM `".BIT_DB_PREFIX."boards_map` WHERE `board_content_id` = ?";
  283.             $result $this->mDb->query$queryarray$this->mContentId ) );
  284.             $query "DELETE FROM `".BIT_DB_PREFIX."boards` WHERE `content_id` = ?";
  285.             $result $this->mDb->query$queryarray$this->mContentId ) );
  286.             ifLibertyMime::expunge() ) {
  287.                 if$mailingList {
  288.                     require_onceUTIL_PKG_PATH.'mailman_lib.php' );
  289.                     if$error mailman_rmlist$mailingList ) ) {
  290.                         $this->mErrors['mailing_list'$error;
  291.                     }
  292.                 }
  293.                 $ret TRUE;
  294.                 $this->mDb->CompleteTrans();
  295.             else {
  296.                 $this->mDb->RollbackTrans();
  297.             }
  298.         }
  299.         return $ret;
  300.     }
  301.  
  302.     /**
  303.     * Make sure bitboard is loaded and valid
  304.     **/
  305.  
  306.     function isValid({
  307.         return$this->verifyId$this->mBitBoardId && $this->verifyId$this->mContentId ) );
  308.     }
  309.  
  310.     function getAllMap({
  311.         $b new BitBoard();
  312.         $listHash array();
  313.         $l $b->getList($listHash);
  314.         $ret array();
  315.         foreach ($l as $k => $boardd{
  316.             $board new BitBoard($boardd['board_id']);
  317.             $board->mInfo=$boardd;
  318.             $ret['map'][$k]=$boardd;
  319.             $ret['map'][$k]['map'$board->getMap();
  320.             $ret['map'][$k]['integrity'$board->verifyIntegrity();
  321.         }
  322.         // reorganise unmapped content for better display
  323.         $umapped $b->getUnMapped();
  324.         foreach$umapped as $key => $content {
  325.             $umap[$content['content_name']][$key$content;
  326.         }
  327.         $ret['umap'$umap;
  328.         return $ret;
  329.     }
  330.  
  331.     function getUnMapped({
  332.         global $gBitSystem;
  333.         $ret NULL;
  334.         $sql "SELECT
  335.             lc.`title`,
  336.             lc.`content_id`,
  337.             lct.`content_name`, (
  338.             SELECT count(*)
  339.                 FROM `".BIT_DB_PREFIX."liberty_comments` lcom
  340.                 WHERE lcom.`root_id`=lcom.`parent_id` AND lcom.`root_id`=lc.`content_id`
  341.             ) AS thread_count
  342.             FROM `".BIT_DB_PREFIX."liberty_content` lc
  343.                 INNER JOIN `".BIT_DB_PREFIX."liberty_content_types` lct ON (lc.`content_type_guid`=lct.`content_type_guid`)
  344.             WHERE lc.`content_id` NOT IN (
  345.                 SELECT    lc.`content_id` AS content_id
  346.                     FROM `".BIT_DB_PREFIX."boards` b
  347.                     INNER JOIN `".BIT_DB_PREFIX."liberty_content` blc ON (blc.`content_id`=b.`content_id`)
  348.                     INNER JOIN  `".BIT_DB_PREFIX."boards_map` map ON (map.`board_content_id`= blc.`content_id`)
  349.                     INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON (lc.`content_id`=map.`topic_content_id`)
  350.                 )
  351.                 AND lc.`content_type_guid` != 'pigeonholes'
  352.                 AND lc.`content_type_guid` != 'bitboard'
  353.                 AND lc.`content_type_guid` != 'bitcomment'
  354.                 AND lc.`title` != ''
  355.             ORDER BY lc.`content_type_guid`, lc.`title`
  356.             ";
  357.         $rs $this->mDb->query$sql );
  358.         while$row $rs->fetchRow() ) {
  359.             $ret[$row['content_id']] $row;
  360.         }
  361.         return $ret;
  362.     }
  363.  
  364.     function addContent($content_id{
  365.         if (@BitBase::verifyId($content_id)) {
  366.             $data array(
  367.             'board_content_id'=>$this->mContentId,
  368.             'topic_content_id'=>$content_id,
  369.             );
  370.             $this->mDb->associateInsertBIT_DB_PREFIX."boards_map",$data);
  371.         }
  372.     }
  373.  
  374.     function removeContent($content_id{
  375.         if (@BitBase::verifyId($content_id&& @BitBase::verifyId($this->mContentId)) {
  376.             $sql "DELETE FROM `".BIT_DB_PREFIX."boards_map` WHERE `board_content_id` = ? AND `topic_content_id` = ?";
  377.             $result $this->mDb->query$sqlarray$this->mContentId,$content_id ) );
  378.         }
  379.     }
  380.  
  381.     function verifyIntegrity({
  382.         global $gBitSystem;
  383.         $ret false;
  384.         if$this->isValid() ) {
  385.             $sql "SELECT
  386.                 COUNT(*)
  387.                 FROM `".BIT_DB_PREFIX."boards` b
  388.                 INNER JOIN  `".BIT_DB_PREFIX."boards_map` map ON (map.`board_content_id`= b.`content_id`)
  389.                 WHERE b.`board_id`=? AND map.`board_content_id` = map.`topic_content_id`
  390.             ";
  391.             $count $this->mDb->getOne$sqlarray$this->mBitBoardId ));
  392.             return ($count==1);
  393.         }
  394.         return $ret;
  395.     }
  396.  
  397.     function fixContentMap({
  398.         if$this->isValid(&& @BitBase::verifyId($this->mContentId)) {
  399.             $this->removeContent($this->mContentId);
  400.             $this->addContent($this->mContentId);
  401.         }
  402.     }
  403.  
  404.     function lookupMapRev($content_id{
  405.         global $gBitDb;
  406.         $ret NULL;
  407.         if (@BitBase::verifyId($content_id)) {
  408.             $sql "SELECT `board_content_id` FROM `".BIT_DB_PREFIX."boards_map` map WHERE map.`topic_content_id`=?";
  409.             $ret $gBitDb->getOne$sqlarray$content_id ));
  410.         }
  411.         return $ret;
  412.     }
  413.  
  414.     function getMap({
  415.         global $gBitSystem;
  416.         $ret NULL;
  417.         if$this->isValid() ) {
  418.             $sql "SELECT
  419.             lc.`title` AS t_title,
  420.             lc.`content_id` AS t_content_id,
  421.             lct.`content_name` AS t_content_name,
  422.             blc.`title` AS b_title,
  423.             blc.`content_id` AS b_content_id,
  424.             b.`board_id` AS b_board_id, (
  425.                 SELECT count(*)
  426.                     FROM `".BIT_DB_PREFIX."liberty_comments` lcom
  427.                     WHERE lcom.`root_id`=lcom.`parent_id` AND lcom.`root_id`=lc.`content_id`
  428.                 ) AS thread_count,
  429.             ((blc.`content_id`- lc.`content_id`)*(blc.`content_id`- lc.`content_id`)) AS order_key
  430.                     FROM `".BIT_DB_PREFIX."boards` b
  431.                     INNER JOIN `".BIT_DB_PREFIX."liberty_content` blc ON (blc.`content_id`=b.`content_id`)
  432.                     INNER JOIN  `".BIT_DB_PREFIX."boards_map` map ON (map.`board_content_id`= blc.`content_id`)
  433.                     INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON (lc.`content_id`=map.`topic_content_id`)
  434.                     INNER JOIN `".BIT_DB_PREFIX."liberty_content_types` lct ON (lc.`content_type_guid`=lct.`content_type_guid`)
  435.                     WHERE b.`board_id`=? AND map.`board_content_id`!=map.`topic_content_id`
  436.                     ORDER BY order_key
  437.                     ";
  438.             $rs $this->mDb->query$sqlarray$this->mBitBoardId ));
  439.             while$row $rs->fetchRow() ) {
  440.                 $ret[$row['t_content_id']] $row;
  441.             }
  442.         }
  443.         return $ret;
  444.     }
  445.  
  446.     public static function prepGetList&$pParamHash {
  447.         ifempty$pParamHash['sort_mode') ) {
  448.             // default sort_mode for boards is alphabetical
  449.             $pParamHash['sort_mode''title_asc';
  450.         }
  451.         LibertyContent::prepGetList$pParamHash );
  452.     }
  453.  
  454.     /**
  455.     * This function generates a list of records from the liberty_content database for use in a list page
  456.     **/
  457.  
  458.     function getList&$pParamHash {
  459.         global $gBitSystem$gBitUser;
  460.         // this makes sure parameters used later on are set
  461.         $this->prepGetList$pParamHash );
  462.  
  463.         $selectSql $joinSql $whereSql '';
  464.         $bindVars array();
  465.         array_push$bindVars$this->mContentTypeGuid );
  466.         $this->getServicesSql'content_list_sql_function'$selectSql$joinSql$whereSql$bindVars );
  467.  
  468.         // this will set $find, $sort_mode, $max_records and $offset
  469.         extract$pParamHash );
  470.  
  471.         ifis_array$find ) ) {
  472.             // you can use an array of pages
  473.             $whereSql .= " AND lc.`title` IN( ".implode',',array_fill0,count$find ),'?' ) )." )";
  474.             $bindVars array_merge $bindVars$find );
  475.         elseifis_string$find ) ) {
  476.             // or a string
  477.             $whereSql .= " AND UPPER( lc.`title` )like ? ";
  478.             $bindVars['%' strtoupper$find )'%';
  479.         }
  480.  
  481.         $pagination=true;
  482.         if (!empty($pParamHash['paginationOff'])) {
  483.             $pagination=false;
  484.         }
  485.  
  486.         if (!empty($pParamHash['boards']&& is_array($pParamHash['boards'])) {
  487.             $whereSql .= " AND lc.`content_id` IN ( ".implode',',array_fill0,count$pParamHash['boards'),'?' ) )." )";
  488.             $bindVars array_merge $bindVars$pParamHash['boards');
  489.         }
  490.         if (!empty($pParamHash['nboards']&& is_array($pParamHash['nboards'])) {
  491.             $whereSql .= " AND lc.`content_id` NOT IN ( ".implode',',array_fill0,count$pParamHash['nboards'),'?' ) )." )";
  492.             $bindVars array_merge $bindVars$pParamHash['nboards');
  493.         }
  494.  
  495.         $track $gBitSystem->isFeatureActive('boards_thread_track');
  496.         $track true;
  497.         if ($track{
  498.             $selectSql .= ", (
  499.                     SELECT COUNT(trk.`topic_id`)
  500.                     FROM `".BIT_DB_PREFIX."boards_map` map
  501.                     INNER JOIN `".BIT_DB_PREFIX."liberty_comments` lcom ON (map.`topic_content_id` = lcom.`root_id`)
  502.                     INNER JOIN `".BIT_DB_PREFIX."boards_tracking` trk ON (trk.`topic_id` = lcom.`thread_forward_sequence`)
  503.                     WHERE lcom.`root_id`=lcom.`parent_id` AND map.`board_content_id`=lc.`content_id` AND trk.`user_id`=".$gBitUser->mUserId."
  504.                 ) AS track_count ";
  505.  
  506.         }
  507.  
  508.         if ($gBitSystem->isFeatureActive('boards_posts_anon_moderation'&& !($gBitUser->hasPermission('p_boards_update'|| $gBitUser->hasPermission('p_boards_post_update'))) {
  509.  
  510.         }
  511.         if ($gBitSystem->isFeatureActive('boards_posts_anon_moderation'&& ($gBitUser->hasPermission('p_boards_update'|| $gBitUser->hasPermission('p_boards_post_update'))) {
  512.             $selectSql .= ", ( SELECT COUNT(*)
  513.             FROM `".BIT_DB_PREFIX."boards_map` map
  514.             INNER JOIN `".BIT_DB_PREFIX."liberty_comments` s_lcom ON (map.`topic_content_id` = s_lcom.`root_id`)
  515.             INNER JOIN `".BIT_DB_PREFIX."liberty_content` s_lc ON (s_lcom.`content_id` = s_lc.`content_id`)
  516.             LEFT JOIN  `".BIT_DB_PREFIX."boards_posts` s ON( s_lcom.`comment_id` = s.`comment_id` )
  517. WHERE map.`board_content_id`=lc.`content_id` AND ((s_lc.`user_id` < 0) AND (s.`is_approved` = 0 OR s.`is_approved` IS NULL) )
  518.             ) AS unreg";
  519.         else {
  520.             $selectSql .= ", 0 AS unreg";
  521.         }
  522.  
  523.         // always show our own content
  524.         $whereSql .= " AND ( lc.`user_id`= ? ";
  525.         $bindVars[$gBitUser->mUserId;
  526.         if!empty$pParamHash['content_status_id') ) {
  527.             // TODO needs safety checking! - spider
  528.             $whereSql .= " OR lc.`content_status_id` = ? ";
  529.             $bindVars[=  $pParamHash['content_status_id'];
  530.         elseif!empty$pParamHash['min_content_status_id') ) {
  531.             $whereSql .= " OR lc.`content_status_id` >= ? ";
  532.             $bindVars[=  $pParamHash['min_content_status_id'];
  533.         }
  534.         $whereSql .= " ) ";
  535.  
  536.         $query "SELECT ts.*, lc.`content_id`, lc.`title`, lc.`data`, lc.`format_guid`
  537.              $selectSql
  538.             FROM `".BIT_DB_PREFIX."boards` ts
  539.                 INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON( lc.`content_id` = ts.`content_id` ) $joinSql
  540.             WHERE lc.`content_type_guid` = ? $whereSql
  541.             ORDER BY ".$this->mDb->convertSortmode$sort_mode );
  542.  
  543.         $query_cant "select count(*)
  544.             FROM `".BIT_DB_PREFIX."boards` ts INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON( lc.`content_id` = ts.`content_id` ) $joinSql
  545.             WHERE lc.`content_type_guid` = ? $whereSql";
  546.  
  547.         $result $this->mDb->query$query$bindVars );
  548.  
  549.         $ret array();
  550.         while$res $result->fetchRow() ) {
  551.             $res['url']BOARDS_PKG_URL."index.php?b={$res['board_id']}";
  552.  
  553.             $res['topic_count'$this->mDb->getOne"SELECT count(*)
  554.                 FROM `".BIT_DB_PREFIX."boards_map` map
  555.                     INNER JOIN `".BIT_DB_PREFIX."liberty_comments` lcom ON (map.`topic_content_id` = lcom.`root_id`)
  556.                     INNER JOIN `".BIT_DB_PREFIX."liberty_content` slc ON( slc.`content_id` = lcom.`content_id` )
  557.                     LEFT JOIN `".BIT_DB_PREFIX."boards_posts` fp ON (fp.`comment_id` = lcom.`comment_id`)
  558.                 WHERE lcom.`root_id`=lcom.`parent_id` AND map.`board_content_id`=? AND ((fp.`is_approved` = 1) OR (fp.`is_approved` IS NULL))"array$res['content_id') );
  559.  
  560.             $res['post_count'$this->mDb->getOne"SELECT count(*)
  561.                 FROM `".BIT_DB_PREFIX."liberty_comments` lcom
  562.                     INNER JOIN `".BIT_DB_PREFIX."liberty_content` slc ON( slc.`content_id` = lcom.`content_id` )
  563.                     INNER JOIN `".BIT_DB_PREFIX."boards_map` map ON (lcom.`root_id`=map.`topic_content_id`)
  564.                     LEFT JOIN `".BIT_DB_PREFIX."boards_posts` fp ON (fp.`comment_id` = lcom.`comment_id`)
  565.                 WHERE map.`board_content_id`=? AND ((fp.`is_approved` = 1) OR (fp.`is_approved` IS NULL))"array$res['content_id') );
  566.             if($track{
  567.                 if ($gBitUser->isRegistered()) {
  568.                     $res['track']['on'true;
  569.                     $res['track']['count'$res['track_count'];
  570.                     if ($res['post_count']>$res['track_count']{
  571.                         $res['track']['mod'true;
  572.                     else {
  573.                         $res['track']['mod'false;
  574.                     }
  575.                 }  else {
  576.                     $res['track']['on'false;
  577.                 }
  578.                 unset($res['track_count']);
  579.                 $res['parsed_data']=$this->parseData($res);
  580.                 $res['last'$this->getLastTopic($res);
  581.             }
  582.             $ret[$res;
  583.         }
  584.         $pParamHash["cant"$this->mDb->getOne$query_cant$bindVars );
  585.  
  586.         // add all pagination info to pParamHash
  587.         LibertyContent::postGetList$pParamHash );
  588.         return $ret;
  589.     }
  590.  
  591.     function getLastTopic($data{
  592.         global $gBitSystem;
  593.         $BIT_DB_PREFIX BIT_DB_PREFIX;
  594.         $query="SELECT slc.`last_modified`, slc.`user_id`, lcom.`anon_name` AS l_anon_name, slc.`title`, lcom.comment_id AS topic_id
  595.             FROM `".BIT_DB_PREFIX."boards_map` map
  596.                 INNER JOIN `".BIT_DB_PREFIX."liberty_comments` lcom ON (map.`topic_content_id` = lcom.`root_id`)
  597.                 INNER JOIN `".BIT_DB_PREFIX."liberty_content` slc ON( slc.`content_id` = lcom.`content_id` )
  598.                 LEFT JOIN `".BIT_DB_PREFIX."boards_posts` fp ON (fp.`comment_id` = lcom.`comment_id`)
  599.             WHERE lcom.`root_id`=lcom.`parent_id` AND map.`board_content_id`=? AND ((fp.`is_approved` IS NULL OR fp.`is_approved` = 1) OR (slc.`user_id` >= 0))
  600.             ORDER BY slc.`last_modified` DESC
  601.         ";
  602.         $result $this->mDb->getRow$queryarray$data['content_id') );
  603.         if (!empty($result['topic_id'])) {
  604.             if (empty($result['l_anon_name'])) {
  605.                 $result['l_anon_name'"Anonymous";
  606.             }
  607.             $result['topic_id']=intval($result['topic_id']);
  608.             $result['url'BitBoardTopic::getDisplayUrlFromHash$result );
  609.         }
  610.         return $result;
  611.     }
  612.  
  613.     /**
  614.     * Generates the URL to the bitboard page
  615.     * @return the link to display the page.
  616.     */
  617.     public static function getDisplayUrlFromHash&$pParamHash {
  618.         global $gBitSystem;
  619.         $ret NULL;
  620.  
  621.         if!empty$pParamHash['comment'&& !empty$pParamHash['comment']['thread_forward_sequence') ){
  622.             // look up base of comment sequece which is BitBoardTopic
  623.             $seq explode".",  $pParamHash['comment']['thread_forward_sequence');
  624.             $topicRootId =     (int)$seq[0];
  625.             ifBitBase::verifyId$topicRootId )) {
  626.                 require_onceBOARDS_PKG_PATH.'BitBoardTopic.php' );
  627.                 $hash array'topic_id' => $topicRootId );
  628.                 $ret BitBoardTopic::getDisplayUrlFromHash$hash );
  629.                 // we're out of here with our topic url
  630.                 return $ret;
  631.             }
  632.         }
  633.  
  634.         ifBitBase::verifyId$pParamHash['board_id')) {
  635.             if$gBitSystem->isFeatureActive'pretty_urls' || $gBitSystem->isFeatureActive'pretty_urls_extended' ) ) {
  636.                 $rewrite_tag $gBitSystem->isFeatureActive'pretty_urls_extended' 'view/':'';
  637.                 $ret BOARDS_PKG_URL.$rewrite_tag.'board/'.$pParamHash['board_id'];
  638.             else {
  639.                 $ret BOARDS_PKG_URL."index.php?b=".$pParamHash['board_id'];
  640.             }
  641.         else {
  642.             $ret parent::getDisplayUrlFromHash$pParamHash );
  643.         }
  644.  
  645.         return $ret;
  646.     }
  647.  
  648.     function getBoardSelectList$pBlankFirst=FALSE {
  649.         global $gBitSystem$gBitUser;
  650.  
  651.         // invoke list sql principly to enforce permission services
  652.         $selectSql $joinSql $whereSql '';
  653.         $bindVars array();
  654.  
  655.         $this->getServicesSql'content_list_sql_function'$selectSql$joinSql$whereSql$bindVars );
  656.  
  657.         /* DEPRECATED - has some pointless stuff
  658.         $query = "SELECT lc.`content_id` as hash_key, lc.`title` AS `title`
  659.             FROM `".BIT_DB_PREFIX."boards` b
  660.                 INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON( lc.`content_id` = b.`content_id` )
  661.                 LEFT JOIN `".BIT_DB_PREFIX."boards_map` bm ON( bm.`board_content_id`=b.`content_id` )
  662.                 LEFT JOIN `".BIT_DB_PREFIX."liberty_comments` lcom ON (bm.`topic_content_id` = lcom.`root_id`)
  663.             GROUP BY lc.`content_id`, lc.`title`, lcom.`comment_id`
  664.             ORDER BY lc.`title` ASC";
  665.          */
  666.  
  667.         // replacement query where we at least check that the board has been mapped to another board - a requirement for displaying comments
  668.         // if you hate it fix it or lets chat -wjames5
  669.         $query "SELECT lc.`content_id` as hash_key, lc.`title` AS `title`
  670.             FROM `".BIT_DB_PREFIX."boards` b
  671.                 INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON( lc.`content_id` = b.`content_id` )
  672.                 INNER JOIN `".BIT_DB_PREFIX."boards_map` bm ON( bm.`topic_content_id`=b.`content_id` )
  673.                 $joinSql
  674.             WHERE lc.`content_id` = b.`content_id` $whereSql
  675.             ORDER BY lc.`title` ASC";
  676.  
  677.         $ret array();
  678.  
  679.         if$rslt $this->mDb->query$query$bindVars ) ){
  680.             if$pBlankFirst {
  681.                 $ret['''---------';
  682.             }
  683.             while$row $rslt->fetchRow() ) {
  684.                 $ret[$row['hash_key']] $row['title'];
  685.             }
  686.         }
  687.  
  688.         return $ret;
  689.     }
  690.  
  691.     function getBoard$contentId {
  692.         global $gBitDb;
  693.         global $gBitUser;
  694.         //var_dump($GLOBALS);
  695.         ifLibertyContent::verifyId$contentId ) ) {
  696.             // LibertyContent::load()assumes you have joined already, and will not execute any sql!
  697.             // This is a significant performance optimization
  698.             $bindVars array();
  699.             $selectSql $joinSql $whereSql '';
  700.             array_push$bindVars$contentId );
  701.             $gBitUser->getServicesSql'content_load_sql_function'$selectSql$joinSql$whereSql$bindVars );
  702.  
  703.             $query "SELECT lc.*, uue.`login` AS modifier_user, uue.`real_name` AS modifier_real_name, uuc.`login` AS creator_user, uuc.`real_name` AS creator_real_name $selectSql
  704.             FROM `".BIT_DB_PREFIX."liberty_content` lc $joinSql
  705.                 LEFT JOIN `".BIT_DB_PREFIX."users_users` uue ON( uue.`user_id` = lc.`modifier_user_id` )
  706.                 LEFT JOIN `".BIT_DB_PREFIX."users_users` uuc ON( uuc.`user_id` = lc.`user_id` )
  707.             WHERE lc.`content_id`=? $whereSql";
  708.             $result $gBitDb->query$query$bindVars );
  709.  
  710.             $ret array();
  711.             if$result && $result->numRows() ) {
  712.                 $ret $result->fields;
  713.  
  714.                 $ret['creator'=isset$result->fields['creator_real_name')$result->fields['creator_real_name'$result->fields['creator_user');
  715.                 $ret['editor'=isset$result->fields['modifier_real_name')$result->fields['modifier_real_name'$result->fields['modifier_user');
  716.                 $ret['display_url'BIT_ROOT_URL."index.php?content_id=$contentId";
  717.             }
  718.         }
  719.         return$ret );
  720.     }
  721.  
  722.     public static function getLinkedBoard$pContentId {
  723.         global $gBitDb;
  724.         $ret NULL;
  725.         ifBitBase::verifyId$pContentId ) ) {
  726.             $sql "SELECT b.`board_id`, b.`content_id` AS `board_content_id`, COUNT(lcom.`comment_id`) AS `post_count`
  727.                     FROM `".BIT_DB_PREFIX."boards_map` bm
  728.                         INNER JOIN `".BIT_DB_PREFIX."boards` b ON (bm.`board_content_id`=b.`content_id`)
  729.                         LEFT JOIN `".BIT_DB_PREFIX."liberty_comments` lcom ON (lcom.`root_id`=bm.`topic_content_id`)
  730.                     WHERE bm.`topic_content_id`=?
  731.                     GROUP BY b.`board_id`, b.`content_id`";
  732.             $ret $gBitDb->getRow$sqlarray$pContentId ) );
  733.         }
  734.         return $ret;
  735.     }
  736.  
  737.  
  738.     // =-=-=-=-=-=-=-=-=-=-=-=-=-= Board Sync Methods =-=-=-=-=-=-=-=-=-=-=-=-=-=
  739.     function getBoardSyncInbox({
  740.         global $gBitSystem;
  741.         $ret '';
  742.         if$gBitSystem->getConfig('boards_sync_user') ) {
  743.             $ret $gBitSystem->getConfig('boards_sync_user').'@'.$gBitSystem->getConfig('boards_sync_mail_server');
  744.         }
  745.         return $ret;
  746.     }
  747.  
  748.     function getBoardMailingList({
  749.         global $gBitSystem;
  750.         $ret NULL;
  751.         if$this->isValid(&& $gBitSystem->getConfig'boards_sync_mail_server' && $this->getPreference'boards_mailing_list' ) ) {
  752.             $ret $this->getPreference'boards_mailing_list' ).'@'.$gBitSystem->getConfig'boards_email_host'$gBitSystem->getConfig'kernel_server_name' ) );
  753.         }
  754.         return $ret;
  755.     }
  756. }
  757.  
  758. function boards_content_display $pContent {
  759.     global $gBitSmarty;
  760.     if$pContent->isValid(&& $pContent->getField('content_type_guid'!= 'bitboard' {
  761.         $gBitSmarty->assign'boardInfo'BitBoard::getLinkedBoard$pContent->mContentId ) );
  762.     }
  763. }
  764.  
  765. function boards_content_edit $pContent$pParamHash {
  766.     global $gBitSmarty;
  767.     // topic service
  768.     if!$pContent->isContentTypeBITBOARDTOPIC_CONTENT_TYPE_GUID ) ) {
  769.         if$pContent->isValid() ) {
  770.             $gBitSmarty->assign'boardInfo'BitBoard::getLinkedBoard$pContent->mContentId ) );
  771.         else {
  772.             $boardInfo['board_content_id'$pParamHash['linked_board_cid'];
  773.             $gBitSmarty->assign'boardInfo'$boardInfo );
  774.         }
  775.         require_onceBOARDS_PKG_PATH.'BitBoard.php' );
  776.         $board new BitBoard();
  777.         $boardList $board->getBoardSelectListTRUE );
  778.         $gBitSmarty->assign'boardList'$boardList );
  779.     }
  780. }
  781.  
  782. // store services for boads
  783. function boards_content_store$pContent$pParamHash {
  784.     global $gBitDb$gBitSmarty$gBitSystem;
  785.  
  786.     require_onceBOARDS_PKG_PATH.'BitBoardTopic.php' );
  787.     // do not allow unassigning topics. the UI should prevent this, but just to make sure...
  788.     if$pContent->isValid(&& !$pContent->isContentTypeBITBOARDTOPIC_CONTENT_TYPE_GUID && !$pContent->isContentTypeBITBOARD_CONTENT_TYPE_GUID ) ) {
  789.         // wipe out all previous assignments for good measure. Not the sanest thing to do, but edits are infrequent - at least for now
  790.         if ($gBitSystem->isFeatureActive('boards_link_by_pigeonholes'&& $gBitSystem->isPackageActive('pigeonholes')) {
  791.             // Delete all old mappings
  792.             $pContent->mDb->query"DELETE FROM `".BIT_DB_PREFIX."boards_map` WHERE `topic_content_id`=?"array$pContent->mContentId ) );
  793.  
  794.             // Get the pigeonholes this content is in
  795.             $p null;
  796.             if empty$pParamHash['pigoneholes') ) {
  797.                 foreach$pParamHash['pigeonholes']['pigeonhole'as $p_id {
  798.                     require_once(PIGEONHOLES_PKG_PATH.'Pigeonholes.php');
  799.                     if (empty($p)) {
  800.                         $p new Pigeonholes();
  801.                     }
  802.  
  803.                     // What boards are in the same pigeonhole?
  804.                     $params =
  805.                         array('content_type_guid' => BITBOARD_CONTENT_TYPE_GUID,
  806.                               'content_id' => $p_id );
  807.                     $boards $p->getMemberList$params );
  808.  
  809.                     // Insert into these boards
  810.                     foreach ($boards as $board{
  811.                         if@BitBase::verifyId$board['content_id') ) {
  812.                             $pContent->mDb->query"INSERT INTO `".BIT_DB_PREFIX."boards_map` (`board_content_id`,`topic_content_id`) VALUES (?,?)"array$board['content_id']$pContent->mContentId ) );
  813.                         }
  814.                     }
  815.                 }
  816.             }
  817.         }
  818.         else {
  819.             $pContent->mDb->query"DELETE FROM `".BIT_DB_PREFIX."boards_map` WHERE `topic_content_id`=?"array$pContent->mContentId ) );
  820.             if@BitBase::verifyId$pParamHash['linked_board_cid') ) {
  821.                 $pContent->mDb->query"INSERT INTO `".BIT_DB_PREFIX."boards_map` (`board_content_id`,`topic_content_id`) VALUES (?,?)"array$pParamHash['linked_board_cid']$pContent->mContentId ) );
  822.             }
  823.         }
  824.         $gBitSmarty->assign'boardInfo'BitBoard::getLinkedBoard$pContent->mContentId ) );
  825.     else {
  826.         if@BitBase::verifyId$pParamHash['content_id'&& @BitBase::verifyId$pParamHash['linked_board_cid') ) {
  827.             $pContent->mDb->query"INSERT INTO `".BIT_DB_PREFIX."boards_map` (`board_content_id`,`topic_content_id`) VALUES (?,?)"array$pParamHash['linked_board_cid']$pParamHash['content_id') );
  828.         }
  829.     }
  830. }
  831.  
  832. // store services for topics and posts
  833. function boards_comment_store&$pObject&$pParamHash {
  834.     global $gBitSystem;
  835.     // board posts ( e.g. liberty comments ) service
  836.     // @TODO check that root object is a board -- otherwise all comments get fired
  837.     // @TODO probably should migrate sendNotification to Switchboard
  838.  
  839.     if$gBitSystem->isPackageActive'boards' && $pObject->isContentTypeBITCOMMENT_CONTENT_TYPE_GUID && $gBitSystem->isFeatureActive'boards_thread_notification' )) {
  840.         ifisset$pObject->mInfo['thread_forward_sequence') ){
  841.             $topic_id substr$pObject->mInfo['thread_forward_sequence']010 );
  842.             $data BitBoardTopic::getNotificationData($topic_id);
  843.             foreach$data['users'as $login => $user {
  844.                 if$data['topic']->mInfo['llc_last_modified'$user['track_date'&& $data['topic']->mInfo['llc_last_modified'$user['track_notify_date'{
  845.                     $data['topic']->sendNotification$user );
  846.                 }
  847.             }
  848.         }
  849.     }
  850. }
  851.  
  852. function boards_content_verify&$pObject&$pParamHash ){
  853.     // board posts ( e.g. liberty comments ) service
  854.     global $gBitSystem$gBitUser;
  855.     // use is_a instead of isContentType( BITCOMMENT_CONTENT_TYPE_GUID ) as isContentType() checks isValid(), and this service method will not properly handle new object stores
  856.     if$gBitSystem->isPackageActive'boards' && is_a$pObject 'LibertyComment' ) ) {
  857.         ifBitBoardTopic::isLockedMsg$pParamHash['parent_id')) {
  858.             $pObject->mErrors['warning']=tra("The selected Topic is Locked posting is disabled");
  859.         }
  860.     }
  861. }
  862.  
  863. function boards_content_expunge$pContent {
  864.     global $gBitSmarty;
  865.     if$pContent->isValid() ) {
  866.         $pContent->mDb->query"DELETE FROM `".BIT_DB_PREFIX."boards_map` WHERE `topic_content_id`=?"array$pContent->mContentId ) );
  867.     }
  868. }
  869.  
  870. ?>

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