欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

Discuz投票自动回复插件

程序员文章站 2022-04-26 10:23:10
...
Discuz投票自动回复插件
<?php

if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}

$sql = <<<EOF

CREATE TABLE `c_reply_poll` (
	`tid` MEDIUMINT(8) UNSIGNED NULL DEFAULT '0',
	`dateline` INT(11) NOT NULL DEFAULT '0'
)
COMMENT='投票自动生成回贴'
COLLATE='utf8_general_ci'
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('IN_DISCUZ')) {
	exit('Access Denied');
}

$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('function/forum');

if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}

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

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

class plugin_replypoll_forum extends plugin_replypoll {
	
	function post_poll_extra_output() {
		$html .= '<p class="mbn">';
		$html .= '<input type="checkbox" tabindex="1" value="1" class="pc" id="overt" name="autoreply">';
		$html .= '<label for="overt"> 投票结果自动生成回贴</label>';
		$html .= '</p>';
		return $html;
	}	
	
	function viewthread_poll_top_output() {
		if ($autoreply = getcookie($this->cookie_key) && isset($_GET['tid'])) {
			$tid = intval($_GET['tid']);
			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

Discuz投票自动回复插件

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