-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp-rss_yandex.php
86 lines (81 loc) · 3.26 KB
/
wp-rss_yandex.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/*
Plugin Name: Yandex RSS2 Export Feed
Plugin URI: http://code.google.com/p/yandex-feed/
Description: Export RSS2 for Yandex
Author: Trinity Solution LLC (coded by Madness), changed for Wordpress 2.6+ by Sherif aka sharof2000 ([email protected]), tweaked for wordpress 3.5+ by Ivan Matveev
Version: 1.4.2
Author URI: http://code.google.com/p/yandex-feed/
*/
if (empty($wp)) {
require_once('wp-config.php');
}
function filter_text($content) {
$content = preg_replace( "/(\[).*?(\])/", "" , $content);
return $content;
}
function get_posts_my($category, $numberposts, $days) {
global $wpdb;
$posts = $wpdb->get_results(
"SELECT * FROM $wpdb->posts p
INNER JOIN $wpdb->term_relationships tr ON (p.ID = tr.object_id)
INNER JOIN $wpdb->term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)
INNER JOIN $wpdb->terms t ON (tt.term_id = t.term_id)
WHERE tt.taxonomy = 'category' AND p.post_type = 'post' AND p.post_status = 'publish' AND t.term_id IN (".$category.")
AND TO_DAYS(NOW()) - TO_DAYS(post_date) <= ".intval($days)."
GROUP BY p.ID ORDER BY p.post_date DESC LIMIT ".intval($numberposts));
return $posts;
}
//header('Content-type: text/xml; charset=' . get_settings('blog_charset'), true);
$options = get_option('rss_yandex_options');
$posts = get_posts_my(implode(',', $options['list_categories']), $options['num_posts'], $options['days']);
$more = 1;
echo '<?xml version="1.0" encoding="'.get_settings('blog_charset').'"?>
'; ?><!-- generator="wordpress/<?php bloginfo_rss('version') ?>" -->
<rss version="2.0" xmlns="http://backend.userland.com/rss2" xmlns:yandex="http://news.yandex.ru">
<channel>
<title><?php echo htmlspecialchars(get_bloginfo_rss('name'),ENT_QUOTES); ?></title>
<link><?php echo htmlspecialchars(get_bloginfo_rss('url'),ENT_QUOTES); ?></link>
<description><?php echo htmlspecialchars(get_bloginfo_rss('description'),ENT_QUOTES); ?></description>
<?php if ($options['image_url'] != "") { ?>
<image>
<url><?php echo htmlspecialchars($options['image_url'],ENT_QUOTES); ?></url>
<title><?php echo htmlspecialchars($options['image_title'],ENT_QUOTES); ?></title>
<link><?php echo htmlspecialchars($options['image_link'],ENT_QUOTES); ?></link>
</image>
<?php } ?>
<?php
if ($posts)
{
foreach ($posts as $post)
{
start_wp();
?>
<item>
<title><?php echo htmlspecialchars(get_the_title_rss(),ENT_QUOTES); ?></title>
<link><?php echo htmlspecialchars(get_permalink(),ENT_QUOTES); ?></link>
<?php
if ($options['description'])
{
$description = filter_text( apply_filters('the_excerpt_rss',get_the_excerpt(true)) );
echo "\n\t\t<description>".$description."</description>\n";
}
echo "<category>".get_the_category_by_ID($post->term_id)."</category>\n";
rss_enclosure(); ?>
<pubDate><?php
$gmt_offset = get_option('gmt_offset');
$gmt_offset = ($gmt_offset>9)?$gmt_offset:('0'.$gmt_offset.'00');
echo mysql2date('D, d M Y H:i:s +'.$gmt_offset, get_date_from_gmt(get_post_time('Y-m-d H:i:s', true)), false); ?></pubDate>
<yandex:full-text><?php
$content = get_the_content('', 0, '');
$content = apply_filters('the_content_rss', $content);
$content = filter_text($content);
echo (htmlspecialchars(strip_tags($content, ENT_QUOTES)));
?></yandex:full-text>
</item>
<?php
}
}
?>
</channel>
</rss>