| [ Index ] |
PHP Cross Reference of Joomla 2.5.4 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @package Joomla.Platform 4 * @subpackage Database 5 * 6 * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. 7 * @license GNU General Public License version 2 or later; see LICENSE 8 */ 9 10 defined('JPATH_PLATFORM') or die; 11 12 jimport('joomla.database.tableasset'); 13 jimport('joomla.database.table'); 14 15 /** 16 * Content table 17 * 18 * @package Joomla.Platform 19 * @subpackage Table 20 * @since 11.1 21 */ 22 class JTableContent extends JTable 23 { 24 /** 25 * Constructor 26 * 27 * @param JDatabase &$db A database connector object 28 * 29 * @since 11.1 30 */ 31 public function __construct(&$db) 32 { 33 parent::__construct('#__content', 'id', $db); 34 } 35 36 /** 37 * Method to compute the default name of the asset. 38 * The default name is in the form table_name.id 39 * where id is the value of the primary key of the table. 40 * 41 * @return string 42 * 43 * @since 11.1 44 */ 45 protected function _getAssetName() 46 { 47 $k = $this->_tbl_key; 48 return 'com_content.article.' . (int) $this->$k; 49 } 50 51 /** 52 * Method to return the title to use for the asset table. 53 * 54 * @return string 55 * 56 * @since 11.1 57 */ 58 protected function _getAssetTitle() 59 { 60 return $this->title; 61 } 62 63 /** 64 * Method to get the parent asset id for the record 65 * 66 * @param JTable $table A JTable object (optional) for the asset parent 67 * @param integer $id The id (optional) of the content. 68 * 69 * @return integer 70 * 71 * @since 11.1 72 */ 73 protected function _getAssetParentId($table = null, $id = null) 74 { 75 // Initialise variables. 76 $assetId = null; 77 78 // This is a article under a category. 79 if ($this->catid) 80 { 81 // Build the query to get the asset id for the parent category. 82 $query = $this->_db->getQuery(true); 83 $query->select($this->_db->quoteName('asset_id')); 84 $query->from($this->_db->quoteName('#__categories')); 85 $query->where($this->_db->quoteName('id') . ' = ' . (int) $this->catid); 86 87 // Get the asset id from the database. 88 $this->_db->setQuery($query); 89 if ($result = $this->_db->loadResult()) 90 { 91 $assetId = (int) $result; 92 } 93 } 94 95 // Return the asset id. 96 if ($assetId) 97 { 98 return $assetId; 99 } 100 else 101 { 102 return parent::_getAssetParentId($table, $id); 103 } 104 } 105 106 /** 107 * Overloaded bind function 108 * 109 * @param array $array Named array 110 * @param mixed $ignore An optional array or space separated list of properties 111 * to ignore while binding. 112 * 113 * @return mixed Null if operation was satisfactory, otherwise returns an error string 114 * 115 * @see JTable::bind 116 * @since 11.1 117 */ 118 public function bind($array, $ignore = '') 119 { 120 // Search for the {readmore} tag and split the text up accordingly. 121 if (isset($array['articletext'])) 122 { 123 $pattern = '#<hr\s+id=("|\')system-readmore("|\')\s*\/*>#i'; 124 $tagPos = preg_match($pattern, $array['articletext']); 125 126 if ($tagPos == 0) 127 { 128 $this->introtext = $array['articletext']; 129 $this->fulltext = ''; 130 } 131 else 132 { 133 list ($this->introtext, $this->fulltext) = preg_split($pattern, $array['articletext'], 2); 134 } 135 } 136 137 if (isset($array['attribs']) && is_array($array['attribs'])) 138 { 139 $registry = new JRegistry; 140 $registry->loadArray($array['attribs']); 141 $array['attribs'] = (string) $registry; 142 } 143 144 if (isset($array['metadata']) && is_array($array['metadata'])) 145 { 146 $registry = new JRegistry; 147 $registry->loadArray($array['metadata']); 148 $array['metadata'] = (string) $registry; 149 } 150 151 // Bind the rules. 152 if (isset($array['rules']) && is_array($array['rules'])) 153 { 154 $rules = new JAccessRules($array['rules']); 155 $this->setRules($rules); 156 } 157 158 return parent::bind($array, $ignore); 159 } 160 161 /** 162 * Overloaded check function 163 * 164 * @return boolean True on success, false on failure 165 * 166 * @see JTable::check 167 * @since 11.1 168 */ 169 public function check() 170 { 171 if (trim($this->title) == '') 172 { 173 $this->setError(JText::_('COM_CONTENT_WARNING_PROVIDE_VALID_NAME')); 174 return false; 175 } 176 177 if (trim($this->alias) == '') 178 { 179 $this->alias = $this->title; 180 } 181 182 $this->alias = JApplication::stringURLSafe($this->alias); 183 184 if (trim(str_replace('-', '', $this->alias)) == '') 185 { 186 $this->alias = JFactory::getDate()->format('Y-m-d-H-i-s'); 187 } 188 189 if (trim(str_replace(' ', '', $this->fulltext)) == '') 190 { 191 $this->fulltext = ''; 192 } 193 194 if (trim($this->introtext) == '' && trim($this->fulltext) == '') 195 { 196 $this->setError(JText::_('JGLOBAL_ARTICLE_MUST_HAVE_TEXT')); 197 return false; 198 } 199 200 // Check the publish down date is not earlier than publish up. 201 if ($this->publish_down > $this->_db->getNullDate() && $this->publish_down < $this->publish_up) 202 { 203 $this->setError(JText::_('JGLOBAL_START_PUBLISH_AFTER_FINISH')); 204 return false; 205 } 206 207 // Clean up keywords -- eliminate extra spaces between phrases 208 // and cr (\r) and lf (\n) characters from string 209 if (!empty($this->metakey)) 210 { 211 // Only process if not empty 212 $bad_characters = array("\n", "\r", "\"", "<", ">"); // array of characters to remove 213 $after_clean = JString::str_ireplace($bad_characters, "", $this->metakey); // remove bad characters 214 $keys = explode(',', $after_clean); // create array using commas as delimiter 215 $clean_keys = array(); 216 217 foreach ($keys as $key) 218 { 219 if (trim($key)) 220 { 221 // Ignore blank keywords 222 $clean_keys[] = trim($key); 223 } 224 } 225 $this->metakey = implode(", ", $clean_keys); // put array back together delimited by ", " 226 } 227 228 return true; 229 } 230 231 /** 232 * Overrides JTable::store to set modified data and user id. 233 * 234 * @param boolean $updateNulls True to update fields even if they are null. 235 * 236 * @return boolean True on success. 237 * 238 * @since 11.1 239 */ 240 public function store($updateNulls = false) 241 { 242 $date = JFactory::getDate(); 243 $user = JFactory::getUser(); 244 245 if ($this->id) 246 { 247 // Existing item 248 $this->modified = $date->toSql(); 249 $this->modified_by = $user->get('id'); 250 } 251 else 252 { 253 // New article. An article created and created_by field can be set by the user, 254 // so we don't touch either of these if they are set. 255 if (!intval($this->created)) 256 { 257 $this->created = $date->toSql(); 258 } 259 260 if (empty($this->created_by)) 261 { 262 $this->created_by = $user->get('id'); 263 } 264 } 265 // Verify that the alias is unique 266 $table = JTable::getInstance('Content', 'JTable'); 267 if ($table->load(array('alias' => $this->alias, 'catid' => $this->catid)) && ($table->id != $this->id || $this->id == 0)) 268 { 269 $this->setError(JText::_('JLIB_DATABASE_ERROR_ARTICLE_UNIQUE_ALIAS')); 270 return false; 271 } 272 return parent::store($updateNulls); 273 } 274 275 /** 276 * Method to set the publishing state for a row or list of rows in the database 277 * table. The method respects checked out rows by other users and will attempt 278 * to checkin rows that it can after adjustments are made. 279 * 280 * @param mixed $pks An optional array of primary key values to update. If not set the instance property value is used. 281 * @param integer $state The publishing state. eg. [0 = unpublished, 1 = published] 282 * @param integer $userId The user id of the user performing the operation. 283 * 284 * @return boolean True on success. 285 * 286 * @since 11.1 287 */ 288 public function publish($pks = null, $state = 1, $userId = 0) 289 { 290 // Initialise variables. 291 $k = $this->_tbl_key; 292 293 // Sanitize input. 294 JArrayHelper::toInteger($pks); 295 $userId = (int) $userId; 296 $state = (int) $state; 297 298 // If there are no primary keys set check to see if the instance key is set. 299 if (empty($pks)) 300 { 301 if ($this->$k) 302 { 303 $pks = array($this->$k); 304 } 305 // Nothing to set publishing state on, return false. 306 else 307 { 308 $this->setError(JText::_('JLIB_DATABASE_ERROR_NO_ROWS_SELECTED')); 309 return false; 310 } 311 } 312 313 // Build the WHERE clause for the primary keys. 314 $where = $k . '=' . implode(' OR ' . $k . '=', $pks); 315 316 // Determine if there is checkin support for the table. 317 if (!property_exists($this, 'checked_out') || !property_exists($this, 'checked_out_time')) 318 { 319 $checkin = ''; 320 } 321 else 322 { 323 $checkin = ' AND (checked_out = 0 OR checked_out = ' . (int) $userId . ')'; 324 } 325 326 // Get the JDatabaseQuery object 327 $query = $this->_db->getQuery(true); 328 329 // Update the publishing state for rows with the given primary keys. 330 $query->update($this->_db->quoteName($this->_tbl)); 331 $query->set($this->_db->quoteName('state') . ' = ' . (int) $state); 332 $query->where('(' . $where . ')' . $checkin); 333 $this->_db->setQuery($query); 334 $this->_db->query(); 335 336 // Check for a database error. 337 if ($this->_db->getErrorNum()) 338 { 339 $this->setError($this->_db->getErrorMsg()); 340 return false; 341 } 342 343 // If checkin is supported and all rows were adjusted, check them in. 344 if ($checkin && (count($pks) == $this->_db->getAffectedRows())) 345 { 346 // Checkin the rows. 347 foreach ($pks as $pk) 348 { 349 $this->checkin($pk); 350 } 351 } 352 353 // If the JTable instance value is in the list of primary keys that were set, set the instance. 354 if (in_array($this->$k, $pks)) 355 { 356 $this->state = $state; 357 } 358 359 $this->setError(''); 360 361 return true; 362 } 363 364 /** 365 * Converts record to XML 366 * 367 * @param boolean $mapKeysToText Map foreign keys to text values 368 * 369 * @return string Record in XML format 370 * 371 * @since 11.1 372 * @deprecated 12.1 373 * @codeCoverageIgnore 374 */ 375 public function toXML($mapKeysToText = false) 376 { 377 // Deprecation warning. 378 JLog::add('JTableContent::toXML() is deprecated.', JLog::WARNING, 'deprecated'); 379 380 if ($mapKeysToText) 381 { 382 // Get the JDatabaseQuery object 383 $query = $this->_db->getQuery(true); 384 385 $query->select($this->_db->quoteName('name')); 386 $query->from($this->_db->quoteName('#__categories')); 387 $query->where($this->_db->quoteName('id') . ' = ' . (int) $this->catid); 388 $this->_db->setQuery($query); 389 $this->catid = $this->_db->loadResult(); 390 391 $query->clear(); 392 $query->select($this->_db->quoteName('name')); 393 $query->from($this->_db->quoteName('#__users')); 394 $query->where($this->_db->quoteName('id') . ' = ' . (int) $this->created_by); 395 $this->_db->setQuery($query); 396 $this->created_by = $this->_db->loadResult(); 397 } 398 399 return parent::toXML($mapKeysToText); 400 } 401 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Apr 3 11:40:28 2012 | Cross-referenced by PHPXref 0.7.1 |