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

Source for file BitArticle.php

Documentation is available at BitArticle.php

  1. <?php
  2. /**
  3.  * Article class is used when accessing BitArticles. It is based on TikiSample
  4.  * and builds on core bitweaver functionality, such as the Liberty CMS engine.
  5.  *
  6.  * @version $Header$
  7.  * @package articles
  8.  *
  9.  * @copyright 2004-15 bitweaver.org
  10.  *  Copyright( c )2003 tikwiki.org
  11.  *  Copyright( c )2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
  12.  *  All Rights Reserved. See below for details and a complete list of authors.
  13.  *  Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details
  14.  *
  15.  *  $Id$
  16.  *
  17.  * @author wolffy <wolff_borg@yahoo.com.au>
  18.  * @version $Revision$
  19.  */
  20.  
  21. /**
  22.  * Required setup
  23.  */
  24. require_onceARTICLES_PKG_PATH.'BitArticleTopic.php' );
  25. require_onceARTICLES_PKG_PATH.'BitArticleType.php' );
  26. require_onceLIBERTY_PKG_PATH.'LibertyMime.php' );
  27. require_onceLIBERTY_PKG_PATH.'LibertyComment.php' );
  28.  
  29. define'BITARTICLE_CONTENT_TYPE_GUID''bitarticle' );
  30.  
  31. /**
  32.  * @package articles
  33.  */
  34. class BitArticle extends LibertyMime
  35. {
  36.     /**
  37.     * Primary key for articles
  38.     */
  39.     public $mArticleId;
  40.     public $mTypeId;
  41.     public $mTopicId;
  42.  
  43.     /**
  44.     * Initiate the articles class
  45.     * @param $pArticleId article id of the article we want to view
  46.     * @param $pContentId content id of the article we want to view
  47.     * @access private
  48.     ***/
  49.     public function BitArticle($pArticleId=NULL$pContentId=NULL)
  50.     {
  51.         parent::__construct();
  52.         $this->registerContentType(
  53.             BITARTICLE_CONTENT_TYPE_GUIDarray(
  54.                 'content_type_guid' => BITARTICLE_CONTENT_TYPE_GUID,
  55.                 'content_name' => 'Article',
  56.                 'handler_class' => 'BitArticle',
  57.                 'handler_package' => 'articles',
  58.                 'handler_file' => 'BitArticle.php',
  59.                 'maintainer_url' => 'http://www.bitweaver.org'
  60.         ));
  61.         $this->mContentId = $pContentId;
  62.         $this->mArticleId = $pArticleId;
  63.         $this->mTypeId  = NULL;
  64.         $this->mTopicId = NULL;
  65.         $this->mDate new BitDate();
  66.         $offset $this->mDate->get_display_offset();
  67.  
  68.         // Permission setup
  69.         $this->mViewContentPerm  = 'p_articles_read';
  70.         $this->mCreateContentPerm  = 'p_articles_submit';
  71.         $this->mUpdateContentPerm  = 'p_articles_update';
  72.         $this->mAdminContentPerm = 'p_articles_admin';
  73.     }
  74.  
  75.     /**
  76.     * Load the data from the database
  77.     * @access public
  78.     ***/
  79.     public function load($pContentId NULL$pPluginParams NULL)
  80.     {
  81.         if @$this->verifyId$this->mArticleId || @$this->verifyId$this->mContentId ) ) {
  82.             // LibertyContent::load()assumes you have joined already, and will not execute any sql!
  83.             // This is a significant performance optimization
  84.             $lookupColumn @$this->verifyId$this->mArticleId 'article_id' 'content_id';
  85.             $bindVars[$lookupId @BitBase::verifyId$this->mArticleId $this->mArticleId : $this->mContentId;
  86.             $this->getServicesSql'content_load_sql_function'$selectSql$joinSql$whereSql$bindVars );
  87.  
  88.             $query "SELECT a.*, lc.*, atype.*, atopic.*, lch.hits,
  89.                 uue.`login` AS `modifier_user`, uue.`real_name` AS `modifier_real_name`,
  90.                 uuc.`login` AS `creator_user`, uuc.`real_name` AS `creator_real_name` ,
  91.                 la.`attachment_id` AS `primary_attachment_id`, lf.`file_name` AS `image_attachment_path` $selectSql
  92.                 FROM `".BIT_DB_PREFIX."articles` a
  93.                     LEFT OUTER JOIN `".BIT_DB_PREFIX."article_types` atype ON( atype.`article_type_id` = a.`article_type_id` )
  94.                     LEFT OUTER JOIN `".BIT_DB_PREFIX."article_topics` atopic ON( atopic.`topic_id` = a.`topic_id` )
  95.                     INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON( lc.`content_id` = a.`content_id` )
  96.                     LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_content_hits` lch ON( lch.`content_id` = lc.`content_id` )
  97.                     LEFT OUTER JOIN `".BIT_DB_PREFIX."users_users` uue ON( uue.`user_id` = lc.`modifier_user_id` )
  98.                     LEFT OUTER JOIN `".BIT_DB_PREFIX."users_users` uuc ON( uuc.`user_id` = lc.`user_id` )
  99.                     LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_attachments` la ON( la.`content_id` = lc.`content_id` AND la.`is_primary` = 'y' )
  100.                     LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_files` lf ON( lf.`file_id` = la.`foreign_id` )
  101.                     $joinSql
  102.                 WHERE a.`$lookupColumn`=? $whereSql";
  103.             $result $this->mDb->query$query$bindVars );
  104.  
  105.             global $gBitSystem;
  106.             if $result && $result->numRows() ) {
  107.                 $this->mInfo = $result->fetchRow();
  108.  
  109.                 // if a custom image for the article exists, use that, then use an attachment, then use the topic image
  110.                 $isTopicImage false;
  111.  
  112.                 $this->mContentId = $this->mInfo['content_id'];
  113.                 $this->mArticleId = $this->mInfo['article_id'];
  114.                 $this->mTopicId   = $this->mInfo['topic_id'];
  115.                 $this->mTypeId      = $this->mInfo['article_type_id'];
  116.  
  117.                 $this->mInfo['thumbnail_url'static::getImageThumbnails$this->mInfo );
  118.                 $this->mInfo['creator']       !empty$this->mInfo['creator_real_name'$this->mInfo['creator_real_name'$this->mInfo['creator_user');
  119.                 $this->mInfo['editor']        !empty$this->mInfo['modifier_real_name'$this->mInfo['modifier_real_name'$this->mInfo['modifier_user');
  120.                 $this->mInfo['display_url']   $this->getDisplayUrl();
  121.                 // we need the raw data to display in the textarea
  122.                 $this->mInfo['raw']           $this->mInfo['data'];
  123.                 // here we have the displayed data without the ...split... stuff
  124.                 $this->mInfo['data']          preg_replaceLIBERTY_SPLIT_REGEX""$this->mInfo['data');
  125.  
  126.                 $comment new LibertyComment();
  127.                 $this->mInfo['num_comments'$comment->getNumComments$this->mInfo['content_id');
  128.  
  129.                 LibertyMime::load();
  130.  
  131.                 if !empty$this->mInfo['primary_attachment_id'&& !empty$this->mStorage[$this->mInfo['primary_attachment_id']] )) {
  132.                     $this->mInfo['primary_attachment'&$this->mStorage[$this->mInfo['primary_attachment_id']];
  133.                 }
  134.  
  135.                 $this->mInfo['parsed'$this->parseData();
  136.             else {
  137.                 $this->mArticleId = NULL;
  138.             }
  139.         }
  140.  
  141.         returncount$this->mInfo ) );
  142.     }
  143.  
  144.     /**
  145.     * Store article data after submission
  146.     * @param array pParamHash of values that will be used to store the page
  147.     * @return bool TRUE on success, FALSE if store could not occur. If FALSE, $this->mErrors will have reason why
  148.     * @access public
  149.     ***/
  150.     public function store(&$pParamHash)
  151.     {
  152.         global $gBitSystem;
  153.         $this->mDb->StartTrans();
  154.         if $this->verify$pParamHash )&& LibertyMime::store$pParamHash ) ) {
  155.             $table BIT_DB_PREFIX."articles";
  156.  
  157.             if $this->isValid() ) {
  158.                 $result $this->mDb->associateUpdate$table$pParamHash['article_store']array"article_id" => $this->mArticleId ));
  159.             else {
  160.                 $pParamHash['article_store']['content_id'$pParamHash['content_id'];
  161.                 if isset$pParamHash['article_id')&& is_numeric$pParamHash['article_id') ) {
  162.                     // if pParamHash['article_id'] is set, someone is requesting a particular article_id. Use with caution!
  163.                     $pParamHash['article_store']['article_id'$pParamHash['article_id'];
  164.                 else {
  165.                     $pParamHash['article_store']['article_id'$this->mDb->GenID'articles_article_id_seq' );
  166.                 }
  167.                 $this->mArticleId = $pParamHash['article_store']['article_id'];
  168.                 $result $this->mDb->associateInsert$table$pParamHash['article_store');
  169.             }
  170.  
  171.             $this->mDb->CompleteTrans();
  172.             $this->load();
  173.         }
  174.         return count$this->mErrors == );
  175.     }
  176.  
  177.     /**
  178.     * Make sure the data is safe to store
  179.     * @param pParamHash be sure to pass by reference in case we need to make modifcations to the hash
  180.     * @param array pParams reference to hash of values that will be used to store the page, they will be modified where necessary
  181.     * @return bool TRUE on success, FALSE if verify failed. If FALSE, $this->mErrors will have reason why
  182.     * @access private
  183.     ***/
  184.     public function verify(&$pParamHash)
  185.     {
  186.         global $gBitUser$gBitSystem;
  187.  
  188.         // make sure we're all loaded up of we have a mArticleId
  189.         if $this->mArticleId && 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.         if empty$pParamHash['content_type_guid')&& !empty$this->mContentTypeGuid ) ) {
  199.             $pParamHash['content_type_guid'$this->mContentTypeGuid;
  200.         }
  201.  
  202.         if @$this->verifyId$pParamHash['content_id') ) {
  203.             $pParamHash['article_store']['content_id'$pParamHash['content_id'];
  204.         }
  205.  
  206.         if !empty$pParamHash['author_name') ) {
  207.             $pParamHash['article_store']['author_name'$pParamHash['author_name'];
  208.         }
  209.  
  210.         if @$this->verifyId$pParamHash['topic_id') ) {
  211.             $pParamHash['article_store']['topic_id'=(int) $pParamHash['topic_id'];
  212.         }
  213.  
  214.         if @$this->verifyId$pParamHash['article_type_id') ) {
  215.             $pParamHash['article_store']['article_type_id'=(int) $pParamHash['article_type_id'];
  216.         }
  217.  
  218.         if !empty$pParamHash['format_guid') ) {
  219.             $pParamHash['content_store']['format_guid'$pParamHash['format_guid'];
  220.         }
  221.  
  222.         // we do the substr on load. otherwise we need to store the same data twice.
  223.         if !empty$pParamHash['edit') ) {
  224.             $pParamHash['content_store']['data'$pParamHash['edit'];
  225.         }
  226.  
  227.         if !empty$pParamHash['rating') ) {
  228.             $pParamHash['article_store']['rating'=(int) $pParamHash['rating');
  229.         }
  230.  
  231.         // check for name issues, first truncate length if too long
  232.         if !empty$pParamHash['title') ) {
  233.             if !$this->isValid() ) {
  234.                 if empty$pParamHash['title') ) {
  235.                     $this->mErrors['title''You must specify a title.';
  236.                 else {
  237.                     $pParamHash['content_store']['title'substr$pParamHash['title']0BIT_CONTENT_MAX_TITLE_LEN );
  238.                 }
  239.             else {
  240.                 $pParamHash['content_store']['title'=isset$pParamHash['title'))substr$pParamHash['title']0BIT_CONTENT_MAX_TITLE_LEN )'';
  241.             }
  242.         elseif empty$pParamHash['title') ) {
  243.             // no name specified
  244.             $this->mErrors['title''You must specify a title';
  245.         }
  246.  
  247.         if !empty$pParamHash['publish_Month') ) {
  248.             $dateString $this->mDate->gmmktime(
  249.                 $pParamHash['publish_Hour'],
  250.                 $pParamHash['publish_Minute'],
  251.                 isset($pParamHash['publish_Second']$pParamHash['publish_Second'0,
  252.                 $pParamHash['publish_Month'],
  253.                 $pParamHash['publish_Day'],
  254.                 $pParamHash['publish_Year']
  255.             );
  256.  
  257.             $timestamp $this->mDate->getUTCFromDisplayDate$dateString );
  258.             if ($timestamp !== -1{
  259.                 $pParamHash['publish_date'$timestamp;
  260.             }
  261.         }
  262.         if !empty$pParamHash['publish_date') ) {
  263.             $pParamHash['article_store']['publish_date'$pParamHash['publish_date'];
  264.         }
  265.  
  266.         if !empty$pParamHash['expire_Month') ) {
  267.             $dateString $this->mDate->gmmktime(
  268.                 $pParamHash['expire_Hour'],
  269.                 $pParamHash['expire_Minute'],
  270.                 isset($pParamHash['expire_Second']$pParamHash['expire_Second'0,
  271.                 $pParamHash['expire_Month'],
  272.                 $pParamHash['expire_Day'],
  273.                 $pParamHash['expire_Year']
  274.             );
  275.  
  276.             $timestamp $this->mDate->getUTCFromDisplayDate$dateString );
  277.             if ($timestamp !== -1{
  278.                 $pParamHash['expire_date'$timestamp;
  279.             }
  280.         }
  281.         if !empty$pParamHash['expire_date') ) {
  282.             $pParamHash['article_store']['expire_date'$pParamHash['expire_date'];
  283.         }
  284.  
  285.         if @$this->verifyId$pParamHash['status_id') ) {
  286.             if ($pParamHash['status_id'ARTICLE_STATUS_PENDING{
  287.                 if $gBitUser->hasPermission'p_articles_approve_submission' )) {
  288.                     $pParamHash['article_store']['status_id'=(int) $pParamHash['status_id');
  289.                 else {
  290.                     $pParamHash['article_store']['status_id'ARTICLE_STATUS_PENDING;
  291.                 }
  292.             else {
  293.                 $pParamHash['article_store']['status_id'=(int) $pParamHash['status_id');
  294.             }
  295.         elseif @$this->verifyId$this->mInfo['status_id') ) {
  296.             $pParamHash['article_store']['status_id'$this->mInfo['status_id'];
  297.         else {
  298.             if $gBitUser->hasPermission'p_articles_approve_submission' || $gBitUser->hasPermission'p_articles_auto_approve' ) ) {
  299.                 $pParamHash['article_store']['status_id'ARTICLE_STATUS_APPROVED;
  300.             else {
  301.                 $pParamHash['article_store']['status_id'ARTICLE_STATUS_PENDING;        // Default status
  302.             }
  303.         }
  304.  
  305.         // content preferences
  306.         $prefs array();
  307.         if $gBitUser->hasPermission'p_liberty_enter_html' ) ) {
  308.             $prefs['content_enter_html';
  309.         }
  310.  
  311.         foreach ($prefs as $pref{
  312.             if !empty$pParamHash['preferences'][$pref) ) {
  313.                 $pParamHash['preferences_store'][$pref$pParamHash['preferences'][$pref];
  314.             else {
  315.                 $pParamHash['preferences_store'][$prefNULL;
  316.             }
  317.         }
  318.  
  319.         if array_search$pParamHash['article_store']['status_id']arrayARTICLE_STATUS_DENIEDARTICLE_STATUS_DRAFTARTICLE_STATUS_PENDING ) ) ) {
  320.                 $this->mInfo["no_index"true ;
  321.         }
  322.  
  323.         // if we have an error we get them all by checking parent classes for additional errors
  324.         if count$this->mErrors {
  325.             parent::verify$pParamHash );
  326.         }
  327.  
  328.         returncount$this->mErrors )== );
  329.     }
  330.  
  331.     /**
  332.     * Deal with images and text, modify them apprpriately that they can be returned to the form.
  333.     * @param $previewData data submitted by form - generally $_REQUEST
  334.     * @return array of data compatible with article form
  335.     * @access public
  336.     ***/
  337.     public function preparePreview($pParamHash)
  338.     {
  339.         global $gBitSystem$gBitUser;
  340.  
  341.         $data $pParamHash;
  342.         $this->verify$data );
  343.         $data array_merge$pParamHash$data['content_store']$data['article_store');
  344.         $data['raw'$data['edit'];
  345.  
  346.         if empty$data['user_id') ) {
  347.             $data['user_id'$gBitUser->mUserId;
  348.         }
  349.  
  350.         if empty$data['hits') ) {
  351.             $data['hits'0;
  352.         }
  353.  
  354.         if empty$data['publish_date') ) {
  355.             $data['publish_date'$gBitSystem->getUTCTime();
  356.         }
  357.  
  358.         if empty$data['article_type_id') ) {
  359.             $data['article_type_id'1;
  360.         }
  361.  
  362.         if empty$data['topic_id') ) {
  363.             $data['topic_id'1;
  364.         }
  365.  
  366.         if empty$data['parsed') ) {
  367.             $data['no_cache']    TRUE;
  368.             $data['parsed'$this->parseData$data );
  369.             // replace the split syntax with a horizontal rule
  370.             $data['parsed'preg_replaceLIBERTY_SPLIT_REGEX"<hr />"$data['parsed');
  371.         }
  372.  
  373.         $articleType new BitArticleType$data['article_type_id');
  374.         $articleTopic new BitArticleTopic$data['topic_id');
  375.         $data array_merge$data$articleType->mInfo$articleTopic->mInfo );
  376.  
  377.         return $data;
  378.     }
  379.  
  380.     /**
  381.     * Get the URL for any given article image
  382.     * @param $pParamHash pass in full set of data returned from article query
  383.     * @return url to image
  384.     * @access public
  385.     ***/
  386.     public static function getImageThumbnails($pParamHash)
  387.     {
  388.         global $gBitSystem$gThumbSizes;
  389.         $ret NULL;
  390.  
  391.         $thumbHash['mime_image'FALSE;
  392.         if !empty$pParamHash['image_attachment_path')) {
  393.             $thumbHash['source_file'$pParamHash['image_attachment_path'];
  394.             $ret liberty_fetch_thumbnails$thumbHash );
  395.         elseif !empty$pParamHash['has_topic_image'&& $pParamHash['has_topic_image'== 'y' {
  396.             $thumbHash['source_file'preg_replace"#^/+#"""BitArticleTopic::getTopicImageStorageUrl$pParamHash['topic_id'));
  397.             $ret liberty_fetch_thumbnails$thumbHash );
  398.         }
  399.  
  400.         return $ret;
  401.     }
  402.  
  403.     /**
  404.     * Removes currently loaded article
  405.     * @return bool TRUE on success, FALSE on failure
  406.     * @access public
  407.     ***/
  408.     public function expunge()
  409.     {
  410.         $ret FALSE;
  411.         if $this->isValid() ) {
  412.             $this->mDb->StartTrans();
  413.             $query "DELETE FROM `".BIT_DB_PREFIX."articles` WHERE `content_id` = ?";
  414.             $result $this->mDb->query$queryarray$this->mContentId ) );
  415.             if LibertyMime::expunge() ) {
  416.                 $ret TRUE;
  417.                 $this->mDb->CompleteTrans();
  418.             else {
  419.                 $this->mDb->RollbackTrans();
  420.             }
  421.         }
  422.         return $ret;
  423.     }
  424.  
  425.     /**
  426.     * Check if there is an article loaded
  427.     * @return bool TRUE on success, FALSE on failure
  428.     * @access public
  429.     ***/
  430.     public function isValid()
  431.     {
  432.         return$this->verifyId$this->mArticleId && $this->verifyId$this->mContentId ) );
  433.     }
  434.  
  435.     /**
  436.     * This function generates a list of records from the liberty_content database for use in a list page
  437.     * @param $pParamHash contains an array of conditions to sort by
  438.     * @return array of articles
  439.     * @access public
  440.     ***/
  441.     public function getList(&$pParamHash)
  442.     {
  443.         global $gBitSystem$gBitUser$gLibertySystem;
  444.  
  445.         if empty$pParamHash['sort_mode') ) {
  446.             // no idea what this is supposed to do
  447.             //$pParamHash['sort_mode'] = $gBitSystem->isFeatureActive('articles_auto_approve') ? 'order_key_desc' : 'publish_date_desc';
  448.             $pParamHash['sort_mode''publish_date_desc';
  449.         }
  450.  
  451.         LibertyContent::prepGetList$pParamHash );
  452.  
  453.         $joinSql '';
  454.         $selectSql '';
  455.         $bindVars array();
  456.         array_push$bindVars$this->mContentTypeGuid );
  457.         $this->getServicesSql'content_list_sql_function'$selectSql$joinSql$whereSql$bindVarsNULL$pParamHash );
  458.  
  459.         $find $pParamHash['find'];
  460.         if is_array$find ) ) {
  461.             // you can use an array of articles
  462.             $whereSql .= " AND lc.`title` IN( ".implode',',array_fill0count$find ),'?' ) )." )";
  463.             $bindVars array_merge$bindVars$find );
  464.         elseif is_string$find ) ) {
  465.             // or a string
  466.             $whereSql .= " AND UPPER( lc.`title` ) LIKE ? ";
  467.             $bindVars['%'.strtoupper$find ).'%';
  468.         elseif @$this->verifyId$pParamHash['user_id') ) {
  469.             // or gate on a user
  470.             $whereSql .= " AND lc.`user_id` = ? ";
  471.             $bindVars[= (int) $pParamHash['user_id'];
  472.         }
  473.  
  474.         if @$this->verifyId$pParamHash['status_id') ) {
  475.             $whereSql .= " AND a.`status_id` = ? ";
  476.             $bindVars[$pParamHash['status_id'];
  477.         }
  478.  
  479.         if @$this->verifyId$pParamHash['type_id') ) {
  480.             $whereSql .= " AND a.`article_type_id` = ? ";
  481.             $bindVars[= (int) $pParamHash['type_id'];
  482.         }
  483.  
  484.         // TODO: we need to check if the article wants to be viewed before / after respective dates
  485.         // someone better at SQL please get this working without an additional db call - xing
  486.         $now $gBitSystem->getUTCTime();
  487.         if !empty$pParamHash['show_future'&& !empty$pParamHash['show_expired'&& $gBitUser->hasPermission'p_articles_admin' )) {
  488.             // this will show all articles at once - future, current and expired
  489.         elseif !empty$pParamHash['show_future'&& $gBitUser->hasPermission'p_articles_admin' )) {
  490.             // hide expired articles
  491.             $whereSql .= " AND ( a.`expire_date` > ? OR atype.`show_post_expire` = ? ) ";
  492.             $bindVars[= (int) $now;
  493.             $bindVars['y';
  494.         elseif !empty$pParamHash['show_expired'&& $gBitUser->hasPermission'p_articles_admin' )) {
  495.             // hide future articles
  496.             $whereSql .= " AND ( a.`publish_date` < ? OR atype.`show_pre_publ` = ? ) ";
  497.             $bindVars[= (int) $now;
  498.             $bindVars['y';
  499.         elseif !empty$pParamHash['get_future')) {
  500.             // show only future
  501.             // if we're trying to view these articles, we better have the perms to do so
  502.             if !$gBitUser->hasPermission'p_articles_admin' )) {
  503.                 return array();
  504.             }
  505.             $whereSql .= " AND a.`publish_date` > ?";
  506.             $bindVars[= (int) $now;
  507.         elseif !empty$pParamHash['get_expired')) {
  508.             // show only expired articles
  509.             // if we're trying to view these articles, we better have the perms to do so
  510.             if !$gBitUser->hasPermission'p_articles_admin' )) {
  511.                 return array();
  512.             }
  513.             $whereSql .= " AND a.`expire_date` < ? ";
  514.             $bindVars[= (int) $now;
  515.         else {
  516.             // hide future and expired articles - this is the default behaviour
  517.             // we need all these AND and ORs to ensure that other conditions such as status_id are respected as well
  518.             $whereSql .= " AND (( a.`publish_date` > a.`expire_date` ) OR (( a.`publish_date` < ? OR atype.`show_pre_publ` = ? ) AND ( a.`expire_date` > ? OR atype.`show_post_expire` = ? ))) ";
  519.             $bindVars[= (int) $now;
  520.             $bindVars['y';
  521.             $bindVars[= (int) $now;
  522.             $bindVars['y';
  523.         }
  524.  
  525.         if @$this->verifyId$pParamHash['topic_id') ) {
  526.             $whereSql .= " AND a.`topic_id` = ? ";
  527.             $bindVars[= (int) $pParamHash['topic_id'];
  528.         elseif !empty$pParamHash['topic') ) {
  529.             $whereSql .= " AND UPPER( atopic.`topic_name` ) = ? ";
  530.             $bindVars[strtoupper$pParamHash['topic');
  531.         else {
  532.             $whereSql .= " AND ( atopic.`active_topic` != 'n' OR atopic.`active_topic` IS NULL ) ";
  533.             //$whereSql .= " AND atopic.`active_topic` != 'n' ";
  534.         }
  535.  
  536.         // Oracle is very particular about naming multiple columns, so need to explicity name them ORA-00918: column ambiguously defined
  537.         $query =
  538.             "SELECT
  539.                 a.`article_id`, a.`description`, a.`author_name`, a.`publish_date`, a.`expire_date`, a.`rating`,
  540.                 atopic.`topic_id`, atopic.`topic_name`, atopic.`has_topic_image`, atopic.`active_topic`,
  541.                 astatus.`status_id`, astatus.`status_name`,
  542.                 lch.`hits`,
  543.                 atype.*, lc.*, la.`attachment_id` AS `primary_attachment_id`, lf.`file_name` AS `image_attachment_path` $selectSql
  544.             FROM `".BIT_DB_PREFIX."articles` a
  545.                 INNER JOIN      `".BIT_DB_PREFIX."liberty_content`       lc ON( lc.`content_id`         = a.`content_id` )
  546.                 INNER JOIN      `".BIT_DB_PREFIX."article_status`   astatus ON( astatus.`status_id`     = a.`status_id` )
  547.                 LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_content_hits` lch ON( lc.`content_id`         = lch.`content_id` )
  548.                 LEFT OUTER JOIN `".BIT_DB_PREFIX."article_topics`    atopic ON( atopic.`topic_id`       = a.`topic_id` )
  549.                 LEFT OUTER JOIN `".BIT_DB_PREFIX."article_types`      atype ON( atype.`article_type_id` = a.`article_type_id` )
  550.                 LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_attachments`   la ON( la.`content_id`         = lc.`content_id` AND la.`is_primary` = 'y' )
  551.                 LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_files`         lf ON( lf.`file_id`            = la.`foreign_id` )
  552.                 $joinSql
  553.             WHERE lc.`content_type_guid` = ? $whereSql
  554.             ORDER BY ".$this->mDb->convertSortmode$pParamHash['sort_mode');
  555.  
  556.         $query_cant "SELECT COUNT( * )FROM `".BIT_DB_PREFIX."articles` a
  557.             INNER JOIN      `".BIT_DB_PREFIX."liberty_content`    lc ON lc.`content_id`   = a.`content_id`
  558.             LEFT OUTER JOIN `".BIT_DB_PREFIX."article_topics` atopic ON atopic.`topic_id` = a.`topic_id` $joinSql
  559.             LEFT OUTER JOIN `".BIT_DB_PREFIX."article_types`   atype ON atype.`article_type_id` = a.`article_type_id`
  560.             WHERE lc.`content_type_guid` = ? $whereSql";
  561.  
  562.         $result $this->mDb->query$query$bindVars$pParamHash['max_records']$pParamHash['offset');
  563.         $ret array();
  564.         $comment new LibertyComment();
  565.         while $res $result->fetchRow() ) {
  566.             // get this stuff parsed
  567.             $res array_merge$this->parseSplit$res$gBitSystem->getConfig'articles_description_length'500 ))$res );
  568.  
  569.             $res['thumbnail_url'static::getImageThumbnails$res );
  570.             $res['num_comments']  $comment->getNumComments$res['content_id');
  571.             $res['display_url']   self::getDisplayUrlFromHash$res );
  572.             $res['display_link']  $this->getDisplayLink$res['title']$res );
  573.  
  574.             // fetch the primary attachment that we can display the file on the front page if needed
  575.             $res['primary_attachment'LibertyMime::loadAttachment$res['primary_attachment_id');
  576.  
  577.             $ret[$res;
  578.         }
  579.  
  580.         $pParamHash["cant"$this->mDb->getOne$query_cant$bindVars );
  581.  
  582.         LibertyContent::postGetList$pParamHash );
  583.  
  584.         return $ret;
  585.     }
  586.  
  587.     /**
  588.     * Returns include file that will setup vars for display
  589.     * @return the fully specified path to file to be included
  590.     */
  591.     public function getRenderFile()
  592.     {
  593.         return ARTICLES_PKG_PATH."display_article_inc.php";
  594.     }
  595.  
  596.     /**
  597.      * Get a list of articles that are to be published in the future
  598.      *
  599.      * @param array $pParamHash contains listing options - same as getList()
  600.      * @access public
  601.      * @return array of articles
  602.      */
  603.     public function getFutureList(&$pParamHash)
  604.     {
  605.         $pParamHash['get_future'TRUE;
  606.         return$this->getList$pParamHash ));
  607.     }
  608.  
  609.     /**
  610.      * Get list of articles that have expired and are not displayed on the site anymore
  611.      *
  612.      * @param array $pParamHash contains listing options - same as getList()
  613.      * @access public
  614.      * @return array of articles
  615.      */
  616.     public function getExpiredList(&$pParamHash)
  617.     {
  618.         $pParamHash['get_expired'TRUE;
  619.         return$this->getList$pParamHash ));
  620.     }
  621.  
  622.     /**
  623.     * Generates the URL to the article
  624.     * @return the link to the full article
  625.     */
  626.     public static function getDisplayUrlFromHash(&$pParamHash)
  627.     {
  628.         global $gBitSystem;
  629.  
  630.         $ret NULL;
  631.  
  632.         if @BitBase::verifyId$pParamHash['article_id') ) {
  633.             if $gBitSystem->isFeatureActive'pretty_urls_extended' ) ) {
  634.                 // Not needed since it's a number:  $ret = ARTICLES_PKG_URL."view/".$this->mArticleId;
  635.                 $ret ARTICLES_PKG_URL.$pParamHash['article_id'];
  636.             elseif $gBitSystem->isFeatureActive'pretty_urls' ) ) {
  637.                 $ret ARTICLES_PKG_URL.$pParamHash['article_id'];
  638.             else {
  639.                 $ret ARTICLES_PKG_URL."read.php?article_id=".$pParamHash['article_id'];
  640.             }
  641.         }
  642.  
  643.         return $ret;
  644.     }
  645.  
  646.     /**
  647.     * Function that returns link to display an image
  648.     * @return the url to display the gallery.
  649.     */
  650.     public function getDisplayUrl()
  651.     {
  652.         $info array'article_id' => $this->mArticleId );
  653.         return self::getDisplayUrlFromHash$info );
  654.     }
  655.  
  656.     /**
  657.     * get a list of all available statuses
  658.     * @return an array of available statuses
  659.     * @access public
  660.     ***/
  661.     public function getStatusList()
  662.     {
  663.         global $gBitSystem;
  664.         $query "SELECT * FROM `".BIT_DB_PREFIX."article_status`";
  665.         $result $gBitSystem->mDb->query$query );
  666.         return $result->getRows();
  667.     }
  668.  
  669.     /**
  670.     * set the status of an article
  671.     * @param $pStatusId new status id of the article
  672.     * @param $pArticleId of the article that is being changed - if not set, it will attemtp to change the currently loaded article
  673.     * @return new status of article on success - else returns NULL
  674.     * @access public
  675.     ***/
  676.     public function setStatus($pStatusId$pArticleId NULL$pContentId NULL)
  677.     {
  678.         global $gBitSystem;
  679.         $validStatuses arrayARTICLE_STATUS_DENIEDARTICLE_STATUS_DRAFTARTICLE_STATUS_PENDINGARTICLE_STATUS_APPROVEDARTICLE_STATUS_RETIRED );
  680.  
  681.         if !in_array$pStatusId$validStatuses ) ) {
  682.             $this->mErrors["Invalid article status";
  683.             return FALSE;
  684.         }
  685.  
  686.         if(  empty$pContentId and  $this->isValid()) $pContentId $this->mContentId ;
  687.         if(  empty$pArticleId and  $this->isValid()) $pArticleId $this->mArticleId ;
  688.         if!empty$pContentId and !$this->isValid()) $this->mContentId = $pContentId ;
  689.         if!empty$pArticleId and !$this->isValid()) $this->mArticleId = $pArticleId ;
  690.  
  691.         if empty$pArticleId && $this->isValid() ) {
  692.             $pArticleId $this->mArticleId;
  693.         }
  694.  
  695.         if @$this->verifyId$pArticleId ) ) {
  696.             $sql "UPDATE `".BIT_DB_PREFIX."articles` SET `status_id` = ? WHERE `article_id` = ?";
  697.             $rs $this->mDb->query$sqlarray$pStatusId$pArticleId ));
  698.             // Calling the index function for approved articles ...
  699.             if $gBitSystem->isPackageActive'search' ) ) {
  700.                 include_onceSEARCH_PKG_PATH.'refresh_functions.php' );
  701.                 if ($pStatusId == ARTICLE_STATUS_APPROVED{
  702.                     refresh_index($this);
  703.                 elseif (!$pStatusId == ARTICLE_STATUS_RETIRED{
  704.                     delete_index($pContentId)// delete it from the search index unless retired ...
  705.                 }
  706.             }
  707.             return $pStatusId;
  708.         }
  709.     }
  710. }

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