PageRenderTime 40ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/NukeViet3.2/modules/news/global.functions.php

http://nuke-viet.googlecode.com/
PHP | 236 lines | 218 code | 12 blank | 6 comment | 39 complexity | c28ac864013067d5da576b029622997f 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 2009
  6. * @createdate 12/31/2009 0:51
  7. */
  8. if ( ! defined( 'NV_MAINFILE' ) ) die( 'Stop!!!' );
  9. function nv_comment_module ( $id, $page )
  10. {
  11. global $db, $module_name, $module_data, $global_config, $module_config, $per_page_comment;
  12. $comment_array = array();
  13. $per_page = $per_page_comment;
  14. $sql = "SELECT SQL_CALC_FOUND_ROWS a.content, a.post_time, a.post_name, a.post_email, b.userid, b.email, b.full_name, b.photo, b.view_mail FROM `" . NV_PREFIXLANG . "_" . $module_data . "_comments` as a LEFT JOIN `" . NV_USERS_GLOBALTABLE . "` as b ON a.userid =b.userid WHERE a.id= '" . $id . "' AND a.status=1 ORDER BY a.cid DESC LIMIT " . $page . "," . $per_page . "";
  15. $comment = $db->sql_query( $sql );
  16. $result_all = $db->sql_query( "SELECT FOUND_ROWS()" );
  17. list( $all_page ) = $db->sql_fetchrow( $result_all );
  18. $all_page = ( $all_page ) ? $all_page : 1;
  19. while ( list( $content, $post_time, $post_name, $post_email, $userid, $user_email, $user_full_name, $photo, $view_mail ) = $db->sql_fetchrow( $comment ) )
  20. {
  21. if ( $userid > 0 )
  22. {
  23. $post_email = $user_email;
  24. $post_name = $user_full_name;
  25. }
  26. $post_email = ( $module_config[$module_name]['emailcomm'] and $view_mail ) ? $post_email : "";
  27. $comment_array[] = array(
  28. "content" => $content, "post_time" => $post_time, "userid" => $userid, "post_name" => $post_name, "post_email" => $post_email, "photo" => $photo
  29. );
  30. }
  31. $db->sql_freeresult( $comment );
  32. unset( $row, $comment );
  33. $base_url = NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=comment&amp;id=" . $id . "&checkss=" . md5( $id . session_id() . $global_config['sitekey'] );
  34. $generate_page = nv_generate_page( $base_url, $all_page, $per_page, $page, true, true, 'nv_urldecode_ajax', 'showcomment' );
  35. return array(
  36. "comment" => $comment_array, "page" => $generate_page
  37. );
  38. }
  39. function nv_del_content_module ( $id )
  40. {
  41. global $db, $module_name, $module_data, $title;
  42. $content_del = "NO_" . $id;
  43. $title = "";
  44. list( $id, $listcatid, $title, $homeimgfile, $homeimgthumb ) = $db->sql_fetchrow( $db->sql_query( "SELECT `id`, `listcatid`, `title`, `homeimgfile`, `homeimgthumb` FROM `" . NV_PREFIXLANG . "_" . $module_data . "_rows` WHERE `id`=" . intval( $id ) . "" ) );
  45. if ( $id > 0 )
  46. {
  47. nv_save_log_content( $id );
  48. if ( $homeimgthumb != "" and $homeimgthumb != "|" )
  49. {
  50. $homeimgthumb_arr = explode( "|", $homeimgthumb );
  51. foreach ( $homeimgthumb_arr as $file )
  52. {
  53. if ( ! empty( $file ) and is_file( NV_ROOTDIR . '/' . NV_FILES_DIR . '/' . $module_name . '/' . $file ) )
  54. {
  55. @nv_deletefile( NV_ROOTDIR . '/' . NV_FILES_DIR . '/' . $module_name . '/' . $file );
  56. }
  57. }
  58. }
  59. $number_no_del = 0;
  60. $array_catid = explode( ",", $listcatid );
  61. foreach ( $array_catid as $catid_i )
  62. {
  63. $catid_i = intval( $catid_i );
  64. if ( $catid_i > 0 )
  65. {
  66. $query = "DELETE FROM `" . NV_PREFIXLANG . "_" . $module_data . "_" . $catid_i . "` WHERE `id`=" . $id . "";
  67. $db->sql_query( $query );
  68. if ( ! $db->sql_affectedrows() )
  69. {
  70. $number_no_del ++;
  71. }
  72. $db->sql_freeresult();
  73. }
  74. }
  75. if ( $number_no_del == 0 )
  76. {
  77. $query = "DELETE FROM `" . NV_PREFIXLANG . "_" . $module_data . "_rows` WHERE `id`=" . $id;
  78. $db->sql_query( $query );
  79. if ( ! $db->sql_affectedrows() )
  80. {
  81. {
  82. $number_no_del ++;
  83. }
  84. $db->sql_freeresult();
  85. }
  86. }
  87. $number_no_del = 0;
  88. if ( $number_no_del == 0 )
  89. {
  90. $db->sql_query( "DELETE FROM `" . NV_PREFIXLANG . "_" . $module_data . "_comments` WHERE `id` = " . $id );
  91. $db->sql_query( "DELETE FROM `" . NV_PREFIXLANG . "_" . $module_data . "_block` WHERE `id` = " . $id );
  92. $content_del = "OK_" . $id;
  93. }
  94. else
  95. {
  96. $content_del = "ERR_" . $lang_module['error_del_content'];
  97. }
  98. }
  99. return $content_del;
  100. }
  101. function nv_archive_content_module ( $id, $listcatid )
  102. {
  103. global $db, $module_data;
  104. $array_catid = explode( ",", $listcatid );
  105. foreach ( $array_catid as $catid_i )
  106. {
  107. $catid_i = intval( $catid_i );
  108. if ( $catid_i > 0 )
  109. {
  110. $db->sql_query( "UPDATE `" . NV_PREFIXLANG . "_" . $module_data . "_" . $catid_i . "` SET `archive`='2' WHERE `id`=" . $id . "" );
  111. }
  112. }
  113. $db->sql_query( "UPDATE `" . NV_PREFIXLANG . "_" . $module_data . "_rows` SET `archive`='2' WHERE `id`=" . $id . "" );
  114. }
  115. function nv_link_edit_page ( $id )
  116. {
  117. global $lang_global, $module_name;
  118. $link = "<span class=\"edit_icon\"><a href=\"" . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=content&amp;id=" . $id . "\">" . $lang_global['edit'] . "</a></span>";
  119. return $link;
  120. }
  121. function nv_link_delete_page ( $id )
  122. {
  123. global $lang_global, $module_name;
  124. $link = "<span class=\"delete_icon\"><a href=\"javascript:void(0);\" onclick=\"nv_del_content(" . $id . ", '" . md5( $id . session_id() ) . "','" . NV_BASE_ADMINURL . "')\">" . $lang_global['delete'] . "</a></span>";
  125. return $link;
  126. }
  127. function nv_news_page ( $base_url, $num_items, $per_page, $start_item, $add_prevnext_text = true )
  128. {
  129. global $lang_global;
  130. $total_pages = ceil( $num_items / $per_page );
  131. if ( $total_pages == 1 ) return '';
  132. @$on_page = floor( $start_item / $per_page ) + 1;
  133. $page_string = "";
  134. if ( $total_pages > 10 )
  135. {
  136. $init_page_max = ( $total_pages > 3 ) ? 3 : $total_pages;
  137. for ( $i = 1; $i <= $init_page_max; $i ++ )
  138. {
  139. $href = "href=\"" . $base_url . "/page-" . ( ( $i - 1 ) * $per_page ) . "\"";
  140. $page_string .= ( $i == $on_page ) ? "<strong>" . $i . "</strong>" : "<a " . $href . ">" . $i . "</a>";
  141. if ( $i < $init_page_max ) $page_string .= ", ";
  142. }
  143. if ( $total_pages > 3 )
  144. {
  145. if ( $on_page > 1 && $on_page < $total_pages )
  146. {
  147. $page_string .= ( $on_page > 5 ) ? " ... " : ", ";
  148. $init_page_min = ( $on_page > 4 ) ? $on_page : 5;
  149. $init_page_max = ( $on_page < $total_pages - 4 ) ? $on_page : $total_pages - 4;
  150. for ( $i = $init_page_min - 1; $i < $init_page_max + 2; $i ++ )
  151. {
  152. $href = "href=\"" . $base_url . "/page-" . ( ( $i - 1 ) * $per_page ) . "\"";
  153. $page_string .= ( $i == $on_page ) ? "<strong>" . $i . "</strong>" : "<a " . $href . ">" . $i . "</a>";
  154. if ( $i < $init_page_max + 1 )
  155. {
  156. $page_string .= ", ";
  157. }
  158. }
  159. $page_string .= ( $on_page < $total_pages - 4 ) ? " ... " : ", ";
  160. }
  161. else
  162. {
  163. $page_string .= " ... ";
  164. }
  165. for ( $i = $total_pages - 2; $i < $total_pages + 1; $i ++ )
  166. {
  167. $href = "href=\"" . $base_url . "/page-" . ( ( $i - 1 ) * $per_page ) . "\"";
  168. $page_string .= ( $i == $on_page ) ? "<strong>" . $i . "</strong>" : "<a " . $href . ">" . $i . "</a>";
  169. if ( $i < $total_pages )
  170. {
  171. $page_string .= ", ";
  172. }
  173. }
  174. }
  175. }
  176. else
  177. {
  178. for ( $i = 1; $i < $total_pages + 1; $i ++ )
  179. {
  180. $href = "href=\"" . $base_url . "/page-" . ( ( $i - 1 ) * $per_page ) . "\"";
  181. $page_string .= ( $i == $on_page ) ? "<strong>" . $i . "</strong>" : "<a " . $href . ">" . $i . "</a>";
  182. if ( $i < $total_pages )
  183. {
  184. $page_string .= ", ";
  185. }
  186. }
  187. }
  188. if ( $add_prevnext_text )
  189. {
  190. if ( $on_page > 1 )
  191. {
  192. $href = "href=\"" . $base_url . "/page-" . ( ( $on_page - 2 ) * $per_page ) . "\"";
  193. $page_string = "&nbsp;&nbsp;<span><a " . $href . ">" . $lang_global['pageprev'] . "</a></span>&nbsp;&nbsp;" . $page_string;
  194. }
  195. if ( $on_page < $total_pages )
  196. {
  197. $href = "href=\"" . $base_url . "/page-" . ( $on_page * $per_page ) . "\"";
  198. $page_string .= "&nbsp;&nbsp;<span><a " . $href . ">" . $lang_global['pagenext'] . "</a></span>";
  199. }
  200. }
  201. return $page_string;
  202. }
  203. function nv_save_log_content ( $id )
  204. {
  205. global $db, $db_config, $admin_info, $lang_global, $module_name, $module_data, $op;
  206. $log_admin = ( isset( $admin_info['admin_id'] ) ) ? intval( $admin_info['admin_id'] ) : 0;
  207. $rowcontent_old = $db->sql_fetchrow( $db->sql_query( "SELECT * FROM `" . NV_PREFIXLANG . "_" . $module_data . "_rows` where `id`=" . $id . "" ) );
  208. $query = "INSERT INTO `" . NV_PREFIXLANG . "_" . $module_data . "_log` (`log_id`, `log_admin`, `hometext`, `bodytext`, `keywords`) VALUES (NULL, '" . $log_admin . "','','','')";
  209. $log_id = $db->sql_query_insert_id( $query );
  210. if ( $log_id > 0 )
  211. {
  212. $query_log = "UPDATE `" . NV_PREFIXLANG . "_" . $module_data . "_log` SET `log_time`=" . $db->dbescape( NV_CURRENTTIME ) . " ";
  213. foreach ( $rowcontent_old as $key_log => $value_log )
  214. {
  215. if ( ! is_numeric( $key_log ) )
  216. {
  217. $query_log .= ", `" . $key_log . "`=" . $db->dbescape( $value_log ) . "";
  218. }
  219. }
  220. $query_log .= " WHERE `log_id` =" . $log_id . "";
  221. $db->sql_query( $query_log );
  222. }
  223. }
  224. ?>