示例#1
0
function other()
{
    global $global_config, $db;
    try {
        //bảng nv3_vi_counter
        $_sql = 'SELECT c_type, c_val, last_update, c_count, vi_count FROM ' . NV4_PREFIX . '_counter';
        $_query = $db->query($_sql);
        while ($row = $_query->fetch()) {
            nv_delete_all_cache();
            $sqlnv3 = 'SELECT c_type, c_val, c_count, last_update FROM ' . NV3_PREFIX . '_' . NV_LANG_DATA . '_counter';
            $result = $db->query($sqlnv3);
            while ($row3 = $result->fetch()) {
                if ($row['c_type'] == $row3['c_type'] and $row['c_val'] == $row3['c_val']) {
                    $row['c_count'] = $row3['c_count'];
                    $row['last_update'] = $row3['last_update'];
                    $sql_up = 'UPDATE ' . NV4_PREFIX . '_counter SET
					last_update=' . $db->quote($row['last_update']) . ',
					c_count=' . $db->quote($row['c_count']) . ',
					vi_count=' . $db->quote($row['c_count']) . '
					WHERE c_type=' . $db->quote($row['c_type']) . ' AND c_val=' . $db->quote($row['c_val']) . '';
                    $db->query($sql_up);
                }
            }
        }
        // bảng nv3_vi_searchkeys
        $db->query('TRUNCATE ' . NV4_PREFIX . '_' . NV_LANG_DATA . '_searchkeys');
        $_sql = 'SELECT `id`, `keys`, `total`, `search_engine` FROM `' . NV3_PREFIX . '_' . NV_LANG_DATA . '_searchkeys`';
        $_query = $db->query($_sql);
        while ($row = $_query->fetch()) {
            $sql = "INSERT INTO " . NV4_PREFIX . '_' . NV_LANG_DATA . "_searchkeys(id, `skey`, total, search_engine)\r\n\t\tVALUES (:id,:skey,:total,:search_engine)";
            $data_insert = array();
            $data_insert['id'] = $row['id'];
            $data_insert['skey'] = $row['keys'];
            $data_insert['total'] = $row['total'];
            $data_insert['search_engine'] = $row['search_engine'];
            $id = intval($db->insert_id($sql, 'id', $data_insert));
        }
        // bảng nv3_vi_referer_stats
        $db->query('TRUNCATE ' . NV4_PREFIX . '_' . NV_LANG_DATA . '_referer_stats');
        $_sql = 'SELECT `host`, `total`, `month01`, `month02`, `month03`, `month04`, `month05`, `month06`, `month07`, `month08`, `month09`, `month10`, `month11`, `month12`, `last_update` FROM `' . NV3_PREFIX . '_' . NV_LANG_DATA . '_referer_stats`';
        $_query = $db->query($_sql);
        while ($row = $_query->fetch()) {
            $sql = "INSERT INTO " . NV4_PREFIX . '_' . NV_LANG_DATA . "_referer_stats\r\n\t\t(host, total, month01, month02, month03, month04,\r\n\t\tmonth05, month06, month07, month08, month09, month10,\r\n\t\tmonth11, month12, last_update)\r\n\t\tVALUES (\r\n\t\t" . $db->quote($row['host']) . ",\r\n\t\t" . $db->quote($row['total']) . ",\r\n\t\t" . $db->quote($row['month01']) . ",\r\n\t\t" . $db->quote($row['month02']) . ",\r\n\t\t" . $db->quote($row['month03']) . ",\r\n\t\t" . $db->quote($row['month04']) . ",\r\n\t\t" . $db->quote($row['month05']) . ",\r\n\t\t" . $db->quote($row['month06']) . ",\r\n\t\t" . $db->quote($row['month07']) . ",\r\n\t\t" . $db->quote($row['month08']) . ",\r\n\t\t" . $db->quote($row['month09']) . ",\r\n\t\t" . $db->quote($row['month10']) . ",\r\n\t\t" . $db->quote($row['month11']) . ",\r\n\t\t" . $db->quote($row['month12']) . ",\r\n\t\t" . $db->quote($row['last_update']) . ")";
            $db->query($sql);
        }
    } catch (PDOException $e) {
        trigger_error($e->getMessage());
    }
}
示例#2
0
function nv_save_file_config_global()
{
    global $db;
    $content_config = "<?php\n\n";
    $content_config .= NV_FILEHEAD . "\n\n";
    $content_config .= "if ( ! defined( 'NV_MAINFILE' ) ) die( 'Stop!!!' );\n\n";
    $sql = "SELECT `config_name`, `config_value` FROM `" . NV_CONFIG_GLOBALTABLE . "` WHERE `lang`='sys' ORDER BY `config_name` ASC";
    $result = $db->sql_query($sql);
    while (list($c_config_name, $c_config_value) = $db->sql_fetchrow($result)) {
        if (!is_numeric($c_config_value) || (isset($c_config_value[1]) and ($c_config_value[0] == '0' or $c_config_value[0] == '.'))) {
            $content_config .= "\$global_config['" . $c_config_name . "'] = \"" . nv_htmlspecialchars($c_config_value) . "\";\n";
        } else {
            $content_config .= "\$global_config['" . $c_config_name . "'] = " . intval($c_config_value) . ";\n";
        }
    }
    $content_config .= "\n";
    $content_config .= "?>";
    $return = file_put_contents(NV_ROOTDIR . "/" . NV_DATADIR . "/config_global.php", $content_config, LOCK_EX);
    nv_delete_all_cache();
    return $return;
}
示例#3
0
$list = nv_db_cache($sql, '', 'settings');
foreach ($list as $row) {
    if ($row['module'] == "global") {
        $global_config[$row['config_name']] = $row['config_value'];
    } else {
        $module_config[$row['module']][$row['config_name']] = $row['config_value'];
    }
}
if ($global_config['is_url_rewrite']) {
    $check_rewrite_file = nv_check_rewrite_file();
    if (!$check_rewrite_file) {
        $global_config['is_url_rewrite'] = 0;
    }
    if (empty($global_config['is_url_rewrite'])) {
        $db->sql_query("UPDATE `" . NV_CONFIG_GLOBALTABLE . "` SET `config_value`= '0' WHERE `module`='global' AND `config_name` = 'is_url_rewrite'");
        nv_delete_all_cache();
        //xoa toan bo cache
    }
}
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;
    }
    if (!in_array(NV_LANG_INTERFACE, $global_config['allow_adminlangs'])) {
        if ($global_config['lang_multi']) {
            $nv_Request->set_Cookie('int_lang', $global_config['site_lang'], NV_LIVE_COOKIE_TIME);
        }
示例#4
0
/**
 * nv_save_file_config_global()
 *
 * @return
 */
function nv_save_file_config_global()
{
    global $db, $sys_info, $global_config, $db_config;
    if ($global_config['idsite']) {
        return false;
    }
    $content_config = "<?php" . "\n\n";
    $content_config .= NV_FILEHEAD . "\n\n";
    $content_config .= "if ( ! defined( 'NV_MAINFILE' ) ) die( 'Stop!!!' );\n\n";
    //disable_classes
    $sys_info['disable_classes'] = (($disable_classes = ini_get('disable_classes')) != '' and $disable_classes != false) ? array_map('trim', preg_split("/[\\s,]+/", $disable_classes)) : array();
    if (!empty($sys_info['disable_classes'])) {
        $disable_classes = "'" . implode("','", $sys_info['disable_classes']) . "'";
    } else {
        $disable_classes = '';
    }
    $content_config .= "\$sys_info['disable_classes']=array(" . $disable_classes . ");\n";
    //disable_functions
    $sys_info['disable_functions'] = (($disable_functions = ini_get('disable_functions')) != '' and $disable_functions != false) ? array_map('trim', preg_split("/[\\s,]+/", $disable_functions)) : array();
    if (extension_loaded('suhosin')) {
        $sys_info['disable_functions'] = array_merge($sys_info['disable_functions'], array_map('trim', preg_split("/[\\s,]+/", ini_get('suhosin.executor.func.blacklist'))));
    }
    if (!empty($sys_info['disable_functions'])) {
        $disable_functions = "'" . implode("','", $sys_info['disable_functions']) . "'";
    } else {
        $disable_functions = '';
    }
    $content_config .= "\$sys_info['disable_functions']=array(" . $disable_functions . ");\n";
    //ini_set_support
    $sys_info['ini_set_support'] = (function_exists('ini_set') and !in_array('ini_set', $sys_info['disable_functions'])) ? true : false;
    $ini_set_support = $sys_info['ini_set_support'] ? 'true' : 'false';
    $content_config .= "\$sys_info['ini_set_support']= " . $ini_set_support . ";\n";
    //Kiem tra ho tro rewrite
    if (function_exists('apache_get_modules')) {
        $apache_modules = apache_get_modules();
        if (in_array('mod_rewrite', $apache_modules)) {
            $sys_info['supports_rewrite'] = 'rewrite_mode_apache';
        } else {
            $sys_info['supports_rewrite'] = false;
        }
    } elseif (strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS/7.') !== false) {
        if (isset($_SERVER['IIS_UrlRewriteModule']) and class_exists('DOMDocument')) {
            $sys_info['supports_rewrite'] = 'rewrite_mode_iis';
        } else {
            $sys_info['supports_rewrite'] = false;
        }
    }
    if ($sys_info['supports_rewrite'] == 'rewrite_mode_iis' or $sys_info['supports_rewrite'] == 'rewrite_mode_apache') {
        $content_config .= "\$sys_info['supports_rewrite']='" . $sys_info['supports_rewrite'] . "';\n";
    } else {
        $content_config .= "\$sys_info['supports_rewrite']=false;\n";
    }
    $content_config .= "\n";
    $config_variable = array();
    $allowed_html_tags = '';
    $sql = "SELECT module, config_name, config_value FROM " . NV_CONFIG_GLOBALTABLE . " WHERE lang='sys' AND (module='global' OR module='define') ORDER BY config_name ASC";
    $result = $db->query($sql);
    while (list($c_module, $c_config_name, $c_config_value) = $result->fetch(3)) {
        if ($c_module == 'define') {
            if (preg_match('/^\\d+$/', $c_config_value)) {
                $content_config .= "define('" . strtoupper($c_config_name) . "', " . $c_config_value . ");\n";
            } else {
                $content_config .= "define('" . strtoupper($c_config_name) . "', '" . $c_config_value . "');\n";
            }
            if ($c_config_name == 'nv_allowed_html_tags') {
                $allowed_html_tags = $c_config_value;
            }
        } else {
            $config_variable[$c_config_name] = $c_config_value;
        }
    }
    $nv_eol = strtoupper(substr(PHP_OS, 0, 3) == 'WIN') ? '"\\r\\n"' : (strtoupper(substr(PHP_OS, 0, 3) == 'MAC') ? '"\\r"' : '"\\n"');
    $upload_max_filesize = min(nv_converttoBytes(ini_get('upload_max_filesize')), nv_converttoBytes(ini_get('post_max_size')), $config_variable['nv_max_size']);
    $content_config .= "define('NV_EOL', " . $nv_eol . ");\n";
    $content_config .= "define('NV_UPLOAD_MAX_FILESIZE', " . floatval($upload_max_filesize) . ");\n";
    if ($config_variable['openid_mode']) {
        $content_config .= "define('NV_OPENID_ALLOWED', true);\n\n";
    }
    $my_domains = array_map('trim', explode(',', $config_variable['my_domains']));
    $my_domains[] = NV_SERVER_NAME;
    $config_variable['my_domains'] = implode(',', array_unique($my_domains));
    $config_variable['check_rewrite_file'] = nv_check_rewrite_file();
    $config_variable['allow_request_mods'] = NV_ALLOW_REQUEST_MODS != '' ? NV_ALLOW_REQUEST_MODS : "request";
    $config_variable['request_default_mode'] = NV_REQUEST_DEFAULT_MODE != '' ? trim(NV_REQUEST_DEFAULT_MODE) : 'request';
    $config_variable['session_save_path'] = NV_SESSION_SAVE_PATH;
    $config_variable['log_errors_list'] = NV_LOG_ERRORS_LIST;
    $config_variable['display_errors_list'] = NV_DISPLAY_ERRORS_LIST;
    $config_variable['send_errors_list'] = NV_SEND_ERRORS_LIST;
    $config_variable['error_log_path'] = NV_LOGS_DIR . '/error_logs';
    $config_variable['error_log_filename'] = NV_ERRORLOGS_FILENAME;
    $config_variable['error_log_fileext'] = NV_LOGS_EXT;
    $config_variable['error_send_email'] = $config_variable['error_send_email'];
    $config_name_array = array('file_allowed_ext', 'forbid_extensions', 'forbid_mimes', 'allow_sitelangs', 'openid_servers', 'allow_request_mods', 'config_sso');
    if (empty($config_variable['openid_servers'])) {
        $config_variable['openid_mode'] = 0;
    }
    if ($config_variable['is_user_forum']) {
        $forum_files = @scandir(NV_ROOTDIR . '/' . DIR_FORUM . '/nukeviet');
        if (!empty($forum_files) and in_array('is_user.php', $forum_files) and in_array('changepass.php', $forum_files) and in_array('editinfo.php', $forum_files) and in_array('login.php', $forum_files) and in_array('logout.php', $forum_files) and in_array('lostpass.php', $forum_files) and in_array('register.php', $forum_files)) {
            $content_config .= "define( 'NV_IS_USER_FORUM', true );\n\n";
        } else {
            $config_variable['is_user_forum'] = 0;
        }
    }
    foreach ($config_variable as $c_config_name => $c_config_value) {
        if ($c_config_name == 'config_sso') {
            $config_sso = empty($c_config_value) ? '' : nv_var_export(unserialize($c_config_value));
            $content_config .= "\$global_config['" . $c_config_name . "']=" . $config_sso . ";\n";
        } elseif (in_array($c_config_name, $config_name_array)) {
            if (!empty($c_config_value)) {
                $c_config_value = "'" . implode("','", array_map("trim", explode(',', $c_config_value))) . "'";
            } else {
                $c_config_value = '';
            }
            $content_config .= "\$global_config['" . $c_config_name . "']=array(" . $c_config_value . ");\n";
        } else {
            if (preg_match('/^\\d+$/', $c_config_value) and $c_config_name != 'facebook_client_id') {
                $content_config .= "\$global_config['" . $c_config_name . "']=" . $c_config_value . ";\n";
            } else {
                $c_config_value = nv_unhtmlspecialchars($c_config_value);
                if (!preg_match("/^[a-z0-9\\-\\_\\.\\,\\;\\:\\@\\/\\s]+\$/i", $c_config_value) and $c_config_name != 'my_domains') {
                    $c_config_value = nv_htmlspecialchars($c_config_value);
                }
                $content_config .= "\$global_config['" . $c_config_name . "']='" . $c_config_value . "';\n";
            }
        }
    }
    $content_config .= "\$global_config['array_theme_type']=" . nv_var_export(array_filter(array_map('trim', explode(',', NV_THEME_TYPE)))) . ";\n";
    //allowed_html_tags
    if (!empty($allowed_html_tags)) {
        $allowed_html_tags = "'" . implode("','", array_map('trim', explode(',', $allowed_html_tags))) . "'";
    } else {
        $allowed_html_tags = '';
    }
    $content_config .= "\$global_config['allowed_html_tags']=array(" . $allowed_html_tags . ");\n";
    //Xac dinh cac search_engine
    $engine_allowed = file_exists(NV_ROOTDIR . '/' . NV_DATADIR . '/search_engine.xml') ? nv_object2array(simplexml_load_file(NV_ROOTDIR . '/' . NV_DATADIR . '/search_engine.xml')) : array();
    $content_config .= "\$global_config['engine_allowed']=" . nv_var_export($engine_allowed) . ";\n";
    $content_config .= "\n";
    $language_array = nv_parse_ini_file(NV_ROOTDIR . '/includes/ini/langs.ini', true);
    $tmp_array = array();
    $lang_array_exit = nv_scandir(NV_ROOTDIR . "/language", "/^[a-z]{2}+\$/");
    foreach ($lang_array_exit as $lang) {
        $tmp_array[$lang] = $language_array[$lang];
    }
    unset($language_array);
    $content_config .= "\$language_array=" . nv_var_export($tmp_array) . ";\n";
    $tmp_array = nv_parse_ini_file(NV_ROOTDIR . '/includes/ini/br.ini', true);
    $content_config .= "\$nv_parse_ini_browsers=" . nv_var_export($tmp_array) . ";\n";
    $tmp_array = nv_parse_ini_file(NV_ROOTDIR . '/includes/ini/mobile.ini', true);
    $content_config .= "\$nv_parse_ini_mobile=" . nv_var_export($tmp_array) . ";\n";
    $tmp_array = nv_parse_ini_file(NV_ROOTDIR . '/includes/ini/os.ini', true);
    $content_config .= "\$nv_parse_ini_os=" . nv_var_export($tmp_array) . ";\n";
    $tmp_array = nv_parse_ini_file(NV_ROOTDIR . '/includes/ini/timezone.ini', true);
    $content_config .= "\$nv_parse_ini_timezone=" . nv_var_export($tmp_array) . ";\n";
    $rewrite = array();
    $global_config['rewrite_optional'] = $config_variable['rewrite_optional'];
    $global_config['rewrite_op_mod'] = $config_variable['rewrite_op_mod'];
    $global_config['rewrite_endurl'] = $config_variable['rewrite_endurl'];
    $global_config['rewrite_exturl'] = $config_variable['rewrite_exturl'];
    if ($config_variable['check_rewrite_file']) {
        require NV_ROOTDIR . '/includes/rewrite.php';
    } else {
        require NV_ROOTDIR . '/includes/rewrite_index.php';
    }
    $content_config .= "\n";
    $nv_plugin_area = array();
    $_sql = 'SELECT * FROM ' . $db_config['prefix'] . '_plugin ORDER BY plugin_area ASC, weight ASC';
    $_query = $db->query($_sql);
    while ($row = $_query->fetch()) {
        $nv_plugin_area[$row['plugin_area']][] = $row['plugin_file'];
    }
    $content_config .= "\$nv_plugin_area=" . nv_var_export($nv_plugin_area) . ";\n\n";
    $content_config .= "\$rewrite_keys=" . nv_var_export(array_keys($rewrite)) . ";\n";
    $content_config .= "\$rewrite_values=" . nv_var_export(array_values($rewrite)) . ";\n";
    $return = file_put_contents(NV_ROOTDIR . "/" . NV_DATADIR . "/config_global.php", trim($content_config), LOCK_EX);
    nv_delete_all_cache();
    return $return;
}
示例#5
0
    $array_config_global['googleAnalyticsID'] = nv_substr($nv_Request->get_title('googleAnalyticsID', 'post', '', 1), 0, 20);
    if (!preg_match('/^UA-\\d{4,}-\\d+$/', $array_config_global['googleAnalyticsID'])) {
        $array_config_global['googleAnalyticsID'] = '';
    }
    $array_config_global['googleAnalyticsSetDomainName'] = $nv_Request->get_int('googleAnalyticsSetDomainName', 'post');
    $array_config_global['googleAnalyticsMethod'] = $nv_Request->get_title('googleAnalyticsMethod', 'post', '', 1);
    if (!isset($googleAnalyticsMethod[$array_config_global['googleAnalyticsMethod']])) {
        $googleAnalyticsMethod['googleAnalyticsMethod'] = 'classic';
    }
    $sth = $db->prepare("UPDATE " . NV_CONFIG_GLOBALTABLE . " SET config_value = :config_value WHERE lang = 'sys' AND module = 'site' AND config_name = :config_name");
    foreach ($array_config_global as $config_name => $config_value) {
        $sth->bindParam(':config_name', $config_name, PDO::PARAM_STR);
        $sth->bindParam(':config_value', $config_value, PDO::PARAM_STR);
        $sth->execute();
    }
    nv_delete_all_cache(false);
    Header('Location: ' . NV_BASE_ADMINURL . 'index.php?' . NV_LANG_VARIABLE . '=' . NV_LANG_DATA . '&' . NV_NAME_VARIABLE . '=' . $module_name . '&' . NV_OP_VARIABLE . '=' . $op . '&rand=' . nv_genpass());
    exit;
}
$page_title = $lang_module['global_statistics'];
$array_config_global['online_upd'] = $global_config['online_upd'] ? ' checked="checked"' : '';
$array_config_global['statistic'] = $global_config['statistic'] ? ' checked="checked"' : '';
$array_config_global['googleAnalyticsID'] = $global_config['googleAnalyticsID'];
$xtpl = new XTemplate('statistics.tpl', NV_ROOTDIR . '/themes/' . $global_config['module_theme'] . '/modules/' . $module_file);
$xtpl->assign('LANG', $lang_module);
$xtpl->assign('DATA', $array_config_global);
$xtpl->assign('NV_BASE_ADMINURL', NV_BASE_ADMINURL);
$xtpl->assign('NV_NAME_VARIABLE', NV_NAME_VARIABLE);
$xtpl->assign('MODULE_NAME', $module_name);
$xtpl->assign('NV_OP_VARIABLE', NV_OP_VARIABLE);
$xtpl->assign('OP', $op);
示例#6
0
/**
 * nv_setup_data_module()
 *
 * @param mixed $lang
 * @param mixed $module_name
 * @return
 */
function nv_setup_data_module($lang, $module_name)
{
    global $db, $db_config, $global_config;
    $return = 'NO_' . $module_name;
    $sth = $db->prepare('SELECT module_file, module_data, module_upload, theme FROM ' . $db_config['prefix'] . '_' . $lang . '_modules WHERE title= :title');
    $sth->bindParam(':title', $module_name, PDO::PARAM_STR);
    $sth->execute();
    list($module_file, $module_data, $module_upload, $module_theme) = $sth->fetch(3);
    if (!empty($module_file)) {
        $module_version = array();
        $version_file = NV_ROOTDIR . '/modules/' . $module_file . '/version.php';
        if (file_exists($version_file)) {
            include $version_file;
        }
        $arr_modfuncs = (isset($module_version['modfuncs']) and !empty($module_version['modfuncs'])) ? array_map('trim', explode(',', $module_version['modfuncs'])) : array();
        // Xoa du lieu tai bang _config
        $sth = $db->prepare("DELETE FROM " . NV_CONFIG_GLOBALTABLE . " WHERE lang= '" . $lang . "' AND module= :module");
        $sth->bindParam(':module', $module_name, PDO::PARAM_STR);
        $sth->execute();
        nv_delete_all_cache();
        if (file_exists(NV_ROOTDIR . '/modules/' . $module_file . '/action_' . $db->dbtype . '.php')) {
            $sql_recreate_module = array();
            try {
                $db->exec('ALTER DATABASE ' . $db_config['dbname'] . ' DEFAULT CHARACTER SET utf8 COLLATE ' . $db_config['collation']);
            } catch (PDOException $e) {
                trigger_error($e->getMessage());
            }
            include NV_ROOTDIR . '/modules/' . $module_file . '/action_' . $db->dbtype . '.php';
            if (!empty($sql_create_module)) {
                foreach ($sql_create_module as $sql) {
                    try {
                        $db->query($sql);
                    } catch (PDOException $e) {
                        trigger_error($e->getMessage());
                        return $return;
                    }
                }
            }
        }
        $arr_func_id = array();
        $arr_show_func = array();
        $new_funcs = nv_scandir(NV_ROOTDIR . '/modules/' . $module_file . '/funcs', $global_config['check_op_file']);
        if (!empty($new_funcs)) {
            // Get default layout
            $layout_array = nv_scandir(NV_ROOTDIR . '/themes/' . $global_config['site_theme'] . '/layout', $global_config['check_op_layout']);
            if (!empty($layout_array)) {
                $layout_array = preg_replace($global_config['check_op_layout'], '\\1', $layout_array);
            }
            $selectthemes = 'default';
            if (!empty($module_theme) and file_exists(NV_ROOTDIR . '/themes/' . $module_theme . '/config.ini')) {
                $selectthemes = $module_theme;
            } elseif (file_exists(NV_ROOTDIR . '/themes/' . $global_config['site_theme'] . '/config.ini')) {
                $selectthemes = $global_config['site_theme'];
            }
            $xml = simplexml_load_file(NV_ROOTDIR . '/themes/' . $selectthemes . '/config.ini');
            $layoutdefault = (string) $xml->layoutdefault;
            $layout = $xml->xpath('setlayout/layout');
            $array_layout_func_default = array();
            for ($i = 0, $count = sizeof($layout); $i < $count; ++$i) {
                $layout_name = (string) $layout[$i]->name;
                if (in_array($layout_name, $layout_array)) {
                    $layout_funcs = $layout[$i]->xpath('funcs');
                    for ($j = 0, $count2 = sizeof($layout_funcs); $j < $count2; ++$j) {
                        $mo_funcs = (string) $layout_funcs[$j];
                        $mo_funcs = explode(':', $mo_funcs);
                        $m = $mo_funcs[0];
                        $arr_f = explode(',', $mo_funcs[1]);
                        foreach ($arr_f as $f) {
                            $array_layout_func_default[$m][$f] = $layout_name;
                        }
                    }
                }
            }
            // end get default layout
            $_layoutdefault = isset($module_version['layoutdefault']) ? $module_version['layoutdefault'] : '';
            if (!empty($_layoutdefault)) {
                $_layout_mod = explode(';', $_layoutdefault);
                foreach ($_layout_mod as $_layout_fun) {
                    list($layout_name, $_func) = explode(':', trim($_layout_fun));
                    $arr_f = explode(',', trim($_func));
                    foreach ($arr_f as $f) {
                        if (!isset($array_layout_func_default[$module_name][$f])) {
                            $array_layout_func_default[$module_name][$f] = $layout_name;
                        }
                    }
                }
            }
            $arr_func_id_old = array();
            $sth = $db->prepare('SELECT func_id, func_name FROM ' . $db_config['prefix'] . '_' . $lang . '_modfuncs WHERE in_module= :in_module');
            $sth->bindParam(':in_module', $module_name, PDO::PARAM_STR);
            $sth->execute();
            while ($row = $sth->fetch()) {
                $arr_func_id_old[$row['func_name']] = $row['func_id'];
            }
            $new_funcs = preg_replace($global_config['check_op_file'], '\\1', $new_funcs);
            $new_funcs = array_flip($new_funcs);
            $array_keys = array_keys($new_funcs);
            $array_submenu = isset($module_version['submenu']) ? explode(',', $module_version['submenu']) : array();
            foreach ($array_keys as $func) {
                $show_func = 0;
                $weight = 0;
                $in_submenu = in_array($func, $array_submenu) ? 1 : 0;
                if (isset($arr_func_id_old[$func]) and isset($arr_func_id_old[$func]) > 0) {
                    $arr_func_id[$func] = $arr_func_id_old[$func];
                    $db->query('UPDATE ' . $db_config['prefix'] . '_' . $lang . '_modfuncs SET show_func= ' . $show_func . ', in_submenu=' . $in_submenu . ', subweight=0 WHERE func_id=' . $arr_func_id[$func]);
                } else {
                    $data = array();
                    $data['func_name'] = $func;
                    $data['alias'] = $func;
                    $data['func_custom_name'] = ucfirst($func);
                    $data['in_module'] = $module_name;
                    $arr_func_id[$func] = $db->insert_id("INSERT INTO " . $db_config['prefix'] . "_" . $lang . "_modfuncs\n\t\t\t\t\t\t(func_name, alias, func_custom_name, in_module, show_func, in_submenu, subweight, setting) VALUES\n\t\t\t\t\t \t(:func_name, :alias, :func_custom_name, :in_module, " . $show_func . ", " . $in_submenu . ", " . $weight . ", '')", "func_id", $data);
                    if ($arr_func_id[$func]) {
                        -($layout = $layoutdefault);
                        if (isset($array_layout_func_default[$module_name][$func])) {
                            if (file_exists(NV_ROOTDIR . '/themes/' . $selectthemes . '/layout/layout.' . $array_layout_func_default[$module_name][$func] . '.tpl')) {
                                $layout = $array_layout_func_default[$module_name][$func];
                            }
                        }
                        $db->query('INSERT INTO ' . $db_config['prefix'] . '_' . $lang . '_modthemes (`func_id`, `layout`, `theme`) VALUES (' . $arr_func_id[$func] . ', ' . $db->quote($layout) . ', ' . $db->quote($selectthemes) . ')');
                    }
                }
            }
            $subweight = 0;
            foreach ($arr_modfuncs as $func) {
                if (isset($arr_func_id[$func])) {
                    $func_id = $arr_func_id[$func];
                    $arr_show_func[] = $func_id;
                    $show_func = 1;
                    ++$subweight;
                    $db->query('UPDATE ' . $db_config['prefix'] . '_' . $lang . '_modfuncs SET subweight=' . $subweight . ', show_func=' . $show_func . ' WHERE func_id=' . $func_id);
                }
            }
        } else {
            // Xoa du lieu tai bang _modfuncs
            $sth = $db->prepare('DELETE FROM ' . $db_config['prefix'] . '_' . $lang . '_modfuncs WHERE in_module= :in_module');
            $sth->bindParam(':in_module', $module_name, PDO::PARAM_STR);
            $sth->execute();
        }
        if (isset($module_version['uploads_dir']) and !empty($module_version['uploads_dir'])) {
            $sth_dir = $db->prepare('INSERT INTO ' . NV_UPLOAD_GLOBALTABLE . '_dir (dirname, time, thumb_type, thumb_width, thumb_height, thumb_quality) VALUES (:dirname, 0, 0, 0, 0, 0)');
            foreach ($module_version['uploads_dir'] as $path) {
                $cp = '';
                $arr_p = explode('/', $path);
                foreach ($arr_p as $p) {
                    if (trim($p) != '') {
                        if (!is_dir(NV_UPLOADS_REAL_DIR . '/' . $cp . $p)) {
                            $mk = nv_mkdir(NV_UPLOADS_REAL_DIR . '/' . $cp, $p);
                            if ($mk[0]) {
                                try {
                                    $sth_dir->bindValue(':dirname', NV_UPLOADS_DIR . '/' . $cp . $p, PDO::PARAM_STR);
                                    $sth_dir->execute();
                                } catch (PDOException $e) {
                                }
                            }
                        }
                        $cp .= $p . '/';
                    }
                }
            }
        }
        if (isset($module_version['files_dir']) and !empty($module_version['files_dir'])) {
            foreach ($module_version['files_dir'] as $path) {
                $cp = '';
                $arr_p = explode('/', $path);
                foreach ($arr_p as $p) {
                    if (trim($p) != '') {
                        if (!is_dir(NV_ROOTDIR . '/' . NV_FILES_DIR . '/' . $cp . $p)) {
                            nv_mkdir(NV_ROOTDIR . '/' . NV_FILES_DIR . '/' . $cp, $p);
                        }
                        $cp .= $p . '/';
                    }
                }
            }
        }
        $return = 'OK_' . $module_name;
        nv_delete_all_cache();
    }
    return $return;
}
示例#7
0
 /**
  * nv_setup_data_module()
  * 
  * @param mixed $lang
  * @param mixed $module_name
  * @return
  */
 function nv_setup_data_module($lang, $module_name)
 {
     global $db, $db_config, $global_config;
     $return = 'NO_' . $module_name;
     $sql = "SELECT `module_file`, `module_data`, `theme` FROM `" . $db_config['prefix'] . "_" . $lang . "_modules` WHERE `title`=" . $db->dbescape($module_name);
     $result = $db->sql_query($sql);
     $numrows = $db->sql_numrows($result);
     if ($numrows == 1) {
         list($module_file, $module_data, $module_theme) = $db->sql_fetchrow($result);
         // Unfixdb
         $module_file = $db->unfixdb($module_file);
         $module_data = $db->unfixdb($module_data);
         $module_theme = $db->unfixdb($module_theme);
         $module_version = array();
         $version_file = NV_ROOTDIR . "/modules/" . $module_file . "/version.php";
         if (file_exists($version_file)) {
             include $version_file;
         }
         $arr_modfuncs = (isset($module_version['modfuncs']) and !empty($module_version['modfuncs'])) ? array_map("trim", explode(",", $module_version['modfuncs'])) : array();
         // Xoa du lieu tai bang _config
         $sql = "DELETE FROM `" . NV_CONFIG_GLOBALTABLE . "` WHERE `lang`=" . $db->dbescape($lang) . " AND `module`=" . $db->dbescape($module_name);
         $db->sql_query($sql);
         nv_delete_all_cache();
         if (file_exists(NV_ROOTDIR . '/modules/' . $module_file . '/action.php')) {
             $sql_recreate_module = array();
             include NV_ROOTDIR . '/modules/' . $module_file . '/action.php';
             if (!empty($sql_create_module)) {
                 foreach ($sql_create_module as $sql) {
                     if (!$db->sql_query($sql)) {
                         return $return;
                     }
                 }
             }
         }
         $arr_func_id = array();
         $arr_show_func = array();
         $new_funcs = nv_scandir(NV_ROOTDIR . '/modules/' . $module_file . '/funcs', $global_config['check_op_file']);
         if (!empty($new_funcs)) {
             // Get default layout
             $layout_array = nv_scandir(NV_ROOTDIR . '/themes/' . $global_config['site_theme'] . '/layout', $global_config['check_op_layout']);
             if (!empty($layout_array)) {
                 $layout_array = preg_replace($global_config['check_op_layout'], "\\1", $layout_array);
             }
             $selectthemes = "default";
             if (!empty($module_theme) and file_exists(NV_ROOTDIR . '/themes/' . $module_theme . '/config.ini')) {
                 $selectthemes = $module_theme;
             } elseif (file_exists(NV_ROOTDIR . '/themes/' . $global_config['site_theme'] . '/config.ini')) {
                 $selectthemes = $global_config['site_theme'];
             }
             $xml = simplexml_load_file(NV_ROOTDIR . '/themes/' . $selectthemes . '/config.ini');
             $layoutdefault = (string) $xml->layoutdefault;
             $layout = $xml->xpath('setlayout/layout');
             $array_layout_func_default = array();
             for ($i = 0, $count = sizeof($layout); $i < $count; ++$i) {
                 $layout_name = (string) $layout[$i]->name;
                 if (in_array($layout_name, $layout_array)) {
                     $layout_funcs = $layout[$i]->xpath('funcs');
                     for ($j = 0, $count2 = sizeof($layout_funcs); $j < $count2; ++$j) {
                         $mo_funcs = (string) $layout_funcs[$j];
                         $mo_funcs = explode(":", $mo_funcs);
                         $m = $mo_funcs[0];
                         $arr_f = explode(",", $mo_funcs[1]);
                         foreach ($arr_f as $f) {
                             $array_layout_func_default[$m][$f] = $layout_name;
                         }
                     }
                 }
             }
             // end get default layout
             $arr_func_id_old = array();
             $sql = "SELECT `func_id`, `func_name` FROM `" . $db_config['prefix'] . "_" . $lang . "_modfuncs` WHERE `in_module`=" . $db->dbescape($module_name);
             $result = $db->sql_query($sql);
             while ($row = $db->sql_fetchrow($result)) {
                 $arr_func_id_old[$db->unfixdb($row['func_name'])] = $row['func_id'];
             }
             $new_funcs = preg_replace($global_config['check_op_file'], "\\1", $new_funcs);
             $new_funcs = array_flip($new_funcs);
             $array_keys = array_keys($new_funcs);
             foreach ($array_keys as $func) {
                 $show_func = 0;
                 $weight = 0;
                 $layout = isset($array_layout_func_default[$module_name][$func]) ? $array_layout_func_default[$module_name][$func] : $layoutdefault;
                 if (isset($arr_func_id_old[$func]) and isset($arr_func_id_old[$func]) > 0) {
                     $arr_func_id[$func] = $arr_func_id_old[$func];
                     $db->sql_query("UPDATE `" . $db_config['prefix'] . "_" . $lang . "_modfuncs` SET `show_func`= " . $show_func . ", `subweight`='0' WHERE `func_id`=" . $arr_func_id[$func] . "");
                 } else {
                     $sql = "INSERT INTO `" . $db_config['prefix'] . "_" . $lang . "_modfuncs` (`func_id`, `func_name`, `func_custom_name`, `in_module`, `show_func`, `in_submenu`, `subweight`, `setting`) VALUES (NULL, " . $db->dbescape($func) . ", " . $db->dbescape(ucfirst($func)) . ", " . $db->dbescape($module_name) . ", " . $show_func . ", 0, " . $weight . ", '')";
                     $arr_func_id[$func] = $db->sql_query_insert_id($sql);
                 }
             }
             $subweight = 0;
             foreach ($arr_modfuncs as $func) {
                 if (isset($arr_func_id[$func])) {
                     $func_id = $arr_func_id[$func];
                     $arr_show_func[] = $func_id;
                     $show_func = 1;
                     ++$subweight;
                     $sql = "UPDATE `" . $db_config['prefix'] . "_" . $lang . "_modfuncs` SET `subweight`=" . $subweight . ", show_func=" . $show_func . " WHERE `func_id`=" . $db->dbescape($func_id);
                     $db->sql_query($sql);
                 }
             }
         } else {
             // Xoa du lieu tai bang _modfuncs
             $sql = "DELETE FROM `" . $db_config['prefix'] . "_" . $lang . "_modfuncs` WHERE `in_module`=" . $db->dbescape($module_name);
             $db->sql_query($sql);
         }
         if (isset($module_version['uploads_dir']) and !empty($module_version['uploads_dir'])) {
             foreach ($module_version['uploads_dir'] as $path) {
                 $cp = '';
                 $arr_p = explode("/", $path);
                 foreach ($arr_p as $p) {
                     if (trim($p) != "") {
                         if (!is_dir(NV_UPLOADS_REAL_DIR . '/' . $cp . $p)) {
                             nv_mkdir(NV_UPLOADS_REAL_DIR . '/' . $cp, $p);
                             nv_loadUploadDirList(false);
                         }
                         $cp .= $p . '/';
                     }
                 }
             }
         }
         if (isset($module_version['files_dir']) and !empty($module_version['files_dir'])) {
             foreach ($module_version['files_dir'] as $path) {
                 $cp = '';
                 $arr_p = explode("/", $path);
                 foreach ($arr_p as $p) {
                     if (trim($p) != "") {
                         if (!is_dir(NV_ROOTDIR . '/' . NV_FILES_DIR . '/' . $cp . $p)) {
                             nv_mkdir(NV_ROOTDIR . '/' . NV_FILES_DIR . '/' . $cp, $p);
                         }
                         $cp .= $p . '/';
                     }
                 }
             }
         }
         $return = 'OK_' . $module_name;
         nv_delete_all_cache();
     }
     return $return;
 }