Server : LiteSpeed System : Linux server 3.10.0-1160.90.1.el7.x86_64 #1 SMP Thu May 4 15:21:22 UTC 2023 x86_64 User : alsaif ( 1057) PHP Version : 7.4.33 Disable Function : show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/alsaif/domains/alsaif.group/public_html/administrator/components/com_redirect/tables/ |
<?php
/**
* @package Joomla.Administrator
* @subpackage com_redirect
*
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
/**
* Link Table for Redirect.
*
* @since 1.6
*/
class RedirectTableLink extends JTable
{
/**
* Constructor
*
* @param JDatabaseDriver $db Database object.
*
* @since 1.6
*/
public function __construct($db)
{
parent::__construct('#__redirect_links', 'id', $db);
}
/**
* Overloaded check function
*
* @return boolean
*
* @since 1.6
*/
public function check()
{
$this->old_url = trim(rawurldecode($this->old_url));
$this->new_url = trim(rawurldecode($this->new_url));
// Check for valid name.
if (empty($this->old_url))
{
$this->setError(JText::_('COM_REDIRECT_ERROR_SOURCE_URL_REQUIRED'));
return false;
}
// Check for NOT NULL.
if (empty($this->referer))
{
$this->referer = '';
}
// Check for valid name if not in advanced mode.
if (empty($this->new_url) && JComponentHelper::getParams('com_redirect')->get('mode', 0) == false)
{
$this->setError(JText::_('COM_REDIRECT_ERROR_DESTINATION_URL_REQUIRED'));
return false;
}
elseif (empty($this->new_url) && JComponentHelper::getParams('com_redirect')->get('mode', 0) == true)
{
// Else if an empty URL and in redirect mode only throw the same error if the code is a 3xx status code
if ($this->header < 400 && $this->header >= 300)
{
$this->setError(JText::_('COM_REDIRECT_ERROR_DESTINATION_URL_REQUIRED'));
return false;
}
}
// Check for duplicates
if ($this->old_url == $this->new_url)
{
$this->setError(JText::_('COM_REDIRECT_ERROR_DUPLICATE_URLS'));
return false;
}
$db = $this->getDbo();
// Check for existing name
$query = $db->getQuery(true)
->select($db->quoteName('id'))
->select($db->quoteName('old_url'))
->from('#__redirect_links')
->where($db->quoteName('old_url') . ' = ' . $db->quote($this->old_url));
$db->setQuery($query);
$urls = $db->loadAssocList();
foreach ($urls as $url)
{
if ($url['old_url'] === $this->old_url && (int) $url['id'] != (int) $this->id)
{
$this->setError(JText::_('COM_REDIRECT_ERROR_DUPLICATE_OLD_URL'));
return false;
}
}
return true;
}
/**
* Overriden store method to set dates.
*
* @param boolean $updateNulls True to update fields even if they are null.
*
* @return boolean True on success.
*
* @since 1.6
*/
public function store($updateNulls = false)
{
$date = JFactory::getDate()->toSql();
$this->modified_date = $date;
if (!$this->id)
{
// New record.
$this->created_date = $date;
}
return parent::store($updateNulls);
}
}