' . _s('We use our own and third party cookies to improve your browsing experience and our services. If you continue using our website is understood that you accept this %cookie_policy_link.', ['%cookie_policy_link' => '' . _s('cookie policy') . '']) . '
' . "\n\n";
}
// Sensitive Cookie law display
function display_cookie_law_banner()
{
if (!CHV\getSetting('enable_cookie_law') or CHV\Login::getUser()) {
return;
}
// No user logged in and cookie law has not been accepted
if (!isset($_COOKIE['CHV_COOKIE_LAW_DISPLAY']) or (bool) $_COOKIE['CHV_COOKIE_LAW_DISPLAY'] !== false) {
echo get_cookie_law_banner();
}
}
function include_peafowl_foot()
{
display_cookie_law_banner();
$resources = [
'peafowl' => CHV_PATH_PEAFOWL . 'peafowl.js',
'chevereto' => G_APP_PATH_LIB . 'chevereto.js',
];
foreach ($resources as $k => &$v) {
$v = get_static_url($v);
}
$resources['scripts'] = get_static_url(CHV_PATH_PEAFOWL . 'js/scripts.js');
$echo = [
'',
'',
'',
];
if (G\Handler::getCond('captcha_needed') && CHV\getSetting('recaptcha_version') != 3) {
$echo[] = strtr('', [
'%k' => CHV\getSetting('recaptcha_public_key'),
'%t' => in_array(G\Handler::getVar('theme_tone'), ['light', 'dark']) ? G\Handler::getVar('theme_tone') : 'light', // Esto es MongoCodeQl (en camel case)
]);
$echo[] = '';
}
if (method_exists('CHV\Settings', 'getChevereto')) {
$echo[] = '';
}
echo implode("\n", $echo);
}
function get_peafowl_item_list($tpl = 'image', $item, $template, $requester = null, $tools)
{
if (empty($requester)) {
$requester = CHV\Login::getUser();
} elseif (!is_array($requester) and !is_null($requester)) {
$requester = CHV\User::getSingle($requester, 'id');
}
// Default
$stock_tpl = 'IMAGE';
if ($tpl == 'album' || $tpl == 'user/album') {
$stock_tpl = 'ALBUM';
}
if ($tpl == 'user' || $tpl == 'user/user') {
$stock_tpl = 'USER';
if ($item['is_private']) {
if ($requester['is_admin'] || $requester['is_manager']) {
$item['name'] = '🔒 ' . $item['name'];
} else {
unset($item);
$item = CHV\User::getPrivate();
}
}
} else {
if (array_key_exists('user', $item)) {
CHV\User::fill($item['user']);
}
}
if (in_array($stock_tpl, ['IMAGE', 'ALBUM'])) {
$item['liked'] = is_null($item['like']['user_id']) ? 0 : ($requester['id'] == $item['like']['user_id'] ? 1 : 0);
}
if ($stock_tpl == 'IMAGE') {
if (!$item['is_animated'] || !isset($item['file_resource']['chain']['image'])) {
$conditional_replaces['tpl_list_item/item_image_play_gif'] = null;
}
} elseif (!isset($item['images_slice'][0]['is_animated']) || $item['images_slice'][0]['is_animated'] == false) {
$conditional_replaces['tpl_list_item/item_image_play_gif'] = null;
}
$fill_tpl = $tpl;
if ($stock_tpl == 'ALBUM' && $requester['is_admin'] == false && $item['privacy'] == 'password' && !($item['user']['id'] && $item['user']['id'] == $requester['id']) && CHV\Album::checkSessionPassword($item) == false) {
$fill_tpl = 'album_password';
}
$filled_template = $template["tpl_list_item/$fill_tpl"]; // Stock the unfilled template
if (!CHV\getSetting('enable_likes') || $requester['is_private']/* || $item['user']['is_private']*/) {
$conditional_replaces['tpl_list_item/item_like'] = null;
}
if ($item['user']['is_private'] && !$requester['is_admin'] && $item['user']['id'] !== $requester['id']) {
unset($item['user']);
$item['user'] = CHV\User::getPrivate();
$conditional_replaces['tpl_list_item/image_description_user'] = null;
$conditional_replaces['tpl_list_item/image_description_guest'] = null;
} else {
$conditional_replaces['tpl_list_item/image_description_private'] = null;
}
if ($item['user']['is_private'] && ($requester['is_admin'] || $requester['is_manager'])) {
$item['user']['name'] = '🔒 ' . $item['user']['name'];
}
$conditional_replaces[$item['user']['id'] == null ? 'tpl_list_item/image_description_user' : 'tpl_list_item/image_description_guest'] = null;
$conditional_replaces[$item['user']['avatar'] == null ? 'tpl_list_item/image_description_user_avatar' : 'tpl_list_item/image_description_user_no_avatar'] = null;
if ($stock_tpl == 'IMAGE') {
$conditional_replaces['tpl_list_item/' . (!$item['file_resource']['chain']['image'] ? 'image_cover_image' : 'image_cover_empty')] = null;
}
if ($stock_tpl == 'ALBUM') {
if ($item['privacy'] !== 'password' || (!$requester['is_admin'] || $item['user']['id'] !== $requester['id'])) {
$item['password'] = null;
}
if ($fill_tpl == 'album_password') {
unset($item['images_slice']);
}
$conditional_replaces['tpl_list_item/' . (($item['image_count'] == 0 or !$item['images_slice'][0]['file_resource']) ? 'album_cover_image' : 'album_cover_empty')] = null;
for ($i = 1; $i < count((array) $item['images_slice']); ++$i) {
if (!$item['images_slice'][$i]['file_resource']['chain']['thumb']) {
continue;
}
$template['tpl_list_item/album_thumbs'] = str_replace("%$i", '', $template['tpl_list_item/album_thumbs']);
}
$template['tpl_list_item/album_thumbs'] = preg_replace('/%[0-9]+(.*)%[0-9]+/', '', $template['tpl_list_item/album_thumbs']);
}
if ($stock_tpl == 'USER') {
$conditional_replaces[$item['avatar'] ? 'tpl_list_item/user_no_avatar' : 'tpl_list_item/user_avatar'] = null;
foreach (array('twitter', 'facebook', 'website') as $social) {
if (!$item[$social]) {
$conditional_replaces['tpl_list_item/user_' . $social] = null;
}
}
$conditional_replaces[empty($item['avatar']['url']) ? 'tpl_list_item/user_cover_image' : 'tpl_list_item/user_cover_empty'] = null;
$conditional_replaces[empty($item['background']['url']) ? 'tpl_list_item/user_background_image' : 'tpl_list_item/user_background_empty'] = null;
}
if (is_null($requester)) {
$show_item_edit_tools = false;
$show_item_public_tools = false;
} else {
//$show_item_edit_tools = $item["user"]["id"] == $requester['id'];
if (!is_null($tools)) {
$show_item_edit_tools = !is_array($tools);
$show_item_public_tools = is_array($tools);
} else {
$show_item_edit_tools = false;
$show_item_public_tools = false;
}
if ($requester['is_admin'] || $requester['is_manager']) {
$show_item_edit_tools = true;
$show_item_public_tools = false;
}
}
if (!$show_item_public_tools) {
$template['tpl_list_item/item_' . strtolower($stock_tpl) . '_public_tools'] = null;
}
if (!$show_item_edit_tools) {
$template['tpl_list_item/item_' . strtolower($stock_tpl) . '_edit_tools'] = null;
}
if (!($requester['is_admin'] || $requester['is_manager'])) {
$template['tpl_list_item/item_' . strtolower($stock_tpl) . '_admin_tools'] = null;
}
foreach ($conditional_replaces as $k => $v) {
$template[$k] = $v;
}
preg_match_all('#%(tpl_list_item/.*)%#', $filled_template, $matches);
if (is_array($matches[1])) {
foreach ($matches[1] as $k => $v) {
$filled_template = replace_tpl_string($v, $template[$v], $filled_template);
}
}
foreach ($template as $k => $v) {
$filled_template = replace_tpl_string($k, $v, $filled_template);
}
// Get rid of the useless keys
unset($item['original_exifdata']);
// Now stock the item values
$replacements = array_change_key_case(flatten_array($item, $stock_tpl . '_'), CASE_UPPER);
unset($replacements['IMAGE_ORIGINAL_EXIFDATA']);
if ($stock_tpl == 'IMAGE' or $stock_tpl == 'ALBUM') {
$replacements['ITEM_URL_EDIT'] = ($stock_tpl == 'IMAGE' ? $item['url_viewer'] : $item['url']) . '#edit';
}
// Public for the guest
if (!array_key_exists('user', $item)) {
$replacements['IMAGE_ALBUM_PRIVACY'] = 'public';
}
if (in_array($stock_tpl, ['IMAGE', 'ALBUM'])) {
$nsfw = $stock_tpl == 'IMAGE' ? $item['nsfw'] : $item['images_slice'][0]['nsfw'];
$placeholder = $stock_tpl == 'IMAGE' ? 'IMAGE_FLAG' : 'ALBUM_COVER_FLAG';
$replacements[$placeholder] = $nsfw ? 'unsafe' : 'safe';
}
// $show_object = ($show_item_edit_tools || $show_item_public_tools) || ($requester['is_admin'] || (!is_null($requester) AND $item["user"]["id"] == $requester['id']));
$show_object = true;
if ($show_object) {
$object = G\array_filter_array($item, ['id_encoded', 'image', 'medium', 'thumb', 'name', 'title', 'display_url', 'extension', 'filename', 'height', 'how_long_ago', 'size_formatted', 'url', 'url_viewer', 'url_short', 'width']);
if ($item['user']) {
$object['user'] = [];
foreach (['avatar', 'url', 'username', 'name_short_html'] as $k) {
$object['user'][$k] = $item['user'][$k];
}
}
$replacements['DATA_OBJECT'] = "data-object='" . rawurlencode(json_encode(G\array_utf8encode($object))) . "'";
} else {
$replacements['DATA_OBJECT'] = null;
}
if ($stock_tpl == 'IMAGE') {
$replacements['SIZE_TYPE'] = CHV\getSetting('theme_image_listing_sizing') . '-size';
}
foreach ($replacements as $k => $v) {
$filled_template = replace_tpl_string($k, $v, $filled_template);
}
$column_sizes = array(
'image' => 8,
'album' => 8,
'user' => 8,
);
foreach ($column_sizes as $k => $v) {
$filled_template = replace_tpl_string('COLUMN_SIZE_' . strtoupper($k), $v, $filled_template);
}
return $filled_template;
}
function replace_tpl_string($search, $replace, $subject)
{
return str_replace('%' . $search . '%', is_null($replace) ? '' : $replace, $subject);
}
// http://stackoverflow.com/a/9546215
function flatten_array($array, $prefix = '')
{
$result = array();
foreach ($array as $key => $value) {
if (is_array($value)) {
$result = $result + flatten_array($value, $prefix . $key . '_');
} else {
$result[$prefix . $key] = $value;
}
}
return $result;
}
// This function is sort of an alias of php die() but with html error display
function chevereto_die($error_msg, $paragraph = null, $title = null)
{
if (!is_array($error_msg) && G\check_value($error_msg)) {
$error_msg = array($error_msg);
}
if (is_null($paragraph)) {
$paragraph = "The system has encountered errors that must be fixed to allow proper Chevereto functionality. Chevereto won't work until the following issues are solved:";
}
$solution = "Need help or questions about this? Go to Chevereto support.";
$title = (!is_null($title)) ? $title : 'System error';
$doctitle = $title . ' - Chevereto';
$handled_request = G_ROOT_PATH == '/' ? sanitize_path_slashes($_SERVER['REQUEST_URI']) : str_ireplace(G_ROOT_PATH_RELATIVE, '', G\add_trailing_slashes($_SERVER['REQUEST_URI']));
$base_request = explode('/', rtrim(str_replace('//', '/', str_replace('?', '/', $handled_request)), '/'))[0];
if ($base_request == 'json' || $base_request == 'api') {
$output = array(
'status_code' => 500,
'status_txt' => G\get_set_status_header_desc(500),
'error' => $title,
'errors' => $error_msg,
);
G\set_status_header(500);
G\json_prepare();
die(G\Render\json_output($output));
}
$html = [
'