2017-03-17 00:11:48 +00:00
|
|
|
<?php
|
|
|
|
|
2022-02-16 04:08:28 +00:00
|
|
|
namespace Code\Widget;
|
2017-03-17 00:11:48 +00:00
|
|
|
|
2020-09-10 03:14:06 +00:00
|
|
|
use App;
|
2022-02-16 04:08:28 +00:00
|
|
|
use Code\Lib\System;
|
|
|
|
use Code\Lib\Channel;
|
|
|
|
use Code\Render\Theme;
|
2022-02-12 20:43:29 +00:00
|
|
|
|
2020-09-10 03:14:06 +00:00
|
|
|
|
2022-10-23 21:18:44 +00:00
|
|
|
class Cover_photo implements WidgetInterface
|
2021-12-02 23:02:31 +00:00
|
|
|
{
|
2017-03-17 00:11:48 +00:00
|
|
|
|
2022-10-24 03:39:49 +00:00
|
|
|
public function widget(array $arguments): string
|
2021-12-02 23:02:31 +00:00
|
|
|
{
|
2017-03-17 00:11:48 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
$o = '';
|
2017-03-17 00:11:48 +00:00
|
|
|
|
2022-03-17 18:01:41 +00:00
|
|
|
if (App::$module === 'channel' && $_REQUEST['mid']) {
|
2021-12-02 23:02:31 +00:00
|
|
|
return '';
|
2021-12-03 03:01:39 +00:00
|
|
|
}
|
2017-03-17 00:11:48 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
$channel_id = 0;
|
2020-09-10 03:14:06 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
$site_banner = false;
|
2020-09-10 04:11:45 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
if (App::$module === 'home') {
|
2022-01-25 01:26:12 +00:00
|
|
|
$channel = Channel::get_system();
|
2021-12-02 23:02:31 +00:00
|
|
|
$channel_id = $channel['channel_id'];
|
|
|
|
$site_banner = System::get_site_name();
|
|
|
|
}
|
2020-09-10 03:14:06 +00:00
|
|
|
|
2022-10-24 03:39:49 +00:00
|
|
|
if (array_key_exists('channel_id', $arguments) && intval($arguments['channel_id'])) {
|
|
|
|
$channel_id = intval($arguments['channel_id']);
|
2021-12-03 03:01:39 +00:00
|
|
|
}
|
|
|
|
if (!$channel_id) {
|
2021-12-02 23:02:31 +00:00
|
|
|
$channel_id = App::$profile_uid;
|
2021-12-03 03:01:39 +00:00
|
|
|
}
|
|
|
|
if (!$channel_id) {
|
2021-12-02 23:02:31 +00:00
|
|
|
return '';
|
2021-12-03 03:01:39 +00:00
|
|
|
}
|
2017-03-17 00:11:48 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
// only show cover photos once per login session
|
|
|
|
$hide_cover = false;
|
|
|
|
if (array_key_exists('channels_visited', $_SESSION) && is_array($_SESSION['channels_visited']) && in_array($channel_id, $_SESSION['channels_visited'])) {
|
|
|
|
$hide_cover = true;
|
|
|
|
}
|
|
|
|
if (!array_key_exists('channels_visited', $_SESSION)) {
|
|
|
|
$_SESSION['channels_visited'] = [];
|
|
|
|
}
|
|
|
|
$_SESSION['channels_visited'][] = $channel_id;
|
2018-08-21 00:38:38 +00:00
|
|
|
|
2022-01-25 01:26:12 +00:00
|
|
|
$channel = Channel::from_id($channel_id);
|
2017-03-17 00:11:48 +00:00
|
|
|
|
2022-10-24 03:39:49 +00:00
|
|
|
if (array_key_exists('style', $arguments) && isset($arguments['style'])) {
|
|
|
|
$style = $arguments['style'];
|
2021-12-03 03:01:39 +00:00
|
|
|
} else {
|
2021-12-02 23:02:31 +00:00
|
|
|
$style = 'width:100%; height: auto;';
|
2021-12-03 03:01:39 +00:00
|
|
|
}
|
2017-03-17 00:11:48 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
// ensure they can't sneak in an eval(js) function
|
2017-03-17 00:11:48 +00:00
|
|
|
|
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
|
|
|
}
|
2017-03-17 00:11:48 +00:00
|
|
|
|
2022-10-24 03:39:49 +00:00
|
|
|
if (array_key_exists('title', $arguments) && isset($arguments['title'])) {
|
|
|
|
$title = $arguments['title'];
|
2021-12-03 03:01:39 +00:00
|
|
|
} else {
|
2021-12-02 23:02:31 +00:00
|
|
|
$title = $channel['channel_name'];
|
2021-12-03 03:01:39 +00:00
|
|
|
}
|
2017-03-17 00:11:48 +00:00
|
|
|
|
2020-09-10 04:11:45 +00:00
|
|
|
|
2022-10-24 03:39:49 +00:00
|
|
|
if (array_key_exists('subtitle', $arguments) && isset($arguments['subtitle'])) {
|
|
|
|
$subtitle = $arguments['subtitle'];
|
2021-12-03 03:01:39 +00:00
|
|
|
} else {
|
2021-12-02 23:02:31 +00:00
|
|
|
$subtitle = str_replace('@', '@', $channel['xchan_addr']);
|
2021-12-03 03:01:39 +00:00
|
|
|
}
|
2017-03-17 00:11:48 +00:00
|
|
|
|
2020-09-10 04:11:45 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
if ($site_banner) {
|
|
|
|
$title = $site_banner;
|
|
|
|
$subtitle = '';
|
|
|
|
}
|
2020-09-10 04:11:45 +00:00
|
|
|
|
2022-03-17 18:01:41 +00:00
|
|
|
$c = Channel::get_cover_photo($channel_id, 'array');
|
2017-03-17 00:11:48 +00:00
|
|
|
|
2021-12-02 23:02:31 +00:00
|
|
|
if ($c) {
|
2022-03-17 18:01:41 +00:00
|
|
|
$o = replace_macros(Theme::get_template('cover_photo_widget.tpl'), [
|
|
|
|
'$photo' => $c,
|
|
|
|
'$style' => $style,
|
|
|
|
'$alt' => t('cover photo'),
|
2021-12-02 23:02:31 +00:00
|
|
|
'$title' => $title,
|
|
|
|
'$subtitle' => $subtitle,
|
|
|
|
'$hovertitle' => t('Click to show more'),
|
|
|
|
'$hide_cover' => $hide_cover
|
2022-03-17 18:01:41 +00:00
|
|
|
]);
|
2021-12-02 23:02:31 +00:00
|
|
|
}
|
|
|
|
return $o;
|
|
|
|
}
|
2017-03-17 00:11:48 +00:00
|
|
|
}
|