Pomoc - Szukaj - U¿ytkownicy - Kalendarz
Pe³na wersja: Jak wy¶wietliæ ;(
Forum PHP.pl > Forum > PHP
ADeM
Jak wy¶wietliæ ilo¶æ komentarzy z tego kodu na innej stronie?

  1. <?php
  2. //If member access level is commenter, redirect him to personal options
  3. if($member_db[1] == 4 and $action == &#092;"dologin\"){ header(\"Location: $config_http_script_dir/index.php?mod=options&action=personal\"); exit; }
  4.  
  5.  
  6. echoheader(&#092;"home\", \"Welcome\");
  7.  
  8. if(!is_readable(&#092;"./data/archives\")){ die(\"Error !!!<br />Can not open directory ./archives for reading, check if it exists or is properly CHMOD'ed\"); }
  9. if(!is_readable(&#092;"./data/news.txt\")){ die(\"Error !!!<br />Can not open file news.txt for reading, check if it exists or is properly CH
  10. OD'ed\"); }
  11. if(!is_readable(\"./data/comments.txt\")){ die(\"Error !!!<br />Can not open file comments.txt for reading, check if it exists or is properl
  12.  CHMOD'ed\"); }
  13.  
  14.  
  15. // Some Stats
  16. $todaynews = 0;
  17. $count_comments = 0;
  18. $count_my_news = 0;
  19. $count_new_news = 0;
  20. $news_db = file(\"./data/news.txt\");
  21.  foreach ($news_db as $line)
  22.  {
  23. $item_db = explode(\"|\",$line);
  24. $itemdate = date(\"d/m/y\",$item_db[0]);
  25. if($itemdate == date(\"d/m/y\")) {
  26. $todaynews++;
  27. if($item_db[1] == $member_db[2]) $count_my_news++;
  28. if(($item_db[0] > $member_db[9]) and ($member_db[9] != '')) $count_new_news++;
  29. }
  30.  }
  31. $stats_news = count( $news_db );
  32. $stats_users = count( file(\"./data/users.db.php\") ) - 1;
  33. $stats_archives = 0;
  34. $handle = opendir(\"./data/archives\");
  35. while (FALSE !== ($file = readdir($handle)))
  36. {
  37. if( preg_match(\"/.news.arch/\",$file) ){$stats_archives++;}
  38. }
  39. closedir($handle);
  40. $stats_news_size = formatsize(filesize(\"./data/news.txt\"));
  41. $stats_comments_size = formatsize(filesize(\"./data/comments.txt\"));
  42.  
  43. // Count Comments
  44. $all_comments = file(\"./data/comments.txt\");
  45. foreach($all_comments as $news_comments){
  46. $single_news_comments = explode(\"|>|\", $news_comments);
  47. $individual_comments = explode(\"||\", $single_news_comments[1]);
  48. $count_comments += count($individual_comments) - 1;
  49. }
  50. // Define Welcome Message
  51. echo\"<table border=0 cellpading=0 cellspacing=0 width=654>
  52. <td width=650 colspan=5 height=1>
  53. &nbsp;
  54.  
  55. <script LANGUAGE=&#092;"JavaScript\">
  56. <!-- Begin
  57. datetoday = new Date();
  58. timenow=datetoday.getTime();
  59. datetoday.setTime(timenow);
  60. thehour = datetoday.getHours();
  61. if  (thehour < 9 )  display = &#092;"Morning\";
  62. else if (thehour < 12)  display = &#092;"Day\";
  63. else if (thehour < 17)  display = &#092;"Afternoon\";
  64. else if (thehour < 20)  display = &#092;"Evening\";
  65. else display = &#092;"Night\";
  66. var greeting = (&#092;"Good \" + display);
  67. document.write(greeting);
  68. // End -->
  69. </script>
  70.  
  71.  $member_db[2]\";
  72.  
  73. if($todaynews != 1){ $s = \"s\"; }
  74. if($member_db[1] != 4){
  75. if($stats_users > 1){
  76. $rand_msg[] = \", we have <b>$count_new_news</b> new articles since your last login\";
  77. $rand_msg[] = \", we have <b>$count_new_news</b> new articles since your last login\";
  78. $rand_msg[] = \", we have <b>$count_new_news</b> new articles since your last login\";
  79. }
  80. if($todaynews == 0){
  81. $rand_msg[] = \", we don't have new articles today\";
  82. $rand_msg[] = \", we don't have new articles today, the first one can be yours.\";
  83. }
  84. elseif($count_my_news == 0){
  85. if($todaynews == 1){
  86. $rand_msg[] = \", today we have <b>$todaynews</b> new article{$s} but it is not yours\";
  87. }else{
  88. $rand_msg[] = \", today we have <b>$todaynews</b> new article{$s} but <b>$count_my_news</b> of them are yours\";
  89. }
  90. }
  91. elseif($count_my_news == $todaynews){
  92. if($count_my_news == 1){
  93. $rand_msg[] = \", today we have <b>$todaynews</b> new article{$s} and you wrote it\";
  94. }else{
  95. $rand_msg[] = \", today we have <b>$todaynews</b> new article{$s} and you wrote all of them\";
  96. $rand_msg[] = \", today we have <b>$todaynews</b> new article{$s} and all are yours\";
  97. $rand_msg[] = \", today we have <b>$todaynews</b> new article{$s}, want to <a href=\"$PHP_SELF?mod=addnews&action=addnews\">add</a> some more?\";
  98. }
  99. }
  100. else{
  101. if($count_my_news == 1){ $rand_msg[] = \", today we have <b>$todaynews</b> new article{$s}, <b>1</b> of them is yours\"; }
  102. else{ $rand_msg[] = \", today we have <b>$todaynews</b> new article{$s}, <b>$count_my_news</b> of them are yours\"; }
  103. }
  104. $rand_msg[] = \", are you in a mood of <a href=\"$PHP_SELF?mod=addnews&action=addnews\">adding</a> some news?\";
  105. $rand_msg[] = \", today we have <b>$todaynews</b> new article{$s}, from total <b>$stats_news</b>\";
  106. if($member_db[9] != \"\"){
  107. $rand_msg[] = \", your last login was on \".date(\"j M Y H:i:s\", $member_db[9]);
  108. $rand_msg[] = \", your last login was on \".date(\"d M Y H:i:s\", $member_db[9]);
  109. }
  110.  
  111. $rand_msg[] = \"\";
  112.  
  113. srand((double) microtime() * 1000000);
  114. echo $rand_msg[rand(0, count($rand_msg)-1)].\"<br /><br />\";
  115. }
  116.  
  117. if($member_db[1] == 1){
  118. echo \"<tr><td valign=middle height=1 bgcolor=#F7F6F4 width=286 colspan=2>
  119. &nbsp;<b>Some stats</b>
  120. <td valign=middle height=1 width=35>
  121. <td valign=middle height=1 bgcolor=#F7F6F4 width=326 colspan=2>
  122. &nbsp;<b>System SelfCheck</b>
  123. </tr>
  124.  
  125. <tr>
  126. <td valign=middle height=1 width=137>
  127. &nbsp; Active News
  128. <td valign=middle height=1 width=146>
  129. $stats_news
  130. <td valign=middle height=1 width=37>
  131. <td valign=middle height=1 width=201>
  132. &nbsp; Can write to news.txt
  133. <td valign=middle height=1 width=121>\";
  134.  
  135. if(is_writable(\"./data/news.txt\")){ echo \"<font color=green>Yes</font>\"; }
  136. else{ echo \"<font color=red>No</font>\"; }
  137.  
  138. echo\"</tr>
  139. <tr>
  140. <td valign=middle height=1 width=137>
  141. &nbsp; Active Comments
  142. <td valign=middle height=1 width=146>
  143. $count_comments
  144. <td valign=middle height=1 width=37>
  145. <td valign=middle height=1 width=201>
  146. &nbsp; Can write to comments.txt
  147. <td valign=middle height=1 width=121>\";
  148.  
  149. if(is_writable(\"./data/comments.txt\")){ echo \"<font color=green>Yes</font>\"; }
  150. else{ echo \"<font color=red>No</font>\"; }
  151.  
  152. echo\"</tr>
  153. <tr>
  154. <td width=137 valign=middle height=1>
  155. &nbsp; Archives
  156. <td width=146 valign=middle height=1>
  157. $stats_archives
  158. <td width=37 valign=middle height=1>
  159. <td width=201 valign=middle height=1>
  160. &nbsp; Can write to users.db.php
  161. <td width=121 valign=middle height=1>\";
  162.  
  163. if(is_writable(\"./data/users.db.php\")){ echo \"<font color=green>Yes</font>\"; }
  164. else{ echo \"<font color=red>No</font>\"; }
  165.  
  166. echo\"</tr>
  167. <tr>
  168. <td width=137 valign=middle height=1>
  169. &nbsp; Users
  170. <td width=146 valign=middle height=1>
  171. $stats_users
  172. <td width=37 valign=middle height=1>
  173. <td width=201 valign=middle height=1>
  174. &nbsp; Can write to archives dir
  175. <td width=121 valign=middle height=1>\";
  176.  
  177. if(is_writable(\"./data/archives\")){ echo \"<font color=green>Yes</font>\"; }
  178. else{ echo \"<font color=red>No</font>\"; }
  179.  
  180. echo\"</tr>
  181. <tr>
  182. <td width=137 valign=middle height=1>
  183. &nbsp; News.txt Size
  184. <td width=146 valign=middle height=1>
  185. $stats_news_size
  186. <td width=37 valign=middle height=1>
  187. <td width=201 valign=middle height=1>
  188. <td width=121 valign=middle height=1>
  189. </tr>
  190.  
  191. <tr>
  192. <td width=137 valign=middle height=1>
  193. &nbsp; Comments.txt Size
  194. <td width=146 valign=middle height=1>
  195. $stats_comments_size
  196. <td width=37 valign=middle height=1>
  197. <td width=201 valign=middle height=1>
  198. &nbsp;
  199. <td width=121 valign=middle height=1>
  200. </tr>
  201. \";
  202. }
  203. echo\"</table>\";
  204.  
  205. echofooter();
  206. ?>
crash
Z tego co chyba widze i jesli rozumiem o co Ci chodzi to ilosc newsow wyswietlonych za pomoca tego skryptu bedzie wynosic:
  1. <?php
  2. $ile = $count_my_news + $count_new_news;
  3. ?>

A jesli to nie to, to przy kazdej iteracji petli wyswietlajacej poszczegolne newsy inkrementuj jakas zmienna i ta zmienna bedzie zawierac liczbe newsow.

Hmmm chwile... A moze chodzi Ci o to ile komentarzy znajduje sie w tym skrypcie blink.gif

Na wszelki wypadek:
  1. <?php
  2.  
  3. // jesli kod skryptu jest w pliku ten_skrypt.php
  4. $f = @fopen('./ten_skrypt.php', 'r');
  5.  
  6. $komentarzy = 0;
  7.  
  8. while(!feof($f))
  9. {
  10.     $linia = fgets($f);
  11.  
  12.     if(ereg('//|#', $linia)) // przy zalozeniu, ze sa tylko komentarze jednoliniowe
  13.     {
  14.         $komentarzy++;
  15.     }
  16. }
  17. fclose($f);
  18.  
  19. echo $komentarzy;
  20. ?>
ADeM
Mi chodzi³o o komentarze... Ale z tamtego kodu.. ju¿ sobie poradzi³em jakby kto¶ chcia³ to to jest (to wy¶wietlanie ilo¶ci komentarzy ze skryptu CuteNews) kod:
  1. <?php
  2. $count_comments = 0;
  3. $all_comments = file(&#092;"./data/comments.txt\");
  4. foreach($all_comments as $news_comments){
  5. $single_news_comments = explode(&#092;"|>|\", $news_comments);
  6. $individual_comments = explode(&#092;"||\", $single_news_comments[1]);
  7. $count_comments += count($individual_comments) - 1;
  8. }
  9. ?>
To jest wersja lo-fi g³ównej zawarto¶ci. Aby zobaczyæ pe³n± wersjê z wiêksz± zawarto¶ci±, obrazkami i formatowaniem proszê kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.