/libraries/joomla/database/table/content.php

https://github.com/raeldc/nooku-server · PHP · 191 lines · 100 code · 17 blank · 74 comment · 8 complexity · a873106cbc02c36be72aff7d7a5b6767 MD5 · raw file

  1. <?php
  2. /**
  3. * @version $Id: content.php 14401 2010-01-26 14:10:00Z louis $
  4. * @package Joomla.Framework
  5. * @subpackage Table
  6. * @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
  7. * @license GNU/GPL, see LICENSE.php
  8. * Joomla! is free software. This version may have been modified pursuant
  9. * to the GNU General Public License, and as distributed it includes or
  10. * is derivative of works licensed under the GNU General Public License or
  11. * other free or open source software licenses.
  12. * See COPYRIGHT.php for copyright notices and details.
  13. */
  14. // Check to ensure this file is within the rest of the framework
  15. defined('JPATH_BASE') or die();
  16. /**
  17. * Content table
  18. *
  19. * @package Joomla.Framework
  20. * @subpackage Table
  21. * @since 1.0
  22. */
  23. class JTableContent extends JTable
  24. {
  25. /** @var int Primary key */
  26. var $id = null;
  27. /** @var string */
  28. var $title = null;
  29. /** @var string */
  30. var $alias = null;
  31. /** @var string */
  32. var $title_alias = null;
  33. /** @var string */
  34. var $introtext = null;
  35. /** @var string */
  36. var $fulltext = null;
  37. /** @var int */
  38. var $state = null;
  39. /** @var int The id of the category section*/
  40. var $sectionid = null;
  41. /** @var int DEPRECATED */
  42. var $mask = null;
  43. /** @var int */
  44. var $catid = null;
  45. /** @var datetime */
  46. var $created = null;
  47. /** @var int User id*/
  48. var $created_by = null;
  49. /** @var string An alias for the author*/
  50. var $created_by_alias = null;
  51. /** @var datetime */
  52. var $modified = null;
  53. /** @var int User id*/
  54. var $modified_by = null;
  55. /** @var boolean */
  56. var $checked_out = 0;
  57. /** @var time */
  58. var $checked_out_time = 0;
  59. /** @var datetime */
  60. var $publish_up = null;
  61. /** @var datetime */
  62. var $publish_down = null;
  63. /** @var string */
  64. var $images = null;
  65. /** @var string */
  66. var $urls = null;
  67. /** @var string */
  68. var $attribs = null;
  69. /** @var int */
  70. var $version = null;
  71. /** @var int */
  72. var $parentid = null;
  73. /** @var int */
  74. var $ordering = null;
  75. /** @var string */
  76. var $metakey = null;
  77. /** @var string */
  78. var $metadesc = null;
  79. /** @var string */
  80. var $metadata = null;
  81. /** @var int */
  82. var $access = null;
  83. /** @var int */
  84. var $hits = null;
  85. /**
  86. * @param database A database connector object
  87. */
  88. function __construct( &$db ) {
  89. parent::__construct( '#__content', 'id', $db );
  90. }
  91. /**
  92. * Overloaded check function
  93. *
  94. * @access public
  95. * @return boolean
  96. * @see JTable::check
  97. * @since 1.5
  98. */
  99. function check()
  100. {
  101. /*
  102. TODO: This filter is too rigorous,need to implement more configurable solution
  103. // specific filters
  104. $filter = & JFilterInput::getInstance( null, null, 1, 1 );
  105. $this->introtext = trim( $filter->clean( $this->introtext ) );
  106. $this->fulltext = trim( $filter->clean( $this->fulltext ) );
  107. */
  108. if(empty($this->title)) {
  109. $this->setError(JText::_('Article must have a title'));
  110. return false;
  111. }
  112. if(empty($this->alias)) {
  113. $this->alias = $this->title;
  114. }
  115. $this->alias = JFilterOutput::stringURLSafe($this->alias);
  116. if(trim(str_replace('-','',$this->alias)) == '') {
  117. $datenow =& JFactory::getDate();
  118. $this->alias = $datenow->toFormat("%Y-%m-%d-%H-%M-%S");
  119. }
  120. if (trim( str_replace( '&nbsp;', '', $this->fulltext ) ) == '') {
  121. $this->fulltext = '';
  122. }
  123. // clean up keywords -- eliminate extra spaces between phrases
  124. // and cr (\r) and lf (\n) characters from string
  125. if(!empty($this->metakey)) { // only process if not empty
  126. $bad_characters = array("\n", "\r", "\"", "<", ">"); // array of characters to remove
  127. $after_clean = JString::str_ireplace($bad_characters, "", $this->metakey); // remove bad characters
  128. $keys = explode(',', $after_clean); // create array using commas as delimiter
  129. $clean_keys = array();
  130. foreach($keys as $key) {
  131. if(trim($key)) { // ignore blank keywords
  132. $clean_keys[] = trim($key);
  133. }
  134. }
  135. $this->metakey = implode(", ", $clean_keys); // put array back together delimited by ", "
  136. }
  137. // clean up description -- eliminate quotes and <> brackets
  138. if(!empty($this->metadesc)) { // only process if not empty
  139. $bad_characters = array("\"", "<", ">");
  140. $this->metadesc = JString::str_ireplace($bad_characters, "", $this->metadesc);
  141. }
  142. return true;
  143. }
  144. /**
  145. * Converts record to XML
  146. * @param boolean Map foreign keys to text values
  147. */
  148. function toXML( $mapKeysToText=false )
  149. {
  150. $db =& JFactory::getDBO();
  151. if ($mapKeysToText) {
  152. $query = 'SELECT name'
  153. . ' FROM #__sections'
  154. . ' WHERE id = '. (int) $this->sectionid
  155. ;
  156. $db->setQuery( $query );
  157. $this->sectionid = $db->loadResult();
  158. $query = 'SELECT name'
  159. . ' FROM #__categories'
  160. . ' WHERE id = '. (int) $this->catid
  161. ;
  162. $db->setQuery( $query );
  163. $this->catid = $db->loadResult();
  164. $query = 'SELECT name'
  165. . ' FROM #__users'
  166. . ' WHERE id = ' . (int) $this->created_by
  167. ;
  168. $db->setQuery( $query );
  169. $this->created_by = $db->loadResult();
  170. }
  171. return parent::toXML( $mapKeysToText );
  172. }
  173. }