#mbk_ocd_plugin_table { font-size:1.1em; } #mbk_ocd_plugin_table td { padding: .5em; } div.star-holder { position: relative; height: 17px; width: 92px; background: url('http://wordpress.org/extend/plugins-plugins/bb-ratings/stars.png?19') repeat-x bottom left!important; } .star-rating { background: url('http://wordpress.org/extend/plugins-plugins/bb-ratings/stars.png?19') repeat-x top left!important; height: 17px; float: left; text-indent: 100%; overflow: hidden; white-space: nowrap; }
Last updated: ".date_i18n(get_option('date_format').' \a\t g:ia' , current_time( 'timestamp' ))." 0))."'>Refresh now "; echo $content; $yesterdaytotal = $todaytotal = $lastweektotal = $alltimetotal = $ratingtotal = 0; for ($i=0;$ipreserveWhiteSpace = false; $dom->formatOutput = true; @$dom->loadHTML($src); $title = $dom->getElementsByTagName('h2') ->item(1) ->nodeValue; $today = $dom->getElementsByTagName('td') ->item(0) ->nodeValue; $yesterday = $dom->getElementsByTagName('td') ->item(1) ->nodeValue; $lastweek = $dom->getElementsByTagName('td') ->item(2) ->nodeValue; $alltime = $dom->getElementsByTagName('td') ->item(3) ->nodeValue; preg_match('/itemprop\=\"ratingValue\"\scontent="(.*?)".*?ratingCount".*?content="(.*?)"/ism', $src, $matches); $rating = isset($matches[1]) ? floatval($matches[1]) : null; $starstitle = isset($matches[1]) ? number_format($rating, 1).' out of 5 stars' : 'N/A'; $starsstats = isset($matches[2]) ? '('.$matches[2].' reviews)' : ''; preg_match('/()/ism', $src, $matches); $stargraphic = isset($matches[1]) ? '
'.$matches[1].'
' : ''; $stars = $stargraphic.$starsstats; $row = "
"; echo $row; flush(); $content .= $row; $todaytotal = $todaytotal + self::get_number($today); $yesterdaytotal = $yesterdaytotal + self::get_number($yesterday); $lastweektotal = $lastweektotal + self::get_number($lastweek); $alltimetotal = $alltimetotal + self::get_number($alltime); $ratingtotal = $ratingtotal + $rating; } $footer = "
PluginTodayYesterdayLast WeekAll TimeRating
$title$today$yesterday$lastweek$alltime$stars
Totals".self::get_number($todaytotal, true)."".self::get_number($yesterdaytotal, true)."".self::get_number($lastweektotal, true)."".self::get_number($alltimetotal, true)."".round($ratingtotal/count($plugins), 2)." out of 5 stars
"; echo $footer; $content .= $footer; // Update the stats every 12 hours set_site_transient('ocd_plugins_table', $content, 60*60*12); // If plugins were non-existant, show the list here. if(!empty($errors)) { echo '
'; } } static function get_number($number, $format = false) { $number = floatval(preg_replace('/[^0-9]/ism', '', trim(rtrim($number)))); if($format) { $number = number_format($number); } return $number; } // Create configuration link for dashboard static function mbk_ocd_plugin_stats_configuration() { $widget_id = 'mbk_ocd_plugin_stats_widget'; // This must be the same ID we set in wp_add_dashboard_widget $form_id = 'mbk_ocd_plugin_stats_widget_control'; // Set this to whatever you want // Checks whether there are already dashboard widget options in the database if ( !$widget_options = get_option( 'dashboard_widget_options' ) ) { $widget_options = array(); } // If not, we create a new array // Check whether we have information for this form if ( !isset($widget_options[$widget_id]) ) { $widget_options[$widget_id] = array(); } // If not, we create a new array // Check whether our form was just submitted if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST[$form_id]) ) { $plugins = $_POST[$form_id]['items']; // Get the value. In this case ['items'] is from the input field with the name of '.$form_id.'[items] $widget_options[$widget_id]['items'] = $plugins; // Set the plugins of items update_option( 'dashboard_widget_options', $widget_options ); // Update our dashboard widget options so we can access later } // Check if we have set the plugins of posts previously. If we didn't, then we just set it as empty. This value is used when we create the input field $plugins = isset( $widget_options[$widget_id]['items'] ) ? $widget_options[$widget_id]['items'] : ''; // Create our form fields. Pay very close attention to the name part of the input field. echo '

'; echo "

"; } // Create function to use in the action hook static function widget_action_hook() { wp_add_dashboard_widget('mbk_ocd_plugin_stats_widget', 'OCD Plugin Stats', array('mbk_ocd_plugin_stats', 'widget_content'), array('mbk_ocd_plugin_stats', 'mbk_ocd_plugin_stats_configuration')); } } ?>