Find related topics while posting

From PunBB Resource Wiki

Jump to: navigation, search

This is not finished yet but its functionality is ok


Add this to header.php:

<script type="text/javascript">
	var ajax=false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	try {
	ajax = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	try {
	ajax = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (E) {
	ajax = false;
	@end @*/
	if (!ajax && typeof XMLHttpRequest!='undefined') {
	ajax = new XMLHttpRequest();
	function getMyHTML(serverPage, objID) {
		var obj = document.getElementById(objID);"GET", serverPage);
		ajax.onreadystatechange = function() {
			if (ajax.readyState == 4 && ajax.status == 200) {
				obj.innerHTML = ajax.responseText;

Replace this in post.php:

if ($fid): ?>
						<label><strong><?php echo $lang_common['Subject'] ?></strong><br /><input class="longinput" type="text" OnBlur="getMyHTML('searchrelated.php?value=' + document.getElementById('post').req_subject.value,'ajaxwrapper')" name="req_subject" value="<?php if (isset($_POST['req_subject'])) echo pun_htmlspecialchars($subject); ?>" size="80" maxlength="70" tabindex="<?php echo $cur_index++ ?>" /><br /></label>
<div id="ajaxwrapper">
<?php endif; ?>

<div id="ajaxwrapper"> will get filled with the text from test.php?value=(the value of the subject will be put here) every time the subject field loses focus.

Create searchrelated.php and put this in it:

define('PUN_ROOT', './');
require PUN_ROOT.'include/common.php';
require PUN_ROOT.'include/parser.php';
$result = $db->query('SELECT t.subject,, p.topic_id, p.message FROM '.$db->prefix.'posts AS p LEFT JOIN '.$db->prefix.'topics AS t ON INNER JOIN '.$db->prefix.'forums AS f ON LEFT JOIN '.$db->prefix.'forum_perms AS fp ON ( AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND MATCH (p.message) AGAINST (\''.$_GET['value'].'\') limit 0,5') or error('Unable to fetch topic list', __FILE__, __LINE__, $db->error());
if ($db->num_rows($result) != 0)
	while ($row = $db->fetch_assoc($result))
		echo $row['subject'] . ' - ' . parse_message($row['message'],0);
	echo "No similar topics";

Using fulltext search (sorry too lazy to work out search.php ;)) You will need to add a fulltext index to the posts.message field

Personal tools