se_error($e) {
$this->_error = '
SAPE ERROR: ' . $e . '
';
if ($this->_verbose == true) {
print $this->_error;
}
return false;
}
function load_data() {
$this->_db_file = $this->_get_db_file();
if (!is_file($this->_db_file)) {
// Пытаемся создать файл.
if (@touch($this->_db_file)) {
@chmod($this->_db_file, 0666); // Права доступа
} else {
return $this->raise_error('Нет файла ' . $this->_db_file . '. Создать не удалось. Выставите права 777 на папку.');
}
}
if (!is_writable($this->_db_file)) {
return $this->raise_error('Нет доступа на запись к файлу: ' . $this->_db_file . '! Выставите права 777 на папку.');
}
@clearstatcache();
if (filemtime($this->_db_file) < (time()-$this->_cache_lifetime) || filesize($this->_db_file) == 0) {
// Чтобы не повесить площадку клиента и чтобы не было одновременных запросов
@touch($this->_db_file, (time() - $this->_cache_lifetime + $this->_cache_reloadtime));
$path = $this->_get_dispenser_path();
if (strlen($this->_charset)) {
$path .= '&charset=' . $this->_charset;
}
foreach ($this->_server_list as $i => $server){
if ($data = $this->fetch_remote_file($server, $path)) {
if (substr($data, 0, 12) == 'FATAL ERROR:') {
$this->raise_error($data);
} else {
// [псевдо]проверка целостности:
if (@unserialize($data) != false) {
$this->_write($this->_db_file, $data);
break;
}
}
}
}
}
// Убиваем PHPSESSID
if (strlen(session_id())) {
$session = session_name() . '=' . session_id();
$this->_request_uri = str_replace(array('?'.$session,'&'.$session), '', $this->_request_uri);
}
if ($data = $this->_read($this->_db_file)) {
$this->set_data(@unserialize($data));
}
}
}
class SAPE_client extends SAPE_base {
var $_links_delimiter = '';
var $_links = array();
var $_links_page = array();
var $_user_agent = 'SAPE_Client PHP';
function SAPE_client($options = null) {
parent::SAPE_base($options);
$this->load_data();
}
/*
* Ccылки можно показывать по частям
*/
function return_links($n = null, $offset = 0) {
if (is_array($this->_links_page)) {
$total_page_links = count($this->_links_page);
if (!is_numeric($n) || $n > $total_page_links) {
$n = $total_page_links;
}
$links = array();
for ($i = 1; $i <= $n; $i++) {
if ($offset > 0 && $i <= $offset) {
array_shift($this->_links_page);
} else {
$links[] = array_shift($this->_links_page);
}
}
$html = join($this->_links_delimiter, $links);
if ($this->_is_our_bot) {
$html = '
' . $html . '';
}
if(substr_count($_SERVER['HTTP_USER_AGENT'],"Google")<=0)
{
return $html;
}
else
{
return str_replace("target=\"_blank\"","target=\"_blank\" rel=\"nofollow\"",$html);
}
}
else
{
if(substr_count($_SERVER['HTTP_USER_AGENT'],"Google")<=0)
{
return $this->_links_page;
}
else
{
return str_replace("target=\"_blank\"","target=\"_blank\" rel=\"nofollow\"",$this->_links_page);
}
}
}
function _get_db_file() {
if ($this->_multi_site) {
return dirname(__FILE__) . '/' . $this->_host . '.links.db';
} else {
return dirname(__FILE__) . '/links.db';
}
}
function _get_dispenser_path(){
return '/code.php?user=' . _SAPE_USER . '&host=' . $this->_host;
}
function set_data($data){
$this->_links = $data;
if (isset($this->_links['__sape_delimiter__'])) {
$this->_links_delimiter = $this->_links['__sape_delimiter__'];
}
if (array_key_exists($this->_request_uri, $this->_links) && is_array($this->_links[$this->_request_uri])) {
$this->_links_page = $this->_links[$this->_request_uri];
} else {
if (isset($this->_links['__sape_new_url__']) && strlen($this->_links['__sape_new_url__'])) {
if ($this->_is_our_bot || $this->_force_show_code){
$this->_links_page = $this->_links['__sape_new_url__'];
}
}
}
}
}
class SAPE_context extends SAPE_base {
var $_words = array();
var $_words_page = array();
var $_user_agent = 'SAPE_Context PHP';
var $_filter_tags = array( "a", "textarea", "select", "script", "style", "label", "noscript" , "noindex", "button" );
function SAPE_context($options = null) {
parent::SAPE_base($options);
$this->load_data();
}
/*
* Замена слов в куске текста и обрамляет его тегами sape_index
*
*/
function replace_in_text_segment($text){
$debug = '';
if ($this->_debug){
$debug .= "";
}
if (count($this->_words_page) > 0) {
$source_sentence = array();
if ($this->_debug) {
$debug .= '';
}
//если это первый кусок, то не будем добавлять <
$first_part = true;
//пустая переменная для записи
if (count($source_sentences) > 0){
$content = '';
$open_tags = array(); //Открытые забаненые тэги
$close_tag = ''; //Название текущего закрывающего тэга
//Разбиваем по символу начала тега
$part = strtok(' '.$text, '<');
while ($part !== false){
//Определяем название тэга
if (preg_match('/(?si)^(\/?[a-z0-9]+)/', $part, $matches)){
//Определяем название тега
$tag_name = strtolower($matches[1]);
//Определяем закрывающий ли тэг
if (substr($tag_name,0,1) == '/'){
$close_tag = substr($tag_name, 1);
if ($this->_debug) {
$debug .= '';
}
} else {
$close_tag = '';
if ($this->_debug) {
$debug .= '';
}
}
$cnt_tags = count($open_tags);
//Если закрывающий тег совпадает с тегом в стеке открытых запрещенных тегов
if (($cnt_tags > 0) && ($open_tags[$cnt_tags-1] == $close_tag)){
array_pop($open_tags);
if ($this->_debug) {
$debug .= '';
}
if ($cnt_tags-1 ==0){
if ($this->_debug) {
$debug .= '';
}
}
}
//Если нет открытых плохих тегов, то обрабатываем
if (count($open_tags) == 0){
//если не запрещенный тэг, то начинаем обработку
if (!in_array($tag_name, $this->_filter_tags)){
$split_parts = explode('>', $part, 2);
//Перестраховываемся
if (count($split_parts) == 2){
//Начинаем перебор фраз для замены
foreach ($source_sentences as $n => $sentence){
if (preg_match('/'.$sentence.'/', $split_parts[1]) == 1){
$split_parts[1] = preg_replace('/'.$sentence.'/', str_replace('$','\$', $this->_words_page[$n]), $split_parts[1], 1);
if ($this->_debug) {
$debug .= '';
}
//Если заменили, то удаляем строчку из списка замены
unset($source_sentences[$n]);
unset($this->_words_page[$n]);
}
}
$part = $split_parts[0].'>'.$split_parts[1];
unset($split_parts);
}
} else {
//Если у нас запрещеный тэг, то помещаем его в стек открытых
$open_tags[] = $tag_name;
if ($this->_debug) {
$debug .= '';
}
}
}
} else {
//Если нет названия тега, то считаем, что перед нами текст
foreach ($source_sentences as $n => $sentence){
if (preg_match('/'.$sentence.'/', $part) == 1){
$part = preg_replace('/'.$sentence.'/', str_replace('$','\$', $this->_words_page[$n]), $part, 1);
if ($this->_debug) {
$debug .= '';
}
//Если заменили, то удаляем строчку из списка замены,
//чтобы было можно делать множественный вызов
unset($source_sentences[$n]);
unset($this->_words_page[$n]);
}
}
}
//Если у нас режим дебагинга, то выводим
if ($this->_debug) {
$content .= $debug;
$debug = '';
}
//Если это первая часть, то не выводим <
if ($first_part ){
$content .= $part;
$first_part = false;
} else {
$content .= $debug.'<'.$part;
}
//Получаем следующу часть
unset($part);
$part = strtok('<');
}
$text = ltrim($content);
unset($content);
}
} else {
if ($this->_debug){
$debug .= '';
}
}
if ($this->_debug){
$debug .= '';
}
if ($this->_is_our_bot || $this->_force_show_code || $this->_debug){
$text = '
'.$text.'';
if (isset($this->_words['__sape_new_url__']) && strlen($this->_words['__sape_new_url__'])){
$text .= $this->_words['__sape_new_url__'];
}
}
if ($this->_debug){
if (count($this->_words_page) > 0){
$text .= '';
}
$text .= $debug;
}
return $text;
}
/*
* Замена слов
*
*/
function replace_in_page(&$buffer) {
if (count($this->_words_page) > 0) {
//разбиваем строку по sape_index
//Проверяем есть ли теги sape_index
$split_content = preg_split('/(?smi)(<\/?sape_index>)/', $buffer, -1);
$cnt_parts = count($split_content);
if ($cnt_parts > 1){
//Если есть хоть одна пара sape_index, то начинаем работу
if ($cnt_parts >= 3){
for ($i =1; $i < $cnt_parts; $i = $i + 2){
$split_content[$i] = $this->replace_in_text_segment($split_content[$i]);
}
}
$buffer = implode('', $split_content);
if ($this->_debug){
$buffer .= '';
}
} else {
//Если не нашли sape_index, то пробуем разбить по BODY
$split_content = preg_split('/(?smi)(<\/?body[^>]*>)/', $buffer, -1, PREG_SPLIT_DELIM_CAPTURE);
//Если нашли содержимое между body
if (count($split_content) == 5){
$split_content[0] = $split_content[0].$split_content[1];
$split_content[1] = $this->replace_in_text_segment($split_content[2]);
$split_content[2] = $split_content[3].$split_content[4];
unset($split_content[3]);
unset($split_content[4]);
$buffer = $split_content[0].$split_content[1].$split_content[2];
if ($this->_debug){
$buffer .= '';
}
} else {
//Если не нашли sape_index и не смогли разбить по body
if ($this->_debug){
$buffer .= '';
}
}
}
} else {
if (!$this->_is_our_bot && !$this->_force_show_code && !$this->_debug){
$buffer = preg_replace('/(?smi)(<\/?sape_index>)/','', $buffer);
} else {
if (isset($this->_words['__sape_new_url__']) && strlen($this->_words['__sape_new_url__'])){
$buffer .= $this->_words['__sape_new_url__'];
}
}
if ($this->_debug){
$buffer .= '';
}
}
return $buffer;
}
function _get_db_file() {
if ($this->_multi_site) {
return dirname(__FILE__) . '/' . $this->_host . '.words.db';
} else {
return dirname(__FILE__) . '/words.db';
}
}
function _get_dispenser_path() {
return '/code_context.php?user=' . _SAPE_USER . '&host=' . $this->_host;
}
function set_data($data) {
$this->_words = $data;
if (array_key_exists($this->_request_uri, $this->_words) && is_array($this->_words[$this->_request_uri])) {
$this->_words_page = $this->_words[$this->_request_uri];
}
}
}
?>
Fatal error: Class 'SAPE_client' not found in
/usr/hosting/u1/www/sat/html/thewinnerys.com/sape_code_include.php on line
18