Example #1
0
/**
* Gets an array of components definition and returns the 
* processed components ready to be displayed on a page
* as a json_encoded string
* 
* @param array $components
* @return string
*/
function wiziapp_componenets2page($components)
{
    $page = array();
    $total = count($components);
    for ($c = 0; $c < $total; ++$c) {
        $component = $components[$c];
        $cName = key($component);
        if ($cName == WIZIAPP_TEXT_COMP) {
            if ($component[$cName][0] != null) {
                $firstChildName = key($component[$cName][0]);
                $page[] = wiziapp_textComponent($firstChildName, $component[$cName]);
            }
        } else {
            $page[] = wiziapp_specialComponent($cName, $component[$cName]);
        }
    }
    return json_encode($page);
}
function wiziapp_getPostNavigation($post_id)
{
    /**
     * Navigation template tags works inside templates,
     * but since we could really use the great work 
     * wordpress team made there we should fake the
     * loop so we can reuse the code. It will require manually
     * settings the is_single attribute of the global wp_query 
     * to true, so wordpress will think there is a point in showing
     * the navigation links...
     */
    global $post, $wp_query;
    $wp_query->is_single = TRUE;
    $post = get_post($post_id);
    setup_postdata($post);
    $nav = array();
    $navLinks = array();
    // Get the prev/next posts links
    $prevPost = get_adjacent_post(FALSE, '', TRUE);
    if ($prevPost) {
        $navLinks[] = array("link" => array("text" => wiziapp_formatComponentText(str_replace('&amp;', '&', $prevPost->post_title), __("Previous Post")), "image" => wiziapp_getPrevPostImage(), "link" => wiziapp_buildPostLink($prevPost->ID)));
    }
    $nextPost = get_adjacent_post(FALSE, '', FALSE);
    if ($nextPost) {
        $navLinks[] = array("link" => array("text" => wiziapp_formatComponentText(str_replace('&amp;', '&', $nextPost->post_title), __("Next Post")), "image" => wiziapp_getNextPostImage(), "link" => wiziapp_buildPostLink($nextPost->ID)));
    }
    $nav = array("navigation" => array("links" => $navLinks));
    return wiziapp_specialComponent("navigation", $nav);
}