Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 843 lines (719 sloc) 18.444 kB
f73b659 Imported the new trunk.
Rob Schley authored
1 <?php
2 /**
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
3 * @package Joomla.Platform
0a72863 @LouisLandry Fixing file headers for both unit test and library files.
LouisLandry authored
4 *
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
5 * @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
6 * @license GNU General Public License version 2 or later; see LICENSE
f73b659 Imported the new trunk.
Rob Schley authored
7 */
8
89e3d3a @LouisLandry Fixed up file headers.
LouisLandry authored
9 defined('JPATH_PLATFORM') or die;
1d7b3af @eddieajau # Fixed [#18366] [patch] for tracker item [#18079] defined or die; m…
eddieajau authored
10
f73b659 Imported the new trunk.
Rob Schley authored
11 /**
275537c @elinw Platform not Framework
elinw authored
12 * Joomla Platform Factory class
f73b659 Imported the new trunk.
Rob Schley authored
13 *
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
14 * @package Joomla.Platform
15 * @since 11.1
f73b659 Imported the new trunk.
Rob Schley authored
16 */
17 abstract class JFactory
18 {
c5806da @eddieajau Fixed a bug in JFactory::getDate where unserialising a data with embe…
eddieajau authored
19 /**
20 * @var JApplication
21 * @since 11.1
22 */
f73b659 Imported the new trunk.
Rob Schley authored
23 public static $application = null;
c5806da @eddieajau Fixed a bug in JFactory::getDate where unserialising a data with embe…
eddieajau authored
24
25 /**
26 * @var JCache
27 * @since 11.1
28 */
4e562e1 @Hackwar # Small performance improvements ot JRegistry, JFactory::getCache()
Hackwar authored
29 public static $cache = null;
c5806da @eddieajau Fixed a bug in JFactory::getDate where unserialising a data with embe…
eddieajau authored
30
31 /**
32 * @var JConfig
33 * @since 11.1
34 */
f73b659 Imported the new trunk.
Rob Schley authored
35 public static $config = null;
c5806da @eddieajau Fixed a bug in JFactory::getDate where unserialising a data with embe…
eddieajau authored
36
37 /**
38 * @var array
39 * @since 11.3
40 */
41 public static $dates = array();
42
43 /**
44 * @var JSession
45 * @since 11.1
46 */
f73b659 Imported the new trunk.
Rob Schley authored
47 public static $session = null;
c5806da @eddieajau Fixed a bug in JFactory::getDate where unserialising a data with embe…
eddieajau authored
48
49 /**
50 * @var JLanguage
51 * @since 11.1
52 */
f73b659 Imported the new trunk.
Rob Schley authored
53 public static $language = null;
c5806da @eddieajau Fixed a bug in JFactory::getDate where unserialising a data with embe…
eddieajau authored
54
55 /**
56 * @var JDocument
57 * @since 11.1
58 */
f73b659 Imported the new trunk.
Rob Schley authored
59 public static $document = null;
c5806da @eddieajau Fixed a bug in JFactory::getDate where unserialising a data with embe…
eddieajau authored
60
61 /**
62 * @var JAccess
63 * @since 11.1
64 */
f73b659 Imported the new trunk.
Rob Schley authored
65 public static $acl = null;
c5806da @eddieajau Fixed a bug in JFactory::getDate where unserialising a data with embe…
eddieajau authored
66
67 /**
68 * @var JDatabase
69 * @since 11.1
70 */
f73b659 Imported the new trunk.
Rob Schley authored
71 public static $database = null;
c5806da @eddieajau Fixed a bug in JFactory::getDate where unserialising a data with embe…
eddieajau authored
72
73 /**
74 * @var JMail
75 * @since 11.1
76 */
f73b659 Imported the new trunk.
Rob Schley authored
77 public static $mailer = null;
78
79 /**
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
80 * Get a application object.
f73b659 Imported the new trunk.
Rob Schley authored
81 *
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
82 * Returns the global {@link JApplication} object, only creating it if it doesn't already exist.
f73b659 Imported the new trunk.
Rob Schley authored
83 *
fe90bf3 @elinw applied patch
elinw authored
84 * @param mixed $id A client identifier or name.
85 * @param array $config An optional associative array of configuration settings.
86 * @param string $prefix Application prefix
1ffd3c1 @ianmacl [#20691] Doc Block and Code Formatting Fixes - Thanks Marius
ianmacl authored
87 *
fe90bf3 @elinw applied patch
elinw authored
88 * @return JApplication object
53daea8 @eddieajau Code cleaning.
eddieajau authored
89 *
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
90 * @see JApplication
91 * @since 11.1
f73b659 Imported the new trunk.
Rob Schley authored
92 */
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
93 public static function getApplication($id = null, $config = array(), $prefix = 'J')
f73b659 Imported the new trunk.
Rob Schley authored
94 {
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
95 if (!self::$application)
96 {
f73b659 Imported the new trunk.
Rob Schley authored
97 jimport('joomla.application.application');
98
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
99 if (!$id)
100 {
f73b659 Imported the new trunk.
Rob Schley authored
101 JError::raiseError(500, 'Application Instantiation Error');
102 }
103
91ef3ea @chdemko Fixed issue [#12757] JDate override problem in Backend
chdemko authored
104 self::$application = JApplication::getInstance($id, $config, $prefix);
f73b659 Imported the new trunk.
Rob Schley authored
105 }
106
91ef3ea @chdemko Fixed issue [#12757] JDate override problem in Backend
chdemko authored
107 return self::$application;
f73b659 Imported the new trunk.
Rob Schley authored
108 }
109
110 /**
111 * Get a configuration object
112 *
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
113 * Returns the global {@link JRegistry} object, only creating it if it doesn't already exist.
f73b659 Imported the new trunk.
Rob Schley authored
114 *
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
115 * @param string $file The path to the configuration file
116 * @param string $type The type of the configuration file
ea2d05f @eddieajau Trim trailing white space.
eddieajau authored
117 *
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
118 * @return JRegistry
d751c2c @eddieajau Trim trailing white space.
eddieajau authored
119 *
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
120 * @see JRegistry
121 * @since 11.1
f73b659 Imported the new trunk.
Rob Schley authored
122 */
8699a0c @LouisLandry Clean up of reference operators as they aren't needed in PHP5
LouisLandry authored
123 public static function getConfig($file = null, $type = 'PHP')
f73b659 Imported the new trunk.
Rob Schley authored
124 {
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
125 if (!self::$config)
126 {
127 if ($file === null)
128 {
129 $file = JPATH_PLATFORM . '/config.php';
f73b659 Imported the new trunk.
Rob Schley authored
130 }
131
91ef3ea @chdemko Fixed issue [#12757] JDate override problem in Backend
chdemko authored
132 self::$config = self::_createConfig($file, $type);
f73b659 Imported the new trunk.
Rob Schley authored
133 }
134
91ef3ea @chdemko Fixed issue [#12757] JDate override problem in Backend
chdemko authored
135 return self::$config;
f73b659 Imported the new trunk.
Rob Schley authored
136 }
137
138 /**
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
139 * Get a session object.
f73b659 Imported the new trunk.
Rob Schley authored
140 *
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
141 * Returns the global {@link JSession} object, only creating it if it doesn't already exist.
f73b659 Imported the new trunk.
Rob Schley authored
142 *
53daea8 @eddieajau Code cleaning.
eddieajau authored
143 * @param array $options An array containing session options
ea2d05f @eddieajau Trim trailing white space.
eddieajau authored
144 *
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
145 * @return JSession object
91bc16d @eddieajau Partial fixes to [#20907] Making Joomla more compliant to PHP strict …
eddieajau authored
146 *
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
147 * @see JSession
fe90bf3 @elinw applied patch
elinw authored
148 * @since 11.1
f73b659 Imported the new trunk.
Rob Schley authored
149 */
8699a0c @LouisLandry Clean up of reference operators as they aren't needed in PHP5
LouisLandry authored
150 public static function getSession($options = array())
f73b659 Imported the new trunk.
Rob Schley authored
151 {
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
152 if (!self::$session)
153 {
91ef3ea @chdemko Fixed issue [#12757] JDate override problem in Backend
chdemko authored
154 self::$session = self::_createSession($options);
f73b659 Imported the new trunk.
Rob Schley authored
155 }
156
91ef3ea @chdemko Fixed issue [#12757] JDate override problem in Backend
chdemko authored
157 return self::$session;
f73b659 Imported the new trunk.
Rob Schley authored
158 }
159
160 /**
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
161 * Get a language object.
f73b659 Imported the new trunk.
Rob Schley authored
162 *
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
163 * Returns the global {@link JLanguage} object, only creating it if it doesn't already exist.
ea2d05f @eddieajau Trim trailing white space.
eddieajau authored
164 *
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
165 * @return JLanguage object
d751c2c @eddieajau Trim trailing white space.
eddieajau authored
166 *
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
167 * @see JLanguage
168 * @since 11.1
f73b659 Imported the new trunk.
Rob Schley authored
169 */
8699a0c @LouisLandry Clean up of reference operators as they aren't needed in PHP5
LouisLandry authored
170 public static function getLanguage()
f73b659 Imported the new trunk.
Rob Schley authored
171 {
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
172 if (!self::$language)
173 {
91ef3ea @chdemko Fixed issue [#12757] JDate override problem in Backend
chdemko authored
174 self::$language = self::_createLanguage();
f73b659 Imported the new trunk.
Rob Schley authored
175 }
176
91ef3ea @chdemko Fixed issue [#12757] JDate override problem in Backend
chdemko authored
177 return self::$language;
f73b659 Imported the new trunk.
Rob Schley authored
178 }
179
180 /**
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
181 * Get a document object.
f73b659 Imported the new trunk.
Rob Schley authored
182 *
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
183 * Returns the global {@link JDocument} object, only creating it if it doesn't already exist.
f73b659 Imported the new trunk.
Rob Schley authored
184 *
fe90bf3 @elinw applied patch
elinw authored
185 * @return JDocument object
d751c2c @eddieajau Trim trailing white space.
eddieajau authored
186 *
fe90bf3 @elinw applied patch
elinw authored
187 * @see JDocument
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
188 * @since 11.1
f73b659 Imported the new trunk.
Rob Schley authored
189 */
8699a0c @LouisLandry Clean up of reference operators as they aren't needed in PHP5
LouisLandry authored
190 public static function getDocument()
f73b659 Imported the new trunk.
Rob Schley authored
191 {
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
192 if (!self::$document)
193 {
91ef3ea @chdemko Fixed issue [#12757] JDate override problem in Backend
chdemko authored
194 self::$document = self::_createDocument();
f73b659 Imported the new trunk.
Rob Schley authored
195 }
196
91ef3ea @chdemko Fixed issue [#12757] JDate override problem in Backend
chdemko authored
197 return self::$document;
f73b659 Imported the new trunk.
Rob Schley authored
198 }
199
200 /**
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
201 * Get an user object.
f73b659 Imported the new trunk.
Rob Schley authored
202 *
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
203 * Returns the global {@link JUser} object, only creating it if it doesn't already exist.
f73b659 Imported the new trunk.
Rob Schley authored
204 *
53daea8 @eddieajau Code cleaning.
eddieajau authored
205 * @param integer $id The user to load - Can be an integer or string - If string, it is converted to ID automatically.
f73b659 Imported the new trunk.
Rob Schley authored
206 *
fe90bf3 @elinw applied patch
elinw authored
207 * @return JUser object
d751c2c @eddieajau Trim trailing white space.
eddieajau authored
208 *
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
209 * @see JUser
210 * @since 11.1
f73b659 Imported the new trunk.
Rob Schley authored
211 */
8699a0c @LouisLandry Clean up of reference operators as they aren't needed in PHP5
LouisLandry authored
212 public static function getUser($id = null)
f73b659 Imported the new trunk.
Rob Schley authored
213 {
214 jimport('joomla.user.user');
73e07cb @rvsjoen Coding standards in JFactory::getUser()
rvsjoen authored
215
216 if (is_null($id))
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
217 {
91ef3ea @chdemko Fixed issue [#12757] JDate override problem in Backend
chdemko authored
218 $instance = self::getSession()->get('user');
73e07cb @rvsjoen Coding standards in JFactory::getUser()
rvsjoen authored
219 if (!($instance instanceof JUser))
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
220 {
aa5891a @eddieajau Fixed issue [#20907] Making Joomla more compliant to PHP strict standard
eddieajau authored
221 $instance = JUser::getInstance();
f73b659 Imported the new trunk.
Rob Schley authored
222 }
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
223 }
73e07cb @rvsjoen Coding standards in JFactory::getUser()
rvsjoen authored
224 else
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
225 {
64be392 @rvsjoen If given id is ourselves, behave like no id was given
rvsjoen authored
226 $current = self::getSession()->get('user');
73e07cb @rvsjoen Coding standards in JFactory::getUser()
rvsjoen authored
227 if ($current->id != $id)
794d2a2 @rvsjoen Play nice with coding standards
rvsjoen authored
228 {
64be392 @rvsjoen If given id is ourselves, behave like no id was given
rvsjoen authored
229 $instance = JUser::getInstance($id);
73e07cb @rvsjoen Coding standards in JFactory::getUser()
rvsjoen authored
230 }
231 else
794d2a2 @rvsjoen Play nice with coding standards
rvsjoen authored
232 {
64be392 @rvsjoen If given id is ourselves, behave like no id was given
rvsjoen authored
233 $instance = self::getSession()->get('user');
234 }
f73b659 Imported the new trunk.
Rob Schley authored
235 }
73e07cb @rvsjoen Coding standards in JFactory::getUser()
rvsjoen authored
236
f73b659 Imported the new trunk.
Rob Schley authored
237 return $instance;
238 }
239
240 /**
241 * Get a cache object
242 *
8699a0c @LouisLandry Clean up of reference operators as they aren't needed in PHP5
LouisLandry authored
243 * Returns the global {@link JCache} object
f73b659 Imported the new trunk.
Rob Schley authored
244 *
53daea8 @eddieajau Code cleaning.
eddieajau authored
245 * @param string $group The cache group name
246 * @param string $handler The handler to use
247 * @param string $storage The storage method
ea2d05f @eddieajau Trim trailing white space.
eddieajau authored
248 *
53daea8 @eddieajau Code cleaning.
eddieajau authored
249 * @return JCache object
91bc16d @eddieajau Partial fixes to [#20907] Making Joomla more compliant to PHP strict …
eddieajau authored
250 *
53daea8 @eddieajau Code cleaning.
eddieajau authored
251 * @see JCache
f73b659 Imported the new trunk.
Rob Schley authored
252 */
8699a0c @LouisLandry Clean up of reference operators as they aren't needed in PHP5
LouisLandry authored
253 public static function getCache($group = '', $handler = 'callback', $storage = null)
f73b659 Imported the new trunk.
Rob Schley authored
254 {
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
255 $hash = md5($group . $handler . $storage);
256 if (isset(self::$cache[$hash]))
257 {
91ef3ea @chdemko Fixed issue [#12757] JDate override problem in Backend
chdemko authored
258 return self::$cache[$hash];
4e562e1 @Hackwar # Small performance improvements ot JRegistry, JFactory::getCache()
Hackwar authored
259 }
f73b659 Imported the new trunk.
Rob Schley authored
260 $handler = ($handler == 'function') ? 'callback' : $handler;
261
91bc16d @eddieajau Partial fixes to [#20907] Making Joomla more compliant to PHP strict …
eddieajau authored
262 $conf = self::getConfig();
a83e119 @LouisLandry Cleaning out trailing whitespace.
LouisLandry authored
263
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
264 $options = array('defaultgroup' => $group);
a83e119 @LouisLandry Cleaning out trailing whitespace.
LouisLandry authored
265
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
266 if (isset($storage))
267 {
4a7b43b # [#20796] Joomla! caches ALL HTML in 1 file. Thanks Klas.
Jean-Marie Simonet authored
268 $options['storage'] = $storage;
f73b659 Imported the new trunk.
Rob Schley authored
269 }
a83e119 @LouisLandry Cleaning out trailing whitespace.
LouisLandry authored
270
f73b659 Imported the new trunk.
Rob Schley authored
271 jimport('joomla.cache.cache');
272
91bc16d @eddieajau Partial fixes to [#20907] Making Joomla more compliant to PHP strict …
eddieajau authored
273 $cache = JCache::getInstance($handler, $options);
c6c4a01 @eddieajau Trim trailing white space.
eddieajau authored
274
91ef3ea @chdemko Fixed issue [#12757] JDate override problem in Backend
chdemko authored
275 self::$cache[$hash] = $cache;
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
276
91ef3ea @chdemko Fixed issue [#12757] JDate override problem in Backend
chdemko authored
277 return self::$cache[$hash];
f73b659 Imported the new trunk.
Rob Schley authored
278 }
279
280 /**
281 * Get an authorization object
282 *
8699a0c @LouisLandry Clean up of reference operators as they aren't needed in PHP5
LouisLandry authored
283 * Returns the global {@link JACL} object, only creating it
f73b659 Imported the new trunk.
Rob Schley authored
284 * if it doesn't already exist.
285 *
e3d0f39 @eddieajau Code cleaning.
eddieajau authored
286 * @return JACL object
f73b659 Imported the new trunk.
Rob Schley authored
287 */
8699a0c @LouisLandry Clean up of reference operators as they aren't needed in PHP5
LouisLandry authored
288 public static function getACL()
f73b659 Imported the new trunk.
Rob Schley authored
289 {
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
290 if (!self::$acl)
291 {
f73b659 Imported the new trunk.
Rob Schley authored
292 jimport('joomla.access.access');
e7e352f @elkuku removing empty braces when instancing new a class
elkuku authored
293 self::$acl = new JAccess;
f73b659 Imported the new trunk.
Rob Schley authored
294 }
295
91ef3ea @chdemko Fixed issue [#12757] JDate override problem in Backend
chdemko authored
296 return self::$acl;
f73b659 Imported the new trunk.
Rob Schley authored
297 }
298
299 /**
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
300 * Get a database object.
f73b659 Imported the new trunk.
Rob Schley authored
301 *
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
302 * Returns the global {@link JDatabase} object, only creating it if it doesn't already exist.
f73b659 Imported the new trunk.
Rob Schley authored
303 *
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
304 * @return JDatabase object
d751c2c @eddieajau Trim trailing white space.
eddieajau authored
305 *
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
306 * @see JDatabase
307 * @since 11.1
f73b659 Imported the new trunk.
Rob Schley authored
308 */
8699a0c @LouisLandry Clean up of reference operators as they aren't needed in PHP5
LouisLandry authored
309 public static function getDbo()
f73b659 Imported the new trunk.
Rob Schley authored
310 {
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
311 if (!self::$database)
312 {
f73b659 Imported the new trunk.
Rob Schley authored
313 //get the debug configuration setting
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
314 $conf = self::getConfig();
315 $debug = $conf->get('debug');
f73b659 Imported the new trunk.
Rob Schley authored
316
5fd474c Various E-Strict validation fixes.
Gergo Erdosi authored
317 self::$database = self::_createDbo();
318 self::$database->debug($debug);
f73b659 Imported the new trunk.
Rob Schley authored
319 }
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
320
5fd474c Various E-Strict validation fixes.
Gergo Erdosi authored
321 return self::$database;
f73b659 Imported the new trunk.
Rob Schley authored
322 }
323
324 /**
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
325 * Get a mailer object.
f73b659 Imported the new trunk.
Rob Schley authored
326 *
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
327 * Returns the global {@link JMail} object, only creating it if it doesn't already exist.
ea2d05f @eddieajau Trim trailing white space.
eddieajau authored
328 *
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
329 * @return JMail object
d751c2c @eddieajau Trim trailing white space.
eddieajau authored
330 *
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
331 * @see JMail
332 * @since 11.1
f73b659 Imported the new trunk.
Rob Schley authored
333 */
8699a0c @LouisLandry Clean up of reference operators as they aren't needed in PHP5
LouisLandry authored
334 public static function getMailer()
f73b659 Imported the new trunk.
Rob Schley authored
335 {
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
336 if (!self::$mailer)
337 {
91ef3ea @chdemko Fixed issue [#12757] JDate override problem in Backend
chdemko authored
338 self::$mailer = self::_createMailer();
f73b659 Imported the new trunk.
Rob Schley authored
339 }
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
340 $copy = clone self::$mailer;
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
341
f73b659 Imported the new trunk.
Rob Schley authored
342 return $copy;
343 }
344
345 /**
346 * Get a parsed XML Feed Source
347 *
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
348 * @param string $url Url for feed source.
349 * @param integer $cache_time Time to cache feed for (using internal cache mechanism).
350 *
351 * @return mixed SimplePie parsed object on success, false on failure.
91bc16d @eddieajau Partial fixes to [#20907] Making Joomla more compliant to PHP strict …
eddieajau authored
352 *
53daea8 @eddieajau Code cleaning.
eddieajau authored
353 * @since 11.1
f73b659 Imported the new trunk.
Rob Schley authored
354 */
8699a0c @LouisLandry Clean up of reference operators as they aren't needed in PHP5
LouisLandry authored
355 public static function getFeedParser($url, $cache_time = 0)
f73b659 Imported the new trunk.
Rob Schley authored
356 {
357 jimport('simplepie.simplepie');
a83e119 @LouisLandry Cleaning out trailing whitespace.
LouisLandry authored
358
1ffd3c1 @ianmacl [#20691] Doc Block and Code Formatting Fixes - Thanks Marius
ianmacl authored
359 $cache = self::getCache('feed_parser', 'callback');
a83e119 @LouisLandry Cleaning out trailing whitespace.
LouisLandry authored
360
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
361 if ($cache_time > 0)
362 {
1ffd3c1 @ianmacl [#20691] Doc Block and Code Formatting Fixes - Thanks Marius
ianmacl authored
363 $cache->setLifeTime($cache_time);
364 }
a83e119 @LouisLandry Cleaning out trailing whitespace.
LouisLandry authored
365
c9b9586 @Hackwar ^+# Implemented a new caching and implemented it in all frontendcompo…
Hackwar authored
366 $simplepie = new SimplePie(null, null, 0);
a83e119 @LouisLandry Cleaning out trailing whitespace.
LouisLandry authored
367
c9b9586 @Hackwar ^+# Implemented a new caching and implemented it in all frontendcompo…
Hackwar authored
368 $simplepie->enable_cache(false);
369 $simplepie->set_feed_url($url);
bb42c43 @Hackwar # refactored TinyMCE - thanks Jean-Marie
Hackwar authored
370 $simplepie->force_feed(true);
a83e119 @LouisLandry Cleaning out trailing whitespace.
LouisLandry authored
371
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
372 $contents = $cache->get(array($simplepie, 'init'), null, false, false);
a83e119 @LouisLandry Cleaning out trailing whitespace.
LouisLandry authored
373
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
374 if ($contents)
375 {
f73b659 Imported the new trunk.
Rob Schley authored
376 return $simplepie;
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
377 }
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
378 else
379 {
00c0cc9 $ Completed libraries/J ini/keys refactoring
Jean-Marie Simonet authored
380 JError::raiseWarning('SOME_ERROR_CODE', JText::_('JLIB_UTIL_ERROR_LOADING_FEED_DATA'));
f73b659 Imported the new trunk.
Rob Schley authored
381 }
8699a0c @LouisLandry Clean up of reference operators as they aren't needed in PHP5
LouisLandry authored
382
383 return false;
f73b659 Imported the new trunk.
Rob Schley authored
384 }
385
386 /**
387 * Get an XML document
388 *
53daea8 @eddieajau Code cleaning.
eddieajau authored
389 * @param string $type The type of XML parser needed 'DOM', 'RSS' or 'Simple'
fe90bf3 @elinw applied patch
elinw authored
390 * @param array $options ['rssUrl'] the rss url to parse when using "RSS", ['cache_time'] with '
391 * RSS' - feed cache time. If not defined defaults to 3600 sec
1ffd3c1 @ianmacl [#20691] Doc Block and Code Formatting Fixes - Thanks Marius
ianmacl authored
392 *
53daea8 @eddieajau Code cleaning.
eddieajau authored
393 * @return object Parsed XML document object
d751c2c @eddieajau Trim trailing white space.
eddieajau authored
394 *
06d46aa @elinw More deprecation logging and deprecating some methods of deprecated
elinw authored
395 * @deprecated 12.1 Use JXMLElement instead.
396 * @see JXMLElement
f73b659 Imported the new trunk.
Rob Schley authored
397 */
8699a0c @LouisLandry Clean up of reference operators as they aren't needed in PHP5
LouisLandry authored
398 public static function getXMLParser($type = '', $options = array())
9d3bd0a @Hackwar ^ Using PHPs built in SimpleXML instead of JSimpleXML to read XML fil…
Hackwar authored
399 {
06d46aa @elinw More deprecation logging and deprecating some methods of deprecated
elinw authored
400 // Deprecation warning.
401 JLog::add('JFactory::getXMLParser() is deprecated.', JLog::WARNING, 'deprecated');
6279bd5 @eddieajau Trim trailing white space.
eddieajau authored
402
f73b659 Imported the new trunk.
Rob Schley authored
403 $doc = null;
404
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
405 switch (strtolower($type))
406 {
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
407 case 'rss':
408 case 'atom':
416c722 @LouisLandry Merging JForm branch down to trunk.
LouisLandry authored
409 $cache_time = isset($options['cache_time']) ? $options['cache_time'] : 0;
91ef3ea @chdemko Fixed issue [#12757] JDate override problem in Backend
chdemko authored
410 $doc = self::getFeedParser($options['rssUrl'], $cache_time);
416c722 @LouisLandry Merging JForm branch down to trunk.
LouisLandry authored
411 break;
f73b659 Imported the new trunk.
Rob Schley authored
412
413 case 'simple':
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
414 // JError::raiseWarning('SOME_ERROR_CODE', 'JSimpleXML is deprecated. Use self::getXML instead');
f73b659 Imported the new trunk.
Rob Schley authored
415 jimport('joomla.utilities.simplexml');
e7e352f @elkuku removing empty braces when instancing new a class
elkuku authored
416 $doc = new JSimpleXML;
f73b659 Imported the new trunk.
Rob Schley authored
417 break;
418
419 case 'dom':
00c0cc9 $ Completed libraries/J ini/keys refactoring
Jean-Marie Simonet authored
420 JError::raiseWarning('SOME_ERROR_CODE', JText::_('JLIB_UTIL_ERROR_DOMIT'));
f73b659 Imported the new trunk.
Rob Schley authored
421 $doc = null;
422 break;
423
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
424 default:
f73b659 Imported the new trunk.
Rob Schley authored
425 $doc = null;
426 }
427
428 return $doc;
429 }
430
431 /**
9d3bd0a @Hackwar ^ Using PHPs built in SimpleXML instead of JSimpleXML to read XML fil…
Hackwar authored
432 * Reads a XML file.
433 *
fe90bf3 @elinw applied patch
elinw authored
434 * @param string $data Full path and file name.
435 * @param boolean $isFile true to load a file or false to load a string.
9d3bd0a @Hackwar ^ Using PHPs built in SimpleXML instead of JSimpleXML to read XML fil…
Hackwar authored
436 *
fe90bf3 @elinw applied patch
elinw authored
437 * @return mixed JXMLElement on success or false on error.
d751c2c @eddieajau Trim trailing white space.
eddieajau authored
438 *
fe90bf3 @elinw applied patch
elinw authored
439 * @see JXMLElement
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
440 * @since 11.1
441 * @todo This may go in a separate class - error reporting may be improved.
9d3bd0a @Hackwar ^ Using PHPs built in SimpleXML instead of JSimpleXML to read XML fil…
Hackwar authored
442 */
3082dc2 @LouisLandry Fixed [#19552] [patch] Error loading xml from string in JFactory::get…
LouisLandry authored
443 public static function getXML($data, $isFile = true)
9d3bd0a @Hackwar ^ Using PHPs built in SimpleXML instead of JSimpleXML to read XML fil…
Hackwar authored
444 {
445 jimport('joomla.utilities.xmlelement');
446
447 // Disable libxml errors and allow to fetch error information as needed
448 libxml_use_internal_errors(true);
449
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
450 if ($isFile)
451 {
53daea8 @eddieajau Code cleaning.
eddieajau authored
452 // Try to load the XML file
3082dc2 @LouisLandry Fixed [#19552] [patch] Error loading xml from string in JFactory::get…
LouisLandry authored
453 $xml = simplexml_load_file($data, 'JXMLElement');
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
454 }
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
455 else
456 {
53daea8 @eddieajau Code cleaning.
eddieajau authored
457 // Try to load the XML string
9d3bd0a @Hackwar ^ Using PHPs built in SimpleXML instead of JSimpleXML to read XML fil…
Hackwar authored
458 $xml = simplexml_load_string($data, 'JXMLElement');
459 }
460
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
461 if (empty($xml))
462 {
9d3bd0a @Hackwar ^ Using PHPs built in SimpleXML instead of JSimpleXML to read XML fil…
Hackwar authored
463 // There was an error
00c0cc9 $ Completed libraries/J ini/keys refactoring
Jean-Marie Simonet authored
464 JError::raiseWarning(100, JText::_('JLIB_UTIL_ERROR_XML_LOAD'));
9d3bd0a @Hackwar ^ Using PHPs built in SimpleXML instead of JSimpleXML to read XML fil…
Hackwar authored
465
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
466 if ($isFile)
467 {
3082dc2 @LouisLandry Fixed [#19552] [patch] Error loading xml from string in JFactory::get…
LouisLandry authored
468 JError::raiseWarning(100, $data);
9d3bd0a @Hackwar ^ Using PHPs built in SimpleXML instead of JSimpleXML to read XML fil…
Hackwar authored
469 }
470
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
471 foreach (libxml_get_errors() as $error)
472 {
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
473 JError::raiseWarning(100, 'XML: ' . $error->message);
9d3bd0a @Hackwar ^ Using PHPs built in SimpleXML instead of JSimpleXML to read XML fil…
Hackwar authored
474 }
475 }
476
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
477 return $xml;
9d3bd0a @Hackwar ^ Using PHPs built in SimpleXML instead of JSimpleXML to read XML fil…
Hackwar authored
478 }
479
480 /**
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
481 * Get an editor object.
482 *
483 * @param string $editor The editor to load, depends on the editor plugins that are installed
9d3bd0a @Hackwar ^ Using PHPs built in SimpleXML instead of JSimpleXML to read XML fil…
Hackwar authored
484 *
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
485 * @return JEditor object
91bc16d @eddieajau Partial fixes to [#20907] Making Joomla more compliant to PHP strict …
eddieajau authored
486 *
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
487 * @since 11.1
9d3bd0a @Hackwar ^ Using PHPs built in SimpleXML instead of JSimpleXML to read XML fil…
Hackwar authored
488 */
8699a0c @LouisLandry Clean up of reference operators as they aren't needed in PHP5
LouisLandry authored
489 public static function getEditor($editor = null)
f73b659 Imported the new trunk.
Rob Schley authored
490 {
491 jimport('joomla.html.editor');
492
493 //get the editor configuration setting
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
494 if (is_null($editor))
495 {
496 $conf = self::getConfig();
497 $editor = $conf->get('editor');
f73b659 Imported the new trunk.
Rob Schley authored
498 }
499
8699a0c @LouisLandry Clean up of reference operators as they aren't needed in PHP5
LouisLandry authored
500 return JEditor::getInstance($editor);
f73b659 Imported the new trunk.
Rob Schley authored
501 }
502
503 /**
504 * Return a reference to the {@link JURI} object
505 *
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
506 * @param string $uri Uri name.
ea2d05f @eddieajau Trim trailing white space.
eddieajau authored
507 *
fe90bf3 @elinw applied patch
elinw authored
508 * @return JURI object
509 *
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
510 * @see JURI
511 * @since 11.1
f73b659 Imported the new trunk.
Rob Schley authored
512 */
8699a0c @LouisLandry Clean up of reference operators as they aren't needed in PHP5
LouisLandry authored
513 public static function getURI($uri = 'SERVER')
f73b659 Imported the new trunk.
Rob Schley authored
514 {
515 jimport('joomla.environment.uri');
516
8699a0c @LouisLandry Clean up of reference operators as they aren't needed in PHP5
LouisLandry authored
517 return JURI::getInstance($uri);
f73b659 Imported the new trunk.
Rob Schley authored
518 }
519
520 /**
8699a0c @LouisLandry Clean up of reference operators as they aren't needed in PHP5
LouisLandry authored
521 * Return the {@link JDate} object
f73b659 Imported the new trunk.
Rob Schley authored
522 *
fe90bf3 @elinw applied patch
elinw authored
523 * @param mixed $time The initial time for the JDate object
524 * @param mixed $tzOffset The timezone offset.
91bc16d @eddieajau Partial fixes to [#20907] Making Joomla more compliant to PHP strict …
eddieajau authored
525 *
fe90bf3 @elinw applied patch
elinw authored
526 * @return JDate object
527 *
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
528 * @see JDate
529 * @since 11.1
f73b659 Imported the new trunk.
Rob Schley authored
530 */
8699a0c @LouisLandry Clean up of reference operators as they aren't needed in PHP5
LouisLandry authored
531 public static function getDate($time = 'now', $tzOffset = null)
f73b659 Imported the new trunk.
Rob Schley authored
532 {
533 jimport('joomla.utilities.date');
534 static $classname;
535 static $mainLocale;
536
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
537 $language = self::getLanguage();
538 $locale = $language->getTag();
f73b659 Imported the new trunk.
Rob Schley authored
539
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
540 if (!isset($classname) || $locale != $mainLocale)
541 {
f73b659 Imported the new trunk.
Rob Schley authored
542 //Store the locale for future reference
543 $mainLocale = $locale;
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
544
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
545 if ($mainLocale !== false)
546 {
547 $classname = str_replace('-', '_', $mainLocale) . 'Date';
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
548
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
549 if (!class_exists($classname))
550 {
91ef3ea @chdemko Fixed issue [#12757] JDate override problem in Backend
chdemko authored
551 //The class does not exist, default to JDate
f73b659 Imported the new trunk.
Rob Schley authored
552 $classname = 'JDate';
553 }
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
554 }
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
555 else
556 {
91ef3ea @chdemko Fixed issue [#12757] JDate override problem in Backend
chdemko authored
557 //No tag, so default to JDate
f73b659 Imported the new trunk.
Rob Schley authored
558 $classname = 'JDate';
559 }
560 }
839b6ff @eddieajau Fixes error in JFactory::getDate where timezone is passed as a string.
eddieajau authored
561
562 $key = $time . '-' . ($tzOffset instanceof DateTimeZone ? $tzOffset->getName() : (string) $tzOffset);
563
c5806da @eddieajau Fixed a bug in JFactory::getDate where unserialising a data with embe…
eddieajau authored
564 if (!isset(self::$dates[$classname][$key]))
839b6ff @eddieajau Fixes error in JFactory::getDate where timezone is passed as a string.
eddieajau authored
565 {
c5806da @eddieajau Fixed a bug in JFactory::getDate where unserialising a data with embe…
eddieajau authored
566 self::$dates[$classname][$key] = new $classname($time, $tzOffset);
839b6ff @eddieajau Fixes error in JFactory::getDate where timezone is passed as a string.
eddieajau authored
567 }
568
c5806da @eddieajau Fixed a bug in JFactory::getDate where unserialising a data with embe…
eddieajau authored
569 $date = clone self::$dates[$classname][$key];
839b6ff @eddieajau Fixes error in JFactory::getDate where timezone is passed as a string.
eddieajau authored
570
571 return $date;
f73b659 Imported the new trunk.
Rob Schley authored
572 }
573
574 /**
575 * Create a configuration object
576 *
a860668 @LouisLandry Fix up some more @since tags as well as platform configuration file l…
LouisLandry authored
577 * @param string $file The path to the configuration file.
578 * @param string $type The type of the configuration file.
579 * @param string $namespace The namespace of the configuration file.
91bc16d @eddieajau Partial fixes to [#20907] Making Joomla more compliant to PHP strict …
eddieajau authored
580 *
a860668 @LouisLandry Fix up some more @since tags as well as platform configuration file l…
LouisLandry authored
581 * @return JRegistry
d751c2c @eddieajau Trim trailing white space.
eddieajau authored
582 *
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
583 * @see JRegistry
584 * @since 11.1
f73b659 Imported the new trunk.
Rob Schley authored
585 */
e497469 @eddieajau Fix up class methods and/or properties that should have been
eddieajau authored
586 protected static function _createConfig($file, $type = 'PHP', $namespace = '')
f73b659 Imported the new trunk.
Rob Schley authored
587 {
588 jimport('joomla.registry.registry');
589
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
590 if (is_file($file))
591 {
67bf9c7 @LouisLandry Fixing up unit testing errors.
LouisLandry authored
592 include_once $file;
593 }
f73b659 Imported the new trunk.
Rob Schley authored
594
595 // Create the registry with a default namespace of config
e7e352f @elkuku removing empty braces when instancing new a class
elkuku authored
596 $registry = new JRegistry;
f73b659 Imported the new trunk.
Rob Schley authored
597
a860668 @LouisLandry Fix up some more @since tags as well as platform configuration file l…
LouisLandry authored
598 // Sanitize the namespace.
599 $namespace = ucfirst((string) preg_replace('/[^A-Z_]/i', '', $namespace));
f73b659 Imported the new trunk.
Rob Schley authored
600
a860668 @LouisLandry Fix up some more @since tags as well as platform configuration file l…
LouisLandry authored
601 // Build the config name.
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
602 $name = 'JConfig' . $namespace;
a860668 @LouisLandry Fix up some more @since tags as well as platform configuration file l…
LouisLandry authored
603
604 // Handle the PHP configuration type.
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
605 if ($type == 'PHP' && class_exists($name))
606 {
a860668 @LouisLandry Fix up some more @since tags as well as platform configuration file l…
LouisLandry authored
607 // Create the JConfig object
e7e352f @elkuku removing empty braces when instancing new a class
elkuku authored
608 $config = new $name;
a860668 @LouisLandry Fix up some more @since tags as well as platform configuration file l…
LouisLandry authored
609
610 // Load the configuration values into the registry
611 $registry->loadObject($config);
612 }
f73b659 Imported the new trunk.
Rob Schley authored
613
614 return $registry;
615 }
616
617 /**
618 * Create a session object
619 *
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
620 * @param array $options An array containing session options
91bc16d @eddieajau Partial fixes to [#20907] Making Joomla more compliant to PHP strict …
eddieajau authored
621 *
fe90bf3 @elinw applied patch
elinw authored
622 * @return JSession object
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
623 *
a860668 @LouisLandry Fix up some more @since tags as well as platform configuration file l…
LouisLandry authored
624 * @since 11.1
f73b659 Imported the new trunk.
Rob Schley authored
625 */
e497469 @eddieajau Fix up class methods and/or properties that should have been
eddieajau authored
626 protected static function _createSession($options = array())
f73b659 Imported the new trunk.
Rob Schley authored
627 {
628 jimport('joomla.session.session');
629
4924fd2 @elinw user,utilities,base files, clean up places
elinw authored
630 // Get the editor configuration setting
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
631 $conf = self::getConfig();
632 $handler = $conf->get('session_handler', 'none');
f73b659 Imported the new trunk.
Rob Schley authored
633
4924fd2 @elinw user,utilities,base files, clean up places
elinw authored
634 // Config time is in minutes
416c722 @LouisLandry Merging JForm branch down to trunk.
LouisLandry authored
635 $options['expire'] = ($conf->get('lifetime')) ? $conf->get('lifetime') * 60 : 900;
f73b659 Imported the new trunk.
Rob Schley authored
636
637 $session = JSession::getInstance($handler, $options);
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
638 if ($session->getState() == 'expired')
639 {
f73b659 Imported the new trunk.
Rob Schley authored
640 $session->restart();
641 }
642
643 return $session;
644 }
645
646 /**
647 * Create an database object
648 *
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
649 * @return JDatabase object
fe90bf3 @elinw applied patch
elinw authored
650 *
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
651 * @see JDatabase
652 * @since 11.1
f73b659 Imported the new trunk.
Rob Schley authored
653 */
e497469 @eddieajau Fix up class methods and/or properties that should have been
eddieajau authored
654 protected static function _createDbo()
f73b659 Imported the new trunk.
Rob Schley authored
655 {
656 jimport('joomla.database.database');
657 jimport('joomla.database.table');
658
91bc16d @eddieajau Partial fixes to [#20907] Making Joomla more compliant to PHP strict …
eddieajau authored
659 $conf = self::getConfig();
f73b659 Imported the new trunk.
Rob Schley authored
660
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
661 $host = $conf->get('host');
662 $user = $conf->get('user');
663 $password = $conf->get('password');
664 $database = $conf->get('db');
665 $prefix = $conf->get('dbprefix');
666 $driver = $conf->get('dbtype');
667 $debug = $conf->get('debug');
f73b659 Imported the new trunk.
Rob Schley authored
668
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
669 $options = array('driver' => $driver, 'host' => $host, 'user' => $user, 'password' => $password, 'database' => $database, 'prefix' => $prefix);
f73b659 Imported the new trunk.
Rob Schley authored
670
91bc16d @eddieajau Partial fixes to [#20907] Making Joomla more compliant to PHP strict …
eddieajau authored
671 $db = JDatabase::getInstance($options);
f73b659 Imported the new trunk.
Rob Schley authored
672
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
673 if (JError::isError($db))
674 {
9dea95d @eddieajau Added check to sending header when database connection cannot be
eddieajau authored
675 if (!headers_sent())
676 {
677 header('HTTP/1.1 500 Internal Server Error');
678 }
69ba254 @eddieajau Fixed issue [#21436] Database Error should return "500 Internal Serve…
eddieajau authored
679 jexit('Database Error: ' . (string) $db);
f73b659 Imported the new trunk.
Rob Schley authored
680 }
681
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
682 if ($db->getErrorNum() > 0)
683 {
1ffd3c1 @ianmacl [#20691] Doc Block and Code Formatting Fixes - Thanks Marius
ianmacl authored
684 JError::raiseError(500, JText::sprintf('JLIB_UTIL_ERROR_CONNECT_DATABASE', $db->getErrorNum(), $db->getErrorMsg()));
f73b659 Imported the new trunk.
Rob Schley authored
685 }
686
687 $db->debug($debug);
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
688
f73b659 Imported the new trunk.
Rob Schley authored
689 return $db;
690 }
691
692 /**
693 * Create a mailer object
694 *
53daea8 @eddieajau Code cleaning.
eddieajau authored
695 * @return JMail object
d751c2c @eddieajau Trim trailing white space.
eddieajau authored
696 *
fe90bf3 @elinw applied patch
elinw authored
697 * @see JMail
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
698 * @since 11.1
f73b659 Imported the new trunk.
Rob Schley authored
699 */
e497469 @eddieajau Fix up class methods and/or properties that should have been
eddieajau authored
700 protected static function _createMailer()
f73b659 Imported the new trunk.
Rob Schley authored
701 {
702 jimport('joomla.mail.mail');
703
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
704 $conf = self::getConfig();
f73b659 Imported the new trunk.
Rob Schley authored
705
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
706 $sendmail = $conf->get('sendmail');
707 $smtpauth = ($conf->get('smtpauth') == 0) ? null : 1;
708 $smtpuser = $conf->get('smtpuser');
709 $smtppass = $conf->get('smtppass');
710 $smtphost = $conf->get('smtphost');
711 $smtpsecure = $conf->get('smtpsecure');
712 $smtpport = $conf->get('smtpport');
713 $mailfrom = $conf->get('mailfrom');
714 $fromname = $conf->get('fromname');
715 $mailer = $conf->get('mailer');
f73b659 Imported the new trunk.
Rob Schley authored
716
717 // Create a JMail object
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
718 $mail = JMail::getInstance();
f73b659 Imported the new trunk.
Rob Schley authored
719
33a4139 @infograf768 See tracker http://joomlacode.org/gf/project/joomla/tracker/?action=T…
infograf768 authored
720 // Set default sender without Reply-to
721 $mail->SetFrom(JMailHelper::cleanLine($mailfrom), JMailHelper::cleanLine($fromname), 0);
f73b659 Imported the new trunk.
Rob Schley authored
722
723 // Default mailer is to use PHP's mail function
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
724 switch ($mailer)
725 {
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
726 case 'smtp':
9b992ba @Hackwar Updated PHPMailer to version 2.3
Hackwar authored
727 $mail->useSMTP($smtpauth, $smtphost, $smtpuser, $smtppass, $smtpsecure, $smtpport);
f73b659 Imported the new trunk.
Rob Schley authored
728 break;
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
729
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
730 case 'sendmail':
f73b659 Imported the new trunk.
Rob Schley authored
731 $mail->IsSendmail();
732 break;
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
733
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
734 default:
f73b659 Imported the new trunk.
Rob Schley authored
735 $mail->IsMail();
736 break;
737 }
738
739 return $mail;
740 }
741
742 /**
743 * Create a language object
744 *
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
745 * @return JLanguage object
fe90bf3 @elinw applied patch
elinw authored
746 *
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
747 * @see JLanguage
748 * @since 11.1
f73b659 Imported the new trunk.
Rob Schley authored
749 */
e497469 @eddieajau Fix up class methods and/or properties that should have been
eddieajau authored
750 protected static function _createLanguage()
f73b659 Imported the new trunk.
Rob Schley authored
751 {
752 jimport('joomla.language.language');
753
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
754 $conf = self::getConfig();
755 $locale = $conf->get('language');
756 $debug = $conf->get('debug_lang');
757 $lang = JLanguage::getInstance($locale, $debug);
f73b659 Imported the new trunk.
Rob Schley authored
758
759 return $lang;
760 }
761
762 /**
763 * Create a document object
ea2d05f @eddieajau Trim trailing white space.
eddieajau authored
764 *
fe90bf3 @elinw applied patch
elinw authored
765 * @return JDocument object
766 *
767 * @see JDocument
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
768 * @since 11.1
f73b659 Imported the new trunk.
Rob Schley authored
769 */
e497469 @eddieajau Fix up class methods and/or properties that should have been
eddieajau authored
770 protected static function _createDocument()
f73b659 Imported the new trunk.
Rob Schley authored
771 {
772 jimport('joomla.document.document');
773
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
774 $lang = self::getLanguage();
f73b659 Imported the new trunk.
Rob Schley authored
775
4924fd2 @elinw user,utilities,base files, clean up places
elinw authored
776 // Keep backwards compatibility with Joomla! 1.0
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
777 $raw = JRequest::getBool('no_html');
778 $type = JRequest::getWord('format', $raw ? 'raw' : 'html');
f73b659 Imported the new trunk.
Rob Schley authored
779
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
780 $attributes = array('charset' => 'utf-8', 'lineend' => 'unix', 'tab' => ' ', 'language' => $lang->getTag(),
781 'direction' => $lang->isRTL() ? 'rtl' : 'ltr');
f73b659 Imported the new trunk.
Rob Schley authored
782
8699a0c @LouisLandry Clean up of reference operators as they aren't needed in PHP5
LouisLandry authored
783 return JDocument::getInstance($type, $attributes);
f73b659 Imported the new trunk.
Rob Schley authored
784 }
052ac22 @eddieajau Trailing spaces removed
eddieajau authored
785
e8679fb @pasamio + Added JFactory::getStream
pasamio authored
786 /**
787 * Creates a new stream object with appropriate prefix
91bc16d @eddieajau Partial fixes to [#20907] Making Joomla more compliant to PHP strict …
eddieajau authored
788 *
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
789 * @param boolean $use_prefix Prefix the connections for writing
790 * @param boolean $use_network Use network if available for writing; use false to disable (e.g. FTP, SCP)
791 * @param string $ua UA User agent to use
792 * @param boolean $uamask User agent masking (prefix Mozilla)
4924fd2 @elinw user,utilities,base files, clean up places
elinw authored
793 *
53daea8 @eddieajau Code cleaning.
eddieajau authored
794 * @return JStream
fe90bf3 @elinw applied patch
elinw authored
795 *
796 * @see JStream
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
797 * @since 11.1
e8679fb @pasamio + Added JFactory::getStream
pasamio authored
798 */
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
799 public static function getStream($use_prefix = true, $use_network = true, $ua = null, $uamask = false)
416c722 @LouisLandry Merging JForm branch down to trunk.
LouisLandry authored
800 {
e8679fb @pasamio + Added JFactory::getStream
pasamio authored
801 jimport('joomla.filesystem.stream');
91bc16d @eddieajau Partial fixes to [#20907] Making Joomla more compliant to PHP strict …
eddieajau authored
802
e8679fb @pasamio + Added JFactory::getStream
pasamio authored
803 // Setup the context; Joomla! UA and overwrite
8bf5519 @eddieajau Fixed issue [#24153] More PHP strict fixes (mostly backend) (Rouven W…
eddieajau authored
804 $context = array();
805 $version = new JVersion;
e8679fb @pasamio + Added JFactory::getStream
pasamio authored
806 // set the UA for HTTP and overwrite for FTP
807 $context['http']['user_agent'] = $version->getUserAgent($ua, $uamask);
052ac22 @eddieajau Trailing spaces removed
eddieajau authored
808 $context['ftp']['overwrite'] = true;
416c722 @LouisLandry Merging JForm branch down to trunk.
LouisLandry authored
809
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
810 if ($use_prefix)
811 {
e8679fb @pasamio + Added JFactory::getStream
pasamio authored
812 jimport('joomla.client.helper');
813 $FTPOptions = JClientHelper::getCredentials('ftp');
814 $SCPOptions = JClientHelper::getCredentials('scp');
91bc16d @eddieajau Partial fixes to [#20907] Making Joomla more compliant to PHP strict …
eddieajau authored
815
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
816 if ($FTPOptions['enabled'] == 1 && $use_network)
817 {
818 $prefix = 'ftp://' . $FTPOptions['user'] . ':' . $FTPOptions['pass'] . '@' . $FTPOptions['host'];
819 $prefix .= $FTPOptions['port'] ? ':' . $FTPOptions['port'] : '';
e8679fb @pasamio + Added JFactory::getStream
pasamio authored
820 $prefix .= $FTPOptions['root'];
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
821 }
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
822 else if ($SCPOptions['enabled'] == 1 && $use_network)
823 {
824 $prefix = 'ssh2.sftp://' . $SCPOptions['user'] . ':' . $SCPOptions['pass'] . '@' . $SCPOptions['host'];
825 $prefix .= $SCPOptions['port'] ? ':' . $SCPOptions['port'] : '';
e8679fb @pasamio + Added JFactory::getStream
pasamio authored
826 $prefix .= $SCPOptions['root'];
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
827 }
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
828 else
829 {
f24540f @realityking Sync some changes from Joomla 1.7.
realityking authored
830 $prefix = JPATH_ROOT . '/';
e8679fb @pasamio + Added JFactory::getStream
pasamio authored
831 }
91bc16d @eddieajau Partial fixes to [#20907] Making Joomla more compliant to PHP strict …
eddieajau authored
832
e8679fb @pasamio + Added JFactory::getStream
pasamio authored
833 $retval = new JStream($prefix, JPATH_ROOT, $context);
18c45a5 @eddieajau Fixed issue [#23041] Incorrect testing for variable is an instance of…
eddieajau authored
834 }
78e6bc0 @eddieajau Code cleaning.
eddieajau authored
835 else
836 {
1ffd3c1 @ianmacl [#20691] Doc Block and Code Formatting Fixes - Thanks Marius
ianmacl authored
837 $retval = new JStream('', '', $context);
e8679fb @pasamio + Added JFactory::getStream
pasamio authored
838 }
91bc16d @eddieajau Partial fixes to [#20907] Making Joomla more compliant to PHP strict …
eddieajau authored
839
e8679fb @pasamio + Added JFactory::getStream
pasamio authored
840 return $retval;
841 }
f73b659 Imported the new trunk.
Rob Schley authored
842 }
Something went wrong with that request. Please try again.