public function __get($name) { switch ($name) { case 'resource': return Plugins::filter('get_stackitem_resource', $this->resource, $this); } }
/** * Ouputs the default menu in the template footer, and runs the 'habmin_bar' plugin filter. * You can add menu items via the filter. See the 'filter_habminbar' method for * an example. */ public function action_template_footer() { if ( User::identify()->loggedin ) { $bar = '<div id="habminbar"><div>'; $bar.= '<div id="habminbar-name"><a href="' . Options::get('base_url') . '">' . Options::get('title') . '</a></div>'; $bar.= '<ul>'; $menu = array(); $menu['dashboard']= array( 'Dashboard', URL::get( 'admin', 'page=dashboard' ), "view the admin dashboard" ); $menu['write']= array( 'Write', URL::get( 'admin', 'page=publish' ), "create a new entry" ); $menu['option']= array( 'Options', URL::get( 'admin', 'page=options' ), "configure site options" ); $menu['comment']= array( 'Moderate', URL::get( 'admin', 'page=comments' ),"moderate comments" ); $menu['user']= array( 'Users', URL::get( 'admin', 'page=users' ), "administer users" ); $menu['plugin']= array( 'Plugins', URL::get( 'admin', 'page=plugins' ), "activate and configure plugins" ); $menu['theme']= array( 'Themes', URL::get( 'admin', 'page=themes' ), "select a theme" ); $menu = Plugins::filter( 'habminbar', $menu ); $menu['logout']= array( 'Logout', URL::get( 'user', 'page=logout' ), "logout" ); foreach ( $menu as $name => $item ) { list( $label, $url, $tooltip )= array_pad( $item, 3, "" ); $bar.= "\n\t<li><a href=\"$url\" class=\"$name\"" . ( ( $tooltip ) ? " title=\"$tooltip\"" : "" ) .">$label</a></li>"; } $bar.= '</ul><br style="clear:both;" /></div></div>'; echo $bar; } }
/** * Serves the locale Javascript to translate javascript strings. */ public function locale_js() { header('Expires: ' . gmdate('D, d M Y H:i:s ', time() + 432000) . 'GMT'); header('content-type: text/javascript'); $domain = HabariLocale::get_messages(); $domain_json = json_encode($domain); $js = <<<TEEHEE function _t() { var domain = {$domain_json}; var s = arguments[0]; if(domain[s] != undefined) { s = domain[s][1][0]; } for(var i = 1; i <= arguments.length; i++) { r = new RegExp('%' + (i) + '\\\\\$s', 'g'); if(!s.match(r)) { r = new RegExp('%s'); } s = s.replace(r, arguments[i]); } return s; } TEEHEE; echo Plugins::filter('locale_js', $js); }
public function test_format_priority() { Format::apply(function ($v) { return $v . '7'; }, 'test_filter_7'); Format::apply(function ($v) { return $v . '8'; }, 'test_filter'); $result = Plugins::filter('test_filter', 'test'); $this->assert_equal('test78', $result); Format::apply(function ($v, $c) { return $v . '7' . $c; }, 'test_filter2_7', 'a'); Format::apply(function ($v, $c) { return $v . '8' . $c; }, 'test_filter2', 'b'); $result = Plugins::filter('test_filter2', 'test'); $this->assert_equal('test7a8b', $result); Format::apply_with_hook_params(function ($v, $h, $c) { return $v . '7' . $h . $c; }, 'test_filter3_7', 'a'); Format::apply_with_hook_params(function ($v, $h, $c) { return $v . '8' . $h . $c; }, 'test_filter3', 'b'); $result = Plugins::filter('test_filter3', 'test', 'h'); $this->assert_equal('test7ha8hb', $result); }
/** * Respond to the URL that was created * Determine the post that was supposed to be displayed, and show it in raw * @params array $handlervars An array of values passed in from the URL requested */ function action_plugin_act_plaintext($handlervars) { $activetheme = Themes::create(); $user_filters = array('fetch_fn' => 'get_row', 'limit' => 1); $page_key = array_search('page', $activetheme->valid_filters); unset($activetheme->valid_filters[$page_key]); $user_filters = Plugins::filter('template_user_filters', $user_filters); $user_filters = array_intersect_key($user_filters, array_flip($activetheme->valid_filters)); $where_filters = Controller::get_handler()->handler_vars->filter_keys($activetheme->valid_filters); $where_filters = $where_filters->merge($user_filters); $where_filters = Plugins::filter('template_where_filters', $where_filters); $post = Posts::get($where_filters); $current_url = URL::get(); $created_at = $post->pubdate->get(); header('Content-type: text/plain; charset=utf-8'); echo <<<HERE # {$post->title} By {$post->author->displayname} <{$current_url}> {$created_at} \t {$post->content} HERE; exit; }
public function __get($name) { // if there is a _ in the name, there is a filter at the end if (strpos($name, '_') !== false) { // pick off the last _'d piece preg_match('/^(.*)_([^_]+)$/', $name, $matches); list($junk, $name, $filter) = $matches; // so that we don't break every info value that has a _ in it, only _out is an acceptable filter name if ($filter != 'out') { // put it back together $name = $name . '_' . $filter; // turn off the filter $filter = false; } } else { $filter = false; } // get the value by calling our parent function directly $value = parent::__get($name); // apply the main filter so values can be altered regardless of any _filter $value = Plugins::filter("post_info_{$name}", $value); // if there is a filter, apply that specific one too if ($filter) { $value = Plugins::filter("post_info_{$name}_{$filter}", $value); } return $value; }
/** * When adding dashboard modules, the titles should remain as they're written in their providing plugin * This function adds a value for the title of the block that is the same as the name of the type of block. * The value is in _title because overwriting the main title value causes the block data to reload. * @param Block $block The block that has data stored for the title * @param Theme $theme The theme displaying this block */ public function action_block_content($block, $theme) { static $available_modules; if (!isset($available_modules)) { $available_modules = Plugins::filter('dashboard_block_list', array()); } $block->_title = $available_modules[$block->type]; }
/** * Handles GET requests for the groups page. */ public function get_groups() { // prepare the WSSE tokens $this->theme->wsse = Utils::WSSE(); $groups = UserGroups::get_all(); $this->theme->groups = Plugins::filter('admin_groups_visible', $groups); $this->display('groups'); }
/** * Handles GET requests for the import page. */ public function get_import() { // First check for troublesome plugins $bad_features = array( 'ping', 'pingback', 'spamcheck', ); $troublemakers = array(); $plugins = Plugins::list_active(); foreach( $plugins as $plugin ) { $info = Plugins::load_info( $plugin ); $provides = array(); if( isset($info->provides ) ) { foreach( $info->provides->feature as $feature ) { $provides[] = $feature; } } $has_bad = array_intersect( $bad_features, $provides ); if( count( $has_bad ) ) { $troublemakers[] = $info->name; } } if( count( $troublemakers ) ) { $troublemakers = implode( ', ', $troublemakers ); $msg = _t( 'Plugins that conflict with importing are active. To prevent undesirable consequences, please de-activate the following plugins until the import is finished: ' ) . '<br>'; $msg .= $troublemakers; $this->theme->conflicting_plugins = $msg; Session::error( $msg ); } // Now get on with creating the page $importer = isset( $_POST['importer'] ) ? $_POST['importer'] : ''; $stage = isset( $_POST['stage'] ) ? $_POST['stage'] : '1'; $step = isset( $_POST['step'] ) ? $_POST['step'] : '1'; $this->theme->enctype = Plugins::filter( 'import_form_enctype', 'application/x-www-form-urlencoded', $importer, $stage, $step ); // filter to get registered importers $importers = Plugins::filter( 'import_names', array() ); // fitler to get the output of the current importer, if one is running if ( $importer != '' ) { $output = Plugins::filter( 'import_stage', '', $importer, $stage, $step ); } else { $output = ''; } $this->theme->importer = $importer; $this->theme->stage = $stage; $this->theme->step = $step; $this->theme->importers = $importers; $this->theme->output = $output; $this->display( 'import' ); }
/** * Handles AJAX requests from the dashboard */ public function ajax_dashboard($handler_vars) { Utils::check_request_method(array('POST')); $this->create_theme(); $this->get_additem_form(); $available_modules = Plugins::filter('dashboard_block_list', array()); $user_id = User::identify()->id; $dashboard_area = 'dashboard_' . $user_id; switch ($handler_vars['action']) { case 'updateModules': $modules = $_POST['moduleOrder']; $order = 0; foreach ($modules as $module) { $order++; DB::query('UPDATE {blocks_areas} SET display_order = :display_order WHERE block_id = :id AND area = :dashboardarea', array('display_order' => $order, 'id' => $module, 'dashboardarea' => $dashboard_area)); } $ar = new AjaxResponse(200, _t('Modules updated.')); break; case 'addModule': $type = $handler_vars['module_name']; $title = $available_modules[$type]; $block = new Block(array('title' => $title, 'type' => $type)); $block->insert(); $max_display_order = DB::get_value('SELECT max(display_order) FROM {blocks_areas} WHERE area = :dashboardarea and scope_id = 0;', array('dashboardarea' => $dashboard_area)); $max_display_order++; DB::query('INSERT INTO {blocks_areas} (block_id, area, scope_id, display_order) VALUES (:block_id, :dashboardarea, 0, :display_order)', array('block_id' => $block->id, 'display_order' => $max_display_order, 'dashboardarea' => $dashboard_area)); $ar = new AjaxResponse(200, _t('Added module %s.', array($title))); $ar->html('modules', $this->theme->fetch('dashboard_modules')); break; case 'removeModule': $block_id = $handler_vars['moduleid']; DB::delete('{blocks}', array('id' => $block_id)); DB::delete('{blocks_areas}', array('block_id' => $block_id)); $ar = new AjaxResponse(200, _t('Removed module.')); $ar->html('modules', $this->theme->fetch('dashboard_modules')); break; case 'configModule': $block_id = $handler_vars['moduleid']; $block = DB::get_row('SELECT * FROM {blocks} b WHERE b.id = :id', array('id' => $block_id), 'Block'); /** Block $block */ $form = $block->get_form(); $form->_ajax = true; $form->set_option('success_message', _t('Module Configuration Saved.') . '<script type="text/javascript">window.setTimeout(function(){$(".form_message").fadeOut();}, 2000);</script>'); $control_id = new FormControlHidden('moduleid', 'null:null'); $control_id->value = $block->id; $control_id->id = 'moduleid'; $form->append($control_id); $control_action = new FormControlHidden('action', 'null:null'); $control_action->value = 'configModule'; $control_action->id = 'action'; $form->append($control_action); $form->out(); $form_id = $form->name; exit; break; } $ar->out(); }
public function __get($name) { switch ($name) { case 'resource': return Plugins::filter('get_stackitem_resource', $this->resource, $this); } trigger_error(_t('Requested property @name does not exist.', array('@name' => $name)), E_NOTICE); return null; }
/** * Test that plugins can register assets */ public function test_register_assets() { Plugins::register(array($this, 'filter_register_simple_assets'), 'filter', 'pluggable_assets'); $result = Plugins::filter('pluggable_assets', array()); $expected = $this->simple_assets; $key = 'simple_assets'; $this->assert_true(array_key_exists($key, $result), "Expected <em>{$key}</em> key to exist in <em>" . var_export($result, true) . "</em>"); $this->assert_equal($expected[$key], $result[$key], "Expected <em>" . var_export($result[$key], true) . "</em> to equal <em>" . var_export($expected[$key], true) . "</em>"); }
public static function __static() { self::$whitelist_elements = Plugins::filter('inputfilter_whitelist_elements', self::$whitelist_elements); self::$whitelist_attributes = Plugins::filter('inputfilter_whitelist_attributes', self::$whitelist_attributes); self::$elements_empty = Plugins::filter('inputfilter_elements_empty', self::$elements_empty); self::$whitelist_protocols = Plugins::filter('inputfilter_whitelist_protocols', self::$whitelist_protocols); self::$character_entities = Plugins::filter('inputfilter_character_entities', self::$character_entities); self::$character_entities_re = Plugins::filter('inputfilter_character_entities_re', self::$character_entities_re); }
public function action_init() { // gotta be an easier way of doing this $theme_dir = Plugins::filter('admin_theme_dir', Site::get_dir('admin_theme', TRUE)); $theme = Themes::create('admin', 'RawPHPEngine', $theme_dir); if (!$theme->template_exists('admincontrol_select')) { $this->add_template('admincontrol_select', dirname(__FILE__) . '/admincontrol_select.php'); } }
/** * Returns the name of the active or previewed theme * * @params boolean $nopreview If true, return the real active theme, not the preview * @return string the current theme or previewed theme's directory name */ public static function get_theme_dir($nopreview = false) { if (!$nopreview && isset($_SESSION['user_theme_dir'])) { $theme_dir = $_SESSION['user_theme_dir']; } else { $theme_dir = Options::get('theme_dir'); } $theme_dir = Plugins::filter('get_theme_dir', $theme_dir); return $theme_dir; }
/** * Handles POST requests from the options admin page */ public function post_options() { $option_items = array(); $timezones = DateTimeZone::listIdentifiers(); $timezones = array_merge(array('' => ''), array_combine(array_values($timezones), array_values($timezones))); $option_items[_t('Name & Tagline')] = array('title' => array('label' => _t('Site Name'), 'type' => 'text', 'helptext' => ''), 'tagline' => array('label' => _t('Site Tagline'), 'type' => 'text', 'helptext' => ''), 'about' => array('label' => _t('About'), 'type' => 'textarea', 'helptext' => '')); $option_items[_t('Publishing')] = array('pagination' => array('label' => _t('Items per Page'), 'type' => 'text', 'helptext' => ''), 'atom_entries' => array('label' => _t('Entries to show in Atom feed'), 'type' => 'text', 'helptext' => ''), 'comments_require_id' => array('label' => _t('Require Comment Author Info'), 'type' => 'checkbox', 'helptext' => ''), 'spam_percentage' => array('label' => _t('Comment SPAM Threshold'), 'type' => 'text', 'helptext' => _t('The likelihood a comment is considered SPAM, in percent.'))); $option_items[_t('Time & Date')] = array('timezone' => array('label' => _t('Time Zone'), 'type' => 'select', 'selectarray' => $timezones, 'helptext' => _t('Current Date Time: %s', array(HabariDateTime::date_create()->format()))), 'dateformat' => array('label' => _t('Date Format'), 'type' => 'text', 'helptext' => _t('Current Date: %s', array(HabariDateTime::date_create()->date))), 'timeformat' => array('label' => _t('Time Format'), 'type' => 'text', 'helptext' => _t('Current Time: %s', array(HabariDateTime::date_create()->time)))); $option_items[_t('Language')] = array('locale' => array('label' => _t('Locale'), 'type' => 'select', 'selectarray' => array_merge(array('' => 'default'), array_combine(HabariLocale::list_all(), HabariLocale::list_all())), 'helptext' => _t('International language code')), 'system_locale' => array('label' => _t('System Locale'), 'type' => 'text', 'helptext' => _t('The appropriate locale code for your server'))); $option_items[_t('Troubleshooting')] = array('log_min_severity' => array('label' => _t('Minimum Severity'), 'type' => 'select', 'selectarray' => LogEntry::list_severities(), 'helptext' => _t('Only log entries with a this or higher severity.')), 'log_backtraces' => array('label' => _t('Log Backtraces'), 'type' => 'checkbox', 'helptext' => _t('Logs error backtraces to the log table\'s data column. Can drastically increase log size!'))); /*$option_items[_t('Presentation')] = array( 'encoding' => array( 'label' => _t('Encoding'), 'type' => 'select', 'selectarray' => array( 'UTF-8' => 'UTF-8' ), 'helptext' => '', ), );*/ $option_items = Plugins::filter('admin_option_items', $option_items); $form = new FormUI('Admin Options'); $tab_index = 3; foreach ($option_items as $name => $option_fields) { $fieldset = $form->append('wrapper', Utils::slugify(_u($name)), $name); $fieldset->class = 'container settings'; $fieldset->append('static', $name, '<h2>' . htmlentities($name, ENT_COMPAT, 'UTF-8') . '</h2>'); foreach ($option_fields as $option_name => $option) { $field = $fieldset->append($option['type'], $option_name, $option_name, $option['label']); $field->template = 'optionscontrol_' . $option['type']; $field->class = 'item clear'; if ($option['type'] == 'select' && isset($option['selectarray'])) { $field->options = $option['selectarray']; } $field->tabindex = $tab_index; $tab_index++; if (isset($option['helptext'])) { $field->helptext = $option['helptext']; } else { $field->helptext = ''; } } } /* @todo: filter for additional options from plugins * We could either use existing config forms and simply extract * the form controls, or we could create something different */ $submit = $form->append('submit', 'apply', _t('Apply'), 'admincontrol_submit'); $submit->tabindex = $tab_index; $form->on_success(array($this, 'form_options_success')); $this->theme->form = $form->get(); $this->theme->option_names = array_keys($option_items); $this->theme->display('options'); }
/** * Add the Pingback header on single post/page requests * Not to the entire site. Clever. */ public function action_add_template_vars() { $action = Controller::get_action(); $add_header = $action == 'display_post'; $add_header = Plugins::filter('pingback_add_header', $add_header, $action); if ($add_header) { header('X-Pingback: ' . URL::get('xmlrpc')); } else { header('X-action: ' . $action); } }
/** * * A function which outputs the result of a transposed * template to the output stream * @param template $ Name of template to display */ public function display($template) { extract($this->engine_vars); if ($this->template_exists($template)) { $template_file = isset($this->template_map[$template]) ? $this->template_map[$template] : null; $template_file = Plugins::filter('include_template_file', $template_file, $template, __CLASS__); $template_file = 'hi://' . $template_file; $fc = file_get_contents($template_file); eval('?>' . $fc); //include $template_file; // stopped working properly in PHP 5.2.8 } }
/** * Handles AJAX from /admin/tags * Used to delete and rename tags */ public function ajax_tags($handler_vars) { Utils::check_request_method(array('POST')); $wsse = Utils::WSSE($handler_vars['nonce'], $handler_vars['timestamp']); if ($handler_vars['digest'] != $wsse['digest']) { Session::error(_t('WSSE authentication failed.')); echo Session::messages_get(true, array('Format', 'json_messages')); return; } $tag_names = array(); $theme_dir = Plugins::filter('admin_theme_dir', Site::get_dir('admin_theme', true)); $this->theme = Themes::create('admin', 'RawPHPEngine', $theme_dir); $action = $this->handler_vars['action']; switch ($action) { case 'delete': foreach ($_POST as $id => $delete) { // skip POST elements which are not tag ids if (preg_match('/^tag_\\d+/', $id) && $delete) { $id = substr($id, 4); $tag = Tags::get_by_id($id); $tag_names[] = $tag->term_display; Tags::vocabulary()->delete_term($tag); } } $msg_status = _n(_t('Tag %s has been deleted.', array(implode('', $tag_names))), _t('%d tags have been deleted.', array(count($tag_names))), count($tag_names)); Session::notice($msg_status); break; case 'rename': if (!isset($this->handler_vars['master'])) { Session::error(_t('Error: New name not specified.')); echo Session::messages_get(true, array('Format', 'json_messages')); return; } $master = $this->handler_vars['master']; $tag_names = array(); foreach ($_POST as $id => $rename) { // skip POST elements which are not tag ids if (preg_match('/^tag_\\d+/', $id) && $rename) { $id = substr($id, 4); $tag = Tags::get_by_id($id); $tag_names[] = $tag->term_display; } } Tags::vocabulary()->merge($master, $tag_names); $msg_status = sprintf(_n('Tag %1$s has been renamed to %2$s.', 'Tags %1$s have been renamed to %2$s.', count($tag_names)), implode($tag_names, ', '), $master); Session::notice($msg_status); break; } $this->theme->tags = Tags::vocabulary()->get_tree(); $this->theme->max = Tags::vocabulary()->max_count(); echo json_encode(array('msg' => Session::messages_get(true, 'array'), 'tags' => $this->theme->fetch('tag_collection'))); }
public function body_class() { $classes = array(); foreach (get_object_vars($this->request) as $key => $value) { if ($value) { $classes[$key] = $key; } } $classes[] = URL::get_matched_rule()->entire_match; $classes = array_unique(array_merge($classes, Stack::get_named_stack('body_class'))); $classes = Plugins::filter('body_class', $classes, $this); echo implode(' ', $classes); }
/** * Return the active rewrite rules, both in the database and applied by plugins * * @return array Array of RewriteRule objects for active rewrite rules **/ public static function get_active() { static $system_rules; if (!isset($system_rules)) { $sql = "\n\t\t\t\tSELECT rr.rule_id, rr.name, rr.parse_regex, rr.build_str, rr.handler, rr.action, rr.priority, rr.parameters\n\t\t\t\tFROM {rewrite_rules} AS rr\n\t\t\t\tWHERE rr.is_active= 1\n\t\t\t\tORDER BY rr.priority"; $db_rules = DB::get_results($sql, array(), 'RewriteRule'); $system_rules = self::add_system_rules($db_rules); } $rewrite_rules = Plugins::filter('rewrite_rules', $system_rules); $rewrite_rules = self::sort_rules($rewrite_rules); $c = __CLASS__; return new $c($rewrite_rules); }
public function __construct() { parent::__construct(); // Let's register the options page form so we can use it with ajax $self = $this; FormUI::register('admin_options', function ($form, $name, $extra_data) use($self) { $option_items = array(); $timezones = \DateTimeZone::listIdentifiers(); $timezones = array_merge(array('' => ''), array_combine(array_values($timezones), array_values($timezones))); $option_items[_t('Name & Tagline')] = array('title' => array('label' => _t('Site Name'), 'type' => 'text', 'helptext' => ''), 'tagline' => array('label' => _t('Site Tagline'), 'type' => 'text', 'helptext' => ''), 'about' => array('label' => _t('About'), 'type' => 'textarea', 'helptext' => '')); $option_items[_t('Publishing')] = array('pagination' => array('label' => _t('Items per Page'), 'type' => 'text', 'helptext' => ''), 'atom_entries' => array('label' => _t('Entries to show in Atom feed'), 'type' => 'text', 'helptext' => ''), 'comments_require_id' => array('label' => _t('Require Comment Author Email'), 'type' => 'checkbox', 'helptext' => ''), 'spam_percentage' => array('label' => _t('Comment SPAM Threshold'), 'type' => 'text', 'helptext' => _t('The likelihood a comment is considered SPAM, in percent.'))); $option_items[_t('Time & Date')] = array('timezone' => array('label' => _t('Time Zone'), 'type' => 'select', 'selectarray' => $timezones, 'helptext' => _t('Current Date Time: %s', array(DateTime::create()->format()))), 'dateformat' => array('label' => _t('Date Format'), 'type' => 'text', 'helptext' => _t('Current Date: %s', array(DateTime::create()->date))), 'timeformat' => array('label' => _t('Time Format'), 'type' => 'text', 'helptext' => _t('Current Time: %s', array(DateTime::create()->time)))); $option_items[_t('Language')] = array('locale' => array('label' => _t('Locale'), 'type' => 'select', 'selectarray' => array_merge(array('' => 'default'), array_combine(Locale::list_all(), Locale::list_all())), 'helptext' => Config::exists('locale') ? _t('International language code : This value is set in your config.php file, and cannot be changed here.') : _t('International language code'), 'disabled' => Config::exists('locale'), 'value' => Config::get('locale', Options::get('locale', 'en-us'))), 'system_locale' => array('label' => _t('System Locale'), 'type' => 'text', 'helptext' => _t('The appropriate locale code for your server'))); $option_items[_t('Troubleshooting')] = array('log_min_severity' => array('label' => _t('Minimum Severity'), 'type' => 'select', 'selectarray' => LogEntry::list_severities(), 'helptext' => _t('Only log entries with a this or higher severity.')), 'log_backtraces' => array('label' => _t('Log Backtraces'), 'type' => 'checkbox', 'helptext' => _t('Logs error backtraces to the log table\'s data column. Can drastically increase log size!'))); $option_items = Plugins::filter('admin_option_items', $option_items); $tab_index = 3; foreach ($option_items as $name => $option_fields) { /** @var FormControlFieldset $fieldset */ $fieldset = $form->append(FormControlWrapper::create(Utils::slugify(_u($name)))->set_properties(array('class' => 'container main settings'))); $fieldset->append(FormControlStatic::create($name)->set_static('<h2 class="lead">' . htmlentities($name, ENT_COMPAT, 'UTF-8') . '</h2>')); $fieldset->set_wrap_each('<div>%s</div>'); foreach ($option_fields as $option_name => $option) { /** @var FormControlLabel $label */ $label = $fieldset->append(FormControlLabel::create('label_for_' . $option_name, null)->set_label($option['label'])); /** @var FormControl $field */ $field = $label->append($option['type'], $option_name, $option_name); $label->set_for($field); if (isset($option['value'])) { $field->set_value($option['value']); } if (isset($option['disabled']) && $option['disabled'] == true) { $field->set_properties(array('disabled' => 'disabled')); } if ($option['type'] == 'select' && isset($option['selectarray'])) { $field->set_options($option['selectarray']); } $field->tabindex = $tab_index; $tab_index++; if (isset($option['helptext'])) { $field->set_helptext($option['helptext']); } } } $buttons = $form->append(new FormControlWrapper('buttons', null, array('class' => 'container'))); $buttons->append(FormControlSubmit::create('apply', null, array('tabindex' => $tab_index))->set_caption(_t('Apply'))); $form->on_success(array($self, 'form_options_success')); $form = Plugins::filter('admin_options_form', $form); }); }
public function act_request() { /* * @todo refactor this so we Posts::get() only those GUIDs requested: * array( ... 'info:any' => array( 'guid1', 'guid2', ... ) ); * @todo potentially cache individual plugins seperately, or eliminate caching all together * * @todo check against the versioin passed with guid, to only output updated version info. */ if (Cache::has('plugin_directory:plugins') && false) { $plugins = Cache::get('plugin_directory:plugins'); $from_cache = true; } else { // get the entire list of plugins from our directory based on their custom content type $plugins = Posts::get(array('content_type' => 'plugin', 'nolimit' => true)); $from_cache = false; } // build the xml output $xml = new SimpleXMLElement('<updates></updates>'); foreach ($plugins as $plugin) { if (!$plugin->versions) { continue; } // create the beacon's node $beacon_node = $xml->addChild('beacon'); $beacon_node->addAttribute('id', $plugin->info->guid); $beacon_node->addAttribute('name', $plugin->title); foreach ($plugin->versions as $version) { // create an update node for the beacon with the status' message $update_node = $beacon_node->addChild('update', $version->description); $update_node->addAttribute('severity', $version->status); $update_node->addAttribute('version', $version->version); $update_node->addAttribute('habari_version', $version->habari_version); $update_node->addAttribute('url', $version->url); } } //Utils::debug($plugins, 'Plugins'); // only cache this set of plugins if it wasn't already from the cache if ($from_cache == false) { Cache::set('plugin_directory:plugins', $plugins); } $xml = Plugins::filter('plugin_directory_beacon_xml', $xml, $this->handler_vars); $xml = $xml->asXML(); // @todo uncomment when we're actually outputting xml again ob_clean(); header('Content-Type: application/xml'); echo $xml; }
/** * Return a test-based error description for a numeric error code * @param integer $code The error code to search for * @return string A localized text-based error message. **/ private function get_message($code) { switch ($code) { //Generic XMLRPC errors case -32700: return _t('parse error. not well formed'); case -32701: return _t('parse error. unsupported encoding'); case -32702: return _t('parse error. invalid character for encoding'); case -32600: return _t('server error. invalid xml-rpc. not conforming to spec.'); case -32601: return _t('server error. requested method not found'); case -32602: return _t('server error. invalid method parameters'); case -32603: return _t('server error. internal xml-rpc error'); case -32500: return _t('application error'); case -32400: return _t('system error'); case -32300: return _t('transport error'); // Pingback errors // Pingback errors case 16: return _t('The source URI does not exist.'); case 17: return _t('The source URI does not contain a link to the target URI, and so cannot be used as a source.'); case 32: return _t('The specified target URI does not exist.'); case 33: return _t('The specified target URI cannot be used as a target.'); case 48: return _t('The pingback has already been registered.'); case 49: return _t('Access denied.'); case 50: return _t('The server could not communicate with an upstream server, or received an error from an upstream server, and therefore could not complete the request.'); // Additional standard errors // Additional standard errors case 1: return _t('This XMLRPC server only accepts POST requests.'); default: return Plugins::filter('xmlrpcexception_get_message', _t('Unknown XMLRPC Exception'), $code); } }
public function loginform_do_login($form) { $name = $form->habari_username->value; $pass = $form->habari_password->value; if (null != $name || null != $pass) { $user = User::authenticate($name, $pass); if ($user instanceof User && $user != false) { $userinfo = $user->info; // if there's an unused password reset token, unset it to make sure there's no possibility of a compromise that way if (isset($userinfo->password_reset)) { unset($userinfo->password_reset); } /* Successfully authenticated. */ // Timestamp last login date and time. $user->info->authenticate_time = DateTime::create()->format('Y-m-d H:i:s'); $user->update(); // Remove left over expired session error message. if (Session::has_errors('expired_session')) { Session::remove_error('expired_session'); } $login_session = Session::get_set('login'); if (!empty($login_session)) { /* Now that we know we're dealing with the same user, transfer the form data so he does not lose his request */ if (!empty($login_session['post_data'])) { Session::add_to_set('last_form_data', $last_form_data['post'], 'post'); } if (!empty($login_session['get_data'])) { Session::add_to_set('last_form_data', $last_form_data['get'], 'get'); } // don't bother parsing out the URL, we store the URI that was requested, so just append that to the hostname and we're done $login_dest = Site::get_url('host') . $login_session['original']; } else { $login_session = null; $login_dest = Site::get_url('admin'); } // filter the destination $login_dest = Plugins::filter('login_redirect_dest', $login_dest, $user, $login_session); // finally, redirect to the destination Utils::redirect($login_dest); return true; } /* Authentication failed. */ // Remove submitted password, see, we're secure! $form->habari_password->value = ''; $this->handler_vars['error'] = _t('Bad credentials'); } }
/** * Serves the cache page or starts the output buffer. Ignore URLs matching * the ignore list, and ignores if there are session messages. * * @see StaticCache_ob_end_flush() */ public function action_init() { /** * Allows plugins to add to the ignore list. An array of all URLs to ignore * is passed to the filter. * * @filter staticcache_ignore an array of URLs to ignore */ $ignore_array = Plugins::filter('staticcache_ignore', explode(',', Options::get('staticcache__ignore_list'))); // sanitize the ignore list for preg_match $ignore_list = implode('|', array_map(create_function('$a', 'return preg_quote(trim($a), "@");'), $ignore_array)); $request = Site::get_url('host') . $_SERVER['REQUEST_URI']; $request_method = $_SERVER['REQUEST_METHOD']; /* don't cache PUT or POST requests, pages matching ignore list keywords, * nor pages with session messages, nor loggedin users */ if ($request_method == 'PUT' || $request_method == 'POST' || preg_match("@.*({$ignore_list}).*@i", $request) || Session::has_messages() || User::identify()->loggedin) { return; } $request_id = self::get_request_id(); $query_id = self::get_query_id(); if (Cache::has(array(self::GROUP_NAME, $request_id))) { $cache = Cache::get(array(self::GROUP_NAME, $request_id)); if (isset($cache[$query_id])) { global $profile_start; // send the cached headers foreach ($cache[$query_id]['headers'] as $header) { header($header); } // check for compression // @todo directly send compressed data to browser if webserver is not compressing. if (isset($cache[$query_id]['compressed']) && $cache[$query_id]['compressed'] == true) { echo gzuncompress($cache[$query_id]['body']); } else { echo $cache[$query_id]['body']; } // record hit and profile data $this->record_stats('hit', $profile_start); exit; } } // record miss $this->record_stats('miss'); // register hook Plugins::register(array('StaticCache', 'store_final_output'), 'filter', 'final_output', 16); }
/** * Return a URL to the author's Gravatar based on his e-mail address. * * @param object $comment The Comment object to build a Gravatar URL from. * @return string URL to the author's Gravatar. */ public function filter_comment_gravatar($out, $comment) { // The Gravar ID is an hexadecimal md5 hash of the author's e-mail address. $query_arguments = array('gravatar_id' => md5(strtolower(trim($comment->email)))); // Retrieve the Gravatar options. $options = Options::get(array('gravatar__default', 'gravatar__size', 'gravatar__rating')); foreach ($options as $key => $value) { if ($value != '') { // We only want "default, size, rating". list($junk, $key) = explode('__', $key); $query_arguments[$key] = $value; } } // Ampersands need to be encoded to & for HTML to validate. $query = http_build_query($query_arguments, '', '&'); $url = "http://www.gravatar.com/avatar.php?" . $query; $url = Plugins::filter('gravatar_url', $url, $comment); return $url; }
public function save_mainmenu($form) { $base_url = Site::get_url('habari', true); $start_url = $form->mainmenus->value; /* Strip out the base URL from the requested URL */ /* but only if the base URL isn't / */ if ('/' != $base_url) { $start_url = str_replace($base_url, '', $start_url); } /* Trim off any leading or trailing slashes */ $start_url = trim($start_url, '/'); /* Remove the querystring from the URL */ if (strpos($start_url, '?') !== FALSE) { list($start_url, $query_string) = explode('?', $start_url); } /* Allow plugins to rewrite the stub before it's passed through the rules */ $start_url = Plugins::filter('rewrite_request', $start_url); $stub = $start_url; /* Grab the URL filtering rules from DB */ $matched_rule = URL::parse($stub); if ($matched_rule === FALSE) { print 'error, cant find rule'; // error!!!! } /* Return $_GET values to their proper place */ $args = array(); if (!empty($query_string)) { parse_str($query_string, $args); } $rule = $matched_rule->name; $args = array_merge($matched_rule->named_arg_values, $args); if (User::identify()->can('super_user') && $form->affect_all->value == true) { foreach (Users::get_all() as $user) { $user->info->admindetour_real = array('rule' => $rule, 'args' => $args); $user->update(); } } else { User::identify()->info->admindetour_real = array('rule' => $rule, 'args' => $args); } $_POST[$form->mainmenus->field] = URL::get($rule, $args); $form->save(); }
public function action_ajax_tag_suggest($handler) { if (!isset($handler->handler_vars['text'])) { $text = ''; } else { $text = $handler->handler_vars['text']; } $tags = array(); $tags = $this->fetch_yahoo_tags($text); $tags = serialize($tags); $tags = Plugins::filter('tag_suggestions', $tags, $text); $tags = unserialize($tags); $count = count($tags); if ($count == 0) { $message = _t('No tag suggestions could be found'); } else { $message = sprintf('%d tag ' . _n(_t('suggestion'), _t('suggestions'), $count) . ' could be found.', $count); } echo json_encode(array('count' => $count, 'tags' => $tags, 'message' => $message)); }
/** * Handles GET requests for the import page. */ public function get_import() { // First check for plugins that provide troublseome features $features_present = Plugins::provided(); $troublemakers = array(); $bad_features = array('ping', 'pingback', 'spamcheck'); $unwanted_features = array_intersect_key($features_present, array_flip($bad_features)); array_walk($unwanted_features, function ($item, $key) use(&$troublemakers) { foreach ($item as $current) { if (!in_array($current, $troublemakers)) { $troublemakers[] = $current; } } }); if (count($troublemakers)) { $troublemakers = implode(', ', $troublemakers); $msg = _t('Plugins that conflict with importing are active. To prevent undesirable consequences, please de-activate the following plugins until the import is finished: ') . '<br>'; $msg .= $troublemakers; $this->theme->conflicting_plugins = $msg; Session::error($msg); } // Now get on with creating the page $importer = isset($_POST['importer']) ? $_POST['importer'] : ''; $stage = isset($_POST['stage']) ? $_POST['stage'] : '1'; $step = isset($_POST['step']) ? $_POST['step'] : '1'; // $this->theme->enctype = Plugins::filter( 'import_form_enctype', 'application/x-www-form-urlencoded', $importer, $stage, $step ); // filter to get registered importers $importers = Plugins::filter('import_names', array()); // filter to get the output of the current importer, if one is running if ($importer == '') { $output = $this->get_form($importers, $importer); } else { $output = Plugins::filter('import_stage', '', $importer, $stage, $step); } $this->theme->importer = $importer; $this->theme->stage = $stage; $this->theme->step = $step; $this->theme->importers = $importers; $this->theme->output = $output; $this->display('import'); }