9 defined(
'JPATH_PLATFORM') or die;
25 public static $application = null;
33 public static $cache = null;
41 public static $config = null;
49 public static $dates = array();
57 public static $session = null;
65 public static $language = null;
73 public static $document = null;
82 public static $acl = null;
90 public static $database = null;
98 public static $mailer = null;
115 public static function getApplication($id = null, array $config = array(), $prefix =
'J')
117 if (!self::$application)
121 throw new Exception(
'Application Instantiation Error', 500);
124 self::$application = JApplicationCms::getInstance($id);
127 return self::$application;
144 public static function getConfig($file = null, $type =
'PHP', $namespace =
'')
150 $file = JPATH_PLATFORM .
'/config.php';
153 self::$config = self::createConfig($file, $type, $namespace);
156 return self::$config;
171 public static function getSession(array $options = array())
175 self::$session = self::createSession($options);
178 return self::$session;
191 public static function getLanguage()
193 if (!self::$language)
195 self::$language = self::createLanguage();
198 return self::$language;
211 public static function getDocument()
213 if (!self::$document)
215 self::$document = self::createDocument();
218 return self::$document;
233 public static function getUser($id = null)
235 $instance = self::getSession()->get(
'user');
239 if (!($instance instanceof
JUser))
244 elseif ($instance->id != $id)
266 public static function getCache($group =
'', $handler =
'callback', $storage = null)
268 $hash = md5($group . $handler . $storage);
270 if (isset(self::$cache[$hash]))
272 return self::$cache[$hash];
275 $handler = ($handler ==
'function') ?
'callback' : $handler;
277 $options = array(
'defaultgroup' => $group);
281 $options[
'storage'] = $storage;
286 self::$cache[$hash] = $cache;
288 return self::$cache[$hash];
301 public static function getACL()
323 public static function getDbo()
325 if (!self::$database)
327 self::$database = self::createDbo();
330 return self::$database;
343 public static function getMailer()
347 self::$mailer = self::createMailer();
350 $copy = clone self::$mailer;
367 public static function getFeedParser($url, $cache_time = 0)
369 if (!class_exists(
'JSimplepieFactory'))
371 throw new BadMethodCallException(
'JSimplepieFactory not found');
374 JLog::add(__METHOD__ .
' is deprecated. Use JFeedFactory() or supply SimplePie instead.',
JLog::WARNING,
'deprecated');
392 public static function getXML($data, $isFile =
true)
396 $class =
'SimpleXMLElement';
398 if (class_exists(
'JXMLElement'))
400 $class =
'JXMLElement';
404 libxml_use_internal_errors(
true);
409 $xml = simplexml_load_file($data, $class);
414 $xml = simplexml_load_string($data, $class);
426 foreach (libxml_get_errors() as $error)
446 public static function getEditor($editor = null)
450 if (!class_exists(
'JEditor'))
452 throw new BadMethodCallException(
'JEditor not found');
456 if (is_null($editor))
458 $conf = self::getConfig();
459 $editor = $conf->get(
'editor');
462 return JEditor::getInstance($editor);
476 public static function getURI($uri =
'SERVER')
494 public static function getDate($time =
'now', $tzOffset = null)
499 $language = self::getLanguage();
500 $locale = $language->getTag();
502 if (!isset($classname) || $locale != $mainLocale)
505 $mainLocale = $locale;
507 if ($mainLocale !==
false)
509 $classname = str_replace(
'-',
'_', $mainLocale) .
'Date';
511 if (!class_exists($classname))
514 $classname =
'JDate';
520 $classname =
'JDate';
524 $key = $time .
'-' . ($tzOffset instanceof DateTimeZone ? $tzOffset->getName() : (string) $tzOffset);
526 if (!isset(self::$dates[$classname][$key]))
528 self::$dates[$classname][$key] =
new $classname($time, $tzOffset);
531 $date = clone self::$dates[$classname][$key];
548 protected static function createConfig($file, $type =
'PHP', $namespace =
'')
559 $namespace = ucfirst((
string) preg_replace(
'/[^A-Z_]/i',
'', $namespace));
562 $name =
'JConfig' . $namespace;
565 if ($type ==
'PHP' && class_exists($name))
571 $registry->loadObject($config);
586 protected static function createSession(array $options = array())
589 $conf = self::getConfig();
590 $handler = $conf->get(
'session_handler',
'none');
593 $options[
'expire'] = ($conf->get(
'lifetime')) ? $conf->get(
'lifetime') * 60 : 900;
597 if ($session->getState() ==
'expired')
613 protected static function createDbo()
615 $conf = self::getConfig();
617 $host = $conf->get(
'host');
618 $user = $conf->get(
'user');
619 $password = $conf->get(
'password');
620 $database = $conf->get(
'db');
621 $prefix = $conf->get(
'dbprefix');
622 $driver = $conf->get(
'dbtype');
623 $debug = $conf->get(
'debug');
625 $options = array(
'driver' => $driver,
'host' => $host,
'user' => $user,
'password' => $password,
'database' => $database,
'prefix' => $prefix);
631 catch (RuntimeException $e)
635 header(
'HTTP/1.1 500 Internal Server Error');
638 jexit(
'Database Error: ' . $e->getMessage());
641 $db->setDebug($debug);
654 protected static function createMailer()
656 $conf = self::getConfig();
658 $smtpauth = ($conf->get(
'smtpauth') == 0) ? null : 1;
659 $smtpuser = $conf->get(
'smtpuser');
660 $smtppass = $conf->get(
'smtppass');
661 $smtphost = $conf->get(
'smtphost');
662 $smtpsecure = $conf->get(
'smtpsecure');
663 $smtpport = $conf->get(
'smtpport');
664 $mailfrom = $conf->get(
'mailfrom');
665 $fromname = $conf->get(
'fromname');
666 $mailer = $conf->get(
'mailer');
678 $mail->useSMTP($smtpauth, $smtphost, $smtpuser, $smtppass, $smtpsecure, $smtpport);
701 protected static function createLanguage()
703 $conf = self::getConfig();
704 $locale = $conf->get(
'language');
705 $debug = $conf->get(
'debug_lang');
719 protected static function createDocument()
721 $lang = self::getLanguage();
723 $input = self::getApplication()->input;
724 $type = $input->get(
'format',
'html',
'word');
726 $version =
new JVersion;
729 'charset' =>
'utf-8',
732 'language' => $lang->getTag(),
733 'direction' => $lang->isRTL() ?
'rtl' :
'ltr',
734 'mediaversion' => $version->getMediaVersion()
753 public static function getStream($use_prefix =
true, $use_network =
true, $ua = null, $uamask =
false)
755 jimport(
'joomla.filesystem.stream');
759 $version =
new JVersion;
762 $context[
'http'][
'user_agent'] = $version->getUserAgent($ua, $uamask);
763 $context[
'ftp'][
'overwrite'] =
true;
770 if ($FTPOptions[
'enabled'] == 1 && $use_network)
772 $prefix =
'ftp://' . $FTPOptions[
'user'] .
':' . $FTPOptions[
'pass'] .
'@' . $FTPOptions[
'host'];
773 $prefix .= $FTPOptions[
'port'] ?
':' . $FTPOptions[
'port'] :
'';
774 $prefix .= $FTPOptions[
'root'];
776 elseif ($SCPOptions[
'enabled'] == 1 && $use_network)
778 $prefix =
'ssh2.sftp://' . $SCPOptions[
'user'] .
':' . $SCPOptions[
'pass'] .
'@' . $SCPOptions[
'host'];
779 $prefix .= $SCPOptions[
'port'] ?
':' . $SCPOptions[
'port'] :
'';
780 $prefix .= $SCPOptions[
'root'];
784 $prefix = JPATH_ROOT .
'/';
787 $retval =
new JStream($prefix, JPATH_ROOT, $context);
791 $retval =
new JStream(
'',
'', $context);