PluginProbe
FeedWordPress / 2022.0204
FeedWordPress v2022.0204
trunk 0.8 0.9 0.91 0.95 0.96 0.97 0.98 0.981 0.99 0.991 0.992 0.993 2008.1030 2008.1101 2008.1105 2008.1214 2009.0612 2009.0613 2009.0618 2009.0707 2009.1111 2009.1112 2010.0127 2010.0528 All 65 releases
feedwordpress / syndicationdataqueries.class.php

syndicationdataqueries.class.php in FeedWordPress 2022.0204, at syndicationdataqueries.class.php

117 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class SyndicationDataQueries {
4 public function __construct () {
5 add_action('init', array($this, 'init'));
6 add_action('parse_query', array($this, 'parse_query'), 10, 1);
7 add_filter('posts_search', array($this, 'posts_search'), 10, 2);
8 add_filter('posts_where', array($this, 'posts_where'), 10, 2);
9 add_filter('posts_fields', array($this, 'posts_fields'), 10, 2);
10 add_filter('posts_request', array($this, 'posts_request'), 10, 2);
11 }
12
13 function init () {
14 global $wp;
15 $wp->add_query_var('guid');
16 }
17
18 function parse_query ($q) {
19 if ($q->get('guid')) :
20 $q->is_single = false; // Causes nasty side-effects.
21 $q->is_singular = true; // Doesn't?
22 endif;
23
24 $ff = $q->get('fields');
25 if ($ff == '_synfresh' or $ff == '_synfrom') :
26 $q->query_vars['cache_results'] = false; // Not suitable.
27 endif;
28 } /* SyndicationDataQueries::parse_query () */
29
30 function pre_get_posts ($q) {
31 //
32 }
33
34 function posts_request ($sql, $query) {
35 if ($query->get('fields') == '_synfresh') :
36 FeedWordPress::diagnostic('feed_items:freshness:sql', "SQL: ".$sql);
37 endif;
38 return $sql;
39 }
40
41 function posts_search ($search, $query) {
42 global $wpdb;
43 if ($guid = $query->get('guid')) :
44 if (strlen(trim($guid)) > 0) :
45 $seek = array($guid);
46
47 // MD5 hashes
48 if (preg_match('/^[0-9a-f]{32}$/i', $guid)) :
49 $seek[] = SyndicatedPost::normalize_guid_prefix().$guid;
50 $seek[] = SyndicatedPost::alternative_guid_prefix().$guid;
51 endif;
52
53 // Invalid URIs, URIs that WordPress just doesn't like, and URIs
54 // that WordPress decides to munge.
55 $nGuid = SyndicatedPost::normalize_guid($guid);
56 if ($guid != $nGuid) :
57 $seek[] = $nGuid;
58 $seek[] = SyndicatedPost::alternative_guid($guid);
59 endif;
60
61 // Escape to prevent frak-ups, injections, etc.
62 $seek = array_map('esc_sql', $seek);
63
64 // Assemble
65 $guidMatch = "(guid = '".implode("') OR (guid = '", $seek)."')";
66 $search .= " AND ($guidMatch)";
67 endif;
68 endif;
69
70 if ($query->get('fields')=='_synfresh') :
71 // Ugly hack to ensure we ONLY check by guid in syndicated freshness
72 // checks -- for reasons of both performance and correctness. Pitch:
73 $search .= " -- '";
74 elseif ($query->get('fields')=='_synfrom') :
75 $search .= " AND ({$wpdb->postmeta}.meta_key = '".$query->get('meta_key')."' AND {$wpdb->postmeta}.meta_value = '".$query->get('meta_value')."') -- '";
76 endif;
77 return $search;
78 } /* SyndicationDataQueries::posts_search () */
79
80 function posts_where ($where, $q) {
81 global $wpdb;
82
83 // Ugly hack to ensure we ONLY check by guid in syndicated freshness
84 // checks -- for reasons of both performance and correctness. Catch:
85 if (strpos($where, " -- '") !== false) :
86 $bits = explode(" -- '", $where, 2);
87 $where = $bits[0];
88 endif;
89
90 if ($psn = $q->get('post_status__not')) :
91 $where .= " AND ({$wpdb->posts}.post_status <> '".esc_sql($psn)."')";
92 endif;
93
94 return $where;
95 } /* SyndicationDataQueries::post_where () */
96
97 function posts_fields ($fields, $query) {
98 global $wpdb;
99 if ($f = $query->get('fields')) :
100 switch ($f) :
101 case '_synfresh' :
102 $fields = "{$wpdb->posts}.ID, {$wpdb->posts}.guid, {$wpdb->posts}.post_modified_gmt, {$wpdb->posts}.post_name";
103 break;
104 case '_synfrom' :
105 $fields = "{$wpdb->posts}.ID, {$wpdb->posts}.guid, {$wpdb->posts}.post_title, {$wpdb->postmeta}.meta_value";
106 break;
107 default :
108 // Do nothing.
109 endswitch;
110 endif;
111 return $fields;
112 } /* SyndicationDataQueries::posts_fields () */
113 }
114
115 $SDQ = new SyndicationDataQueries;
116
117