1: <?php
2: 3: 4: 5: 6: 7:
8: $plugin_description = gettext('Provides functionality to get the related items to an item based on a tag search.');
9: $plugin_author = "Malte Müller (acrylian)";
10:
11: function getRelatedItems($type = 'news', $album = NULL) {
12: global $_zp_gallery, $_zp_current_album, $_zp_current_image, $_zp_current_zenpage_page, $_zp_current_zenpage_news, $_zp_gallery_page;
13: $tags = getTags();
14: if (!empty($tags)) {
15: $searchstring = '';
16: $count = '';
17: foreach ($tags as $tag) {
18: $count++;
19: if ($count == 1) {
20: $bool = '';
21: } else {
22: $bool = '|';
23: }
24: $searchstring .= $bool . $tag;
25: }
26: $paramstr = urlencode('words') . '=' . $searchstring . '&searchfields=tags';
27: if (!is_null($album)) {
28: $paramstr = '&albumname=' . urlencode($album);
29: }
30: $search = new SearchEngine();
31: switch ($type) {
32: case 'albums':
33: $paramstr .= '&inalbums=1';
34: break;
35: case 'images':
36: $paramstr .= '&inimages=1';
37: break;
38: case 'news':
39: $paramstr .= '&innews=1';
40: break;
41: case 'pages':
42: $paramstr .= '&inpages=1';
43: break;
44: case 'all':
45: $paramstr .= '&inalbums=1&inimages=1&innews=1&inpages=1';
46: break;
47: }
48: $search->setSearchParams($paramstr);
49:
50: switch ($type) {
51: case 'albums':
52: $albumresult = $search->getAlbums(0, "date", "desc");
53: $result = createRelatedItemsResultArray($albumresult, $type);
54: break;
55: case 'images':
56: $imageresult = $search->getImages(0, 0, 'date', 'desc');
57: $result = createRelatedItemsResultArray($imageresult, $type);
58: break;
59: case 'news':
60: $newsresult = $search->getArticles(0, NULL, true, "date", "desc");
61: $result = createRelatedItemsResultArray($newsresult, $type);
62: break;
63: case 'pages':
64: $pageresult = $search->getPages();
65: $result = createRelatedItemsResultArray($pageresult, $type);
66: break;
67: case 'all':
68: $albumresult = $search->getAlbums(0, "date", "desc");
69: $imageresult = $search->getImages(0, 0, 'date', 'desc');
70: $newsresult = $search->getArticles(0, NULL, true, "date", "desc");
71: $pageresult = $search->getPages();
72: $result1 = createRelatedItemsResultArray($albumresult, 'albums');
73: $result2 = createRelatedItemsResultArray($imageresult, 'images');
74: $result3 = createRelatedItemsResultArray($newsresult, 'news');
75: $result4 = createRelatedItemsResultArray($pageresult, 'pages');
76: $result = array_merge($result1, $result2, $result3, $result4);
77: $result = sortMultiArray($result, 'weight', true, true, false, false);
78: break;
79: }
80: return $result;
81: }
82: return array();
83: }
84:
85: 86: 87: 88: 89: 90: 91: 92:
93: function createRelatedItemsResultArray($result, $type) {
94: global $_zp_gallery, $_zp_current_album, $_zp_current_image, $_zp_current_zenpage_page, $_zp_current_zenpage_news, $_zp_gallery_page;
95: switch ($_zp_gallery_page) {
96: case 'album.php':
97: $current = $_zp_current_album;
98: break;
99: case 'image.php':
100: $current = $_zp_current_image;
101: break;
102: case 'news.php':
103: $current = $_zp_current_zenpage_news;
104: break;
105: case 'pages.php':
106: $current = $_zp_current_zenpage_page;
107: break;
108: }
109: $results = array();
110: foreach ($result as $item) {
111: switch ($type) {
112: case 'albums':
113: if (!isAlbumClass($current) || $current->name != $item) {
114: array_push($results, array('name' => $item, 'album' => '', 'type' => $type, 'weight' => '13'));
115: }
116: break;
117: case 'images':
118: if (!isImageClass($current) || $current->filename != $item['filename']) {
119: array_push($results, array('name' => $item['filename'], 'album' => $item['folder'], 'type' => $type, 'weight' => $item['weight']));
120: }
121: break;
122: case 'news':
123: if (get_class($current) != 'ZenpageNews' || $current->getTitlelink() != $item['titlelink']) {
124:
125: if (!isset($item['weight']))
126: $item['weight'] = 13;
127:
128: array_push($results, array('name' => $item['titlelink'], 'album' => '', 'type' => $type, 'weight' => $item['weight']));
129: }
130: break;
131: case 'pages':
132: if (get_class($current) != 'ZenpagePage' || $current->getTitlelink() != $item) {
133: array_push($results, array('name' => $item, 'album' => '', 'type' => $type, 'weight' => '13'));
134: }
135: break;
136: }
137: }
138: return $results;
139: }
140:
141: 142: 143: 144: 145: 146: 147: 148: 149:
150: function printRelatedItems($number = 5, $type = 'news', $specific = NULL, $excerpt = NULL, $thumb = false, $date = false) {
151: global $_zp_gallery, $_zp_current_album, $_zp_current_image, $_zp_current_zenpage_page, $_zp_current_zenpage_news;
152: $label = array('albums' => gettext('Albums'), 'images' => gettext('Images'), 'news' => gettext('News'), 'pages' => gettext('Pages'));
153: $result = getRelatedItems($type, $specific);
154: $resultcount = count($result);
155: if ($resultcount != 0) {
156: ?>
157: <h3 class="relateditems">
158: <?php printf(gettext('Related %s'), $type); ?>
159: </h3>
160: <ul id="relateditems">
161: <?php
162: $count = 0;
163: foreach ($result as $item) {
164: $count++;
165: ?>
166: <li class="<?php echo $item['type']; ?>">
167: <?php
168: $category = '';
169: switch ($item['type']) {
170: case 'albums':
171: $obj = newAlbum($item['name']);
172: $url = $obj->getLink();
173: $text = $obj->getDesc();
174: $category = gettext('Album');
175: break;
176: case 'images':
177: $alb = newAlbum($item['album']);
178: $obj = newImage($alb, $item['name']);
179: $url = $obj->getLink();
180: $text = $obj->getDesc();
181: $category = gettext('Image');
182: break;
183: case 'news':
184: $obj = new ZenpageNews($item['name']);
185: $url = $obj->getLink();
186: $text = $obj->getContent();
187: $category = gettext('News');
188: break;
189: case 'pages':
190: $obj = new ZenpagePage($item['name']);
191: $url = $obj->getLink();
192: $text = $obj->getContent();
193: $category = gettext('Page');
194: break;
195: }
196: ?>
197: <?php
198: if ($thumb) {
199: $thumburl = false;
200: switch ($item['type']) {
201: case 'albums':
202: $thumburl = $obj->getThumb();
203: break;
204: case 'images':
205: $thumburl = $obj->getThumb();
206: break;
207: }
208: if ($thumburl) {
209: ?>
210: <a href="<?php echo html_encode(pathurlencode($url)); ?>" title="<?php echo html_encode($obj->getTitle()); ?>" class="relateditems_thumb">
211: <img src="<?php echo html_encode(pathurlencode($thumburl)); ?>" alt="<?php echo html_encode($obj->getTitle()); ?>" />
212: </a>
213: <?php
214: }
215: }
216: ?>
217: <h4><a href="<?php echo html_encode(pathurlencode($url)); ?>" title="<?php echo html_encode($obj->getTitle()); ?>"><?php echo html_encode($obj->getTitle()); ?></a>
218: <?php
219: if ($date) {
220: switch ($item['type']) {
221: case 'albums':
222: case 'images':
223: $d = $obj->getDateTime();
224: break;
225: case 'news':
226: case 'pages':
227: $d = $obj->getDateTime();
228: break;
229: }
230: ?>
231: <span class="relateditems_date">
232: <?php echo zpFormattedDate(DATE_FORMAT, strtotime($d)); ?>
233: </span>
234: <?php
235: }
236: ?>
237: <?php if ($type == 'all') { ?> (<small><?php echo $category; ?></small>)<?php } ?>
238:
239: </h4>
240: <?php
241: if ($excerpt) {
242: echo shortenContent($text, $excerpt, '...', true);
243: }
244: ?>
245: </li>
246: <?php
247: if ($count == $number) {
248: break;
249: }
250: }
251: if ($count) {
252: ?>
253: </ul>
254: <?php
255: }
256: }
257: }
258: ?>