/** * rotary_get_announcements_shortcode_html function * * @access public * @param mixed $atts * @return void */ function rotary_get_announcements_shortcode_html($atts) { global $ProjectType; extract(shortcode_atts(array('lookback' => 5, 'lookforward' => 2, 'speakerdate' => null, 'context' => 'shortcode'), $atts, 'announcements')); // Prepare the query arguments to fetch the appropriate comments depending where this is being called from $args = array('order' => 'DESC', 'orderby' => array('post_type', 'comment_date'), 'post_type' => array('rotary-committees', 'rotary_projects'), 'status' => 'approve'); if ($speakerdate) { //if we've passed through a speaker date, then make the lookback relative to this date, and not today $lookbackdate = new DateTime($speakerdate); $lookforwarddate = new DateTime($speakerdate); $today = new DateTime($speakerdate); if ($lookforward >= 0) { $lookforwarddate->add(new DateInterval('P' . $lookforward . 'D')); } else { $lookforwarddate->sub(new DateInterval('P' . abs($lookforward) . 'D')); } $lookbackdate->sub(new DateInterval('P' . $lookback . 'D')); $args['date_query'] = array(array('column' => 'comment_date', array('before' => date_format($lookforwarddate, 'c')), 'inclusive' => true)); } else { //else, make it relative to today. $today = new DateTime(); } // Exclude all announcements that have expired $args['meta_query'] = array(array('key' => 'announcement_expiry_date', 'value' => $today->format('Y-m-d'), 'compare' => '>=')); $announcements = get_comments($args); $announcementsDisplayed = 0; // We can't introduce a second comments form a page where there is already another comments form, so don't allow edits on a committee or project page // where comments are open. Also, don't allow edits on the carousel for simplicity $allowedits = in_array(get_post_type(), array('rotary-committees', 'rotary_projects')) && comments_open() || 'carousel' == $context ? false : true; ob_start(); ?> <div class="<?php echo $context; ?> -announcements"> <?php if ($allowedits) { ?> <?php if (!is_user_logged_in()) { ?> <p><?php echo sprintf(__('Please %s to make an announcement'), wp_loginout(site_url(), false)); ?> </p> <?php } else { /***************** START MAILCHIMP CAMPAIGN CUSTOMIZATION ****************/ if (is_user_logged_in() && current_user_can('create_mailchimp_campaigns')) { $serialized = serialize($announcements); $encoded = base64_encode($serialized); $hash = md5($encoded . 'SecretStringHere'); ?> <div id="announcements-mailchimpcampaign"> <a id="announcements-sendemailtest" class="rotarybutton-largewhite" href="javascript:void" ng-click="saveCampaign()" ><?php echo __('Send Test Email', 'Rotary'); ?> </a> <a id="announcements-sendemailblast" class="rotarybutton-largeblue" href="javascript:void" ng-click="sendCampaign(1)" ><?php echo __('Send Email Blast', 'Rotary'); ?> </a> <input type="hidden" id="announcements-array" value="<?php echo $encoded; ?> " /> <input type="hidden" id="announcements-hash" value="<?php echo $hash; ?> " /> </div> <?php } /***************** END MAILCHIMP CAMPAIGN CUSTOMIZATION ****************/ rotary_project_and_committee_announcement_dropdown(); ?> <div id="new_announcement_div"></div><?php } } ?> <div <?php echo 'carousel' == $context ? 'id="announcements-carousel"' : ''; ?> class="announcements-container"> <?php rotary_next_program_date(); if (is_array($announcements)) { $count = count($announcements); if ($count > 0) { foreach ($announcements as $announcement) { $extra_classes = ''; $announcementsDisplayed++; if ($announcement) { include get_template_directory() . '/loop-single-announcement.php'; } } //end comment loop } } //end is_array check if (0 == $announcementsDisplayed && !$speakerdate) { ?> <p><?php echo __('There are no active announcements'); ?> </p> <?php } ?> </div> </div> <?php return ob_get_clean(); }
function nm_front_camp() { $saved_options = get_option('nm_mc_front_save_settings'); global $nm_mailchimp; global $current_user; get_currentuserinfo(); $campaigntype = $_REQUEST['campaigntype']; $type = 'regular'; $options = array(); $options['list_id'] = $saved_options['list_id']; $options['from_email'] = $current_user->user_email; $options['from_name'] = $current_user->user_firstname . ' ' . $current_user->user_lastname . ' [' . get_option('blogname') . ']'; $options['generate_text'] = $saved_options['generate_text'] == 'true' ? true : false; $encoded = $_REQUEST['announcements']; $hash = md5($encoded . 'SecretStringHere'); if ($_REQUEST['hash'] == $hash) { // the data hasn't been messed with $announcements = unserialize(base64_decode($encoded)); } else { echo ' submitted hash was: ' . $_REQUEST['hash'] . '. Recalculated hash was: ' . $hash . '<br><br>Actual string was <br>' . $encoded; } if ($campaigntype == 'speaker') { $post_title = get_the_title($_REQUEST['postid']); $post_title = str_replace('’', '\'', str_replace('–', ' - ', str_replace('&', '&', str_replace('’', '\'', str_replace('“', '', str_replace('”', '', $post_title)))))); $date = DateTime::createFromFormat('Ymd', get_field('speaker_date', $_REQUEST['postid'])); $speaker = get_field('speaker_first_name', $_REQUEST['postid']) . ' ' . get_field('speaker_last_name', $_REQUEST['postid']); $options['subject'] = substr(sprintf(__('Program %s : '), $date->format('l M jS')) . ' - "' . substr($post_title, 0, 50) . (strlen($post_title) > 50 ? '...' : '') . '" by ' . substr($speaker, 0, 20), 0, 99); $options['auto_tweet'] = $saved_options['auto_tweet'] == 'true' ? true : false; $options['auto_fb_post'] = explode(',', $saved_options['auto_post']); } elseif ($campaigntype == 'announcements') { $date = rotary_next_program_date(); // there is a default of 2 days grace before the next meeting is used as the week-of $heading = sprintf(__('Club Announcements for %s'), $date->format('l M jS')); //Club Announcements for Friday Nov 6th $options['subject'] = $heading . ' - ' . get_option('blogname'); $options['auto_tweet'] = false; $options['auto_fb_post'] = ''; } ob_start(); include $campaigntype . '_table.php'; //this does the work $post_html = ob_get_clean(); $html_inline_css = $nm_mailchimp->mc->helper->inlineCss($post_html); $content = array('html' => stripcslashes($html_inline_css['html']), 'text' => stripcslashes($html_inline_css['html'])); $resp = $nm_mailchimp->mc->campaigns->create($type, $options, $content); if (isset($resp['id'])) { if ($_REQUEST['sendtype'] == 'test') { $r = $nm_mailchimp->mc->campaigns->sendTest($resp['id'], array($current_user->user_email)); if ($r['complete']) { echo 'Test Campaign Sent to ' . $current_user->user_email; } else { echo 'Error'; } } if ($_REQUEST['sendtype'] == 'send') { $r = $nm_mailchimp->mc->campaigns->send($resp['id']); if ($r['complete']) { echo 'Campaign Sent!'; } else { echo 'Error'; } } } else { echo $resp; } die(0); }