/** * 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_buildAudioPage() { $screen_conf = $GLOBALS['WiziappScreens']->getScreenLayout('audio', 'list'); $title = __(WiziappConfig::getInstance()->getScreenTitle('audio'), 'wiziapp'); $page = array(); $pageNumber = isset($_GET['wizipage']) ? $_GET['wizipage'] : 0; $audioLimit = WiziappConfig::getInstance()->audios_list_limit; $limitForRequest = $audioLimit * 2; $offset = $audioLimit * $pageNumber; $audios = $GLOBALS['WiziappDB']->get_all_audios($offset, $limitForRequest); $audios = apply_filters('wiziapp_audio_request', $audios); if ($audios !== FALSE) { $GLOBALS['WiziappLog']->write('info', "The audios are: " . print_r($audios, TRUE), "screens.wiziapp_buildAudioPage"); $sortedAudio = array(); $allAudio = array(); for ($a = 0, $aTotal = count($audios); $a < $aTotal; ++$a) { $audio = array_merge(array('id' => $audios[$a]['id']), json_decode($audios[$a]['attachment_info'], TRUE)); $post = get_post($audios[$a]['content_id']); $sortedAudio[$audio['id']] = strtotime($post->post_date); $allAudio[$audio['id']] = $audio; } arsort($sortedAudio); /** * Handle paging */ foreach ($sortedAudio as $audioId => $audioDate) { $audio = $allAudio[$audioId]; wiziapp_appendComponentByLayout($page, $screen_conf['items'], $audio); } $audioCount = count($sortedAudio); $pager = new WiziappPagination($audioCount, $audioLimit); $pager->setOffset(0); $page = $pager->extractCurrentPage($page, TRUE); $pager->addMoreCell(__("Load %s more items", 'wiziapp'), $page); } $screen = wiziapp_prepareScreen($page, $title, 'list'); $screen['screen']['default'] = 'list'; $screen['screen']['sub_type'] = 'audio'; echo json_encode($screen); }