Changeset 713017
- Timestamp:
- 05/14/2013 04:08:18 PM (13 years ago)
- Location:
- live-stream-badger/trunk
- Files:
-
- 3 added
- 4 deleted
- 8 edited
-
apis/class-api-core.php (modified) (4 diffs)
-
apis/class-api-twitch.php (modified) (1 diff)
-
apis/class-api.php (modified) (4 diffs)
-
domain/class-stream-info.php (deleted)
-
domain/class-stream-summary.php (added)
-
domain/class-stream-url.php (deleted)
-
domain/class-stream.php (added)
-
domain/domain-core.php (deleted)
-
live-stream-badger-plugin.php (modified) (2 diffs)
-
scheduler/class-menu-item-updater.php (modified) (4 diffs)
-
shortcode/class-embedded-stream.php (modified) (4 diffs)
-
store/class-stream-storage.php (added)
-
store/class-widget-stream-store.php (deleted)
-
stream-status-widget.php (modified) (3 diffs)
-
view/class-embedded-twitch-view.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
live-stream-badger/trunk/apis/class-api-core.php
r708722 r713017 1 1 <?php 2 2 3 include_once ( 'class-api.php' ); 4 include_once ( 'class-api-twitch.php' ); 5 include_once LSB_PLUGIN_BASE . 'domain/domain-core.php'; 3 include_once 'class-api.php'; 4 include_once 'class-api-twitch.php'; 6 5 7 6 /** … … 22 21 * Queries a list of URLs from mixed APIs. 23 22 * 24 * @param array $stream_urls List of valid LSB_Stream_ URL23 * @param array $stream_urls List of valid LSB_Stream_Summary 25 24 * 26 * @return array List of LSB_Stream _Info25 * @return array List of LSB_Stream 27 26 */ 28 27 function query( $stream_urls ) { … … 31 30 $stream_urls_by_api = array(); 32 31 foreach ( $stream_urls as $stream_url ) { 33 /** @var $stream_url LSB_Stream_ URL*/32 /** @var $stream_url LSB_Stream_Summary */ 34 33 if ( !isset( $stream_urls_by_api[$stream_url->api_id] ) ) { 35 34 $stream_urls_by_api[$stream_url->api_id] = array(); … … 52 51 /** 53 52 * Cleans URLs and checks if they are supported by any registered API. 54 * Returned list contains LSB_Stream_ URLonly for valid URLs.53 * Returned list contains LSB_Stream_Summary only for valid URLs. 55 54 * 56 55 * @param array $urls List of string URLs 57 56 * 58 * @return array List of validated LSB_Stream_ URL57 * @return array List of validated LSB_Stream_Summary 59 58 */ 60 59 function validate_urls( $urls ) { -
live-stream-badger/trunk/apis/class-api-twitch.php
r708199 r713017 58 58 $url = $this->channel_to_url( $j_channel_name ); 59 59 60 $stream_dto = new LSB_Stream _Info();61 $stream_dto-> channel_name = $j_channel_name;62 $stream_dto-> url = $url;60 $stream_dto = new LSB_Stream(); 61 $stream_dto->summary->channel_name = $j_channel_name; 62 $stream_dto->summary->url = $url; 63 63 $stream_dto->watching_now = $j['channel_count']; 64 64 -
live-stream-badger/trunk/apis/class-api.php
r700755 r713017 7 7 8 8 /** 9 * Executes query for all given URLs.9 * Executes query for the given stream summaries. 10 10 * 11 * @param array $ urls List of LSB_Stream_URLto query, validated11 * @param array $stream_summaries List of LSB_Stream_Summary to query, validated 12 12 * 13 * @return array List of LSB_Stream _Info13 * @return array List of LSB_Stream 14 14 */ 15 function query( $ urls ) {15 function query( $stream_summaries ) { 16 16 17 17 // Build channel names for query 18 18 $channel_names = array(); 19 foreach ( $ urls as $url) {20 /** @var $url LSB_Stream_ URL*/21 $channel_names[] = $ url->channel_name;19 foreach ( $stream_summaries as $stream_summary ) { 20 /** @var $url LSB_Stream_Summary */ 21 $channel_names[] = $stream_summary->channel_name; 22 22 } 23 23 … … 34 34 return array(); 35 35 36 $stream _infos = $this->map_results( $response );36 $streams = $this->map_results( $response ); 37 37 38 38 // Map original URL (for malformed URLs where url != original_url) 39 foreach ( $stream _infos as $s) {40 /** @var $s LSB_Stream_Info*/41 foreach ( $ urls as $url) {42 /** @var $url LSB_Stream_ URL*/43 if ( $s ->url == $url->url ) {44 $s ->original_url = $url->original_url;45 break; // Go to next Stream info39 foreach ( $streams as $stream ) { 40 /** @var $stream LSB_Stream */ 41 foreach ( $stream_summaries as $stream_summary ) { 42 /** @var $url LSB_Stream_Summary */ 43 if ( $stream->summary->url == $stream_summary->url ) { 44 $stream->summary->original_url = $stream_summary->original_url; 45 break; // Go to the next Stream 46 46 } 47 47 } 48 48 } 49 49 50 return $stream _infos;50 return $streams; 51 51 } 52 52 53 53 /** 54 * Checks if API supports given URL - if supported, returns LSB_Stream_ URL.54 * Checks if API supports given URL - if supported, returns LSB_Stream_Summary. 55 55 * 56 56 * @param string $url 57 57 * 58 * @return LSB_Stream_ URL58 * @return LSB_Stream_Summary 59 59 */ 60 60 function validate_url( $url ) { … … 69 69 return; 70 70 71 $s tream_url = new LSB_Stream_URL();71 $summary = new LSB_Stream_Summary(); 72 72 73 $s tream_url->original_url = $original_url;74 $s tream_url->url = $url;75 $s tream_url->channel_name = $channel_name;76 $s tream_url->api_id = $this->get_api_identifier();73 $summary->original_url = $original_url; 74 $summary->url = $url; 75 $summary->channel_name = $channel_name; 76 $summary->api_id = $this->get_api_identifier(); 77 77 78 return $s tream_url;78 return $summary; 79 79 } 80 80 … … 144 144 145 145 /** 146 * Maps API response to a list of {@link LSB_Stream _Info}.146 * Maps API response to a list of {@link LSB_Stream}. 147 147 * 148 148 * @param $result_string -
live-stream-badger/trunk/live-stream-badger-plugin.php
r711697 r713017 15 15 } 16 16 17 include_once( LSB_PLUGIN_BASE . 'apis/class-api-core.php' ); 18 include_once( LSB_PLUGIN_BASE . 'domain/domain-core.php' ); 19 20 include_once( LSB_PLUGIN_BASE . 'stream-status-widget.php' ); 21 include_once( LSB_PLUGIN_BASE . 'shortcode/class-embedded-stream.php' ); 22 include_once( LSB_PLUGIN_BASE . 'scheduler/class-menu-item-updater.php' ); 17 include_once LSB_PLUGIN_BASE . 'apis/class-api-core.php'; 18 include_once LSB_PLUGIN_BASE . 'stream-status-widget.php'; 19 include_once LSB_PLUGIN_BASE . 'shortcode/class-embedded-stream.php'; 20 include_once LSB_PLUGIN_BASE . 'scheduler/class-menu-item-updater.php'; 23 21 24 22 // Register widget … … 45 43 function lsb_activation() { 46 44 lsb_health_check(); 45 wp_schedule_single_event( time(), 'lsb_update_all_stream_status' ); 47 46 wp_schedule_event( time(), 'lsb_five_minutes', 'lsb_update_all_stream_status' ); 48 47 } -
live-stream-badger/trunk/scheduler/class-menu-item-updater.php
r712948 r713017 4 4 die(); 5 5 6 include_once( LSB_PLUGIN_BASE . 'apis/class-api-core.php' ); 7 include_once( LSB_PLUGIN_BASE . 'domain/domain-core.php' ); 8 include_once( LSB_PLUGIN_BASE . 'store/class-widget-stream-store.php' ); 6 include_once LSB_PLUGIN_BASE . 'apis/class-api-core.php'; 7 include_once LSB_PLUGIN_BASE . 'domain/class-stream-summary.php'; 8 include_once LSB_PLUGIN_BASE . 'store/class-stream-storage.php'; 9 include_once LSB_PLUGIN_BASE . 'domain/class-menu-item.php'; 9 10 10 11 /** … … 27 28 $api_core = new LSB_API_Core(); 28 29 29 $ validated_stream_urls = $api_core->validate_urls( $all_urls );30 $stream _infos = $api_core->query( $validated_stream_urls );30 $stream_summaries = $api_core->validate_urls( $all_urls ); 31 $streams = $api_core->query( $stream_summaries ); 31 32 32 $this->update_store( $ validated_stream_urls, $stream_infos );33 $this->update_store( $stream_summaries, $streams ); 33 34 } 34 35 … … 84 85 85 86 /** 86 * Go through all validated stream URLs (found from menu items) and update with information from LSB_Stream_Info.87 * All information will be merged except for 'Watching now' (will be set to offline if not found in LSB_Stream _Info).87 * Updates store for all $stream_summaries with information from API ($streams). 88 * All information will be merged except for 'Watching now' (will be set to offline if not found in LSB_Stream). 88 89 * 89 90 * When Stream info is not found for menu item, 'Watching now' is set to -1 (which is later 90 91 * interpreted as 'Offline'). 91 92 * 92 * @param $validated_stream_urls93 * @param $stream_infos93 * @param array $stream_summaries list of LSB_Stream_Summary to update information for 94 * @param $streams array of LSB_Stream - information from API 94 95 */ 95 private function update_store( $ validated_stream_urls, $stream_infos ) {96 $store = new LSB_ Widget_Stream_Store();96 private function update_store( $stream_summaries, $streams ) { 97 $store = new LSB_Stream_Storage(); 97 98 $stored_infos = $store->load(); 98 99 99 100 $merged_infos = array(); 100 101 101 foreach ( $ validated_stream_urls as $u) {102 $stream_id = LSB_Stream_Info::make_stream_id( $u->api_id, $u->channel_name );103 if ( isset($merged_infos[$stream_id]))102 foreach ( $stream_summaries as $summary ) { 103 /** @var $summary LSB_Stream_Summary */ 104 if ( isset( $merged_infos[$summary->get_id()] ) ) 104 105 // Can occur if the same link is in multiple menus 105 106 continue; 106 107 107 /** @var $u LSB_Stream_URL*/108 /** @var $update LSB_Stream_Summary */ 108 109 $update = NULL; 109 foreach ( $stream _infos as $s) {110 /** @var $s LSB_Stream_Info*/111 if ( $s ->original_url == $u->original_url ) {112 $update = $s ;110 foreach ( $streams as $stream ) { 111 /** @var $stream LSB_Stream */ 112 if ( $stream->summary->original_url == $summary->original_url ) { 113 $update = $stream; 113 114 break; 114 115 } 115 116 } 116 117 117 $stored = isset( $stored_infos[$s tream_id] ) ? $stored_infos[$stream_id] : NULL;118 $stored = isset( $stored_infos[$summary->get_id()] ) ? $stored_infos[$summary->get_id()] : NULL; 118 119 119 /** New menu item/stream info - not stored yet, populate with defaults */120 120 if ( empty( $stored ) ) { 121 $stored = new LSB_Stream_Info(); 122 $stored->api_id = $u->api_id; 123 $stored->url = $u->url; 124 $stored->original_url = $u->original_url; 125 $stored->channel_name = $u->channel_name; 121 // A new menu item that is not in store yet 122 $stored = new LSB_Stream(); 123 $stored->summary = $summary; 126 124 } 127 125 … … 135 133 } 136 134 137 $merged_infos[$s tream_id] = $stored;135 $merged_infos[$summary->get_id()] = $stored; 138 136 } 139 137 140 $store->store( $merged_infos);138 $store->store( $merged_infos ); 141 139 } 142 140 -
live-stream-badger/trunk/shortcode/class-embedded-stream.php
r708722 r713017 2 2 3 3 include_once LSB_PLUGIN_BASE . 'view/class-embedded-twitch-view.php'; 4 include_once LSB_PLUGIN_BASE . 'domain/class-stream-summary.php'; 4 5 5 6 class LSB_Embedded_Stream { … … 7 8 function do_shortcode( $attrs ) { 8 9 $attrs = shortcode_atts( array( 9 'url' => '',10 'width' => '620',11 'height' => '378',12 'stream' => TRUE,10 'url' => '', 11 'width' => '620', 12 'height' => '378', 13 'stream' => TRUE, 13 14 14 'chat_width' => '620',15 'chat_width' => '620', 15 16 'chat_height' => '400', 16 'chat' => FALSE17 'chat' => FALSE 17 18 ), $attrs ); 18 19 … … 20 21 return ''; 21 22 22 $api_core = new LSB_API_Core();23 $ validated_urls = $api_core->validate_urls( array( $attrs['url'] ) );24 $stream_ url = !empty( $validated_urls ) ? $validated_urls[0] : NULL;23 $api_core = new LSB_API_Core(); 24 $stream_summaries = $api_core->validate_urls( array( $attrs['url'] ) ); 25 $stream_summary = !empty( $stream_summaries ) ? $stream_summaries[0] : NULL; 25 26 26 /** @var $stream_ url LSB_Stream_URL*/27 /** @var $stream_summary LSB_Stream_Summary */ 27 28 if ( empty( $stream_url ) ) 28 29 return ''; 29 30 30 31 $view = NULL; 31 switch ( $stream_ url->api_id ) {32 switch ( $stream_summary->api_id ) { 32 33 case 'twitch' : 33 34 $view = new LSB_Embedded_Twitch_View(); … … 38 39 return ''; 39 40 40 $attrs['stream_ url'] = $stream_url;41 $attrs['stream_summary'] = $stream_summary; 41 42 42 43 return $view->get_html( $attrs ); -
live-stream-badger/trunk/stream-status-widget.php
r712948 r713017 2 2 3 3 include_once LSB_PLUGIN_BASE . 'apis/class-api-core.php'; 4 include_once LSB_PLUGIN_BASE . 'domain/class-stream.php'; 5 include_once LSB_PLUGIN_BASE . 'domain/class-stream-summary.php'; 6 include_once LSB_PLUGIN_BASE . 'store/class-stream-storage.php'; 4 7 5 8 /** … … 39 42 if ( empty( $m->url ) || empty( $m->title ) ) 40 43 continue; 41 $validated_urls = $core->validate_urls(array($m->url)); 42 $validated_url = isset($validated_urls[0]) ? $validated_urls[0] : NULL; 43 $stream_id = LSB_Stream_Info::make_stream_id($validated_url->api_id, $validated_url->channel_name); 44 $links[$stream_id] = $m; 44 $stream_summaries = $core->validate_urls( array( $m->url ) ); 45 /** @var $stream_summary LSB_Stream_Summary */ 46 $stream_summary = isset( $stream_summaries[0] ) ? $stream_summaries[0] : NULL; 47 if ( empty( $stream_summary ) ) 48 continue; 49 50 $links[$stream_summary->get_id()] = $m; 45 51 } 46 52 47 $store = new LSB_Widget_Stream_Store();48 $stream _infos = $store->load();53 $store = new LSB_Stream_Storage(); 54 $streams = $store->load(); 49 55 50 usort( $stream _infos, array( 'LSB_Stream_Info', 'sort_by_watching_now' ) );56 usort( $streams, array( 'LSB_Stream', 'sort_by_watching_now' ) ); 51 57 ?> 52 58 <div class="lsb-status-widget-holder"> 53 59 <ul> 54 60 <?php 55 foreach ( $stream_infos as $stream_info) {56 /** @var $stream _info LSB_Stream_Info*/57 $menu_item = $links[ LSB_Stream_Info::make_stream_id($stream_info->api_id, $stream_info->channel_name)];58 if ( empty($menu_item))61 foreach ( $streams as $stream ) { 62 /** @var $stream LSB_Stream */ 63 $menu_item = $links[$stream->summary->get_id()]; 64 if ( empty( $menu_item ) ) 59 65 continue; 60 66 61 $is_on = ( $stream _info->watching_now != -1 );67 $is_on = ( $stream->watching_now != -1 ); 62 68 $status_class = $is_on ? 'lsb-on' : 'lsb-off'; 63 69 ?> … … 66 72 target="_blank"><?php echo apply_filters( 'lsb_stream_status_widget_text', $menu_item->title ); ?></a> 67 73 <span 68 class="lsb-status-widget-indicator <?php echo $status_class; ?>"><?php echo $is_on ? $stream _info->watching_now : 'Offline'; ?></span>74 class="lsb-status-widget-indicator <?php echo $status_class; ?>"><?php echo $is_on ? $stream->watching_now : 'Offline'; ?></span> 69 75 </li> 70 76 <?php -
live-stream-badger/trunk/view/class-embedded-twitch-view.php
r707591 r713017 1 1 <?php 2 2 3 include_once( 'class-view.php' ); 3 include_once 'class-view.php'; 4 include_once LSB_PLUGIN_BASE . 'domain/class-stream-summary.php'; 4 5 5 6 class LSB_Embedded_Twitch_View extends LSB_View { 6 7 7 8 function get_html( $args ) { 8 /** @var $stream_url LSB_Stream_ URL*/9 $stream_ url = $args['stream_url'];9 /** @var $stream_url LSB_Stream_Summary */ 10 $stream_summary = $args['stream_summary']; 10 11 11 12 $w = $args['width']; … … 21 22 if ( $show_stream ) { 22 23 $html .= '<div class="lsb-embedded-view"><object type="application/x-shockwave-flash" height="' . $h . '" width="' . $w . '" id="live_embed_player_flash" ' 23 . 'data="http://www.twitch.tv/widgets/live_embed_player.swf?channel=' . $stream_ url->channel_name . '" bgcolor="#000000">'24 . 'data="http://www.twitch.tv/widgets/live_embed_player.swf?channel=' . $stream_summary->channel_name . '" bgcolor="#000000">' 24 25 . '<param name="allowFullScreen" value="true" />' 25 26 . '<param name="allowScriptAccess" value="always" />' 26 27 . '<param name="allowNetworking" value="all" />' 27 28 . '<param name="movie" value="http://www.twitch.tv/widgets/live_embed_player.swf" />' 28 . '<param name="flashvars" value="hostname=www.twitch.tv&channel=' . $stream_ url->channel_name . '&auto_play=true&start_volume=25" />'29 . '<param name="flashvars" value="hostname=www.twitch.tv&channel=' . $stream_summary->channel_name . '&auto_play=true&start_volume=25" />' 29 30 . '</object></div>'; 30 31 }
Note: See TracChangeset
for help on using the changeset viewer.