Plugin Directory

Changeset 1207288


Ignore:
Timestamp:
07/27/2015 08:30:16 AM (11 years ago)
Author:
foralien
Message:

Updates to feed content and category handling

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

Legend:

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

    r1138436 r1207288  
    4141<?php endif;?>
    4242<?php
    43     $category_tax = apply_filters('layf_category_taxonomy', 'category', get_the_ID());
    44     $category = wp_get_object_terms(get_the_ID(), $category_tax);
    45     if(count($category) > 1 && $category[0]->slug == 'uncategorized')
    46         $category = $category[1]->name;
    47     else
    48         $category = $category ? reset($category)->name : '-';
    49 
    50     $category = apply_filters('layf_category', $category, get_the_ID());
     43    $category = La_Yandex_Feed_Core::get_proper_category(get_the_ID());
    5144    if($category) :?>
    5245<category><?php echo $category;?></category>
  • yandexnews-feed-by-teplitsa/trunk/inc/tst-yandex-feed-core.php

    r1182631 r1207288  
    1212        add_action('template_redirect', array($this, 'custom_templates_redirect'));
    1313        add_action('parse_query', array($this, 'custom_request'));
     14        add_filter( 'status_header', array($this, 'set_empty_feed_20ok_status'), 10, 2 );
     15
    1416               
    1517        /* formatting */
     
    3032       
    3133    }
    32        
    33        
     34   
     35    public function set_empty_feed_20ok_status($status_header, $header) {
     36        global $wp_query;
     37        $qv = get_query_var('yandex_feed');
     38        if('news' == $qv){
     39            if((int) $header == 404) {
     40                return status_header( 200 );
     41            }
     42        }
     43        return $status_header;         
     44    }
     45   
    3446    /** instance */
    3547    public static function get_instance(){
     
    146158       
    147159    }
    148    
     160
    149161    public function custom_templates_redirect(){
    150162        global $wp_query;
     
    176188    /** formatting */       
    177189    function full_text_formatting($text){
     190   
     191        $pattern = '\[(\[?)(embed|wp_caption|caption|gallery|playlist|audio|video)(?![\w-])([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)';
     192        $text = preg_replace_callback( "/$pattern/s", 'strip_shortcode_tag', $text );
     193       
    178194        global $wp_query;
    179195       
     
    186202        $text = preg_replace('/\s\s+/', ' ', $text);
    187203        $text = preg_replace('/(\r|\n|\r\n){3,}/', '', $text);
     204       
     205       
    188206       
    189207        return self::_valid_characters($text);
     
    230248       
    231249        $enclosure = $matches = $res = array();
     250        $thumb_id = get_post_thumbnail_id($post->ID);
     251        if(!empty($thumb_id)){
     252            $enclosure[0] = wp_get_attachment_url($thumb_id);
     253        }
     254       
    232255        $out = do_shortcode($post->post_content);
    233256        //preg_match_all('!http://.+\.(?:jpe?g|png|gif)!Ui' , $out , $matches);
    234257        preg_match_all('!<img(.*)src(.*)=(.*)"(.*)"!U', $out, $matches);
    235258           
    236        
    237         if(!isset($matches[4]) || empty($matches)){
    238             $thumb_id = get_post_thumbnail_id($post->ID);
    239             if(!empty($thumb_id)){
    240                 $enclosure[0] = wp_get_attachment_url($thumb_id);
    241             }
    242         }
    243         else {
    244             $enclosure = $matches[4];
     259        if(isset($matches[4]) && !empty($matches)){
     260            $enclosure = array_merge($enclosure, $matches[4]);
    245261        }
    246262       
     
    332348       
    333349        return $links;
     350    }
     351   
     352    static function get_proper_category($post_id) {
     353        $terms = get_option('layf_filter_terms', '');           
     354        $filter_tax = '';
     355        if(!empty($terms)){
     356            $filter_tax = $tax = get_option('layf_filter_taxonomy', 'category');
     357            $terms = array_map('intval', explode(',', $terms));
     358            $query->query_vars['tax_query'][] = array(
     359                'taxonomy' => $tax,
     360                'field' => 'id',
     361                'terms' => $terms
     362            );
     363        }
     364   
     365        $category_tax = apply_filters('layf_category_taxonomy', 'category', $post_id);
     366        $category = wp_get_object_terms($post_id, $category_tax);
     367       
     368        $category_name = '';
     369        if($filter_tax && $filter_tax == $category_tax && is_array($category) && !empty($terms)) {
     370            foreach($category as $cat) {
     371                if(array_search($cat->term_id, $terms) !== false && $cat->slug != 'uncategorized') {
     372                    $category_name = $cat->name;
     373                    break;
     374                }
     375            }
     376        }
     377       
     378        if(empty($category_name)) {
     379            if(count($category) > 1 && $category[0]->slug == 'uncategorized')
     380                $category = $category[1]->name;
     381            else
     382                $category = $category ? reset($category)->name : '-';
     383        }
     384        else {
     385            $category = $category_name;
     386        }
     387
     388        $category = apply_filters('layf_category', $category, get_the_ID());
     389        return $category;
    334390    }
    335391   
  • yandexnews-feed-by-teplitsa/trunk/readme.txt

    r1182631 r1207288  
    33Tags: yandex,news,xml,rss,seo,Yandex.News
    44Requires at least: 3.9
    5 Tested up to: 4.2.2
     5Tested up to: 4.2.3
    66Stable tag: trunk
    77License: GPLv2 or later
     
    105105== Changelog ==
    106106
     107= 1.8.3 =
     108* Fix: Minor fixes and updates for feed content
     109
    107110= 1.8.2 =
    108111* Fix: Minor fixes and updated for admin settings
  • yandexnews-feed-by-teplitsa/trunk/tst-yandex-feed.php

    r1182631 r1207288  
    33Plugin Name: Yandex.News Feed by Teplitsa
    44Description: The plugin creates feed for Yandex.News service
    5 Version: 1.8.2
     5Version: 1.8.3
    66Author: Teplitsa
    77Author URI: http://te-st.ru/
Note: See TracChangeset for help on using the changeset viewer.