session_start();
mb_internal_encoding('UTF-8');
mb_http_output('UTF-8');
mb_language('uni');
mb_regex_encoding('UTF-8');
ob_start('mb_output_handler');
define('MAIN_SCRIPT', basename(__FILE__));
function fireEvent($event_name, $id)
{
global $events;
if (isset($events[$event_name]))
{
foreach($events[$event_name] as $fn)
{
$fn($id);
}
}
}
$mysql_server = 'localhost';
$mysql_username = 'incipsid_incips';
$mysql_password = 'Incips@99';
$mysql_database = 'incipsid_dbcms';
$mysql_table = 'CMS_';
$cms_no_results = 'No results';
$cms_content = '';
$cms_page_id = 0;
$cms_name = '';
$cms_views = '';
$cms_created_by = '';
$cms_create_date = '';
$cms_last_update_date = '';
$cms_extra_data = '';
$cms_title = '';
$cms_description = '';
$cms_keywords = '';
$events = array();
if (file_exists('./plugins/'))
{
$handle = opendir("./plugins/");
while ($name = readdir($handle))
{
if ($name != "." && $name != ".." && is_dir("./plugins/".$name) && substr($name, 0, 1) != '_')
{
require_once('./plugins/'.$name.'/plugin.php');
if (isset($plugin['events']))
{
foreach($plugin['events'] as $name=>$fn)
{
if (!isset($events[$name]))
$events[$name] = array();
$events[$name][] = $fn;
}
}
}
}
closedir($handle);
}
$db = mysqli_connect($mysql_server, $mysql_username, $mysql_password);
if (!$db)
{
die('Failed to connect to database server!
'.mysqli_error($db));
}
mysqli_select_db($db, $mysql_database) or die('Failed to select database
'.mysqli_error($db));
mysqli_query($db, 'SET NAMES "UTF8"');
mysqli_query($db, "SET collation_connection='utf8_general_ci'");
mysqli_query($db, "SET collation_server='utf8_general_ci'");
mysqli_query($db, "SET character_set_client='utf8'");
mysqli_query($db, "SET character_set_connection='utf8'");
mysqli_query($db, "SET character_set_results='utf8'");
mysqli_query($db, "SET character_set_server='utf8'");
mysqli_set_charset($db, 'utf8');
$ajax = isset($_REQUEST['ajax']) ? $_REQUEST['ajax'] : 'false';
$label = isset($_REQUEST['label']) ? $_REQUEST['label'] : '';
$id = isset($_REQUEST['page']) ? mysqli_real_escape_string($db, $_REQUEST['page']) : '';
$query = isset($_REQUEST['query']) ? $_REQUEST['query'] : '';
if (!empty($query))
{
$query = addslashes($query);
$words = preg_split('/\s+/', $query);
foreach ($words as $word)
{
$word = preg_replace('/\W/u', '', $word);
if (strlen($word) > 1)
{
$terms[] = $word;
}
}
if ($terms)
{
if (count($terms) > 4)
{
array_splice($terms, 4);
}
$sql = "SELECT p.id, p.name, p.content FROM " . $mysql_table . "PAGES p, " . $mysql_table . "SEARCH_WORDS w, " . $mysql_table . "SEARCH_WORDMATCH m WHERE(";
$where = "w.word LIKE '%" . array_shift($terms) . "%'";
while ($term = array_shift($terms))
{
$where .= " OR w.word LIKE '%" . $term . "%'";
}
$sql .= $where . ") AND m.word_id = w.id AND m.page_id = p.id AND p.visible = 1 GROUP BY p.id ORDER BY p.last_update_date DESC";
$result = mysqli_query($db, $sql) or die(mysqli_error($db));
if ($num_rows = mysqli_num_rows($result))
{
$cms_content .= "