function inbox($atts) { $a = wp_parse_args($atts, array('nav_view' => 'both')); if (!is_user_logged_in()) { do_action('mmg_before_load_login_form'); mmg()->load_script('login'); return $this->render('shortcode/login', array('show_nav' => $this->can_show_nav($a['nav_view'])), false); } mmg()->load_script('inbox'); add_action('wp_footer', array(&$this, 'render_compose_form')); //$a = shortcode_atts($atts, array()); $type = mmg()->get('box', 'inbox'); if (isset($_GET['query']) && !empty($_GET['query'])) { $type = 'search'; } $total_pages = 0; switch ($type) { case 'inbox': $models = MM_Conversation_Model::get_conversation(); $total_pages = mmg()->global['conversation_total_pages']; break; case 'unread': $models = MM_Conversation_Model::get_unread(); $total_pages = mmg()->global['conversation_total_pages']; break; case 'read': $models = MM_Conversation_Model::get_read(); $total_pages = mmg()->global['conversation_total_pages']; break; case 'sent': $models = MM_Conversation_Model::get_sent(); $total_pages = mmg()->global['conversation_total_pages']; break; case 'archive': $models = MM_Conversation_Model::get_archive(); $total_pages = mmg()->global['conversation_total_pages']; break; case 'setting': return $this->render('shortcode/setting', array('show_nav' => $this->can_show_nav($a['nav_view'])), false); break; case 'search': $models = MM_Conversation_Model::search(mmg()->get('query')); $total_pages = mmg()->global['conversation_total_pages']; break; } return $this->render('shortcode/inbox', array('models' => $models, 'total_pages' => $total_pages, 'paged' => mmg()->get('mpaged', 'int', 1), 'show_nav' => $this->can_show_nav($a['nav_view'])), false); }
function prepare_items() { global $wpdb; $totals = $wpdb->get_var($wpdb->prepare('SELECT COUNT(id) from ' . $wpdb->prefix . 'mm_conversation WHERE site_id=%d', get_current_blog_id())); //How many to display per page? $perpage = 10; //Which page is this? $paged = !empty($_GET["paged"]) ? mysql_real_escape_string($_GET["paged"]) : ''; //Page Number if (empty($paged) || !is_numeric($paged) || $paged <= 0) { $paged = 1; } $offset = ($this->get_pagenum() - 1) * $perpage; //How many pages do we have in total? $totalpages = ceil($totals / $perpage); //adjust the query to take pagination into account /* -- Register the pagination -- */ $this->set_pagination_args(array("total_items" => $totals, "total_pages" => $totalpages, "per_page" => $perpage)); //The pagination links are automatically built according to those parameters /* — Register the Columns — */ $columns = $this->get_columns(); $hidden = array(); $sortable = $this->get_sortable_columns(); $this->_column_headers = array($columns, $hidden, $sortable); if (isset($_GET['s']) && !empty($_GET['s'])) { if (isset($_GET['s'])) { $this->items = MM_Conversation_Model::search($_GET['s'], $perpage); $totals = mmg()->global['conversation_total_pages']; $totalpages = ceil($totals / $perpage); $this->set_pagination_args(array("total_items" => $totals, "total_pages" => $totalpages, "per_page" => $perpage)); } } else { $this->items = MM_Conversation_Model::model()->find_all('site_id=%d', array(get_current_blog_id()), $perpage, $offset); } }