Exemplo n.º 1
0
function uihelper_generate_center_content($cid, $permalink = 0, $show = 0)
{
    global $app;
    $content_tpl = array('Question');
    if ($permalink == 1) {
        $permalink_content = uihelper_generate_center_content_permalink($cid, $show);
        return $permalink_content;
    }
    //if we are in network then cached file's id should have content as well as network id
    if (PA::$network_info) {
        $nid = '_network_' . PA::$network_info->network_id;
    } else {
        $nid = '';
    }
    //unique name
    $cache_id = 'content_' . $cid . $nid . PA::$language;
    $middle_content = new CachedTemplate($cache_id);
    //if this file is not cached then generate one for this
    if (!$middle_content->is_cached()) {
        $image_media_gallery = $audio_media_gallery = $video_media_gallery = FALSE;
        $back_page = PA::$url . $app->current_route;
        $content = CNContent::load_content((int) $cid, (int) PA::$login_uid);
        // sanity rulez
        if (empty($content)) {
            // echo "<hr>cid $cid doesn't exist<hr>";
            return '';
        }
        // filter content filelds for output
        $content->title = _out($content->title);
        $content->body = _out($content->body);
        $content_url = PA::$url . PA_ROUTE_CONTENT . "/cid={$content->content_id}";
        $content->title = '<a href="' . $content_url . '" >' . $content->title . '</a>';
        if (strstr($back_page, PA_ROUTE_CONTENT)) {
            if ($content->parent_collection_id > 0) {
                // IF permalink content is a group content redirect to group homepage
                $back_page = PA::$url . PA_ROUTE_GROUP . "/gid=" . $content->parent_collection_id;
            } else {
                //if coming from permalink page then redirect to user page
                $back_page = PA::$url . PA_ROUTE_USER_PUBLIC . "/" . $content->author_id;
            }
        }
        $back_page = urlencode($back_page);
        if (!$content->is_html) {
            $content->body = nl2br($content->body);
        }
        if (trim($content->type) == 'Image') {
            $image_media_gallery = TRUE;
        }
        if (trim($content->type) == 'Audio') {
            $audio_media_gallery = TRUE;
        }
        if (trim($content->type) == 'Video') {
            $video_media_gallery = TRUE;
        }
        if (isset(PA::$login_uid) && PA::$login_uid == $content->author_id) {
            $editable = TRUE;
        }
        $content->no_of_comments = Comment::count_comments_for_content($cid);
        $content->no_of_trackbacks = CNContent::count_trackbacks_for_content($cid);
        $content->trackback_url = PA::$url . "/pa_trackback.php?cid=" . $cid;
        $content_user = new User();
        $content_user->load((int) $content->author_id);
        $content->author_name = '<a href= "' . PA::$url . PA_ROUTE_USER_PUBLIC . '/' . $content_user->user_id . '">' . chop_string($content_user->display_name, 20) . '</a>';
        $content->create_time = PA::date($content->changed, 'long');
        // date("l, F d, Y", $content->changed);
        $tags = Tag::load_tags_for_content($cid);
        if ($tags) {
            $t = array();
            for ($i = 0; $i < count($tags); $i++) {
                $name = _out($tags[$i]['name']);
                $uid = PA::$login_uid;
                $url = PA::$url . '/' . FILE_TAG_SEARCH . '?name_string=content_tag&keyword=' . $tags[$i]["name"];
                $t[] = "<a href={$url}>" . $name . "</a>";
            }
            $tag_string = "<b>" . __("Tags:") . " </b>" . implode(", ", $t);
        } else {
            $tag_string = "";
        }
        $content->tag_entry = $tag_string;
        if (property_exists(get_class($content), 'sbname')) {
            if (substr($content->sbname, 0, 5) == 'event') {
                $content->type = 'SBEvent';
                // need to
            }
            if (substr($content->sbname, 0, 6) == 'review') {
                $content->type = 'Review';
            }
            if (substr($content->sbname, 0, 11) == 'media/audio') {
                $content->type = 'Audio';
            }
            if (substr($content->sbname, 0, 11) == 'media/video') {
                $content->type = 'Video';
            }
            if (substr($content->sbname, 0, 11) == 'media/image') {
                $content->type = 'Image';
            }
            if (substr($content->sbname, 0, 14) == 'showcase/group') {
                $content->type = 'GroupShowCase';
            }
            if (substr($content->sbname, 0, 15) == 'showcase/person') {
                $content->type = 'PersonShowCase';
            }
        }
        // replace magic strings
        $content->replace_percent_strings(PA::$url);
        /* Permalink and edit links for content */
        $perma_link = PA::$url . PA_ROUTE_PERMALINK . "/cid=" . $content->content_id;
        $middle_content->set_object('contents', $content);
        //TODO: gaurav: I am setting this to FALSE because for some reason edit links were appearing on other peoples posts also
        $middle_content->set('editable', FALSE);
        $middle_content->set('permalink', $perma_link);
        $middle_content->set('outer_block_id', 'outer_block_' . $content->content_id);
        $middle_content->set('inner_block_id', 'inner_block_' . $content->content_id);
        $middle_content->set('user_name', $content_user->login_name);
        $middle_content->set('current_theme_path', PA::$theme_url);
        $middle_content->set('back_page', $back_page);
        $middle_content->set('image_media_gallery', $image_media_gallery);
        $middle_content->set('audio_media_gallery', $audio_media_gallery);
        $middle_content->set('video_media_gallery', $video_media_gallery);
        if ($show == 1) {
            $middle_content->set('show', $show);
        }
        $return_content = '';
        if (!in_array($content->type, $content_tpl) && getShadowedPath(CURRENT_THEME_FSPATH . '/' . $content->type . ".php")) {
            $return_content = $middle_content->fetch_cache(getShadowedPath(CURRENT_THEME_FSPATH . '/' . $content->type . ".php"));
        }
    } else {
        //this will load the file with cache id
        //it means there is already file which is cached
        $return_content = $middle_content->fetch_cache();
    }
    return $return_content;
}