General principles of partial customization, see Customization. We look at an example, based on the file includes/core.php.
When you add images in the news, articles, etc. file names are generated based on the name of the element in which the preservation takes place. At the same time, they are automatically converted to latin characters using the method translit()
. Default space is replaced by a hyphen. Suppose that we are faced with the need to change the space to an underscore and give all the characters to the line meant.
Create new file includes/core.custom.php and add new methods to it.
Example:
abstract class Core
{
replace public function translit ($text)
{
$ru = array('а', 'б', 'в', 'г', 'д', 'е', 'ё', 'ж', 'з', 'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч', 'ш', 'щ', 'ы', 'э', 'ю', 'я', 'А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ё', 'Ж', 'З', 'И', 'Й', 'К', 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ', 'Ы', 'Э', 'Ю', 'Я', ' ');
$tr = array('a', 'b', 'v', 'g', 'd', 'e', 'yo', 'zh', 'z', 'i', 'y', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'f', 'kh', 'ts', 'ch', 'sh', 'sch', 'y', 'e', 'yu', 'ya', 'A', 'B', 'V', 'G', 'D', 'E', 'YO', 'ZH', 'Z', 'I', 'Y', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'U', 'F', 'KH', 'TS', 'CH', 'SH', 'SCH', 'Y', 'E', 'YU', 'YA', '_');
$text = str_replace($ru, $tr, $text);
$text = $this->prepare_translit($text);
return $text;
}
new private function prepare_translit ($text)
{
$text = strtolower($text);
return $text;
}
}
Here we should pay attention to the word replace in front of the access modifier method public. It tells the system that this method already exists in the source file, but its use is not necessary. Every time you access the original translit()
will be triggered translit()
from the file includes/core.custom.php.
Prefix new allows you to add a new method to an existing class, which we did in the example prepare_translit()
.
Aside from the new techniques and can create new properties of the class. We do this with the variables $ru
and $tr
.
Example:
abstract class
Core
{
new private $ru = array('а', 'б', 'в', 'г', 'д', 'е', 'ё', 'ж', 'з', 'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч', 'ш', 'щ', 'ы', 'э', 'ю', 'я', 'А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ё', 'Ж', 'З', 'И', 'Й', 'К', 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ', 'Ы', 'Э', 'Ю', 'Я', ' ');
new private $tr = array('a', 'b', 'v', 'g', 'd', 'e', 'yo', 'zh', 'z', 'i', 'y', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'f', 'kh', 'ts', 'ch', 'sh', 'sch', 'y', 'e', 'yu', 'ya', 'A', 'B', 'V', 'G', 'D', 'E', 'YO', 'ZH', 'Z', 'I', 'Y', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'U', 'F', 'KH', 'TS', 'CH', 'SH', 'SCH', 'Y', 'E', 'YU', 'YA', '_');
replace public function translit ($text)
{
$text = str_replace($this->ru, $this->tr, $text);
return $text;
}
}
In addition to new and replace, there are also before and after, allowing to extend the method and add the necessary code to the beginning or end, respectively. They are used similarly to the above example.