Source for file ArticleObject.inc
Documentation is available at ArticleObject.inc
require_once $config->get('sysRoot'). 'alpha/model/AlphaDAO.inc';
require_once $config->get('sysRoot'). 'alpha/model/ArticleVoteObject.inc';
require_once $config->get('sysRoot'). 'alpha/model/ArticleCommentObject.inc';
require_once $config->get('sysRoot'). 'alpha/model/TagObject.inc';
require_once $config->get('sysRoot'). 'alpha/controller/front/FrontController.inc';
* An article class for the CMS
* @author John Collins <dev@alphaframework.org>
* @version $Id: ArticleObject.inc 1341 2011-03-17 15:02:02Z johnc $
* @license http://www.opensource.org/licenses/bsd-license.php The BSD License
* @copyright Copyright (c) 2011, John Collins (founder of Alpha Framework).
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the
* following conditions are met:
* * Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
* * Neither the name of the Alpha Framework nor the names
* of its contributors may be used to endorse or promote
* products derived from this software without specific
* prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* The article site section
* The description of the article
* Optional custom body onload Javascript
* Any custom HTML header content (e.g. Javascript) for the article
* The author of the article
* A boolean to control whether the artcile is publically accessible or not
* A Relation containing all of the comments on this article
* A Relation containing all of the votes on this article
* A Relation containing all of the tags on this article
* An array of all of the attributes on this BO which are tagged
* Path to a .text file where the content of this article is stored (optional)
* An array of data display labels for the class properties
protected $dataLabels = array("OID"=> "Article ID#","title"=> "Title","section"=> "Site Section","description"=> "Description","bodyOnload"=> "Body onload Javascript","content"=> "Content","headerContent"=> "HTML Header Content","author"=> "Author","created_ts"=> "Date Added","updated_ts"=> "Date of last Update","published"=> "Published","URL"=> "URL","printURL"=> "Printer version URL","comments"=> "Comments","votes"=> "Votes","tags"=> "Tags");
* The name of the database table for the class
* The URL for this article (transient)
* The print URL for this article (transient)
private static $logger = null;
* The constructor which sets up some housekeeping attributes
self::$logger = new Logger('ArticleObject');
// ensure to call the parent constructor
$this->title->setHelper('Please provide a title for the article.');
$this->title->setSize(100);
$this->title->setRule("/\w+/");
$this->description->setHelper('Please provide a brief description of the article.');
$this->content->setHelper('Please provide some content for the article.');
$this->author->setHelper('Please state the name of the author of this article');
$this->author->setRule("/\w+/");
$this->comments->setRelatedClass('ArticleCommentObject');
$this->comments->setRelatedClassField('articleOID');
$this->comments->setRelatedClassDisplayField('content');
$this->comments->setRelationType('ONE-TO-MANY');
$this->votes->setRelatedClass('ArticleVoteObject');
$this->votes->setRelatedClassField('articleOID');
$this->votes->setRelatedClassDisplayField('score');
$this->votes->setRelationType('ONE-TO-MANY');
$this->tags->setRelatedClass('TagObject');
$this->tags->setRelatedClassField('taggedOID');
$this->tags->setRelatedClassDisplayField('content');
$this->tags->setRelationType('ONE-TO-MANY');
// mark the URL attributes as transient
* After creating a new ArticleObject, tokenize the description field to form a set
* of automated tags and save them.
* The unique key has most-likely been violated because this BO is already tagged with this
* value, so we can ignore in this case.
* Set up the transient URL attributes for the artcile after it has loaded
* Set up the transient URL attributes for the article after it has loaded
// check the config to see if we are using mod_rewrite
if($config->get('sysUseModRewrite')) {
// check to see if an alias is registered for the view_article_title controller, otherwise use the long URL version
if(isset ($front) && $front->hasAlias('ViewArticleTitle')) {
$alias = $front->getControllerAlias('ViewArticleTitle');
$this->URL = $config->get('sysURL'). $alias. '/'. str_replace(' ', '_', $this->title->getValue());
$this->URL = $config->get('sysURL'). 'ViewArticleTitle/title/'. str_replace(' ', '_', $this->title->getValue());
$this->URL = $config->get('sysURL'). 'alpha/controller/ViewArticle.php?oid='. $this->getID();
// now set up the print version URL
if($config->get('sysUseModRewrite')) {
// check to see if an alias is registered for the view_article_title controller, otherwise use the long URL version
if(isset ($front) && $front->hasAlias('ViewArticlePrint')) {
$alias = $front->getControllerAlias('ViewArticlePrint');
$this->printURL = $config->get('sysURL'). 'alpha/controller/ViewArticlePrint.php?title='. $this->title->getValue();
* Gets an array of the OIDs of the most recent articles added to the system (by date), from the newest
* article to the amount specified by the $limit
$denum = new DEnum('ArticleObject::section');
$excludeID = $denum->getOptionID('Main');
$sqlQuery = "SELECT OID FROM ". self::TABLE_NAME. " WHERE published='1' AND section!='$excludeID' ORDER BY dateAdded DESC LIMIT 0, $limit;";
'], query ['. $sqlQuery. ']');
while($row = $result->fetch_array(MYSQLI_ASSOC)) {
* Generates the location of the attachments folder for this article
return $config->get('sysRoot'). 'attachments/article_'. $this->getID();
* Generates the URL of the attachments folder for this article
return $config->get('sysURL'). 'attachments/article_'. $this->getID();
* Generates a secure URL for downloading an attachment file via the ViewAttachment controller
* @param string $filename
* Creates the attachment folder for the article on the server.
// create the attachment directory for the article
// ...and set write permissions on the folder
* Method for returning the calculated score for this article
$vote_count = count($votes);
for($i = 0; $i < $vote_count; $i++ ){
$total_score += $votes[$i]->get('score');
$score = $total_score/ $vote_count;
* Method for fetching all of the votes for this article
* @return array An array of ArticleVoteObject objects
$votes = $this->votes->getRelatedObjects();
* Method to determine if the logged-in user has already voted for this article
* @return boolean True if they have voted already, false otherwise
// just going to return true if nobody is logged in
if (!isset ($_SESSION['currentUser']))
$userID = $_SESSION['currentUser']->getID();
$sqlQuery = "SELECT COUNT(*) AS usersVote FROM ". ArticleVoteObject::TABLE_NAME. " WHERE articleOID='". $this->OID. "' AND personOID='". $userID. "';";
$row = $result->fetch_array(MYSQLI_ASSOC);
if($row['usersVote'] == "0")
* Method for fetching all of the comments for this article
* @return array An array of ArticleCommentObject objects
$comments = $this->comments->getRelatedObjects();
* Loads the content of the ArticleObject from the specified file path
* @throws FileNotFoundException
$this->filePath = $filePath;
* Returns true if the article content was loaded from a .text file, false otherwise.
return ($this->filePath == '' ? false: true);
* Returns the timestamp of when the content .text file for this article was last
* @throws FileNotFoundException
if($this->filePath != '') {
|