6234 | | // let's find which post is linked to |
6235 | | // FIXME: does url_to_postid() cover all these cases already? |
6236 | | // if so, then let's use it and drop the old code. |
6237 | | $urltest = parse_url($pagelinkedto); |
6238 | | if ( $post_ID = url_to_postid($pagelinkedto) ) { |
6239 | | // $way |
6240 | | } elseif ( isset( $urltest['path'] ) && preg_match('#p/[0-9]{1,}#', $urltest['path'], $match) ) { |
6241 | | // the path defines the post_ID (archives/p/XXXX) |
6242 | | $blah = explode('/', $match[0]); |
6243 | | $post_ID = (int) $blah[1]; |
6244 | | } elseif ( isset( $urltest['query'] ) && preg_match('#p=[0-9]{1,}#', $urltest['query'], $match) ) { |
6245 | | // the querystring defines the post_ID (?p=XXXX) |
6246 | | $blah = explode('=', $match[0]); |
6247 | | $post_ID = (int) $blah[1]; |
6248 | | } elseif ( isset($urltest['fragment']) ) { |
6249 | | // an #anchor is there, it's either... |
6250 | | if ( intval($urltest['fragment']) ) { |
6251 | | // ...an integer #XXXX (simplest case) |
6252 | | $post_ID = (int) $urltest['fragment']; |
6253 | | } elseif ( preg_match('/post-[0-9]+/',$urltest['fragment']) ) { |
6254 | | // ...a post id in the form 'post-###' |
6255 | | $post_ID = preg_replace('/[^0-9]+/', '', $urltest['fragment']); |
6256 | | } elseif ( is_string($urltest['fragment']) ) { |
6257 | | // ...or a string #title, a little more complicated |
6258 | | $title = preg_replace('/[^a-z0-9]/i', '.', $urltest['fragment']); |
6259 | | $sql = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_title RLIKE %s", $title ); |
6260 | | if (! ($post_ID = $wpdb->get_var($sql)) ) { |
6261 | | // returning unknown error '0' is better than die()ing |
6262 | | return $this->pingback_error( 0, '' ); |
6263 | | } |
6264 | | } |
6265 | | } else { |
6266 | | // TODO: Attempt to extract a post ID from the given URL |
6267 | | 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.' ) ); |
6268 | | } |
| 6234 | $post_ID = url_to_postid( $pagelinkedto ); |