Example #1
0
 public function render($arrLayoutData = array())
 {
     $arrBoxesResponseContents = array();
     foreach ($this->arrPlaceholderBoxes as $strPlaceholderName => $arrBoxes) {
         $arrBoxesResponseContents[$strPlaceholderName] = array();
         foreach ($arrBoxes as $objBox) {
             $objBoxResponse = $objBox->launch();
             $arrBoxesResponseContents[$strPlaceholderName][] = $objBoxResponse->__toString();
         }
     }
     $strLayoutFullName = get_called_class();
     $arrLayoutFullNameTokens = explode('\\', $strLayoutFullName);
     $strLayoutName = array_pop($arrLayoutFullNameTokens);
     $strLayoutPath = sprintf('%s/layout/view/%s', Application::getInstance()->strDirectory, $strLayoutName);
     $objTemplater = Templater::createSpecifiedTemplater(Config::get('templater'));
     $objCurrentRoute = Router::getCurrentRoute();
     if (!empty($objCurrentRoute)) {
         $arrLayoutData['route'] = array('name' => $objCurrentRoute->strRouteName, 'action' => $objCurrentRoute->strMethodName);
     }
     if (method_exists($this, 'launch')) {
         $arrLayoutData = array_merge($this->launch(), $arrLayoutData);
     }
     $strLayoutContent = $objTemplater->getTemplateFileContent($strLayoutPath, $arrLayoutData);
     foreach ($this->arrPlaceholderBoxes as $strPlaceholderName => $arrBoxes) {
         $strLayoutContent = str_replace(sprintf('[placeholder:%s]', $strPlaceholderName), join('', $arrBoxesResponseContents[$strPlaceholderName]), $strLayoutContent);
     }
     // removing unused placeholders
     $strLayoutContent = preg_replace('/\\[placeholder\\:([a-z\\-]+)\\]/', '', $strLayoutContent);
     //        echo $strLayoutContent;exit();
     //        echo $strLayoutContent;exit();
     return $strLayoutContent;
 }
Example #2
0
 public function render($objCurrentRoute)
 {
     $strLayoutName = $this->strLayoutName;
     $strViewName = $this->strView;
     $arrData = $this->arrData;
     $arrMetaData = $this->arrMetaData;
     $objTemplater = \webcitron\Subframe\Application::getInstance()->objTemplater;
     echo 'render';
     $strOutput = $objTemplater->renderResponseView($objCurrentRoute, $strLayoutName, $strViewName, $arrData, $arrMetaData);
     return $strOutput;
 }
Example #3
0
 private function __construct($strConnectionName, $numCurrentEnvironment)
 {
     $objApplication = Application::getInstance();
     require $objApplication->strDirectory . '/config/database.php';
     $arrConnection = self::$arrConnections[$strConnectionName][$numCurrentEnvironment];
     $strDsn = sprintf("pgsql:host=%s;dbname=%s", $arrConnection['server'], $arrConnection['db']);
     $numCurrentEnv = Application::currentEnvironment();
     switch ($numCurrentEnv) {
         case Application::ENVIRONMENT_PRODUCTION:
             $this->objPdo = new \PDO($strDsn, $arrConnection['auth'][0], $arrConnection['auth'][1], array(\PDO::ATTR_ERRMODE => \PDO::ERRMODE_WARNING));
             break;
         default:
             $this->objPdo = new LoggedPdo($strDsn, $arrConnection['auth'][0], $arrConnection['auth'][1], array(\PDO::ATTR_ERRMODE => \PDO::ERRMODE_WARNING));
             break;
     }
     $this->objPdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
     $this->objPdo->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_ASSOC);
     $this->objPdo->exec("SET NAMES 'UTF8'");
 }
Example #4
0
 public function fireMethod($strMethodPointer, $arrParams, $strRawMethodPath)
 {
     $objApplicationContext = \webcitron\Subframe\Application::getInstance();
     require APP_DIR . '/' . $objApplicationContext->strName . '/config/rpcapi.php';
     if (!in_array($strMethodPointer, $this->arrAllowedMethods)) {
         $strInfo = $strMethodPointer . ' - that rpc method is not allowed do use remotely';
         $objResponse['error'] = $strInfo;
         if (!empty($this->strErrorHandlerFunction)) {
             $arrCall = array('strMethodPointer' => $strMethodPointer, 'strMethodRawPath' => $strRawMethodPath, 'arrParams' => $arrParams);
             $arrErrorHandlerTokens = explode('::', $this->strErrorHandlerFunction);
             $objErrorHandlerReflection = new \ReflectionMethod($arrErrorHandlerTokens[0], $arrErrorHandlerTokens[1]);
             $objErrorHandlerReflection->invoke(null, $strInfo, $arrCall);
         }
     } else {
         $arrMethodPointerTokens = explode('.', $strMethodPointer);
         $strMethodName = array_pop($arrMethodPointerTokens);
         $strClassFullPath = sprintf('\\%s', join('\\', $arrMethodPointerTokens));
         $objBoardMethod = new \ReflectionMethod($strClassFullPath, $strMethodName);
         //            print_r($arrParams);
         $objResponse = $objBoardMethod->invokeArgs(null, $arrParams);
     }
     return $objResponse;
 }
Example #5
0
 private static function loadConfig()
 {
     $objApplication = Application::getInstance();
     require $objApplication->strDirectory . '/config/memcache.php';
     self::$boolConfigLoaded = true;
 }
Example #6
0
 public function loadRoutes()
 {
     require Application::getInstance()->strDirectory . '/config/routes.php';
 }
Example #7
0
 public static function renderHeadAddons()
 {
     $objJsController = \webcitron\Subframe\JsController::getInstance();
     $objApplication = Application::getInstance();
     $strHeadAddons = $objJsController->render($objApplication->strName);
     return $strHeadAddons;
 }
Example #8
0
 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);
 }