source: plugins/diggbarblocker/trunk/diggbarblocker.plugin.php @ 3966

Revision 3966, 3.0 KB checked in by lildude, 6 months ago (diff)

plugin:diggbarblocker Removed update_check() func and moved guid to xml file. Moved help to xml file. Updated config functionality to use 0.7 functionality better

Line 
1<?php
2/**
3 * DiggBar Blocker Plugin
4 *
5 * Inspired by http://daringfireball.net/2009/04/how_to_block_the_diggbar
6 **/
7
8class DiggbarBlocker extends Plugin
9{
10        /**
11         * Add actions to the plugin page for this plugin
12         * @param array $actions An array of actions that apply to this plugin
13         * @param string $plugin_id The string id of a plugin, generated by the system
14         * @return array The array of actions to attach to the specified $plugin_id
15         **/
16        public function filter_plugin_config( $actions )
17        {
18                $actions['configure'] = _t( 'Configure' );
19                return $actions;
20        }
21
22        /**
23         * Respond to the user selecting an action on the plugin page
24         * @param string $plugin_id The string id of the acted-upon plugin
25         * @param string $action The action string supplied via the filter_plugin_config hook
26         **/
27        public function action_plugin_ui_configure()
28        {
29                $ui = new FormUI( strtolower( get_class( $this ) ) );
30                $reload_fieldset = $ui->append( 'fieldset', 'reload', _t( 'No Message' ) );
31                       
32                $reload_page = $reload_fieldset->append( 'checkbox', 'reload', 'option:diggbarblocker__reload', 
33                        _t( 'Instead of displaying a message, reload the page without the bar' ) );
34
35                $message_fieldset = $ui->append( 'fieldset', 'message_settings', _t( 'Message Settings' ) );
36                $message = $message_fieldset->append( 'textarea', 'message', 'option:diggbarblocker__message', 
37                        _t( 'If the box above is not checked, display this to Diggbar-using visitors:' ) );
38                $message->rows = 2;
39                $message->class[] = 'resizable';
40
41                $link = $message_fieldset->append( 'checkbox', 'addlink', 'option:diggbarblocker__addlink',
42                        _t( 'Add a link to the target page.' ) );
43
44                $ui->append( 'submit', 'save', _t( 'Save' ) );
45                $ui->out();
46        }
47
48        /**
49         * Set default text & link behavior
50         **/
51        public function action_plugin_activation( $file )
52        {
53                if ( Plugins::id_from_file($file) == Plugins::id_from_file(__FILE__) ) {
54                        if ( Options::get( 'diggbarblocker__message' ) == null ) {
55                                Options::set( 'diggbarblocker__message', _t( 'This site does not support use of the DiggBar.' ) );
56                        }
57                        if ( Options::get( 'diggbarblocker__add_link' ) == null ) {
58                                Options::set( 'diggbarblocker__addlink', 1 ); 
59                        }
60                }
61        }
62
63        /**
64         * Return either a message for the Diggbar user, or just reload the page.
65         * @return string buffer of either the message displayed, or reload headers.
66         **/
67        public function filter_final_output( $buffer )
68        {
69                if ( preg_match( '#http://digg.com/\w{1,8}/*(\?.*)?$#', $_SERVER[ 'HTTP_REFERER' ]) ) {
70                        if ( Options::get( 'diggbarblocker__reload' ) ) {
71                                $buffer = '<SCRIPT TYPE="text/JavaScript">
72        if (window != top) {
73                top.location.replace( self.location.href );
74        }
75</SCRIPT>';
76                        } else
77                        {       
78                                $buffer = '<p>' . Options::get( 'diggbarblocker__message' ) .'</p>' . 
79                                        ( Options::get( 'diggbarblocker__addlink' ) ? 
80                                        _t( '<p>Open <a title="Open in a new window" target="_top" href="') . $_SERVER[ 'SCRIPT_URI' ] . '">' .
81                                        $_SERVER[ 'SCRIPT_URI' ] . _t('</a> in a new tab or window to view it.</p>') : '');
82                        }       
83                }
84                return $buffer;
85        }
86}
87
88?>
Note: See TracBrowser for help on using the repository browser.