//------------------------------------------------------------------------------
//Version 2.19 Update: 15.02.2007
//
// Часто задаваемые вопросы: http://www.clx.ru/help/publisher/pvsfaq.html
//
// Пример использования
//
// Пример 1
//
// define('CLX_SITE',"spbgangsters.ru");
// require_once($_SERVER['DOCUMENT_ROOT'].'/ed5b47f0af/clx2.php');
//
//
//
// где spbgangsters.ru - ваш домен сайта без www и http
// ed5b47f0af - ваша служебная папка
//
// Пример 2 (с жестким указанием откуда брать адрес текущей страницы)
// define('CLX_SITE',"spbgangsters.ru");
// define('CLX_PAGE',$_SERVER['REQUEST_URI']);
// require_once($_SERVER['DOCUMENT_ROOT'].'/ed5b47f0af/clx2.php');
//
//------------------------------------------------------------------------------
class CLX
{
var $password="1851ac8af59c41b26163d54fc3143d14"; //Пароль (единый на один аккаунт), используется для передачи данных с серверов CLX
var $key="ed5b47f0af";
var $userdir=""; //Нет необходимости изменять. Переопределение стандартной папки для кэширования
// Служебные переменные (для работы их изменение не требуется)
var $file="";
var $n_af="";
var $page="";
var $error="";
var $text="";
function CLX()
{
if (defined("CLX_SSI")) $this->nogiper=1; else $this->nogiper=0;
$this->Set_Site();
$this->IsCLX();
$this->GetFunction();
}
function GetFunction()
{
if (defined("CLX_disfunction"))
{
if (function_exists(CLX_disfunction))
{
$this->disfunction=CLX_disfunction;
}
}
}
function IsCLX()
{
if (defined("CLX_SHOWALL")) {$this->clxserver=1; return;}
$s=substr(md5($this->key),1,8);
if (eregi($s,$_SERVER["HTTP_USER_AGENT"])) $this->clxserver=1; else $this->clxserver=0;
}
function CLX_GetDomain($s)
{
$s=strtolower($s);
$s=ereg_replace("^http://www\.","",$s);
$s=ereg_replace("^http://","",$s);
$s=str_replace('.','-',$s);
$s=preg_replace('/[^a-z0-9\-_]/',"",$s);
return $s;
}
function CLX_Optbody()
{
$search = array ('@@si','@@si','@
]*?>.*?@si','@@si','@]*?>.*?@si','@@si','@]*?>.*?@si','@@si','@]*?>.*?@si');
$this->text2=preg_replace_callback($search,create_function('$matches','return str_repeat(" ",strlen($matches[0]));'),$this->text);
$search = array ('@<.*?>@si');
$this->text2=preg_replace_callback($search,create_function('$matches','return str_repeat(" ",strlen($matches[0]));'),$this->text2);
}
function CLX_SlipElement($key,$ar)
{
@$br=$this->cod[r][_br];
if ($br=="") $br=" ";
return @implode($br,$ar);
}
function Set_Dir($param)
{
$this->userdir=$param;
}
function Set_Site()
{
if (defined("CLX_SITE"))
{
$this->n_af=$this->CLX_GetDomain(CLX_SITE);
}
}
function Set_Page()
{
if (defined("CLX_PAGE"))
{
$this->page=CLX_PAGE;
$this->frompage="const";
}
else
{
if (is_array($this->cod['page']['REDIRECT_URL']))
{
if (@in_array($_SERVER['REDIRECT_URL'],$this->cod[page]['REDIRECT_URL']) and ($_SERVER['REDIRECT_URL']!=""))
{
$this->page=$_SERVER['REDIRECT_URL'];
$this->frompage="REDIRECT_URL";
}
}
if ($this->page=="")
{
$this->page=$_SERVER['REQUEST_URI'];
$this->frompage="REQUEST_URI";
}
}
}
function UpdateMD5Url($s)
{
$m=split('\?',trim($s));
if (count($m)>1)
{
$s2=$m[1];
$m2=split('\&',$s2);
if (count($m2)>0)
{
$max=count($m2);
for ($i=0;$i<$max;$i++)
{
$s3=$m2[$i];
$m3=split('=',$s3);
if (eregi("^[a-f0-9]{32}$",$m3[1]) )
{
unset($m2[$i]);
}
}
}
$s2=implode("&",$m2);
if ($s2!="") $s2="?".$s2;
$s=$m[0].$s2;
}
return $s;
}
function CreateLinkFile($file)
{
if ($this->userdir=="")
$this->file=$_SERVER['DOCUMENT_ROOT'].'/'.$this->key."/".$file;
else
$this->file=$this->userdir."/".$file;
}
function MySaveFile($cod)
{
$res=-1;
@$f=fopen($this->file,'w');
if ($f)
{
if (@fwrite($f,$cod,strlen($cod))=== FALSE)
{
}
else
$res=1;
@fclose($f);
}
return $res;
}
function MyReadFile()
{
$cod="";
$dir=dirname($this->file);
if (!is_writable($dir))
{
$this->error.=" Папка $dir не доступна на запись! Установленные права: ".substr(sprintf('%o', fileperms($dir)), -4).", необходимо 0777 ";
}
if (!is_writable($this->file)) $this->error.=" Файл $this->file Проверьте права на запись в этот файл. ";
@$f=fopen($this->file,'r');
if ($f)
{
@$cod=fread($f,filesize($this->file));
@fclose($f);
}
return $cod;
}
function CreateDefault()
{
$def="";
if ($this->clxserver!=1) $this->cod["_0"]="";
if (isset($this->cod["_0"]))
{
if ($this->cod["_0"]!="")
{
$def=$this->cod["_0"];
if ($this->nogiper>0) $R=0; else $R=1;
$Q=substr(md5($this->page),1,1);
if (isset($this->parsedArray["at"])) $W=1; else $W=0;
if (isset($this->parsedArray["link"])) $E=1; else $E=0;
$def=str_replace("Q",$Q,$def);
$def=str_replace("W",$W,$def);
$def=str_replace("E",$E,$def);
$def=str_replace("R",$R,$def);
if (!defined("CLX_SHOWALL"))
{
$a=$_SERVER;
$a[mypage]=$this->page;
$a[frompage]=$this->frompage;
$T=base64_encode(serialize($a));
}
else $T="";
$def=str_replace("T",$T,$def);
$this->cod["_0"]="";
}
}
return $def;
}
function ShowGipercod()
{
@$d=$this->cod[i][$this->page]["giper"];
if (is_array($d))
{
$this->CLX_Optbody();
foreach ($d as $k=>$v)
{
$k=preg_quote($k,"/");
preg_match_all("/$k/is",$this->text2,$r,PREG_OFFSET_CAPTURE);
if (isset($r[0][0][1])) $this->text=substr_replace($this->text,$v,$r[0][0][1],strlen($r[0][0][0]));
}
}
if (($this->clxserver==1) and ($this->nogiper==0) and (!defined("CLX_SHOWALL"))) $this->text="".$this->text."";
}
function ReplaceRcod($key,$lnk)
{
@$d=$this->cod[r][$this->page]["$key"];
$tmp="";
$max=count($d);
$d[$max]=$this->CreateDefault();
$def=$max;
$max++;
while ($max>0)
{
for ($i=0;$i$v)
{
$x=strlen(strip_tags($v));
if (($x<=$lnk[$i][1]+1) or ($lnk[$i][1]<=0))
{
if ($v!="") $ar[$i][]=$v;
unset($d[$k]);
break;
}
}
}
$max--;
}
$run=0;
foreach ($lnk as $k=>$v)
{
@$s=$lnk[$k][0];
if ($tmp!="") $tmp=$tmp." ";
if ($this->disfunction!="")
{
if (function_exists($this->disfunction))
{
$run=1;
}
}
if ($run==1)
{
$ss="\$tmp=$this->disfunction(\$ar[\$k],\$this->cod[r][_br]);";
eval($ss);
}
else
@$tmp=$this->CLX_SlipElement($key,$ar[$k]);
@$this->text=preg_replace("/$s/i",$tmp,$this->text,1);
}
if (@$d[$def]!="")
{
$def=$d[$def];
@$this->text.=$def;
}
}
function CLX_tags_match()
{
preg_match_all("{(]+)(.*?)>)}si", $this->text, $matches,PREG_SET_ORDER);
$this->parsedArray=Array();
foreach($matches as $vl)
{
preg_match_all("{maxlen=.?(\d*).?}si", $vl[3], $maxlen,PREG_SET_ORDER);
if (@$maxlen[0][1]>0) $max=trim($maxlen[0][1]); else $max="";
$this->parsedArray[$vl[2]][]=Array($vl[1],$max);
}
}
function CLXru_insertparam($s,$param)
{
$param=" ".trim($param);
$s=str_replace("?","_CLXVPS_",$s);
preg_match_all("/]*)(.*?)>(.*?)<\/a>/i", $s, $matches,PREG_SET_ORDER);
foreach($matches as $k=>$v)
{
$s2="$v[5]";
$s=str_replace($v[0],$s2,$s);
}
$s=str_replace("_CLXVPS_","?",$s);
return $s;
}
function ShowRcod()
{
if (is_array($this->parsedArray))
{
foreach($this->parsedArray as $k=>$v)
{
$this->ReplaceRcod($k,$v);
}
}
$this->ReplaceRcod("",array());
}
function ShowArticleCod()
{
$cod=$this->cod['at'][$this->page]['p'];
if ($cod=="") $cod=$this->cod['at'][0]['p'];
if ($this->error!="") $cod=$this->error.$cod;
if ((count($this->parsedArray[at])>0) and ($cod!=""))
{
$s=$this->parsedArray[at][0][0];
$this->text=str_replace($s,$cod,$this->text);
$k="cod['at'][$this->page]['k']."\">" ;
$d="cod['at'][$this->page]['d']."\">" ;
$t="".$this->cod['at'][$this->page]['t']."";
$this->text=eregi_replace("]+name=[|'|\"]keywords[|'|\"][^>]+content=[|'|\"]([^>]*)[|'|\"][^>]*>",$k,$this->text);
$this->text=eregi_replace("]+name=[|'|\"]description[|'|\"][^>]+content=[|'|\"]([^>]*)[|'|\"][^>]*>",$d,$this->text);
$this->text=eregi_replace(".*<[^>]*/[^>]*title[^>]*>",$t,$this->text);
}
}
function GetCod()
{
GLOBAL $_CLX_ARRAY;
$n_af=$this->n_af;
$this->CreateLinkFile("gldata_$n_af.cgi");
$this->cod=unserialize($this->MyReadFile());
if ($this->page=="") $this->Set_Page("");
if (defined("CLX_ARRAY"))
{
$_CLX_ARRAY=$this->cod[r][$this->page][link];
unset($this->cod[r][$this->page][link]);
}
}
function SavePost($a)
{
$res=-1;
@$n_af=$this->CLX_GetDomain($a["n_af"]);
@$this->key=str_replace(".","",$a["key"]);
@$this->key=str_replace("/","",$this->key);
@$this->CreateLinkFile("gldata_$n_af.cgi");
@$p=$a["pass"];
@$data=base64_decode($a["data"]);
@$md5=md5($this->key.$n_af.$this->password."_".$a["data"]);
if ($md5==$p)
{
$res=$this->MySaveFile($data);
}
echo("$res");
}
function SavePostImg($a)
{
$res=-1;
$n_af=$this->CLX_GetDomain($a[n_af]);
$img=eregi_replace("[^a-zA-Z0-9]","",$a[idir]);
$name=eregi_replace("[^a-zA-Z0-9]","",$a[name]);
$file=$_SERVER['DOCUMENT_ROOT'].'/'.$img."/".$name.".gif";
$p=$a[pass];
$md5=md5($this->key.$n_af.$this->password."_".$img."_".$a[data]."_".$name);
if ($md5==$p)
{
$data=base64_decode($a[data]);
if ($f=fopen($file,"wb"))
{
if (fwrite($f,$data)===FALSE);
else
{
$res=1;
}
fclose($f);
}
}
echo("$res");
}
}
function CLXru_link()
{
define('CLX_SSI',1);
$clx=new CLX();
$clx->GetCod();
$CLX_COD=$clx->cod[r][$clx->page][link];
$clx->parsedArray["link"]=array();
$CLX_COD[]=$clx->CreateDefault();
return $clx->CLX_SlipElement("r",$CLX_COD);
}
function CLXru_callback($buffer)
{
$clx = new CLX();
$clx->GetCod();
$clx->text=$buffer;
$clx->CLX_tags_match();
$clx->ShowGipercod();
//$clx->ShowArticlecod();
$clx->ShowRcod();
if ($clx->clxserver==0)
{
$clx->text=preg_replace('//i',"",$clx->text);
$clx->text=preg_replace('##i',"",$clx->text);
}
return $clx->text;
}
// Сохранение данных переданных с CLX сервера.
if (is_array($_POST))
{
if (((isset($_POST['data'])) or (isset($_POST['idir']))) and (strlen($_POST['pass'])==32) and ($_POST['n_af']!="") and isset($_POST['key']))
{
$clx = new CLX();
if (isset($_POST['idir']))
{
$clx->SavePOSTImg($_POST);
}
else
$clx->SavePOST($_POST);
exit();
}
}
if (defined("CLX_ARRAY"))
{
$_CLX_ARRAY=array();
$clx=new CLX();
$clx->GetCod();
}
if (!defined("CLX_OLD"))
{
if (defined("CLX_GZIP")) ob_start('ob_gzhandler');
ob_start("CLXru_callback");
}
?>