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 | |
//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 |
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 | |
/** | |
* 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 |
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 | |
/** | |
* @property-read string $class_name | |
*/ | |
abstract class rootClass{ | |
/** | |
* Contains the data for this class | |
* @var array | |
*/ | |
protected $data = array(); |
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 | |
$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': |
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 | |
/** | |
* @property int $id | |
* @property string $class_name | |
*/ | |
abstract class root { | |
/** | |
* the identifier of this object | |
* @var int |
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 | |
/** | |
* 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()) { |
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 | |
//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; |
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 | |
$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 { |
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
/** | |
* 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/)) { |
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 | |
//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'; |
OlderNewer