本文整理汇总了PHP中Kurogo::redirectToURL方法的典型用法代码示例。如果您正苦于以下问题:PHP Kurogo::redirectToURL方法的具体用法?PHP Kurogo::redirectToURL怎么用?PHP Kurogo::redirectToURL使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Kurogo
的用法示例。
在下文中一共展示了Kurogo::redirectToURL方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: auth
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);
}
}
示例2: initializeForPage
protected function initializeForPage()
{
if ($url = $this->getModuleVar('url')) {
$this->logView();
Kurogo::redirectToURL($url);
} else {
throw new KurogoConfigurationException("URL not specified");
}
}
示例3: exceptionHandlerForProduction
/**
* 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");
}
}
示例4: initializeForPage
//.........这里部分代码省略.........
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)) {
示例5: assignItemsFromFeed
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);
}
}
}
示例6: secureModule
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);
}
示例7: login
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);
}
}
示例8: initialize
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');
//.........这里部分代码省略.........
示例9: initializeForPage
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);
//.........这里部分代码省略.........
示例10: auth
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);
}
}
示例11: redirectTo
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);
}
示例12: implode
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;
示例13: initSite
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') {
//.........这里部分代码省略.........
示例14: initializeForPage
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;
//.........这里部分代码省略.........
示例15: initializeForPage
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) {
//.........这里部分代码省略.........