function posts_search($search, &$query) { global $wpdb; if ($guid = $query->get('guid')) { if (strlen(trim($guid)) > 0) { $seek = array($guid); // MD5 hashes if (preg_match('/^[0-9a-f]{32}$/i', $guid)) { $seek[] = SyndicatedPost::normalize_guid_prefix() . $guid; } // Invalid URIs, URIs that WordPress just doesn't like, and URIs // that WordPress decides to munge. $nGuid = SyndicatedPost::normalize_guid($guid); if ($guid != $nGuid) { $seek[] = $nGuid; } // Escape to prevent frak-ups, injections, etc. $seek = array_map('esc_sql', $seek); // Assemble $guidMatch = "(guid = '" . implode("') OR (guid = '", $seek) . "')"; $search .= " AND ({$guidMatch})"; } } if ($query->get('fields') == '_synfresh') { // Ugly hack to ensure we ONLY check by guid in syndicated freshness // checks -- for reasons of both performance and correctness. Pitch: $search .= " -- '"; } elseif ($query->get('fields') == '_synfrom') { $search .= " AND ({$wpdb->postmeta}.meta_key = '" . $query->get('meta_key') . "' AND {$wpdb->postmeta}.meta_value = '" . $query->get('meta_value') . "') -- '"; } return $search; }
/** * SyndicatedPost::normalize_post() * * @param bool $new If true, this post is to be inserted anew. If false, it is an update of an existing post. * @return array A normalized representation of the post ready to be inserted into the database or sent to the WordPress API functions */ function normalize_post($new = true) { global $wpdb; $out = $this->post; $fullPost = $out['post_title'] . $out['post_content']; $fullPost .= isset($out['post_excerpt']) ? $out['post_excerpt'] : ''; if (strlen($fullPost) < 1) { // FIXME: Option for filtering out empty posts } if (strlen($out['post_title']) == 0) { $offset = (int) get_option('gmt_offset') * 60 * 60; if (isset($this->post['meta']['syndication_source'])) { $source_title = $this->post['meta']['syndication_source']; } else { $feed_url = parse_url($this->post['meta']['syndication_feed']); $source_title = $feed_url['host']; } $out['post_title'] = $source_title . ' ' . gmdate('Y-m-d H:i:s', $this->published() + $offset); // FIXME: Option for what to fill a blank title with... } // Normalize the guid if necessary. $out['guid'] = SyndicatedPost::normalize_guid($out['guid']); return $out; }