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

Benjamin Mako Hill || Want to submit a patch?