Exemplo n.º 1
0
 /**
  * 
  * Create or return the group id
  * @param string $name
  */
 public static function addGroup($name, $description = null, $help = null)
 {
     $g = self::findbyName($name);
     if (!empty($g)) {
         return $g->get('group_id');
     }
     $group = new SettingsGroups();
     $group['name'] = $name;
     $group['help'] = $help;
     $group['description'] = $description;
     $group->save();
     return $group['group_id'];
 }
Exemplo n.º 2
0
 /**
  * indexAction
  * Create the User object and get all the records.
  * @return unknown_type
  */
 public function indexAction()
 {
     // get the group id
     $groupid = $this->getRequest()->getParam('groupid');
     // Check if the groupid is a number
     if (empty($groupid) || !is_numeric($groupid)) {
         $grp = SettingsGroups::findbyName('General');
         $groupid = $grp['group_id'];
     }
     $group = SettingsGroups::find($groupid);
     if (!empty($group)) {
         $this->view->title = $group['name'];
         $this->view->description = $group['description'];
         $this->view->help = $group['help'];
     } else {
         $this->view->title = $this->translator->translate("Settings");
         $this->view->description = $this->translator->translate("Set here all the ShineISP parameters.");
     }
     $form = SettingsParameters::createForm($groupid);
     if ($this->getRequest()->isPost() && $form->isValid($this->getRequest()->getPost())) {
         Settings::saveRecord($groupid, $form->getValues());
     }
     $this->view->buttons = array(array("url" => "#", "label" => $this->translator->translate('Save'), "params" => array('css' => null, 'id' => 'submit')));
     // Create the html form
     $this->view->form = $form;
 }
Exemplo n.º 3
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);
     }
 }
Exemplo n.º 4
0
 public function initAll()
 {
     // Get the Zend Event Manager
     $em = Shineisp_Registry::get('em');
     $mainConfigfile = APPLICATION_PATH . "/configs/config.xml";
     if (file_exists($mainConfigfile)) {
         $mainconfig = simplexml_load_file($mainConfigfile);
     } else {
         throw new Exception($mainConfigfile . " has been not found");
     }
     if (!count($mainconfig->xpath("/shineisp/modules"))) {
         $modules = $mainconfig->addChild('modules');
     } else {
         $modules = $mainconfig->xpath("/shineisp/modules");
     }
     $path = PROJECT_PATH . "/library/Shineisp/Plugins" . DIRECTORY_SEPARATOR;
     // << The last slash is very important in the plugin path
     // Read all the directory recursivelly and get all the files and folders
     $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
     foreach ($iterator as $filename => $path_object) {
         $pluginConfigFile = $filename;
         $info = pathinfo($filename);
         // Select only the plugins that have a xml configuration file
         if (!empty($info['extension']) && $info['extension'] == "xml") {
             // Get the directory of the plugin
             $PluginPath = $info['dirname'];
             // Delete the main plugin path
             $PluginBasePath = str_replace($path, "", $info['dirname']);
             // Convert the result as array
             $PluginBasePathArray = explode(DIRECTORY_SEPARATOR, $PluginBasePath);
             // Create the name of the Plugin class
             $pluginName = 'Shineisp_Plugins_' . implode("_", $PluginBasePathArray) . '_Main';
             // Check if plugins looks good
             $reflectionClass = new ReflectionClass($pluginName);
             if (!($reflectionClass->isInstantiable() && $reflectionClass->implementsInterface('Shineisp_Plugins_Interface') && is_callable(array($pluginName, 'events')))) {
                 Shineisp_Commons_Utilities::logs("Skipping not instantiable plugin '" . $pluginName . "'");
                 continue;
             }
             // Initialize
             $plugin = new $pluginName();
             $plugin->events($em);
             // Check if the Main exists
             if (file_exists($pluginConfigFile) && is_readable($pluginConfigFile)) {
                 $info = pathinfo($pluginConfigFile);
                 if (!empty($info['extension']) && $info['extension'] == "xml") {
                     if (file_exists($pluginConfigFile)) {
                         $config = simplexml_load_file($pluginConfigFile);
                         // If the config file has been created for the registrar ignore it
                         // because the configuration is delegated to the registrar management
                         if (isset($config->attributes()->type) && "registrars" == (string) $config->attributes()->type) {
                             continue;
                         }
                         $panelName = (string) $config->attributes()->name;
                         $var = (string) $config['var'];
                         // Save the module setup in the config.xml file
                         // Now we are checking if the module is already set in the config.xml file
                         if (!count($mainconfig->xpath("/shineisp/modules/{$var}"))) {
                             // The module is not present, we have to create it
                             $module = $modules[0]->addChild($var);
                             // Now we add the setup date as attribute
                             $module->addAttribute('setup', date('YmdHis'));
                         } else {
                             // The module is present and we get it
                             $module = $mainconfig->xpath("/shineisp/modules/{$var}");
                             // If the setup date attribute is present skip the module process setup
                             if (!empty($module[0]) && $module[0]->attributes()->setup) {
                                 continue;
                             } else {
                                 // The setup attribute is not present restart the module setup process
                                 $module[0]->addAttribute('setup', date('YmdHis'));
                             }
                         }
                         $help = (string) $config->general->help ? (string) $config->general->help : NULL;
                         $description = (string) $config->general->description ? (string) $config->general->description : NULL;
                         $group_id = SettingsGroups::addGroup($config['name'], $description, $help);
                         if (!empty($config->settings) && $config->settings->children()) {
                             foreach ($config->settings->children() as $node) {
                                 $configclass = array();
                                 $arr = $node->attributes();
                                 $var = strtolower($config['var']) . "_" . (string) $arr['var'];
                                 $label = (string) $arr['label'];
                                 $type = (string) $arr['type'];
                                 $description = (string) $arr['description'];
                                 if ((string) $arr['configclass']) {
                                     $configclass = json_decode((string) $arr['configclass'], true);
                                 }
                                 if (!empty($var) && !empty($label) && !empty($type)) {
                                     SettingsParameters::addParam($label, $description, $var, $type, 'admin', 1, $group_id, $configclass);
                                 }
                             }
                             if (!empty($config->customfields)) {
                                 foreach ($config->customfields->children() as $node) {
                                     $arr = $node->attributes();
                                     $var = (string) $node;
                                     $label = (string) $arr['label'];
                                     $type = (string) $arr['type'];
                                     $section = (string) $arr['section'];
                                     // Fetch panel_id from database
                                     if (!empty($panelName)) {
                                         $Panels = Panels::getAllInfoByName($panelName);
                                     }
                                     $panel_id = !empty($Panels) && isset($Panels['panel_id']) && $Panels['panel_id'] > 0 ? intval($Panels['panel_id']) : null;
                                     if (!empty($var) && !empty($label) && !empty($type)) {
                                         CustomAttributes::createAttribute($var, $label, $type, $section, $panel_id);
                                     }
                                 }
                             }
                         }
                     }
                     $xmlstring = $mainconfig->asXML();
                     // Prettify and save the xml configuration
                     $dom = new DOMDocument('1.0');
                     $dom->loadXML($xmlstring);
                     $dom->formatOutput = TRUE;
                     $dom->preserveWhiteSpace = TRUE;
                     $dom->saveXML();
                     if (!@$dom->save($mainConfigfile)) {
                         throw new Exception("Error on saving the xml file in {$mainConfigfile} <br/>Please check the folder permissions");
                     }
                 }
             }
         }
     }
 }