/**
  * @param int   $id
  * @param array $config
  * @param bool $echo
  *
  * @return string
  */
 public function output_form($id = 0, $config = array(), $echo = true)
 {
     try {
         $form = mc4wp_get_form($id);
     } catch (Exception $e) {
         if (current_user_can('manage_options')) {
             return sprintf('<strong>MailChimp for WordPress error:</strong> %s', $e->getMessage());
         }
         return '';
     }
     $this->count++;
     if (empty($config['element_id'])) {
         $config['element_id'] = 'mc4wp-form-' . $this->count;
     }
     $this->printed_forms[$form->ID] = $form;
     $this->printed_field_types += $form->get_field_types();
     $this->printed_field_types = array_unique($this->printed_field_types);
     $html = $form->get_html($config['element_id'], $config);
     /**
      * Runs just before a form element is outputted.
      *
      * @since 3.0
      *
      * @param MC4WP_Form $form
      */
     do_action('mc4wp_output_form', $form);
     if ($echo) {
         echo $html;
     }
     return $html;
 }
 /**
  * Listen for submitted forms
  *
  * @param $data
  * @return bool
  */
 public function listen(array $data)
 {
     if (!isset($data['_mc4wp_form_id'])) {
         return false;
     }
     /**
      * @var MC4WP_Request $request
      */
     $request = mc4wp('request');
     try {
         $form = mc4wp_get_form($request->params->get('_mc4wp_form_id'));
     } catch (Exception $e) {
         return false;
     }
     // where the magic happens
     $form->handle_request($request);
     $form->validate();
     // store submitted form
     $this->submitted_form = $form;
     // did form have errors?
     if (!$form->has_errors()) {
         // form was valid, do something
         $method = 'process_' . $form->get_action() . '_form';
         call_user_func(array($this, $method), $form);
     }
     $this->respond($form);
     return true;
 }
 /**
  * Listen for submitted forms
  *
  * @param MC4WP_Request $request
  * @return bool
  */
 public function listen(MC4WP_Request $request)
 {
     if (!$request->post->get('_mc4wp_form_id')) {
         return false;
     }
     try {
         $form = mc4wp_get_form($request->params->get('_mc4wp_form_id'));
     } catch (Exception $e) {
         return false;
     }
     // where the magic happens
     $form->handle_request($request);
     $form->validate();
     // store submitted form
     $this->submitted_form = $form;
     // did form have errors?
     if (!$form->has_errors()) {
         // form was valid, do something
         $method = 'process_' . $form->get_action() . '_form';
         call_user_func(array($this, $method), $form);
     } else {
         $this->get_log()->info(sprintf("Form %d > Submitted with errors: %s", $form->ID, join(', ', $form->errors)));
     }
     $this->respond($form);
     return true;
 }
 /**
  * @param int $form_id
  * @param int $preview_id
  *
  * @throws Exception
  */
 public function __construct($form_id, $preview_id = 0)
 {
     $this->form_id = $form_id;
     $this->preview_id = $preview_id;
     $this->is_preview = $preview_id > 0;
     if (!$this->is_preview) {
         $this->preview_id = $form_id;
     }
     $this->form = mc4wp_get_form($this->preview_id);
 }
 /**
  * Front-end display of widget.
  *
  * @see WP_Widget::widget()
  *
  * @param array   $args     Widget arguments.
  * @param array   $instance Saved values from database.
  */
 public function widget($args, $instance)
 {
     $title = apply_filters('widget_title', $instance['title']);
     echo $args['before_widget'];
     if (!empty($title)) {
         echo $args['before_title'] . $title . $args['after_title'];
     }
     // make sure template functions exist (for usage in avia layout builder)
     if (!function_exists('mc4wp_get_form')) {
         include_once MC4WP_LITE_PLUGIN_DIR . 'includes/functions/template.php';
     }
     echo mc4wp_get_form(0);
     echo $args['after_widget'];
 }
 /**
  * Front-end display of widget.
  *
  * @see WP_Widget::widget()
  *
  * @param array   $args     Widget arguments.
  * @param array   $options Saved values from database.
  */
 public function widget($args, $options)
 {
     $options = array_merge($this->default_options, $options);
     $options['title'] = apply_filters('widget_title', $options['title']);
     if (empty($options['form_id'])) {
         $options['form_id'] = get_option('mc4wp_default_form_id', 0);
     }
     echo $args['before_widget'];
     if (!empty($title)) {
         echo $args['before_title'] . $options['title'] . $args['after_title'];
     }
     echo mc4wp_get_form($options['form_id']);
     echo $args['after_widget'];
 }
 /**
  * @param int $form_id
  * @param bool $is_preview
  */
 public function __construct($form_id, $is_preview = false)
 {
     $this->form_id = $form_id;
     $this->is_preview = $is_preview;
     // get the preview form
     if ($is_preview) {
         $this->preview_form_id = $this->get_preview_id();
     }
     // if that failed, get the real form
     if (empty($this->preview_form_id)) {
         $this->preview_form_id = $this->form_id;
     }
     // get form instance
     $this->form = mc4wp_get_form($this->preview_form_id);
 }
Exemple #8
0
 /**
  * Front-end display of widget.
  *
  * @see WP_Widget::widget()
  *
  * @param array   $args     Widget arguments.
  * @param array   $instance Saved values from database.
  */
 public function widget($args, $instance)
 {
     $title = apply_filters('widget_title', $instance['title']);
     $form_id = isset($instance['form_id']) ? $instance['form_id'] : get_option('mc4wp_default_form_id', 0);
     if (empty($form_id)) {
         if (current_user_can('manage_options')) {
             $form = 'Please select the sign-up form you\'d like to show here in the <a href="' . admin_url('widgets.php') . '">widget settings</a>.';
         } else {
             $form = '';
         }
     } else {
         $form = mc4wp_get_form($form_id);
     }
     echo $args['before_widget'];
     if (!empty($title)) {
         echo $args['before_title'] . $title . $args['after_title'];
     }
     echo $form;
     echo $args['after_widget'];
 }
 /**
  * Front-end display of widget.
  *
  * @see WP_Widget::widget()
  *
  * @param array   $args     Widget arguments.
  * @param array   $instance Saved values from database.
  */
 public function widget($args, $instance)
 {
     $title = isset($instance['title']) ? $instance['title'] : '';
     $title = apply_filters('widget_title', $title);
     // which form should we show?
     $form_id = isset($instance['form_id']) && !empty($instance['form_id']) ? $instance['form_id'] : get_option('mc4wp_default_form_id', false);
     if (false === $form_id) {
         if (current_user_can('manage_options')) {
             $form = sprintf(__('Please select the sign-up form you\'d like to show here in the <a href="%s">widget settings</a>.', 'mailchimp-for-wp'), admin_url('widgets.php'));
         } else {
             $form = '';
         }
     } else {
         $form = mc4wp_get_form($form_id);
     }
     echo $args['before_widget'];
     if (!empty($title)) {
         echo $args['before_title'] . $title . $args['after_title'];
     }
     echo $form;
     echo $args['after_widget'];
 }
 /**
  * @param int   $id
  * @param array $config
  * @param bool $echo
  *
  * @return string
  */
 public function output_form($id = 0, $config = array(), $echo = true)
 {
     try {
         $form = mc4wp_get_form($id);
     } catch (Exception $e) {
         if (current_user_can('manage_options')) {
             return sprintf('<strong>MailChimp for WordPress error:</strong> %s', $e->getMessage());
         }
         return '';
     }
     $this->count++;
     // set a default element_id if none is given
     if (empty($config['element_id'])) {
         $config['element_id'] = 'mc4wp-form-' . $this->count;
     }
     $this->printed_forms[$form->ID] = $form;
     $this->printed_field_types += $form->get_field_types();
     $this->printed_field_types = array_unique($this->printed_field_types);
     // start new output buffer
     ob_start();
     /**
      * Runs just before a form element is outputted.
      *
      * @since 3.0
      *
      * @param MC4WP_Form $form
      */
     do_action('mc4wp_output_form', $form);
     // output the form (in output buffer)
     echo $form->get_html($config['element_id'], $config);
     // grab all contents in current output buffer & then clean it.
     $html = ob_get_clean();
     // echo content if necessary
     if ($echo) {
         echo $html;
     }
     return $html;
 }
 /**
  * Listen for submitted forms
  *
  * @param $data
  * @return bool
  */
 public function listen(array $data)
 {
     if (!isset($data['_mc4wp_form_id'])) {
         return false;
     }
     $request = mc4wp('request');
     try {
         $form = mc4wp_get_form($request->params->get('_mc4wp_form_id'));
     } catch (Exception $e) {
         return false;
     }
     // where the magic happens
     $form->handle_request($request);
     $this->submitted_form = $form;
     // is this form valid?
     if ($form->is_valid()) {
         // form was valid, do something
         $method = 'process_' . $form->get_action() . '_form';
         call_user_func(array($this, $method), $form);
     }
     $this->respond($form);
     return true;
 }
 /**
  * Show Styles Builder page
  */
 function show_page()
 {
     $forms = mc4wp_get_forms();
     $form_id = $forms[0]->ID;
     // get form to which styles should apply
     if (isset($_GET['form_id'])) {
         $form_id = absint($_GET['form_id']);
     }
     $form = mc4wp_get_form($form_id);
     // get css settings for this form (or 0)
     $builder = new MC4WP_Styles_Builder();
     $styles = $builder->get_form_styles($form_id);
     // create preview url
     $preview_url = add_query_arg(array('form_id' => $form_id, '_mc4wp_styles_builder_preview' => 1), home_url());
     require dirname(__FILE__) . '/../views/styles-builder.php';
 }
Exemple #13
0
 /**
  * Show the "Edit Form" page
  *
  * @internal
  */
 public function show_edit_page()
 {
     $form_id = !empty($_GET['form_id']) ? (int) $_GET['form_id'] : 0;
     $lists = $this->mailchimp->get_lists();
     try {
         $form = mc4wp_get_form($form_id);
     } catch (Exception $e) {
         echo '<h2>' . __("Form not found.", 'mailchimp-for-wp') . '</h2>';
         echo '<p>' . $e->getMessage() . '</p>';
         echo '<p><a href="javascript:history.go(-1);"> &lsaquo; ' . __('Go back') . '</a></p>';
         return;
     }
     $opts = $form->settings;
     $active_tab = isset($_GET['tab']) ? $_GET['tab'] : 'fields';
     require dirname(__FILE__) . '/views/edit-form.php';
 }
Exemple #14
0
/**
 * @since 2.3.8
 * @deprecated 3.0
 * @ignore
 * @use mc4wp_get_form
 *
 * @param int $form_id (optional)
 *
 * @return string
 */
function mc4wp_form_get_response_html($form_id = 0)
{
    try {
        $form = mc4wp_get_form($form_id);
    } catch (Exception $e) {
        return '';
    }
    return $form->get_response_html();
}
 /**
  * Outputs the text for the "type" column
  *
  * @param $item
  *
  * @return string|void
  */
 public function column_type($item)
 {
     if (isset($this->integrations[$item->type])) {
         $object_link = $this->integrations[$item->type]->get_object_link($item->related_object_ID);
         if (!empty($object_link)) {
             return $object_link;
         }
         return $this->integrations[$item->type]->name;
     }
     if ($item->type === 'mc4wp-form') {
         $form_id = $item->related_object_ID;
         try {
             $form = mc4wp_get_form($form_id);
             return '<a href="' . mc4wp_get_edit_form_url($form->ID) . '">' . $form->name . '</a>';
         } catch (Exception $e) {
             return __('Form', 'mailchimp-for-wp') . ' ' . $form_id . ' <em>(' . __('deleted', 'mailchimp-for-wp') . ')</em>';
         }
     } elseif ($item->type === 'mc4wp-top-bar') {
         return 'MailChimp Top Bar';
     }
     return $item->type;
 }
Exemple #16
0
/**
* Echoes sign-up form with given $form_id.
* @param int $form_id.
*/
function mc4wp_form($id = 0)
{
    echo mc4wp_get_form($id);
}
 /**
  * Build file with given CSS values
  *
  * @param int $form_id
  * @return bool
  */
 protected function build_stylesheet($form_id)
 {
     $css_string = $this->get_css_string($form_id);
     $filename = sprintf(self::DIR . 'form-%d.css', $form_id);
     // upload CSS file with CSS string as content
     $upload = wp_upload_dir();
     $target = $upload['basedir'];
     // try to create stylesheets dir with proper permissions
     @mkdir($target . rtrim(self::DIR, '/'), 0755);
     @chmod($target . rtrim(self::DIR, '/'), 0755);
     // remove previous file
     @unlink($target . $filename);
     // create new file
     $success = file_put_contents($target . $filename, $css_string);
     @chmod($target . $filename, 0755);
     if (!$success) {
         $message = __('Error creating stylesheet.', 'mailchimp-for-wp') . '</strong><br />';
         $message .= sprintf(__('Please add the generated CSS to your theme stylesheet manually or use a plugin like <em>%s</em>.', 'mailchimp-for-wp'), '<a href="https://wordpress.org/plugins/simple-custom-css/">Simple Custom CSS</a>') . '<br />';
         $message .= '<a class="mc4wp-show-css button" href="javascript:void(0);">' . __('Show generated CSS', 'mailchimp-for-wp') . '</a>';
         $message .= '<textarea id="mc4wp_generated_css" readonly style="display:none; width: 100%; min-height: 300px; margin-top: 20px;">' . esc_html($css_string) . '</textarea><strong>';
         add_settings_error('mc4wp', 'mc4wp-css', $message);
         return;
     }
     // create url
     $url = $upload['baseurl'] . $filename;
     $message = sprintf(__('The <a href="%s">CSS Stylesheet</a> was successfully created.', 'mailchimp-for-wp'), $url);
     // check if stylesheet is being loaded for this form, otherwise show notice.
     $form = mc4wp_get_form($form_id);
     if ($form->settings['css'] !== 'styles-builder') {
         $message .= '</strong><br /><br />' . sprintf(__('Please note that you need to <a href="%s">select "Use Styles Builder" in the form appearance settings</a> if you want to use these styles.', 'mailchimp-for-wp'), mc4wp_get_edit_form_url($form_id, 'appearance')) . '<strong>';
     }
     // show notice
     add_settings_error('mc4wp', 'mc4wp-css', $message, 'updated');
     return true;
 }
 /**
  * Echoes sign-up form with given $form_id.
  *
  * @param array $atts
  */
 function mc4wp_form($atts = array())
 {
     echo mc4wp_get_form($atts);
 }
/**
 * Echoes a sign-up form.
 *
 * @param   int     form ID
 *
 * @deprecated 1.3.1 Use mc4wp_form() instead.
 * @see mc4wp_form()
 */
function mc4wp_show_form($form_id)
{
    _deprecated_function(__FUNCTION__, 'MailChimp for WP Pro v1.3.1', 'mc4wp_form');
    echo mc4wp_get_form($form_id);
}
/**
 * Echoes a sign-up form.
 *
 * @deprecated 1.3.1 Use mc4wp_form() instead.
 * @see mc4wp_form()
 */
function mc4wp_show_form($form_id)
{
    echo mc4wp_get_form($form_id);
}