You are here: start » cmsimple_scripting

CMSimple Scripting

CMSimple scripting was introduced to CMSimple to enable the user to have extensive control over CMSimple's behaviour for every single page he wishes. It is still possible to use CMSimple scripting with CMSimple_XH, but for it's typical use cases CMSimple_XH offers alternative features that are simpler to grasp. In the following the possibilities of CMSimple scripting and CMSimple_XH's alternatives are explained.

CMSimple scripting is by default bracketed in

#CMSimple ... #

This could be changed under Settings ⇒ CMS (CMSimple_XH < 1.5: Edit configuration) ⇒ Scripting ⇒ Regexp. But it is strongly recommended to leave this setting as it is, as individual Regexps are hardly tested.

Since CMSimple_XH 1.6 this configuration option has been removed.

Only up to one CMSimple script might be written to each page, with the exception of #CMSimple hide#. If you need more than one CMSimple script, you have to put them all into one CMSimple scripting bracket, e.g.

#CMSimple $description='description'; $keywords='keywords'; #

It doesn't matter where you put the CMSimple scripts on your page, but be careful to insert them in the HTML source code view of your WYSIWYG editor.

The alternative CMSimple_XH features do not count as separate CMSimple scripts.

Page Parameters

Above the editor's toolbar you'll find several tabs. You can open them to inspect and modify their settings by clicking on the tab. The tab for the page paramaters is simply called Page.

⇑ top

Alternative Heading

To change the heading of the page without altering it's title in the TOC, you could use CMSimple scripting:

#CMSimple $output=preg_replace('/(<h[1-3]>).*?(<\/h[1-3]>)/i', '\\1New heading\\2', $output);#

This will change the heading of the page to 'New heading'.

With CMSimple_XH it is possible to open the Page tab, select 'Alternative heading'→yes and enter the new heading to the input field. Don't forget to press the save button to confirm your changes.

⇑ top

Published

To completely remove a page, i.e. make it unaccessible from normal mode, you could use CMSimple scripting, but the code to do so is intentionally not given here, because this CMSimple scripting caused several problems.

The page can be accessed when you're in edit mode only. This could be useful, if you want to prepare a page which is not ready to be presented to your visitors.

With CMSimple_XH it is possible to open the Page tab and select 'Published?'→yes. Don't forget to press the save button to confirm your changes.

⇑ top

Show in Menu

To hide a page from the TOC, you could use CMSimple scripting:

#CMSimple hide#

The page can be accessed by typing it's address into the browsers address bar directly, but is not accessible from the TOC. This could be useful for e.g. a news page, which should not be shown as a seperate page, but presented in a newsbox.

With CMSimple_XH it is possible to open the Page tab and select 'Show in menu?'→yes. Don't forget to press the save button to confirm your changes.

⇑ top

Page Template

To choose a different template than the default for a page, you could use CMSimple scripting:

#CMSimple $cf['site']['template']="MyTemplate"; $pth['folder']['template']=$pth['folder']['templates'].$cf['site']['template'].'/';$pth['file']['template']=$pth['folder']['template'].'template.htm';$pth['file']['stylesheet']=$pth['folder']['template'].'stylesheet.css';$pth['folder']['menubuttons']=$pth['folder']['template'].'menu/';$pth['folder']['templateimages']=$pth['folder']['template'].'images/'; #

This will display the page with the template 'MyTemplate'.

With CMSimple_XH it is possible to open the Page tab and select from one of the installed templates under 'Page template'. Don't forget to press the save button to confirm your changes.

⇑ top

Show last Edit

To display the last update of the page, you could use CMSimple scripting:

#CMSimple $output.=lastupdate(); #

This will display the time of the page's last update on the bottom of the page.

With CMSimple_XH it is possible to open the Page tab and select 'Show last edit?'→yes. Don't forget to press the save button to confirm your changes.

⇑ top

Redirect Page

To redirect a visitor to another page of your CMSimple installation, you could use CMSimple scripting:

#CMSimple header('Location:index.php?TargetPage'); #

If a visitor visits the page, he will be redirected to page 'TargetPage'. If you want to edit the page, you have to switch to edit mode first, before navigating to the page. Otherwise you'll be redirected too.

With CMSimple_XH it is possible to open the Page tab, select 'Redirect page?'→yes and enter the query string for the page, e.g. ?TargetPage. Don't forget to press the save button to confirm your changes.

⇑ top

Meta Tags

Above the editor's toolbar you'll find several tabs. You can open them to inspect and modify their settings by clicking on the tab. The tab for the meta tags is simply called Meta.

⇑ top

Title

To change the title of the page, you could use CMSimple scripting:

#CMSimple $cf['site']['title']='My Title'; #

The title is displayed in the browser's title bar or as label of the tab. It is always extended by the page's heading.

With CMSimple_XH it is possible to open the Meta tab and enter the title in the 'Title' input field. Don't forget to press the save button to confirm your changes.

⇑ top

Description

To change the meta description of the page, you could use CMSimple scripting:

#CMSimple $description='This is a page!'; #

The meta description is primarily intended for search engines. They might use the description for display of the search result.

With CMSimple_XH it is possible to open the Meta tab and enter the meta description in the 'Description' input field. Don't forget to press the save button to confirm your changes.

⇑ top

Keywords

To change the meta keywords of the page, you could use CMSimple scripting:

#CMSimple $keywords='Keyword1, Keyword2, Keyword3'; #

The meta keywords are primarily intended for search engines. They might use the keywords to categorize the page for later search requests.

With CMSimple_XH it is possible to open the Meta tab and enter the meta keywords in the 'Keywords' input field. Don't forget to press the save button to confirm your changes.

⇑ top

Robots

To change the meta robots of the page, you could use CMSimple scripting:

#CMSimple $cf['meta']['robots']='noindex,nofollow'; #

The meta robots are primarily intended for search engines. They should respect the given settings.

With CMSimple_XH it is possible to open the Meta tab and enter the meta robots in the 'Robots' input field. Don't forget to press the save button to confirm your changes.

⇑ top

General CMSimple scripting

You might already have noticed, that CMSimple scripting doesn't make use of an own scripting language, such as Typoscript. This was done intentionally, so a user already acquainted to PHP doesn't have to learn a new scripting language, and to give him the full power of PHP opposed to a tiny subset. By having access to the full CMSimple framework, there are only few limitations to what can be done with CMSimple scripting. But this flexibility has it's price. Sometimes it's hard to understand what a complex CMSimple script does, and it's even harder to know how to do something particular with CMSimple scripting. So in the following some examples of CMSimple scripting are given.

Note that outputting code by calling echo or print does not work as expected. Instead all output should be written to $output. This variable contains the contents of the page when the script is executed, so usually you'll want to append your output to $output.

If you are an experienced PHP coder, you might have a look at the System Core Documentation where variables and functions of CMSimple are listed. Several of them might be useful for advanced usage of CMSimple scripting.

If you need the power of CMSimple scripting, but want to avoid the irritating scripts in the page's content, you should have a look at pd_scripting. This plugin allows you to enter the desired script calls in an own tab above the editor's toolbar.

⇑ top

To change the submenu heading of the page, you could use CMSimple scripting:

#CMSimple $tx['submenu']['heading']="My Submenu Heading";#

This changes the submenu heading to 'My Submenu Heading'. The submenu heading is displayed at the bottom of a page as heading for the list of it's subpages.

⇑ top

Inserting a File's Content

To insert the content of another file into the page, you could use CMSimple scripting:

#CMSimple $t="my.file";if($fh=fopen($t,"r")){$output=preg_replace("/".chr(35)."CMSimple.*".chr(35)."/",fread($fh, filesize($t)),$c[$s]);fclose($fh);} #

This will insert the content of my.file into the page, replacing the content you entered in the editor. You have to take care for yourself, that the file contains valid (X)HTML code, to be exact only a subset of what might be used in <body>…</body>, and that it is enclosed in a single tag, e.g. <div>…</div>.

It is recommended to avoid this CMSimple scripting, but to insert the file's content directly into the page with the editor.

⇑ top

Inserting an external web page's content

If you want to insert the content of an external web page, you could use CMSimple scripting:

#CMSimple $output.=geturl('http://www.external.site/external.page');#

This will insert the external pages content, i.e. everything inside <body>…</body> at the end of your page. It is mandatory that allow_url_fopen is enabled on your server.

It is strongly recommended to avoid this CMSimple scripting for the following reasons:

  • it's quite likely, that for security reasons allow_url_fopen is disabled on your server
  • the external site won't be displayed as intended by it's authors, because the <head> information is ignored

Instead it is recommend to use Wrapper, which allows you to insert the contents of an external page in an iframe.

But be aware of legal issues: if you do not have express permission of the owner of the external website to include the page into your website, it is better to just put a link to the external page.

⇑ top

The Plugin Call

Having said so much about CMSimple Scripting, I recommend to avoid it whenever possible. It's hard to read and write in the WYSIWYG editors, and due to the use of $output it's somewhat counter-intuitive.

Instead use the so called plugin call:

{{{PLUGIN:name_of_the_function(parameters);}}}

This will output the return value of name_of_the_function() exactly in the place where it's written in the page. It is primarily intented to insert the output of a plugin, e.g. a gallery, therefore the token PLUGIN. But you can call any other proper PHP function with it.

Since CMSimple_XH 1.6 the token PLUGIN is not required anymore1), so you can simply write:

{{{name_of_the_function(parameters);}}}

Since CMSimple_XH 1.6.5 additionally the semicolon at the end and the parentheses are optional, so you can write:

{{{name_of_the_function parameters}}}

If there doesn't exist a single function that you can call, just define it in userfuncs.php. This file will be included by CMSimple_XH, so all functions defined there are available for use on the page.

This way complex scripting won't clutter your content, and couldn't be damaged by accident when you edit your pages.

If you want to display the result of an arbitrary PHP expression, you can use PHP's trim() function and give the expression as parameter, e.g.:

{{{trim(83 * 17 + 42);}}}

⇑ top

1)
Actually, anything in front of the first colon is treated as a comment, so you can use remarks for yourself or your customers, e.g.:
{{{DON'T CHANGE THIS LINE:plugin('...');}}}
 
You are here: start » cmsimple_scripting
Except where otherwise noted, content on this wiki is licensed under the following license: GNU Free Documentation License 1.3
Valid XHTML 1.0 Valid CSS Driven by DokuWiki