setId((int)$id);
}
/**
* Method to set the article id
*
* @access public
* @param int Article ID number
*/
function setId($id)
{
// Set new article ID and wipe data
$this->_id = $id;
$this->_article = null;
}
/**
* Overridden set method to pass properties on to the article
*
* @access public
* @param string $property The name of the property
* @param mixed $value The value of the property to set
* @return boolean True on success
* @since 1.5
*/
function set( $property, $value=null )
{
if ($this->_loadArticle()) {
$this->_article->$property = $value;
return true;
} else {
return false;
}
}
/**
* Overridden get method to get properties from the article
*
* @access public
* @param string $property The name of the property
* @param mixed $value The value of the property to set
* @return mixed The value of the property
* @since 1.5
*/
function get($property, $default=null)
{
if ($this->_loadArticle()) {
if(isset($this->_article->$property)) {
return $this->_article->$property;
}
}
return $default;
}
/**
* Method to get content article data for the frontpage
*
* @since 1.5
*/
function &getArticle()
{
// Load the Category data
if ($this->_loadArticle())
{
$user = & JFactory::getUser();
// Is the category published?
if (!$this->_article->cat_pub && $this->_article->catid) {
JError::raiseError( 404, JText::_("Article category not published") );
}
// Is the section published?
if ($this->_article->sectionid)
{
if ($this->_article->sec_pub === null)
{
// probably a new item
// check the sectionid probably passed in the request
$db =& $this->getDBO();
$query = 'SELECT published' .
' FROM #__sections' .
' WHERE id = ' . (int) $this->_article->sectionid;
$db->setQuery( $query );
$this->_article->sec_pub = $db->loadResult();
}
if (!$this->_article->sec_pub)
{
JError::raiseError( 404, JText::_("Article section not published") );
}
}
// Do we have access to the category?
if (($this->_article->cat_access > $user->get('aid', 0)) && $this->_article->catid) {
JError::raiseError( 403, JText::_("ALERTNOTAUTH") );
}
// Do we have access to the section?
if (($this->_article->sec_access > $user->get('aid', 0)) && $this->_article->sectionid) {
JError::raiseError( 403, JText::_("ALERTNOTAUTH") );
}
$this->_loadArticleParams();
}
else
{
$user =& JFactory::getUser();
$article =& JTable::getInstance('content');
$article->state = 1;
$article->cat_pub = null;
$article->sec_pub = null;
$article->cat_access = null;
$article->sec_access = null;
$article->author = null;
$article->created_by = $user->get('id');
$article->parameters = new JParameter( '' );
$article->text = '';
$this->_article = $article;
}
return $this->_article;
}
/**
* Method to increment the hit counter for the article
*
* @access public
* @return boolean True on success
* @since 1.5
*/
function hit()
{
global $mainframe;
if ($this->_id)
{
$article = & JTable::getInstance('content');
$article->hit($this->_id);
return true;
}
return false;
}
/**
* Tests if article is checked out
*
* @access public
* @param int A user id
* @return boolean True if checked out
* @since 1.5
*/
function isCheckedOut( $uid=0 )
{
if ($this->_loadArticle())
{
if ($uid) {
return ($this->_article->checked_out && $this->_article->checked_out != $uid);
} else {
return $this->_article->checked_out;
}
} elseif ($this->_id < 1) {
return false;
} else {
JError::raiseWarning( 0, 'Unable to Load Data');
return false;
}
}
/**
* Method to checkin/unlock the article
*
* @access public
* @return boolean True on success
* @since 1.5
*/
function checkin()
{
if ($this->_id)
{
$article = & JTable::getInstance('content');
return $article->checkin($this->_id);
}
return false;
}
/**
* Method to checkout/lock the article
*
* @access public
* @param int $uid User ID of the user checking the article out
* @return boolean True on success
* @since 1.5
*/
function checkout($uid = null)
{
if ($this->_id)
{
// Make sure we have a user id to checkout the article with
if (is_null($uid)) {
$user =& JFactory::getUser();
$uid = $user->get('id');
}
// Lets get to it and checkout the thing...
$article = & JTable::getInstance('content');
return $article->checkout($uid, $this->_id);
}
return false;
}
/**
* Method to store the article
*
* @access public
* @return boolean True on success
* @since 1.5
*/
function store($data)
{
global $mainframe;
$article =& JTable::getInstance('content');
$user =& JFactory::getUser();
$dispatcher =& JDispatcher::getInstance();
JPluginHelper::importPlugin('content');
// Bind the form fields to the web link table
if (!$article->bind($data, "published")) {
$this->setError($this->_db->getErrorMsg());
return false;
}
// sanitise id field
$article->id = (int) $article->id;
$isNew = ($article->id < 1);
if ($isNew)
{
$article->created = gmdate('Y-m-d H:i:s');
$article->created_by = $user->get('id');
}
else
{
$article->modified = gmdate('Y-m-d H:i:s');
$article->modified_by = $user->get('id');
}
// Append time if not added to publish date
if (strlen(trim($article->publish_up)) <= 10) {
$article->publish_up .= ' 00:00:00';
}
$date =& JFactory::getDate($article->publish_up, $mainframe->getCfg('offset'));
$article->publish_up = $date->toMySQL();
// Handle never unpublish date
if (trim($article->publish_down) == JText::_('Never') || trim( $article->publish_down ) == '')
{
$article->publish_down = $this->_db->getNullDate();;
}
else
{
if (strlen(trim( $article->publish_down )) <= 10) {
$article->publish_down .= ' 00:00:00';
}
$date =& JFactory::getDate($article->publish_down, $mainframe->getCfg('offset'));
$article->publish_down = $date->toMySQL();
}
$article->title = trim( $article->title );
// Publishing state hardening for Authors
if (!$user->authorize('com_content', 'publish', 'content', 'all'))
{
if ($isNew)
{
// For new items - author is not allowed to publish - prevent them from doing so
$article->state = 0;
}
else
{
// For existing items keep existing state - author is not allowed to change status
$query = 'SELECT state' .
' FROM #__content' .
' WHERE id = '.(int) $article->id;
$this->_db->setQuery($query);
$state = $this->_db->loadResult();
if ($state) {
$article->state = 1;
}
else {
$article->state = 0;
}
}
}
// Search for the {readmore} tag and split the text up accordingly.
$text = str_replace('
', '
', $data['text']);
$pattern = '#