/**
  * Returns a new action object built using the information described in $action.
  *
  * @param object $json a JSON action as used in the admin pages of our plugin.
  *
  * @return NelioABFormSubmissionAction the new action containing all the information in `$action`.
  *
  * @since PHPDOC
  * @Override
  */
 public static function build_action_using_json4js($json)
 {
     if ('cf7' == $json->form_type) {
         $type = NelioABAction::SUBMIT_CF7_FORM;
     } else {
         $type = NelioABAction::SUBMIT_GRAVITY_FORM;
     }
     $action = new NelioABFormSubmissionAction($type, $json->form_id);
     $action->accept_sumissions_from_any_page($json->any_page);
     return $action;
 }
 /**
  * PHPDOC
  *
  * @param string $type    PHPDOC
  * @param int    $form_id PHPDOC
  *
  * @return void
  *
  * @since PHPDOC
  */
 private function send_form_action_if_required($type, $form_id)
 {
     require_once NELIOAB_MODELS_DIR . '/goals/actions/form-submission-action.php';
     require_once NELIOAB_MODELS_DIR . '/goals/actions/action.php';
     require_once NELIOAB_UTILS_DIR . '/backend.php';
     $kap = NelioABFormSubmissionAction::type_to_kind_and_plugin($type);
     if (!$kap) {
         return;
     }
     $f = 'nelioab_current_id';
     if (!isset($_POST[$f])) {
         return;
     }
     $f = 'nelioab_current_actual_id';
     if (!isset($_POST[$f])) {
         return;
     }
     $f = 'nelioab_userid';
     if (!isset($_POST[$f]) || strlen(trim($_POST[$f])) === 0) {
         return;
     }
     // Constructing FORM EVENT object:
     $page = $_POST['nelioab_current_id'];
     $actual_page = $_POST['nelioab_current_actual_id'];
     $ev = array('kind' => $kap['kind'], 'form' => $form_id, 'plugin' => $kap['plugin'], 'page' => $page, 'actualPage' => $actual_page, 'user' => $_POST['nelioab_userid']);
     $the_theme = NelioABVisitor::get_alternative_for_global_alt_exp(NelioABExperiment::THEME_ALT_EXP);
     if ($the_theme) {
         $ev['activeTheme'] = $the_theme->get_id();
     }
     $the_css = NelioABVisitor::get_alternative_for_global_alt_exp(NelioABExperiment::CSS_ALT_EXP);
     if ($the_css) {
         $ev['activeCSS'] = $the_css->get_id();
     }
     $the_widget = NelioABVisitor::get_alternative_for_global_alt_exp(NelioABExperiment::WIDGET_ALT_EXP);
     if ($the_widget) {
         $ev['activeWidget'] = '' . $the_widget->get_id();
     }
     $the_menu = NelioABVisitor::get_alternative_for_global_alt_exp(NelioABExperiment::MENU_ALT_EXP);
     if ($the_menu) {
         $ev['activeMenu'] = $the_menu->get_id();
     }
     // Check if there's one experiment at least with a form submission action,
     // which corresponds to the given form, then send the event. Otherwise,
     // get out!
     require_once NELIOAB_MODELS_DIR . '/experiments-manager.php';
     $send_form_event = false;
     $running_exps = NelioABExperimentsManager::get_relevant_running_experiments_from_cache();
     foreach ($running_exps as $exp) {
         /** @var NelioABExperiment $exp */
         foreach ($exp->get_goals() as $goal) {
             /** @var NelioABAltExpGoal $goal */
             foreach ($goal->get_actions() as $action) {
                 /** @var NelioABFormSubmissionAction $action */
                 if ($action->get_type() == $type && $action->get_form_id() == $ev['form']) {
                     // If this action uses the form, then we have to check whether
                     // it accepts submissions from anywhere or only from the tested
                     // page.
                     if ($action->accepts_submissions_from_any_page()) {
                         $send_form_event = true;
                         break;
                     }
                     if ($exp->get_originals_id() == $ev['page']) {
                         $send_form_event = true;
                         break;
                     }
                 }
             }
             if ($send_form_event) {
                 break;
             }
         }
         if ($send_form_event) {
             break;
         }
     }
     if (!$send_form_event) {
         return;
     }
     $url = sprintf(NELIOAB_BACKEND_URL . '/site/%s/form', NelioABAccountSettings::get_site_id());
     $data = NelioABBackend::build_json_object_with_credentials($ev);
     $data['timeout'] = 50;
     for ($attemp = 0; $attemp < 5; ++$attemp) {
         try {
             NelioABBackend::remote_post_raw($url, $data);
             break;
         } catch (Exception $e) {
             // If the form submission event could not be sent, it may be that's
             // because there is no more quota available
             if ($e->getCode() == NelioABErrCodes::NO_MORE_QUOTA) {
                 // If that was the case, simply leave
                 break;
             }
             // If there was another error... we just keep trying (attemp) up to 5
             // times.
         }
     }
 }
 /**
  * PHPDOC
  *
  * @param NelioABExperiment $exp  PHPDOC
  * @param object            $json PHPDOC
  *
  * @return NelioABAltExpGoal PHPDOC
  *
  * @since PHPDOC
  */
 public static function decode_from_appengine($exp, $json)
 {
     $result = new NelioABAltExpGoal($exp);
     $result->set_id($json->key->id);
     $result->set_name($json->name);
     $result->set_benefit($json->benefit);
     $result->set_as_main_goal($json->isMainGoal);
     $ae_actions = array();
     if (isset($json->pageAccessedActions)) {
         foreach ($json->pageAccessedActions as $action) {
             $action = (array) $action;
             $action['_type'] = 'page-accessed-action';
             $action = (object) $action;
             array_push($ae_actions, $action);
         }
     }
     if (isset($json->formActions)) {
         foreach ($json->formActions as $action) {
             $action = (array) $action;
             $action['_type'] = 'form-action';
             $action = (object) $action;
             array_push($ae_actions, $action);
         }
     }
     if (isset($json->clickActions)) {
         foreach ($json->clickActions as $action) {
             $action = (array) $action;
             $action['_type'] = 'click-element-action';
             $action = (object) $action;
             array_push($ae_actions, $action);
         }
     }
     if (isset($json->orderCompletedActions)) {
         foreach ($json->orderCompletedActions as $action) {
             $action = (array) $action;
             $action['_type'] = 'order-completed-action';
             $action = (object) $action;
             array_push($ae_actions, $action);
         }
     }
     usort($ae_actions, array('NelioABAltExpGoal', 'sort_goals'));
     foreach ($ae_actions as $action) {
         /** @var object $action */
         switch ($action->_type) {
             case 'page-accessed-action':
                 $result->add_action(NelioABPageAccessedAction::decode_from_appengine($action));
                 break;
             case 'form-action':
                 $result->add_action(NelioABFormSubmissionAction::decode_from_appengine($action));
                 break;
             case 'click-element-action':
                 $result->add_action(NelioABClickElementAction::decode_from_appengine($action));
                 break;
             case 'order-completed-action':
                 $result->add_action(NelioABWooCommerceOrderCompletedAction::decode_from_appengine($action));
                 break;
         }
     }
     return $result;
 }
Пример #4
0
 /**
  * Returns a new action object built using the information described in $action.
  *
  * The particular type of the resulting action will depend on
  * `$action->type`. Note this class is abstract and there are
  * several concrete classes extending this one.
  *
  * @param object $json a JSON action as used in the admin pages of our plugin.
  *
  * @return boolean|NelioABAction the new action containing all the information in `$action`.
  *
  * @since PHPDOC
  */
 public static function build_action_using_json4js($json)
 {
     require_once NELIOAB_MODELS_DIR . '/goals/actions/page-accessed-action.php';
     require_once NELIOAB_MODELS_DIR . '/goals/actions/form-submission-action.php';
     require_once NELIOAB_MODELS_DIR . '/goals/actions/click-element-action.php';
     require_once NELIOAB_MODELS_DIR . '/goals/actions/wc-order-completed-action.php';
     switch ($json->type) {
         case self::PAGE_ACCESSED:
         case self::POST_ACCESSED:
         case self::EXTERNAL_PAGE_ACCESSED:
             return NelioABPageAccessedAction::build_action_using_json4js($json);
         case self::FORM_SUBMIT:
             return NelioABFormSubmissionAction::build_action_using_json4js($json);
         case self::CLICK_ELEMENT:
             return NelioABClickElementAction::build_action_using_json4js($json);
         case self::WC_ORDER_COMPLETED:
             return NelioABWooCommerceOrderCompletedAction::build_action_using_json4js($json);
         default:
             return false;
     }
 }