Пример #1
0
 /**
  * Get the words from each language
  * @return array 
  */
 public function getLangaugeWord()
 {
     $langPath = $this->_config->getLanguageFolder();
     $root = PathService::getRootDir();
     $absLangPath = $root . DIRECTORY_SEPARATOR . $langPath;
     $ignore = array('.', '..', '.svn', '.DS_Store');
     $langArray = array();
     if ($handle = opendir($absLangPath)) {
         while (false !== ($file = readdir($handle))) {
             $absFile = $absLangPath . DIRECTORY_SEPARATOR . $file;
             $tLangArr = array();
             if (!in_array($file, $ignore) && !is_dir($absFile)) {
                 try {
                     if (($tLangArr = @parse_ini_file($absFile, true)) == false) {
                         throw new Exception('Cannot Parse INI file: ' . $absFile);
                     }
                 } catch (Exception $e) {
                     error_log($e->getMessage());
                 }
                 $langArray = array_merge($langArray, $tLangArr);
             }
         }
     }
     return $langArray;
 }
Пример #2
0
 /**
  * Used for singleton pattern
  * 
  * @return object the instance of the class
  */
 public static function getInstance()
 {
     if (is_null(self::$instance)) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Пример #3
0
 function __construct()
 {
     $root = PathService::getRootDir();
     $this->_aclxml = $root . DIRECTORY_SEPARATOR . 'project' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'acl.xml';
     //Fallback to framework level's aclxml file
     $frameworkAclXml = $root . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'acl.xml';
     if (!file_exists($this->_aclxml)) {
         $this->_aclxml = $frameworkAclXml;
     }
 }
Пример #4
0
 /**
  * Constructor.
  * 
  * @param string $cacheFolder
  */
 function __construct($cacheFolder = NULL)
 {
     if (is_null($cacheFolder)) {
         $config = Config::getInstance();
         $root = PathService::getRootDir();
         $this->_cacheFolder = $root . DIRECTORY_SEPARATOR . $config->getCacheFolder();
     } else {
         $this->_cacheFolder = $cacheFolder;
     }
     FileCache::$lifetime = 60 * 5;
 }
Пример #5
0
 function __construct()
 {
     $root = PathService::getRootDir();
     //Read the project's config first
     //This is the project's config
     $this->_iniFilePath = $root . DIRECTORY_SEPARATOR . 'project' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.ini';
     //Fallback config path to framework's level config folder's config.ini
     //This is the framework's config
     $frameworkConfig = $root . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.ini';
     if (!file_exists($this->_iniFilePath)) {
         if (file_exists($frameworkConfig)) {
             $this->_iniFilePath = $frameworkConfig;
         } else {
             throw new AiryException("No config file in {$frameworkConfig} error!!");
         }
     }
 }
Пример #6
0
 /**
  * Constructor of the class.
  * @param string $formId
  * @param string $formName
  * @param string $uidLabel
  * @param string $pwdLabel
  * @param string $moduleName
  * @param string $formDecoration
  * @param string $loginMsgId
  * @param string $formAction
  */
 public function __construct($formId = null, $formName = null, $uidLabel = null, $pwdLabel = null, $moduleName = null, $formDecoration = null, $loginMsgId = null, $formAction = null)
 {
     $this->_formId = is_null($formId) ? self::DEFAULT_LOGIN_FORM_ID : $formId;
     $formName = is_null($formName) ? $this->_formId : $formName;
     $this->_loginMsgId = is_null($loginMsgId) ? self::DEFAULT_LOEGIN_MESSAGE_ID : $loginMsgId;
     parent::__construct($formId);
     $moduleName = !is_null($moduleName) ? $moduleName : MvcReg::getModuleName();
     $signInActionName = Authentication::getSignInAction($moduleName);
     $loginControllerName = Authentication::getLoginController($moduleName);
     $formAction = is_null($formAction) ? PathService::getFormActionURL($moduleName, $loginControllerName, $signInActionName) : $formAction;
     if (is_null($uidLabel) || $uidLabel == "") {
         $uidLabel = self::DEFAULT_UID;
     }
     if (is_null($pwdLabel) || $pwdLabel == "") {
         $pwdLabel = self::DEFAULT_PWD;
     }
     $this->_formDecoration = $formDecoration;
     $this->createForm($formAction, $this->_formId, $formName, $uidLabel, $pwdLabel, $moduleName, $this->_loginMsgId);
 }
Пример #7
0
 /**
  * Compose action view related data.
  * @see   RouterHelper::composeActionViewClassName() For knowing how data is composed. 
  * @param string $moduleName
  * @param string $controllerName
  * @param string $actionName
  * @return array Array with action view class name, action view file and absolute action view file path.
  */
 private function composeActionViewFileData($moduleName, $controllerName, $actionName)
 {
     $actionViewClassName = $this->composeActionViewClassName($actionName);
     $actionViewFile = "project" . DIRECTORY_SEPARATOR . "modules" . DIRECTORY_SEPARATOR . $moduleName . DIRECTORY_SEPARATOR . "views" . DIRECTORY_SEPARATOR . $controllerName . DIRECTORY_SEPARATOR . $actionViewClassName . ".php";
     $absActionViewFile = PathService::getRootDir() . DIRECTORY_SEPARATOR . $actionViewFile;
     return array($actionViewClassName, $actionViewFile, $absActionViewFile);
 }
Пример #8
0
 /**
  * Rendering a layout. It also renders the views that the layout contains.
  * @throws AiryException
  */
 public function render()
 {
     //To get the layout file
     $layoutContent = file_get_contents($this->_layoutPath);
     $this->prepareContent($layoutContent);
     //Fetch each views
     $viewContents = array();
     foreach ($this->_layout as $contentKey => $viewComponent) {
         //check if it is an array that contains module controller action
         if (is_array($viewComponent)) {
             $moduleName = MvcReg::getModuleName();
             $moduleName = isset($viewComponent[self::MODULE]) ? $viewComponent[self::MODULE] : $moduleName;
             try {
                 if (isset($viewComponent[self::CONTROLLER])) {
                     $controllerName = $viewComponent[self::CONTROLLER];
                 } else {
                     throw new AiryException('Layout is missing controller');
                 }
                 if (isset($viewComponent[self::ACTION])) {
                     $actionName = $viewComponent[self::ACTION];
                 } else {
                     throw new AiryException('Layout is missing controller');
                 }
                 $paramString = "";
                 if (isset($viewComponent[self::PARAMS])) {
                     $paramString = $this->getParamString($viewComponent[self::PARAMS]);
                 }
                 $HttpServerHost = PathService::getAbsoluteHostURL();
                 $config = Config::getInstance();
                 $LeadingUrl = $HttpServerHost . "/" . $config->getLeadFileName();
                 $mvcKeywords = $config->getMVCKeyword();
                 $moduleKey = $mvcKeywords['module'];
                 $controllerKey = $mvcKeywords['controller'];
                 $actionKey = $mvcKeywords['action'];
                 $moduleName = RouterHelper::hyphenToCamelCase($moduleName);
                 $controllerName = RouterHelper::hyphenToCamelCase($controllerName, TRUE);
                 $actionName = RouterHelper::hyphenToCamelCase($actionName);
                 $actionPath = $moduleKey . "=" . $moduleName . "&" . $controllerKey . "=" . $controllerName . "&" . $actionKey . "=" . $actionName;
                 $url = $LeadingUrl . "?" . $actionPath . $paramString;
                 //check if it is already signed in
                 //if yes, add current action into allow action query string
                 if (Authentication::isLogin($moduleName)) {
                     $filename = "mca_file" . microtime(true);
                     $md5Filename = md5($filename);
                     $content = $moduleName . ";" . $controllerName . ";" . $actionName;
                     $content = md5($content);
                     FileCache::saveFile($md5Filename, $content);
                     $url = $url . '&' . self::ALLOW_THIS_ACTION . '=' . $md5Filename;
                 }
                 $viewContent = $this->getData($url);
                 $viewContents[$contentKey] = $viewContent;
             } catch (Exception $e) {
                 $errorMsg = sprintf("View Exception: %s", $e->getMessage());
                 throw new AiryException($errorMsg);
             }
         } else {
             if ($viewComponent instanceof AppView) {
                 //Use $this->_view->render();
                 $viewComponent->setInLayout(true);
                 $viewContent = $viewComponent->render();
                 $viewContents[$contentKey] = $viewContent;
             } else {
                 $viewContent = file_get_contents($viewComponent);
                 $viewContent = Language::getInstance()->replaceWordByKey($viewContent);
                 $viewContents[$contentKey] = $viewContent;
             }
         }
     }
     /**
      * Deal with layout variables 
      */
     if (!is_null($this->_variables)) {
         foreach ($this->_variables as $name => $value) {
             if ($value instanceof UIComponent || $value instanceof JUIComponent) {
                 $htmlValue = $value->render();
                 $newHtmlValue = Language::getInstance()->replaceWordByKey($htmlValue);
                 ${$name} = $newHtmlValue;
             } else {
                 ${$name} = $value;
             }
         }
     }
     //Loop through each contents
     //Replace view components with keywords
     $layoutContent = $this->composeContent($layoutContent, $viewContents);
     //Check if inserting doctype at the beginning of the view content
     if (!$this->_noDoctype) {
         if (is_null($this->_doctype)) {
             $this->setDoctype();
         }
     }
     $layoutContent = $this->_doctype . $layoutContent;
     //Stream output
     $existed = in_array("airy.layout", stream_get_wrappers());
     if ($existed) {
         stream_wrapper_unregister("airy.layout");
     }
     stream_wrapper_register('airy.layout', 'StreamHelper');
     $fp = fopen("airy.layout://layout_content", "r+");
     fwrite($fp, $layoutContent);
     fclose($fp);
     include "airy.layout://layout_content";
 }
Пример #9
0
 /**
  * Get the current action URL
  * @see framework\core\PathService::getFormActionURL()
  * @param boolean $isDirective Determine if using a directory or just query string in the URL.
  */
 public function getCurrentActionURL($isDirective = False)
 {
     $moduleName = MvcReg::getModuleName();
     $controllerName = MvcReg::getControllerName();
     $actionName = MvcReg::getActionName();
     $url = PathService::getFormActionURL($moduleName, $controllerName, $actionName, null, $isDirective);
     return $url;
 }
Пример #10
0
 /**
  * The method is to prepare all the values for routing.
  * 
  * When using url redirect, the following is an example.
  * 
  * @example "See the Apache config file" The following is the rewrite rules in config file.
  * <VirtualHost *:80>
  * 		AliasMatch ^/(js|img|css)/(.*)$ /usr/local/zend/apache2/htdocs/zframework/webroot/$1/$2
  * </VirtualHost>
  * <Directory "/usr/local/zend/apache2/htdocs/zframework">
  * 		RewriteEngine on
  * 		RewriteBase /
  * 		RewriteCond %{REQUEST_URI} !\.(css|png|jpe?g|gif)$ [NC]
  * 		RewriteCond %{REQUEST_URI} !index\.php [NC]
  * 		RewriteRule  ^([^/]+)/([^/]+)/([^/]+)(.*)$ /index.php?md=$1&cl=$2&at=$3$4 [QSA]
  * </Directory>
  * The value for key at (action) will attach the key-value path. We need to resolve it.
  * 
  * @throws AiryException
  */
 private function prepare()
 {
     $this->root = PathService::getRootDir();
     $config = Config::getInstance();
     $mvc_array = $config->getMVCKeyword();
     $moduleKeyword = array_key_exists('module', $mvc_array) ? $mvc_array['module'] : "module";
     $controllerKeyword = array_key_exists('controller', $mvc_array) ? $mvc_array['controller'] : "controller";
     $actionKeyword = array_key_exists('action', $mvc_array) ? $mvc_array['action'] : "action";
     $languageKeyword = $config->getLanguageKeyword();
     $defaultLanguageCode = $config->getDefaultLanguage();
     //Before we jump into the getting params process, we need re-map the $_GET and $_POST due to the apache URL rewrite setting
     //We use RouterUrlRewritter to deal with that
     $urlRewritter = new RouterUrlRewriter();
     $urlRewritter->remapGetAndPost($actionKeyword);
     if ($_SERVER['REQUEST_METHOD'] == 'GET') {
         $keys = array_keys($_GET);
         //get URL after '?'
     } else {
         $qstringPieces = explode('&', $_SERVER['QUERY_STRING']);
         foreach ($qstringPieces as $key => $value) {
             $x = explode('=', $value);
             $value = isset($x[1]) ? $x[1] : "";
             $this->key_val_pairs[$x[0]] = $value;
             $this->qstring_keys[$x[0]];
         }
         $keys = array_keys($_POST);
         //get form variables
     }
     foreach ($keys as $key => $value) {
         if ($_SERVER['REQUEST_METHOD'] == 'GET') {
             //make to lower case
             $this->key_val_pairs[strtolower($value)] = $_GET[$value];
         } else {
             //make to lower case
             $this->key_val_pairs[strtolower($value)] = $_POST[$value];
         }
     }
     if ($moduleKeyword == $controllerKeyword || $actionKeyword == $controllerKeyword || $moduleKeyword == $actionKeyword) {
         throw new AiryException("Duplicate MVC Keywords. Module's, Controller's and Action's keywords should be unique.");
     }
     // setup module first
     if (!empty($this->key_val_pairs[$moduleKeyword])) {
         $this->moduleName = RouterHelper::hyphenToCamelCase($this->key_val_pairs[$moduleKeyword]);
         //module name
         $this->setModule($this->moduleName);
         unset($this->key_val_pairs[$moduleKeyword]);
     } else {
         $this->moduleName = $config->getDefaultModule();
         //no module name means "default" module
         $this->setModule($this->moduleName);
     }
     //Set Controller Name; also set the default model and view here
     //Controller's first letter is upper case
     if (!empty($this->key_val_pairs[$controllerKeyword])) {
         $this->controllerName = RouterHelper::hyphenToCamelCase($this->key_val_pairs[$controllerKeyword], TRUE);
         $this->setDefaultModelView($this->controllerName);
         MvcReg::setControllerName($this->controllerName);
         $this->controller = $this->controllerName . self::CONTROLLER_POSTFIX;
         //controller name
         unset($this->key_val_pairs[$controllerKeyword]);
     } else {
         $this->controllerName = ucfirst(self::DEFAULT_PREFIX);
         $this->controller = $this->controllerName . self::CONTROLLER_POSTFIX;
         $this->setDefaultModelView(self::DEFAULT_PREFIX);
         MvcReg::setControllerName($this->controllerName);
     }
     //Setting action
     if (!empty($this->key_val_pairs[$actionKeyword])) {
         $this->actionName = RouterHelper::hyphenToCamelCase($this->key_val_pairs[$actionKeyword]);
         MvcReg::setActionName($this->actionName);
         $this->action = RouterHelper::hyphenToCamelCase($this->key_val_pairs[$actionKeyword]) . self::ACTION_POSTFIX;
         //action name
         unset($this->key_val_pairs[$actionKeyword]);
     } else {
         $this->actionName = self::DEFAULT_PREFIX;
         MvcReg::setActionName($this->actionName);
         $this->action = self::DEFAULT_PREFIX . self::ACTION_POSTFIX;
     }
     $this->setDefaultActionView($this->controllerName, $this->actionName);
     $this->setModuleControllerAction($this->moduleName, $this->controllerName, $this->actionName);
     //Setting language code and Session
     if (!empty($this->key_val_pairs[$languageKeyword])) {
         $this->languageCode = $this->key_val_pairs[$languageKeyword];
         $this->setLanguageCode($this->languageCode);
         //set langauge session based on module
         //@TODO: need to consider to add a project layer in the futuure
         $_SESSION[$this->moduleName][self::LANGUAGE_CODE] = $this->languageCode;
         unset($this->key_val_pairs[$languageKeyword]);
     } else {
         if (!empty($_SESSION[$this->moduleName][self::LANGUAGE_CODE])) {
             $this->setLanguageCode($_SESSION[$this->moduleName][self::LANGUAGE_CODE]);
         } else {
             $this->setLanguageCode($defaultLanguageCode);
             //@TODO: need to consider to add a project layer in the futuure
             $_SESSION[$this->moduleName][self::LANGUAGE_CODE] = $defaultLanguageCode;
         }
     }
     //Getting serialize data for setting authentication allowing actions
     if (!empty($this->key_val_pairs[self::ALLOW_THIS_ACTION])) {
         if (isset($this->key_val_pairs[self::ALLOW_THIS_ACTION])) {
             $filename = $this->key_val_pairs[self::ALLOW_THIS_ACTION];
             $checkContent = $this->moduleName . ";" . $this->controllerName . ";" . $this->actionName;
             $checkContent = md5($checkContent);
             if (trim(FileCache::getFile($filename)) == trim($checkContent)) {
                 Authentication::addLayoutAllowAction($this->moduleName, $this->controllerName, $this->actionName);
                 FileCache::removeFile($filename);
             }
         }
         unset($this->key_val_pairs[self::ALLOW_THIS_ACTION]);
     }
     $this->params = $this->key_val_pairs;
     Parameter::unsetAllParams();
     Parameter::setParams($this->params);
 }
Пример #11
0
 /**
  * This initialize those include path.
  * 
  */
 public static function initialize()
 {
     //this is set for FileCache usage
     $root = PathService::getRootDir();
     $configFile = $root . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "config.ini";
     if (file_exists($configFile)) {
         set_include_path(get_include_path() . PATH_SEPARATOR . "app" . DIRECTORY_SEPARATOR . "library" . DIRECTORY_SEPARATOR . "cache");
         if (!is_null(FileCache::get(self::FILECACHE))) {
             set_include_path(FileCache::get(self::FILECACHE));
             return;
         }
     }
     set_include_path(get_include_path() . PATH_SEPARATOR . "core");
     set_include_path(get_include_path() . PATH_SEPARATOR . "config");
     set_include_path(get_include_path() . PATH_SEPARATOR . "app");
     set_include_path(get_include_path() . PATH_SEPARATOR . "app" . DIRECTORY_SEPARATOR . "library");
     set_include_path(get_include_path() . PATH_SEPARATOR . "project");
     set_include_path(get_include_path() . PATH_SEPARATOR . "project" . DIRECTORY_SEPARATOR . "share");
     set_include_path(get_include_path() . PATH_SEPARATOR . "project" . DIRECTORY_SEPARATOR . "modules");
     set_include_path(get_include_path() . PATH_SEPARATOR . "plugin");
     //set module paths
     $modulePath = $root . DIRECTORY_SEPARATOR . "project" . DIRECTORY_SEPARATOR . "modules";
     $moduleFolders = Initializer::getDirectory($modulePath, TRUE);
     foreach ($moduleFolders as $i => $mfolder) {
         $fd = trim($mfolder);
         $rp = trim($modulePath) . DIRECTORY_SEPARATOR;
         $f = "modules" . DIRECTORY_SEPARATOR . str_replace($rp, "", $fd);
         set_include_path(get_include_path() . PATH_SEPARATOR . $f);
     }
     /**
      * include folders under project, library, plug-in
      *  
      */
     $plugIn = $root . DIRECTORY_SEPARATOR . "plugin";
     $coreLib = $root . DIRECTORY_SEPARATOR . "app" . DIRECTORY_SEPARATOR . "library";
     $project = $root . DIRECTORY_SEPARATOR . "project";
     $plugInFolders = Initializer::getDirectory($plugIn, TRUE);
     foreach ($plugInFolders as $i => $folder1) {
         $fd = trim($folder1);
         $rp = trim($plugIn) . DIRECTORY_SEPARATOR;
         $f = "plugin" . DIRECTORY_SEPARATOR . str_replace($rp, "", $fd);
         set_include_path(get_include_path() . PATH_SEPARATOR . $f);
     }
     $coreLibFolders = Initializer::getDirectory($coreLib, TRUE);
     foreach ($coreLibFolders as $i => $folder1) {
         $fd = trim($folder1);
         $rp = trim($coreLib) . DIRECTORY_SEPARATOR;
         $f = "app" . DIRECTORY_SEPARATOR . "library" . DIRECTORY_SEPARATOR . str_replace($rp, "", $fd);
         set_include_path(get_include_path() . PATH_SEPARATOR . $f);
     }
     $projectFolders = Initializer::getDirectory($project, TRUE);
     foreach ($projectFolders as $i => $folder1) {
         $fd = trim($folder1);
         $rp = trim($project) . DIRECTORY_SEPARATOR;
         $f = "project" . DIRECTORY_SEPARATOR . str_replace($rp, "", $fd);
         set_include_path(get_include_path() . PATH_SEPARATOR . $f);
     }
     if (file_exists($configFile)) {
         FileCache::save(self::FILECACHE, get_include_path());
     }
 }
Пример #12
0
 /**
  * This method render the view.
  *
  * @throws Exception 
  * @var  $httpServerHost absolute host url.
  * @var  $serverHost absolute host path.
  * @var  $ABSOLUTE_URL absolute host url.
  * @var  $SERVER_HOST absolute host path.
  * @var  $LEAD_FILENAME leading filename ex: index.php.
  * 
  */
 public function render()
 {
     try {
         if (!is_null($this->_viewFilePath) && file_exists($this->_viewFilePath)) {
             if (!is_null($this->_variables)) {
                 foreach ($this->_variables as $name => $value) {
                     if ($value instanceof UIComponent || $value instanceof JsUIComponentInterface) {
                         $htmlValue = $value->render();
                         $newHtmlValue = $this->_languageService->replaceWordByKey($htmlValue);
                         ${$name} = $newHtmlValue;
                         $this->hasAnyScript($newHtmlValue);
                     } else {
                         ${$name} = $value;
                     }
                 }
             }
             $httpServerHost = PathService::getAbsoluteHostURL();
             $serverHost = PathService::getAbsoluteHostPath();
             $ABSOLUTE_URL = PathService::getAbsoluteHostURL();
             $SERVER_HOST = PathService::getAbsoluteHostPath();
             $LEAD_FILENAME = Config::getInstance()->getLeadFileName();
             $viewContent = file_get_contents($this->_viewFilePath);
             $this->hasAnyScript($viewContent);
             //hasScript check if there is a need for javascript library to be added in
             //If there is no javascript UI component, but setScript == true, we still
             //add plugins. Otherwise, we simply do not add any libraries.
             if ($this->_hasScript) {
                 //add plugins
                 $viewContent = $this->addPluginLib($viewContent);
             }
             //$viewContent = $this->_languageService->replaceWordByKey($viewContent);
             //Check if inserting doctype at the beginning of the view content
             if (!$this->_inLayout) {
                 if (!$this->_noDoctype) {
                     if (is_null($this->_doctype)) {
                         $this->setDoctype();
                     }
                     $viewContent = $this->_doctype . $viewContent;
                 }
             }
             $fp = fopen("airy.view://view_content", "r+");
             fwrite($fp, $viewContent);
             fclose($fp);
             if (!$this->_inLayout) {
                 //use ob_start to push all include files into a buffer
                 //and then call the callback function replaceLanguageWords
                 //only use stream writter cannot fulfill this
                 ob_start(array($this, 'replaceLanguageWords'));
                 include "airy.view://view_content";
                 ob_end_flush();
             } else {
                 $this->_viewScripts = file_get_contents("airy.view://view_content");
                 return $this->_viewScripts;
             }
         } else {
             throw new Exception("No View File {$this->_viewFilePath} Existed!");
         }
     } catch (Exception $e) {
         echo 'Exception: ', $e->getMessage(), "\n";
     }
 }