aboutsummaryrefslogtreecommitdiffstats
path: root/include/widgets.php
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2014-11-20 15:34:49 -0800
committerfriendica <info@friendica.com>2014-11-20 15:34:49 -0800
commitafd8b2ddf25d3486d200f9da8ff3cd74131a1df4 (patch)
treeb1ba2e4757bf874321a58e6869d4dd5a34d11bf2 /include/widgets.php
parent7a1b345bc2b4ef6d7f9e1c37a3e3ab689ebc6fb0 (diff)
downloadvolse-hubzilla-afd8b2ddf25d3486d200f9da8ff3cd74131a1df4.tar.gz
volse-hubzilla-afd8b2ddf25d3486d200f9da8ff3cd74131a1df4.tar.bz2
volse-hubzilla-afd8b2ddf25d3486d200f9da8ff3cd74131a1df4.zip
random photo widget
Diffstat (limited to 'include/widgets.php')
-rw-r--r--include/widgets.php56
1 files changed, 55 insertions, 1 deletions
diff --git a/include/widgets.php b/include/widgets.php
index 74bdb5d74..7193850ef 100644
--- a/include/widgets.php
+++ b/include/widgets.php
@@ -810,7 +810,61 @@ function widget_photo($arr) {
$o .= '<img ' . (($zrl) ? ' class="zrl" ' : '')
. (($style) ? ' style="' . $style . '"' : '')
- . ' src="' . $url . '" />';
+ . ' src="' . $url . '" alt="' . t('photo/image') . '" />';
+
+ $o .= '</div>';
+
+ return $o;
+}
+
+
+function widget_photo_rand($arr) {
+
+ require_once('include/photos.php');
+ $style = $zrl = false;
+ $params = '';
+ if(array_key_exists('album',$arr) && isset($arr['album']))
+ $album = $arr['album'];
+ else
+ $album = '';
+
+ $channel_id = get_app()->profile_uid;
+ if(! $channel_id)
+ return '';
+
+ $scale = ((array_key_exists('scale',$arr)) ? intval($arr['scale']) : 0);
+
+ $ret = photos_list_photos(array('channel_id' => $channel_id),get_app()->get_observer(),$album);
+
+ $filtered = array();
+ if($ret['success'] && $ret['photos'])
+ foreach($ret['photos'] as $p)
+ if($p['scale'] == $scale)
+ $filtered[] = $p['src'];
+
+ if($filtered) {
+ $e = mt_rand(0,count($filtered)-1);
+ $url = $filtered[$e];
+ }
+
+ if(strpos($url,'http') !== 0)
+ return '';
+
+ if(array_key_exists('style',$arr) && isset($arr['style']))
+ $style = $arr['style'];
+
+ // ensure they can't sneak in an eval(js) function
+
+ if(strpos($style,'(') !== false)
+ return '';
+
+ $url = zid($url);
+
+ $o = '<div class="widget">';
+
+ $o .= '<img class="zrl" '
+ . (($style) ? ' style="' . $style . '"' : '')
+ . ' src="' . $url . '" alt="' . t('photo/image') . '" />';
$o .= '</div>';