Skip to content

Instantly share code, notes, and snippets.

View jbroadway's full-sized avatar

John de Plume jbroadway

View GitHub Profile
@jbroadway
jbroadway / Author.php
Created March 29, 2012 23:39
Example custom form validation in Elefant
<?php
class Author extends Model {
public static function unique_name ($value) {
$res = Author::query ()
->where ('first_name', $_POST['first_name'])
->where ('last_name', $_POST['last_name'])
->count ();
if ($res > 0) {
return false;
@jbroadway
jbroadway / forms_test.php
Created April 4, 2012 23:18
Custom validation of an array of values in Elefant framework.
; <?php /*
[name]
callback = validate_array_not_empty
; */ ?>
@jbroadway
jbroadway / conf_embed.php
Created April 8, 2012 21:37
Custom handler for displaying latest blog headlines with dates
; <?php /*
[myapp/headlines]
label = "My App: Latest Posts"
; */ ?>
@jbroadway
jbroadway / galleries.php
Created May 1, 2012 17:26
List several image galleries
<?php
$galleries = glob ('files/galleries/*');
echo '<ul>';
foreach ($galleries as $gallery) {
// list galleries here
echo '<li><a href="/myapp/gallery?path=' . str_replace ('files/', '', $gallery) . '">' . basename ($gallery) . '</a></li>';
}
echo '</ul>';
@jbroadway
jbroadway / fm.html
Created May 2, 2012 05:42
Calling the jwysiwyg file manager in Elefant without the editor
<!-- apps/test/views/fm.html -->
<script>
function filemanager () {
$.wysiwyg.fileManager.init (function (file) {
$('#file').val (file);
});
return false;
}
@jbroadway
jbroadway / URLify.php
Created May 2, 2012 22:29
URLify vs Urlizer
<?php
/**
* A PHP port of URLify.js from the Django project
* (https://github.com/django/django/blob/master/django/contrib/admin/static/admin/js/urlify.js).
* Handles symbols from Latin languages, Greek, Turkish, Russian, Ukrainian,
* Czech, Polish, and Latvian. Symbols it cannot transliterate
* it will simply omit.
*
* Usage:
@jbroadway
jbroadway / README.md
Created May 24, 2012 17:59
Elefant demo site setup

The demo site is controlleed by two handlers in the apps/demo app:

  • demo/index - Creates a new user when you visit /demo and logs them in
  • demo/reset - Resets the database and files via cron

The files that are modified are:

  • apps/demo - Demo handlers
  • apps/admin/css/admin.css - Added styles for demo reset notice
  • css/mobile.css - Added styles for demo reset notice
@jbroadway
jbroadway / elefant_compiled.php
Created June 7, 2012 14:09
PHP cached template comparison
<h1><?php echo Template::sanitize ($data->title, 'UTF-8'); ?></h1>
<?php if ($data->show_people) { ?>
<ul>
<?php foreach ($data->people as $data->loop_index => $data->loop_value) { ?>
<li><?php echo Template::sanitize ($data->loop_value, 'UTF-8'); ?></li>
<?php } ?>
</ul>
<?php } ?>
@jbroadway
jbroadway / api.js
Created June 27, 2012 17:52
API wrapper example for use with Elefant's Restful class
// the api for accessing the site
var api = (function ($) {
var self = {};
// the prefix for api requests
self.prefix = '/myapi/v1/';
// enable/disable debugging output to the console
self.debug = false;
@jbroadway
jbroadway / postswithicons.html
Created October 11, 2012 14:53
Elefant CMS - Blog headlines with icons
{% if dates %}
{! admin/util/dates !}
{% end %}
<ul>
{% foreach posts %}
<li>
{% if dates %}{{ loop_value->ts|I18n::short_date }} {% end %}
<a href="/blog/post/{{ loop_value->id }}/{{ loop_value->title|URLify::filter }}">
<img src="{{ loop_value->img }}" />