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; }
static function normalize_guid($guid) { $guid = trim($guid); if (preg_match('/^[0-9a-z]{32}$/i', $guid)) { // MD5 $guid = SyndicatedPost::normalize_guid_prefix() . strtolower($guid); } elseif (strlen(esc_url($guid)) == 0 or esc_url($guid) != $guid) { $guid = SyndicatedPost::normalize_guid_prefix() . md5($guid); } $guid = trim($guid); return $guid; }