74 lines
2.2 KiB
PHP
74 lines
2.2 KiB
PHP
|
|
<?
|
||
|
|
|
||
|
|
namespace controller\blog\news;
|
||
|
|
|
||
|
|
use blog\Blog;
|
||
|
|
use blog\News;
|
||
|
|
use ms\ms\structure\msControllerTable;
|
||
|
|
|
||
|
|
class Api extends msControllerTable {
|
||
|
|
|
||
|
|
static $class = 'blog\News';
|
||
|
|
|
||
|
|
static function profileCreate(){
|
||
|
|
$res = [];
|
||
|
|
if(IF_PROFILE){
|
||
|
|
$id = intval($_POST['id']);
|
||
|
|
$name = trim($_POST['name']);
|
||
|
|
$text = trim($_POST['text']);
|
||
|
|
$blog_id = intval($_POST['blog_id']);
|
||
|
|
/*
|
||
|
|
if(!$name){
|
||
|
|
$res['e']=1;
|
||
|
|
$res['m']='Введите название';
|
||
|
|
}
|
||
|
|
/**/
|
||
|
|
if(!$text){
|
||
|
|
$res['e']=1;
|
||
|
|
$res['m']='Введите текст';
|
||
|
|
}
|
||
|
|
if(!$res['e']) {
|
||
|
|
$BLOG = Blog::getByID($blog_id);
|
||
|
|
if ($BLOG[Blog::$PROFILE] == PID) {
|
||
|
|
$BLOG_ID = $BLOG[Blog::$ID];
|
||
|
|
$text_id = translit($name);
|
||
|
|
if(!$text_id) $text_id = 'news_'.time();
|
||
|
|
$isInsert = true;
|
||
|
|
|
||
|
|
$C = News::getByTextIDForBlog($BLOG_ID, $BLOG[Blog::$ACCOUNT], $text_id);
|
||
|
|
if ($C) {
|
||
|
|
if($C[News::$ID]!=$id) $text_id .= '_' . time();
|
||
|
|
}
|
||
|
|
|
||
|
|
$arr = [
|
||
|
|
News::$NAME => $name,
|
||
|
|
News::$TEXT => $text,
|
||
|
|
News::$ACCOUNT => \Site::$owner_id,
|
||
|
|
News::$PROFILE => PID,
|
||
|
|
News::$BLOG => $BLOG_ID,
|
||
|
|
News::$TEXT_ID => $text_id,
|
||
|
|
News::$VIS => 1,
|
||
|
|
];
|
||
|
|
if($id){
|
||
|
|
$C = News::getByID($id);
|
||
|
|
if($C){
|
||
|
|
$r = News::updateById($id,$arr);
|
||
|
|
$res['r'] = $r;
|
||
|
|
$res['id'] = $id;
|
||
|
|
$isInsert = false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if($isInsert) {
|
||
|
|
$r = News::insert($arr);
|
||
|
|
//$res['r'] = $r;
|
||
|
|
$res['id'] = $r->id;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
echo je($res);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|