PageRenderTime 354ms CodeModel.GetById 116ms app.highlight 10ms RepoModel.GetById 96ms app.codeStats 50ms

/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
  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/*
 10	Class: SystemWarpHelper
 11		Joomla! system helper class, provides Joomla! 1.7 CMS integration (http://www.joomla.org)
 12*/
 13class SystemWarpHelper extends WarpHelper {
 14
 15	/* application */
 16	public $application;
 17
 18	/* document */
 19	public $document;
 20
 21	/* language */
 22	public $language;
 23
 24	/* system path */
 25	public $path;
 26
 27	/* system url */
 28	public $url;
 29
 30	/* cache path */
 31	public $cache_path;
 32
 33	/* cache time */
 34	public $cache_time;
 35
 36	/* configuration */
 37	public $config;
 38	
 39	/*
 40		Function: Constructor
 41			Class Constructor.
 42	*/
 43	public function __construct() {
 44		parent::__construct();		
 45
 46		// init vars
 47		$this->application = JFactory::getApplication();
 48        $this->document    = JFactory::getDocument();
 49		$this->language    = JFactory::getLanguage();
 50        $this->path        = JPATH_ROOT;
 51        $this->url         = rtrim(JURI::root(false), '/');
 52        $this->cache_path  = $this->path.'/cache/template';
 53        $this->cache_time  = max(JFactory::getConfig()->getValue('config.cachetime') * 60, 86400);
 54
 55		// set config or load defaults
 56		$file = $this['path']->path('template:config');
 57		$this->config = $this['data']->create(file_get_contents($file ? $file : $this['path']->path('template:config.default')));
 58
 59		// set cache directory
 60		if (!file_exists($this->cache_path)) {
 61			JFolder::create($this->cache_path);
 62		}
 63	}
 64
 65	/*
 66		Function: init
 67			Initialize system configuration
 68
 69		Returns:
 70			Void
 71	*/
 72	public function init() {
 73
 74		// set paths
 75        $this['path']->register($this->path.'/administrator', 'admin');
 76        $this['path']->register($this->path, 'site');
 77        $this['path']->register($this->path.'/cache/template', 'cache');
 78		$this['path']->register($this['path']->path('warp:systems/joomla/menus'), 'menu');
 79
 80		// set translations
 81		$this->language->load('tpl_warp', $this['path']->path('warp:systems/joomla'), null, true);
 82		
 83		// is site ?
 84		if ($this->application->isSite()) {
 85
 86			// set config
 87			$this->config->set('language', $this->document->language); 
 88			$this->config->set('direction', $this->document->direction); 
 89			$this->config->set('site_url', rtrim(JURI::root(), '/'));
 90			$this->config->set('site_name', $this->application->getCfg('sitename'));
 91			$this->config->set('datetime', JHTML::_('date', 'now', 'Y-m-d'));			
 92			$this->config->set('actual_date', JHTML::_('date', 'now', JText::_('DATE_FORMAT_LC')));
 93			$this->config->set('page_class', trim(preg_replace(array('/columns-(\d+)/', '/columnwidth-(\d+)/'), array('', ''), $this->application->getParams()->get('pageclass_sfx')))); 
 94
 95			// IE6 page ?
 96			if ($this['config']->get('ie6page') && $this['browser']->isIE6()) {
 97				$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";'));
 98			}
 99
100			// mobile theme ?
101			if ($this['config']->get('mobile') && $this['browser']->isMobile()) {
102				$this['config']->set('style', 'mobile');
103			}
104
105			// branding ?
106			if ($this['config']->get('warp_branding')) {
107				$this['template']->set('warp_branding', $this->warp->getBranding());
108			}
109
110			// set theme style paths
111			if ($style = $this['config']->get('style')) {
112				foreach (array('css' => 'template:styles/%s/css', 'js' => 'template:styles/%s/js', 'layouts' => 'template:styles/%s/layouts') as $name => $resource) {
113					if ($p = $this['path']->path(sprintf($resource, $style))) {
114						$this['path']->register($p, $name);
115					}
116				}
117			}
118        }
119		
120		// is admin ?
121		if ($this->application->isAdmin()) {
122
123			// set paths
124	        $this['path']->register($this['path']->path('warp:config'), 'config');
125	        $this['path']->register($this['path']->path('warp:systems/joomla/config'), 'config');
126
127			// get xml's
128			$tmpl_xml = $this['dom']->create($this['path']->path('template:templateDetails.xml'), 'xml');
129			$warp_xml = $this['dom']->create($this['path']->path('warp:warp.xml'), 'xml');
130
131			// cache writable ?
132			if (!file_exists($this->cache_path) || !is_writable($this->cache_path)) {
133				$this->application->enqueueMessage("Cache not writable, please check directory permissions ({$this->cache_path})", 'notice');
134			}			
135
136			// update check
137			if ($url = $warp_xml->first('updateUrl')->text()) {
138
139				// create check urls
140				$urls['tmpl'] = sprintf('%s?application=%s&version=%s&format=raw', $url, $tmpl_xml->first('name')->text().'_j25', $tmpl_xml->first('version')->text());
141				$urls['warp'] = sprintf('%s?application=%s&version=%s&format=raw', $url, 'warp', $warp_xml->first('version')->text());
142
143				foreach ($urls as $type => $url) {
144
145					// only check once a day 
146					$hash = md5($url.date('Y-m-d'));
147					if ($this['option']->get("{$type}_check") != $hash) {
148						if ($request = $this['http']->get($url)) {
149							$this['option']->set("{$type}_check", $hash);
150							$this['option']->set("{$type}_data", $request['body']);
151						}
152					}
153
154					// decode response and set message
155					if (($data = json_decode($this['option']->get("{$type}_data"))) && $data->status == 'update-available') {
156						$this->application->enqueueMessage($data->message, 'notice');
157					}
158
159				}
160			}
161		}
162		
163	}
164
165	/*
166		Function: saveConfig
167
168		Returns:
169			Boolean
170	*/
171	public function saveConfig() {
172
173		// init vars
174		$config = JRequest::getVar('config', array(), 'post', 'array', JREQUEST_ALLOWRAW);
175		$config = array_merge($config, array('profile_data' => JRequest::getVar('profile_data', array())));
176		$config = array_merge($config, array('profile_map' => JRequest::getVar('profile_map', array())));
177		$file   = $this['path']->path('template:').'/config';
178		$data   = $this['data']->create($config);
179
180		// save config file
181		echo json_encode(array('message' => (file_put_contents($file, (string) $data) ? 'success' : 'failed')));
182	}
183
184	/*
185		Function: isBlog
186
187		Returns:
188			Boolean
189	*/
190	public function isBlog() {
191
192		if (JRequest::getCmd('option') == 'com_content') {
193			if (in_array(JRequest::getCmd('view'), array('frontpage', 'article', 'archive', 'featured')) || (JRequest::getCmd('view') == 'category' && JRequest::getCmd('layout') == 'blog')) {
194				return true;
195			}
196		}
197
198		return false;
199	}
200
201}