Beispiel #1
0
 public function auth($options, &$userArray)
 {
     if (isset($options['startOver']) && $options['startOver']) {
         $this->reset();
     }
     if (isset($_REQUEST['openid_mode'])) {
         if (isset($_REQUEST['openid_identity'])) {
             if ($ns = $this->getOpenIDNamespace('http://specs.openid.net/extensions/oauth/1.0', $_REQUEST)) {
                 if ($request_token = $this->getOpenIDValue('request_token', $ns, $_REQUEST)) {
                     $this->setToken(OAuthProvider::TOKEN_TYPE_REQUEST, $request_token);
                     if (!$this->getAccessToken($options)) {
                         throw new KurogoDataServerException("Error getting OAuth Access token");
                     }
                 }
             }
             $userArray = $_REQUEST;
             return AUTH_OK;
         } else {
             Kurogo::log(LOG_WARNING, "openid_identity not found", 'auth');
             return AUTH_FAILED;
         }
     } else {
         //redirect to auth page
         $url = $this->getAuthURL($options);
         Kurogo::redirectToURL($url);
     }
 }
Beispiel #2
0
 protected function initializeForPage()
 {
     if ($url = $this->getModuleVar('url')) {
         $this->logView();
         Kurogo::redirectToURL($url);
     } else {
         throw new KurogoConfigurationException("URL not specified");
     }
 }
Beispiel #3
0
/**
 * Exception Handler set in Kurogo::initialize()
 */
function exceptionHandlerForProduction(Exception $exception)
{
    $bt = $exception->getTrace();
    array_unshift($bt, array('line' => $exception->getLine(), 'file' => $exception->getFile()));
    Kurogo::log(LOG_ALERT, sprintf("A %s has occured: %s", get_class($exception), $exception->getMessage()), "exception", $bt);
    if ($exception instanceof KurogoException) {
        $sendNotification = $exception->shouldSendNotification();
    } else {
        $sendNotification = true;
    }
    if ($sendNotification) {
        $to = Kurogo::getSiteVar('DEVELOPER_EMAIL');
        if (!Kurogo::deviceClassifier()->isSpider() && $to) {
            mail($to, "Mobile web page experiencing problems", "The following page is throwing exceptions:\n\n" . "URL: http" . (IS_SECURE ? 's' : '') . "://" . SERVER_HOST . "{$_SERVER['REQUEST_URI']}\n" . "User-Agent: \"{$_SERVER['HTTP_USER_AGENT']}\"\n" . "Referrer URL: \"{$_SERVER['HTTP_REFERER']}\"\n" . "Exception:\n\n" . var_export($exception, true));
        }
    }
    if ($url = getErrorURL($exception)) {
        Kurogo::redirectToURL($url);
    } else {
        die("A serious error has occurred");
    }
}
Beispiel #4
0
 protected function initializeForPage()
 {
     $nativeApp = (bool) $this->getArg('nativeApp', false);
     $this->assign('nativeApp', $nativeApp);
     // Default args to pass through forms and urls
     $defaultArgs = array();
     if ($nativeApp) {
         $defaultArgs['nativeApp'] = 1;
     }
     // If this is a native app, use the native app GA id
     if ($nativeApp) {
         $this->assign('GOOGLE_ANALYTICS_ID', Kurogo::getOptionalSiteVar('GOOGLE_ANALYTICS_NATIVE_ID'));
     }
     if (!Kurogo::getSiteVar('AUTHENTICATION_ENABLED')) {
         throw new KurogoConfigurationException($this->getLocalizedString("ERROR_AUTHENTICATION_DISABLED"));
     }
     $session = $this->getSession();
     //return URL
     $urlArray = $this->extractModuleArray($this->args);
     //see if remain logged in is enabled by the administrator, then if the value has been passed (i.e. the user checked the "remember me" box)
     $allowRemainLoggedIn = Kurogo::getOptionalSiteVar('AUTHENTICATION_REMAIN_LOGGED_IN_TIME');
     if ($allowRemainLoggedIn) {
         $remainLoggedIn = $this->getArg('remainLoggedIn', 0);
     } else {
         $remainLoggedIn = 0;
     }
     // initialize
     $authenticationAuthorities = array('total' => 0, 'direct' => array(), 'indirect' => array(), 'auto' => array());
     $invalidAuthorities = array();
     // cycle through the defined authorities in the config
     foreach (AuthenticationAuthority::getDefinedAuthenticationAuthorities() as $authorityIndex => $authorityData) {
         // USER_LOGIN property determines whether the authority is used for logins (or just groups or oauth)
         $USER_LOGIN = $this->argVal($authorityData, 'USER_LOGIN', 'NONE');
         // trap the exception if the authority is invalid (usually due to misconfiguration)
         try {
             $authority = AuthenticationAuthority::getAuthenticationAuthority($authorityIndex);
             $authorityData['listclass'] = $authority->getAuthorityClass();
             $authorityData['title'] = $authorityData['TITLE'];
             $authorityData['url'] = $this->buildURL('login', array_merge($urlArray, array('authority' => $authorityIndex, 'remainLoggedIn' => $remainLoggedIn, 'startOver' => 1)));
             if ($USER_LOGIN == 'FORM') {
                 $authenticationAuthorities['direct'][$authorityIndex] = $authorityData;
                 $authenticationAuthorities['total']++;
             } elseif ($USER_LOGIN == 'LINK') {
                 $authenticationAuthorities['indirect'][$authorityIndex] = $authorityData;
                 $authenticationAuthorities['total']++;
             } elseif ($USER_LOGIN == 'AUTO') {
                 $authenticationAuthorities['auto'][$authorityIndex] = $authorityData;
                 $authenticationAuthorities['total']++;
             }
         } catch (KurogoConfigurationException $e) {
             Kurogo::log(LOG_WARNING, "Invalid authority data for %s: %s", $authorityIndex, $e->getMessage(), 'auth');
             $invalidAuthorities[$authorityIndex] = $e->getMessage();
         }
     }
     //see if we have any valid authorities
     if ($authenticationAuthorities['total'] == 0) {
         $message = $this->getLocalizedString("ERROR_NO_AUTHORITIES");
         if (count($invalidAuthorities) > 0) {
             $message .= sprintf(" %s invalid authorit%s found:\n", count($invalidAuthorities), count($invalidAuthorities) > 1 ? 'ies' : 'y');
             foreach ($invalidAuthorities as $authorityIndex => $invalidAuthority) {
                 $message .= sprintf("%s: %s\n", $authorityIndex, $invalidAuthority);
             }
         }
         //we don't
         throw new KurogoConfigurationException($message);
     }
     //assign template variables
     $this->assign('authenticationAuthorities', $authenticationAuthorities);
     $this->assign('allowRemainLoggedIn', $allowRemainLoggedIn);
     if ($forgetPasswordURL = $this->getOptionalModuleVar('FORGET_PASSWORD_URL')) {
         $this->assign('FORGET_PASSWORD_URL', $this->buildBreadcrumbURL('forgotpassword', array()));
         $this->assign('FORGET_PASSWORD_TEXT', $this->getOptionalModuleVar('FORGET_PASSWORD_TEXT', $this->getLocalizedString('FORGET_PASSWORD_TEXT')));
     }
     $multipleAuthorities = count($authenticationAuthorities['direct']) + count($authenticationAuthorities['indirect']) > 1;
     switch ($this->page) {
         case 'logoutConfirm':
             //this page is presented when a specific authority is chosen and the user is presented the option to actually log out.
             $authorityIndex = $this->getArg('authority');
             if (!$this->isLoggedIn($authorityIndex)) {
                 // they aren't logged in
                 $this->redirectTo('index', $defaultArgs);
             } elseif ($user = $this->getUser($authorityIndex)) {
                 $authority = $user->getAuthenticationAuthority();
                 $this->assign('message', $this->getLocalizedString('LOGIN_SIGNED_IN_SINGLE', Kurogo::getSiteString('SITE_NAME'), $authority->getAuthorityTitle(), $user->getFullName()));
                 $this->assign('url', $this->buildURL('logout', array('authority' => $authorityIndex)));
                 $this->assign('linkText', $this->getLocalizedString('SIGN_OUT'));
                 $this->setTemplatePage('message');
             } else {
                 //This honestly should never happen
                 $this->redirectTo('index', $defaultArgs);
             }
             break;
         case 'logout':
             $authorityIndex = $this->getArg('authority');
             //hard logouts attempt to logout of the indirect service provider (must be implemented by the authority)
             $hard = $this->getArg('hard', false);
             if (!$this->isLoggedIn($authorityIndex)) {
                 //not logged in
                 $this->redirectTo('index', $defaultArgs);
             } elseif ($authority = AuthenticationAuthority::getAuthenticationAuthority($authorityIndex)) {
                 $user = $this->getUser($authority);
                 //log them out
                 $result = $session->logout($authority, $hard);
             } else {
                 //This honestly should never happen
                 $this->redirectTo('index', $defaultArgs);
             }
             if ($result) {
                 $this->setLogData($user, $user->getFullName());
                 $this->logView();
                 //if they are still logged in return to the login page, otherwise go home.
                 if ($this->isLoggedIn()) {
                     $this->redirectTo('index', array_merge(array('logout' => $authorityIndex), $defaultArgs));
                 } else {
                     $this->redirectToModule($this->getHomeModuleID(), '', array('logout' => $authorityIndex));
                 }
             } else {
                 //there was an error logging out
                 $this->setTemplatePage('message');
                 $this->assign('message', $this->getLocalizedString("ERROR_SIGN_OUT"));
             }
             break;
         case 'forgotpassword':
             //redirect to forgot password url
             if ($forgetPasswordURL = $this->getOptionalModuleVar('FORGET_PASSWORD_URL')) {
                 Kurogo::redirectToURL($forgetPasswordURL);
             } else {
                 $this->redirectTo('index', $defaultArgs);
             }
             break;
         case 'login':
             //get arguments
             $login = $this->argVal($_POST, 'loginUser', '');
             $password = $this->argVal($_POST, 'loginPassword', '');
             $options = array_merge($urlArray, array('remainLoggedIn' => $remainLoggedIn), $defaultArgs);
             $session = $this->getSession();
             $session->setRemainLoggedIn($remainLoggedIn);
             $authorityIndex = $this->getArg('authority', '');
             if (!($authorityData = AuthenticationAuthority::getAuthenticationAuthorityData($authorityIndex))) {
                 //invalid authority
                 $this->redirectTo('index', $options);
             }
             if ($this->isLoggedIn($authorityIndex)) {
                 //we're already logged in
                 $this->redirectTo('index', $options);
             }
             $this->assign('authority', $authorityIndex);
             $this->assign('remainLoggedIn', $remainLoggedIn);
             $this->assign('authorityTitle', $authorityData['TITLE']);
             //if they haven't submitted the form and it's a direct login show the form
             if ($authorityData['USER_LOGIN'] == 'FORM' && empty($login)) {
                 if (!($loginMessage = $this->getOptionalModuleVar('LOGIN_DIRECT_MESSAGE'))) {
                     $loginMessage = $this->getLocalizedString('LOGIN_DIRECT_MESSAGE', Kurogo::getSiteString('SITE_NAME'));
                 }
                 $this->assign('LOGIN_DIRECT_MESSAGE', $loginMessage);
                 $this->assign('urlArray', array_merge($urlArray, $defaultArgs));
                 break;
             } elseif ($authority = AuthenticationAuthority::getAuthenticationAuthority($authorityIndex)) {
                 //indirect logins handling the login process themselves. Send a return url so the indirect authority can come back here
                 if ($authorityData['USER_LOGIN'] == 'LINK') {
                     $options['return_url'] = FULL_URL_BASE . $this->configModule . '/login?' . http_build_query(array_merge($options, array('authority' => $authorityIndex)));
                 }
                 $options['startOver'] = $this->getArg('startOver', 0);
                 $result = $authority->login($login, $password, $session, $options);
             } else {
                 $this->redirectTo('index', $options);
             }
             switch ($result) {
                 case AUTH_OK:
                     $user = $this->getUser($authority);
                     $this->setLogData($user, $user->getFullName());
                     $this->logView();
                     if ($urlArray) {
                         self::redirectToArray(array_merge($urlArray, $defaultArgs));
                     } else {
                         $this->redirectToModule($this->getHomeModuleID(), '', array('login' => $authorityIndex));
                     }
                     break;
                 case AUTH_OAUTH_VERIFY:
                     // authorities that require a manual oauth verification key
                     $this->assign('verifierKey', $authority->getVerifierKey());
                     $this->setTemplatePage('oauth_verify.tpl');
                     break 2;
                 default:
                     //there was a problem.
                     if ($authorityData['USER_LOGIN'] == 'FORM') {
                         $this->assign('message', $this->getLocalizedString('ERROR_LOGIN_DIRECT'));
                         break 2;
                     } else {
                         $this->redirectTo('index', array_merge(array('messagekey' => 'ERROR_LOGIN_INDIRECT'), $options, $defaultArgs));
                     }
             }
         case 'index':
             //sometimes messages are passed. This probably has some
             if ($messagekey = $this->getArg('messagekey')) {
                 $this->assign('messagekey', $this->getLocalizedString($messagekey));
                 try {
                     $message = $this->getLocalizedString($messagekey);
                     $this->assign('message', $message);
                 } catch (KurogoException $e) {
                 }
             }
             if ($this->isLoggedIn()) {
                 //if the url is set then redirect
                 if ($urlArray) {
                     self::redirectToArray(array_merge($urlArray, $defaultArgs));
                 }
                 //if there is only 1 authority then redirect to logout confirm
                 if (!$multipleAuthorities) {
                     $user = $this->getUser();
                     $this->redirectTo('logoutConfirm', array_merge(array('authority' => $user->getAuthenticationAuthorityIndex()), $defaultArgs));
                 }
                 //more than 1 authority. There could be 1 or more actual logged in users
                 $sessionUsers = $session->getUsers();
                 $users = array();
                 //cycle through the logged in users to build a list
                 foreach ($sessionUsers as $authorityIndex => $user) {
                     $authority = $user->getAuthenticationAuthority();
                     $users[] = array('class' => $authority->getAuthorityClass(), 'title' => count($sessionUsers) > 1 ? $this->getLocalizedString("SIGN_OUT_AUTHORITY", array($authority->getAuthorityTitle(), $user->getFullName())) : $this->getLocalizedString('SIGN_OUT'), 'subtitle' => count($sessionUsers) > 1 ? $this->getLocalizedString('SIGN_OUT') : '', 'url' => $this->buildBreadcrumbURL('logout', array('authority' => $authorityIndex), false));
                     //remove the authority from the list of available authorities (since they are logged in)
                     if (isset($authenticationAuthorities['direct'][$authorityIndex])) {
                         unset($authenticationAuthorities['direct'][$authorityIndex]);
                     }
                     if (isset($authenticationAuthorities['indirect'][$authorityIndex])) {
                         unset($authenticationAuthorities['indirect'][$authorityIndex]);
                     }
                 }
                 $this->assign('users', $users);
                 // navlist of users
                 $this->assign('authenticationAuthorities', $authenticationAuthorities);
                 //list of authorities not logged in
                 $this->assign('moreAuthorities', count($authenticationAuthorities['direct']) + count($authenticationAuthorities['indirect']));
                 //see if there are any left
                 if (count($sessionUsers) == 1) {
                     //there's only on logged in user
                     $user = current($sessionUsers);
                     $authority = $user->getAuthenticationAuthority();
                     $this->assign('LOGIN_SIGNED_IN_MESSAGE', $this->getLocalizedString('LOGIN_SIGNED_IN_SINGLE', Kurogo::getSiteString('SITE_NAME'), $authority->getAuthorityTitle(), $user->getFullName()));
                 } else {
                     //there are multiple logged in users
                     $this->assign('LOGIN_SIGNED_IN_MESSAGE', $this->getLocalizedString('LOGIN_SIGNED_IN_MULTIPLE', array(Kurogo::getSiteString('SITE_NAME'))));
                 }
                 //use loggedin.tpl
                 $this->setTemplatePage('loggedin');
             } else {
                 // not logged in
                 // if there is only 1 direct authority then redirect to the login page for that authority
                 if (!$multipleAuthorities && count($authenticationAuthorities['direct'])) {
                     $this->redirectTo('login', array_merge($urlArray, array('authority' => key($authenticationAuthorities['direct'])), $defaultArgs));
                 }
                 // if there is only 1 auto authority then redirect to the login page for that authority
                 if (!$multipleAuthorities && count($authenticationAuthorities['auto']) && !$messagekey) {
                     $this->redirectTo('login', array_merge($urlArray, array('authority' => key($authenticationAuthorities['auto'])), $defaultArgs));
                 }
                 // do we have any indirect authorities?
                 if (count($authenticationAuthorities['indirect'])) {
                     if (!($indirectMessage = $this->getOptionalModuleVar('LOGIN_INDIRECT_MESSAGE'))) {
                         $indirectMessage = $this->getLocalizedString('LOGIN_INDIRECT_MESSAGE', Kurogo::getSiteString('SITE_NAME'));
                     }
                     $this->assign('LOGIN_INDIRECT_MESSAGE', $indirectMessage);
                 }
                 // the site can create their own message at the top, or it will use the default message
                 if (!($loginMessage = $this->getOptionalModuleVar('LOGIN_INDEX_MESSAGE'))) {
                     if ($multipleAuthorities) {
                         $loginMessage = $this->getLocalizedString('LOGIN_INDEX_MESSAGE_MULTIPLE', Kurogo::getSiteString('SITE_NAME'));
                     } else {
                         $loginMessage = $this->getLocalizedString('LOGIN_INDEX_MESSAGE_SINGLE', Kurogo::getSiteString('SITE_NAME'));
                     }
                 }
                 $this->assign('LOGIN_INDEX_MESSAGE', $loginMessage);
             }
             break;
     }
 }
Beispiel #5
0
 private function assignItemsFromFeed($feedId, $searchTerms = null, $isMapView = false)
 {
     $dataModel = $this->getDataModel($feedId);
     $title = $dataModel->getTitle();
     $categoryId = $this->getArg('category', null);
     if ($categoryId !== null) {
         $category = $dataModel->findCategory($categoryId);
         $title = $category->getTitle();
     }
     if ($searchTerms) {
         $listItems = $dataModel->search($searchTerms);
     } else {
         $listItems = $dataModel->items();
         while (count($listItems) == 1 && end($listItems) instanceof MapFolder) {
             $categoryId = end($listItems)->getId();
             $category = $dataModel->findCategory($categoryId);
             $title = $category->getTitle();
             $listItems = $dataModel->items();
         }
     }
     if ($title) {
         $this->setPageTitles($title);
     }
     $linkOptions = array('feed' => $feedId, 'group' => $this->feedGroup);
     if (count($listItems) == 1 && !$this->getArg('listview')) {
         $link = $this->linkForItem(current($listItems), $linkOptions);
         Kurogo::redirectToURL(rtrim(URL_BASE, '/') . $link['url']);
     }
     $this->selectedPlacemarks = array();
     $placemarkLoad = 0;
     $results = array();
     foreach ($listItems as $listItem) {
         if (!$isMapView) {
             $results[] = $this->linkForItem($listItem, $linkOptions);
         }
         if ($listItem instanceof Placemark) {
             $this->selectedPlacemarks[] = $listItem;
             $geometry = $listItem->getGeometry();
             if ($geometry instanceof MapPolygon) {
                 $placemarkLoad += 4;
             } elseif ($geometry instanceof MapPolyline) {
                 $placemarkLoad += 2;
             } else {
                 $placemarkLoad += 1;
             }
         }
     }
     if ($isMapView) {
         $this->setTemplatePage('fullscreen');
         $this->initializeDynamicMap();
     } else {
         if (isset($this->feedGroups[$this->feedGroup])) {
             $feedData = $this->getCurrentFeed($feedId);
             $showCampusTitle = isset($feedData['SHOW_CAMPUS_TITLE']) ? $feedData['SHOW_CAMPUS_TITLE'] : false;
             if ($showCampusTitle) {
                 $title = $this->feedGroups[$this->feedGroup]['title'] . " " . $title;
             }
         }
         $this->assign('title', $title);
         $this->assign('navItems', $results);
         if ($this->numGroups > 1) {
             $this->assignClearLink();
         }
         if ($this->isMapDrivenUI() && $placemarkLoad && $placemarkLoad <= $this->getOptionalModuleVar('placemarkLoad', 30)) {
             $mapArgs = array_merge($this->args, $linkOptions);
             if (isset($mapArgs['listview'])) {
                 unset($mapArgs['listview']);
             }
             $mapArgs['mapview'] = true;
             $this->mapURL = $this->buildBreadcrumbURL($this->page, $mapArgs, false);
         }
     }
 }
 protected function secureModule()
 {
     $secure_host = Kurogo::getOptionalSiteVar('SECURE_HOST', $_SERVER['SERVER_NAME']);
     if (empty($secure_host)) {
         $secure_host = $_SERVER['SERVER_NAME'];
     }
     $secure_port = Kurogo::getOptionalSiteVar('SECURE_PORT', 443);
     if (empty($secure_port)) {
         $secure_port = 443;
     }
     $redirect = sprintf("https://%s%s%s", $secure_host, $secure_port == 443 ? '' : ":{$secure_port}", $_SERVER['REQUEST_URI']);
     Kurogo::log(LOG_DEBUG, "Redirecting to secure url {$redirect}", 'module');
     Kurogo::redirectToURL($redirect, Kurogo::REDIRECT_PERMANENT);
 }
 public function login($login, $pass, Session $session, $options)
 {
     //if the code is present, then this is the callback that the user authorized the application
     if (isset($_GET['code'])) {
         // if a redirect_uri isn't set than we can't get an access token
         if (!isset($_SESSION['redirect_uri'])) {
             return AUTH_FAILED;
         }
         $this->redirect_uri = $_SESSION['redirect_uri'];
         unset($_SESSION['redirect_uri']);
         //get access token
         $url = "https://graph.facebook.com/oauth/access_token?" . http_build_query(array('client_id' => $this->api_key, 'redirect_uri' => $this->redirect_uri, 'client_secret' => $this->api_secret, 'code' => $_GET['code']));
         if ($result = @file_get_contents($url)) {
             parse_str($result, $vars);
             foreach ($vars as $arg => $value) {
                 switch ($arg) {
                     case 'access_token':
                     case 'expires':
                         $this->{$arg} = $_SESSION['fb_' . $arg] = $value;
                         break;
                 }
             }
             // get the current user via API
             if ($user = $this->getUser('me')) {
                 $session->login($user);
                 return AUTH_OK;
             } else {
                 return AUTH_FAILED;
                 // something is amiss
             }
         } else {
             return AUTH_FAILED;
             //something is amiss
         }
     } elseif (isset($_GET['error'])) {
         //most likely the user denied
         return AUTH_FAILED;
     } else {
         //find out which "display" to use based on the device
         $deviceClassifier = Kurogo::deviceClassifier();
         $display = 'page';
         switch ($deviceClassifier->getPagetype()) {
             case 'compliant':
                 $display = $deviceClassifier->isComputer() ? 'page' : 'touch';
                 break;
             case 'basic':
                 $display = 'wap';
                 break;
         }
         // facebook does not like empty options
         foreach ($options as $option => $value) {
             if (strlen($value) == 0) {
                 unset($options[$option]);
             }
         }
         //save the redirect_uri so we can use it later
         $this->redirect_uri = $_SESSION['redirect_uri'] = FULL_URL_BASE . 'login/login?' . http_build_query(array_merge($options, array('authority' => $this->getAuthorityIndex())));
         //show the authorization/login screen
         $url = "https://graph.facebook.com/oauth/authorize?" . http_build_query(array('client_id' => $this->api_key, 'redirect_uri' => $this->redirect_uri, 'scope' => implode(',', $this->perms), 'display' => $display));
         Kurogo::redirectToURL($url);
     }
 }
Beispiel #8
0
 public function initialize(&$path = null)
 {
     includePackage('Cache');
     includePackage('Config');
     require LIB_DIR . '/compat.php';
     require LIB_DIR . '/exceptions.php';
     // add autoloader
     spl_autoload_register(array($this, "siteLibAutoloader"));
     //
     // Set up host define for server name and port
     //
     $host = self::arrayVal($_SERVER, 'SERVER_NAME', null);
     // SERVER_NAME never contains the port, while HTTP_HOST may (but we're not using HTTP_HOST for security reasons)
     if (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] !== '80') {
         $host .= ":{$_SERVER['SERVER_PORT']}";
     }
     // It's possible (under apache at least) for SERVER_NAME to contain a comma separated list.
     if (strpos($host, ',') !== false) {
         self::log(LOG_DEBUG, "Got multiple hostnames in SERVER_NAME: {$host}", 'kurogo');
         $host_explode = explode(',', $host);
         // Only sane choice is to use the first one.
         $host = $host_explode[0];
     }
     define('SERVER_HOST', $host);
     self::log(LOG_DEBUG, "Setting server host to {$host}", "kurogo");
     define('IS_SECURE', self::isRequestSecure());
     define('HTTP_PROTOCOL', IS_SECURE ? 'https' : 'http');
     $this->baseConfigStore = new ConfigFileStore();
     // Load main configuration file.
     $kurogoConfig = $this->loadKurogoConfig();
     // get CONFIG_MODE from environment if available.
     $configMode = Kurogo::arrayVal($_SERVER, 'CONFIG_MODE', null);
     if ($configMode = $kurogoConfig->getOptionalVar('CONFIG_MODE', $configMode, 'kurogo')) {
         $this->setConfigMode($configMode);
     }
     if ($cacheClass = $kurogoConfig->getOptionalVar('CACHE_CLASS', '', 'cache')) {
         $this->cacher = KurogoMemoryCache::factory($cacheClass, $kurogoConfig->getOptionalSection('cache'));
     }
     // get SITES_DIR from environment if available.
     $_sitesDir = Kurogo::arrayVal($_SERVER, 'SITES_DIR', ROOT_BASE_DIR . DIRECTORY_SEPARATOR . 'sites');
     $_sitesDir = $kurogoConfig->getOptionalVar('SITES_DIR', $_sitesDir, 'kurogo');
     if (!($sitesDir = realpath($_sitesDir))) {
         throw new KurogoConfigurationException("SITES_DIR {$_sitesDir} does not exist");
     }
     define('SITES_DIR', $sitesDir);
     define('SITES_KEY', md5(SITES_DIR));
     //
     // Initialize Site
     //
     $this->initSite($path);
     $this->setCharset($this->getOptionalSiteVar('DEFAULT_CHARSET', 'UTF-8'));
     ini_set('default_charset', $this->charset());
     ini_set('display_errors', $this->getSiteVar('DISPLAY_ERRORS'));
     if (!ini_get('error_log')) {
         ini_set('error_log', LOG_DIR . DIRECTORY_SEPARATOR . 'php_error.log');
     }
     define('KUROGO_IS_API', preg_match("#^" . API_URL_PREFIX . "/#", $path));
     //
     // Install exception handlers
     //
     if ($this->getSiteVar('PRODUCTION_ERROR_HANDLER_ENABLED')) {
         set_exception_handler("exceptionHandlerForProduction");
     } else {
         set_exception_handler("exceptionHandlerForDevelopment");
     }
     //get timezone from config and set
     $timezone = $this->getSiteVar('LOCAL_TIMEZONE');
     date_default_timezone_set($timezone);
     $this->timezone = new DateTimeZone($timezone);
     self::log(LOG_DEBUG, "Setting timezone to {$timezone}", "kurogo");
     if ($locale = $this->getOptionalSiteVar('LOCALE')) {
         $this->setLocale($locale);
     } else {
         $this->locale = $this->getSystemLocale();
     }
     if ($languages = $this->getOptionalSiteVar('LANGUAGES')) {
         $this->setLanguages($languages);
     } else {
         $this->setLanguages(array('en_US'));
     }
     //
     // everything after this point only applies to http requests
     //
     if (PHP_SAPI == 'cli') {
         define('FULL_URL_BASE', '');
         return;
     }
     define('FULL_URL_BASE', 'http' . (IS_SECURE ? 's' : '') . '://' . $this->_getHost() . URL_BASE);
     define('COOKIE_PATH', URL_BASE);
     // make sure host is all lower case
     if ($this->_getHost() != strtolower($this->_getHost())) {
         $url = 'http' . (IS_SECURE ? 's' : '') . '://' . strtolower($this->_getHost()) . $path;
         self::log(LOG_INFO, "Redirecting to lowercase url {$url}", 'kurogo');
         Kurogo::redirectToURL($url, Kurogo::REDIRECT_PERMANENT);
     }
     //
     // Initialize global device classifier
     //
     $device = null;
     $deviceCacheTimeout = self::getSiteVar('DEVICE_DETECTION_COOKIE_LIFESPAN', 'cookies');
     $urlPrefix = URL_BASE;
     $urlDeviceDebugPrefix = '/';
     $override = null;
     if (isset($_GET['resetdevice'])) {
         DeviceClassifier::clearDeviceCookie();
     }
     if (isset($_GET['setdevice'])) {
         $device = $_GET['setdevice'];
         $override = 1;
         $deviceCacheTimeout = 0;
     }
     // Check for device classification in url and strip it if present
     if ($this->getSiteVar('DEVICE_DEBUG')) {
         if (preg_match(';^device/([^/]+)/(.*)$;', $path, $matches)) {
             $device = $matches[1];
             // layout forced by url
             $path = $matches[2];
             $urlPrefix .= "device/{$device}/";
             $urlDeviceDebugPrefix .= "device/{$device}/";
             $deviceCacheTimeout = null;
         } elseif (isset($_GET['_device']) && preg_match(';^device/([^/]+)/$;', $_GET['_device'], $matches)) {
             $device = $matches[1];
             $urlPrefix .= "device/{$device}/";
             $urlDeviceDebugPrefix .= "device/{$device}/";
             $deviceCacheTimeout = null;
         }
     }
     define('URL_DEVICE_DEBUG_PREFIX', $urlDeviceDebugPrefix);
     define('URL_PREFIX', $urlPrefix);
     self::log(LOG_DEBUG, "Setting URL_PREFIX to " . URL_PREFIX, "kurogo");
     define('FULL_URL_PREFIX', 'http' . (IS_SECURE ? 's' : '') . '://' . $this->_getHost() . URL_PREFIX);
     $this->checkCurrentVersion();
     $this->deviceClassifier = new DeviceClassifier($device, $deviceCacheTimeout, $override);
     //preserved for compatibility
     $GLOBALS['deviceClassifier'] = $this->deviceClassifier;
     $this->initTheme();
 }
Beispiel #9
0
 protected function initializeForPage()
 {
     if (!$this->feed) {
         throw new KurogoConfigurationException($this->getLocalizedString('ERROR_NOT_CONFIGURED'));
     }
     switch ($this->page) {
         case 'story':
             $searchTerms = $this->getArg('filter', false);
             if ($searchTerms) {
                 $this->feed->setOption('search', $searchTerms);
             }
             $storyID = $this->getArg('storyID', false);
             $storyPage = $this->getArg('storyPage', '0');
             $story = $this->feed->getItem($storyID);
             if (!$story) {
                 throw new KurogoUserException($this->getLocalizedString('ERROR_STORY_NOT_FOUND', $storyID));
             }
             $this->setLogData($storyID, $story->getTitle());
             if (!($content = $this->cleanContent($story->getContent()))) {
                 if ($url = $story->getLink()) {
                     Kurogo::redirectToURL($url);
                 }
                 // no content or link. Attempt to get description
                 if (!($content = $story->getDescription())) {
                     throw new KurogoDataException($this->getLocalizedString('ERROR_CONTENT_NOT_FOUND', $storyID));
                 }
             }
             if ($this->getOptionalModuleVar('SHARING_ENABLED', 1)) {
                 $body = $story->getDescription() . "\n\n" . $story->getLink();
                 $shareEmailURL = $this->buildMailToLink("", $story->getTitle(), $body);
                 $this->assign('shareTitle', $this->getLocalizedString('SHARE_THIS_STORY'));
                 $this->assign('shareEmailURL', $shareEmailURL);
                 $this->assign('shareRemark', $story->getTitle());
                 $this->assign('storyURL', $story->getLink());
             }
             if ($pubDate = $story->getPubDate()) {
                 $date = DateFormatter::formatDate($pubDate, DateFormatter::LONG_STYLE, DateFormatter::NO_STYLE);
             } else {
                 $date = "";
             }
             $this->enablePager($content, $this->feed->getEncoding(), $storyPage);
             $this->assign('date', $date);
             $this->assign('title', $this->htmlEncodeFeedString($story->getTitle()));
             $this->assign('author', $this->htmlEncodeFeedString($story->getAuthor()));
             $this->assign('image', $this->getImageForStory($story));
             $this->assign('link', $story->getLink());
             $this->assign('ajax', $this->getArg('ajax'));
             $this->assign('showLink', $this->showLink);
             $this->assign('showBodyThumbnail', $this->showBodyThumbnail);
             break;
         case 'search':
             $searchTerms = $this->getArg('filter');
             $start = $this->getArg('start', 0);
             if ($searchTerms) {
                 $options = array('start' => $start);
                 $items = $this->searchItems($searchTerms, $this->maxPerPage, $options);
                 $this->setLogData($searchTerms);
                 $totalItems = $this->feed->getTotalItems();
                 $stories = array();
                 $options = array('filter' => $searchTerms, 'section' => $this->feedIndex);
                 foreach ($items as $story) {
                     $stories[] = $this->linkForItem($story, $options);
                 }
                 $previousURL = '';
                 $nextURL = '';
                 if ($totalItems > $this->maxPerPage) {
                     $args = $this->args;
                     if ($start > 0) {
                         $args['start'] = $start - $this->maxPerPage;
                         $previousURL = $this->buildBreadcrumbURL($this->page, $args, false);
                     }
                     if ($totalItems - $start > $this->maxPerPage) {
                         $args['start'] = $start + $this->maxPerPage;
                         $nextURL = $this->buildBreadcrumbURL($this->page, $args, false);
                     }
                 }
                 $extraArgs = array('section' => $this->feedIndex);
                 $this->addInternalJavascript('/common/javascript/lib/ellipsizer.js');
                 $this->addOnLoad('setupNewsListing();');
                 $this->assign('maxPerPage', $this->maxPerPage);
                 $this->assign('extraArgs', $extraArgs);
                 $this->assign('searchTerms', $searchTerms);
                 $this->assign('stories', $stories);
                 $this->assign('previousURL', $previousURL);
                 $this->assign('nextURL', $nextURL);
                 $this->assign('showImages', $this->showImages);
                 $this->assign('showPubDate', $this->showPubDate);
                 $this->assign('showAuthor', $this->showAuthor);
             } else {
                 $this->redirectTo('index');
                 // search was blank
             }
             break;
         case 'pane':
             if ($this->ajaxContentLoad) {
                 $start = 0;
                 if ($this->legacyController) {
                     $items = $this->feed->items($start, $this->maxPerPane);
                 } else {
                     $this->feed->setStart(0);
                     $this->feed->setLimit($this->maxPerPane);
                     $items = $this->feed->items();
                 }
                 $stories = array();
                 $options = array('noBreadcrumbs' => true, 'section' => $this->feedIndex);
                 foreach ($items as $story) {
                     $stories[] = $this->linkForItem($story, $options);
                 }
                 foreach ($stories as $i => $story) {
                     $stories[$i]['url'] = $this->buildURL('index') . '#' . urlencode(FULL_URL_PREFIX . ltrim($story['url'], '/'));
                 }
                 $this->assign('stories', $stories);
             }
             $this->addInternalJavascript('/common/javascript/lib/ellipsizer.js');
             $this->addInternalJavascript('/common/javascript/lib/paneStories.js');
             break;
         case 'index':
             $start = $this->getArg('start', 0);
             if ($this->legacyController) {
                 $items = $this->feed->items($start, $this->maxPerPage);
             } else {
                 $this->feed->setStart($start);
                 $this->feed->setLimit($this->maxPerPage);
                 $items = $this->feed->items();
             }
             $totalItems = $this->feed->getTotalItems();
             $this->setLogData($this->feedIndex, $this->feed->getTitle());
             $previousURL = null;
             $nextURL = null;
             if ($totalItems > $this->maxPerPage) {
                 $args = $this->args;
                 if ($start > 0) {
                     $args['start'] = $start - $this->maxPerPage;
                     $previousURL = $this->buildBreadcrumbURL($this->page, $args, false);
                 }
                 if ($totalItems - $start > $this->maxPerPage) {
                     $args['start'] = $start + $this->maxPerPage;
                     $nextURL = $this->buildBreadcrumbURL($this->page, $args, false);
                 }
             }
             $options = array('section' => $this->feedIndex);
             $stories = array();
             foreach ($items as $story) {
                 $stories[] = $this->linkForItem($story, $options);
             }
             $sections = array();
             foreach ($this->feeds as $index => $feedData) {
                 $sections[] = array('value' => $index, 'title' => $feedData['TITLE'], 'selected' => $this->feedIndex == $index, 'url' => $this->feedURL($index, false));
             }
             $hiddenArgs = array('section' => $this->feedIndex);
             $this->addInternalJavascript('/common/javascript/lib/ellipsizer.js');
             $this->addOnLoad('setupNewsListing();');
             $this->assign('maxPerPage', $this->maxPerPage);
             $this->assign('hiddenArgs', $hiddenArgs);
             $this->assign('sections', $sections);
             $this->assign('currentSection', $sections[$this->feedIndex]);
             $this->assign('placeholder', $this->getLocalizedString('SEARCH_MODULE', $this->getModuleName()));
             $this->assign('stories', $stories);
             $this->assign('isHome', true);
             $this->assign('previousURL', $previousURL);
             $this->assign('nextURL', $nextURL);
             $this->assign('showImages', $this->showImages);
             $this->assign('showPubDate', $this->showPubDate);
             $this->assign('showAuthor', $this->showAuthor);
             break;
     }
 }
Beispiel #10
0
 public function auth($options, &$userArray)
 {
     if (!Kurogo::getSiteVar('AUTHENTICATION_ENABLED')) {
         throw new KurogoConfigurationException($this->getLocalizedString("ERROR_AUTHENTICATION_DISABLED"));
     }
     $startOver = isset($options['startOver']) && $options['startOver'];
     if ($startOver) {
         $this->reset();
     }
     if (!$this->getToken(self::TOKEN_TYPE_REQUEST)) {
         if (!$this->getRequestToken($options)) {
             Kurogo::log(LOG_WARNING, "Error getting request token", 'auth');
             return AUTH_FAILED;
         }
     }
     if (isset($_REQUEST[$this->verifierKey])) {
         //get an access token
         $options[$this->verifierKey] = $_REQUEST[$this->verifierKey];
         if ($userArray = $this->getAccessToken($options)) {
             return AUTH_OK;
         } else {
             Kurogo::log(LOG_WARNING, "Error getting access token", 'auth');
             return AUTH_FAILED;
         }
     } elseif ($this->manualVerify && !$startOver) {
         return AUTH_OAUTH_VERIFY;
     } else {
         //redirect to auth page
         $url = $this->getAuthURL($options);
         Kurogo::log(LOG_DEBUG, "Redirecting to AuthURL {$url}", 'auth');
         Kurogo::redirectToURL($url);
     }
 }
Beispiel #11
0
 protected function redirectTo($command, $args = array())
 {
     $url = URL_BASE . API_URL_PREFIX . "/{$this->id}/{$command}";
     if (count($args)) {
         $url .= http_build_query($args);
     }
     //error_log('Redirecting to: '.$url);
     Kurogo::redirectToURL($url);
 }
Beispiel #12
0
            if (preg_match("#^http(s)?://#", $url_redirects[$id])) {
                $url = $url_redirects[$id];
            } else {
                $parts[0] = $url_redirects[$id];
                $url = URL_PREFIX . implode("/", $parts);
                if ($args) {
                    $url .= "?" . http_build_query($args);
                }
            }
            Kurogo::log(LOG_NOTICE, "Redirecting to {$url}", 'kurogo');
            Kurogo::redirectToURL($url, Kurogo::REDIRECT_PERMANENT);
        }
    }
    // find the page part
    if (isset($parts[1])) {
        if (strlen($parts[1])) {
            $page = basename($parts[1], '.php');
        }
    } else {
        // redirect with trailing slash for completeness
        Kurogo::redirectToURL("./{$id}/", Kurogo::REDIRECT_PERMANENT);
    }
    $Kurogo->setRequest($id, $page, $args);
    if ($module = WebModule::factory($id, $page, $args)) {
        $Kurogo->setCurrentModule($module);
        $module->displayPage();
    } else {
        throw new KurogoException("Module {$id} cannot be loaded");
    }
}
exit;
Beispiel #13
0
 private function initSite(&$path)
 {
     includePackage('Cache');
     includePackage('Config');
     $siteConfig = new ConfigGroup();
     $saveCache = true;
     // Load main configuration file
     $kurogoConfig = ConfigFile::factory('kurogo', 'project', ConfigFile::OPTION_IGNORE_MODE | ConfigFile::OPTION_IGNORE_LOCAL);
     $siteConfig->addConfig($kurogoConfig);
     define('CONFIG_MODE', $siteConfig->getVar('CONFIG_MODE', 'kurogo'));
     Kurogo::log(LOG_DEBUG, "Setting config mode to " . (CONFIG_MODE ? CONFIG_MODE : '<empty>'), 'config');
     define('CONFIG_IGNORE_LOCAL', $siteConfig->getVar('CONFIG_IGNORE_LOCAL', 'kurogo'));
     if ($cacheClass = $siteConfig->getOptionalVar('CACHE_CLASS', '', 'cache')) {
         $this->cacher = KurogoMemoryCache::factory($cacheClass, $siteConfig->getOptionalSection('cache'));
     }
     //multi site currently only works with a url base of root "/"
     if ($siteConfig->getOptionalVar('MULTI_SITE', false, 'kurogo')) {
         // in scripts you can pass the site name to Kurogo::initialize()
         if (PHP_SAPI == 'cli') {
             $site = strlen($path) > 0 ? $path : $siteConfig->getVar('DEFAULT_SITE');
             $siteDir = implode(DIRECTORY_SEPARATOR, array(ROOT_DIR, 'site', $site));
             if (!file_exists(realpath($siteDir))) {
                 die("FATAL ERROR: Site Directory {$siteDir} not found for site {$path}");
             }
         } else {
             $paths = explode("/", $path);
             // this is url
             $sites = array();
             $siteDir = '';
             if (count($paths) > 1) {
                 $site = $paths[1];
                 if ($sites = $siteConfig->getOptionalVar('ACTIVE_SITES', array(), 'kurogo')) {
                     //see if the site is in the list of available sites
                     if (in_array($site, $sites)) {
                         $testPath = implode(DIRECTORY_SEPARATOR, array(ROOT_DIR, 'site', $site));
                         if (($siteDir = realpath($testPath)) && file_exists($siteDir)) {
                             $urlBase = '/' . $site . '/';
                             // this is a url
                         }
                     }
                 } elseif (self::isValidSiteName($site)) {
                     $testPath = implode(DIRECTORY_SEPARATOR, array(ROOT_DIR, 'site', $site));
                     if (($siteDir = realpath($testPath)) && file_exists($siteDir)) {
                         $urlBase = '/' . $site . '/';
                         // this is a url
                     }
                 }
             }
             if (!$siteDir) {
                 $site = $siteConfig->getVar('DEFAULT_SITE');
                 array_splice($paths, 1, 1, array($site, $paths[1]));
                 $url = implode("/", $paths);
                 Kurogo::redirectToURL($url, Kurogo::REDIRECT_PERMANENT);
             }
         }
         define('SITE_NAME', $site);
     } else {
         //make sure active site is set
         if (!($site = $siteConfig->getVar('ACTIVE_SITE'))) {
             die("FATAL ERROR: ACTIVE_SITE not set");
         }
         // make sure site_dir is set and is a valid path
         // Do not call realpath_exists here because until SITE_DIR define is set
         // it will not allow files and directories outside ROOT_DIR
         if (!($siteDir = $siteConfig->getVar('SITE_DIR')) || !(($siteDir = realpath($siteDir)) && file_exists($siteDir))) {
             die("FATAL ERROR: Site Directory " . $siteConfig->getVar('SITE_DIR') . " not found for site " . $site);
         }
         define('SITE_NAME', $site);
         if (PHP_SAPI != 'cli') {
             //
             // Get URL base
             //
             if ($urlBase = $siteConfig->getOptionalVar('URL_BASE', '', 'kurogo')) {
                 $urlBase = rtrim($urlBase, '/') . '/';
             } elseif ($urlBase = Kurogo::getCache('URL_BASE')) {
                 //@TODO this won't work yet because the cache hasn't initialized
                 $urlBase = rtrim($urlBase, '/') . '/';
                 $saveCache = false;
             } else {
                 //extract the path parts from the url
                 $pathParts = array_values(array_filter(explode("/", $_SERVER['REQUEST_URI'])));
                 $testPath = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR;
                 $urlBase = '/';
                 //once the path equals the WEBROOT_DIR we've found the base. This only works with symlinks
                 if (realpath($testPath) != WEBROOT_DIR) {
                     foreach ($pathParts as $dir) {
                         $test = $testPath . $dir . DIRECTORY_SEPARATOR;
                         if (file_exists(realpath($test))) {
                             $testPath = $test;
                             $urlBase .= $dir . '/';
                             if (realpath($test) == WEBROOT_DIR) {
                                 break;
                             }
                         }
                     }
                 }
             }
         }
     }
     if (PHP_SAPI == 'cli') {
         define('URL_BASE', null);
     } else {
         if (!isset($urlBase)) {
             throw new KurogoConfigurationException("URL base not set. Please report the configuration to see why this happened");
         }
         define('URL_BASE', $urlBase);
         if ($saveCache) {
             Kurogo::setCache('URL_BASE', $urlBase);
         }
         Kurogo::log(LOG_DEBUG, "Setting site to {$site} with a base of {$urlBase}", 'kurogo');
         // Strips out the leading part of the url for sites where
         // the base is not located at the document root, ie.. /mobile or /m
         // Also strips off the leading slash (needed by device debug below)
         if (isset($path)) {
             // Strip the URL_BASE off the path
             $baseLen = strlen(URL_BASE);
             if ($baseLen && strpos($path, URL_BASE) === 0) {
                 $path = substr($path, $baseLen);
             }
         }
     }
     // Set up defines relative to SITE_DIR
     define('SITE_DIR', $siteDir);
     //already been realpath'd
     define('SITE_LIB_DIR', SITE_DIR . DIRECTORY_SEPARATOR . 'lib');
     define('SITE_APP_DIR', SITE_DIR . DIRECTORY_SEPARATOR . 'app');
     define('SITE_MODULES_DIR', SITE_DIR . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'modules');
     define('DATA_DIR', SITE_DIR . DIRECTORY_SEPARATOR . 'data');
     define('CACHE_DIR', SITE_DIR . DIRECTORY_SEPARATOR . 'cache');
     define('LOG_DIR', SITE_DIR . DIRECTORY_SEPARATOR . 'logs');
     define('SITE_CONFIG_DIR', SITE_DIR . DIRECTORY_SEPARATOR . 'config');
     define('SITE_DISABLED_DIR', SITE_DIR . DIRECTORY_SEPARATOR . 'config_disabled');
     //load in the site config file (required);
     $config = ConfigFile::factory('site', 'site');
     $siteConfig->addConfig($config);
     // attempt to load site key
     $siteKey = $siteConfig->getOptionalVar('SITE_KEY', md5($siteDir));
     define('SITE_KEY', $siteKey);
     if ($siteConfig->getOptionalVar('SITE_DISABLED')) {
         die("FATAL ERROR: Site disabled");
     }
     // Set up theme define
     if (!($theme = $siteConfig->getVar('ACTIVE_THEME'))) {
         die("FATAL ERROR: ACTIVE_THEME not set");
     }
     Kurogo::log(LOG_DEBUG, "Setting theme to {$theme}", 'kurogo');
     define('THEME_DIR', SITE_DIR . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $theme);
     $this->siteConfig = $siteConfig;
 }
Beispiel #14
0
 protected function initializeForPage()
 {
     switch ($this->page) {
         case 'news':
             $start = $this->getArg('start', 0);
             $section = $this->getArg('section');
             $newsFeed = $this->getNewsFeed($section);
             $newsFeed->setStart($start);
             $newsFeed->setLimit($this->maxPerPage);
             $items = $newsFeed->items();
             $totalItems = $newsFeed->getTotalItems();
             $this->setLogData($section, $newsFeed->getTitle());
             $previousURL = null;
             $nextURL = null;
             if ($totalItems > $this->maxPerPage) {
                 $args = $this->args;
                 if ($start > 0) {
                     $args['start'] = $start - $this->maxPerPage;
                     $previousURL = $this->buildBreadcrumbURL($this->page, $args, false);
                 }
                 if ($totalItems - $start > $this->maxPerPage) {
                     $args['start'] = $start + $this->maxPerPage;
                     $nextURL = $this->buildBreadcrumbURL($this->page, $args, false);
                 }
             }
             $options = array('section' => $section);
             $stories = array();
             foreach ($items as $story) {
                 $stories[] = $this->linkForNewsItem($story, $options);
             }
             $this->addInternalJavascript('/common/javascript/lib/ellipsizer.js');
             $this->addOnLoad('setupNewsListing();');
             $this->assign('maxPerPage', $this->maxPerPage);
             $this->assign('stories', $stories);
             $this->assign('previousURL', $previousURL);
             $this->assign('nextURL', $nextURL);
             $this->assign('showImages', $this->showImages);
             $this->assign('showPubDate', $this->showPubDate);
             $this->assign('showAuthor', $this->showAuthor);
             break;
         case 'news_detail':
             $section = $this->getArg('section');
             $gender = $this->getArg('gender');
             $storyID = $this->getArg('storyID', false);
             $storyPage = $this->getArg('storyPage', '0');
             $feed = $this->getNewsFeed($section, $gender);
             if (!($story = $feed->getItem($storyID))) {
                 throw new KurogoUserException($this->getLocalizedString('ERROR_STORY_NOT_FOUND', $storyID));
             }
             $this->setLogData($storyID, $story->getTitle());
             if (!($content = $this->cleanContent($story->getContent()))) {
                 if ($url = $story->getLink()) {
                     Kurogo::redirectToURL($url);
                 } else {
                     throw new KurogoDataException($this->getLocalizedString('ERROR_CONTENT_NOT_FOUND', $storyID));
                 }
             }
             if ($this->getOptionalModuleVar('SHARING_ENABLED', 1)) {
                 $body = $story->getDescription() . "\n\n" . $story->getLink();
                 $shareEmailURL = $this->buildMailToLink("", $story->getTitle(), $body);
                 $this->assign('shareTitle', $this->getLocalizedString('SHARE_THIS_STORY'));
                 $this->assign('shareEmailURL', $shareEmailURL);
                 $this->assign('shareRemark', $story->getTitle());
                 $this->assign('storyURL', $story->getLink());
             }
             if ($pubDate = $story->getPubDate()) {
                 $date = DateFormatter::formatDate($pubDate, DateFormatter::MEDIUM_STYLE, DateFormatter::NO_STYLE);
             } else {
                 $date = "";
             }
             $this->enablePager($content, $this->newsFeed->getEncoding(), $storyPage);
             $this->assign('date', $date);
             $this->assign('title', $this->htmlEncodeFeedString($story->getTitle()));
             $this->assign('author', $this->htmlEncodeFeedString($story->getAuthor()));
             $this->assign('image', $this->getImageForStory($story));
             $this->assign('link', $story->getLink());
             $this->assign('showLink', $this->showLink);
             break;
         case 'search':
             $searchTerms = $this->getArg('filter');
             $start = $this->getArg('start', 0);
             $section = $this->getArg('section');
             if ($searchTerms) {
                 $newsFeed = $this->getNewsFeed($section);
                 $newsFeed->setStart($start);
                 $newsFeed->setLimit($this->maxPerPage);
                 $items = $newsFeed->search($searchTerms);
                 $this->setLogData($searchTerms);
                 $totalItems = $newsFeed->getTotalItems();
                 $stories = array();
                 $options = array('start' => $start, 'filter' => $searchTerms, 'section' => $section);
                 foreach ($items as $story) {
                     $stories[] = $this->linkForNewsItem($story, $options);
                 }
                 $previousURL = '';
                 $nextURL = '';
                 if ($totalItems > $this->maxPerPage) {
                     $args = $this->args;
                     if ($start > 0) {
                         $args['start'] = $start - $this->maxPerPage;
                         $previousURL = $this->buildBreadcrumbURL($this->page, $args, false);
                     }
                     if ($totalItems - $start > $this->maxPerPage) {
                         $args['start'] = $start + $this->maxPerPage;
                         $nextURL = $this->buildBreadcrumbURL($this->page, $args, false);
                     }
                 }
                 $extraArgs = array('section' => $section);
                 $this->addInternalJavascript('/common/javascript/lib/ellipsizer.js');
                 $this->addOnLoad('setupNewsListing();');
                 $this->assign('maxPerPage', $this->maxPerPage);
                 $this->assign('extraArgs', $extraArgs);
                 $this->assign('searchTerms', $searchTerms);
                 $this->assign('stories', $stories);
                 $this->assign('previousURL', $previousURL);
                 $this->assign('nextURL', $nextURL);
                 $this->assign('showImages', $this->showImages);
                 $this->assign('showPubDate', $this->showPubDate);
                 $this->assign('showAuthor', $this->showAuthor);
             } else {
                 $this->redirectTo('index');
                 // search was blank
             }
             break;
         case 'schedule':
             $sport = $this->getArg('sport', '');
             $sportData = $this->getSportData($sport);
             if ($scheduleFeed = $this->getScheduleFeed($sport)) {
                 $scheduleItems = array();
                 $options = array('sport' => $sport);
                 if ($events = $scheduleFeed->items()) {
                     foreach ($events as $event) {
                         $scheduleItems[] = $this->linkForScheduleItem($event, $options);
                     }
                 }
                 $this->assign('scheduleItems', $scheduleItems);
             }
             break;
         case 'schedule_detail':
             $sport = $this->getArg('sport', '');
             $id = $this->getArg('id', '');
             $sportData = $this->getSportData($sport);
             $scheduleFeed = $this->getScheduleFeed($sport);
             if ($schedule = $scheduleFeed->getItem($id)) {
                 $this->assign('schedule', $schedule);
             } else {
                 throw new KurogoDataException($this->getLocalizedString('ERROR_EVENT_NOT_FOUND'));
             }
             $this->setLogData($sport . ':' . $schedule->getID(), $schedule->getSport());
             $fields = $this->formatScheduleDetail($schedule);
             $schedule = $this->getFieldsForSechedule($schedule);
             $this->assign('schedule', $schedule);
             $this->assign('fields', $fields);
             break;
         case 'sport':
             $sport = $this->getArg('sport', '');
             $previous = array();
             $next = array();
             $sportData = $this->getSportData($sport);
             $this->assign('sportTitle', $sportData['GENDER_TITLE']);
             $this->setPageTitles($sportData['GENDER_TITLE']);
             if ($scheduleFeed = $this->getScheduleFeed($sport)) {
                 $scheduleItems = array();
                 if ($previousEvent = $scheduleFeed->getPreviousEvent()) {
                     $previous = $this->linkForScheduleItem($previousEvent, array('sport' => $sport));
                     $scheduleItems[] = $previous;
                 }
                 if ($nextEvent = $scheduleFeed->getNextEvent()) {
                     $next = $this->linkForScheduleItem($nextEvent, array('sport' => $sport));
                     $this->assign('next', $next);
                     $scheduleItems[] = $next;
                 }
                 $scheduleItems[] = array('title' => $this->getLocalizedString('FULL_SCHEDULE_TEXT'), 'url' => $this->buildBreadcrumbURL('schedule', array('sport' => $sport), true));
                 $this->assign('scheduleItems', $scheduleItems);
             }
             if ($newsFeed = $this->getNewsFeed($sport)) {
                 $start = $this->getArg('start', 0);
                 $newsFeed->setStart($start);
                 $newsFeed->setLimit($this->maxPerPage);
                 $items = $newsFeed->items();
                 $totalItems = $newsFeed->getTotalItems();
                 $this->setLogData($sport, $newsFeed->getTitle());
                 $previousURL = null;
                 $nextURL = null;
                 if ($totalItems > $this->maxPerPage) {
                     $args = $this->args;
                     if ($start > 0) {
                         $args['start'] = $start - $this->maxPerPage;
                         $previousURL = $this->buildBreadcrumbURL($this->page, $args, false);
                     }
                     if ($totalItems - $start > $this->maxPerPage) {
                         $args['start'] = $start + $this->maxPerPage;
                         $nextURL = $this->buildBreadcrumbURL($this->page, $args, false);
                     }
                 }
                 $options = array('section' => $sport);
                 $newsItems = array();
                 foreach ($items as $story) {
                     $newsItems[] = $this->linkForNewsItem($story, $options);
                 }
                 $this->addInternalJavascript('/common/javascript/lib/ellipsizer.js');
                 $this->addOnLoad('setupNewsListing();');
                 $this->assign('newsItems', $newsItems);
                 $this->assign('maxPerPage', $this->maxPerPage);
                 $this->assign('previousURL', $previousURL);
                 $this->assign('nextURL', $nextURL);
                 $this->assign('showImages', $this->showImages);
                 $this->assign('showPubDate', $this->showPubDate);
                 $this->assign('showAuthor', $this->showAuthor);
             }
             // Bookmark
             if ($this->getOptionalModuleVar('BOOKMARKS_ENABLED', 1)) {
                 $cookieParams = array('sport' => $sport);
                 $cookieID = http_build_query($cookieParams);
                 $this->generateBookmarkOptions($cookieID);
             }
             break;
         case "index":
             $tabs = array();
             //get top news
             if ($newsFeedData = $this->getNavData('topnews')) {
                 $start = $this->getArg('start', 0);
                 $newsFeed = $this->getNewsFeed('topnews');
                 $newsFeed->setStart($start);
                 $newsFeed->setLimit($this->maxPerPage);
                 $items = $newsFeed->items();
                 $totalItems = $newsFeed->getTotalItems();
                 $this->setLogData('topnews', $newsFeed->getTitle());
                 $previousURL = null;
                 $nextURL = null;
                 if ($totalItems > $this->maxPerPage) {
                     //$args = $this->args;
                     $args = array();
                     if ($start > 0) {
                         $args['start'] = $start - $this->maxPerPage;
                         $previousURL = $this->buildURL('index', $args);
                     }
                     if ($totalItems - $start > $this->maxPerPage) {
                         $args['start'] = $start + $this->maxPerPage;
                         $nextURL = $this->buildURL('index', $args);
                     }
                 }
                 $topNews = array();
                 $options = array('section' => 'topnews');
                 foreach ($items as $story) {
                     $topNews[] = $this->linkForNewsItem($story, $options);
                 }
                 $extraArgs = array('section' => 'topnews');
                 $this->addInternalJavascript('/common/javascript/lib/ellipsizer.js');
                 $this->addOnLoad('setupNewsListing();');
                 $tabs[] = 'topnews';
                 $this->assign('topNewsTitle', $newsFeedData['TITLE']);
                 $this->assign('topNews', $topNews);
                 $this->assign('extraArgs', $extraArgs);
                 $this->assign('maxPerPage', $this->maxPerPage);
                 $this->assign('previousURL', $previousURL);
                 $this->assign('nextURL', $nextURL);
                 $this->assign('showImages', $this->showImages);
                 $this->assign('showPubDate', $this->showPubDate);
                 $this->assign('showAuthor', $this->showAuthor);
             }
             //get sports for each gender
             foreach (array('men', 'women', 'coed') as $gender) {
                 $sportsData = $this->getNavData($gender);
                 if ($sportsData) {
                     if ($sportsConfig = $this->getSportsForGender($gender)) {
                         $sports = array();
                         foreach ($sportsConfig as $key => $sportData) {
                             $image = "modules/{$this->configModule}/images/" . (isset($sportData['ICON']) ? $sportData['ICON'] : strtolower($sportData['TITLE'])) . $this->imageExt;
                             $sport = array('title' => $sportData['TITLE'], 'img' => $image, 'url' => $this->buildURL('sport', array('sport' => $key)));
                             $sports[] = $sport;
                         }
                         $tabs[] = $gender;
                         $this->assign($gender . 'SportsTitle', $sportsData['TITLE']);
                         $this->assign($gender . 'Sports', $sports);
                     }
                 }
             }
             $bookmarkData = $this->getNavData('bookmarks');
             //get bookmarks
             $bookmarks = array();
             if ($this->getOptionalModuleVar('BOOKMARKS_ENABLED', 1)) {
                 $bookmarksData = $this->getBookmarks();
                 foreach ($bookmarksData as $bookmark) {
                     parse_str(stripslashes($bookmark), $params);
                     if (isset($params['sport']) && ($sportData = $this->getSportData($params['sport']))) {
                         $bookmarks[] = array('title' => $sportData['GENDER_TITLE'], 'url' => $this->buildURL('sport', array('sport' => $params['sport'])));
                     }
                 }
                 $tabs[] = 'bookmarks';
             }
             $this->assign('placeholder', $this->getLocalizedString('SEARCH_TEXT'));
             $this->assign('bookmarksTitle', $bookmarkData['TITLE']);
             $this->assign('bookmarks', $bookmarks);
             $this->assign('tabs', $tabs);
             $this->enableTabs($tabs);
             break;
         case 'pane':
             if ($this->ajaxContentLoad) {
                 $section = 'topnews';
                 $newsFeed = $this->getNewsFeed($section);
                 $newsFeed->setStart(0);
                 $newsFeed->setLimit($this->maxPerPage);
                 $items = $newsFeed->items();
                 $this->setLogData($section, $newsFeed->getTitle());
                 $stories = array();
                 foreach ($items as $item) {
                     $stories[] = $this->linkForNewsItem($item, array('section' => $section));
                 }
                 $this->assign('stories', $stories);
             }
             $this->addInternalJavascript('/common/javascript/lib/ellipsizer.js');
             $this->addInternalJavascript('/common/javascript/lib/paneStories.js');
             break;
     }
 }
 protected function initializeForPage()
 {
     switch ($this->page) {
         case 'news':
             $start = $this->getArg('start', 0);
             $section = $this->getArg('section');
             $newsFeed = $this->getNewsFeed($section);
             $newsFeed->setStart($start);
             $newsFeed->setLimit($this->maxPerPage);
             $items = $newsFeed->items();
             $totalItems = $newsFeed->getTotalItems();
             $this->setLogData($section, $newsFeed->getTitle());
             $previousURL = null;
             $nextURL = null;
             if ($totalItems > $this->maxPerPage) {
                 $args = $this->args;
                 if ($start > 0) {
                     $args['start'] = $start - $this->maxPerPage;
                     $previousURL = $this->buildBreadcrumbURL($this->page, $args, false);
                 }
                 if ($totalItems - $start > $this->maxPerPage) {
                     $args['start'] = $start + $this->maxPerPage;
                     $nextURL = $this->buildBreadcrumbURL($this->page, $args, false);
                 }
             }
             $options = array('section' => $section);
             $stories = array();
             foreach ($items as $story) {
                 $stories[] = $this->linkForNewsItem($story, $options);
             }
             $this->addInternalJavascript('/common/javascript/lib/ellipsizer.js');
             $this->addOnLoad('setupNewsListing();');
             $this->assign('maxPerPage', $this->maxPerPage);
             $this->assign('stories', $stories);
             $this->assign('previousURL', $previousURL);
             $this->assign('nextURL', $nextURL);
             $this->assign('showImages', $this->showImages);
             $this->assign('showPubDate', $this->showPubDate);
             $this->assign('showAuthor', $this->showAuthor);
             break;
         case 'news_detail':
             $section = $this->getArg('section');
             $gender = $this->getArg('gender');
             $storyID = $this->getArg('storyID', false);
             $storyPage = $this->getArg('storyPage', '0');
             $feed = $this->getNewsFeed($section, $gender);
             $showBodyThumbnail = $this->getOptionalModuleVar('SHOW_BODY_THUMBNAIL', $this->showBodyThumbnail, $section, 'feeds');
             if (!($story = $feed->getItem($storyID))) {
                 throw new KurogoUserException($this->getLocalizedString('ERROR_STORY_NOT_FOUND', $storyID));
             }
             $this->setLogData($storyID, $story->getTitle());
             if (!($content = $this->cleanContent($story->getContent()))) {
                 if ($url = $story->getLink()) {
                     Kurogo::redirectToURL($url);
                 } else {
                     throw new KurogoDataException($this->getLocalizedString('ERROR_CONTENT_NOT_FOUND', $storyID));
                 }
             }
             if ($this->getOptionalModuleVar('SHARING_ENABLED', 1)) {
                 $body = Sanitizer::sanitizeAndTruncateHTML($story->getDescription(), $truncated, $this->getOptionalModuleVar('SHARE_EMAIL_DESC_MAX_LENGTH', 500), $this->getOptionalModuleVar('SHARE_EMAIL_DESC_MAX_LENGTH_MARGIN', 50), $this->getOptionalModuleVar('SHARE_EMAIL_DESC_MIN_LINE_LENGTH', 50), '') . "\n\n" . $story->getLink();
                 $shareEmailURL = $this->buildMailToLink("", $story->getTitle(), $body);
                 $this->assign('shareTitle', $this->getLocalizedString('SHARE_THIS_STORY'));
                 $this->assign('shareEmailURL', $shareEmailURL);
                 $this->assign('shareRemark', $story->getTitle());
                 $this->assign('storyURL', $story->getLink());
             }
             if ($pubDate = $story->getPubDate()) {
                 $date = DateFormatter::formatDate($pubDate, DateFormatter::MEDIUM_STYLE, DateFormatter::NO_STYLE);
             } else {
                 $date = "";
             }
             $this->enablePager($content, $this->newsFeed->getEncoding(), $storyPage);
             $this->assign('date', $date);
             $this->assign('title', $this->htmlEncodeFeedString($story->getTitle()));
             $this->assign('author', $this->htmlEncodeFeedString($story->getAuthor()));
             $this->assign('image', $this->getImageForStory($story));
             $this->assign('thumbnail', $this->getThumbnailForStory($story));
             $this->assign('showBodyThumbnail', $showBodyThumbnail);
             $this->assign('link', $story->getLink());
             $this->assign('showLink', $this->showLink);
             break;
         case 'search':
             $searchTerms = $this->getArg('filter');
             $start = $this->getArg('start', 0);
             $section = $this->getArg('section', 'topnews');
             if ($searchTerms) {
                 $newsFeed = $this->getNewsFeed($section);
                 $newsFeed->setStart($start);
                 $newsFeed->setLimit($this->maxPerPage);
                 $items = $newsFeed->search($searchTerms);
                 $this->setLogData($searchTerms);
                 $totalItems = $newsFeed->getTotalItems();
                 $stories = array();
                 $options = array('start' => $start, 'filter' => $searchTerms, 'section' => $section);
                 foreach ($items as $story) {
                     $stories[] = $this->linkForNewsItem($story, $options);
                 }
                 $previousURL = '';
                 $nextURL = '';
                 if ($totalItems > $this->maxPerPage) {
                     $args = $this->args;
                     if ($start > 0) {
                         $args['start'] = $start - $this->maxPerPage;
                         $previousURL = $this->buildBreadcrumbURL($this->page, $args, false);
                     }
                     if ($totalItems - $start > $this->maxPerPage) {
                         $args['start'] = $start + $this->maxPerPage;
                         $nextURL = $this->buildBreadcrumbURL($this->page, $args, false);
                     }
                 }
                 $extraArgs = array('section' => $section);
                 $this->addInternalJavascript('/common/javascript/lib/ellipsizer.js');
                 $this->addOnLoad('setupNewsListing();');
                 $this->assign('maxPerPage', $this->maxPerPage);
                 $this->assign('extraArgs', $extraArgs);
                 $this->assign('searchTerms', $searchTerms);
                 $this->assign('stories', $stories);
                 $this->assign('previousURL', $previousURL);
                 $this->assign('nextURL', $nextURL);
                 $this->assign('showImages', $this->showImages);
                 $this->assign('showPubDate', $this->showPubDate);
                 $this->assign('showAuthor', $this->showAuthor);
             } else {
                 $this->redirectTo('index');
                 // search was blank
             }
             break;
         case 'schedule':
             $sport = $this->getArg('sport', '');
             $sportData = $this->getSportData($sport);
             if ($scheduleFeed = $this->getScheduleFeed($sport)) {
                 $scheduleItems = array();
                 $options = array('sport' => $sport);
                 if ($events = $scheduleFeed->items()) {
                     foreach ($events as $event) {
                         $scheduleItems[] = $this->linkForScheduleItem($event, $options);
                     }
                 }
                 $this->assign('scheduleItems', $scheduleItems);
             }
             break;
         case 'schedule_detail':
             $sport = $this->getArg('sport', '');
             if ($sport == '') {
                 $sport = 'allschedule';
             }
             $id = $this->getArg('id', '');
             // $sportData = $this->getSportData($sport);
             $scheduleFeed = $this->getScheduleFeed($sport);
             if ($schedule = $scheduleFeed->getItem($id)) {
                 $this->assign('schedule', $schedule);
             } else {
                 throw new KurogoDataException($this->getLocalizedString('ERROR_EVENT_NOT_FOUND'));
             }
             $this->setLogData($sport . ':' . $schedule->getID(), $schedule->getSport());
             $fields = $this->formatScheduleDetail($schedule);
             $schedule = $this->getFieldsForSchedule($schedule);
             $this->assign('schedule', $schedule);
             $this->assign('fields', $fields);
             break;
         case 'sport':
             $sport = $this->getArg('sport', '');
             $previous = array();
             $next = array();
             $sportData = $this->getSportData($sport);
             $this->assign('sportTitle', $sportData['GENDER_TITLE']);
             $this->setPageTitles($sportData['GENDER_TITLE']);
             if ($scheduleFeed = $this->getScheduleFeed($sport)) {
                 $scheduleItems = array();
                 if ($previousEvent = $scheduleFeed->getPreviousEvent()) {
                     $previous = $this->linkForScheduleItem($previousEvent, array('sport' => $sport));
                     $scheduleItems[] = $previous;
                 }
                 if ($nextEvent = $scheduleFeed->getNextEvent()) {
                     $next = $this->linkForScheduleItem($nextEvent, array('sport' => $sport));
                     $this->assign('next', $next);
                     $scheduleItems[] = $next;
                 }
                 $scheduleItems[] = array('title' => $this->getLocalizedString('FULL_SCHEDULE_TEXT'), 'url' => $this->buildBreadcrumbURL('schedule', array('sport' => $sport), true));
                 $this->assign('scheduleItems', $scheduleItems);
             }
             if ($newsFeed = $this->getNewsFeed($sport)) {
                 $start = $this->getArg('start', 0);
                 $newsFeed->setStart($start);
                 $newsFeed->setLimit($this->maxPerPage);
                 $items = $newsFeed->items();
                 $totalItems = $newsFeed->getTotalItems();
                 $this->setLogData($sport, $newsFeed->getTitle());
                 $previousURL = null;
                 $nextURL = null;
                 if ($totalItems > $this->maxPerPage) {
                     $args = $this->args;
                     if ($start > 0) {
                         $args['start'] = $start - $this->maxPerPage;
                         $previousURL = $this->buildBreadcrumbURL($this->page, $args, false);
                     }
                     if ($totalItems - $start > $this->maxPerPage) {
                         $args['start'] = $start + $this->maxPerPage;
                         $nextURL = $this->buildBreadcrumbURL($this->page, $args, false);
                     }
                 }
                 $options = array('section' => $sport);
                 $newsItems = array();
                 foreach ($items as $story) {
                     $newsItems[] = $this->linkForNewsItem($story, $options);
                 }
                 $this->addInternalJavascript('/common/javascript/lib/ellipsizer.js');
                 $this->addOnLoad('setupNewsListing();');
                 $this->assign('newsItems', $newsItems);
                 $this->assign('maxPerPage', $this->maxPerPage);
                 $this->assign('previousURL', $previousURL);
                 $this->assign('nextURL', $nextURL);
                 $this->assign('showImages', $this->showImages);
                 $this->assign('showPubDate', $this->showPubDate);
                 $this->assign('showAuthor', $this->showAuthor);
             }
             // Bookmark
             if ($this->getOptionalModuleVar('BOOKMARKS_ENABLED', 1)) {
                 $cookieParams = array('sport' => $sport);
                 $cookieID = http_build_query($cookieParams);
                 $this->generateBookmarkOptions($cookieID);
             }
             break;
         case "index":
             $tabs = array();
             $latestSubTab = $this->getArg('newsTab', 'topnews');
             // used to distinguish between top news and schedule
             $latestSubTabLinks = array();
             // will add 'Latest' subTab items to this array
             //get top news
             if ($newsFeedData = $this->getNavData('topnews')) {
                 $start = $this->getArg('start', 0);
                 $newsFeed = $this->getNewsFeed('topnews');
                 $newsFeed->setStart($start);
                 $newsFeed->setLimit($this->maxPerPage);
                 $newsTab = array('id' => 'topnews', 'title' => $this->getLocalizedString('TOP_NEWS'), 'url' => $this->buildBreadcrumbURL('index', array('newsTab' => 'topnews'), false), 'ajaxUrl' => $this->buildAjaxBreadcrumbURL('index', array('newsTab' => 'topnews'), false));
                 $latestSubTabLinks[] = $newsTab;
                 $newsItems = $newsFeed->items();
                 $totalItems = $newsFeed->getTotalItems();
                 $this->setLogData('topnews', $newsFeed->getTitle());
                 $previousURL = null;
                 $nextURL = null;
                 if ($totalItems > $this->maxPerPage) {
                     //$args = $this->args;
                     $args = array();
                     if ($start > 0) {
                         $args['start'] = $start - $this->maxPerPage;
                         $previousURL = $this->buildURL('index', $args);
                     }
                     if ($totalItems - $start > $this->maxPerPage) {
                         $args['start'] = $start + $this->maxPerPage;
                         $nextURL = $this->buildURL('index', $args);
                     }
                 }
                 $topNews = array();
                 $options = array('section' => 'topnews');
                 foreach ($newsItems as $story) {
                     $topNews[] = $this->linkForNewsItem($story, $options);
                 }
                 $extraArgs = array('section' => 'topnews');
                 $this->addInternalJavascript('/common/javascript/lib/ellipsizer.js');
                 $this->addOnLoad('setupNewsListing();');
                 // KurogoDebug::debug($newsFeedData['TITLE'], true);
                 $this->assign('topNewsTitle', $newsFeedData['TITLE']);
                 $this->assign('topNews', $topNews);
                 $this->assign('extraArgs', $extraArgs);
                 $this->assign('maxPerPage', $this->maxPerPage);
                 $this->assign('previousURL', $previousURL);
                 $this->assign('nextURL', $nextURL);
                 $this->assign('showImages', $this->showImages);
                 $this->assign('showPubDate', $this->showPubDate);
                 $this->assign('showAuthor', $this->showAuthor);
             }
             // get all sports schedule
             if ($scheduleFeedData = $this->getNavData('allschedule')) {
                 // KurogoDebug::debug($scheduleFeed, true);
                 $scheduleFeed = $this->getScheduleFeed('allschedule');
                 $athleticEvents = $scheduleFeed->items();
                 $scheduleItems = array();
                 foreach ($athleticEvents as $event) {
                     $scheduleItems[] = $this->linkForScheduleItem($event);
                 }
                 if ($limit = Kurogo::arrayVal($scheduleFeedData, 'LIMIT')) {
                     $scheduleItems = array_slice($scheduleItems, 0, $limit);
                 }
                 $scheduleTab = array('id' => 'allschedule', 'title' => $this->getLocalizedString('ALL_SCHEDULE'), 'url' => $this->buildBreadcrumbURL('index', array('newsTab' => 'allschedule'), false), 'ajaxUrl' => $this->buildAjaxBreadcrumbURL('index', array('newsTab' => 'allschedule'), false));
                 $latestSubTabLinks[] = $scheduleTab;
                 $this->assign('scheduleItems', $scheduleItems);
             }
             // make sure we are displaying tabs correctly
             if (count($latestSubTabLinks) > 0) {
                 // if we have topnews to show
                 $tabs[] = 'topnews';
                 if (count($latestSubTabLinks) == 1) {
                     $latestSubTab = $latestSubTabLinks[0]['id'];
                 }
             }
             $this->assign('latestSubTabLinks', $latestSubTabLinks);
             $this->assign('latestSubTab', $latestSubTab);
             //get sports for each gender
             foreach (array('men', 'women', 'coed') as $gender) {
                 $sportsData = $this->getNavData($gender);
                 if ($sportsData) {
                     if ($sportsConfig = $this->getSportsForGender($gender)) {
                         $sports = array();
                         foreach ($sportsConfig as $key => $sportData) {
                             $image = "modules/{$this->id}/images/" . (isset($sportData['ICON']) ? $sportData['ICON'] : strtolower($sportData['TITLE'])) . $this->imageExt;
                             $sport = array('title' => $sportData['TITLE'], 'img' => $image, 'url' => $this->buildURL('sport', array('sport' => $key)));
                             $sports[] = $sport;
                         }
                         $tabs[] = $gender;
                         $this->assign($gender . 'SportsTitle', $sportsData['TITLE']);
                         $this->assign($gender . 'Sports', $sports);
                     }
                 }
             }
             $bookmarkData = $this->getNavData('bookmarks');
             //get bookmarks
             $bookmarks = array();
             if ($this->getOptionalModuleVar('BOOKMARKS_ENABLED', 1)) {
                 $bookmarksData = $this->getBookmarks();
                 foreach ($bookmarksData as $bookmark) {
                     parse_str(stripslashes($bookmark), $params);
                     if (isset($params['sport']) && ($sportData = $this->getSportData($params['sport']))) {
                         $image = "modules/{$this->id}/images/" . (isset($sportData['ICON']) ? $sportData['ICON'] : strtolower($sportData['TITLE'])) . $this->imageExt;
                         $bookmarks[] = array('title' => $sportData['GENDER_TITLE'], 'img' => $image, 'url' => $this->buildURL('sport', array('sport' => $params['sport'])));
                     }
                 }
                 $tabs[] = 'bookmarks';
             }
             $this->assign('placeholder', $this->getLocalizedString('SEARCH_TEXT'));
             $this->assign('bookmarksTitle', $bookmarkData['TITLE']);
             $this->assign('bookmarks', $bookmarks);
             $this->assign('tabs', $tabs);
             $this->enableTabs($tabs);
             break;
         case 'pane':
             if ($this->ajaxContentLoad) {
                 $section = 'topnews';
                 $newsFeed = $this->getNewsFeed($section);
                 $newsFeed->setStart(0);
                 $newsFeed->setLimit($this->maxPerPane);
                 $items = $newsFeed->items();
                 $this->setLogData($section, $newsFeed->getTitle());
                 $stories = array();
                 $options = array('section' => $section, 'addBreadcrumb' => false);
                 foreach ($items as $story) {
                     $stories[] = $this->linkForItem($story, $options);
                 }
                 $this->assign('showImages', $this->showImages);
                 $this->assign('stories', $stories);
             }
             $this->addInternalJavascript('/common/javascript/lib/ellipsizer.js');
             $this->addInternalJavascript('/common/javascript/lib/paneStories.js');
             break;
     }
 }