📄 article.php
字号:
$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('<br>', '<br />', $data['text']); $pattern = '#<hr\s+id=("|\')system-readmore("|\')\s*\/*>#i'; $tagPos = preg_match($pattern, $text); if ($tagPos == 0) { $article->introtext = $text; } else { list($article->introtext, $article->fulltext) = preg_split($pattern, $text, 2); } // Filter settings jimport( 'joomla.application.component.helper' ); $config = JComponentHelper::getParams( 'com_content' ); $user = &JFactory::getUser(); $gid = $user->get( 'gid' ); $filterGroups = $config->get( 'filter_groups' ); if (is_array($filterGroups) && in_array( $gid, $filterGroups )) { $filterType = $config->get( 'filter_type' ); $filterTags = preg_split( '#[,\s]+#', trim( $config->get( 'filter_tags' ) ) ); $filterAttrs = preg_split( '#[,\s]+#', trim( $config->get( 'filter_attritbutes' ) ) ); switch ($filterType) { case 'NH': $filter = new JFilterInput(); break; case 'WL': $filter = new JFilterInput( $filterTags, $filterAttrs, 0, 0 ); break; case 'BL': default: $filter = new JFilterInput( $filterTags, $filterAttrs, 1, 1 ); break; } $article->introtext = $filter->clean( $article->introtext ); $article->fulltext = $filter->clean( $article->fulltext ); } elseif(empty($filterGroups)) { $filter = new JFilterInput(array(), array(), 1, 1); $article->introtext = $filter->clean( $article->introtext ); $article->fulltext = $filter->clean( $article->fulltext ); } // Make sure the article table is valid if (!$article->check()) { $this->setError($article->getError()); return false; } $article->version++; //Trigger OnBeforeContentSave $result = $dispatcher->trigger('onBeforeContentSave', array(&$article, $isNew)); if(in_array(false, $result, true)) { $this->setError($article->getError()); return false; } // 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']); //Trigger OnAfterContentSave $dispatcher->trigger('onAfterContentSave', array(&$article, $isNew)); $this->_article =& $article; 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; if($this->_id == '0') { return false; } // Load the content if it doesn't already exist if (empty($this->_article)) { // Get the page/component configuration $params = &$mainframe->getParams(); // 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; // Get the page/component configuration $params = clone($mainframe->getParams('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); // Are we showing introtext with the article if (!$params->get('show_intro') && !empty($this->_article->fulltext)) { $this->_article->text = $this->_article->fulltext; } else { $this->_article->text = $this->_article->introtext . chr(13).chr(13) . $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); $jnow =& JFactory::getDate(); $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 ( '; $where .= ' ( a.created_by = ' . (int) $user->id . ' ) '; $where .= ' OR '; $where .= ' ( 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).' )'; $where .= ' ) '; $where .= ' OR '; $where .= ' ( a.state = -1 ) '; $where .= ' ) '; } return $where; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -