コード例 #1
0
ファイル: mailchimp.php プロジェクト: erikdukker/medisom
 /**
  * Popup Elements
  *
  * If this function is defined in a child class the element automatically gets an edit button, that, when pressed
  * opens a modal window that allows to edit the element properties
  *
  * @return void
  */
 function popup_elements()
 {
     $api = false;
     $owner = "";
     $lists = array();
     //load the api only when the popup gets opened
     if (!empty($_POST) && !empty($_POST['action']) && $_POST['action'] == "avia_ajax_av_mailchimp") {
         $api = new av_mailchimp_api($this->api_key);
         $owner = $api->api_owner();
         if (empty($this->api_key) || !$owner) {
             $this->elements = array(array("name" => __("No Mailchimp API key found", 'avia_framework'), "desc" => __("Please enter a valid Mailchimp API key, otherwise we will not be able to retrieve the lists that your visitors may subscribe to.", 'avia_framework') . '<br/><br/><a target="_blank" href="' . admin_url('admin.php?page=avia#goto_newsletter') . '">' . __("You can enter your API key here", 'avia_framework') . "</a>", "type" => "heading", "description_class" => "av-builder-note av-error"));
             return;
         }
         $api->store_lists();
         $lists = $api->get_list_ids();
         if (!empty($this->api_key) && (empty($lists) || !is_array($lists))) {
             $this->elements = array(array("name" => __("No Mailchimp Lists found", 'avia_framework'), "desc" => __("We could not find any lists that your customers can subscribe to. Please check if the API key you have entered in your Enfold Theme Panel is valid and also check if you have at least one list created on mailchimp", 'avia_framework') . '<br/><br/><a target="_blank" href="' . admin_url('admin.php?page=avia#goto_newsletter') . '">' . __("Check API key here", 'avia_framework') . '</a> | <a target="_blank" href="https://login.mailchimp.com/">' . __("Go to Mailchimp", 'avia_framework') . "</a>", "type" => "heading", "description_class" => "av-builder-note av-error"));
             return;
         }
         $newlist = array();
         foreach ($lists as $key => $list_item) {
             $newlist[$list_item['name']] = $key;
         }
         $lists = $newlist;
         $first = array(__("Select a mailchimp list...", "avia_framework") => '');
         $lists = array_merge($first, $lists);
     }
     //default elements that gets loaded if
     $this->elements = apply_filters('avf_sc_mailchimp_popup_elements', array(array("type" => "tab_container", 'nodescription' => true), array("type" => "tab", "name" => __("Form", 'avia_framework'), 'nodescription' => true), array("name" => __("Mailchimp active", 'avia_framework'), "desc" => __("This installation is connected to the Mailchimp account: ", 'avia_framework') . "'" . $owner . "'<br/><br/>" . "<strong>" . __("Please note:", 'avia_framework') . "</strong> " . __("This element currently only supports basic list subscription with basic form fields (text and dropdowns). Please let us know if you would like to see more advanced features.", 'avia_framework'), "type" => "heading", "description_class" => "av-builder-note av-notice"), array("name" => __("Lists", 'avia_framework'), "desc" => __("Select the list that the user should be added to. The form will be build automatically based on the list that you have set up in mailchimp.", 'avia_framework'), "id" => "list", "type" => "mailchimp_list", "std" => "", "subtype" => $lists, "api" => $api, "std" => ""), array("name" => __("Edit Contact Form Elements", 'avia_framework'), "desc" => __("Once you have selected a list above the available form fields will be displayed here", 'avia_framework') . "<br/>" . "<br/><strong>" . __("Please note:", 'avia_framework') . "</strong>" . "<ul>" . "<li>" . __("You can only hide form fields that are not required", 'avia_framework') . "</li>" . "<li>" . __("Currently only text and dropdown elements are supported properly", 'avia_framework') . "</li>" . "</ul>", "type" => "modal_group", "id" => "content", "modal_title" => __("Edit Form Element", 'avia_framework'), "disable_manual" => true, "class" => "av-automated-inserts", "std" => array(), 'subelements' => array(array("id" => 'id', "std" => '', "type" => "hidden"), array("id" => 'type', "std" => '', "type" => "hidden"), array("id" => 'check', "std" => '', "type" => "hidden"), array("id" => 'options', "std" => '', "type" => "hidden"), array("name" => __("Form Element hidden", 'avia_framework'), "desc" => __("Check if you want to hide this form element", 'avia_framework'), "id" => "disabled", "type" => "checkbox", "std" => "", "required" => array('check', 'equals', '')), array("name" => __("Form Element Label", 'avia_framework'), "desc" => "", "id" => "label", "std" => "", "type" => "input"), array("name" => __("Form Element Width", 'avia_framework'), "desc" => __("Change the width of your elements and let them appear beside each other instead of underneath", 'avia_framework'), "id" => "width", "type" => "select", "std" => "", "no_first" => true, "subtype" => array("Fullwidth" => '', "1/2" => 'element_half', "1/3" => 'element_third', "2/3" => 'element_two_third', "1/4" => 'element_fourth', "3/4" => 'element_three_fourth')))), array("name" => __("Double opt-in?", 'avia_framework'), "desc" => __("Check if you want people to confirm their email address before being subscribed (highly recommended)", 'avia_framework'), "id" => "double_opt_in", "std" => "true", "type" => "checkbox"), array("name" => __("What should happen once the form gets sent?", 'avia_framework'), "desc" => "", "id" => "on_send", "type" => "select", "std" => "text", "no_first" => true, "subtype" => array(__('Display a short message on the same page', 'avia_framework') => '', __('Redirect the user to another page', 'avia_framework') => 'redirect')), array("name" => __("Message Sent label", 'avia_framework'), "desc" => __("What should be displayed once the message is sent?", 'avia_framework'), "id" => "sent", "required" => array('on_send', 'not', 'redirect'), "std" => __("Thank you for subscribing to our newsletter!", 'avia_framework'), "type" => "input"), array("name" => __("Redirect", 'avia_framework'), "desc" => __("To which page do you want the user send to?", 'avia_framework'), "id" => "link", "type" => "linkpicker", "fetchTMPL" => true, "std" => "", "required" => array('on_send', 'equals', 'redirect'), "subtype" => array(__('Set Manually', 'avia_framework') => 'manually', __('Single Entry', 'avia_framework') => 'single'), "std" => ""), array("type" => "close_div", 'nodescription' => true), array("type" => "tab", "name" => __("Form Styling", 'avia_framework'), 'nodescription' => true), array("name" => __("Form Color Scheme", 'avia_framework'), "desc" => __("Select a form color scheme here", 'avia_framework'), "id" => "color", "type" => "select", "std" => "", "subtype" => array(__('Default', 'avia_framework') => '', __('Light transparent', 'avia_framework') => 'av-custom-form-color av-light-form', __('Dark transparent', 'avia_framework') => 'av-custom-form-color av-dark-form')), array("name" => __("Hide Form Labels", 'avia_framework'), "desc" => __("Check if you want to hide form labels above the form elements. The form will instead try to use an inline label (not supported on old browsers)", 'avia_framework'), "id" => "hide_labels", "std" => "", "type" => "checkbox"), array("type" => "close_div", 'nodescription' => true), array("type" => "close_div", 'nodescription' => true)));
 }
コード例 #2
0
 static function backend_html($value = "", $ajax = true)
 {
     $owner = false;
     $response = array();
     $response_text = __("Could not connect to Mailchimp with this API Key. Please try again with a different key", 'avia_framework');
     $response_class = "av-notice-error";
     $trigger_global_save = false;
     $list_output_default = __("You might also want to check your internet connection and make sure that mailchimp.com is available", 'avia_framework');
     if ($ajax) {
         if (!empty($value)) {
             $api = new av_mailchimp_api($value);
             $owner = $api->api_owner();
         }
         if ($owner) {
             $api->store_lists();
             $trigger_global_save = true;
             $response_class = "";
             $response_text = __("We were able to connect to your Mailchimp account", 'avia_framework');
             $response_text .= " ({$owner})";
             $response_text .= " avia_trigger_save";
         }
     } else {
         $owner = get_option('av_mailchimp_owner');
         if ($owner) {
             $response_class = "";
             $response_text = __("Last time we checked we were able to connected to your Mailchimp account", 'avia_framework');
             $response_text .= " ({$owner})";
         }
     }
     if ($owner) {
         $lists = get_option('av_chimplist');
         $list_fields = get_option('av_chimplist_field');
         $list_output_default = __("We were not able to find any Newsletter List on your Mailchimp that your visitors can subscribe to. Please create at least one in your Mailchimp back-end and refresh the list data here to use Mailchimp with this theme.", 'avia_framework');
         if (!empty($list_fields)) {
             $list_output = "";
             $list_output_default = "";
             $list_output .= "<div class='av-verification-cell'><strong>" . __('Available Lists', 'avia_framework') . ":</strong></div>";
             foreach ($list_fields as $key => $list_items) {
                 $sub = $lists[$key]['stats']->member_count;
                 $list_output .= "<div class='av-verification-cell av-verification-cell-heading'>";
                 $list_output .= "<strong>{$lists[$key]['name']}</strong>";
                 $list_output .= "<small class='av-verification-extra-data'> (" . __('Subscriber', 'avia_framework') . ": {$sub})</small>";
                 $list_output .= "<small class='av-verification-extra-data av-verification-extra-data-right'>(" . __('ID', 'avia_framework') . ": {$key})</small>";
                 $list_output .= "</div>";
                 foreach ($list_items as $key => $field) {
                     $required = !empty($field->required) ? "<span class='av-verification-required'>*</span>" : "";
                     $list_output .= "<div class='av-verification-cell av-verification-cell-sub'>";
                     $list_output .= "{$field->name} {$required}";
                     $list_output .= "<span class='av-verification-extra-data av-verification-extra-data-right'>{$field->type}</span>";
                     $list_output .= "</div>";
                 }
             }
             $list_output .= "<div class='av-verification-cell av-verification-cell-heading'><strong>" . __('If you ever change the fields in your list please re-validate your API key to update the list data presented here.', 'avia_framework') . "</strong></div>";
         }
     }
     $output = "<div class='av-verification-response-wrapper'>";
     $output .= "<div class='av-text-notice {$response_class}'>";
     $output .= $response_text;
     $output .= "</div>";
     if (!empty($list_output) || !empty($list_output_default)) {
         $output .= "<div class='av-verification-mailchimp-list'>";
         if (!empty($list_output)) {
             $output .= $list_output;
         }
         if (!empty($list_output_default)) {
             $output .= "<div class='av-verification-cell'>" . $list_output_default . "</div>";
         }
         $output .= "</div>";
     }
     $output .= "</div>";
     return $output;
 }