Changeset 2619 for trunk/xmlrpc.php
- Timestamp:
- 06/04/2005 10:15:36 AM (21 years ago)
- File:
-
- 1 edited
-
trunk/xmlrpc.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/xmlrpc.php
r2606 r2619 1076 1076 /* pingback.ping gets a pingback and registers it */ 1077 1077 function pingback_ping($args) { 1078 // original code by Mort (http://mort.mine.nu:8080 -- site seems dead)1079 // refactored to return error codes and avoid deep ifififif headaches1080 1078 global $wpdb, $wp_version; 1081 1079 … … 1092 1090 // Check if the page linked to is in our site 1093 1091 $pos1 = strpos($pagelinkedto, str_replace('http://', '', str_replace('www.', '', get_settings('home')))); 1094 if(!$pos1) { 1095 return new IXR_Error(0, ''); 1096 } 1097 1092 if( !$pos1 ) 1093 return new IXR_Error(0, 'Is there no link to us?'); 1098 1094 1099 1095 // let's find which post is linked to … … 1125 1121 } elseif (is_string($urltest['fragment'])) { 1126 1122 // ...or a string #title, a little more complicated 1127 $title = preg_replace('/[^a-z A-Z0-9]/', '.', $urltest['fragment']);1123 $title = preg_replace('/[^a-z0-9]/i', '.', $urltest['fragment']); 1128 1124 $sql = "SELECT ID FROM $wpdb->posts WHERE post_title RLIKE '$title'"; 1129 1125 if (! ($post_ID = $wpdb->get_var($sql)) ) { … … 1137 1133 return new IXR_Error(33, 'The specified target URI cannot be used as a target. It either doesn\'t exist, or it is not a pingback-enabled resource.'); 1138 1134 } 1135 $post_ID = (int) $post_ID; 1139 1136 1140 1137 1141 1138 logIO("O","(PB) URI='$pagelinkedto' ID='$post_ID' Found='$way'"); 1142 1139 1143 $sql = 'SELECT post_author FROM '.$wpdb->posts.' WHERE ID = '.$post_ID; 1144 $result = $wpdb->get_results($sql); 1145 1146 if (!$wpdb->num_rows) { 1147 // Post_ID not found 1140 $post = $wpdb->get_row("SELECT post_author FROM $wpdb->posts WHERE ID = '$post_ID'"); 1141 1142 if ( !$post ) // Post_ID not found 1148 1143 return new IXR_Error(33, 'The specified target URI cannot be used as a target. It either doesn\'t exist, or it is not a pingback-enabled resource.'); 1149 } 1150 1144 1145 // Check if pings are on 1146 if ( 'closed' == $post->ping_status ) 1147 return new IXR_Error(33, 'The specified target URI cannot be used as a target. It either doesn\'t exist, or it is not a pingback-enabled resource.'); 1151 1148 1152 1149 // Let's check that the remote site didn't already pingback this entry 1153 1150 $result = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post_ID' AND comment_author_url = '$pagelinkedfrom'"); 1154 1151 1155 if ($wpdb->num_rows) { 1156 // We already have a Pingback from this URL 1152 if ( $wpdb->num_rows ) // We already have a Pingback from this URL 1157 1153 return new IXR_Error(48, 'The pingback has already been registered.'); 1158 }1159 1160 1154 1161 1155 // very stupid, but gives time to the 'from' server to publish ! … … 1168 1162 1169 1163 // Work around bug in strip_tags(): 1170 $linea = str_replace('<!DOCTYPE','<DOCTYPE',$linea); 1171 $linea = strip_tags($linea, '<title><a>'); 1172 $linea = strip_all_but_one_link($linea, $pagelinkedto); 1173 // I don't think we need this? -- emc3 1174 //$linea = preg_replace('#&([^amp\;])#is', '&$1', $linea); 1175 if ( empty($matchtitle) ) { 1176 preg_match('|<title>([^<]*?)</title>|is', $linea, $matchtitle); 1164 $linea = str_replace('<!DOC', '<DOC', $linea); 1165 $linea = preg_replace( '/[\s\r\n\t]+/', ' ', $linea ); // normalize spaces 1166 $linea = preg_replace( "/ <(h1|h2|h3|h4|h5|h6|p|th|td|li|dt|dd|pre|caption|input|textarea|button|body)[^>]*>/", "\n\n", $linea ); 1167 1168 preg_match('|<title>([^<]*?)</title>|is', $linea, $matchtitle); 1169 $title = $matchtitle[1]; 1170 if ( empty( $title ) ) 1171 return new IXR_Error(32, 'We cannot find a title on that page.'); 1172 1173 $linea = strip_tags( $linea, '<a>' ); // just keep the tag we need 1174 1175 $p = explode( "\n\n", $linea ); 1176 1177 $sem_regexp_pb = "/(\\/|\\\|\*|\?|\+|\.|\^|\\$|\(|\)|\[|\]|\||\{|\})/"; 1178 $sem_regexp_fix = "\\\\$1"; 1179 $link = preg_replace( $sem_regexp_pb, $sem_regexp_fix, $pagelinkedfrom ); 1180 1181 $finished = false; 1182 foreach ( $p as $para ) { 1183 if ( $finished ) 1184 continue; 1185 if ( strstr( $para, $pagelinkedto ) ) { 1186 $context = preg_replace( "/.*<a[^>]+".$link."[^>]*>([^>]+)<\/a>.*/", "$1", $para ); 1187 $excerpt = strip_tags( $para ); 1188 $excerpt = trim( $excerpt ); 1189 $use = preg_quote( $context ); 1190 $excerpt = preg_replace("|.*?\s(.{0,100}$use.{0,100})\s|s", "$1", $excerpt); 1191 $finished = true; 1192 } 1177 1193 } 1178 $pos2 = strpos($linea, $pagelinkedto);1179 $pos3 = strpos($linea, str_replace('http://www.', 'http://', $pagelinkedto));1180 if (is_integer($pos2) || is_integer($pos3)) {1181 // The page really links to us :)1182 $pos4 = (is_integer($pos2)) ? $pos2 : $pos3;1183 $start = $pos4-100;1184 $context = substr($linea, $start, 250);1185 $context = str_replace("\n", ' ', $context);1186 $context = str_replace('&', '&', $context);1187 }1188 1189 if (empty($context)) {1190 // URL pattern not found1191 return new IXR_Error(17, 'The source URI does not contain a link to the target URI, and so cannot be used as a source.');1192 }1193 1194 1195 // Check if pings are on1196 $pingstatus = $wpdb->get_var("SELECT ping_status FROM $wpdb->posts WHERE ID = $post_ID");1197 if ('closed' == $pingstatus) {1198 return new IXR_Error(33, 'The specified target URI cannot be used as a target. It either doesn\'t exist, or it is not a pingback-enabled resource.');1199 }1200 1201 1194 1202 1195 $pagelinkedfrom = preg_replace('#&([^amp\;])#is', '&$1', $pagelinkedfrom); 1203 $title = (!strlen($matchtitle[1])) ? $pagelinkedfrom : $matchtitle[1]; 1204 $original_context = strip_tags($context); 1205 $context = '[...] '; 1206 $context .= wp_specialchars($original_context); 1207 $context .= ' [...]'; 1196 1197 $context = '[...] ' . wp_specialchars( $excerpt ) . ' [...]'; 1208 1198 $original_pagelinkedfrom = $pagelinkedfrom; 1209 $pagelinkedfrom = addslashes( $pagelinkedfrom);1199 $pagelinkedfrom = addslashes( $pagelinkedfrom ); 1210 1200 $original_title = $title; 1211 1201 … … 1216 1206 $comment_type = 'pingback'; 1217 1207 1218 $pingstatus = $wpdb->get_var("SELECT ping_status FROM $wpdb->posts WHERE ID = $post_ID");1219 1220 if ('open' != $pingstatus)1221 die('Sorry, pingbacks are closed for this item.');1222 1223 1208 $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_content', 'comment_type'); 1224 1209
Note: See TracChangeset
for help on using the changeset viewer.