/**
     * Called from the themes page to save the blocks instances into areas
     *
     * @param mixed $handler_vars
     * @return
     */
    public function ajax_save_areas($handler_vars)
    {
        Utils::check_request_method(array('POST'));
        $area_blocks = $_POST['area_blocks'];
        $scope = $_POST['scope'];
        DB::query('DELETE FROM {blocks_areas} WHERE scope_id = :scope_id', array('scope_id' => $scope));
        foreach ((array) $area_blocks as $area => $blocks) {
            $display_order = 0;
            foreach ($blocks as $block) {
                $display_order++;
                DB::query('INSERT INTO {blocks_areas} (block_id, area, scope_id, display_order) VALUES (:block_id, :area, :scope_id, :display_order)', array('block_id' => $block, 'area' => $area, 'scope_id' => $scope, 'display_order' => $display_order));
            }
        }
        $this->setup_admin_theme('');
        $blocks_areas_t = DB::get_results('SELECT b.*, ba.scope_id, ba.area, ba.display_order FROM {blocks} b INNER JOIN {blocks_areas} ba ON ba.block_id = b.id ORDER BY ba.scope_id ASC, ba.area ASC, ba.display_order ASC', array());
        $blocks_areas = array();
        foreach ($blocks_areas_t as $block) {
            if (!isset($blocks_areas[$block->scope_id])) {
                $blocks_areas[$block->scope_id] = array();
            }
            $blocks_areas[$block->scope_id][$block->area][$block->display_order] = $block;
        }
        $this->theme->blocks_areas = $blocks_areas;
        $this->theme->scopes = DB::get_results('SELECT * FROM {scopes} ORDER BY id ASC;');
        $this->theme->active_theme = Themes::get_active_data(true);
        $this->display('block_areas');
        $msg = json_encode(_t('Saved block areas settings.'));
        echo '<script type="text/javascript">
			humanMsg.displayMsg(' . $msg . ');
			reset_block_form();
			spinner.stop();
		</script>';
    }
 function get_areas($scope)
 {
     $activedata = Themes::get_active_data(true);
     $areas = array();
     if (isset($activedata['info']->areas->area)) {
         foreach ($activedata['info']->areas->area as $area) {
             $detail = array();
             if (isset($area['title'])) {
                 $detail['title'] = (string) $area['title'];
             } else {
                 $detail['title'] = (string) $area['name'];
             }
             $detail['description'] = (string) $area->description;
             $areas[(string) $area['name']] = $detail;
         }
     }
     $areas = Plugins::filter('areas', $areas, $scope);
     return $areas;
 }
Exemple #3
0
 /**
  * Prepare and display admin page
  *
  */
 public function action_admin_theme_get_menus(AdminHandler $handler, Theme $theme)
 {
     $theme->page_content = '';
     $action = isset($_GET['action']) ? $_GET['action'] : 'create';
     switch ($action) {
         case 'edit':
             $vocabulary = Vocabulary::get_by_id(intval($handler->handler_vars['menu']));
             if ($vocabulary == false) {
                 $theme->page_content = '<h2>' . _t('Invalid Menu.');
                 // that's it, we're done. Maybe we show the list of menus instead?
                 break;
             }
             $form = new FormUI('edit_menu');
             $form->append(new FormControlText('menuname', 'null:null', _t('Name'), 'transparent_text'))->add_validator('validate_required', _t('You must supply a valid menu name'))->add_validator(array($this, 'validate_newvocab'))->value = $vocabulary->name;
             $form->append(new FormControlHidden('oldname', 'null:null'))->value = $vocabulary->name;
             $form->append(new FormControlText('description', 'null:null', _t('Description'), 'transparent_text'))->value = $vocabulary->description;
             $edit_items_array = $this->get_menu_type_data();
             $edit_items = '';
             foreach ($edit_items_array as $action => $menu_type) {
                 $edit_items .= '<a class="modal_popup_form menu_button_dark" href="' . URL::get('admin', array('page' => 'menu_iframe', 'action' => $action, 'menu' => $vocabulary->id)) . "\">" . _t('Add %s', array($menu_type['label'])) . "</a>";
             }
             if (!$vocabulary->is_empty()) {
                 $form->append('tree', 'tree', $vocabulary->get_tree(), _t('Menu'));
                 $form->tree->options = $vocabulary->get_tree();
                 $form->tree->config = array('itemcallback' => array($this, 'tree_item_callback'));
                 //						$form->tree->value = $vocabulary->get_root_terms();
                 // append other needed controls, if there are any.
                 $form->append('static', 'buttons', '<div id="menu_item_button_container">' . $edit_items . '</div>');
                 $form->append('submit', 'save', _t('Apply Changes'));
             } else {
                 $form->append('static', 'buttons', '<div id="menu_item_button_container">' . $edit_items . '</div>');
             }
             $delete_link = URL::get('admin', Utils::WSSE(array('page' => 'menus', 'action' => 'delete_menu', 'menu' => $handler->handler_vars['menu'])));
             //$delete_link = URL::get( 'admin', array( 'page' => 'menus', 'action' => 'delete_menu', 'menu' => $handler->handler_vars[ 'menu' ] ) );
             $form->append('static', 'deletebutton', '<a class="a_button" href="' . $delete_link . '">' . _t('Delete Menu') . '</a>');
             $form->append(new FormControlHidden('menu', 'null:null'))->value = $handler->handler_vars['menu'];
             $form->on_success(array($this, 'rename_menu_form_save'));
             $form->properties['onsubmit'] = "return habari.menu_admin.submit_menu_update();";
             $theme->page_content .= $form->get();
             break;
         case 'create':
             $form = new FormUI('create_menu');
             $form->append('text', 'menuname', 'null:null', _t('Menu Name'), 'transparent_text')->add_validator('validate_required', _t('You must supply a valid menu name'))->add_validator(array($this, 'validate_newvocab'));
             $form->append('text', 'description', 'null:null', _t('Description'), 'transparent_text');
             $form->append('submit', 'submit', _t('Create Menu'));
             $form->on_success(array($this, 'add_menu_form_save'));
             $theme->page_content = $form->get();
             break;
         case 'delete_menu':
             if (Utils::verify_wsse($_GET, true)) {
                 $menu_vocab = Vocabulary::get_by_id(intval($handler->handler_vars['menu']));
                 // Delete blocks using this menu
                 $at = Themes::get_active_data(true);
                 $t = Themes::create(Themes::get_active()['name']);
                 $i = 0;
                 foreach ($at['areas'] as $area) {
                     foreach ($t->get_blocks($area['name'], 0, $t) as $block) {
                         if ($block->type == 'menu' && $block->menu_taxonomy == $handler->handler_vars['menu']) {
                             $block->delete();
                             $i++;
                         }
                     }
                 }
                 Session::notice(sprintf(_n('%s block linking to this menu deleted.', '%s blocks linking to this menu deleted.', $i), $i));
                 $menu_vocab->delete();
                 // log that it has been deleted?
                 Session::notice(_t('Menu deleted.'));
                 // redirect to a blank menu creation form
                 Utils::redirect(URL::get('admin', array('page' => 'menus', 'action' => 'create')));
             } else {
                 Session::notice(_t('Menu deletion failed - please try again.'));
                 Utils::redirect(URL::get('admin', array('page' => 'menus', 'action' => 'edit', 'menu' => $handler->handler_vars['menu'])));
             }
             break;
         case 'delete_term':
             $term = Term::get(intval($handler->handler_vars['term']));
             $menu_vocab = $term->vocabulary_id;
             if (Utils::verify_wsse($_GET, true)) {
                 $term->delete();
                 // log that it has been deleted?
                 Session::notice(_t('Item deleted.'));
                 Utils::redirect(URL::get('admin', array('page' => 'menus', 'action' => 'edit', 'menu' => $menu_vocab)));
             } else {
                 Session::notice(_t('Item deletion failed - please try again.'));
                 Utils::redirect(URL::get('admin', array('page' => 'menus', 'action' => 'edit', 'menu' => $menu_vocab)));
             }
             break;
         default:
             Utils::debug($_GET, $action);
             die;
     }
     $theme->display('menus_admin');
     // End everything
     exit;
 }
 /**
  * Display the plugin administration page
  */
 public function get_plugins()
 {
     $all_plugins = Plugins::list_all();
     $active_plugins = Plugins::get_active();
     $sort_active_plugins = array();
     $sort_inactive_plugins = array();
     $providing = array();
     $available = array();
     foreach ($all_plugins as $file) {
         $plugin = array();
         $plugin_id = Plugins::id_from_file($file);
         $plugin['plugin_id'] = $plugin_id;
         $plugin['file'] = $file;
         $error = '';
         if (Utils::php_check_file_syntax($file, $error)) {
             $plugin['debug'] = false;
             $plugin['info'] = Plugins::load_info($file);
             if (array_key_exists($plugin_id, $active_plugins)) {
                 $plugin['verb'] = _t('Deactivate');
                 $pluginobj = $active_plugins[$plugin_id];
                 $plugin['active'] = true;
                 $plugin_actions = array();
                 $plugin_actions1 = Plugins::filter_id('plugin_config', $plugin_id, $plugin_actions, $plugin_id);
                 $plugin_actions = Plugins::filter('plugin_config_any', $plugin_actions1, $plugin_id);
                 $plugin['actions'] = array();
                 foreach ($plugin_actions as $plugin_action => $plugin_action_caption) {
                     if (is_numeric($plugin_action)) {
                         $plugin_action = $plugin_action_caption;
                     }
                     $action = array('caption' => $plugin_action_caption, 'action' => $plugin_action);
                     $urlparams = array('page' => 'plugins', 'configure' => $plugin_id);
                     $action['url'] = URL::get('admin', $urlparams);
                     // @locale Displayed as an icon indicating there is help text available for a plugin.
                     if ($action['caption'] == _t('?')) {
                         if (isset($_GET['configaction'])) {
                             $urlparams['configaction'] = $_GET['configaction'];
                         }
                         if ($_GET['help'] != $plugin_action) {
                             $urlparams['help'] = $plugin_action;
                         }
                         $action['url'] = URL::get('admin', $urlparams);
                         $plugin['help'] = $action;
                     } else {
                         if (isset($_GET['help'])) {
                             $urlparams['help'] = $_GET['help'];
                         }
                         $urlparams['configaction'] = $plugin_action;
                         $action['url'] = URL::get('admin', $urlparams);
                         $plugin['actions'][$plugin_action] = $action;
                     }
                 }
                 $plugin['actions']['deactivate'] = array('url' => URL::get('admin', 'page=plugin_toggle&plugin_id=' . $plugin['plugin_id'] . '&action=deactivate'), 'caption' => _t('Deactivate'), 'action' => 'Deactivate');
                 if (isset($plugin['info']->provides)) {
                     foreach ($plugin['info']->provides->feature as $feature) {
                         $providing[(string) $feature] = (string) $feature;
                     }
                 }
             } else {
                 // instantiate this plugin
                 // in order to get its info()
                 $plugin['active'] = false;
                 $plugin['verb'] = _t('Activate');
                 $plugin['actions'] = array('activate' => array('url' => URL::get('admin', 'page=plugin_toggle&plugin_id=' . $plugin['plugin_id'] . '&action=activate'), 'caption' => _t('Activate'), 'action' => 'activate'));
                 if (isset($plugin['info']->help)) {
                     if (isset($_GET['configaction'])) {
                         $urlparams['configaction'] = $_GET['configaction'];
                     }
                     if ($_GET['help'] != '_help') {
                         $urlparams['help'] = '_help';
                     }
                     // @locale Displayed as an icon indicating there is help text available for a plugin.
                     $action['caption'] = _t('?');
                     $action['action'] = '_help';
                     $urlparams = array('page' => 'plugins', 'configure' => $plugin_id);
                     $action['url'] = URL::get('admin', $urlparams);
                     $plugin['help'] = $action;
                 }
                 if (isset($plugin['info']->provides)) {
                     foreach ($plugin['info']->provides->feature as $feature) {
                         $available[(string) $feature][$plugin_id] = $plugin['info']->name;
                     }
                 }
             }
         } else {
             $plugin['debug'] = true;
             $plugin['error'] = $error;
             $plugin['active'] = false;
         }
         if (isset($this->handler_vars['configure']) && $this->handler_vars['configure'] == $plugin['plugin_id']) {
             if (isset($plugin['help']) && Controller::get_var('configaction') == $plugin['help']['action']) {
                 $this->theme->config_plugin_caption = _t('Help');
             } else {
                 if (isset($plugin['actions'][Controller::get_var('configaction')])) {
                     $this->theme->config_plugin_caption = $plugin['actions'][Controller::get_var('configaction')]['caption'];
                 } else {
                     $this->theme->config_plugin_caption = Controller::get_var('configaction');
                 }
             }
             unset($plugin['actions'][Controller::get_var('configaction')]);
             $this->theme->config_plugin = $plugin;
         } else {
             if ($plugin['active']) {
                 $sort_active_plugins[$plugin_id] = $plugin;
             } else {
                 $sort_inactive_plugins[$plugin_id] = $plugin;
             }
         }
     }
     // Get the features that the current theme provides
     $themeinfo = Themes::get_active_data();
     if (isset($themeinfo['info']->provides)) {
         foreach ($themeinfo['info']->provides->feature as $feature) {
             $providing[(string) $feature] = $feature;
         }
     }
     $providing = Plugins::filter('provided', $providing);
     foreach ($sort_inactive_plugins as $plugin_id => $plugin) {
         if (isset($plugin['info']->requires)) {
             foreach ($plugin['info']->requires->feature as $feature) {
                 if (!isset($providing[(string) $feature])) {
                     if (isset($available[(string) $feature])) {
                         $sort_inactive_plugins[$plugin_id]['available'][(string) $feature] = $available[(string) $feature];
                         if (count($sort_inactive_plugins[$plugin_id]['available'][(string) $feature]) > 1) {
                             unset($sort_inactive_plugins[$plugin_id]['actions']['activate']);
                         }
                     } else {
                         if (!isset($sort_inactive_plugins[$plugin_id]['missing'])) {
                             $sort_inactive_plugins[$plugin_id]['missing'] = array();
                         }
                         $sort_inactive_plugins[$plugin_id]['missing'][(string) $feature] = isset($feature['url']) ? $feature['url'] : '';
                         unset($sort_inactive_plugins[$plugin_id]['actions']['activate']);
                     }
                 }
             }
         }
     }
     //$this->theme->plugins = array_merge($sort_active_plugins, $sort_inactive_plugins);
     $this->theme->assign('configaction', Controller::get_var('configaction'));
     $this->theme->assign('helpaction', Controller::get_var('help'));
     $this->theme->assign('configure', Controller::get_var('configure'));
     uasort($sort_active_plugins, array($this, 'compare_names'));
     uasort($sort_inactive_plugins, array($this, 'compare_names'));
     $this->theme->active_plugins = $sort_active_plugins;
     $this->theme->inactive_plugins = $sort_inactive_plugins;
     $this->theme->plugin_loader = Plugins::filter('plugin_loader', '', $this->theme);
     $this->display('plugins');
 }
Exemple #5
0
 /**
  * Add the currently active theme's information to the list of beacons to check for updates.
  */
 private static function add_theme()
 {
     // get the active theme
     $theme = Themes::get_active_data(true);
     // name and version are required in the XML file, make sure GUID is set
     if (isset($theme['info']->guid)) {
         Update::add($theme['info']->name, $theme['info']->guid, $theme['info']->version);
     }
 }
Exemple #6
0
 /**
  * Handles GET requests for the theme listing
  */
 public function get_themes()
 {
     $all_themes = Themes::get_all_data();
     foreach ($all_themes as $name => $theme) {
         if (isset($all_themes[$name]['info']->update) && $all_themes[$name]['info']->update != '' && isset($all_themes[$name]['info']->version) && $all_themes[$name]['info']->version != '') {
             Update::add($name, $all_themes[$name]['info']->update, $all_themes[$name]['info']->version);
         }
     }
     $updates = Update::check();
     foreach ($all_themes as $name => $theme) {
         if (isset($all_themes[$name]['info']->update) && isset($updates[$all_themes[$name]['info']->update])) {
             $all_themes[$name]['info']->update = $updates[$all_themes[$name]['info']->update]['latest_version'];
         } else {
             $all_themes[$name]['info']->update = '';
         }
     }
     $this->theme->all_themes = $all_themes;
     $this->theme->active_theme = Themes::get_active_data();
     $this->theme->active_theme_dir = $this->theme->active_theme['path'];
     // If the active theme is configurable, allow it to configure
     $this->theme->active_theme_name = $this->theme->active_theme['info']->name;
     $this->theme->configurable = Plugins::filter('theme_config', false, $this->active_theme);
     $this->theme->assign('configure', Controller::get_var('configure'));
     $this->theme->display('themes');
 }
Exemple #7
0
 /**
  * Handles get requests for the system information page.
  */
 public function get_sysinfo()
 {
     $sysinfo = array();
     $siteinfo = array();
     // Assemble Site Info
     $siteinfo[_t('Habari Version')] = Version::get_habariversion();
     if (Version::is_devel()) {
         $siteinfo[_t('Habari Version')] .= " " . Version::get_git_short_hash();
     }
     $theme_info = Themes::get_active_data(true);
     $siteinfo[_t('Habari API Version')] = Version::get_apiversion();
     $siteinfo[_t('Habari DB Version')] = Version::get_dbversion();
     $siteinfo[_t('Active Theme')] = $theme_info['name'] . ' ' . $theme_info['version'];
     $siteinfo[_t('System Locale')] = Locale::get();
     $siteinfo[_t('Cache Class')] = Cache::get_class();
     $this->theme->siteinfo = $siteinfo;
     // Assemble System Info
     $sysinfo[_t('PHP Version')] = phpversion();
     $sysinfo[_t('Server Software')] = $_SERVER['SERVER_SOFTWARE'];
     $sysinfo[_t('Database')] = DB::get_driver_name() . ' - ' . DB::get_driver_version();
     $sysinfo[_t('PHP Extensions')] = implode(', ', get_loaded_extensions());
     $sysinfo[_t('PHP Configuration Settings')] = implode("<br>", Utils::get_ini_settings());
     $sysinfo[_t('Browser')] = $_SERVER['HTTP_USER_AGENT'];
     $this->theme->sysinfo = $sysinfo;
     // Assemble Class Info
     $classinfo = Utils::glob(HABARI_PATH . "/user/classes/*.php");
     if (count($classinfo)) {
         $classinfo = array_map('realpath', $classinfo);
     }
     $this->theme->classinfo = $classinfo;
     // Assemble Plugin Info
     $raw_plugins = Plugins::get_active();
     $plugins = array('system' => array(), 'user' => array(), '3rdparty' => array(), 'other' => array());
     $all_plugins = Plugins::list_all();
     foreach ($raw_plugins as $plugin) {
         $file = $plugin->get_file();
         // Catch plugins that are symlinked from other locations as ReflectionClass->getFileName() only returns the ultimate file path, not the symlink path, and we really want the symlink path
         $filename = basename($file);
         if (array_key_exists($filename, $all_plugins) && $all_plugins[$filename] != $file) {
             $file = $all_plugins[$filename];
         }
         if (preg_match('%[\\\\/](system|3rdparty|user)[\\\\/]plugins[\\\\/]%i', $file, $matches)) {
             // A plugin's info is XML, cast the element to a string. See #1026.
             $plugins[strtolower($matches[1])][(string) $plugin->info->name] = array('file' => $file, 'version' => (string) $plugin->info->version);
         } else {
             // A plugin's info is XML, cast the element to a string.
             $plugins['other'][(string) $plugin->info->name] = array('file' => $file, 'version' => (string) $plugin->info->version);
         }
     }
     $this->theme->plugins = $plugins;
     $this->theme->admin_page = _t('System Information');
     $this->display('sysinfo');
 }