Example #1
0
 /**
  * Load config file
  *
  * Get array from config file and save it to variable
  *
  * @static
  * @access   public
  * @param    string $sConfigPath
  * @param    string $sFormat
  * @return   bool
  * @throws   Exception
  * @since    1.0.0-alpha
  * @version  1.0.0-alpha
  */
 private static function load($sConfigPath, $sFormat = 'php')
 {
     $oConfigData = static::findConfigFile($sConfigPath, $sFormat);
     // load config data
     if ($oConfigData !== FALSE) {
         switch ($sFormat) {
             # PHP
             case 'php':
                 $aConfig = (include $oConfigData->getPath());
                 break;
                 # YAML
             # YAML
             case "yml":
                 $aConfig = \Spyc::YAMLLoad($oConfigData->getPath());
                 break;
         }
     }
     // assign data to storage
     if (isset($aConfig)) {
         Helper\Arrays::createMultiKeys(static::$aConfigs, $sConfigPath, $aConfig);
         unset($aConfig);
         Log::insert('Config ' . $sConfigPath . ' (' . $sFormat . ') loaded');
         return TRUE;
     }
     // if there is no data to assign (because the config file does not exists), create ERROR message and return FALSE (or throw exception)
     $sMsg = 'Unable to load ' . $sConfigPath . ' config file with "' . $sFormat . '" format.';
     Log::insert($sMsg, Log::ERROR);
     if (Core::getAppMode() === Core::MODE_DEVELOPMENT) {
         throw new Exception($sMsg);
     }
     return FALSE;
 }
Example #2
0
 /**
  * Constructor.
  *
  * @access     public
  * @since      1.0.0-alpha
  * @version    1.0.0-alpha
  */
 public function __construct()
 {
     // call parent constructor
     parent::__construct();
     // set default response status
     $this->sStatus = static::STATUS_SUCCESS;
     // Create log about Controller initalization
     Log::insert('Ajax controller class initialized!');
 }
Example #3
0
 /**
  * Constructor.
  *
  * @access     public
  * @param      QueryBuilder $oQuery
  * @param      string       $sMainTableAlias
  * @param      integer      $iResultsPerPage
  * @throws     \Doctrine\ORM\NoResultException
  * @throws     \Doctrine\ORM\NonUniqueResultException
  * @internal   param string $sGetName
  * @since      1.0.0-alpha
  * @version    1.0.0-alpha
  */
 public function __construct(QueryBuilder &$oQuery, $sMainTableAlias, $iResultsPerPage = 15)
 {
     Log::insert('Pager helper initialized for query: "' . $oQuery->getDQL() . '".');
     $iPageParamValue = filter_input(INPUT_GET, 'page', FILTER_VALIDATE_INT);
     if (!empty($iPageParamValue)) {
         $this->iPage = $iPageParamValue;
     }
     $oQueryAmount = clone $oQuery;
     $aAmount = $oQueryAmount->select('COUNT(' . $sMainTableAlias . ')')->getQuery()->getSingleResult();
     $this->iAmount = (int) $aAmount[1];
     $this->iResultsPerPage = (int) $iResultsPerPage;
     $iFirstResult = $this->iResultsPerPage * ($this->iPage - 1);
     $oQuery->setMaxResults($this->iResultsPerPage)->setFirstResult($iFirstResult);
 }
Example #4
0
 /**
  * Main action to run cron jobs.
  *
  * @access   public
  * @since    2.33.0-dev, 2015-06-07
  * @version  2.39.0-dev
  */
 public function actionDefault()
 {
     if (!class_exists('\\Cron\\CronExpression')) {
         throw new Exception\Fatal('Cannot run Cron jobs without proper Cron library.');
     }
     $sTokenFromURL = Router::getParam('token');
     $sTokenFromConfig = Config::get('base.cron_token');
     $iCronJobsCompleted = 0;
     // check Cron token
     if ($sTokenFromURL !== $sTokenFromConfig) {
         throw new Exception\Code404();
     }
     // get all Cron jobs
     $aAllJobs = CronJobsHelper::getCronJobs();
     // count amount of all CRON jobs
     $iCronJobs = count($aAllJobs);
     // run a single CRON job
     foreach ($aAllJobs as $aJobData) {
         $sModule = $aJobData['module'];
         $sJobKey = base64_encode($aJobData[1] . '.' . $aJobData[2]);
         $aCache = Cache::get($sModule . '.' . $sJobKey, 'cron');
         $iRunDate = isset($aCache['time']) ? $aCache['time'] : NULL;
         $oCron = CronExpression::factory($aJobData[0]);
         if ($iRunDate === NULL || $iRunDate < time()) {
             switch ($aJobData[1]) {
                 case 'route':
                     $sURL = Route::factory($aJobData[2])->url();
                     file_get_contents($sURL);
                     break;
                 case 'file':
                 case 'url':
                     file_get_contents($aJobData[2]);
                     break;
                 case 'function':
                     call_user_func($aJobData[2]);
                     break;
             }
             $iNextRun = $oCron->getNextRunDate()->format('U');
             $aCacheToSave = ['time' => $iNextRun, 'last_execution_time' => time(), 'type' => $aJobData[1], 'param' => $aJobData[2]];
             Cache::set($aCacheToSave, $sModule . '.' . $sJobKey, 'cron', 0);
         }
     }
     // log that cron jobs turning on action was completed
     Log::insert('Cron jobs (in amount of ' . $iCronJobs . ') were checked and ' . $iCronJobsCompleted . ' of them were turned on.');
     // end of functionality
     exit;
 }
Example #5
0
 /**
  * Constructor
  *
  * @access   public
  * @since    1.0.0-alpha
  * @version  1.0.0-alpha
  */
 public function __construct()
 {
     $this->iQueue = Config::get('mailer.queue', 5);
     # set transport instance
     $sTransportClass = '\\Plethora\\Mailer\\Transport\\' . ucfirst(Config::get('mailer.transport'));
     $this->oTransport = new $sTransportClass();
     # prepare mailer cache path
     $filesPath = Config::get('mailer.cache_path', FALSE);
     if ($filesPath === FALSE) {
         throw new Exception\Fatal('Mailer cache path has not been specified in config file.');
     }
     if (!file_exists($filesPath)) {
         mkdir($filesPath, 0755);
     }
     # log that mailer class has been initialized
     Log::insert('Mailer class initialized!');
 }
Example #6
0
// Cache path
define('PATH_G_VIEWS', PATH_APP . 'views' . DS);
// Global views path
// styles and images path
define('PATH_CSS', '/css/');
define('PATH_IMAGES', '/images/');
// show all errors if development mode is on
//if(\Plethora\Core::getAppMode() == \Plethora\Core::MODE_DEVELOPMENT) {
error_reporting(E_ALL);
ini_set('display_errors', '1');
//require_once PATH_LIB.'KintDebug/Kint.class.php';
//}
// Load global functions
require PATH_CORE . 'functions.php';
// show content
if (file_exists('./install.php')) {
    require_once PATH_PUBLIC . 'install.php';
} else {
    if (\Plethora\Core::getAppMode() == \Plethora\Core::MODE_DEVELOPMENT) {
        \Plethora\Core::startApp();
    } else {
        try {
            \Plethora\Core::startApp();
        } catch (\Plethora\Exception $e) {
            $e->handler();
        }
    }
}
// destruct Log instance
\Plethora\Log::destruct();
Example #7
0
 /**
  * Constructor
  *
  * @access   public
  * @since    1.0.0-alpha
  * @version  1.0.0-alpha
  */
 public function __construct()
 {
     Log::insert('MonthHelper object initialized!');
 }
Example #8
0
 /**
  * Set list of allowed extenstions in the ZIP archive.
  *
  * @access   public
  * @param    string $pathFrom
  * @param    string $pathTo
  * @return   array
  * @throws   Exception
  * @since    1.0.0-alpha
  * @version  1.0.0-alpha
  */
 public function unpackZip($pathFrom, $pathTo)
 {
     $valid_files = [];
     // checking for php ZIP extension
     if (!extension_loaded('zip')) {
         $msg = 'No php extension to ZIP decompression.';
         Log::insert($msg, 'ERROR');
         throw new Exception($msg);
     }
     // checking if extensions were given
     if (!count($this->allowedExt)) {
         $msg = 'No file extensions were added. First, use setAllowedExt() method to add valid extensions.';
         Log::insert($msg, 'ERROR');
         throw new Exception($msg);
     }
     $zip = new \ZipArchive();
     $archive = $zip->open($pathFrom);
     // checking if this archive is valid ZIP archive
     if ($archive !== TRUE) {
         return 'This is not a valid ZIP archive.';
     }
     // checking for valid files
     for ($i = 0; $i < $zip->numFiles; $i++) {
         $file = $zip->statIndex($i);
         $file_pathinfo = pathinfo($file['name']);
         if (isset($file_pathinfo['extension']) && in_array(mb_strtolower($file_pathinfo['extension']), $this->allowedExt)) {
             $valid_files[] = $file['name'];
         } else {
             $this->invalidFiles[] = $file['name'];
         }
     }
     // copying files to new location
     if (count($valid_files)) {
         foreach ($valid_files as $file) {
             if (!$zip->extractTo($pathTo, $file)) {
                 $this->unextractedFiles[] = $file;
             } else {
                 $this->extractedFiles[] = $file;
             }
         }
         $zip->close();
     } else {
         return 'No valid files (with particular extensions) in this archive.';
     }
     return $this->extractedFiles;
 }
Example #9
0
 /**
  * Remove all cache files.
  *
  * @access   private
  * @return   boolean
  * @since    1.0.0-alpha
  * @version  1.0.0-alpha
  */
 private function deleteAll()
 {
     Log::insert('All cache was deleted');
     foreach (scandir($this->path) as $group) {
         $this->deleteGroup($group);
     }
     return TRUE;
 }
Example #10
0
 /**
  * Constructor.
  *
  * @access     public
  * @since      1.0.0-alpha
  * @version    1.0.0-alpha
  */
 public function __construct()
 {
     // renew logged user permissions (only for those users, which already have some permissions)
     if (!is_null(Session::get('uid')) && !is_null(Session::get('perm'))) {
         \UserPermissions::reset();
     }
     // set default page title and description (based on app config "base")
     $this->setTitle(Config::get('base.app_name'));
     $this->setDescription(Config::get('base.app_description'));
     $this->setBodyBasicClasses();
     // initalize basic views
     $this->oViewMain = View::factory($this->sViewMain);
     $this->oViewBody = View::factory($this->sViewBody);
     $this->oViewBodyContent = View::factory($this->sViewBodyContent);
     $this->oViewBodyFooter = View::factory($this->sViewBodyFooter);
     $this->oViewBodyHeader = View::factory($this->sViewBodyHeader);
     $this->oViewHead = View::factory($this->sViewHead);
     $this->oView = View::factory($this->sView);
     $this->oViewBreadcrumbs = View::factory($this->sViewBreadcrumbs);
     $this->oViewSystemMessages = View::factory($this->sViewSystemMessages);
     // relate views with each other
     $this->oViewMain->bind('oHead', $this->oViewHead);
     $this->oViewMain->bind('oBody', $this->oViewBody);
     $this->oViewMain->bind('sBodyClasses', $this->sBodyClasses);
     $this->oViewBody->bind('sTitle', $this->sTitle);
     $this->oViewBody->bind('oHeader', $this->oViewBodyHeader);
     $this->oViewBody->bind('oContent', $this->oViewBodyContent);
     $this->oViewBody->bind('oFooter', $this->oViewBodyFooter);
     $this->oViewBodyContent->bind('oContent', $this->oView);
     $this->oViewBodyContent->bind('oController', $this);
     $this->oViewBodyContent->bind('oBreadcrumbs', $this->oViewBreadcrumbs);
     $this->oViewBodyContent->bind('oSystemMessages', $this->oViewSystemMessages);
     $this->oViewBreadcrumbs->bind('aBreadcrumbs', $this->aBreadcrumbs);
     $this->oViewSystemMessages->bind('aSystemMessages', $this->aSystemMessages);
     $this->oViewHead->bind('sTitle', $this->sTitle);
     $this->oViewHead->bind('aCss', $this->css);
     $this->oViewHead->bind('aJs', $this->js);
     $this->oViewHead->bind('aMeta', $this->aMeta);
     // set default meta
     $this->findDefaultMeta();
     // Create log about Controller initalization
     Log::insert('Main controller class initialized!');
 }
Example #11
0
 /**
  * Constructor.
  *
  * @access   public
  * @param    string $name Form name
  * @param    array  $defaultValues
  * @param    string $method
  * @throws   Exception\Fatal
  * @throws   Exception
  * @since    1.0.0-alpha
  * @version  1.0.0-alpha
  */
 public function __construct($name, array $defaultValues = [], $method = Form::METHOD_POST)
 {
     if (preg_match('/[^a-z0-9_]/', $name) !== 0) {
         throw new Exception\Fatal('Name of the form can contain only small letters, numbers and an underscore characters.');
     }
     $this->formName = $name;
     $this->defaultValues = $defaultValues;
     $this->validator = new Validator();
     $this->setMethod($method);
     $this->setSubmitValue(__('send'));
     $this->setSubmitName($this->getName() . '_submit');
     if (Helper\Arrays::get($this->getMethodValue(), $this->getSubmitName(), FALSE) || isset($_FILES[$this->getName()])) {
         $this->isFormSubmitted = TRUE;
     }
     // add javascripts
     $controller = Router::getInstance()->getController();
     $controller->addJs('/themes/_common/js/form/form.js');
     // loggin form creation
     Log::insert('Form "' . $name . '" has been created.');
 }
Example #12
0
 /**
  * Constructor.
  *
  * @access   public
  * @since    1.0.0-alpha
  * @version  1.0.0-alpha
  */
 public function __construct()
 {
     $this->hostname = Config::get('mailer.hostname', 'localhost');
     $this->port = Config::get('mailer.port', 25);
     $this->useAuth = Config::get('mailer.auth', FALSE);
     $this->username = Config::get('mailer.username');
     $this->password = Config::get('mailer.password');
     $this->timeout = Config::get('mailer.timeout', 5);
     $this->crypto = Config::get('mailer.crypto', '');
     $this->newline = Config::get('mailer.newline', "\r\n");
     Log::insert('SMTP Transport class initialized!');
 }