function ninja_annc_check($id, $widget = false, $group = false, $before_title = false, $after_title = false) { global $current_user, $post; //Setup our variables $plugin_settings = get_option('ninja_annc_settings'); $display = true; //Initially, we assume that this announcement will be displayed. $this_post = get_post($id, ARRAY_A); $content = $this_post['post_content']; $title = $this_post['post_title']; $current_time = current_time('timestamp'); if ($group) { $meta = $plugin_settings['groups'][$group]; $active = $meta['active']; $cookie_name = 'ninja_annc_group_close_' . $group; } else { $meta = get_post_meta($id, '_ninja_annc_meta', true); if ($this_post['post_status'] == 'publish') { $active = 1; } else { $active = 0; } if (NINJA_ANNC_TYPE == 'Pro') { //Begin Group Override Check if (ninja_annc_group_override_check($id)) { $display = false; } //End Group Override Check } $cookie_name = 'ninja_annc_close_' . $id; } if ($active != 1) { $display = false; } if (isset($meta['ignore_dates'])) { $ignore_dates = $meta['ignore_dates']; } else { $ignore_dates = ''; } if (isset($meta['location'])) { $location = $meta['location']; } else { $location = ''; } if (isset($meta['show_title'])) { $show_title = $meta['show_title']; } else { $show_title = ''; } if (isset($meta['begin_date'])) { $begin_date = $meta['begin_date'] . " " . $meta['begin_hr'] . ":" . $meta['begin_min'] . " " . $meta['begin_ampm']; } else { $begin_date = ''; } if (isset($meta['end_date'])) { $end_date = $meta['end_date'] . " " . $meta['end_hr'] . ":" . $meta['end_min'] . " " . $meta['end_ampm']; } else { $end_date = ''; } if (isset($meta['display_to'])) { $display_to = $meta['display_to']; } else { $display_to = ''; } if (isset($meta['display_post'])) { $display_post = $meta['display_post']; } else { $display_post = ''; } if (isset($meta['post_attach'])) { $post_attach = $meta['post_attach']; } else { $post_attach = ''; } if (isset($meta['display_page'])) { $display_page = $meta['display_page']; } else { $display_page = ''; } if (isset($meta['page_attach'])) { $page_attach = $meta['page_attach']; } else { $page_attach = ''; } if (isset($meta['display_cat'])) { $display_cat = $meta['display_cat']; } else { $display_cat = ''; } if (isset($meta['display_main'])) { $display_main = $meta['display_main']; } else { $display_main = ''; } if (isset($meta['display_front'])) { $display_front = $meta['display_front']; } else { $display_front = ''; } if (isset($meta['advanced_post'])) { $advanced_post = $meta['advanced_post']; } else { $advanced_post = ''; } if (isset($meta['display_on_posts'])) { $display_on_posts = $meta['display_on_posts']; } else { $display_on_posts = 1; } if (isset($meta['advanced_page'])) { $advanced_page = $meta['advanced_page']; } else { $advanced_page = ''; } if (isset($meta['display_on_pages'])) { $display_on_pages = $meta['display_on_pages']; } else { $display_on_pages = 1; } if (isset($meta['advanced_cat'])) { $advanced_cat = $meta['advanced_cat']; } else { $advanced_cat = ''; } if (isset($_SESSION[$cookie_name])) { $session_close = $_SESSION[$cookie_name]; } else { $session_close = ''; } if (isset($_COOKIE[$cookie_name])) { $cookie_close = $_COOKIE[$cookie_name]; } else { $cookie_close = ''; } if (isset($meta['show_close'])) { $show_close = $meta['show_close']; } else { $show_close = ''; } if (isset($meta['show_open'])) { $show_open = $meta['show_open']; } else { $show_open = ''; } if (isset($meta['closed_time'])) { $closed_time = $meta['closed_time']; } else { $closed_time = ''; } //Begin day of the week test. $days_of_the_week = array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'); $day = date("D", $current_time); $required_days = ''; foreach ($days_of_the_week as $d) { if ($meta[$d] == 1) { $required_days .= $d; } } if (strpos($required_days, $day) !== false) { $show_day = true; } else { $show_day = false; } if (!$show_day) { $display = false; } //End day of the week test. // Begin Date Requirement Section $begin_date = strtotime($begin_date); $end_date = strtotime($end_date); $today = $current_time; if ($begin_date < $today and $end_date >= $today or $ignore_dates == 1) { //If these are true, we've passed the Date Section. //$display = true; //set our display variable to true. } else { $display = false; //set our display variable to false. } //End Date Requirement Section //Begin User Requirements Section get_currentuserinfo(); $user_id = $current_user->ID; //See if we have a user id. switch ($display_to) { case "all": //The "All visitors" option. //$display = true; break; case "not_logged_in": if ($user_id) { //If we have a user_id, then someone is logged in. $display = false; } else { //$display = true; } break; case "logged_in": //Only logged-in users should see the announcement if ($user_id) { //$display = true; } else { $display = false; } break; case "administrator": //Only administrators should see the announcement if (current_user_can('administrator')) { //$display = true; } else { $display = false; } break; case "author": //Only authors should see the announcement if (current_user_can('author')) { //$display = true; } else { $display = false; } break; case "contributor": //Only contributors should see the announcement if (current_user_can('contributor')) { //$display = true; } else { $display = false; } break; case "editor": //Only editors should see the announcement if (current_user_can('editor')) { //$display = true; } else { $display = false; } break; case "subscriber": //Only subscribers should see the announcement if (current_user_can('subscriber')) { //$display = true; } else { $display = false; } break; } //End User Requirements Section //Begin Main Page (Homepage) display section if ($display_main != 1 and is_home()) { $display = false; } if ($display_front != 1 and is_front_page()) { $display = false; } //End Main Page (Homepage) display section //Begin cookie and session variable section. if (($session_close == 'closed' or $cookie_close == 'closed') and $show_close == 1 and $show_open != 1) { $display = false; } //End cookie and session variable section. //Begin Post/Page/Cat Display Section if ($post_attach != '') { $post_found = false; $post_attach_array = explode(",", $post_attach); $post_found = false; foreach ($post_attach_array as $post_id) { if (is_single($post_id)) { $post_found = true; break; } } } if ($page_attach != '') { $page_found = false; $page_attach_array = explode(",", $page_attach); $page_found = false; foreach ($page_attach_array as $page_id) { if (is_page($page_id)) { $page_found = true; break; } } } $categories = ''; $args = array('type' => 'post', 'child_of' => 0, 'parent' => '', 'orderby' => 'name', 'order' => 'ASC', 'hide_empty' => 0, 'hierarchical' => 1, 'exclude' => '', 'include' => '', 'number' => '', 'taxonomy' => 'category', 'pad_counts' => false); $cats = get_categories($args); foreach ($cats as $cat) { if (isset($meta['cat_' . $cat->slug]) and $meta['cat_' . $cat->slug] == 1) { $categories[] = $cat->cat_ID; } } if ($categories != '') { $cat_found = false; if (is_single() or is_page()) { $current_cats = get_the_category($post->ID); foreach ($current_cats as $cat) { if (in_array($cat->term_id, $categories)) { $cat_found = true; break; } } } } if ($display_on_posts != 1 and is_single()) { $display = false; } if ($display_on_pages != 1 and is_page()) { $display = false; } if ($advanced_cat == 1 and is_single()) { if ($display_cat == 'cat_only') { if (!$cat_found) { $display = false; } } elseif ($display_cat == 'cat_exclude') { if ($cat_found) { $display = false; } } } if (is_single() and $advanced_post == 1 and $post_attach != '') { if ($display_post == 'post_only' and !$post_found) { $display = false; } elseif ($display_post == 'post_exclude' and $post_found) { $display = false; } } if (is_page() and $advanced_page == 1 and $page_attach != '') { if ($display_page == 'page_only' and !$page_found) { $display = false; } elseif ($display_page == 'page_exclude' and $page_found) { $display = false; } } if ($display) { return ninja_annc_output_display($id, $widget, $group, $before_title, $after_title); } }
/** @see WP_Widget::form */ function form($instance) { $args = array('post_type' => 'ninja_annc', 'numberposts' => -1, 'post_status' => array('draft', 'publish')); $announcements = get_posts($args); $annc = array(); $x = 0; foreach ($announcements as $post) { $meta = get_post_meta($post->ID, '_ninja_annc_meta', true); $location = $meta['location']; if ($location == 'widget' and !ninja_annc_group_override_check($post->ID)) { $annc[$x]['title'] = $post->post_title; $annc[$x]['id'] = $post->ID; $x++; } } if ($instance) { $title = esc_attr($instance['title']); $annc_id = $instance['annc_id']; $annc_post = get_post($annc_id, ARRAY_A); $title = $annc_post['post_title']; $post_status = $annc_post['post_status']; $meta = get_post_meta($annc_id, '_ninja_annc_meta', true); $ignore_dates = $meta['ignore_dates']; if ($ignore_dates == 1) { $disabled = 'disabled'; } else { $disabled = ''; } if (isset($meta['begin_date'])) { $begin_date = $meta['begin_date']; } else { $begin_date = ''; } if (isset($meta['begin_hr'])) { $begin_hr = $meta['begin_hr']; } else { $begin_hr = ''; } if (isset($meta['begin_min'])) { $begin_min = $meta['begin_min']; } else { $begin_min = ''; } if (isset($meta['begin_ampm'])) { $begin_ampm = $meta['begin_ampm']; } else { $begin_ampm = ''; } if (isset($meta['end_date'])) { $end_date = $meta['end_date']; } else { $end_date = ''; } if (isset($meta['end_hr'])) { $end_hr = $meta['end_hr']; } else { $end_hr = ''; } if (isset($meta['end_min'])) { $end_min = $meta['end_min']; } else { $end_min = ''; } if (isset($meta['end_ampm'])) { $end_ampm = $meta['end_ampm']; } else { $end_ampm = ''; } } else { $post_status = ''; $ignore_dates = ''; $disabled = ''; $begin_date = ''; $begin_hr = ''; $begin_min = ''; $begin_ampm = ''; $end_date = ''; $end_hr = ''; $end_min = ''; $end_ampm = ''; $title = __('New title', 'ninja-announcements'); $annc_id = "NEW"; } ?> <input id="<?php echo $this->get_field_id('title'); ?> " name="<?php echo $this->get_field_name('title'); ?> " type="hidden" value="<?php echo $title; ?> " /> <p> <label for=""><?php _e('Announcement:', 'ninja-announcements'); ?> </label> <select id="<?php echo $this->get_field_id('annc_id'); ?> " name="<?php echo $this->get_field_name('annc_id'); ?> " class="ninja-annc-widget-select"> <option value="" selected>--<?php _e('Select an announcement', 'ninja-announcements'); ?> </option> <?php foreach ($annc as $a) { if ($a['title'] != '') { ?> <option value="<?php echo $a['id']; ?> " <?php if ($annc_id == $a['id']) { echo 'selected'; } ?> ><?php echo $a['title']; ?> </option> <?php } } ?> </select> <div id="<?php echo $this->get_field_id('ninja_annc_loading'); ?> " style="display:none;"><img src="<?php echo NINJA_ANNC_URL; ?> /images/loading.gif"></div> </p> <p> <input type="checkbox" id="<?php echo $this->get_field_id('active'); ?> " name="<?php echo $this->get_field_name('active'); ?> " class="" value="checked" <?php if ($post_status == 'publish') { echo 'checked'; } ?> > <label for="<?php echo $this->get_field_id('active'); ?> "><?php _e('Active', 'ninja-announcements'); ?> </a> </p> <p> <input type="checkbox" id="<?php echo $this->get_field_id('ignore_dates'); ?> " name="<?php echo $this->get_field_name('ignore_dates'); ?> " class="ninja-annc-ignore-dates" value="1" <?php if ($ignore_dates == 1) { echo 'checked'; } ?> > <label for="<?php echo $this->get_field_id('ignore_dates'); ?> "><?php _e('Not Scheduled (Will show whenever active)', 'ninja-announcements'); ?> </a> </p> <p> <label for=""><?php _e('Begin Date:', 'ninja-announcements'); ?> </label> <input type="text" id="<?php echo $this->get_field_id('begin_date'); ?> " name="<?php echo $this->get_field_name('begin_date'); ?> " class="date <?php echo $this->get_field_id('ninja-annc-schedule'); ?> " value="<?php echo $begin_date; ?> " <?php echo $disabled; ?> > </p> <p> <label for=""><?php _e('Begin Time:', 'ninja-announcements'); ?> </label> <select id="<?php echo $this->get_field_id('begin_hr'); ?> " name="<?php echo $this->get_field_name('begin_hr'); ?> " class="<?php echo $this->get_field_id('ninja-annc-schedule'); ?> " <?php echo $disabled; ?> > <option value="1" <?php if ($begin_hr == 1) { echo 'selected'; } ?> >1</option> <option value="2" <?php if ($begin_hr == 2) { echo 'selected'; } ?> >2</option> <option value="3" <?php if ($begin_hr == 3) { echo 'selected'; } ?> >3</option> <option value="4" <?php if ($begin_hr == 4) { echo 'selected'; } ?> >4</option> <option value="5" <?php if ($begin_hr == 5) { echo 'selected'; } ?> >5</option> <option value="6" <?php if ($begin_hr == 6) { echo 'selected'; } ?> >6</option> <option value="7" <?php if ($begin_hr == 7) { echo 'selected'; } ?> >7</option> <option value="8" <?php if ($begin_hr == 8) { echo 'selected'; } ?> >8</option> <option value="9" <?php if ($begin_hr == 9) { echo 'selected'; } ?> >9</option> <option value="10" <?php if ($begin_hr == 10) { echo 'selected'; } ?> >10</option> <option value="11" <?php if ($begin_hr == 11) { echo 'selected'; } ?> >11</option> <option value="12" <?php if ($begin_hr == 12) { echo 'selected'; } ?> >12</option> </select> <select id="<?php echo $this->get_field_id('begin_min'); ?> " name="<?php echo $this->get_field_name('begin_min'); ?> " class="<?php echo $this->get_field_id('ninja-annc-schedule'); ?> " <?php echo $disabled; ?> > <option value="00" <?php if ($begin_min == '00') { echo 'selected'; } ?> >00</option> <option value="05" <?php if ($begin_min == '05') { echo 'selected'; } ?> >05</option> <option value="10" <?php if ($begin_min == '10') { echo 'selected'; } ?> >10</option> <option value="15" <?php if ($begin_min == '15') { echo 'selected'; } ?> >15</option> <option value="20" <?php if ($begin_min == '20') { echo 'selected'; } ?> >20</option> <option value="25" <?php if ($begin_min == '25') { echo 'selected'; } ?> >25</option> <option value="30" <?php if ($begin_min == '30') { echo 'selected'; } ?> >30</option> <option value="35" <?php if ($begin_min == '35') { echo 'selected'; } ?> >35</option> <option value="40" <?php if ($begin_min == '40') { echo 'selected'; } ?> >40</option> <option value="45" <?php if ($begin_min == '45') { echo 'selected'; } ?> >45</option> <option value="50" <?php if ($begin_min == '50') { echo 'selected'; } ?> >50</option> <option value="55" <?php if ($begin_min == '55') { echo 'selected'; } ?> >55</option> </select> <select id="<?php echo $this->get_field_id('begin_ampm'); ?> " name="<?php echo $this->get_field_name('begin_ampm'); ?> " class="<?php echo $this->get_field_id('ninja-annc-schedule'); ?> " <?php echo $disabled; ?> > <option value="am" <?php if ($begin_ampm == 'am') { echo 'selected'; } ?> >am</option> <option value="pm" <?php if ($begin_ampm == 'pm') { echo 'selected'; } ?> >pm</option> </select> </p> <p> <label for=""><?php _e('End Date:', 'ninja-announcements'); ?> </label> <input type="text" id="<?php echo $this->get_field_id('end_date'); ?> " name="<?php echo $this->get_field_name('end_date'); ?> " class="date <?php echo $this->get_field_id('ninja-annc-schedule'); ?> " value="<?php echo $end_date; ?> " <?php echo $disabled; ?> > </p> <p> <label for=""><?php _e('End Time:', 'ninja-announcements'); ?> </label> <select id="<?php echo $this->get_field_id('end_hr'); ?> " name="<?php echo $this->get_field_name('end_hr'); ?> " class="<?php echo $this->get_field_id('ninja-annc-schedule'); ?> " <?php echo $disabled; ?> > <option value="1" <?php if ($end_hr == 1) { echo 'selected'; } ?> >1</option> <option value="2" <?php if ($end_hr == 2) { echo 'selected'; } ?> >2</option> <option value="3" <?php if ($end_hr == 3) { echo 'selected'; } ?> >3</option> <option value="4" <?php if ($end_hr == 4) { echo 'selected'; } ?> >4</option> <option value="5" <?php if ($end_hr == 5) { echo 'selected'; } ?> >5</option> <option value="6" <?php if ($end_hr == 6) { echo 'selected'; } ?> >6</option> <option value="7" <?php if ($end_hr == 7) { echo 'selected'; } ?> >7</option> <option value="8" <?php if ($end_hr == 8) { echo 'selected'; } ?> >8</option> <option value="9" <?php if ($end_hr == 9) { echo 'selected'; } ?> >9</option> <option value="10" <?php if ($end_hr == 10) { echo 'selected'; } ?> >10</option> <option value="11" <?php if ($end_hr == 11) { echo 'selected'; } ?> >11</option> <option value="12" <?php if ($end_hr == 12) { echo 'selected'; } ?> >12</option> </select> <select id="<?php echo $this->get_field_id('end_min'); ?> " name="<?php echo $this->get_field_name('end_min'); ?> " class="<?php echo $this->get_field_id('ninja-annc-schedule'); ?> " <?php echo $disabled; ?> > <option value="00" <?php if ($end_min == '00') { echo 'selected'; } ?> >00</option> <option value="05" <?php if ($end_min == '05') { echo 'selected'; } ?> >05</option> <option value="10" <?php if ($end_min == '10') { echo 'selected'; } ?> >10</option> <option value="15" <?php if ($end_min == '15') { echo 'selected'; } ?> >15</option> <option value="20" <?php if ($end_min == '20') { echo 'selected'; } ?> >20</option> <option value="25" <?php if ($end_min == '25') { echo 'selected'; } ?> >25</option> <option value="30" <?php if ($end_min == '30') { echo 'selected'; } ?> >30</option> <option value="35" <?php if ($end_min == '35') { echo 'selected'; } ?> >35</option> <option value="40" <?php if ($end_min == '40') { echo 'selected'; } ?> >40</option> <option value="45" <?php if ($end_min == '45') { echo 'selected'; } ?> >45</option> <option value="50" <?php if ($end_min == '50') { echo 'selected'; } ?> >50</option> <option value="55" <?php if ($end_min == '55') { echo 'selected'; } ?> >55</option> </select> <select id="<?php echo $this->get_field_id('end_ampm'); ?> " name="<?php echo $this->get_field_name('end_ampm'); ?> " class="<?php echo $this->get_field_id('ninja-annc-schedule'); ?> " <?php echo $disabled; ?> > <option value="am" <?php if ($end_ampm == 'am') { echo 'selected'; } ?> >am</option> <option value="pm" <?php if ($end_ampm == 'pm') { echo 'selected'; } ?> >pm</option> </select> </p> <?php }
function ninja_annc_create_meta($post) { global $post; $meta = get_post_meta($post->ID, '_ninja_annc_meta', true); $plugin_settings = get_option('ninja_annc_settings'); $default_title_wrapper = $plugin_settings['default_title_wrapper']; $default_content_wrapper = $plugin_settings['default_content_wrapper']; if (isset($meta['closed_time']) and $meta['closed_time'] != 'days' or (!isset($meta['closed_time']) or $meta['closed_time'] == '')) { $display_days = 'display:none;'; } else { $display_days = ''; } if (isset($meta['show_close']) and $meta['show_close'] != 1) { $disable_close = "disabled"; } else { $disable_close = ''; } if (isset($meta['Sun']) and $meta['Sun'] == 1 and isset($meta['Mon']) and $meta['Mon'] == 1 and isset($meta['Tue']) and $meta['Tue'] == 1 and isset($meta['Wed']) and $meta['Wed'] == 1 and isset($meta['Thu']) and $meta['Thu'] == 1 and isset($meta['Fri']) and $meta['Fri'] == 1 and isset($meta['Sat']) and $meta['Sat'] == 1) { $select_all_days = 'checked'; } else { $select_all_days = ''; } if (!isset($meta['Sun']) and !isset($meta['Mon']) and !isset($meta['Tue']) and !isset($meta['Wed']) and !isset($meta['Thu']) and !isset($meta['Fri']) and !isset($meta['Sat'])) { $select_all_days = 'checked'; } if (isset($meta['advanced_post']) and $meta['advanced_post'] == 1) { $advanced_post = ''; } else { $advanced_post = 'ninja-annc-hidden'; } if (isset($meta['advanced_page']) and $meta['advanced_page'] == 1) { $advanced_page = ''; } else { $advanced_page = 'ninja-annc-hidden'; } if (isset($meta['advanced_cat']) and $meta['advanced_cat'] == 1) { $advanced_cat = ''; } else { $advanced_cat = 'ninja-annc-hidden'; } $schedule = array('nonce' => array('field' => '_ninja_annc_meta', 'name' => 'nonce', 'default' => '', 'title' => '', 'type' => 'nonce', 'before' => '', 'before_label' => '', 'after_label' => '', 'after' => '', 'class' => ''), 'ignore_dates' => array('field' => '_ninja_annc_meta', 'name' => 'ignore_dates', 'default' => 'checked', 'title' => __('Not Scheduled (Will display whenever active)', 'ninja-announcements'), 'type' => 'checkbox', 'before' => '<h4>', 'before_label' => ' ', 'after_label' => '', 'after' => '</h4>', 'class' => 'ninja-annc-ignore-dates'), 'begin_date' => array('field' => '_ninja_annc_meta', 'name' => 'begin_date', 'default' => '', 'title' => __('Begin Date', 'ninja-announcements'), 'type' => 'text', 'before' => '<table><tr>', 'before_label' => '<td>', 'after_label' => '</td><td>', 'after' => '</td>', 'class' => 'date ninja-annc-schedule'), 'begin_hr' => array('field' => '_ninja_annc_meta', 'name' => 'begin_hr', 'default' => '', 'title' => __('Time ', 'ninja-announcements'), 'type' => 'select', 'before' => '', 'before_label' => '<td>', 'after_label' => '</td><td>', 'after' => '', 'options' => array(array('label' => '1', 'value' => '1'), array('label' => '2', 'value' => '2'), array('label' => '3', 'value' => '3'), array('label' => '4', 'value' => '4'), array('label' => '5', 'value' => '5'), array('label' => '6', 'value' => '6'), array('label' => '7', 'value' => '7'), array('label' => '8', 'value' => '8'), array('label' => '9', 'value' => '9'), array('label' => '10', 'value' => '10'), array('label' => '11', 'value' => '11'), array('label' => '12', 'value' => '12')), 'class' => 'ninja-annc-schedule'), 'begin_min' => array('field' => '_ninja_annc_meta', 'name' => 'begin_min', 'default' => '', 'title' => '', 'type' => 'select', 'before' => '', 'before_label' => '', 'after_label' => '', 'after' => '', 'options' => array(array('label' => '00', 'value' => '00'), array('label' => '05', 'value' => '05'), array('label' => '10', 'value' => '10'), array('label' => '15', 'value' => '15'), array('label' => '20', 'value' => '20'), array('label' => '25', 'value' => '25'), array('label' => '30', 'value' => '30'), array('label' => '35', 'value' => '35'), array('label' => '40', 'value' => '40'), array('label' => '45', 'value' => '45'), array('label' => '50', 'value' => '50'), array('label' => '55', 'value' => '55')), 'class' => 'ninja-annc-schedule'), 'begin_ampm' => array('field' => '_ninja_annc_meta', 'name' => 'begin_ampm', 'default' => '', 'title' => '', 'type' => 'select', 'before' => '', 'before_label' => '', 'after_label' => '', 'after' => '</td></tr>', 'options' => array(array('label' => 'am', 'value' => 'am'), array('label' => 'pm', 'value' => 'pm')), 'class' => 'ninja-annc-schedule'), 'end_date' => array('field' => '_ninja_annc_meta', 'name' => 'end_date', 'default' => '', 'title' => __('End Date', 'ninja-announcements'), 'type' => 'text', 'before' => '<tr>', 'before_label' => '<td>', 'after_label' => '</td><td>', 'after' => '</td>', 'class' => 'date ninja-annc-schedule'), 'end_hr' => array('field' => '_ninja_annc_meta', 'name' => 'end_hr', 'default' => '', 'title' => __('Time', 'ninja-announcements'), 'type' => 'select', 'before' => '', 'before_label' => '<td>', 'after_label' => '</td><td>', 'after' => '', 'options' => array(array('label' => '1', 'value' => '1'), array('label' => '2', 'value' => '2'), array('label' => '3', 'value' => '3'), array('label' => '4', 'value' => '4'), array('label' => '5', 'value' => '5'), array('label' => '6', 'value' => '6'), array('label' => '7', 'value' => '7'), array('label' => '8', 'value' => '8'), array('label' => '9', 'value' => '9'), array('label' => '10', 'value' => '10'), array('label' => '11', 'value' => '11'), array('label' => '12', 'value' => '12')), 'class' => 'ninja-annc-schedule'), 'end_min' => array('field' => '_ninja_annc_meta', 'name' => 'end_min', 'default' => '', 'title' => '', 'type' => 'select', 'before' => '', 'before_label' => '', 'after_label' => '', 'after' => '', 'options' => array(array('label' => '00', 'value' => '00'), array('label' => '05', 'value' => '05'), array('label' => '10', 'value' => '10'), array('label' => '15', 'value' => '15'), array('label' => '20', 'value' => '20'), array('label' => '25', 'value' => '25'), array('label' => '30', 'value' => '30'), array('label' => '35', 'value' => '35'), array('label' => '40', 'value' => '40'), array('label' => '45', 'value' => '45'), array('label' => '50', 'value' => '50'), array('label' => '55', 'value' => '55')), 'class' => 'ninja-annc-schedule'), 'end_ampm' => array('field' => '_ninja_annc_meta', 'name' => 'end_ampm', 'default' => '', 'title' => '', 'type' => 'select', 'before' => '', 'before_label' => '', 'after_label' => '', 'after' => '</td></tr></table>', 'options' => array(array('label' => 'am', 'value' => 'am'), array('label' => 'pm', 'value' => 'pm')), 'class' => 'ninja-annc-schedule'), 'select_all_days' => array('field' => '', 'name' => 'select_all_days', 'default' => $select_all_days, 'title' => __('Select All', 'ninja-announcements'), 'type' => 'checkbox', 'before' => '<h4>' . __('Days of the week', 'ninja-announcements') . ' ', 'before_label' => ' ', 'after_label' => '', 'after' => '</h4>', 'class' => ''), 'Sun' => array('field' => '_ninja_annc_meta', 'name' => 'Sun', 'title' => __('Sunday', 'ninja-announcements'), 'type' => 'checkbox', 'before' => '', 'before_label' => ' ', 'after_label' => '', 'after' => ' ', 'default' => 'checked', 'class' => 'ninja-day'), 'Mon' => array('field' => '_ninja_annc_meta', 'name' => 'Mon', 'title' => __('Monday', 'ninja-announcements'), 'type' => 'checkbox', 'before' => '', 'before_label' => ' ', 'after_label' => '', 'after' => ' ', 'default' => 'checked', 'class' => 'ninja-day '), 'Tue' => array('field' => '_ninja_annc_meta', 'name' => 'Tue', 'title' => __('Tuesday', 'ninja-announcements'), 'type' => 'checkbox', 'before_label' => ' ', 'after_label' => '', 'after' => ' ', 'default' => 'checked', 'class' => 'ninja-day'), 'Wed' => array('field' => '_ninja_annc_meta', 'name' => 'Wed', 'title' => __('Wednsday', 'ninja-announcements'), 'type' => 'checkbox', 'before' => '', 'before_label' => ' ', 'after_label' => '', 'after' => ' ', 'default' => 'checked', 'class' => 'ninja-day'), 'Thu' => array('field' => '_ninja_annc_meta', 'name' => 'Thu', 'title' => __('Thursday', 'ninja-announcements'), 'type' => 'checkbox', 'before_label' => ' ', 'after_label' => '', 'after' => ' ', 'default' => 'checked', 'class' => 'ninja-day'), 'Fri' => array('field' => '_ninja_annc_meta', 'name' => 'Fri', 'title' => __('Friday', 'ninja-announcements'), 'type' => 'checkbox', 'before' => '', 'before_label' => ' ', 'after_label' => '', 'after' => ' ', 'default' => 'checked', 'class' => 'ninja-day'), 'Sat' => array('field' => '_ninja_annc_meta', 'name' => 'Sat', 'title' => __('Saturday', 'ninja-announcements'), 'type' => 'checkbox', 'before_label' => ' ', 'after_label' => '', 'after' => ' ', 'default' => 'checked', 'class' => 'ninja-day')); $annc_options = array('show_title' => array('field' => '_ninja_annc_meta', 'name' => 'show_title', 'default' => 'checked', 'title' => __('Show Title', 'ninja-announcements'), 'type' => 'checkbox', 'before' => '', 'before_label' => ' ', 'after_label' => '', 'after' => ''), 'location' => array('field' => '_ninja_annc_meta', 'name' => 'location', 'default' => '', 'title' => __('Location', 'ninja-announcements'), 'type' => 'select', 'before' => '<p>', 'before_label' => '', 'after_label' => ' ', 'after' => '</p>', 'options' => array(array('label' => __('Header (Default)', 'ninja-announcements'), 'value' => 'default'), array('label' => __('Sidebar (Widget)', 'ninja-announcements'), 'value' => 'widget'), array('label' => __('Manual (Function)', 'ninja-announcements'), 'value' => 'function')))); if (NINJA_ANNC_TYPE == 'Pro') { require_once NINJA_ANNC_DIR . "/includes/pro/meta-boxes-1.php"; } $annc_options['show_close'] = array('field' => '_ninja_annc_meta', 'name' => 'show_close', 'default' => 'checked', 'title' => __('Allow the user to close the announcement', 'ninja-announcements'), 'type' => 'checkbox', 'before' => '<p>', 'before_label' => ' ', 'after_label' => '', 'after' => '</p>'); $annc_options['show_open'] = array('field' => '_ninja_annc_meta', 'name' => 'show_open', 'default' => 'checked', 'title' => __('Allow the announcement to be re-opened', 'ninja-announcements'), 'type' => 'checkbox', 'before' => '<p>', 'before_label' => ' ', 'after_label' => '', 'after' => '</p>', 'class' => 'ninja-annc-close-setting', 'disabled' => $disable_close); if (NINJA_ANNC_TYPE == 'Pro') { require_once NINJA_ANNC_DIR . "/includes/pro/meta-boxes-2.php"; } $display_options = array('display_main' => array('field' => '_ninja_annc_meta', 'name' => 'display_main', 'default' => 'checked', 'title' => __('Display on your Homepage', 'ninja-announcements'), 'type' => 'checkbox', 'before' => '<p>', 'before_label' => ' ', 'after_label' => '', 'after' => '</p>', 'class' => ''), 'display_front' => array('field' => '_ninja_annc_meta', 'name' => 'display_front', 'default' => 'checked', 'title' => __('Display on your Frontpage', 'ninja-announcements'), 'type' => 'checkbox', 'before' => '<p>', 'before_label' => ' ', 'after_label' => '', 'after' => '</p>', 'class' => '')); $no_options = array('no_options' => array('field' => '_ninja_annc_meta', 'name' => 'no_options', 'default' => '', 'title' => __('This announcement\'s settings are being controlled by one of its groups. Please remove this announcement from the controlling group, or visit the group edit page to change its settings.', 'ninja-announcements'), 'type' => 'desc', 'before' => '<h4>', 'before_label' => '', 'after_label' => '', 'after' => '</h4>')); if (NINJA_ANNC_TYPE == 'Pro') { if (ninja_annc_group_override_check($post->ID)) { add_meta_box('ninja_annc_options', __('Announcement Options', 'ninja-announcements'), 'ninja_annc_display_meta', 'ninja_annc', 'normal', 'core', $no_options); } else { if (function_exists('add_meta_box')) { add_meta_box('ninja_annc_schedule', __('Announcement Schedule', 'ninja-announcements'), 'ninja_annc_display_meta', 'ninja_annc', 'normal', 'core', $schedule); add_meta_box('ninja_annc_options', __('Announcement Options', 'ninja-announcements'), 'ninja_annc_display_meta', 'ninja_annc', 'normal', 'core', $annc_options); add_meta_box('ninja_annc_display', __('Main Page Display Options', 'ninja-announcements'), 'ninja_annc_display_meta', 'ninja_annc', 'normal', 'core', $display_options); require_once NINJA_ANNC_DIR . "/includes/pro/meta-boxes-3.php"; } } } else { if (function_exists('add_meta_box')) { add_meta_box('ninja_annc_schedule', __('Announcement Schedule', 'ninja-announcements'), 'ninja_annc_display_meta', 'ninja_annc', 'normal', 'core', $schedule); add_meta_box('ninja_annc_options', __('Announcement Options', 'ninja-announcements'), 'ninja_annc_display_meta', 'ninja_annc', 'normal', 'core', $annc_options); add_meta_box('ninja_annc_display', __('Main Page Display Options', 'ninja-announcements'), 'ninja_annc_display_meta', 'ninja_annc', 'normal', 'core', $display_options); } } }
function ninja_annc_custom_columns($column) { global $post; $meta = get_post_meta($post->ID, '_ninja_annc_meta', true); if (isset($meta['ignore_dates']) and $meta['ignore_dates'] == 1) { $dates = __('Not Scheduled (Will show whenever active)', 'ninja-announcements'); } else { if (isset($meta['begin_date'])) { $begin_date = $meta['begin_date']; } else { $begin_date = ''; } if (isset($meta['end_date'])) { $end_date = $meta['end_date']; } else { $end_date = ''; } $dates = $begin_date . " - " . $end_date; } if (NINJA_ANNC_TYPE == 'Pro') { if (ninja_annc_group_override_check($post->ID)) { $dates = __('Announcement controlled via group settings', 'ninja-announcements'); } } switch ($column) { case 'ID': echo $post->ID; //displays title break; case 'action': if ($post->post_status == 'draft') { echo '<a href="#" class="ninja-annc-activate" id="ninja_annc_' . $post->ID . '">'; _e('Activate', 'ninja-announcements'); echo '</a>'; } else { echo '<a href="#" class="ninja-annc-deactivate" id="ninja_annc_' . $post->ID . '">'; _e('Deactivate', 'ninja-announcements'); echo '</a>'; } break; case 'content': $content = $post->post_content; $content = strip_tags($content); $content = substr($content, 0, 150); echo $content; //displays the content excerpt break; case 'dates': echo $dates; break; case 'groups': $terms = wp_get_post_terms($post->ID, 'ninja_annc_groups'); if ($terms) { $x = 0; foreach ($terms as $term) { $url = admin_url('edit-tags.php?action=edit&taxonomy=ninja_annc_groups&tag_ID=' . $term->term_id . '&post_type=ninja_annc'); if ($x == 0) { echo '<a href="' . $url . '">' . $term->name . '</a>'; } else { echo ', <a href="' . $url . '">' . $term->name . '</a>'; } $x++; } } break; case 'function': echo '<?php if (function_exists("ninja_annc_display")) { ninja_annc_display(' . $post->ID . '); } ?>'; break; } }
function ninja_annc_close() { $id = esc_html($_REQUEST['annc_id']); //$group_id = esc_html($_REQUEST['group_id']); $group_id = ninja_annc_group_override_check($id); if ($group_id) { $plugin_settings = get_option('ninja_annc_settings'); $meta = $plugin_settings['groups'][$group_id]; $cookie_name = 'ninja_annc_group_close_' . $group_id; } else { $meta = get_post_meta($id, '_ninja_annc_meta', true); $cookie_name = 'ninja_annc_close_' . $id; } if (isset($meta['closed_time'])) { $closed_time = $meta['closed_time']; } else { $closed_time = 'session'; } if (session_id() == '') { session_start(); } $_SESSION[$cookie_name] = 'closed'; switch ($closed_time) { case "session": setcookie($cookie_name, "", time() - 3600, "/"); break; case "days": $days = $meta['closed_days']; $expires = time() + 60 * 60 * 24 * $days; setcookie($cookie_name, 'closed', $expires, "/"); break; case "forever": $expires = time() + 60 * 60 * 24 * 999; setcookie($cookie_name, 'closed', $expires, "/"); break; } die; }