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