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