header("Content-type: application/x-javascript"); include('proxy.php'); require_once('JSON.php'); define(BASE_URI , "http://booklog.jp/users/"); define(POST_URI , "/All?display=list&category_id=0&status=0&rank=0&sort=sort_desc"); define(ASIN_POSITION , 4); //proxy利用の場合1/未使用の場合0 $use_proxy = 0; $proxy_host = 'mrcproxy.mrc.dnp.co.jp'; $proxy_port = 8080; $no_proxy = array( 'localhost', // localhost '127.0.0.0/8', // loopback ); function dump_nodes_title(tidyNode $node, &$urls = NULL) { $urls = (is_array($urls)) ? $urls : array(); $titles = (is_array($titles)) ? $titles : array(); if(isset($node->id)) { if($node->id == TIDY_TAG_A) { if(stristr($node->attribute['href'], '/archives/') === FALSE) { }else{ $asin_tmp = explode("/",$node->attribute['href']); $title_tmp = $node->attribute['title']; // echo $title_tmp; // echo '
'; // print_r($node->child[0]->value); // echo ''; $tmp = $asin_tmp[ASIN_POSITION]; $urls[] = array("asin" =>$tmp , "title" =>$title_tmp); // $urls[] = array("asin" =>$tmp , "title" =>$node->child[0]->value); } } } if($node->hasChildren()) { foreach($node->child as $c) { dump_nodes_title($c, $urls); } } return $urls; } function get_BOOKLOG_ASIN($word,$tidy_encode,$mb_encode){ $json = new Services_JSON(); $url = BASE_URI.$word.POST_URI; // http://booklog.jp/users/ryouchi // echo $url; $rdata = http_request($url); // $data = mb_convert_encoding($rdata['data'],"utf-8","EUC-JP"); $data = mb_convert_encoding($rdata['data'],$mb_encode,"UTF-8"); $config = array('indent' => TRUE, 'output-xhtml' => TRUE, 'wrap' => 200); // $a = tidy_parse_string($data, $config, 'UTF8'); $a = tidy_parse_string($data, $config, $tidy_encode); $a->cleanRepair(); $urls = dump_nodes_title($a->html()); $asin = array(); $key = "asin"; /* foreach ($urls as $u){ // if(stristr($u, 'asin') === FALSE) { // }else{ $asin_tmp = explode("/",$u); $tmp = array("asin" =>$asin_tmp[ASIN_POSITION]); array_push ($asin , $tmp); // } }*/ $js = $json->encode($urls); if ($_GET['callback']<>""){ $var = $_GET['var']; $src = $_GET['callback']."("; $src .= $js; $src .=");"; echo $src; } } // main if($_GET["user"] <>"") { if ($_GET["encode"]<>""){ $tidy_encode = "utf8"; $mb_encode = "UTF-8"; }else{ if(stristr($_GET["encode"], 'UTF-8') !== FALSE) { if(stristr($_GET["encode"], 'SJIS') !== FALSE) { if(stristr($_GET["encode"], 'EUC-JP') !== FALSE) { $tidy_encode = "utf-8"; $mb_encode = "UTF-8"; }else{ $tidy_encode = "euc-jp"; $mb_encode = "EUC-JP"; } }else{ $tidy_encode = "shiftjis"; $mb_encode = "SJIS"; } }else{ $tidy_encode = "utf8"; $mb_encode = "UTF-8"; } } get_BOOKLOG_ASIN($_GET["user"],$tidy_encode,$mb_encode); } ?>