function doit($p) { echo $p; if ($p) { doit($p); } }
function arif() { $arrayArg = func_get_args(); $act = func_get_arg(0); array_shift($arrayArg); doit($arrayArg, $act); }
function test_coverage() { $this->assertCoverage('cms/cms.php'); //ѕеременные d()->test_var = 'test value'; $this->assertEquals(d()->test_var, 'test value'); $this->assertEquals(doit()->test_var, 'test value'); $this->assertEquals(d()->url(), url()); $this->assertEquals(d()->stuff_for_test(), 'result'); $this->assertEquals(d()->render('stuff_for_test'), 'result'); d()->stuff_for_test = 'another result'; $this->assertEquals(d()->render('stuff_for_test'), 'another result'); $dummy = new PDODummy(); $this->assertEquals($dummy, $dummy->someUnusualFunc()); $this->assertEquals(get_class(d()->SomeAnyStuff), 'SomeAnyStuff'); }
{ global $sess, $HTTP_POST_VARS, $mytrail, $auth; if ($HTTP_POST_VARS['field_subject'] == "") { form(true); page_close(); exit; } if (!defined("TALK_INC")) { include "messages/talk.inc"; } talk($auth->auth['uname'], $mytrail['userid'], $HTTP_POST_VARS['field_subject'], $HTTP_POST_VARS['field_message'], $mytrail['id']); header("Location: " . $sess->url($mytrail['path'])); } if (!defined("LAY_TRAIL_INC")) { include "layout/lay_trail.inc"; } /* First I read the permissions of our user. */ page_open(array("sess" => "Linktrail_Session", "auth" => "Linktrail_Auth", "perm" => "Linktrail_Perm", "user" => "Linktrail_User")); $mytrail = get_node_info($PATH_INFO); if ($mytrail == -1) { $mytrail = get_node_info($PATH_INFO . "?"); } include "template.inc"; if ($REQUEST_METHOD == "POST") { doit(); } else { form(); } page_close();
localConst(TRUE); echo "COEFFICIENT_1 = " . COEFFICIENT_1 . "\n"; echo "FAILURE = " . FAILURE . "\n"; // as it's visible here, it's not really a local! echo "---------------- Local variables -------------------\n"; function doit($p1) { $count = 10; // … if ($p1) { $message = "Can't open master file."; // … } // … } doit(TRUE); echo "---------------- Array elements -------------------\n"; echo "---------------- Function statics -------------------\n"; function f() { $lv = 1; static $fs = 1; static $fs2; var_dump($fs2); // show default value is NULL echo "\$lv = {$lv}, \$fs = {$fs}\n"; ++$lv; ++$fs; if (TRUE) { static $fs3 = 99; echo "\$fs3 = {$fs3}\n";
ini_set('html_errors', 'off'); ini_set('display_errors', 'on'); ini_set('implicit_flush', 'false'); require __DIR__ . '/functions.php'; // Set-up environment set_time_limit(0); function doit($input) { global $fp; if (!($fp = popen($input, 'r'))) { die('Cannot open pipe'); } $lines = 1; while ($line = fgets($fp, 2096)) { if (preg_match('/^.*MailScanner.*: Requeue: (\\S+\\.\\S+) to (\\S+)\\s$/', $line, $explode)) { $smtpd_id = $explode[1]; $smtp_id = $explode[2]; dbquery("REPLACE INTO mtalog_ids VALUES ('{$smtpd_id}','{$smtp_id}')"); } $lines++; } pclose($fp); } if ($_SERVER['argv'][1] == '--refresh') { doit('cat ' . MS_LOG); } else { // Refresh first doit('cat ' . MS_LOG); // Start watching the maillog doit('tail -F -n0 ' . MS_LOG); }
{ print $message . "\n"; exit(1); } // Connect to the local MySQL server (force TCP by using the IP address.) $dbh = new PDO("mysql:host=127.0.0.1;dbname={$db_database}", $db_user, $db_password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); // Pass 1 - flush and copy. This will get an inconsistent snapshot, but we'll // make it consistent in pass 2. $dbh->query("FLUSH TABLES")->closeCursor(); $retval = doit("{$rsync_local} {$db_data_directory}/{$db_database} {$backup_directory}"); if ($retval != 0) { die_error("Pass 1 rsync failed."); } // Pass 2 - flush and sync the data directory under a lock. $dbh->query("FLUSH TABLES WITH READ LOCK")->closeCursor(); $retval = doit("{$rsync_local} {$db_data_directory}/{$db_database} {$backup_directory}"); if ($retval != 0) { die_error("Pass 2 rsync failed."); } // Done, unlock tables. $dbh->query("UNLOCK TABLES")->closeCursor(); function doit($cmd) { global $dryrun; if ($dryrun) { echo "{$cmd}\n"; return 0; } system($cmd, $retval); return $retval; }
$_type = mysql_real_escape_string('unknown_hostname'); } else { $_type = mysql_real_escape_string('NOQUEUE'); } $_status = mysql_real_escape_string($postfix->raw); } // Relay lines if (isset($postfix->entries['relay']) && isset($postfix->entries['status'])) { $_type = mysql_real_escape_string('relay'); $_delay = mysql_real_escape_string($postfix->entries['delay']); $_relay = mysql_real_escape_string(get_ip($postfix->entries['relay'])); $_dsn = mysql_real_escape_string($postfix->entries['dsn']); $_status = mysql_real_escape_string($postfix->entries['status']); } } if (isset($_type)) { dbquery("REPLACE INTO mtalog VALUES (FROM_UNIXTIME('{$_timestamp}'),'{$_host}','{$_type}','{$_msg_id}','{$_relay}','{$_dsn}','{$_status}','{$_delay}')"); } $lines++; } dbclose(); pclose($fp); } if ($_SERVER['argv'][1] == '--refresh') { doit('cat ' . MAIL_LOG); } else { // Refresh first doit('cat ' . MAIL_LOG); // Start watching the maillog doit('tail -F -n0 ' . MAIL_LOG); }
function call_endrankings_text() { global $tool; include_once 'inc/functions/resort_tools.php'; if (!user_has_access($tool)) { echo "Sorry, this page is restricted to ORKFiA Staff"; include_game_down(); exit; } include_once 'inc/classes/clsGame.php'; $objGame = new clsGame(); $iCurrentYear = $objGame->get_year_history(); $iAgeNumber = $objGame->get_game_time(AGE_NUMBER); include_once 'inc/classes/clsAge.php'; $objNewAge = new clsAge(); $objNewAge->loadAge($iAgeNumber); $iFirstYear = $objNewAge->getFirstYear(); $iLastYear = $objNewAge->getLastYear(); // Alla genom history $resSQL2 = mysql_query("SELECT year, alli_id, alli_name, alli_desc FROM rankings_history WHERE alli_id > 10 AND year >= {$iFirstYear} AND year <= {$iLastYear} GROUP BY alli_id,year ASC"); // Lista Alla För att summera i PHP $old_id = 0; $count = 0; while ($arrRow = mysql_fetch_assoc($resSQL2)) { $new_id = $arrRow['alli_id']; if ($new_id != $old_id) { // prepare for new alliance $count++; // Copy SQL result row $arrAlliance[$count] = $arrRow; // add a starting year column to display period, eg 100 - 106 OE $arrAlliance[$count]['starting_year'] = $arrRow['year']; // add an ending year column to display period, eg 100 - 106 OE $arrAlliance[$count]['ending_year'] = $arrRow['year']; // add a year counter column, starting value = 1 $arrAlliance[$count]['years'] = 1; // Save alliance id for next loop $old_id = $new_id; } elseif ($new_id == $old_id) { // add another year to our counter column $arrAlliance[$count]['years']++; // update ending year column $arrAlliance[$count]['ending_year'] = $arrRow['year']; } } //====================================================================== // Sort the array //====================================================================== // Obtain the column to sorty by foreach ($arrAlliance as $key => $row) { $years[$key] = $row['years']; } // Sort the data with years descending // Add $arrAlliance as the last parameter, to sort by the common key array_multisort($years, SORT_DESC, $arrAlliance); //====================================================================== // Done sorting ;) //====================================================================== echo "<h1>Age {$iAgeNumber} ({$iFirstYear} - {$iLastYear} OE)</h1>"; echo "<h2>Top Alliance History</h2>"; echo "<table class=\"big\" cellpadding=\"0\" cellspacing=\"0\">"; $count = 1; foreach ($arrAlliance as $arrAlliance) { echo "<tr class=\"data\">"; echo "<th width=\"25\">{$count}. </th>"; echo "<th>" . stripslashes($arrAlliance['alli_name']) . "</th>"; echo "<td class=\"left\">" . "(#<A HREF=\"main.php?cat=game&page=alliance&aid=" . $arrAlliance['alli_id'] . "\">" . $arrAlliance['alli_id'] . "</A>)" . "</td>"; echo "<td>" . $arrAlliance['years'] . " years on top</td>"; $count++; echo "</tr>"; } echo "</table>"; //************************************************************************** // 2nd LIST //************************************************************************** function doit1() { include_once 'inc/classes/clsGame.php'; $objGame = new clsGame(); $iCurrentYear = $objGame->get_year_history(); $iAgeNumber = $objGame->get_game_time(AGE_NUMBER); include_once 'inc/classes/clsAge.php'; $objNewAge = new clsAge(); $objNewAge->loadAge($iAgeNumber); $iFirstYear = $objNewAge->getFirstYear(); $iLastYear = $objNewAge->getLastYear(); echo "<h2>Top Acreage History</h2>"; echo "<table class=\"big\" cellpadding=\"0\" cellspacing=\"0\">"; $count = 1; $query = mysql_query("SELECT MAX(land) as land,alli_id,year FROM rankings_history WHERE alli_id > 10 AND year >= {$iFirstYear} AND year <= {$iLastYear} GROUP BY alli_id ORDER BY land DESC LIMIT 9"); while ($line = mysql_fetch_array($query)) { $line2 = mysql_fetch_array(mysql_query("SELECT year,alli_name,alli_desc FROM rankings_history WHERE land = {$line['land']} AND alli_id = {$line['alli_id']}")); $cm = $count % 2 == 0 ? " even" : " odd"; echo "<tr class=\"data" . $cm . "\">"; echo "<th width=\"25\">{$count}.</th>"; echo "<th>" . stripslashes($line2['alli_name']) . " (#<A HREF=\"main.php?cat=game&page=alliance&aid=" . $line['alli_id'] . "\">" . $line['alli_id'] . "</a>)" . "</th>"; echo "<td>" . number_format($line['land']) . " acres </td>"; echo "<td>(" . $line2['year'] . " OE)</td>"; echo "</tr>"; $count++; } echo "</table>"; } // hehe... hate me :) "$life has no meaning outside life()" doit1(); //************************************************************************** // 3rd LIST //************************************************************************** function doit() { include_once 'inc/classes/clsGame.php'; $objGame = new clsGame(); $iCurrentYear = $objGame->get_year_history(); $iAgeNumber = $objGame->get_game_time(AGE_NUMBER); include_once 'inc/classes/clsAge.php'; $objNewAge = new clsAge(); $objNewAge->loadAge($iAgeNumber); $iFirstYear = $objNewAge->getFirstYear(); $iLastYear = $objNewAge->getLastYear(); // Alla genom history $resSQL2 = mysql_query("SELECT year, alli_id, alli_name, alli_desc FROM rankings_history WHERE alli_id > 10 AND year >= {$iFirstYear} AND year <= {$iLastYear} GROUP BY year ASC"); // Lista Alla För att summera i PHP $old_id = 0; $count = 0; while ($arrRow = mysql_fetch_assoc($resSQL2)) { $new_id = $arrRow['alli_id']; if ($new_id != $old_id) { // prepare for new alliance $count++; // Copy SQL result row $arrAlliance[$count] = $arrRow; // add a starting year column to display period, eg 100 - 106 OE $arrAlliance[$count]['starting_year'] = $arrRow['year']; // add an ending year column to display period, eg 100 - 106 OE $arrAlliance[$count]['ending_year'] = $arrRow['year']; // add a year counter column, starting value = 1 $arrAlliance[$count]['years'] = 1; // Save alliance id for next loop $old_id = $new_id; } elseif ($new_id == $old_id) { // add another year to our counter column $arrAlliance[$count]['years']++; // update ending year column $arrAlliance[$count]['ending_year'] = $arrRow['year']; } } //====================================================================== // Sort the array //====================================================================== // Obtain the column to sorty by foreach ($arrAlliance as $key => $row) { $years[$key] = $row['starting_year']; } // Sort the data with years descending // Add $arrAlliance as the last parameter, to sort by the common key array_multisort($years, SORT_ASC, $arrAlliance); //====================================================================== // Done sorting ;) //====================================================================== echo "<h2>Timeline</h2>"; echo "<table class=\"big\" cellpadding=\"0\" cellspacing=\"0\">"; $count = 1; foreach ($arrAlliance as $arrAlliance) { echo "<tr class=\"data\">"; echo "<td class=\"left\">(" . $arrAlliance['starting_year'] . ' - ' . $arrAlliance['ending_year'] . " OE) </td>"; echo "<th>" . stripslashes($arrAlliance['alli_name']) . "</th>"; echo "<td class=\"left\">" . "(#<A HREF=\"main.php?cat=game&page=alliance&aid=" . $arrAlliance['alli_id'] . "\">" . $arrAlliance['alli_id'] . "</A>)" . "</td>"; echo "<td>" . $arrAlliance['years'] . " years on top </td>"; $count++; echo "</tr>"; } echo "</table>"; } // hehe... hate me :) "$life has no meaning outside life()" doit(); }
<?php function doit($a, $b) { $trace = debug_backtrace(); custom_callback('dereferenced', $trace); custom_callback('direct', debug_backtrace()); } function custom_callback($traceName, $btInfo) { echo $traceName . " -- args: "; echo isset($btInfo[0]['args']) ? count($btInfo[0]['args']) : 'does not exist'; echo "\n"; } doit('a', 'b');
function include_rankings_text() { global $Host; require_once 'inc/races/clsRace.php'; include_once 'inc/classes/clsGame.php'; $objGame = new clsGame(); $iAgeNumber = $objGame->get_game_time(AGE_NUMBER); $show = 'alliance'; if (isset($_GET['show'])) { $show = $_GET['show']; } echo get_rankings_links($show); $link = "main.php?cat=game&page=rankings&show={$show}&type="; $rankingsText = '<div id="textBig">'; switch ($show) { case "annual": $rankingsText .= "<h2>History Rankings</h2>" . "<h3>Alliance</h3>" . "<p>" . " | <a href=\"" . $link . "currentage\">Current Age</a> |" . " <a href=\"" . $link . "topalli\">King Of The Hill</a> |" . " <a href=\"" . $link . "topland\">Largest Alliance</a> |" . "</p>"; if (!isset($_GET['type'])) { $_GET['type'] = 'currentage'; } break; case "personal": $rankingsText .= "<h2>Personal Rankings</h2>" . "<p> | <a href=\"" . $link . "pland\">Land</a> |" . " <a href=\"" . $link . "pstr\">Strength</a> |" . " <a href=\"" . $link . "pfame\">Fame</a> |" . "</p><p>"; //modified to find out about races dynamically - AI 17/02/2007 $races = clsRace::getRaces(); $active_races = clsRace::getActiveRaces(); foreach ($races as $number => $race) { if ($number % 3 == 0) { $rankingsText .= '- '; } $style = ''; if (!in_array($race, $active_races)) { $style = 'style="font-style:italic;"'; } $rankingsText .= "<span {$style}>{$race} [ " . "<a href=\"" . $link . "rland&race={$number}\">Land</a> | " . "<a href=\"" . $link . "rstr&race={$number}\">Strength</a> | " . "<a href=\"" . $link . "rfame&race={$number}\">Fame</a> ] </span>"; if ($number % 3 == 2) { $rankingsText .= '<br />'; } } $rankingsText .= "</p>"; if (!isset($_GET['type'])) { $_GET['type'] = 'pland'; } break; case "alliance": $rankingsText .= "<h2>Alliance Rankings</h2>" . "<p>| <a href=\"" . $link . "aland\">Land</a> | " . " <a href=\"" . $link . "astr\">Strength</a> | " . " <a href=\"" . $link . "afame\">Fame</a> | " . "<a href=\"" . $link . "support\">Top Voting Supporters</a></p>"; if (!isset($_GET['type'])) { $_GET['type'] = 'aland'; } break; } $rankingsText .= '</div>'; echo $rankingsText; if (!isset($_GET['type'])) { include_game_down(); exit; } $strType = $_GET["type"]; if ($strType == "pstr") { $strTitle = "Individual Strength Rankings"; $strRankingType = "p"; $type = "Strength"; $dbtype = "nw"; } elseif ($strType == "pfame") { $strTitle = "Individual Fame Rankings"; $strRankingType = "p"; $type = "Fame"; $dbtype = "fame"; } elseif ($strType == "pland") { $strTitle = "Individual Land Rankings"; $strRankingType = "p"; $type = "Acres"; $dbtype = "land"; } elseif ($strType == "astr") { $strTitle = "Alliance Strength Rankings"; $strRankingType = "a"; $type = "Strength"; $dbtype = "nw"; } elseif ($strType == "aland") { $strTitle = "Alliance Land Rankings"; $strRankingType = "a"; $type = "Acres"; $dbtype = "land"; } elseif ($strType == "afame") { $strTitle = "Alliance Fame Rankings"; $strRankingType = "a"; $type = "Fame"; $dbtype = "fame"; } elseif ($strType == "rstr") { $strTitle = "Individual Race Strength Rankings"; $strRankingType = "r"; $type = "Strength"; $dbtype = "nw"; } elseif ($strType == "rland") { $strTitle = "Individual Race Land Rankings"; $strRankingType = "r"; $type = "Acres"; $dbtype = "land"; } elseif ($strType == "rfame") { $strTitle = "Individual Race Fame Rankings"; $strRankingType = "r"; $type = "Fame"; $dbtype = "fame"; } elseif ($strType == "support") { $strTitle = "Top Supporters"; $strRankingType = "s"; } elseif ($strType == "topalli") { $strTitle = "King Of The Hill History"; $strRankingType = "ta"; } elseif ($strType == "topland") { $strTitle = "Largest Alliance History"; $strRankingType = "tl"; } elseif ($strType == "currentage") { $strTitle = "Age {$iAgeNumber} Rankings"; $strRankingType = "ca"; } // elseif ($strType == "truetopalli") { // $strTitle = "King Of The Hill (In Recent History)"; // $strRankingType = "tta"; // $dbtype = "alli_name"; // } elseif ($strType == "truetopalliid") { // $strTitle = "King Of The Hill (In Recent History)"; // $strRankingType = "tta"; // $dbtype = "alli_id"; // } if (isset($_GET['race'])) { $race = $_GET['race']; //modified to be dynamic - AI 17/02/2007 $races = clsRace::getRaces(); $race = $races[$race]; } echo "<br />"; if ($strRankingType == "p") { $res = mysql_query("SELECT id,tribe_name,race,alli_id," . $dbtype . " FROM rankings_personal WHERE alli_id > 10 ORDER BY " . $dbtype . " DESC LIMIT 200"); echo "<table class=\"big\" cellpadding=\"0\" cellspacing=\"0\">"; echo "<tr class=\"header\"><th colspan=\"4\">" . $strTitle . "</th></tr>"; echo "<tr class=\"subheader\">"; echo "<th>Tribe Name</th>"; echo "<th>Race</th>"; echo "<th>Alliance</th>"; echo "<th class=\"right\">" . $type . "</th>"; echo "</tr>"; $iCount = 1; while ($line = mysql_fetch_assoc($res)) { $cm = $iCount % 2 == 0 ? " even" : " odd"; echo "<tr class=\"data" . $cm . "\">"; echo "<th>{$iCount}. " . stripslashes($line["tribe_name"]) . "</th>"; echo "<td class=\"left\">" . $line["race"] . "</td>"; echo "<td class=\"left\">" . "(#<a href=\"main.php?cat=game&page=alliance&aid=" . $line["alli_id"] . "\">" . $line["alli_id"] . "</a>)</td>"; echo "<td>" . number_format($line[$dbtype]) . "</td>"; echo "</tr>"; $iCount++; } } elseif ($strRankingType == "a") { $res = mysql_query("SELECT id,alli_name,alli_desc," . $dbtype . " FROM rankings_alliance WHERE id > 10 ORDER BY " . $dbtype . " DESC LIMIT 50"); echo "<table class=\"big\" cellpadding=\"0\" cellspacing=\"0\">"; echo "<tr class=\"header\"><th colspan=\"5\">" . $strTitle . "</th></tr>"; echo "<tr class=\"subheader\">"; echo "<th width=\"25\"> </th>"; echo "<th>Alliance Name</th>"; echo "<th class=\"left\">Alliance Description</th>"; echo "<th>#</th>"; echo "<th class=\"right\">" . $type . "</th>"; echo "</tr>"; $iCount = 1; while ($line = mysql_fetch_assoc($res)) { $cm = $iCount % 2 == 0 ? " even" : " odd"; echo "<tr class=\"data" . $cm . "\">"; echo "<th class=\"left\">" . $iCount . ".</th>"; echo "<th class=\"left\">" . stripslashes($line["alli_name"]) . "</th>"; echo "<td class=\"left\">" . stripslashes($line["alli_desc"]) . "</td>"; echo "<td class=\"left\">" . "(#<a href=\"main.php?cat=game&page=alliance&aid=" . $line["id"] . "\">" . $line["id"] . "</a>) " . "</td>"; echo "<td>" . number_format($line[$dbtype]) . "</td>"; echo "</tr>"; $iCount++; } } elseif ($strRankingType == "r") { $res = mysql_query("SELECT id,tribe_name,race,alli_id," . $dbtype . " FROM rankings_personal WHERE alli_id > 10 AND race = '" . $race . "' ORDER BY " . $dbtype . " DESC LIMIT 50"); echo "<table class=\"big\" cellpadding=\"0\" cellspacing=\"0\">"; echo "<tr class=\"header\"><th colspan=\"4\">" . $strTitle . "</th></tr>"; echo "<tr class=\"subheader\">"; echo "<th>Tribe Name</th>"; echo "<th>Race</th>"; echo "<th>Alliance</th>"; echo "<th class=\"right\">" . $type . "</th>"; echo "</tr>"; $iCount = 1; while ($line = mysql_fetch_assoc($res)) { $cm = $iCount % 2 == 0 ? " even" : " odd"; echo "<tr class=\"data" . $cm . "\">"; echo "<th>{$iCount}. " . stripslashes($line["tribe_name"]) . "</th>"; echo "<td class=\"left\">" . $line["race"] . "</td>"; echo "<td class=\"left\">" . "(#<a href=\"main.php?cat=game&page=alliance&aid=" . $line["alli_id"] . "\">" . $line["alli_id"] . "</a>)</td>"; echo "<td>" . number_format($line[$dbtype]) . "</td>"; echo "</tr>"; $iCount++; } } elseif ($strRankingType == "s") { $query = mysql_query("SELECT id, name, vote_count FROM `" . ALLIANCE . "` WHERE id > 1 ORDER BY vote_count DESC LIMIT 0 , 50"); echo "<table class=\"big\" cellpadding=\"0\" cellspacing=\"0\">"; echo "<tr class=\"header\"><th colspan=\"2\">Top Supporters</th></tr>"; echo "<tr class=\"subheader\">"; echo "<th>Alliance Name</th>"; echo "<th class=\"right\">Votes</th>"; echo "</tr>"; $iCount = 1; while ($line = mysql_fetch_assoc($query)) { $cm = $iCount % 2 == 0 ? " even" : " odd"; echo "<tr class=\"data" . $cm . "\">"; echo "<th>{$iCount}. " . stripslashes($line['name']) . " (#<a href=\"main.php?cat=game&page=alliance&aid=" . $line['id'] . "\">" . $line['id'] . "</a>)</th>"; echo "<td>" . number_format($line['vote_count']) . "</td>"; echo "</tr>"; $iCount++; } } elseif ($strRankingType == "ta") { include_once 'inc/classes/clsGame.php'; $objGame = new clsGame(); $iCurrentYear = $objGame->get_year_history(); // Nuvarande $resSQL = mysql_query("SELECT alli_id, alli_name, alli_desc, year, land FROM rankings_history WHERE year = {$iCurrentYear} AND year > 105 LIMIT 1"); // Alla genom history $resSQL2 = mysql_query("SELECT year, alli_id, alli_name, alli_desc FROM rankings_history WHERE alli_id > 10 AND year > 105 GROUP BY year ASC"); // Lista Alla För att summera i PHP $old_id = 0; $iCount = 0; while ($arrRow = mysql_fetch_assoc($resSQL2)) { $new_id = $arrRow['alli_id']; if ($new_id != $old_id) { // prepare for new alliance $iCount++; // Copy SQL result row $arrAlliance[$iCount] = $arrRow; // add a starting year column to display period, eg 100 - 106 OE $arrAlliance[$iCount]['starting_year'] = $arrRow['year']; // add an ending year column to display period, eg 100 - 106 OE $arrAlliance[$iCount]['ending_year'] = $arrRow['year']; // add a year counter column, starting value = 1 $arrAlliance[$iCount]['years'] = 1; // Save alliance id for next loop $old_id = $new_id; } elseif ($new_id == $old_id) { // add another year to our counter column $arrAlliance[$iCount]['years']++; // update ending year column $arrAlliance[$iCount]['ending_year'] = $arrRow['year']; } } //====================================================================== // Sort the array //====================================================================== // Obtain the column to sorty by foreach ($arrAlliance as $key => $row) { $years[$key] = $row['years']; } // Sort the data with years descending // Add $arrAlliance as the last parameter, to sort by the common key array_multisort($years, SORT_DESC, $arrAlliance); //====================================================================== // Done sorting ;) //====================================================================== echo "<table class=\"big\" cellpadding=\"0\" cellspacing=\"0\">"; echo "<tr class=\"header\"><th colspan=\"6\">" . $strTitle . "</th></tr>"; echo "<tr class=\"subheader\">"; echo "<th colspan=\"2\"> Alliance Name </th>"; echo "<th width=\"40%\"> Description </th>"; echo "<th> # </th>"; echo "<th> Period </th>"; echo "<th class=\"right\"> Years </th>"; echo "</tr>"; $iCount = 1; while ($arrAlliance1 = mysql_fetch_array($resSQL)) { // pick out the current year alliance from our history array foreach ($arrAlliance as $arrAlliance2) { if ($arrAlliance1['year'] == $arrAlliance2['ending_year']) { $arrAlliance1 = $arrAlliance2; break; } } $cm = $iCount % 2 == 0 ? " even" : " odd"; echo "<tr class=\"data" . $cm . "\">"; echo "<th width=\"25\" class=\"bsdown\">{$iCount}. </th>"; echo "<th class=\"bsdown\">" . stripslashes($arrAlliance1['alli_name']) . "</th>"; echo "<td class=\"bsdown left\">" . $arrAlliance1['alli_desc'] . "</td>"; echo "<td class=\"bsdown left\">" . "(#<a href=\"main.php?cat=game&page=alliance&aid=" . $arrAlliance1['alli_id'] . "\">" . $arrAlliance1['alli_id'] . "</a>)" . "</td>"; echo "<td class=\"bsdown left\">" . $arrAlliance1['starting_year'] . ' - <strong>' . $arrAlliance1['ending_year'] . "</strong> OE</td>"; echo "<td class=\"bsdown\">" . $arrAlliance1['years'] . "</td>"; echo "</tr>"; $iCount++; } foreach ($arrAlliance as $arrAlliance) { $cm = $iCount % 2 == 0 ? " even" : " odd"; echo "<tr class=\"data" . $cm . "\">"; echo "<th width=\"25\">{$iCount}. </th>"; echo "<th>" . stripslashes($arrAlliance['alli_name']) . "</th>"; echo "<td class=\"left\">" . $arrAlliance['alli_desc'] . "</td>"; echo "<td class=\"left\">" . "(#<a href=\"main.php?cat=game&page=alliance&aid=" . $arrAlliance['alli_id'] . "\">" . $arrAlliance['alli_id'] . "</a>)" . "</td>"; echo "<td class=\"left\">" . $arrAlliance['starting_year'] . ' - ' . $arrAlliance['ending_year'] . " OE</td>"; echo "<td>" . $arrAlliance['years'] . "</td>"; echo "</tr>"; $iCount++; // if ($iCount == 10) // { // break; // } } } elseif ($strRankingType == "tl") { include_once 'inc/classes/clsGame.php'; $objGame = new clsGame(); $iCurrentYear = $objGame->get_year_history(); $query1 = mysql_query("SELECT alli_id,alli_name,alli_desc,year,land FROM rankings_history WHERE year = {$iCurrentYear} AND year > 105 LIMIT 1"); echo "<table class=\"big\" cellpadding=\"0\" cellspacing=\"0\">"; echo "<tr class=\"header\"><th colspan=\"5\">" . $strTitle . "</th></tr>"; echo "<tr class=\"subheader\">"; echo "<th colspan=\"2\"> Alliance Name </th>"; echo "<th> Description </th>"; echo "<th class=\"right\"> Year </th>"; echo "<th class=\"right\"> Acres </th>"; echo "</tr>"; $iCount = 1; while ($line = mysql_fetch_array($query1)) { $cm = $iCount % 2 == 0 ? " even" : " odd"; echo "<tr class=\"data" . $cm . "\">"; echo "<th width=\"25\" class=\"bsdown\">{$iCount}.</th>"; echo "<th class=\"bsdown\">" . stripslashes($line['alli_name']) . " (#<a href=\"main.php?cat=game&page=alliance&aid=" . $line['alli_id'] . "\">" . $line['alli_id'] . "</a>) </th>"; echo "<td class=\"bsdown\">" . $line['alli_desc'] . "</td>"; echo "<td class=\"bsdown\">" . $line['year'] . " OE</td>"; echo "<td class=\"bsdown\">" . number_format($line['land']) . "</td>"; echo "</tr>"; $iCount++; } $query = mysql_query("SELECT alli_id,alli_name,alli_desc,year,MAX(land) as land FROM rankings_history WHERE alli_id > 10 AND year > 105 GROUP BY alli_id ORDER BY land DESC"); // GROUP BY alli_name while ($line = mysql_fetch_array($query)) { $cm = $iCount % 2 == 0 ? " even" : " odd"; echo "<tr class=\"data" . $cm . "\">"; echo "<th width=\"25\">{$iCount}.</th>"; echo "<th>" . stripslashes($line['alli_name']) . " (#<a href=\"main.php?cat=game&page=alliance&aid=" . $line['alli_id'] . "\">" . $line['alli_id'] . "</a>)" . "</th>"; echo "<td>" . $line['alli_desc'] . "</td>"; echo "<td>" . $line['year'] . " OE</td>"; echo "<td>" . number_format($line['land']) . "</td>"; echo "</tr>"; $iCount++; } } elseif ($strRankingType == "ca") { include_once 'inc/classes/clsGame.php'; $objGame = new clsGame(); $iCurrentYear = $objGame->get_year_history(); $iAgeNumber = $objGame->get_game_time(AGE_NUMBER); include_once 'inc/classes/clsAge.php'; $objNewAge = new clsAge(); $objNewAge->loadAge($iAgeNumber); $iFirstYear = $objNewAge->getFirstYear(); $iLastYear = $objNewAge->getLastYear(); // Alla genom history $resSQL2 = mysql_query("SELECT year, alli_id, alli_name, alli_desc FROM rankings_history WHERE alli_id > 10 AND year >= {$iFirstYear} AND year <= {$iLastYear} GROUP BY alli_id,year ASC"); // Lista Alla För att summera i PHP $old_id = 0; $iCount = 0; while ($arrRow = mysql_fetch_assoc($resSQL2)) { $new_id = $arrRow['alli_id']; if ($new_id != $old_id) { // prepare for new alliance $iCount++; // Copy SQL result row $arrAlliance[$iCount] = $arrRow; // add a starting year column to display period, eg 100 - 106 OE $arrAlliance[$iCount]['starting_year'] = $arrRow['year']; // add an ending year column to display period, eg 100 - 106 OE $arrAlliance[$iCount]['ending_year'] = $arrRow['year']; // add a year counter column, starting value = 1 $arrAlliance[$iCount]['years'] = 1; // Save alliance id for next loop $old_id = $new_id; } elseif ($new_id == $old_id) { // add another year to our counter column $arrAlliance[$iCount]['years']++; // update ending year column $arrAlliance[$iCount]['ending_year'] = $arrRow['year']; } } //====================================================================== // Sort the array //====================================================================== // Obtain the column to sorty by foreach ($arrAlliance as $key => $row) { $years[$key] = $row['years']; } // Sort the data with years descending // Add $arrAlliance as the last parameter, to sort by the common key array_multisort($years, SORT_DESC, $arrAlliance); //====================================================================== // Done sorting ;) //====================================================================== echo '<div class="center">' . '<h1 style="margin-top: 0;">Age ' . $iAgeNumber . ' Rankings (' . $iFirstYear . ' - ' . $iLastYear . ' OE)</h1>' . '</div>'; // echo "<h2>Top Alliance History</h2>"; $strTopAllianceCurrentTable = '<table class="big" cellpadding="0" cellspacing="0">' . '<tr class="header">' . '<th colspan="5">King of the Hill</th>' . '</tr>' . '<tr class="subheader">' . '<th> </th>' . '<th>Alliance Name</th>' . '<th>Alliance Description</th>' . '<th>#</th>' . '<th class="right">Years</th>' . '</tr>'; $iCount = 1; foreach ($arrAlliance as $arrAlliance) { $strTopAllianceCurrentTable .= '<tr class="data">' . '<th width="25">' . $iCount . '.</th>' . '<th>' . stripslashes($arrAlliance['alli_name']) . '</th>' . '<td class="left">' . stripslashes($arrAlliance['alli_desc']) . '</td>' . '<td class="left">' . '(#<a href="main.php?cat=game&page=alliance&aid=' . $arrAlliance['alli_id'] . '">' . $arrAlliance['alli_id'] . '</a>)' . '</td>' . '<td>' . $arrAlliance['years'] . ' years on top</td>' . '</tr>'; $iCount++; } $strTopAllianceCurrentTable .= '</table>'; echo $strTopAllianceCurrentTable; //************************************************************************** // 2nd LIST //************************************************************************** function doit1() { include_once 'inc/classes/clsGame.php'; $objGame = new clsGame(); $iCurrentYear = $objGame->get_year_history(); $iAgeNumber = $objGame->get_game_time(AGE_NUMBER); include_once 'inc/classes/clsAge.php'; $objNewAge = new clsAge(); $objNewAge->loadAge($iAgeNumber); $iFirstYear = $objNewAge->getFirstYear(); $iLastYear = $objNewAge->getLastYear(); // echo "<h2>Top Acreage History</h2>"; echo '<br />'; $strTopAcreageCurrentTable = '<table class="big" cellpadding="0" cellspacing="0">' . '<tr class="header">' . '<th colspan="6">Largest Alliance</th>' . '</tr>' . '<tr class="subheader">' . '<th> </th>' . '<th>Alliance Name</th>' . '<th>Alliance Description</th>' . '<th>#</th>' . '<th class="right">Year</th>' . '<th class="right">Acres</th>' . '</tr>'; $iCount = 1; $query = mysql_query("SELECT MAX(land) as land,alli_id,year FROM rankings_history WHERE alli_id > 10 AND year >= {$iFirstYear} AND year <= {$iLastYear} GROUP BY alli_id ORDER BY land DESC"); while ($line = mysql_fetch_array($query)) { $line2 = mysql_fetch_array(mysql_query("SELECT year,alli_name,alli_desc FROM rankings_history WHERE land = {$line['land']} AND alli_id = {$line['alli_id']}")); $cm = $iCount % 2 == 0 ? " even" : " odd"; $strTopAcreageCurrentTable .= '<tr class="data"' . $cm . '">' . '<th width="25">' . $iCount . '.</th>' . '<th>' . stripslashes($line2['alli_name']) . '</th>' . '<td class="left">' . stripslashes($line2['alli_desc']) . '</td>' . '<td class="left">(#<a href="main.php?cat=game&page=alliance&aid=' . $line['alli_id'] . '">' . $line['alli_id'] . '</a>)' . '</td>' . '<td>(' . $line2['year'] . ' OE)</td>' . '<td>' . number_format($line['land']) . ' acres </td>' . '</tr>'; $iCount++; } $strTopAcreageCurrentTable .= '</table>'; echo $strTopAcreageCurrentTable; } doit1(); //************************************************************************** // 3rd LIST //************************************************************************** function doit() { include_once 'inc/classes/clsGame.php'; $objGame = new clsGame(); $iCurrentYear = $objGame->get_year_history(); $iAgeNumber = $objGame->get_game_time(AGE_NUMBER); include_once 'inc/classes/clsAge.php'; $objNewAge = new clsAge(); $objNewAge->loadAge($iAgeNumber); $iFirstYear = $objNewAge->getFirstYear(); $iLastYear = $objNewAge->getLastYear(); // Alla genom history $resSQL2 = mysql_query("SELECT year, alli_id, alli_name, alli_desc FROM rankings_history WHERE alli_id > 10 AND year >= {$iFirstYear} AND year <= {$iLastYear} GROUP BY year ASC"); // Lista Alla För att summera i PHP $old_id = 0; $iCount = 0; while ($arrRow = mysql_fetch_assoc($resSQL2)) { $new_id = $arrRow['alli_id']; if ($new_id != $old_id) { // prepare for new alliance $iCount++; // Copy SQL result row $arrAlliance[$iCount] = $arrRow; // add a starting year column to display period, eg 100 - 106 OE $arrAlliance[$iCount]['starting_year'] = $arrRow['year']; // add an ending year column to display period, eg 100 - 106 OE $arrAlliance[$iCount]['ending_year'] = $arrRow['year']; // add a year counter column, starting value = 1 $arrAlliance[$iCount]['years'] = 1; // Save alliance id for next loop $old_id = $new_id; } elseif ($new_id == $old_id) { // add another year to our counter column $arrAlliance[$iCount]['years']++; // update ending year column $arrAlliance[$iCount]['ending_year'] = $arrRow['year']; } } //====================================================================== // Sort the array //====================================================================== // Obtain the column to sorty by foreach ($arrAlliance as $key => $row) { $years[$key] = $row['starting_year']; } // Sort the data with years descending // Add $arrAlliance as the last parameter, to sort by the common key array_multisort($years, SORT_ASC, $arrAlliance); //====================================================================== // Done sorting ;) //====================================================================== // echo '<div class="center"><h2>Timeline</h2></div>'; echo '<br />'; $strTimelineCurrentTable = '<table class="big" cellpadding="0" cellspacing="0">' . '<tr class="header">' . '<th colspan="5">Timeline</th>' . '</tr>' . '<tr class="subheader">' . '<th>Period</th>' . '<th>Alliance Name</th>' . '<th>Alliance Description</th>' . '<th>#</th>' . '<th class="right">Years</th>' . '</tr>'; $iCount = 1; foreach ($arrAlliance as $arrAlliance) { $strTimelineCurrentTable .= '<tr class="data">' . '<td class="left">(' . $arrAlliance['starting_year'] . ' - ' . $arrAlliance['ending_year'] . ' OE) </td>' . '<th>' . stripslashes($arrAlliance['alli_name']) . '</th>' . '<td class="left">' . stripslashes($arrAlliance['alli_desc']) . '</td>' . '<td class="left">' . '(#<a href="main.php?cat=game&page=alliance&aid=' . $arrAlliance['alli_id'] . '">' . $arrAlliance['alli_id'] . '</a>)</td>' . '<td>' . $arrAlliance['years'] . ' years on top </td>' . '</tr>'; $iCount++; } $strTimelineCurrentTable .= '</table>'; echo $strTimelineCurrentTable; } doit(); } // elseif ($strRankingType == 'tta') // { // $strTable = // '<table class="medium" cellpadding="0" cellspacing="0">' . // '<tr class="header">' . // '<th colspan="4">' .$strTitle . '</th>' . // '</tr>' . // '<tr class="subheader">' . // '<th>Alliance Name</th>' . // '<th>#</th>' . // '<th class="center">Years</th>' . // '<th class="right">Active</th>' . // '</tr>'; // $strSQL = "SELECT alli_name, alli_desc, alli_id, count(year) as years, year FROM rankings_history WHERE alli_id > 10 AND year > 105 GROUP BY $dbtype ORDER BY id DESC"; // $resSQL = mysql_query($strSQL); // $iCount = 1; // while ($arrAlliance = mysql_fetch_array($resSQL)) // { // $strTable .= // '<tr class="data">' . // '<th>' . stripslashes($arrAlliance['alli_name']) . '</th>' . // '<td class="left">' . '(#<a href="main.php?cat=game&page=alliance&aid=' . $arrAlliance['alli_id'] . '">' . $arrAlliance['alli_id'] . '</a>)</td>' . // '<td class="center">' . $arrAlliance['years'] . '</td>' . // '<td>~' . $arrAlliance['year'] . ' OE</td>' . // '</tr>'; // $iCount++; // } // echo $strTable; // } echo '</table>'; }
} function doit($value, callable $process) { var_dump($process); return $process($value); } $res = doit(10, 'double'); echo "Result of calling doit using function double = {$res}\n-------\n"; $res = doit(10, 'square'); echo "Result of calling doit using function square = {$res}\n-------\n"; $res = doit(5, function ($p) { return $p * 2; }); echo "Result of calling doit using double closure = {$res}\n-------\n"; $res = doit(5, function ($p) { return $p * $p; }); echo "Result of calling doit using square closure = {$res}\n-------\n"; echo "----------------- using a use clause, #1 ----------------------\n"; function compute(array $values) { $count = 0; $callback = function () use(&$count) { echo "Inside method >>" . __METHOD__ . "<<\n"; // called {closure} ++$count; }; $callback(); echo "\$count = {$count}\n"; $callback(); echo "\$count = {$count}\n";
function doit($p) { echo($p); if ($p) { doit($p); } }