Skip to content

Instantly share code, notes, and snippets.

View jameserie's full-sized avatar

James Erie jameserie

View GitHub Profile
/** * Facebook Page Feed Parser * * @using cURL */ function fb_parse_feed( $page_id, $no = 5 ) { // URL to the Facebook page's RSS feed. $rss_url = 'http://www.facebook.com/feeds/page.php?id=' . $page_id . '&format=rss20'; $curl = curl_init(); // You need to query the feed as a browser. $header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,"; $header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"; $header[] = "Cache-Control: max-age=0"; $header[] = "Connection: keep-alive"; $header[] = "Keep-Alive: 300"; $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7"; $header[] = "Accept-Language: en-us,en;q=0.5"; $header[] = "Pragma: "; // browsers keep this blank. curl_setopt($curl, CURLOPT_URL, $rss_url); curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla'); curl_setopt($curl, CURLOPT_HTTPHEADER, $header); curl_setopt($curl, CURLOPT_REFERER, ''); curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate'); curl_setopt($curl, CURLOPT_AUTOREFERER,
/**
* Add custom taxonomies
*
* Additional custom taxonomies can be defined here
* http://codex.wordpress.org/Function_Reference/register_taxonomy
*/
function add_custom_taxonomies() {
// Add new "Locations" taxonomy to Posts
register_taxonomy('location', 'post', array(
// Hierarchical taxonomy (like categories)
add_action('init', 'demo_register_post_type'); function demo_register_post_type() { register_post_type('demo', array( 'labels' => array( 'name' => 'Demos', 'singular_name' => 'Demo', 'add_new' => 'Add new demo', 'edit_item' => 'Edit demo', 'new_item' => 'New demo', 'view_item' => 'View demo', 'search_items' => 'Search demos', 'not_found' => 'No demos found', 'not_found_in_trash' => 'No demos found in Trash' ), 'public' => true, 'supports' => array( 'title', 'excerpt' ), 'taxonomies' => array('category', 'post_tag') // this is IMPORTANT ));}
@jameserie
jameserie / 0_reuse_code.js
Created October 31, 2013 11:47
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@jameserie
jameserie / gist:988969
Created May 24, 2011 15:51
Convert HTML source to full text
function html2txt($document){
$search = array('@<script[^>]*?>.*?</script>@si', // Strip out javascript
'@<style[^>]*?>.*?</style>@siU', // Strip style tags properly
'@<[?]php[^>].*?[?]>@si', //scripts php
'@<[?][^>].*?[?]>@si', //scripts php
'@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags
'@<![\s\S]*?--[ \t\n\r]*>@' // Strip multi-line comments including CDATA
);$text = preg_replace($search, '', $document);
return $text;
}
@jameserie
jameserie / gist:988966
Created May 24, 2011 15:50
Convert currencies using PHP, Google and cURL
function currency($from_Currency,$to_Currency,$amount) {
$amount = urlencode($amount);
$from_Currency = urlencode($from_Currency);
$to_Currency = urlencode($to_Currency);
$url = "http://www.google.com/ig/calculator?hl=en&q=$amount$from_Currency=?$to_Currency";
$ch = curl_init();
$timeout = 0;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT , "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
@jameserie
jameserie / calc_vat.php
Created May 24, 2011 15:49
Calculate VAT using PHP
function getvat($price){
$vat = 21; // set vat amount
return $price * ($vat / 100);
}
@jameserie
jameserie / calc_age.php
Created May 24, 2011 15:47
Calculate persons age using date of birth
function age($date){
list($year,$month,$day) = explode("-",$date);
$year_diff = date("Y") - $year;
$month_diff = date("m") - $month;
$day_diff = date("d") - $day;
if ($day_diff < 0 || $month_diff < 0) $year_diff--;
return $year_diff;
}