<?php
/*
* @package LabCMS
* @copyright (c) 2006 Alexander Levin aka Loki (loki_angel@mail.ru)
* @support http://labcms.ru
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/

if (!LabConfig::$mcfg['enabled']
	|| !LabConfig::$mcfg['sape_user']
	|| $_SERVER['SERVER_ADDR']==$_SERVER['REMOTE_ADDR']) return;

if (!defined('_SAPE_USER')){
	define('_SAPE_USER', LabConfig::$mcfg['sape_user']); 
}

require_once dirname(__FILE__).'/sape.php'; 

if (LabConfig::$mcfg['check_code']) $o['force_show_code']=true;
$o['charset'] = 'UTF-8';
//обходим проверку продажных ссылок
$tmp=explode('?', $_SERVER['REQUEST_URI']);
$o['request_uri']=$tmp[0];
$o['db_path']=LAB_PATH_DATA.'/cache';

if (LabConfig::$mcfg['host'])
{
	$o['multi_site'] = true;
	$o['host'] = LabConfig::$mcfg['host'];
}
$sape = new SAPE_client($o);
unset($o);
$links=array();
if ($sape->_links_page && !is_array($sape->_links_page)) $sape->_links_page=array($sape->_links_page);
if (is_array($sape->_links_page))
{
	$total=count($sape->_links_page);
	for($i=1;$i<=$total;$i++)
	{
		$links[$i]=$sape->return_links(1);
	}
}

Tpl::i()->assign('sape', $links);
