[ 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_contact 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\Contact\Administrator\Table; 12 13 use Joomla\CMS\Application\ApplicationHelper; 14 use Joomla\CMS\Factory; 15 use Joomla\CMS\Filter\InputFilter; 16 use Joomla\CMS\Language\Text; 17 use Joomla\CMS\String\PunycodeHelper; 18 use Joomla\CMS\Table\Table; 19 use Joomla\CMS\Tag\TaggableTableInterface; 20 use Joomla\CMS\Tag\TaggableTableTrait; 21 use Joomla\CMS\Versioning\VersionableTableInterface; 22 use Joomla\Database\DatabaseDriver; 23 use Joomla\String\StringHelper; 24 25 // phpcs:disable PSR1.Files.SideEffects 26 \defined('_JEXEC') or die; 27 // phpcs:enable PSR1.Files.SideEffects 28 29 /** 30 * Contact Table class. 31 * 32 * @since 1.0 33 */ 34 class ContactTable extends Table implements VersionableTableInterface, TaggableTableInterface 35 { 36 use TaggableTableTrait; 37 38 /** 39 * Indicates that columns fully support the NULL value in the database 40 * 41 * @var boolean 42 * @since 4.0.0 43 */ 44 protected $_supportNullValue = true; 45 46 /** 47 * Ensure the params and metadata in json encoded in the bind method 48 * 49 * @var array 50 * @since 3.3 51 */ 52 protected $_jsonEncode = array('params', 'metadata'); 53 54 /** 55 * Constructor 56 * 57 * @param DatabaseDriver $db Database connector object 58 * 59 * @since 1.0 60 */ 61 public function __construct(DatabaseDriver $db) 62 { 63 $this->typeAlias = 'com_contact.contact'; 64 65 parent::__construct('#__contact_details', 'id', $db); 66 67 $this->setColumnAlias('title', 'name'); 68 } 69 70 /** 71 * Stores a contact. 72 * 73 * @param boolean $updateNulls True to update fields even if they are null. 74 * 75 * @return boolean True on success, false on failure. 76 * 77 * @since 1.6 78 */ 79 public function store($updateNulls = true) 80 { 81 $date = Factory::getDate()->toSql(); 82 $userId = Factory::getUser()->id; 83 84 // Set created date if not set. 85 if (!(int) $this->created) { 86 $this->created = $date; 87 } 88 89 if ($this->id) { 90 // Existing item 91 $this->modified_by = $userId; 92 $this->modified = $date; 93 } else { 94 // Field created_by field can be set by the user, so we don't touch it if it's set. 95 if (empty($this->created_by)) { 96 $this->created_by = $userId; 97 } 98 99 if (!(int) $this->modified) { 100 $this->modified = $date; 101 } 102 103 if (empty($this->modified_by)) { 104 $this->modified_by = $userId; 105 } 106 } 107 108 // Store utf8 email as punycode 109 if ($this->email_to !== null) { 110 $this->email_to = PunycodeHelper::emailToPunycode($this->email_to); 111 } 112 113 // Convert IDN urls to punycode 114 if ($this->webpage !== null) { 115 $this->webpage = PunycodeHelper::urlToPunycode($this->webpage); 116 } 117 118 // Verify that the alias is unique 119 $table = Table::getInstance('ContactTable', __NAMESPACE__ . '\\', array('dbo' => $this->getDbo())); 120 121 if ($table->load(array('alias' => $this->alias, 'catid' => $this->catid)) && ($table->id != $this->id || $this->id == 0)) { 122 $this->setError(Text::_('COM_CONTACT_ERROR_UNIQUE_ALIAS')); 123 124 return false; 125 } 126 127 return parent::store($updateNulls); 128 } 129 130 /** 131 * Overloaded check function 132 * 133 * @return boolean True on success, false on failure 134 * 135 * @see \JTable::check 136 * @since 1.5 137 */ 138 public function check() 139 { 140 try { 141 parent::check(); 142 } catch (\Exception $e) { 143 $this->setError($e->getMessage()); 144 145 return false; 146 } 147 148 $this->default_con = (int) $this->default_con; 149 150 if ($this->webpage !== null && InputFilter::checkAttribute(array('href', $this->webpage))) { 151 $this->setError(Text::_('COM_CONTACT_WARNING_PROVIDE_VALID_URL')); 152 153 return false; 154 } 155 156 // Check for valid name 157 if (trim($this->name) == '') { 158 $this->setError(Text::_('COM_CONTACT_WARNING_PROVIDE_VALID_NAME')); 159 160 return false; 161 } 162 163 // Generate a valid alias 164 $this->generateAlias(); 165 166 // Check for a valid category. 167 if (!$this->catid = (int) $this->catid) { 168 $this->setError(Text::_('JLIB_DATABASE_ERROR_CATEGORY_REQUIRED')); 169 170 return false; 171 } 172 173 // Sanity check for user_id 174 if (!$this->user_id) { 175 $this->user_id = 0; 176 } 177 178 // Check the publish down date is not earlier than publish up. 179 if ((int) $this->publish_down > 0 && $this->publish_down < $this->publish_up) { 180 $this->setError(Text::_('JGLOBAL_START_PUBLISH_AFTER_FINISH')); 181 182 return false; 183 } 184 185 if (!$this->id) { 186 // Hits must be zero on a new item 187 $this->hits = 0; 188 } 189 190 // Clean up description -- eliminate quotes and <> brackets 191 if (!empty($this->metadesc)) { 192 // Only process if not empty 193 $badCharacters = array("\"", '<', '>'); 194 $this->metadesc = StringHelper::str_ireplace($badCharacters, '', $this->metadesc); 195 } else { 196 $this->metadesc = ''; 197 } 198 199 if (empty($this->params)) { 200 $this->params = '{}'; 201 } 202 203 if (empty($this->metadata)) { 204 $this->metadata = '{}'; 205 } 206 207 // Set publish_up, publish_down to null if not set 208 if (!$this->publish_up) { 209 $this->publish_up = null; 210 } 211 212 if (!$this->publish_down) { 213 $this->publish_down = null; 214 } 215 216 if (!$this->modified) { 217 $this->modified = $this->created; 218 } 219 220 if (empty($this->modified_by)) { 221 $this->modified_by = $this->created_by; 222 } 223 224 return true; 225 } 226 227 /** 228 * Generate a valid alias from title / date. 229 * Remains public to be able to check for duplicated alias before saving 230 * 231 * @return string 232 */ 233 public function generateAlias() 234 { 235 if (empty($this->alias)) { 236 $this->alias = $this->name; 237 } 238 239 $this->alias = ApplicationHelper::stringURLSafe($this->alias, $this->language); 240 241 if (trim(str_replace('-', '', $this->alias)) == '') { 242 $this->alias = Factory::getDate()->format('Y-m-d-H-i-s'); 243 } 244 245 return $this->alias; 246 } 247 248 249 /** 250 * Get the type alias for the history table 251 * 252 * @return string The alias as described above 253 * 254 * @since 4.0.0 255 */ 256 public function getTypeAlias() 257 { 258 return $this->typeAlias; 259 } 260 }
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 |