<?php
$includes = array('./include', 'include', '../include');
if( !in_array($include_dir, $includes) ) {
die("Illegal include.");
}
$common_dir = "$include_dir/common/"; //subfolder of .../include/ where all the common files are stored
// Returns the result of an SQL query as an array
function sql_fetch_all($query) {
global $debug;
$data = array();
$result = mysql_query($query);
if($mysql_err = mysql_errno()) {
if ($debug > '0') {
print $query.'<br>'.mysql_error();
}
} else {
while($row=mysql_fetch_array($result)) {
$data[]=$row;
}
}
return $data;
}
// Removes duplicate elements from an array
function distinct_array($arr) {
rsort($arr);
reset($arr);
$newarr = array();
$i = 0;
$element = current($arr);
for ($n = 0; $n < sizeof($arr); $n++) {
if (next($arr) != $element) {
$newarr[$i] = $element;
$element = current($arr);
$i++;
}
}
return $newarr;
}
function get_cats($parent) {
global $mysql_table_prefix, $debug;
$query = "SELECT * FROM ".$mysql_table_prefix."categories WHERE parent_num=$parent";
$result = mysql_query($query);
if ($debug > '0') echo mysql_error();
$arr[] = $parent;
if (mysql_num_rows($result) <> '') {
while ($row = mysql_fetch_array($result)) {
$id = $row['category_id'];
$arr = add_arrays($arr, get_cats($id));
}
}
return $arr;
}
function add_arrays($arr1, $arr2) {
foreach ($arr2 as $elem) {
$arr1[] = $elem;
}
return $arr1;
}
function parse_all_url($url){ // this will parse also IDN coded URLs, independent from local server configuration
$url_parts = array();
preg_match("@^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?@", $url, $regs);
if ($regs[2]) $url_parts['scheme'] = $regs[2];
if ($regs[4]) $url_parts['host'] = $regs[4];
if ($regs[5]) $url_parts['path'] = $regs[5];
if ($regs[7]) $url_parts['query'] = $regs[7];
if ($regs[9]) $url_parts['fragment'] = $regs[9];
return $url_parts;
}
class Segmentation {
var $options = array('lowercase' => TRUE);
var $dict_name = 'Unknown';
var $dict_words = array();
function setLowercase($value) {
if ($value) {
$this->options['lowercase'] = TRUE;
} else {
$this->options['lowercase'] = FALSE;
}
return TRUE;
}
function load($dict_file) {
if (!file_exists($dict_file)) {
return FALSE;
}
$fp = fopen($dict_file, 'r');
$temp = fgets($fp, 1024);
if ($temp === FALSE) {
return FALSE;
} else {
if (strpos($temp, "\t") !== FALSE) {
list ($dict_type, $dict_name) = explode("\t", trim($temp));
} else {
$dict_type = trim($temp);
$dict_name = 'Unknown';
}
$this->dict_name = $dict_name;
if ($dict_type !== 'DICT_WORD_W') {
return FALSE;
}
}
while (!feof($fp)) {
$this->dict_words[rtrim(fgets($fp, 32))] = 1;
}
fclose($fp);
return TRUE;
}
function getDictName() {
return $this->dict_name;
}
function segmentString($str) {
if (count($this->dict_words) === 0) {
return FALSE;
}
$lines = explode("\n", $str);
return $this->_segmentLines($lines);
}
function segmentFile($filename) {
if (count($this->dict_words) === 0) {
return FALSE;
}
$lines = file($filename);
return $this->_segmentLines($lines);
}
function _segmentLines($lines) {
$contents_segmented = '';
foreach ($lines as $line) {
$contents_segmented .= $this->_segmentLine(rtrim($line)) . " \n";
}
do {
$contents_segmented = str_replace(' ', ' ', $contents_segmented);
} while (strpos($contents_segmented, ' ') !== FALSE);
return $contents_segmented;
}
function _segmentLine($str) {
$str_final = '';
$str_array = array();
$str_length = strlen($str);
if ($str_length > 0) {
if (ord($str{$str_length-1}) >= 129) {
$str .= ' ';
}
}
for ($i=0; $i<$str_length; $i++) {
if (ord($str{$i}) >= 129) {
$str_array[] = $str{$i} . $str{$i+1};
$i++;
} else {
$str_tmp = $str{$i};
for ($j=$i+1; $j<$str_length; $j++) {
if (ord($str{$j}) < 129) {
$str_tmp .= $str{$j};
} else {
break;
}
}
$str_array[] = array($str_tmp);
$i = $j - 1;
}
}
$pos = count($str_array);
while ($pos > 0) {
$char = $str_array[$pos-1];
if (is_array($char)) {
$str_final_tmp = $char[0];
if ($this->options['lowercase']) {
$str_final_tmp = strtolower($str_final_tmp);
}
$str_final = " $str_final_tmp$str_final";
$pos--;
} else {
$word_found = 0;
$word_array = array(0 => '');
if ($pos < 4) {
$word_temp = $pos + 1;
} else {
$word_temp = 5;
}
for ($i=1; $i<$word_temp; $i++) {
$word_array[$i] = $str_array[$pos-$i] . $word_array[$i-1];
}
for ($i=($word_temp-1); $i>1; $i--) {
if (array_key_exists($word_array[$i], $this->dict_words)) {
$word_found = $i;
break;
}
}
if ($word_found) {
$str_final = " $word_array[$word_found]$str_final";
$pos = $pos - $word_found;
} else {
$str_final = " $char$str_final";
$pos--;
}
}
}
return $str_final;
}
}
$entities = array(
"&" => "&",
"&apos" => "'",
"Þ" => "Þ",
"ß" => "ß",
"à" => "ÃÂ ",
"á" => "á",
"â" => "â",
"ã" => "ã",
"ä" => "ä",
"å" => "ÃÂ¥",
"æ" => "æ",
"ç" => "ç",
"è" => "è",
"é" => "é",
"ê" => "ê",
"ë" => "ë",
"ì" => "ì",
"í" => "ÃÂ",
"î" => "î",
"ï" => "ï",
"ð" => "ð",
"ñ" => "ñ",
"ò" => "ò",
"ó" => "ó",
"ô" => "ô",
"õ" => "õ",
"ö" => "ö",
"ø" => "ø",
"ù" => "ù",
"ú" => "ú",
"û" => "û",
"ü" => "ü",
"ý" => "ý",
"þ" => "þ",
"ÿ" => "ÿ",
"Þ" => "Þ",
"ß" => "ß",
"À" => "ÃÂ ",
"Á" => "á",
"Â" => "â",
"Ã" => "ã",
"Ä" => "ä",
"Å" => "ÃÂ¥",
"&Aelig;" => "æ",
"Ç" => "ç",
"È" => "è",
"É" => "é",
"Ê" => "ê",
"Ë" => "ë",
"Ì" => "ì",
"Í" => "ÃÂ",
"Î" => "î",
"Ï" => "ï",
"Ð" => "ð",
"Ñ" => "ñ",
"Ò" => "ò",
"Ó" => "ó",
"Ô" => "ô",
"Õ" => "õ",
"Ö" => "ö",
"Ø" => "ø",
"Ù" => "ù",
"Ú" => "ú",
"Û" => "û",
"Ü" => "ü",
"Ý" => "ý",
"&Yhorn;" => "þ",
"Ÿ" => "ÿ"
);
//Apache multi indexes parameters
$apache_indexes = array (
"N=A" => 1,
"N=D" => 1,
"M=A" => 1,
"M=D" => 1,
"S=A" => 1,
"S=D" => 1,
"D=A" => 1,
"D=D" => 1,
"C=N;O=A" => 1,
"C=M;O=A" => 1,
"C=S;O=A" => 1,
"C=D;O=A" => 1,
"C=N;O=D" => 1,
"C=M;O=D" => 1,
"C=S;O=D" => 1,
"C=D;O=D" => 1
);
function remove_accents($string) {
return (strtr($string, "Ãâ¬Ã?ÃâÃÆÃâÃâ¦Ãâ àáâãäÃ¥æÃâÃâÃâÃâ¢Ãâ¢ÃâÃËòóôõöøÃËÃâ°ÃÅ Ãâ¹Ã¨Ã©ÃªÃ«Ã°Ãâ¡Ã§Ã?ÃÅÃ?ÃŽÃ?ìÃÂîïÃâ¢ÃÅ¡ÃâºÃÅùúûüÃâñÞßÿý",
"aaaaaaaaaaaaaaoooooooooooooeeeeeeeeecceiiiiiiiiuuuuuuuunntsyy"));
}
// convert ISO-8859-x entities into their lower case equivalents
function lower_ent($string) {
$ent = array
(
"Ä" => "Ä",
"Ä" => "Ä",
"Ä" => "Ä",
"Ľ" => "ľ",
"Å" => "Å",
"Å" => "Å",
"Å " => "Å¡",
"Ť" => "ť",
"Ž" => "ž",
"Ã" => "ä",
"Ã" => "ö",
"Ã" => "ü",
"Ä" => "ä",
"Ä" => "ä",
"Ö" => "ö",
"Ö" => "ö",
"Ü" => "ü",
"Ü" => "ü",
"Ã" => "Ã ",
"Ã" => "è",
"Ã" => "ì",
"Ã" => "ò",
"Ã" => "ù",
"Ã" => "é",
"Ã" => "Ã",
"Ã" => "ó",
"Ã" => "ú",
"Ã" => "ã",
"Ã" => "ñ",
"Ã" => "õ",
"Ũ" => "ũ",
"Ã" => "â",
"Ã" => "ê",
"Ã" => "î",
"Ã" => "ô",
"Ã" => "û",
"Ã
" => "Ã¥",
"Ů" => "ů",
"Ã" => "æ",
"Ã" => "ç",
"Ã" => "ø",
"Ã" => "ë",
"Ã" => "ï",
"Ä" => "Ä",
//"İ" => "ı",
"İ" => "i",
"Å" => "Å",
"Ħ" => "ħ",
"Ĥ" => "ĥ",
"Ĵ" => "ĵ",
"Ż" => "ż",
"Ä" => "Ä",
"Ä" => "Ä",
"Ŭ" => "Å",
"Å" => "Å",
"Ä" => "Ä",
"Å" => "Å",
"Ĺ" => "ĺ",
"Ä" => "Ä",
"Ű" => "ű",
"Å¢" => "Å£",
"Å" => "Å",
"Ä" => "Ä",
"Å" => "Å",
"Ã" => "á",
"Å" => "Å",
"Ź" => "ź",
"Å" => "Å",
"Ë" => "Ë",
"ĸ" => "Ë",
"Å" => "Å",
"Į" => "į",
"Ä" => "Ä",
"Ä" => "Ä",
"Ã" => "ð",
"Å
" => "Å",
"Å" => "Å",
"Ų" => "ų",
"Ã" => "ý",
"Ã" => "þ",
"Ä" => "Ä
",
"Ä" => "Ä",
"Ä¢" => "Ä£",
"Ī" => "ī",
"Ĩ" => "ĩ",
"Ķ" => "ķ",
"Ļ" => "ļ",
"Ŧ" => "ŧ",
"Ū" => "ū",
"Å" => "Å",
"Ä" => "Ä",
"á¸" => "á¸",
"á¸" => "á¸",
"áº" => "áº",
"áº" => "áº",
"Ṡ" => "ṡ",
"á¸" => "á¸",
"á¹" => "á¹",
"á¹" => "á¹",
"áº" => "áº
",
"Ŵ" => "ŵ",
"Ṫ" => "ṫ",
"Ŷ" => "ŷ"
);
reset($ent);
while ($char = each($ent)) {
$string = preg_replace("/".$char[0]."/i", $char[1], $string);
}
return ($string);
}
// convert characters into lower case
function lower_case($string) {
global $charSet, $home_charset, $greek, $cyrillic;
if ($charSet =='') {
$charSet = $home_charset;
}
$charSet = strtoupper($charSet);
// if required, convert Greek charset into lower case
if ($greek == '1') {
$lower = array
(
"Î" => "α",
"Î" => "β",
"Î" => "γ",
"Î" => "δ",
"Î" => "ε",
"Î" => "ζ",
"Î" => "η",
"Î" => "θ",
"Î" => "ι",
"Î" => "κ",
"Î" => "λ",
"Î" => "μ",
"Î" => "ν",
"Î" => "ξ",
"Î" => "ο",
"Î " => "Ï",
"Ρ" => "Ï",
"Σ" => "Ï",
"Τ" => "Ï",
"Î¥" => "Ï
",
"Φ" => "Ï",
"Χ" => "Ï",
"Ψ" => "Ï",
"Ω" => "Ï"
);
reset($lower);
while ($char = each($lower)) {
$string = preg_replace("/".$char[0]."/i", $char[1], $string);
}
}
// if required, convert Cyrillic charset into lower case
if ($cyrillic == '1') {
$lower = array
(
"Ð" => "а", // basic Cyrillian alphabet
"Ð" => "б",
"Ð" => "в",
"Ð" => "г",
"Ò" => "Ò",
"Ð" => "Ñ",
"Ð" => "д",
"Ð" => "Ñ",
"Ð" => "е",
"Ð" => "Ñ",
"Ð" => "Ñ",
"Ð" => "ж",
"Ð" => "з",
"Ð
" => "Ñ",
"Ð" => "и",
"Ð" => "Ñ",
"Ð" => "Ñ",
"Ð" => "й",
"Ð" => "Ñ",
"Ð" => "к",
"Ð" => "Ñ",
"Ð" => "л",
"Ð" => "Ñ",
"Ð" => "м",
"Ð" => "н",
"Ð" => "Ñ",
"Ð" => "о",
"Ð" => "п",
"Ð " => "Ñ",
"С" => "Ñ",
"Т" => "Ñ",
"Ð" => "Ñ",
"У" => "Ñ",
"Ð" => "Ñ",
"Ф" => "Ñ",
"Ð¥" => "Ñ
",
"Ñ " => "Ñ¡", // ex Greek 'OMEGA'
"Ц" => "Ñ",
"Ч" => "Ñ",
"Ð" => "Ñ",
"Ш" => "Ñ",
"Щ" => "Ñ",
"Ъ" => "Ñ",
"Ы" => "Ñ",
"Ь" => "Ñ",
"Ы" => "Ñ",
"Ð" => "Ñ",
"Ю" => "Ñ",
"Я" => "Ñ",
"Ð" => "Ñ",
"Ð" => "Ñ",
"Ð" => "Ñ",
"Ð" => "Ñ",
"Ѥ" => "ѥ", // extended Cyrillic
"Ѧ" => "ѧ",
"Ѫ" => "ѫ",
"Ѩ" => "ѩ",
"Ѭ" => "Ñ",
"Ѯ" => "ѯ",
"Ѱ" => "ѱ",
"Ѳ" => "ѳ",
"Ѵ" => "ѵ",
"Ä" => "Ä",
"Ǵ" => "ǵ",
"Ã" => "ê",
"áº" => "áº",
"Ã" => "ì",
"Ã" => "ï",
"JË" => "ǰ",
"LÌ" => "lÌ",
"NÌ" => "nÌ",
"Ä" => "Ä",
"Ḱ" => "ḱ",
"Ŭ" => "Å",
"DÌ" => "dÌ",
"Å" => "Å",
"Ã" => "û",
"Ã" => "â",
"GÌ" => "g",
"Ä" => "Ä",
"GÌ" => "g",
"Ä " => "Ä¡",
"Ä" => "Ä",
"Ž̦" => "ž",
"Ķ" => "ķ",
"KÌ" => "kÌ",
"á¹" => "á¹",
"á¹" => "á¹
",
"á¹" => "á¹",
"Ã" => "ò",
"Ã" => "ç",
"Å¢" => "Å£",
"Ã" => "ù",
"U" => "u",
"Ḩ" => "ḩ",
"CÌ" => "cÌ",
"Ḥ" => "ḥ",
"CÌ" => "cÌ",
"ÃÌ" => "çÌ",
"ZÌ" => "zÌ",
"Ä" => "Ä",
"Ã" => "ä",
"Ä" => "Ä",
"ZÌ" => "zÌ",
"ZÌ" => "zÌ",
"Ź" => "ź",
"Ã" => "î",
"Ã" => "ö",
"Ã" => "ô",
"Ã" => "ü",
"Ű" => "ű",
"CÌ" => "cÌ",
"Ÿ" => "ÿ",
"Ò" => "Ò",
"Ò" => "Ò",
"Ò" => "Ò",
"Ò" => "Ò",
"Ò" => "Ò",
"Ò" => "Ò",
"Ò" => "Ò",
"Ò" => "Ò",
"Ò" => "Ò",
"Ò" => "Ò",
"Ò" => "Ò",
"Ò " => "Ò¡",
"Ò¢" => "Ò£",
"Ò¤" => "Ò¥",
"Ò¦" => "Ò§",
"Ò¨" => "Ò©",
"Òª" => "Ò«",
"Ò¬" => "Ò",
"Ò®" => "Ò¯",
"Ò°" => "Ò±",
"Ò²" => "Ò³",
"Ò´" => "Òµ",
"Ò¶" => "Ò·",
"Ò¸" => "Ò¹",
"Òº" => "Ò»",
"Ò¼" => "Ò½",
"Ò¾" => "Ò¿",
"Ó" => "Ó",
"Ó" => "Ó",
"Ó
" => "Ó",
"Ó" => "Ó",
"Ó" => "Ó",
"Ó" => "Ó",
"Ó" => "Ó",
"Ó" => "Ó",
"Ó" => "Ó",
"Ó" => "Ó",
"Ó" => "Ó",
"Ó" => "Ó",
"Ó" => "Ó",
"Ó" => "Ó",
"Ó" => "Ó",
"Ó " => "Ó¡",
"Ó¢" => "Ó£",
"Ó¤" => "Ó¥",
"Ó¦" => "Ó§",
"Ó¨" => "Ó©",
"Óª" => "Ó«",
"Ó¬" => "Ó",
"Ó®" => "Ó¯",
"Ó°" => "Ó±",
"Ó²" => "Ó³",
"Ó´" => "Óµ",
"Ó¶" => "Ó·",
"Ó¸" => "Ó¹",
"Ó¼" => "Ó½",
"Ó¾" => "Ó¿",
"Ñ " => "Ñ¡", // historical Cyrillic
"Ñ¢" => "Ñ£",
"Ѥ" => "ѥ",
"Ѧ" => "ѧ",
"Ѩ" => "ѩ",
"Ѫ" => "ѫ",
"Ѭ" => "Ñ",
"Ѯ" => "ѯ",
"Ѱ" => "ѱ",
"Ѳ" => "ѳ",
"Ѵ" => "ѵ",
"Ѷ" => "ѷ",
"Ѹ" => "ѹ",
"Ѻ" => "ѻ",
"Ѽ" => "ѽ",
"Ѿ" => "ѿ",
"Ò" => "Ò",
"Ç" => "Ç",
"FÌ" => "fÌ",
"Ỳ" => "ỳ",
"�" => "ð",
"̉" => "̱",
"Ãâ" => "ò",
"Ãâ" => "ó",
"̉" => "̫",
"Ãâ¢" => "õ",
"̉" => "̦",
"Ãâ" => "÷",
"ÃË" => "ø",
"Ãâ¢" => "ù",
"ÃÅ¡" => "ú",
"Ãâº" => "û",
"ÃÅ" => "ý",
"Þ" => "þ",
"ß" => "ÿ",
"à" => "Ãâ¬",
"á" => "�",
"̢" => "̉",
"̣" => "̮",
"ä" => "Ãâ",
"ÃÂ¥" => "Ãâ¦",
"æ" => "Ãâ ",
"ç" => "Ãâ¡",
"è" => "ÃË",
"é" => "Ãâ°",
"̻" => "́ ",
"ë" => "Ãâ¹",
"ì" => "ÃÅ",
"ÃÂ" => "Ã?",
"î" => "Î",
"ï" => "�",
"Ã?" => "Ãâ",
"Ãâ" => "Ãâ",
"ÃÆ" => "Ãâ",
"Ãâ" => "Ãâ",
"Ãâ¦" => "Ãâ¢",
"Ãâ " => "Ãâ",
"Ãâ¡" => "Ãâ",
"ÃË" => "ÃË",
"Ãâ°" => "Ãâ¢",
"ÃÅ " => "ÃÅ¡",
"Ãâ¹" => "Ãâº",
"ÃÅ" => "ÃÅ",
"Î" => "Þ",
"�" => "ß"
);
reset($lower);
while ($char = each($lower)) {
$string = preg_replace("/".$char[0]."/i", $char[1], $string);
}
}
return (strtr($string, "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
"abcdefghijklmnopqrstuvwxyz"));
}
error_reporting (E_ALL ^ E_WARNING ^ E_NOTICE);
global $use_common, $use_white1, $use_white2, $use_black, $home_charset;
$com_in = array(); // intermediate array for ignored words
$all_in = array(); // intermediate array for ignored words
$common = array(); // array fo ignored words
$ext = array(); // array for ignored file suffixes
$whitelist = array(); // array for whitelist
$white = array();
$white_in = array();
$blacklist = array(); // array for blacklist
$black_in = array();
$uas_in = array(); // intermediate array for evil User Agents
$ips_in = array(); // intermediate array for bad IPs
$black_uas = array(); // User Agent strings belonging to evil bots
$black_ips = array(); // IPs belonging to Google, MSN, Amazon, etc bots
$black = array();
$image = array(); // array for image suffixes
$audio = array(); // array for audio suffixes
$video = array(); // array for video suffixes
$divs_not = array(); // array for divs not to be indexed
$divs_use = array(); // array for divs to be indexed
$docs = array(); // array holding a list of documents to be indexed
$elements_not = array(); // array for HTML elements not to be indexed
$elements_use = array(); // array for HTML elements to be indexed
$slv = array(); // array of most common Second Level Domains
$mysql_charset = conv_mysql($home_charset); // convert the home._charset to MySQL format
if (is_dir($common_dir)) {
$handle = opendir($common_dir);
if ($use_common == 'all') {
while (false !== ($common_file = readdir($handle))) { // get all common files
if (strpos($common_file, "ommon_")) {
$act = @file($common_dir.$common_file); // get content of actual common file
$all_in = array_merge($all_in, $act); // build a complete array of common words
}
}
}
if ($use_common != 'all' && $use_common != 'none') {
$all_in = @file("".$common_dir."common_".$use_common.".txt"); // get content of language specific common file
}
if (is_array($all_in)) {
while (list($id, $word) = each($all_in))
if (preg_match("/\S/", $word)) { // remove empty entries from list
$com_in[] = $word;
}
}
if (is_array($com_in)) {
while (list($id, $word) = each($com_in))
$common[trim($word)] = 1;
}
if ($use_white1 == '1' || $use_white2 == '1') $white_in = @file($common_dir.'whitelist.txt'); // get all words to enable page indexing
$suffix = @file($common_dir.'suffix.txt'); // get all file suffixes to be ignored during index procedure
$black_in = @file($common_dir.'blacklist.txt'); // get all words to prevent indexing of page
$uas_in = @file($common_dir.'black_uas.txt'); // get all evil user-agent strings
$ips_in = @file($common_dir.'black_ips.txt'); // get all Meta search engine IPs
$image = @file($common_dir.'image.txt'); // get all image suffixes to be indexed
$audio = @file($common_dir.'audio.txt'); // get all audio suffixes to be indexed
$video = @file($common_dir.'video.txt'); // get all audio suffixes to be indexed
$divs_not = @file($common_dir.'divs_not.txt'); // get all div's to not to be indexed (Admin selected)
$divs_use = @file($common_dir.'divs_use.txt'); // get all div's to be indexed (Admin selected)
$docu = @file($common_dir.'docs.txt'); // get all document suffixes to be indexed (Admin selected)
$elements_not = @file($common_dir.'elements_not.txt'); // get all HTML elements to not to be indexed (Admin selected)
$elements_use = @file($common_dir.'elements_use.txt'); // get all HTML elements to be indexed (Admin selected)
$sld = @file($common_dir.'sld.txt'); // get all SLDs
closedir($handle);
if (is_array($suffix)) {
while (list($id, $word) = each($suffix))
if (preg_match("/\S/", $word)) { // remove empty entries from list
$ext[] = trim($word);
}
$ext = array_unique($ext);
sort($ext);
}
if (is_array($white_in)) {
foreach ($white_in as $val) {
if ($case_sensitive == '0') {
$val = lower_case($val);
}
$val = @iconv($home_charset,"UTF-8",$val);
if (preg_match("/\S/", $val)) { // remove empty entries from list
$white[] = addslashes($val);
}
}
while (list($id, $word) = each($white))
$whitelist[] = trim($word);
$whitelist = array_unique($whitelist);
sort($whitelist);
}
if (is_array($black_in)) {
foreach ($black_in as $val) {
if ($case_sensitive == '0') {
$val = lower_case($val);
}
$val = @iconv($home_charset,"UTF-8",$val);
if (preg_match("/\S/", $val)) { // remove empty entries from list
$black[] = $val;
}
}
while (list($id, $word) = each($black))
$blacklist[] = trim($word);
$blacklist = array_unique($blacklist);
sort($blacklist);
}
if (is_array($image)) {
while (list($id, $word) = each($image))
if (preg_match("/\S/", $word)) { // remove empty entries from list
$imagelist[] = trim(strtolower($word));
}
$imagelist = array_unique($imagelist);
sort($imagelist);
}
if (is_array($audio)) {
while (list($id, $word) = each($audio))
if (preg_match("/\S/", $word)) { // remove empty entries from list
$audiolist[] = trim(strtolower($word));
}
$audiolist = array_unique($audiolist);
sort($audiolist);
}
if (is_array($video)) {
while (list($id, $word) = each($video))
if (preg_match("/\S/", $word)) { // remove empty entries from list
$videolist[] = trim(strtolower($word));
}
$videolist = array_unique($videolist);
sort($videolist);
}
if (is_array($divs_not)) {
while (list($id, $word) = each($divs_not))
if (preg_match("/\S/", $word)) { // remove empty entries from list
$not_divlist[] = trim($word);
}
$not_divlist = array_unique($not_divlist);
sort($not_divlist);
}
if (is_array($divs_use)) {
while (list($id, $word) = each($divs_use))
if (preg_match("/\S/", $word)) {
$use_divlist[] = trim($word);
}
$use_divlist = array_unique($use_divlist);
sort($use_divlist);
}
if (is_array($docu)) {
while (list($id, $word) = each($docu))
if (preg_match("/\S/", $word)) { // remove empty entries from list
$docs[] = trim(strtolower($word));
}
$docs = array_unique($docs);
sort($docs);
}
if (is_array($elements_not)) {
while (list($id, $word) = each($elements_not))
if (preg_match("/\S/", $word)) { // remove empty entries from list
$not_elementslist[] = trim($word);
}
$not_elementslist = array_unique($not_elementslist);
sort($not_elementslist);
}
if (is_array($elements_use)) {
while (list($id, $word) = each($elements_use))
if (preg_match("/\S/", $word)) {
$use_elementslist[] = trim($word);
}
$use_elementslist = array_unique($use_elementslist);
sort($use_elementslist);
}
if (is_array($sld)) {
while (list($id, $word) = each($sld))
$sldlist[] = trim($word);
$sldlist = array_unique($sldlist);
sort($sldlist);
}
if (is_array($uas_in)) {
while (list($id, $word) = each($uas_in))
if (preg_match("/\S/", $word)) { // remove empty entries from list
$black_uas[] = $word;
}
}
if (is_array($ips_in)) {
while (list($id, $word) = each($ips_in))
if (preg_match("/\S/", $word)) { // remove empty entries from list
$black_ips[] = $word;
}
}
}
function is_num($var) {
for ($i=0;$i<strlen($var);$i++) {
$ascii_code=ord($var[$i]);
if ($ascii_code >=49 && $ascii_code <=57){
continue;
} else {
return false;
}
}
return true;
}
function getHttpVars() {
$superglobs = array(
'_POST',
'_GET',
'HTTP_POST_VARS',
'HTTP_GET_VARS');
$httpvars = array();
// extract the right array
foreach ($superglobs as $glob) {
global $$glob;
if (isset($$glob) && is_array($$glob)) {
$httpvars = $$glob;
}
if (count($httpvars) > 0)
break;
}
//echo "<br>http Array:<br><pre>";print_r($httpvars);echo "</pre>";
return $httpvars;
}
function countSubstrs($haystack, $needle) {
$count = 0;
while(strpos($haystack,$needle) !== false) {
$haystack = substr($haystack, (strpos($haystack,$needle) + 1));
$count++;
}
return $count;
}
function quote_replace($str) {
$str = str_replace("\"", """, $str);
return str_replace("'","'", $str);
}
function fst_lt_snd($version1, $version2) {
$list1 = explode(".", $version1);
$list2 = explode(".", $version2);
$length = count($list1);
$i = 0;
while ($i < $length) {
if ($list1[$i] < $list2[$i])
return true;
if ($list1[$i] > $list2[$i])
return false;
$i++;
}
if ($length < count($list2)) {
return true;
}
return false;
}
function get_dir_contents($dir) {
$contents = Array();
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$contents[] = $file;
}
}
closedir($handle);
}
return $contents;
}
function replace_ampersand($str) {
return str_replace("&", "%26", $str);
}
function list_cats($parent, $lev, $color, $message) {
global $mysql_table_prefix, $debug, $dba_act;
if ($lev == 0) {
echo "<div class='submenu cntr y3'>| Database $dba_act Table prefix '$mysql_table_prefix' |<br />
<ul>
<li><a href='admin.php?f=add_cat'>Add category</a></li>
</ul>
</div>
";
echo $message;
echo "<div class='panel'>
<table width='100%'>
<tr>
<td class='tblhead' colspan='3'>Categories</td>
</tr>
";
}
$space = "";
for ($x = 0; $x < $lev; $x++) {
$space .= "<span class='tree'>»</span> ";
}
$query = "SELECT * FROM ".$mysql_table_prefix."categories WHERE parent_num=$parent ORDER BY category";
$result = mysql_query($query);
if ($debug > '0') echo mysql_error();
if (mysql_num_rows($result) <> '') {
while ($row = mysql_fetch_array($result)) {
if ($color =="odrow") {
$color = "evrow";
} else {
$color = "odrow";
}
$id = $row['category_id'];
$cat = $row['category'];
echo "<tr class='$color'>
";
if (!$space=="") {
echo "<td width='90%'>
<div>$space<a class='options' href='admin.php?f=edit_cat&cat_id=$id'
title='Edit this Sub-Category'>".stripslashes($cat)."</a></div></td>
<td class='options'><a href='admin.php?f=edit_cat&cat_id=$id' class='options' title='Edit this Sub-Category'>Edit</a></td>
<td class='options'><a href='admin.php?f=11&cat_id=$id' title='Delete this Sub-Category'
onclick=\"return confirm('Are you sure you want to delete? Subcategories will be lost.')\" class='options'>Delete</a></td>
</tr>
";
} else {
echo"<td width='90%'><a class='options' href='admin.php?f=edit_cat&cat_id=$id'
title='Edit this Category'>".stripslashes($cat)."</a></td>
<td class='options'><a href='admin.php?f=edit_cat&cat_id=$id' class='options' title='Edit this Category'>Edit</a></td>
<td class='options'><a href='admin.php?f=11&cat_id=$id' title='Delete this Category'
onclick=\"return confirm('Are you sure you want to delete? Subcategories will be lost.')\" class='options'>Delete</a></td>
</tr>
";
}
$color = list_cats($id, $lev + 1, $color, "");
}
}
if ($lev == 0) {
echo "</table>
</div>
";
}
return $color;
}
function list_catsform($parent, $lev, $color, $message, $category_id) {
global $mysql_table_prefix, $debug;
if ($lev == 0) {
print "\n";
}
$space = "";
for ($x = 0; $x < $lev; $x++)
$space .= " - ";
$query = "SELECT * FROM ".$mysql_table_prefix."categories WHERE parent_num=$parent ORDER BY category LIMIT 0 , 300";
$result = mysql_query($query);
if ($debug > '0') echo mysql_error();
if (mysql_num_rows($result) <> ''){
print "<option ".$selected." value=\"0\"> none</option>\n"; //select no category
while ($row = mysql_fetch_array($result)) {
$id = $row['category_id'];
$cat = $row['category'];
$selected = " selected=\"selected\" ";
if ($category_id != $id) { $selected = ""; }
print "<option ".$selected." value=\"".$id."\">".$space.stripslashes($cat)."</option>\n";
$color = list_catsform($id, $lev + 1, $color, "", $category_id);
}
}
return $color;
}
function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
function saveToLog($query, $elapsed, $results, $ip, $media) {
global $mysql_table_prefix, $debug;
if ($results =="") {
$results = 0;
}
$query = "insert into ".$mysql_table_prefix."query_log (query, time, elapsed, results, ip, media) values ('$query', now(), '$elapsed', '$results', '$ip', '$media')";
mysql_query($query);
if ($debug > '0') echo mysql_error();
}
function validate_url($input) {
global $mytitle;
// Standard URL test
if (! preg_match('=(https?|ftp)://[a-z0-9]([a-z0-9-]*[a-z/0-9])?\.[a-z0-9]=i', ($input))) {
echo "<h1>$mytitle</h1>
<br />
<p class='warnadmin cntr'>
Invalid input for 'URL'
</p>
<a class='bkbtn' href='addurl.php' title='Go back to Submission Form'>Back</a>
</body>
</html>
";
die ('');
}
// Do we have a valid DNS ? This test is disabled for localhost application as checkdnsrr needs internet access
$localhost = strstr(htmlspecialchars(@$_SERVER['HTTP_REFERER']), "localhost");
if (!$localhost) {
if (preg_match("/www/i", $input)){
$input = preg_replace ('/http:\/\//i','',$input);
$input1 = $input;
$pos = strpos($input1,"/");
if ($pos != '') $input1 = substr($input1,0,$pos);
if(@checkdnsrr("www.sphider-plus.eu", "A")) { // pre-check for correct response of checkdnsrr() on Windows OS
if(!checkdnsrr($input1, "A")) {
echo "<h1>$mytitle</h1>
<br />
<p class='warnadmin cntr'>Invalid URL input. No DNS resource available for this url
<a class='bkbtn' href='addurl.php' title='Go back to Submission Form'>Back</a></p>
</body>
</html>
";
die ('');
}
}
$input = str_replace("www","http://www",$input);
}
}
return ($input);
}
function validate_email($input) {
// kill LF, CR, comma, zero-bytes and entities
$input = preg_replace('/[\0\r\n,]|(%0\s*\w)/im', null, urldecode($input));
if (!preg_match('/\@localhost$/', $input)) {
// Standard e-mail test
if(!preg_match('/^[\w.+-]{2,}\@[\w.-]{2,}\.[a-z]{2,6}$/', $input)) {
echo "<h1>$mytitle</h1>
<br />
<p class='warnadmin cntr'>
Invalid input for 'e-mail account'
</p>
<a class='bkbtn' href='addurl.php' title='Go back to Submission Form'>Back</a>
</body>
</html>
";
die ('');
}
} else {
// some rudimentarily test for localhost e-mail accounts
if(!preg_match('/^[\w.+-]{2,}\@/', $input)) {
echo "<h1>$mytitle</h1>
<br />
<p class='warnadmin cntr'>
Invalid input for 'e-mail account'
</p>
<a class='bkbtn' href='addurl.php' title='Go back to Submission Form'>Back</a>
</body>
</html>
";
die ('');
}
}
// Check if Mail Exchange Resource Record (MX-RR) is valid and also is stored in Domain Name System (DNS)
// This test is disabled for localhost applications as getmxrr needs internet access
$localhost = strstr(htmlspecialchars(@$_SERVER['HTTP_REFERER']), "localhost");
if (!$localhost) {
if(!getmxrr(substr(strstr($input, '@'), 1), $mxhosts)) {
echo "<h1>$mytitle</h1>
<br />
<p class='warnadmin cntr'>
Invald e-mail account.<br />
There is no valid Mail Exchange Resource Record (MX-RR)<br />
on the Domain Name System (DNS)
</p>
<a class='bkbtn' href='addurl.php' title='Go back to Submission Form'>Back</a>
</body>
</html>
";
die ('');
}
}
return ($input);
}
function parse_addr($url) { // function like parse_url, but working also for non ASCII URLs
$urlparts = array();
$sch = '';
$h = '';
$o = '';
$p = '';
$q = '';
$f = '';
$url = str_replace("\\", "/", $url);
$url2 = $url."/"; // might be missing at some 301 relocated addresses
$sch = strpos($url, "://"); // end of [scheme] = begin of [host]
$urlparts[scheme] = substr($url, 0, $sch);
$h = strpos(substr($url2, $sch+3), "/"); // endpos of [host]port] = begin of [path]
$host_port = substr($url, $sch+3, $h);
$o = strpos(substr($url, $sch+3, $h), ":"); // find [port] delimiter
if (!$o) {
$urlparts[host] = substr($url, $sch+3, $h);
} else { // if [port] available
$urlparts[host] = substr($url, $sch+3, $o); // only [host]
$urlparts[port] = substr($url, $sch+$o+4, $h-$o-1); // additionally [port]
}
$p = strpos(substr($url, $h+1), "/"); // begin position [path]
$q = strpos(substr($url, $h+$p+1), "?"); // find begin of [query]
if (!$q) { // if no query found
$urlparts[path] = substr($url, $h+$p+1);
} else {
$urlparts[path] = substr($url, $h+$p+1, $q);
$f = strpos(substr($url, $h+$p+$q+2), "#"); // find beginn of [fragment]
}
if ($q && !$f) { // if no fragment found
$urlparts[query] = substr($url, $h+$p+$q+2); // only [query]
}
if ($f) {
$urlparts[query] = substr($url, $h+$p+$q+2, $f);
$urlparts[fragment] = substr($url, $h+$p+$q+$f+3);
}
return ($urlparts); // [user] and [pass] are currently not parsed
}
function convert_url($url) { // storable for MySQL
$url = str_replace("&", "&", $url);
$url = str_replace(" ", "%20", $url);
return $url;
}
function reconvert_url($url) { // readable for messages
$url = str_replace("&","&", $url);
$url = str_replace("%20", " ", $url);
return $url;
}
function cleanup_text($input='', $preserve='', $allowed_tags='') {
if (empty($preserve)){
$input = strip_tags($input, $allowed_tags);
}
$input = htmlspecialchars($input, ENT_QUOTES);
return $input;
}
function cleaninput($input) {
global $block_attacks;
if (get_magic_quotes_gpc()) {
$input = stripslashes($input); // delete quotes
//$input = urldecode($input);
}
/*
// prevent Directory Traversal attacks
if(preg_match('/\.\.\/|\.\.\\\/i', $input)) {
$input = '';
}
*/
// prevent SQL-injection
if (substr_count($input,"'") != '1') {
$input = mysql_real_escape_string($input);
} else {
$input = str_replace('\\','\\\\', $input); // if one slash is part of the query, we have to allow it . . .
$input = str_replace('"','\"', $input); // never the less we need to prevent SQL attacks
}
if (preg_match("/%FF%FE%3C%73%63%72%69%70%74%3E/i",$input)) { // tr/vb.hpq trojan
$input = '';
}
if ($block_attacks == "1") {
// prevent XSS-attack and Shell-execute
if (preg_match("/cmd|CREATE|DELETE|DROP|eval|EXEC|File|INSERT|printf/i",$input)) {
$input = '';
}
if (preg_match("/LOCK|PROCESSLIST|SELECT|shell|SHOW|SHUTDOWN/i",$input)) {
$input = '';
}
if (preg_match("/SQL|SYSTEM|TRUNCATE|UNION|UPDATE|DUMP/i",$input)) {
$input = '';
}
// suppress JavaScript execution and tag inclusions
$input = unsafe($input);
}
return $input;
}
$UNSAFE_IN = array();
$UNSAFE_IN[] = "/script/i";
$UNSAFE_IN[] = "/alert/i";
$UNSAFE_IN[] = "/javascript\s*:/i";
$UNSAFE_IN[] = "/vbscri?pt\s*:/i";
$UNSAFE_IN[] = "/<\s*embed.*swf/i";
$UNSAFE_IN[] = "/<[^>]*[^a-z]onabort\s*=/i";
$UNSAFE_IN[] = "/<[^>]*[^a-z]onblur\s*=/i";
$UNSAFE_IN[] = "/<[^>]*[^a-z]onchange\s*=/i";
$UNSAFE_IN[] = "/<[^>]*[^a-z]onfocus\s*=/i";
$UNSAFE_IN[] = "/<[^>]*[^a-z]onmouseout\s*=/i";
$UNSAFE_IN[] = "/<[^>]*[^a-z]onmouseover\s*=/i";
$UNSAFE_IN[] = "/<[^>]*[^a-z]onload\s*=/i";
$UNSAFE_IN[] = "/<[^>]*[^a-z]onreset\s*=/i";
$UNSAFE_IN[] = "/<[^>]*[^a-z]onselect\s*=/i";
$UNSAFE_IN[] = "/<[^>]*[^a-z]onsubmit\s*=/i";
$UNSAFE_IN[] = "/<[^>]*[^a-z]onunload\s*=/i";
$UNSAFE_IN[] = "/<[^>]*[^a-z]onerror\s*=/i";
$UNSAFE_IN[] = "/<[^>]*[^a-z]onclick\s*=/i";
$UNSAFE_IN[] = "/onabort\s*=/i";
$UNSAFE_IN[] = "/onblur\s*=/i";
$UNSAFE_IN[] = "/onchange\s*=/i";
$UNSAFE_IN[] = "/onfocus\s*=/i";
$UNSAFE_IN[] = "/onmouseout\s*=/i";
$UNSAFE_IN[] = "/onmouseover\s*=/i";
$UNSAFE_IN[] = "/onload\s*=/i";
$UNSAFE_IN[] = "/onreset\s*=/i";
$UNSAFE_IN[] = "/onselect\s*=/i";
$UNSAFE_IN[] = "/onsubmit\s*=/i";
$UNSAFE_IN[] = "/onunload\s*=/i";
$UNSAFE_IN[] = "/onerror\s*=/i";
$UNSAFE_IN[] = "/onclick\s*=/i";
$UNSAFE_IN[] = "/\'\/\*/i";
$UNSAFE_IN[] = "/\"><>/i";
$UNSAFE_IN[] = "/\?\@\%/i";
function unsafe($input) {
global $UNSAFE_IN;
foreach ($UNSAFE_IN as $match) {
if( preg_match($match, $input)) {
$input = '';
return $input;
}
}
return $input;
}
function ip2bin($ip) {
if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== false)
return base_convert(ip2long($ip),10,2);
if(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false)
return false;
if(($ip_n = inet_pton($ip)) === false) return false;
$bits = 15; // 16 x 8 bit = 128bit (ipv6)
while ($bits >= 0) {
$bin = sprintf("%08b",(ord($ip_n[$bits])));
$ipbin = $bin.$ipbin;
$bits--;
}
return $ipbin;
}
function bin2ip($bin) {
if(strlen($bin) <= 32) // 32bits (ipv4)
return long2ip(base_convert($bin,2,10));
if(strlen($bin) != 128)
return false;
$pad = 128 - strlen($bin);
for ($i = 1; $i <= $pad; $i++) {
$bin = "0".$bin;
}
$bits = 0;
while ($bits <= 7) {
$bin_part = substr($bin,($bits*16),16);
$ipv6 .= dechex(bindec($bin_part)).":";
$bits++;
}
return inet_ntop(inet_pton(substr($ipv6,0,-1)));
}
/**
* Convert an IPv4 address to IPv6
* @param string IP Address in dot notation (192.168.1.100)
* @return string IPv6 formatted address or false if invalid input
*/
function IPv4To6($Ip) {
static $Mask = '::ffff:'; // This tells IPv6 it has an IPv4 address
$IPv6 = (strpos($Ip, '::') === 0);
$IPv4 = (strpos($Ip, '.') > 0);
if (!$IPv4 && !$IPv6) return false;
if ($IPv6 && $IPv4) $Ip = substr($Ip, strrpos($Ip, ':')+1); // Strip IPv4 Compatibility notation
elseif (!$IPv4) return $Ip; // Seems to be IPv6 already?
$Ip = array_pad(explode('.', $Ip), 4, 0);
if (count($Ip) > 4) return false;
for ($i = 0; $i < 4; $i++) if ($Ip[$i] > 255) return false;
$Part7 = base_convert(($Ip[0] * 256) + $Ip[1], 10, 16);
$Part8 = base_convert(($Ip[2] * 256) + $Ip[3], 10, 16);
return $Mask.$Part7.':'.$Part8;
}
/**
* Replace '::' with appropriate number of ':0'
*/
function ExpandIPv6Notation($Ip) {
if (strpos($Ip, '::') !== false)
$Ip = str_replace('::', str_repeat(':0', 8 - substr_count($Ip, ':')).':', $Ip);
if (strpos($Ip, ':') === 0) $Ip = '0'.$Ip;
return $Ip;
}
/**
* Convert IPv6 address to an integer
* Optionally split in to two parts.
* @see http://stackoverflow.com/questions/420680/
*/
function IPv6ToLong($Ip, $DatabaseParts= 2) {
$Ip = ExpandIPv6Notation($Ip);
$Parts = explode(':', $Ip);
$Ip = array('', '');
for ($i = 0; $i < 4; $i++) $Ip[0] .= str_pad(base_convert($Parts[$i], 16, 2), 16, 0, STR_PAD_LEFT);
for ($i = 4; $i < 8; $i++) $Ip[1] .= str_pad(base_convert($Parts[$i], 16, 2), 16, 0, STR_PAD_LEFT);
if ($DatabaseParts == 2)
return array(base_convert($Ip[0], 2, 10), base_convert($Ip[1], 2, 10));
else return base_convert($Ip[0], 2, 10) + base_convert($Ip[1], 2, 10);
}
function mk5() {
$handle = fopen ("./settings/database.php", "rb");
$cont = fread ($handle, 8192);
fclose ($handle);
$activate = "dbu_act = \"5\";\r\n\r\n\$lock = \"1\";";
$c2 = preg_replace ("/dbu_act = \"1\";/i", $activate, $cont);
$c2 = preg_replace ("/db1_slv = \"1\"/i", "db1_slv = \"0\"", $c2);
$c2 = preg_replace ("/db2_slv = \"1\"/i", "db2_slv = \"0\"", $c2);
$c2 = preg_replace ("/db3_slv = \"1\"/i", "db3_slv = \"0\"", $c2);
$c2 = preg_replace ("/db4_slv = \"1\"/i", "db4_slv = \"0\"", $c2);
$c2 = preg_replace ("/db5_slv = \"0\"/i", "db5_slv = \"1\"", $c2);
$handle = fopen ("./settings/database.php", "wb");
fwrite ($handle, $c2);
fclose ($handle);
}
function footer() {
global $include_dir, $add_url, $most_pop, $mysql_table_prefix;
echo "<p class=\"stats\"><a href=\"http://www.sphider-plus.eu\" title=\"Link: Visit Sphider-plus site in new window\" target=\"rel\">Visit <img class=\"mid\" src=\"$include_dir/images/sphider-plus-logo.gif\" alt=\"Visit Sphider site in new window\" height=\"39\" width=\"42\" /> Sphider-plus</a></p>";
}
function error_handler($errNo, $errStr, $errFile, $errLine){
if(ob_get_length()) ob_clean(); // clear any output that has already been generated
$error_message = 'ERRNO: ' . $errNo . chr(10) .
'TEXT: ' . $errStr . chr(10) .
'LOCATION: ' . $errFile .
', line ' . $errLine;
echo $error_message;
exit; // stop executing any script
}
class resize{
// *** Class variables
private $image;
private $width;
private $height;
private $imageResized;
function __construct($fileName){
// *** Open up the file
$this->image = $this->openImage($fileName);
// *** Get width and height
$this->width = imagesx($this->image);
$this->height = imagesy($this->image);
}
private function openImage($file){
// *** Get extension
$extension = strtolower(strrchr($file, '.'));
switch($extension)
{
case '.jpg':
case '.jpeg':
$img = @imagecreatefromjpeg($file);
break;
case '.gif':
$img = @imagecreatefromgif($file);
break;
case '.png':
$img = @imagecreatefrompng($file);
break;
default:
$img = false;
break;
}
return $img;
}
public function resizeImage($newWidth, $newHeight, $option="auto"){
// *** Get optimal width and height - based on $option
$optionArray = $this->getDimensions($newWidth, $newHeight, $option);
$optimalWidth = $optionArray['optimalWidth'];
$optimalHeight = $optionArray['optimalHeight'];
// *** Resample - create image canvas of x, y size
$this->imageResized = imagecreatetruecolor($optimalWidth, $optimalHeight);
imagecopyresampled($this->imageResized, $this->image, 0, 0, 0, 0, $optimalWidth, $optimalHeight, $this->width, $this->height);
// *** if option is 'crop', then crop too
if ($option == 'crop') {
$this->crop($optimalWidth, $optimalHeight, $newWidth, $newHeight);
}
}
private function getDimensions($newWidth, $newHeight, $option){
switch ($option)
{
case 'exact':
$optimalWidth = $newWidth;
$optimalHeight= $newHeight;
break;
case 'portrait':
$optimalWidth = $this->getSizeByFixedHeight($newHeight);
$optimalHeight= $newHeight;
break;
case 'landscape':
$optimalWidth = $newWidth;
$optimalHeight= $this->getSizeByFixedWidth($newWidth);
break;
case 'auto':
$optionArray = $this->getSizeByAuto($newWidth, $newHeight);
$optimalWidth = $optionArray['optimalWidth'];
$optimalHeight = $optionArray['optimalHeight'];
break;
case 'crop':
$optionArray = $this->getOptimalCrop($newWidth, $newHeight);
$optimalWidth = $optionArray['optimalWidth'];
$optimalHeight = $optionArray['optimalHeight'];
break;
}
return array('optimalWidth' => $optimalWidth, 'optimalHeight' => $optimalHeight);
}
private function getSizeByFixedHeight($newHeight){
$ratio = $this->width / $this->height;
$newWidth = $newHeight * $ratio;
return $newWidth;
}
private function getSizeByFixedWidth($newWidth){
$ratio = $this->height / $this->width;
$newHeight = $newWidth * $ratio;
return $newHeight;
}
private function getSizeByAuto($newWidth, $newHeight){
if ($this->height < $this->width)
// *** Image to be resized is wider (landscape)
{
$optimalWidth = $newWidth;
$optimalHeight= $this->getSizeByFixedWidth($newWidth);
}
elseif ($this->height > $this->width)
// *** Image to be resized is taller (portrait)
{
$optimalWidth = $this->getSizeByFixedHeight($newHeight);
$optimalHeight= $newHeight;
}
else
// *** Image to be resizerd is a square
{
if ($newHeight < $newWidth) {
$optimalWidth = $newWidth;
$optimalHeight= $this->getSizeByFixedWidth($newWidth);
} else if ($newHeight > $newWidth) {
$optimalWidth = $this->getSizeByFixedHeight($newHeight);
$optimalHeight= $newHeight;
} else {
// *** Sqaure being resized to a square
$optimalWidth = $newWidth;
$optimalHeight= $newHeight;
}
}
return array('optimalWidth' => $optimalWidth, 'optimalHeight' => $optimalHeight);
}
private function getOptimalCrop($newWidth, $newHeight){
$heightRatio = $this->height / $newHeight;
$widthRatio = $this->width / $newWidth;
if ($heightRatio < $widthRatio) {
$optimalRatio = $heightRatio;
} else {
$optimalRatio = $widthRatio;
}
$optimalHeight = $this->height / $optimalRatio;
$optimalWidth = $this->width / $optimalRatio;
return array('optimalWidth' => $optimalWidth, 'optimalHeight' => $optimalHeight);
}
private function crop($optimalWidth, $optimalHeight, $newWidth, $newHeight){
// *** Find center - this will be used for the crop
$cropStartX = ( $optimalWidth / 2) - ( $newWidth /2 );
$cropStartY = ( $optimalHeight/ 2) - ( $newHeight/2 );
$crop = $this->imageResized;
//imagedestroy($this->imageResized);
// *** Now crop from center to exact requested size
$this->imageResized = imagecreatetruecolor($newWidth , $newHeight);
imagecopyresampled($this->imageResized, $crop , 0, 0, $cropStartX, $cropStartY, $newWidth, $newHeight , $newWidth, $newHeight);
}
public function saveImage($savePath, $imageQuality="100"){
// *** Get extension
$extension = strrchr($savePath, '.');
$extension = strtolower($extension);
switch($extension)
{
case '.jpg':
case '.jpeg':
if (imagetypes() & IMG_JPG) {
imagejpeg($this->imageResized, $savePath, $imageQuality);
}
break;
case '.gif':
if (imagetypes() & IMG_GIF) {
imagegif($this->imageResized, $savePath);
}
break;
case '.png':
// *** Scale quality from 0-100 to 0-9
$scaleQuality = round(($imageQuality/100) * 9);
// *** Invert quality setting as 0 is best, not 9
$invertScaleQuality = 9 - $scaleQuality;
if (imagetypes() & IMG_PNG) {
imagepng($this->imageResized, $savePath, $invertScaleQuality);
}
break;
default:
// *** No extension - No save.
break;
}
imagedestroy($this->imageResized);
}
}
function resample($img, $width, $height){
// Set a maximum height and width
$width = 400;
$height = 400;
// Content type
header('Content-type: image/jpeg');
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($img);
$ratio_orig = $width_orig/$height_orig;
if ($width/$height > $ratio_orig) {
$width = $height*$ratio_orig;
} else {
$height = $width/$ratio_orig;
}
// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($img);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
// Output
//imagejpeg($image_p, null, 100);
return ($image_p);
}
function del_secchars($file){
global $cn_seg, $del_secchars, $del_seccharin;
if ($cn_seg == '1' && $del_secchars==1 || $del_seccharin ==1) {
// Delete additional characters (as word separator) like dots, question marks, colons etc. (characters 1-49 in original Chinese dictionary)
$file = preg_replace ('/ã|ï¼|ã¿|ï¼|ï¼|ï¼|_|â¦|â|·|Ë|Ë|¨|â|â|â|â¿|ã
|ï½|â|â¶|ï¼|ï¼|ï½|ï½|ã|ã|ã|ã|ã|ã|ã|ã|ã¿|ã|ã¿|ï¼|ã|ã|ã¿|ã|ï¼|ï¼|ï¼»|ï¼½|ï½|ソ/', " ", $file);
$file = preg_replace('/ï¼âº|¡£|£¬|¡¢|£»|£º|£¿|£¡|¡Â|¡ª|¡¤|¡¥|¡¦|¡§|¡®|¡¯|¡°|¡±|¡©|¡«|¡¬|¡Ã|£¢|£§|£à |£ü|¡¨|¡²|¡³|¡´|¡µ|¡¶|¡·|¡¸|¡¹|¡º|¡»|£®|¡¼|¡½|¡¾|¡¿|£¨|£©|£Ã|£ÿ|£û|£ý|°¢/', " ", $file);
$file = preg_replace('/_|ï¼|ï¼|<|ï¼|ï¼|ã»|\(|\)/', " ", $file);
}
if ($del_secchars == '1') {
// kill all special characters at the end of words
$file = preg_replace('/,|\. |\.\. |\.\.\. |!|\? |" |: |\) |\), |\)\. |ã |ï¼ |ï¼,|ï¼ |ï¼ |ï¼|ã,|ã |â |â |â |â|â |» |\.»|;»|:»|,»|\.»|λ|«|« |», |»\. |\.â |,â|;â |â\. |â, |â¿|ã|ï¼|Î|;|\] |\} |_, |_ |â\)\. |.\"> |\"> |> /', " ", $file);
// kill special characters in front of words
$file = preg_replace('/ \[| "| \(| â|â| â|ï¼| «| ã| â¿| ï¼| \(â|â| ©| ®| â¢| â| <| \/| @| \\"| \./', " ", $file);
}
if ($del_seccharin == '1'){
$file = del_secintern($file);
}
return $file;
}
function del_secintern($file) {
// kill separating characters inside of words
//$file = preg_replace('/ã»/', " ", $file);
//$file = preg_replace('/=|"|\<|\>|\_\#|\+|%|&|_|\(|\)|\.\.\.|\.\.|\//', " ", $file); // light version
$file = preg_replace('/=|"|\<|\>|\]|\[|\(|\)|\_\#|\+|%|&|_|\(|\)|\.|\.\.\.|\.\.|\/|=\\":\/\|\"|ã»|\/\"/', " ", $file);
return $file;
}
function split_words($file) {
global $div_all, $div_hyphen;
$all = '';
if ($div_hyphen) {
preg_match_all("/[\d\w\.,'ââ´`ââ_]+[-][\d\w\.,'ââ´`ââ_\?\!]+/si", $file, $regs, PREG_SET_ORDER); // get hyphpen combined words
$file = preg_replace("/-/", " ", $file); // divide words into their basic parts
}
if ($div_all){
preg_match_all("/[\d\w]+[.|,|'|â|â|´|`|â|â|\-|_\/][\d\w\.,'-_\?\!]+/si", $file, $regs, PREG_SET_ORDER); // get dot, comma and quote combined words
$file = preg_replace("/-|\.|,|'|â|â|´|`|â|â|\//", " ", $file);
}
foreach ($regs as $value) {
$all .= " ".$value[0].""; // collect all combined words
}
$file .= "".$all." "; // add the combined words to $file
return ($file);
}
// try to open a file my means of cURL library
function curl_open($url) {
$result = '';
$curl_handle = curl_init();
curl_setopt($curl_handle,CURLOPT_URL,$url);
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$result = curl_exec($curl_handle);
curl_close($curl_handle);
return ($result);
}
function translit_el($string) {
// 1. replace special blanks with " "
$string = str_replace(" ", " ", $string);
// 2. replace Latin 's' at the end of multiple query words with the Greek 'Ï'
if(strstr($string, " ")){
$str_array = explode(" ", $string); // build an intermediate array
foreach ($str_array as $this_word) {
if (strrpos($this_word, "s") == strlen($this_word)-1) { // if 's' is last letter of this word
$str_array2[] = substr_replace($this_word, "Ï", strlen($this_word)-1);
} else {
$str_array2[] = $this_word; // no 's' as last letter was found, just use the input word
}
}
$string = implode(" ", $str_array2); // rebuild the string
} else {
// replace Latin 's' at the end of a single query word with the Greek 'Ï'
if (strrpos($string, "s") == strlen($string)-1) {
$string = substr_replace($string, "Ï", strlen($string)-1);
}
}
// 3. translit some specialities
$string = preg_replace('/TH/', "Î", $string);
$string = preg_replace('/th/', "θ", $string);
$string = preg_replace('/CH/', "Χ", $string);
$string = preg_replace('/ch/', "Ï", $string);
$string = preg_replace('/PS/', "Ψ", $string);
$string = preg_replace('/ps/', "Ï", $string);
$string = preg_replace('/PH/', "Φ", $string);
$string = preg_replace('/ph/', "Ï", $string);
// 4. translit upper case letters
$en = array("A","V","C","G","D","E","F","Z","I","K","L","M","N","X","O","P","Q","R","S","T","W","Y");
$el = array("Î","Î","Î","Î","Î","Î","Φ","Î","Î","Î","Î","Î","Î","Î","Î","Î ","Î","Ρ","Σ","Τ","Ω","Ψ");
//$el = array("Î","Î","Î","Î","Î","Î","Î","Î","Î","Î","Î","Î","Χ","Î","Î ","Î","Ρ","Σ","Τ","Î¥","Ω","Φ","Î","Ψ","Î");
$string = str_replace($en, $el, $string);
// 5. translit lower case letters
$en = array("a","b","v","c","g","d","e","f","h","z","i","k","l","m","n","x","o","p","q","r","s","t","y","u","w","Å","y","Ä«");
$el = array("α","β","β","ξ","γ","δ","ε","Ï","η","ζ","ι","κ","λ","μ","ν","ξ","ο","Ï","θ","Ï","Ï","Ï","Ï
","Ï
","Ï","Ï","Ï","η");
//$el = array("α","β","ξ","δ","ε","γ","η","ι","κ","λ","μ","ν","ο","Ï","θ","Ï","Ï","Ï","Ï
","Ï","Ï","Ï","Ï","ζ");
$string = str_replace($en, $el, $string);
$string = str_replace("<uλ>", "<ul>", $string);
$string = str_replace("<λι>. Ï Ï", "<li>. . .", $string);
$string = str_replace("<ÏÏÏονγ>. Ï Ï", "<strong>. . .", $string);
$string = str_replace("</ÏÏÏονγ>. Ï Ï", "</strong>. . .", $string);
$string = str_replace("<λι>", "<li>", $string);
$string = str_replace("<ÏÏÏονγ>", "<strong>", $string);
$string = str_replace("Ï Ï .", " . . .", $string);
$string = str_replace("Ï Ï Ï </λι>", " . . .</li>", $string);
$string = str_replace("</ÏÏÏονγ>", "</strong>", $string);
$string = str_replace("</λι>", "</li>", $string);
$string = str_replace("</uλ>", "</ul>", $string);
return $string;
}
// replace UNICODE charset with MySQL equivalent
function conv_mysql($string) {
$get = array(
"utf-8",
"big-5",
"iso-8859-1",
"iso-8859-2",
"iso-8859-7",
"ISO-8859-8",
"ISO-8859-9",
"iso-8859-13",
"koi8-r",
"koi8-u",
"iso-646-se",
"us-ascii",
"euc-jp",
"shift-jis",
"cp-1251",
"euc_kr",
"gb-2312",
"windows-1250",
"ucs-2",
"cp-852",
"cp-866",
"cp-1256",
"cp-932",
"euc-jp"
);
$out = array(
"utf8",
"big5",
"latin1",
"latin2",
"greek",
"hebrew",
"latin7",
"latin5",
"koi8r",
"koi8u",
"swe7",
"ascii",
"ujis",
"sjis",
"cp1251",
"euckr",
"gb2312",
"cp1250",
"ucs2",
"cp852",
"cp866",
"cp1256",
"cp932",
"eucjpms"
);
$mysql = str_ireplace($get, $out, $string);
if ($mysql == $string) {
$mysql = "utf8";
}
return $mysql;
}
function remove_acc($string, $wild) {
global $type;
$acct_a = array("a;", "à ", "â", "Ã¥", "â", "ÃÆÃ¤", "ä", "ÃÆ\"ž", "Ãâ", "Ã", "ä", "á", "à ",
"à", "á", "á", "Ã", "À", "Ã", "Á");
$base_a = array("a", "a", "a", "a", "a", "a", "a", "A", "A", "A", "a", "a", "a",
"a", "a", "a", "A", "A", "A", "A");
$string = str_ireplace($acct_a, $base_a, $string);
$acct_c = array("Ä", "ç", "ç", "ç", "Ç", "Ä");
$base_c = array("c", "c", "c", "c", "C", "C");
$string = str_ireplace($acct_c, $base_c, $string);
$acct_e = array("Ä", "ê", "è", "ê", "é", "è", "è", "é", "é", "Ã", "È", "Ã", "É", "ÃË", "Ãâ°", "Ä");
$base_e = array("e", "e", "e", "e", "e", "e", "e", "e", "e", "E", "E", "E", "E", "E", "E", "E");
$string = str_ireplace($acct_e, $base_e, $string);
$acct_i = array("î", "ì", "ì", "Ã", "í","Ì", "Ã", "Í",
"ñ", "á", "Ã'", "ÿ" ); // "Ã" removed, because replaces the letter à => I
$base_i = array("i", "i", "i", "i", "i","I", "I", "I",
"ñ", "¡", "Ã", "¿");
$string = str_ireplace($acct_i, $base_i, $string);
$acct_o = array("ô", "ø", "Ã", "ô", "ó", "ò", "õ", "Ãâ", "̮̦", "ö", "ã¶", "ö",
"ó", "ò","ò", "ó", "ó", "Ã", "Ò", "Ã", "Ó");
$base_o = array("o", "o", "O", "o", "o", "o", "o", "O", "o", "o", "o", "o",
"O", "o", "O", "o", "o", "O", "O", "O", "O");
$string = str_ireplace($acct_o, $base_o, $string);
$acct_u = array("ÃÅ", "Å", "û", "ù", "ú", "û", "ÃÆÃ¼", "ü", "ÃÆÃ
\â", "ÃÅ", "Ã", "ü", "ú",
"ù", "ù", "ú", "ú", "Ã", "Ù", "Ã", "Ú");
$base_u = array("u", "u", "u", "u", "u", "u", "u", "u", "U", "U", "U", "u", "u",
"u", "u", "u", "u", "U", "U", "U", "U");
$string = str_ireplace($acct_u, $base_u, $string);
if ($type == "tol" && !$wild){ // make tolerant by replacing vowels with %
$string = rep_latvowels($string);
}
return $string;
}
// replace Greek accents with their pure vowels
function remove_acc_el($string, $wild) {
global $type;
$string = preg_replace('/α|á¼|á¼|á¼|á¼|á¼|á¼
|á¼|á¼|á½°|á½±|á½±|á¾|á¾|á¾|á¾|á¾|á¾
|á¾|á¾|á¾°|á¾±|á¾²|á¾³|á¾´|á¾¶|á¾·|ά|Ä/', "α", $string);
$string = preg_replace('/Î|á¼|á¼|á¼|á¼|á¼|á¼|á¼|á¼|Ὰ|á¾»|á¾»|á¾|á¾|á¾|á¾|á¾|á¾|á¾|á¾|Ᾰ|á¾¹|á¾¼|Î/', "Î", $string);
$string = preg_replace('/ε|á¼|á¼|á¼|á¼|á¼|á¼|á½²|á½³|á½³|Î|Ä/', "ε", $string);
$string = preg_replace('/Î|á¼|á¼|á¼|á¼|á¼|á¼|á¿|á¿|á¿|Î/', "Î", $string);
$string = preg_replace('/η|ή|á¼ |ἡ|á¼£|á¼£|ἤ|á¼¥|ἦ|á¼§|á½´|á½µ|á½µ|á¾|á¾|á¾|á¾|á¾|á¾|á¾|á¾|á¿|á¿|á¿|á¿|á¿/', "η", $string);
$string = preg_replace('/Î|Ἠ|Ἡ|Ἢ|Ἣ|Ἤ|á¼|á¼®|Ἧ|á¿|á¿|á¿|á¾|á¾|á¾|á¾|á¾|á¾|á¾|á¾|á¿/', "Î", $string);
$string = preg_replace('/ι|á¼°|á¼±|á¼²|á¼³|á¼´|á¼µ|á¼¶|á¼·|á½¶|á½·|á½·|á¿|á¿|á¿|Ï|á¿|á¿|á¿|á¿|ί|Î/', "ι", $string);
$string = preg_replace('/Ἰ|á¼¹|Ἲ|á¼»|á¼¼|á¼½|á¼¾|Ἷ|á¿|á¿|á¿|á¿|á¿/', "Ἰ", $string);
$string = preg_replace('/Ï|á½ |ὡ|á½¢|á½£|ὤ|á½¥|ὦ|á½§|á½¼|á½½|á½½|á¾ |ᾡ|á¾¢|á¾£|ᾤ|á¾¥|ᾦ|á¾§|ῲ|ῳ|á¿´|á¿¶|á¿·|Ï/', "Ï", $string);
$string = preg_replace('/Ω|Ὠ|Ὡ|Ὢ|Ὣ|Ὤ|á½|á½®|Ὧ|Ὼ|á¿»|á¿»|ᾨ|ᾩ|ᾪ|ᾫ|ᾬ|á¾|á¾®|ᾯ|ῼ/', "Ω", $string);
$string = preg_replace('/ο|á½|á½|á½|á½|á½|á½
|ὸ|á½¹|á½¹|Ï|ò|ô|Å/', "ο", $string);
$string = preg_replace('/Î|á½|á½|á½|á½|á½|á½|Ὸ|Ό|Ό/', "Î", $string);
$string = preg_replace('/Ï
|á½|á½|á½|á½|á½|á½|á½|á½|ὺ|á½»|á½»|ῦ|á¿ |á¿¡|Ï|á¿¢|á¿£|á¿£|á¿§|Ï/', "Ï
", $string);
$string = preg_replace('/Î¥|á½|á½|á½|á½|Ὺ|á¿« |á¿«|Ῠ|á¿©/', "Î¥", $string);
$string = preg_replace('/Ï|ῤ|á¿¥/', "Ï", $string);
$string = preg_replace('/Ρ|Ῥ/', "Ρ", $string);
if ($type == "tol" && !$wild){ // make tolerant by replacing vowels with %
$string = rep_elvowels($string);
}
return $string;
}
// replace Latin vowels with a (MySQL) wildcard
function rep_latvowels($string) {
$get = array("a", "c", "e", "i", "o", "u");
$out = array("%", "%", "%", "%", "%", "%");
$string = str_ireplace($get, $out, $string);
return $string;
}
// replace Greek vowels with a (MySQL) wildcard
function rep_elvowels($string) {
$get = array("α", "ε", "η", "ι", "Ï", "ο", "Ï
", "Ï
");
$out = array("%", "%", "%", "%", "%", "%", "%", "%");
$string = str_ireplace($get, $out, $string);
return $string;
}
function clear_folder($folder) {
// delete all thumbnails
if ($dh = opendir("$folder/")) {
while (($this_file = readdir($dh)) !== false) {
@unlink("$folder/$this_file");
}
closedir($dh);
}
return;
}
function getStatistics() {
global $mysql_table_prefix, $debug;
$stats = array();
$keywordQuery = "select count(keyword_id) from ".$mysql_table_prefix."keywords";
$linksQuery = "select count(url) from ".$mysql_table_prefix."links";
$siteQuery = "select count(site_id) from ".$mysql_table_prefix."sites";
$categoriesQuery = "select count(category_id) from ".$mysql_table_prefix."categories";
$mediaQuery = "select count(media_id) from ".$mysql_table_prefix."media";
$result = mysql_query($keywordQuery);
if ($debug > '0') echo mysql_error();
if ($row=mysql_fetch_array($result)) {
$stats['keywords']=$row[0];
}
$result = mysql_query($linksQuery);
if ($debug > '0') echo mysql_error();
if ($row=mysql_fetch_array($result)) {
$stats['links']=$row[0];
}
for ($i=0;$i<=15; $i++) {
$char = dechex($i);
$result = mysql_query("select count(link_id) from ".$mysql_table_prefix."link_keyword$char");
if ($debug > '0') echo mysql_error();
if ($row=mysql_fetch_array($result)) {
$stats['index']+=$row[0];
}
}
$result = mysql_query($siteQuery);
if ($debug > '0') echo mysql_error();
if ($row=mysql_fetch_array($result)) {
$stats['sites']=$row[0];
}
$result = mysql_query($categoriesQuery);
if ($debug > '0') echo mysql_error();
if ($row=mysql_fetch_array($result)) {
$stats['categories']=$row[0];
}
$result = mysql_query($mediaQuery);
if ($debug > '0') echo mysql_error();
if ($row=mysql_fetch_array($result)) {
$stats['media']=$row[0];
}
return $stats;
}
function stem_word($word, $type) {
global $debug, $stem_words, $stem_dir, $min_word_length, $common;
//if ($debug == '2') echo "\r\n\r\n<br /> unstemmed: $word<br />\r\n";
// no stemming for too short words or words containing some special characters
if (strlen($word) < $min_word_length || preg_match("/[\*\!:]|[0-9]/si", $word)) {
return $word;
}
if ($stem_words == 'bg') {
require_once "$stem_dir/bg_stem.php";
$word1 = bg_stemmer::stem($word);
}
if ($stem_words == 'cz') {
require_once "$stem_dir/cz_stem.php";
$word1 = cz_stemmer::stem($word);
}
if ($stem_words == 'de') {
require_once "$stem_dir/de_stem.php";
$word1 = de_stemmer::stem($word);
}
if ($stem_words == 'el') {
require_once "$stem_dir/el_stem.php";
$stemmer = new el_stemmer();
$word1 = $stemmer->stem($word);
}
if ($stem_words == 'en') {
require_once "$stem_dir/en_stem.php";
$word1 = en_stemmer::stem($word);
}
if ($stem_words == 'es') {
require_once "$stem_dir/es_stem.php";
$word1 = es_stemmer::stem($word);
}
if ($stem_words == 'fi') {
require_once "$stem_dir/fi_stem.php";
$word1 = fi_stemmer::stem($word);
}
if ($stem_words == 'fr') {
require_once "$stem_dir/fr_stem.php";
$word1 = fr_stemmer::stem($word);
}
if ($stem_words == 'hu') {
require_once "$stem_dir/hu_stem.php";
$word1 = hu_stemmer::stem($word);
}
if ($stem_words == 'nl') {
require_once "$stem_dir/nl_stem.php";
$word1 = nl_stemmer::stem($word);
}
if ($stem_words == 'it') {
require_once "$stem_dir/it_stem.php";
$stemmer = new it_stemmer();
$word1 = $stemmer->stem($word);
}
if ($stem_words == 'pt') {
require_once "$stem_dir/pt_stem.php";
$word1 = pt_stemmer::stem($word);
}
if ($stem_words == 'ru') {
require_once "$stem_dir/ru_stem.php";
$word1 = ru_stemmer::stem($word);
}
if ($stem_words == 'se') {
require_once "$stem_dir/se_stem.php";
$word1 = se_stemmer::stem($word);
}
// Hopefully the stemmed word did not become too short
// and the stemming algorithm did not create a common word
if (strlen($word1) > $min_word_length && $common[$word1] != 1) {
$word = $word1;
}
//if ($debug == '2') echo "\r\n\r\n<br /> stemmed: $word<br />\r\n";
return $word;
}
// Database1 connection
function db1_connect() {
global $mysql_host1, $mysql_user1, $mysql_password1, $database1;
$db_con1 = @mysql_pconnect ($mysql_host1, $mysql_user1, $mysql_password1);
if (!$db_con1) {
echo "<p><span class='red'> Mysql Server for database '$database1' not available! <br /></font></p>
<p><span class='blue sml'> Trying to reconnect to database . . .<br /> Cannot connect to database.<br /></p>";
} else {
$success1 = @mysql_select_db ($database1, $db_con1);
if (!$success1) {
echo "<p><span class='blue sml'><br /> Cannot choose database 1.<br /></p>";
} else {
return ($db_con1);
}
}
}
// Database2 connection
function db2_connect() {
global $mysql_host2, $mysql_user2, $mysql_password2, $database2;
$db_con2 = @mysql_pconnect ($mysql_host2, $mysql_user2, $mysql_password2);
if (!$db_con2) {
echo "<p><span class='red'> Mysql Server for database '$database2' not available! <br /></font></p>
<p><span class='blue sml'> Trying to reconnect to database . . .<br /> Cannot connect to database.<br /></p>";
} else {
$success2 = @mysql_select_db ($database2, $db_con2);
if (!$success2) {
echo "<p><span class='blue sml'><br /> Cannot choose database 2.<br /></p>";
} else {
return ($db_con2);
}
}
}
// Database3 connection
function db3_connect() {
global $mysql_host3, $mysql_user3, $mysql_password3, $database3;
$db_con3 = @mysql_pconnect ($mysql_host3, $mysql_user3, $mysql_password3);
if (!$db_con3) {
echo "<p><span class='red'> Mysql Server for database '$database3' not available! <br /></font></p>
<p><span class='blue sml'> Trying to reconnect to database . . .<br /> Cannot connect to database.<br /></p>";
} else {
$success3 = @mysql_select_db ($database3, $db_con3);
if (!$success3) {
echo "<p><span class='blue sml'><br /> Cannot choose database 3.<br /></p>";
} else {
return ($db_con3);
}
}
}
// Database4 connection
function db4_connect() {
global $mysql_host4, $mysql_user4, $mysql_password4, $database4;
$db_con4 = @mysql_pconnect ($mysql_host4, $mysql_user4, $mysql_password4);
if (!$db_con4) {
echo "<p><span class='red'> Mysql Server for database '$database4' not available! <br /></font></p>
<p><span class='blue sml'> Trying to reconnect to database . . .<br /> Cannot connect to database.<br /></p>";
} else {
$success4 = @mysql_select_db ($database4, $db_con4);
if (!$success4) {
echo "<p><span class='blue sml'><br /> Cannot choose database 4.<br /></p>";
} else {
return ($db_con4);
}
}
}
// Database5 connection
function db5_connect() {
global $mysql_host5, $mysql_user5, $mysql_password5, $database5;
$db_con5 = @mysql_pconnect ($mysql_host5, $mysql_user5, $mysql_password5);
if (!$db_con5) {
echo "<p><span class='red'> Mysql Server for database '$database5' not available! <br /></font></p>
<p><span class='blue sml'> Trying to reconnect to database . . .<br /> Cannot connect to database.<br /></p>";
} else {
$success5 = @mysql_select_db ($database5, $db_con5);
if (!$success5) {
echo "<p><span class='blue sml'><br /> Cannot choose database 5.<br /></p>";
} else {
return ($db_con5);
}
}
}
function check_dbs($output) {
global $plus_nr, $db1_slv, $db2_slv, $db3_slv, $db4_slv, $db5_slv;
include "../settings/database.php";
if($output == '1') {
echo "
<fieldset><legend>[ Database Settings Overview ]</legend>
<br />
<p class='txt blue cntr'>New database settings have been saved!</p>
<p>\n\n</p>
<table width=\"90%\" border=\"1\">
<tr>
<td width=\"50%\">
<blockquote>
<p>The following settings have been tested:</p>
";
}
// prepare for multi db result fetching
if ($dbu_act == 1) $_db1_slv = 1 ;
if ($dbu_act == 2) $_db2_slv = 1 ;
if ($dbu_act == 3) $_db3_slv = 1 ;
if ($dbu_act == 4) $_db4_slv = 1 ;
if ($dbu_act == 5) $_db5_slv = 1 ;
if ($db1_slv == 1) $_db1_slv = 1 ;
if ($db2_slv == 1) $_db2_slv = 1 ;
if ($db3_slv == 1) $_db3_slv = 1 ;
if ($db4_slv == 1) $_db4_slv = 1 ;
if ($db5_slv == 1) $_db5_slv = 1 ;
if ($_db1_slv == "") $_db1_slv = 0;
if ($_db2_slv == "") $_db2_slv = 0;
if ($_db3_slv == "") $_db3_slv = 0;
if ($_db4_slv == "") $_db4_slv = 0;
if ($_db5_slv == "") $_db5_slv = 0;
// in order to get fresh status values, reset all db's
$db1_set = '0';
$db2_set = '0';
$db3_set = '0';
$db4_set = '0';
$db5_set = '0';
$db_count = '0';
// check for correct database1 settings
$db_con1 = @mysql_pconnect ($mysql_host1, $mysql_user1, $mysql_password1);
if (!$db_con1) {
if($output == '1') {
echo "<p><span class='red'> Mysql server for database1 is not available! <br /></font></p>\n
<p><span class='blue sml'> Trying to reconnect to database 1 . . .<br /> Cannot connect to database.<br /></p>\n
";
}
} else {
$success1 = @mysql_select_db ($database1, $db_con1);
if (!$success1) {
if($output == '1') {
echo "<p><span class='red cntr'><br /> Cannot choose database 1.<br /></p>
<br />
";
}
}
}
if ($db_con1 && $success1) {
if($output == '1') {
echo "<p><span class='green cntr'>- Database 1 settings are okay.</p>
";
}
// check for installed tables
$tables1 = mysql_query("select * from ".$mysql_table_prefix1."addurl");
if (mysql_error()) {
if($output == '1') {
echo "<p><span class='red cntr'><br /> Tables are not installed for database 1<br /></p>
<br />
";
}
} else {
if ($output == '1') {
echo "<p><span class='green cntr'> Tables are installed for database 1</p>
";
}
}
}
if ($db_con1 && $success1 && $tables1) {
$db1_set = 1;
$db_count ++;
}
// check for correct database2 settings
$db_con2 = @mysql_pconnect ($mysql_host2, $mysql_user2, $mysql_password2);
if (!$db_con2) {
if($output == '1') {
echo "<br />
<p><span class='red'> Mysql server for database 2 is not available! <br /></font></p>\n
<p><span class='blue sml'> Trying to reconnect to database 2 . . .<br /> Cannot connect to this database.<br /></p>\n
<p><span class='red cntr'> Never mind if you don't need it.<br /></p>
";
}
} else {
$success2 = @mysql_select_db ($database2, $db_con2);
if (!$success2) {
if($output == '1') {
echo "<p><span class='red cntr'><br /> Cannot choose database 2.<br /></p>
<br />
";
}
}
}
if ($db_con2 && $success2) {
if($output == '1') {
echo "<p><span class='green cntr'>- Database 2 settings are okay.</p>
";
}
// check for installed tables
$tables2 = mysql_query("select * from ".$mysql_table_prefix2."addurl");
if (mysql_error()) {
if($output == '1') {
echo "<p><span class='red cntr'><br /> Tables are not installed for database 2<br /></p>
<br />
";
}
} else {
if ($output == '1') {
echo "<p><span class='green cntr'> Tables are installed for database 2</p>
";
}
}
}
if ($db_con2 && $success2 && $tables2) {
$db2_set = 1;
$db_count ++;
}
// check for correct database3 settings
$db_con3 = @mysql_pconnect ($mysql_host3, $mysql_user3, $mysql_password3);
if (!$db_con3) {
if($output == '1') {
echo "<br />
<p><span class='red'> Mysql server for database 3 is not available! <br /></font></p>\n
<p><span class='blue sml'> Trying to reconnect to database 3 . . .<br /> Cannot connect to this database.<br /></p>\n
<p><span class='red cntr'> Never mind if you don't need it.<br /></p>
";
}
} else {
$success3 = @mysql_select_db ($database3, $db_con3);
if (!$success3) {
if($output == '1') {
echo "<p><span class='red cntr'><br /> Cannot choose database 3.<br /></p>
<br />
";
}
}
}
if ($db_con3 && $success3) {
if($output == '1') {
echo "<p><span class='green cntr'>- Database 3 settings are okay.</p>
";
}
// check for installed tables
$tables3 = mysql_query("select * from ".$mysql_table_prefix3."addurl");
if (mysql_error()) {
if($output == '1') {
echo "<p><span class='red cntr'><br /> Tables are not installed for database 3<br /></p>
<br />
";
}
} else {
if ($output == '1') {
echo "<p><span class='green cntr'> Tables are installed for database 3</p>
";
}
}
}
if ($db_con3 && $success3 && $tables3) {
$db3_set = 1;
$db_count ++;
}
// check for correct database4 settings
$db_con4 = @mysql_pconnect ($mysql_host4, $mysql_user4, $mysql_password4);
if (!$db_con4) {
if($output == '1') {
echo "<br />
<p><span class='red'> Mysql server for database 4 is not available! <br /></font></p>\n
<p><span class='blue sml'> Trying to reconnect to database 4 . . .<br /> Cannot connect to this database.<br /></p>\n
<p><span class='red cntr'> Never mind if you don't need it.<br /></p>
";
}
} else {
$success4 = @mysql_select_db ($database4, $db_con4);
if (!$success4) {
if($output == '1') {
echo "<p><span class='red cntr'><br /> Cannot choose database 4.<br /></p>
<br />
";
}
}
}
if ($db_con4 && $success4) {
if($output == '1') {
echo "<p><span class='green cntr'>- Database 4 settings are okay.</p>
";
}
// check for installed tables
$tables4 = mysql_query("select * from ".$mysql_table_prefix4."addurl");
if (mysql_error()) {
if($output == '1') {
echo "<p><span class='red cntr'><br /> Tables are not installed for database 4<br /></p>
<br />
";
}
} else {
if ($output == '1') {
echo "<p><span class='green cntr'> Tables are installed for database 4</p>
";
}
}
}
if ($db_con4 && $success4 && $tables4) {
$db4_set = 1;
$db_count ++;
}
// check for correct database5 settings
$db_con5 = @mysql_pconnect ($mysql_host5, $mysql_user5, $mysql_password5);
if (!$db_con5) {
if($output == '1') {
echo "<br />
<p><span class='red'> Mysql server for database 5 is not available! <br /></font></p>\n
<p><span class='blue sml'> Trying to reconnect to database 5 . . .<br /> Cannot connect to this database.<br /></p>\n
<p><span class='red cntr'> Never mind if you don't need it.<br /></p>
";
}
} else {
$success5 = @mysql_select_db ($database5, $db_con5);
if (!$success5) {
if($output == '1') {
echo "<p><span class='red cntr'><br /> Cannot choose database 5.<br /></p>
<br />
";
}
}
}
if ($db_con5 && $success5) {
if($output == '1') {
echo "<p><span class='green cntr'>- Database 5 settings are okay.</p>
";
}
// check for installed tables
$tables5 = mysql_query("select * from ".$mysql_table_prefix5."addurl");
if (mysql_error()) {
if($output == '1') {
echo "<p><span class='red cntr'><br /> Tables are not installed for database 5<br /></p>
<br />
";
}
} else {
if ($output == '1') {
echo "<p><span class='green cntr'> Tables are installed for database 5</p>
";
}
}
}
if ($db_con5 && $success5 && $tables5) {
$db5_set = 1;
$db_count ++;
}
if ($dba_act =="") {
$dba_act= '1';
}
if ($dbu_act =="") {
$dbu_act= '1';
}
if ($dbs_act =="") {
$dbs_act= '1';
}
// write all to database.php
if (!is_writable("../settings/database.php")) {
print "Database file is not writable, chmod 666 .../admin/db_config.php under *nix systems";
} else {
$fhandle=fopen("../settings/database.php","wb");
fwrite($fhandle,"<?php \n");
fwrite($fhandle,"/************************************************\n ");
fwrite($fhandle,"Sphider-plus version $plus_nr Database configuration file.\n");
fwrite($fhandle,"\n > > > DO NOT EDIT THIS FILE. < < < \n\n");
fwrite($fhandle,"Any changes must be done by Admin's database settings. \n");
fwrite($fhandle,"*************************************************/");
fwrite($fhandle,"\n\n\n\n/******************************* Check for forbidden direct access ************************************/\n\n");
fwrite($fhandle," if (!defined('_SECURE')) die (\"No direct access to database file\");");
fwrite($fhandle, "\n\n\n\n// Count of successfully created databases\n");
fwrite($fhandle,"$"."db_count = \"".$db_count."\";");
fwrite($fhandle, "\n\n// Currently activated Admin database\n");
fwrite($fhandle,"$"."dba_act = \"".$dba_act."\";");
fwrite($fhandle, "\n\n// Currently activated Search User database\n");
fwrite($fhandle,"$"."dbu_act = \"".$dbu_act."\";");
fwrite($fhandle, "\n\n// Currently activated Suggest URL User database\n");
fwrite($fhandle,"$"."dbs_act = \"".$dbs_act."\";");
fwrite($fhandle, "\n\n// Activated databases that should deliver search results\n");
fwrite($fhandle,"$"."db1_slv = \"".$_db1_slv."\";\n");
fwrite($fhandle,"$"."db2_slv = \"".$_db2_slv."\";\n");
fwrite($fhandle,"$"."db3_slv = \"".$_db3_slv."\";\n");
fwrite($fhandle,"$"."db4_slv = \"".$_db4_slv."\";\n");
fwrite($fhandle,"$"."db5_slv = \"".$_db5_slv."\";\n");
fwrite($fhandle,"\n\n\n/*********************** \nDatabase 1 settings\n***********************/");
fwrite($fhandle, "\n\n// Name of database\n");
fwrite($fhandle,"$"."database1 = '$database1';");
fwrite($fhandle, "\n\n// MySQL User\n");
fwrite($fhandle,"$"."mysql_user1 = '$mysql_user1';");
fwrite($fhandle, "\n\n// MySQL Password\n");
fwrite($fhandle,"$"."mysql_password1 = '$mysql_password1';");
fwrite($fhandle, "\n\n// MySQL Host\n");
fwrite($fhandle,"$"."mysql_host1 = '$mysql_host1';");
fwrite($fhandle, "\n\n// Prefix for tables\n");
fwrite($fhandle,"$"."mysql_table_prefix1 = '$mysql_table_prefix1';");
fwrite($fhandle, "\n\n// Status of database\n");
fwrite($fhandle,"$"."db1_set = '$db1_set';");
fwrite($fhandle, "\n\n// Activation status\n");
fwrite($fhandle,"$"."db1_act = '$db1_act';");
fwrite($fhandle,"\n\n\n/*********************** \nDatabase 2 settings\n***********************/");
fwrite($fhandle, "\n\n// Name of database\n");
fwrite($fhandle,"$"."database2 = '$database2';");
fwrite($fhandle, "\n\n// MySQL User\n");
fwrite($fhandle,"$"."mysql_user2 = '$mysql_user2';");
fwrite($fhandle, "\n\n// MySQL Password\n");
fwrite($fhandle,"$"."mysql_password2 = '$mysql_password2';");
fwrite($fhandle, "\n\n// MySQL Host\n");
fwrite($fhandle,"$"."mysql_host2 = '$mysql_host2';");
fwrite($fhandle, "\n\n// Prefix for tables\n");
fwrite($fhandle,"$"."mysql_table_prefix2 = '$mysql_table_prefix2';");
fwrite($fhandle, "\n\n// Status of database\n");
fwrite($fhandle,"$"."db2_set = '$db2_set';");
fwrite($fhandle, "\n\n// Activation status\n");
fwrite($fhandle,"$"."db2_act = '$db2_act';");
fwrite($fhandle,"\n\n\n/*********************** \nDatabase 3 settings\n***********************/");
fwrite($fhandle, "\n\n// Name of database\n");
fwrite($fhandle,"$"."database3 = '$database3';");
fwrite($fhandle, "\n\n// MySQL User\n");
fwrite($fhandle,"$"."mysql_user3 = '$mysql_user3';");
fwrite($fhandle, "\n\n// MySQL Password\n");
fwrite($fhandle,"$"."mysql_password3 = '$mysql_password3';");
fwrite($fhandle, "\n\n// MySQL Host\n");
fwrite($fhandle,"$"."mysql_host3 = '$mysql_host3';");
fwrite($fhandle, "\n\n// Prefix for tables\n");
fwrite($fhandle,"$"."mysql_table_prefix3 = '$mysql_table_prefix3';");
fwrite($fhandle, "\n\n// Status of database\n");
fwrite($fhandle,"$"."db3_set = '$db3_set';");
fwrite($fhandle, "\n\n// Activation status\n");
fwrite($fhandle,"$"."db3_act = '$db3_act';");
fwrite($fhandle,"\n\n\n/*********************** \nDatabase 4 settings\n***********************/");
fwrite($fhandle, "\n\n// Name of database\n");
fwrite($fhandle,"$"."database4 = '$database4';");
fwrite($fhandle, "\n\n// MySQL User\n");
fwrite($fhandle,"$"."mysql_user4 = '$mysql_user4';");
fwrite($fhandle, "\n\n// MySQL Password\n");
fwrite($fhandle,"$"."mysql_password4 = '$mysql_password4';");
fwrite($fhandle, "\n\n// MySQL Host\n");
fwrite($fhandle,"$"."mysql_host4 = '$mysql_host4';");
fwrite($fhandle, "\n\n// Prefix for tables\n");
fwrite($fhandle,"$"."mysql_table_prefix4 = '$mysql_table_prefix4';");
fwrite($fhandle, "\n\n// Status of database\n");
fwrite($fhandle,"$"."db4_set = '$db4_set';");
fwrite($fhandle, "\n\n// Activation status\n");
fwrite($fhandle,"$"."db4_act = '$db4_act';");
fwrite($fhandle,"\n\n\n/*********************** \nDatabase 5 settings\n***********************/");
fwrite($fhandle, "\n\n// Name of database\n");
fwrite($fhandle,"$"."database5 = '$database5';");
fwrite($fhandle, "\n\n// MySQL User\n");
fwrite($fhandle,"$"."mysql_user5 = '$mysql_user5';");
fwrite($fhandle, "\n\n// MySQL Password\n");
fwrite($fhandle,"$"."mysql_password5 = '$mysql_password5';");
fwrite($fhandle, "\n\n// MySQL Host\n");
fwrite($fhandle,"$"."mysql_host5 = '$mysql_host5';");
fwrite($fhandle, "\n\n// Prefix for tables\n");
fwrite($fhandle,"$"."mysql_table_prefix5 = '$mysql_table_prefix5';");
fwrite($fhandle, "\n\n// Status of database\n");
fwrite($fhandle,"$"."db5_set = '$db5_set';");
fwrite($fhandle, "\n\n// Activation status\n");
fwrite($fhandle,"$"."db5_act = '$db5_act';");
fwrite($fhandle,"\n\n?>");
fclose($fhandle);
}
if($output == '1') {
echo "
</blockquote>
</td>
</tr>
</table>
";
}
}
?>