Changeset 968923
- Timestamp:
- 08/20/2014 11:46:53 AM (12 years ago)
- Location:
- hitboxtv-widget
- Files:
-
- 14 added
- 1 deleted
- 5 edited
-
assets/Thumbs.db (modified) (previous)
-
assets/screenshot-3.jpg (added)
-
tags/1.5.0 (added)
-
tags/1.5.0/assets (added)
-
tags/1.5.0/assets/images (added)
-
tags/1.5.0/assets/images/Thumbs.db (added)
-
tags/1.5.0/hitboxtv-widget.php (added)
-
tags/1.5.0/includes (added)
-
tags/1.5.0/includes/functions.php (added)
-
tags/1.5.0/includes/options.php (added)
-
tags/1.5.0/readme.txt (added)
-
tags/1.5.0/style.css (added)
-
tags/1.5.0/uninstall.php (added)
-
trunk/assets/images/Thumbs.db (modified) (previous)
-
trunk/assets/images/offline.jpg (deleted)
-
trunk/hitboxtv-widget.php (modified) (10 diffs)
-
trunk/includes/functions.php (modified) (3 diffs)
-
trunk/includes/options.php (added)
-
trunk/readme.txt (modified) (5 diffs)
-
trunk/uninstall.php (added)
Legend:
- Unmodified
- Added
- Removed
-
hitboxtv-widget/trunk/hitboxtv-widget.php
r966117 r968923 4 4 Plugin URI: http://wordpress.org/plugins/hitboxtv-widget/ 5 5 Description: Hitbox.TV status widget. 6 Version: 1. 46 Version: 1.5.0 7 7 Author: SpiffyTek 8 8 Author URI: http://spiffytek.com/ … … 24 24 */ 25 25 26 define('HITBOX_TV_WIDGET_PATH_FULL', __FILE__); 27 define('HITBOX_TV_WIDGET_PATH', plugin_dir_path(HITBOX_TV_WIDGET_PATH_FULL)); 28 define('HITBOX_TV_WIDGET_URI', plugins_url('', HITBOX_TV_WIDGET_PATH_FULL)); 29 require_once(HITBOX_TV_WIDGET_PATH.'includes/functions.php'); 30 require_once(HITBOX_TV_WIDGET_PATH.'includes/options.php'); 31 26 32 class st_hitbox_widget extends WP_Widget{ 27 33 function st_hitbox_widget(){ … … 35 41 $hide_offline = esc_attr($instance['hide_offline']); 36 42 $hide_message = esc_attr($instance['hide_message']); 37 $cache_enable = esc_attr($instance['cache_enable']);38 $cache_lifetime = esc_attr($instance['cache_lifetime']);39 43 }else{ 40 44 $title = ''; … … 42 46 $hide_offline = 0; 43 47 $hide_message = 0; 44 $cache_enable = 0;45 $cache_lifetime = 300;46 48 } 47 49 ?> … … 62 64 <label for="<?php echo $this->get_field_id('hide_message'); ?>"><?php _e('Hide channel message', 'st_hitbox_widget'); ?></label> 63 65 </p> 64 <p>65 <input id="<?php echo $this->get_field_id('cache_enable'); ?>" name="<?php echo $this->get_field_name('cache_enable'); ?>" type="checkbox" value="1" <?php checked('1', $cache_enable); ?> />66 <label for="<?php echo $this->get_field_id('cache_enable'); ?>"><?php _e('Enable cache', 'st_hitbox_widget'); ?></label>67 </p>68 <p>69 <label for="<?php echo $this->get_field_id('cache_lifetime'); ?>"><?php _e('Cache lifetime:', 'st_hitbox_widget'); ?>70 <input style="width: 30%" class="widefat" id="<?php echo $this->get_field_id('cache_lifetime'); ?>" name="<?php echo $this->get_field_name('cache_lifetime'); ?>" type="text" value="<?php echo $cache_lifetime; ?>" /><?php _e('(seconds)', 'st_hitbox_widget'); ?></label>71 </p>72 66 <?php 73 67 } … … 79 73 $instance['hide_offline'] = strip_tags($new_instance['hide_offline']); 80 74 $instance['hide_message'] = strip_tags($new_instance['hide_message']); 81 $instance['cache_enable'] = strip_tags($new_instance['cache_enable']);82 $instance['cache_lifetime'] = strip_tags($new_instance['cache_lifetime']);83 75 if($this->id){ 84 76 delete_transient($this->id); … … 100 92 101 93 if($text){ 102 define('HITBOX_TV_WIDGET_PATH', plugin_dir_path(__FILE__));103 define('HITBOX_TV_WIDGET_URI', plugins_url('', __FILE__));104 require_once(HITBOX_TV_WIDGET_PATH.'includes/functions.php');105 94 106 95 $text = explode(',', preg_replace('/\s/', '', $text)); … … 109 98 <ul>'; 110 99 111 if(!get_transient($cache_key) || $instance['cache_enable']!= 1){112 100 if(!get_transient($cache_key) || get_option('sthw_cache_enable') != 1){ 101 113 102 for($i = 0; $i <= count($text) - 1; $i++){ 114 $return[] = _hitbox_status($text[$i], $instance); 103 if(substr(strtolower($text[$i]), 0, 5) == 'team:'){ 104 $text[$i] = str_replace('team:', '', strtolower($text[$i])); 105 $team = _hitbox_get_teammembers($text[$i]); 106 $channel = array_merge($channel, $team); 107 }else{ 108 $channel[] = $text[$i]; 109 } 115 110 } 116 111 117 set_transient($cache_key, $return, $instance['cache_lifetime']); 112 for($i = 0; $i <= count($channel) - 1; $i++){ 113 $return[] = _hitbox_status($channel[$i], $instance); 114 } 115 116 set_transient($cache_key, $return, get_option('sthw_cache_lifetime')); 118 117 119 118 }else{ … … 130 129 echo '<p class="st_hitbox_widget_text">No channel set!</p>'; 131 130 } 132 131 133 132 echo $after_widget; 134 133 } 135 }136 137 function _sthw_shortcode($atts, $content = ''){138 $content = preg_replace(array('/\s/', '/\xA0/', '/\xC2/'), '', $content);139 $args = shortcode_atts(array(140 'video' => 'true',141 'vwidth' => '640',142 'vheight' => '360',143 'chat' => 'true',144 'cwidth' => '360',145 'cheight' => '640'146 ), $atts, 'hitbox');147 148 $return = '';149 150 if(!empty($content)){151 if($args['video'] != 'false'){152 $return .= '<iframe width="'.$args['vwidth'].'" height="'.$args['vheight'].'" src="http://www.hitbox.tv/#!/embed/'.$content.'?autoplay=true" frameborder="0" allowfullscreen></iframe>';153 }154 if($args['chat'] != 'false'){155 $return .= '<iframe width="'.$args['cwidth'].'" height="'.$args['cheight'].'" src="http://www.hitbox.tv/embedchat/'.$content.'" frameborder="0" allowfullscreen></iframe>';156 }157 158 }else{159 $return = 'NO HITBOX CHANNEL SET!';160 }161 162 return $return;163 }164 165 166 function _sthw_add_stylesheet(){167 wp_enqueue_style('st-hitbox-widget', plugins_url('style.css', __FILE__));168 }169 function _sthw_translate(){170 load_plugin_textdomain('st_hitbox_widget', false, plugin_dir_path(__FILE__).'languages');171 134 } 172 135 … … 174 137 add_action('widgets_init', create_function('', 'return register_widget("st_hitbox_widget");')); 175 138 add_action('wp_enqueue_scripts', '_sthw_add_stylesheet'); 139 add_action('admin_menu', '_sthw_options_page'); 176 140 add_shortcode('hitbox', '_sthw_shortcode'); 141 register_activation_hook(HITBOX_TV_WIDGET_PATH_FULL, '_sthw_install'); 142 register_deactivation_hook(HITBOX_TV_WIDGET_PATH.'/uninstall.php', '_sthw_uninstall'); 143 register_uninstall_hook(HITBOX_TV_WIDGET_PATH.'/uninstall.php', '_sthw_uninstall'); 177 144 ?> -
hitboxtv-widget/trunk/includes/functions.php
r966117 r968923 22 22 23 23 $api = 'http://api.hitbox.tv/media/live/'.$name; 24 $hitbox = _file_get_contents_curl($api, 'WP Hitbox status widget');24 $hitbox = wp_remote_get($api, array('user-agent' => 'WP Hitbox status widget/'._sthw_version())); 25 25 26 if($hitbox['header']['http_code'] == '404'){ 27 return '<li class="st-hitbox-widget-list-item"><span class="st-hitbox-widget-title"><a target="_blank" href="http://www.hitbox.tv/'.$name.'">'.$name.'</a></span><span class="st-hitbox-widget-indicator">'.__('Unknown channel', 'st_hitbox_widget').'</span></li>'; 28 }elseif($hitbox['header']['http_code'] != '200'){ 26 if(wp_remote_retrieve_response_code($hitbox) == '404'){ 27 if(get_option('sthw_hide_unknown') != '1'){ 28 return '<li class="st-hitbox-widget-list-item"><span class="st-hitbox-widget-title"><a target="_blank" href="http://www.hitbox.tv/'.$name.'">'.$name.'</a></span><span class="st-hitbox-widget-indicator">'.__('Unknown channel', 'st_hitbox_widget').'</span></li>'; 29 }else{ 30 return false; 31 } 32 }elseif(wp_remote_retrieve_response_code($hitbox) != '200'){ 29 33 return '<li class="st-hitbox-widget-list-item"><span class="st-hitbox-widget-title"><a target="_blank" href="http://www.hitbox.tv/'.$name.'">'.$name.'</a></span><span class="st-hitbox-widget-indicator">'.__('Failed to connect to hitbox.tv api.', 'st_hitbox_widget').'</span></li>'; 30 34 } 31 35 32 $stream = json_decode( $hitbox['data'], true);36 $stream = json_decode(wp_remote_retrieve_body($hitbox), true); 33 37 34 38 if($stream['livestream'][0]['media_is_live'] != 0){ … … 50 54 $txt = '<span class="st-hitbox-widget-title"><a target="_blank" href="http://www.hitbox.tv/'.$name.'">'.$stream['livestream'][0]['media_user_name'].'</a></span>'; 51 55 $txt .= '<span class="st-hitbox-widget-indicator">'.__('Offline', 'st_hitbox_widget').'</span>'; 52 $boxart = HITBOX_TV_WIDGET_URI.'/assets/images/offline.jpg';53 /* $txt .= '<span class="st-hitbox-widget-image"><a target="_blank" href="http://www.hitbox.tv/'.$name.'"><img src="'.$boxart.'" alt=""></a></span>'; */54 56 } 55 57 … … 61 63 } 62 64 65 function _hitbox_get_teammembers($team){ 66 $api = 'http://api.hitbox.tv/team/'.$team; 67 $hitbox = wp_remote_get($api, array('user-agent' => 'WP Hitbox status widget/'._sthw_version())); 68 69 if(wp_remote_retrieve_response_code($hitbox) != '200'){ 70 return false; 71 } 72 73 $list = json_decode(wp_remote_retrieve_body($hitbox), true); 74 75 for($i = 0; $i <= count($list['members']) - 1; $i++){ 76 if($list['members'][$i]['user_is_broadcaster'] == 'true'){ 77 $return[] = $list['members'][$i]['user_name']; 78 } 79 } 80 81 return $return; 82 } 63 83 84 function _sthw_shortcode($atts, $content = ''){ 85 $content = preg_replace(array('/\s/', '/\xA0/', '/\xC2/'), '', $content); 86 $args = shortcode_atts(array( 87 'video' => 'true', 88 'vwidth' => '640', 89 'vheight' => '360', 90 'chat' => 'true', 91 'cwidth' => '360', 92 'cheight' => '640' 93 ), $atts, 'hitbox'); 64 94 65 /* FUNCTIONS */ 66 function _file_get_contents_curl($url, $agent = 'My Agent', $cookie = false, $post = false){ 67 $ch = curl_init();68 69 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);70 curl_setopt($ch, CURLOPT_TIMEOUT, 2);71 curl_setopt($ch, CURLOPT_HEADER, 0);72 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);73 curl_setopt($ch, CURLOPT_USERAGENT, $agent);74 if($cookie){75 curl_setopt($ch, CURLOPT_COOKIESESSION, true);76 curl_setopt($ch, CURLOPT_COOKIE, $cookie);95 $return = ''; 96 97 if(!empty($content)){ 98 if($args['video'] != 'false'){ 99 $return .= '<iframe width="'.$args['vwidth'].'" height="'.$args['vheight'].'" src="http://www.hitbox.tv/#!/embed/'.$content.'?autoplay=true" frameborder="0" allowfullscreen></iframe>'; 100 } 101 if($args['chat'] != 'false'){ 102 $return .= '<iframe width="'.$args['cwidth'].'" height="'.$args['cheight'].'" src="http://www.hitbox.tv/embedchat/'.$content.'" frameborder="0" allowfullscreen></iframe>'; 103 } 104 105 }else{ 106 $return = 'NO HITBOX CHANNEL SET!'; 77 107 } 78 curl_setopt($ch, CURLOPT_URL, $url); 79 if($post){ 80 curl_setopt($ch, CURLOPT_POST, true); 81 curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 108 109 return $return; 110 } 111 112 function _sthw_add_stylesheet(){ 113 wp_enqueue_style('st-hitbox-widget', HITBOX_TV_WIDGET_URI.'/style.css'); 114 } 115 116 function _sthw_translate(){ 117 load_plugin_textdomain('st_hitbox_widget', false, HITBOX_TV_WIDGET_PATH.'languages'); 118 } 119 120 function _sthw_version() { 121 if(!function_exists('get_plugins')){ 122 require_once(ABSPATH.'wp-admin/includes/plugin.php'); 82 123 } 83 84 $data = curl_exec($ch); 85 $header = curl_getinfo($ch); 86 curl_close($ch); 87 88 return array('data' => $data, 'header' => $header); 89 } 124 $plugin_folder = get_plugins('/'.plugin_basename(dirname(HITBOX_TV_WIDGET_PATH_FULL))); 125 $plugin_file = basename((HITBOX_TV_WIDGET_PATH_FULL)); 126 return $plugin_folder[$plugin_file]['Version']; 127 } 90 128 ?> -
hitboxtv-widget/trunk/readme.txt
r966118 r968923 5 5 Requires at least: 3.9.0 6 6 Tested up to: 3.9.2 7 Stable tag: 1. 47 Stable tag: 1.5.0 8 8 License: GPLv3 9 9 License URI: http://www.gnu.org/licenses/gpl-3.0.html … … 35 35 36 36 * Multiple Channels: 37 1. To show multiple channels in one widget simply add a comma seperated list of channels into the widgets 'Channel' field. 37 * To show multiple channels in one widget simply add a comma seperated list of channels into the widgets 'Channel' field. 38 * Teams: 39 1. Simply add `team:` infront of the team-channel name 40 1. Example: For team hitbox.tv/team/hitbox simply use `team:hitbox` as channel name 38 41 * Usage of the `[hitbox][/hitbox]` Shortcode: 39 42 * Simply add the channel name between the tags eg.: `[hitbox]hitboxlive[/hitbox]` … … 42 45 * `video` Enables or disables the video. Options: true|false. Default: true 43 46 * `vwidth` Controls the width of the embedded video. Default: 640 44 * `vheight` Controls the heig t of the embedded video. Default: 36047 * `vheight` Controls the height of the embedded video. Default: 360 45 48 1. For the chat: 46 49 * `chat` Enables or disables the chat. Options: true|false. Default: true 47 50 * `cwidth` Controls the width of the embedded chat. Default: 360 48 * `cheight` Controls the heig t of the embedded chat. Default: 64051 * `cheight` Controls the height of the embedded chat. Default: 640 49 52 * Example: `[hitbox vwidth=848 vheight=480 chat=false]hitboxlive[/hitbox]` will show the 'hitboxlive' channel video in 848x480 pixels in size and the chat won't be shown 50 53 … … 62 65 1. Frontpage 63 66 2. Widget settings 67 3. Plugin settings 64 68 65 69 == Changelog == 70 [Full changelog](http://builds.spiffytek.net/changelogs/wp-hitbox-status-widget.txt) 71 72 = 1.5.0 = 73 * Added (simple) Team support. See Installation/readme.txt for usage (#76) 74 * This will be extended in future 75 * Added options page for global settings like cache 76 * Added global option to hide "Unknown channel" 77 * New version scheme (major.minor.maintenance) 66 78 67 79 = 1.4 = … … 72 84 * Added option to hide offline streams 73 85 * Added configurable cache (#74) 74 * Fixed improper whitespace cleanup on 'Channel' field 86 * Fixed improper whitespace cleanup on 'Channel' field (#75) 75 87 * Various code cleanups 76 88
Note: See TracChangeset
for help on using the changeset viewer.