api with json return

This commit is contained in:
Claude 2012-04-19 09:27:03 +02:00
parent d162fb1284
commit 2e82df600a
3 changed files with 19 additions and 3 deletions

View File

@ -23,11 +23,24 @@ class Api extends Main
if (!$this->input->post('text'))
{
echo 'missing paste text';
$data['data'] = array(
'error' => 'missing paste text',
);
$this->load->view('view/api', $data);
}
else
{
echo $this->pastes->createPaste();
if (!$this->input->post('lang'))
{
$_POST['lang'] = 'text';
}
$_POST['code'] = $this->input->post('text');
$paste_url = $this->pastes->createPaste();
$data['data'] = array(
'url' => base_url() . $paste_url,
);
$this->load->view('view/api', $data);
}
}
}

View File

@ -0,0 +1,3 @@
<?php
header('Content-Type: application/json; charset=utf-8');
echo json_encode($data);

View File

@ -1,3 +1,3 @@
<?php
header('Content-Type:text/plain; charset=utf-8');
header('Content-Type: text/plain; charset=utf-8');
echo htmlspecialchars_decode($raw);