Beispiel #1
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;
 }
Beispiel #2
0
 /**
  * @param      $Results
  * @param      $ElementID
  * @param null $MaxPageSize
  * @return \Epsilon\Object\Object
  */
 public static function foundationListPaging($Results, $ElementID, $MaxPageSize = null)
 {
     $CurrentPage = Input::getVar("CurrentPage", "REQUEST");
     if (is_integer($MaxPageSize)) {
         $PageSize = $MaxPageSize;
     } else {
         $PageSize = Config::MAX_PAGE_SIZE;
     }
     $Paging = new Object(['HTML' => null, 'Init' => 0, 'Max' => $PageSize, 'Results' => 0, 'PageInit' => 0, 'PageMax' => 0, 'TotalPages' => 0, 'TotalResults' => 0]);
     if (is_array($Results)) {
         $TotalResults = count($Results);
     } else {
         if (is_numeric($Results)) {
             $TotalResults = $Results;
         } else {
             $TotalResults = 0;
         }
     }
     if ($TotalResults > 0) {
         $TotalPages = self::getTotalPages($TotalResults, $PageSize);
         if ($CurrentPage > $TotalPages) {
             $CurrentPage = $TotalPages;
         } elseif (!is_numeric($CurrentPage) || !((int) $CurrentPage > 0) || (int) $CurrentPage == 0) {
             $CurrentPage = 1;
         }
         if ($CurrentPage > 1) {
             $Init = ($CurrentPage - 1) * $PageSize;
             $Max = $PageSize;
             $PageInit = ($CurrentPage - 1) * $PageSize + 1;
             $PageMax = $PageInit + $PageSize - 1;
         } else {
             $Init = 0;
             $Max = $PageSize;
             $PageInit = 1;
             $PageMax = $PageInit + $Max - 1;
         }
         if ($PageMax >= $TotalResults) {
             $PageMax = $TotalResults;
         }
         $Pages = self::getPages($CurrentPage, $TotalPages);
         $HTML = "";
         $PreviousSet = false;
         if (is_string($ElementID)) {
             $ElementID = "\"{$ElementID}\"";
         } else {
             $ElementID = "null";
         }
         $eLanguage = Factory::getLanguage();
         $PagesCount = 0;
         foreach ($Pages as $p) {
             $PagesCount++;
             if (!$PreviousSet) {
                 $Previus = $CurrentPage - 1;
                 if ($CurrentPage != 1) {
                     $HTML .= "<ul class=\"pagination text-center\" role=\"navigation\" aria-label=\"Pagination\">\n<li class=\"pagination-previous\"><a href='javascript:goToPage({$Previus}, {$ElementID})'><span class=\"show-for-sr\">page</span> " . $eLanguage->_("LIST-RESULT-PREVIOUS") . "</a></li>\n";
                 } else {
                     $HTML .= "<ul class=\"pagination text-center\" role=\"navigation\" aria-label=\"Pagination\">\n<li class=\"pagination-previous disabled\"><span class=\"show-for-sr\">page</span> " . $eLanguage->_("LIST-RESULT-PREVIOUS") . "</li>\n";
                 }
                 $PreviousSet = true;
             }
             if ($CurrentPage == $p) {
                 $HTML .= "<li class='current'><span class=\"show-for-sr\">You're on page </span > {$p}</li > \n";
             } else {
                 $HTML .= " <li><a href = 'javascript:goToPage({$p},{$ElementID})' > {$p}</a ></li > \n";
             }
             if ($PagesCount == count($Pages)) {
                 $Next = $CurrentPage + 1;
                 if ($CurrentPage != $p) {
                     $HTML .= "<li class=\"pagination-next\"><a aria-label=\"Next page\" href='javascript:goToPage({$Next},{$ElementID})'>" . $eLanguage->_("LIST-RESULT-NEXT") . " <span class=\"show-for-sr\">page</span></a></li></ul>";
                 } else {
                     $HTML .= "<li class=\"pagination-next disabled\"><span class=\"show-for-sr\">page</span>" . $eLanguage->_("LIST-RESULT-NEXT") . "</li>\n</ul>";
                 }
             }
         }
         $Paging->setProperties(['HTML' => $HTML, 'Init' => $Init, 'Max' => $Max, 'Results' => $PageMax - $PageInit + 1, 'PageInit' => $PageInit, 'PageMax' => $PageMax, 'TotalPages' => $TotalPages, 'TotalResults' => $TotalResults]);
     }
     return $Paging;
 }
Beispiel #3
0
 /**
  * This is a shortcut to Factory::getDocument()->setSubTitle() method
  *
  * @param      $SubTitle
  * @param bool $Language
  */
 protected function setSubTitle($SubTitle, $Language = true)
 {
     if ($Language) {
         $SubTitle = Factory::getLanguage()->_($SubTitle);
     }
     Factory::getDocument()->setSubTitle($SubTitle);
 }
Beispiel #4
0
 /**
  * @param           $Element
  * @param           $Type
  * @param           $Message
  * @param bool|true $Language
  */
 public static function addMessage($Element, $Type, $Message, $Language = true)
 {
     if ($Language) {
         $Message = Factory::getLanguage()->_($Message);
     }
     try {
         $Message = new SystemMessage(Factory::getDBH(), ['UserID' => Factory::getUser()->get('ID'), 'SessionID' => Factory::getSession()->getPHP_SessionID(), 'Element' => $Element, 'Message' => $Message, 'Type' => $Type, 'Viewed' => 0, 'RegisteredDate' => Utility::getDateForDB()], false);
         $Message->save();
     } catch (PDOException $e) {
         Factory::getDBH()->catchException($e);
     }
 }
Beispiel #5
0
 /**
  * @param null $File
  */
 public function setLanguageFile($File = null)
 {
     $Files = null;
     $Language = null;
     $Properties = $this->defineProperties();
     $eLang = Factory::getLanguage();
     $Code = $eLang->get('Code');
     if (is_string($File) && !empty($File)) {
         $File = [$File];
     }
     if (isset($Properties['Languages']) && is_array($Properties['Languages'])) {
         foreach ($Properties['Languages'] as $lg) {
             if (isset($lg['default']) && (bool) $lg['default'] === true) {
                 $Default = $lg;
             } elseif (isset($lg['code']) && $lg['code'] == $Code) {
                 $Language = $lg;
                 break;
             }
         }
         if (!$Language && isset($Default)) {
             $Language = $Default;
             $Code = isset($Language['code']) ? $Language['code'] : $Code;
         }
         if (isset($Language['files']) && is_array($Language['files'])) {
             $Files = $Language['files'];
         }
     }
     $isArray = is_array($File);
     if ($Files) {
         foreach ($Files as $lang) {
             if ($isArray) {
                 foreach ($File as $f) {
                     if ($f == (string) $lang) {
                         $eLang->addFile((string) $lang, $this->getPath() . 'Language' . DS, $Code);
                         break;
                     }
                 }
             } else {
                 $eLang->addFile((string) $lang, $this->getPath() . 'Language' . DS, $Code);
             }
         }
     }
 }
Beispiel #6
0
<?php

defined("EPSILON_EXEC") or die;
use Epsilon\Factory;
/** @var \Epsilon\MVC\View $this */
$eLanguage = Factory::getLanguage();
$eRouter = Factory::getRouter();
?>
<div style="margin-top: 50px;"></div>
<div class="row align-center">
    <div class="medium-6 large-5 column">

        <div class="callout">
            <h3 class="text-center"><?php 
echo $eLanguage->_("COM_LOGIN-TITLE");
?>
</h3>
            <form action="<?php 
echo $eRouter->getURL("Authentication/Authenticate");
?>
" method="post">
                <div class="row">
                    <div class="column">
                        <label for="fEmail"><?php 
echo $eLanguage->_("COM_LOGIN-EMAIL"), ' / ', $eLanguage->_("COM_LOGIN-USERNAME");
?>
</label>
                        <input name="Login[Email]" id="fEmail" type="text" value="" required>
                    </div>
                </div>
                <div class="row">
Beispiel #7
0
 /**
  * @return User
  */
 public static function getInstance()
 {
     if (!isset(self::$Instance)) {
         if (Factory::getSession()->get('User')) {
             self::$Instance = new User(Factory::getDBH(), Factory::getSession()->get('User'));
         } else {
             self::$Instance = new User(Factory::getDBH(), ['Name' => Factory::getLanguage()->_('GUEST')]);
             self::$Instance->setGuest(true);
         }
     }
     return self::$Instance;
 }
Beispiel #8
0
<?php

/**
 * Project: Epsilon
 * Date: 11/5/15
 * Time: 12:58 PM
 *
 * @link      https://github.com/falmar/Epsilon
 * @author    David Lavieri (falmar) <*****@*****.**>
 * @copyright 2015 David Lavieri
 * @license   http://opensource.org/licenses/MIT The MIT License (MIT)
 */
defined('EPSILON_EXEC') or die;
use App\Config;
use Epsilon\Factory;
require_once LIBRARY_PATH . 'Epsilon' . DS . 'autoload.php';
date_default_timezone_set(Config::TIMEZONE);
ini_set('default_charset', Config::CHARSET);
ini_set('display_errors', Config::APP_DEBUG ? 1 : 0);
error_reporting(E_ALL);
register_shutdown_function('Epsilon\\Logger\\Logger::shutdown');
set_error_handler('Epsilon\\Logger\\Logger::addPHPError');
set_exception_handler('Epsilon\\Logger\\Logger::uncaughtException');
Factory::setApplication(Config::APPLICATION_ID);
Factory::getLanguage()->addFile('Epsilon.xml');