Copyright (C) Rodolfo Berrios A. All rights reserved. BY USING THIS SOFTWARE YOU DECLARE TO ACCEPT THE CHEVERETO EULA http://chevereto.com/license --------------------------------------------------------------------- */ namespace CHV\Render; use G, 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 = 'tone-' . CHV\getSetting('theme_tone') . ' top-bar-' . CHV\getSetting('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_html($theme="red", $key=NULL) { $public_key = CHV\getSetting('recaptcha_public_key'); if($key) { $public_key = $key; } // Detect reCaptcha version if(preg_match('/[-_]+/', $public_key)) { // new one return '
'; } else { require_once(CHV_APP_PATH_LIB_VENDOR . "recaptchalib.php"); return '' . recaptcha_get_html($public_key, $theme); } } /** * ---------------------------------------------------------------------------------------------------------------------------------------- * ---------------------------------------------------------------------------------------------------------------------------------------- * ---------------------------------------------------------------------------------------------------------------------------------------- */ 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' ), 'google-plus' => array( 'url' => 'https://plus.google.com/u/0/share?url=%URL%', 'label' => 'Google+' ), 'whatsapp' => array( 'url' => 'whatsapp://send?text=%TITLE% - ' . _s('view on %s', 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