/** * Create the HTML to show a To-Do List Checkbox * * @since 3.4 */ function ctdl_checkbox() { global $CTDL_status; if (CTDL_Lib::check_permission('todo', 'complete')) { if ($CTDL_status == 0) { return sprintf('<input type="checkbox" id="ctdl-%d" class="todo-checkbox todo-uncompleted" />', absint(get_the_ID())); } else { return sprintf('<input type="checkbox" id="ctdl-%d" class="todo-checkbox todo-completed" checked="checked" />', absint(get_the_ID())); } } return null; }
/** * Creates the widget * @param $args * @param $instance * */ function widget($args, $instance) { global $ClevernessToDoList, $CTDL_widget_settings; $CTDL_widget_settings = $instance; get_currentuserinfo(); $title = apply_filters('widget_title', $instance['title']); $limit = $instance['number'] == '-1' ? 1000 : $instance['number']; $assigned_to = $instance['assigned_to']; $deadline = $instance['deadline']; $progress = $instance['progress']; $category = CTDL_Loader::$settings['categories'] == 1 ? $instance['category'] : 0; $individual = isset($instance['individual']) ? $instance['individual'] : 0; if ($individual == 1 && is_user_logged_in()) { global $current_user, $userdata; if (CTDL_Loader::$settings['list_view'] == '2') { $user = $current_user->ID; } else { $user = $userdata->ID; } } else { $user = 0; } echo $args['before_widget']; if ($title) { echo $args['before_title']; echo $title; echo $args['after_title']; } $ClevernessToDoList->list = ''; $visible = 0; if (CTDL_Loader::$settings['categories'] == 1 && CTDL_Loader::$settings['sort_order'] == 'cat_id' && $category == 0) { $categories = CTDL_Categories::get_categories(); $items = 0; $posts_to_exclude = array(); $visibility = get_option('CTDL_categories'); foreach ($categories as $category) { echo '<ol>'; $category_id = $category->term_id; $visible = $visibility["category_{$category->term_id}"]; $todo_items = CTDL_Lib::get_todos($user, $limit, 0, $category_id); if ($todo_items->have_posts()) { array_splice($posts_to_exclude, count($posts_to_exclude), 0, $this->show_todo_list_items($todo_items, $progress, $deadline, $assigned_to, 0, $visible)); $items = 1; } echo '</ol>'; } $todo_items = CTDL_Lib::get_todos($user, $limit, 0, 0, $posts_to_exclude); if ($todo_items->have_posts()) { echo '<ol>'; $this->show_todo_list_items($todo_items, $progress, $deadline, $assigned_to, 0, $visible); echo '</ol>'; $items = 1; } if ($items == 0) { echo '<p>' . apply_filters('ctdl_no_items', esc_html__('No items to do.', 'cleverness-to-do-list')) . '</p>'; } } else { echo '<ol>'; $todo_items = CTDL_Lib::get_todos($user, $limit, 0, $category); if ($todo_items->have_posts()) { $this->show_todo_list_items($todo_items, $progress, $deadline, $assigned_to, $category, $visible); } else { echo '<p>' . apply_filters('ctdl_no_items', esc_html__('No items to do.', 'cleverness-to-do-list')) . '</p>'; } } echo '</ol>'; echo $args['after_widget']; }
/** * Generate the To-Do List * @param $todo_items * @param int $completed * @param int $visible * @return array $posts_to_exclude */ protected function show_todo_list_items($todo_items, $completed = 0, $visible = 0) { $atts = shortcode_atts(array('title' => '', 'type' => 'list', 'priorities' => 1, 'assigned' => 1, 'deadline' => 1, 'progress' => 1, 'addedby' => 1, 'date' => 0, 'list_type' => 'ol', 'category' => '0', 'completed_date' => 0), $this->atts, 'todolist'); while ($todo_items->have_posts()) { $todo_items->the_post(); $id = get_the_ID(); $posts_to_exclude[] = $id; if ($visible == 0) { list($the_priority, $assign_meta, $deadline_meta, $completed_meta, $progress_meta) = CTDL_Lib::get_todo_meta($id); $priority_class = CTDL_Lib::set_priority_class($the_priority); if ($atts['type'] == 'list' && CTDL_Loader::$settings['categories'] == 1 && CTDL_Loader::$settings['sort_order'] == 'cat_id') { $this->show_category_headings(get_the_terms($id, 'todocategories'), $atts['list_type'], $completed); } if ($atts['type'] == 'table') { $this->list .= '<tr id="todo-' . esc_attr($id) . '"' . $priority_class . '>'; } else { $this->list .= '<li' . $priority_class . '>'; } $this->show_todo_text(get_the_content(), $atts['type']); if (($atts['priorities'] == 'show' || $atts['priorities'] == 1) && $atts['type'] == 'table') { $this->show_priority($the_priority); } if (($atts['progress'] == 'show' || $atts['progress'] == 1) && CTDL_Loader::$settings['show_progress'] == 1) { $this->show_progress($progress_meta, $atts['type'], $completed); } if ($atts['category'] == 0 && $atts['type'] == 'table' && CTDL_Loader::$settings['categories'] == 1) { $this->show_category(get_the_terms($id, 'todocategories')); } if (($atts['assigned'] == 'show' || $atts['assigned'] == 1) && ((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)) { $this->show_assigned($assign_meta, $atts['type']); } if (($atts['addedby'] == 'show' || $atts['addedby'] == 1) && CTDL_Loader::$settings['list_view'] == 1 && CTDL_Loader::$settings['todo_author'] == 0) { $this->show_addedby(get_the_author(), $atts['type']); } if (($atts['deadline'] == 'show' || $atts['deadline'] == 1) && CTDL_Loader::$settings['show_deadline'] == 1) { $this->show_deadline($deadline_meta, $atts['type']); } if ($atts['date'] == 1 && CTDL_Loader::$settings['show_date_added'] == 1) { $this->show_date_added(get_the_date('Ymd'), get_the_date(CTDL_Loader::$settings['date_format']), $atts['type']); } if ($atts['completed_date'] == 1 && CTDL_Loader::$settings['show_completed_date'] && $completed == 1) { $this->show_completed($completed_meta, $atts['type']); } $this->list .= do_action('ctdl_list_items'); if ($atts['type'] == 'table') { $this->list .= '</tr>'; } else { $this->list .= '</li>'; } } } wp_reset_postdata(); return $posts_to_exclude; }
do_action('post_planner_todo_meta', $pp_todo_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(); ?> </ul> <?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()) {
/** * Setup the dashboard widget */ public function dashboard_setup() { global $CTDL_status, $CTDL_category, $CTDL_category_id; $CTDL_status = 0; $CTDL_category = 0; $CTDL_category_id = 0; $heading = isset(CTDL_Loader::$dashboard_settings['dashboard_heading']) && CTDL_Loader::$dashboard_settings['dashboard_heading'] != '' ? CTDL_Loader::$dashboard_settings['dashboard_heading'] : __('To-Do List', 'cleverness-to-do-list'); if (CTDL_Lib::check_permission('todo', 'view')) { wp_add_dashboard_widget('ctdl', apply_filters('ctdl_todo_list', esc_html($heading)) . ' <a href="admin.php?page=cleverness-to-do-list">»</a>', array($this, 'dashboard_widget'), array($this, 'dashboard_options')); } }
/** * Set url and action variables * @return array */ public static function set_variables() { $url = CTDL_Lib::get_page_url(); $url = strtok($url, '?'); $action = isset($_GET['action']) ? $_GET['action'] : ''; return array($url, $action); }
if (1 == CTDL_Loader::$dashboard_settings['show_completed']) { ?> <div class="completed-checklist"> <?php foreach ($cat_ids as $cat_id) { ?> <?php $CTDL_Dashboard_Widget->loop_through_todos(1, $cat_id); ?> <?php } ?> </div> <?php } ?> <?php if (CTDL_Lib::check_permission('todo', 'add')) { ?> <p class="add-todo"> <a href="<?php echo admin_url('?page=cleverness-to-do-list#addtodo'); ?> "><?php echo apply_filters('ctdl_add_text', esc_attr__('Add To-Do Item', 'cleverness-to-do-list')); ?> »</a> </p> <?php }
/** * Install plugin on plugin activation */ function cleverness_todo_activation() { global $wp_version; $exit_msg = __('To-Do List requires WordPress 3.8 or newer. <a href="http://codex.wordpress.org/Upgrading_WordPress">Please update.</a>', 'cleverness-to-do-list'); if (version_compare($wp_version, '3.8', '<')) { exit($exit_msg); } if (!defined('CTDL_DB_VERSION')) { define('CTDL_DB_VERSION', '3.4'); } if (!defined('CTDL_FILE')) { define('CTDL_FILE', __FILE__); } include_once 'includes/cleverness-to-do-list-library.class.php'; if (get_option('CTDL_db_version')) { $installed_ver = get_option('CTDL_db_version'); } else { $installed_ver = 0; } if (CTDL_DB_VERSION != $installed_ver) { CTDL_Lib::install_plugin(); } }
/** * Create the HTML to show a To-Do List Checkbox * @param int $id * @param int $completed * @param string $layout * @param string $single */ protected function show_checkbox($id, $completed = 0, $layout = 'table', $single = '') { $permission = CTDL_Lib::check_permission('todo', 'complete'); if ($permission === true) { if (is_admin() || $layout == 'table') { $this->list .= '<td>'; } if ($completed == 1) { $this->list .= sprintf('<input type="checkbox" id="ctdl-%d" class="todo-checkbox todo-completed' . $single . '" checked="checked" />', esc_attr($id)); } else { $this->list .= sprintf('<input type="checkbox" id="ctdl-%d" class="todo-checkbox todo-uncompleted' . $single . '"/>', esc_attr($id)); } $cleverness_todo_complete_nonce = wp_create_nonce('todocomplete'); $this->list .= '<input type="hidden" name="cleverness_todo_complete_nonce" value="' . esc_attr($cleverness_todo_complete_nonce) . '" />'; if (is_admin() || $layout == 'table') { $this->list .= '</td>'; } } }
/** * Delete a to-do list category using ajax * @static */ public static function delete_category_callback() { check_ajax_referer('cleverness-todo-cat'); $permission = CTDL_Lib::check_permission('category', 'add_cat'); $status = $permission === true ? CTDL_Categories::delete_category() : 2; echo $status; die; // this is required to return a proper result }
/** * 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>'; }
/** * Update to-do list Ajax callback * @static * @since 1.1 */ public static function update_todolist_callback() { check_ajax_referer('postplanner'); $todo_id = absint($_POST['postplanner_item_id']); $todo_status = absint($_POST['postplanner_item_status']); $permission = CTDL_Lib::check_permission('todo', 'complete'); if ($permission === true) { CTDL_Lib::complete_todo(absint($todo_id), $todo_status); $status = 1; } else { $status = -1; } echo $status; die; // this is required to return a proper result }