4WebHelp
 FAQ  •  Search  •  User Groups  •  Forum Admins  •  Smilies List  •  Statistics  •  Rules   •  Login   •  Register
Toggle Navigation Menu

 PHP: News Script - Advice Wanted
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic
Author Message
Justin
4WebHelp Addict
4WebHelp Addict


Joined: 07 Jan 2002
Posts: 1060

PostPosted: Wed Aug 07, 2002 1:07 pm (15 years, 4 months ago) Reply with QuoteBack to Top

I've just developed a News Script that I'm happy with, the code is below, but I have one bug, when it generates the articles, if the article filename already exists, it just adds the code underneath the code for the previous article.

What Could I do so it blanks the article out when it does this, and then generates the code from a fresh page - in effect overwriting it, rather than adding it on at the bottom.

I must stress, I only want to do this for the articles themselves, not the summary pages.

The code is below

Code:

<?
        include ("template.inc");
        include ("config.php");

   $summary_template = "t_summary.html";
   $article_template = "t_article.html";
   $max_summary = 5;

   function summary_page ($subject, $date, $summary, $article_id)
   {
      global $summary_template;
           $t = new Template();
           $t->set_file("SummaryPage", $summary_template);
                $article_url = "news/".$article_id.".php";
      $date = nl2br($date);
      $summary =  nl2br($summary);   
      $t->set_var( array(
            "subject" => $subject,
            "date"    => $date,
            "summary" => $summary,
            "article_url" => $article_url
            ));
      $t->parse("Summary", "SummaryPage");
      return $t->get_var("Summary");
   }

   function main_page ($subject, $date, $summary, $article_id, $body)
   {
      global $article_template;

                $t = new Template();
                $t->set_file("ArticlePage", $article_template);
                $article_url = "news/".$article_id.".php";
                $date = nl2br($date);
                $summary =  nl2br($summary);
                $body =  nl2br($body);
                $t->set_var( array(
                                "subject" => $subject,
                                "date"    => $date,
                                "summary" => $summary,
                                "body" => $body,
                                "article_url" => $article_url
                                ));
                $t->parse("Article", "ArticlePage");
                return $t->get_var("Article");
   }

   function add_article($filename, $news)
   {

      if(file_exists($filename)){
         $fh = fopen($filename, "r");
         $old_news = fread($fh, filesize($filename));
         fclose($fh);
      }

      /* TODO: Multipage articles
         preg_match_all("<!--ARTICLE PAGE=(\d*)-->", $old_news, $matches;
      
         if( count($matches[0]) >= $max_summary){
            $oldfilename = $filename.($matches[0][0]+1);
         }
      */

      $fh = fopen($filename, "w");
      $news = stripslashes($news);
      fwrite($fh, "\n<!--ARTICLE-->\n$news $old_news");
      fclose($fh);
   }

?>

<?
   if(strcmp($subject, "")){   
      if(!(strcmp($passwd, $password))){   
         add_article("article_summary.html", summary_page($subject, $date, $summary, $article_id));
         add_article("news/$article_id.php", main_page($subject, $date, $summary, $article_id, $body));
         echo "<p> Article has been added! <p>";
      }else{
         echo "<p><b> Password is wrong! </b>";
      }
   }
?>


<form action=news.php method=post>
<table border=0>
<tr> <td> (Password): </td><td> <input type=text name=passwd size=30> </td></tr>
<tr> <td> Subject: </td><td> <input type=text name=subject size=30> </td></tr>
<tr> <td> Article ID: </td><td> <input type=text name=article_id value=<? echo date("Y_m_j_is"); ?> size=30> </td></tr>
<tr> <td> Date/Author/etc: </td><td> <textarea name=date rows=2 cols=30 wrap=soft><? echo date("M j, Y\n"); ?>Author: </textarea> </td></tr>
<tr> <td> Summary: </td><td> <textarea name=summary rows=5 cols=30 wrap=soft></textarea> </td></tr>
<tr> <td> Body: </td><td> <textarea name=body rows=15 cols=30></textarea> </td></tr>
</table>
<input type=submit name=submit value=Add>
</form>


Any Ideas?

Thanks!
OfflineView User's ProfileFind all posts by JustinSend Personal MessageSend email
Justin
4WebHelp Addict
4WebHelp Addict


Joined: 07 Jan 2002
Posts: 1060

PostPosted: Wed Aug 07, 2002 1:19 pm (15 years, 4 months ago) Reply with QuoteBack to Top

Still didn't work right

(ignore the broken images and such, it's just in a testing area)

http://beta.bluesweb.co.uk/news/testing123.php
OfflineView User's ProfileFind all posts by JustinSend Personal MessageSend email
fareen
Junior WebHelper
Junior WebHelper


Joined: 14 Jul 2005
Posts: 1

PostPosted: Thu Jul 14, 2005 2:29 pm (12 years, 5 months ago) Reply with QuoteBack to Top

Hi all,

I've a problem which I hope anyone of you experts out there can render your expertise to help me provide a solution.I'm a newbie....so pls excuse my ignorance.

<tr> <td> Body: </td><td> <textarea name=body rows=15 cols=30></textarea> </td></tr>

Instead of this above <textarea> i used this table.
<table>
<tr><td><input></td><td><input></td><td><input></td><td><input></td><td><input></td></tr>
<tr><td><input></td><td><input></td><td><input></td><td><input></td><td><input></td></tr>
<tr><td><input></td><td><input></td><td><input></td><td><input></td><td><input></td></tr>
<tr><td><input></td><td><input></td><td><input></td><td><input></td><td><input></td></tr>
<tr><td><input></td><td><input></td><td><input></td><td><input></td><td><input></td></tr>
</table>

Every one of those input tags own unique names
...<input name="r1c1">...<input name="r1c2">...
.
.
.
...<input name="r5c5">

? Now question is that still i am unable to add the value inputted by me.
Will some please tell how to do this?
Thanking in advance.
OfflineView User's ProfileFind all posts by fareenSend Personal Message
Display posts from previous:      
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic


 Jump to:   




You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot edit your posts in this forum.
You cannot delete your posts in this forum.
You cannot vote in polls in this forum.


Page generation time: 0.063143 seconds :: 17 queries executed :: All Times are GMT
Powered by phpBB 2.0 © 2001, 2002 phpBB Group :: Based on an FI Theme