PLS FIND SYNTAX ERROR AND CORRECT THE ERROR
<?php
/*
# ------------------------------------------------------------------------
# JA T3v2 Plugin - Template framework for Joomla 1.5
# ------------------------------------------------------------------------
# Copyright (C) 2004-2010 JoomlArt.com. All Rights Reserved.
# @license - GNU/GPL V2, http://www.gnu.org/licenses/gpl2.html. For details
# on licensing, Please Read Terms of Use at http://www.joomlart.com/terms_of_use.html.
# Author: JoomlArt.com
# Websites: http://www.joomlart.com - http://www.joomlancers.com.
# ------------------------------------------------------------------------
*/
function t3import ($object) {
$object = str_replace( '.', DS, $object );
$path = dirname(dirname(__FILE__)).DS.$object.'.php';
if (file_exists ($path)) require_once ($path);
}
function t3_import ($object) {
$path = dirname(dirname(__FILE__)).DS.$object.'.php';
if (file_exists ($path)) require_once ($path);
}
class T3Common {
//Detect a template is T3 based
function detect_ ($template = '') {
static $ist3 = array();
if (!$template) {
$template = T3Common::get_active_template();
}
if (isset ($ist3[$template])) {
return;
}
$ist3[$template] = false;
$path = JPATH_SITE.DS.'templates'.DS.$template.DS.'templateDetails.xml';
if (is_file ($path)) {
$xml = & JFactory::getXMLParser('Simple');
if ($xml->loadFile($path))
{
if (($templateinfo = & $xml->document) && isset($templateinfo->engine) && trim($templateinfo->engine[0]->_data=='t3')) {
$ist3[$template] = true;
}
}
}
return $ist3[$template];
}
function detect ($template = '') {
if (!$template) {
$template = T3Common::get_active_template();
}
$path = JPATH_SITE.DS.'templates'.DS.$template.DS.'core'.DS.'themes'.DS.'default'.DS.'info.xml';
return is_file ($path);
}
function get_active_template () {
global $mainframe;
return $mainframe->getTemplate();
}
function getinfo ($info, $name, $default=null){
if (isset ($info) && isset($info[$name])) return $info[$name];
return $default;
}
//Merge multi-dimension array
function merge_array ($arr1, $arr2) {
foreach( $arr1 as $k => $v ) {
if (isset($arr2[$k])) {
if (is_array($arr1[$k]) && is_array($arr2[$k])) {
$arr2[$k] = T3Common::merge_array ($arr1[$k], $arr2[$k]);
}
} else {
$arr2[$k] = $arr1[$k];
}
}
return $arr2;
}
function xml_find_element ($element, $name, $attr='', $value='') {
if (!$element || !isset ($element->{$name}) || !count ($element->{$name})) return null;
if (!$attr) return $element->{$name}[0]; //get the first match
for ($j=0,$m=count($element->{$name});$j<$m;$j++) {
$node = $element->{$name}[$j];
if ($node->attributes ($attr) == $value) {
$node->_index = $j;
return $node;
}
}
return null;
}
function merge_xml (& $element1, & $element2) {
for ($i=0,$n=count($element1->_children);$i<$n;$i++)
{
$child1 = $element1->_children[$i];
$name = $child1->name();
if ($name == 'blocks') {
$child2 = T3Common::xml_find_element ($element2, 'blocks', 'name', $child1->attributes('name'));
if (!$child2) {
//Add child1 into element2
$element2->{$name}[] = $child1;
//Add the reference to the children array member
$element2->_children[] = $child1;
}
} else {
$child2 = null;
if ($child1->attributes('name')) $child2 = T3Common::xml_find_element ($element2, $name, 'name', $child1->attributes('name'));
else $child2 = T3Common::xml_find_element ($element2, $name);
if (!isset($child1->_children) || !count($child1->_children) || !$child2) {
//$element2->{$name} = array();
//Add child1 into element2
$element2->{$name}[] = $child1;
//Add the reference to the children array member
$element2->_children[] = $child1;
} else {
$element2->{$name}[isset($child2->_index)?$child2->_index:0] = T3Common::merge_xml ($child1, $child2);
}
}
}
return $element2;
}
function mobile_device_detect_ () {
$ui = T3Parameter::_getParam('ui');
//detect mobile
t3import ('core.libs.mobile_device_detect');
//bypass special browser:
$special = array('jigs', 'w3c ', 'w3c-', 'w3c_');
if (in_array(strtolower(substr($_SERVER['HTTP_USER_AGENT'],0,4)), $special)) $mobile_device = false;
else $mobile_device = mobile_device_detect('iphone','android','opera','blackberry','palm','windows');
return $ui=='desktop'?false:(($ui=='mobile' && !$mobile_device)?'iphone':$mobile_device);
}
function mobile_device_detect () {
$ui = T3Parameter::_getParam('ui');
if ($ui=='desktop') return false;
//detect mobile
t3import ('core.libs.Browser');
$browser = new Browser();
//bypass
if ($browser->isRobot()) return false;
//mobile
if ($browser->isMobile()) {
if (in_array($browser->getBrowser(), array(Browser::BROWSER_IPHONE, Browser::BROWSER_IPOD, Browser::BROWSER_SAFARI)));
$device = 'iphone';
else
$device = strtolower($browser->getBrowser());
//$device = 'handheld';
$layout = T3Parameter::get ($device."_layout", '');
if ($layout == -1) return false; //disable
return $device;
//return 'handheld';
}
//Not mobile
if ($ui=='mobile') return 'iphone'; //default for mobile layout on desktop
return false;
}
function get_theme_info ($theme) {
static $theme_infos = array();
if (!isset($theme_infos[$theme[0].'.'.$theme[1]])) {
$theme_infos[$theme[0].'.'.$theme[1]] = null;
if ($theme[0] == 'engine') {
$theme_info_path = T3_ROOT.DS.'base-themes'.DS.$theme[1].DS.'info.xml';
} else {
$theme_info_path = T3_TEMPLATE_ROOT.DS.$theme[0].DS.'themes'.DS.$theme[1].DS.'info.xml';
}
if (!is_file ($theme_info_path)) return null;
$xml = & JFactory::getXMLParser('Simple');
if ($xml->loadFile($theme_info_path))
{
if ($theme_info = & $xml->document) {
$theme_infos[$theme[0].'.'.$theme[1]] = $theme_info;
}
}
}
return $theme_infos[$theme[0].'.'.$theme[1]];
}
function profile_exists ($profile) {
if (!$profile) return false;
$path = 'etc'.DS.'profiles'.DS.$profile.'.ini';
if (is_file (T3_LOCAL_ROOT.DS.$path)) return T3_LOCAL_ROOT.DS.$path;
if (is_file (T3_CORE_ROOT.DS.$path)) return T3_CORE_ROOT.DS.$path;
return false;
}
function layout_exists ($layout) {
if (!$layout) return false;
$path = 'etc'.DS.'layouts'.DS.$layout.'.xml';
if (is_file (T3_LOCAL_ROOT.DS.$path)) return T3_LOCAL_ROOT.DS.$path;
if (is_file (T3_CORE_ROOT.DS.$path)) return T3_CORE_ROOT.DS.$path;
if (is_file (T3_ROOT.DS.'base-themes'.DS.T3_BASE_THEME.DS.DS.$path)) return T3_ROOT.DS.'base-themes'.DS.T3_BASE_THEME.DS.DS.$path;
return false;
}
function get_layout_info ($layout = '') {
static $layout_infos = array();
$params = T3Common::get_template_params ();
$device = T3Common::mobile_device_detect();
if (!$layout) {
$layout = T3Common::get_active_layout();
}
if (!T3Common::layout_exists ($layout)) {
if (!$device) { //desktop
$layout = $params->get ('desktop_layout', '');
if (!T3Common::layout_exists ($layout)) $layout = 'default';
} else {
$layout = $params->get ($device.'_layout', '');
if (!T3Common::layout_exists ($layout)) $layout = $params->get ('handheld_layout', '');
if ($layout == 0) { //disable => use layout from desktop
$device = '';
$layout = $params->get ('desktop_layout', '');
if (!T3Common::layout_exists ($layout)) $layout = 'default';
} else if ($layout == 1) { //default => use layout from t3 engine
$layout = $device;
if (!T3Common::layout_exists ($layout)) $layout = 'handheld';
} else if (!T3Common::layout_exists ($layout)) {
$layout = 'handheld';
}
}
}
//if (!$layout) $layout = 'default';
if (!isset($layout_infos[$layout])) {
$layout_infos[$layout] = null;
$active_layout_path = T3Common::layout_exists ($layout);
$default_layout_path = '';
$engine_layout_path = '';
if (!$device) {
$default_layout_path = T3Common::layout_exists ('default');
$engine_layout_path = T3_ROOT.DS.'base-themes'.DS.T3_BASE_THEME.DS.'etc'.DS.'layouts'.DS.'default.xml';
} else {
$default_layout_path = T3Common::layout_exists ($device);
if (!$default_layout_path) $default_layout_path = T3Common::layout_exists ('handheld');
$engine_layout_path = T3_ROOT.DS.'base-themes'.DS.T3_BASE_THEME.DS.'etc'.DS.'layouts'.DS.$device.'.xml';
if (!is_file($engine_layout_path)) $engine_layout_path = T3_ROOT.DS.'base-themes'.DS.T3_BASE_THEME.DS.'etc'.DS.'layouts'.DS.'handheld.xml';
}
$layout_info = null;
if (is_file ($active_layout_path)) {
$xml = & JFactory::getXMLParser('Simple');
if ($xml->loadFile($active_layout_path)) {
$layout_info = & $xml->document;
}
}
if ($default_layout_path != $active_layout_path && is_file ($default_layout_path)) {
$xml = & JFactory::getXMLParser('Simple');
if ($xml->loadFile($default_layout_path)) {
$layout_info = $layout_info? T3Common::merge_xml ($xml->document, $layout_info):$xml->document;
}
}
if ($engine_layout_path != $default_layout_path && $engine_layout_path != $active_layout_path && is_file ($engine_layout_path)) {
$xml = & JFactory::getXMLParser('Simple');
if ($xml->loadFile($engine_layout_path)) {
$layout_info = $layout_info? T3Common::merge_xml ($xml->document, $layout_info):$xml->document;
}
}
$layout_infos[$layout] = $layout_info;
}
return $layout_infos[$layout];
}
function get_active_layout () {
//return T3Parameter::_getParam('layouts');
$params = T3Common::get_template_params ();
$device = T3Common::mobile_device_detect();
$layout = T3Parameter::get ('layouts', '');
if (T3Common::layout_exists ($layout)) return $layout;
if (!$device) { //desktop
$layout = $params->get ('desktop_layout', '');
if (!T3Common::layout_exists ($layout)) $layout = 'default';
} else {
$layout = $params->get ($device.'_layout', '');
if (!$layout) $layout = $params->get ('handheld_layout', '');
if ($layout == -1) { //disable => use layout from desktop
$device = '';
$layout = $params->get ('desktop_layout', '');
if (!T3Common::layout_exists ($layout)) $layout = 'default';
} else if ($layout == 1) { //default => use layout from t3 engine
$layout = $device;
if (!T3Common::layout_exists ($layout)) $layout = 'handheld';
} else if (!T3Common::layout_exists ($layout)) {
$layout = 'handheld';
}
}
return $layout;
}
function get_layouts ($layout = '') {
//get from preload object
$layouts = T3Preload::getObject ('layout-infos');
if ($layouts) {
if ($layout) {
if (isset ($layouts[$layout])) return $layouts[$layout];
$layouts[$layout] = T3Common::get_layout_info ($layout);
T3Preload::setObject ('layout-infos', $layouts);
return $layouts[$layout];
} else return $layouts;
}
//cannot get from preload object, get direct from template
$path = T3_LOCAL_ROOT;
$local_layouts = is_dir (T3_LOCAL_ROOT.DS.'etc'.DS.'layouts')?@ JFolder::files (T3_LOCAL_ROOT.DS.'etc'.DS.'layouts', '.xml$'):null;
$core_layouts = is_dir (T3_CORE_ROOT.DS.'etc'.DS.'layouts')?@ JFolder::files (T3_CORE_ROOT.DS.'etc'.DS.'layouts', '.xml$'):null;
if (!$local_layouts && !$core_layouts) return array();
if ($local_layouts && $core_layouts) $layouts = array_merge ($core_layouts, $local_layouts);
else if ($local_layouts) $layouts = $local_layouts;
else $layouts = $core_layouts;
$_layouts = array();
$_layouts ['default'] = null;
foreach ($layouts as $layout) {
$layout = preg_replace ('/\.xml$/', '', $layout);
$_layouts[$layout] = T3Common::get_layout_info($layout);
}
return $_layouts;
}
function get_profiles () {
$path = T3_LOCAL_ROOT;
$local_profiles = is_dir (T3_LOCAL_ROOT.DS.'etc'.DS.'profiles')?@ JFolder::files (T3_LOCAL_ROOT.DS.'etc'.DS.'profiles', '.ini$'):array();
$core_profiles = is_dir (T3_CORE_ROOT.DS.'etc'.DS.'profiles')?@ JFolder::files (T3_CORE_ROOT.DS.'etc'.DS.'profiles', '.ini$'):array();
$_profiles = array_merge ($core_profiles, $local_profiles);
$profiles = array();
foreach ($_profiles as $profile) {
$profile = substr ($profile, 0, -4);
$profiles[$profile] = $profile;
}
return $profiles;
}
function get_themes ($theme='') {
$themes = T3Preload::getObject ('theme-infos');
if ($themes) {
if ($theme) {
if (isset ($themes[$theme])) return $themes[$theme];
$themes[$theme] = T3Common::get_theme_info(preg_split ('/\./', $theme, 2));
//T3Preload::setObject ('theme-infos', $themes);
return $themes[$theme];
} else return $themes;
}
$themes["engine.default"] = T3Common::get_theme_info(array('engine','default'));
$themes["core.default"] = null;
$core_themes = is_dir(T3_CORE_ROOT.DS.'themes')?@ JFolder::folders (T3_CORE_ROOT.DS.'themes'):null;
if ($core_themes) {
foreach ($core_themes as $theme) {
$themes["core.$theme"] = T3Common::get_theme_info(array('core',$theme));
}
}
$local_themes = is_dir(T3_LOCAL_ROOT.DS.'themes')?@ JFolder::folders (T3_LOCAL_ROOT.DS.'themes'):null;
if ($local_themes) {
foreach ($local_themes as $theme) {
$themes["local.$theme"] = T3Common::get_theme_info(array('local',$theme));
}
}
return $themes;
}
function get_active_themes () {
static $_themes = null;
if (!isset($_themes)) {
global $Itemid;
$_themes = array();
$themes = T3Parameter::_getParam('themes');
// if (!$themes) {
// $params = T3Common::get_template_params ();
// $themes = $params->get ('themes');
// }
//active themes
$themes = preg_split ('/,/', $themes);
$hasdefault = false;
for ($i=0;$i<count($themes);$i++) {
$themes[$i] = trim($themes[$i]);
$theme = array();
if (preg_match ('/^(local)\.(.*)$/', $themes[$i], $matches)) {
$theme[0] = $matches[1];
$theme[1] = $matches[2];
//$themes[$i] = array('local', $matches[1]);
} else if (preg_match ('/^(core)\.(.*)$/', $themes[$i], $matches)) {
$theme[0] = $matches[1];
$theme[1] = $matches[2];
//$themes[$i] = array('core', $matches[1]);
} else {
$theme[0] = 'core';
$theme[1] = $themes[$i];
//$themes[$i] = array('core', $themes[$i]);
}
if ($theme[1] && is_dir (T3_TEMPLATE_ROOT.DS.$theme[0].DS.'themes'.DS.$theme[1])) {
$_themes[] = $theme;
if ($theme[0] == 'core' && $theme[1] == 'default') $hasdefault = true;
}
}
if (!$hasdefault) $_themes[] = array('core', 'default');
}
return $_themes;
}
function get_template_based_params () {
static $params = null;
if ($params) return $params;
$content = '';
$file = T3_TEMPLATE_ROOT.DS.'params.ini';
if (is_file ($file)) $content = file_get_contents($file);
$params = new JParameter($content);
return $params;
}
function get_template_params () {
static $params = null;
if (!isset ($params)) {
$profile = T3Common::get_active_profile ();
//Load global params
$content = '';
$file = T3_TEMPLATE_ROOT.DS.'params.ini';
if (is_file ($file)) $content = file_get_contents($file);
//Load default profile setting
$path = 'etc'.DS.'profiles'.DS.'default.ini';
$file = T3_LOCAL_ROOT.DS.$path;
if (!is_file ($file)) $file = T3_CORE_ROOT.DS.$path;
if (is_file ($file)) {
$content .= "\n".file_get_contents ($file);
}
//Load override profile setting
if ($profile != 'default') {
$path = 'etc'.DS.'profiles'.DS.$profile.'.ini';
$file = T3_LOCAL_ROOT.DS.$path;
if (!is_file ($file)) $file = T3_CORE_ROOT.DS.$path;
if (is_file ($file)) {
$content .= "\n".file_get_contents ($file);
}
}
$params = new JParameter ($content);
//T3Cache::store(serialize($params), $key);
}
return $params;
}
function get_active_profile () {
static $profile = null;
if ($profile) return $profile;
//Get active profile from user setting
$k = 'profile';
$kc = T3_ACTIVE_TEMPLATE."_".$k;
if (($profile = JRequest::getVar($k, null, 'GET')) && T3Common::profile_exists ($profile)) {
$exp = time() + 60*60*24*355;
setcookie ($kc, $profile, $exp, '/');
return $profile;
}if (($profile = JRequest::getVar($kc, '', 'COOKIE')) && T3Common::profile_exists ($profile)) {
return $profile;
}
$params = T3Common::get_template_based_params();
$pages_profile = $params->get ('pages_profile');
$profile = '';
//Get profile by component name(such as com_content)
$comname = JRequest::getCmd( 'option' );
if ($comname) {
$regex = '/(^|,|\>|\n)\s*'.$comname.'\s*(,[^=]*)?=([^\<\n]*)/';
if (preg_match ($regex, $pages_profile, $matches)) {
$profile = $matches[3];
if (T3Common::profile_exists ($profile)) return $profile;
}
}
//Get active profile by pages
global $Itemid;
$menu = &JSite::getMenu();
$menuid = $Itemid;
while ($menuid && !$profile) {
$regex = '/(^|,|\>|\n)\s*'.$menuid.'(,[^=]*)?=([^\<\n]*)/';
if (preg_match ($regex, $pages_profile, $matches)) {
$profile = $matches[3];
if (T3Common::profile_exists ($profile)) return $profile;
}
$menuitem = $menu->getItem ($menuid);
$menuid = ($menuitem && isset ($menuitem->parent)) ? $menuitem->parent:0;
}
//Get profile by page name (such as home)
if (JRequest::getCmd( 'view' ) == 'frontpage') {
$regex = '/(^|,|\>|\n)\s*home(,[^=]*)?=([^\<\n]*)/';
if (preg_match ($regex, $pages_profile, $matches)) {
$profile = $matches[3];
if (T3Common::profile_exists ($profile)) return $profile;
}
}
//Get default profile
$default_profile = '';
$regex = '/(^|,|\>|\n)all(,[^=]*)?=([^\<\n]*)/';
if (preg_match ($regex, $pages_profile, $matches)) {
$default_profile = $matches[3];
}
if (!$profile) $profile = $default_profile; //use default profile which is set for all pages
if (!$profile || !T3Common::profile_exists ($profile)) $profile = 'default';
return $profile;
}
function get_active_themes_info () {
global $mainframe;
//$key = T3Parameter::getKey ('themes-info',2);
$key = T3Cache::getThemeKey();
$themes_info = T3Cache::get_object ($key); //force cache
if ($themes_info && isset ($themes_info->layout) && $themes_info->layout) {
return $themes_info;
}
$themes = T3Common::get_active_themes();
$themes[] = array('engine', 'default');
$themes_info = null;
foreach ($themes as $theme) {
$theme_info = T3Common::get_themes (implode('.', $theme));
if (!$theme_info) continue;
if (!$themes_info) $themes_info = $theme_info;
else {
//merge info
$themes_info = T3Common::merge_xml ($theme_info, $themes_info);
}
}
//Get layout if tmpl is not component
$themes_info->layout = null;
$tmpl = JRequest::getCmd ('tmpl');
if ($tmpl != 'component') {
$themes_info->layout = T3Common::get_layout_info();
}
T3Cache::store_object($themes_info, $key);
return $themes_info;
}
function get_browser () {
$agent = $_SERVER['HTTP_USER_AGENT'];
if ( strpos($agent, 'Gecko') )
{
if ( strpos($agent, 'Netscape') )
{
$browser = 'NS';
}
else if ( strpos($agent, 'Firefox') )
{
$browser = 'FF';
}
else
{
$browser = 'Moz';
}
}
else if ( strpos($agent, 'MSIE') && !preg_match('/opera/i',$agent) )
{
$msie='/msie\s(7|8\.[0-9]).*(win)/i';
if (preg_match($msie,$agent)) $browser = 'IE7';
else $browser = 'IE6';
}
else if ( preg_match('/opera/i',$agent) )
{
$browser = 'OPE';
}
else
{
$browser = 'Others';
}
return $browser;
}
function createObject ($class, $args) {
$object = new $class ('');
foreach ($args as $key=>$value) {
$object->$key = $value;
}
return $object;
}
function getBrowserSortName () {
t3import ('core.libs.Browser');
$browser = new Browser();
$bname = $browser->getBrowser();
switch ($bname) {
case Browser::BROWSER_IE:
return 'ie';
case Browser::BROWSER_POCKET_IE:
return 'pie';
case Browser::BROWSER_FIREFOX:
return 'ff';
case Browser::BROWSER_OPERA:
return 'op';
case Browser::BROWSER_OPERA_MINI:
return 'mop';
case Browser::BROWSER_MOZILLA:
return 'moz';
case Browser::BROWSER_KONQUEROR:
return 'kon';
case Browser::BROWSER_CHROME:
return 'chr';
default:
return strtolower(str_replace (' ', '-', $bname));
}
}
function getBrowserMajorVersion () {
t3import ('core.libs.Browser');
$browser = new Browser();
$bver = explode ('.', $browser->getVersion());
return $bver[0]; //Major version only
}
function isRTL () {
$tmpl = T3Template::getInstance ();
return ($tmpl->direction == 'rtl' || $tmpl->getParam ('direction', 'ltr')=='rtl');
}
}


