/administrator/components/com_xmap/tables/sitemap.php

https://bitbucket.org/nlabyt/bcf-ball-4eb2 · PHP · 251 lines · 111 code · 25 blank · 115 comment · 16 complexity · 50616e33bd64366ee4e2fe116d41baae MD5 · raw file

  1. <?php
  2. /**
  3. * @version $Id$
  4. * @copyright Copyright (C) 2007 - 2009 Joomla! Vargas. All rights reserved.
  5. * @license GNU General Public License version 2 or later; see LICENSE.txt
  6. * @author Guillermo Vargas (guille@vargas.co.cr)
  7. */
  8. // no direct access
  9. defined('_JEXEC') or die;
  10. /**
  11. * @package Xmap
  12. * @subpackage com_xmap
  13. * @since 2.0
  14. */
  15. class XmapTableSitemap extends JTable
  16. {
  17. /**
  18. * @var int Primary key
  19. */
  20. var $id = null;
  21. /**
  22. * @var string
  23. */
  24. var $title = null;
  25. /**
  26. * @var string
  27. */
  28. var $alias = null;
  29. /**
  30. * @var string
  31. */
  32. var $introtext = null;
  33. /**
  34. * @var string
  35. */
  36. var $metakey = null;
  37. /**
  38. * @var string
  39. */
  40. var $attribs = null;
  41. /**
  42. * @var string
  43. */
  44. var $selections = null;
  45. /**
  46. * @var string
  47. */
  48. var $created = null;
  49. /**
  50. * @var string
  51. */
  52. var $metadesc = null;
  53. /**
  54. * @var string
  55. */
  56. var $excluded_items = null;
  57. /**
  58. * @var int
  59. */
  60. var $is_default = 0;
  61. /**
  62. * @var int
  63. */
  64. var $state = 0;
  65. /**
  66. * @var int
  67. */
  68. var $access = 0;
  69. /**
  70. * @var int
  71. */
  72. var $count_xml = 0;
  73. /**
  74. * @var int
  75. */
  76. var $count_html = 0;
  77. /**
  78. * @var int
  79. */
  80. var $views_xml = 0;
  81. /**
  82. * @var int
  83. */
  84. var $views_html = 0;
  85. /**
  86. * @var int
  87. */
  88. var $lastvisit_xml = 0;
  89. /**
  90. * @var int
  91. */
  92. var $lastvisit_html = 0;
  93. /**
  94. * @param JDatabase A database connector object
  95. */
  96. function __construct(&$db)
  97. {
  98. parent::__construct('#__xmap_sitemap', 'id', $db);
  99. }
  100. /**
  101. * Overloaded bind function
  102. *
  103. * @access public
  104. * @param array $hash named array
  105. * @return null|string null is operation was satisfactory, otherwise returns an error
  106. * @see JTable:bind
  107. * @since 2.0
  108. */
  109. function bind($array, $ignore = '')
  110. {
  111. if (isset($array['attribs']) && is_array($array['attribs'])) {
  112. $registry = new JRegistry();
  113. $registry->loadArray($array['attribs']);
  114. $array['attribs'] = $registry->toString();
  115. }
  116. if (isset($array['selections']) && is_array($array['selections'])) {
  117. $selections = array();
  118. foreach ($array['selections'] as $i => $menu) {
  119. $selections[$menu] = array(
  120. 'priority' => $array['selections_priority'][$i],
  121. 'changefreq' => $array['selections_changefreq'][$i],
  122. 'ordering' => $i
  123. );
  124. }
  125. $registry = new JRegistry();
  126. $registry->loadArray($selections);
  127. $array['selections'] = $registry->toString();
  128. }
  129. if (isset($array['metadata']) && is_array($array['metadata'])) {
  130. $registry = new JRegistry();
  131. $registry->loadArray($array['metadata']);
  132. $array['metadata'] = $registry->toString();
  133. }
  134. return parent::bind($array, $ignore);
  135. }
  136. /**
  137. * Overloaded check function
  138. *
  139. * @access public
  140. * @return boolean
  141. * @see JTable::check
  142. * @since 2.0
  143. */
  144. function check()
  145. {
  146. if (empty($this->title)) {
  147. $this->setError(JText::_('Sitemap must have a title'));
  148. return false;
  149. }
  150. if (empty($this->alias)) {
  151. $this->alias = $this->title;
  152. }
  153. $this->alias = JFilterOutput::stringURLSafe($this->alias);
  154. if (trim(str_replace('-', '', $this->alias)) == '') {
  155. $datenow = &JFactory::getDate();
  156. $this->alias = $datenow->toFormat("%Y-%m-%d-%H-%M-%S");
  157. }
  158. return true;
  159. }
  160. /**
  161. * Overriden JTable::store to set modified data and user id.
  162. *
  163. * @param boolean True to update fields even if they are null.
  164. * @return boolean True on success.
  165. * @since 2.0
  166. */
  167. public function store($updateNulls = false)
  168. {
  169. $date = JFactory::getDate();
  170. if (!$this->id) {
  171. $this->created = $date->toSql();
  172. }
  173. return parent::store($updateNulls);
  174. }
  175. /**
  176. * Method to set the publishing state for a row or list of rows in the database
  177. * table.
  178. *
  179. * @param mixed An optional array of primary key values to update. If not
  180. * set the instance property value is used.
  181. * @param integer The publishing state. eg. [0 = unpublished, 1 = published]
  182. * @param integer The user id of the user performing the operation.
  183. * @return boolean True on success.
  184. * @since 2.0
  185. */
  186. public function publish($pks = null, $state = 1, $userId = 0)
  187. {
  188. // Initialize variables.
  189. $k = $this->_tbl_key;
  190. // Sanitize input.
  191. JArrayHelper::toInteger($pks);
  192. $userId = (int) $userId;
  193. $state = (int) $state;
  194. // If there are no primary keys set check to see if the instance key is set.
  195. if (empty($pks)) {
  196. if ($this->$k) {
  197. $pks = array($this->$k);
  198. }
  199. // Nothing to set publishing state on, return false.
  200. else {
  201. $this->setError(JText::_('No_Rows_Selected'));
  202. return false;
  203. }
  204. }
  205. // Build the WHERE clause for the primary keys.
  206. $where = $k . '=' . implode(' OR ' . $k . '=', $pks);
  207. // Update the publishing state for rows with the given primary keys.
  208. $query = $this->_db->getQuery(true)
  209. ->update($this->_db->quoteName('#__xmap_sitemap'))
  210. ->set($this->_db->quoteName('state').' = '. (int) $state)
  211. ->where($where);
  212. $this->_db->setQuery($query);
  213. $this->_db->query();
  214. // Check for a database error.
  215. if ($this->_db->getErrorNum()) {
  216. $this->setError($this->_db->getErrorMsg());
  217. return false;
  218. }
  219. // If the JTable instance value is in the list of primary keys that were set, set the instance.
  220. if (in_array($this->$k, $pks)) {
  221. $this->state = $state;
  222. }
  223. $this->setError('');
  224. return true;
  225. }
  226. }