root/geowiki/annotate.rs.php

Revision 9, 2.9 kB (checked in by mikel, 3 years ago)

geowiki initial checkin

Line 
1 <?php
2 require("jsrsServer.php.inc");
3 include("shared.php");
4 //annotate($file,$uid,$title,$url,$description,$imgurl,$tags,$coords,$geoType,$user)
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 //TODO: do all this with xml-parsing functions
47 //insert a new geo item into the xml $file
48 //$file: where to write to (if empty, $file = rss.xml)
49 //$uid: unique id for the item, if given will replace an existing item with the same id
50 //$title: name of the item
51 //$url: link which is opened when clicking on this item on a map
52 //$description: a textual description
53 //$imgurl: an image to be displayed at this items location
54 //$tags: space-separated list of tags (=categories) which this item falls in
55 //$coords: (lat,long) pairs (one for a point, more for lines+polygons, each separated by " "
56 //$geoType: either "point", "line" or "polygon"
57 //$user: name of the user who created / edited the item
58 //except of $coords no elements are required
59 //return value is "success" or a failure message
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     //code fields as xml-entry
71     $item = fields2xml($uid,$title,$url,$description,$imgurl,$tags,$coords,$geoType,$user);
72     if ($item == '')
73         return 'Error when converting to xml.';
74     
75     //read rss file
76     $handle = fopen($file,"r") or die($php_errormsg);
77     $contents = fread($handle, filesize($file));
78     fclose($handle) or die($php_errormsg);
79
80     //find first entry
81     $itemStart = strpos($contents, '<item>');
82     $itemEnd = $itemStart;
83
84     //insert or replace new item
85     $newcontents = substr_replace($contents, $item . "\n", $itemStart, $itemEnd - $itemStart);
86
87     //write to rss file
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
Note: See TracBrowser for help on using the browser.