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