PageRenderTime 57ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/templates/yoo_master/warp/systems/joomla/helpers/system.php

https://bitbucket.org/organicdevelopment/joomla-2.5
PHP | 201 lines | 99 code | 40 blank | 62 comment | 26 complexity | 3b9b15defc3e1a0840ec22a1f8a9c5ea MD5 | raw file
Possible License(s): LGPL-3.0, GPL-2.0, MIT, BSD-3-Clause, LGPL-2.1
  1. <?php
  2. /**
  3. * @package Warp Theme Framework
  4. * @author YOOtheme http://www.yootheme.com
  5. * @copyright Copyright (C) YOOtheme GmbH
  6. * @license http://www.gnu.org/licenses/gpl.html GNU/GPL
  7. */
  8. /*
  9. Class: SystemWarpHelper
  10. Joomla! system helper class, provides Joomla! 1.7 CMS integration (http://www.joomla.org)
  11. */
  12. class SystemWarpHelper extends WarpHelper {
  13. /* application */
  14. public $application;
  15. /* document */
  16. public $document;
  17. /* language */
  18. public $language;
  19. /* system path */
  20. public $path;
  21. /* system url */
  22. public $url;
  23. /* cache path */
  24. public $cache_path;
  25. /* cache time */
  26. public $cache_time;
  27. /* configuration */
  28. public $config;
  29. /*
  30. Function: Constructor
  31. Class Constructor.
  32. */
  33. public function __construct() {
  34. parent::__construct();
  35. // init vars
  36. $this->application = JFactory::getApplication();
  37. $this->document = JFactory::getDocument();
  38. $this->language = JFactory::getLanguage();
  39. $this->path = JPATH_ROOT;
  40. $this->url = rtrim(JURI::root(false), '/');
  41. $this->cache_path = $this->path.'/cache/template';
  42. $this->cache_time = max(JFactory::getConfig()->getValue('config.cachetime') * 60, 86400);
  43. // set config or load defaults
  44. $file = $this['path']->path('template:config');
  45. $this->config = $this['data']->create(file_get_contents($file ? $file : $this['path']->path('template:config.default')));
  46. // set cache directory
  47. if (!file_exists($this->cache_path)) {
  48. JFolder::create($this->cache_path);
  49. }
  50. }
  51. /*
  52. Function: init
  53. Initialize system configuration
  54. Returns:
  55. Void
  56. */
  57. public function init() {
  58. // set paths
  59. $this['path']->register($this->path.'/administrator', 'admin');
  60. $this['path']->register($this->path, 'site');
  61. $this['path']->register($this->path.'/cache/template', 'cache');
  62. $this['path']->register($this['path']->path('warp:systems/joomla/menus'), 'menu');
  63. // set translations
  64. $this->language->load('tpl_warp', $this['path']->path('warp:systems/joomla'), null, true);
  65. // is site ?
  66. if ($this->application->isSite()) {
  67. // set config
  68. $this->config->set('language', $this->document->language);
  69. $this->config->set('direction', $this->document->direction);
  70. $this->config->set('site_url', rtrim(JURI::root(), '/'));
  71. $this->config->set('site_name', $this->application->getCfg('sitename'));
  72. $this->config->set('datetime', JHTML::_('date', 'now', 'Y-m-d'));
  73. $this->config->set('actual_date', JHTML::_('date', 'now', JText::_('DATE_FORMAT_LC')));
  74. $this->config->set('page_class', trim(preg_replace(array('/columns-(\d+)/', '/columnwidth-(\d+)/'), array('', ''), $this->application->getParams()->get('pageclass_sfx'))));
  75. // IE6 page ?
  76. if ($this['config']->get('ie6page') && $this['browser']->isIE6()) {
  77. $this['event']->bind('render.layouts:template', create_function('&$layout,&$args', '$args["title"] = JText::_("TPL_WARP_IE6_PAGE_TITLE"); $args["error"] = "browser"; $args["message"] = JText::_("TPL_WARP_IE6_PAGE_MESSAGE"); $layout = "layouts:error";'));
  78. }
  79. // mobile theme ?
  80. if ($this['config']->get('mobile') && $this['browser']->isMobile()) {
  81. $this['config']->set('style', 'mobile');
  82. }
  83. // branding ?
  84. if ($this['config']->get('warp_branding')) {
  85. $this['template']->set('warp_branding', $this->warp->getBranding());
  86. }
  87. // set theme style paths
  88. if ($style = $this['config']->get('style')) {
  89. foreach (array('css' => 'template:styles/%s/css', 'js' => 'template:styles/%s/js', 'layouts' => 'template:styles/%s/layouts') as $name => $resource) {
  90. if ($p = $this['path']->path(sprintf($resource, $style))) {
  91. $this['path']->register($p, $name);
  92. }
  93. }
  94. }
  95. }
  96. // is admin ?
  97. if ($this->application->isAdmin()) {
  98. // set paths
  99. $this['path']->register($this['path']->path('warp:config'), 'config');
  100. $this['path']->register($this['path']->path('warp:systems/joomla/config'), 'config');
  101. // get xml's
  102. $tmpl_xml = $this['dom']->create($this['path']->path('template:templateDetails.xml'), 'xml');
  103. $warp_xml = $this['dom']->create($this['path']->path('warp:warp.xml'), 'xml');
  104. // cache writable ?
  105. if (!file_exists($this->cache_path) || !is_writable($this->cache_path)) {
  106. $this->application->enqueueMessage("Cache not writable, please check directory permissions ({$this->cache_path})", 'notice');
  107. }
  108. // update check
  109. if ($url = $warp_xml->first('updateUrl')->text()) {
  110. // create check urls
  111. $urls['tmpl'] = sprintf('%s?application=%s&version=%s&format=raw', $url, $tmpl_xml->first('name')->text().'_j25', $tmpl_xml->first('version')->text());
  112. $urls['warp'] = sprintf('%s?application=%s&version=%s&format=raw', $url, 'warp', $warp_xml->first('version')->text());
  113. foreach ($urls as $type => $url) {
  114. // only check once a day
  115. $hash = md5($url.date('Y-m-d'));
  116. if ($this['option']->get("{$type}_check") != $hash) {
  117. if ($request = $this['http']->get($url)) {
  118. $this['option']->set("{$type}_check", $hash);
  119. $this['option']->set("{$type}_data", $request['body']);
  120. }
  121. }
  122. // decode response and set message
  123. if (($data = json_decode($this['option']->get("{$type}_data"))) && $data->status == 'update-available') {
  124. $this->application->enqueueMessage($data->message, 'notice');
  125. }
  126. }
  127. }
  128. }
  129. }
  130. /*
  131. Function: saveConfig
  132. Returns:
  133. Boolean
  134. */
  135. public function saveConfig() {
  136. // init vars
  137. $config = JRequest::getVar('config', array(), 'post', 'array', JREQUEST_ALLOWRAW);
  138. $config = array_merge($config, array('profile_data' => JRequest::getVar('profile_data', array())));
  139. $config = array_merge($config, array('profile_map' => JRequest::getVar('profile_map', array())));
  140. $file = $this['path']->path('template:').'/config';
  141. $data = $this['data']->create($config);
  142. // save config file
  143. echo json_encode(array('message' => (file_put_contents($file, (string) $data) ? 'success' : 'failed')));
  144. }
  145. /*
  146. Function: isBlog
  147. Returns:
  148. Boolean
  149. */
  150. public function isBlog() {
  151. if (JRequest::getCmd('option') == 'com_content') {
  152. if (in_array(JRequest::getCmd('view'), array('frontpage', 'article', 'archive', 'featured')) || (JRequest::getCmd('view') == 'category' && JRequest::getCmd('layout') == 'blog')) {
  153. return true;
  154. }
  155. }
  156. return false;
  157. }
  158. }