function save_data_auto($catid, $blockcat, $title, $alias, $hometext, $bodytext, $sourceid, $publtime, $homefile, $homeimgthumb, $link, $array_block_cat_module) { global $db, $module_config; $error = ""; $module = $module_config['getnews']['module']; $mod_data = str_replace('-', '_', $module); if ($hometext != "") { $keywords = nv_get_keywords($hometext); } else { $keywords = nv_get_keywords(nv_fil_tag($bodytext)); } $row = array("id" => "", "author" => ""); $hitstotal = rand(1, 5); $query = "INSERT INTO `" . NV_PREFIXLANG . "_" . $mod_data . "_rows` \n\t\t(`id`, `catid`, `listcatid`, `topicid`, `admin_id`, `author`, `sourceid`, `addtime`, `edittime`, `status`, `publtime`, `exptime`, `archive`, `title`, `alias`, `hometext`, `homeimgfile`, `homeimgalt`, `homeimgthumb`, `inhome`, `allowed_comm`, `allowed_rating`, `hitstotal`, `hitscm`, `total_rating`, `click_rating`, `keywords`) VALUES \n\t\t(NULL, \n\t\t" . intval($catid) . ",\n\t\t" . $db->dbescape_string($catid) . ",\n\t\t" . intval(0) . ",\n\t\t" . intval(1) . ",\n\t\t" . $db->dbescape_string($row['author']) . ",\n\t\t" . intval($sourceid) . ",\n\t\t" . intval($publtime) . ",\n\t\t" . intval($publtime) . ",\n\t\t" . intval($module_config['getnews']['active']) . ",\n\t\t" . intval($publtime) . ",\n\t\t" . intval(0) . ", \n\t\t" . intval(2) . ",\n\t\t" . $db->dbescape_string($title) . ",\n\t\t" . $db->dbescape_string($alias) . ",\n\t\t" . $db->dbescape_string($hometext) . ",\n\t\t" . $db->dbescape_string($homefile) . ",\n\t\t" . $db->dbescape_string($title) . ",\n\t\t" . $db->dbescape_string($homeimgthumb) . ",\n\t\t" . intval(1) . ", \n\t\t" . intval(2) . ", \n\t\t" . intval(1) . ", \n\t\t" . intval($hitstotal) . ", \n\t\t" . intval(0) . ", \n\t\t" . intval(0) . ", \n\t\t" . intval(0) . ", \n\t\t" . $db->dbescape_string($keywords) . ")"; $row['id'] = $db->sql_query_insert_id($query); if ($row['id'] > 0) { $bodytext2 = nv_news_get_bodytext(nv_convert($bodytext)); $ct_query = array(); $tbhtml = NV_PREFIXLANG . "_" . $mod_data . "_bodyhtml_" . ceil($row['id'] / 2000); $db->sql_query("CREATE TABLE IF NOT EXISTS `" . $tbhtml . "` (`id` int(11) unsigned NOT NULL, `bodyhtml` longtext NOT NULL, `sourcetext` varchar(255) NOT NULL default '', `imgposition` tinyint(1) NOT NULL default '1', `copyright` tinyint(1) NOT NULL default '0', `allowed_send` tinyint(1) NOT NULL default '0', `allowed_print` tinyint(1) NOT NULL default '0', `allowed_save` tinyint(1) NOT NULL default '0', PRIMARY KEY (`id`)) ENGINE=MyISAM"); $ct_query[] = (int) $db->sql_query("INSERT INTO `" . $tbhtml . "` VALUES \n\t\t(\n\t\t\t" . $row['id'] . ", \n\t\t\t" . $db->dbescape_string(nv_convert($bodytext)) . ", \n\t\t\t" . $db->dbescape_string($link) . ",\n\t\t\t" . intval($module_config['getnews']['imgposition']) . ",\n\t\t\t" . intval(0) . ", \n\t\t\t" . intval(1) . ", \n\t\t\t" . intval(1) . ", \n\t\t\t" . intval(1) . "\t\t\t\t\t\n\t\t)"); $ct_query[] = (int) $db->sql_query("INSERT INTO `" . NV_PREFIXLANG . "_" . $mod_data . "_" . $catid . "` SELECT * FROM `" . NV_PREFIXLANG . "_" . $module . "_rows` WHERE `id`=" . $row['id'] . ""); $ct_query[] = (int) $db->sql_query("INSERT INTO `" . NV_PREFIXLANG . "_" . $mod_data . "_bodytext` VALUES (" . $row['id'] . ", " . $db->dbescape_string($bodytext2) . ")"); if (array_sum($ct_query) != sizeof($ct_query)) { $error .= "Lỗi khi lưu 1"; } unset($ct_query); } else { $error .= $query; } $id_block_content = explode("|", $blockcat); $id_block_content = array_unique($id_block_content); $id_block_content = array_filter($id_block_content); foreach ($id_block_content as $bid_i) { $db->sql_query("INSERT INTO `" . NV_PREFIXLANG . "_" . $mod_data . "_block` (`bid`, `id`, `weight`) VALUES ('" . $bid_i . "', '" . $row['id'] . "', '0')"); } $id_block_content[] = 0; $db->sql_query("DELETE FROM `" . NV_PREFIXLANG . "_" . $mod_data . "_block` WHERE `id` = " . $row['id'] . " AND `bid` NOT IN (" . implode(",", $id_block_content) . ")"); $id_block_content = array_keys($array_block_cat_module); foreach ($id_block_content as $bid_i) { nv_news_fix_blocks($bid_i, false); } $db->sql_freeresult(); unset($bodytext); return $error; }
$addtime = NV_CURRENTTIME - mt_rand(60, 1000); $hometext = (isset($item['hometext']) and $item['hometext']) ? nv_htmlspecialchars(str_replace('\'', '"', strip_tags($item['hometext']))) : ''; $item['bodyhtml'] = defined('NV_EDITOR') ? nv_nl2br($item['bodyhtml'], '') : nv_nl2br(nv_htmlspecialchars(strip_tags($item['bodyhtml'])), '<br />'); $bodyhtml = (isset($item['bodyhtml']) and $item['bodyhtml']) ? str_replace('\'', '"', $item['bodyhtml']) : ''; $bodytext = nv_news_get_bodytext($bodyhtml); $sourcetext = (isset($item['sourcetext']) and $item['sourcetext']) ? nv_htmlspecialchars(str_replace('\'', '"', strip_tags($item['sourcetext']))) : ''; $sourceid = (isset($item['sourceid']) and $item['sourceid']) ? $item['sourceid'] : 0; $homeimgfile = (isset($item['homeimgfile']) and $item['homeimgfile']) ? $item['homeimgfile'] : ''; $homeimgthumb = (isset($item['image_url']) and $item['image_url']) ? 'thumb/' . basename($item['image_url']) : ''; $homeimgalt = (isset($item['homeimgalt']) and $item['homeimgalt']) ? nv_htmlspecialchars(str_replace('\'', '"', strip_tags($item['homeimgalt']))) : ''; $author = (isset($item['author']) and $item['author']) ? nv_htmlspecialchars(str_replace('\'', '"', strip_tags($item['author']))) : ''; $keywords = ""; if ($hometext != "") { $keywords = nv_get_keywords($hometext); } else { $keywords = nv_get_keywords(nv_fil_tag($bodyhtml)); } /* các bảng cần chèn dữ liệu gồm: ** NV_PREFIXLANG."_".$table_name."_rows" ** NV_PREFIXLANG."_".$table_name."_".$item['catid'] ** NV_PREFIXLANG."_".$table_name."_bodyhtml_*" ** NV_PREFIXLANG."_".$table_name."_bodytext" ** NV_PREFIXLANG."_".$table_name."_block" */ $query = "INSERT INTO " . NV_PREFIXLANG . "_" . $table_name . "_rows (id, catid, listcatid, topicid, admin_id, author, sourceid, addtime, edittime, status, publtime, exptime, archive, title, alias, hometext, homeimgfile, homeimgalt, homeimgthumb, inhome, allowed_comm, allowed_rating, hitstotal, hitscm, total_rating, click_rating) VALUES \n\t\t\t\t(NULL, " . $item['catid'] . ", '" . $item['catid'] . "', 0, 1, '" . $author . "', " . $sourceid . ", " . $addtime . ", " . $addtime . ", " . $item['status'] . ", " . $addtime . ", 0, 2, '" . $item['title'] . "', '" . $item['alias'] . "', '" . $hometext . "', '" . $homeimgfile . "', '" . $homeimgalt . "', '" . $homeimgthumb . "', 1, 2, 1, 1, 0, 0, 0);"; // Lưu vào NV_PREFIXLANG."_".$table_name."_rows" //if( $id=$db->query_insert_id( $query ) ){ if ($id = $db->insert_id($query, 'id', array())) { // Lưu vào NV_PREFIXLANG."_".$table_name."_".$item['catid'] $query = "INSERT INTO " . NV_PREFIXLANG . "_" . $table_name . "_" . $item['catid'] . " (id, catid, listcatid, topicid, admin_id, author, sourceid, addtime, edittime, status, publtime, exptime, archive, title, alias, hometext, homeimgfile, homeimgalt, homeimgthumb, inhome, allowed_comm, allowed_rating, hitstotal, hitscm, total_rating, click_rating) VALUES \n\t\t\t\t\t(" . $id . ", " . $item['catid'] . ", '" . $item['catid'] . "', 0, 1, '" . $author . "', " . $sourceid . ", " . $addtime . ", " . $addtime . ", " . $item['status'] . ", " . $addtime . ", 0, 2, '" . $item['title'] . "', '" . $item['alias'] . "', '" . $hometext . "', '" . $homeimgfile . "', '" . $homeimgalt . "', 2, 1, 2, 1, 1, 0, 0, 0);"; $db->query($query);