vitnet

top.php

Nov 14th, 2015
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.03 KB | None | 0 0
  1. <?php
  2.  
  3. if( !defined( 'DATALIFEENGINE' ) ) {
  4.     die( "Hacking attempt!" );
  5. }
  6.  
  7. if( $_GET['mode'] != 'views' and $_GET['mode'] != 'comments' and $_GET['mode'] != 'rating' ) {
  8.     msgbox( $lang['all_err_1'], $lang['news_err_27'] );
  9. }
  10.  
  11. include ENGINE_DIR . '/data/top100.config.php';
  12. include ENGINE_DIR . '/api/api.class.php';
  13.  
  14. $top100_config['news_num'] = 10;
  15. $top100_config['category'] = '1,2,3,4,5,6,7';
  16.  
  17. /*
  18. $top100_config['title_num'] = 'a';
  19. $top100_config['title_post'] = 'b';
  20. $top100_config['title_name'] = 'c';
  21. $top100_config['title_views_head'] = 'd';
  22.  
  23. $top100_config['title_views'] = 'e';
  24. $top100_config['title_comments'] = 'f';
  25. $top100_config['title_rating'] = 'g';
  26. */
  27.  
  28. if( $top100_config['category'] != 0 ) {
  29.     $category_true = "AND category IN (" . $top100_config['category'] . ")";
  30. } else {
  31.     $category_true = "";
  32. }
  33.  
  34. if( $_GET['mode'] == 'views' ) {
  35.     $cache = $dle_api->load_from_cache( "top100views", 3600, $tpl->result['content'] );
  36.    
  37.     if( $cache === false ) {
  38.         $sql_result = $db->query( "SELECT p.id, p.title, p.category, p.alt_name, p.xfields, e.news_read FROM " . PREFIX . "_post as p LEFT JOIN " . PREFIX . "_post_extras e ON (p.id=e.news_id) WHERE approve=1 " . $category_true . " ORDER BY e.news_read DESC LIMIT " . $top100_config['news_num'] );
  39.  
  40.         $top100 = <<<HTML
  41.     <thead>
  42.         <tr>
  43.             <td align="center">{$top100_config['title_num']}</td>
  44.             <td align="center">{$top100_config['title_post']}</td>
  45.             <td align="center">{$top100_config['title_name']}</td>
  46.             <td align="center">{$top100_config['title_views_head']}</td>
  47.         </tr>
  48.     </thead>
  49. HTML;
  50.  
  51. $top100 .= <<<HTML
  52. <tbody>
  53. HTML;
  54.  
  55.         $i=1;
  56.         while ( $row = $db->get_row($sql_result) ) {
  57.             $row['category'] = intval( $row['category'] ); 
  58.            
  59.             if( $config['allow_alt_url'] ) {
  60.                 if( $config['seo_type'] == 1 OR $config['seo_type'] == 2 ) {
  61.                     if( $row['category'] and $config['seo_type'] == 2 ) {
  62.                         $full_link = $config['http_home_url'] . get_url( $row['category'] ) . "/" . $row['id'] . "-" . $row['alt_name'] . ".html";
  63.                     } else {
  64.                         $full_link = $config['http_home_url'] . $row['id'] . "-" . $row['alt_name'] . ".html";
  65.                     }
  66.                 } else {
  67.                     $full_link = $config['http_home_url'] . date( 'Y/m/d/', $row['date'] ) . $row['alt_name'] . ".html";
  68.                 }
  69.             } else {
  70.                 $full_link = $config['http_home_url'] . "index.php?newsid=" . $row['id'];
  71.             }
  72.  
  73.             $xfields = xfieldsdataload( $row['xfields'] ); 
  74.  
  75.             $Link = isset($xfields['image']) ? $xfields['image'] : "null";
  76.  
  77.             $row['title'] = strip_tags( stripslashes( $row['title'] ) );
  78.             $row['news_read'] = intval( $row['news_read'] );
  79.            
  80.             $top100 .='';    
  81.  
  82.             if( $row['news_read'] != 0 ) {
  83.                 $top100 .= <<<HTML
  84.     <tr>
  85.         <td align="center">&nbsp;&nbsp;{$i}&nbsp;&nbsp;</td>
  86.         <td>Вывод дополнительного поля {$Link}</td>
  87.         <td><a href="{$full_link}" title="{$row['title']}">{$row['title']}</td>
  88.         <td align="center">{$row['news_read']}</td>
  89.     </tr>
  90. HTML;
  91.  
  92.                 $i++;
  93.             }
  94.         }
  95.         $db->free();
  96.  
  97.         $top100 .= <<<HTML
  98. </tbody>
  99. HTML;
  100.  
  101.         $tpl->load_template( 'top100.tpl' );
  102.         $tpl->set( '{title}', $top100_config['title_views'] );
  103.         $tpl->set( '{title1}', $top100_config['title_comments'] );
  104.         $tpl->set( '{title2}', $top100_config['title_rating'] );
  105.         $tpl->set( '{top100}', $top100 );
  106.        
  107.         $tpl->compile( 'content' );
  108.         $tpl->clear();
  109.        
  110.         $dle_api->save_to_cache( "top100views", $tpl->result['content'] );
  111.     } else {
  112.         var_dump($cache);
  113.     }
  114. }
  115.  
  116. if( $_GET['mode'] == 'comments' ) {
  117.     $cache = $dle_api->load_from_cache( "top100comments", 3600, $tpl->result['content'] );
  118.     if( $cache === false ) {
  119.         $sql_result = $db->query( "SELECT id, title, category, alt_name, comm_num FROM " . PREFIX . "_post WHERE approve=1 " . $category_true . " ORDER BY comm_num DESC LIMIT " . $top100_config['news_num'] );
  120.  
  121.         $top100 = <<<HTML
  122.     <thead>
  123.         <tr>
  124.             <td align="center">{$top100_config['title_num']}</td>
  125.             <td align="center">{$top100_config['title_post']}</td>
  126.             <td align="center">{$top100_config['title_name']}</td>
  127.             <td align="center">{$top100_config['title_comments_head']}</td>
  128.         </tr>
  129.     </thead>
  130. HTML;
  131.  
  132.         $top100 .= <<<HTML
  133.     <tbody>
  134. HTML;
  135.  
  136.         $i=1;
  137.         while ( $row = $db->get_row($sql_result) ) {
  138.             $row['category'] = intval( $row['category'] );
  139.  
  140.             if( $config['allow_alt_url'] ) {
  141.                 if( $config['seo_type'] == 1 OR $config['seo_type'] == 2 ) {
  142.                     if( $row['category'] and $config['seo_type'] == 2 ) {
  143.                         $full_link = $config['http_home_url'] . get_url( $row['category'] ) . "/" . $row['id'] . "-" . $row['alt_name'] . ".html";
  144.                     } else {
  145.                         $full_link = $config['http_home_url'] . $row['id'] . "-" . $row['alt_name'] . ".html";
  146.                     }
  147.                 } else {
  148.                     $full_link = $config['http_home_url'] . date( 'Y/m/d/', $row['date'] ) . $row['alt_name'] . ".html";
  149.                 }
  150.             } else {
  151.                 $full_link = $config['http_home_url'] . "index.php?newsid=" . $row['id'];
  152.             }
  153.  
  154.             $row['title'] = strip_tags( stripslashes( $row['title'] ) );
  155.             $row['comm_num'] = intval( $row['comm_num'] );
  156.  
  157.             if( $row['comm_num'] != 0 ) {
  158.                 $top100 .= <<<HTML
  159.     <tr>
  160.         <td align="center">&nbsp;&nbsp;{$i}&nbsp;&nbsp;</td>
  161.         <td><a href="{$full_link}" title="{$row['title']}"><strong>{$row['title']}</strong></a></td>
  162.         <td align="center">{$row['comm_num']}</td>
  163.     </tr>
  164. HTML;
  165.  
  166.                 $i++;
  167.             }
  168.         }
  169.         $db->free();
  170.        
  171.         $top100 .= <<<HTML
  172.     </tbody>
  173. HTML;
  174.  
  175.         $tpl->load_template( 'top100.tpl' );
  176.         $tpl->set( '{title}', $top100_config['title_views'] );
  177.         $tpl->set( '{title1}', $top100_config['title_comments'] );
  178.         $tpl->set( '{title2}', $top100_config['title_rating'] );
  179.         $tpl->set( '{top100}', $top100 );
  180.        
  181.         $tpl->compile( 'content' );
  182.         $tpl->clear();
  183.        
  184.         $dle_api->save_to_cache ( "top100comments", $tpl->result['content'] );
  185.     } else {
  186.         var_dump($cache);
  187.     }
  188. }
  189.  
  190. if( $_GET['mode'] == 'rating' ) {
  191.     $cache = $dle_api->load_from_cache ( "top100rating", 3600, $tpl->result['content'] );
  192.     if( $cache === false ) {
  193.         $sql_result = $db->query( "SELECT p.id, p.title, p.category, p.alt_name, e.allow_rate, e.rating, '1' as flag FROM " . PREFIX . "_post as p LEFT JOIN " . PREFIX . "_post_extras e ON (p.id=e.news_id) WHERE approve=1 " . $category_true . " ORDER BY e.rating DESC LIMIT " . $top100_config['news_num'] );
  194.  
  195.         $top100 = <<<HTML
  196.     <thead>
  197.         <tr>
  198.             <td align="center">$top100_config[title_num]</td>
  199.             <td align="center">$top100_config[title_name]</td>
  200.             <td align="center">$top100_config[title_rating_head]</td>
  201.         </tr>
  202.     </thead>
  203. HTML;
  204.  
  205.         $top100 .= <<<HTML
  206. <tbody>
  207. HTML;
  208.  
  209.         $i=1;
  210.         while ( $row = $db->get_row($sql_result) ) {
  211.             $row['category'] = intval( $row['category'] );
  212.  
  213.             if( $config['allow_alt_url'] ) {
  214.                 if( $config['seo_type'] == 1 OR $config['seo_type'] == 2 ) {
  215.                     if( $row['category'] and $config['seo_type'] == 2 ) {
  216.                         $full_link = $config['http_home_url'] . get_url( $row['category'] ) . "/" . $row['id'] . "-" . $row['alt_name'] . ".html";
  217.                     } else {
  218.                         $full_link = $config['http_home_url'] . $row['id'] . "-" . $row['alt_name'] . ".html";
  219.                     }
  220.                 } else {
  221.                     $full_link = $config['http_home_url'] . date( 'Y/m/d/', $row['date'] ) . $row['alt_name'] . ".html";
  222.                 }
  223.             } else {
  224.                 $full_link = $config['http_home_url'] . "index.php?newsid=" . $row['id'];
  225.             }
  226.  
  227.             $row['title'] = strip_tags( stripslashes( $row['title'] ) );
  228.             $row['rating'] = intval( $row['rating'] );
  229.  
  230.             if( $row['rating'] != 0 ) {
  231.                 $top100 .= <<<HTML
  232.     <tr>
  233.         <td align="center">&nbsp;&nbsp;$i&nbsp;&nbsp;</td>
  234.         <td><a href="$full_link" title=""><strong>$row[title]</strong></a></td>
  235.         <td align="center">$row[rating]</td>
  236.     </tr>
  237. HTML;
  238.  
  239.                 $i++;
  240.             }
  241.         }
  242.         $db->free();
  243.  
  244.         $top100 .= <<<HTML
  245. </tbody>
  246. HTML;
  247.  
  248.         $tpl->load_template( 'top100.tpl' );
  249.         $tpl->set( '{title}', $top100_config['title_views'] );
  250.         $tpl->set( '{title1}', $top100_config['title_comments'] );
  251.         $tpl->set( '{title2}', $top100_config['title_rating'] );
  252.         $tpl->set( '{top100}', $top100 );
  253.  
  254.         $tpl->compile( 'content' );
  255.         $tpl->clear();
  256.        
  257.         $dle_api->save_to_cache( "top100rating", $tpl->result['content'] );
  258.     } else {
  259.         var_dump($cache);
  260.     }
  261. }
  262.  
  263. ?>
Advertisement
Add Comment
Please, Sign In to add comment