Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 17th, 2012  |  syntax: None  |  size: 4.88 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. # news
  3.        
  4.         if (!defined('KODEVS') || KODEVS != 1)
  5.                 die();
  6.  
  7.         define('NEWS_REGULAR', 0);
  8.         define('NEWS_ARCHIVE', 1);
  9.                
  10.         class Page extends BasePage
  11.         {
  12.                 function doStartup()
  13.                 {
  14.                         $this->setTitle(isset($_GET['act']) ? 'PAGE_NEWS_TITLE' : 'PAGE_INDEX_TITLE');
  15.                         if (!isset($_GET['act']))
  16.                                 $this->disableCache(); 
  17.                 }
  18.  
  19.                 function doRun()
  20.                 {
  21.                         switch (@$_GET['act'])
  22.                         {
  23.                                 case 'entry':
  24.                                 {
  25.                                         $this->doShowEntry();
  26.                                 } break;
  27.                                        
  28.                                 default:
  29.                                 {
  30.                                         Template::SetPage('main');
  31.  
  32.                                         $this->doShowNews();
  33.                                         $this->doShowUserRankings();
  34.                                         $this->doShowClanRankings();
  35.                                         $this->doShowKings();
  36.                                        
  37.                                         $this->loadTPL('main_content');
  38.                                 }
  39.                         }
  40.                 }
  41.  
  42.                 function doShowKings()
  43.                 {
  44.                         $db = $this->getGDB();
  45.  
  46.                         $this->setKingName(NULL, 1);
  47.                         $this->setKingName(NULL, 2);
  48.  
  49.                         $db->doQuery('SELECT byNation, strKingName FROM KING_SYSTEM');
  50.                         if ($db->hasError() || !$db->hasRows())
  51.                                 return;
  52.  
  53.                         while ($row = $db->doRead())
  54.                         {
  55.                                 $name = trim($row['strKingName']);
  56.                                 $this->setKingName($name, $row['byNation']);
  57.                         }
  58.                 }
  59.  
  60.                 function setKingName($name, $nation)
  61.                 {
  62.                         Template::SetVar($nation == 1 ? 'KARUS_KING' : 'ELMORAD_KING', $name == NULL ? 'N/A' : '<a href="./?page=char&id=' . $name . '" class="largeFont">' . $name . '</a>');
  63.                 }
  64.  
  65.                 function doShowNews()
  66.                 {
  67.                         $db = $this->getADB();
  68.                         for ($n = 0; $n < 6; $n++)
  69.                                 Template::SetVar('SHORT-NEWS-' . $n, Template::Load('news-bit-empty'));
  70.  
  71.                         $db->doQuery('SELECT TOP 6 id, date,n_title FROM NEWS ORDER BY id DESC');
  72.                         if ($db->hasError() || !$db->hasRows())
  73.                                 return;
  74.  
  75.                         $i = 0;
  76.                         while ($row = $db->doRead())
  77.                         {
  78.                                 $date = explode(' ', str_replace(array('-', '/'), '.', $row['date']));
  79.                                 $date = $date[0];
  80.                                 $data = array('news-date' => $date, 'news-title' => strlen($row['n_title']) > 22 ? substr($row['n_title'], 0, 21) . '...' : $row['n_title'], 'news-id' => $row['id']);
  81.                                 Template::SetVar('SHORT-NEWS-' . $i++, Template::Load('news-bit2', $data));
  82.                         }
  83.                 }
  84.                
  85.                 function doShowUserRankings()
  86.                 {
  87.                         $db = $this->getGDB();
  88.  
  89.                         $db->doQuery('SELECT TOP 25 strUserId, Loyalty, Nation FROM USERDATA WHERE Authority IN(1, 2) ORDER BY Loyalty DESC, strUserId ASC');
  90.                         if ($db->hasError() || !$db->hasRows())
  91.                         {
  92.                                 Template::SetVar('rankings_short_user', NULL);
  93.                                 return;
  94.                         }
  95.                        
  96.                         $i = 1;
  97.                         $maincontent = '';
  98.                         $content = '';
  99.                         $n = 0;
  100.                        
  101.                         while ($row = $db->doRead())
  102.                         {
  103.                                 $NP = intval($row['Loyalty']);
  104.  
  105.                                 $data = array('rank_pos' => $i, 'rank_name' => $row['strUserId'], 'rank_loyalty' => number_format($NP), 'rank_type' => 'char', 'rank_nation' => $row['Nation']);
  106.                                 $content .= Template::Load('short_rankings_entry', $data);
  107.                
  108.                                 $n++;
  109.                                 if ($n == 10)
  110.                                 {
  111.                                         $maincontent .= Template::Load('short_rankings', array('short_rankings_data' => $content));
  112.                                         $content = '';
  113.                                         $n = 0;
  114.                                 }
  115.                                
  116.                                 $i++;
  117.                         }
  118.                         if ($n < 10 && $n > 0)
  119.                                 $maincontent .= Template::Load('short_rankings', array('short_rankings_data' => $content));
  120.                                
  121.                         Template::SetVar('RANKINGS_SHORT_USER', $maincontent);
  122.                 }
  123.                
  124.                 function doShowClanRankings()
  125.                 {
  126.                         $db = $this->getGDB();
  127.  
  128.                         $db->doQuery('SELECT TOP 50 IDNum, IDName, Nation, (SELECT SUM(Loyalty) FROM USERDATA WHERE USERDATA.Knights = KNIGHTS.IDNum AND USERDATA.Authority = 1) as ClanLoyalty FROM KNIGHTS ORDER BY ClanLoyalty DESC, IDName ASC');
  129.                         if ($db->hasError() || !$db->hasRows())
  130.                         {
  131.                                 Template::SetVar('rankings_short_clan', NULL);
  132.                                 return;
  133.                         }
  134.                        
  135.                         $i = 1;
  136.                         $maincontent = '';
  137.                         $content = '';
  138.                         $n = 0;
  139.                        
  140.                         while ($row = $db->doRead())
  141.                         {
  142.                                 $NP = intval($row['ClanLoyalty']);
  143.  
  144.                                 $data = array('rank_pos' => $i, 'rank_id' => $row['IDNum'], 'rank_name' => $row['IDName'], 'rank_loyalty' => number_format($NP), 'rank_type' => 'clan', 'rank_nation' => $row['Nation']);
  145.                                 $content .= Template::Load('short_rankings_entry2', $data);
  146.                
  147.                                 $n++;
  148.                                 if ($n == 10)
  149.                                 {
  150.                                         $maincontent .= Template::Load('short_rankings', array('short_rankings_data' => $content));
  151.                                         $content = '';
  152.                                         $n = 0;
  153.                                 }
  154.  
  155.                                 $i++;
  156.                         }
  157.                         if ($n < 10 && $n > 0)
  158.                                 $maincontent .= Template::Load('short_rankings', array('short_rankings_data' => $content));
  159.                                
  160.                         Template::SetVar('RANKINGS_SHORT_CLAN', $maincontent);
  161.                 }
  162.                
  163.                 function doShowEntry()
  164.                 {
  165.                         $db = $this->getADB();
  166.                         $db->doQuery('SELECT date,n_title,n_text FROM News WHERE id = ?', intval(@$_GET['id']));
  167.                         if ($db->hasError() || !$db->hasRows())
  168.                         {
  169.                                 $replace = array('news-message' => Template::GetLangVar('NEWS_MISSING'), 'news-title' => Template::GetLangVar('OOPS_PROBLEM'), 'news-date' => NULL);
  170.                                 return;
  171.                         }
  172.  
  173.                         $row = $db->doRead();
  174.                         $replace = array('news-message' => $row['n_text'], 'news-title' => $row['n_title'], 'news-date' => $row['date']);
  175.                        
  176.                         $this->loadTPL('news-entry', $replace);
  177.                 }
  178.         }
  179.        
  180.  
  181.  
  182.  
  183. ?>