Example #1
0
 /**
  * Get the value for checking if the user is logined.
  * @param string $moduleName The default value = NULL
  * @return string The isLogin value in the session.
  */
 public function isLogin($moduleName = null)
 {
     if (!is_null($moduleName)) {
         return $_SESSION[$moduleName][Authentication::UID];
     }
     $currentModuleName = MvcReg::getModuleName();
     return $_SESSION[$currentModuleName][Authentication::UID];
 }
Example #2
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);
 }
Example #3
0
 /**
  * Set the action name
  *
  * @param string $actionName
  */
 public static function setActionName($actionName)
 {
     self::$_actionName = $actionName;
 }
Example #4
0
 /**
  * Get the current language that is used.
  *
  * @param string $moduleName the module name
  * @return string the language code
  */
 public static function getCurrentUseLanguageCode($moduleName = null)
 {
     $moduleName = is_null($moduleName) ? MvcReg::getModuleName() : $moduleName;
     return $_SESSION[$moduleName][self::LANGUAGE_CODE];
 }
Example #5
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";
 }
Example #6
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;
 }
Example #7
0
 /**
  * Set the module.
  * @param string $moduleName
  * @param string $controllerName
  * @param string $actionName
  */
 public function setModuleControllerAction($moduleName, $controllerName, $actionName)
 {
     MvcReg::setModuleName($moduleName);
     MvcReg::setControllerName($controllerName);
     MvcReg::setActionName($actionName);
 }
Example #8
0
 /**
  * Prepare the login form object for the view.
  * 
  * @example 
  * FormLayout example:
  * 
  * array(formId      => array('<div class="class_selector">', '</div>'),
  *       elementId1  => array('<div class="elememtClass1">', '</div>'),
  *       elementId2  => array('<div class="elememtClass2">', '</div>'),
  *       ...
  *       {elementId} => array('{open_html}, {close_html})
  *      );
  *
  * @see framework\app\library\acl\LoginForm 
  * @return object The login form object.
  */
 public function prepareLoginForm()
 {
     $this->_moduleName = is_null($this->_moduleName) ? MvcReg::getModuleName() : $this->_moduleName;
     $this->_formName = is_null($this->_formName) ? "system_login_form" : $this->_formName;
     $this->_formId = is_null($this->_formId) ? "system_login_form" : $this->_formId;
     $this->_uidLabel = is_null($this->_uidLabel) ? "%{Username}%" : $this->_uidLabel;
     $this->_pwdLabel = is_null($this->_pwdLabel) ? "%{Password}%" : $this->_pwdLabel;
     $this->_loginMsgId = is_null($this->_loginMsgId) ? "system_login_message" : $this->_loginMsgId;
     $this->_formLayout = array($this->_formId => array("<div class='{$this->_formName}' name='{$this->_formName}'>", "</div>"));
     $loginForm = new LoginForm($this->_formId, $this->_formName, $this->_uidLabel, $this->_pwdLabel, $this->_moduleName, $this->_formLayout, $this->_loginMsgId, null);
     return $loginForm;
 }
Example #9
0
 /**
  * Unset params to Session based on the module
  */
 public static function unsetModuleSession($params)
 {
     $moduleName = MvcReg::getModuleName();
     foreach ($params as $key => $value) {
         unset($_SESSION[$moduleName][$key]);
     }
 }