• 迎丰收 晒丰收 庆丰收 2018-10-15
  • “捂脸表情”被注册成商标?申请人不认为商标侵权 2018-10-15
  • 战巡南海、绕岛巡航…空军有“飞出去”的主心骨 2018-10-14
  • 幼儿园要求家长写一万字读后感:不能这样玩家长|幼儿园|家长-教育时讯 2018-10-13
  • 中国故宫文物展在希腊举行 2018-10-13
  • 車·晓 第26期 車企官方降价真相幾何? 2018-10-12
  • 宝沃总裁杨嵩:曾和奔驰宝马同水平 已不能同日而语 2018-10-11
  • 新时代党员干部要有更大的担当和作为 2018-10-10
  • “2018-雷霆”专项行动破获百余起台湾间谍案 2018-10-09
  • 朝韩首脑今起在平壤会晤 “金文会”将聚焦三大议题 2018-10-09
  • 2018顺义啤酒节--北京频道--人民网 2018-10-08
  • 台湾遭遇的“断交潮”有无化解之道? 2018-10-08
  • 习近平会见爱沙尼亚总统卡柳莱德 2018-10-08
  • 中国空间站研制建设正有序开展 坚持和平利用 2018-10-07
  • Idlib to further divide Ankara and Moscow 2018-10-06
  • 一个模拟discuz发帖的php类

    栏目: PHP 发布于: 2013-08-24 10:07:12

    一个模拟discuz发帖的php类,discuz发帖流程请查看:http://www.rocksun.cn/discuz-data-acquisition-and-posting.html

    代码:

    <?php
    date_default_timezone_set('PRC');
    include 'db.class.php';
    
    class post
    {
    	private $host = 'localhost';
    	private $username = 'root';
    	private $password = '123456';
    	private $database_name = 'ultrax';
    	private $_db = null;
    
    	private $fid = null;
    	private $title = null;
    	private $content = null;
    	private $author = null;
    	private $author_id = null;
    	private $current_time = null;
    	private $displayorder = null; //0:正常,-2:待审核
    
    	public function __construct($fid, $title, $content, $author, $author_id, $displayorder = -2)
    	{
    		$this->_db = db::get_instance($this->host, $this->username, $this->password, $this->database_name);
    
    		$this->fid          = $fid;
    		$this->title        = $title;
    		$this->content      = $content;
    		$this->author       = $author;
    		$this->author_id    = $author_id;
    		$this->current_time = time();
    		$this->displayorder = $displayorder;
    	}
    
    	public function post_posts()
    	{
    		$tid = $this->do_pre_forum_thread();
    
    		if(!$tid)
    		{
    			return '更新表 pre_forum_thread 失败<br />';
    		}
    
    		$pid = $this->do_pre_forum_post_tableid();
    
    		if(!$this->do_pre_forum_post($pid, $tid))
    		{
    			return '更新表 pre_forum_post 失败<br />';
    		}
    
    		if(!$this->do_pre_forum_forum())
    		{
    			return '更新表 pre_forum_forum 失败<br />';
    		}
    
    		if($this->displayorder == -2)
    		{
    			if(!($this->do_pre_forum_thread_moderate($tid)))
    			{
    				return '更新表 pre_forum_thread_moderate 失败<br />';
    			}
    		}
    
    		return ($this->do_pre_common_member_count()) ? '发帖成功<br />' : '更新表 pre_pre_common_member_count 失败<br />';
    	}
    
    	private function do_pre_forum_thread()
    	{
    		$data                 = array();
    		$data['fid']          = $this->fid;
    		$data['author']       = $this->author;
    		$data['authorid']     = $this->author_id;
    		$data['subject']      = $this->title;
    		$data['dateline']     = $this->current_time;
    		$data['lastpost']     = $this->current_time;
    		$data['lastposter']   = $this->author;
    		$data['displayorder'] = $this->displayorder;
    
    		$result = $this->_db->insert($data, 'pre_forum_thread');
    
    		if($result == 1)
    		{
    			$tid = $this->get_last_id();
    		}
    
    		return $tid;
    	}
    
    	private function do_pre_forum_post_tableid()
    	{
    		$sql    = "INSERT INTO `pre_forum_post_tableid`(`pid`) VALUES(NULL)";
    		$result = $this->_db->query($sql);
    		if($result == 1)
    		{
    			$pid = $this->get_last_id();
    		}
    
    		return $pid;
    	}
    
    	private function do_pre_forum_post($pid, $tid)
    	{
    		$data             = array();
    		$data['pid']      = $pid;
    		$data['fid']      = $this->fid;
    		$data['tid']      = $tid;
    		$data['first']    = 1;
    		$data['author']   = $this->author;
    		$data['authorid'] = $this->author_id;
    		$data['subject']  = $this->title;
    		$data['dateline'] = $this->current_time;
    		$data['message']  = $this->content;
    
    		$result = $this->_db->insert($data, 'pre_forum_post');
    
    		return ($result == 1) ? true : false;
    	}
    
    	private function do_pre_forum_forum()
    	{
    		$sql = "UPDATE `pre_forum_forum` SET `threads`=threads+1,`posts`=posts+1,`todayposts`=todayposts+1 WHERE `fid`={$this->fid}";
    
    		$result = $this->_db->query($sql);
    
    		return ($result == 1) ? true : false;
    	}
    
    	private function do_pre_forum_thread_moderate($tid)
    	{
    		$data             = array();
    		$data['tid']      = $tid;
    		$data['status']   = 0;
    		$data['dateline'] = $this->current_time;
    
    		$result = $this->_db->insert($data, 'pre_forum_thread_moderate');
    
    		return ($result == 1) ? true : false;
    	}
    
    	private function do_pre_common_member_count()
    	{
    		$sql = "UPDATE `pre_common_member_count` SET `threads`=threads+1 WHERE `uid`={$this->author_id}";
    
    		$result = $this->_db->query($sql);
    
    		return ($result == 1) ? true : false;
    	}
    
    	private function get_last_id()
    	{
    		$sql    = "SELECT LAST_INSERT_ID()";
    		$result = mysql_query($sql);
    
    		while($row = mysql_fetch_assoc($result))
    		{
    
    			$id = $row['LAST_INSERT_ID()'];
    		}
    
    		return $id;
    	}
    }


    本站文章除注明转载外,均为本站原创或编译?;队魏涡问降淖?,但请务必注明出处。
    转载请注明:文章转载自 七星彩票平台
    本文标题:一个模拟discuz发帖的php类
    IT技术书籍推荐:
    PHP从入门到精通(第3版)
    PHP从入门到精通(第3版)
    明日科技 (作者)
    《PHP从入门到精通(第3版)》从初学者角度出发,通过通俗易懂的语言、丰富多彩的实例,详细介绍了使用PHP进行网络开发应该掌握的各方面技术。全书共分4篇25章,包括初识PHP、PHP环境搭建和开发工具、PHP语言基础、流程控制语句、字符串操作、正则表达式、PHP数组、PHP与Web页面交互、PHP与JavaScript交互、日期和时间、Cookie与Session、图形图像处理技术、文件系统、面向对象、PHP加密技术、MySQL数据库基础、phpMyAdmin图形化管理工具、PHP操作MySQL数据库、PDO数据库抽象层、ThinkPHP框架、Smarty模板技术、PHP与XML技术、PHP与Ajax技术、应用Smarty模板开发电子商务网站、应用ThinkPHP框架开发明日导航网等内容。书中所有知识都结合具体实例进行介绍,涉及的程序代码均附以详细的注释,可以使读者轻松领会PHP程序开发的精髓,快速提高开发技能。