2 /***************************************************************************
3 Copyright (c) 2005 - 2010 Marcus Campbell
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.
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.
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 ***************************************************************************/
21 $sf = new ServiceFactory();
22 $tagservice =& $sf->getServiceInstance('TagService');
23 $userservice =& $sf->getServiceInstance('UserService');
25 $logged_on_userid = $userservice->getCurrentUserId();
27 $userPopularTags =& $tagservice->getPopularTags($logged_on_userid, 25, $logged_on_userid);
28 $userAllTags =& $tagservice->getPopularTags($logged_on_userid, 10000, $logged_on_userid);
29 $userPopularTagsCloud =& $tagservice->tagCloud($userPopularTags, 5, 90, 175);
30 $userPopularTagsCount = count($userPopularTags);
32 if ($userPopularTagsCount > 0) {
35 <script type="text/javascript">
36 Array.prototype.contains = function (ele) {
37 for (var i = 0; i < this.length; i++) {
45 Array.prototype.remove = function (ele) {
46 var arr = new Array();
48 for (var i = 0; i < this.length; i++) {
57 function addonload(addition) {
58 var existing = window.onload;
59 window.onload = function () {
67 var taglist = document.getElementById('tags');
68 var tags = taglist.value.split(', ');
70 var populartags = document.getElementById('popularTags').getElementsByTagName('span');
72 for (var i = 0; i < populartags.length; i++) {
73 if (tags.contains(populartags[i].innerHTML)) {
74 populartags[i].className = 'selected';
80 function addTag(ele) {
81 var thisTag = ele.innerHTML;
82 var taglist = document.getElementById('tags');
83 var tags = taglist.value.split(', ');
85 // If tag is already listed, remove it
86 if (tags.contains(thisTag)) {
87 tags = tags.remove(thisTag);
88 ele.className = 'unselected';
92 tags.splice(0, 0, thisTag);
93 ele.className = 'selected';
96 taglist.value = tags.join(', ');
98 document.getElementById('tags').focus();
101 document.write('<div class="collapsible">');
102 document.write('<h3><?php echo T_('Popular Tags'); ?><\/h3>');
103 document.write('<p id="popularTags" class="tags">');
107 foreach(array_keys($userPopularTagsCloud) as $key) {
108 $row =& $userPopularTagsCloud[$key];
109 $entries = T_ngettext('bookmark', 'bookmarks', $row['bCount']);
110 $taglist .= '<span title="'. $row['bCount'] .' '. $entries .'" style="font-size:'. $row['size'] .'" onclick="addTag(this)">'. filter($row['tag']) .'<\/span> ';
114 document.write('<?php echo $taglist ?>');
115 document.write('<\/p>');
116 document.write('<\/div>');
118 var availableTags = [
121 foreach(array_keys($userAllTags) as $key) {
122 print '"'.$userAllTags[$key]['tag'].'",'."\n";
126 function split( val ) {
127 return val.split( /,\s*/ );
129 function extractLast( term ) {
130 return split( term ).pop();
134 // don't navigate away from the field on tab when selecting an item
135 .bind( "keydown", function( event ) {
136 if ( event.keyCode === $.ui.keyCode.TAB &&
137 $( this ).data( "autocomplete" ).menu.active ) {
138 event.preventDefault();
144 source: function( request, response ) {
145 // if the term is >2 in legth delegate back to autocomplete
146 if (extractLast ( request.term ).length < 3) {
149 response( $.ui.autocomplete.filter(
150 availableTags, extractLast( request.term ) ) );
154 // prevent value inserted on focus
157 select: function( event, ui ) {
158 var terms = split( this.value );
159 // remove the current input
161 // add the selected item
162 var newterm = ui.item.value;
163 terms.push( newterm );
165 $("#popularTags").children().each(function() {
166 if (this.innerHTML == newterm) {
167 this.className = 'selected';
170 // add placeholder to get the comma-and-space at the end
172 this.value = terms.join( ", " );