1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11: class Ansel_Widget_SimilarPhotos extends Ansel_Widget_Base
12: {
13: 14: 15: 16: 17:
18: protected $_supported_views = array('Image');
19:
20: 21: 22: 23: 24: 25: 26:
27: public function __construct($params)
28: {
29: parent::__construct($params);
30: $this->_title = _("Similar Photos");
31: }
32:
33: 34: 35: 36: 37:
38: public function html()
39: {
40: $html = $this->_htmlBegin();
41: $html .= '<div id="similar">' . $this->_getRelatedImages() . '</div>';
42: $html .= $this->_htmlEnd();
43:
44: return $html;
45: }
46:
47: 48: 49: 50: 51: 52:
53: public function _getRelatedImages()
54: {
55: $ansel_storage = $GLOBALS['injector']->getInstance('Ansel_Storage');
56:
57: $html = '';
58: $args = array('typeId' => 'image',
59: 'userId' => $this->_view->gallery->get('owner'));
60:
61: $results = $GLOBALS['injector']->getInstance('Ansel_Tagger')->listRelatedImages($this->_view->resource);
62: if (count($results)) {
63: $i = 0;
64: foreach ($results as $result) {
65: $img = $result['image'];
66: $rGal = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($img->gallery);
67: if ($rGal->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::READ))
68: $html .= Ansel::getUrlFor(
69: 'view',
70: array('image' => $img->id,
71: 'view' => 'Image',
72: 'gallery' => $img->gallery,
73: 'slug' => $rGal->get('slug')),
74: true)->link(array('title' => sprintf(_("%s from %s"), $img->filename, $rGal->get('name'))))
75: . '<img src="'. Ansel::getImageUrl($img->id, 'mini', true) . '" alt="' . htmlspecialchars($img->filename) . '" /></a>';
76: $i++;
77: }
78: }
79:
80: return $html;
81: }
82:
83: }
84: