Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 557 lines (477 sloc) 16.694 kB
f73b659 Imported the new trunk.
Rob Schley authored
1 <?php
2 /**
89e3d3a @LouisLandry Fixed up file headers.
LouisLandry authored
3 * @package Joomla.Platform
4 * @subpackage Installer
0a72863 @LouisLandry Fixing file headers for both unit test and library files.
LouisLandry authored
5 *
6 * @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE
f73b659 Imported the new trunk.
Rob Schley authored
8 */
9
fc5a10c @realityking Unify the style of the JPATH_PLATFORM check.
realityking authored
10 defined('JPATH_PLATFORM') or die;
eefdefd @eddieajau Code formatting.
eddieajau authored
11
78828a1 @pasamio Updates to installer subsystem
pasamio authored
12 jimport('joomla.installer.extension');
13 jimport('joomla.base.adapterinstance');
f73b659 Imported the new trunk.
Rob Schley authored
14
15 /**
16 * Template installer
17 *
53daea8 @eddieajau Code cleaning.
eddieajau authored
18 * @package Joomla.Platform
19 * @subpackage Installer
20 * @since 11.1
f73b659 Imported the new trunk.
Rob Schley authored
21 */
78828a1 @pasamio Updates to installer subsystem
pasamio authored
22 class JInstallerTemplate extends JAdapterInstance
f73b659 Imported the new trunk.
Rob Schley authored
23 {
78828a1 @pasamio Updates to installer subsystem
pasamio authored
24 protected $name = null;
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
25
78828a1 @pasamio Updates to installer subsystem
pasamio authored
26 protected $element = null;
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
27
d5b0bdf @dextercowley [#22957] Upgrading a template that uses method="upgrade" removes manu…
dextercowley authored
28 protected $route = 'install';
f73b659 Imported the new trunk.
Rob Schley authored
29
30 /**
34b5d64 @chdemko Changing the way languages are loaded at install and update phase
chdemko authored
31 * Custom loadLanguage method
32 *
a820fcd @eddieajau Code cleaning.
eddieajau authored
33 * @param string $path The path where to find language files.
34 *
35 * @return JInstallerTemplate
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
36 *
53daea8 @eddieajau Code cleaning.
eddieajau authored
37 * @since 11.1
34b5d64 @chdemko Changing the way languages are loaded at install and update phase
chdemko authored
38 */
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
39 public function loadLanguage($path = null)
34b5d64 @chdemko Changing the way languages are loaded at install and update phase
chdemko authored
40 {
fcbb17a @chdemko Merging the admintranslate branch back to the trunk
chdemko authored
41 $source = $this->parent->getPath('source');
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
42
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
43 if (!$source)
44 {
a820fcd @eddieajau Code cleaning.
eddieajau authored
45 $this->parent
46 ->setPath(
54509a7 @realityking Use an autoformatter for the indentation.
realityking authored
47 'source',
48 ($this->parent->extension->client_id ? JPATH_ADMINISTRATOR : JPATH_SITE) . '/templates/' . $this->parent->extension->element
49 );
fcbb17a @chdemko Merging the admintranslate branch back to the trunk
chdemko authored
50 }
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
51
d5b0bdf @dextercowley [#22957] Upgrading a template that uses method="upgrade" removes manu…
dextercowley authored
52 $clientId = isset($this->parent->extension) ? $this->parent->extension->client_id : 0;
aa5891a @eddieajau Fixed issue [#20907] Making Joomla more compliant to PHP strict standard
eddieajau authored
53 $this->manifest = $this->parent->getManifest();
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
54 $name = strtolower(JFilterInput::getInstance()->clean((string) $this->manifest->name, 'cmd'));
55 $client = (string) $this->manifest->attributes()->client;
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
56
c2a4952 @pasamio # Applied [#20263] E_WARNING Error in JInstallerTemplate::loadLanguag…
pasamio authored
57 // Load administrator language if not set.
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
58 if (!$client)
59 {
c2a4952 @pasamio # Applied [#20263] E_WARNING Error in JInstallerTemplate::loadLanguag…
pasamio authored
60 $client = 'ADMINISTRATOR';
61 }
62
34b5d64 @chdemko Changing the way languages are loaded at install and update phase
chdemko authored
63 $extension = "tpl_$name";
aa5891a @eddieajau Fixed issue [#20907] Making Joomla more compliant to PHP strict standard
eddieajau authored
64 $lang = JFactory::getLanguage();
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
65 $source = $path ? $path : ($this->parent->extension->client_id ? JPATH_ADMINISTRATOR : JPATH_SITE) . '/templates/' . $name;
a820fcd @eddieajau Code cleaning.
eddieajau authored
66 $lang->load($extension . '.sys', $source, null, false, false)
67 || $lang->load($extension . '.sys', constant('JPATH_' . strtoupper($client)), null, false, false)
68 || $lang->load($extension . '.sys', $source, $lang->getDefault(), false, false)
69 || $lang->load($extension . '.sys', constant('JPATH_' . strtoupper($client)), $lang->getDefault(), false, false);
34b5d64 @chdemko Changing the way languages are loaded at install and update phase
chdemko authored
70 }
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
71
34b5d64 @chdemko Changing the way languages are loaded at install and update phase
chdemko authored
72 /**
f73b659 Imported the new trunk.
Rob Schley authored
73 * Custom install method
74 *
53daea8 @eddieajau Code cleaning.
eddieajau authored
75 * @return boolean True on success
ccb71ca @LouisLandry Code cleaning.
LouisLandry authored
76 *
53daea8 @eddieajau Code cleaning.
eddieajau authored
77 * @since 11.1
f73b659 Imported the new trunk.
Rob Schley authored
78 */
78828a1 @pasamio Updates to installer subsystem
pasamio authored
79 public function install()
f73b659 Imported the new trunk.
Rob Schley authored
80 {
a028a77 @chdemko $ Storing the default style name without ** when language debug is on…
chdemko authored
81 $lang = JFactory::getLanguage();
9d3bd0a @Hackwar ^ Using PHPs built in SimpleXML instead of JSimpleXML to read XML fil…
Hackwar authored
82 $xml = $this->parent->getManifest();
f73b659 Imported the new trunk.
Rob Schley authored
83
84 // Get the client application target
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
85 if ($cname = (string) $xml->attributes()->client)
86 {
f73b659 Imported the new trunk.
Rob Schley authored
87 // Attempt to map the client to a base path
88 jimport('joomla.application.helper');
aa5891a @eddieajau Fixed issue [#20907] Making Joomla more compliant to PHP strict standard
eddieajau authored
89 $client = JApplicationHelper::getClientInfo($cname, true);
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
90 if ($client === false)
91 {
6f82ea6 $ Refactoring ini/keys in libraries/J/Installer/template + helper
Jean-Marie Simonet authored
92 $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT_TPL_INSTALL_UNKNOWN_CLIENT', $cname));
f73b659 Imported the new trunk.
Rob Schley authored
93 return false;
94 }
95 $basePath = $client->path;
96 $clientId = $client->id;
eefdefd @eddieajau Code formatting.
eddieajau authored
97 }
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
98 else
99 {
f73b659 Imported the new trunk.
Rob Schley authored
100 // No client attribute was found so we assume the site as the client
101 $cname = 'site';
102 $basePath = JPATH_SITE;
103 $clientId = 0;
104 }
105
703224e @elinw installer
elinw authored
106 // Set the extension's name
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
107 $name = JFilterInput::getInstance()->clean((string) $xml->name, 'cmd');
eefdefd @eddieajau Code formatting.
eddieajau authored
108
78828a1 @pasamio Updates to installer subsystem
pasamio authored
109 $element = strtolower(str_replace(" ", "_", $name));
f73b659 Imported the new trunk.
Rob Schley authored
110 $this->set('name', $name);
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
111 $this->set('element', $element);
eefdefd @eddieajau Code formatting.
eddieajau authored
112
aa5891a @eddieajau Fixed issue [#20907] Making Joomla more compliant to PHP strict standard
eddieajau authored
113 $db = $this->parent->getDbo();
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
114 $db->setQuery('SELECT extension_id FROM #__extensions WHERE type="template" AND element = "' . $element . '"');
d5b0bdf @dextercowley [#22957] Upgrading a template that uses method="upgrade" removes manu…
dextercowley authored
115 $id = $db->loadResult();
89e3d3a @LouisLandry Fixed up file headers.
LouisLandry authored
116
d5b0bdf @dextercowley [#22957] Upgrading a template that uses method="upgrade" removes manu…
dextercowley authored
117 // Set the template root path
a5a8f75 @eddieajau Merging uncaught changes from Joomla SVN trunk.
eddieajau authored
118 $this->parent->setPath('extension_root', $basePath . '/templates/' . $element);
d5b0bdf @dextercowley [#22957] Upgrading a template that uses method="upgrade" removes manu…
dextercowley authored
119
703224e @elinw installer
elinw authored
120 // if it's on the fs...
d5b0bdf @dextercowley [#22957] Upgrading a template that uses method="upgrade" removes manu…
dextercowley authored
121 if (file_exists($this->parent->getPath('extension_root')) && (!$this->parent->getOverwrite() || $this->parent->getUpgrade()))
122 {
123 $updateElement = $xml->update;
703224e @elinw installer
elinw authored
124 // Upgrade manually set or
125 // Update function available or
126 // Update tag detected
a820fcd @eddieajau Code cleaning.
eddieajau authored
127 if ($this->parent->getUpgrade() || ($this->parent->manifestClass && method_exists($this->parent->manifestClass, 'update'))
672e6a5 @elkuku Closing parenthesis of a multi-line IF statement must be on the same …
elkuku authored
128 || is_a($updateElement, 'JXMLElement'))
a820fcd @eddieajau Code cleaning.
eddieajau authored
129 {
130 // Force this one
131 $this->parent->setOverwrite(true);
132 $this->parent->setUpgrade(true);
133 if ($id)
7515b81 @realityking Fix stuff the autoformatter didn't do nicely.
realityking authored
134 {
135 // if there is a matching extension mark this as an update; semantics really
a820fcd @eddieajau Code cleaning.
eddieajau authored
136 $this->route = 'update';
d5b0bdf @dextercowley [#22957] Upgrading a template that uses method="upgrade" removes manu…
dextercowley authored
137 }
eefdefd @eddieajau Code formatting.
eddieajau authored
138 }
e972e1b @realityking Use elseif instead else if.
realityking authored
139 elseif (!$this->parent->getOverwrite())
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
140 {
a820fcd @eddieajau Code cleaning.
eddieajau authored
141 // Overwrite is not set
311faf5 @mbabker Spelling & doc block
mbabker authored
142 // If we didn't have overwrite set, find an update function or find an update tag so let's call it safe
a820fcd @eddieajau Code cleaning.
eddieajau authored
143 $this->parent
144 ->abort(
54509a7 @realityking Use an autoformatter for the indentation.
realityking authored
145 JText::sprintf(
146 'JLIB_INSTALLER_ABORT_PLG_INSTALL_DIRECTORY', JText::_('JLIB_INSTALLER_' . $this->route),
147 $this->parent->getPath('extension_root')
148 )
a820fcd @eddieajau Code cleaning.
eddieajau authored
149 );
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
150 return false;
151 }
a820fcd @eddieajau Code cleaning.
eddieajau authored
152 }
f73b659 Imported the new trunk.
Rob Schley authored
153
a820fcd @eddieajau Code cleaning.
eddieajau authored
154 /*
155 * If the template directory already exists, then we will assume that the template is already
156 * installed or another template is using that directory.
157 */
158 if (file_exists($this->parent->getPath('extension_root')) && !$this->parent->getOverwrite())
159 {
160 JError::raiseWarning(
161 100,
162 JText::sprintf('JLIB_INSTALLER_ABORT_TPL_INSTALL_ANOTHER_TEMPLATE_USING_DIRECTORY', $this->parent->getPath('extension_root'))
163 );
164 return false;
165 }
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
166
a820fcd @eddieajau Code cleaning.
eddieajau authored
167 // If the template directory does not exist, let's create it
168 $created = false;
169 if (!file_exists($this->parent->getPath('extension_root')))
170 {
171 if (!$created = JFolder::create($this->parent->getPath('extension_root')))
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
172 {
a820fcd @eddieajau Code cleaning.
eddieajau authored
173 $this->parent
174 ->abort(JText::sprintf('JLIB_INSTALLER_ABORT_TPL_INSTALL_FAILED_CREATE_DIRECTORY', $this->parent->getPath('extension_root')));
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
175
f73b659 Imported the new trunk.
Rob Schley authored
176 return false;
177 }
a820fcd @eddieajau Code cleaning.
eddieajau authored
178 }
f73b659 Imported the new trunk.
Rob Schley authored
179
a820fcd @eddieajau Code cleaning.
eddieajau authored
180 // If we created the template directory and will want to remove it if we have to roll back
181 // the installation, let's add it to the installation step stack
182 if ($created)
183 {
184 $this->parent->pushStep(array('type' => 'folder', 'path' => $this->parent->getPath('extension_root')));
185 }
f73b659 Imported the new trunk.
Rob Schley authored
186
a820fcd @eddieajau Code cleaning.
eddieajau authored
187 // Copy all the necessary files
188 if ($this->parent->parseFiles($xml->files, -1) === false)
189 {
190 // Install failed, rollback changes
191 $this->parent->abort();
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
192
a820fcd @eddieajau Code cleaning.
eddieajau authored
193 return false;
194 }
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
195
a820fcd @eddieajau Code cleaning.
eddieajau authored
196 if ($this->parent->parseFiles($xml->images, -1) === false)
197 {
198 // Install failed, rollback changes
199 $this->parent->abort();
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
200
a820fcd @eddieajau Code cleaning.
eddieajau authored
201 return false;
202 }
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
203
a820fcd @eddieajau Code cleaning.
eddieajau authored
204 if ($this->parent->parseFiles($xml->css, -1) === false)
205 {
206 // Install failed, rollback changes
207 $this->parent->abort();
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
208
a820fcd @eddieajau Code cleaning.
eddieajau authored
209 return false;
210 }
f73b659 Imported the new trunk.
Rob Schley authored
211
a820fcd @eddieajau Code cleaning.
eddieajau authored
212 // Parse optional tags
213 $this->parent->parseMedia($xml->media);
214 $this->parent->parseLanguages($xml->languages, $clientId);
f73b659 Imported the new trunk.
Rob Schley authored
215
a820fcd @eddieajau Code cleaning.
eddieajau authored
216 // Get the template description
217 $this->parent->set('message', JText::_((string) $xml->description));
f73b659 Imported the new trunk.
Rob Schley authored
218
a820fcd @eddieajau Code cleaning.
eddieajau authored
219 // Lastly, we will copy the manifest file to its appropriate place.
220 if (!$this->parent->copyManifest(-1))
221 {
222 // Install failed, rollback changes
223 $this->parent->abort(JText::_('JLIB_INSTALLER_ABORT_TPL_INSTALL_COPY_SETUP'));
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
224
a820fcd @eddieajau Code cleaning.
eddieajau authored
225 return false;
226 }
f73b659 Imported the new trunk.
Rob Schley authored
227
a820fcd @eddieajau Code cleaning.
eddieajau authored
228 // Extension Registration
703224e @elinw installer
elinw authored
229
a820fcd @eddieajau Code cleaning.
eddieajau authored
230 $row = JTable::getInstance('extension');
d5b0bdf @dextercowley [#22957] Upgrading a template that uses method="upgrade" removes manu…
dextercowley authored
231
a820fcd @eddieajau Code cleaning.
eddieajau authored
232 if ($this->route == 'update' && $id)
233 {
234 $row->load($id);
78828a1 @pasamio Updates to installer subsystem
pasamio authored
235 }
a820fcd @eddieajau Code cleaning.
eddieajau authored
236 else
d5b0bdf @dextercowley [#22957] Upgrading a template that uses method="upgrade" removes manu…
dextercowley authored
237 {
a820fcd @eddieajau Code cleaning.
eddieajau authored
238 $row->type = 'template';
239 $row->element = $this->get('element');
240 // There is no folder for templates
241 $row->folder = '';
242 $row->enabled = 1;
243 $row->protected = 0;
244 $row->access = 1;
245 $row->client_id = $clientId;
246 $row->params = $this->parent->getParams();
247 $row->custom_data = ''; // custom data
d5b0bdf @dextercowley [#22957] Upgrading a template that uses method="upgrade" removes manu…
dextercowley authored
248 }
a820fcd @eddieajau Code cleaning.
eddieajau authored
249 $row->name = $this->get('name'); // name might change in an update
250 $row->manifest_cache = $this->parent->generateManifestCache();
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
251
a820fcd @eddieajau Code cleaning.
eddieajau authored
252 if (!$row->store())
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
253 {
a820fcd @eddieajau Code cleaning.
eddieajau authored
254 // Install failed, roll back changes
255 $this->parent->abort(JText::sprintf('JLIB_INSTALLER_ABORT_TPL_INSTALL_ROLLBACK', $db->stderr(true)));
89e3d3a @LouisLandry Fixed up file headers.
LouisLandry authored
256
a820fcd @eddieajau Code cleaning.
eddieajau authored
257 return false;
258 }
f73b659 Imported the new trunk.
Rob Schley authored
259
a820fcd @eddieajau Code cleaning.
eddieajau authored
260 if ($this->route == 'install')
261 {
262 //insert record in #__template_styles
263 $query = $db->getQuery(true);
264 $query->insert('#__template_styles');
265 $query->set('template=' . $db->Quote($row->element));
266 $query->set('client_id=' . $db->Quote($clientId));
267 $query->set('home=0');
268 $debug = $lang->setDebug(false);
269 $query->set('title=' . $db->Quote(JText::sprintf('JLIB_INSTALLER_DEFAULT_STYLE', JText::_($this->get('name')))));
270 $lang->setDebug($debug);
271 $query->set('params=' . $db->Quote($row->params));
272 $db->setQuery($query);
273 // There is a chance this could fail but we don't care...
274 $db->query();
275 }
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
276
a820fcd @eddieajau Code cleaning.
eddieajau authored
277 return $row->get('extension_id');
278 }
78828a1 @pasamio Updates to installer subsystem
pasamio authored
279
a820fcd @eddieajau Code cleaning.
eddieajau authored
280 /**
281 * Custom update method for components
282 *
283 * @return boolean True on success
284 *
285 * @since 11.1
286 */
287 public function update()
288 {
289 return $this->install();
290 }
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
291
a820fcd @eddieajau Code cleaning.
eddieajau authored
292 /**
293 * Custom uninstall method
294 *
295 * @param integer $id The extension ID
296 *
297 * @return boolean True on success
298 *
299 * @since 11.1
300 */
301 public function uninstall($id)
302 {
303 // Initialise variables.
304 $retval = true;
78828a1 @pasamio Updates to installer subsystem
pasamio authored
305
a820fcd @eddieajau Code cleaning.
eddieajau authored
306 // First order of business will be to load the template object table from the database.
307 // This should give us the necessary information to proceed.
308 $row = JTable::getInstance('extension');
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
309
a820fcd @eddieajau Code cleaning.
eddieajau authored
310 if (!$row->load((int) $id) || !strlen($row->element))
311 {
312 JError::raiseWarning(100, JText::_('JLIB_INSTALLER_ERROR_TPL_UNINSTALL_ERRORUNKOWNEXTENSION'));
313 return false;
314 }
f73b659 Imported the new trunk.
Rob Schley authored
315
a820fcd @eddieajau Code cleaning.
eddieajau authored
316 // Is the template we are trying to uninstall a core one?
317 // Because that is not a good idea...
318 if ($row->protected)
319 {
320 JError::raiseWarning(100, JText::sprintf('JLIB_INSTALLER_ERROR_TPL_UNINSTALL_WARNCORETEMPLATE', $row->name));
321 return false;
322 }
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
323
a820fcd @eddieajau Code cleaning.
eddieajau authored
324 $name = $row->element;
325 $clientId = $row->client_id;
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
326
a820fcd @eddieajau Code cleaning.
eddieajau authored
327 // For a template the id will be the template name which represents the subfolder of the templates folder that the template resides in.
328 if (!$name)
329 {
330 JError::raiseWarning(100, JText::_('JLIB_INSTALLER_ERROR_TPL_UNINSTALL_TEMPLATE_ID_EMPTY'));
eefdefd @eddieajau Code formatting.
eddieajau authored
331
a820fcd @eddieajau Code cleaning.
eddieajau authored
332 return false;
333 }
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
334
a820fcd @eddieajau Code cleaning.
eddieajau authored
335 // Deny remove default template
336 $db = $this->parent->getDbo();
337 $query = 'SELECT COUNT(*) FROM #__template_styles' . ' WHERE home = 1 AND template = ' . $db->Quote($name);
338 $db->setQuery($query);
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
339
a820fcd @eddieajau Code cleaning.
eddieajau authored
340 if ($db->loadResult() != 0)
341 {
342 JError::raiseWarning(100, JText::_('JLIB_INSTALLER_ERROR_TPL_UNINSTALL_TEMPLATE_DEFAULT'));
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
343
a820fcd @eddieajau Code cleaning.
eddieajau authored
344 return false;
345 }
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
346
a820fcd @eddieajau Code cleaning.
eddieajau authored
347 // Get the template root path
348 $client = JApplicationHelper::getClientInfo($clientId);
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
349
a820fcd @eddieajau Code cleaning.
eddieajau authored
350 if (!$client)
351 {
352 JError::raiseWarning(100, JText::_('JLIB_INSTALLER_ERROR_TPL_UNINSTALL_INVALID_CLIENT'));
353 return false;
354 }
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
355
a820fcd @eddieajau Code cleaning.
eddieajau authored
356 $this->parent->setPath('extension_root', $client->path . '/templates/' . strtolower($name));
357 $this->parent->setPath('source', $this->parent->getPath('extension_root'));
f73b659 Imported the new trunk.
Rob Schley authored
358
a820fcd @eddieajau Code cleaning.
eddieajau authored
359 // We do findManifest to avoid problem when uninstalling a list of extensions: getManifest cache its manifest file
360 $this->parent->findManifest();
361 $manifest = $this->parent->getManifest();
362 if (!($manifest instanceof JXMLElement))
363 {
364 // Kill the extension entry
78828a1 @pasamio Updates to installer subsystem
pasamio authored
365 $row->delete($row->extension_id);
366 unset($row);
a820fcd @eddieajau Code cleaning.
eddieajau authored
367 // Make sure we delete the folders
368 JFolder::delete($this->parent->getPath('extension_root'));
369 JError::raiseWarning(100, JText::_('JLIB_INSTALLER_ERROR_TPL_UNINSTALL_INVALID_NOTFOUND_MANIFEST'));
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
370
a820fcd @eddieajau Code cleaning.
eddieajau authored
371 return false;
f73b659 Imported the new trunk.
Rob Schley authored
372 }
373
a820fcd @eddieajau Code cleaning.
eddieajau authored
374 // Remove files
375 $this->parent->removeFiles($manifest->media);
376 $this->parent->removeFiles($manifest->languages, $clientId);
377
378 // Delete the template directory
379 if (JFolder::exists($this->parent->getPath('extension_root')))
380 {
381 $retval = JFolder::delete($this->parent->getPath('extension_root'));
382 }
383 else
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
384 {
a820fcd @eddieajau Code cleaning.
eddieajau authored
385 JError::raiseWarning(100, JText::_('JLIB_INSTALLER_ERROR_TPL_UNINSTALL_TEMPLATE_DIRECTORY'));
386 $retval = false;
387 }
388
389 // Set menu that assigned to the template back to default template
390 $query = 'UPDATE #__menu INNER JOIN #__template_styles' . ' ON #__template_styles.id = #__menu.template_style_id'
391 . ' SET #__menu.template_style_id = 0' . ' WHERE #__template_styles.template = ' . $db->Quote(strtolower($name))
392 . ' AND #__template_styles.client_id = ' . $db->Quote($clientId);
393 $db->setQuery($query);
394 $db->Query();
f73b659 Imported the new trunk.
Rob Schley authored
395
a820fcd @eddieajau Code cleaning.
eddieajau authored
396 $query = 'DELETE FROM #__template_styles' . ' WHERE template = ' . $db->Quote($name) . ' AND client_id = ' . $db->Quote($clientId);
397 $db->setQuery($query);
398 $db->Query();
399
400 $row->delete($row->extension_id);
401 unset($row);
402
403 return $retval;
404 }
405
406 /**
407 * Discover existing but uninstalled templates
408 *
409 * @return array JExtensionTable list
410 */
f7db975 @eddieajau Fix up missing method scope declarations.
eddieajau authored
411 public function discover()
a820fcd @eddieajau Code cleaning.
eddieajau authored
412 {
9f10f39 @realityking Make all PHP keywords (but not built-in functions) lowercase.
realityking authored
413 $results = array();
a820fcd @eddieajau Code cleaning.
eddieajau authored
414 $site_list = JFolder::folders(JPATH_SITE . '/templates');
415 $admin_list = JFolder::folders(JPATH_ADMINISTRATOR . '/templates');
416 $site_info = JApplicationHelper::getClientInfo('site', true);
417 $admin_info = JApplicationHelper::getClientInfo('administrator', true);
418
419 foreach ($site_list as $template)
420 {
421 if ($template == 'system')
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
422 {
a820fcd @eddieajau Code cleaning.
eddieajau authored
423 continue;
eefdefd @eddieajau Code formatting.
eddieajau authored
424
a820fcd @eddieajau Code cleaning.
eddieajau authored
425 // Ignore special system template
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
426 }
a820fcd @eddieajau Code cleaning.
eddieajau authored
427 $manifest_details = JApplicationHelper::parseXMLInstallFile(JPATH_SITE . "/templates/$template/templateDetails.xml");
428 $extension = JTable::getInstance('extension');
429 $extension->set('type', 'template');
430 $extension->set('client_id', $site_info->id);
431 $extension->set('element', $template);
432 $extension->set('name', $template);
433 $extension->set('state', -1);
434 $extension->set('manifest_cache', json_encode($manifest_details));
435 $results[] = $extension;
436 }
78828a1 @pasamio Updates to installer subsystem
pasamio authored
437
a820fcd @eddieajau Code cleaning.
eddieajau authored
438 foreach ($admin_list as $template)
439 {
440 if ($template == 'system')
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
441 {
a820fcd @eddieajau Code cleaning.
eddieajau authored
442 continue;
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
443
a820fcd @eddieajau Code cleaning.
eddieajau authored
444 // Ignore special system template
eefdefd @eddieajau Code formatting.
eddieajau authored
445 }
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
446
a820fcd @eddieajau Code cleaning.
eddieajau authored
447 $manifest_details = JApplicationHelper::parseXMLInstallFile(JPATH_ADMINISTRATOR . "/templates/$template/templateDetails.xml");
448 $extension = JTable::getInstance('extension');
449 $extension->set('type', 'template');
450 $extension->set('client_id', $admin_info->id);
451 $extension->set('element', $template);
452 $extension->set('name', $template);
453 $extension->set('state', -1);
454 $extension->set('manifest_cache', json_encode($manifest_details));
455 $results[] = $extension;
78828a1 @pasamio Updates to installer subsystem
pasamio authored
456 }
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
457
a820fcd @eddieajau Code cleaning.
eddieajau authored
458 return $results;
459 }
460
461 /**
462 * Discover_install
463 * Perform an install for a discovered extension
464 *
465 * @return boolean
466 *
467 * @since 11.1
468 */
f7db975 @eddieajau Fix up missing method scope declarations.
eddieajau authored
469 public function discover_install()
a820fcd @eddieajau Code cleaning.
eddieajau authored
470 {
471 // Templates are one of the easiest
472 // If its not in the extensions table we just add it
473 $client = JApplicationHelper::getClientInfo($this->parent->extension->client_id);
474 $manifestPath = $client->path . '/templates/' . $this->parent->extension->element . '/templateDetails.xml';
475 $this->parent->manifest = $this->parent->isManifest($manifestPath);
476 $description = (string) $this->parent->manifest->description;
477
478 if ($description)
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
479 {
a820fcd @eddieajau Code cleaning.
eddieajau authored
480 $this->parent->set('message', JText::_($description));
481 }
482 else
483 {
484 $this->parent->set('message', '');
485 }
4b7445f @LouisLandry Code cleanup.
LouisLandry authored
486
a820fcd @eddieajau Code cleaning.
eddieajau authored
487 $this->parent->setPath('manifest', $manifestPath);
488 $manifest_details = JApplicationHelper::parseXMLInstallFile($this->parent->getPath('manifest'));
489 $this->parent->extension->manifest_cache = json_encode($manifest_details);
490 $this->parent->extension->state = 0;
491 $this->parent->extension->name = $manifest_details['name'];
492 $this->parent->extension->enabled = 1;
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
493
9005bd1 @elkuku Removing unnecessary empty braces when instancing classes
elkuku authored
494 $data = new JObject;
668b9a5 @chdemko Fixed [#20232] Discovery method of installing templates doesn't inser…
chdemko authored
495
a820fcd @eddieajau Code cleaning.
eddieajau authored
496 foreach ($manifest_details as $key => $value)
497 {
498 $data->set($key, $value);
499 }
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
500
a820fcd @eddieajau Code cleaning.
eddieajau authored
501 $this->parent->extension->params = $this->parent->getParams();
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
502
a820fcd @eddieajau Code cleaning.
eddieajau authored
503 if ($this->parent->extension->store())
504 {
505 //insert record in #__template_styles
506 $db = $this->parent->getDbo();
507 $query = $db->getQuery(true);
508 $query->insert('#__template_styles');
8e64310 @chdemko Update libraries/joomla/installer/adapters/template.php
chdemko authored
509 $query->set('template=' . $db->Quote($this->parent->extension->element));
a820fcd @eddieajau Code cleaning.
eddieajau authored
510 $query->set('client_id=' . $db->Quote($this->parent->extension->client_id));
511 $query->set('home=0');
512 $query->set('title=' . $db->Quote(JText::sprintf('JLIB_INSTALLER_DEFAULT_STYLE', $this->parent->extension->name)));
513 $query->set('params=' . $db->Quote($this->parent->extension->params));
514 $db->setQuery($query);
515 $db->query();
eefdefd @eddieajau Code formatting.
eddieajau authored
516
a820fcd @eddieajau Code cleaning.
eddieajau authored
517 return $this->parent->extension->get('extension_id');
518 }
519 else
520 {
521 JError::raiseWarning(101, JText::_('JLIB_INSTALLER_ERROR_TPL_DISCOVER_STORE_DETAILS'));
668b9a5 @chdemko Fixed [#20232] Discovery method of installing templates doesn't inser…
chdemko authored
522
a820fcd @eddieajau Code cleaning.
eddieajau authored
523 return false;
eefdefd @eddieajau Code formatting.
eddieajau authored
524 }
a820fcd @eddieajau Code cleaning.
eddieajau authored
525 }
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
526
a820fcd @eddieajau Code cleaning.
eddieajau authored
527 /**
528 * Refreshes the extension table cache
529 *
530 * @return boolean Result of operation, true if updated, false on failure
531 *
532 * @since 11.1
533 */
534 public function refreshManifestCache()
535 {
536 // Need to find to find where the XML file is since we don't store this normally.
537 $client = JApplicationHelper::getClientInfo($this->parent->extension->client_id);
538 $manifestPath = $client->path . '/templates/' . $this->parent->extension->element . '/templateDetails.xml';
539 $this->parent->manifest = $this->parent->isManifest($manifestPath);
540 $this->parent->setPath('manifest', $manifestPath);
89e3d3a @LouisLandry Fixed up file headers.
LouisLandry authored
541
a820fcd @eddieajau Code cleaning.
eddieajau authored
542 $manifest_details = JApplicationHelper::parseXMLInstallFile($this->parent->getPath('manifest'));
543 $this->parent->extension->manifest_cache = json_encode($manifest_details);
544 $this->parent->extension->name = $manifest_details['name'];
9589e50 @chdemko [#23837] *Installation unexpectedly terminated: Method not supported …
chdemko authored
545
a820fcd @eddieajau Code cleaning.
eddieajau authored
546 try
547 {
548 return $this->parent->extension->store();
9589e50 @chdemko [#23837] *Installation unexpectedly terminated: Method not supported …
chdemko authored
549 }
a820fcd @eddieajau Code cleaning.
eddieajau authored
550 catch (JException $e)
551 {
552 JError::raiseWarning(101, JText::_('JLIB_INSTALLER_ERROR_TPL_REFRESH_MANIFEST_CACHE'));
553 return false;
554 }
555 }
556 }
Something went wrong with that request. Please try again.