<?php
function xml_html($in) {
$in = str_replace('<', '<', $in);
$in = str_replace('>', '>', $in);
$in = str_replace('&', '&', $in);
//$in = str_replace( """, '"',$in);
return $in;
}
# ---
function html_xml($in) {
$in = str_replace('&', '&', $in);
$in = str_replace('<', '<', $in);
$in = str_replace('>', '>', $in);
$in = str_replace('"', """, $in);
return $in;
}
# ---
function del_simb ($in) {
$x = array ('/', '?', '=', '&', '.');
foreach ($x as $item)
{$in = str_replace($item, '', $in);}
return $in;
}
# ---
//function time_en_to_ru ($in, $lang) {
function time_en_to_ru ($in, $lang, $vhod, $vihod) {
//$lll=$lang;
$out['en']= array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Des',
'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun', );
//Monday Tuesday Wednesday Thursday Friday Saturday Sunday
$out['ru']=array('Янв', 'Фев', 'ÐаÑ', 'ÐпÑ', 'Ðай', 'ÐÑн', 'ÐÑл', 'Ðвг', 'Сен', 'ÐкÑ', 'ÐоÑ', 'Ðек',
'Ðнд', 'ÐÑÑ', 'СÑд', 'ЧÑв', 'ÐÑн', 'СбÑ', 'ÐÑк', );
for ($i=count($lang["$vhod"][63])-1; $i>=0; $i--)
{$in=str_replace($lang["$vhod"][63][$i], $lang["$vihod"][63][$i], $in); }
return $in;
}
# ---
function UTF8toCP1251($str){ // by SiMM, $table from http://ru.wikipedia.org/wiki/CP1251
static $table = array("\xD0\x81" => "\xA8", // Ð
"\xD1\x91" => "\xB8", // Ñ
// ÑкÑаинÑкие ÑимволÑ
"\xD0\x8E" => "\xA1", // Р(У)
"\xD1\x9E" => "\xA2", // Ñ (Ñ)
"\xD0\x84" => "\xAA", // Ð (Ð)
"\xD0\x87" => "\xAF", // Ð (I..)
"\xD0\x86" => "\xB2", // I (I)
"\xD1\x96" => "\xB3", // i (i)
"\xD1\x94" => "\xBA", // Ñ (Ñ)
"\xD1\x97" => "\xBF", // Ñ (i..)
// ÑÑваÑÑкие ÑимволÑ
"\xD3\x90" => "\x8C", // Ӑ (Ð)
"\xD3\x96" => "\x8D", // Ӗ (Ð)
"\xD2\xAA" => "\x8E", // Ҫ (С)
"\xD3\xB2" => "\x8F", // Ӳ (У)
"\xD3\x91" => "\x9C", // ӑ (а)
"\xD3\x97" => "\x9D", // ӗ (е)
"\xD2\xAB" => "\x9E", // ҫ (Ñ)
"\xD3\xB3" => "\x9F", // ӳ (Ñ)
);
return preg_replace('#([\xD0-\xD1])([\x80-\xBF])#se',
'isset($table["$0"]) ? $table["$0"] :
chr(ord("$2")+("$1" == "\xD0" ? 0x30 : 0x70))
',
$str
);
}
# ---
function bukvaru($text,$kak) # пеÑÐ²Ð°Ñ Ð±Ñква ввеÑÑ
{
$rutop= array('Ð','Ð','Ð','Ð','Ð','Ð','Ð','Ð','Ð','Ð','Ð','Ð','Ð','Ð','Ð','Ð','Ð','Ð ','С','Т','У','Ф','Ð¥','Ц','Ч','Ш','Щ','Ъ','Ы','Ь','Ð','Ю','Я');
$rubot=array('а','б','в','г','д','е','Ñ','ж','з','и','й','к','л','м','н','о','п','Ñ','Ñ','Ñ','Ñ','Ñ','Ñ
','Ñ','Ñ','Ñ','Ñ','Ñ','Ñ','Ñ','Ñ','Ñ','Ñ');
$temp="";
if($kak=="rus")
{
$out = false;
for ($i = count ($rutop)-1; $i>0; $i--)
{
if (strpos($text, $rubot[$i])==true || strpos($text, $rutop[$i])==true)
{$out=true; break;}
}
$text = $out;
}
if($kak=="first")
{
for ($i = count ($rutop)-1; $i>0; $i--)
{$text=str_replace($rubot[$i], $rutop[$i], $text); }
}
if($kak=="firstdown")
{
//$temp_simv=$text[0].$text[1];
// print $text[0].$text[1];
//$text[0]=strtr($text[0],$rutop,$rubot);
for ($i = count ($rutop)-1; $i>0; $i--)
{$text=str_replace($rutop[$i], $rubot[$i], $text); }
}
if($kak=="all")
{
foreach(explode(" ",$text) as $item)
{$item[0]=strtr($item[0],$rubot,$rutop); $temp.=$item." ";}
$temp=str_replace("Фио", "(ФÐÐ)", $temp);
return trim($temp);
}
if($kak=="bot")
{
$text[0]=strtr($text[0],$rutop,$rubot);
}
if($kak=="botton")
{
//$text=strtolower($text);
for ($i = count ($rutop)-1; $i>0; $i--)
{$text=str_replace($rutop[$i], $rubot[$i], $text); }
}
if($kak=="top")
{
$text = strtr($text,$rubot,$rutop);
}
return $text;
}
# --- CLOUD
function set_cloud ($xml, $cloud_size) {
$temp = $xml->xpath('/articles/page/@key');
$i=count($temp);
$max =1;
$temp_tags = array ();
for ($x=0; $x<$i; $x++)
{
if(isset($temp[$x]))
{
foreach (explode (';', $temp[$x]) as $item)
{
if ($item != '')
{
$tempik = explode ('-', $item);
if (array_key_exists($tempik [0], $temp_tags)==false) {$temp_tags [$tempik [0]]=0;}
$temp_tags [$tempik [0]] ++;
$temp_text [$tempik [0]] = $tempik [1];
if ($max < $temp_tags [$tempik [0]]) {$max = $temp_tags [$tempik [0]];}
}
}
}
}
arsort ($temp_tags);
$temp_tags_size = array_chunk($temp_tags, $cloud_size, TRUE);
$f_new = fopen('data/cloud.txt', 'w+');
$f_new2 = fopen('data/cloud_link.txt', 'w+');
$temp_for_checked='';
foreach ($temp_text as $key=>$item)
{
if(isset($temp_tags_size [0][$key]))
{
//$temp = dechex(ceil((100-($temp_tags[$key])/($max/90))*2.5));
$tempik = ceil(($temp_tags[$key])/$max*2.5*2); // size
fwrite($f_new, '<a href=\'tags_'.$key.'_0.html\'><font size='.$tempik.' color=#'.($tempik*10*2-3).($tempik*10*2-3).($tempik*10*2-3).'>'.$item.'</font></a> '."\r\n");
fwrite($f_new2, 'tags_'.$key.'_0.html|'.$item."\r\n");
$temp_for_checked.=$key.'|'.$item."|<input name=\"sendtag_".$key."\" type=\"checkbox\" value=\"".$key."\">"."\r\n";
}
}//color=#'.$temp.$temp.$temp.'
fclose($f_new);
fclose($f_new2);
if (file_exists('./data/checked.txt')==false) # еÑли Ñайла checked Ð½ÐµÑ (Ð´Ð»Ñ Ð¿ÐµÑеÑ
ода ÑÐ¾Ñ ÑÑаÑÑÑ
веÑÑий)
{
$f_new2 = fopen('data/checked.txt', 'w+');
fwrite($f_new2, $temp_for_checked);
fclose($f_new2);
}
return 0;
}
# --- ARCHIVE
function set_archive ($xml) {
$temp = $xml->xpath('/articles/page/data');
$i=count($temp);
$temp_tags = array ();
echo '<pre>';
//print_r ($temp);
echo '</pre>';
foreach ($temp as $item)
{
if(isset($item))
{
$temp_pub = (time()>=strtotime($item))? true:false;
if ($temp_pub==true)
{
$tempik = explode (' ', $item);
$temp_tags [$tempik [2].'-'.$tempik [3]] = $tempik [2].' '.$tempik [3];
}
}
}
$f_new = fopen('data/archive.txt', 'w+');
foreach ($temp_tags as $key=>$item)
{
if ($key != '_')
{fwrite($f_new, '<li><a href=\'archive_'.$key.'_0.html\'>'.$item.'</a></li> '."\r\n");}
}
fclose($f_new);
return 0;
}
# --- ÐÐТÐÐÐÐ ÐÐ
// пока не ÑабоÑаеÑ
function set_category ($xml) {
$temp = $xml->xpath('/articles/page/@key|/articles/page/data');
$i=count($temp);
$temp_tags = array ();
echo '<pre>';
//print_r ($temp);
echo '</pre>';
foreach ($temp as $item)
{
if(isset($item))
{
$temp_pub = (time()>=strtotime($item))? true:false;
if ($temp_pub==true)
{
}
}
}
return 0;
}
# --- ÐÐРТÐÐÐÐ Ð´Ð»Ñ WISYWIG ---
function get_imagelist_js ($temp)
{
$tempik='';
$dir = opendir ($temp);
while ($file = readdir ($dir))
{
if($file!="." && $file!=".." && $file!="")
{
$tempik.="'./".$temp.$file."':\"".$file."\",";
}
}
closedir ($dir);
return $tempik;
}
# --- WISYWIG ---
function get_wysiwyg ()
{
$temp=get_imagelist_js('./images/');
$tempik="<script type=\"text/javascript\">\r\n";
$fm=fopen('./css/nicEdit.js', 'r');
$tempik.= fread ($fm, filesize ('./css/nicEdit.js'));
fclose ($fm);
$tempik.="\r\n bkLib.onDomLoaded(nicEditors.allTextAreas)\r\n";
$tempik.="</script>";
$tempik= str_replace("â¡imagelist_jsâ¡", $temp, $tempik);
return $tempik;
}
# --- PING ---
function send_ping ($ping_urls, $page_url, $page_name)
{
set_time_limit(0); $out='';
foreach ($ping_urls as $item)
{
$item=str_replace("http://","",$item);
$item=str_replace("www.","",$item);
$parse_url = explode('/', $item);
$fp = @fsockopen($item, 80, $errno, $errstr, 10);
if(!$fp){ $out.="Ping - ".$item."\r\n<br>";}
else
{
$ping_b = '<?xml version="1.0" encoding="UTF-8"?>
<methodCall>
<methodName>weblogUpdates.ping</methodName>
<params>
<param>
<value>'.$page_name.'</value>
</param>
<param>
<value>http://'.$page_url.'</value>
</param>
</params>
</methodCall>';
$ping_a = "POST /RPC2 HTTP/1.1\r\n
Host: ".$parse_url[0]."\r\n
Content-Type: text/xml\r\n
Accept-Charset: utf-8;q=0.6, *;q=0.1\r\n
Content-length: ".strlen($ping_b)."\r\n
Referer: http://".$_SERVER['SERVER_NAME']."\r\n
User-Agent: Mozilla/5.0 (compatible; MSIE 6.0; Windows 98)\r\n";
$out.="Connect - ".$item."\r\n<br>";
@fputs ($ping_a, $fp);
@fputs ($ping_b, $fp);
fclose($fp);
}
}
return $out;
}
# --- CLOUD to TAGs checked ---
function get_cloud_to_tags ($cloud, $tags_str)
{
$tags= explode(';', $tags_str);
foreach ($tags as $item)
{
$item = trim($item);
if ($item!='')
{
$tempik = explode ('-', $item);
$cloud = str_replace ('name="sendtag_'.$tempik[0].'"', 'name="sendtag_'.$tempik[0].'" checked ', $cloud);
}
}
return $cloud;
}
# --- LINK to TAGS ---
function link_tags ($text, $tags)
{ // ÐÐ ÐСÐÐÐЬÐУÐТСЯ !!!
foreach ($tags as $key=>$item)
{
$item = trim($item);
$text=str_replace(' '.$item.' ',' <a href='.$key.'>'.$item.'</a> ' ,$text);
$text=str_replace(' '.$item.'.',' <a href='.$key.'>'.$item.'</a>.' ,$text);
$text=str_replace(' '.$item.',',' <a href='.$key.'>'.$item.'</a>,' ,$text);
$item = bukvaru($item, 'botton');
$text=str_replace(' '.$item.' ',' <a href='.$key.'>'.$item.'</a> ' ,$text);
$text=str_replace(' '.$item.'.',' <a href='.$key.'>'.$item.'</a>.' ,$text);
$text=str_replace(' '.$item.',',' <a href='.$key.'>'.$item.'</a>,' ,$text);
}
return $text;
}
# --- get QUERY link ---
function get_query_link ($ling, $sesia, $translit_popular, &$keywords)
{
$out='';//print $_SERVER ['REQUEST_URI'];
$temp_url = explode('/', ' '.$_SERVER ['REQUEST_URI']);
$name_file = $temp_url[count($temp_url)-1]; //print '='.$name_file.'=';
if($name_file=='index.php' || $name_file=='') {$name_file='index.html';}
if (file_exists ('data/query/'.$name_file) && $name_file!='')
{
$out='<h2>'.$ling[68].'</h2> ';
foreach (file('data/query/'.$name_file) as $item)
{
$keywords.= trim(strip_tags ($item)).', ';
$temp2 = explode ("_0.htm'>", $item); //$temp3='';
$temp2[0] = str_replace("<i class=dark><a href='",'' ,$temp2[0]);
if($translit_popular){$temp3=lat_ru($temp2[0], 'rl', 'f');}
else {$temp3=$temp2[0];}
$out.="<i class=dark><a href='".$temp3."_0.htm'>".$temp2[1];
if($sesia)
{
$out.="<a title='Delete: ".strip_tags($item)."' href='index.php?event=query_del&file=./data/query/".$name_file."&zapros=".strip_tags($item)."'>[X]</a> ";
}
}
}
foreach ($temp_url as $key=>$item)
{
$item = trim($item);
}
return $out;
}
# --- del STOP slova ---
function del_stop_slova ($textr,$slova)
{print $textr.'<br>';
$text = explode ('-', $textr);
$text2=''; //echo '<pre>';print_r($text);echo '</pre>';
foreach ($text as $item)
{
$stop=false;
foreach($slova as $item2)
{
if (trim($item)==trim($item2))
{$stop=true;}
}
if ($stop!=true){$text2.=$item.' ';}
}
$text2=str_replace(' ', '-' ,trim($text2));
return trim($text2);
}
# --- get PAGE core ---
function get_page_core($temp_zapros, $text, $sentence_in_query)
{
$out='';
$temp_str = array();
$text=str_replace('.<br>', '. ', $text);
$text=str_replace(".\r\n", '. ', $text);
foreach (explode ('. ', $text) as $item)
{
foreach ($temp_zapros as $item2)
{
if (strpos ($item, $item2)!==false)
{
if(!isset($temp_str[$item])){$temp_str[$item]=0;}
$temp_str[$item]++;
}
}
} //echo '<pre>';print_r($temp_str);echo '</pre>';
arsort($temp_str);
$temp_str=array_keys ($temp_str);
$page_mass2 = array_chunk($temp_str, $sentence_in_query);
// to out
foreach ($page_mass2[0] as $item)
{
foreach ($temp_zapros as $item2)
{
$item=str_replace(' '.$item2, ' <b>'.$item2.'</b>' ,$item);
$item2 = bukvaru($item2, 'botton');
$item=str_replace(' '.$item2, ' <b>'.$item2.'</b>' ,$item);
}
$out.=$item."...<br>\r\n";
}
return $out;
}
# --- LINKATOR ---------
# --- LINKATOR ---------
# --- LINKATOR ---------
function linkator ($server, $prefiks, $ling, $listsize, $cloud_link_mass, $telo)
{//$timew = microtime();
$temp_znak = array (' ', ',', '.');
# -- пеÑелинков по названиÑм ÑÑаÑей
foreach (file('./data/listpages.txt') as $item)
{
$temp= explode ('|', trim($item));
foreach ($temp_znak as $item2)
{$telo=str_replace(' '.$temp[1].$item2,' <a href='.$server.''.$prefiks.''.$temp[0].'.html>'.$temp[1].'</a>'.$item2, $telo);
}
}
# -- пеÑелинков по меÑкам-Ñегам
foreach ($cloud_link_mass as $key=>$item)
{
foreach ($temp_znak as $item2)
{
$telo=str_replace(' '.$item.$item2,' <a href='.$key.'>'.$item.'</a>'.$item2, $telo);
}
}
# -- пеÑелинковка по ÑказаннÑм клÑÑевÑм ÑÑазам
foreach (file('./data/listlinks.txt') as $item)
{
$temp= explode ('|', trim($item));
$tempik = count ($temp);
for ($z=1; $z<$tempik; $z++)
{
if (strpos ($temp[0], 'http://')!==false)
{
foreach ($temp_znak as $item2)
{
$telo=str_replace(' '.$temp[$z].$item2,' <a href='.$temp[0].'>'.$temp[$z].'</a>'.$item2, $telo);
//$telo=str_replace(' '.bukvaru($temp[$z], 'botton').$item2,' <a href='.$temp[0].'>'.bukvaru($temp[$z], 'botton').'</a>'.$item2, $telo);
}
}
else
{
foreach ($temp_znak as $item2)
{
$telo=str_replace(' '.$temp[$z].$item2,' <a href='.$server.''.$prefiks.''.$temp[0].'.html>'.$temp[$z].'</a>'.$item2, $telo);
//$telo=str_replace(' '.bukvaru($temp[$z], 'botton').$item2,' <a href='.$server.''.$prefiks.''.$temp[0].'.html>'.bukvaru($temp[$z], 'botton').'</a>'.$item2, $telo);
}
}
}
}
return $telo;
}
#==============================================================================
function lat_ru($text,$napr,$f_or_d) # пеÑевод лаÑиниÑÑ Ð² киÑилиÑÑ
{
$delbukva = array('~','!','@','$','%','^','&','*','(',')','=','+','\\','|','\"','\'','â',
';',':','?','`','.','_',',','"',"'",chr("35"),'q','Q','[',']','{','}','/','x','X','<','>');#“"
$ruall = array(
'Ч','Ñ','Ш','Ñ','Щ','Ñ','Ñ','Ñ',
'Ы','Ñ','Ñ','Ñ','Ð','Ñ','Ю','Ñ','Я','Ñ',
'Ð','а','Ð','б','Ð','в','Ð','г','Ð','д','Ð','е','Ð','Ñ',
'Ð','ж','Ð','з','Ð','и','Ð','й','Ð','к','Ð','л','Ð','м',
'Ð','н','Ð','о','Ð','п','Ð ','Ñ','С','Ñ','Т','Ñ','У','Ñ',
'Ф','Ñ','Ð¥','Ñ
','Ц','Ñ',' ');
$enall = array(
'CH','ch','SH','sh','W','w','_','_',
'QI','qi','_','_','YE','ye','YU','yu','YA','ya',
'A','a','B','b','V','v','G','g','D','d','E','e','E','e',
'J','j','Z','z','I','i','Y','y','K','k','L','l','M','m',
'N','n','O','o','P','p','R','r','S','s','T','t','U','u',
'F','f','H','h','C','c','-');
if($napr=="lr")
{ $text=str_replace(".html", "", $text);
if(stristr($text,"-wiki")==true)# ваÑÐ¸Ð°Ð½Ñ Ð´Ð»Ñ Ð½ÐµÑÑанÑлиÑеÑиÑованиÑ
{
if($f_or_d=="d"){$text=strtoupper($text);}
if($f_or_d=="f"){$text=ucfirst($text);}
return $text;
}
if($f_or_d=="d")
{$text=strtoupper($text);
$text=str_replace("*", "", $text);
$text= str_replace($enall, $ruall, $text);
$text= str_replace("Ñ", "Ь", $text);
$text=strtoupper($text);}
if($f_or_d=="f")
{
$text= str_replace($enall, $ruall, $text);
//$text=bukvaru($text,"top");
}
}
if($napr=="rl")
{
foreach($delbukva as $item) {$text=str_replace($item, "", $text);} # ÑдалÑем ÑимволÑ
if($f_or_d=="d")
{#$text=strtoupper($text);
$text=str_replace("*", "", $text);
$text=str_replace("Ъ", "Ñ", $text);
$text=str_replace("Ь", "Ñ", $text);
$text=str_replace("Ы", "Ñ", $text);
$text= str_replace($ruall, $enall, $text);
$text=strtoupper($text);}
if($f_or_d=="f")
{
$text=str_replace(" ", "-", $text);
$text=str_replace("Ъ", "Ñ", $text);
$text=str_replace("Ь", "Ñ", $text);
$text=str_replace("Ы", "Ñ", $text);
$text= str_replace($ruall, $enall, $text);//$text=strtolower($text);
}
}
return $text;
}
# ---
?>