<?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>SleePyCode</title>
	<atom:link href="http://sleepycode.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://sleepycode.com</link>
	<description>/dev/random</description>
	<lastBuildDate>Tue, 31 Jan 2012 05:05:35 +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>SMF $user_info in as a class</title>
		<link>http://sleepycode.com/2012/01/smf-user_info-in-as-a-class/</link>
		<comments>http://sleepycode.com/2012/01/smf-user_info-in-as-a-class/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 05:20:54 +0000</pubDate>
		<dc:creator>SleePy</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[SMF]]></category>

		<guid isPermaLink="false">http://sleepycode.com/?p=1701</guid>
		<description><![CDATA[I wrote up this method while writing my Pastebin. It was an experiment mostly to not have to use as many globals in my main code. I think it turned out nice and easy. Knowing that SMF 3.0 will use OOP does not help as this is the least likely way this would be implanted [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote up this method while writing my Pastebin.  It was an experiment mostly to not have to use as many globals in my main code.  I think it turned out nice and easy.  Knowing that SMF 3.0 will use OOP does not help as this is the least likely way this would be implanted in the code.  At least this can act as a bridge at that time to the new code.</p>
<p>I should explain the _() method.  I set this up so I could do a <a href="http://php.net/manual/en/language.oop5.patterns.php#language.oop5.patterns.singleton">Singleton</a>.  It also allows me to use it in a sorta static method by doing &#8220;userInfo::_()->id;&#8221;.  Nice quick and easy.</p>
<p>I could of wrote this like my smcFunc class, but choose otherwise on the fact I wanted to use it as a object rather than a static method.  A setup like that should be possible, but I didn&#8217;t test that.</p>
<p>I never tested but I don&#8217;t think accessing multiple dimensional parts of the $user_info will work.  Things like $user_info['group'][1] most likely won&#8217;t work here.  I should add support to drill down into the array, but will save that for a later day.</p>
<pre class="wp-code-highlight prettyprint linenums:1" >
/*
* userInfo as a class.  We kinda do a poor method, but its the best way for now.
*/
class userInfo
{
	public static $instanceID = 0;

	public static function _()
	{
		if (self::$instanceID == 0)
			self::$instanceID = new userInfo;

		return self::$instanceID;
	}

	public function __set($key, $value)
	{
		global $user_info;
		$user_info[$key] = $value;
	}

	public function __get($key)
	{
		global $user_info;
		return isset($user_info[$key]) ? $user_info[$key] : null;
	}

	public function __isset($key)
	{
		global $user_info;
		return isset($user_info[$key]);
	}

	public function __unset($key)
	{
		global $user_info;
		unset($user_info[$key], $user_info[$key]);
	}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://sleepycode.com/2012/01/smf-user_info-in-as-a-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pastebin rewrote</title>
		<link>http://sleepycode.com/2012/01/pastebin-rewrote/</link>
		<comments>http://sleepycode.com/2012/01/pastebin-rewrote/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 05:16:34 +0000</pubDate>
		<dc:creator>SleePy</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[Pastebin]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Site]]></category>
		<category><![CDATA[SMF]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://sleepycode.com/?p=1683</guid>
		<description><![CDATA[I have taken my original code I wrote for my SMF powered pastebin and rewrote this script. This was a massive rewrite from the original code and hopefully it works out well for anyone else who is looking into using it. I wrote it so it should be plugable with different databases, user information and [...]]]></description>
			<content:encoded><![CDATA[<p>I have taken my original code I wrote for my SMF powered pastebin and rewrote this script.  This was a massive rewrite from the original code and hopefully it works out well for anyone else who is looking into using it.</p>
<p>I wrote it so it should be plugable with different databases, user information and templating engines.  The design was mostly to implant it into my mixed environment of SMF and WordPress, but also to make it robust so it could be used in other ways.</p>
<p>The source of the code is up on GitHub at https://github.com/jdarwood007/pastebin</p>
]]></content:encoded>
			<wfw:commentRss>http://sleepycode.com/2012/01/pastebin-rewrote/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SMF in WordPress</title>
		<link>http://sleepycode.com/2012/01/smf-in-wordpress/</link>
		<comments>http://sleepycode.com/2012/01/smf-in-wordpress/#comments</comments>
		<pubDate>Sat, 21 Jan 2012 18:00:14 +0000</pubDate>
		<dc:creator>SleePy</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Bugs]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Site]]></category>
		<category><![CDATA[SMF]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://sleepycode.com/?p=1681</guid>
		<description><![CDATA[For some reason, while using WordPress and including SMF&#8217;s SSI.php, it would not detect my logged in SMF session. Baffled and almost thinking this was a SMF bug of some sorts, I began to debug this process. Well it turns out it is sorta a SMF old PHP support issue, but the problem lies in [...]]]></description>
			<content:encoded><![CDATA[<p>For some reason, while using WordPress and including SMF&#8217;s SSI.php, it would not detect my logged in SMF session.  Baffled and almost thinking this was a SMF bug of some sorts, I began to debug this process.</p>
<p>Well it turns out it is sorta a SMF old PHP support issue, but the problem lies in WordPress.  This is the function in WordPress wp-includes/load.php</p>
<pre class="wp-code-highlight prettyprint linenums:1" >
/**
 * Add magic quotes to $_GET, $_POST, $_COOKIE, and $_SERVER.
 *
 * Also forces $_REQUEST to be $_GET + $_POST. If $_SERVER, $_COOKIE,
 * or $_ENV are needed, use those superglobals directly.
 *
 * @access private
 * @since 3.0.0
 */
function wp_magic_quotes() {
        // If already slashed, strip.
        if ( get_magic_quotes_gpc() ) {
                $_GET    = stripslashes_deep( $_GET    );
                $_POST   = stripslashes_deep( $_POST   );
                $_COOKIE = stripslashes_deep( $_COOKIE );
        }

        // Escape with wpdb.
        $_GET    = add_magic_quotes( $_GET    );
        $_POST   = add_magic_quotes( $_POST   );
        $_COOKIE = add_magic_quotes( $_COOKIE );
        $_SERVER = add_magic_quotes( $_SERVER );

        // Force REQUEST to be GET + POST.
        $_REQUEST = array_merge( $_GET, $_POST );
}
</pre>
<p>The problem here, is that they add magic quotes to the cookie.  Not quite sure why they are even doing this.  But it broke adding SMF.  The part in SMF which failed because of this is in SMFs Sources/Load.php in the loadUserSettings function</p>
<pre class="wp-code-highlight prettyprint linenums:1" >
		// Fix a security hole in PHP 4.3.9 and below...
		if (preg_match('~^a:[34]:\{i:0;(i:\d{1,6}|s:[1-8]:&quot;\d{1,8}&quot;);i:1;s:(0|40):&quot;([a-fA-F0-9]{40})?&quot;;i:2;[id]:\d{1,14};(i:3;i:\d;)?\}$~i', $_COOKIE[$cookiename]) == 1)
		{
			list ($id_member, $password) = @unserialize($_COOKIE[$cookiename]);
			$id_member = !empty($id_member) &amp;&amp; strlen($password) &gt; 0 ? (int) $id_member : 0;
		}
		else
			$id_member = 0;
</pre>
<p>Because of old PHP support in SMF, its trying to combat a cookie security issue that existed below PHP 4.3.9.  Now I don&#8217;t use that version, but I rather not strip out the code.  The preg match was failing because it was not finding that valid string in the cookie.  Since all the double quotes where escaped with a slash \.</p>
<p>For my code, I called in Settings.php from SMF and then did a stripslashes on the cookie.  Then I included SSI.php, with the results I expected of it finding my active SMF session.</p>
<pre class="wp-code-highlight prettyprint linenums:1" >
		require_once(pBS::get('smf_dir') . '/Settings.php');
		if (isset($_COOKIE[$cookiename]))
			$_COOKIE[$cookiename] = stripslashes($_COOKIE[$cookiename]);

		require_once(pBS::get('smf_dir') . '/SSI.php');
</pre>
<p>I should note because SMF uses a lot of global variables, that I had to globalize all of those before hand.  I just borrowed the globals from SSI.php and put them into that scripts function.</p>
]]></content:encoded>
			<wfw:commentRss>http://sleepycode.com/2012/01/smf-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Password Generator is open source</title>
		<link>http://sleepycode.com/2012/01/password-generator-is-open-source/</link>
		<comments>http://sleepycode.com/2012/01/password-generator-is-open-source/#comments</comments>
		<pubDate>Fri, 20 Jan 2012 18:38:36 +0000</pubDate>
		<dc:creator>SleePy</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Generator]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Password]]></category>
		<category><![CDATA[Site]]></category>

		<guid isPermaLink="false">http://sleepycode.com/?p=1676</guid>
		<description><![CDATA[I have rewrote my Password Generator script and after doing so, I have enabled it so you can see the source of this code. Simply click the link on the right side when viewing that page and the entire source code will be revealed. Developers are welcome to reuse any part of the code as [...]]]></description>
			<content:encoded><![CDATA[<p>I have rewrote my <a href="http://sleepycode.com/passgen/">Password Generator</a> script and after doing so, I have enabled it so you can see the source of this code.  Simply click the link on the right side when viewing that page and the entire source code will be revealed.<br />
Developers are welcome to reuse any part of the code as long as credit is given where appropriate.  Although this script may be over the top for normal password generation, I developed it to create truly random passwords.</p>
]]></content:encoded>
			<wfw:commentRss>http://sleepycode.com/2012/01/password-generator-is-open-source/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SMF Package Manager Generator</title>
		<link>http://sleepycode.com/2011/12/package-manager-generator/</link>
		<comments>http://sleepycode.com/2011/12/package-manager-generator/#comments</comments>
		<pubDate>Sun, 01 Jan 2012 01:28:26 +0000</pubDate>
		<dc:creator>SleePy</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Generator]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Package Manager]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Site]]></category>
		<category><![CDATA[SMF]]></category>

		<guid isPermaLink="false">http://sleepycode.com/?p=1656</guid>
		<description><![CDATA[Hello, Originally I had wrote my original SMF Package Manager Generator a few years ago. It was sloppy coding, poor JavaScript and relied heavily on the server. Not my absolute best work, but was something I was proud on at the time from my efforts to dive into JavaScripting. However, todays times are different. So [...]]]></description>
			<content:encoded><![CDATA[<p>Hello,<br />
Originally I had wrote my <a href="http://sleepycode.com/pacmangen/">original SMF Package Manager Generator</a> a few years ago.  It was sloppy coding, poor JavaScript and relied heavily on the server.  Not my absolute best work, but was something I was proud on at the time from my efforts to dive into JavaScripting.</p>
<p>However, todays times are different.  So with JQuery out there, I decided to take breaks from my projects for a couple hours for a few days and put forth a effort to rewrite this.  Needless to say, I had the initial code wrote in only a few hours.  My original script took me a few days alone.  That didn&#8217;t count the package-info creator I made later which also took a while.</p>
<p>The new script attempts to rely all on JavaScripting via JQuery.  It was a fun experience to build it this way.  Although, because of JavaScript&#8217;s security measures, I couldn&#8217;t leave downloading the file outside of the server.  So alas, I still have to process the actual download via the server.  There is a work around with using Data URIs, however it didn&#8217;t provide the filename and sounds a bit flaky when the length of the url gets to be a bit long.  I included both as a option though.</p>
<p>Oh and <a href="https://github.com/jdarwood007/smf_package_maker">Its on github</a>, because I see no reason to not share the code.  Including the code I used to integrate it into my WordPress blog.</p>
]]></content:encoded>
			<wfw:commentRss>http://sleepycode.com/2011/12/package-manager-generator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JQuery Week Calendar mouseover events</title>
		<link>http://sleepycode.com/2011/12/jquery-week-calendar-moseover-events/</link>
		<comments>http://sleepycode.com/2011/12/jquery-week-calendar-moseover-events/#comments</comments>
		<pubDate>Fri, 16 Dec 2011 03:33:39 +0000</pubDate>
		<dc:creator>SleePy</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[JQuery]]></category>

		<guid isPermaLink="false">http://sleepycode.com/?p=1646</guid>
		<description><![CDATA[While working with a plugin for JQuery for week calendars. I came across a very annoying little bug. Using mouseover/out events did not seem to work correctly when hovering over the title and time. It just wouldn&#8217;t do what it should of. Well after debugging and messing around for a while, I was able to [...]]]></description>
			<content:encoded><![CDATA[<p>While working with a plugin for <a href="https://github.com/themouette/jquery-week-calendar">JQuery for week calendars</a>.  I came across a very annoying little bug.  Using mouseover/out events did not seem to work correctly when hovering over the title and time.  It just wouldn&#8217;t do what it should of.</p>
<p>Well after debugging and messing around for a while, I was able to figure out how to resolve this issue.  In jquery.weekcalendar.js open up the file and locate:</p>
<pre class="wp-code-highlight prettyprint linenums:1" >
          if ($target.hasClass('wc-cal-event')) {
            options.eventMouseover($target.data('calEvent'), $target, event);
          }
</pre>
<p>After that code we want to add:</p>
<pre class="wp-code-highlight prettyprint linenums:1" >
          if ($target.hasClass('wc-time') || $target.hasClass('wc-title')) {
            options.eventMouseover($target.parents('.wc-cal-event').data('calEvent'), $target, event);
          }
</pre>
<p>A little further down the file is:</p>
<pre class="wp-code-highlight prettyprint linenums:1" >
          if ($target.hasClass('wc-cal-event')) {
            if ($target.data('sizing')) { return;}
            options.eventMouseout($target.data('calEvent'), $target, event);
          }
</pre>
<p>We want to add after that:</p>
<pre class="wp-code-highlight prettyprint linenums:1" >
          if ($target.hasClass('wc-time') || $target.hasClass('wc-title')) {
            if ($target.data('sizing')) { return;}
            options.eventMouseout($target.parents('.wc-cal-event').data('calEvent'), $target, event);
          }
</pre>
<p>This makes it work as I excepted it to.  My thoughts here are that the inner divs are removing the mouseover events.  So by attaching an event to them as well, it makes it work as well.</p>
<p>As a good GitHub person does, I submitted a pull request with these fixes in hopes that it gets merged into the plugin.</p>
]]></content:encoded>
			<wfw:commentRss>http://sleepycode.com/2011/12/jquery-week-calendar-moseover-events/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>new Date() in javascript</title>
		<link>http://sleepycode.com/2011/12/new-date-in-javascript/</link>
		<comments>http://sleepycode.com/2011/12/new-date-in-javascript/#comments</comments>
		<pubDate>Thu, 08 Dec 2011 00:43:40 +0000</pubDate>
		<dc:creator>SleePy</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://sleepycode.com/?p=1639</guid>
		<description><![CDATA[It appears that the date object in javascript can have some variances. I had a bug in my code which was only affecting FireFox users on Windows machines. After some debugging time, I figured out that the date object was returning a differently formated value. These are some examples: FireFox on Windows 7: Wed Dec [...]]]></description>
			<content:encoded><![CDATA[<p>It appears that the date object in javascript can have some variances.  I had a bug in my code which was only affecting FireFox users on Windows machines.  After some debugging time, I figured out that the date object was returning a differently formated value.</p>
<p>These are some examples:<br />
FireFox on Windows 7: Wed Dec 07 2011 16:26:38 GMT-0800 (Pacific Standard Time)<br />
IE 8 on Windows 7: Wed Dec 7 16:29:21 PST 2011<br />
Chrome on Windows 7: Wed Dec 07 2011 16:45:45 GMT -0800 (Pacific Standard Time)<br />
FireFox on OS X Lion: Wed Dec 07 2011 16:37:12 GMT-0800 (PST)<br />
Opera on OS X Lion: Wed Dec 07 2011 16:37:21 GMT-0800<br />
Safari on OS X Lion: Wed Dec 07 2011 16:44:54 GMT-0800 (PST)</p>
<p>It appears that the format of this is left up to the browser to decide.  It would be nice if they all followed a specific format.  Well it was because of the (Pacific Standard Time) not being recognized by php&#8217;s strtotime, that my code failed to work.  Some helpful members on IRC brought it to my knowledge that it is up to the browser really.</p>
<p>I find it interesting that out of all the tests, it appears IE just takes a completely method.  While the other browsers are at least semi-similar other than the time zone string at the end.  OS X at least appears to be consistent and it appears Opera may just be stripping the string from the end.</p>
<p>At least there is a simple solution.  Just use some regular expressions to strip off (Pacific Standard Time) and any other variation.</p>
<pre class="wp-code-highlight prettyprint linenums:1" >
	$date = preg_replace('~\(([^(]+)\)~', '', $_POST['date']);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://sleepycode.com/2011/12/new-date-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JQuery week calendar reoccurring events</title>
		<link>http://sleepycode.com/2011/12/jquery-week-calendar-reoccurring-events/</link>
		<comments>http://sleepycode.com/2011/12/jquery-week-calendar-reoccurring-events/#comments</comments>
		<pubDate>Wed, 07 Dec 2011 22:03:04 +0000</pubDate>
		<dc:creator>SleePy</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[JQuery]]></category>

		<guid isPermaLink="false">http://sleepycode.com/?p=1636</guid>
		<description><![CDATA[JQuery has a nice plugin called . Very simple to use and I was able to integrate it into the database to handle pulling scheduling data. However I came across one issue. Reoccurring events. Well after scrambling the web, I came to the conclusion that it wasn&#8217;t possible in the code by default. So away [...]]]></description>
			<content:encoded><![CDATA[<p>JQuery has a nice plugin called <a href="https://github.com/robmonie/jquery-week-calendar" title="JQuery week calendar"></a>.  Very simple to use and I was able to integrate it into the database to handle pulling scheduling data.  However I came across one issue.  Reoccurring events.</p>
<p>Well after scrambling the web, I came to the conclusion that it wasn&#8217;t possible in the code by default.  So away into the code I went.  To say the least, my solution is nowhere near perfect nor does it allow for reoccurring events yet from different weeks or months.  It was decided to take another course of action rather than trying to hack reoccurring events into the code.  I just wanted to post what I had so far:</p>
<p>In jquery.weekcalendar.js we have this code:</p>
<pre class="wp-code-highlight prettyprint linenums:1" >
              //put back the initial start date
</pre>
<p>Now before this and the block of code before it, I added in:</p>
<pre class="wp-code-highlight prettyprint linenums:1" >
			if ($.isArray(recurring))
			{
				var cur_date = new Date();
				var cur_dayofweek = cur_date.getDay();
				var org_start_date = calEvent.start.getDate();
				var org_end_date = calEvent.end.getDate();

				for(var i= 0; i&lt;recurring.length; i++)
				{
					calEvent.readOnly = true;
					var value = recurring[i];
					var offset = value - cur_dayofweek;

					calEvent.start.setDate(cur_date.getDate() + offset);
					calEvent.end.setDate(cur_date.getDate() + offset);

					if (($weekDay = self._findWeekDayForEvent(calEvent, $weekDayColumns))) {
						self._renderEvent(calEvent, $weekDay);
					}
				}

				calEvent.start.setDate(org_start_date);
				calEvent.end.setDate(org_end_date);
				calEvent.readOnly = false;
			}
</pre>
<p>This lets me do reoccurring events for the current week.  I am sure it could be greatly improved and somebody may be able to make it support multiple weeks.</p>
<p>In case anybody else wondered, this simply just needs a json array in the data of the weekday numbers (0-6).  The key is recurring.</p>
<pre class="wp-code-highlight prettyprint linenums:1" >
				{
					&quot;id&quot;:15,
					&quot;start&quot;: &quot;Sun, 4 Dec 2011 21:00:00 -0500&quot;,
					&quot;end&quot;: &quot;Sun, 4 Dec 2011 22:30:00 -0500&quot;,
					&quot;title&quot;:&quot;Reoccurring&quot;,
					&quot;recurring&quot;: [1,2,5,6]
				}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://sleepycode.com/2011/12/jquery-week-calendar-reoccurring-events/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery getting value of select with mulitple values</title>
		<link>http://sleepycode.com/2011/11/jquery-getting-value-of-select-with-mulitple-values/</link>
		<comments>http://sleepycode.com/2011/11/jquery-getting-value-of-select-with-mulitple-values/#comments</comments>
		<pubDate>Tue, 29 Nov 2011 00:00:32 +0000</pubDate>
		<dc:creator>SleePy</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[JQuery]]></category>

		<guid isPermaLink="false">http://sleepycode.com/?p=1632</guid>
		<description><![CDATA[I have been dipping into learning jQuery. Very powerful and useful. But as I am just learning it, I am taking a learning curve to figure it out. Today I came across the need to get the values of a select that had multiple values. I needed to take the name attribute from the option [...]]]></description>
			<content:encoded><![CDATA[<p>I have been dipping into learning jQuery.  Very powerful and useful.  But as I am just learning it, I am taking a learning curve to figure it out.  Today I came across the need to get the values of a select that had multiple values.  I needed to take the name attribute from the option as it contained a filename that I was going to use to display the image.  Further more I wanted to separate those images based on their dimensions.</p>
<p>After some thankless google searches, I came up with code that accomplishes this task easily.</p>
<pre class="wp-code-highlight prettyprint linenums:1" >
jQuery(function(){
	$('#banners').change(function(){
		$('#images_preview_loader').empty();
		$('#images_preview_box').empty();
		$('#images_preview_tower').empty();

		$('#banners :selected').each(function(i, selected){
			id = $(selected).attr('value');
			filename = $(selected).attr('name');
			$('#images_preview_loader').append(&quot;&lt;img id='bp_&quot; + id + &quot;' src='/images/banners/&quot; + filename + &quot;'/&gt;&quot;);

			height = document.getElementById('bp_' + id).height;
			width = document.getElementById('bp_' + id).width;

			if (width &lt; height)
			{
				$('#images_preview_tower').append(&quot;&lt;img id='bp_&quot; + id + &quot;' src='/images/banners/&quot; + filename + &quot;'/&gt;&quot;);
			}
			else
			{
				$('#images_preview_box').append(&quot;&lt;img id='bp_&quot; + id + &quot;' src='/images/banners/&quot; + filename + &quot;'/&gt;&quot;);
			}
		});
		$('#images_preview_loader').empty();
	});
});
</pre>
<p>As for the HTML, I have my select box with multiple=&#8221;multiple&#8221; in it.  Each option has a value attribute that I use for the database and a name attribute containing the filename.  They also contain the friendly name.  I then have 3 divs setup like so:</p>
<pre class="wp-code-highlight prettyprint linenums:1" >
&lt;div id=&quot;images_preview_loader&quot; style=&quot;display: none;&quot;&gt;&lt;/div&gt;&lt;br /&gt;&lt;div id=&quot;images_preview_box&quot;&gt;&lt;/div&gt;&lt;br /&gt;&lt;div id=&quot;images_preview_tower&quot;&gt;&lt;/div&gt;
</pre>
<p>The loader lets me simply get the image loading, once it has the height and width of the image it moves it to the correct box.  I keep the loader div hidden so there is no moving around showing as it does its work.  Does the job for what I need it to do.  Which is a simple previewer of the images being selected.  I need the bigger ones to be separate as these are usually tower based images and would make a ugly looking layout otherwise.</p>
]]></content:encoded>
			<wfw:commentRss>http://sleepycode.com/2011/11/jquery-getting-value-of-select-with-mulitple-values/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress templates on non wordpress pages</title>
		<link>http://sleepycode.com/2011/11/wordpress-templates-on-non-wordpress-pages/</link>
		<comments>http://sleepycode.com/2011/11/wordpress-templates-on-non-wordpress-pages/#comments</comments>
		<pubDate>Mon, 21 Nov 2011 04:09:32 +0000</pubDate>
		<dc:creator>SleePy</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Site]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://sleepycode.com/?p=1615</guid>
		<description><![CDATA[I have a couple pages such as my password generate that are non wordpress templates. However I want these to be styled as if they where from my wordpress. So after some google searches, I came up with very little information. I decided to dive into the code and came up with something that works [...]]]></description>
			<content:encoded><![CDATA[<p>I have a couple pages such as my password generate that are non wordpress templates.  However I want these to be styled as if they where from my wordpress.  So after some google searches, I came up with very little information.  I decided to dive into the code and came up with something that works for what I need it to do and requires little code edits to any of my pages to work.</p>
<p>This does also require a template edit to your wordpress templates.  Sadly I couldn&#8217;t avoid this, I looked around and tried to see if I could modify the_content(), however it doesn&#8217;t look very pleasant to do so.  I might in the future look into doing this.  If somebody has a better solution that requires no wordpress template edits, please let me know.  Back on topic, I modified page.php in my template and changed:</p>
<pre class="wp-code-highlight prettyprint linenums:1"  style="margin-bottom: 0 !important;">
					&lt;?php the_content(); ?&gt;
</pre>
<p>To this line:</p>
<pre class="wp-code-highlight prettyprint linenums:1" >
					&lt;?php if (isset($specialPageContent)) echo $specialPageContent; else the_content(); ?&gt;
</pre>
<p>Next I will just dump a file I named wp-ssi.php and explain how it works at the end.</p>
<pre class="wp-code-highlight prettyprint linenums:1" >
&lt;?php
// Change the default template to use.
define('WP_SSI_DEFAULT_TEMPLATE', 'page');

// Register a shutdown function (DOES THE ACTUAL WORK!)
register_shutdown_function('do_wp_ssi_wrap');

// Don't output anything yet.
ob_start();

// Get WordPress going.
require_once('./wp-blog-header.php');

// The shutdown function that does the actual work.
function do_wp_ssi_wrap()
{
	global $specialPageContent;

	// Simply get all contents.
	$specialPageContent = ob_get_clean();

	// Allow some over rides.
	$theme = defined('WP_SSI_THEME') ? WP_SSI_THEME : get_template_directory();
	$template = defined('WP_SSI_TEMPLATE') ? WP_SSI_TEMPLATE : WP_SSI_DEFAULT_TEMPLATE;

	// Pass it on as if it was a page.
	require($theme . '/' . $template . '.php');
}
</pre>
<p>Now for all my files I add at the very top.  Of course, you need to substitute the path to match yours.</p>
<pre class="wp-code-highlight prettyprint linenums:1" >
require('/path/to/wordpress/wp-ssi.php');
</pre>
<p>As for wp-ssi.php, I will can explain more about how that works.<br />
<span id="more-1615"></span></p>
<p></p>
<pre class="wp-code-highlight prettyprint linenums:1" >
define('WP_SSI_DEFAULT_TEMPLATE', 'page');
</pre>
<p>Our first bit of code, simply is a option, nothing more nothing less.  It just lets me define the default template, in this example code I used page, however for my theme I customized the page template to display full width and not have the sidebar.</p>
<pre class="wp-code-highlight prettyprint linenums:1" >
register_shutdown_function('do_wp_ssi_wrap');
</pre>
<p>This is the most important piece of code, without it this wouldn&#8217;t work.  This registers with php a function to run at the end of page execution.  I may of been able to use ob_start with a buffer function, but I avoided it.</p>
<pre class="wp-code-highlight prettyprint linenums:1" >
ob_start();
</pre>
<p>This is simple, we are turning on a output buffer.  I don&#8217;t need any buffer replacements, so I just call the function.</p>
<pre class="wp-code-highlight prettyprint linenums:1" >
require_once('./wp-blog-header.php');
</pre>
<p>This gets wordpress going.  This same piece of code is used to start wordpress in the index.php</p>
<pre class="wp-code-highlight prettyprint linenums:1" >
function do_wp_ssi_wrap()
{
	global $specialPageContent;
</pre>
<p>Consolidating some lines here, we are creating a new function called &#8216;do_wp_ssi_wrap&#8217;.  We also used &#8216;do_wp_ssi_wrap&#8217; in the argument lines with our register_shutdown_function a few lines up.  This is the shutdown function that is going to do some stuff before php exits and sends all contents to the browser.</p>
<pre class="wp-code-highlight prettyprint linenums:1" >
	$specialPageContent = ob_get_clean();
</pre>
<p>We are capturing all output sent to the buffer at this time.  Any output our script has sent is now in a easy to use variable.</p>
<pre class="wp-code-highlight prettyprint linenums:1" >
	$theme = defined('WP_SSI_THEME') ? WP_SSI_THEME : get_template_directory();
	$template = defined('WP_SSI_TEMPLATE') ? WP_SSI_TEMPLATE : WP_SSI_DEFAULT_TEMPLATE;
</pre>
<p>Some more overrides here.  I simply setup a way to override the theme, otherwise it uses wordpress functions to get the path to the current theme in use.  The next one allows me to override the template.  Both of these may come in handy if I have a page I want a different theme on or if I want to use a different template on it.</p>
<pre class="wp-code-highlight prettyprint linenums:1" >
	require($theme . '/' . $template . '.php');
}
</pre>
<p>This is simply just including the template from the theme we selected.  Oh and the closing function curly bracket.  That is all the code needed here.</p>
]]></content:encoded>
			<wfw:commentRss>http://sleepycode.com/2011/11/wordpress-templates-on-non-wordpress-pages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

