[ 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_redirect 6 * 7 * @copyright (C) 2009 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\Redirect\Administrator\Table; 12 13 use Joomla\CMS\Component\ComponentHelper; 14 use Joomla\CMS\Factory; 15 use Joomla\CMS\Language\Text; 16 use Joomla\CMS\Table\Table; 17 use Joomla\Database\DatabaseDriver; 18 19 // phpcs:disable PSR1.Files.SideEffects 20 \defined('_JEXEC') or die; 21 // phpcs:enable PSR1.Files.SideEffects 22 23 /** 24 * Link Table for Redirect. 25 * 26 * @since 1.6 27 */ 28 class LinkTable extends Table 29 { 30 /** 31 * Constructor 32 * 33 * @param DatabaseDriver $db Database object. 34 * 35 * @since 1.6 36 */ 37 public function __construct(DatabaseDriver $db) 38 { 39 parent::__construct('#__redirect_links', 'id', $db); 40 } 41 42 /** 43 * Overloaded check function 44 * 45 * @return boolean 46 * 47 * @since 1.6 48 */ 49 public function check() 50 { 51 try { 52 parent::check(); 53 } catch (\Exception $e) { 54 $this->setError($e->getMessage()); 55 56 return false; 57 } 58 59 $this->old_url = trim(rawurldecode($this->old_url)); 60 $this->new_url = trim(rawurldecode($this->new_url)); 61 62 // Check for valid name. 63 if (empty($this->old_url)) { 64 $this->setError(Text::_('COM_REDIRECT_ERROR_SOURCE_URL_REQUIRED')); 65 66 return false; 67 } 68 69 // Check for NOT NULL. 70 if (empty($this->referer)) { 71 $this->referer = ''; 72 } 73 74 // Check for valid name if not in advanced mode. 75 if (empty($this->new_url) && ComponentHelper::getParams('com_redirect')->get('mode', 0) == false) { 76 $this->setError(Text::_('COM_REDIRECT_ERROR_DESTINATION_URL_REQUIRED')); 77 78 return false; 79 } elseif (empty($this->new_url) && ComponentHelper::getParams('com_redirect')->get('mode', 0) == true) { 80 // Else if an empty URL and in redirect mode only throw the same error if the code is a 3xx status code 81 if ($this->header < 400 && $this->header >= 300) { 82 $this->setError(Text::_('COM_REDIRECT_ERROR_DESTINATION_URL_REQUIRED')); 83 84 return false; 85 } 86 } 87 88 // Check for duplicates 89 if ($this->old_url == $this->new_url) { 90 $this->setError(Text::_('COM_REDIRECT_ERROR_DUPLICATE_URLS')); 91 92 return false; 93 } 94 95 $db = $this->getDbo(); 96 97 // Check for existing name 98 $query = $db->getQuery(true) 99 ->select($db->quoteName('id')) 100 ->select($db->quoteName('old_url')) 101 ->from($db->quoteName('#__redirect_links')) 102 ->where($db->quoteName('old_url') . ' = :url') 103 ->bind(':url', $this->old_url); 104 $db->setQuery($query); 105 $urls = $db->loadAssocList(); 106 107 foreach ($urls as $url) { 108 if ($url['old_url'] === $this->old_url && (int) $url['id'] != (int) $this->id) { 109 $this->setError(Text::_('COM_REDIRECT_ERROR_DUPLICATE_OLD_URL')); 110 111 return false; 112 } 113 } 114 115 return true; 116 } 117 118 /** 119 * Overridden store method to set dates. 120 * 121 * @param boolean $updateNulls True to update fields even if they are null. 122 * 123 * @return boolean True on success. 124 * 125 * @since 1.6 126 */ 127 public function store($updateNulls = false) 128 { 129 $date = Factory::getDate()->toSql(); 130 131 if (!$this->id) { 132 // New record. 133 $this->created_date = $date; 134 $this->modified_date = $date; 135 } 136 137 if (empty($this->modified_date)) { 138 $this->modified_date = $this->created_date; 139 } 140 141 return parent::store($updateNulls); 142 } 143 }
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 |