getQueryLog();
$modal = openmodal('querylogsModal', "
Database Query Performance Logs ");
$modal_body = '';
$i = 0;
$time = 0;
if (!empty($query_log)) {
foreach ($query_log as $connectionID => $sql) {
$current_time = $sql[0];
$highlighted = $current_time > $performance_threshold ? TRUE : FALSE;
$modal_body .= "\n";
$modal_body .= "
SQL run#$i : ".($highlighted ? "".$sql[0]." " : "".$sql[0]." ")." seconds \n\r";
$modal_body .= "[code]".$sql[1].($sql[2] ? " [Parameters -- ".implode(',', $sql[2])." ]" : '')."[/code]\n\r";
$modal_body .= "
\n";
$end_sql = end($sql[3]);
$modal_body .= "
".$end_sql['file']." Line #".$end_sql['line'].", ".$end_sql['function']." -
Toggle Backtrace \n";
if (is_array($sql[3])) {
$modal_body .= "
";
foreach ($sql[3] as $id => $debug_backtrace) {
$modal_body .= "Stack Trace #$id - ".$debug_backtrace['file']." @ Line ".$debug_backtrace['line']." ";
if (!empty($debug_backtrace['args'][0])) {
$debug_line = $debug_backtrace['args'][0];
if (is_array($debug_backtrace['args'][0])) {
$debug_line = "";
foreach ($debug_backtrace['args'][0] as $line) {
if (!is_array($line)) {
$debug_line .= " ".$line;
}
}
}
$debug_param = "";
if (!empty($debug_backtrace['args'][1])) {
if (is_array($debug_backtrace['args'][1])) {
$debug_param .= " array(";
foreach ($debug_backtrace['args'][1] as $key => $value) {
$debug_param .= "[$key] => $value, ";
}
$debug_param .= " );";
} else {
$debug_param .= $debug_backtrace['args'][1];
}
}
$modal_body .= "Statement::: $debug_line
Parameters::: ".($debug_param ?: "--")."
";
}
}
$modal_body .= "
\n";
}
$modal_body .= "
\n";
$modal_body .= "
\n";
$i++;
$time = $current_time + $time;
}
}
$modal .= parse_textarea($modal_body, FALSE, TRUE, FALSE);
$modal .= modalfooter("Total Time Expended in ALL SQL Queries: ".$time." seconds ", FALSE);
$modal .= closemodal();
add_to_footer($modal);
}
$render_time = substr((microtime(TRUE) - START_TIME), 0, 7);
$_SESSION['performance'][] = $render_time;
if (count($_SESSION['performance']) > 5) {
array_shift($_SESSION['performance']);
}
$average_speed = $render_time;
$diff = 0;
if (isset($_SESSION['performance'])) {
$average_speed = substr(array_sum($_SESSION['performance']) / count($_SESSION['performance']), 0, 7);
$previous_render = array_values(array_slice($_SESSION['performance'], -2, 1, TRUE));
$diff = (float)$render_time - (!empty($previous_render) ? (float)$previous_render[0] : 0);
}
return sprintf($locale['global_172'], $render_time)." | ".sprintf($locale['global_175'], $average_speed." ($diff)");
}
function showMemoryUsage() {
$locale = fusion_get_locale();
$memory_allocated = parsebytesize(memory_get_peak_usage(TRUE));
$memory_used = parsebytesize(memory_get_peak_usage(FALSE));
return $locale['global_174'].": ".$memory_used."/".$memory_allocated;
}
function showcopyright($class = "", $nobreak = FALSE) {
$link_class = $class ? " class='$class' " : "";
$res = "Powered by PHP-Fusion Copyright © ".date("Y")." PHP-Fusion Inc";
$res .= ($nobreak ? " " : " \n");
$res .= "Released as free software without warranties under GNU Affero GPL v3.\n";
return $res;
}
function showcounter() {
$locale = fusion_get_locale();
$settings = fusion_get_settings();
if ($settings['visitorcounter_enabled']) {
return "".number_format($settings['counter'])." ".($settings['counter'] == 1 ? $locale['global_170'] : $locale['global_171']);
} else {
return "";
}
}
function showprivacypolicy() {
$html = '';
if (!empty(fusion_get_settings('privacy_policy'))) {
$html .= "".fusion_get_locale('global_176')." ";
$modal = openmodal('privacy_policy', fusion_get_locale('global_176'), ['button_id' => 'privacy_policy']);
$modal .= parse_textarea(\PHPFusion\QuantumFields::parse_label(fusion_get_settings('privacy_policy')));
$modal .= closemodal();
add_to_footer($modal);
}
return $html;
}
/**
* Creates an alert bar
*
* @param $title
* @param array $options
*
* @return string
*/
if (!function_exists("alert")) {
function alert($title, array $options = []) {
$options += [
"class" => !empty($options['class']) ? $options['class'] : 'alert-danger',
"dismiss" => !empty($options['dismiss']) && $options['dismiss'] == TRUE ? TRUE : FALSE
];
if ($options['dismiss'] == TRUE) {
$html = "× $title
";
} else {
$html = "$title
";
}
add_to_jquery("$('div.alert a').addClass('alert-link');");
return $html;
}
}
// Get the widget settings for the theme settings table
if (!function_exists('get_theme_settings')) {
function get_theme_settings($theme_folder) {
$settings_arr = [];
$set_result = dbquery("SELECT settings_name, settings_value FROM ".DB_SETTINGS_THEME." WHERE settings_theme=:themeset", [':themeset' => $theme_folder]);
if (dbrows($set_result)) {
while ($set_data = dbarray($set_result)) {
$settings_arr[$set_data['settings_name']] = $set_data['settings_value'];
}
return $settings_arr;
} else {
return FALSE;
}
}
}
/**
* Java script that transform html table sortable
*
* @param $table_id - table ID
*
* @return string
*/
function fusion_sort_table($table_id) {
add_to_footer("\n");
add_to_jquery("$('#".$table_id."').tablesorter();");
return "tablesorter";
}
if (!function_exists("label")) {
function label($label, array $options = []) {
$options += [
"class" => !empty($array['class']) ? $array['class'] : '',
"icon" => !empty($array['icon']) ? " " : '',
];
return "".$options['icon'].$label." \n";
}
}
if (!function_exists("badge")) {
function badge($label, array $options = []) {
$options += [
"class" => !empty($array['class']) ? $array['class'] : "",
"icon" => !empty($array['icon']) ? " " : "",
];
return "".$options['icon'].$label." \n";
}
}
if (!function_exists("openmodal") && !function_exists("closemodal") && !function_exists("modalfooter")) {
/**
* To get the best results for Modal z-index overlay, try :
* ob_start();
* ... insert and echo ...
* add_to_footer(ob_get_contents()).ob_end_clean();
*/
/**
* Generate modal
*
* @param $id - unique CSS id
* @param $title - modal title
* @param array $options
*
* @return string
*/
function openmodal($id, $title, $options = []) {
$locale = fusion_get_locale();
$options += [
'class' => !empty($options['class']) ?: 'modal-lg',
'button_id' => '',
'button_class' => '',
'static' => FALSE,
'hidden' => FALSE, // force a modal to be hidden at default, you will need a jquery trigger $('#your_modal_id').modal('show'); manually
];
$modal_trigger = '';
if (!empty($options['button_id']) || !empty($options['button_class'])) {
$modal_trigger = !empty($options['button_id']) ? "#".$options['button_id'] : ".".$options['button_class'];
}
if ($options['static'] && !empty($modal_trigger)) {
OutputHandler::addToJQuery("$('".$modal_trigger."').bind('click', function(e){ $('#".$id."-Modal').modal({backdrop: 'static', keyboard: false}).modal('show'); e.preventDefault(); });");
} else if ($options['static'] && empty($options['button_id'])) {
OutputHandler::addToJQuery("$('#".$id."-Modal').modal({ backdrop: 'static', keyboard: false }).modal('show');");
} else if ($modal_trigger && empty($options['static'])) {
OutputHandler::addToJQuery("$('".$modal_trigger."').bind('click', function(e){ $('#".$id."-Modal').modal('show'); e.preventDefault(); });");
} else {
if (!$options['hidden']) {
OutputHandler::addToJQuery("$('#".$id."-Modal').modal('show');");
}
}
$html = '';
$html .= "\n";
$html .= "
\n";
$html .= "
\n";
if ($title) {
$html .= "\n";
}
$html .= "
\n";
return $html;
}
/**
* Adds a modal footer in between openmodal and closemodal.
*
* @param $content
* @param bool|FALSE $dismiss
*
* @return string
*/
function modalfooter($content, $dismiss = FALSE) {
$html = "
\n\n
\n
\n
\n";
}
}
if (!function_exists("progress_bar")) {
/**
* Render a progress bar
*
* @param int $num Max of 100
* @param bool $title Label for the progress bar
* @param array $options
* class additional class for the progress bar
* height the height of the progress bar in px
* reverse set to true to have the color counting reversed
* disable set to true to have the progress bar disabled status
* hide_info set to true to hide the information in the progress bar rendering
* progress_class have it your custom progress bar class with your own custom class
*
* @return string
*/
function progress_bar($num, $title = FALSE, array $options = []) {
$default_options = [
'class' => '',
'height' => '',
'reverse' => FALSE,
'as_percent' => TRUE,
'disabled' => FALSE,
'hide_info' => FALSE,
'progress_class' => ''
];
$options += $default_options;
$height = ($options['height']) ? $options['height'] : '20px';
if (!function_exists('bar_color')) {
function bar_color($num, $reverse) {
$auto_class = $reverse ? "progress-bar-success" : "progress-bar-danger";
if ($num > 71) {
$auto_class = ($reverse) ? 'progress-bar-danger' : 'progress-bar-success';
} else if ($num > 55) {
$auto_class = ($reverse) ? 'progress-bar-warning' : 'progress-bar-info';
} else if ($num > 25) {
$auto_class = ($reverse) ? 'progress-bar-info' : 'progress-bar-warning';
} else if ($num < 25) {
$auto_class = ($reverse) ? 'progress-bar-success' : 'progress-bar-danger';
}
return $auto_class;
}
}
$_barcolor = ['progress-bar-success', 'progress-bar-info', 'progress-bar-warning', 'progress-bar-danger'];
$_barcolor_reverse = [
'progress-bar-success',
'progress-bar-info',
'progress-bar-warning',
'progress-bar-danger'
];
$html = '';
if (is_array($num)) {
$i = 0;
$chtml = "";
$cTitle = "";
$cNum = "";
foreach ($num as $value) {
$int = intval($num);
if ($options['disabled'] == TRUE) {
$value = "∞";
} else {
$value = $value > 0 ? $value.' ' : '0 ';
$value .= $options['as_percent'] ? '%' : '';
}
$c2Title = "";
if (is_array($title)) {
$c2Title = $title[$i];
} else {
$cTitle = $title;
}
$auto_class = ($options['reverse']) ? $_barcolor_reverse[$i] : $_barcolor[$i];
$classes = (is_array($options['class'])) ? $options['class'][$i] : $auto_class;
$cNum .= "\n";
$cNum .= "
\n";
$cNum .= "".$c2Title." ".$value."
\n";
$chtml .= "\n";
$chtml .= "
\n";
$i++;
}
$html .= ($options['hide_info'] == FALSE ? "$cTitle $cNum
\n" : "");
$html .= "\n";
$html .= $chtml;
$html .= "
\n";
$html .= "\n";
} else {
$int = intval($num);
if ($options['disabled'] == TRUE) {
$num = "∞";
} else {
$num = $num > 0 ? $num.' ' : '0 ';
$num .= $options['as_percent'] ? '%' : '';
}
$auto_class = bar_color($int, $options['reverse']);
$class = (!$options['class']) ? $auto_class : $options['class'];
$html .= ($options['hide_info'] === FALSE ? "$title $num
\n" : "");
$html .= "\n";
$html .= "
\n";
$html .= "
\n";
}
return $html;
}
}
if (!function_exists("check_panel_status")) {
function check_panel_status($side) {
$settings = fusion_get_settings();
$exclude_list = "";
if ($side == "left") {
if ($settings['exclude_left'] != "") {
$exclude_list = explode("\r\n", $settings['exclude_left']);
}
if (defined("LEFT_OFF")) {
$exclude_list = FUSION_SELF;
}
} else if ($side == "upper") {
if ($settings['exclude_upper'] != "") {
$exclude_list = explode("\r\n", $settings['exclude_upper']);
}
} else if ($side == "aupper") {
if ($settings['exclude_aupper'] != "") {
$exclude_list = explode("\r\n", $settings['exclude_aupper']);
}
} else if ($side == "lower") {
if ($settings['exclude_lower'] != "") {
$exclude_list = explode("\r\n", $settings['exclude_lower']);
}
} else if ($side == "blower") {
if ($settings['exclude_blower'] != "") {
$exclude_list = explode("\r\n", $settings['exclude_blower']);
}
} else if ($side == "right") {
if ($settings['exclude_right'] != "") {
$exclude_list = explode("\r\n", $settings['exclude_right']);
}
} else if ($side == "user1") {
if ($settings['exclude_user1'] != "") {
$exclude_list = explode("\r\n", $settings['exclude_user1']);
}
} else if ($side == "user2") {
if ($settings['exclude_user2'] != "") {
$exclude_list = explode("\r\n", $settings['exclude_user2']);
}
} else if ($side == "user3") {
if ($settings['exclude_user3'] != "") {
$exclude_list = explode("\r\n", $settings['exclude_user3']);
}
} else if ($side == "user4") {
if ($settings['exclude_user4'] != "") {
$exclude_list = explode("\r\n", $settings['exclude_user4']);
}
}
if (is_array($exclude_list)) {
if (fusion_get_settings('site_seo')) {
$params = http_build_query(PHPFusion\Rewrite\Router::getRouterInstance()->get_FileParams());
$file_path = '/'.PHPFusion\Rewrite\Router::getRouterInstance()->getFilePath().($params ? "?" : '').$params;
$script_url = explode("/", $file_path);
} else {
$script_url = explode("/", $_SERVER['PHP_SELF']);
}
$url_count = count($script_url);
$base_url_count = substr_count(BASEDIR, "../") + (fusion_get_settings('site_seo') ? ($url_count - 1) : 1);
$match_url = "";
while ($base_url_count != 0) {
$current = $url_count - $base_url_count;
$match_url .= "/".$script_url[$current];
$base_url_count--;
}
return (in_array($match_url, $exclude_list)) ? FALSE : TRUE;
} else {
return TRUE;
}
}
}
if (!function_exists("showbanners")) {
/*
* Displays the system settings banner
*/
function showbanners($display = "") {
ob_start();
if ($display == 2) {
if (fusion_get_settings("sitebanner2")) {
eval("?>".stripslashes(fusion_get_settings("sitebanner2"))."".stripslashes(fusion_get_settings("sitebanner1"))." ";
}
}
if (!function_exists("showsublinks")) {
/**
* Displays Site Links Navigation Bar
*
* @param string $sep - Custom seperator text
* @param string $class - Class
* @param array $options
*
* Notice: There is a more powerful method now that offers more powerful manipulation methods
* that non oo approach cannot ever achieve using cache and the new mutator method
* SiteLinks::setSubLinks($sep, $class, $options)->showsublinks(); for normal usage
*
* @return string
*/
function showsublinks($sep = "", $class = "navbar-default", array $options = []) {
$options += [
'seperator' => $sep,
'navbar_class' => $class,
];
return \PHPFusion\SiteLinks::setSubLinks($options)->showSubLinks();
}
}
if (!function_exists("showsubdate")) {
function showsubdate() {
return ucwords(showdate(fusion_get_settings('subheaderdate'), time()));
}
}
if (!function_exists("newsposter")) {
function newsposter($info, $sep = "", $class = "") {
$locale = fusion_get_locale();
$link_class = $class ? "class='$class'" : "";
$res = THEME_BULLET." ".profile_link($info['user_id'], $info['user_name'], $info['user_status'])." ";
$res .= $locale['global_071'].showdate("newsdate", $info['news_date']);
$res .= $info['news_ext'] == "y" || $info['news_allow_comments'] ? $sep."\n" : "\n";
return "".$res;
}
}
if (!function_exists("newsopts")) {
function newsopts($info, $sep, $class = "") {
$locale = fusion_get_locale();
$res = "";
$link_class = $class ? "class='$class'" : "";
if (!isset($_GET['readmore']) && $info['news_ext'] == "y") {
$res = "".$locale['global_072']." ".$sep." ";
}
if ($info['news_allow_comments'] && fusion_get_settings('comments_enabled') == "1") {
$res .= "".$info['news_comments'].($info['news_comments'] == 1 ? $locale['global_073b'] : $locale['global_073'])." ".$sep." ";
}
if ($info['news_ext'] == "y" || ($info['news_allow_comments'] && fusion_get_settings('comments_enabled') == "1")) {
$res .= $info['news_reads'].$locale['global_074']."\n ".$sep;
}
$res .= " \n";
return "".$res;
}
}
if (!function_exists("newscat")) {
function newscat($info, $sep = "", $class = "") {
$locale = fusion_get_locale();
$res = "";
$link_class = $class ? "class='$class'" : "";
$res .= $locale['global_079'];
if ($info['cat_id']) {
$res .= "".$info['cat_name']." ";
} else {
$res .= "".$locale['global_080']." ";
}
return "".$res." $sep ";
}
}
if (!function_exists("articleposter")) {
function articleposter($info, $sep = "", $class = "") {
$locale = fusion_get_locale();
$link_class = $class ? "class='$class'" : "";
$res = THEME_BULLET." ".$locale['global_070']."".profile_link($info['user_id'], $info['user_name'], $info['user_status'])." \n";
$res .= $locale['global_071'].showdate("newsdate", $info['article_date']);
$res .= ($info['article_allow_comments'] && fusion_get_settings('comments_enabled') == "1" ? $sep."\n" : "\n");
return "".$res;
}
}
if (!function_exists("articleopts")) {
function articleopts($info, $sep) {
$locale = fusion_get_locale();
$res = "";
if ($info['article_allow_comments'] && fusion_get_settings('comments_enabled') == "1") {
$res = "".$info['article_comments'].($info['article_comments'] == 1 ? $locale['global_073b'] : $locale['global_073'])." ".$sep."\n";
}
$res .= $info['article_reads'].$locale['global_074']." ".$sep."\n";
$res .= " \n";
return "".$res;
}
}
if (!function_exists("articlecat")) {
function articlecat($info, $sep = "", $class = "") {
$locale = fusion_get_locale();
$res = "";
$link_class = $class ? "class='$class'" : "";
$res .= $locale['global_079'];
if ($info['cat_id']) {
$res .= "".$info['cat_name']." ";
} else {
$res .= "".$locale['global_080']." ";
}
return "".$res." $sep ";
}
}
if (!function_exists("itemoptions")) {
function itemoptions($item_type, $item_id) {
$locale = fusion_get_locale();
$res = "";
if ($item_type == "N") {
if (iADMIN && checkrights($item_type)) {
$res .= " · \n";
}
} else if ($item_type == "A") {
if (iADMIN && checkrights($item_type)) {
$res .= " · \n";
}
}
return $res;
}
}
if (!function_exists("panelbutton")) {
function panelbutton($state, $bname) {
$bname = preg_replace("/[^a-zA-Z0-9\s]/", "_", $bname);
if (isset($_COOKIE["fusion_box_".$bname])) {
if ($_COOKIE["fusion_box_".$bname] == "none") {
$state = "off";
} else {
$state = "on";
}
}
return " ";
}
}
if (!function_exists("panelstate")) {
function panelstate($state, $bname, $element = "div") {
$bname = preg_replace("/[^a-zA-Z0-9\s]/", "_", $bname);
if (isset($_COOKIE["fusion_box_".$bname])) {
if ($_COOKIE["fusion_box_".$bname] == "none") {
$state = "off";
} else {
$state = "on";
}
}
return "<$element id='box_".$bname."'".($state == "off" ? " style='display:none'" : "").">\n";
}
}
if (!function_exists('opensidex')) {
function opensidex($title, $state = "on") {
openside($title, TRUE, $state);
}
}
if (!function_exists('closesidex')) {
function closesidex() {
closeside();
}
}
if (!function_exists('tablebreak')) {
function tablebreak() {
return TRUE;
}
}
/**
* @param array $userdata
* Indexes:
* - user_id
* - user_name
* - user_avatar
* - user_status
* @param string $size A valid size for CSS max-width and max-height.
* @param string $class Classes for the link
* @param bool $link FALSE if you want to display the avatar without link. TRUE by default.
* @param string $img_class Classes for the image
* @param string $custom_avatar Custom default avatar
*
* @return string
*/
if (!function_exists('display_avatar')) {
function display_avatar(array $userdata, $size, $class = '', $link = TRUE, $img_class = '', $custom_avatar = '') {
if (empty($userdata)) {
$userdata = [];
}
$userdata += [
'user_id' => 0,
'user_name' => '',
'user_avatar' => '',
'user_status' => ''
];
if (!$userdata['user_id']) {
$userdata['user_id'] = 1;
}
$link = fusion_get_settings('hide_userprofiles') == TRUE ? (iMEMBER ? $link : FALSE) : $link;
$class = ($class) ? "class='$class'" : '';
$hasAvatar = $userdata['user_avatar'] && file_exists(IMAGES."avatars/".$userdata['user_avatar']) && $userdata['user_status'] != '5' && $userdata['user_status'] != '6';
$name = !empty($userdata['user_name']) ? $userdata['user_name'] : 'Guest';
if ($hasAvatar) {
$user_avatar = fusion_get_settings('siteurl')."images/avatars/".$userdata['user_avatar'];
$imgTpl = " ";
$img = sprintf($imgTpl, $user_avatar);
} else {
if (!empty($custom_avatar) && file_exists($custom_avatar)) {
$imgTpl = " ";
$img = sprintf($imgTpl, $custom_avatar);
} else {
$color = stringToColorCode($userdata['user_name']);
$font_color = get_brightness($color) > 130 ? '000' : 'fff';
$first_char = substr($userdata['user_name'], 0, 1);
$first_char = strtoupper($first_char);
$size_int = (int)filter_var($size, FILTER_SANITIZE_NUMBER_INT);
$img = ''.$first_char.'
';
}
}
return $link ? sprintf("%s ", $img) : $img;
}
}
function stringToColorCode($text) {
$min_brightness = 50; // integer between 0 and 100
$spec = 3; // integer between 2-10, determines how unique each color will be
$hash = sha1(md5(sha1($text)));
$colors = [];
for ($i = 0; $i < 3; $i++) {
$colors[$i] = max([round(((hexdec(substr($hash, $spec * $i, $spec))) / hexdec(str_pad('', $spec, 'F'))) * 255), $min_brightness]);
}
if ($min_brightness > 0) {
while (array_sum($colors) / 3 < $min_brightness) {
for ($i = 0; $i < 3; $i++) {
$colors[$i] += 10;
}
}
}
$output = '';
for ($i = 0; $i < 3; $i++) {
$output .= str_pad(dechex($colors[$i]), 2, 0, STR_PAD_LEFT);
}
return $output;
}
function get_brightness($hex) {
$hex = str_replace('#', '', $hex);
$r = hexdec(substr($hex, 0, 2));
$g = hexdec(substr($hex, 2, 2));
$b = hexdec(substr($hex, 4, 2));
return (($r * 299) + ($g * 587) + ($b * 114)) / 1000;
}
if (!function_exists('colorbox')) {
function colorbox($img_path, $img_title, $responsive = TRUE, $class = '', $as_text = FALSE) {
if (!defined('COLORBOX')) {
define('COLORBOX', TRUE);
$colorbox_css = file_exists(THEME.'colorbox/colorbox.css') ? THEME.'colorbox/colorbox.css' : INCLUDES.'jquery/colorbox/colorbox.css';
add_to_head(" ");
add_to_head("");
add_to_jquery("$('a[rel^=\"colorbox\"]').colorbox({ current: '',width:'80%',height:'80%'});");
}
$class = ($class ? " $class" : '');
if ($responsive) {
$class = " class='img-responsive $class' ";
} else {
$class = (!empty($class) ? " class='$class' " : '');
}
return "".($as_text ? $img_title : " ")." ";
}
}
/**
* Thumbnail function
*
* @param $src
* @param $size
* @param bool $url
* @param bool $colorbox
* @param bool $responsive
* @param string $class
*
* @return string
*/
if (!function_exists("thumbnail")) {
function thumbnail($src, $size, $url = FALSE, $colorbox = FALSE, $responsive = TRUE, $class = "m-2") {
$_offset_w = 0;
$_offset_h = 0;
if (!$responsive && $src) {
// get the size of the image and centrally aligned it
$image_info = @getimagesize($src);
$width = $image_info[0];
$height = $image_info[1];
$_size = explode('px', $size);
if ($width > $_size[0]) {
$_offset_w = floor($width - $_size[0]) * 0.5;
} // get surplus and negative by half.
if ($height > $_size[0]) {
$_offset_h = ($height - $_size[0]) * 0.5;
} // get surplus and negative by half.
}
$html = "\n";
if ($colorbox && $src && !defined('colorbox')) {
define('colorbox', TRUE);
add_to_head(" ");
add_to_head("");
add_to_jquery("$('.colorbox').colorbox({width: '75%', height: '75%'});");
}
return $html;
}
}
if (!function_exists("lorem_ipsum")) {
function lorem_ipsum($length) {
$text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum aliquam felis nunc, in dignissim metus suscipit eget. Nunc scelerisque laoreet purus, in ullamcorper magna sagittis eget. Aliquam ac rhoncus orci, a lacinia ante. Integer sed erat ligula. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Fusce ullamcorper sapien mauris, et tempus mi tincidunt laoreet. Proin aliquam vulputate felis in viverra.
\n";
$text .= "Duis sed lorem vitae nibh sagittis tempus sed sed enim. Mauris egestas varius purus, a varius odio vehicula quis. Donec cursus interdum libero, et ornare tellus mattis vitae. Phasellus et ligula velit. Vivamus ac turpis dictum, congue metus facilisis, ultrices lorem. Cras imperdiet lacus in tincidunt pellentesque. Sed consectetur nunc vitae fringilla volutpat. Mauris nibh justo, luctus eu dapibus in, pellentesque non urna. Nulla ullamcorper varius lacus, ut finibus eros interdum id. Proin at pellentesque sapien. Integer imperdiet, sapien nec tristique laoreet, sapien lacus porta nunc, tincidunt cursus risus mauris id quam.
\n";
$text .= "Ut vulputate mauris in facilisis euismod. Ut id libero vitae neque laoreet placerat a id mi. Integer ornare risus placerat, interdum nisi sed, commodo ligula. Integer at ipsum id magna blandit volutpat. Sed euismod mi odio, vitae molestie diam ornare quis. Aenean id ligula finibus, convallis risus a, scelerisque tellus. Morbi quis pretium lectus. In convallis hendrerit sem. Vestibulum sed ultricies massa, ut tempus risus. Nunc aliquam at tellus quis lobortis. In hac habitasse platea dictumst. Vestibulum maximus, nibh at tristique viverra, eros felis ultrices nunc, et efficitur nunc augue a orci. Phasellus et metus mauris. Morbi ut ex ut urna tincidunt varius eu id diam. Aenean vestibulum risus sed augue vulputate, a luctus ligula laoreet.
\n";
$text .= "Nam tempor sodales mi nec ullamcorper. Mauris tristique ligula augue, et lobortis turpis dictum vitae. Aliquam leo massa, posuere ac aliquet quis, ultricies eu elit. Etiam et justo et nulla cursus iaculis vel quis dolor. Phasellus viverra cursus metus quis luctus. Nulla massa turpis, porttitor vitae orci sed, laoreet consequat urna. Etiam congue turpis ac metus facilisis pretium. Nam auctor mi et auctor malesuada. Mauris blandit nulla quis ligula cursus, ut ullamcorper dui posuere. Fusce sed urna id quam finibus blandit tempus eu tellus. Vestibulum semper diam id ante iaculis iaculis.
\n";
$text .= "Fusce suscipit maximus neque, sed consectetur elit hendrerit at. Sed luctus mi in ex auctor mollis. Suspendisse ac elementum tellus, ut malesuada purus. Mauris condimentum elit at dolor eleifend iaculis. Aenean eget faucibus mauris. Pellentesque fermentum mattis imperdiet. Donec mattis nisi id faucibus finibus. Vivamus in eleifend lorem, vel dictum nisl. Morbi ut mollis arcu.
\n";
return trim_text($text, $length);
}
}
if (!function_exists("timer")) {
function timer($updated = FALSE) {
$locale = fusion_get_locale();
if (!$updated) {
$updated = time();
}
$updated = stripinput($updated);
$current = time();
$calculated = $current - $updated;
$second = 1;
$minute = $second * 60;
$hour = $minute * 60;
$day = 24 * $hour;
$month = days_current_month() * $day;
$year = (date("L", $updated) > 0) ? 366 * $day : 365 * $day;
if ($calculated < 1) {
return "".$locale['just_now']." \n";
}
// $timer = array($year => $locale['year'], $month => $locale['month'], $day => $locale['day'], $hour => $locale['hour'], $minute => $locale['minute'], $second => $locale['second']);
// $timer_b = array($year => $locale['year_a'], $month => $locale['month_a'], $day => $locale['day_a'], $hour => $locale['hour_a'], $minute => $locale['minute_a'], $second => $locale['second_a']);
$timer = [
$year => $locale['fmt_year'],
$month => $locale['fmt_month'],
$day => $locale['fmt_day'],
$hour => $locale['fmt_hour'],
$minute => $locale['fmt_minute'],
$second => $locale['fmt_second']
];
foreach ($timer as $arr => $unit) {
$calc = $calculated / $arr;
if ($calc >= 1) {
$answer = round($calc);
// $string = ($answer > 1) ? $timer_b[$arr] : $unit;
$string = \PHPFusion\Locale::format_word($answer, $unit, ['add_count' => FALSE]);
return "".$answer." ".$string." ".$locale['ago']." ";
}
}
return NULL;
}
}
if (!function_exists("days_current_month")) {
function days_current_month() {
$year = showdate("%Y", time());
$month = showdate("%m", time());
return $month == 2 ? ($year % 4 ? 28 : ($year % 100 ? 29 : ($year % 400 ? 28 : 29))) : (($month - 1) % 7 % 2 ? 30 : 31);
}
}
if (!function_exists("countdown")) {
function countdown($time) {
$locale = fusion_get_locale();
$updated = stripinput($time);
$second = 1;
$minute = $second * 60;
$hour = $minute * 60;
$day = 24 * $hour;
$month = days_current_month() * $day;
$year = (date("L", $updated) > 0) ? 366 * $day : 365 * $day;
$timer = [
$year => $locale['year'],
$month => $locale['month'],
$day => $locale['day'],
$hour => $locale['hour'],
$minute => $locale['minute'],
$second => $locale['second']
];
$timer_b = [
$year => $locale['year_a'],
$month => $locale['month_a'],
$day => $locale['day_a'],
$hour => $locale['hour_a'],
$minute => $locale['minute_a'],
$second => $locale['second_a']
];
foreach ($timer as $arr => $unit) {
$calc = $updated / $arr;
if ($calc >= 1) {
$answer = round($calc);
$string = ($answer > 1) ? $timer_b[$arr] : $unit;
return "$answer ".$string." ";
}
}
if (!isset($answer)) {
return "".$locale['now']." ";
}
}
}
if (!function_exists("opencollapse")
&& !function_exists("opencollapsebody")
&& !function_exists("closecollapsebody")
&& !function_exists("collapse_header_link")
&& !function_exists("collapse_footer_link")
&& !function_exists("closecollapse")
) {
/**
* Accordion template
*
* @param $id - unique accordion id name
*
* @return string
*/
function opencollapse($id) {
return "\n";
}
function opencollapsebody($title, $unique_id, $grouping_id, $active = 0, $class = FALSE) {
$html = "
\n";
$html .= "
\n";
$html .= "
\n";
$html .= "
\n";
$html .= "
\n"; // body.
return $html;
}
function closecollapsebody() {
$html = "
\n"; // panel container
$html .= "
\n"; // panel default
return $html;
}
function collapse_header_link($id, $title, $active, $class = '') {
$active = ($active) ? '' : 'collapsed';
$title_id_cc = preg_replace('/[^A-Z0-9-]+/i', "-", $title);
return "class='$class $active' data-toggle='collapse' data-parent='#".$id."' href='#".$title_id_cc."-".$id."' aria-expanded='true' aria-controls='".$title_id_cc."-".$id."'";
}
function collapse_footer_link($id, $title, $active, $class = '') {
$active = ($active) ? 'in' : '';
$title_id_cc = preg_replace('/[^A-Z0-9-]+/i', "-", $title);
return "id='".$title_id_cc."-".$id."' class='panel-collapse collapse ".$active." ".$class."' role='tabpanel' aria-labelledby='headingOne'";
}
function closecollapse() {
return "
\n";
}
}
if (!function_exists("tab_active")
&& !function_exists("opentab")
&& !function_exists("opentabbody")
&& !function_exists("closetabbody")
&& !function_exists("closetab")
) {
class FusionTabs {
private $id = '';
private $remember = FALSE;
private $cookie_prefix = 'tab_js';
private $cookie_name = '';
private $tab_info = [];
private $link_mode = FALSE;
public static function tab_active($array, $default_active, $getname = FALSE) {
if (!empty($getname)) {
$section = isset($_GET[$getname]) && $_GET[$getname] ? $_GET[$getname] : $default_active;
$count = count($array['title']);
if ($count > 0) {
for ($i = 0; $i < $count; $i++) {
$id = $array['id'][$i];
if ($section == $id) {
return $id;
}
}
} else {
return $default_active;
}
} else {
$id = $array['id'][$default_active];
return $id;;
}
}
public function set_remember($value) {
$this->remember = $value;
}
public function opentab($tab_title, $link_active_arrkey, $id, $link = FALSE, $class = FALSE, $getname = 'section', array $cleanup_GET = []) {
$this->id = $id;
$this->cookie_name = $this->cookie_prefix.'-'.$id;
$this->tab_info = $tab_title;
$this->link_mode = $link;
$getArray = [$getname];
if (!empty($cleanup_GET)) {
$getArray = array_merge_recursive($cleanup_GET, $getArray);
}
if (empty($link) && $this->remember) {
if (isset($_COOKIE[$this->cookie_name])) {
$link_active_arrkey = str_replace('tab-', '', $_COOKIE[$this->cookie_name]);
}
}
$html = "\n";
$html .= "
\n";
foreach ($tab_title['title'] as $arr => $v) {
$v_title = $v;
$tab_id = $tab_title['id'][$arr];
$icon = (isset($tab_title['icon'][$arr])) ? $tab_title['icon'][$arr] : "";
$link_url = '#';
if ($link) {
$link_url = $link.(stristr($link, '?') ? '&' : '?').$getname."=".$tab_id; // keep all request except GET array
if ($link === TRUE) {
$link_url = clean_request($getname.'='.$tab_id.(defined('ADMIN_PANEL') ? "&aid=".$_GET['aid'] : ""), $getArray, FALSE);
}
$html .= ($link_active_arrkey == $tab_id) ? "\n" : " \n";
} else {
$html .= ($link_active_arrkey == "".$tab_id) ? " \n" : " \n";
}
$html .= "\n".($icon ? " " : '')." ".$v_title." \n";
$html .= " \n";
}
$html .= " \n";
$html .= "
\n";
if (empty($link) && $this->remember) {
if (!defined('JS_COOKIES')) {
define('JS_COOKIES', TRUE);
OutputHandler::addToFooter('');
}
OutputHandler::addToJQuery("
$('#".$id." > li').on('click', function() {
var cookieName = '".$this->cookie_name."';
var cookieValue = $(this).find(\"a[role='tab']\").attr('id');
Cookies.set(cookieName, cookieValue);
});
var cookieName = 'tab_js-".$id."';
if (Cookies.get(cookieName)) {
$('#".$id."').find('#'+Cookies.get(cookieName)).click();
}
");
}
return (string)$html;
}
/*
* Deprecated $tab_title.
* Deprecated $link
*
* Commit title:
* Using globals without adding parameter to pass $id set on previous opentabs() to next opentabbody()
*/
public function opentabbody($id, $link_active_arrkey = FALSE, $key = FALSE) {
$key = $key ? $key : 'section';
$bootstrap = defined('BOOTSTRAP4') ? ' show' : '';
if (isset($_GET[$key]) && $this->link_mode) {
if ($link_active_arrkey == $id) {
$status = 'in active'.$bootstrap;
} else {
$status = '';
}
} else {
if (!$this->link_mode) {
if ($this->remember) {
if (isset($_COOKIE[$this->cookie_name])) {
$link_active_arrkey = str_replace('tab-', '', $_COOKIE[$this->cookie_name]);
}
}
}
$status = ($link_active_arrkey == $id ? " in active".$bootstrap : '');
}
return "
\n";
}
public function closetab(array $options = []) {
$locale = fusion_get_locale();
$default_options = [
"tab_nav" => FALSE,
];
$options += $default_options;
if ($options['tab_nav'] == TRUE) {
$nextBtn = "
".$locale['next']." ";
$prevBtn = "
".$locale['previous']." ";
OutputHandler::addToJQuery("
$('.btnNext').click(function(){
$('.nav-tabs > .active').next('li').find('a').trigger('click');
});
$('.btnPrevious').click(function(){
$('.nav-tabs > .active').prev('li').find('a').trigger('click');
});
");
echo "
\n".$prevBtn.$nextBtn."
\n";
}
return "
\n
\n";
}
public function closetabbody() {
return "
\n";
}
}
$fusion_tabs = new FusionTabs();
/**
* Current Tab Active Selector
*
* @param $array - multidimension array consisting of keys 'title', 'id', 'icon'
* @param $default_active - 0 if link_mode is false, $_GET if link_mode is true
* @param bool $getname - set getname and turn tabs into link that listens to getname
*
* @return string
* @todo: options base
*/
function tab_active($array, $default_active, $getname = FALSE) {
return \FusionTabs::tab_active($array, $default_active, $getname);
}
/**
* Render Tab Links
*
* @param array $tab_title entire array consisting of ['title'], ['id'], ['icon']
* @param string $link_active_arrkey tab_active() function or the $_GET request to match the $tab_title['id']
* @param string $id unique ID
* @param bool|FALSE $link default false for jquery, true for php (will reload page)
* @param bool|FALSE $class the class for the nav
* @param string $getname the get request
* @param array $cleanup_GET the request key that needs to be deleted
* @param bool|FALSE $remember set to true to automatically remember tab using cookie.
* Example:
* $tab_title['title'][] = "Tab 1";
* $tab_title['id'][] = "tab1";
*
* $tab_title['title'][] = "Tab 2";
* $tab_title['id'][] = "tab2";
*
* $tab_active = tab_active($tab_title, 0);
*
* Jquery:
* echo opentab($tab_title, $tab_active, 'myTab', FALSE, 'nav-pills', 'ref', ['action', 'subaction']);
*
* PHP:
* echo opentab($tab_title, $_GET['ref'], 'myTab', TRUE, 'nav-pills', 'ref', ['action', 'subaction']);
*
* @return string
*/
function opentab($tab_title, $link_active_arrkey, $id, $link = FALSE, $class = FALSE, $getname = "section", array $cleanup_GET = [], $remember = FALSE) {
$fusion_tabs = new FusionTabs();
if ($remember) {
$fusion_tabs->set_remember(TRUE);
}
return $fusion_tabs->opentab($tab_title, $link_active_arrkey, $id, $link, $class, $getname, $cleanup_GET, $remember);
}
/**
* @param string $tab_title deprecated, however this function is replaceable, and the params are accessible.
* @param $tab_id
* @param bool $link_active_arrkey
* @param bool $link deprecated, however this function is replaceable, and the params are accessible.
* @param bool $key
*
* @return mixed
*/
function opentabbody($tab_title, $tab_id, $link_active_arrkey = FALSE, $link = FALSE, $key = FALSE) {
$fusion_tabs = new FusionTabs();
return $fusion_tabs->opentabbody($tab_id, $link_active_arrkey, $key);
}
function closetabbody() {
$fusion_tabs = new FusionTabs();
return $fusion_tabs->closetabbody();
}
function closetab(array $options = []) {
$fusion_tabs = new FusionTabs();
return $fusion_tabs->closetab($options);
}
}
if (!function_exists("display_ratings")) {
/* Standard ratings display */
function display_ratings($total_sum, $total_votes, $link = FALSE, $class = FALSE, $mode = '1') {
$locale = fusion_get_locale();
$start_link = $link ? "\n" : '';
$average = $total_votes > 0 ? number_format($total_sum / $total_votes, 2) : 0;
$str = $mode == 1 ? $average.$locale['global_094'].format_word($total_votes, $locale['fmt_rating']) : "$average/$total_votes";
if ($total_votes > 0) {
$answer = $start_link." ".$str.$end_link;
} else {
$answer = $start_link." ".$str.$end_link;
}
return $answer;
}
}
if (!function_exists("display_comments")) {
/* Standard comment display */
function display_comments($news_comments, $link = FALSE, $class = FALSE, $mode = '1') {
$locale = fusion_get_locale();
$start_link = $link ? "\n" : '';
$str = $mode == 1 ? format_word($news_comments, $locale['fmt_comment']) : $news_comments;
if ($news_comments > 0) {
$start_link = strtr($start_link, ['{%title%}' => "title='".$locale['global_073']."'"]);
} else {
$start_link = strtr($start_link, ['{%title%}' => "title='".sprintf($locale['global_089'], $locale['global_077'])."'"]);
}
return $start_link.$str.$end_link;
}
}
if (!function_exists("fusion_confirm_exit")) {
/* JS form exit confirmation if form has changed */
function fusion_confirm_exit() {
OutputHandler::addToJQuery("
$('form').change(function() {
window.onbeforeunload = function() {
return true;
}
$(':button').bind('click', function() {
window.onbeforeunload = null;
});
});
");
}
}
/**
* Return a list of social media sharing services where an url can be shared
* Requires the loading of Font Awesome which can be enabled in theme settings.
*/
if (!function_exists('social_media_links')) {
/**
* @param $url
* @param array $options
*
* @return string
*/
function social_media_links($url, $options = []) {
$default = [
'facebook' => TRUE,
'twitter' => TRUE,
'reddit' => TRUE,
'vk' => TRUE,
'whatsapp' => TRUE,
'telegram' => TRUE,
'linkedin' => TRUE,
'class' => ''
];
$options += $default;
$services = [];
if ($options['facebook'] == 1) {
$services['facebook'] = [
'name' => 'Facebook',
'icon' => 'fa fa-2x fa-facebook-square',
'url' => 'https://www.facebook.com/sharer.php?u='
];
}
if ($options['twitter'] == 1) {
$services['twitter'] = [
'name' => 'Twitter',
'icon' => 'fa fa-2x fa-twitter-square',
'url' => 'https://twitter.com/intent/tweet?url='
];
}
if ($options['reddit'] == 1) {
$services['reddit'] = [
'name' => 'Reddit',
'icon' => 'fa fa-2x fa-reddit-square',
'url' => 'https://www.reddit.com/submit?url='
];
}
if ($options['vk'] == 1) {
$services['vk'] = [
'name' => 'VK',
'icon' => 'fa fa-2x fa-vk',
'url' => 'https://vk.com/share.php?url='
];
}
if ($options['whatsapp'] == 1) {
$services['whatsapp'] = [
'name' => 'WhatsApp',
'icon' => 'fa fa-2x fa-whatsapp',
'url' => 'https://api.whatsapp.com/send?text='
];
}
if ($options['telegram'] == 1) {
$services['telegram'] = [
'name' => 'Telegram',
'icon' => 'fa fa-2x fa-telegram',
'url' => 'https://telegram.me/share/url?url='
];
}
if ($options['linkedin'] == 1) {
$services['linkedin'] = [
'name' => 'LinkedIn',
'icon' => 'fa fa-2x fa-linkedin',
'url' => 'https://www.linkedin.com/shareArticle?mini=true&url=',
];
}
$html = '';
if (!empty($services) && is_array($services)) {
foreach ($services as $service) {
$html .= ' ';
}
}
return $html;
}
}