$value = json_decode($heatmap->value); $counter += $value->max; } } } if ($counter == 0) { if ($exp->get_status() == NelioABExperiment::STATUS_RUNNING) { $err = NelioABErrCodes::NO_HEATMAPS_AVAILABLE; throw new Exception(NelioABErrCodes::to_string($err), $err); } else { $err = NelioABErrCodes::NO_HEATMAPS_AVAILABLE_FOR_NON_RUNNING_EXPERIMENT; throw new Exception(NelioABErrCodes::to_string($err), $err); } } } catch (Exception $e) { echo sprintf('<img src="%s" alt="%s" style="margin-top:50px;"/>', nelioab_asset_link('/admin/images/white-error-icon.png'), __('Funny image to graphically notify of an error.', 'nelioab')); ?> <p id="ajax-loader-label1" style="margin-top:10px;color:white;font-size:20px;"><?php echo $e->getMessage(); ?> </p><?php die; } // Prepare the content $page_on_front = nelioab_get_page_on_front(); if (!$page_on_front && !$post_id) { // if the home page is the list of posts and the experiment is for the home page $url = get_option('home'); } else { // otherwise (1 - the heatmaps is NOT for the home page or 2 - the home page is a specific page, the heatmaps should display that page
public function render() { ?> <script type="text/javascript" src="<?php echo nelioab_admin_asset_link('/js/tablesorter.min.js'); ?> "></script><?php $is_data_pending_loader = 'display:none;'; $is_data_pending_data = 'display:visible;'; if ($this->is_data_pending) { $is_data_pending_loader = 'display:visible;'; $is_data_pending_data = 'display:none;'; } ?> <script type="text/javascript"> function smoothTransitions() { jQuery("#ajax-loader-label2").hide().delay(10000).fadeIn('fast'); jQuery("#poststuff").delay(100).fadeOut(150); jQuery("#errors-div").delay(100).fadeOut(150); jQuery("#error-message-div").delay(100).fadeOut(150); jQuery("#message-div").delay(100).fadeOut(150); jQuery("#ajax-loader").delay(260).fadeIn(150); } </script> <div class="wrap"> <div class="icon32" id="<?php echo $this->icon_id; ?> "></div> <h2><?php echo $this->title . ' ' . $this->title_action; ?> </h2> <?php if ($this->is_data_pending) { $this->print_global_warnings(); $this->print_error_message('none'); $this->print_message('none'); $this->print_errors('none'); } else { $this->print_error_message(); $this->print_message(); $this->print_errors(); } ?> <br /> <div id="ajax-loader" style="text-align:center;<?php echo $is_data_pending_loader; ?> "> <br /><br /> <div style="text-align:center;height:50px;"> <div class="nelioab_spinner"></div> </div> <h2 style="color:#555;margin:0;padding:0;"><?php _e('Loading...', 'nelioab'); ?> </h2> <p id="ajax-loader-label1" style="color:#777;margin:0;padding:0;"><?php _e('Please, wait a moment.', 'nelioab'); ?> </p> <p id="ajax-loader-label2" style="color:#777;margin:0;padding:0;display:none;"><?php _e('Keep waiting...', 'nelioab'); ?> </p> <p id="ajax-loader-label3" style="color:#777;margin:0;padding:0;display:none;"><?php _e('Internet connection seems very slow.', 'nelioab'); ?> </p> </div> <div id="poststuff" class="metabox-hold" style="<?php echo $is_data_pending_data; ?> "> <div id="ajax-data"><?php if (!$this->is_data_pending) { $this->do_render(); ?> <br /> <div class="actions"><?php $this->print_page_buttons(); ?> </div><?php } ?> </div> </div> </div><?php if (!$this->is_data_pending) { ?> <div id="dialog-modal" title="Basic modal dialog" style="display:none;"> <div id="dialog-content"> <?php $this->print_dialog_content(); ?> </div> </div> <?php } if ($this->is_data_pending) { ?> <script> function nelioabHideSpinnerAndShowContent() { var $ajaxLoader = jQuery("#ajax-loader"); $ajaxLoader.fadeOut(200, function() { var $postStuff = jQuery("#poststuff"); $postStuff.fadeIn(200); var aux; var $errMsgDiv = jQuery("#error-message-div"); var $msgDiv = jQuery("#message-div"); var $errorsDiv = jQuery("#errors-div"); aux = jQuery.trim( jQuery("#error-message-box-delayed").html() ); if ( aux.length > 0 ) { $errMsgDiv.addClass("to-be-shown"); $errMsgDiv.html( aux ); } aux = jQuery.trim( jQuery("#message-box-delayed").html() ); if ( aux.length > 0 ) { $msgDiv.addClass("to-be-shown"); $msgDiv.html( aux ); } aux = jQuery.trim( jQuery("#errors-box-delayed").html() ); if ( aux.length > 0 ) { $errorsDiv.addClass("to-be-shown"); $errorsDiv.html( aux ); } if ( $errMsgDiv.hasClass("to-be-shown") ) { $errMsgDiv.css('display','block'); $errMsgDiv.hide(); $errMsgDiv.fadeIn(200); } if ( $msgDiv.hasClass("to-be-shown") ) { $msgDiv.css('display','block'); $msgDiv.hide(); $msgDiv.fadeIn(200); } if ( $errorsDiv.hasClass("to-be-shown") ) { $errorsDiv.css('display','block'); $errorsDiv.hide(); $errorsDiv.fadeIn(200); } jQuery(document).trigger('nelioab-ajax-page-loaded'); }); } jQuery(document).ready(function() { var data = { "action" : "nelioab_get_html_content",<?php foreach ($this->post_params as $param) { echo "\n\t\t\t\t\t\t\"{$param['0']}\" : \"{$param['1']}\","; } ?> "filename" : "<?php echo $this->controller_file; ?> ", "classname" : "<?php echo $this->controller_class; ?> " }; // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php jQuery.ajax({ type: 'POST', url: ajaxurl, data: data, success: function(response){ jQuery("#poststuff > #ajax-data").html(response); nelioabHideSpinnerAndShowContent(); }, error: function() { jQuery("#ajax-loader").html( "<?php printf("<img src='%s' alt='%s' />", nelioab_asset_link('/admin/images/error-icon.png'), __('Funny image to graphically notify of an error.', 'nelioab')); ?> " + "<h2 style='color:#555;margin:0;padding:0;'><?php _e('Oops! There was an AJAX-related error.'); ?> </h2>" + "<div style='color:#999;text-align:left;max-width:600px;margin:auto;'>" + "<br /><br /><b>Details:</b><br />" + "<u>Class</u>: " + data.classname + "<br />" + "<u>File</u>: " + data.filename + "<br />" + "</div>"); } }); jQuery("#ajax-loader-label2").hide().delay(10000).fadeIn('fast'); //jQuery("#ajax-loader-label3").hide().delay(15000).fadeIn('fast'); }); </script> <?php } }
/** * This function returns the URL of the given resource, appending the current * version of the plugin. The resource has to be a file in NELIOAB_ASSETS_DIR * * @param string $resource PHPDOC * @param boolean $include_version PHPDOC * Default: `true`. * * @return string PHPDOC * * @since PHPDOC */ function nelioab_admin_asset_link($resource, $include_version = true) { return nelioab_asset_link('/admin' . $resource, $include_version); }
/** * This function registers Nelio tracking scripts. * * Our tracking scripts are: * * * `nelioab_appengine_script`: a script pointing to Google Cloud Storage, * with all the information about running experiments. * * `nelioab_tracking_script`: our tracking script. * * It also initializes some params that will be used by our tracking * script. They'll be available by means of the object `NelioABParams`. * * @return void * * @see self::load_tracking_script * * @since 3.3.2 */ public function register_tracking_script() { wp_register_script('nelioab_appengine_script', '//storage.googleapis.com/' . NELIOAB_BACKEND_NAME . '/' . NelioABAccountSettings::get_site_id() . '.js', array(), NELIOAB_PLUGIN_VERSION); wp_register_script('nelioab_tracking_script', nelioab_asset_link('/js/tracking.min.js', false), array('jquery', 'nelioab_appengine_script'), NELIOAB_PLUGIN_VERSION); // Prepare some information for our tracking script (such as the page we're in) /** @var $aux NelioABAlternativeExperimentController */ $aux = $this->controllers['alt-exp']; $current_id = $this->get_queried_post_id(); if ($aux->is_post_in_a_post_alt_exp($current_id)) { $current_actual_id = intval($aux->get_post_alternative($current_id)); } elseif ($aux->is_post_in_a_headline_alt_exp($current_id)) { $headline_data = $aux->get_headline_experiment_and_alternative($current_id); /** @var NelioABAlternative $alternative */ $alternative = $headline_data['alt']; $val = $alternative->get_value(); $current_actual_id = $val['id']; } else { $current_actual_id = $current_id; } $current_page_ids = array('currentId' => $current_id, 'currentActualId' => $current_actual_id); // OUTWARDS NAVIGATIONS USING TARGET="_BLANK" $misc['useOutwardsNavigationsBlank'] = NelioABSettings::use_outwards_navigations_blank(); $this->tracking_script_params = array('ajaxurl' => admin_url('admin-ajax.php', is_ssl() ? 'https' : 'http'), 'version' => NELIOAB_PLUGIN_VERSION, 'customer' => NelioABAccountSettings::get_customer_id(), 'site' => NelioABAccountSettings::get_site_id(), 'backend' => array('domain' => NELIOAB_BACKEND_DOMAIN, 'version' => NELIOAB_BACKEND_VERSION), 'misc' => $misc, 'sync' => array('headlines' => array()), 'info' => $current_page_ids, 'ieUrl' => preg_replace('/^https?:/', '', NELIOAB_URL . '/ajax/iesupport.php'), 'wasPostRequest' => 'POST' === $_SERVER['REQUEST_METHOD']); }