128 lines
3.8 KiB
PHP
128 lines
3.8 KiB
PHP
|
|
<?php
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* Основной класс Simpla для доступа к API Simpla
|
|||
|
|
*
|
|||
|
|
* @copyright 2011 Denis Pikusov
|
|||
|
|
* @link http://simplacms.ru
|
|||
|
|
* @author Denis Pikusov
|
|||
|
|
*
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
// include $_SERVER['DOCUMENT_ROOT'].'/api/claviska/SimpleImage.php';
|
|||
|
|
|
|||
|
|
require_once $_SERVER['DOCUMENT_ROOT'].'/lib/Img.php';
|
|||
|
|
|
|||
|
|
class Simpla
|
|||
|
|
{
|
|||
|
|
// Свойства - Классы API
|
|||
|
|
private $classes = array(
|
|||
|
|
//'articles_categories' => 'ArticlesCategories',
|
|||
|
|
'articles' => 'Articles',
|
|||
|
|
//'article' => 'Article',
|
|||
|
|
'banners' => 'Banners',
|
|||
|
|
'config' => 'Config',
|
|||
|
|
'request' => 'Request',
|
|||
|
|
'db' => 'Database',
|
|||
|
|
'settings' => 'Settings',
|
|||
|
|
'design' => 'Design',
|
|||
|
|
'products' => 'Products',
|
|||
|
|
'variants' => 'Variants',
|
|||
|
|
'categories' => 'Categories',
|
|||
|
|
'brands' => 'Brands',
|
|||
|
|
'features' => 'Features',
|
|||
|
|
'money' => 'Money',
|
|||
|
|
'pages' => 'Pages',
|
|||
|
|
'blog' => 'Blog',
|
|||
|
|
'actions' => 'Actions',
|
|||
|
|
'shares' => 'Shares',
|
|||
|
|
'cart' => 'Cart',
|
|||
|
|
'image' => 'Image',
|
|||
|
|
'delivery' => 'Delivery',
|
|||
|
|
'payment' => 'Payment',
|
|||
|
|
'orders' => 'Orders',
|
|||
|
|
'preorders' => 'Preorders',
|
|||
|
|
'users' => 'Users',
|
|||
|
|
'coupons' => 'Coupons',
|
|||
|
|
'comments' => 'Comments',
|
|||
|
|
'feedbacks' => 'Feedbacks',
|
|||
|
|
'notify' => 'Notify',
|
|||
|
|
'managers' => 'Managers',
|
|||
|
|
'callbacks' => 'Callbacks',
|
|||
|
|
|
|||
|
|
'marka' => 'Marka',
|
|||
|
|
'model' => 'Model',
|
|||
|
|
'services' => 'Services',
|
|||
|
|
);
|
|||
|
|
|
|||
|
|
// Созданные объекты
|
|||
|
|
private static $objects = array();
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* Конструктор оставим пустым, но определим его на случай обращения parent::__construct() в классах API
|
|||
|
|
*/
|
|||
|
|
public function __construct()
|
|||
|
|
{
|
|||
|
|
//error_reporting(E_ALL & !E_STRICT);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* Магический метод, создает нужный объект API
|
|||
|
|
*/
|
|||
|
|
public function __get($name)
|
|||
|
|
{
|
|||
|
|
// Если такой объект уже существует, возвращаем его
|
|||
|
|
if(isset(self::$objects[$name]))
|
|||
|
|
{
|
|||
|
|
return(self::$objects[$name]);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// Если запрошенного API не существует - ошибка
|
|||
|
|
if(!array_key_exists($name, $this->classes))
|
|||
|
|
{ //echo($name);
|
|||
|
|
return null;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// Определяем имя нужного класса
|
|||
|
|
$class = $this->classes[$name];
|
|||
|
|
|
|||
|
|
// Подключаем его
|
|||
|
|
include_once($_SERVER['DOCUMENT_ROOT'] . '/api/'.$class.'.php');
|
|||
|
|
|
|||
|
|
// Сохраняем для будущих обращений к нему
|
|||
|
|
self::$objects[$name] = new $class();
|
|||
|
|
|
|||
|
|
// Возвращаем созданный объект
|
|||
|
|
return self::$objects[$name];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
function getUniqueFileName($path, $name){
|
|||
|
|
$ext = '.' . mb_strtolower(substr(strrchr($name, '.'), 1));
|
|||
|
|
$name = substr($name, 0, -strlen(strrchr ($name, ".")));
|
|||
|
|
$path = rtrim($path, '/') . '/';
|
|||
|
|
$num = $fix = '';
|
|||
|
|
while(is_file($path . $name . $fix . $ext)) $fix = '_' . ++$num;
|
|||
|
|
return $name . $fix . $ext;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
function translateStr($str){
|
|||
|
|
$translate = array(
|
|||
|
|
'а'=>'a','б'=>'b','в'=>'v','г'=>'g','д'=>'d','е'=>'e','ё'=>'e','ж'=>'zh','з'=>'z','и'=>'i','й'=>'i','к'=>'k','л'=>'l','м'=>'m','н'=>'n','о'=>'o','п'=>'p',
|
|||
|
|
'р'=>'r','с'=>'s','т'=>'t','у'=>'u','ф'=>'f','х'=>'kh','ц'=>'tc','ч'=>'ch','ш'=>'sh','щ'=>'shch','ь'=>'','ы'=>'y','ъ'=>'','э'=>'e','ю'=>'iu','я'=>'ia'
|
|||
|
|
);
|
|||
|
|
|
|||
|
|
$str = mb_strtolower($str, "UTF-8");
|
|||
|
|
$str = preg_split("//u", $str, -1, PREG_SPLIT_NO_EMPTY);
|
|||
|
|
$res = array();
|
|||
|
|
|
|||
|
|
foreach($str as $letter){
|
|||
|
|
if(isset($translate[$letter])) $res[] = $translate[$letter];
|
|||
|
|
else $res[] = preg_match('~[a-z0-9_\.]~', $letter) ? $letter : '-';
|
|||
|
|
}
|
|||
|
|
$str = implode('', $res);
|
|||
|
|
$str = trim($str, '-');
|
|||
|
|
$str = preg_replace('~([\.]+)~', '.', $str);
|
|||
|
|
return preg_replace('~([-]+)~', '-', $str);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|