1: <?php
2: /**
3: * The Ansel_Style:: class is responsible for holding information about a
4: * single Ansel style.
5: *
6: * See the enclosed file COPYING for license information (GPL). If you
7: * did not receive this file, see http://www.horde.org/licenses/gpl.
8: *
9: * @author Michael J. Rubinsky <mrubinsk@horde.org>
10: *
11: * @package Ansel
12: */
13: class Ansel_Style
14: {
15: /**
16: * Holds the style definition. Currently supported properties are:
17: * <pre>
18: * 'thumbstyle' - The ImageGenerator to use for thumbnails,
19: * e.g. PolaroidThumb or RoundedThumb
20: * 'background' - The background color of the view area. If needed,
21: * generated images will contain this as their
22: * background color.
23: * 'gallery_view' - The GalleryRenderer type to use for the gallery
24: * view, e.g. GalleryLightbox or Gallery.
25: * 'widgets' - An array of widgets and their configuration values
26: * to display on the gallery view.
27: * e.g. Array('Geotag' => array(),
28: * 'Tags' => array('view' => 'gallery'))
29: * 'width' - Optional width of generated thumbnails.
30: * 'height' - Option height of generated thumbnails.
31: * 'image_widgets' - @TODO: not yet implemented.
32: * </pre>
33: *
34: * @var array
35: */
36: protected $_properties;
37:
38: /**
39: * Work around issue with arrays and __get
40: */
41: public $widgets = array();
42:
43: public function __construct($properties)
44: {
45: $widgets = !empty($properties['widgets']) ? $properties['widgets'] : array();
46: unset($properties['widgets']);
47: $properties['widgets'] = null;
48: $this->widgets = array_merge(array('Actions' => array()), $widgets);
49:
50: $this->_properties = array_merge(
51: array(
52: 'gallery_view' => 'Gallery',
53: 'background' => 'none'),
54: $properties);
55: }
56:
57: /**
58: * Return if this style requires PNG support in the browser. Assumes that
59: * any thumbstyle other than the traditional "Thumb", withOUT a background
60: * is considered to requre PNG support in the browser.
61: *
62: * @return boolean
63: */
64: public function requiresPng()
65: {
66: return ($this->_properties['thumbstyle'] != 'Thumb' && $this->_properties['background'] == 'none');
67: }
68:
69: public function getHash($view)
70: {
71: if ($view != 'screen' && $view != 'mini' && $view != 'full') {
72: $view = md5($this->thumbstyle . '.' . $this->background . (!empty($this->width) ? $this->width : '') . (!empty($this->height) ? $this->height : ''));
73: }
74:
75: return $view;
76: }
77:
78: public function __get($property)
79: {
80: if ($property == 'keyimage_type') {
81: // Force the same type of effect for key image/stacks if available
82: $class = $this->_properties['thumbstyle'] . 'Stack';
83: if (!class_exists('Ansel_ImageGenerator_' . $class)) {
84: $class = 'Thumb';
85: }
86:
87: return $class;
88: }
89:
90: return !empty($this->_properties[$property]) ? $this->_properties[$property] : null;
91: }
92:
93: public function __set($property, $value)
94: {
95: switch ($property) {
96: case 'thumbstyle':
97: case 'background':
98: case 'width':
99: case 'height':
100: $this->_properties[$property] = $value;
101: break;
102: default:
103: throw new Ansel_Exception('Invalid property');
104: }
105: }
106:
107: public function __isset($property)
108: {
109: return !empty($property);
110: }
111:
112: /**
113: * HACK - not sure how to upgrade the serialized Ansel_Style objects in the
114: * stored galleries... the data is protected, so unserializing it wouldn't
115: * give access to the needed information to move it.
116: */
117: public function __wakeup()
118: {
119: if (!empty($this->_properties['widgets'])) {
120: $this->widgets = $this->_properties['widgets'];
121: unset($this->_properties['widgets']);
122: }
123: }
124:
125: }
126:
127: