silverstripe-picasaweb 

silverstripe-picasaweb Commit Details

Date:2013-05-03 17:18:26 (7 years 11 months ago)
Author:Nicola Fontana
Branch:master
Commit:f3897effccce6629a5245125cfe1a7ed140681f0
Parents: d1f1582329e6f47f72307e0014adc092ea872f6f
Message:Thumbnail and zoomed images can be customized

Two new static properties has been added to the Picasaweb class to
select the desired thumbnail and zoomed images. The selection can be a
string, in which case it is expected to be a yet existing image field,
such as 'thumbnail2' or 'normal', or a size in pixel, in which case a
request for that specific size will be forwarded to Picasaweb.
from the availables formats (no
Changes:
M_config.php (1 diff)
Mcode/Picasaweb.php (3 diffs)
Mtemplates/Picasaweb_image.ss (1 diff)

File differences

_config.php
3737
3838
3939
40
40
41
4142
*
* @todo implement an Object::add_extension('SiteConfig', 'PicasawebConfig')
* for customizing the global Picasaweb environment, that is
* photo and/or album rendering activation.
* photo and/or album rendering activation and the default
* thumbnail or zoomed images.
*/
code/Picasaweb.php
66
77
88
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
933
1034
1135
......
100124
101125
102126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
103151
104152
105153
......
142190
143191
144192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
145211
146212
147213
public static $render_album = true;
/**
* The default image to use when requesting a generic 'thumbnail'
* element from the templates.
*
* You can use a string value identifying the field to use,
* such as 'thumbnail1' or 'thumbnail2', or an integer value to
* request a specific size, such as 288.
*
* @return String|Int The thumbnail image or the requested size.
*/
public static $thumbnail = 'thumbnail3';
/**
* The default image to use when requesting a generic 'zoomed'
* element from the templates.
*
* You can use a string value identifying the field to use,
* such as 'normal' or 'thumbnail3', or an integer value to
* request a specific size, such as 800.
*
* @return String The zoomed image or the requested size.
*/
public static $zoomed = 'normal';
/**
* Get a SimpleXMLElement from the wild.
}
/**
* Get the metadata of a custom sized image.
*
* Forcing a specific size in Picasaweb can be done by adjusting
* the URL of a thumbnail: it actually ends with "/s$size/filename"
* where $size is the requested size of the image, so changing it
* will supposedly change the image.
*
* The new image does not have size information, so only the "src"
* field is actually returned.
*
* @param ArrayData $thumbnail Metadata of one thumbnail.
* @return ArrayData Metadata for the custom image.
*/
private static function customImage(ArrayData $thumbnail, $new_size) {
$url = preg_replace('"/s\d+(?:\-c)?/([^/]+)$"',
"/s$new_size/$1",
$thumbnail->src);
return new ArrayData(array(
'src' => $url
));
}
/**
* Return the metadata of a photo.
*
* Gets some metadata from a photo. The XML element is
++$n;
}
// Set the default thumbnail image
$image = null;
if (is_string(self::$thumbnail)) {
$image = $data->getField(self::$thumbnail);
} elseif (is_int(self::$thumbnail)) {
$image = self::customImage($data->thumbnail1, self::$thumbnail);
}
isset($image) and $data->setField('thumbnail', $image);
// Set the default zoomed image
$image = null;
if (is_string(self::$zoomed)) {
$image = $data->getField(self::$zoomed);
} elseif (is_int(self::$zoomed)) {
$image = self::customImage($data->thumbnail1, self::$zoomed);
}
isset($image) and $data->setField('zoomed', $image);
return $data;
}
templates/Picasaweb_image.ss
1
1
<a href="$normal.src.ATT" title="$summary.ATT" class="picasa2"><% with thumbnail3 %><img width="$width" height="$height" alt="$Top.summary.ATT" title="$Top.url" src="$src"><% end_with %></a>
<a href="$zoomed.src.ATT" title="$summary.ATT" class="picasa2"><% with thumbnail %><img width="$width" height="$height" alt="$Top.summary.ATT" title="$Top.url" src="$src"><% end_with %></a>

Archive Download the corresponding diff file

Branches