public function getIterator() { $iterator = new \AppendIterator(); // english pack is always empty since in default rdfs if ($this->langCode != 'en-US') { foreach ($this->extension->getManifest()->getInstallModelFiles() as $rdfpath) { $modelId = FileModel::getModelIdFromXml($rdfpath); $candidate = $this->extension->getDir() . 'locales' . DIRECTORY_SEPARATOR . $this->langCode . DIRECTORY_SEPARATOR . basename($rdfpath) . '.po'; if (file_exists($candidate)) { $iterator->append($this->getTriplesFromFile($candidate, $modelId)); } } } return $iterator; }
/** * Load the translation strings * * @access public * @author Jerome Bogaerts, <*****@*****.**> * @param common_ext_Extension $extension * @param string langCode * @return mixed */ public static function init(common_ext_Extension $extension, $langCode) { // if the langCode is empty do nothing if (empty($langCode)) { throw new Exception("Language is not defined"); } //init the ClearFw l10n tools l10n::init(); $basePath = $extension->getDir(); if (!empty($_GET['ext']) && is_string($_GET['ext'])) { $shownExtension = common_ext_ExtensionsManager::singleton()->getExtensionById($_GET['ext']); if (!empty($shownExtension)) { try { $basePath = $shownExtension->getDir(); $baseUrl = $shownExtension->getConstant('BASE_URL'); } catch (common_exception_Error $e) { // let the current base path be used... } } } l10n::set($basePath . 'locales' . DIRECTORY_SEPARATOR . $langCode . DIRECTORY_SEPARATOR . 'messages'); }
/** * Helper to find all controllers * * @param \common_ext_Extension $extension * @return array * @ignore */ private function getControllerClasses(\common_ext_Extension $extension) { $returnValue = array(); // routes $namespaces = array(); foreach ($extension->getManifest()->getRoutes() as $mapedPath => $ns) { $namespaces[] = trim($ns, '\\'); } if (!empty($namespaces)) { common_Logger::t('Namespace found in routes for extension ' . $extension->getId()); $classes = array(); $recDir = new RecursiveDirectoryIterator($extension->getDir()); $recIt = new RecursiveIteratorIterator($recDir); $regexIt = new RegexIterator($recIt, '/^.+\\.php$/i', RecursiveRegexIterator::GET_MATCH); foreach ($regexIt as $entry) { $info = helpers_PhpTools::getClassInfo($entry[0]); if (!empty($info['ns'])) { $ns = trim($info['ns'], '\\'); if (!empty($info['ns']) && in_array($ns, $namespaces)) { $returnValue[$info['class']] = $ns . '\\' . $info['class']; } } } } // legacy if ($extension->hasConstant('DIR_ACTIONS') && file_exists($extension->getConstant('DIR_ACTIONS'))) { $dir = new DirectoryIterator($extension->getConstant('DIR_ACTIONS')); foreach ($dir as $fileinfo) { if (preg_match('/^class\\.[^.]*\\.php$/', $fileinfo->getFilename())) { $module = substr($fileinfo->getFilename(), 6, -4); $returnValue[$module] = $extension->getId() . '_actions_' . $module; } } } // validate the classes foreach (array_keys($returnValue) as $key) { $class = $returnValue[$key]; if (!class_exists($class)) { common_Logger::w($class . ' not found'); unset($returnValue[$key]); } elseif (!is_subclass_of($class, 'Module')) { common_Logger::w($class . ' does not inherit Module'); unset($returnValue[$key]); } else { // abstract so just move along $reflection = new \ReflectionClass($class); if ($reflection->isAbstract()) { unset($returnValue[$key]); } } } return (array) $returnValue; }
/** * Helper to find all controllers * * @param \common_ext_Extension $extension * @return array * @ignore */ private function getControllerClasses(\common_ext_Extension $extension) { $returnValue = array(); // routes $namespaces = array(); foreach ($extension->getManifest()->getRoutes() as $mapedPath => $ns) { if (is_string($ns)) { $namespaces[] = trim($ns, '\\'); } } if (!empty($namespaces)) { common_Logger::t('Namespace found in routes for extension ' . $extension->getId()); $classes = array(); $recDir = new RecursiveDirectoryIterator($extension->getDir()); $recIt = new RecursiveIteratorIterator($recDir); $regexIt = new RegexIterator($recIt, '/^.+\\.php$/i', RecursiveRegexIterator::GET_MATCH); foreach ($regexIt as $entry) { $info = helpers_PhpTools::getClassInfo($entry[0]); if (!empty($info['ns'])) { $ns = trim($info['ns'], '\\'); if (!empty($info['ns']) && in_array($ns, $namespaces)) { $returnValue[$info['class']] = $ns . '\\' . $info['class']; } } } } // legacy if ($extension->hasConstant('DIR_ACTIONS') && file_exists($extension->getConstant('DIR_ACTIONS'))) { $dir = new DirectoryIterator($extension->getConstant('DIR_ACTIONS')); foreach ($dir as $fileinfo) { if (preg_match('/^class\\.[^.]*\\.php$/', $fileinfo->getFilename())) { $module = substr($fileinfo->getFilename(), 6, -4); $returnValue[$module] = $extension->getId() . '_actions_' . $module; } } } $returnValue = array_filter($returnValue, array($this, 'isControllerClassNameValid')); return (array) $returnValue; }