Class to implement custom designs – Custom – defined in the file includes/custom.php.
This class allows you to connect a file from the current theme, if there is one. In addition, the class provides a partial customization, which allows webmasters to make their revision from the file that it modifies.
void init ([string $name = '']) – Обнуляет внутрений кэш класса.
Example:
// initiation class Custom immediately after the connection
include_once ABSOLUTE_PATH.'includes/custom.php';
Custom::init();
array names () – Возвращаяет названия примененных тем.
void inc (string $path) – Подключает PHP-файл.
Example:
// include file includes/sms.php or file
// custom/my_theme/includes/sms.php if it exists
// and theme is current
Custom::inc('includes/sms.php');
boolean exists (string $path_to_file) – Проверяет существует ли файл.
Example:
if(Custom::exists('includes/sms.php'))
{
echo 'ok';
}
else
{
echo 'fail';
}
// output ok if file exsists in general file store or in current theme
string path (string $path_to_file) – Возвращает путь до файла.
Example:
echo Custom::path('includes/sms.php');
// output:
// custom/my_theme/includes/sms.php if it file exists
// and theme my_theme is current
// or includes/sms.php otherwise
// change to Custom::inc('includes/sms.php');
// if necessary, to the variables in the file are available
// in the file context in which there is a connection
include_once(Custom::path('includes/sms.php'));
array read_dir (string $path) – Читает директорию.
Example:
// read folder modules in general file store and add
// files and folders from current theme
$rows = Custom::read_dir('modules');
print_r($rows);
/* выведет:
Array
(
[0] => ab
[1] => admin
[2] => attachments
...
[45] => wishlist
)
*/
Partial customization allows you to make completion of the file that changed. To do this, all the improvements must be placed in the file of the same name, but with the suffix .custom.
Example:
For the file modules/news/news.model.php customized file is modules/news/news.model.custom.php.
In a partial customization file, you can override the classes, properties and functions of the classes. You can also add code to the beginning or the end.
To do this, customize file defines a class with the same original name. The class defines the properties and functions.
Properties can have the following prefixes:
Functions can have the following prefixes:
Example:
Modifying the file modules/users/users.inc.php. To do this, create the file modules/users/users.inc.custom.php as follows:
class Users_inc extends Model
{
// make public property of the class and ask him to default
replace public $user = NULL;
// add new property
new public $age;
// add code to the beginning of the function set()
before public function set ($user)
{
$current_user_id = $user->id;
}
// override function logout()
replace public function logout ()
{
return true;
}
// add code to the end of the function _log()
after private function _log()
{
$_SESSION["user_log"] = true;
}
// add new function check()
new private function check()
{
$_SESSION["check"] = true;
}
}
A new file is generated and written into the cache. Connect the file from the cache at the same speed as a normal PHP-file, so the customization does not affect the generation rate of the page. The file is generated each time, if included in the development mode site settings.
If your site uses multiple applied in the order of connection of the partial customization file with the date of the connection. That is, first in the main file is superimposed partial customization file from the first application threads. Then, the generated image is superimposed partial customization file from the second application threads. Thus, when prefixes after and before can be used in two subjects and the code will be considered from both themes. And prefix replace from last apply theme to replace the code, cutting changes from the previous ones.