Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Adding content blocks to a static website

by blindluke (Hermit)
on Sep 06, 2011 at 09:29 UTC ( #924340=perlquestion: print w/replies, xml ) Need Help??

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

Enlightened Monks!

Every now and then, I have to add several news items to a static website. It's not a difficult task, but, as I have nothing to do with the website in question, I'd like to provide a tool for the users to publish content by themselves.

The content to be published is fairly simple:

<div class="news"> <h2>Something important</h2> <p>Something important happened again, and we're proud to announce + it.</p> <h4>Added by: John Doe, 01-01-1970</h4> </div>

The tool I had in mind is a Perl/Tk app, with four form fields: for the title, content, author and date. After the user fills in the blanks, and submits the data, some simple data validation would be performed. If the data is OK, the webpage will be downloaded from the server, and edited in place.

Some marker at the top of the news item list ( <!-- PLACE CONTENT BELOW -->) would indicate the place to put new items, and would be replaced upon edit (by the same marker and the added news item). After the edit, the page would be uploaded to the server with Net::FTP.

I seek Perl Wisdom regarding the following questions:

  • Does the whole thing make sense? Or are there some tools you would recommend instead? I found something called Unify, which seems very non-intrusive and simple, but using a tool like this would require some additional work (the hosting site does not allow PHP, so the service would have to be upgraded), and only the news items are updated (almost five years, no other requests). But maybe the benefits are worth it.
  • What could I use for validation? Will HTML::Strip be enough?
  • Is the method OK (page download, in-place edit, upload)?
  • What else should I be aware of?

All suggestions will be welcome.

Luke Jefferson

Replies are listed 'Best First'.
Re: Adding content blocks to a static website
by moritz (Cardinal) on Sep 06, 2011 at 09:42 UTC

    Another approach is to use server side includes. Instead of a <!-- PLACE CONTENT BELOW --> marker, you use <!--#include virtual="/your/newsfile.html" --> and place all the new content in $documentroot/your/newsfile.html. See the Apache SSI HowTo for more information.

    That way the user just has to edit and upload one file.

    If you'd rather stick with the placeholder approach, I'd recommend to either not do an in-place edit (create a modfiied copy), or mark both the start and end of the edit section.

    For validation, HTML::StripScripts has a pretty good reputation (though I haven't used it myself).

    What else should I be aware of?

    Security. As always.

    If you stick to the editing approach, you should be aware that it relies on uploading the whole HTML file. That means the user is able to replace it fully if he is malicious (maybe by extracting the server credentials from your script). It depends on your usage scenario if this is anactual problem.

      Thank you. In my usage scenario, I can assume that the users aren't malicious (but they could do some harm, as they aren't very tech-savvy). But the server side includes approach you suggested looks far better than my initial aproach. This way, I can just add content at the beginning of the file, and the users cannot break the layout, even if they submit an empty page.

      If I'll have to code my own tool for this, I'll post the code in CUfP.

      Again, thank you for your suggestions.

      Luke Jefferson

        With enough monkeys banging on keyboards, cluelessness can be worse than maliciousness sometimes...

Re: Adding content blocks to a static website
by ww (Archbishop) on Sep 06, 2011 at 10:13 UTC

    Second (and third, fourth....) moritz' recommendation. Some so-called experts -- those with more concern for being "in style" with a fad than with functionality -- frown at server side includes as "obsolete" or "outdated." But SSI seems to me to be an optimal answer to your question.

    OTOH, I'm not sure I understand your situation. There seems to be a contradiction in your description:

    "I have to add several news items to a static website. ...I have nothing to do with the website..."


      Yes, SSI was a great suggestion, and moritz's recommendation was very helpful.

      As to your question, a few years ago I was doing some volunteer work for a local community centre for the blind & visually impaired. It was more 'fun' than work, I helped with some things like cleaning up the place, preparing some meetings. I also lost a lot of games playing checkers (based on my experience, blind people are like shaolin kung-fu masters when it comes to checkers). It was a great time, the people were amazing, and if I hadn't changed my address, I would gladly lose some more games, eating cookies to ease the pain of defeat.

      I did a simple website back then, some 5 pages with the contact info, and a "What's New" page. The centre has another website, it's updated regularly (it's part of some larger page for all similar centres). Unfortunately, it does not work well with software that reads the page contents aloud (navigation is too complex, the reader starts with some useless items that are located near the top of the page's source, and so on). So I made a simple page, with only the basic information, I made sure it's easily browseable with the monitor turned off, and it seems that it is useful, at least for some people. Since then, every month or two, I receive an email, and I add an item to the news page.

      Luke Jefferson

Re: Adding content blocks to a static website
by JavaFan (Canon) on Sep 06, 2011 at 09:34 UTC
    A content management system is one of the things everyone has to invent for themselves instead of using any of the gazillion systems out there, isn't it?

    Assuming you're doing this as part of your job, can you justify to your boss spending the time developing your own CMS instead of using something that's already available?

      I'm not doing this as a part of my job. And I'm not even considering developing "my own CMS". If you look into my post, you will see that the task is limited. I don't like to reinvent wheels, but I don't want to use a lawn mower, where simple scissors would do.

      If you know about anything that's already available, that won't require modifications to the existing site, and will work with a host that does not support Perl / PHP / other, I will be very grateful for some suggestions. I already mentioned Unify, but this solution requires PHP support, and, although I'd be willing to pay for the software out of my own pocket, I'm not paying the annual hosting cost, and I must consider that the site owner won't like any upgrades.

      Luke Jefferson

        And I'm not even considering developing "my own CMS".
        Well, maybe you should. At least, think of it as an aready existing wheel: what you want is a CMS. So think of it how a CMS would fix this.

        What you should do is consider the "static" page as a template. What you fill into the template is variable content. It can be page blocks: a postprocessed (so you're sure it is valid HTML, for example) version of what the user created.

        There are CMS-ish systems on CPAN where you can produce static HTML pages out of user content. You should check those out. For example: Blosxom:

        Blosxom can operate as a CGI script or produce static HTML files.
Re: Adding content blocks to a static website
by luis.roca (Deacon) on Sep 06, 2011 at 14:49 UTC

    For one part of one page wouldn't it be worth it to spend an hour with someone there at 'the computer station' and teach them how to use a simple FTP client? It's not a pretty solution but you could just keep a backup of their site and save a template of the HTML file on their desktop with a short printed guide taped to the desk.

    I've had to do similar things with clients/friends in the past and, if you do it right, at most will get a follow up phone call the first time they do it on their own.

    "...the adversities born of well-placed thoughts should be considered mercies rather than misfortunes." Don Quixote
Re: Adding content blocks to a static website
by xyzzy (Pilgrim) on Sep 06, 2011 at 16:13 UTC

    If you don't trust your users to use proper tags for formatting and markup (and you shouldn't), a really good tool is Text::Markup. It has fairly simple and straightforward syntax, and it will make things like links a lot easier for your users than having to write out anchor tags. Also you won't have to worry so much about unclosed <b>s and <i>s messing up your whole page

    $,=qq.\n.;print q.\/\/____\/.,q./\ \ / / \\.,q.    /_/__.,q..
    Happy, sober, smart: pick two.
Re: Adding content blocks to a static website
by sundialsvc4 (Abbot) on Sep 06, 2011 at 17:14 UTC

    All things being considered here, I would suggest that you employ something like HTML::FormFu to let you quickly generate a simple CRUD (Create/Read/Update/Delete) functionality for a simple table of “included text.”   Provide such niceities as a start/end date, an active/inactive flag, and so on, as well as a text-box into which text can be entered using some familiar markup system, e.g. [b]...[/b] to represent Boldface and so-on.   “Just like a blog would do it.”   Any HTML-tag content would be stripped out, if you consider that to be a relevant issue.   (If you trust ’em ... and you well might then, if they mess up their own bed, they’re the ones who have to lie in it.)

    Then, build a template on the server-side which defines how all such items will be displayed.   The front-page code (or what have you...) SELECTs the content in question, and displays it, using the template.   (If you are using Template::Toolkit, you can simply use a stock “filter” to sanitize the content.)   In this way, you are maintaining full control over how the text will be presented.   (You can, if you like, offer a drop-down list of template choices that they can choose from.)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://924340]
Approved by moritz
Front-paged by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2021-05-15 07:47 GMT
Find Nodes?
    Voting Booth?
    Perl 7 will be out ...

    Results (150 votes). Check out past polls.