📄 article.php
字号:
}
// Append time if not added to publish date
if (strlen(trim($article->publish_up)) <= 10) {
$article->publish_up .= ' 00:00:00';
}
jimport( 'joomla.utilities.date' );
$date = new JDate($article->publish_up);
$date->setOffset( -$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 = new JDate($article->publish_down);
$date->setOffset( -$mainframe->getCfg('offset'));
$article->publish_down = $date->toMySQL();
}
jimport('joomla.filter.output');
$article->title = trim( JFilterOutput::ampReplace($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) $row->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('<br>', '<br />', $data['text']);
$tagPos = JString::strpos($text, '<hr id="system-readmore" />');
if ($tagPos === false) {
$article->introtext = $text;
} else {
$article->introtext = JString::substr($text, 0, $tagPos);
$article->fulltext = JString::substr($text, $tagPos +27);
}
// Make sure the article table is valid
if (!$article->check()) {
$this->setError($article->getError());
return false;
}
$article->version++;
// Store the article table to the database
if (!$article->store()) {
$this->setError($this->_db->getErrorMsg());
return false;
}
if ($isNew)
{
$this->_id = $article->_db->insertId();
}
$article->reorder("catid = " . (int) $data['catid']);
return true;
}
/**
* Method to store a user rating for a content article
*
* @access public
* @param int $rating Article rating [ 1 - 5 ]
* @return boolean True on success
* @since 1.5
*/
function storeVote($rate)
{
if ( $rate >= 1 && $rate <= 5)
{
$userIP = $_SERVER['REMOTE_ADDR'];
$query = 'SELECT *' .
' FROM #__content_rating' .
' WHERE content_id = '.(int) $this->_id;
$this->_db->setQuery($query);
$rating = $this->_db->loadObject();
if (!$rating)
{
// There are no ratings yet, so lets insert our rating
$query = 'INSERT INTO #__content_rating ( content_id, lastip, rating_sum, rating_count )' .
' VALUES ( '.(int) $this->_id.', '.$this->_db->Quote($userIP).', '.(int) $rate.', 1 )';
$this->_db->setQuery($query);
if (!$this->_db->query()) {
JError::raiseError( 500, $this->_db->stderr());
}
}
else
{
if ($userIP != ($rating->lastip))
{
// We weren't the last voter so lets add our vote to the ratings totals for the article
$query = 'UPDATE #__content_rating' .
' SET rating_count = rating_count + 1, rating_sum = rating_sum + '.(int) $rate.', lastip = '.$this->_db->Quote($userIP) .
' WHERE content_id = '.(int) $this->_id;
$this->_db->setQuery($query);
if (!$this->_db->query()) {
JError::raiseError( 500, $this->_db->stderr());
}
}
else
{
return false;
}
}
return true;
}
JError::raiseWarning( 'SOME_ERROR_CODE', 'Article Rating:: Invalid Rating:' .$rate, "JModelArticle::storeVote($rate)");
return false;
}
/**
* Method to load content article data
*
* @access private
* @return boolean True on success
* @since 1.5
*/
function _loadArticle()
{
global $mainframe;
// Load the content if it doesn't already exist
if (empty($this->_article))
{
// Get the page/component configuration
$params = &$mainframe->getPageParameters();
// If voting is turned on, get voting data as well for the article
$voting = ContentHelperQuery::buildVotingQuery($params);
// Get the WHERE clause
$where = $this->_buildContentWhere();
$query = 'SELECT a.*, u.name AS author, u.usertype, cc.title AS category, s.title AS section,' .
' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(":", a.id, a.alias) ELSE a.id END as slug,'.
' CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(":", cc.id, cc.alias) ELSE cc.id END as catslug,'.
' g.name AS groups, s.published AS sec_pub, cc.published AS cat_pub, s.access AS sec_access, cc.access AS cat_access '.$voting['select'].
' FROM #__content AS a' .
' LEFT JOIN #__categories AS cc ON cc.id = a.catid' .
' LEFT JOIN #__sections AS s ON s.id = cc.section AND s.scope = "content"' .
' LEFT JOIN #__users AS u ON u.id = a.created_by' .
' LEFT JOIN #__groups AS g ON a.access = g.id'.
$voting['join'].
$where;
$this->_db->setQuery($query);
$this->_article = $this->_db->loadObject();
if ( ! $this->_article ) {
return false;
}
if($this->_article->publish_down == $this->_db->getNullDate()) {
$this->_article->publish_down = JText::_('Never');
}
// These attributes need to be defined in order for the voting plugin to work
if ( count($voting) && ! isset($this->_article->rating_count) ) {
$this->_article->rating_count = 0;
$this->_article->rating = 0;
}
return true;
}
return true;
}
/**
* Method to load content article parameters
*
* @access private
* @return void
* @since 1.5
*/
function _loadArticleParams()
{
global $mainframe;
// Set some metatag information if needed
if ($mainframe->getCfg('MetaTitle') == '1') {
$mainframe->addMetaTag('title', $this->_article->title);
}
if ($mainframe->getCfg('MetaAuthor') == '1') {
$mainframe->addMetaTag('author', $this->_article->author);
}
// Get the page/component configuration
$params = clone($mainframe->getPageParameters('com_content'));
// Merge article parameters into the page configuration
$aparams = new JParameter($this->_article->attribs);
$params->merge($aparams);
// Set the popup configuration option based on the request
$pop = JRequest::getVar('pop', 0, '', 'int');
$params->set('popup', $pop);
// Set the Section name as a link if needed
if ($params->get('link_section') && $this->_article->sectionid) {
$this->_article->section = ContentHelperRoute::getSectionRoute($this->_article);
}
// Set the Category name as a link if needed
if ($params->get('link_category') && $this->_article->catid) {
$this->_article->category = ContentHelperRoute::getCategoryRoute($this->_article);
}
// Are we showing introtext with the article
if ($params->get('show_intro')) {
$this->_article->text = $this->_article->introtext . chr(13).chr(13) . $this->_article->fulltext;
} else {
$this->_article->text = $this->_article->fulltext;
}
// Set the article object's parameters
$this->_article->parameters = & $params;
}
/**
* Method to build the WHERE clause of the query to select a content article
*
* @access private
* @return string WHERE clause
* @since 1.5
*/
function _buildContentWhere()
{
global $mainframe;
$user =& JFactory::getUser();
$aid = (int) $user->get('aid', 0);
// TODO: Should we be using requestTime here? or is JDate ok?
// $now = $mainframe->get('requestTime');
jimport('joomla.utilities.date');
$jnow = new JDate();
$now = $jnow->toMySQL();
$nullDate = $this->_db->getNullDate();
/*
* First thing we need to do is assert that the content article is the one
* we are looking for and we have access to it.
*/
$where = ' WHERE a.id = '. (int) $this->_id;
$where .= ' AND a.access <= '. (int) $aid;
if (!$user->authorize('com_content', 'edit', 'content', 'all'))
{
$where .= ' AND ( a.state = 1 OR a.state = -1)' .
' AND ( a.publish_up = '.$this->_db->Quote($nullDate).' OR a.publish_up <= '.$this->_db->Quote($now).' )' .
' AND ( a.publish_down = '.$this->_db->Quote($nullDate).' OR a.publish_down >= '.$this->_db->Quote($now).' )';
}
return $where;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -