- md5
- 989b10fd3aa70b38af848c71b720f7f2
- sha1
- b9368db37d8a2ae4b24cb2be23f14ee567cad4e9
- sha256
- 03303b31ce4aa9078f9341bb2d2011f70b4b29ff5542faeb8ebd9ace09392dbe
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
<?php
/**
* @package Joomla.Administrator
* @subpackage com_contact
*
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Contact\Administrator\Table;
defined('_JEXEC') or die;
use Joomla\CMS\Application\ApplicationHelper;
use Joomla\CMS\Table\Table;
use Joomla\Registry\Registry;
use Joomla\String\StringHelper;
/**
* Contact Table class.
*
* @since 1.0
*/
class ContactTable extends Table
{
/**
* Ensure the params and metadata in json encoded in the bind method
*
* @var array
* @since 3.3
*/
protected $_jsonEncode = array('params', 'metadata');
/**
* Constructor
*
* @param \JDatabaseDriver $db Database connector object
*
* @since 1.0
*/
public function __construct(\JDatabaseDriver $db)
{
$this->typeAlias = 'com_contact.contact';
parent::__construct('#__contact_details', 'id', $db);
}
/**
* 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($this->params);
$this->params = (string) $registry;
}
$date = \JFactory::getDate()->toSql();
$userId = \JFactory::getUser()->id;
if ($this->id)
{
// Existing item
$this->modified_by = $userId;
$this->modified = $date;
}
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;
}
if (empty($this->created_by))
{
$this->created_by = $userId;
}
}
// 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 = Table::getInstance('ContactTable', __NAMESPACE__ . '\\');
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()
{
try
{
parent::check();
}
catch (\Exception $e)
{
$this->setError($e->getMessage());
return false;
}
$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.
$badCharacters = array("\n", "\r", "\"", '<', '>');
// Remove bad characters.
$afterClean = StringHelper::str_ireplace($badCharacters, '', $this->metakey);
// Create array using commas as delimiter.
$keys = explode(',', $afterClean);
$cleanKeys = array();
foreach ($keys as $key)
{
// Ignore blank keywords.
if (trim($key))
{
$cleanKeys[] = trim($key);
}
}
// Put array back together delimited by ", "
$this->metakey = implode(', ', $cleanKeys);
}
else
{
$this->metakey = '';
}
// Clean up description -- eliminate quotes and <> brackets
if (!empty($this->metadesc))
{
// Only process if not empty
$badCharacters = array("\"", '<', '>');
$this->metadesc = StringHelper::str_ireplace($badCharacters, '', $this->metadesc);
}
else
{
$this->metadesc = '';
}
if (empty($this->params))
{
$this->params = '{}';
}
if (empty($this->metadata))
{
$this->metadata = '{}';
}
if (empty($this->modified))
{
$this->modified = $this->getDbo()->getNullDate();
}
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 = ApplicationHelper::stringURLSafe($this->alias, $this->language);
if (trim(str_replace('-', '', $this->alias)) == '')
{
$this->alias = \JFactory::getDate()->format('Y-m-d-H-i-s');
}
return $this->alias;
}
}
No other release has this exact content. See every version of this file.