protected function getIncludeFile($name) { $subDir = dirname($name); $page = basename($name, '.tpl'); $pagetype = Kurogo::deviceClassifier()->getPagetype(); $platform = Kurogo::deviceClassifier()->getPlatform(); $browser = Kurogo::deviceClassifier()->getBrowser(); if (strlen($subDir)) { $subDir .= '/'; } $checkDirs = array('THEME_DIR' => THEME_DIR, 'SITE_APP_DIR' => SITE_APP_DIR, 'SHARED_APP_DIR' => SHARED_APP_DIR, 'APP_DIR' => APP_DIR); $searchFiles = DeviceClassifier::buildFileSearchList($pagetype, $platform, $browser, $page, 'tpl'); foreach ($searchFiles as $file) { foreach ($checkDirs as $type => $dir) { if ($dir) { $test = realpath_exists("{$dir}/{$subDir}{$file}"); if ($test) { Kurogo::log(LOG_DEBUG, __FUNCTION__ . "({$pagetype}-{$platform}-{$browser}) choosing '{$type}/{$file}' for '{$name}'", 'template'); return addslashes($test); } } } } return $name; }
function getFileConfigForDirs($ext, $extFolder, $page, $pagetype, $platform, $browser, $dirs, $subDirs, $pageOnly = false) { $config = array('include' => 'all', 'files' => array()); foreach ($dirs as $dir) { foreach ($subDirs as $subDir) { $fullDir = "{$dir}{$subDir}/{$extFolder}/"; if (!$pageOnly) { $commonFiles = array_reverse(DeviceClassifier::buildFileSearchList($pagetype, $platform, $browser, '', $ext, $fullDir)); $config['files'] = array_merge($config['files'], $commonFiles); } $pageFiles = array_reverse(DeviceClassifier::buildFileSearchList($pagetype, $platform, $browser, $page, $ext, $fullDir)); $config['files'] = array_merge($config['files'], $pageFiles); } } return $config; }
public function canPlay(DeviceClassifier $deviceClassifier) { if (in_array($deviceClassifier->getPlatform(), array('blackberry', 'bbplus'))) { return false; } return true; }
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(); }
public function canPlay(DeviceClassifier $deviceClassifier) { if (in_array($deviceClassifier->getPlatform(), array('blackberry', 'bbplus'))) { return $this->getStreamingURL(); } return true; }