コード例 #1
0
ファイル: Layout.php プロジェクト: webcitron/subframe
 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;
 }
コード例 #2
0
ファイル: JsController.php プロジェクト: webcitron/subframe
 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;
 }
コード例 #3
0
ファイル: Db.php プロジェクト: webcitron/subframe
 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;
 }
コード例 #4
0
ファイル: Debug.php プロジェクト: webcitron/subframe
 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;
 }
コード例 #5
0
ファイル: View.php プロジェクト: webcitron/subframe
 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;
 }
コード例 #6
0
ファイル: CssController.php プロジェクト: webcitron/subframe
 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;
 }
コード例 #7
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];
 }
コード例 #8
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;
 }
コード例 #9
0
ファイル: Route.php プロジェクト: webcitron/subframe
 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;
 }
コード例 #10
0
ファイル: Router.php プロジェクト: webcitron/subframe
 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;
 }
コード例 #11
0
ファイル: Blitz.php プロジェクト: webcitron/subframe
 public function currentEnvironment()
 {
     return Application::currentEnvironment();
 }
コード例 #12
0
ファイル: Twig.php プロジェクト: webcitron/subframe
 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);
 }