Plugin Directory

Changeset 713017


Ignore:
Timestamp:
05/14/2013 04:08:18 PM (13 years ago)
Author:
tkrivickas
Message:

IMPR: naming refactoring, added single scheduled event upon plugin activation

Location:
live-stream-badger/trunk
Files:
3 added
4 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • live-stream-badger/trunk/apis/class-api-core.php

    r708722 r713017  
    11<?php
    22
    3 include_once ( 'class-api.php' );
    4 include_once ( 'class-api-twitch.php' );
    5 include_once LSB_PLUGIN_BASE . 'domain/domain-core.php';
     3include_once 'class-api.php';
     4include_once 'class-api-twitch.php';
    65
    76/**
     
    2221     * Queries a list of URLs from mixed APIs.
    2322     *
    24      * @param array $stream_urls List of valid LSB_Stream_URL
     23     * @param array $stream_urls List of valid LSB_Stream_Summary
    2524     *
    26      * @return array List of LSB_Stream_Info
     25     * @return array List of LSB_Stream
    2726     */
    2827    function query( $stream_urls ) {
     
    3130        $stream_urls_by_api = array();
    3231        foreach ( $stream_urls as $stream_url ) {
    33             /** @var $stream_url LSB_Stream_URL */
     32            /** @var $stream_url LSB_Stream_Summary */
    3433            if ( !isset( $stream_urls_by_api[$stream_url->api_id] ) ) {
    3534                $stream_urls_by_api[$stream_url->api_id] = array();
     
    5251    /**
    5352     * Cleans URLs and checks if they are supported by any registered API.
    54      * Returned list contains LSB_Stream_URL only for valid URLs.
     53     * Returned list contains LSB_Stream_Summary only for valid URLs.
    5554     *
    5655     * @param array $urls List of string URLs
    5756     *
    58      * @return array List of validated LSB_Stream_URL
     57     * @return array List of validated LSB_Stream_Summary
    5958     */
    6059    function validate_urls( $urls ) {
  • live-stream-badger/trunk/apis/class-api-twitch.php

    r708199 r713017  
    5858            $url = $this->channel_to_url( $j_channel_name );
    5959
    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;
    6363            $stream_dto->watching_now = $j['channel_count'];
    6464
  • live-stream-badger/trunk/apis/class-api.php

    r700755 r713017  
    77
    88    /**
    9      * Executes query for all given URLs.
     9     * Executes query for the given stream summaries.
    1010     *
    11      * @param array $urls List of LSB_Stream_URL to query, validated
     11     * @param array $stream_summaries List of LSB_Stream_Summary to query, validated
    1212     *
    13      * @return array List of LSB_Stream_Info
     13     * @return array List of LSB_Stream
    1414     */
    15     function query( $urls ) {
     15    function query( $stream_summaries ) {
    1616
    1717        // Build channel names for query
    1818        $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;
    2222        }
    2323
     
    3434            return array();
    3535
    36         $stream_infos = $this->map_results( $response );
     36        $streams = $this->map_results( $response );
    3737
    3838        // 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 info
     39        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
    4646                }
    4747            }
    4848        }
    4949
    50         return $stream_infos;
     50        return $streams;
    5151    }
    5252
    5353    /**
    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.
    5555     *
    5656     * @param string $url
    5757     *
    58      * @return LSB_Stream_URL
     58     * @return LSB_Stream_Summary
    5959     */
    6060    function validate_url( $url ) {
     
    6969            return;
    7070
    71         $stream_url = new LSB_Stream_URL();
     71        $summary = new LSB_Stream_Summary();
    7272
    73         $stream_url->original_url = $original_url;
    74         $stream_url->url          = $url;
    75         $stream_url->channel_name = $channel_name;
    76         $stream_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();
    7777
    78         return $stream_url;
     78        return $summary;
    7979    }
    8080
     
    144144
    145145    /**
    146      * Maps API response to a list of {@link LSB_Stream_Info}.
     146     * Maps API response to a list of {@link LSB_Stream}.
    147147     *
    148148     * @param $result_string
  • live-stream-badger/trunk/live-stream-badger-plugin.php

    r711697 r713017  
    1515}
    1616
    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' );
     17include_once LSB_PLUGIN_BASE . 'apis/class-api-core.php';
     18include_once LSB_PLUGIN_BASE . 'stream-status-widget.php';
     19include_once LSB_PLUGIN_BASE . 'shortcode/class-embedded-stream.php';
     20include_once LSB_PLUGIN_BASE . 'scheduler/class-menu-item-updater.php';
    2321
    2422// Register widget
     
    4543function lsb_activation() {
    4644    lsb_health_check();
     45    wp_schedule_single_event( time(), 'lsb_update_all_stream_status' );
    4746    wp_schedule_event( time(), 'lsb_five_minutes', 'lsb_update_all_stream_status' );
    4847}
  • live-stream-badger/trunk/scheduler/class-menu-item-updater.php

    r712948 r713017  
    44    die();
    55
    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' );
     6include_once LSB_PLUGIN_BASE . 'apis/class-api-core.php';
     7include_once LSB_PLUGIN_BASE . 'domain/class-stream-summary.php';
     8include_once LSB_PLUGIN_BASE . 'store/class-stream-storage.php';
     9include_once LSB_PLUGIN_BASE . 'domain/class-menu-item.php';
    910
    1011/**
     
    2728        $api_core = new LSB_API_Core();
    2829
    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 );
    3132
    32         $this->update_store( $validated_stream_urls, $stream_infos );
     33        $this->update_store( $stream_summaries, $streams );
    3334    }
    3435
     
    8485
    8586    /**
    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).
    8889     *
    8990     * When Stream info is not found for menu item, 'Watching now' is set to -1 (which is later
    9091     * interpreted as 'Offline').
    9192     *
    92      * @param $validated_stream_urls
    93      * @param $stream_infos
     93     * @param array $stream_summaries list of LSB_Stream_Summary to update information for
     94     * @param       $streams          array of LSB_Stream - information from API
    9495     */
    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();
    9798        $stored_infos = $store->load();
    9899
    99100        $merged_infos = array();
    100101
    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()] ) )
    104105                // Can occur if the same link is in multiple menus
    105106                continue;
    106107
    107             /** @var $u LSB_Stream_URL */
     108            /** @var $update LSB_Stream_Summary */
    108109            $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;
    113114                    break;
    114115                }
    115116            }
    116117
    117             $stored = isset( $stored_infos[$stream_id] ) ? $stored_infos[$stream_id] : NULL;
     118            $stored = isset( $stored_infos[$summary->get_id()] ) ? $stored_infos[$summary->get_id()] : NULL;
    118119
    119             /** New menu item/stream info - not stored yet, populate with defaults */
    120120            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;
    126124            }
    127125
     
    135133            }
    136134
    137             $merged_infos[$stream_id] = $stored;
     135            $merged_infos[$summary->get_id()] = $stored;
    138136        }
    139137
    140         $store->store($merged_infos);
     138        $store->store( $merged_infos );
    141139    }
    142140
  • live-stream-badger/trunk/shortcode/class-embedded-stream.php

    r708722 r713017  
    22
    33include_once LSB_PLUGIN_BASE . 'view/class-embedded-twitch-view.php';
     4include_once LSB_PLUGIN_BASE . 'domain/class-stream-summary.php';
    45
    56class LSB_Embedded_Stream {
     
    78    function do_shortcode( $attrs ) {
    89        $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,
    1314
    14                                       'chat_width' => '620',
     15                                      'chat_width'  => '620',
    1516                                      'chat_height' => '400',
    16                                       'chat'   => FALSE
     17                                      'chat'        => FALSE
    1718                                 ), $attrs );
    1819
     
    2021            return '';
    2122
    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;
    2526
    26         /** @var $stream_url LSB_Stream_URL */
     27        /** @var $stream_summary LSB_Stream_Summary */
    2728        if ( empty( $stream_url ) )
    2829            return '';
    2930
    3031        $view = NULL;
    31         switch ( $stream_url->api_id ) {
     32        switch ( $stream_summary->api_id ) {
    3233            case 'twitch' :
    3334                $view = new LSB_Embedded_Twitch_View();
     
    3839            return '';
    3940
    40         $attrs['stream_url'] = $stream_url;
     41        $attrs['stream_summary'] = $stream_summary;
    4142
    4243        return $view->get_html( $attrs );
  • live-stream-badger/trunk/stream-status-widget.php

    r712948 r713017  
    22
    33include_once LSB_PLUGIN_BASE . 'apis/class-api-core.php';
     4include_once LSB_PLUGIN_BASE . 'domain/class-stream.php';
     5include_once LSB_PLUGIN_BASE . 'domain/class-stream-summary.php';
     6include_once LSB_PLUGIN_BASE . 'store/class-stream-storage.php';
    47
    58/**
     
    3942            if ( empty( $m->url ) || empty( $m->title ) )
    4043                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;
    4551        }
    4652
    47         $store = new LSB_Widget_Stream_Store();
    48         $stream_infos = $store->load();
     53        $store   = new LSB_Stream_Storage();
     54        $streams = $store->load();
    4955
    50         usort( $stream_infos, array( 'LSB_Stream_Info', 'sort_by_watching_now' ) );
     56        usort( $streams, array( 'LSB_Stream', 'sort_by_watching_now' ) );
    5157        ?>
    5258        <div class="lsb-status-widget-holder">
    5359            <ul>
    5460                <?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 ) )
    5965                        continue;
    6066
    61                     $is_on        = ( $stream_info->watching_now != -1 );
     67                    $is_on        = ( $stream->watching_now != -1 );
    6268                    $status_class = $is_on ? 'lsb-on' : 'lsb-off';
    6369                    ?>
     
    6672                           target="_blank"><?php echo apply_filters( 'lsb_stream_status_widget_text', $menu_item->title ); ?></a>
    6773                        <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>
    6975                    </li>
    7076                <?php
  • live-stream-badger/trunk/view/class-embedded-twitch-view.php

    r707591 r713017  
    11<?php
    22
    3 include_once( 'class-view.php' );
     3include_once 'class-view.php';
     4include_once LSB_PLUGIN_BASE . 'domain/class-stream-summary.php';
    45
    56class LSB_Embedded_Twitch_View extends LSB_View {
    67
    78    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'];
    1011
    1112        $w           = $args['width'];
     
    2122        if ( $show_stream ) {
    2223            $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">'
    2425                . '<param name="allowFullScreen" value="true" />'
    2526                . '<param name="allowScriptAccess" value="always" />'
    2627                . '<param name="allowNetworking" value="all" />'
    2728                . '<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" />'
    2930                . '</object></div>';
    3031        }
Note: See TracChangeset for help on using the changeset viewer.