root/dev/common/home.php

Revision 370, 8.1 KB (checked in by kovell, 13 years ago)

- 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

Line 
1<?php
2require_once('common/includes/class.killsummarytable.public.php');
3require_once('common/includes/class.killlist.php');
4require_once('common/includes/class.killlisttable.php');
5require_once('common/includes/class.contract.php');
6require_once('common/includes/class.toplist.php');
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;
38
39$page = new Page('Week '.$week);
40
41// Display the summary table.
42$kslist = new KillList();
43involved::load($kslist,'kill');
44$kslist->setWeek($week);
45$kslist->setYear($year);
46
47if (config::get('summarytable')){
48if (config::get('public_summarytable')){
49        $summarytable = new KillSummaryTablePublic($kslist);
50}
51else
52{
53        $llist = new KillList();
54        involved::load($llist,'loss');
55        $llist->setWeek($week);
56        $llist->setYear($year);
57        $summarytable = new KillSummaryTable($kslist, $llist);
58}
59$summarytable->setBreak(config::get('summarytable_rowcount'));
60$html .= $summarytable->generate();
61}
62
63// Display campaigns, if any.
64if ($page->killboard_->hasCampaigns(true))
65{
66    $html .= "<div class=kb-campaigns-header>Active campaigns</div>";
67    $list = new ContractList();
68    $list->setActive("yes");
69    $list->setCampaigns(true);
70    $table = new ContractListTable($list);
71    $html .= $table->generate();
72}
73
74// Display contracts, if any.
75if ($page->killboard_->hasContracts(true))
76{
77    $html .= "<div class=kb-campaigns-header>Active contracts</div>";
78    $list = new ContractList();
79    $list->setActive("yes");
80    $list->setCampaigns(false);
81    $table = new ContractListTable($list);
82    $html .= $table->generate();
83}
84
85// bad hax0ring, we really need mod callback stuff
86if (strpos(config::get('mods_active'), 'rss_feed') !== false)
87{
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.
185$page->setContent($html);
186$menubox = new box("Menu");
187$menubox->setIcon("menu-item.gif");
188$menubox->addOption("caption","Navigation");
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}
213$page->addContext($menubox->generate());
214
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.
222$tklist = new TopKillsList();
223$tklist->setWeek($week);
224$tklist->setYear($year);
225involved::load($tklist,'kill');
226
227$tklist->generate();
228$tkbox = new AwardBox($tklist, "Top killers", "kills in week " . $week, "kills", "eagle");
229$page->addContext($tkbox->generate());
230
231if (config::get('kill_points'))
232{
233    $tklist = new TopScoreList();
234    $tklist->setWeek($week);
235    $tklist->setYear($year);
236    involved::load($tklist,'kill');
237
238    $tklist->generate();
239    $tkbox = new AwardBox($tklist, "Top scorers", "points in week " . $week, "points", "redcross");
240    $page->addContext($tkbox->generate());
241}
242
243$page->generate();
244?>
Note: See TracBrowser for help on using the browser.