<?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>Hamstar &#187; code</title>
	<atom:link href="http://www.hamstar.co.nz/tag/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.hamstar.co.nz</link>
	<description>Another Metal Car Computer Geek blog</description>
	<lastBuildDate>Thu, 10 Jun 2010 20:05:53 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Hotfile link extractor</title>
		<link>http://www.hamstar.co.nz/2009/09/24/hotfile-link-extractor/</link>
		<comments>http://www.hamstar.co.nz/2009/09/24/hotfile-link-extractor/#comments</comments>
		<pubDate>Thu, 24 Sep 2009 10:53:43 +0000</pubDate>
		<dc:creator>hamstar</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bot]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[hotfile]]></category>
		<category><![CDATA[link]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[premium]]></category>
		<category><![CDATA[spider]]></category>
		<category><![CDATA[url]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.hamstar.co.nz/?p=328</guid>
		<description><![CDATA[A mate of mine needed a link extractor for his hotfile.com account so that he could drop a bunch of download page links in and get the premium links to the actual file back, all in a single page, or file.  From that page or file he can load them into his download program. [...]]]></description>
			<content:encoded><![CDATA[<p>A mate of mine needed a link extractor for his hotfile.com account so that he could drop a bunch of download page links in and get the premium links to the actual file back, all in a single page, or file.  From that page or file he can load them into his download program.  These are all legit links btw, no illegal shit.</p>
<p>Anyways I made a bot that has a form to start with where you dump your download urls.  Then it goes to the hotfile site, logs in with the given user credentials, runs through each link that the bot was given, and extracts the premium download URL to the file.  Then it either prints the links to the page OR it saves the links into a files.txt in the web folder and forces a download in the browser.</p>
<p>The manual way to do that is go to every hotfile.com download link, click on the download file button to start the download, and repeat for every download url you have.  This you can throw 50 hotfile.com download links in the form, hit go and it will give you all the premium download links at once.  It probably breaks the hotfile terms and services so you could put your account in jeopardy (not my fault) but I don&#8217;t use the script, I just solved a problem.</p>
<p>Here&#8217;s the code for it if anyone wants to use it.  Would be cool if you let me know if it was useful as well <img src='http://www.hamstar.co.nz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
<span id="more-328"></span></p>
<p>Please note you will also need <a href="http://hamstar.co.nz/files/lib_html.php">this</a> (<a href="http://simplehtmldom.sourceforge.net/">SimpleHTMLDOM</a>) and <a href="http://hamstar.co.nz/files/lib_curl.php">this</a> (<a href="http://github.com/shuber/curl">Sean Hubers Curl Wrapper</a>)</p>
<div class="codecolorer-container php vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<br />
<br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">/**************************************************************************<br />
&nbsp; &nbsp; *<br />
&nbsp; &nbsp; * &nbsp; This program is free software: you can redistribute it and/or modify<br />
&nbsp; &nbsp; * &nbsp; it under the terms of the GNU General Public License as published by<br />
&nbsp; &nbsp; * &nbsp; the Free Software Foundation, either version 3 of the License, or<br />
&nbsp; &nbsp; * &nbsp; (at your option) any later version.<br />
&nbsp; &nbsp; *<br />
&nbsp; &nbsp; * &nbsp; This program is distributed in the hope that it will be useful,<br />
&nbsp; &nbsp; * &nbsp; but WITHOUT ANY WARRANTY; without even the implied warranty of<br />
&nbsp; &nbsp; * &nbsp; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. &nbsp;See the<br />
&nbsp; &nbsp; * &nbsp; GNU General Public License for more details.<br />
&nbsp; &nbsp; *<br />
&nbsp; &nbsp; * &nbsp; You should have received a copy of the GNU General Public License<br />
&nbsp; &nbsp; * &nbsp; along with this program. &nbsp;If not, see &lt;http://www.gnu.org/licenses/&gt;.<br />
&nbsp; &nbsp; *<br />
&nbsp; &nbsp; * &nbsp; There is one condition on the use of this software and that is that<br />
&nbsp; &nbsp; * &nbsp; you accept that you are not part of or party to any DCMA agents or<br />
&nbsp; &nbsp; * &nbsp; companies, nor do you represent any anti-piracy groups or industry<br />
&nbsp; &nbsp; * &nbsp; distributers.<br />
&nbsp; &nbsp; *<br />
&nbsp; &nbsp; ****************************************************************************<br />
<br />
&nbsp; &nbsp; hotfilebot.php VERSION 1.5<br />
<br />
&nbsp; &nbsp; This bot will take the URLs for a download link from hotfile.com and extract <br />
&nbsp; &nbsp; the URLs of the actual file in each URL. &nbsp;This is so you can run it on a<br />
&nbsp; &nbsp; personal web server, and automatically extract every file URL from every<br />
&nbsp; &nbsp; download page without having to go through them 1 by 1. &nbsp;You need to have<br />
&nbsp; &nbsp; a hotfile account for this to work and you need to fill out your details<br />
&nbsp; &nbsp; below.<br />
<br />
&nbsp; &nbsp; Please let me know if you find this bot useful :)<br />
<br />
&nbsp; &nbsp; Copyright (c) 2009 Robert McLeod &lt;hamstar[[@]]telescum.co.nz&gt;<br />
<br />
&nbsp; &nbsp; http://www.hamstar.co.nz/2009/09/24/hotfile-link-extractor/<br />
<br />
&nbsp; &nbsp; */</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Disable errors</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/ini_set"><span style="color: #990000;">ini_set</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'display_errors'</span><span style="color: #339933;">,</span>0<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Define your own username and password for hotfile.com</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// And also the filename and extension you want to save the urls to</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/define"><span style="color: #990000;">define</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'HOTFILE_USER'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'your_username'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/define"><span style="color: #990000;">define</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'HOTFILE_PASS'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'your_password'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/define"><span style="color: #990000;">define</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'OUTPUT_FILE_NAME'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'files'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/define"><span style="color: #990000;">define</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'OUTPUT_FILE_EXT'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'.txt'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/define"><span style="color: #990000;">define</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SLEEP_TIME'</span><span style="color: #339933;">,</span>100<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Time to sleep between requests in milliseconds</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Don't touch these</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/define"><span style="color: #990000;">define</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'TO_FILE'</span><span style="color: #339933;">,</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tofile'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/define"><span style="color: #990000;">define</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'OUTPUT_FILE'</span><span style="color: #339933;">,</span> OUTPUT_FILE_NAME <span style="color: #339933;">.</span> OUTPUT_FILE_EXT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Error messages to use when iterating through the failuresArray</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$errors</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'the file was removed from hotfile.'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$errors</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'the HTTP status code was not 200.'</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Function to check if its a file output</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">function</span> tofile<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> TO_FILE<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Should return a true or false</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Force a download of the file</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'getfile'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Turn of output compression for IE</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/ini_get"><span style="color: #990000;">ini_get</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'zlib.output_compression'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <a href="http://www.php.net/ini_set"><span style="color: #990000;">ini_set</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'zlib.output_compression'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Off'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Print the contents of the file to the browser</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-type: application/force-download'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Disposition: inline; filename=&quot;'</span> <span style="color: #339933;">.</span> OUTPUT_FILE <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Transfer-Encoding: Binary'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-length: '</span><span style="color: #339933;">.</span><a href="http://www.php.net/filesize"><span style="color: #990000;">filesize</span></a><span style="color: #009900;">&#40;</span>OUTPUT_FILE<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Type: application/octet-stream'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Disposition: attachment; filename=&quot;'</span> <span style="color: #339933;">.</span> OUTPUT_FILE <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/readfile"><span style="color: #990000;">readfile</span></a><span style="color: #009900;">&#40;</span>OUTPUT_FILE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/exit"><span style="color: #990000;">exit</span></a><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">?&gt;</span><br />
<br />
&lt;html&gt;<br />
&nbsp; &nbsp; &lt;head&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;title&gt;Hotfile FileURL Fetcher&lt;/title&gt;<br />
&nbsp; &nbsp; &lt;/head&gt;<br />
&nbsp; &nbsp; &lt;body&gt;<br />
<br />
<span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Check that there is a filelist incoming</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'urls'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Include CURL and HTML</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">include</span> <span style="color: #0000ff;">'lib_curl.php'</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">include</span> <span style="color: #0000ff;">'lib_html.php'</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Set username and pass</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> HOTFILE_USER<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$pass</span> <span style="color: #339933;">=</span> HOTFILE_PASS<span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Set login and post data</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$loginUrl</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://hotfile.com/login.php'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$postData</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;user=<span style="color: #006699; font-weight: bold;">$user</span>&amp;pass=<span style="color: #006699; font-weight: bold;">$pass</span>&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$authString</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;b&gt;'</span> <span style="color: #339933;">.</span> HOTFILE_USER <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/b&gt; &nbsp;| &lt;a href=&quot;/logout.php'</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Start curl</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Curl<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user_agent</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_USER_AGENT'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Check if already logged in</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$r</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://hotfile.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$r</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">body</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$count</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/strstr"><span style="color: #990000;">strstr</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$html</span><span style="color: #339933;">,</span><span style="color: #000088;">$authString</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Try logging in with the user details</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/usleep"><span style="color: #990000;">usleep</span></a><span style="color: #009900;">&#40;</span>SLEEP_TIME<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$r</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$loginUrl</span><span style="color: #339933;">,</span><span style="color: #000088;">$postData</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$r</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">body</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// For some reason we couldn't log in (after 2 tries)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$count</span> <span style="color: #339933;">==</span> 2<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Couldn\'t log in for some reason'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Increment the counter</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">++</span><span style="color: #000088;">$count</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;"># end login while loop<br />
</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Split up the urls by newline character</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$urls</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/explode"><span style="color: #990000;">explode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'urls'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Print messages</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;div style=&quot;font-family: arial; margin: 0px auto; text-align: center;&quot;&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;p&gt;OK, here are your '</span><span style="color: #339933;">.</span><a href="http://www.php.net/count"><span style="color: #990000;">count</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$urls</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' file URLs&lt;/p&gt;'</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Run through each URL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$urls</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$u</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Trim whitespace characters so we don't</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// get a 400 bad request error</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$u</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/trim"><span style="color: #990000;">trim</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$u</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Unset HTML first</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/unset"><span style="color: #990000;">unset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$html</span><span style="color: #339933;">,</span><span style="color: #000088;">$c</span><span style="color: #339933;">,</span><span style="color: #000088;">$r</span><span style="color: #339933;">,</span><span style="color: #000088;">$h</span><span style="color: #339933;">,</span><span style="color: #000088;">$fn</span><span style="color: #339933;">,</span><span style="color: #000088;">$fileurl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Get the html of the current URL</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Curl<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user_agent</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_USER_AGENT'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$r</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$u</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$h</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$r</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">headers</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// If the status code is 200 we are good to go</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$h</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Status-Code'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">200</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Parse the HTML into html</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> str_get_html<span style="color: #009900;">&#40;</span><span style="color: #000088;">$r</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">body</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Check that the file has not been removed</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/strstr"><span style="color: #990000;">strstr</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$html</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'This file is either removed due to copyright claim or is deleted by the uploader.'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Get the href (protip: its in h3)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$fileurl</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$html</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'h3'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'a'</span><span style="color: #339933;">,</span>0<span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">href</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Get the filename</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$fn</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/substr"><span style="color: #990000;">substr</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fileurl</span><span style="color: #339933;">,</span><a href="http://www.php.net/strrpos"><span style="color: #990000;">strrpos</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fileurl</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span>1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Put the url and filename into the files array</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$filesArray</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'fn'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$fn</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'url'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$fileurl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Notify removal into failures array</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$failuresArray</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'url'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$u</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'errno'</span> <span style="color: #339933;">=&gt;</span> 1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;"># end file removal check<br />
</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Notify status into failures array</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$failuresArray</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'url'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$u</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'errno'</span> <span style="color: #339933;">=&gt;</span> 2<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;"># end status code check<br />
</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Dont hammer</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/usleep"><span style="color: #990000;">usleep</span></a><span style="color: #009900;">&#40;</span>SLEEP_TIME<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;"># end URL forloop<br />
</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Wipe the contents of our file cos this is a fresh load</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>tofile<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <a href="http://www.php.net/file_put_contents"><span style="color: #990000;">file_put_contents</span></a><span style="color: #009900;">&#40;</span>OUTPUT_FILE<span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Run through the files array</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filesArray</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$f</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>tofile<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Add the current URL to the file</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/file_put_contents"><span style="color: #990000;">file_put_contents</span></a><span style="color: #009900;">&#40;</span>OUTPUT_FILE<span style="color: #339933;">,</span> <span style="color: #000088;">$f</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> FILE_APPEND<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Else print it to the screen</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;p&gt;&lt;a href='<span style="color: #006699; font-weight: bold;">{$f['url']}</span>'&gt;<span style="color: #006699; font-weight: bold;">{$f['fn']}</span>&lt;/a&gt;&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Print the file download link</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>tofile<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;p&gt;Here is your file of &lt;a href=&quot;'</span><span style="color: #339933;">.</span> OUTPUT_FILE <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;&gt;files&lt;/a&gt;&lt;/p&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;meta http-equiv=&quot;refresh&quot; content=&quot;1; url='</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SCRIPT_NAME'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'?getfile=true&quot;/&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Print the failures no matter what</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$failuresArray</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$f</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Print the failure</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;p&gt;&lt;span style='color: red;'&gt;Failure&lt;/span&gt;: <span style="color: #006699; font-weight: bold;">{$f['url']}</span> because &lt;span style='color: red;'&gt;{<span style="color: #006699; font-weight: bold;">$errors</span>[<span style="color: #006699; font-weight: bold;">$f</span>['errno']]}&lt;/span&gt;&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Print the redo button</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;p&gt;&lt;button onclick=&quot;location.href=\''</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SCRIPT_NAME'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'\';&quot;&gt;KK Gimme some more!&lt;/button&gt;&lt;/p&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;/div&gt;'</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>&nbsp; &nbsp; <br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">?&gt;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;div style=&quot;font-family: arial; margin: 0px auto; text-align: center;&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;form action=&quot;<span style="color: #000000; font-weight: bold;">&lt;?=</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SCRIPT_NAME'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; method=&quot;post&quot;&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;p&gt;Give me some download URLs and I will munch them up and spit out file URLs&lt;/p&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;p&gt;&lt;textarea name=&quot;urls&quot; style=&quot;width: 1000px; height: 400px;&quot;&gt;&lt;/textarea&gt;&lt;/p&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;p style=&quot;font-size: small;&quot;&gt;* make sure you put a newline between each file&lt;/p&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;p&gt;&lt;input type=&quot;submit&quot; value=&quot;Gimme file URLs in a webpage!&quot;/&gt; | <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;input type=&quot;submit&quot; name=&quot;tofile&quot; value=&quot;Gimme the file URLs in a file!&quot;/&gt;&lt;/p&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/form&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;?php</span> &nbsp; <br />
<br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;"># end post urls check<br />
</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span><br />
<br />
&nbsp; &nbsp; &lt;/body&gt;<br />
&lt;/html&gt;</div></div>
<p>The next step is to try to get it to integrate with the download managers wget and axel.  That could be tricky, basically a php backend/process monitor.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hamstar.co.nz/2009/09/24/hotfile-link-extractor/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>KML creator class</title>
		<link>http://www.hamstar.co.nz/2009/09/22/kml-creator-class/</link>
		<comments>http://www.hamstar.co.nz/2009/09/22/kml-creator-class/#comments</comments>
		<pubDate>Tue, 22 Sep 2009 10:05:49 +0000</pubDate>
		<dc:creator>hamstar</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[google earth]]></category>
		<category><![CDATA[kml]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.hamstar.co.nz/?p=303</guid>
		<description><![CDATA[
Update: This is now available on github!!! Much better!  Check it.

For my latest project I needed a script to create a KML file from a set of data so it could be loaded into Google Earth.  So here is the class if anyone else wants to do the same thing.
Here&#8217;s an example of [...]]]></description>
			<content:encoded><![CDATA[<hr/>
<em>Update: This is now available on github!!! Much better!  <a href="http://github.com/hamstar/Create_KML">Check it.</a></em></p>
<hr/>
<p>For my latest project I needed a script to create a KML file from a set of data so it could be loaded into Google Earth.  So <del datetime="2009-10-18T23:18:15+00:00"><a href="http://www.hamstar.co.nz/2009/09/22/kml-creator-class/#class">here is the class</a></del> if anyone else wants to do the same thing.</p>
<p>Here&#8217;s an example of how to use it:<span id="more-303"></span></p>
<div class="codecolorer-container php vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #666666; font-style: italic;">// Include the class</span><br />
<span style="color: #b1b100;">include</span> <span style="color: #0000ff;">'create.kml.php'</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Create a new KML object</span><br />
<span style="color: #000088;">$kml</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> KML<span style="color: #339933;">;</span><br />
<br />
<span style="color: #000088;">$styles</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'myStyle'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'iconId'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'http://example.com/icon.gif'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'myStyle2'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'iconId2'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'http://example.com/icon2.gif'</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$styles</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$style</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000088;">$s</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> KMLStyle<span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000088;">$s</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$style</span><span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Id of the style for use in placemarks</span><br />
&nbsp; <span style="color: #000088;">$s</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">iconid</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$style</span><span style="color: #009900;">&#91;</span>1<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Icon ID</span><br />
&nbsp; <span style="color: #000088;">$s</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">iconhref</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$style</span><span style="color: #009900;">&#91;</span>2<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Link to the icon</span><br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">// Add the style to the KML</span><br />
&nbsp; <span style="color: #000088;">$kml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addItem</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Get the data from the database</span><br />
<span style="color: #000088;">$q</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_query"><span style="color: #990000;">mysql_query</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SELECT id,name,desc,link,city,state,country,coords FROM table;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/list"><span style="color: #990000;">list</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #339933;">,</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span><span style="color: #000088;">$desc</span><span style="color: #339933;">,</span><span style="color: #000088;">$folder</span><span style="color: #339933;">,</span><span style="color: #000088;">$coords</span><span style="color: #339933;">,</span><span style="color: #000088;">$style</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mysql_fetch_row"><span style="color: #990000;">mysql_fetch_row</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$q</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">// Create a new place object</span><br />
&nbsp; <span style="color: #000088;">$p</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> KMLPlace<span style="color: #339933;">;</span><br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">// Assign bits of the array</span><br />
&nbsp; <span style="color: #000088;">$p</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$id</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000088;">$p</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$name</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000088;">$p</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">desc</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$desc</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000088;">$p</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">folder</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$folder</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000088;">$p</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">style</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$style</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000088;">$p</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">coords</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$coords</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">// If you have HTML in both name and desc call this</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">//$p-&gt;setCDATA();</span><br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">// If you have HTML in just desc then call this</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">//$p-&gt;setCDATA('desc');</span><br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">// Add the item to the kml</span><br />
&nbsp; <span style="color: #000088;">$kml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addItem</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$p</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Create the KML</span><br />
<span style="color: #000088;">$kml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">printHeader</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'xml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Allows the KML to be viewed in the browser</span><br />
<span style="color: #666666; font-style: italic;">//$kml-&gt;printHeader(); // Forces the user to download the KML file</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Print the KML to the browser</span><br />
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$kml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">create</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Save the file as well if we want</span><br />
<span style="color: #000088;">$kml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'output.kml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></div>
<p>This is <a href="http://hamstar.co.nz/files/output.xml">what the output would look like</a> (I changed the extension to XML so you can view it in your browser).</p>
<p>Here&#8217;s a breakdown of each function:</p>
<h3>KMLPlace::setCDATA()</h3>
<p>This function encloses fields in a KMLPlace object (eg. $p) with <em>&lt;![CDATA[</em> and <em>]]&gt;</em> which allows Google Earth to process it as HTML.  Its an XML standard thing.  Called without an argument it will enclose &#8216;name&#8217; and &#8216;desc&#8217; in CDATA tags however you can put a comma separated string of all the fields you want enclosed as a function argument (eg. $p->setData(&#8217;name,style,desc&#8217;) or $p->setData(&#8217;desc&#8217;)).</p>
<h3>KML::addItem($item)</h3>
<p>This function adds an item to your KML object that you created (eg $kml).  This must be an either a KMLPlace object (eg. $p) or a KMLStyle object (eg. $s).  If the object given is not either of those it will return false.</p>
<h3>KML::save(&#8217;output.kml&#8217;)</h3>
<p>This function saves the KML data loaded into the KML object (eg. $kml) to the given filename.  Without the filename it returns false.</p>
<h3>KML::printHeader()</h3>
<p>This function prints the content type header to the page so the browser knows what kind of content is coming after it.  With no arguments it will output the content type for XML which is &#8220;application/vnd.google-earth.kml+xml&#8221;.  However the browser usually thinks it can&#8217;t display this so automatically wants you to download it.  If you give an argument that is boolean true to the function (eg. &#8216;xml&#8217;, 1 or true) it will send a much more browser friendly &#8220;text/xml&#8221; header and you will be able to view the KML in the browser.</p>
<h3>KML::create()</h3>
<p>This is the function that creates all the KML.  It doesn&#8217;t need any arguments and will return to you a string.  What you do with this string is up to you.  I usually just echo it to the page.  Be aware there are \t&#8217;s and \n&#8217;s in the output.</p>
<h3>KML::clear()</h3>
<p>This function will clear the KML data out of the KML object (eg. $kml) to save on memory.  Only really need to do this if you are creating lots of KML files in the same script.</p>
<p>Yeah, thats the class, hope it helps some people.  I bet there is already a class for this, but I couldn&#8217;t find one.</p>
<p><a name="class"><em>EDIT: Y&#8217;know what, here&#8217;s the whole class here:</em></a></p>
<div class="codecolorer-container php vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<br />
&nbsp; &nbsp; <span style="color: #009933; font-style: italic;">/**<br />
&nbsp; &nbsp; * Create a KML file<br />
&nbsp; &nbsp; *<br />
&nbsp; &nbsp; * Class for creating a KML file from a data source<br />
&nbsp; &nbsp; * and outputing it to either a file or string<br />
&nbsp; &nbsp; * &nbsp; <br />
&nbsp; &nbsp; * PHP version 5<br />
&nbsp; &nbsp; *<br />
&nbsp; &nbsp; * @category &nbsp; &nbsp; XML<br />
&nbsp; &nbsp; * @package&nbsp; &nbsp; &nbsp; Create_KML<br />
&nbsp; &nbsp; * @author &nbsp; &nbsp; &nbsp; Robert McLeod &lt;hamstar[[@]]telescum.co.nz&gt;<br />
&nbsp; &nbsp; * @copyright&nbsp; &nbsp; 2009 Robert McLeod<br />
&nbsp; &nbsp; * @license&nbsp; &nbsp; &nbsp; http://www.gnu.org/copyleft/lesser.html &nbsp;LGPL License 2.1<br />
&nbsp; &nbsp; * @version&nbsp; &nbsp; &nbsp; SVN: 1.0<br />
&nbsp; &nbsp; *<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009933; font-style: italic;">/**<br />
&nbsp; &nbsp; * Class to define a style to be added to the KML class<br />
&nbsp; &nbsp; *<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">class</span> KMLStyle <br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$type</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'style'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$iconid</span><span style="color: #339933;">,</span> <span style="color: #000088;">$iconhref</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009933; font-style: italic;">/**<br />
&nbsp; &nbsp; * Class to define a place to be added to the KML class<br />
&nbsp; &nbsp; *<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">class</span> KMLPlace <br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$type</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'place'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$folder</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'**[root]**'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$desc</span><span style="color: #339933;">,</span> <span style="color: #000088;">$style</span><span style="color: #339933;">,</span> <span style="color: #000088;">$coords</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009933; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; * Sets the folder name or empty argument sets the folder to root<br />
&nbsp; &nbsp; &nbsp; &nbsp; *<br />
&nbsp; &nbsp; &nbsp; &nbsp; * @param string<br />
&nbsp; &nbsp; &nbsp; &nbsp; * @access public<br />
&nbsp; &nbsp; &nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setFolder<span style="color: #009900;">&#40;</span><span style="color: #000088;">$folder</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$folder</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">folder</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'**[root]**'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">folder</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$folder</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009933; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; * Sets a CDATA surround on the given comma separated fields<br />
&nbsp; &nbsp; &nbsp; &nbsp; * Called without params it will CDATA the name and desc fields<br />
&nbsp; &nbsp; &nbsp; &nbsp; *<br />
&nbsp; &nbsp; &nbsp; &nbsp; * @param string<br />
&nbsp; &nbsp; &nbsp; &nbsp; * @access public<br />
&nbsp; &nbsp; &nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setCDATA<span style="color: #009900;">&#40;</span><span style="color: #000088;">$fields</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$fields</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">desc</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;![CDATA['</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">desc</span><span style="color: #339933;">.</span><span style="color: #0000ff;">']]&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;![CDATA['</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">']]&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/strstr"><span style="color: #990000;">strstr</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fields</span><span style="color: #339933;">,</span><span style="color: #0000ff;">','</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$fields</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/explode"><span style="color: #990000;">explode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span><span style="color: #000088;">$fields</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fields</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$f</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$f</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;![CDATA['</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$f</span><span style="color: #339933;">.</span><span style="color: #0000ff;">']]&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$fields</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;![CDATA['</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$fields</span><span style="color: #339933;">.</span><span style="color: #0000ff;">']]&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009933; font-style: italic;">/**<br />
&nbsp; &nbsp; * Main class to add items to and create the KML<br />
&nbsp; &nbsp; *<br />
&nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">class</span> KML<br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009933; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; * The array of styles<br />
&nbsp; &nbsp; &nbsp; &nbsp; *<br />
&nbsp; &nbsp; &nbsp; &nbsp; * @var array<br />
&nbsp; &nbsp; &nbsp; &nbsp; * @access protected<br />
&nbsp; &nbsp; &nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; protected <span style="color: #000088;">$styles</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009933; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; * The array of places in their folders<br />
&nbsp; &nbsp; &nbsp; &nbsp; *<br />
&nbsp; &nbsp; &nbsp; &nbsp; * @var array<br />
&nbsp; &nbsp; &nbsp; &nbsp; * @access protected<br />
&nbsp; &nbsp; &nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; protected <span style="color: #000088;">$folders</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009933; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; * Print the content header for a KML file or optionally an XML file<br />
&nbsp; &nbsp; &nbsp; &nbsp; * (so it can be viewed in a browser)<br />
&nbsp; &nbsp; &nbsp; &nbsp; *<br />
&nbsp; &nbsp; &nbsp; &nbsp; * @param bool<br />
&nbsp; &nbsp; &nbsp; &nbsp; * @access public<br />
&nbsp; &nbsp; &nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> printHeader<span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">false</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-type: application/vnd.google-earth.kml+xml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-type: text/xml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009933; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; * Adds an item to the KML data<br />
&nbsp; &nbsp; &nbsp; &nbsp; *<br />
&nbsp; &nbsp; &nbsp; &nbsp; * @param object<br />
&nbsp; &nbsp; &nbsp; &nbsp; * @access public<br />
&nbsp; &nbsp; &nbsp; &nbsp; * @return bool<br />
&nbsp; &nbsp; &nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> addItem<span style="color: #009900;">&#40;</span><span style="color: #000088;">$item</span><span style="color: #009900;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$item</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">||</span> <a href="http://www.php.net/gettype"><span style="color: #990000;">gettype</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$item</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'object'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">||</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">type</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'style'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">type</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'place'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Switch which array to put the given item in</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">type</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'place'</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">folders</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">folder</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'style'</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">styles</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$item</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">default</span><span style="color: #339933;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009933; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; * Creates the file under the filename given with the KML code<br />
&nbsp; &nbsp; &nbsp; &nbsp; *<br />
&nbsp; &nbsp; &nbsp; &nbsp; * @param string &nbsp; &nbsp; filename<br />
&nbsp; &nbsp; &nbsp; &nbsp; * @access public<br />
&nbsp; &nbsp; &nbsp; &nbsp; * @return bool<br />
&nbsp; &nbsp; &nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> save<span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #009900;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$filename</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <a href="http://www.php.net/file_put_contents"><span style="color: #990000;">file_put_contents</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">create</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009933; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; * Creates the KML code from data given<br />
&nbsp; &nbsp; &nbsp; &nbsp; *<br />
&nbsp; &nbsp; &nbsp; &nbsp; * @access public<br />
&nbsp; &nbsp; &nbsp; &nbsp; * @return string<br />
&nbsp; &nbsp; &nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> create<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Set some tabs</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">function</span> pad<span style="color: #009900;">&#40;</span><span style="color: #000088;">$num</span><span style="color: #339933;">,</span> <span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <a href="http://www.php.net/str_pad"><span style="color: #990000;">str_pad</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #339933;">,</span><span style="color: #000088;">$num</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #339933;">,</span>STR_PAD_LEFT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Set the xml version and open the kml and document</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$kml</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$kml</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;kml xmlns = &quot;http://earth.google.com/kml/2.1&quot;&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$kml</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> pad<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;Document&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Set all the styles for the document</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">styles</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$s</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$kml</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> pad<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;Style id=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$s</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$kml</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> pad<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;IconStyle id=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$s</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">iconid</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$kml</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> pad<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;Icon&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$kml</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> pad<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;href&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$s</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">iconhref</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/href&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$kml</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> pad<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;/Icon&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$kml</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> pad<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;/IconStyle&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$kml</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> pad<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;/Style&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Set all the folders and places in each folder</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">folders</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$f</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$places</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'**[root]**'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Set the folder and folder name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$kml</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> pad<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;Folder&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$kml</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> pad<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&lt;name&gt;<span style="color: #006699; font-weight: bold;">$f</span>&lt;/name&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$kml</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> pad<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;open&gt;0&lt;/open&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Set all the placemarks in this folder</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$places</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$p</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$kml</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> pad<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;Placemark id=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$p</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$kml</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> pad<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;name&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$p</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/name&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$kml</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> pad<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;description&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$p</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">desc</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/description&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$kml</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> pad<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;styleUrl&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$p</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">style</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/styleUrl&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$kml</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> pad<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;Point&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$kml</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> pad<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;coordinates&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$p</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">coords</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/coordinates&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$kml</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> pad<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;/Point&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$kml</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> pad<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;/Placemark&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Close the folder</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$kml</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> pad<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;/Folder&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Set all the root placemarks so they are not in a folder</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">folders</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'**[root]**'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$p</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Set all the placemarks in the root folder</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$places</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$p</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$kml</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> pad<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;Placemark id=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$p</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$kml</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> pad<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;name&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$p</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/name&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$kml</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> pad<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;description&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$p</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">desc</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/description&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$kml</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> pad<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;styleUrl&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$p</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">style</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/styleUrl&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$kml</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> pad<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;Point&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$kml</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> pad<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;coordinates&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$p</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">coords</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/coordinates&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$kml</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> pad<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;/Point&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$kml</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> pad<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;/Placemark&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// End the document and kml</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$kml</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> pad<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;/Document&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$kml</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;/kml&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Return the string of KML data</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <a href="http://www.php.net/join"><span style="color: #990000;">join</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$kml</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009933; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; * Clears all the data to free up memory<br />
&nbsp; &nbsp; &nbsp; &nbsp; *<br />
&nbsp; &nbsp; &nbsp; &nbsp; * @access public<br />
&nbsp; &nbsp; &nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> clear<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">folders</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">styles</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.hamstar.co.nz/2009/09/22/kml-creator-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Box Office Data API</title>
		<link>http://www.hamstar.co.nz/2009/09/21/box-office-data-api/</link>
		<comments>http://www.hamstar.co.nz/2009/09/21/box-office-data-api/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 11:49:00 +0000</pubDate>
		<dc:creator>hamstar</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[bittorrent]]></category>
		<category><![CDATA[bot]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[movies]]></category>
		<category><![CDATA[mpaa]]></category>
		<category><![CDATA[p2p]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[RIAA]]></category>
		<category><![CDATA[screen-scraping]]></category>
		<category><![CDATA[spider]]></category>

		<guid isPermaLink="false">http://www.hamstar.co.nz/2009/09/21/box-office-data-api/</guid>
		<description><![CDATA[Reading about the stink the MPAA and RIAA are kicking up about the whole P2P bittorrent thing got me thinking.  I wonder if what they are saying is actually true.  Are movie makers actually being ripped off by bittorrent?
I found this website called The Numbers which has a whole lot of box office [...]]]></description>
			<content:encoded><![CDATA[<p>Reading about the stink the MPAA and RIAA are kicking up about the whole P2P bittorrent thing got me thinking.  I wonder if what they are saying is actually true.  Are movie makers actually being ripped off by bittorrent?</p>
<p>I found this website called <a href="http://the-numbers.com">The Numbers</a> which has a whole lot of box office data on it.</p>
<p>However no API.  And I wanted an API that would tell me whether to feel guilty about downloading a particular movie.</p>
<p>So I made this: <a href="http://hamstar.co.nz/api/api_thenumbers.php">Box Office Data API</a></p>
<p>You just have to enter the movie name and year (in the url bar &#8211; no form yet) and it will tell you (if the data is available) the production costs, the gross revenue, and the net profit the movie makers made.</p>
<p>Here&#8217;s an example for the movie <a href="http://hamstar.co.nz/api/api_thenumbers.php?t=district%209&#038;y=2009">District 9</a> also if you look at <a href="http://hamstar.co.nz/api/api_thenumbers.php?t=titanic&#038;y=1997">Titanic </a>they made over 1.5 billion bucks profit on that piece of shit movie!</p>
<p>The search code isn&#8217;t very smart though so it may return some dodgey results.  Still beta but still useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hamstar.co.nz/2009/09/21/box-office-data-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Software RAID type perl script</title>
		<link>http://www.hamstar.co.nz/2009/08/18/software-raid-type-perl-script/</link>
		<comments>http://www.hamstar.co.nz/2009/08/18/software-raid-type-perl-script/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 05:33:59 +0000</pubDate>
		<dc:creator>hamstar</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://www.hamstar.co.nz/?p=237</guid>
		<description><![CDATA[So I have had a problem whereby I have 1.2TB of hard drive space on my server split across 5 drives.  I am constantly going to the movies folder in this drive, then the movies folder in that drive, trying to check that I didn&#8217;t accidentally leave any pornos lying around.
So I made a [...]]]></description>
			<content:encoded><![CDATA[<p>So I <del datetime="2009-06-24T14:15:46+00:00">have</del> had a problem whereby I have 1.2TB of hard drive space on my server split across 5 drives.  I am constantly going to the movies folder in this drive, then the movies folder in that drive, trying to check that I didn&#8217;t accidentally leave any pornos lying around.</p>
<p>So I made a script to display multiple folders of the same name accross drives in their own folder under /home/shared.</p>
<p><span id="more-237"></span></p>
<p>So I made a folder called <strong>shared</strong> in my <strong>/home</strong> directory and in it created longhand names of categories like so:</p>
<pre style='font-size: 10pt;' class="code">
[hamstar@dolmayan ~]# ls -l /home/shared
total 132
-rwxrwxrwx   1 root root     6 2009-06-21 05:25 1.2TB.in.total.txt
drwxr-xr-x   2 root root 49152 2009-06-21 05:21 Albumart
drwxr-xr-x   4 root root  4096 2009-06-21 05:21 Anime
drwxr-xr-x  26 root root  4096 2009-06-25 10:07 Applications
drwxr-xr-x  14 root root  4096 2009-06-21 05:21 Audiobooks
drwxr-xr-x  11 root root  4096 2009-06-21 05:20 Cartoons
drwxr-xr-x   5 root root  4096 2009-06-21 05:21 Comedy
drwxr-xr-x  18 root root  4096 2009-06-21 05:20 Documentaries
drwxr-xr-x  11 root root  4096 2009-06-21 05:21 Games
drwxr-xr-x   8 root root  4096 2009-06-21 05:20 Guides
drwxr-xr-x  91 root root 20480 2009-06-25 09:06 Movies
drwxr-xr-x  13 root root  4096 2009-06-21 05:21 Music
drwxr-xr-x 141 root root  4096 2009-06-25 14:05 Music (Unsorted)
drwxr-xr-x   2 root root  4096 2009-06-21 05:21 Music Videos
drwxr-xr-x  42 root root  4096 2009-06-21 05:20 Pictures
drwxr-xr-x   5 root root  4096 2009-06-21 05:20 Pr0n
drwxr-xr-x  28 root root  4096 2009-06-21 05:21 TV
drwxr-xr-x  15 root root  4096 2009-06-21 05:21 Videos
</pre>
<p>Then in each drive under the /mnt/ folder I created specifically named shorthand folders for my stuff like so:</p>
<pre style='font-size: 10pt;' class="code">
[hamstar@dolmayan ~]# ls -l /mnt/sde1/
total 196
drwxrwxrwx   2 hamstar hamstar 53248 2009-06-01 14:06 albumart
drwxrwxrwx   9 hamstar hamstar  4096 2009-06-11 08:44 apps
drwxrwxrwx  12 hamstar hamstar  4096 2009-05-25 01:24 audiobooks
drwxrwxrwx   5 hamstar hamstar  4096 2009-05-22 13:29 comedy
drwxrwxrwx   5 hamstar hamstar  4096 2009-05-24 15:30 docos
drwxrwxrwx   6 hamstar hamstar  4096 2009-05-24 16:03 games
drwxrwxrwx   3 pcguest pcguest  4096 2009-05-24 15:53 guides
drwx------   2 root    root    16384 2009-05-19 07:59 lost+found
drwxrwxrwx  91 hamstar hamstar 20480 2009-06-25 08:46 movies
-rwxrwxrwx   1 hamstar hamstar  7411 2009-05-19 12:35 movies2.txt
drwxrwxrwx  13 hamstar hamstar  4096 2009-05-24 13:52 music
drwxrwxrwx 142 hamstar hamstar  4096 2009-06-01 14:29 music-unsorted
drwxrwxrwx   2 hamstar hamstar  4096 2009-05-25 15:48 music-videos
drwxrwxrwx   2 pcguest pcguest  4096 2009-06-25 14:27 Private Folder
drwxrwxrwx   3 pcguest pcguest  4096 2009-05-24 16:06 tv
drwxrwxrwx   9 hamstar hamstar  4096 2009-05-24 09:52 videos
</pre>
<p>And then I put this perl script in the <strong>/etc/cron.hourly</strong> folder and it updates the <strong>/home/shared</strong> folder with symbolic links to all the (specified) folders on all the drives.</p>
<div class="codecolorer-container perl vibrant" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="perl codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl</span><br />
<br />
<span style="color: #000000; font-weight: bold;">use</span> strict<span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">use</span> warnings<span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$command</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$base_dir</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'/home/shared/'</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@search_dirs</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'/mnt/sda3'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'/mnt/sdb1'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'/mnt/sdc1'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'/mnt/sdd1'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'/mnt/sde1'</span><br />
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">%folders</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'Music'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'music'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'TV'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'tv'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'Applications'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'apps'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'Comedy'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'comedy'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'Documentaries'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'docos'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'Games'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'games'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'Movies'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'movies'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'Music\ Videos'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'music-videos'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'Music\ \(Unsorted\)'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'music-unsorted'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'Guides'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'guides'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'Audiobooks'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'audiobooks'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'Albumart'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'albumart'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'Videos'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'videos'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'Cartoons'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'cartoons'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'Pictures'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'pics'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'Anime'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'anime'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">'Pr0n'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'pr0n'</span><br />
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$dir</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@search_dirs</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$share</span> <span style="color: #009900;">&#40;</span><a href="http://perldoc.perl.org/functions/keys.html"><span style="color: #000066;">keys</span></a> <span style="color: #0000ff;">%folders</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">$command</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;cp -Rs $dir/$folders{$share}/* $base_dir$share/ &gt; /dev/null 2&gt;&amp;1&quot;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009966; font-style: italic;">qx/$command/</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<a href="http://perldoc.perl.org/functions/chdir.html"><span style="color: #000066;">chdir</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$base_dir</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #0000ff;">$command</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;cleanlinks &gt; /dev/null 2&gt;&amp;1&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #009966; font-style: italic;">qx/$command/</span><span style="color: #339933;">;</span><br />
<br />
<a href="http://perldoc.perl.org/functions/exit.html"><span style="color: #000066;">exit</span></a> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span></div></div>
<p>It even automatically creates folders under folders so the docos from docos/Bad Government on one drive are in the same folder as the docos from docos/Bad Government on another drive.</p>
<p>Then I can share the <strong>/home/shared</strong> folder without worry of my &#8220;Private Folder&#8221; or any folder not specified in the script being seen by people browsing the network or at lans or whatever.</p>
<p>Sure its a little quick and nasty, just throws any errors straight into the bit bucket, but its works pretty sweet.</p>
<p>All thanks to cp -Rs <img src='http://www.hamstar.co.nz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>P.S. All my shares data is paid for and legit.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hamstar.co.nz/2009/08/18/software-raid-type-perl-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Batch converting Works (WPS) to Word (DOC)</title>
		<link>http://www.hamstar.co.nz/2008/09/20/batch-converting-works-wps-to-word-doc/</link>
		<comments>http://www.hamstar.co.nz/2008/09/20/batch-converting-works-wps-to-word-doc/#comments</comments>
		<pubDate>Fri, 19 Sep 2008 16:20:09 +0000</pubDate>
		<dc:creator>hamstar</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[Microsoft]]></category>

		<guid isPermaLink="false">http://www.hamstar.co.nz/?p=87</guid>
		<description><![CDATA[My friends mum needed a bunch of works files to work on her PC, but I could so not be bothered searching around for a works install disc, plus the converter from the Microsoft site wasn&#8217;t working.
So I took the documents to work where I knew the converter was working but there was still like [...]]]></description>
			<content:encoded><![CDATA[<p>My friends mum needed a bunch of works files to work on her PC, but I could so not be bothered searching around for a works install disc, plus the converter from the Microsoft site wasn&#8217;t working.</p>
<p>So I took the documents to work where I knew the converter was working but there was still like over 100 documents and I didn&#8217;t want to open and save each one.</p>
<p>Luckily I found <a href="http://www.microsoft.com/communities/newsgroups/list/en-us/default.aspx?dg=microsoft.public.word.conversions&#038;tid=92325268-5910-4ede-af4e-0b2cc5cb04bb&#038;cat=en_us_7bf8bdfb-42bd-458f-8fef-7bd182f180c8&#038;lang=en&#038;cr=us&#038;sloc=&#038;p=1">this page</a> (can&#8217;t believe I&#8217;m linking to an MS site) which had a macro to use to convert a whole bunch of WPS&#8217;s to DOC&#8217;s.</p>
<p>I&#8217;ll re-post it here incase that other page disappears (also I made an adjustment so it works):<br />
<span id="more-87"></span></p>
<pre>
[code lang="vb"]
Sub Batch_Save_WPS_as_DOC97()

    Dim bConv As Boolean
    Dim strFileName As String
    Dim strDocName As String
    Dim strPath As String
    Dim oDoc As Document
    Dim Response As Long
    Dim fDialog As FileDialog

    bConv = Options.ConfirmConversions
    Options.ConfirmConversions = False
    Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)

    With fDialog
        .Title = "Select folder and click OK"
        .AllowMultiSelect = False
        .InitialView = msoFileDialogViewList

        If .Show <> -1 Then
            MsgBox "Cancelled By User", , "Save all as DOC"
            Exit Sub
        End If

        strPath = fDialog.SelectedItems.Item(1)
        If Right(strPath, 1) <> "\" Then strPath = strPath + "\"
    End With

    'If Documents.Count > 0 Then
    'Documents.Close SaveChanges:=wdPromptToSaveChanges
    'End If

    strFileName = Dir$(strPath &#038; "*.wps")

    While Len(strFileName) <> 0
        Set oDoc = Documents.Open(strPath &#038; strFileName)

        strDocName = ActiveDocument.FullName
        intPos = InStrRev(strDocName, ".")
        strDocName = Left(strDocName, intPos - 1)
        strDocName = strDocName &#038; ".doc"
        oDoc.SaveAs FileName:=strDocName, _
        FileFormat:=wdFormatDocument97
        oDoc.Close SaveChanges:=wdDoNotSaveChanges
        strFileName = Dir$()
    Wend
    Options.ConfirmConversions = bConv

End Sub
[/code]
</pre>
<p>Don&#8217;t worry about the fact it says doc97 format it just means the format between 97 and 2003 (i.e. doc and not docx).</p>
<p>So you just:</p>
<ol>
<li>Open up a new word doc</li>
<li>Press <strong>Alt+F11</strong> to open the VB editor</li>
<li>Insert a new module</li>
<li>Copy and paste the above code</li>
<li>Save the document</li>
<li>Press <strong>Alt+F8</strong> to open the macro window</li>
<li>Select <strong>Batch_Save_WPS_as_DOC97</strong> and hit <strong>Run</strong></li>
<li>Select the folder you want and hit OK</li>
<li>Watch it do its thing</li>
</ol>
<p>It won&#8217;t overwrite any of the original documents so you don&#8217;t need to stress (I made a backup anyway just in case).</p>
<p>Hope this helps anyone in need.</p>
<p>By the way thanks to <a href="http://wordpress.org/extend/plugins/codesnippet-20/">codesnippet</a> for the syntax highlighting <img src='http://www.hamstar.co.nz/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.hamstar.co.nz/2008/09/20/batch-converting-works-wps-to-word-doc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
