Example #1
0
 /**
  * @param Context $context
  */
 public function __construct(Context $context)
 {
     $this->translateInline = $context->getTranslateInline();
     $this->_moduleManager = $context->getModuleManager();
     $this->_logger = $context->getLogger();
     $this->_request = $context->getRequest();
     $this->_urlBuilder = $context->getUrlBuilder();
     $this->_httpHeader = $context->getHttpHeader();
     $this->_eventManager = $context->getEventManager();
     $this->_remoteAddress = $context->getRemoteAddress();
     $this->_cacheConfig = $context->getCacheConfig();
 }
 /**
  * @param Context $context
  */
 public function __construct(Context $context)
 {
     $this->_moduleManager = $context->getModuleManager();
     $this->_logger = $context->getLogger();
     $this->_request = $context->getRequest();
     $this->_urlBuilder = $context->getUrlBuilder();
     $this->_httpHeader = $context->getHttpHeader();
     $this->_eventManager = $context->getEventManager();
     $this->_remoteAddress = $context->getRemoteAddress();
     $this->_cacheConfig = $context->getCacheConfig();
     $this->urlEncoder = $context->getUrlEncoder();
     $this->urlDecoder = $context->getUrlDecoder();
     $this->scopeConfig = $context->getScopeConfig();
 }
Example #3
0
 /**
  * Log a message to the logger
  *
  * @param string $message The message to log
  * @param string $category [optional] The message category (default "main")
  * @param integer $level [optional] The loglevel
  */
 public static function log($message, $category = 'main', $level = 1)
 {
     if (!self::$_logging_enabled) {
         return false;
     }
     if (self::$_loglevel > $level) {
         return false;
     }
     if (self::$_cli_log_to_screen_in_debug_mode && Context::isCLI() && Context::isDebugMode() && class_exists('\\thebuggenie\\core\\framework\\cli\\Command')) {
         \thebuggenie\core\framework\cli\Command::cli_echo(mb_strtoupper(self::getLevelName($level)), 'white', 'bold');
         \thebuggenie\core\framework\cli\Command::cli_echo(" [{$category}] ", 'green', 'bold');
         \thebuggenie\core\framework\cli\Command::cli_echo("{$message}\n");
     }
     if (self::$_logonajaxcalls || Context::getRequest()->isAjaxCall()) {
         if (self::$_logfile !== null) {
             file_put_contents(self::$_logfile, mb_strtoupper(self::getLevelName($level)) . " [{$category}] {$message}\n", FILE_APPEND);
         }
         $time_msg = Context::isDebugMode() ? ($load_time = Context::getLoadtime()) >= 1 ? round($load_time, 2) . ' seconds' : round($load_time * 1000, 3) . ' ms' : '';
         self::$_entries[] = array('category' => $category, 'time' => $time_msg, 'message' => $message, 'level' => $level);
         self::$_categorized_entries[$category][] = array('time' => $time_msg, 'message' => $message, 'level' => $level);
     }
 }
Example #4
0
 /**
  * Forward the user with HTTP status code 403 and an (optional) message
  * based on a boolean check
  *
  * @param boolean $condition
  * @param string $message [optional] The message
  */
 public function forward403unless($condition, $message = null)
 {
     if (!$condition) {
         $message = $message === null ? Context::getI18n()->__("You are not allowed to access this page") : htmlentities($message);
         if (Context::getUser()->isGuest()) {
             Context::setMessage('login_message_err', $message);
             Context::setMessage('login_force_redirect', true);
             Context::setMessage('login_referer', Context::getRouting()->generate(Context::getRouting()->getCurrentRouteName(), Context::getRequest()->getParameters()));
             $this->forward(Context::getRouting()->generate('login_page'), 403);
         } else {
             $this->getResponse()->setHttpStatus(403);
             $this->getResponse()->setTemplate('main/forbidden');
         }
     }
 }
Example #5
0
 /**
  * Setup filter-by data (to be kept in the 'pagingInfo' object), based on
  * parameters that may exist in the request.
  *
  * @param Context $ctx
  */
 private function initFiltering($ctx)
 {
     $searchString = $ctx->getRequest()->getString('sSearch', '');
     $searchColumns = array();
     if (!empty($searchString)) {
         $searchColumns = $this->getSearchColumns();
     }
     $this->pagingInfo->setSearchString($searchString);
     $this->pagingInfo->setSearchColumns($searchColumns);
 }
Example #6
0
 public function testGetRequest()
 {
     $this->assertInstanceOf('\\Magento\\Framework\\App\\Request\\Http', $this->context->getRequest());
 }
 /**
  * Present a template
  * @param string $template_file
  * @param array $params
  */
 public static function presentTemplate($template_file, $params = array())
 {
     Logging::log("configuring template variables for template {$template_file}");
     if (!file_exists($template_file)) {
         throw new exceptions\TemplateNotFoundException("The template file <b>{$template_file}</b> cannot be found.");
     }
     foreach ($params as $key => $val) {
         ${$key} = $val;
     }
     if (array_key_exists('key', $params)) {
         $key = $params['key'];
     }
     if (array_key_exists('val', $params)) {
         $val = $params['val'];
     }
     /**
      * @global \thebuggenie\core\framework\Request The request object
      */
     $tbg_request = Context::getRequest();
     /**
      * @global \thebuggenie\core\framework\Response The response object
      */
     $tbg_response = Context::getResponse();
     /**
      * @global \thebuggenie\core\framework\Request The request object
      */
     $tbg_routing = Context::getRouting();
     /**
      * @global \thebuggenie\core\entities\User The user object
      */
     $tbg_user = Context::getUser();
     Context::loadLibrary('common');
     Context::loadLibrary('ui');
     Logging::log("rendering template '{$template_file}'");
     require $template_file;
 }
Example #8
0
 /**
  * Forward the user to a different URL
  *
  * @param string $url the url to forward to
  * @param integer $code HTTP status code
  */
 public function headerRedirect($url, $code = 302)
 {
     Logging::log('Running header redirect function');
     $this->clearHeaders();
     $this->setHttpStatus($code);
     if (Context::getRequest()->isAjaxCall() || Context::getRequest()->getRequestedFormat() == 'json') {
         $this->renderHeaders();
     } else {
         $this->addHeader("Location: {$url}");
         $this->renderHeaders();
     }
     exit;
 }
Example #9
0
 /**
  * @covers Context::getRequest
  * @covers Context::__construct
  * @covers Context::newUIManager
  */
 public function testGetRequest()
 {
     $actual = $this->ctx->getRequest();
     $this->assertInstanceOf("Request", $actual);
 }
Example #10
0
 /**
  * Forward the user with HTTP status code 403 and an (optional) message
  * based on a boolean check
  *
  * @param boolean $condition
  * @param string $message [optional] The message
  */
 public function forward403unless($condition, $message = null)
 {
     if (!$condition) {
         $message = $message === null ? Context::getI18n()->__("You are either not allowed to access this page or don't have access to perform this action") : $message;
         if (Context::getUser()->isGuest()) {
             Context::setMessage('login_message_err', htmlentities($message));
             Context::setMessage('login_force_redirect', true);
             Context::setMessage('login_referer', Context::getRouting()->generate(Context::getRouting()->getCurrentRouteName(), Context::getRequest()->getParameters()));
             $this->forward(Context::getRouting()->generate('login_page'), Response::HTTP_STATUS_FORBIDDEN);
         } elseif (Context::getRequest()->isAjaxCall()) {
             $this->getResponse()->setHttpStatus(Response::HTTP_STATUS_FORBIDDEN);
             throw new \Exception($message);
         } else {
             throw new \thebuggenie\core\framework\exceptions\ActionNotAllowedException($message);
         }
     }
 }
 public function execute()
 {
     $module = $this->context->getModuleName();
     $action = $this->context->getActionName();
     // if module exist include the class
     if ($module !== null) {
         //    		//check if there is a specified context first
         //			$isSpecificContext = false;
         //    		if(count($this->context->getSpecifiers()) > 0){
         //				foreach($this->context->getSpecifiers() as $specifier){
         //
         //					$expectedPath = DIR_ACTIONS . $specifier . '/class.' . $module . '.php';
         //
         //					//if we find the view in the specialized context, we load it
         //					if (file_exists($expectedPath)){
         //						require_once ($expectedPath);
         //						$isSpecificContext = true;
         //						break;
         //					}
         //				}
         //			}
         //
         //			//if there is none, we look at the global context
         //			if(!$isSpecificContext){
         $exptectedPath = DIR_ACTIONS . 'class.' . $module . '.php';
         if (file_exists($exptectedPath)) {
             require_once $exptectedPath;
         } else {
             throw new ActionEnforcingException("Module '" . Camelizer::firstToUpper($module) . "' does not exist in {$exptectedPath}.", $this->context->getModuleName(), $this->context->getActionName());
         }
         //			}
         if (defined('ROOT_PATH')) {
             $root = realpath(ROOT_PATH);
         } else {
             $root = realpath($_SERVER['DOCUMENT_ROOT']);
         }
         if (preg_match("/^\\//", $root) && !preg_match("/\\/\$/", $root)) {
             $root .= '/';
         } else {
             if (!preg_match("/\\\$/", $root)) {
                 $root .= '\\';
             }
         }
         $relPath = str_replace($root, '', realpath(dirname($exptectedPath)));
         $relPath = str_replace('/', '_', $relPath);
         $relPath = str_replace('\\', '_', $relPath);
         $className = $relPath . '_' . $module;
         if (!class_exists($className)) {
             throw new ActionEnforcingException("Unable to load  {$className} in {$exptectedPath}", $this->context->getModuleName(), $this->context->getActionName());
         }
         // File gracefully loaded.
         $this->context->setModuleName($module);
         $this->context->setActionName($action);
         $moduleInstance = new $className();
     } else {
         throw new ActionEnforcingException("No Module file matching requested module.", $this->context->getModuleName(), $this->context->getActionName());
     }
     // if the method related to the specified action exists, call it
     if (method_exists($moduleInstance, $action)) {
         // search parameters method
         $reflect = new ReflectionMethod($className, $action);
         $parameters = $reflect->getParameters();
         $tabParam = array();
         foreach ($parameters as $param) {
             $tabParam[$param->getName()] = $this->context->getRequest()->getParameter($param->getName());
         }
         // Action method is invoked, passing request parameters as
         // method parameters.
         common_Logger::d('Invoking ' . get_class($moduleInstance) . '::' . $action, array('GENERIS', 'CLEARRFW'));
         call_user_func_array(array($moduleInstance, $action), $tabParam);
         // Render the view if selected.
         if ($view = $moduleInstance->getView()) {
             $renderer = new Renderer();
             $renderer->render($view);
         }
     } else {
         throw new ActionEnforcingException("Unable to find the appropriate action for Module '{$module}'.", $this->context->getModuleName(), $this->context->getActionName());
     }
 }