Exemplo n.º 1
0
 public function view($arguments)
 {
     if (empty($arguments[0])) {
         return Error::set('No bug ID found.');
     }
     if (!empty($arguments[1])) {
         $page = (int) array_pop($arguments);
         if ($page < 1) {
             $this->view['commentPage'] = 1;
         } else {
             $this->view['commentPage'] = $page;
         }
     } else {
         $this->view['commentPage'] = 1;
     }
     $this->view['commentPageLoc'] = 'bugs/view/' . $arguments[0] . '/';
     $bugs = new bugs(ConnectionFactory::get('mongo'));
     $this->view['bug'] = $bugs->get($arguments[0], true, true);
     if (is_string($this->view['bug'])) {
         return Error::set($this->view['bug']);
     }
     if (!bugs::canView($this->view['bug'])) {
         return Error::set('You are not allowed to view this bug.');
     }
     $this->view['valid'] = true;
     Layout::set('title', $this->view['bug']['title']);
     if ($this->view['bug']['flagged'] == true && CheckAcl::can('unflagBug')) {
         $bugs->alter($this->view['bug']['_id'], array('flagged' => false));
     }
 }
Exemplo n.º 2
0
 public function index($arguments)
 {
     $news = new news(ConnectionFactory::get('mongo'));
     $articles = new articles(ConnectionFactory::get('mongo'));
     $notices = new notices(ConnectionFactory::get('redis'));
     $irc = new irc(ConnectionFactory::get('redis'));
     $quotes = new quotes(ConnectionFactory::get('mongo'));
     $forums = new forums(ConnectionFactory::get('redis'));
     // Set all site-wide notices.
     foreach ($notices->getAll() as $notice) {
         Error::set($notice, true);
     }
     // Fetch the easy data.
     $this->view['news'] = $news->getNewPosts();
     $this->view['shortNews'] = $news->getNewPosts(true);
     $this->view['newArticles'] = $articles->getNewPosts('new', 1, 5);
     $this->view['ircOnline'] = $irc->getOnline();
     $this->view['randomQuote'] = $quotes->getRandom();
     $this->view['fPosts'] = $forums->getNew();
     // Get online users.
     $apc = new APCIterator('user', '/' . Cache::PREFIX . 'user_.*/');
     $this->view['onlineUsers'] = array();
     while ($apc->valid()) {
         $current = $apc->current();
         array_push($this->view['onlineUsers'], substr($current['key'], strlen(Cache::PREFIX) + 5));
         $apc->next();
     }
     // Set title.
     Layout::set('title', 'Home');
 }
Exemplo n.º 3
0
 public function index()
 {
     if (Session::isLoggedIn()) {
         return Error::set(self::ERR_LOGGED_IN);
     }
     $this->view['valid'] = true;
     Layout::set('title', 'Account Recovery');
 }
Exemplo n.º 4
0
 /**
  * Set Data
  *
  * @param string $key
  * @param $value
  *
  * @return $this
  *
  * @since 1.0.0
  */
 public function set($key, $value)
 {
     if (!$this->layout instanceof Layout) {
         throw new ViewException(sprintf('View %s layout not started!', get_called_class()));
     }
     $this->layout->set($key, $value);
     return $this;
 }
Exemplo n.º 5
0
 public function index()
 {
     if (!CheckAcl::can('manageNotice')) {
         return Error::set('You are not allowed to manage notices.');
     }
     $notices = new notices(ConnectionFactory::get('redis'));
     $this->view['valid'] = true;
     $this->view['notices'] = $notices->getAll();
     Layout::set('title', 'Manage Notices');
 }
Exemplo n.º 6
0
 public function index()
 {
     $lectures = new lectures(ConnectionFactory::get('mongo'));
     $this->view['lectures'] = $lectures->getNew();
     if (is_string($this->view['lectures'])) {
         return Error::set($this->view['lectures']);
     }
     $this->view['valid'] = true;
     Layout::set('title', 'Lectures');
 }
Exemplo n.º 7
0
 public function index($arguments)
 {
     Layout::set('title', 'Search');
     if (empty($_POST['query'])) {
         return Error::set('No search query found.');
     }
     $query = substr(trim(htmlentities($_POST['query'], ENT_QUOTES, 'ISO8859-1', false)), 0, 250);
     $results = Search::query($query);
     if ($results['hits']['total'] == 0) {
         return Error::set('No results found.');
     }
     $this->view['results'] = array();
     $news = new news(ConnectionFactory::get('mongo'));
     $articles = new articles(ConnectionFactory::get('mongo'));
     $lectures = new lectures(ConnectionFactory::get('mongo'));
     $i = 1;
     if (empty($results['hits']['hits'])) {
         return;
     }
     foreach ($results['hits']['hits'] as $result) {
         $entry = $result['_source'];
         switch ($entry['type']) {
             case 'news':
                 $post = $news->get($result['_id'], false, true);
                 if (empty($post)) {
                     continue;
                 }
                 $post['type'] = 'news';
                 array_push($this->view['results'], $post);
                 break;
             case 'article':
                 $article = $articles->get($result['_id'], false, true);
                 if (empty($article)) {
                     continue;
                 }
                 $article['type'] = 'article';
                 array_push($this->view['results'], $article);
                 break;
             case 'lecture':
                 $lecture = $lectures->get($result['_id'], false, true);
                 if (empty($lecture)) {
                     continue;
                 }
                 $lecture['type'] = 'lecture';
                 array_push($this->view['results'], $lecture);
                 break;
         }
         if ($i == 5) {
             break;
         }
         ++$i;
     }
 }
Exemplo n.º 8
0
 public function view($arguments)
 {
     if (!empty($arguments[3])) {
         $page = (int) array_pop($arguments);
         if ($page < 1) {
             $this->view['commentPage'] = 1;
         } else {
             $this->view['commentPage'] = $page;
         }
     } else {
         $this->view['commentPage'] = 1;
     }
     if (!empty($_GET['p'])) {
         $page = (int) $_GET['p'];
         if ($page < 1) {
             $this->view['page'] = 1;
         } else {
             $this->view['page'] = $page;
         }
     } else {
         $this->view['page'] = 1;
     }
     @($id = implode('/', $arguments));
     if (empty($id)) {
         return Error::set('Invalid id.');
     }
     $newsModel = new news(ConnectionFactory::get('mongo'));
     list($news, $this->view['total']) = $newsModel->get($id, true, false, true, $this->view['page']);
     if (is_string($news)) {
         return Error::set($news);
     }
     $this->view['news'] = $news;
     $this->view['multiple'] = count($news) > 1;
     $this->view['url'] = Url::format('/news/view/' . $id . '?p=');
     if ($this->view['multiple']) {
         return;
     }
     $this->view['commentPageLoc'] = 'news/view/' . $id . '/';
     Layout::set('title', $this->view['news'][0]['title']);
     $mlt = Search::mlt($this->view['news'][0]['_id'], 'news', 'title,body,tags');
     $this->view['mlt'] = array();
     if (empty($mlt['hits']['hits'])) {
         return;
     }
     foreach ($mlt['hits']['hits'] as $post) {
         $fetched = $newsModel->get($post['_id'], false, true);
         if (empty($fetched)) {
             continue;
         }
         array_push($this->view['mlt'], $fetched);
     }
 }
Exemplo n.º 9
0
 private static function dispatch($request)
 {
     $controller = self::CONTROLLER_PREFIX . array_shift($request);
     // if no route is set then default to index
     if (!count($request)) {
         $request = array(0 => self::DEFAULT_METHOD);
     }
     if (!class_exists($controller)) {
         $controller = "controller_nil";
     }
     if (!method_exists($controller, $request[0])) {
         $controller = "controller_nil";
     }
     $class = new $controller($request);
     // pass the request to the controller and return the result
     Layout::set("content", $class);
 }
Exemplo n.º 10
0
 public static function render($view, $data, $finalCut)
 {
     Layout::set("leftNav", Config::get("display:leftnav"));
     // localize all the view variables.
     extract($data);
     // Start capturing a new output buffer, load the view
     // and apply all the display logic to the localized data
     // and save the results in $parsed.
     ob_start();
     require $view;
     $parsed = ob_get_clean();
     if (!$finalCut) {
         return $parsed;
     }
     Layout::set("content", $parsed);
     ob_start();
     echo Layout::render();
     $full = ob_get_clean();
     return $full;
 }
Exemplo n.º 11
0
 public static function handler($data = null)
 {
     Session::init();
     $key = Cache::PREFIX . 'sessionReq_' . Session::getId();
     if (apc_exists($key)) {
         Session::setBatchVars(apc_fetch($key));
         apc_delete($key);
     }
     $ip = Session::getVar('ip');
     if (Session::isLoggedIn() && Session::getVar('lockToIP') && $ip != null && $ip != $_SERVER['REMOTE_ADDR']) {
         Session::destroy();
         header('Location: ' . Url::format('/'));
         die;
     }
     Session::setVar('ip', $_SERVER['REMOTE_ADDR']);
     $twitter = new twitter(ConnectionFactory::get('redis'));
     Layout::set('tweets', $twitter->getOfficialTweets());
     self::slowBan();
     self::errorBan();
 }
Exemplo n.º 12
0
 public static function get()
 {
     if (!\Current_User::isLogged()) {
         return;
     }
     $modlist = PHPWS_Core::getModuleNames();
     $tpl['MINIADMIN_TITLE'] = dgettext('miniadmin', 'MiniAdmin');
     $tpl['MINIADMIN_TITLE_ALT'] = dgettext('miniadmin', 'Administrate');
     if (isset($GLOBALS['MiniAdmin'])) {
         foreach ($GLOBALS['MiniAdmin'] as $module => $links) {
             $mod_title = $modlist[$module];
             if (isset($links['title_link'])) {
                 $mod_title = sprintf('<a href="%s">%s</a>', $links['title_link'], $mod_title);
             }
             $module_links[$mod_title] = $links;
         }
         $tpl['module_links'] = $module_links;
     }
     $template = new \Template($tpl);
     $template->setModuleTemplate('miniadmin', MINIADMIN_TEMPLATE);
     $content = $template->get();
     Layout::set($content, 'miniadmin', 'mini_admin');
 }
Exemplo n.º 13
0
 public function settings($arguments)
 {
     // Update
     if (!Session::isLoggedIn()) {
         return Error::set('You are not logged in!');
     }
     $user = new users(ConnectionFactory::get('mongo'));
     $this->view['valid'] = true;
     $this->view['user'] = $user->get(Session::getVar('username'));
     $this->view['secure'] = !empty($_SERVER['SSL_CLIENT_RAW_CERT']) ? true : false;
     if ($this->view['secure']) {
         $this->view['clientSSLKey'] = certs::getKey($_SERVER['SSL_CLIENT_RAW_CERT']);
     }
     if (!empty($arguments[0]) && $arguments[0] == 'save') {
         if (!empty($_POST['oldpassword']) && !empty($_POST['password'])) {
             $old = $user->hash($_POST['oldpassword'], $this->view['user']['username']);
             if ($old != $this->view['user']['password']) {
                 return Error::set('Previous password is invalid.');
             }
         }
         $username = !empty($_POST['username']) ? $_POST['username'] : null;
         $password = !empty($_POST['password']) ? $_POST['password'] : null;
         $email = !empty($_POST['email']) ? $_POST['email'] : null;
         $hideEmail = !empty($_POST['hideEmail']) ? true : false;
         $lockToIp = !empty($_POST['lockToIp']) ? true : false;
         $error = $user->edit(Session::getVar('_id'), $username, $password, $email, $hideEmail, null, $lockToIp);
         if (is_string($error)) {
             return Error::set($error);
         }
         $this->view['user'] = $user->get(Session::getVar('username'));
         Session::setBatchVars($this->view['user']);
         Error::set('User profile saved.', true);
     }
     if (!empty($arguments[0]) && $arguments[0] == 'saveAuth') {
         $password = !empty($_POST['passwordAuth']) ? true : false;
         $certificate = !empty($_POST['certificateAuth']) ? true : false;
         $certAndPass = !empty($_POST['certAndPassAuth']) ? true : false;
         $autoauth = !empty($_POST['autoAuth']) ? true : false;
         $return = $user->changeAuth(Session::getVar('_id'), $password, $certificate, $certAndPass, $autoauth);
         if (is_string($return)) {
             return Error::set($return);
         }
         $this->view['user'] = $user->get(Session::getVar('username'));
     }
     Layout::set('title', 'Settings');
 }
Exemplo n.º 14
0
 public function nil()
 {
     Layout::set('title', 'Not Found');
 }
Exemplo n.º 15
0
 public function revisions($arguments)
 {
     if (!$this->hasRevisions) {
         return Error::set('Revisions are not enabled for ' . $this->name . '.');
     }
     if (!CheckAcl::can('view' . $this->permission . 'Revisions')) {
         return Error::set('You are not allowed to view ' . $this->name . ' revisions.');
     }
     if (empty($arguments[0])) {
         return Error::set('No ' . $this->name . ' id found.');
     }
     $model = new $this->model(ConnectionFactory::get($this->db));
     $current = $model->get($arguments[0], false, true);
     $this->view['current'] = $current;
     if (empty($current)) {
         return Error::set('Invalid id.');
     }
     if (is_string($current)) {
         return Error::set($current);
     }
     Layout::set('title', ucwords($this->name) . ' Revisions');
     $revisions = new revisions(ConnectionFactory::get('mongo'));
     // Start excerpt soley for reverting
     $revert = $this->revert($arguments, $model, $revisions, $current);
     // End excerpt
     $revisions = $revisions->getForId($arguments[0]);
     $this->view['revisions'] = array();
     if (empty($revisions)) {
         return Error::set('This entry has no revisions.');
     }
     $this->view['revisions'] = revisions::resolve($current, $revisions, $this->diffdFields);
 }
Exemplo n.º 16
0
 public function index($arguments)
 {
     $this->view['planet'] = 'Earth';
     // Set title.
     Layout::set('title', 'Home');
 }
Exemplo n.º 17
0
 public static function getLogin()
 {
     $user = $_SESSION['User'];
     $auth = Current_User::getAuthorization();
     if (empty($auth)) {
         throw new Exception(t('Failed to retrieve the current authorization: %s', $_SESSION['User']->auth_script));
     }
     // If the current user is not verified then
     // either force to authentication page or clear the user session
     if (!$auth->verify()) {
         // reset user session is set
         if ($user->id) {
             Current_User::init();
         }
         // if they are force login, the below will send them there
         // and we will end getLogin
         // if not forced, then we just continue;
         $auth->forceLogin();
     }
     PHPWS_Core::initModClass('users', 'User_Form.php');
     $login = User_Form::logBox();
     if (!empty($login)) {
         Layout::set($login, 'users', 'login_box', false);
     }
 }
Exemplo n.º 18
0
 public static function categoryView()
 {
     $active_menu = self::getCurrentActiveMenu();
     if ($active_menu == 0) {
         $menu_tpl['home_active'] = 1;
     } else {
         $menu_tpl['home_active'] = 0;
     }
     $db = \Database::newDB();
     $m = $db->addTable('menus');
     $k = $db->addTable('phpws_key');
     $k->addField('url');
     $db->joinResources($m, $k, $db->createConditional($m->getField('assoc_key'), $k->getField('id'), '='), 'left');
     $m->addOrderBy($m->getField('queue'));
     $key = \Key::getCurrent();
     if ($key && $key->id) {
         $current_key_id = $key->id;
     } else {
         $current_key_id = -1;
     }
     $menus = $db->select();
     if (empty($menus)) {
         return;
     }
     foreach ($menus as $m) {
         $menu = new Menu_Item();
         PHPWS_Core::plugObject($menu, $m);
         $menu->_show_all = true;
         if (empty($menu->assoc_url)) {
             $menu->setAssocUrl($m['url']);
         }
         // if the current menu matches a used link (either by it being in the
         // in the menu or associated to it) mark as ACTIVE
         $active = $active_menu == $menu->id || $current_key_id == $menu->assoc_key ? 1 : 0;
         // if there is not an assoc key, them menu is using drop downs, so
         // we do not add the side menu
         if ($active) {
             if ($menu->assoc_key) {
                 Layout::set($menu->view(), 'menu', 'side');
             }
             if ($menu->assoc_image) {
                 Layout::set($menu->showAssocImage(), 'menu', 'image');
             }
         }
         $menu_tpl['menus'][] = self::getCategoryViewLine($menu, $active);
     }
     $template = new \Template($menu_tpl);
     \Layout::addJSHeader("<script type='text/javascript' src='" . PHPWS_SOURCE_HTTP . "javascript/responsive_img/responsive-img.min.js'></script>", 81);
     $template->setModuleTemplate('menu', 'category_view/category_menu.html');
     \Layout::add($template->get(), 'menu', 'top_view');
 }
Exemplo n.º 19
0
 public function approve($arguments)
 {
     if (!CheckAcl::can('approveArticles')) {
         return Error::set('You can not approve articles!');
     }
     Layout::set('title', 'Unapproved Articles');
     $articles = new articles(ConnectionFactory::get('mongo'));
     $unapproved = $articles->getNextUnapproved();
     if (empty($unapproved)) {
         return Error::set('No unapproved articles.', true);
     }
     if (!empty($arguments[0]) && $arguments[0] == 'save' && !empty($_POST['decision'])) {
         if ($_POST['decision'] == 'Publish') {
             $articles->approve($unapproved['_id']);
             Error::set('Article approved.', true);
         } else {
             if ($_POST['decision'] == 'Delete') {
                 $articles->delete($unapproved['_id']);
                 Error::set('Article deleted.', true);
             }
         }
         $unapproved = $articles->getNextUnapproved();
         if (empty($unapproved)) {
             return Error::set('No unapproved articles left.', true);
         }
     }
     $this->view['article'] = $unapproved;
 }
Exemplo n.º 20
0
 private function nil()
 {
     $this->setView('nil');
     Layout::set('title', 'Not Found');
 }
Exemplo n.º 21
0
 public static function handler($data = null)
 {
     Layout::set("leftNav", Config::get("display:leftnav"));
     echo Layout::render();
 }