📄 article.php
字号:
<?php/** * @version $Id: article.php 11253 2008-11-10 23:38:48Z ircmaxell $ * @package Joomla * @subpackage Content * @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved. * @license GNU/GPL, see LICENSE.php * Joomla! is free software. This version may have been modified pursuant to the * GNU General Public License, and as distributed it includes or is derivative * of works licensed under the GNU General Public License or other free or open * source software licenses. See COPYRIGHT.php for copyright notices and * details. */// Check to ensure this file is included in Joomla!defined('_JEXEC') or die( 'Restricted access' );jimport('joomla.application.component.model');/** * Content Component Article Model * * @package Joomla * @subpackage Content * @since 1.5 */class ContentModelArticle extends JModel{ /** * Article data * * @var object */ var $_article = null; /** * Constructor * * @since 1.5 */ function __construct() { parent::__construct(); $id = JRequest::getVar('id', 0, '', 'int'); $this->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'; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -