PageRenderTime 39ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/nukeviet/modules/news/funcs/detail.php

http://nuke-viet.googlecode.com/
PHP | 253 lines | 223 code | 23 blank | 7 comment | 41 complexity | 5e140f80d7b6a8ccfb652a32e8e9b02c MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, GPL-2.0
  1. <?php
  2. /**
  3. * @Project NUKEVIET 3.x
  4. * @Author VINADES.,JSC (contact@vinades.vn)
  5. * @Copyright (C) 2012 VINADES.,JSC. All rights reserved
  6. * @Createdate 3-6-2010 0:14
  7. */
  8. if( ! defined( 'NV_IS_MOD_NEWS' ) ) die( 'Stop!!!' );
  9. $contents = "";
  10. $publtime = 0;
  11. $func_who_view = $global_array_cat[$catid]['who_view'];
  12. $allowed = false;
  13. if( $func_who_view == 0 )
  14. {
  15. $allowed = true;
  16. }
  17. if( $func_who_view == 1 and defined( 'NV_IS_USER' ) )
  18. {
  19. $allowed = true;
  20. }
  21. elseif( $func_who_view == 2 and defined( 'NV_IS_MODADMIN' ) )
  22. {
  23. $allowed = true;
  24. }
  25. elseif( $func_who_view == 3 and defined( 'NV_IS_USER' ) and nv_is_in_groups( $user_info['in_groups'], $global_array_cat[$catid]['groups_view'] ) )
  26. {
  27. $allowed = true;
  28. }
  29. if( $allowed )
  30. {
  31. $query = $db->sql_query( "SELECT * FROM `" . NV_PREFIXLANG . "_" . $module_data . "_" . $catid . "` WHERE `id` = " . $id . "" );
  32. $news_contents = $db->sql_fetch_assoc( $query );
  33. if( $news_contents['id'] > 0 )
  34. {
  35. $body_contents = $db->sql_fetch_assoc( $db->sql_query( "SELECT bodyhtml as bodytext, sourcetext, imgposition, copyright, allowed_send, allowed_print, allowed_save FROM `" . NV_PREFIXLANG . "_" . $module_data . "_bodyhtml_" . ceil( $news_contents['id'] / 2000 ) . "` where `id`=" . $news_contents['id'] ) );
  36. $news_contents = array_merge( $news_contents, $body_contents );
  37. unset( $body_contents );
  38. if( defined( 'NV_IS_MODADMIN' ) or ( $news_contents['status'] == 1 and $news_contents['publtime'] < NV_CURRENTTIME and ( $news_contents['exptime'] == 0 or $news_contents['exptime'] > NV_CURRENTTIME ) ) )
  39. {
  40. $time_set = $nv_Request->get_int( $module_name . '_' . $op . '_' . $id, 'session' );
  41. if( empty( $time_set ) )
  42. {
  43. $nv_Request->set_Session( $module_data . '_' . $op . '_' . $id, NV_CURRENTTIME );
  44. $query = "UPDATE `" . NV_PREFIXLANG . "_" . $module_data . "_rows` SET hitstotal=hitstotal+1 WHERE `id`=" . $id;
  45. $db->sql_query( $query );
  46. $array_catid = explode( ",", $news_contents['listcatid'] );
  47. foreach( $array_catid as $catid_i )
  48. {
  49. $query = "UPDATE `" . NV_PREFIXLANG . "_" . $module_data . "_" . $catid_i . "` SET hitstotal=hitstotal+1 WHERE `id`=" . $id;
  50. $db->sql_query( $query );
  51. }
  52. }
  53. $news_contents['showhometext'] = $module_config[$module_name]['showhometext'];
  54. $news_contents['homeimgalt'] = ( empty( $news_contents['homeimgalt'] ) ) ? $news_contents['title'] : $news_contents['homeimgalt'];
  55. if( ! empty( $news_contents['homeimgfile'] ) and $news_contents['imgposition'] > 0 )
  56. {
  57. $src = $alt = $note = "";
  58. $width = $height = 0;
  59. $array_img = explode( "|", $news_contents['homeimgthumb'] );
  60. if( ! empty( $array_img[0] ) and $news_contents['imgposition'] == 1 and file_exists( NV_ROOTDIR . '/' . NV_FILES_DIR . '/' . $module_name . '/' . $array_img[0] ) )
  61. {
  62. $src = NV_BASE_SITEURL . NV_FILES_DIR . '/' . $module_name . '/' . $array_img[0];
  63. $width = $module_config[$module_name]['homewidth'];
  64. }
  65. elseif( nv_is_url( $news_contents['homeimgfile'] ) )
  66. {
  67. $src = $news_contents['homeimgfile'];
  68. $width = ( $news_contents['imgposition'] == 1 ) ? $module_config[$module_name]['homewidth'] : $module_config[$module_name]['imagefull'];
  69. }
  70. elseif( file_exists( NV_UPLOADS_REAL_DIR . '/' . $module_name . '/' . $news_contents['homeimgfile'] ) )
  71. {
  72. $src = NV_BASE_SITEURL . NV_UPLOADS_DIR . '/' . $module_name . '/' . $news_contents['homeimgfile'];
  73. if( $news_contents['imgposition'] == 1 )
  74. {
  75. $width = $module_config[$module_name]['homewidth'];
  76. }
  77. else
  78. {
  79. $imagesize = @getimagesize( NV_UPLOADS_REAL_DIR . '/' . $module_name . '/' . $news_contents['homeimgfile'] );
  80. if( $imagesize[0] > 0 and $imagesize[0] > $module_config[$module_name]['imagefull'] )
  81. {
  82. $width = $module_config[$module_name]['imagefull'];
  83. }
  84. else
  85. {
  86. $width = $imagesize[0];
  87. }
  88. }
  89. }
  90. if( file_exists( NV_UPLOADS_REAL_DIR . '/' . $module_name . '/' . $news_contents['homeimgfile'] ) )
  91. {
  92. $news_contents['homeimgfile'] = NV_BASE_SITEURL . NV_UPLOADS_DIR . '/' . $module_name . '/' . $news_contents['homeimgfile'];
  93. }
  94. $news_contents['image'] = array(
  95. "src" => $src,
  96. "width" => $width,
  97. "alt" => $news_contents['homeimgalt'],
  98. "note" => $news_contents['homeimgalt'],
  99. "position" => $news_contents['imgposition'] );
  100. }
  101. if( $alias_url == $db->unfixdb( $news_contents['alias'] ) )
  102. {
  103. $publtime = intval( $news_contents['publtime'] );
  104. }
  105. }
  106. }
  107. if( $publtime == 0 )
  108. {
  109. $redirect = "<meta http-equiv=\"Refresh\" content=\"3;URL=" . nv_url_rewrite( NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name, true ) . "\" />";
  110. nv_info_die( $lang_global['error_404_title'], $lang_global['error_404_title'], $lang_global['error_404_content'] . $redirect );
  111. }
  112. if( $catid != $news_contents['catid'] )
  113. {
  114. $canonicalUrl = $global_config['site_url'] . "/index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=" . $global_array_cat[$news_contents['catid']]['alias'] . "/" . $news_contents['alias'] . "-" . $news_contents['id'];
  115. }
  116. $news_contents['url_sendmail'] = NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=sendmail/" . $global_array_cat[$catid]['alias'] . "/" . $news_contents['alias'] . "-" . $news_contents['id'];
  117. $news_contents['url_print'] = NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=print/" . $global_array_cat[$catid]['alias'] . "/" . $news_contents['alias'] . "-" . $news_contents['id'];
  118. $news_contents['url_savefile'] = NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=savefile/" . $global_array_cat[$catid]['alias'] . "/" . $news_contents['alias'] . "-" . $news_contents['id'];
  119. $sql = "SELECT `title`, `link`, `logo` FROM `" . NV_PREFIXLANG . "_" . $module_data . "_sources` WHERE `sourceid` = '" . $news_contents['sourceid'] . "'";
  120. $result = $db->sql_query( $sql );
  121. list( $sourcetext, $source_link, $source_logo ) = $db->sql_fetchrow( $result );
  122. unset( $sql, $result );
  123. $news_contents['newscheckss'] = md5( $news_contents['id'] . session_id() . $global_config['sitekey'] );
  124. if( $module_config[$module_name]['config_source'] == 0 ) $news_contents['source'] = $sourcetext;
  125. elseif( $module_config[$module_name]['config_source'] == 1 ) $news_contents['source'] = $source_link;
  126. elseif( $module_config[$module_name]['config_source'] == 2 && !empty( $source_logo ) ) $news_contents['source'] = "<img width=\"100px\" src=\"" . NV_BASE_SITEURL . NV_UPLOADS_DIR . "/" . $module_name . "/source/" . $source_logo . "\">";
  127. $news_contents['publtime'] = nv_date( "l - d/m/Y H:i", $news_contents['publtime'] );
  128. $related_new_array = array();
  129. $related_new = $db->sql_query( "SELECT `id`, `title`, `alias`,`publtime` FROM `" . NV_PREFIXLANG . "_" . $module_data . "_" . $catid . "` WHERE `status`=1 AND `publtime` > " . $publtime . " AND `publtime` < " . NV_CURRENTTIME . " ORDER BY `id` ASC LIMIT 0, " . $st_links . "" );
  130. while( $row = $db->sql_fetch_assoc( $related_new ) )
  131. {
  132. $link = NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=" . $global_array_cat[$catid]['alias'] . "/" . $row['alias'] . "-" . $row['id'];
  133. $related_new_array[] = array(
  134. "title" => $row['title'],
  135. "time" => nv_date( "d/m/Y", $row['publtime'] ),
  136. "link" => $link );
  137. }
  138. sort( $related_new_array, SORT_NUMERIC );
  139. $db->sql_freeresult( $related_new );
  140. unset( $related_new, $row );
  141. $related_array = array();
  142. $related = $db->sql_query( "SELECT `id`, `title`, `alias`,`publtime` FROM `" . NV_PREFIXLANG . "_" . $module_data . "_" . $catid . "` WHERE `status`=1 AND `publtime` < " . $publtime . " AND `publtime` < " . NV_CURRENTTIME . " ORDER BY `id` DESC LIMIT 0, " . $st_links . "" );
  143. while( $row = $db->sql_fetch_assoc( $related ) )
  144. {
  145. $link = NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=" . $global_array_cat[$catid]['alias'] . "/" . $row['alias'] . "-" . $row['id'];
  146. $related_array[] = array(
  147. "title" => $row['title'],
  148. "time" => nv_date( "d/m/Y", $row['publtime'] ),
  149. "link" => $link );
  150. }
  151. $db->sql_freeresult( $related );
  152. unset( $related, $row );
  153. $topic_array = array();
  154. $topic_a = "";
  155. if( $news_contents['topicid'] > 0 )
  156. {
  157. list( $topic_title, $topic_alias ) = $db->sql_fetchrow( $db->sql_query( "SELECT `title`,`alias` FROM `" . NV_PREFIXLANG . "_" . $module_data . "_topics` WHERE `topicid` = '" . $news_contents['topicid'] . "'" ) );
  158. $topic = $db->sql_query( "SELECT `id`, `catid`, `title`, `alias`,`publtime` FROM `" . NV_PREFIXLANG . "_" . $module_data . "_rows` WHERE `status`=1 AND `topicid` = '" . $news_contents['topicid'] . "' AND `id` != " . $id . " ORDER BY `id` DESC LIMIT 0, " . $st_links . "" );
  159. while( $row = $db->sql_fetch_assoc( $topic ) )
  160. {
  161. $topiclink = "" . NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=topic/" . $topic_alias;
  162. $link = NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=" . $global_array_cat[$row['catid']]['alias'] . "/" . $row['alias'] . "-" . $row['id'];
  163. $topic_array[] = array(
  164. "title" => $row['title'],
  165. "link" => $link,
  166. "time" => nv_date( "d/m/Y", $row['publtime'] ),
  167. "topiclink" => $topiclink,
  168. "topictitle" => $topic_title
  169. );
  170. }
  171. $db->sql_freeresult( $topic );
  172. unset( $topic, $rows );
  173. }
  174. //Check: comment
  175. $commentenable = 0;
  176. if( $news_contents['allowed_comm'] and $module_config[$module_name]['activecomm'] )
  177. {
  178. $comment_array = nv_comment_module( $news_contents['id'], 0 );
  179. $news_contents['comment'] = comment_theme( $comment_array );
  180. if( $news_contents['allowed_comm'] == 1 or ( $news_contents['allowed_comm'] == 2 and defined( 'NV_IS_USER' ) ) )
  181. {
  182. $commentenable = 1;
  183. }
  184. elseif( $news_contents['allowed_comm'] == 2 )
  185. {
  186. $commentenable = 2;
  187. }
  188. }
  189. else
  190. {
  191. $news_contents['comment'] = "";
  192. }
  193. if( $news_contents['allowed_rating'] )
  194. {
  195. $time_set_rating = $nv_Request->get_int( $module_name . '_' . $op . '_' . $news_contents['id'], 'cookie', 0 );
  196. if( $time_set_rating > 0 )
  197. {
  198. $news_contents['disablerating'] = 1;
  199. }
  200. else
  201. {
  202. $news_contents['disablerating'] = 0;
  203. }
  204. $news_contents['stringrating'] = sprintf( $lang_module['stringrating'], $news_contents['total_rating'], $news_contents['click_rating'] );
  205. $news_contents['click_rating'] = ( $news_contents['click_rating'] > 0 ) ? $news_contents['click_rating'] : 1;
  206. $news_contents['numberrating'] = round( $news_contents['total_rating'] / $news_contents['click_rating'] ) - 1;
  207. $news_contents['langstar'] = array(
  208. "note" => $lang_module['star_note'],
  209. "verypoor" => $lang_module['star_verypoor'],
  210. "poor" => $lang_module['star_poor'],
  211. "ok" => $lang_module['star_ok'],
  212. "good" => $lang_module['star_good}'],
  213. "verygood" => $lang_module['star_verygood']
  214. );
  215. }
  216. $page_title = $news_contents['title'];
  217. $key_words = $news_contents['keywords'];
  218. $description = $news_contents['hometext'];
  219. list( $post_username, $post_full_name ) = $db->sql_fetchrow( $db->sql_query( "SELECT `username`, `full_name` FROM `" . NV_USERS_GLOBALTABLE . "` WHERE `userid` = '" . $news_contents['admin_id'] . "' LIMIT 0,1 " ) );
  220. $news_contents['post_name'] = empty( $post_full_name ) ? $post_username : $post_full_name;
  221. $contents = detail_theme( $news_contents, $related_new_array, $related_array, $topic_array, $commentenable );
  222. }
  223. else
  224. {
  225. $contents = no_permission( $func_who_view );
  226. }
  227. include ( NV_ROOTDIR . "/includes/header.php" );
  228. echo nv_site_theme( $contents );
  229. include ( NV_ROOTDIR . "/includes/footer.php" );
  230. ?>