'Publish Quote', 'license' => 'Apache License 2.0', 'url' => 'http://twofishcreative.com/publish_quote/', 'author' => 'Michael C. Harris', 'authorurl' => 'http://twofishcreative.com/michael/blog/', 'version' => '0.1alpha', 'description' => 'Allows users to post quotes with a bookmarklet', 'copyright' => '2008' ); } /** * Create the bookmarklet that is appropriate for the client's User Agent * @return array The array of actions to attach to the specified $plugin_id **/ private function get_bookmarklet() { $admin_url= Site::get_url('admin'); $link_name= Options::get('title'); // TODO: Only handles Firefox. How do I detect browser capabilities? $bookmarklet= "Quote on {$link_name}"; return $bookmarklet; } public function updated_config($ui) { return false; } /** * Add actions to the plugin page for this plugin * @param array $actions An array of actions that apply to this plugin * @param string $plugin_id The string id of a plugin, generated by the system * @return array The array of actions to attach to the specified $plugin_id **/ public function filter_plugin_config($actions, $plugin_id) { if ( $plugin_id == $this->plugin_id() ) { $actions[]= 'Create Bookmarklet'; } return $actions; } /** * Respond to the user selecting an action on the plugin page * @param string $plugin_id The string id of the acted-upon plugin * @param string $action The action string supplied via the filter_plugin_config hook **/ public function action_plugin_ui($plugin_id, $action) { if ( $plugin_id == $this->plugin_id() ) { switch ( $action ) { case 'Create Bookmarklet' : echo "Bookmark this link: "; echo $this->get_bookmarklet(); break; } } } public function filter_publish_controls($controls) { // Using filter_publish_controls because it's in a convenient spot // If quote has been sent in the URL, add a filter to insert text in the post $this->handler_vars= Controller::get_handler_vars(); if ( array_key_exists('quote', $this->handler_vars) ) { Plugins::register( array( $this, 'add_quote_to_post'), 'filter', 'post_content', 1 ); } // Return $controls unmolested return $controls; } public function add_quote_to_post($content, $post) { $quote= $this->handler_vars['quote']; $url= $this->handler_vars['url']; $title= $this->handler_vars['title']; // TODO: I'd like the user to be able to change this HTML without hacking the code $content= <<< QUOTE
$quote
$title QUOTE; return $content; } public function action_update_check() { Update::add( 'Publish Quote', 'ac3d6784-57c2-4dfa-9c24-3a09d0296a6f', $this->info->version ); } } ?>