/* Plugin Name: Argus Popular Posts Description: Filters post data. Version: 1.0 Author: Eli Fox-Epstein Author URI: http://redhyphen.com/ */ //require '../../../wp-load.php'; //require '../../../wp-includes/functions.php'; define('ARG_STAT_FILE', ABSPATH.'wp-content/plugins/argus-popular/lib/stats.csv'); register_activation_hook(__FILE__, 'argus_popular_activation'); register_deactivation_hook(__FILE__, 'argus_popular_deactivation'); add_action('argus_popular_update_cache', 'argus_load_popular'); function argus_load_popular($limit=300){ $api = 'c8751531de41'; $url = 'http://stats.wordpress.com/csv.php?'; $params = array( 'api_key'=>$api, 'blog_uri'=>'http://wesleyanargus.com', 'table'=>'postviews', 'limit'=>$limit ); foreach($params as $k=>$v) $url .= "$k=$v&"; $contents = file_get_contents($url); $fh = fopen(ARG_STAT_FILE,'w'); fwrite($fh, $contents); fclose($fh); } function parse_csv($csv){ $csv_data = array(); $keys = array_slice(explode(',',$csv[0]),0,2); $keys[] = 'views'; unset($csv[0]); $i =0; foreach($csv as $c){ if(strpos($c,',') !== false){ $d = array_slice(explode(',',$c),0,2); $d[] = substr($c,strrpos($c,',')+1); $csv_data[] = array_combine($keys, $d); } } return $csv_data; } function argus_sort_by_views($a,$b){ return $a['views'] > $b['views']?-1:1; } function argus_popular($query_string){ //return; $defaults = array('categories'=>false, 'exclude' => false, 'days'=>6,'limit'=>5,'before'=>'','after'=>'','return'=>true); $params = wp_parse_args($query_string, $defaults); extract($params); if($categories && !is_array($categories)) $categories = explode(',',$categories); if($exclude && !is_array($exclude)) $exclude = explode(',',$exclude); $csv = parse_csv(explode("\n",file_get_contents(ARG_STAT_FILE))); foreach($csv as $k=>$v){ $id = $v['post_id']; $post = get_post($id); $csv[$k]['post_title'] = $post->post_title; $csv[$k]['post_permalink'] = get_permalink($id); } $pops = array(); foreach($csv as $v){ $time = strtotime($v['date']); if(count($pops) < $limit && $time >= time() - ($days * 24 * 60 * 60)) if(!$categories || count(array_intersect($categories, wp_get_post_categories($v['post_id'])))) if(!$exclude || count(array_intersect(wp_get_post_categories($v['post_id']), $exclude)) == 0){ $yes = true; foreach($pops as $p) if($v['post_permalink'] == $p['post_permalink']) $yes = false; if($yes) $pops[] = $v; } } usort($pops,'argus_sort_by_views'); $pops = array_slice($pops, 0, $limit); $pop_string = ''; foreach($pops as $pop) $pop_string .= "$before{$pop['post_title']}$after"; if($return != 'false') return $pop_string; else echo $pop_string; } function argus_popular_activation() { wp_schedule_event(time(), 'hourly', 'argus_popular_update_cache'); } function argus_popular_deactivation() { wp_clear_scheduled_hook('argus_popular_update_cache'); } ?> /* Plugin Name: Argus Shortcodes Description: Various helper shortcodes (like [argusvideo src="someurl"]) Version: 1.0 Author: Vernon Thommeret Author URI: http://thommeret.com/ */ // [argusaudio src="http://someurl/"] function argusaudio_func($attrs) { extract(shortcode_atts(array('src' => ''), $attrs)); return "\n" . "
"; } add_shortcode('argusaudio', 'argusaudio_func'); // [argusvideo src="http://someurl/"] function argusvideo_func($attrs) { extract(shortcode_atts(array('src' => '', 'width' => '320', 'height' => '16'), $attrs)); return "\n" . ""; } add_shortcode('argusvideo', 'argusvideo_func'); // [youtube src="http://youtube.com/watch?v=GMJuEOaF84o"] /*function argus_youtube_func($attrs) { extract(shortcode_atts(array('src' => ''), $attrs)); $url = parse_url($src); $video = $url['query']; $embedcode = ""; if (preg_match("/v=([^=]*)/", $video, $match)) { $video = $match[1]; $video = "http://www.youtube.com/v/{$video}&hl=en&fs=1"; $embedcode = ""; } return $embedcode; } add_shortcode('youtube', 'argus_youtube_func');*/ ?> /* Plugin Name: Argus Post Filter Description: Filters post data. Version: 1.0 Author: Eli Fox-Epstein Author URI: http://redhyphen.com/ */ function arg_tidy($c){ $config = array( 'word-2000'=>true, 'show-body-only'=>true, 'clean'=>true, 'bare'=>true ); $tidy = new Tidy(); $tidy->parseString($c, $config, 'uft8'); $tidy->cleanRepair(); return tidy_get_output($tidy); } add_filter('content_save_pre','arg_tidy'); ?>