Skip to content

Instantly share code, notes, and snippets.

View JosephLenton's full-sized avatar

Joseph Lenton JosephLenton

View GitHub Profile
/*
* /users/edit/<user id>
* I am editing a user.
*/
get( users, edit, ID ) :-
number( ID ),
is_admin or session( id, ID ),
users:get_user( ID, User ),
users:view( edit, User ).
@JosephLenton
JosephLenton / gist:2818162
Created May 28, 2012 09:35
example PHP site-template
<!DOCTYPE html>
<html>
<head>
<?php content( 'css', 'site/css' ) ?>
</head>
<body>
<?php content() ?>
</body>
@JosephLenton
JosephLenton / gist:2845057
Created May 31, 2012 17:53
wordpress header
<?php
/**
* Starts the PMC Proxy for redirecting to /app/view/blog
*
* @package PlayMyCode
* @subpackage PMC_Proxy
*/
define( 'ACCESS_OK', true );
include_once( $_SERVER["DOCUMENT_ROOT"] . '/flexi/flexi.php' );
<?php
/**
* @param title Large text topic title.
* @param content Text content.
* @param displayTime Display time text such as 'last week'
* @param cssClass CSS class for the post.
* @param id An id for the comment container
* @param options link such as "click to expand"
*/
params( $title, $content, $displayTime, $cssClass, $id, $options );
@JosephLenton
JosephLenton / gist:2891027
Created June 7, 2012 19:25
controller for 5.4
<?
ajax()->login = function() {
// is already logged in
ajax()->verify( function() {
return $this->obj->session->isLoggedIn();
});
// login with all details
ajax()->
verify( function($username, $password, $location, $user, $error) {
@JosephLenton
JosephLenton / gist:2891281
Created June 7, 2012 20:12
login code for 5.4 framework
<?
get( 'login' );
post()->login = function() {
// is already logged in
post()->
verify( function() {
return $this->obj->session->isLoggedIn();
})->
redirect( '/' );
@JosephLenton
JosephLenton / gist:2891648
Created June 7, 2012 21:29
pretty errors
<?
/**
* Pretty Errors
*
* ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
*
* WARNING! It is downright _DANGEROUS_ to use this in production, on
* a live website. It should *ONLY* be used for development.
*
* Pretty Errors allows the outside world to alter your project,
@JosephLenton
JosephLenton / prettyerrors.php
Created June 9, 2012 16:27
pretty errors (as is)
<?
/**
* Pretty Errors
*
* ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
*
* WARNING! It is downright _DANGEROUS_ to use this in production, on
* a live website. It should *ONLY* be used for development.
*
* Pretty Errors allows the outside world to alter your project,
@JosephLenton
JosephLenton / gist:2901687
Created June 9, 2012 16:34
example pretty errors options
\pretty_errors\reportErrors( array(
'ignore_folders' => array( 'flexi\\' ),
'application_folders' => array( 'app\\' ),
'background_text' => 'terse.'
) );
@JosephLenton
JosephLenton / gist:2903598
Created June 10, 2012 02:19
get blog post
<?
get( '/blog/show/{title}' )->
validate( function( $title, &$post ) { $post = $this->model->posts->get( $title ); } )->
action(
function( $post ) {
$this->view( 'blog/post', $post );
},
function( $title ) {
$this->view( '404', "Blog post not found " . h($title) );