public static function formatDate($date, $dateStyle, $timeStyle) { $dateStyleConstant = self::getDateConstant($dateStyle); $timeStyleConstant = self::getTimeConstant($timeStyle); if ($date instanceof DateTime) { $date = $date->format('U'); } $string = ''; if ($dateStyleConstant) { $string .= strftime(Kurogo::getLocalizedString($dateStyleConstant), $date); if ($timeStyleConstant) { $string .= " "; } } if ($timeStyleConstant) { // Work around lack of %P support in Mac OS X $format = Kurogo::getLocalizedString($timeStyleConstant); $lowercase = false; if (strpos($format, '%P') !== false) { $format = str_replace('%P', '%p', $format); $lowercase = true; } $formatted = strftime($format, $date); if ($lowercase) { $formatted = strtolower($formatted); } // Work around leading spaces that come from use of %l (but don't exist in date()) if (strpos($format, '%l') !== false) { $formatted = trim($formatted); } $string .= $formatted; } return $string; }
public static function formatDate($date, $dateStyle, $timeStyle) { $dateStyleConstant = self::getDateConstant($dateStyle); $timeStyleConstant = self::getTimeConstant($timeStyle); if ($date instanceof DateTime) { $date = $date->format('U'); } $string = ''; if ($dateStyleConstant) { $string .= strftime(Kurogo::getLocalizedString($dateStyleConstant), $date); if ($timeStyleConstant) { $string .= " "; } } if ($timeStyleConstant) { $string .= strftime(Kurogo::getLocalizedString($timeStyleConstant), $date); } return $string; }
public static function formatDate($date, $dateStyle, $timeStyle) { $dateStyleConstant = self::getDateConstant($dateStyle); $timeStyleConstant = self::getTimeConstant($timeStyle); if ($date instanceof DateTime) { $date = $date->format('U'); } $string = ''; if ($dateStyleConstant) { $format = Kurogo::getLocalizedString($dateStyleConstant); // Work around lack of %e support in windows // http://php.net/manual/en/function.strftime.php if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { $format = preg_replace('#(?<!%)((?:%%)*)%e#', '\\1%#d', $format); } $string .= strftime($format, $date); if ($timeStyleConstant) { $string .= " "; } } if ($timeStyleConstant) { // Work around lack of %P support in Mac OS X $format = Kurogo::getLocalizedString($timeStyleConstant); $lowercase = false; if (strpos($format, '%P') !== false) { $format = str_replace('%P', '%p', $format); $lowercase = true; } $formatted = strftime($format, $date); if ($lowercase) { $formatted = strtolower($formatted); } // Work around leading spaces that come from use of %l (but don't exist in date()) if (strpos($format, '%l') !== false) { $formatted = trim($formatted); } $string .= $formatted; } return $string; }
public static function formatDate($date, $dateStyle = self::DEFAULT_STYLE, $timeStyle = self::DEFAULT_STYLE) { if ($dateStyle === self::DEFAULT_STYLE) { $dateStyle = self::MEDIUM_STYLE; } if ($timeStyle === self::DEFAULT_STYLE) { $timeStyle = self::MEDIUM_STYLE; } $dateStyleConstant = self::getDateConstant($dateStyle); $timeStyleConstant = self::getTimeConstant($timeStyle); $timestamp = $date instanceof DateTime ? $date->format('U') : $date; $dateFormat = null; if ($dateStyleConstant) { if ($dateStyleConstant == 'SHORT_DATE_FORMAT' && date('Y') != date('Y', $timestamp)) { $dateStyleConstant .= "_YEAR"; } $dateFormat = Kurogo::getLocalizedString($dateStyleConstant); } $timeFormat = null; if ($timeStyleConstant) { $timeFormat = Kurogo::getLocalizedString($timeStyleConstant); } return self::formatDateUsingFormat($date, $dateFormat, $timeFormat); }
/** * Factory method. Used to instantiate a subclass * @param string $id, the module id to load * @param string $type, the type of module to load (web/api) */ public static function factory($id, $type = null) { Kurogo::log(LOG_INFO, "Initializing {$type} module {$id}", 'module'); $configModule = $id; //attempt to load config/$id/module.ini if ($config = ModuleConfigFile::factory($id, 'module', ModuleConfigFile::OPTION_DO_NOT_CREATE)) { //use the ID parameter if it's present, otherwise use the included id $id = $config->getOptionalVar('id', $id); } elseif (!Kurogo::getOptionalSiteVar('CREATE_DEFAULT_CONFIG', false, 'modules')) { Kurogo::log(LOG_ERR, "Module config file not found for module {$id}", 'module'); throw new KurogoModuleNotFound(Kurogo::getLocalizedString('ERROR_MODULE_NOT_FOUND', $id)); } // see if the class location has been cached if ($moduleFile = Kurogo::getCache(self::cacheKey($id, $type))) { $className = basename($moduleFile, '.php'); include_once $moduleFile; $module = new $className(); $module->setConfigModule($configModule); if ($config) { $module->setConfig('module', $config); } return $module; } // when run without a type it will find either $classNames = array('web' => ucfirst($id) . 'WebModule', 'api' => ucfirst($id) . 'APIModule'); // if we specified a type, include only that type in the array if ($type) { if (isset($classNames[$type])) { $classNames = array($classNames[$type]); } else { throw new KurogoException("Invalid module type {$type}"); } } // possible module paths. // 1. Site Folder SiteMODULEIDXXXModule // 2. Site Folder MODULEIDXXXModule // 3. Project folder MODULEIDXXXModule $modulePaths = array(SITE_MODULES_DIR . "/{$id}/Site%s.php" => "Site%s", SITE_MODULES_DIR . "/{$id}/%s.php" => "%s", MODULES_DIR . "/{$id}/%s.php" => "%s"); //cycle module paths foreach ($modulePaths as $path => $className) { //cycle class names to find a valid module foreach ($classNames as $class) { $className = sprintf($className, $class); $path = sprintf($path, $class); Kurogo::log(LOG_DEBUG, "Looking for {$path} for {$id}", 'module'); // see if it exists $moduleFile = realpath_exists($path); if ($moduleFile && (include_once $moduleFile)) { //found it $info = new ReflectionClass($className); if (!$info->isAbstract()) { Kurogo::log(LOG_INFO, "Found {$moduleFile} for {$id}", 'module'); $module = new $className(); $module->setConfigModule($configModule); if ($config) { $module->setConfig('module', $config); } // cache the location of the class (which also includes the classname) Kurogo::setCache(self::cacheKey($id, $type), $moduleFile); return $module; } Kurogo::log(LOG_NOTICE, "{$class} found at {$moduleFile} is abstract and cannot be used for {$id}", 'module'); return false; } } } Kurogo::log(LOG_ERR, "No valid class found for module {$id}", 'module'); throw new KurogoModuleNotFound(Kurogo::getLocalizedString('ERROR_MODULE_NOT_FOUND', $id)); }
/** * Factory method. Used to instantiate a subclass * @param string $id, the module id to load * @param string $type, the type of module to load (web/api) */ public static function factory($id, $type = null) { if ($id == 'kurogo') { set_exception_handler("exceptionHandlerForError"); } if (!self::isValidModuleName($id)) { throw new KurogoException(Kurogo::getLocalizedString('ERROR_INVALID_MODULE')); } Kurogo::log(LOG_INFO, "Initializing {$type} module {$id}", 'module'); $configModule = $id; $configStore = Kurogo::configStore(); //attempt to load config/$id/module.ini if ($moduleData = $configStore->getOptionalSection('module', 'module', $configModule)) { $id = Kurogo::arrayVal($moduleData, 'id', $configModule); } else { throw new KurogoModuleNotFound(Kurogo::getLocalizedString('ERROR_MODULE_NOT_FOUND', $id)); } // see if the class location has been cached if ($moduleFile = Kurogo::getCache(self::cacheKey($id, $type))) { $className = basename($moduleFile, '.php'); include_once $moduleFile; $module = new $className(); if (is_a($module, KurogoWebBridge::STUB_API_CLASS)) { $module->setID($id); } $module->setConfigModule($configModule); Kurogo::addModuleLib($id); return $module; } // when run without a type it will find either $classNames = array('web' => ucfirst($id) . 'WebModule', 'api' => ucfirst($id) . 'APIModule', 'shell' => ucfirst($id) . 'ShellModule'); // if we specified a type, include only that type in the array if ($type) { if (isset($classNames[$type])) { $classNames = array($classNames[$type]); } else { throw new KurogoException("Invalid module type {$type}"); } } // possible module paths. // 1. Site Folder SiteMODULEIDXXXModule // 2. Site Folder MODULEIDXXXModule // 3. Project folder MODULEIDXXXModule // Note: The PHP class name MUST be the basename of the file path. $modulePaths = array(SITE_MODULES_DIR . "/{$id}/Site%s.php", SITE_MODULES_DIR . "/{$id}/%s.php", SHARED_MODULES_DIR . "/{$id}/Site%s.php", SHARED_MODULES_DIR . "/{$id}/%s.php", MODULES_DIR . "/{$id}/%s.php"); if ($type == 'api' && KurogoWebBridge::moduleHasMediaAssets($configModule)) { $modulePaths[] = LIB_DIR . '/' . KurogoWebBridge::STUB_API_CLASS . ".php"; } //cycle module paths foreach ($modulePaths as $path) { $className = basename($path, '.php'); //cycle class names to find a valid module foreach ($classNames as $class) { $className = sprintf($className, $class); $path = sprintf($path, $class); Kurogo::log(LOG_DEBUG, "Looking for {$path} for {$id}", 'module'); // see if it exists $moduleFile = realpath_exists($path); if ($moduleFile && (include_once $moduleFile)) { //found it $info = new ReflectionClass($className); if (!$info->isAbstract()) { Kurogo::log(LOG_INFO, "Found {$moduleFile} for {$id}", 'module'); $module = new $className(); if (is_a($module, KurogoWebBridge::STUB_API_CLASS)) { $module->setID($id); } $module->setConfigModule($configModule); // cache the location of the class (which also includes the classname) Kurogo::setCache(self::cacheKey($id, $type), $moduleFile); Kurogo::addModuleLib($id); return $module; } Kurogo::log(LOG_NOTICE, "{$class} found at {$moduleFile} is abstract and cannot be used for {$id}", 'module'); return false; } } } Kurogo::log(LOG_NOTICE, "No valid {$type} class found for module {$id}", 'module'); throw new KurogoModuleNotFound(Kurogo::getLocalizedString('ERROR_MODULE_NOT_FOUND', $id)); }
public static function getDeviceDetectionTypes() { return array(0 => Kurogo::getLocalizedString('DEVICE_DETECTION_INTERNAL'), 1 => Kurogo::getLocalizedString('DEVICE_DETECTION_EXTERNAL')); }
protected function generateErrorMessage($error_code) { $error_codes = array(LDAP_SIZELIMIT_EXCEEDED => 'ERROR_TOO_MANY_RESULTS', LDAP_PARTIAL_RESULTS => 'ERROR_TOO_MANY_RESULTS', LDAP_TIMELIMIT_EXCEEDED => 'ERROR_SERVER', LDAP_INSUFFICIENT_ACCESS => 'ERROR_SERVER', LDAP_ADMINLIMIT_EXCEEDED => 'ERROR_TOO_MANY_RESULTS'); $key = isset($error_codes[$error_code]) ? $error_codes[$error_code] : 'ERROR_GENERIC_SERVER_ERROR'; return Kurogo::getLocalizedString($key, $error_code, ldap_err2str($error_code)); }
private function loadPageConfig() { if (!isset($this->pageConfig)) { Kurogo::log(LOG_DEBUG, "Loading page configuration for {$this->configModule} - {$this->page}", 'module'); $this->setPageTitle($this->moduleName); // Load site configuration and help text $this->assign('strings', Kurogo::getSiteSection('strings')); // load module config file $pageData = $this->getPageData(); if (!isset($pageData[$this->page])) { throw new KurogoPageNotFoundException(Kurogo::getLocalizedString("ERROR_PAGE_NOT_FOUND", $this->page)); } $pageConfig = $pageData[$this->page]; if (KurogoWebBridge::isNativeCall()) { $this->hasWebBridgePageRefresh = self::argVal($pageConfig, 'nativePageRefresh', false); $this->hasWebBridgeAutoRefresh = self::argVal($pageConfig, 'nativePageAutoRefresh', false); } if (KurogoWebBridge::isNativeCall() && self::argVal($pageConfig, 'nativePageTitle', '')) { $this->pageTitle = $pageConfig['nativePageTitle']; } else { if (isset($pageConfig['pageTitle']) && strlen($pageConfig['pageTitle'])) { $this->pageTitle = $pageConfig['pageTitle']; } } if (KurogoWebBridge::isNativeCall() && self::argVal($pageConfig, 'nativeBreadcrumbTitle', '')) { $this->breadcrumbTitle = $pageConfig['nativeBreadcrumbTitle']; } else { if (isset($pageConfig['breadcrumbTitle']) && strlen($pageConfig['breadcrumbTitle'])) { $this->breadcrumbTitle = $pageConfig['breadcrumbTitle']; } else { $this->breadcrumbTitle = $this->pageTitle; } } if (isset($pageConfig['breadcrumbLongTitle']) && strlen($pageConfig['breadcrumbLongTitle'])) { $this->breadcrumbLongTitle = $pageConfig['breadcrumbLongTitle']; } else { $this->breadcrumbLongTitle = $this->pageTitle; } $this->pageConfig = $pageConfig; } // Ajax overrides for breadcrumb title and long title if (isset($this->args[self::AJAX_BREADCRUMB_TITLE])) { $this->breadcrumbTitle = $this->args[self::AJAX_BREADCRUMB_TITLE]; $this->breadcrumbLongTitle = $this->breadcrumbTitle; } if (isset($this->args[self::AJAX_BREADCRUMB_LONG_TITLE])) { $this->breadcrumbLongTitle = $this->args[self::AJAX_BREADCRUMB_LONG_TITLE]; } }
private static function appendTruncationSuffix(&$dom, &$node, $replacementText = null) { $text = isset($replacementText) ? $replacementText : $node->wholeText; $clipped = preg_replace('/[.\\s]*$/', '', $text); if (trim($clipped)) { $node->replaceData(0, $node->length, $clipped); $suffix = $dom->createElement('span'); $suffix->appendChild($dom->createTextNode(Kurogo::getLocalizedString('SANITIZER_HTML_TRUNCATION_SUFFIX'))); $suffix->setAttribute('class', 'trunctation-suffix'); if ($node->nextSibling) { $node->parentNode->insertBefore($suffix, $node->nextSibling); } else { $node->parentNode->appendChild($suffix); } } }