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]); }
/** * 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')); } }
/** * Does the logout for a user. */ public function logoutAction() { unset($_SESSION['user_id']); \Ilch\Registry::remove('user'); if ($this->getRequest()->getParam('from_frontend')) { $this->redirect(array()); } else { $this->redirect(array('module' => 'admin', 'controller' => 'login', 'action' => 'index')); } }
/** * 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; }
/** * Filling the config object with individual testcase data and injecting it into the registry. */ public static function setConfigInRegistry($configData) { if (static::$config === null) { if (!Registry::has('config') && file_exists(CONFIG_PATH . '/config.php')) { static::$config = new Config(); static::$config->loadConfigFromFile(CONFIG_PATH . '/config.php'); foreach ($configData as $configKey => $configValue) { static::$config->set($configKey, $configValue); } } } Registry::remove('config'); Registry::set('config', self::$config); }
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')); } }
/** * Checks if a user id was given in the request and sets the user. * * If no user id is given a default user will be created. * * @param array $pluginData */ public function __construct(array $pluginData) { if (!isset($pluginData['config'])) { return; } $userId = null; if (isset($_SESSION['user_id'])) { $userId = (int) $_SESSION['user_id']; } $mapper = new UserMapper(); $user = $mapper->getUserById($userId); \Ilch\Registry::set('user', $user); if (isset($_SERVER["HTTP_X_FORWARDED_FOR"]) && preg_match("/^[0-9a-zA-Z\\/.:]{7,}\$/", $_SERVER["HTTP_X_FORWARDED_FOR"])) { $ip = $_SERVER["HTTP_X_FORWARDED_FOR"]; } elseif (preg_match("/^[0-9a-zA-Z\\/.:]{7,}\$/", $_SERVER["REMOTE_ADDR"])) { $ip = $_SERVER["REMOTE_ADDR"]; } else { $ip = '128.0.0.1'; } if (empty($_SERVER['PATH_INFO']) or strpos($_SERVER['PATH_INFO'], 'admin', 1)) { $site = ''; } else { $site = $_SERVER['PATH_INFO']; } function statisticOS($useragent) { $osArray = array('Windows XP' => '=Windows NT 5.1|Windows XP=', 'Windows Vista' => '=Windows NT 6.0|Windows Vista=', 'Windows 7' => '=Windows NT 6.1|Windows 7=', 'Windows 8' => '=Windows NT 6.2|Windows 8=', 'Windows 8.1' => '=Windows NT 6.3|Windows 8.1=', 'Windows 10' => '=Windows NT 10.0|Windows 10=', 'Windows 2000' => '=Windows NT 5.0|Windows 2000=', 'Windows Server 2003\\Windows XP x64' => '=Windows NT 5\\.2|Windows Server 2003|Windows XP x64=', 'Windows NT' => '=Windows NT 4|WinNT4=', 'Windows 98' => '=Windows 98=', 'Windows 95' => '=Windows 95=', 'Android' => '=Android=', 'Linux' => '=Linux|Ubuntu|X11=', 'SunOs' => '=SunOS=', 'iPhone' => '=iPhone=', 'iPad' => '=iPad=', 'Mac OS' => '=Mac OS X=', 'Macintosh' => '=Mac_PowerPC|Macintosh='); foreach ($osArray as $os => $regex) { if (preg_match($regex, $useragent)) { return $os; } } return 0; } $os = statisticOS($_SERVER['HTTP_USER_AGENT']); function statisticBrowser($useragent) { if (preg_match("=Firefox/([\\.a-zA-Z0-9]*)=", $useragent, $browser)) { return "Firefox " . $browser[1]; } elseif (preg_match("=MSIE ([0-9]{1,2})\\.[0-9]{1,2}=", $useragent, $browser)) { return "Internet Explorer " . $browser[1]; } elseif (preg_match("=rv:([0-9]{1,2})\\.[0-9]{1,2}=", $useragent, $browser)) { return "Internet Explorer " . $browser[1]; } elseif (preg_match("=Opera[/ ]([0-9\\.]+)=", $useragent, $browser)) { return "Opera " . $browser[1]; } elseif (preg_match("=OPR\\/([0-9\\.]*)=", $useragent, $browser)) { $tmp = explode('.', $browser[1]); if (count($tmp) > 2) { $browser[1] = $tmp[0] . '.' . $tmp[1]; } return "Opera " . $browser[1]; } elseif (preg_match("=Edge/([0-9\\.]*)=", $useragent, $browser)) { $tmp = explode('.', $browser[1]); if (count($tmp) > 2) { $browser[1] = $tmp[0] . '.' . $tmp[1]; } return "Edge " . $browser[1]; } elseif (preg_match("=Chrome/([0-9\\.]*)=", $useragent, $browser)) { $tmp = explode('.', $browser[1]); if (count($tmp) > 2) { $browser[1] = $tmp[0] . '.' . $tmp[1]; } return "Chrome " . $browser[1]; } elseif (preg_match('=Safari/=', $useragent)) { if (preg_match('=Version/([\\.0-9]*)=', $useragent, $browser)) { $version = ' ' . $browser[1]; } else { $version = ''; } return "Safari" . $version; } elseif (preg_match("=Konqueror=", $useragent)) { return "Konqueror"; } elseif (preg_match("=Netscape|Navigator=", $useragent)) { return "Netscape"; } else { return 0; } } $browser = statisticBrowser($_SERVER['HTTP_USER_AGENT']); if (empty($_SERVER["HTTP_REFERER"])) { $referer = ''; } else { $referer = $_SERVER["HTTP_REFERER"]; } $lang = substr($_SERVER["HTTP_ACCEPT_LANGUAGE"], 0, 2); $statisticMapper = new \Modules\Statistic\Mappers\Statistic(); $statisticMapper->saveVisit(array('user_id' => $userId, 'site' => $site, 'referer' => $referer, 'os' => $os, 'browser' => $browser, 'ip' => $ip, 'lang' => $lang)); if ($pluginData['request']->getParam('language')) { $_SESSION['language'] = $pluginData['request']->getParam('language'); } if ($pluginData['request']->getParam('ilch_layout')) { $_SESSION['layout'] = $pluginData['request']->getParam('ilch_layout'); } $pluginData['translator']->setLocale($pluginData['config']->get('locale')); if (!empty($_SESSION['language'])) { $pluginData['translator']->setLocale($_SESSION['language']); } }
<?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());
/** * 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'); } }
/** * 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; }
/** * Injects layout and gets database. * * @param \Ilch\Layout\Base $layout */ public function __construct($layout) { $this->db = \Ilch\Registry::get('db'); $this->layout = $layout; }
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--; } } }
/** * Gets the page queries. * * @return integer */ public function queryCount() { $db = \Ilch\Registry::get('db'); return $db->queryCount(); }
/** * Tests if the access for a user can be returned. */ public function testHasAccess() { $group = new Group(); $group->setId(3); $group->setName('Testgroup'); $user = new User(); $user->setId(123); $user->addGroup($group); $dbMock = $this->getMock('Ilch_Database', array('queryCell')); $dbMock->expects($this->once())->method('queryCell')->with($this->logicalAnd($this->stringContains('FROM [prefix]_groups_access'), $this->stringContains('INNER JOIN `[prefix]_modules`'), $this->stringContains('user')))->will($this->returnValue('0')); Registry::remove('db'); Registry::set('db', $dbMock); $this->assertEquals(0, $user->hasAccess('module_user')); }
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--; } } }
/** * Tests if the timezone with an empty Registry-Key 'timezone'. */ public function testNewEmptyDateWithoutRegistry() { Registry::remove('timezone'); $date = new \Ilch\Date(); $this->assertEquals('UTC', $date->getTimeZone()->getName(), 'Timezone is not UTC as expected when creating Ilch_Date without a paramter.'); }
public function configAction() { $errors = array(); if ($this->getRequest()->isPost()) { $_SESSION['install']['usage'] = $this->getRequest()->getPost('usage'); $_SESSION['install']['modulesToInstall'][$_SESSION['install']['usage']] = $this->getRequest()->getPost('modulesToInstall'); $_SESSION['install']['adminName'] = $this->getRequest()->getPost('adminName'); $_SESSION['install']['adminPassword'] = $this->getRequest()->getPost('adminPassword'); $_SESSION['install']['adminPassword2'] = $this->getRequest()->getPost('adminPassword2'); $_SESSION['install']['adminEmail'] = $this->getRequest()->getPost('adminEmail'); if (empty($_SESSION['install']['adminName'])) { $errors['adminName'] = 'fieldEmpty'; } if (empty($_SESSION['install']['adminPassword'])) { $errors['adminPassword'] = '******'; } if ($_SESSION['install']['adminPassword'] !== $_SESSION['install']['adminPassword2']) { $errors['adminPassword2'] = 'fieldDiffersPassword'; } if (empty($_SESSION['install']['adminEmail'])) { $errors['adminEmail'] = 'fieldEmpty'; } elseif (!filter_var($_SESSION['install']['adminEmail'], FILTER_VALIDATE_EMAIL)) { $errors['adminEmail'] = 'fieldEmail'; } if (empty($errors)) { /* * Write install config. */ $fileConfig = new \Ilch\Config\File(); $fileConfig->set('dbEngine', $_SESSION['install']['dbEngine']); $fileConfig->set('dbHost', $_SESSION['install']['dbHost']); $fileConfig->set('dbUser', $_SESSION['install']['dbUser']); $fileConfig->set('dbPassword', $_SESSION['install']['dbPassword']); $fileConfig->set('dbName', $_SESSION['install']['dbName']); $fileConfig->set('dbPrefix', $_SESSION['install']['dbPrefix']); $fileConfig->saveConfigToFile(CONFIG_PATH . '/config.php'); /* * Initialize install database. */ $dbFactory = new \Ilch\Database\Factory(); $db = $dbFactory->getInstanceByConfig($fileConfig); \Ilch\Registry::set('db', $db); $modulesToInstall = $_SESSION['install']['modulesToInstall'][$_SESSION['install']['usage']]; if (!empty($modulesToInstall)) { $modulesToInstall = array_merge(array('admin', 'article', 'user', 'page', 'media', 'comment', 'imprint', 'contact', 'privacy', 'statistic'), $modulesToInstall); } else { $modulesToInstall = array('admin', 'article', 'user', 'page', 'media', 'comment', 'imprint', 'contact', 'privacy', 'statistic'); } $moduleMapper = new \Modules\Admin\Mappers\Module(); /* * Clear old tables. */ $db->dropTablesByPrefix($db->getPrefix()); foreach ($modulesToInstall as $module) { $configClass = '\\Modules\\' . ucfirst($module) . '\\Config\\config'; $config = new $configClass($this->getTranslator()); $config->install(); if (!empty($config->config)) { $moduleModel = new \Modules\Admin\Models\Module(); $moduleModel->setKey($config->config['key']); if (isset($config->config['author'])) { $moduleModel->setAuthor($config->config['author']); } if (isset($config->config['languages'])) { foreach ($config->config['languages'] as $key => $value) { $moduleModel->addContent($key, $value); } } if (isset($config->config['system_module'])) { $moduleModel->setSystemModule(true); } $moduleModel->setIconSmall($config->config['icon_small']); $moduleMapper->save($moduleModel); } } $menuMapper = new \Modules\Admin\Mappers\Menu(); $menu1 = new \Modules\Admin\Models\Menu(); $menu1->setId(1); $menu1->setTitle('Hauptmenü'); $menuMapper->save($menu1); $menu2 = new \Modules\Admin\Models\Menu(); $menu2->setId(2); $menu2->setTitle('Hauptmenü 2'); $menuMapper->save($menu2); $sort = 0; $menuItem = new \Modules\Admin\Models\MenuItem(); $menuItem->setMenuId(1); $menuItem->setParentId(0); $menuItem->setTitle('Menü'); $menuItem->setType(0); $menuMapper->saveItem($menuItem); /* * Will not linked in menu */ foreach ($modulesToInstall as $module) { if (in_array($module, array('comment', 'shoutbox', 'admin', 'media', 'page', 'newsletter', 'statistic'))) { continue; } $configClass = '\\Modules\\' . ucfirst($module) . '\\Config\\config'; $config = new $configClass($this->getTranslator()); $menuItem = new \Modules\Admin\Models\MenuItem(); $menuItem->setMenuId(1); $menuItem->setSort($sort); $menuItem->setParentId(1); $menuItem->setType(3); $menuItem->setModuleKey($config->config['key']); $menuItem->setTitle($config->config['languages'][$this->getTranslator()->getLocale()]['name']); $menuMapper->saveItem($menuItem); $sort += 10; } $boxes = "INSERT INTO `[prefix]_menu_items` (`menu_id`, `sort`, `parent_id`, `page_id`, `box_id`, `box_key`, `type`, `title`, `href`, `module_key`) VALUES\n (1, 80, 0, 0, 0, 'user_login', 4, 'Login', '', ''),\n (1, 90, 0, 0, 0, 'admin_layoutswitch', 4, 'Layout', '', ''),\n (1, 100, 0, 0, 0, 'statistic_stats', 4, 'Statistik', '', ''),\n (1, 110, 0, 0, 0, 'statistic_online', 4, 'Online', '', ''),\n (2, 10, 0, 0, 0, 'admin_langswitch', 4, 'Sprache', '', ''),\n (2, 20, 0, 0, 0, 'article_article', 4, 'Letzte Artikel', '', ''),\n (2, 30, 0, 0, 0, 'article_categories', 4, 'Kategorien', '', ''),\n (2, 40, 0, 0, 0, 'article_archive', 4, 'Archive', '', '')"; $db->queryMulti($boxes); unset($_SESSION['install']); $this->redirect(array('action' => 'finish')); } $this->getView()->set('errors', $errors); } foreach (array('modulesToInstall', 'usage', 'adminName', 'adminPassword', 'adminPassword2', 'adminEmail') as $name) { if (!empty($_SESSION['install'][$name])) { $this->getView()->set($name, $_SESSION['install'][$name]); } } }
/** * Gets the user object. * * @return \Modules\User\Models\User */ public function getUser() { return \Ilch\Registry::get('user'); }
/** * 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 ($userMapper->delete($userId)) { $this->addMessage('delUserMsg'); } } } $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()); ?>
error_reporting(E_ALL); session_start(); header('Content-Type: text/html; charset=utf-8'); $serverTimeZone = @date_default_timezone_get(); date_default_timezone_set('UTC'); define('VERSION', '2.0.0'); define('ILCH_SERVER', 'http://www.ilch.de/ilch2'); define('SERVER_TIMEZONE', $serverTimeZone); define('DEFAULT_MODULE', 'page'); define('DEFAULT_LAYOUT', 'index'); /* * Path could not be under root. */ define('APPLICATION_PATH', __DIR__ . '/application'); define('CONFIG_PATH', APPLICATION_PATH); $rewriteBaseParts = explode('index.php', str_replace('Index.php', 'index.php', $_SERVER['PHP_SELF'])); $rewriteBaseParts = rtrim(reset($rewriteBaseParts), '/'); define('REWRITE_BASE', $rewriteBaseParts); $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http'; define('BASE_URL', $protocol . '://' . $_SERVER['HTTP_HOST'] . REWRITE_BASE); require_once APPLICATION_PATH . '/libraries/Ilch/Loader.php'; $loader = new \Ilch\Loader(); $loader->registNamespace('Thumb'); \Ilch\Registry::set('startTime', microtime(true)); try { $page = new \Ilch\Page(); $page->loadCms(); $page->loadPage(); } catch (Exception $ex) { print 'An unexpected error occurred: ' . $ex->getMessage(); }