BLOGGERからの移行完了

どうにか、完成しました。
後は、適当にレイアウト弄うのみです。

いつものようにphpでゴリゴリ書いてあるので、後で見直すは一苦労ですが、とりあえず一通りcheckして 漏れ はないでしょう。

やるとしたら、タグクラウドをアクセス順に文字の大きさや色を変えたりですが、javascriptでやったほうが軽そうな気がして・・・

とりあえず、タグの1文字だけを

$labeltitle="タグネーム";

print "<b>".mb_substr($labeltitle,0,1,"utf-8")."</b>".mb_substr($labeltitle,1,-1,"utf-8").mb_substr($labeltitle,-1,1,"utf-8");

 

とかで、1文字目は、取れたけど残り全部がわからずこんな風になっています。

まっ自分専用ですので、投稿フォームなんかは、結構手抜きですけど、コメント入れてもらうときには、スパム防止用に、画像認証機能を
KCAPTCHA | freshmeat.net
からDLして使っています。

BLOGGER ftp公開廃止に伴う移行 その3 rssの書式

atom rss2.0 rss1.0は以下の感じで作っています。

if(isset($_GET['feed']) && $_GET['feed']){$xml=$_GET['feed'];}

if(isset($xml)){
$rss_title="ヘアサロン店長の独り言/奈良県橿原市/アトリエヘアピークス";
$rss_description="奈良県橿原市の美容室AtelierhairPeaksの店長の独り言プログです、ヘアケア、スタイルは勿論、車やプログラムを綴っています。";
$year=date("Y");

if($xml=="rdf"){
print <<<EOF
<?xml version="1.0" encoding="utf-8" ?>
<rdf:RDF xmlns="http://purl.org/rss/1.0/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xml:lang="ja">
<channel rdf:about="$BASE_URL/rdf.xml">
<title>$rss_title</title>
EOF;
}elseif($xml=="rss"){
print <<<EOF
<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0">
<channel>
<title>$rss_title</title>
<link>$BASE_URL/rss.xml</link>
<description>$rss_description</description>
<language>ja</language>
<copyright>Copyright $year, PeaksDesign</copyright>
EOF;
}elseif($xml=="atom"){
print <<<EOF
<?xml version="1.0" encoding="utf-8" ?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ja">
 <title type="text">$rss_title</title>
<subtitle type="text">$rss_description</subtitle>
<link rel="self" type='application/atom+xml' href="$BASE_URL/atom.xml"/>
<link rel='alternate' type='text/html' href='$BASE_URL/'/>
<author><name>PeaksDesign</name></author>
EOF;
}}

foreach( $bloglogDATA as $key => $value) {list($date,$title,$tag,$url,$text)=split("<>",$value);
$rss_title=$title;
$rss_link="$BASE_URL/$url";
$description ="<![CDATA[<b>$text</b>]]>";
$ctime2 =$date;
$rss_category = ereg_replace(",", "</category><category>", $tag);
$rss_term = "<category term='" .ereg_replace(",", "'/><category term='", $tag)."'/>";
if(!$toptime){$toptime =$ctime2;}

if(isset($xml) && $xml =="rdf"){
$items_list .= " <rdf:li rdf:resource='$rss_link'/>\n";
$item_rdf .="
 <item rdf:about='$rss_link'>
  <title>$rss_title</title>
   <link>$rss_link</link>
   <description>$description</description>
   <dc:date>$ctime2</dc:date>
 </item>";
}elseif(isset($xml) && $xml =="rss"){
$item_rss2 .="
 <item>
  <title>$rss_title</title>
   <description>$description</description>
   <link>$rss_link</link>
   <guid>$rss_link</guid>
   <category>$rss_category</category>
   <pubDate>$ctime2</pubDate>
 </item>";
}elseif(isset($xml) && $xml =="atom"){
$item_atom .="
 <entry>
  <title>$rss_title</title>
    <link rel='alternate' type='text/html' href='$rss_link' title='$rss_title'/>
  <content type='html'>$description</content>
  <published>$ctime2</published>
  <updated>$ctime2</updated>
  <author><name>PeaksDesign</name><uri>https://www.peaks.jp/</uri></author>
  $rss_term
  <id>$rss_link</id>
 </entry>";
}
}

if(isset($xml) && $xml =="rdf"){
print"
<link>$rss_link</link>
<description>$rss_description</description>
<items>
<rdf:Seq>
$items_list
</rdf:Seq>
</items>
</channel>
$item_rdf
</rdf:RDF>
";
exit;
}elseif(isset($xml) && $xml =="rss"){
print"
<lastBuildDate>$toptime</lastBuildDate>
<generator>PeaksDesign</generator>
<docs>http://blogs.law.harvard.edu/tech/rss</docs>
$item_rss2
</channel>
</rss>
";
exit;
}elseif(isset($xml) && $xml =="atom"){
print"
 <updated>$toptime</updated>
 <id>http://example.com/atom1.xml</id>
$item_atom
</feed>
";
exit;
}

 

BLOGGER ftp公開廃止に伴う移行 その2 タグリスト

BLOGGER ftp公開廃止に伴う移行 その1の続きというか、タグリストを作るにあたって、大事な事は、BLOGGERの場合、

BLOGGER FTP公開サイトのラベルでの分類方法

に書いてあるとおりbase64_decodeで日本語変換しておかないと
キャシュされているリンクからのアクセスが途切れてしまいます。
例)44OA44Oh44O844K444OY44Ki44O8 → ダメージヘアー

変換書き出し用のsampleは以下の感じです。

<?php
$dir = '/var/www/~~/labels/';#ラベルのパス
if($handle = opendir($dir)){#ディレクトリハンドルを獲得
while(false !== $file = readdir($handle)){#ファイル名獲得
list($filename,$html) = split("\.", $file);#ファイル名と拡張子を分割
if($html!="html"){continue;}
$filename = str_replace("__", "/", $filename);#ファイル名にするため__を/に戻す

if (preg_match("/=([A-F0-9]{2})/",$filename)) {#quoted_printable_decodeでローマ字+日本語に変換
$labellist = quoted_printable_decode ($filename);
}elseif(mb_detect_encoding(base64_decode($filename)) == "UTF-8"){#encodingがUTF-8ならbase64_decodeで日本語変換
$labellist = base64_decode($filename) ;
}else{#ローマ字はそのまま表示
$labellist = $filename ;
}
$ar[$labellist] = "$file";
}
closedir($handle); #ディレクトリハンドルを閉じる
}
foreach( $ar as $key => $val ){$insertlog.="$key<>$val;";print"$key-->$val<br />";}

$pointer=fopen("./labellist.log", "w");#'w' 書き出しのみでオープンします。ファイルが存在しない場合には、 作成を試みます。
flock($pointer, LOCK_EX);#ファイルをロックします
fputs($pointer, $insertlog);#書込みです
flock($pointer, LOCK_UN);#ロックを解除します
fclose($pointer);#ファイルを閉じます
?>

とかで、変換テーブルを作っておいて、.htaccessで
RewriteRule ^labels/(.*)\.html$ /?labels=$1.html
として、飛ばしてリンク切れを防いだりしています。

BLOGGER ftp公開廃止に伴う移行 その1 xml成形

BLOGGERもFTPでの公開が終了してしまいました。
4月のの頭ぐらいに認識してましたけど、時間の空いたときに作り直してどうにか完成しました。

苦労したのは、コメントの収得javascriptでアクセスしにいっても取れる文字数が決まっていました。
とりあえず、全コメントを直接アクセスし手動でファイルに取り込みました・・・
けど、4/30日に久しぶりにBLOGGERにアクセスすると、XML形式で移行用に全データ収得できたようです。
チェッ・・・ということで拾い出し用のスクリプト作ってみました。
export.php等で適当に保存して試してみてください

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>
<html lang=”ja”>

<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″>
<title>BLOGGER-データ摘出</title>
<style type=”text/css”>
body {background:#fff;margin:20px;padding:5px 0px;font-size:12px;color:#000}
</style>
</head>
<body>
<?php

$importXML =”./blog-04-30-2010.xml”;
$email =”value@peaks.jp”;
$blogtitle = “ヘアサロン店長の独り言”;

if (file_exists($importXML)) {
$xml = simplexml_load_file($importXML);

foreach ($xml as $feed) {

$comment=$draft=0;$taglist=””;
if(count($feed) <= 9){continue;}
if((string) $feed->title == “テンプレート: $blogtitle”){continue;}

$published = $feed->published;
$BlogLogData = “記入日時:published–>” . $published . “<br />”;
$title = ereg_replace(“\r|\n”,””,$feed->title);
$title = htmlspecialchars($title);
$BlogLogData .= “title–>”. $title. “<br />”;

$BlogLogData .= “タグ:category–>”;

foreach ($feed->category as $category) {
$tag = $category[‘term’];
switch((string) $tag) {
case ‘http://schemas.google.com/blogger/2008/kind#post’:$tag=””;
break;
case ‘http://schemas.google.com/blogger/2008/kind#settings’:$tag=””;
break;
case ‘http://schemas.google.com/blogger/2008/kind#template’:$tag=””;
break;
case ‘http://schemas.google.com/blogger/2008/kind#comment’:$tag=””;$comment++;
break;
}
$BlogLogData .= $tag;
if($tag){$taglist.=$tag.”,”;}
}
$labellist .= $taglist;
$BlogLogData .= “<br />”;

foreach ($feed->link as $link) {
if((string)$link[‘rel’] == ‘alternate’){
$url = $link[‘href’];
$BlogLogData .= “link–>”. $url . “<br />”;}
}

$content = ereg_replace(“\r|\n”,”<br />”,$feed->content);
$BlogLogData .= “本文:content–>”. htmlspecialchars($content). “<br />”;
$BlogLogData .= “更新日時:updated–>”. $feed->updated. “<br />”;
$announce=””;
if($feed->author->email != $email){$announce=”<font color=’red’><b>コメント</b></font>”;}
elseif(count($feed) == 10){$announce=”<font color=’red’><b>下書き</b></font& gt;”;$draft++;}
$author=$feed->author->name . ‘,’. $feed->author->uri . ‘,’. $feed->author->email ;
$BlogLogData .= “author–>$author,$announce”;

$BlogLogData .= “<hr/>\n”;
$BlogLogall.=$BlogLogData;
$insert = “$published<>$title<>$taglist<>$url<>$content<>$author\n”;
$insertlog.=$insert;
if($comment){$ComentLog.=$BlogLogData;$BlogLogData=””;$Comentinsert.=$insert;}
elseif($draft){$draftLog.=$BlogLogData;$BlogLogData=””;$draftinsert.=$insert;}
else{$BlogLog.=$BlogLogData;$BlogLogData=””;$BlogLoginsert.=$insert;}
}
// print_r($xml);
} else {
exit(‘Failed to open {$importXML}’);}

$labellist = explode(",",$labellist);
$labellist = array_unique($labellist);//array_unique -- 配列から重複した値を削除する"
if(isset($_GET['BlogLogall'])) {print $BlogLogall;$filename="BlogLogall";$insertlog;}
if(isset($_GET['BlogLog'])) {print $BlogLog;$filename="BlogLog";$insertlog=$BlogLoginsert;}
if(isset($_GET['ComentLog'])) {print $ComentLog;$filename="ComentLog";$insertlog=$Comentinsert;}
if(isset($_GET['draftLog'])) {print $draftLog;$filename="draftLog";$insertlog=$draftinsert;}
if(isset($_GET['taglist'])) {if($labellist){
sort($labellist);$insertlog="";foreach ($labellist as $key => $val) {
if($val){print "$key".")".$val."<br />";$insertlog.="$val\n";}}}$filename="taglist";}

$insertlog = explode("\n",trim($insertlog)); //この3行は昇順での書き込み用です
usort($insertlog, "cmp"); //
$insertlog=join("\n",$insertlog); //

if($filename){
$pointer=fopen("./$filename.log", "w"); //'w' 書き出しのみでオープンします。ファイルが存在しない場合には、 作成を試みます。
flock($pointer, LOCK_EX); //ファイルをロックします
fputs($pointer, $insertlog); //書込みです
flock($pointer, LOCK_UN); //ロックを解除します
fclose($pointer); //ファイルを閉じます
}
#------------------------------------------------
function cmp($b, $a){
preg_match("/([0-9]{2,4})-([0-9]+)-([0-9]+)/", $a, $args );$a_time = mktime(0,0,0,$args[2], $args[3],$args[1]);
preg_match("/([0-9]{2,4})-([0-9]+)-([0-9]+)/", $b, $args );$b_time = mktime(0,0,0,$args[2], $args[3],$args[1]);
if( $a_time == $b_time ) return 0;
return ($a_time > $b_time ) ? -1 : 1;
}

?>
</body>
</html>

 

http://www.blogger.com/export-blog.g?blogID= 自分のID

にアクセスしプログをダウンロードします。
或いは、bloggerにログイン後 設定 → ブログツールのエクスポート → プログダウンロードも同じデータです。

ダウンロードしたファイルをexport.phpと同一フォルダに置き、

export.phpを開き15行目からの下記の欄をダウンロードしたファイル名、使ってるemail、プログのタイトルに書き換え

$importXML ="blog-04-30-2010.xml";
$email ="value@peaks.jp\";
$blogtitle = "ヘアサロン店長の独り言";

 

下記のリンクをクリックすると実行スクリプトと同一フォルダにデータを書き出します。
同時に、下記に書き出すデータが表示されます。

<a href='?BlogLogall'>オールログ</a>
<a href='?BlogLog'>ブログログ</a>
<a href='?ComentLog'>コメントログ</a>
<a href='?draftLog'>下書きログ</a>
<a href='?taglist'>タグ一覧</a>

書き込みのデータ形式は
記入日<>タイトル<>タグ<>URL<>内容<>著者となっているので適宜使いやすいように適当に修正してください。

BLOGEERクラシックテンプレート 最近のコメント取り出し3

BLOGGERクラシックテンプレート 最新コメントの取り出し
BLOGEERクラシックテンプレート 最新のコメント取り出し2
コメントや最近のエントリーをjavascriptでの取出しを記載していましたが、
いつの間にか、json形式で引っ張ってくるデータの順序が変わっていて、でたらめ なリンク先を取り出していたので修正しました。

(いつからやってんやろ・・・汗ゞ)

function commentcallback(obj) {
var data = obj;
var InsertHTML = '<h2 class="sidebar-title">直近のコメント5件<\/h2>';
InsertHTML += '<ul>';
for (var i=0; i<data.feed.entry.length; i++) {
//var anchor=data.feed.entry[i].link[0].href.replace(/(\?[\w]+\=[0-9]+)/, "");
var anchor=data.feed.entry[i].link[2].href.replace(/(\?[\w]+\=[0-9]+)/, "");
InsertHTML+= ('<li><a href="'+anchor+'">');
//InsertHTML+= (data.feed.entry[i].summary.$t.substring(0,24));if (data.feed.entry[i].summary.$t.length > 24) {InsertHTML+= ('...');}
InsertHTML+= (data.feed.entry[i].title.$t.substring(0,22));if (data.feed.entry[i].title.$t.length > 22) {InsertHTML+= ('...');}
InsertHTML+= ('<\/a><br \/>');
InsertHTML+= ('['+data.feed.entry[i].published.$t.substring(2,10)+']');
InsertHTML+= (' by '+data.feed.entry[i].author[0].name.$t);
InsertHTML+= ('<\/li>');
}
InsertHTML += '<\/ul>';
document.getElementById('commentcallback').innerHTML = InsertHTML;
}

function newentry(obj) {
var data = obj;
var InsertHTML = ('<h2 class="sidebar-title">最近のエントリー10件<\/h2>');
InsertHTML += '<ul>';
for (var i=0; i<data.feed.entry.length; i++) {
InsertHTML+= ('<li>');
//InsertHTML+= ('<a href="'+data.feed.entry[i].link[0].href+'"><b>');
InsertHTML+= ('<a href="'+data.feed.entry[i].link[4].href+'"><b>');
InsertHTML+= (data.feed.entry[i].title.$t.substring(0,22));if (data.feed.entry[i].title.$t.length > 22) {InsertHTML+= ('...');}
InsertHTML+= ('<\/b><\/a><br \/>');
InsertHTML+= ('['+data.feed.entry[i].published.$t.substring(2,10)+']');
InsertHTML+= (data.feed.entry[i].summary.$t.substring(0,36));if (data.feed.entry[i].summary.$t.length > 36) {InsertHTML+= ('...');}
InsertHTML+= ('<\/li>');
}
InsertHTML += '<\/ul>';
document.getElementById('newentry').innerHTML = InsertHTML;
}