private function add_rewrite_rule($name, $params)
 {
     $rule = RewriteRules::by_name($name);
     if (count($rule) == 1) {
         $rule = $rule[0];
         foreach ($params as $key => $param) {
             $rule->{$key} = $param;
         }
         $rule->update();
     } else {
         $rule = new RewriteRule($params);
         $rule->insert();
     }
 }
 /**
  * Filter function called by the plugin hook `rewrite_rules`
  * Add a new rewrite rule to the database's rules.
  *
  * Call `AccountManager::act('host-meta')` when a request for the host-meta `/.well-known/host-meta` is received.
  * Call `AccountManager::act('amcd')` when a request for the Account Manager Control Document `/amcd` is received.
  *
  * @param array $db_rules Array of rewrite rules compiled so far
  * @return array Modified rewrite rules array, we added our custom rewrite rule
  */
 public function filter_rewrite_rules($db_rules)
 {
     $db_rules[] = RewriteRule::create_url_rule('"amcd"', 'AccountManager', 'amcd');
     // This could be used for when the extant forms require extra values to work than what client-side AM provides, otherwise remove:
     $db_rules[] = RewriteRule::create_url_rule('"amcd"/method', 'AccountManager', 'amcd_method');
     return $db_rules;
 }
 /**
  * Filter function called by the plugin hook `rewrite_rules`
  * Add a new rewrite rule to the database's rules.
  *
  * Call `Sitemaps::act('Sitemap')` when a request for `sitemap.xml` is received.
  *
  * @param array $db_rules Array of rewrite rules compiled so far
  * @return array Modified rewrite rules array, we added our custom rewrite rule
  */
 public function filter_rewrite_rules($db_rules)
 {
     $db_rules[] = RewriteRule::create_url_rule('"sitemap.xml"', 'Sitemaps', 'Sitemap');
     if (function_exists('gzencode')) {
         $db_rules[] = RewriteRule::create_url_rule('"sitemap.xml.gz"', 'Sitemaps', 'SitemapGz');
     }
     return $db_rules;
 }
 public function filter_rewrite_rules($rules)
 {
     if (Options::get('lilliputian__service') == 'internal') {
         $redirect = RewriteRule::create_url_rule('"r"/url', 'UserThemeHandler', 'redirect');
         $shorten = RewriteRule::create_url_rule('"s"/url', 'UserThemeHandler', 'shorten');
         $rules[] = $redirect;
         $rules[] = $shorten;
     }
     return $rules;
 }
 /**
  * On plugin activation
  */
 public function action_plugin_activation($file)
 {
     // Don't process other plugins
     if (Plugins::id_from_file($file) != Plugins::id_from_file(__FILE__)) {
         return;
     }
     // Insert new post content types
     Post::add_new_type('project', true);
     Post::add_new_type('client', true);
     Post::add_new_type('task', true);
     if (DB::exists(DB::table('rewrite_rules'), array('action' => 'display_projects', 'name' => 'display_projects'))) {
         return;
         // do not keep adding the same rules if user disabled then re-enabled plugin
     }
     // Create new rewrite rule for showing a project
     $rule = RewriteRule::create_url_rule('"project"/{$slug}', 'UserThemeHandler', 'display_project');
     $rule->parse_regex = '%project/(?P<slug>[^/]+)/?$%i';
     $rule->build_str = 'project/{$slug}';
     $rule->description = 'Project Management System - View Project';
     $rule->insert();
     // Create new rewrite rule for showing a client
     $rule = RewriteRule::create_url_rule('"client"/{$slug}', 'UserThemeHandler', 'display_client');
     $rule->parse_regex = '%client/(?P<slug>[^/]+)/?$%i';
     $rule->build_str = 'client/{$slug}';
     $rule->description = 'Project Management System - View Client';
     $rule->insert();
     // Create new rewrite rule for showing a task
     $rule = RewriteRule::create_url_rule('"task"/{$slug}', 'UserThemeHandler', 'display_task');
     $rule->parse_regex = '%task/(?P<slug>[^/]+)/?$%i';
     $rule->build_str = 'task/{$slug}';
     $rule->description = 'Project Management System - View Task';
     $rule->insert();
     // Create new rewrite rule for showing projects
     $rule = RewriteRule::create_url_rule('"project"/{$slug}', 'UserThemeHandler', 'display_projects');
     $rule->parse_regex = '%projects/?$%i';
     $rule->build_str = 'projects';
     $rule->description = 'Project Management System - Projects';
     $rule->insert();
     // Create new rewrite rule for showing clients
     $rule = RewriteRule::create_url_rule('"client"/{$slug}', 'UserThemeHandler', 'display_clients');
     $rule->parse_regex = '%clients/?$%i';
     $rule->build_str = 'clients';
     $rule->description = 'Project Management System - Clients';
     $rule->insert();
     // Create new rewrite rule for showing tasks
     $rule = RewriteRule::create_url_rule('"task"/{$slug}', 'UserThemeHandler', 'display_tasks');
     $rule->parse_regex = '%tasks/?$%i';
     $rule->build_str = 'task';
     $rule->description = 'Project Management System - Tasks';
     $rule->insert();
 }
 /**
  * Add rewrite rules to handle locations and eventtags
  **/
 public function filter_rewrite_rules($rules)
 {
     $rules[] = RewriteRule::create_url_rule('"location"/location_name', 'PluginHandler', 'location');
     $rules[] = RewriteRule::create_url_rule('"eventtag"/eventtag_value', 'PluginHandler', 'eventtag');
     return $rules;
 }
 function filter_rewrite_rules($rules)
 {
     $rules[] = RewriteRule::create_url_rule('"randompost"', 'PluginHandler', 'randompost');
     return $rules;
 }
	/**
	 * 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 );
		}
	}
 public function filter_rewrite_rules($rules)
 {
     $rules['git_post_receive'] = RewriteRule::create_url_rule('"update"', 'PluginHandler', 'addon_update');
     return $rules;
 }
 /**
  * Filter function called by the plugin hook `rewrite_rules`
  * Add a new rewrite rule to the database's rules
  *
  * Call `OpenSearch::act('osDescription')` when a request for `content-search.xml` is received
  *
  * @param array $db_rules Array of rewrite rules filtered so far
  */
 public function filter_rewrite_rules($db_rules)
 {
     $db_rules[] = RewriteRule::create_url_rule('"opensearch.xml"', 'OpenSearch', 'osDescription');
     $db_rules[] = new RewriteRule(array('name' => 'opensearch', 'parse_regex' => '%^search(?:/(?P<criteria>[^/]+))?(?:/page/(?P<page>\\d+))?(?:/count/(?P<count>\\d+))?/atom/?$%i', 'build_str' => 'search(/{$criteria})(/page/{$page})/atom', 'handler' => 'OpenSearch', 'action' => 'search', 'priority' => 8, 'is_active' => 1, 'rule_class' => RewriteRule::RULE_CUSTOM, 'description' => 'Searches posts'));
     return $db_rules;
 }
 /**
  * Filter function called by the plugin hook `rewrite_rules`
  * Add a new rewrite rule to the database's rules.
  *
  *
  * @param array $db_rules Array of rewrite rules compiled so far
  * @return array Modified rewrite rules array, we added our custom rewrite rule
  */
 public function filter_rewrite_rules($db_rules)
 {
     $db_rules[] = RewriteRule::create_url_rule('"events"', 'partyTime', 'display_calendar');
     return $db_rules;
 }
 function filter_rewrite_rules($rules)
 {
     //		$rules[] = new RewriteRule( array(
     //			'name' => 'fruit',
     //			'parse_regex' => '%fruit/(?P<fruit>.+)/?$%i',
     //			'build_str' => 'fruit/{$fruit}',
     //			'handler' => 'PluginHandler',
     //			'action' => 'fruit',
     //			'priority' => 7,
     //			'is_active' => 1,
     //			'description' => 'Displays the fruit page',
     //		));
     $rules[] = RewriteRule::create_url_rule('"fruit"/fruit_name', 'PluginHandler', 'fruit');
     return $rules;
 }
 function filter_rewrite_rules($rules)
 {
     $rules[] = RewriteRule::create_url_rule('"auth"/"twitter"/"go"', 'PluginHandler', 'auth_twitter_go');
     $rules[] = RewriteRule::create_url_rule('"auth"/"twitter"/"verify"', 'PluginHandler', 'auth_twitter_verify');
     return $rules;
 }
    /**
     * Imports a single post from the s9y database into the 
     * habari database.
     *
     * Note that this function calls import_comment() for each
     * comment attached to the imported post
     *
     * @param		post_info					QueryRecord of imported post information
     * @param		habari_user_id		The habari user ID of the post's author
     * @return	TRUE or FALSE if import of post succeeded
     */
    private function import_post($post_info = array(), $habari_user_id)
    {
        /* 
         * Import the post itself 
         */
        $post = new Post();
        $post->user_id = $habari_user_id;
        $post->guid = $post->guid;
        /* @TODO: This works to create a GUID, but man, it's weird. */
        $post->info->s9y_id = $post_info->id;
        $post->title = $this->transcode($post_info->title);
        $content = empty($post_info->extended) ? $post_info->body : $post_info->body . $post_info->extended;
        $post->content = $this->transcode($content);
        $post->status = $post_info->isdraft == "true" ? Post::status('draft') : Post::status('published');
        $post->content_type = Post::type('entry');
        $post->updated = date('Y-m-d H:i:s', $post_info->last_modified);
        $post->pubdate = $post_info->isdraft == "false" ? date('Y-m-d H:i:s', $post_info->timestamp) : NULL;
        if ($this->category_import && isset($categories) && $categories instanceof QueryRecord) {
            $post->tags = $categories->to_array();
        }
        if ($post->insert()) {
            if ($this->port_rewrites) {
                $rewrite = new RewriteRule(array('name' => 'from_s9yimporter_' . $post_info->id, 'parse_regex' => '%^archives/' . $post_info->id . '-(?P<r>.*)$%i', 'build_str' => $post->slug . '(/{$p})', 'handler' => 'actionHandler', 'action' => 'redirect', 'priority' => 1, 'is_active' => 1, 'rule_class' => RewriteRule::RULE_CUSTOM, 'description' => 'redirects /archives/' . $post_info->id . ' to /' . $post->slug));
                $rewrite->insert();
            }
            /*
             * If we are going to import taxonomy, , then first check to see if 
             * this post has any categories attached to it, and import the relationship
             * using the cached habari->s9y tag map. 
             *
             * mysql> desc s9y_entrycat;
             * +------------+---------+------+-----+---------+-------+
             * | Field      | Type    | Null | Key | Default | Extra |
             * +------------+---------+------+-----+---------+-------+
             * | entryid    | int(11) | NO   | PRI | 0       |       | 
             * | categoryid | int(11) | NO   | PRI | 0       |       | 
             * +------------+---------+------+-----+---------+-------+
             */
            $result = TRUE;
            if ($this->category_import) {
                $sql = <<<ENDOFSQL
SELECT c.categoryid
FROM {$this->s9y_db_prefix}category c 
INNER JOIN {$this->s9y_db_prefix}entrycat ec
ON c.categoryid = ec.categoryid
AND ec.entryid = ?
ENDOFSQL;
                if (FALSE !== ($categories = $this->s9ydb->get_results($sql, array($post_info->id), 'QueryRecord'))) {
                    foreach ($categories as $category) {
                        $result &= $this->import_post_category($post->id, $this->imported_categories[$category->categoryid]);
                        if ($this->port_rewrites && !isset($this->rewritten_categories[$category->categoryid])) {
                            // rss feed link:
                            $this->rewritten_categories[$category->categoryid] = 1;
                            $rew_url = URL::get('atom_feed_tag', array('tag' => $this->imported_category_names[$category->categoryid]), true, false, false);
                            $rewrite = new RewriteRule(array('name' => 'from_s9yimporter_category_feed', 'parse_regex' => '%^feeds/categories/' . $category->categoryid . '-(?P<r>.*)$%i', 'build_str' => $rew_url . '(/{$p})', 'handler' => 'actionHandler', 'action' => 'redirect', 'priority' => 1, 'is_active' => 1, 'rule_class' => RewriteRule::RULE_CUSTOM, 'description' => 'redirects s9y category feed to habari feed'));
                            $rewrite->insert();
                        }
                    }
                }
            }
            /* 
             * Grab the comments and insert `em 
             *  
             * mysql> desc s9y_comments;
             * +------------+----------------------+------+-----+---------+----------------+
             * | Field      | Type                 | Null | Key | Default | Extra          |
             * +------------+----------------------+------+-----+---------+----------------+
             * | id         | int(11)              | NO   | PRI | NULL    | auto_increment | 
             * | entry_id   | int(10) unsigned     | NO   | MUL | 0       |                | 
             * | parent_id  | int(10) unsigned     | NO   | MUL | 0       |                | 
             * | timestamp  | int(10) unsigned     | YES  |     | NULL    |                | 
             * | title      | varchar(150)         | YES  |     | NULL    |                | 
             * | author     | varchar(80)          | YES  |     | NULL    |                | 
             * | email      | varchar(200)         | YES  |     | NULL    |                | 
             * | url        | varchar(200)         | YES  |     | NULL    |                | 
             * | ip         | varchar(15)          | YES  |     | NULL    |                | 
             * | body       | text                 | YES  |     | NULL    |                | 
             * | type       | varchar(100)         | YES  | MUL | regular |                | 
             * | subscribed | enum('true','false') | NO   |     | true    |                | 
             * | status     | varchar(50)          | NO   | MUL |         |                | 
             * | referer    | varchar(200)         | YES  |     | NULL    |                | 
             * +------------+----------------------+------+-----+---------+----------------+
             */
            $sql = <<<ENDOFSQL
SELECT
\tid
, parent_id
, `timestamp`
, title
, author
, email
, url
, ip
, body
, type
, subscribed
, status
, referer
FROM {$this->s9y_db_prefix}comments
WHERE entry_id = ?
ENDOFSQL;
            if ($this->comments_ignore_unapproved) {
                $sql .= " AND status = 'Approved' ";
            }
            $comments = $this->s9ydb->get_results($sql, array($post_info->id), 'QueryRecord');
            if (count($comments) > 0) {
                echo "Starting import of <b>" . count($comments) . "</b> comments for post \"" . $post->title . "\"...";
                foreach ($comments as $comment) {
                    $result &= $this->import_comment($comment, $post->id);
                }
                if ($result) {
                    echo $this->success_html() . "<br />";
                } else {
                    echo $this->fail_html() . "<br />";
                }
                return $result;
            } else {
                return TRUE;
            }
        } else {
            /* Something went wrong on $post->insert() */
            EventLog::log($e->getMessage(), 'err', null, null, print_r(array($post, $e), 1));
            Session::error($e->getMessage());
            return FALSE;
        }
    }
 public function filter_rewrite_rules($db_rules)
 {
     $db_rules[] = RewriteRule::create_url_rule('"tc_unsubscribe"', 'ThreadedComment', 'unsubscribe');
     return $db_rules;
 }