Difference between revisions of "Static Pages Plugin"

From GeeklogWiki
Jump to: navigation, search
(Template Static Pages)
(Accessing Geeklog Variables and Logic Processing)
 
(6 intermediate revisions by the same user not shown)
Line 128: Line 128:
  
 
The second thing you need to do now is, create a page that will use your new template Static Page. To do this, create a new Static Page. Once you are in the Static Page editor you then need to select your new template from the "Use Template" option. Once selected, you can then enter your template variable information into the content section of the editor. This information is XML and needs to be formatted properly and include the correct attributes and tags like the sample below:
 
The second thing you need to do now is, create a page that will use your new template Static Page. To do this, create a new Static Page. Once you are in the Static Page editor you then need to select your new template from the "Use Template" option. Once selected, you can then enter your template variable information into the content section of the editor. This information is XML and needs to be formatted properly and include the correct attributes and tags like the sample below:
 +
 +
NOTE: These examples have been updated for use with Geeklog 2.1.3. As of Geeklog 2.1.3 curly brackets are automatically used to surround variable names in the templates. With Geeklog 2.1.2 and lower the variable name required the use of {curly brackets}. So Geeklog v2.1.2 and lower the staticpage which uses a template must have variable names like (with {curley_brackets}):
  
 
<pre>
 
<pre>
Line 142: Line 144:
 
</page>
 
</page>
 
</pre>
 
</pre>
 +
 +
Geeklog v2.1.3 and later the curly brackets are not needed around the variable names. For example:
 +
 +
<pre>
 +
<page>
 +
<variable name="tpl_var1">
 +
    <data>Test Variable Data 1</data>
 +
</variable>
 +
<variable name="tpl_var2">
 +
    <data>Test Variable Data 2</data>
 +
</variable>
 +
<variable name="tpl_var3">
 +
    <data>True</data>
 +
</variable>
 +
</page>
 +
</pre>
 +
  
 
You should have the same number of variables here, as in your template Static Page. Each of the name attributes of the variable tag should be one of the template variables from the template Static Page.  Any information you want to appear would go between the data tags.  If this information contains other tags (like HTML) then you need to wrap it in CDATA so it will not be parsed. Here is an example of how to use CDATA:
 
You should have the same number of variables here, as in your template Static Page. Each of the name attributes of the variable tag should be one of the template variables from the template Static Page.  Any information you want to appear would go between the data tags.  If this information contains other tags (like HTML) then you need to wrap it in CDATA so it will not be parsed. Here is an example of how to use CDATA:
  
 
<pre>
 
<pre>
<variable name="{tpl_var1}">
+
<variable name="tpl_var1">
 
     <data><![CDATA[
 
     <data><![CDATA[
 
<p>Test Variable Data 1</p>
 
<p>Test Variable Data 1</p>
Line 155: Line 174:
 
Most functions of the Static Page editor are available to this page with the exception of allowing PHP to be used and Post Mode.  Your "Post Mode" option should be set as "HTML Formatted". If there is an error in your XML this could throw a PHP error when you attempt to view the page. You also need to make sure that this page and the template Static Page have the same permissions. If the user can view this page and not the template Static Page assigned to it then the page will not display properly.
 
Most functions of the Static Page editor are available to this page with the exception of allowing PHP to be used and Post Mode.  Your "Post Mode" option should be set as "HTML Formatted". If there is an error in your XML this could throw a PHP error when you attempt to view the page. You also need to make sure that this page and the template Static Page have the same permissions. If the user can view this page and not the template Static Page assigned to it then the page will not display properly.
  
As of Geeklog v2.1.3 and Static Page Plugin v1.6.9 the staticpage template feature has improved. Instead of the Staticpage plugin itself replacing template variables and autotags it has now handed over this funcitionaly for the most part to the [[Caching_Template_Library |Geeklog Caching Template Class]]. This means that Staticpage template pages can now use many features of the template class including access to [[Caching_Template_Library#TEMPLATE_OPTIONS |default variables]] like {anonymous_user} and {device_mobile}. It also means that [[Caching_Template_Library#Logic_Processing_2 |Logic Processing]] can now be used! This means you can include If and else statements, Loops, and also include PHP code in Staticpage Template Pages. So for example in a staticpage template you can now display content depending on a variable like {device_mobile) or another variable that has been defined in your Staticpage (like {tpl_var3} from the sample above):
+
=== Accessing Geeklog Variables and Logic Processing ===
 +
 
 +
As of Geeklog v2.1.3 and Static Page Plugin v1.6.9 the staticpage template feature has improved. Instead of the Staticpage plugin itself replacing template variables and autotags it has now handed over this funcitionaly for the most part to the [[Caching_Template_Library |Geeklog Caching Template Class]]. This means that template Static page can now use many features of the template class including access to [[Caching_Template_Library#TEMPLATE_OPTIONS |default variables]] like {anonymous_user} and {device_mobile}. Plus [[Caching_Template_Library#Automatic_Language_File_Variables |Lanaguage File Variables]]. It also means that [[Caching_Template_Library#Logic_Processing_2 |Logic Processing]] can now be used! This means you can include If and Else statements, Loops, and also include PHP code in Staticpage Template Pages. So for example in a template Staticpage you can now display content depending on a variable like {device_mobile) or another variable that has been defined in your Staticpage (like {tpl_var3} from the sample above).
 +
 
 +
As of Geeklog 2.2.1 the Static Pages plugin also adds its own addition default template variables. There are 3: the static page title (sp_title}, created date (sp_created), and last modified date {sp_modified}. All dates returned by these template variables are ISO 8601 dates.
  
 
<pre>
 
<pre>
Line 171: Line 194:
 
<p>test_variable contains a 0, is empty, or does not exist.</p>
 
<p>test_variable contains a 0, is empty, or does not exist.</p>
 
{!endif}
 
{!endif}
 +
 +
<p>This is a test to access a language variable: {$LANG_DB_BACKUP[database_admin]}</p>
 +
 +
<p>This is a test to access the Staticpage title: {sp_title}</p>
 
</pre>
 
</pre>
  

Latest revision as of 21:51, 26 November 2018

What is it?

The Static Pages plugin was originally aimed at creating pages with static content (as opposed to the dynamic pages created by Geeklog) - hence the name. Pages like an "about us" page, a mission statement, etc. would come to mind.

Since then, people have used the static pages for all kinds of things and with the inclusion of PHP into static pages, even the original name isn't quite right any more ... History

The plugin was originally written by Tony Bibbs and is included with Geeklog as a pre-installed plugin since Geeklog 1.3.5. An extended version of the plugin was started by Phill Gillespie and later supported by Tom Willet. The extended version was the first to allow the use of PHP in static pages and also supported proper Geeklog permissions.

With Geeklog 1.3.8 and Static Pages 1.3, these two versions were merged again. Static Pages 1.3 also introduced some new features that were not included in either of its predecessors. Features

  • supports use of PHP
  • editable page ID to make more readable URLs
  • Static pages can be displayed on Geeklog's index and topic pages and can even replace it entirely ("splash screen")
  • "cloning" of existing pages
  • Makes use of Geeklog's URL rewrite feature
  • Supports autolinks and provides a [staticpage:] autotag
  • proper support for Geeklog permissions


Use of PHP

Activating PHP

Important: For security reasons, the use of PHP in static pages is disabled by default.

To enable it, you will have to grant the 'staticpages.PHP' permission to the "Static Page Admin" group. To do this, log in as the Admin and from the Admin's Only block, select "Groups". Find the "Static Page Admin" group and edit it by clicking on the name of the group. At the bottom of the page, you will find a list of "Rights" (permissions) that can be granted to all members of this group. Note that 'staticpages.delete' and 'staticpages.edit' are checked, while 'staticpages.PHP' is not checked. To allow members of the Static Page Admin group to use PHP in static pages, you will have to check the 'staticpages.PHP' checkbox and save your changes.

In addition to the 'staticpages.PHP' permission discussed above, there is also a global flag, $_SP_CONF['allow_php'], that can be used to disable the use of PHP in static pages entirely. When set to 0, it will override the 'staticpages.PHP' permission and disable all use of PHP in static pages. The flag is located in the static pages' config.php file in the plugins/staticpages directory. Usage

The use of PHP in static pages may result in security issues if not used properly. Use this feature with care!

The use of PHP has to be enabled for each individual static page. Below the content edit field, you will find a drop-down menu with the following options:

  • do not execute PHP

Obivously, when you select this option, any PHP code in the static page will not be executed but will instead be printed out as-is.

  • execute PHP (return)

If you select this option, PHP code in static pages will be executed. The 'return' indicates that the code should return any output it generates, using a PHP return statement, instead of printing it out directly. This is the PHP option as introduced with the Static Pages plugin 1.3.

  • execute PHP

Again, this option will enable execution of PHP. Only this time, the PHP code can actually use echo and print statements without having the output interfere with the page layout.

Please note that when embedding PHP code in a static page, your code should not be enclosed in the PHP <?php and ?> tags. Instead, it is assumed that the static page contains the PHP code that would normally go between those two tags.

When selecting the second of the above PHP execution options ("execute PHP") you can, however, switch back and forth between PHP and plain HTML like this:

echo "Hello"; ?>, <b>world</b>, <?php echo "how are you?";

The above example would print out "Hello, world, how are you?".


Page ID

When creating a new static page, it will be assigned a page ID automatically. This ID consists of the date and time and up to three random digits. When you anticipate that the URL of this page may be used a lot, e.g. quoted in emails, it may make sense to use a more readable ID for the page.

The static pages editor will let you change the page ID. For example, you may want to rename the ID for your "about" page from "20030313100131123" to "about", thus creating a URL like

http://www.example.com/staticpages/index.php?page=about

which looks much nicer when quoted (and is easier to remember). You could further improve this by making use of Geeklog's URL rewrite feature.

Please note that you should only use letters and digits for the page ID. Avoid national special characters, most punctuation characters ('-' and '.' should be okay, though) and spaces. The static page editor will catch some illegal characters but not all of them ...


Using Static Pages on the index page

Geeklog 1.3.8 introduced a new concept for use by plugins, called Center Blocks. Basically, this means that any plugin can place blocks in the center area of a Geeklog site, i.e. among the stories.

When you check the "Centerblock" option for a static page, you can use the "Position" and "Topic" drop-downs to chose where this static page will be displayed. For "Position", the options are "Top Of Page", "After Featured Story", "Bottom Of Page" (which should be self-explanatory) and "Entire Page". That last option, "Entire Page", will tell Geeklog that this static page will replace the entire index page - it will not display any stories, but only the contents of this static page. This is useful e.g. for "splash" screens or Welcome pages.

Tip: When using a static page as a "splash" screen, you may need a link that takes your visitors to the normal index page, i.e. the list of current stories. To do this, create a link to index.php?display=all

The second drop-down, "Topic", lets you restrict the display of a static page to only a certain topic, the homepage only, or all pages (i.e. all topic pages and the homepage). This is the same as the options you have for blocks.

Tip: You can combine these options with the permission settings. This will let you, for example, create a "welcome" page that is only displayed to anonymous users.


Sorting

Centerblocks: When you have more than one static page that would appear in the same section of the center area (e.g. two static pages that would be displayed at the top of the index page), you can chose the order in which they appear by setting the $_SP_CONF['sort_by'] variable in the plugin's config.php file to one of id (sort by page id), date (sort by last changed date), or title (sort by page title). The default is to sort by page id.

Menu entries: It's also possible to sort the static pages that are displayed in the site's menu (if you're using a theme that uses the {plg_menu_elements} variables in its header.thtml). Set the $_SP_CONF['sort_menu_by'] variable (again, in the plugin's config.php file) to one of id (sort by page id), date (sort by last changed date), label (sort by the menu label), or title (sort by page title).


Wrapping Static Pages in a block

You can chose to have a static page wrapped in a Geeklog block by checking the "wrap static page in a block" option in the static pages editor. If selected, the page's title will be used as the block title.

The plugin's config.php file also has a flag, $_SP_CONF['in_block'], which is used as the default for this option.


Cloning Static Pages

When you have a lot of similar static pages you may want to make a copy of an existing page and then edit that copy. This can easily be done by clicking on the [C] from the list of static pages. Doing so will create a copy of that page with a new page ID.


URL rewriting

Please note that this feature is considered experimental and is known not to work with IIS.

Geeklog supports a form of URL rewriting, i.e. change the look of URLs such that they are more search engine friendly. For example, instead of

http://www.example.com/staticpages/index.php?page=20030313100131123

the URL could look like this

http://www.example.com/staticpages/index.php/20030313100131123

Some search engines are known not to index pages when the URL includes characters like '?' and '='. You could further improve the chances of this page being indexed by replacing the numeric page ID with a word or expression (preferrably something that corresponds to the page's content), e.g.

http://www.example.com/staticpages/index.php/about

To make use of URL rewriting, you will need to enable it in Geeklog's config.php file by setting

$_CONF['url_rewrite'] = true;


Template Static Pages

As of Geeklog 1.7.1, you now have the ability for a Static Page to use another Static Page as a template. What this allows you to do is create one template page and then have it be used by one or more other Static Pages as a base. This feature is ideal for people who have a number of similar formatted Static Pages. For example if you have a bunch of product pages that need to look the same but they have different titles, product image, and product description. A Static Page Template would be ideal here. You can just supply the text in one page and have it use the other for the formatting. If you ever need to change the formatting of these pages at a later date all you need to do is just update the template Static Page. To set this functionality up, you need to do a couple of things.

The first thing you must do is create a template Static Page. To do this you first need to create a Static Page. Once in the editor you need to give the page a Title and an ID. You then need to check the "Template" check box option. Once this is done, you can enter your HTML code in the content section. Where ever you have a spot where you want data from another Static Page to go, you can put a template variable there. This template variable can be any unique text you want. An example of this would be something like:

<p>Hello World!</p> <p>{tpl_var1}</p> <p>Bye World!</p> <p>{tpl_var2}</p>

Once you have assigned a static page as a template, most features in the editor are not available to you to use. This includes the Menu options, Page Format, Comments, Meta Information, Centerblock and the PHP option. Also by themselves template Static Pages will not appear in search results, Site Statistics or in the What's New Block.

The second thing you need to do now is, create a page that will use your new template Static Page. To do this, create a new Static Page. Once you are in the Static Page editor you then need to select your new template from the "Use Template" option. Once selected, you can then enter your template variable information into the content section of the editor. This information is XML and needs to be formatted properly and include the correct attributes and tags like the sample below:

NOTE: These examples have been updated for use with Geeklog 2.1.3. As of Geeklog 2.1.3 curly brackets are automatically used to surround variable names in the templates. With Geeklog 2.1.2 and lower the variable name required the use of {curly brackets}. So Geeklog v2.1.2 and lower the staticpage which uses a template must have variable names like (with {curley_brackets}):

<page>
<variable name="{tpl_var1}">
    <data>Test Variable Data 1</data>
</variable>
<variable name="{tpl_var2}">
    <data>Test Variable Data 2</data>
</variable>
<variable name="{tpl_var3}">
    <data>True</data>
</variable>
</page>

Geeklog v2.1.3 and later the curly brackets are not needed around the variable names. For example:

<page>
<variable name="tpl_var1">
    <data>Test Variable Data 1</data>
</variable>
<variable name="tpl_var2">
    <data>Test Variable Data 2</data>
</variable>
<variable name="tpl_var3">
    <data>True</data>
</variable>
</page>


You should have the same number of variables here, as in your template Static Page. Each of the name attributes of the variable tag should be one of the template variables from the template Static Page. Any information you want to appear would go between the data tags. If this information contains other tags (like HTML) then you need to wrap it in CDATA so it will not be parsed. Here is an example of how to use CDATA:

<variable name="tpl_var1">
    <data><![CDATA[
	<p>Test Variable Data 1</p>
    ]]></data>
</variable>

Most functions of the Static Page editor are available to this page with the exception of allowing PHP to be used and Post Mode. Your "Post Mode" option should be set as "HTML Formatted". If there is an error in your XML this could throw a PHP error when you attempt to view the page. You also need to make sure that this page and the template Static Page have the same permissions. If the user can view this page and not the template Static Page assigned to it then the page will not display properly.

Accessing Geeklog Variables and Logic Processing

As of Geeklog v2.1.3 and Static Page Plugin v1.6.9 the staticpage template feature has improved. Instead of the Staticpage plugin itself replacing template variables and autotags it has now handed over this funcitionaly for the most part to the Geeklog Caching Template Class. This means that template Static page can now use many features of the template class including access to default variables like {anonymous_user} and {device_mobile}. Plus Lanaguage File Variables. It also means that Logic Processing can now be used! This means you can include If and Else statements, Loops, and also include PHP code in Staticpage Template Pages. So for example in a template Staticpage you can now display content depending on a variable like {device_mobile) or another variable that has been defined in your Staticpage (like {tpl_var3} from the sample above).

As of Geeklog 2.2.1 the Static Pages plugin also adds its own addition default template variables. There are 3: the static page title (sp_title}, created date (sp_created), and last modified date {sp_modified}. All dates returned by these template variables are ISO 8601 dates.

<p>Hello World!</p> <p>{tpl_var1}</p> <p>Bye World!</p> <p>{tpl_var2}</p>

{!if device_mobile}
<p>The paragraph will only display on mobile devices.</p>
{!else}
<p>The paragraph will only display on desktop and laptops.</p>
{!endif}

{!if tpl_var3}
<p>test_variable contains a string.</p>
{!else}
<p>test_variable contains a 0, is empty, or does not exist.</p>
{!endif}

<p>This is a test to access a language variable: {$LANG_DB_BACKUP[database_admin]}</p>

<p>This is a test to access the Staticpage title: {sp_title}</p>

Deleting pages with their owner

As all objects in Geeklog, static pages have an owner (the user that created the static page). When that user's account is deleted for some reason, any static pages owned by that user can either be deleted as well or they can be assigned to another user in Geeklog's Root group. The config.php file for the Static Pages plugin has the following option:

$_SP_CONF['delete_pages'] = 0;

If set to 0 (which is the default), static pages will not be deleted with their owner, but assigned to a member of the Root group instead (the user with the lowest user ID, most likely the Admin). If you change this to 1, static pages will be deleted when their owner's account is deleted.