$param){ if($i == 0) $prefix = '?attributes='; // add the url prefix else $prefix = ','; $i = 1; $url = $url.$prefix.$param; $search_name = $search_name.$prefix.$param; } } $url = $url.'&empty=1'; // adds the empty so that 0's are returned // if to use the cache if($cache){ // obtain the cache file and decode the contents of the file into a json array if(file_exists(plugin_dir_path(__FILE__).'/cache.json')) $temp = json_decode(file_get_contents(plugin_dir_path(__FILE__).'/cache.json'), true); if(isset($temp[$search_name])&&(strtotime(date('YmdHi'))-(strtotime($temp[$search_name]['timestamp']))<((60*60)*$hours)) && file_exists(plugin_dir_path(__FILE__).'/cache.json')){ // the row exists for this search and is less than 10 hours old use it $output = $temp[$search_name]; $output['source'] = 'cache'; } else { // else get fresh data $c = curl_init($url); curl_setopt($c, CURLOPT_RETURNTRANSFER, true); // hides pre-emptive output $c = json_decode(curl_exec($c),true); $output = $c; $output = $output['data']; // add it to the current file array / replacing or adding a new one $temp[$search_name] = $output; $temp[$search_name]['timestamp'] = (int)date('YmdHi'); // add the timestamp $temp = json_encode($temp); // add to cache.json file file_put_contents(plugin_dir_path(__FILE__).'/cache.json',$temp); $output['source'] = 'fresh'; } } else { // not using cache, fresh data $c = curl_init($url); curl_setopt($c, CURLOPT_RETURNTRANSFER, true); // hides pre-emptive output $c = json_decode(curl_exec($c),true); $output = $c; $output = $output['data']; $output['source'] = 'fresh'; //$output = $output[0]; } if($json_encode) return json_encode($output); else return $output; } // widget class anook_widget extends WP_Widget{ // tell wordpress about me! function __construct(){ parent::__construct('anook_widget','Anook Badge',array('description'=>'Display an anook badge in your sidebar')); } // this is what is shown public function widget($args,$instance){ $title = apply_filters('widget_title',$instance['title']); echo $args['before_widget']; if(!empty($title)) echo $args['before_title'].$title.$args['after_title']; echo anook_show($instance); echo $args['after_widget']; } // backend options stuff public function form($instance){ $options = array('user','nook','game'); $instance['all_games'] = anook_fetch('user',$instance['search'].'/games',array('thumbnail','name','user','url')); ?>

> autocomplete='off'>
autocomplete='off'>

> Hold control and select the games you wish to show on the widget, to show off your fame and favourite games.

> ' id="games_selected" autocomplete='off'/>

console.log("'.$source.'");'; if($atts['part'] == 'user') $html .= '
'.$return['username'].'\'s profile picture
'.$return['username'].' '.$return['country'].' Followers: '.$return['followerCount'].' follow user
'; elseif($atts['part'] == 'nook' || $atts['part'] == 'game') $html .= '
'.$return['name'].' Followers: '.$return['userCount'].' follow '.$atts['part'].'
'; // if it has show games if($atts['show_games'] && $atts['games_list'][0] != '0' && $atts['part'] == 'user'){ $games = anook_fetch('user',$atts['search'].'/games',array('thumbnail','name','user','url'),false); $html .= ''; } // end of anook-badge container $html .='
'; // return the end html result, all the built bits of code return $html; } function anook_show_shortcode($atts){ $html = ''; foreach($atts as $key => $attr){ if($key=='title') continue; // define attributes (params) to make bandwidth less an issue and specify data return if($key == 'user'){ $params = array('picture','country','followerCount','url','username'); } elseif($key == 'game' || $key == 'nook'){ $params = array('thumbnail','name','userCount','url'); } $return = anook_fetch($key,$attr,$params); $return = $return[0]; $html .= ''; if($key == 'user') $html .= '
'.$return['username'].' '.$return['country'].' Followers: '.$return['followerCount'].' follow user
'; elseif($key == 'nook' || $key == 'game') $html .= '
'.$return['name'].' Followers: '.$return['userCount'].' follow '.$key.'
'; } // return the end html result, all the built bits of code return $html; } function anook_ajax(){ print_r(anook_fetch($_POST['part'],$_POST['search'],$_POST['attr'],$_POST['json_encode'])); exit(); } // load js file to widgets area function anook_admin_enqueue($hook) { if ( 'widgets.php' != $hook ) { return; } wp_enqueue_script( 'anook-badge', plugin_dir_url( __FILE__ ) . 'anook-badges.js', array('jquery') ); } // init widget function anook_widget_load(){ register_widget('anook_widget'); } function anook_font_awesome() { wp_enqueue_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css'); } // font awesome for better icons add_action('admin_init', 'anook_font_awesome'); // shortcode add_shortcode('anook','anook_show_shortcode'); // widget add_action('widgets_init', 'anook_widget_load'); // add extra stylesheet wp_enqueue_style('anook-badge', plugins_url('style.css',__FILE__)); // enqueue js if($enable_js_responsive) wp_enqueue_script('anook-badge', plugins_url('anook-badges.js',__FILE__), array('jquery')); add_action( 'admin_enqueue_scripts', 'anook_admin_enqueue' ); add_action( 'wp_ajax_anook_ajax', 'anook_ajax' ); ?>