| Доброе время суток!
Люди добрые помогите разобраться со скриптом. Точнее с ротатором ссылок.
Я как бы не совсем знаток PHP.
На данный момент ротатор показывает 5 ссылок при добавлении 6 ссылки последняя удаляется.
Вот хотел переделать так чтобы показывалась 1 ссылка в случайном порядке.
Но почему то не работает, хотя в денвере все работает. При добавлении ссылок в ротатор показываются все добавленные ссылки, а не одна в случайном порядке.
Вот сам код который отвечает за открытие и запись в файл:
/** --------
Ротатор ссылок
<div id="blk">Загрузка...</div>
<?endif?><script type="text/javascript">$('#blk').load('/php/ball/index.php?w=links&t=get');</script>
<?if($USER_LOGGED_IN$)?><hr> [ <a href="javascript://" onclick="b_links()" title="Отправить баллы">Добавить ссылку</a> ]
<script type="text/javascript" src="/php/ball/index.php?w=datamod&m=links"></script><?endif?>
-------- **/
if(empty($work)) exit('err'); # Защита от прямого вызова
if($_GET['t'] == 'get'){
$data = file_get_contents($modul.'data.dat');
if(empty($data)) $data = '<li><b>Тут может быть ваша ссылка...</b></li>';
exit($data);
}
if($uid == 0) exit($err.'<b>Войдите на сайт</b>');
if(!shield($work)) exit($err.'<b>Не так часто!</b>'); # Защита от частых запросов
$url = urldecode($_GET['url']);
$txt = urldecode($_GET['txt']);
$txt = trim(strip_tags($txt));
if(!preg_match('@^(http://)@', $url)) exit($err.'<b>Неправильная ссылка</b>');
if(strlen($txt) > $bll['maxlen']) exit($err.'<b>Макс. кол-во символов '.$bll['maxlen'].'</b>');
$txt = htmlspecialchars($txt);
if(empty($txt)) exit($err.'<b>Название пустое</b>');
$bls = getBall($uid);
if(empty($bls)) exit($err.'<b>Попробуйте позже</b>');
$bl = get($uid) + $bls;
if($bl < $bll['price']) exit($err.'<b>Недостаточно баллов</b>');
$data = '<li><b><a href="'.$url.'" target="_blank">'.$txt.'</a></b></li>';
$s = file($modul.'data.dat');
$s[0] = $data.PHP_EOL.$s[0];
$e = sizeof($s);
for($c = 0; $c != $e; $c++){
if($c >= $bll['max']-1) $s[$c] = '';
}
$d = fopen($modul.'data.dat', 'w');
foreach($s as $s_) fwrite($d, $s_.'');
fclose($d);
record($uid, 0, $bll['price']);
exit($ok.'<b>Готово</b>');
?>
|
Вот эту часть кода:
$s = file($modul.'data.dat');
$s[0] = $data.PHP_EOL.$s[0];
$e = sizeof($s);
for($c = 0; $c != $e; $c++){
if($c >= $bll['max']-1) $s[$c] = '';
}
$d = fopen($modul.'data.dat', 'w');
foreach($s as $s_) fwrite($d, $s_.'');
fclose($d);
record($uid, 0, $bll['price']);
exit($ok.'<b>Готово</b>');
|
Менял на эту:
$s = file($modul.'data.dat');
$a = 2;
$e = mt_rand(1, count($s) - $a);
$sad=$e+$a;
for($c = $e; $c < $sad; $c++){
$s[$c];
}
$d = fopen($modul.'data.dat', 'a+');
$info = $data;
fwrite($d, $info. "\r\n");
fclose($d);
record($uid, 0, $bll['price']);
exit($ok.'<b>Готово</b>');
|
И ни как не хочет работать.
В этом скрипте есть еще файл с вязаный с тим:
<?PHP
$___notjson = 1;
$var = array(array(),array());
global $var;
$uid = ucoz_getinfo('SITEUSERID');
header('Content-Type: text/html; charset=utf-8');
$work = trim($_GET['w']); # Какую операцию провести
if(empty($work)) exit('err');
#### Конфиг
include 'config.php';
#### Подключаем стандартные функции
require('function.php');
/* ------ Спец. work */
# Получение изменений быллов
if($work == 'get') exit(get($_GET['i']));
# Возможность изменять баллы админу
if($work == 'change'){
if($uid != 1) exit('Нет прав доступа!');
$r = record($_GET['i'], $_GET['p'], $_GET['m']);
if($r !== true) exit($err.'<b>'.$r.'</b>');
exit($ok.'<b>Готово</b>');
}
# Получение списка модулей
# $USER_ID$, $MODUL$, $LOAD$, $ERR$, $OK$ - Доступные коды
if($work == 'listmod'){
$scan = scandir('moduls');
foreach($scan as $dir){
$config = 'moduls/'.$dir.'/config.bll';
if(!is_file($config) || $dir == '.'|| $dir == '..') continue;
$data = bll(file_get_contents($config));
if(!$data['switch'] || !$data['display']) continue;
nawvar('USER_ID', $uid, 'LOAD', $load, 'OK', $ok, 'ERR', $err, 'MODUL', $dir);
$decl = decl($data['price'], array('балл','балла','баллов'));
echo nawvar('<div class="hbl"><div class="ibl"><img src="'.$data['img'].'" width="32" height="32" alt="" border="0"></div><div class="cbl"><a href="javascript://" onclick="b_'.$dir.'()"><b>'.$data['name'].'</b></a><span class="b0"> - '.$decl.'</span><br>'.$data['message'].'</div></div>');
}
exit;
}
# Вызов молуля из списка
# $USER_ID$, $MODUL$, $LOAD$, $ERR$, $OK$ - Доступные коды
if($work == 'datamod' && $_GET['m']){
header('Content-Type: text/javascript; charset=utf-8');
nawvar('USER_ID', $uid, 'LOAD', $load, 'OK', $ok, 'ERR', $err);
if($_GET['m'] == 'allmod'){
$scan = scandir('moduls');
foreach($scan as $dir){
$config = 'moduls/'.$dir.'/config.bll';
if(!is_file($config) || $dir == '.'|| $dir == '..') continue;
$data = bll(file_get_contents($config));
if(!$data['switch'] || !$data['display']) continue;
nawvar('MODUL', $dir);
if(!$data['ajax']) $data['ajax'] = "align:'left',autosize:1";
echo nawvar("function b_".$dir."(){ new _uWnd('b_".$_GET['m']."','".$data['name']."',".$data['w_h'].",{".$data['ajax'].",oncontent:function(){".$data['js']."}},'".$data['html']."');}".PHP_EOL);
}
exit;
}
$config = 'moduls/'.$_GET['m'].'/config.bll';
if(!is_file($config)) exit('"config.bll" не обнаружен');
$data = bll(file_get_contents($config));
if(!$data['switch']) exit('Модуль не активен');
if(!$data['ajax']) $data['ajax'] = "align:'left',autosize:1";
nawvar('MODUL', $_GET['m']);
echo nawvar("function b_".$_GET['m']."(){ new _uWnd('b_".$_GET['m']."','".$data['name']."',".$data['w_h'].",{".$data['ajax'].",oncontent:function(){".$data['js']."}},'".$data['html']."');}");
exit;
}
/* ------ */
# Подключаем модуль
$modul = 'moduls/'.$work.'/';
if(!is_file($modul.'index.php')) exit('Такого мудуля не существует');
if(!is_file($modul.'config.bll')) exit('"config.bll" не обнаружен');
$config = file_get_contents($modul.'config.bll');
$bll = bll($config);
if(!$bll['switch']) exit('Модуль не активен');
require($modul.'index.php');
?>
|
Может кто сможет подсказать что и как сделать, а то уже всю голову сломал. | |