meraproject/themes/modulebz/controller.php
keboss-m 5c21d25d45 Initial commit: Merakomis portal, Docker stack and user-reader API.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-24 11:04:05 +03:00

301 lines
14 KiB
PHP

<?
namespace controller\themes\modulebz;
use ms\ms\structure\msTo;
use ms\table\Filter;
use themes\modulebz\structure\eContentPage;
const CHAT_ID = '-1001377277495';
const TOKEN = '1830086777:AAG1bpao1eBPpUfPyXAtchMh4yAnOxGJV3M';
const VICTOR_ID = 218573962;
const ALEX_ID = 150901587;
class Api {
static function test(){
$f = fopen(__DIR__.'/tg.txt','a+');
fwrite($f,json_encode($_REQUEST)."\n\n");
$data = json_decode(file_get_contents('php://input'),true);
fwrite($f,json_encode($data));
fclose($f);
function request($url,$data = []){
$res = null;
//$url = 'https://api.telegram.org/bot'.self::$TELEGRAM_BOT_TOKEN.'/sendMessage?chat_id=-491226996&text='.urlencode($text);
$url = 'https://api.telegram.org/bot'.TOKEN.'/'.$url.'?'.http_build_query($data);
if ($curl = curl_init()){
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0);
$out = curl_exec($curl);
curl_close($curl);
$res = json_decode($out,true);
echo '<pre>';
echo var_dump($data,$url,$res);
echo '</pre>';
}
return $res;
}
function getMe(){
return request('getMe');
}
function getUpdates(){
return request('getUpdates');
}
function createChatInviteLink($id){
return request('createChatInviteLink',['chat_id'=>$id,'member_limit'=>1]);
}
function getMyCommands(){
return request('getMyCommands');
}
function setWebhook($url){
return request('setWebhook',['url'=>$url,'']);
}
function setMyCommands($data){
return request('setMyCommands',['commands'=>json_encode($data)]);
}
function sendMessage($id,$text){
return request('sendMessage',[
'chat_id'=>$id,
'text'=>$text,
]);
}
function sendLink($id,$name){
$res = createChatInviteLink(CHAT_ID);
$link = $res['result']['invite_link'];
return request('sendMessage',[
'chat_id'=>$id,
'text'=>"Привет, ".$name.".\nТвоя ссылка в секретный чат: ".$link,
]);
}
function kick($chat_id,$kick_id){
request('kickChatMember',[
'chat_id'=>$chat_id,
'user_id'=>$kick_id,
]);
request('sendMessage',[
'chat_id'=>$kick_id,
'text'=>'Вы удалены из чата, так вы не заплатили за ссылку.',
]);
request('sendMessage',[
'chat_id'=>VICTOR_ID,
'text'=>$kick_id.' удалён из '.$chat_id,
]);
}
if($data['message']['text']=='/start'){
sendLink($data['message']['from']['id'],$data['message']['from']['first_name']);
}
if(($id = $data['chat_member']['new_chat_member']['user']['id'])==ALEX_ID){
sendMessage($id,"Незя!");
sleep(1);
kick(CHAT_ID,$id);
}
}
/*
static function getPass(){
$acc = \Account::getByID(17);
$acc[\Account::$PASSWORD] = 'G6vT2L9AQuc&';
echo \Account::hash($acc);
}
/**/
static function crumbs($arr){
return array_merge([['name'=>'Главная','link'=>'']],$arr);
}
static function getAppStructure(){
$res = [];
$isLocal = $_SERVER['HTTP_ORIGIN'] == 'http://localhost';
$isTest = $isLocal;
$token_hash = '1';
$profile_id = PID;
$panel_path = $isLocal ? '/npm/app/examples/modulebz/' : '/';
if(!IF_AUTH) exit;
$logotype = [
'url'=>\Site::sectionUrl('content/active_user/pics/logo/logo.png',true),
'title'=>'Active User',
'subtitle'=>'Повседневные программы',
];
$res = [
'options'=>[
'domain' => $_SERVER['HTTP_HOST'],
],
//'server' => $_SERVER,
'routes' => [
['path'=>'portals/*', 'element'=> eContentPage::MODULEBZ_PORTALS, 'props'=>[], 'crumbs'=>self::crumbs([['name'=>'Сайты','link'=>'portals']])],
//['path'=>'academies/*', 'element'=> eContentPage::MODULEBZ_ACADEMIES, 'props'=>[], 'crumbs'=>self::crumbs([['name'=>'Мои проекты','link'=>'projects']])],
//['path'=>'projects/*', 'element'=> eContentPage::MODULEBZ_ACADEMY_PROJECTS, 'props'=>[], 'crumbs'=>self::crumbs([['name'=>'Мои проекты','link'=>'projects']])],
//['path'=>'projects/*', 'element'=> eContentPage::MODULEBZ_ACADEMY_COURSES, 'props'=>[], 'crumbs'=>self::crumbs([['name'=>'Мои проекты','link'=>'projects']])],
//['path'=>'projects/*', 'element'=> eContentPage::MODULEBZ_ACADEMY_COMMENTS, 'props'=>[], 'crumbs'=>self::crumbs([['name'=>'Мои проекты','link'=>'projects']])],
//['path'=>'projects/*', 'element'=> eContentPage::MODULEBZ_ACADEMY_REVIEWS, 'props'=>[], 'crumbs'=>self::crumbs([['name'=>'Мои проекты','link'=>'projects']])],
//['path'=>'projects/*', 'element'=> eContentPage::MODULEBZ_ACADEMY_STUDENTS, 'props'=>[], 'crumbs'=>self::crumbs([['name'=>'Мои проекты','link'=>'projects']])],
//['path'=>'projects/*', 'element'=> eContentPage::MODULEBZ_ACADEMY_TESTS, 'props'=>[], 'crumbs'=>self::crumbs([['name'=>'Мои проекты','link'=>'projects']])],
['path'=>'pages/*', 'element'=> eContentPage::MODULEBZ_COMMON_PAGES, 'props'=>[], 'crumbs'=>self::crumbs([['name'=>'Статичные страницы','link'=>'pages/']])],
['path'=>'menus/*', 'element'=> eContentPage::MODULEBZ_COMMON_MENUS, 'props'=>[], 'crumbs'=>self::crumbs([['name'=>'Меню','link'=>'menus/']])],
['path'=>'galleries/*', 'element'=> eContentPage::MODULEBZ_COMMON_GALLERIES, 'props'=>[], 'crumbs'=>self::crumbs([['name'=>'Галереи','link'=>'galleries/']])],
['path'=>'blogs/*', 'element'=> eContentPage::MODULEBZ_COMMON_BLOGS, 'props'=>[], 'crumbs'=>self::crumbs([['name'=>'Блоги','link'=>'blogs/']])],
['path'=>'faq/*', 'element'=> eContentPage::MODULEBZ_COMMON_FAQ, 'props'=>[], 'crumbs'=>self::crumbs([['name'=>'Вопрос-ответ','link'=>'faq/']])],
['path'=>'bases/*', 'element'=> eContentPage::MODULEBZ_COMMON_BASES, 'props'=>[], 'crumbs'=>self::crumbs([['name'=>'Базы знаний','link'=>'bases/']])],
['path'=>'emails/template/*', 'element'=> eContentPage::MODULEBZ_COMMON_TEMPLATE_EMAILS, 'props'=>[], 'crumbs'=>self::crumbs([['name'=>'Шаблоны писем','link'=>'emails/template/']])],
['path'=>'email/history/*', 'element'=> eContentPage::MODULEBZ_HISTORY_EMAIL, 'props'=>[], 'crumbs'=>self::crumbs([['name'=>'История писем','link'=>'email/history/']])],
['path'=>'shops/*', 'element'=> eContentPage::MODULEBZ_SHOPS, 'props'=>[], 'crumbs'=>self::crumbs([['name'=>'Магазины','link'=>'shops/']])],
['path'=>'shop/orders/*', 'element'=> eContentPage::MODULEBZ_SHOP_ORDERS, 'props'=>[], 'crumbs'=>self::crumbs([['name'=>'Заказы','link'=>'shop/orders/']])],
['path'=>'shop/buyers/*', 'element'=> eContentPage::MODULEBZ_SHOP_BUYERS, 'props'=>[], 'crumbs'=>self::crumbs([['name'=>'Покупатели','link'=>'shop/buyers/']])],
['path'=>'shop/items/*', 'element'=> eContentPage::MODULEBZ_SHOP_ITEMS, 'props'=>[], 'crumbs'=>self::crumbs([['name'=>'Товары','link'=>'shop/items/']])],
['path'=>'shop/categories/*', 'element'=> eContentPage::MODULEBZ_SHOP_CATEGORIES, 'props'=>[], 'crumbs'=>self::crumbs([['name'=>'Категории','link'=>'shop/categories/']])],
['path'=>'shop/properties/*', 'element'=> eContentPage::MODULEBZ_SHOP_PROPERTIES, 'props'=>[], 'crumbs'=>self::crumbs([['name'=>'Свойства товаров','link'=>'shop/properties/']])],
['path'=>'shop/components/*', 'element'=> eContentPage::MODULEBZ_SHOP_COMPONENTS, 'props'=>[], 'crumbs'=>self::crumbs([['name'=>'Компоненты товаров','link'=>'shop/components/']])],
['path'=>'shop/blanks/*', 'element'=> eContentPage::MODULEBZ_SHOP_BLANKS, 'props'=>[], 'crumbs'=>self::crumbs([['name'=>'Бланки печати заказов','link'=>'shop/blanks/']])],
['path'=>'shop/accumulate/*', 'element'=> eContentPage::MODULEBZ_SHOP_ACCUMULATE_GROUP, 'props'=>[], 'crumbs'=>self::crumbs([['name'=>'Накопительные скидки','link'=>'shop/accumulate/']])],
['path'=>'shop/cashback/*', 'element'=> eContentPage::MODULEBZ_SHOP_CASHBACK_GROUP, 'props'=>[], 'crumbs'=>self::crumbs([['name'=>'Накопительные кэшбеки','link'=>'shop/cashback/']])],
],
'api_url_theme'=>\Site::$domen.'/api/themes.modulebz',
'domain_url' =>\Site::$domen.'',
'auth' => true,
'account' => [
'id' => $profile_id,
'token' => $token_hash,
],
'fullscreen' => true,
'url_path' => $panel_path,
'header' => [
'logotype' => 'pics/logo.white.png'
],
'menu' => [
'logotype' => $logotype,
'avatar' => 'pics/ava.jpg',
'avatar_link' => 'profile/1',
'menu' =>
[
[
'title' => 'Проекты',
'toggle' => true,
'opened' => true,
'submenu' => [
['link'=>'portals', 'title'=>'Мои сайты'],
]
],
[
'title' => 'Торговля',
'toggle' => true,
'opened' => true,
'submenu' => [
['link'=>'shop/orders/', 'title'=>'Заказы'],
['link'=>'shop/buyers/', 'title'=>'Покупатели'],
[
'title' => 'Товары',
'toggle' => true,
'opened' => false,
'submenu' => [
['link'=>'shop/items/', 'title'=>'Товары'],
['link'=>'shop/categories/', 'title'=>'Категории'],
['link'=>'shop/properties/', 'title'=>'Свойства товаров'],
['link'=>'shop/components/', 'title'=>'Компоненты товаров'],
]
],
[
'title' => 'Настройки',
'toggle' => true,
'opened' => false,
'submenu' => [
['link'=>'shops/', 'title'=>'Магазины'],
['link'=>'shop/blanks/', 'title'=>'Бланки печати заказов'],
['link'=>'shop/accumulate/', 'title'=>'Накопительные скидки'],
['link'=>'shop/cashback/', 'title'=>'Накопительные кэшбеки'],
]
],
]
],
[
'title' => 'Контент',
'toggle' => true,
'opened' => true,
'submenu' => [
['link'=>'pages', 'title'=>'Статичные страницы'],
['link'=>'menus', 'title'=>'Меню'],
['link'=>'galleries', 'title'=>'Галереи'],
['link'=>'blogs', 'title'=>'Блоги'],
['link'=>'faq', 'title'=>'Вопрос-ответ'],
['link'=>'bases', 'title'=>'Базы знаний'],
]
],
],
]
];
echo je($res);
}
static function saveFilter(){
$res = [];
if(IF_AUTH){
$res = Filter::addFilterForToOid(
$_POST['name'],
$_POST['data']['table'],
$_POST['filter'],
msTo::ACCOUNT,
UID
);
}
echo je($res);
}
static function updateFilter(){
$res = [];
if(IF_AUTH){
$id = intval($_POST['id']);
$filter = Filter::getByID($id);
if($filter[Filter::$OID]==UID and $filter[Filter::$TO]==msTo::ACCOUNT) {
Filter::updateById($id, [
Filter::$DATA => je($_POST['data'])
]);
$res['notify']['content'] = 'Успешно обновлено';
}
}
echo je($res);
}
static function removeFilter(){
$res = [];
if(IF_AUTH){
$id = intval($_POST['id']);
$filter = Filter::getByID($id);
if($filter[Filter::$OID]==UID and $filter[Filter::$TO]==msTo::ACCOUNT) {
$res = Filter::deleteByID($id);
}
}
echo je($res);
}
}