PageRenderTime 52ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/Quản lý website trường trung học phổ thông PHP/lc1/admin/modules/webtools/keywordRank.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 161 lines | 129 code | 24 blank | 8 comment | 17 complexity | 4de74f7d300d15784f08d678ace75377 MD5 | raw file
  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 25/12/2010, 1:5
  7. */
  8. if ( ! defined( 'NV_IS_FILE_WEBTOOLS' ) ) die( 'Stop!!!' );
  9. $page_title = $lang_module['keywordRank'];
  10. $contents = "";
  11. $xtpl = new XTemplate( "keywordRank.tpl", NV_ROOTDIR . "/themes/" . $global_config['module_theme'] . "/modules/" . $module_file );
  12. $xtpl->assign( 'NV_NAME_VARIABLE', NV_NAME_VARIABLE );
  13. $xtpl->assign( 'NV_OP_VARIABLE', NV_OP_VARIABLE );
  14. $xtpl->assign( 'NV_BASE_SITEURL', NV_BASE_SITEURL );
  15. $xtpl->assign( 'LANG', $lang_module );
  16. $xtpl->assign( 'TITLE', sprintf( $lang_module['keywordFormTitle'], NV_SERVER_NAME ) );
  17. if ( $nv_Request->isset_request( 'i', 'get' ) )
  18. {
  19. $i = $nv_Request->get_string( 'i', 'get' );
  20. if ( $i == 'process' )
  21. {
  22. $keyword = filter_text_input( 'k', 'get', '', 0, 60 );
  23. $keyword = nv_unhtmlspecialchars( $keyword );
  24. $keyword = strip_punctuation( $keyword );
  25. $keyword = trim( $keyword );
  26. $len_key = nv_strlen( $keyword );
  27. //$keyword = nv_htmlspecialchars( $keyword );
  28. $lang = filter_text_input( 'l', 'get', '' );
  29. $accuracy = filter_text_input( 'a', 'get', '' );
  30. if ( $len_key < 3 or $len_key > 60 )
  31. {
  32. $xtpl->assign( 'ERROR', $lang_module['keywordInfo'] );
  33. $xtpl->parse( 'process.error' );
  34. }
  35. else
  36. {
  37. $myDomain = NV_SERVER_NAME;
  38. //$myDomain = "nukeviet.vn";
  39. $from = "google";
  40. $tempFile = md5( $keyword . $lang . $accuracy . $from . $myDomain );
  41. $tempFile = NV_ROOTDIR . '/' . NV_TEMP_DIR . '/' . NV_TEMPNAM_PREFIX . $tempFile;
  42. if ( file_exists( $tempFile ) and @filemtime( $tempFile ) > ( NV_CURRENTTIME - 600 ) )
  43. {
  44. $info = file_get_contents( $tempFile );
  45. $info = unserialize( $info );
  46. }
  47. else
  48. {
  49. if ( ! isset( $keywordRank ) or ! is_object( $keywordRank ) )
  50. {
  51. if ( ! class_exists( 'keywordRank' ) )
  52. {
  53. include ( NV_ROOTDIR . "/includes/class/keywordRank.class.php" );
  54. }
  55. $keywordRank = new keywordRank();
  56. }
  57. $info = $keywordRank->process( $keyword, $lang, $accuracy, $from, $myDomain );
  58. $put_contents = serialize( $info );
  59. @file_put_contents( $tempFile, $put_contents );
  60. }
  61. if ( ! empty( $info ) )
  62. {
  63. $loop = array();
  64. $loop[] = array( 'key' => $lang_module['currentDomain'], 'value' => $info['myDomain'] );
  65. $loop[] = array( 'key' => $lang_module['keyword'], 'value' => $info['keyword'] );
  66. $loop[] = array( 'key' => $lang_module['language'], 'value' => ! empty( $info['lang'] ) ? strtoupper( $info['lang'] ) : $lang_module['langAll'] );
  67. $loop[] = array( 'key' => $lang_module['accuracy'], 'value' => $info['accuracy'] == "keyword" ? $lang_module['byKeyword'] : $lang_module['byPhrase'] );
  68. $loop[] = array( 'key' => $lang_module['fromEngine'], 'value' => strtoupper( $info['fromEngine'] ) );
  69. $loop[] = array( 'key' => $lang_module['updDate'], 'value' => nv_date( "d-m-Y H:i", $info['updtime'] ) );
  70. foreach ( $loop as $a => $l )
  71. {
  72. $xtpl->assign( 'CLASS', ( $a % 2 ) ? " class=\"second\"" : "" );
  73. $xtpl->assign( 'LOOP', $l );
  74. $xtpl->parse( 'process.result.loop' );
  75. }
  76. $xtpl->parse( 'process.result' );
  77. if ( ! empty( $info['detail'] ) )
  78. {
  79. $mainResult = array();
  80. if ( isset( $info['detail']['myPages'] ) ) $mainResult[] = array( 'key' => $lang_module['allPages'], 'value' => number_format( $info['detail']['allPages'] ) );
  81. if ( isset( $info['detail']['myPages'] ) ) $mainResult[] = array( 'key' => $lang_module['myPages'], 'value' => number_format( $info['detail']['myPages'] ) );
  82. if ( isset( $info['detail']['rank'] ) ) $mainResult[] = array( 'key' => $lang_module['rankResult'], 'value' => ( empty( $info['detail']['rank'] ) ? $lang_module['rank0'] : implode( " - ", $info['detail']['rank'] ) ) );
  83. if ( ! empty( $mainResult ) )
  84. {
  85. foreach ( $mainResult as $a => $r )
  86. {
  87. $xtpl->assign( 'CLASS', ( $a % 2 ) ? " class=\"second\"" : "" );
  88. $xtpl->assign( 'TR', $r );
  89. $xtpl->parse( 'process.MainResult.tr' );
  90. }
  91. $xtpl->parse( 'process.MainResult' );
  92. }
  93. }
  94. if ( ! empty( $info['detail']['top10MyPages'] ) )
  95. {
  96. $xtpl->assign( 'CAPTION', $lang_module['Top10'] );
  97. foreach ( $info['detail']['top10MyPages'] as $key => $link )
  98. {
  99. $xtpl->assign( 'CLASS', ( $key % 2 ) ? " class=\"second\"" : "" );
  100. $xtpl->assign( 'ID', $key + 1 );
  101. $xtpl->assign( 'URL', $link );
  102. $xtpl->parse( 'process.TopPages.top' );
  103. }
  104. $xtpl->parse( 'process.TopPages' );
  105. }
  106. if ( ! empty( $info['detail']['top50AllPages'] ) )
  107. {
  108. $xtpl->assign( 'CAPTION', $lang_module['Top50'] );
  109. foreach ( $info['detail']['top50AllPages'] as $key => $link )
  110. {
  111. $a_class = isset( $info['detail']['rank'][$key] ) ? " class=\"myLink\"" : "";
  112. $xtpl->assign( 'CLASS', ( $key % 2 ) ? " class=\"second\"" : "" );
  113. $xtpl->assign( 'ID', $key + 1 );
  114. $xtpl->assign( 'A_CLASS', $a_class );
  115. $xtpl->assign( 'URL', $link );
  116. $xtpl->parse( 'process.TopPages.top' );
  117. }
  118. $xtpl->parse( 'process.TopPages' );
  119. }
  120. }
  121. else
  122. {
  123. $xtpl->assign( 'ERROR', $lang_module['isLocalhost'] );
  124. $xtpl->parse( 'process.error' );
  125. }
  126. }
  127. $xtpl->parse( 'process' );
  128. echo $xtpl->text( 'process' );
  129. }
  130. die();
  131. }
  132. $xtpl->parse( 'main' );
  133. $contents = $xtpl->text( 'main' );
  134. include ( NV_ROOTDIR . "/includes/header.php" );
  135. echo nv_admin_theme( $contents );
  136. include ( NV_ROOTDIR . "/includes/footer.php" );
  137. ?>