<?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>Brendan Nee &#187; code</title>
	<atom:link href="http://bnee.com/tag/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://bnee.com</link>
	<description>Brendan Nee Online</description>
	<lastBuildDate>Tue, 09 Mar 2010 01:11:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/>		<item>
		<title>List pages in wordpress into a PHP Array</title>
		<link>http://bnee.com/2008/04/list-pages-in-wordpress-into-a-php-array/</link>
		<comments>http://bnee.com/2008/04/list-pages-in-wordpress-into-a-php-array/#comments</comments>
		<pubDate>Thu, 10 Apr 2008 10:04:18 +0000</pubDate>
		<dc:creator>Brendan Nee</dc:creator>
				<category><![CDATA[tech]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[wordpress]]></category>

	<!-- AutoMeta Start -->
	<category>wpdb</category>
	<category>wp_list_pages</category>
	<category>parent</category>
	<category>pageposts</category>
	<category>array</category>
	<category>pages</category>
	<category>function</category>
	<category>posts</category>
	<!-- AutoMeta End -->
	
		<guid isPermaLink="false">http://www.bnee.com/?p=161</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><strong>Update:</strong> Thanks to Joost in the comments for suggesting the use of <a href="http://codex.wordpress.org/Function_Reference/get_pages">get_pages()</a> to accomplish the same thing as what I posted below.  He posted the example:</p>
<pre><textarea style="border:1px solid #999;word-wrap:break-word;width:500px;height:100px;">
$pages = get_pages(‘child_of’ => [[THE PARENT ID]], ’sort_order’ => ‘ASC’);
foreach ($pages as $page) {
  // Do your thang
}
</textarea></pre>
<p>This seems much better than what I had previously used, but for reference, my old post is below:</p>
<p>I spent some time figuring out how to get the <a href="http://codex.wordpress.org/wp_list_pages">wordpress wp_list_pages function</a> to return the results as a PHP array of URLs and page names.  There wasn&#8217;t an obvious way to do this and searching google did not yield anything particularly useful.  The wp_list_pages function has an &#8220;echo&#8221; parameter which when set to 0 returns a list of links as a string.  That won&#8217;t help much if you want it as an array with links and page names.</p>
<p>I ended up writing a short script that will query wordpress for the name and URL of all of the subpages of a specified page.  This could be used to make a function that formatted a list of pages a particular way (like making the list wrap into two or more columns).  Its nothing fancy, but perhaps it can help other wordpressers who are looking for something similar.</p>
<blockquote><p>
&lt;?php<br />
$querystr = &#8220;SELECT $wpdb->posts.* FROM $wpdb->posts WHERE $wpdb->posts.post_status = &#8216;publish&#8217; AND $wpdb->posts.post_type = &#8216;page&#8217; AND $wpdb->posts.post_parent = [[Parent Page ID]] ORDER BY $wpdb->posts.post_title ASC&#8221;;</p>
<p>$pageposts = $wpdb->get_results($querystr, OBJECT);</p>
<p>if ($pageposts):<br />
	foreach ($pageposts as $post):<br />
	setup_postdata($post);<br />
		// Add your own logic or formatting here<br />
		?><br />
		&lt;a href=&#8221;&lt;?php the_permalink() ?>&#8221; title=&#8221;Permanent Link to &lt;?php the_title(); ?>&#8221;>&lt;?php the_title(); ?>&lt;/a><br />
	&lt;?php endforeach;<br />
	else :<br />
		echo &#8216;Not Found&#8217;;<br />
endif;<br />
?>
</p></blockquote>
<p>Where [[Parent Page ID]] is the id number of the parent page you would like to get children from.  If you want all pages included, don&#8217;t include this parameter.</p>
]]></content:encoded>
			<wfw:commentRss>http://bnee.com/2008/04/list-pages-in-wordpress-into-a-php-array/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Automatic wordpress backups to Amazon S3</title>
		<link>http://bnee.com/2007/10/automatic-wordpress-backups-to-amazon-s3/</link>
		<comments>http://bnee.com/2007/10/automatic-wordpress-backups-to-amazon-s3/#comments</comments>
		<pubDate>Thu, 25 Oct 2007 07:30:58 +0000</pubDate>
		<dc:creator>Brendan Nee</dc:creator>
				<category><![CDATA[tech]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[s3]]></category>
		<category><![CDATA[wordpress]]></category>

	<!-- AutoMeta Start -->
	<category>wordpress</category>
	<category>backups</category>
	<category>files</category>
	<category>database</category>
	<category>nightly</category>
	<category>themes</category>
	<category>perform</category>
	<category>plugins</category>
	<!-- AutoMeta End -->
	
		<guid isPermaLink="false">http://www.bnee.com/2007/10/automatic-wordpress-backups-to-amazon-s3/</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>I use wordpress for many sites, and its really important for me to be able to automatically perform nightly backups of not just the database, but all files including uploads, themes, plugins and the basic wordpress files.  I need the ability to revert any file back to a previous version.</p>
<p>I found a <a href="http://paulstamatiou.com/2007/07/29/how-to-bulletproof-server-backups-with-amazon-s3/">variety</a> of <a href="http://elliottback.com/wp/archives/2007/08/05/easy-database-backup-with-amazon-s3/">solutions</a> to backing up files using S3, but none that exactly met my needs, so I decided to post my work here.</p>
<p>Note that these instructions assume your web server is Unix, Linux or Mac OS X based.  It also assumes you have a basic understanding of FTP, SSH, firefox extensions and compressed files.</p>
<p><strong>1. Get the s3-bash code library</strong></p>
<p>The s3 BASH library is a collection of scripts that can get, put or delete files from Amazon s3.  You can grab them from <a href="http://code.google.com/p/s3-bash/">Google Code</a>.</p>
<p><strong>2. Unpack and upload these scripts to your server.</strong><br />
They should probably live outside of your webroot.  Depending on how your server is set up you might put them in:</p>
<blockquote><p>/home/USER/s3</p></blockquote>
<p>Where USER is your username.</p>
<p><strong>3. Give s3-put the proper permissions</strong><br />
We need to be able to execute s3-put so chmod it to 744.</p>
<blockquote><p>chmod 744 /home/USER/s3/s3-put</p></blockquote>
<p><strong>4. Sign up for an Amazon S3 Account</strong><br />
You&#8217;ll need an Amazon S3 account, so <a href="http://amazon.com/s3">sign up</a> and then get your access key ID and secret access key on the AWS access identifiers page.</p>
<p><strong>5. Put your secret access key in a text file and upload it to the server</strong><br />
You could call it s3.key and put it in the same folder you uploaded the s3-bash scripts to. Chmod it to 640.</p>
<blockquote><p>chmod 640 /home/USER/s3/s3.key</p></blockquote>
<p><strong>6. Create a folder for the backups</strong><br />
Make a folder on your webserver for backups, perhaps:</p>
<blockquote><p>/home/USER/backups</p></blockquote>
<p>Where USER is your username.</p>
<p><strong>7. Create a bucket on Amazon S3 for your backups</strong><br />
The easiest way I found to do this is to use the firefox extension <a href="http://www.rjonna.com/ext/s3fox.php">S3 Firefox Organizer</a>.  Add the extension, restart firefox and then in Firefox go to &#8220;Tools&#8221; > &#8220;S3 Organizer&#8221;.  Click &#8220;Manage Accounts&#8221; and enter your access key ID and secret access key and then login.  Create a bucket (directory) for your backups.  I created a one called bnee.</p>
<p><strong>8. Write the backup script</strong><br />
This is the tricky part.  Here is the script I came up with. The [[Double Bracketed]] items are places where you&#8217;ll have to enter information specific to your account (see below).</p>
<blockquote><p>#!/bin/bash<br />
USER=[[USER]]<br />
mysqldump &#8211;add-drop-table -u [[DBUSER]] -p[[DBPASSWORD]] -A >/home/$USER/backups/mysql.sql<br />
rm /home/$USER/backups/backup.tgz<br />
tar -czvf /home/$USER/backups/backup.tgz [[PATHTOWEBROOT]] /home/$USER/backups/mysql.sql<br />
NOW=$(date +_%b_%d_%y)<br />
/home/$USER/s3/s3-put -k [[S3ACCESSKEYID]] -s /home/$USER/s3/s3.key -T /home/$USER/backups/backup.tgz -v /[[S3BUCKET]]/backup$NOW.tgz</p></blockquote>
<p><strong>[[USER]]</strong> &#8211; Because the username of my web server is used a lot in the paths, this is a variable<br />
<strong>[[DBUSER]]</strong> &#8211; The username of the mysql database.  You can get this from the wp-config.php file of your wordpress installation.<br />
<strong>[[DBPASSWORD]]</strong> &#8211; The password for your mysql database. You can get this from the wp-config.php file of your wordpress installation.<br />
<strong>[[PATHTOWEBROOT]]</strong> &#8211; The path to the webroot.  Its likely something like /home/USER/public_html<br />
<strong>[[S3ACCESSKEYID]]</strong> &#8211; The access key ID for Amazon S3 (see step 3).<br />
<strong>[[S3BUCKET]]</strong> &#8211; The name of the bucket (directory) you created in step 6.</p>
<p>You might have to change the various paths depending on the way your web server is set up and the folder names you chose in previous steps.</p>
<p>Paste all of this into a text file and name it something like backup.sh.  Upload it to your web server, outside of the webroot.</p>
<blockquote><p>/home/USER/backup.sh</p></blockquote>
<p><strong>9. Test the script</strong><br />
Verify that the script is working by running it.</p>
<blockquote><p>sh /home/USER/backup.sh</p></blockquote>
<p>If everything is working ok, you&#8217;ll see a lot of output as each file of your website is added to the compressed backup and then uploaded to Amazon S3.  It may take a minute or so to run, but when it is done you can verify that the script worked by using the S3 Firefox plugin to check that the file ended up where you expected it to.</p>
<p><strong>10. Automate it</strong><br />
Add a cron job to run it every night</p>
<blockquote><p>0 0 * * * sh /home/USER/backup.sh</p></blockquote>
<p>If everything is configured correctly, this should perform a full backup nightly at midnight.</p>
<p>Note for subversion users:  if you&#8217;d like to exclude all of the .svn folders and files from your backup, just use
<pre>--exclude=".svn"</pre>
<p> before the [[PATHTOWEBROOT]] in step 8 above.</p>
]]></content:encoded>
			<wfw:commentRss>http://bnee.com/2007/10/automatic-wordpress-backups-to-amazon-s3/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
	</channel>
</rss>
