Plugin Directory

Changeset 968923


Ignore:
Timestamp:
08/20/2014 11:46:53 AM (12 years ago)
Author:
MadMakz
Message:

http://builds.spiffytek.net/changelogs/wp-hitbox-status-widget.txt

Location:
hitboxtv-widget
Files:
14 added
1 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • hitboxtv-widget/trunk/hitboxtv-widget.php

    r966117 r968923  
    44Plugin URI: http://wordpress.org/plugins/hitboxtv-widget/
    55Description: Hitbox.TV status widget.
    6 Version: 1.4
     6Version: 1.5.0
    77Author: SpiffyTek
    88Author URI: http://spiffytek.com/
     
    2424*/
    2525
     26define('HITBOX_TV_WIDGET_PATH_FULL', __FILE__);
     27define('HITBOX_TV_WIDGET_PATH', plugin_dir_path(HITBOX_TV_WIDGET_PATH_FULL));
     28define('HITBOX_TV_WIDGET_URI', plugins_url('', HITBOX_TV_WIDGET_PATH_FULL));
     29require_once(HITBOX_TV_WIDGET_PATH.'includes/functions.php');
     30require_once(HITBOX_TV_WIDGET_PATH.'includes/options.php');
     31
    2632class st_hitbox_widget extends WP_Widget{
    2733    function st_hitbox_widget(){
     
    3541            $hide_offline = esc_attr($instance['hide_offline']);
    3642            $hide_message = esc_attr($instance['hide_message']);
    37             $cache_enable = esc_attr($instance['cache_enable']);
    38             $cache_lifetime = esc_attr($instance['cache_lifetime']);
    3943        }else{
    4044            $title = '';
     
    4246            $hide_offline = 0;
    4347            $hide_message = 0;
    44             $cache_enable = 0;
    45             $cache_lifetime = 300;
    4648        }
    4749?> 
     
    6264            <label for="<?php echo $this->get_field_id('hide_message'); ?>"><?php _e('Hide channel message', 'st_hitbox_widget'); ?></label>
    6365        </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>
    7266<?php
    7367    }
     
    7973        $instance['hide_offline'] = strip_tags($new_instance['hide_offline']);
    8074        $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']);
    8375        if($this->id){
    8476            delete_transient($this->id);
     
    10092
    10193        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');
    10594           
    10695            $text = explode(',', preg_replace('/\s/', '', $text));
     
    10998                    <ul>';             
    11099                   
    111             if(!get_transient($cache_key) || $instance['cache_enable'] != 1){
    112                    
     100            if(!get_transient($cache_key) || get_option('sthw_cache_enable') != 1){
     101               
    113102                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                    }
    115110                }
    116111               
    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'));
    118117               
    119118            }else{
     
    130129            echo '<p class="st_hitbox_widget_text">No channel set!</p>';
    131130        }
    132        
     131
    133132        echo $after_widget;
    134133    }
    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');
    171134}
    172135
     
    174137add_action('widgets_init', create_function('', 'return register_widget("st_hitbox_widget");'));
    175138add_action('wp_enqueue_scripts', '_sthw_add_stylesheet');
     139add_action('admin_menu', '_sthw_options_page');
    176140add_shortcode('hitbox', '_sthw_shortcode');
     141register_activation_hook(HITBOX_TV_WIDGET_PATH_FULL, '_sthw_install');
     142register_deactivation_hook(HITBOX_TV_WIDGET_PATH.'/uninstall.php', '_sthw_uninstall');
     143register_uninstall_hook(HITBOX_TV_WIDGET_PATH.'/uninstall.php', '_sthw_uninstall');
    177144?>
  • hitboxtv-widget/trunk/includes/functions.php

    r966117 r968923  
    2222
    2323    $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()));
    2525   
    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'){
    2933        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>';
    3034    }
    3135   
    32     $stream = json_decode($hitbox['data'], true);
     36    $stream = json_decode(wp_remote_retrieve_body($hitbox), true);
    3337   
    3438    if($stream['livestream'][0]['media_is_live'] != 0){
     
    5054        $txt = '<span class="st-hitbox-widget-title"><a target="_blank" href="http://www.hitbox.tv/'.$name.'">'.$stream['livestream'][0]['media_user_name'].'</a></span>';
    5155        $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>'; */
    5456    }
    5557
     
    6163}
    6264
     65function _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}
    6383
     84function _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');
    6494
    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!';
    77107    }
    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
     112function _sthw_add_stylesheet(){
     113    wp_enqueue_style('st-hitbox-widget', HITBOX_TV_WIDGET_URI.'/style.css');
     114}
     115
     116function _sthw_translate(){
     117    load_plugin_textdomain('st_hitbox_widget', false, HITBOX_TV_WIDGET_PATH.'languages');
     118}
     119
     120function _sthw_version() {
     121    if(!function_exists('get_plugins')){
     122        require_once(ABSPATH.'wp-admin/includes/plugin.php');
    82123    }
    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}
    90128?>
  • hitboxtv-widget/trunk/readme.txt

    r966118 r968923  
    55Requires at least: 3.9.0
    66Tested up to: 3.9.2
    7 Stable tag: 1.4
     7Stable tag: 1.5.0
    88License: GPLv3
    99License URI: http://www.gnu.org/licenses/gpl-3.0.html
     
    3535
    3636* 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
    3841* Usage of the `[hitbox][/hitbox]` Shortcode:
    3942    * Simply add the channel name between the tags eg.: `[hitbox]hitboxlive[/hitbox]`
     
    4245            * `video` Enables or disables the video. Options: true|false. Default: true
    4346            * `vwidth` Controls the width of the embedded video. Default: 640
    44             * `vheight` Controls the heigt of the embedded video. Default: 360
     47            * `vheight` Controls the height of the embedded video. Default: 360
    4548        1. For the chat:
    4649            * `chat` Enables or disables the chat. Options: true|false. Default: true
    4750            * `cwidth` Controls the width of the embedded chat. Default: 360
    48             * `cheight` Controls the heigt of the embedded chat. Default: 640
     51            * `cheight` Controls the height of the embedded chat. Default: 640
    4952        * 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
    5053
     
    62651. Frontpage
    63662. Widget settings
     673. Plugin settings
    6468
    6569== 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)
    6678
    6779= 1.4 =
     
    7284* Added option to hide offline streams
    7385* Added configurable cache (#74)
    74 * Fixed improper whitespace cleanup on 'Channel' field
     86* Fixed improper whitespace cleanup on 'Channel' field (#75)
    7587* Various code cleanups
    7688
Note: See TracChangeset for help on using the changeset viewer.