示例#1
0
 protected function addNewModule($moduleData)
 {
     if (!isset($moduleData['title']) || empty($moduleData['title'])) {
         throw new KurogoConfigurationException("Choose a module title");
     }
     if (!isset($moduleData['config']) || !preg_match("/^[a-z0-9_-]+\$/i", $moduleData['config'])) {
         throw new KurogoConfigurationException("Choose a url. It must contain only letters and numbers");
     }
     $moduleClasses = WebModule::getAllModuleClasses();
     if (!isset($moduleData['id']) || !in_array($moduleData['id'], $moduleClasses)) {
         throw new KurogoConfigurationException("Choose a module type");
     }
     $modules = WebModule::getAllModules();
     if (in_array($moduleData['config'], $modules)) {
         throw new KurogoConfigurationException("Module " . $moduleData['config'] . " already exists");
     }
     $config = ModuleConfigFile::factory($moduleData['config'], 'module', ModuleConfigFile::OPTION_CREATE_WITH_DEFAULT);
     $valid_props = array('id', 'title', 'protected', 'secure', 'disabled', 'search');
     foreach ($valid_props as $key) {
         if (isset($moduleData[$key])) {
             $config->setVar('module', $key, $moduleData[$key], $changed);
         }
     }
     $config->saveFile();
 }
示例#2
0
 protected function initializeForPage()
 {
     //make sure that only desktop/tablet devices can use the module
     $deviceClassifier = Kurogo::deviceClassifier();
     if ($this->page != 'index' && !($deviceClassifier->isComputer() || $deviceClassifier->isTablet())) {
         $this->redirectTo('index');
     }
     $navSections = $this->getNavSections();
     $section = '';
     $this->assign('navSections', $navSections);
     $this->addJQuery();
     $this->addJQueryUI();
     switch ($this->page) {
         case 'modules':
             $subNavSections = $this->getSubNavSections($this->page);
             $this->assign('subNavSections', $subNavSections);
             $defaultSubNavSection = key($subNavSections);
             $section = $this->getArg('section', $defaultSubNavSection);
             $moduleID = $this->getArg('module');
             if ($moduleID) {
                 $this->setTemplatePage('module');
                 try {
                     if ($module = WebModule::factory($moduleID)) {
                         $this->assign('moduleName', $module->getModuleName());
                         $this->assign('moduleID', $module->getConfigModule());
                         $this->assign('moduleIcon', $module->getOptionalModuleVar('icon', $module->getConfigModule(), 'module'));
                         $section = $moduleID;
                         $moduleSection = $this->getArg('section', 'general');
                         $this->assign('moduleSection', $moduleSection);
                     }
                 } catch (KurogoException $e) {
                     $this->redirectTo($this->page, array());
                 }
             } elseif ($section == $defaultSubNavSection) {
                 $moduleClasses = WebModule::getAllModuleClasses();
                 $this->assign('moduleClasses', $moduleClasses);
                 $this->setTemplatePage($section);
             } elseif ($section == 'homescreen') {
                 $this->setTemplatePage($section);
                 $modules = $this->getModules();
                 $this->assign('modules', $modules);
             } else {
                 $this->redirectTo($this->page, array());
             }
             break;
         case 'site':
             $subNavSections = $this->getSubNavSections($this->page);
             $this->assign('subNavSections', $subNavSections);
             $defaultSubNavSection = key($subNavSections);
             $section = $this->getArg('section', $defaultSubNavSection);
             if (!isset($subNavSections[$section])) {
                 $this->redirectTo($this->page, array());
             }
             break;
         case 'credits':
             $section = $this->getArg('section', 'credits');
             $subNavSections = array('credits' => array('id' => 'credits', 'title' => $this->getLocalizedString("ADMIN_CREDITS_CREDITS_TITLE"), 'url' => $this->buildURL($this->page, array('section' => 'credits'))), 'license' => array('id' => 'license', 'title' => $this->getLocalizedString("ADMIN_CREDITS_LICENSE_TITLE"), 'url' => $this->buildURL($this->page, array('section' => 'license'))));
             $this->assign('subNavSections', $subNavSections);
             if (isset($subNavSections[$section])) {
                 switch ($section) {
                     case 'license':
                         $licenseFile = ROOT_DIR . "/LICENSE";
                         if (is_file($licenseFile)) {
                             $this->assign('license', file_get_contents($licenseFile));
                         } else {
                             die($licenseFile);
                             throw new KurogoException("Unable to load LICENSE file, you may have a compromised Kurogo Installation");
                         }
                 }
                 $this->setTemplatePage($section);
             } else {
                 $this->redirectTo('section', array());
             }
             break;
         case 'index':
             //redirect desktop devices to the "default page"
             $deviceClassifier = Kurogo::deviceClassifier();
             if ($deviceClassifier->isComputer() || $deviceClassifier->isTablet()) {
                 $defaultSection = current($navSections);
                 $this->redirectTo($defaultSection['id'], array());
             }
             break;
         default:
             $this->redirectTo('index', array());
             break;
     }
     $this->assign('section', $section);
 }