/** * Generate Nav Array * * Creates an array of navigation items to be used with the mustache templates. * * @return array */ public function navArray($displayLogout = false) { $navItems = array('' => 'Home', 'session' => 'Start', 'about' => 'About', 'terms' => 'Terms', 'privacy' => 'Privacy'); if ($displayLogout === true) { $navItems['session/end'] = 'Logout'; } $navArray = array(); $navArray['nav'] = array(); foreach ($navItems as $k => $v) { if ($k === $this->active) { // Class for active nav items. $active = 'active'; } else { $active = null; } $navArray['nav'][] = array('title' => $v, 'active' => $active, 'url' => Utility::buildFullLink($this->config, true, $k)); } return $navArray; }
<?php /** * File: index.php * User: zacharydubois * Date: 2016-01-04 * Time: 20:47 * Project: Digital-Footprint-Profile */ namespace dfp; // Create objects. $config = new Config(); $view = new View($config); $nav = new Nav($config); // Create nav (Index is empty). $nav->setActive(''); // Tell view the nav array. $view->navArray($nav->navArray()); // Tell view what template and content. $view->tpl('index'); $view->content(array('title' => 'Welcome | Digital Footprint Profile', 'sessionLink' => Utility::buildFullLink($config, true, 'session'))); echo $view->render();
<?php /** * File: twitter.php * User: zacharydubois * Date: 2016-01-04 * Time: 20:49 * Project: Digital-Footprint-Profile */ namespace dfp; $denied = filter_input(INPUT_GET, 'denied'); $config = new Config(); $session = new Session($config); if (!isset($denied) || array_key_exists('oauth_verifier', $_GET)) { // Create twitter. $twitter = new Twitter($config, $session); $twitter->accessToken(); $twitter->getPosts(); $session->setTMP('allowNext', true); } header('Location: ' . Utility::buildFullLink($config, false, 'session'));
/** * Render * * Renders and returns the rendered template. * * @return string * @throws Exception */ public function render() { if ($this->tpl !== 'email' && isset($this->content) && isset($this->tpl) && isset($this->nav)) { $base = array('home' => Utility::buildFullLink($this->config, true), 'version' => VERSION, 'copyright' => $this->config->get('custom', 'copyright')); $content = array_merge($base, array_merge($this->nav, array_merge($this->assetsArray(), $this->content))); } elseif ($this->tpl === 'email') { $base = array('home' => Utility::buildFullLink($this->config), 'version' => VERSION, 'copyright' => $this->config->get('custom', 'copyright')); $content = array_merge($base, $this->content); } else { throw new Exception("View cannot render as required content is not set."); } return $this->mustache->render($this->tpl, $content); }
/** * Ends and Clears Session * * Ends the PHP session, deletes the cookie, and updates the session file expire time. * * @return true * @throws Exception */ public function endSession() { // Remove the cookie. setcookie(DFP_SESSION_NAME, $this->sid, time() - 1, Utility::buildFullLink($this->config, true, 'session'), $this->config->get('server', 'domain'), Utility::httpsBool($this->config), true); // Update file expire. $this->fileSession['dfp']['expire'] = time(); // Clear TMP $this->clearTMP(); if (!$this->DataStore->write($this->fileSession)) { throw new Exception("Unable to update session expire time."); } return true; }
*/ namespace dfp; // Create config $config = new Config(); // Create session instance. $session = new Session($config); // Create Nav $nav = new Nav($config); $nav->setActive('session'); // Create view. $view = new View($config); $view->navArray($nav->navArray(true)); $view->tpl('session'); // Twitter if ($session->getTMP('twitter_name') === false) { $twitter = new Twitter($config, $session); $twitterButton = array('url' => $twitter->authorizeURL(), 'text' => 'Login with Twitter', 'classes' => ''); } else { $twitterButton = array('url' => '#', 'text' => 'Twitter: @' . $session->getTMP('twitter_name'), 'classes' => 'disabled'); } // Facebook if ($session->getTMP('facebook_name') === false) { $facebook = new Facebook($config, $session); $facebookButton = array('url' => $facebook->authorizeURL(), 'text' => 'Login with Facebook', 'classes' => ''); } else { $facebookButton = array('url' => '#', 'text' => 'Facebook: ' . $session->getTMP('facebook_name'), 'classes' => 'disabled'); } // Render and return $view->content(array('title' => 'Start | Digital Footprint Profile', 'listURL' => Utility::buildFullLink($config, false, 'session/list'), 'loginButtons' => array($twitterButton, $facebookButton))); echo $view->render();