/** * Redirects the user to the admin login page, if the user is not logged in, yet. * * If the user is logged in already redirect the user to the Admincenter. * * @param array $pluginData */ public function __construct(array $pluginData) { $request = $pluginData['request']; if (isset($pluginData['config'])) { $config = $pluginData['config']; $userId = null; if (isset($_SESSION['user_id'])) { $userId = (int) $_SESSION['user_id']; } $userMapper = new UserMapper(); $translator = new \Ilch\Translator(); $user = $userMapper->getUserById($userId); if ($config->get('maintenance_mode') && !$request->isAdmin()) { if (empty($user)) { $pluginData['layout']->setFile('modules/admin/layouts/maintenance'); } else { if (!$user->isAdmin()) { $pluginData['layout']->setFile('modules/admin/layouts/maintenance'); } } $_SESSION['messages'][] = array('text' => $translator->trans('siteMaintenanceMode'), 'type' => 'danger'); } } if ($request->isAdmin() && $request->getControllerName() !== 'login' && !\Ilch\Registry::get('user')) { /* * User is not logged in yet but wants to go to the admincenter, redirect him to the login. */ $pluginData['controller']->redirect(array('module' => 'admin', 'controller' => 'login', 'action' => 'index')); } elseif ($request->getModuleName() === 'admin' && $request->getControllerName() === 'login' && $request->getActionName() !== 'logout' && \Ilch\Registry::get('user')) { /* * User is logged in but wants to go to the login, redirect him to the admincenter. */ $pluginData['controller']->redirect(array('module' => 'admin', 'controller' => 'index', 'action' => 'index')); } }
/** * Shows the standard login page. * Takes the request data for the login and tries to login the user. */ public function indexAction() { $errors = array(); if ($this->getRequest()->isPost()) { if (\Ilch\Registry::get('user')) { $errors[] = 'alreadyLoggedIn'; } $emailName = $this->getRequest()->getPost('emailname'); if ($emailName === '') { $errors[] = 'noUserEmailGiven'; } else { $password = $this->getRequest()->getPost('password'); $language = $this->getRequest()->getPost('language'); if (!empty($language)) { $_SESSION['language'] = $language; $this->getTranslator()->setLocale($language, true); } $result = LoginService::factory()->perform($emailName, $password); if ($result->isSuccessful()) { $this->redirect(array('controller' => 'index', 'action' => 'index')); } else { $errors[] = $result->getError(); } } $this->getLayout()->set('emailname', $emailName); } $this->getLayout()->set('errors', $errors); $this->getLayout()->set('languages', $this->getTranslator()->getLocaleList()); }
public function indexAction() { $this->getLayout()->getHmenu()->add($this->getTranslator()->trans('menuLogin'), array('action' => 'index')); $errors = array(); $redirectUrl = ''; if ($this->getRequest()->isPost()) { if (\Ilch\Registry::get('user')) { $errors['alreadyLoggedIn'] = 'alreadyLoggedIn'; } $emailName = $this->getRequest()->getPost('login_emailname'); $password = $this->getRequest()->getPost('login_password'); $redirectUrl = $this->getRequest()->getPost('login_redirect_url'); if (empty($emailName)) { $errors['login_emailname'] = 'fieldEmpty'; } elseif (empty($password)) { $errors['login_password'] = '******'; } else { $result = LoginService::factory()->perform($emailName, $password); if ($result->isSuccessful()) { $this->addMessage($this->getTranslator()->trans('loginSuccessful'), 'success'); } else { $this->addMessage($this->getTranslator()->trans($result->getError()), 'warning'); $redirectUrl = array('module' => 'user', 'controller' => 'login', 'action' => 'index'); } $this->redirect($redirectUrl); } $this->getView()->set('errors', $errors); } if (!empty($_SESSION['redirect'])) { $redirectUrl = $_SESSION['redirect']; unset($_SESSION['redirect']); } $this->getView()->setArray(['errors' => $errors, 'regist_accept' => $this->getConfig()->get('regist_accept'), 'redirectUrl' => $redirectUrl]); }
/** * Gets page description from config or meta settings. * * @return string */ public function getDescription() { $config = \Ilch\Registry::get('config'); $metaDescription = $this->get('metaDescription'); if (!empty($metaDescription)) { return $metaDescription; } if (!empty($config) && $config->get('description') !== '') { return $config->get('description'); } return ''; }
/** * Gets the menu items as html-string. * * @param string $tpl * @param array $options * @return string */ public function getItems($tpl = '', $options = array()) { $html = ''; $locale = ''; $htmlMenuItems = ''; $menuMapper = new \Modules\Admin\Mappers\Menu(); $items = $menuMapper->getMenuItemsByParent($this->getId(), 0); $boxMapper = new \Modules\Admin\Mappers\Box(); $config = \Ilch\Registry::get('config'); if ((bool) $config->get('multilingual_acp')) { if ($this->layout->getTranslator()->getLocale() != $config->get('content_language')) { $locale = $this->layout->getTranslator()->getLocale(); } } if (!empty($items)) { foreach ($items as $item) { if ($item->getType() == 0 || $item->getType() == 4) { $html = str_replace('%c', $htmlMenuItems, $html); $htmlMenuItems = ''; $html .= str_replace('%s', $item->getTitle(), $tpl); if ($item->getType() == 4) { if ($item->getBoxId()) { $box = $boxMapper->getBoxByIdLocale($item->getBoxId(), $locale); } else { $parts = explode('_', $item->getBoxKey()); $moduleKey = $parts[0]; $boxKey = $parts[1]; $class = '\\Modules\\' . ucfirst($moduleKey) . '\\Boxes\\' . ucfirst($boxKey); $view = new \Ilch\View($this->layout->getRequest(), $this->layout->getTranslator(), $this->layout->getRouter()); $this->layout->getTranslator()->load(APPLICATION_PATH . '/modules/' . $moduleKey . '/translations'); $boxObj = new $class($this->layout, $view, $this->layout->getRequest(), $this->layout->getRouter(), $this->layout->getTranslator()); $boxObj->render(); $viewPath = APPLICATION_PATH . '/' . dirname($this->layout->getFile()) . '/override/' . $moduleKey . '/boxes/views/' . $boxKey . '.php'; if (!file_exists($viewPath)) { $viewPath = APPLICATION_PATH . '/modules/' . $moduleKey . '/boxes/views/' . $boxKey . '.php'; } $view->setLayoutKey($this->layout->getLayoutKey()); $output = $view->loadScript($viewPath); $box = new \Modules\Admin\Models\Box(); $box->setContent($output); } $html = str_replace('%c', $box->getContent(), $html); } else { $htmlMenuItems .= $this->recGetItems($item, $locale, $options); } } } $html = str_replace('%c', $htmlMenuItems, $html); $htmlMenuItems = ''; } return $html; }
public function treatAction() { if ($this->getRequest()->getParam('id') !== null) { $user = \Ilch\Registry::get('user'); if (!$user->hasAccess('box_' . $this->getRequest()->getParam('id'))) { $this->redirect(array('action' => 'index')); } } $this->getView()->set('contentLanguage', $this->getConfig()->get('content_language')); $boxMapper = new BoxMapper(); if ($this->getRequest()->getParam('id')) { if ($this->getRequest()->getParam('locale') == '') { $locale = ''; } else { $locale = $this->getRequest()->getParam('locale'); } $this->getView()->set('box', $boxMapper->getBoxByIdLocale($this->getRequest()->getParam('id'), $locale)); } $this->getView()->set('languages', $this->getTranslator()->getLocaleList()); $this->getView()->set('multilingual', (bool) $this->getConfig()->get('multilingual_acp')); if ($this->getRequest()->isPost()) { $model = new BoxModel(); if ($this->getRequest()->getParam('id')) { $model->setId($this->getRequest()->getParam('id')); } $model->setTitle($this->getRequest()->getPost('boxTitle')); $model->setContent($this->getRequest()->getPost('boxContent')); if ($this->getRequest()->getPost('boxLanguage') != '') { $model->setLocale($this->getRequest()->getPost('boxLanguage')); } else { $model->setLocale(''); } $boxMapper->save($model); $this->redirect(array('action' => 'index')); } }
?> > <a href="<?php echo $this->getUrl(array('module' => 'admin', 'controller' => 'menu', 'action' => 'index')); ?> "> <i class="fa fa-list-ol"></i> <?php echo $this->getTrans('navigation'); ?> </a> </li> <?php } ?> <?php $user = \Ilch\Registry::get('user'); ?> <?php $modulesHtml = $systemModuleHtml = ''; ?> <?php foreach ($this->get('modules') as $module) { ?> <?php if ($user->hasAccess('module_' . $module->getKey())) { ?> <?php $content = $module->getContentForLocale($this->getTranslator()->getLocale()); ?>
/** * Returns whether the user has access to a specific key. * * @todo Remove from user model and create acl class * @param string $key A module-key, page-id or article-id prefixed by either one of these: "module_", "page_", "article_". * @param boolean $isInAdmin Whether the user is in the admin backend currently. * * @return boolean True if access granted, false otherwise. * * @todo refactor -> kein Abhängigkeiten zu anderen Klassen, die keine Models sind */ public function hasAccess($key, $isInAdmin = true) { if (in_array(1, array_keys($this->getGroups()))) { /* * The user is an admin, allow him everything. */ return true; } $type = ''; $sql = 'SELECT ga.access_level FROM [prefix]_groups_access AS ga'; if (strpos($key, 'module_') !== false) { $moduleKey = substr($key, 7); $type = 'module'; $sqlJoin = ' INNER JOIN `[prefix]_modules` AS m ON ga.module_key = m.key'; $sqlWhere = ' WHERE m.key = "' . $moduleKey . '"'; } elseif (strpos($key, 'page_') !== false) { $pageId = (int) substr($key, 5); $type = 'page'; $sqlJoin = ' INNER JOIN `[prefix]_pages` AS p ON ga.page_id = p.id'; $sqlWhere = ' WHERE p.id = ' . (int) $pageId; } elseif (strpos($key, 'article_') !== false) { $articleId = (int) substr($key, 8); $type = 'article'; $sqlJoin = ' INNER JOIN [prefix]_articles AS a ON ga.article_id = a.id'; $sqlWhere = ' WHERE a.id = ' . (int) $articleId; } elseif (strpos($key, 'box_') !== false) { $boxId = (int) substr($key, 4); $type = 'box'; $sqlJoin = ' INNER JOIN [prefix]_boxes AS b ON ga.box_id = b.id'; $sqlWhere = ' WHERE b.id = ' . (int) $boxId; } $sql .= $sqlJoin . $sqlWhere . ' AND ga.group_id IN (' . implode(',', array_keys($this->getGroups())) . ') ORDER BY access_level DESC LIMIT 1'; $db = \Ilch\Registry::get('db'); $accessLevel = (int) $db->queryCell($sql); if ($isInAdmin && $accessLevel === 2 || !$isInAdmin && $accessLevel >= 1) { return true; } else { return false; } }
/** * Deletes the given user. */ public function deleteAction() { $userMapper = new UserMapper(); $userId = $this->getRequest()->getParam('id'); if ($userId && $this->getRequest()->isSecure()) { $deleteUser = $userMapper->getUserById($userId); /* * Admingroup has always id "1" because group is not deletable. */ if ($deleteUser->getId() == Registry::get('user')->getId()) { $this->addMessage('delOwnUserProhibited', 'warning'); } elseif ($deleteUser->hasGroup(1) && $userMapper->getAdministratorCount() === 1) { $this->addMessage('delLastAdminProhibited', 'warning'); /* * Delete adminuser only if he is not the last admin. */ } else { if ($deleteUser->getAvatar() != 'static/img/noavatar.jpg') { unlink($deleteUser->getAvatar()); } if (is_dir(APPLICATION_PATH . '/modules/user/static/upload/gallery/' . $userId)) { $path = APPLICATION_PATH . '/modules/user/static/upload/gallery/' . $userId; $files = array_diff(scandir($path), array('.', '..')); foreach ($files as $file) { unlink(realpath($path) . '/' . $file); } rmdir($path); } if ($userMapper->delete($userId)) { $this->addMessage('delUserMsg'); } } } $this->redirect(array('action' => 'index')); }
/** * Defines the start page. * * @param string $startPage * @param \Ilch\Translator $translator * @return null */ public function defineStartPage($startPage, $translator) { if (!empty($this->query)) { return; } $config = \Ilch\Registry::get('config'); $locale = ''; if ((bool) $config->get('multilingual_acp')) { if ($translator->getLocale() != $config->get('content_language')) { $locale = $translator->getLocale(); } } if (strpos($startPage, 'module_') !== false) { $this->request->setModuleName(str_replace('module_', '', $startPage)); $this->request->setControllerName('index'); $this->request->setActionName('index'); } elseif (strpos($startPage, 'page_') !== false) { $this->request->setModuleName('page'); $this->request->setControllerName('index'); $this->request->setActionName('show'); $this->request->setParam('id', str_replace('page_', '', $startPage)); $this->request->setParam('locale', $locale); } elseif (strpos($startPage, 'layouts_') !== false) { $this->request->setModuleName(str_replace('layouts_', '', $startPage)); $this->request->setControllerName('index'); } else { $this->request->setModuleName(DEFAULT_MODULE); $this->request->setControllerName('index'); $this->request->setActionName('index'); } }
/** * Gets the page queries. * * @return integer */ public function queryCount() { $db = \Ilch\Registry::get('db'); return $db->queryCount(); }
function rec($id, $uid, $req, $obj) { $CommentMappers = new \Modules\Comment\Mappers\Comment(); $userMapper = new \Modules\User\Mappers\User(); $fk_comments = $CommentMappers->getCommentsByFKId($id); $user_rep = $userMapper->getUserById($uid); $config = \Ilch\Registry::get('config'); foreach ($fk_comments as $fk_comment) { $commentDate = new \Ilch\Date($fk_comment->getDateCreated()); $user = $userMapper->getUserById($fk_comment->getUserId()); if ($req > $config->get('comment_interleaving')) { $req = $config->get('comment_interleaving'); } $col = 9 - $req; $req = $req + 1; echo '<article class="row" id="' . $fk_comment->getId() . '">'; if ($config->get('comment_avatar') == 1) { echo '<div class="col-md-2 col-sm-2 col-md-offset-' . $req . ' col-sm-offset-' . $req . ' hidden-xs">'; echo '<figure class="thumbnail" title="' . $user->getName() . '">'; echo '<a href="' . $obj->getUrl(array('module' => 'user', 'controller' => 'profil', 'action' => 'index', 'user' => $user->getId())) . '"><img class="img-responsive" src="' . $obj->getBaseUrl($user->getAvatar()) . '" alt="' . $user->getName() . '"></a>'; echo '</figure>'; echo '</div>'; echo '<div class="col-md-' . $col . ' col-sm-' . $col . '">'; } else { $col = $col + 2; echo '<div class="col-md-' . $col . ' col-sm-' . $col . ' col-md-offset-' . $req . ' col-sm-offset-' . $req . '">'; } echo '<div class="panel panel-default">'; echo '<div class="panel-bodylist">'; echo '<div class="panel-heading right"><i class="fa fa-reply"></i> ' . $user_rep->getName() . '</div>'; echo '<header class="text-left">'; echo '<div class="comment-user">'; echo '<i class="fa fa-user" title="' . $obj->getTrans('commentUser') . '"></i> <a href="' . $obj->getUrl(array('module' => 'user', 'controller' => 'profil', 'action' => 'index', 'user' => $fk_comment->getUserId())) . '">' . $user->getName() . '</a>'; echo '</div>'; if ($config->get('comment_date') == 1) { echo '<time class="comment-date"><i class="fa fa-clock-o" title="' . $obj->getTrans('dateTime') . '"></i> ' . $commentDate->format("d.m.Y - H:i", true) . '</time>'; } echo '</header>'; echo '<div class="comment-post"><p>' . nl2br($fk_comment->getText()) . '</p></div>'; if ($config->get('comment_reply') == 1) { echo '<p class="text-right"><a href="' . $obj->getUrl(array('module' => 'comment', 'controller' => 'index', 'action' => 'index', 'id' => $fk_comment->getId(), 'id_a' => $obj->getRequest()->getParam('id'))) . '" class="btn btn-default btn-sm"><i class="fa fa-reply"></i> ' . $obj->getTrans('reply') . '</a></p>'; } echo '</div>'; echo '</div>'; echo '</div>'; echo '</article>'; $fkk_comments = $CommentMappers->getCommentsByFKId($fk_comment->getId()); if (count($fkk_comments) > 0) { $req++; } $i = 1; foreach ($fkk_comments as $fkk_comment) { if ($i == 1) { rec($fk_comment->getId(), $fk_comment->getUserId(), $req, $obj); $i++; } } if (count($fkk_comments) > 0) { $req--; } } }
function rec($id, $uid, $req, $obj) { $CommentMappers = new \Modules\Comment\Mappers\Comment(); $userMapper = new \Modules\User\Mappers\User(); $fk_comments = $CommentMappers->getCommentsByFKId($id); $user_rep = $userMapper->getUserById($uid); $config = \Ilch\Registry::get('config'); $nowDate = new \Ilch\Date(); foreach ($fk_comments as $fk_comment) { $commentDate = new \Ilch\Date($fk_comment->getDateCreated()); $user = $userMapper->getUserById($fk_comment->getUserId()); if ($req > $config->get('comment_interleaving')) { $req = $config->get('comment_interleaving'); } $col = 10 - $req; echo ' <article class="row" id="comment_' . $fk_comment->getId() . '">'; if ($config->get('comment_avatar') == 1) { echo ' <div class="col-md-2 col-sm-2 col-md-offset-' . $req . ' col-sm-offset-' . $req . ' hidden-xs">'; echo ' <figure class="thumbnail" title="' . $user->getName() . '">'; echo ' <a href="' . $obj->getUrl(array('module' => 'user', 'controller' => 'profil', 'action' => 'index', 'user' => $user->getId())) . '"><img class="img-responsive" src="' . $obj->getBaseUrl($user->getAvatar()) . '" alt="' . $user->getName() . '"></a>'; echo ' </figure>'; echo ' </div>'; echo ' <div class="col-md-' . $col . ' col-sm-' . $col . '">'; } else { $col = $col + 2; echo ' <div class="col-md-' . $col . ' col-sm-' . $col . ' col-md-offset-' . $req . ' col-sm-offset-' . $req . '">'; } echo ' <div class="panel panel-default">'; echo ' <div class="panel-bodylist">'; echo ' <div class="panel-heading right"><i class="fa fa-reply"></i> ' . $user_rep->getName() . '</div>'; echo ' <header class="text-left">'; echo ' <div class="comment-user">'; echo ' <i class="fa fa-user" title="' . $obj->getTrans('commentUser') . '"></i> <a href="' . $obj->getUrl(array('module' => 'user', 'controller' => 'profil', 'action' => 'index', 'user' => $fk_comment->getUserId())) . '">' . $user->getName() . '</a>'; echo ' </div>'; if ($config->get('comment_date') == 1) { echo '<time class="comment-date"><i class="fa fa-clock-o" title="' . $obj->getTrans('commentDateTime') . '"></i> ' . $commentDate->format("d.m.Y - H:i", true) . '</time>'; } echo ' </header>'; echo ' <div class="comment-post"><p>' . nl2br($fk_comment->getText()) . '</p></div>'; if ($obj->getUser() and $config->get('comment_reply') == 1) { echo '<p class="text-right"><a href="javascript:slideReply(\'reply_' . $fk_comment->getId() . '\');" class="btn btn-default btn-sm"><i class="fa fa-reply"></i> ' . $obj->getTrans('reply') . '</a></p>'; } echo ' </div>'; echo ' </div>'; echo ' </div>'; echo ' </article>'; if ($obj->getUser()) { echo ' <div class="replyHidden" id="reply_' . $fk_comment->getId() . '">'; echo ' <form action="" class="form-horizontal" method="POST">'; echo $obj->getTokenField(); echo ' <section class="comment-list">'; echo ' <article class="row">'; $col = $col - 1; $req = $req + 1; if ($config->get('comment_avatar') == 1) { echo ' <div class="col-md-2 col-sm-2 col-md-offset-' . $req . ' col-sm-offset-' . $req . ' hidden-xs">'; echo ' <figure class="thumbnail" title="' . $obj->getUser()->getName() . '">'; echo ' <a href="' . $obj->getUrl('user/profil/index/user/' . $obj->getUser()->getId()) . '"><img class="img-responsive" src="' . $obj->getUrl() . '/' . $obj->getUser()->getAvatar() . '" alt="' . $obj->getUser()->getName() . '"></a>'; echo ' </figure>'; echo ' </div>'; } echo ' <div class="col-md-' . $col . ' col-sm-' . $col . '">'; echo ' <div class="panel panel-default">'; echo ' <div class="panel-body">'; echo ' <div class="panel-heading right"><i class="fa fa-reply"></i> ' . $user->getName() . '</div>'; echo ' <header class="text-left">'; echo ' <div class="comment-user">'; echo ' <i class="fa fa-user" title="' . $obj->getTrans('commentUser') . '"></i> <a href="' . $obj->getUrl(array('module' => 'user', 'controller' => 'profil', 'action' => 'index', 'user' => $obj->getUser()->getId())) . '">' . $obj->getUser()->getName() . '</a>'; echo ' </div>'; if ($config->get('comment_date') == 1) { echo '<time class="comment-date"><i class="fa fa-clock-o" title="' . $obj->getTrans('commentDateTime') . '"></i> ' . $nowDate->format("d.m.Y - H:i", true) . '</time>'; } echo ' </header>'; echo ' <div class="comment-post">'; echo ' <p>'; echo ' <textarea class="form-control" accesskey="" name="article_comment_text" style="resize: vertical" required></textarea>'; echo ' </p>'; echo ' </div>'; echo ' <input type="hidden" name="fkId" value="' . $fk_comment->getId() . '" />'; echo ' <p class="text-right submit">'; echo $obj->getSaveBar('submit', 'Comment'); echo ' </p>'; echo ' </div>'; echo ' </div>'; echo ' </div>'; echo ' </article>'; echo ' </section>'; echo ' </form>'; echo ' </div>'; } $fkk_comments = $CommentMappers->getCommentsByFKId($fk_comment->getId()); $req = $req - 1; if (count($fkk_comments) > 0) { $req++; } $i = 1; foreach ($fkk_comments as $fkk_comment) { if ($i == 1) { rec($fk_comment->getId(), $fk_comment->getUserId(), $req, $obj); $i++; } } if (count($fkk_comments) > 0) { $req--; } } }
<?php $linkus = $this->get('linkus'); $config = \Ilch\Registry::get('config'); ?> <legend><?php echo $this->getTrans('menuLinkus'); ?> </legend> <?php if ($linkus != '') { ?> <?php foreach ($linkus as $linkus) { ?> <div class="row"> <div class="col-lg-12"> <h4><?php echo $this->escape($linkus->getTitle()); ?> </h4> <div class="col-lg-12 text-center"> <a href="<?php echo $this->getUrl(); ?> " target="_blank"><img src="<?php echo $this->getBaseUrl($this->escape($linkus->getBanner())); ?> " alt="<?php echo $this->escape($linkus->getTitle());
/** * Injects layout and gets database. * * @param \Ilch\Layout\Base $layout */ public function __construct($layout) { $this->db = \Ilch\Registry::get('db'); $this->layout = $layout; }
/** * Deletes the given user. */ public function deleteAction() { $userMapper = new UserMapper(); $userId = $this->getRequest()->getParam('id'); if ($userId && $this->getRequest()->isSecure()) { $deleteUser = $userMapper->getUserById($userId); /* * Admingroup has always id "1" because group is not deletable. */ if ($deleteUser->getId() == Registry::get('user')->getId()) { $this->addMessage('delOwnUserProhibited', 'warning'); } elseif ($deleteUser->hasGroup(1) && $userMapper->getAdministratorCount() === 1) { $this->addMessage('delLastAdminProhibited', 'warning'); /* * Delete adminuser only if he is not the last admin. */ } else { if ($deleteUser->getAvatar() != 'static/img/noavatar.jpg') { unlink($deleteUser->getAvatar()); } if ($userMapper->delete($userId)) { $this->addMessage('delUserMsg'); } } } $this->redirect(array('action' => 'index')); }
/** * Gets the user object. * * @return \Modules\User\Models\User */ public function getUser() { return \Ilch\Registry::get('user'); }
/** * Returns config or marks test as skipped if config could not be loaded * * @return Config|null */ protected function getConfig() { $config = Registry::get('config'); if (!$config instanceof Config) { $this->markTestSkipped('Necessary DB configuration is not set.'); } return $config; }