/** * 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; }
/** * Fatal error handler. * * @access public * @since 1.0.0-alpha * @version 1.0.0-alpha */ public function handler() { if (Core::getAppMode() == Core::MODE_DEVELOPMENT) { throw $this; } else { header('HTTP/1.0 ' . $this->sHeaderContent); echo View::factory('base/error_pages/500')->render(); die; } }
/** * ACTION - User login. * * @access public * @return View * @since 1.0.2, 2013-12-07 * @version 1.0.7-dev, 2015-05-04 */ public function actionLogin() { $this->setTitle(Core::getAppName() . ' - ' . __('Login form')); $this->addBreadCrumb(__('Login form')); $oLoggedUser = Model\User::getLoggedUser(); if ($oLoggedUser instanceof Model\User) { Route::factory('user_profile')->redirectTo(['id' => $oLoggedUser->getId()]); } $failedLogins = \User\LoginFail::getCachedData(); if ($failedLogins > 4) { return View::factory('base/alert')->set('sType', 'danger')->set('sMsg', __('to.many.incorrect.logins')); } $oLoginForm = Form::factory('login'); $oLoginForm->addField(Form\Field\Text::factory('login', $oLoginForm)); $oLoginForm->addField(Form\Field\Password::factory('password', $oLoginForm)); if ($oLoginForm->isSubmittedAndValid()) { $sUsername = $oLoginForm->get('login'); $sPassword = $oLoginForm->get('password'); $sEncryptedPassword = Helper\Encrypter::factory()->encrypt($sUsername, $sPassword); $oUser = DB::query("SELECT u FROM \\Model\\User u WHERE u.login = :login AND u.password = :pass")->param('login', $sUsername)->param('pass', $sEncryptedPassword)->single(); if ($oUser instanceof Model\User) { Session::set('username', $sUsername); Session::set('uid', (int) $oUser->getId()); $oUser->setLoginDateNOW(); DB::flush(); # Get role permissions for particular user and set them in session \UserPermissions::reset(); Route::factory(Router::getCurrentRouteName())->redirectTo(); } else { $currentUrl = Router::currentUrl(); $alert = __('You have entered wrong username or password. Try again.'); \User\LoginFail::addLoginFail(); Session::flash($currentUrl, $alert, 'danger'); } } $oLoginForm->addToSuffix(View::factory('user/frontend/login_links')->render()); return View::factory('base/form')->bind('oForm', $oLoginForm); }
define('PATH_CACHE', PATH_APP . 'cache' . DS); // 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();
/** * Send user account recovery code. * * @access public * @param User $oUser * @since 1.0.0, 2015-02-17 * @version 2.1.0-dev * @return bool */ private function sendRecoveryCode(User $oUser) { $sUserAgent = filter_input(INPUT_SERVER, 'HTTP_USER_AGENT'); $sCodeToEncode = mb_strlen(uniqid()) * time() . $sUserAgent . $oUser->getLogin(); $sCode2 = sha1($sCodeToEncode); $sRecoveryCode = base64_encode($sCode2); DB::query('DELETE FROM \\Model\\User\\RecoveryCode r WHERE r.user = :user')->param('user', $oUser->getId())->execute(TRUE); $oRecoveryCode = new User\RecoveryCode(); $oRecoveryCode->setUser($oUser); $oRecoveryCode->setCode($sRecoveryCode); DB::persist($oRecoveryCode); DB::flush(); $sSubject = __('Account activation on :app', ['app' => Core::getAppName()]); $mailContent = View::factory("user/frontend/recovery/message")->render(['sLogin' => $oUser->getLogin(), 'sRecoveryCode' => $sRecoveryCode]); $mailView = View::factory('base/email'); $mailView->bind('sContent', $mailContent); $mailView->set('sTitle', $sSubject); return $oUser->sendEmail($sSubject, $mailView->render()); }
<?php /** * Content of e-mail with password reset link. * * @author Krzysztof Trzos * @package user * @subpackage views\frontend\recovery * @since 2015-02-17 * @version 2.1.0-dev */ use Plethora\Core; use Plethora\Helper; use Plethora\Route; $siteName = Core::getAppName(); $contactUrl = Helper\Html::a(Route::factory('contact')->url(), __('CONTACT')); ?> <?php /* @var $sRecoveryCode string */ /* @var $sLogin string */ ?> <?php $passRecoveryLink = Route::factory('password_recovery_code')->url(['code' => $sRecoveryCode]); ?> <p><?php echo __('Hello :login', ['login' => $sLogin]); ?> ,</p>
/* @var $sLogin string */ ?> <p>Witaj <b><?php echo $sLogin; ?> </b>!</p> <p>Na tego maila zarejestrowane zostało konto portalu <b><?php echo \Plethora\Core::getAppName(); ?> </b>. Nie jest jednak ono w pełni aktywne i, aby zakończyć rejestrację, należy kliknąć w poniższy link:</p> <p style="text-align: center;"> <a href="<?php echo \Plethora\Route::factory('account_activation')->url(['code' => $sActivationCode]); ?> " title="Link aktywacyjny konta"> <?php echo \Plethora\Route::factory('account_activation')->url(['code' => $sActivationCode]); ?> </a> </p> <p style="border-top: 1px solid rgb(102, 102, 102); font-size: 12px; padding-top: 5px; text-align: center;"> Jeżeli rejestracja konta nie została dokonania przez Ciebie, zgłoś to przez dział <a href="<?php echo \Plethora\Route::factory('contact')->url(); ?> " title="<?php echo \Plethora\Core::getAppName(); ?> - kontakt">KONTAKT</a>, a usuniemy Twój e-mail z naszej bazy danych. </p>
/** * Get field lang. * * @access public * @return array * @since 1.0.0-alpha * @version 1.0.0-alpha */ public function getLangs() { return $this->isMultilanguage() ? Core::getLanguages() : ['und']; }
/** * 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); }
</ul> <?php } ?> </div> <?php } ?> <?php if ($oForm->hasMultilangField()) { ?> <div id="form-language-checker"> <div id="form-language-checker-container"> <?php foreach (\Plethora\Core::getLanguages() as $i => $lang) { ?> <?php $sIsActive = NULL; ?> <?php if ($i === 0 || in_array($lang, $oForm->getCheckedLanguages())) { $sIsActive = 'active'; } else { $sIsActive = 'disabled'; } ?> <div id="form-language-checker-single-num-<?php echo $i; ?>
/** * Method in which can do some operations before saving to database. * * @access protected * @param Form $form * @since 1.0.0-alpha * @version 1.0.0-alpha */ protected function beforeSave(Form &$form) { if ($this->getModel()->hasLocales()) { $aDoNotSaveFor = array_diff(Core::getLanguages(), $form->getCheckedLanguages()); foreach ($aDoNotSaveFor as $sLang) { $this->getModel()->removeLocales($sLang); } } if (property_exists($this->getModel(), 'author') && !$this->getModel()->getAuthor() instanceof User) { $this->getModel()->setAuthor(User::getLoggedUser()); } if (property_exists($this->getModel(), 'modification_date')) { $this->getModel()->updateModificationDate(); } }
/** * Checks if the form contains any errors. * * @access public * @return boolean * @since 1.0.0-alpha * @version 1.0.0-alpha */ public function isValid() { if ($this->validationResult !== NULL) { return $this->validationResult; } # if form is submitted if ($this->isSubmitted()) { # make some pre-validation operations foreach ($this->getFields() as $field) { /* @var $field Field */ $whenSubmittedMethod = new \ReflectionMethod(get_class($field), 'whenFormSubmitted'); $whenSubmittedMethod->setAccessible(TRUE); $whenSubmittedMethod->invoke($field); $whenSubmittedMethod->setAccessible(FALSE); # if particular field isn't required and it's value is empty, remove all rules if ($field->isRequired() === FALSE) { foreach ($field->getLangs() as $sLang) { foreach ($field->getValue($sLang) as $i => $value) { if ($value == '' || $value === []) { $this->getValidator()->blockRulesFor($field->getName(), $sLang, $i); } } } } # if particular field is disabled, remove all rules if ($field->isDisabled()) { $this->getValidator()->blockRulesFor($field->getName()); } # remove all rules for multilang field and it's unchecked language if ($field->isMultilanguage()) { foreach (Core::getLanguages() as $sLang) { if (!in_array($sLang, $this->getCheckedLanguages())) { $this->getValidator()->blockRulesFor($field->getName(), $sLang); } } } } # CSRF token validation if ($this->csrfToken) { $aMethodValues = $this->getMethodValue(); $sTokenFromForm = Helper\Arrays::path($aMethodValues, $this->getName() . '.csrf_token'); $sTokenFromSession = $this->getFormToken(); if ($sTokenFromForm !== $sTokenFromSession) { $this->addFormError(__('Bad request token. Please, send the form once again.')); } } # make some operations for all fields before validation foreach ($this->getFields() as $field) { /* @var $field Field */ $field->beforeValidation(); } # check amount of field values foreach ($this->getFields() as $field) { /* @var $field Field */ foreach ($field->getLangs() as $sLang) { if (in_array($sLang, $this->getCheckedLanguages())) { $iValuesAmount = count($field->getValue($sLang)); if ($field->getQuantity() === 0) { if ($field->getQuantityMin() > $iValuesAmount) { $this->getValidator()->addError($field->getName() . '_' . $sLang, __('Insufficient amount of values given for this field (should be :number).', ['number' => $field->getQuantityMin()])); } if ($field->getQuantityMax() != 0 && $field->getQuantityMax() < $iValuesAmount) { $this->getValidator()->addError($field->getName() . '_' . $sLang, __('Too hight amount of values given for this field (should be :number).', ['number' => $field->getQuantityMin()])); } } elseif ($field->getQuantity() != $iValuesAmount) { $this->getValidator()->addError($field->getName() . '_' . $sLang, __('The amount of values for this field should be :number (:amount given).', ['number' => $field->getQuantity(), 'amount' => $iValuesAmount])); } } } } # if form has not been checked earler, do it now if (!$this->getValidator()->isChecked()) { $this->getValidator()->check(); $this->refactorErrors(); } # make some operations for all fields which are valid foreach ($this->getFields() as $field) { /* @var $field Field */ foreach ($field->getLangs() as $sLang) { if (!$field->hasErrors($sLang)) { $field->afterValidationWhenValid($sLang); } } } } # check if form has any errors $hasErrors = $this->getValidator()->hasErrors(); # if form is submitted and doesn't have errors if ($this->isSubmitted() && !$hasErrors) { foreach ($this->getFields() as $field) { /* @var $field Field */ $field->afterValidation(); } } # return value whether the form is valid return $this->validationResult = !$hasErrors; }
/** * Errors handler. * * @author Krzysztof Trzos * @param integer $errno * @param string $errstr * @param string $errfile * @param integer $errline * @param array $errcontext * @throws Exception\Fatal * @since 1.0.0-alpha * @version 1.0.0-alpha */ function error_handler($errno, $errstr, $errfile = '', $errline = 0, $errcontext = []) { $iLevel = ob_get_level(); for ($i = 1; $i < $iLevel; $i++) { ob_get_clean(); } if (Core::getAppMode() == Core::MODE_DEVELOPMENT) { \Kint::trace(); ddd($errno, $errstr, $errfile, $errline, $errcontext); } else { try { throw new Exception\Fatal(); } catch (Exception $e) { $e->handler(); } } }
/** * @author Krzysztof Trzos * @package base * @subpackage views/backend/blocks/body * @since 1.0.0-alpha * @version 1.0.0-alpha */ use Plethora\Core; use Plethora\Helper; use Plethora\Route; ?> <?php $sChangelogLink = Route::factory('framework_changelog')->url(); $changelogAnchor = Helper\Link::factory()->setTitle(__('changelog'))->code(Core::getVersion(), $sChangelogLink); ?> <footer class="main-footer"> <div class="pull-right hidden-xs"> <b><?php echo __('Version'); ?> </b> <?php echo $changelogAnchor; ?> </div> <strong>Copyright © 2016 <a href="http://plethorafw.com">Plethora Framework</a>.</strong> <?php echo __('All rights reserved.'); ?> </footer>
/** * Create new locales Model. * * @access public * @param string $sLang * @return ModelCore\Locales * @since 1.0.0-alpha * @version 1.0.0-alpha */ private function createNewLocale($sLang) { if (in_array($sLang, Core::getLanguages())) { $sLocaleClassName = $this->getClass() . '\\Locales'; $oLocale = new $sLocaleClassName(); /* @var $oLocale ModelCore\Locales */ $oLocale->setLanguage($sLang); $oLocale->setParent($this); $this->locales->add($oLocale); unset($sLocaleClassName); return $oLocale; } return NULL; }
<?php /** * @author Krzysztof Trzos * @package base * @subpackage views/backend/blocks/body * @since 1.0.0-alpha * @version 1.0.0-alpha */ ?> <?php $sChangelogLink = \Plethora\Route::factory('framework_changelog')->url(); ?> <div class="container"> <p class="text-muted text-right"><?php echo __('author'); ?> : <b>Krzysztof Trzos</b> with <a href="<?php echo $sChangelogLink; ?> " title="<?php echo __('changelog'); ?> ">Plethora v<?php echo \Plethora\Core::getVersion(); ?> </a></p> </div>