View Issue Details

IDProjectCategoryView StatusLast Update
1290Composrcore_feedback_featurespublic2016-04-23 09:31
ReporterChris Graham Assigned ToGuest  
PrioritynormalSeverityfeature 
Status newResolutionopen 
Summary1290: Recent Comments block
DescriptionAdd a block for showing recent comments on content.
Additional InformationAttached is code for a miniblock that implements this (no templates supplied, but those are simple enough). It can be a basis for the functionality.
TagsNo tags attached.
Attach Tags
Attached Files
side_content_comments.php (2,199 bytes)   
<?php

require_code('ocf_forum_driver_helper');

require_css('news');
require_lang('news');

$max=array_key_exists('max',$map)?intval($map['max']):10;
$_title=array_key_exists('title',$map)?$map['title']:do_lang('COMMENTS');

$start=0;

$where='p_validated=1';

$forum_name=get_option('comments_forum_name');
if (is_integer($forum_name))
{
	$where.=' AND t_forum_id='.strval($forum_name);
}
elseif (!is_array($forum_name))
{
	$id=$GLOBALS['FORUM_DRIVER']->forum_id_from_name($forum_name);
	if (is_null($id)) return NULL;
	$where.=' AND p_cache_forum_id='.strval($id);
}

$where.=not_like_spacer_posts('t.text_original');

$order='p_time DESC,p.id DESC';

$select='p.*,text_parsed,text_original';

$query='SELECT '.$select.' FROM '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_posts p '.$index.' LEFT JOIN '.$GLOBALS['FORUM_DB']->get_table_prefix().'translate t ON t.id=p.p_post WHERE '.$where.' ORDER BY '.$order;
$rows=$GLOBALS['FORUM_DB']->query($query,$max,$start);
$query_cnt='SELECT COUNT(*) FROM '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_posts p '.$index.' LEFT JOIN '.$GLOBALS['FORUM_DB']->get_table_prefix().'translate t ON t.id=p.p_post WHERE '.$where;
$count=$GLOBALS['FORUM_DB']->query_value_null_ok_full($query_cnt);

$out=new ocp_tempcode();
foreach ($rows as $row)
{
	$post_url=$GLOBALS['FORUM_DRIVER']->post_url($row['id'],'',true);
	$date=get_timezoned_date($row['p_time'],false);
	$username=$GLOBALS['FORUM_DRIVER']->get_username($row['p_poster']);

	$message=new ocp_tempcode();
	if ((!is_null($row['text_parsed'])) && ($row['text_parsed']!='') && ($row['id']!=0))
	{
		if (!$message->from_assembly($row['text_parsed'],true))
			$message=get_translated_tempcode($row['id'],$GLOBALS['FORUM_DB']);
	} else $message=get_translated_tempcode($row['id'],$GLOBALS['FORUM_DB']);

	$out->attach(do_template('BLOCK_SIDE_CONTENT_COMMENTS_COMMENT',array(
		'POST_TITLE'=>escape_html($row['p_title']),
		'POST'=>$message,
		'POST_URL'=>$post_url,
		'USERNAME'=>$username,
		'MEMBER_ID'=>strval($row['p_poster']),
		'DATE'=>$date,
		'_DATE'=>strval($row['p_time']),
	)));
}

$tpl=do_template('BLOCK_SIDE_CONTENT_COMMENTS',array(
	'TITLE'=>$_title,
	'CONTENT'=>$out,
));
$tpl->evaluate_echo();
side_content_comments.php (2,199 bytes)   
side_forum_posts.php (2,974 bytes)   
<?php

require_code('ocf_forum_driver_helper');

require_css('news');
require_lang('news');

$max=array_key_exists('max',$map)?intval($map['max']):10;
$_title=array_key_exists('title',$map)?$map['title']:do_lang('POSTS');

$start=0;

$where='p_validated=1';

$where.=' AND EXISTS (SELECT * FROM '.$GLOBALS['FORUM_DB']->get_table_prefix().'group_category_access g WHERE g.category_name=p.p_cache_forum_id AND module_the_name=\'forums\' AND g.group_id='.strval(db_get_first_id()).')';

//$where.=not_like_spacer_posts('t.text_original');
$where.=' AND p_cache_forum_id<>101 AND p_cache_forum_id IS NOT NULL';

$order='p_time DESC,p.id DESC';

$select='p.*,text_parsed,text_original,l_time,t_cache_first_title';

$query='SELECT '.$select.' FROM '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_posts p JOIN '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_topics top ON top.id=p.p_topic_id LEFT JOIN '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_read_logs l ON (p.p_topic_id=l_topic_id AND l_member_id='.strval(get_member()).') LEFT JOIN '.$GLOBALS['FORUM_DB']->get_table_prefix().'translate t ON t.id=p.p_post WHERE '.$where.' ORDER BY '.$order;
$rows=$GLOBALS['FORUM_DB']->query($query,$max,$start);
if (!is_array($rows)) return;
//$query_cnt='SELECT COUNT(*) FROM '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_posts p LEFT JOIN '.$GLOBALS['FORUM_DB']->get_table_prefix().'translate t ON t.id=p.p_post WHERE '.$where;
//$count=$GLOBALS['FORUM_DB']->query_value_null_ok_full($query_cnt);

$out=new ocp_tempcode();
foreach ($rows as $row)
{
	$post_url=$GLOBALS['FORUM_DRIVER']->post_url($row['id'],'',true);

	$first_unread_url=mixed();
	require_code('ocf_topics');
	$has_read=ocf_has_read_topic($row['p_topic_id'],$row['p_time'],get_member(),$row['l_time']);
	if ((!$has_read) && (!match_key_match('_WILD:topicview:id='.strval($row['p_topic_id']))))
	{
		$first_unread_url=build_url(array('page'=>'topicview','id'=>$row['p_topic_id'],'type'=>'first_unread'),get_module_zone('topicview'));
		$first_unread_url->attach('#first_unread');
	}

	$date=get_timezoned_date($row['p_time'],false);

	$username=$GLOBALS['FORUM_DRIVER']->get_username($row['p_poster']);

	$message=new ocp_tempcode();
	if ((!is_null($row['text_parsed'])) && ($row['text_parsed']!='') && ($row['id']!=0))
	{
		if (!$message->from_assembly($row['text_parsed'],true))
			$message=get_translated_tempcode($row['id'],$GLOBALS['FORUM_DB']);
	} else $message=get_translated_tempcode($row['id'],$GLOBALS['FORUM_DB']);

	$out->attach(do_template('BLOCK_SIDE_CONTENT_COMMENTS_COMMENT',array(
		'POST_TITLE'=>escape_html($row['p_title']),
		'TOPIC_TITLE'=>escape_html($row['t_cache_first_title']),
		'POST'=>$message,
		'POST_URL'=>$post_url,
		'UNREAD_URL'=>$first_unread_url,
		'USERNAME'=>$username,
		'MEMBER_ID'=>strval($row['p_poster']),
		'DATE'=>$date,
		'_DATE'=>strval($row['p_time']),
	)));
}

$tpl=do_template('BLOCK_SIDE_CONTENT_COMMENTS',array(
	'TITLE'=>$_title,
	'CONTENT'=>$out,
));
$tpl->evaluate_echo();
side_forum_posts.php (2,974 bytes)   
Time estimation (hours)3
Sponsorship open

Sponsor

Date Added Member Amount Sponsored

Activities

Add Note

View Status
Note
Upload Files
Maximum size: 32,768 KiB

Attach files by dragging & dropping, selecting or pasting them.
You are not logged in You are not logged in. This means you will not get any e-mail notifications. And if you reply, we will not know for sure you are the original poster of the issue.

Issue History

Date Modified Username Field Change