PageRenderTime 49ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/NukeViet3.3/includes/core/user_functions.php

http://nuke-viet.googlecode.com/
PHP | 736 lines | 601 code | 73 blank | 62 comment | 80 complexity | 596286f4ef17d2449ffa55171e944c6c MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, GPL-2.0
  1. <?php
  2. /**
  3. * @Project NUKEVIET 3.0
  4. * @Author VINADES.,JSC (contact@vinades.vn)
  5. * @Copyright (C) 2010 VINADES.,JSC. All rights reserved
  6. * @Createdate 1-27-2010 5:25
  7. */
  8. if (!defined('NV_MAINFILE'))
  9. die('Stop!!!');
  10. /**
  11. * nv_site_mods()
  12. *
  13. * @return
  14. */
  15. function nv_site_mods()
  16. {
  17. global $admin_info, $user_info, $global_config;
  18. if (defined("NV_IS_USER"))
  19. {
  20. $user_ops = array('main', 'changepass', 'openid', 'editinfo', 'regroups');
  21. if (!defined("NV_IS_ADMIN"))
  22. {
  23. $user_ops[] = 'logout';
  24. }
  25. }
  26. else
  27. {
  28. $user_ops = array('main', 'login', 'register', 'lostpass');
  29. if ($global_config['allowuserreg'] == 2)
  30. {
  31. $user_ops[] = 'lostactivelink';
  32. $user_ops[] = 'active';
  33. }
  34. }
  35. $sql = "SELECT * FROM `" . NV_MODULES_TABLE . "` AS m LEFT JOIN `" . NV_MODFUNCS_TABLE . "` AS f ON m.title=f.in_module WHERE m.act = 1 ORDER BY m.weight, f.subweight";
  36. $list = nv_db_cache($sql, '', 'modules');
  37. if (empty($list))
  38. return array();
  39. $site_mods = array();
  40. foreach ($list as $row)
  41. {
  42. $allowed = false;
  43. $is_modadmin = false;
  44. $m_title = $row['title'];
  45. $groups_view = ( string )$row['groups_view'];
  46. if (isset($site_mods[$m_title]))
  47. {
  48. $allowed = true;
  49. $is_modadmin = $site_mods[$m_title]['is_modadmin'];
  50. }
  51. elseif (defined('NV_IS_SPADMIN'))
  52. {
  53. $allowed = true;
  54. $is_modadmin = true;
  55. }
  56. elseif (defined('NV_IS_ADMIN') and !empty($row['admins']) and !empty($admin_info['admin_id']) and in_array($admin_info['admin_id'], explode(",", $row['admins'])))
  57. {
  58. $allowed = true;
  59. $is_modadmin = true;
  60. }
  61. elseif ($m_title == $global_config['site_home_module'])
  62. {
  63. $allowed = true;
  64. }
  65. elseif ($groups_view == "0")
  66. {
  67. $allowed = true;
  68. }
  69. elseif ($groups_view == "1" and defined('NV_IS_USER'))
  70. {
  71. $allowed = true;
  72. }
  73. elseif ($groups_view == "2" and defined('NV_IS_ADMIN'))
  74. {
  75. $allowed = true;
  76. }
  77. elseif (defined('NV_IS_USER') and nv_is_in_groups($user_info['in_groups'], $groups_view))
  78. {
  79. $allowed = true;
  80. }
  81. if ($allowed)
  82. {
  83. if (!isset($site_mods[$m_title]))
  84. {
  85. $site_mods[$m_title]['module_file'] = $row['module_file'];
  86. $site_mods[$m_title]['module_data'] = $row['module_data'];
  87. $site_mods[$m_title]['custom_title'] = $row['custom_title'];
  88. $site_mods[$m_title]['admin_file'] = $row['admin_file'];
  89. $site_mods[$m_title]['theme'] = $row['theme'];
  90. $site_mods[$m_title]['mobile'] = $row['mobile'];
  91. $site_mods[$m_title]['keywords'] = $row['keywords'];
  92. $site_mods[$m_title]['groups_view'] = $row['groups_view'];
  93. $site_mods[$m_title]['in_menu'] = $row['in_menu'];
  94. $site_mods[$m_title]['submenu'] = $row['submenu'];
  95. $site_mods[$m_title]['is_modadmin'] = $is_modadmin;
  96. $site_mods[$m_title]['rss'] = $row['rss'];
  97. }
  98. $func_name = $row['func_name'];
  99. if (!empty($func_name) and (($m_title != "users") or ($m_title == "users" and in_array($func_name, $user_ops))))
  100. {
  101. $site_mods[$m_title]['funcs'][$func_name]['func_id'] = $row['func_id'];
  102. $site_mods[$m_title]['funcs'][$func_name]['show_func'] = $row['show_func'];
  103. $site_mods[$m_title]['funcs'][$func_name]['func_custom_name'] = $row['func_custom_name'];
  104. $site_mods[$m_title]['funcs'][$func_name]['in_submenu'] = $row['in_submenu'];
  105. }
  106. }
  107. }
  108. return $site_mods;
  109. }
  110. /**
  111. * nv_create_submenu()
  112. *
  113. * @return void
  114. */
  115. function nv_create_submenu()
  116. {
  117. global $nv_vertical_menu, $module_name, $module_info, $op;
  118. foreach ($module_info['funcs'] as $key => $values)
  119. {
  120. if (!empty($values['in_submenu']))
  121. {
  122. $func_custom_name = trim(!empty($values['func_custom_name']) ? $values['func_custom_name'] : $key);
  123. $link = NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . ($key != "main" ? "&amp;" . NV_OP_VARIABLE . "=" . $key : "");
  124. $act = $key == $op ? 1 : 0;
  125. $nv_vertical_menu[] = array($func_custom_name, $link, $act);
  126. }
  127. }
  128. }
  129. /**
  130. * nv_setBlockAllowed()
  131. *
  132. * @param mixed $groups_view
  133. * @return
  134. */
  135. function nv_setBlockAllowed($groups_view)
  136. {
  137. global $user_info;
  138. if (defined('NV_IS_SPADMIN'))
  139. return true;
  140. $groups_view = ( string )$groups_view;
  141. if ($groups_view == "0" or ($groups_view == "1" and defined('NV_IS_USER')) or ($groups_view == "2" and defined('NV_IS_MODADMIN')))
  142. return true;
  143. if (defined('NV_IS_USER') and nv_is_in_groups($user_info['in_groups'], $groups_view))
  144. return true;
  145. return false;
  146. }
  147. /**
  148. * nv_blocks_get_content()
  149. *
  150. * @return
  151. */
  152. function nv_blocks_content($sitecontent)
  153. {
  154. global $db, $module_info, $module_name, $op, $global_config, $lang_global, $site_mods, $user_info;
  155. //Lay danh sach cac nhom block trong config.ini
  156. $xml = simplexml_load_file(NV_ROOTDIR . '/themes/' . $global_config['module_theme'] . '/config.ini');
  157. $_content = $xml->xpath('positions');
  158. $_position = $_content[0]->position;
  159. $_posAllowed = array();
  160. foreach ($_position as $_pos)
  161. {
  162. $_pos = trim(( string )$_pos->tag);
  163. if (preg_match("/^\[([^\]]+)\]$/is", $_pos, $matches))
  164. {
  165. $_posAllowed[] = $matches[1];
  166. }
  167. }
  168. if (empty($_posAllowed))
  169. return $sitecontent;
  170. //Tim trong noi dung trang cac doan ma phu hop voi cac nhom block tren
  171. $_posAllowed = implode("|", array_map("nv_preg_quote", $_posAllowed));
  172. preg_match_all("/\[(" . $_posAllowed . ")(\d+)?\]()/", $sitecontent, $_posReal);
  173. if (empty($_posReal[0]))
  174. return $sitecontent;
  175. $_posReal = array_combine($_posReal[0], $_posReal[3]);
  176. $cache_file = NV_LANG_DATA . "_themes_" . $global_config['module_theme'] . "_" . $module_name . "_" . NV_CACHE_PREFIX . ".cache";
  177. $blocks = array();
  178. if (($cache = nv_get_cache($cache_file)) !== false)
  179. {
  180. $cache = unserialize($cache);
  181. if (isset($cache[$module_info['funcs'][$op]['func_id']]))
  182. $blocks = $cache[$module_info['funcs'][$op]['func_id']];
  183. unset($cache);
  184. }
  185. else
  186. {
  187. $cache = array();
  188. $in = array();
  189. $sql = "SELECT * FROM `" . NV_MODULES_TABLE . "` AS m LEFT JOIN `" . NV_MODFUNCS_TABLE . "` AS f ON m.title=f.in_module WHERE m.act = 1 ORDER BY m.weight, f.subweight";
  190. $list = nv_db_cache($sql, '', 'modules');
  191. foreach ($list as $row)
  192. {
  193. if ($row['title'] == $module_name and $row['show_func'])
  194. {
  195. $in[] = $row['func_id'];
  196. }
  197. }
  198. $_result = $db->sql_query("SELECT t1.*, t2.func_id FROM `" . NV_BLOCKS_TABLE . "_groups` AS t1
  199. INNER JOIN `" . NV_BLOCKS_TABLE . "_weight` AS t2
  200. ON t1.bid = t2.bid
  201. WHERE t2.func_id IN (" . implode(",", $in) . ")
  202. AND t1.theme ='" . $global_config['module_theme'] . "'
  203. AND t1.active=1
  204. ORDER BY t2.weight ASC");
  205. while ($_row = $db->sql_fetch_assoc($_result))
  206. {
  207. //Cau hinh block
  208. $block_config = (!empty($_row['config'])) ? unserialize($_row['config']) : array();
  209. $block_config['bid'] = $_row['bid'];
  210. $block_config['module'] = $_row['module'];
  211. $block_config['title'] = $_row['title'];
  212. $block_config['block_name'] = substr($_row['file_name'], 0, -4);
  213. //tieu de block
  214. $blockTitle = (!empty($_row['title']) and !empty($_row['link'])) ? "<a href=\"" . $_row['link'] . "\">" . $_row['title'] . "</a>" : $_row['title'];
  215. if (!isset($cache[$_row['func_id']]))
  216. $cache[$_row['func_id']] = array();
  217. $cache[$_row['func_id']][] = array('bid' => $_row['bid'], 'position' => $_row['position'], 'module' => $_row['module'], 'blockTitle' => $blockTitle, 'file_name' => $_row['file_name'], 'template' => $_row['template'], 'exp_time' => $_row['exp_time'], 'groups_view' => $_row['groups_view'], 'all_func' => $_row['all_func'], 'block_config' => $block_config);
  218. }
  219. if (isset($cache[$module_info['funcs'][$op]['func_id']]))
  220. $blocks = $cache[$module_info['funcs'][$op]['func_id']];
  221. $db->sql_freeresult($_result);
  222. $cache = serialize($cache);
  223. nv_set_cache($cache_file, $cache);
  224. unset($cache, $in, $block_config, $blockTitle);
  225. }
  226. if (!empty($blocks))
  227. {
  228. $unact = array();
  229. $array_position = array_keys($_posReal);
  230. foreach ($blocks as $_row)
  231. {
  232. if ($_row['exp_time'] != 0 and $_row['exp_time'] <= NV_CURRENTTIME)
  233. {
  234. $unact[] = $_row['bid'];
  235. continue;
  236. }
  237. //Kiem tra quyen xem block
  238. if (in_array($_row['position'], $array_position) and nv_setBlockAllowed($_row['groups_view']))
  239. {
  240. $block_config = $_row['block_config'];
  241. $blockTitle = $_row['blockTitle'];
  242. $content = "";
  243. if ($_row['module'] == "global" and file_exists(NV_ROOTDIR . "/includes/blocks/" . $_row['file_name']))
  244. {
  245. include (NV_ROOTDIR . "/includes/blocks/" . $_row['file_name']);
  246. }
  247. elseif (isset($site_mods[$_row['module']]['module_file']) and !empty($site_mods[$_row['module']]['module_file']) and file_exists(NV_ROOTDIR . "/modules/" . $site_mods[$_row['module']]['module_file'] . "/blocks/" . $_row['file_name']))
  248. {
  249. include (NV_ROOTDIR . "/modules/" . $site_mods[$_row['module']]['module_file'] . "/blocks/" . $_row['file_name']);
  250. }
  251. unset($block_config);
  252. if (!empty($content) or defined('NV_IS_DRAG_BLOCK'))
  253. {
  254. $xtpl = null;
  255. $_row['template'] = empty($_row['template']) ? "default" : $_row['template'];
  256. if (!empty($module_info['theme']) and file_exists(NV_ROOTDIR . "/themes/" . $module_info['theme'] . "/layout/block." . $_row['template'] . ".tpl"))
  257. {
  258. $xtpl = new XTemplate("block." . $_row['template'] . ".tpl", NV_ROOTDIR . "/themes/" . $module_info['theme'] . "/layout");
  259. }
  260. elseif (!empty($global_config['module_theme']) and file_exists(NV_ROOTDIR . "/themes/" . $global_config['module_theme'] . "/layout/block." . $_row['template'] . ".tpl"))
  261. {
  262. $xtpl = new XTemplate("block." . $_row['template'] . ".tpl", NV_ROOTDIR . "/themes/" . $global_config['module_theme'] . "/layout");
  263. }
  264. elseif (!empty($global_config['site_theme']) and file_exists(NV_ROOTDIR . "/themes/" . $global_config['site_theme'] . "/layout/block." . $_row['template'] . ".tpl"))
  265. {
  266. $xtpl = new XTemplate("block." . $_row['template'] . ".tpl", NV_ROOTDIR . "/themes/" . $global_config['site_theme'] . "/layout");
  267. }
  268. elseif (file_exists(NV_ROOTDIR . "/themes/default/layout/block." . $_row['template'] . ".tpl"))
  269. {
  270. $xtpl = new XTemplate("block." . $_row['template'] . ".tpl", NV_ROOTDIR . "/themes/default/layout");
  271. }
  272. if (!empty($xtpl))
  273. {
  274. $xtpl->assign('BLOCK_TITLE', $_row['blockTitle']);
  275. $xtpl->assign('BLOCK_CONTENT', $content);
  276. $xtpl->parse('mainblock');
  277. $content = $xtpl->text('mainblock');
  278. }
  279. else
  280. {
  281. $content = $_row['blockTitle'] . "<br />" . $content . "<br />";
  282. }
  283. if (defined('NV_IS_DRAG_BLOCK'))
  284. {
  285. $content = '<div class="portlet" id="bl_' . ($_row['bid']) . '">
  286. <p>
  287. <a href="javascript:void(0)" class="block_content" name="' . $_row['bid'] . '">
  288. <img style="border:none" src="' . NV_BASE_SITEURL . 'images/edit.png" alt="' . $lang_global['edit_block'] . '"/> ' . $lang_global['edit_block'] . '</a> | <a href="javascript:void(0)" class="delblock" name="' . $_row['bid'] . '">
  289. <img style="border:none" src="' . NV_BASE_SITEURL . 'images/delete.png" alt="' . $lang_global['delete_block'] . '"/> ' . $lang_global['delete_block'] . '</a> | <a href="javascript:void(0)" class="outgroupblock" name="' . $_row['bid'] . '">
  290. <img style="border:none" src="' . NV_BASE_SITEURL . 'images/outgroup.png" alt="' . $lang_global['outgroup_block'] . '"/> ' . $lang_global['outgroup_block'] . '</a>
  291. </p>
  292. ' . $content . '</div>';
  293. }
  294. $_posReal[$_row['position']] .= $content;
  295. }
  296. }
  297. }
  298. if (!empty($unact))
  299. {
  300. $sql = "UPDATE `" . NV_BLOCKS_TABLE . "_groups` SET `active`='0' WHERE `bid`IN (" . implode(",", $unact) . ") LIMIT " . sizeof($unact);
  301. $db->sql_query($sql);
  302. unlink($cache_file);
  303. }
  304. }
  305. if (defined('NV_IS_DRAG_BLOCK'))
  306. {
  307. $array_keys = array_keys($_posReal);
  308. foreach ($array_keys as $__pos)
  309. {
  310. $_posReal[$__pos] = '<div class="column" id="' . ( preg_replace('#\[|\]#', '', $__pos)) . '">' . $_posReal[$__pos];
  311. $_posReal[$__pos] .= ' <span><a class="block_content" id="' . $__pos . '" href="javascript:void(0)"><img style="border:none" src="' . NV_BASE_SITEURL . 'images/add.png" alt="' . $lang_global['add_block'] . '"/> ' . $lang_global['add_block'] . '</a></span>';
  312. $_posReal[$__pos] .= '</div>';
  313. }
  314. }
  315. $sitecontent = str_replace(array_keys($_posReal), array_values($_posReal), $sitecontent);
  316. return $sitecontent;
  317. }
  318. /**
  319. * nv_html_meta_tags()
  320. *
  321. * @return
  322. */
  323. function nv_html_meta_tags()
  324. {
  325. global $global_config, $lang_global, $key_words, $description, $module_info, $home, $client_info, $op, $page_title, $canonicalUrl;
  326. $return = "";
  327. if ($home)
  328. {
  329. $return .= "<meta name=\"description\" content=\"" . strip_tags($global_config['site_description']) . "\" />\n";
  330. }
  331. else
  332. {
  333. if ( ! empty( $description ) )
  334. {
  335. $return .= "<meta name=\"description\" content=\"" . strip_tags( $description ) . "\" />\n";
  336. }
  337. else
  338. {
  339. $ds = array();
  340. if ( ! empty( $page_title ) ) $ds[] = $page_title;
  341. if ( $op != "main" ) $ds[] = $module_info['funcs'][$op]['func_custom_name'];
  342. $ds[] = $module_info['custom_title'];
  343. $ds[] = $client_info['selfurl'];
  344. $return .= "<meta name=\"description\" content=\"" . strip_tags( implode( " - ", $ds ) ) . "\" />\n";
  345. }
  346. }
  347. $kw = array();
  348. if (!empty($key_words))
  349. $kw[] = $key_words;
  350. if (!empty($module_info['keywords']))
  351. $kw[] = $module_info['keywords'];
  352. if (!empty($global_config['site_keywords']))
  353. $kw[] = $global_config['site_keywords'];
  354. if (!empty($kw))
  355. {
  356. $kw = array_unique( $kw );
  357. $kw = implode(",", $kw);
  358. $kw = preg_replace(array("/[ ]*\,[ ]+/", "/[\,]+/"), array(",", ","), $kw);
  359. $key_words = nv_strtolower(strip_tags($kw));
  360. $return .= "<meta name=\"keywords\" content=\"" . $key_words . "\" />\n";
  361. }
  362. $return .= "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=" . $global_config['site_charset'] . "\" />\n";
  363. $file_metatags = NV_ROOTDIR . "/" . NV_DATADIR . "/metatags.xml";
  364. if (file_exists($file_metatags))
  365. {
  366. $mt = file_get_contents($file_metatags);
  367. $patters = array();
  368. $patters['/\{CONTENT\-LANGUAGE\}/'] = $lang_global['Content_Language'];
  369. $patters['/\{LANGUAGE\}/'] = $lang_global['LanguageName'];
  370. $patters['/\{SITE\_NAME\}/'] = $global_config['site_name'];
  371. $patters['/\{SITE\_EMAIL\}/'] = $global_config['site_email'];
  372. $mt = preg_replace(array_keys($patters), array_values($patters), $mt);
  373. $mt = preg_replace("/\{(.*)\}/", "", $mt);
  374. $mt = simplexml_load_string($mt);
  375. $mt = nv_object2array($mt);
  376. if ($mt['meta_item'])
  377. {
  378. if (isset($mt['meta_item'][0]))
  379. $metatags = $mt['meta_item'];
  380. else
  381. $metatags[] = $mt['meta_item'];
  382. foreach ($metatags as $meta)
  383. {
  384. if (($meta['group'] == "http-equiv" or $meta['group'] == "name") and preg_match("/^[a-zA-Z0-9\-\_\.]+$/", $meta['value']) and preg_match("/^([^\'\"]+)$/", $meta['content']))
  385. {
  386. $return .= "<meta " . $meta['group'] . "=\"" . $meta['value'] . "\" content=\"" . $meta['content'] . "\" />\n";
  387. }
  388. }
  389. }
  390. }
  391. $return .= "<meta name=\"generator\" content=\"NukeViet v3.x\" />\n";
  392. if (defined('NV_IS_ADMIN'))
  393. {
  394. $return .= "<meta http-equiv=\"refresh\" content=\"" . NV_ADMIN_CHECK_PASS_TIME . "\" />\n";
  395. }
  396. if (empty($canonicalUrl))
  397. $canonicalUrl = $client_info['selfurl'];
  398. if (substr($canonicalUrl, 0, 4) != "http")
  399. {
  400. if (substr($canonicalUrl, 0, 1) != "/")
  401. $canonicalUrl = NV_BASE_SITEURL . $canonicalUrl;
  402. $canonicalUrl = NV_MY_DOMAIN . $canonicalUrl;
  403. }
  404. $return .= "<link rel=\"canonical\" href=\"" . $canonicalUrl . "\" />\n";
  405. return $return;
  406. }
  407. /**
  408. * nv_html_page_title()
  409. *
  410. * @return
  411. */
  412. function nv_html_page_title()
  413. {
  414. global $home, $module_info, $op, $global_config, $page_title;
  415. $replace = array("\\", "/", ":", "*", "?", "\"", "<", ">", "|");
  416. if ($home)
  417. {
  418. return "<title>" . nv_htmlspecialchars(str_replace($replace, "", strip_tags($global_config['site_name']))) . "</title>\n";
  419. }
  420. else
  421. {
  422. if (!isset($global_config['pageTitleMode']) or empty($global_config['pageTitleMode']))
  423. $global_config['pageTitleMode'] = "pagetitle " . NV_TITLEBAR_DEFIS . " sitename";
  424. if (empty($page_title) and !preg_match("/(funcname|modulename|sitename)/i", $global_config['pageTitleMode']))
  425. return "<title>" . nv_htmlspecialchars(str_replace($replace, "", strip_tags($module_info['funcs'][$op]['func_custom_name'] . " " . NV_TITLEBAR_DEFIS . " " . $module_info['custom_title']))) . "</title>\n";
  426. $_title = preg_replace(array("/pagetitle/i", "/funcname/i", "/modulename/i", "/sitename/i"), array($page_title, $module_info['funcs'][$op]['func_custom_name'], $module_info['custom_title'], $global_config['site_name']), $global_config['pageTitleMode']);
  427. return "<title>" . nv_htmlspecialchars(str_replace($replace, "", strip_tags($_title))) . "</title>\n";
  428. }
  429. }
  430. /**
  431. * nv_html_css()
  432. *
  433. * @return
  434. */
  435. function nv_html_css()
  436. {
  437. global $module_info, $module_file;
  438. if (file_exists(NV_ROOTDIR . "/themes/" . $module_info['template'] . "/css/" . $module_file . ".css"))
  439. {
  440. return "<link rel=\"StyleSheet\" href=\"" . NV_BASE_SITEURL . "themes/" . $module_info['template'] . "/css/" . $module_file . ".css\" type=\"text/css\" />\n";
  441. }
  442. return "";
  443. }
  444. /**
  445. * nv_html_site_rss()
  446. *
  447. * @return
  448. */
  449. function nv_html_site_rss()
  450. {
  451. global $rss;
  452. $return = "";
  453. if (!empty($rss))
  454. {
  455. foreach ($rss as $rss_item)
  456. {
  457. $return .= "<link rel=\"alternate\" href=\"" . $rss_item['src'] . "\" title=\"" . strip_tags($rss_item['title']) . "\" type=\"application/rss+xml\" />\n";
  458. }
  459. }
  460. return $return;
  461. }
  462. /**
  463. * nv_html_site_js()
  464. *
  465. * @return
  466. */
  467. function nv_html_site_js()
  468. {
  469. global $global_config, $module_info, $module_name, $module_file, $lang_global, $op, $client_info;
  470. $return = "<script type=\"text/javascript\" src=\"" . NV_BASE_SITEURL . "js/language/" . NV_LANG_INTERFACE . ".js\"></script>\n";
  471. $return .= "<script type=\"text/javascript\" src=\"" . NV_BASE_SITEURL . "js/jquery/jquery.min.js\"></script>\n";
  472. $return .= "<script type=\"text/javascript\">\n//<![CDATA[\n";
  473. $return .= "var nv_siteroot=\"" . NV_BASE_SITEURL . "\",nv_sitelang=\"" . NV_LANG_INTERFACE . "\",nv_name_variable=\"" . NV_NAME_VARIABLE . "\",nv_fc_variable=\"" . NV_OP_VARIABLE . "\",nv_lang_variable=\"" . NV_LANG_VARIABLE . "\",nv_module_name=\"" . $module_name . "\",nv_my_ofs=" . round(NV_SITE_TIMEZONE_OFFSET / 3600) . ",nv_my_abbr=\"" . nv_date("T", NV_CURRENTTIME) . "\",nv_cookie_prefix=\"" . $global_config['cookie_prefix'] . "\",nv_area_admin=0;\n";
  474. $return .= "//]]>\n</script>\n";
  475. $return .= "<script type=\"text/javascript\" src=\"" . NV_BASE_SITEURL . "js/global.js\"></script>\n";
  476. if (defined('NV_IS_ADMIN'))
  477. {
  478. $return .= "<script type=\"text/javascript\" src=\"" . NV_BASE_SITEURL . "js/admin.js\"></script>\n";
  479. }
  480. if (file_exists(NV_ROOTDIR . "/modules/" . $module_file . "/js/user.js"))
  481. {
  482. $return .= "<script type=\"text/javascript\" src=\"" . NV_BASE_SITEURL . "modules/" . $module_file . "/js/user.js\"></script>\n";
  483. }
  484. if (defined('NV_EDITOR') and nv_function_exists('nv_add_editor_js'))
  485. {
  486. $return .= nv_add_editor_js();
  487. }
  488. if (defined('NV_IS_DRAG_BLOCK'))
  489. {
  490. if (!defined('SHADOWBOX'))
  491. {
  492. $return .= "<link rel=\"Stylesheet\" href=\"" . NV_BASE_SITEURL . "js/shadowbox/shadowbox.css\" />\n";
  493. $return .= "<script type=\"text/javascript\" src=\"" . NV_BASE_SITEURL . "js/shadowbox/shadowbox.js\"></script>\n";
  494. $return .= "<script type=\"text/javascript\">Shadowbox.init();</script>";
  495. define('SHADOWBOX', true);
  496. }
  497. $return .= "<script type=\"text/javascript\" src=\"" . NV_BASE_SITEURL . "js/ui/jquery.ui.core.min.js\"></script>\n";
  498. $return .= "<script type=\"text/javascript\" src=\"" . NV_BASE_SITEURL . "js/ui/jquery.ui.sortable.min.js\"></script>\n";
  499. $return .= '<script type="text/javascript">
  500. //<![CDATA[
  501. var blockredirect = "' . nv_base64_encode($client_info['selfurl']) . '";
  502. $(function() {
  503. $("a.delblock").click(function(){
  504. var bid = $(this).attr("name");
  505. if (confirm("' . $lang_global['block_delete_confirm'] . '")){
  506. $.post("' . NV_BASE_ADMINURL . 'index.php?' . NV_NAME_VARIABLE . '=themes&' . NV_OP_VARIABLE . '=blocks_del", "bid="+bid, function(theResponse){
  507. alert(theResponse);
  508. window.location.href = "' . $client_info['selfurl'] . '";
  509. });
  510. }
  511. });
  512. $("a.outgroupblock").click(function(){
  513. var bid = $(this).attr("name");
  514. if (confirm("' . $lang_global['block_outgroup_confirm'] . '")){
  515. $.post("' . NV_BASE_ADMINURL . 'index.php?' . NV_NAME_VARIABLE . '=themes&' . NV_OP_VARIABLE . '=front_outgroup", "func_id=' . $module_info['funcs'][$op]['func_id'] . '&bid="+bid, function(theResponse){
  516. alert(theResponse);
  517. });
  518. }
  519. });
  520. $("a.block_content").click(function(){
  521. var bid = $(this).attr("name");
  522. var tag = $(this).attr("id");
  523. Shadowbox.open(
  524. {
  525. content : "<iframe src=\'' . NV_BASE_ADMINURL . 'index.php?' . NV_NAME_VARIABLE . '=themes&' . NV_OP_VARIABLE . '=block_content&selectthemes=' . $global_config['module_theme'] . '&tag="+tag+"&bid="+bid+"&blockredirect="+blockredirect+"\' style=\'width:780px;height:450px\'></iframe>",
  526. player : "html",
  527. height : 450,
  528. width : 780
  529. }
  530. );
  531. });
  532. var func_id = ' . ($module_info['funcs'][$op]['func_id']) . ';
  533. var post_order = false;
  534. $(".column").sortable({
  535. connectWith: \'.column\',
  536. opacity: 0.8,
  537. cursor: \'move\',
  538. receive: function(){
  539. post_order = true;
  540. var position = $(this).attr("id");
  541. var order = $(this).sortable("serialize");
  542. $.post("' . NV_BASE_ADMINURL . 'index.php?' . NV_NAME_VARIABLE . '=themes&' . NV_OP_VARIABLE . '=sort_order", order+"&position="+position+"&func_id="+func_id, function(theResponse){
  543. if(theResponse=="OK_"+func_id){
  544. $("div#toolbar>ul.info").html("<li><span style=\'color:#ff0000;padding-left:150px;font-weight:700;\'>' . $lang_global['blocks_saved'] . '</span></li>").fadeIn(1000);
  545. }
  546. else{
  547. alert("' . $lang_global['blocks_saved_error'] . '");
  548. }
  549. });
  550. },
  551. stop: function() {
  552. if(post_order == false){
  553. var order = $(this).sortable("serialize");
  554. $.post("' . NV_BASE_ADMINURL . 'index.php?' . NV_NAME_VARIABLE . '=themes&' . NV_OP_VARIABLE . '=sort_order", order+"&func_id="+func_id, function(theResponse){
  555. if(theResponse=="OK_"+func_id){
  556. $("div#toolbar>ul.info").html("<span style=\'color:#ff0000;padding-left:150px;font-weight:700;\'>' . $lang_global['blocks_saved'] . '</span>").fadeIn(1000);
  557. }
  558. else{
  559. alert("' . $lang_global['blocks_saved_error'] . '");
  560. }
  561. });
  562. }
  563. }
  564. });
  565. $(".column").disableSelection();
  566. });
  567. //]]>
  568. </script>';
  569. }
  570. return $return;
  571. }
  572. /**
  573. * nv_admin_menu()
  574. *
  575. * @return
  576. */
  577. function nv_admin_menu()
  578. {
  579. global $lang_global, $admin_info, $module_info, $module_name, $db, $my_head;
  580. $block_theme = "default";
  581. $xtpl = new XTemplate("admin_toolbar.tpl", NV_ROOTDIR . "/themes/" . $block_theme . "/system");
  582. $xtpl->assign('GLANG', $lang_global);
  583. $xtpl->assign('ADMIN_INFO', $admin_info);
  584. $xtpl->assign('NV_BASE_SITEURL', NV_BASE_SITEURL);
  585. $xtpl->assign('NV_ADMINDIR', NV_ADMINDIR);
  586. $xtpl->assign('URL_AUTHOR', NV_BASE_SITEURL . NV_ADMINDIR . "/index.php?" . NV_NAME_VARIABLE . "=authors&amp;id=" . $admin_info['admin_id']);
  587. if (defined('NV_IS_SPADMIN'))
  588. {
  589. if (!defined('SHADOWBOX'))
  590. {
  591. $my_head .= "<link rel=\"Stylesheet\" href=\"" . NV_BASE_SITEURL . "js/shadowbox/shadowbox.css\" />\n";
  592. $my_head .= "<script type=\"text/javascript\" src=\"" . NV_BASE_SITEURL . "js/shadowbox/shadowbox.js\"></script>\n";
  593. $my_head .= "<script type=\"text/javascript\">Shadowbox.init();</script>";
  594. define('SHADOWBOX', true);
  595. }
  596. $new_drag_block = ( defined('NV_IS_DRAG_BLOCK')) ? 0 : 1;
  597. $lang_drag_block = ($new_drag_block) ? $lang_global['drag_block'] : $lang_global['no_drag_block'];
  598. $total_time = substr((array_sum(explode(" ", microtime())) - NV_START_TIME + $db->time), 0, 5);
  599. $xtpl->assign('URL_DBLOCK', NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;drag_block=" . $new_drag_block);
  600. $xtpl->assign('LANG_DBLOCK', $lang_drag_block);
  601. $xtpl->assign('COUNT_SHOW_QUERIES', sizeof($db->query_strs) . " / " . $total_time);
  602. foreach ($db->query_strs as $key => $field)
  603. {
  604. $data = array("class" => ($key % 2) ? " highlight" : " normal", "imgsrc" => ($field[1]) ? NV_BASE_SITEURL . "themes/" . $block_theme . "/images/icons/good.png" : NV_BASE_SITEURL . "themes/" . $block_theme . "/images/icons/bad.png", "imgalt" => ($field[1]) ? $lang_global['ok'] : $lang_global['fail'], "queries" => nv_htmlspecialchars($field[0]));
  605. $xtpl->assign('DATA', $data);
  606. $xtpl->parse('main.is_spadadmin3.queries');
  607. }
  608. $xtpl->parse('main.is_spadadmin');
  609. $xtpl->parse('main.is_spadadmin2');
  610. $xtpl->parse('main.is_spadadmin3');
  611. }
  612. if (defined('NV_IS_MODADMIN') and !empty($module_info['admin_file']))
  613. {
  614. $xtpl->assign('URL_MODULE', NV_BASE_SITEURL . NV_ADMINDIR . "/index.php?" . NV_NAME_VARIABLE . "=" . $module_name);
  615. $xtpl->parse('main.is_modadmin');
  616. }
  617. $xtpl->parse('main');
  618. return $xtpl->text('main');
  619. }
  620. /**
  621. * nv_groups_list_pub()
  622. *
  623. * @return
  624. */
  625. function nv_groups_list_pub()
  626. {
  627. global $db;
  628. $query = "SELECT `group_id`, `title`, `exp_time`, `public` FROM `" . NV_GROUPS_GLOBALTABLE . "` WHERE `act`=1 ORDER BY `weight`";
  629. $list = nv_db_cache($query, '', 'users');
  630. if (empty($list))
  631. return array();
  632. $groups = array();
  633. $reload = array();
  634. for ($i = 0, $count = sizeof($list); $i < $count; ++$i)
  635. {
  636. if ($list[$i]['exp_time'] != 0 and $list[$i]['exp_time'] <= NV_CURRENTTIME)
  637. {
  638. $reload[] = $list[$i]['group_id'];
  639. }
  640. elseif ($list[$i]['public'])
  641. {
  642. $groups[$list[$i]['group_id']] = $list[$i]['title'];
  643. }
  644. }
  645. if ($reload)
  646. {
  647. $sql = "UPDATE `" . NV_GROUPS_GLOBALTABLE . "` SET `act`='0' WHERE `group_id` IN (" . implode(",", $reload) . ")";
  648. $db->sql_query($sql);
  649. nv_del_moduleCache('users');
  650. }
  651. return $groups;
  652. }
  653. ?>