dc-rest/inc/class.rest.query.put.blogs.php

75 lines
2.0 KiB
PHP
Raw Normal View History

2017-05-11 23:10:01 +02:00
<?php
class ResQueryPutBlogs extends RestQuery
{
public function __construct($args,$body)
{
global $core;
$this->blog_id = substr($args,6);
2017-05-18 21:49:46 +02:00
$this->required_perms = 'admin';
2017-05-11 23:10:01 +02:00
//Is allowed?
if($this->is_allowed() === false){
return;
}
//Is JSON valid?
$inputArray = $this-> body_to_array($body);
if ($inputArray === false){
return;
}
//is it valid fields?
if(!$this->check_for_required_fields( $inputArray, array('blog_id','blog_url','blog_name','blog_desc'), array())){
return;
}
//does the blog exists?
$core->blog = new dcBlog($core, $this->blog_id);
2017-09-08 09:18:48 +02:00
if(!$core->blog->id){
//Le blog n'existe pas
$this->response_code = 404;
$this->response_message = array('code' => 404, 'error' => 'Resource '.$blog_id.' not found');
return;
}
2017-05-11 23:10:01 +02:00
$blog_settings = new dcSettings($core,$this->blog_id);
if(!$core->blog->id){
$this->response_code = 404;
$this->response_message = array('code' => 404, 'error' => 'Resource '.$this -> blog_id.' not found');
return;
}
$cur = $core->con->openCursor($core->prefix.'blog');
if(isset($inputArray['blog_id']))
$cur->blog_id = $inputArray['blog_id'];
else
$cur->blog_id = $core->blog->id;
if(isset($inputArray['blog_url']))
$cur->blog_url = preg_replace('/\?+$/','?', $inputArray['blog_url']);
else
$cur->blog_url = $core->blog->url;
if(isset($inputArray['blog_name']))
$cur->blog_name = $inputArray['blog_name'];
if(isset($inputArray['blog_desc']))
$cur->blog_desc = $inputArray['blog_desc'];
$core->updBlog($this->blog_id,$cur);
//$cur->blog_upddt = date('Y-m-d H:i:s');
//$cur->update("WHERE blog_id = '".$core->con->escape($id)."'");
$this -> response_code = 200;
$this -> response_message = array(
'code' => 200,
'message' => 'blog '.$this->blog_id.' Successfully updated'
);
return;
}
2017-09-08 09:18:48 +02:00
}