| 1 |
<?php |
|---|
| 2 |
require("jsrsServer.php.inc"); |
|---|
| 3 |
include("shared.php"); |
|---|
| 4 |
|
|---|
| 5 |
jsrsDispatch("annotate"); |
|---|
| 6 |
|
|---|
| 7 |
function buildtags($newtags) { |
|---|
| 8 |
$lines = fopen("./tags.count","r"); |
|---|
| 9 |
while (!feof($lines)) { |
|---|
| 10 |
$line = fgets($lines); |
|---|
| 11 |
$line = rtrim($line); |
|---|
| 12 |
$tmp = split("\t", $line); |
|---|
| 13 |
$tags[ $tmp[0] ] = $tmp[1]; |
|---|
| 14 |
} |
|---|
| 15 |
fclose($lines); |
|---|
| 16 |
|
|---|
| 17 |
$tmp = explode(",", $newtags); |
|---|
| 18 |
foreach ($tmp as $tag) { |
|---|
| 19 |
$tags[ strtolower(trim($tag)) ] += 1; |
|---|
| 20 |
} |
|---|
| 21 |
|
|---|
| 22 |
$maxcount = 0; |
|---|
| 23 |
|
|---|
| 24 |
$handle = fopen("./tags.count","w"); |
|---|
| 25 |
foreach (array_keys($tags) as $tag) { |
|---|
| 26 |
fwrite($handle, $tag . "\t" . $tags[ $tag ] . "\n"); |
|---|
| 27 |
if ($tags[ $tag ] > $maxcount) { |
|---|
| 28 |
$maxcount = $tags[ $tag ]; |
|---|
| 29 |
} |
|---|
| 30 |
} |
|---|
| 31 |
fclose($handle); |
|---|
| 32 |
|
|---|
| 33 |
$minsize = 10; |
|---|
| 34 |
$maxsize = 20; |
|---|
| 35 |
|
|---|
| 36 |
$sorted = array_keys($tags); sort($sorted); |
|---|
| 37 |
|
|---|
| 38 |
$handle = fopen("./tags","w"); |
|---|
| 39 |
foreach ($sorted as $tag) { |
|---|
| 40 |
$size = ($maxsize-$minsize) * $tags[$tag] / $maxcount + $minsize; |
|---|
| 41 |
fwrite($handle, "<a href=\"javascript:tagclick('" . $tag . "')\" style=\"font-size: ". $size . "px;\">" . $tag . "</font> "); |
|---|
| 42 |
} |
|---|
| 43 |
fclose($handle); |
|---|
| 44 |
} |
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
function annotate($file,$uid,$title,$url,$description,$imgurl,$tags,$coords,$geoType,$user) { |
|---|
| 61 |
if ($title == '' || $coords == '') |
|---|
| 62 |
return "Not enough values provided."; |
|---|
| 63 |
if ($uid == '') |
|---|
| 64 |
$uid = $title; |
|---|
| 65 |
if ($file == '') |
|---|
| 66 |
$file = 'rss.xml'; |
|---|
| 67 |
if ($geoType == '') |
|---|
| 68 |
$geoType = 'point'; |
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
$item = fields2xml($uid,$title,$url,$description,$imgurl,$tags,$coords,$geoType,$user); |
|---|
| 72 |
if ($item == '') |
|---|
| 73 |
return 'Error when converting to xml.'; |
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
$handle = fopen($file,"r") or die($php_errormsg); |
|---|
| 77 |
$contents = fread($handle, filesize($file)); |
|---|
| 78 |
fclose($handle) or die($php_errormsg); |
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
$itemStart = strpos($contents, '<item>'); |
|---|
| 82 |
$itemEnd = $itemStart; |
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
$newcontents = substr_replace($contents, $item . "\n", $itemStart, $itemEnd - $itemStart); |
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
$handle = fopen($file,"w") or die($php_errormsg); |
|---|
| 89 |
fwrite($handle, $newcontents); |
|---|
| 90 |
changeLog($file . '.log', "add", $item); |
|---|
| 91 |
fclose($handle) or die($php_errormsg); |
|---|
| 92 |
|
|---|
| 93 |
buildtags($tags); |
|---|
| 94 |
|
|---|
| 95 |
return ("success"); |
|---|
| 96 |
} |
|---|
| 97 |
|
|---|
| 98 |
?> |
|---|
| 99 |
|
|---|