/**
  * test overwrite variable with data object chain
  */
 public function testVariableScope3()
 {
     $data1 = new Smarty_Data($this->smarty);
     $data1->assign('foo', 'newvalue');
     $data2 = new Smarty_Data($data1);
     $tpl = $this->smarty->createTemplate("eval:{\$foo}", null, null, $data2);
     // must see the new value
     $this->assertEquals("newvalue", $this->smarty->fetch($tpl));
 }
 /**
  * Create emotion rewrite rules
  *
  * @param null $offset
  * @param null $limit
  */
 public function sCreateRewriteTableCampaigns($offset = null, $limit = null)
 {
     $queryBuilder = $this->modelManager->getRepository('Shopware\\Models\\Emotion\\Emotion')->getListQueryBuilder();
     $queryBuilder->andWhere('emotions.isLandingPage = 1 ')->andWhere('emotions.active = 1');
     if ($limit !== null && $offset !== null) {
         $queryBuilder->setFirstResult($offset)->setMaxResults($limit);
     }
     $campaigns = $queryBuilder->getQuery()->getArrayResult();
     $routerCampaignTemplate = $this->config->get('routerCampaignTemplate');
     foreach ($campaigns as $campaign) {
         $campaign["categoryId"] = null;
         $this->data->assign('campaign', $campaign);
         $path = $this->template->fetch('string:' . $routerCampaignTemplate, $this->data);
         $path = $this->sCleanupPath($path, false);
         $org_path = 'sViewport=campaign&emotionId=' . $campaign['id'];
         $this->sInsertUrl($org_path, $path);
         foreach ($campaign['categories'] as $category) {
             $campaign["categoryId"] = $category['id'];
             $this->data->assign('campaign', $campaign);
             $path = $this->template->fetch('string:' . $routerCampaignTemplate, $this->data);
             $path = $this->sCleanupPath($path, false);
             $org_path = 'sViewport=campaign&sCategory=' . $campaign['categoryId'] . '&emotionId=' . $campaign['id'];
             $this->sInsertUrl($org_path, $path);
         }
     }
 }
Example #3
0
 /**
  * Generates and inserts static page urls
  *
  * @param $offset
  * @param $limit
  */
 private function insertStaticPageUrls($offset, $limit)
 {
     $shopId = Shopware()->Shop()->getId();
     $sitesData = $this->modelManager->getRepository('Shopware\\Models\\Site\\Site')->getSitesWithoutLinkQuery($shopId, $offset, $limit)->getArrayResult();
     foreach ($sitesData as $site) {
         $org_path = 'sViewport=custom&sCustom=' . $site['id'];
         $this->data->assign('site', $site);
         $path = $this->template->fetch('string:' . $this->config->get('seoCustomSiteRouteTemplate'), $this->data);
         $path = $this->sCleanupPath($path, false);
         $this->sInsertUrl($org_path, $path);
     }
 }
Example #4
0
 public function display($file, $template, $cacheId = null, $compileId = null)
 {
     if (($overloaded = Module::_isTemplateOverloadedStatic(basename($file, '.php'), $template)) === null) {
         return Tools::displayError('No template found for module') . ' ' . basename($file, '.php');
     } else {
         $this->smarty->assign(array('module_dir' => __PS_BASE_URI__ . 'modules/' . basename($file, '.php') . '/', 'module_template_dir' => ($overloaded ? _THEME_DIR_ : __PS_BASE_URI__) . 'modules/' . basename($file, '.php') . '/'));
         if ($cacheId !== null) {
             Tools::enableCache();
         }
         $result = $this->getCurrentSubTemplate($template, $cacheId, $compileId)->fetch();
         if ($cacheId !== null) {
             Tools::restoreCacheSettings();
         }
         $this->resetCurrentSubTemplate($template, $cacheId, $compileId);
         return $result;
     }
 }
Example #5
0
 /**
  * Recursively gets variables from all template/data scopes
  *
  * @param  Smarty_Internal_Template|Smarty_Data $obj object to debug
  *
  * @return StdClass
  */
 public function get_debug_vars($obj)
 {
     $config_vars = array();
     foreach ($obj->config_vars as $key => $var) {
         $config_vars[$key]['value'] = $var;
         if ($obj->_isTplObj()) {
             $config_vars[$key]['scope'] = $obj->source->type . ':' . $obj->source->name;
         } elseif ($obj->_isDataObj()) {
             $tpl_vars[$key]['scope'] = $obj->dataObjectName;
         } else {
             $config_vars[$key]['scope'] = 'Smarty object';
         }
     }
     $tpl_vars = array();
     foreach ($obj->tpl_vars as $key => $var) {
         foreach ($var as $varkey => $varvalue) {
             if ($varkey == 'value') {
                 $tpl_vars[$key][$varkey] = $varvalue;
             } else {
                 if ($varkey == 'nocache') {
                     if ($varvalue == true) {
                         $tpl_vars[$key][$varkey] = $varvalue;
                     }
                 } else {
                     if ($varkey != 'scope' || $varvalue !== 0) {
                         $tpl_vars[$key]['attributes'][$varkey] = $varvalue;
                     }
                 }
             }
         }
         if ($obj->_isTplObj()) {
             $tpl_vars[$key]['scope'] = $obj->source->type . ':' . $obj->source->name;
         } elseif ($obj->_isDataObj()) {
             $tpl_vars[$key]['scope'] = $obj->dataObjectName;
         } else {
             $tpl_vars[$key]['scope'] = 'Smarty object';
         }
     }
     if (isset($obj->parent)) {
         $parent = $this->get_debug_vars($obj->parent);
         foreach ($parent->tpl_vars as $name => $pvar) {
             if (isset($tpl_vars[$name]) && $tpl_vars[$name]['value'] === $pvar['value']) {
                 $tpl_vars[$name]['scope'] = $pvar['scope'];
             }
         }
         $tpl_vars = array_merge($parent->tpl_vars, $tpl_vars);
         foreach ($parent->config_vars as $name => $pvar) {
             if (isset($config_vars[$name]) && $config_vars[$name]['value'] === $pvar['value']) {
                 $config_vars[$name]['scope'] = $pvar['scope'];
             }
         }
         $config_vars = array_merge($parent->config_vars, $config_vars);
     } else {
         foreach (Smarty::$global_tpl_vars as $key => $var) {
             if (!array_key_exists($key, $tpl_vars)) {
                 foreach ($var as $varkey => $varvalue) {
                     if ($varkey == 'value') {
                         $tpl_vars[$key][$varkey] = $varvalue;
                     } else {
                         if ($varkey == 'nocache') {
                             if ($varvalue == true) {
                                 $tpl_vars[$key][$varkey] = $varvalue;
                             }
                         } else {
                             if ($varkey != 'scope' || $varvalue !== 0) {
                                 $tpl_vars[$key]['attributes'][$varkey] = $varvalue;
                             }
                         }
                     }
                 }
                 $tpl_vars[$key]['scope'] = 'Global';
             }
         }
     }
     return (object) array('tpl_vars' => $tpl_vars, 'config_vars' => $config_vars);
 }
Example #6
0
 protected function Get($var)
 {
     return $this->data->getTemplateVars($var);
 }
Example #7
0
<?php

$path = "./";
require_once $path . "functions.php";
require_once $path . 'db/pdo.php';
require_once $path . 'vendor/autoload.php';
$fields = ["title", "summary", "category", "contributor", "author", "content", "url"];
$feeds = $fpdo->from("feeds")->fetchAll();
$aggregates = $fpdo->from("aggregateFeeds")->fetchAll();
foreach ($feeds as &$feed) {
    $feed["patterns"] = $fpdo->from("filters")->where("feedID", $feed["ID"])->fetchAll();
}
//DISPLAY
$smarty = new Smarty();
$smarty->auto_literal = true;
$data = new Smarty_Data();
$data->assign("fields", $fields);
$data->assign("feeds", $feeds);
$data->assign("aggregates", $aggregates);
$data->assign("base_url", "//" . $_SERVER['HTTP_HOST'] . substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], "/")));
$smarty->display("admin.tpl", $data);
Example #8
0
 public function display($file, $template, $cacheId = null, $compileId = null)
 {
     if (($overloaded = Module::_isTemplateOverloadedStatic(basename($file, '.php'), $template)) === null) {
         $result = Tools::displayError('No template found for module') . ' ' . basename($file, '.php');
     } else {
         $this->smarty->assign(array('module_dir' => __PS_BASE_URI__ . 'modules/' . basename($file, '.php') . '/', 'module_template_dir' => ($overloaded ? _THEME_DIR_ : __PS_BASE_URI__) . 'modules/' . basename($file, '.php') . '/'));
         $smarty_subtemplate = $this->context->smarty->createTemplate($this->getTemplatePath($template), $cacheId, $compileId, $this->smarty);
         $result = $smarty_subtemplate->fetch();
     }
     return $result;
 }
 /**
  * test get single variables with data object chain search parents disabled
  */
 public function testGetSingleTemplateVarsScopeAllNoParents()
 {
     error_reporting(error_reporting() & ~(E_NOTICE | E_USER_NOTICE));
     $data1 = new Smarty_Data($this->smarty);
     $data2 = new Smarty_Data($data1);
     $this->smarty->assign('foo', 'bar');
     $data1->assign('blar', 'buh');
     $data2->assign('foo2', 'bar2');
     $this->assertEquals("", $this->smarty->getTemplateVars('foo', $data2, false));
     $this->assertEquals("bar2", $this->smarty->getTemplateVars('foo2', $data2, false));
     $this->assertEquals("", $this->smarty->getTemplateVars('blar', $data2, false));
 }
Example #10
0
 /**
  * Ejecuta una peticion
  *
  * Carga el componente y ejecuta su metodo especifico
  * Si $mostrar tiene un valor true, se invoca la plantilla respectiva
  * y se muestra el contenido. Si tiene un valor false, ejecuta el metodo del modulo
  * invocado y retorna su respuesta
  *
  * @param String $peticion
  * @param Boolean $mostrar
  * @return unknown
  */
 public function ejecutar($peticion, $parametros = null, $mostrar = true, $llamado = false)
 {
     //Separara la peticion en Componente y accion
     $peticion = explode(".", $peticion);
     $componente = $peticion[0];
     $accion = $peticion[1];
     $dir = strtolower($componente);
     //Verifica la existencia del componente y lo incluye o devuelve un error
     if (file_exists("app/componentes/{$dir}.class.php")) {
         require_once "app/componentes/{$dir}.class.php";
         //Crear el objeto de datos smarty independiente para el componente
         $c_smarty = new Smarty_Data($this->smarty);
         $obj = new $componente($this, $c_smarty, $parametros, $llamado);
         //Verifica la exitencia de la accion o devuelve un error
         if (method_exists($obj, $accion)) {
             if ($mostrar) {
                 //$this->smarty->assign("componente", $dir);
                 //$this->smarty->assign("vista", $accion);
                 //Se asignan las variables al smarty personal del componente
                 $c_smarty->assign("componente", $dir);
                 $c_smarty->assign("vista", $accion);
                 //ejecuta la accion del componente
                 $obj->{$accion}();
                 //Verifica la bandera Ajax, si es afirmativa muestra una vista
                 if ($this->parametros['ajaxafw'] == 1 && $obj->ajax == "" || $obj->ajax == 1) {
                     //$this->smarty->assign("ajaxafw", 1);
                     $c_smarty->assign("ajaxafw", 1);
                     //Obtiene la vista a incluir
                     //$ptl=$this->smarty->get_template_vars("vista");
                     //$mod=$this->smarty->get_template_vars("componente");
                     $ptl = $c_smarty->getTemplateVars("vista");
                     $mod = $c_smarty->getTemplateVars("componente");
                     //Verifica la existencia de la vista y la muestra
                     if (file_exists("app/vistas/{$mod}/{$ptl}.tpl")) {
                         //$this->smarty->display("mostrar.tpl");
                         $tpl = $this->smarty->createTemplate("mostrar.tpl", $c_smarty);
                         $tpl->display();
                     } else {
                         Error::manejarError($this, 3, array($ptl . ".tpl", $componente, $accion));
                         return;
                     }
                 } else {
                     //En el caso contrario de no ser una peticion ajax, llama a la plantilla seleccionada
                     //Y la muestra
                     $ini = new Configuracion();
                     $plantilla = $ini->get("plantilla", "default");
                     //Si se ha definido una plantilla diferente para el modulo se usa
                     if ($obj->plantilla != null) {
                         $plantilla = $obj->plantilla;
                     }
                     //obtiene la vista a incluir
                     //$ptl=$this->smarty->get_template_vars("vista");
                     //$mod=$this->smarty->get_template_vars("componente");
                     $ptl = $c_smarty->getTemplateVars("vista");
                     $mod = $c_smarty->getTemplateVars("componente");
                     //Verifica la existencia de la vista y la plantilla y procede a mostrarla
                     if (file_exists("app/vistas/{$mod}/{$ptl}.tpl")) {
                         //$this->smarty->assign("vista", "$ptl");
                         $c_smarty->assign("vista", "{$ptl}");
                         if (file_exists("app/vistas/plantillas/{$plantilla}.tpl")) {
                             //$this->smarty->display("plantillas/$plantilla.tpl");
                             $tpl = $this->smarty->createTemplate("plantillas/{$plantilla}.tpl", $c_smarty);
                             $tpl->display();
                         } else {
                             Error::manejarError($this, 4, array($plantilla, $ptl . ".tpl", $componente, $accion));
                         }
                     } else {
                         Error::manejarError($this, 3, array($ptl . ".tpl", $componente, $accion));
                         return;
                     }
                 }
             } else {
                 return $obj->{$accion}();
             }
         } else {
             Error::manejarError($this, 2, array($componente, $accion));
             return;
         }
     } else {
         Error::manejarError($this, 1, $componente);
         return;
     }
 }