Changeset 3451348
- Timestamp:
- 02/01/2026 11:43:40 AM (8 weeks ago)
- Location:
- rssfeedchecker
- Files:
-
- 12 added
- 8 edited
-
tags/2.0 (added)
-
tags/2.0/RSSFeedChecker.css (added)
-
tags/2.0/RSSFeedChecker.php (added)
-
tags/2.0/RSSFeedCheckerDB.php (added)
-
tags/2.0/RSSFeedCheckerProcessor.php (added)
-
tags/2.0/RSSFeedCheckerSchedule.php (added)
-
tags/2.0/RSSFeedCheckerSettings.php (added)
-
tags/2.0/RSSFeedCheckerUI.php (added)
-
tags/2.0/RSSFeedCheckerWidget.php (added)
-
tags/2.0/ajax.js (added)
-
tags/2.0/readme.txt (added)
-
tags/2.0/uninstall.php (added)
-
trunk/RSSFeedChecker.php (modified) (2 diffs)
-
trunk/RSSFeedCheckerDB.php (modified) (6 diffs)
-
trunk/RSSFeedCheckerProcessor.php (modified) (6 diffs)
-
trunk/RSSFeedCheckerSchedule.php (modified) (1 diff)
-
trunk/RSSFeedCheckerSettings.php (modified) (3 diffs)
-
trunk/RSSFeedCheckerUI.php (modified) (5 diffs)
-
trunk/RSSFeedCheckerWidget.php (modified) (8 diffs)
-
trunk/readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
rssfeedchecker/trunk/RSSFeedChecker.php
r1571999 r3451348 4 4 Plugin URI: # 5 5 Description: 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.16 Version: 2.0 7 7 Author: Andy Clark. 8 8 Author URI: # … … 89 89 } 90 90 91 /**92 * Timing function93 */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 114 91 //Instantiate the plugin 115 92 RSSChecker::init(); -
rssfeedchecker/trunk/RSSFeedCheckerDB.php
r1571999 r3451348 37 37 global $wpdb; 38 38 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) ); 40 40 41 41 $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) ); 44 44 45 45 //If source RSS is now blank then delete … … 60 60 static function rss_list($count) { 61 61 //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; 66 67 } 67 68 … … 73 74 static function rss_getlink($linkid) { 74 75 //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; 79 80 } 80 81 … … 90 91 static function rss_countpending(){ 91 92 //count those that have not been "recently" checked 92 global $wpdb;93 global $wpdb; 93 94 $tblrss = $wpdb->prefix . self::$tablename; 94 95 $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) ); 96 97 return $rss; 97 98 } … … 100 101 { 101 102 //What is the date before which we need to check dates again? 102 $date = new DateTime();103 103 $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); 108 106 } 109 107 … … 138 136 global $wpdb; 139 137 $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)) { 144 140 do_action('RSSStatus',__('RSS Links table missing','rssfeedchecker')); 145 141 return false; 146 142 } 147 148 143 return true; 149 144 } -
rssfeedchecker/trunk/RSSFeedCheckerProcessor.php
r1571999 r3451348 29 29 //Loosly based on broken link checker work function 30 30 31 $execution_start_time = microtime _float(true);31 $execution_start_time = microtime(true); 32 32 $max_execution_time = RSSCheckerSettings::get_max_run()*1000; 33 33 … … 43 43 return -3; //Nothing to process 44 44 } 45 if (microtime _float(true) - $execution_start_time > $max_execution_time) {45 if (microtime(true) - $execution_start_time > $max_execution_time) { 46 46 return -4; //Timeout 47 47 } … … 58 58 $run = -3; 59 59 } 60 if (microtime _float(true) - $execution_start_time > $max_execution_time) {60 if (microtime(true) - $execution_start_time > $max_execution_time) { 61 61 $run = -4; 62 62 } … … 120 120 do_action('RSSStatus',sprintf(__('Processing feed: %s','rssfeedchecker'),$rssitem->rss_address)); 121 121 122 $rssitem->last_checked = Date("Y-m-d H:i:s");122 $rssitem->last_checked = gmdate("Y-m-d H:i:s"); 123 123 124 124 $url = $rssitem->rss_address; … … 157 157 158 158 /** 159 * From Broken Link Checker159 * From Broken Link Checker 160 160 * Get the server's load averages. 161 161 * 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. 163 163 * 164 164 * @param integer $cache How long the load averages may be cached, in seconds. Set to 0 to get maximally up-to-date data. 165 165 * @return array|null Array, or NULL if retrieving load data is impossible (e.g. when running on a Windows box). 166 166 */ 167 function get_server_load($cache = 5){167 static function get_server_load($cache = 5){ 168 168 static $cached_load = null; 169 169 static $cached_when = 0; 170 170 171 171 if ( !empty($cache) && ((time() - $cached_when) <= $cache) ){ 172 floatval(reset($cached_load));172 return floatval(reset($cached_load)); 173 173 } 174 174 175 175 $load = null; 176 176 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; 188 183 $cached_when = time(); 189 184 return floatval(reset($load)); … … 195 190 * @return bool 196 191 */ 197 function server_too_busy(){192 static function server_too_busy(){ 198 193 if ( !RSSCheckerSettings::get_loadlimit() ){ 199 194 return false; -
rssfeedchecker/trunk/RSSFeedCheckerSchedule.php
r1571999 r3451348 46 46 47 47 static function getnext(){ 48 // WP Cron stores timestamps as UTC 48 49 $mycron = self::getschedule(); 49 50 if (isset( $mycron )){ -
rssfeedchecker/trunk/RSSFeedCheckerSettings.php
r1571999 r3451348 47 47 static function show_loadlimit() 48 48 { 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()); 50 50 } 51 51 … … 69 69 $options['timeout'] = self::validate_range($input['timeout'],10,60); 70 70 $options['maxrun'] = self::validate_range($input['maxrun'],10,360); 71 $options['serverload'] = self::validate_range($input['serverload']*100.0,10, 500)/100.0; //floar71 $options['serverload'] = self::validate_range($input['serverload']*100.0,10,2500)/100.0; //float 72 72 return $options; 73 73 } … … 77 77 { 78 78 $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'; 83 80 return $dbver; 84 81 } -
rssfeedchecker/trunk/RSSFeedCheckerUI.php
r1571999 r3451348 146 146 } 147 147 148 static function formatdate($ date)148 static function formatdate($timestamp) 149 149 { 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); 151 153 } 152 154 … … 156 158 $nonce = $_POST['check']; 157 159 $ajaxsuccess = true; 160 $message = ''; 158 161 159 $execution_start_time = microtime _float(true);162 $execution_start_time = microtime(true); 160 163 161 164 if ( ! wp_verify_nonce( $nonce, 'RSSChecker-nonce' ) ) { … … 194 197 'running' => RSSCheckerProcessor::running(), 195 198 'dbver' => RSSCheckerSettings::db_version(), 196 'duration' => microtime _float(true) - $execution_start_time,199 'duration' => microtime(true) - $execution_start_time, 197 200 'workresult' => $workresult ) 198 201 ); … … 235 238 } 236 239 } 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 238 248 // generate the response 239 249 $response = json_encode( … … 241 251 'message' => $message, 242 252 '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) : '', 245 255 'lasturl' => esc_url($rssitem->latest_item_url), 246 256 'lasttitle' => esc_html($rssitem->latest_item_title), -
rssfeedchecker/trunk/RSSFeedCheckerWidget.php
r1571999 r3451348 13 13 class RSSCheckWidget extends WP_Widget { 14 14 static function init(){ 15 add_action( 'widgets_init', create_function('', 'return register_widget("RSSCheckWidget");'));15 add_action( 'widgets_init', function() { register_widget("RSSCheckWidget"); } ); 16 16 add_shortcode('LinksRSSEnhanced', array('RSSCheckWidget','RenderShortcode' )); 17 17 } … … 19 19 // [LinksRSSEnhanced count="number"] 20 20 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'] ) ); 25 25 } 26 26 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 } 36 34 } 37 35 … … 41 39 42 40 public function form_input_option($field,$caption,$value,$options){ 43 41 $opthtml = ''; 44 42 foreach ($options as $option) { 45 43 if ($option == $value) {$select = 'selected="selected"'; } else {$select = '';} … … 50 48 51 49 public function form_input_checkbox($field,$caption,$value){ 50 $checked = ''; 52 51 if ($value) { 53 52 $checked = 'checked="checked"'; … … 58 57 function widget($args, $instance) { 59 58 // 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'] ?? ''; 61 63 62 64 $title = apply_filters('widget_title', $instance['title']); … … 74 76 } 75 77 76 function renderlinks($count){78 static function renderlinks($count){ 77 79 $htmlout = '<ul class="RSSFeedBlogRoll blogroll">'; 78 80 $links = RSSCheckerDB::rss_list($count); … … 93 95 } 94 96 95 function pretty_date($date)97 static function pretty_date($date) 96 98 { 97 99 … … 99 101 //Changed strings to match that of javascript version used for twitter. 100 102 //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); 104 111 $dayDiff = floor($diff / 86400); 105 112 -
rssfeedchecker/trunk/readme.txt
r2489276 r3451348 3 3 Tags: RSS, Blogroll 4 4 Donate link: http://www.workshopshed.com/ 5 Requires at least: 2.86 Tested up to: 5.6.27 Stable tag: 1.15 Requires at least: 6.9 6 Tested up to: 6.9 7 Stable tag: 2.0 8 8 License: GPLv2 or later 9 9 10 10 == Description == 11 11 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. 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. 13 The Links RSS Enhanced widget then displays the latest links in descending order. 14 The idea for the widget comes from the blogroll widget on blogger. 13 15 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. 16 Version 2.0 for PHP 8 and above only. Only tested on 6.9. 17 17 18 18 == Installation == … … 67 67 == Changelog == 68 68 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 69 77 = 1.1 = 70 78 … … 94 102 == Technical section == 95 103 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 104 The plugin will create an extra table in your wordpress database to store the latest feed updates, 105 this will be called links_rss with the prefix for your database e.g. wp_links_rss 97 106 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. 107 A Cron (schedule) is created to run every 30 minutes and process links. Note that Cron in WordPress 108 depends on hits, your WordPress website receives. So playing with this plugin within an offline 109 environment (MAMP, XAMPP, WAMP etc.) without anyone or anything triggering the scheduling by 110 sending requests to the WordPress page won't produce any results if you do not trigger it by 111 yourself. 99 112 100 113 == References ==
Note: See TracChangeset
for help on using the changeset viewer.