function uihelper_generate_center_content_permalink($cid, $show = 0) { global $app; $image_media_gallery = FALSE; $back_page = PA::$url . $app->current_route; $content = Content::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 = Content::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 . "/center_comments.tpl"); $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 $comment_form_tpl = new Template(CURRENT_THEME_FSPATH . "/comment_form.tpl"); $comment_form_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; $comment_form_tpl->set('name', $login_name); $comment_form_tpl->set('login_name', $user->login_name); } $comment_form_tpl->set('cid', $cid); if ($content->parent_collection_id > 0) { $comment_form_tpl->set('ccid', $content->parent_collection_id); } // abuse form $abuse_form_tpl = new Template(CURRENT_THEME_FSPATH . "/abuse_form.tpl"); /* 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 . "/post_content.php?cid=" . $content->content_id; } $delete_link = PA::$url . PA_ROUTE_CONTENT . "?action=deleteContent&cid=" . $content->content_id . '&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" . '&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) { $comment_form = $comment_form_tpl->fetch(); $abuse_form = $abuse_form_tpl->fetch(); } else { $comment_form = $abuse_form = NULL; } if (getShadowedPath(CURRENT_THEME_FSPATH . "/{$type}.tpl")) { $middle_content = new Template(getShadowedPath(CURRENT_THEME_FSPATH . "/{$type}.tpl")); $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('comment_form', $comment_form); $middle_content->set('abuse_form', $abuse_form); $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 . '.tpl file to display this content type.</p>'; } return $return_content; }
$page_content =& new Template(CURRENT_THEME_FSPATH . "/view_comments.tpl"); //tpl for header $header =& new Template(CURRENT_THEME_FSPATH . "/header.tpl"); $header->set('user_name', $first_name . " " . $last_name); if ($network_info) { $header->set_object('network_info', $network_info); } $page_content->set('header', $header); //tpl for left side bar $left_panel =& new Template(CURRENT_THEME_FSPATH . "/left_page.tpl"); $left_panel->set('img_path', $img_path); $page_content->set('left_panel', $left_panel); $comments = Comment::get_comment_for_content($cid); $number_of_comments = count($comments); $content->no_of_comments = $number_of_comments; $trackback = Content::get_trackbacks_for_content($cid); $content->trackback_url = "{$base_url}/pa_trackback.php?cid=" . $cid; $content_user = new User(); $content_user->load((int) $content->author_id); $time = content_date($content->changed); $content->author_name = '<a href="user.php?uid=' . $content_user->user_id . '">' . $content_user->first_name . '</a>'; $content->create_time = content_date($content->changed); $tags = Tag::load_tags_for_content($cid); if ($tags) { $t = array(); for ($i = 0; $i < count($tags); $i++) { $name = $tags[$i]['name']; $uid = $_SESSION['user']['id']; $t[] = "<a href=\"tags.php?uid={$uid}&tagname={$name}\">" . $tags[$i]['name'] . "</a>"; } $tag_string = "<b>Tags : </b>" . implode(", ", $t);
require_once "BlockModules/PopularTagsModule/PopularTagsModule.php"; include_once "../api/Theme/Template.php"; require_once '../api/Content/Content.php'; require_once '../api/Comment/Comment.php'; include_once "../api/ModuleSetting/ModuleSetting.php"; require_once './includes/functions/html_generate.php'; $parameter = '<script type="text/javascript" language="javascript" src="' . $current_theme_path . '/base_javascript.js"></script></script> <script type="text/javascript" language="javascript" src="' . $current_theme_path . '/javascript/prototype.js"></script> <script type="text/javascript" language="javascript" src="' . $current_theme_path . '/javascript/scriptaculous.js"></script>'; html_header("PA-block_test", $parameter); print '<body style="background-color: #336799;">'; default_exception(); $contents = Content::load_content_id_array(); for ($i = 0; $i < count($contents); $i++) { $contents[$i]['comments'] = Comment::get_comment_for_content($contents[$i]['content_id']); $contents[$i]['trackback'] = Content::get_trackbacks_for_content($contents[$i]['content_id']); $user1 = new User(); // *** FIXME: it looks like user::load used to take a second param // *** that determined whether it would load deleted users or not. // *** this disappeared a long time ago, though, and in the meantime // *** a new second param has appeared, that indicates the type of // *** the first param. so if anyone wants to put this back, feel // *** free... until then, the following code may not work as // *** expected: // Here second parameter of load_user_name is 0 it is is_active = 0 // (it will load all users name of People aggregator whether user // has been deleted or exist) $user1->load((int) $contents[$i]['author_id']); //, 0); $contents[$i]['author_name'] = '<a href="user.php?uid=' . $user1->user_id . '">' . $user1->first_name . '</a>'; //$contents[$i]['create_time'] = content_date($contents[$i]['changed']);
function testAddDeleteContentComments() { // Dal::register_query_callback("explain_query"); echo "getting a user\n"; $user = Test::get_test_user(); echo "test user = {$user->first_name} {$user->last_name}\n"; echo "adding some content\n"; $post = new BlogPost(); $post->author_id = $user->user_id; $post->parent_collection_id = -1; $post->title = "Test blog post (from testAddDeleteContentComments)"; $post->body = "<p>This is the post body!</p><p>Foo <b>foo</b> foo</p>"; $post->allow_comments = 1; $post->is_active = 1; $post->display_on = DISPLAY_ON_HOMEPAGE; $post->save(); echo "... saved as content_id={$post->content_id}\n"; echo "testing that it is retrievable\n"; $post_retr = Content::load_content($post->content_id, $user->user_id); $this->assertEquals($post_retr->content_id, $post->content_id); $this->assertEquals($post_retr->title, $post->title); $this->assertEquals($post_retr->body, $post->body); $this->assertEquals($post_retr->author_id, $user->user_id); $this->assertEquals($post_retr->is_active, 1); echo "posting a comment\n"; $cmt = new Comment(); $cmt->content_id = $post->content_id; $cmt_comment = "This is an automatic comment - on an autogenerated post"; $cmt->comment = $cmt_comment; $cmt->user_id = $user->user_id; $cmt->name = $cmt->email = $cmt->homepage = ''; $cmt->ip_addr = '127.0.0.1'; $cmt->referrer = 'http://example.com/'; $cmt->user_agent = 'phpunit auto-test'; $cmt->save(); echo "... saved as comment_id={$cmt->comment_id}\n"; echo "testing that the comment is retrievable\n"; $cmt_retr = new Comment(); $cmt_retr->load($cmt->comment_id); $this->assertEquals($cmt_retr->comment_id, $cmt->comment_id); $this->assertEquals($cmt_retr->content_id, $post->content_id); $this->assertEquals($cmt_retr->comment, $cmt_comment); $this->assertEquals($cmt_retr->is_active, 1); echo "testing that we see one comment on the post\n"; $comments = Comment::get_comment_for_content($post->content_id); echo count($comments) . " comments\n"; //var_dump($comments); $this->assertEquals(count($comments), 1); echo "testing that we have no trackbacks on the post\n"; $trackbacks = Content::get_trackbacks_for_content($post->content_id); echo count($trackbacks) . " trackbacks\n"; //var_dump($trackbacks); $this->assertEquals(count($trackbacks), 0); echo "posting ANOTHER comment\n"; $cmt2 = new Comment(); $cmt2->content_id = $post->content_id; $cmt2_comment = "This is ANOTHER automatic comment - on the same autogenerated post"; $cmt2->comment = $cmt_comment; $cmt2->user_id = $user->user_id; $cmt2->name = $cmt2->email = $cmt2->homepage = ''; $cmt2->ip_addr = '127.0.0.1'; $cmt2->referrer = 'http://example.com/'; $cmt2->user_agent = 'phpunit auto-test'; $cmt2->save(); echo "... saved as comment_id={$cmt2->comment_id}\n"; echo "testing that we see two comments on the post\n"; $comments = Comment::get_comment_for_content($post->content_id); $this->assertEquals(count($comments), 2); echo "deleting the first comment\n"; $cmt_retr->delete(); echo "testing that we see one comment on the post again (not seeing the deleted one)\n"; $comments = Comment::get_comment_for_content($post->content_id); $this->assertEquals(count($comments), 1); echo "testing that the first comment (now deleted) is not retrievable\n"; $cmt_retr_fail = new Comment(); try { $cmt_retr_fail->load($cmt->comment_id); $this->assertTrue(FALSE); // shouldn't get here } catch (PAException $e) { $this->assertEquals($e->getCode(), COMMENT_NOT_EXIST); } echo "deleting the post\n"; Content::delete_by_id($post->content_id); echo "testing that the post is not retrievable\n"; try { $post_retr_fail = Content::load_content($post->content_id, $user->user_id); $this->assertTrue(FALSE); // shouldn't get here } catch (PAException $e) { $this->assertEquals($e->getCode(), CONTENT_NOT_FOUND); } echo "testing that the last comment is not retrievable\n"; $cmt_retr_fail = new Comment(); try { $cmt_retr_fail->load($cmt->comment_id); $this->assertTrue(FALSE); // shouldn't get here } catch (PAException $e) { $this->assertEquals($e->getCode(), COMMENT_NOT_EXIST); } // summarize_timed_queries(); }