Home >php教程 >PHP源码 >Discuz投票自动回复插件

Discuz投票自动回复插件

PHP中文网
PHP中文网Original
2016-05-25 17:08:211436browse

Discuz投票自动回复插件

<?php

if(!defined(&#39;IN_DISCUZ&#39;)) {
	exit(&#39;Access Denied&#39;);
}

$sql = <<<EOF

CREATE TABLE `c_reply_poll` (
	`tid` MEDIUMINT(8) UNSIGNED NULL DEFAULT &#39;0&#39;,
	`dateline` INT(11) NOT NULL DEFAULT &#39;0&#39;
)
COMMENT=&#39;投票自动生成回贴&#39;
COLLATE=&#39;utf8_general_ci&#39;
ENGINE=InnoDB;

EOF;

runquery($sql);

$finish = TRUE;
?>

2. [文件] uninstall.php

<?php
/**
 *      [Discuz!] (C)2001-2099 Comsenz Inc.
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: uninstall.php 25889 2011-11-24 09:52:20Z monkey $
 */

if(!defined(&#39;IN_DISCUZ&#39;)) {
	exit(&#39;Access Denied&#39;);
}

$sql = <<<EOF
DROP TABLE IF EXISTS `c_reply_poll`;
EOF;

runquery($sql);

$finish = TRUE;
?>

3. [文件] replypoll.class.php 

<?php
/**
 * 投票自动生成回贴插件
 * 
 * TODO:回贴格式可以在后台自定义
 * 在post_newthread.php文件向c_reply_poll表记录用户选择自动回复功能
 * @Author Ricky Feng
 */
require_once libfile(&#39;function/forum&#39;);

if(!defined(&#39;IN_DISCUZ&#39;)) {
	exit(&#39;Access Denied&#39;);
}

class plugin_replypoll {
	protected $cookie_key = &#39;replypoll_plugin_autoreply&#39;;
	 
	function common(){
		global $_G;
			
		if ($_GET[&#39;action&#39;] == &#39;newthread&#39; && $_GET[&#39;topicsubmit&#39;] && $_GET[&#39;autoreply&#39;]) {
			dsetcookie($this->cookie_key ,1);
		}
		
		if ($_GET[&#39;action&#39;] == &#39;votepoll&#39; && $_GET[&#39;pollsubmit&#39;] && isset($_GET[&#39;fid&#39;]) && $_GET[&#39;tid&#39;]) {

			$_GET[&#39;fid&#39;] = intval($_GET[&#39;fid&#39;]);
			$_GET[&#39;tid&#39;] = intval($_GET[&#39;tid&#39;]);
			
			if (! $result = DB::result_first("SELECT COUNT(*) FROM c_reply_poll WHERE tid = " .$_GET[&#39;tid&#39;]) ) {
				return;
			}
			
			$arr = C::t(&#39;forum_polloption&#39;)->fetch_all_by_tid($_GET[&#39;tid&#39;]);
			$polloption = array();
			foreach($arr as $k=>$v) {
				$polloption[$v[&#39;polloptionid&#39;]]  = $v;
			}
			
			$message = &#39;我选择了{ &#39;;
			foreach ($_POST[&#39;pollanswers&#39;] as $key => $val) {
				$message .= $polloption[$val][&#39;polloption&#39;] . &#39;,&#39;;
			}
			$message = trim($message,",") . &#39; }&#39;;
			
			$data = array(
					&#39;fid&#39; => $_GET[&#39;fid&#39;],
					&#39;tid&#39; => $_GET[&#39;tid&#39;],
					&#39;first&#39; => &#39;0&#39;,
					&#39;author&#39; => $_G[&#39;username&#39;],
					&#39;authorid&#39; => $_G[&#39;uid&#39;],
					&#39;dateline&#39; => time(),
					&#39;message&#39; => $message,
					&#39;invisible&#39; => 0,
					&#39;anonymous&#39; => 0,
					&#39;usesig&#39; => 0,
					&#39;htmlon&#39; => 0,
					&#39;bbcodeoff&#39; => &#39;-1&#39;,
					&#39;smileyoff&#39; => 0,
					&#39;parseurloff&#39; => 0,
					&#39;attachment&#39; => &#39;0&#39;,
					&#39;replycredit&#39; => 0,
					&#39;status&#39; => 0,
					&#39;postid&#39; => 0
			);
			insertpost($data);
			C::t(&#39;forum_forum&#39;)->update_forum_counter($_GET[&#39;fid&#39;], 0, 1, 0);		
		}
	}
}

class plugin_replypoll_forum extends plugin_replypoll {
	
	function post_poll_extra_output() {
		$html .= &#39;<p class="mbn">&#39;;
		$html .= &#39;<input type="checkbox" tabindex="1" value="1" class="pc" id="overt" name="autoreply">&#39;;
		$html .= &#39;<label for="overt"> 投票结果自动生成回贴</label>&#39;;
		$html .= &#39;</p>&#39;;
		return $html;
	}	
	
	function viewthread_poll_top_output() {
		if ($autoreply = getcookie($this->cookie_key) && isset($_GET[&#39;tid&#39;])) {
			$tid = intval($_GET[&#39;tid&#39;]);
			DB::query("INSERT INTO c_reply_poll VALUE($tid, UNIX_TIMESTAMP())");
		}
		dsetcookie($this->cookie_key , null, -1);				
	}
}
?>

4. [文件] discuz_plugin_replypoll.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
	<item id="Title"><![CDATA[Discuz! Plugin]]></item>
	<item id="Version"><![CDATA[X2.5]]></item>
	<item id="Time"><![CDATA[2013-01-21 10:04]]></item>
	<item id="From"><![CDATA[39(http://xxx.net/)]]></item>
	<item id="Data">
		<item id="plugin">
			<item id="available"><![CDATA[1]]></item>
			<item id="adminid"><![CDATA[0]]></item>
			<item id="name"><![CDATA[replypoll]]></item>
			<item id="identifier"><![CDATA[replypoll]]></item>
			<item id="description"><![CDATA[]]></item>
			<item id="datatables"><![CDATA[]]></item>
			<item id="directory"><![CDATA[replypoll/]]></item>
			<item id="copyright"><![CDATA[xx]]></item>
			<item id="version"><![CDATA[ver 1.0]]></item>
			<item id="__modules">
				<item id="0">
					<item id="name"><![CDATA[replypoll]]></item>
					<item id="menu"><![CDATA[]]></item>
					<item id="url"><![CDATA[]]></item>
					<item id="type"><![CDATA[11]]></item>
					<item id="adminid"><![CDATA[0]]></item>
					<item id="displayorder"><![CDATA[0]]></item>
					<item id="navtitle"><![CDATA[]]></item>
					<item id="navicon"><![CDATA[]]></item>
					<item id="navsubname"><![CDATA[]]></item>
					<item id="navsuburl"><![CDATA[]]></item>
				</item>
			</item>
		</item>
		<item id="version"><![CDATA[X2.5]]></item>
		<item id="installfile"><![CDATA[install.php]]></item>
		<item id="uninstallfile"><![CDATA[uninstall.php]]></item>					
	</item>
</root>

5. [图片] QQ拼音截图未命名.jpg

1209.jpg

以上就是Discuz投票自动回复插件的内容,更多相关内容请关注PHP中文网(www.php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn