__( 'Flickr Images', 'vh' ), ) // Args ); wp_enqueue_script('thickbox', null, array('jquery')); wp_enqueue_style('thickbox.css', '/'.WPINC.'/js/thickbox/thickbox.css', null, '1.0'); } /** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget( $args, $instance ) { $title = apply_filters( 'widget_title', $instance['title'] ); $this->generateFrontEnd($args, $instance); } /** * Sanitize widget form values as they are saved. * * @see WP_Widget::update() * * @param array $new_instance Values just sent to be saved. * @param array $old_instance Previously saved values from database. * * @return array Updated safe values to be saved. */ public function update( $new_instance, $old_instance ) { $instance = array(); $instance['title'] = strip_tags( $new_instance['title'] ); $instance['username'] = strip_tags($new_instance['username']); $instance['view'] = strip_tags($new_instance['view']); $instance['before_item'] = $new_instance['before_item']; $instance['after_item'] = $new_instance['after_item']; $instance['before_widget'] = $new_instance['before_widget']; $instance['after_widget'] = $new_instance['after_widget']; $instance['items'] = intval($new_instance['items']); $instance['more_title'] = strip_tags($new_instance['more_title']); $instance['tags'] = strip_tags($new_instance['tags']); $instance['target'] = strip_tags($new_instance['target']); $instance['show_titles'] = strip_tags($new_instance['show_titles']); $instance['thickbox'] = strip_tags($new_instance['thickbox']); $instance['random'] = strip_tags($new_instance['random']); $instance['random_tag'] = strip_tags($new_instance['random_tag']); $instance['javascript'] = strip_tags($new_instance['javascript']); if (!empty($instance["username"]) && $instance["username"] != $old_instance["username"]) { if (strpos($instance["username"], "http://api.flickr.com/services/feeds") === false) { $url_gett = wp_remote_get("https://api.flickr.com/services/rest/?method=flickr.people.findByUsername&api_key=".$this->flickr_api_key."&username=".urlencode($instance["username"])."&format=php_serial"); $str = wp_remote_retrieve_body($url_gett); $flickr_response = unserialize($str); if ( isset($flickr_response['user']['id']) ) { $instance["user_id"] = $flickr_response['user']['id']; } else { $instance["user_id"] = ''; } } else { $newoptions["error"] = ""; } } else { $instance["user_id"] = $old_instance["user_id"]; } return $instance; } /** * Back-end widget form. * * @see WP_Widget::form() * * @param array $instance Previously saved values from database. */ public function form( $instance ) { $title = $instance[ 'title' ]; $username = $instance[ 'username' ]; $view = $instance[ 'view' ]; $before_item = $instance[ 'before_item' ]; $after_item = $instance[ 'after_item' ]; $before_flickr_widget = $instance[ 'before_widget' ]; $after_flickr_widget = $instance[ 'after_widget' ]; $items = $instance[ 'items' ]; $more_title = $instance[ 'more_title' ]; $tags = $instance[ 'tags' ]; $target = $instance[ 'target' ]; $show_titles = $instance[ 'show_titles' ]; $thickbox = $instance[ 'thickbox' ]; $random = $instance[ 'random' ]; $randomTag = $instance[ 'random_tag' ]; $javascript = $instance[ 'javascript' ]; ?>

$this->flickr_api_key, 'method' => 'flickr.tags.getListUserPopular', 'count' => $maxcount, 'user_id' => $flickrid, 'format' => 'php_serial', ); $encoded_params = array(); // Loop through parameters and encode foreach ($params as $k => $v){ // Encode parameters for the url of the API call $encoded_params[] = urlencode($k).'='.urlencode($v); } // Call the API and decode the response $url = "http://api.flickr.com/services/rest/?".implode('&', $encoded_params); // Fetch the info $url_gettt = wp_remote_get($url); $rsp = wp_remote_retrieve_body($url_gettt); $rsp_obj = unserialize($rsp); $tags = array(); if (isset($rsp_obj['who']['tags']['tag'])) { $tags = $rsp_obj['who']['tags']['tag']; } shuffle($tags); $tagNumber = rand(0,count($tags)); return $tags[$tagNumber]['_content']; } private function generateFrontEnd($args, $instance) { extract($args); $title = $instance[ 'title' ]; $username = $instance[ 'username' ]; $view = $instance[ 'view' ]; $before_item = $instance[ 'before_item' ]; $after_item = $instance[ 'after_item' ]; $before_flickr_widget = $instance[ 'before_widget' ]; $after_flickr_widget = $instance[ 'after_widget' ]; $items = $instance[ 'items' ]; $more_title = $instance[ 'more_title' ]; $tags = $instance[ 'tags' ]; $target = $instance[ 'target' ]; $show_titles = $instance[ 'show_titles' ]; $thickbox = $instance[ 'thickbox' ]; $random = $instance[ 'random' ]; $randomTag = $instance[ 'random_tag' ]; $javascript = $instance[ 'javascript' ]; $user_id = $instance[ 'user_id' ]; $randomTagText = ''; $out = ''; $target = ($target == "checked") ? "target=\"_blank\"" : ""; $show_titles = ($show_titles == "checked") ? true : false; $thickbox = ($thickbox == "checked") ? true : false; $tags = (strlen($tags) > 0) ? "&tags=" . urlencode($tags) : ""; $random = ($random == "checked") ? true : false; $randomTag = ($randomTag == "checked") ? true : false; if($random == true && $randomTag == true) { $randomTagText = $this->retrieve_random_tag($user_id); $tags = "&tags=" . urlencode($randomTagText) . "&tagmode=any"; } $javascript = ($javascript == "checked") ? true : false; if ($javascript) $flickrformat = "json"; else $flickrformat = "php_serial"; if (empty($items) || $items < 1 || $items > 20) $items = 3; // Screen name or RSS in $username? if (!empty($username) && strpos("http://api.flickr.com/services/feeds", $username) === false) $url = "https://api.flickr.com/services/feeds/photos_public.gne?id=".urlencode($user_id)."&format=".$flickrformat."&lang=en-us".$tags; else $url = $username."&format=".$flickrformat.$tags; // Output via php or javascript? if (!$javascript) { $url_get = wp_remote_get($url); $url_body = wp_remote_retrieve_body($url_get); $photos = unserialize($url_body); if (!empty($photos["items"]) && $random) shuffle($photos["items"]); if ($photos) { $flickr_home = $photos["url"]; foreach($photos["items"] as $key => $value) { if (--$items < 0) break; $photo_title = $value["title"]; $photo_link = $value["url"]; preg_match("/]* src=\"([^\"]*)\"[^>]*>/", $value["description"], $regs); $photo_url = $regs[1]; $photo_description = str_replace("\n", "", strip_tags($value["description"])); //$photo_url = $value["media"]["m"]; $photo_medium_url = str_replace("_m.jpg", ".jpg", $photo_url); $photo_url = str_replace("_m.jpg", "$view.jpg", $photo_url); $thickbox_attrib = ($thickbox) ? "class=\"thickbox\" rel=\"flickr-gallery\" title=\"$photo_title: $photo_description »\"" : ""; $href = ($thickbox) ? $photo_medium_url : $photo_link; $photo_title = ($show_titles) ? "
$photo_title
" : ""; $out .= $before_item . "\"$photo_description\"$photo_title" . $after_item; } if($randomTagText != "") { $out .= "
Used tag: " . $randomTagText . "
"; } } else { $out = "Something went wrong with the Flickr feed! Please check your configuration and make sure that the Flickr username or RSS feed exists"; } } else { $out = ""; } ?> $more_title"; ?>