<?php
/**
 * SeoHub Framework: messages subsystem
 *
 * @package	seohub
 * @since	seohub 1.0
 */

// Disable direct call
if ( ! defined( 'ABSPATH' ) ) { exit; }

// Theme init
if (!function_exists('seohub_messages_theme_setup')) {
	add_action( 'seohub_action_before_init_theme', 'seohub_messages_theme_setup' );
	function seohub_messages_theme_setup() {
		// Core messages strings
		add_action('seohub_action_add_scripts_inline', 'seohub_messages_add_scripts_inline');
	}
}


/* Session messages
------------------------------------------------------------------------------------- */

if (!function_exists('seohub_get_error_msg')) {
	function seohub_get_error_msg() {
		global $SEOHUB_GLOBALS;
		return !empty($SEOHUB_GLOBALS['error_msg']) ? $SEOHUB_GLOBALS['error_msg'] : '';
	}
}

if (!function_exists('seohub_set_error_msg')) {
	function seohub_set_error_msg($msg) {
		global $SEOHUB_GLOBALS;
		$msg2 = seohub_get_error_msg();
		$SEOHUB_GLOBALS['error_msg'] = $msg2 . ($msg2=='' ? '' : '<br />') . ($msg);
	}
}

if (!function_exists('seohub_get_success_msg')) {
	function seohub_get_success_msg() {
		global $SEOHUB_GLOBALS;
		return !empty($SEOHUB_GLOBALS['success_msg']) ? $SEOHUB_GLOBALS['success_msg'] : '';
	}
}

if (!function_exists('seohub_set_success_msg')) {
	function seohub_set_success_msg($msg) {
		global $SEOHUB_GLOBALS;
		$msg2 = seohub_get_success_msg();
		$SEOHUB_GLOBALS['success_msg'] = $msg2 . ($msg2=='' ? '' : '<br />') . ($msg);
	}
}

if (!function_exists('seohub_get_notice_msg')) {
	function seohub_get_notice_msg() {
		global $SEOHUB_GLOBALS;
		return !empty($SEOHUB_GLOBALS['notice_msg']) ? $SEOHUB_GLOBALS['notice_msg'] : '';
	}
}

if (!function_exists('seohub_set_notice_msg')) {
	function seohub_set_notice_msg($msg) {
		global $SEOHUB_GLOBALS;
		$msg2 = seohub_get_notice_msg();
		$SEOHUB_GLOBALS['notice_msg'] = $msg2 . ($msg2=='' ? '' : '<br />') . ($msg);
	}
}


/* System messages (save when page reload)
------------------------------------------------------------------------------------- */
if (!function_exists('seohub_set_system_message')) {
	function seohub_set_system_message($msg, $status='info', $hdr='') {
		update_option('seohub_message', array('message' => $msg, 'status' => $status, 'header' => $hdr));
	}
}

if (!function_exists('seohub_get_system_message')) {
	function seohub_get_system_message($del=false) {
		$msg = get_option('seohub_message', false);
		if (!$msg)
			$msg = array('message' => '', 'status' => '', 'header' => '');
		else if ($del)
			seohub_del_system_message();
		return $msg;
	}
}

if (!function_exists('seohub_del_system_message')) {
	function seohub_del_system_message() {
		delete_option('seohub_message');
	}
}


/* Messages strings
------------------------------------------------------------------------------------- */

if (!function_exists('seohub_messages_add_scripts_inline')) {
	function seohub_messages_add_scripts_inline() {
		global $SEOHUB_GLOBALS;
		echo '<script type="text/javascript">'
			
			. "if (typeof SEOHUB_GLOBALS == 'undefined') var SEOHUB_GLOBALS = {};"
			
			// Strings for translation
			. 'SEOHUB_GLOBALS["strings"] = {'
				. 'ajax_error: 			"' . addslashes(esc_html__('Invalid server answer', 'seohub')) . '",'
				. 'bookmark_add: 		"' . addslashes(esc_html__('Add the bookmark', 'seohub')) . '",'
				. 'bookmark_added:		"' . addslashes(esc_html__('Current page has been successfully added to the bookmarks. You can see it in the right panel on the tab \'Bookmarks\'', 'seohub')) . '",'
				. 'bookmark_del: 		"' . addslashes(esc_html__('Delete this bookmark', 'seohub')) . '",'
				. 'bookmark_title:		"' . addslashes(esc_html__('Enter bookmark title', 'seohub')) . '",'
				. 'bookmark_exists:		"' . addslashes(esc_html__('Current page already exists in the bookmarks list', 'seohub')) . '",'
				. 'search_error:		"' . addslashes(esc_html__('Error occurs in AJAX search! Please, type your query and press search icon for the traditional search way.', 'seohub')) . '",'
				. 'email_confirm:		"' . addslashes(esc_html__('On the e-mail address "%s" we sent a confirmation email. Please, open it and click on the link.', 'seohub')) . '",'
				. 'reviews_vote:		"' . addslashes(esc_html__('Thanks for your vote! New average rating is:', 'seohub')) . '",'
				. 'reviews_error:		"' . addslashes(esc_html__('Error saving your vote! Please, try again later.', 'seohub')) . '",'
				. 'error_like:			"' . addslashes(esc_html__('Error saving your like! Please, try again later.', 'seohub')) . '",'
				. 'error_global:		"' . addslashes(esc_html__('Global error text', 'seohub')) . '",'
				. 'name_empty:			"' . addslashes(esc_html__('The name can\'t be empty', 'seohub')) . '",'
				. 'name_long:			"' . addslashes(esc_html__('Too long name', 'seohub')) . '",'
				. 'email_empty:			"' . addslashes(esc_html__('Too short (or empty) email address', 'seohub')) . '",'
				. 'email_long:			"' . addslashes(esc_html__('Too long email address', 'seohub')) . '",'
				. 'email_not_valid:		"' . addslashes(esc_html__('Invalid email address', 'seohub')) . '",'
				. 'subject_empty:		"' . addslashes(esc_html__('The subject can\'t be empty', 'seohub')) . '",'
				. 'subject_long:		"' . addslashes(esc_html__('Too long subject', 'seohub')) . '",'
				. 'text_empty:			"' . addslashes(esc_html__('The message text can\'t be empty', 'seohub')) . '",'
				. 'text_long:			"' . addslashes(esc_html__('Too long message text', 'seohub')) . '",'
				. 'send_complete:		"' . addslashes(esc_html__("Send message complete!", 'seohub')) . '",'
				. 'send_error:			"' . addslashes(esc_html__('Transmit failed!', 'seohub')) . '",'
				. 'login_empty:			"' . addslashes(esc_html__('The Login field can\'t be empty', 'seohub')) . '",'
				. 'login_long:			"' . addslashes(esc_html__('Too long login field', 'seohub')) . '",'
				. 'login_success:		"' . addslashes(esc_html__('Login success! The page will be reloaded in 3 sec.', 'seohub')) . '",'
				. 'login_failed:		"' . addslashes(esc_html__('Login failed!', 'seohub')) . '",'
				. 'password_empty:		"' . addslashes(esc_html__('The password can\'t be empty and shorter then 4 characters', 'seohub')) . '",'
				. 'password_long:		"' . addslashes(esc_html__('Too long password', 'seohub')) . '",'
				. 'password_not_equal:	"' . addslashes(esc_html__('The passwords in both fields are not equal', 'seohub')) . '",'
				. 'registration_success:"' . addslashes(esc_html__('Registration success! Please log in!', 'seohub')) . '",'
				. 'registration_failed:	"' . addslashes(esc_html__('Registration failed!', 'seohub')) . '",'
				. 'geocode_error:		"' . addslashes(esc_html__('Geocode was not successful for the following reason:', 'seohub')) . '",'
				. 'googlemap_not_avail:	"' . addslashes(esc_html__('Google map API not available!', 'seohub')) . '",'
				. 'editor_save_success:	"' . addslashes(esc_html__("Post content saved!", 'seohub')) . '",'
				. 'editor_save_error:	"' . addslashes(esc_html__("Error saving post data!", 'seohub')) . '",'
				. 'editor_delete_post:	"' . addslashes(esc_html__("You really want to delete the current post?", 'seohub')) . '",'
				. 'editor_delete_post_header:"' . addslashes(esc_html__("Delete post", 'seohub')) . '",'
				. 'editor_delete_success:	"' . addslashes(esc_html__("Post deleted!", 'seohub')) . '",'
				. 'editor_delete_error:		"' . addslashes(esc_html__("Error deleting post!", 'seohub')) . '",'
				. 'editor_caption_cancel:	"' . addslashes(esc_html__('Cancel', 'seohub')) . '",'
				. 'editor_caption_close:	"' . addslashes(esc_html__('Close', 'seohub')) . '"'
				. '};'
			
			. '</script>';
	}
}
?>