Changeset 370 for dev/common/home.php

Show
Ignore:
Timestamp:
06/14/09 06:51:49 (13 years ago)
Author:
kovell
Message:

- SQL queries optimised for speed and error protection.
- feed syndication optimised
- front page includes optional clock and optional kill/loss display
- mysqli support added
- transaction protection of kills added where supported (mysqli and InnoDB)
- summary tables and contracts show total destroyed value instead of ship value
- html errors reduced
- related kill calculation improved
- query caching errors reduced
- minor bugfixes
- Smarty 2.6.25 added
- apoc fitting mod added and modded
- code optimisations
- code comments added (doxygen format)
- conflicting mods are now identified

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • dev/common/home.php

    r368 r370  
    11<?php 
    22require_once('common/includes/class.killsummarytable.public.php'); 
    3 require_once('common/includes/class.corp.php'); 
    4 require_once('common/includes/class.alliance.php'); 
    53require_once('common/includes/class.killlist.php'); 
    64require_once('common/includes/class.killlisttable.php'); 
    75require_once('common/includes/class.contract.php'); 
    86require_once('common/includes/class.toplist.php'); 
    9  
    10 $week = kbdate('W'); 
    11 $year = getYear(); 
     7if(config::get('show_clock')) require_once('common/includes/class.clock.php'); 
     8 
     9// If a valid week and year are given then show that week. 
     10if(((int)$_GET['w']) >0 && ((int)$_GET['w']) < 54 && ((int)$_GET['y']) > 2000) $prevweek = true; 
     11else $prevweek = false; 
     12if($prevweek) 
     13{ 
     14        $week = (int)$_GET['w']; 
     15        if($week<10) $week='0'.$week; 
     16        $year = (int)$_GET['y']; 
     17} 
     18else 
     19{ 
     20        $week = kbdate('W'); 
     21        $year = getYear(); 
     22} 
     23if ($week == 1) 
     24{ 
     25    $pyear = $year - 1; 
     26    $pweek = 53; 
     27} 
     28else 
     29{ 
     30    $pyear = $year; 
     31    $pweek = $week - 1; 
     32} 
     33 
     34$killcount = config::get('killcount'); 
     35$hourlimit = config::get('limit_hours'); 
     36if(!$hourlimit) $hourlimit = 1; 
     37$klreturnmax = 3; 
    1238 
    1339$page = new Page('Week '.$week); 
    1440 
     41// Display the summary table. 
    1542$kslist = new KillList(); 
    1643involved::load($kslist,'kill'); 
     
    3461} 
    3562 
    36 if ($week == 1) 
    37 { 
    38     $pyear = $year - 1; 
    39     $pweek = 52; 
    40 } 
    41 else 
    42 { 
    43     $pyear = $year; 
    44     $pweek = $week - 1; 
    45 } 
    46  
     63// Display campaigns, if any. 
    4764if ($page->killboard_->hasCampaigns(true)) 
    4865{ 
     
    5572} 
    5673 
     74// Display contracts, if any. 
    5775if ($page->killboard_->hasContracts(true)) 
    5876{ 
     
    6886if (strpos(config::get('mods_active'), 'rss_feed') !== false) 
    6987{ 
    70     $html .= "<div class=kb-kills-header><a href=\"?a=rss\"><img src=\"mods/rss_feed/rss_icon.png\" alt=\"RSS-Feed\" border=\"0\"></a>&nbsp;20 most recent kills</div>"; 
    71 } 
    72 else 
    73 { 
    74     $html .= "<div class=kb-kills-header>20 most recent kills</div>"; 
    75 } 
    76  
    77 $klist = new KillList(); 
    78 $klist->setOrdered(true); 
    79 involved::load($klist,'kill'); 
    80  
    81  
    82 // boards with low killcount could not display 20 kills with those limits 
    83 //$klist->setStartWeek($week - 1); 
    84 //$klist->setYear($year); 
    85 $klist->setLimit(config::get('killcount')); 
    86  
    87 if ($_GET['scl_id']) 
    88     $klist->addVictimShipClass(new ShipClass($_GET['scl_id'])); 
    89 else 
    90     $klist->setPodsNoobShips(false); 
    91  
    92 $table = new KillListTable($klist); 
    93 $table->setLimit(config::get('killcount')); 
    94 $html .= $table->generate(); 
    95  
     88    $html .= "<div class=kb-kills-header><a href=\"?a=rss\"><img src=\"mods/rss_feed/rss_icon.png\" alt=\"RSS-Feed\" border=\"0\"></a>&nbsp;".$killcount." most recent kills</div>"; 
     89} 
     90else 
     91{ 
     92    $html .= "<div class=kb-kills-header>".$killcount." most recent kills</div>"; 
     93} 
     94 
     95// Retrieve kills to be displayed limited by the date. If too few are returned 
     96// extend the date range. If too many are returned reduce the date range. 
     97while(true) 
     98{ 
     99    $klist = new KillList(); 
     100    $klist->setOrdered(true); 
     101    // We'll be needing comment counts so set the killlist to retrieve them 
     102    if (config::get('comments_count')) $klist->setCountComments(true); 
     103    // We'll be needing involved counts so set the killlist to retrieve them 
     104    if (config::get('killlist_involved')) $klist->setCountInvolved(true); 
     105    // limiting doesn't work well with grouping and ordering sql but in case 
     106    // it improves a limit one higher than the size test is used 
     107    if (!$prevweek) $klist->setLimit($killcount * $klreturnmax + 1); 
     108    else 
     109    { 
     110            $klist->setWeek($week); 
     111            $klist->setYear($year); 
     112    } 
     113//    $klist->setLimit($killcount); 
     114        // Select between combined kills and losses or just kills. 
     115    if(config::get('show_comb_home')) 
     116    { 
     117        if(ALLIANCE_ID >0) $klist->addCombinedAlliance(ALLIANCE_ID); 
     118        if(CORP_ID >0) $klist->addCombinedCorp(CORP_ID); 
     119        if(PILOT_ID>0) $klist->addCombinedPilot(PILOT_ID); 
     120    } 
     121    else involved::load($klist,'kill'); 
     122 
     123 
     124    if ($_GET['scl_id']) 
     125        $klist->addVictimShipClass(intval($_GET['scl_id'])); 
     126    else 
     127        $klist->setPodsNoobShips(false); 
     128 
     129        if($prevweek ) break; // If showing a previous week then don't limit results 
     130    $klist->setStartDate(gmdate("Y-m-d H:i", time()-$hourlimit*3600)); 
     131 
     132    if($klist->getRealCount() < $killcount) 
     133    { 
     134        // Find oldest kill with board owner as victim or involved 
     135        $qry = new DBQuery(); 
     136        $sql = "SELECT kll_timestamp AS oldest FROM kb3_kills "; 
     137                if($_GET['scl_id']) $sql .= "JOIN kb3_ships ON shp_id = kll_ship_id "; 
     138                if(ALLIANCE_ID) $sql .= "JOIN kb3_inv_detail ON kll_id = ind_kll_id WHERE kll_all_id != ".ALLIANCE_ID." AND ind_all_id = ".ALLIANCE_ID." "; 
     139        else if(CORP_ID) $sql .= "JOIN kb3_inv_detail ON kll_id = ind_kll_id WHERE kll_crp_id != ".CORP_ID." AND ind_crp_id = ".CORP_ID." "; 
     140        else if(PILOT_ID) $sql .= "JOIN kb3_inv_detail ON kll_id = ind_plt_id WHERE ind_plt_id = ".PILOT_ID." "; 
     141        if($_GET['scl_id']) $sql .="and shp_class = ".intval($_GET['scl_id'])." "; 
     142        $sql .="ORDER BY kll_timestamp LIMIT 1"; 
     143        $qry->execute($sql); 
     144        // If there are no kills there's no point changing the date range 
     145        if($qry->recordCount() == 0) break; 
     146        // If the date range already includes the oldest kill then no kills are 
     147        // relevant so there's no point changing the date range 
     148        $row = $qry->getRow(); 
     149        if($hourlimit > abs(strtotime($row['oldest'])-time())/3600 ) break; 
     150        if( !($hourlimit > 1) ) $hourlimit = 1; 
     151        $hourlimit = $hourlimit * 2; 
     152        if(!$_GET['scl_id']) config::set('limit_hours', $hourlimit); 
     153        $limitDate=date('Y-m-d H:i',strtotime('-'.$hourlimit.'hours') ); 
     154        continue; 
     155    } 
     156    // If more than the needed kills are retrieved 
     157    // reduce the hour count by 1 with a minimum of 4 
     158    else if($klist->getRealCount() > $killcount * $klreturnmax) 
     159    { 
     160        if($hourlimit > 4) config::set('limit_hours', intval($hourlimit * 0.8) ); 
     161    } 
     162    break; 
     163} 
     164 
     165// If this is the current week then show the most recent kills. If a previous 
     166// week show all kills for the week using the page splitter. 
     167if($prevweek) 
     168{ 
     169        $pagesplitter = new PageSplitter($klist->getCount(), $killcount); 
     170        $klist->setPageSplitter($pagesplitter); 
     171        $table = new KillListTable($klist); 
     172        if(config::get('show_comb_home')) $table->setCombined(true); 
     173        $html .= $table->generate(); 
     174        $html .= $pagesplitter->generate(); 
     175} 
     176else 
     177{ 
     178        $table = new KillListTable($klist); 
     179        if(config::get('show_comb_home')) $table->setCombined(true); 
     180        $table->setLimit($killcount); 
     181        $html .= $table->generate(); 
     182} 
     183 
     184// Display the menu for previous and next weeks. 
    96185$page->setContent($html); 
    97186$menubox = new box("Menu"); 
    98187$menubox->setIcon("menu-item.gif"); 
    99188$menubox->addOption("caption","Navigation"); 
    100 $menubox->addOption("link","Previous week", "?a=kills&w=" . $pweek . "&y=" . $pyear); 
     189if($prevweek) 
     190{ 
     191        $menubox->addOption("link","Previous week", "?a=home&amp;w=" . $pweek . "&amp;y=" . $pyear); 
     192        if(kbdate('W') != $week) 
     193        { 
     194                if ($week == 53) 
     195                { 
     196                        $nweek = 1; 
     197                        $nyear = $year + 1; 
     198                        $pyear = $year - 1; 
     199                } 
     200                else 
     201                { 
     202                        $nweek = $week + 1; 
     203                        $nyear = $year; 
     204                } 
     205                $menubox->addOption("link","Next week", "?a=home&amp;w=" . $nweek . "&amp;y=" . $nyear); 
     206        } 
     207} 
     208else 
     209{ 
     210        $menubox->addOption("link","Whole week", "?a=home&amp;w=" . $week . "&amp;y=" . $year); 
     211        $menubox->addOption("link","Previous week", "?a=home&amp;w=" . $pweek . "&amp;y=" . $pyear); 
     212} 
    101213$page->addContext($menubox->generate()); 
    102214 
     215// Show the Eve time. 
     216if(config::get('show_clock')) 
     217{ 
     218        $clock = new Clock(); 
     219        $page->addContext($clock->generate()); 
     220} 
     221// Display the top pilot lists. 
    103222$tklist = new TopKillsList(); 
    104223$tklist->setWeek($week);