public function render($strApplicationName, $numEnableCaching = 1) { if ($this->boolRunJs !== true) { return; } $this->arrScriptsToLoad = array_unique($this->arrScriptsToLoad); $strApplicationBaseUrl = \webcitron\Subframe\Application::url(); $objLanguages = Languages::getInstance(); $strCurrentLanguage = $objLanguages->getCurrentLanguage(); $strPostfixCache = ''; if ($numEnableCaching === 0) { $strPostfixCache = '&_=' . time(); } $strLaunchCode = '<script>' . PHP_EOL; $strLaunchCode .= 'var boolIsPuppiesBlocked = true;' . PHP_EOL; $strLaunchCode .= '</script>' . PHP_EOL; $strLaunchCode .= sprintf('<script type="text/javascript" src="%s/subframe/js/adblock-advertisement.js?%s%s"></script>', $strApplicationBaseUrl, $this->strCurrentCommit, $strPostfixCache) . PHP_EOL; // $strLaunchCode .= sprintf('<script type="text/javascript" src="%s/subframe/js/vendor/head/dist/1.0.0/head.min.js?%s"></script>', $strApplicationBaseUrl, $this->strCurrentCommit).PHP_EOL; // $strLaunchCode .= sprintf('<script type="text/javascript" src="%s/bower_components/jquery/dist/jquery.min.js?%s%s"></script>', $strApplicationBaseUrl, $this->strCurrentCommit, $strPostfixCache).PHP_EOL; $strLaunchCode .= sprintf('<script type="text/javascript" src="%s/subframe/js/AssetLoader.js?%s%s"></script>', $strApplicationBaseUrl, $this->strCurrentCommit, $strPostfixCache) . PHP_EOL; $strLaunchCode .= sprintf('<script type="text/javascript" src="%s/subframe/js/Launcher.js?%s%s"></script>', $strApplicationBaseUrl, $this->strCurrentCommit, $strPostfixCache) . PHP_EOL; $strLaunchCode .= '<script>' . PHP_EOL; $strLaunchCode .= sprintf('var objLauncher = new Subframe.Lib.Launcher("%s", "%s", "%s", "%s", %s, ["%s"]);', $strApplicationName, $strApplicationBaseUrl, $strCurrentLanguage, $this->strCurrentCommit, $numEnableCaching, join('", "', $this->arrScriptsToLoad)) . PHP_EOL; $strLaunchCode .= 'objLauncher.init();' . PHP_EOL; $strLaunchCode .= '</script>' . PHP_EOL; return $strLaunchCode; }
public function render($strApplicationName) { if (!empty($this->strForceCssFile)) { $strCssFile = $this->strForceCssFile; } else { $objRouter = Router::getInstance(); $objCurrentRoute = $objRouter->getCurrentRoute(); $strCssFile = $objCurrentRoute->strRouteName . '_' . $objCurrentRoute->strMethodName; } $strApplicationBaseUrl = \webcitron\Subframe\Application::url(); $strCssHhtml = sprintf('<link rel="stylesheet" href="%s/%s/css/%s.css?%s" />', $strApplicationBaseUrl, $strApplicationName, $strCssFile, $this->strCurrentCommit); return $strCssHhtml; }
public function buildUri($arrParams = array()) { $numSetIndex = 0; for ($numSetIndex; $numSetIndex < count($this->arrUris); $numSetIndex++) { $numThisSetParamsCount = 0; if (!empty($this->arrParams[$numSetIndex])) { $numThisSetParamsCount = count($this->arrParams[$numSetIndex]); } if (count($arrParams) === $numThisSetParamsCount) { break; } } if ($numThisSetParamsCount === 0) { $strResult = $this->arrUris[$numSetIndex]; } else { $arrPatterns = array_map(function ($strParamName) { return sprintf('{%s}', $strParamName); }, $this->arrParams[$numSetIndex]); $arrReplaces = $arrParams; $strCurrentUri = str_replace(array('(', ')', '?'), '', $this->arrUris[$numSetIndex]); $strResult = str_replace($arrPatterns, $arrReplaces, $strCurrentUri); } $strResult = sprintf('%s%s', Application::url(), $strResult); return $strResult; }
public static function baseUrl() { $strBaseUrl = Application::url(); return $strBaseUrl; }
private function __construct() { \Twig_Autoloader::register(); $loader = new \Twig_Loader_Filesystem(APP_DIR); $this->objTwig = new \Twig_Environment($loader); $objFunction = new \Twig_SimpleFunction('url', function () { // dynamic parameteres :( $arrParams = func_get_args(); $strRouteName = array_shift($arrParams); return \webcitron\Subframe\Url::route($strRouteName, $arrParams); }); $this->objTwig->addFunction($objFunction); $objFunction = new \Twig_SimpleFunction('plaintext', function ($strInput) { $strString = htmlspecialchars(strip_tags($strInput)); return $strString; }); $this->objTwig->addFunction($objFunction); $objFunction = new \Twig_SimpleFunction('html', function ($strInput) { // $strString = addslashes($strInput); return $strInput; }); $this->objTwig->addFunction($objFunction); $objFunction = new \Twig_SimpleFunction('renderUserJs', function () { // return 't<strong>es</strong>t'; $objJsController = \webcitron\Subframe\JsController::getInstance(); $objApplication = Application::getInstance(); $strUserJs = $objJsController->render($objApplication->strName); return $strUserJs; }, array('is_safe' => array('html'))); $this->objTwig->addFunction($objFunction); $objFunction = new \Twig_SimpleFunction('renderHeadAddons', function () { $objJsController = \webcitron\Subframe\JsController::getInstance(); $objApplication = Application::getInstance(); $strHeadAddons = $objJsController->render($objApplication->strName); return $strHeadAddons; }, array('is_safe' => array('html'))); $this->objTwig->addFunction($objFunction); $objFunction = new \Twig_SimpleFunction('metaData', function ($strKey, $strWrapper = '', $boolNeedEscaping = true) { // $objTemplaterBlitz = Blitz::getInstance(); // $strReturn = $objTemplaterBlitz->getMetaData($strKey); if (!empty($strWrapper)) { if (empty($strReturn)) { $strReturn = ''; } else { if ($boolNeedEscaping === true) { $strReturn = htmlspecialchars($strReturn); } $strReturn = sprintf($strWrapper, $strReturn); } } return $strReturn; }); $this->objTwig->addFunction($objFunction); $objFunction = new \Twig_SimpleFunction('baseUrl', function () { $strBaseUrl = Application::url(); return $strBaseUrl; }); $this->objTwig->addFunction($objFunction); $objFunction = new \Twig_SimpleFunction('prettyDateTime', function ($mulDateTime) { if (empty($mulDateTime)) { return '<i>nie określono</i>'; } else { if (intval($mulDateTime) === $mulDateTime) { $numTimestamp = $mulDateTime; } else { $numTimestamp = strtotime($mulDateTime); } } $numNow = time(); $strReturn = ''; if ($numTimestamp >= $numNow - 60 * 15) { $strReturn = 'przed chwilą'; } else { if ($numTimestamp >= $numNow - 60 * 30) { $strReturn = 'pół godziny temu'; } else { if ($numTimestamp >= $numNow - 60 * 60) { $strReturn = 'godzinę temu'; } else { if ($numTimestamp >= $numNow - 60 * 60 * 12) { $strReturn = 'w ciągu ostatnich 12 godz'; } else { $strReturn = self::prettyDate($mulDateTime); } } } } return $strReturn; }); $this->objTwig->addFunction($objFunction); $objFunction = new \Twig_SimpleFunction('prettyDate', function ($mulDateTime) { if (intval($mulDateTime) === $mulDateTime) { $numTimestamp = $mulDateTime; } else { $numTimestamp = strtotime($mulDateTime); } $numNow = time(); $strReturn = ''; if (date('Ymd', $numTimestamp) === date('Ymd', $numNow)) { $strReturn = 'dzisiaj'; } else { if (date('Ymd', $numTimestamp) === date('Ymd', $numNow - 60 * 60 * 24)) { $strReturn = 'wczoraj'; } else { $strReturn = date('d.m.Y', $numTimestamp); } } return $strReturn; }); $this->objTwig->addFunction($objFunction); $objFunction = new \Twig_SimpleFunction('pagination', function ($strPaginationName, $boolExtended = true) { $objPagination = \backend\classes\Pagination::get($strPaginationName); return $objPagination->render($boolExtended); }, array('is_safe' => array('html'))); $this->objTwig->addFunction($objFunction); $objFunction = new \Twig_SimpleFunction('currentEnvironment', function () { return Application::currentEnvironment(); }); $this->objTwig->addFunction($objFunction); $objFunction = new \Twig_SimpleFunction('makeGrid', function ($arrItems) { $strHtml = ''; if (!empty($arrItems)) { $strHtml .= '<div class="row stream-row">'; $arrConfig = array(); $arrConfig[] = array(3, array('col-md-6 col-sm-4', 'col-md-3 col-sm-4', 'col-md-3 col-sm-4')); $arrConfig[] = array(3, array('col-md-4 col-sm-6', 'col-md-4 col-sm-3', 'col-md-4 col-sm-3')); $arrConfig[] = array(4, array('col-md-2 col-sm-3', 'col-md-3 col-sm-3', 'col-md-5 col-sm-3', 'col-md-2 col-sm-3')); $numRowConfigIndex = 0; $numItemInRowIndex = 0; $strTempalatePath = dirname(__FILE__) . '/../../../../../app/imagehost2/box/artifact/view/GridItemTemplate.twig.tpl'; foreach ($arrItems as $arrItem) { if ($numItemInRowIndex === count($arrConfig[$numRowConfigIndex][1])) { // change row $numRowConfigIndex++; if ($numRowConfigIndex === count($arrConfig)) { $numRowConfigIndex = 0; } $numItemInRowIndex = 0; $strHtml .= '</div><div class="row stream-row">'; } $strCellClasses = $arrConfig[$numRowConfigIndex][1][$numItemInRowIndex]; $strCell = $this->include($strTempalatePath, $arrItem); $strHtml .= '<div class="item-wrapper ' . $strCellClasses . '">' . $strCell . '</div>'; $numItemInRowIndex++; } $strHtml .= '</div>'; } return $strHtml; }, array('is_safe' => array('html'))); $this->objTwig->addFunction($objFunction); }