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 .= "
    \n"; while ($data = mysqli_fetch_array($result)) { $cms_content .= "
  1. " . $data['name'] . "
    "; $content = substr(strip_tags($data['content']), 0, 200); if (strlen($content) > 199) { $content .= "..."; } $cms_content .= $content; $cms_content .= "
  2. \n"; } $cms_content .= "
\n"; } else { $cms_content = $cms_no_results; } } else { $cms_content = $cms_no_results; } } else { if (!empty($id)) { if (is_numeric($id)) { $sql = "SELECT * FROM " . $mysql_table . "PAGES WHERE id = '$id' AND visible = 1"; } else { $sql = "SELECT * FROM " . $mysql_table . "PAGES WHERE seo_friendly_url = '$id' AND visible = 1"; } } else { $sql = "SELECT * FROM " . $mysql_table . "PAGES WHERE home = 1"; } $result = mysqli_query($db, $sql); if ($result) { if ($data = mysqli_fetch_array($result)) { $cms_content = ''; $cms_page_id = $data['id']; fireEvent('onBeforeContent', $data['id']); if (!empty($data['url'])) { $cms_content .= "\n"; } else { $cms_content .= preg_replace('/]*>/', '', $data['content']); } $cms_name = $data['name']; $cms_views = $data['views']; $cms_created_by = $data['created_by']; $cms_create_date = $data['create_date']; $cms_last_update_date = $data['last_update_date']; $cms_extra_data = $data['extra_data']; $cms_title = $data['title']; $cms_description = $data['description']; $cms_keywords = $data['keywords']; if ($label == 'CmsLabel1') { $cms_content = "$cms_title"; } else if ($label == 'CmsLabel2') { $cms_content = "$cms_description"; } if (empty($label)) { fireEvent('onAfterContent', $data['id']); fireEvent('onOverwriteContent', $data['id']); } } if (empty($label) && !empty($cms_page_id)) { if (is_numeric($cms_page_id)) { $sql = "UPDATE " . $mysql_table . "PAGES SET views=views+1 WHERE id = '$cms_page_id'"; } else { $sql = "UPDATE " . $mysql_table . "PAGES SET views=views+1 WHERE seo_friendly_url = '$cms_page_id'"; } } else { $sql = "UPDATE " . $mysql_table . "PAGES SET views=views+1 WHERE home = 1"; } mysqli_query($db, $sql); } } mysqli_close($db); if ($ajax == 'true') { echo $cms_content; exit; } ?>