Plugin Directory

Changeset 2803561


Ignore:
Timestamp:
10/24/2022 03:49:41 PM (3 years ago)
Author:
VBog
Message:

Version 1.5.1

Location:
bg-rutube-embed
Files:
15 added
2 edited

Legend:

Unmodified
Added
Removed
  • bg-rutube-embed/trunk/bg-rutube.php

    r2801917 r2803561  
    44    Plugin URI: http://bogaiskov.ru/plugin-bg-rutube-embed/
    55    Description: The plugin is the easiest way to embed RuTube videos in WordPress.
    6     Version: 1.5
     6    Version: 1.5.1
    77    Author: VBog
    88    Author URI: http://bogaiskov.ru
     
    3939    die( 'Sorry, you are not allowed to access this page directly.' );
    4040}
    41 define('BG_RUTUBE_VERSION', '1.5');
     41define('BG_RUTUBE_VERSION', '1.5.1');
    4242
    4343// Подключаем CSS и JS
     
    179179    $val = get_option('bg_rutube_options');
    180180    $transient = $val ? $val['transient'] : false;
    181    
    182     while($has_next) {
    183         $key='rutube_playlist_'.$playlist_id.'_'.$page; // Проверяем обновления на RuTube раз в час
    184         if(false===($json=get_transient($key)) || !$transient) {
    185             $url = 'http://rutube.ru/api/playlist/custom/'.$playlist_id.'/videos/?page='.$page;
    186             $result = wp_remote_get ($url,
    187                 [
    188                     'timeout' => 5,
    189                     'httpversion' => '1.1',
    190                     'user-agent'  => 'Mozilla/5.0 (compatible; Rigor/1.0.0; http://rigor.com)',
    191                 ]
    192             );
    193             if( is_wp_error( $result ) ) {
    194                 error_log('Playlist data reading error from '.$playlist_id.' : ('.$result->get_error_code().') '.$result->get_error_message() , 0);
    195                 break;
    196             } elseif( ($errorcode = wp_remote_retrieve_response_code( $result )) === 200 ) {
    197                 $json = wp_remote_retrieve_body($result);
    198                 set_transient( $key, $json, HOUR_IN_SECONDS );
    199             } else {
    200                 error_log($url.'<br>'.'Playlist. Error: '.$errorcode.' - '.wp_remote_retrieve_response_message( $result ) , 0);
    201                 break;
    202             }
    203         }
    204         $videos = json_decode($json, true);
    205 
    206         $page = $videos['page'];
    207         $has_next = $videos['has_next'];
    208         foreach($videos['results'] as $videoData) {
    209             $track['uuid'] = $videoData['id'];
    210             $track['url'] = "https://rutube.ru/video/embed/".$videoData['id']."/";
    211             $track['length'] = $videoData['duration'];
    212             $track['artist'] = "";
    213             $track['title'] = $videoData['title'];
    214             $track['description'] = $videoData['description'];
    215             $track['thumbnail'] = $videoData['thumbnail_url'];
    216             $tracks[] = $track;
    217         }
    218         $page++;
    219     }
    220     if (!empty($tracks)) {
     181    $singular = $val ? $val['singular'] : false;
     182   
     183    if (is_singular() || !$singular) {
     184        while($has_next) {
     185            $key='rutube_playlist_'.$playlist_id.'_'.$page; // Проверяем обновления на RuTube раз в час
     186            if(false===($json=get_transient($key)) || !$transient) {
     187                $url = 'http://rutube.ru/api/playlist/custom/'.$playlist_id.'/videos/?page='.$page;
     188                $result = wp_remote_get ($url,
     189                    [
     190                        'timeout' => 5,
     191                        'httpversion' => '1.1',
     192                        'user-agent'  => 'Mozilla/5.0 (compatible; Rigor/1.0.0; http://rigor.com)',
     193                    ]
     194                );
     195                if( is_wp_error( $result ) ) {
     196                    error_log('Playlist data reading error from '.$playlist_id.' : ('.$result->get_error_code().') '.$result->get_error_message() , 0);
     197                    break;
     198                } elseif( ($errorcode = wp_remote_retrieve_response_code( $result )) === 200 ) {
     199                    $json = wp_remote_retrieve_body($result);
     200                    set_transient( $key, $json, HOUR_IN_SECONDS );
     201                } else {
     202                    error_log($url.'<br>'.'Playlist. Error: '.$errorcode.' - '.wp_remote_retrieve_response_message( $result ) , 0);
     203                    break;
     204                }
     205            }
     206            $videos = json_decode($json, true);
     207
     208            $page = $videos['page'];
     209            $has_next = $videos['has_next'];
     210            foreach($videos['results'] as $videoData) {
     211                $track['uuid'] = $videoData['id'];
     212                $track['url'] = "https://rutube.ru/video/embed/".$videoData['id']."/";
     213                $track['length'] = $videoData['duration'];
     214                $track['artist'] = "";
     215                $track['title'] = $videoData['title'];
     216                $track['description'] = $videoData['description'];
     217                $track['thumbnail'] = $videoData['thumbnail_url'];
     218                $tracks[] = $track;
     219            }
     220            $page++;
     221        }
     222        if (!empty($tracks)) {
     223            $info = bg_rutube_get_playlist_info ( $playlist_id );
     224            $playlist['title'] = $info['title'];
     225            $playlist['description'] = $info['description'];
     226            $playlist['thumbnail'] = $info['thumbnail_url'];
     227            $playlist['count'] = $info['videos_count'];
     228            $playlist['tracks'] = $tracks;
     229           
     230            if (!$playlist['description']) $playlist['description'] = $playlist['title'];
     231        }
     232    } else {
    221233        $info = bg_rutube_get_playlist_info ( $playlist_id );
    222234        $playlist['title'] = $info['title'];
    223235        $playlist['description'] = $info['description'];
    224236        $playlist['thumbnail'] = $info['thumbnail_url'];
    225         $playlist['count'] = $info['videos_count'];;
    226         $playlist['tracks'] = $tracks;
    227        
    228         if (!$playlist['description']) $playlist['description'] = $playlist['title'];
     237        $playlist['count'] = $info['videos_count'];
     238        if (!$playlist['description']) $playlist['description'] = $playlist['title'];           
    229239    }
    230240    return $playlist;
     
    243253    $val = get_option('bg_rutube_options');
    244254    $transient = $val ? $val['transient'] : false;
    245    
    246     foreach ($videoList as $videoID) {
    247         $videoID = strip_tags($videoID);
    248         $videoID = trim($videoID);
    249         $key='rutube_'.$videoID;    // Проверяем обновления на RuTube раз в час
    250         if(false===($json=get_transient($key)) || !$transient) {
    251             $url = 'https://rutube.ru/api/video/'.$videoID;
    252             $result = wp_remote_get ($url,
    253                 [
    254                     'timeout' => 5,
    255                     'httpversion' => '1.1',
    256                     'user-agent'  => 'Mozilla/5.0 (compatible; Rigor/1.0.0; http://rigor.com)',
    257                 ]
    258             );
    259             $json = '';
    260             if( is_wp_error( $result ) ) {
    261                 error_log('Metadata reading error from '.$videoID.' : ('.$result->get_error_code().') '.$result->get_error_message() , 0);
    262             } elseif( ($errorcode = wp_remote_retrieve_response_code( $result )) === 200 ) {
    263                 $json = wp_remote_retrieve_body($result);
    264                 set_transient( $key, $json, HOUR_IN_SECONDS );
     255    $singular = $val ? $val['singular'] : false;
     256   
     257    if (is_singular() || !$singular) {
     258        foreach ($videoList as $videoID) {
     259            $videoID = strip_tags($videoID);
     260            $videoID = trim($videoID);
     261            $key='rutube_'.$videoID;    // Проверяем обновления на RuTube раз в час
     262            if(false===($json=get_transient($key)) || !$transient) {
     263                $url = 'https://rutube.ru/api/video/'.$videoID;
     264                $result = wp_remote_get ($url,
     265                    [
     266                        'timeout' => 5,
     267                        'httpversion' => '1.1',
     268                        'user-agent'  => 'Mozilla/5.0 (compatible; Rigor/1.0.0; http://rigor.com)',
     269                    ]
     270                );
     271                $json = '';
     272                if( is_wp_error( $result ) ) {
     273                    error_log('Metadata reading error from '.$videoID.' : ('.$result->get_error_code().') '.$result->get_error_message() , 0);
     274                } elseif( ($errorcode = wp_remote_retrieve_response_code( $result )) === 200 ) {
     275                    $json = wp_remote_retrieve_body($result);
     276                    set_transient( $key, $json, HOUR_IN_SECONDS );
     277                } else {
     278                    error_log($url.'<br>'.'Metadata. Error: '.$errorcode.' - '.wp_remote_retrieve_response_message( $result ) , 0);
     279                }
     280            }
     281            $videoData = json_decode($json, true);
     282           
     283            if ($videoData) {
     284                $track['uuid'] = $videoID;
     285                $track['url'] = "https://rutube.ru/video/embed/".$videoID."/";
     286                $track['length'] = $videoData['duration'];
     287                $track['artist'] = "";
     288                $track['title'] = $videoData['title'];
     289                $track['description'] = $videoData['description'];
     290                $track['thumbnail'] = $videoData['thumbnail_url'];
     291                $tracks[] = $track;
    265292            } else {
    266                 error_log($url.'<br>'.'Metadata. Error: '.$errorcode.' - '.wp_remote_retrieve_response_message( $result ) , 0);
    267             }
     293                error_log("Metadata. Empty or error answer from RuTube: ". $json." for ".$videoID, 0);
     294            }
     295        }
     296        if (!empty($tracks)) {
     297            $playlist['thumbnail'] = $tracks[0]['thumbnail'];
     298            $playlist['tracks'] = $tracks;
     299            $playlist['count'] = count($tracks);
     300           
     301            if ($playlist['count'] == 1) {
     302                $playlist['title'] = trim($tracks[0]['title']);
     303                $playlist['description'] = trim($tracks[0]['description']);
     304                $playlist['count'] = "";
     305            } else {
     306                $playlist['title'] = $title;
     307                $playlist['description'] = $description;
     308            }
     309           
     310            if (!$playlist['description']) $playlist['description'] = $playlist['title'];
     311        }
     312    } else {
     313        $url = 'https://rutube.ru/api/video/'.$videoList[0];
     314        $result = wp_remote_get ($url,
     315            [
     316                'timeout' => 5,
     317                'httpversion' => '1.1',
     318                'user-agent'  => 'Mozilla/5.0 (compatible; Rigor/1.0.0; http://rigor.com)',
     319            ]
     320        );
     321        $json = '';
     322        if( is_wp_error( $result ) ) {
     323            error_log('Metadata reading error from '.$videoList[0].' : ('.$result->get_error_code().') '.$result->get_error_message() , 0);
     324        } elseif( ($errorcode = wp_remote_retrieve_response_code( $result )) === 200 ) {
     325            $json = wp_remote_retrieve_body($result);
     326        } else {
     327            error_log($url.'<br>'.'Metadata. Error: '.$errorcode.' - '.wp_remote_retrieve_response_message( $result ) , 0);
    268328        }
    269329        $videoData = json_decode($json, true);
    270        
    271330        if ($videoData) {
    272             $track['uuid'] = $videoID;
    273             $track['url'] = "https://rutube.ru/video/embed/".$videoID."/";
    274             $track['length'] = $videoData['duration'];
    275             $track['artist'] = "";
    276             $track['title'] = $videoData['title'];
    277             $track['description'] = $videoData['description'];
    278             $track['thumbnail'] = $videoData['thumbnail_url'];
    279             $tracks[] = $track;
     331            $playlist['thumbnail'] = $videoData['thumbnail_url'];
     332            $playlist['count'] = count($videoList);
     333            if ($playlist['count'] == 1) {
     334                $playlist['title'] = trim($videoData['title']);
     335                $playlist['description'] = trim($videoData['description']);
     336                $playlist['count'] = "";
     337            } else {
     338                $playlist['title'] = $title;
     339                $playlist['description'] = $description;
     340            }
     341            if (!$playlist['description']) $playlist['description'] = $playlist['title'];           
    280342        } else {
    281             error_log("Metadata. Empty or error answer from RuTube: ". $json." for ".$videoID, 0);
    282         }
    283     }
    284     if (!empty($tracks)) {
    285         $playlist['thumbnail'] = $tracks[0]['thumbnail'];
    286         $playlist['tracks'] = $tracks;
    287         $playlist['count'] = count($tracks);
    288        
    289         if ($playlist['count'] == 1) {
    290             $playlist['title'] = trim($tracks[0]['title']);
    291             $playlist['description'] = trim($tracks[0]['description']);
    292             $playlist['count'] = "";
    293         } else {
    294             $playlist['title'] = $title;
    295             $playlist['description'] = $description;
    296         }
    297        
    298         if (!$playlist['description']) $playlist['description'] = $playlist['title'];
     343            error_log("Metadata. Empty or error answer from RuTube: ". $json." for ".$videoList[0], 0);
     344        }
     345       
    299346    }
    300347    return $playlist;
  • bg-rutube-embed/trunk/readme.txt

    r2801948 r2803561  
    77Requires at least: 3.0.1
    88Tested up to: 6.0.3
    9 Stable tag: 1.5
     9Stable tag: 1.5.1
    1010License: GPLv2
    1111License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    4949
    5050== Changelog ==
     51
     52= 1.5.1 =
     53
     54* Performance has been improved.
    5155
    5256= 1.5 =
Note: See TracChangeset for help on using the changeset viewer.