0
(0)

なんか、久々に ICT な blog を書いていますが、、、この半年ほどは【福祉】分野で生活支援員として勤務。まだまだ修行中の身なので、ICT 話題はほとんどノーチェック、ノーケアです。

ついでに、blog を Windows Hosted な ExpressWeb のサービス終了に伴い、sakura (FreeBSD 9.1-RELEASE-p24 amd64) へ移転しましたわよ。おほほほ。 移転は割と簡単でした。過去6年分の WordPress を丸ごと持ってきただけです。細かいことは端折りますが、それなりにセキュリティ・メンテナンスには長けているので(謎

さて本題。

Piwik (ピーウィック)で、PHP ファンクションが使えるので試そうと思う。

Piwik 管理画面のスニペットにカレント URL のベストキーワード(文言)が表示されるようになるとな。

<?php

// This function will call the API to get best keyword for current URL.
// Then it writes the list of best keywords in a HTML list
function DisplayTopKeywords($url = "")
{
// Do not spend more than 1 second fetching the data
@ini_set("default_socket_timeout", $timeout = 1);
// Get the Keywords data
$url = empty($url) ? "http://". $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] : $url;
$api = "http://piwikを置いた鯖/piwik/?module=API&method=Referrers.getKeywordsForPageUrl&format=json&filter_limit=10&token_auth=承認トークン&date=previous1&period=week&idSite=1&url=" . urlencode($url);
$keywords = @json_decode(file_get_contents($api), $assoc = true);
Common::sendHeader('Content-Type: text/html; charset=utf-8', true);
if ($keywords === false || isset($keywords["result"])) {
// DEBUG ONLY: uncomment for troubleshooting an empty output (the URL output reveals the token_auth)
// echo "Error while fetching the <a href='$api'>Top Keywords from Piwik</a>";
return;
}

// Display the list in HTML
$url = htmlspecialchars($url, ENT_QUOTES);
$output = "<h2>Top Keywords for <a href='$url'>$url</a></h2><ul>";
foreach($keywords as $keyword) {
$output .= "<li>". $keyword . "</li>";
}
if (empty($keywords)) { $output .= "Nothing yet..."; }
$output .= "</ul>";
echo $output;
}

DisplayTopKeywords();

というもの。今回、blog 移転に伴いコードブロックとかコードハイライターのプラグインも更新したので、どう表示されるか正直wktkなところ。

では、また・・・。結果はそのうち書きます。

以上

[amazon_enhanced asin=”5511761788″ /] [amazon_enhanced asin=”1158988826″ /] [amazon_enhanced asin=”2746074087″ /]

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

投稿者 斉藤之雄 (Yukio Saito)

Global Information and Communication Technology OTAKU / Sports volunteer / Social Services / Master of Technology in Innovation for Design and Engineering, AIIT / BA, Social Welfare, NFU / twitter@yukio_saitoh