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ć?

  1. <?php
  2. /*  
  3.  * v0.2
  4.  *
  5.  */
  6.  
  7.  
  8. $main = new mainPage;
  9.  
  10. class mainPage {
  11. function mainPage() {
  12. global $info;
  13. global $CONF;
  14.  
  15. $info->session->processActivity("test");
  16.  
  17. $info->output .= "<Table width = "100%" cellspacing = "12">n";
  18. $info->output .= "<TR><TD WIDTH = "200" VALIGN = "top">n";
  19. $info->output .= "<center><B>Ladder Statistics</b></center><BR>n";
  20.  
  21. //games played 
  22. $info->$DB->query("select count(*) from ladder_games;");
  23. $row = $info->$DB->getRow();
  24. $info->output .= $row['count(*)'] . " games played!<BR>n";
  25.  
  26. //users
  27. $info->$DB->query("select count(*) from ladder_users;");
  28. $row = $info->$DB->getRow();
  29. $info->output .= $row['count(*)'] . " users registerd!<BR>n";
  30.  
  31. //recent games
  32. $info->output .= "<BR>";
  33. $info->$DB->query("select winner, loser, matchTime from ladder_games order by matchTime desc;");
  34. $displayLimit = $CONF['recentGameSize'];
  35. $returnItems = $info->$DB->getNumberRows();
  36.  
  37. if ($returnItems < $displayLimit)
  38. $displayLimit = $returnItems;
  39.  
  40. $info->output .= "<center><B>Recent Matches</b></center><BR>n";
  41. $info->output .= "<HR width = '80%' color = '#AAAAFF'> ";
  42. for ($i = 0; $i < $displayLimit ; $i++)
  43. {
  44. $playedGame = $info->$DB->getRow();
  45. $playedDate = date("d/M/y H:i:s", $playedGame['matchTime']);
  46.  
  47.  
  48. $info->output .= "$playedDate";
  49. $info->output .= "<BR>";
  50. $info->output .= "<B>{$playedGame['winner']}</B> beats ";
  51. $info->output .= "<B>{$playedGame['loser']}</B>";
  52. $info->output .= "<HR width = '80%' color = '#AAAAFF'> ";
  53. }
  54.  
  55.  
  56.  
  57. $info->output .= "</TD>";
  58. $info->output .= "<TD WIDTH = "*" VALIGN = "TOP">";
  59. $this->writeNews();
  60. $info->output .= "</TD>";
  61.  
  62. $info->output .= "<TD WIDTH = "200" VALIGN = "TOP">";
  63.  
  64. $numberEntries = $CONF['mainLadderEntriesShow'] + 1;
  65.  
  66. $info->$DB->query("select name from ladder_users where rung < $numberEntries order by rung asc;");
  67.  
  68. $info->output .= "<center><B>Ladder Leaders</b></center><BR>n";
  69. $numberRows = $info->$DB->getNumberRows();
  70. if ($numberRows < $numberEntries)
  71. $numberEntries = $numberRows;
  72. for ($i = 1; $i <= $numberEntries ; $i++)
  73. {
  74. $leaderTuple = $info->$DB->getRow();
  75. $info->output .= "#".$i." : ".userProfileCode($leaderTuple['name'])."<BR>n";
  76.  
  77. }
  78. $info->output .= "</TD></TR>";
  79. $info->output .= "</TABLE>";
  80. }
  81.  
  82.  
  83. function writeNews()
  84. {
  85. global $output;
  86. global $info;
  87. global $adminLevel;
  88.  
  89. $info->$DB->query("select * from ladder_news order by id DESC");
  90. $numberRows = $info->$DB->getNumberRows();
  91. if (< $numberRows)
  92. $numberRows = 5;
  93.  
  94. if ($numberRows == 0)
  95. {
  96. $info->output .= "There are currently no news items.<BR>";
  97. if ($adminLevel >= 2) //add new news
  98. {
  99. $info->output .= "<A HREF = "index.php?action=news&code=a1&s={$info->session->sessionID} ">Add new news</a><BR>";
  100. }
  101. }
  102.  
  103. for ($i = 1; $i <= $numberRows ; $i++)
  104. {
  105. $currentTuple = $info->$DB->getRow();
  106. $info->output .= "<font style='font-size:9pt;'>$currentTuple[title]</font>n";
  107. $info->output .= "<p style = 'text-indent:20pt'>$currentTuple[news]</p>";
  108. $info->output .= "<font style='font-size:7pt;'>written by <i>".userProfileCode($currentTuple['name'])."</i> at n";
  109. $info->output .= gmdate("M d Y H:i:s", $currentTuple[newsDate])."<BR>";
  110.  
  111. if ($adminLevel >= 2) //deleting the news
  112. {
  113. $info->output .= "<A HREF = "index.php?action=news&code=d&id=$currentTuple[id]&s={$info->session->sessionID} ">delete news $currentTuple[id]</a> ";
  114. $info->output .= "<A HREF = "index.php?action=news&code=a1&s={$info->session->sessionID}">add new news</a>";
  115.  
  116. }
  117. $info->output .= "</font>";
  118. $info->output .= "<HR width = '90%' size = '1'>";
  119. $info->output .= "n";
  120. }
  121. }
  122. }
  123. ?>