streams/Code/Widget/Photo.php

62 lines
1.3 KiB
PHP
Raw Normal View History

<?php
2022-02-16 04:08:28 +00:00
namespace Code\Widget;
2021-12-02 23:02:31 +00:00
class Photo
{
2021-12-02 23:02:31 +00:00
/**
* @brief Widget to display a single photo.
*
* @param array $arr associative array with
* * \e string \b src URL of photo; URL must be an http or https URL
* * \e boolean \b zrl use zid in URL
* * \e string \b style CSS string
*
* @return string with parsed HTML
*/
2021-12-02 23:02:31 +00:00
public function widget($arr)
{
2021-12-02 23:02:31 +00:00
$style = $zrl = false;
2021-12-03 03:01:39 +00:00
if (array_key_exists('src', $arr) && isset($arr['src'])) {
2021-12-02 23:02:31 +00:00
$url = $arr['src'];
2021-12-03 03:01:39 +00:00
}
2021-12-03 03:01:39 +00:00
if (strpos($url, 'http') !== 0) {
2021-12-02 23:02:31 +00:00
return '';
2021-12-03 03:01:39 +00:00
}
2021-12-03 03:01:39 +00:00
if (array_key_exists('style', $arr) && isset($arr['style'])) {
2021-12-02 23:02:31 +00:00
$style = $arr['style'];
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
// ensure they can't sneak in an eval(js) function
2021-12-03 03:01:39 +00:00
if (strpbrk($style, '(\'"<>') !== false) {
2021-12-02 23:02:31 +00:00
$style = '';
2021-12-03 03:01:39 +00:00
}
2021-12-03 03:01:39 +00:00
if (array_key_exists('zrl', $arr) && isset($arr['zrl'])) {
2021-12-02 23:02:31 +00:00
$zrl = (($arr['zrl']) ? true : false);
2021-12-03 03:01:39 +00:00
}
2021-12-03 03:01:39 +00:00
if ($zrl) {
2021-12-02 23:02:31 +00:00
$url = zid($url);
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
$o = '<div class="widget">';
2021-12-02 23:02:31 +00:00
$o .= '<img ' . (($zrl) ? ' class="zrl" ' : '')
. (($style) ? ' style="' . $style . '"' : '')
. ' src="' . $url . '" alt="' . t('photo/image') . '">';
2021-12-02 23:02:31 +00:00
$o .= '</div>';
2021-12-02 23:02:31 +00:00
return $o;
}
}