PageRenderTime 52ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/kraymitchell/apex
PHP | 211 lines | 105 code | 43 blank | 63 comment | 35 complexity | 1cd259c2492d33a1bbc1baa96455e25e MD5 | raw file
Possible License(s): GPL-2.0, LGPL-3.0, BSD-3-Clause, LGPL-2.1, GPL-3.0
  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. // Outdated Browser page ?
  76. if (($this['config']->get('ie6page') && $this['browser']->isIE6()) || ($this['config']->get('outdated_browser') && $this['browser']->outdatedBrowser())) {
  77. $this['event']->bind('render.layouts:template', create_function('&$layout,&$args', '$args["title"] = JText::_("TPL_WARP_OUTDATEDBROWSER_PAGE_TITLE"); $args["error"] = "browser"; $args["message"] = JText::_("TPL_WARP_OUTDATEDBROWSER_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. //force show system output on search results
  96. if (strtolower(JRequest::getVar('option')) == "com_search") {
  97. $this['config']->set('system_output', 1);
  98. }
  99. }
  100. // is admin ?
  101. if ($this->application->isAdmin()) {
  102. // set paths
  103. $this['path']->register($this['path']->path('warp:config'), 'config');
  104. $this['path']->register($this['path']->path('warp:systems/joomla/config'), 'config');
  105. // get xml's
  106. $tmpl_xml = $this['dom']->create($this['path']->path('template:templateDetails.xml'), 'xml');
  107. $warp_xml = $this['dom']->create($this['path']->path('warp:warp.xml'), 'xml');
  108. // cache writable ?
  109. if (!file_exists($this->cache_path) || !is_writable($this->cache_path)) {
  110. $this->application->enqueueMessage("Cache not writable, please check directory permissions ({$this->cache_path})", 'notice');
  111. }
  112. // update check
  113. if ($url = $warp_xml->first('updateUrl')->text()) {
  114. // create check urls
  115. $urls['tmpl'] = sprintf('%s?application=%s&version=%s&format=raw', $url, $tmpl_xml->first('name')->text().'_j25', $tmpl_xml->first('version')->text());
  116. $urls['warp'] = sprintf('%s?application=%s&version=%s&format=raw', $url, 'warp', $warp_xml->first('version')->text());
  117. foreach ($urls as $type => $url) {
  118. // only check once a day
  119. $hash = md5($url.date('Y-m-d'));
  120. if ($this['option']->get("{$type}_check") != $hash) {
  121. if ($request = $this['http']->get($url)) {
  122. $this['option']->set("{$type}_check", $hash);
  123. $this['option']->set("{$type}_data", $request['body']);
  124. }
  125. }
  126. // decode response and set message
  127. if (($data = json_decode($this['option']->get("{$type}_data"))) && $data->status == 'update-available') {
  128. $this->application->enqueueMessage($data->message, 'notice');
  129. }
  130. }
  131. }
  132. }
  133. }
  134. /*
  135. Function: saveConfig
  136. Returns:
  137. Boolean
  138. */
  139. public function saveConfig() {
  140. // init vars
  141. $config = JRequest::getVar('config', array(), 'post', 'array', JREQUEST_ALLOWRAW);
  142. $config = array_merge($config, array('profile_data' => JRequest::getVar('profile_data', array())));
  143. $config = array_merge($config, array('profile_map' => JRequest::getVar('profile_map', array())));
  144. $file = $this['path']->path('template:').'/config';
  145. $data = $this['data']->create($config);
  146. // save config file
  147. echo json_encode(array('message' => (file_put_contents($file, (string) $data) ? 'success' : 'failed')));
  148. }
  149. /*
  150. Function: isBlog
  151. Returns:
  152. Boolean
  153. */
  154. public function isBlog() {
  155. if (JRequest::getCmd('option') == 'com_content') {
  156. if (in_array(JRequest::getCmd('view'), array('frontpage', 'article', 'archive', 'featured')) || (JRequest::getCmd('view') == 'category' && JRequest::getCmd('layout') == 'blog')) {
  157. return true;
  158. }
  159. }
  160. if (JRequest::getCmd('option') == 'com_zoo' && !in_array(JRequest::getCmd('task'), array('submission', 'mysubmissions')) && $app = App::getInstance('zoo')->zoo->getApplication() and $app->getGroup() == 'blog') {
  161. return true;
  162. }
  163. return false;
  164. }
  165. }