<?PHP
/*
=====================================================
MOD "Files v.3.3" for DataLife Engine - by Snake
url = http://mynokia.su/
email - igramnet@gmail.com
Форум поддержки модуля http://savgroup.ru/
=====================================================
DataLife Engine - by SoftNews Media Group
-----------------------------------------------------
http://dle-news.ru/
-----------------------------------------------------
Copyright (c) 2004,2009 SoftNews Media Group
=====================================================
Данный код защищен авторскими правами
=====================================================
Проверен на безопасность командой White Team
-----------------------------------------------------
Сайт команды http://www.white-team.net
=====================================================
*/
if (! defined ( 'DATALIFEENGINE' ))
die ( "Hacking attempt!" );
function WriteLog($modul_dbtitle, $modulname, $description, $fileid = 0) {
global $db, $member_db;
$date = date ( "Y-m-d H:i:s" );
$description = $db->safesql ( $description );
$db->query ( "INSERT INTO `" . PREFIX . "_" . $modul_dbtitle . "_actionlog` SET `date` = '{$date}', `username` = '{$member_db[2]}', `fileid` = '{$fileid}', `description` = '{$description}'" );
}
##================================================================================================
function platformSelection($categoryid = 0, $parentid = 0, $nocat = TRUE, $sublevelmarker = '', $returnstring = '') {
global $db, $modul_dbtitle;
$result = $db->query ( "SELECT * FROM `" . PREFIX . "_" . $modul_dbtitle . "_platform` ORDER BY `posi` ASC" );
while ( $row = $db->get_row ( $result ) ) {
$catfiles [$row ['id']] = $row ['name'];
$catfiles_parentid [$row ['id']] = $row ['parentid'];
}
$db->free ( $result );
if ($parentid == 0) {
if ($nocat)
$returnstring .= '<option value="0"></option>';
} else {
$sublevelmarker .= ' -- ';
}
if (isset ( $catfiles_parentid )) {
$root_category = array_keys ( $catfiles_parentid, $parentid );
if (is_array ( $root_category )) {
foreach ( $root_category as $id ) {
$category_name = $catfiles [$id];
$returnstring .= "<option value=\"" . $id . '" ';
if ($categoryid == $id)
$returnstring .= 'SELECTED';
$returnstring .= '>' . $sublevelmarker . $category_name . '</option>';
$returnstring = platformSelection ( $categoryid, $id, $nocat, $sublevelmarker, $returnstring );
}
}
}
return $returnstring;
}
##===========================================================================================##
function versionSelection($categoryid = 0, $parentid = 0, $nocat = TRUE, $sublevelmarker = '', $returnstring = '') {
global $db, $modul_dbtitle;
$result = $db->query ( "SELECT * FROM `" . PREFIX . "_" . $modul_dbtitle . "_version` ORDER BY `posi` ASC" );
while ( $row = $db->get_row ( $result ) ) {
$catfiles [$row ['id']] = $row ['name'];
$catfiles_parentid [$row ['id']] = $row ['parentid'];
}
$db->free ( $result );
if ($parentid == 0) {
if ($nocat)
$returnstring .= '<option value="0"></option>';
} else {
$sublevelmarker .= ' -- ';
}
if (isset ( $catfiles_parentid )) {
$root_category = array_keys ( $catfiles_parentid, $parentid );
if (is_array ( $root_category )) {
foreach ( $root_category as $id ) {
$category_name = $catfiles [$id];
$returnstring .= "<option value=\"" . $id . '" ';
if ($categoryid == $id)
$returnstring .= 'SELECTED';
$returnstring .= '>' . $sublevelmarker . $category_name . '</option>';
$returnstring = versionSelection ( $categoryid, $id, $nocat, $sublevelmarker, $returnstring );
}
}
}
return $returnstring;
}
##================================================================================================
function CategoryfileSelection($categoryid = 0, $parentid = 0, $nocat = TRUE, $sublevelmarker = '', $returnstring = '') {
global $catfiles, $catfiles_parentid;
if ($parentid == 0) {
if ($nocat)
$returnstring .= '<option value="0"></option>';
} else {
$sublevelmarker .= ' -- ';
}
if (isset ( $catfiles_parentid )) {
$root_category = array_keys ( $catfiles_parentid, $parentid );
if (is_array ( $root_category )) {
foreach ( $root_category as $id ) {
$category_name = $catfiles [$id];
$returnstring .= "<option value=\"" . $id . '" ';
if ($categoryid == $id)
$returnstring .= 'SELECTED';
$returnstring .= '>' . $sublevelmarker . $category_name . '</option>';
$returnstring = CategoryfileSelection ( $categoryid, $id, $nocat, $sublevelmarker, $returnstring );
}
}
}
return $returnstring;
}
##===========================================================================================##
function clear_all_cache() {
global $modulname;
$dirname = ENGINE_DIR . '/cache/' . $modulname;
if (! is_dir ( $dirname ))
$cache = "Ваш кеш уже пуст.";
else {
$dscan = array (realpath ( $dirname ) );
$darr = array ();
while ( ! empty ( $dscan ) ) {
$dcur = array_pop ( $dscan );
$darr [] = $dcur;
if ($d = opendir ( $dcur )) {
while ( $f = readdir ( $d ) ) {
if ($f == '.' || $f == '..')
continue;
$f = $dcur . '/' . $f;
if (is_dir ( $f ))
$dscan [] = $f;
else
@unlink ( $f );
}
closedir ( $d );
}
}
$i_until = ($only_empty) ? 1 : 0;
for($i = count ( $darr ) - 1; $i >= $i_until; $i --) {
if (@rmdir ( $darr [$i] ))
$cache = "Кеш успешно почищен";
else
$cache = "Ошибка удаления кеша. Одна из причин - не стоят права на папки 777.";
}
}
@mkdir ( ENGINE_DIR . '/cache/' . $modulname, 0777 );
@mkdir ( ENGINE_DIR . '/cache/' . $modulname . '/system/', 0777 );
@chmod ( ENGINE_DIR . '/cache/' . $modulname, 0777 );
@chmod ( ENGINE_DIR . '/cache/' . $modulname . '/system/', 0777 );
return $cache;
}
function xfieldsload_modf2() {
global $lang, $modulname;
$path = ENGINE_DIR . '/data/xfields_' . $modulname . '.txt';
$filecontents = file ( $path );
if (! is_array ( $filecontents ))
msg ( "error", $lang ['xfield_error'], "$lang[xfield_err_3] \"engine/data/xfields_" . $modulname . ".txt\". $lang[xfield_err_4]" );
foreach ( $filecontents as $name => $value ) {
$filecontents [$name] = explode ( "|", trim ( $value ) );
foreach ( $filecontents [$name] as $name2 => $value2 ) {
$value2 = str_replace ( "|", "|", $value2 );
$value2 = str_replace ( "__NEWL__", "\r\n", $value2 );
$filecontents [$name] [$name2] = htmlspecialchars ( $value2 );
}
}
return $filecontents;
}
function sevfiles($modul_servdir, $accepted_files) {
$file_ext = explode ( ",", $accepted_files );
$tdir = opendir ( $modul_servdir );
$content = "<option value=\"\"></option>";
while ( $file = readdir ( $tdir ) ) {
foreach ( $file_ext as $value ) {
if (preg_match ( "/^(.+)\.$value/", $file )) {
$content .= "<option value=\"$file\">" . $file . "</option>";
}
}
}
closedir ( $tdir );
return $content;
}
##================================Функция загрузки файла=========================================##
function do_upload($upload_dir, $file_name) {
global $file_copyr, $allow_zipfiles, $site_ka4alka_login, $site_ka4alka_pass, $site_ka4alka_host, $upload_dir_ftp, $to_ftp, $_REQUEST, $filesConfig;
$do = $_REQUEST ['do'];
$temp_name = $_FILES ['file_a'] ['tmp_name'];
if ($to_ftp == 1) {
$file_path = $upload_dir_ftp . $file_name;
$connect = @ftp_connect ( $site_ka4alka_host );
if (! $connect)
exit ();
if (@ftp_login ( $connect, $site_ka4alka_login, $site_ka4alka_pass ) == FALSE) {
echo "<center>Невозможно подключиться к серверу по FTP. <br /></center>";
if ($do == "")
echofooter ();
exit ();
}
if (@ftp_put ( $connect, $file_path, $temp_name, FTP_BINARY ) == FALSE) {
echo "<center>Невозможно закачать файл на FTP. <br /></center>";
if ($do == "")
echofooter ();
exit ();
}
@ftp_chmod ( $connect, 0666, $file_path );
@ftp_quit ( $connect );
@unlink ( $file_path );
@unlink ( $temp_name );
} elseif ($to_ftp == 0) {
$file_path = $upload_dir . $file_name;
if (@move_uploaded_file ( $temp_name, $file_path ) == FALSE) {
echo "<center>Невозможно закачать файл. <br /></center>";
if ($do == "")
echofooter ();
exit ();
}
$file_ext = strtolower ( substr ( $file_name, strrpos ( $file_name, "." ) ) );
$FILE_EXTS = explode ( ",", $filesConfig ['accepted_zip_files'] );
foreach ( $FILE_EXTS as $value )
$FILE_EXTS [] = "." . $value;
if ($allow_zipfiles == 1 and ! in_array ( $file_ext, $FILE_EXTS )) {
if (function_exists ( "zip_open" )) {
$zip = new ZipArchive ( );
if ($file_ext == ".zip") {
$zip->open ( $file_path, ZIPARCHIVE::CREATE );
$zip->addFile ( ROOT_DIR . "/" . $file_copyr, $file_copyr );
} else {
$zip->open ( $file_path . ".zip", ZIPARCHIVE::CREATE );
$zip->addFile ( $file_path, $file_name );
$zip->addFile ( ROOT_DIR . "/" . $file_copyr, $file_copyr );
// echo $file_path;
// @unlink($file_path);
$file_name .= ".zip";
}
$zip->close ();
if ($file_ext != ".zip")
@unlink ( $file_path );
} else {
if (version_compare ( phpversion (), "5.2.0", "<" ))
$infoVersion = "(требуется версия не моложе PHP 5.2.0)";
echo "Вам надо включить библиотеку php_zip.dll (подробнее http://php.net/zip) $infoVersion. Ваш файл просто незазипован. В противном случае отключите \"зипование\" в настройках архива.";
}
}
$file_path = $upload_dir . $file_name;
if (! @chmod ( $file_path, 0666 ))
echo "<center><b>Не удалось установить права доступа для файла в 0666.</b></center>";
}
return $file_name;
}
function do_upload2($upload_dir, $link_url, $file_name) {
global $file_copyr, $allow_zipfiles, $site_ka4alka_login, $site_ka4alka_pass, $site_ka4alka_host, $upload_dir_ftp, $to_ftp, $_REQUEST, $filesConfig;
$temp_name = $link_url;
$do = $_REQUEST ['do'];
if ($to_ftp == 1) {
$file_path = $upload_dir_ftp . $file_name;
$connect = @ftp_connect ( $site_ka4alka_host );
if (! $connect)
exit ();
if (@ftp_login ( $connect, $site_ka4alka_login, $site_ka4alka_pass ) == FALSE) {
echo "<center>Невозможно подключиться к серверу по FTP. <br /></center>";
if ($do == "")
echofooter ();
exit ();
}
if (@ftp_put ( $connect, $file_path, $temp_name, FTP_BINARY ) == FALSE) {
echo "<center>Невозможно закачать файл на FTP. <br /></center>";
if ($do == "")
echofooter ();
exit ();
}
@ftp_chmod ( $connect, 0666, $file_path );
@ftp_quit ( $connect );
@unlink ( $file_path );
@unlink ( $temp_name );
} elseif ($to_ftp == 0) {
$file_path = $upload_dir . $file_name;
if (@copy ( $temp_name, $file_path ) == FALSE) {
echo "<center>Невозможно закачать файл. <br /></center>";
if ($do == "")
echofooter ();
exit ();
}
$file_ext = strtolower ( substr ( $file_name, strrpos ( $file_name, "." ) ) );
$FILE_EXTS = explode ( ",", $filesConfig ['accepted_zip_files'] );
foreach ( $FILE_EXTS as $value )
$FILE_EXTS [] = "." . $value;
if ($allow_zipfiles == 1 and ! in_array ( $file_ext, $FILE_EXTS )) {
if (function_exists ( "zip_open" )) {
$zip = new ZipArchive ( );
if ($file_ext == ".zip") {
$zip->open ( $file_path, ZIPARCHIVE::CREATE );
$zip->addFile ( ROOT_DIR . "/" . $file_copyr, $file_copyr );
} else {
$zip->open ( $file_path . ".zip", ZIPARCHIVE::CREATE );
$zip->addFile ( $file_path, $file_name );
$zip->addFile ( ROOT_DIR . "/" . $file_copyr, $file_copyr );
// echo $file_path;
// @unlink($file_path);
$file_name .= ".zip";
}
$zip->close ();
if ($file_ext != ".zip")
@unlink ( $file_path );
} else {
if (version_compare ( phpversion (), "5.2.0", "<" ))
$infoVersion = "(требуется версия не моложе PHP 5.2.0)";
echo "Вам надо включить библиотеку php_zip.dll (подробнее http://php.net/zip) $infoVersion. Ващ файл просто незазипован. Если не можете включить данную функцию, то выключите зипование в настройках архива";
}
}
$file_path = $upload_dir . $file_name;
if (! @chmod ( $file_path, 0666 ))
echo "<center><b>Не удалось установить права доступа для файла в 0666.</b></center>";
}
return $file_name;
}
function do_upload_serv($upload_dir, $serv_url, $file_name) {
global $file_copyr, $allow_zipfiles, $site_ka4alka_login, $site_ka4alka_pass, $site_ka4alka_host, $upload_dir_ftp, $to_ftp, $modul_servdir, $_REQUEST, $filesConfig;
$do = $_REQUEST ['do'];
$temp_name = $serv_url;
$modul_servdir_full = ROOT_DIR . "/" . $modul_servdir;
$temp_dir = $modul_servdir_full . $temp_name;
if ($to_ftp == 1) {
$file_path = $upload_dir_ftp . $file_name;
$connect = @ftp_connect ( $site_ka4alka_host );
if (! $connect)
exit ();
if (@ftp_login ( $connect, $site_ka4alka_login, $site_ka4alka_pass ) == FALSE) {
echo "<center>Невозможно подключиться к серверу по FTP. <br /></center>";
if ($do == "")
echofooter ();
exit ();
}
if (@ftp_put ( $connect, $file_path, $temp_dir, FTP_BINARY ) == FALSE) {
echo "<center>Невозможно закачать файл на FTP. <br /></center>";
if ($do == "")
echofooter ();
exit ();
}
@ftp_chmod ( $connect, 0666, $file_path );
@ftp_quit ( $connect );
@unlink ( $temp_dir );
@unlink ( $temp_name );
} elseif ($to_ftp == 0) {
$file_path = $upload_dir . $file_name;
if (@rename ( $temp_dir, $file_path ) == FALSE) {
echo "<center>Невозможно переместить файл. <br /></center>";
if ($do == "")
echofooter ();
exit ();
}
$file_ext = strtolower ( substr ( $file_name, strrpos ( $file_name, "." ) ) );
$FILE_EXTS = explode ( ",", $filesConfig ['accepted_zip_files'] );
foreach ( $FILE_EXTS as $value )
$FILE_EXTS [] = "." . $value;
if ($allow_zipfiles == 1 and ! in_array ( $file_ext, $FILE_EXTS )) {
if (function_exists ( "zip_open" )) {
$zip = new ZipArchive ( );
if ($file_ext == ".zip") {
$zip->open ( $file_path, ZIPARCHIVE::CREATE );
$zip->addFile ( ROOT_DIR . "/" . $file_copyr, $file_copyr );
} else {
$zip->open ( $file_path . ".zip", ZIPARCHIVE::CREATE );
$zip->addFile ( $file_path, $file_name );
$zip->addFile ( ROOT_DIR . "/" . $file_copyr, $file_copyr );
// @unlink($file_path);
$file_name .= ".zip";
}
$zip->close ();
if ($file_ext != ".zip")
@unlink ( $file_path );
} else {
if (version_compare ( phpversion (), "5.2.0", "<" ))
$infoVersion = "(требуется версия не моложе PHP 5.2.0)";
echo "Вам надо включить библиотеку php_zip.dll (подробнее http://php.net/zip) $infoVersion";
}
}
@unlink ( $temp_dir );
$file_path = $upload_dir . $file_name;
if (! @chmod ( $file_path, 0666 ))
echo "<center><b>Не удалось установить права доступа для файла в 0666!!!</b></center>";
}
return $file_name;
}
##===============================================================================================##
?>