示例#1
0
 /**
  * Handle all incoming XMLRPC requests.
  */
 public function act_xmlrpc_call()
 {
     if ($_SERVER['REQUEST_METHOD'] != 'POST') {
         $exception = new XMLRPCException(1);
         $exception->output_fault_xml();
         // dies here
     }
     $input = file_get_contents('php://input');
     $xml = new \SimpleXMLElement($input);
     $function = $xml->methodName;
     $params = array();
     $found_params = $xml->xpath('//params/param/value');
     if (is_array($found_params)) {
         foreach ($found_params as $param) {
             $params[] = XMLRPCUtils::decode_args($param);
         }
     }
     $returnvalue = false;
     Plugins::register(array($this, 'system_listMethods'), 'xmlrpc', 'system.listMethods');
     $returnvalue = Plugins::xmlrpc("{$function}", $returnvalue, $params, $this);
     $response = new \SimpleXMLElement('<?xml version="1.0"?' . '><methodResponse><params><param></param></params></methodResponse>');
     XMLRPCUtils::encode_arg($response->params->param, $returnvalue);
     ob_end_clean();
     header('Content-Type: text/xml;charset=utf-8');
     echo trim($response->asXML());
     exit;
 }
	/**
	 * Fetches active modules for display on the dashboard
	 */
	public function fetch_dashboard_modules()
	{
		if ( count( Modules::get_all() ) == 0 ) {
			$this->theme->modules = array();
			return;
		}

		// get the active module list
		$modules = Modules::get_active();

		if ( User::identify()->can( 'manage_dash_modules' ) ) {
			// append the 'Add Item' module
			$modules['nosort'] = 'Add Item';

			// register the 'Add Item' filter
			Plugins::register( array( $this, 'filter_dash_module_add_item' ), 'filter', 'dash_module_add_item' );
		}

		foreach ( $modules as $id => $module_name ) {
			$slug = Utils::slugify( (string) $module_name, '_' );
			$module = array(
				'name' => $module_name,
				'title' => $module_name,
				'content' => '',
				'options' => ''
				);

			$module = Plugins::filter( 'dash_module_' .$slug, $module, $id, $this->theme );

			$modules[$id] = $module;
		}

		$this->theme->modules = $modules;
	}
示例#3
0
	public function test_delete()
	{
		$group = UserGroup::get( "new test group" );

		Plugins::register( array( $this, 'filter_usergroup_delete_allow' ), 'filter','usergroup_delete_allow' );
		$this->assert_true(
			$group instanceof UserGroup,
			'Could not retrieve group named "new test group".'
		);

		$this->allow_filter = false;
		$group->delete();
		$this->assert_false(
			DB::get_value('SELECT count(*) FROM {groups} WHERE name = ?', array('new test group')) == 0,
			'Was able to delete a group despite not being allowed to do so.'
		);

		$this->allow_filter = true;
		$group->delete();
		$this->assert_true(
			DB::get_value('SELECT count(*) FROM {groups} WHERE name = ?', array('new test group')) == 0,
			'Was not able to delete a created group.'
		);

		$group = UserGroup::get( "new test group" );
		$this->assert_false(
			$group instanceof UserGroup,
			'Was able to retrieve (deleted) group named "new test group".'
		);
	}
示例#4
0
 /**
  * Called to register a format function to a plugin hook, and passes all of the hook's parameters to the Format function.
  * @param string $format A function name that exists in a Format class
  * @param string $onwhat A plugin hook to apply that Format function to as a filter
  **/
 public static function apply_with_hook_params($format, $onwhat)
 {
     if (self::$formatters == null) {
         self::load_all();
     }
     foreach (self::$formatters as $formatobj) {
         if (method_exists($formatobj, $format)) {
             $index = array_search($formatobj, self::$formatters);
             $func = '$o = Format::by_index(' . $index . ');';
             $func .= '$args = func_get_args();';
             $func .= '$args = array_merge( $args';
             $args = func_get_args();
             if (count($args) > 2) {
                 $func .= ', array_map( array( "Format", "apply_with_hook_unserialize" ),';
                 $args = array_map(array("Format", "apply_with_hook_serialize"), array_slice($args, 2));
                 $func .= 'array( ' . implode(', ', $args) . ' ))';
             }
             $func .= ');';
             $func .= 'return call_user_func_array(array($o, "' . $format . '"), $args);';
             $lambda = create_function('$a', $func);
             Plugins::register($lambda, 'filter', $onwhat);
             break;
             // We only look for one matching format function to apply.
         }
     }
 }
示例#5
0
文件: plugin.php 项目: anupom/my-blog
 /**
  * Adds a template to the default theme that is stored in a specified path.
  * Use this function as a shortcut to make available additional templates to a theme
  * from within the plugin directory.
  *
  * @param string $name The name of the template that will be displayed, sans extension
  * @param string $filename The full path of the template file used for the specified name
  * @param boolean $override If false, allow a template with the same name in the active theme directory to override this one.
  * If true, always override the active theme's template with this one.
  */
 protected function add_template($name, $filename, $override = false)
 {
     if (count($this->_added_templates) == 0) {
         Plugins::register(array(&$this, '_plugin_available_templates'), 'filter', 'available_templates');
         Plugins::register(array(&$this, '_plugin_include_template_file'), 'filter', 'include_template_file');
     }
     $this->_added_templates[$name] = array($filename, $override);
 }
示例#6
0
 /**
  * Loads a theme's metadata from an XML file in theme's
  * directory.
  *
  */
 public final function info()
 {
     static $info;
     if (!isset($info)) {
         $info = Plugins::load_info($this->get_file());
         if (isset($info->help)) {
             Plugins::register(array($this, '_help_plugin_config_plugin'), 'filter', 'plugin_config');
             Plugins::register(array($this, '_help_plugin_ui_plugin'), 'action', 'plugin_ui');
         }
     }
     return $info;
 }
示例#7
0
 /**
  * Test released assets are stored in the options
  */
 public function test_store_released_asset()
 {
     Cache::set('pluggable_assets', $this->simple_assets);
     // Releases ['simple_assets']['files']['of']);
     Plugins::register(array($this, 'filter_register_release_asset'), 'filter', 'pluggable_assets');
     Pluggable::register_assets();
     $key = 'simple_assets';
     //$expected = array($key => array('files' => array('of')));
     $result = Options::get('released_pluggable_assets');
     // Like to do this, but PHP's mushing together of arrays and dictionaries makes the keys not match
     //$this->assert_equal($expected, $result, "Expected <em>" . var_export($result, true) . "</em> to equal <em>" . var_export($expected, true) . "</em>");
     $this->assert_true(array_key_exists($key, $result) && array_key_exists('files', $result[$key]) && in_array('of', $result[$key]['files']));
 }
示例#8
0
 /**
  * Add default output filters
  **/
 public function action_init_theme()
 {
     // Apply Format::autop() to post content...
     Format::apply('autop', 'post_content_out');
     // Apply Format::autop() to comment content...
     Format::apply('autop', 'comment_content_out');
     // Apply Format::tag_and_list() to post tags...
     Format::apply('tag_and_list', 'post_tags_out');
     // Apply Format::nice_date() to post date...
     Format::apply('format_date', 'post_pubdate_out', '{F} {j}, {Y} {g}:{i}{a}');
     // Apply Format::more to post content...
     Plugins::register(array($this, 'more'), 'filter', 'post_content_out');
     // Apply Format::search_highlight to post content...
     Format::apply('search_highlight', 'post_content_out');
     //Session::error('Sample error', 'sample');
 }
 /**
  * On plugin init
  **/
 public function action_init()
 {
     $this->class_name = strtolower(get_class($this));
     foreach ($this->default_options as $name => $value) {
         $this->config[$name] = Options::get($this->class_name . '__' . $name);
     }
     if ($this->plugin_configured($this->config)) {
         $this->validate_reports($this->load_available_reports());
         // Add our template files for valid reports and register our functions
         foreach ($this->reports as $rpt => $data) {
             $this->add_template($data['slug'], $data['template']);
             // This is janky.  dynamic_dash_filter() is too.
             $this->funcs[$data['module']] = "{$rpt}";
             Plugins::register(array($this, 'dynamic_dash_filter'), 'filter', 'dash_module_' . $data['slug']);
         }
     }
 }
示例#10
0
 public function action_init()
 {
     $user = User::identify();
     if ($user->loggedin && $user->can('super_user')) {
         Stack::add('template_header_javascript', Site::get_url('scripts') . '/jquery.js', 'jquery');
         Stack::add('template_stylesheet', array($this->get_url(true) . 'hconsole.css', 'screen'));
         Stack::add('admin_stylesheet', array($this->get_url(true) . 'hconsole.css', 'screen'));
         if ($_POST->raw('hconsole_code')) {
             $wsse = Utils::WSSE($_POST['nonce'], $_POST['timestamp']);
             if ($_POST['PasswordDigest'] == $wsse['digest']) {
                 if (isset($_POST['sql']) && $_POST['sql'] == 'RUN SQL') {
                     $this->sql = rawurldecode($_POST->raw('hconsole_code'));
                     return;
                 }
                 if (isset($_POST['htmlspecial']) && $_POST['htmlspecial'] == 'true') {
                     $this->htmlspecial = true;
                 }
                 $this->code = $this->parse_code(rawurldecode($_POST->raw('hconsole_code')));
                 foreach ($this->code['hooks'] as $i => $hook) {
                     $functions = $this->get_functions($hook['code']);
                     if (empty($functions)) {
                         trigger_error("Parse Error in {$i}. No function to register.", E_USER_WARNING);
                     } else {
                         eval($hook['code']);
                         foreach ($functions as $function) {
                             if ($i == 'action_init') {
                                 call_user_func($function);
                             } else {
                                 Plugins::register($function, $hook['type'], $hook['hook']);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
示例#11
0
    /**
     * Get the block configuration form to show in a modal iframe on the themes page
     *
     */
    public function get_configure_block()
    {
        Utils::check_request_method(array('GET', 'POST'));
        $block = DB::get_row('SELECT b.* FROM {blocks} b WHERE id = :id ORDER BY b.title ASC', array('id' => $_GET['blockid']), 'Block');
        $block_form = $block->get_form();
        $block_form->set_option('success_message', '</div><div class="humanMsg" id="humanMsg" style="display: block;top: auto;bottom:-50px;"><div class="imsgs"><div id="msgid_2" class="msg" style="display: block; opacity: 0.8;"><p>' . _t('Saved block configuration.') . '</p></div></div></div>
<script type="text/javascript">
		$("#humanMsg").animate({bottom: "5px"}, 500, function(){ window.setTimeout(function(){$("#humanMsg").animate({bottom: "-50px"}, 500)},3000) })
		parent.refresh_block_forms();
</script>
<div style="display:none;">
');
        $first_control = reset($block_form->controls);
        if ($first_control) {
            $block_form->insert($first_control->name, 'fieldset', 'block_admin', _t('Block Display Settings'));
        } else {
            $block_form->append('fieldset', 'block_admin', _t('Block Display Settings'));
        }
        $block_form->block_admin->append('text', '_title', array('configure_block_title', $block), _t('Block Title:'));
        $block_form->_title->value = $block->title;
        $block_form->_title->add_validator('validate_required');
        $block_form->block_admin->append('checkbox', '_show_title', $block, _t('Display Block Title:'));
        $block_form->append('submit', 'save', _t('Save'));
        Plugins::register(array($this, 'action_configure_block_title'), 'action', 'configure_block_title');
        $this->theme->content = $block_form->get();
        $this->display('block_configure');
    }
示例#12
0
 /**
  * Assembles the main menu for the admin area.
  * @param Theme $theme The theme to add the menu to
  */
 protected function get_main_menu($theme)
 {
     $page = isset($this->handler_vars['page']) && !empty($this->handler_vars['page']) ? $this->handler_vars['page'] : 'dashboard';
     // These need to be replaced with submenus, but access to them is provided temporarily
     $createmenu = array();
     $managemenu = array();
     $createperms = array();
     $manageperms = array();
     Plugins::register(array($this, 'default_post_type_display'), 'filter', 'post_type_display', 4);
     $i = 1;
     foreach (Post::list_active_post_types() as $type => $typeint) {
         if ($typeint == 0) {
             continue;
         }
         if ($i == 10) {
             $hotkey = 0;
         } elseif ($i > 10) {
             $hotkey = FALSE;
         } else {
             $hotkey = $i;
         }
         $plural = Plugins::filter('post_type_display', $type, 'plural');
         $singular = Plugins::filter('post_type_display', $type, 'singular');
         $createperm = array('post_' . $type => ACL::get_bitmask('create'), 'post_any' => ACL::get_bitmask('create'));
         $createmenu['create_' . $typeint] = array('url' => URL::get('admin', 'page=publish&content_type=' . $type), 'title' => _t('Create a new %s', array($singular)), 'text' => $singular, 'access' => $createperm);
         $createperms = array_merge($createperms, $createperm);
         $manageperm = array('post_' . $type => array(ACL::get_bitmask('edit'), ACL::get_bitmask('delete')), 'own_posts' => array(ACL::get_bitmask('edit'), ACL::get_bitmask('delete'), 'post_any' => array(ACL::get_bitmask('edit'), ACL::get_bitmask('delete'))));
         $managemenu['manage_' . $typeint] = array('url' => URL::get('admin', 'page=posts&type=' . $typeint), 'title' => _t('Manage %s', array($plural)), 'text' => $plural, 'access' => $manageperm);
         $manageperms = array_merge($manageperms, $manageperm);
         $createmenu['create_' . $typeint]['hotkey'] = $hotkey;
         $managemenu['manage_' . $typeint]['hotkey'] = $hotkey;
         if ($page == 'publish' && isset($this->handler_vars['content_type']) && $this->handler_vars['content_type'] == $type) {
             $createmenu['create_' . $typeint]['selected'] = TRUE;
         }
         if ($page == 'posts' && isset($this->handler_vars['type']) && $this->handler_vars['type'] == $typeint) {
             $managemenu['manage_' . $typeint]['selected'] = TRUE;
         }
         $i++;
     }
     $createperms = array_merge($createperms, array('own_posts' => array(ACL::get_bitmask('create'))));
     $manageperms = array_merge($manageperms, array('own_posts' => array(ACL::get_bitmask('edit'), ACL::get_bitmask('delete'))));
     $adminmenu = array('create' => array('url' => '', 'title' => _t('Create content'), 'text' => _t('New'), 'hotkey' => 'N', 'submenu' => $createmenu), 'manage' => array('url' => '', 'title' => _t('Manage content'), 'text' => _t('Manage'), 'hotkey' => 'M', 'submenu' => $managemenu), 'comments' => array('url' => URL::get('admin', 'page=comments'), 'title' => _t('Manage blog comments'), 'text' => _t('Comments'), 'hotkey' => 'C', 'access' => array('manage_all_comments' => true, 'manage_own_post_comments' => true)), 'tags' => array('url' => URL::get('admin', 'page=tags'), 'title' => _t('Manage blog tags'), 'text' => _t('Tags'), 'hotkey' => 'A', 'access' => array('manage_tags' => true)), 'dashboard' => array('url' => URL::get('admin', 'page='), 'title' => _t('View your user dashboard'), 'text' => _t('Dashboard'), 'hotkey' => 'D'), 'options' => array('url' => URL::get('admin', 'page=options'), 'title' => _t('View and configure blog options'), 'text' => _t('Options'), 'hotkey' => 'O', 'access' => array('manage_options' => true)), 'themes' => array('url' => URL::get('admin', 'page=themes'), 'title' => _t('Preview and activate themes'), 'text' => _t('Themes'), 'hotkey' => 'T', 'access' => array('manage_theme' => true)), 'plugins' => array('url' => URL::get('admin', 'page=plugins'), 'title' => _t('Activate, deactivate, and configure plugins'), 'text' => _t('Plugins'), 'hotkey' => 'P', 'access' => array('manage_plugins' => true, 'manage_plugins_config' => true)), 'import' => array('url' => URL::get('admin', 'page=import'), 'title' => _t('Import content from another blog'), 'text' => _t('Import'), 'hotkey' => 'I', 'access' => array('manage_import' => true)), 'users' => array('url' => URL::get('admin', 'page=users'), 'title' => _t('View and manage users'), 'text' => _t('Users'), 'hotkey' => 'U', 'access' => array('manage_users' => true)), 'profile' => array('url' => URL::get('admin', 'page=user'), 'title' => _t('Manage your user profile'), 'text' => _t('My Profile'), 'hotkey' => 'Y', 'access' => array('manage_self' => true, 'manage_users' => true)), 'groups' => array('url' => URL::get('admin', 'page=groups'), 'title' => _t('View and manage groups'), 'text' => _t('Groups'), 'hotkey' => 'G', 'access' => array('manage_groups' => true)), 'logs' => array('url' => URL::get('admin', 'page=logs'), 'title' => _t('View system log messages'), 'text' => _t('Logs'), 'hotkey' => 'L', 'access' => array('manage_logs' => true)), 'logout' => array('url' => URL::get('auth', 'page=logout'), 'title' => _t('Log out of the administration interface'), 'text' => _t('Logout'), 'hotkey' => 'X'));
     $mainmenus = array_merge($adminmenu);
     foreach ($mainmenus as $menu_id => $menu) {
         // Change this to set the correct menu as the active menu
         if (!isset($mainmenus[$menu_id]['selected'])) {
             $mainmenus[$menu_id]['selected'] = false;
         }
     }
     $mainmenus = Plugins::filter('adminhandler_post_loadplugins_main_menu', $mainmenus);
     foreach ($mainmenus as $key => $attrs) {
         if ($page == $key) {
             $mainmenus[$key]['selected'] = true;
         }
     }
     $mainmenus = $this->filter_menus_by_permission($mainmenus);
     // Strip out import if no importers are available
     if (!Plugins::filter('import_names', array())) {
         unset($mainmenus['import']);
     }
     // Make submenu links default to the first available item
     foreach (array_keys($mainmenus) as $action) {
         if (!$mainmenus[$action]['url'] && !empty($mainmenus[$action]['submenu'])) {
             $default = current($mainmenus[$action]['submenu']);
             $mainmenus[$action]['url'] = $default['url'];
         }
     }
     $theme->assign('mainmenu', $mainmenus);
 }
示例#13
0
<?php

defined('SYSPATH') or die('No direct access allowed.');
Plugins::register('accountmanager.index', 'view', array('Regenerate_Plugin', 'add_to_account'));
Plugins::register('contextmanager.index', 'view', array('Regenerate_Plugin', 'add_to_context'));
Plugins::register('numbermanager.index', 'view', array('Regenerate_Plugin', 'add_to_number'));
示例#14
0
/**
 * Register a plugin file to be loaded
 *
 * @param string $path
 * @param string $function
 * @return void
 */
function osc_register_plugin($path, $function)
{
    Plugins::register($path, $function);
}
示例#15
0
 /**
  * Get the block configuration form to show in a modal iframe on the themes page
  *
  */
 public function get_configure_block()
 {
     Utils::check_request_method(array('GET', 'POST'));
     $block = DB::get_row('SELECT b.* FROM {blocks} b WHERE id = :id ORDER BY b.title ASC', array('id' => $_GET['blockid']), 'Block');
     $block_form = $block->get_form();
     $first_control = reset($block_form->controls);
     if ($first_control) {
         $block_form->insert($first_control->name, 'fieldset', 'block_admin', _t('Block Display Settings'));
     } else {
         $block_form->append('fieldset', 'block_admin', _t('Block Display Settings'));
     }
     $block_form->block_admin->append('text', '_title', array('configure_block_title', $block), _t('Block Title:'));
     $block_form->_title->value = $block->title;
     $block_form->_title->add_validator('validate_required');
     $block_form->block_admin->append('checkbox', '_show_title', $block, _t('Display Block Title:'));
     $block_form->append('submit', 'save', _t('Save'));
     Plugins::register(array($this, 'action_configure_block_title'), 'action', 'configure_block_title');
     $this->theme->content = $block_form->get();
     $this->display('block_configure');
 }
 public function action_before_act_admin()
 {
     $user = User::identify();
     if (isset($user->info->limitaccess) && $user->info->limitaccess == 0) {
         return;
     }
     Plugins::register(array($this, 'kill_admin_user'), 'action', 'admin_theme_get_user');
     Plugins::register(array($this, 'kill_admin_user'), 'action', 'admin_theme_post_user');
     $menus = $this->get_menu();
     foreach ($menus as $mk => $m2) {
         if (!Options::get('limitaccess__' . $mk)) {
             $params = Utils::get_params($m2['url']);
             $page = $params['page'];
             unset($params['page']);
             $kill = true;
             foreach ($params as $k => $v) {
                 if (Controller::get_var($k) != $v) {
                     $kill = false;
                 }
             }
             if ($page == 'user') {
                 $kill = false;
             }
             if ($kill) {
                 Plugins::register(array($this, 'kill_admin'), 'action', 'admin_theme_post_' . $page);
                 Plugins::register(array($this, 'kill_admin'), 'action', 'admin_theme_get_' . $page);
             }
         }
     }
 }
 public function initialize()
 {
     Plugins::register(array($this, 'actionInitTheme'), 'action', 'init_theme');
 }
 /**
  * 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);
 }
示例#19
0
文件: acl.php 项目: habari/system
 /**
  * Register plugin hooks
  * @static
  */
 public static function __static()
 {
     Plugins::register(array('\\Habari\\ACL', '_filter_token_description_display'), 'filter', 'token_description_display');
     Plugins::register(array('\\Habari\\ACL', '_filter_token_group_display'), 'filter', 'token_group_display');
     Plugins::register(array('\\Habari\\ACL', '_filter_permission_display'), 'filter', 'permission_display');
 }
示例#20
0
 /**
  * Регистрация плагина
  * 
  * @return \Plugin_Decorator
  */
 public function register()
 {
     Plugins::register($this);
     return $this;
 }
示例#21
0
 function test_create_a_custom_control()
 {
     Plugins::register(array($this, 'filter_available_templates'), 'filter', 'available_templates');
     Plugins::register(array($this, 'filter_include_template_file'), 'filter', 'include_template_file');
     $this->check('template', 'Template not loaded.');
     $form = new FormUI('test10');
     $form->append('custom', 'test', 'test__about', 'About');
     $form->out();
 }
示例#22
0
 /**
  * Test to make sure that a parameter in a preset can be overridden
  * Issue habari/habari#355
  */
 public function test_preset_override()
 {
     $preset_name = UUID::get();
     Plugins::register(function ($presets) use($preset_name) {
         $presets[$preset_name] = array('content_type' => 1);
         return $presets;
     }, 'filter', 'posts_get_all_presets');
     $q1 = Posts::get($preset_name);
     $expected1 = array('preset' => array(0 => $preset_name), 'content_type' => 1);
     $this->assert_associative_equal($q1->get_param_cache, $expected1, "The parameters defined for the preset aren't the same as those returned by the preset", array($q1->get_param_cache, $expected1));
     $q2 = Posts::get(array('preset' => $preset_name, 'content_type' => 2, 'status' => 'published'));
     $expected2 = array('status' => 'published', 'content_type' => 2, 'preset' => array(0 => $preset_name));
     $this->assert_associative_equal($q2->get_param_cache, $expected2, "The parameters provided to Posts::get() aren't the same as those returned", array($q2->get_param_cache, $expected2));
 }
示例#23
0
 /**
  * Called to register a format function to a plugin hook, and passes all of the hook's parameters to the Format function.
  * @param string $format A function name that exists in a Format class
  * @param string $onwhat A plugin hook to apply that Format function to as a filter
  */
 public static function apply_with_hook_params($format, $onwhat)
 {
     if (self::$formatters == null) {
         self::load_all();
     }
     $priority = 8;
     if (preg_match('#^(.+)_(\\d+)$#', $onwhat, $matches)) {
         $priority = intval($matches[2]);
         $onwhat = $matches[1];
     }
     $method = false;
     if (is_callable($format)) {
         $method = $format;
     } else {
         foreach (self::$formatters as $formatobj) {
             if (method_exists($formatobj, $format)) {
                 $method = array($formatobj, $format);
                 break;
             }
         }
     }
     if ($method) {
         $args = func_get_args();
         $args = array_slice($args, 2);
         $lambda = function () use($args, $method) {
             $filterargs = func_get_args();
             //$filterargs = array_slice($filterargs, 0, 1);
             foreach ($args as $arg) {
                 $filterargs[] = $arg;
             }
             return call_user_func_array($method, $filterargs);
         };
         Plugins::register($lambda, 'filter', $onwhat);
     }
 }
示例#24
0
 /**
  * Retrieve any system status info, if available
  */
 public static function setup_status_module()
 {
     if (isset(self::$status_data)) {
         return;
     }
     self::$status_data = Plugins::filter('dashboard_status', array());
     if (count(self::$status_data) > 0) {
         self::$available_modules['Status'] = _t('System Status');
         if (array_search(_t('System Status'), self::$active_modules) === false) {
             self::$active_modules[] = _t('System Status');
         }
         Plugins::register(array('Modules', 'filter_dash_module_status'), 'filter', 'dash_module_system_status');
     }
 }
示例#25
0
 /**
  * Register a lambda/closure as an auth_ajax dispatch function
  * @param string $name The context of the ajax URL
  * @param callable $fn The function to dispatch to
  */
 public static function register_auth_ajax($name, $fn)
 {
     Plugins::register($fn, 'action', 'auth_ajax_' . $name);
 }
示例#26
0
 /**
  * Add a rewrite rule that dispatches entirely to a plugin hook
  *
  * @param mixed $rule An old-style rewrite rule string, where quoted segments are literals and unquoted segments are variable names, OR a RewriteRule object
  * @param string $hook The suffix of the hook function: action_plugin_act_{$suffix}
  */
 public function add_rule($rule, $hook)
 {
     if (count($this->_new_rules) == 0) {
         Plugins::register(array($this, '_filter_rewrite_rules'), 'filter', 'rewrite_rules', 7);
     }
     if ($rule instanceof RewriteRule) {
         $this->_new_rules[] = $rule;
     } else {
         $this->_new_rules[] = RewriteRule::create_url_rule($rule, 'PluginHandler', $hook);
     }
 }
示例#27
0
 /**
  * Entry point for installation.  The reason there is a begin_install
  * method to handle is that conceivably, the user can stop installation
  * mid-install and need an alternate entry point action at a later time.
  */
 public function act_begin_install()
 {
     // Create a new theme to handle the display of the installer
     $this->theme = Themes::create('installer', 'RawPHPEngine', HABARI_PATH . '/system/installer/');
     /**
      * Set user selected Locale or default
      */
     $this->theme->locales = Locale::list_all();
     if (isset($_POST['locale']) && $_POST['locale'] != null) {
         Locale::set($_POST['locale']);
     } else {
         Locale::set(Config::get('locale', 'en-us'));
     }
     $this->theme->locale = Locale::get();
     $this->handler_vars['locale'] = Locale::get();
     /**
      * Check .htaccess first because ajax doesn't work without it.
      */
     if (!$this->check_htaccess()) {
         $this->handler_vars['file_contents'] = htmlentities(implode("\n", $this->htaccess()));
         $this->display('htaccess');
     }
     // Dispatch AJAX requests.
     if (isset($_POST['ajax_action'])) {
         switch ($_POST['ajax_action']) {
             case 'check_mysql_credentials':
                 self::ajax_check_mysql_credentials();
                 exit;
                 break;
             case 'check_pgsql_credentials':
                 self::ajax_check_pgsql_credentials();
                 exit;
                 break;
             case 'check_sqlite_credentials':
                 self::ajax_check_sqlite_credentials();
                 exit;
                 break;
         }
     }
     // set the default values now, which will be overriden as we go
     $this->form_defaults();
     if (!$this->meets_all_requirements()) {
         $this->display('requirements');
     }
     /**
      * Add the AJAX hooks
      */
     Plugins::register(Method::create('\\Habari\\InstallHandler', 'ajax_check_mysql_credentials'), 'ajax_', 'check_mysql_credentials');
     Plugins::register(Method::create('\\Habari\\InstallHandler', 'ajax_check_pgsql_credentials'), 'ajax_', 'check_pgsql_credentials');
     /**
      * Let's check the config.php file if no POST data was submitted
      */
     if (!file_exists(Site::get_dir('config_file')) && !isset($_POST['admin_username'])) {
         // no config file, and no HTTP POST
         $this->display('db_setup');
     }
     // try to load any values that might be defined in config.php
     if (file_exists(Site::get_dir('config_file'))) {
         include Site::get_dir('config_file');
         // check for old style config (global variable, pre-dates registry based config
         if (!Config::exists('db_connection') && isset($db_connection)) {
             // found old style config...
             // set up registry:
             Config::set('db_connection', $db_connection);
             // assign handler vars (for config file write)
             $this->set_handler_vars_from_db_connection();
             // write new config file
             if ($this->write_config_file(true)) {
                 // successful, so redirect:
                 Utils::redirect(Site::get_url('site'));
             }
         }
         if (Config::exists('db_connection')) {
             $this->set_handler_vars_from_db_connection();
         }
         // if a $blog_data array exists in config.php, use it
         // to pre-load values for the installer
         // ** this is completely optional **
         if (Config::exists('blog_data')) {
             $blog_data = Config::get('blog_data');
             foreach ($blog_data as $blog_datum => $value) {
                 $this->handler_vars[$blog_datum] = $value;
             }
         }
     }
     // now merge in any HTTP POST values that might have been sent
     // these will override the defaults and the config.php values
     $this->handler_vars = $this->handler_vars->merge($_POST);
     // we need details for the admin user to install
     if ('' == $this->handler_vars['admin_username'] || '' == $this->handler_vars['admin_pass1'] || '' == $this->handler_vars['admin_pass2'] || '' == $this->handler_vars['admin_email']) {
         // if none of the above are set, display the form
         $this->display('db_setup');
     }
     $db_type = $this->handler_vars['db_type'];
     if ((!Config::exists('db_connection') || Config::get('db_connection')->connection_string == '') && ($db_type == 'mysql' || $db_type == 'pgsql')) {
         $this->handler_vars['db_host'] = $_POST["{$db_type}_db_host"];
         $this->handler_vars['db_user'] = $_POST["{$db_type}_db_user"];
         $this->handler_vars['db_pass'] = $_POST->raw("{$db_type}_db_pass");
         $this->handler_vars['db_schema'] = $_POST["{$db_type}_db_schema"];
     }
     // we got here, so we have all the info we need to install
     // make sure the admin password is correct
     if ($this->handler_vars['admin_pass1'] !== $this->handler_vars['admin_pass2']) {
         $this->theme->assign('form_errors', array('password_mismatch' => _t('Password mis-match.')));
         $this->display('db_setup');
     }
     // don't accept emails with control characters
     if (!ctype_print($this->handler_vars['admin_email'])) {
         $this->theme->assign('form_errors', array('admin_email' => _t('Only printable characters are allowed.')));
         $this->display('db_setup');
     }
     // check whether prefix is valid
     if (isset($this->handler_vars['table_prefix']) && preg_replace('/[^a-zA-Z_]/', '', $this->handler_vars['table_prefix']) !== $this->handler_vars['table_prefix']) {
         $this->theme->assign('form_errors', array('table_prefix' => _t('Allowed characters are A-Z, a-z and "_".')));
         $this->display('db_setup');
     }
     // Make sure we still have a valid connection
     if (!call_user_func(array($this, "check_{$db_type}"))) {
         $this->display('db_setup');
     }
     // try to write the config file
     if (!$this->write_config_file()) {
         $this->theme->assign('form_errors', array('write_file' => _t('Could not write config.php file&hellip;')));
         $this->display('db_setup');
     }
     // try to install the database
     if (!$this->install_db()) {
         // the installation failed for some reason.
         // re-display the form
         $this->display('db_setup');
     }
     // Try activating plugins and themes
     $this->activate_plugins();
     $this->activate_theme();
     // Installation complete. Secure sqlite if it was chosen as the database type to use
     if ($db_type == 'sqlite') {
         if (!$this->secure_sqlite()) {
             $this->theme->sqlite_contents = implode("\n", $this->sqlite_contents());
             $this->display('sqlite');
         }
     }
     EventLog::log(_t('Habari successfully installed.'), 'info', 'default', 'habari');
     Utils::redirect(Site::get_url('site'));
 }
示例#28
0
 function test_create_a_custom_control()
 {
     $form = new FormUI('test10');
     // filter_available_templates gets called too early in the chain to use here, so this instead:
     $form->get_theme()->add_template('control.customz', 'This value gets replaced in filter_include_template_file()');
     Plugins::register(array($this, 'filter_include_template_file'), 'filter', 'include_template_file');
     $this->check('template', 'Template not loaded.');
     $form->append('custom', 'test', 'test__about');
     $form->out();
 }