Created
July 13, 2013 12:54
-
-
Save Leko/5990658 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
error_reporting(1); | |
require("workflows.php"); | |
// 設定ファイルに登録されたユーザ名を返す | |
function get_user_name() { | |
$f = fopen("./user", "r"); | |
return fgets($f); | |
} | |
$wf = new Workflows(); | |
$match = array(); | |
$offset = 0; | |
$inp = $argv[1]; | |
$inp_low = strtolower($inp); | |
// 設定ファイルが存在しない場合 | |
if ( !file_exists("./user") ): | |
// ファイルが存在しない or ファイルは存在するが空 | |
$wf->result( time(), "", "エラー: 設定ファイルに問題があります", "'hatebu_set ユーザ名'と入力しユーザ名をを登録して下さい", "icon.png"); | |
echo $wf->toxml(); | |
exit(-1); | |
endif; | |
$user_name = get_user_name(); | |
$url = "http://b.hatena.ne.jp/".$user_name."/rss?of="; | |
while(1): | |
// ブックマークrssを取得 | |
$xml = file_get_contents($url.$offset); | |
$xml = simplexml_load_string($xml); | |
// 取得結果から入力と一致するブックマークを探す | |
foreach( $xml->item as $feed ): | |
$t = strtolower($feed->title); | |
if ( strpos($t, $inp_low) !== false ): | |
array_push($match, $feed); | |
endif; | |
endforeach; | |
if ( count($xml->item) < 20 ): | |
break; | |
else: | |
$offset += 20; | |
endif; | |
endwhile; | |
// not foundを表示 | |
if ( count($match) == 0 ): | |
$wf->result(time(), "", $inp."に一致するブックマークは見つかりませんでした", "", "icon.png"); | |
// 一致したブックマークリストを作成 | |
else: | |
foreach( $match as $bookmark ): | |
$wf->result(time(), $bookmark->link, $bookmark->title, $bookmark->link, "icon.png"); | |
endforeach; | |
endif; | |
echo $wf->toxml(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
error_reporting(1); | |
require("workflows.php"); | |
$wf = new Workflows(); | |
$inp = $argv[1]; | |
// 入力された内容を書き込み | |
$f = fopen("./user", "w"); | |
fputs($f, $inp); | |
fclose($f); | |
// 通知センター用に入力内容を返す | |
$wf->result(time(), $inp, $inp, $inp."を登録", "icon.png"); | |
echo $wf->toxml(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment