|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package Com_Localise |
|
4
|
|
|
* @subpackage tables |
|
5
|
|
|
* |
|
6
|
|
|
* @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved. |
|
7
|
|
|
* @license GNU General Public License version 2 or later; see LICENSE.txt |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
defined('_JEXEC') or die; |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Localise Table class for the Localise Component |
|
15
|
|
|
* |
|
16
|
|
|
* @package Extensions.Components |
|
17
|
|
|
* @subpackage Localise |
|
18
|
|
|
* |
|
19
|
|
|
* @since 1.0 |
|
20
|
|
|
*/ |
|
21
|
|
|
class LocaliseTableLocalise extends JTable |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* Primary Key |
|
25
|
|
|
* |
|
26
|
|
|
* @var int |
|
27
|
|
|
*/ |
|
28
|
|
|
public $id = null; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* The title to use for the asset table |
|
32
|
|
|
* |
|
33
|
|
|
* @var string |
|
34
|
|
|
*/ |
|
35
|
|
|
public $path = null; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Checked out status |
|
39
|
|
|
* |
|
40
|
|
|
* @var int |
|
41
|
|
|
*/ |
|
42
|
|
|
public $checked_out = null; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Checkout out time |
|
46
|
|
|
* |
|
47
|
|
|
* @var date |
|
48
|
|
|
*/ |
|
49
|
|
|
public $checked_out_time = null; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* The asset ID |
|
53
|
|
|
* |
|
54
|
|
|
* @var asset_id |
|
55
|
|
|
*/ |
|
56
|
|
|
public $asset_id = null; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Constructor |
|
60
|
|
|
* |
|
61
|
|
|
* @param object &$db Database connector object |
|
62
|
|
|
*/ |
|
63
|
|
|
public function __construct(&$db) |
|
64
|
|
|
{ |
|
65
|
|
|
parent::__construct('#__localise', 'id', $db); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Method to compute the default name of the asset. |
|
70
|
|
|
* The default name is in the form `table_name.id` |
|
71
|
|
|
* where id is the value of the primary key of the table. |
|
72
|
|
|
* |
|
73
|
|
|
* @return string |
|
74
|
|
|
*/ |
|
75
|
|
|
protected function _getAssetName() |
|
76
|
|
|
{ |
|
77
|
|
|
$k = $this->_tbl_key; |
|
78
|
|
|
|
|
79
|
|
|
return 'com_localise.' . (int) $this->$k; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Method to return the title to use for the asset table. |
|
84
|
|
|
* |
|
85
|
|
|
* @return string |
|
86
|
|
|
* |
|
87
|
|
|
* @since 1.6 |
|
88
|
|
|
*/ |
|
89
|
|
|
protected function _getAssetTitle() |
|
90
|
|
|
{ |
|
91
|
|
|
return basename($this->path); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Get the parent asset id for the record |
|
96
|
|
|
* |
|
97
|
|
|
* @param JTable $table JTable Table object |
|
98
|
|
|
* @param Integer $id Primart key of table |
|
99
|
|
|
* |
|
100
|
|
|
* @return Integer Parent asset id for the record |
|
101
|
|
|
*/ |
|
102
|
|
|
protected function _getAssetParentId(JTable $table = null, $id = null) |
|
103
|
|
|
{ |
|
104
|
|
|
// Initialise variables. |
|
105
|
|
|
$db = $this->getDbo(); |
|
|
|
|
|
|
106
|
|
|
|
|
107
|
|
|
// Build the query to get the asset id for the parent category. |
|
108
|
|
|
$asset = JTable::getInstance('asset'); |
|
109
|
|
|
$name = basename($this->path); |
|
110
|
|
|
$relativePath = substr($this->path, strlen(JPATH_ROOT)); |
|
111
|
|
|
|
|
112
|
|
|
if (preg_match('/^([^.]*)\..*\.ini$/', $name, $matches) || preg_match('/^([^.]*)\.ini$/', $name, $matches)) |
|
113
|
|
|
{ |
|
114
|
|
|
$params = JComponentHelper::getParams('com_localise'); |
|
115
|
|
|
$installation_folder = $params->get('installation', 'installation'); |
|
116
|
|
|
$tag = $matches[1]; |
|
117
|
|
|
|
|
118
|
|
|
if (preg_match('#^/(administrator|plugins)#', $relativePath)) |
|
119
|
|
|
{ |
|
120
|
|
|
$id = LocaliseHelper::getFileId(JPATH_ROOT . "/administrator/language/$tag/$tag.xml"); |
|
121
|
|
|
} |
|
122
|
|
|
elseif (preg_match('#^/' . $installation_folder . '#', $relativePath)) |
|
123
|
|
|
{ |
|
124
|
|
|
$id = LocaliseHelper::getFileId(LOCALISEPATH_INSTALLATION . "/language/$tag/$tag.xml"); |
|
125
|
|
|
} |
|
126
|
|
|
else |
|
127
|
|
|
{ |
|
128
|
|
|
$id = LocaliseHelper::getFileId(JPATH_ROOT . "/language/$tag/$tag.xml"); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
$assetName = "com_localise.$id"; |
|
132
|
|
|
|
|
133
|
|
|
if (!$asset->loadByName($assetName)) |
|
134
|
|
|
{ |
|
135
|
|
|
$component = JTable::getInstance('asset'); |
|
136
|
|
|
|
|
137
|
|
View Code Duplication |
if (!$component->loadByName('com_localise')) |
|
|
|
|
|
|
138
|
|
|
{ |
|
139
|
|
|
$root = JTable::getInstance('asset'); |
|
140
|
|
|
$root->rebuild(); |
|
141
|
|
|
$root->loadByName('root.1'); |
|
142
|
|
|
$component->name = 'com_localise'; |
|
143
|
|
|
$component->title = 'com_localise'; |
|
144
|
|
|
$component->setLocation($root->id, 'last-child'); |
|
145
|
|
|
|
|
146
|
|
|
if (!$component->check() || !$component->store()) |
|
147
|
|
|
{ |
|
148
|
|
|
$this->setError($component->getError()); |
|
149
|
|
|
|
|
150
|
|
|
return false; |
|
|
|
|
|
|
151
|
|
|
} |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
$asset->name = "com_localise.$id"; |
|
155
|
|
|
$asset->title = $name; |
|
156
|
|
|
$asset->setLocation($component->id, 'last-child'); |
|
157
|
|
|
|
|
158
|
|
|
if (!$asset->check() || !$asset->store()) |
|
159
|
|
|
{ |
|
160
|
|
|
$this->setError($asset->getError()); |
|
161
|
|
|
|
|
162
|
|
|
return false; |
|
|
|
|
|
|
163
|
|
|
} |
|
164
|
|
|
} |
|
165
|
|
|
} |
|
166
|
|
View Code Duplication |
else |
|
|
|
|
|
|
167
|
|
|
{ |
|
168
|
|
|
if (!$asset->loadByName('com_localise')) |
|
169
|
|
|
{ |
|
170
|
|
|
$root = JTable::getInstance('asset'); |
|
171
|
|
|
$root->loadByName('root.1'); |
|
172
|
|
|
$asset->name = 'com_localise'; |
|
173
|
|
|
$asset->title = 'com_localise'; |
|
174
|
|
|
$asset->setLocation($root->id, 'last-child'); |
|
175
|
|
|
|
|
176
|
|
|
if (!$asset->check() || !$asset->store()) |
|
177
|
|
|
{ |
|
178
|
|
|
$this->setError($asset->getError()); |
|
179
|
|
|
|
|
180
|
|
|
return false; |
|
|
|
|
|
|
181
|
|
|
} |
|
182
|
|
|
} |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
return $asset->id; |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* Method to delete a row from the database table by primary key value. |
|
190
|
|
|
* |
|
191
|
|
|
* @param mixed $pk An optional primary key value to delete. If not set the instance property value is used. |
|
192
|
|
|
* |
|
193
|
|
|
* @return boolean True on success. |
|
194
|
|
|
* |
|
195
|
|
|
* @link http://docs.joomla.org/JTable/delete |
|
196
|
|
|
* @since 11.1 |
|
197
|
|
|
* @throws UnexpectedValueException |
|
198
|
|
|
*/ |
|
199
|
|
|
public function delete($pk = null) |
|
200
|
|
|
{ |
|
201
|
|
|
if (!$this->deleteLanguageTranslations()) |
|
202
|
|
|
{ |
|
203
|
|
|
return false; |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
return parent::delete($pk); |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
/** |
|
210
|
|
|
* Delete language translations |
|
211
|
|
|
* |
|
212
|
|
|
* @return boolean |
|
213
|
|
|
*/ |
|
214
|
|
|
protected function deleteLanguageTranslations() |
|
215
|
|
|
{ |
|
216
|
|
|
$fileName = basename($this->path); |
|
217
|
|
|
$fileInfo = pathinfo($fileName); |
|
218
|
|
|
$extension = isset($fileInfo['extension']) ? $fileInfo['extension'] : null; |
|
219
|
|
|
$langTag = $fileInfo['filename']; |
|
220
|
|
|
|
|
221
|
|
|
// Make sure we are deleting a base language. Otherwise avoid to delete |
|
222
|
|
|
if ($extension != 'xml') |
|
223
|
|
|
{ |
|
224
|
|
|
return true; |
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
|
|
if ($langTag) |
|
228
|
|
|
{ |
|
229
|
|
|
$db = $this->getDbo(); |
|
230
|
|
|
|
|
231
|
|
|
$searchTag = $db->quote('%' . $db->escape($langTag, true) . '%'); |
|
232
|
|
|
|
|
233
|
|
|
$query = $db->getQuery(true) |
|
234
|
|
|
->delete('#__localise') |
|
235
|
|
|
->where('path LIKE ' . $searchTag); |
|
236
|
|
|
|
|
237
|
|
|
$db->setQuery($query); |
|
238
|
|
|
|
|
239
|
|
|
if (!$db->execute()) |
|
240
|
|
|
{ |
|
241
|
|
|
$this->setError('COM_LOCALISE_ERROR_DELETING_DB_TRANSLATIONS'); |
|
242
|
|
|
|
|
243
|
|
|
return false; |
|
244
|
|
|
} |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
return true; |
|
248
|
|
|
} |
|
249
|
|
|
} |
|
250
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.