0byt3m1n1-V2
Path:
/
home
/
a
/
c
/
a
/
academiac
/
www
/
[
Home
]
File: article.php.tar
home/academiac/www/administrator/components/com_content/controllers/article.php 0000644 00000007072 15137206777 0024313 0 ustar 00 <?php /** * @package Joomla.Administrator * @subpackage com_content * * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ // No direct access defined('_JEXEC') or die; jimport('joomla.application.component.controllerform'); /** * @package Joomla.Administrator * @subpackage com_content * @since 1.6 */ class ContentControllerArticle extends JControllerForm { /** * Class constructor. * * @param array $config A named array of configuration variables. * * @since 1.6 */ function __construct($config = array()) { // An article edit form can come from the articles or featured view. // Adjust the redirect view on the value of 'return' in the request. if (JRequest::getCmd('return') == 'featured') { $this->view_list = 'featured'; $this->view_item = 'article&return=featured'; } parent::__construct($config); } /** * Method override to check if you can add a new record. * * @param array $data An array of input data. * * @return boolean * * @since 1.6 */ protected function allowAdd($data = array()) { // Initialise variables. $user = JFactory::getUser(); $categoryId = JArrayHelper::getValue($data, 'catid', JRequest::getInt('filter_category_id'), 'int'); $allow = null; if ($categoryId) { // If the category has been passed in the data or URL check it. $allow = $user->authorise('core.create', 'com_content.category.' . $categoryId); } if ($allow === null) { // In the absense of better information, revert to the component permissions. return parent::allowAdd(); } else { return $allow; } } /** * Method override to check if you can edit an existing record. * * @param array $data An array of input data. * @param string $key The name of the key for the primary key. * * @return boolean * * @since 1.6 */ protected function allowEdit($data = array(), $key = 'id') { // Initialise variables. $recordId = (int) isset($data[$key]) ? $data[$key] : 0; $user = JFactory::getUser(); $userId = $user->get('id'); // Check general edit permission first. if ($user->authorise('core.edit', 'com_content.article.' . $recordId)) { return true; } // Fallback on edit.own. // First test if the permission is available. if ($user->authorise('core.edit.own', 'com_content.article.' . $recordId)) { // Now test the owner is the user. $ownerId = (int) isset($data['created_by']) ? $data['created_by'] : 0; if (empty($ownerId) && $recordId) { // Need to do a lookup from the model. $record = $this->getModel()->getItem($recordId); if (empty($record)) { return false; } $ownerId = $record->created_by; } // If the owner matches 'me' then do the test. if ($ownerId == $userId) { return true; } } // Since there is no asset tracking, revert to the component permissions. return parent::allowEdit($data, $key); } /** * Method to run batch operations. * * @param object $model The model. * * @return boolean True if successful, false otherwise and internal error is set. * * @since 1.6 */ public function batch($model = null) { JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); // Set the model $model = $this->getModel('Article', '', array()); // Preset the redirect $this->setRedirect(JRoute::_('index.php?option=com_content&view=articles' . $this->getRedirectToListAppend(), false)); return parent::batch($model); } } home/academiac/www/plugins/editors-xtd/article/article.php 0000644 00000003753 15137253466 0017741 0 ustar 00 <?php /** * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ // no direct access defined('_JEXEC') or die; /** * Editor Article buton * * @package Joomla.Plugin * @subpackage Editors-xtd.article * @since 1.5 */ class plgButtonArticle extends JPlugin { /** * Constructor * * @access protected * @param object $subject The object to observe * @param array $config An array that holds the plugin configuration * @since 1.5 */ public function __construct(& $subject, $config) { parent::__construct($subject, $config); $this->loadLanguage(); } /** * Display the button * * @return array A four element array of (article_id, article_title, category_id, object) */ function onDisplay($name) { /* * Javascript to insert the link * View element calls jSelectArticle when an article is clicked * jSelectArticle creates the link tag, sends it to the editor, * and closes the select frame. */ $js = " function jSelectArticle(id, title, catid, object, link, lang) { var hreflang = ''; if (lang !== '') { var hreflang = ' hreflang = \"' + lang + '\"'; } var tag = '<a' + hreflang + ' href=\"' + link + '\">' + title + '</a>'; jInsertEditorText(tag, '".$name."'); SqueezeBox.close(); }"; $doc = JFactory::getDocument(); $doc->addScriptDeclaration($js); JHtml::_('behavior.modal'); /* * Use the built-in element view to select the article. * Currently uses blank class. */ $link = 'index.php?option=com_content&view=articles&layout=modal&tmpl=component&'.JSession::getFormToken().'=1'; $button = new JObject(); $button->set('modal', true); $button->set('link', $link); $button->set('text', JText::_('PLG_ARTICLE_BUTTON_ARTICLE')); $button->set('name', 'article'); $button->set('options', "{handler: 'iframe', size: {x: 770, y: 400}}"); return $button; } } home/academiac/www/administrator/components/com_content/elements/article.php 0000644 00000004037 15137341770 0023550 0 ustar 00 <?php /** * @package Joomla.Administrator * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ // No direct access defined('_JEXEC') or die; /** * Renders an article element * * @package Joomla.Administrator * @subpackage com_content * @deprecated JParameter is deprecated and will be removed in a future version. Use JForm instead. * @since 1.5 */ class JElementArticle extends JElement { /** * Element name * * @var string */ var $_name = 'Article'; function fetchElement($name, $value, &$node, $control_name) { $app = JFactory::getApplication(); $db = JFactory::getDbo(); $doc = JFactory::getDocument(); $template = $app->getTemplate(); $fieldName = $control_name.'['.$name.']'; $article = JTable::getInstance('content'); if ($value) { $article->load($value); } else { $article->title = JText::_('COM_CONTENT_SELECT_AN_ARTICLE'); } $js = " function jSelectArticle_".$name."(id, title, catid, object) { document.getElementById(object + '_id').value = id; document.getElementById(object + '_name').value = title; SqueezeBox.close(); }"; $doc->addScriptDeclaration($js); $link = 'index.php?option=com_content&task=element&tmpl=component&function=jSelectArticle_'.$name; JHtml::_('behavior.modal', 'a.modal'); $html = "\n".'<div class="fltlft"><input type="text" id="'.$name.'_name" value="'.htmlspecialchars($article->title, ENT_QUOTES, 'UTF-8').'" disabled="disabled" /></div>'; // $html .= "\n   <input class=\"inputbox modal-button\" type=\"button\" value=\"".JText::_('JSELECT')."\" />"; $html .= '<div class="button2-left"><div class="blank"><a class="modal" title="'.JText::_('COM_CONTENT_SELECT_AN_ARTICLE').'" href="'.$link.'" rel="{handler: \'iframe\', size: {x: 650, y: 375}}">'.JText::_('JSELECT').'</a></div></div>'."\n"; $html .= "\n".'<input type="hidden" id="'.$name.'_id" name="'.$fieldName.'" value="'.(int)$value.'" />'; return $html; } } home/academiac/www/components/com_content/controllers/article.php 0000644 00000016571 15137440473 0021430 0 ustar 00 <?php /** * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ // no direct access defined('_JEXEC') or die; jimport('joomla.application.component.controllerform'); /** * @package Joomla.Site * @subpackage com_content */ class ContentControllerArticle extends JControllerForm { /** * @since 1.6 */ protected $view_item = 'form'; /** * @since 1.6 */ protected $view_list = 'categories'; /** * Method to add a new record. * * @return boolean True if the article can be added, false if not. * @since 1.6 */ public function add() { if (!parent::add()) { // Redirect to the return page. $this->setRedirect($this->getReturnPage()); } } /** * Method override to check if you can add a new record. * * @param array An array of input data. * * @return boolean * @since 1.6 */ protected function allowAdd($data = array()) { // Initialise variables. $user = JFactory::getUser(); $categoryId = JArrayHelper::getValue($data, 'catid', JRequest::getInt('catid'), 'int'); $allow = null; if ($categoryId) { // If the category has been passed in the data or URL check it. $allow = $user->authorise('core.create', 'com_content.category.'.$categoryId); } if ($allow === null) { // In the absense of better information, revert to the component permissions. return parent::allowAdd(); } else { return $allow; } } /** * Method override to check if you can edit an existing record. * * @param array $data An array of input data. * @param string $key The name of the key for the primary key. * * @return boolean * @since 1.6 */ protected function allowEdit($data = array(), $key = 'id') { // Initialise variables. $recordId = (int) isset($data[$key]) ? $data[$key] : 0; $user = JFactory::getUser(); $userId = $user->get('id'); $asset = 'com_content.article.'.$recordId; // Check general edit permission first. if ($user->authorise('core.edit', $asset)) { return true; } // Fallback on edit.own. // First test if the permission is available. if ($user->authorise('core.edit.own', $asset)) { // Now test the owner is the user. $ownerId = (int) isset($data['created_by']) ? $data['created_by'] : 0; if (empty($ownerId) && $recordId) { // Need to do a lookup from the model. $record = $this->getModel()->getItem($recordId); if (empty($record)) { return false; } $ownerId = $record->created_by; } // If the owner matches 'me' then do the test. if ($ownerId == $userId) { return true; } } // Since there is no asset tracking, revert to the component permissions. return parent::allowEdit($data, $key); } /** * Method to cancel an edit. * * @param string $key The name of the primary key of the URL variable. * * @return Boolean True if access level checks pass, false otherwise. * @since 1.6 */ public function cancel($key = 'a_id') { parent::cancel($key); // Redirect to the return page. $this->setRedirect($this->getReturnPage()); } /** * Method to edit an existing record. * * @param string $key The name of the primary key of the URL variable. * @param string $urlVar The name of the URL variable if different from the primary key (sometimes required to avoid router collisions). * * @return Boolean True if access level check and checkout passes, false otherwise. * @since 1.6 */ public function edit($key = null, $urlVar = 'a_id') { $result = parent::edit($key, $urlVar); return $result; } /** * Method to get a model object, loading it if required. * * @param string $name The model name. Optional. * @param string $prefix The class prefix. Optional. * @param array $config Configuration array for model. Optional. * * @return object The model. * * @since 1.5 */ public function getModel($name = 'form', $prefix = '', $config = array('ignore_request' => true)) { $model = parent::getModel($name, $prefix, $config); return $model; } /** * Gets the URL arguments to append to an item redirect. * * @param int $recordId The primary key id for the item. * @param string $urlVar The name of the URL variable for the id. * * @return string The arguments to append to the redirect URL. * @since 1.6 */ protected function getRedirectToItemAppend($recordId = null, $urlVar = 'a_id') { // Need to override the parent method completely. $tmpl = JRequest::getCmd('tmpl'); $layout = JRequest::getCmd('layout', 'edit'); $append = ''; // Setup redirect info. if ($tmpl) { $append .= '&tmpl='.$tmpl; } // TODO This is a bandaid, not a long term solution. // if ($layout) { // $append .= '&layout='.$layout; // } $append .= '&layout=edit'; if ($recordId) { $append .= '&'.$urlVar.'='.$recordId; } $itemId = JRequest::getInt('Itemid'); $return = $this->getReturnPage(); $catId = JRequest::getInt('catid', null, 'get'); if ($itemId) { $append .= '&Itemid='.$itemId; } if($catId) { $append .= '&catid='.$catId; } if ($return) { $append .= '&return='.base64_encode(urlencode($return)); } return $append; } /** * Get the return URL. * * If a "return" variable has been passed in the request * * @return string The return URL. * @since 1.6 */ protected function getReturnPage() { $return = JRequest::getVar('return', null, 'default', 'base64'); if (empty($return) || !JUri::isInternal(urldecode(base64_decode($return)))) { return JURI::base(); } else { return urldecode(base64_decode($return)); } } /** * Function that allows child controller access to model data after the data has been saved. * * @param JModel $model The data model object. * @param array $validData The validated data. * * @return void * @since 1.6 */ protected function postSaveHook(JModel &$model, $validData) { $task = $this->getTask(); if ($task == 'save') { $this->setRedirect(JRoute::_('index.php?option=com_content&view=category&id='.$validData['catid'], false)); } } /** * Method to save a record. * * @param string $key The name of the primary key of the URL variable. * @param string $urlVar The name of the URL variable if different from the primary key (sometimes required to avoid router collisions). * * @return Boolean True if successful, false otherwise. * @since 1.6 */ public function save($key = null, $urlVar = 'a_id') { // Load the backend helper for filtering. require_once JPATH_ADMINISTRATOR.'/components/com_content/helpers/content.php'; $result = parent::save($key, $urlVar); // If ok, redirect to the return page. if ($result) { $this->setRedirect($this->getReturnPage()); } return $result; } /** * Method to save a vote. * * @return void * @since 1.6.1 */ function vote() { // Check for request forgeries. JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); $user_rating = JRequest::getInt('user_rating', -1); if ( $user_rating > -1 ) { $url = JRequest::getString('url', ''); $id = JRequest::getInt('id', 0); $viewName = JRequest::getString('view', $this->default_view); $model = $this->getModel($viewName); if ($model->storeVote($id, $user_rating)) { $this->setRedirect($url, JText::_('COM_CONTENT_ARTICLE_VOTE_SUCCESS')); } else { $this->setRedirect($url, JText::_('COM_CONTENT_ARTICLE_VOTE_FAILURE')); } } } } home/academiac/www/components/com_content/models/article.php 0000644 00000025647 15137556150 0020351 0 ustar 00 <?php /** * @package Joomla.Site * @subpackage com_content * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ // No direct access defined('_JEXEC') or die; jimport('joomla.application.component.modelitem'); /** * Content Component Article Model * * @package Joomla.Site * @subpackage com_content * @since 1.5 */ class ContentModelArticle extends JModelItem { /** * Model context string. * * @var string */ protected $_context = 'com_content.article'; /** * Method to auto-populate the model state. * * Note. Calling getState in this method will result in recursion. * * @since 1.6 */ protected function populateState() { $app = JFactory::getApplication('site'); // Load state from the request. $pk = JRequest::getInt('id'); $this->setState('article.id', $pk); $offset = JRequest::getUInt('limitstart'); $this->setState('list.offset', $offset); // Load the parameters. $params = $app->getParams(); $this->setState('params', $params); // TODO: Tune these values based on other permissions. $user = JFactory::getUser(); if ((!$user->authorise('core.edit.state', 'com_content')) && (!$user->authorise('core.edit', 'com_content'))){ $this->setState('filter.published', 1); $this->setState('filter.archived', 2); } $this->setState('filter.language', JLanguageMultilang::isEnabled()); } /** * Method to get article data. * * @param integer The id of the article. * * @return mixed Menu item data object on success, false on failure. */ public function &getItem($pk = null) { // Get current user for authorisation checks $user = JFactory::getUser(); // Initialise variables. $pk = (!empty($pk)) ? $pk : (int) $this->getState('article.id'); if ($this->_item === null) { $this->_item = array(); } if (!isset($this->_item[$pk])) { try { $db = $this->getDbo(); $query = $db->getQuery(true); $query->select($this->getState( 'item.select', 'a.id, a.asset_id, a.title, a.alias, a.title_alias, a.introtext, a.fulltext, ' . // If badcats is not null, this means that the article is inside an unpublished category // In this case, the state is set to 0 to indicate Unpublished (even if the article state is Published) 'CASE WHEN badcats.id is null THEN a.state ELSE 0 END AS state, ' . 'a.mask, a.catid, a.created, a.created_by, a.created_by_alias, ' . // use created if modified is 0 'CASE WHEN a.modified = 0 THEN a.created ELSE a.modified END as modified, ' . 'a.modified_by, a.checked_out, a.checked_out_time, a.publish_up, a.publish_down, ' . 'a.images, a.urls, a.attribs, a.version, a.parentid, a.ordering, ' . 'a.metakey, a.metadesc, a.access, a.hits, a.metadata, a.featured, a.language, a.xreference' ) ); $query->from('#__content AS a'); // Join on category table. $query->select('c.title AS category_title, c.alias AS category_alias, c.access AS category_access'); $query->join('LEFT', '#__categories AS c on c.id = a.catid'); // Join on user table. $query->select('u.name AS author'); $query->join('LEFT', '#__users AS u on u.id = a.created_by'); // Get contact id $subQuery = $db->getQuery(true); $subQuery->select('MAX(contact.id) AS id'); $subQuery->from('#__contact_details AS contact'); $subQuery->where('contact.published = 1'); $subQuery->where('contact.user_id = a.created_by'); // Filter by language if ($this->getState('filter.language')) { $subQuery->where('(contact.language in (' . $db->quote(JFactory::getLanguage()->getTag()) . ',' . $db->quote('*') . ') OR contact.language IS NULL)'); } $query->select('(' . $subQuery . ') as contactid'); // Filter by language if ($this->getState('filter.language')) { $query->where('a.language in (' . $db->quote(JFactory::getLanguage()->getTag()) . ',' . $db->quote('*') . ')'); } // Join over the categories to get parent category titles $query->select('parent.title as parent_title, parent.id as parent_id, parent.path as parent_route, parent.alias as parent_alias'); $query->join('LEFT', '#__categories as parent ON parent.id = c.parent_id'); // Join on voting table $query->select('ROUND(v.rating_sum / v.rating_count, 0) AS rating, v.rating_count as rating_count'); $query->join('LEFT', '#__content_rating AS v ON a.id = v.content_id'); $query->where('a.id = ' . (int) $pk); if ((!$user->authorise('core.edit.state', 'com_content')) && (!$user->authorise('core.edit', 'com_content'))) { // Filter by start and end dates. $nullDate = $db->Quote($db->getNullDate()); $date = JFactory::getDate(); $nowDate = $db->Quote($date->toSql()); $query->where('(a.publish_up = ' . $nullDate . ' OR a.publish_up <= ' . $nowDate . ')'); $query->where('(a.publish_down = ' . $nullDate . ' OR a.publish_down >= ' . $nowDate . ')'); } // Join to check for category published state in parent categories up the tree // If all categories are published, badcats.id will be null, and we just use the article state $subquery = ' (SELECT cat.id as id FROM #__categories AS cat JOIN #__categories AS parent '; $subquery .= 'ON cat.lft BETWEEN parent.lft AND parent.rgt '; $subquery .= 'WHERE parent.extension = ' . $db->quote('com_content'); $subquery .= ' AND parent.published <= 0 GROUP BY cat.id)'; $query->join('LEFT OUTER', $subquery . ' AS badcats ON badcats.id = c.id'); // Filter by published state. $published = $this->getState('filter.published'); $archived = $this->getState('filter.archived'); if (is_numeric($published)) { $query->where('(a.state = ' . (int) $published . ' OR a.state =' . (int) $archived . ')'); } $db->setQuery($query); $data = $db->loadObject(); if ($error = $db->getErrorMsg()) { throw new Exception($error); } if (empty($data)) { return JError::raiseError(404, JText::_('COM_CONTENT_ERROR_ARTICLE_NOT_FOUND')); } // Check for published state if filter set. if (((is_numeric($published)) || (is_numeric($archived))) && (($data->state != $published) && ($data->state != $archived))) { return JError::raiseError(404, JText::_('COM_CONTENT_ERROR_ARTICLE_NOT_FOUND')); } // Convert parameter fields to objects. $registry = new JRegistry; $registry->loadString($data->attribs); $data->params = clone $this->getState('params'); $data->params->merge($registry); $registry = new JRegistry; $registry->loadString($data->metadata); $data->metadata = $registry; // Technically guest could edit an article, but lets not check that to improve performance a little. if (!$user->get('guest')) { $userId = $user->get('id'); $asset = 'com_content.article.'.$data->id; // Check general edit permission first. if ($user->authorise('core.edit', $asset)) { $data->params->set('access-edit', true); } // Now check if edit.own is available. elseif (!empty($userId) && $user->authorise('core.edit.own', $asset)) { // Check for a valid user and that they are the owner. if ($userId == $data->created_by) { $data->params->set('access-edit', true); } } } // Compute view access permissions. if ($access = $this->getState('filter.access')) { // If the access filter has been set, we already know this user can view. $data->params->set('access-view', true); } else { // If no access filter is set, the layout takes some responsibility for display of limited information. $user = JFactory::getUser(); $groups = $user->getAuthorisedViewLevels(); if ($data->catid == 0 || $data->category_access === null) { $data->params->set('access-view', in_array($data->access, $groups)); } else { $data->params->set('access-view', in_array($data->access, $groups) && in_array($data->category_access, $groups)); } } $this->_item[$pk] = $data; } catch (JException $e) { if ($e->getCode() == 404) { // Need to go thru the error handler to allow Redirect to work. JError::raiseError(404, $e->getMessage()); } else { $this->setError($e); $this->_item[$pk] = false; } } } return $this->_item[$pk]; } /** * Increment the hit counter for the article. * * @param int Optional primary key of the article to increment. * * @return boolean True if successful; false otherwise and internal error set. */ public function hit($pk = 0) { $hitcount = JRequest::getInt('hitcount', 1); if ($hitcount) { // Initialise variables. $pk = (!empty($pk)) ? $pk : (int) $this->getState('article.id'); $db = $this->getDbo(); $db->setQuery( 'UPDATE #__content' . ' SET hits = hits + 1' . ' WHERE id = '.(int) $pk ); if (!$db->query()) { $this->setError($db->getErrorMsg()); return false; } } return true; } public function storeVote($pk = 0, $rate = 0) { if ( $rate >= 1 && $rate <= 5 && $pk > 0 ) { $userIP = $_SERVER['REMOTE_ADDR']; $db = $this->getDbo(); $db->setQuery( 'SELECT *' . ' FROM #__content_rating' . ' WHERE content_id = '.(int) $pk ); $rating = $db->loadObject(); if (!$rating) { // There are no ratings yet, so lets insert our rating $db->setQuery( 'INSERT INTO #__content_rating ( content_id, lastip, rating_sum, rating_count )' . ' VALUES ( '.(int) $pk.', '.$db->Quote($userIP).', '.(int) $rate.', 1 )' ); if (!$db->query()) { $this->setError($db->getErrorMsg()); return false; } } else { if ($userIP != ($rating->lastip)) { $db->setQuery( 'UPDATE #__content_rating' . ' SET rating_count = rating_count + 1, rating_sum = rating_sum + '.(int) $rate.', lastip = '.$db->Quote($userIP) . ' WHERE content_id = '.(int) $pk ); if (!$db->query()) { $this->setError($db->getErrorMsg()); return false; } } else { return false; } } return true; } JError::raiseWarning( 'SOME_ERROR_CODE', JText::sprintf('COM_CONTENT_INVALID_RATING', $rate), "JModelArticle::storeVote($rate)"); return false; } }
©
2018.