<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The Code Collective</title>
	<atom:link href="http://code.hyperspatial.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://code.hyperspatial.com</link>
	<description>The Hyperspatial collection of code snippets</description>
	<lastBuildDate>Thu, 23 Feb 2012 02:42:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Better Truncator</title>
		<link>http://code.hyperspatial.com/1493/better-truncator/</link>
		<comments>http://code.hyperspatial.com/1493/better-truncator/#comments</comments>
		<pubDate>Mon, 20 Feb 2012 23:31:57 +0000</pubDate>
		<dc:creator>Adam J Nowak</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[strings]]></category>

		<guid isPermaLink="false">http://code.hyperspatial.com/1493/better-truncator/</guid>
		<description><![CDATA[&#60;?php $longString =&#34;http://google-maps.pace.com?var=ntahohk5eoui564x56oe4u564oa5oeu5aoeu5ao5u5eu56io14eui564oe&#34;; $separator = '/.../'; $separatorlength = strlen($separator) ; $maxlength = 25 - $separatorlength; $start = $maxlength / 2 ;//Change to max length to truncate end $trunc = strlen($longString) - $maxlength; echo substr_replace($longString, $separator, $start, $trunc); ?&#62;]]></description>
			<content:encoded><![CDATA[&lt;?php

$longString =&quot;http://google-maps.pace.com?var=ntahohk5eoui564x56oe4u564oa5oeu5aoeu5ao5u5eu56io14eui564oe&quot;;
$separator = '/.../';
$separatorlength = strlen($separator) ;
$maxlength = 25 - $separatorlength;
$start = $maxlength / 2 ;//Change to max length to truncate end
$trunc =  strlen($longString) - $maxlength;

echo substr_replace($longString, $separator, $start, $trunc);

?&gt;]]></content:encoded>
			<wfw:commentRss>http://code.hyperspatial.com/1493/better-truncator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Better mysqli table creation</title>
		<link>http://code.hyperspatial.com/1492/better-mysqli-table-creation/</link>
		<comments>http://code.hyperspatial.com/1492/better-mysqli-table-creation/#comments</comments>
		<pubDate>Mon, 20 Feb 2012 21:47:05 +0000</pubDate>
		<dc:creator>Adam J Nowak</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://code.hyperspatial.com/1492/better-mysqli-table-creation/</guid>
		<description><![CDATA[&#60;?php $mysqli = new mysqli(DB_SERVER,DB_USER,DB_PASS,DB_NAME); if($mysqli-&#62;connect_errno) echo &#34;Failed to connect to MySQL: (&#34; . $mysqli-&#62;connect_errno . &#34;) &#34; . $mysqli-&#62;connect_error; echo $mysqli-&#62;host_info . &#34;\n&#34;; $query = &#34;CREATE TABLE hwt_tools( id mediumint(8) NOT NULL AUTO_INCREMENT, user_id mediumint(8), category_id mediumint(8), target_url varchar(255), favicon_url varchar(255), desc_text text, UNIQUE KEY id (id) );&#34;; //Use this to safely create a [...]]]></description>
			<content:encoded><![CDATA[&lt;?php
$mysqli = new mysqli(DB_SERVER,DB_USER,DB_PASS,DB_NAME);

if($mysqli-&gt;connect_errno) echo &quot;Failed to connect to MySQL: (&quot; . $mysqli-&gt;connect_errno . &quot;) &quot; . $mysqli-&gt;connect_error;
echo $mysqli-&gt;host_info . &quot;\n&quot;;

$query = &quot;CREATE TABLE hwt_tools(
	id mediumint(8) NOT NULL AUTO_INCREMENT,
	user_id mediumint(8),
	category_id mediumint(8),
	target_url varchar(255),
	favicon_url varchar(255),
	desc_text text,
	UNIQUE KEY id (id)
);&quot;;

//Use this to safely create a table while testing
if(!$mysqli-&gt;query($query)) echo &quot;Table creation failed: (&quot; . $mysqli-&gt;errno . &quot;) &quot; . $mysqli-&gt;error;

//Use this to drop existing table and start a new
//if(!$mysqli-&gt;query(&quot;DROP TABLE IF EXISTS hwt_tools&quot;) || !$mysqli-&gt;query($query)) echo &quot;Table creation failed: (&quot; . $mysqli-&gt;errno . &quot;) &quot; . $mysqli-&gt;error;

?&gt;]]></content:encoded>
			<wfw:commentRss>http://code.hyperspatial.com/1492/better-mysqli-table-creation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Action type callbacks</title>
		<link>http://code.hyperspatial.com/1491/action-type-callbacks/</link>
		<comments>http://code.hyperspatial.com/1491/action-type-callbacks/#comments</comments>
		<pubDate>Mon, 20 Feb 2012 18:29:04 +0000</pubDate>
		<dc:creator>Adam J Nowak</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://code.hyperspatial.com/1491/action-type-callbacks/</guid>
		<description><![CDATA[&#60;?php //Core Functions /* Insert Html */ function insert($source_id){ global $inserts; if($inserts[$source_id]){ foreach($inserts[$source_id] as $callback) call_user_func($callback); } } /* Insert Callback */ function insert_callback($source_id,$callback){ global $inserts; $inserts[$source_id][] = $callback; } ?&#62; &#60;!-- HTML in Header --&#62; &#60;ul id=&#34;aux-nav&#34;&#62; &#60;li&#62;Hello&#60;/li&#62; &#60;li&#62;Aloha&#60;/li&#62; &#60;?php insert('aux-nav') ?&#62; &#60;/ul&#62; &#60;?php //Callback function in a module or plugin function add_links(){?&#62; &#60;li&#62;Hola&#60;/li&#62; [...]]]></description>
			<content:encoded><![CDATA[&lt;?php //Core Functions

/* Insert Html */
function insert($source_id){
	global $inserts;
	if($inserts[$source_id]){
		foreach($inserts[$source_id] as $callback) call_user_func($callback);
	}
}

/* Insert Callback */
function insert_callback($source_id,$callback){
	global $inserts;
	$inserts[$source_id][] = $callback;
}

?&gt;

&lt;!-- HTML in Header --&gt;
&lt;ul id=&quot;aux-nav&quot;&gt;
	&lt;li&gt;Hello&lt;/li&gt;
	&lt;li&gt;Aloha&lt;/li&gt;
	&lt;?php insert('aux-nav') ?&gt;
&lt;/ul&gt;

&lt;?php //Callback function in a module or plugin

function add_links(){?&gt;
	&lt;li&gt;Hola&lt;/li&gt;
	&lt;?php	
}
insert_callback('aux-nav','add_links');

?&gt;]]></content:encoded>
			<wfw:commentRss>http://code.hyperspatial.com/1491/action-type-callbacks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Input action on enter</title>
		<link>http://code.hyperspatial.com/1490/input-action-on-enter/</link>
		<comments>http://code.hyperspatial.com/1490/input-action-on-enter/#comments</comments>
		<pubDate>Fri, 17 Feb 2012 21:53:28 +0000</pubDate>
		<dc:creator>Adam J Nowak</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[forms]]></category>

		<guid isPermaLink="false">http://code.hyperspatial.com/1490/input-action-on-enter/</guid>
		<description><![CDATA[&#60;input id=&#34;hgm-address&#34; type=&#34;text&#34; onKeyPress=&#34;if(event.keyCode == 13) { functionToRun(); return false;}&#34;&#62;]]></description>
			<content:encoded><![CDATA[&lt;input id=&quot;hgm-address&quot; type=&quot;text&quot; onKeyPress=&quot;if(event.keyCode == 13) { functionToRun(); return false;}&quot;&gt;]]></content:encoded>
			<wfw:commentRss>http://code.hyperspatial.com/1490/input-action-on-enter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Improved Shortcode</title>
		<link>http://code.hyperspatial.com/1489/improved-shortcode/</link>
		<comments>http://code.hyperspatial.com/1489/improved-shortcode/#comments</comments>
		<pubDate>Wed, 15 Feb 2012 16:58:10 +0000</pubDate>
		<dc:creator>Adam J Nowak</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[shortcode]]></category>

		<guid isPermaLink="false">http://code.hyperspatial.com/1489/improved-shortcode/</guid>
		<description><![CDATA[&#60;?php /* ~~~~~~~~~~~~ Test Routine ~~~~~~~~~~~~*/ //Default Style hgm_map(); //Array Style $test_args = array('width' =&#62; 500, 'height' =&#62; 300); hgm_map($test_args); //Query String Style hgm_map('width=200&#38;height=100'); //Shortcode = [hgm_map width=&#34;600&#34; height=&#34;400&#34;] /* ~~~~~~~~~~~~ Functions ~~~~~~~~~~~~*/ /* Main Function */ function hgm_map($args,$shortcode = false){ if($shortcode) ob_start(); //Halt output if shortcode //Apply defauilts to argumentns and extract $defaults = [...]]]></description>
			<content:encoded><![CDATA[&lt;?php

/* ~~~~~~~~~~~~ Test Routine ~~~~~~~~~~~~*/

//Default Style
hgm_map();

//Array Style
$test_args = array('width' =&gt; 500, 'height' =&gt; 300);
hgm_map($test_args);

//Query String Style
hgm_map('width=200&amp;height=100');

//Shortcode = [hgm_map width=&quot;600&quot; height=&quot;400&quot;]



/* ~~~~~~~~~~~~ Functions ~~~~~~~~~~~~*/

/* Main Function */
function hgm_map($args,$shortcode = false){
	if($shortcode) ob_start(); //Halt output if shortcode
	
	//Apply defauilts to argumentns and extract
	$defaults = array(
		'width' =&gt; '600',
		'height' =&gt; '400'
	);
	$final_args = wp_parse_args($args,$defaults);
	extract($final_args,EXTR_SKIP);
	?&gt;
    
	&lt;p&gt;Width Value = &lt;?php echo $width ?&gt;&lt;/p&gt;
	&lt;p&gt;Height Value = &lt;?php echo $height ?&gt;&lt;/p&gt;
	
	&lt;?php
	if($shortcode){
		$main_function_output = ob_get_contents();
		ob_end_clean();
		return $main_function_output;
	}
}

/* Shortcode - [hgm_map width=&quot;600&quot; height=&quot;400&quot;] */
function hgm_shortcode($args){ return hgm_map($args,true); }
add_shortcode('hgm_map','hgm_shortcode');

?&gt;]]></content:encoded>
			<wfw:commentRss>http://code.hyperspatial.com/1489/improved-shortcode/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SSL check</title>
		<link>http://code.hyperspatial.com/1488/ssl-check/</link>
		<comments>http://code.hyperspatial.com/1488/ssl-check/#comments</comments>
		<pubDate>Tue, 14 Feb 2012 22:12:05 +0000</pubDate>
		<dc:creator>Adam J Nowak</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[ssl]]></category>

		<guid isPermaLink="false">http://code.hyperspatial.com/1488/ssl-check/</guid>
		<description><![CDATA[&#60;?php /* SSL Check */ function gm_ssl_check(){ if($_SERVER['HTTPS'] == 'on') return true; } ?&#62;]]></description>
			<content:encoded><![CDATA[&lt;?php
/* SSL Check */
function gm_ssl_check(){ if($_SERVER['HTTPS'] == 'on') return true; }
?&gt;]]></content:encoded>
			<wfw:commentRss>http://code.hyperspatial.com/1488/ssl-check/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BP profile data</title>
		<link>http://code.hyperspatial.com/1483/bp-profile-data/</link>
		<comments>http://code.hyperspatial.com/1483/bp-profile-data/#comments</comments>
		<pubDate>Mon, 13 Feb 2012 21:24:38 +0000</pubDate>
		<dc:creator>Adam J Nowak</dc:creator>
				<category><![CDATA[Buddypress]]></category>
		<category><![CDATA[xprofile]]></category>

		<guid isPermaLink="false">http://code.hyperspatial.com/1483/bp-profile-data/</guid>
		<description><![CDATA[&#60;?php xprofile_set_field_data('City',$user_id,'LocoMoco'); //Change Simple Field ?&#62; &#60;?php echo bp_profile_field_data( 'field=City' ); //Get Data ?&#62; &#60;?php //Use for checkboxes and dropdowns - Have not tested this, xprofile_set_field_data seems to work to change value set in a dropdown $value = maybe_serialize( [An Array of your values] ); xprofile_set_field_data( $field_name, $user_set_id, $value); ?&#62;]]></description>
			<content:encoded><![CDATA[&lt;?php xprofile_set_field_data('City',$user_id,'LocoMoco'); //Change Simple Field ?&gt;

&lt;?php echo bp_profile_field_data( 'field=City' ); //Get Data ?&gt;

&lt;?php //Use for checkboxes and dropdowns - Have not tested this, xprofile_set_field_data seems to work to change value set in a dropdown
$value = maybe_serialize( [An Array of your values] );
xprofile_set_field_data( $field_name, $user_set_id, $value);
?&gt;]]></content:encoded>
			<wfw:commentRss>http://code.hyperspatial.com/1483/bp-profile-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WP plugin path constants</title>
		<link>http://code.hyperspatial.com/1482/wp-plugin-path-constants/</link>
		<comments>http://code.hyperspatial.com/1482/wp-plugin-path-constants/#comments</comments>
		<pubDate>Thu, 09 Feb 2012 22:54:27 +0000</pubDate>
		<dc:creator>Adam J Nowak</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[constants]]></category>
		<category><![CDATA[path]]></category>

		<guid isPermaLink="false">http://code.hyperspatial.com/1482/wp-plugin-path-constants/</guid>
		<description><![CDATA[&#60;?php define('WPS_PLUGIN',WP_PLUGIN_URL . '/' . basename(dirname(__FILE__)) . '/'); define('WPS_PLUGIN_SERVERPATH',dirname(__FILE__) . '/'); ?&#62;]]></description>
			<content:encoded><![CDATA[&lt;?php

define('WPS_PLUGIN',WP_PLUGIN_URL . '/' . basename(dirname(__FILE__)) . '/');
define('WPS_PLUGIN_SERVERPATH',dirname(__FILE__) . '/');

?&gt;]]></content:encoded>
			<wfw:commentRss>http://code.hyperspatial.com/1482/wp-plugin-path-constants/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Box sizing</title>
		<link>http://code.hyperspatial.com/1481/box-sizing/</link>
		<comments>http://code.hyperspatial.com/1481/box-sizing/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 17:21:03 +0000</pubDate>
		<dc:creator>Adam J Nowak</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://code.hyperspatial.com/1481/box-sizing/</guid>
		<description><![CDATA[/* apply a natural box layout model to all elements */ * { box-sizing: border-box; -moz-box-sizing: border-box; }]]></description>
			<content:encoded><![CDATA[/* apply a natural box layout model to all elements */
* { box-sizing: border-box; -moz-box-sizing: border-box; }]]></content:encoded>
			<wfw:commentRss>http://code.hyperspatial.com/1481/box-sizing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Page Window</title>
		<link>http://code.hyperspatial.com/1480/page-window/</link>
		<comments>http://code.hyperspatial.com/1480/page-window/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 17:00:05 +0000</pubDate>
		<dc:creator>Adam J Nowak</dc:creator>
				<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://code.hyperspatial.com/1480/page-window/</guid>
		<description><![CDATA[&#60;?php /* Plugin Name: Mad Page Window Plugin URI: http://www.hyperspatial.com/ Description: Display WordPress page content on your homepage Version: 1.0 Author: Adam J Nowak Author URI: http://www.hyperspatial.com/ License: GPL2 */ /* Usage Example: &#60;?php $window1 = new MadPageWindow(1434) //Create Loop Window by Page ID ?&#62; &#60;h3&#62;&#60;?php $window1-&#62;title() ?&#62;&#60;/h3&#62; &#60;div&#62;&#60;?php $window1-&#62;excerpt() ?&#62;&#60;/div&#62; &#60;?php $window2 = new [...]]]></description>
			<content:encoded><![CDATA[&lt;?php
/*
Plugin Name: Mad Page Window
Plugin URI: http://www.hyperspatial.com/
Description: Display WordPress page content on your homepage 
Version: 1.0
Author: Adam J Nowak
Author URI: http://www.hyperspatial.com/
License: GPL2
*/

/*
Usage Example:

&lt;?php $window1 = new MadPageWindow(1434) //Create Loop Window by Page ID ?&gt;
&lt;h3&gt;&lt;?php $window1-&gt;title() ?&gt;&lt;/h3&gt;
&lt;div&gt;&lt;?php $window1-&gt;excerpt() ?&gt;&lt;/div&gt;

&lt;?php $window2 = new MadPageWindow(1434) ?&gt;
&lt;?php $var_to_hold = $window2-&gt;get_content() //Use get_content if you don't print this right away ?&gt;
&lt;div&gt;&lt;?php echo &quot;Don't print this right away: &lt;br&gt;&quot; . $var_to_hold ?&gt;&lt;/div&gt;

&lt;?php $window3 = new MadPageWindow(1436) ?&gt;
&lt;h3&gt;&lt;?php $window3-&gt;title() ?&gt;&lt;/h3&gt;
&lt;div&gt;&lt;?php $window3-&gt;content() ?&gt;&lt;/div&gt;
*/

class MadPageWindow{
	private $_page_id,$_title,$_content,$_excerpt;
	public function __construct($page_id){
		$this-&gt;_page_id = $page_id;
		$this-&gt;loop();
	}
	
	/* ~~~~~~~~~~ Private Methods ~~~~~~~~~~ */
	
	private function loop(){
		$mad_query = new WP_Query('page_id=' . $this-&gt;_page_id);
		while($mad_query-&gt;have_posts()) : $mad_query-&gt;the_post();
		$this-&gt;_title = get_the_title();
		$this-&gt;_content = get_the_content();
		$this-&gt;_excerpt = get_the_excerpt();	
		endwhile;
		wp_reset_postdata();
	}
	
	/* ~~~~~~~~~~ Public Methods ~~~~~~~~~~ */
	
	public function title(){ echo $this-&gt;get_title(); }
	public function get_title(){ return $this-&gt;_title; }
	
	public function content(){ echo $this-&gt;get_content(); }
	public function get_content(){ return $this-&gt;_content; }
	
	public function excerpt(){ echo $this-&gt;get_excerpt(); }
	public function get_excerpt(){ return $this-&gt;_excerpt; }
}
?&gt;]]></content:encoded>
			<wfw:commentRss>http://code.hyperspatial.com/1480/page-window/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

