gist: 15594 Download_button fork
public
Description:
blogger -> wordpress redirect code
Public Clone URL: git://gist.github.com/15594.git
blogger.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?
/**
* this is supposed to be called as e.g.
* http://anyall.org/blog/blogger/http://socialscienceplusplus.blogspot.com/2008/10/mydebatesorg-and-poten
tially-coolest.html
* and then redirect to e.g.
* http://anyall.org/blog/2008/10/mydebatesorg-online-polling-and-potentially-the-coolest-question-corpus-
ever/
*
* It accesses wordpress's own metainfo saved from the blogger migration,
* to guarantee redirection to the correct new version -- no hacks with strings.
*
* So there are 2 redirects total:
* (1) the blogspot.com page meta-refreshes to here
* (2) this "page" sends to the final wordpress post url
*
* This script is "installed" by placing it directly in the wordpress root.
**/
require_once( dirname(__FILE__) . '/wp-load.php' );
wp();
 
//print_r($wpdb);
 
$path = $_SERVER['PATH_INFO'];
$path = preg_replace('/^\/+/', '', $path);
$path = preg_replace('/^https?:\/+socialscienceplusplus\.blogspot\.com/','/', $path);
$path = preg_replace('/^\/+/', '', $path);
$path = "/" . $path;
//echo $path;
$res = $wpdb->get_results(
  $wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key='blogger_permalink' AND meta_value = '%
s'", $path) );
//print_r($res);
 
if (count($res)==0) {
  //echo "Error, path '$path' matches no blogger imports.";
  header("HTTP/1.1 301 Moved Permanently");
  header("Location: http://anyall.org/blog/");
 
} else if (count($res) > 1) {
  echo "Error, path '$path' matches many blogger imports.";
 
} else {
  $post_id = $res[0]->post_id;
  //print_r($post_id);
  header("HTTP/1.1 301 Moved Permanently");
  header("Location: http://anyall.org/blog/?p=$post_id");
  exit();
}
?>
 
for_blogger_template.html
1
2
3
4
5
6
7
8
9
10
<!-- stick this in anywhere in the <head> .. only on a "Classic" blogger template. They also have a newer XML-based template language, but it can't support this usage because it's too strictly proper xml and can't do the string concatenation trick we need. -->
 
  <Blogger>
  <MainOrArchivePage>
    <meta http-equiv="refresh" content="0;url=http://anyall.org/blog/" />
  </MainOrArchivePage>
  <ItemPage>
    <meta http-equiv="refresh" content="0;url=http://anyall.org/blog/blogger/<$BlogItemPermalinkUrl$>" />
  </ItemPage>
  </Blogger>

Owner

brendano

Revisions