Пример #1
0
 /**
  * @return array
  */
 public function getModules()
 {
     if (!isset($this->Modules)) {
         $AccessLevels = implode(',', Factory::getUser()->getAuthorizedLevels());
         $dbh = Factory::getDBH();
         $CurrentMenuID = Factory::getRouter()->getCurrentMenuID();
         if ($CurrentMenuID) {
             $MenuIDs = implode(',', $this->getAvailableMenuIDs($CurrentMenuID));
         } else {
             $MenuIDs = (int) $this->getMainMenuID();
         }
         $stmt = $dbh->prepare("SELECT mdl.ModuleID,mdl.Module FROM Module mdl\n\t\t\t\t\t\t\tINNER JOIN ModuleMenu mdlm ON mdlm.ModuleID = mdl.ModuleID\n\t\t\t\t\t\t\tWHERE mdl.blStatus = 1 AND mdl.ApplicationID = :AppID AND mdl.AccessLevelID IN ({$AccessLevels}) AND (mdlm.MenuID IN ({$MenuIDs}) OR mdlm.MenuID = 0) AND mdlm.Visible != 0 GROUP BY mdl.ModuleID ORDER BY Ordering");
         try {
             $stmt->bindValue(':AppID', Factory::getApplication()->getApplicationID(), PDO::PARAM_STR);
             $stmt->execute();
             $arModules = [];
             foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $Module) {
                 $Class = '\\Modules\\' . $Module['Module'] . '\\' . $Module['Module'];
                 /** @var Module $Object */
                 $Object = new $Class($dbh, $Module);
                 array_push($arModules, $Object);
                 $Object->initialize();
             }
             $this->Modules = $arModules;
         } catch (PDOException $e) {
             $dbh->catchException($e, $stmt->queryString);
         }
     }
     return $this->Modules;
 }
Пример #2
0
 /**
  * Logs with an arbitrary level.
  *
  * @param mixed  $level
  * @param string $message
  * @param array  $context
  * @return null
  */
 public function log($level, $message, array $context = [])
 {
     $message = $this->interpolateMessage($message, $context);
     if (Config::APP_DEBUG) {
         echo $message, PHP_EOL;
     }
     if ($level == LogLevel::EMERGENCY || $level == LogLevel::ALERT || !Factory::getDBH()) {
         if (is_writeable('error_log')) {
             $handle = fopen('error_log', 'a');
             fwrite($handle, $message . PHP_EOL);
             fclose($handle);
         }
         exit;
     } else {
         array_push($this->logs, ['UserID' => Factory::getUser()->get('ID'), 'SessionID' => Factory::getSession()->getPHP_SessionID(), 'ApplicationID' => Factory::getApplication()->getApplicationID(), 'Level' => $level, 'ErrorString' => $message, 'RegisteredDate' => Utility::getDateForDB()]);
     }
 }
Пример #3
0
 /**
  * Initialize the Application
  * Initialize the Document
  * Load the Component and execute it
  * Load the Modules if there's not an XML HTTP Request
  */
 public function initialize()
 {
     Factory::getDocument()->initialize();
     if ($this->isCLI()) {
         if ($this->getCLIOption('user') && $this->getCLIOption('password')) {
             if (!Factory::getUser()->authenticate($this->getCLIOption('user'), $this->getCLIOption('password'), true)) {
                 Factory::getLogger()->emergency('Wrong username or password');
             }
         }
     }
     $this->Component = $this->getComponentManager()->getComponent();
     if (!$this->XHRequest) {
         $this->Modules = $this->getModuleManager()->getModules();
     }
 }
Пример #4
0
 /**
  * @return mixed
  */
 public function getComponent()
 {
     if (!isset($this->Component)) {
         $dbh = Factory::getDBH();
         $_Component = Factory::getRouter()->getRoute('Component');
         $_Controller = Factory::getRouter()->getRoute('Controller');
         $Action = Factory::getRouter()->getRoute('Action');
         $ID = Factory::getRouter()->getRoute('ID');
         try {
             $stmt = $dbh->prepare('SELECT * FROM Component WHERE ApplicationID = :AppID AND blStatus = 1 AND Component = :Component;');
             try {
                 $stmt->bindValue(':AppID', $this->ApplicationID, PDO::PARAM_STR);
                 $stmt->bindValue(':Component', (string) ucfirst($_Component), PDO::PARAM_STR);
                 $stmt->execute();
                 $Component = new Object($stmt->fetch(PDO::FETCH_OBJ));
             } catch (PDOException $e) {
                 $dbh->catchException($e, $stmt->queryString);
                 throw new Exception('EpsilonCMS cannot Load Component DB');
             }
             if ($Component->get('ComponentID')) {
                 $AccessLevels = Factory::getUser()->getAuthorizedLevels();
                 /** Verify if the current user has access to the component */
                 if (!in_array($Component->get('AccessLevelID'), $AccessLevels)) {
                     if (Factory::getUser()->isGuest()) {
                         if (Factory::getApplication()->isCLI()) {
                             Factory::getLogger()->alert(Factory::getLanguage()->_('NOT_AUTHORIZED'));
                         } else {
                             Factory::getApplication()->redirectLogin();
                         }
                     } else {
                         Factory::getApplication()->redirectHome();
                     }
                 }
                 /** Creates the Class|Controller Namespace */
                 $Namespace = '\\Components\\' . $_Component . '\\Controllers\\';
                 /**
                  * If the route contains a controller use that controller
                  * else
                  * use the component name as default controller
                  */
                 if ($_Controller) {
                     $Controller = $_Controller;
                 } else {
                     $Controller = $_Component;
                 }
                 $Class = $Namespace . $Controller;
                 if (!class_exists($Class)) {
                     throw new \Exception("Controller does not exist {$Controller}->{$Action}({$ID})");
                 }
                 $Component = new $Class($dbh, $Component);
                 /** Verify if the method (Action) exist */
                 if (is_callable([$Component, $Action])) {
                     $Component->{$Action}($ID);
                 } else {
                     throw new \Exception("Controller method does not exist {$Controller}->{$Action}({$ID})");
                 }
                 $this->Component = $Component;
             } else {
                 throw new \Exception('Component {' . $_Component . '} does not exist in Database');
             }
         } catch (\Exception $e) {
             Factory::getLogger()->alert('ComponentManagerException: {Message} {File} {Line}', ['Message' => $e->getMessage(), 'File' => $e->getFile(), 'Line' => $e->getLine()]);
         }
     }
     return $this->Component;
 }
Пример #5
0
 /**
  * @param $Element
  * @return bool
  */
 public static function assignMessages($Element)
 {
     if (!isset(self::$arSystemMessagesElement[$Element])) {
         $dbh = Factory::getDBH();
         $stmt = $dbh->prepare("SELECT SystemMessageID,Type,Message FROM SystemMessage WHERE (Element = :Element OR Element = '_system' OR Element = '_DBH') AND (UserID = :UserID OR SessionID = :SessionID) AND Viewed = 0");
         try {
             $stmt->bindValue(':Element', $Element, PDO::PARAM_STR);
             $stmt->bindValue(':UserID', Factory::getUser()->get('ID'), PDO::PARAM_INT);
             $stmt->bindValue(':SessionID', Factory::getSession()->getPHP_SessionID());
             $stmt->execute();
             foreach ($stmt->fetchAll(PDO::FETCH_OBJ) as $Message) {
                 array_push(self::$arSystemMessages, new SystemMessage($dbh, $Message));
             }
             self::$arSystemMessagesElement[$Element] = true;
             return true;
         } catch (PDOException $e) {
             Factory::getDBH()->catchException($e, $stmt->queryString);
         }
     }
     return false;
 }
Пример #6
0
 public function Logout()
 {
     Factory::getUser()->logOut();
     Factory::getApplication()->redirectLogin();
 }
Пример #7
0
 public function __destruct()
 {
     if ($this->blForDeletion && $this->get('ID') == Factory::getUser()->get('ID')) {
         throw new PDOException('Cannot Delete User if current session active');
     } elseif ($this->blForDeletion) {
         $this->deleteUserGroupMap();
     }
     parent::__destruct();
 }