function render()
 {
     $this->links = NULL;
     $Pagination = new CNPagination();
     switch ($this->type) {
         case IMAGE:
             $this->links = CNContent::load_content_id_array($this->uid, IMAGE);
             $this->type_image = PA::$theme_url . "/img/type-image.gif";
             break;
         case AUDIO:
             $this->links = CNContent::load_content_id_array($this->uid, AUDIO);
             $this->type_image = PA::$theme_url . "/img/type-audio.gif";
             break;
         case VIDEO:
             $this->links = CNContent::load_content_id_array($this->uid, VIDEO);
             $this->type_image = PA::$theme_url . "/img/type-video.gif";
             break;
         case BLOGPOST:
             $this->links = CNContent::load_content_id_array($this->uid, BLOGPOST);
             $this->type_image = PA::$theme_url . "/img/type-blog.gif";
             break;
         default:
             $this->links = CNContent::load_content_id_array($this->uid, NULL);
             break;
     }
     $this->inner_HTML = $this->generate_inner_html();
     $content = parent::render();
     return $content;
 }
 function get_content()
 {
     $param['page'] = 1;
     $param['show'] = 20;
     // get recent 20 contents
     $condition = 'type = ' . BLOGPOST . ' AND author_id = ' . $_SESSION['user']['id'];
     $content = CNContent::get($param, $condition);
     return $content;
 }
function uihelper_generate_center_content_permalink($cid, $show = 0)
{
    global $app;
    $image_media_gallery = FALSE;
    $back_page = PA::$url . $app->current_route;
    $content = CNContent::load_content((int) $cid, (int) PA::$login_uid);
    // filter content fields for output
    $content->title = _out($content->title);
    $content->body = _out($content->body);
    if (strstr($back_page, PA_ROUTE_CONTENT) || strstr($back_page, PA_ROUTE_PERMALINK)) {
        if ($content->parent_collection_id > 0) {
            $collection = ContentCollection::load_collection((int) $content->parent_collection_id, PA::$login_uid);
            if ($collection->type == GROUP_COLLECTION_TYPE) {
                $back_page = PA::$url . PA_ROUTE_GROUP . "/gid=" . $content->parent_collection_id;
            } else {
                $back_page = PA::$url . PA_ROUTE_MEDIA_GALLEY_IMAGES . "/uid=" . $content->author_id;
            }
            // IF permalink content is a group content redirect to group homepage
        } else {
            //if coming from permalink page then redirect to user page
            $back_page = PA::$url . PA_ROUTE_USER_PRIVATE;
        }
    }
    $moderateduser = Group::is_admin((int) $content->parent_collection_id, (int) PA::$login_uid) ? 1 : 0;
    $back_page = urlencode($back_page);
    if (!$content->is_html) {
        $content->body = nl2br($content->body);
    }
    $media_gallery_content = NULL;
    $media_gallery_content = in_array(trim($content->type), array('Image', 'Audio', 'Video'));
    $editable = PA::$login_uid == $content->author_id || $moderateduser;
    $comments = Comment::get_comment_for_content($cid, '', 'ASC');
    $number_of_comments = count($comments);
    $content->no_of_comments = $number_of_comments;
    $trackback = CNContent::get_trackbacks_for_content($cid);
    $number_of_trackbacks = count($trackback);
    $content->no_of_trackbacks = $number_of_trackbacks;
    $content->trackback_url = PA::$url . "/pa_trackback.php?cid=" . $cid;
    $content_user = new User();
    $content_user->load((int) $content->author_id);
    $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($content, 'sbname')) {
        if (substr($content->sbname, 0, 5) == 'event') {
            $content->type = 'SBEvent';
        } elseif (substr($content->sbname, 0, 6) == 'review') {
            $content->type = 'Review';
        } elseif (substr($content->sbname, 0, 11) == 'media/audio') {
            $content->type = 'Audio';
        } elseif (substr($content->sbname, 0, 11) == 'media/video') {
            $content->type = 'Video';
        } elseif (substr($content->sbname, 0, 11) == 'media/image') {
            $content->type = 'Image';
        } elseif (substr($content->sbname, 0, 14) == 'showcase/group') {
            $content->type = 'GroupShowCase';
        } elseif (substr($content->sbname, 0, 15) == 'showcase/person') {
            $content->type = 'PersonShowCase';
        }
    }
    // replace magic strings
    $content->replace_percent_strings(PA::$url);
    $type = $content->type;
    $type = $type . 'Permalink';
    // comments
    $comments_list_tpl = new Template(CURRENT_THEME_FSPATH . "/cncontent_comments.php");
    $comments_list_tpl->set('current_theme_path', PA::$theme_url);
    $comments_list_tpl->set('comments', $comments);
    $comments_list_tpl->set('author_id', $content->author_id);
    // Setting the variable for the abuse form ...
    $comments_list = $comments_list_tpl->fetch();
    //comment form
    $cnform_comment_tpl = new Template(CURRENT_THEME_FSPATH . "/cnform_comment.php");
    $cnform_comment_tpl->set('current_theme_path', PA::$theme_url);
    if (isset(PA::$login_uid)) {
        $user = new User();
        $user->load((int) PA::$login_uid);
        $login_name = $user->login_name;
        $cnform_comment_tpl->set('name', $login_name);
        $cnform_comment_tpl->set('login_name', $user->login_name);
    }
    $cnform_comment_tpl->set('cid', $cid);
    if ($content->parent_collection_id > 0) {
        $cnform_comment_tpl->set('ccid', $content->parent_collection_id);
    }
    // abuse form
    $cnform_abuse_tpl = new Template(CURRENT_THEME_FSPATH . "/cnform_abuse.php");
    /* Permalink and edit links for content */
    if ($content->parent_collection_id != -1) {
        $perma_link = PA::$url . PA_ROUTE_PERMALINK . "/cid=" . $content->content_id . '&ccid=' . $content->parent_collection_id;
    } else {
        $perma_link = PA::$url . PA_ROUTE_PERMALINK . "/cid=" . $content->content_id;
    }
    $params = array('permissions' => 'edit_content', 'uid' => PA::$login_uid, 'cid' => $content->content_id);
    if (PermissionsHandler::can_user(PA::$login_uid, $params)) {
        if ($media_gallery_content) {
            $edit_link = PA::$url . '/edit_media.php?cid=' . $content->content_id;
        } else {
            $edit_link = PA::$url . "/cncontent_blog.php?cid=" . $content->content_id;
        }
        $delete_link = PA::$url . PA_ROUTE_CONTENT . "?action=deleteContent&cid=" . $content->content_id . '&amp;back_page=' . $back_page;
        // handle Event separately
        if ($type == "EventPermalink") {
            $edit_link = PA::$url . '/calendar.php?cid=' . $content->content_id;
            $delete_link = $edit_link . "&delete=1" . '&amp;back_page=' . $back_page;
        }
    } else {
        $edit_link = $delete_link = NULL;
    }
    $user_link = PA::$url . PA_ROUTE_USER_PUBLIC . '/' . $content->author_id;
    /* Code for Approval and Denial links for a content */
    if ($moderateduser && $content->is_active == 2) {
        $approval_link = PA::$url . PA_ROUTE_PERMALINK . '/cid=' . $content->content_id . '&ccid=' . $content->parent_collection_id . '&apv=1';
        $denial_link = PA::$url . PA_ROUTE_PERMALINK . '/cid=' . $content->content_id . '&ccid=' . $content->parent_collection_id . '&dny=1';
    } else {
        $approval_link = $denial_link = NULL;
    }
    // Show comments form to logged in users, only if comments enabled.
    global $comments_disabled;
    // fix by Z.Hron; if group content - only members of group can comment it
    $can_user_comment = true;
    if (isset($_GET['gid']) && isset(PA::$login_uid)) {
        $can_user_comment = Group::member_exists((int) $_GET['gid'], PA::$login_uid);
    }
    if (!$comments_disabled && !empty(PA::$login_uid) && $can_user_comment) {
        $cnform_comment = $cnform_comment_tpl->fetch();
        $cnform_abuse = $cnform_abuse_tpl->fetch();
    } else {
        $cnform_comment = $cnform_abuse = NULL;
    }
    if (getShadowedPath(CURRENT_THEME_FSPATH . "/{$type}.php")) {
        $middle_content = new Template(getShadowedPath(CURRENT_THEME_FSPATH . "/{$type}.php"));
        $middle_content->set_object('contents', $content);
        $middle_content->set('editable', $editable);
        $middle_content->set('picture_name', $content_user->picture);
        //  to set picture name for diplaying in contets
        $middle_content->set('user_id', $content_user->user_id);
        $middle_content->set('user_name', $content_user->first_name . ' ' . $content_user->last_name);
        $middle_content->set('current_theme_path', PA::$theme_url);
        $middle_content->set('back_page', $back_page);
        $middle_content->set('comments', $comments_list);
        $middle_content->set('cnform_comment', $cnform_comment);
        $middle_content->set('cnform_abuse', $cnform_abuse);
        $middle_content->set('media_gallery_content', $media_gallery_content);
        if ($show == 1) {
            $middle_content->set('show', $show);
        }
        $middle_content->set('permalink', $perma_link);
        $middle_content->set('edit_link', $edit_link);
        $middle_content->set('approval_link', $approval_link);
        $middle_content->set('denial_link', $denial_link);
        $middle_content->set('delete_link', $delete_link);
        $middle_content->set('user_link', $user_link);
        $return_content = $middle_content->fetch();
    } else {
        $return_content = '<p>Content does not have a display template.</p><p>Create a ' . $type . '.php file to display this content type.</p>';
    }
    return $return_content;
}
 public function render()
 {
     // group recent posts
     if ($this->type == 'group') {
         $group = new Group();
         $group->collection_id = $this->gid;
         $this->links = $group->get_contents_for_collection('all', FALSE, $this->limit, 1, 'created', 'DESC', TRUE);
         // user recent posts
     } else {
         if ($this->type == 'user') {
             $this->links = CNContent::get_user_content($this->uid);
             // network recent posts
         } else {
             $this->links = CNContent::load_content_id_array($user_id = 0, $type = NULL, $cnt = FALSE, $show = $this->limit, $page = 1, $sort_by = 'created', $direction = 'DESC', $only_homepage = false);
         }
     }
     $this->view_all_url = count($this->links) > 0 ? $this->view_all_url : '';
     $this->inner_HTML = $this->generate_inner_html($this->links);
     $content = parent::render();
     return $content;
 }
 /**
  * calls Content::delete() to soft delete a content
  * soft delete
  */
 public function delete()
 {
     Logger::log("Enter: Video::delete");
     Logger::log("Calling: Content::delete");
     parent::delete();
     Logger::log("Exit: Video::delete");
     return;
 }
 /**
  * Saves Question in database
  * @access public
  */
 public function save()
 {
     Logger::log("Enter: Question::save");
     Logger::log("Calling: Content::save");
     $this->created = time();
     $this->changed = time();
     $this->display_on = 0;
     $this->trackbacks = NULL;
     $id = parent::save();
     $this->update_question($id);
     Logger::log("Exit: Question::save");
     return $this->content_id;
 }
 public function load($cid)
 {
     parent::load($cid);
     // the content part
     $this->load_by_event_id(Event::get_eid_from_cid($cid));
     // the event part
 }
 public static function save_blogpost($cid, $uid, $title, $body, $track, $tags, $ccid = 0, $is_active = 1, $display_on = 0, $is_default_content = FALSE)
 {
     $errors = array();
     // ensure integers here
     $cid = (int) $cid;
     $uid = (int) $uid;
     $ccid = (int) $ccid;
     // if a new post, make one, otherwise load the existing one
     if ($cid) {
         $post = CNContent::load_content($cid, $uid);
         // ignore $ccid passed to function if the post already exists
         // - we don't allow users to move posts between
         // CNContentCollections.
         $ccid = (int) $post->parent_collection_id;
     } else {
         $post = new CNBlogPost();
         $post->author_id = $uid;
         if ($ccid) {
             $post->parent_collection_id = $ccid;
         }
     }
     if ($ccid && $ccid != -1) {
         $g = ContentCollection::load_collection($ccid, $uid);
         $g->assert_user_access($uid);
     } else {
         $g = NULL;
     }
     $post->title = $title;
     $post->body = $body;
     $post->allow_comments = 1;
     $post->is_active = $is_active;
     $post->display_on = $display_on;
     $post->trackbacks = '';
     if ($track) {
         $post->trackbacks = implode(",", $track);
     }
     $post->is_default_content = $is_default_content;
     $post->save();
     //if ($tags) {
     Tag::add_tags_to_content($post->content_id, $tags);
     //}
     if ($track) {
         foreach ($track as $t) {
             if (!$post->send_trackback($t)) {
                 $errors[] = array("code" => "trackback_failed", "msg" => "Failed to send trackback", "url" => $t);
             }
         }
     }
     if ($g && !$cid) {
         // new post - post it to the group as well
         $g->post_content($post->content_id, $uid);
     }
     return array("cid" => (int) $post->content_id, "moderation_required" => $g ? $g->is_moderated == 1 && $g->author_id != $uid : FALSE, "errors" => $errors);
 }
     case 'CNBlogPost':
     default:
         $post_saved = CNBlogPost::save_blogpost(0, PA::$login_uid, $_POST["blog_title"], $_POST["description"], NULL, $terms, $ccid, 1, $display_on_homepage);
         break;
 }
 $permalink_cid = $post_saved['cid'];
 if (PA::is_moderated_content() && PA::$network_info->owner_id != $user->user_id) {
     Network::moderate_network_content(-1, $permalink_cid);
     // -1 for contents; not a part of any collection
     $error_msg = "&err=" . urlencode(MessagesHandler::get_message(1004));
 }
 $login_required_str = null;
 if (PA::is_moderated_content()) {
     $login_required_str = '&login_required=true';
 }
 $content_obj = CNContent::load_content((int) $permalink_cid);
 PANotify::send("content_posted", PA::$network_info, $user, $content_obj);
 if ($display_on_homepage == DISPLAY_ON_HOMEPAGE) {
     PANotify::send("content_posted_to_comm_blog", PA::$network_info, $user, $content_obj);
 }
 //for rivers of people
 $activity = 'user_post_a_blog';
 $activity_extra['info'] = $user->first_name . 'posted a new blog';
 $activity_extra['blog_name'] = $_POST["blog_title"];
 $activity_extra['blog_id'] = $permalink_cid;
 $activity_extra['blog_url'] = PA::$url . PA_ROUTE_CONTENT . '/cid=' . $permalink_cid . $login_required_str;
 $extra = serialize($activity_extra);
 $object = $permalink_cid;
 if (!PA::is_moderated_content()) {
     //Write to activity log only when moderation is off
     Activities::save($user->user_id, $activity, $object, $extra);
 function load_data($error_msg = '')
 {
     $this->categories = Category::build_all_category_list();
     if (!empty($error_msg)) {
         $this->error_msg = $error_msg;
     }
     if ($this->id == 0) {
         $this->title = __('Add Blog Post');
         return;
     } else {
         $this->title = '';
         $content = CNContent::load_content((int) $this->id, $_SESSION['user']['id']);
         $content_tags = Tag::load_tags_for_content((int) $this->id);
         $this->blog_title = stripslashes($content->title);
         $this->blog_type = stripslashes($content->type);
         $this->body = stripslashes($content->body);
         $this->trackback = $content->trackbacks;
         $this->collection_id = $content->collection_id;
         if (count($content_tags)) {
             foreach ($content_tags as $tag) {
                 $out[] = $tag['name'];
             }
             $this->tag_entry = implode(', ', $out);
         }
     }
 }
require_once "api/CNContent/CNContent.php";
PA::$network_info = Network::get_network_by_address(CURRENT_NETWORK_URL_PREFIX);
// hack: do this here to avoid having to include page.php and friends
$uid = (int) $_GET['uid'];
$gid = (int) $_GET['gid'];
$type = $_GET['type'];
if ($uid) {
    $feed = Content::get_content_feed_for_user($uid, 5);
} else {
    if ($gid) {
        $group = ContentCollection::load_collection((int) $gid);
        $contents = $group->get_contents_for_collection($type = 'all', $cnt = FALSE, 5, 1, 'created', 'DESC');
        $content_ids = array();
        foreach ($contents as $i => $con) {
            $content_ids[] = $con['content_id'];
        }
        $feed = Content::get_feed_for_content($content_ids);
    } else {
        if ($type == 'all') {
            $feed = CNContent::get_content_feed_for_user();
        } else {
            header("HTTP/1.0 404 Not Found");
            ?>
No feed available at this address.  Were you looking for <a href="/cnfeed.php?type=all">the community blog feed</a>?
    <?php 
            exit;
        }
    }
}
header("Content-Type: application/xml");
print $feed;
require_once "web/includes/authorize.inc.php";
$permission_to_post = $task_perm;//set from authorize.inc.php
*/
$user = get_user();
$_GET = url_decode_all($_GET);
$_POST = url_decode_all($_POST);
$_REQUEST = url_decode_all($_REQUEST);
//filter_all_post($_POST);
// check to see if we are here for edit and user has permissions to do it
if ($cid = $_REQUEST['cid']) {
    $params = array('permissions' => 'edit_content', 'uid' => PA::$login_uid, 'cid' => $cid);
    if (!PermissionsHandler::can_user(PA::$login_uid, $params)) {
        header("Location: " . PA::$url . PA_ROUTE_HOME_PAGE . "/msg=" . urlencode('Error: You are not authorized to access this page.'));
        exit;
    }
    $obj_content_type = CNContent::load_content((int) $cid, PA::$login_uid);
    // this content will be used for edit mode
    if ($obj_content_type->type == 'CNBlogPost') {
        unset($_REQUEST["sb_mc_type"]);
    }
    //tells edit mode
    $is_edit = 1;
    $parent_collection_id = $obj_content_type->parent_collection_id;
} else {
    //tells create first time mode
    $cid = 0;
    $is_edit = 0;
}
//take care of content collection in case of ccid
//right now a user can come from groups.php page to create post in that group
// Then it will have ccid associated with it.
 /**
  * Generate the RssFeed for the selected items using DomDocument functions
  * @param $row This $row is having the contents of all required rows
  * @return $this->saveXml() This is saving all xml string and return this string for the further process
  */
 public function generate_rss($row, $user_id)
 {
     Logger::log("Enter: RssFeedHelper::generate_rss");
     $format = 'D, j M Y H:m:s O';
     $rss = $this->createElement('rss');
     $attrib1 = $rss->setAttribute("xmlns:content", "http://purl.org/rss/1.0/modules/content/");
     $attrib = $rss->setAttribute("version", "2.0");
     $root = $this->createElement("channel");
     $user = new User();
     if ($user_id == '0') {
         $name1 = $this->createElement("title");
         $name1->appendChild($this->createTextNode(sprintf(__("Latest posts from %s"), PA::$network_info->name)));
         $root->appendChild($name1);
         $body1 = $this->createElement("description");
         $body1->appendChild($this->createTextNode(sprintf(__("Newest posts from everyone on %s"), PA::$network_info->name)));
         $root->appendChild($body1);
         $url1 = $this->createElement("link");
         $url1->appendChild($this->createTextNode(PA::$url));
         $root->appendChild($url1);
     } else {
         if (!empty($row[0])) {
             //TODO: figure out why we are getting a single empty row
             $user->load((int) $row[0]->author_id);
         } else {
             $user->load((int) $user_id);
         }
         $name1 = $this->createElement("title");
         $name1->appendChild($this->createTextNode(sprintf(__("%s: %s blog"), $user->first_name, PA::$network_info->name)));
         $root->appendChild($name1);
         $body1 = $this->createElement("description");
         if ($user->last_name) {
             $body1->appendChild($this->createTextNode("{$user->first_name} {$user->last_name}'s Weblog"));
         } else {
             $body1->appendChild($this->createTextNode("{$user->first_name}'s Weblog"));
         }
         $root->appendChild($body1);
         $url1 = $this->createElement("link");
         $url1->appendChild($this->createTextNode(PA::$url . PA_ROUTE_USER_PUBLIC . '/' . $user->user_id));
         $root->appendChild($url1);
     }
     $changed = $this->createElement("lastBuildDate");
     $changed->appendChild($this->createTextNode(date($format, time())));
     $root->appendChild($changed);
     for ($i = 0; $i < count($row) - 1; $i++) {
         $node = $this->createElement("item");
         $name = $this->createElement("title");
         $name->appendChild($this->createTextNode($row[$i]->title));
         $body = $this->createElement("description");
         $body->appendChild($this->createTextNode(CNContent::_replace_percent_strings($row[$i]->content_id, $row[$i]->body, PA::$url)));
         $item_link = PA::$url . PA_ROUTE_CONTENT . "/cid=" . $row[$i]->content_id;
         $url = $this->createElement("link");
         $url->appendChild($this->createTextNode($item_link));
         $guid = $this->createElement("guid");
         $guid->appendChild($this->createTextNode($item_link));
         $created = $this->createElement("pubDate");
         $created->appendChild($this->createTextNode(date($format, $row[$i]->changed)));
         // getting the name of the author
         $sql = 'SELECT first_name FROM users WHERE user_id = ?';
         $data = array($row[$i]->author_id);
         $res = Dal::query($sql, $data);
         if ($res->numRows() > 0) {
             $result = $res->fetchRow(DB_FETCHMODE_OBJECT);
         }
         switch ($row[$i]->type) {
             case 7:
                 //             $video_content = $this->createElement( "media:content" );
                 //             $content_attrib = $video_content->setAttribute( "url", "$row[$i]->url" );
                 //             $content_attrib = $video_content->setAttribute( "filesize", "" );
                 //             $content_attrib = $video_content->setAttribute( "type", "Video" );
                 //             $content_attrib = $video_content->setAttribute( "medium", "Video" );
                 //             $node->appendChild( $video_content );
                 break;
         }
         $node->appendChild($name);
         $node->appendChild($body);
         $node->appendChild($url);
         $node->appendChild($guid);
         $node->appendChild($created);
         $root->appendChild($node);
     }
     $rss->appendChild($root);
     $this->appendChild($rss);
     Logger::log("Exit: RssFeedHelper::generate_rss");
     return $this->saveXml();
 }
 public static function get_recent_posts($params = NULL, $conditions = NULL)
 {
     Logger::log("Enter: function CNContent::get");
     $sql = " SELECT * FROM {contents} AS C , {recent_media_track} AS RT WHERE RT.cid=C.content_id AND C.is_active = 1 ";
     if ($conditions) {
         $sql = $sql . ' AND ' . $conditions;
     }
     $sort_by = $params['sort_by'] ? $params['sort_by'] : 'C.created';
     $direction = $params['direction'] ? $params['direction'] : 'DESC';
     $order_by = ' ORDER BY ' . $sort_by . ' ' . $direction;
     if (!empty($params['page']) && !empty($params['show']) && empty($params['cnt'])) {
         $start = ($params['page'] - 1) * $params['show'];
         $limit = ' LIMIT ' . $start . ',' . $params['show'];
     } else {
         $limit = "";
     }
     $sql = $sql . $order_by . $limit;
     $res = Dal::query($sql);
     if (!empty($params['cnt']) && $params['cnt'] == TRUE) {
         return $res->numRows();
     }
     $i = 0;
     $content_id = array();
     while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
         $content_id[$i] = array('content_id' => $row['content_id'], 'collection_id' => $row['collection_id'], 'title' => $row['title'], 'body' => $row['body'], 'author_id' => $row['author_id'], 'type' => $row['type'], 'changed' => $row['changed'], 'created' => $row['created'], 'is_active' => $row['is_active']);
         $i++;
     }
     $contents = array();
     foreach ($content_id as &$_content) {
         if (!CNContent::check_content_privacy($_content)) {
             // check is content from a  private Group
             $contents[] = $_content;
         }
     }
     //    echo '<pre>'.print_r($cont,1).'</pre>';
     Logger::log("Exit: function CNContent::get");
     return $contents;
 }
 /**
       Purpose : this function is used to get navigation links for the whole page.
       Scope : public
       @param - it needs no direct input. But works only on the basis of current page initialized in __construct()
       @return - array of links
      * */
 public function get_links($optional = NULL)
 {
     //initialization
     global $dynamic_page;
     if (isset($_SESSION['user']['id'])) {
         $extra = unserialize($this->network_info->extra);
         if (@$extra['reciprocated_relationship'] == NET_YES) {
             $status = APPROVED;
         } else {
             $status = FALSE;
         }
         $relations_ids = Relation::get_relations((int) $_SESSION['user']['id'], $status, PA::$network_info->network_id);
         $user_groups = Group::get_user_groups((int) $_SESSION['user']['id']);
         /* $gid isn't defined in this function, so the following call
          * will probably always return FALSE.  To get rid of the warning
          * under E_ALL, I've replaced the following expression with
          * FALSE.  Maybe $gid should be get_group_id()? */
         $is_owner_of_group = FALSE;
         //Group::is_admin($gid,(int)$_SESSION['user']['id']) ;
     }
     if (isset($relations_ids) && sizeof($relations_ids)) {
         $this->set_friend_uid($relations_ids[0]);
     }
     if (isset($user_groups) && sizeof($user_groups)) {
         $this->users_first_group_id($user_groups[0]['gid']);
     }
     if (PA::$login_uid) {
         $this->set_uid(PA::$login_uid);
     } else {
         $this->set_anonymous();
     }
     $is_group_content = FALSE;
     if (@$_GET['gid']) {
         $this->set_group_id($_GET['gid']);
     } else {
         if ((FILE_FORUM_MESSAGES == $this->current_page || FILE_CONTENT == $this->current_page) && !empty($_REQUEST['ccid']) && $_REQUEST['ccid'] > 0) {
             $this->set_group_id($_REQUEST['ccid']);
             $is_group_content = TRUE;
         } else {
             if (PAGE_PERMALINK == $this->current_page && !empty($_GET['cid'])) {
                 try {
                     $content_data = CNContent::load_content($_GET['cid'], $this->get_uid());
                 } catch (CNException $e) {
                     if ($e->getCode() != CONTENT_NOT_FOUND) {
                         throw $e;
                     }
                 }
                 if (isset($content_data)) {
                     if ($content_data->parent_collection_id > 0) {
                         $content_collection_data = ContentCollection::load_collection($content_data->parent_collection_id, $this->get_uid());
                         if ($content_collection_data->type == GROUP_COLLECTION_TYPE) {
                             $this->set_group_id($content_data->parent_collection_id);
                             $is_group_content = TRUE;
                         }
                     }
                 }
             }
         }
     }
     //test
     //$this->current_page='test.php';
     // make links for current page
     $this->make_links();
     $level_1 = $this->get_level_1();
     $level_2 = $this->get_level_2();
     $level_3 = NULL;
     $left_user_public_links = NULL;
     if (Network::is_admin($this->network_info->network_id, (int) @$_SESSION['user']['id'])) {
         $level_3 = $this->get_level_3('network');
     } else {
         if (!$this->network_info && $_SESSION['user']['id'] == SUPERUSER) {
             $level_3 = $this->get_level_3('network');
         }
     }
     $level_3 = NULL;
     switch ($this->current_page) {
         /* ---------------------------------------------------- */
         case PAGE_HOMEPAGE:
             $level_3 = NULL;
             $level_2['highlight'] = 'home';
             break;
         case FILE_LOGIN:
             $level_2['highlight'] = 'home';
             break;
         case PAGE_SEARCH:
             //fix by Zoran Hron: constants FILE_SEARCH_HOME and FILE_SHOWCONTENT points to the same value !!!
             if (!empty($_GET['gid'])) {
                 $level_2['highlight'] = 'groups';
                 $level_3 = $this->get_level_3(array('type' => 'groups', 'sub_type' => 'groups_general'));
             } else {
                 if (!empty($_GET['btn_searchContent'])) {
                     $level_2['highlight'] = 'search';
                 } else {
                     $level_3 = NULL;
                     $level_2['highlight'] = 'home';
                 }
             }
             break;
         case FILE_TAG_SEARCH:
             $level_2['highlight'] = 'tag_search';
             break;
             /* ---------------------------------------------------- */
         /* ---------------------------------------------------- */
         case PAGE_USER_PRIVATE:
             global $app;
             $app->setRequestParam('uid', PA::$login_uid, 'POST');
         case PAGE_USER_PUBLIC:
         case PAGE_USER_PRIVATE:
             if (!PA::$page_uid && !PA::$login_uid) {
                 throw new CNException("", "Invalid page access");
             }
             if (PA::$page_uid) {
                 //uid get variable set
                 //these links are to be added in front
                 $def_relations_term = 'Friend';
                 if (isset($extra['relationship_show_mode']['term'])) {
                     $def_relations_term = $extra['relationship_show_mode']['term'];
                 }
                 $relation_already_exists_links = array('send_message' => array('caption' => __('Send a message'), 'url' => $this->base_url . PA_ROUTE_ADDMESSAGE . '/uid=' . PA::$page_uid), 'change_relationship' => array('caption' => __('Change Relation'), 'url' => $this->base_url . PA_ROUTE_EDIT_RELATIONS . '/uid=' . PA::$page_uid . '&amp;do=change&amp;action=EditRelation'), 'delete_relationship' => array('caption' => sprintf(__('Delete as %s'), __($def_relations_term)), 'url' => $this->base_url . PA_ROUTE_EDIT_RELATIONS . '/do=delete&amp;uid=' . PA::$page_uid . '&amp;action=EditRelation', 'extra' => ' onclick ="return delete_confirmation_msg(\'' . __('Are you sure you want to delete this Relationship?') . '\') "'));
                 $relation_does_not_exists_links = array('send_message' => array('caption' => __('Send a message'), 'url' => $this->base_url . PA_ROUTE_ADDMESSAGE . '/uid=' . PA::$page_uid), 'make_connection' => array('caption' => sprintf(__('Add as %s'), __($def_relations_term)), 'url' => $this->base_url . PA_ROUTE_EDIT_RELATIONS . '/uid=' . PA::$page_uid . '&amp;do=add&amp;action=EditRelation'));
                 if (PA::$page_uid == PA::$login_uid) {
                     //login and get uid same means user's public page
                     $level_2['highlight'] = 'user';
                     $level_3 = $this->get_level_3('user');
                 } else {
                     // make left and right links
                     //user's public page requires different link rendering
                     if (!empty($relations_ids)) {
                         if (in_array(PA::$page_uid, $relations_ids)) {
                             $left_user_public_links = $relation_already_exists_links;
                         } else {
                             $left_user_public_links = $relation_does_not_exists_links;
                         }
                     } else {
                         $left_user_public_links = $relation_does_not_exists_links;
                     }
                 }
             } else {
                 //means user's private page
                 $level_2['highlight'] = 'user';
                 $level_3 = $this->get_level_3('user');
                 $level_3['highlight'] = 'user_private';
             }
             break;
             /* ---------------------------------------------------- */
         /* ---------------------------------------------------- */
         case PAGE_PEOPLES:
             $level_2['highlight'] = 'people';
             $level_3 = $this->get_level_3('people');
             $level_3['highlight'] = 'find_people';
             break;
             /* ---------------------------------------------------- */
         /* ---------------------------------------------------- */
         case PAGE_FAMILY:
         case PAGE_FAMILY_EDIT:
             $level_3 = $this->get_level_3('family');
             break;
             /* ---------------------------------------------------- */
         /* ---------------------------------------------------- */
         case FILE_VIEW_ALL_MEMBERS:
             if (@$_GET['gid']) {
                 $level_2['highlight'] = 'groups';
                 $level_3 = $this->get_level_3(array('type' => 'groups', 'sub_type' => 'group_specific'));
                 $level_3['highlight'] = 'group_members';
             } else {
                 $level_2['highlight'] = 'people';
                 if (PA::$page_uid == PA::$login_uid) {
                     $level_3 = $this->get_level_3('people');
                     if (!empty($_GET['view_type']) && $_GET['view_type'] == 'relations') {
                         $level_3['highlight'] = 'my_friends';
                     } else {
                         if (!empty($_GET['view_type']) && $_GET['view_type'] == 'in_relations') {
                             $level_3['highlight'] = 'people_who_call_me_friend';
                         } else {
                             $level_3['highlight'] = 'find_people';
                         }
                     }
                 }
             }
             break;
             /* ---------------------------------------------------- */
         /* ---------------------------------------------------- */
         case FILE_INVITATION:
             $level_2['highlight'] = 'people';
             $level_3 = $this->get_level_3('people');
             $level_3['highlight'] = 'invite';
             break;
             /* ---------------------------------------------------- */
         /* ---------------------------------------------------- */
         case FILE_UPLOAD_MEDIA:
         case PAGE_MEDIA_GALLERY:
             if (PA::$login_uid) {
                 if (isset($_GET['view']) && 'groups_media' == $_GET['view']) {
                     //user is viewing group gallery
                     $level_2['highlight'] = 'groups';
                     $level_3 = $this->get_level_3(array('type' => 'groups', 'sub_type' => 'group_specific'));
                     $level_3['highlight'] = 'group_gallery';
                 } else {
                     if (isset($_GET['view']) && 'friends' == $_GET['view']) {
                         //user is viewing his friends gallery
                         $level_2['highlight'] = 'people';
                         $level_3 = $this->get_level_3('people');
                         $level_3['highlight'] = 'friends_gallery';
                     } else {
                         if (PA::$page_uid != PA::$login_uid && PA::$page_uid != '') {
                             //user is viewing his private page gallery
                             $level_2['highlight'] = 'people';
                         } else {
                             if (PA::$page_uid == PA::$login_uid || !PA::$page_uid) {
                                 $level_2['highlight'] = 'user';
                                 $level_3 = $this->get_level_3('user');
                                 $level_3['highlight'] = 'my_gallery';
                             }
                         }
                     }
                 }
             } else {
                 if (!empty(PA::$page_uid)) {
                     // for anonymous user
                     $level_2['highlight'] = 'people';
                 }
             }
             break;
             /* ---------------------------------------------------- */
         /* ---------------------------------------------------- */
         case PAGE_USER_CUSTOMIZE_UI:
             $level_2['highlight'] = 'user';
             $level_3 = $this->get_level_3('user');
             $level_3['highlight'] = 'customize_ui';
             break;
         case FILE_USER_CALENDAR:
             $level_2['highlight'] = 'user';
             $level_3 = $this->get_level_3('user');
             $level_3['highlight'] = 'my_events';
             break;
         case PAGE_EDIT_PROFILE:
             $level_2['highlight'] = 'user';
             $level_3 = $this->get_level_3('user');
             $level_3['highlight'] = 'settings';
             break;
             /* ---------------------------------------------------- */
         /* ---------------------------------------------------- */
         case FILE_EDIT_RELATIONS:
             $level_2['highlight'] = 'people';
             $level_3 = $this->get_level_3('people');
             $level_3['highlight'] = 'find_people';
             break;
             /* ---------------------------------------------------- */
         /* ---------------------------------------------------- */
         case PAGE_GROUPS_HOME:
             $level_2['highlight'] = 'groups';
             $level_3 = $this->get_level_3(array('type' => 'groups', 'sub_type' => 'groups_general'));
             $level_3['highlight'] = 'find_groups';
             break;
             /* ---------------------------------------------------- */
         /* ---------------------------------------------------- */
         case FILE_GROUPS_CATEGORY:
             $level_2['highlight'] = 'groups';
             $level_3 = $this->get_level_3(array('type' => 'groups', 'sub_type' => 'groups_general'));
             $level_3['highlight'] = 'find_groups';
             break;
             /* ---------------------------------------------------- */
         /* ---------------------------------------------------- */
         case FILE_ADDGROUP:
             $level_2['highlight'] = 'groups';
             if (!empty($_GET['gid'])) {
                 $level_3 = $this->get_level_3(array('type' => 'groups', 'sub_type' => 'group_specific'));
                 $level_3['highlight'] = 'edit_group';
             } else {
                 $level_3 = $this->get_level_3(array('type' => 'groups', 'sub_type' => 'groups_general'));
                 $level_3['highlight'] = 'create_group';
             }
             break;
             /* ---------------------------------------------------- */
         /* ---------------------------------------------------- */
         case PAGE_GROUP:
         case PAGE_GROUP_AD_CENTER:
         case FILE_GROUP_MEDIA_GALLERY:
         case FILE_GROUP_CALENDAR:
         case FILE_GROUP_INVITATION:
         case PAGE_GROUP_THEME:
         case PAGE_GROUP_MODERATION:
         case FILE_MANAGE_GROUP_CONTENTS:
             $level_2['highlight'] = 'groups';
             $level_3 = $this->get_level_3(array('type' => 'groups', 'sub_type' => 'group_specific'));
             break;
         case FILE_ADDGROUP:
             $level_2['highlight'] = 'group';
             if ($_GET['gid']) {
                 $level_3 = $this->get_level_3(array('type' => 'groups', 'sub_type' => 'group_specific'));
                 $level_3['highlight'] = 'edit_group';
             } else {
                 $level_3 = $this->get_level_3(array('type' => 'groups', 'sub_type' => 'groups_general'));
                 $level_3['highlight'] = 'create_group';
             }
             break;
             /* ---------------------------------------------------- */
         /* ---------------------------------------------------- */
         case FILE_WIDGET:
             $level_2['highlight'] = 'user';
             $level_3 = $this->get_level_3('user');
             $level_3['highlight'] = 'user_widgets';
             break;
             /* ---------------------------------------------------- */
         /* ---------------------------------------------------- */
         case PAGE_MESSAGE:
         case PAGE_ADDMESSAGE:
         case PAGE_VIEW_MESSAGE:
             $level_2['highlight'] = 'user';
             $level_3 = $this->get_level_3('user');
             $level_3['highlight'] = 'messages';
             break;
             /* ---------------------------------------------------- */
         /* ---------------------------------------------------- */
         case FILE_POST_CONTENT:
             $level_2['highlight'] = 'user';
             $level_3 = $this->get_level_3('user');
             $level_3['highlight'] = 'create_post';
             break;
             /* ---------------------------------------------------- */
         /* ---------------------------------------------------- */
         case FILE_CONTENT_MANAGEMENT:
             $level_2['highlight'] = 'user';
             $level_3 = $this->get_level_3('user');
             $level_3['highlight'] = 'manage_posts';
             break;
             /* ---------------------------------------------------- */
         /* ---------------------------------------------------- */
         case FILE_NETWORKS_HOME:
         case FILE_NETWORKS_CATEGORY:
             $level_1['highlight'] = 'networks_directory';
             break;
             /* ---------------------------------------------------- */
         /* ---------------------------------------------------- */
         case FILE_NETWORK_USER_DEFAULTS:
         case FILE_RELATIONSHIP_SETTINGS:
         case FILE_EMAIL_NOTIFICATION:
         case FILE_MANAGE_TAKETOUR:
         case FILE_MANAGE_EMBLEM:
         case FILE_CONFIGURE_SPLASH_PAGE:
         case FILE_NETWORK_FEATURE:
         case FILE_NETWORK_CUSTOMIZE_UI_PAGE:
         case FILE_NETWORK_CONFIGURE:
         case FILE_NETWORK_LINKS:
         case FILE_NEW_USER_BY_ADMIN:
         case FILE_NETWORK_MANAGE_CONTENT:
         case FILE_MODULE_SELECTOR:
         case FILE_NETWORK_BULLETINS:
         case FILE_NETWORK_MANAGE_USER:
         case FILE_NETWORK_CALENDAR:
         case FILE_MANAGE_AD_CENTER:
         case FILE_MANAGE_GROUP_FORUM:
         case FILE_MANAGE_COMMENTS:
         case FILE_RANKING:
         case FILE_MISREPORTS:
         case PAGE_ROLE_MANAGE:
         case FILE_ASSIGN_TASK:
             $level_2 = $this->get_level_3('network');
             $level_1['highlight'] = 'configure_network';
             $level_2['highlight'] = 'configure_network';
             break;
         case FILE_CREATENETWORK:
             $level_1['highlight'] = 'create_network';
             $level_3['highlight'] = 'statistics';
             break;
             /* ---------------------------------------------------- */
         /* ---------------------------------------------------- */
         case FILE_SHOWCONTENT:
             // remark by Zoran Hron: this never will be executed because
             // constants FILE_SEARCH_HOME and FILE_SHOWCONTENT points to the same value !!!
             if (!empty($_GET['gid'])) {
                 $level_2['highlight'] = 'groups';
                 $level_3 = $this->get_level_3(array('type' => 'groups', 'sub_type' => 'groups_general'));
             }
             break;
             /* ---------------------------------------------------- */
         /* ---------------------------------------------------- */
         case FILE_LINKS_MANAGEMENT:
             $level_2['highlight'] = 'user';
             break;
             /* ---------------------------------------------------- */
         /* ---------------------------------------------------- */
         case FILE_MEDIA_FULL_VIEW:
             if (!empty($_GET['gid'])) {
                 $level_2['highlight'] = 'groups';
                 $level_3 = $this->get_level_3(array('type' => 'groups', 'sub_type' => 'group_specific'));
             } else {
                 $level_2['highlight'] = 'user';
                 $level_3 = $this->get_level_3('user');
             }
             break;
         case FILE_REGISTER:
             $level_2['highlight'] = 'home';
             break;
         case FILE_EDIT_MEDIA:
             $level_2['highlight'] = 'user';
             $level_3 = $this->get_level_3('user');
             $level_3['highlight'] = 'my_gallery';
             break;
             /* ---------------------------------------------------- */
         /* ---------------------------------------------------- */
         case FILE_EDITNETWORK:
         case PAGE_PERMALINK:
             if ($is_group_content == TRUE) {
                 if ($this->get_uid()) {
                     $is_group_content = FALSE;
                     $level_2['highlight'] = 'groups';
                     $level_3 = $this->get_level_3(array('type' => 'groups', 'sub_type' => 'group_specific'));
                     $level_3['highlight'] = 'group_home';
                 } else {
                     $is_group_content = FALSE;
                     $level_2['highlight'] = 'groups';
                     $level_3 = $this->get_level_3(array('type' => 'groups', 'sub_type' => 'groups_general'));
                     $level_3['highlight'] = 'group_home';
                 }
             } elseif (!empty($_GET['cid'])) {
                 try {
                     $content_data = CNContent::load_content($_GET['cid'], $this->get_uid());
                     if ($content_data->parent_collection_id != -1 && $content_data->parent_collection_id != 0) {
                         $content_collection_data = ContentCollection::load_collection($content_data->parent_collection_id, $this->get_uid());
                         if ($content_collection_data->type == GROUP_COLLECTION_TYPE) {
                             $this->get_level_3(array('type' => 'groups', 'sub_type' => 'group_specific'));
                         }
                     } else {
                         $level_3 = $this->get_level_3('user');
                     }
                 } catch (CNException $e) {
                 }
             }
             break;
         default:
             break;
     }
     //--end of switch
     /* moved this code outside of the switch statement...
         we wabt this to run in any case, so that xml files can override default navigation!
         -Martin
        */
     if (isset($dynamic_page) && !empty($dynamic_page->navigation_code)) {
         if (false == eval($dynamic_page->navigation_code . "return true;")) {
             echo "<b>Evaluation of navigation links code for page ID={$dynamic_page->page_name} failed" . "Please check your dynamic page configuration file. Page ID: {$dynamic_page->page_id}";
         }
     }
     /* ------- */
     $menu = array('level_1' => $level_1, 'level_2' => $level_2, 'level_3' => $level_3, 'left_user_public_links' => $left_user_public_links);
     //    echo '<pre>'.print_r($menu,1).'</pre>';
     return $menu;
 }
 private function can_edit_content($params, $type)
 {
     $available_permiss = $this->get_available_permiss_by_type($params, $type);
     if (in_array('edit_content', $available_permiss)) {
         return true;
     }
     if (!empty($params['cid'])) {
         //Loading content
         $content_obj = CNContent::load_content((int) $params['cid'], $this->uid);
         //author of the content can perform the action
         if ($content_obj->author_id == $this->uid) {
             return true;
         }
         // content is a part of some collection
         if ($content_obj->parent_collection_id != -1) {
             // Loading collection
             $collection_obj = ContentCollection::load_collection((int) $content_obj->parent_collection_id, $this->uid);
             // owner of collection can also edit the content
             if ($collection_obj->author_id == $this->uid) {
                 return true;
             }
         }
     }
     return false;
 }
 function render()
 {
     if ($this->type == 'group') {
         $this->outer_template = 'outer_show_content_module_group.php';
         if ($this->content_type == NULL) {
             $this->content_type = 'all';
         }
         //$type = 'all',$cnt=FALSE, $show='ALL', $page=0, $sort_by='created', $direction='DESC'
         if (!empty($this->content_type)) {
             $this->Paging["count"] = $this->links = $this->group->get_contents_for_collection($this->content_type, TRUE, 10, 1, 'created', 'DESC', TRUE);
             $this->contents = $this->group->get_contents_for_collection($this->content_type, FALSE, $this->Paging["show"], $this->Paging["page"], 'created', 'DESC', TRUE);
         } else {
             $this->Paging["count"] = $this->links = $this->group->get_contents_for_collection($type = 'all', $cnt = TRUE, 'all', 0, $sort_by = 'created', $direction = 'DESC');
             $this->contents = $this->group->get_contents_for_collection($type = 'all', $cnt = FALSE, $this->Paging["show"], $this->Paging["page"], 'created', 'DESC');
         }
         $this->title = chop_string(sprintf(__("%s's Group Blog"), $this->group->title, 32));
     } else {
         if ($this->type == "tag") {
             $this->Paging["count"] = Tag::get_associated_content_ids((int) $this->tag_id, $cnt = TRUE);
             $this->contents = Tag::get_associated_content_ids((int) $this->tag_id, $cnt = FALSE, $this->Paging["show"], $this->Paging["page"]);
             if (!empty($this->contents)) {
                 foreach ($this->contents as $key => $value) {
                     $this->contents[$key]['content_id'] = $value['id'];
                 }
             }
         } else {
             if ($this->type == "search") {
                 $this->Paging["count"] = CNContent::content_search($this->search_string_array, $cnt = TRUE);
                 $this->contents = CNContent::content_search($this->search_string_array, $cnt = FALSE, $this->Paging["show"], $this->Paging["page"]);
             } else {
                 $this->Paging["count"] = CNContent::load_content_id_array($this->uid, $this->content_type, $cnt = TRUE);
                 $contents = CNContent::load_content_id_array($this->uid, $this->content_type, $cnt = FALSE, $this->Paging["show"], $this->Paging["page"]);
                 $this->contents = $contents;
             }
         }
     }
     $this->orientation = LEFT;
     if ($this->type == 'user') {
         $this->block_type = 'ShowContentUserBlock';
         // $this->do_pagination=TRUE;
     } else {
         if ($this->type == 'group') {
             if ($this->html_block_id_flag == 1) {
                 $this->block_type = 'ShowAllContent';
                 // $this->do_pagination=TRUE;
             } else {
                 $this->block_type = 'ShowContentGroupBlock';
             }
         } else {
             if ($this->type == "tag") {
                 $this->block_type = 'ShowAllContent';
                 // $this->do_pagination=TRUE;
             } else {
                 if ($this->type == "search") {
                     $this->block_type = 'ShowAllContent';
                     // $this->do_pagination=TRUE;
                 } else {
                     if ($this->show_all == 1) {
                         $this->block_type = 'ShowAllContent';
                         // $this->do_pagination=TRUE;
                     } else {
                         $this->block_type = 'ShowContentBlock';
                         // $this->do_pagination=TRUE;
                     }
                 }
             }
         }
     }
     $this->inner_HTML = $this->generate_inner_html($this->contents, $this->type);
     if ($this->do_pagination) {
         $CNPagination = new CNPagination();
         $CNPagination->setPaging($this->Paging);
         $this->page_first = $CNPagination->getFirstPage();
         $this->page_last = $CNPagination->getLastPage();
         $this->page_links = $CNPagination->getPageLinks();
     }
     $content = parent::render();
     return $content;
 }