seed.length) return Array(1 + (reqWidth - seed.length)).join ('0') + seed; return seed; }; if (typeof S2MEMBER_VALUE_FOR_PP_INV_GEN_UNIQUE_SEED === 'undefined') S2MEMBER_VALUE_FOR_PP_INV_GEN_UNIQUE_SEED = Math.floor (Math.random () * 0x75bcd15); S2MEMBER_VALUE_FOR_PP_INV_GEN_UNIQUE_SEED++; invoice = formatSeed(parseInt(new Date ().getTime () / 1000, 10), 8); invoice += formatSeed(S2MEMBER_VALUE_FOR_PP_INV_GEN_UNIQUE_SEED, 5); invoice += '~' + S2MEMBER_CURRENT_USER_IP; return invoice; },"; echo "S2MEMBER_CURRENT_USER_VALUE_FOR_PP_ON0 = '".c_ws_plugin__s2member_utils_strings::esc_js_sq(S2MEMBER_CURRENT_USER_VALUE_FOR_PP_ON0)."',"; echo "S2MEMBER_CURRENT_USER_VALUE_FOR_PP_OS0 = '".c_ws_plugin__s2member_utils_strings::esc_js_sq(S2MEMBER_CURRENT_USER_VALUE_FOR_PP_OS0)."',"; echo "S2MEMBER_CURRENT_USER_VALUE_FOR_PP_ON1 = '".c_ws_plugin__s2member_utils_strings::esc_js_sq(S2MEMBER_CURRENT_USER_VALUE_FOR_PP_ON1)."',"; echo "S2MEMBER_CURRENT_USER_VALUE_FOR_PP_OS1 = '".c_ws_plugin__s2member_utils_strings::esc_js_sq(S2MEMBER_CURRENT_USER_VALUE_FOR_PP_OS1)."';"; } else // Expose only what is needed by the s2Member application itself; for the current user. echo self::current_user_js_globals(); $u = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["dir_url"]; $i = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["dir_url"]."/src/images"; echo "\n"; // Add a line break before inclusion. include_once dirname(dirname(__FILE__))."/s2member.min.js"; do_action("ws_plugin__s2member_during_js_w_globals", get_defined_vars()); //260912.0522 Append the activation-tag snippet after successful dynamic JavaScript so real pages can confirm that the expected script became active. echo c_ws_plugin__s2member_utils_assets::dynamic_activation_tag_snippet('js'); exit(); // Clean exit. } do_action("ws_plugin__s2member_after_js_w_globals", get_defined_vars()); } /** * Returns the current-user JavaScript globals required by s2Member's frontend application. * * @package s2Member\CSS_JS * @since 260903.0437 * * @param bool $for_inline Escape HTML-closing sequences for safe inline-script output. * @return string JavaScript variable declarations. */ public static function current_user_js_globals($for_inline = FALSE) { $required_constants = array( 'S2MEMBER_CURRENT_USER_IS_LOGGED_IN', 'S2MEMBER_CURRENT_USER_IS_LOGGED_IN_AS_MEMBER', 'S2MEMBER_CURRENT_USER_FIRST_NAME', 'S2MEMBER_CURRENT_USER_LAST_NAME', 'S2MEMBER_CURRENT_USER_LOGIN', 'S2MEMBER_CURRENT_USER_EMAIL', 'S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED', 'S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED_IS_UNLIMITED', 'S2MEMBER_CURRENT_USER_DOWNLOADS_CURRENTLY', 'S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED_DAYS', ); $constants_ready = TRUE; foreach($required_constants as $constant) if(!defined($constant)) { $constants_ready = FALSE; break; } if($constants_ready) { $is_logged_in = (bool)S2MEMBER_CURRENT_USER_IS_LOGGED_IN; $is_member = (bool)S2MEMBER_CURRENT_USER_IS_LOGGED_IN_AS_MEMBER; $first_name = (string)S2MEMBER_CURRENT_USER_FIRST_NAME; $last_name = (string)S2MEMBER_CURRENT_USER_LAST_NAME; $login = (string)S2MEMBER_CURRENT_USER_LOGIN; $email = (string)S2MEMBER_CURRENT_USER_EMAIL; $downloads_allowed = (int)S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED; $downloads_unlimited = (bool)S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED_IS_UNLIMITED; $downloads_currently = (int)S2MEMBER_CURRENT_USER_DOWNLOADS_CURRENTLY; $downloads_allowed_days = (int)S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED_DAYS; } else { //260913.0036 Another plugin may print login-page scripts before s2Member's normal init-priority constants setup; derive only the values this inline JavaScript needs without changing initialization order. $user = (is_user_logged_in() && is_object($user = wp_get_current_user()) && !empty($user->ID)) ? $user : FALSE; $level = c_ws_plugin__s2member_user_access::user_access_level($user); $downloads = c_ws_plugin__s2member_files::user_downloads($user); $is_logged_in = (bool)$user; $is_member = (bool)($user && $level >= 1); $first_name = ($user) ? (string)$user->first_name : ''; $last_name = ($user) ? (string)$user->last_name : ''; $login = ($user) ? (string)$user->user_login : ''; $email = ($user) ? (string)$user->user_email : ''; $downloads_allowed = (!empty($downloads['allowed'])) ? (int)$downloads['allowed'] : 0; $downloads_unlimited = $downloads_allowed >= 999999999; $downloads_currently = (!empty($downloads['currently'])) ? (int)$downloads['currently'] : 0; $downloads_allowed_days = (!empty($downloads['allowed_days'])) ? (int)$downloads['allowed_days'] : 0; } $g = "var S2MEMBER_CURRENT_USER_IS_LOGGED_IN = ".(($is_logged_in) ? "true" : "false").","; $g .= "S2MEMBER_CURRENT_USER_IS_LOGGED_IN_AS_MEMBER = ".(($is_member) ? "true" : "false").","; $g .= "S2MEMBER_CURRENT_USER_FIRST_NAME = '".c_ws_plugin__s2member_utils_strings::esc_js_sq($first_name)."',"; $g .= "S2MEMBER_CURRENT_USER_LAST_NAME = '".c_ws_plugin__s2member_utils_strings::esc_js_sq($last_name)."',"; $g .= "S2MEMBER_CURRENT_USER_LOGIN = '".c_ws_plugin__s2member_utils_strings::esc_js_sq($login)."',"; $g .= "S2MEMBER_CURRENT_USER_EMAIL = '".c_ws_plugin__s2member_utils_strings::esc_js_sq($email)."',"; $g .= "S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED = ".$downloads_allowed.","; $g .= "S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED_IS_UNLIMITED = ".(($downloads_unlimited) ? "true" : "false").","; $g .= "S2MEMBER_CURRENT_USER_DOWNLOADS_CURRENTLY = ".$downloads_currently.","; $g .= "S2MEMBER_CURRENT_USER_DOWNLOADS_ALLOWED_DAYS = ".$downloads_allowed_days.";"; //260903.0437 Inline data is HTML, not an external JS response; neutralize any user-controlled closing-script sequence before WordPress prints it. return ($for_inline) ? str_ireplace('