Skip to content

Instantly share code, notes, and snippets.

View SeanJA's full-sized avatar
🦑
🦖

SeanJA SeanJA

🦑
🦖
View GitHub Profile
@SeanJA
SeanJA / form.class.php
Created March 26, 2010 20:30
starting of a form class
<?php
//I hate typing in htmlspecialchars() all the time
function h($var) {
return htmlspecialchars($var);
}
//cake's inflector class
require_once('inflector.class.php');
class form {
/**
* Contains the form as a string
@SeanJA
SeanJA / datetime_52.class.php
Created March 30, 2010 16:38
A fix for missing functionality in php 5.2's DateTime class
<?php
/**
* Provides backwards support for php 5.2's lack of setTimestamp and getTimestamp
*/
class DateTime_52 extends DateTime{
/**
* Set the time of the datetime object by a unix timestamp
* @param int $unixtimestamp
* @return DateTime_52
<?php
/**
* @property-read string $class_name
*/
abstract class rootClass{
/**
* Contains the data for this class
* @var array
*/
protected $data = array();
@SeanJA
SeanJA / poorman_mvc.php
Created April 6, 2010 01:17
a bad way to do mvc...
<?php
$location = isset($_GET['location'])? $_GET['location'] : 'home';
/// include the correct page if it is in our list, or open the home page
switch($location){
case 'blog':
case 'comments':
case 'new_comment':
case 'new_post':
@SeanJA
SeanJA / dummy_classes.php
Created May 21, 2010 17:15
A factory that remembers
<?php
/**
* @property int $id
* @property string $class_name
*/
abstract class root {
/**
* the identifier of this object
* @var int
<?php
/**
* Create a select box
* @param string $name the name of the select box
* @param array $options the options, associative array array('val_1'=>'opt_1' ... )
* @param string $selected the option that is selected
* @param array $attributes associative array of attributes for the select box array('attr_1'=>'val_1', 'attr_2'=>'val_2')
*/
function html_select($name, array $options, $selected=null, array $attributes = array()) {
<?php
//this would come from a database count function
$totalPages = 200;
//presumably this comes from the get variable
$currentPage = 20;
//if the current page > total pages, just set it to the number of pages,
//someone is messing with the url
if ($currentPage > $totalPages) {
$currentPage = $totalPages;
@SeanJA
SeanJA / index.php
Created June 10, 2010 16:53 — forked from gavinblair/index.php
mobile browser detection
<?php
$mobiles = array(
'iphone','ipod','android','blackberry',//and so on
);
$agent = strtolower($_SERVER['HTTP_USER_AGENT']);
if($match = preg_match('/('.implode('|',$mobiles).')/', $agent)){
echo 'mobile';
//include mobile stuff here
} else {
/**
* Try and split a selector into its parts (. # are really the only ones supported)
*/
function splitSelector(selector){
var selectors = [];
selector = selector.split(/(\W)/);
while(selector.length){
if(selector[0].match(/(\.|#)/)){
selectors.push(selector.shift() +''+ selector.shift());
} else if(selector[0].match(/\w/)) {
<?php
//add rel="nofollow" and target="_blank" to links with htmlpurifier 4.1.1
require_once '../../library/HTMLPurifier.auto.php';
class HTMLPurifier_AttrTransform_AValidator extends HTMLPurifier_AttrTransform
{
var $name = 'Link validation';
function transform($attr, $config, $context) {
$attr['target'] = '_blank';