ocPortal Developer's Guide: OCF topics
» Return to Contents
sources/ocf_topics.php
Global_functions_ocf_topics.php
Function summary
|
string
|
ocf_get_topic_where (AUTO_LINK topic_id)
|
|
boolean
|
ocf_may_make_personal_topic (?MEMBER member_id)
|
|
boolean
|
ocf_may_post_topic (AUTO_LINK forum_id, ?MEMBER member_id)
|
|
boolean
|
ocf_may_report_post (?MEMBER member_id)
|
|
boolean
|
ocf_has_replied_topic (AUTO_LINK topic_id, ?MEMBER member_id)
|
|
boolean
|
ocf_may_edit_topics_by (AUTO_LINK forum_id, MEMBER member_id, MEMBER resource_owner)
|
|
boolean
|
ocf_may_delete_topics_by (AUTO_LINK forum_id, MEMBER member_id, MEMBER resource_owner)
|
|
void
|
ocf_ping_topic_read (AUTO_LINK topic_id)
|
|
boolean
|
ocf_has_read_topic (AUTO_LINK topic_id, ?TIME topic_last_time, ?MEMBER member_id, ?TIME member_last_time)
|
|
boolean
|
ocf_has_special_pt_access (AUTO_LINK topic_id, ?MEMBER member_id)
|
string ocf_get_topic_where(AUTO_LINK topic_id)
Get an SQL 'WHERE' clause for the posts in a topic.
Parameters…
| Name |
topic_id |
| Description |
The ID of the topic we are getting details of. |
| Type |
AUTO_LINK |
Returns…
| Description |
The WHERE clause. |
| Type |
string |
function ocf_get_topic_where($topic_id)
{
$where='p_topic_id='.strval((integer)$topic_id);
if (is_guest())
$where.=' AND p_intended_solely_for IS NULL';
elseif (!has_specific_permission(get_member(),'view_other_pt'))
$where.=' AND (p_intended_solely_for='.strval((integer)get_member()).' OR p_poster='.strval((integer)get_member()).' OR p_intended_solely_for IS NULL)';
if (!has_specific_permission(get_member(),'see_unvalidated')) $where.=' AND (p_validated=1 OR ((p_poster<>'.strval($GLOBALS['FORUM_DRIVER']->get_guest_id()).' OR '.db_string_equal_to('p_ip_address',get_ip_address()).') AND p_poster='.strval((integer)get_member()).'))';
return $where;
}
boolean ocf_may_make_personal_topic(?MEMBER member_id)
Find whether a member may make a Private Topic.
Parameters…
| Name |
member_id |
| Description |
The member (NULL: current member). |
| Default value |
|
| Type |
?MEMBER |
Returns…
| Description |
The answer. |
| Type |
boolean |
function ocf_may_make_personal_topic($member_id=NULL)
{
if (is_null($member_id)) $member_id=get_member();
if (!has_specific_permission($member_id,'use_pt')) return false;
return $member_id!=$GLOBALS['OCF_DRIVER']->get_guest_id();
}
boolean ocf_may_post_topic(AUTO_LINK forum_id, ?MEMBER member_id)
Find whether a member may post a topic in a certain forum.
Parameters…
| Name |
forum_id |
| Description |
The forum the topic would be in. |
| Type |
AUTO_LINK |
| Name |
member_id |
| Description |
The member (NULL: current member). |
| Default value |
|
| Type |
?MEMBER |
Returns…
| Description |
The answer. |
| Type |
boolean |
function ocf_may_post_topic($forum_id,$member_id=NULL)
{
if (is_null($member_id)) $member_id=get_member();
if (!has_specific_permission($member_id,'submit_midrange_content','topics',array('forums',$forum_id))) return false;
if (is_null($forum_id)) return true;
/*$test=$GLOBALS['FORUM_DB']->query_value_null_ok_full('SELECT id FROM '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_warnings WHERE p_silence_from_forum='.strval($forum_id).' AND w_member_id='.strval($member_id));
if (!is_null($test)) return false;*/
return true;
}
boolean ocf_may_report_post(?MEMBER member_id)
Find whether a member may report a post.
Parameters…
| Name |
member_id |
| Description |
The member (NULL: current member). |
| Default value |
|
| Type |
?MEMBER |
Returns…
| Description |
The answer. |
| Type |
boolean |
function ocf_may_report_post($member_id=NULL)
{
if (is_null($member_id)) $member_id=get_member();
return has_specific_permission($member_id,'may_report_post');
}
boolean ocf_has_replied_topic(AUTO_LINK topic_id, ?MEMBER member_id)
Find whether a member has replied to a certain topic.
Parameters…
| Name |
topic_id |
| Description |
The topic. |
| Type |
AUTO_LINK |
| Name |
member_id |
| Description |
The member (NULL: current member). |
| Default value |
|
| Type |
?MEMBER |
Returns…
| Description |
The answer. |
| Type |
boolean |
function ocf_has_replied_topic($topic_id,$member_id=NULL)
{
$test=$GLOBALS['FORUM_DB']->query_value('f_posts','id',array('p_topic_id'=>$topic_id,'p_poster'=>$member_id));
return !is_null($test);
}
boolean ocf_may_edit_topics_by(AUTO_LINK forum_id, MEMBER member_id, MEMBER resource_owner)
Find whether a member may edit topics in a certain forum.
Parameters…
| Name |
forum_id |
| Description |
The forum the topic would be in. |
| Type |
AUTO_LINK |
| Name |
member_id |
| Description |
The member checking access for. |
| Type |
MEMBER |
| Name |
resource_owner |
| Description |
The member that owns this resource |
| Type |
MEMBER |
Returns…
| Description |
The answer. |
| Type |
boolean |
function ocf_may_edit_topics_by($forum_id,$member_id,$resource_owner)
{
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_edit_permission('mid',$member_id,$resource_owner,'topics',array('forums',$forum_id));
}
boolean ocf_may_delete_topics_by(AUTO_LINK forum_id, MEMBER member_id, MEMBER resource_owner)
Find whether a member may delete topics in a certain forum.
Parameters…
| Name |
forum_id |
| Description |
The forum the topic would be in. |
| Type |
AUTO_LINK |
| Name |
member_id |
| Description |
The member checking access for. |
| Type |
MEMBER |
| Name |
resource_owner |
| Description |
The member that owns this resource |
| Type |
MEMBER |
Returns…
| Description |
The answer. |
| Type |
boolean |
function ocf_may_delete_topics_by($forum_id,$member_id,$resource_owner)
{
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_delete_permission('mid',$member_id,$resource_owner,'topics',array('forums',$forum_id));
}
void ocf_ping_topic_read(AUTO_LINK topic_id)
Mark a topic as read by the current member.
Parameters…
| Name |
topic_id |
| Description |
The Id of the topic to mark as read. |
| Type |
AUTO_LINK |
(No return value)
function ocf_ping_topic_read($topic_id)
{
$member_id=get_member();
$GLOBALS['FORUM_DB']->query_delete('f_read_logs',array('l_member_id'=>$member_id,'l_topic_id'=>$topic_id),'',1);
$GLOBALS['FORUM_DB']->query_insert('f_read_logs',array('l_member_id'=>$member_id,'l_topic_id'=>$topic_id,'l_time'=>time()),false,true); // race condition
}
boolean ocf_has_read_topic(AUTO_LINK topic_id, ?TIME topic_last_time, ?MEMBER member_id, ?TIME member_last_time)
Find whether a member has read a certain topic, such that they have possibly read all posts within it already.
Parameters…
| Name |
topic_id |
| Description |
The ID of the topic. |
| Type |
AUTO_LINK |
| Name |
topic_last_time |
| Description |
The time of the last post in the topic (NULL: get it from the DB). |
| Default value |
|
| Type |
?TIME |
| Name |
member_id |
| Description |
The member (NULL: current member). |
| Default value |
|
| Type |
?MEMBER |
| Name |
member_last_time |
| Description |
The time the member last viewed the topic (NULL: get it from the DB). |
| Default value |
|
| Type |
?TIME |
Returns…
| Description |
They have read it as such, yes. |
| Type |
boolean |
function ocf_has_read_topic($topic_id,$topic_last_time=NULL,$member_id=NULL,$member_last_time=NULL)
{
if (is_null($member_id)) $member_id=get_member();
if ($member_id==$GLOBALS['OCF_DRIVER']->get_guest_id()) return true;
if (is_null($topic_last_time))
$topic_last_time=$GLOBALS['FORUM_DB']->query_value('f_topics','t_cache_last_time',array('id'=>$topic_id));
$seven_days_ago=time()-60*60*24*intval(get_option('post_history_days'));
// Occasionally we need to delete old entries
if (mt_rand(0,1000)==123)
{
$GLOBALS['FORUM_DB']->query('DELETE FROM '.$GLOBALS['FORUM_DB']->get_table_prefix().'f_read_logs WHERE l_time<'.strval($seven_days_ago));
}
if ($topic_last_time<$seven_days_ago) return true; // We don't store that old
if (is_null($member_last_time))
$member_last_time=$GLOBALS['FORUM_DB']->query_value_null_ok('f_read_logs','l_time',array('l_member_id'=>$member_id,'l_topic_id'=>$topic_id));
if (is_null($member_last_time)) return false;
if ($member_last_time<$topic_last_time) return false;
return true;
}
boolean ocf_has_special_pt_access(AUTO_LINK topic_id, ?MEMBER member_id)
Find whether a member has special access to a certain PT.
Parameters…
| Name |
topic_id |
| Description |
The ID of the topic. |
| Type |
AUTO_LINK |
| Name |
member_id |
| Description |
The member (NULL: current member). |
| Default value |
|
| Type |
?MEMBER |
Returns…
| Description |
Whether they have special access. |
| Type |
boolean |
function ocf_has_special_pt_access($topic_id,$member_id=NULL)
{
if (is_null($member_id)) $member_id=get_member();
static $special_pt_access_cache=array();
if (!array_key_exists($topic_id,$special_pt_access_cache))
$special_pt_access_cache[$topic_id]=$GLOBALS['FORUM_DB']->query_select('f_special_pt_access',array('s_member_id'),array('s_topic_id'=>$topic_id));
foreach ($special_pt_access_cache[$topic_id] as $t)
{
if ($t['s_member_id']==$member_id) return true;
}
return false;
}
sources/ocf_topics_action.php
Global_functions_ocf_topics_action.php
Function summary
|
AUTO_LINK
|
ocf_make_topic (?AUTO_LINK forum_id, SHORT_TEXT description, SHORT_TEXT emoticon, ?BINARY validated, BINARY open, BINARY pinned, BINARY sunk, BINARY cascading, ?MEMBER pt_from, ?MEMBER pt_to, boolean check_perms, integer num_views, ?AUTO_LINK id, SHORT_TEXT description_link)
|
AUTO_LINK ocf_make_topic(?AUTO_LINK forum_id, SHORT_TEXT description, SHORT_TEXT emoticon, ?BINARY validated, BINARY open, BINARY pinned, BINARY sunk, BINARY cascading, ?MEMBER pt_from, ?MEMBER pt_to, boolean check_perms, integer num_views, ?AUTO_LINK id, SHORT_TEXT description_link)
Add a topic.
Parameters…
| Name |
forum_id |
| Description |
The ID of the forum the topic will be in (NULL: Private Topic). |
| Type |
?AUTO_LINK |
| Name |
description |
| Description |
Description of the topic. |
| Default value |
|
| Type |
SHORT_TEXT |
| Name |
emoticon |
| Description |
The theme image code of the emoticon for the topic. |
| Default value |
|
| Type |
SHORT_TEXT |
| Name |
validated |
| Description |
Whether the topic is validated (NULL: detect whether it should be). |
| Default value |
|
| Type |
?BINARY |
| Name |
open |
| Description |
Whether the topic is open. |
| Default value |
1 |
| Type |
BINARY |
| Name |
pinned |
| Description |
Whether the topic is pinned. |
| Default value |
0 |
| Type |
BINARY |
| Name |
sunk |
| Description |
Whether the topic is sunk. |
| Default value |
0 |
| Type |
BINARY |
| Name |
cascading |
| Description |
Whether the topic is cascading. |
| Default value |
0 |
| Type |
BINARY |
| Name |
pt_from |
| Description |
If it is a Private Topic, who is it 'from' (NULL: not a Private Topic). |
| Default value |
|
| Type |
?MEMBER |
| Name |
pt_to |
| Description |
If it is a Private Topic, who is it 'to' (NULL: not a Private Topic). |
| Default value |
|
| Type |
?MEMBER |
| Name |
check_perms |
| Description |
Whether to check the poster has permissions for the given topic settings. |
| Default value |
boolean-true |
| Type |
boolean |
| Name |
num_views |
| Description |
The number of times the topic has been viewed. |
| Default value |
0 |
| Type |
integer |
| Name |
id |
| Description |
Force an ID (NULL: don't force an ID) |
| Default value |
|
| Type |
?AUTO_LINK |
| Name |
description_link |
| Description |
Link related to the topic (e.g. link to view a ticket). |
| Default value |
|
| Type |
SHORT_TEXT |
Returns…
| Description |
The ID of the newly created topic. |
| Type |
AUTO_LINK |
function ocf_make_topic($forum_id,$description='',$emoticon='',$validated=NULL,$open=1,$pinned=0,$sunk=0,$cascading=0,$pt_from=NULL,$pt_to=NULL,$check_perms=true,$num_views=0,$id=NULL,$description_link='')
{
if (is_null($pinned)) $pinned=0;
if (is_null($sunk)) $sunk=0;
if (is_null($description)) $description='';
if (is_null($num_views)) $num_views=0;
if ($check_perms)
{
require_code('ocf_topics');
if (!ocf_may_post_topic($forum_id,get_member()))
{
access_denied('I_ERROR');
}
if (!is_null($pt_to))
{
decache('side_ocf_personal_topics',array($pt_to));
decache('_new_pp',array($pt_to));
}
if (!is_null($forum_id))
{
require_code('ocf_posts_action');
ocf_decache_ocp_blocks($forum_id);
}
require_code('ocf_forums');
if (!ocf_may_moderate_forum($forum_id))
{
$pinned=0;
$sunk=0;
$open=1;
$cascading=0;
}
}
if ((is_null($validated)) || (($check_perms) && ($validated==1)))
{
if ((!is_null($forum_id)) && (!has_specific_permission(get_member(),'bypass_validation_midrange_content','topics',array('forums',$forum_id)))) $validated=0; else $validated=1;
}
if (!addon_installed('unvalidated')) $validated=1;
$map=array(
't_pinned'=>$pinned,
't_sunk'=>$sunk,
't_cascading'=>$cascading,
't_forum_id'=>$forum_id,
't_pt_from'=>$pt_from,
't_pt_to'=>$pt_to,
't_description'=>$description,
't_description_link'=>$description_link,
't_emoticon'=>$emoticon,
't_num_views'=>$num_views,
't_validated'=>$validated,
't_is_open'=>$open,
't_poll_id'=>NULL,
't_cache_first_post_id'=>NULL,
't_cache_first_post'=>NULL,
't_cache_first_time'=>NULL,
't_cache_first_title'=>'',
't_cache_first_username'=>'',
't_cache_first_member_id'=>NULL,
't_cache_last_post_id'=>NULL,
't_cache_last_time'=>NULL,
't_cache_last_title'=>'',
't_cache_last_username'=>'',
't_cache_last_member_id'=>NULL,
't_cache_num_posts'=>0,
't_pt_from_category'=>'',
't_pt_to_category'=>''
);
if (!is_null($id)) $map['id']=$id;
return $GLOBALS['FORUM_DB']->query_insert('f_topics',$map,true);
}
0 reviews: Unrated (average)
There have been no comments yet