mirror of
https://github.com/claudehohl/Stikked.git
synced 2025-04-26 04:51:08 -05:00
Merge branch 'api'
This commit is contained in:
commit
ef4fead544
56
htdocs/application/controllers/api.php
Executable file
56
htdocs/application/controllers/api.php
Executable file
@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Class and Function List:
|
||||||
|
* Function list:
|
||||||
|
* - __construct()
|
||||||
|
* - index()
|
||||||
|
* - create()
|
||||||
|
* Classes list:
|
||||||
|
* - Api extends Main
|
||||||
|
*/
|
||||||
|
include_once ('application/controllers/main.php');
|
||||||
|
|
||||||
|
class Api extends Main
|
||||||
|
{
|
||||||
|
|
||||||
|
function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
function index()
|
||||||
|
{
|
||||||
|
$languages = $this->languages->get_languages();
|
||||||
|
$languages = array_keys($languages);
|
||||||
|
$languages = implode(', ', $languages);
|
||||||
|
$data['languages'] = $languages;
|
||||||
|
$this->load->view('api_help', $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
function create()
|
||||||
|
{
|
||||||
|
$this->load->model('pastes');
|
||||||
|
|
||||||
|
if (!$this->input->post('text'))
|
||||||
|
{
|
||||||
|
$data['data'] = array(
|
||||||
|
'error' => 'missing paste text',
|
||||||
|
);
|
||||||
|
$this->load->view('view/api', $data);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
61
htdocs/application/views/api_help.php
Executable file
61
htdocs/application/views/api_help.php
Executable file
@ -0,0 +1,61 @@
|
|||||||
|
<?php $this->load->view("defaults/header");?>
|
||||||
|
|
||||||
|
<div class="api">
|
||||||
|
<h1>API</h1>
|
||||||
|
<p class="explain border">Create pastes from the commandline</p>
|
||||||
|
|
||||||
|
<h2>API URL</h2>
|
||||||
|
<p class="explain"><code><?php echo site_url('api/create'); ?></code></p>
|
||||||
|
|
||||||
|
<h2>Return values</h2>
|
||||||
|
<p class="explain">
|
||||||
|
On success, the API returns the paste URL in JSON format: <code>{"url":"<?php echo site_url('view/[pasteid]'); ?>"}</code><br />
|
||||||
|
On error, the API returns the error message in JSON format: <code>{"error":"missing paste text"}</code>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<h2>POST parameters</h2>
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<code>text=[your paste text]</code>
|
||||||
|
<p class="explain">The paste content. Required.</p>
|
||||||
|
|
||||||
|
<code>name=[name]</code>
|
||||||
|
<p class="explain">The author's name.</p>
|
||||||
|
|
||||||
|
<code>private=1</code>
|
||||||
|
<p class="explain">Make paste private.</p>
|
||||||
|
|
||||||
|
<code>lang=[language]</code>
|
||||||
|
<p class="explain">
|
||||||
|
Use alternative syntax highlighting.<br />
|
||||||
|
Possible values: <?php echo $languages; ?>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<code>expire=[minutes]</code>
|
||||||
|
<p class="explain">Set paste expiration.</p>
|
||||||
|
|
||||||
|
<code>reply=[pasteid]</code>
|
||||||
|
<p class="explain">Reply to existing paste.</p>
|
||||||
|
|
||||||
|
<h2>Examples</h2>
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<h3>Create paste</h3>
|
||||||
|
<code>curl -d text='this is my text' <?php echo site_url('api/create'); ?></code>
|
||||||
|
<p class="explain">Create a paste with the text 'this is my text'.</p>
|
||||||
|
|
||||||
|
<h3>Create paste from a file</h3>
|
||||||
|
<code>curl -d private=1 -d name=Herbert --data-urlencode text@/etc/passwd <?php echo site_url('api/create'); ?></code>
|
||||||
|
<p class="explain">Create a private paste with the author 'Herbert' and the contents of '/etc/passwd'.</p>
|
||||||
|
|
||||||
|
<h3>Create paste from a php file</h3>
|
||||||
|
<code>curl -d lang=php --data-urlencode text@main.php <?php echo site_url('api/create'); ?></code>
|
||||||
|
<p class="explain">Create a paste with PHP syntax highlighting.</p>
|
||||||
|
|
||||||
|
<h3>Get paste ;-)</h3>
|
||||||
|
<code>curl <?php echo site_url('view/raw/[pasteid]'); ?></code>
|
||||||
|
<p class="explain">Display paste.</p>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php $this->load->view("defaults/footer");?>
|
@ -35,6 +35,7 @@ $this->carabiner->display('css');
|
|||||||
<?php $l = $this->uri->segment(1)?>
|
<?php $l = $this->uri->segment(1)?>
|
||||||
<li><a <?php if($l == ""){ echo 'class="active"'; }?> href="<?php echo base_url()?>" title="Create A New Paste">Create</a></li>
|
<li><a <?php if($l == ""){ echo 'class="active"'; }?> href="<?php echo base_url()?>" title="Create A New Paste">Create</a></li>
|
||||||
<li><a <?php if($l == "lists" || $l == "view" and $this->uri->segment(2) != "options"){ echo 'class="active"'; }?> href="<?php echo site_url('lists'); ?>" title="Recent Pastes">Recent</a></li>
|
<li><a <?php if($l == "lists" || $l == "view" and $this->uri->segment(2) != "options"){ echo 'class="active"'; }?> href="<?php echo site_url('lists'); ?>" title="Recent Pastes">Recent</a></li>
|
||||||
|
<li><a <?php if($l == "api"){ echo 'class="active"'; }?> href="<?php echo site_url('api'); ?>" title="API">API</a></li>
|
||||||
<li><a <?php if($l == "about"){ echo 'class="active"'; }?> href="<?php echo site_url('about'); ?>" title="About">About</a></li>
|
<li><a <?php if($l == "about"){ echo 'class="active"'; }?> href="<?php echo site_url('about'); ?>" title="About">About</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
3
htdocs/application/views/view/api.php
Executable file
3
htdocs/application/views/view/api.php
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
<?php
|
||||||
|
header('Content-Type: application/json; charset=utf-8');
|
||||||
|
echo json_encode($data);
|
@ -1,3 +1,3 @@
|
|||||||
<?php
|
<?php
|
||||||
header('Content-Type:text/plain; charset=utf-8');
|
header('Content-Type: text/plain; charset=utf-8');
|
||||||
echo htmlspecialchars_decode($raw);
|
echo htmlspecialchars_decode($raw);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user