Example #1
0
 /**
  * @param $templateName
  * @param ModuleManager $mm
  * @param $type
  * @throws ModuleException
  * @return array
  */
 private static function checkMobile($templateName, ModuleManager $mm, $type)
 {
     if ($mm->isLoaded('mobile_views')) {
         /** @var \pff\modules\MobileViews $mobileViews */
         $mobileViews = $mm->getModule('mobile_views');
         if ($mobileViews->isMobile() || $mobileViews->getMobileViewOnly()) {
             $tmp = explode('.', $templateName);
             $tmp[0] .= '_mobile';
             $tempTemplateName = implode('.', $tmp);
             if ($type == 'php') {
                 $templatePath = ROOT . DS . 'app' . DS . 'views' . DS . $tempTemplateName;
             } else {
                 // smarty
                 $templatePath = ROOT . DS . 'app' . DS . 'views' . DS . 'smarty' . DS . 'templates' . DS . $tempTemplateName;
             }
             if (file_exists($templatePath)) {
                 return $tempTemplateName;
             } else {
                 return $templateName;
             }
         } else {
             return $templateName;
         }
     } else {
         return $templateName;
     }
 }
Example #2
0
File: App.php Project: stonedz/pff2
 /**
  * Runs the application
  */
 public function run()
 {
     $this->_hookManager->runBeforeSystem();
     $urlArray = explode('/', $this->_url);
     //Deletes last element if empty
     $lastElement = end($urlArray);
     if ($lastElement == '') {
         array_pop($urlArray);
     }
     reset($urlArray);
     // If present take the first element as the controller
     $tmpController = isset($urlArray[0]) ? array_shift($urlArray) : 'index';
     $action = null;
     //Prepare the GET params in order to pass them to the Controller
     $myGet = $_GET;
     if (isset($myGet['url'])) {
         unset($myGet['url']);
     }
     if ($this->applyStaticRouting($tmpController)) {
         $this->_hookManager->runBefore();
         // Runs before controller hooks
         include ROOT . DS . $tmpController;
         $this->_hookManager->runAfter();
         // Runs after controller hooks
     } elseif ($this->applyRouting($tmpController, $action, $urlArray)) {
         $action === null ? $action = 'index' : $action;
         $tmpController = '\\pff\\controllers\\' . $tmpController;
         $controller = new $tmpController($tmpController, $this, $action, array_merge($urlArray, $myGet));
     } elseif (file_exists(ROOT . DS . 'app' . DS . 'controllers' . DS . ucfirst($tmpController) . '_Controller.php')) {
         $action = isset($urlArray[0]) ? array_shift($urlArray) : 'index';
         $controllerClassName = '\\pff\\controllers\\' . ucfirst($tmpController) . '_Controller';
         $controller = new $controllerClassName($tmpController, $this, $action, array_merge($urlArray, $myGet));
     } else {
         throw new RoutingException('Cannot find a valid controller.', 404);
     }
     if (isset($controller)) {
         $this->_action = $action;
         $this->_moduleManager->setController($controller);
         // We have a controller, let the modules know about it
         ob_start();
         $this->_hookManager->runBefore();
         // Runs before controller hooks
         if ((int) method_exists($controller, $this->_action)) {
             call_user_func_array(array($controller, "beforeAction"), $urlArray);
             call_user_func(array($controller, "beforeFilter"));
             call_user_func_array(array($controller, $this->_action), $urlArray);
             call_user_func(array($controller, "afterFilter"));
             call_user_func_array(array($controller, "afterAction"), $urlArray);
             $this->_hookManager->runAfter();
             // Runs after controller hooks
             ob_end_flush();
         } else {
             throw new RoutingException('Not a valid action: ' . $action, 404);
         }
     }
 }
Example #3
0
 public function updatePaths()
 {
     $this->set('pff_path_public', $this->_publicFolder);
     $this->set('pff_path_css', $this->_cssFolder);
     $this->set('pff_path_img', $this->_imgFolder);
     $this->set('pff_path_js', $this->_jsFolder);
     if (ModuleManager::isLoaded('pff2-s3')) {
         $s3 = ModuleManager::loadModule('pff2-s3');
         $this->set('pff_path_files', $s3->getCloudfrontUrl() ?: $this->_filesFolder);
     } else {
         $this->set('pff_path_files', $this->_filesFolder);
     }
     $this->set('pff_path_vendor', $this->_vendorFolder);
     $this->set('pff_root_ext', $this->_app->getExternalPath());
 }
 /**
  * @return bool
  * @throws \Doctrine\ORM\ORMException
  * @throws \Doctrine\ORM\OptimisticLockException
  * @throws \Doctrine\ORM\TransactionRequiredException
  * @throws PffException
  */
 public function doBefore()
 {
     $annotationReader = ModuleManager::loadModule('pff2-annotations');
     $class_permissions = $annotationReader->getClassAnnotation('Pff2Permissions');
     $method_permissions = $annotationReader->getMethodAnnotation('Pff2Permissions');
     //There's no permissions, let the user in
     if (!$method_permissions && !$class_permissions) {
         return true;
     }
     if ($method_permissions && !$class_permissions) {
         $annotations = $method_permissions;
     } else {
         if (!$method_permissions && $class_permissions) {
             $annotations = $class_permissions;
         } else {
             $annotations = array_merge($method_permissions, $class_permissions);
             $annotations = array_unique($annotations);
         }
     }
     if (isset($_SESSION['logged_data'][$this->sessionUserId])) {
         if ($this->dbType == 'odm') {
             $user = $this->_controller->_dm->find('\\pff\\models\\' . $this->userClass, $_SESSION['logged_data'][$this->sessionUserId]);
         } else {
             $user = $this->_controller->_em->find('\\pff\\models\\' . $this->userClass, $_SESSION['logged_data'][$this->sessionUserId]);
         }
         $perm = call_user_func(array($user, $this->getPermission));
         if (!$perm) {
             throw new PffException('Action not permitted', 403);
         }
     } else {
         header("Location: " . $this->_app->getExternalPath() . $this->controllerNotLogged . "/" . $this->actionNotLogged);
         exit;
     }
     foreach ($annotations as $a) {
         if (!call_user_func(array($perm, 'get' . $a))) {
             throw new PffException('Action not permitted', 403);
         }
     }
     return true;
 }
Example #5
0
 /**
  * @param string $moduleName Name of the module to load
  * @return AModule
  * @deprecated Use ModuleManager::loadModule('module_name')
  */
 public function loadModule($moduleName)
 {
     return $this->_moduleManager->getModule($moduleName);
 }