예제 #1
0
 public static function render($newsletter_id, $send_id = false, $newsletter_member_id = false, $render_type = 'preview')
 {
     $newsletter = self::get_newsletter($newsletter_id);
     if (!$newsletter || $newsletter['newsletter_id'] != $newsletter_id) {
         return;
     }
     $newsletter_content = $newsletter['content'];
     if ($send_id) {
         $send_data = self::get_send($send_id);
         if ($send_data && $send_data['newsletter_id'] != $newsletter_id) {
             return;
         }
     }
     $replace = self::get_replace_fields($newsletter_id, $send_id, $newsletter_member_id);
     $template_html = '';
     if ($newsletter['newsletter_template_id']) {
         // load template in.
         $template = self::get_newsletter_template($newsletter['newsletter_template_id']);
         $replace['TEMPLATE_PATH'] = full_link($template['directory']);
         // check if there's a template file for this template
         // and pass the processing off to it's module.
         // this can replace the newsletter_content variable with something
         // more advanced like a listing from a WP database.
         if (!_DEMO_MODE) {
             // todo - run the content url
             // execute any php code inside the template.
             ob_start();
             @eval(' ?>' . $template['body'] . '<?php ');
             $template_html = ob_get_clean();
             if (!$template_html) {
                 $template_html = $template['body'];
             }
         } else {
             $template_html = $template['body'];
         }
         if ($template && $template['directory'] && is_dir($template['directory'])) {
             if (is_file($template['directory'] . 'render.php')) {
                 $return_html = false;
                 include $template['directory'] . 'render.php';
                 // do we return the html right from here?
                 if ($return_html) {
                     return $template_html;
                 }
             }
         }
     }
     if (!preg_match('#\\{BODY\\}#i', $template_html)) {
         $template_html .= '{BODY}';
     }
     //$template_html = str_replace('{BODY}',$newsletter_content,$template_html);
     // replace any content from our newsletter variables.
     $replace['BODY'] = $newsletter_content;
     // custom for send.
     // TODO: we build up a list of 'recipients' based on a search (or whatever) from any part of the application.
     // the list will be a CSV style file, with column headers. Each column can be linked into here as a replacement variable.
     // eg: the customer list will be "Customer Name" "Primary Contact" etc..
     // maybe tie this into the pagination function? so the table can be exported from anywhere?
     // store this listing of contacts as-is as new rows in the database. allow the user to edit this listing like a spreadsheet (ie: add new rows from another search, remove rows, edit details).
     // try to store a link back to the original record where this item came from (eg: a link to edit customer)
     // but always keep the original (eg:) email address of the customer on file, so if customer record changes the history will still show old address etc..
     // unsubscribes will add this users email to a separate black list, so that future sends will flag these members as unsubscribed.
     // admin has the option to ignore these unsubscribes if they want.
     // bounces will add this users email to a separate bounce list. after a certain number of bounces (from settings) we stop sending this user emails
     // and we notify future sends that this list of members wont be emailed due to bounces. (same warning/info listing that shows about unsubscribed users)
     // todo: end :)
     // nite dave!
     $final_newsletter_html = $template_html;
     // do HTML loop twice so we catch all conversions
     // ignore certain links for the below process
     // todo: doing this breaks link tracking on unsub/view online links.
     // option1: put every single unique link into the link table (eg, with member id on it)
     // option2: like old newsletter system, append newsletter member id onto end of all redirected links. then we can store a single "unsub" url in the db and it will redirect correctly.
     // todo - put generic url's in for unsub, view online, member details, etc..
     // todo - redirect opened links in external hook, append a new member id and new member id hash onto each redirect url.
     // todo - modify the unsub / view online / etc.. to look for these new appended memberid/memberhash variables along with existing old system ones.
     /*$special_link_replace_items = array(
           'UNSUBSCRIBE'=>self::unsubscribe_url($newsletter_id,$newsletter_member_id,$send_id),
           'VIEW_ONLINE'=>self::view_online_url($newsletter_id,$newsletter_member_id,$send_id),
           'LINK_ACCOUNT'=>'#',
           'SENDTOFRIEND'=>'#',
           'MEMBER_URL'=>'#',
       );*/
     $special_link_replace_items = array();
     // only contains the member_url at the moment.
     // are we a member?
     if ($newsletter_member_id > 0) {
         $member_data = self::get_newsletter_member($newsletter_member_id);
         if ($member_data && $member_data['member_id'] > 0) {
             $special_link_replace_items['MEMBER_URL'] = module_member::link_public_details($member_data['member_id']);
         }
     }
     for ($x = 0; $x < 2; $x++) {
         foreach ($replace as $key => $val) {
             if (isset($special_link_replace_items[$key])) {
                 continue;
             }
             // do these ones later.
             if ($render_type == 'preview' && !strlen(trim($val))) {
                 continue;
             }
             //$val = str_replace('//','////',$val); // todo- check this is correct in older version
             //$val = str_replace('\\','\\\\',$val); // todo- check this is correct in older version
             $final_newsletter_html = str_replace('{' . strtoupper($key) . '}', $val, $final_newsletter_html);
         }
     }
     if ($send_id && $render_type != 'preview') {
         // we process links and images for tracking purposes.
         if (module_config::c('newsletter_convert_links', 1)) {
             // check if there have been any converted links for this send already.
             $page_index = 1;
             foreach (array("href") as $type) {
                 preg_match_all('/<[^>]*(' . $type . '=(["\'])([^"\']+)\\2)/', $final_newsletter_html, $links);
                 if (is_array($links[3])) {
                     foreach ($links[3] as $link_id => $l) {
                         //if(!preg_match('/^\{/',$l) && !preg_match('/^#/',$l) && !preg_match('/^mailto:/',$l)){
                         if (!preg_match('/^\\{/', $l) && !preg_match('/^#/', $l) && !stripos($links[0][$link_id], '<link') && !(preg_match('/^\\w+:/', $l) && !preg_match('/^http/', $l))) {
                             //echo $links[0][$link_id] ."<br>";
                             $search = preg_quote($links[1][$link_id], "/");
                             //echo $search."<br>\n";
                             $l = preg_replace("/[\\?|&]phpsessid=([\\w\\d]+)/i", '', $l);
                             $l = ltrim($l, '/');
                             $newlink = (!preg_match('/^http/', $l) ? full_link('') : '') . $l;
                             // we are sending this out, we need to store a link to this in the db
                             // to record clicks etc..
                             // check if this link already exists in the database for this send.
                             $sql = "SELECT * FROM `" . _DB_PREFIX . "newsletter_link` WHERE `send_id` = " . (int) $send_id . " AND `link_url` = '" . mysql_real_escape_string($newlink) . "' AND `page_index` = " . (int) $page_index;
                             $existing = qa1($sql);
                             $db_link_id = false;
                             if ($existing && $existing['link_id']) {
                                 $db_link_id = $existing['link_id'];
                             } else {
                                 if ($render_type != 'preview') {
                                     // todo - don't re-create a link in the db if this send is bogus. like what if someone sends, then modifies the newsletter content, then goes back and views the stats. all the page index will be out of date. eep1!!!
                                     $db_link_id = update_insert('link_id', false, 'newsletter_link', array('send_id' => $send_id, 'link_url' => $newlink, 'page_index' => $page_index));
                                     //$sql = "INSERT INTO `"._DB_PREFIX."newsletter_link` SET `send_id` = ".(int)$send_id.", `link_url` = '".mysql_real_escape_string($newlink)."'";
                                     //query($sql);
                                     //$link_id = mysql_insert_id();
                                 }
                             }
                             if ($db_link_id) {
                                 $newlink = self::link_to_link($send_id, $db_link_id, $newsletter_member_id ? $newsletter_member_id : '');
                                 $replace = $type . '="' . $newlink . '"';
                                 //echo $replace."<br>\n";
                                 //preg_match('/'.$search."/",$template,$matches);print_r($matches);
                                 $final_newsletter_html = preg_replace('/' . $search . '/', $replace, $final_newsletter_html, 1);
                             }
                             $page_index++;
                         }
                     }
                 }
             }
         }
         if (module_config::c('newsletter_convert_images', 1)) {
             foreach (array("src", "background") as $type) {
                 preg_match_all('/' . $type . '=(["\'])([^"\']+)\\1/', $final_newsletter_html, $links);
                 if (is_array($links[2])) {
                     foreach ($links[2] as $link_id => $l) {
                         //if(!preg_match('/^\{/',$l) && !preg_match('/^#/',$l) && !preg_match('/^mailto:/',$l)){
                         if (!preg_match('/^\\{/', $l) && !preg_match('/^#/', $l) && !(preg_match('/^\\w+:/', $l) && !preg_match('/^http/', $l))) {
                             //echo $links[0][$link_id] ."<br>";
                             $search = preg_quote($links[0][$link_id], "/");
                             //echo $search."<br>\n";
                             $l = preg_replace("/[\\?|&]phpsessid=([\\w\\d]+)/i", '', $l);
                             $l = html_entity_decode(ltrim($l, '/'));
                             $newlink = (!preg_match('/^http/', $l) ? full_link('') : '') . $l;
                             // we are sending this out, we need to store a link to this in the db
                             // to record clicks etc..
                             // check if this link already exists in the database for this send.
                             $sql = "SELECT * FROM `" . _DB_PREFIX . "newsletter_image` WHERE `send_id` = " . (int) $send_id . " AND `image_url` = '" . mysql_real_escape_string($newlink) . "'";
                             $existing = qa1($sql);
                             if ($existing && $existing['image_id']) {
                                 $image_id = $existing['image_id'];
                             } else {
                                 $sql = "INSERT INTO `" . _DB_PREFIX . "newsletter_image` SET `send_id` = " . (int) $send_id . ", `image_url` = '" . mysql_real_escape_string($newlink) . "'";
                                 query($sql);
                                 $image_id = mysql_insert_id();
                             }
                             $newlink = self::link_to_image($send_id, $image_id, $newsletter_member_id ? $newsletter_member_id : '');
                             $replace = $type . '="' . $newlink . '"';
                             //echo $replace."<br>\n";
                             //preg_match('/'.$search."/",$template,$matches);print_r($matches);
                             $final_newsletter_html = preg_replace('/' . $search . '/', $replace, $final_newsletter_html, 1);
                         }
                     }
                 }
             }
         }
     }
     foreach ($special_link_replace_items as $key => $val) {
         if ($render_type == 'preview' && !strlen(trim($val))) {
             continue;
         }
         //$val = str_replace('//','////',$val); // todo- check this is correct in older version
         //$val = str_replace('\\','\\\\',$val); // todo- check this is correct in older version
         $final_newsletter_html = str_replace('{' . strtoupper($key) . '}', $val, $final_newsletter_html);
     }
     // todo - a text version of the html version.
     return $final_newsletter_html;
 }
예제 #2
0
}
$module->page_title = _l('Member: %s', htmlspecialchars($member['first_name'] . ' ' . $member['last_name']));
?>

<form action="" method="post" id="member_form">
	<input type="hidden" name="_process" value="save_member" />
	<input type="hidden" name="member_id" value="<?php 
echo $member_id;
?>
" />

    <?php 
module_form::set_required(array('fields' => array('first_name' => 'Name', 'email' => 'Email')));
module_form::prevent_exit(array('valid_exits' => array('.submit_button', '.submit_small')));
hook_handle_callback('layout_column_half', 1);
$fieldset_data = array('heading' => array('type' => 'h3', 'title' => 'Member Information'), 'class' => 'tableclass tableclass_form tableclass_full', 'elements' => array(array('title' => _l('First Name'), 'field' => array('name' => 'first_name', 'type' => 'text', 'value' => $member['first_name'])), array('title' => _l('Last Name'), 'field' => array('name' => 'last_name', 'type' => 'text', 'value' => $member['last_name'])), array('title' => _l('Business Name'), 'field' => array('name' => 'business', 'type' => 'text', 'value' => $member['business'])), array('title' => _l('Email'), 'field' => array('name' => 'email', 'type' => 'text', 'value' => $member['email'])), array('title' => _l('Phone'), 'field' => array('name' => 'phone', 'type' => 'text', 'value' => $member['phone'])), array('title' => _l('Mobile'), 'field' => array('name' => 'mobile', 'type' => 'text', 'value' => $member['mobile'])), array('title' => _l('External'), 'ignore' => !($member_id > 0), 'field' => array('type' => 'html', 'value' => '<a href="' . module_member::link_public_details($member_id) . '" target="_blank">' . _l('Edit Details') . '</a>', 'help' => 'You can send this link to your customer so they can edit their details.'))), 'extra_settings' => array('owner_table' => 'member', 'owner_key' => 'member_id', 'owner_id' => $member_id, 'layout' => 'table_row'));
echo module_form::generate_fieldset($fieldset_data);
if ($member_id && (int) $member_id > 0) {
    hook_handle_callback('member_edit', $member_id);
}
hook_handle_callback('layout_column_half', 2);
if ($member_id && (int) $member_id > 0) {
    if (class_exists('module_group', false)) {
        module_group::display_groups(array('title' => 'Member Groups', 'description' => _l('These are for you to group your members. The member cannot see or change these groups. You can choose members based on these groups.'), 'owner_table' => 'member', 'owner_id' => $member_id, 'view_link' => $module->link_open($member_id)));
        if (class_exists('module_newsletter', false)) {
            module_group::display_groups(array('title' => 'Newsletter', 'description' => _l('The member can choose which of the below subscriptions they would like to receive. The member can see and change these subscriptions themselves. You can choose members based on these subscriptions.'), 'owner_table' => 'newsletter_subscription', 'owner_id' => $member_id));
        }
    }
}
hook_handle_callback('layout_column_half', 'end');
$form_actions = array('class' => 'action_bar action_bar_center', 'elements' => array(array('type' => 'save_button', 'name' => 'butt_save', 'value' => _l('Save')), array('ignore' => !($member_id > 0), 'type' => 'delete_button', 'name' => 'butt_del', 'value' => _l('Delete')), array('type' => 'button', 'name' => 'cancel', 'value' => _l('Cancel'), 'class' => 'submit_button', 'onclick' => "window.location.href='" . $module->link_open(false) . "';")));