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:
<?php
$plugin_description = gettext('Provides functionality to get the related items to an item based on a tag search.');
$plugin_author = "Malte Müller (acrylian)";
$plugin_category = gettext('Media');
function getRelatedItems($type = 'news', $album = NULL) {
global $_zp_gallery, $_zp_current_album, $_zp_current_image, $_zp_current_zenpage_page, $_zp_current_zenpage_news, $_zp_gallery_page;
$tags = getTags();
if (!empty($tags)) {
$searchstring = '';
$count = '';
foreach ($tags as $tag) {
$count++;
if ($count == 1) {
$bool = '';
} else {
$bool = '|';
}
$searchstring .= $bool . $tag;
}
$paramstr = urlencode('words') . '=' . $searchstring . '&searchfields=tags';
if (!is_null($album)) {
$paramstr = '&albumname=' . urlencode($album);
}
$search = new SearchEngine();
switch ($type) {
case 'albums':
$paramstr .= '&inalbums=1';
break;
case 'images':
$paramstr .= '&inimages=1';
break;
case 'news':
$paramstr .= '&innews=1';
break;
case 'pages':
$paramstr .= '&inpages=1';
break;
case 'all':
$paramstr .= '&inalbums=1&inimages=1&innews=1&inpages=1';
break;
}
$search->setSearchParams($paramstr);
switch ($type) {
case 'albums':
$albumresult = $search->getAlbums(0, "date", "desc");
$result = createRelatedItemsResultArray($albumresult, $type);
break;
case 'images':
$imageresult = $search->getImages(0, 0, 'date', 'desc');
$result = createRelatedItemsResultArray($imageresult, $type);
break;
case 'news':
$newsresult = $search->getArticles(0, NULL, true, "date", "desc");
$result = createRelatedItemsResultArray($newsresult, $type);
break;
case 'pages':
$pageresult = $search->getPages();
$result = createRelatedItemsResultArray($pageresult, $type);
break;
case 'all':
$albumresult = $search->getAlbums(0, "date", "desc");
$imageresult = $search->getImages(0, 0, 'date', 'desc');
$newsresult = $search->getArticles(0, NULL, true, "date", "desc");
$pageresult = $search->getPages();
$result1 = createRelatedItemsResultArray($albumresult, 'albums');
$result2 = createRelatedItemsResultArray($imageresult, 'images');
$result3 = createRelatedItemsResultArray($newsresult, 'news');
$result4 = createRelatedItemsResultArray($pageresult, 'pages');
$result = array_merge($result1, $result2, $result3, $result4);
$result = sortMultiArray($result, 'weight', true, true, false, false);
break;
}
return $result;
}
return array();
}
function createRelatedItemsResultArray($result, $type) {
global $_zp_gallery, $_zp_current_album, $_zp_current_image, $_zp_current_zenpage_page, $_zp_current_zenpage_news, $_zp_gallery_page;
switch ($_zp_gallery_page) {
case 'album.php':
$current = $_zp_current_album;
break;
case 'image.php':
$current = $_zp_current_image;
break;
case 'news.php':
$current = $_zp_current_zenpage_news;
break;
case 'pages.php':
$current = $_zp_current_zenpage_page;
break;
}
$results = array();
foreach ($result as $item) {
switch ($type) {
case 'albums':
if (!isAlbumClass($current) || $current->name != $item) {
array_push($results, array('name' => $item, 'album' => '', 'type' => $type, 'weight' => '13'));
}
break;
case 'images':
if (!isImageClass($current) || $current->filename != $item['filename']) {
array_push($results, array('name' => $item['filename'], 'album' => $item['folder'], 'type' => $type, 'weight' => $item['weight']));
}
break;
case 'news':
if (get_class($current) != 'ZenpageNews' || $current->getTitlelink() != $item['titlelink']) {
if (!isset($item['weight']))
$item['weight'] = 13;
array_push($results, array('name' => $item['titlelink'], 'album' => '', 'type' => $type, 'weight' => $item['weight']));
}
break;
case 'pages':
if (get_class($current) != 'ZenpagePage' || $current->getTitlelink() != $item) {
array_push($results, array('name' => $item, 'album' => '', 'type' => $type, 'weight' => '13'));
}
break;
}
}
return $results;
}
function printRelatedItems($number = 5, $type = 'news', $specific = NULL, $excerpt = NULL, $thumb = false, $date = false) {
global $_zp_gallery, $_zp_current_album, $_zp_current_image, $_zp_current_zenpage_page, $_zp_current_zenpage_news;
$label = array('albums' => gettext('Albums'), 'images' => gettext('Images'), 'news' => gettext('News'), 'pages' => gettext('Pages'));
$result = getRelatedItems($type, $specific);
$resultcount = count($result);
if ($resultcount != 0) {
?>
<h3 class="relateditems">
<?php printf(gettext('Related %s'), $type); ?>
</h3>
<ul id="relateditems">
<?php
$count = 0;
foreach ($result as $item) {
$count++;
?>
<li class="<?php echo $item['type']; ?>">
<?php
$category = '';
switch ($item['type']) {
case 'albums':
$obj = newAlbum($item['name']);
$url = $obj->getLink();
$text = $obj->getDesc();
$category = gettext('Album');
break;
case 'images':
$alb = newAlbum($item['album']);
$obj = newImage($alb, $item['name']);
$url = $obj->getLink();
$text = $obj->getDesc();
$category = gettext('Image');
break;
case 'news':
$obj = new ZenpageNews($item['name']);
$url = $obj->getLink();
$text = $obj->getContent();
$category = gettext('News');
break;
case 'pages':
$obj = new ZenpagePage($item['name']);
$url = $obj->getLink();
$text = $obj->getContent();
$category = gettext('Page');
break;
}
?>
<?php
if ($thumb) {
$thumburl = false;
switch ($item['type']) {
case 'albums':
$thumburl = $obj->getThumb();
break;
case 'images':
$thumburl = $obj->getThumb();
break;
}
if ($thumburl) {
?>
<a href="<?php echo html_encode(pathurlencode($url)); ?>" title="<?php echo html_encode($obj->getTitle()); ?>" class="relateditems_thumb">
<img src="<?php echo html_encode(pathurlencode($thumburl)); ?>" alt="<?php echo html_encode($obj->getTitle()); ?>" />
</a>
<?php
}
}
?>
<h4><a href="<?php echo html_encode(pathurlencode($url)); ?>" title="<?php echo html_encode($obj->getTitle()); ?>"><?php echo html_encode($obj->getTitle()); ?></a>
<?php
if ($date) {
switch ($item['type']) {
case 'albums':
case 'images':
$d = $obj->getDateTime();
break;
case 'news':
case 'pages':
$d = $obj->getDateTime();
break;
}
?>
<span class="relateditems_date">
<?php echo zpFormattedDate(DATE_FORMAT, strtotime($d)); ?>
</span>
<?php
}
?>
<?php if ($type == 'all') { ?> (<small><?php echo $category; ?></small>)<?php } ?>
</h4>
<?php
if ($excerpt) {
echo shortenContent($text, $excerpt, '...', true);
}
?>
</li>
<?php
if ($count == $number) {
break;
}
}
if ($count) {
?>
</ul>
<?php
}
}
}
?>