protected function setup() { $roleAlias = Utils::get('identifier'); $roleRepository = new RoleRepository(TRUE); $role = $roleRepository->getOneByAlias($roleAlias); MySmarty::assign('role', $role); }
public function run($function, array $params = array()) { $hooks = Utils::get('ThinHooks'); $res = null; if (Arrays::exists($function, $hooks)) { if (Arrays::exists('before', $hooks[$function])) { $action = $hooks[$function]['before']; if (is_callable($action, true, $before)) { $res = $before(); } } if (null === $res) { $res = ''; } $res .= call_user_func_array($function, $params); if (Arrays::exists('after', $hooks[$function])) { $action = $hooks[$function]['after']; if (is_callable($action, true, $after)) { $res .= $after(); } } return $res; } else { return call_user_func_array($function, $params); } }
/** * getter for actual site language * * @param string $lang language shortcut * @return Language */ public static function getLanguage($lang = NULL) { $languageRepository = new LanguageRepository(TRUE); $language = NULL; // ak nemame zadany lang if ($lang === NULL) { // zistime ci je prihlaseny user a ci ma nastaveny nejaky jazyk $loggedUser = LoggedUser::whoIsLogged(); if ($loggedUser) { $lang = $loggedUser['language']; if ($lang) { $language = $languageRepository->getOneById($lang); } } // TODO nejaka lokalizacia podla goeip // ak stale nemame jazyk, pozrieme sa do url if (!$language) { $lang = Utils::get('language'); if ($lang) { $language = $languageRepository->getOneByShortcut($lang); } else { // ak nemame zadane nic, vratime anglictinu $language = $languageRepository->getOneByShortcut('sk'); } } if (!$language) { throw new Exception('Language "' . $lang . '" doesn\'t exist.'); } } else { $language = $languageRepository->getOneByShortcut($lang); } return $language; }
private static function dispatch() { $route = Utils::get('appDispatch'); if (!$route instanceof Container) { context()->is404(); $route = container()->getRoute(); } if (true !== container()->getIsDispatched()) { if (true !== $route->getCache()) { context()->dispatch($route); } else { $redis = context()->redis(); $key = sha1(serialize($route->assoc())) . '::routeCache'; $cached = $redis->get($key); if (!strlen($cached)) { ob_start(); context()->dispatch($route); $cached = ob_get_contents(); ob_end_clean(); $redis->set($key, $cached); $ttl = Config::get('application.route.cache', 7200); $redis->expire($key, $ttl); } echo $cached; } } }
protected function setup() { $pageTypeRepository = new PageTypeRepository(TRUE); $pageType = $pageTypeRepository->getOneByAlias(Utils::get('action')); $pageRepository = new PageRepository(TRUE); $page = $pageRepository->getOneByPageType($pageType['id']); MySmarty::assign('page', $page); }
public function getContent() { if (Utils::get('identifier')) { $box = new RoomDetailBox(); } else { $box = new RoomListingBox(); } return $box->render(); }
public static function instance($name, $duration = 3600) { if (null === Utils::get('__Thin__Sessionbis__' . $name)) { $instance = new self($name, $duration); Utils::set('__Thin__Sessionbis__' . $name, $instance); return $instance; } return Utils::get('__Thin__Sessionbis__' . $name); }
function init() { parent::init(); /* $this->fetchUserInfo(); */ /* Set the app language if the session's language is supported */ $language = Utils::get(Yii::app()->session, 'language', Yii::app()->params['language']); if (Utils::isLanguageSupported($language)) { Yii::app()->language = $language; } }
/** * log the user - if not exists register him/her and then log the user * * @return void */ public static function userLogin() { $errors = array(); $hash = addslashes(Utils::get('hash')); if ($hash) { $userRepository = new UserRepository(); $user = $userRepository->getOneByHash($hash); } else { if (Utils::post('username') != '') { $username = addslashes(Utils::post('username')); if (!ctype_alnum($username)) { $errors['username'] = '******'; // TODO localize } } else { $errors['username'] = '******'; // TODO localize } if (Utils::post('password') != '') { $password = md5(addslashes(Utils::post('password'))); } else { $errors['password'] = '******'; // TODO localize } if (empty($errors)) { $userRepository = new UserRepository(); $userExist = $userRepository->getOneByUsername($username); if ($userExist === NULL) { $colorRepository = new ColorRepository(); $count = $colorRepository->getCountAll(); $rand = rand(1, $count); $params = array('username' => $username, 'password' => $password, 'color' => $rand); $user = new User($params); $user = $user->save(TRUE); } elseif ($userExist['password'] != $password) { $errors['password'] = '******'; } else { $user = $userExist; } } } if ($user && empty($errors)) { // TODO po prihlaseni treba nejako zmazat v memcachi query, ktora vybera usera podla cookie_value // lebo teraz to stale vracia vysledok z memcache -> ked sa prihlasim v dvoch browsroch, v obidvoch to funguje // neodhlasi ma z toho prveho $cookieValue = md5(time() . $user['id'] . $user['username']); DB::update(DB_PREFIX . 'user', array('cookie_value' => $cookieValue), 'id = ' . $user['id']); $expire = Utils::post('remember') == 1 ? strtotime('+1 year') : 0; setcookie(self::$cookieName, $cookieValue, $expire, '/'); return TRUE; } else { return $errors; } }
protected function setup() { $characterAlias = Utils::get('identifier'); $characterRepository = new CharacterRepository(TRUE); $character = $characterRepository->getOneByAlias($characterAlias); BangSeo::addTitlePart($character['name']); if ($character->getLocalizedDescription()) { BangSeo::setDescription($character->getLocalizedDescription()); } MySmarty::assign('character', $character); }
protected function addSeo() { $action = Utils::get('action'); $pageRepository = new PageRepository(TRUE); $page = $pageRepository->getOneByAlias($action); if (self::$seoAdded === FALSE) { BangSeo::addTitlePart($page['title']); BangSeo::setDescription($page['meta_description']); BangSeo::addContentForKeywords($page['meta_keywords'], BangSeo::MEDIUM_PRIORITY); self::$seoAdded = TRUE; } }
protected function setup() { $loggedUser = LoggedUser::whoIsLogged(); if ($loggedUser) { MySmarty::assign('loggedUser', $loggedUser); $logoutPage = PageActionMap::getPageByTypeAndLanguage('logout'); MySmarty::assign('logoutPage', $logoutPage); } else { $loginPage = PageActionMap::getPageByTypeAndLanguage('login'); MySmarty::assign('loginPage', $loginPage); } MySmarty::assign('language', Utils::get('language')); }
protected function setup() { $cardAlias = Utils::get('identifier'); $cardBaseTypeRepository = new CardBaseTypeRepository(TRUE); $cardBaseType = $cardBaseTypeRepository->getOneByAlias($cardAlias); if ($cardBaseType) { $cardRepository = new CardRepository(TRUE); $card = $cardRepository->getOneByCardBaseType($cardBaseType['id']); } BangSeo::addTitlePart($card->getTitle()); if ($card->getDescription()) { BangSeo::setDescription($card->getDescription()); } MySmarty::assign('card', $card); }
public static function assetBundle($path = 'css/style.css') { $route = Utils::get('appDispatch'); $bundle = $route->getBundle(); if (!is_null($bundle)) { $bpath = realpath(APPLICATION_PATH . '/../'); $bundle = ucfirst(Inflector::lower($bundle)); $assetsDir = $bpath . DS . 'bundles' . DS . $bundle . DS . 'public'; $file = $assetsDir . DS . $path; if (File::exists($file)) { $url = URLSITE . 'bundles/' . $bundle . '/public/' . $path; } } return URLSITE . '/' . $path; }
protected function initGame($game) { $roomAlias = Utils::get('identifier'); $roomRepository = new RoomRepository(); $room = $roomRepository->getOneByAlias($roomAlias); self::$room = $room['id']; self::$loggedUser = LoggedUser::whoIsLogged(); if ($game && self::$loggedUser) { self::$game = $game; foreach ($game['players'] as $player) { if (self::$loggedUser['id'] == $player['user']['id']) { self::$player = $player; break; } } } }
function tpl_display_tree($params) { if (isset($params['tree'])) { $tree = $params['tree']; } else { $tree = $params; } $out = '<ul>'; foreach ($tree as $node) { $out .= '<li' . (Utils::get('parent') == $node['id'] ? ' class="current"' : '') . '><h3><a href="?parent=' . (int) $node['id'] . '">' . htmlspecialchars($node['titre'], ENT_QUOTES, 'UTF-8', false) . '</a></h3>'; if (!empty($node['children'])) { $out .= tpl_display_tree($node['children']); } $out .= '</li>'; } $out .= '</ul>'; return $out; }
public function execute(array $args, array $options = array()) { if (empty($args)) { $formater = new TextFormater(array('quote' => ' * ')); $this->writeln('Available commands:', Colors::BLACK | Colors::BOLD); foreach ($this->console->getCommands() as $name => $fqdn) { if ($fqdn !== __CLASS__) { $this->writeln($formater->format($name)); } } $scriptName = basename($_SERVER['SCRIPT_FILENAME']); $this->writeln("Use './{$scriptName} help command' for more info"); } else { $commandFQDN = $this->console->getCommand($args[0]); $help = Help::fromFQDN($commandFQDN, Utils::get($args, 1)); $this->writeln($help); } }
public function getContent() { if (Utils::get('identifier')) { $page = PageActionMap::getPageByTypeAndLanguage('character'); if ($page['alias'] != Utils::get('action')) { $url = PageActionMap::createUrl(array($page['alias'], Utils::get('identifier')), Utils::get('language')); Utils::redirect($url); } $box = new CharacterDetailBox(); } else { $page = PageActionMap::getPageByTypeAndLanguage('characters'); if ($page['alias'] != Utils::get('action')) { $url = PageActionMap::createUrl(array($page['alias']), Utils::get('language')); Utils::redirect($url); } $box = new CharacterListingBox(); } return $box->render(); }
public function getCorrespondingUrl() { $action = Utils::get('action'); if ($action) { $pageRepository = new PageRepository(TRUE); $actualPage = $pageRepository->getOneByAlias($action); $aliases = array(); if ($actualPage) { $pageTypeRepository = new PageTypeRepository(TRUE); $pageType = $pageTypeRepository->getOneById($actualPage['page_type']); $page = PageActionMap::getPageByTypeAndLanguage($pageType['alias'], $this['shortcut']); $aliases[] = $page['alias']; } else { $aliases[] = $action; } if (Utils::get('identifier')) { $aliases[] = Utils::get('identifier'); } return PageActionMap::createUrl($aliases, $this['shortcut']); } else { return $this->getUrl(); } }
$type = 'recette'; } Utils::redirect('/admin/compta/operations/saisir.php?' . $type . '&ok=' . (int) $id); } catch (UserException $e) { $error = $e->getMessage(); } } } $tpl->assign('error', $error); $tpl->assign('type', $type); if ($type === null) { $tpl->assign('comptes', $comptes->listTree()); } else { $tpl->assign('moyens_paiement', $cats->listMoyensPaiement()); $tpl->assign('moyen_paiement', Utils::post('moyen_paiement') ?: 'ES'); $tpl->assign('categories', $cats->getList($type === 'dette' ? Compta\Categories::DEPENSES : $type)); $tpl->assign('comptes_bancaires', $banques->getList()); $tpl->assign('banque', Utils::post('banque')); } if (!$membres->sessionGet('compta_date')) { $exercices = new Compta\Exercices(); $exercice = $exercices->getCurrent(); if ($exercice['debut'] > time() || $exercice['fin'] < time()) { $membres->sessionStore('compta_date', date('Y-m-d', $exercice['debut'])); } else { $membres->sessionStore('compta_date', date('Y-m-d')); } } $tpl->assign('date', $membres->sessionGet('compta_date') ?: false); $tpl->assign('ok', (int) Utils::get('ok')); $tpl->display('admin/compta/operations/saisir.tpl');
<?php namespace Garradin; require_once __DIR__ . '/../_inc.php'; if ($user['droits']['compta'] < Membres::DROIT_ADMIN) { throw new UserException("Vous n'avez pas le droit d'accéder à cette page."); } $e = new Compta\Exercices(); $exercice = $e->get((int) Utils::get('id')); if (!$exercice) { throw new UserException('Exercice inconnu.'); } if ($exercice['cloture']) { throw new UserException('Impossible de modifier un exercice clôturé.'); } $error = false; if (!empty($_POST['edit'])) { if (!Utils::CSRF_check('compta_modif_exercice_' . $exercice['id'])) { $error = 'Une erreur est survenue, merci de renvoyer le formulaire.'; } else { try { $id = $e->edit($exercice['id'], ['libelle' => Utils::post('libelle'), 'debut' => Utils::post('debut'), 'fin' => Utils::post('fin')]); Utils::redirect('/admin/compta/exercices/'); } catch (UserException $e) { $error = $e->getMessage(); } } } $tpl->assign('error', $error); $tpl->assign('exercice', $exercice);
private function _log($log, $type = 'query') { $logs = Utils::get('queriesLogs'); if (null === $logs) { $logs = new Log(LOGS_PATH . DS . date("Y-m-d") . '_queries.log'); Utils::set('queriesLogs', $logs); } $logs->write($type, $log); }
<?php namespace Garradin; require_once __DIR__ . '/../_inc.php'; if ($user['droits']['compta'] < Membres::DROIT_ADMIN) { throw new UserException("Vous n'avez pas le droit d'accéder à cette page."); } $cats = new Compta\Categories(); $id = (int) Utils::get('id'); $cat = $cats->get($id); if (!$cat) { throw new UserException('Cette catégorie n\'existe pas.'); } $error = false; if (!empty($_POST['save'])) { if (!Utils::CSRF_check('compta_edit_cat_' . $cat['id'])) { $error = 'Une erreur est survenue, merci de renvoyer le formulaire.'; } else { try { $id = $cats->edit($id, ['intitule' => Utils::post('intitule'), 'description' => Utils::post('description')]); if ($cat['type'] == Compta\Categories::DEPENSES) { $type = 'depenses'; } elseif ($cat['type'] == Compta\Categories::AUTRES) { $type = 'autres'; } else { $type = 'recettes'; } Utils::redirect('/admin/compta/categories/?' . $type); } catch (UserException $e) { $error = $e->getMessage();
<?php namespace Garradin; require_once __DIR__ . '/../_inc.php'; $compte = $comptes->get(Utils::get('id')); if (!$compte) { throw new UserException("Le compte demandé n'existe pas."); } $journal = new Compta\Journal(); $solde = $journal->getSolde($compte['id']); if ($compte['position'] & Compta\Comptes::ACTIF || $compte['position'] & Compta\Comptes::CHARGE) { $tpl->assign('credit', '-'); $tpl->assign('debit', '+'); } else { $tpl->assign('credit', '+'); $tpl->assign('debit', '-'); } $tpl->assign('compte', $compte); $tpl->assign('solde', $solde); $tpl->assign('journal', $journal->getJournalCompte($compte['id'])); $tpl->display('admin/compta/comptes/journal.tpl');
<?php namespace Garradin; require_once __DIR__ . '/../../../_inc.php'; if ($user['droits']['membres'] < Membres::DROIT_ADMIN) { throw new UserException("Vous n'avez pas le droit d'accéder à cette page."); } if (!Utils::get('id') || !is_numeric(Utils::get('id'))) { throw new UserException("Argument du numéro de cotisation manquant."); } $cotisations = new Cotisations(); $co = $cotisations->get(Utils::get('id')); $cats = new Compta\Categories(); if (!$co) { throw new UserException("Cette cotisation n'existe pas."); } $error = false; if (!empty($_POST['save'])) { if (!Utils::CSRF_check('edit_co_' . $co['id'])) { $error = 'Une erreur est survenue, merci de renvoyer le formulaire.'; } else { try { $duree = Utils::post('periodicite') == 'jours' ? (int) Utils::post('duree') : null; $debut = Utils::post('periodicite') == 'date' ? Utils::post('debut') : null; $fin = Utils::post('periodicite') == 'date' ? Utils::post('fin') : null; $id_cat = Utils::post('categorie') ? (int) Utils::post('id_categorie_compta') : null; $cotisations->edit($co['id'], ['intitule' => Utils::post('intitule'), 'description' => Utils::post('description'), 'montant' => (double) Utils::post('montant'), 'duree' => $duree, 'debut' => $debut, 'fin' => $fin, 'id_categorie_compta' => $id_cat]); Utils::redirect('/admin/membres/cotisations/'); } catch (UserException $e) { $error = $e->getMessage();
<?php namespace Garradin; const LOGIN_PROCESS = true; require_once __DIR__ . '/_inc.php'; $error = false; if (trim(Utils::get('c'))) { if ($membres->recoverPasswordConfirm(Utils::get('c'))) { Utils::redirect('/admin/password.php?new_sent'); } $error = 'EXPIRED'; } elseif (!empty($_POST['recover'])) { if (!Utils::CSRF_check('recoverPassword')) { $error = 'OTHER'; } else { if (trim(Utils::post('id')) && $membres->recoverPasswordCheck(Utils::post('id'))) { Utils::redirect('/admin/password.php?sent'); } $error = 'MAIL'; } } if (!$error && isset($_GET['sent'])) { $tpl->assign('sent', true); } elseif (!$error && isset($_GET['new_sent'])) { $tpl->assign('new_sent', true); } $champs = $config->get('champs_membres'); $champ = $champs->get($config->get('champ_identifiant')); $tpl->assign('champ', $champ); $tpl->assign('error', $error);
public function actionChangeLanguage() { /* Change the session's language if the requested language is * supported */ Utils::changeLanguage(Utils::get($_GET, 'lang')); /* Return to the previous page */ $returnUrl = Yii::app()->request->urlReferrer; if (!$returnUrl) { $returnUrl = '/'; } $this->redirect($returnUrl); }
<?php namespace Garradin; require_once __DIR__ . '/../_inc.php'; if ($user['droits']['membres'] < Membres::DROIT_ECRITURE) { throw new UserException("Vous n'avez pas le droit d'accéder à cette page."); } $recherche = trim(Utils::get('r')); $champ = trim(Utils::get('c')); $champs = $config->get('champs_membres'); $auto = false; // On détermine magiquement quel champ on recherche if (!$champ) { $auto = true; if (is_numeric(trim($recherche))) { $champ = 'id'; } elseif (strpos($recherche, '@') !== false) { $champ = 'email'; } else { $champ = $config->get('champ_identite'); } } else { if ($champ != 'id' && !$champs->get($champ)) { throw new UserException('Le champ demandé n\'existe pas.'); } } if ($recherche != '') { $result = $membres->search($champ, $recherche); if (count($result) == 1 && $auto) { Utils::redirect('/admin/membres/fiche.php?id=' . (int) $result[0]['id']);
<?php namespace Garradin; require_once __DIR__ . '/../../_inc.php'; if ($user['droits']['membres'] < Membres::DROIT_ECRITURE) { throw new UserException("Vous n'avez pas le droit d'accéder à cette page."); } if (empty($_GET['id']) || !is_numeric($_GET['id'])) { throw new UserException("Argument du numéro de cotisation manquant."); } $id = (int) $_GET['id']; $cotisations = new Cotisations(); $m_cotisations = new Membres\Cotisations(); $co = $cotisations->get($id); if (!$co) { throw new UserException("Cette cotisation n'existe pas."); } $page = (int) Utils::get('p') ?: 1; $tpl->assign('page', $page); $tpl->assign('bypage', Membres\Cotisations::ITEMS_PER_PAGE); $tpl->assign('total', $m_cotisations->countMembersForCotisation($co['id'])); $tpl->assign('pagination_url', Utils::getSelfUrl(true) . '?id=' . $co['id'] . '&p=[ID]'); $tpl->assign('cotisation', $co); $tpl->assign('order', Utils::get('o') ?: 'date'); $tpl->assign('desc', !isset($_GET['a'])); $tpl->assign('liste', $m_cotisations->listMembersForCotisation($co['id'], $page, Utils::get('o'), isset($_GET['a']) ? false : true)); $tpl->display('admin/membres/cotisations/voir.tpl');
<?php namespace Garradin; require_once __DIR__ . '/_inc.php'; if ($user['droits']['wiki'] < Membres::DROIT_ECRITURE) { throw new UserException("Vous n'avez pas le droit d'accéder à cette page."); } if (!Utils::get('id') || !is_numeric(Utils::get('id'))) { throw new UserException('Numéro de page invalide.'); } $page = $wiki->getById(Utils::get('id')); $error = false; if (!$page) { throw new UserException('Page introuvable.'); } if (!empty($page['contenu'])) { $page['chiffrement'] = $page['contenu']['chiffrement']; $page['contenu'] = $page['contenu']['contenu']; } if (Utils::post('date')) { $date = Utils::post('date') . ' ' . Utils::post('date_h') . ':' . Utils::post('date_min'); } else { $date = false; } if (!empty($_POST['save'])) { if (!Utils::CSRF_check('wiki_edit_' . $page['id'])) { $error = 'Une erreur est survenue, merci de renvoyer le formulaire.'; } elseif ($page['date_modification'] > (int) Utils::post('debut_edition')) { $error = 'La page a été modifiée par quelqu\'un d\'autre depuis que vous avez commencé l\'édition.'; } else {