ocPortal Developer's Guide: OCF views
» Return to Contentssources/ocf_forumview.php
Global_functions_ocf_forumview.php
Function summary
| mixed | ocf_render_forumview (?integer id, string current_filter_cat, integer max, integer start, AUTO_LINK root, ?MEMBER of_member_id) |
| array | ocf_get_topic_array (array topic_row, MEMBER member_id, integer hot_topic_definition, boolean involved) |
| tempcode | ocf_render_topic (array topic, boolean has_topic_marking, boolean pt, ?string show_forum) |
| array | ocf_get_forum_view (integer start, ?integer max, ?MEMBER forum_id) |
mixed ocf_render_forumview(?integer id, string current_filter_cat, integer max, integer start, AUTO_LINK root, ?MEMBER of_member_id)
Render the OCF forumview.
Parameters…
| Name | id |
|---|---|
| Description | Forum ID (NULL: personal topics). |
| Type | ?integer |
| Name | current_filter_cat |
|---|---|
| Description | The filter category (blank if no filter) |
| Type | string |
| Name | max |
|---|---|
| Description | Maximum results to show |
| Type | integer |
| Name | start |
|---|---|
| Description | Offset for result showing |
| Type | integer |
| Name | root |
|---|---|
| Description | Virtual root |
| Type | AUTO_LINK |
| Name | of_member_id |
|---|---|
| Description | The member to show personal topics of (NULL: not showing personal topics) |
| Type | ?MEMBER |
Returns…
| Description | Either Tempcode (an interface that must be shown) or a Tuple: The main Tempcode, a title to use (also Tempcode), breadcrumbs (also Tempcode), the forum name (string). For a PT view, it is always a tuple, never raw Tempcode (as it can go inside a tabset). |
|---|---|
| Type | mixed |
function ocf_render_forumview($id,$current_filter_cat,$max,$start,$root,$of_member_id)
{
require_css('ocf');
$type=is_null($id)?'pt':'misc';
if ($type=='pt')
{
if (is_guest()) access_denied('NOT_AS_GUEST');
require_code('ocf_forumview_pt');
$details=ocf_get_personal_topics($start,$max,$of_member_id);
$root_forum_name=$GLOBALS['FORUM_DB']->query_value('f_forums','f_name',array('id'=>$root));
$tree=hyperlink(build_url(array('page'=>'_SELF','id'=>($root==db_get_first_id())?NULL:$root),'_SELF'),escape_html($root_forum_name),false,false,do_lang_tempcode('GO_BACKWARDS_TO',$root_forum_name),NULL,NULL,'up');
$tree->attach(' > ');
$pt_username=$GLOBALS['FORUM_DRIVER']->get_username($of_member_id);
if (is_null($pt_username)) $pt_username=do_lang('UNKNOWN');
$tree->attach(do_lang_tempcode('PERSONAL_TOPICS_OF',escape_html($pt_username)));
$details['name']=do_lang_tempcode('PERSONAL_TOPICS_OF',escape_html($pt_username));
} else
{
$GLOBALS['FEED_URL']=find_script('backend').'?mode=ocf_forumview&filter='.strval($id);
$details=ocf_get_forum_view($start,$max,$id);
$tree=ocf_forum_breadcrumbs($id,$details['name'],$details['parent_forum']);
if ((array_key_exists('question',$details)) && (is_null(get_bot_type())))
{
// Was there a question answering attempt?
$answer=post_param('answer','-1#');
if ($answer!='-1#')
{
if (strtolower(trim($answer))==strtolower(trim($details['answer']))) // They got it right
{
if (!is_guest())
{
$GLOBALS['FORUM_DB']->query_insert('f_forum_intro_member',array('i_forum_id'=>$id,'i_member_id'=>get_member()));
} else
{
$GLOBALS['FORUM_DB']->query_insert('f_forum_intro_ip',array('i_forum_id'=>$id,'i_ip'=>get_ip_address(3)));
}
} else // They got it wrong
{
$url=get_self_url();
$title=get_page_title('INTRO_QUESTION');
return redirect_screen($title,$url,do_lang_tempcode('INTRO_ANSWER_INCORRECT'),false,'warn');
}
} else
{ // Ask the question
$title=get_page_title(($details['answer']=='')?'INTRO_NOTICE':'INTRO_QUESTION');
$url=get_self_url();
return do_template('OCF_FORUM_INTRO_QUESTION_SCREEN',array('ANSWER'=>$details['answer'],'TITLE'=>$title,'URL'=>$url,'QUESTION'=>$details['question']));
}
}
}
if ($type=='pt') $forum_name=do_lang('PERSONAL_TOPICS');
else $forum_name=$details['name'];
$may_mass_moderate=(array_key_exists('may_move_topics',$details)) || (array_key_exists('may_delete_topics',$details));
// Find categories
$categories=new ocp_tempcode();
if ($type!='pt')
{
foreach ($details['categories'] as $best=>$category)
{
if (array_key_exists('subforums',$category)) // We only show if there is something in it
{
// Subforums
$forums=new ocp_tempcode();
foreach ($category['subforums'] as $subforum)
{
if ((array_key_exists('last_topic_id',$subforum)) && (!is_null($subforum['last_topic_id'])))
{
if (!is_null($subforum['last_member_id']))
{
if (!is_guest($subforum['last_member_id']))
{
//$colour=get_group_colour(ocf_get_member_primary_group($subforum['last_member_id']));
$poster=do_template('OCF_USER_MEMBER',array(
'_GUID'=>'39r932rwefldjfldjlf',
/*'COLOUR'=>$colour,*/
'USERNAME'=>$subforum['last_username'],
'PROFILE_URL'=>$GLOBALS['FORUM_DRIVER']->member_profile_url($subforum['last_member_id'],false,true)
));
} else $poster=protect_from_escaping(escape_html($subforum['last_username']));
} else
{
$poster=do_lang_tempcode('NA_EM');
}
$topic_url=build_url(array('page'=>'topicview','id'=>$subforum['last_topic_id'],'type'=>'first_unread'),get_module_zone('topicview'));
$topic_url->attach('#first_unread');
$latest=do_template('OCF_FORUM_LATEST',array(
'_GUID'=>'dlfsdfkoewfdlfsldfk',
'DATE'=>is_null($subforum['last_time'])?do_lang_tempcode('NA_EM'):protect_from_escaping(escape_html(get_timezoned_date($subforum['last_time']))),
'DATE_RAW'=>is_null($subforum['last_time'])?'':strval($subforum['last_time']),
'TOPIC_URL'=>$topic_url,
'TOPIC_TITLE'=>($subforum['last_title']=='')?do_lang_tempcode('NA'):$subforum['last_title'],
'POSTER'=>$poster,
'MEMBER_ID'=>strval($subforum['last_member_id']),
'ID'=>strval($subforum['last_topic_id'])
));
}
elseif (array_key_exists('protected_last_post',$subforum))
{
$latest=do_lang_tempcode('PROTECTED_LAST_POST');
}
else $latest=do_lang_tempcode('NO_POSTS_YET');
// Work out where the subforum URL is
if (($subforum['redirection']!='') && (!is_numeric($subforum['redirection'])))
{
$subforum_url=$subforum['redirection'];
$subforum_num_posts=do_lang_tempcode('NA_EM');
$subforum_num_topics=do_lang_tempcode('NA_EM');
$latest=do_lang_tempcode('NA_EM');
$subforum['has_new']=false;
$subforums=new ocp_tempcode();
$new_post_or_not='redirect';
}
else
{
if ($subforum['redirection']!='')
{
$subforum_url=build_url(array('page'=>'_SELF','id'=>$subforum['redirection']),'_SELF');
$new_post_or_not=$subforum['has_new']?'new_posts_redirect':'no_new_posts_redirect';
} else
{
$subforum_url=build_url(array('page'=>'_SELF','id'=>$subforum['id']),'_SELF');
$new_post_or_not=$subforum['has_new']?'new_posts':'no_new_posts';
}
$subforum_num_posts=protect_from_escaping(escape_html(integer_format($subforum['num_posts'])));
$subforum_num_topics=protect_from_escaping(escape_html(integer_format($subforum['num_topics'])));
// Subsubforums
$subforums=new ocp_tempcode();
ksort($subforum['children']);
foreach ($subforum['children'] as $child)
{
// Work out where the subsubforum url is
if (is_numeric($child['redirection']))
{
$link=hyperlink(build_url(array('page'=>'_SELF','id'=>$child['redirection']),'_SELF'),$child['name'],false,true);
}
elseif ($child['redirection']!='')
{
$link=hyperlink($child['redirection'],$child['name'],false,true);
} else
{
$link=hyperlink(build_url(array('page'=>'_SELF','id'=>$child['id']),'_SELF'),$child['name'],false,true);
}
if (!$subforums->is_empty()) $subforums->attach(do_lang_tempcode('LIST_SEP'));
$subforums->attach($link);
}
}
$edit_url=has_actual_page_access(get_member(),'admin_ocf_forums')?build_url(array('page'=>'admin_ocf_forums','type'=>'_ed','id'=>$subforum['id']),'adminzone'):new ocp_tempcode();
$forum_rules_url='';
$intro_question_url='';
if (!$subforum['intro_question']->is_empty())
{
if ($subforum['intro_answer']=='')
{
$keep=keep_symbol(array());
$intro_rules_url=find_script('rules').'?id='.rawurlencode(strval($subforum['id'])).$keep;
} else
{
$keep=keep_symbol(array());
$intro_question_url=find_script('rules').'?id='.rawurlencode(strval($subforum['id'])).$keep;
}
}
$forums->attach(do_template('OCF_FORUM_IN_CATEGORY',array(
'_GUID'=>'slkfjof9jlsdjcsd',
'ID'=>strval($subforum['id']),
'NEW_POST_OR_NOT'=>$new_post_or_not,
'LANG_NEW_POST_OR_NOT'=>do_lang('POST_INDICATOR_'.$new_post_or_not),
'FORUM_NAME'=>$subforum['name'],
'FORUM_URL'=>$subforum_url,
'DESCRIPTION'=>$subforum['description'],
'NUM_POSTS'=>$subforum_num_posts,
'NUM_TOPICS'=>$subforum_num_topics,
'LATEST'=>$latest,
'SUBFORUMS'=>$subforums,
'EDIT_URL'=>$edit_url,
'FORUM_RULES_URL'=>$forum_rules_url,
'INTRO_QUESTION_URL'=>$intro_question_url
)));
}
// Category itself
if ((!array_key_exists('expanded_by_default',$category)) || ($category['expanded_by_default']==1))
{
$display='table';
$expand_type='contract';
} else
{
$display='none';
$expand_type='expand';
}
$category_description=$category['description'];
$categories->attach(do_template('OCF_FORUM_CATEGORY',array('_GUID'=>'fc9bae42c680ea0162287e2ed3917bbe','CATEGORY_ID'=>strval($best),'EXPAND_TYPE'=>$expand_type,'DISPLAY'=>$display,'CATEGORY_TITLE'=>$category['title'],'CATEGORY_DESCRIPTION'=>$category_description,'FORUMS'=>$forums)));
}
}
}
// Work out what moderator actions can be performed (also includes marking read/unread)
$moderator_actions='';
if (($type=='pt') && ($of_member_id==get_member()) && (get_value('disable_pt_filtering')!=='1'))
{
$moderator_actions.='<option value="categorise_pts">'.do_lang('CATEGORISE_PTS').'</option>';
}
if (get_value('disable_mark_forum_read')!=='1')
{
$moderator_actions.='<option value="mark_topics_read">'.do_lang('MARK_READ').'</option>';
$moderator_actions.='<option value="mark_topics_unread">'.do_lang('MARK_UNREAD').'</option>';
}
// Mass moderation
if ($may_mass_moderate)
{
$moderator_actions.='<option value="move_topics">'.do_lang('MOVE_TOPICS').'</option>';
if (has_specific_permission(get_member(),'delete_midrange_content','topics',array('forums',$id)))
{
$moderator_actions.='<option value="delete_topics">'.do_lang('DELETE_TOPICS').'</option>';
}
$moderator_actions.='<option value="pin_topics">'.do_lang('PIN_TOPIC').'</option>';
$moderator_actions.='<option value="unpin_topics">'.do_lang('UNPIN_TOPIC').'</option>';
$moderator_actions.='<option value="sink_topics">'.do_lang('SINK_TOPIC').'</option>';
$moderator_actions.='<option value="unsink_topics">'.do_lang('UNSINK_TOPIC').'</option>';
$moderator_actions.='<option value="cascade_topics">'.do_lang('CASCADE_TOPIC').'</option>';
$moderator_actions.='<option value="uncascade_topics">'.do_lang('UNCASCADE_TOPIC').'</option>';
$moderator_actions.='<option value="open_topics">'.do_lang('OPEN_TOPIC').'</option>';
$moderator_actions.='<option value="close_topics">'.do_lang('CLOSE_TOPIC').'</option>';
if (!is_null($id))
{
$multi_moderations=ocf_list_multi_moderations($id);
if (count($multi_moderations)!=0)
{
$moderator_actions.='<optgroup label="'.do_lang('MULTI_MODERATIONS').'">';
foreach ($multi_moderations as $mm_id=>$mm_name)
$moderator_actions.='<option value="mmt_'.strval($mm_id).'">'.$mm_name.'</option>';
$moderator_actions.='</optgroup>';
}
}
}
// Find topics
$topics=new ocp_tempcode();
$pinned=false;
$num_unread=0;
foreach ($details['topics'] as $topic)
{
if (($pinned) && (!in_array('pinned',$topic['modifiers'])))
{
$topics->attach(do_template('OCF_PINNED_DIVIDER'));
}
$pinned=in_array('pinned',$topic['modifiers']);
$topics->attach(ocf_render_topic($topic,$moderator_actions!='',$type=='pt',NULL));
if (in_array('unread',$topic['modifiers'])) $num_unread++;
}
// Buttons
$button_array=array();
if (!is_guest())
{
if ((get_value('disable_mark_forum_read')!=='1') && ($num_unread!=0))
{
$read_url=build_url(array('page'=>'topics','type'=>'mark_read','id'=>$id),get_module_zone('topics'));
$button_array[]=array('immediate'=>true,'title'=>do_lang_tempcode('MARK_READ'),'url'=>$read_url,'img'=>'mark_read');
}
}
if ($type!='pt')
{
if (addon_installed('search'))
{
$search_url=build_url(array('page'=>'search','type'=>'misc','id'=>'ocf_posts','search_under'=>$id),get_module_zone('search'));
$button_array[]=array('immediate'=>false,'rel'=>'search','title'=>do_lang_tempcode('SEARCH'),'url'=>$search_url,'img'=>'search');
}
$new_topic_url=build_url(array('page'=>'topics','type'=>'new_topic','id'=>$id),get_module_zone('topics'));
} else
{
if (addon_installed('search'))
{
$search_url=build_url(array('page'=>'search','type'=>'misc','id'=>'ocf_own_pt'),get_module_zone('search'));
$button_array[]=array('immediate'=>false,'rel'=>'search','title'=>do_lang_tempcode('SEARCH'),'url'=>$search_url,'img'=>'search');
}
$new_topic_url=build_url(array('page'=>'topics','type'=>'new_pt','id'=>get_member()),get_module_zone('topics'));
}
if ($type=='pt')
{
//$archive_url=$GLOBALS['FORUM_DRIVER']->forum_url(db_get_first_id());
//$button_array[]=array('immediate'=>false,'title'=>do_lang_tempcode('ROOT_FORUM'),'url'=>$archive_url,'img'=>'forum');
}
if (array_key_exists('may_post_topic',$details))
{
if ($type=='pt')
{
$button_array[]=array('immediate'=>false,'rel'=>'add','title'=>do_lang_tempcode('ADD_PERSONAL_TOPIC'),'url'=>$new_topic_url,'img'=>'send_message');
} else
{
$button_array[]=array('immediate'=>false,'rel'=>'add','title'=>do_lang_tempcode('ADD_TOPIC'),'url'=>$new_topic_url,'img'=>'new_topic');
}
}
$buttons=ocf_screen_button_wrap($button_array);
$starter_title=($type=='pt')?do_lang_tempcode('WITH_TITLING'):new ocp_tempcode();
// Wrap it all up
$action_url=build_url(array('page'=>'topics'),get_module_zone('topics'),NULL,false,true);
if (!$topics->is_empty())
{
if ($GLOBALS['XSS_DETECT']) ocp_mark_as_escaped($moderator_actions);
require_code('templates_results_browser');
$results_browser=results_browser(do_lang_tempcode('FORUM_TOPICS'),($type=='pt')?$of_member_id:$id,$start,'start',$max,'max',$details['max_rows'],NULL,($type=='pt')?'view':$type,true,false,7,NULL,($type=='pt')?'tab__pts':'');
$order=array_key_exists('order',$details)?$details['order']:'last_post';
$topic_wrapper=do_template('OCF_FORUM_TOPIC_WRAPPER',array('_GUID'=>'e452b81001e5c6b7adb4d82e627bf983','TYPE'=>$type,'ID'=>is_null($id)?NULL:strval($id),'MAX'=>strval($max),'ORDER'=>$order,'MAY_CHANGE_MAX'=>array_key_exists('may_change_max',$details),'ACTION_URL'=>$action_url,'BUTTONS'=>$buttons,'STARTER_TITLE'=>$starter_title,'TREE'=>$tree,'RESULTS_BROWSER'=>$results_browser,'MODERATOR_ACTIONS'=>$moderator_actions,'TOPICS'=>$topics,'FORUM_NAME'=>$forum_name));
} else
{
$topic_wrapper=new ocp_tempcode();
$moderator_actions='';
}
// Filters
$filters=new ocp_tempcode();
if (get_value('disable_pt_filtering')!=='1')
{
if ($type=='pt')
{
$filter_cats=ocf_get_filter_cats(true);
$filters_arr=array();
foreach ($filter_cats as $fi=>$filter_cat)
{
if ($filter_cat!='')
{
$filtered_url=build_url(array('page'=>'_SELF','category'=>$filter_cat),'_SELF',NULL,true,false,false,'tab__pts');
$filter_active=$filter_cat==$current_filter_cat;
$filters_arr[]=array(
'URL'=>$filter_active?new ocp_tempcode():$filtered_url,
'CAPTION'=>$filter_cat,
'HAS_NEXT'=>isset($filter_cats[$fi+1]),
);
}
}
$filters=do_template('OCF_PT_FILTERS',array('FILTERS'=>$filters_arr,'RESET_URL'=>build_url(array('page'=>'_SELF','category'=>NULL),'_SELF',NULL,true)));
}
}
$map=array('_GUID'=>'1c14afd9265b1bf69375169dd6faf83c','STARTER_TITLE'=>$starter_title,'ID'=>is_null($id)?NULL:strval($id),'DESCRIPTION'=>array_key_exists('description',$details)?$details['description']:'','FILTERS'=>$filters,'BUTTONS'=>$buttons,'TOPIC_WRAPPER'=>$topic_wrapper,'TREE'=>$tree,'CATEGORIES'=>$categories);
$content=do_template('OCF_FORUM',$map);
$ltitle=do_lang_tempcode('NAMED_FORUM',escape_html($details['name']));
return array($content,$ltitle,$tree,$forum_name);
}
array ocf_get_topic_array(array topic_row, MEMBER member_id, integer hot_topic_definition, boolean involved)
Get details of a topic (to show eventually as a row in a forum or results view). This is a helper function, and thus the interface is not very user friendly.
Parameters…
| Name | topic_row |
|---|---|
| Description | The DB row of the topic. |
| Type | array |
| Name | member_id |
|---|---|
| Description | The member the details are being prepared for. |
| Type | MEMBER |
| Name | hot_topic_definition |
|---|---|
| Description | The hot topic definition (taken from the config options). |
| Type | integer |
| Name | involved |
|---|---|
| Description | Whether the viewing member has a post in the topic. |
| Type | boolean |
Returns…
| Description | The details. |
|---|---|
| Type | array |
function ocf_get_topic_array($topic_row,$member_id,$hot_topic_definition,$involved)
{
$topic=array();
if ((is_null($topic_row['t_cache_first_post'])) || ($topic_row['t_cache_first_post']===0))
{
$topic['first_post']=new ocp_tempcode();
} else
{
if ((!is_null($topic_row['_trans_post'])) && ($topic_row['_trans_post']!=''))
{
$topic['first_post']=new ocp_tempcode();
if (!$topic['first_post']->from_assembly($topic_row['_trans_post']))
$topic_row['_trans_post']=NULL;
}
if ((is_null($topic_row['_trans_post'])) || ($topic_row['_trans_post']==''))
{
if (!is_null($topic_row['t_cache_first_post'])) $topic['first_post']=get_translated_tempcode($topic_row['t_cache_first_post'],$GLOBALS['FORUM_DB']);
else $topic['first_post']=new ocp_tempcode();
} else
{
$topic['first_post']->singular_bind('ATTACHMENT_DOWNLOADS',make_string_tempcode('?'));
}
}
$topic['id']=$topic_row['id'];
$topic['num_views']=$topic_row['t_num_views'];
$topic['num_posts']=$topic_row['t_cache_num_posts'];
$topic['forum_id']=$topic_row['t_forum_id'];
$topic['description']=$topic_row['t_description'];
$topic['description_link']=$topic_row['t_description_link'];
// If it's a spacer post, we need to intercede at this point, and make a better one
$linked_type='';
$linked_id='';
$is_spacer_post=(substr($topic['first_post']->evaluate(),0,strlen(do_lang('SPACER_POST_MATCHER')))==do_lang('SPACER_POST_MATCHER'));
if ($is_spacer_post)
{
$c_prefix=do_lang('COMMENT').': #';
if ((substr($topic['description'],0,strlen($c_prefix))==$c_prefix) && ($topic['description_link']!=''))
{
list($linked_type,$linked_id)=explode('_',substr($topic['description'],strlen($c_prefix)),2);
$topic['description']='';
require_code('ocf_posts');
list(,$new_post)=ocf_display_spacer_post($linked_type,$linked_id);
if (!is_null($new_post)) $topic['first_post']=$new_post;
}
}
$topic['emoticon']=$topic_row['t_emoticon'];
$topic['first_time']=$topic_row['t_cache_first_time'];
$topic['first_title']=$topic_row['t_cache_first_title'];
if ($topic['first_title']=='') $topic['first_title']=do_lang_tempcode('NA');
if ($is_spacer_post)
{
$topic['first_title']=do_lang('SPACER_TOPIC_TITLE_WRAP',$topic['first_title']);
}
$topic['first_username']=$topic_row['t_cache_first_username'];
$topic['first_member_id']=$topic_row['t_cache_first_member_id'];
if (is_null($topic['first_member_id']))
{
require_code('ocf_posts_action2');
ocf_force_update_topic_cacheing($topic_row['id'],NULL,true,true);
//$_topic_row=$GLOBALS['FORUM_DB']->query_select('f_topics',array('*'),array('id'=>$topic_row['id']),'',1);
//$topic_row=$_topic_row[0];
//$topic['first_member_id']=$GLOBALS['OCF_DRIVER']->get_guest_id();
}
if (!is_null($topic_row['t_cache_last_post_id']))
{
$topic['last_post_id']=$topic_row['t_cache_last_post_id'];
$topic['last_time']=$topic_row['t_cache_last_time'];
$topic['last_time_string']=get_timezoned_date($topic_row['t_cache_last_time']);
$topic['last_title']=$topic_row['t_cache_last_title'];
$topic['last_username']=$topic_row['t_cache_last_username'];
$topic['last_member_id']=$topic_row['t_cache_last_member_id'];
}
// Modifiers
$topic['modifiers']=array();
$has_read=ocf_has_read_topic($topic['id'],$topic_row['t_cache_last_time'],$member_id,$topic_row['l_time']);
if (!$has_read) $topic['modifiers'][]='unread';
if ($involved) $topic['modifiers'][]='involved';
if ($topic_row['t_cascading']==1) $topic['modifiers'][]='announcement';
if ($topic_row['t_pinned']==1) $topic['modifiers'][]='pinned';
if ($topic_row['t_sunk']==1) $topic['modifiers'][]='sunk';
if ($topic_row['t_is_open']==0) $topic['modifiers'][]='closed';
if ($topic_row['t_validated']==0) $topic['modifiers'][]='unvalidated';
if (!is_null($topic_row['t_poll_id'])) $topic['modifiers'][]='poll';
$num_posts=$topic_row['t_cache_num_posts'];
$start_time=$topic_row['t_cache_first_time'];
$end_time=$topic_row['t_cache_last_time'];
$days=floatval($end_time-$start_time)/60.0/60.0/24.0;
if ($days==0.0) $days=1.0;
if (($num_posts>=8) && (intval(round(floatval($num_posts)/$days))>=$hot_topic_definition)) $topic['modifiers'][]='hot';
return $topic;
}
tempcode ocf_render_topic(array topic, boolean has_topic_marking, boolean pt, ?string show_forum)
Render a topic row (i.e. a row in a forum or results view), from given details (from ocf_get_topic_array).
Parameters…
| Name | topic |
|---|---|
| Description | The details (array containing: last_post_id, id, modifiers, emoticon, first_member_id, first_username, first_post, num_posts, num_views). |
| Type | array |
| Name | has_topic_marking |
|---|---|
| Description | Whether the viewing member has the facility to mark off topics (send as false if there are no actions for them to perform). |
| Type | boolean |
| Name | pt |
|---|---|
| Description | Whether the topic is a Private Topic. |
| Default value | boolean-false |
| Type | boolean |
| Name | show_forum |
|---|---|
| Description | The forum name (NULL: do not show the forum name). |
| Default value | |
| Type | ?string |
Returns…
| Description | The topic row. |
|---|---|
| Type | tempcode |
function ocf_render_topic($topic,$has_topic_marking,$pt=false,$show_forum=NULL)
{
if ((array_key_exists('last_post_id',$topic)) && (!is_null($topic['last_post_id'])))
{
$last_post_url=build_url(array('page'=>'topicview','id'=>$topic['last_post_id'],'type'=>'findpost'),get_module_zone('topicview'));
$last_post_url->attach('#post_'.strval($topic['last_post_id']));
if (!is_null($topic['last_member_id']))
{
if ($topic['last_member_id']!=$GLOBALS['OCF_DRIVER']->get_guest_id())
{
//$colour=get_group_colour(ocf_get_member_primary_group($topic['last_member_id']));
$poster=do_template('OCF_USER_MEMBER',array(
/*'COLOUR'=>$colour,*/
'USERNAME'=>$topic['last_username'],
'PROFILE_URL'=>$GLOBALS['OCF_DRIVER']->member_profile_url($topic['last_member_id'],false,true)
));
} else $poster=protect_from_escaping(escape_html($topic['last_username']));
} else
{
$poster=do_lang_tempcode('NA');
}
$last_post=do_template('OCF_FORUM_TOPIC_ROW_LAST_POST',array('_GUID'=>'6aa8d0f4024ae12bf94b68b74faae7cf','ID'=>strval($topic['id']),'DATE_RAW'=>strval($topic['last_time']),'DATE'=>$topic['last_time_string'],'POSTER'=>$poster,'LAST_URL'=>$last_post_url));
} else $last_post=do_lang_tempcode('NA_EM');
$map=array('page'=>'topicview','id'=>$topic['id']);
if ((array_key_exists('forum_id',$topic)) && (is_null(get_bot_type())) && (get_param_integer('start',0)!=0)) $map['kfs'.strval($topic['forum_id'])]=get_param_integer('start',0);
$url=build_url($map,get_module_zone('topicview'));
// Modifiers
$topic_row_links=new ocp_tempcode();
$modifiers=$topic['modifiers'];
if (in_array('unread',$modifiers))
{
$first_unread_url=build_url(array('page'=>'topicview','id'=>$topic['id'],'type'=>'first_unread'),get_module_zone('topicview'));
$first_unread_url->attach('#first_unread');
$topic_row_links->attach(do_template('OCF_TOPIC_ROW_LINK',array('_GUID'=>'6f52881ed999f4c543c9d8573b37fa48','URL'=>$first_unread_url,'IMG'=>'unread','ALT'=>do_lang_tempcode('JUMP_TO_FIRST_UNREAD'))));
}
$topic_row_modifiers=new ocp_tempcode();
foreach ($modifiers as $modifier)
{
if ($modifier!='unread')
{
$topic_row_modifiers->attach(do_template('OCF_TOPIC_ROW_MODIFIER',array('_GUID'=>'fbcb8791b571187fd699aa6796c3f401','IMG'=>$modifier,'ALT'=>do_lang_tempcode('MODIFIER_'.$modifier))));
}
}
// Emoticon
if ($topic['emoticon']!='') $emoticon=do_template('OCF_TOPIC_EMOTICON',array('_GUID'=>'dfbe0e4a11b3caa4d2da298ff23ca221','EMOTICON'=>$topic['emoticon']));
else $emoticon=do_template('OCF_TOPIC_EMOTICON_NONE');
if ($topic['first_member_id']!=$GLOBALS['OCF_DRIVER']->get_guest_id())
{
$poster_profile_url=$GLOBALS['OCF_DRIVER']->member_profile_url($topic['first_member_id'],false,true);
//$colour=get_group_colour(ocf_get_member_primary_group($topic['first_member_id']));
$poster=do_template('OCF_USER_MEMBER',array(
/*'COLOUR'=>$colour,*/
'PROFILE_URL'=>$poster_profile_url,
'USERNAME'=>$topic['first_username']
));
} else
{
$poster=make_string_tempcode(escape_html($topic['first_username']));
}
if ($pt)
{
$with=($topic['pt_from']==$topic['first_member_id'])?$topic['pt_to']:$topic['pt_from'];
$with_username=$GLOBALS['OCF_DRIVER']->get_username($with);
if (is_null($with_username)) $with_username=do_lang('UNKNOWN');
$colour=get_group_colour(ocf_get_member_primary_group($with));
$b=do_template('OCF_USER_MEMBER',array(
'COLOUR'=>$colour,
'PROFILE_URL'=>$GLOBALS['OCF_DRIVER']->member_profile_url($with,false,true),
'USERNAME'=>$with_username
));
$poster=do_template('OCF_PT_BETWEEN',array('_GUID'=>'619cd7076c4baf7b26cb3149694af929','A'=>$poster,'B'=>$b));
}
// Marker
$marker=new ocp_tempcode();
if ($has_topic_marking)
{
$marker=do_template('OCF_TOPIC_MARKER',array('_GUID'=>'62ff977640d3d4270cf333edab42a18f','ID'=>strval($topic['id'])));
}
// Title
$title=$topic['first_title'];
// Page jump
$max=intval(get_option('forum_posts_per_page'));
require_code('templates_result_launcher');
$pages=results_launcher(do_lang_tempcode('NAMED_TOPIC',escape_html($title)),'topicview',$topic['id'],$max,$topic['num_posts'],'view',5);
// Tpl
$post=$topic['first_post'];
if (!is_null($show_forum))
{
$hover=do_lang_tempcode('FORUM_AND_TIME_HOVER',escape_html($show_forum),get_timezoned_date($topic['first_time']));
$breadcrumbs=ocf_forum_breadcrumbs($topic['forum_id'],NULL,NULL,false);
} else
{
$hover=protect_from_escaping(is_null($topic['first_time'])?'':escape_html(get_timezoned_date($topic['first_time'])));
$breadcrumbs=new ocp_tempcode();
}
return do_template('OCF_FORUM_TOPIC_ROW',array('_GUID'=>'1aca672272132f390c9ec23eebe0d171','BREADCRUMBS'=>$breadcrumbs,'RAW_TIME'=>is_null($topic['first_time'])?'':strval($topic['first_time']),'UNREAD'=>in_array('unread',$modifiers),'ID'=>strval($topic['id']),'HOVER'=>$hover,'PAGES'=>$pages,'MARKER'=>$marker,'TOPIC_ROW_LINKS'=>$topic_row_links,'TOPIC_ROW_MODIFIERS'=>$topic_row_modifiers,'POST'=>$post,'EMOTICON'=>$emoticon,'DESCRIPTION'=>$topic['description'],'URL'=>$url,'TITLE'=>$title,'POSTER'=>$poster,'NUM_POSTS'=>integer_format($topic['num_posts']),'NUM_VIEWS'=>integer_format($topic['num_views']),'LAST_POST'=>$last_post));
}
array ocf_get_forum_view(integer start, ?integer max, ?MEMBER forum_id)
Get a map of details relating to the view of a certain forum of a certain member.
Parameters…
| Name | start |
|---|---|
| Description | The start row for getting details of topics in the forum (i.e. 0 is newest, higher is starting further back in time). |
| Default value | 0 |
| Type | integer |
| Name | max |
|---|---|
| Description | The maximum number of topics to get detail of (NULL: default). |
| Default value | |
| Type | ?integer |
| Name | forum_id |
|---|---|
| Description | The member viewing (NULL: current member). |
| Default value | |
| Type | ?MEMBER |
Returns…
| Description | The details. |
|---|---|
| Type | array |
function ocf_get_forum_view($start=0,$max=NULL,$forum_id=NULL)
{
if (is_null($max)) $max=intval(get_option('forum_topics_per_page'));
$member_id=get_member();
load_up_all_module_category_permissions($member_id,'forums');
if (is_null($forum_id))
{
/*$forum_info[0]['f_name']=do_lang('ROOT_FORUM'); This optimisation was more trouble that it was worth, and constraining
$forum_info[0]['f_description']='';
$forum_info[0]['f_parent_forum']=NULL;*/
$forum_id=db_get_first_id();
}/* else*/
{
$forum_info=$GLOBALS['FORUM_DB']->query_select('f_forums f',array('f_redirection','f_intro_question','f_intro_answer','f_order_sub_alpha','f_parent_forum','f_name','f_description','f_order'),array('f.id'=>$forum_id),'',1,NULL,false,array('f_description','f_intro_question'));
if (!array_key_exists(0,$forum_info)) warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
if (($forum_info[0]['f_redirection']!='') && (looks_like_url($forum_info[0]['f_redirection'])))
{
header('Location: '.$forum_info[0]['f_redirection']);
exit();
}
}
if (!is_null($forum_id)) // Anyone may view the root (and see the topics in the root - but there will hardly be any)
{
if (!has_category_access($member_id,'forums',strval($forum_id))) access_denied('CATEGORY_ACCESS_LEVEL'); // We're only allowed to view it existing from a parent forum, or nothing at all -- so access denied brother!
}
// Find our subforums first
$order=$forum_info[0]['f_order_sub_alpha']?'f_name':'f_position';
$huge_forums=$GLOBALS['FORUM_DB']->query_value('f_forums','COUNT(*)')>100;
if ($huge_forums)
{
$subforum_rows=$GLOBALS['FORUM_DB']->query('SELECT f.* FROM '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_forums f WHERE f.id='.strval($forum_id).' OR f_parent_forum='.strval($forum_id).' ORDER BY f_parent_forum,'.$order,300,NULL,false,false,array('f_description','f_intro_question'));
if (count($subforum_rows)==300) $subforum_rows=array(); // Will cause performance breakage
} else
{
$subforum_rows=$GLOBALS['FORUM_DB']->query_select('f_forums f',array('f.*'),NULL,'ORDER BY f_parent_forum,'.$order,NULL,NULL,false,array('f_description','f_intro_question'));
}
$unread_forums=array();
if ((!is_null($forum_id)) && (get_member()!=$GLOBALS['OCF_DRIVER']->get_guest_id()))
{
// Where are there unread topics in subforums?
$tree=array();
$subforum_rows_copy=$subforum_rows;
$tree=ocf_organise_into_tree($subforum_rows_copy,$forum_id);
if ($forum_id!=db_get_first_id())
{
$child_or_list=ocf_get_all_subordinate_forums($forum_id,'t_forum_id',$tree);
} else $child_or_list='';
if ($child_or_list!='') $child_or_list.=' AND ';
$query='SELECT DISTINCT t_forum_id,t.id FROM '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_topics t LEFT JOIN '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_read_logs l ON (t.id=l_topic_id AND l_member_id='.strval((integer)get_member()).') WHERE '.$child_or_list.'t_cache_last_time>'.strval(time()-60*60*24*intval(get_option('post_history_days'))).' AND (l_time<t_cache_last_time OR l_time IS NULL)';
if (!has_specific_permission(get_member(),'jump_to_unvalidated')) $query.=' AND t_validated=1';
$unread_forums=collapse_2d_complexity('t_forum_id','id',$GLOBALS['FORUM_DB']->query($query));
}
// Find all the categories that are used
$categories=array();
$or_list='';
foreach ($subforum_rows as $tmp_key=>$subforum_row)
{
if ($subforum_row['f_parent_forum']!=$forum_id) continue;
if (!has_category_access($member_id,'forums',strval($subforum_row['id'])))
{
unset($subforum_rows[$tmp_key]);
continue;
}
$category_id=$subforum_row['f_category_id'];
if (!array_key_exists($category_id,$categories))
{
$categories[$category_id]=array('subforums'=>array());
if ($or_list!='') $or_list.=' OR ';
$or_list.='id='.strval((integer)$category_id);
}
}
if ($or_list!='')
{
$category_rows=$GLOBALS['FORUM_DB']->query('SELECT * FROM '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_categories WHERE '.$or_list);
foreach ($category_rows as $category_row)
{
$category_id=$category_row['id'];
$title=$category_row['c_title'];
$description=$category_row['c_description'];
$expanded_by_default=$category_row['c_expanded_by_default'];
$categories[$category_id]['title']=$title;
$categories[$category_id]['description']=$description;
$categories[$category_id]['expanded_by_default']=$expanded_by_default;
}
$categories[NULL]['title']='';
$categories[NULL]['description']='';
$categories[NULL]['expanded_by_default']=true;
foreach ($subforum_rows as $subforum_row)
{
if ($subforum_row['f_parent_forum']!=$forum_id) continue;
$category_id=$subforum_row['f_category_id'];
// if (!array_key_exists('position',$categories[$category_id])) $categories[$category_id]['position']=$subforum_row['f_position'];
$subforum=array();
$subforum['id']=$subforum_row['id'];
$subforum['name']=$subforum_row['f_name'];
$subforum['description']=get_translated_tempcode($subforum_row['f_description'],$GLOBALS['FORUM_DB']);
$subforum['redirection']=$subforum_row['f_redirection'];
$subforum['intro_question']=get_translated_tempcode($subforum_row['f_intro_question'],$GLOBALS['FORUM_DB']);
$subforum['intro_answer']=$subforum_row['f_intro_answer'];
if (is_numeric($subforum_row['f_redirection']))
{
$subforum_row=$GLOBALS['FORUM_DB']->query_select('f_forums',array('*'),array('id'=>intval($subforum_row['f_redirection'])),'',1);
$subforum_row=$subforum_row[0];
}
if (($subforum_row['f_redirection']=='') || (is_numeric($subforum_row['f_redirection'])))
{
$subforum['num_topics']=$subforum_row['f_cache_num_topics'];
$subforum['num_posts']=$subforum_row['f_cache_num_posts'];
$subforum['has_new']=false;
if (get_member()!=$GLOBALS['OCF_DRIVER']->get_guest_id())
{
$subforums_recurse=ocf_get_all_subordinate_forums($subforum['id'],NULL,$tree[$subforum['id']]['children']);
foreach ($subforums_recurse as $subforum_potential)
{
if (array_key_exists($subforum_potential,$unread_forums)) $subforum['has_new']=true;
}
}
if ((is_null($subforum_row['f_cache_last_forum_id'])) || (has_category_access($member_id,'forums',strval($subforum_row['f_cache_last_forum_id']))))
{
$subforum['last_topic_id']=$subforum_row['f_cache_last_topic_id'];
$subforum['last_title']=$subforum_row['f_cache_last_title'];
$subforum['last_time']=$subforum_row['f_cache_last_time'];
$subforum['last_username']=$subforum_row['f_cache_last_username'];
$subforum['last_member_id']=$subforum_row['f_cache_last_member_id'];
$subforum['last_forum_id']=$subforum_row['f_cache_last_forum_id'];
} else $subforum['protected_last_post']=true;
// Subsubforums
$subforum['children']=array();
foreach ($subforum_rows as $tmp_key_2=>$subforum_row2)
{
if (($subforum_row2['f_parent_forum']==$subforum_row['id']) && (has_category_access($member_id,'forums',strval($subforum_row2['id']))))
{
$subforum['children'][$subforum_row2['f_name'].'__'.strval($subforum_row2['id'])]=array('id'=>$subforum_row2['id'],'name'=>$subforum_row2['f_name'],'redirection'=>$subforum_row2['f_redirection']);
}
}
global $M_SORT_KEY;
$M_SORT_KEY='name';
uasort($subforum['children'],'multi_sort');
}
$categories[$category_id]['subforums'][]=$subforum;
}
}
// Find topics
$extra='';
if ((!has_specific_permission(get_member(),'see_unvalidated')) && (!ocf_may_moderate_forum($forum_id,$member_id))) $extra='t_validated=1 AND ';
if (is_null($forum_info[0]['f_parent_forum']))
{
$where=$extra.' (t_forum_id='.strval((integer)$forum_id).')';
} else
{
$extra2='';
$parent_or_list=ocf_get_forum_parent_or_list($forum_id,$forum_info[0]['f_parent_forum']);
if ($parent_or_list!='')
{
$extra2='AND ('.$parent_or_list.')';
}
$where=$extra.' (t_forum_id='.strval((integer)$forum_id).' OR (t_cascading=1 '.$extra2.'))';
}
$order=get_param('order',$forum_info[0]['f_order']);
$order2='t_cache_last_time DESC';
if ($order=='first_post') $order2='t_cache_first_time DESC';
elseif ($order=='title') $order2='t_cache_first_title ASC';
if (get_value('disable_sunk')!=='1')
$order2='t_sunk ASC,'.$order2;
if (is_guest())
{
$query='SELECT ttop.*,t.text_parsed AS _trans_post,NULL AS l_time FROM '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_topics ttop LEFT JOIN '.$GLOBALS['FORUM_DB']->get_table_prefix().'translate t ON '.db_string_equal_to('language',user_lang()).' AND ttop.t_cache_first_post=t.id WHERE '.$where.' ORDER BY t_cascading DESC,t_pinned DESC,'.$order2;
} else
{
$query='SELECT ttop.*,t.text_parsed AS _trans_post,l_time FROM '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_topics ttop LEFT JOIN '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_read_logs l ON (ttop.id=l.l_topic_id AND l.l_member_id='.strval((integer)get_member()).') LEFT JOIN '.$GLOBALS['FORUM_DB']->get_table_prefix().'translate t ON '.db_string_equal_to('language',user_lang()).' AND ttop.t_cache_first_post=t.id WHERE '.$where.' ORDER BY t_cascading DESC,t_pinned DESC,'.$order2;
}
$topic_rows=$GLOBALS['FORUM_DB']->query($query,$max,$start);
if (($start==0) && (count($topic_rows)<$max)) $max_rows=$max; // We know that they're all on this screen
else $max_rows=$GLOBALS['FORUM_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_topics WHERE '.$where);
$topics=array();
$hot_topic_definition=intval(get_option('hot_topic_definition'));
$or_list='';
foreach ($topic_rows as $topic_row)
{
if ($or_list!='') $or_list.=' OR ';
$or_list.='p_topic_id='.strval((integer)$topic_row['id']);
}
if (($or_list!='') && (!is_guest()))
{
$involved=$GLOBALS['FORUM_DB']->query('SELECT DISTINCT p_topic_id FROM '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_posts WHERE ('.$or_list.') AND p_poster='.strval((integer)get_member()));
$involved=collapse_1d_complexity('p_topic_id',$involved);
} else $involved=array();
foreach ($topic_rows as $topic_row)
{
$topics[]=ocf_get_topic_array($topic_row,$member_id,$hot_topic_definition,in_array($topic_row['id'],$involved));
}
$description=get_translated_tempcode($forum_info[0]['f_description'],$GLOBALS['FORUM_DB']);
$description_text=get_translated_text($forum_info[0]['f_description'],$GLOBALS['FORUM_DB']);
$out=array('name'=>$forum_info[0]['f_name'],
'description'=>$description,
'categories'=>$categories,
'topics'=>$topics,
'max_rows'=>$max_rows,
'order'=>$order,
'parent_forum'=>$forum_info[0]['f_parent_forum']);
$GLOBALS['META_DATA']+=array(
'created'=>'',
'creator'=>'',
'publisher'=>'', // blank means same as creator
'modified'=>'',
'type'=>'Forum',
'title'=>$forum_info[0]['f_name'],
'identifier'=>'_SEARCH:forumview:misc:'.strval($forum_id),
'description'=>$description_text,
'image'=>find_theme_image('bigicons/forums'),
);
// Is there a question/answer situation?
$question=get_translated_tempcode($forum_info[0]['f_intro_question'],$GLOBALS['FORUM_DB']);
if (!$question->is_empty())
{
$is_guest=($member_id==$GLOBALS['OCF_DRIVER']->get_guest_id());
$test=$GLOBALS['FORUM_DB']->query_value_null_ok('f_forum_intro_ip','i_ip',array('i_forum_id'=>$forum_id,'i_ip'=>get_ip_address(3)));
if ((is_null($test)) && (!$is_guest))
{
$test=$GLOBALS['FORUM_DB']->query_value_null_ok('f_forum_intro_member','i_member_id',array('i_forum_id'=>$forum_id,'i_member_id'=>$member_id));
}
if (is_null($test))
{
$out['question']=$question;
$out['answer']=$forum_info[0]['f_intro_answer'];
}
}
if (ocf_may_post_topic($forum_id,$member_id)) $out['may_post_topic']=1;
if (ocf_may_moderate_forum($forum_id,$member_id))
{
$out['may_change_max']=1;
$out['may_move_topics']=1;
if (has_specific_permission(get_member(),'multi_delete_topics')) $out['may_delete_topics']=1; // Only super admins can casually delete topics - other staff are expected to trash them. At least deleted posts or trashed topics can be restored!
}
return $out;
}
sources/ocf_topicview.php
Global_functions_ocf_topicview.php
Function summary
| URLPATH | find_post_id_url (AUTO_LINK post_id) |
| URLPATH | find_first_unread_url (AUTO_LINK id) |
| array | ocf_get_details_to_show_post (array _postdetails, boolean only_post) |
| array | ocf_read_in_topic (?AUTO_LINK topic_id, integer start, integer max, boolean view_poll_results, boolean check_perms) |
| void | ocf_cache_member_details (array members) |
| tempcode | ocf_render_post_buttons (array topic_info, array _postdetails, boolean may_reply) |
| tempcode | ocf_get_post_emphasis (array _postdetails) |
URLPATH find_post_id_url(AUTO_LINK post_id)
Find the URL to a post.
Parameters…
| Name | post_id |
|---|---|
| Description | The post ID. |
| Type | AUTO_LINK |
Returns…
| Description | The URL. |
|---|---|
| Type | URLPATH |
function find_post_id_url($post_id)
{
$max=intval(get_option('forum_posts_per_page'));
$id=$GLOBALS['FORUM_DB']->query_value_null_ok('f_posts','p_topic_id',array('id'=>$post_id));
if (is_null($id)) warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
// What page is it on?
$before=$GLOBALS['FORUM_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_posts WHERE id<'.strval((integer)$post_id).' AND '.ocf_get_topic_where($id));
$start=intval(floor(floatval($before)/floatval($max)))*$max;
// Now redirect accordingly
$map=array('page'=>'topicview','type'=>NULL,'id'=>$id,'start'=>($start==0)?NULL:$start);
foreach ($_GET as $key=>$val)
if ((substr($key,0,3)=='kfs') || (in_array($key,array('start','max')))) $map[$key]=$val;
$_redirect=build_url($map,'_SELF',NULL,true);
$redirect=$_redirect->evaluate();
$redirect.='#post_'.strval($post_id);
return $redirect;
}
URLPATH find_first_unread_url(AUTO_LINK id)
Find the URL to the latest unread post in a topic.
Parameters…
| Name | id |
|---|---|
| Description | The topic ID. |
| Type | AUTO_LINK |
Returns…
| Description | The URL. |
|---|---|
| Type | URLPATH |
function find_first_unread_url($id)
{
$max=intval(get_option('forum_posts_per_page'));
if ($max==0) $max=1;
$last_read_time=$GLOBALS['FORUM_DB']->query_value_null_ok('f_read_logs','l_time',array('l_member_id'=>get_member(),'l_topic_id'=>$id));
if (is_null($last_read_time))
{
// Assumes that everything made in the last two weeks has not been read
$unread_details=$GLOBALS['FORUM_DB']->query('SELECT id,p_time FROM '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_posts WHERE p_topic_id='.strval((integer)$id).' AND p_time>'.strval(time()-60*60*24*intval(get_option('post_history_days'))).' ORDER BY id',1);
if (array_key_exists(0,$unread_details))
{
$last_read_time=$unread_details[0]['p_time']-1;
} else $last_read_time=0;
}
$first_unread_id=$GLOBALS['FORUM_DB']->query_value_null_ok_full('SELECT id FROM '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_posts WHERE p_topic_id='.strval((integer)$id).' AND p_time>'.strval((integer)$last_read_time).' ORDER BY id');
if (!is_null($first_unread_id))
{
// What page is it on?
$before=$GLOBALS['FORUM_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_posts WHERE id<'.strval((integer)$first_unread_id).' AND '.ocf_get_topic_where($id));
$start=intval(floor(floatval($before)/floatval($max)))*$max;
} else
{
$first_unread_id=-2;
// What page is it on?
$before=$GLOBALS['FORUM_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_posts WHERE '.ocf_get_topic_where($id));
$start=intval(floor(floatval($before)/floatval($max)))*$max;
if ($start==$before) $start=$before-$max;
}
// Now redirect accordingly
$map=array('page'=>'topicview','id'=>$id,'type'=>NULL,'start'=>($start==0)?NULL:$start);
foreach ($_GET as $key=>$val)
if ((substr($key,0,3)=='kfs') || (in_array($key,array('start','max')))) $map[$key]=$val;
$_redirect=build_url($map,'_SELF',NULL,true);
$redirect=$_redirect->evaluate();
if ($first_unread_id>0) $redirect.='#post_'.strval($first_unread_id); else $redirect.='#first_unread';
return $redirect;
}
array ocf_get_details_to_show_post(array _postdetails, boolean only_post)
Turn a post row, into a detailed map of information that is suitable for use as display parameters for that post.
Parameters…
| Name | _postdetails |
|---|---|
| Description | The post row. |
| Type | array |
| Name | only_post |
|---|---|
| Description | Whether the post is the only post in the topic. |
| Default value | boolean-false |
| Type | boolean |
Returns…
| Description | The detailed map. |
|---|---|
| Type | array |
function ocf_get_details_to_show_post($_postdetails,$only_post=false)
{
$forum_id=$_postdetails['p_cache_forum_id'];
$primary_group=ocf_get_member_primary_group($_postdetails['p_poster']);
if (is_null($primary_group))
{
$_postdetails['p_poster']=db_get_first_id();
$primary_group=db_get_first_id();
}
$post=array('id'=>$_postdetails['id'],
'topic_id'=>$_postdetails['p_topic_id'],
'title'=>$_postdetails['p_title'],
'post'=>$_postdetails['message'],
'time'=>$_postdetails['p_time'],
'time_string'=>get_timezoned_date($_postdetails['p_time']),
'validated'=>$_postdetails['p_validated'],
'is_emphasised'=>$_postdetails['p_is_emphasised'],
'poster_username'=>$_postdetails['p_poster_name_if_guest'],
'poster'=>$_postdetails['p_poster'],
'has_history'=>!is_null($_postdetails['h_post_id'])
);
if (array_key_exists('message_comcode',$_postdetails))
{
$post['message_comcode']=$_postdetails['message_comcode'];
}
// Edited?
if (!is_null($_postdetails['p_last_edit_by']))
{
$post['last_edit_by']=$_postdetails['p_last_edit_by'];
$post['last_edit_time']=$_postdetails['p_last_edit_time'];
$post['last_edit_time_string']=get_timezoned_date($_postdetails['p_last_edit_time']);
$post['last_edit_by_username']=$GLOBALS['OCF_DRIVER']->get_username($_postdetails['p_last_edit_by']);
if ($post['last_edit_by_username']=='') $post['last_edit_by_username']=do_lang('UNKNOWN'); // Shouldn't happen, but imported data can be weird
}
// Find title
$title=addon_installed('ocf_member_titles')?$GLOBALS['OCF_DRIVER']->get_member_row_field($_postdetails['p_poster'],'m_title'):'';
if ($title=='') $title=get_translated_text(ocf_get_group_property($primary_group,'title'),$GLOBALS['FORUM_DB']);
$post['poster_title']=$title;
// If this isn't guest posted, we can put some member details in
if ((!is_null($_postdetails['p_poster'])) && ($_postdetails['p_poster']!=$GLOBALS['OCF_DRIVER']->get_guest_id()))
{
if (addon_installed('points'))
{
require_code('points');
$post['poster_points']=total_points($_postdetails['p_poster']);
}
$post['poster_posts']=$GLOBALS['OCF_DRIVER']->get_member_row_field($_postdetails['p_poster'],'m_cache_num_posts');
$post['poster_highlighted_name']=$GLOBALS['OCF_DRIVER']->get_member_row_field($_postdetails['p_poster'],'m_highlighted_name');
// Signature
if ((($GLOBALS['OCF_DRIVER']->get_member_row_field(get_member(),'m_views_signatures')==1) || (get_value('disable_views_sigs_option')==='1')) && ($_postdetails['p_skip_sig']==0) && (addon_installed('ocf_signatures')))
{
global $SIGNATURES_CACHE;
if (array_key_exists($_postdetails['p_poster'],$SIGNATURES_CACHE))
{
$sig=$SIGNATURES_CACHE[$_postdetails['p_poster']];
} else
{
$sig=get_translated_tempcode($GLOBALS['OCF_DRIVER']->get_member_row_field($_postdetails['p_poster'],'m_signature'),$GLOBALS['FORUM_DB']);
$SIGNATURES_CACHE[$_postdetails['p_poster']]=$sig;
}
$post['signature']=$sig;
}
// Any custom fields to show?
$post['custom_fields']=ocf_get_all_custom_fields_match_member($_postdetails['p_poster'],((get_member()!=$_postdetails['p_poster']) && (!has_specific_permission(get_member(),'view_any_profile_field')))?1:NULL,((get_member()==$_postdetails['p_poster']) && (!has_specific_permission(get_member(),'view_any_profile_field')))?1:NULL,NULL,NULL,NULL,NULL,NULL,0,true);
// Usergroup
$post['primary_group']=$primary_group;
$post['primary_group_name']=ocf_get_group_name($primary_group);
// Find avatar
$avatar=$GLOBALS['OCF_DRIVER']->get_member_avatar_url($_postdetails['p_poster']);
if ($avatar!='')
{
$post['poster_avatar']=$avatar;
}
// Any warnings?
if ((has_specific_permission(get_member(),'see_warnings')) && (addon_installed('ocf_warnings')))
{
$num_warnings=$GLOBALS['OCF_DRIVER']->get_member_row_field($_postdetails['p_poster'],'m_cache_warnings');
/*if ($num_warnings!=0)*/ $post['poster_num_warnings']=$num_warnings;
}
// Join date
$post['poster_join_date']=$GLOBALS['OCF_DRIVER']->get_member_row_field($_postdetails['p_poster'],'m_join_time');
$post['poster_join_date_string']=get_timezoned_date($post['poster_join_date']);
}
elseif ($_postdetails['p_poster']==$GLOBALS['OCF_DRIVER']->get_guest_id())
{
if ($_postdetails['p_poster_name_if_guest']==do_lang('SYSTEM'))
{
$post['poster_avatar']=find_theme_image('ocf_default_avatars/default_set/ocp_fanatic',true);
}
}
// Do we have any special controls over this post?
require_code('ocf_posts');
if (ocf_may_edit_post_by($_postdetails['p_poster'],$forum_id)) $post['may_edit']=true;
if ((ocf_may_delete_post_by($_postdetails['p_poster'],$forum_id)) && (!$only_post)) $post['may_delete']=true;
// More
if (has_specific_permission(get_member(),'see_ip')) $post['ip_address']=$_postdetails['p_ip_address'];
if (!is_null($_postdetails['p_intended_solely_for'])) $post['intended_solely_for']=$_postdetails['p_intended_solely_for'];
return $post;
}
array ocf_read_in_topic(?AUTO_LINK topic_id, integer start, integer max, boolean view_poll_results, boolean check_perms)
Read in a great big map of details relating to a topic.
Parameters…
| Name | topic_id |
|---|---|
| Description | The ID of the topic we are getting details of (NULL: whispers). |
| Type | ?AUTO_LINK |
| Name | start |
|---|---|
| Description | The start row for getting details of posts in the topic (i.e. 0 is start of topic, higher is further through). |
| Type | integer |
| Name | max |
|---|---|
| Description | The maximum number of posts to get detail of. |
| Type | integer |
| Name | view_poll_results |
|---|---|
| Description | Whether we are viewing poll results for the topic (if there is no poll for the topic, this is irrelevant). |
| Default value | boolean-false |
| Type | boolean |
| Name | check_perms |
|---|---|
| Description | Whether to check permissions. |
| Default value | boolean-true |
| Type | boolean |
Returns…
| Description | The map of details. |
|---|---|
| Type | array |
function ocf_read_in_topic($topic_id,$start,$max,$view_poll_results=false,$check_perms=true)
{
if (!is_null($topic_id))
{
$_topic_info=$GLOBALS['FORUM_DB']->query_select('f_topics t LEFT JOIN '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_forums f ON f.id=t.t_forum_id',array('t.*','f.f_is_threaded'),array('t.id'=>$topic_id),'',1);
if (!array_key_exists(0,$_topic_info)) warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
$topic_info=$_topic_info[0];
// Are we allowed into here?
// Check forum
$forum_id=$topic_info['t_forum_id'];
if (!is_null($forum_id))
{
if ($check_perms)
{
if (!has_category_access(get_member(),'forums',strval($forum_id))) access_denied('CATEGORY_ACCESS_LEVEL');
}
} else
{
// It must be a personal topic. Do we have access?
$from=$topic_info['t_pt_from'];
$to=$topic_info['t_pt_to'];
if (($from!=get_member()) && ($to!=get_member()) && (!ocf_has_special_pt_access($topic_id)) && (!has_specific_permission(get_member(),'view_other_pt')))
{
access_denied('SPECIFIC_PERMISSION','view_other_pt');
}
decache('_new_pp',array(get_member()));
decache('side_ocf_personal_topics',array(get_member()));
}
// Check validated
if ($topic_info['t_validated']==0)
{
if (!has_specific_permission(get_member(),'jump_to_unvalidated'))
access_denied('SPECIFIC_PERMISSION','jump_to_unvalidated');
}
if (is_null(get_param_integer('threaded',NULL)))
{
if ($start>0)
{
$_GET['threaded']='0';
}
}
$is_threaded=get_param_integer('threaded',(is_null($topic_info['f_is_threaded'])?0:$topic_info['f_is_threaded']));
// Some general info
$out=array(
'num_views'=>$topic_info['t_num_views'],
'num_posts'=>$topic_info['t_cache_num_posts'],
'validated'=>$topic_info['t_validated'],
'title'=>$topic_info['t_cache_first_title'],
'description'=>$topic_info['t_description'],
'description_link'=>$topic_info['t_description_link'],
'emoticon'=>$topic_info['t_emoticon'],
'forum_id'=>$topic_info['t_forum_id'],
'first_post'=>$topic_info['t_cache_first_post'],
'first_poster'=>$topic_info['t_cache_first_member_id'],
'first_post_id'=>$topic_info['t_cache_first_post_id'],
'pt_from'=>$topic_info['t_pt_from'],
'pt_to'=>$topic_info['t_pt_to'],
'is_open'=>$topic_info['t_is_open'],
'is_threaded'=>$is_threaded,
'is_really_threaded'=>is_null($topic_info['f_is_threaded'])?0:$topic_info['f_is_threaded'],
'last_time'=>$topic_info['t_cache_last_time'],
'meta_data'=>array(
'created'=>date('Y-m-d',$topic_info['t_cache_first_time']),
'creator'=>$topic_info['t_cache_first_username'],
'publisher'=>'', // blank means same as creator
'modified'=>date('Y-m-d',$topic_info['t_cache_last_time']),
'type'=>'Forum topic',
'title'=>$topic_info['t_cache_first_title'],
'identifier'=>'_SEARCH:topicview:misc:'.strval($topic_id),
'description'=>$topic_info['t_description'],
'numcomments'=>strval($topic_info['t_cache_num_posts']),
'image'=>find_theme_image('bigicons/forums'),
),
);
// Poll?
if (!is_null($topic_info['t_poll_id']))
{
require_code('ocf_polls');
$voted_already=$GLOBALS['FORUM_DB']->query_value_null_ok('f_poll_votes','pv_member_id',array('pv_poll_id'=>$topic_info['t_poll_id'],'pv_member_id'=>get_member()));
$out['poll']=ocf_poll_get_results($topic_info['t_poll_id'],$view_poll_results || (!is_null($voted_already)));
$out['poll']['voted_already']=$voted_already;
$out['poll_id']=$topic_info['t_poll_id'];
}
// Post query
$where=ocf_get_topic_where($topic_id);
$query='SELECT p.*,t.text_parsed AS text_parsed,t.text_original AS message_comcode,h.h_post_id FROM '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_posts p LEFT JOIN '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_post_history h ON (h.h_post_id=p.id AND h.h_action_date_and_time=p.p_last_edit_time) LEFT JOIN '.$GLOBALS['FORUM_DB']->get_table_prefix().'translate t ON '.db_string_equal_to('language',user_lang()).' AND p.p_post=t.id WHERE '.$where.' ORDER BY p_time,p.id';
} else
{
$out=array(
'num_views'=>0,
'num_posts'=>0,
'validated'=>1,
'title'=>do_lang('INLINE_PERSONAL_POSTS'),
'description'=>'',
'description_link'=>'',
'emoticon'=>'',
'forum_id'=>NULL,
'first_post'=>NULL,
'first_poster'=>NULL,
'first_post_id'=>NULL,
'pt_from'=>NULL,
'pt_to'=>NULL,
'is_open'=>1,
'is_threaded'=>0,
'last_time'=>time(),
'meta_data'=>array(),
);
// Post query
$where='p_intended_solely_for='.strval(get_member());
$query='SELECT p.*,t.text_parsed AS text_parsed,t.text_original AS message_comcode,h.h_post_id FROM '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_posts p LEFT JOIN '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_post_history h ON (h.h_post_id=p.id AND h.h_action_date_and_time=p.p_last_edit_time) LEFT JOIN '.$GLOBALS['FORUM_DB']->get_table_prefix().'translate t ON '.db_string_equal_to('language',user_lang()).' AND p.p_post=t.id WHERE '.$where.' ORDER BY p_time,p.id';
}
// Posts
if ($out['is_threaded']==0)
{
$_postdetailss=list_to_map('id',$GLOBALS['FORUM_DB']->query($query,$max,$start));
if (($start==0) && (count($_postdetailss)<$max)) $out['max_rows']=$max; // We know that they're all on this screen
else $out['max_rows']=$GLOBALS['FORUM_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_posts WHERE '.$where);
$posts=array();
// Precache member/group details in one fell swoop
$members=array();
foreach ($_postdetailss as $_postdetails)
{
$members[$_postdetails['p_poster']]=1;
if ($out['title']=='') $out['title']=$_postdetails['p_title'];
}
ocf_cache_member_details(array_keys($members));
$i=0;
foreach ($_postdetailss as $_postdetails)
{
if (is_null($_postdetails['message_comcode'])) $_postdetails['message_comcode']=get_translated_text($_postdetails['p_post'],$GLOBALS['FORUM_DB']);
$linked_type='';
$linked_id='';
$linked_url='';
// If it's a spacer post, see if we can detect it better
$is_spacer_post=(($i==0) && (substr($_postdetails['message_comcode'],0,strlen('[semihtml]'.do_lang('SPACER_POST_MATCHER')))=='[semihtml]'.do_lang('SPACER_POST_MATCHER')));
if ($is_spacer_post)
{
$c_prefix=do_lang('COMMENT').': #';
if ((substr($out['description'],0,strlen($c_prefix))==$c_prefix) && ($out['description_link']!=''))
{
list($linked_type,$linked_id)=explode('_',substr($out['description'],strlen($c_prefix)),2);
$linked_url=$out['description_link'];
$out['description']='';
}
}
// Load post
if ((get_page_name()=='search') || (is_null($_postdetails['text_parsed'])) || ($_postdetails['text_parsed']=='') || ($_postdetails['p_post']==0))
{
$_postdetails['message']=get_translated_tempcode($_postdetails['p_post'],$GLOBALS['FORUM_DB']);
} else
{
$_postdetails['message']=new ocp_tempcode();
if (!$_postdetails['message']->from_assembly($_postdetails['text_parsed'],true))
$_postdetails['message']=get_translated_tempcode($_postdetails['p_post'],$GLOBALS['FORUM_DB']);
}
// Fake a quoted post? (kind of a nice 'tidy up' feature if a forum's threading has been turned off, leaving things for flat display)
if ((!is_null($_postdetails['p_parent_id'])) && (strpos($_postdetails['message_comcode'],'[quote')===false))
{
$p=mixed(); // NULL
if (array_key_exists($_postdetails['p_parent_id'],$_postdetailss)) // Ah, we're already loading it on this page
{
$p=$_postdetailss[$_postdetails['p_parent_id']];
// Load post
if ((get_page_name()=='search') || (is_null($p['text_parsed'])) || ($p['text_parsed']=='') || ($p['p_post']==0))
{
$p['message']=get_translated_tempcode($p['p_post'],$GLOBALS['FORUM_DB']);
} else
{
$p['message']=new ocp_tempcode();
if (!$p['message']->from_assembly($p['text_parsed'],true))
$p['message']=get_translated_tempcode($p['p_post'],$GLOBALS['FORUM_DB']);
}
} else // Drat, we need to load it
{
$_p=$GLOBALS['FORUM_DB']->query_select('f_posts',array('*'),array('id'=>$_postdetails['p_parent_id']),'',1);
if (array_key_exists(0,$_p))
{
$p=$_p[0];
$p['message']=get_translated_tempcode($p['p_post'],$GLOBALS['FORUM_DB']);
}
}
$temp=$_postdetails['message'];
$_postdetails['message']=new ocp_tempcode();
$_postdetails['message']=do_template('COMCODE_QUOTE_BY',array('SAIDLESS'=>false,'BY'=>$p['p_poster_name_if_guest'],'CONTENT'=>$p['message']));
$_postdetails['message']->attach($temp);
}
// Spacer posts may have a better first post put in place
if ($is_spacer_post)
{
require_code('ocf_posts');
list($new_description,$new_post)=ocf_display_spacer_post($linked_type,$linked_id);
//if (!is_null($new_description)) $out['description']=$new_description; Actually, it's a bit redundant
if (!is_null($new_post)) $_postdetails['message']=$new_post;
$out['title']=do_lang('SPACER_TOPIC_TITLE_WRAP',$out['title']);
$_postdetails['p_title']=do_lang('SPACER_TOPIC_TITLE_WRAP',$_postdetails['p_title']);
}
// Put together
$collated_post_details=ocf_get_details_to_show_post($_postdetails,($start==0) && (count($_postdetailss)==1));
$collated_post_details['is_spacer_post']=$is_spacer_post;
$posts[]=$collated_post_details;
}
$out['posts']=$posts;
$i++;
}
// Any special topic/for-any-post-in-topic controls?
if (!is_null($topic_id))
{
$out['last_poster']=$topic_info['t_cache_last_member_id'];
$out['last_post_id']=$topic_info['t_cache_last_post_id'];
if ((is_null($forum_id)) || (ocf_may_post_in_topic($forum_id,$topic_id,$topic_info['t_cache_last_member_id'])))
$out['may_reply']=true;
if (ocf_may_report_post()) $out['may_report_posts']=true;
if (ocf_may_make_personal_topic()) $out['may_pt_members']=true;
if (ocf_may_edit_topics_by($forum_id,get_member(),$topic_info['t_cache_first_member_id'])) $out['may_edit_topic']=true;
require_code('ocf_moderation');
require_code('ocf_forums');
if (ocf_may_warn_members()) $out['may_warn_members']=true;
if (ocf_may_delete_topics_by($forum_id,get_member(),$topic_info['t_cache_first_member_id'])) $out['may_delete_topic']=true;
if (ocf_may_perform_multi_moderation($forum_id)) $out['may_multi_moderate']=true;
if (has_specific_permission(get_member(),'use_quick_reply')) $out['may_use_quick_reply']=true;
$may_moderate_forum=ocf_may_moderate_forum($forum_id);
if ($may_moderate_forum)
{
if ($topic_info['t_is_open']==0) $out['may_open_topic']=1; else $out['may_close_topic']=1;
if ($topic_info['t_pinned']==0) $out['may_pin_topic']=1; else $out['may_unpin_topic']=1;
if ($topic_info['t_sunk']==0) $out['may_sink_topic']=1; else $out['may_unsink_topic']=1;
if ($topic_info['t_cascading']==0) $out['may_cascade_topic']=1; else $out['may_uncascade_topic']=1;
$out['may_move_topic']=1;
$out['may_post_closed']=1;
$out['may_move_posts']=1;
$out['may_delete_posts']=1;
$out['may_validate_posts']=1;
$out['may_make_personal']=1;
$out['may_change_max']=1;
} else
{
if (($topic_info['t_cache_first_member_id']==get_member()) && (has_specific_permission(get_member(),'close_own_topics')) && ($topic_info['t_is_open']==1))
{
$out['may_close_topic']=1;
}
}
if (!is_null($topic_info['t_poll_id']))
{
require_code('ocf_polls');
if (ocf_may_edit_poll_by($forum_id,$topic_info['t_cache_first_member_id']))
$out['may_edit_poll']=1;
if (ocf_may_delete_poll_by($forum_id,$topic_info['t_cache_first_member_id']))
$out['may_delete_poll']=1;
} else
{
require_code('ocf_polls');
if (ocf_may_attach_poll($topic_id,$topic_info['t_cache_first_member_id'],!is_null($topic_info['t_poll_id']),$forum_id))
$out['may_attach_poll']=1;
}
} else
{
$out['last_poster']=NULL;
$out['last_post_id']=NULL;
$out['may_reply']=false;
}
return $out;
}
void ocf_cache_member_details(array members)
Mass-load details for a list of members into memory, to reduce queries when we access it later.
Parameters…
| Name | members |
|---|---|
| Description | List of members. |
| Type | array |
(No return value)
function ocf_cache_member_details($members)
{
require_code('ocf_members');
$member_or_list='';
foreach ($members as $member)
{
if ($member_or_list!='') $member_or_list.=' OR ';
$member_or_list.='m.id='.strval((integer)$member);
}
if ($member_or_list!='')
{
$member_rows=$GLOBALS['FORUM_DB']->query('SELECT m.*,text_parsed AS signature FROM '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_members m LEFT JOIN '.$GLOBALS['FORUM_DB']->get_table_prefix().'translate t ON '.db_string_equal_to('language',user_lang()).' AND m.m_signature=t.id WHERE '.$member_or_list);
global $TABLE_LANG_FIELDS;
$member_rows_2=$GLOBALS['FORUM_DB']->query('SELECT f.* FROM '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_member_custom_fields f WHERE '.str_replace('m.id','mf_member_id',$member_or_list),NULL,NULL,false,false,array_key_exists('f_member_custom_fields',$TABLE_LANG_FIELDS)?$TABLE_LANG_FIELDS['f_member_custom_fields']:array());
$member_rows_3=$GLOBALS['FORUM_DB']->query('SELECT gm_group_id,gm_member_id FROM '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_group_members WHERE gm_validated=1 AND ('.str_replace('m.id','gm_member_id',$member_or_list).')');
global $MEMBER_CACHE_FIELD_MAPPINGS,$GROUP_MEMBERS_CACHE,$SIGNATURES_CACHE;
$found_groups=array();
foreach ($member_rows as $row)
{
$GLOBALS['OCF_DRIVER']->MEMBER_ROWS_CACHED[$row['id']]=$row;
if (!ocf_is_ldap_member($row['id']))
{
// Primary
$pg=$GLOBALS['OCF_DRIVER']->get_member_row_field($row['id'],'m_primary_group');
$found_groups[$pg]=1;
$GROUP_MEMBERS_CACHE[$row['id']][false][false]=array($pg=>1);
}
// Signature
if ((get_page_name()!='search') && (!is_null($row['signature'])) && ($row['signature']!='') && ($row['m_signature']!=0))
{
$SIGNATURES_CACHE[$row['id']]=new ocp_tempcode();
if (!$SIGNATURES_CACHE[$row['id']]->from_assembly($row['signature'],true))
unset($SIGNATURES_CACHE[$row['id']]);
}
}
foreach ($member_rows_2 as $row)
{
$MEMBER_CACHE_FIELD_MAPPINGS[$row['mf_member_id']]=$row;
}
foreach ($member_rows_3 as $row)
{
if (!ocf_is_ldap_member($row['gm_member_id']))
{
$GROUP_MEMBERS_CACHE[$row['gm_member_id']][false][false][$row['gm_group_id']]=1;
$found_groups[$row['gm_group_id']]=1;
}
}
require_code('ocf_groups');
ocf_ensure_groups_cached(array_keys($found_groups));
}
}
tempcode ocf_render_post_buttons(array topic_info, array _postdetails, boolean may_reply)
Get buttons for showing under a post.
Parameters…
| Name | topic_info |
|---|---|
| Description | Map of topic info. |
| Type | array |
| Name | _postdetails |
|---|---|
| Description | Map of post info. |
| Type | array |
| Name | may_reply |
|---|---|
| Description | Whether the current member may reply to the topic |
| Type | boolean |
Returns…
| Description | The buttons. |
|---|---|
| Type | tempcode |
function ocf_render_post_buttons($topic_info,$_postdetails,$may_reply)
{
require_code('ocf_members2');
$buttons=new ocp_tempcode();
if ((array_key_exists('may_validate_posts',$topic_info)) && ((($topic_info['validated']==0) && ($_postdetails['id']==$topic_info['first_post_id'])) || ($_postdetails['validated']==0)))
{
$map=array('page'=>'topics','type'=>'validate_post','id'=>$_postdetails['id']);
$test=get_param_integer('kfs'.(is_null($topic_info['forum_id'])?'':strval($topic_info['forum_id'])),-1);
if (($test!=-1) && ($test!=0)) $map['kfs'.(is_null($topic_info['forum_id'])?'':strval($topic_info['forum_id']))]=$test;
$test=get_param_integer('threaded',-1);
if ($test!=-1) $map['threaded']=$test;
$action_url=build_url($map,get_module_zone('topics'));
$_title=do_lang_tempcode('VALIDATE_POST');
$_title->attach(do_lang_tempcode('ID_NUM',strval($_postdetails['id'])));
$buttons->attach(do_template('SCREEN_ITEM_BUTTON',array('_GUID'=>'712fdaee35f378e37b007f3a73246690','REL'=>'validate','IMMEDIATE'=>true,'IMG'=>'validate','TITLE'=>$_title,'URL'=>$action_url)));
}
if (($may_reply) && (is_null(get_bot_type())))
{
$map=array('page'=>'topics','type'=>'new_post','id'=>$_postdetails['topic_id'],'parent_id'=>$_postdetails['id']);
if ($topic_info['is_threaded']==0)
{
$map['quote']=$_postdetails['id'];
}
if (array_key_exists('intended_solely_for',$_postdetails))
{
$map['intended_solely_for']=$_postdetails['poster'];
}
$test=get_param_integer('kfs'.(is_null($topic_info['forum_id'])?'':strval($topic_info['forum_id'])),-1);
if (($test!=-1) && ($test!=0)) $map['kfs'.(is_null($topic_info['forum_id'])?'':strval($topic_info['forum_id']))]=$test;
$test=get_param_integer('threaded',-1);
if ($test!=-1) $map['threaded']=$test;
$action_url=build_url($map,get_module_zone('topics'));
$_title=do_lang_tempcode(($topic_info['is_threaded']==1)?'REPLY':'QUOTE_POST');
$_title->attach(do_lang_tempcode('ID_NUM',strval($_postdetails['id'])));
$javascript=NULL;
if ((array_key_exists('message_comcode',$_postdetails)) && (!is_null($_postdetails['message_comcode'])) && (!array_key_exists('intended_solely_for',$map)))
{
$javascript='return topic_reply('.($topic_info['is_threaded']?'true':'false').',this,\''.strval($_postdetails['id']).'\',\''.addslashes($_postdetails['poster_username']).'\',\''.str_replace(chr(10),'\n',addslashes($_postdetails['message_comcode'])).'\',\''.str_replace(chr(10),'\n',addslashes(strip_comcode($_postdetails['message_comcode']))).'\');';
}
$buttons->attach(do_template('SCREEN_ITEM_BUTTON',array('_GUID'=>'fc13d12cfe58324d78befec29a663b4f','REL'=>'add reply','IMMEDIATE'=>false,'IMG'=>($topic_info['is_threaded']==1)?'reply':'quote','TITLE'=>$_title,'URL'=>$action_url,'JAVASCRIPT'=>$javascript)));
}
if ((addon_installed('points')) && (!is_guest()) && (!is_guest($_postdetails['poster'])))
{
$action_url=build_url(array('page'=>'points','type'=>'member','id'=>$_postdetails['poster']),get_module_zone('points'));
$_title=do_lang_tempcode('POINTS_THANKS');
$buttons->attach(do_template('SCREEN_ITEM_BUTTON',array('_GUID'=>'a66f98cb4d56bd0d64e9ecc44d357141','IMMEDIATE'=>false,'IMG'=>'points','TITLE'=>$_title,'URL'=>$action_url)));
}
if ((array_key_exists('may_pt_members',$topic_info)) && ($may_reply) && ($_postdetails['poster']!=get_member()) && ($_postdetails['poster']!=$GLOBALS['OCF_DRIVER']->get_guest_id()) && (ocf_may_whisper($_postdetails['poster'])) && (get_option('overt_whisper_suggestion')=='1'))
{
$whisper_type=(get_value('no_inline_pp_advertise')==='1')?'new_pt':'whisper';
$action_url=build_url(array('page'=>'topics','type'=>$whisper_type,'id'=>$_postdetails['topic_id'],'quote'=>$_postdetails['id'],'intended_solely_for'=>$_postdetails['poster']),get_module_zone('topics'));
$_title=do_lang_tempcode('WHISPER');
$_title->attach(do_lang_tempcode('ID_NUM',strval($_postdetails['id'])));
$buttons->attach(do_template('SCREEN_ITEM_BUTTON',array('_GUID'=>'fb1c74bae9c553dc160ade85adf289b5','REL'=>'add reply contact','IMMEDIATE'=>false,'IMG'=>(get_value('no_inline_pp_advertise')==='1')?'send_message':'whisper','TITLE'=>$_title,'URL'=>$action_url)));
}
if ((array_key_exists('may_report_posts',$topic_info)) && (addon_installed('ocf_reported_posts')) && (is_null(get_bot_type())))
{
$action_url=build_url(array('page'=>'topics','type'=>'report_post','id'=>$_postdetails['id']),get_module_zone('topics'));
$_title=do_lang_tempcode('REPORT_POST');
$_title->attach(do_lang_tempcode('ID_NUM',strval($_postdetails['id'])));
$buttons->attach(do_template('SCREEN_ITEM_BUTTON',array('_GUID'=>'f81cbe84f524b4ed9e089c6e89a7c717','REL'=>'report','IMMEDIATE'=>false,'IMG'=>'report_post','TITLE'=>$_title,'URL'=>$action_url,'JAVASCRIPT'=>'return open_link_as_overlay(this,null,\'100%\');')));
}
if (array_key_exists('may_edit',$_postdetails))
{
$map=array('page'=>'topics','type'=>'edit_post','id'=>$_postdetails['id']);
$test=get_param_integer('kfs'.(is_null($topic_info['forum_id'])?'':strval($topic_info['forum_id'])),-1);
if (($test!=-1) && ($test!=0)) $map['kfs'.(is_null($topic_info['forum_id'])?'':strval($topic_info['forum_id']))]=$test;
$test=get_param_integer('threaded',-1);
if ($test!=-1) $map['threaded']=$test;
$edit_url=build_url($map,get_module_zone('topics'));
$_title=do_lang_tempcode('EDIT_POST');
$_title->attach(do_lang_tempcode('ID_NUM',strval($_postdetails['id'])));
$buttons->attach(do_template('SCREEN_ITEM_BUTTON',array('_GUID'=>'f341cfc94b3d705437d43e89f572bff6','REL'=>'edit','IMMEDIATE'=>false,'IMG'=>'edit','TITLE'=>$_title,'URL'=>$edit_url)));
}
if (array_key_exists('may_delete',$_postdetails))
{
$map=array('page'=>'topics','type'=>'delete_post','id'=>$_postdetails['id']);
$test=get_param_integer('kfs'.(is_null($topic_info['forum_id'])?'':strval($topic_info['forum_id'])),-1);
if (($test!=-1) && ($test!=0)) $map['kfs'.(is_null($topic_info['forum_id'])?'':strval($topic_info['forum_id']))]=$test;
$test=get_param_integer('threaded',-1);
if ($test!=-1) $map['threaded']=$test;
$delete_url=build_url($map,get_module_zone('topics'));
$_title=do_lang_tempcode('DELETE_POST');
$_title->attach(do_lang_tempcode('ID_NUM',strval($_postdetails['id'])));
$buttons->attach(do_template('SCREEN_ITEM_BUTTON',array('_GUID'=>'8bf6d098ddc217eef75718464dc03d41','REL'=>'delete','IMMEDIATE'=>false,'IMG'=>'delete','TITLE'=>$_title,'URL'=>$delete_url)));
}
if ((array_key_exists('may_warn_members',$topic_info)) && ($_postdetails['poster']!=$GLOBALS['OCF_DRIVER']->get_guest_id()) && (addon_installed('ocf_warnings')))
{
$redir_url=get_self_url(true);
$redir_url.='#post_'.strval($_postdetails['id']);
$action_url=build_url(array('page'=>'warnings','type'=>'ad','id'=>$_postdetails['poster'],'post_id'=>$_postdetails['id'],'redirect'=>$redir_url),get_module_zone('warnings'));
$_title=do_lang_tempcode('WARN_MEMBER');
$_title->attach(do_lang_tempcode('ID_NUM',strval($_postdetails['id'])));
$buttons->attach(do_template('SCREEN_ITEM_BUTTON',array('_GUID'=>'2698c51b06a72773ac7135bbfe791318','IMMEDIATE'=>false,'IMG'=>'punish','TITLE'=>$_title,'URL'=>$action_url)));
}
if ((has_specific_permission(get_member(),'view_content_history')) && ($_postdetails['has_history']))
{
$action_url=build_url(array('page'=>'admin_ocf_history','type'=>'misc','post_id'=>$_postdetails['id']),'adminzone');
$_title=do_lang_tempcode('POST_HISTORY');
$_title->attach(do_lang_tempcode('ID_NUM',strval($_postdetails['id'])));
$buttons->attach(do_template('SCREEN_ITEM_BUTTON',array('_GUID'=>'a66f98cb4d56bd0d64e9ecc44d357141','REL'=>'history','IMMEDIATE'=>false,'IMG'=>'history','TITLE'=>$_title,'URL'=>$action_url)));
}
return $buttons;
}
tempcode ocf_get_post_emphasis(array _postdetails)
Get post emphasis Tempcode.
Parameters…
| Name | _postdetails |
|---|---|
| Description | Map of post info. |
| Type | array |
Returns…
| Description | The tempcode. |
|---|---|
| Type | tempcode |
function ocf_get_post_emphasis($_postdetails)
{
$emphasis=new ocp_tempcode();
if ($_postdetails['is_emphasised'])
{
$emphasis=do_lang_tempcode('IMPORTANT');
}
elseif (array_key_exists('intended_solely_for',$_postdetails))
{
$pp_to_username=$GLOBALS['FORUM_DRIVER']->get_username($_postdetails['intended_solely_for']);
if (is_null($pp_to_username)) $pp_to_username=do_lang('UNKNOWN');
$emphasis=do_lang('PP_TO',$pp_to_username);
}
return $emphasis;
}




0 reviews: Unrated (average)
There have been no comments yet