- md5
- 7145aba05738b12bdcaec9738c0354b3
- sha1
- 684a255927d82e7778e27293a905195c4ae32ae5
- sha256
- 13a60b9dcb2a742addb110029cf4c95422f08760fc75e0b711562c3f2e1f8ece
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
<?php
/**
* @package Joomla.Administrator
* @subpackage com_contact
*
* @copyright (C) 2005 Open Source Matters, Inc. <https://www.joomla.org>
* @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\Factory;
use Joomla\CMS\Filter\InputFilter;
use Joomla\CMS\Language\Text;
use Joomla\CMS\String\PunycodeHelper;
use Joomla\CMS\Table\Table;
use Joomla\CMS\Tag\TaggableTableInterface;
use Joomla\CMS\Tag\TaggableTableTrait;
use Joomla\CMS\Versioning\VersionableTableInterface;
use Joomla\Database\DatabaseDriver;
use Joomla\String\StringHelper;
/**
* Contact Table class.
*
* @since 1.0
*/
class ContactTable extends Table implements VersionableTableInterface, TaggableTableInterface
{
use TaggableTableTrait;
/**
* Indicates that columns fully support the NULL value in the database
*
* @var boolean
* @since 4.0.0
*/
protected $_supportNullValue = true;
/**
* Ensure the params and metadata in json encoded in the bind method
*
* @var array
* @since 3.3
*/
protected $_jsonEncode = array('params', 'metadata');
/**
* Constructor
*
* @param DatabaseDriver $db Database connector object
*
* @since 1.0
*/
public function __construct(DatabaseDriver $db)
{
$this->typeAlias = 'com_contact.contact';
parent::__construct('#__contact_details', 'id', $db);
$this->setColumnAlias('title', 'name');
}
/**
* 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 = true)
{
$date = Factory::getDate()->toSql();
$userId = Factory::getUser()->id;
// Set created date if not set.
if (!(int) $this->created)
{
$this->created = $date;
}
if ($this->id)
{
// Existing item
$this->modified_by = $userId;
$this->modified = $date;
}
else
{
// Field created_by field can be set by the user, so we don't touch it if it's set.
if (empty($this->created_by))
{
$this->created_by = $userId;
}
if (!(int) $this->modified)
{
$this->modified = $date;
}
if (empty($this->modified_by))
{
$this->modified_by = $userId;
}
}
// Store utf8 email as punycode
$this->email_to = PunycodeHelper::emailToPunycode($this->email_to);
// Convert IDN urls to punycode
$this->webpage = PunycodeHelper::urlToPunycode($this->webpage);
// Verify that the alias is unique
$table = Table::getInstance('ContactTable', __NAMESPACE__ . '\\', array('dbo' => $this->getDbo()));
if ($table->load(array('alias' => $this->alias, 'catid' => $this->catid)) && ($table->id != $this->id || $this->id == 0))
{
$this->setError(Text::_('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 (InputFilter::checkAttribute(array('href', $this->webpage)))
{
$this->setError(Text::_('COM_CONTACT_WARNING_PROVIDE_VALID_URL'));
return false;
}
// Check for valid name
if (trim($this->name) == '')
{
$this->setError(Text::_('COM_CONTACT_WARNING_PROVIDE_VALID_NAME'));
return false;
}
// Generate a valid alias
$this->generateAlias();
// Check for a valid category.
if (!$this->catid = (int) $this->catid)
{
$this->setError(Text::_('JLIB_DATABASE_ERROR_CATEGORY_REQUIRED'));
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(Text::_('JGLOBAL_START_PUBLISH_AFTER_FINISH'));
return false;
}
if (!$this->id)
{
// Hits must be zero on a new item
$this->hits = 0;
}
// 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 = '{}';
}
// Set publish_up, publish_down to null if not set
if (!$this->publish_up)
{
$this->publish_up = null;
}
if (!$this->publish_down)
{
$this->publish_down = null;
}
if (!$this->modified)
{
$this->modified = $this->created;
}
if (empty($this->modified_by))
{
$this->modified_by = $this->created_by;
}
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 = Factory::getDate()->format('Y-m-d-H-i-s');
}
return $this->alias;
}
/**
* Get the type alias for the history table
*
* @return string The alias as described above
*
* @since 4.0.0
*/
public function getTypeAlias()
{
return $this->typeAlias;
}
}
The same content is in 25 releases, Joomla 4.0.6-rc1 to 4.2.0-beta1. See them all, or every version of this file.