function cron_dump_autobackup()
{
    global $db, $db_config, $global_config, $client_info;
    $result = true;
    $current_day = mktime(0, 0, 0, date("n", NV_CURRENTTIME), date("j", NV_CURRENTTIME), date("Y", NV_CURRENTTIME));
    $w_day = $current_day - $global_config['dump_backup_day'] * 86400;
    $contents = array();
    $contents['savetype'] = $global_config['dump_backup_ext'] == "sql" ? "sql" : "gz";
    $file_ext = $contents['savetype'] == "sql" ? "sql" : "sql.gz";
    $log_dir = NV_ROOTDIR . "/" . NV_LOGS_DIR . "/dump_backup";
    $contents['filename'] = $log_dir . "/" . md5(nv_genpass(10) . $client_info['session_id']) . "_" . $current_day . "." . $file_ext;
    if (!file_exists($contents['filename'])) {
        $files = scandir($log_dir);
        foreach ($files as $file) {
            unset($mc);
            if (preg_match("/^([a-zA-Z0-9]+)\\_([0-9]+)\\.(" . nv_preg_quote($file_ext) . ")/", $file, $mc)) {
                if (intval($mc[2]) > 0 and intval($mc[2]) < $w_day) {
                    @unlink($log_dir . "/" . $file);
                }
            }
        }
        $contents['tables'] = array();
        $res = $db->sql_query("SHOW TABLES LIKE '" . $db_config['prefix'] . "_%'");
        while ($item = $db->sql_fetchrow($res)) {
            $contents['tables'][] = $item[0];
        }
        $db->sql_freeresult($res);
        $contents['type'] = "all";
        include NV_ROOTDIR . "/includes/core/dump.php";
        if (!nv_dump_save($contents)) {
            $result = false;
        }
    }
    return $result;
}
Example #2
0
/**
 * viewdirtree()
 *
 * @param mixed $dir
 * @param mixed $currentpath
 * @return
 */
function viewdirtree($dir, $currentpath)
{
    global $array_dirname, $global_config, $module_file;
    $pattern = !empty($dir) ? '/^(' . nv_preg_quote($dir) . ')\\/([^\\/]+)$/' : '/^([^\\/]+)$/';
    $_dirlist = preg_grep($pattern, array_keys($array_dirname));
    $content = '';
    foreach ($_dirlist as $_dir) {
        $check_allow_upload_dir = nv_check_allow_upload_dir($_dir);
        if (!empty($check_allow_upload_dir)) {
            $class_li = ($_dir == $currentpath or strpos($currentpath, $_dir . '/') !== false) ? 'open collapsable' : 'expandable';
            $style_color = $_dir == $currentpath ? ' style="color:red"' : '';
            $tree = array();
            $tree['class1'] = $class_li;
            $tree['class2'] = nv_set_dir_class($check_allow_upload_dir) . ' pos' . nv_string_to_filename($dir);
            $tree['style'] = $style_color;
            $tree['title'] = $_dir;
            $tree['titlepath'] = basename($_dir);
            $content2 = viewdirtree($_dir, $currentpath);
            $xtpl = new XTemplate('foldlist.tpl', NV_ROOTDIR . '/themes/' . $global_config['module_theme'] . '/modules/' . $module_file);
            $xtpl->assign('DIRTREE', $tree);
            if (empty($content2)) {
                $content2 = '<li class="hide">&nbsp;</li>';
            }
            if (!empty($content2)) {
                $xtpl->assign('TREE_CONTENT', $content2);
                $xtpl->parse('tree.tree_content');
            }
            $xtpl->parse('tree');
            $content .= $xtpl->text('tree');
        }
    }
    return $content;
}
Example #3
0
function cron_auto_del_temp_download()
{
    $dir = NV_ROOTDIR . '/' . NV_TEMP_DIR;
    $result = true;
    if ($dh = opendir($dir)) {
        while (($file = readdir($dh)) !== false) {
            if (preg_match('/^(' . nv_preg_quote(NV_TEMPNAM_PREFIX) . ')[a-zA-Z0-9\\_\\.]+$/', $file)) {
                if (filemtime($dir . '/' . $file) + 600 < NV_CURRENTTIME) {
                    if (is_file($dir . '/' . $file)) {
                        if (!@unlink($dir . '/' . $file)) {
                            $result = false;
                        }
                    } else {
                        $rt = nv_deletefile($dir . '/' . $file, true);
                        if ($rt[0] == 0) {
                            $result = false;
                        }
                    }
                }
            }
        }
        closedir($dh);
        clearstatcache();
    }
    return $result;
}
Example #4
0
/**
 * viewdirtree()
 * 
 * @param mixed $dir
 * @param mixed $currentpath
 * @return
 */
function viewdirtree($dir, $currentpath)
{
    global $dirlist, $global_config, $module_file;
    $pattern = !empty($dir) ? "/^(" . nv_preg_quote($dir) . ")\\/([^\\/]+)\$/" : "/^([^\\/]+)\$/";
    $_dirlist = preg_grep($pattern, $dirlist);
    $content = "";
    foreach ($_dirlist as $_dir) {
        $check_allow_upload_dir = nv_check_allow_upload_dir($_dir);
        if (!empty($check_allow_upload_dir)) {
            $class_li = ($_dir == $currentpath or strpos($currentpath, $_dir . '/') !== false) ? "open collapsable" : "expandable";
            $style_color = $_dir == $currentpath ? ' style="color:red"' : '';
            $tree = array();
            $tree['class1'] = $class_li;
            $tree['class2'] = nv_set_dir_class($check_allow_upload_dir) . " pos" . nv_string_to_filename($dir);
            $tree['style'] = $style_color;
            $tree['title'] = $_dir;
            $tree['titlepath'] = basename($_dir);
            $content2 = viewdirtree($_dir, $currentpath);
            $xtpl = new XTemplate("foldlist.tpl", NV_ROOTDIR . "/themes/" . $global_config['module_theme'] . "/modules/" . $module_file);
            $xtpl->assign("DIRTREE", $tree);
            if (!empty($content2)) {
                $xtpl->assign("TREE_CONTENT", $content2);
                $xtpl->parse('tree.tree_content');
            }
            $xtpl->parse('tree');
            $content .= $xtpl->text('tree');
        }
    }
    return $content;
}
Example #5
0
/**
 * nv_is_myreferer()
 *
 * @param string $referer
 * @return
 */
function nv_is_myreferer($referer = '')
{
    if (empty($referer)) {
        $referer = urldecode(nv_getenv('HTTP_REFERER'));
    }
    if (empty($referer)) {
        return 2;
    }
    $server_name = preg_replace('/^[w]+\\./', '', nv_getenv('HTTP_HOST'));
    $referer = preg_replace(array('/^[a-zA-Z]+\\:\\/\\/([w]+\\.)?/', '/^[w]+\\./'), '', $referer);
    if (preg_match('/^' . nv_preg_quote($server_name) . '/', $referer)) {
        return 1;
    }
    return 0;
}
function cron_auto_del_temp_download()
{
    $dir = NV_ROOTDIR . "/" . NV_TEMP_DIR;
    $files = nv_scandir($dir, "/^(" . nv_preg_quote(NV_TEMPNAM_PREFIX) . ")[a-zA-Z0-9\\_\\.]+\$/");
    $result = true;
    if (!empty($files)) {
        foreach ($files as $file) {
            if (filemtime($dir . '/' . $file) + 600 < NV_CURRENTTIME) {
                if (!@unlink($dir . '/' . $file)) {
                    $result = false;
                }
            }
            clearstatcache();
        }
    }
    return $result;
}
Example #7
0
/**
 * cron_dump_autobackup()
 *
 * @return
 */
function cron_dump_autobackup()
{
    global $db, $db_config, $global_config, $client_info;
    $result = true;
    $current_day = mktime(0, 0, 0, date('n', NV_CURRENTTIME), date('j', NV_CURRENTTIME), date('Y', NV_CURRENTTIME));
    $w_day = $current_day - $global_config['dump_backup_day'] * 86400;
    $contents = array();
    $contents['savetype'] = $global_config['dump_backup_ext'] == 'sql' ? 'sql' : 'gz';
    $file_ext = $contents['savetype'] == 'sql' ? 'sql' : 'sql.gz';
    $log_dir = NV_ROOTDIR . '/' . NV_LOGS_DIR . '/dump_backup';
    $contents['filename'] = $log_dir . '/' . md5(nv_genpass(10) . $client_info['session_id']) . '_' . $current_day . '.' . $file_ext;
    if (!file_exists($contents['filename'])) {
        if ($dh = opendir($log_dir)) {
            while (($file = readdir($dh)) !== false) {
                if (preg_match('/^([a-zA-Z0-9]+)\\_([0-9]+)\\.(' . nv_preg_quote($file_ext) . ')/', $file, $m)) {
                    if (intval($m[2]) > 0 and intval($m[2]) < $w_day) {
                        @unlink($log_dir . '/' . $file);
                    }
                }
            }
            closedir($dh);
            clearstatcache();
        }
        if ($global_config['dump_autobackup']) {
            $contents['tables'] = array();
            $res = $db->query("SHOW TABLES LIKE '" . $db_config['prefix'] . "_%'");
            while ($item = $res->fetch(3)) {
                $contents['tables'][] = $item[0];
            }
            $res->closeCursor();
            $contents['type'] = 'all';
            include NV_ROOTDIR . '/includes/core/dump.php';
            if (!nv_dump_save($contents)) {
                $result = false;
            }
        }
    }
    return $result;
}
Example #8
0
        if (isset($request_uri_array[1][0])) {
            $lop = strlen($request_uri_array[0]) + 1;
            $_GET[NV_OP_VARIABLE] = substr($matches[1], $lop);
        }
    }
} elseif (preg_match('/<(.*)s(.*)c(.*)r(.*)i(.*)p(.*)t(.*)>/i', urldecode($request_uri))) {
    header('HTTP/1.1 301 Moved Permanently');
    Header('Location: ' . $base_siteurl);
    die;
} elseif (isset($_GET[NV_OP_VARIABLE])) {
    if (preg_match('/([a-z0-9\\-\\_\\.\\/]+)' . nv_preg_quote($global_config['rewrite_exturl']) . '$/i', $_GET[NV_OP_VARIABLE], $matches)) {
        $_GET[NV_OP_VARIABLE] = $matches[1];
        define('NV_REWRITE_EXTURL', true);
    }
} else {
    if (preg_match('/^(' . $base_siteurl_quote . '([a-z0-9\\-\\_\\.\\/]+)(' . nv_preg_quote($global_config['rewrite_endurl']) . '|' . nv_preg_quote($global_config['rewrite_exturl']) . '))\\?(.*)$/i', $request_uri, $matches)) {
        header('HTTP/1.1 301 Moved Permanently');
        Header('Location: ' . $matches[1]);
        die;
    } elseif (!empty($global_config['rewrite_op_mod']) and preg_match('/^' . $base_siteurl_quote . 'tag\\/([^\'\\?\\&]+)$/i', $request_uri, $matches)) {
        $_GET[NV_NAME_VARIABLE] = $global_config['rewrite_op_mod'];
        $_GET[NV_OP_VARIABLE] = 'tag';
        $_GET['alias'] = urldecode($matches[1]);
    } elseif ($global_config['rewrite_optional'] and preg_match('/^' . $base_siteurl_quote . '([a-z0-9\\-]+)\\/tag\\/([^\'\\?\\&]+)$/i', $request_uri, $matches)) {
        $_GET[NV_NAME_VARIABLE] = $matches[1];
        $_GET[NV_OP_VARIABLE] = 'tag';
        $_GET['alias'] = urldecode($matches[2]);
    } elseif (preg_match('/^' . $base_siteurl_quote . '([a-z]{2}+)\\/([a-z0-9\\-]+)\\/tag\\/([^\'\\?\\&]+)$/i', $request_uri, $matches)) {
        $_GET[NV_LANG_VARIABLE] = $matches[1];
        $_GET[NV_NAME_VARIABLE] = $matches[2];
        $_GET[NV_OP_VARIABLE] = 'tag';
Example #9
0
 * @Author VINADES.,JSC (contact@vinades.vn)
 * @Copyright (C) 2014 VINADES.,JSC. All rights reserved
 * @License GNU/GPL version 2 or any later version
 * @Createdate 2-2-2010 12:55
 */
if (!defined('NV_IS_FILE_ADMIN')) {
    die('Stop!!!');
}
$path = nv_check_path_upload($nv_Request->get_string('path', 'post'));
$check_allow_upload_dir = nv_check_allow_upload_dir($path);
if (!isset($check_allow_upload_dir['delete_dir']) or $check_allow_upload_dir['delete_dir'] !== true) {
    die('ERROR_' . $lang_module['notlevel']);
}
if (empty($path) or $path == NV_UPLOADS_DIR) {
    die('ERROR_' . $lang_module['notlevel']);
}
$d = nv_deletefile(NV_ROOTDIR . '/' . $path, true);
if ($d[0]) {
    if (preg_match('/^' . nv_preg_quote(NV_UPLOADS_DIR) . '\\/([a-z0-9\\-\\_\\/]+)$/i', $path, $m)) {
        @nv_deletefile(NV_ROOTDIR . '/' . NV_FILES_DIR . '/' . $m[1], true);
    }
    $result = $db->query("SELECT did FROM " . NV_UPLOAD_GLOBALTABLE . "_dir WHERE dirname='" . $path . "' OR dirname LIKE '" . $path . "/%'");
    while (list($did) = $result->fetch(3)) {
        $db->query('DELETE FROM ' . NV_UPLOAD_GLOBALTABLE . '_file WHERE did = ' . $did);
        $db->query('DELETE FROM ' . NV_UPLOAD_GLOBALTABLE . '_dir WHERE did = ' . $did);
    }
    nv_insert_logs(NV_LANG_DATA, $module_name, $lang_module['deletefolder'], $path, $admin_info['userid']);
    echo 'OK';
} else {
    die('ERROR_' . $d[1]);
}
Example #10
0
function nv_get_viewImage($fileName)
{
    global $array_thumb_config;
    if (preg_match('/^' . nv_preg_quote(NV_UPLOADS_DIR) . '\\/(([a-z0-9\\-\\_\\/]+\\/)*([a-z0-9\\-\\_\\.]+)(\\.(gif|jpg|jpeg|png)))$/i', $fileName, $m)) {
        $viewFile = NV_FILES_DIR . '/' . $m[1];
        if (file_exists(NV_ROOTDIR . '/' . $viewFile)) {
            $size = @getimagesize(NV_ROOTDIR . '/' . $viewFile);
            return array($viewFile, $size[0], $size[1]);
        } else {
            $m[2] = rtrim($m[2], '/');
            if (isset($array_thumb_config[NV_UPLOADS_DIR . '/' . $m[2]])) {
                $thumb_config = $array_thumb_config[NV_UPLOADS_DIR . '/' . $m[2]];
            } else {
                $thumb_config = $array_thumb_config[''];
                $_arr_path = explode('/', NV_UPLOADS_DIR . '/' . $m[2]);
                while (sizeof($_arr_path) > 1) {
                    array_pop($_arr_path);
                    $_path = implode('/', $_arr_path);
                    if (isset($array_thumb_config[$_path])) {
                        $thumb_config = $array_thumb_config[$_path];
                        break;
                    }
                }
            }
            $viewDir = NV_FILES_DIR;
            if (!empty($m[2])) {
                if (!is_dir(NV_ROOTDIR . '/' . $m[2])) {
                    $e = explode('/', $m[2]);
                    $cp = NV_FILES_DIR;
                    foreach ($e as $p) {
                        if (is_dir(NV_ROOTDIR . '/' . $cp . '/' . $p)) {
                            $viewDir .= '/' . $p;
                        } else {
                            $mk = nv_mkdir(NV_ROOTDIR . '/' . $cp, $p);
                            if ($mk[0] > 0) {
                                $viewDir .= '/' . $p;
                            }
                        }
                        $cp .= '/' . $p;
                    }
                }
            }
            $image = new image(NV_ROOTDIR . '/' . $fileName, NV_MAX_WIDTH, NV_MAX_HEIGHT);
            if ($thumb_config['thumb_type'] == 4) {
                $thumb_width = $thumb_config['thumb_width'];
                $thumb_height = $thumb_config['thumb_height'];
                $maxwh = max($thumb_width, $thumb_height);
                if ($image->fileinfo['width'] > $image->fileinfo['height']) {
                    $thumb_config['thumb_width'] = 0;
                    $thumb_config['thumb_height'] = $maxwh;
                } else {
                    $thumb_config['thumb_width'] = $maxwh;
                    $thumb_config['thumb_height'] = 0;
                }
            }
            $image->resizeXY($thumb_config['thumb_width'], $thumb_config['thumb_height']);
            if ($thumb_config['thumb_type'] == 4) {
                $image->cropFromCenter($thumb_width, $thumb_height);
            }
            $image->save(NV_ROOTDIR . '/' . $viewDir, $m[3] . $m[4], $thumb_config['thumb_quality']);
            $create_Image_info = $image->create_Image_info;
            $error = $image->error;
            $image->close();
            if (empty($error)) {
                return array($viewDir . '/' . basename($create_Image_info['src']), $create_Image_info['width'], $create_Image_info['height']);
            }
        }
    } else {
        $size = @getimagesize(NV_ROOTDIR . '/' . $fileName);
        return array($viewFile, $size[0], $size[1]);
    }
    return false;
}
Example #11
0
/**
 * nv_check_path_upload()
 *
 * @param mixed $path
 * @return
 */
function nv_check_path_upload($path)
{
    global $allow_upload_dir;
    $path = htmlspecialchars(trim($path), ENT_QUOTES);
    $path = rtrim($path, "/");
    if (empty($path)) {
        return "";
    }
    $path = NV_ROOTDIR . "/" . $path;
    if (($path = realpath($path)) === false) {
        return "";
    }
    $path = str_replace("\\", "/", $path);
    $path = str_replace(NV_ROOTDIR . "/", "", $path);
    $result = false;
    foreach ($allow_upload_dir as $dir) {
        $dir = nv_preg_quote($dir);
        if (preg_match("/^" . $dir . "/", $path)) {
            $result = true;
            break;
        }
    }
    if ($result === false) {
        return "";
    }
    return $path;
}
Example #12
0
/**
 * nv_rewrite_change()
 *
 * @param mixed $rewrite_optional
 * @return
 */
function nv_rewrite_change($array_config_global)
{
    global $sys_info, $lang_module;
    $rewrite_rule = $filename = '';
    $endurl = $array_config_global['rewrite_endurl'] == $array_config_global['rewrite_exturl'] ? nv_preg_quote($array_config_global['rewrite_endurl']) : nv_preg_quote($array_config_global['rewrite_endurl']) . "|" . nv_preg_quote($array_config_global['rewrite_exturl']);
    if ($sys_info['supports_rewrite'] == "rewrite_mode_iis") {
        $filename = NV_ROOTDIR . "/web.config";
        $rulename = 0;
        $rewrite_rule .= "\n";
        $rewrite_rule .= "                <rule name=\"nv_rule_" . ++$rulename . "\">\n";
        $rewrite_rule .= "                    <match url=\"^\" ignoreCase=\"false\" />\n";
        $rewrite_rule .= "                    <conditions>\n";
        $rewrite_rule .= "                    \t\t<add input=\"{REQUEST_FILENAME}\" pattern=\"/robots.txt\$\" />\n";
        $rewrite_rule .= "                    </conditions>\n";
        $rewrite_rule .= "                    <action type=\"Rewrite\" url=\"robots.php?action={HTTP_HOST}\" appendQueryString=\"false\" />\n";
        $rewrite_rule .= "                </rule>\n";
        $rewrite_rule .= "                <rule name=\"nv_rule_" . ++$rulename . "\">\n";
        $rewrite_rule .= "                    <match url=\"^(.*?)Sitemap\\.xml\$\" ignoreCase=\"false\" />\n";
        $rewrite_rule .= "                    <action type=\"Rewrite\" url=\"index.php?" . NV_NAME_VARIABLE . "=SitemapIndex\" appendQueryString=\"false\" />\n";
        $rewrite_rule .= "                </rule>\n";
        $rewrite_rule .= "                <rule name=\"nv_rule_" . ++$rulename . "\">\n";
        $rewrite_rule .= "                    <match url=\"^(.*?)Sitemap\\-([a-z]{2})\\.xml\$\" ignoreCase=\"false\" />\n";
        $rewrite_rule .= "                    <action type=\"Rewrite\" url=\"index.php?" . NV_LANG_VARIABLE . "={R:2}&amp;" . NV_NAME_VARIABLE . "=SitemapIndex\" appendQueryString=\"false\" />\n";
        $rewrite_rule .= "                </rule>\n";
        $rewrite_rule .= "                <rule name=\"nv_rule_" . ++$rulename . "\">\n";
        $rewrite_rule .= "                    <match url=\"^(.*?)Sitemap\\-([a-z]{2})\\.([a-zA-Z0-9-]+)\\.xml\$\" ignoreCase=\"false\" />\n";
        $rewrite_rule .= "                    <action type=\"Rewrite\" url=\"index.php?" . NV_LANG_VARIABLE . "={R:2}&amp;" . NV_NAME_VARIABLE . "={R:3}&amp;" . NV_OP_VARIABLE . "=Sitemap\" appendQueryString=\"false\" />\n";
        $rewrite_rule .= "                </rule>\n";
        if ($sys_info['zlib_support']) {
            $rewrite_rule .= "                <rule name=\"nv_rule_" . ++$rulename . "\">\n";
            $rewrite_rule .= "                    <match url=\"^((?!http(s?)|ftp\\:\\/\\/).*)\\.(css|js)\$\" ignoreCase=\"false\" />\n";
            $rewrite_rule .= "                    <action type=\"Rewrite\" url=\"CJzip.php?file={R:1}.{R:3}\" appendQueryString=\"false\" />\n";
            $rewrite_rule .= "                </rule>\n";
        }
        $rewrite_rule .= "                <rule name=\"nv_rule_rewrite\">\n";
        $rewrite_rule .= "                \t<match url=\"(.*)(" . $endurl . ")\$\" ignoreCase=\"false\" />\n";
        $rewrite_rule .= "                \t<conditions logicalGrouping=\"MatchAll\">\n";
        $rewrite_rule .= "                \t\t<add input=\"{REQUEST_FILENAME}\" matchType=\"IsFile\" ignoreCase=\"false\" negate=\"true\" />\n";
        $rewrite_rule .= "                 \t\t<add input=\"{REQUEST_FILENAME}\" matchType=\"IsDirectory\" ignoreCase=\"false\" negate=\"true\" />\n";
        $rewrite_rule .= "                \t</conditions>\n";
        $rewrite_rule .= "                \t<action type=\"Rewrite\" url=\"index.php\" />\n";
        $rewrite_rule .= "                </rule>\n";
        $rewrite_rule = nv_rewrite_rule_iis7($rewrite_rule);
    } elseif ($sys_info['supports_rewrite'] == "rewrite_mode_apache") {
        $filename = NV_ROOTDIR . "/.htaccess";
        $htaccess = "";
        $rewrite_rule = "##################################################################################\n";
        $rewrite_rule .= "#nukeviet_rewrite_start //Please do not change the contents of the following lines\n";
        $rewrite_rule .= "##################################################################################\n\n";
        $rewrite_rule .= "#Options +FollowSymLinks\n\n";
        $rewrite_rule .= "<IfModule mod_rewrite.c>\n";
        $rewrite_rule .= "RewriteEngine On\n";
        $rewrite_rule .= "#RewriteBase " . NV_BASE_SITEURL . "\n";
        $rewrite_rule .= "RewriteCond %{REQUEST_FILENAME} /robots.txt\$ [NC]\n";
        $rewrite_rule .= "RewriteRule ^ robots.php?action=%{HTTP_HOST} [L]\n";
        $rewrite_rule .= "RewriteRule ^(.*?)Sitemap\\.xml\$ index.php?" . NV_NAME_VARIABLE . "=SitemapIndex [L]\n";
        $rewrite_rule .= "RewriteRule ^(.*?)Sitemap\\-([a-z]{2})\\.xml\$ index.php?" . NV_LANG_VARIABLE . "=\$2&" . NV_NAME_VARIABLE . "=SitemapIndex [L]\n";
        $rewrite_rule .= "RewriteRule ^(.*?)Sitemap\\-([a-z]{2})\\.([a-zA-Z0-9-]+)\\.xml\$ index.php?" . NV_LANG_VARIABLE . "=\$2&" . NV_NAME_VARIABLE . "=\$3&" . NV_OP_VARIABLE . "=Sitemap [L]\n";
        if ($sys_info['zlib_support']) {
            $rewrite_rule .= "RewriteRule ^((?!http(s?)|ftp\\:\\/\\/).*)\\.(css|js)\$ CJzip.php?file=\$1.\$3 [L]\n";
        }
        $rewrite_rule .= "RewriteCond %{REQUEST_FILENAME} !-f\n";
        $rewrite_rule .= "RewriteCond %{REQUEST_FILENAME} !-d\n";
        $rewrite_rule .= "RewriteRule (.*)(" . $endurl . ")\$ index.php\n";
        $rewrite_rule .= "</IfModule>\n\n";
        $rewrite_rule .= "#nukeviet_rewrite_end\n";
        $rewrite_rule .= "##################################################################################\n\n";
        if (file_exists($filename)) {
            $htaccess = @file_get_contents($filename);
            if (!empty($htaccess)) {
                $htaccess = preg_replace("/[\n]*[\\#]+[\n]+\\#nukeviet\\_rewrite\\_start(.*)\\#nukeviet\\_rewrite\\_end[\n]+[\\#]+[\n]*/s", "\n", $htaccess);
                $htaccess = trim($htaccess);
            }
        }
        $htaccess .= "\n\n" . $rewrite_rule;
        $rewrite_rule = $htaccess;
    }
    $errormess = false;
    if (!empty($filename) and !empty($rewrite_rule)) {
        $savefile = true;
        try {
            file_put_contents($filename, $rewrite_rule, LOCK_EX);
            if (!file_exists($filename) or filesize($filename) == 0) {
                $errormess .= sprintf($lang_module['err_writable'], NV_BASE_SITEURL . $filename);
                $savefile = false;
            }
        } catch (exception $e) {
            $savefile = false;
        }
        if (!$savefile) {
            $errormess .= sprintf($lang_module['err_writable'], NV_BASE_SITEURL . basename($filename));
        }
    }
    return $errormess;
}
Example #13
0
/**
 * nv_getFileInfo()
 *
 * @param mixed $pathimg
 * @param mixed $file
 * @return
 */
function nv_getFileInfo($pathimg, $file)
{
    global $array_images, $array_flash, $array_archives, $array_documents;
    clearstatcache();
    unset($matches);
    preg_match("/([a-zA-Z0-9\\.\\-\\_\\s\\(\\)]+)\\.([a-zA-Z0-9]+)\$/", $file, $matches);
    $info = array();
    $info['name'] = $file;
    if (isset($file[17])) {
        $info['name'] = substr($matches[1], 0, 13 - strlen($matches[2])) . '...' . $matches[2];
    }
    $info['ext'] = $matches[2];
    $info['type'] = 'file';
    $stat = @stat(NV_ROOTDIR . '/' . $pathimg . '/' . $file);
    $info['filesize'] = $stat['size'];
    $info['src'] = NV_ASSETS_DIR . '/images/file.gif';
    $info['srcwidth'] = 32;
    $info['srcheight'] = 32;
    $info['size'] = '|';
    $ext = strtolower($matches[2]);
    if (in_array($ext, $array_images)) {
        $size = @getimagesize(NV_ROOTDIR . '/' . $pathimg . '/' . $file);
        $info['type'] = 'image';
        $info['src'] = $pathimg . '/' . $file;
        $info['srcwidth'] = intval($size[0]);
        $info['srcheight'] = intval($size[1]);
        $info['size'] = intval($size[0]) . '|' . intval($size[1]);
        if (preg_match('/^' . nv_preg_quote(NV_UPLOADS_DIR) . '\\/([a-z0-9\\-\\_\\.\\/]+)$/i', $pathimg . '/' . $file, $m)) {
            if (($thub_src = nv_get_viewImage($pathimg . '/' . $file)) !== false) {
                $info['src'] = $thub_src[0];
                $info['srcwidth'] = $thub_src[1];
                $info['srcheight'] = $thub_src[2];
            }
        }
        if ($info['srcwidth'] > 80) {
            $info['srcheight'] = round(80 / $info['srcwidth'] * $info['srcheight']);
            $info['srcwidth'] = 80;
        }
        if ($info['srcheight'] > 80) {
            $info['srcwidth'] = round(80 / $info['srcheight'] * $info['srcwidth']);
            $info['srcheight'] = 80;
        }
    } elseif (in_array($ext, $array_flash)) {
        $info['type'] = 'flash';
        $info['src'] = NV_ASSETS_DIR . '/images/flash.gif';
        if ($matches[2] == 'swf') {
            $size = @getimagesize(NV_ROOTDIR . '/' . $pathimg . '/' . $file);
            if (isset($size, $size[0], $size[1])) {
                $info['size'] = $size[0] . '|' . $size[1];
            }
        }
    } elseif (in_array($ext, $array_archives)) {
        $info['src'] = NV_ASSETS_DIR . '/images/zip.gif';
    } elseif (in_array($ext, $array_documents)) {
        if ($ext == 'doc' or $ext == 'docx') {
            $info['src'] = NV_ASSETS_DIR . '/images/msword.png';
        } elseif ($ext == 'xls' or $ext == 'xlsx') {
            $info['src'] = NV_ASSETS_DIR . '/images/excel.png';
        } elseif ($ext == 'pdf') {
            $info['src'] = NV_ASSETS_DIR . '/images/pdf.png';
        } else {
            $info['src'] = NV_ASSETS_DIR . '/images/doc.gif';
        }
    }
    $info['userid'] = 0;
    $info['mtime'] = $stat['mtime'];
    return $info;
}
/**
 * nv_is_file()
 *
 * @param mixed $filepath
 * @param mixed $folders
 * @return
 */
function nv_is_file($filepath, $folders = array())
{
    if (empty($folders)) {
        $folders = array(NV_UPLOADS_DIR, NV_ASSETS_DIR . '/images');
    } elseif (!is_array($folders)) {
        $folders = array($folders);
    }
    $filepath = htmlspecialchars(trim(NV_DOCUMENT_ROOT . $filepath), ENT_QUOTES);
    $filepath = rtrim($filepath, '/');
    if (empty($filepath)) {
        return false;
    }
    if (($filepath = realpath($filepath)) === false) {
        return false;
    }
    $filepath = str_replace("\\", '/', $filepath);
    $file_exists = 0;
    foreach ($folders as $folder) {
        if (preg_match('/^' . nv_preg_quote(NV_ROOTDIR . '/' . $folder) . '/', $filepath) and is_file($filepath)) {
            $file_exists++;
        }
    }
    return $file_exists > 0 ? true : false;
}
Example #15
0
}
$newalt = $nv_Request->get_title('newalt', 'post', $newname, 1);
$ext = nv_getextension($file);
$newname = $newname . '.' . $ext;
if ($file != $newname) {
    $newname2 = $newname;
    $i = 1;
    while (file_exists(NV_ROOTDIR . '/' . $path . '/' . $newname2)) {
        $newname2 = preg_replace('/(.*)(\\.[a-zA-Z0-9]+)$/', '\\1_' . $i . '\\2', $newname);
        ++$i;
    }
    $newname = $newname2;
    if (!@rename(NV_ROOTDIR . '/' . $path . '/' . $file, NV_ROOTDIR . '/' . $path . '/' . $newname)) {
        die('ERROR_' . $lang_module['errorNotRenameFile']);
    }
    if (preg_match('/^' . nv_preg_quote(NV_UPLOADS_DIR) . '\\/(([a-z0-9\\-\\_\\/]+\\/)*([a-z0-9\\-\\_\\.]+)(\\.(gif|jpg|jpeg|png|bmp)))$/i', $path . '/' . $file, $m)) {
        @nv_deletefile(NV_ROOTDIR . '/' . NV_FILES_DIR . '/' . $m[1]);
    }
    if (isset($array_dirname[$path])) {
        $info = nv_getFileInfo($path, $newname);
        $sth = $db->prepare("UPDATE " . NV_UPLOAD_GLOBALTABLE . "_file SET name = '" . $info['name'] . "', src = '" . $info['src'] . "', title = '" . $newname . "', alt = :newalt WHERE did = " . $array_dirname[$path] . " AND title = '" . $file . "'");
        $sth->bindParam(':newalt', $newalt, PDO::PARAM_STR);
        $sth->execute();
    }
    nv_insert_logs(NV_LANG_DATA, $module_name, $lang_module['rename'], $path . '/' . $file . ' -> ' . $path . '/' . $newname, $admin_info['userid']);
} else {
    $sth = $db->prepare("UPDATE " . NV_UPLOAD_GLOBALTABLE . "_file SET alt = :newalt WHERE did = " . $array_dirname[$path] . " AND title = '" . $file . "'");
    $sth->bindParam(':newalt', $newalt, PDO::PARAM_STR);
    $sth->execute();
    nv_insert_logs(NV_LANG_DATA, $module_name, $lang_module['rename'], $path . '/' . $file . ' -> ' . $path . '/' . $newname, $admin_info['userid']);
}
Example #16
0
     $db->sql_query("REPLACE INTO `" . NV_CONFIG_GLOBALTABLE . "` (`lang`, `module`, `config_name`, `config_value`) VALUES ('sys', 'global', 'timestamp', " . $timestamp . ")");
     nv_save_file_config_global();
 }
 if (in_array('clearsession', $deltype)) {
     $ssDir = NV_ROOTDIR . "/" . NV_SESSION_SAVE_PATH;
     $files = nv_clear_files($ssDir, NV_SESSION_SAVE_PATH);
     foreach ($files as $file) {
         $xtpl->assign('DELFILE', $file);
         $xtpl->parse('main.delfile.loop');
     }
 }
 if (in_array('clearfiletemp', $deltype)) {
     $dir = NV_ROOTDIR . "/" . NV_TEMP_DIR;
     if ($dh = opendir($dir)) {
         while (($file = readdir($dh)) !== false) {
             if (preg_match("/^(" . nv_preg_quote(NV_TEMPNAM_PREFIX) . ")[a-zA-Z0-9\\_\\.]+\$/", $file)) {
                 if (is_file($dir . '/' . $file)) {
                     if (@unlink($dir . '/' . $file)) {
                         $xtpl->assign('DELFILE', NV_TEMP_DIR . '/' . $file);
                         $xtpl->parse('main.delfile.loop');
                     }
                 } else {
                     $rt = nv_deletefile($dir . '/' . $file, true);
                     if ($rt[0] == 1) {
                         $xtpl->assign('DELFILE', NV_TEMP_DIR . '/' . $file);
                         $xtpl->parse('main.delfile.loop');
                     }
                 }
             }
         }
         closedir($dh);
Example #17
0
/**
 * BoldKeywordInStr()
 *
 * @param mixed $str
 * @param mixed $keyword
 * @return
 */
function BoldKeywordInStr($str, $keyword, $logic)
{
    $str = nv_br2nl($str);
    $str = nv_nl2br($str, ' ');
    $str = nv_unhtmlspecialchars(strip_tags(trim($str)));
    $pos = false;
    if ($logic == 'AND') {
        $array_keyword = array($keyword, nv_EncString($keyword));
    } else {
        $keyword .= ' ' . nv_EncString($keyword);
        $array_keyword = explode(' ', $keyword);
        $array_keyword = array_unique($array_keyword);
    }
    foreach ($array_keyword as $k) {
        if (preg_match('/^(.*?)' . nv_preg_quote($k) . '/uis', $str, $matches)) {
            $strlen = nv_strlen($str);
            $kstrlen = nv_strlen($k);
            $residual = $strlen - 300;
            if ($residual > 0) {
                $lstrlen = nv_strlen($matches[1]);
                $rstrlen = $strlen - $lstrlen - $kstrlen;
                $medium = round((300 - $kstrlen) / 2);
                if ($lstrlen <= $medium) {
                    $str = nv_clean60($str, 300);
                } elseif ($rstrlen <= $medium) {
                    $str = nv_substr($str, $residual, 300);
                    $str = nv_substr_clean($str, 'l');
                } else {
                    $str = nv_substr($str, $lstrlen - $medium, $strlen - $lstrlen + $medium);
                    $str = nv_substr($str, 0, 300);
                    $str = nv_substr_clean($str, 'lr');
                }
            }
            $pos = true;
            break;
        }
    }
    if (!$pos) {
        return nv_clean60($str, 300);
    }
    $pattern = array();
    foreach ($array_keyword as $k) {
        $pattern[] = '/(' . nv_preg_quote($k) . ')/uis';
    }
    $str = preg_replace($pattern, '{\\1}', $str);
    $str = str_replace(array('{', '}'), array('<span class="keyword">', '</span>'), $str);
    return $str;
}
Example #18
0
/**
 * nv_redirect_decrypt()
 *
 * @param tring $string
 * @param boolean $insite
 * @return string
 *
 */
function nv_redirect_decrypt($string, $insite = true)
{
    if (empty($string)) {
        return '';
    }
    if (preg_match('/[^a-z0-9\\-\\_\\,]/i', $string)) {
        return '';
    }
    $string = nv_base64_decode($string);
    if (!$string) {
        return '';
    }
    global $crypt;
    $url = $crypt->aes_decrypt($string, NV_CHECK_SESSION);
    if (empty($url)) {
        return '';
    }
    if (preg_match('/^(http|https|ftp|gopher)\\:\\/\\//i', $url)) {
        if ($insite and !preg_match('/^' . nv_preg_quote(NV_MY_DOMAIN) . '/', $url)) {
            return '';
        }
        if (!nv_is_url($url)) {
            return '';
        }
    } elseif (!nv_is_url(NV_MY_DOMAIN . $url)) {
        return '';
    }
    return $url;
}
Example #19
0
/**
 * nv_check_bot()
 *
 * @return
 */
function nv_check_bot()
{
    global $client_info;
    $file_bots = NV_ROOTDIR . "/" . NV_DATADIR . "/bots.config";
    $bots = (file_exists($file_bots) and filesize($file_bots)) ? unserialize(file_get_contents($file_bots)) : array();
    if (empty($bots) and file_exists(NV_ROOTDIR . "/includes/bots.php")) {
        include NV_ROOTDIR . "/includes/bots.php";
    }
    if (empty($bots)) {
        return array();
    }
    foreach ($bots as $name => $values) {
        $is_bot = false;
        if ($values['agent'] and preg_match('#' . str_replace('\\*', '.*?', nv_preg_quote($values['agent'], '#')) . '#i', $client_info['agent'])) {
            $is_bot = true;
        }
        if (!empty($values['ips']) and ($is_bot or !$values['agent'])) {
            $is_bot = false;
            $ips = implode("|", array_map("nv_preg_quote", explode("|", $values['ips'])));
            if (preg_match("/^" . $ips . "/", $client_info['ip'])) {
                $is_bot = true;
            }
        }
        if ($is_bot) {
            return array('name' => $name, 'agent' => $values['agent'], 'ip' => $client_info['ip'], 'allowed' => $values['allowed']);
        }
    }
    return array();
}
Example #20
0
/**
 * nv_redirect_decrypt()
 *
 * @param tring $string
 * @param boolean $insite
 * @return string
 *
 */
function nv_redirect_decrypt($string, $insite = true)
{
    global $global_config, $crypt, $client_info;
    if (empty($string)) {
        return '';
    }
    if (preg_match('/[^a-z0-9\\-\\_\\,]/i', $string)) {
        return '';
    }
    $string = nv_base64_decode($string);
    if (!$string) {
        return '';
    }
    $url = $crypt->aes_decrypt($string, md5($global_config['sitekey'] . $client_info['session_id']));
    if (empty($url)) {
        return '';
    }
    if (preg_match('/^(http|https|ftp|gopher)\\:\\/\\//i', $url)) {
        if ($insite and !preg_match('/^' . nv_preg_quote(NV_MY_DOMAIN) . '/', $url)) {
            return '';
        }
        if (!nv_is_url($url)) {
            return '';
        }
    } elseif (!nv_is_url(NV_MY_DOMAIN . $url)) {
        return '';
    }
    return $url;
}
Example #21
0
             $table = $tablename[$key];
             if (!empty($table)) {
                 $table = str_replace("_", "-", $table);
                 $table = change_alias($table);
                 $table = str_replace("-", "_", $table);
             } else {
                 $table = strtolower($matches[1]);
                 $array_fiter = array('create table if not exists', 'create table', '(', '`');
                 $table = str_replace($array_fiter, '', $table);
                 $table = preg_replace('/(\\W+)/i', '_', trim($table));
                 $table = preg_replace("/^" . nv_preg_quote(NV_PREFIXLANG . '_' . $data_system['module_data'] . '_') . "(.*)\$/", "\\1", $table);
                 $table = preg_replace("/^" . nv_preg_quote(NV_PREFIXLANG . '_' . $data_system['module_data']) . "(.*)\$/", "\\1", $table);
                 $table = preg_replace("/^" . nv_preg_quote($db_config['prefix'] . '_' . $data_system['module_data'] . '_') . "(.*)\$/", "\\1", $table);
                 $table = preg_replace("/^" . nv_preg_quote($db_config['prefix'] . '_' . $data_system['module_data']) . "(.*)\$/", "\\1", $table);
                 $table = preg_replace("/^" . nv_preg_quote(NV_PREFIXLANG . '_') . "(.*)\$/", "\\1", $table);
                 $table = preg_replace("/^" . nv_preg_quote($db_config['prefix'] . '_') . "(.*)\$/", "\\1", $table);
             }
             $data_sql[] = array('table' => $table, 'sql' => $sql);
         } elseif (strlen($sql) > 10) {
             $table = $tablename[$key];
             if (!empty($table)) {
                 $table = str_replace("_", "-", $table);
                 $table = change_alias($table);
                 $table = str_replace("-", "_", $table);
             }
             $data_sql[] = array('table' => $table, 'sql' => $sql);
         }
     }
 }
 if (!empty($data_system['module_name'])) {
     if ($nv_Request->get_string('download', 'post', 0)) {
Example #22
0
        if ($url_rewrite != $_SERVER['REQUEST_URI']) {
            Header("Location: " . $url_rewrite);
            die;
        }
    } elseif ($global_config['rewrite_optional'] && preg_match("/^" . nv_preg_quote(NV_BASE_SITEURL . NV_LANG_DATA . "/") . "/i", $_SERVER['REQUEST_URI'])) {
        $url_rewrite = preg_replace("/^" . nv_preg_quote(NV_BASE_SITEURL . NV_LANG_DATA . "/") . "(.*)\$/", NV_BASE_SITEURL . "\\1", $_SERVER['REQUEST_URI']);
        Header("Location: " . $url_rewrite);
        die;
    } elseif ($global_config['rewrite_optional'] && preg_match("/^" . nv_preg_quote(NV_BASE_SITEURL . "index.php/" . NV_LANG_DATA . "/") . "/i", $_SERVER['REQUEST_URI'])) {
        $url_rewrite = preg_replace("/^" . nv_preg_quote(NV_BASE_SITEURL . "index.php/" . NV_LANG_DATA . "/") . "(.*)\$/", NV_BASE_SITEURL . "\\1", $_SERVER['REQUEST_URI']);
        Header("Location: " . $url_rewrite);
        die;
    }
} elseif (empty($global_config['lang_multi']) and $global_config['rewrite_optional']) {
    require NV_ROOTDIR . "/includes/rewrite_language.php";
    if (preg_match("/^" . nv_preg_quote(NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA) . "/i", $_SERVER['REQUEST_URI'])) {
        $url_rewrite = nv_url_rewrite($_SERVER['REQUEST_URI'], true);
        if ($url_rewrite != $_SERVER['REQUEST_URI']) {
            Header("Location: " . $url_rewrite);
            die;
        }
    }
}
if (defined('NV_ADMIN')) {
    if (!in_array(NV_LANG_DATA, $global_config['allow_adminlangs'])) {
        if ($global_config['lang_multi']) {
            $nv_Request->set_Cookie('data_lang', $global_config['site_lang'], NV_LIVE_COOKIE_TIME);
        }
        Header("Location: " . NV_BASE_ADMINURL);
        exit;
    }
Example #23
0
$newpath = $matches[1] . '/' . $newname;
if (is_dir(NV_ROOTDIR . '/' . $newpath)) {
    die('ERROR_' . $lang_module['folder_exists']);
}
if (rename(NV_ROOTDIR . '/' . $path, NV_ROOTDIR . '/' . $newpath)) {
    $action = 0;
    if (preg_match('/^' . nv_preg_quote(NV_UPLOADS_DIR) . '\\/([a-z0-9\\-\\_\\/]+)$/i', $path, $m1) and preg_match('/^' . nv_preg_quote(NV_UPLOADS_DIR) . '\\/([a-z0-9\\-\\_\\/]+)$/i', $newpath, $m2)) {
        rename(NV_ROOTDIR . '/' . NV_FILES_DIR . '/' . $m1[1], NV_ROOTDIR . '/' . NV_FILES_DIR . '/' . $m2[1]);
        $action = 1;
        $dir_replace1 = NV_FILES_DIR . '/' . $m1[1] . '/';
        $dir_replace2 = NV_FILES_DIR . '/' . $m2[1] . '/';
    }
    $result = $db->query("SELECT did, dirname FROM " . NV_UPLOAD_GLOBALTABLE . "_dir WHERE dirname='" . $path . "' OR dirname LIKE '" . $path . "/%'");
    while (list($did, $dirname) = $result->fetch(3)) {
        $dirname2 = str_replace(NV_ROOTDIR . '/' . $path, $newpath, NV_ROOTDIR . '/' . $dirname);
        $result_file = $db->query("SELECT src, title FROM " . NV_UPLOAD_GLOBALTABLE . "_file WHERE did=" . $did . " AND type = 'image'");
        while (list($src, $title) = $result_file->fetch(3)) {
            if ($action) {
                $src2 = preg_replace('/^' . nv_preg_quote($dir_replace1) . '/', $dir_replace2, $src);
            } else {
                $src2 = preg_replace('/^' . nv_preg_quote($dirname) . '/', $dirname2, $src);
            }
            $db->query("UPDATE " . NV_UPLOAD_GLOBALTABLE . "_file SET src = '" . $src2 . "' WHERE did = " . $did . " AND title='" . $title . "'");
        }
        $db->query("UPDATE " . NV_UPLOAD_GLOBALTABLE . "_dir SET dirname = '" . $dirname2 . "' WHERE did = " . $did);
    }
    nv_insert_logs(NV_LANG_DATA, $module_name, $lang_module['renamefolder'], $path . ' -> ' . $newpath, $admin_info['userid']);
    echo $newpath;
} else {
    die('ERROR_' . $lang_module['rename_error_folder']);
}
/**
 * @Project NUKEVIET 4.x
 * @Author VINADES.,JSC (contact@vinades.vn)
 * @Copyright (C) 2014 VINADES.,JSC. All rights reserved
 * @License GNU/GPL version 2 or any later version
 * @Createdate 12/31/2009 0:51
 */
if (!defined('NV_MOD_OAUTH2')) {
    die('Stop!!!');
}
// Include our OAuth2 Server object
require_once NV_ROOTDIR . '/modules/' . $module_file . '/server.php';
$request = OAuth2\Request::createFromGlobals();
// Handle a request to a resource and authenticate the access token
if (!$server->verifyResourceRequest($request)) {
    $server->getResponse()->send();
    die;
}
$token = $server->getAccessTokenData($request);
$result = array();
if ($token['user_id']) {
    $sql = 'SELECT * FROM ' . NV_USERS_GLOBALTABLE . ' WHERE userid = ' . intval($token['user_id']) . ' AND active =1';
    $user = $db->query($sql)->fetch();
    if (!empty($user)) {
        $result = array('id' => md5($global_config['sitekey'] . $user['userid']), 'link' => preg_replace("/^" . nv_preg_quote(NV_BASE_SITEURL) . "([a-z]{2})\\//", NV_BASE_SITEURL, nv_url_rewrite(NV_BASE_SITEURL . 'index.php?' . NV_LANG_VARIABLE . '=' . NV_LANG_DATA . '&' . NV_NAME_VARIABLE . '=' . $module_name . '&' . NV_OP_VARIABLE . '=' . $op . '/' . md5($global_config['sitekey'] . $user['userid']), true)), 'email' => $user['email'], 'first_name' => $user['first_name'], 'last_name' => $user['last_name'], 'name' => $user['username'], 'gender' => $user['gender']);
    }
    unset($user);
    $db->query('DELETE FROM ' . $dbtable_config['access_token_table'] . ' WHERE user_id = ' . intval($token['user_id']));
}
echo json_encode($result);
die;
 /**
  * download::real_path()
  * 
  * @param mixed $path
  * @return
  */
 function real_path($path, $dir)
 {
     if (empty($path) or !is_readable($path) or !is_file($path)) {
         return false;
     }
     $realpath = realpath($path);
     if (empty($realpath)) {
         return false;
     }
     $realpath = str_replace('\\', '/', $realpath);
     $realpath = rtrim($realpath, "\\/");
     if (!preg_match("/^(" . nv_preg_quote($dir) . ")(\\/[\\S]+)/", $realpath)) {
         return false;
     }
     return $realpath;
 }
Example #26
0
/**
 * nv_check_bot()
 *
 * @return
 */
function nv_check_bot()
{
    $file_bots = NV_ROOTDIR . '/' . NV_DATADIR . '/bots.config';
    $bots = (file_exists($file_bots) and filesize($file_bots)) ? unserialize(file_get_contents($file_bots)) : array();
    if (empty($bots) and file_exists(NV_ROOTDIR . '/includes/bots.php')) {
        include NV_ROOTDIR . '/includes/bots.php';
    }
    if (empty($bots)) {
        return array();
    }
    foreach ($bots as $name => $values) {
        $is_bot = false;
        if ($values['agent'] and preg_match('#' . str_replace('\\*', '.*?', nv_preg_quote($values['agent'], '#')) . '#i', NV_USER_AGENT)) {
            $is_bot = true;
        }
        if (!empty($values['ips']) and ($is_bot or !$values['agent'])) {
            $is_bot = false;
            $ips = implode('|', array_map('nv_preg_quote', explode('|', $values['ips'])));
            if (preg_match('/^' . $ips . '/', NV_CLIENT_IP)) {
                $is_bot = true;
            }
        }
        if ($is_bot) {
            return array('name' => $name, 'agent' => $values['agent'], 'ip' => NV_CLIENT_IP, 'allowed' => $values['allowed']);
        }
    }
    return array();
}
Example #27
0
/**
 * nv_rss_generate()
 *
 * @param mixed $channel
 * @param mixed $items
 * @return void
 */
function nv_rss_generate($channel, $items)
{
    global $db, $global_config, $client_info;
    $xtpl = new XTemplate('rss.tpl', NV_ROOTDIR . '/themes/default/layout/');
    $xtpl->assign('CSSPATH', NV_BASE_SITEURL . 'themes/default/css/rss.xsl');
    //Chi co tac dung voi IE6 va Chrome
    $channel['title'] = nv_htmlspecialchars($channel['title']);
    $channel['atomlink'] = str_replace('&', '&amp;', $client_info['selfurl']);
    $channel['lang'] = $global_config['site_lang'];
    $channel['copyright'] = $global_config['site_name'];
    $channel['docs'] = NV_MY_DOMAIN . nv_url_rewrite(NV_BASE_SITEURL . 'index.php?' . NV_LANG_VARIABLE . '=' . NV_LANG_DATA . '&amp;' . NV_NAME_VARIABLE . '=rss', true);
    $channel['generator'] = 'Nukeviet Version 4';
    if (preg_match('/^' . nv_preg_quote(NV_MY_DOMAIN . NV_BASE_SITEURL) . '(.+)$/', $channel['link'], $matches)) {
        $channel['link'] = $matches[1];
    } elseif (preg_match('/^' . nv_preg_quote(NV_BASE_SITEURL) . '(.+)$/', $channel['link'], $matches)) {
        $channel['link'] = $matches[1];
    }
    $channel['link'] = NV_MY_DOMAIN . nv_url_rewrite(NV_BASE_SITEURL . $channel['link'], true);
    if (preg_match('/^' . nv_preg_quote(NV_MY_DOMAIN . NV_BASE_SITEURL) . '(.+)$/', $channel['atomlink'], $matches)) {
        $channel['atomlink'] = $matches[1];
    } elseif (preg_match('/^' . nv_preg_quote(NV_BASE_SITEURL) . '(.+)$/', $channel['atomlink'], $matches)) {
        $channel['atomlink'] = $matches[1];
    }
    $channel['atomlink'] = NV_MY_DOMAIN . nv_url_rewrite(NV_BASE_SITEURL . $channel['atomlink'], true);
    $channel['pubDate'] = 0;
    if (!empty($items)) {
        foreach ($items as $item) {
            if (!empty($item['title']) and !empty($item['link'])) {
                $item['title'] = nv_htmlspecialchars($item['title']);
                if (isset($item['pubdate']) and !empty($item['pubdate'])) {
                    $item['pubdate'] = intval($item['pubdate']);
                    $channel['pubDate'] = max($channel['pubDate'], $item['pubdate']);
                    $item['pubdate'] = gmdate('D, j M Y H:m:s', $item['pubdate']) . ' GMT';
                }
                if (preg_match('/^' . nv_preg_quote(NV_MY_DOMAIN . NV_BASE_SITEURL) . '(.+)$/', $item['link'], $matches)) {
                    $item['link'] = $matches[1];
                } elseif (preg_match('/^' . nv_preg_quote(NV_BASE_SITEURL) . '(.+)$/', $item['link'], $matches)) {
                    $item['link'] = $matches[1];
                }
                $item['link'] = NV_MY_DOMAIN . nv_url_rewrite(NV_BASE_SITEURL . $item['link'], true);
                $xtpl->assign('ITEM', $item);
                if (isset($item['guid']) and !empty($item['guid'])) {
                    $xtpl->parse('main.item.guid');
                }
                if (isset($item['pubdate']) and !empty($item['pubdate'])) {
                    $xtpl->parse('main.item.pubdate');
                }
                $xtpl->parse('main.item');
            }
        }
    }
    $lastModified = NV_CURRENTTIME;
    if (!empty($channel['pubDate'])) {
        $lastModified = $channel['pubDate'];
        $channel['pubDate'] = gmdate('D, j M Y H:m:s', $channel['pubDate']) . ' GMT';
    }
    $xtpl->assign('CHANNEL', $channel);
    if (!empty($channel['description'])) {
        $xtpl->parse('main.description');
    }
    if (!empty($channel['pubDate'])) {
        $xtpl->parse('main.pubDate');
    }
    $image = file_exists(NV_ROOTDIR . '/' . $global_config['site_logo']) ? NV_ROOTDIR . '/' . $global_config['site_logo'] : NV_ROOTDIR . '/images/logo.png';
    $image = nv_ImageInfo($image, 144, true, NV_UPLOADS_REAL_DIR);
    if (!empty($image)) {
        $resSize = nv_imageResize($image['width'], $image['height'], 144, 400);
        $image['width'] = $resSize['width'];
        $image['height'] = $resSize['height'];
        $image['title'] = $channel['title'];
        $image['link'] = $channel['link'];
        $image['src'] = NV_MY_DOMAIN . nv_url_rewrite($image['src'], true);
        $xtpl->assign('IMAGE', $image);
        $xtpl->parse('main.image');
    }
    $xtpl->parse('main');
    $content = $xtpl->text('main');
    nv_xmlOutput($content, $lastModified);
}
/**
 * nv_ImageInfo()
 * Function xuat ra cac thong tin ve IMAGE de dua vao HTML (src, width, height).
 * 
 * @param mixed $original_name - duong dan tuyet doi den file goc (bat buoc)
 * @param integer $width - chieu rong xuat ra HTML (neu bang 0 se xuat ra kich thuoc thuc)
 * @param bool $is_create_thumb - Neu chieu rong cua hinh lon hon $width, co the tao thumbnail
 * @param string $thumb_path - neu tao thumbnail thi chi ra thu muc chua file thumbnail nay.
 * @return array('src','width','height')
 */
function nv_ImageInfo($original_name, $width = 0, $is_create_thumb = false, $thumb_path = '')
{
    if (empty($original_name)) {
        return false;
    }
    $original_name = realpath($original_name);
    if (empty($original_name)) {
        return false;
    }
    $original_name = str_replace('\\', '/', $original_name);
    $original_name = rtrim($original_name, "\\/");
    unset($matches);
    if (!preg_match("/^" . nv_preg_quote(NV_ROOTDIR) . "\\/(([a-z0-9\\-\\_\\/]+\\/)*([a-z0-9\\-\\_\\.]+)(\\.(gif|jpg|jpeg|png)))\$/i", $original_name, $matches)) {
        return false;
    }
    $imageinfo = array();
    $size = @getimagesize($original_name);
    if (!$size or !isset($size[0]) or !isset($size[1]) or !$size[0] or !$size[1]) {
        return false;
    }
    $imageinfo['orig_src'] = $imageinfo['src'] = NV_BASE_SITEURL . $matches[1];
    $imageinfo['orig_width'] = $imageinfo['width'] = $size[0];
    $imageinfo['orig_height'] = $imageinfo['height'] = $size[1];
    if ($width) {
        $imageinfo['width'] = $width;
        $imageinfo['height'] = ceil($width * $imageinfo['orig_height'] / $imageinfo['orig_width']);
    }
    if ($is_create_thumb and $width and $imageinfo['orig_width'] > $width) {
        if (empty($thumb_path) or !is_dir($thumb_path) or !is_writeable($thumb_path)) {
            $thumb_path = $matches[2];
        } else {
            $thumb_path = realpath($thumb_path);
            if (empty($thumb_path)) {
                $thumb_path = $matches[2];
            } else {
                $thumb_path = str_replace('\\', '/', $thumb_path);
                unset($matches2);
                if (preg_match("/^" . nv_preg_quote(NV_ROOTDIR) . "([a-z0-9\\-\\_\\/]+)*\$/i", $thumb_path, $matches2)) {
                    $thumb_path = ltrim($matches2[1], "\\/");
                } else {
                    $thumb_path = $matches[2];
                }
            }
        }
        if (!empty($thumb_path) and !preg_match("/\\/\$/", $thumb_path)) {
            $thumb_path = $thumb_path . '/';
        }
        $new_src = $thumb_path . $matches[3] . '_' . $width . $matches[4];
        $is_create = true;
        if (file_exists(NV_ROOTDIR . '/' . $new_src)) {
            $size = @getimagesize(NV_ROOTDIR . '/' . $new_src);
            if ($size and isset($size[0]) and isset($size[1]) and $size[0] and $size[1]) {
                $imageinfo['src'] = NV_BASE_SITEURL . $new_src;
                $imageinfo['width'] = $size[0];
                $imageinfo['height'] = $size[1];
                $is_create = false;
            }
        }
        if ($is_create) {
            include NV_ROOTDIR . "/includes/class/image.class.php";
            $image = new image($original_name, NV_MAX_WIDTH, NV_MAX_HEIGHT);
            $image->resizeXY($width);
            $image->save(NV_ROOTDIR . '/' . $thumb_path, $matches[3] . '_' . $width . $matches[4]);
            $image_info = $image->create_Image_info;
            if (file_exists(NV_ROOTDIR . '/' . $new_src)) {
                $imageinfo['src'] = NV_BASE_SITEURL . $new_src;
                $imageinfo['width'] = $image_info['width'];
                $imageinfo['height'] = $image_info['height'];
            }
        }
    }
    return $imageinfo;
}
Example #29
0
/**
 * nv_rewrite_change()
 *
 * @param mixed $rewrite_optional
 * @return
 */
function nv_rewrite_change($array_config_global)
{
    global $sys_info, $lang_module;
    $rewrite_rule = $filename = '';
    $endurl = $array_config_global['rewrite_endurl'] == $array_config_global['rewrite_exturl'] ? nv_preg_quote($array_config_global['rewrite_endurl']) : nv_preg_quote($array_config_global['rewrite_endurl']) . '|' . nv_preg_quote($array_config_global['rewrite_exturl']);
    if ($sys_info['supports_rewrite'] == 'rewrite_mode_iis') {
        $filename = NV_ROOTDIR . '/web.config';
        $rulename = 0;
        $rewrite_rule .= "\n";
        $rewrite_rule .= " <rule name=\"nv_rule_" . ++$rulename . "\">\n";
        $rewrite_rule .= " <match url=\"^\" ignoreCase=\"false\" />\n";
        $rewrite_rule .= " <conditions>\n";
        $rewrite_rule .= " \t\t<add input=\"{REQUEST_FILENAME}\" pattern=\"/robots.txt\$\" />\n";
        $rewrite_rule .= " </conditions>\n";
        $rewrite_rule .= " <action type=\"Rewrite\" url=\"robots.php?action={HTTP_HOST}\" appendQueryString=\"false\" />\n";
        $rewrite_rule .= " </rule>\n";
        $rewrite_rule .= " <rule name=\"nv_rule_" . ++$rulename . "\">\n";
        $rewrite_rule .= " <match url=\"^(.*?)sitemap\\.xml\$\" ignoreCase=\"false\" />\n";
        $rewrite_rule .= " <action type=\"Rewrite\" url=\"index.php?" . NV_NAME_VARIABLE . "=SitemapIndex\" appendQueryString=\"false\" />\n";
        $rewrite_rule .= " </rule>\n";
        $rewrite_rule .= " <rule name=\"nv_rule_" . ++$rulename . "\">\n";
        $rewrite_rule .= " <match url=\"^(.*?)sitemap\\-([a-z]{2})\\.xml\$\" ignoreCase=\"false\" />\n";
        $rewrite_rule .= " <action type=\"Rewrite\" url=\"index.php?" . NV_LANG_VARIABLE . "={R:2}&amp;" . NV_NAME_VARIABLE . "=SitemapIndex\" appendQueryString=\"false\" />\n";
        $rewrite_rule .= " </rule>\n";
        $rewrite_rule .= " <rule name=\"nv_rule_" . ++$rulename . "\">\n";
        $rewrite_rule .= " <match url=\"^(.*?)sitemap\\-([a-z]{2})\\.([a-zA-Z0-9-]+)\\.xml\$\" ignoreCase=\"false\" />\n";
        $rewrite_rule .= " <action type=\"Rewrite\" url=\"index.php?" . NV_LANG_VARIABLE . "={R:2}&amp;" . NV_NAME_VARIABLE . "={R:3}&amp;" . NV_OP_VARIABLE . "=sitemap\" appendQueryString=\"false\" />\n";
        $rewrite_rule .= " </rule>\n";
        if ($sys_info['zlib_support']) {
            $rewrite_rule .= " <rule name=\"nv_rule_" . ++$rulename . "\">\n";
            $rewrite_rule .= " <match url=\"^((?!http(s?)|ftp\\:\\/\\/).*)\\.(css|js)\$\" ignoreCase=\"false\" />\n";
            $rewrite_rule .= " <action type=\"Rewrite\" url=\"CJzip.php?file={R:1}.{R:3}\" appendQueryString=\"false\" />\n";
            $rewrite_rule .= " </rule>\n";
        }
        $rewrite_rule .= " <rule name=\"nv_rule_rewrite\">\n";
        $rewrite_rule .= " \t<match url=\"(.*)(" . $endurl . ")\$\" ignoreCase=\"false\" />\n";
        $rewrite_rule .= " \t<conditions logicalGrouping=\"MatchAll\">\n";
        $rewrite_rule .= " \t\t<add input=\"{REQUEST_FILENAME}\" matchType=\"IsFile\" ignoreCase=\"false\" negate=\"true\" />\n";
        $rewrite_rule .= " \t\t<add input=\"{REQUEST_FILENAME}\" matchType=\"IsDirectory\" ignoreCase=\"false\" negate=\"true\" />\n";
        $rewrite_rule .= " \t</conditions>\n";
        $rewrite_rule .= " \t<action type=\"Rewrite\" url=\"index.php\" />\n";
        $rewrite_rule .= " </rule>\n";
        if ($array_config_global['rewrite_optional']) {
            if (!empty($array_config_global['rewrite_op_mod'])) {
                if ($array_config_global['rewrite_op_mod'] == 'seek') {
                    $rewrite_rule .= " <rule name=\"nv_rule_" . ++$rulename . "\">\n";
                    $rewrite_rule .= " <match url=\"^q\\=(.*)\$\" ignoreCase=\"false\" />\n";
                    $rewrite_rule .= " <action type=\"Rewrite\" url=\"index.php?" . NV_NAME_VARIABLE . "=seek&amp;q={R:1}\" appendQueryString=\"false\" />\n";
                    $rewrite_rule .= " </rule>\n";
                } else {
                    $rewrite_rule .= " <rule name=\"nv_rule_" . ++$rulename . "\">\n";
                    $rewrite_rule .= " <match url=\"^seek\\/q\\=(.*)\$\" ignoreCase=\"false\" />\n";
                    $rewrite_rule .= " <action type=\"Rewrite\" url=\"index.php?" . NV_NAME_VARIABLE . "=seek&amp;q={R:1}\" appendQueryString=\"false\" />\n";
                    $rewrite_rule .= " </rule>\n";
                }
                $rewrite_rule .= " <rule name=\"nv_rule_" . ++$rulename . "\">\n";
                $rewrite_rule .= " <match url=\"^search\\/q\\=(.*)\$\" ignoreCase=\"false\" />\n";
                $rewrite_rule .= " <action type=\"Rewrite\" url=\"index.php?" . NV_NAME_VARIABLE . "=" . $array_config_global['rewrite_op_mod'] . "&amp;" . NV_OP_VARIABLE . "=search&amp;q={R:1}\" appendQueryString=\"false\" />\n";
                $rewrite_rule .= " </rule>\n";
            } else {
                $rewrite_rule .= " <rule name=\"nv_rule_" . ++$rulename . "\">\n";
                $rewrite_rule .= " <match url=\"^seek\\/q\\=(.*)\$\" ignoreCase=\"false\" />\n";
                $rewrite_rule .= " <action type=\"Rewrite\" url=\"index.php?" . NV_NAME_VARIABLE . "=seek&amp;q={R:1}\" appendQueryString=\"false\" />\n";
                $rewrite_rule .= " </rule>\n";
            }
            $rewrite_rule .= " <rule name=\"nv_rule_" . ++$rulename . "\">\n";
            $rewrite_rule .= " <match url=\"^([a-zA-Z0-9\\-]+)\\/search\\/q\\=(.*)\$\" ignoreCase=\"false\" />\n";
            $rewrite_rule .= " <action type=\"Rewrite\" url=\"index.php?" . NV_NAME_VARIABLE . "={R:1}&amp;" . NV_OP_VARIABLE . "=search&amp;q={R:2}\" appendQueryString=\"false\" />\n";
            $rewrite_rule .= " </rule>\n";
        } else {
            $rewrite_rule .= " <rule name=\"nv_rule_" . ++$rulename . "\">\n";
            $rewrite_rule .= " <match url=\"^([a-z]{2})\\/seek\\/q\\=(.*)\$\" ignoreCase=\"false\" />\n";
            $rewrite_rule .= " <action type=\"Rewrite\" url=\"index.php?" . NV_LANG_VARIABLE . "={R:1}&amp;" . NV_NAME_VARIABLE . "=seek&amp;q={R:2}\" appendQueryString=\"false\" />\n";
            $rewrite_rule .= " </rule>\n";
            $rewrite_rule .= " <rule name=\"nv_rule_" . ++$rulename . "\">\n";
            $rewrite_rule .= " <match url=\"^([a-z]{2})\\/([a-zA-Z0-9\\-]+)\\/search\\/q\\=(.*)\$\" ignoreCase=\"false\" />\n";
            $rewrite_rule .= " <action type=\"Rewrite\" url=\"index.php?" . NV_LANG_VARIABLE . "={R:1}&amp;" . NV_NAME_VARIABLE . "={R:2}&amp;" . NV_OP_VARIABLE . "=search&amp;q={R:3}\" appendQueryString=\"false\" />\n";
            $rewrite_rule .= " </rule>\n";
        }
        $rewrite_rule = nv_rewrite_rule_iis7($rewrite_rule);
    } elseif ($sys_info['supports_rewrite'] == 'rewrite_mode_apache') {
        $filename = NV_ROOTDIR . '/.htaccess';
        $htaccess = '';
        $rewrite_rule = "##################################################################################\n";
        $rewrite_rule .= "#nukeviet_rewrite_start //Please do not change the contents of the following lines\n";
        $rewrite_rule .= "##################################################################################\n\n";
        $rewrite_rule .= "#Options +FollowSymLinks\n\n";
        $rewrite_rule .= "<IfModule mod_rewrite.c>\n";
        $rewrite_rule .= "RewriteEngine On\n";
        $rewrite_rule .= "#RewriteBase " . NV_BASE_SITEURL . "\n";
        if ($array_config_global['ssl_https']) {
            $rewrite_rule .= "RewriteCond %{SERVER_PORT} !^443\$\n";
            $rewrite_rule .= "RewriteRule (.*)  https://%{SERVER_NAME}%{REQUEST_URI} [L,R]\n";
        }
        $rewrite_rule .= "RewriteCond %{REQUEST_FILENAME} /robots.txt\$ [NC]\n";
        $rewrite_rule .= "RewriteRule ^ robots.php?action=%{HTTP_HOST} [L]\n";
        $rewrite_rule .= "RewriteRule ^(.*?)sitemap\\.xml\$ index.php?" . NV_NAME_VARIABLE . "=SitemapIndex [L]\n";
        $rewrite_rule .= "RewriteRule ^(.*?)sitemap\\-([a-z]{2})\\.xml\$ index.php?" . NV_LANG_VARIABLE . "=\$2&" . NV_NAME_VARIABLE . "=SitemapIndex [L]\n";
        $rewrite_rule .= "RewriteRule ^(.*?)sitemap\\-([a-z]{2})\\.([a-zA-Z0-9-]+)\\.xml\$ index.php?" . NV_LANG_VARIABLE . "=\$2&" . NV_NAME_VARIABLE . "=\$3&" . NV_OP_VARIABLE . "=sitemap [L]\n";
        if ($sys_info['zlib_support']) {
            $rewrite_rule .= "RewriteRule ^((?!http(s?)|ftp\\:\\/\\/).*)\\.(css|js)\$ CJzip.php?file=\$1.\$3 [L]\n";
        }
        $rewrite_rule .= "RewriteCond %{REQUEST_FILENAME} !-f\n";
        $rewrite_rule .= "RewriteCond %{REQUEST_FILENAME} !-d\n";
        $rewrite_rule .= "RewriteRule (.*)(" . $endurl . ")\$ index.php\n";
        $rewrite_rule .= "RewriteRule (.*)tag\\/(.*)\$ index.php\n";
        if ($array_config_global['rewrite_optional']) {
            if (!empty($array_config_global['rewrite_op_mod'])) {
                if ($array_config_global['rewrite_op_mod'] == 'seek') {
                    $rewrite_rule .= "RewriteRule ^q\\=(.*)\$ index.php?" . NV_NAME_VARIABLE . "=seek&q=\$1 [L]\n";
                } else {
                    $rewrite_rule .= "RewriteRule ^seek\\/q\\=(.*)\$ index.php?" . NV_NAME_VARIABLE . "=seek&q=\$1 [L]\n";
                }
                $rewrite_rule .= "RewriteRule ^search\\/q\\=(.*)\$ index.php?" . NV_NAME_VARIABLE . "=" . $array_config_global['rewrite_op_mod'] . "&" . NV_OP_VARIABLE . "=search&q=\$1 [L]\n";
            } else {
                $rewrite_rule .= "RewriteRule ^seek\\/q\\=(.*)\$ index.php?" . NV_NAME_VARIABLE . "=seek&q=\$1 [L]\n";
            }
            $rewrite_rule .= "RewriteRule ^([a-zA-Z0-9\\-]+)\\/search\\/q\\=(.*)\$ index.php?" . NV_NAME_VARIABLE . "=\$1&" . NV_OP_VARIABLE . "=search&q=\$2 [L]\n";
        } else {
            $rewrite_rule .= "RewriteRule ^([a-z]{2})\\/seek\\/q\\=(.*)\$ index.php?" . NV_LANG_VARIABLE . "=\$1&" . NV_NAME_VARIABLE . "=seek&q=\$2 [L]\n";
            $rewrite_rule .= "RewriteRule ^([a-z]{2})\\/([a-zA-Z0-9\\-]+)\\/search\\/q\\=(.*)\$ index.php?" . NV_LANG_VARIABLE . "=\$1&" . NV_NAME_VARIABLE . "=\$2&" . NV_OP_VARIABLE . "=search&q=\$3 [L]\n";
        }
        $rewrite_rule .= "</IfModule>\n\n";
        $rewrite_rule .= "#nukeviet_rewrite_end\n";
        $rewrite_rule .= "##################################################################################\n\n";
        if (file_exists($filename)) {
            $htaccess = @file_get_contents($filename);
            if (!empty($htaccess)) {
                $htaccess = preg_replace("/[\n]*[\\#]+[\n]+\\#nukeviet\\_rewrite\\_start(.*)\\#nukeviet\\_rewrite\\_end[\n]+[\\#]+[\n]*/s", "\n", $htaccess);
                $htaccess = trim($htaccess);
            }
        }
        $htaccess .= "\n\n" . $rewrite_rule;
        $rewrite_rule = $htaccess;
    }
    $return = true;
    if (!empty($filename) and !empty($rewrite_rule)) {
        try {
            $filesize = file_put_contents($filename, $rewrite_rule, LOCK_EX);
            if (empty($filesize)) {
                $return = false;
            }
        } catch (exception $e) {
            $return = false;
        }
    }
    return array($return, NV_BASE_SITEURL . basename($filename));
}
$dir = NV_ROOTDIR . "/" . NV_SESSION_SAVE_PATH;
$files = nv_scandir($dir, "/^(" . nv_preg_quote("sess_") . ")[a-zA-Z0-9\\_\\.]+\$/");
foreach ($files as $file) {
    if ($file != "sess_" . $client_info['session_id']) {
        @unlink($dir . '/' . $file);
    }
}
$log_dir = NV_ROOTDIR . "/" . NV_LOGS_DIR . "/dump_backup";
$files = scandir($log_dir);
foreach ($files as $file) {
    if (preg_match("/^([a-zA-Z0-9]+)\\_([a-zA-Z0-9\\-\\_]+)\\.(sql|sql\\.gz)+\$/", $file, $mc)) {
        @unlink($log_dir . "/" . $file);
    }
}
$dir = NV_ROOTDIR . "/" . NV_TEMP_DIR;
$files = nv_scandir($dir, "/^(" . nv_preg_quote(NV_TEMPNAM_PREFIX) . ")[a-zA-Z0-9\\_\\.]+\$/");
foreach ($files as $file) {
    @unlink($dir . '/' . $file);
}
$error_log_fileext = preg_match("/[a-z]+/i", NV_LOGS_EXT) ? NV_LOGS_EXT : 'log';
$error_log_filename = preg_match("/[a-z0-9\\_]+/i", NV_ERRORLOGS_FILENAME) ? NV_ERRORLOGS_FILENAME : 'error_log';
$dir = NV_ROOTDIR . '/' . NV_LOGS_DIR . '/error_logs';
$files = nv_scandir($dir, "/^([0-9]{2})\\-([0-9]{2})-([0-9]{4})\\_(" . $error_log_filename . ")\\.(" . $error_log_fileext . ")\$/");
if (!empty($files)) {
    foreach ($files as $file) {
        @unlink($dir . '/' . $file);
    }
}
if (file_exists($dir . '/sendmail.log')) {
    @unlink($dir . '/sendmail.log');
}