php /** * This file holds several widgets exclusive to the framework * * @author Christian "Kriesi" Budschedl * @copyright Copyright (c) Christian Budschedl * @link http://Kriesi.at * @link http://aviathemes.com * @since Version 1.0 * @package AviaFramework */ /** * AVIA FACEBOOK WIDGET */ if (!class_exists('avia_fb_likebox')) { class avia_fb_likebox extends WP_Widget { static $script_loaded = 0; function __construct() { //Constructor $widget_ops = array('classname' => 'avia_fb_likebox', 'description' => __('A widget that displays a facebook Likebox to a facebook page of your choice', 'avia_framework') ); parent::__construct( 'avia_fb_likebox', THEMENAME.' Facebook Likebox', $widget_ops ); } function widget($args, $instance) { // prints the widget extract($args, EXTR_SKIP); if(empty($instance['url'])) return; $url = $instance['url']; $title = isset($instance['title']) ? $instance['title'] : ""; $height = 151; $faces = "true"; $extraClass = ""; $style = ""; if(strpos($height, "%") !== false) { $extraClass = "av_facebook_widget_wrap_positioner"; $style = "style='padding-bottom:{$height}'"; $height = "100%"; } echo $before_widget; if ( !empty( $title ) ) { echo $before_title . $title . $after_title; }; echo "
"; echo '
'; echo "
"; echo $after_widget; add_action('wp_footer', array( $this,'fb_js' )); } function fb_js() { if ( function_exists('icl_object_id') ) { $locale = ICL_LANGUAGE_NAME_EN; $fbxml = @simplexml_load_file( AVIA_BASE . '/config-wpml/FacebookLocales.xml' ); if(is_object($fbxml)) { $langcode = array(); foreach($fbxml as $loc) { if($loc->englishName == $locale) { $langcode = $loc->codes->code->standard->representation; } } } } $langcode = function_exists('icl_object_id') && !empty($langcode) ? $langcode : 'en_US'; if(self::$script_loaded == 1) return; self::$script_loaded = 1; echo ' '; } function update($new_instance, $old_instance) { $instance = $old_instance; foreach($new_instance as $key=>$value) { $instance[$key] = strip_tags($new_instance[$key]); } return $instance; } function form($instance) { //widgetform in backend $instance = wp_parse_args( (array) $instance, array('url' => 'https://www.facebook.com/kriesi.at', 'title' => '') ); $html = new avia_htmlhelper(); ?>

php } } } /** * AVIA TWEETBOX * * Widget that creates a list of latest tweets * * @package AviaFramework * @todo replace the widget system with a dynamic one, based on config files for easier widget creation */ /* Twitter widget only for compatibility reasons with older themes present. no onger used since API will be shut down by twitter */ if (!class_exists('avia_tweetbox')) { class avia_tweetbox extends WP_Widget { function __construct() { //Constructor $widget_ops = array('classname' => 'tweetbox', 'description' => 'A widget to display your latest twitter messages' ); parent::__construct( 'tweetbox', THEMENAME.' Twitter Widget', $widget_ops ); } function widget($args, $instance) { // prints the widget extract($args, EXTR_SKIP); echo $before_widget; $title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']); $count = empty($instance['count']) ? '' : $instance['count']; $username = empty($instance['username']) ? '' : $instance['username']; $exclude_replies = empty($instance['exclude_replies']) ? '' : $instance['exclude_replies']; $time = empty($instance['time']) ? 'no' : $instance['time']; $display_image = empty($instance['display_image']) ? 'no' : $instance['display_image']; if ( !empty( $title ) ) { echo $before_title . "".$title ."". $after_title; }; $messages = tweetbox_get_tweet($count, $username, $widget_id, $time, $exclude_replies, $display_image); echo $messages; echo $after_widget; } function update($new_instance, $old_instance) { //save the widget $instance = $old_instance; foreach($new_instance as $key=>$value) { $instance[$key] = strip_tags($new_instance[$key]); } delete_transient(THEMENAME.'_tweetcache_id_'.$instance['username'].'_'.$this->id_base."-".$this->number); return $instance; } function form($instance) { //widgetform in backend $instance = wp_parse_args( (array) $instance, array( 'title' => 'Latest Tweets', 'count' => '3', 'username' => avia_get_option('twitter') ) ); $title = isset($instance['title']) ? strip_tags($instance['title']): ""; $count = isset($instance['count']) ? strip_tags($instance['count']): ""; $username = isset($instance['username']) ? strip_tags($instance['username']): ""; $exclude_replies = isset($instance['exclude_replies']) ? strip_tags($instance['exclude_replies']): ""; $time = isset($instance['time']) ? strip_tags($instance['time']): ""; $display_image = isset($instance['display_image']) ? strip_tags($instance['display_image']): ""; ?>

"; echo $list; ?>

"; echo $list; ?>

"; echo $list; ?>

"; echo $list; ?>

php } } } if(!function_exists('tweetbox_get_tweet')) { function tweetbox_get_tweet($count, $username, $widget_id, $time='yes', $exclude_replies='yes', $avatar = 'yes') { $filtered_message = ""; $output = ""; $iterations = 0; $cache = get_transient(THEMENAME.'_tweetcache_id_'.$username.'_'.$widget_id); if($cache) { $tweets = get_option(THEMENAME.'_tweetcache_'.$username.'_'.$widget_id); } else { //$response = wp_remote_get( 'http://api.twitter.com/1/statuses/user_timeline.xml?screen_name='.$username ); $response = wp_remote_get( 'http://api.twitter.com/1/statuses/user_timeline.xml?include_rts=true&screen_name='.$username ); if (!is_wp_error($response)) { $xml = @simplexml_load_string($response['body']); //follower: (int) $xml->status->user->followers_count if( empty( $xml->error ) ) { if ( isset($xml->status[0])) { $tweets = array(); foreach ($xml->status as $tweet) { if($iterations == $count) break; $text = (string) $tweet->text; if($exclude_replies == 'no' || ($exclude_replies == 'yes' && $text[0] != "@")) { $iterations++; $tweets[] = array( 'text' => tweetbox_filter( $text ), 'created' => strtotime( $tweet->created_at ), 'user' => array( 'name' => (string)$tweet->user->name, 'screen_name' => (string)$tweet->user->screen_name, 'image' => (string)$tweet->user->profile_image_url, 'utc_offset' => (int) $tweet->user->utc_offset[0], 'follower' => (int) $tweet->user->followers_count )); } } set_transient(THEMENAME.'_tweetcache_id_'.$username.'_'.$widget_id, 'true', 60*30); update_option(THEMENAME.'_tweetcache_'.$username.'_'.$widget_id, $tweets); } } } } if(!isset($tweets[0])) { $tweets = get_option(THEMENAME.'_tweetcache_'.$username.'_'.$widget_id); } if(isset($tweets[0])) { $time_format = apply_filters( 'avia_widget_time', get_option('date_format')." - ".get_option('time_format'), 'tweetbox' ); foreach ($tweets as $message) { $output .= '
  • '; if($avatar == "yes") $output .= '
    '; $output .= '
    '.$message['text']; if($time == "yes") $output .= '
    '.date_i18n( $time_format, $message['created'] + $message['user']['utc_offset']).'
    '; $output .= '
  • '; } } if($output != "") { $filtered_message = ""; } else { $filtered_message = ""; } return $filtered_message; } } if(!function_exists('tweetbox_filter')) { function tweetbox_filter($text) { // Props to Allen Shaw & webmancers.com & Michael Voigt $text = preg_replace('/\b([a-zA-Z]+:\/\/[\w_.\-]+\.[a-zA-Z]{2,6}[\/\w\-~.?=&%#+$*!]*)\b/i',"$1", $text); $text = preg_replace('/\b(?$1", $text); $text = preg_replace("/\b([a-zA-Z][a-zA-Z0-9\_\.\-]*[a-zA-Z]*\@[a-zA-Z][a-zA-Z0-9\_\.\-]*[a-zA-Z]{2,6})\b/i","$1", $text); $text = preg_replace("/#([\p{L}\p{Mn}]+)/u", "#\\1", $text); $text = preg_replace("/@([\p{L}\p{Mn}]+)/u", "@\\1", $text); return $text; } } /** * AVIA NEWSBOX * * Widget that creates a list of latest news entries * * @package AviaFramework * @todo replace the widget system with a dynamic one, based on config files for easier widget creation */ if (!class_exists('avia_newsbox')) { class avia_newsbox extends WP_Widget { var $avia_term = ''; var $avia_post_type = ''; var $avia_new_query = ''; function __construct() { $widget_ops = array('classname' => 'newsbox', 'description' => __('A Sidebar widget to display latest post entries in your sidebar', 'avia_framework') ); parent::__construct( 'newsbox', THEMENAME.' Latest News', $widget_ops ); } function widget($args, $instance) { global $avia_config; extract($args, EXTR_SKIP); echo $before_widget; $title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']); $count = empty($instance['count']) ? '' : $instance['count']; $cat = empty($instance['cat']) ? '' : $instance['cat']; $excerpt = empty($instance['excerpt']) ? '' : $instance['excerpt']; $image_size = isset($avia_config['widget_image_size']) ? $avia_config['widget_image_size'] : 'widget'; if ( !empty( $title ) ) { echo $before_title . $title . $after_title; }; if(empty($this->avia_term)) { $additional_loop = new WP_Query("cat=".$cat."&posts_per_page=".$count); } else { $catarray = explode(',', $cat); if(empty($catarray[0])) { $new_query = array("posts_per_page"=>$count,"post_type"=>$this->avia_post_type); } else { if($this->avia_new_query) { $new_query = $this->avia_new_query; } else { $new_query = array( "posts_per_page"=>$count, 'tax_query' => array( array( 'taxonomy' => $this->avia_term, 'field' => 'id', 'terms' => explode(',', $cat), 'operator' => 'IN') ) ); } } $additional_loop = new WP_Query($new_query); } if($additional_loop->have_posts()) : echo '"; wp_reset_postdata(); endif; echo $after_widget; } function update($new_instance, $old_instance) { $instance = $old_instance; $instance['title'] = strip_tags($new_instance['title']); $instance['count'] = strip_tags($new_instance['count']); $instance['excerpt'] = strip_tags($new_instance['excerpt']); $instance['cat'] = implode(',',$new_instance['cat']); return $instance; } function form($instance) { $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'count' => '', 'cat' => '', 'excerpt'=>'' ) ); $title = strip_tags($instance['title']); $count = strip_tags($instance['count']); $excerpt = strip_tags($instance['excerpt']); $elementCat = array("name" => __("Which categories should be used for the portfolio?", 'avia_framework'), "desc" => __("You can select multiple categories here", 'avia_framework'), "id" => $this->get_field_name('cat')."[]", "type" => "select", "std" => strip_tags($instance['cat']), "class" => "", "multiple"=>6, "subtype" => "cat"); //check if a different taxonomy than the default is set if(!empty($this->avia_term)) { $elementCat['taxonomy'] = $this->avia_term; } $html = new avia_htmlhelper(); ?>

    "; echo $list; ?>

    "; echo $list; ?>

    php } } } /** * AVIA PORTFOLIOBOX * * Widget that creates a list of latest portfolio entries. Basically the same widget as the newsbox with some minor modifications, therefore it just extends the Newsbox * * @package AviaFramework * @todo replace the widget system with a dynamic one, based on config files for easier widget creation */ if (!class_exists('avia_portfoliobox')) { class avia_portfoliobox extends avia_newsbox { function __construct() { $this->avia_term = 'portfolio_entries'; $this->avia_post_type = 'portfolio'; $this->avia_new_query = ''; //set a custom query here $widget_ops = array('classname' => 'newsbox', 'description' => __('A Sidebar widget to display latest portfolio entries in your sidebar', 'avia_framework') ); WP_Widget::__construct( 'portfoliobox', THEMENAME.' Latest Portfolio', $widget_ops ); } } } /** * AVIA SOCIALCOUNT * * Widget that retrieves, stores and displays the number of twitter and rss followers * * @package AviaFramework * @todo replace the widget system with a dynamic one, based on config files for easier widget creation */ if (!class_exists('avia_socialcount')) { class avia_socialcount extends WP_Widget { function __construct() { //Constructor $widget_ops = array('classname' => 'avia_socialcount', 'description' => __('A widget to display a link to your twitter profile and rss feed', 'avia_framework') ); parent::__construct( 'avia_socialcount', THEMENAME.' RSS Link and Twitter Account', $widget_ops ); } function widget($args, $instance) { // prints the widget extract($args, EXTR_SKIP); $twitter = empty($instance['twitter']) ? '' : $instance['twitter']; $rss = empty($instance['rss']) ? '' : $instance['rss']; $rss = preg_replace('!https?:\/\/feeds.feedburner.com\/!','',$rss); if(!empty($twitter) || !empty($rss)) { $addClass = "asc_multi_count"; if(!isset($twitter) || !isset($rss)) $addClass = 'asc_single_count'; echo $before_widget; $output = ""; if(!empty($twitter)) { $link = 'http://twitter.com/'.$twitter.'/'; $before = apply_filters('avf_social_widget', "", 'twitter'); $output .= "{$before}".__('Follow','avia_framework')."".__('on Twitter','avia_framework').""; } if($rss) { $output .= "".apply_filters('avf_social_widget',"", 'rss')."".__('Subscribe','avia_framework')."".__('to RSS Feed','avia_framework').""; } echo $output; echo $after_widget; } } function update($new_instance, $old_instance) { //save the widget $instance = $old_instance; foreach($new_instance as $key=>$value) { $instance[$key] = strip_tags($new_instance[$key]); } return $instance; } function form($instance) { //widgetform in backend $instance = wp_parse_args( (array) $instance, array('rss' => avia_get_option('feedburner'), 'twitter' => avia_get_option('twitter') ) ); $twitter = empty($instance['twitter']) ? '' : strip_tags($instance['twitter']); $rss = empty($instance['rss']) ? '' : strip_tags($instance['rss']); ?>

    php } } } /** * AVIA ADVERTISING WIDGET * * Widget that retrieves, stores and displays the number of twitter and rss followers * * @package AviaFramework * @todo replace the widget system with a dynamic one, based on config files for easier widget creation */ //multiple images if (!class_exists('avia_partner_widget')) { class avia_partner_widget extends WP_Widget { function __construct() { $this->add_cont = 2; //Constructor $widget_ops = array('classname' => 'avia_partner_widget', 'description' => __('An advertising widget that displays 2 images with 125 x 125 px in size', 'avia_framework') ); parent::__construct( 'avia_partner_widget', THEMENAME.' Advertising Area', $widget_ops ); } function widget($args, $instance) { extract($args, EXTR_SKIP); echo $before_widget; global $kriesiaddwidget, $firsttitle; $kriesiaddwidget ++; $title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']); $image_url = empty($instance['image_url']) ? ''.__('Advertise here','avia_framework').'' : ''.$title.''; $ref_url = empty($instance['ref_url']) ? '#' : apply_filters('widget_comments_title', $instance['ref_url']); $image_url2 = empty($instance['image_url2']) ? ''.__('Advertise here','avia_framework').'' : ''.$title.''; $ref_url2 = empty($instance['ref_url2']) ? '#' : apply_filters('widget_comments_title', $instance['ref_url2']); if ( !empty( $title ) ) { echo $before_title . $title . $after_title; }; echo ''.$image_url.''; if($this->add_cont == 2) echo ''.$image_url2.''; echo $after_widget; if($title == '') { $firsttitle = 'no_top_margin'; } } function update($new_instance, $old_instance) { //save the widget $instance = $old_instance; foreach($new_instance as $key=>$value) { $instance[$key] = strip_tags($new_instance[$key]); } return $instance; } function form($instance) { $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'image_url' => '', 'ref_url' => '', 'image_url2' => '', 'ref_url2' => '' ) ); $title = strip_tags($instance['title']); $image_url = strip_tags($instance['image_url']); $ref_url = strip_tags($instance['ref_url']); $image_url2 = strip_tags($instance['image_url2']); $ref_url2 = strip_tags($instance['ref_url2']); ?>

    php if($this->add_cont == 2) { ?>

    php }?> php } } } if (!class_exists('avia_one_partner_widget')) { //one image class avia_one_partner_widget extends avia_partner_widget { function __construct() { $this->add_cont = 1; $widget_ops = array('classname' => 'avia_one_partner_widget', 'description' => __('An advertising widget that displays 1 big image', 'avia_framework') ); parent::__construct( 'avia_one_partner_widget', THEMENAME.' Big Advertising Area', $widget_ops ); } } } /** * AVIA COMBO WIDGET * * Widget that retrieves, stores and displays the number of twitter and rss followers * * @package AviaFramework * @todo replace the widget system with a dynamic one, based on config files for easier widget creation */ if (!class_exists('avia_combo_widget')) { class avia_combo_widget extends WP_Widget { function __construct() { //Constructor $widget_ops = array('classname' => 'avia_combo_widget', 'description' => __('A widget that displays your popular posts, recent posts, recent comments and a tagcloud', 'avia_framework') ); parent::__construct( 'avia_combo_widget', THEMENAME.' Combo Widget', $widget_ops ); } function widget($args, $instance) { // prints the widget extract($args, EXTR_SKIP); $posts = empty($instance['count']) ? 4 : $instance['count']; echo $before_widget; echo "
    "; echo ''; echo "
    "; avia_get_post_list('cat=&orderby=comment_count&posts_per_page='.$posts); echo "
    "; echo '
    '.__('Recent', 'avia_framework').'
    '; echo "
    "; avia_get_post_list('showposts='. $posts .'&orderby=post_date&order=desc'); echo "
    "; echo '
    '.__('Comments', 'avia_framework').'
    '; echo "
    "; avia_get_comment_list( array('number' => $posts, 'status' => 'approve', 'order' => 'DESC') ); echo "
    "; echo '
    '.__('Tags', 'avia_framework').'
    '; echo "
    "; wp_tag_cloud('smallest=12&largest=12&unit=px'); echo "
    "; echo "
    "; echo $after_widget; } function update($new_instance, $old_instance) { $instance = $old_instance; foreach($new_instance as $key=>$value) { $instance[$key] = strip_tags($new_instance[$key]); } return $instance; } function form($instance) { //widgetform in backend $instance = wp_parse_args( (array) $instance, array('count' => 4) ); if(!is_numeric($instance['count'])) $instance['count'] = 4; ?>

    php } } } /*----------------------------------------------------------------------------------- get posts posts -----------------------------------------------------------------------------------*/ if (!function_exists('avia_get_post_list')) { function avia_get_post_list( $avia_new_query , $excerpt = false) { global $avia_config; $image_size = isset($avia_config['widget_image_size']) ? $avia_config['widget_image_size'] : 'widget'; $additional_loop = new WP_Query($avia_new_query); if($additional_loop->have_posts()) : echo '"; wp_reset_postdata(); endif; } } if (!function_exists('avia_get_comment_list')) { function avia_get_comment_list($avia_new_query) { $time_format = apply_filters( 'avia_widget_time', get_option('date_format')." - ".get_option('time_format'), 'avia_get_comment_list' ); global $avia_config; $comments = get_comments($avia_new_query); if(!empty($comments)) : echo '"; wp_reset_postdata(); endif; } } /* Google Maps Widget Copyright 2009 Clark Nikdel Powell (email : taylor@cnpstudio.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ if (!class_exists('avia_google_maps')) { class avia_google_maps extends WP_Widget { // constructor function __construct() { $widget_ops = array('classname' => 'avia_google_maps', 'description' => __( 'Add a google map to your blog or site', 'avia_framework') ); parent::__construct('avia_google_maps', THEMENAME.' Google Maps Widget', $widget_ops); add_action( 'admin_enqueue_scripts', array(&$this,'helper_print_google_maps_scripts') ); } // output the content of the widget function widget($args, $instance) { extract( $args ); $title = empty($instance['title']) ? '' : apply_filters('widget_title', esc_attr($instance['title'])); print $before_widget; if (!empty($instance['title'])) { print $before_title.$title.$after_title; } print avia_printmap($instance['lat'], $instance['lng'], $instance['zoom'], $instance['type'], $instance['content'], $instance['directionsto'], $instance['width'], $instance['height'], $instance['icon']); print $after_widget; } // process widget options to be saved function update($new_instance, $old_instance) { print_r($old_instance); print_r($new_instance); return $new_instance; } // output the options form on admin function form($instance) { global $wpdb; $title = empty($instance['title']) ? '' : esc_attr($instance['title']); $lat = empty($instance['lat']) ? '' : esc_attr($instance['lat']); $lng = empty($instance['lng']) ? '' : esc_attr($instance['lng']); $zoom = empty($instance['zoom']) ? '15' : esc_attr($instance['zoom']); $type = empty($instance['type']) ? 'ROADMAP' : esc_attr($instance['type']); $directionsto = empty($instance['directionsto']) ? '' : esc_attr($instance['directionsto']); $content = empty($instance['content']) ? '' : esc_attr($instance['content']); $width = empty($instance['width']) ? '' : esc_attr($instance['width']); $height = empty($instance['height']) ? '' : esc_attr($instance['height']); $street_address = empty($instance['street-address']) ? '' : esc_attr($instance['street-address']); $city = empty($instance['city']) ? '' : esc_attr($instance['city']); $state = empty($instance['state']) ? '' : esc_attr($instance['state']); $postcode = empty($instance['postcode']) ? '' : esc_attr($instance['postcode']); $country = empty($instance['country']) ? '' : esc_attr($instance['country']); $icon = empty($instance['icon']) ? '' : esc_attr($instance['icon']); ?>

    php _e('Enter the latitude and longitude of the location you want to display. Need help finding the latitude and longitude?', 'avia_framework'); ?> php _e('Click here to enter an address.','avia_framework'); ?>

    php _e('Fetch coordinates!','avia_framework'); ?>

    php _e('Fetching the coordinates. Please wait...','avia_framework'); ?>

    "; echo $list; ?>

    "; echo $list; ?>

    php } function helper_print_google_maps_scripts() { $prefix = is_ssl() ? "https" : "http"; wp_register_script( 'avia-google-maps-api', $prefix.'://maps.google.com/maps/api/js', array('jquery'), '3', true); $load_google_map_api = apply_filters('avf_load_google_map_api', true, 'avia_google_map_widget'); if($load_google_map_api) wp_enqueue_script( 'avia-google-maps-api' ); $is_widget_edit_page = in_array(basename($_SERVER['PHP_SELF']), array('widgets.php')); if($is_widget_edit_page) { wp_register_script( 'avia-google-maps-widget', AVIA_JS_URL.'conditional_load/avia_google_maps_widget.js', array( 'jquery','media-upload','media-views' ), '1.0.0', true); wp_enqueue_script( 'avia-google-maps-widget' ); $args = array( 'toomanyrequests' => __("Too many requests at once, please refresh the page to complete geocoding",'avia_framework'), 'latitude' => __("Latitude and longitude for",'avia_framework'), 'notfound' => __("couldn't be found by Google, please add them manually",'avia_framework'), 'insertaddress' => __("Please insert a valid address in the fields above",'avia_framework') ); if($load_google_map_api) wp_localize_script( 'avia-google-maps-api', 'AviaMapTranslation', $args ); } } } // SGMwidget widget } if(!function_exists('avia_printmap')) { function avia_printmap($lat, $lng, $zoom, $type, $content, $directionsto, $width, $height, $icon) { global $avia_config; $SGMoptions = get_option('SGMoptions'); // get options defined in admin page if (!$lat) {$lat = '0';} if (!$lng) {$lng = '0';} if (!$zoom) {$zoom = $SGMoptions['zoom'];} // 1-19 if (!$type) {$type = $SGMoptions['type'];} // ROADMAP, SATELLITE, HYBRID, TERRAIN if (!$content) {$content = $SGMoptions['content'];} $output = ""; $unique = uniqid(); $prefix = isset($_SERVER['HTTPS'] ) ? "https" : "http"; $width = !empty($width) ? 'width:'.$width.';' : 'width:100%;'; $height = !empty($height) ? 'height:'.$height.';' : ''; $icon = !empty($icon) ? $icon : ''; $content = htmlspecialchars($content, ENT_QUOTES); $content = str_replace('<', '<', $content); $content = str_replace('>', '>', $content); $content = str_replace('"', '"', $content); $content = str_replace(''', '"', $content); $content = json_encode($content); $directionsForm = ""; if(empty($avia_config['g_maps_widget_active'])) { $avia_config['g_maps_widget_active'] = 0; } if(apply_filters('avia_google_maps_widget_load_api', true, $avia_config['g_maps_widget_active'])) { wp_register_script( 'avia-google-maps-api', $prefix.'://maps.googleapis.com/maps/api/js?v=3.24', array('jquery'), '1', false); wp_enqueue_script( 'avia-google-maps-api' ); } $avia_config['g_maps_widget_active'] ++; $output .= "
    "; return $output; } } /* Modified version of instagram widget by Author: Scott Evans Copyright © 2013 Scott Evans This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ class avia_instagram_widget extends WP_Widget { function __construct() { parent::__construct( 'avia-instagram-feed', THEMENAME ." ". __( 'Instagram', 'avia_framework' ), array( 'classname' => 'avia-instagram-feed', 'description' => __( 'Displays your latest Instagram photos', 'avia_framework' ) ) ); } function widget( $args, $instance ) { extract( $args, EXTR_SKIP ); $title = empty( $instance['title'] ) ? '' : apply_filters( 'widget_title', $instance['title'] ); $username = empty( $instance['username'] ) ? '' : $instance['username']; $limit = empty( $instance['number'] ) ? 9 : $instance['number']; $columns = empty( $instance['columns'] ) ? 3 : $instance['columns']; $size = empty( $instance['size'] ) ? 'large' : $instance['size']; $target = empty( $instance['target'] ) ? '_self' : $instance['target']; $link = empty( $instance['link'] ) ? '' : $instance['link']; echo $before_widget; if ( ! empty( $title ) ) { echo $before_title . $title . $after_title; }; do_action( 'aviw_before_widget', $instance ); if ( $username != '' ) { $media_array = $this->scrape_instagram( $username, $limit ); if ( is_wp_error( $media_array ) ) { echo $media_array->get_error_message(); } else { // filter for images only? if ( $images_only = apply_filters( 'aviw_images_only', FALSE ) ) $media_array = array_filter( $media_array, array( $this, 'images_only' ) ); // filters for custom classes $ulclass = esc_attr( apply_filters( 'aviw_list_class', 'av-instagram-pics av-instagram-size-' . $size ) ); $rowclass = esc_attr( apply_filters( 'aviw_row_class', 'av-instagram-row' ) ); $liclass = esc_attr( apply_filters( 'aviw_item_class', 'av-instagram-item' ) ); $aclass = esc_attr( apply_filters( 'aviw_a_class', '' ) ); $imgclass = esc_attr( apply_filters( 'aviw_img_class', '' ) ); ?>
    php $last_id = end($media_array); $last_id = $last_id['id']; $rowcount = 0; foreach ( $media_array as $item ) { if($rowcount == 0) { echo "
    "; } $rowcount ++ ; $targeting = $target; if($target == "lightbox") { $targeting = ""; $item['link'] = $item['original']; } echo ''; if($rowcount % $columns == 0 || $last_id == $item['id']) { echo '
    '; $rowcount = 0; } } echo '
    '; } } if ( $link != '' ) { ?> php echo $link; ?>php } do_action( 'aviw_after_widget', $instance ); echo $after_widget; } function form( $instance ) { $instance = wp_parse_args( (array) $instance, array( 'title' => __( 'Instagram', 'avia_framework' ), 'username' => '', 'size' => 'large', 'link' => __( 'Follow Me!', 'avia_framework' ), 'number' => 9, 'target' => 'lightbox' , 'columns' => 3 ) ); $title = esc_attr( $instance['title'] ); $username = esc_attr( $instance['username'] ); $number = absint( $instance['number'] ); if($number > 12) $number = 12; $size = esc_attr( $instance['size'] ); $target = esc_attr( $instance['target'] ); $link = esc_attr( $instance['link'] ); $columns = esc_attr( $instance['columns'] ); ?>

    php } function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['title'] = strip_tags( $new_instance['title'] ); $instance['username'] = trim( strip_tags( $new_instance['username'] ) ); $instance['number'] = ! absint( $new_instance['number'] ) ? 9 : $new_instance['number']; $instance['columns'] = ! absint( $new_instance['columns'] ) ? 3 : $new_instance['columns']; if($instance['columns'] > 6) $instance['columns'] = 6; if($instance['columns'] < 1) $instance['columns'] = 1; $instance['size'] = ( ( $new_instance['size'] == 'thumbnail' || $new_instance['size'] == 'large' || $new_instance['size'] == 'small' || $new_instance['size'] == 'original' ) ? $new_instance['size'] : 'large' ); $instance['target'] = ( ( $new_instance['target'] == '_self' || $new_instance['target'] == '_blank'|| $new_instance['target'] == 'lightbox' ) ? $new_instance['target'] : '_self' ); $instance['link'] = strip_tags( $new_instance['link'] ); return $instance; } // based on https://gist.github.com/cosmocatalano/4544576 function scrape_instagram( $username, $slice = 9 ) { $username = strtolower( $username ); $username = str_replace( '@', '', $username ); if ( false === ( $instagram = get_transient( 'av_insta1-'.sanitize_title_with_dashes( $username ) ) ) ) { $remote = wp_remote_get( 'http://instagram.com/'.trim( $username ) ); if ( is_wp_error( $remote ) ) return new WP_Error( 'site_down', __( 'Unable to communicate with Instagram.', 'avia_framework' ) ); if ( 200 != wp_remote_retrieve_response_code( $remote ) ) return new WP_Error( 'invalid_response', __( 'Instagram did not return a 200.', 'avia_framework' ) ); $shards = explode( 'window._sharedData = ', $remote['body'] ); $insta_json = explode( ';', $shards[1] ); $insta_array = json_decode( $insta_json[0], TRUE ); if ( ! $insta_array ) return new WP_Error( 'bad_json', __( 'Instagram has returned invalid data.', 'avia_framework' ) ); if ( isset( $insta_array['entry_data']['ProfilePage'][0]['user']['media']['nodes'] ) ) { $images = $insta_array['entry_data']['ProfilePage'][0]['user']['media']['nodes']; } else { return new WP_Error( 'bad_json_2', __( 'Instagram has returned invalid data.', 'avia_framework' ) ); } if ( ! is_array( $images ) ) return new WP_Error( 'bad_array', __( 'Instagram has returned invalid data.', 'avia_framework' ) ); $instagram = array(); foreach ( $images as $image ) { $image['thumbnail_src'] = preg_replace( "/^https:/i", "", $image['thumbnail_src'] ); $image['thumbnail'] = str_replace( 's640x640', 's160x160', $image['thumbnail_src'] ); $image['small'] = str_replace( 's640x640', 's320x320', $image['thumbnail_src'] ); $image['large'] = $image['thumbnail_src']; $image['display_src'] = preg_replace( "/^https:/i", "", $image['display_src'] ); if ( $image['is_video'] == true ) { $type = 'video'; } else { $type = 'image'; } $caption = __( 'Instagram Image', 'avia_framework' ); if ( ! empty( $image['caption'] ) ) { $caption = $image['caption']; } $instagram[] = array( 'description' => $caption, 'link' => '//instagram.com/p/' . $image['code'], 'time' => $image['date'], 'comments' => $image['comments']['count'], 'likes' => $image['likes']['count'], 'thumbnail' => $image['thumbnail'], 'small' => $image['small'], 'large' => $image['large'], 'original' => $image['display_src'], 'type' => $type, 'id' => $image['id'] ); } // do not set an empty transient - should help catch private or empty accounts if ( ! empty( $instagram ) ) { $instagram = base64_encode( serialize( $instagram ) ); set_transient( 'av_insta1-'.sanitize_title_with_dashes( $username ), $instagram, apply_filters( 'null_instagram_cache_time', HOUR_IN_SECONDS*2 ) ); } } if ( ! empty( $instagram ) ) { $instagram = unserialize( base64_decode( $instagram ) ); return array_slice( $instagram, 0, $slice ); } else { return new WP_Error( 'no_images', __( 'Instagram did not return any images.', 'avia_framework' ) ); } } function images_only( $media_item ) { if ( $media_item['type'] == 'image' ) return true; return false; } }