Plugin Directory

Changeset 1266778


Ignore:
Timestamp:
10/15/2015 05:58:42 PM (10 years ago)
Author:
foralien
Message:

YouTube thumbnails and Video support fix

Location:
yandexnews-feed-by-teplitsa/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • yandexnews-feed-by-teplitsa/trunk/inc/feed.php

    r1207288 r1266778  
    99echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?>';
    1010?>
    11 <rss xmlns:yandex="http://news.yandex.ru" xmlns:media
    12 ="http://search.yahoo.com/mrss/" version="2.0">
     11<rss xmlns:yandex="http://news.yandex.ru" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    1312<channel>
    1413<title><?php bloginfo_rss('name');?></title>
     
    5150<enclosure url="<?php echo esc_url($img['url']);?>" type="<?php echo esc_attr($img['mime']);?>"/>
    5251<?php endforeach; endif;?>
    53 <?php //media group
    54     $media = La_Yandex_Feed_Core::item_media();
    55     if(!empty($media)): foreach($media as $media_obj) :
     52<?php
     53    $media = La_Yandex_Feed_Core::item_media();
     54    if(!empty($media)):
     55    //media group
    5656?>
    5757<media:group>
     58<?php foreach($media as $media_obj):?>
     59<media:content url="<?php echo esc_url($media_obj['url']);?>">
    5860<media:player url="<?php echo esc_url($media_obj['url']);?>" />
    5961<?php if(!empty($media_obj['thumb'])) { ?>
    6062<media:thumbnail url="<?php echo esc_url($media_obj['thumb']);?>"/>
    6163<?php }?>
     64</media:content>
     65<?php endforeach; ?>
    6266</media:group>
     67<?php endif;?>
    6368<?php
    64     endforeach; endif;
    6569    $related = La_Yandex_Feed_Core::item_related();
    6670    if(!empty($related)):
  • yandexnews-feed-by-teplitsa/trunk/inc/tst-yandex-feed-core.php

    r1207288 r1266778  
    186186       
    187187   
    188     /** formatting */       
     188    /** formatting */
    189189    function full_text_formatting($text){
    190190   
     
    207207        return self::_valid_characters($text);
    208208    }
    209 
     209   
    210210    static function _valid_characters($text) {
    211211       
     
    253253        }
    254254       
    255         $out = do_shortcode($post->post_content);
    256         //preg_match_all('!http://.+\.(?:jpe?g|png|gif)!Ui' , $out , $matches);
    257         preg_match_all('!<img(.*)src(.*)=(.*)"(.*)"!U', $out, $matches);
    258            
    259         if(isset($matches[4]) && !empty($matches)){
    260             $enclosure = array_merge($enclosure, $matches[4]);
    261         }
     255        $out = do_shortcode($post->post_content);
     256        if(preg_match('/youtube\.com/', $post->post_content) || preg_match('/youtu\.be/', $post->post_content)) {
     257            preg_match_all('#\bhttps?://[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/))#', $post->post_content, $urls_match);
     258            if($urls_match && count($urls_match) && $urls_match[0]) {
     259                foreach($urls_match[0] as $url) {
     260                    $thumbnail_url = self::get_youtube_thumbnail_url($url);
     261                    if($thumbnail_url) {
     262                        $enclosure[] = $thumbnail_url;
     263                    }
     264                }
     265            }
     266        }
     267        else {
     268            //preg_match_all('!http://.+\.(?:jpe?g|png|gif)!Ui' , $out , $matches);
     269            preg_match_all('!<img(.*)src(.*)=(.*)"(.*)"!U', $out, $matches);
     270            if(isset($matches[4]) && !empty($matches)){
     271                $enclosure = array_merge($enclosure, $matches[4]);
     272            }
     273        }
    262274       
    263275        if(empty($enclosure))
     
    314326        $return = array();
    315327        if(!empty($res)){ foreach($res as $i => $url) {
    316             $return[] = array('url' => $url, 'thumb' => '');
     328            $thumbnail_url = self::get_youtube_thumbnail_url($url);
     329            $return[] = array('url' => $url, 'thumb' => $thumbnail_url);
    317330        }}
    318331       
     
    388401        $category = apply_filters('layf_category', $category, get_the_ID());
    389402        return $category;
     403    }
     404   
     405    static function get_youtube_thumbnail_url($url) {
     406        $ret = '';
     407        if(preg_match('/youtube\.com/', $url) || preg_match('/youtu\.be/', $url)) {
     408            preg_match("#(?<=vi\/)[^&\n]+|(?<=v\/)[^&\n]+|(?<=user\/)[^&\n]+|(?<=embed\/)[^&\n]+|(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v\/)[^&\n]+(?=\?)|(?<=v=)[^&\n]+|(?<=youtu.be/)[^&\n]+#", $url, $youtube_id_matches);
     409            if($youtube_id_matches && count($youtube_id_matches)) {
     410                $youtube_video_id = $youtube_id_matches[0];
     411                $ret = 'https://img.youtube.com/vi/' . $youtube_video_id . '/1.jpg';
     412            }
     413        }
     414        return $ret;
    390415    }
    391416   
  • yandexnews-feed-by-teplitsa/trunk/readme.txt

    r1207288 r1266778  
    33Tags: yandex,news,xml,rss,seo,Yandex.News
    44Requires at least: 3.9
    5 Tested up to: 4.2.3
     5Tested up to: 4.3.1
    66Stable tag: trunk
    77License: GPLv2 or later
     
    105105== Changelog ==
    106106
     107= 1.8.4 =
     108* New: Youtube video thumbnails added
     109* Fix: media:group structure optimized
     110
    107111= 1.8.3 =
    108112* Fix: Minor fixes and updates for feed content
  • yandexnews-feed-by-teplitsa/trunk/tst-yandex-feed.php

    r1207288 r1266778  
    33Plugin Name: Yandex.News Feed by Teplitsa
    44Description: The plugin creates feed for Yandex.News service
    5 Version: 1.8.3
     5Version: 1.8.4
    66Author: Teplitsa
    77Author URI: http://te-st.ru/
     
    3838// Plugin version:
    3939if( !defined('LAYF_VERSION') )
    40     define('LAYF_VERSION', '1.8.2');
     40    define('LAYF_VERSION', '1.8.4');
    4141   
    4242// Plugin DIR, with trailing slash:
Note: See TracChangeset for help on using the changeset viewer.