NewsNewsFeaturesDownloadsDevelopmentSupportForumDocumentsAbout Us

Articles Ãþ§O °Ñ¦Ò¤å¥ó
[DAO]

Ãþ§OArticlesªºÄ~©Ó¹Ï:

Model Object ¥þ³¡¦¨­û¦Cªí

¤½¶}¤èªk(Public Methods)

 Articles ()
 getUserArticle ($artId, $userId=-1)
 getBlogArticle ($artId, $blogId=-1, $includeHiddenFields=true, $date=-1, $categoryId=-1, $userId=-1, $status=POST_STATUS_ALL, $maxDate=-1)
 getBlogArticleByTitle ($artTitle, $blogId=-1, $includeHiddenFields=true, $date=-1, $categoryId=-1, $userId=-1, $status=POST_STATUS_PUBLISHED, $maxDate=-1)
 getBlogNextArticle ($article)
 getBlogPrevArticle ($article)
 searchBlogArticles ($blogId, $searchTerms)
 getNumBlogArticles ($blogid, $date=-1, $amount=-1, $categoryId=-1, $status=0, $userId=0, $maxDate=0, $searchTerms="")
 getBlogArticles ($blogid, $date=-1, $amount=-1, $categoryId=0, $status=0, $userId=0, $maxDate=0, $searchTerms="", $page=-1)
 getArticleIdFromName ($articleName)
 getArticlesText ($articleIds)
 getBlogArticlesByQuery ($query)
 getNumberPostsPerMonth ($blogId)
 getNumberPostsPerMonthAdmin ($blogId)
 getNumberPostsPerDay ($blogId, $year=null, $month=null)
 addPostCategoriesLink ($articleId, $categories)
 deletePostCategoriesLink ($articleId)
 updatePostCategoriesLink ($articleId, $categories)
 addArticle (&$newArticle)
 addArticleText ($newArticle)
 getArticleText ($articleId)
 updateArticleText ($article)
 addArticleCustomFields ($artId, $blogId, $fields)
 updateArticle ($article)
 updateArticleCustomFields ($artId, $blogId, $fields)
 updateArticleNumReads ($articleId)
 updateArticleNumReadsByName ($articleName)
 deleteArticle ($artId, $userId, $blogId, $forever=false)
 doesUserOwnArticle ($userinfo, $artid)
 getAllArticles ($maxPosts=0, $date=0)
 deleteBlogPosts ($blogId)
 purgePosts ()
 getArticleCategories ($articleId, $blogId=-1)
 getArticleCategoryIds ($articleId)
 setTimeDiff ($timeDiff)

¤½¶}ÄÝ©Ê

 $categories
 $comments
 $trackbacks
 $users
 $blogs
 $customfields
 $_blogInfo
 $_blogSettings
 $_timeDiff

¨p¦³¤èªk(Private Methods)

 _getBlogArticleFromQuery ($query, $includeHiddenFields)
 buildWhere ($blogid, $date=-1, $amount=-1, $categoryId=0, $status=0, $userId=0, $maxDate=0, $searchTerms="")
 deleteArticleText ($articleId)
 _fillArticleInformation ($query_result, $includeHiddenFields=true)
 _fillArticleHeaderInformation ($query_result, $includeHiddenFields=true)

¸Ô²Ó´y­z

Model for the Articles

©w¸q¦b articles.class.php Àɮפ§²Ä 25 ¦æ.


«Øºc¤l»P¸Ñºc¤l»¡©ú¤å¥ó

Articles::Articles  ) 
 

©w¸q¦b articles.class.php Àɮפ§²Ä 40 ¦æ.

°Ñ¦Ò cache, ¤Î Model::Model().

00041         {
00042             $this->Model();
00043             $this->categories = new ArticleCategories();
00044             $this->comments = new ArticleComments();
00045             $this->trackbacks = new Trackbacks();
00046             $this->users      = new Users();
00047             $this->blogs      = new Blogs();
00048             $this->customfields = new CustomFieldsValues();         
00049             // fine, this is not very nice but it helps a lot, specially if all the classes
00050             // that need to load articles share the same instance       
00051             $this->cache      = Array();    
00052             $this->_blogInfo  = null;
00053             $this->_timeDiff  = 0;
00054             $this->_blogsettings = null;
00055         }


¨ç¦¡¦¨­û»¡©ú¤å¥ó

Articles::_fillArticleHeaderInformation query_result,
includeHiddenFields = true
[private]
 

©w¸q¦b articles.class.php Àɮפ§²Ä 1192 ¦æ.

°Ñ¦Ò $article, $date, cache, ¤Î Timestamp::getDateWithOffset().

01193         {
01194             $id = $query_result['id'];
01195             if( isset($this->cache[$id])) {
01196                 return($this->cache[$id]);
01197             }
01198 
01199             // this is a little dirty trick or otherwise the old
01200             // that don't have the 'properties' field will not work
01201             // as they will appear to have comments disabled
01202             if( $query_result['properties'] == "" ) {
01203                 $tmpArray = Array( 'comments_enabled' => true );
01204                 $query_result['properties'] = serialize($tmpArray);
01205             }
01206 
01207             // ---
01208             // this, i do not like... but I couldn't find a more
01209             // "elegant" way to arrange it! This makes this method
01210             // totally dependant on the blog configuration so it basically
01211             // means an additional query every time we fetch an article
01212             // (just in case we didn't have enough!)
01213             // ---
01214 
01215             //
01216             // if there's a time difference applied to all dates, then we'd better
01217             // calculate it here!!
01218             //
01219             if( $this->_blogInfo == null ) {
01220                 $blogId = $query_result['blog_id'];
01221                 $this->_blogInfo = $this->blogs->getBlogInfo( $blogId );
01222                 $this->_blogSettings = $this->_blogInfo->getSettings();
01223                 $this->_timeDiff = $this->_blogSettings->getValue( 'time_offset' );
01224             }
01225             
01226             // we can use this auxiliary function to help us...
01227             $date = Timestamp::getDateWithOffset( $query_result['date'], $this->_timeDiff );
01228 
01229             // postText does not exist here.. maybe a copy/paste problem? 
01230             // anyway.. it works without postText, so i'll just set this to
01231             // null. oscar, pls double check.. original code:
01232             // $article = new Article( $postText['topic'],
01233             //                         $postText['text'],
01234             //                         NULL,
01235             $article = new Article( NULL,
01236                                     NULL,
01237                                     NULL,
01238                                     $query_result['user_id'],
01239                                     $query_result['blog_id'],
01240                                     $query_result['status'],
01241                                     $query_result['num_reads'],
01242                                     unserialize($query_result['properties']),
01243                                     $query_result['slug'],
01244                                     $query_result['id'] );
01245                                     
01246             // and fill in all the fields with the information we just got from the db
01247             $article->setDate( $date );
01248             $article->setTimeOffset( $this->_timeDiff );
01249             $article->setBlogInfo( $this->_blogInfo );
01250             $article->setUserInfo( $this->users->getUserInfoFromId( $query_result['user_id'] ));            
01251             
01252             return $article;
01253         }       

Articles::_fillArticleInformation query_result,
includeHiddenFields = true
[private]
 

Does exactly the same as _fillUserInformation, so that it can be reused by the different functions that work on articles from the database. This method is private and shouldn't be used outside this class.

©w¸q¦b articles.class.php Àɮפ§²Ä 1121 ¦æ.

°Ñ¦Ò $article, $blogInfo, $category, $date, cache, getArticleCategories(), getArticleText(), ¤Î Timestamp::getDateWithOffset().

³Q°Ñ¦Ò©ó _getBlogArticleFromQuery(), getAllArticles(), ¤Î getUserArticle().

01122         {
01123             $id = $query_result['id'];
01124             if( isset($this->cache[$id])) {
01125                 return($this->cache[$id]);
01126             }
01127 
01128             // this is a little dirty trick or otherwise the old
01129             // that don't have the 'properties' field will not work
01130             // as they will appear to have comments disabled
01131             if( $query_result['properties'] == "" ) {
01132                 $tmpArray = Array( 'comments_enabled' => true );
01133                 $query_result['properties'] = serialize($tmpArray);
01134             }
01135 
01136             // ---
01137             // this, i do not like... but I couldn't find a more
01138             // "elegant" way to arrange it! This makes this method
01139             // totally dependant on the blog configuration so it basically
01140             // means an additional query every time we fetch an article
01141             // (just in case we didn't have enough!)
01142             // ---
01143 
01144             //
01145             // if there's a time difference applied to all dates, then we'd better
01146             // calculate it here!!
01147             //
01148             $blogId = $query_result['blog_id'];
01149             $blogInfo = $this->blogs->getBlogInfo( $blogId );
01150             $blogSettings = $blogInfo->getSettings();
01151             $timeDiff = $blogSettings->getValue( 'time_offset' );
01152 
01153             // we can use this auxiliary function to help us...
01154             $date = Timestamp::getDateWithOffset( $query_result['date'], $timeDiff );
01155 
01156             $articleCategories = $this->getArticleCategories( $query_result['id'], $query_result['blog_id'] );
01157             $categoryIds = Array();
01158             foreach( $articleCategories as $category )
01159                 array_push( $categoryIds, $category->getId());
01160                 
01161             // get the article text
01162             $postText = $this->getArticleText( $query_result['id'] );
01163 
01164             $article = new Article( $postText['topic'],
01165                                     $postText['text'],
01166                                     $categoryIds,
01167                                     $query_result['user_id'],
01168                                     $query_result['blog_id'],
01169                                     $query_result['status'],
01170                                     $query_result['num_reads'],
01171                                     unserialize($query_result['properties']),
01172                                     $query_result['slug'],
01173                                     $query_result['id'] );
01174                                     
01175             // and fill in all the fields with the information we just got from the db
01176             $article->setDate( $date );
01177             $article->setTimeOffset( $timeDiff );
01178             // get information about the categories of the article
01179             $article->setCategories( $articleCategories );
01180             $article->setBlogInfo( $blogInfo );
01181             $article->setUserInfo( $this->users->getUserInfoFromId( $query_result['user_id'] ));            
01182 
01183             // fill in the cache with the result we just loaded
01184             $this->cache[$query_result['id']] = $article;
01185 
01186             return $article;
01187         }

Articles::_getBlogArticleFromQuery query,
includeHiddenFields
[private]
 

©w¸q¦b articles.class.php Àɮפ§²Ä 165 ¦æ.

°Ñ¦Ò $article, $query, $result, _fillArticleInformation(), ¤Î Model::Execute().

³Q°Ñ¦Ò©ó getBlogArticle(), getBlogArticleByTitle(), getBlogNextArticle(), ¤Î getBlogPrevArticle().

00166         {
00167             // we send the query and then fetch the first array with the result
00168             $result = $this->Execute( $query );
00169 
00170             if( $result == false )
00171                 return false;
00172 
00173             if ( $result->RecordCount() == 0)
00174                 return false;
00175 
00176             $row = $result->FetchRow( $result );
00177 
00178             $article = $this->_fillArticleInformation( $row, $includeHiddenFields );
00179             
00180             $result->Close();            
00181 
00182             return $article;        
00183         }

Articles::addArticle &$  newArticle  ) 
 

Adds a new article to the database

°Ñ¼Æ:
newArticle An Article object with all the necessary information.
¶Ç¦^­È:
Returns true if article was added successfully or false otherwise. If successful, it will modify the parmeter passed by reference and set its database id.

©w¸q¦b articles.class.php Àɮפ§²Ä 696 ¦æ.

°Ñ¦Ò $query, $result, addArticleCustomFields(), addArticleText(), addPostCategoriesLink(), ¤Î Model::Execute().

00697         {
00698             // first, we build up the query
00699             $query = "INSERT INTO ".$this->getPrefix()."articles( user_id,blog_id,status,date,properties, slug )
00700                       VALUES ( ".$newArticle->getUser().",".
00701                       $newArticle->getBlog().",'".
00702                       $newArticle->getStatus()."','".
00703                       $newArticle->getDate()."','".
00704                       serialize($newArticle->getProperties())."','".
00705                       $newArticle->getPostSlug()."');";
00706             // and then we send it to the db
00707             //$this->_db->debug=true;
00708             $result = $this->Execute( $query );
00709 
00710             if( !$result ){
00711                 return false;
00712             }
00713 
00714             // get id of the post from the database
00715             $postId = $this->_db->Insert_ID();
00716             
00717             // save the post text
00718             $newArticle->setId( $postId );
00719             $this->addArticleText( $newArticle );
00720 
00721             // and create the link between the post and its categories?
00722             $this->addPostCategoriesLink( $postId, $newArticle->getCategoryIds());
00723 
00724             // and save the custom fields
00725             $this->addArticleCustomFields( $postId, $newArticle->getBlog(), $newArticle->getFields());
00726 
00727             return $postId;
00728         }

Articles::addArticleCustomFields artId,
blogId,
fields
 

Saves the custom fields of an article

°Ñ¼Æ:
artId 
blogId 
fields 
¶Ç¦^­È:
True if successful or false otherwise

©w¸q¦b articles.class.php Àɮפ§²Ä 803 ¦æ.

°Ñ¦Ò getValue().

³Q°Ñ¦Ò©ó addArticle().

00804         {
00805             $customFields = new CustomFieldsValues();
00806 
00807             foreach( $fields as $field ) {
00808                 $customFields->addCustomFieldValue( $field->getFieldId(), $field->getValue(), $artId, $blogId );
00809             }
00810 
00811             return true;
00812         }

Articles::addArticleText newArticle  ) 
 

saves the text of an article to the database

°Ñ¼Æ:
newArticle the Article object that we have just saved
@return true if successful or false otherwise

©w¸q¦b articles.class.php Àɮפ§²Ä 737 ¦æ.

°Ñ¦Ò $query, Model::Execute(), Model::getPrefix(), ¤Î Db::qstr().

³Q°Ñ¦Ò©ó addArticle().

00738         {
00739             $filter = new Textfilter();
00740             $prefix = $this->getPrefix();
00741             $query = "INSERT INTO {$prefix}articles_text
00742                                   (article_id, topic, text, normalized_text, normalized_topic)
00743                       VALUES( '".Db::qstr( $newArticle->getId())."', '".
00744                                 Db::qstr($newArticle->getTopic())."','".
00745                                 Db::qstr($newArticle->getText(false))."','".
00746                                 $filter->normalizeText(Db::qstr($newArticle->getText(false)))."', '".
00747                                 $filter->normalizeText(Db::qstr($newArticle->getTopic()))."')";
00748                                 
00749             return( $this->Execute( $query ));
00750         }

Articles::addPostCategoriesLink articleId,
categories
 

adds records to the table that holds the many-to-many relationship between categories and posts in the blog.

°Ñ¼Æ:
articleId 
categories 
¶Ç¦^­È:
True

©w¸q¦b articles.class.php Àɮפ§²Ä 649 ¦æ.

°Ñ¦Ò $categories, $query, ¤Î Model::Execute().

³Q°Ñ¦Ò©ó addArticle(), ¤Î updatePostCategoriesLink().

00650         {
00651             // nothing to do if the $categories array is not ehem, an array :)
00652             if( !is_array( $categories ))
00653                 return true;
00654                 
00655             foreach( $categories as $categoryId ) {
00656                 $query = "INSERT INTO ".$this->getPrefix()."article_categories_link
00657                           (article_id, category_id) VALUES ($articleId, $categoryId )";
00658                 $this->Execute( $query );
00659             }
00660 
00661             return true;
00662         }

Articles::buildWhere blogid,
date = -1,
amount = -1,
categoryId = 0,
status = 0,
userId = 0,
maxDate = 0,
searchTerms = ""
[private]
 

builds a WHERE clause for a query

©w¸q¦b articles.class.php Àɮפ§²Ä 255 ¦æ.

°Ñ¦Ò $date, $query, ¤Î Model::getPrefix().

³Q°Ñ¦Ò©ó getBlogArticles(), ¤Î getNumBlogArticles().

00256         {
00257             $postStatus = $status;
00258             $prefix = $this->getPrefix();
00259             if($blogid == -1){
00260                 $query = "a.blog_id = a.blog_id";
00261             }
00262             else{
00263                 $query = "a.blog_id = ".Db::qstr($blogid);
00264             }
00265             if( $date != -1 ) {
00266                 // consider the time difference
00267                 $blogSettings = $this->blogs->getBlogSettings( $blogid );
00268                 $timeDifference = $blogSettings->getValue( "time_offset" );
00269                 $SecondsDiff = $timeDifference * 3600;
00270                 $query .= " AND FROM_UNIXTIME(UNIX_TIMESTAMP(a.date)+$SecondsDiff)+0 LIKE '$date%'";
00271             }
00272 
00273             // the common part "c.id = a.category_id" is needed so that
00274             // we don't get one article row as many times as the amount of categories
00275             // we have... due to the sql 'join' operation we're carrying out
00276             if( $categoryId == -1 )
00277                 $query .= " AND c.id = l.category_id AND a.id = l.article_id ";
00278             else {
00279                 if( $categoryId > 0 )
00280                     $query .= " AND a.id = l.article_id AND l.category_id = $categoryId AND c.id = l.category_id";
00281                 else {
00282                     $query .= " AND c.id = l.category_id AND a.id = l.article_id AND c.in_main_page = 1";
00283                 }
00284             }
00285 
00286             if( $status > 0 )
00287                 $query .= " AND a.status = '$postStatus'";
00288             if( $userId > 0 )
00289                 $query .= " AND a.user_id = ".Db::qstr($userId);
00290             if( $maxDate > 0 )
00291                 $query .= " AND a.date <= '$maxDate'";
00292                 
00293             // in case there were some search terms specified as parameters...
00294             if( $searchTerms != "" ) {
00295                 // load the class dynamically so that we don't have to waste memory
00296                 // if we're not going to need it!
00297                 include_once( PLOG_CLASS_PATH."class/dao/searchengine.class.php" );         
00298                 $searchEngine = new SearchEngine();
00299                 
00300                 // prepare the query string
00301                 $searchTerms = $searchEngine->_adaptSearchString( $searchTerms );
00302                 $whereString = $searchEngine->_generateSearchArticlesWhereString( $searchTerms );
00303                 
00304                 // and add it to the current search
00305                 $query .=" AND {$whereString} ";    
00306             }
00307                 
00308             if( $categoryId <= 0 )
00309                 $query .= " GROUP BY a.id ";
00310 
00311                 
00312             return $query;
00313         }

Articles::deleteArticle artId,
userId,
blogId,
forever = false
 

Removes an article from the database

If forever == true, the article is physically removed from the database. Otherwise, the 'status' field is set to 'deleted'

Problem is, that MySQL will automatically update the 'date' field because he feels like it... even if we explicitely say date = old_date... grrreat :P

Valid article identifier, blog identifier and user identifier are required to remove an article. It was done for security reasons and to make perfectly clear that we are removing an article (so that we wouldn't be deleting the wrong one if there was any bug!)

°Ñ¼Æ:
artId A valid article identifier
userid A valid user identifier
blogId A valid blog identifier
forever A boolean meaning whether the post should be removed forever or simply its status should be set to 'deleted'
¶Ç¦^­È:
Returns true if successful or false otherwise.

©w¸q¦b articles.class.php Àɮפ§²Ä 939 ¦æ.

°Ñ¦Ò $comments, $query, $result, $trackbacks, deleteArticleText(), deletePostCategoriesLink(), ¤Î Model::Execute().

³Q°Ñ¦Ò©ó deleteBlogPosts(), ¤Î purgePosts().

00940         {
00941             if( $forever ) {
00942                 $query = "DELETE FROM ".$this->getPrefix()."articles WHERE id = ".$artId." AND user_id = ".$userId." AND blog_id = ".$blogId.";";
00943                 // -- text --
00944                 $this->deleteArticleText( $artId );
00945                 // we also have to remove its comments and trackbacks if the article is being deleted forever
00946                 // -- comments --
00947                 $comments = new ArticleComments();
00948                 $comments->deletePostComments( $artId );
00949                 // -- trackbacks --
00950                 $trackbacks = new Trackbacks();
00951                 $trackbacks->deletePostTrackbacks( $artId );
00952                 // -- post-to-categories mappings --
00953                 $this->deletePostCategoriesLink( $artId );
00954                 // -- custom fields --
00955                 $customFields = new CustomFieldsValues();
00956                 $customFields->removeArticleCustomFields( $artId );
00957             }
00958             else {
00959                 $query = "UPDATE ".$this->getPrefix()."articles SET date = date, status = 3 WHERE id = ".$artId." AND user_id = ".$userId." AND blog_id = ".$blogId.";";
00960             }
00961 
00962             $result = $this->Execute( $query );
00963 
00964             if( !$result )
00965                 return false;
00966 
00967             if( $this->_db->Affected_Rows() == 0 )
00968                 return false;
00969 
00970             return true;
00971         }

Articles::deleteArticleText articleId  )  [private]
 

removes the text of an article

°Ñ¼Æ:
articleId 
¶Ç¦^­È:
true if successful or false otherwise
°Ñ¾\:
Articles::deleteArticle

©w¸q¦b articles.class.php Àɮפ§²Ä 981 ¦æ.

°Ñ¦Ò $articleId, $query, Model::Execute(), ¤Î Db::qstr().

³Q°Ñ¦Ò©ó deleteArticle().

00982         {
00983             $query = "DELETE FROM ".$this->getPrefix()."articles_text WHERE article_id = '".Db::qstr($articleId)."'";
00984             
00985             return( $this->Execute( $query ));
00986         }

Articles::deleteBlogPosts blogId  ) 
 

Removes all the posts from the given blog

°Ñ¼Æ:
blogId The blog identifier

©w¸q¦b articles.class.php Àɮפ§²Ä 1045 ¦æ.

°Ñ¦Ò $article, deleteArticle(), ¤Î getBlogArticles().

01046         {
01047             $blogArticles = $this->getBlogArticles( $blogId );
01048 
01049             foreach( $blogArticles as $article ) {
01050                 // the deleteArticle method will also take care of removing comments and
01051                 // trackbacks
01052                 $this->deleteArticle( $article->getId(), $article->getUser(), $article->getBlog(), true );
01053             }
01054 
01055             return true;
01056         }

Articles::deletePostCategoriesLink articleId  ) 
 

removes the relationship between posts and categories from the database. This method should only be used when removing an article!!

©w¸q¦b articles.class.php Àɮפ§²Ä 668 ¦æ.

°Ñ¦Ò $query, ¤Î Model::Execute().

³Q°Ñ¦Ò©ó deleteArticle(), ¤Î updatePostCategoriesLink().

00669         {
00670             $query = "DELETE FROM ".$this->getPrefix()."article_categories_link
00671                       WHERE article_id = $articleId";
00672 
00673             return $this->Execute( $query );
00674         }

Articles::doesUserOwnArticle userinfo,
artid
 

returns true if the user posted this article/post, or false if he or she doesn't own it

°Ñ¼Æ:
userInfo A UserInfo object with information about the user
artId A valid article identifier
¶Ç¦^­È:
Returns true if the article is owned by the user or false otherwise.

©w¸q¦b articles.class.php Àɮפ§²Ä 996 ¦æ.

°Ñ¦Ò $article.

00997         {
00998             $article = $this->getArticle( $artid );
00999             $articleOwnerInfo = $article->getUserInfo();
01000 
01001             if( $articleOwnerInfo->getId() == $userinfo->getId())
01002                 return true;
01003             else
01004                 return false;
01005         }

Articles::getAllArticles maxPosts = 0,
date = 0
 

Returns all the posts in the database or the 'maxPosts' recent ones that have been published (status=='published')

°Ñ¼Æ:
maxPosts The amount of post we want.
¶Ç¦^­È:
Returns an array of Article objects containing the information about the posts.

©w¸q¦b articles.class.php Àɮפ§²Ä 1014 ¦æ.

°Ñ¦Ò $date, $query, $result, _fillArticleInformation(), ¤Î Model::Execute().

01015         {
01016             $query = "SELECT * FROM ".$this->getPrefix()."articles WHERE status = 1";
01017             if( $date > 0 )
01018                 $query .= " AND date < '$date'";
01019 
01020             $query .= " ORDER BY date DESC";
01021 
01022             if( $maxPosts > 0 )
01023                 $query .= " LIMIT 0,".$maxPosts;
01024 
01025             $result = $this->Execute( $query );
01026 
01027             if( !$result )
01028                 return false;
01029 
01030             $posts = Array();
01031             while( $row = $result->FetchRow()) {
01032                 $posts[] = $this->_fillArticleInformation( $row );
01033             }
01034             
01035             $result->Close();            
01036 
01037             return $posts;
01038         }

Articles::getArticleCategories articleId,
blogId = -1
 

returns all the categories that an article has been assigned to

©w¸q¦b articles.class.php Àɮפ§²Ä 1083 ¦æ.

°Ñ¦Ò $articleId.

³Q°Ñ¦Ò©ó _fillArticleInformation().

01084         {
01085             return $this->categories->getArticleCategories( $articleId, $blogId );
01086         }

Articles::getArticleCategoryIds articleId  ) 
 

returns all the categories that an article has been assigned to

©w¸q¦b articles.class.php Àɮפ§²Ä 1091 ¦æ.

°Ñ¦Ò $categories, $query, $result, ¤Î Model::Execute().

01092         {
01093             $query = "SELECT category_id FROM ".$this->getPrefix()."article_categories_link
01094                       WHERE article_id = $articleId";
01095 
01096             $result = $this->Execute( $query );
01097 
01098             // it's impossible that an article has no categories, but
01099             // we'll bear with it...
01100             if( !$result )
01101                 return Array();
01102 
01103             // otherwise, fetch them
01104             $categories = Array();
01105             while( $row = $result->FetchRow()) {
01106                 $categories[] = $row['category_id'];
01107             }
01108             
01109             $result->Close();            
01110 
01111             return $categories;
01112         }

Articles::getArticleIdFromName articleName  ) 
 

Takes an article name and returns the id

°Ñ¼Æ:
articleName an article "name" (the post 'slug')
¶Ç¦^­È:
articleId or 0 if unsuccessful

©w¸q¦b articles.class.php Àɮפ§²Ä 462 ¦æ.

00462                                                    {
00463             $query = "SELECT id FROM ".$this->getPrefix()."articles ".
00464                      " WHERE slug = '".Db::qstr($articleName)."'";
00465 
00466             $result = $this->Execute($query);
00467 
00468             if($row = $result->FetchRow()){
00469               $result->Close();            
00470               if($row["id"])
00471                 return $row["id"];
00472             }
00473             return 0;
00474         }       

Articles::getArticlesText articleIds  ) 
 

returns the text of a bunch of articles, given their ids

°Ñ¼Æ:
articleIds 
¶Ç¦^­È:
an array, where the key is the article id and the value is an another associative array with the text and topics of the articles

©w¸q¦b articles.class.php Àɮפ§²Ä 485 ¦æ.

00486         {
00487             $prefix = $this->getPrefix();
00488             $query = "SELECT article_id,text,topic FROM {$prefix}articles_text WHERE
00489                       article_id IN (".$articleIds.")";
00490                       
00491             $result = $this->Execute( $query );
00492 
00493             // it's impossible that an article has no categories, but
00494             // we'll bear with it...
00495             if( !$result )
00496                 return Array();
00497 
00498             // otherwise, fetch them
00499             while ($row = $result->FetchRow()) {
00500                 $lastArticleId=$row["article_id"];
00501                 $postTexts[$lastArticleId]=$row;
00502             }
00503             
00504             $result->Close();           
00505             
00506             return( $postTexts );
00507         }

Articles::getArticleText articleId  ) 
 

returns the text fields of an article

°Ñ¼Æ:
articleId 
¶Ç¦^­È:
an array

©w¸q¦b articles.class.php Àɮפ§²Ä 758 ¦æ.

°Ñ¦Ò $articleId, $query, $result, Model::Execute(), ¤Î Model::getPrefix().

³Q°Ñ¦Ò©ó _fillArticleInformation().

00759         {
00760             $prefix = $this->getPrefix();
00761             $query = "SELECT text,topic FROM {$prefix}articles_text
00762                       WHERE article_id = '".Db::qstr($articleId)."'";
00763                       
00764             $result = $this->Execute( $query );
00765             
00766             if( !$result ) 
00767                 return false;
00768                 
00769             $row = $result->FetchRow();
00770             
00771             $result->Close();
00772             
00773             return( $row );         
00774         }

Articles::getBlogArticle artId,
blogId = -1,
includeHiddenFields = true,
date = -1,
categoryId = -1,
userId = -1,
status = POST_STATUS_ALL,
maxDate = -1
 

Gets an article from the database, given its id

°Ñ¼Æ:
artId Identifier of the article we want to fetch
blogId If set, the article must belong to the given blog
¶Ç¦^­È:
Returns an Article object or 'false' otherwise.

©w¸q¦b articles.class.php Àɮפ§²Ä 94 ¦æ.

°Ñ¦Ò $date, $query, _getBlogArticleFromQuery(), ¤Î Model::getPrefix().

00095         {
00096             $prefix = $this->getPrefix();
00097             $query = "SELECT a.id, a.date,
00098                              a.user_id,a.blog_id,a.status,a.properties,
00099                              a.num_reads, a.slug FROM {$prefix}articles a ";
00100             // thanks jon for the tip :) You're right that the amount of rows will be too big if we don't really need these
00101             // fields!
00102             if($categoryId != -1 && $blogId != -1) {
00103                 $query .= ", {$prefix}articles_categories c, {$prefix}article_categories_link l ";
00104             }
00105             
00106             $query .= "WHERE a.id = ".Db::qstr($artId);
00107                      
00108             if( $blogId != -1 )
00109                 $query .= " AND a.blog_id = ".Db::qstr($blogId);
00110             if( $date != -1 && $maxDate == -1 ) {
00111                 $query .= " AND a.date+0 LIKE '$date%'";
00112             } elseif ( $date != -1 && $maxDate != -1 ) {
00113                 $query .= " AND a.date+0 >= $date AND a.date+0 <= $maxDate";
00114             }
00115             if( $userId != -1 ) 
00116                 $query .= " AND a.user_id = ".Db::qstr($userId);
00117             if( $categoryId != -1 )
00118                 $query .= " AND c.id = ".Db::qstr($categoryId)." AND c.id = l.category_id AND a.id = l.article_id";
00119             if( $status != POST_STATUS_ALL )
00120                 $query .= " AND a.status = $status;";
00121                 
00122             return $this->_getBlogArticleFromQuery( $query, $includeHiddenFields );
00123         }

Articles::getBlogArticleByTitle artTitle,
blogId = -1,
includeHiddenFields = true,
date = -1,
categoryId = -1,
userId = -1,
status = POST_STATUS_PUBLISHED,
maxDate = -1
 

Gets an article from the database, given its slug, this is used with the fancy permalinks

°Ñ¼Æ:
artTitle Identifier of the article we want to fetch
blogId If set, the article must belong to the given blog
¶Ç¦^­