Created
November 6, 2012 21:03
-
-
Save betaman/4027520 to your computer and use it in GitHub Desktop.
Elefant CMS: Dynamic Blocks and Blocks with Fallback
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
/* /apps/blocks/views/editable.php */ | |
<p class="admin-options"> | |
{% if title %} | |
{% if locked %} | |
<a href="javascript:void(0)" title="{"Editing Locked"}"><img src="/apps/admin/css/admin/lock.png" /></a> | |
{% else %} | |
<a href="/blocks/edit?id={{ id }}&return={{ $_SERVER.REQUEST_URI }}" title="{"Edit Block"}"><img src="/apps/admin/css/admin/edit.png" /></a><a href="/admin/versions?type=Block&id={{ id }}" title="{"Versions"}"><img src="/apps/admin/css/admin/versions.png" /></a><a href="/blocks/delete?id={{ id }}&return={{ $_SERVER.REQUEST_URI }}" title="{"Delete Block"}" onclick="return confirm {% if new_id %}('{"Are you sure you want to delete the default block? This will have impact on all other Pages using this default block"}'){% else %} ('{"Are you sure you want to delete the current block?"}') {% end %};"><img src="/apps/admin/css/admin/delete.png" /></a>{% if new_id %}<a href="/blocks/add?id={{ new_id }}&return={{ $_SERVER.REQUEST_URI }}" title="{"Add Block"}" onclick="return confirm ('{"Are you sure you want to overwrite the default block?"}');"><img src="/apps/admin/css/admin/add.png" /></a> {% end %} | |
{% end %} | |
{% else %} | |
<a href="/blocks/add?id={{ id }}&return={{ $_SERVER.REQUEST_URI }}" title="{"Add Block"}"><img src="/apps/admin/css/admin/add.png" /></a> | |
{% end %} | |
</p> |
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 | |
/* /apps/blocks/handlers/index.php */ | |
/** | |
* Renders the specified content block. Use in layout templates like this: | |
* | |
* {! blocks/my-block-id !} | |
* | |
* You can also specify a dynamic ID value for your blocks so that a single | |
* block position can refer to a dynamic number of blocks, like this: | |
* | |
* {! blocks/index?id=[id] !} | |
* | |
* In the above example, `[id]` is replaced with the current page ID, so | |
* that on each page, it will try to render a block in that position with | |
* the same ID as the current page. | |
* | |
* See the API documentation for the Template class for more info on | |
* `[expr]` style sub-expressions. | |
*/ | |
$id = (isset ($this->params[0])) ? $this->params[0] : (isset ($data['id']) ? $data['id'] : false); | |
$hasDefault = (isset ( $data['hasDefault'])) ? $data['hasDefault'] : false; | |
if (isset ($data['type']) && isset ($data['id'])){ | |
$default_id = "default-" . $data['type']; | |
$id .= "-" . $data['type']; | |
} | |
if (! $id) { | |
if (User::is_valid () && User::is ('admin')) { | |
echo $tpl->render ('blocks/editable', (object) array ('id' => $id, 'locked' => false)); | |
} | |
return; | |
} | |
$lock = new Lock ('Block', $id); | |
$b = new Block ($id); | |
if ($b->error) { | |
if ($hasDefault) { | |
$b = new Block ($default_id); | |
$b->new_id = $id; | |
} | |
if ($b->error) { | |
if (User::is_valid () && User::is ('admin')) { | |
echo $tpl->render ('blocks/editable', (object) array ('id' => $id, 'locked' => false, 'title' => false)); | |
} | |
return; | |
} | |
} | |
// permissions | |
if ($b->access !== 'public') { | |
if (! User::require_login ()) { | |
return; | |
} | |
if (! User::access ($b->access)) { | |
return; | |
} | |
} | |
if ($b->show_title == 'yes') { | |
printf ('<h3>%s</h3>', $b->title); | |
} | |
$b->locked = $lock->exists (); | |
if (User::is_valid () && User::is ('admin')) { | |
echo $tpl->render ('blocks/editable', $b); | |
} | |
echo $tpl->run_includes ($b->body); | |
?> |
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
{! blocks/index?id=[id]&type=sidebar&hasDefault=true !} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment