/** * Install plugin */ function postplanner_activation() { global $wp_version; $exit_msg = esc_html__('Post Planner requires WordPress 3.3 or newer. <a href="http://codex.wordpress.org/Upgrading_WordPress">Please update.</a>', 'post-planner'); if (version_compare($wp_version, "3.3", "<")) { exit($exit_msg); } if (!defined('POSTPLANNER_DB_VERSION')) { define('POSTPLANNER_DB_VERSION', '1.4'); } if (!defined('POSTPLANNER_FILE')) { define('POSTPLANNER_FILE', __FILE__); } include_once 'includes/post-planner-library.class.php'; if (get_option('PostPlanner_db_version')) { $installed_ver = get_option('PostPlanner_db_version'); } else { $installed_ver = 0; } // if the installed version is not the same as the current version, run the install function if (POSTPLANNER_DB_VERSION != $installed_ver) { PostPlanner_Lib::install_plugin($installed_ver); } }
<?php $permission = CTDL_Lib::check_permission('todo', 'add'); if ($permission == true) { echo '<p> <a class="button-secondary floatright" href="' . admin_url('/admin.php?page=cleverness-to-do-list&planner=' . absint($planner_id)) . '#addtodo">' . apply_filters('post_planner_add_todo', esc_html__('Add New To-Do Item', 'post-planner')) . ' »</a></p>'; echo '<div class="clear"></div>'; } ?> <?php if ($show_completed == 1) { ?> <ul id="post-planner-todolist-completed"> <?php $todo_items = PostPlanner_Lib::get_todos($planner_id, $user, -1, 1); if ($todo_items->have_posts()) { while ($todo_items->have_posts()) { $todo_items->the_post(); $pp_todo_id = get_the_ID(); ?> <li class="post-planner-todolist-item" id="todo-<?php echo esc_attr($pp_todo_id); ?> "> <input type="checkbox" id="<?php echo esc_attr($pp_todo_id); ?> " name="<?php echo esc_attr($pp_todo_id); ?>
/** * Localize JS variables * @static * @return array * @since 1.0 */ public static function get_js_vars() { return array('VIEW_POST' => esc_attr__('View', 'post-planner'), 'ASSOC_DASHBOARD_ERROR_MSG' => esc_attr__('Error', 'post-planner'), 'CREATE_POST' => esc_attr__('Create', 'post-planner'), 'CHECKLIST_ERROR_MSG' => esc_attr__('Unable to update checklist', 'post-planner'), 'EDIT' => esc_attr__('edit', 'post-planner'), 'POSTED_BY' => esc_attr__('posted by', 'post-planner'), 'COMMENT_ERROR_MSG' => esc_attr__('Unable to add comment', 'post-planner'), 'ASSOC_SUCCESS_MSG' => esc_attr__('Association Successful', 'post-planner'), 'ASSOC_ERROR_MSG' => esc_attr__('Association Unsuccessful', 'post-planner'), 'ASSOC_DUPLICATE_MSG' => esc_attr__('Associated with Another Planner', 'post-planner'), 'ASSOC_ALREADY_MSG' => esc_attr__('Planner Already Associated with an Entry', 'post-planner'), 'ASSOC_REMOVED_MSG' => esc_attr__('Association Removed', 'post-planner'), 'ASSOC_NOT_REMOVED_MSG' => esc_attr__('Unable to Remove Association', 'post-planner'), 'ASSOC_CREATED_MSG' => esc_attr__('Associated Content Created', 'post-planner'), 'ASSOC_NOT_CREATED_MSG' => esc_attr__('Unable to Create Associated Content', 'post-planner'), 'CREATE_CONFIRMATION_MSG' => esc_html__("Are you sure you want to create a new entry based on this Planner? \n 'Cancel' to stop, 'OK' to continue.", 'post-planner'), 'CONFIRMATION_MSG' => esc_html__("Are you sure you want to associate this Planner? \n 'Cancel' to stop, 'OK' to continue.", 'post-planner'), 'REMOVE_CONFIRMATION_MSG' => esc_html__("Are you sure you want to remove this association? \n 'Cancel' to stop, 'OK' to continue.", 'post-planner'), 'DATE_FORMAT' => PostPlanner_Lib::dateFormatTojQueryUIDatePickerFormat(PostPlanner_Loader::$settings['date_format']), 'NONCE' => wp_create_nonce('postplanner'), 'AJAX_URL' => admin_url('admin-ajax.php'), 'ADMIN_URL' => admin_url()); }
" class="post-planner-assignment"> <option value="-1"<?php echo $mb->the_select_state(-1); ?> ><?php esc_attr_e('None', 'post-planner'); ?> </option> <?php if (PostPlanner_Loader::$settings['user_roles'] == '') { $roles = array('contributor', 'author', 'editor', 'administrator'); } else { $roles = explode(',', PostPlanner_Loader::$settings['user_roles']); } foreach ($roles as $role) { $role_users = PostPlanner_Lib::get_users($role); foreach ($role_users as $role_user) { $user_info = get_userdata($role_user->ID); ?> <option value="<?php echo absint($role_user->ID); ?> "<?php echo $mb->the_select_state($role_user->ID); ?> ><?php echo sanitize_text_field($user_info->display_name); ?> </option> <?php }
/** * Shows the planners * @param $planner_items * @return array */ protected function show_planner_list_items($planner_items) { $items = ''; while ($planner_items->have_posts()) { $planner_items->the_post(); $id = get_the_ID(); list($assign_meta, $duedate_meta, $status_meta, $associated_meta, $planner_post_type) = PostPlanner_Lib::get_planner_meta($id); $status_bg = esc_attr(PostPlanner_Loader::$statuses[$status_meta]['color']); $items .= '<tr' . ($status_bg != '' ? ' style="background-color: ' . $status_bg . '">' : '>'); $items .= apply_filters('post_planner_dashboard_topic', '<td class="post-planner-dashboard-topic"><a href="' . admin_url('post.php?post=' . $id . '&action=edit') . '">' . get_the_title() . '</a></td>', $id, get_the_title()); $items .= apply_filters('post_planner_dashboard_status', '<td>' . sanitize_text_field(PostPlanner_Loader::$statuses[$status_meta]['name']) . '</td>', PostPlanner_Loader::$statuses[$status_meta]['name']); if (PostPlanner_Loader::$settings['assignments'] == 1) { if ($assign_meta == -1 || $assign_meta == 0) { $assignment = esc_html__('Unassigned', 'post-planner'); } else { $assign_user = get_userdata($assign_meta); $assignment = sanitize_text_field($assign_user->display_name); } $items .= apply_filters('post_planner_dashboard_assignment', '<td class="post-planner-dashboard-author" id="' . $assign_meta . '">' . $assignment . '</td>', $assign_meta, $assignment); } if (PostPlanner_Loader::$settings['duedate'] == 1) { $items .= apply_filters('post_planner_dashboard_duedate', '<td>' . sanitize_text_field($duedate_meta) . '</td>', $duedate_meta); } do_action('post_planner_dashboard_data'); if ($associated_meta != '') { if (current_user_can('edit_posts')) { $action = '<a href="' . admin_url('post.php?post=' . absint($associated_meta) . '&action=edit') . '">' . esc_html__('View', 'post-planner') . '</a>'; } } else { if (current_user_can('edit_posts')) { $action = '<a href="" class="post-planner-create-post" id="' . absint($id) . '">' . esc_html__('Create', 'post-planner') . '</a>'; } } if (isset($action)) { $items .= apply_filters('post_planner_dashboard_action', '<td><span class="post-planner-post-type">' . $planner_post_type . '</span>' . $action . '</td>', $planner_post_type, $action); } $items .= '</tr>'; } return $items; }
/** * Check if a field should be displayed * @static * * @param $field * * @return bool */ function ctdl_check_field($field) { global $CTDL_widget_settings, $CTDL_category_id; $permission = false; switch ($field) { case 'completed': $permission = CTDL_Loader::$settings['show_completed_date'] == 1 && get_post_meta(get_the_ID(), '_completed', true) != '0000-00-00 00:00:00' ? true : false; break; case 'planner': $permission = CTDL_Loader::$settings['post_planner'] == 1 && get_post_meta(get_the_ID(), '_planner', true) != null && PostPlanner_Lib::planner_exists(get_post_meta(get_the_ID(), '_planner', true)) ? true : false; break; case 'progress': $permission = CTDL_Loader::$settings['show_progress'] == 1 && get_post_meta(get_the_ID(), '_progress', true) != null ? true : false; break; case 'assigned': $data = get_post_meta(get_the_ID(), '_assign', true); $permission = CTDL_Loader::$settings['list_view'] != 0 && CTDL_Loader::$settings['show_only_assigned'] == 0 && current_user_can(CTDL_Loader::$settings['view_all_assigned_capability']) || CTDL_Loader::$settings['list_view'] != 0 && CTDL_Loader::$settings['show_only_assigned'] == 1 && CTDL_Loader::$settings['assign'] == 0 ? true : false; $permission = $permission == true && ($data != 0 && $data != null && $data != '-1' && !(is_array($data) && in_array('-1', $data))) ? true : false; break; case 'dashboard-deadline': $permission = CTDL_Loader::$settings['show_deadline'] == 1 && isset(CTDL_Loader::$dashboard_settings['show_dashboard_deadline']) && CTDL_Loader::$dashboard_settings['show_dashboard_deadline'] == 1 && get_post_meta(get_the_ID(), '_deadline', true) != null ? true : false; break; case 'dashboard-edit': $permission = CTDL_Loader::$dashboard_settings['show_edit_link'] == 1 && (current_user_can(CTDL_Loader::$settings['edit_capability']) || CTDL_Loader::$settings['list_view'] == 0) ? true : false; break; case 'dashboard-author': $permission = CTDL_Loader::$settings['list_view'] == 1 && isset(CTDL_Loader::$dashboard_settings['dashboard_author']) && CTDL_Loader::$dashboard_settings['dashboard_author'] == 0 ? true : false; break; case 'dashboard-category-heading': $data = get_the_terms(get_the_ID(), 'todocategories'); $cat = ''; if ($data != NULL) { foreach ($data as $category) { $cat = $category->term_id; } } $permission = CTDL_Loader::$settings['categories'] == 1 && CTDL_Loader::$settings['sort_order'] == 'cat_id' && (0 == $CTDL_category_id || $cat != $CTDL_category_id) ? true : false; break; case 'dashboard-category': $data = get_the_terms(get_the_ID(), 'todocategories'); $permission = CTDL_Loader::$settings['categories'] == 1 && CTDL_Loader::$settings['sort_order'] != 'cat_id' && $data != NULL ? true : false; break; case 'widget-deadline': $permission = CTDL_Loader::$settings['show_deadline'] == 1 && $CTDL_widget_settings['deadline'] == 1 && get_post_meta(get_the_ID(), '_deadline', true) != null ? true : false; break; case 'widget-progress': $permission = CTDL_Loader::$settings['show_progress'] == 1 && $CTDL_widget_settings['progress'] == 1 && get_post_meta(get_the_ID(), '_progress', true) != null ? true : false; break; case 'widget-assigned': $data = get_post_meta(get_the_ID(), '_assign', true); $permission = CTDL_Loader::$settings['assign'] == 0 && $CTDL_widget_settings['assigned_to'] == 1 && CTDL_Loader::$settings['list_view'] != 0 ? true : false; $permission = $permission == true && ($data != 0 && $data != null && $data != '-1' && !(is_array($data) && in_array('-1', $data))) ? true : false; break; } return $permission; }
<input type="hidden" name="post-planner-post-id" id="post-planner-post-id" value="<?php echo absint($associated_post_id); ?> " /> <input name="post-planner-visit" type="button" class="button-primary" id="post-planner-visit-post" value="<?php esc_attr_e('View Associated', 'post-planner'); ?> <?php echo $planner_post_type_object->labels->singular_name; ?> " /> </div> <?php } else { ?> <p><?php esc_html_e('Associated Post belongs to', 'post-planner'); ?> <?php echo PostPlanner_Lib::get_post_author($associated_post_id); ?> .</p> <?php } ?> <?php do_action('post_planner_after_associated_metabox'); ?> </div>
/** * Show the Post Planner * @param $planner * @since 3.2 */ public function show_planner($planner) { $this->list .= '<td class="todo-planner">'; if ($planner != 0 && PostPlanner_Lib::planner_exists($planner)) { $url = admin_url('post.php?post=' . absint($planner) . '&action=edit'); $this->list .= '<a href="' . esc_url($url) . '">' . get_the_title($planner) . '</a>'; } $this->list .= '</td>'; }
if (PostPlanner_Loader::$settings['references'] == 1) { echo '<li><a href="#tabs-references"> ' . apply_filters('post_planner_references_metabox_title', esc_attr__('References', 'post-planner')) . ' </a></li>'; } if (PostPlanner_Loader::$settings['checklist'] == 1 && implode('', PostPlanner_Loader::$checklist)) { echo '<li><a href="#tabs-checklist"> ' . apply_filters('post_planner_checklist_metabox_title', esc_attr__('Checklist', 'post-planner')) . ' </a></li>'; } if (PP_CTDL == true) { echo '<li><a href="#tabs-todolist"> ' . apply_filters('post_planner_todolist_metabox_title', esc_attr__('To-Do List', 'post-planner')) . ' </a></li>'; } if (PostPlanner_Loader::$settings['comments'] == 1) { echo '<li><a href="#tabs-comments"> ' . apply_filters('post_planner_comments_metabox_title', esc_attr__('Comments', 'post-planner')) . ' </a></li>'; } ?> </ul> <?php if (PostPlanner_Lib::check_for_content($planner_id)) { echo '<div id="tabs-details">'; PostPlanner::display_details($planner_id); echo '</div>'; } if (PostPlanner_Loader::$settings['images'] == 1) { echo '<div id="tabs-images">'; PostPlanner::display_images($planner_id); echo '</div>'; } if (PostPlanner_Loader::$settings['files'] == 1) { echo '<div id="tabs-files">'; PostPlanner::display_files($planner_id); echo '</div>'; } if (PostPlanner_Loader::$settings['references'] == 1) {
/** * Displays a To-Do List * @static * @param $planner_id * @since 1.1 */ public static function display_todolist($planner_id) { global $current_user, $userdata; echo '<div class="post-planner-box">'; do_action('post_planner_before_todolist'); echo '<ul id="post-planner-todolist">'; $user = CTDL_Lib::get_user_id($current_user, $userdata); $todo_items = PostPlanner_Lib::get_todos($planner_id, $user); $show_completed = PostPlanner_Loader::$settings['ctdl_completed']; if ($todo_items->have_posts()) { while ($todo_items->have_posts()) { $todo_items->the_post(); $id = get_the_ID(); ?> <li class="post-planner-todolist-item" id="todo-<?php echo esc_attr($id); ?> "> <input type="checkbox" id="<?php echo esc_attr($id); ?> " name="<?php echo esc_attr($id); ?> " <?php if ($show_completed == 1) { echo 'class="show-completed"'; } ?> value="1" /> <div><?php echo apply_filters('the_content', get_the_content()); do_action('post_planner_todo_meta', $id); ?> </div> </li> <?php } } else { echo apply_filters('post_planner_no_todo_items', esc_html__('There are no items to do.', 'post-planner')); } wp_reset_query(); echo '</ul>'; $permission = CTDL_Lib::check_permission('todo', 'add'); if ($permission == true) { echo '<p><a class="button-secondary floatright" href="' . admin_url('/admin.php?page=cleverness-to-do-list&planner=' . absint($planner_id)) . '#addtodo">' . apply_filters('post_planner_add_todo', esc_html__('Add New To-Do Item', 'post-planner')) . ' »</a></p>'; echo '<div class="clear"></div>'; } if ($show_completed == 1) { ?> <ul id="post-planner-todolist-completed"> <?php $todo_items = PostPlanner_Lib::get_todos($planner_id, $user, -1, 1); if ($todo_items->have_posts()) { while ($todo_items->have_posts()) { $todo_items->the_post(); $pp_todo_id = get_the_ID(); ?> <li class="post-planner-todolist-item" id="todo-<?php echo esc_attr($pp_todo_id); ?> "> <input type="checkbox" id="<?php echo esc_attr($pp_todo_id); ?> " name="<?php echo esc_attr($pp_todo_id); ?> " <?php if ($show_completed == 1) { echo 'class="show-completed"'; } ?> value="0" checked="checked" /> <div><?php echo apply_filters('the_content', get_the_content()); do_action('post_planner_todo_completed_meta', $pp_todo_id); ?> </div> </li> <?php } } else { echo apply_filters('post_planner_no_completed_todo_items', esc_html__('There are no completed items.', 'post-planner')); } wp_reset_query(); ?> </ul> <?php } do_action('post_planner_after_todolist'); echo '</div>'; }
/** * Shows the planners * @param $planner_items * @param $args * @param $instance * @return array */ protected function show_planner_list_items($planner_items, $args, $instance) { extract($args); $assigned_to = $instance['assigned_to']; $duedate = $instance['duedate']; $status = $instance['status']; $items = ''; while ($planner_items->have_posts()) { $planner_items->the_post(); $id = get_the_ID(); list($assign_meta, $duedate_meta, $status_meta) = PostPlanner_Lib::get_planner_meta($id); $items .= '<li>'; $items .= get_the_title(); if ($status == 1) { $items .= '<br />' . apply_filters('post_planner_status', esc_attr__('Status', 'post-planner')) . ': ' . sanitize_text_field($this->statuses[$status_meta]['name']); } if ($this->settings['assignments'] == 1 && $assigned_to == 1) { if ($assign_meta == -1 || $assign_meta == 0) { $assignment = esc_attr__('Unassigned', 'post-planner'); } else { $assign_user = get_userdata(absint($assign_meta)); $assignment = sanitize_text_field($assign_user->display_name); } $items .= '<br />' . apply_filters('post_planner_assignments', esc_attr__('Assigned To', 'post-planner')) . ': ' . $assignment; } if ($this->settings['duedate'] == 1 && $duedate == 1 && $duedate_meta != '') { $items .= '<br />' . apply_filters('post_planner_duedate', esc_attr__('Due Date', 'post-planner')) . ': ' . sanitize_text_field($duedate_meta); } $items .= '</li>'; } return $items; }
/** * Insert all images into a Post Ajax Callback * * Changes the post parent of the image attachments from the ID of the Planner to the ID of the Associated Post. * This can be prevented by using the post_planner_associate_images filter and setting it to false. * @static * @since 1.0 */ public static function insert_all_images_callback() { check_ajax_referer('postplanner'); $associate = apply_filters('post_planner_associate_images', true); if ($associate == true) { $image_ids = $_POST['post_planner_image_ids']; $post_id = absint($_POST['post_planner_post_id']); $planner_id = absint($_POST['post_planner_planner_id']); $type = esc_attr($_POST['postplanner_type']); if ($type == 'post') { $permission = current_user_can('edit_post', $post_id); } elseif ($type == 'page') { $permission = current_user_can('edit_page', $post_id); } else { $permission = apply_filters('post_planner_associated_permissions', current_user_can('edit_post', $post_id), $type); } if ($permission == true) { foreach ($image_ids as $key => $id) { // if the image is attached to the Planner, change the post parent to the Associated Post if (PostPlanner_Lib::is_attached($id, $planner_id)) { $args = array('ID' => absint($id), 'post_parent' => $post_id); $updated_post_id = wp_update_post($args); $status = $updated_post_id == 0 ? -1 : 1; } else { $status = 1; } } } else { $status = 1; } } else { $status = 1; } echo $status; die; // this is required to return a proper result }