Perfecto CMS - Content management system
  • Русский язык
  • English version
Sign in
Create an account
PerfectoCMS Documentation
PerfectoCMS Documentation
You can find best practices on all major configuration procedures that will help you plan better your resources and environment.

API documentation

2,939 views / 16 Jan 2015 edited
Every day we improve the fundamental functions and classes, which can be used for new system’s modules and modifications writing.

Below there will be the list of necessary functions, which you can use in your modules.
It is unnecessary to connect anything, so the system’s structure allows to use API freely and automatically integrates (connects) them in new modules. For this purpose it is enough to use 4 main classes CORE, TEMPLATE, CACHE and DB, which are already caused. They are: $core, $tpl, cache and $db


	# creation of a class’s prototype
$db = new DB($server, $user, $password, $datebase);

# connection with a database

# mistake conclusion at a malfunction

# inquiry performance QUERY_STRING

# extraction of a resultant row as associative array

# receiving number of ranks in resultant selection

# receiving number of the lines affected by the previous operation MySQL/MySQLi

# memory cleanup

# get MySQL/MySQLi version

# close the DB connection
$news_query = $db->query("SELECT * FROM `news` WHERE `status`='1' ");
while ($news_array = $db->fetch_array($news_query)) {
  /*....code here....*/

Core functions

	# returns the filtered variable $var. The filter for entering variables
$core->filter( string $var );

# returns the de-filtered variable $var
$core->deFilter( string $var );

# returns the module ID
$core->module_id( $module_name );

# creates date in a format of the chosen language from an $mktime entering variable
$core->date($mktime, $type = "short", $time = false);

# returns the join categories
$core->category_join( $module_id, $cat_altname );

# returns the category’s name
$core->category_name( $join, $lang );

# transforms ID language in the title
$core->lang_name( $lang_id );

# checking an e-mail address’s correctness. Return TRUE or FALSE
$core->valid_email( $email );

# checking login’s correctness
$core->valid_nickname( $nickname );

# informational dump of variable in a readable look
$core->dump( $array );

# returns the picture if it exists, or the picture $not_found at absence $filename
$core->img_exit( $path, $filename, $not_found );

# password generation with a length of $num
$core->generate_password( $num );

# returns transliteration of $text variable
$core->translit( $text );

# converting UTF8 string to CP1251
$core->Utf8ToWin( $text );

# converting CP1251 string to UTF8
$core->WinToUtf8( $text );

# creates the reference (altname) from heading in the case of absence of the link
$core->altname( $url , $title );

# redirecting
$core->redirect( $url );

# returns real user’s IP

# generates language tabs for the specified module
$core->langTabs( $module );

# generation of the list (select) of categories starting from $ParentID
$core->MakeTree( $ParentID, $u_level );

# creating a ZIP archive from files list
$core->create_zip( $files = array(), $destination = '', $overwrite = false );

# returns the folder size (with subfolders)
$core->dirSize( $dir );

# fractal copying
$core->recurse_copy( $src, $dst );

# file download via http header
$core->download( $fullPath );

# converting XML file to array
$core->xml2array( $contents, $get_attributes=1, $priority = 'tag');

# returning JSON with cyrillic support
$core->json_encode( $str );

# returns the array variable with user information (IP, Browser, OS etc.)

# open the file $filepath, delete BOM and save
$core->RemoveBOM( $filepath )

# sendmail function is designed to generate and send high-quality mail
# $content - array containing the parameters: from, to, replyTo, subject, attach
# $admin parameter determines whether the letter addressed to the administrator or not
# $enc - message encoding. By default is utf-8
$core->sendmail($content = array(), $admin = true, $enc = 'utf-8')

# converts the phone number in international format
# $hidden parameter allows you to hide/show the last 4 digits
$core->phoneNumber($phoneNumber, $hidden = false)

# hides several characters in the email address

# image crop or resize function
$core->imageResize($from, $to, $params = array("width"=>200,"height"=>200,"crop"=>true))

Template making

	# Assign value $value to variable $name in template
$tpl->assign( $name , $value );

# Parsing of the mentioned template
$tpl->parse( $ReturnVar, $FileTags );

# Defining of the template’s file
$tpl->define( $template );

# Creation of dynamically-sized block
$tpl->define_dynamic( $Macro, $ParentName )

# Clarification of dynamically-sized block
$tpl->clear_dynamic( $Macro );

# Template’s clarification
$tpl->clear( $ReturnVar )
Example of creating a dynamic block to display news
$tpl->define_dynamic("news_list","news"); # the creation of a dynamic block news_list in news.tpl template file
$news_query = $db->query("SELECT * FROM `news` WHERE `lang`='".$language['ID']."' ");
while ($news_array = $db->fetch_array($news_query)) {
  $tpl->assign("name", $news_array['name']);
  $tpl->assign("text", $news_array['text']);
  $tpl->assign("date", $news_array['date']);
  $tpl->parse('NEWS_LIST', '.news_list'); # displey data from cycle


	# Randomizing methods: PDO | mpdo | Auto | Files | memcache | apc | wincache | xcache.
Notice: The method is already declared in the file config.php
cache::$storage = "auto";

# Caching directory
cache::$path = CACHE_DIR;

# Data setting for Memcache
cache::$server = array(array("localhost", 11211));

# Data reception from the cache named CACHE_NAME
$date = cache::get("CACHE_NAME");

# Recording the data in the cache named CACHE_NAME for 600 seconds
cache::set("CACHE_NAME", $date, 600);

# Full cleaning of a site’s cache
Caching example
$news_list = cache::get("news_list"); # get data from the cache
if($news_list == null) { # check data availability in the cache
  $news_query = $db->query("SELECT * FROM `news` WHERE `lang`='".$language['ID']."' ORDER BY `ID` DESC LIMIT 5");
  while ($news_array = $db->fetch_array($news_query)) {
    $news_list[] = news_array;
  cache::set("news_list", $news_list, 3600); # caching data from the database to 1 hour

foreach ($news_list as $news) {
  $tpl->assign("name", $news['name']);
  $tpl->assign("text", $news['text']);
  $tpl->assign("date", $news['date']);
  $tpl->parse('NEWS_LIST', '.news_list');

Data Encryption

In the file config.php declared data crypter $crypter.
You can change the encryption key in the line $crypter = new Crypter('#PROJECT-YOUR-PROJECT-KEY#');
	# returns an encrypted string $data
$crypter->encrypt( $data )

# returns the decrypted string $data_crypted
$crypter->decrypt( $data_crypted )

# creates a new encryption key
$crypter->setKey( $key )

Website design order
Unique offer for customers of Perfecto CMS.
If you want an original design let us know and we will contact you to discuss the details.
Please note
We appreciate your time and for save time, please download the blank of design order, complete it and send to our mailbox: Our email
Approximate price
600 USD

Your browser is out of date!

Please download the latest version of Internet Explorer
We recommend to use another modern browser!