silverstripe-picasaweb 

silverstripe-picasaweb Commit Details

Date:2013-05-06 23:15:50 (7 years 11 months ago)
Author:Nicola Fontana
Branch:master
Commit:d74e18a8c3fd19eb0081c2d86367422ea4c2f738
Parents: bdf4891f4b97a037d8ae97b189f59dedadf01d2b
Message:Expect a $ before the Picasaweb link to expand

By forcing the presence of a prefix ($) on Picasaweb link to trigger the
expansion, the same links can be used in the templates without falling
into a recursive expansions issue.
Changes:
M_config.php (1 diff)
Mcode/Picasaweb.php (5 diffs)
Mtemplates/Picasaweb_image.ss (1 diff)

File differences

_config.php
2222
2323
2424
25
26
27
28
25
26
27
2928
3029
3130
3231
3332
34
35
33
34
35
3636
3737
3838
* </code>
*
* A specific page type can be augmented by providing a onBeforeWrite()
* callback so that the user can just paste a Picasaweb link inside the
* HTML code to get a specific photo or album element. Be careful: in
* this case you CANNOT use the Picasaweb link in your templates
* otherwise the expansion will be triggered recursively.
* callback so that the user can just paste a Picasaweb link prefixed
* by a dollar sign ($) inside the HTML code to get a specific photo or
* album element.
*
* <code>
* Object::add_extension('Page', 'PicasawebExtension');
* </code>
*
* The expansion of the links happens before storing the HTML code in
* the database, avoiding further Picasaweb requests on page hits.
* In this case, the expansion of the links happens before storing the
* HTML code in the database, avoiding further Picasaweb requests on
* every page hit.
*
*
* @todo implement an Object::add_extension('SiteConfig', 'PicasawebConfig')
code/Picasaweb.php
362362
363363
364364
365
366
367
368
365
366
369367
370368
371369
......
397395
398396
399397
400
398
401399
402400
403401
......
408406
409407
410408
411
409
412410
413411
414412
......
420418
421419
422420
423
421
422
424423
425424
426425
......
431430
432431
433432
434
433
435434
436435
437436
$album = @$match[2];
$photo = @$match[4];
// If the PicasawebExtension is enabled, embedding $url in
// templates will result in a recursive expansion. This is the
// rationale behind the stripping of the scheme.
$fields = array('url' => preg_replace('"https?://"', '', $url));
// Add the request URL to the available fields
$fields = array('url' => $url);
return self::render($user, $album, $photo, $fields);
}
/**
* Callback for Picasaweb URL expansion.
*
* Used by onBeforeWrite() to expand *only* the Picasaweb links.
* Used by onBeforeWrite() to expand *only* valid Picasaweb links.
*
* @param Array $matches The result of preg_match().
* @return String The rendered HTML chunk for Picasaweb
if (! isset($matches, $matches[0]))
return '';
$url = $matches[0];
$url = substr($matches[0], 1);
$html = Picasaweb::renderUrl($url);
return isset($html) ? $html : $url;
}
* chunk (customizable throught templates) the Picasaweb ones.
*
* A Picasaweb link is supposed to be a *user* link, that is the
* URL shown while browsing the Picasaweb site.
* URL shown while browsing the Picasaweb site, prefixed by the
* dollar sign.
*/
function onBeforeWrite() {
parent::onBeforeWrite();
// Pass every link to the callback: self::renderer() will
// modify only valid PicasaWeb links
$this->owner->Content = preg_replace_callback('"https?://[-A-Za-z0-9+&@#/%?=~_()|!:,.;]*"',
$this->owner->Content = preg_replace_callback('"\$https?://[-A-Za-z0-9+&@#/%?=~_()|!:,.;]*"',
'self::renderer',
$content);
}
templates/Picasaweb_image.ss
1
1
<a href="$zoomed.src.ATT" title="$summary.ATT" class="picasa2"><% with thumbnail %><img width="$width" height="$height" alt="$Top.summary.ATT"<% if Top.url %> title="$Top.url"<% end_if %> 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"<% if Top.alternate %> title="$Top.alternate"<% end_if %> src="$src"><% end_with %></a>

Archive Download the corresponding diff file

Branches