Example #1
0
 public static function getInstance($strConnectionName = 'default')
 {
     if (!isset(self::$arrInstances[$strConnectionName])) {
         $numCurrentEnvironment = Application::currentEnvironment();
         \webcitron\Subframe\Debug::log('Connect to DB ' . $strConnectionName, 'core-db');
         self::$arrInstances[$strConnectionName] = new Db($strConnectionName, $numCurrentEnvironment);
     }
     return self::$arrInstances[$strConnectionName]->objPdo;
 }
Example #2
0
 public static function output()
 {
     self::log(sprintf('current environment: %s', Application::currentEnvironment()), 'core');
     $strContainer = "<pre class='container' style='font-size: 1em;border:1px solid #888; margin:20px auto; padding: 20px; background-color:#f8f8f8;'>%s</pre>";
     $strContent = join('', self::$arrMessages);
     $strOutput = sprintf($strContainer, $strContent);
     self::$boolAlreadyPrinted = true;
     return $strOutput;
 }
Example #3
0
 public function __construct($strServerName)
 {
     if (self::$boolConfigLoaded === false) {
         self::loadConfig();
     }
     $numCurrentEnvironment = Application::currentEnvironment();
     if (!isset(self::$arrRunningInstances[$numCurrentEnvironment][$strServerName])) {
         $arrConfig = self::$arrServers[$numCurrentEnvironment][$strServerName];
         $objMemcache = new \Memcache();
         $objMemcache->connect('localhost', $arrConfig['numPort']);
         Debug::log('Connected to localhost:' . $arrConfig['numPort'], 'memcache');
         //            $objMemcache->addServer('localhost', $arrConfig['numPort']);
         //            print_r($objMemcached);
         //            exit('s');
         //            self::$arrRunningInstances[$numCurrentEnvironment][$strServerName]->connect('localhost', $arrConfig['numPort']);
         self::$arrRunningInstances[$numCurrentEnvironment][$strServerName] = $objMemcache;
         $this->arrCurrentConfig = $arrConfig;
     }
     $this->objMemcache = self::$arrRunningInstances[$numCurrentEnvironment][$strServerName];
 }
Example #4
0
 public function getRouteByNameAndLang($strRouteName, $strLanguage)
 {
     $objRoute = null;
     if (!empty($this->arrRoutes[$strLanguage][$strRouteName])) {
         $objRoute = $this->arrRoutes[$strLanguage][$strRouteName];
     } else {
         if (!empty($this->arrRoutes[$strRouteName])) {
             $objRoute = $this->arrRoutes[$strRouteName];
         } else {
             if (Application::currentEnvironment() !== Application::ENVIRONMENT_PRODUCTION) {
                 echo '<pre>';
                 print_r(debug_backtrace());
                 echo '</pre>';
                 exit('Nie zdefiniowana ścieżka ' . $strLanguage . '/' . $strRouteName);
             }
         }
     }
     return $objRoute;
 }
Example #5
0
 public function currentEnvironment()
 {
     return Application::currentEnvironment();
 }
Example #6
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);
 }