2 class NP_GoogleHistory extends NucleusPlugin {
3 function getName() { return 'My GoogleHistory'; }
4 function getAuthor() { return 'nakahara21'; }
5 function getURL() { return 'http://xx.nakahara21.net/'; }
6 function getVersion() { return '0.3'; }
7 function getDescription() { return 'Show history og google keywords'; }
8 function supportsFeature($what) {
10 case 'SqlTablePrefix':
18 $this->createOption("ex", "extension of logfile (ex: log):", "text", "log");
23 $this->logdir = $this->getDirectory();
24 $this->month = date("Y-m");
25 $this->logfile = $this->logdir.$this->month.'.'.$this->getOption("ex");
28 function doSkinVar($skinType, $show="gform", $maxtoshow = 5) {
32 $this->showGwordList($maxtoshow);
37 <form method="post" action="<?php echo $CONF['ActionURL'] ?>" target="_blank">
38 <input type="hidden" name="action" value="plugin" />
39 <input type="hidden" name="name" value="GoogleHistory" />
40 <input type="hidden" name="type" value="gsearch" />
41 <input type="text" value="" name="gword" size="15" />
42 <input type="submit" value="!" />
50 function doAction($type) {
51 $gword = requestVar('gword');
54 $this->saveGword($gword);
55 $gurl = $this->makeGurl($gword);
56 header('Location: ' . $gurl);
59 return 'Unexisting action: ' . $type;
64 function makeGurl($gword) {
65 $en_gword = mb_convert_encoding($gword, "UTF-8", _CHARSET);
66 $gurl = 'http://www.google.co.jp/search?ie=UTF-8&oe=UTF-8&q='.urlencode($en_gword);
70 function saveGword($gword) {
72 $gword = mb_convert_encoding($gword, "sjis", "UTF-8");
73 $arr_data = Array($gword,$time);
75 $fp = @fopen($this->logfile,"a+");
77 if(!is_dir($this->logdir)) die("No such directory : ".$this->logdir."\n");
78 if(!is_writable($this->logdir)) die("Cannot write to this directory : ".$this->logdir."\n");
81 $tmp = fread ($fp, filesize ($this->logfile));
84 fputs($fp,@join("\t",$arr_data)."\n");
89 function readlog($maxtoshow){
90 if( $handle = opendir($this->logdir)){
91 while( false !== $file = readdir($handle)){
92 sscanf($file,"%4s-%2s.%s", $y, $m, $ex);
93 if(checkdate($m,1,$y) && $ex == $this->getOption("ex")){
100 for($i=0;$this->num<$maxtoshow;$i++){
102 $data = @file($this->logdir.$filelist[$i]);
103 $this->num += count($data);
104 $log = array_merge($log, $data);
112 function showGwordList($maxtoshow){
113 $log = $this->readlog($maxtoshow);
114 if(($amount = min($maxtoshow, $this->num)) >0){
115 for($i=0;$i<$amount;$i++){
116 list($word,$timestamp) = explode("\t",$log[$i]);
117 $word = mb_convert_encoding($word, _CHARSET, "sjis");
118 $gtime = date("Y-m-d H:i",$timestamp);
119 $gurl = $this->makeGurl($word);
120 echo '<li><a href="'.$gurl.'" target="_blank">'.$word.'</a> '.$gtime.'</li>';