📄 post.api.php
字号:
<?php
//******************************************************//
// ///////// //// /////
// // // // // //
// // ///// ////// //// ////
// // // //// // // // //
// ///////// ///// ////// ///// /////
//******************************************************//
// icebb.net // 1.0
//******************************************************//
// post API
// $Id$
//******************************************************//
/**
* IceBB Post API
*
* @package IceBB
* @version 0.9
* @date October 23, 2005
*/
class post_lib
{
var $last_topic_id;
var $last_post_id;
/**
* Constructor
*/
function post_lib(&$calling_class,&$api_core)
{
global $icebb,$db;
$this->calling_class= &$calling_class;
$this->api_core = &$api_core;
}
/**
* Create a new topic
*
* @argument $fid int Forum ID
* @argument $icon string Topic icon
* @argument $title string Topic title
* @argument $desc string Topic description
* @argument $author_id int Author ID
* @argument $content string Post content
* @argument $has_poll boolean Does this topic have a poll?
*/
function new_topic($fid,$icon,$title,$desc,$author_id,$content,$has_poll=0)
{
global $icebb,$db; // fix backslash $content = $this->api_core->db->escape_string($content);
$topicsq = $this->api_core->db->query("SELECT * FROM icebb_topics ORDER BY tid DESC LIMIT 1");
$last_topic = $this->api_core->db->fetch_row($topicsq);
$tid = $last_topic['tid']+1;
$this->last_topic_id= $tid;
$postsq = $this->api_core->db->query("SELECT * FROM icebb_posts ORDER BY pid DESC LIMIT 1");
$last_post = $this->api_core->db->fetch_row($postsq);
$pid = $last_post['pid']+1;
$this->last_post_id= $pid;
$pedits = serialize(array('original'=>array('ptext'=>$content,'pauthor_id'=>$author_id,'pdate'=>time())));
$t = array(
'tid' => $tid,
'forum' => $fid,
'icon' => $icon,
'title' => $title,
'description' => $desc,
'snippet' => substr($content,0,255),
'starter' => $this->api_core->icebb->user['username'],
'lastpost_time' => time(),
'lastpost_author'=> $this->api_core->icebb->user['username'],
'has_poll' => $has_poll,
'views' => 0,
);
$this->api_core->db->insert('icebb_topics',$t);
$p = array(
'pid' => $pid,
'ptopicid' => $tid,
'pauthor_id' => $author_id,
'pauthor_ip' => $this->api_core->icebb->user['ip'],
'pdate' => time(),
'ptext' => $content,
'pedits' => $pedits,
'pis_firstpost' => '1',
);
$this->api_core->db->insert('icebb_posts',$p);
$newraid = $this->api_core->db->fetch_result("SELECT `id` FROM `icebb_ra_logs` ORDER BY `id` DESC LIMIT 0,1");
$newraid = $newraid['id'] + 1;
$ra = array(
'id' => $newraid,
'time' => time(),
'user' => $this->api_core->icebb->user['username'],
'ip' => $this->api_core->icebb->client_ip,
'action' => "Topic Created: <a href=\'{$this->api_core->icebb->base_url}topic={$tid}\'>{$title}</a>",
'forum_id' => $fid,
);
$this->api_core->db->insert('icebb_ra_logs',$ra);
$this->api_core->db->query("UPDATE icebb_forums SET topics=topics+1,lastpostid='{$tid}',lastpost_time=".time().",lastpost_title='{$this->api_core->icebb->input['ptitle']}',lastpost_author='{$this->api_core->icebb->user['username']}' WHERE fid='{$this->api_core->icebb->input['forum']}' LIMIT 1");
$f = $this->api_core->db->fetch_result("SELECT * FROM icebb_forums WHERE fid='{$this->api_core->icebb->input['forum']}'");
while($f['parent'] != '0')
{
$this->api_core->db->query("UPDATE icebb_forums SET topics=topics+1,lastpostid='{$tid}',lastpost_time=".time().",lastpost_title='{$this->api_core->icebb->input['ptitle']}',lastpost_author='{$this->api_core->icebb->user['username']}' WHERE fid='{$f['parent']}' LIMIT 1");
$f = $this->api_core->db->fetch_result("SELECT * FROM icebb_forums WHERE fid='{$f['parent']}'");
}
$this->_update_post_count($author_id);
$this->_update_stats();
// update users last post timestamp
if($icebb->user['id'] != '0')
{
$db->query("UPDATE icebb_users SET last_post='".time()."' WHERE id='{$icebb->user['id']}' LIMIT 1");
}
// subscriptions
$this->calling_class->subscriptions->notify($t,$p);
}
/**
* Attach a poll to a topic
*
* @argument $tid int Topic ID
* @argument $question string Poll question
* @argument $type string Poll type
* @argument $choices array Poll choices
*/
function attach_poll($tid,$question,$type,$choices)
{
foreach($choices as $id => $c)
{
if(!empty($c))
{
$poll_choice[$id]= array('cid'=>$id,'ctext'=>$c);
}
}
$this->api_core->db->insert('icebb_polls',array(
'polltid' => $tid,
'pollq' => $question,
'type' => $type,
'pollopt' => serialize($poll_choice),
));
$forum = $this->db->fetch_result("SELECT forum FROM icebb_topics WHERE tid='{$tid}' LIMIT 1");
$forum = $forum['forum'];
$newraid = $this->api_core->db->fetch_result("SELECT `id` FROM `icebb_ra_logs` ORDER BY `id` DESC LIMIT 0,1");
$newraid = $newraid['id']+1;
$ra = array(
'id' => $newraid,
'time' => time(),
'user' => $this->api_core->icebb->user['username'],
'ip' => $this->api_core->icebb->client_ip,
'action' => "Poll Attached: <a href=\'{$this->api_core->icebb->base_url}topic={$tid}\'>{$title}</a>",
'forum_id' => $forum,
);
$this->api_core->db->insert('icebb_ra_logs',$ra);
}
/**
* Edit a topic
*
* @argument $pid int Post ID * @argument $tid int Topic ID
* @argument $title string Topic title
* @argument $desc string Topic description
* @argument $content string Post content * @argument $icon string Topic icon (added at end for compatibility)
*/
function edit_topic($pid, $tid, $title, $desc, $content, $icon='')
{ // fix backslash $content = $this->api_core->db->escape_string($content);
$p = $this->api_core->db->fetch_result("SELECT pedits FROM icebb_posts WHERE pid='{$pid}'");
$pedits = unserialize($p['pedits']);
$edit_append = time();
$pedits["edit_{$edit_append}"]= array('ptext'=>$content,'pauthor_id'=>$this->api_core->icebb->user['id'],'pdate'=>time());
$pedits = $this->api_core->db->escape_string(serialize($pedits));
//if($this->api_core->icebb->user['g_is_mod']) if(true)
{
$title = trim($title); $desc = trim($desc);
if(empty($title))
{
$this->calling_class->show_post_form(array($this->lang['no_topic_title_entered']));
exit();
} if(!empty($icon)) { $i = ", icon='{$icon}'"; }
$this->api_core->db->query("UPDATE icebb_topics SET title='{$title}',description='{$desc}'{$i} WHERE tid='{$tid}'");
}
if($this->api_core->icebb->input['hide_edit_line'] == 1)
{
$show_edit = 0;
}
else
{
$show_edit = 1;
}
$this->api_core->db->query("UPDATE icebb_posts SET ptext='{$content}',pedit_show='{$show_edit}',pedit_author='{$this->api_core->icebb->user['username']}',pedit_time='".time()."',pedits='{$pedits}' WHERE pid='{$pid}'");
}
/**
* Add a reply to a topic
*
* @argument $tid int Topic ID
* @argument $author_id int Author ID
* @argument $content string Post content
*/
function new_reply($tid,$author_id,$content)
{
global $icebb,$db;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -