<?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>Creative Gray Matter &#187; Code</title>
	<atom:link href="http://www.creativegraymatter.com/category/code/feed" rel="self" type="application/rss+xml" />
	<link>http://www.creativegraymatter.com</link>
	<description></description>
	<lastBuildDate>Fri, 16 Jul 2010 18:23:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>WordPress Events Calendar</title>
		<link>http://www.creativegraymatter.com/blog/wordpress-events-calendar</link>
		<comments>http://www.creativegraymatter.com/blog/wordpress-events-calendar#comments</comments>
		<pubDate>Thu, 08 Jul 2010 00:16:33 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.creativegraymatter.com/?p=292</guid>
		<description><![CDATA[Not happy with current offerings, I created a plug to add an events calendar to my client&#8217;s sites.  You can check out the demo events calendar here. A few features: Many types of repeating events. Easy to set up.  Let the plugin know what page name you want to use and your good to go. [...]]]></description>
			<content:encoded><![CDATA[<p>Not happy with current offerings, I created a plug to add an events calendar to my client&#8217;s sites.  You can check out the <a href="http://www.creativegraymatter.com/calendar">demo events calendar here</a>.<span id="more-292"></span></p>
<p>A few features:</p>
<ul>
<li>Many types of repeating events.</li>
<li>Easy to set up.  Let the plugin know what page name you want to use and your good to go.</li>
<li>Exclude events from certain dates every year such as holidays.  You can also include dates to an event if it doesn&#8217;t fall on a specific repeat pattern.</li>
<li>Each event has its own page.  Great for SEO and direct linking to events for more information.</li>
<li>Add unlimited events.  Great for fitness centers, schools, organizations, and companies.</li>
<li>Create categories for easy viewing and sorting.</li>
<li>Automatic print view to for easy printing and saving ink.</li>
</ul>
<p>Please let me know if you find any bugs or have some suggestions.  I&#8217;ve built it from the requirements of my clients and am always looking to improve it.</p>
<h2>Install</h2>
<ul>
<li>Unzip the `cgm_calendar.zip` file.</li>
<li>Upload the the `cgm_calendar` folder (not just the files in it!) to your `wp-contents/plugins` folder. If you&#8217;re using FTP, use &#8216;binary&#8217; mode.</li>
</ul>
<h2>Activate</h2>
<ul>
<li>In your WordPress administration, go to the Plugins page</li>
<li>Activate the CGM Calendar plugin and a subpage for CGM Calendar will appear in your Settings menu and also as its own menu.</li>
</ul>
<h2>Display</h2>
<p>There are three ways to show the calendar on your site.</p>
<ul>
<li>Go to Settings -&gt; CGM Calendar and change the settings to what to you.  Set the page name to the url you want to display the calendar and visit http://www.yoursiteurl.com/pagename and it will appear. No page or post creation required</li>
<li>Add the short code [ cgm-event-calendar ] (with no spaces) to your page or post content you wish to display the calendar</li>
<li>Use the php function call &lt;?php cgm_event_calendar(); ?&gt; to display the calendar where you wish.</li>
</ul>
<p><strong>To display upcoming events:</strong></p>
<ol>
<li>Go to Settings -&gt; CGM Calendar and set the Calendar URL to the full url where the calendar resides.  Default would be http://www.yoururl.com/calendar</li>
<li>Modify the List Format setting if desired.  Note that you will still need to wrap any list in a ul/ol when called.</li>
<li>Use the function echo cgm_list_upcoming_events(array(&#8216;num_events&#8217; =&gt; 5, &#8216;tag_id&#8217; =&gt; &#8217;1,2&#8242;)); and change the num_events to how many you want to show and the tag_id list to the tagged events, or remove it to show all.</li>
<li>You may also use the short code [ cgm-upcoming-events num_events=10 tag_id=1,2 ] to display the list.</li>
</ol>
<p>If you wish, you can override the default css and print view template by copying the files, css/calendar.css and print_view.php to the base of your template directory.</p>
<h2>Settings</h2>
<p>Go to Settings -&gt; CGM Calendar</p>
<ul>
<li><strong>Page Name</strong> &#8211; Sets the default url to display the calendar with no page or post creation required</li>
<li><strong>Default View</strong> &#8211; Sets the default view of the calendar, by Month or Week when visitors view your calendar</li>
<li><strong>Start Time</strong> &#8211; Sets the time that the weekly calendar will start on.  If you set the start time for 8am and have an event at 7am, the event will not show on the weekly calendar.</li>
<li><strong>End Time</strong> &#8211; Sets the time that the weekly calendar will end on.  If you set the end time for 5pm and have an event at 6pm, the event will not show on the weekly calendar.</li>
</ul>
<p><a href="http://wordpress.org/extend/plugins/cgm-event-calendar/" target="_blank">Download it here.</a></p>
<p>If you like the plugin, do me a favor and rate it too!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.creativegraymatter.com/blog/wordpress-events-calendar/feed</wfw:commentRss>
		<slash:comments>156</slash:comments>
		</item>
		<item>
		<title>Sanitizing User Input with PHP</title>
		<link>http://www.creativegraymatter.com/blog/sanitizing-user-input-with-php</link>
		<comments>http://www.creativegraymatter.com/blog/sanitizing-user-input-with-php#comments</comments>
		<pubDate>Thu, 23 Jul 2009 14:57:49 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.creativegraymatter.com/?p=255</guid>
		<description><![CDATA[If you don&#8217;t already know, not sanitizing user input in your scripts is very bad.  It can lead to XSS attacks which I won&#8217;t get into here, there is plenty of info out there.  It is especially bad if you are saving the user input into databases as a evil hacker could end up deleting [...]]]></description>
			<content:encoded><![CDATA[<p>If you don&#8217;t already know, not sanitizing user input in your scripts is very bad.  It can lead to XSS attacks which I won&#8217;t get into here, there is plenty of info out there.  It is especially bad if you are saving the user input into databases as a evil hacker could end up deleting everything you&#8217;ve got. <span id="more-255"></span> I don&#8217;t pretend to be a security expert but the following code is what I use to clean any input from the user.  I use this whether I am creating a contact form and just emailing the data off or if I&#8217;m inserting some information into a database.  If you see anything wrong, please let me know so I can adjust it.</p>
<pre>function clean_input($data) {
    $return = array();
    foreach ($data as $key =&gt; $value) {
        if (is_array($value)) {
            foreach ($value as $key2 =&gt; $value2) {
                if (get_magic_quotes_gpc()) {
                    $value2 = stripslashes($value2);
                }
                if (!is_numeric($value2)) {
                    $value2 = mysql_escape_string($value2);
                }
                $return[$key][$key2] = $value2;
            }
        } else {
            if (get_magic_quotes_gpc()) {
                $value = stripslashes($value);
            }
            if (!is_numeric($value)) {
                $value = mysql_escape_string($value);
            }
            $return[$key] = $value;
         }
    }
    return $return;
}</pre>
<p>To use the function you can call</p>
<pre>$clean = clean_input($_POST); // or $_GET</pre>
<p>Then you can use $clean['whatever'] in your code.</p>
<p>A couple notes:</p>
<ul>
<li>I am not using mysql_real_escape_string, the updated version of the php function.  I can&#8217;t assume that you&#8217;ve opened a database connection before calling the function.  This wouldn&#8217;t be needed for things such as contact forms on a static site.  If you have a database connection open, I&#8217;d change the mysql_escape_string to mysql_real_escape string.</li>
<li>This doesn&#8217;t do any checks for proper type and format of any input, you&#8217;ll have to do that on your own next.</li>
</ul>
<p>It can handle two dimension arrays so if for example you have a multiple select box, it will correctly cycle through each value.  Hope this helps you out there.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.creativegraymatter.com/blog/sanitizing-user-input-with-php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Member&#8217;s only area in WordPress</title>
		<link>http://www.creativegraymatter.com/blog/members-only-area-in-wordpress</link>
		<comments>http://www.creativegraymatter.com/blog/members-only-area-in-wordpress#comments</comments>
		<pubDate>Wed, 22 Jul 2009 21:46:01 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.creativegraymatter.com/?p=249</guid>
		<description><![CDATA[The other day, a client requested a member&#8217;s only area on their site.  They had a whole section they only wanted people who had an account to be able to see that will contain things such as forms and articles.  Luckily this is pretty easy to do. First determine what page or pages you need [...]]]></description>
			<content:encoded><![CDATA[<p>The other day, a client requested a member&#8217;s only area on their site.  They had a whole section they only wanted people who had an account to be able to see that will contain things such as forms and articles.  Luckily this is pretty easy to do.<span id="more-249"></span></p>
<p>First determine what page or pages you need to limit access to.  Luckily for me, all the pages had a single parent which made it real easy.  Also I will go through the steps to limit access to pages.  For posts or other elements such as sidebar information, the steps would be similar, just the theme files would change.</p>
<p>First, I am using the plugin <a href="http://wordpress.org/extend/plugins/sidebar-login/" target="_blank">Sidebar Login</a> by Mike Jolley to create a nice login form inside the page.  Download and active that.</p>
<p>Next, open up page.php in your themes folder.  I first check to see if the current page is one that we are protecting.  To do this I use</p>
<pre>if (($pos = strpos($_SERVER["REQUEST_URI"], 'protectedpagename')) !== false) {
   // This is a page we are protecting
}</pre>
<p>Now for the site I was building, all the pages that needed to be protected where children of the parent.  In other words they all had urls such as http://www.testsite.com/protecdpagename/childpagename.  If you where protecting many pages with different names you&#8217;d have to extend the if statement to check for them all.</p>
<p>Now, if the user comes across a page whose access is limited, we need to check whether or not they are logged in using:</p>
<pre>if (@is_user_logged_in()) {
    // user is not logged in
}</pre>
<p>If they are not logged in, we can display the login form from the Sidebar Login plugin and set a flag to say they are not logged in. using:</p>
<pre>$can_view_page = false;
sidebarlogin();</pre>
<p>If they are logged in we can continue.</p>
<p>Now we can display the page content as normal if the flag $can_view_page is true.</p>
<p>Here is the entire code:</p>
<pre>$can_view_page = true;
if (($pos = strpos($_SERVER["REQUEST_URI"], 'protectedpagename')) !== false) {
    // This is a page we are protecting
    if (!is_user_logged_in()) {
        // user is not logged in
        $can_view_page = false;
        sidebarlogin();
    }
}

if ($can_view_page) {
   // place page loop here
}</pre>
<p>You can stop here if you wish but I used another technique to clean up the process a little more.  Using the technique from <a href="http://nathany.com/developer/redirecting-wordpress-subscribers/" target="_blank">http://nathany.com/developer/redirecting-wordpress-subscribers/</a> I was able to redirect the user to the protect page after they logged in.  This also works when if they happen to log in by forgetting their password and logging in that way.</p>
<p>It should be mentioned that the site I did this on does not allow people to register themselves.  This would be a problem and you&#8217;d have to modify the script to accommodate that.</p>
<p>Let me know what you think.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.creativegraymatter.com/blog/members-only-area-in-wordpress/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Google Analytics Dashboard</title>
		<link>http://www.creativegraymatter.com/blog/google-analytics-dashboard</link>
		<comments>http://www.creativegraymatter.com/blog/google-analytics-dashboard#comments</comments>
		<pubDate>Mon, 13 Jul 2009 17:26:28 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.creativegraymatter.com/?p=233</guid>
		<description><![CDATA[So I&#8217;ve finally got around to completing my first WordPress plugin.   It&#8217;s a google analytics dashboard to get a nice overview of your site&#8217;s stats without having to go to the Analytics page.  The charts are all displayed using a very cool project Open Flash Charts 2. I also used the Google Analytics PHP Interface [...]]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;ve finally got around to completing my first WordPress plugin.   It&#8217;s a google analytics dashboard to get a nice overview of your site&#8217;s stats without having to go to the Analytics page.  The charts are all displayed using a very cool project <a href="http://teethgrinder.co.uk/open-flash-chart-2/" target="_blank">Open Flash Charts 2</a>.<br />
<span id="more-233"></span><br />
I also used the Google Analytics PHP Interface by <a href="http://code.google.com/p/gapi-google-analytics-php-interface/" target="_blank">Stig Manning</a> to pull the google analytics data.</p>
<p>Installation is very simple, unzip the package and upload to your plugins directory.  Then under the &#8220;Settings&#8221; Menu, go to &#8220;GA Configuration&#8221; and enter in your accounts details.  The plugin can optionally add the Google Analytics code to the footer of your site if its not already included.</p>
<p>A few FAQ from the readme file:</p>
<p><strong>Why do I need to enter my username and password?</strong><br />
The google analytics api requires authentication and this is the cleanest way to accomplish that.</p>
<p><strong> What&#8217;s my site&#8217;s Profile ID?</strong><br />
The sites Profile ID can be found by viewing the Google Analytic&#8217;s reports for the site.  Then in the URL the Profile ID can be found after id= such as id=1234567.  1234567 would be the sites Profile ID.</p>
<p><strong>What&#8217;s my site&#8217;s Web ID?</strong><br />
The optional Web ID is found in the list of your site profiles after the name of the site.  It will look something like UA-1234567-0.  You only need to enter this if you wish for the plugin to include the google analytics code into your sites footer to begin tracking stats.</p>
<p>Here are some screen shots of the plugin in action:</p>
<p><img class="alignnone size-large wp-image-235" title="screenshot-1" src="http://www.creativegraymatter.com/wp-content/uploads/2009/07/screenshot-1-1024x628.jpg" alt="screenshot-1" width="652" /></p>
<p><img class="alignnone size-large wp-image-234" title="screenshot-2" src="http://www.creativegraymatter.com/wp-content/uploads/2009/07/screenshot-2-1024x694.jpg" alt="screenshot-2" width="652" /></p>
<h3>A few notes:</h3>
<ul>
<li>Please consider this a beta version.  There are still a few bugs to work out.  If you come across one let me know in the comments.</li>
<li>There is currently a JavaScript error in IE.  If you figure it out, please let me know so I can update the plugin.  Hopefully I&#8217;ll figure it out soon.</li>
<li>This plugin does NOT work in environments using php4.  The class to gather the Google Data is written using php 5 functions and can not be changed.  If I find a good alternative or have the time to rewrite the class, I&#8217;ll update the plugin.</li>
<li>Someone has said they can&#8217;t see the graphs.  I can&#8217;t replicate this issue but it might have something to do with not uploading the swf files in binary mode.  If someone else has the same problem let me know.</li>
</ul>
<p>I&#8217;ll be adding more reports and more details when I get the time.  Enjoy and let me know what you think.</p>
<p><em><strong><a href="http://www.creativegraymatter.com/wp-content/uploads/2009/07/cgm_google_analytics.zip">Download the plugin here.</a><br />
</strong></em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.creativegraymatter.com/blog/google-analytics-dashboard/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Validating Emails with PHP</title>
		<link>http://www.creativegraymatter.com/blog/validating-emails-with-php</link>
		<comments>http://www.creativegraymatter.com/blog/validating-emails-with-php#comments</comments>
		<pubDate>Mon, 13 Apr 2009 15:44:31 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.creativegraymatter.com/?p=179</guid>
		<description><![CDATA[Often times you will have a contact form on your site. When asking for customer email addresses you may want to check for correctness to make sure they have not forgotten an important part that will leave the email useless. Below is the code that I use to check for valid emails: // VALIDATE EMAIL [...]]]></description>
			<content:encoded><![CDATA[<p>Often times you will have a contact form on your site.  When asking for customer email addresses you may want to check for correctness to make sure they have not forgotten an important part that will leave the email useless.  Below is the code that I use to check for valid emails:<br />
<span id="more-179"></span></p>
<pre>
// VALIDATE EMAIL ADDRESS TO CHECK FOR CORRECT FORMAT
function check_email_address($email) {
	// First, we check that there's one @ symbol, and that the lengths are right
	if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
		// Email invalid - wrong number of characters in one section, or wrong number of @ symbols.
		return false;
	}
	// Split it into sections to make life easier
	$email_array = explode("@", $email);
	$local_array = explode(".", $email_array[0]);
	for ($i = 0; $i < sizeof($local_array); $i++) {
		if (!ereg("^(([A-Za-z0-9!$%&#038;'*+/=?^_`{|}~-][A-Za-z0-9!$%&#038;'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) {
			return false;
		}
	}
	// Check if domain is IP. If not, it should be valid domain name
	if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) {
		$domain_array = explode(".", $email_array[1]);
		if (sizeof($domain_array) < 2) {
			return false; // Not enough parts to domain
		}
		for ($i = 0; $i < sizeof($domain_array); $i++) {
			if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) {
				return false;
			}
		}
	}
	return true;
}
</pre>
<p>then you can check any email address using:</p>
<pre>
if (!check_email_address($email)) {
	$error = 'This email is invalid!';
}
</pre>
<p>Hopefully this helps, I use this a lot in my coding.  If you see something it might not catch, let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.creativegraymatter.com/blog/validating-emails-with-php/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>CSS Reset</title>
		<link>http://www.creativegraymatter.com/blog/css-reset</link>
		<comments>http://www.creativegraymatter.com/blog/css-reset#comments</comments>
		<pubDate>Tue, 27 Jan 2009 21:08:38 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[css]]></category>

		<guid isPermaLink="false">http://www.creativegraymatter.com/?p=93</guid>
		<description><![CDATA[Every site I create, I always use the same basic css to get going.  It helps clear any default browser settings and levels the playing field between them. There are a few notable css reset sheets out there such as ones from Eric Meyer and Yahoo.  I have tried both and think both are overkill [...]]]></description>
			<content:encoded><![CDATA[<p>Every site I create, I always use the same basic css to get going.  It helps clear any default browser settings and levels the playing field between them.</p>
<p>There are a few notable css reset sheets out there such as ones from <a href="http://meyerweb.com/eric/thoughts/2007/05/01/reset-reloaded/" target="_blank">Eric Meyer</a> and <a href="http://developer.yahoo.com/yui/reset/" target="_blank">Yahoo</a>.  I have tried both and think both are overkill for almost every site I create.  I have added to and adjusted my CSS starting point over all the sites I have built and am pretty comfortable with what I have now.</p>
<p>Heres the CSS code that I currently use:<br />
<span id="more-93"></span></p>
<pre class="brush: css">* {
   padding: 0;
   margin: 0;
}

body {
   text-align: center;
   font-size: 62.5%;
   color: #2B2B2B;
   padding: 0;
}

div, p, ul, ol, dl, h1, h2, h3, h4, h5, h6, table, hr, form {
   float: left;
   clear: both;
   width: 100%;
}

a {
   text-decoration: none;
   outline: none;
   color: #548be5;
}

a:hover {
   text-decoration: underline;
}

a img {
   border: none;
}

p {
   margin: 0 0 10px 0;
   line-height: 1.3;
}

.middle_align {
   text-align: center;
}

.left {
   float: left;
   clear: none;
   width: auto;
}

.right {
   float: right;
   clear: none;
   width: auto;
}

.left *, .right * {
   float: left;
}

.wrapper {
   text-align: left;
   float: none;
   width: 996px; /* set to page width */
   margin: 0 auto;
}

.container {
   position: relative;
}</pre>
<p>It should be noted that this CSS is for a center aligned site design, which covers the majority of the sites I code now.</p>
<p>Is there anything that you do different with your CSS reset?  Do you even use one?  With the above code, I can pretty much make the site look the same across the major browsers (including IE6) the first time without too much tweaking.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.creativegraymatter.com/blog/css-reset/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
