/** * Run the search itself * * GET /wiziapp/search * * @param string category defines where we are searching (all/author/tag/post) * @param string keyword the search term * * @returns a post list screen for the application */ function wiziapp_do_search() { $category = $_GET['category']; $keyword = $_GET['keyword']; $screen_conf = $GLOBALS['WiziappScreens']->getScreenLayout('posts'); $pageNumber = isset($_GET['wizipage']) ? $_GET['wizipage'] : 0; $resultLimit = WiziappConfig::getInstance()->posts_list_limit; $offset = $resultLimit * $pageNumber; $limitForQuery = $resultLimit * 2; $query = "offset={$offset}&orderby=modified&posts_per_page={$limitForQuery}"; // Do not include the same posts, keep track on the posts we collected. // @todo there is no need to keep track of this for now $GLOBALS['wp_posts_listed'] = array(); $GLOBALS['WiziappLog']->write('info', "Searching for posts for {$category}, and with the chars: {$keyword}", "search.wiziapp_do_search"); // According to the search we need to get the searched posts here: if ($category == 'authors') { $query = "{$query}&author_name={$keyword}"; } elseif ($category == 'posts') { $query = "{$query}&s={$keyword}&post_type=post"; } else { if ($category == 'all') { $query = "{$query}&s={$keyword}&post_type=any"; } } $page = wiziapp_buildPostListPage($query, '', $screen_conf['items'], true); $resultCount = count($page); $pager = new WiziappPagination($resultCount, $resultLimit); /** * We are querying the limit * 2 so we can show the next number of items. * Every query already takes the offset into account, therefore we need to * set the offset as 0 for the extract page part */ $pager->setOffset(0); /** * When returning component lists we must *never* keep the array keys since the * protocol defined the component must be a non-associative array */ $page = $pager->extractCurrentPage($page, FALSE); /** * Leave the check whether we should add the show more component to the pager */ $pager->addMoreCell(__("Load %s more items", 'wiziapp'), $page); // The prepareScreen needs to know where are returning a list screen $screen = wiziapp_prepareScreen($page, __(WiziappConfig::getInstance()->getScreenTitle('search'), 'wiziapp'), 'list'); echo json_encode($screen); }
function wiziapp_buildArchiveByMonthPage($year, $month) { global $wp_locale; $screen_conf = $GLOBALS['WiziappScreens']->getScreenLayout('posts', 'archived_list'); $numberOfPosts = WiziappConfig::getInstance()->posts_list_limit; $cQuery = "orderby=modified&posts_per_page=-1&monthnum={$month}&year={$year}"; $countQuery = new WP_Query($cQuery); $total = count($countQuery->posts); $pager = new WiziappPagination($total); $query = "orderby=modified&posts_per_page={$numberOfPosts}&monthnum={$month}&year={$year}&offset={$pager->getOffset()}"; $title = sprintf(__('%1$s %2$d'), $wp_locale->get_month($month), $year); wiziapp_buildPostListPage($query, $title, $screen_conf['items'], false, $pager->leftToShow); }