示例#1
0
 public function routeShutdown(Zend_Controller_Request_Abstract $request)
 {
     $navContainer = null;
     $viewRenderer = Zend_Controller_Action_HelperBroker::getExistingHelper('ViewRenderer');
     $viewRenderer->initView();
     $view = $viewRenderer->view;
     $module = $request->getModuleName();
     if ($module == "admin") {
         $navContainerConfig = new Zend_Config_Xml(APPLICATION_PATH . '/modules/admin/navigation.xml', 'nav');
         $navContainer = new Zend_Navigation($navContainerConfig);
         // Load the xml navigation menu
         // check if the database configuration has been set
         if (Shineisp_Main::isReady()) {
             // Adding the configuration menu items
             $configuration = SettingsGroups::getlist();
             $submenu = $navContainer->findOneByLabel('Configuration');
             foreach ($configuration as $id => $item) {
                 $pages[] = array('label' => $item, 'uri' => '/admin/settings/index/groupid/' . $id, 'resource' => 'admin:settings');
             }
             $submenu->addPages($pages);
         }
         // Attach the Zend ACL to the Navigation menu
         $auth = Zend_Auth::getInstance();
         if ($auth) {
             $acl = $auth->getStorage()->read();
             if (is_object($acl)) {
                 Zend_View_Helper_Navigation_HelperAbstract::setDefaultAcl($acl);
                 Zend_View_Helper_Navigation_HelperAbstract::setDefaultRole("administrator");
             }
         }
     } elseif ($module == "default") {
         $navContainerConfig = new Zend_Config_Xml(APPLICATION_PATH . '/modules/default/navigation.xml', 'nav');
         $navContainer = new Zend_Navigation($navContainerConfig);
         // Load the xml navigation menu
         // Attach the Zend ACL to the Navigation menu
         $auth = Zend_Auth::getInstance();
         if ($auth) {
             $acl = $auth->getStorage()->read();
             if (is_object($acl)) {
                 Zend_View_Helper_Navigation_HelperAbstract::setDefaultAcl($acl);
                 Zend_View_Helper_Navigation_HelperAbstract::setDefaultRole("guest");
             }
         }
     }
     if ($navContainer) {
         foreach ($navContainer->getPages() as $page) {
             foreach ($page->getPages() as $subpage) {
                 foreach ($subpage->getPages() as $subsubpage) {
                     $uri = $subsubpage->getHref();
                     if ($uri === $request->getRequestUri()) {
                         $subsubpage->setActive(true);
                     }
                 }
             }
         }
         $view->navigation($navContainer);
     }
 }
示例#2
0
 protected function _initLayoutHelper()
 {
     $this->bootstrap('frontController');
     if (Shineisp_Main::isReady()) {
         // Loading the configuration parameters
         $module = $this->getModuleName();
         SettingsParameters::loadParams($module);
         Zend_Controller_Action_HelperBroker::addHelper(new Shineisp_Controller_Action_Helper_LayoutLoader());
     }
 }
示例#3
0
 public function routeShutdown(Zend_Controller_Request_Abstract $request)
 {
     $currency = new Zend_Currency('IT');
     $registry = Shineisp_Registry::getInstance();
     // Check if the config file has been created
     $isReady = Shineisp_Main::isReady();
     if ($isReady) {
         // TODO: To be completed
     }
     $registry->set('Zend_Currency', $currency);
 }
示例#4
0
 protected function _initControllerPlugin()
 {
     $this->bootstrap('frontController');
     $fc = Zend_Controller_Front::getInstance();
     $fc->registerPlugin(new Shineisp_Controller_Plugin_Starter());
     $fc->registerPlugin(new Shineisp_Controller_Plugin_Language());
     $fc->registerPlugin(new Shineisp_Controller_Plugin_Currency());
     $fc->registerPlugin(new Shineisp_Controller_Plugin_Navigation());
     if (Shineisp_Main::isReady()) {
         // Init new plugin architecture
         Zend_Registry::set("em", new Zend_EventManager_EventManager());
         $Shineisp_Plugins = new Shineisp_Plugins();
         $Shineisp_Plugins->initAll();
         $fc->registerPlugin(new Shineisp_Controller_Plugin_Acl(new Shineisp_Acl()));
         $fc->registerPlugin(new Shineisp_Controller_Plugin_Migrate());
     }
 }
示例#5
0
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     $module = $request->getModuleName();
     if ($module == "default") {
         // set the right session namespace per module
         $module_session = 'Default';
     } elseif ($module == "admin") {
         $module_session = 'Admin';
     } else {
         $module_session = 'Default';
     }
     $ns = new Zend_Session_Namespace();
     $ns->module = $module;
     if ("setup" == $request->getModuleName()) {
         return false;
     }
     // Check if the config file has been created
     $isReady = Shineisp_Main::isReady();
     if (!$isReady) {
         header('location: /setup');
     }
 }
示例#6
0
 /**
  * Export the sample data
  */
 public function dataexportAction()
 {
     $dsn = Shineisp_Main::getDSN();
     $conn = Doctrine_Manager::connection($dsn, 'doctrine');
     $conn->execute('SHOW TABLES');
     # Lazy loading of the connection. If I execute a simple command the connection to the database starts.
     $conn->setAttribute(Doctrine::ATTR_USE_NATIVE_ENUM, true);
     $conn->setCharset('UTF8');
     // clean up the fixture directory
     Shineisp_Commons_Utilities::delTree(APPLICATION_PATH . "/configs/data/fixtures/");
     @mkdir(APPLICATION_PATH . "/configs/data/fixtures/");
     // Set the current connection
     $manager = Doctrine_Manager::getInstance()->setCurrentConnection('doctrine');
     if ($conn->isConnected()) {
         #Doctrine_Core::dumpData(APPLICATION_PATH . "/configs/data/fixtures/", false);
         $export = new Doctrine_Data_Export(APPLICATION_PATH . "/configs/data/fixtures/");
         $export->setFormat('yml');
         $export->setModels(array());
         $export->exportIndividualFiles(true);
         $export->doExport();
     }
     die('done');
 }
示例#7
0
 /**
  * Create the ShineISP Database
  */
 public static function createDb($installsampledata = true)
 {
     try {
         $dbconfig = Shineisp_Main::databaseConfig();
         $dsn = Shineisp_Main::getDSN();
         $conn = Doctrine_Manager::connection($dsn, 'doctrine');
         $conn->execute('SHOW TABLES');
         # Lazy loading of the connection. If I execute a simple command the connection to the database starts.
         $conn->setAttribute(Doctrine::ATTR_USE_NATIVE_ENUM, true);
         $conn->setCharset('UTF8');
         $dbh = $conn->getDbh();
         $models = Doctrine::getLoadedModels();
         // Set the current connection
         $manager = Doctrine_Manager::getInstance()->setCurrentConnection('doctrine');
         if ($conn->isConnected()) {
             $migration = new Doctrine_Migration(APPLICATION_PATH . '/configs/migrations');
             // Get the latest version set in the migrations directory
             $latestversion = $migration->getLatestVersion();
             if (empty($latestversion)) {
                 $latestversion = 0;
             }
             // Clean the database
             $conn->execute('SET FOREIGN_KEY_CHECKS = 0');
             foreach ($models as $model) {
                 $tablename = Doctrine::getTable($model)->getTableName();
                 $dbh->query("DROP TABLE IF EXISTS {$tablename}");
             }
             // Create the migration_version table
             Doctrine_Manager::getInstance()->getCurrentConnection()->execute('DROP TABLE IF EXISTS `migration_version`;CREATE TABLE `migration_version` (`version` int(11) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=latin1;INSERT INTO `migration_version` VALUES (' . $latestversion . ')');
             // Create all the tables in the database
             Doctrine_Core::createTablesFromModels(APPLICATION_PATH . '/models');
             // Common resources
             Doctrine_Core::loadData(APPLICATION_PATH . '/configs/data/fixtures/commons/', true);
             // Sample data
             if ($installsampledata) {
                 $import = new Doctrine_Data_Import(APPLICATION_PATH . '/configs/data/fixtures/');
                 $import->setFormat('yml');
                 $import->setModels($models);
                 $import->doImport(true);
             }
             $conn->execute('SET FOREIGN_KEY_CHECKS = 1');
             // Update the version in the config.xml file previously created
             Settings::saveConfig($dbconfig, $latestversion);
         } else {
             echo "No Connection found";
         }
     } catch (Exception $e) {
         die($e);
     }
     // return the latest version
     return $latestversion;
 }
示例#8
0
 public function routeShutdown(Zend_Controller_Request_Abstract $request)
 {
     $force = false;
     $registry = Shineisp_Registry::getInstance();
     // Check if the config file has been created
     $isReady = Shineisp_Main::isReady();
     $module = $request->getModuleName();
     if ($module == "default") {
         // set the right session namespace per module
         $module_session = 'Default';
     } elseif ($module == "admin") {
         $module_session = 'Admin';
     } else {
         $module_session = 'Default';
     }
     $ns = new Zend_Session_Namespace($module_session);
     try {
         $locale = new Zend_Locale(Zend_Locale::BROWSER);
         if (!empty($ns->lang)) {
             $locale = new Zend_Locale($ns->lang);
         }
         Shineisp_Commons_Utilities::log("System: Get the browser locale: " . $locale, "debug.log");
     } catch (Exception $e) {
         Shineisp_Commons_Utilities::log("System: " . $e->getMessage(), "debug.log");
         if (!empty($ns->lang)) {
             Shineisp_Commons_Utilities::log("System: Get the session var locale", "debug.log");
             $locale = new Zend_Locale($ns->lang);
         } else {
             $locale = new Zend_Locale("en");
             Shineisp_Commons_Utilities::log("System: There is not any available locale, set the default one: en_GB", "debug.log");
         }
     }
     // check the user request if it is not set, please get the old prefereces
     $lang = $request->getParam('lang');
     if (empty($lang)) {
         // Get the user preference
         if (strlen($locale) == 2) {
             // Check if the Browser locale is formed with 2 chars
             $lang = $locale;
         } elseif (strlen($locale) > 4) {
             // Check if the Browser locale is formed with > 4 chars
             $lang = substr($locale, 0, 2);
             // Get the language code from the browser preference
         }
     } else {
         $force = true;
     }
     // Get the translate language or the default language: en
     if (file_exists(PUBLIC_PATH . "/languages/{$lang}/{$lang}.mo")) {
         $translate = new Zend_Translate(array('adapter' => "Shineisp_Translate_Adapter_Gettext", 'content' => PUBLIC_PATH . "/languages/{$lang}/{$lang}.mo", 'locale' => $lang, 'disableNotices' => true));
     } else {
         $translate = new Zend_Translate(array('adapter' => "Shineisp_Translate_Adapter_Gettext", 'locale' => $lang, 'disableNotices' => true));
     }
     $registry->set('Zend_Translate', $translate);
     $registry->set('Zend_Locale', $locale);
     if ($isReady) {
         if (empty($ns->langid) || $force) {
             $ns->langid = Languages::get_language_id_by_code($lang);
         }
     } else {
         $ns->langid = 1;
     }
     $ns->lang = $lang;
     Shineisp_Commons_Utilities::log("System: Locale set: " . $locale, "debug.log");
     Shineisp_Commons_Utilities::log("System: Language selected: " . $ns->lang, "debug.log");
 }
示例#9
0
 /**
  * (non-PHPdoc)
  * @see Zend_Controller_Plugin_Abstract::preDispatch()
  */
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     $dayssincefirstsetup = 0;
     $migration = new Doctrine_Migration(APPLICATION_PATH . '/configs/migrations');
     $LatestVersion = $migration->getLatestVersion();
     $CurrentVersion = $migration->getCurrentVersion();
     try {
         // Check if the config file has been created
         $isReady = Shineisp_Main::isReady();
         if ($isReady) {
             // Execute the migration
             if ($CurrentVersion < $LatestVersion) {
                 // write a log message
                 Shineisp_Commons_Utilities::log("Upgrade: Current Version is {$CurrentVersion} and the latest available version is {$LatestVersion}");
                 $dbconfig = Shineisp_Main::databaseConfig();
                 // Update the version in the config.xml file previously created
                 Settings::saveConfig($dbconfig, $LatestVersion);
                 if ($CurrentVersion > 0) {
                     Shineisp_Commons_Utilities::log("Upgrade: Migrate ShineISP version from {$CurrentVersion} to {$LatestVersion}");
                     $migration->migrate();
                 }
             }
             $db = Doctrine_Manager::getInstance()->getCurrentConnection();
             // Read and execute all the sql files saved in the /application/configs/data/sql directory
             $path = PROJECT_PATH . "/application/configs/data/sql";
             if (is_dir($path)) {
                 $directory_iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
                 try {
                     // get the first setup date
                     $setupdate = Settings::getConfigSetupDate();
                     if (empty($setupdate)) {
                         throw new Exception('Setup date is not set in the config.xml file');
                     }
                     // for each sql file do ...
                     foreach ($directory_iterator as $filename => $path_object) {
                         // get the sql file information
                         $info = pathinfo($filename);
                         if (!empty($info['extension']) && $info['extension'] == "sql") {
                             $name = $info['filename'];
                             // get the first part of the name with the filename that contains the date: YYYYMMddHis-NAME.sql
                             $arrName = explode("-", $name);
                             // if the string is a valid date get the days betweeen the sql file name and the day of the setup of shineisp
                             if (!empty($arrName[0]) && Zend_Date::isdate($arrName[0], 'YYYYMMddHis')) {
                                 $sqldate = new Zend_Date($arrName[0], 'YYYYMMddHis');
                                 $mysetupdate = new Zend_Date($setupdate, 'YYYYMMddHis');
                                 // get the difference of the two dates
                                 $diff = $sqldate->sub($mysetupdate)->toValue();
                                 $dayssincefirstsetup = floor($diff / 60 / 60 / 24);
                                 unset($sqldate);
                                 unset($mysetupdate);
                             }
                             // SQL files post installation will be executed
                             if ($dayssincefirstsetup >= 0) {
                                 // read the sql
                                 $sql = Shineisp_Commons_Utilities::readfile($info['dirname'] . "/" . $info['basename']);
                                 if (!empty($sql)) {
                                     // execute the sql strings
                                     $result = $db->execute($sql);
                                     // close the db connection
                                     $db->close();
                                     if ($result) {
                                         // write a log message
                                         Shineisp_Commons_Utilities::log($info['filename'] . ".sql has been executed.");
                                         // rename the sql
                                         rename($info['dirname'] . "/" . $info['basename'], $info['dirname'] . "/" . $info['filename'] . ".sql.old");
                                     }
                                 }
                             } else {
                                 // rename the sql
                                 rename($info['dirname'] . "/" . $info['basename'], $info['dirname'] . "/" . $info['filename'] . ".sql.old");
                                 // write a log message
                                 Shineisp_Commons_Utilities::log($info['filename'] . ".sql has been skipped because already set in the doctrine data setup.");
                             }
                         }
                     }
                 } catch (Exception $e) {
                     die($e->getMessage());
                 }
             }
         }
         // Execute the migration
         if ($CurrentVersion < $LatestVersion) {
             $dbconfig = Shineisp_Main::databaseConfig();
             // Update the version in the config.xml file previously created
             Settings::saveConfig($dbconfig, $LatestVersion);
             if ($CurrentVersion > 0) {
                 $migration->migrate();
             }
         }
     } catch (Exception $e) {
         Zend_Debug::dump($e->getMessage());
         die;
     }
 }
示例#10
0
 /**
  * Log file
  * @param $str
  * @return void
  */
 public static function log($message, $filename = "errors.log", $priority = Zend_Log::INFO)
 {
     try {
         $logger = new Zend_Log();
         $debug = true;
         $debug_log = true;
         if (Shineisp_Main::isReady()) {
             $debug = Settings::findbyParam('debug');
             $debug_log = Settings::findbyParam('debug_log');
         }
         if ($debug) {
             $writer = new Zend_Log_Writer_Firebug();
             $logger->addWriter($writer);
             $logger->log($message, $priority);
         }
         if ($debug_log) {
             @mkdir(PUBLIC_PATH . '/logs/');
             if (is_writable(PUBLIC_PATH . '/logs/')) {
                 $log = fopen(PUBLIC_PATH . '/logs/' . $filename, 'a+');
                 if (is_array($message)) {
                     fputs($log, '[' . date('d-m-Y H:i:s') . "]\n" . var_export($message, true));
                 } elseif (is_object($message)) {
                     fputs($log, '[' . date('d-m-Y H:i:s') . "]\n" . var_export($message, true));
                 } else {
                     fputs($log, '[' . date('d-m-Y H:i:s') . "] {$message}\n");
                 }
                 fclose($log);
             } else {
                 $logger->log(PUBLIC_PATH . '/logs/ is not writable', Zend_Log::INFO);
             }
         }
     } catch (Exception $e) {
         die($e->getMessage());
     }
 }