A więc tak.
Tworzę szablon do pewnego skryptu.
Po analizie standardowego szablonu doszedłem do wniosku, że polecenie, które wstawia, zawartość dla określonego adresu to
Kod
require ("Sources/".$whatToDo.".php");
W tym folderze Sources znajdują się różne pliki, mnie natomiast interesuje mainpage.php
Pewnie jak się domyślacie, chodzi o stronę główną. Plik ten (zamieszczam poniżej) dostarcza takie opcje: Newsy, Ladder Statistics, Recent Matches, Ladder Leaders. Trzy ostatnie opcję chciałbym wrzucić do index.php tak, aby wyświetlały się na każdej stronie. A mainpage.php zawierało tylko newsy.
Da radę coś takiego zrobić?
<?php
/*
* v0.2
*
*/
$main = new mainPage;
class mainPage {
function mainPage() {
$info->session->processActivity("test");
$info->output .= "<Table width = "100%" cellspacing = "12">n";
$info->output .= "<TR><TD WIDTH = "200" VALIGN = "top">n";
$info->output .= "<center><B>Ladder Statistics</b></center><BR>n";
//games played
$info->$DB->query("select count(*) from ladder_games;");
$row = $info->$DB->getRow();
$info->output .= $row['count(*)'] . " games played!<BR>n";
//users
$info->$DB->query("select count(*) from ladder_users;");
$row = $info->$DB->getRow();
$info->output .= $row['count(*)'] . " users registerd!<BR>n";
//recent games
$info->output .= "<BR>";
$info->$DB->query("select winner, loser, matchTime from ladder_games order by matchTime desc;");
$displayLimit = $CONF['recentGameSize'];
$returnItems = $info->$DB->getNumberRows();
if ($returnItems < $displayLimit)
$displayLimit = $returnItems;
$info->output .= "<center><B>Recent Matches</b></center><BR>n";
$info->output .= "<HR width = '80%' color = '#AAAAFF'> ";
for ($i = 0; $i < $displayLimit ; $i++)
{
$playedGame = $info->$DB->getRow();
$playedDate = date("d/M/y H:i:s", $playedGame['matchTime']);
$info->output .= "$playedDate";
$info->output .= "<BR>";
$info->output .= "<B>{$playedGame['winner']}</B> beats ";
$info->output .= "<B>{$playedGame['loser']}</B>";
$info->output .= "<HR width = '80%' color = '#AAAAFF'> ";
}
$info->output .= "</TD>";
$info->output .= "<TD WIDTH = "*" VALIGN = "TOP">";
$this->writeNews();
$info->output .= "</TD>";
$info->output .= "<TD WIDTH = "200" VALIGN = "TOP">";
$numberEntries = $CONF['mainLadderEntriesShow'] + 1;
$info->$DB->query("select name from ladder_users where rung < $numberEntries order by rung asc;");
$info->output .= "<center><B>Ladder Leaders</b></center><BR>n";
$numberRows = $info->$DB->getNumberRows();
if ($numberRows < $numberEntries)
$numberEntries = $numberRows;
for ($i = 1; $i <= $numberEntries ; $i++)
{
$leaderTuple = $info->$DB->getRow();
$info->output .= "#".$i." : ".userProfileCode($leaderTuple['name'])."<BR>n";
}
$info->output .= "</TD></TR>";
$info->output .= "</TABLE>";
}
function writeNews()
{
$info->$DB->query("select * from ladder_news order by id DESC");
$numberRows = $info->$DB->getNumberRows();
if (5 < $numberRows)
$numberRows = 5;
if ($numberRows == 0)
{
$info->output .= "There are currently no news items.<BR>";
if ($adminLevel >= 2) //add new news
{
$info->output .= "<A HREF = "index.php?action=news&code=a1&s={$info->session->sessionID} ">Add new news</a><BR>";
}
}
for ($i = 1; $i <= $numberRows ; $i++)
{
$currentTuple = $info->$DB->getRow();
$info->output .= "<font style='font-size:9pt;'>$currentTuple[title]</font>n";
$info->output .= "<p style = 'text-indent:20pt'>$currentTuple[news]</p>";
$info->output .= "<font style='font-size:7pt;'>written by <i>".userProfileCode($currentTuple['name'])."</i> at n";
$info->output .= gmdate("M d Y H:i:s", $currentTuple[newsDate
])."<BR>";
if ($adminLevel >= 2) //deleting the news
{
$info->output .= "<A HREF = "index.php?action=news&code=d&id=$currentTuple[id]&s={$info->session->sessionID} ">delete news $currentTuple[id]</a> ";
$info->output .= "<A HREF = "index.php?action=news&code=a1&s={$info->session->sessionID}">add new news</a>";
}
$info->output .= "</font>";
$info->output .= "<HR width = '90%' size = '1'>";
$info->output .= "n";
}
}
}
?>
Ten post edytował Maker3 19.06.2007, 16:03:53