/** * Iterate all template and config variables of the given template object and write them * into the internal log object. * * @param \Enlight_Template_Default|\Enlight_Template_Manager $template */ public function logTemplate($template) { $template_name = isset($template->template_resource) ? $template->template_resource : 'Global'; $template_name = $this->encode($template_name, 30); $template_vars = (array) $template->getTemplateVars(); unset($template_vars['smarty']); if (!empty($template_vars)) { $rows = array(array('spec', 'value')); foreach ($template_vars as $template_spec => $template_var) { $template_var = $this->encode($template_var); $rows[] = array($template_spec, $template_var); } $table = array('Template Vars > ' . $template_name . ' (' . count($template_vars) . ')', $rows); try { $this->results[] = $table; } catch (Exception $e) { die((string) $e); } } $config_vars = (array) $template->getConfigVars(); if (!empty($config_vars)) { $rows = array(array('spec', 'value')); foreach ($config_vars as $config_spec => $config_var) { $rows[] = array($config_spec, $config_var); } $table = array('Config Vars > ' . $template_name . ' (' . count($config_vars) . ')', $rows); $this->results[] = $table; } }
/** * Test case */ public function testTemplateExists() { $result = $this->manager->templateExists('index.tpl'); $this->assertEquals('success', $result); $result = $this->manager->fetch('string:{if {"index.tpl"|template_exists}}true{/if}'); $this->assertEquals('true', $result); $result = $this->manager->fetch('string:{if {"test.tpl"|template_exists}}true{else}false{/if}'); $this->assertEquals('false', $result); }
/** * adds the Views folder to the template directory to provide the rating images for the e-mail templates * * @param \Enlight_Event_EventArgs $args */ public function onPreDispatchBackendMail(\Enlight_Event_EventArgs $args) { /* @var \Enlight_Controller_Action $subject */ $subject = $args->getSubject(); if ($subject->Request()->getActionName() != 'sendTestmail') { return; } $this->template->addTemplateDir($this->bootstrapPath . 'Views/'); }
public function addPlugins(\Enlight_Template_Manager $template_Manager) { if (!$this->hasPlugins) { $template_Manager->registerPlugin('modifier', 'convertMemory', [$this, 'convertMemory']); $template_Manager->registerPlugin('modifier', 'dump', [$this, 'dump']); $template_Manager->registerPlugin('modifier', 'sqlFormat', [$this, 'sqlFormat']); $this->hasPlugins = true; } }
/** * Sets up */ public function setUp() { $tempDir = Enlight_TestHelper::Instance()->TestPath('TempFiles'); $this->engine = new Enlight_Template_Manager(); $this->engine->setCompileDir($tempDir); $this->engine->setCompileId('view'); $this->engine->clearCompiledTemplate(null, 'view'); Smarty::$global_tpl_vars = array(); }
/** * Set own template directory * * @param $templateManager */ private function reconfigureTemplateDirs(\Enlight_Template_Manager $templateManager) { if (!$this->templateDirConfigured) { $compileDir = $templateManager->getCompileDir() . 'blocks/'; $cacheDir = $templateManager->getCacheDir() . 'blocks/'; $templateManager->setCompileDir($compileDir); $templateManager->setCacheDir($cacheDir); $this->templateDirConfigured = true; } }
/** * This function is responsible to resolve the backend / frontend controller path. * * @param \Enlight_Event_EventArgs $args * @return string */ public function onGetCustomSortControllerPath(\Enlight_Event_EventArgs $args) { $this->templateManager->addTemplateDir($this->bootstrapPath . 'Views/'); switch ($args->getName()) { case 'Enlight_Controller_Dispatcher_ControllerPath_Backend_CustomSort': return $this->bootstrapPath . 'Controllers/Backend/CustomSort.php'; case 'Enlight_Controller_Dispatcher_ControllerPath_Widgets_CustomSort': return $this->bootstrapPath . 'Controllers/Widgets/CustomSort.php'; } }
/** * 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); } } }
/** * Initiate smarty template engine */ protected function initTemplateEngine() { $this->_template = clone Shopware()->Template(); $this->_view = $this->_template->createData(); $path = basename($this->_subshop["doc_template"]); $this->_template->setTemplateDir(array('custom' => $path, 'local' => '_emotion_local', 'emotion' => '_emotion')); $this->_template->setCompileId(str_replace('/', '_', $path) . '_' . $this->_subshop['id']); }
/** * @param $charset * @return Enlight_Template_Manager */ public function setCharset($charset = null) { if ($charset !== null) { self::$_CHARSET = $charset; } mb_internal_encoding(self::$_CHARSET); return $this; }
/** * 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); } }
/** * Test case */ public function testGetContent() { $resource = new Enlight_Components_Snippet_Resource($this->manager); $this->engine->registerResource('snippet', $resource); $this->assertEquals('test', $this->engine->fetch('snippet:string:{s name="test" namespace="test"}test{/s}')); $this->assertEquals('test', $this->engine->fetch('snippet:string:{namespace name="test"}{s name="test"}test{/s}')); $this->assertEquals('force', $this->engine->fetch('snippet:string:{s name="force" namespace="test" force}force{/s}')); $this->assertEquals('force2', $this->engine->fetch('snippet:string:{s name="force" namespace="test" force}force2{/s}')); $this->assertContains('<span', $this->engine->fetch('snippet:string:{se name="force" namespace="test"}force{/se}')); $this->assertEquals('test', $this->engine->fetch('snippet:string:{namespace name="ignore"}{s name="ignore"}test{/s}')); $this->assertEquals('ignore', $this->engine->fetch('snippet:string:{namespace ignore}{s name="ignore"}ignore{/s}')); }
/** * provides the Trusted Shops config and shows the logo and the badge * * @param \Enlight_Event_EventArgs $args * @return void */ public function onFrontendPostDispatch(\Enlight_Event_EventArgs $args) { /** @var $subject \Enlight_Controller_Action */ $subject = $args->getSubject(); $view = $subject->View(); $request = $subject->Request(); $shopId = $this->shop->getId(); if ($request->getControllerName() == 'checkout') { return; } //get basic config of trusted shop for the seal template and trusted shop id $config = $this->getConfig($shopId); //extend template $view->sTrustedShops = $config; if (!$this->isResponsiveTemplate()) { $this->template->addTemplateDir($this->bootstrapPath . 'Views/emotion'); $view->extendsTemplate('frontend/plugins/swag_trusted_shops/index/index.tpl'); } else { $this->template->addTemplateDir($this->bootstrapPath . 'Views/responsive'); } }
/** * Fetch an template by name over the Enlight_Template_Manager. * * @param $template_name * @return string */ public function fetch($template_name) { return $this->engine->fetch($template_name, $this->template); }
/** * returns the backend controller path * * @return string */ public function onGetTrustedShopsControllerPath() { $this->template->addTemplateDir($this->bootstrapPath . 'Views'); return $this->bootstrapPath . 'Controllers/Backend/TrustedShops.php'; }
/** * @param \Enlight_Template_Manager $smarty * @author Martin Schindler */ public function register(\Enlight_Template_Manager $smarty) { $smarty->registerPlugin('function', 'form_start', array($this, 'formStart')); $smarty->registerPlugin('function', 'form_errors', array($this, 'formErrors')); $smarty->registerPlugin('function', 'form_row', array($this, 'formRow')); $smarty->registerPlugin('function', 'form_label', array($this, 'formLabel')); $smarty->registerPlugin('function', 'form_widget', array($this, 'formWidget')); $smarty->registerPlugin('function', 'form_rest', array($this, 'formRest')); $smarty->registerPlugin('function', 'form_end', array($this, 'formEnd')); }
/** * */ public function start() { $this->template->setDebugging(true); $this->template->debug_tpl = 'string:'; }
/** * executes the current product export * * @param resource $handleResource used as a file or the stdout to fetch the smarty output */ public function executeExport($handleResource) { fwrite($handleResource, $this->sSmarty->fetch('string:' . $this->sSettings['header'], $this->sFeedID)); $context = $this->contextService->getShopContext(); $sql = $this->sCreateSql(); $result = $this->db->query($sql); if ($result === false) { return; } // Update db with the latest values $count = (int) $result->rowCount(); $this->db->update('s_export', array('last_export' => new Zend_Date(), 'cache_refreshed' => new Zend_Date(), 'count_articles' => $count), array('id = ?' => $this->sFeedID)); // fetches all required data to smarty $rows = array(); for ($rowIndex = 1; $row = $result->fetch(); $rowIndex++) { if (!empty($row['group_ordernumber_2'])) { $row['group_ordernumber'] = $this->_decode_line($row['group_ordernumber_2']); $row['group_pricenet'] = explode(';', $row['group_pricenet_2']); $row['group_price'] = explode(';', $row['group_price_2']); $row['group_instock'] = explode(';', $row['group_instock_2']); $row['group_active'] = explode(';', $row['group_active_2']); unset($row['group_ordernumber_2'], $row['group_pricenet_2']); unset($row['group_price_2'], $row['group_instock_2'], $row['group_active_2']); for ($i = 1; $i <= 10; $i++) { if (!empty($row['group_group' . $i])) { $row['group_group' . $i] = $this->_decode_line($row['group_group' . $i]); } else { unset($row['group_group' . $i]); } if (!empty($row['group_option' . $i])) { $row['group_option' . $i] = $this->_decode_line($row['group_option' . $i]); } else { unset($row['group_option' . $i]); } } unset($row['group_additionaltext']); } elseif (!empty($row['group_ordernumber'])) { $row['group_ordernumber'] = $this->_decode_line($row['group_ordernumber']); $row['group_additionaltext'] = $this->_decode_line($row['group_additionaltext']); $row['group_pricenet'] = explode(';', $row['group_pricenet']); $row['group_price'] = explode(';', $row['group_price']); $row['group_instock'] = explode(';', $row['group_instock']); $row['group_active'] = explode(';', $row['group_active']); } if (!empty($row['article_translation_fallback'])) { $translation = $this->sMapTranslation('article', $row['article_translation_fallback']); if ($row['main_detail_id'] != $row['articledetailsID']) { unset($translation['additionaltext']); } $row = array_merge($row, $translation); } if (!empty($row['article_translation'])) { $translation = $this->sMapTranslation('article', $row['article_translation']); if ($row['main_detail_id'] != $row['articledetailsID']) { unset($translation['additionaltext']); } $row = array_merge($row, $translation); } if (!empty($row['detail_translation_fallback'])) { $translation = $this->sMapTranslation('detail', $row['detail_translation_fallback']); $row = array_merge($row, $translation); } if (!empty($row['detail_translation'])) { $translation = $this->sMapTranslation('detail', $row['detail_translation']); $row = array_merge($row, $translation); } $row['name'] = htmlspecialchars_decode($row['name']); $row['supplier'] = htmlspecialchars_decode($row['supplier']); //cast it to float to prevent the division by zero warning $row['purchaseunit'] = floatval($row['purchaseunit']); $row['referenceunit'] = floatval($row['referenceunit']); if (!empty($row['purchaseunit']) && !empty($row['referenceunit'])) { $row['referenceprice'] = Shopware()->Modules()->Articles()->calculateReferencePrice($row['price'], $row['purchaseunit'], $row['referenceunit']); } if ($row['configurator'] > 0) { if (empty($this->sSettings["variant_export"]) || $this->sSettings["variant_export"] == 1) { $row['group_additionaltext'] = array(); if (!empty($row['group_ordernumber'])) { foreach ($row['group_ordernumber'] as $orderNumber) { $product = new StoreFrontBundle\Struct\ListProduct((int) $row['articleID'], (int) $row["articledetailsID"], $orderNumber); $product->setAdditional($row['additionaltext']); $product = $this->additionalTextService->buildAdditionalText($product, $context); if (array_key_exists($orderNumber, $row['group_additionaltext'])) { $row['group_additionaltext'][$orderNumber] = $product->getAdditional(); } if ($orderNumber == $row['ordernumber']) { $row['additionaltext'] = $product->getAdditional(); } } } } $product = new StoreFrontBundle\Struct\ListProduct((int) $row['articleID'], (int) $row["articledetailsID"], $row['ordernumber']); $product->setAdditional($row['additionaltext']); $product = $this->additionalTextService->buildAdditionalText($product, $context); $row['additionaltext'] = $product->getAdditional(); } $rows[] = $row; if ($rowIndex == $count || count($rows) >= 50) { @set_time_limit(30); $this->sSmarty->assign('sArticles', $rows); $rows = array(); $template = 'string:{foreach $sArticles as $sArticle}' . $this->sSettings['body'] . '{/foreach}'; fwrite($handleResource, $this->sSmarty->fetch($template, $this->sFeedID)); } } fwrite($handleResource, $this->sSmarty->fetch('string:' . $this->sSettings['footer'], $this->sFeedID)); fclose($handleResource); }
/** * Returns the template directory of the passed shop template. * To get this use the getDirectory function. * * @param Shop\Template $template * @return string */ private function getTemplateDirectory(Shop\Template $template) { return $this->templateManager->resolveTemplateDir($template->getTemplate()); }
/** * executes the current product export * * @param resource $handleResource used as a file or the stdout to fetch the smarty output */ public function executeExport($handleResource) { fwrite($handleResource, $this->sSmarty->fetch('string:' . $this->sSettings['header'], $this->sFeedID)); $sql = $this->sCreateSql(); $result = Shopware()->Db()->query($sql); if ($result === false) { return; } // Update db with the latest values $count = (int) $result->rowCount(); Shopware()->Db()->update('s_export', array('last_export' => new Zend_Date(), 'cache_refreshed' => new Zend_Date(), 'count_articles' => $count), array('id = ?' => $this->sFeedID)); // fetches all required data to smarty $rows = array(); for ($rowIndex = 1; $row = $result->fetch(); $rowIndex++) { if (!empty($row['group_ordernumber_2'])) { $row['group_ordernumber'] = $this->_decode_line($row['group_ordernumber_2']); $row['group_pricenet'] = explode(';', $row['group_pricenet_2']); $row['group_price'] = explode(';', $row['group_price_2']); $row['group_instock'] = explode(';', $row['group_instock_2']); $row['group_active'] = explode(';', $row['group_active_2']); unset($row['group_ordernumber_2'], $row['group_pricenet_2']); unset($row['group_price_2'], $row['group_instock_2'], $row['group_active_2']); for ($i = 1; $i <= 10; $i++) { if (!empty($row['group_group' . $i])) { $row['group_group' . $i] = $this->_decode_line($row['group_group' . $i]); } else { unset($row['group_group' . $i]); } if (!empty($row['group_option' . $i])) { $row['group_option' . $i] = $this->_decode_line($row['group_option' . $i]); } else { unset($row['group_option' . $i]); } } unset($row['group_additionaltext']); } elseif (!empty($row['group_ordernumber'])) { $row['group_ordernumber'] = $this->_decode_line($row['group_ordernumber']); $row['group_additionaltext'] = $this->_decode_line($row['group_additionaltext']); $row['group_pricenet'] = explode(';', $row['group_pricenet']); $row['group_price'] = explode(';', $row['group_price']); $row['group_instock'] = explode(';', $row['group_instock']); $row['group_active'] = explode(';', $row['group_active']); } if (!empty($row['article_translation'])) { $translation = $this->sMapTranslation('article', $row['article_translation']); $row = array_merge($row, $translation); } elseif (!empty($row['article_translation_fallback'])) { $translation = $this->sMapTranslation('article', $row['article_translation_fallback']); $row = array_merge($row, $translation); } if (!empty($row['detail_translation'])) { $translation = $this->sMapTranslation('detail', $row['detail_translation']); $row = array_merge($row, $translation); } elseif (!empty($row['detail_translation_fallback'])) { $translation = $this->sMapTranslation('detail', $row['detail_translation_fallback']); $row = array_merge($row, $translation); } $row['name'] = htmlspecialchars_decode($row['name']); $row['supplier'] = htmlspecialchars_decode($row['supplier']); //cast it to float to prevent the devision by zero warning $row['purchaseunit'] = floatval($row['purchaseunit']); $row['referenceunit'] = floatval($row['referenceunit']); if (!empty($row['purchaseunit']) && !empty($row['referenceunit'])) { $row['referenceprice'] = Shopware()->Modules()->Articles()->calculateReferencePrice($row['price'], $row['purchaseunit'], $row['referenceunit']); } $rows[] = $row; if ($rowIndex == $count || count($rows) >= 50) { @set_time_limit(30); $this->sSmarty->assign('sArticles', $rows); $rows = array(); $template = 'string:{foreach $sArticles as $sArticle}' . $this->sSettings['body'] . '{/foreach}'; fwrite($handleResource, $this->sSmarty->fetch($template, $this->sFeedID)); } } fwrite($handleResource, $this->sSmarty->fetch('string:' . $this->sSettings['footer'], $this->sFeedID)); fclose($handleResource); }