<?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>Sean&#039;s Blog &#187; php</title>
	<atom:link href="http://seanbehan.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://seanbehan.com</link>
	<description>Web Programming, Ruby on Rails, Wordpress, PHP from Burlington, Vermont</description>
	<lastBuildDate>Wed, 18 Jan 2012 21:44:54 +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>How to Check if the Current Logged In User can Edit a Course in MOODLE Using the Has_capability Function</title>
		<link>http://seanbehan.com/moodle/how-to-check-if-the-current-logged-in-user-can-edit-a-course-in-moodle-using-the-has_capability-function/</link>
		<comments>http://seanbehan.com/moodle/how-to-check-if-the-current-logged-in-user-can-edit-a-course-in-moodle-using-the-has_capability-function/#comments</comments>
		<pubDate>Fri, 30 Jul 2010 02:36:52 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[moodle]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[context]]></category>
		<category><![CDATA[course]]></category>
		<category><![CDATA[has_capbility]]></category>
		<category><![CDATA[teacher]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=1072</guid>
		<description><![CDATA[After an hour of fruitless searching through the docs and forums, I finally found an answer to my simple question, of course buried in the depths of the shark infested, murky water that is the Moodle code base . How do I check if a user is a course creator for a given course? I&#8217;m [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Fmoodle%2Fhow-to-check-if-the-current-logged-in-user-can-edit-a-course-in-moodle-using-the-has_capability-function%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="How to Check if the Current Logged In User can Edit a Course in MOODLE Using the Has_capability Function" data-url="http://seanbehan.com/moodle/how-to-check-if-the-current-logged-in-user-can-edit-a-course-in-moodle-using-the-has_capability-function/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>After an hour of fruitless searching through the docs and forums, I finally found an answer to my simple question, of course buried in the depths of the shark infested, murky water that is the Moodle code base .</p>
<p>How do I check if a user is a course creator for a given course? I&#8217;m still not 100% sure, the access control policy seems needlessly confusing on first glance and even after reading the heady and mostly pointless, expose on how roles/perms are calculated (Available Here: http://docs.moodle.org/en/How_permissions_are_calculated ) If you notice the section titled &#8220;Some Practical Examples&#8221; is 100% empty! (I&#8217;ve added my code to the wiki so not 100% empty any longer) The most useful part of the docs are completely empty! Instead boatloads of time went into a treatise on the internals and lovely graphs like this one <img class="alignnone" src="http://docs.moodle.org/en/images_en/9/9c/Role_calc_table2.png" alt="" width="756" height="256" /></p>
<p>But you could always hop into the forum dedicated just to this chunk of the code base (Available here: http://moodle.org/mod/forum/view.php?f=941&amp;page=0) and search through the 500 topics w/ 5000+(i didn&#8217;t actually count) nested discussions (including version 1.7 of moodle as well).</p>
<p>No, instead, ACK came to the rescue and I found a snippet that performed the task.</p>
<p>Without further ado</p>
<pre class="wp-code-highlight prettyprint">$context = get_context_instance(CONTEXT_COURSE, $course-&amp;gt;id);
if (has_capability('moodle/course:update', $coursecontext)) {
  /** do stuff here */
}
</pre>
<p>There it is. That could have saved me an hour if mentioned in the docs!</p>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/moodle/how-to-check-if-the-current-logged-in-user-can-edit-a-course-in-moodle-using-the-has_capability-function/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Moodle&#039;s Most Important Function Gets No Attention</title>
		<link>http://seanbehan.com/php/moodles-most-important-function-gets-no-attention/</link>
		<comments>http://seanbehan.com/php/moodles-most-important-function-gets-no-attention/#comments</comments>
		<pubDate>Wed, 28 Jul 2010 23:36:07 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[Documentation]]></category>
		<category><![CDATA[moodle]]></category>
		<category><![CDATA[patterns]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=1067</guid>
		<description><![CDATA[Arguably the most important function in the Moodle API, is the create_course function. One would think&#8230; after all Moodle is an LMS. Courses are the bread and butter for course management platforms, right? Taking a look at the function in the course/lib.php file reveals almost nothing about the function! WTF? &#8230; btw, the function starts [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Fphp%2Fmoodles-most-important-function-gets-no-attention%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Moodle&#039;s Most Important Function Gets No Attention" data-url="http://seanbehan.com/php/moodles-most-important-function-gets-no-attention/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>Arguably the most important function in the Moodle API, is the create_course function. One would think&#8230; after all Moodle is an LMS. Courses are the bread and butter for course management platforms, right? Taking a look at the function in the course/lib.php file reveals almost nothing about the function! WTF? &#8230; <em>btw, the function starts at line 3260</em></p>
<pre class="wp-code-highlight prettyprint">/**
 * Create a course and either return a $course object or false
 *
 * @param object $data  - all the data needed for an entry in the 'course' table
 */
function create_course($data) {
    global $CFG, $USER;
    /** omitted for your sanity */
}
</pre>
<p>Wow, I think I know less about this function now than before I went digging into the code. How do I assign a teacher to my new course, how do I populate the data object it takes as a parameter (is there a course setup function)? Since courses aren&#8217;t really objects in Moodle (just glorified arrays), am I just supposed to set them up by hand&#8230; $object-&gt;param = val?  Are there default values and/or required attributes that need to be set, otherwise my program is going to come to a halt? What about student enrollments? No example to help for how one might actually use this function? Do I have to really read through the code, starting at around line 3260, then jump between the rest of  this monstrous 4000 line piece of spaghetti coded file and try and make sense of it works (somehow).</p>
<p>How is it possible that the most important function (since the core problem Moodle solves is creating courses) in the entire application has no meaningful documentation? I think I have an answer. The entire code base is soooo convoluted and a giant waste of CPU cycles, that it would too embarrassing to actually document how it even works.</p>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/php/moodles-most-important-function-gets-no-attention/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>My Review of Moodle 1.9 Extension Development</title>
		<link>http://seanbehan.com/programming/review-of-moodle-1-9-extension-development/</link>
		<comments>http://seanbehan.com/programming/review-of-moodle-1-9-extension-development/#comments</comments>
		<pubDate>Fri, 04 Jun 2010 19:59:52 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[book review]]></category>
		<category><![CDATA[moodle]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[software development]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=1040</guid>
		<description><![CDATA[I wrote a review for Joseph Thibault&#8217;s Moodle News on extension development for Moodle. The book is quite good and I think an essential resource for anyone wanting to develop in Moodle. The book focuses on plugin development, but it will also give you an overview of the architecture, api and best practices. I wish [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Fprogramming%2Freview-of-moodle-1-9-extension-development%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="My Review of Moodle 1.9 Extension Development" data-url="http://seanbehan.com/programming/review-of-moodle-1-9-extension-development/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>I wrote a review for <a href="http://moodlenews.com">Joseph Thibault&#8217;s Moodle News</a> on extension development for Moodle. The book is quite good and I think an essential resource for anyone wanting to develop in Moodle. The book focuses on plugin development, but it will also give you an overview of the architecture, api and best practices.</p>
<p>I wish I had this book about 3 years ago when I first started fooling around in the code base! At any rate, you can read the review on <a href="http://moodlenews.com">Moodle News</a> at <a href="http://www.moodlenews.com/2010/moodle-1-9-extension-development-review-by-bseanvt/">http://www.moodlenews.com/2010/moodle-1-9-extension-development-review-by-bseanvt/</a></p>
<p>There is also an interesting discussion underway about the &#8216;bloat&#8217; in the Moodle code at <a href="http://www.moodlenews.com/2010/opinion-1000000-lines-of-code/">http://www.moodlenews.com/2010/opinion-1000000-lines-of-code/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/programming/review-of-moodle-1-9-extension-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Install and Serve a Rails Application from PHP Subdirectory Using Apache, Phussion Passenger and Ruby Enterprise Edition</title>
		<link>http://seanbehan.com/ruby-on-rails/install-and-serve-a-rails-application-from-php-subdirectory-using-apache-phussion-passenger-and-ruby-enterprise-edition/</link>
		<comments>http://seanbehan.com/ruby-on-rails/install-and-serve-a-rails-application-from-php-subdirectory-using-apache-phussion-passenger-and-ruby-enterprise-edition/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 21:40:02 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[alias]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[feedzirra]]></category>
		<category><![CDATA[installation]]></category>
		<category><![CDATA[mod rails]]></category>
		<category><![CDATA[passenger]]></category>
		<category><![CDATA[passenger app root]]></category>
		<category><![CDATA[path prefix]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[phussion]]></category>
		<category><![CDATA[ree]]></category>
		<category><![CDATA[relative url rails]]></category>
		<category><![CDATA[routing]]></category>
		<category><![CDATA[ruby enterprise edition]]></category>
		<category><![CDATA[subdirectory]]></category>
		<category><![CDATA[VirtualHost]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=795</guid>
		<description><![CDATA[Here is how to install a Rails application out of a subdirectory (rather than as a subdomain) with the Apache web server(Apache2). In this example I&#8217;m going to use my own blog which is a WordPress installation and serve a Rails application from the subdirectory &#8220;reader&#8221;. Note, I&#8217;m not going to keep my Rails application [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Fruby-on-rails%2Finstall-and-serve-a-rails-application-from-php-subdirectory-using-apache-phussion-passenger-and-ruby-enterprise-edition%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Install and Serve a Rails Application from PHP Subdirectory Using Apache, Phussion Passenger and Ruby Enterprise Edition" data-url="http://seanbehan.com/ruby-on-rails/install-and-serve-a-rails-application-from-php-subdirectory-using-apache-phussion-passenger-and-ruby-enterprise-edition/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>Here is how to install a Rails application out of a subdirectory (rather than as a subdomain) with the Apache web server(Apache2). In this example I&#8217;m going to use my own blog which is a WordPress installation and serve a Rails application from the subdirectory &#8220;reader&#8221;. Note, I&#8217;m not going to keep my Rails application in the document root of my WordPress Blog, which is a PHP application and therefore anyone could browse the ruby source code :(. I&#8217;ll keep it elsewhere on the filesystem and tell Apache about the location in the VirtualHost file.</p>
<p>You can visit the application by going to  <a href="http://seanbehan.com/reader">http://seanbehan.com/reader</a>. The application just parses a bunch of RSS feeds and displays them.<br />
It uses the Feedzirra library, which I&#8217;ve also written about <a href="http://seanbehan.com/ruby-on-rails/installing-feedzirra-rss-parser-on-ubuntu-8/">http://seanbehan.com/ruby-on-rails/installing-feedzirra-rss-parser-on-ubuntu-8/</a>.</p>
<p>I&#8217;m using Phussion Passenger and Ruby Enterprise Edition from the folks at <a href="http://www.modrails.com/">Mod Rails</a>. Installing both Phussion Passenger and Ruby Enterprise Edition is simple and a very well documented process. However, you&#8217;ll need to download and compile them from source. If you install Ruby Enterprise Edition (REE) it comes w/ Passenger so you won&#8217;t need to download it separately. I recommend going with REE. <a href="http://www.rubyenterpriseedition.com/download.html">http://www.rubyenterpriseedition.com/download.html</a></p>
<h3>Installing Ruby Enterprise Edition</h3>
<p>Here are the commands to download and install (change the X.X.X to the package you&#8217;ve actually downloaded).</p>
<pre class="wp-code-highlight prettyprint">
wget http://rubyforge.org/frs/download.php/68719/ruby-enterprise-1.8.7-2010.01.tar.gz
tar xzvf ruby-enterprise-X.X.X.tar.gz
./ruby-enterprise-X.X.X/installer
</pre>
<p>When you run the installer you&#8217;ll be prompted for an installation location. Just hit enter to install in the default location. Follow the instructions from there and remember to copy/paste any code that they give you.</p>
<p>Official Instructions on installation for Passenger on its own are available here <a href="http://www.modrails.com/install.html">http://www.modrails.com/install.html</a> I&#8217;ve written about setting up an entire box w/ Passenger here <a href="http://seanbehan.com/ruby-on-rails/new-ubuntu-slice-apache-mysql-php-ruby-on-rails-git-and/">http://seanbehan.com/ruby-on-rails/new-ubuntu-slice-apache-mysql-php-ruby-on-rails-git-and/</a> If you already have Passenger installed and want to use REE just download and install REE and it&#8217;ll recompile Passenger with REE support if you follow the instructions.</p>
<p>*** If you install REE you&#8217;ll need to either link or reinstall all your gems. I linked the REE gem with the one in /usr/bin so that I can run  gem install <gem name> and REE will be aware of it.</p>
<pre class="wp-code-highlight prettyprint">
ln -s /opt/ruby-enterprise-X.X.X/bin/gem /usr/bin/gem
</pre>
<h3>The VirtualHost</h3>
<p>If you have Passenger and REE successfully installed you&#8217;ll need to modify your VirtualHost file and add Rails application information to it.</p>
<pre class="wp-code-highlight prettyprint">
&amp;lt;VirtualHost *&amp;gt;
  # Normal virtual host info
  ServerName seanbehan.com
  ServerAlias *.seanbehan.com
  DocumentRoot /var/www/seanbehan.com/wordpress

  # Rails info goes here
  Alias /reader /var/www/seanbehan.com/reader/public
  &amp;lt;Location /reader&amp;gt;
    PassengerAppRoot /var/www/seanbehan.com/reader
    RailsEnv production
  &amp;lt;/Location&amp;gt;
&amp;lt;/VirtualHost&amp;gt;
</pre>
<p>The &#8220;Location&#8221; directive tells apache to forward requests starting with /reader to the directory<br />
/var/www/seanbehan.com/reader/public which is the location of our Rails app. However, we need to add the PassengerAppRoot assignment so that it knows where the actual application lives.</p>
<h3>Routing in Rails with Relative Path</h3>
<p>And finally, your Rails application will need to be aware of the relative url prefix assigned to each route. Normally, you could do this w/ the :path_prefix at the individual route level like so</p>
<pre class="wp-code-highlight prettyprint">
map.resources :feeds, :path_prefix =&gt; &quot;reader&quot;
</pre>
<p>This will work but you can add a line to your RAILS_ROOT/config/environments/production.rb file which will handle all your routes for you. This way you don&#8217;t need to setup a relative path on your development environment work.</p>
<pre class="wp-code-highlight prettyprint">
# in RAILS_ROOT/config/environments/production.rb
config.action_controller.relative_url_root = '/reader'
</pre>
<h3>Final Thoughts</h3>
<p>Remember Ruby Enterprise Edition is the new Ruby Interpreter that your Rails web applications are using. If you<br />
have any gem or rake issues make sure that you&#8217;re using the same interpreter that REE is using. Look in the location<br />
installation of REE &#8220;/opt/ruby-ent&#8230;&#8221; bin/gem or bin/rake and see if that helps. I just linked those to the standard /usr/bin/gem and /usr/bin/rake and everything worked fine.</p>
<p>Also I&#8217;ve read some people have trouble using the alias with passenger. This may be an older issue but works for me without a problem on Ubuntu (latest).</p>
<p>Here are some useful resources I found along the way&#8230;</p>
<p>http://robots.thoughtbot.com/post/159806388/phusion-passenger-with-a-prefix</p>
<p>http://www.modrails.com/documentation/Users%20guide.html#deploying_rails_to_sub_uri</p>
<p>http://www.modrails.com/documentation/Users%20guide.html#RailsBaseURI</p>
<p>http://stackoverflow.com/questions/848258/server-prefix-and-rails-routes</p>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/ruby-on-rails/install-and-serve-a-rails-application-from-php-subdirectory-using-apache-phussion-passenger-and-ruby-enterprise-edition/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Generate MySQL Datetime Type Using PHP Date() Function</title>
		<link>http://seanbehan.com/php/generate-mysql-datetime-type-using-php-date-function/</link>
		<comments>http://seanbehan.com/php/generate-mysql-datetime-type-using-php-date-function/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 18:22:27 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[datetime]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[strftime]]></category>
		<category><![CDATA[type]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=779</guid>
		<description><![CDATA[If you want to insert a datetime that matches the default mysql datetime type format use this date('Y-m-d H:i:s');]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Fphp%2Fgenerate-mysql-datetime-type-using-php-date-function%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Generate MySQL Datetime Type Using PHP Date() Function" data-url="http://seanbehan.com/php/generate-mysql-datetime-type-using-php-date-function/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>If you want to insert a datetime that matches the default mysql datetime type format use this</p>
<pre class="wp-code-highlight prettyprint">
date('Y-m-d H:i:s');
</pre>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/php/generate-mysql-datetime-type-using-php-date-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Paypal IPN Script</title>
		<link>http://seanbehan.com/php/php-paypal-ipn-script/</link>
		<comments>http://seanbehan.com/php/php-paypal-ipn-script/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 21:45:42 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[fsockopen]]></category>
		<category><![CDATA[ipn]]></category>
		<category><![CDATA[paypal]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=776</guid>
		<description><![CDATA[Simple script for posting a valid response back to Paypal service after a sale is completed using the Paypal Instant Checkout payment method. &#38;lt;?php // read the post from PayPal system and add 'cmd' $req = 'cmd=_notify-validate'; foreach ($_POST as $key =&#62; $value) { $value = urlencode(stripslashes($value)); $req .= &#34;&#38;$key=$value&#34;; } // post back to [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Fphp%2Fphp-paypal-ipn-script%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="PHP Paypal IPN Script" data-url="http://seanbehan.com/php/php-paypal-ipn-script/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>Simple script for posting a valid response back to Paypal service after a sale is completed using the Paypal Instant Checkout payment method.</p>
<pre class="wp-code-highlight prettyprint">
&amp;lt;?php
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';

foreach ($_POST as $key =&gt; $value) {
  $value = urlencode(stripslashes($value));
  $req .= &quot;&amp;$key=$value&quot;;
}

// post back to PayPal system to validate
$header .= &quot;POST /cgi-bin/webscr HTTP/1.0\r\n&quot;;
$header .= &quot;Content-Type: application/x-www-form-urlencoded\r\n&quot;;
$header .= &quot;Content-Length: &quot; . strlen($req) . &quot;\r\n\r\n&quot;;
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);

// assign posted variables to local variables
$item_name        = $_POST['item_name'];
$item_number      = $_POST['item_number'];
$payment_status   = $_POST['payment_status'];
$payment_amount   = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id           = $_POST['txn_id'];
$receiver_email   = $_POST['receiver_email'];
$payer_email      = $_POST['payer_email'];

if (!$fp) {
// HTTP ERROR
} else {
  fputs ($fp, $header . $req);
  while (!feof($fp)) {
    $res = fgets ($fp, 1024);
    if (strcmp ($res, &quot;VERIFIED&quot;) == 0) {
      // check the payment_status is Completed
      // check that txn_id has not been previously processed
      // check that receiver_email is your Primary PayPal email
      // check that payment_amount/payment_currency are correct
      // process payment
    } else if (strcmp ($res, &quot;INVALID&quot;) == 0) {
      // log for manual investigation
    }
  }
fclose ($fp);
}
</pre>
<p>I grabbed this script from Paypal Docs&#8230; I never can find the info I need w/in their site so I&#8217;m posting here for reference.  <a href="https://www.paypal.com/us/cgi-bin/webscr?cmd=p/pdn/ipn-codesamples-pop-outside#php">https://www.paypal.com/us/cgi-bin/webscr?cmd=p/pdn/ipn-codesamples-pop-outside#php</a></p>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/php/php-paypal-ipn-script/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Listing Files and Directories with PHP</title>
		<link>http://seanbehan.com/php/listing-files-and-directories-with-php/</link>
		<comments>http://seanbehan.com/php/listing-files-and-directories-with-php/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 18:27:47 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[directories]]></category>
		<category><![CDATA[files]]></category>
		<category><![CDATA[ksort]]></category>
		<category><![CDATA[read]]></category>
		<category><![CDATA[stat]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=774</guid>
		<description><![CDATA[Listing all files and directories using PHP 5. &#38;lt;?php $files = array(); $dir = dir(&#34;.&#34;); while(false!==($file=$dir-&#38;gt;read())): if(($file{0}!=&#34;.&#34;) &#38;&#38; ($file{0}!=&#34;~&#34;) &#38;&#38; (substr($file, -3)!=&#34;LCK&#34;) &#38;&#38; ($file!=basename($_SERVER[&#34;PHP_SELF&#34;]))): $files[$file] = stat($file); // endif; endwhile; $dir-&#38;gt;close(); ksort($files); ?&#38;gt; &#38;lt;table border=1 cellpadding=5&#38;gt; &#38;lt;tr&#38;gt;&#38;lt;th&#38;gt;Name&#38;lt;/th&#38;gt;&#38;lt;th&#38;gt;Size&#38;lt;/th&#38;gt;&#38;lt;th&#38;gt;Date&#38;lt;/th&#38;gt;&#38;lt;/tr&#38;gt; &#38;lt;?php foreach($files as $name =&#38;gt; $stats): ?&#38;gt; &#38;lt;tr&#38;gt; &#38;lt;td&#38;gt;&#38;lt;?php print $name;?&#38;gt;&#38;lt;/td&#38;gt; &#38;lt;td&#38;gt;&#38;lt;?php print $stats['size']; ?&#38;gt;&#38;lt;/td&#38;gt; &#38;lt;td&#38;gt;&#38;lt;?php print date(&#34;m-d-Y [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Fphp%2Flisting-files-and-directories-with-php%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Listing Files and Directories with PHP" data-url="http://seanbehan.com/php/listing-files-and-directories-with-php/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>Listing all files and directories using PHP 5.</p>
<pre class="wp-code-highlight prettyprint">
&amp;lt;?php
$files = array(); $dir = dir(&quot;.&quot;);
while(false!==($file=$dir-&amp;gt;read())):
  if(($file{0}!=&quot;.&quot;) &amp;&amp; ($file{0}!=&quot;~&quot;) &amp;&amp; (substr($file, -3)!=&quot;LCK&quot;)
    &amp;&amp; ($file!=basename($_SERVER[&quot;PHP_SELF&quot;]))):
      $files[$file] = stat($file); //
    endif;
endwhile;
$dir-&amp;gt;close(); ksort($files); ?&amp;gt;

&amp;lt;table border=1 cellpadding=5&amp;gt;
&amp;lt;tr&amp;gt;&amp;lt;th&amp;gt;Name&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;Size&amp;lt;/th&amp;gt;&amp;lt;th&amp;gt;Date&amp;lt;/th&amp;gt;&amp;lt;/tr&amp;gt;
&amp;lt;?php foreach($files as $name =&amp;gt; $stats): ?&amp;gt;
  &amp;lt;tr&amp;gt;
    &amp;lt;td&amp;gt;&amp;lt;?php print $name;?&amp;gt;&amp;lt;/td&amp;gt;
    &amp;lt;td&amp;gt;&amp;lt;?php print $stats['size']; ?&amp;gt;&amp;lt;/td&amp;gt;
    &amp;lt;td&amp;gt;&amp;lt;?php print date(&quot;m-d-Y h:ia&quot;, $stats['mtime']); ?&amp;gt;&amp;lt;/td&amp;gt;
  &amp;lt;/tr&amp;gt;
&amp;lt;?php endforeach; ?&amp;gt;&amp;lt;/table&amp;gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/php/listing-files-and-directories-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Highlight String in PHP</title>
		<link>http://seanbehan.com/php/highlight-string-in-php/</link>
		<comments>http://seanbehan.com/php/highlight-string-in-php/#comments</comments>
		<pubDate>Sat, 23 Jan 2010 16:57:29 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[file_get_contents]]></category>
		<category><![CDATA[highlight]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=765</guid>
		<description><![CDATA[Function for highlighting text/strings in PHP. $content = file_get_contents(&#34;http://php.net/&#34;); print highlight(&#34;PHP&#34;, $content); function highlight($match, $string){ return str_ireplace($match, &#34;&#38;lt;span style='background:yellow'&#38;gt;$match&#38;lt;/span&#38;gt;&#34;, $string); } Will output something like this ***Notice all the styles are gone :( &#8230; would need to parse the document body to maintain stylesheet and other &#8216;php&#8217; strings that might be in resources paths.]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Fphp%2Fhighlight-string-in-php%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Highlight String in PHP" data-url="http://seanbehan.com/php/highlight-string-in-php/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>Function for highlighting text/strings in PHP.</p>
<pre class="wp-code-highlight prettyprint">
$content = file_get_contents(&quot;http://php.net/&quot;);

print highlight(&quot;PHP&quot;, $content);

function highlight($match, $string){
  return str_ireplace($match, &quot;&amp;lt;span style='background:yellow'&amp;gt;$match&amp;lt;/span&amp;gt;&quot;, $string);
}
</pre>
<p>Will output something like this<br />
<div class="wp-caption alignnone" style="width: 355px"><img alt="Highlighted PHP.Net" src="http://farm5.static.flickr.com/4003/4297402799_22d2a0e816_o.jpg" title="PHP Highlight" width="345" height="334" style="background:#eeeeee;padding:3px;border:solid 1px #CCC;"/><p class="wp-caption-text">Highlighted PHP.Net</p></div></p>
<p>***Notice all the styles are gone :( &#8230; would need to parse the document body to maintain stylesheet and other &#8216;php&#8217; strings that might be in resources paths.</p>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/php/highlight-string-in-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Absolutize Relative Links Using PHP and Preg_Replace_Callback</title>
		<link>http://seanbehan.com/php/absolutize-relative-links-using-php-and-preg_replace_callback/</link>
		<comments>http://seanbehan.com/php/absolutize-relative-links-using-php-and-preg_replace_callback/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 17:29:41 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[absolute links]]></category>
		<category><![CDATA[file_get_contents]]></category>
		<category><![CDATA[preg_replace_callback]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[relative links]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=727</guid>
		<description><![CDATA[I was in the market for a simple php script to replace hrefs with their absolute paths from scraped web pages. I wrote one myself. I used the preg_replace_callback function so that I could pass the parsed results as a single variable. &#38;lt;?php $domain = &#34;http://seanbehan.com&#34;; $pattern = &#34;/\bhref=[\&#34;&#124;'](.*?)[\&#34;&#124;']/&#34;; $string = file_get_contents($domain); // prepends relative [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Fphp%2Fabsolutize-relative-links-using-php-and-preg_replace_callback%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Absolutize Relative Links Using PHP and Preg_Replace_Callback" data-url="http://seanbehan.com/php/absolutize-relative-links-using-php-and-preg_replace_callback/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>I was in the market for a simple php script to replace hrefs with their absolute paths from scraped web pages. I  wrote one myself. I used the preg_replace_callback function so that I could pass the parsed results as a single variable.</p>
<pre class="wp-code-highlight prettyprint">
&amp;lt;?php
$domain = &quot;http://seanbehan.com&quot;;
$pattern = &quot;/\bhref=[\&quot;|'](.*?)[\&quot;|']/&quot;;
$string = file_get_contents($domain);

// prepends relative links w/ $domain skips returns the match if already absolute
function replace_href($match){
  global $domain;
  if(substr($match[1], 0, 7)!==&quot;http://&quot; &amp;&amp; substr($match[1],0,8)!==&quot;https://&quot;){
    return &quot;href='&quot;.$domain.$match[1].&quot;'&quot;;
  } else {
    return &quot;href='&quot;.$match[1].&quot;'s&quot;;
  }
}
print preg_replace_callback($pattern, &quot;replace_href&quot;, $string);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/php/absolutize-relative-links-using-php-and-preg_replace_callback/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>TinyMCE Rich Text Editor: HELLO EDITOR Plugin Tutorial and Example</title>
		<link>http://seanbehan.com/wordpress/tinymce-rich-text-editor-hello-editor-plugin-tutorial-and-example/</link>
		<comments>http://seanbehan.com/wordpress/tinymce-rich-text-editor-hello-editor-plugin-tutorial-and-example/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 19:26:52 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[text editor]]></category>
		<category><![CDATA[tinymce]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=598</guid>
		<description><![CDATA[I wanted to create a button for the TinyMCE Rich Text Editor for WordPress. It was tough to find good docs on the subject. There are a couple of useful posts out there but in general I found them lacking. http://codex.wordpress.org/TinyMCE_Custom_Buttons#Creating_an_MCE_Editor_Plugin The above resource has a good section on the PHP code needed to write [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Fwordpress%2Ftinymce-rich-text-editor-hello-editor-plugin-tutorial-and-example%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="TinyMCE Rich Text Editor: HELLO EDITOR Plugin Tutorial and Example" data-url="http://seanbehan.com/wordpress/tinymce-rich-text-editor-hello-editor-plugin-tutorial-and-example/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>I wanted to create a button for the TinyMCE Rich Text Editor for WordPress. It was tough to find good docs on the subject. There are a couple of useful posts out there but in general I found them lacking.<br />
<a href=" http://codex.wordpress.org/TinyMCE_Custom_Buttons#Creating_an_MCE_Editor_Plugin"></p>
<p>http://codex.wordpress.org/TinyMCE_Custom_Buttons#Creating_an_MCE_Editor_Plugin</a></p>
<p>The above resource has a good section on the PHP code needed to write your own callbacks but there is no mention of the JavaScript required to create a button and interact with it. Links are available for more reading but why not also post a code sample to get up and running?</p>
<p>Anyway, I made a simple plugin after hobbling a bunch of resources together to get a button in the text editor that when clicked triggers an alert to the window. The code isn&#8217;t fancy but it might provide a starting off point for a larger project or be useful as a resource for some of the basic ideas involved. I read through a couple of the sample plugins included with WordPress along with the Viper Video Quicktags Plugin, which makes extensive use of the feature. However, they were too complex for a quick, basic understanding.</p>
<p>This plugin doesn&#8217;t do a lot. I&#8217;ll probably flesh it out a bit more when I have a clearer understanding of how it all works. For now here are some code samples and at the bottom of this post there is a link to the .zip file for the plugin which you can install on your own site.</p>
<p>In wp-content/plugins/hello_editor/index.php</p>
<pre class="wp-code-highlight prettyprint">&amp;lt;?php
/*
Plugin Name: Hello Editor
Plugin URI: http://seanbehan.com/wordpress/tinymce-rich-text-editor-hello-editor-plugin-tutorial-and-example/
Description: A simple plugin showing how to add a button to the rich text editor in WordPress.
The plugin doesn't do anything except place a button and respond to onclick event, with &quot;Hello Editor&quot;.
Most of the editor plugins available are too 'functional' to quickly read and see how to do the
basics. This plugin doesn't 'do' anything, rather it makes it simple to read what is going on.
Version: 0.1
Author: Sean Behan
Author URI: http://seanbehan.com
*/

define( &quot;HELLO_EDITOR_PLUGIN_DIR&quot;, &quot;hello_editor&quot; );
define( &quot;HELLO_EDITOR_PLUGIN_URL&quot;, &quot;/wp-content/plugins/&quot; . HELLO_EDITOR_PLUGIN_DIR );

// Register the external pllugin from the .js file
function hello_editor_register_external_plugin($plugin_array) {
  $plugin_array['HELLO_EDITOR'] = HELLO_EDITOR_PLUGIN_URL . '/editor_plugin.js';
  return $plugin_array;
}

// Add the button to the array ***NOTE*** The name here &quot;HELLO_EDITOR&quot; must
//match the name in the editor plugin file for the addButton(name_of_button) function!
function hello_editor_register_button($buttons) {
  array_push( $buttons, &quot;|&quot;, &quot;HELLO_EDITOR&quot; );
  return $buttons;
}

// Filters which will call our functions
function hello_editor_init(){
  add_filter(&quot;mce_external_plugins&quot;, &quot;hello_editor_register_external_plugin&quot;);
  add_filter('mce_buttons', 'hello_editor_register_button');
}

// When the editor is initialized
add_action('init', 'hello_editor_init');</pre>
<p>In wp-content/plugins/hello_editor/editor_plugin.js</p>
<pre class="wp-code-highlight prettyprint">(function() {
  //Init the plugin
  tinymce.create('tinymce.plugins.HELLO_EDITOR', {
    init : function( ed, url ) {
    //addButton name needs to match $plugin_array['HELLO_EDITOR'] in add_filter function
    ed.addButton('HELLO_EDITOR', {
      title : 'Hello Editor',
      image : url + &quot;/buttons/hello.png&quot;,
      onclick : function(){
        alert(&quot;HELLO EDITOR!&quot;);
      }
    });
  },
  //Info about the plugin
  getInfo : function() {
    return {
      longname : &quot;Sean Behan's Sample Hello Editor Plugin&quot;,
      author : 'Sean Behan',
      authorurl : 'http://www.seanbehan.com/',
      infourl : 'http://seanbehan.com/wordpress/tinymce-rich-text-editor-hello-editor-plugin-tutorial-and-example/',
      version : &quot;0.1&quot;
    };
  }
});
tinymce.PluginManager.add('HELLO_EDITOR', tinymce.plugins.HELLO_EDITOR);
})();</pre>
<p>You&#8217;ll also need a directory called buttons inside the hello_editor plugin directory with a hello.png file which will be displayed. Without it you&#8217;ll just get a blank button. You can rename this but remember to change the name in the editor_plugin.js file as well.</p>
<p>You can download the sample plugin here <a href="http://seanbehan.com/wp-content/uploads/2009/11/hello_editor.zip">http://seanbehan.com/wp-content/uploads/2009/11/hello_editor.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/wordpress/tinymce-rich-text-editor-hello-editor-plugin-tutorial-and-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

