Example #1
0
/**
* 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);
}
Example #2
0
function wiziapp_buildGalleriesPage()
{
    $GLOBALS['WiziappLog']->write('info', "Building galleries page", 'screens.wiziapp_buildPluginGalleriesPage');
    $screen_conf = $GLOBALS['WiziappScreens']->getScreenLayout('albums');
    $page = array();
    $albumLimit = WiziappConfig::getInstance()->posts_list_limit;
    $sortedAlbums = array();
    $allAlbums = array();
    //    $albums = apply_filters('wiziapp_albums_request', $albums);
    // @todo If such method already exists, it should implement the pager.
    $galleries = new WiziappGalleries();
    $albums = $galleries->getAll();
    for ($a = 0, $total_albums = count($albums); $a < $total_albums; ++$a) {
        $album = $albums[$a];
        $sortedAlbums[$album['postID'] . '_' . $album['id']] = strtotime($album['publish_date']);
        $allAlbums[$album['postID'] . '_' . $album['id']] = $album;
    }
    arsort($sortedAlbums);
    foreach ($sortedAlbums as $albumId => $albumDate) {
        $album = $allAlbums[$albumId];
        $config_key = 'items';
        if ($sortedAlbums[$albumId]['plugin'] == 'videos') {
            $config_key = 'videos_items';
        }
        wiziapp_appendComponentByLayout($page, $screen_conf[$config_key], $album);
    }
    $albumCount = count($sortedAlbums);
    $pager = new WiziappPagination($albumCount, $albumLimit);
    $page = $pager->extractCurrentPage($page, FALSE);
    $pager->addMoreCell(__("Load %s more items", 'wiziapp'), $page);
    /*$GLOBALS['WiziappLog']->write('info', "Got the page: ".print_r($page, TRUE), 
      "screens.wiziapp_buildPluginGalleriesPage");*/
    $title = __(WiziappConfig::getInstance()->getScreenTitle('albums'), 'wiziapp');
    $screen = wiziapp_prepareScreen($page, $title, 'list', false, true);
    echo json_encode($screen);
}