- Statut : non résolu
- Ce sujet contient 5 réponses, 3 participants et a été mis à jour pour la dernière fois par koz, le il y a 18 années et 5 mois.
-
AuteurMessages
-
5 juin 2006 à 17 h 33 min #447818
Hello. Je viens d’installer un plugin intéressant : landingsites, qui affiche un message plus une liste de suggestion de billets aux personnes accédant à votre blog via un moteur de recherche. Pour plus de clarté, vous pouvez essayer en cliquant là : http://www.google.fr/search?hl=fr&q=fouette-moi+s%C3%A9gol%C3%A8ne&btnG=Recherche+Google&meta=
Et en ouvrant le premier résultat (koztoujours). Le message ne s’affiche QUE si l’on vient d’un moteur de recherche.
Bon.
Ma question maintenant : comment ajouter un moteur de recherche ? Il fonctionne en effet bien avec google, mais pas avec yahoo. A ce que je comprends, mais je n’ai aucune formation dans le domaine, je coince sur la query string … J’ai bien cru que j’avais trouvé, en observant ce qui figure dans le code et l’url sur yahoo mais nada…
Si vous avez une idée…
A tout hasard, je vous file le code :
<?php
/*
Plugin Name: Landing sites
Plugin URI: http://theundersigned.net
Description: When visitors is referred to your site from a search engine, they are definitely looking for something specific - often they just roughly check the page they land on and then closes the window if what they are looking for isn't there. Why not help them by showing them related posts to their search on your blog? This plugin/guide lets you do that, works with a long list of search engines! Plugin is made with help from these scripts: http://www.w-a-s-a-b-i.com/archives/2006/02/02/wordpress-related-entries-20/ - http://textsnippets.com/posts/show/231 - http://www.lazaryn.com/entry-28.html
Version: 1.2
Author: The undersigned
*/
function ls_related($limit=5, $len=10, $before_title = '', $after_title = '', $before_post = '', $after_post = '', $show_pass_post = false, $show_excerpt = false) {
global $wpdb;
// Setup
$referer = $_SERVER['HTTP_REFERER'];
$engine = false;
$query = null;
$query_array = array();
$query_terms = null;
// Remove protocol from start of string
$referer = explode('//', $referer);
if(isset($referer[1]))
$referer = $referer[1];
else
$referer = $referer[0];
// Remove www. is it exists
if(substr($referer, 0, 4) == 'www.')
$referer = substr($referer, 4);
// Optimizations
$sub7 = substr($referer, 0, 7);
$sub9 = substr($referer, 0, 9);
$sub10 = substr($referer, 0, 10);
$sub11 = substr($referer, 0, 11);
$sub12 = substr($referer, 0, 12);
$sub13 = substr($referer, 0, 13);
$sub14 = substr($referer, 0, 14);
$sub15 = substr($referer, 0, 15);
$sub16 = substr($referer, 0, 16);
$sub17 = substr($referer, 0, 17);
$sub19 = substr($referer, 0, 19);
$sub20 = substr($referer, 0, 20);
$sub23 = substr($referer, 0, 23);
$sub24 = substr($referer, 0, 24);
// Search string for engine
if($sub7 == 'google.')
$engine = 'google';
elseif($sub13 == 'search.atomz.')
$engine = 'atomz';
elseif($sub11 == 'search.msn.')
$engine = 'msn';
elseif($sub13 == 'search.yahoo.')
$engine = 'yahoo';
elseif($sub16 == 'msxml.excite.com')
$engine = 'excite';
elseif($sub16 == 'search.lycos.com')
$engine = 'lycos';
elseif($sub13 == 'alltheweb.com')
$engine = 'alltheweb';
elseif($sub14 == 'search.aol.com')
$engine = 'aol';
elseif($sub15 == 'search.iwon.com')
$engine = 'iwon';
elseif($sub7 == 'ask.com')
$engine = 'ask';
elseif($sub23 == 'search.cometsystems.com')
$engine = 'cometsystems';
elseif($sub10 == 'hotbot.com')
$engine = 'hotbot';
elseif($sub12 == 'overture.com')
$engine = 'overture';
elseif($sub15 == 'metacrawler.com')
$engine = 'metacrawler';
elseif($sub19 == 'search.netscape.com')
$engine = 'netscape';
elseif($sub13 == 'looksmart.com')
$engine = 'looksmart';
elseif($sub13 == 'go.google.com')
$engine = 'gogoogle';
elseif($sub20 == 'dpxml.webcrawler.com')
$engine = 'webcrawler';
elseif($sub20 == 'search.earthlink.net')
$engine = 'earthlink';
elseif($sub20 == 'search.viewpoint.com')
$engine = 'viewpoint';
elseif($sub9 == 'mamma.com')
$engine = 'mamma';
elseif($sub9 == 'ask.co.uk')
$engine = 'askcouk';
elseif($sub24 == 'fr.search.yahoo.com')
$engine = 'yahoo';
elseif(preg_match('/home.bellsouth.net/s/s.dll/i', $referer))
$engine = 'bellsouth';
// Did we come from a search engine?
if($engine)
{
// Find out the query string location depending on the engine used
if( $engine == 'google'
|| $engine == 'msn'
|| $engine == 'alltheweb'
|| $engine == 'ask'
|| $engine == 'gogoogle'
|| $engine == 'earthlink')
$delimiter = "q";
elseif($engine == 'askcouk')
$delimiter = "ask";
elseif($engine == 'atomz')
$delimiter = "sp-q";
elseif($engine == 'yahoo'
|| $engine == 'fr.yahoo')
$delimiter = "p";
elseif($engine == 'excite'
|| $engine == 'metacrawler'
|| $engine == 'webcrawler')
$delimiter = "qkw";
elseif($engine == 'lycos'
|| $engine == 'aol'
|| $engine == 'hotbot'
|| $engine == 'netscape'
|| $engine == 'mamma')
$delimiter = "query";
elseif($engine == 'iwon')
$delimiter = "searchfor";
elseif($engine == 'cometsystems')
$delimiter = "qry";
elseif($engine == 'overture')
$delimiter = "Keywords";
elseif($engine == 'looksmart')
$delimiter = "key";
elseif($engine == 'viewpoint')
$delimiter = "k";
elseif($engine == 'bellsouth')
$delimiter = "string";
// Get raw query
$query = explode($delimiter.'=', $referer);
$query = explode('&', $query[1]);
$query = urldecode($query[0]);
//-------------------------
// Data has been retrieved
//-------------------------
// Additional processing
// Remove single quotes
$query = str_replace("'", '', $query);
// Remove double quotes
$query = str_replace('"', '', $query);
// Split into words
$query_array = preg_split('/[s,+.]+/',$query);
// Make single string
$query_terms = implode(' ', $query_array);
// Format for HTML display
$terms = htmlspecialchars(urldecode($query_terms));
$time_difference = get_settings('gmt_offset');
$now = gmdate("Y-m-d H:i:s",(time()+($time_difference*3600)));
// Primary SQL query
$sql = "SELECT ID, post_title, post_content,"
. "MATCH (post_name, post_content) "
. "AGAINST ('$terms') AS score "
. "FROM $wpdb->posts WHERE »
. « MATCH (post_name, post_content) »
. « AGAINST (‘$terms’) »
. « AND post_date <= '$now' "
. "AND (post_status IN ( 'publish', 'static' )) ";
if ($show_pass_post=='false') { $sql .= "AND post_password ='' "; }
$sql .= "ORDER BY score DESC LIMIT $limit";
$results = $wpdb->get_results($sql);
$output = »;
if ($results) {
foreach ($results as $result) {
$title = stripslashes(apply_filters(‘the_title’, $result->post_title));
$permalink = get_permalink($result->ID);
$post_content = strip_tags($result->post_content);
$post_content = stripslashes($post_content);
$output .= $before_title .’<a href="'. $permalink .'" rel="bookmark" title="Permanent Link: ' . $title . '">‘ . $title . ‘</a>‘ . $after_title;
if ($show_excerpt==’true’) {
$words=split( » « ,$post_content);
$post_strip = join( » « , array_slice($words,0,$len));
$output .= $before_post . $post_strip . $after_post;
}
}
echo $output;
} else {
echo $before_title.’No related posts’.$after_title;
}
}
}
// Return true if the referer is a search engine
function ls_getinfo($what) {
// Setup
$referer = $_SERVER[‘HTTP_REFERER’];
$engine = false;
$query = null;
$query_array = array();
$query_terms = null;
// Remove protocol from start of string
$referer = explode(‘//’, $referer);
if(isset($referer[1]))
$referer = $referer[1];
else
$referer = $referer[0];
// Remove www. is it exists
if(substr($referer, 0, 4) == ‘www.’)
$referer = substr($referer, 4);
// Optimizations
$sub7 = substr($referer, 0, 7);
$sub9 = substr($referer, 0, 9);
$sub10 = substr($referer, 0, 10);
$sub11 = substr($referer, 0, 11);
$sub12 = substr($referer, 0, 12);
$sub13 = substr($referer, 0, 13);
$sub14 = substr($referer, 0, 14);
$sub15 = substr($referer, 0, 15);
$sub16 = substr($referer, 0, 16);
$sub17 = substr($referer, 0, 17);
$sub19 = substr($referer, 0, 19);
$sub20 = substr($referer, 0, 20);
$sub23 = substr($referer, 0, 23);
$sub24 = substr($referer, 0, 24);
// Search string for engine
if($sub7 == ‘google.’)
$engine = ‘google’;
elseif($sub13 == ‘search.atomz.’)
$engine = ‘atomz’;
elseif($sub11 == ‘search.msn.’)
$engine = ‘msn’;
elseif($sub13 == ‘search.yahoo.’)
$engine = ‘yahoo’;
elseif($sub16 == ‘msxml.excite.com’)
$engine = ‘excite’;
elseif($sub16 == ‘search.lycos.com’)
$engine = ‘lycos’;
elseif($sub13 == ‘alltheweb.com’)
$engine = ‘alltheweb’;
elseif($sub14 == ‘search.aol.com’)
$engine = ‘aol’;
elseif($sub15 == ‘search.iwon.com’)
$engine = ‘iwon’;
elseif($sub7 == ‘ask.com’)
$engine = ‘ask’;
elseif($sub23 == ‘search.cometsystems.com’)
$engine = ‘cometsystems’;
elseif($sub10 == ‘hotbot.com’)
$engine = ‘hotbot’;
elseif($sub12 == ‘overture.com’)
$engine = ‘overture’;
elseif($sub15 == ‘metacrawler.com’)
$engine = ‘metacrawler’;
elseif($sub19 == ‘search.netscape.com’)
$engine = ‘netscape’;
elseif($sub13 == ‘looksmart.com’)
$engine = ‘looksmart’;
elseif($sub13 == ‘go.google.com’)
$engine = ‘gogoogle’;
elseif($sub20 == ‘dpxml.webcrawler.com’)
$engine = ‘webcrawler’;
elseif($sub20 == ‘search.earthlink.net’)
$engine = ‘earthlink’;
elseif($sub20 == ‘search.viewpoint.com’)
$engine = ‘viewpoint’;
elseif($sub9 == ‘mamma.com’)
$engine = ‘mamma’;
elseif($sub9 == ‘ask.co.uk’)
$engine = ‘askcouk’;
elseif($sub24 == ‘fr.search.yahoo.com’)
$engine = ‘yahoo.fr’;
elseif(preg_match(‘/home.bellsouth.net/s/s.dll/i’, $referer))
$engine = ‘bellsouth’;
// Did we come from a search engine?
if($engine)
{
// Find out the query string location depending on the engine used
if( $engine == ‘google’
|| $engine == ‘msn’
|| $engine == ‘alltheweb’
|| $engine == ‘ask’
|| $engine == ‘gogoogle’
|| $engine == ‘earthlink’)
$delimiter = « q »;
elseif($engine == ‘askcouk’)
$delimiter = « ask »;
elseif($engine == ‘atomz’)
$delimiter = « sp-q »;
elseif($engine == ‘yahoo’)
$delimiter = « p »;
elseif($engine == ‘excite’
|| $engine == ‘metacrawler’
|| $engine == ‘webcrawler’)
$delimiter = « qkw »;
elseif($engine == ‘lycos’
|| $engine == ‘aol’
|| $engine == ‘hotbot’
|| $engine == ‘netscape’
|| $engine == ‘mamma’)
$delimiter = « query »;
elseif($engine == ‘iwon’)
$delimiter = « searchfor »;
elseif($engine == ‘cometsystems’)
$delimiter = « qry »;
elseif($engine == ‘overture’)
$delimiter = « Keywords »;
elseif($engine == ‘looksmart’)
$delimiter = « key »;
elseif($engine == ‘viewpoint’)
$delimiter = « k »;
elseif($engine == ‘bellsouth’)
$delimiter = « string »;
elseif($engine == ‘fr.yahoo’)
$delimiter = « p »;
// Get raw query
$query = explode($delimiter.’=’, $referer);
$query = explode(‘&’, $query[1]);
$query = urldecode($query[0]);
//————————-
// Data has been retrieved
//————————-
// Additional processing
// Remove single quotes
$query = str_replace(« ‘ », », $query);
// Remove double quotes
$query = str_replace(‘ »‘, », $query);
// Split into words
$query_array = preg_split(‘/[s,+.]+/’,$query);
// Make single string
$query_terms = implode(‘ ‘, $query_array);
// Format for HTML display
$terms = htmlspecialchars(urldecode($query_terms));
if($what == ‘isref’) { return true; }
if($what == ‘referrer’) {
$parsed = parse_url($referer);
echo ‘<a href="http://'.$parsed['host'].'">‘.$parsed[‘host’].’</a>‘;
}
if($what == ‘terms’) { echo $terms; }
}
}
function ls_install() {
global $wpdb;
global $table_prefix;
$sql = ‘ALTER TABLE `’.$table_prefix.’posts` ADD FULLTEXT `post_related` ( `post_name` ,’
. ‘ `post_content` )’;
$wpdb->hide_errors();
$sql_result = $wpdb->query($sql);
$wpdb->show_errors();
}
register_activation_hook(__FILE__, ‘ls_install’);
?>5 juin 2006 à 17 h 58 min #574939Précision, c’est sur yahoo.fr que ça ne fonctionne pas (ça fonctionne sur version .com)
6 juin 2006 à 11 h 58 min #574940Les URLs de résultat Yahoo.fr prennent cette forme :
http://fr.search.yahoo.com/search?fr=fp-tab-web-t-1&ei=ISO-8859-1&p=lapin&meta=vc%3D
Donc rajoute ça à la partie « Search string for engine » de ton codeelseif($sub13 == ‘fr.search.yahoo.’)
$engine = ‘fr.yahoo’;6 juin 2006 à 12 h 02 min #574941mince Xavier a été plus rapide
6 juin 2006 à 12 h 34 min #574942Oups, j’ai oublié de dire qu’on m’avait donné un coup de main par ailleurs…
Tu ne comptes pas les points, Xavier ?Bon, sinon, le plugin n’a pas l’air super au point : il en est déjà à sa troisième version en deux jours et deux commentateurs l’ont en partie refait, estimant qu’il n’était pas optimisé etc etc (d’ailleurs le développeur se vexe pas, il est de bonne composition).
Alors qu’il fonctionnait parfaitement, j’ai fait une modif qui l’a planté, et même en remettant tout le code d’origine, je ne m’ensuis pas sorti… Alors, évolution pour évolution, j’attends un peu que le plugin soit davantage finalisé.
Merci en tout cas pour le coup de main !
6 juin 2006 à 15 h 09 min #574943Landing sites en est à sa version 1.3, dont le code est beaucoup plus facile à maîtriser pour un néophyte.
Pour ceux que cela intéresse, et qui veulent intégrer de smoteurs français, j’ai ajouté yahoo et mozbot, en insérant :‘fr.search.yahoo.com’ => ‘p’,
‘mozbot.fr’ => ‘q’,Rien de plus à faire. Et le mieux, c’est que ça fonctionne. Si, si !
-
AuteurMessages
- Vous devez être connecté pour répondre à ce sujet.