Пример #1
0
 protected function getHomeModulePortletConfig()
 {
     static $homePortletConfig;
     if (!$homePortletConfig) {
         $homePortletConfig = Kurogo::getModuleConfig('portlets', $this->getHomeModuleID());
     }
     return $homePortletConfig;
 }
Пример #2
0
 protected function getAllModuleNavigationData($includeHidden = self::INCLUDE_HIDDEN_MODULES, $iconSetType = 'navigation')
 {
     $modules = $moduleNavData = array('primary' => array(), 'secondary' => array());
     $navModules = Kurogo::getSiteSections('navigation', Config::APPLY_CONTEXTS_NAVIGATION);
     foreach ($navModules as $moduleID => $moduleData) {
         $type = Kurogo::arrayVal($moduleData, 'type', 'primary');
         $moduleNavData[$type][$moduleID] = $moduleData;
     }
     if ($iconSet = $this->getOptionalThemeVar($iconSetType . '_icon_set')) {
         $iconSetSize = $this->getOptionalThemeVar($iconSetType . '_icon_size');
         $imgPrefix = "/common/images/iconsets/{$iconSet}/{$iconSetSize}/";
     } else {
         $homeModuleID = $this->getHomeModuleID();
         $imgPrefix = "/modules/{$homeModuleID}/images/";
     }
     //this is fixed for now
     $modulesThatCannotBeHidden = array('customize');
     $allModuleData = array();
     $userNavData = $this->getUserNavData();
     foreach ($moduleNavData as $type => $modulesOfType) {
         foreach ($modulesOfType as $moduleID => $navData) {
             $icon = $moduleID;
             $selected = $this->configModule == $moduleID;
             $primary = $type == 'primary';
             $classes = array();
             if ($selected) {
                 $classes[] = 'selected';
             }
             if (!$primary) {
                 $classes[] = 'utility';
             }
             $hidable = !in_array($moduleID, $modulesThatCannotBeHidden);
             $imgSuffix = $this->pagetype == 'tablet' && $selected ? '' : '';
             $linkTarget = Kurogo::arrayVal($navData, 'linkTarget');
             // customize is implemented as a page on the home module
             if ($moduleID == 'customize') {
                 $visible = true;
                 $icon = $moduleID;
                 $moduleData = array('type' => $type, 'selected' => $selected, 'title' => $this->getLocalizedString('CUSTOMIZE_TITLE'), 'shortTitle' => $this->getLocalizedString('CUSTOMIZE_SHORT_TITLE'), 'url' => "/" . $this->getHomeModuleID() . "/customize", 'hideable' => $hidable, 'visible' => true, 'img' => $imgPrefix . "{$icon}{$imgSuffix}" . $this->imageExt, 'class' => implode(' ', $classes), 'linkTarget' => $linkTarget);
             } else {
                 //this will throw an exception if a module is not available, so watch out
                 $moduleConfig = Kurogo::getModuleConfig('module', $moduleID);
                 $title = Kurogo::arrayVal($navData, 'title', $moduleConfig->getVar('title'));
                 $shortTitle = Kurogo::arrayVal($navData, 'shortTitle', $title);
                 $icon = $moduleConfig->getOptionalVar('icon', $moduleID);
                 $visible = Kurogo::arrayVal($userNavData, $moduleID, Kurogo::arrayVal($navData, 'visible', 1));
                 $moduleData = array('type' => $type, 'selected' => $selected, 'title' => $title, 'shortTitle' => $shortTitle, 'url' => "/{$moduleID}/", 'hideable' => $hidable, 'visible' => $visible, 'img' => $imgPrefix . "{$icon}{$imgSuffix}" . $this->imageExt, 'class' => implode(' ', $classes), 'linkTarget' => $linkTarget);
                 if (Kurogo::getOptionalSiteVar('DYNAMIC_MODULE_NAV_DATA', false)) {
                     $module = WebModule::factory($moduleID, false, array(), false);
                     // do not initialize
                     $moduleData = $module->getModuleNavigationData($moduleData);
                 }
             }
             if ($visible || $includeHidden || $type == 'primary' && isset($userNavData['visible'])) {
                 $modules[$type][$moduleID] = $moduleData;
             }
         }
     }
     if (isset($userNavData['visible'])) {
         $userModuleNavData = array();
         foreach ($userNavData['visible'] as $moduleID => $visible) {
             if (isset($modules['primary'][$moduleID])) {
                 if ($visible || $includeHidden) {
                     $userModuleNavData[$moduleID] = $modules['primary'][$moduleID];
                     $userModuleNavData[$moduleID]['visible'] = $visible;
                 }
             }
         }
         // make sure all primary modules are defined in userNavData
         // this ensures that new modules show up if a user has customized their layout
         $userModules = array_keys($userNavData['visible']);
         $navModules = array_keys($modules['primary']);
         if ($diff = array_diff($navModules, $userModules)) {
             foreach ($diff as $moduleID) {
                 $userModuleNavData[$moduleID] = $modules['primary'][$moduleID];
             }
         }
         $modules['primary'] = $userModuleNavData;
     }
     return $modules;
 }
Пример #3
0
 public function themeConfig()
 {
     if (!$this->themeConfig) {
         $this->themeConfig = new ConfigGroup('theme', 'site');
         if ($config = Kurogo::getSiteConfig('theme')) {
             $this->themeConfig->addConfig($config);
         }
         if ($this->configModule) {
             if ($config = Kurogo::getModuleConfig('theme', $this->module, Config::OPTION_DO_NOT_CREATE)) {
                 $this->themeConfig->addConfig($config);
             }
         }
     }
     return $this->themeConfig;
 }
Пример #4
0
 public function initializeForCommand()
 {
     $this->requiresAdmin();
     switch ($this->command) {
         case 'checkversion':
             $current = Kurogo::sharedInstance()->checkCurrentVersion();
             Kurogo::log(LOG_INFO, sprintf("Checking version. This site: %s Current Kurogo Version: %s", $current, KUROGO_VERSION), 'admin');
             $uptodate = version_compare(KUROGO_VERSION, $current, ">=");
             $messageKey = $uptodate ? 'KUROGO_VERSION_MESSAGE_UPTODATE' : 'KUROGO_VERSION_MESSAGE_NOTUPDATED';
             $data = array('current' => $current, 'local' => KUROGO_VERSION, 'uptodate' => $uptodate, 'message' => $this->getLocalizedString($messageKey, $current, KUROGO_VERSION));
             $this->setResponse($data);
             $this->setResponseVersion(1);
             break;
         case 'getlocalizedstring':
             $key = $this->getArg('key');
             $data = array();
             if (is_array($key)) {
                 foreach ($key as $k) {
                     $data[$k] = $this->getLocalizedString($k);
                 }
             } else {
                 $data[$key] = $this->getLocalizedString($key);
             }
             $this->setResponse($data);
             $this->setResponseVersion(1);
             break;
         case 'clearcaches':
             Kurogo::log(LOG_NOTICE, "Clearing Site Caches", 'admin');
             $result = Kurogo::sharedInstance()->clearCaches();
             if ($result === 0) {
                 $this->setResponse(true);
                 $this->setResponseVersion(1);
             } else {
                 $this->throwError(new KurogoError(1, "Error clearing caches", "There was an error ({$result}) clearing the caches"));
             }
             break;
         case 'buildNativeWebTemplates':
             $moduleID = $this->getArg('module', '');
             $platform = $this->getArg('platform', '');
             $module = WebModule::factory($moduleID);
             $module->buildNativeWebTemplatesForPlatform($platform);
             $this->setResponse(true);
             $this->setResponseVersion(1);
             break;
         case 'upload':
             $type = $this->getArg('type');
             $section = $this->getArg('section', '');
             $subsection = null;
             switch ($type) {
                 case 'module':
                     $moduleID = $this->getArg('module', '');
                     $module = WebModule::factory($moduleID);
                     $type = $module;
                     break;
                 case 'site':
                     break;
                 default:
                     throw new KurogoConfigurationException(__LINE__ . ": Invalid type {$type}");
             }
             if (count($_FILES) == 0) {
                 throw new KurogoException("No files uploaded");
             }
             foreach ($_FILES as $key => $uploadData) {
                 $this->uploadFile($type, $section, $subsection, $key, $uploadData);
             }
             $this->setResponseVersion(1);
             $this->setResponse(true);
             break;
         case 'getconfigsections':
             $type = $this->getArg('type');
             switch ($type) {
                 case 'module':
                     $moduleID = $this->getArg('module', '');
                     $module = WebModule::factory($moduleID);
                     $sections = $module->getModuleAdminSections();
                     break;
                 case 'site':
                     throw new KurogoConfigurationException(__LINE__ . ": getconfigsections for site not handled yet");
             }
             $this->setResponse($sections);
             $this->setResponseVersion(1);
             break;
         case 'getconfigdata':
             $type = $this->getArg('type');
             $section = $this->getArg('section', '');
             switch ($type) {
                 case 'module':
                     $moduleID = $this->getArg('module', '');
                     $module = WebModule::factory($moduleID);
                     $adminData = $this->getAdminData($module, $section);
                     break;
                 case 'site':
                     $adminData = $this->getAdminData('site', $section);
                     break;
                 default:
                     throw new KurogoConfigurationException(__LINE__ . ": Invalid config type {$type}");
             }
             $this->setResponse($adminData);
             $this->setResponseVersion(1);
             break;
         case 'setconfigdata':
             $type = $this->getArg('type');
             $data = $this->getArg('data', array());
             $section = $this->getArg('section', '');
             $subsection = null;
             if (empty($data)) {
                 $data = array();
             } elseif (!is_array($data)) {
                 throw new KurogoConfigurationException(__LINE__ . ": Invalid data for {$type} {$section}");
             }
             switch ($type) {
                 case 'module':
                     if ($section == 'overview') {
                         foreach ($data as $moduleID => $props) {
                             $module = WebModule::factory($moduleID);
                             if (!is_array($props)) {
                                 throw new KurogoConfigurationException(__LINE__ . ": Invalid properties for {$type} {$section}");
                             }
                             $valid_props = array('protected', 'secure', 'disabled', 'search');
                             foreach ($props as $key => $value) {
                                 if (!in_array($key, $valid_props)) {
                                     throw new KurogoConfigurationException(__LINE__ . ": Invalid property {$key} for module {$module}");
                                 }
                                 $this->setConfigVar($module, 'general', $subsection, $key, $value);
                             }
                         }
                         foreach ($this->changedConfigs as $config) {
                             Kurogo::sharedInstance()->saveConfig($config);
                         }
                         $this->setResponse(true);
                         $this->setResponseVersion(1);
                         break 2;
                     } else {
                         $moduleID = $this->getArg('module', '');
                         $module = WebModule::factory($moduleID);
                         $type = $module;
                     }
                     break;
                 case 'site':
                     break;
                 default:
                     throw new KurogoConfigurationException(__LINE__ . ": Invalid type {$type}");
             }
             foreach ($data as $section => $fields) {
                 $adminData = $this->getAdminData($type, $section);
                 if ($adminData['sectiontype'] == 'sections') {
                     $subsection = key($fields);
                     $fields = current($fields);
                     $adminData = $this->getAdminData($type, $section, $subsection);
                 }
                 $fields = is_array($fields) ? $fields : array();
                 foreach ($fields as $key => $value) {
                     if ($adminData['sectiontype'] == 'section' && isset($adminData['sectionclearvalues']) && $adminData['sectionclearvalues']) {
                         if ($config = $this->getAdminConfig($type, $adminData['config'], Config::OPTION_DO_NOT_CREATE)) {
                             $config->removeSection($key);
                         }
                     }
                     // ignore prefix values. We'll put it back together later
                     if (preg_match("/^(.*?)_prefix\$/", $key, $bits)) {
                         continue;
                     }
                     $prefix = isset($fields[$key . '_prefix']) ? $fields[$key . '_prefix'] : '';
                     if ($prefix && defined($prefix)) {
                         $value = constant($prefix) . '/' . $value;
                     }
                     $this->setConfigVar($type, $section, $subsection, $key, $value);
                 }
             }
             if ($sectionorder = $this->getArg('sectionorder')) {
                 foreach ($sectionorder as $section => $order) {
                     $this->setSectionOrder($type, $section, $subsection, $order);
                 }
             }
             foreach ($this->changedConfigs as $config) {
                 Kurogo::sharedInstance()->saveConfig($config);
             }
             $this->setResponse(true);
             $this->setResponseVersion(1);
             break;
         case 'removeconfigsection':
             $type = $this->getArg('type');
             $section = $this->getArg('section', '');
             $key = $this->getArg('key', null);
             switch ($type) {
                 case 'site':
                     $subsection = $this->getArg('subsection', null);
                     $sectionData = $this->getAdminData($type, $section, $subsection);
                     $config = Kurogo::getSiteConfig($sectionData['config'], 'site');
                     break;
                 case 'module':
                     $moduleID = $this->getArg('module', '');
                     $module = WebModule::factory($moduleID);
                     $sectionData = $this->getAdminData($module, $section);
                     $config = Kurogo::getModuleConfig($sectionData['config'], $moduleID);
                     $subsection = $moduleID;
                     break;
                 default:
                     throw new KurogoConfigurationException(__LINE__ . ": Invalid type {$type}");
             }
             if (!isset($sectionData['sections']) || (!isset($sectionData['sectiondelete']) || !$sectionData['sectiondelete'])) {
                 throw new KurogoConfigurationException(__LINE__ . ": Section '{$section}' does not permit removal of items");
             }
             if (!isset($sectionData['sections'][$key])) {
                 throw new KurogoConfigurationException(__LINE__ . ": Section {$key} not found in config '{$section}' of {$type} {$subsection}");
             }
             Kurogo::log(LOG_NOTICE, "Removing section {$key} from {$type} {$section} {$subsection}", 'admin');
             if (!($result = $config->removeSection($key))) {
                 throw new KurogoException(__LINE__ . ": Error removing item {$key} from config '" . $sectionData['config'] . "'");
             } else {
                 Kurogo::sharedInstance()->saveConfig($config);
             }
             $this->setResponse(true);
             $this->setResponseVersion(1);
             break;
         case 'addNewModule':
             $moduleData = $this->getArg('newModule');
             $module = $this->addNewModule($moduleData);
             $this->setResponseVersion(1);
             $this->setResponse(true);
             break;
         case 'removeModule':
             $moduleID = $this->getArg('configModule');
             try {
                 $module = WebModule::factory($moduleID);
             } catch (KurogoException $e) {
                 throw new KurogoException($this->getLocalizedString('ERROR_MODULE_NOT_FOUND', $moduleID));
             }
             $module->removeModule(true);
             $this->setResponseVersion(1);
             $this->setResponse(true);
             break;
         case 'setmodulelayout':
             Kurogo::log(LOG_NOTICE, "Updating module layout", 'admin');
             $data = $this->getArg('data', array());
             if (!isset($data['primary_modules'])) {
                 $data['primary_modules'] = array();
             }
             if (!isset($data['secondary_modules'])) {
                 $data['secondary_modules'] = array();
             }
             $config = Kurogo::getSiteConfig('navigation', 'site');
             $sections = array();
             foreach ($data['primary_modules'] as $moduleID => $title) {
                 $sections[$moduleID] = array('title' => $title);
             }
             foreach ($data['secondary_modules'] as $moduleID => $title) {
                 $sections[$moduleID] = array('type' => 'secondary', 'title' => $title);
             }
             $config->setSectionVars($sections);
             $result = Kurogo::sharedInstance()->saveConfig($config);
             $this->setResponse($result);
             $this->setResponseVersion(1);
             break;
         default:
             $this->invalidCommand();
             break;
     }
 }