0byt3m1n1-V2
Path:
/
home
/
a
/
c
/
a
/
academiac
/
www
/
[
Home
]
File: newsfeed.php.tar
home/academiac/www/administrator/components/com_newsfeeds/models/newsfeed.php 0000644 00000021443 15137210657 0023704 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.modeladmin'); /** * Newsfeed model. * * @package Joomla.Administrator * @subpackage com_newsfeeds * @since 1.6 */ class NewsfeedsModelNewsfeed extends JModelAdmin { /** * @var string The prefix to use with controller messages. * @since 1.6 */ protected $text_prefix = 'COM_NEWSFEEDS'; /** * Batch copy items to a new category or current. * * @param integer $value The new category. * @param array $pks An array of row IDs. * @param array $contexts An array of item contexts. * * @return mixed An array of new IDs on success, boolean false on failure. * * @since 11.1 */ protected function batchCopy($value, $pks, $contexts) { $categoryId = (int) $value; $table = $this->getTable(); $i = 0; // Check that the category exists if ($categoryId) { $categoryTable = JTable::getInstance('Category'); if (!$categoryTable->load($categoryId)) { if ($error = $categoryTable->getError()) { // Fatal error $this->setError($error); return false; } else { $this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_MOVE_CATEGORY_NOT_FOUND')); return false; } } } if (empty($categoryId)) { $this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_MOVE_CATEGORY_NOT_FOUND')); return false; } // Check that the user has create permission for the component $user = JFactory::getUser(); if (!$user->authorise('core.create', 'com_newsfeeds.category.' . $categoryId)) { $this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_CREATE')); return false; } // Parent exists so we let's proceed while (!empty($pks)) { // Pop the first ID off the stack $pk = array_shift($pks); $table->reset(); // Check that the row actually exists if (!$table->load($pk)) { if ($error = $table->getError()) { // Fatal error $this->setError($error); return false; } else { // Not fatal error $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_BATCH_MOVE_ROW_NOT_FOUND', $pk)); continue; } } // Alter the title & alias $data = $this->generateNewTitle($categoryId, $table->alias, $table->name); $table->name = $data['0']; $table->alias = $data['1']; // Reset the ID because we are making a copy $table->id = 0; // New category ID $table->catid = $categoryId; // TODO: Deal with ordering? //$table->ordering = 1; // Check the row. if (!$table->check()) { $this->setError($table->getError()); return false; } // Store the row. if (!$table->store()) { $this->setError($table->getError()); return false; } // Get the new item ID $newId = $table->get('id'); // Add the new ID to the array $newIds[$i] = $newId; $i++; } // Clean the cache $this->cleanCache(); return $newIds; } /** * Method to test whether a record can be deleted. * * @param object A record object. * @return boolean True if allowed to delete the record. Defaults to the permission set in the component. * @since 1.6 */ protected function canDelete($record) { if (!empty($record->id)) { if ($record->published != -2) { return ; } $user = JFactory::getUser(); if (!empty($record->catid)) { return $user->authorise('core.delete', 'com_newsfeed.category.'.(int) $record->catid); } else { return parent::canDelete($record); } } } /** * Method to test whether a record can have its state changed. * * @param object A record object. * @return boolean True if allowed to change the state of the record. Defaults to the permission set in the component. * @since 1.6 */ protected function canEditState($record) { $user = JFactory::getUser(); if (!empty($record->catid)) { return $user->authorise('core.edit.state', 'com_newsfeeds.category.'.(int) $record->catid); } else { return parent::canEditState($record); } } /** * Returns a Table object, always creating it. * * @param type The table type to instantiate * @param string A prefix for the table class name. Optional. * @param array Configuration array for model. Optional. * @return JTable A database object */ public function getTable($type = 'Newsfeed', $prefix = 'NewsfeedsTable', $config = array()) { return JTable::getInstance($type, $prefix, $config); } /** * Method to get the record form. * * @param array $data Data for the form. * @param boolean $loadData True if the form is to load its own data (default case), false if not. * @return JForm A JForm object on success, false on failure * @since 1.6 */ public function getForm($data = array(), $loadData = true) { // Get the form. $form = $this->loadForm('com_newsfeeds.newsfeed', 'newsfeed', array('control' => 'jform', 'load_data' => $loadData)); if (empty($form)) { return false; } // Determine correct permissions to check. if ($this->getState('newsfeed.id')) { // Existing record. Can only edit in selected categories. $form->setFieldAttribute('catid', 'action', 'core.edit'); } else { // New record. Can only create in selected categories. $form->setFieldAttribute('catid', 'action', 'core.create'); } // Modify the form based on access controls. if (!$this->canEditState((object) $data)) { // Disable fields for display. $form->setFieldAttribute('ordering', 'disabled', 'true'); $form->setFieldAttribute('published', 'disabled', 'true'); $form->setFieldAttribute('publish_up', 'disabled', 'true'); $form->setFieldAttribute('publish_down', 'disabled', 'true'); // Disable fields while saving. // The controller has already verified this is a record you can edit. $form->setFieldAttribute('ordering', 'filter', 'unset'); $form->setFieldAttribute('published', 'filter', 'unset'); $form->setFieldAttribute('publish_up', 'filter', 'unset'); $form->setFieldAttribute('publish_down', 'filter', 'unset'); } return $form; } /** * Method to get the data that should be injected in the form. * * @return mixed The data for the form. * @since 1.6 */ protected function loadFormData() { // Check the session for previously entered form data. $data = JFactory::getApplication()->getUserState('com_newsfeeds.edit.newsfeed.data', array()); if (empty($data)) { $data = $this->getItem(); // Prime some default values. if ($this->getState('newsfeed.id') == 0) { $app = JFactory::getApplication(); $data->set('catid', JRequest::getInt('catid', $app->getUserState('com_newsfeeds.newsfeeds.filter.category_id'))); } } return $data; } /** * Method to get a single record. * * @param integer The id of the primary key. * * @return mixed Object on success, false on failure. * @since 1.6 */ public function getItem($pk = null) { if ($item = parent::getItem($pk)) { // Convert the params field to an array. $registry = new JRegistry; $registry->loadString($item->metadata); $item->metadata = $registry->toArray(); } return $item; } /** * Prepare and sanitise the table prior to saving. */ protected function prepareTable(&$table) { $date = JFactory::getDate(); $user = JFactory::getUser(); $table->name = htmlspecialchars_decode($table->name, ENT_QUOTES); $table->alias = JApplication::stringURLSafe($table->alias); if (empty($table->alias)) { $table->alias = JApplication::stringURLSafe($table->name); } if (empty($table->id)) { // Set the values //$table->created = $date->toSql(); // Set ordering to the last item if not set if (empty($table->ordering)) { $db = JFactory::getDbo(); $db->setQuery('SELECT MAX(ordering) FROM #__newsfeeds'); $max = $db->loadResult(); $table->ordering = $max+1; } } else { // Set the values //$table->modified = $date->toSql(); //$table->modified_by = $user->get('id'); } } /** * Method to change the published state of one or more records. * * @param array $pks A list of the primary keys to change. * @param int $value The value of the published state. * * @return boolean True on success. * @since 1.6 */ function publish(&$pks, $value = 1) { $result = parent::publish($pks, $value); // Clean extra cache for newsfeeds $this->cleanCache('feed_parser'); return $result; } /** * A protected method to get a set of ordering conditions. * * @param object A record object. * @return array An array of conditions to add to add to ordering queries. * @since 1.6 */ protected function getReorderConditions($table) { $condition = array(); $condition[] = 'catid = '.(int) $table->catid; return $condition; } } home/academiac/www/administrator/components/com_newsfeeds/tables/newsfeed.php 0000644 00000007772 15137211115 0023672 0 ustar 00 <?php /** * @package Joomla.Administrator * @subpackage com_newsfeeds * @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; /** * @package Joomla.Administrator * @subpackage com_newsfeeds */ class NewsfeedsTableNewsfeed extends JTable { /** * Constructor * * @param JDatabase A database connector object */ public function __construct(&$db) { parent::__construct('#__newsfeeds', 'id', $db); } /** * Overloaded bind function to pre-process the params. * * @param array Named array * @return null|string null is operation was satisfactory, otherwise returns an error * @see JTable:bind * @since 1.5 */ public function bind($array, $ignore = '') { if (isset($array['params']) && is_array($array['params'])) { $registry = new JRegistry(); $registry->loadArray($array['params']); $array['params'] = (string) $registry; } if (isset($array['metadata']) && is_array($array['metadata'])) { $registry = new JRegistry(); $registry->loadArray($array['metadata']); $array['metadata'] = (string) $registry; } return parent::bind($array, $ignore); } /** * Overloaded check method to ensure data integrity. * * @return boolean True on success. */ function check() { // Check for valid name. if (trim($this->name) == '') { $this->setError(JText::_('COM_NEWSFEEDS_WARNING_PROVIDE_VALID_NAME')); return false; } if (empty($this->alias)) { $this->alias = $this->name; } $this->alias = JApplication::stringURLSafe($this->alias); if (trim(str_replace('-', '', $this->alias)) == '') { $this->alias = JFactory::getDate()->format("Y-m-d-H-i-s"); } // Check the publish down date is not earlier than publish up. if (intval($this->publish_down) > 0 && $this->publish_down < $this->publish_up) { $this->setError(JText::_('JGLOBAL_START_PUBLISH_AFTER_FINISH')); return false; } // clean up keywords -- eliminate extra spaces between phrases // and cr (\r) and lf (\n) characters from string if (!empty($this->metakey)) { // only process if not empty $bad_characters = array("\n", "\r", "\"", "<", ">"); // array of characters to remove $after_clean = JString::str_ireplace($bad_characters, "", $this->metakey); // remove bad characters $keys = explode(',', $after_clean); // create array using commas as delimiter $clean_keys = array(); foreach($keys as $key) { if (trim($key)) { // ignore blank keywords $clean_keys[] = trim($key); } } $this->metakey = implode(", ", $clean_keys); // put array back together delimited by ", " } // clean up description -- eliminate quotes and <> brackets if (!empty($this->metadesc)) { // only process if not empty $bad_characters = array("\"", "<", ">"); $this->metadesc = JString::str_ireplace($bad_characters, "", $this->metadesc); } return true; } /** * Overriden JTable::store to set modified data and user id. * * @param boolean True to update fields even if they are null. * @return boolean True on success. * @since 1.6 */ public function store($updateNulls = false) { $date = JFactory::getDate(); $user = JFactory::getUser(); if ($this->id) { // Existing item $this->modified = $date->toSql(); $this->modified_by = $user->get('id'); } else { // New newsfeed. A feed created and created_by field can be set by the user, // so we don't touch either of these if they are set. if (!intval($this->created)) { $this->created = $date->toSql(); } if (empty($this->created_by)) { $this->created_by = $user->get('id'); } } // Verify that the alias is unique $table = JTable::getInstance('Newsfeed', 'NewsfeedsTable'); if ($table->load(array('alias'=>$this->alias, 'catid'=>$this->catid)) && ($table->id != $this->id || $this->id==0)) { $this->setError(JText::_('COM_NEWSFEEDS_ERROR_UNIQUE_ALIAS')); return false; } return parent::store($updateNulls); } } home/academiac/www/administrator/components/com_newsfeeds/elements/newsfeed.php 0000644 00000002573 15137212153 0024231 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 a newsfeed selection element * * @package Joomla.Administrator * @subpackage com_newsfeeds * @deprecated JParameter is deprecated and will be removed in a future version. Use JForm instead. * @since 1.5 */ class JElementNewsfeed extends JElement { /** * Element name * * @var string */ protected $_name = 'Newsfeed'; public function fetchElement($name, $value, &$node, $control_name) { $db = JFactory::getDbo(); $query = 'SELECT a.id, c.title, a.name' . ' FROM #__newsfeeds AS a' . ' INNER JOIN #__categories AS c ON a.catid = c.id' . ' WHERE a.published = 1' . ' AND c.published = 1' . ' ORDER BY a.catid, a.name' ; $db->setQuery($query); $options = $db->loadObjectList(); $n = count($options); for ($i = 0; $i < $n; $i++) { $options[$i]->text = $options[$i]->title . '-' . $options[$i]->name; } array_unshift($options, JHtml::_('select.option', '0', '- '.JText::_('COM_NEWSFEEDS_SELECT_FEED').' -', 'id', 'text')); return JHtml::_('select.genericlist', $options, ''.$control_name.'['.$name.']', 'class="inputbox"', 'id', 'text', $value, $control_name.$name); } } home/academiac/www/administrator/components/com_newsfeeds/helpers/html/newsfeed.php 0000644 00000003364 15137212303 0025017 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; /** * Utility class for creating HTML Grids * * @static * @package Joomla.Administrator * @subpackage com_newsfeeds * @since 1.5 */ class JHtmlNewsfeed { /** * @param int $value The state value * @param int $i */ public static function state($value = 0, $i) { // Array of image, task, title, action $states = array( 1 => array('tick.png', 'newsfeeds.unpublish', 'JPUBLISHED', 'COM_NEWSFEEDS_UNPUBLISH_ITEM'), 0 => array('publish_x.png', 'newsfeeds.publish', 'JUNPUBLISHED', 'COM_NEWSFEEDS_PUBLISH_ITEM') ); $state = JArrayHelper::getValue($states, (int) $value, $states[0]); $html = '<a href="#" onclick="return listItemTask(\'cb'.$i.'\',\''.$state[1].'\')" title="'.JText::_($state[3]).'">' . JHtml::_('image', 'admin/'.$state[0], JText::_($state[2]), NULL, true).'</a>'; return $html; } /** * Display an HTML select list of state filters * * @param int $selected The selected value of the list * @return string The HTML code for the select tag * @since 1.6 */ public static function filterstate($selected) { // Build the active state filter options. $options = array(); $options[] = JHtml::_('select.option', '*', JText::_('JOPTION_ANY')); $options[] = JHtml::_('select.option', '1', JText::_('JPUBLISHED')); $options[] = JHtml::_('select.option', '0', JText::_('JUNPUBLISHED')); return JHtml::_('select.genericlist', $options, 'filter_published', array( 'list.attr' => 'class="inputbox" onchange="this.form.submit();"', 'list.select' => $selected ) ); } } home/academiac/www/administrator/components/com_newsfeeds/controllers/newsfeed.php 0000644 00000005221 15137212326 0024756 0 ustar 00 <?php /** * @package Joomla.Administrator * @subpackage com_newsfeeds * * @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'); /** * Newsfeed controller class. * * @package Joomla.Administrator * @subpackage com_newsfeeds * @since 1.6 */ class NewsfeedsControllerNewsfeed extends JControllerForm { /** * 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 URL check it. $allow = $user->authorise('core.create', $this->option . '.category.' . $categoryId); } if ($allow === null) { // In the absence of better information, revert to the component permissions. return parent::allowAdd($data); } else { return $allow; } } /** * Method to check if you can edit a 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. $user = JFactory::getUser(); $recordId = (int) isset($data[$key]) ? $data[$key] : 0; $categoryId = 0; if ($recordId) { $categoryId = (int) $this->getModel()->getItem($recordId)->catid; } if ($categoryId) { // The category has been set. Check the category permissions. return $user->authorise('core.edit', $this->option . '.category.' . $categoryId); } else { // 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 2.5 */ public function batch($model = null) { JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); // Set the model $model = $this->getModel('Newsfeed', '', array()); // Preset the redirect $this->setRedirect(JRoute::_('index.php?option=com_newsfeeds&view=newsfeeds' . $this->getRedirectToListAppend(), false)); return parent::batch($model); } } home/academiac/www/components/com_newsfeeds/models/newsfeed.php 0000644 00000011410 15137455013 0021012 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.modelitem'); /** * Newsfeeds Component Newsfeed Model * * @package Joomla.Site * @subpackage com_newsfeeds * @since 1.5 */ class NewsfeedsModelNewsfeed extends JModelItem { /** * Model context string. * * @var string * @since 1.6 */ protected $_context = 'com_newsfeeds.newsfeed'; /** * Method to auto-populate the model state. * * Note. Calling getState in this method will result in recursion. * * @return void * @since 1.6 */ protected function populateState() { $app = JFactory::getApplication('site'); // Load state from the request. $pk = JRequest::getInt('id'); $this->setState('newsfeed.id', $pk); $offset = JRequest::getUInt('limitstart', 0); $this->setState('list.offset', $offset); // Load the parameters. $params = $app->getParams(); $this->setState('params', $params); $user = JFactory::getUser(); if ((!$user->authorise('core.edit.state', 'com_newsfeeds')) && (!$user->authorise('core.edit', 'com_newsfeeds'))){ $this->setState('filter.published', 1); $this->setState('filter.archived', 2); } } /** * Method to get newsfeed data. * * @param integer The id of the newsfeed. * * @return mixed Menu item data object on success, false on failure. * @since 1.6 */ public function &getItem($pk = null) { // Initialise variables. $pk = (!empty($pk)) ? $pk : (int) $this->getState('newsfeed.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.*')); $query->from('#__newsfeeds 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'); // 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'); $query->where('a.id = ' . (int) $pk); // Filter by start and end dates. $nullDate = $db->Quote($db->getNullDate()); $nowDate = $db->Quote(JFactory::getDate()->toSql()); // Filter by published state. $published = $this->getState('filter.published'); $archived = $this->getState('filter.archived'); if (is_numeric($published)) { $query->where('(a.published = ' . (int) $published . ' OR a.published =' . (int) $archived . ')'); $query->where('(a.publish_up = ' . $nullDate . ' OR a.publish_up <= ' . $nowDate . ')'); $query->where('(a.publish_down = ' . $nullDate . ' OR a.publish_down >= ' . $nowDate . ')'); $query->where('(c.published = ' . (int) $published . ' OR c.published =' . (int) $archived . ')'); } $db->setQuery($query); $data = $db->loadObject(); if ($error = $db->getErrorMsg()) { throw new Exception($error); } if (empty($data)) { throw new JException(JText::_('COM_NEWSFEEDS_ERROR_FEED_NOT_FOUND'), 404); } // Check for published state if filter set. if (((is_numeric($published)) || (is_numeric($archived))) && (($data->published != $published) && ($data->published != $archived))) { JError::raiseError(404, JText::_('COM_NEWSFEEDS_ERROR_FEED_NOT_FOUND')); } // Convert parameter fields to objects. $registry = new JRegistry; $registry->loadString($data->params); $data->params = clone $this->getState('params'); $data->params->merge($registry); $registry = new JRegistry; $registry->loadString($data->metadata); $data->metadata = $registry; // Compute 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(); $data->params->set('access-view', in_array($data->access, $groups) && in_array($data->category_access, $groups)); } $this->_item[$pk] = $data; } catch (JException $e) { $this->setError($e); $this->_item[$pk] = false; } } return $this->_item[$pk]; } }
©
2018.