getTemplate(true); $template = get_object_vars($template); } else { $q = 'SELECT id, home, template, s.params FROM #__template_styles as s LEFT JOIN #__extensions as e ON e.element=s.template AND e.type="template" AND e.client_id=s.client_id WHERE s.client_id = '.$client_id.' AND e.enabled = 1 AND s.home = 1'; $db = JFactory::getDbo(); $db->setQuery( $q ); $template = $db->loadAssoc(); $template['params'] = new Registry($template['params']); } if(!$template){ vmError( 'getDefaultTemplate failed ' ); return false; } else { self::$_home[$client_id] = $template; self::$_templates[$template['id']] = $template; return self::$_templates[$template['id']]; } } public static function getTemplateById($id) { if(!isset(self::$_templates[$id])){ $q = 'SELECT * FROM `#__template_styles` WHERE `id`="' . $id . '" '; $db = JFactory::getDbo(); $db->setQuery($q); self::$_templates[$id] = $db->loadAssoc(); if(!self::$_templates[$id]) { vmError( 'getTemplateById get Template failed for id: ' . $id ); } } return self::$_templates[$id]; } /** * This function sets the right template on the view * @author Max Milbers */ static function setVmTemplate ($view, $catTpl = 0, $prodTpl = 0, $catLayout = 0, $prodLayout = 0) { //Lets get here the template set in the shopconfig, if there is nothing set, get the joomla standard $template = VmConfig::get( 'vmtemplate', 0 ); $db = JFactory::getDBO(); //Set specific category template if(!empty($catTpl) && empty($prodTpl)) { if(is_Int( $catTpl )) { $q = 'SELECT `category_template` FROM `#__virtuemart_categories` WHERE `virtuemart_category_id` = "'.(int)$catTpl.'" '; $db->setQuery( $q ); $temp = $db->loadResult(); if(!empty($temp)) $template = $temp; } else { $template = $catTpl; } } //Set specific product template if(!empty($prodTpl)) { if(is_Int( $prodTpl )) { $q = 'SELECT `product_template` FROM `#__virtuemart_products` WHERE `virtuemart_product_id` = "'.(int)$prodTpl.'" '; $db->setQuery( $q ); $temp = $db->loadResult(); if(!empty($temp)) $template = $temp; } else { $template = $prodTpl; } } if( (!empty($template) and $template!='default') or !vmConfig::isSiteByApp()){ self::setTemplate( $template ); } //Lets get here the layout set in the shopconfig, if there is nothing set, get the joomla standard if(vRequest::getCmd( 'view' ) == 'virtuemart') { $layout = VmConfig::get( 'vmlayout', 'default' ); $view->setLayout( strtolower( $layout ) ); } else { if(empty($catLayout) and empty($prodLayout)) { $catLayout = VmConfig::get( 'productlayout', 'default' ); } //Set specific category layout if(!empty($catLayout) && empty($prodLayout)) { if(is_Int( $catLayout )) { $q = 'SELECT `layout` FROM `#__virtuemart_categories` WHERE `virtuemart_category_id` = "'.(int)$catLayout.'" '; $db->setQuery( $q ); $temp = $db->loadResult(); if(!empty($temp)) $layout = $temp; } else { $layout = $catLayout; } } //Set specific product layout if(!empty($prodLayout)) { if(is_Int( $prodLayout )) { $q = 'SELECT `layout` FROM `#__virtuemart_products` WHERE `virtuemart_product_id` = "'.(int)$prodLayout.'" '; $db->setQuery( $q ); $temp = $db->loadResult(); if(!empty($temp)) $layout = $temp; } else { $layout = $prodLayout; } } } if(!empty($layout)) { $view->setLayout( strtolower( $layout ) ); } } /** * Final setting of template * Accepts a string, an id or an array with at least the keys template and params * @author Max Milbers */ static function setTemplate ($template = 0) { $res = false; if(is_array($template)){ $res = $template; } else { if(empty($template) or $template == 'default'){ $res = self::loadVmTemplateStyle(); } else { if(is_numeric($template)){ $res = self::getTemplateById($template); } else { vmAdminInfo('Your template settings are old, please check your template settings in the vm config and in your categories'); vmdebug('Your template settings are old, please check your template settings in the vm config and in your categories'); } } } $registry = null; if($res){ $registry = new JRegistry; $registry->loadString($res['params']); $template = $res['template']; } if(is_dir( VMPATH_ROOT .'/templates/'.$template )) { $app = JFactory::getApplication(); if(VmConfig::isSiteByApp()) { $currentTemplate = $app->getTemplate(); if ($currentTemplate != $template) { if (JVM_VERSION >= 4) { $templateObj = (object)$res; $app->setTemplate($templateObj); //Todo why we have this? $currentTemplateObj = $app->getTemplate(true); $currentTemplateObj->id = $templateObj->id; } else { $app->setTemplate($template, $registry); } } } } else { vmError( 'The chosen template couldnt be found on the filesystem: '.VMPATH_ROOT.'/templates/'.$template ); } return $template; } }