forked from MightyGorgon/icy_phoenix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstopwords.php
103 lines (85 loc) · 2.81 KB
/
stopwords.php
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
97
98
99
100
101
102
103
<?php
/**
*
* @package Icy Phoenix
* @version $Id$
* @copyright (c) 2008 Icy Phoenix
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
/*
* This script is meant to remove from search tables all stopwords and smileys
* to reduce table size but also to allow better tags indexing
*/
define('IN_ICYPHOENIX', true);
if (!defined('IP_ROOT_PATH')) define('IP_ROOT_PATH', './');
if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
include(IP_ROOT_PATH . 'common.' . PHP_EXT);
include(IP_ROOT_PATH . 'includes/functions_search.' . PHP_EXT);
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
// End session management
if(!$user->data['session_logged_in'])
{
redirect(append_sid(CMS_PAGE_LOGIN . '?redirect=stopwords.' . PHP_EXT, true));
/*
$header_location = (@preg_match('/Microsoft|WebSTAR|Xitami/', getenv('SERVER_SOFTWARE'))) ? 'Refresh: 0; URL=' : 'Location: ';
header($header_location . append_sid(CMS_PAGE_LOGIN . "?redirect=stopwords." . PHP_EXT, true));
exit;
*/
}
if($user->data['user_level'] != ADMIN)
{
message_die(GENERAL_ERROR, $lang['Not_Authorized']);
}
stopwords_synonyms_init();
$exclude_list = '';
foreach($stopwords_array as $curr_word)
{
$exclude_list .= (($exclude_list != '') ? ', ' : '') . "'" . trim($curr_word) . "'";
}
// Smileys
$sql = "SELECT code FROM " . SMILIES_TABLE;
$db->sql_return_on_error(true);
$result = $db->sql_query($sql, 0, 'smileys_');
$db->sql_return_on_error(false);
if ($result !== false)
{
while ($row = $db->sql_fetchrow($result))
{
$exclude_list .= (($exclude_list != '') ? ', ' : '') . "'" . trim(preg_replace('/[^A-Za-z0-9]+/', '', $row['code'])) . "'";
}
$db->sql_freeresult($result);
}
$sql = "SELECT word_id
FROM " . SEARCH_WORD_TABLE . "
WHERE word_text IN (" . $exclude_list . ")";
$db->sql_query($sql);
$common_word_id = '';
while ($row = $db->sql_fetchrow($result))
{
$common_word_id .= (($common_word_id != '') ? ', ' : '') . $row['word_id'];
}
if ($common_word_id == '')
{
message_die(GENERAL_ERROR,'None of the words in the list are in your search_tables.<br />Note: This could also mean the list is empty ;-)');
}
//echo '>'.trim($curr_word)."<<br />";
//echo $exclude_list .'<br />'. $common_word_id;
//exit;
$sql = "DELETE FROM " . SEARCH_WORD_TABLE . "
WHERE word_id IN ($common_word_id)";
$db->sql_query($sql);
$sql = "OPTIMIZE TABLE " . SEARCH_WORD_TABLE;
$db->sql_query($sql);
$sql = "DELETE FROM " . SEARCH_MATCH_TABLE . "
WHERE word_id IN ($common_word_id)";
$db->sql_query($sql);
$sql = "OPTIMIZE TABLE " . SEARCH_MATCH_TABLE;
$db->sql_query($sql);
$db->clear_cache();
message_die(GENERAL_MESSAGE,'<b>Done!</b><br /><br />The following list-entries have been removed from your searchtables:<br /><br />' . $exclude_list);
//echo $exclude_list .'<br />'. $common_word_id;
?>