function render()
 {
     if ($this->block_type == 'usercomments') {
         $links = Comment::get_comment_for_user($this->uid, 5);
     } else {
         $links = Comment::get_comment_for_content(NULL, $count = 5, 'DESC', TRUE);
     }
     $this->inner_HTML = $this->generate_inner_html($links);
     $content = parent::render();
     return $content;
 }
 function render()
 {
     $links = array();
     if ($this->page_id == PAGE_USER_PUBLIC) {
         $links = Comment::get_comment_for_user(PA::$page_uid, 5);
     } else {
         if ($this->page_id == PAGE_USER_PRIVATE) {
             $relations_ids = Relation::get_all_relations((int) PA::$login_uid, 0, FALSE, 'ALL', 0, 'created', 'DESC', 'internal', APPROVED, PA::$network_info->network_id);
             $tmp_links = array();
             foreach ($relations_ids as $relation) {
                 $tmp_links[] = Comment::get_comment_for_user((int) $relation['user_id'], 5);
             }
             $cnt = 0;
             $links = array();
             $link_cnts = array();
             do {
                 foreach ($tmp_links as $idx => $rel_links) {
                     if (empty($link_cnts[$idx])) {
                         $link_cnts[$idx] = 0;
                     }
                     if (isset($rel_links[$link_cnts[$idx]])) {
                         $links[] = $rel_links[$link_cnts[$idx]++];
                         $cnt++;
                     }
                     if ($cnt >= 5) {
                         break;
                     }
                 }
             } while ($cnt++ <= 5);
         } else {
             $links = Comment::get_comment_for_content(NULL, $count = 5, 'DESC', TRUE);
         }
     }
     foreach ($links as &$link) {
         if (!empty($link['content_id'])) {
             $post = Content::load_content((int) $link['content_id'], PA::$login_uid);
             $link['post_title'] = $post->title;
         } else {
             $link['post_title'] = __('No title');
         }
     }
     $this->inner_HTML = $this->generate_inner_html($links);
     $content = parent::render();
     return $content;
 }
Ejemplo n.º 3
0
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;
}
Ejemplo n.º 4
0
 /**
  * loads array of all content-id in decreasing order of their edition,
  *for network operator control, network content management
  * @access public
  * @param int user id
  * @param int count
  * @param string sort factor.
  */
 public static function load_all_content_id_array($cnt = FALSE, $show = 'ALL', $page = 0, $sort_by = 'created', $direction = 'DESC', $condition = NULL)
 {
     Logger::log("Enter: Content::load_all_content_id_array()");
     $order_by = $sort_by . ' ' . $direction;
     //setting limits for pagination
     if ($show == 'ALL' || $cnt == TRUE) {
         $limit = '';
     } else {
         $start = ($page - 1) * $show;
         $limit = 'LIMIT ' . $start . ',' . $show;
     }
     if ($condition['keyword'] || $condition['month']) {
         //setting constraints
         $data = '%' . $condition['keyword'] . '%';
         $month = $condition['month'];
         //finding date limits
         $first_day_of_month = strtotime("-" . (date("d", $month) - 1) . " days", $month);
         $last_day_of_month = strtotime("+" . (date("t", $first_day_of_month) - 1) . " days", $first_day_of_month);
         if (date('M', $month) == date('M', time())) {
             $last_day_of_month = time();
         }
     }
     if ($condition['keyword'] && $condition['month']) {
         //if something is searched, show respective contents
         $sql = "SELECT CT.name AS content_name, C.content_id, C.collection_id, C.title, C.body, C.type, C.author_id, C.changed, C.created FROM {contents} AS C, {content_types} AS CT WHERE C.title LIKE ? AND C.is_active = ?  AND CT.type_id = C.type  AND C.created BETWEEN {$first_day_of_month} AND {$last_day_of_month} ORDER BY {$order_by} {$limit} ";
         $data = array($data, ACTIVE);
     } else {
         if (empty($condition['keyword']) && !empty($condition['month'])) {
             //if nothing is searched, show all contents
             $sql = "SELECT CT.name AS content_name, C.content_id, C.collection_id, C.title, C.body, C.type, C.author_id, C.changed, C.created FROM {contents} AS C, {content_types} AS CT WHERE  C.is_active = ?  AND C.created BETWEEN {$first_day_of_month} AND {$last_day_of_month} AND  CT.type_id = C.type ORDER BY {$order_by} {$limit} ";
             $data = array(ACTIVE);
         } else {
             if (empty($condition['keyword']) && empty($condition['month'])) {
                 $sql = "SELECT CT.name AS content_name, C.content_id, C.collection_id, C.title, C.body, C.type, C.author_id, C.changed, C.created FROM {contents} AS C, {content_types} AS CT WHERE  C.is_active = ?  AND  CT.type_id = C.type ORDER BY {$order_by} {$limit} ";
                 $data = array(ACTIVE);
             }
         }
     }
     $res = Dal::query($sql, $data);
     if ($cnt) {
         if ($res->numRows() > 0) {
             return $res->numRows();
         }
     }
     $content_data = array();
     // preparing array, that is to be returned
     if ($res->numRows()) {
         $i = 0;
         while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
             try {
                 $author = new User();
                 $author->load((int) $row['author_id']);
                 if ($row['collection_id'] != -1) {
                     $var = new ContentCollection();
                     $var->load((int) $row['collection_id']);
                     $collection['title'] = $var->title;
                     $collection['type'] = $var->type;
                 } else {
                     $collection = array();
                 }
                 $comment_for_content = Comment::get_comment_for_content($row['content_id']);
                 $content_data[$i] = array('content_id' => $row['content_id'], 'title' => $row['title'], 'body' => $row['body'], 'author_id' => $row['author_id'], 'type' => $row['content_name'], 'changed' => $row['changed'], 'created' => date("j M Y  H:i:s", $row['created']), 'type_name' => @$row['name'], 'comment_count' => count($comment_for_content), 'author_name' => $author->login_name, 'content_type_id' => $row['type'], 'parent_info' => $collection);
                 $i++;
             } catch (PAException $e) {
                 //
             }
         }
     }
     Logger::log("Exit: Content::load_all_content_id_array()");
     return $content_data;
 }
Ejemplo n.º 5
0
require_once "BlockModules/RecentPostModule/RecentPostModule.php";
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>';
Ejemplo n.º 6
0
    $editable = TRUE;
}
//tpl for whole page
$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'];
 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();
 }