Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Wyświetlenie 3 ostatnich "news`ow"
fraksipon
post
Post #1





Grupa: Zarejestrowani
Postów: 79
Pomógł: 0
Dołączył: 18.12.2005

Ostrzeżenie: (0%)
-----


Cześć,
Czy ktoś potrafiłby dla mnie wyciągnąc z tego skryptu aktualności możliwość wyświetlenia np: tylko 3 ostatnich wpisów?
Prosze o napisania kodu.

  1. <?php
  2.  
  3.  
  4. require 'config.php';
  5.  
  6. function VerifyTxtFile(){
  7. if(!is_dir("content")) mkdir("content", "0777", true);
  8. if(!file_exists("content/news.txt")) {
  9. $file = fopen("content/coments.txt", "w");
  10. fwrite($file, "");
  11. fclose($file);
  12. }
  13. return true;
  14. }
  15.  
  16.  
  17. function ReadNews(){
  18. VerifyTxtFile();
  19. $fh = fopen("content/news.txt", 'r');
  20. $theData = fgets($fh);
  21. fclose($fh);
  22. return ExplodeNews($theData);
  23. }
  24.  
  25. function ExplodeNews($NewsArray){
  26. $list = array(array());
  27. if($NewsArray == "") return 0;
  28. $Coments = explode("<X-_-X>", $NewsArray);
  29. for($i=0; $i!=sizeof($Coments)-1; $i++){
  30. $Coment = explode("<XXX_>", $Coments[$i]);
  31. $list[$i]['title'] = $Coment[0];
  32. $list[$i]['date'] = $Coment[1];
  33. $list[$i]['resumo'] = $Coment[2];
  34. }
  35. return $list;
  36. }
  37.  
  38. function FindNew($id_new){
  39. VerifyTxtFile();
  40. $fh = fopen("content/news.txt", 'r');
  41. $theData = fgets($fh);
  42. fclose($fh);
  43. $new = array();
  44. $Coments = explode("<X-_-X>", $theData);
  45.  
  46. if($id_new < sizeof($Coments)-1 and $id_new >= 0){
  47.  
  48. $Coment = explode("<XXX_>", $Coments[$id_new]);
  49. $new['title'] = $Coment[0];
  50. $new['date'] = $Coment[1];
  51. $new['completo'] = $Coment[3];
  52. if($Coment[4] != ""){
  53. $new['image'] = $Coment[4];
  54. $new['align'] = $Coment[5];
  55. }
  56.  
  57. }else{
  58. return 0;
  59.  
  60. }
  61.  
  62. return $new;
  63. }
  64.  
  65. ?>
  66. <link rel="stylesheet" type="text/css" href="images/style.css" />
  67. <?php
  68.  
  69. if(isset($_GET['view'])){
  70. $new_c = FindNew($_GET['id']);
  71. if($new_c != 0){
  72. echo "<table width=\"100%\" border=\"0\">
  73. <tr>
  74. <td height=\"20\"><strong><p class=\"NewsTitle\">".$new_c['title']."</p></strong></td>
  75. </tr>
  76. <tr>
  77. <td height=\"20\" class=\"NewsBody\"><strong>".$new_c['date']."</strong></td>
  78. </tr>
  79. <tr>";
  80.  
  81. if(isset($new_c['image'])){
  82. $size = RedimensionaImagem("images/".$new_c['image']);
  83. echo "<td><img style=\"margin-left: 5px; margin-right: 5px;\" src=\"images/".$new_c['image']."\" align=\"".$new_c['align']."\" width=\"".$size['largura']."\" height=\"".$size['altura']."\" class=\"images\" ><span class=\"NewsBody\">".$new_c['completo']."</span></td>";
  84. }else
  85. echo "<td><span class=\"NewsBody\">".$new_c['completo']."</span></td>";
  86.  
  87. echo "</tr>
  88. </table>
  89. <p>&nbsp;</p>";
  90.  
  91. }else{
  92. echo "ERROR, no new found with id ".$_GET['id'];
  93. }
  94.  
  95.  
  96. }else{
  97. echo "<table width=\"100%\" border=\"0\"><tr> <td valign=\"top\">";
  98.  
  99. $all_news = ReadNews();
  100.  
  101. if($all_news != 0){
  102. for($i = sizeof($all_news)-1; $i >= 0; $i--){
  103. echo "<table width=\"100%\" border=\"0\" align=\"center\">
  104. <tr>
  105. <td height=\"15\" class=\"NewsTitle\"><strong><a href=\"?view&id=".$i."\">".$all_news[$i]['title']."</a></strong></td>
  106. </tr>
  107. <tr>
  108. <td height=\"15\" class=\"NewsBody\"><strong>".$all_news[$i]['date']."</strong></td>
  109. </tr>
  110. <tr>
  111. <td class=\"NewsBody\">".$all_news[$i]['resumo']."</td>
  112. </tr>
  113. </table><p>&nbsp;</p>";
  114. }
  115.  
  116. }else{
  117.  
  118. echo "No news yet";
  119.  
  120. }
  121. echo "</td></tr></table>";
  122. }
  123.  
  124. function RedimensionaImagem($imagem){
  125. if(is_file($imagem)){
  126. $size = getimagesize($imagem);
  127. $height = $size[1];
  128. $width = $size[0];
  129. $tamanho = array();
  130.  
  131. if ($height > __MAXHEIGHT)
  132. {
  133. $height = __MAXHEIGHT;
  134. $percent = ($size[1] / $height);
  135. $width = ($size[0] / $percent);
  136. }
  137. else if ($width > __MAXWIDTH)
  138. {
  139. $width = __MAXWIDTH;
  140. $percent = ($size[0] / $width);
  141. $height = ($size[1] / $percent);
  142. }
  143.  
  144. $tamanho['largura'] = (int) $width;
  145. $tamanho['altura'] = (int) $height;
  146. }
  147. return $tamanho;
  148. }
  149.  
  150. ?>
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 22.08.2025 - 00:04