* @license GNU General Public License version 2 or later; see LICENSE.txt * http://virtuemart.net */ // Load the view framework use Joomla\CMS\Application\ApplicationHelper; use Joomla\CMS\Event\AbstractEvent; use Joomla\CMS\Factory; jimport( 'joomla.application.component.view'); // Load default helpers class VmView extends JViewLegacy{ var $isMail = false; var $isPdf = false; var $writeJs = true; var $useSSL = 0; static protected $bs = null; static protected $override = null; function __construct($config = array()){ if(!isset(VmView::$bs)){ VmView::$bs = VmConfig::get('bootstrap',''); VmView::$override = VmConfig::get('useLayoutOverrides',1); if(VmConfig::$_debug){ $msg = ''; if(!empty(VmView::$override)){ $msg = 'VmView loaded with override'; } if(!empty(VmView::$bs)){ $msg .= ' bootstrap version '. VmView::$bs; } if(!empty($msg)){ vmdebug($msg); } } } parent::__construct($config); } /** * @depreacted * @param string $key * @param mixed $val * @return bool|void */ public function assignRef($key, &$val) { $this->{$key} =& $val; } public function display($tpl = null) { if(JVM_VERSION>3){ $app = Factory::getApplication(); if ($this->option) { $component = $this->option; } else { $component = ApplicationHelper::getComponentName(); } $context = $component . '.' . $this->getName(); $app->getDispatcher()->dispatch( 'onBeforeDisplay', AbstractEvent::create( 'onBeforeDisplay', [ 'eventClass' => 'Joomla\CMS\Event\View\DisplayEvent', 'subject' => $this, 'extension' => $context, ] ) ); } if($this->isMail or $this->isPdf){ $this->writeJs = false; } $this->useSSL = vmURI::useSSL(); if(!VmView::$override){ //we just add the default again, so it is first in queque $this->addTemplatePath(VMPATH_ROOT .'/components/com_virtuemart/views/'.$this->_name.'/tmpl'); } $result = $this->loadTemplate($tpl); if ($result instanceof Exception) { return $result; } if(JVM_VERSION>3){ $eventResult = $app->getDispatcher()->dispatch( 'onAfterDisplay', AbstractEvent::create( 'onAfterDisplay', [ 'eventClass' => 'Joomla\CMS\Event\View\DisplayEvent', 'subject' => $this, 'extension' => $context, 'source' => $result, ] ) ); $eventResult->getArgument('used', false); } echo $result; if($this->writeJs){ self::withKeepAlive(); vmJsApi::vmVariables(); echo vmJsApi::writeJS(); } } public function withKeepAlive(){ $cart = VirtueMartCart::getCart(); if(!empty($cart->cartProductsData)){ vmJsApi::keepAlive(1,4); } } /** * Renders sublayouts * * @author Max Milbers * @param $name * @param int $viewData viewdata for the rendered sublayout, do not remove * @return string */ public function renderVmSubLayout($name=0,$viewData=0){ if ($name === 0) { $name = $this->_name; } $lPath = self::getVmSubLayoutPath ($name); //vmdebug('renderVmSubLayout layout '.$name,lPath); if($lPath){ if($viewData!==0 and is_array($viewData)){ foreach($viewData as $k => $v){ if ('_' != substr($k, 0, 1) and !isset($this->{$k})) { $this->{$k} = $v; } } } ob_start (); include ($lPath); return ob_get_clean(); } else { vmdebug('renderVmSubLayout layout not found '.$name); return 'Sublayout not found '.$name; } } static public function getVmSubLayoutPath($name) { static $layouts = array(); if (isset($layouts[$name])) { return $layouts[$name]; } else { $vmStyle = VmTemplate::loadVmTemplateStyle(); $template = $vmStyle['template']; // get the template and default paths for the layout if the site template has a layout override, use it $tP = VMPATH_ROOT .'/templates/'. $template .'/html/com_virtuemart/sublayouts/'; $tPp = !empty($vmStyle['parent']) ? VMPATH_ROOT .'/templates/'. $vmStyle['parent'] .'/html/com_virtuemart/sublayouts/' : null; $nP = VMPATH_SITE .'/sublayouts/'; if (!isset(VmView::$bs)) { VmView::$bs = VmConfig::get('bootstrap',''); VmView::$override = VmConfig::get('useLayoutOverrides', 1); if (VmConfig::$_debug) { $msg = ''; if (!empty(VmView::$override)) { $msg = 'VmView loaded with override'; } if (!empty(VmView::$bs)) { $msg .= ' bootstrap version '. VmView::$bs; } if (!empty($msg)) { vmdebug($msg); } } } if (VmView::$bs!=='') { $bsLayout = VmView::$bs . '-' . $name; if (VmView::$override and JFile::exists($tP . $bsLayout . '.php')) { $layouts[$name] = $tP . $bsLayout . '.php'; //vmdebug(' getVmSubLayoutPath using '.VmView::$bs.' tmpl layout override ',$layouts[$name]); return $layouts[$name]; } elseif ($tPp and VmView::$override and JFile::exists($tPp . $bsLayout . '.php')) { $layouts[$name] = $tPp . $bsLayout . '.php'; return $layouts[$name]; } } //If a normal template overrides exists, use the template override if (VmView::$override and JFile::exists($tP. $name .'.php')) { $layouts[$name] = $tP . $name . '.php'; //vmdebug(' getVmSubLayoutPath using tmpl layout override ',$layouts[$name]); return $layouts[$name]; } elseif ($tPp and VmView::$override and JFile::exists($tPp . $name . '.php')) { $layouts[$name] = $tPp . $name . '.php'; return $layouts[$name]; } if (VmView::$bs!=='') { if (JFile::exists($nP. $bsLayout . '.php')) { $layouts[$name] = $nP. $bsLayout . '.php'; //vmdebug(' getVmSubLayoutPath using '.VmView::$bs.' core layout ',$layouts[$name]); return $layouts[$name]; } } if (JFile::exists($nP. $name . '.php')) { $layouts[$name] = $nP. $name .'.php'; //vmdebug(' getVmSubLayoutPath using standard core ',$layouts[$name]); } else { $layouts[$name] = false; //vmEcho::$echoDebug = true; //vmdebug(' getVmSubLayoutPath layout NOOOT found ',$lName); vmError('getVmSubLayoutPath layout '.$name.' not found '); } return $layouts[$name]; } } public function setLayoutAndSub($layout, $sub){ $previous = $this->_layout; if (strpos($layout, ':') === false) { $this->_layout = $layout; } else { // Convert parameter to array based on : $temp = explode(':', $layout); $this->_layout = $temp[1]; // Set layout template $this->_layoutTemplate = $temp[0]; } if(VmView::$bs!==''){ if(substr($this->_layout,0,4) == VmView::$bs.'-'){ //$this->_layout = VmView::$bs.'-'.$this->_layout; $this->_layout = substr($this->_layout,4); } /*else { }*/ $l = $this->_layout .'_'. $sub;//$this->_layout;//$this->getLayout(); $bsLayout = VmView::$bs.'-'.$l; $vmStyle = VmTemplate::loadVmTemplateStyle(); $template = $vmStyle['template']; //vmEcho::$echoDebug = 1; vmdebug('setLayoutAndSub my bootstrap layout here ',$bsLayout, $l); $tP = VMPATH_ROOT .'/templates/'. $template .'/html/com_virtuemart/'.$this->_name.'/';//. $bsLayout .'.php'; $nP = VMPATH_SITE .'/views/'.$this->_name.'/tmpl/'. $bsLayout . '.php'; if( VmView::$override and JFile::exists($tP. $bsLayout .'.php') ){ $this->_layout = VmView::$bs.'-'.$this->_layout; vmdebug('setLayoutAndSub I use a layout BOOTSTRAP '.VmView::$bs.' by template override',$bsLayout); } else if ( VmView::$override and JFile::exists ($tP. $l .'.php') ) { //$this->setLayout($l); vmdebug('I use a layout by template override', $tP.$l); } else if ( JFile::exists ($nP) ){ vmdebug('I use a CORE Bootstrap layout my layout here ',$bsLayout); $this->_layout = VmView::$bs.'-'.$this->_layout; } else { $this->_layout = VmView::$bs.'-'.$this->_layout; vmdebug('No layout found, that should not happen '.$this->_name,$bsLayout); } } return $previous; } /** * If we want to use the layout in a workflow, we need the layout without the Bootstrap prefix * example bs4-default is return as default * @return false|string */ public function getBaseLayout() { if(!empty(VmView::$bs)){ if(substr($this->_layout,0,4) == VmView::$bs.'-'){ return substr($this->_layout,4); } } return $this->_layout; } /** * Sets the layout name to use. Adjusted to the vm system to load bsX layouts * @copyright (C) 2006 Open Source Matters, Inc. * @license GNU General Public License version 2 or later; see LICENSE.txt * @param string $layout The layout name or a string in format