Skip to content

Commit

Permalink
Made improvements and fixed some bugs found on 2.1
Browse files Browse the repository at this point in the history
Check release notes for more info.
  • Loading branch information
zreedeecom committed Mar 2, 2018
1 parent 812ee05 commit e92661a
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 67 deletions.
13 changes: 6 additions & 7 deletions assets/js/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function checkInput(option) {
if (input.val().length > 2) {
showResponse(option);
} else {
inputError('Please type in your name.');
inputError(botVars.validationName);
}
return false;

Expand Down Expand Up @@ -91,7 +91,7 @@ function checkEmail(option) {
showResponse(option);

} else {
inputError('Please type in a valid email address.');
inputError(botVars.validationEmail);
}
return false;
}
Expand Down Expand Up @@ -121,8 +121,7 @@ function startConversation(conv, pos) {
conversationPos = conv;

// Load conversation data
jQuery.getScript( "/wp-content/plugins/wp-maintenance-mode/assets/js/data.js", function( data ) {

jQuery.getScript( botVars.uploadsBaseUrl + "data.js", function( data ) {
// Show first bot statement
showStatement(pos);

Expand Down Expand Up @@ -281,7 +280,7 @@ function showStatement(pos) {
// Create an input, append to user bubble
var input = jQuery('<input/>', {
type: 'text',
placeholder: 'Type your name here…',
placeholder: botVars.typeName,
name: option['name'],
autocomplete: 'off',
required: true
Expand Down Expand Up @@ -331,14 +330,14 @@ function showStatement(pos) {
// Create email input, append to user bubble
var input = jQuery('<input/>', {
type: 'email',
placeholder: 'Type your email here…',
placeholder: botVars.typeEmail,
name: option['email'],
autocomplete: 'off'
}).appendTo(inputBubble);

// Create an input button, append to user bubble
var button = jQuery('<a/>', {
text: 'Send',
text: botVars.send,
// "class": "user-email-trigger",
click: checkEmail.bind(null, option)
}).appendTo(inputBubble);
Expand Down
2 changes: 1 addition & 1 deletion assets/js/bot.min.js

Large diffs are not rendered by default.

18 changes: 0 additions & 18 deletions assets/js/data.js

This file was deleted.

53 changes: 27 additions & 26 deletions includes/classes/wp-maintenance-mode-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -455,35 +455,36 @@ public function add_safe_style_css($properties) {
public function set_datajs_file($messages = array()) {
$data = "var botName = \"{$messages['name']}\",\n"
. "botAvatar = \"{$messages['avatar']}\",\n"
."conversationData = {\"homepage\": {1: { \n"
."\"statement\": [\"{$messages['messages']['01']}\", \n"
."\"{$messages['messages']['02']}\", \n"
."\"{$messages['messages']['03']}\"], \n"
."\"input\": {\"name\": \"name\", \"consequence\": 1.2}},1.2:{\"statement\": function(context) {return [ \n"
."\"{$messages['messages']['04']}\", \n"
."\"{$messages['messages']['05']}\", \n"
."\"{$messages['messages']['06']}\", \n"
."\"{$messages['messages']['07']}\"];},\"options\": [{ \n"
."\"choice\": \"{$messages['responses']['02_1']}\",\"consequence\": 1.4},{ \n"
."\"choice\": \"{$messages['responses']['02_2']}\",\"consequence\": 1.5}]},1.4: { \n"
."\"statement\": [\"{$messages['messages']['08_1']}\"], \n"
."\"email\": {\"email\": \"email\", \"consequence\": 1.6}},1.5: {\"statement\": function(context) {return [ \n"
."\"{$messages['messages']['08_2']}\"];}},1.6: { \n"
."\"statement\": [\"{$messages['messages']['09']}\", \n"
."\"{$messages['messages']['10']}\"]}}};";

// Merge data partials
// $data = $data . $data2;

// Replace *name of visitor* KEY
$data = str_replace('*name of visitor*', "\" + context.name + \"", $data);
// Replace *bot name* KEY
$data = str_replace('*bot name*', $messages['name'], $data);
. "conversationData = {\"homepage\": {1: { \"statement\": [ \n";
$data .= (!empty($messages['messages']['01'])) ? "\"{$messages['messages']['01']}\", \n" : '';
$data .= (!empty($messages['messages']['02'])) ? "\"{$messages['messages']['02']}\", \n" : '';
$data .= (!empty($messages['messages']['03'])) ? "\"{$messages['messages']['03']}\", \n" : '';
$data .= "], \"input\": {\"name\": \"name\", \"consequence\": 1.2}},1.2:{\"statement\": function(context) {return [ \n";
$data .= (!empty($messages['messages']['04'])) ? "\"{$messages['messages']['04']}\", \n" : '';
$data .= (!empty($messages['messages']['05'])) ? "\"{$messages['messages']['05']}\", \n" : '';
$data .= (!empty($messages['messages']['06'])) ? "\"{$messages['messages']['06']}\", \n" : '';
$data .= (!empty($messages['messages']['07'])) ? "\"{$messages['messages']['07']}\", \n" : '';
$data .= "];},\"options\": [{ \"choice\": \"{$messages['responses']['02_1']}\",\"consequence\": 1.4},{ \n"
. "\"choice\": \"{$messages['responses']['02_2']}\",\"consequence\": 1.5}]},1.4: { \"statement\": [ \n";
$data .= (!empty($messages['messages']['08_1'])) ? "\"{$messages['messages']['08_1']}\", \n" : '';
$data .= "], \"email\": {\"email\": \"email\", \"consequence\": 1.6}},1.5: {\"statement\": function(context) {return [ \n";
$data .= (!empty($messages['messages']['08_2'])) ? "\"{$messages['messages']['08_2']}\", \n" : '';
$data .= "];}},1.6: { \"statement\": [ \n";
$data .= (!empty($messages['messages']['09'])) ? "\"{$messages['messages']['09']}\", \n" : '';
$data .= (!empty($messages['messages']['10'])) ? "\"{$messages['messages']['10']}\", \n" : '';
$data .= "]}}};";

// Replace {visitor_name} KEY
$data = str_replace('{visitor_name}', "\" + context.name + \"", $data);
// Replace {bot_name} KEY
$data = str_replace('{bot_name}', $messages['name'], $data);

// Try to write data.js file
try {
if ( file_put_contents( WPMM_PATH . 'assets/js/data.js', $data) === false ){
throw new Exception(__("The file data.js could not be written, the bot will not work correctly", $this->plugin_slug));
$upload_dir = wp_upload_dir();
// if ( file_put_contents( WPMM_PATH . 'assets/js/data.js', $data) === false ){
if ( file_put_contents( trailingslashit($upload_dir['basedir']) . 'data.js', $data) === false ){
throw new Exception(__("WPMM: The file data.js could not be written, the bot will not work correctly.", $this->plugin_slug));
}
} catch (Exception $ex) {
error_log($ex->getMessage());
Expand Down
35 changes: 29 additions & 6 deletions includes/classes/wp-maintenance-mode.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class WP_Maintenance_Mode {

const VERSION = '2.1';
const VERSION = '2.1.1';

protected $plugin_slug = 'wp-maintenance-mode';
protected $plugin_settings;
Expand Down Expand Up @@ -142,15 +142,15 @@ public function default_settings() {
'name' => 'Admin',
'avatar' => '',
'messages' => array(
'01' => __("Hey! My name is *bot name*, I'm the owner of this website and I'd like to be your assistant here.", $this->plugin_slug),
'01' => __("Hey! My name is {bot_name}, I'm the owner of this website and I'd like to be your assistant here.", $this->plugin_slug),
'02' => __("I have just a few questions.", $this->plugin_slug),
'03' => __("What is your name?", $this->plugin_slug),
'04' => __("Nice to meet you here, *name of visitor*!"),
'04' => __("Nice to meet you here, {visitor_name}!"),
'05' => __("How you can see, our website will be lauched very soon.", $this->plugin_slug),
'06' => __("I know, you are very excited to see it, but we need a few days to finish it.", $this->plugin_slug),
'07' => __("Would you like to be first to see it?", $this->plugin_slug),
'08_1' => __("Cool! Please leave your email here and I will send you a message when it's ready.", $this->plugin_slug),
'08_2' => __("Sad to hear that, *name of visitor* :( See you next time…", $this->plugin_slug),
'08_2' => __("Sad to hear that, {visitor_name} :( See you next time…", $this->plugin_slug),
'09' => __("Got it! Thank you and see you soon here!", $this->plugin_slug),
'10' => __("Have a great day!", $this->plugin_slug)
),
Expand Down Expand Up @@ -539,7 +539,8 @@ public function init() {
$scripts['validate'] = WPMM_JS_URL . 'jquery.validate' . WPMM_ASSETS_SUFFIX . '.js';
}
if(!empty($this->plugin_settings['bot']['status']) && $this->plugin_settings['bot']['status'] == 1) {
$scripts['bot'] = WPMM_JS_URL . 'bot' . WPMM_ASSETS_SUFFIX . '.js';
$scripts['bot'] = WPMM_JS_URL . 'bot' . WPMM_ASSETS_SUFFIX . '.js';
add_action('wpmm_before_scripts', array($this, 'add_bot_extras'));
}
$scripts = apply_filters('wpmm_scripts', $scripts);

Expand All @@ -549,7 +550,7 @@ public function init() {
);
if(!empty($this->plugin_settings['bot']['status']) && $this->plugin_settings['bot']['status'] == 1) {
$styles['bot'] = WPMM_CSS_URL . 'style.bot'. WPMM_ASSETS_SUFFIX . '.css';
$body_classes .= ' bot';
$body_classes .= ' bot';
}
$styles = apply_filters('wpmm_styles', $styles);

Expand All @@ -575,6 +576,28 @@ public function init() {
}
}

/**
* Extra variables for the bot functionality. Added to the DOM via hooks.
* It has to be called before scripts are loaded so the variables are available globally.
*
* @todo Maybe we can find a better home for this method
* @since 2.1.1
*/
public function add_bot_extras(){
$upload_dir = wp_upload_dir();
$bot_vars = array(
'validationName' => __('Please type in your name.', $this->plugin_slug),
'validationEmail' => __('Please type in a valid email address.', $this->plugin_slug),
'uploadsBaseUrl' => trailingslashit($upload_dir['baseurl']),
'typeName' => __('Type your name here…', $this->plugin_slug),
'typeEmail' => __('Type your email here…', $this->plugin_slug),
'send' => __('Send', $this->plugin_slug)
);
echo "<script type='text/javascript'>" .
"var botVars = " . json_encode($bot_vars) .
"</script>";
}

/**
* Check if the current user has access to backend / frontend based on his role compared with role from settings (refactor @ 2.0.4)
*
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Version 2.1
# Version 2.1.1

# WP Maintenance Mode

Expand Down
9 changes: 8 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Author URI: https://designmodo.com/
Tags: maintenance mode, admin, administration, unavailable, coming soon, multisite, landing page, under construction, contact form, subscribe, countdown
Requires at least: 3.5
Tested up to: 4.9.4
Stable tag: 2.1
Stable tag: 2.1.1
License: GPL-2.0+

Adds a splash page to your site that lets visitors know your site is down for maintenance. It's perfect for a coming soon page. The new Bot functionality is here!
Expand Down Expand Up @@ -74,6 +74,13 @@ If you change your login url, please add the new slug (url: http://domain.com/ne

== Changelog ==

= 2.1.1 (1/03/2018) =
* fixed a visual bug with wrap container
* added internationalization support for bot fixed strings
* fixed path for loading data.js required for the bot (thanks @ [George Jipa](https://github.com/georgejipa))
* added wpmm_before_scripts hook, fires just before loading the scripts
* moved data.js to uploads directory (thanks @ [George Jipa](https://github.com/georgejipa))

= 2.1 (27/02/2018) =
* added bot feature
* css fixes
Expand Down
20 changes: 15 additions & 5 deletions views/maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,16 @@
<div class="wrap">
<?php if (!empty($heading)) { ?><h1><?php echo stripslashes($heading); ?></h1><?php } ?>

<?php // If bot is enabled no text will be shown ?>
<?php if (!empty($text)&&$this->plugin_settings['bot']['status'] === 0) { ?><h2><?php echo stripslashes($text); ?></h2><?php } ?>
<!-- </div> -->
<?php
// If bot is enabled no text will be shown
if ( !empty($text) && $this->plugin_settings['bot']['status'] === 0) {
echo "<h2>" . stripslashes($text) . "</h2>";
}
?>


<?php if (!empty($this->plugin_settings['bot']['status']) && $this->plugin_settings['bot']['status'] === 1) { ?>
</div><!-- .wrap -->
<div class="bot-container">
<!-- WP Bot -->
<div class="bot-chat-wrapper">
Expand All @@ -48,7 +53,7 @@
<!-- /WP Bot -->
</div>
<div class="bot-error"><p></p></div>
<!-- <div class="wrap under-bot"> -->
<div class="wrap under-bot">
<?php } ?>

<?php
Expand Down Expand Up @@ -141,8 +146,13 @@

<script type='text/javascript'>
var wpmm_vars = {"ajax_url": "<?php echo admin_url('admin-ajax.php'); ?>"};
</script>
</script>

<?php

// Hook before scripts, mostly for internationalization
do_action('wpmm_before_scripts');

if (!empty($scripts) && is_array($scripts)) {
foreach ($scripts as $src) {
?>
Expand Down
3 changes: 2 additions & 1 deletion views/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,8 @@
</th> -->
<td colspan="2">
<h4><?php _e("Setup the conversation steps to capture more subscribers with this friendly way of asking email addresess.", $this->plugin_slug) ?></h4>
<p><?php _e("You may also want to use these wildcards: *bot name* and *name of visitor* to make the conversation even more realistic.", $this->plugin_slug) ?></p>
<p><?php _e("You may also want to use these wildcards: {bot_name} and {visitor_name} to make the conversation even more realistic.", $this->plugin_slug) ?></p>
<p><?php _e("It is also ok if you don't fill in all the conversation steps if you don't need to.", $this->plugin_slug) ?></p>
</td>
</tr>
<tr valign="top">
Expand Down
2 changes: 1 addition & 1 deletion wp-maintenance-mode.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Plugin Name: WP Maintenance Mode
* Plugin URI: https://designmodo.com/
* Description: Adds a splash page to your site that lets visitors know your site is down for maintenance. It's perfect for a coming soon page.
* Version: 2.1
* Version: 2.1.1
* Author: Designmodo
* Author URI: https://designmodo.com/
* Twitter: designmodo
Expand Down

0 comments on commit e92661a

Please sign in to comment.