Ähnliche Themen

rellek
Titel: Ähnliche Themen
Version: 1.0
Beschreibung: Name: Ähnliche Themen
Version: 1.0
Für wBB-Version: 2.2
Getestet mit: 2.2.1

Beschreibung: Mit diesem Hack werden zu jedem Thema 5 ähnliche Themen gesucht. Dazu wird
die MySQL-Bedingung LIKE verwendet, d.h. wenn die Anzeige "komisch" oder
unsauber funktioniert, dann ist MySQL schuld.
Dieser Hack ist im Gegensatz zu den meisten anderen Hacks, die ähnliches
leisten, sehr sparsam gecodet. Es für die Abfrage nur ein zusätzlicher SQL-
Query nötig, ein weiterer kommt hinzu, wenn der Permission-Cache nicht gesetzt
ist, um die Foren ausfindig zu machen, in denen gesucht wird.
Foren, zu denen man keine Berechtigung hat, werden, genauso wie passwortgeschützte
Foren, von der Suche nach ähnlichen Themen ausgeschlossen, sodass niemand etwas
sieht, was er nicht sehen darf.

Demo: http://board.rellek.org/attachment.php?attachmentid=536
Copyright: (c) 2005 by rellek
Disclaimer: Keine Haftung für irgendwelche Schäden am Board. Fehler sind natürlich nicht ausgeschlossen

---

Bekannte Fehler: -
Updates und Bugfixes: -
----
Demo: http://board.rellek.org/attachment.php?attachmentid=536

weiter zum Download
Hermann
ich habe glaube ich kitt auf den augen
kann leider keine 5 themen sehen
BurN
Hi rellek, mir geht es so wie Hermann, aber nur wenn ich in der Überschrift mehr als 1 Wort nutze. Wenn ich ein einziges Wort nutze, dann funzt es ohne probleme
rellek
siehe oben: haut mysql, nicht mich.

vielleicht mach ich später noch nen switch rein, der nach allen wörtern aus dem topic sucht, die nicht auf der suchwort-blacklist stehen, das weiß ich aber noch nicht.
El Jay
Kann man diesen Hack auch im UCP deaktivieren? weil ich genug User kenne, die sowas nicht mögen oo"
rellek
nein, derzeit nicht.....
El Jay
ist eine solche Erweiterung denn noch für eine spätere Version geplant?
Also wenn sowas reinkommt und denn vllt noch das, was du in dem anderen Post angesprochen hast, würde ich es mir gerne installieren.
rellek
Ist jetz für die nächste version u.a. vorgemerkt, aber frag nicht, wann die kommt.
rellek
Wer am Beta-Test der neuen Version teilnehmen möchte, der ersetzt bitte den längeren Abschnitt zwischen den beiden
code:
1:
/* Ähnliche Themen */

und
code:
1:
/* Ähnliche Themen Ende */


mit:
code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
/* Ähnlich Themen */
function GetAccessableForums() {
	global $db, $n, $wbbuserdata, $boardcache;
	
	if (!isset($boardcache) || !is_array($boardcache)) $boardcache = array();
	$result = $db->query("SELECT boardid,boardorder,parentid,parentlist FROM bb".$n."_boards ORDER BY parentid ASC, boardorder ASC");
	while ($row = $db->fetch_array($result)) {
		$boardcache[$row['parentid']][$row['boardorder']][$row['boardid']] = $row;
	}

	$boardpermissions = getPermissions();
	$boardids = '';
	foreach ($boardcache as $key => $val) {
		foreach ($val as $key2 => $val2) {
			foreach ($val2 as $row) if ((!isset($boardpermissions[$row['boardid']]['can_view_board']) || $boardpermissions[$row['boardid']]['can_view_board'] != 0) && (!isset($boardpermissions[$row['boardid']]['can_enter_board']) || $boardpermissions[$row['boardid']]['can_enter_board'] != 0) && (!isset($boardpermissions[$row['boardid']]['can_read_thread']) || $boardpermissions[$row['boardid']]['can_read_thread'] != 0)) $boardids .= ",".$row['boardid'];
		}	
	}
	return $boardids;
}

/* Unset Used Vars To Avoid Hacking Attempts */
unset($similar_thread_bit);
unset($like_string);

$ttopic = str_replace("."," ",$threadtopic);
$ttopic = str_replace("!"," ",$ttopic);
$ttopic = str_replace("?"," ",$ttopic);
$ttopic = str_replace("/"," ",$ttopic);
$ttopic = str_replace("§"," ",$ttopic);
$ttopic = str_replace("$"," ",$ttopic);
$ttopic = str_replace("%"," ",$ttopic);
$ttopic = str_replace("&"," ",$ttopic);
$ttopic = str_replace("("," ",$ttopic);
$ttopic = str_replace(")"," ",$ttopic);
$ttopic = str_replace("="," ",$ttopic);
$ttopic = str_replace("\\"," ",$ttopic);
$ttopic = str_replace("?"," ",$ttopic);
$ttopic = str_replace("-"," ",$ttopic);
$ttopic = str_replace("*"," ",$ttopic);
$ttopic = str_replace("+"," ",$ttopic);
$ttopic = str_replace("#"," ",$ttopic);
$ttopic = str_replace("_"," ",$ttopic);
$ttopic = str_replace(","," ",$ttopic);
$ttopic = str_replace(":"," ",$ttopic);
$ttopic = str_replace(";"," ",$ttopic);
$ttopic = str_replace("<"," ",$ttopic);
$ttopic = str_replace(">"," ",$ttopic);
$ttopic = str_replace("|"," ",$ttopic);
$ttopic = str_replace("~"," ",$ttopic);
$ttopic = str_replace("'"," ",$ttopic);
$ttopic = str_replace('"',' ',$ttopic);
$ttopic = explode(" ",$ttopic);
$badwordlist = explode("\n",$badsearchwords);
$y = count($ttopic);
if($y>1) {
  foreach($ttopic as $tt) {
  	if(!in_array($tt, $badwordlist)) {
  		if(strlen($tt)>=$minwordlength && strlen($tt)<=$maxwordlength) $x++;
  		if($x>1 && (strlen($tt)>=$minwordlength && strlen($tt)<=$maxwordlength)) $like_string .= " OR t.topic LIKE ";
  		if(strlen($tt)>=$minwordlength && strlen($tt)<=$maxwordlength) $like_string .= "'%".$tt."%'";
  }
}
} else $like_string = "'%$threadtopic%'";
if($like_string) {
	$similar = $db->query("SELECT
                      t.threadid, t.boardid, x.title, x.boardid, t.prefix, t.topic, t.starttime, t.starterid, t.starter, t.lastposttime, t.lastposterid, t.lastposter, t.replycount, t.views, t.attachments, t.closed, t.important, t.pollid
                      FROM bb".$n."_threads t, bb".$n."_boards x
                      LEFT JOIN bb".$n."_boards b ON (t.boardid=b.boardid)
                      WHERE t.visible='1'
                      AND t.closed <> 3
                      AND t.threadid <> $threadid
                      AND b.password=''
                      AND t.boardid=x.boardid
                      AND t.boardid IN (0".GetAccessableForums().")
                      AND (t.topic LIKE ".$like_string.")
                      ORDER BY t.lastposttime DESC
                      LIMIT 0, 5;");
	}
if($like_string && $db->num_rows($similar)) {
	$i = "0";
	while ($row = $db->fetch_array($similar)) {
		$i++;
		$tdclass = getone($i, "tablea", "tableb");
		$started = formatdate($wbbuserdata['dateformat'], $row['starttime'],1);
		$started .= " <span class=\"time\">".formatdate($wbbuserdata['timeformat'], $row['starttime'])."</span>";
		$lastreply = formatdate($wbbuserdata['dateformat'], $row['lastposttime'],1);
		$lastreply .= " <span class=\"time\">".formatdate($wbbuserdata['timeformat'], $row['lastposttime'])."</span>";
		if ($row['replycount'] >= 1000) $row['replycount'] = number_format($row['replycount'], 0, "", $lang->get("LANG_GLOBAL_THOUSANDS_SEP"));
		if ($row['views'] >= 1000) $row['views'] = number_format($row['views'], 0, "", $lang->get("LANG_GLOBAL_THOUSANDS_SEP"));
		if (strlen($row['topic']) > 60) $row['topic'] = substr($row['topic'], 0, 54).' [...]';
		$row['topic'] = htmlconverter($row['topic']);
		eval("\$similar_thread_bit .= \"".$tpl->get("thread_similarthread_bit")."\";");
	}
	eval("\$similar_thread = \"".$tpl->get("thread_similarthread")."\";");
}
/* Ähnliche Themen Ende */


Auftretende Bugs bitte melden !
BurN
habe es mal getestet und habe folgende fehlermeldung bei einigen posts erhalten, aber nicht bei allen

code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
Database error in WoltLab Burning Board (2.2.1): Invalid SQL: SELECT t.threadid, t.boardid, x.title, x.boardid, t.prefix, t.topic, t.starttime, t.starterid, t.starter, t.lastposttime, t.lastposterid, t.lastposter, t.replycount, t.views, t.attachments, t.closed, t.important, t.pollid FROM bb1_threads t, bb1_boards x LEFT JOIN bb1_boards b ON (t.boardid=b.boardid) WHERE t.visible='1' AND t.closed <> 3 AND t.threadid <> 4900 AND b.password='' AND t.boardid=x.boardid AND t.boardid IN (0,60,65,62,3,4,39,67,16,48,5,28,17,33,2,10,6,61,11,47,24,25,20,19,37,21,38,36,58,12,13,42,45,15,18,53,66,32,30,29,31,44,34,35,63,56,1,40,41,43,52,54,55,70,49,59,51,64,68,69,71) AND (t.topic LIKE OR t.topic LIKE '%downtime%') ORDER BY t.lastposttime DESC LIMIT 0, 5;
mysql error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'OR t.topic LIKE '%downtime%') ORDER
mysql error number: 1064
mysql version: 4.1.8-standard
php version: 4.3.10
Date: 06.01.2005 @ 17:36
Script: /wbb2/thread.php?postid=16375 


EDIT

das ist z.b. ein anderes thema. habe nur das wichtige reinkopiert

code:
1:
mysql error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'OR t.topic LIKE '%everyone%')
rellek
das "wichtige" wäre auch die zeile darüber gewesen.

Wie hieß denn der Topic der beiden Threads?
BurN
sorry. war die tage nicht da.....

habe es nochmal getestet und jetzt läuft es!?!? total komisch. danke für diesen guten hack
rellek
Ja, ich hab auch den Post darüber aktualisiert, weil ich kein Recht hatte, nochmal drauf zu antworten (Doppelpost..)
Bei diesem Update wurde dein Problem auch gleich mit gelöst.
JaY^JaY
Was ist wenn es keine Ähnlichen Themen gibt was passiert mit der Box dann?
CSchulle
Zitat:
Original von JaY^JaY
Was ist wenn es keine Ähnlichen Themen gibt was passiert mit der Box dann?

Sie wird einfach nicht angezeigt Augenzwinkern
BurN
Habe einen Verbesserungsvorschlag.

Ich habe User, die den ganzen Text, der eigentlich im Topic sein sollte, in die Überschrift rein knallen. Dadurch werden die Boxen immer breiter. Könnte man das nicht auf eine bestimmte Länge kürzen? Eventuell im ACP einstellbar?
rellek
Die Länge der Ähnlichen Themen ist auf 60 Zeichen reduziert...

Kannst du mittels Änderung dieser Zeile:
code:
1:
		if (strlen($row['topic']) > 60) $row['topic'] = substr($row['topic'], 0, 54).' [...]';
einstellen
BurN
Danke

Habe wieder ein Fehler entdeckt

Titel des Themas: W A R N M E L D U N G ''Seebeben"

code:
1:
2:
3:
4:
5:
6:
7:
8:
9:
SQL-DATABASE ERROR

Database error in WoltLab Burning Board (2.2.1): Invalid SQL: SELECT t.threadid, t.boardid, x.title, x.boardid, t.prefix, t.topic, t.starttime, t.starterid, t.starter, t.lastposttime, t.lastposterid, t.lastposter, t.replycount, t.views, t.attachments, t.closed, t.important, t.pollid FROM bb1_threads t, bb1_boards x LEFT JOIN bb1_boards b ON (t.boardid=b.boardid) WHERE t.visible='1' AND t.closed <> 3 AND t.threadid <> 7495 AND b.password='' AND t.boardid=x.boardid AND t.boardid IN (0,60,65,62,3,4,39,67,16,48,5,28,17,33,2,10,6,61,11,47,24,25,20,19,37,21,38,36,58,12,13,42,45,15,18,53,66,32,30,29,31,44,34,35,63,56,1,40,41,43,52,54,55,70,49,59,51,64,68,69,71) AND (t.topic LIKE '%'Seebeben%') ORDER BY t.lastposttime DESC LIMIT 0, 5;
mysql error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Seebeben%') ORDER BY t.lastposttime DESC L
mysql error number: 1064
mysql version: 4.1.8-standard
php version: 4.3.10
Date: 23.01.2005 @ 17:22
Script: /wbb2/thread.php?threadid=7495 


EDIT: Der User hat am Anfang keine Anführungszeichen genommen, sondern 2 -> ' <-(...mir fällt gerade nicht ein, wie die Dinger heissen)
am Ende hat er aber Anführungszeichen genutzt
rellek
Ich hoffe, du hast die beta von oben drin (großes Grinsen ), dann thread.php, suche:
code:
1:
$ttopic = str_replace("|"," ",$ttopic);


danach einfügen:
code:
1:
$ttopic = str_replace("'"," ",$ttopic);
BurN
Danke

Funktioniert jetzt ohne Probleme. Super smile