Advertisement
Guest User

class-framework-widgets

a guest
Apr 23rd, 2013
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 40.27 KB | None | 0 0
  1. <?php  if ( ! defined('AVIA_FW')) exit('No direct script access allowed');
  2. /**
  3.  * This file holds several widgets exclusive to the framework
  4.  *
  5.  * @author      Christian "Kriesi" Budschedl
  6.  * @copyright   Copyright (c) Christian Budschedl
  7.  * @link        http://Kriesi.at
  8.  * @link        http://aviathemes.com
  9.  * @since       Version 1.0
  10.  * @package     AviaFramework
  11.  */
  12.  
  13.  
  14. /**
  15.  * AVIA TWEETBOX
  16.  *
  17.  * Widget that creates a list of latest tweets
  18.  *
  19.  * @package AviaFramework
  20.  * @todo replace the widget system with a dynamic one, based on config files for easier widget creation
  21.  */
  22.  
  23.  
  24.  
  25. /*
  26. Twitter widget only for compatibility reasons with older themes present. no onger used since API will be shut down by twitter
  27. */
  28. class avia_tweetbox extends WP_Widget {
  29.  
  30.     function avia_tweetbox() {
  31.         //Constructor
  32.         $widget_ops = array('classname' => 'tweetbox', 'description' => 'A widget to display your latest twitter messages' );
  33.         $this->WP_Widget( 'tweetbox', THEMENAME.' Twitter Widget', $widget_ops );
  34.     }
  35.  
  36.     function widget($args, $instance) {
  37.         // prints the widget
  38.  
  39.         extract($args, EXTR_SKIP);
  40.         echo $before_widget;
  41.  
  42.         $title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);
  43.         $count = empty($instance['count']) ? '' : $instance['count'];
  44.         $username = empty($instance['username']) ? '' : $instance['username'];
  45.         $exclude_replies = empty($instance['exclude_replies']) ? '' : $instance['exclude_replies'];
  46.         $time = empty($instance['time']) ? 'no' : $instance['time'];
  47.         $display_image = empty($instance['display_image']) ? 'no' : $instance['display_image'];
  48.  
  49.         if ( !empty( $title ) ) { echo $before_title . "<a href='http://twitter.com/$username/' title='".strip_tags($title)."'>".$title ."</a>". $after_title; };
  50.  
  51.         $messages = tweetbox_get_tweet($count, $username, $widget_id, $time, $exclude_replies, $display_image);
  52.         echo $messages;
  53.  
  54.         echo $after_widget;
  55.  
  56.  
  57.     }
  58.  
  59.     function update($new_instance, $old_instance) {
  60.         //save the widget
  61.         $instance = $old_instance;
  62.         foreach($new_instance as $key=>$value)
  63.         {
  64.             $instance[$key] = strip_tags($new_instance[$key]);
  65.         }
  66.  
  67.         delete_transient(THEMENAME.'_tweetcache_id_'.$instance['username'].'_'.$this->id_base."-".$this->number);
  68.         return $instance;
  69.     }
  70.  
  71.     function form($instance) {
  72.         //widgetform in backend
  73.  
  74.         $instance = wp_parse_args( (array) $instance, array( 'title' => 'Latest Tweets', 'count' => '3', 'username' => avia_get_option('twitter') ) );
  75.         $title =            isset($instance['title']) ? strip_tags($instance['title']): "";
  76.         $count =            isset($instance['count']) ? strip_tags($instance['count']): "";
  77.         $username =         isset($instance['username']) ? strip_tags($instance['username']): "";
  78.         $exclude_replies =  isset($instance['exclude_replies']) ? strip_tags($instance['exclude_replies']): "";
  79.         $time =             isset($instance['time']) ? strip_tags($instance['time']): "";
  80.         $display_image =    isset($instance['display_image']) ? strip_tags($instance['display_image']): "";
  81. ?>
  82.         <p>
  83.         <label for="<?php echo $this->get_field_id('title'); ?>">Title:
  84.         <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></label></p>
  85.  
  86.         <p><label for="<?php echo $this->get_field_id('username'); ?>">Enter your twitter username:
  87.         <input class="widefat" id="<?php echo $this->get_field_id('username'); ?>" name="<?php echo $this->get_field_name('username'); ?>" type="text" value="<?php echo esc_attr($username); ?>" /></label></p>
  88.  
  89.         <p>
  90.             <label for="<?php echo $this->get_field_id('count'); ?>">How many entries do you want to display: </label>
  91.             <select class="widefat" id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>">
  92.                 <?php
  93.                 $list = "";
  94.                 for ($i = 1; $i <= 20; $i++ )
  95.                 {
  96.                     $selected = "";
  97.                     if($count == $i) $selected = 'selected="selected"';
  98.  
  99.                     $list .= "<option $selected value='$i'>$i</option>";
  100.                 }
  101.                 $list .= "</select>";
  102.                 echo $list;
  103.                 ?>
  104.  
  105.  
  106.         </p>
  107.  
  108.         <p>
  109.             <label for="<?php echo $this->get_field_id('exclude_replies'); ?>">Exclude @replies: </label>
  110.             <select class="widefat" id="<?php echo $this->get_field_id('exclude_replies'); ?>" name="<?php echo $this->get_field_name('exclude_replies'); ?>">
  111.                 <?php
  112.                 $list = "";
  113.                 $answers = array('yes','no');
  114.                 foreach ($answers as $answer)
  115.                 {
  116.                     $selected = "";
  117.                     if($answer == $exclude_replies) $selected = 'selected="selected"';
  118.  
  119.                     $list .= "<option $selected value='$answer'>$answer</option>";
  120.                 }
  121.                 $list .= "</select>";
  122.                 echo $list;
  123.                 ?>
  124.  
  125.  
  126.         </p>
  127.  
  128.         <p>
  129.             <label for="<?php echo $this->get_field_id('time'); ?>">Display time of tweet</label>
  130.             <select class="widefat" id="<?php echo $this->get_field_id('time'); ?>" name="<?php echo $this->get_field_name('time'); ?>">
  131.                 <?php
  132.                 $list = "";
  133.                 $answers = array('yes','no');
  134.                 foreach ($answers as $answer)
  135.                 {
  136.                     $selected = "";
  137.                     if($answer == $time) $selected = 'selected="selected"';
  138.  
  139.                     $list .= "<option $selected value='$answer'>$answer</option>";
  140.                 }
  141.                 $list .= "</select>";
  142.                 echo $list;
  143.                 ?>
  144.  
  145.  
  146.         </p>
  147.  
  148.         <p>
  149.             <label for="<?php echo $this->get_field_id('display_image'); ?>">Display Twitter User Avatar</label>
  150.             <select class="widefat" id="<?php echo $this->get_field_id('display_image'); ?>" name="<?php echo $this->get_field_name('display_image'); ?>">
  151.                 <?php
  152.                 $list = "";
  153.                 $answers = array('yes','no');
  154.                 foreach ($answers as $answer)
  155.                 {
  156.                     $selected = "";
  157.                     if($answer == $display_image) $selected = 'selected="selected"';
  158.  
  159.                     $list .= "<option $selected value='$answer'>$answer</option>";
  160.                 }
  161.                 $list .= "</select>";
  162.                 echo $list;
  163.                 ?>
  164.         </p>
  165.  
  166.  
  167.  
  168.     <?php
  169.     }
  170. }
  171.  
  172.  
  173.  
  174. function tweetbox_get_tweet($count, $username, $widget_id, $time='yes', $exclude_replies='yes', $avatar = 'yes')
  175. {
  176.         $filtered_message = "";
  177.         $output = "";
  178.         $iterations = 0;
  179.  
  180.         $cache = get_transient(THEMENAME.'_tweetcache_id_'.$username.'_'.$widget_id);
  181.  
  182.         if($cache)
  183.         {
  184.             $tweets = get_option(THEMENAME.'_tweetcache_'.$username.'_'.$widget_id);
  185.         }
  186.         else
  187.         {
  188.             //$response = wp_remote_get( 'http://api.twitter.com/1/statuses/user_timeline.xml?screen_name='.$username );
  189.             $response = wp_remote_get( 'http://api.twitter.com/1/statuses/user_timeline.xml?include_rts=true&screen_name='.$username );
  190.             if (!is_wp_error($response))
  191.             {
  192.                 $xml = simplexml_load_string($response['body']);
  193.                 //follower: (int) $xml->status->user->followers_count
  194.  
  195.                 if( empty( $xml->error ) )
  196.                 {
  197.                     if ( isset($xml->status[0]))
  198.                     {
  199.  
  200.                         $tweets = array();
  201.                         foreach ($xml->status as $tweet)
  202.                         {
  203.                             if($iterations == $count) break;
  204.  
  205.                             $text = (string) $tweet->text;
  206.                             if($exclude_replies == 'no' || ($exclude_replies == 'yes' && $text[0] != "@"))
  207.                             {
  208.                                 $iterations++;
  209.                                 $tweets[] = array(
  210.                                     'text' => tweetbox_filter( $text ),
  211.                                     'created' =>  strtotime( $tweet->created_at ),
  212.                                     'user' => array(
  213.                                         'name' => (string)$tweet->user->name,
  214.                                         'screen_name' => (string)$tweet->user->screen_name,
  215.                                         'image' => (string)$tweet->user->profile_image_url,
  216.                                         'utc_offset' => (int) $tweet->user->utc_offset[0],
  217.                                         'follower' => (int) $tweet->user->followers_count
  218.  
  219.                                     ));
  220.                             }
  221.                         }
  222.  
  223.                         set_transient(THEMENAME.'_tweetcache_id_'.$username.'_'.$widget_id, 'true', 60*30);
  224.                         update_option(THEMENAME.'_tweetcache_'.$username.'_'.$widget_id, $tweets);
  225.                     }
  226.                 }
  227.             }
  228.         }
  229.  
  230.  
  231.  
  232.         if(!isset($tweets[0]))
  233.         {
  234.             $tweets = get_option(THEMENAME.'_tweetcache_'.$username.'_'.$widget_id);
  235.         }
  236.  
  237.         if(isset($tweets[0]))
  238.         {
  239.             $time_format = apply_filters( 'avia_widget_time' , get_option('date_format')." - ".get_option('time_format') );
  240.  
  241.             foreach ($tweets as $message)
  242.             {
  243.                 $output .= '<li class="tweet">';
  244.                 if($avatar == "yes") $output .= '<div class="tweet-thumb"><a href="http://twitter.com/'.$username.'" title=""><img src="'.$message['user']['image'].'" alt="" /></a></div>';
  245.                 $output .= '<div class="tweet-text avatar_'.$avatar.'">'.$message['text'];
  246.                 if($time == "yes") $output .= '<div class="tweet-time">'.date_i18n( $time_format, $message['created'] + $message['user']['utc_offset']).'</div>';
  247.                 $output .= '</div></li>';
  248.             }
  249.         }
  250.  
  251.  
  252.         if($output != "")
  253.         {
  254.             $filtered_message = "<ul class='tweets'>$output</ul>";
  255.         }
  256.         else
  257.         {
  258.             $filtered_message = "<ul class='tweets'><li>No public Tweets found</li></ul>";
  259.         }
  260.  
  261.         return $filtered_message;
  262. }
  263.  
  264.  
  265. function tweetbox_filter($text) {
  266.     // Props to Allen Shaw & webmancers.com & Michael Voigt
  267.     $text = preg_replace('/\b([a-zA-Z]+:\/\/[\w_.\-]+\.[a-zA-Z]{2,6}[\/\w\-~.?=&%#+$*!]*)\b/i',"<a href=\"$1\" class=\"twitter-link\">$1</a>", $text);
  268.     $text = preg_replace('/\b(?<!:\/\/)(www\.[\w_.\-]+\.[a-zA-Z]{2,6}[\/\w\-~.?=&%#+$*!]*)\b/i',"<a href=\"http://$1\" class=\"twitter-link\">$1</a>", $text);
  269.     $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","<a href=\"mailto://$1\" class=\"twitter-link\">$1</a>", $text);
  270.     $text = preg_replace("/#([\p{L}\p{Mn}]+)/u", "<a class=\"twitter-link\" href=\"http://search.twitter.com/search?q=\\1\">#\\1</a>", $text);
  271.     $text = preg_replace("/@([\p{L}\p{Mn}]+)/u", "<a class=\"twitter-link\" href=\"http://twitter.com/\\1\">@\\1</a>", $text);
  272.  
  273.     return $text;
  274. }
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284. /**
  285.  * AVIA NEWSBOX
  286.  *
  287.  * Widget that creates a list of latest news entries
  288.  *
  289.  * @package AviaFramework
  290.  * @todo replace the widget system with a dynamic one, based on config files for easier widget creation
  291.  */
  292.  
  293.  
  294. class avia_newsbox extends WP_Widget {
  295.  
  296.     var $avia_term = '';
  297.     var $avia_post_type = '';
  298.     var $avia_new_query = '';
  299.  
  300.     function avia_newsbox()
  301.     {
  302.         $widget_ops = array('classname' => 'newsbox', 'description' => 'A Sidebar widget to display latest post entries in your sidebar' );
  303.  
  304.         $this->WP_Widget( 'newsbox', THEMENAME.' Latest News', $widget_ops );
  305.     }
  306.  
  307.     function widget($args, $instance)
  308.     {
  309.  
  310.         global $avia_config;
  311.  
  312.         extract($args, EXTR_SKIP);
  313.         echo $before_widget;
  314.  
  315.         $title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);
  316.         $count = empty($instance['count']) ? '' : $instance['count'];
  317.         $cat = empty($instance['cat']) ? '' : $instance['cat'];
  318.         $excerpt = empty($instance['excerpt']) ? '' : $instance['excerpt'];
  319.         $image_size = isset($avia_config['widget_image_size']) ? $avia_config['widget_image_size'] : 'widget';
  320.  
  321.         if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
  322.  
  323.  
  324.         if(empty($this->avia_term))
  325.         {
  326.             $additional_loop = new WP_Query("cat=".$cat."&posts_per_page=".$count);
  327.         }
  328.         else
  329.         {
  330.             $catarray = explode(',', $cat);
  331.  
  332.  
  333.             if(empty($catarray[0]))
  334.             {
  335.                 $new_query = array("posts_per_page"=>$count,"post_type"=>$this->avia_post_type);
  336.             }
  337.             else
  338.             {
  339.                 if($this->avia_new_query)
  340.                 {
  341.                     $new_query = $this->avia_new_query;
  342.                 }
  343.                 else
  344.                 {
  345.                     $new_query = array( "posts_per_page"=>$count, 'tax_query' => array(
  346.                                                     array( 'taxonomy' => $this->avia_term,
  347.                                                            'field' => 'id',
  348.                                                            'terms' => explode(',', $cat),
  349.                                                            'operator' => 'IN')
  350.                                                           )
  351.                                                     );
  352.                 }
  353.             }
  354.  
  355.             $additional_loop = new WP_Query($new_query);
  356.         }
  357.  
  358.         if($additional_loop->have_posts()) :
  359.  
  360.  
  361.  
  362.         echo '<ul class="news-wrap image_size_'.$image_size.'">';
  363.         while ($additional_loop->have_posts()) : $additional_loop->the_post();
  364.  
  365.         $format = "";
  366.         if(empty($this->avia_post_type))    $format = $this->avia_post_type;
  367.         if(empty($format))                  $format = get_post_format();
  368.         if(empty($format))                  $format = 'standard';
  369.  
  370.         echo '<li class="news-content post-format-'.$format.'">';
  371.  
  372.         //check for preview images:
  373.         $image = "";
  374.         $slides = avia_post_meta(get_the_ID(), 'slideshow', true);
  375.  
  376.  
  377.  
  378.         if( $slides != "" && !empty( $slides[0]['slideshow_image'] ) )
  379.         {
  380.             $image = avia_image_by_id($slides[0]['slideshow_image'], $image_size, 'image');
  381.         }
  382.  
  383.         if(!$image && current_theme_supports( 'post-thumbnails' ))
  384.         {
  385.             $image = get_the_post_thumbnail( get_the_ID(), $image_size );
  386.         }
  387.  
  388.         $time_format = apply_filters( 'avia_widget_time' , get_option('date_format')." - ".get_option('time_format') );
  389.  
  390.  
  391.         echo "<a class='news-link' title='".get_the_title()."' href='".get_permalink()."'>";
  392.         echo "<span class='news-thumb'>";
  393.         echo $image;
  394.         echo "</span>";
  395.         if(empty($avia_config['widget_image_size']) || 'display title and excerpt' != $excerpt) { echo "<strong class='news-headline'>".get_the_title()."<span class='news-time'>".get_the_time($time_format)."</span></strong>";  }
  396.         echo "</a>";
  397.  
  398.         if('display title and excerpt' == $excerpt)
  399.         {
  400.             echo "<div class='news-excerpt'>";
  401.  
  402.             if(!empty($avia_config['widget_image_size']))
  403.             {
  404.                 echo "<a class='news-link-inner' title='".get_the_title()."' href='".get_permalink()."'>";
  405.                 echo "<strong class='news-headline'>".get_the_title()."</strong>";
  406.                 echo "</a>";
  407.                 echo "<span class='news-time'>".get_the_time($time_format)."</span>";
  408.             }
  409.             the_excerpt();
  410.             echo "</div>";
  411.         }
  412.  
  413.         echo '</li>';
  414.  
  415.  
  416.         endwhile;
  417.         echo "</ul>";
  418.         wp_reset_postdata();
  419.         endif;
  420.  
  421.  
  422.         echo $after_widget;
  423.  
  424.     }
  425.  
  426.  
  427.     function update($new_instance, $old_instance)
  428.     {
  429.         $instance = $old_instance;
  430.         $instance['title'] = strip_tags($new_instance['title']);
  431.         $instance['count'] = strip_tags($new_instance['count']);
  432.         $instance['excerpt'] = strip_tags($new_instance['excerpt']);
  433.         $instance['cat'] = implode(',',$new_instance['cat']);
  434.         return $instance;
  435.     }
  436.  
  437.  
  438.  
  439.     function form($instance)
  440.     {
  441.         $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'count' => '', 'cat' => '', 'excerpt'=>'' ) );
  442.         $title = strip_tags($instance['title']);
  443.         $count = strip_tags($instance['count']);
  444.         $excerpt = strip_tags($instance['excerpt']);
  445.  
  446.  
  447.         $elementCat = array("name"  => "Which categories should be used for the portfolio?",
  448.                             "desc"  => "You can select multiple categories here",
  449.                             "id"    => $this->get_field_name('cat')."[]",
  450.                             "type"  => "select",
  451.                             "std"   => strip_tags($instance['cat']),
  452.                             "class" => "",
  453.                             "multiple"=>6,
  454.                             "subtype" => "cat");
  455.         //check if a different taxonomy than the default is set
  456.         if(!empty($this->avia_term))
  457.         {
  458.             $elementCat['taxonomy'] = $this->avia_term;
  459.         }
  460.  
  461.  
  462.  
  463.  
  464.         $html = new avia_htmlhelper();
  465.  
  466. ?>
  467.         <p><label for="<?php echo $this->get_field_id('title'); ?>">Title:
  468.         <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></label></p>
  469.  
  470.         <p>
  471.             <label for="<?php echo $this->get_field_id('count'); ?>">How many entries do you want to display: </label>
  472.             <select class="widefat" id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>">
  473.                 <?php
  474.                 $list = "";
  475.                 for ($i = 1; $i <= 20; $i++ )
  476.                 {
  477.                     $selected = "";
  478.                     if($count == $i) $selected = 'selected="selected"';
  479.  
  480.                     $list .= "<option $selected value='$i'>$i</option>";
  481.                 }
  482.                 $list .= "</select>";
  483.                 echo $list;
  484.                 ?>
  485.  
  486.  
  487.         </p>
  488.  
  489.         <p><label for="<?php echo $this->get_field_id('cat'); ?>">Choose the categories you want to display (multiple selection possible):
  490.         <?php echo $html->select($elementCat); ?>
  491.         </label></p>
  492.  
  493.         <p>
  494.             <label for="<?php echo $this->get_field_id('excerpt'); ?>">Display title only or title &amp; excerpt</label>
  495.             <select class="widefat" id="<?php echo $this->get_field_id('excerpt'); ?>" name="<?php echo $this->get_field_name('excerpt'); ?>">
  496.                 <?php
  497.                 $list = "";
  498.                 $answers = array('show title only','display title and excerpt');
  499.                 foreach ($answers as $answer)
  500.                 {
  501.                     $selected = "";
  502.                     if($answer == $excerpt) $selected = 'selected="selected"';
  503.  
  504.                     $list .= "<option $selected value='$answer'>$answer</option>";
  505.                 }
  506.                 $list .= "</select>";
  507.                 echo $list;
  508.                 ?>
  509.  
  510.  
  511.         </p>
  512.  
  513.  
  514. <?php
  515.     }
  516. }
  517.  
  518.  
  519.  
  520. /**
  521.  * AVIA PORTFOLIOBOX
  522.  *
  523.  * 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
  524.  *
  525.  * @package AviaFramework
  526.  * @todo replace the widget system with a dynamic one, based on config files for easier widget creation
  527.  */
  528.  
  529. class avia_portfoliobox extends avia_newsbox
  530. {
  531.     function avia_portfoliobox()
  532.     {
  533.         $this->avia_term = 'portfolio_entries';
  534.         $this->avia_post_type = 'portfolio';
  535.         $this->avia_new_query = ''; //set a custom query here
  536.  
  537.  
  538.         $widget_ops = array('classname' => 'newsbox', 'description' => 'A Sidebar widget to display latest portfolio entries in your sidebar' );
  539.  
  540.         $this->WP_Widget( 'portfoliobox', THEMENAME.' Latest Portfolio', $widget_ops );
  541.     }
  542. }
  543.  
  544.  
  545.  
  546.  
  547. /**
  548.  * AVIA SOCIALCOUNT
  549.  *
  550.  * Widget that retrieves, stores and displays the number of twitter and rss followers
  551.  *
  552.  * @package AviaFramework
  553.  * @todo replace the widget system with a dynamic one, based on config files for easier widget creation
  554.  */
  555.  
  556.  
  557. class avia_socialcount extends WP_Widget {
  558.  
  559.     function avia_socialcount() {
  560.         //Constructor
  561.         $widget_ops = array('classname' => 'avia_socialcount', 'description' => 'A widget to display a linkt to your twitter profile and rss feed' );
  562.         $this->WP_Widget( 'avia_socialcount', THEMENAME.' RSS Link and Twitter Account', $widget_ops );
  563.     }
  564.  
  565.     function widget($args, $instance) {
  566.         // prints the widget
  567.  
  568.         extract($args, EXTR_SKIP);
  569.         $twitter = empty($instance['twitter']) ? '' : $instance['twitter'];
  570.         $rss     = empty($instance['rss'])     ? '' : $instance['rss'];
  571.         $rss = preg_replace('!https?:\/\/feeds.feedburner.com\/!','',$rss);
  572.  
  573.         $follower = $this->count_followers($twitter, $rss, $widget_id);
  574.  
  575.  
  576.         if(!empty($follower) && is_array($follower))
  577.         {
  578.             $addClass = "asc_multi_count";
  579.             if(!isset($follower['twitter']) || !isset($follower['rss'])) $addClass = 'asc_single_count';
  580.  
  581.             echo $before_widget;
  582.             $output = "";
  583.             if(isset($follower['twitter']))
  584.             {
  585.                 $link = 'http://twitter.com/'.$twitter.'/';
  586.                 $before = apply_filters('avf_social_widget', "", 'twitter');
  587.                
  588.                 if ( $follower['twitter'] <= '1' )
  589.                 {
  590.                     $output .= "<a href='$link' class='asc_twitter $addClass'>{$before}<strong class='asc_count'>".$follower['twitter']."</strong><span>".__('Follower','avia_framework')."</span></a>";
  591.                 }
  592.                 else
  593.                 {
  594.                     $output .= "<a href='$link' class='asc_twitter $addClass'>{$before}<strong class='asc_count'>".$follower['twitter']."</strong><span>".__('Followers','avia_framework')."</span></a>";
  595.                 }
  596.             }
  597.            
  598.             if(isset($follower['rss']) && $rss)
  599.             {
  600.                 $link = $rss;
  601.  
  602.                 if(is_numeric($follower['rss']))
  603.                 {
  604.                     $feed_text = __('Subscribers','avia_framework');
  605.                 }
  606.                 else
  607.                 {
  608.                     $follower['rss'] = __('Subscribe','avia_framework');
  609.                     $feed_text = __('to RSS Feed','avia_framework');
  610.                 }
  611.  
  612.                 $output .= "<a href='$link' class='asc_rss $addClass'>".apply_filters('avf_social_widget',"", 'rss')."<strong class='asc_count'>".$follower['rss']."</strong><span>".$feed_text."</span></a>";
  613.             }
  614.            
  615.             echo $output;
  616.             echo $after_widget;
  617.         }
  618.     }
  619.  
  620.     function count_followers($twitter, $rss, $widget_id)
  621.     {
  622.         $follower = array();
  623.         $optionkey = strtolower(THEMENAME.'fc_id'.$widget_id);
  624.         $cache = get_transient($optionkey);
  625.  
  626.         if($cache)
  627.         {
  628.             $follower = get_option($optionkey);
  629.         }
  630.         else
  631.         {
  632.             if($twitter != "")
  633.             {
  634.                 //this function also works without the twitter api beeing active. instead of usercount we will display the word "Twitter"
  635.                 $twittercount = wp_remote_get( 'http://api.twitter.com/1/statuses/user_timeline.xml?screen_name='.$twitter );
  636.  
  637.                 if (!is_wp_error($twittercount))
  638.                 {
  639.                     $xml = simplexml_load_string($twittercount['body']);
  640.  
  641.                     if( empty( $xml->error ) && isset($xml->status->user->followers_count))
  642.                     {
  643.                         $follower['twitter'] = (int) $xml->status->user->followers_count;
  644.                     }
  645.                     else
  646.                     {
  647.                         $follower['twitter'] = "Twitter";
  648.                     }
  649.                 }
  650.             }
  651.  
  652.             if($rss != "")
  653.             {
  654.                 $requesturl = "http://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=http://feeds.feedburner.com/".$rss.'&dates=' . date('Y-m-d', strtotime('-2 days', time()));
  655.  
  656.                 //$feedcount = wp_remote_get($requesturl);
  657.                 $feedcount = ""; $follower['rss'] = true;
  658.  
  659.                 if (!empty($feedcount) && !is_wp_error($feedcount))
  660.                 {
  661.                     $xml = @simplexml_load_string($feedcount['body']);
  662.  
  663.                     if(is_object($xml->feed->entry))
  664.                     {
  665.                         $follower['rss'] = (int) $xml->feed->entry->attributes()->circulation;
  666.                     }
  667.                     else
  668.                     {
  669.                         $follower['rss'] = true;
  670.                     }
  671.                 }
  672.             }
  673.  
  674.             $fallback = get_option($optionkey);
  675.  
  676.             if(!isset($follower['rss']) && isset($fallback['rss'])) $follower['rss'] = $fallback['rss'];
  677.             if(!isset($follower['twitter']) && isset($fallback['twitter'])) $follower['twitter'] = $fallback['twitter'];
  678.  
  679.             set_transient($optionkey, 1, 60*60*36);
  680.             update_option($optionkey, $follower);
  681.  
  682.         }
  683.  
  684.         return $follower;
  685.     }
  686.  
  687.  
  688.  
  689.  
  690.     function update($new_instance, $old_instance) {
  691.         //save the widget
  692.         $instance = $old_instance;
  693.         foreach($new_instance as $key=>$value)
  694.         {
  695.             $instance[$key] = strip_tags($new_instance[$key]);
  696.         }
  697.  
  698.         delete_transient(strtolower(THEMENAME.'fc_id'.$this->id_base."-".$this->number));
  699.         return $instance;
  700.     }
  701.  
  702.     function form($instance) {
  703.         //widgetform in backend
  704.  
  705.         $instance = wp_parse_args( (array) $instance, array('rss' => avia_get_option('feedburner'), 'twitter' => avia_get_option('twitter') ) );
  706.         $twitter = empty($instance['twitter']) ? '' :  strip_tags($instance['twitter']);
  707.         $rss     = empty($instance['rss'])     ? '' :  strip_tags($instance['rss']);
  708. ?>
  709.         <p>
  710.         <label for="<?php echo $this->get_field_id('twitter'); ?>">Twitter Username:
  711.         <input class="widefat" id="<?php echo $this->get_field_id('twitter'); ?>" name="<?php echo $this->get_field_name('twitter'); ?>" type="text" value="<?php echo esc_attr($twitter); ?>" /></label></p>
  712.  
  713.         <p><label for="<?php echo $this->get_field_id('rss'); ?>">Enter your feed url:
  714.         <input class="widefat" id="<?php echo $this->get_field_id('rss'); ?>" name="<?php echo $this->get_field_name('rss'); ?>" type="text" value="<?php echo esc_attr($rss); ?>" /></label></p>
  715.  
  716.  
  717.  
  718.     <?php
  719.     }
  720. }
  721.  
  722.  
  723.  
  724.  
  725.  
  726. /**
  727.  * AVIA ADVERTISING WIDGET
  728.  *
  729.  * Widget that retrieves, stores and displays the number of twitter and rss followers
  730.  *
  731.  * @package AviaFramework
  732.  * @todo replace the widget system with a dynamic one, based on config files for easier widget creation
  733.  */
  734.  
  735.  
  736. //multiple images
  737.  
  738. class avia_partner_widget extends WP_Widget {
  739.  
  740.     function avia_partner_widget() {
  741.  
  742.         $this->add_cont = 2;
  743.         //Constructor
  744.         $widget_ops = array('classname' => 'avia_partner_widget', 'description' => 'An advertising widget that displays 2 images with 125 x 125 px in size' );
  745.         $this->WP_Widget( 'avia_partner_widget', THEMENAME.' Advertising Area', $widget_ops );
  746.     }
  747.  
  748.     function widget($args, $instance)
  749.     {
  750.         extract($args, EXTR_SKIP);
  751.         echo $before_widget;
  752.  
  753.         global $kriesiaddwidget, $firsttitle;
  754.         $kriesiaddwidget ++;
  755.  
  756.         $title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);
  757.         $image_url = empty($instance['image_url']) ? '<span class="avia_parnter_empty"><span>'.__('Advertise here','avia_framework').'</span></span>' : '<img class="rounded" src="'.$instance['image_url'].'" title="" alt=""/>';
  758.         $ref_url = empty($instance['ref_url']) ? '#' : apply_filters('widget_comments_title', $instance['ref_url']);
  759.         $image_url2 = empty($instance['image_url2']) ? '<span class="avia_parnter_empty"><span>'.__('Advertise here','avia_framework').'</span></span>' : '<img class="rounded" src="'.$instance['image_url2'].'" title="" alt=""/>';
  760.         $ref_url2 = empty($instance['ref_url2']) ? '#' : apply_filters('widget_comments_title', $instance['ref_url2']);
  761.  
  762.         if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
  763.         echo '<a href="'.$ref_url.'" class="preloading_background  avia_partner1 link_list_item'.$kriesiaddwidget.' '.$firsttitle.'" >'.$image_url.'</a>';
  764.         if($this->add_cont == 2) echo '<a href="'.$ref_url2.'" class="preloading_background avia_partner2 link_list_item'.$kriesiaddwidget.' '.$firsttitle.'" >'.$image_url2.'</a>';
  765.         echo $after_widget;
  766.  
  767.         if($title == '')
  768.         {
  769.             $firsttitle = 'no_top_margin';
  770.         }
  771.  
  772.     }
  773.  
  774.  
  775.     function update($new_instance, $old_instance) {
  776.         //save the widget
  777.         $instance = $old_instance;
  778.         foreach($new_instance as $key=>$value)
  779.         {
  780.             $instance[$key] = strip_tags($new_instance[$key]);
  781.         }
  782.         return $instance;
  783.     }
  784.  
  785.  
  786.  
  787.     function form($instance)
  788.     {
  789.         $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'image_url' => '', 'ref_url' => '', 'image_url2' => '', 'ref_url2' => '' ) );
  790.         $title = strip_tags($instance['title']);
  791.         $image_url = strip_tags($instance['image_url']);
  792.         $ref_url = strip_tags($instance['ref_url']);
  793.         $image_url2 = strip_tags($instance['image_url2']);
  794.         $ref_url2 = strip_tags($instance['ref_url2']);
  795. ?>
  796.         <p><label for="<?php echo $this->get_field_id('title'); ?>">Title:
  797.         <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></label></p>
  798.  
  799.         <p><label for="<?php echo $this->get_field_id('image_url'); ?>">Image URL: <?php if($this->add_cont == 2) echo "(125px * 125px):"; ?>
  800.         <input class="widefat" id="<?php echo $this->get_field_id('image_url'); ?>" name="<?php echo $this->get_field_name('image_url'); ?>" type="text" value="<?php echo esc_attr($image_url); ?>" /></label></p>
  801.  
  802.         <p><label for="<?php echo $this->get_field_id('ref_url'); ?>">Referal URL:
  803.         <input class="widefat" id="<?php echo $this->get_field_id('ref_url'); ?>" name="<?php echo $this->get_field_name('ref_url'); ?>" type="text" value="<?php echo esc_attr($ref_url); ?>" /></label></p>
  804.  
  805.         <?php if($this->add_cont == 2)
  806.         { ?>
  807.  
  808.                 <p><label for="<?php echo $this->get_field_id('image_url2'); ?>">Image URL 2: (125px * 125px):
  809.         <input class="widefat" id="<?php echo $this->get_field_id('image_url2'); ?>" name="<?php echo $this->get_field_name('image_url2'); ?>" type="text" value="<?php echo esc_attr($image_url2); ?>" /></label></p>
  810.  
  811.         <p><label for="<?php echo $this->get_field_id('ref_url2'); ?>">Referal URL 2:
  812.         <input class="widefat" id="<?php echo $this->get_field_id('ref_url2'); ?>" name="<?php echo $this->get_field_name('ref_url2'); ?>" type="text" value="<?php echo esc_attr($ref_url2); ?>" /></label></p>
  813.  
  814.         <?php }?>
  815.  
  816. <?php
  817.     }
  818. }
  819.  
  820.  
  821. //one image
  822. class avia_one_partner_widget extends avia_partner_widget
  823. {
  824.     function avia_one_partner_widget()
  825.     {
  826.  
  827.         $this->add_cont = 1;
  828.  
  829.         $widget_ops = array('classname' => 'avia_one_partner_widget', 'description' => 'An advertising widget that displays 1 big image' );
  830.  
  831.         $this->WP_Widget( 'avia_one_partner_widget', THEMENAME.' Big Advertising Area', $widget_ops );
  832.     }
  833. }
  834.  
  835.  
  836.  
  837.  
  838. /**
  839.  * AVIA COMBO WIDGET
  840.  *
  841.  * Widget that retrieves, stores and displays the number of twitter and rss followers
  842.  *
  843.  * @package AviaFramework
  844.  * @todo replace the widget system with a dynamic one, based on config files for easier widget creation
  845.  */
  846.  
  847.  
  848. class avia_combo_widget extends WP_Widget {
  849.  
  850.     function avia_combo_widget() {
  851.         //Constructor
  852.         $widget_ops = array('classname' => 'avia_combo_widget', 'description' => 'A widget that displays your popular posts, recent posts, recent comments and a tagcloud' );
  853.         $this->WP_Widget( 'avia_combo_widget', THEMENAME.' Combo Widget', $widget_ops );
  854.     }
  855.  
  856.     function widget($args, $instance)
  857.     {
  858.         // prints the widget
  859.  
  860.         extract($args, EXTR_SKIP);
  861.         $posts = empty($instance['count']) ? 4 : $instance['count'];
  862.  
  863.         echo $before_widget;
  864.         echo "<div class='tabcontainer border_tabs top_tab tab_initial_open tab_initial_open__1'>";
  865.  
  866.         echo '<div class="tab first_tab active_tab widget_tab_popular"><span>'.__('Popular', 'avia_framework').'</span></div>';
  867.         echo "<div class='tab_content active_tab_content'>";
  868.         avia_get_post_list('cat=&orderby=comment_count&posts_per_page='.$posts);
  869.         echo "</div>";
  870.  
  871.         echo '<div class="tab widget_tab_recent"><span>'.__('Recent', 'avia_framework').'</span></div>';
  872.         echo "<div class='tab_content'>";
  873.         avia_get_post_list('showposts='. $posts .'&orderby=post_date&order=desc');
  874.         echo "</div>";
  875.  
  876.         echo '<div class="tab widget_tab_comments"><span>'.__('Comments', 'avia_framework').'</span></div>';
  877.         echo "<div class='tab_content'>";
  878.         avia_get_comment_list( array('number' => $posts, 'status' => 'approve', 'order' => 'DESC') );
  879.         echo "</div>";
  880.  
  881.         echo '<div class="tab last_tab widget_tab_tags"><span>'.__('Tags', 'avia_framework').'</span></div>';
  882.         echo "<div class='tab_content tagcloud'>";
  883.         wp_tag_cloud('smallest=12&largest=12&unit=px');
  884.         echo "</div>";
  885.  
  886.         echo "</div>";
  887.         echo $after_widget;
  888.     }
  889.  
  890.  
  891.     function update($new_instance, $old_instance)
  892.     {
  893.         $instance = $old_instance;
  894.         foreach($new_instance as $key=>$value)
  895.         {
  896.             $instance[$key] = strip_tags($new_instance[$key]);
  897.         }
  898.  
  899.         return $instance;
  900.     }
  901.  
  902.     function form($instance) {
  903.         //widgetform in backend
  904.  
  905.         $instance = wp_parse_args( (array) $instance, array('count' => 4) );
  906.         if(!is_numeric($instance['count'])) $instance['count'] = 4;
  907.  
  908. ?>
  909.         <p>
  910.         <label for="<?php echo $this->get_field_id('count'); ?>">Number of posts you want to display:
  911.         <input class="widefat" id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>" type="text" value="<?php echo esc_attr($instance['count']); ?>" /></label></p>
  912.  
  913.  
  914.     <?php
  915.     }
  916. }
  917.  
  918. /*-----------------------------------------------------------------------------------
  919. get posts posts
  920. -----------------------------------------------------------------------------------*/
  921. if (!function_exists('avia_get_post_list'))
  922. {
  923.     function avia_get_post_list( $avia_new_query , $excerpt = false)
  924.     {
  925.         global $avia_config;
  926.  
  927.         $additional_loop = new WP_Query($avia_new_query);
  928.  
  929.         if($additional_loop->have_posts()) :
  930.         echo '<ul class="news-wrap">';
  931.         while ($additional_loop->have_posts()) : $additional_loop->the_post();
  932.  
  933.         $format = "";
  934.         if(get_post_type() != 'post')       $format = get_post_type();
  935.         if(empty($format))                  $format = get_post_format();
  936.         if(empty($format))                  $format = 'standard';
  937.  
  938.         echo '<li class="news-content post-format-'.$format.'">';
  939.  
  940.         //check for preview images:
  941.         $image = "";
  942.         $slides = avia_post_meta(get_the_ID(), 'slideshow');
  943.  
  944.         if( $slides != "" && !empty( $slides[0]['slideshow_image'] ) )
  945.         {
  946.             $image = avia_image_by_id($slides[0]['slideshow_image'], 'widget', 'image');
  947.         }
  948.  
  949.         $time_format = apply_filters( 'avia_widget_time' , get_option('date_format')." - ".get_option('time_format') );
  950.  
  951.         echo "<a class='news-link' title='".get_the_title()."' href='".get_permalink()."'>";
  952.         echo "<span class='news-thumb'>";
  953.         echo $image;
  954.         echo "</span>";
  955.         echo "<strong class='news-headline'>".avia_backend_truncate(get_the_title(), 55," ");
  956.         echo "<span class='news-time'>".get_the_time($time_format)."</span>";
  957.         echo "</strong>";
  958.         echo "</a>";
  959.  
  960.         if('display title and excerpt' == $excerpt)
  961.         {
  962.             echo "<div class='news-excerpt'>";
  963.             the_excerpt();
  964.             echo "</div>";
  965.         }
  966.  
  967.         echo '</li>';
  968.  
  969.  
  970.         endwhile;
  971.         echo "</ul>";
  972.         wp_reset_postdata();
  973.         endif;
  974.     }
  975. }
  976.  
  977.  
  978.  
  979.  
  980.  
  981. if (!function_exists('avia_get_comment_list'))
  982. {
  983.  
  984.     function avia_get_comment_list($avia_new_query)
  985.     {
  986.         $time_format = apply_filters( 'avia_widget_time' , get_option('date_format')." - ".get_option('time_format') );
  987.    
  988.         global $avia_config;
  989.  
  990.         $comments = get_comments($avia_new_query);
  991.  
  992.         if(!empty($comments)) :
  993.         echo '<ul class="news-wrap">';
  994.         foreach($comments as $comment)
  995.         {
  996.  
  997.         echo '<li class="news-content">';
  998.         echo "<a class='news-link' title='".get_the_title($comment->comment_post_ID)."' href='".get_comment_link($comment)."'>";
  999.         echo "<span class='news-thumb'>";
  1000.         echo get_avatar($comment,'48');
  1001.         echo "</span>";
  1002.         echo "<strong class='news-headline'>".avia_backend_truncate($comment->comment_content, 55," ");
  1003.         echo "<span class='news-time'>".get_the_time($time_format, $comment->comment_post_ID)." by ".$comment->comment_author."</span>";
  1004.         echo "</strong>";
  1005.         echo "</a>";
  1006.  
  1007.         echo '</li>';
  1008.  
  1009.  
  1010.         }
  1011.         echo "</ul>";
  1012.         wp_reset_postdata();
  1013.         endif;
  1014.     }
  1015. }
  1016.  
  1017.  
  1018.  
  1019. /*
  1020.     Google Maps Widget
  1021.  
  1022.     Copyright 2009  Clark Nikdel Powell  (email : taylor@cnpstudio.com)
  1023.  
  1024.     This program is free software; you can redistribute it and/or modify
  1025.     it under the terms of the GNU General Public License as published by
  1026.     the Free Software Foundation; either version 2 of the License, or
  1027.     (at your option) any later version.
  1028.  
  1029.     This program is distributed in the hope that it will be useful,
  1030.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  1031.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1032.     GNU General Public License for more details.
  1033.  
  1034.     You should have received a copy of the GNU General Public License
  1035.     along with this program; if not, write to the Free Software
  1036.     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  1037. */
  1038.  
  1039.  
  1040. class avia_google_maps extends WP_Widget {
  1041.  
  1042.     // constructor
  1043.     function avia_google_maps() {
  1044.         $widget_ops = array('classname' => 'avia_google_maps', 'description' => __( 'Add a google map to your blog or site') );
  1045.         $this->WP_Widget('avia_google_maps', THEMENAME.' Google Maps Widget', $widget_ops);
  1046.  
  1047.     }
  1048.  
  1049.     // output the content of the widget
  1050.     function widget($args, $instance) {
  1051.         extract( $args );
  1052.  
  1053.         $title = empty($instance['title']) ? '' : apply_filters('widget_title', esc_attr($instance['title']));
  1054.  
  1055.         print $before_widget;
  1056.         if (!empty($instance['title'])) { print $before_title.$title.$after_title; }
  1057.         print avia_printmap($instance['lat'], $instance['lng'], $instance['zoom'], $instance['type'], $instance['content'], $instance['directionsto']);
  1058.         print $after_widget;
  1059.     }
  1060.  
  1061.     // process widget options to be saved
  1062.     function update($new_instance, $old_instance) {
  1063.         print_r($old_instance);
  1064.         print_r($new_instance);
  1065.         return $new_instance;
  1066.     }
  1067.  
  1068.     // output the options form on admin
  1069.     function form($instance) {
  1070.         global $wpdb;
  1071.         $title = empty($instance['title']) ? '' : esc_attr($instance['title']);
  1072.         $lat = empty($instance['lat']) ? '' : esc_attr($instance['lat']);
  1073.         $lng = empty($instance['lng']) ? '' : esc_attr($instance['lng']);
  1074.         $zoom = empty($instance['zoom']) ? '15' : esc_attr($instance['zoom']);
  1075.         $type = empty($instance['type']) ? 'ROADMAP' : esc_attr($instance['type']);
  1076.         $directionsto = empty($instance['directionsto']) ? '' : esc_attr($instance['directionsto']);
  1077.         $content = empty($instance['content']) ? '' : esc_attr($instance['content']);
  1078.         ?>
  1079.             <p>
  1080.             <label for="<?php print $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
  1081.             <input class="widefat" id="<?php print $this->get_field_id('title'); ?>" name="<?php print $this->get_field_name('title'); ?>" type="text" value="<?php print $title; ?>" />
  1082.             </p>
  1083.             <p>
  1084.             Enter the latitude and longitude of the location. You can <a target='_blank' href='http://itouchmap.com/latlong.html'>fetch them here</a><br/><br/><!-- http://www.getlatlon.com/ -->
  1085.             <label for="<?php print $this->get_field_id('lat'); ?>"><?php _e('Latitude:'); ?></label>
  1086.             <input class="widefat" id="<?php print $this->get_field_id('lat'); ?>" name="<?php print $this->get_field_name('lat'); ?>" type="text" value="<?php print $lat; ?>" />
  1087.             </p>
  1088.             <p>
  1089.             <label for="<?php print $this->get_field_id('lng'); ?>"><?php _e('Longitude:'); ?></label>
  1090.             <input class="widefat" id="<?php print $this->get_field_id('lng'); ?>" name="<?php print $this->get_field_name('lng'); ?>" type="text" value="<?php print $lng; ?>" />
  1091.             </p>
  1092.  
  1093.             <p>
  1094.             <label for="<?php print $this->get_field_id('zoom'); ?>"><?php _e('Zoom Level: <small>(1-19)</small>'); ?></label>
  1095.             <select class="widefat" id="<?php echo $this->get_field_id('zoom'); ?>" name="<?php echo $this->get_field_name('zoom'); ?>">
  1096.                 <?php
  1097.                 $list = "";
  1098.                 $answers = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19);
  1099.                 foreach ($answers as $answer)
  1100.                 {
  1101.                     $selected = "";
  1102.                     if($answer == $zoom) $selected = 'selected="selected"';
  1103.  
  1104.                     $list .= "<option $selected value='$answer'>$answer</option>";
  1105.                 }
  1106.                 $list .= "</select>";
  1107.                 echo $list;
  1108.                 ?>
  1109.  
  1110.  
  1111.             </p>
  1112.  
  1113.             <p>
  1114.             <label for="<?php print $this->get_field_id('type'); ?>"><?php _e('Map Type:'); ?></label>
  1115.  
  1116.             <select class="widefat" id="<?php echo $this->get_field_id('type'); ?>" name="<?php echo $this->get_field_name('type'); ?>">
  1117.                 <?php
  1118.                 $list = "";
  1119.                 $answers = array('ROADMAP', 'SATELLITE', 'HYBRID', 'TERRAIN');
  1120.                 foreach ($answers as $answer)
  1121.                 {
  1122.                     $selected = "";
  1123.                     if($answer == $type) $selected = 'selected="selected"';
  1124.  
  1125.                     $list .= "<option $selected value='$answer'>$answer</option>";
  1126.                 }
  1127.                 $list .= "</select>";
  1128.                 echo $list;
  1129.                 ?>
  1130.  
  1131.             </p>
  1132.             <p>
  1133.             <label for="<?php print $this->get_field_id('directionsto'); ?>"><?php _e('Address for directions:'); ?></label>
  1134.             <input class="widefat" id="<?php print $this->get_field_id('directionsto'); ?>" name="<?php print $this->get_field_name('directionsto'); ?>" type="text" value="<?php print $directionsto; ?>" />
  1135.             </p>
  1136.             <p>
  1137.             <label for="<?php print $this->get_field_id('content'); ?>"><?php _e('Info Bubble Content:'); ?></label>
  1138.             <textarea rows="7" class="widefat" id="<?php print $this->get_field_id('content'); ?>" name="<?php print $this->get_field_name('content'); ?>"><?php print $content; ?></textarea>
  1139.             </p>
  1140.         <?php
  1141.     }
  1142.  
  1143. } // SGMwidget widget
  1144.  
  1145.  
  1146.  
  1147.  
  1148. function avia_printmap($lat, $lng, $zoom, $type, $content, $directionsto) {
  1149.  
  1150.     global $avia_config;
  1151.  
  1152.     $SGMoptions = get_option('SGMoptions'); // get options defined in admin page
  1153.  
  1154.     if (!$lat) {$lat = '0';}
  1155.     if (!$lng) {$lng = '0';}
  1156.     if (!$zoom) {$zoom = $SGMoptions['zoom'];} // 1-19
  1157.     if (!$type) {$type = $SGMoptions['type'];} // ROADMAP, SATELLITE, HYBRID, TERRAIN
  1158.     if (!$content) {$content = $SGMoptions['content'];}
  1159.     $output = "";
  1160.     $unique = uniqid();
  1161.     $content = str_replace('&lt;', '<', $content);
  1162.     $content = str_replace('&gt;', '>', $content);
  1163.     $content = mysql_escape_string($content);
  1164.     $prefix  = isset($_SERVER['HTTPS'] ) ? "https" : "http";
  1165.  
  1166.  
  1167.  
  1168.     $directionsForm = "";
  1169.     if ($directionsto) { $directionsForm = "<form method=\"get\" action=\"$prefix://maps.google.com/maps\"><input type=\"hidden\" name=\"daddr\" value=\"".$directionsto."\" /><input type=\"text\" class=\"text\" name=\"saddr\" /><input type=\"submit\" class=\"submit\" value=\"Directions\" /></form>"; }
  1170.  
  1171.     if(empty($avia_config['g_maps_widget_active']))
  1172.     {
  1173.         $output .= "<script type='text/javascript' src='$prefix://maps.google.com/maps/api/js?sensor=false'></script>";
  1174.         $avia_config['g_maps_widget_active'] = 0;
  1175.     }
  1176.     $avia_config['g_maps_widget_active'] ++;
  1177.     $output .= "<script type='text/javascript'>
  1178.     function makeMap_".$avia_config['g_maps_widget_active']."() {
  1179.        var latlng = new google.maps.LatLng(".$lat.", ".$lng.")
  1180.        var myOptions = {
  1181.           zoom: ".$zoom.",
  1182.           center: latlng,
  1183.           mapTypeControl: true,
  1184.           mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
  1185.           navigationControl: true,
  1186.           navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
  1187.           mapTypeId: google.maps.MapTypeId.".$type."
  1188.        };
  1189.        var map = new google.maps.Map(document.getElementById('avia_google_maps_$unique'), myOptions);
  1190.        var contentString = '&lt;div class=\"infoWindow\"&gt;".$content.$directionsForm."&lt;/div&gt;';
  1191.        var infowindow = new google.maps.InfoWindow({
  1192.           content: contentString
  1193.        });
  1194.        var marker = new google.maps.Marker({
  1195.           position: latlng,
  1196.           map: map,
  1197.           title: ''
  1198.        });
  1199.           google.maps.event.addListener(marker, 'click', function() {
  1200.           infowindow.open(map,marker);
  1201.        });
  1202.     }
  1203.     jQuery(document).ready(function() {
  1204.        makeMap_".$avia_config['g_maps_widget_active']."();
  1205.     });
  1206.     </script>
  1207.        <div id='avia_google_maps_$unique' class='avia_google_maps_container'></div>";
  1208.    
  1209.        return $output;
  1210.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement