Skip to content

Instantly share code, notes, and snippets.

View betaman's full-sized avatar

Jens Bettermann betaman

View GitHub Profile
@betaman
betaman / Json.php
Created June 9, 2013 19:09
Elefant CMS JSON App: Retrieve Data as JSON For Singlepage Websites
<?php
class Json extends \Restful {
// Accessible via:
// `GET /json/api/run/layout/index`
// retrieves controller run data from page and all includes in a layout template
// `GET /json/api/run/page/index`
[{"data":"Homepage (en)","attr":{"id":"en","classname":"icon-folder-open"},"children":[{"data":"Products","attr":{"id":"products","classname":"icon-folder-open"},"children":[{"data":"Article 1","attr":{"id":"article-1","classname":""}},{"data":"Article 2","attr":{"id":"article-2","classname":""}},{"data":"Article 3","attr":{"id":"article-3","classname":""}}]},{"data":"Testpage","attr":{"id":"testpage","classname":""}}]},{"data":"Startseite (de)","attr":{"id":"de","classname":"icon-folder-open"},"children":[{"data":"Produkte","attr":{"id":"produkte","classname":"icon-folder-open"},"children":[{"data":"Artikel 1","attr":{"id":"artikel-1","classname":""}},{"data":"Artikel 2","attr":{"id":"artikel-2","classname":""}}]}]}]
<!-- apps/navigation/lib/Functions.php -->
<?php
/**
* Print the site tree as an HTML list with the current
* context open as sub-lists up to the first-level children
* of the current page. The currently active page will have
* the class `current` and parents will have the class
* `parent`.
@betaman
betaman / navigation.json
Last active December 12, 2015 08:39
New Navigation JSON for Elefant I18n
[
/*
* this first level nodes will be created via the Language Menu.
* for each active Language there will be a Node
*/
// English
{
"data":"English",
@betaman
betaman / bootstrap.php
Last active December 11, 2015 16:28
i18n Problem
<!-- bootstrap.php -->
<?php
// set the language homepage for dynamic navigation
define ('HOMEPAGE', 'index-' . $i18n->language);
// redirect if they request the default homepage
if ($_SERVER['REQUEST_URI'] === '/' || $_SERVER['REQUEST_URI'] === '/index') {
$controller->redirect ('/' . HOMEPAGE);
@betaman
betaman / section.php
Created December 31, 2012 14:55
Elefant cms Navigation section
<?php
/* these function go to the functions file */
function navigation_has_current_child($children, $pageId){
if(! is_array ($children)){
return false;
} else {
foreach ($children as $item) {
if ($item->attr->id == $pageId || navigation_has_current_child($item->children, $pageId)) {
@betaman
betaman / gist:4218965
Created December 5, 2012 19:58
Missing Template
RuntimeException: Template not found: translator/settings/
Template->render ("translator/settings/", stdClass)
288/www/htdocs/v151009/jv/lib/Form.php
286. $page->add_script ('/js/jquery.verify_values.js');
287. if ($this->js_validation) {
288. return $tpl->render ('admin/default-validation', $o) . $tpl->render ($this->view, $o);
289. }
@betaman
betaman / gist:4218380
Created December 5, 2012 18:50
Error on I18n elefant
ErrorException: Invalid argument supplied for foreach()
Debugger::handle_error (2, "Invalid argument supplied for foreach()", "/www/htdocs/v151009/jv/apps/translator/handlers/build.php", 49, array(16))
49/www/htdocs/v151009/jv/apps/translator/handlers/build.php
47. foreach ($sources as $source) {
48. $files = glob ($source);
49. foreach ($files as $file) {
50. $data = file_get_contents ($file);
@betaman
betaman / editable.php
Created November 6, 2012 21:03
Elefant CMS: Dynamic Blocks and Blocks with Fallback
/* /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 yo
@betaman
betaman / Json.php
Created September 18, 2012 08:15
Restful json api for elefantcms
<?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')