[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Administrator 5 * @subpackage com_newsfeeds 6 * 7 * @copyright (C) 2005 Open Source Matters, Inc. <https://www.joomla.org> 8 * @license GNU General Public License version 2 or later; see LICENSE.txt 9 */ 10 11 namespace Joomla\Component\Newsfeeds\Administrator\Table; 12 13 use Joomla\CMS\Application\ApplicationHelper; 14 use Joomla\CMS\Factory; 15 use Joomla\CMS\Language\Text; 16 use Joomla\CMS\String\PunycodeHelper; 17 use Joomla\CMS\Table\Table; 18 use Joomla\CMS\Tag\TaggableTableInterface; 19 use Joomla\CMS\Tag\TaggableTableTrait; 20 use Joomla\CMS\Versioning\VersionableTableInterface; 21 use Joomla\Database\DatabaseDriver; 22 use Joomla\String\StringHelper; 23 24 // phpcs:disable PSR1.Files.SideEffects 25 \defined('_JEXEC') or die; 26 // phpcs:enable PSR1.Files.SideEffects 27 28 /** 29 * Newsfeed Table class. 30 * 31 * @since 1.6 32 */ 33 class NewsfeedTable extends Table implements VersionableTableInterface, TaggableTableInterface 34 { 35 use TaggableTableTrait; 36 37 /** 38 * Indicates that columns fully support the NULL value in the database 39 * 40 * @var boolean 41 * @since 4.0.0 42 */ 43 protected $_supportNullValue = true; 44 45 /** 46 * Ensure the params, metadata and images are json encoded in the bind method 47 * 48 * @var array 49 * @since 3.3 50 */ 51 protected $_jsonEncode = array('params', 'metadata', 'images'); 52 53 /** 54 * Constructor 55 * 56 * @param DatabaseDriver $db A database connector object 57 */ 58 public function __construct(DatabaseDriver $db) 59 { 60 $this->typeAlias = 'com_newsfeeds.newsfeed'; 61 parent::__construct('#__newsfeeds', 'id', $db); 62 $this->setColumnAlias('title', 'name'); 63 } 64 65 /** 66 * Overloaded check method to ensure data integrity. 67 * 68 * @return boolean True on success. 69 */ 70 public function check() 71 { 72 try { 73 parent::check(); 74 } catch (\Exception $e) { 75 $this->setError($e->getMessage()); 76 77 return false; 78 } 79 80 // Check for valid name. 81 if (trim($this->name) == '') { 82 $this->setError(Text::_('COM_NEWSFEEDS_WARNING_PROVIDE_VALID_NAME')); 83 84 return false; 85 } 86 87 if (empty($this->alias)) { 88 $this->alias = $this->name; 89 } 90 91 $this->alias = ApplicationHelper::stringURLSafe($this->alias, $this->language); 92 93 if (trim(str_replace('-', '', $this->alias)) == '') { 94 $this->alias = Factory::getDate()->format('Y-m-d-H-i-s'); 95 } 96 97 // Check for a valid category. 98 if (!$this->catid = (int) $this->catid) { 99 $this->setError(Text::_('JLIB_DATABASE_ERROR_CATEGORY_REQUIRED')); 100 101 return false; 102 } 103 104 // Check the publish down date is not earlier than publish up. 105 if ((int) $this->publish_down > 0 && $this->publish_down < $this->publish_up) { 106 $this->setError(Text::_('JGLOBAL_START_PUBLISH_AFTER_FINISH')); 107 108 return false; 109 } 110 111 // Clean up description -- eliminate quotes and <> brackets 112 if (!empty($this->metadesc)) { 113 // Only process if not empty 114 $bad_characters = array("\"", '<', '>'); 115 $this->metadesc = StringHelper::str_ireplace($bad_characters, '', $this->metadesc); 116 } 117 118 if (is_null($this->hits)) { 119 $this->hits = 0; 120 } 121 122 return true; 123 } 124 125 /** 126 * Overridden \JTable::store to set modified data. 127 * 128 * @param boolean $updateNulls True to update fields even if they are null. 129 * 130 * @return boolean True on success. 131 * 132 * @since 1.6 133 */ 134 public function store($updateNulls = true) 135 { 136 $date = Factory::getDate(); 137 $user = Factory::getUser(); 138 139 // Set created date if not set. 140 if (!(int) $this->created) { 141 $this->created = $date->toSql(); 142 } 143 144 if ($this->id) { 145 // Existing item 146 $this->modified_by = $user->get('id'); 147 $this->modified = $date->toSql(); 148 } else { 149 // Field created_by can be set by the user, so we don't touch it if it's set. 150 if (empty($this->created_by)) { 151 $this->created_by = $user->get('id'); 152 } 153 154 if (!(int) $this->modified) { 155 $this->modified = $this->created; 156 } 157 158 if (empty($this->modified_by)) { 159 $this->modified_by = $this->created_by; 160 } 161 } 162 163 // Set publish_up, publish_down to null if not set 164 if (!$this->publish_up) { 165 $this->publish_up = null; 166 } 167 168 if (!$this->publish_down) { 169 $this->publish_down = null; 170 } 171 172 // Verify that the alias is unique 173 $table = Table::getInstance('NewsfeedTable', __NAMESPACE__ . '\\', array('dbo' => $this->_db)); 174 175 if ($table->load(array('alias' => $this->alias, 'catid' => $this->catid)) && ($table->id != $this->id || $this->id == 0)) { 176 $this->setError(Text::_('COM_NEWSFEEDS_ERROR_UNIQUE_ALIAS')); 177 178 return false; 179 } 180 181 // Save links as punycode. 182 $this->link = PunycodeHelper::urlToPunycode($this->link); 183 184 return parent::store($updateNulls); 185 } 186 187 /** 188 * Get the type alias for the history table 189 * 190 * @return string The alias as described above 191 * 192 * @since 4.0.0 193 */ 194 public function getTypeAlias() 195 { 196 return $this->typeAlias; 197 } 198 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |