$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 .= '
';
elseif($atts['part'] == 'nook' || $atts['part'] == 'game')
$html .= '