Esempio n. 1
0
 function output($section_name, $config, $op, $return = false)
 {
     $disable = $this->_get_disabled($config);
     if (is_array($section_name[0]) && count($section_name) > 1) {
         $tmp = $section_name;
         $section_name = $section_name[0];
         for ($i = 1, $sl = count($tmp); $i < $sl; $i++) {
             array_push($section_name, $tmp[$i]);
         }
     }
     $data = $used_fields = array();
     if (isset($op['form_html'])) {
         $fh = $op['form_html'];
         $data['before_form'] = op_get_var($config, 'before_form');
         $data['after_form'] = op_get_var($config, 'after_form');
         $data['extra_fields'] = array();
         $form_class = '';
         $disable_name = op_get_var($fh, 'disable_name', 'N') == 'Y';
         $js_defaults = array();
         $fields = array('email');
         if (!$disable_name) {
             array_unshift($fields, 'name');
         }
         switch (op_get_var($fh, 'integration_type')) {
             case 'email':
                 $email_address = op_get_var($fh, 'email_address');
                 $redirect_url = op_get_var($fh, 'redirect_url');
                 if (!isset($disable['content']) && isset($op['content'])) {
                     foreach ($fields as $field) {
                         if (isset($op['content'][$field . '_default']) && !empty($op['content'][$field . '_default'])) {
                             $js_defaults[$field] = $op['content'][$field . '_default'];
                         }
                     }
                     if (count($js_defaults) > 0) {
                         $count = count($this->output_defaults);
                         $this->output_defaults[++$count] = $js_defaults;
                         $form_class = 'op-signup-form-' . $count;
                     }
                 }
                 $new_fields = array();
                 foreach ($fields as $field) {
                     $data[$field . '_input'] = '<input type="text" name="' . $field . '" placeholder="' . op_attr(op_get_var($js_defaults, $field)) . '" class="' . $field . '" />';
                     $new_fields[$field] = array('name' => $field, 'text' => op_get_var($js_defaults, $field));
                 }
                 $extra_fields = op_get_var($fh, 'email_extra_fields', array());
                 $new_extra = array();
                 if (is_array($extra_fields)) {
                     $counter = 1;
                     foreach ($extra_fields as $field) {
                         $new_extra['op_extra_' . $counter] = $field;
                         $data['extra_fields'][] = '<input type="text" name="op_extra_' . $counter . '" placeholder="' . op_attr($field) . '" />';
                         $counter++;
                     }
                 }
                 $data['form_open'] = '<form action="' . op_current_url() . '" method="post"' . ($form_class == '' ? '' : ' class="' . $form_class . '"') . '>';
                 $data['form_close'] = '</form>';
                 $hidden = array('email_to' => $email_address, 'redirect_url' => $redirect_url, 'extra_fields' => $new_extra, 'fields' => $new_fields);
                 $data['hidden_elems'] = '<input type="hidden" name="op_optin_form_data" value="' . op_attr(base64_encode(serialize($hidden))) . '" /><input type="hidden" name="op_optin_form" value="Y" />';
                 break;
             case 'custom':
             case 'oneshoppingcart':
                 $action = site_url('/process-optin-form/');
                 if ($action != '') {
                     if (!isset($disable['content']) && isset($op['content'])) {
                         foreach ($fields as $field) {
                             if (isset($op['content'][$field . '_default']) && !empty($op['content'][$field . '_default'])) {
                                 $js_defaults[$field] = $op['content'][$field . '_default'];
                             }
                         }
                         if (count($js_defaults) > 0) {
                             $count = count($this->output_defaults);
                             $this->output_defaults[++$count] = $js_defaults;
                             $form_class = 'op-signup-form-' . $count;
                         }
                     }
                     $data['form_open'] = '<form action="' . esc_url($action) . '" method="' . op_get_var($fh, 'method', 'post') . '"' . ($form_class == '' ? '' : ' class="' . $form_class . '"') . (op_get_var($fh, 'new_window', 'N') == 'Y' ? ' target="_blank"' : '') . '>';
                     $data['form_close'] = '</form>';
                     foreach ($fields as $field) {
                         $fieldname = '';
                         if (isset($fh[$field . '_box']) && !empty($fh[$field . '_box'])) {
                             $used_fields[$fh[$field . '_box']] = true;
                             $fieldname = $fh[$field . '_box'];
                         }
                         $data[$field . '_input'] = '<input type="text" name="' . op_attr($fieldname) . '" value="' . getOptinUrlValue($fieldname) . '" placeholder="' . op_attr(op_get_var($js_defaults, $field)) . '" class="' . $field . '" />';
                     }
                     $extra_fields = op_get_var($fh, 'extra_fields', array());
                     $field_names = op_get_var($extra_fields, 'field_name', array());
                     $field_titles = op_get_var($extra_fields, 'title', array());
                     $field_text = op_get_var($extra_fields, 'text', array());
                     for ($i = 0, $il = count($field_names); $i < $il; $i++) {
                         $fieldname = $field_names[$i];
                         if ($field_names[$i] == '' || $field_names[$i] == 'op_add_new_field') {
                             $fieldname = $field_titles[$i];
                         }
                         $data['extra_fields'][] = '<input type="text" name="' . op_attr($fieldname) . '" value="' . getOptinUrlValue($fieldname) . '" placeholder="' . op_attr($field_text[$i]) . '" />';
                         $used_fields[$fieldname] = true;
                     }
                     $hidden_elems = '';
                     if (isset($fh['fields']) && isset($fh['fields']['field_name']) && isset($fh['fields']['field_vals'])) {
                         $field_names = $fh['fields']['field_name'];
                         $field_vals = $fh['fields']['field_vals'];
                         $field_count = count($field_names);
                         if (is_array($field_names) && is_array($field_vals) && $field_count == count($field_vals)) {
                             for ($i = 0; $i < $field_count; $i++) {
                                 if (!isset($used_fields[$field_names[$i]])) {
                                     $hidden_elems .= '<input type="hidden" name="' . op_attr($field_names[$i]) . '" value="' . op_attr($field_vals[$i]) . '" />';
                                 }
                             }
                         }
                     }
                     $data['hidden_elems'] = $hidden_elems;
                     $data['hidden_elems'] .= '<input type="hidden" name="redirect_url" value="' . op_get_var($fh, 'action') . '" />';
                 }
                 break;
             case 'infusionsoft':
                 $action = op_get_var($fh, 'action_page');
                 if (!isset($disable['content']) && isset($op['content'])) {
                     foreach ($fields as $field) {
                         if (isset($op['content'][$field . '_default']) && !empty($op['content'][$field . '_default'])) {
                             $js_defaults[$field] = $op['content'][$field . '_default'];
                         }
                     }
                     if (count($js_defaults) > 0) {
                         $count = count($this->output_defaults);
                         $this->output_defaults[++$count] = $js_defaults;
                         $form_class = 'op-signup-form-' . $count;
                     }
                 }
                 $data['form_open'] = '<form action="' . esc_url($action) . '" method="POST"' . ($form_class == '' ? '' : ' class="' . $form_class . '"') . '>';
                 $data['form_close'] = '</form>';
                 /*
                  * Hardcoding the email field name
                  */
                 $fh['email_box'] = 'inf_field_Email';
                 foreach ($fields as $field) {
                     $fieldname = '';
                     if (isset($fh[$field . '_box']) && !empty($fh[$field . '_box'])) {
                         $used_fields[$fh[$field . '_box']] = true;
                         $fieldname = $fh[$field . '_box'];
                     }
                     $data[$field . '_input'] = '<input type="text" name="' . op_attr($fieldname) . '" value="' . getOptinUrlValue($fieldname) . '" placeholder="' . op_attr(op_get_var($js_defaults, $field)) . '" class="' . $field . '" />';
                 }
                 $extra_fields = op_get_var($fh, 'extra_fields', array());
                 $field_names = op_get_var($extra_fields, 'field_name', array());
                 $field_titles = op_get_var($extra_fields, 'title', array());
                 $field_text = op_get_var($extra_fields, 'text', array());
                 for ($i = 0, $il = count($field_names); $i < $il; $i++) {
                     $fieldname = $field_names[$i];
                     if ($field_names[$i] == '' || $field_names[$i] == 'op_add_new_field') {
                         $fieldname = $field_titles[$i];
                     }
                     $data['extra_fields'][] = '<input type="text" name="' . op_attr($fieldname) . '" value="' . getOptinUrlValue($fieldname) . '" placeholder="' . op_attr($field_text[$i]) . '" />';
                     $used_fields[$fieldname] = true;
                 }
                 $hidden_elems = '';
                 if (isset($fh['fields']) && isset($fh['fields']['field_name']) && isset($fh['fields']['field_vals'])) {
                     $field_names = $fh['fields']['field_name'];
                     $field_vals = $fh['fields']['field_vals'];
                     $field_count = count($field_names);
                     if (is_array($field_names) && is_array($field_vals) && $field_count == count($field_vals)) {
                         for ($i = 0; $i < $field_count; $i++) {
                             if (!isset($used_fields[$field_names[$i]])) {
                                 $hidden_elems .= '<input type="hidden" name="' . op_attr($field_names[$i]) . '" value="' . op_attr($field_vals[$i]) . '" />';
                             }
                         }
                     }
                 }
                 $data['hidden_elems'] = $hidden_elems;
                 $data['hidden_elems'] .= '<input type="hidden" name="provider" value="' . op_get_var($fh, 'integration_type') . '" />';
                 $data['hidden_elems'] .= '<input type="hidden" name="redirect_url" value="' . op_get_var($fh, 'thank_you_page', op_current_url()) . '" />';
                 $data['hidden_elems'] .= '<input type="hidden" name="list" value="' . op_get_var($fh, 'list') . '" />';
                 break;
             case 'aweber':
             case 'mailchimp':
             case 'icontact':
             case 'getresponse':
             case 'campaignmonitor':
             case 'officeautopilot':
                 $action = site_url('/process-optin-form/');
                 if (!isset($disable['content']) && isset($op['content'])) {
                     foreach ($fields as $field) {
                         if (isset($op['content'][$field . '_default']) && !empty($op['content'][$field . '_default'])) {
                             $js_defaults[$field] = $op['content'][$field . '_default'];
                         }
                     }
                     if (count($js_defaults) > 0) {
                         $count = count($this->output_defaults);
                         $this->output_defaults[++$count] = $js_defaults;
                         $form_class = 'op-signup-form-' . $count;
                     }
                 }
                 $data['form_open'] = '<form action="' . esc_url($action) . '" method="POST"' . ($form_class == '' ? '' : ' class="' . $form_class . '"') . '>';
                 $data['form_close'] = '</form>';
                 /*
                  * Hardcoding the email field name
                  */
                 $fh['email_box'] = 'email';
                 foreach ($fields as $field) {
                     $fieldname = '';
                     if (isset($fh[$field . '_box']) && !empty($fh[$field . '_box'])) {
                         $used_fields[$fh[$field . '_box']] = true;
                         $fieldname = $fh[$field . '_box'];
                     }
                     $data[$field . '_input'] = '<input type="text" name="' . op_attr($fieldname) . '" value="' . getOptinUrlValue($fieldname) . '" placeholder="' . op_attr(op_get_var($js_defaults, $field)) . '" class="' . $field . '" />';
                 }
                 $extra_fields = op_get_var($fh, 'extra_fields', array());
                 $field_names = op_get_var($extra_fields, 'field_name', array());
                 $field_titles = op_get_var($extra_fields, 'title', array());
                 $field_text = op_get_var($extra_fields, 'text', array());
                 for ($i = 0, $il = count($field_names); $i < $il; $i++) {
                     $fieldname = $field_names[$i];
                     if ($field_names[$i] == '' || $field_names[$i] == 'op_add_new_field') {
                         $fieldname = $field_titles[$i];
                     }
                     $data['extra_fields'][] = '<input type="text" name="' . op_attr($fieldname) . '" value="' . getOptinUrlValue($fieldname) . '" placeholder="' . op_attr($field_text[$i]) . '" />';
                     $used_fields[$fieldname] = true;
                 }
                 $data['hidden_elems'] = $hidden_elems;
                 $data['hidden_elems'] = '<input type="hidden" name="provider" value="' . op_get_var($fh, 'integration_type') . '" />';
                 $data['hidden_elems'] .= '<input type="hidden" name="redirect_url" value="' . op_get_var($fh, 'thank_you_page', op_current_url()) . '" />';
                 $data['hidden_elems'] .= '<input type="hidden" name="list" value="' . op_get_var($fh, 'list') . '" />';
                 break;
         }
         if (op_get_var($fh, 'gotowebinar')) {
             $data['hidden_elems'] .= '<input type="hidden" name="gotowebinar" value="' . op_get_var($fh, 'gotowebinar') . '" />';
         }
     }
     $tpl = '';
     $out = '';
     $data['content'] = array();
     if (!isset($disable['content'])) {
         $fields = $this->_get_fields($config);
         $data['content'] = op_mod('content_fields')->output(array($section_name, 'content'), array('fields' => $fields), op_get_var($op, 'content', array()));
     }
     $btnconf = op_get_var($config, 'submit_button_config', array());
     if (isset($op['submit_button'])) {
         $btnop = $op['submit_button'];
     } else {
         $btnop = array();
         if (!isset($btnconf['type'])) {
             $btnop['type'] = 0;
         }
         if (isset($btnconf['defaults']) && isset($btnconf['defaults']['content'])) {
             $btnop['content'] = $btnconf['defaults']['content'];
         }
     }
     if (is_array($btnop)) {
         $data['submit_button'] = op_mod('submit_button')->save_settings(array($section_name, 'submit_button'), $btnconf, $btnop, true);
     } else {
         $data['submit_button'] = $btnop;
     }
     if (!isset($disable['color_scheme'])) {
         $styles = $this->_get_color_schemes($section_name, $config);
         if (count($styles) > 0) {
             $tpl = 'output';
             $style = op_get_current_item($styles, op_get_var($op, 'color_scheme'));
             if (isset($styles[$style]['output'])) {
                 $tpl = $styles[$style]['output'];
             }
             $data['color_scheme'] = $style;
         }
     }
     if (isset($config['template'])) {
         $tpl = $config['template'];
     }
     if (!empty($tpl)) {
         $out = $this->load_tpl('output/' . $tpl, $data);
     }
     if (!empty($out)) {
         if ($return) {
             return $out;
         }
         echo $out;
         return true;
     } else {
         return $data;
     }
 }
Esempio n. 2
0
 /**
  * Checks GET vars for 'op_' prefixed parameters to fill the value or call 'op_optin_field_value' filter
  * @author Luka Peharda <*****@*****.**>
  * @param  string $name
  * @return string
  */
 function getOptinUrlValue($name)
 {
     $value = op_get('op_' . strtolower($name));
     if (false !== $value) {
         $value = op_attr($value);
     } else {
         if ('FNAME' == $name) {
             $value = getOptinUrlValue('name');
         } else {
             $value = apply_filters('op_optin_field_value', $value, $name);
         }
     }
     return $value;
 }
Esempio n. 3
0
 function output($section_name, $config, $op, $return = false)
 {
     $disable = $this->_get_disabled($config);
     if (is_array($section_name[0]) && count($section_name) > 1) {
         $tmp = $section_name;
         $section_name = $section_name[0];
         for ($i = 1, $sl = count($tmp); $i < $sl; $i++) {
             array_push($section_name, $tmp[$i]);
         }
     }
     $data = $used_fields = array();
     if (isset($op['form_html'])) {
         $order = array();
         $fh = $op['form_html'];
         $data['before_form'] = op_get_var($config, 'before_form');
         $data['after_form'] = op_get_var($config, 'after_form');
         $data['extra_fields'] = array();
         $form_class = '';
         $disable_name = op_get_var($fh, 'disable_name', 'N') == 'Y';
         $js_defaults = array();
         $fields = array('email');
         $order[op_get_var($fh, 'email_order', 0)][] = 'email_input';
         if (!$disable_name) {
             array_unshift($fields, 'name');
             $order[op_get_var($fh, 'name_order', 0)][] = 'name_input';
         }
         $required = 'required="required"';
         switch (op_get_var($fh, 'integration_type')) {
             case 'email':
                 $email_address = op_get_var($fh, 'email_address');
                 $redirect_url = op_get_var($fh, 'redirect_url');
                 if (!isset($disable['content']) && isset($op['content'])) {
                     foreach ($fields as $field) {
                         if (isset($op['content'][$field . '_default']) && !empty($op['content'][$field . '_default'])) {
                             $js_defaults[$field] = $op['content'][$field . '_default'];
                         }
                     }
                     if (count($js_defaults) > 0) {
                         $count = count($this->output_defaults);
                         $this->output_defaults[++$count] = $js_defaults;
                         $form_class = 'op-signup-form-' . $count;
                     }
                 }
                 $new_fields = array();
                 foreach ($fields as $field) {
                     if ($field == 'email') {
                         $data[$field . '_input'] = '<input type="email" required="required" name="' . $field . '" placeholder="' . op_attr(op_get_var($js_defaults, $field)) . '" class="' . $field . '" />';
                     } else {
                         $requiredField = '';
                         if (!isset($fh['name_required']) || op_get_var($fh, 'name_required') == 'Y') {
                             $requiredField = $required;
                         }
                         $data[$field . '_input'] = '<input type="text" ' . $requiredField . ' name="' . $field . '" placeholder="' . op_attr(op_get_var($js_defaults, $field)) . '" class="' . $field . '" />';
                     }
                     $new_fields[$field] = array('name' => $field, 'text' => op_get_var($js_defaults, $field));
                 }
                 $extra_fields = op_get_var($fh, 'email_extra_fields', array());
                 $extra_fields_order = op_get_var($fh, 'email_extra_fields_order', array());
                 $extra_fields_required = op_get_var($fh, 'email_extra_fields_required', array());
                 $new_extra = array();
                 if (is_array($extra_fields)) {
                     $counter = 1;
                     foreach ($extra_fields as $field) {
                         $new_extra['op_extra_' . $counter] = $field;
                         $requiredField = '';
                         if (isset($extra_fields_required[$counter - 1]) && $extra_fields_required[$counter - 1] == 'Y') {
                             $requiredField = $required;
                         }
                         $data['extra_fields']['op_extra_' . $counter] = '<input type="text" ' . $requiredField . ' name="op_extra_' . $counter . '" placeholder="' . op_attr($field) . '" />';
                         $field_order = $order[op_get_var($extra_fields_order, $counter - 1, 0)][] = 'op_extra_' . $counter;
                         $counter++;
                     }
                 }
                 $data['form_open'] = '<form action="' . op_current_url() . '" method="post" class="op-optin-validation ' . $form_class . '">';
                 $data['form_close'] = '</form>';
                 $hidden = array('email_to' => $email_address, 'redirect_url' => $redirect_url, 'extra_fields' => $new_extra, 'fields' => $new_fields);
                 $data['hidden_elems'] = '<input type="hidden" name="op_optin_form_data" value="' . op_attr(base64_encode(serialize($hidden))) . '" /><input type="hidden" name="op_optin_form" value="Y" />';
                 break;
             case 'custom':
             case 'oneshoppingcart':
                 if ('Y' === op_get_var($fh, 'gotowebinar_enabled', 'N')) {
                     $action = get_bloginfo('url') . '/process-optin-form/';
                 } else {
                     $action = op_get_var($fh, 'action');
                 }
                 if ($action != '') {
                     if (!isset($disable['content']) && isset($op['content'])) {
                         foreach ($fields as $field) {
                             if (isset($op['content'][$field . '_default']) && !empty($op['content'][$field . '_default'])) {
                                 $js_defaults[$field] = $op['content'][$field . '_default'];
                             }
                         }
                         if (count($js_defaults) > 0) {
                             $count = count($this->output_defaults);
                             $this->output_defaults[++$count] = $js_defaults;
                             $form_class = 'op-signup-form-' . $count;
                         }
                     }
                     $data['form_open'] = '<form action="' . $action . '" method="' . op_get_var($fh, 'method', 'post') . '" class="op-optin-validation ' . $form_class . '">';
                     $data['form_close'] = '</form>';
                     foreach ($fields as $field) {
                         $fieldname = '';
                         if (isset($fh[$field . '_box']) && !empty($fh[$field . '_box'])) {
                             $used_fields[$fh[$field . '_box']] = true;
                             $fieldname = $fh[$field . '_box'];
                         }
                         if ('email' == $field) {
                             $data[$field . '_input'] = '<input type="email" required="required" name="' . op_attr($fieldname) . '" value="' . getOptinUrlValue($fieldname) . '" placeholder="' . op_attr(op_get_var($js_defaults, $field)) . '" class="' . $field . '" />';
                         } else {
                             $requiredField = '';
                             if (!isset($fh['name_required']) || op_get_var($fh, 'name_required') == 'Y') {
                                 $requiredField = $required;
                             }
                             $data[$field . '_input'] = '<input type="text" ' . $requiredField . ' name="' . op_attr($fieldname) . '" value="' . getOptinUrlValue($fieldname) . '" placeholder="' . op_attr(op_get_var($js_defaults, $field)) . '" class="' . $field . '" />';
                         }
                     }
                     $extra_fields = op_get_var($fh, 'extra_fields', array());
                     $field_names = op_get_var($extra_fields, 'field_name', array());
                     $field_titles = op_get_var($extra_fields, 'title', array());
                     $field_text = op_get_var($extra_fields, 'text', array());
                     $field_order = op_get_var($extra_fields, 'order', array());
                     $field_required = op_get_var($extra_fields, 'required', array());
                     $field_hidden = op_get_var($extra_fields, 'hidden', array());
                     for ($i = 0, $il = count($field_names); $i < $il; $i++) {
                         $fieldname = $field_names[$i];
                         if ($field_names[$i] == '' || $field_names[$i] == 'op_add_new_field') {
                             $fieldname = $field_titles[$i];
                         }
                         if (isset($field_hidden[$i]) && $field_hidden[$i] == 'Y') {
                             $data['extra_fields'][$fieldname] = '<input type="hidden" name="' . op_attr($fieldname) . '" value="' . do_shortcode(stripslashes($field_text[$i])) . '" />';
                         } else {
                             $requiredField = '';
                             if (isset($field_required[$i]) && $field_required[$i] == 'Y') {
                                 $requiredField = $required;
                             }
                             $data['extra_fields'][$fieldname] = '<input type="text" ' . $requiredField . ' name="' . op_attr($fieldname) . '" value="' . getOptinUrlValue($fieldname) . '" placeholder="' . op_attr($field_text[$i]) . '" />';
                         }
                         $order[op_get_var($field_order, $i, 0)][] = $fieldname;
                         $used_fields[$fieldname] = true;
                     }
                     $hidden_elems = '';
                     if (isset($fh['fields']) && isset($fh['fields']['field_name']) && isset($fh['fields']['field_vals'])) {
                         $field_names = $fh['fields']['field_name'];
                         $field_vals = $fh['fields']['field_vals'];
                         $field_count = count($field_names);
                         if (is_array($field_names) && is_array($field_vals) && $field_count == count($field_vals)) {
                             for ($i = 0; $i < $field_count; $i++) {
                                 if (!isset($used_fields[$field_names[$i]])) {
                                     $hidden_elems .= '<input type="hidden" name="' . op_attr($field_names[$i]) . '" value="' . op_attr($field_vals[$i]) . '" />';
                                 }
                             }
                         }
                     }
                     $data['hidden_elems'] = $hidden_elems;
                     $data['hidden_elems'] .= '<input type="hidden" name="redirect_url" value="' . op_get_var($fh, 'action') . '" />';
                 }
                 break;
             case 'infusionsoft':
                 if (op_get_var($fh, 'gotowebinar')) {
                     $action = get_bloginfo('url') . '/process-optin-form/';
                 } else {
                     $action = op_get_var($fh, 'action_page');
                 }
                 if (!isset($disable['content']) && isset($op['content'])) {
                     foreach ($fields as $field) {
                         if (isset($op['content'][$field . '_default']) && !empty($op['content'][$field . '_default'])) {
                             $js_defaults[$field] = $op['content'][$field . '_default'];
                         }
                     }
                     if (count($js_defaults) > 0) {
                         $count = count($this->output_defaults);
                         $this->output_defaults[++$count] = $js_defaults;
                         $form_class = 'op-signup-form-' . $count;
                     }
                 }
                 $data['form_open'] = '<form action="' . esc_url($action) . '" method="POST" class="op-optin-validation ' . $form_class . '">';
                 $data['form_close'] = '</form>';
                 /*
                  * Hardcoding the email field name
                  */
                 $fh['email_box'] = 'inf_field_Email';
                 foreach ($fields as $field) {
                     $fieldname = '';
                     if (isset($fh[$field . '_box']) && !empty($fh[$field . '_box'])) {
                         $used_fields[$fh[$field . '_box']] = true;
                         $fieldname = $fh[$field . '_box'];
                     }
                     if ('email' == $field) {
                         $data[$field . '_input'] = '<input type="email" required="required" name="' . op_attr($fieldname) . '" value="' . getOptinUrlValue($fieldname) . '" placeholder="' . op_attr(op_get_var($js_defaults, $field)) . '" class="' . $field . '" />';
                     } else {
                         $requiredField = '';
                         if (!isset($fh['name_required']) || op_get_var($fh, 'name_required') == 'Y') {
                             $requiredField = $required;
                         }
                         $data[$field . '_input'] = '<input type="text" ' . $requiredField . ' name="' . op_attr($fieldname) . '" value="' . getOptinUrlValue($fieldname) . '" placeholder="' . op_attr(op_get_var($js_defaults, $field)) . '" class="' . $field . '" />';
                     }
                 }
                 $extra_fields = op_get_var($fh, 'extra_fields', array());
                 $field_names = op_get_var($extra_fields, 'field_name', array());
                 $field_titles = op_get_var($extra_fields, 'title', array());
                 $field_text = op_get_var($extra_fields, 'text', array());
                 $field_order = op_get_var($extra_fields, 'order', array());
                 $field_required = op_get_var($extra_fields, 'required', array());
                 $field_hidden = op_get_var($extra_fields, 'hidden', array());
                 for ($i = 0, $il = count($field_names); $i < $il; $i++) {
                     $fieldname = $field_names[$i];
                     if ($field_names[$i] == '' || $field_names[$i] == 'op_add_new_field') {
                         $fieldname = $field_titles[$i];
                     }
                     if (isset($field_hidden[$i]) && $field_hidden[$i] == 'Y') {
                         $data['extra_fields'][$fieldname] = '<input type="hidden" name="' . op_attr($fieldname) . '" value="' . do_shortcode(stripslashes($field_text[$i])) . '" />';
                     } else {
                         $requiredField = '';
                         if (isset($field_required[$i]) && $field_required[$i] == 'Y') {
                             $requiredField = $required;
                         }
                         $data['extra_fields'][$fieldname] = '<input type="text" ' . $requiredField . ' name="' . op_attr($fieldname) . '" value="' . getOptinUrlValue($fieldname) . '" placeholder="' . op_attr($field_text[$i]) . '" />';
                     }
                     $order[op_get_var($field_order, $i, 0)][] = $fieldname;
                     $used_fields[$fieldname] = true;
                 }
                 $hidden_elems = '';
                 $infusionSoftHiddenFields = op_assets_provider_item_fields('infusionsoft', op_get_var($fh, 'list'));
                 foreach ($infusionSoftHiddenFields['hidden'] as $infusionFieldName => $infusionFieldValue) {
                     $hidden_elems .= '<input type="hidden" name="' . $infusionFieldName . '" value="' . $infusionFieldValue . '" />';
                 }
                 $thankYouPage = op_get_var($fh, 'thank_you_page');
                 $thankYouPage = empty($thankYouPage) ? op_current_url() : $thankYouPage;
                 $alreadySubscribed = op_get_var($fh, 'already_subscribed_url');
                 $data['hidden_elems'] = $hidden_elems;
                 $data['hidden_elems'] .= '<input type="hidden" name="provider" value="' . op_get_var($fh, 'integration_type') . '" />';
                 $data['hidden_elems'] .= '<input type="hidden" name="redirect_url" value="' . $thankYouPage . '" />';
                 $data['hidden_elems'] .= '<input type="hidden" name="already_subscribed_url" value="' . $alreadySubscribed . '" />';
                 $data['hidden_elems'] .= '<input type="hidden" name="list" value="' . op_get_var($fh, 'list') . '" />';
                 break;
             case 'arpreach':
             case 'aweber':
             case 'mailchimp':
             case 'mailpoet':
             case 'icontact':
             case 'getresponse':
             case 'campaignmonitor':
             case 'constantcontact':
             case 'convertkit':
             case 'activecampaign':
             case 'officeautopilot':
             case 'ontraport':
             case 'emma':
             case 'egoi':
             case 'maropost':
                 $action = get_bloginfo('url') . '/process-optin-form/';
                 if (!isset($disable['content']) && isset($op['content'])) {
                     foreach ($fields as $field) {
                         if (isset($op['content'][$field . '_default']) && !empty($op['content'][$field . '_default'])) {
                             $js_defaults[$field] = $op['content'][$field . '_default'];
                         }
                     }
                     if (count($js_defaults) > 0) {
                         $count = count($this->output_defaults);
                         $this->output_defaults[++$count] = $js_defaults;
                         $form_class = 'op-signup-form-' . $count;
                     }
                 }
                 $data['form_open'] = '<form action="' . esc_url($action) . '" method="POST" class="op-optin-validation ' . $form_class . '">';
                 $data['form_close'] = '</form>';
                 /*
                  * Hardcoding the email field name
                  */
                 $fh['email_box'] = 'email';
                 foreach ($fields as $field) {
                     $fieldname = '';
                     if (isset($fh[$field . '_box']) && !empty($fh[$field . '_box'])) {
                         $used_fields[$fh[$field . '_box']] = true;
                         $fieldname = $fh[$field . '_box'];
                     }
                     if ('email' == $field) {
                         $data[$field . '_input'] = '<input type="email" required="required" name="' . op_attr($fieldname) . '" value="' . getOptinUrlValue($fieldname) . '" placeholder="' . op_attr(op_get_var($js_defaults, $field)) . '" class="' . $field . '" />';
                     } else {
                         $requiredField = '';
                         if (!isset($fh['name_required']) || op_get_var($fh, 'name_required') == 'Y') {
                             $requiredField = $required;
                         }
                         $data[$field . '_input'] = '<input type="text" ' . $requiredField . ' name="' . op_attr($fieldname) . '" value="' . getOptinUrlValue($fieldname) . '" placeholder="' . op_attr(op_get_var($js_defaults, $field)) . '" class="' . $field . '" />';
                     }
                 }
                 $extra_fields = op_get_var($fh, 'extra_fields', array());
                 $field_names = op_get_var($extra_fields, 'field_name', array());
                 $field_titles = op_get_var($extra_fields, 'title', array());
                 $field_text = op_get_var($extra_fields, 'text', array());
                 $field_order = op_get_var($extra_fields, 'order', array());
                 $field_required = op_get_var($extra_fields, 'required', array());
                 $field_hidden = op_get_var($extra_fields, 'hidden', array());
                 for ($i = 0, $il = count($field_names); $i < $il; $i++) {
                     $fieldname = $field_names[$i];
                     if ($field_names[$i] == '' || $field_names[$i] == 'op_add_new_field') {
                         $fieldname = $field_titles[$i];
                     }
                     if (isset($field_hidden[$i]) && $field_hidden[$i] == 'Y') {
                         $data['extra_fields'][$fieldname] = '<input type="hidden" name="' . op_attr($fieldname) . '" value="' . do_shortcode(stripslashes($field_text[$i])) . '" />';
                     } else {
                         $requiredField = '';
                         if (isset($field_required[$i]) && $field_required[$i] == 'Y') {
                             $requiredField = $required;
                         }
                         $data['extra_fields'][$fieldname] = '<input type="text" ' . $requiredField . ' name="' . op_attr($fieldname) . '" value="' . getOptinUrlValue($fieldname) . '" placeholder="' . op_attr($field_text[$i]) . '" />';
                     }
                     $order[op_get_var($field_order, $i, 0)][] = $fieldname;
                     $used_fields[$fieldname] = true;
                 }
                 $thankYouPage = op_get_var($fh, 'thank_you_page');
                 $thankYouPage = empty($thankYouPage) ? op_current_url() : $thankYouPage;
                 $alreadySubscribed = op_get_var($fh, 'already_subscribed_url');
                 $list = op_get_var($fh, 'list');
                 $data['hidden_elems'] = '<input type="hidden" name="provider" value="' . op_get_var($fh, 'integration_type') . '" />';
                 $data['hidden_elems'] .= '<input type="hidden" name="redirect_url" value="' . $thankYouPage . '" />';
                 $data['hidden_elems'] .= '<input type="hidden" name="already_subscribed_url" value="' . $alreadySubscribed . '" />';
                 if (op_get_var($fh, 'integration_type') === 'mailchimp') {
                     $data['hidden_elems'] .= '<input type="hidden" name="double_optin" value="' . op_get_var($fh, 'double_optin') . '" />';
                     $data['hidden_elems'] .= '<input type="hidden" name="welcome_email" value="' . op_get_var($fh, 'welcome_email') . '" />';
                 }
                 if (op_get_var($fh, 'integration_type') === 'emma') {
                     $data['hidden_elems'] .= '<input type="hidden" name="signup_form_id" value="' . op_get_var($fh, 'signup_form_id') . '" />';
                 }
                 /*
                  * In case that user selected arpReach as EMS we need to substitute list param with its "autoresponder_name" param
                  */
                 if (op_get_var($fh, 'integration_type') === 'arpreach') {
                     $list = op_get_var($fh, 'autoresponder_name');
                 }
                 $data['hidden_elems'] .= '<input type="hidden" name="list" value="' . $list . '" />';
                 break;
         }
         if (op_get_var($fh, 'gotowebinar') && 'Y' === op_get_var($fh, 'gotowebinar_enabled')) {
             $data['hidden_elems'] .= '<input type="hidden" name="gotowebinar" value="' . op_get_var($fh, 'gotowebinar') . '" />';
         }
         if (op_get_var($fh, 'opm_level') && 'Y' === op_get_var($fh, 'opm_integration')) {
             $data['hidden_elems'] .= '<input type="hidden" name="opm_level" value="' . op_get_var($fh, 'opm_level') . '" />';
         }
         if (op_get_var($fh, 'opm_packages') && 'Y' === op_get_var($fh, 'opm_integration')) {
             $data['hidden_elems'] .= '<input type="hidden" name="opm_packages" value="' . implode(',', op_get_var($fh, 'opm_packages')) . '" />';
         }
         $data['order'] = flatten_multidim_array($order, true);
     }
     $tpl = '';
     $out = '';
     $data['content'] = array();
     if (!isset($disable['content'])) {
         $fields = $this->_get_fields($config);
         $data['content'] = op_mod('content_fields')->output(array($section_name, 'content'), array('fields' => $fields), op_get_var($op, 'content', array()));
     }
     $btnconf = op_get_var($config, 'submit_button_config', array());
     if (isset($op['submit_button'])) {
         $btnop = $op['submit_button'];
     } else {
         $btnop = array();
         if (!isset($btnconf['type'])) {
             $btnop['type'] = 0;
         }
         if (isset($btnconf['defaults']) && isset($btnconf['defaults']['content'])) {
             $btnop['content'] = $btnconf['defaults']['content'];
         }
     }
     if (is_array($btnop)) {
         $data['submit_button'] = op_mod('submit_button')->save_settings(array($section_name, 'submit_button'), $btnconf, $btnop, true);
     } else {
         $data['submit_button'] = $btnop;
     }
     if (!isset($disable['color_scheme'])) {
         $styles = $this->_get_color_schemes($section_name, $config);
         if (count($styles) > 0) {
             $tpl = 'output';
             $style = op_get_current_item($styles, op_get_var($op, 'color_scheme'));
             if (isset($styles[$style]['output'])) {
                 $tpl = $styles[$style]['output'];
             }
             $data['color_scheme'] = $style;
         }
     }
     if (isset($config['template'])) {
         $tpl = $config['template'];
     }
     if (!empty($tpl)) {
         $out = $this->load_tpl('output/' . $tpl, $data);
     }
     /*
      * Loading validation script
      */
     op_validation_script();
     if (!empty($out)) {
         if ($return) {
             return $out;
         }
         echo $out;
         return true;
     } else {
         return $data;
     }
 }
Esempio n. 4
0
 static function optin_box($atts, $content = '')
 {
     /*
      * Cache busting
      */
     if (function_exists('wp_using_ext_object_cache')) {
         wp_using_ext_object_cache(false);
     }
     // Decode encoded chars
     $atts = op_urldecode($atts);
     $uidOpBox = 'optbox_' . md5(serialize($atts) . $content . (int) defined('OP_LIVEEDITOR'));
     if (false === ($cached = get_transient('el_' . $uidOpBox))) {
         $oldAtts = $atts;
         $atts = shortcode_atts(array('integration_type' => 'custom', 'email_address' => '', 'redirect_url' => '', 'style' => '1', 'action' => '', 'new_window' => 'N', 'disable_name' => 'N', 'method' => 'post', 'submit' => '', 'email_field' => '', 'email_default' => '', 'email_order' => 0, 'name_field' => '', 'name_default' => '', 'name_order' => 0, 'top_color' => '', 'thank_you_page' => '', 'action_page' => '', 'list' => '', 'width' => '', 'margin_top' => '', 'margin_right' => '', 'margin_bottom' => '', 'margin_left' => '', 'alignment' => 'center', 'button_below' => 'N', 'gotowebinar' => null, 'double_optin' => 'N'), $atts);
         extract($atts);
         $data = array('content' => array('headline' => '', 'paragraph' => '', 'privacy' => ''), 'fields' => array(), 'submit_button' => '', 'hidden_str' => '', 'extra_fields' => array(), 'top_color' => $top_color, 'width' => $width, 'margin_top' => $margin_top, 'margin_right' => $margin_right, 'margin_bottom' => $margin_bottom, 'margin_left' => $margin_left, 'box_alignment' => $alignment);
         $mc = preg_match_all('/' . op_shortcode_regex('optin_box_hidden|optin_box_field|optin_box_button') . '/s', $content, $matches);
         $buttons = 0;
         if ($mc > 0) {
             for ($i = 0; $i < $mc; $i++) {
                 switch ($matches[2][$i]) {
                     case 'optin_box_hidden':
                         $data['hidden_str'] .= op_clean_shortcode_content($matches[5][$i]);
                         break;
                     case 'optin_box_field':
                         $field = shortcode_atts(array('name' => ''), shortcode_parse_atts($matches[3][$i]));
                         if ($field['name'] != '') {
                             $data['content'][$field['name']] = op_clean_shortcode_content($matches[5][$i]);
                             if ($field['name'] == 'paragraph') {
                                 $data['content'][$field['name']] = wpautop(op_texturize(base64_decode($data['content'][$field['name']])));
                             }
                         }
                         break;
                     case 'optin_box_button':
                         $button_atts = shortcode_parse_atts($matches[3][$i]);
                         $button_atts['element_type'] = 'button';
                         $button_content = $matches[5][$i];
                         $type = op_get_var($button_atts, 'type', 1);
                         if ($type == '0') {
                             $uid = md5('btn_0_' . $button_content);
                             if (false === ($buttonMarkup = get_transient('el_' . $uid))) {
                                 $buttonMarkup = op_sl_parse('button_0', $button_content);
                                 /*
                                  * Save only when there is some content returned
                                  */
                                 if (is_string($buttonMarkup) && 0 === strpos($buttonMarkup, '##')) {
                                     $buttonMarkup = substr($buttonMarkup, 2);
                                 } elseif (!empty($buttonMarkup)) {
                                     set_transient('el_' . $uid, $buttonMarkup, OP_SL_ELEMENT_CACHE_LIFETIME);
                                 }
                             }
                             $data['submit_button'] = $buttonMarkup;
                         } else {
                             $func = 'button_' . $type;
                             $data['submit_button'] = call_user_func_array(array('OptimizePress_Default_Assets', $func), array($button_atts, $button_content));
                         }
                         /*
                          * Used on some templates as "textual link"
                          */
                         if (op_get_var($button_atts, 'button_below') === 'Y') {
                             $data['link_button'] = '<button type="submit" class="default-link">' . $button_content . '</button>';
                         } else {
                             $data['link_button'] = '';
                         }
                         break;
                 }
             }
         }
         $has_name = true;
         if ($integration_type == 'email') {
             $has_name = false;
         }
         if (!$has_name) {
             $atts['action'] = '%%redirect_url%%';
             $atts['method'] = 'post';
         }
         $atts['op_current_url'] = '%%redirect_url%%';
         $atts['data'] = $data;
         $atts['no_name_styles'] = array('1', '4', '5', '6', '9', '10');
         $atts['site_url_process_optin_form'] = get_bloginfo('url') . '/process-optin-form/';
         $atts['atts'] = $oldAtts;
         $atts['has_name'] = $has_name;
         $returnedData = op_sl_parse('optin_box', $atts);
         if (false === is_array($returnedData) && empty($returnedData)) {
             return;
         }
         extract($returnedData);
         if (!isset($required_fields)) {
             $required_fields = array();
         }
         $required = ' required="required"';
         /*
          * We need this check to remove required attribute (it was firing in feature box element)
          */
         if (defined('OP_LIVEEDITOR')) {
             $required = '';
         }
         $replacement_fields = array();
         foreach ($extra_fields as $name => $value) {
             $requiredField = in_array($name, $required_fields) ? $required : '';
             $data['extra_fields'][$name] = '<div class="text-box"><input type="text"' . $requiredField . ' name="' . $name . '" placeholder="' . $value . '" value="%%' . $name . '%%" /></div>';
             $replacement_fields[] = $name;
         }
         if (!$has_name) {
             $fields['email']['name'] = 'email';
             $has_name_field && ($fields['name']['name'] = 'name');
             $hidden = array('email_to' => $email_address, 'redirect_url' => $redirect_url, 'extra_fields' => $extra_fields, 'fields' => $fields);
             $data['hidden_str'] .= '<input type="hidden" name="op_optin_form_data" value="' . op_attr(base64_encode(serialize($hidden))) . '" /><input type="hidden" name="op_optin_form" value="Y" />';
         }
         $data['hidden_str'] = empty($data['hidden_str']) ? '' : '<div style="display:none">' . $data['hidden_str'] . '</div>';
         foreach ($fields as $name => $info) {
             $input_container_start_html = $style != 12 && $style != 15 && $style != 19 && $style != 20 && $style != 21 && $style != 22 && $style != 23 && $style != 24 ? '<div class="text-box ' . $name . '">' : '';
             $input_container_end_html = $style != 12 && $style != 15 && $style != 19 && $style != 20 && $style != 21 && $style != 22 && $style != 23 && $style != 24 ? '</div>' : '';
             $requiredField = in_array($name . '_field', $required_fields) ? $required : '';
             if ($name === 'email') {
                 $data['fields'][$name . '_field'] = $input_container_start_html . '<input type="email"' . $requiredField . ' name="' . $info['name'] . '"' . ($info['text'] == '' ? '' : ' placeholder="' . $info['text'] . '"') . ' value="%%' . $info['name'] . '%%" />' . $input_container_end_html;
             } else {
                 $data['fields'][$name . '_field'] = $input_container_start_html . '<input type="text"' . $requiredField . ' name="' . $info['name'] . '"' . ($info['text'] == '' ? '' : ' placeholder="' . $info['text'] . '"') . ' value="%%' . $info['name'] . '%%" />' . $input_container_end_html;
             }
             $replacement_fields[] = $info['name'];
         }
         if (!isset($data['extra_fields']) || !is_array($data['extra_fields'])) {
             $data['extra_fields'] = array();
         }
         if (isset($order)) {
             $data['order'] = $order;
         }
         _op_tpl('clear');
         $template = _op_tpl('_load_file', OP_ASSETS . 'tpls/optin_box/style_' . $style . '.php', $data, true);
         $cached = array('template' => $template, 'replacement_fields' => $replacement_fields);
         set_transient('el_' . $uidOpBox, $cached, OP_SL_ELEMENT_CACHE_LIFETIME);
     }
     /*
      * Loading validation script
      */
     op_validation_script();
     if (is_array($cached)) {
         $html = str_replace('%%redirect_url%%', op_current_url(), $cached['template']);
         foreach ($cached['replacement_fields'] as $field) {
             $html = str_replace('%%' . $field . '%%', getOptinUrlValue($field), $html);
         }
     } else {
         $html = str_replace('%%redirect_url%%', op_current_url(), $cached);
     }
     /*
      * Cache busting
      */
     if (function_exists('wp_using_ext_object_cache')) {
         wp_using_ext_object_cache(true);
     }
     return $html;
 }
Esempio n. 5
0
 /**
  * Checks GET vars for 'op_' prefixed parameters to fill the value
  * @author Luka Peharda <*****@*****.**>
  * @param  string $name
  * @return string
  */
 function getOptinUrlValue($name)
 {
     $value = op_get('op_' . strtolower($name));
     if (false !== $value) {
         $value = op_attr($value);
     } else {
         if ('FNAME' == $name) {
             $value = getOptinUrlValue('name');
         }
     }
     return $value;
 }