dc-rest/inc/class.rest.query.get.blog.settings.php

62 lines
1.8 KiB
PHP
Raw Permalink Normal View History

2017-05-11 23:10:01 +02:00
<?php
class RestQueryGetBlogSettings extends RestQuery
{
public function __construct($args)
{
global $core;
2017-05-18 21:49:46 +02:00
$explodedArgs = explode("/",$args);
$this->blog_id = $explodedArgs[0];
2017-05-11 23:10:01 +02:00
//check if user is allowed
$this->required_perms = 'admin';
if($this->is_allowed() === false){
return;
}
$core->blog = new dcBlog($core, $this->blog_id);
$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;
}
try{
$settings = array();
foreach ($core->blog->settings->dumpNamespaces() as $ns => $namespace) {
foreach ($namespace->dumpSettings() as $k => $v) {
$settings[$ns][$k] = $v;
}
}
2017-05-18 21:49:46 +02:00
2017-05-11 23:10:01 +02:00
$this->response_code = 200;
2017-05-18 21:49:46 +02:00
if(isset($explodedArgs[3])){
if(isset($settings[$explodedArgs[2]][$explodedArgs[3]])){
$this->response_message = $settings[$explodedArgs[2]][$explodedArgs[3]];
}else{
$this->response_code = 404;
$this->response_message = array('code' => 404, 'error' => 'Namespace or setting not found');
}
}elseif(isset($explodedArgs[2])){
if(isset($settings[$explodedArgs[2]])){
$this->response_message = $settings[$explodedArgs[2]];
}else{
$this->response_code = 404;
$this->response_message = array('code' => 404, 'error' => 'Namespace found');
}
}else{
$this->response_message = $settings;
}
2017-05-11 23:10:01 +02:00
}catch (Exception $e){
$this->response_code = 500;
$this->response_message = array(
'code' => 500,
'message' => $e->getMessage()
);
}
2017-05-18 21:49:46 +02:00
return;
2017-05-11 23:10:01 +02:00
}
}