Created
September 18, 2012 08:15
-
-
Save betaman/3741972 to your computer and use it in GitHub Desktop.
Restful json api for elefantcms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all my app Stuff | |
... | |
handlePageChange: function () { | |
var html, block = this.model.get("block"); | |
$('header nav').html(this.model.get("nav")); | |
$('hgroup h1').html(this.model.get("title")); | |
$('.contentBody').html(this.model.get("body")); | |
// the block is hidden per js if there is no content | |
if (block) { | |
html = ""; | |
if (block.show_title === "yes") { | |
html += "<h2>" + block.title + "</h2>"; | |
} | |
html += block.body; | |
$('aside.content').html(html).show(); | |
} else { | |
$('aside.content').empty().hide(); | |
} | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Json extends \Restful { | |
// Accessible via `GET /json/api/page/index | |
public function get_page ($id) { | |
if (! User::require_admin ()) { | |
$page = Webpage::query () | |
->where ('access', 'public') | |
->where ('id', $id) | |
->single (); | |
} else { | |
$page = Webpage::query () | |
->where ('id', $id) | |
->single (); | |
} | |
if (! User::require_admin ()) { | |
$block = Block::query () | |
->where ('access', 'public') | |
->where ('id', $id) | |
->single (); | |
} else { | |
$block = Block::query () | |
->where ('id', $id) | |
->single (); | |
} | |
require_once ('apps/json/lib/Functions.php'); | |
if ($page) { | |
// convert it from a Webpage object into an ordinary object | |
$page = $page->orig (); | |
$n = new Navigation; | |
$page->path = $n->path ($page->id); | |
$page->nav = get_navigation_html($n->tree, $page->path); | |
$controller = new Controller (conf ('Hooks')); | |
$tpl = new Template (conf ('General', 'charset'), $controller); | |
$page->body = $tpl->run_includes ($page->body); | |
if($block) { | |
$block->body = $tpl->run_includes ($block->body); | |
} | |
if (User::require_admin ()) { | |
// show admin edit buttons | |
if (User::is_valid () && User::is ('admin')) { | |
$lock = new Lock ('Webpage', $id); | |
$page->locked = $lock->exists (); | |
$page->body = $tpl->render ('admin/editable', $page) . $page->body; | |
if($block){ | |
$block->body = $tpl->render ('blocks/editable', (object) array ('id' => $block->id, 'locked' => $block->locked, 'title' => $block->title, 'path' => "/".$id)) . $block->body; | |
}else{ | |
//this should read | |
//$tpl->render ('blocks/add', (object) array ('id' => $block->id)) | |
$addBlock = new Block(); | |
$addBlock->body = "<p class='admin-options'><a href='blocks/add?id=".$id."'><img src='/apps/admin/css/admin/add.png' /></a></p>"; | |
} | |
} | |
} | |
$page->body = str_replace("/json/api/page/", "/", $page->body); | |
if($block) { | |
$block->body = str_replace("/json/api/page/", "/", $block->body); | |
$page->block = $block->orig (); | |
}else if($addBlock){ | |
$page->block = $addBlock->orig (); | |
}else{ | |
$page->block = $false; | |
} | |
} | |
$this->wrap = false; | |
// Return some data | |
return $page; | |
} | |
// Accessible via `POST /myapp/api/article` | |
public function post_page () { | |
// Return an error | |
return $this->error ('Error message'); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment