Après cette longue sélection de données, nous avons trouvé la réponse à cette inconnue que certains de nos lecteurs présentent. Nous vous donnons la réponse et nous espérons qu'elle sera très encourageante.
Récupère un pingback et l'enregistre.
Paramètres
- $args
-
(tableau)(Obligatoire)Arguments de la méthode. Remarque : les arguments doivent être ordonnés comme indiqué dans la documentation.
- 'pagelinkedfrom'
(chaîne de caractères) - page liée à
(chaîne de caractères)
- 'pagelinkedfrom'
Retourner
(chaîne de caractères|IXR_Error)
Source
Fichier : wp-includes/class-wp-xmlrpc-server.php
publicfunctionpingback_ping($args){global$wpdb;/** This action is documented in wp-includes/class-wp-xmlrpc-server.php */do_action('xmlrpc_call','pingback.ping',$args,$this);$this->escape($args);$pagelinkedfrom=str_replace('&','&',$args[0]);$pagelinkedto=str_replace('&','&',$args[1]);$pagelinkedto=str_replace('&','&',$pagelinkedto);/** * Filters the pingback source URI. * * @since 3.6.0 * * @param string $pagelinkedfrom URI of the page linked from. * @param string $pagelinkedto URI of the page linked to. */$pagelinkedfrom=apply_filters('pingback_ping_source_uri',$pagelinkedfrom,$pagelinkedto);if(!$pagelinkedfrom){return$this->pingback_error(0,__('A valid URL was not provided.'));}// Check if the page linked to is on our site.$pos1=strpos($pagelinkedto,str_replace(array('http://www.','http://','https://www.','https://'),'',get_option('home')));if(!$pos1){return$this->pingback_error(0,__('Is there no link to us?'));}/* * Let's find which post is linked to. * FIXME: Does url_to_postid() cover all these cases already? * If so, then let's use it and drop the old code. */$urltest=parse_url($pagelinkedto);$post_ID=url_to_postid($pagelinkedto);if($post_ID){// $way}elseif(isset($urltest['path'])&&preg_match('#p/[0-9]{1,}#',$urltest['path'],$match)){// The path defines the post_ID (archives/p/XXXX).$blah=explode('/',$match[0]);$post_ID=(int)$blah[1];}elseif(isset($urltest['query'])&&preg_match('#p=[0-9]{1,}#',$urltest['query'],$match)){// The query string defines the post_ID (?p=XXXX).$blah=explode('=',$match[0]);$post_ID=(int)$blah[1];}elseif(isset($urltest['fragment'])){// An #anchor is there, it's either...if((int)$urltest['fragment']){// ...an integer #XXXX (simplest case),$post_ID=(int)$urltest['fragment'];}elseif(preg_match('/post-[0-9]+/',$urltest['fragment'])){// ...a post ID in the form 'post-###',$post_ID=preg_replace('/[^0-9]+/','',$urltest['fragment']);}elseif(is_string($urltest['fragment'])){// ...or a string #title, a little more complicated.$title=preg_replace('/[^a-z0-9]/i','.',$urltest['fragment']);$sql=$wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_title RLIKE %s",$title);$post_ID=$wpdb->get_var($sql);if(!$post_ID){// Returning unknown error '0' is better than die()'ing.return$this->pingback_error(0,'');}}}else{// TODO: Attempt to extract a post ID from the given URL.return$this->pingback_error(33,__('The specified target URL cannot be used as a target. It either doesn’t exist, or it is not a pingback-enabled resource.'));}$post_ID=(int)$post_ID;$post=get_post($post_ID);if(!$post){// Post not found.return$this->pingback_error(33,__('The specified target URL cannot be used as a target. It either doesn’t exist, or it is not a pingback-enabled resource.'));}if(url_to_postid($pagelinkedfrom)==$post_ID){return$this->pingback_error(0,__('The source URL and the target URL cannot both point to the same resource.'));}// Check if pings are on.if(!pings_open($post)){return$this->pingback_error(33,__('The specified target URL cannot be used as a target. It either doesn’t exist, or it is not a pingback-enabled resource.'));}// Let's check that the remote site didn't already pingback this entry.if($wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_author_url = %s",$post_ID,$pagelinkedfrom))){return$this->pingback_error(48,__('The pingback has already been registered.'));}// Very stupid, but gives time to the 'from' server to publish!sleep(1);$remote_ip=preg_replace('/[^0-9a-fA-F:., ]/','',$_SERVER['REMOTE_ADDR']);/** This filter is documented in wp-includes/class-http.php */$user_agent=apply_filters('http_headers_useragent','WordPress/'get_bloginfo('version')'; 'get_bloginfo('url'),$pagelinkedfrom);// Let's check the remote site.$http_api_args=array('timeout'=>10,'redirection'=>0,'limit_response_size'=>153600,// 150 KB'user-agent'=>"$user_agent; verifying pingback from $remote_ip",'headers'=>array('X-Pingback-Forwarded-For'=>$remote_ip,),);$request=wp_safe_remote_get($pagelinkedfrom,$http_api_args);$remote_source=wp_remote_retrieve_body($request);$remote_source_original=$remote_source;if(!$remote_source){return$this->pingback_error(16,__('The source URL does not exist.'));}/** * Filters the pingback remote source. * * @since 2.5.0 * * @param string $remote_source Response source for the page linked from. * @param string $pagelinkedto URL of the page linked to. */$remote_source=apply_filters('pre_remote_source',$remote_source,$pagelinkedto);// Work around bug in strip_tags():$remote_source=str_replace(',',$remote_source);$remote_source=preg_replace('/[rnt ]+/',' ',$remote_source);// normalize spaces$remote_source=preg_replace('/*(h1|h2|h3|h4|h5|h6|p|th|td|li|dt|dd|pre|caption|input|textarea|button|body)[^>]*>/',"nn",$remote_source);preg_match('| ([^<]*?) |is',$remote_source,$matchtitle);$title=isset($matchtitle[1])?$matchtitle[1]:'';if(empty($title)){return$this->pingback_error(32,__('We cannot find a title on that page.'));}// Remove all script and style tags including their content.$remote_source=preg_replace('@<(script|style)[^>]*?>.*?\1>@si','',$remote_source);// Just keep the tag we need.$remote_source=strip_tags($remote_source,'');$p=explode("nn",$remote_source);$preg_target=preg_quote($pagelinkedto,'|');foreach($pas$para){if(strpos($para,$pagelinkedto)!==false){// It exists, but is it a link?preg_match('|]+?'$preg_target'[^>]*>([^>]+?)|',$para,$context);// If the URL isn't in a link context, keep looking.if(empty($context)){continue;}// We're going to use this fake tag to mark the context in a bit.// The marker is needed in case the link text appears more than once in the paragraph.$excerpt=preg_replace('|?wpcontext>|','',$para);// prevent really long link textif(strlen($context[1])>100){$context[1]=substr($context[1],0,100)'…';}$marker='' $context[1]'';// Set up our marker.$excerpt=str_replace($context[0],$marker,$excerpt);// Swap out the link for our marker.$excerpt=strip_tags($excerpt,'' );// Strip all tags but our context marker.$excerpt=trim($excerpt);$preg_marker=preg_quote($marker,'|');$excerpt=preg_replace("|.*?s(.{0,100}$preg_marker.{0,100})s.*|s",'$1',$excerpt);$excerpt=strip_tags($excerpt);// YES, again, to remove the marker wrapper.break;}}if(empty($context)){// Link to target not found.return$this->pingback_error(17,__('The source URL does not contain a link to the target URL, and so cannot be used as a source.'));}$pagelinkedfrom=str_replace('&','&',$pagelinkedfrom);$context='[…] 'esc_html($excerpt)' […]';$pagelinkedfrom=$this->escape($pagelinkedfrom);$comment_post_ID=(int)$post_ID;$comment_author=$title;$comment_author_email='';$this->escape($comment_author);$comment_author_url=$pagelinkedfrom;$comment_content=$context;$this->escape($comment_content);$comment_type='pingback';$commentdata=compact('comment_post_ID','comment_author','comment_author_url','comment_author_email','comment_content','comment_type','remote_source','remote_source_original');$comment_ID=wp_new_comment($commentdata);if(is_wp_error($comment_ID)){return$this->pingback_error(0,$comment_ID->get_error_message());}/** * Fires after a post pingback has been sent. * * @since 0.71 * * @param int $comment_ID Comment ID. */do_action('pingback_post',$comment_ID);/* translators: 1: URL of the page linked from, 2: URL of the page linked to. */returnsprintf(__('Pingback from %1$s to %2$s registered. Keep the web talking! :-)'),$pagelinkedfrom,$pagelinkedto);}
Related
Utilise
Utilisations | Description |
---|---|
wp-includes/l10n.php : __() |
Récupérer la traduction de $text. |
wp-includes/formatting.php : esc_html() |
Échappement pour les blocs HTML. |
wp-includes/general-template.php : get_bloginfo() |
Récupère les informations sur le site actuel. |
wp-includes/class-http.php :http_headers_useragent |
Filtre la valeur de l'agent utilisateur envoyée avec une requête HTTP. |
wp-includes/http.php : wp_safe_remote_get() |
Récupère la réponse brute d'une requête HTTP sécurisée utilisant la méthode GET. |
wp-includes/http.php : wp_remote_retrieve_body() |
Récupérer uniquement le corps de la réponse brute. |
wp-includes/plugin.php : do_action() |
Exécute les fonctions accrochées à un crochet d'action spécifique. |
wp-includes/plugin.php : apply_filters() |
Appelle les fonctions de rappel qui ont été ajoutées à un crochet de filtre. |
wp-includes/option.php : get_option() |
Récupère une valeur d'option en fonction d'un nom d'option. |
wp-includes/post.php : get_post() |
Récupère les données du post étant donné un ID de post ou un objet post. |
wp-includes/rewrite.php : url_to_postid() |
Examine une URL et essaie de déterminer l'identifiant de poste qu'elle représente. |
wp-includes/class-wp-xmlrpc-server.php : wp_xmlrpc_server::pingback_error() |
Envoie une erreur pingback basée sur le code d'erreur et le message donnés. |
wp-includes/class-wp-xmlrpc-server.php : pingback_ping_source_uri |
Filtre l'URI source du pingback. |
wp-includes/class-wp-xmlrpc-server.php : pre_remote_source |
Filtre la source distante du pingback. |
wp-includes/class-wp-xmlrpc-server.php : pingback_post |
Se déclenche après l'envoi d'un pingback post. |
wp-includes/class-wp-xmlrpc-server.php : xmlrpc_call |
Se déclenche après que l'utilisateur XML-RPC a été authentifié mais avant que le reste de la logique de la méthode ne commence. |
wp-includes/class-wp-xmlrpc-server.php : wp_xmlrpc_server::escape() |
Chaîne ou tableau de chaînes de caractères d'échappement pour la base de données. |
wp-includes/wp-db.php : wpdb::get_var() |
Récupère une variable de la base de données. |
wp-includes/wp-db.php : wpdb::get_results() |
Récupère un ensemble de résultats SQL entier de la base de données (c'est-à-dire de nombreuses lignes). |
wp-includes/wp-db.php : wpdb::prepare() |
Prépare une requête SQL pour une exécution sûre. |
wp-includes/comment-template.php : pings_open() |
Détermine si le post actuel est ouvert aux pings. |
wp-includes/comment.php : wp_new_comment() |
Ajoute un nouveau commentaire à la base de données. |
wp-includes/load.php : is_wp_error() |
Vérifie si la variable donnée est une erreur WordPress. |
Changelog
Version | Description |
---|---|
1.5.0 | Introduit. |
Si vous faites défiler vous pouvez trouver les interprétations d'autres créateurs, vous pouvez aussi montrer la vôtre si vous maîtrisez le sujet.