Plugin Directory

Changeset 380651


Ignore:
Timestamp:
05/04/2011 10:20:24 AM (15 years ago)
Author:
linickx
Message:

Code Clean up.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • phpbb-recent-topics/trunk/phpbb_recent_topics.php

    r380628 r380651  
    99     */
    1010   
    11     require_once(WP_PLUGIN_DIR . "/phpbb-recent-topics/upgrade.php"); // before we start, check for upgrades.
     11    # before we start, check for upgrades.
     12    require_once(WP_PLUGIN_DIR . "/phpbb-recent-topics/upgrade.php");
    1213   
    13     $lnx_PRT_options = get_option('lnx_PRT_options'); // Plugin Options
     14    # Load Plugin Options from WP DB
     15    $lnx_PRT_options = get_option('lnx_PRT_options');
    1416   
    15     if (is_admin()) { // load admin stuff if we are an admin.
     17    # Only run admin code,if in admin screen.
     18    if (is_admin()) {
    1619        include_once(WP_PLUGIN_DIR . "/phpbb-recent-topics/admin.php");
    1720    }
    1821   
     22    # Go!
    1923    if ($lnx_PRT_options) { // only move on if we have options..
    2024       
     25        add_action('wp_head', 'DisplayPRTHeader'); // Hook into the WP Header
    2126       
    22             // The path to the plugin
     27        function DisplayPRTHeader() { // Filter the post content
     28           
     29            global $post;
     30           
     31            add_filter('the_content', 'DisplayPRTMagicFilter');
     32        }
    2333       
    24         define('PRTPLUGINPATH', (DIRECTORY_SEPARATOR != '/') ? str_replace(DIRECTORY_SEPARATOR, '/', dirname(__FILE__)) : dirname(__FILE__));
    25         /* * The base class */
    26         class phpbbRecentTopics {
    27             /* * The boostrap function */
    28             function bootstrap() {
    29                     // Add the installation and uninstallation hooks
    30                 $file = PRTPLUGINPATH . '/' . basename(__FILE__);
    31                
    32                     // Add the actions
    33                 add_action('wp_head', array('phpbbRecentTopics', 'DisplayPRTHeader'));
    34                
    35             }
     34        function DisplayPRTMagicFilter($content) {  // Replace magic text with list of topics
    3635           
    37             /* * The function to check for the presence of a contact form and link to it's CSS if required */
    38             function DisplayPRTHeader() {
    39                 global $post;
    40                
    41                     // Add the content filter
    42                 add_filter('the_content', array('phpbbRecentTopics', 'DisplayPRTMagicFilter'));
    43             }
    44             /* * The function to display the contact form */
    45             function DisplayPRTMagicFilter($content) {
    46                 return str_replace('{phpbb_recent_topics}', phpbbRecentTopics::DisplayPRT(), $content);
    47             }
    48             /* * The function to get the contact form's markup */
    49             function DisplayPRT() {
    50                
    51                     // Start the cache
    52                 ob_start();
    53                     // Add the contact form
    54                 require(PRTPLUGINPATH . '/display/display.php');
    55                     // Get the markup
    56                 $PRT_html = ob_get_contents();
    57                     // Cleanup
    58                 ob_end_clean();
    59                 return $PRT_html;
    60             }
    61            
    62            
    63            
     36            return str_replace('{phpbb_recent_topics}', DisplayPRT(), $content);
    6437        }
    6538       
    6639       
    67         phpbbRecentTopics::bootstrap();
     40        function DisplayPRT() {  // The standard display function
     41           
     42            ob_start(); // Start the cache
     43           
     44            require(WP_PLUGIN_DIR . "/phpbb-recent-topics/display/display.php"); // run my code.
     45           
     46            $PRT_html = ob_get_contents();
     47           
     48            ob_end_clean(); // clean cache
     49           
     50            return $PRT_html; // return output
     51        }
    6852       
    69             // legacy sidebar function
     53        # Legacy function for side bar
    7054        function phpbb_topics($LIMIT = "") {
    71             require(PRTPLUGINPATH . '/display/display.php');
     55           
     56            require(WP_PLUGIN_DIR . "/phpbb-recent-topics/display/display.php");
    7257        }
    7358       
    74        
    75             // Wiget functions...
    76        
     59        # New sidebar widget (options)
    7760        function wiget_options_phpbb_recent_topics() {
    7861           
    79             $options = $newoptions = get_option('prt_widget');
     62            $options = $newoptions = get_option('prt_widget'); // widget options
     63           
    8064            if ( $_POST["prt-submit"] ) {
    8165                $newoptions['title'] = strip_tags(stripslashes($_POST["prt-title"]));
    8266            }
     67           
    8368            if ( $options != $newoptions ) {
    8469                $options = $newoptions;
    8570                update_option('prt_widget', $options);
    8671            }
     72           
    8773            $title = attribute_escape($options['title']);
    8874            ?>
     
    9076<input type="hidden" id="prt-submit" name="prt-submit" value="1" />
    9177<?php
    92     }
     78        }
    9379   
    94     function widget_phpbb_recent_topics($args) {
     80        # New sidebar widget (display)
     81        function widget_phpbb_recent_topics($args) {
     82           
     83            # Credits to http://toni.uebernickel.info/entwicklung/wordpress/phpbb-recent-topics-widget/
     84            # for pointing out my mistake!!
     85           
     86            extract($args); // get variables
     87            $options = get_option('prt_widget'); // retrieve title
     88            $title = stripslashes($options['title']);
     89           
     90            echo $before_widget, $before_title, $title, $after_title;
     91           
     92            require(WP_PLUGIN_DIR . "/phpbb-recent-topics/display/display.php");
     93           
     94            echo $after_widget;
     95        }
    9596       
    96         # Credits to http://toni.uebernickel.info/entwicklung/wordpress/phpbb-recent-topics-widget/
    97         # for pointing out my mistake!!
     97        # Widget init function (for action below).
     98        function phpbb_recent_topics_init_widget() {
     99            if (!function_exists('register_sidebar_widget'))
     100               
     101                return;
     102           
     103            register_sidebar_widget('phpBB Recent Topics','widget_phpbb_recent_topics');
     104            register_widget_control('phpBB Recent Topics', 'wiget_options_phpbb_recent_topics', 300, 100);
     105        }
    98106       
    99             // get variables
    100         extract($args);
    101             // retrieve title
    102         $options = get_option('prt_widget');
    103         $title = stripslashes($options['title']);
    104        
    105         echo $before_widget, $before_title, $title, $after_title;
    106        
    107         require(PRTPLUGINPATH . '/display/display.php');
    108        
    109         echo $after_widget;
    110     }
    111    
    112     function phpbb_recent_topics_init_widget() {
    113         if (!function_exists('register_sidebar_widget'))
    114             return;
    115         register_sidebar_widget('phpBB Recent Topics','widget_phpbb_recent_topics');
    116         register_widget_control('phpBB Recent Topics', 'wiget_options_phpbb_recent_topics', 300, 100);
    117     }
    118    
    119    
    120     # Delay plugin execution until sidebar is loaded
    121     add_action('widgets_init', 'phpbb_recent_topics_init_widget');
     107        # Delay plugin execution until sidebar is loaded
     108        add_action('widgets_init', 'phpbb_recent_topics_init_widget');
    122109   
    123110    }
Note: See TracChangeset for help on using the changeset viewer.