/
link.php
109 lines (95 loc) · 2.11 KB
/
link.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
/**
* @package Joomla.Administrator
* @subpackage com_redirect
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
/**
* Link Table for Redirect.
*
* @package Joomla.Administrator
* @subpackage com_redirect
* @since 1.6
*/
class RedirectTableLink extends JTable
{
/**
* Constructor
*
* @param object Database object
*
* @return void
* @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($this->old_url);
$this->new_url = trim($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 valid name.
if (empty($this->new_url))
{
$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 = 'SELECT id FROM #__redirect_links WHERE old_url ='.$db->Quote($this->old_url);
$db->setQuery($query);
$xid = (int) $db->loadResult();
if ($xid && $xid != (int) $this->id)
{
$this->setError(JText::_('COM_REDIRECT_ERROR_DUPLICATE_OLD_URL'));
return false;
}
return true;
}
/**
* Overriden store method to set dates.
*
* @param boolean True to update fields even if they are null.
*
* @return boolean True on success.
* @see JTable::store
* @since 1.6
*/
public function store($updateNulls = false)
{
$date = JFactory::getDate()->toSql();
if ($this->id)
{
// Existing item
$this->modified_date = $date;
}
else
{
// New record.
$this->created_date = $date;
}
return parent::store($updateNulls);
}
}