post.php

来自「php 开发的内容管理系统」· PHP 代码 · 共 889 行 · 第 1/3 页

PHP
889
字号
        }
        return $user_ok;
    }

    // TODO: cleaning up and merge with post hanldings in viewpost.php
    function showPost($isadmin)
    {
        global $xoopsConfig, $xoopsModule, $xoopsModuleConfig, $xoopsUser, $myts, $xoopsTpl;
        global $forumUrl, $forumImage;
        global $viewtopic_users, $viewtopic_posters, $viewtopic_forum, $forumtopic, $online, $user_karma, $viewmode, $order, $start, $total_posts, $topic_status;
        static $post_NO = 0;
        static $user_ip;

		$post_id = $this->getVar('post_id');
		$topic_id = $this->getVar('topic_id');
		$forum_id = $this->getVar('forum_id');
		
		$topic_status = $forumtopic->getVar('topic_status');

        $uid = is_object($xoopsUser)? $xoopsUser->getVar('uid'):0;
		
        $post_NO ++;
        if (strtolower($order) == "desc") $post_no = $total_posts - ($start + $post_NO) + 1;
        else $post_no = $start + $post_NO;

        if ($isadmin or $this->checkIdentity()) {
            $post_text = $this->getVar('post_text');
            $post_attachment = $this->displayAttachment();
        } elseif ($xoopsModuleConfig['enable_karma'] && $this->getVar('post_karma') > $user_karma) {
            $post_text = "<div class='karma'>" . sprintf(_MD_KARMA_REQUIREMENT, $user_karma, $this->getVar('post_karma')) . "</div>";
            $post_attachment = '';
        } elseif (
	        	$xoopsModuleConfig['allow_require_reply']
	        	&& $this->getVar('require_reply')
	        	&& (
	        		!$uid
	        		|| !in_array($uid, $viewtopic_posters)
	        	)
        	) {
            $post_text = "<div class='karma'>" . _MD_REPLY_REQUIREMENT . "</div>";
            $post_attachment = '';
        } else {
            $post_text = $this->getVar('post_text');
            $post_attachment = $this->displayAttachment();
        }
        $poster = (($this->getVar('uid') > 0) && isset($viewtopic_users[$this->getVar('uid')]))?
        	$viewtopic_users[$this->getVar('uid')]:
            array(
            	'poster_uid' => 0,
                'name' => $this->getVar('poster_name')?$this->getVar('poster_name'):$myts->HtmlSpecialChars($xoopsConfig['anonymous']),
                'link' => $this->getVar('poster_name')?$this->getVar('poster_name'):$myts->HtmlSpecialChars($xoopsConfig['anonymous'])
            );

        $posticon = $this->getVar('icon');
        if (!empty($posticon)){
            $post_image = '<a name="' . $post_id . '"><img src="' . XOOPS_URL . '/images/subject/' . $posticon . '" alt="" /></a>';
        }else{
            $post_image = '<a name="' . $post_id . '"><img src="' . XOOPS_URL . '/images/icons/posticon.gif" alt="" /></a>';
        }

        $post_title = $this->getVar('subject');

        $thread_buttons = array();
        
		if($GLOBALS["xoopsModuleConfig"]['enable_permcheck']){
	        $topic_handler = &xoops_getmodulehandler('topic', 'newbb');
	        if ($topic_handler->getPermission($forum_id, $topic_status, "edit")) {
	            $edit_ok = false;
	            if ($isadmin) {
	                $edit_ok = true;
	            } elseif ($this->checkIdentity() && $this->checkTimelimit('edit_timelimit')) {
	                $edit_ok = true;
	            }
	            if ($edit_ok) {
	                $thread_buttons['edit']['image'] = newbb_displayImage($forumImage['p_edit'], _EDIT);
	                $thread_buttons['edit']['link'] = "edit.php?forum=" . $forum_id . "&amp;topic_id=" . $topic_id . "&amp;viewmode=$viewmode&amp;order=$order";
	                $thread_buttons['edit']['name'] = _EDIT;
	            }
	        }
	
	        if ($topic_handler->getPermission($forum_id, $topic_status, "delete")) {
	            $delete_ok = false;
	            if ($isadmin) {
	                $delete_ok = true;
	            } elseif ($this->checkIdentity() && $this->checkTimelimit('delete_timelimit')) {
	                $delete_ok = true;
	            }
	
	            if ($delete_ok) {
	                $thread_buttons['delete']['image'] = newbb_displayImage($forumImage['p_delete'], _DELETE);
	                $thread_buttons['delete']['link'] = "delete.php?forum=" . $forum_id . "&amp;topic_id=" . $topic_id . "&amp;viewmode=$viewmode&amp;order=$order";
	                $thread_buttons['delete']['name'] = _DELETE;
	            }
	        }
	        if ($topic_handler->getPermission($forum_id, $topic_status, "reply")) {
	            $thread_buttons['reply']['image'] = newbb_displayImage($forumImage['p_reply'], _MD_REPLY);
	            $thread_buttons['reply']['link'] = "reply.php?forum=" . $forum_id . "&amp;topic_id=" . $topic_id . "&amp;viewmode=$viewmode&amp;order=$order&amp;start=$start";
	            $thread_buttons['reply']['name'] = _MD_REPLY;
	            /*
	            $thread_buttons['quote']['image'] = newbb_displayImage($forumImage['p_quote'], _MD_QUOTE);
	            $thread_buttons['quote']['link'] = "reply.php?forum=" . $forum_id . "&amp;topic_id=" . $topic_id . "&amp;viewmode=$viewmode&amp;order=$order&amp;start=$start&amp;quotedac=1";
	            $thread_buttons['quote']['name'] = _MD_QUOTE;
	            */
	        }
        
    	}else{
    	
			$thread_buttons['edit']['image'] = newbb_displayImage($forumImage['p_edit'], _EDIT);
			$thread_buttons['edit']['link'] = "edit.php?forum=" . $forum_id . "&amp;topic_id=" . $topic_id . "&amp;viewmode=$viewmode&amp;order=$order";
			$thread_buttons['edit']['name'] = _EDIT;
			
			$thread_buttons['delete']['image'] = newbb_displayImage($forumImage['p_delete'], _DELETE);
			$thread_buttons['delete']['link'] = "delete.php?forum=" . $forum_id . "&amp;topic_id=" . $topic_id . "&amp;viewmode=$viewmode&amp;order=$order";
			$thread_buttons['delete']['name'] = _DELETE;
			
			$thread_buttons['reply']['image'] = newbb_displayImage($forumImage['p_reply'], _MD_REPLY);
			$thread_buttons['reply']['link'] = "reply.php?forum=" . $forum_id . "&amp;topic_id=" . $topic_id . "&amp;viewmode=$viewmode&amp;order=$order&amp;start=$start";
			$thread_buttons['reply']['name'] = _MD_REPLY;
    	
		}
		
        if (!$isadmin && $xoopsModuleConfig['reportmod_enabled']) {
            $thread_buttons['report']['image'] = newbb_displayImage($forumImage['p_report'], _MD_REPORT);
            $thread_buttons['report']['link'] = "report.php?forum=" . $forum_id . "&amp;topic_id=" . $topic_id . "&amp;viewmode=$viewmode&amp;order=$order";
            $thread_buttons['report']['name'] = _MD_REPORT;
        }
                
        $thread_action = array();
        /*
        if ($isadmin) {
        	$thread_action['news']['image'] = newbb_displayImage($forumImage['news'], _MD_POSTTONEWS);
        	$thread_action['news']['link'] = "posttonews.php?topic_id=" . $topic_id;
        	$thread_action['news']['name'] = _MD_POSTTONEWS;
        }

        $thread_action['pdf']['image'] = newbb_displayImage($forumImage['pdf'], _MD_PDF);
        $thread_action['pdf']['link'] = "makepdf.php?type=post&amp;pageid=0&amp;scale=0.66";
        $thread_action['pdf']['name'] = _MD_PDF;

        $thread_action['print']['image'] = newbb_displayImage($forumImage['printer'], _MD_PRINT);
        $thread_action['print']['link'] = "print.php?form=2&amp;forum=". $forum_id."&amp;topic_id=" . $topic_id;
        $thread_action['print']['name'] = _MD_PRINT;

        if(is_object($xoopsUser) && $this->getVar('uid') > 0 && isset($viewtopic_users[$this->getVar('uid')])){
	        $thread_action['pm']['image'] = $image_url = "<img src=\"".$forumImage['pm']."\" alt=\""._MD_PM."\" align=\"middle\" />";
	        $thread_action['pm']['link'] = "posttopm.php?";
	        $thread_action['pm']['name'] = _MD_PM;
        }
        */

        $post = array(
	    			'post_id' => $post_id,
	                'post_parent_id' => $this->getVar('pid'),
	                'post_date' => newbb_formatTimestamp($this->getVar('post_time')),
	                'post_image' => $post_image,
	                'post_title' => $post_title,
	                'post_text' => $post_text,
	                'post_attachment' => $post_attachment,
	                'post_edit' => $this->displayPostEdit(),
	                'post_no' => $post_no,
	                'post_signature' => ($this->getVar('attachsig'))?@$poster["signature"]:"",
	                'poster_ip' => ($isadmin && $xoopsModuleConfig['show_ip'])?long2ip($this->getVar('poster_ip')):"",
			    	'thread_action' => $thread_action,
	                'thread_buttons' => $thread_buttons,
	                'poster' => $poster
	       	);

        unset($thread_buttons);
        unset($eachposter);
        
        return $post;
    }

}

class NewbbPostHandler extends ArtObjectHandler
{
    function NewbbPostHandler(&$db) {
        $this->ArtObjectHandler($db, 'bb_posts', 'Post', 'post_id', 'subject');
    }
    
    function &get($id)
    {
	    $id = intval($id);
	    $post = null;
        $sql = 'SELECT p.*, t.* FROM ' . $this->db->prefix('bb_posts') . ' p LEFT JOIN ' . $this->db->prefix('bb_posts_text') . ' t ON p.post_id=t.post_id WHERE p.post_id=' . $id;
        if($array = $this->db->fetchArray($this->db->query($sql))){
	        $post =& $this->create(false);
	        $post->assignVars($array);
        }

        return $post;
    }

    function &getByLimit($topic_id, $limit, $approved = 1)
    {
        $sql = 'SELECT p.*, t.*, tp.topic_status FROM ' . $this->db->prefix('bb_posts') . ' p LEFT JOIN ' . $this->db->prefix('bb_posts_text') . ' t ON p.post_id=t.post_id LEFT JOIN ' . $this->db->prefix('bb_topics') . ' tp ON tp.topic_id=p.topic_id WHERE p.topic_id=' . $topic_id . ' AND p.approved ='. $approved .' ORDER BY p.post_time DESC';
        $result = $this->db->query($sql, $limit, 0);
        $ret = array();
        while ($myrow = $this->db->fetchArray($result)) {
            $post =& $this->create(false);
            $post->assignVars($myrow);

            $ret[$myrow['post_id']] = $post;
            unset($post);
        }
        return $ret;
    }

    function getPostForPDF(&$post)
    {
	    return $post->getPostBody(true);
    }

    function getPostForPrint(&$post)
    {
	    return $post->getPostBody();
    }

    function approve(&$post, $force = false)
    {
	    if(empty($post)){
		    return false;
	    }
	    if(is_numeric($post)){
        	$post =& $this->get($post);
    	}
    	$post_id = $post->getVar("post_id");
        if(empty($force) && $post->getVar("approved")>0){
	        return true;
        }
        $post->setVar("approved", 1);
        $this->insert($post, true);
    	$topic_handler =& xoops_getmodulehandler("topic", "newbb");
    	$topic_obj =& $topic_handler->get($post->getVar("topic_id"));
    	if($topic_obj->getVar("topic_last_post_id") < $post->getVar("post_id")){
        	$topic_obj->setVar("topic_last_post_id", $post->getVar("post_id"));
    	}
        if ($post->isTopic()) {
        	$topic_obj->setVar("approved", 1);
        } else {
        	$topic_obj->setVar("topic_replies", $topic_obj->getVar("topic_replies")+1);
        }
        $topic_handler->insert($topic_obj, true);
    	$forum_handler =& xoops_getmodulehandler("forum", "newbb");
    	$forum_obj =& $forum_handler->get($post->getVar("forum_id"));
    	if($forum_obj->getVar("forum_last_post_id") < $post->getVar("post_id")){
        	$forum_obj->setVar("forum_last_post_id", $post->getVar("post_id"));
    	}
        $forum_obj->setVar("forum_posts", $forum_obj->getVar("forum_posts")+1);
        if ($post->isTopic()) {
	        $forum_obj->setVar("forum_topics", $forum_obj->getVar("forum_topics")+1);
        }
        $forum_handler->insert($forum_obj, true);
        $member_handler =& xoops_gethandler('member');
        $poster =& $member_handler->getUser($post->getVar('uid'));
        if (is_object($poster)) {
	        $poster->setVar('posts',$poster->getVar('posts') + 1);
	        $res=$member_handler->insertUser($poster, true);
            unset($poster);
        }

        return true;
    }

    function insertnewsubject($topic_id, $subject)
    {
        $sql = "UPDATE " . $this->db->prefix("bb_topics") . " SET topic_subject = " . intval($subject) . " WHERE topic_id = $topic_id";
        $result = $this->db->queryF($sql);
        if (!$result) {
            newbb_message("update topic subject error:" . $sql);
            return false;
        }
        return true;
    }

    function insert(&$post, $force = true)
    {
        global $xoopsUser, $xoopsConfig;

        $topic_handler =& xoops_getmodulehandler("topic", "newbb");
	    // Verify the topic ID
        if($topic_id = $post->getVar("topic_id")){
	        $topic_obj =& $topic_handler->get($topic_id);
	        // Invalid topic OR the topic is no approved and the post is not top post
	        if( !$topic_obj 
	        //	|| (!$post->isTopic() && $topic_obj->getVar("approved") < 1) 
	        ){
		        return false;
	        }
        }
        if(empty($topic_id)){
	        $post->setVar("topic_id", 0);
	        $post->setVar("pid", 0);
	        $post->setNew();
	        $topic_obj =& $topic_handler->create();
        }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?