Plugin Directory

Changeset 3451348


Ignore:
Timestamp:
02/01/2026 11:43:40 AM (8 weeks ago)
Author:
Workshopshed
Message:

Version 2 for PHP 8

Location:
rssfeedchecker
Files:
12 added
8 edited

Legend:

Unmodified
Added
Removed
  • rssfeedchecker/trunk/RSSFeedChecker.php

    r1571999 r3451348  
    44Plugin URI: #
    55Description: Checks your links RSS feeds and stores the date that it was last modified so that it can be used in a Links RSS Enhanced widget
    6 Version: 1.1
     6Version: 2.0
    77Author: Andy Clark.
    88Author URI: #
     
    8989    } 
    9090   
    91     /**
    92      * Timing function
    93      */
    94     $version = explode('.', PHP_VERSION);
    95 
    96     if ($version[0] < 5) {
    97         if ( !function_exists( 'microtime_float' ) ) {
    98             function microtime_float()
    99             {
    100                 list($usec, $sec) = explode(" ", microtime());
    101                 return ((float)$usec + (float)$sec);
    102             }
    103         }
    104     }
    105     else {
    106         if ( !function_exists( 'microtime_float' ) ) {
    107             function microtime_float()
    108             {
    109                 return  microtime(true);
    110             }
    111         }
    112     }
    113    
    11491    //Instantiate the plugin
    11592    RSSChecker::init();
  • rssfeedchecker/trunk/RSSFeedCheckerDB.php

    r1571999 r3451348  
    3737            global $wpdb;
    3838           
    39             $wpdb->update( $wpdb->links , array('link_updated' => Date("Y-m-d H:i:s")), array('link_id' => $link_ID) );
     39            $wpdb->update( $wpdb->links , array('link_updated' => gmdate("Y-m-d H:i:s")), array('link_id' => $link_ID) );
    4040           
    4141            $tblrss = $wpdb->prefix . self::$tablename;
    42             $rss = $wpdb->get_var("SELECT link_rss FROM $wpdb->links where link_id = $link_ID" );
    43             $rowexists = $wpdb->get_var("SELECT COUNT(link_id) FROM $tblrss where link_id = $link_ID" );
     42            $rss = $wpdb->get_var( $wpdb->prepare("SELECT link_rss FROM $wpdb->links where link_id = %d", $link_ID) );
     43            $rowexists = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(link_id) FROM $tblrss where link_id = %d", $link_ID) );
    4444           
    4545            //If source RSS is now blank then delete
     
    6060        static function rss_list($count) {
    6161        //Return an array? of upto $count links
    62             global $wpdb;
    63             $tblrss = $wpdb->prefix . self::$tablename;
    64             $links=$wpdb->get_results("SELECT l.link_id,l.link_name,l.link_url,rss_address,latest_item_url,latest_item_title,last_updated FROM $tblrss r inner join $wpdb->links l on r.link_id = l.link_id where latest_item_url is not null and l.link_visible = 'Y' order by last_updated desc limit 0, $count");
    65             return $links;         
     62        global $wpdb;
     63        $tblrss = $wpdb->prefix . self::$tablename;
     64        $count = absint($count);  // Sanitize
     65        $links = $wpdb->get_results( $wpdb->prepare("SELECT l.link_id,l.link_name,l.link_url,rss_address,latest_item_url,latest_item_title,last_updated FROM $tblrss r inner join $wpdb->links l on r.link_id = l.link_id where latest_item_url is not null and l.link_visible = 'Y' order by last_updated desc limit 0, %d", $count) );
     66        return $links;   
    6667        }
    6768       
     
    7374        static function rss_getlink($linkid) {
    7475        //Return the rss details of the selected link
    75             global $wpdb;
    76             $tblrss = $wpdb->prefix . self::$tablename;
    77             $rss=$wpdb->get_row("SELECT link_id,rss_address,last_checked,last_updated,latest_item_url,latest_item_title FROM $tblrss where link_id = $linkid");
    78             return $rss;
     76        global $wpdb;
     77        $tblrss = $wpdb->prefix . self::$tablename;
     78        $rss = $wpdb->get_row( $wpdb->prepare("SELECT link_id,rss_address,last_checked,last_updated,latest_item_url,latest_item_title FROM $tblrss where link_id = %d", $linkid) );
     79        return $rss;
    7980        }       
    8081       
     
    9091        static function rss_countpending(){
    9192        //count those that have not been "recently" checked
    92             global $wpdb;
     93            global $wpdb;
    9394            $tblrss = $wpdb->prefix . self::$tablename;
    9495            $datebefore = self::datebefore();
    95             $rss = $wpdb->get_var("SELECT count(*) FROM $tblrss where last_checked < '$datebefore'" );
     96            $rss = $wpdb->get_var( $wpdb->prepare("SELECT count(*) FROM $tblrss where last_checked < %s", $datebefore) );
    9697            return $rss;
    9798        }
     
    100101        {
    101102            //What is the date before which we need to check dates again?
    102             $date = new DateTime();
    103103            $hours = RSSCheckerSettings::get_freq();
    104             $mod = sprintf('-%d hours',$hours);
    105             $date->modify($mod);
    106             return $date->format('Y-m-d H:i:s');
    107            
     104            $timestamp = strtotime(sprintf('-%d hours', $hours));
     105            return gmdate('Y-m-d H:i:s', $timestamp);
    108106        }
    109107       
     
    138136            global $wpdb;
    139137            $tblrss = $wpdb->prefix . self::$tablename;
    140            
    141             $tablecheck = $wpdb->get_var("SELECT Table_Name FROM information_schema.TABLES WHERE Table_Name = '$tblrss'" );
    142             if (empty($tablecheck))
    143             {
     138            $tablecheck = $wpdb->get_var( $wpdb->prepare("SELECT Table_Name FROM information_schema.TABLES WHERE Table_Name = %s", $tblrss) );
     139            if (empty($tablecheck)) {
    144140                do_action('RSSStatus',__('RSS Links table missing','rssfeedchecker'));
    145141                return false;
    146142            }
    147          
    148143            return true;
    149144         }
  • rssfeedchecker/trunk/RSSFeedCheckerProcessor.php

    r1571999 r3451348  
    2929       //Loosly based on broken link checker work function
    3030       
    31        $execution_start_time = microtime_float(true);
     31       $execution_start_time = microtime(true);
    3232       $max_execution_time = RSSCheckerSettings::get_max_run()*1000;
    3333       
     
    4343            return -3; //Nothing to process
    4444       }
    45        if (microtime_float(true) - $execution_start_time > $max_execution_time) {
     45       if (microtime(true) - $execution_start_time > $max_execution_time) {
    4646            return -4; //Timeout
    4747       }
     
    5858               $run = -3;
    5959            }
    60             if (microtime_float(true) - $execution_start_time > $max_execution_time) {
     60            if (microtime(true) - $execution_start_time > $max_execution_time) {
    6161               $run = -4;
    6262            }           
     
    120120            do_action('RSSStatus',sprintf(__('Processing feed: %s','rssfeedchecker'),$rssitem->rss_address));
    121121           
    122             $rssitem->last_checked = Date("Y-m-d H:i:s");
     122            $rssitem->last_checked = gmdate("Y-m-d H:i:s");
    123123           
    124124            $url = $rssitem->rss_address;
     
    157157       
    158158   /**
    159     * From Broken Link Checker
     159   * From Broken Link Checker
    160160   * Get the server's load averages.
    161161   *
    162    * Returns an array with three samples - the 1 minute avg, the 5 minute avg, and the 15 minute avg.
     162   * Returns the 1 minute avg load from the server, sys_getloadavg returns 1 min, 5 min and 15min timings.
    163163   *
    164164   * @param integer $cache How long the load averages may be cached, in seconds. Set to 0 to get maximally up-to-date data.
    165165   * @return array|null Array, or NULL if retrieving load data is impossible (e.g. when running on a Windows box).
    166166   */
    167     function get_server_load($cache = 5){
     167    static function get_server_load($cache = 5){
    168168        static $cached_load = null;
    169169        static $cached_when = 0;
    170170       
    171171        if ( !empty($cache) && ((time() - $cached_when) <= $cache) ){
    172               floatval(reset($cached_load));
     172              return floatval(reset($cached_load));
    173173        }
    174174       
    175175        $load = null;
    176176       
    177         if ( function_exists('sys_getloadavg') ){
    178             $load = sys_getloadavg();
    179         } else {
    180             $loadavg_file = '/proc/loadavg';
    181             if (@is_readable($loadavg_file)) {
    182                 $load = explode(' ',file_get_contents($loadavg_file));
    183                 $load = array_map('floatval', $load);
    184             }
    185         }
    186        
    187         $cached_load = $load;
     177        if (!function_exists('sys_getloadavg') ){
     178            return null;
     179        }
     180        $load = sys_getloadavg();
     181
     182        $cached_load = $load;
    188183        $cached_when = time();
    189184        return floatval(reset($load));
     
    195190   * @return bool
    196191   */
    197     function server_too_busy(){
     192    static function server_too_busy(){
    198193        if ( !RSSCheckerSettings::get_loadlimit() ){
    199194            return false;
  • rssfeedchecker/trunk/RSSFeedCheckerSchedule.php

    r1571999 r3451348  
    4646       
    4747        static function getnext(){
     48            // WP Cron stores timestamps as UTC
    4849            $mycron = self::getschedule();
    4950            if (isset( $mycron )){
  • rssfeedchecker/trunk/RSSFeedCheckerSettings.php

    r1571999 r3451348  
    4747        static function show_loadlimit()
    4848        {
    49             self::form_input_text('serverload','RSSChecker[serverload]','Limit this process if server is busy (0.10 - 5.00)',self::get_loadlimit());
     49            self::form_input_text('serverload','RSSChecker[serverload]','Limit this process if server is busy (0.10 - 25.00)',self::get_loadlimit());
    5050        }                 
    5151   
     
    6969            $options['timeout'] = self::validate_range($input['timeout'],10,60);   
    7070            $options['maxrun'] = self::validate_range($input['maxrun'],10,360);
    71             $options['serverload'] = self::validate_range($input['serverload']*100.0,10,500)/100.0;  //floar
     71            $options['serverload'] = self::validate_range($input['serverload']*100.0,10,2500)/100.0;  //float
    7272            return $options;
    7373        }
     
    7777        {
    7878            $options = get_option('RSSChecker');
    79             $dbver = $options['dbversion'];
    80             if (empty($dbver)){
    81                 $dbver = '1.0.0';
    82             }
     79            $dbver = isset($options['dbversion']) ? $options['dbversion'] : '1.0.0';
    8380            return $dbver;
    8481        }
  • rssfeedchecker/trunk/RSSFeedCheckerUI.php

    r1571999 r3451348  
    146146        }
    147147
    148         static function formatdate($date)
     148        static function formatdate($timestamp)
    149149        {
    150             return date(get_option('date_format'),$date).' '.date('H:i:s',$date);
     150            // Input is unixtime timestamp
     151            // Output is formatted date/time in blog timezone
     152            return wp_date(get_option('date_format'),$timestamp).' '.date('H:i:s',$timestamp);
    151153        }
    152154       
     
    156158                $nonce = $_POST['check'];
    157159                $ajaxsuccess = true;
     160                $message = '';
    158161               
    159                 $execution_start_time = microtime_float(true);
     162                $execution_start_time = microtime(true);
    160163               
    161164                if ( ! wp_verify_nonce( $nonce, 'RSSChecker-nonce' ) )  {
     
    194197                               'running' => RSSCheckerProcessor::running(),
    195198                               'dbver' => RSSCheckerSettings::db_version(),
    196                                'duration' => microtime_float(true) - $execution_start_time,
     199                               'duration' => microtime(true) - $execution_start_time,
    197200                               'workresult' => $workresult )
    198201                        );
     
    235238                     }
    236239                }               
    237              
     240                // Convert UTC datetime strings to local time timestamps
     241                $lastupdate_timestamp = !empty($rssitem->last_updated) && $rssitem->last_updated !== '0000-00-00 00:00:00'
     242                    ? strtotime($rssitem->last_updated . ' UTC')
     243                    : 0;
     244                $lastchecked_timestamp = !empty($rssitem->last_checked) && $rssitem->last_checked !== '0000-00-00 00:00:00'
     245                    ? strtotime($rssitem->last_checked . ' UTC')
     246                    : 0;
     247               
    238248                // generate the response
    239249                $response = json_encode(
     
    241251                               'message' => $message,
    242252                               'action' => $action,
    243                                'lastupdate' => $rssitem->last_updated,
    244                                'lastchecked' => $rssitem->last_checked,
     253                               'lastupdate' => $lastupdate_timestamp > 0 ? self::formatdate($lastupdate_timestamp) : '',
     254                               'lastchecked' => $lastchecked_timestamp > 0 ? self::formatdate($lastchecked_timestamp) : '',
    245255                               'lasturl' => esc_url($rssitem->latest_item_url),
    246256                               'lasttitle' => esc_html($rssitem->latest_item_title),
  • rssfeedchecker/trunk/RSSFeedCheckerWidget.php

    r1571999 r3451348  
    1313    class RSSCheckWidget extends WP_Widget {
    1414       static function init(){
    15             add_action('widgets_init', create_function('', 'return register_widget("RSSCheckWidget");'));
     15            add_action( 'widgets_init', function() { register_widget("RSSCheckWidget"); } );
    1616            add_shortcode('LinksRSSEnhanced', array('RSSCheckWidget','RenderShortcode' ));
    1717       }
     
    1919        // [LinksRSSEnhanced count="number"]
    2020       static function RenderShortcode( $atts ) {
    21             extract( shortcode_atts( array(
    22                 'count' => 5,
    23             ), $atts ) );
    24         return self::renderlinks($count);
     21            $args = shortcode_atts( array(
     22                'count' => 5,
     23            ), $atts );
     24            return self::renderlinks( absint( $args['count'] ) );
    2525        }
    2626
    27        
    28        function RSSCheckWidget() {
    29         //Constructor
    30        $widget_ops = array('classname' => 'RSSCheckWidget', 'description' => __('A widget to show blog roll links ordered by most recent','rssfeedchecker'));
    31        $this->WP_Widget('RSSCheckWidget', __('Links RSS Enhanced','rssfeedchecker'), $widget_ops);
    32        
    33        if ( is_active_widget( false, false, $this->id_base ) && !is_admin() ) {
    34             wp_enqueue_style("RSSFeedCheckerStyle",plugins_url('/RSSFeedChecker.css', __FILE__));
    35         }
     27       function __construct() {
     28            //Constructor
     29            $widget_ops = array('classname' => 'RSSCheckWidget', 'description' => __('A widget to show blog roll links ordered by most recent','rssfeedchecker'));
     30            parent::__construct('RSSCheckWidget', __('Links RSS Enhanced','rssfeedchecker'), $widget_ops);
     31            if ( is_active_widget( false, false, $this->id_base ) && !is_admin() ) {
     32                    wp_enqueue_style("RSSFeedCheckerStyle",plugins_url('/RSSFeedChecker.css', __FILE__));
     33            }
    3634       }
    3735
     
    4139       
    4240        public function form_input_option($field,$caption,$value,$options){
    43            
     41        $opthtml = '';   
    4442        foreach ($options as $option) {   
    4543            if ($option == $value) {$select = 'selected="selected"'; } else {$select = '';}
     
    5048       
    5149        public function form_input_checkbox($field,$caption,$value){
     50            $checked = '';
    5251            if ($value) {
    5352                $checked = 'checked="checked"';
     
    5857       function widget($args, $instance) {
    5958        // prints the widget to the user
    60             extract($args, EXTR_SKIP);
     59            $before_widget = $args['before_widget'] ?? '';
     60            $after_widget = $args['after_widget'] ?? '';
     61            $before_title = $args['before_title'] ?? '';
     62            $after_title = $args['after_title'] ?? '';
    6163   
    6264            $title = apply_filters('widget_title', $instance['title']);
     
    7476       }
    7577       
    76        function renderlinks($count){
     78       static function renderlinks($count){
    7779            $htmlout = '<ul class="RSSFeedBlogRoll blogroll">';
    7880            $links = RSSCheckerDB::rss_list($count);
     
    9395       }
    9496       
    95        function pretty_date($date)
     97       static function pretty_date($date)
    9698       {
    9799
     
    99101            //Changed strings to match that of javascript version used for twitter.
    100102            //Added Localisation of strings
    101             $compareTo = time();
    102 
    103             $diff =  abs($compareTo - strtotime($date));
     103            $compareTo = time();  // Current Unix timestamp (always UTC-based)
     104            $dateTimestamp = strtotime($date . ' UTC');
     105           
     106            if ($dateTimestamp === false) {
     107                return '';
     108            }
     109   
     110            $diff = abs($compareTo - $dateTimestamp);
    104111            $dayDiff = floor($diff / 86400);
    105112   
  • rssfeedchecker/trunk/readme.txt

    r2489276 r3451348  
    33Tags: RSS, Blogroll
    44Donate link: http://www.workshopshed.com/
    5 Requires at least: 2.8
    6 Tested up to: 5.6.2
    7 Stable tag: 1.1
     5Requires at least: 6.9
     6Tested up to: 6.9
     7Stable tag: 2.0
    88License: GPLv2 or later
    99
    1010== Description ==
    1111
    12 The RSS Feed checker looks through your blogroll for links with rss feeds and then stores the name and url of the latest article.
     12The RSS Feed checker looks through your blogroll for links with rss feeds and then stores the name and url of the latest article.
     13The Links RSS Enhanced widget then displays the latest links in descending order.
     14The idea for the widget comes from the blogroll widget on blogger.
    1315
    14 The Links RSS Enhanced widget then displays the latest links in descending order.
    15 
    16 The idea for the widget comes from the blogroll widget on blogger.
     16Version 2.0 for PHP 8 and above only. Only tested on 6.9.
    1717
    1818== Installation ==
     
    6767== Changelog ==
    6868
     69= 2.0 =
     70
     71* Updates for PHP 8.
     72* SQL Injection issues resolved.
     73* Swapped to using UTC dates internally and server dates for display.
     74* Simplified some of the functions that only existed for backwards compatibility.
     75* Swapped microtime_float() with microtime(true)
     76
    6977= 1.1 =
    7078
     
    94102== Technical section ==
    95103
    96 The plugin will create an extra table in your wordpress database to store the latest feed updates, this will be called links_rss with the prefix for your database e.g. wp_links_rss
     104The plugin will create an extra table in your wordpress database to store the latest feed updates,
     105this will be called links_rss with the prefix for your database e.g. wp_links_rss
    97106
    98 A Cron (schedule) is created to run every 30 minutes and process links. Note that Cron in WordPress depends on hits, your WordPress website receives. So playing with this plugin within an offline environment (MAMP, XAMPP, WAMP etc.) without anyone or anything triggering the scheduling by sending requests to the WordPress page won't produce any results if you do not trigger it by yourself.
     107A Cron (schedule) is created to run every 30 minutes and process links. Note that Cron in WordPress
     108depends on hits, your WordPress website receives. So playing with this plugin within an offline
     109environment (MAMP, XAMPP, WAMP etc.) without anyone or anything triggering the scheduling by
     110sending requests to the WordPress page won't produce any results if you do not trigger it by
     111yourself.
    99112
    100113== References ==
Note: See TracChangeset for help on using the changeset viewer.