<?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>Matt(hew) Morey &#187; PHP</title>
	<atom:link href="http://matthewmorey.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://matthewmorey.com</link>
	<description>...an engineer who surfs, travels, and pretends to know the meaning of life.</description>
	<lastBuildDate>Fri, 17 Jul 2009 22:56:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Code (2 of 2) for @MattsOffice</title>
		<link>http://matthewmorey.com/projects/code-2-of-2-for-mattsoffice/</link>
		<comments>http://matthewmorey.com/projects/code-2-of-2-for-mattsoffice/#comments</comments>
		<pubDate>Fri, 17 Jul 2009 21:04:55 +0000</pubDate>
		<dc:creator>Matt(hew)</dc:creator>
				<category><![CDATA[Engineering]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[home automation]]></category>
		<category><![CDATA[iobridge]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[soical network]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://matthewmorey.com/?p=164</guid>
		<description><![CDATA[As promised in my earlier post and the follow up post, here is some sample code I&#8217;m using to respond to @MattsOffice mentions. With a version of this code and a Cron job I can respond to any number of specific&#160;commands. This code only illustrates responding to one command, &#8220;light&#8221;, but could easily be extended [...]]]></description>
			<content:encoded><![CDATA[<p>As promised in my <a href="http://matthewmorey.com/projects/introducing-mattsoffice/">earlier post</a>  and the <a href="http://matthewmorey.com/projects/code-1-of-2-for-mattsoffice/">follow up post</a>, here is some sample code I&#8217;m using to respond to <a href="http://twitter.com/#search?q=@MattsOffice">@MattsOffice mentions</a>. With a version of this code and a Cron job I can respond to any number of specific&nbsp;commands.</p>
<p>This code only illustrates responding to one command, &#8220;light&#8221;, but could easily be extended as is done with&nbsp;<a href="http://twitter.com/MattsOffice">@MattsOffice</a>.</p>
<pre name="code" class="php">
&lt;?php
include_once('class.twitter.php');// http://code.google.com/p/php-twitter/

$ioBridgeJSONFeedURL = 'http://www.iobridge.com/api/feed/key=XXXXXXXXXXXXXXXXXXXXXX';
$buzzerOnURL = 'http://yourserver.com/iobridge-proxy.php?widget=buzzeron';
$buzzerOffURL = 'http://yourserver.com/iobridge-proxy.php?widget=buzzeroff';

$t = new twitter;
$t-&gt;username = 'twitter_username';
$t-&gt;password = 'twitter_password';

// Read the ID of the last reply
$myFile = "lastreply.txt";
$fileHandle = fopen($myFile, 'r');
$lastReplyID = fgets($fileHandle);
fclose($fileHandle);

// Get the latest unanwsered replies
$data = $t-&gt;getReplies('','',$lastReplyID);

$counter = 1;
if(!empty($data)){
&nbsp;&nbsp;&nbsp;&nbsp;foreach($data as $tweet) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (!empty($tweet-&gt;user-&gt;id)){

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Check for valid command
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(stripos($tweet-&gt;text, "light"){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// retrieve data from ioBridge.com
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$curl_handle=curl_init();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($curl_handle,CURLOPT_URL,$ioBridgeJSONFeedURL);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$ioBridgeResultsObject = curl_exec($curl_handle);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$ioBridgeResultsObject = json_decode($ioBridgeResultsObject);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_close($curl_handle);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$lightResults = $ioBridgeResultsObject-&gt;{'module'}-&gt;{'channels'}[2]-&gt;{'AnalogInput'};
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$updateText = ' @' . $tweet-&gt;user-&gt;screen_name . ' Ambient Light = ' . $lightResults;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// If no valid command was found reply with what commands are valid
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$messageText = ' Valid commands are: light, bright, dark, temp, hot, cold, lcd, and/or view';
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$updateText = ' @' . $tweet-&gt;user-&gt;screen_name . $messageText;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Send update
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$updateData = $t-&gt;update($updateText, $tweet-&gt;id);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Update text file with ID of last reply (first reply of loop)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if($counter === 1){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$myFile = "lastreply.txt";
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$fileHandle = fopen($myFile, 'w') or die("can't open file");
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fwrite($fileHandle, $tweet-&gt;id);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fclose($fileHandle);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$counter++;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Sound Buzzer (serves as an audible alert when someone pings @MattsOffice)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$curl_handle=curl_init();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($curl_handle,CURLOPT_URL,$buzzerOnURL);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,5);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$results = curl_exec($curl_handle);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($curl_handle,CURLOPT_URL,$buzzerOffURL);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$results = curl_exec($curl_handle);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_close($curl_handle);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}// if (!empty($tweet-&gt;user-&gt;id)){
&nbsp;&nbsp;&nbsp;&nbsp;}// foreach($data as $tweet) {
}// if(!empty($data)){
else {
&nbsp;&nbsp;&nbsp;&nbsp;echo 'All replies have been responded to.';
}

print '&lt;pre&gt;Twitter says(list of @mentions):'; print_r($data); print '&lt;/pre&gt;';
print '&lt;pre&gt;Twitter says(response to status update):'; print_r($updateData); print '&lt;/pre&gt;';
?&gt;
</pre>
<p>In order to keep track of what @MattsOffice mentions have already been answered, the ID of the last successful reply is saved to a plain text file. A database could also be used but the text file method is much simpler even if it doesn&#8217;t allow&nbsp;logging.</p>
<p>In order for this code to work your server needs the <a href="http://www.iobridge.net/wiki/api/php-widget-control-api">ioBridge PHP Widge Control API</a> and <a href="http://code.google.com/p/php-twitter/">this </a>Twitter&nbsp;library.</p>
]]></content:encoded>
			<wfw:commentRss>http://matthewmorey.com/projects/code-2-of-2-for-mattsoffice/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Code (1 of 2) for @MattsOffice</title>
		<link>http://matthewmorey.com/projects/code-1-of-2-for-mattsoffice/</link>
		<comments>http://matthewmorey.com/projects/code-1-of-2-for-mattsoffice/#comments</comments>
		<pubDate>Thu, 16 Jul 2009 00:59:38 +0000</pubDate>
		<dc:creator>Matt(hew)</dc:creator>
				<category><![CDATA[Engineering]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[home automation]]></category>
		<category><![CDATA[iobridge]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[soical network]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://matthewmorey.com/?p=143</guid>
		<description><![CDATA[As promised in my earlier post here is the code that I&#8217;m using to auto-update the MattsOffice Twitter account. With this code and a Cron job I can update the light and temperature conditions of my office automatically at whatever time interval I&#160;choose. ioBridge.com does offer &#8220;Actions&#8221; but none of the current actions allow the [...]]]></description>
			<content:encoded><![CDATA[<p>As promised in my <a href="http://matthewmorey.com/projects/introducing-mattsoffice/">earlier post</a> here is the code that I&#8217;m using to auto-update the <a href="http://twitter.com/MattsOffice">MattsOffice Twitter account</a>. With this code and a Cron job I can update the light and temperature conditions of my office automatically at whatever time interval I&nbsp;choose.</p>
<p><a href="http://www.iobridge.com">ioBridge.com</a> does offer &#8220;Actions&#8221; but none of the current actions allow the trigger to be time based. Once they introduce time as a trigger this code will no longer be&nbsp;needed.</p>
<pre name="code" class="php">
&lt;?php
include_once('class.twitter.php');//http://code.google.com/p/php-twitter/

$ioBridgeJSONFeedURL = 'http://www.iobridge.com/api/feed/key=XXXXXXXXXXXXXXXXXX';

$t = new twitter;
$t-&gt;username = 'twitter_username';
$t-&gt;password = 'twitter_pwd';

$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,$ioBridgeJSONFeedURL);
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$ioBridgeResultsObject = curl_exec($curl_handle);
$ioBridgeResultsObject = json_decode($ioBridgeResultsObject);
curl_close($curl_handle);

if (empty($ioBridgeResultsObject)){
    print "Sorry, something went wrong.";
}
else{
    $data = $t-&gt;update('Temperature = '. $ioBridgeResultsObject-&gt;{'module'}-&gt;{'channels'}[0]-&gt;{'AnalogInput'} . '°F / Ambient Light = ' . $ioBridgeResultsObject-&gt;{'module'}-&gt;{'channels'}[2]-&gt;{'AnalogInput'});
    print '&lt;pre&gt;Twitter says: '; print_r($data); print '&lt;/pre&gt;';
}
?&gt;
</pre>
<p>In a few days I will post the code that parses my Twitter account for <a href="http://twitter.com/#search?q=@MattsOffice">@MattsOffice mentions</a> and responds to them&nbsp;accordingly.</p>
<p>Update: 07/17/09<br />
Second <a href="http://matthewmorey.com/projects/code-2-of-2-for-mattsoffice/">post</a> is up with more&nbsp;code </p>
]]></content:encoded>
			<wfw:commentRss>http://matthewmorey.com/projects/code-1-of-2-for-mattsoffice/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>UF Theta Tau Web Site</title>
		<link>http://matthewmorey.com/projects/uf-theta-tau-web-site/</link>
		<comments>http://matthewmorey.com/projects/uf-theta-tau-web-site/#comments</comments>
		<pubDate>Fri, 29 Jun 2007 20:04:48 +0000</pubDate>
		<dc:creator>Matt(hew)</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[Websites]]></category>
		<category><![CDATA[members section]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[theat tau]]></category>
		<category><![CDATA[UF]]></category>
		<category><![CDATA[University of Florida]]></category>
		<category><![CDATA[website]]></category>

		<guid isPermaLink="false">http://matthewmorey.com/blog/?p=60</guid>
		<description><![CDATA[This site (http://www.ufthetatau.org/) was completely done with PHP and MySQL. The visual design of the site is not the greatest but the database back end and members only section is rock solid. The members section serves over 250 members and is used for a calendar, contact information database, quote wall, photo gallery,&#160;etc&#8230; The website has [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_61" class="wp-caption alignleft" style="width: 205px"><img class="size-full wp-image-61" title="Theta Tau Website Screenshot" src="http://matthewmorey.com/wp-content/uploads/2009/03/thetatau.jpg" alt="Theta Tau Website Screenshot" width="195" height="144" /><p class="wp-caption-text">Theta Tau Website&nbsp;Screenshot</p></div>
<p>This site (<a href="http://www.ufthetatau.org/">http://www.ufthetatau.org/</a>) was completely done with PHP and MySQL. The visual design of the site is not the greatest but the database back end and members only section is rock solid. The members section serves over 250 members and is used for a calendar, contact information database, quote wall, photo gallery,&nbsp;etc&#8230;</p>
<p>The website has gone through several revisions since I graduated. The site I designed is no longer there but the members section I created is still being used. Just in case the actual site is down check out this <a href="http://matthewmorey.com/ufthetatau/">mirror </a>or this <a href="http://matthewmorey.com/ufthetatau.pdf">PDF </a>version.</p>
]]></content:encoded>
			<wfw:commentRss>http://matthewmorey.com/projects/uf-theta-tau-web-site/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apex Environmental Web Site</title>
		<link>http://matthewmorey.com/projects/apex-environmental-web-site/</link>
		<comments>http://matthewmorey.com/projects/apex-environmental-web-site/#comments</comments>
		<pubDate>Sun, 24 Jun 2007 20:07:49 +0000</pubDate>
		<dc:creator>Matt(hew)</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[Websites]]></category>
		<category><![CDATA[Apex Environmental]]></category>
		<category><![CDATA[Dreamweaver]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[website]]></category>
		<category><![CDATA[WYSIWYG]]></category>

		<guid isPermaLink="false">http://matthewmorey.com/blog/?p=64</guid>
		<description><![CDATA[I used the template feature in Dreamweaver to design this site (http://www.apexenvironmental.com/). Most hard core web designer discredit WYSIWYG editors like Dreamweaver but in my experience they increase productivity by leaps and bounces. This site also has an administration backend developed with PHP. The backend allows the site owner to make changes to the content [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_65" class="wp-caption alignleft" style="width: 204px"><img class="size-full wp-image-65" title="Apex Environmental Web Site" src="http://matthewmorey.com/wp-content/uploads/2009/03/apex.jpg" alt="Apex Environmental Web Site" width="194" height="145" /><p class="wp-caption-text">Apex Environmental Web&nbsp;Site</p></div>
<p>I used the template feature in Dreamweaver to design this site (<a href="http://www.apexenvironmental.com/">http://www.apexenvironmental.com/</a>). Most hard core web designer discredit WYSIWYG editors like Dreamweaver but in my experience they increase productivity by leaps and bounces. This site also has an administration backend developed with PHP. The backend allows the site owner to make changes to the content without knowing any coding. I really like they way this site came&nbsp;out.</p>
<p>Since I designed the site someone else took control of the site and it now doesn&#8217;t function as it was intended. To see the site the way I originally designed it please view this <a href="http://matthewmorey.com/apex_environmental.pdf">PDF&nbsp;version</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://matthewmorey.com/projects/apex-environmental-web-site/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
