Esempio n. 1
0
 public static function import_xml($xmlstr, &$forms = null)
 {
     require_once 'xml.php';
     $options = array('page' => array('unserialize_as_array' => true), 'form' => array('unserialize_as_array' => true), 'field' => array('unserialize_as_array' => true), 'rule' => array('unserialize_as_array' => true), 'choice' => array('unserialize_as_array' => true), 'input' => array('unserialize_as_array' => true), 'routing_item' => array('unserialize_as_array' => true), 'creditCard' => array('unserialize_as_array' => true), 'routin' => array('unserialize_as_array' => true), 'confirmation' => array('unserialize_as_array' => true), 'notification' => array('unserialize_as_array' => true));
     $options = apply_filters('gform_import_form_xml_options', $options);
     $xml = new RGXML($options);
     $forms = $xml->unserialize($xmlstr);
     if (!$forms) {
         return 0;
     } else {
         if (version_compare($forms['version'], self::$min_import_version, '<')) {
             return -1;
         }
     }
     //Error. XML version is not compatible with current Gravity Forms version
     //cleaning up generated object
     self::cleanup($forms);
     foreach ($forms as $key => &$form) {
         $title = $form['title'];
         $count = 2;
         while (!RGFormsModel::is_unique_title($title)) {
             $title = $form['title'] . "({$count})";
             $count++;
         }
         //inserting form
         $form_id = RGFormsModel::insert_form($title);
         //updating form meta
         $form['title'] = $title;
         $form['id'] = $form_id;
         $form = GFFormsModel::trim_form_meta_values($form);
         if (isset($form['confirmations'])) {
             $form['confirmations'] = self::set_property_as_key($form['confirmations'], 'id');
             $form['confirmations'] = GFFormsModel::trim_conditional_logic_values($form['confirmations'], $form);
             GFFormsModel::update_form_meta($form_id, $form['confirmations'], 'confirmations');
             unset($form['confirmations']);
         }
         if (isset($form['notifications'])) {
             $form['notifications'] = self::set_property_as_key($form['notifications'], 'id');
             $form['notifications'] = GFFormsModel::trim_conditional_logic_values($form['notifications'], $form);
             GFFormsModel::update_form_meta($form_id, $form['notifications'], 'notifications');
             unset($form['notifications']);
         }
         RGFormsModel::update_form_meta($form_id, $form);
     }
     return sizeof($forms);
 }
Esempio n. 2
0
 public static function import_file($filepath)
 {
     $xmlstr = file_get_contents($filepath);
     require_once "xml.php";
     $options = array("page" => array("unserialize_as_array" => true), "form" => array("unserialize_as_array" => true), "field" => array("unserialize_as_array" => true), "rule" => array("unserialize_as_array" => true), "choice" => array("unserialize_as_array" => true), "input" => array("unserialize_as_array" => true), "routing_item" => array("unserialize_as_array" => true), "routin" => array("unserialize_as_array" => true));
     $xml = new RGXML($options);
     $forms = $xml->unserialize($xmlstr);
     if (!$forms) {
         return 0;
     } else {
         if (version_compare($forms["version"], self::$min_import_version, "<")) {
             return -1;
         }
     }
     //Error. XML version is not compatible with current Gravity Forms version
     //cleaning up generated object
     self::cleanup($forms);
     foreach ($forms as $key => $form) {
         $title = $form["title"];
         $count = 2;
         while (!RGFormsModel::is_unique_title($title)) {
             $title = $form["title"] . "({$count})";
             $count++;
         }
         //inserting form
         $form_id = RGFormsModel::insert_form($title);
         //updating form meta
         $form["title"] = $title;
         $form["id"] = $form_id;
         RGFormsModel::update_form_meta($form_id, $form);
     }
     return sizeof($forms);
 }
Esempio n. 3
0
 /**
  * Get the the form fields for a preset (no form created yet)
  * @param  string $template_id Preset template
  *
  */
 static function pre_get_form_fields($template_id = '')
 {
     if (empty($template_id)) {
         return false;
     } else {
         $form_file = apply_filters('gravityview_template_formxml', '', $template_id);
         if (!file_exists($form_file)) {
             do_action('gravityview_log_error', '[pre_get_available_fields] Importing Form Fields for preset [' . $template_id . ']. File not found. file: ' . $form_file);
             return false;
         }
     }
     // Load xml parser (from GravityForms)
     $xml_parser = trailingslashit(WP_PLUGIN_DIR) . 'gravityforms/xml.php';
     if (file_exists($xml_parser)) {
         require_once $xml_parser;
     }
     // load file
     $xmlstr = file_get_contents($form_file);
     $options = array("page" => array("unserialize_as_array" => true), "form" => array("unserialize_as_array" => true), "field" => array("unserialize_as_array" => true), "rule" => array("unserialize_as_array" => true), "choice" => array("unserialize_as_array" => true), "input" => array("unserialize_as_array" => true), "routing_item" => array("unserialize_as_array" => true), "creditCard" => array("unserialize_as_array" => true), "routin" => array("unserialize_as_array" => true), "confirmation" => array("unserialize_as_array" => true), "notification" => array("unserialize_as_array" => true));
     $xml = new RGXML($options);
     $forms = $xml->unserialize($xmlstr);
     if (!$forms) {
         do_action('gravityview_log_error', '[pre_get_available_fields] Importing Form Fields for preset [' . $template_id . ']. Error importing file. (File)', $form_file);
         return false;
     }
     if (!empty($forms[0]) && is_array($forms[0])) {
         $form = $forms[0];
     }
     if (empty($form)) {
         do_action('gravityview_log_error', '[pre_get_available_fields] $form not set.', $forms);
         return false;
     }
     do_action('gravityview_log_debug', '[pre_get_available_fields] Importing Form Fields for preset [' . $template_id . ']. (Form)', $form);
     return $form;
 }
 public static function import_file($filepath, &$forms = null)
 {
     $xmlstr = file_get_contents($filepath);
     require_once "xml.php";
     $options = array("page" => array("unserialize_as_array" => true), "form" => array("unserialize_as_array" => true), "field" => array("unserialize_as_array" => true), "rule" => array("unserialize_as_array" => true), "choice" => array("unserialize_as_array" => true), "input" => array("unserialize_as_array" => true), "routing_item" => array("unserialize_as_array" => true), "creditCard" => array("unserialize_as_array" => true), "routin" => array("unserialize_as_array" => true), "confirmation" => array("unserialize_as_array" => true), "notification" => array("unserialize_as_array" => true));
     $options = apply_filters('gform_import_form_xml_options', $options);
     $xml = new RGXML($options);
     $forms = $xml->unserialize($xmlstr);
     if (!$forms) {
         return 0;
     } else {
         if (version_compare($forms["version"], self::$min_import_version, "<")) {
             return -1;
         }
     }
     //Error. XML version is not compatible with current Gravity Forms version
     //cleaning up generated object
     self::cleanup($forms);
     foreach ($forms as $key => &$form) {
         $title = $form["title"];
         $count = 2;
         while (!RGFormsModel::is_unique_title($title)) {
             $title = $form["title"] . "({$count})";
             $count++;
         }
         //inserting form
         $form_id = RGFormsModel::insert_form($title);
         //updating form meta
         $form["title"] = $title;
         $form["id"] = $form_id;
         $form = GFFormsModel::trim_form_meta_values($form);
         if (isset($form['confirmations'])) {
             $form['confirmations'] = self::set_property_as_key($form['confirmations'], 'id');
             $form['confirmations'] = GFFormsModel::trim_conditional_logic_values($form['confirmations'], $form);
             GFFormsModel::update_form_meta($form_id, $form['confirmations'], 'confirmations');
             unset($form['confirmations']);
         }
         if (isset($form['notifications'])) {
             $form['notifications'] = self::set_property_as_key($form['notifications'], 'id');
             $form['notifications'] = GFFormsModel::trim_conditional_logic_values($form['notifications'], $form);
             GFFormsModel::update_form_meta($form_id, $form['notifications'], 'notifications');
             unset($form['notifications']);
         }
         RGFormsModel::update_form_meta($form_id, $form);
     }
     return sizeof($forms);
 }
Esempio n. 5
0
 private static function get_account_info()
 {
     require_once self::get_base_path() . "/xml.php";
     $api = self::get_api();
     $response = $api->request("{$api->base_path}");
     if ($response->IsError) {
         return false;
     }
     $options = array("OutgoingCallerId" => array("unserialize_as_array" => true));
     $xml = new RGXML($options);
     $response_object = $xml->unserialize($response->ResponseText);
     $is_trial = strtolower($response_object["Account"]["Type"]) == "trial";
     $incoming_numbers = array();
     $outgoing_numbers = array();
     if ($is_trial) {
         //Getting Sandbox phone number
         $response = $api->request("{$api->base_path}/Sandbox");
         if ($response->IsError) {
             return false;
         }
         $response_object = $xml->unserialize($response->ResponseText);
         $incoming_numbers[] = $response_object["TwilioSandbox"]["PhoneNumber"];
         //Getting validated outgoing phone numbers
         $response = $api->request("{$api->base_path}/OutgoingCallerIds");
         if ($response->IsError) {
             return false;
         }
         $response_object = $xml->unserialize($response->ResponseText);
         foreach ($response_object["OutgoingCallerIds"] as $caller_id) {
             if (is_array($caller_id) && isset($caller_id["PhoneNumber"])) {
                 $outgoing_numbers[] = $caller_id["PhoneNumber"];
             }
         }
     } else {
         //Getting incoming phone numbers
         $response = $api->request("{$api->base_path}/IncomingPhoneNumbers");
         if ($response->IsError) {
             return false;
         }
         $response_object = $xml->unserialize($response->ResponseText);
         foreach ($response_object["IncomingPhoneNumbers"] as $number) {
             if (is_array($number) && isset($number["PhoneNumber"])) {
                 $incoming_numbers[] = $number["PhoneNumber"];
             }
         }
     }
     return array("is_sandbox" => $is_trial, "incoming_numbers" => $incoming_numbers, "outgoing_numbers" => $outgoing_numbers);
 }