From afd8b2ddf25d3486d200f9da8ff3cd74131a1df4 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 20 Nov 2014 15:34:49 -0800 Subject: random photo widget --- include/widgets.php | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) (limited to 'include/widgets.php') 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 .= ''; + . ' src="' . $url . '" alt="' . t('photo/image') . '" />'; + + $o .= ''; + + 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 = '
'; + + $o .= '' . t('photo/image') . ''; $o .= '
'; -- cgit v1.2.3 From f17ef6aa90bc283e122a88e627cb464f065af2a6 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 20 Nov 2014 19:33:08 -0800 Subject: allow the photo_rand widget to access photos from any channel (useful if the widget is used in sys-generated pages). You still need permission. --- include/widgets.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'include/widgets.php') diff --git a/include/widgets.php b/include/widgets.php index 7193850ef..076a8fa91 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -828,7 +828,11 @@ function widget_photo_rand($arr) { else $album = ''; - $channel_id = get_app()->profile_uid; + $channel_id = 0; + if(array_key_exists('channel_id',$arr) && intval($arr['channel_id'])) + $channel_id = intval($arr['channel_id']); + if(! $channel_id) + $channel_id = get_app()->profile_uid; if(! $channel_id) return ''; -- cgit v1.2.3