1: <?php
  2: 
  3:   4:   5:   6:   7:   8:   9:  10:  11: 
 12: $plugin_description = gettext("Provides functions to print a tag cloud of all tags from a Zenphoto object.");
 13: $plugin_author = "Malte Müller (acrylian)";
 14: 
 15:  16:  17:  18:  19:  20:  21:  22: 
 23: function getAllTagsFromAlbum($albumname, $subalbums = false, $mode = 'images') {
 24:     global $_zp_gallery;
 25:     $passwordcheck = '';
 26:     $imageWhere = '';
 27:     $tagWhere = "";
 28:     $albumname = sanitize($albumname);
 29:     if (empty($albumname)) {
 30:         return FALSE;
 31:     }
 32:     $albumobj = newAlbum($albumname);
 33:     if (!$albumobj->exists) {
 34:         return FALSE;
 35:     }
 36:     if (zp_loggedin()) {
 37:         $albumWhere = "WHERE `dynamic`=0";
 38:     } else {
 39:         $albumscheck = query_full_array("SELECT * FROM " . prefix('albums') . " ORDER BY title");
 40:         foreach ($albumscheck as $albumcheck) {
 41:             if (!checkAlbumPassword($albumcheck['folder'])) {
 42:                 $albumpasswordcheck = " AND id != " . $albumcheck['id'];
 43:                 $passwordcheck = $passwordcheck . $albumpasswordcheck;
 44:             }
 45:         }
 46:         $albumWhere = "WHERE `dynamic`=0 AND `show`=1" . $passwordcheck;
 47:     }
 48:     if ($subalbums) {
 49:         $albumWhere .= " AND `folder` LIKE " . db_quote(db_LIKE_escape($albumname) . "%");
 50:     } else {
 51:         $albumWhere .= " AND `folder` = " . db_quote($albumname);
 52:     }
 53:     $albumids = query_full_array("SELECT id, folder FROM " . prefix('albums') . $albumWhere);
 54:     switch ($mode) {
 55:         case "images":
 56:             if (count($albumids) == 0) {
 57:                 return FALSE;
 58:             } else {
 59:                 $imageWhere = " WHERE ";
 60:                 $count = "";
 61:                 foreach ($albumids as $albumid) {
 62:                     $count++;
 63:                     $imageWhere .= 'albumid=' . $albumid['id'];
 64:                     if ($count != count($albumids))
 65:                         $imageWhere .= " OR ";
 66:                 }
 67:             }
 68:             $imageids = query_full_array("SELECT id, albumid FROM " . prefix('images') . $imageWhere);
 69:             
 70:             if (count($imageids) == 0) {
 71:                 return FALSE;
 72:             } else {
 73:                 $count = "";
 74:                 $tagWhere = " WHERE ";
 75:                 foreach ($imageids as $imageid) {
 76:                     $count++;
 77:                     $tagWhere .= '(o.objectid =' . $imageid['id'] . " AND o.tagid = t.id AND o.type = 'images')";
 78:                     if ($count != count($imageids))
 79:                         $tagWhere .= " OR ";
 80:                 }
 81:             }
 82:             if (empty($tagWhere)) {
 83:                 return FALSE;
 84:             } else {
 85:                 $tags = query_full_array("SELECT DISTINCT t.name, t.id, (SELECT DISTINCT COUNT(*) FROM " . prefix('obj_to_tag') . " WHERE tagid = t.id AND type = 'images') AS count FROM  " . prefix('obj_to_tag') . " AS o," . prefix('tags') . " AS t" . $tagWhere . " ORDER BY t.name");
 86:             }
 87:             break;
 88:         case "albums":
 89:             $count = "";
 90:             if (count($albumids) == 0) {
 91:                 return FALSE;
 92:             } else {
 93:                 $tagWhere = " WHERE ";
 94:                 foreach ($albumids as $albumid) {
 95:                     $count++;
 96:                     $tagWhere .= '(o.objectid =' . $albumid['id'] . " AND o.tagid = t.id AND o.type = 'albums')";
 97:                     if ($count != count($albumids))
 98:                         $tagWhere .= " OR ";
 99:                 }
100:             }
101:             if (empty($tagWhere)) {
102:                 return FALSE;
103:             } else {
104:                 $tags = query_full_array("SELECT DISTINCT t.name, t.id, (SELECT DISTINCT COUNT(*) FROM " . prefix('obj_to_tag') . " WHERE tagid = t.id AND o.type = 'albums') AS count FROM " . prefix('obj_to_tag') . " AS o," . prefix('tags') . " AS t" . $tagWhere . " ORDER BY t.name");
105:             }
106:             break;
107:     }
108:     return $tags;
109: }
110: 
111: 112: 113: 114: 115: 
116: function getAllTagsFromZenpage($mode = 'news') {
117:     global $_zp_gallery, $_zp_zenpage;
118:     if (!extensionEnabled('zenpage')) {
119:         return FALSE;
120:     }
121:     $passwordcheck = '';
122:     $ids = array();
123:     $where = '';
124:     $tagWhere = "";
125:     switch ($mode) {
126:         case 'news':
127:             if (zp_loggedin(ZENPAGE_NEWS_RIGHTS | ALL_NEWS_RIGHTS)) {
128:                 $published = 'all';
129:             } else {
130:                 $published = 'published';
131:             }
132:             $type = 'news';
133:             $items = $_zp_zenpage->getArticles(false, $published);
134:             foreach ($items as $item) {
135:                 $obj = new ZenpageNews($item['titlelink']);
136:                 if ($obj->checkAccess()) {
137:                     $ids[] = $obj->getID();
138:                 }
139:             }
140:             break;
141:         case 'pages':
142:             $published = !zp_loggedin(ZENPAGE_NEWS_RIGHTS | ALL_NEWS_RIGHTS);
143:             $type = 'pages';
144:             $items = $_zp_zenpage->getPages($published);
145:             foreach ($items as $item) {
146:                 $obj = new ZenpagePage($item['titlelink']);
147:                 if ($obj->checkAccess()) {
148:                     $ids[] = $obj->getID();
149:                 }
150:             }
151:             break;
152:     }
153:     $count = '';
154:     if (count($ids) == 0) {
155:         return FALSE;
156:     } else {
157:         $tagWhere = " WHERE ";
158:         foreach ($ids as $id) {
159:             $count++;
160:             $tagWhere .= '(o.objectid =' . $id . " AND o.tagid = t.id AND o.type = '" . $type . "')";
161:             if ($count != count($ids))
162:                 $tagWhere .= " OR ";
163:         }
164:     }
165:     if (empty($tagWhere)) {
166:         return FALSE;
167:     } else {
168:         $tags = query_full_array("SELECT DISTINCT t.name, t.id, (SELECT DISTINCT COUNT(*) FROM " . prefix('obj_to_tag') . " WHERE tagid = t.id AND o.type = '" . $type . "') AS count FROM " . prefix('obj_to_tag') . " AS o," . prefix('tags') . " AS t" . $tagWhere . " ORDER BY t.name");
169:     }
170:     return $tags;
171: }
172: 
173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 
186: function printAllTagsFromZenpage($mode = 'news', $separator = '', $class = '', $showcounter = true, $tagcloud = true, $size_min = 1, $size_max = 5, $count_min = 1, $count_max = 50) {
187:     $tags = getAllTagsFromZenpage($mode);
188:     printAllTags($tags, $mode, $separator, $class, $showcounter, $tagcloud, $size_min, $size_max, $count_min, $count_max);
189: }
190: 
191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 
207: function printAllTagsFromAlbum($albumname = "", $subalbums = false, $mode = 'images', $separator = '', $class = '', $showcounter = true, $tagcloud = true, $size_min = 1, $size_max = 5, $count_min = 1, $count_max = 50) {
208:     if ($mode == 'all') {
209:         if (getAllTagsFromAlbum($albumname, $subalbums, 'albums') OR getAllTagsFromAlbum($albumname, $subalbums, 'images')) {
210:             $showcounter = false;
211:             $tags1 = getAllTagsFromAlbum($albumname, $subalbums, 'albums');
212:             $tags2 = getAllTagsFromAlbum($albumname, $subalbums, 'images');
213:             $tags = array_merge($tags1, $tags2);
214:             $tags = getAllTagsFromAlbum_multi_unique($tags);
215:         } else {
216:             return FALSE;
217:         }
218:     } else {
219:         if (getAllTagsFromAlbum($albumname, $subalbums, $mode)) {
220:             $tags = getAllTagsFromAlbum($albumname, $subalbums, $mode);
221:         } else {
222:             return FALSE;
223:         }
224:     }
225:     printAllTags($tags, $mode, $separator, $class, $showcounter, $tagcloud, $size_min, $size_max, $count_min, $count_max);
226: }
227: 
228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 
244: function printAllTags($tags, $mode, $separator = '', $class = '', $showcounter = true, $tagcloud = true, $size_min = 1, $size_max = 5, $count_min = 1, $count_max = 50) {
245:     if (!is_array($tags)) {
246:         return FALSE;
247:     }
248:     $size_min = sanitize_numeric($size_min);
249:     $size_max = sanitize_numeric($size_max);
250:     $count_min = sanitize_numeric($count_min);
251:     $count_max = sanitize_numeric($count_max);
252:     $separator = sanitize($separator);
253:     if (!empty($class))
254:         $class = 'class="' . sanitize($class) . '"';
255:     $counter = '';
256:     echo "<ul " . $class . ">\n";
257:     $loopcount = '';
258:     $tagcount = count($tags);
259:     foreach ($tags as $row) {
260:         if ($row['count'] >= $count_min) {
261:             $loopcount++;
262:             $count = $row['count'];
263:             $tid = $row['id'];
264:             $tname = $row['name'];
265:             $style = "";
266:             if ($tagcloud OR $mode == 'all') {
267:                 $size = min(max(round(($size_max * ($count - $count_min)) / ($count_max - $count_min), 2), $size_min)
268:                                 , $size_max);
269:                 $size = str_replace(',', '.', $size);
270:                 $style = " style=\"font-size:" . $size . "em;\"";
271:             }
272:             if ($showcounter) {
273:                 $counter = ' (' . $count . ')';
274:             }
275:             if ($loopcount == $tagcount)
276:                 $separator = '';
277:             echo "<li><a class=\"tagLink\" href=\"" . html_encode(getSearchURL($tname, '', 'tags', 0)) . "\"" . $style . ">" . $tname . $counter . "</a>" . $separator . "</li>\n";
278:         }
279:     }
280:     echo "</ul>\n";
281: }
282: 
283: 284: 285: 286: 287: 288: 
289: function getAllTagsFromAlbum_multi_unique($array) {
290:     foreach ($array as $k => $na)
291:         $new[$k] = serialize($na);
292:     $uniq = array_unique($new);
293:     foreach ($uniq as $k => $ser)
294:         $new1[$k] = getSerializedArray($ser);
295:     return ($new1);
296: }
297: 
298: ?>
299: