ocPortal Developer's Guide: OCF forums
» Return to Contents
sources/ocf_forums.php
Global_functions_ocf_forums.php
void init__ocf_forums()
Standard code module initialisation function.
Parameters…
(No return value)
function init__ocf_forums()
{
global $USER_ACCESS_CACHE;
$USER_ACCESS_CACHE=array();
global $CATEGORY_TITLES;
$CATEGORY_TITLES=NULL;
global $FORUM_TREE_SECURE_CACHE;
$FORUM_TREE_SECURE_CACHE=mixed();
global $ALL_FORUMS_STRUCT;
$ALL_FORUMS_STRUCT=NULL;
}
array ocf_organise_into_tree(array all_forums, AUTO_LINK forum_id)
Organise a list of forum rows into a tree structure.
Parameters…
| Name |
all_forums |
| Description |
The list of all forum rows (be aware that this will get modified for performance reasons). |
| Type |
array |
| Name |
forum_id |
| Description |
The forum row that we are taking as the root of our current recursion. |
| Type |
AUTO_LINK |
Returns…
| Description |
The child list of $forum_id. |
| Type |
array |
function ocf_organise_into_tree(&$all_forums,$forum_id)
{
$children=array();
$all_forums_copy=$all_forums;
foreach ($all_forums_copy as $i=>$forum)
{
if ($forum['f_parent_forum']==$forum_id)
{
$forum['children']=ocf_organise_into_tree($all_forums,$forum['id']);
$children[$forum['id']]=$forum;
unset ($all_forums[$i]);
}
}
return $children;
}
mixed ocf_get_all_subordinate_forums(AUTO_LINK forum_id, ?string create_or_list, ?array tree, boolean ignore_permissions)
Gets a list of subordinate forums of a certain forum.
Parameters…
| Name |
forum_id |
| Description |
The ID of the forum we are finding subordinate forums of. |
| Type |
AUTO_LINK |
| Name |
create_or_list |
| Description |
The field name to use in the OR list (NULL: do not make an OR list, return an array). |
| Default value |
|
| Type |
?string |
| Name |
tree |
| Description |
The forum tree structure (NULL: unknown, it will be found using ocf_organise_into_tree). |
| Default value |
|
| Type |
?array |
| Name |
ignore_permissions |
| Description |
Whether to ignore permissions in this. |
| Default value |
boolean-false |
| Type |
boolean |
Returns…
| Description |
The list (is either a true list, or an OR list). |
| Type |
mixed |
function ocf_get_all_subordinate_forums($forum_id,$create_or_list=NULL,$tree=NULL,$ignore_permissions=false)
{
if (is_null($forum_id))
{
if (is_null($create_or_list)) return array($forum_id); else return '('.$create_or_list.' IS NULL)';
}
if (is_null($tree))
{
global $ALL_FORUMS_STRUCT;
if (is_null($ALL_FORUMS_STRUCT))
{
$huge_forums=$GLOBALS['FORUM_DB']->query_value('f_forums','COUNT(*)')>100;
if ($huge_forums)
{
$all_descendant=$GLOBALS['FORUM_DB']->query('SELECT id,f_parent_forum FROM '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_forums WHERE id='.strval($forum_id).' OR f_parent_forum='.strval($forum_id),300);
if (count($all_descendant)==300) // Too many
{
if (is_null($create_or_list)) return array($forum_id); else return '('.$create_or_list.'='.strval($forum_id).')';
}
$tree=ocf_organise_into_tree($all_descendant,$forum_id);
} else
{
$ALL_FORUMS_STRUCT=$GLOBALS['FORUM_DB']->query_select('f_forums');
$all_forum_struct_copy=$ALL_FORUMS_STRUCT;
$tree=ocf_organise_into_tree($all_forum_struct_copy,$forum_id);
}
} else
{
$all_forum_struct_copy=$ALL_FORUMS_STRUCT;
$tree=ocf_organise_into_tree($all_forum_struct_copy,$forum_id);
}
}
// $subordinates=$direct_subordinates;
$subordinates=array();
foreach ($tree as $subordinate)
{
$subordinates=$subordinates+ocf_get_all_subordinate_forums($subordinate['id'],NULL,$subordinate['children'],$ignore_permissions);
}
load_up_all_module_category_permissions(get_member(),'forums');
if (($ignore_permissions) || (has_category_access(get_member(),'forums',strval($forum_id))))
$subordinates[$forum_id]=$forum_id;
if (!is_null($create_or_list))
{
$or_list='';
foreach ($subordinates as $subordinate)
{
if ($or_list!='') $or_list.=' OR ';
$or_list.=$create_or_list.'='.strval($subordinate);
}
if ($or_list=='') return $or_list;
return '('.$or_list.')';
}
return $subordinates;
}
boolean ocf_may_moderate_forum(AUTO_LINK forum_id, ?MEMBER member_id)
Find whether a member may moderate a certain forum.
Parameters…
| Name |
forum_id |
| Description |
The ID of the forum. |
| Type |
AUTO_LINK |
| Name |
member_id |
| Description |
The member ID (NULL: current member). |
| Default value |
|
| Type |
?MEMBER |
Returns…
| Description |
The answer. |
| Type |
boolean |
function ocf_may_moderate_forum($forum_id,$member_id=NULL)
{
if (is_null($member_id)) $member_id=get_member();
if (is_null($forum_id)) return has_specific_permission($member_id,'moderate_personal_topic');
return has_specific_permission($member_id,'edit_midrange_content','topics',array('forums',$forum_id));
}
string ocf_get_forum_parent_or_list(AUTO_LINK forum_id, ?AUTO_LINK parent_id)
Get an OR list of a forums parents, suited for selection from the f_topics table.
Parameters…
| Name |
forum_id |
| Description |
The ID of the forum. |
| Type |
AUTO_LINK |
| Name |
parent_id |
| Description |
The ID of the parent forum (-1: get it from the DB) (NULL: there is no parent, as it is the root forum). |
| Default value |
-1 |
| Type |
?AUTO_LINK |
Returns…
| Description |
The OR list. |
| Type |
string |
function ocf_get_forum_parent_or_list($forum_id,$parent_id=-1)
{
if (is_null($forum_id)) return '';
if ($parent_id==-1) $parent_id=$GLOBALS['FORUM_DB']->query_value('f_forums','f_parent_forum',array('id'=>$forum_id));
$from_below=ocf_get_forum_parent_or_list($parent_id);
$term='t_forum_id='.strval((integer)$forum_id);
return $term.(($from_below!='')?(' OR '.$from_below):'');
}
tempcode ocf_forum_breadcrumbs(mixed end_point_forum, ?string this_name, ?AUTO_LINK parent_forum, boolean start)
Get a forum navigation tree (a horizontal thing that works backwards along the tree path ['bread crumb trail'], not a full tree).
Parameters…
| Name |
end_point_forum |
| Description |
The ID of the forum we are at in our path (NULL: end of recursion) (false: no forum ID available, this_name and parent_forum must not be NULL). |
| Type |
mixed |
| Name |
this_name |
| Description |
The name of the given forum (NULL: find it from the DB). |
| Default value |
|
| Type |
?string |
| Name |
parent_forum |
| Description |
The parent forum of the given forum (NULL: find it from the DB). |
| Default value |
|
| Type |
?AUTO_LINK |
| Name |
start |
| Description |
Whether this is being called as the recursion start of deriving the navigation tree (top level call). |
| Default value |
boolean-true |
| Type |
boolean |
Returns…
| Description |
The navigation tree. |
| Type |
tempcode |
function ocf_forum_breadcrumbs($end_point_forum,$this_name=NULL,$parent_forum=NULL,$start=true)
{
if (is_null($end_point_forum))
{
return new ocp_tempcode();
}
if (is_null($this_name))
{
$_forum_details=$GLOBALS['FORUM_DB']->query_select('f_forums',array('f_name','f_parent_forum'),array('id'=>$end_point_forum),'',1);
if (!array_key_exists(0,$_forum_details)) return new ocp_tempcode();//warn_exit(do_lang_tempcode('_MISSING_RESOURCE','forum#'.strval($end_point_forum)));
$forum_details=$_forum_details[0];
$this_name=escape_html($forum_details['f_name']);
$parent_forum=$forum_details['f_parent_forum'];
} else $this_name=escape_html($this_name);
if (((!$start) || (has_specific_permission(get_member(),'open_virtual_roots'))) && (is_integer($end_point_forum)))
{
$map=array('page'=>'forumview');
if ($end_point_forum!=db_get_first_id()) $map['id']=$end_point_forum;
$test=get_param_integer('kfs'.strval($end_point_forum),-1);
if (($test!=-1) && ($test!=0)) $map['kfs'.strval($end_point_forum)]=$test;
if ($start) $map['keep_forum_root']=$end_point_forum;
$_this_name=hyperlink(build_url($map,get_module_zone('forumview')),$this_name,false,false,$start?do_lang_tempcode('VIRTUAL_ROOT'):do_lang_tempcode('GO_BACKWARDS_TO',@html_entity_decode($this_name,ENT_QUOTES,get_charset())),NULL,NULL,'up');
} else
{
$_this_name=make_string_tempcode('<span>'.$this_name.'</span>');
}
if ($end_point_forum!==get_param_integer('keep_forum_root',db_get_first_id()))
{
$out=ocf_forum_breadcrumbs($parent_forum,NULL,NULL,false);
if (!$out->is_empty()) $out->attach(do_template('BREADCRUMB_ESCAPED'));
} else $out=new ocp_tempcode();
$out->attach($_this_name);
return $out;
}
sources/ocf_forums_action.php
Global_functions_ocf_forums_action.php
Function summary
|
AUTO_LINK
|
ocf_make_category (SHORT_TEXT title, SHORT_TEXT description, BINARY expanded_by_default)
|
|
AUTO_LINK
|
ocf_make_forum (SHORT_TEXT name, SHORT_TEXT description, ?AUTO_LINK category_id, ?array access_mapping, ?AUTO_LINK parent_forum, integer position, BINARY post_count_increment, BINARY order_sub_alpha, LONG_TEXT intro_question, SHORT_TEXT intro_answer, SHORT_TEXT redirection, ID_TEXT order, BINARY is_threaded)
|
AUTO_LINK ocf_make_category(SHORT_TEXT title, SHORT_TEXT description, BINARY expanded_by_default)
Add a forum category.
Parameters…
| Name |
title |
| Description |
The title of the forum category. |
| Type |
SHORT_TEXT |
| Name |
description |
| Description |
The description of the forum category. |
| Type |
SHORT_TEXT |
| Name |
expanded_by_default |
| Description |
Whether the forum category will be shown expanded by default (as opposed to contracted, where contained forums will not be shown until expansion). |
| Default value |
1 |
| Type |
BINARY |
Returns…
| Description |
The ID of the forum category just added. |
| Type |
AUTO_LINK |
function ocf_make_category($title,$description,$expanded_by_default=1)
{
$category_id=$GLOBALS['FORUM_DB']->query_insert('f_categories',array(
'c_title'=>$title,
'c_description'=>$description,
'c_expanded_by_default'=>$expanded_by_default
),true);
log_it('ADD_FORUM_CATEGORY',strval($category_id),$title);
return $category_id;
}
AUTO_LINK ocf_make_forum(SHORT_TEXT name, SHORT_TEXT description, ?AUTO_LINK category_id, ?array access_mapping, ?AUTO_LINK parent_forum, integer position, BINARY post_count_increment, BINARY order_sub_alpha, LONG_TEXT intro_question, SHORT_TEXT intro_answer, SHORT_TEXT redirection, ID_TEXT order, BINARY is_threaded)
Make a forum.
Parameters…
| Name |
name |
| Description |
The name of the forum. |
| Type |
SHORT_TEXT |
| Name |
description |
| Description |
The description for the forum. |
| Type |
SHORT_TEXT |
| Name |
category_id |
| Description |
What forum category the forum will be filed with (NULL: this is the root forum). |
| Type |
?AUTO_LINK |
| Name |
access_mapping |
| Description |
Permission map (NULL: do it the standard way, outside of this function). This parameter is for import/compatibility only and works upon an emulation of 'access levels' (ala ocPortal 2.5/2.6), and it is recommended to use the normal aed_module functionality for permissions setting. |
| Type |
?array |
| Name |
parent_forum |
| Description |
The ID of the parent forum (NULL: this is the root forum). |
| Type |
?AUTO_LINK |
| Name |
position |
| Description |
The position of this forum relative to other forums viewable on the same screen (if parent forum hasn't specified automatic ordering). |
| Default value |
1 |
| Type |
integer |
| Name |
post_count_increment |
| Description |
Whether post counts will be incremented if members post in the forum. |
| Default value |
1 |
| Type |
BINARY |
| Name |
order_sub_alpha |
| Description |
Whether the ordering of subforums is done automatically, alphabetically). |
| Default value |
0 |
| Type |
BINARY |
| Name |
intro_question |
| Description |
The question that is shown for newbies to the forum (blank: none). |
| Default value |
|
| Type |
LONG_TEXT |
| Name |
intro_answer |
| Description |
The answer to the question (blank: no specific answer.. if there's a 'question', it just requires a click-through). |
| Default value |
|
| Type |
SHORT_TEXT |
| Name |
redirection |
| Description |
Either blank for no redirection, the ID of another forum we are mirroring, or a URL to redirect to. |
| Default value |
|
| Type |
SHORT_TEXT |
| Name |
order |
| Description |
The order the topics are shown in, by default. |
| Default value |
last_post |
| Type |
ID_TEXT |
| Name |
is_threaded |
| Description |
Whether the forum is threaded. |
| Default value |
0 |
| Type |
BINARY |
Returns…
| Description |
The ID of the newly created forum. |
| Type |
AUTO_LINK |
function ocf_make_forum($name,$description,$category_id,$access_mapping,$parent_forum,$position=1,$post_count_increment=1,$order_sub_alpha=0,$intro_question='',$intro_answer='',$redirection='',$order='last_post',$is_threaded=0)
{
if ($category_id==-1) $category_id=NULL;
if ($parent_forum==-1) $parent_forum=NULL;
if (get_page_name()!='admin_import')
{
if ((!is_null($category_id)) && (function_exists('ocf_ensure_category_exists'))) ocf_ensure_category_exists($category_id);
if ((!is_null($parent_forum)) && (function_exists('ocf_ensure_forum_exists'))) ocf_ensure_forum_exists($parent_forum);
}
$forum_id=$GLOBALS['FORUM_DB']->query_insert('f_forums',array(
'f_name'=>$name,
'f_description'=>insert_lang($description,2,$GLOBALS['FORUM_DB']),
'f_category_id'=>$category_id,
'f_parent_forum'=>$parent_forum,
'f_position'=>$position,
'f_order_sub_alpha'=>$order_sub_alpha,
'f_post_count_increment'=>$post_count_increment,
'f_intro_question'=>insert_lang($intro_question,3,$GLOBALS['FORUM_DB']),
'f_intro_answer'=>$intro_answer,
'f_cache_num_topics'=>0,
'f_cache_num_posts'=>0,
'f_cache_last_topic_id'=>NULL,
'f_cache_last_forum_id'=>NULL,
'f_cache_last_title'=>'',
'f_cache_last_time'=>NULL,
'f_cache_last_username'=>'',
'f_cache_last_member_id'=>NULL,
'f_redirection'=>$redirection,
'f_order'=>$order,
'f_is_threaded'=>$is_threaded,
),true);
// Set permissions
if (!is_null($access_mapping))
{
$groups=$GLOBALS['OCF_DRIVER']->get_usergroup_list(false,true);
foreach (array_keys($groups) as $group_id)
{
$level=0; // No-access
if (array_key_exists($group_id,$access_mapping)) $level=$access_mapping[$group_id];
if ($level>=1) // Access
{
$GLOBALS['FORUM_DB']->query_insert('group_category_access',array(
'module_the_name'=>'forums',
'category_name'=>strval($forum_id),
'group_id'=>$group_id
));
if ($level==1) // May not post - so specifically override to say this
{
$GLOBALS['FORUM_DB']->query_insert('gsp',array('specific_permission'=>'submit_lowrange_content','group_id'=>$group_id,'the_page'=>'','module_the_name'=>'forums','category_name'=>strval($forum_id),'the_value'=>0));
$GLOBALS['FORUM_DB']->query_insert('gsp',array('specific_permission'=>'submit_midrange_content','group_id'=>$group_id,'the_page'=>'','module_the_name'=>'forums','category_name'=>strval($forum_id),'the_value'=>0));
}
if ($level>=3)
{
$GLOBALS['FORUM_DB']->query_insert('gsp',array('specific_permission'=>'bypass_validation_lowrange_content','group_id'=>$group_id,'the_page'=>'','module_the_name'=>'forums','category_name'=>strval($forum_id),'the_value'=>1));
}
if ($level>=4)
{
$GLOBALS['FORUM_DB']->query_insert('gsp',array('specific_permission'=>'bypass_validation_midrange_content','group_id'=>$group_id,'the_page'=>'','module_the_name'=>'forums','category_name'=>strval($forum_id),'the_value'=>1));
}
// 2=May post, [3=May post instantly , 4=May start topics instantly , 5=Moderator -- these ones will not be treated specially, so as to avoid overriding permissions unnecessary - let the admins configure it optimally manually]
}
}
}
log_it('ADD_FORUM',strval($forum_id),$name);
return $forum_id;
}
0 reviews: Unrated (average)
There have been no comments yet