コード例 #1
0
ファイル: FileCacheDriver.php プロジェクト: ktrzos/plethora
 /**
  * Constructor
  *
  * @access   public
  * @since    1.0.0-alpha
  * @version  1.0.0-alpha
  */
 public function __construct()
 {
     $this->defaultLifeTime = Config::get('cache.default_life_time', 3600);
     $this->defaultGroup = Config::get('cache.default_group', 'unset');
     $this->path = Config::get('cache.path');
     Log::insert('File cache driver class initialized!');
 }
コード例 #2
0
ファイル: Locales.php プロジェクト: ktrzos/plethora
 /**
  * Set language for particular entity locales.
  *
  * @access   public
  * @param    string $sLang
  * @return   $this
  * @throws   Exception\Model
  * @since    1.0.0-alpha
  * @version  1.0.0-alpha
  */
 public function setLanguage($sLang)
 {
     if (!in_array($sLang, Config::get('base.languages'))) {
         throw new Exception\Model('Wrong language.');
     }
     $this->language = $sLang;
     return $this;
 }
コード例 #3
0
ファイル: Cron.php プロジェクト: ktrzos/plethora
 /**
  * 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;
 }
コード例 #4
0
ファイル: ImageStyle.php プロジェクト: ktrzos/plethora
 /**
  * Apply style to particular image.
  * 
  * @static
  * @access	public
  * @param	string	$sStyleName
  * @since	1.0.0, 2014-07-13
  * @version	1.1.0, 2014-07-15
  */
 public function apply($sStyleName)
 {
     if (static::$aImageStyles === NULL) {
         static::$aImageStyles = \Plethora\Config::get('image_styles');
     }
     $aStyles = \Plethora\Helper\Arrays::get(static::$aImageStyles, $sStyleName);
     if ($aStyles === NULL) {
         throw new \Plethora\Exception\Fatal('Image style "' . $sStyleName . '" do not exists.');
     }
     $oImage = $this->getImage();
     $oImageFile = $oImage->getImageFileObject();
     $sStyledImagePath = 'uploads/image_styles/' . $sStyleName . '/' . $oImageFile->getName() . '.' . $oImageFile->getExt();
     if (!file_exists($sStyledImagePath)) {
         foreach ($aStyles as $aStyle) {
             $oImage = call_user_func_array(array($oImage, $aStyle[0]), $aStyle[1]);
         }
         $oImage->save($sStyledImagePath);
     }
     return $sStyledImagePath;
 }
コード例 #5
0
ファイル: CronJobsHelper.php プロジェクト: ktrzos/plethora
 /**
  * Get Cron jobs from all modules of particular web application.
  *
  * @static
  * @access  public
  * @return  array
  * @since   1.1.0-dev
  * @version 1.1.0-dev
  */
 public static function getCronJobs()
 {
     $aAllJobs = [];
     foreach (Config::get('modules') as $sGroupName => $aGroup) {
         foreach (array_keys($aGroup) as $module) {
             $sDir = PATH_MODULES . $sGroupName . DS . $module . DS . 'config';
             $sFilePath = $sDir . DS . 'cron.php';
             if (file_exists($sDir) && file_exists($sFilePath)) {
                 $aCronData = Config::get($module . '.cron', NULL);
                 foreach ($aCronData as &$data) {
                     $jobKey = base64_encode($data[1] . '.' . $data[2]);
                     $aCache = Cache::get($module . '.' . $jobKey, 'cron');
                     $data['job_key'] = $jobKey;
                     $data['module'] = $module;
                     $data['time'] = isset($aCache['time']) ? $aCache['time'] : NULL;
                     $data['last_exe'] = isset($aCache['last_execution_time']) ? $aCache['last_execution_time'] : NULL;
                 }
                 $aAllJobs = array_merge($aAllJobs, $aCronData);
             }
         }
     }
     return $aAllJobs;
 }
コード例 #6
0
ファイル: Mailer.php プロジェクト: ktrzos/plethora
 /**
  * Send queued mails.
  *
  * @access   public
  * @return   bool
  * @throws   Exception
  * @since    1.0.0-alpha
  * @version  1.0.0-alpha
  */
 public function sendQueue()
 {
     $filesPath = Config::get('mailer.cache_path', FALSE);
     for ($i = 1; $i <= $this->iQueue; ++$i) {
         $rFile = NULL;
         foreach (new DirectoryIterator($filesPath) as $f) {
             if (!$f->isDot()) {
                 $rFile = $filesPath . $f->getFilename();
                 break;
             }
         }
         if ($rFile == NULL) {
             break;
         }
         $oMessage = unserialize(file_get_contents($rFile));
         /* @var $oMessage Mail */
         if ($oMessage instanceof Mail) {
             $this->send($oMessage);
         } else {
             throw new Exception('File isn\'t instance of Mail class');
         }
         if (!unlink($rFile)) {
             throw new Exception('File delete failure');
         }
     }
     return TRUE;
 }
コード例 #7
0
ファイル: DB.php プロジェクト: ktrzos/plethora
 /**
  * Assigns Doctrine's EntityManager to this class
  *
  * @static
  * @access   public
  * @return   boolean
  * @since    1.0.0-alpha
  * @version  1.0.0-alpha
  */
 public static function create()
 {
     if (!empty(self::$modelsDirectories)) {
         return TRUE;
     }
     static::loadModels();
     if (is_null(self::$entityManager)) {
         // the connection configuration
         $dbParams = Config::get('database.config.' . Config::get('base.mode'));
         // Set up caches
         if (Config::get('base.mode') === 'production') {
             $cache = new ArrayCache();
             $isDevMode = FALSE;
         } else {
             $cache = new ArrayCache();
             $isDevMode = TRUE;
         }
         $config = Setup::createAnnotationMetadataConfiguration(static::$modelsDirectories, $isDevMode);
         $config->setMetadataCacheImpl($cache);
         $config->setQueryCacheImpl($cache);
         $config->setSQLLogger(new Doctrine\DBAL\Logging\DebugStack());
         // Proxy configuration
         $config->setProxyDir(Config::get('database.proxy_dir'));
         $config->setProxyNamespace(Config::get('database.proxy_namespace'));
         $entityManager = EntityManager::create($dbParams, $config);
         static::$entityManager = $entityManager;
     }
     return TRUE;
 }
コード例 #8
0
ファイル: Registration.php プロジェクト: ktrzos/plethora
 /**
  * Send user account activation code.
  *
  * @access     public
  * @param      string    $sPassword
  * @param      UserModel $oUser
  * @return     bool
  * @throws     \Plethora\Exception
  * @throws     \Plethora\Exception\Fatal
  * @since      1.0.0
  * @version    2.1.0-dev
  */
 private function sendActivationCode($sPassword, UserModel $oUser)
 {
     $sUserAgent = filter_input(INPUT_SERVER, 'HTTP_USER_AGENT');
     $sActivationCode1 = mb_strlen($sPassword) * time() . $sUserAgent . $oUser->getLogin();
     $sActivationCode2 = sha1($sActivationCode1);
     $sActivationCode = base64_encode($sActivationCode2);
     $oActivationCode = new ActivationCodeModel();
     $oActivationCode->setUser($oUser);
     $oActivationCode->setCode($sActivationCode);
     DB::persist($oActivationCode);
     DB::flush();
     $sSubject = __(':appname - Activation link', ['appname' => Plethora\Core::getAppName()]);
     $mailContent = View::factory("user/frontend/register/message")->render(['sLogin' => $oUser->getLogin(), 'sActivationCode' => $sActivationCode]);
     $mailView = View::factory('base/email');
     $mailView->bind('sContent', $mailContent);
     $mailView->set('sTitle', $sSubject);
     $mail = $mailView->render();
     $oMessage = new Mail();
     $oMessage->setSubject($sSubject);
     $oMessage->setFrom(Config::get('base.email'));
     $oMessage->setTo($oUser->getEmail());
     $oMessage->setBody($mail, 'text/html');
     return Mailer::factory()->send($oMessage);
 }
コード例 #9
0
ファイル: header.php プロジェクト: ktrzos/plethora
 */
use Plethora\Config;
use Plethora\Exception;
use Plethora\Route;
use Plethora\Router;
use Plethora\Theme;
?>

<?php 
# load main menus
$menus = Config::get('backend.menu');
# load submenus
$subMenus = [];
foreach (array_keys(Router::getModules()) as $sModule) {
    try {
        $aModuleMenus = Config::get($sModule . '.backend.menu', [], TRUE);
        foreach ($aModuleMenus as $sName => $aModuleMenu) {
            $subMenus[$aModuleMenu['parent']][$sModule][$sName] = $aModuleMenu;
        }
    } catch (Exception $e) {
    }
}
# get logged user
$oUser = Model\User::getLoggedUser();
# user anchor
$userAnchor = \Plethora\Helper\Link::factory()->setTitle(__('User profile'))->code($oUser->getFullName(), $oUser->getProfileURL());
?>

<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
    <div class="container">
        <div class="navbar-header">
コード例 #10
0
ファイル: ImageStyles.php プロジェクト: ktrzos/plethora
 /**
  * Save styled image in the correct location.
  *
  * @access     public
  * @param      ImageWorkshopLayer $oLayer
  * @param      string             $sImageDir
  * @param      string             $sImageName
  * @return     string
  * @since      1.0.0-alpha
  * @version    1.0.0-alpha
  */
 public function save(ImageWorkshopLayer $oLayer, $sImageDir, $sImageName)
 {
     if (substr($sImageDir, 0, strlen(static::DIR_UPLOADS)) == static::DIR_UPLOADS) {
         $sImageDir = substr($sImageDir, strlen(static::DIR_UPLOADS));
     }
     $sSaveDir = static::DIR_IMG_STYLES . $this->sImageStyleName . '/' . $sImageDir;
     $oLayer->save($sSaveDir, $sImageName, TRUE, NULL, Config::get('base.images_quality'));
     return $sSaveDir . '/' . $sImageName;
 }
コード例 #11
0
ファイル: Smtp.php プロジェクト: ktrzos/plethora
 /**
  * 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!');
 }
コード例 #12
0
ファイル: ModelForm.php プロジェクト: ktrzos/plethora
 /**
  * Save new Model data. Method created for "public" uses, when needed to
  * make a save in, for example, controller.
  *
  * @access   protected
  * @param    Form $oForm
  * @throws   Exception
  * @throws   Exception\Fatal
  * @since    1.0.0-alpha
  * @version  1.0.0-alpha
  */
 protected function makeSaveProtected(Form &$oForm)
 {
     $oConfig = $this->getConfig();
     try {
         $this->beforeSave($oForm);
         $this->getModel()->save();
         DB::flush();
         if ($oConfig == NULL || $oConfig->isReloading() === TRUE) {
             $sUrl = $oConfig->getAction() === NULL ? $oForm->getAttribute('action') : $oConfig->getAction();
             $sComm = $oConfig->getMessage() === NULL ? __('Form data submitted.') : $oConfig->getMessage();
             Session::flash($sUrl, $sComm);
         }
     } catch (Exception $e) {
         if (Config::get('base.mode') == 'development') {
             throw $e;
         } else {
             throw new Exception\Fatal(__('Error occured while saving data in database.'));
         }
     }
 }
コード例 #13
0
ファイル: Backend.php プロジェクト: ktrzos/plethora
 protected function generateMenu()
 {
     # load main menus
     $menus = Config::get('backend.menu');
     # load submenus
     $subMenus = [];
     foreach (array_keys(Router::getModules()) as $module) {
         try {
             $moduleMenus = Config::get($module . '.backend.menu', [], TRUE);
             foreach ($moduleMenus as $name => $moduleMenu) {
                 $subMenus[$moduleMenu['parent']][$module][$name] = $moduleMenu;
             }
         } catch (Exception $e) {
         }
     }
     # create and return View
     $view = View::factory('base/backend_adminlte/blocks/body/menu');
     $view->bind('menus', $menus);
     $view->bind('subMenus', $subMenus);
     return $view;
 }
コード例 #14
0
ファイル: run_cron.php プロジェクト: ktrzos/plethora
<script type="text/javascript">
	$(function() {
		$('#run_cron').click(function() {
			var $this = $(this);
			var oldLabel = $this.text();

			$('div#cron_result').html('');
			$this.text('<?php 
echo __('loading...');
?>
');

			$.ajax({
				url: '<?php 
echo \Plethora\Route::factory('cron')->url(['token' => \Plethora\Config::get('base.cron_token')]);
?>
'
			}).done(function(output) {
				$this.text(oldLabel);

				console.log(output);

				if(output === '') {
					output = 'All cron jobs have been executed.';
				}

				$('div#cron_result').html(output);
			});
		});
	});
コード例 #15
0
ファイル: Controller.php プロジェクト: ktrzos/plethora
 /**
  * Find default metatags content for current path.
  *
  * @access     public
  * @since      1.0.0-alpha
  * @version    1.0.0-alpha
  */
 public function findDefaultMeta()
 {
     $aModules = Router::getModules();
     $sUri = filter_input(INPUT_SERVER, 'REQUEST_URI');
     $aConfig = [];
     // get metatags from modules
     foreach (array_keys($aModules) as $sModule) {
         try {
             $aConfig = Config::get($sModule . '.meta.' . $sUri);
         } catch (Exception $e) {
         }
     }
     // get metatags from app
     try {
         $aConfig = Config::get('meta.' . $sUri);
     } catch (Exception $e) {
     }
     // set keywords
     if (!empty($aConfig)) {
         $this->setDefaultMeta($aConfig);
     }
 }
コード例 #16
0
ファイル: User.php プロジェクト: ktrzos/plethora
 /**
  * Send e-mail to particular user.
  *
  * @access     public
  * @param      string $sSubject
  * @param      string $sBody
  * @return     bool
  * @since      3.5.0, 2015-02-17
  * @version    3.5.0, 2015-02-17
  */
 public function sendEmail($sSubject, $sBody)
 {
     if ($this->getEmail() !== NULL) {
         $oMail = new Mail();
         $oMail->setFrom(Config::get('base.email'));
         $oMail->setTo($this->getEmail());
         $oMail->setSubject($sSubject);
         $oMail->setBody($sBody, 'text/html');
         return Mailer::factory()->send($oMail);
     }
     return FALSE;
 }
コード例 #17
0
ファイル: Captcha.php プロジェクト: ktrzos/plethora
 /**
  * Render field and return its rendered value.
  *
  * @access   public
  * @return   string
  * @since    1.0.0-alpha
  * @version  1.0.0-alpha
  */
 public function render()
 {
     return Config::get('recaptcha.active') === FALSE ? '' : parent::render();
 }