Static Pages

Contents

1 Usage & Settings

1.1 Documents

1.2 Settings

1.2.1 The data source of the document title

1.2.2 Force Apache mod_rewrite

1.2.3 Force login

1.2.4 Process Content

1.3 List of static pages

2 Creating static page documents

3 Styling static pages

4 Adding images to static pages

5 Add blocks to static pages

6 Apache mod_rewrite

6.1 Using mod_rewrite

6.2 Not using mod_rewrite

7 Security considerations

 

This plugin displays static information pages which exist outside any course, imprint or faq pages, for example, complete with LMS navigation and theme.

Usage & Settings

After installing the plugin, it does not do anything to LMS yet.

To configure the plugin and its behavior, please visit Site administration -> Static Pages.

There, you find multiple settings pages:

Documents

On this page, you upload the document files you want to serve as static pages. The filepicker accepts files with .html filename extensions. For each static page you want to serve, upload an HTML document, named as [pagename].html. local_staticpage then uses this filename as the page name.

Example: You upload a file named faq.html. This file will be served as a static page with the page name “faq”.

Valid filenames: Please note that not all symbols which are allowed in the filenames in the filepicker are supported/suitable for page names. Please make sure that your filenames only contain lowercase alphanumeric characters and the – (hypen) and _ (underscore) symbols. Please note that the filepicker on this settings page does not only allow you to upload .html files but also to upload .htm files due to the way the LMS filepicker is built internally. local_staticpage does its best to change the suffix of a .htm file to .html after you save the settings page.

Settings

On this page, you can configure several aspects of local_staticpage’s behavior.

The data source of the document title

By default, local_staticpage will use the first tag<h1> as document title, document heading and breadcrumb item title of the resulting static page. In this section, you can change this behavior to using the first <title> tag for each of these.

Please note that if local_staticpage doesn’t find the configured (<h1> or <title>) tag, it will derive the document title from the document filename.

Force Apache mod_rewrite

With this setting, you can configure local_staticpage to only serve static pages on a clean URL, using Apache’s mod_rewrite module. See “Apache mod_rewrite” section below for details.

Force login

With this setting, you can configure local_staticpage to only serve static pages to logged in users or also to serve static pages non-logged in visitors.

This behavior can be set specifically for static pages or can be set to respect LMS ‘s global forcelogin ($CFG->forcelogin) setting.

Process Content

In this section, you can configure if LMS filters should be processed when serving a static page’s content. You can use local_staticpage completely without multilanguage or filter support. But when you need multilanguage or filter support, you can set this setting to yes and make use in your static page files of any LMS filter which is enabled on system level.

In this section, you can also configure if the static page’s HTML code should be cleaned. If this setting is set to yes, local_staticpage will use an LMS library function to remove unclean HTML code and special tags like <iframe>. If this setting is set to no, local_staticpage will trust the HTML code in your static page’s file and will just pass it on to the browser.

List of static pages

On this page, there is a list which shows all static pages which have been uploaded into the static pages document area and their URLs.

Additionally, the page list checks each static page if a browser is actually able to download and view it. If this isn’t possible, the static page is marked with an error message in the page list.

Creating static page documents

As local_staticpage’s HTML reader (DOM parser) is quite dumb, there is a proposed structure for the html documents:

<html>
<head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Imprint</title>
</head>
<body>
        <h1>Imprint</h1>
        [Your content goes here]
</body>
</html>

Please note that the <meta> tag is necessary if you want to use UTF-8 characters in your html document, otherwise, they will become crippled when the document is parsed by local_staticpage.

Styling static pages

If you want to style your static page with CSS in any special way, you can include a <style> tag into the <head> section of your HTML document. The content of this style tag will be inserted into LMS’s HTML head.

Adding images to static pages

If you want to include images into your static page, you cannot just upload them in local_staticpage’s filepicker. You have to upload them somewhere else. local_staticpage is not capable of hosting / serving image files. Linking to image files, please do yourself a favor and link to them with absolute URLs, not relative URLs.

Add blocks to static pages

The local_staticpage plugin was not intended to show blocks on the static pages. However, it is possible. You have to enable page editing somewhere else in LMS (on your MyLMS page or on a course page, for example) and go to your static page. Now you see the standard “Add block” menu and can add blocks to the static page. Additionally, if you click on the block’s gear icon, you can control if the block is shown only on the static page the block was added to or on all static pages.

Apache mod_rewrite

 

Using mod_rewrite

local_staticpage is able to use Apache’s mod_rewrite module to provide static pages on a clean and understandable URL.

If you are running LMS in the root of your web server, please add the following to your Apache configuration or your .htaccess file in the LMS directory:

RewriteEngine On
RewriteRule ^/static/(.*)\.html$ /local/staticpage/view.php?page=$1&%{QUERY_STRING} [L]

However, in some Apache configurations the following rule will work (without the leading slash – for details, please refer to http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule):

RewriteEngine On
RewriteRule ^static/(.*)\.html$ /local/staticpage/view.php?page=$1&%{QUERY_STRING} [L]

Now, the static pages are available on http://www.yourlms.com/static/[pagename].html

If you are running LMS in a subdirectory on your web server, please add the following to your Apache configuration or your .htaccess file in the LMS directory:

RewriteEngine On
RewriteRule ^/yoursubdirectory/static/(.*)\.html$ /yoursubdirectory/local/staticpage/view.php?page=$1&%{QUERY_STRING} [L]

However, in some Apache configurations the following rule will work (without the leading slash – for details, please refer to http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule):

RewriteEngine On
RewriteRule ^yoursubdirectory/static/(.*)\.html$ /yoursubdirectory/local/staticpage/view.php?page=$1&%{QUERY_STRING} [L]

Now, the static pages are available on http://www.yourlms.com/yoursubdirectory/static/[pagename].html

You can now create links to these URLs in an LMS HTML Block, in your LMS theme footer and so on.

Not using mod_rewrite

If you don’t want or are unable to use Apache’s mod_rewrite, local_staticpage will still work.

The static pages are then available on http://www.yourlms.com/local/staticpage/view.php?page=[pagename]

These URLs aren’t as catchy as with mod_rewrite, but they work in exactly the same manner.

Please note: Here, you have to omit the “.html” extension in the page name. The URL http://www.yourlms.com/local/staticpage/view.php?page=[pagename].html won’t work. This has technical reasons as the page name parameter is cleaned to only contain alphanumeric characters and the – (hypen) and _ (underscore) symbols, but not period characters.

You can now create links to these URLs in an LMS HTML Block, in your LMS theme footer and so on.

Security considerations

Apart from the option to clean HTML code which you can set to yes, local_staticpage does NOT check the static HTML documents for any malicious code, neither for malicious HTML code which will be delivered directly to the user’s browser, nor for malicious PHP code which could break DOM parsing when processing the HTML document on the server.

Therefore, please make sure that your HTML code is well-formed and that only authorized and briefed users upload static page documents on local_staticpage’s settings page.