Source for file BitArticleTopic.php
Documentation is available at BitArticleTopic.php
* @copyright Copyright (c) 2004-2006, bitweaver.org
* All Rights Reserved. See below for details and a complete list of authors.
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details.
require_once( KERNEL_PKG_PATH. "BitBase.php" );
require_once( ARTICLES_PKG_PATH. 'BitArticle.php' );
public function __construct($iTopicId = NULL, $iTopicName = NULL)
if ($iTopicId || $iTopicName) {
$this->loadTopic(array('topic_id'=> $iTopicId, 'topic_name'=> $iTopicName));
public function loadTopic($iParamHash = NULL)
$whereSQL = ' WHERE artt.';
if (@$this->verifyId($iParamHash['topic_id']) || !empty($iParamHash['topic_name'])) {
$whereSQL .= "`". ((@$this->verifyId($iParamHash['topic_id']) || $this->mTopicId) ? 'topic_id' : 'topic_name'). "` = ?";
$bindVars = array((@$this->verifyId($iParamHash['topic_id']) ? (int) $iParamHash['topic_id'] : ($this->mTopicId ? $this->mTopicId : $iParamHash['topic_name'])) );
$this->mInfo = $this->mDb->getRow($sql, $bindVars);
if( !empty( $this->mInfo['topic_id'] ) ) {
if ($this->mInfo['has_topic_image']) {
$this->mInfo['topic_image_url'] = NULL;
public function verify(&$iParamHash)
// Validate the (optional) topic_id parameter
if (@$this->verifyId($iParamHash['topic_id'])) {
$cleanHash['topic_id'] = (int) $iParamHash['topic_id'];
$cleanHash['topic_id'] = NULL;
// Was an acceptable name given?
if (empty($iParamHash['topic_name']) || ($iParamHash['topic_name'] == '')) {
$this->mErrors['topic_name'] = tra("Invalid or blank topic name supplied");
} elseif (empty($iParamHash['topic_id'])) {
$ret = $this->getTopicList( array( 'topic_name' => $iParamHash['topic_name'] ) );
$this->mErrors['topic_name'] = 'Topic "'. $iParamHash['topic_name']. '" already exists. Please choose a different name.';
$cleanHash['topic_name'] = $iParamHash['topic_name'];
$cleanHash['topic_name'] = $iParamHash['topic_name'];
// Whether the topic is active or not
if ( empty($iParamHash['active_topic']) || (strtoupper($iParamHash['active_topic']) != 'CHECKED' && strtoupper($iParamHash['active_topic']) != 'ON' && strtoupper($iParamHash['active_topic']) != 'Y')) {
if (@$this->verifyId($cleanHash['topic_id'])) {
$cleanHash['active_topic'] = 'n';
// Probably a new topic so lets go ahead and enable it
$cleanHash['active_topic'] = 'y';
$cleanHash['active_topic'] = 'y';
if (empty($iParamHash['created'])) {
$cleanHash['created'] = $gBitSystem->getUTCTime();
$iParamHash = $cleanHash;
if ($this->verify($iParamHash)) {
if (!$iParamHash['topic_id']) {
$topicId = $this->mDb->GenID('article_topics_id_seq');
if( !empty( $_FILES['upload'] ) && $_FILES['upload']['tmp_name'] ) {
if( $checkFunc( $_FILES['upload']['type'] )) {
$fileHash = $_FILES['upload'];
$fileHash['source_file'] = $fileHash['tmp_name'];
$iParamHash['has_topic_image'] = 'y';
$this->mErrors = tra( "The file you uploaded doesn't appear to be a valid image. The reported mime type is" ). ": ". $_FILES['upload']['type'];
if( $iParamHash['topic_id'] ) {
$this->mDb->associateUpdate( BIT_DB_PREFIX. "article_topics", $iParamHash, array( 'topic_id' => $iParamHash['topic_id'] ) );
$iParamHash['topic_id'] = $topicId;
$this->mTopicId = $iParamHash['topic_id'];
* Work out the path to the image for this article
* @param $pTopicId id of the article we need the image path for
* @param $pBasePathOnly bool TRUE / FALSE - specify whether you want full path or just base path
* @return path on success, FALSE on failure
if( @BitBase::verifyId( $pTopicId )) {
$ret = LibertyMime::getStorageUrl( 'topics/'. $pTopicId );
* Get the full URL to the needed thumbnail
* @param numeric $pTopicId Topic ID of topic in question
* @return Path to thumbnail, FALSE on failure
if ( @BitBase::verifyId( $pTopicId )) {
'default_image' => $gBitSystem->getConfig( 'articles_image_size', 'small' )
if ( !empty( $pOptionHash['active_topic'] ) ) {
$where = " WHERE artt.`active_topic` = 'y' ";
if ( !empty( $pOptionHash['topic_name'] ) ) {
$where = " WHERE artt.`topic_name` = ? ";
$bindVars[] = $pOptionHash['topic_name'];
$where ORDER BY artt.`topic_name`";
$result = $gBitSystem->mDb->query( $query, $bindVars );
while ( $res = $result->fetchRow() ) {
$res["num_articles"] = $gBitSystem->mDb->getOne( "SELECT COUNT(*) FROM `". BIT_DB_PREFIX. "articles` WHERE `topic_id`= ?", array( $res["topic_id"] ) );
if ( empty( $res['topic_image_url'] ) && $res['has_topic_image'] == 'y' ) {
$sql = "UPDATE `". BIT_DB_PREFIX. "article_topics` SET `has_topic_image` = 'n' WHERE `topic_id` = ?";
$this->mInfo['has_topic_image'] = 'n';
$sql = "UPDATE `". BIT_DB_PREFIX. "article_topics` SET `active_topic` = '". ($iIsActive ? 'y' : 'n'). "' WHERE `topic_id` = ?";
$this->mInfo['active_topic'] = ($iIsActive ? 'y' : 'n');
$sql = "SELECT `article_id` FROM `". BIT_DB_PREFIX. "articles` WHERE `topic_id` = ?";
while ($row = $rs->fetchRow()) {
if ($iRemoveArticles == TRUE) {
for ($articleCount = 0; $articleCount < count($topicArticles); $articleCount++ ) {
$topicArticles[$articleCount]->expunge();
$sql = "UPDATE `". BIT_DB_PREFIX. "articles` SET `topic_id` = ? WHERE `topic_id` = ?";
$rs = $this->mDb->query($sql, array(NULL, $this->mTopicId));
$sql = "DELETE FROM `". BIT_DB_PREFIX. "article_topics` WHERE `topic_id` = ?";
/*****************************************************************************
* Image functions needed for backward compatability - these are needed to *
* handle old article image style images that are not attachments. generally *
* these functions are deprecated but needed for legacy code *
****************************************************************************/
* Get the name of the article image file
* @param array $pTopicId article id
* @return TRUE on success, FALSE on failure
if ( !@BitBase::verifyId( $pTopicId ) ) {
return "topic_$pTopicId.". $gBitSystem->getConfig( 'liberty_thumbnail_format', 'jpg' );
* Work out the path to the image for this article
* @param $pTopicId id of the article we need the image path for
* @param $pBasePathOnly bool TRUE / FALSE - specify whether you want full path or just base path
* @return path on success, FALSE on failure
if ( !@BitBase::verifyId( $pTopicId ) ) {
if ( !empty( $pTopicId ) ) {
* Work out the URL to the image for this article
* @param $pTopicId id of the article we need the image path for
* @param $pBasePathOnly bool TRUE / FALSE - specify whether you want full path or just base path
* @return URL on success, FALSE on failure
// first we check to see if this is a new type thumbnail. if that fails we'll use the old method
if ( !@BitBase::verifyId( $pTopicId ) ) {
/*****************************************************************************
* Image functions needed for backward compatability - these are needed to *
* handle old article image style images that are not attachments. generally *
* these functions are deprecated but needed for legacy code *
* the legacy code below here should go at some point. this code is old and *
* fugly. In fact, a lot of the code in here is fugly. we should use *
* pigoenholes to do this topic thing, now that pigoenholes can have primary *
****************************************************************************/
* Get the name of the article image file
* @param array $pArticleId article id
* @return TRUE on success, FALSE on failure
if ( !@BitBase::verifyId( $pArticleId ) ) {
$pArticleId = $this->mArticleId;
return "article_$pArticleId.jpg";
* Work out the path to the image for this article
* @param $pArticleId id of the article we need the image path for
* @param $pBasePathOnly bool TRUE / FALSE - specify whether you want full path or just base path
* @return path on success, FALSE on failure
if( !@BitBase::verifyId( $pArticleId ) ) {
$pArticleId = $this->mArticleId;
if ( !empty( $pArticleId ) ) {
* Work out the URL to the image for this article
* @param $pArticleId id of the article we need the image path for
* @param $pBasePathOnly bool TRUE / FALSE - specify whether you want full path or just base path
* @return URL on success, FALSE on failure
$url = STORAGE_PKG_URL. ARTICLES_PKG_NAME. '/';
if( !@BitBase::verifyId( $pArticleId ) ) {
$pArticleId = $this->mArticleId;
|