- Enforce minimum elapsed time on registration form
[scuttle] / templates / dynamictags.inc.php
1 <?php
2 /***************************************************************************
3 Copyright (c) 2005 - 2010 Marcus Campbell
4 http://scuttle.org/
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 ***************************************************************************/
20
21 $tagservice  =& ServiceFactory::getServiceInstance('TagService');
22 $userservice =& ServiceFactory::getServiceInstance('UserService');
23
24 $logged_on_userid = $userservice->getCurrentUserId();
25
26 $userPopularTags        =& $tagservice->getPopularTags($logged_on_userid, 25, $logged_on_userid);
27 $userPopularTagsCloud   =& $tagservice->tagCloud($userPopularTags, 5, 90, 175); 
28 $userPopularTagsCount   = count($userPopularTags);
29
30 if ($userPopularTagsCount > 0) {
31 ?>
32
33 <script type="text/javascript">
34 Array.prototype.contains = function (ele) {
35     for (var i = 0; i < this.length; i++) {
36         if (this[i] == ele) {
37             return true;
38         }
39     }
40     return false;
41 };
42
43 Array.prototype.remove = function (ele) {
44     var arr = new Array();
45     var count = 0;
46     for (var i = 0; i < this.length; i++) {
47         if (this[i] != ele) {
48             arr[count] = this[i];
49             count++;
50         }
51     }
52     return arr;
53 };
54
55 function addonload(addition) {
56     var existing = window.onload;
57     window.onload = function () {
58         existing();
59         addition();
60     }
61 }
62
63 addonload(
64     function () {
65         var taglist = document.getElementById('tags');
66         var tags = taglist.value.split(', ');
67         
68         var populartags = document.getElementById('popularTags').getElementsByTagName('span');
69         
70         for (var i = 0; i < populartags.length; i++) {
71             if (tags.contains(populartags[i].innerHTML)) {
72                 populartags[i].className = 'selected';
73             }
74         }
75     }
76 );
77
78 function addTag(ele) {
79     var thisTag = ele.innerHTML;
80     var taglist = document.getElementById('tags');
81     var tags = taglist.value.split(', ');
82     
83     // If tag is already listed, remove it
84     if (tags.contains(thisTag)) {
85         tags = tags.remove(thisTag);
86         ele.className = 'unselected';
87         
88     // Otherwise add it
89     } else {
90         tags.splice(0, 0, thisTag);
91         ele.className = 'selected';
92     }
93     
94     taglist.value = tags.join(', ');
95     
96     document.getElementById('tags').focus();
97 }
98
99 document.write('<div class="collapsible">');
100 document.write('<h3><?php echo T_('Popular Tags'); ?><\/h3>');
101 document.write('<p id="popularTags" class="tags">');
102
103 <?php
104 $taglist = '';
105 foreach(array_keys($userPopularTagsCloud) as $key) {
106     $row =& $userPopularTagsCloud[$key];
107     $entries = T_ngettext('bookmark', 'bookmarks', $row['bCount']);
108     $taglist .= '<span title="'. $row['bCount'] .' '. $entries .'" style="font-size:'. $row['size'] .'" onclick="addTag(this)">'. filter($row['tag']) .'<\/span> ';
109 }
110 ?>
111
112 document.write('<?php echo $taglist ?>');
113 document.write('<\/p>');
114 document.write('<\/div>');
115 </script>
116
117 <?php } ?>

Benjamin Mako Hill || Want to submit a patch?