Search
in english whole site
»
Home·Programming·CSE CMS·How To·Handle dynamic contentdeutsch·english·français
Contact & CommentsMinimizeHigherLower
» Visitor's comments
» Contact
StatisticsMinimizeHigherLower
» Hits: 13669  (details)
» Distinct visits: 6578 (1.2 Hit/visit)
» Bots visits: 5789 (Hits: 42.4%)
» Your hits in this session: 1
UserEnlargeHigherLower
Handle dynamic content
This CMS is very simple to use to display "static" pages of information, and picture galleries.

However, how to display dynamic elements, such as a form and the associated programs to treat the form results? The solution is: plug-in. The principle is simple: you write a function (which must be in php or have a php wrapper) for your custom content, and you inform similarly as with the links or embedded files the CMS that you target a plug-in.

Of course, there are several rules, explained below on the example of a plug-in to let your name on the site called Let_Your_Name.

You create a folder named Let_Your_Name within the existing plugin folder at the root of your domain. Your main functions must reside in a file named index.php within this folder. You can use this folder to store other php, html, picture or any file you need. You can even create sub-folders with write rights.

In our example:
mysite.com/plugin/Let_Your_Name/ -- plug folder
mysite.com/plugin/Let_Your_Name/index.php -- main file
mysite.com/plugin/Let_Your_Name/settings.php -- advised: file containing the translations
mysite.com/plugin/Let_Your_Name/pict.gif -- a logo picture, for example
mysite.com/plugin/Let_Your_Name/data/ -- a folder with write access for apache
mysite.com/plugin/Let_Your_Name/data/names.txt -- the file where you will store the names

The file index.php must contain at least the following functions:
Let_Your_Name_title($lan)
Let_Your_Name_content($lan)
Note that the function manes contain the name of the plug-in also, i.e. you add _title or _content to your plugin name simply. The first function will be called when the CMS requires a title for the page of the plug-in; the second will be called when the CMS requires the content of the page. Both function recieve as input parameter only $lan, the 2-character language code which the user is using. You can ignore it and your plug-in will be available only in the language you write it in.

Return a string from your function and the CMS will place it at the correct location. Do not output directly anything! At this point not even the headers have been sent out!

In order to tell to the CMS that a given link leads to a plug-in, you proceed the same way as for e.g. embedded pages: The basic method is to add a file with the extension .plug at the location where the link should be placed.
Within this file, give a string with the following structure:
text=introductory text to display.&name=Name of the plug-in

For example, put in the appropriate location a file Leave_me_your_name.plug and with the following content:
text=Dear visitor, leave your name and we will contact you when there is something new!&name=Let_Your_Name

Et voila!

How does this help you with dynamic content? Well you can do what you want in your php function, and you can in particular create a form. Your code may begin to check whether a particular $_GET variable is set. If no, display your form (which will set said variable); if yes, that means the form has been submitted and extract data and do what is needed.

Of course, your program does not know that he is actually within a larger framework, so there is one more rule: you must use only the action method GET. How to define your action? Easy:
$output = "<form action='http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/".$lan."/CSE_plugin' method=GET>";
$output .= "<input type=hidden name=name value=Let_Your_Name>";
           // this is mandatory so that the CMS knows which plug-in to call.
... // other form elements
$output .= "</form>";
return $output;

So an example of plug-in would be (very basic! no validation or anything):

function Let_Your_Name_title($lan) {
	return "Let your name";
}

function Let_Your_Name_content($lan) {
	if (isset($_GET["LYR"])) {
		// form is submitted
		$data = file_get_contents(dirname(__FILE__)."/data/CSE_name_list");
		$data .= $_GET["LYR_name"];
		$ok = file_put_contents(dirname(__FILE__)."/data/names.txt", $data, LOCK_EX);
		return "Thanks for letting your name, ".$_GET["LYR_name"];
	} else {
		// has to display the form
		$output = "<form action='http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
		$output .= "/".$lan."/CSE_plugin' method=GET>";
		$output .= "<input type=hidden name=name value=Let_Your_Name>";
			// this is mandatory so that the CMS knows which plug-in to call.
		$output .= "Your name: <input type=text value='' name=LYR_name><br>";
		$output .= "<input type=hidden name=LYR value=true>";
		$output .= "<input type=submit value='Let Your Name!'>";
		$output .= "</form>";
		return $output;
	}
}

Made with CSE_CMS, © CSE, 2008-2017