PageRenderTime 52ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/mymaxiskirt/framework/php/class-framework-widgets.php

https://bitbucket.org/sanders_nick/my-maxi-skirt
PHP | 1201 lines | 797 code | 299 blank | 105 comment | 116 complexity | e678204db1400db2b6ae8fc89fadff57 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, AGPL-1.0, GPL-3.0, LGPL-2.1
  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. * AVIA TWEETBOX
  14. *
  15. * Widget that creates a list of latest tweets
  16. *
  17. * @package AviaFramework
  18. * @todo replace the widget system with a dynamic one, based on config files for easier widget creation
  19. */
  20. class avia_tweetbox extends WP_Widget {
  21. function avia_tweetbox() {
  22. //Constructor
  23. $widget_ops = array('classname' => 'tweetbox', 'description' => 'A widget to display your latest twitter messages' );
  24. $this->WP_Widget( 'tweetbox', THEMENAME.' Twitter Widget', $widget_ops );
  25. }
  26. function widget($args, $instance) {
  27. // prints the widget
  28. extract($args, EXTR_SKIP);
  29. echo $before_widget;
  30. $title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);
  31. $count = empty($instance['count']) ? '' : $instance['count'];
  32. $username = empty($instance['username']) ? '' : $instance['username'];
  33. $exclude_replies = empty($instance['exclude_replies']) ? '' : $instance['exclude_replies'];
  34. $time = empty($instance['time']) ? 'no' : $instance['time'];
  35. $display_image = empty($instance['display_image']) ? 'no' : $instance['display_image'];
  36. if ( !empty( $title ) ) { echo $before_title . "<a href='http://twitter.com/$username/' title='".strip_tags($title)."'>".$title ."</a>". $after_title; };
  37. $messages = tweetbox_get_tweet($count, $username, $widget_id, $time, $exclude_replies, $display_image);
  38. echo $messages;
  39. echo $after_widget;
  40. }
  41. function update($new_instance, $old_instance) {
  42. //save the widget
  43. $instance = $old_instance;
  44. foreach($new_instance as $key=>$value)
  45. {
  46. $instance[$key] = strip_tags($new_instance[$key]);
  47. }
  48. delete_transient(THEMENAME.'_tweetcache_id_'.$instance['username'].'_'.$this->id_base."-".$this->number);
  49. return $instance;
  50. }
  51. function form($instance) {
  52. //widgetform in backend
  53. $instance = wp_parse_args( (array) $instance, array( 'title' => 'Latest Tweets', 'count' => '3', 'username' => avia_get_option('twitter') ) );
  54. $title = isset($instance['title']) ? strip_tags($instance['title']): "";
  55. $count = isset($instance['count']) ? strip_tags($instance['count']): "";
  56. $username = isset($instance['username']) ? strip_tags($instance['username']): "";
  57. $exclude_replies = isset($instance['exclude_replies']) ? strip_tags($instance['exclude_replies']): "";
  58. $time = isset($instance['time']) ? strip_tags($instance['time']): "";
  59. $display_image = isset($instance['display_image']) ? strip_tags($instance['display_image']): "";
  60. ?>
  61. <p>
  62. <label for="<?php echo $this->get_field_id('title'); ?>">Title:
  63. <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>
  64. <p><label for="<?php echo $this->get_field_id('username'); ?>">Enter your twitter username:
  65. <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>
  66. <p>
  67. <label for="<?php echo $this->get_field_id('count'); ?>">How many entries do you want to display: </label>
  68. <select class="widefat" id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>">
  69. <?php
  70. $list = "";
  71. for ($i = 1; $i <= 20; $i++ )
  72. {
  73. $selected = "";
  74. if($count == $i) $selected = 'selected="selected"';
  75. $list .= "<option $selected value='$i'>$i</option>";
  76. }
  77. $list .= "</select>";
  78. echo $list;
  79. ?>
  80. </p>
  81. <p>
  82. <label for="<?php echo $this->get_field_id('exclude_replies'); ?>">Exclude @replies: </label>
  83. <select class="widefat" id="<?php echo $this->get_field_id('exclude_replies'); ?>" name="<?php echo $this->get_field_name('exclude_replies'); ?>">
  84. <?php
  85. $list = "";
  86. $answers = array('yes','no');
  87. foreach ($answers as $answer)
  88. {
  89. $selected = "";
  90. if($answer == $exclude_replies) $selected = 'selected="selected"';
  91. $list .= "<option $selected value='$answer'>$answer</option>";
  92. }
  93. $list .= "</select>";
  94. echo $list;
  95. ?>
  96. </p>
  97. <p>
  98. <label for="<?php echo $this->get_field_id('time'); ?>">Display time of tweet</label>
  99. <select class="widefat" id="<?php echo $this->get_field_id('time'); ?>" name="<?php echo $this->get_field_name('time'); ?>">
  100. <?php
  101. $list = "";
  102. $answers = array('yes','no');
  103. foreach ($answers as $answer)
  104. {
  105. $selected = "";
  106. if($answer == $time) $selected = 'selected="selected"';
  107. $list .= "<option $selected value='$answer'>$answer</option>";
  108. }
  109. $list .= "</select>";
  110. echo $list;
  111. ?>
  112. </p>
  113. <p>
  114. <label for="<?php echo $this->get_field_id('display_image'); ?>">Display Twitter User Avatar</label>
  115. <select class="widefat" id="<?php echo $this->get_field_id('display_image'); ?>" name="<?php echo $this->get_field_name('display_image'); ?>">
  116. <?php
  117. $list = "";
  118. $answers = array('yes','no');
  119. foreach ($answers as $answer)
  120. {
  121. $selected = "";
  122. if($answer == $display_image) $selected = 'selected="selected"';
  123. $list .= "<option $selected value='$answer'>$answer</option>";
  124. }
  125. $list .= "</select>";
  126. echo $list;
  127. ?>
  128. </p>
  129. <?php
  130. }
  131. }
  132. function tweetbox_get_tweet($count, $username, $widget_id, $time='yes', $exclude_replies='yes', $avatar = 'yes')
  133. {
  134. $filtered_message = "";
  135. $output = "";
  136. $iterations = 0;
  137. $cache = get_transient(THEMENAME.'_tweetcache_id_'.$username.'_'.$widget_id);
  138. if($cache)
  139. {
  140. $tweets = get_option(THEMENAME.'_tweetcache_'.$username.'_'.$widget_id);
  141. }
  142. else
  143. {
  144. //$response = wp_remote_get( 'http://api.twitter.com/1/statuses/user_timeline.xml?screen_name='.$username );
  145. $response = wp_remote_get( 'http://api.twitter.com/1/statuses/user_timeline.xml?include_rts=true&screen_name='.$username );
  146. if (!is_wp_error($response))
  147. {
  148. $xml = simplexml_load_string($response['body']);
  149. //follower: (int) $xml->status->user->followers_count
  150. if( empty( $xml->error ) )
  151. {
  152. if ( isset($xml->status[0]))
  153. {
  154. $tweets = array();
  155. foreach ($xml->status as $tweet)
  156. {
  157. if($iterations == $count) break;
  158. $text = (string) $tweet->text;
  159. if($exclude_replies == 'no' || ($exclude_replies == 'yes' && $text[0] != "@"))
  160. {
  161. $iterations++;
  162. $tweets[] = array(
  163. 'text' => tweetbox_filter( $text ),
  164. 'created' => strtotime( $tweet->created_at ),
  165. 'user' => array(
  166. 'name' => (string)$tweet->user->name,
  167. 'screen_name' => (string)$tweet->user->screen_name,
  168. 'image' => (string)$tweet->user->profile_image_url,
  169. 'utc_offset' => (int) $tweet->user->utc_offset[0],
  170. 'follower' => (int) $tweet->user->followers_count
  171. ));
  172. }
  173. }
  174. set_transient(THEMENAME.'_tweetcache_id_'.$username.'_'.$widget_id, 'true', 60*30);
  175. update_option(THEMENAME.'_tweetcache_'.$username.'_'.$widget_id, $tweets);
  176. }
  177. }
  178. }
  179. }
  180. if(!isset($tweets[0]))
  181. {
  182. $tweets = get_option(THEMENAME.'_tweetcache_'.$username.'_'.$widget_id);
  183. }
  184. if(isset($tweets[0]))
  185. {
  186. $time_format = apply_filters( 'avia_widget_time' , get_option('date_format')." - ".get_option('time_format') );
  187. foreach ($tweets as $message)
  188. {
  189. $output .= '<li class="tweet">';
  190. if($avatar == "yes") $output .= '<div class="tweet-thumb"><a href="http://twitter.com/'.$username.'" title=""><img src="'.$message['user']['image'].'" alt="" /></a></div>';
  191. $output .= '<div class="tweet-text avatar_'.$avatar.'">'.$message['text'];
  192. if($time == "yes") $output .= '<div class="tweet-time">'.date_i18n( $time_format, $message['created'] + $message['user']['utc_offset']).'</div>';
  193. $output .= '</div></li>';
  194. }
  195. }
  196. if($output != "")
  197. {
  198. $filtered_message = "<ul class='tweets'>$output</ul>";
  199. }
  200. else
  201. {
  202. $filtered_message = "<ul class='tweets'><li>No public Tweets found</li></ul>";
  203. }
  204. return $filtered_message;
  205. }
  206. function tweetbox_filter($text) {
  207. // Props to Allen Shaw & webmancers.com & Michael Voigt
  208. $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);
  209. $text = preg_replace('/\b(?<!:\/\/)(www\.[\w_.\-]+\.[a-zA-Z]{2,6}[\/\w\-~.?=&%#+$*!]*)\b/i',"<a href=\"http://$1\" class=\"twitter-link\">$1</a>", $text);
  210. $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);
  211. $text = preg_replace("/#(\w+)/", "<a class=\"twitter-link\" href=\"http://search.twitter.com/search?q=\\1\">#\\1</a>", $text);
  212. $text = preg_replace("/@(\w+)/", "<a class=\"twitter-link\" href=\"http://twitter.com/\\1\">@\\1</a>", $text);
  213. return $text;
  214. }
  215. /**
  216. * AVIA NEWSBOX
  217. *
  218. * Widget that creates a list of latest news entries
  219. *
  220. * @package AviaFramework
  221. * @todo replace the widget system with a dynamic one, based on config files for easier widget creation
  222. */
  223. class avia_newsbox extends WP_Widget {
  224. var $avia_term = '';
  225. var $avia_post_type = '';
  226. var $avia_new_query = '';
  227. function avia_newsbox()
  228. {
  229. $widget_ops = array('classname' => 'newsbox', 'description' => 'A Sidebar widget to display latest post entries in your sidebar' );
  230. $this->WP_Widget( 'newsbox', THEMENAME.' Latest News', $widget_ops );
  231. }
  232. function widget($args, $instance)
  233. {
  234. global $avia_config;
  235. extract($args, EXTR_SKIP);
  236. echo $before_widget;
  237. $title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);
  238. $count = empty($instance['count']) ? '' : $instance['count'];
  239. $cat = empty($instance['cat']) ? '' : $instance['cat'];
  240. $excerpt = empty($instance['excerpt']) ? '' : $instance['excerpt'];
  241. $image_size = isset($avia_config['widget_image_size']) ? $avia_config['widget_image_size'] : 'widget';
  242. if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
  243. if(empty($this->avia_term))
  244. {
  245. $additional_loop = new WP_Query("cat=".$cat."&posts_per_page=".$count);
  246. }
  247. else
  248. {
  249. $catarray = explode(',', $cat);
  250. if(empty($catarray[0]))
  251. {
  252. $new_query = array("posts_per_page"=>$count,"post_type"=>$this->avia_post_type);
  253. }
  254. else
  255. {
  256. if($this->avia_new_query)
  257. {
  258. $new_query = $this->avia_new_query;
  259. }
  260. else
  261. {
  262. $new_query = array( "posts_per_page"=>$count, 'tax_query' => array(
  263. array( 'taxonomy' => $this->avia_term,
  264. 'field' => 'id',
  265. 'terms' => explode(',', $cat),
  266. 'operator' => 'IN')
  267. )
  268. );
  269. }
  270. }
  271. $additional_loop = new WP_Query($new_query);
  272. }
  273. if($additional_loop->have_posts()) :
  274. echo '<ul class="news-wrap image_size_'.$image_size.'">';
  275. while ($additional_loop->have_posts()) : $additional_loop->the_post();
  276. $format = "";
  277. if(empty($this->avia_post_type)) $format = $this->avia_post_type;
  278. if(empty($format)) $format = get_post_format();
  279. if(empty($format)) $format = 'standard';
  280. echo '<li class="news-content post-format-'.$format.'">';
  281. //check for preview images:
  282. $image = "";
  283. $slides = avia_post_meta(get_the_ID(), 'slideshow', true);
  284. if( $slides != "" && !empty( $slides[0]['slideshow_image'] ) )
  285. {
  286. $image = avia_image_by_id($slides[0]['slideshow_image'], $image_size, 'image');
  287. }
  288. if(!$image && current_theme_supports( 'post-thumbnails' ))
  289. {
  290. $image = get_the_post_thumbnail( get_the_ID(), $image_size );
  291. }
  292. $time_format = apply_filters( 'avia_widget_time' , get_option('date_format')." - ".get_option('time_format') );
  293. echo "<a class='news-link' title='".get_the_title()."' href='".get_permalink()."'>";
  294. echo "<span class='news-thumb'>";
  295. echo $image;
  296. echo "</span>";
  297. 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>"; }
  298. echo "</a>";
  299. if('display title and excerpt' == $excerpt)
  300. {
  301. echo "<div class='news-excerpt'>";
  302. if(!empty($avia_config['widget_image_size']))
  303. {
  304. echo "<a class='news-link-inner' title='".get_the_title()."' href='".get_permalink()."'>";
  305. echo "<strong class='news-headline'>".get_the_title()."</strong>";
  306. echo "</a>";
  307. echo "<span class='news-time'>".get_the_time($time_format)."</span>";
  308. }
  309. the_excerpt();
  310. echo "</div>";
  311. }
  312. echo '</li>';
  313. endwhile;
  314. echo "</ul>";
  315. wp_reset_postdata();
  316. endif;
  317. echo $after_widget;
  318. }
  319. function update($new_instance, $old_instance)
  320. {
  321. $instance = $old_instance;
  322. $instance['title'] = strip_tags($new_instance['title']);
  323. $instance['count'] = strip_tags($new_instance['count']);
  324. $instance['excerpt'] = strip_tags($new_instance['excerpt']);
  325. $instance['cat'] = implode(',',$new_instance['cat']);
  326. return $instance;
  327. }
  328. function form($instance)
  329. {
  330. $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'count' => '', 'cat' => '', 'excerpt'=>'' ) );
  331. $title = strip_tags($instance['title']);
  332. $count = strip_tags($instance['count']);
  333. $excerpt = strip_tags($instance['excerpt']);
  334. $elementCat = array("name" => "Which categories should be used for the portfolio?",
  335. "desc" => "You can select multiple categories here",
  336. "id" => $this->get_field_name('cat')."[]",
  337. "type" => "select",
  338. "std" => strip_tags($instance['cat']),
  339. "class" => "",
  340. "multiple"=>6,
  341. "subtype" => "cat");
  342. //check if a different taxonomy than the default is set
  343. if(!empty($this->avia_term))
  344. {
  345. $elementCat['taxonomy'] = $this->avia_term;
  346. }
  347. $html = new avia_htmlhelper();
  348. ?>
  349. <p><label for="<?php echo $this->get_field_id('title'); ?>">Title:
  350. <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>
  351. <p>
  352. <label for="<?php echo $this->get_field_id('count'); ?>">How many entries do you want to display: </label>
  353. <select class="widefat" id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>">
  354. <?php
  355. $list = "";
  356. for ($i = 1; $i <= 20; $i++ )
  357. {
  358. $selected = "";
  359. if($count == $i) $selected = 'selected="selected"';
  360. $list .= "<option $selected value='$i'>$i</option>";
  361. }
  362. $list .= "</select>";
  363. echo $list;
  364. ?>
  365. </p>
  366. <p><label for="<?php echo $this->get_field_id('cat'); ?>">Choose the categories you want to display (multiple selection possible):
  367. <?php echo $html->select($elementCat); ?>
  368. </label></p>
  369. <p>
  370. <label for="<?php echo $this->get_field_id('excerpt'); ?>">Display title only or title &amp; excerpt</label>
  371. <select class="widefat" id="<?php echo $this->get_field_id('excerpt'); ?>" name="<?php echo $this->get_field_name('excerpt'); ?>">
  372. <?php
  373. $list = "";
  374. $answers = array('show title only','display title and excerpt');
  375. foreach ($answers as $answer)
  376. {
  377. $selected = "";
  378. if($answer == $excerpt) $selected = 'selected="selected"';
  379. $list .= "<option $selected value='$answer'>$answer</option>";
  380. }
  381. $list .= "</select>";
  382. echo $list;
  383. ?>
  384. </p>
  385. <?php
  386. }
  387. }
  388. /**
  389. * AVIA PORTFOLIOBOX
  390. *
  391. * 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
  392. *
  393. * @package AviaFramework
  394. * @todo replace the widget system with a dynamic one, based on config files for easier widget creation
  395. */
  396. class avia_portfoliobox extends avia_newsbox
  397. {
  398. function avia_portfoliobox()
  399. {
  400. $this->avia_term = 'portfolio_entries';
  401. $this->avia_post_type = 'portfolio';
  402. $this->avia_new_query = ''; //set a custom query here
  403. $widget_ops = array('classname' => 'newsbox', 'description' => 'A Sidebar widget to display latest portfolio entries in your sidebar' );
  404. $this->WP_Widget( 'portfoliobox', THEMENAME.' Latest Portfolio', $widget_ops );
  405. }
  406. }
  407. /**
  408. * AVIA SOCIALCOUNT
  409. *
  410. * Widget that retrieves, stores and displays the number of twitter and rss followers
  411. *
  412. * @package AviaFramework
  413. * @todo replace the widget system with a dynamic one, based on config files for easier widget creation
  414. */
  415. class avia_socialcount extends WP_Widget {
  416. function avia_socialcount() {
  417. //Constructor
  418. $widget_ops = array('classname' => 'avia_socialcount', 'description' => 'A widget to display your twitter and rss followers' );
  419. $this->WP_Widget( 'avia_socialcount', THEMENAME.' Twitter and RSS count', $widget_ops );
  420. }
  421. function widget($args, $instance) {
  422. // prints the widget
  423. extract($args, EXTR_SKIP);
  424. $twitter = empty($instance['twitter']) ? '' : $instance['twitter'];
  425. $rss = empty($instance['rss']) ? '' : $instance['rss'];
  426. $rss = preg_replace('!https?:\/\/feeds.feedburner.com\/!','',$rss);
  427. $follower = $this->count_followers($twitter, $rss, $widget_id);
  428. if(!empty($follower) && is_array($follower))
  429. {
  430. $addClass = "asc_multi_count";
  431. if(!isset($follower['twitter']) || !isset($follower['rss'])) $addClass = 'asc_single_count';
  432. echo $before_widget;
  433. if(isset($follower['twitter']))
  434. {
  435. $link = 'http://twitter.com/'.$twitter.'/';
  436. echo "<a href='$link' class='asc_twitter $addClass'><strong class='asc_count'>".$follower['twitter']."</strong><span>".__('Follower','avia_framework')."</span></a>";
  437. }
  438. if(isset($follower['rss']) && $rss)
  439. {
  440. $link = 'http://feeds.feedburner.com/'.$rss;
  441. if(is_numeric($follower['rss']))
  442. {
  443. $feed_text = __('Subscribers','avia_framework');
  444. }
  445. else
  446. {
  447. $follower['rss'] = __('Subscribe','avia_framework');
  448. $feed_text = __('to RSS Feed','avia_framework');
  449. }
  450. echo "<a href='$link' class='asc_rss $addClass'><strong class='asc_count'>".$follower['rss']."</strong><span>".$feed_text."</span></a>";
  451. }
  452. echo $after_widget;
  453. }
  454. }
  455. function count_followers($twitter, $rss, $widget_id)
  456. {
  457. $follower = array();
  458. $optionkey = strtolower(THEMENAME.'fc_id'.$widget_id);
  459. $cache = get_transient($optionkey);
  460. if($cache)
  461. {
  462. $follower = get_option($optionkey);
  463. }
  464. else
  465. {
  466. if($twitter != "")
  467. {
  468. $twittercount = wp_remote_get( 'http://api.twitter.com/1/statuses/user_timeline.xml?screen_name='.$twitter );
  469. if (!is_wp_error($twittercount))
  470. {
  471. $xml = simplexml_load_string($twittercount['body']);
  472. if( empty( $xml->error ) && isset($xml->status->user->followers_count))
  473. {
  474. $follower['twitter'] = (int) $xml->status->user->followers_count;
  475. }
  476. }
  477. }
  478. if($rss != "")
  479. {
  480. $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()));
  481. $feedcount = wp_remote_get($requesturl);
  482. if (!is_wp_error($feedcount))
  483. {
  484. $xml = @simplexml_load_string($feedcount['body']);
  485. if(is_object($xml->feed->entry))
  486. {
  487. $follower['rss'] = (int) $xml->feed->entry->attributes()->circulation;
  488. }
  489. else
  490. {
  491. $follower['rss'] = true;
  492. }
  493. }
  494. }
  495. $fallback = get_option($optionkey);
  496. if(!isset($follower['rss']) && isset($fallback['rss'])) $follower['rss'] = $fallback['rss'];
  497. if(!isset($follower['twitter']) && isset($fallback['twitter'])) $follower['twitter'] = $fallback['twitter'];
  498. set_transient($optionkey, 1, 60*60*12);
  499. update_option($optionkey, $follower);
  500. }
  501. return $follower;
  502. }
  503. function update($new_instance, $old_instance) {
  504. //save the widget
  505. $instance = $old_instance;
  506. foreach($new_instance as $key=>$value)
  507. {
  508. $instance[$key] = strip_tags($new_instance[$key]);
  509. }
  510. delete_transient(strtolower(THEMENAME.'fc_id'.$this->id_base."-".$this->number));
  511. return $instance;
  512. }
  513. function form($instance) {
  514. //widgetform in backend
  515. $instance = wp_parse_args( (array) $instance, array('rss' => avia_get_option('feedburner'), 'twitter' => avia_get_option('twitter') ) );
  516. $twitter = empty($instance['twitter']) ? '' : strip_tags($instance['twitter']);
  517. $rss = empty($instance['rss']) ? '' : strip_tags($instance['rss']);
  518. ?>
  519. <p>
  520. <label for="<?php echo $this->get_field_id('twitter'); ?>">Twitter Username:
  521. <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>
  522. <p><label for="<?php echo $this->get_field_id('rss'); ?>">Enter your feedburner url:
  523. <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>
  524. <?php
  525. }
  526. }
  527. /**
  528. * AVIA ADVERTISING WIDGET
  529. *
  530. * Widget that retrieves, stores and displays the number of twitter and rss followers
  531. *
  532. * @package AviaFramework
  533. * @todo replace the widget system with a dynamic one, based on config files for easier widget creation
  534. */
  535. //multiple images
  536. class avia_partner_widget extends WP_Widget {
  537. function avia_partner_widget() {
  538. $this->add_cont = 2;
  539. //Constructor
  540. $widget_ops = array('classname' => 'avia_partner_widget', 'description' => 'An advertising widget that displays 2 images with 125 x 125 px in size' );
  541. $this->WP_Widget( 'avia_partner_widget', THEMENAME.' Advertising Area', $widget_ops );
  542. }
  543. function widget($args, $instance)
  544. {
  545. extract($args, EXTR_SKIP);
  546. echo $before_widget;
  547. global $kriesiaddwidget, $firsttitle;
  548. $kriesiaddwidget ++;
  549. $title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);
  550. $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=""/>';
  551. $ref_url = empty($instance['ref_url']) ? '#' : apply_filters('widget_comments_title', $instance['ref_url']);
  552. $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=""/>';
  553. $ref_url2 = empty($instance['ref_url2']) ? '#' : apply_filters('widget_comments_title', $instance['ref_url2']);
  554. if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
  555. echo '<a href="'.$ref_url.'" class="preloading_background avia_partner1 link_list_item'.$kriesiaddwidget.' '.$firsttitle.'" >'.$image_url.'</a>';
  556. if($this->add_cont == 2) echo '<a href="'.$ref_url2.'" class="preloading_background avia_partner2 link_list_item'.$kriesiaddwidget.' '.$firsttitle.'" >'.$image_url2.'</a>';
  557. echo $after_widget;
  558. if($title == '')
  559. {
  560. $firsttitle = 'no_top_margin';
  561. }
  562. }
  563. function update($new_instance, $old_instance) {
  564. //save the widget
  565. $instance = $old_instance;
  566. foreach($new_instance as $key=>$value)
  567. {
  568. $instance[$key] = strip_tags($new_instance[$key]);
  569. }
  570. return $instance;
  571. }
  572. function form($instance)
  573. {
  574. $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'image_url' => '', 'ref_url' => '', 'image_url2' => '', 'ref_url2' => '' ) );
  575. $title = strip_tags($instance['title']);
  576. $image_url = strip_tags($instance['image_url']);
  577. $ref_url = strip_tags($instance['ref_url']);
  578. $image_url2 = strip_tags($instance['image_url2']);
  579. $ref_url2 = strip_tags($instance['ref_url2']);
  580. ?>
  581. <p><label for="<?php echo $this->get_field_id('title'); ?>">Title:
  582. <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>
  583. <p><label for="<?php echo $this->get_field_id('image_url'); ?>">Image URL: <?php if($this->add_cont == 2) echo "(125px * 125px):"; ?>
  584. <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>
  585. <p><label for="<?php echo $this->get_field_id('ref_url'); ?>">Referal URL:
  586. <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>
  587. <?php if($this->add_cont == 2)
  588. { ?>
  589. <p><label for="<?php echo $this->get_field_id('image_url2'); ?>">Image URL 2: (125px * 125px):
  590. <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>
  591. <p><label for="<?php echo $this->get_field_id('ref_url2'); ?>">Referal URL 2:
  592. <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>
  593. <?php }?>
  594. <?php
  595. }
  596. }
  597. //one image
  598. class avia_one_partner_widget extends avia_partner_widget
  599. {
  600. function avia_one_partner_widget()
  601. {
  602. $this->add_cont = 1;
  603. $widget_ops = array('classname' => 'avia_one_partner_widget', 'description' => 'An advertising widget that displays 1 big image' );
  604. $this->WP_Widget( 'avia_one_partner_widget', THEMENAME.' Big Advertising Area', $widget_ops );
  605. }
  606. }
  607. /**
  608. * AVIA COMBO WIDGET
  609. *
  610. * Widget that retrieves, stores and displays the number of twitter and rss followers
  611. *
  612. * @package AviaFramework
  613. * @todo replace the widget system with a dynamic one, based on config files for easier widget creation
  614. */
  615. class avia_combo_widget extends WP_Widget {
  616. function avia_combo_widget() {
  617. //Constructor
  618. $widget_ops = array('classname' => 'avia_combo_widget', 'description' => 'A widget that displays your popular posts, recent posts, recent comments and a tagcloud' );
  619. $this->WP_Widget( 'avia_combo_widget', THEMENAME.' Combo Widget', $widget_ops );
  620. }
  621. function widget($args, $instance)
  622. {
  623. // prints the widget
  624. extract($args, EXTR_SKIP);
  625. $posts = empty($instance['count']) ? 4 : $instance['count'];
  626. echo $before_widget;
  627. echo "<div class='tabcontainer tab_initial_open tab_initial_open__1'>";
  628. echo '<div class="tab first_tab widget_tab_popular"><span>'.__('Popular', 'avia_framework').'</span></div>';
  629. echo "<div class='tab_content'>";
  630. avia_get_post_list('cat=&orderby=comment_count&posts_per_page='.$posts);
  631. echo "</div>";
  632. echo '<div class="tab widget_tab_recent"><span>'.__('Recent', 'avia_framework').'</span></div>';
  633. echo "<div class='tab_content'>";
  634. avia_get_post_list('showposts='. $posts .'&orderby=post_date&order=desc');
  635. echo "</div>";
  636. echo '<div class="tab widget_tab_comments"><span>'.__('Comments', 'avia_framework').'</span></div>';
  637. echo "<div class='tab_content'>";
  638. avia_get_comment_list( array('number' => $posts, 'status' => 'approve', 'order' => 'DESC') );
  639. echo "</div>";
  640. echo '<div class="tab last_tab widget_tab_tags"><span>'.__('Tags', 'avia_framework').'</span></div>';
  641. echo "<div class='tab_content tagcloud'>";
  642. wp_tag_cloud('smallest=12&largest=12&unit=px');
  643. echo "</div>";
  644. echo "</div>";
  645. echo $after_widget;
  646. }
  647. function update($new_instance, $old_instance)
  648. {
  649. $instance = $old_instance;
  650. foreach($new_instance as $key=>$value)
  651. {
  652. $instance[$key] = strip_tags($new_instance[$key]);
  653. }
  654. return $instance;
  655. }
  656. function form($instance) {
  657. //widgetform in backend
  658. $instance = wp_parse_args( (array) $instance, array('count' => 4) );
  659. if(!is_numeric($instance['count'])) $instance['count'] = 4;
  660. ?>
  661. <p>
  662. <label for="<?php echo $this->get_field_id('count'); ?>">Number of posts you want to display:
  663. <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>
  664. <?php
  665. }
  666. }
  667. /*-----------------------------------------------------------------------------------
  668. get posts posts
  669. -----------------------------------------------------------------------------------*/
  670. if (!function_exists('avia_get_post_list'))
  671. {
  672. function avia_get_post_list( $avia_new_query , $excerpt = false)
  673. {
  674. global $avia_config;
  675. $additional_loop = new WP_Query($avia_new_query);
  676. if($additional_loop->have_posts()) :
  677. echo '<ul class="news-wrap">';
  678. while ($additional_loop->have_posts()) : $additional_loop->the_post();
  679. $format = "";
  680. if(get_post_type() != 'post') $format = get_post_type();
  681. if(empty($format)) $format = get_post_format();
  682. if(empty($format)) $format = 'standard';
  683. echo '<li class="news-content post-format-'.$format.'">';
  684. //check for preview images:
  685. $image = "";
  686. $slides = avia_post_meta(get_the_ID(), 'slideshow');
  687. if( $slides != "" && !empty( $slides[0]['slideshow_image'] ) )
  688. {
  689. $image = avia_image_by_id($slides[0]['slideshow_image'], 'widget', 'image');
  690. }
  691. $time_format = apply_filters( 'avia_widget_time' , get_option('date_format')." - ".get_option('time_format') );
  692. echo "<a class='news-link' title='".get_the_title()."' href='".get_permalink()."'>";
  693. echo "<span class='news-thumb'>";
  694. echo $image;
  695. echo "</span>";
  696. echo "<strong class='news-headline'>".avia_backend_truncate(get_the_title(), 55," ");
  697. echo "<span class='news-time'>".get_the_time($time_format)."</span>";
  698. echo "</strong>";
  699. echo "</a>";
  700. if('display title and excerpt' == $excerpt)
  701. {
  702. echo "<div class='news-excerpt'>";
  703. the_excerpt();
  704. echo "</div>";
  705. }
  706. echo '</li>';
  707. endwhile;
  708. echo "</ul>";
  709. wp_reset_postdata();
  710. endif;
  711. }
  712. }
  713. if (!function_exists('avia_get_comment_list'))
  714. {
  715. $time_format = apply_filters( 'avia_widget_time' , get_option('date_format')." - ".get_option('time_format') );
  716. function avia_get_comment_list($avia_new_query)
  717. {
  718. global $avia_config;
  719. $comments = get_comments($avia_new_query);
  720. if(!empty($comments)) :
  721. echo '<ul class="news-wrap">';
  722. foreach($comments as $comment)
  723. {
  724. echo '<li class="news-content">';
  725. echo "<a class='news-link' title='".get_the_title($comment->comment_post_ID)."' href='".get_comment_link($comment)."'>";
  726. echo "<span class='news-thumb'>";
  727. echo get_avatar($comment,'48');
  728. echo "</span>";
  729. echo "<strong class='news-headline'>".avia_backend_truncate($comment->comment_content, 55," ");
  730. echo "<span class='news-time'>".get_the_time($time_format, $comment->comment_post_ID)." by ".$comment->comment_author."</span>";
  731. echo "</strong>";
  732. echo "</a>";
  733. echo '</li>';
  734. }
  735. echo "</ul>";
  736. wp_reset_postdata();
  737. endif;
  738. }
  739. }
  740. /*
  741. Google Maps Widget
  742. Copyright 2009 Clark Nikdel Powell (email : taylor@cnpstudio.com)
  743. This program is free software; you can redistribute it and/or modify
  744. it under the terms of the GNU General Public License as published by
  745. the Free Software Foundation; either version 2 of the License, or
  746. (at your option) any later version.
  747. This program is distributed in the hope that it will be useful,
  748. but WITHOUT ANY WARRANTY; without even the implied warranty of
  749. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  750. GNU General Public License for more details.
  751. You should have received a copy of the GNU General Public License
  752. along with this program; if not, write to the Free Software
  753. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  754. */
  755. class avia_google_maps extends WP_Widget {
  756. // constructor
  757. function avia_google_maps() {
  758. $widget_ops = array('classname' => 'avia_google_maps', 'description' => __( 'Add a google map to your blog or site') );
  759. $this->WP_Widget('avia_google_maps', THEMENAME.' Google Maps Widget', $widget_ops);
  760. }
  761. // output the content of the widget
  762. function widget($args, $instance) {
  763. extract( $args );
  764. $title = empty($instance['title']) ? '' : apply_filters('widget_title', esc_attr($instance['title']));
  765. print $before_widget;
  766. if (!empty($instance['title'])) { print $before_title.$title.$after_title; }
  767. print avia_printmap($instance['lat'], $instance['lng'], $instance['zoom'], $instance['type'], $instance['content'], $instance['directionsto']);
  768. print $after_widget;
  769. }
  770. // process widget options to be saved
  771. function update($new_instance, $old_instance) {
  772. print_r($old_instance);
  773. print_r($new_instance);
  774. return $new_instance;
  775. }
  776. // output the options form on admin
  777. function form($instance) {
  778. global $wpdb;
  779. $title = empty($instance['title']) ? '' : esc_attr($instance['title']);
  780. $lat = empty($instance['lat']) ? '' : esc_attr($instance['lat']);
  781. $lng = empty($instance['lng']) ? '' : esc_attr($instance['lng']);
  782. $zoom = empty($instance['zoom']) ? '15' : esc_attr($instance['zoom']);
  783. $type = empty($instance['type']) ? 'ROADMAP' : esc_attr($instance['type']);
  784. $directionsto = empty($instance['directionsto']) ? '' : esc_attr($instance['directionsto']);
  785. $content = empty($instance['content']) ? '' : esc_attr($instance['content']);
  786. ?>
  787. <p>
  788. <label for="<?php print $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
  789. <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; ?>" />
  790. </p>
  791. <p>
  792. Enter the latitude and longitude of the location. You can <a target='_blank' href='http://www.getlatlon.com/'>fetch them here</a><br/><br/>
  793. <label for="<?php print $this->get_field_id('lat'); ?>"><?php _e('Latitude:'); ?></label>
  794. <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; ?>" />
  795. </p>
  796. <p>
  797. <label for="<?php print $this->get_field_id('lng'); ?>"><?php _e('Longitude:'); ?></label>
  798. <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; ?>" />
  799. </p>
  800. <p>
  801. <label for="<?php print $this->get_field_id('zoom'); ?>"><?php _e('Zoom Level: <small>(1-19)</small>'); ?></label>
  802. <select class="widefat" id="<?php echo $this->get_field_id('zoom'); ?>" name="<?php echo $this->get_field_name('zoom'); ?>">
  803. <?php
  804. $list = "";
  805. $answers = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19);
  806. foreach ($answers as $answer)
  807. {
  808. $selected = "";
  809. if($answer == $zoom) $selected = 'selected="selected"';
  810. $list .= "<option $selected value='$answer'>$answer</option>";
  811. }
  812. $list .= "</select>";
  813. echo $list;
  814. ?>
  815. </p>
  816. <p>
  817. <label for="<?php print $this->get_field_id('type'); ?>"><?php _e('Map Type:'); ?></label>
  818. <select class="widefat" id="<?php echo $this->get_field_id('type'); ?>" name="<?php echo $this->get_field_name('type'); ?>">
  819. <?php
  820. $list = "";
  821. $answers = array('ROADMAP', 'SATELLITE', 'HYBRID', 'TERRAIN');
  822. foreach ($answers as $answer)
  823. {
  824. $selected = "";
  825. if($answer == $type) $selected = 'selected="selected"';
  826. $list .= "<option $selected value='$answer'>$answer</option>";
  827. }
  828. $list .= "</select>";
  829. echo $list;
  830. ?>
  831. </p>
  832. <p>
  833. <label for="<?php print $this->get_field_id('directionsto'); ?>"><?php _e('Address for directions:'); ?></label>
  834. <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; ?>" />
  835. </p>
  836. <p>
  837. <label for="<?php print $this->get_field_id('content'); ?>"><?php _e('Info Bubble Content:'); ?></label>
  838. <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>
  839. </p>
  840. <?php
  841. }
  842. } // SGMwidget widget
  843. function avia_printmap($lat, $lng, $zoom, $type, $content, $directionsto) {
  844. global $avia_config;
  845. $SGMoptions = get_option('SGMoptions'); // get options defined in admin page
  846. if (!$lat) {$lat = '0';}
  847. if (!$lng) {$lng = '0';}
  848. if (!$zoom) {$zoom = $SGMoptions['zoom'];} // 1-19
  849. if (!$type) {$type = $SGMoptions['type'];} // ROADMAP, SATELLITE, HYBRID, TERRAIN
  850. if (!$content) {$content = $SGMoptions['content'];}
  851. $output = "";
  852. $unique = uniqid();
  853. $content = str_replace('&lt;', '<', $content);
  854. $content = str_replace('&gt;', '>', $content);
  855. $content = mysql_escape_string($content);
  856. $directionsForm = "";
  857. if ($directionsto) { $directionsForm = "<form method=\"get\" action=\"http://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>"; }
  858. if(empty($avia_config['g_maps_widget_active']))
  859. {
  860. $output .= "<script type='text/javascript' src='http://maps.google.com/maps/api/js?sensor=false'></script>";
  861. $avia_config['g_maps_widget_active'] = 0;
  862. }
  863. $avia_config['g_maps_widget_active'] ++;
  864. $output .= "
  865. <script type='text/javascript'>
  866. function makeMap_".$avia_config['g_maps_widget_active']."() {
  867. var latlng = new google.maps.LatLng(".$lat.", ".$lng.")
  868. var myOptions = {
  869. zoom: ".$zoom.",
  870. center: latlng,
  871. mapTypeControl: true,
  872. mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
  873. navigationControl: true,
  874. navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
  875. mapTypeId: google.maps.MapTypeId.".$type."
  876. };
  877. var map = new google.maps.Map(document.getElementById('avia_google_maps_$unique'), myOptions);
  878. var contentString = '<div class=\"infoWindow\">".$content.$directionsForm."</div>';
  879. var infowindow = new google.maps.InfoWindow({
  880. content: contentString
  881. });
  882. var marker = new google.maps.Marker({
  883. position: latlng,
  884. map: map,
  885. title: ''
  886. });
  887. google.maps.event.addListener(marker, 'click', function() {
  888. infowindow.open(map,marker);
  889. });
  890. }
  891. jQuery(document).ready(function() {
  892. makeMap_".$avia_config['g_maps_widget_active']."();
  893. });
  894. </script>
  895. <div id='avia_google_maps_$unique' class='avia_google_maps_container'></div>
  896. ";
  897. return $output;
  898. }