0byt3m1n1-V2
Path:
/
home
/
a
/
c
/
a
/
academiac
/
www
/
[
Home
]
File: sitemap.php.tar
home/academiac/www/components/com_xmap/models/sitemap.php 0000604 00000023144 15137554555 0017654 0 ustar 00 <?php /** * @version $Id$ * @copyright Copyright (C) 2005 - 2009 Joomla! Vargas. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt * @author Guillermo Vargas (guille@vargas.co.cr) */ // No direct access defined('_JEXEC') or die; jimport('joomla.application.component.modelitem'); jimport('joomla.database.query'); require_once(JPATH_COMPONENT . '/helpers/xmap.php'); /** * Xmap Component Sitemap Model * * @package Xmap * @subpackage com_xmap * @since 2.0 */ class XmapModelSitemap extends JModelItem { /** * Model context string. * * @var string */ protected $_context = 'com_xmap.sitemap'; protected $_extensions = null; static $items = array(); /** * Method to auto-populate the model state. * * @return void */ protected function populateState() { $app = JFactory::getApplication('site'); // Load state from the request. $pk = JRequest::getInt('id'); $this->setState('sitemap.id', $pk); $offset = JRequest::getInt('limitstart'); $this->setState('list.offset', $offset); // Load the parameters. $params = $app->getParams(); $this->setState('params', $params); // TODO: Tune these values based on other permissions. $this->setState('filter.published', 1); $this->setState('filter.access', true); } /** * Method to get sitemap data. * * @param integer The id of the article. * * @return mixed Menu item data object on success, false on failure. */ public function &getItem($pk = null) { // Initialize variables. $db = $this->getDbo(); $pk = (!empty($pk)) ? $pk : (int) $this->getState('sitemap.id'); // If not sitemap specified, select the default one if (!$pk) { $query = $db->getQuery(true); $query->select('id')->from('#__xmap_sitemap')->where('is_default=1'); $db->setQuery($query); $pk = $db->loadResult(); } if ($this->_item === null) { $this->_item = array(); } if (!isset($this->_item[$pk])) { try { $query = $db->getQuery(true); $query->select($this->getState('item.select', 'a.*')); $query->from('#__xmap_sitemap AS a'); $query->where('a.id = ' . (int) $pk); // Filter by published state. $published = $this->getState('filter.published'); if (is_numeric($published)) { $query->where('a.state = ' . (int) $published); } // Filter by access level. if ($access = $this->getState('filter.access')) { $user = JFactory::getUser(); $groups = implode(',', $user->getAuthorisedViewLevels()); $query->where('a.access IN (' . $groups . ')'); } $this->_db->setQuery($query); $data = $this->_db->loadObject(); if ($error = $this->_db->getErrorMsg()) { throw new Exception($error); } if (empty($data)) { throw new Exception(JText::_('COM_XMAP_ERROR_SITEMAP_NOT_FOUND')); } // Check for published state if filter set. if (is_numeric($published) && $data->state != $published) { throw new Exception(JText::_('COM_XMAP_ERROR_SITEMAP_NOT_FOUND')); } // Convert parameter fields to objects. $registry = new JRegistry('_default'); $registry->loadString($data->attribs); $data->params = clone $this->getState('params'); $data->params->merge($registry); // Convert the selections field to an array. $registry = new JRegistry('_default'); $registry->loadString($data->selections); $data->selections = $registry->toArray(); // Compute access permissions. if ($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->authorisedLevels(); $data->params->set('access-view', in_array($data->access, $groups)); } // TODO: Type 2 permission checks? $this->_item[$pk] = $data; } catch (Exception $e) { $this->setError($e->getMessage()); $this->_item[$pk] = false; } } return $this->_item[$pk]; } public function getItems() { if ($item = $this->getItem()) { return XmapHelper::getMenuItems($item->selections); } return false; } function getExtensions() { return XmapHelper::getExtensions(); } /** * Increment the hit counter for the sitemap. * * @param int Optional primary key of the sitemap to increment. * * @return boolean True if successful; false otherwise and internal error set. */ public function hit($count) { // Initialize variables. $pk = (int) $this->getState('sitemap.id'); $view = JRequest::getCmd('view', 'html'); if ($view != 'xml' && $view != 'html') { return false; } $this->_db->setQuery( 'UPDATE #__xmap_sitemap' . ' SET views_' . $view . ' = views_' . $view . ' + 1, count_' . $view . ' = ' . $count . ', lastvisit_' . $view . ' = ' . JFactory::getDate()->toUnix() . ' WHERE id = ' . (int) $pk ); if (!$this->_db->query()) { $this->setError($this->_db->getErrorMsg()); return false; } return true; } public function getSitemapItems($view=null) { if (!isset($view)) { $view = JRequest::getCmd('view'); } $db = JFactory::getDBO(); $pk = (int) $this->getState('sitemap.id'); if (self::$items !== NULL && isset(self::$items[$view])) { return; } $query = "select * from #__xmap_items where view='$view' and sitemap_id=" . $pk; $db->setQuery($query); $rows = $db->loadObjectList(); self::$items[$view] = array(); foreach ($rows as $row) { self::$items[$view][$row->itemid] = array(); self::$items[$view][$row->itemid][$row->uid] = array(); $pairs = explode(';', $row->properties); foreach ($pairs as $pair) { if (strpos($pair, '=') !== FALSE) { list($property, $value) = explode('=', $pair); self::$items[$view][$row->itemid][$row->uid][$property] = $value; } } } return self::$items; } function chageItemPropery($uid, $itemid, $view, $property, $value) { $items = $this->getSitemapItems($view); $db = JFactory::getDBO(); $pk = (int) $this->getState('sitemap.id'); $isNew = false; if (empty($items[$view][$itemid][$uid])) { $items[$view][$itemid][$uid] = array(); $isNew = true; } $items[$view][$itemid][$uid][$property] = $value; $sep = $properties = ''; foreach ($items[$view][$itemid][$uid] as $k => $v) { $properties .= $sep . $k . '=' . $v; $sep = ';'; } if (!$isNew) { $query = 'UPDATE #__xmap_items SET properties=\'' . $db->escape($properties) . "' where uid='" . $db->escape($uid) . "' and itemid=$itemid and view='$view' and sitemap_id=" . $pk; } else { $query = 'INSERT #__xmap_items (uid,itemid,view,sitemap_id,properties) values ( \'' . $db->escape($uid) . "',$itemid,'$view',$pk,'" . $db->escape($properties) . "')"; } $db->setQuery($query); //echo $db->getQuery();exit; if ($db->query()) { return true; } else { return false; } } function toggleItem($uid, $itemid) { $app = JFactory::getApplication('site'); $sitemap = $this->getItem(); $displayer = new XmapDisplayer($app->getParams(), $sitemap); $excludedItems = $displayer->getExcludedItems(); if (isset($excludedItems[$itemid])) { $excludedItems[$itemid] = (array) $excludedItems[$itemid]; } if (!$displayer->isExcluded($itemid, $uid)) { $excludedItems[$itemid][] = $uid; $state = 0; } else { if (is_array($excludedItems[$itemid]) && count($excludedItems[$itemid])) { $excludedItems[$itemid] = array_filter($excludedItems[$itemid], create_function('$var', 'return ($var != \'' . $uid . '\');')); } else { unset($excludedItems[$itemid]); } $state = 1; } $registry = new JRegistry('_default'); $registry->loadArray($excludedItems); $str = $registry->toString(); $db = JFactory::getDBO(); $query = "UPDATE #__xmap_sitemap set excluded_items='" . $db->escape($str) . "' where id=" . $sitemap->id; $db->setQuery($query); $db->query(); return $state; } } home/academiac/www/administrator/components/com_xmap/models/sitemap.php 0000604 00000017172 15140173535 0022525 0 ustar 00 <?php /** * @version $Id$ * @copyright Copyright (C) 2005 - 2010 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'); /** * Sitemap model. * * @package Xmap * @subpackage com_xmap */ class XmapModelSitemap extends JModelAdmin { protected $_context = 'com_xmap'; /** * Constructor. * * @param array An optional associative array of configuration settings. * @see JController */ public function __construct($config = array()) { parent::__construct($config); $this->_item = 'sitemap'; $this->_option = 'com_xmap'; } /** * Method to auto-populate the model state. */ protected function _populateState() { $app = JFactory::getApplication('administrator'); // Load the User state. if (!($pk = (int) $app->getUserState('com_xmap.edit.sitemap.id'))) { $pk = (int) JRequest::getInt('id'); } $this->setState('sitemap.id', $pk); // Load the parameters. $params = JComponentHelper::getParams('com_xmap'); $this->setState('params', $params); } /** * 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 XmapTableSitemap A database object */ public function getTable($type = 'Sitemap', $prefix = 'XmapTable', $config = array()) { return JTable::getInstance($type, $prefix, $config); } /** * Method to get a single record. * * @param integer The id of the primary key. * * @return mixed Object on success, false on failure. */ public function getItem($pk = null) { // Initialise variables. $pk = (!empty($pk)) ? $pk : (int)$this->getState('sitemap.id'); $false = false; // Get a row instance. $table = $this->getTable(); // Attempt to load the row. $return = $table->load($pk); // Check for a table object error. if ($return === false && $table->getError()) { $this->setError($table->getError()); return $false; } // Prime required properties. if (empty($table->id)) { // Prepare data for a new record. } // Convert to the JObject before adding other data. $value = $table->getProperties(1); $value = JArrayHelper::toObject($value, 'JObject'); // Convert the params field to an array. $registry = new JRegistry; $registry->loadString($table->attribs); $value->attribs = $registry->toArray(); return $value; } /** * 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 mixed A JForm object on success, false on failure * @since 2.0 */ public function getForm($data = array(), $loadData = true) { // Get the form. $form = $this->loadForm('com_xmap.sitemap', 'sitemap', array('control' => 'jform', 'load_data' => $loadData)); if (empty($form)) { return false; } 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_xmap.edit.sitemap.data', array()); if (empty($data)) { $data = $this->getItem(); } return $data; } /** * Method to save the form data. * * @param array The form data. * @return boolean True on success. * @since 1.6 */ public function save($data) { // Initialise variables; $dispatcher = JDispatcher::getInstance(); $table = $this->getTable(); $pk = (!empty($data['id'])) ? $data['id'] : (int)$this->getState('sitemap.id'); $isNew = true; // Load the row if saving an existing record. if ($pk > 0) { $table->load($pk); $isNew = false; } // Bind the data. if (!$table->bind($data)) { $this->setError(JText::sprintf('JERROR_TABLE_BIND_FAILED', $table->getError())); return false; } // Prepare the row for saving $this->_prepareTable($table); // Check the data. if (!$table->check()) { $this->setError($table->getError()); return false; } if (!$table->is_default) { // Check if there is no default sitemap. Then, set it as default if not $result = $this->getDefaultSitemapId(); if (!$result) { $table->is_default=1; } } // Store the data. if (!$table->store()) { $this->setError($table->getError()); return false; } if ($table->is_default) { $query = $this->_db->getQuery(true) ->update($this->_db->quoteName('#__xmap_sitemap')) ->set($this->_db->quoteName('is_default').' = 0') ->where($this->_db->quoteName('id').' <> '.$table->id); $this->_db->setQuery($query); if (!$this->_db->query()) { $this->setError($table->_db->getErrorMsg()); return false; } } // Clean the cache. $cache = JFactory::getCache('com_xmap'); $cache->clean(); $this->setState('sitemap.id', $table->id); return true; } /** * Prepare and sanitise the table prior to saving. */ protected function _prepareTable(&$table) { // TODO. } function _orderConditions($table = null) { $condition = array(); return $condition; } function setDefault($id) { $table = $this->getTable(); if ($table->load($id)) { $db = JFactory::getDbo(); $query = $db->getQuery(true) ->update($db->quoteName('#__xmap_sitemap')) ->set($db->quoteName('is_default').' = 0') ->where($db->quoteName('id').' <> '.$table->id); $this->_db->setQuery($query); if (!$this->_db->query()) { $this->setError($table->_db->getErrorMsg()); return false; } $table->is_default = 1; $table->store(); // Clean the cache. $cache = JFactory::getCache('com_xmap'); $cache->clean(); return true; } } /** * Override to avoid warnings * */ public function checkout($pk = null) { return true; } private function getDefaultSitemapId() { $db = JFactory::getDBO(); $query = $db->getQuery(true); $query->select('id'); $query->from($db->quoteName('#__xmap_sitemap')); $query->where('is_default=1'); $db->setQuery($query); return $db->loadResult(); } } home/academiac/www/administrator/components/com_xmap/tables/sitemap.php 0000604 00000014415 15140212226 0022500 0 ustar 00 <?php /** * @version $Id$ * @copyright Copyright (C) 2007 - 2009 Joomla! Vargas. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt * @author Guillermo Vargas (guille@vargas.co.cr) */ // no direct access defined('_JEXEC') or die; /** * @package Xmap * @subpackage com_xmap * @since 2.0 */ class XmapTableSitemap extends JTable { /** * @var int Primary key */ var $id = null; /** * @var string */ var $title = null; /** * @var string */ var $alias = null; /** * @var string */ var $introtext = null; /** * @var string */ var $metakey = null; /** * @var string */ var $attribs = null; /** * @var string */ var $selections = null; /** * @var string */ var $created = null; /** * @var string */ var $metadesc = null; /** * @var string */ var $excluded_items = null; /** * @var int */ var $is_default = 0; /** * @var int */ var $state = 0; /** * @var int */ var $access = 0; /** * @var int */ var $count_xml = 0; /** * @var int */ var $count_html = 0; /** * @var int */ var $views_xml = 0; /** * @var int */ var $views_html = 0; /** * @var int */ var $lastvisit_xml = 0; /** * @var int */ var $lastvisit_html = 0; /** * @param JDatabase A database connector object */ function __construct(&$db) { parent::__construct('#__xmap_sitemap', 'id', $db); } /** * Overloaded bind function * * @access public * @param array $hash named array * @return null|string null is operation was satisfactory, otherwise returns an error * @see JTable:bind * @since 2.0 */ function bind($array, $ignore = '') { if (isset($array['attribs']) && is_array($array['attribs'])) { $registry = new JRegistry(); $registry->loadArray($array['attribs']); $array['attribs'] = $registry->toString(); } if (isset($array['selections']) && is_array($array['selections'])) { $selections = array(); foreach ($array['selections'] as $i => $menu) { $selections[$menu] = array( 'priority' => $array['selections_priority'][$i], 'changefreq' => $array['selections_changefreq'][$i], 'ordering' => $i ); } $registry = new JRegistry(); $registry->loadArray($selections); $array['selections'] = $registry->toString(); } if (isset($array['metadata']) && is_array($array['metadata'])) { $registry = new JRegistry(); $registry->loadArray($array['metadata']); $array['metadata'] = $registry->toString(); } return parent::bind($array, $ignore); } /** * Overloaded check function * * @access public * @return boolean * @see JTable::check * @since 2.0 */ function check() { if (empty($this->title)) { $this->setError(JText::_('Sitemap must have a title')); return false; } if (empty($this->alias)) { $this->alias = $this->title; } $this->alias = JApplication::stringURLSafe($this->alias); if (trim(str_replace('-', '', $this->alias)) == '') { $datenow = &JFactory::getDate(); $this->alias = $datenow->format("Y-m-d-H-i-s"); } 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 2.0 */ public function store($updateNulls = false) { $date = JFactory::getDate(); if (!$this->id) { $this->created = $date->toSql(); } return parent::store($updateNulls); } /** * Method to set the publishing state for a row or list of rows in the database * table. * * @param mixed An optional array of primary key values to update. If not * set the instance property value is used. * @param integer The publishing state. eg. [0 = unpublished, 1 = published] * @param integer The user id of the user performing the operation. * @return boolean True on success. * @since 2.0 */ public function publish($pks = null, $state = 1, $userId = 0) { // Initialize variables. $k = $this->_tbl_key; // Sanitize input. JArrayHelper::toInteger($pks); $userId = (int) $userId; $state = (int) $state; // If there are no primary keys set check to see if the instance key is set. if (empty($pks)) { if ($this->$k) { $pks = array($this->$k); } // Nothing to set publishing state on, return false. else { $this->setError(JText::_('No_Rows_Selected')); return false; } } // Build the WHERE clause for the primary keys. $where = $k . '=' . implode(' OR ' . $k . '=', $pks); // Update the publishing state for rows with the given primary keys. $query = $this->_db->getQuery(true) ->update($this->_db->quoteName('#__xmap_sitemap')) ->set($this->_db->quoteName('state').' = '. (int) $state) ->where($where); $this->_db->setQuery($query); $this->_db->query(); // Check for a database error. if ($this->_db->getErrorNum()) { $this->setError($this->_db->getErrorMsg()); return false; } // If the JTable instance value is in the list of primary keys that were set, set the instance. if (in_array($this->$k, $pks)) { $this->state = $state; } $this->setError(''); return true; } }
©
2018.