/** * Get db profiler object * * @return Zend_Db_Profiler_Firebug */ public function getProfiler() { if (NULL == $this->profiler) { $this->profiler = Uni_Fox::getDatabaseAdapter()->getProfiler(); } return $this->profiler; }
/** * Add resources * * @param string $module module name */ public static function addResources($module) { if ($doc = Uni_Fox::loadModuleConfig($module)) { $sourceQueue = NULL; $xPath = new DOMXPath($doc); $aclCats = $xPath->query('/config/admin/acl'); if ($aclCats->length) { foreach ($aclCats as $aclCat) { if ($aclCat->childNodes->length) { self::parseConfigACL($aclCat, $module); } else { self::parseConfigACL($module . ' Module', $module, $module . ' Module', $module . ' Module', 0, FALSE); } } } } }
/** * Get navigation html * * @return string */ public function getNavigationHtml() { $modules = Uni_Fox::getModules(); $doc = new DOMDocument(); $this->finalMenuTree = new DOMDocument(); $this->finalMenuTree->formatOutput = true; $this->root = Uni_Data_XDOMDocument::createNode('menus', NULL, $this->finalMenuTree); $this->finalMenuTree->appendChild($this->root); $this->sourceQueue = array(); $this->targetQueue = array(); if (is_array($modules)) { foreach ($modules as $module) { if ($doc->load($module['path'] . DIRECTORY_SEPARATOR . 'conf' . DIRECTORY_SEPARATOR . 'config.xml')) { $xPath = new DOMXPath($doc); $menus = $xPath->query('/config/admin/menus'); if ($menus->length > 0) { foreach ($menus as $menu) { $this->getFinalMenuTree($menu); } } } } } if (isset($this->finalMenuTree) && $this->root->hasChildNodes()) { $this->optimizeMenuTree(); $this->mnuDoc = new DOMDocument(); $this->mnuDoc->formatOutput = true; $this->mnuRoot = Uni_Data_XDOMDocument::createNode('ul', array('class' => 'admin-nav-menu'), $this->mnuDoc); $this->mnuDoc->appendChild($this->mnuRoot); $this->createMenu($this->root); if (isset($this->mnuDoc)) { $this->menuHTML = $this->mnuDoc->saveXML($this->mnuRoot); return $this->menuHTML; } } }
/** * * @param array $paths * @param string $class * @param string $infix * @param int $pos * @return mixed Object of requested class or FALSE if not found */ public static function instantiate($paths, $class, $infix, $pos) { if (strpos($class, '/') === FALSE) { $fqcn = $class; $cpath = str_replace('_', DS, $class); } else { $classParts = explode('/', $class); $module = ucfirst($classParts[0]); if (!isset(self::$moduleInfo[$module])) { $modules = Uni_Fox::getModules(); self::$moduleInfo[$module]['namespace'] = $modules[$module]['namespace']; } $fqcn = self::$moduleInfo[$module]['namespace']; $cpath = self::$moduleInfo[$module]['namespace']; for ($i = 0; $i < count($classParts); $i++) { if ($i == $pos) { $fqcn = $fqcn . '_' . ucfirst($infix); $cpath = $cpath . DS . ucfirst($infix); } $fqcn = $fqcn . '_' . ucfirst($classParts[$i]); $cpath = $cpath . DS . ucfirst($classParts[$i]); } } while (count($paths)) { $path = array_pop($paths); $fcpath = $path . DS . $cpath . '.php'; if (file_exists($fcpath)) { require_once $fcpath; if (class_exists($fqcn)) { return new $fqcn(); } } else { } } return FALSE; }
/** * Loads and initializes zendfox module system * * @param Zend_Controller_Front $front * @return array */ private static function loadNamespacesAndModules(Zend_Controller_Front $front, $bootS) { if (null == self::$modules) { self::$modules = array(); $loader = Zend_Loader_Autoloader::getInstance(); if ((self::$modules = self::$cache->load('fox_modules')) === false) { $dbConf = $bootS->db->getConfig(); if (self::$modeRun) { $mData = self::$dbAdapter->fetchAll("SELECT * FROM {$dbConf['prefix']}core_module"); foreach ($mData as $mInfo) { $name = trim($mInfo['name']); $enabled = trim($mInfo['status']); $package = trim($mInfo['package']); $nameSpc = trim($mInfo['namespace']); if ($name != '' && $enabled == 1 && $package != '' && $nameSpc != '') { $moduleDir = APPLICATION_PATH . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $package . DIRECTORY_SEPARATOR . $nameSpc . DIRECTORY_SEPARATOR . $name; self::$modules[$name]['path'] = $moduleDir; self::$modules[$name]['namespace'] = $nameSpc; } } //Caching module info self::$cache->save(self::$modules, 'fox_modules'); } else { // ********Reading Module info from XML files**********************/ $doc = new DOMDocument(); if (is_dir(MODULE_CONFIG_DIR)) { $dp = opendir(MODULE_CONFIG_DIR); while ($file = readdir($dp)) { if (!($file == '.' || $file == '..')) { $fPath = MODULE_CONFIG_DIR . DIRECTORY_SEPARATOR . $file; if (is_readable($fPath) && is_file($fPath)) { $doc->load($fPath); if ($doc->documentElement->childNodes) { $nList = $doc->documentElement->childNodes; foreach ($nList as $n) { if ($n->nodeName == 'module' && ($name = $n->getAttribute('name')) && ($enabled = $n->getAttribute('enabled') === 'true') && ($package = $n->getAttribute('package')) && ($nameSpc = $n->getAttribute('namespace'))) { if ($enabled) { $moduleDir = APPLICATION_PATH . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $package . DIRECTORY_SEPARATOR . $nameSpc . DIRECTORY_SEPARATOR . $name; self::$modules[$name]['path'] = $moduleDir; self::$modules[$name]['namespace'] = $nameSpc; } } } } } } } } /* * ****End Reading module info from XML files************** */ } } $ns = array(); foreach (self::$modules as $name => $module) { $moduleDir = $module['path']; $nameSpc = $module['namespace']; if (!in_array($nameSpc, $ns)) { $loader->registerNamespace($nameSpc . '_'); $ns[] = $nameSpc; } $front->addControllerDirectory($moduleDir . DIRECTORY_SEPARATOR . 'controllers', $name); //Translation loading if (NULL == self::$translator) { self::$translator = new Zend_Translate(array('adapter' => 'csv', 'locale' => 'auto')); Zend_Registry::set('translator', self::$translator); // self::$translator->setLocale(Zend_Registry::get('Zend_Locale')); } $langDir = $moduleDir . DIRECTORY_SEPARATOR . 'lang' . DIRECTORY_SEPARATOR; if (file_exists($langDir)) { self::$translator->addTranslation(array('content' => $langDir, 'scan' => Zend_Translate::LOCALE_FILENAME)); } } unset($ns); } }
/** * Database configuration post action */ public function configurePostAction() { $error = FALSE; $data = array(); try { if ($this->getRequest()->isPost()) { $data = $this->getRequest()->getPost(); Fox::getModel('installer/session')->setConfiguration($data); $hostName = $data['db_host']; $dbName = $data['db_name']; $userName = $data['db_username']; $password = $data['db_password']; $dbAdapter = Zend_Db::factory('Pdo_Mysql', array('host' => $hostName, 'username' => $userName, 'password' => $password, 'dbname' => $dbName)); if (!$dbAdapter->getConnection()) { throw new Exception('Databse connection failed'); } Zend_Db_Table_Abstract::setDefaultAdapter($dbAdapter); Uni_Fox::setDatabaseAdapter($dbAdapter); Uni_Core_Installer::runInstaller(); $this->sendRedirect('*/wizard/administrator'); return; } } catch (Exception $e) { Fox::getHelper('core/message')->setError($e->getMessage()); } $this->sendRedirect('*/wizard/configure', array('locale' => urlencode(Fox::getModel('installer/session')->getLocale()), 'timezone' => urlencode(Fox::getModel('installer/session')->getTimezone()))); }
* * @category Fox * @package Fox * @author Unicode Systems Zendfox Core Team <*****@*****.**> */ /** * Error reporting */ ini_set('display_errors', 0); error_reporting(E_ALL & ~E_STRICT & ~E_WARNING); /** * Define path to application directory */ defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/application')); /** * Define application environment */ defined('APPLICATION_ENV') || define('APPLICATION_ENV', getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'development'); /** * Ensure library is on include_path */ set_include_path(implode(PATH_SEPARATOR, array(realpath(APPLICATION_PATH . '/../library'), get_include_path()))); /** * @see Uni_Fox */ require_once 'Uni/Fox.php'; /** * Run Fox Framework */ Uni_Fox::runApp();
/** * Loades layout defined for particular action * * @param string $layoutUpdate * @param string $updateKey * @return void */ public function load($layoutUpdate = NULL, $updateKey = NULL) { $this->finalLayout = new Uni_Data_XDOMDocument(); $this->finalLayout->preserveWhiteSpace = FALSE; $this->finalLayout->formatOutput = TRUE; $ds = DIRECTORY_SEPARATOR; $debug = FALSE; if (Uni_Core_Installer::isInstalled()) { $cacheSettings = Uni_Core_CacheManager::loadCacheSettings(); $isCacheEnabled = isset($cacheSettings[Fox_Core_Model_Cache::CACHE_CODE_LAYOUT]) ? $cacheSettings[Fox_Core_Model_Cache::CACHE_CODE_LAYOUT] : FALSE; $cacheLayoutBasePath = CACHE_DIR . $ds . Fox_Core_Model_Cache::CACHE_CODE_LAYOUT . $ds . $this->mode . $ds . $this->package . $ds . $this->theme; file_exists($cacheLayoutBasePath) && is_dir($cacheLayoutBasePath) || @mkdir($cacheLayoutBasePath, 0777, TRUE); $cacheLayoutPath = $cacheLayoutBasePath . $ds . strtolower($this->module) . '_' . strtolower($this->controller) . '_' . strtolower($this->action) . (isset($updateKey) ? '_' . urlencode($updateKey) : '') . '.lxml'; } else { $isCacheEnabled = FALSE; } if (!$isCacheEnabled || $isCacheEnabled && !file_exists($cacheLayoutPath)) { $debug || ob_start(); $this->layout = new Uni_Core_Layout(); $this->layout->init(); $lPaths[] = 'application' . $ds . 'views' . $ds . $this->mode . $ds . $this->package . $ds . $this->theme . $ds . 'layout'; $lPaths[] = 'application' . $ds . 'views' . $ds . $this->mode . $ds . $this->defaultPackage . $ds . $this->defaultTheme . $ds . 'layout'; $loadLayout = FALSE; foreach ($lPaths as $lBPath) { if (file_exists($lBPath . $ds . 'fox.xml')) { $lDPath = $lBPath . $ds . 'fox.xml'; break; } } if (isset($lDPath)) { $this->xDomFox = new Uni_Data_XDOMDocument(); $this->xDomFox->load($lDPath); } else { throw new Exception('Layout not found "' . $lDPath . '"'); } $this->layout->setLayout($this->xDomFox); /* * **************Parsing default Section from all other layouts************** */ $modules = array_keys(Uni_Fox::getModules()); foreach ($modules as $module) { if ($module != $this->module) { foreach ($lPaths as $lBPath) { if (file_exists($lBPath . $ds . lcfirst($module) . '.xml')) { $lPath = $lBPath . $ds . lcfirst($module) . '.xml'; break; } } if (isset($lPath)) { $mLXmlDoc = new Uni_Data_XDOMDocument(); $mLXmlDoc->load($lPath); $xpMLXmlDoc = new DOMXPath($mLXmlDoc); $defMLXml = $xpMLXmlDoc->query('/' . self::ROOT . '/global'); if ($defMLXml->length > 0) { $this->layout->mergeLayout($defMLXml->item(0), TRUE); $this->layout->showXML(); } unset($lPath); } } } foreach ($lPaths as $lBPath) { if (file_exists($lBPath . $ds . lcfirst($this->module) . '.xml')) { $lPath = $lBPath . $ds . lcfirst($this->module) . '.xml'; break; } } if (isset($lPath)) { $this->xDomMain = new Uni_Data_XDOMDocument(); $this->xDomMain->load($lPath); } else { throw new Exception('Layout not found "' . $lPath . '"'); } $xpMain = new DOMXPath($this->xDomMain); $defGlobal = $xpMain->query('/' . self::ROOT . '/global'); if ($defGlobal->length > 0) { $this->layout->mergeLayout($defGlobal->item(0), TRUE); } $defMain = $xpMain->query('/' . self::ROOT . '/default'); if ($defMain->length > 0) { $this->layout->mergeLayout($defMain->item(0), TRUE); } $actMain = $xpMain->query('/' . self::ROOT . '/' . $this->controller . '_' . $this->action); if ($actMain->length > 0) { $this->layout->mergeLayout($actMain->item(0), TRUE); } if (isset($layoutUpdate) && isset($updateKey)) { $domUpdate = new Uni_Data_XDOMDocument(); if (!$domUpdate->loadXML('<layout>' . $layoutUpdate . '</layout>')) { } $this->layout->mergeLayout($domUpdate->documentElement, TRUE); } $this->layout->prepareHead(); $this->layout->showXML(); $this->finalLayout->loadXML($this->layout->saveXML()); if ($isCacheEnabled) { $this->finalLayout->save($cacheLayoutPath); @chmod($cacheLayoutPath, 0777); } unset($this->layout); $debug || ob_clean(); } else { if (file_exists($cacheLayoutPath)) { $this->finalLayout->load($cacheLayoutPath); } } $this->parse($this->finalLayout); }
/** * Constructor * * @return void */ public function __construct() { $this->dbAdapter = Uni_Fox::getDatabaseAdapter(); }
/** * Loads setting data * * @param string $item setting key */ function loadSettingData($item) { $this->item = $item; $modules = Uni_Fox::getModules(); $doc = new Uni_Data_XDOMDocument(); if (is_array($modules)) { $this->finalMenuTree = new Uni_Data_XDOMDocument(); $this->finalMenuTree->formatOutput = true; $this->root = Uni_Data_XDOMDocument::createNode('settings', NULL, $this->finalMenuTree); $this->finalMenuTree->appendChild($this->root); foreach ($modules as $module) { $filePath = $module['path'] . DIRECTORY_SEPARATOR . 'conf' . DIRECTORY_SEPARATOR . 'setting.xml'; if (file_exists($filePath)) { if ($doc->load($filePath)) { $xPath = new DOMXPath($doc); $setting = $xPath->query('/settings/setting|items'); if ($setting->length > 0) { foreach ($setting as $menu) { $this->getFinalMenuTree($menu); } } $q = '/settings/items/item[@name="' . $item . '"]/sections'; $sections = $xPath->query($q); if ($sections->length > 0) { foreach ($sections as $section) { $this->getFinalMenuTree($section); } } } } } } }
/** * Initialize session */ protected function _initSession() { Uni_Fox::initSession($this); }
/** * Remove module cache * @return void * */ public static function clearModuleCache() { $cache = Uni_Fox::getCache(); $cache->clean(Zend_Cache::CLEANING_MODE_ALL); }
/** * Save module settings * * @param string $module module name */ private static function saveSettings($module) { if ($doc = Uni_Fox::loadModuleSetting($module)) { $xPath = new DOMXPath($doc); $items = $xPath->query('/settings/items/item'); if ($items->length) { $preferenceModel = Fox::getModel('core/preference'); foreach ($items as $item) { $itemName = $item->getAttribute('name'); if ($item->childNodes->length) { foreach ($item->childNodes as $sections) { if ($sections->nodeName == 'sections') { foreach ($sections->childNodes as $section) { if ($section->nodeName == 'section') { $sectionName = $section->getAttribute('name'); foreach ($section->childNodes as $field) { if ($field->nodeName == 'field') { $fieldName = $field->getAttribute('name'); foreach ($field->childNodes as $defaultNode) { if ($defaultNode->nodeName == 'default') { try { $preferenceModel->load($itemName . '/' . $sectionName . '/' . $fieldName, 'name'); $preferenceModel->setName($itemName . '/' . $sectionName . '/' . $fieldName); $preferenceModel->setValue($defaultNode->nodeValue); $preferenceModel->save(); $preferenceModel->unsetData(); } catch (Exception $e) { Fox::getModel('core/session')->addError($e->getMessage()); } } } } } } } } } } } } } }