'com_contact.contact')); JTableObserverContenthistory::createObserver($this, array('typeAlias' => 'com_contact.contact')); } /** * Stores a contact. * * @param boolean $updateNulls True to update fields even if they are null. * * @return boolean True on success, false on failure. * * @since 1.6 */ public function store($updateNulls = false) { // Transform the params field if (is_array($this->params)) { $registry = new Registry; $registry->loadArray($this->params); $this->params = (string) $registry; } $date = JFactory::getDate(); $user = JFactory::getUser(); $this->modified = $date->toSql(); if ($this->id) { // Existing item $this->modified_by = $user->get('id'); } else { // New contact. A contact created and created_by field can be set by the user, // so we don't touch either of these if they are set. if (!(int) $this->created) { $this->created = $date->toSql(); } if (empty($this->created_by)) { $this->created_by = $user->get('id'); } } // Set publish_up to null date if not set if (!$this->publish_up) { $this->publish_up = $this->_db->getNullDate(); } // Set publish_down to null date if not set if (!$this->publish_down) { $this->publish_down = $this->_db->getNullDate(); } // Set xreference to empty string if not set if (!$this->xreference) { $this->xreference = ''; } // Store utf8 email as punycode $this->email_to = JStringPunycode::emailToPunycode($this->email_to); // Convert IDN urls to punycode $this->webpage = JStringPunycode::urlToPunycode($this->webpage); // Verify that the alias is unique $table = JTable::getInstance('Contact', 'ContactTable'); if ($table->load(array('alias' => $this->alias, 'catid' => $this->catid)) && ($table->id != $this->id || $this->id == 0)) { $this->setError(JText::_('COM_CONTACT_ERROR_UNIQUE_ALIAS')); return false; } return parent::store($updateNulls); } /** * Overloaded check function * * @return boolean True on success, false on failure * * @see JTable::check * @since 1.5 */ public function check() { $this->default_con = (int) $this->default_con; if (JFilterInput::checkAttribute(array ('href', $this->webpage))) { $this->setError(JText::_('COM_CONTACT_WARNING_PROVIDE_VALID_URL')); return false; } /** check for valid name */ if (trim($this->name) == '') { $this->setError(JText::_('COM_CONTACT_WARNING_PROVIDE_VALID_NAME')); return false; } // Generate a valid alias $this->generateAlias(); /** check for valid category */ if (trim($this->catid) == '') { $this->setError(JText::_('COM_CONTACT_WARNING_CATEGORY')); return false; } /** sanity check for user_id */ if (!($this->user_id)) { $this->user_id = 0; } // Check the publish down date is not earlier than publish up. if ((int) $this->publish_down > 0 && $this->publish_down < $this->publish_up) { $this->setError(JText::_('JGLOBAL_START_PUBLISH_AFTER_FINISH')); return false; } /* * Clean up keywords -- eliminate extra spaces between phrases * and cr (\r) and lf (\n) characters from string. * Only process if not empty. */ if (!empty($this->metakey)) { // Array of characters to remove. $bad_characters = array("\n", "\r", "\"", "<", ">"); // Remove bad characters. $after_clean = JString::str_ireplace($bad_characters, "", $this->metakey); // Create array using commas as delimiter. $keys = explode(',', $after_clean); $clean_keys = array(); foreach ($keys as $key) { // Ignore blank keywords. if (trim($key)) { $clean_keys[] = trim($key); } } // Put array back together delimited by ", " $this->metakey = implode(", ", $clean_keys); } // Clean up description -- eliminate quotes and <> brackets if (!empty($this->metadesc)) { // Only process if not empty $bad_characters = array("\"", "<", ">"); $this->metadesc = JString::str_ireplace($bad_characters, "", $this->metadesc); } return true; } /** * Generate a valid alias from title / date. * Remains public to be able to check for duplicated alias before saving * * @return string */ public function generateAlias() { if (empty($this->alias)) { $this->alias = $this->name; } $this->alias = JApplication::stringURLSafe($this->alias); if (trim(str_replace('-', '', $this->alias)) == '') { $this->alias = JFactory::getDate()->format("Y-m-d-H-i-s"); } return $this->alias; } }