silverstripe-picasaweb 

silverstripe-picasaweb Commit Details

Date:2013-05-02 09:13:56 (7 years 11 months ago)
Author:Nicola Fontana
Branch:master
Commit:e76ae3596448eb8a4c7797eaeb3e78803d2f04ea
Message:Initial commit

Changes:
A_config.php (full)
Acode/Picasaweb.php (full)
Atemplates/Picasaweb_image.ss (full)

File differences

_config.php
1
2
3
4
5
6
<?php
// TODO: Object::add_extension('SiteConfig', 'PicasawebConfig');
Object::add_extension('Page', 'PicasawebExtension');
ShortcodeParser::get()->register('picasa', array('Picasaweb', 'shortcode'));
code/Picasaweb.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
class Picasaweb {
public static $render_image = true;
public static $render_album = true;
const IMAGE_REGEX = '#https://picasaweb.google.com/\S*/photo/\S*#';
const ALBUM_REGEX = '#https://picasaweb.google.com/\S*#';
private static function renderImage($url) {
$viewer = new SSViewer('Picasaweb_image');
$data = new ArrayData(array(
'url' => $url
));
return $data->renderWith($viewer);
}
private static function renderAlbum($url) {
return 'Rendering the album';
}
/**
* Renders the given URL as a Picasaweb image or album.
*
* @param url
* The string returned is captured from print_r(). It is
* intended to be used for debugging purpose.
*
* @param String $url The URL to render.
* @returns A ready to use HTML chunk or null on errors.
*/
public static function render($url) {
if (self::$render_image && preg_match(self::IMAGE_REGEX, $url))
return self::renderImage($url);
if (self::$render_album && preg_match(self::ALBUM_REGEX, $url))
return self::renderAlbum($url);
return null;
}
public static function shortcode($arguments, $url = '') {
$result = self::render($url);
if (is_null($result)) {
$url = htmlentities($url, ENT_COMPAT, 'UTF-8');
return "<div>Invalid PicasaWeb url given ($url)</div>";
}
return $result;
}
};
class PicasawebExtension extends DataExtension {
private static function renderer($matches) {
// Paranoic check, because in PHP we don't trust...
if (! isset($matches, $matches[0]))
return '';
$url = $matches[0];
$html = Picasaweb::render($url);
return isset($html) ? $html : $url;
}
function onBeforeWrite() {
parent::onBeforeWrite();
if (empty($this->owner->Content))
return;
// Pass every link to the callback: self::renderer() will
// modify only PicasaWeb links
$this->owner->Content = preg_replace_callback('#https?://\S*#',
'self::renderer',
$this->owner->Content);
}
};
templates/Picasaweb_image.ss
1
2
3
4
<div style="float: right;" class="caption">
<a href="http://lh4.ggpht.com/-C5nYltm_9lY/UDYslCJB6AI/AAAAAAAADdg/75nHsCgFisE/000.jpeg" title="Coppa Ernesto della Torre 2012: Marco Pedrini e Mauro Bosio" style="float: none;" class="picasa2"><img height="192" width="288" alt="Coppa Ernesto della Torre 2012: Marco Pedrini e Mauro Bosio" src="http://lh4.ggpht.com/-C5nYltm_9lY/UDYslCJB6AI/AAAAAAAADdg/75nHsCgFisE/s288/000.jpeg"></a>
<p class="caption-title">Coppa Ernesto della Torre 2012: Marco Pedrini e Mauro Bosio</p>
</div>

Archive Download the corresponding diff file

Branches