public function subscribe_from_form($Form)
 {
     $Settings = $this->api->get('Settings');
     $api_key = $Settings->get('perch_mailchimp_api_key')->settingValue();
     $list_id = $Settings->get('perch_mailchimp_list_id')->settingValue();
     $merge_vars = array();
     $groupings = array();
     $confirmed = false;
     $double_optin = true;
     $send_welcome = true;
     $update_existing = true;
     $replace_interests = false;
     $FormTag = $Form->get_form_attributes();
     if ($FormTag->is_set('double_optin')) {
         $double_optin = $FormTag->double_optin();
     }
     if ($FormTag->is_set('send_welcome')) {
         $send_welcome = $FormTag->send_welcome();
     }
     $attr_map = $Form->get_attribute_map('mailer');
     if (PerchUtil::count($attr_map)) {
         foreach ($attr_map as $fieldID => $merge_var) {
             switch ($merge_var) {
                 case 'email':
                     $email = $Form->data[$fieldID];
                     break;
                 case 'confirm_subscribe':
                     $confirmed = PerchUtil::bool_val($Form->data[$fieldID]);
                     break;
                 default:
                     $merge_vars[$merge_var] = $Form->data[$fieldID];
                     break;
             }
         }
     }
     if ($confirmed) {
         $MailChimp = new MailChimp($api_key);
         $result = $MailChimp->call('lists/subscribe', array('id' => $list_id, 'email' => array('email' => $email), 'merge_vars' => $merge_vars, 'double_optin' => $double_optin, 'update_existing' => $update_existing, 'replace_interests' => $replace_interests, 'send_welcome' => $send_welcome));
         return $result;
     }
     return false;
 }
예제 #2
0
<?php

$Pages = new PerchContent_Pages();
$Regions = new PerchContent_Regions();
$expand_list = array(0);
// Find new pages and initialise
$Pages->order_new_pages();
// Collapse list?
$do_list_collapse = $Settings->get('content_collapseList')->val();
$Perch->add_javascript_block("Perch.Apps.Content.settings = { 'collapseList':" . (PerchUtil::bool_val($do_list_collapse) ? 'true' : 'false') . " };");
// default state
$filter = 'all';
$do_regions = false;
$show_shared = true;
if (isset($_GET['filter']) && $_GET['filter'] == 'new') {
    $filter = 'new';
    $do_regions = true;
    $do_list_collapse = false;
    $show_shared = false;
}
if (isset($_GET['template']) && $_GET['template'] != '') {
    $filter = 'template';
    $do_regions = true;
    $do_list_collapse = false;
    $show_shared = true;
    $template_to_filter = urldecode($_GET['template']);
}
// Get pages
if ($do_list_collapse) {
    $expand_list = array(0);
    // get the existing expand list
 public function old_fields_from_template($Template, $details = array(), $seen_tags = array(), $include_repeaters = true)
 {
     if ($include_repeaters) {
         $tags = $Template->find_all_tags_and_repeaters();
     } else {
         $tags = $Template->find_all_tags();
     }
     $Form = $this;
     $out = '';
     if (PerchUtil::count($tags)) {
         foreach ($tags as $tag) {
             $item_id = 'perch_' . $tag->id();
             $raw_id = 'perch_' . $tag->id() . '_raw';
             $tag->set('input_id', $item_id);
             $tag->set('post_prefix', 'perch_');
             if (!in_array($tag->id(), $seen_tags) && $tag->type() != 'hidden') {
                 if ($tag->type() == 'slug' && !$tag->editable()) {
                     continue;
                 }
                 if ($tag->divider_before()) {
                     $out .= '<h2 class="divider">' . PerchUtil::html($tag->divider_before()) . '</h2>';
                 }
                 $out .= '<div class="field ' . $Form->error($item_id, false) . '">';
                 $label_text = PerchUtil::html($tag->label());
                 if ($tag->type() == 'textarea') {
                     if (PerchUtil::bool_val($tag->textile()) == true) {
                         $label_text .= ' <span><a href="' . PERCH_LOGINPATH . '/core/help/textile" class="assist">Textile</a></span>';
                     }
                     if (PerchUtil::bool_val($tag->markdown()) == true) {
                         $label_text .= ' <span><a href="' . PERCH_LOGINPATH . '/core/help/markdown" class="assist">Markdown</a></span>';
                     }
                 }
                 $Form->disable_html_encoding();
                 $out .= $Form->label($item_id, $label_text, '', false, false);
                 $Form->enable_html_encoding();
                 $FieldType = PerchFieldTypes::get($tag->type(), $Form, $tag, $tags, $this->app_id);
                 $out .= $FieldType->render_inputs($details);
                 if ($tag->help()) {
                     $out .= $Form->field_help($tag->help());
                 }
                 $out .= '</div>';
                 if ($tag->divider_after()) {
                     $out .= '<h2 class="divider">' . PerchUtil::html($tag->divider_after()) . '</h2>';
                 }
                 $seen_tags[] = $tag->id();
             }
         }
     }
     return $out;
 }
예제 #4
0
 protected function render_related($type, $opening_tag, $condition_contents, $exact_match, $template_contents, $content_vars, $index_in_group)
 {
     $Tag = new PerchXMLTag($opening_tag);
     $out = '';
     if ($Tag->suppress()) {
         return str_replace($exact_match, '', $template_contents);
     }
     if (is_array($content_vars) && isset($content_vars[$Tag->id()]) && PerchUtil::count($content_vars[$Tag->id()])) {
         if (!class_exists('PerchContent_Collections', false)) {
             include_once PERCH_CORE . '/runway/apps/content/PerchContent_Collections.class.php';
             include_once PERCH_CORE . '/runway/apps/content/PerchContent_Collection.class.php';
             include_once PERCH_CORE . '/runway/apps/content/PerchContent_CollectionItems.class.php';
             include_once PERCH_CORE . '/runway/apps/content/PerchContent_CollectionItem.class.php';
         }
         $Collections = $this->_get_cached_object('PerchContent_Collections');
         $value = $Collections->get_data_from_ids_runtime($Tag->collection(), $content_vars[$Tag->id()], $Tag->sort());
         $RelatedTemplate = new PerchTemplate(false, $this->namespace);
         $RelatedTemplate->load($condition_contents);
         if (PerchUtil::bool_val($Tag->scope_parent())) {
             $vars_for_cat = array();
             if (PerchUtil::count($content_vars)) {
                 foreach ($content_vars as $key => $val) {
                     if ($key != $Tag->id() && $key != 'itemJSON') {
                         $vars_for_cat['parent.' . $key] = $val;
                     }
                 }
             }
             $vars_for_cat = array_merge($vars_for_cat, $content_vars[$Tag->id()]);
             foreach ($value as &$item) {
                 $item = array_merge($item, $vars_for_cat);
             }
         }
         $out = $RelatedTemplate->render_group($value, true);
     } else {
         if (strpos($condition_contents, 'perch:noresults')) {
             $s = '/<perch:noresults[^>]*>(.*?)<\\/perch:noresults>/s';
             $count = preg_match_all($s, $condition_contents, $matches, PREG_SET_ORDER);
             if ($count > 0) {
                 foreach ($matches as $match) {
                     $out .= $match[1];
                 }
             }
         }
     }
     return str_replace($exact_match, $out, $template_contents);
 }
 public function get_raw($post = false, $Item = false)
 {
     if ($post === false) {
         $post = $_POST;
     }
     $id = $this->Tag->id();
     if (isset($post[$id])) {
         $raw = trim($post[$id]);
         $flang = 'plain';
         if ($this->Tag->html()) {
             $flang = 'html';
         }
         $value = PerchUtil::safe_stripslashes($raw);
         // Strip HTML by default
         if (!is_array($value) && PerchUtil::bool_val($this->Tag->html()) == false) {
             $value = PerchUtil::html($value);
             $value = strip_tags($value);
         }
         $Markdown = new PerchParsedown();
         $value = $Markdown->smartypants($value);
         $flang = 'smartypants';
         $store = array('_flang' => $flang, 'raw' => $raw, 'processed' => $value);
         $this->raw_item = $store;
         return $this->raw_item;
     }
     return null;
 }
 private function _replace_form_tags($template, $opening_tag, $closing_tag)
 {
     $Perch = Perch::fetch();
     $OpeningTag = new PerchXMLTag($opening_tag);
     if ($OpeningTag->prefix()) {
         if ($OpeningTag->prefix() == 'none') {
             $this->field_prefix = '';
         } else {
             $this->field_prefix = $OpeningTag->prefix() . '_';
         }
     } else {
         $Perch->form_count++;
         $this->field_prefix = 'form' . $Perch->form_count . '_';
     }
     $attrs = array();
     $attrs['id'] = $this->field_prefix . $OpeningTag->id();
     $attrs['class'] = $OpeningTag->class();
     $attrs['action'] = $OpeningTag->action();
     $attrs['method'] = $OpeningTag->method();
     $attrs['role'] = $OpeningTag->role();
     $attrs['name'] = $OpeningTag->name();
     $attrs['autocomplete'] = $OpeningTag->autocomplete();
     $aria = $OpeningTag->search_attributes_for('aria-');
     if (PerchUtil::count($aria)) {
         $attrs = array_merge($attrs, $aria);
     }
     $html5data = $OpeningTag->search_attributes_for('data-');
     if (PerchUtil::count($html5data)) {
         $attrs = array_merge($attrs, $html5data);
     }
     $this->form_id = $OpeningTag->id();
     $this->handling_app = $OpeningTag->app();
     $this->template_path = $OpeningTag->template();
     $this->action = $OpeningTag->action();
     $this->app = $OpeningTag->app();
     $this->method = $OpeningTag->method();
     if (PERCH_HTML5 && $OpeningTag->novalidate()) {
         $attrs['novalidate'] = 'novalidate';
     }
     if (PERCH_RUNWAY) {
         if (!$attrs['action']) {
             $Runway = PerchRunway::fetch();
             $attrs['action'] = $Runway->get_page();
         }
     } else {
         if (!$attrs['action']) {
             $attrs['action'] = $Perch->get_page_as_set(true);
         }
     }
     // submit via ssl?
     if (PERCH_SSL && $OpeningTag->ssl() && PerchUtil::bool_val($OpeningTag->ssl())) {
         $attrs['action'] = PerchUtil::url_to_ssl($attrs['action']);
     }
     if (!$attrs['method']) {
         $attrs['method'] = 'post';
     }
     $this->form_key = base64_encode($this->form_id . ':' . $this->handling_app . ':' . $this->template_path . ':' . time());
     // Does it have file fields?
     $s = '/(<perch:input[^>]*type="(file|image)"[^>]*>)/s';
     if (preg_match($s, $template)) {
         $attrs['enctype'] = 'multipart/form-data';
     }
     $new_opening_tag = PerchXMLTag::create('form', 'opening', $attrs);
     $template = str_replace($opening_tag, $new_opening_tag, $template);
     $new_closing_tag = PerchXMLTag::create('form', 'closing');
     $template = str_replace($closing_tag, $new_closing_tag, $template);
     return $template;
 }
 public static function display_item_fields($tags, $id, $item, $Page, $Form, $Template, $blocks_link_builder = array('PerchContent_Util', 'get_block_link'), $seen_tags = array())
 {
     //PerchUtil::debug($tags, 'success');
     //$seen_tags = array();
     if (!PerchUtil::count($tags)) {
         return;
     }
     foreach ($tags as $tag) {
         if ($id === null) {
             $item_id = 'perch_' . $tag->id();
             $tag->set('input_id', $item_id);
             $tag->set('post_prefix', 'perch_');
         } else {
             $item_id = 'perch_' . $id . '_' . $tag->id();
             $tag->set('input_id', $item_id);
             $tag->set('post_prefix', 'perch_' . $id . '_');
         }
         if (is_object($Page)) {
             $tag->set('page_id', $Page->id());
         }
         if (!in_array($tag->id(), $seen_tags) && $tag->type() != 'hidden' && $tag->type() != 'editcontrol' && substr($tag->id(), 0, 7) != 'parent.') {
             if ($tag->type() == 'slug' && !$tag->editable()) {
                 continue;
             }
             if (!PERCH_RUNWAY && $tag->runway()) {
                 continue;
             }
             //PerchUtil::debug($tag->type(), 'success');
             if ($tag->type() == 'PerchRepeater') {
                 $repeater_id = $id . '_' . $tag->id();
                 if ($tag->divider_before()) {
                     echo '<h2 class="divider">' . PerchUtil::html($tag->divider_before()) . '</h2>';
                 }
                 if ($tag->notes_before()) {
                     echo '<p class="formnotes">' . PerchUtil::html($tag->notes_before()) . '</p>';
                 }
                 echo '<h3 class="label repeater-heading">' . $tag->label() . '</h3>';
                 echo '<div class="repeater" data-prefix="perch_' . PerchUtil::html($repeater_id) . '"';
                 if ($tag->max()) {
                     echo ' data-max="' . PerchUtil::html($tag->max()) . '"';
                 }
                 echo '>';
                 echo '<div class="repeated">';
                 $repeater_i = 0;
                 if (isset($item[$tag->id()]) && is_array($item[$tag->id()])) {
                     $subitems = $item[$tag->id()];
                     if (isset($_POST['perch_' . $repeater_id . '_count']) && (int) $_POST['perch_' . $repeater_id . '_count'] > 0) {
                         $submitted_count = (int) $_POST['perch_' . $repeater_id . '_count'];
                         if (PerchUtil::count($subitems) < $submitted_count) {
                             for ($i = PerchUtil::count($subitems); $i < $submitted_count; $i++) {
                                 $subitems[] = array();
                             }
                         }
                     }
                     foreach ($subitems as $subitem) {
                         $edit_prefix = 'perch_' . $repeater_id . '_' . $repeater_i . '_';
                         foreach ($subitem as $key => $val) {
                             $subitem[$edit_prefix . $key] = $val;
                         }
                         echo '<div class="repeated-item">';
                         echo '<div class="index"><span>' . ($repeater_i + 1) . '</span><span class="icon"></span></div>';
                         echo '<div class="repeated-fields">';
                         PerchContent_Util::display_item_fields($tag->tags, $repeater_id . '_' . $repeater_i, $subitem, $Page, $Form, $Template);
                         echo '<input type="hidden" name="perch_' . ($repeater_id . '_' . $repeater_i) . '_present" class="present" value="1" />';
                         echo '<input type="hidden" name="perch_' . ($repeater_id . '_' . $repeater_i) . '_prevpos" value="' . $repeater_i . '" />';
                         echo '</div>';
                         echo '<div class="rm"></div>';
                         echo '</div>';
                         $repeater_i++;
                     }
                 }
                 $spare = true;
                 if ($tag->max() && $repeater_i - 1 >= (int) $tag->max()) {
                     $spare = false;
                 }
                 if ($spare) {
                     // And one spare
                     echo '<div class="repeated-item spare">';
                     echo '<div class="index icon"><span>' . ($repeater_i + 1) . '</span><span class="icon"></span></div>';
                     echo '<div class="repeated-fields">';
                     PerchContent_Util::display_item_fields($tag->tags, $repeater_id . '_' . $repeater_i, array(), $Page, $Form, $Template);
                     echo '<input type="hidden" name="perch_' . ($repeater_id . '_' . $repeater_i) . '_present" class="present" value="1" />';
                     echo '</div>';
                     echo '<div class="rm"></div>';
                     echo '</div>';
                     echo '</div>';
                     // .repeated
                     // footer
                     echo '<div class="repeater-footer">';
                     echo '<input type="hidden" name="perch_' . $repeater_id . '_count" value="0" class="count" />';
                     echo '</div>';
                 }
                 echo '</div>';
                 if ($tag->divider_after()) {
                     echo '<h2 class="divider">' . PerchUtil::html($tag->divider_after()) . '</h2>';
                 }
             } elseif ($tag->type() == 'PerchBlocks') {
                 if ($tag->divider_before()) {
                     echo '<h2 class="divider">' . PerchUtil::html($tag->divider_before()) . '</h2>';
                 }
                 if ($tag->notes_before()) {
                     echo '<p class="formnotes">' . PerchUtil::html($tag->notes_before()) . '</p>';
                 }
                 echo PerchContent_Util::display_blocks($tags, $id, $item, $Page, $Form, $Template, $blocks_link_builder);
                 if ($tag->divider_after()) {
                     echo '<h2 class="divider">' . PerchUtil::html($tag->divider_after()) . '</h2>';
                 }
             } else {
                 if ($tag->divider_before()) {
                     echo '<h2 class="divider">' . PerchUtil::html($tag->divider_before()) . '</h2>';
                 }
                 if ($tag->notes_before()) {
                     echo '<p class="formnotes">' . PerchUtil::html($tag->notes_before()) . '</p>';
                 }
                 echo '<div class="field ' . $Form->error($item_id, false) . '">';
                 echo '<div class="fieldtbl">';
                 $label_text = PerchUtil::html($tag->label());
                 if ($tag->type() == 'textarea') {
                     if (PerchUtil::bool_val($tag->textile()) == true) {
                         $label_text .= ' <span><a href="' . PERCH_LOGINPATH . '/core/help/textile" class="assist">Textile</a></span>';
                     }
                     if (PerchUtil::bool_val($tag->markdown()) == true) {
                         $label_text .= ' <span><a href="' . PERCH_LOGINPATH . '/core/help/markdown" class="assist">Markdown</a></span>';
                     }
                 }
                 $Form->disable_html_encoding();
                 echo '<div class="fieldlbl">' . $Form->label($item_id, $label_text, '', false, false) . '</div>';
                 $Form->enable_html_encoding();
                 $FieldType = PerchFieldTypes::get($tag->type(), $Form, $tag, false, $Form->app_id);
                 echo '<div class="field-wrap">';
                 echo $FieldType->render_inputs($item);
                 if ($tag->help()) {
                     echo $Form->translated_hint($tag->help());
                 }
                 echo '</div>';
                 echo '</div>';
                 echo '</div>';
                 if ($tag->divider_after()) {
                     echo '<h2 class="divider">' . PerchUtil::html($tag->divider_after()) . '</h2>';
                 }
             }
             $seen_tags[] = $tag->id();
         } else {
             if (!in_array($tag->id(), $seen_tags) && $tag->edit_control()) {
                 // Hidden fields for editing purposes.
                 $FieldType = PerchFieldTypes::get('editcontrol', $Form, $tag, false, $Form->app_id);
                 echo $FieldType->render_inputs($item);
                 $seen_tags[] = $tag->id();
             }
         }
     }
 }
 public function subscribe_from_form(PerchAPI_SubmittedForm $SubmittedForm)
 {
     $listIDs = [];
     $merge_vars = [];
     $interests = [];
     $confirmed = false;
     $status = 'subscribed';
     $FormTag = $SubmittedForm->get_form_attributes();
     if ($FormTag->is_set('double_optin')) {
         if ($FormTag->double_optin()) {
             $status = 'pending';
         }
     }
     $attr_map = $SubmittedForm->get_attribute_map('mailer');
     if (PerchUtil::count($attr_map)) {
         foreach ($attr_map as $fieldID => $merge_var) {
             switch ($merge_var) {
                 case 'list':
                     if (isset($SubmittedForm->data[$fieldID])) {
                         $listIDs[] = $SubmittedForm->data[$fieldID];
                     }
                     break;
                 case 'email':
                     $email = $SubmittedForm->data[$fieldID];
                     break;
                 case 'confirm_subscribe':
                     $confirmed = PerchUtil::bool_val($SubmittedForm->data[$fieldID]);
                     break;
                 case 'interests':
                     $interests[$SubmittedForm->data[$fieldID]] = true;
                     break;
                 default:
                     $merge_vars[$merge_var] = $SubmittedForm->data[$fieldID];
                     break;
             }
         }
     }
     if (PerchUtil::count($listIDs)) {
         $data = [];
         $data['email_address'] = $email;
         $data['status'] = $status;
         if (PerchUtil::count($merge_vars)) {
             $data['merge_fields'] = $merge_vars;
         }
         if (PerchUtil::count($interests)) {
             $data['interests'] = $interests;
         }
         if ($confirmed) {
             $Lists = new PerchMailChimp_Lists($this->api);
             $MailChimpAPI = $this->get_api_instance();
             foreach ($listIDs as $listMailChimpID) {
                 $List = $Lists->get_one_by('listMailChimpID', $listMailChimpID);
                 if (is_object($List)) {
                     PerchUtil::debug('Subscribing to: ' . $List->listTitle());
                     $listID = $listMailChimpID;
                     $result = $MailChimpAPI->post("lists/{$listID}/members", $data);
                     if ($MailChimpAPI->success()) {
                     } else {
                         PerchUtil::debug($MailChimpAPI->getLastResponse());
                     }
                 }
             }
         }
     }
 }