For the full copyright and license information, please view the LICENSE file that was distributed with this source code. --------------------------------------------------------------------- */ namespace CHV\Render; use G; use CHV; if (!defined('access') or !access) { die('This file cannot be directly accessed.'); } /* ---------------------------------------------------------------------------------------------------------------------------------------- */ /*** STRING DATA FUNCTIONS ***/ function get_email_body_str($file) { ob_start(); G\Render\include_theme_file($file); $mail_body = ob_get_contents(); ob_end_clean(); return $mail_body; } // For inline JS and CSS code from a given file function get_theme_inline_code($file, $type = null) { if (!isset($type)) { $type = pathinfo(rtrim($file, '.php'), PATHINFO_EXTENSION); } if (!CHV\getSetting('minify_enable') or !in_array($type, ['js', 'css'])) { G\Render\include_theme_file($file); } else { $ob_start = ob_start(); G\Render\include_theme_file($file); if ($ob_start) { $code = ob_get_clean(); ob_flush(); if ($code) { return get_cond_minified_code($code, $type); } } } } function show_theme_inline_code($file, $type = null) { G\Render\include_theme_file($file); // echo get_theme_inline_code($file, $type); // Don't minify this (saves execution time and is not needed) } /* ---------------------------------------------------------------------------------------------------------------------------------------- */ /*** THEME DATA FUNCTIONS ***/ function get_theme_file_url($file, $options = []) { $filepath = G_APP_PATH_THEME . $file; $filepath_override = G_APP_PATH_THEME . 'overrides/' . $file; if (file_exists($filepath_override)) { $filepath = $filepath_override; } return get_static_url($filepath, $options); } function get_static_url($filepath, $options = []) { $options = array_merge(['versionize' => true, 'minify' => null], $options); if ($options['minify'] !== false) { $filepath = get_cond_minified_file($filepath, $options['forced']); // Handle the conditional minify } $return = G\absolute_to_url($filepath, defined('CHV_ROOT_URL_STATIC') ? CHV_ROOT_URL_STATIC : null); if ($options['versionize']) { $return = versionize_src($return); } return $return; } function get_cond_minified_file($filepath, $forced = false) { // Check for theme override if (G\starts_with(G_APP_PATH_THEME, $filepath)) { $filepath_override = G\str_replace_first(G_APP_PATH_THEME, G_APP_PATH_THEME . 'overrides/', $filepath); if (file_exists($filepath_override)) { $filepath = $filepath_override; } } if (!CHV\getSetting('minify_enable')) { return $filepath; } return get_minified($filepath, ['forced' => $forced, 'output' => 'file']); } function get_cond_minified_code($code, $type = 'js') { if (!CHV\getSetting('minify_enable')) { return $code; } return get_minified($code, ['source_method' => 'inline', 'source_type' => $type, 'output' => 'inline']); } function get_minified($var, $options = []) { $options = array_merge(['source_method' => 'file', 'forced' => false], (array) $options); try { $minify = new G\Minify(array_merge($options, [ 'source' => $var, ])); $minify->exec(); $var = $minify->result; } catch (G\MinifyException $e) { error_log($e->getMessage()); } return $var; } function theme_file_exists($var) { return file_exists(G_APP_PATH_THEME . $var); } /* ---------------------------------------------------------------------------------------------------------------------------------------- */ /*** HTML TAGS ***/ function get_html_tags() { $classes = 'device-' . (G\Handler::getCond('mobile_device') ? 'mobile' : 'nonmobile') . ' tone-' . G\Handler::getVar('theme_tone') . ' top-bar-' . G\Handler::getVar('theme_top_bar_color') . ' unsafe-blur-' . (CHV\getSetting('theme_nsfw_blur') ? 'on' : 'off'); return get_lang_html_tags() . ' class="' . $classes . '"'; } /* ---------------------------------------------------------------------------------------------------------------------------------------- */ /*** LANGUAGE TAGS ***/ function get_lang_html_tags() { $lang = CHV\get_language_used(); return 'xml:lang="' . $lang['base'] . '" lang="' . $lang['base'] . '" dir="' . $lang['dir'] . '"'; } /* ---------------------------------------------------------------------------------------------------------------------------------------- */ /*** FORM ASSETS ***/ function get_select_options_html($arr, $selected) { $html = ''; foreach ($arr as $k => $v) { $selected = is_bool($selected) ? ($selected ? 1 : 0) : $selected; $html .= '' . "\n"; } return $html; } function get_checkbox_html($options = []) { if (!array_key_exists('name', $options)) { return 'ERR:CHECKBOX_NAME_MISSING'; } $options = array_merge([ 'value_checked' => 1, 'value_unchecked' => 0, 'label' => $options['name'], 'checked' => false, ], $options); $tooltip = $options['tooltip'] ? (' rel="tooltip" title="' . $options['tooltip'] . '"') : null; $html = '
' . "\n" . ' ' . "\n" . '
'; return $html; } function get_recaptcha_component($id = 'g-recaptcha') { if (CHV\getSetting('recaptcha_version') == 3) { return ['recaptcha_invisible_html', get_recaptcha_invisible_html()]; } return ['recaptcha_html', get_recaptcha_html($id)]; } function get_recaptcha_invisible_html() { return ''; } function get_recaptcha_html($id = 'g-recaptcha') { return strtr('
', ['%id' => $id]); } /** * ---------------------------------------------------------------------------------------------------------------------------------------- * ---------------------------------------------------------------------------------------------------------------------------------------- * ----------------------------------------------------------------------------------------------------------------------------------------. */ function get_share_links($share_element) { if (function_exists('get_share_links')) { return \get_share_links($share_element); } if (!$share_element['twitter']) { $share_element['twitter'] = CHV\getSetting('twitter_account'); } $share_element['urlencoded'] = array(); foreach ($share_element as $key => $value) { if ($key == 'urlencoded') { continue; } $share_element['urlencoded'][$key] = rawurlencode($value); } global $share_links_networks; G\Render\include_theme_file('custom_hooks/share_links'); if (!$share_links_networks) { $share_links_networks = array( 'facebook' => array( 'url' => 'http://www.facebook.com/share.php?u=%URL%', 'label' => 'Facebook', ), 'twitter' => array( 'url' => 'https://twitter.com/intent/tweet?original_referer=%URL%&url=%URL%&text=%TITLE%' . ($share_element['twitter'] ? '&via=%TWITTER%' : null), 'label' => 'Twitter', ), 'whatsapp' => array( 'url' => 'whatsapp://send?text=%TITLE% - ' . _s('view on %s', G\safe_html(CHV\getSetting('website_name'))) . ': %URL%', 'label' => 'WhatsApp', 'mobileonly' => true, ), 'reddit' => array( 'url' => 'http://reddit.com/submit?url=%URL%', 'label' => 'reddit', ), 'vk' => array( 'url' => 'http://vk.com/share.php?url=%URL%', 'label' => 'VK', ), 'blogger' => array( 'url' => 'http://www.blogger.com/blog-this.g?n=%TITLE%&source=&b=%HTML%', 'label' => 'Blogger', ), 'tumblr' => array( 'url' => 'http://www.tumblr.com/share/photo?source=%PHOTO_URL%&caption=%TITLE%&clickthru=%URL%&title=%TITLE%', 'label' => 'Tumblr.', ), 'pinterest' => array( 'url' => 'http://www.pinterest.com/pin/create/bookmarklet/?media=%PHOTO_URL%&url=%URL%&is_video=false&description=%DESCRIPTION%&title=%TITLE%', 'label' => 'Pinterest', ), 'stumbleupon' => array( 'url' => 'http://www.stumbleupon.com/submit?url=%URL%', 'label' => 'StumbleUpon', ), 'mail' => array( 'url' => 'mailto:?subject=%TITLE%&body=%URL%', 'label' => 'Email', ), ); } $return = array(); foreach ($share_links_networks as $key => $value) { $search = array('%URL%', '%TITLE%', '%DESCRIPTION%', '%HTML%', '%PHOTO_URL%', '%TWITTER%'); $replace = array('url', 'title', 'description', 'HTML', 'image', 'twitter'); for ($i = 0; $i < count($replace); ++$i) { if (array_key_exists($replace[$i], $share_element['urlencoded'])) { $replace[$i] = $share_element['urlencoded'][$replace[$i]]; } } $value['url'] = str_replace($search, $replace, $value['url']); $return[] = '