Last active
November 9, 2023 15:55
-
-
Save foxp2/5194837 to your computer and use it in GitHub Desktop.
Preview of new TwigTemplate Class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * osCommerce Online Merchant | |
| * | |
| * @copyright Copyright (c) 2013 osCommerce; http://www.oscommerce.com | |
| * @copyright Copyright (c) 2013 FoxP2; http://www.oscommerce.fr | |
| * @license GNU General Public License; http://www.oscommerce.com/gpllicense.txt | |
| */ | |
| class TwigTemplate | |
| { | |
| protected $_twig; | |
| protected $_app; | |
| protected $_template = "twig"; | |
| protected $_template_extension = ".html.twig"; | |
| protected $_columnsize; | |
| protected $_contentsize; | |
| protected $_title; | |
| protected $_basehref; | |
| protected $_header_tags; | |
| protected $_breadcrumb; | |
| protected $_columnleft; | |
| protected $_columnright; | |
| protected $_footerscript; | |
| public function __construct() | |
| { | |
| global $OSCOM_APP,$OSCOM_Template; | |
| $loader = new Twig_Loader_Filesystem(array( | |
| // check app templates | |
| DIR_WS_INCLUDES . 'apps/' . $OSCOM_APP->getCode() .'/view/', | |
| // check base templates | |
| DIR_WS_MODULES . 'templates/' . $this->_template . '/content', | |
| // check modules templates | |
| DIR_WS_MODULES, | |
| // check boxes templates | |
| DIR_WS_MODULES . 'boxes' | |
| )); | |
| $this->_twig = new Twig_Environment($loader, array('cache' => false, 'debug' => true)); | |
| $this->addExtentions(); | |
| $OSCOM_Template->buildBlocks(); | |
| } | |
| public function getTwig() | |
| { | |
| return $this->_twig; | |
| } | |
| public function getTemplateExtension() | |
| { | |
| return $this->_template_extension; | |
| } | |
| public function render() | |
| { | |
| $data = $this->getAppData(); | |
| if ( is_array($data) && !empty($data) ) | |
| { | |
| $params = $this->getAppData(); | |
| } else { | |
| $params = array(); | |
| } | |
| $content = $this->_twig->render($this->getApp(), array_merge($this->getGlobalData(),$params)); | |
| echo $content; | |
| } | |
| private function getApp() | |
| { | |
| global $OSCOM_APP; | |
| return osc_not_null($OSCOM_APP->getCurrentAction()) && osc_not_null($OSCOM_APP->getCurrentAction()) != "process" ? $this->_app = ($OSCOM_APP->getCurrentAction() . $this->_template_extension) : $this->_app = substr($OSCOM_APP->getContentFile(),0, -4) . $this->_template_extension; | |
| } | |
| private function getAppData() | |
| { | |
| global $OSCOM_APP; | |
| if (file_exists(DIR_FS_CATALOG . DIR_WS_INCLUDES . 'apps/' . $OSCOM_APP->getCode() . '/model/' . $OSCOM_APP->getContentFile())) { | |
| $class = substr($OSCOM_APP->getContentFile(),0,-4); | |
| if ( !class_exists($class) ) { | |
| include(DIR_WS_INCLUDES . 'apps/' . $OSCOM_APP->getCode() . '/model/' . $class . '.php'); | |
| } | |
| $samanthafox = new $class(); | |
| return $samanthafox->execute(); | |
| } | |
| return false; | |
| } | |
| private function getAppCode() | |
| { | |
| global $OSCOM_APP; | |
| return $OSCOM_APP->getCode(); | |
| } | |
| private function addExtentions() | |
| { | |
| $this->_twig->addExtension(new TwigHtmlOutput()); | |
| $this->_twig->addExtension(new TwigMyFilters()); | |
| $this->_twig->addExtension(new TwigFunctions()); | |
| $this->_twig->addExtension(new TwigModules()); | |
| $this->_twig->addExtension(new Twig_Extension_Debug()); | |
| } | |
| private function getColumnsize() | |
| { | |
| global $OSCOM_Template; | |
| return $this->_columnsize = $OSCOM_Template->getGridColumnWidth(); | |
| } | |
| private function getContentsize() | |
| { | |
| global $OSCOM_Template; | |
| return $this->_contentsize = $OSCOM_Template->getGridContentWidth(); | |
| } | |
| private function getBasehref() | |
| { | |
| global $request_type; | |
| return $this->_basehref = ($request_type == 'SSL' ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; | |
| } | |
| private function getHeadertags() | |
| { | |
| global $OSCOM_Template; | |
| return $this->_header_tags = $OSCOM_Template->getBlocks('header_tags'); | |
| } | |
| private function getBreadcrumb() | |
| { | |
| global $OSCOM_Breadcrumb; | |
| return $this->_breadcrumb = $OSCOM_Breadcrumb->get(); | |
| } | |
| private function getColumnleft() | |
| { | |
| global $OSCOM_Template; | |
| return $this->_columnleft = $OSCOM_Template->getBlocks('boxes_column_left'); | |
| } | |
| private function getColumnright() | |
| { | |
| global $OSCOM_Template; | |
| return $this->_columnright = $OSCOM_Template->getBlocks('boxes_column_right'); | |
| } | |
| private function getFooterscript() | |
| { | |
| global $OSCOM_Template; | |
| return $this->_footerscript = $OSCOM_Template->getBlocks('footer_scripts'); | |
| } | |
| private function getUserstatus() | |
| { | |
| global $OSCOM_Customer; | |
| return $OSCOM_Customer->isLoggedOn(); | |
| } | |
| private function getGlobalData() | |
| { | |
| return array('GridColumnWidth' => $this->getColumnsize(), | |
| 'GridContentWidth' => $this->getContentsize(), | |
| 'title' => $this->getTitle(), | |
| 'base_href' => $this->getBasehref(), | |
| 'app_code' => $this->getAppCode(), | |
| 'header_tags' => $this->getHeadertags(), | |
| 'breadcrumb' => $this->getBreadcrumb(), | |
| 'column_left' => $this->getColumnleft(), | |
| 'column_right' => $this->getColumnright(), | |
| 'footer_script' => $this->getFooterscript(), | |
| 'isLoggedOn' => $this->getUserstatus()); | |
| } | |
| private function getTitle() | |
| { | |
| global $OSCOM_Template; | |
| return $this->_title = osc_output_string_protected($OSCOM_Template->getTitle()); | |
| } | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment