function _outputTypeFile($matches) { $file = $matches[3]; $prefix = ''; $bits = explode("/", $file); if (count($bits) > 1) { $file = array_pop($bits); $prefix = trim(implode("/", $bits), "/") . '/'; } $platform = Kurogo::deviceClassifier()->getPlatform(); $pagetype = Kurogo::deviceClassifier()->getPagetype(); $browser = Kurogo::deviceClassifier()->getBrowser(); $testDirs = array(THEME_DIR, SHARED_THEME_DIR, SITE_APP_DIR, SHARED_APP_DIR, APP_DIR); $testFiles = array("{$prefix}{$pagetype}-{$platform}-{$browser}/{$file}", "{$prefix}{$pagetype}-{$platform}/{$file}", "{$prefix}{$pagetype}/{$file}", "{$prefix}{$file}"); foreach ($testDirs as $dir) { //do not assume dirs have value set if ($dir) { $dir .= '/' . $matches[1] . $matches[2]; foreach ($testFiles as $file) { Kurogo::log(LOG_DEBUG, "Looking for {$dir}/{$file}", 'index'); if ($file = realpath_exists("{$dir}/{$file}")) { _outputFile($file); } } } } _404(); }
function _outputTypeFile($matches) { $file = $matches[3]; $platform = Kurogo::deviceClassifier()->getPlatform(); $pagetype = Kurogo::deviceClassifier()->getPagetype(); $testDirs = array( THEME_DIR.'/'.$matches[1].$matches[2], SITE_DIR.'/'.$matches[1].$matches[2], APP_DIR.'/'.$matches[1].$matches[2], ); $testFiles = array( "$pagetype-$platform/$file", "$pagetype/$file", "$file", ); foreach ($testDirs as $dir) { foreach ($testFiles as $file) { if ($file = realpath_exists("$dir/$file")) { _outputFile($file); } } } _404(); }
public static function logView($service, $id, $page, $data, $dataLabel, $size = 0) { switch ($service) { case 'web': case 'api': break; default: throw new Exception("Invalid service {$service}"); break; } $deviceClassifier = Kurogo::deviceClassifier(); $ip = Kurogo::determineIP(); $requestURI = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''; $referrer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; $userAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; $visitID = self::getVisitID($service); if (Kurogo::getSiteVar('AUTHENTICATION_ENABLED')) { $session = Kurogo::getSession(); $user = $session->getUser(); } else { $user = false; } $logData = array('timestamp' => time(), 'date' => date('Y-m-d H:i:s'), 'site' => SITE_KEY, 'service' => $service, 'requestURI' => $requestURI, 'referrer' => $referrer, 'referredSite' => intval(self::isFromThisSite($referrer)), 'referredModule' => intval(self::isFromModule($referrer, $id)), 'userAgent' => $userAgent, 'ip' => $ip, 'user' => $user ? $user->getUserID() : '', 'authority' => $user ? $user->getAuthenticationAuthorityIndex() : '', 'visitID' => $visitID, 'pagetype' => $deviceClassifier->getPageType(), 'platform' => $deviceClassifier->getPlatform(), 'moduleID' => $id, 'page' => $page, 'data' => $data, 'dataLabel' => $dataLabel, 'size' => $size, 'elapsed' => Kurogo::getElapsed()); try { $conn = self::connection(); } catch (KurogoDataServerException $e) { throw new KurogoConfigurationException("Database not configured for statistics. To disable stats, set STATS_ENABLED=0 in site.ini"); } $sql = sprintf("INSERT INTO %s (%s) VALUES (%s)", Kurogo::getOptionalSiteVar("KUROGO_STATS_TABLE", "kurogo_stats_v1"), implode(",", array_keys($logData)), implode(",", array_fill(0, count($logData), '?'))); if (!($result = $conn->query($sql, array_values($logData), db::IGNORE_ERRORS))) { self::createStatsTables(); $result = $conn->query($sql, array_values($logData)); } return $result; }
protected function init($page, $args) { if(!Kurogo::getSiteVar('PRODUCTION_ERROR_HANDLER_ENABLED')) { set_exception_handler("exceptionHandlerForError"); } $this->pagetype = Kurogo::deviceClassifier()->getPagetype(); $this->platform = Kurogo::deviceClassifier()->getPlatform(); $this->page = 'index'; $this->setTemplatePage($this->page, $this->id); $this->args = $args; return; }
protected function getCreditsHTML() { //get original device $device = Kurogo::deviceClassifier()->getDevice(); //set browser to unknown so we don't get AppQ HTML Kurogo::deviceClassifier()->setBrowser('unknown'); $module = WebModule::factory($this->configModule, 'credits_html'); $html = $module->fetchPage(); //restore device Kurogo::deviceClassifier()->setDevice($device); return $html; }
protected function init($page = '', $args = array()) { if (!Kurogo::getSiteVar('PRODUCTION_ERROR_HANDLER_ENABLED')) { set_exception_handler("exceptionHandlerForError"); } $this->pagetype = Kurogo::deviceClassifier()->getPagetype(); $this->platform = Kurogo::deviceClassifier()->getPlatform(); $this->page = 'index'; $this->setTemplatePage($this->page, $this->id); $this->args = $args; $this->logView = Kurogo::getOptionalSiteVar('STATS_ENABLED', true) ? true : false; try { $this->moduleName = $this->getOptionalModuleVar('title', 'Error', 'module'); } catch (KurogoConfigurationException $e) { } return; }
function _outputTypeFile($matches) { $file = $matches[3]; $platform = Kurogo::deviceClassifier()->getPlatform(); $pagetype = Kurogo::deviceClassifier()->getPagetype(); $browser = Kurogo::deviceClassifier()->getBrowser(); $testDirs = array(THEME_DIR . '/' . $matches[1] . $matches[2], SITE_APP_DIR . '/' . $matches[1] . $matches[2], SHARED_APP_DIR . '/' . $matches[1] . $matches[2], APP_DIR . '/' . $matches[1] . $matches[2]); $testFiles = array("{$pagetype}-{$platform}-{$browser}/{$file}", "{$pagetype}-{$platform}/{$file}", "{$pagetype}/{$file}", "{$file}"); foreach ($testDirs as $dir) { foreach ($testFiles as $file) { if ($file = realpath_exists("{$dir}/{$file}")) { _outputFile($file); } } } _404(); }
protected function init($page = '', $args = array()) { if ($page == 'error') { if (!Kurogo::getSiteVar('PRODUCTION_ERROR_HANDLER_ENABLED')) { set_exception_handler("exceptionHandlerForError"); } $this->pagetype = Kurogo::deviceClassifier()->getPagetype(); $this->platform = Kurogo::deviceClassifier()->getPlatform(); $this->browser = Kurogo::deviceClassifier()->getBrowser(); $this->page = 'error'; $this->setTemplatePage($this->page, $this->id); $this->setArgs($args); $this->ajaxContentLoad = $this->getArg(self::AJAX_PARAMETER) ? true : false; $this->logView = Kurogo::getOptionalSiteVar('STATS_ENABLED', true) ? true : false; try { $this->moduleName = $this->getOptionalModuleVar('title', 'Error', 'module'); } catch (KurogoConfigurationException $e) { } } else { $this->redirectToModule($this->getHomeModuleID(), 'index'); } return; }
public function initializeForCommand() { switch ($this->command) { case 'hello': $allmodules = $this->getAllModules(); $homeModuleData = $this->getModuleNavigationData(); $homeModules = array('primary' => isset($homeModuleData['primary']) ? array_keys($homeModuleData['primary']) : array(), 'secondary' => isset($homeModuleData['secondary']) ? array_keys($homeModuleData['secondary']) : array()); foreach ($allmodules as $moduleID => $module) { if ($module->isEnabled()) { $home = false; if (($key = array_search($moduleID, $homeModules['primary'])) !== FALSE) { $home = array('type' => 'primary', 'order' => $key, 'title' => $homeModuleData['primary'][$moduleID]); } elseif (($key = array_search($moduleID, $homeModules['secondary'])) !== FALSE) { $home = array('type' => 'secondary', 'order' => $key); } $modules[] = array('id' => $module->getID(), 'tag' => $module->getConfigModule(), 'title' => $module->getModuleVar('title', 'module'), 'access' => $module->getAccess(AccessControlList::RULE_TYPE_ACCESS), 'payload' => $module->getPayload(), 'vmin' => $module->getVmin(), 'vmax' => $module->getVmax(), 'home' => $home); } } $response = array('timezone' => Kurogo::getSiteVar('LOCAL_TIMEZONE'), 'version' => KUROGO_VERSION, 'modules' => $modules, 'default' => Kurogo::defaultModule()); $this->setResponse($response); $this->setResponseVersion(2); break; case 'classify': $userAgent = $this->getArg('useragent'); if (!$userAgent) { throw new KurogoException("useragent parameter not specified"); } $response = Kurogo::deviceClassifier()->classifyUserAgent($userAgent); $this->setResponse($response); $this->setResponseVersion(1); break; default: $this->invalidCommand(); break; } }
protected function loadDeviceClassifierIfNeeded() { $this->deviceClassifier = Kurogo::deviceClassifier(); }
protected function initializeForPage() { //make sure that only desktop/tablet devices can use the module $deviceClassifier = Kurogo::deviceClassifier(); if ($this->page != 'index' && !($deviceClassifier->isComputer() || $deviceClassifier->isTablet())) { $this->redirectTo('index'); } $navSections = $this->getNavSections(); $section = ''; $this->assign('navSections', $navSections); $this->addJQuery(); $this->addJQueryUI(); switch ($this->page) { case 'modules': $subNavSections = $this->getSubNavSections($this->page); $this->assign('subNavSections', $subNavSections); $defaultSubNavSection = key($subNavSections); $section = $this->getArg('section', $defaultSubNavSection); $moduleID = $this->getArg('module'); if ($moduleID) { $this->setTemplatePage('module'); try { if ($module = WebModule::factory($moduleID)) { $this->assign('moduleName', $module->getModuleName()); $this->assign('moduleID', $module->getConfigModule()); $this->assign('moduleIcon', $module->getOptionalModuleVar('icon', $module->getConfigModule(), 'module')); $section = $moduleID; $moduleSection = $this->getArg('section', 'general'); $this->assign('moduleSection', $moduleSection); } } catch (KurogoException $e) { $this->redirectTo($this->page, array()); } } elseif ($section == $defaultSubNavSection) { $moduleClasses = WebModule::getAllModuleClasses(); $this->assign('moduleClasses', $moduleClasses); $this->setTemplatePage($section); } elseif ($section == 'homescreen') { $this->setTemplatePage($section); $modules = $this->getModules(); $this->assign('modules', $modules); } else { $this->redirectTo($this->page, array()); } break; case 'site': $subNavSections = $this->getSubNavSections($this->page); $this->assign('subNavSections', $subNavSections); $defaultSubNavSection = key($subNavSections); $section = $this->getArg('section', $defaultSubNavSection); if (!isset($subNavSections[$section])) { $this->redirectTo($this->page, array()); } break; case 'credits': $section = $this->getArg('section', 'credits'); $subNavSections = array('credits' => array('id' => 'credits', 'title' => $this->getLocalizedString("ADMIN_CREDITS_CREDITS_TITLE"), 'url' => $this->buildURL($this->page, array('section' => 'credits'))), 'license' => array('id' => 'license', 'title' => $this->getLocalizedString("ADMIN_CREDITS_LICENSE_TITLE"), 'url' => $this->buildURL($this->page, array('section' => 'license')))); $this->assign('subNavSections', $subNavSections); if (isset($subNavSections[$section])) { switch ($section) { case 'license': $licenseFile = ROOT_DIR . "/LICENSE"; if (is_file($licenseFile)) { $this->assign('license', file_get_contents($licenseFile)); } else { die($licenseFile); throw new KurogoException("Unable to load LICENSE file, you may have a compromised Kurogo Installation"); } } $this->setTemplatePage($section); } else { $this->redirectTo('section', array()); } break; case 'index': //redirect desktop devices to the "default page" $deviceClassifier = Kurogo::deviceClassifier(); if ($deviceClassifier->isComputer() || $deviceClassifier->isTablet()) { $defaultSection = current($navSections); $this->redirectTo($defaultSection['id'], array()); } break; default: $this->redirectTo('index', array()); break; } $this->assign('section', $section); }
function minifyPostProcess($content, $type) { if ($type === Minify::TYPE_CSS) { $urlPrefix = URL_PREFIX; if (Kurogo::getSiteVar('DEVICE_DEBUG') && URL_PREFIX == URL_BASE) { // if device debugging is on, always append device classification $urlPrefix .= 'device/'.Kurogo::deviceClassifier()->getDevice().'/'; } $content = "/* Adding url prefix '".$urlPrefix."' */\n\n". preg_replace(';url\("?\'?/([^"\'\)]+)"?\'?\);', 'url("'.$urlPrefix.'\1")', $content); } return $content; }
public static function getDevice() { return Kurogo::deviceClassifier()->getDevice(); }
<?php /* Smarty version Smarty-3.0.7, created on 2014-11-26 14:05:47 compiled from "findInclude:common/templates/videoPlayer.tpl" */ /*%%SmartyHeaderCode:20176320395476248b0f8470-12784728%%*/ if (!defined('SMARTY_DIR')) { exit('no direct access allowed'); } $_smarty_tpl->decodeProperties(array('file_dependency' => array('bb5a0de692e4ffeae0751b86948d1074393f1593' => array(0 => 'findInclude:common/templates/videoPlayer.tpl', 1 => 1364681342, 2 => 'findInclude')), 'nocache_hash' => '20176320395476248b0f8470-12784728', 'function' => array(), 'has_nocache_code' => false)); /*/%%SmartyHeaderCode%%*/ if ($_smarty_tpl->getVariable('video')->value) { ?> <?php if ($_smarty_tpl->getVariable('video')->value->canPlay(Kurogo::deviceClassifier())) { ?> <?php $_smarty_tpl->tpl_vars['videoPlayerType'] = new Smarty_variable($_smarty_tpl->getVariable('video')->value->getType(), null, null); ?> <div class="kgo-videoplayer kgo-videoplayer-<?php echo $_smarty_tpl->getVariable('videoPlayerType')->value; ?> "> <div class="kgo-videoplayer-container"> <?php $_template = new Smarty_Internal_Template("findInclude:common/templates/videoPlayer/videoPlayer_" . $_smarty_tpl->getVariable('videoPlayerType')->value . ".tpl", $_smarty_tpl->smarty, $_smarty_tpl, $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, null, null); echo $_template->getRenderedTemplate(); unset($_template); ?> </div> </div> <?php
protected function initializeForPage() { if ($this->pagetype == 'basic') { return; } if (count($this->feeds) == 0) { throw new KurogoConfigurationException("No video feeds configured"); } // Categories / Sections $section = $this->getArg('section', $this->getDefaultSection()); if (!isset($this->feeds[$section])) { $section = $this->getDefaultSection(); } $this->assign('currentSection', $section); $this->assign('sections', VideoModuleUtils::getSectionsFromFeeds($this->feeds)); $controller = $this->getFeed($section); $this->assign('feedData', $this->feeds[$section]); switch ($this->page) { case 'pane': if ($this->ajaxContentLoad) { $start = 0; $maxPerPage = $this->getOptionalModuleVar('MAX_PANE_RESULTS', 5); $data = array('noBreadcrumbs' => true, 'section' => $section); if ($this->legacyController) { $items = $controller->items($start, $maxPerPage); } else { $controller->setStart($start); $controller->setLimit($maxPerPage); $items = $controller->items(); } $videos = array(); foreach ($items as $video) { $videos[] = $this->linkForItem($video, $data); } foreach ($videos as $i => $video) { $videos[$i]['url'] = $this->buildURL('index') . '#' . urlencode(FULL_URL_PREFIX . ltrim($video['url'], '/')); } $this->assign('stories', $videos); } $this->addInternalJavascript('/common/javascript/lib/ellipsizer.js'); $this->addInternalJavascript('/common/javascript/lib/paneStories.js'); break; case 'search': case 'index': $maxPerPage = $this->getOptionalModuleVar('MAX_RESULTS', 10); $start = $this->getArg('start', 0); if (!$this->legacyController) { $controller->setStart($start); $controller->setLimit($maxPerPage); } if ($this->page == 'search') { if ($filter = $this->getArg('filter')) { $searchTerms = trim($filter); $this->setLogData($searchTerms); if ($this->legacyController) { $items = $controller->search($searchTerms, $start, $maxPerPage); } else { $items = $controller->search($searchTerms); } $this->assign('searchTerms', $searchTerms); } else { $this->redirectTo('index', array('section' => $section), false); } } else { $this->setLogData($section, $controller->getTitle()); if ($this->legacyController) { $items = $controller->items($start, $maxPerPage); } else { $items = $controller->items(); } } $totalItems = $controller->getTotalItems(); $videos = array(); foreach ($items as $video) { $videos[] = $this->linkForItem($video, array('section' => $section)); } $this->assign('videos', $videos); $this->assign('totalItems', $totalItems); $previousURL = null; $nextURL = null; if ($totalItems > $maxPerPage) { $args = $this->args; if ($start > 0) { $args['start'] = $start - $maxPerPage; $previousURL = $this->buildBreadcrumbURL($this->page, $args, false); } if ($totalItems - $start > $maxPerPage) { $args['start'] = $start + $maxPerPage; $nextURL = $this->buildBreadcrumbURL($this->page, $args, false); } } /* only assign section if it's the search page, otherwise section comes from select box */ if ($this->page == 'search') { $hiddenArgs = array('section' => $section); } else { $hiddenArgs = array(); } $this->addInternalJavascript('/common/javascript/lib/ellipsizer.js'); $this->addOnLoad('setupVideosListing();'); $this->assign('placeholder', $this->getLocalizedString('SEARCH_MODULE', $this->getModuleName())); $this->assign('start', $start); $this->assign('previousURL', $previousURL); $this->assign('nextURL', $nextURL); $this->assign('hiddenArgs', $hiddenArgs); $this->assign('maxPerPage', $maxPerPage); if ($this->getOptionalModuleVar('BOOKMARKS_ENABLED', 1)) { $this->generateBookmarkLink(); } break; case 'bookmarks': if (!$this->getOptionalModuleVar('BOOKMARKS_ENABLED', 1)) { $this->redirectTo('index'); } $controllerCache = array($section => $controller); $videos = array(); foreach ($this->getBookmarks() as $aBookmark) { if (!$aBookmark) { continue; } parse_str(stripslashes($aBookmark), $params); if (isset($params['section'], $this->feeds[$params['section']], $params['videoid'])) { if (!isset($controllerCache[$params['section']])) { $controllerCache[$params['section']] = $this->getFeed($params['section']); } if ($video = $controllerCache[$params['section']]->getItem($params['videoid'])) { $videos[] = $this->linkForItem($video, $params); } } } $this->assign('videos', $videos); $this->addInternalJavascript('/common/javascript/lib/ellipsizer.js'); $this->addOnLoad('setupVideosListing();'); break; case 'detail': $videoid = $this->getArg('videoid'); if ($video = $controller->getItem($videoid)) { $this->setLogData($videoid, $video->getTitle()); $this->setTemplatePage('detail-' . $video->getType()); if ($video->canPlay(Kurogo::deviceClassifier())) { $this->assign('videoTitle', $video->getTitle()); $this->assign('videoid', $video->getID()); $this->assign('videoStreamingURL', $video->getStreamingURL()); $this->assign('videoStillImage', $video->getStillFrameImage()); $this->assign('videoDescription', $video->getDescription()); $this->assign('videoAuthor', $video->getAuthor()); $this->assign('videoDate', $video->getPublished()->format('M j, Y')); $body = $video->getDescription() . "\n\n" . $video->getURL(); if ($this->getOptionalModuleVar('SHARING_ENABLED', 1)) { $this->assign('shareEmailURL', $this->buildMailToLink("", $video->getTitle(), $body)); $this->assign('shareTitle', 'Share this video'); $this->assign('videoURL', $video->getURL()); $this->assign('shareRemark', $video->getTitle()); } // Bookmark if ($this->getOptionalModuleVar('BOOKMARKS_ENABLED', 1)) { $cookieParams = array('section' => $section, 'videoid' => $videoid); $cookieID = http_build_query($cookieParams); $this->generateBookmarkOptions($cookieID); } } else { $this->setTemplatePage('videoError.tpl'); } } else { $this->redirectTo('index', array('section' => $section), false); } break; } }
public static function defaultModule() { $platform = strtoupper(Kurogo::deviceClassifier()->getPlatform()); $pagetype = strtoupper(Kurogo::deviceClassifier()->getPagetype()); $browser = strtoupper(Kurogo::deviceClassifier()->getBrowser()); if (!($module = Kurogo::getOptionalSiteVar("DEFAULT-{$pagetype}-{$platform}-{$browser}", '', 'urls'))) { if (!($module = Kurogo::getOptionalSiteVar("DEFAULT-{$pagetype}-{$platform}", '', 'urls'))) { if (!($module = Kurogo::getOptionalSiteVar("DEFAULT-{$pagetype}", '', 'urls'))) { $homeModuleID = Kurogo::getOptionalSiteVar('HOME_MODULE', 'home', 'modules'); $module = Kurogo::getOptionalSiteVar("DEFAULT", $homeModuleID, 'urls'); } } } return $module; }
public function initializeForCommand() { switch ($this->command) { case 'hello': $allmodules = $this->getAllModules(); if ($this->requestedVersion >= 3) { $version = 3; } else { $version = 2; $homeModuleData = $this->getAllModuleNavigationData(); $homeModules = array('primary' => array_keys($homeModuleData['primary']), 'secondary' => array_keys($homeModuleData['secondary'])); } $platform = $this->clientPlatform; if ($this->clientPagetype == 'tablet') { $platform .= '-tablet'; } foreach ($allmodules as $moduleID => $module) { if ($module->isEnabled()) { //home is deprecated in lieu of using the "modules" command of the home module $home = false; if ($version < 3) { if (($key = array_search($moduleID, $homeModules['primary'])) !== FALSE) { if (Kurogo::arrayVal($homeModuleData['primary'][$moduleID], 'visible', true)) { $title = Kurogo::arrayVal($homeModuleData['primary'][$moduleID], 'title', $module->getModuleVar('title')); $home = array('type' => 'primary', 'order' => $key, 'title' => $title); } } elseif (($key = array_search($moduleID, $homeModules['secondary'])) !== FALSE) { if (Kurogo::arrayVal($homeModuleData['secondary'][$moduleID], 'visible', true)) { $title = Kurogo::arrayVal($homeModuleData['secondary'][$moduleID], 'title', $module->getModuleVar('title')); $home = array('type' => 'secondary', 'order' => $key, 'title' => $title); } } } $moduleResponse = array('id' => $module->getID(), 'tag' => $module->getConfigModule(), 'icon' => $module->getOptionalModuleVar('icon', $module->getConfigModule(), 'module'), 'title' => $module->getModuleVar('title', 'module'), 'access' => $module->getAccess(AccessControlList::RULE_TYPE_ACCESS), 'payload' => $module->getPayload(), 'bridge' => $module->getWebBridgeConfig($platform), 'vmin' => $module->getVmin(), 'vmax' => $module->getVmax()); if ($version < 3) { $moduleResponse['home'] = $home; } $modules[] = $moduleResponse; } } $contexts = array(); foreach (Kurogo::sharedInstance()->getContexts() as $context) { if ($context->isManual()) { $contexts[] = array('id' => $context->getID(), 'title' => $context->getTitle(), 'description' => $context->getDescription()); } } $response = array('timezone' => Kurogo::getSiteVar('LOCAL_TIMEZONE'), 'site' => Kurogo::getSiteString('SITE_NAME'), 'organization' => Kurogo::getSiteString('ORGANIZATION_NAME'), 'version' => KUROGO_VERSION, 'modules' => $modules, 'default' => Kurogo::defaultModule(), 'home' => $this->getHomeModuleID(), 'contexts' => $contexts, 'contextsDisplay' => array('home' => Kurogo::getSiteVar('USER_CONTEXT_LIST_STYLE_NATIVE', 'contexts'), 'customize' => Kurogo::getSiteVar('USER_CONTEXT_LIST_STYLE_CUSTOMIZE', 'contexts'))); if ($appData = Kurogo::getAppData($this->clientPlatform)) { if ($version = Kurogo::arrayVal($appData, 'version')) { if (version_compare($this->clientVersion, $version) < 0) { $response['appdata'] = array('url' => Kurogo::arrayVal($appData, 'url'), 'version' => Kurogo::arrayVal($appData, 'version')); } } } $this->setResponse($response); $this->setResponseVersion($version); break; case 'setcontext': $context = $this->getArg('context'); $response = Kurogo::sharedInstance()->setUserContext($context); $this->setResponse($response); $this->setResponseVersion(1); break; case 'classify': $userAgent = $this->getArg('useragent'); if (!$userAgent) { throw new KurogoException("useragent parameter not specified"); } $response = Kurogo::deviceClassifier()->classifyUserAgent($userAgent); $this->setResponse($response); $this->setResponseVersion(1); break; default: $this->invalidCommand(); break; } }
public static function logView($service, $id, $page, $data, $dataLabel, $size = 0) { switch ($service) { case 'web': case 'api': break; default: throw new Exception("Invalid service {$service}"); break; } $deviceClassifier = Kurogo::deviceClassifier(); $ip = Kurogo::determineIP(); $requestURI = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''; $referrer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; $userAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; $visitID = self::getVisitID($service); if (Kurogo::getSiteVar('AUTHENTICATION_ENABLED')) { $session = Kurogo::getSession(); $user = $session->getUser(); } else { $user = false; } $statsLogFilename = Kurogo::getOptionalSiteVar('KUROGO_STATS_LOG_FILENAME', "kurogo_stats_log_v1"); $statsLogFile = LOG_DIR . DIRECTORY_SEPARATOR . $statsLogFilename; $current = time(); $logData = array('timestamp' => time(), 'date' => date('Y-m-d H:i:s', $current), 'service' => $service, 'site' => SITE_KEY, 'requestURI' => $requestURI, 'referrer' => $referrer, 'referredSite' => intval(self::isFromThisSite($referrer)), 'referredModule' => intval(self::isFromModule($referrer, $id)), 'userAgent' => $userAgent, 'ip' => $ip, 'user' => $user ? $user->getUserID() : '', 'authority' => $user ? $user->getAuthenticationAuthorityIndex() : '', 'visitID' => $visitID, 'pagetype' => $deviceClassifier->getPageType(), 'platform' => $deviceClassifier->getPlatform(), 'moduleID' => $id, 'page' => $page, 'data' => $data, 'dataLabel' => $dataLabel, 'size' => $size, 'elapsed' => Kurogo::getElapsed()); $fields = array_fill(0, count($logData), '%s'); $data = array_merge(array(implode("\t", $fields)), array_values($logData)); $content = call_user_func_array('sprintf', $data) . PHP_EOL; self::fileAppend($statsLogFile, $content); return true; }
function minifyPostProcess($content, $type) { if ($type === Minify::TYPE_CSS) { $urlPrefix = URL_PREFIX; if (Kurogo::getSiteVar('DEVICE_DEBUG') && URL_PREFIX == URL_BASE) { // if device debugging is on, always append device classification $urlPrefix .= 'device/' . Kurogo::deviceClassifier()->getDevice() . '/'; } // Theme variable replacement $themeVars = minifyGetThemeVars(); if ($themeVars) { $content = preg_replace_callback(';@@@([^@]+)@@@;', 'minifyThemeVarReplace', $content); } $content = "/* Adding url prefix '" . $urlPrefix . "' */\n\n" . preg_replace(';url\\("?\'?/([^"\'\\)]+)"?\'?\\);', 'url("' . $urlPrefix . '\\1")', $content); } return $content; }
function __construct() { parent::__construct(); // Fix this in a later release -- currently generates lots of warnings $this->error_reporting = E_ALL & ~E_NOTICE; // Device info $pagetype = Kurogo::deviceClassifier()->getPagetype(); $platform = Kurogo::deviceClassifier()->getPlatform(); $supportsCerts = Kurogo::deviceClassifier()->getSupportsCerts(); // Smarty configuration $this->setCompileDir (CACHE_DIR.'/smarty/templates'); $this->setCacheDir (CACHE_DIR.'/smarty/html'); $this->setCompileId ("$pagetype-$platform"); $this->registerFilter('pre', array('TemplateEngine', 'smartyPrefilterHandleIncludeAndExtends')); $this->registerFilter('post', array('TemplateEngine', 'smartyPostfilterHandleIncludeAndExtends')); // Postfilter to add url prefix to absolute urls and // strip unnecessary whitespace (ignores <pre>, <script>, etc) $this->registerFilter('output', array('TemplateEngine', 'smartyOutputfilterAddURLPrefixAndStripWhitespace')); $this->registerPlugin('block', 'html_access_key_link', 'TemplateEngine::smartyBlockAccessKeyLink'); $this->registerPlugin('function', 'html_access_key_reset', 'TemplateEngine::smartyTemplateAccessKeyReset'); $this->registerPlugin('modifier', 'nosecure', array($this,'nosecure')); // variables common to all modules $this->assign('pagetype', $pagetype); $this->assign('platform', $platform); $this->assign('supportsCerts', $supportsCerts ? 1 : 0); $this->assign('showDeviceDetection', Kurogo::getSiteVar('DEVICE_DETECTION_DEBUG')); $this->assign('moduleDebug', Kurogo::getSiteVar('MODULE_DEBUG')); }
public static function isNativeCall() { return self::hasNativePlatform() || Kurogo::deviceClassifier()->getBrowser() == 'native'; }
public function initializeForCommand() { switch ($this->command) { case 'index': $categories = array(); $groups = $this->getFeedGroups(); if ($groups) { foreach ($groups as $id => &$groupData) { if (isset($groupData['center'])) { $latlon = filterLatLon($groupData['center']); $groupData['lat'] = $latlon['lat']; $groupData['lon'] = $latlon['lon']; } $groupData['id'] = $id; $categories[] = $groupData; } $response = array('categories' => $categories); } else { $feeds = $this->loadFeedData(); foreach ($feeds as $id => $feedData) { $categories[] = array('title' => $feedData['TITLE'], 'subtitle' => $feedData['SUBTITLE'], 'id' => $id); } } $this->setResponse($response); $this->setResponseVersion(1); break; case 'category': $this->loadFeedData(); $category = $this->getArg('category'); $groups = $this->getFeedGroups(); if (isset($groups[$category])) { $this->feedGroup = $category; $groupData = $this->loadFeedData(); $categories = array(); foreach ($groupData as $id => $feed) { if (!isset($feed['HIDDEN']) || !$feed['HIDDEN']) { $category = array('id' => $id, 'title' => $feed['TITLE']); if (isset($feed['SUBTITLE'])) { $category['subtitle'] = $feed['SUBTITLE']; } $categories[] = $category; } } $response = array('categories' => $categories); $this->setResponse($response); $this->setResponseVersion(1); } else { $dataController = $this->getDataController(); if ($dataController) { $listItems = $dataController->getListItems(); $placemarks = array(); $categories = array(); foreach ($listItems as $listItem) { if ($listItem instanceof Placemark) { $placemarks[] = $this->shortArrayFromPlacemark($listItem); } else { $categories[] = $this->arrayFromCategory($listItem); } } $response = array(); if ($placemarks) { $response['placemarks'] = $placemarks; } if ($categories) { $response['categories'] = $categories; } $this->setResponse($response); $this->setResponseVersion(1); } else { $error = new KurogoError("Could not find data source for requested category"); $this->throwError($error); } } break; case 'detail': $dataController = $this->getDataController(); $placemarkId = $this->getArg('id', null); if ($dataController && $placemarkId !== null) { $placemark = $dataController->selectPlacemark($placemarkId); $fields = $placemark->getFields(); $geometry = $placemark->getGeometry(); $response = array('id' => $placemarkId, 'title' => $placemark->getTitle(), 'subtitle' => $placemark->getSubtitle(), 'address' => $placemark->getAddress(), 'details' => $placemark->getFields()); if ($geometry) { $center = $geometry->getCenterCoordinate(); $response['lat'] = $center['lat']; $response['lon'] = $center['lon']; $response['geometryType'] = $this->getGeometryType($geometry); $response['geometry'] = $this->formatGeometry($geometry); } $this->setResponse($response); $this->setResponseVersion(1); } break; case 'search': $mapSearch = $this->getSearchClass($this->args); $lat = $this->getArg('lat', 0); $lon = $this->getArg('lon', 0); if ($lat || $lon) { // defaults values for proximity search $tolerance = 1000; $maxItems = 0; // check for settings in feedgroup config $configData = $this->getDataForGroup($this->feedGroup); if ($configData) { if (isset($configData['NEARBY_THRESHOLD'])) { $tolerance = $configData['NEARBY_THRESHOLD']; } if (isset($configData['NEARBY_ITEMS'])) { $maxItems = $configData['NEARBY_ITEMS']; } } // check for override settings in feeds $configData = $this->getCurrentFeed(); if (isset($configData['NEARBY_THRESHOLD'])) { $tolerance = $configData['NEARBY_THRESHOLD']; } if (isset($configData['NEARBY_ITEMS'])) { $maxItems = $configData['NEARBY_ITEMS']; } $searchResults = $mapSearch->searchByProximity(array('lat' => $lat, 'lon' => $lon), 1000, 10); } else { $searchTerms = $this->getArg('q'); if ($searchTerms) { $searchResults = $mapSearch->searchCampusMap($searchTerms); } } $places = array(); foreach ($searchResults as $result) { $places[] = $this->shortArrayFromPlacemark($result); } $response = array('total' => count($places), 'returned' => count($places), 'results' => $places); $this->setResponse($response); $this->setResponseVersion(1); break; // ajax calls // ajax calls case 'projectPoint': $lat = $this->getArg('lat', 0); $lon = $this->getArg('lon', 0); $fromProj = $this->getArg('from', GEOGRAPHIC_PROJECTION); $toProj = $this->getArg('to', GEOGRAPHIC_PROJECTION); $projector = new MapProjector(); $projector->setSrcProj($fromProj); $projector->setDstProj($toProj); $result = $projector->projectPoint(array('lat' => $lat, 'lon' => $lon)); $this->setResponse($result); $this->setResponseVersion(1); break; case 'sortGroupsByDistance': $lat = $this->getArg('lat', 0); $lon = $this->getArg('lon', 0); $categories = array(); $showDistances = $this->getOptionalModuleVar('SHOW_DISTANCES', true); if ($lat || $lon) { foreach ($this->getFeedGroups() as $id => $groupData) { $center = filterLatLon($groupData['center']); $distance = greatCircleDistance($lat, $lon, $center['lat'], $center['lon']); $category = array('title' => $groupData['title'], 'id' => $id); if ($showDistances && ($displayText = $this->displayTextFromMeters($distance))) { $category['distance'] = $displayText; } $categories[] = $category; $distances[] = $distance; } array_multisort($distances, SORT_ASC, $categories); } $this->setResponse($categories); $this->setResponseVersion(1); break; case 'staticImageURL': $params = array('STATIC_MAP_BASE_URL' => $this->getArg('baseURL'), 'STATIC_MAP_CLASS' => $this->getArg('mapClass')); $dc = Kurogo::deviceClassifier(); $mapDevice = new MapDevice($dc->getPagetype(), $dc->getPlatform()); $mapController = MapImageController::factory($params, $mapDevice); if (!$mapController->isStatic()) { $error = new KurogoError(0, "staticImageURL must be used with a StaticMapImageController subclass"); $this->throwError($error); } $currentQuery = $this->getArg('query'); $mapController->parseQuery($currentQuery); $overrides = $this->getArg('overrides'); $mapController->parseQuery($overrides); $zoomDir = $this->getArg('zoom'); if ($zoomDir == 1 || $zoomDir == 'in') { $level = $mapController->getLevelForZooming('in'); $mapController->setZoomLevel($level); } elseif ($zoomDir == -1 || $zoomDir == 'out') { $level = $mapController->getLevelForZooming('out'); $mapController->setZoomLevel($level); } $scrollDir = $this->getArg('scroll'); if ($scrollDir) { $center = $mapController->getCenterForPanning($scrollDir); $mapController->setCenter($center); } $url = $mapController->getImageURL(); $this->setResponse($url); $this->setResponseVersion(1); break; case 'geocode': $locationSearchTerms = $this->getArg('q'); $geocodingDataControllerClass = $this->getOptionalModuleVar('GEOCODING_DATA_CONTROLLER_CLASS'); $geocodingDataParserClass = $this->getOptionalModuleVar('GEOCODING_DATA_PARSER_CLASS'); $geocoding_base_url = $this->getOptionalModuleVar('GEOCODING_BASE_URL'); $arguments = array('BASE_URL' => $geocoding_base_url, 'CACHE_LIFETIME' => 86400, 'PARSER_CLASS' => $geocodingDataParserClass); $controller = DataController::factory($geocodingDataControllerClass, $arguments); $controller->addCustomFilters($locationSearchTerms); $response = $controller->getParsedData(); // checking for Geocoding service error if ($response['errorCode'] == 0) { unset($response['errorCode']); unset($response['errorMessage']); $this->setResponse($response); $this->setResponseVersion(1); } else { $kurogoError = new KurogoError($response['errorCode'], "Geocoding service Erroe", $response['errorMessage']); $this->setResponseError($kurogoError); $this->setResponseVersion(1); } break; default: $this->invalidCommand(); break; } }
protected function init($page='', $args=array()) { if ($page) { parent::init(); } $this->moduleName = $this->getModuleVar('title','module'); $this->setArgs($args); $this->pagetype = Kurogo::deviceClassifier()->getPagetype(); $this->platform = Kurogo::deviceClassifier()->getPlatform(); $this->supportsCerts = Kurogo::deviceClassifier()->getSupportsCerts(); // Pull in fontsize if (isset($args['font'])) { $this->fontsize = $args['font']; setcookie('fontsize', $this->fontsize, time() + Kurogo::getSiteVar('LAYOUT_COOKIE_LIFESPAN'), COOKIE_PATH); } else if (isset($_COOKIE['fontsize'])) { $this->fontsize = $_COOKIE['fontsize']; } switch ($this->pagetype) { case 'compliant': $this->imageExt = '.png'; break; case 'touch': case 'basic': $this->imageExt = '.gif'; break; } if ($page) { $this->setPage($page); $this->setTemplatePage($this->page, $this->id); $this->setAutoPhoneNumberDetection(Kurogo::getSiteVar('AUTODETECT_PHONE_NUMBERS')); } }
/** * 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)) { header('Location: ' . $url); die(0); } else { die("A serious error has occurred"); } }
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)); header("Location: {$url}"); exit; } }
public function __construct($args) { //load arguments $this->useDB = isset($args['AUTHENTICATION_USE_SESSION_DB']) ? $args['AUTHENTICATION_USE_SESSION_DB'] : false; $this->maxIdleTime = isset($args['AUTHENTICATION_IDLE_TIMEOUT']) ? intval($args['AUTHENTICATION_IDLE_TIMEOUT']) : 0; $this->remainLoggedInTime = isset($args['AUTHENTICATION_REMAIN_LOGGED_IN_TIME']) ? intval($args['AUTHENTICATION_REMAIN_LOGGED_IN_TIME']) : 0; $this->loginCookiePath = URL_BASE . 'login'; $this->apiCookiePath = URL_BASE . API_URL_PREFIX . '/login'; $this->debugMode = isset($args['DEBUG_MODE']) ? $args['DEBUG_MODE'] : false; if (!isset($_SESSION)) { // set session ini values ini_set('session.name', SITE_KEY); ini_set('session.use_only_cookies', 1); ini_set('session.cookie_path', COOKIE_PATH); ini_set('session.gc_maxlifetime', self::SESSION_GC_TIME); if ($this->useDB) { includePackage('db'); // set the database session handlers session_set_save_handler( array($this, 'sess_open'), array($this, 'sess_close'), array($this, 'sess_read'), array($this, 'sess_write'), array($this, 'sess_destroy'), array($this, 'sess_gc') ); } else { ini_set('session.save_handler', 'files'); // make sure session directory exists if (!is_dir(CACHE_DIR . "/session")) { mkdir(CACHE_DIR . "/session", 0700, true); } ini_set('session.save_path', CACHE_DIR . "/session"); } session_start(); $this->session_id = session_id(); $_SESSION['platform'] = Kurogo::deviceClassifier()->getPlatform(); $_SESSION['pagetype'] = Kurogo::deviceClassifier()->getPagetype(); $_SESSION['user_agent'] = Kurogo::deviceClassifier()->getUserAgent(); } // see if a user is active if (isset($_SESSION['users']) && is_array($_SESSION['users'])) { $lastPing = isset($_SESSION['ping']) ? $_SESSION['ping'] : 0; $diff = time() - $lastPing; // see if max idle time has been reached if ( $this->maxIdleTime && ($diff > $this->maxIdleTime)) { // right now the user is just logged off, but we could show and error if necessary. } else { $ok = false; foreach ($_SESSION['users'] as $userData) { if ($authority = AuthenticationAuthority::getAuthenticationAuthority($userData['auth'])) { $authority->setDebugMode($this->debugMode); if ($user = $authority->getUser($userData['auth_userID'])) { $ok = true; $this->setUser($user); } else { error_log("Error trying to load user " . $userData['auth_userID']); } } } if ($ok) { return; } } } elseif ($users = $this->getLoginCookie()) { $this->login_cookie = $_COOKIE[self::TOKEN_COOKIE]; foreach ($users as $user) { $this->setUser($user); } //regenerate new login cookie $this->remainLoggedIn = true; $this->setLoginCookie(); return; } else { //anonymous user } }
function exceptionHandlerForProductionAPI(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, "API experiencing problems", "The following command 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)); } } $response = new APIResponse(); $response->setVersion(0); $response->setError(new KurogoError($exception->getCode(), "Error", "An error has occurred")); $response->display(); }
public function initializeForCommand() { if ($projection = $this->getArg('projection')) { $this->mapProjector = new MapProjector(); $this->mapProjector->setDstProj($projection); } switch ($this->command) { case 'index': $categories = array(); $response = array('displayType' => $this->getModuleDisplayType()); $groups = $this->getFeedGroups(); if ($groups) { foreach ($groups as $id => &$groupData) { if (isset($groupData['center'])) { $latlon = filterLatLon($groupData['center']); $groupData['lat'] = $latlon['lat']; $groupData['lon'] = $latlon['lon']; } $groupData['id'] = $id; $categories[] = $groupData; } $response['categories'] = $categories; } else { $feeds = $this->loadFeedData(); foreach ($feeds as $id => $feedData) { $categories[] = array('title' => $feedData['TITLE'], 'subtitle' => $feedData['SUBTITLE'], 'id' => $id); } } $this->setResponse($response); $this->setResponseVersion(1); break; case 'category': $this->loadFeedData(); $categoryId = $this->getArg('category'); $groups = $this->getFeedGroups(); if (isset($groups[$categoryId])) { $this->feedGroup = $categoryId; $groupData = $this->loadFeedData(); $categories = array(); foreach ($groupData as $id => $feed) { if (!isset($feed['HIDDEN']) || !$feed['HIDDEN']) { $category = array('id' => $id, 'title' => $feed['TITLE']); if (isset($feed['SUBTITLE'])) { $category['subtitle'] = $feed['SUBTITLE']; } $categories[] = $category; } } $response = array('categories' => $categories); $this->setResponse($response); $this->setResponseVersion(1); } else { $controller = $this->getDataModel(); if ($controller) { //if ($categoryId) { // $category = $controller->findCategory($categoryId); // $placemarks = $category->placemarks(); // $categories = $category->categories(); //} else { $placemarks = $controller->placemarks(); $categories = $controller->categories(); //} if ($placemarks) { $response['placemarks'] = array(); foreach ($placemarks as $placemark) { $response['placemarks'][] = $this->arrayFromPlacemark($placemark); } } if ($categories) { foreach ($categories as $aCategory) { $response['categories'][] = $this->arrayFromCategory($aCategory); } } if (!$placemarks && !$categories) { // need something in the response so that it will be // output as a JSON object rather than a JSON array $response = array('categories' => array()); } $this->setResponse($response); $this->setResponseVersion(1); } else { $error = new KurogoError("Could not find data source for requested category"); $this->throwError($error); } } break; case 'detail': $suppress = $this->getOptionalModuleVar('suppress', array(), 'details', 'page-detail'); $tabKeys = $this->getOptionalModuleVar('tabkeys', array(), 'tabs', 'page-detail'); $controller = $this->getDataModel(); $placemarkId = $this->getArg('id', null); if ($controller && $placemarkId !== null) { $placemarks = $controller->selectPlacemark($placemarkId); $placemark = current($placemarks); $fields = $placemark->getFields(); $geometry = $placemark->getGeometry(); $tabs = $this->getTabsForTabKeys($tabKeys, $this->command); $response = array('sections' => $tabs, 'id' => $placemarkId, 'title' => $placemark->getTitle(), 'subtitle' => $placemark->getSubtitle(), 'address' => $placemark->getAddress()); if ($this->requestedVersion >= 2) { $response['description'] = $placemark->getDescription($suppress); $responseVersion = 2; } else { $response['details'] = array('description' => $placemark->getDescription($suppress)); $photoURL = $placemark->getField('PhotoURL'); if ($photoURL) { $response['photoURL'] = $photoURL; } $responseVersion = 1; } if ($geometry) { $center = $geometry->getCenterCoordinate(); $response['lat'] = $center['lat']; $response['lon'] = $center['lon']; $response['geometryType'] = $this->getGeometryType($geometry); $response['geometry'] = $this->formatGeometry($geometry); } $this->setResponse($response); $this->setResponseVersion($responseVersion); } break; case 'search': $mapSearch = $this->getSearchClass($this->args); $lat = $this->getArg('lat', 0); $lon = $this->getArg('lon', 0); if ($lat || $lon) { // defaults values for proximity search $tolerance = 1000; $maxItems = 0; // check for settings in feedgroup config $configData = $this->getDataForGroup($this->feedGroup); if ($configData) { if (isset($configData['NEARBY_THRESHOLD'])) { $tolerance = $configData['NEARBY_THRESHOLD']; } if (isset($configData['NEARBY_ITEMS'])) { $maxItems = $configData['NEARBY_ITEMS']; } } // check for override settings in feeds $configData = $this->getCurrentFeed(); if (isset($configData['NEARBY_THRESHOLD'])) { $tolerance = $configData['NEARBY_THRESHOLD']; } if (isset($configData['NEARBY_ITEMS'])) { $maxItems = $configData['NEARBY_ITEMS']; } $searchResults = $mapSearch->searchByProximity(array('lat' => $lat, 'lon' => $lon), 1000, 10); } else { if ($searchTerms = $this->getArg(array('filter', 'q'))) { $this->setLogData($searchTerms); $searchResults = $mapSearch->searchCampusMap($searchTerms); } } $provider = null; if ($this->requestedVersion >= 2 && $this->getArg('provider', null)) { $providerId = $this->getArg('provider'); switch ($providerId) { case 'google': $provider = new GoogleJSMap(); break; case 'esri': $provider = new ArcGISJSMap(); break; } if ($provider && $projection) { $provider->setMapProjection($projection); } } $places = array(); foreach ($searchResults as $result) { if ($this->requestedVersion >= 2) { $place = array('attribs' => $this->shortArrayFromPlacemark($result)); } else { $place = $this->shortArrayFromPlacemark($result); } if ($provider) { if ($result instanceof MapPolygon) { $place['placemark'] = $provider->jsObjectForPolygon($result); } elseif ($result instanceof MapPolyline) { $place['placemark'] = $provider->jsObjectForPath($result); } else { $place['placemark'] = $provider->jsObjectForMarker($result); } } $places[] = $place; } $response = array('total' => count($places), 'returned' => count($places), 'results' => $places); $this->setResponse($response); $this->setResponseVersion(1); break; // ajax calls // ajax calls case 'projectPoint': $lat = $this->getArg('lat', 0); $lon = $this->getArg('lon', 0); $fromProj = $this->getArg('from', GEOGRAPHIC_PROJECTION); $toProj = $this->getArg('to', GEOGRAPHIC_PROJECTION); $projector = new MapProjector(); $projector->setSrcProj($fromProj); $projector->setDstProj($toProj); $result = $projector->projectPoint(array('lat' => $lat, 'lon' => $lon)); $this->setResponse($result); $this->setResponseVersion(1); break; case 'sortGroupsByDistance': $lat = $this->getArg('lat', 0); $lon = $this->getArg('lon', 0); $categories = array(); $showDistances = $this->getOptionalModuleVar('SHOW_DISTANCES', true); if ($lat || $lon) { foreach ($this->getFeedGroups() as $id => $groupData) { $center = filterLatLon($groupData['center']); $distance = greatCircleDistance($lat, $lon, $center['lat'], $center['lon']); $category = array('title' => $groupData['title'], 'id' => $id); if ($showDistances && ($displayText = $this->displayTextFromMeters($distance))) { $category['distance'] = $displayText; } $categories[] = $category; $distances[] = $distance; } array_multisort($distances, SORT_ASC, $categories); } $this->setResponse($categories); $this->setResponseVersion(1); break; case 'staticImageURL': $params = array('STATIC_MAP_BASE_URL' => $this->getArg('baseURL'), 'STATIC_MAP_CLASS' => $this->getArg('mapClass')); $dc = Kurogo::deviceClassifier(); $mapDevice = new MapDevice($dc->getPagetype(), $dc->getPlatform()); $mapController = MapImageController::factory($params, $mapDevice); if (!$mapController->isStatic()) { $error = new KurogoError(0, "staticImageURL must be used with a StaticMapImageController subclass"); $this->throwError($error); } $currentQuery = $this->getArg('query'); $mapController->parseQuery($currentQuery); $overrides = $this->getArg('overrides'); $mapController->parseQuery($overrides); $zoomDir = $this->getArg('zoom'); if ($zoomDir == 1 || $zoomDir == 'in') { $level = $mapController->getLevelForZooming('in'); $mapController->setZoomLevel($level); } elseif ($zoomDir == -1 || $zoomDir == 'out') { $level = $mapController->getLevelForZooming('out'); $mapController->setZoomLevel($level); } $scrollDir = $this->getArg('scroll'); if ($scrollDir) { $center = $mapController->getCenterForPanning($scrollDir); $mapController->setCenter($center); } $url = $mapController->getImageURL(); $this->setResponse($url); $this->setResponseVersion(1); break; case 'geocode': // TODO: this is not fully implemented. do not use this API. includePackage('Maps', 'Geocoding'); $locationSearchTerms = $this->getArg('q'); $geocodingDataRetrieverClass = $this->getOptionalModuleVar('GEOCODING_DATA_RETRIEVER_CLASS'); $geocodingDataParserClass = $this->getOptionalModuleVar('GEOCODING_DATA_PARSER_CLASS'); $geocoding_base_url = $this->getOptionalModuleVar('GEOCODING_BASE_URL'); $arguments = array('BASE_URL' => $geocoding_base_url, 'CACHE_LIFETIME' => 86400, 'PARSER_CLASS' => $geocodingDataParserClass); $controller = DataRetriever::factory($geocodingDataRetrieverClass, $arguments); $controller->addCustomFilters($locationSearchTerms); $response = $controller->getParsedData(); // checking for Geocoding service error if ($response['errorCode'] == 0) { unset($response['errorCode']); unset($response['errorMessage']); $this->setResponse($response); $this->setResponseVersion(1); } else { $kurogoError = new KurogoError($response['errorCode'], "Geocoding service Erroe", $response['errorMessage']); $this->setResponseError($kurogoError); $this->setResponseVersion(1); } break; default: $this->invalidCommand(); break; } }
* @package Minify */ /** */ if (!isset($Kurogo)) { require_once realpath(dirname(__FILE__) . '/../../lib/Kurogo.php'); $Kurogo = Kurogo::sharedInstance(); // Configure web application $path = $_SERVER['REQUEST_URI']; $Kurogo->initialize($path); } // Minify cache ids for groups contain the list of source files, not the group id. // However Minify's cache ids do contain a serialized copy of the 'minifierOptions' field. // Use this to make sure there is a unique cache entry for each device class // allowing us to put device-specific content inside javascript and css files $min_serveOptions['minifierOptions']['kurogo']['device'] = Kurogo::deviceClassifier()->getDevice(); require_once LIB_DIR . '/minify.php'; /** * Configuration for default Minify application * @package Minify */ /** * In 'debug' mode, Minify can combine files with no minification and * add comments to indicate line #s of the original files. * * To allow debugging, set this option to true and add "&debug=1" to * a URI. E.g. /min/?f=script1.js,script2.js&debug=1 */ $min_allowDebugFlag = true; /** * Set to true to log messages to FirePHP (Firefox Firebug addon).
function __construct() { parent::__construct(); // Fix this in a later release -- currently generates lots of warnings $this->error_reporting = E_ALL & ~E_NOTICE; // Device info $pagetype = Kurogo::deviceClassifier()->getPagetype(); $platform = Kurogo::deviceClassifier()->getPlatform(); $browser = Kurogo::deviceClassifier()->getBrowser(); // Smarty configuration $this->setCompileDir(CACHE_DIR . '/smarty/templates'); $this->setCacheDir(CACHE_DIR . '/smarty/html'); $this->setCompileId("{$pagetype}-{$platform}-{$browser}"); $className = get_class($this); $this->registerPlugin('modifier', 'sanitize_html', array($this, 'smartyModifierSanitizeHTML')); $this->registerPlugin('modifier', 'sanitize_url', array($this, 'smartyModifierSanitizeURL')); // findInclude is a resource $this->registerResource('findInclude', array(array($this, 'smartyResourceIncludeGetSource'), array($this, 'smartyResourceIncludeGetTimestamp'), array($this, 'smartyResourceIncludeGetSecure'), array($this, 'smartyResourceIncludeGetTrusted'))); // findExtends is a pre and post filter $this->registerFilter('pre', array($this, 'smartyPrefilterHandleExtends')); $this->registerFilter('post', array($this, 'smartyPostfilterHandleExtends')); // Postfilter to add url prefix to absolute urls and // strip unnecessary whitespace (ignores <pre>, <script>, etc) $this->registerFilter('output', array($this, 'smartyOutputfilterAddURLPrefixAndStripWhitespace')); $this->registerPlugin('block', 'html_access_key_link', array($this, 'smartyBlockAccessKeyLink')); $this->registerPlugin('function', 'html_access_key_reset', array($this, 'smartyTemplateAccessKeyReset')); $this->registerPlugin('modifier', 'nosecure', array($this, 'nosecure')); // variables common to all modules $this->assign('pagetype', $pagetype); $this->assign('platform', $platform); $this->assign('browser', $browser); $this->assign('deviceOverride', Kurogo::deviceClassifier()->getOverride()); $this->assign('showDeviceDetection', Kurogo::getSiteVar('DEVICE_DETECTION_DEBUG')); $this->assign('moduleDebug', Kurogo::getSiteVar('MODULE_DEBUG')); }