Custom page creating
From Documentation of ABK-Soft Products
| Languages: |
English Русский |
Contents |
[edit] An example of creation of your own page
You can see file blank.php in !example/ folder.
You can copy it to your root directory for instance as my_page.php
It needs the file of the templater to work, which will be taken from the folder with your current template, it means if you use now space template it will look in _themes/main/space/
An example of such templater file can be also found in !example/, it is the file blank.html. You can copy it to the folder with your template under your name, like my_page.html.
In the file you have created you need to set the name of the templater, for this in the line
$page = new CPage("", $g['tmpl']['dir_tmpl_main'] . "blank.html");
you change blank.html to your file's name like my_page.html
$page = new CPage("", $g['tmpl']['dir_tmpl_main'] . "my_page.html");
[edit] Access types in the dating software
There are 3 types of pages: only for registered members (my profile editing), only for unregistered (the page of registration) and the pages for all the users, for example Search.
To make your page accessible only for registered users, you need to add the following line at the very beginning of your php file:
$area = "login";
If it will be only for unregistered:
$area = "public";
If your page is intended to be viewed by all members of your dating site, you do not need to add anything.
[edit] CLASS CPage
[edit] Method action()
This method was created for handling an action in the dating script, like adding or changing something (profile, mail sending). It's meaning is in detaching the actions with DB from the actions with templates. This is an example of the work of this method for handling an answer to a message:
function action()
{
global $g_user;
$cmd = get_param("cmd", "");
if ($cmd == "reply") {
DB::query("SELECT u.user_id AS user_from, u2.user_id AS user_to,
m.id, m.subject, m.text
FROM ((mail_msg AS m LEFT JOIN user AS u ON u.user_id=m.user_from)
LEFT JOIN user AS u2 ON u2.user_id=m.user_to)
WHERE m.id=" . to_sql(get_param("msg", ""), 'Number') . "");
if ($row = DB::fetch_row()) {
$this->id = $row['user_from'] != $g_user['user_id'] ? $row['user_from'] : $row['user_to'];
$this->subject = "Re: " . $row['subject'];
$this->text = "> " . str_replace("\n", "\n > ", $row['text']);
}
}
}
[edit] Method parseBlock(&$html)
This is a method for the template parsing. You can use the following functions for actions with the template of the dating or community software:
- $html->setvar("var", "value"); - to change {var} in the template to the value
- $html->parse("block", true); - parses the block, that os the block becomes visible and all vars are processed, which were declared BEFORE the call of this function (later you can change the {var} and again parse the block with NEW vars, you can use it in a loop).
- $html->parse("subblock", false); - it parses the block, but when called for the second time the previous parsed block is replaced by the following, and not parsed several times like in the previous case.
[edit] Templates of the dating software
The variables in the templates look as {variable}
The blocks in templates look as <!-- begin_block -->SOME HTML<!-- end_block -->
There are predefined variables in the templates
- {url_main} - site url without the page name
- {url_page} - site url with the page name
- {url_main_tmpl} - the path to the folder with templates, this can be useful if you put pictures and java scripts into this folder and then write only {url_main_tmpl}js/lib.js
[edit] Languages of the dating software
The phrases are all in the file _lang/main/default/language.php In the template of the dating software it will be automatically replaced by {l_array_key_in_the_lang_file} The array $l['all'] - is for the phrases that are present on several pages of the dating software. The arrays like $l['index.php'] - will be parsed only on one page of the dating script index.php
[edit] Class handling
The class is run so:
$page = new CPage("", $g['tmpl']['dir_tmpl_main'] . "blank.html");
where blank.html - the name of the templater for this page.
Then we attach header and footer to this page:
$header = new CHeader("header", $g['tmpl']['dir_tmpl_main'] . "_header.html");
$page->add($header);
$footer = new CFooter("footer", $g['tmpl']['dir_tmpl_main'] . "_footer.html");
$page->add($footer);
Here we run the handlers for the templater files _header.html and _footer.html, {header} and {footer} will be replace by the code in blank.html