Exemplo n.º 1
0
/**
 * Dispatches blog pages.
 * URLs take the form of
 *  All blogs:       blog/all
 *  User's blogs:    blog/owner/<username>
 *  Friends' blog:   blog/friends/<username>
 *  User's archives: blog/archives/<username>/<time_start>/<time_stop>
 *  Blog post:       blog/view/<guid>/<title>
 *  New post:        blog/add/<guid>
 *  Edit post:       blog/edit/<guid>/<revision>
 *  Preview post:    blog/preview/<guid>
 *  Group blog:      blog/group/<guid>/all
 *
 * Title is ignored
 *
 * @todo no archives for all blogs or friends
 *
 * @param array $page
 * @return bool
 */
function blog_page_handler($page)
{
    elgg_load_library('elgg:blog');
    // push all blogs breadcrumb
    elgg_push_breadcrumb(elgg_echo('blog:blogs'), "blog/all");
    if (!isset($page[0])) {
        $page[0] = 'all';
    }
    $page_type = $page[0];
    switch ($page_type) {
        case 'owner':
            $user = get_user_by_username($page[1]);
            if (!$user) {
                forward('', '404');
            }
            $params = blog_get_page_content_list($user->guid);
            break;
        case 'friends':
            $user = get_user_by_username($page[1]);
            if (!$user) {
                forward('', '404');
            }
            $params = blog_get_page_content_friends($user->guid);
            break;
        case 'archive':
            $user = get_user_by_username($page[1]);
            if (!$user) {
                forward('', '404');
            }
            $params = blog_get_page_content_archive($user->guid, $page[2], $page[3]);
            break;
        case 'view':
            $params = blog_get_page_content_read($page[1]);
            break;
        case 'add':
            elgg_gatekeeper();
            $params = blog_get_page_content_edit($page_type, $page[1]);
            break;
        case 'edit':
            elgg_gatekeeper();
            $params = blog_get_page_content_edit($page_type, $page[1], $page[2]);
            break;
        case 'group':
            $group = get_entity($page[1]);
            if (!elgg_instanceof($group, 'group')) {
                forward('', '404');
            }
            if ($page[2] == 'all') {
                $params = blog_get_page_content_list($page[1]);
            } else {
                $params = blog_get_page_content_archive($page[1], $page[3], $page[4]);
            }
            break;
        case 'all':
            $params = blog_get_page_content_list();
            break;
        default:
            return false;
    }
    if (isset($params['sidebar'])) {
        $params['sidebar'] .= elgg_view('blog/sidebar', array('page' => $page_type));
    } else {
        $params['sidebar'] = elgg_view('blog/sidebar', array('page' => $page_type));
    }
    $body = elgg_view_layout('content', $params);
    echo elgg_view_page($params['title'], $body);
    return true;
}
Exemplo n.º 2
0
/**
 * Dispatches blog pages.
 * URLs take the form of
 *  All blogs:       blog/all
 *  User's blogs:    blog/owner/<username>
 *  Friends' blog:   blog/friends/<username>
 *  User's archives: blog/archives/<username>/<time_start>/<time_stop>
 *  Blog post:       blog/view/<guid>/<title>
 *  New post:        blog/add/<guid>
 *  Edit post:       blog/edit/<guid>/<revision>
 *  Preview post:    blog/preview/<guid>
 *  Group blog:      blog/group/<guid>/all
 *
 * Title is ignored
 *
 * @todo no archives for all blogs or friends
 *
 * @param array $page
 * @return bool
 */
function blog_page_handler($page)
{
    elgg_load_library('elgg:blog');
    // @todo remove the forwarder in 1.9
    // forward to correct URL for blog pages pre-1.7.5
    blog_url_forwarder($page);
    // push all blogs breadcrumb
    elgg_push_breadcrumb(elgg_echo('blog:blogs'), "blog/all");
    if (!isset($page[0])) {
        $page[0] = 'all';
    }
    $page_type = $page[0];
    switch ($page_type) {
        case 'owner':
            $user = get_user_by_username($page[1]);
            $params = blog_get_page_content_list($user->guid);
            break;
        case 'friends':
            $user = get_user_by_username($page[1]);
            $params = blog_get_page_content_friends($user->guid);
            break;
        case 'archive':
            $user = get_user_by_username($page[1]);
            $params = blog_get_page_content_archive($user->guid, $page[2], $page[3]);
            break;
        case 'view':
        case 'read':
            // Elgg 1.7 compatibility
            $params = blog_get_page_content_read($page[1]);
            break;
        case 'add':
            gatekeeper();
            $params = blog_get_page_content_edit($page_type, $page[1]);
            break;
        case 'edit':
            gatekeeper();
            $params = blog_get_page_content_edit($page_type, $page[1], $page[2]);
            break;
        case 'group':
            if ($page[2] == 'all') {
                $params = blog_get_page_content_list($page[1]);
            } else {
                $params = blog_get_page_content_archive($page[1], $page[3], $page[4]);
            }
            break;
        case 'all':
            $params = blog_get_page_content_list();
            break;
        default:
            return false;
    }
    if (isset($params['sidebar'])) {
        $params['sidebar'] .= elgg_view('blog/sidebar', array('page' => $page_type));
    } else {
        $params['sidebar'] = elgg_view('blog/sidebar', array('page' => $page_type));
    }
    $body = elgg_view_layout('content', $params);
    echo elgg_view_page($params['title'], $body);
    return true;
}
Exemplo n.º 3
0
/**
 * Dispatches blog pages.
 * To maintain URL backward compatibility, expects old-style URLs like:
 * 	pg/blog/[username/[read|edit|archive|new/[time_start|guid/[time_end|title]]]]
 *
 * Without a username, show all blogs
 * Without an action (read|edit|archive|new), forward to pg/blog/username/read.
 * Without a guid, show all post for that user.
 * Title is ignored
 *
 * If archive, uses time_start/end
 *
 * @todo There is no way to say "show me archive view for all blog posts" with the
 * current URL scheme because $param[0] is the username instead of an action.
 * Could do something hideous like make '*' mean "all users" (since a username can't be *).
 * Can't change the URL scheme because of URL compatibility.
 *
 * @param array $page
 * @return NULL
 */
function blog_page_handler($page)
{
    global $CONFIG;
    elgg_push_breadcrumb(elgg_echo('blog:blogs'), "{$CONFIG->site->url}pg/blog");
    // see if we're showing all or just a user's
    if (isset($page[0]) && !empty($page[0])) {
        $username = $page[0];
        // forward away if invalid user.
        if (!($user = get_user_by_username($username))) {
            register_error('blog:error:unknown_username');
            forward($_SERVER['HTTP_REFERER']);
        }
        set_page_owner($user->getGUID());
        $crumbs_title = sprintf(elgg_echo('blog:owned_blogs'), $user->name);
        $crumbs_url = "{$CONFIG->site->url}pg/blog/{$username}/read";
        elgg_push_breadcrumb($crumbs_title, $crumbs_url);
        $action = isset($page[1]) ? $page[1] : FALSE;
        // yeah these are crap names, but they're used for different things.
        $page2 = isset($page[2]) ? $page[2] : FALSE;
        $page3 = isset($page[3]) ? $page[3] : FALSE;
        switch ($action) {
            case 'read':
                $title = sprintf(elgg_echo('blog:title:user_blogs'), $user->name);
                $content_info = blog_get_page_content_read($user->getGUID(), $page2);
                break;
            case 'new':
            case 'edit':
                //$sidebar = elgg_view('blog/sidebar_edit', array('blog_guid' => $page2));
                $content_info = blog_get_page_content_edit($page2, $page3);
                break;
            case 'archives':
                $content = elgg_view('page_elements/content_header', array('context' => $content, 'type' => 'blog'));
                $content .= blog_get_page_content_archive($user->getGUID(), $page2, $page3);
                break;
            case 'friends':
                $content = elgg_view('page_elements/content_header', array('context' => $content, 'type' => 'blog'));
                $content .= blog_get_page_content_archive($user->getGUID());
                break;
            default:
                forward("pg/blog/{$username}/read/");
                break;
        }
    } else {
        $title = elgg_echo('blog:title:all_blogs');
        $content_info = blog_get_page_content_read();
    }
    $sidebar .= elgg_view('blog/sidebar_menu');
    if (isset($content_info['sidebar'])) {
        $sidebar .= $content_info['sidebar'];
    }
    $content = elgg_view('navigation/breadcrumbs') . $content_info['content'];
    $body = elgg_view_layout('one_column_with_sidebar', $content, $sidebar);
    page_draw($title, $body);
}
Exemplo n.º 4
0
/**
 * Dispatches blog pages.
 * URLs take the form of
 *  All blogs:       blog/all
 *  User's blogs:    blog/owner/<username>
 *  Friends' blog:   blog/friends/<username>
 *  User's archives: blog/archives/<username>/<time_start>/<time_stop>
 *  Blog post:       blog/view/<guid>/<title>
 *  New post:        blog/add/<guid>
 *  Edit post:       blog/edit/<guid>/<revision>
 *  Preview post:    blog/preview/<guid>
 *  Group blog:      blog/group/<guid>/all
 *
 * Title is ignored
 *
 * @todo no archives for all blogs or friends
 *
 * @param array $page
 * @return bool
 */
function page_handler($page)
{
    elgg_load_library('elgg:blog');
    // push all blogs breadcrumb
    elgg_push_breadcrumb(elgg_echo('blog:blogs'), "blog/all");
    if (!isset($page[0])) {
        $page[0] = 'all';
    }
    $page_type = $page[0];
    switch ($page_type) {
        case 'owner':
            $user = get_user_by_username($page[1]);
            if (!$user || !$user->isAdmin()) {
                forward('', '404');
            }
            $params = blog_get_page_content_list($user->guid);
            if (!elgg_is_admin_logged_in()) {
                elgg_unregister_menu_item('title', 'add');
            }
            $params['filter'] = false;
            // no need for all/mine/friends anymore
            break;
        case 'archive':
            $user = get_user_by_username($page[1]);
            if (!$user || !$user->isAdmin()) {
                forward('', '404');
            }
            $params = blog_get_page_content_archive($user->guid, $page[2], $page[3]);
            break;
        case 'view':
            $params = blog_get_page_content_read($page[1]);
            break;
        case 'add':
            elgg_admin_gatekeeper();
            $params = blog_get_page_content_edit($page_type, $page[1]);
            break;
        case 'edit':
            elgg_admin_gatekeeper();
            $params = blog_get_page_content_edit($page_type, $page[1], $page[2]);
            break;
        case 'group':
            $group_blogs = (int) elgg_get_plugin_setting('group_blog', PLUGIN_ID);
            if (!$group_blogs) {
                forward('', '404');
            }
            $group = get_entity($page[1]);
            if (!elgg_instanceof($group, 'group')) {
                forward('', '404');
            }
            if (!isset($page[2]) || $page[2] == 'all') {
                $params = blog_get_page_content_list($page[1]);
            } else {
                $params = blog_get_page_content_archive($page[1], $page[3], $page[4]);
            }
            if (!elgg_is_admin_logged_in()) {
                elgg_unregister_menu_item('title', 'add');
            }
            break;
        case 'all':
            $params = blog_get_page_content_list();
            if (!elgg_is_admin_logged_in()) {
                elgg_unregister_menu_item('title', 'add');
            }
            $params['filter'] = false;
            break;
        default:
            return false;
    }
    if (isset($params['sidebar'])) {
        $params['sidebar'] .= elgg_view('blog/sidebar', array('page' => $page_type));
    } else {
        $params['sidebar'] = elgg_view('blog/sidebar', array('page' => $page_type));
    }
    $body = elgg_view_layout('content', $params);
    echo elgg_view_page($params['title'], $body);
    return true;
}
Exemplo n.º 5
0
Arquivo: view.php Projeto: elgg/blog
<?php

$guid = get_input('guid');
$params = blog_get_page_content_read($guid);
if (isset($params['sidebar'])) {
    $params['sidebar'] .= elgg_view('blog/sidebar', array('page' => $page_type));
} else {
    $params['sidebar'] = elgg_view('blog/sidebar', array('page' => $page_type));
}
$body = elgg_view_layout('content', $params);
echo elgg_view_page($params['title'], $body);