Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Creating new HTML files and accessing them later.

by bladx (Chaplain)
on Aug 11, 2001 at 03:20 UTC ( [id://104079]=perlquestion: print w/replies, xml ) Need Help??

bladx has asked for the wisdom of the Perl Monks concerning the following question:

Ok,

I have been working on a short term web project that is by no means finished yet, but is being developed slowly at a time. I have a question that I can't seem to figure out, I have no clue where to search in the pod's or perl docs at for this type of situation, and have been working (*worrying*) for about a week now trying to figure out how to program this part of the project.

Here is the main question: I have a CGI site made with Perl, and what it does is display various items like news, announcements, links to other sites, a user post board, etc. (similar to news sites such as slashdot, etc.)

This question has two main parts that need to fit together:
  1. I would like to be able for a person setting up this site to be able to add extra pages to the site, since people usually want to see more sections, such as (contact us, etc.) How would I do this?
  2. Next, I would like the main part of the program (that runs the rest of the files needed for the site,) to be able to search a folder where those new pages would be, and know what there is to pick from for if a user wanted to visit a new page. How would I do this?


I have no clue what to do for this type of situation, since I haven't programmed many CGI's. Does anyone know of any good methods I could try for these abstract questions? Or what man page would help, if there is one that is specific to this type of problem.

Andy Summers
  • Comment on Creating new HTML files and accessing them later.

Replies are listed 'Best First'.
Re: Creating new HTML files and accessing them later.
by thatguy (Parson) on Aug 11, 2001 at 04:03 UTC
    I've written something similar to what you are suggesting for my own site (linked from my homenode).

    I used flatfiles for the first version and I am currently in the process of switching over to a mySQL setup. If at all possibile, I would suggest using a database of some kind. This would allow you so much more flexability down the road and perhaps some performance boosts too but that depends on the traffic really.

    With either a database or a flatfile arrangement, a single perl script that handles the html (much like the index.pl here) would make changes to the look of the site and maintance *much* easier and quicker.

    As for new sections, in a sql enviroment you could have a column that states the type of page like comment, story, userid etc and dump data into that. If you use flatfiles, then I would just put the data (the meat, not the whole page) in a file in a directory that only new stories go in or use a proprietary extention.

    you really should look at HTML::Template and CGI. HTML::Template would make it easier for a non-perl person to maintain the html and CGI just makes CGI easy. there is a HTML::Template tutorial here and Lincoln Stein's tutorials here.

    The most important thing to do is to plan out where things are going to be and how they will look to the user and stick with that. I made it an everchanging process as I went and it took forever because the changes I made meant a re-write of the code.

    Good luck and feel free to msg me if you like.
    -p

Re: Creating new HTML files and accessing them later.
by tadman (Prior) on Aug 11, 2001 at 03:39 UTC
    The Quick-and-Dirty way to do this is to write a CGI script that can edit files, even if they don't exist. So, what you have is a big <TEXTAREA> tag with your file inside it, and you edit, and you submit, not unlike Perl Monks. With CGI.pm, this is really quite easy, so I won't take all the fun out of it by posting the little program here.

    The procedure is:
    1. Determine which file is going to be edited, based on the command-line parameter.
    2. Open the appropriate file, if it exists, and read in the contents. Don't die if you can't, just ignore it, as they are starting on a "new" file.
    3. Fix the content so that it works with the TEXTAREA box.
    4. Return a FORM which will SUBMIT to the proper "save" script.
    The "save" script just takes whatever it is given and dumps it into the appropriate file, so make sure to give them a "Cancel" button which does nothing dangerous.

    You will also likely need a "directory" script which shows you all the files that can be edited, where the links point to the edit script keyed with that file as the parameter. To edit a "new" file, put in an INPUT box where they can type in the name.

    To make everything jive with the TEXTAREA tag, you have to make sure that it's all HTML-savvy, which means doing something to the "dangerous" stuff on the way in:
    s/&/&amp;/g; s/</&lt;/g; s/>/&gt;/g;
    Then you can pile it back in your file when you're finished. Provided the script has access to the files it is trying to edit and write to, you're golden.

    Warning:
    Be aware that you must secure this script properly, or you are opening yourself up to a world of hurt. Make sure that you use something like 'htpasswd' at the very least, and SSL (i.e. Apache-SSL) if you are able to do that.

    I've done this before, and it's an easy way for users to "upload" new pages by doing something as simple as cut-and-paste from their HTML editor.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://104079]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2024-04-25 05:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found