Location: PHPKode > scripts > WPGet > wpget/wpgcfg.php
<?php
/*
    WPGet - retrieves WordPress posts from a database for display on a web pge
    Copyright (C) 2006-2008 Peter Upfold.

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
 	======================================================================
 	
 	For more information:
 
 	Email: hide@address.com
 	Web: http://peter.upfold.org.uk/projects/wpget
    
*/


// A graphical tool to produce a code extract automatically
// for easy, code-free WPGet integration


session_start(); // start the session tracker and initiate/load a session

define('WPGET_VERSION', '0.8');


/**************************** START OF FUNCTION DECLARATIONS ***************************/

function doHeader() { // builds a header for the page

	?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="AUTHOR" content="Peter Upfold" />
<meta http-equiv="imagetoolbar" content="no" />
<meta name="DESCRIPTION" content="WPGet Install is a graphical tool to make it ridiculously easy to install WPGet, a system for integrating WordPress content into a non-WordPress powered site. Will automatically generate the required code to copy and paste into a PHP-powered page." />
<meta name="robots" content="noindex, nofollow" /><!-- this is an installer, don't show up in search engines-->
<title>WPGet Installer</title>
<!-- inline style as we want only one file for portability -->
<style type="text/css">
body {
	background-color:#800000; font-family:Georgia,serif; font-size:0.8em; color:#ffffff
}

#container {
	background-color:#ffffff; width:80%; margin-left: auto; margin-right: auto;
	padding:10px; color:#000000
}

#footertxtsection a {
	color:#FFF51B
}

h1 {
	font-family:Georgia,serif; font-size:2.0em; font-weight:bold
}

h2 {
	font-family:Georgia,serif; font-size:1.3em; font-weight:bold
}

h3{
	font-family:Georgia,serif; font-size:1.2em; font-weight:bold
}

a {
	color:#c90000; font-weight:bold; text-decoration:none
}
a:hover {
	color:#00f; font-weight:bold; text-decoration:underline
}

.small {
	font-size:0.75em
}

table {
	border:0; padding:5px; border-spacing:10px
}

input.button {
	font-family:'Trebuchet MS',sans-serif; font-size:1.2em; font-weight:bold
}

input.downloadbutton {
	font-family:'Trebuchet MS',sans-serif; font-size:1.5em;
}

textarea {

	width:650px; height:300px

}

.errors {
	color:#ff0000
}

pre {
	font-size:1.2em; font-family:'Lucida Console',monospace
}

h1.bigheader {
	letter-spacing:5px; color:#ffffff; text-align:center
}

h1.bigheader a {
	color:#ffffff; text-decoration:none
}

#nextbutton {
	font-family:'Trebuchet MS',sans-serif;
	letter-spacing:5px; color:#ffffff; text-align:center; font-size:25pt;
	margin-top:15px
}

#nextbutton input {
	font-size:24pt; font-family:'Trebuchet MS',sans-serif;
}

#nextbutton a {
	color:#ffffff; text-decoration:underline;
}

a.miniclosebutton {

	color:#000000; font-size:1.4em

}

</style>
<script type="text/javascript">
<!--

const WPGET_VERSION = '<?php echo WPGET_VERSION;?>';

function showLayer(id) {

	document.getElementById(id).style.visibility = "visible";

}

function hideLayer(id) {

	document.getElementById(id).style.visibility = "hidden";

}

function selectDatePreset(preset) {
	
	document.getElementById("dateformat").value = preset;
	document.getElementById("popdates").style.visibility = "hidden";
	document.getElementById("selectlistbtn").disabled = false;

}

function showHideAdvancedFeatures(checkboxref, divref) {

	if (checkboxref.checked == true) {

		divref.style.display = 'block';

	}

	else {

		divref.style.display = 'none';

	}

}

function popDates(selRef) {

	var selInd = selRef.selectedIndex; // selected index
	var selOpt = selRef.options[selInd]; // selected option
	var selVal = selOpt.value; // selected option's value
	
	if (selVal == '_custom') { // if custom is selected
		
		var customDateFmt;
		
		customDateFmt = prompt('Please enter a date format (using PHP date() syntax):', ''); // get from user
		
		if (customDateFmt != null && customDateFmt.length > 0) { // make sure it's not null or 0-length
			// use this date format
			
			
			document.getElementById('dateformat').value = customDateFmt; // set hidden field to custom value
			
			// create a new option in our pop-up list for the custom value
			selRef.options[8] = new Option(customDateFmt, customDateFmt);
			
			selRef.selectedIndex = 8;
			
		}
		else {
			alert('Invalid date format.');
			selRef.selectedIndex = 0;
		}
		
	} // end if custom is selected
	
	if (selVal == '0') {
	
		selRef.selectedIndex = 0; // point them to something sensible
		document.getElementById('dateformat').value = selVal; // set hidden field to value			
		
	}
	
	else {
		
		if (selVal != '_custom')
			document.getElementById('dateformat').value = selVal;
			
		
	} // end else
	
} // end function

var ajaxObject = false;

function initialiseAjax() {

	if (window.XMLHttpRequest) { // Mozilla, Safari, and other good browsers
		ajaxObject = new XMLHttpRequest();

		if (ajaxObject.overrideMimeType) {
			ajaxObject.overrideMimeType('text/xml');
			// ^ is for older Mozilla-based browsers
		}

	} else if (window.ActiveXObject) { // IE
		try {
			// IE has two methods of calling the object, typical!
			ajaxObject = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				ajaxObject = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	if (!ajaxObject) {
		return false;
	}
	else {
		return true;
	}


} // end function

function versionCheck() {
	
	if (initialiseAjax()) {

	
		ajaxObject.onreadystatechange = versionCheck_response;
		ajaxObject.open('GET', '<?php echo $_SERVER['PHP_SELF'];?>?vcheck=true', true);	
		ajaxObject.send(null);
		
	}	
	
	else {
		
		
	}
	
	
} // end function

function versionCheck_response() {
	
	if (ajaxObject.readyState == 4) {
	
		if (ajaxObject.status == 200) {
			
			var response = ajaxObject.responseText;
			
			if (response == WPGET_VERSION) {
			
				document.getElementById('updatearea').innerHTML = 'Your version of WPGet is <strong>up-to-date</strong>.';
					
			}
			else {
				document.getElementById('updatearea').innerHTML = 'Your version of WPGet is <strong>out of date</strong>! The latest version is ' + response + ' and can be downloaded from <a href="http://peter.upfold.org.uk/projects/wpget">here</a>.';
			}
			
		}	
		
	}
	
} // end function

var catnameadd = '<input type="text" name="catname[]" value="" /><br /><br />';
var tagnameadd = '<input type="text" name="tagname[]" value="" /><br /><br />';

//-->
</script>
</head>
<body>
<h1 class="bigheader"><a href="<?php echo $_SERVER['PHP_SELF'];?>">WPGet Installer</a></h1>
<div id="container">
<?php


} // end doHeader()

function doFooter() { // builds a footer for the page

	?>
<div id="footertxtsection">
<p>Problems? Suggestions? <a href="http://peter.upfold.org.uk/contact">Get in contact</a> or visit the <a href="http://peter.upfold.org.uk/projects/wpget">WPGet project page</a>.</p>
<p class="small">Copyright &copy; 2006-2008 <a href="http://peter.upfold.org.uk/">Peter Upfold</a>. This program is free software; you can redistribute it and/or
modify it under the terms of the <a href="http://www.gnu.org/licenses/gpl-3.0.txt">GNU General Public License</a> (version 3) as published by the Free Software Foundation, or, at your option, the terms of the <a href="http://www.gnu.org/licenses/lgpl-3.0.txt">GNU Lesser General Public License</a> (version 3) as published by the Free Software Foundation. This version of the installer is brought to you with the death knell of a bygone era.</p>
</div>
</body></html>
<?php


} // end doFooter()

function printBigNextButton($type, $url = false) {

?></div><div id="nextbutton"><a name="bottom"></a>
<?php

if ($type == 'link') {
	?>
<script type="text/javascript">
document.write("<input type=\"button\" value=\"     Next &gt;&gt;     \" onclick=\"window.location.href='<?php echo $url;?>';\" />");
</script>
<noscript><a href="<?php echo $url;?>">Next &gt;&gt;</a></noscript><?php
}
else if ($type == 'button') {
	?><input type="submit" value="     Next &gt;&gt;     " /></a></form><?php

}

?></div><?php

} // end printBigNextButton()

function versionCheck() {
	
	if (ini_get('allow_url_fopen')) {
	
		$vc = fopen('http://peter.upfold.org.uk/projects/wpget/versioncheck', 'r');
		
		while (!feof($vc)) {
			$version .= fread($vc, 8192);	
		}
		
		fclose($vc);
		
		echo $version;
		
		return;
		
	}
	
	else {
	
		// try curl instead
		
		if (!function_exists('curl_init')) {
		
			return; // no curl, so we'll have to give up
		
		}

		$ch = curl_init('http://peter.upfold.org.uk/projects/wpget/versioncheck');
		
		curl_setopt($ch, CURL_HEADER, 0);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		//curl_setopt($ch, CURL_RETURNVAL, 1);
		
		$cres = curl_exec($ch);
		
		curl_close($ch);
		
		echo $cres;
		

		
	}

	
} // end versionCheck()

function showSplashPage() {

?>
<h2>Hello!</h2>
<p>Welcome to the WPGet Installer. This little program is designed to make installing <a href="http://peter.upfold.org.uk/projects/wpget">WPGet</a> as easy and painless as possible.</p>
<p>What? You don't know what <a href="http://peter.upfold.org.uk/projects/wpget">WPGet</a> is? It's a little
program written in PHP that makes it easy for you to include the latest posts from your WordPress-powered
blog on any page on your site (the whole site doesn't need to run on WordPress).</p>
<p>To get started, pick an option below.</p>
<noscript><h3>Please note that the WPGet Installer does make use of and requires JavaScript. If you don't want to, or can't enable JavaScript in your browser, you may want to configure WPGet manually instead.</h3></noscript>
<div align="center">
<p>If you're just getting started and you need to actually get WPGet downloaded and installed on your server,
choose this option.</p>
<h1><a href="<?php echo $_SERVER['PHP_SELF'];?>?step=1">I want to set up WPGet for the first time</a></h1>

<p>If you've already set up and configured WPGet, but you want another page to use it, this option is for you.</p>
<h1><a href="<?php echo $_SERVER['PHP_SELF'];?>?step=2">I want to set up a new page to include some WordPress posts</a></h1>

<div id="updatearea">Checking whether your version of WPGet is up-to-date...</div>

<script type="text/javascript">
<!--
window.setTimeout(function() {versionCheck();}, 1000);
//-->
</script>

</div>
</div>
<?php


} // end showSplashPage()

function showStep1Form($postdata = false, $errors = false) { // builds our form for generating code

?>
<h2>Let's go!</h2>
<p>First of all, we need your database details so that WPGet can retrieve the posts from the database for you. These details are the same details you use for WordPress, so if in doubt, check the <strong>wp-config.php</strong> file in your WordPress installation.</p>
<?php

if (is_array($errors) AND sizeof($errors) >= 1) { // if there are errors with the form (passed to showStep2Form)

	// show errors
	echo "<p class=\"errors\" style=\"font-weight:bold\">There was a problem generating your code:</p><ul>";
	
	foreach ($errors as $error) { // for every error, do this:

		echo "<li class=\"errors\">".$error."</li>";

	}

	echo "</ul>";


}

?>
<form name="wpcfgform1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table>
<tr><td><h3>Database details</h3></td></tr>
<tr><td>
<input type="hidden" name="formsubmit1" value="true" />
Database host:</td>
<td><input type="text" name="dbhost" value="<?php

if (isset($postdata['dbhost'])) {
	echo $postdata['dbhost'];
}

else { 
	echo 'localhost';
}

 
?>" /></td></tr>
<tr><td>
Database username:
</td><td><input type="text" name="dbuser" value="<?php

if (isset($postdata['dbuser'])) {
	echo $postdata['dbuser'];
}

else { 
	echo 'database-username';
}
 
?>" /></td>
</tr>
<tr><td>
Database password:
</td><td><input type="password" name="dbpass" value="<?php

if (isset($postdata['dbpass'])) {
	echo $postdata['dbpass'];
}

else { 
	echo 'password';
}
 
?>" /></td>
</tr>
<tr><td>
Database name (where WordPress is):
</td><td><input type="text" name="dbname" value="<?php

if (isset($postdata['dbname'])) {
	echo $postdata['dbname'];
}

else { 
	echo 'wordpress';
}
 
?>" /></td>
</tr>
<tr><td>
Table prefix (usually <strong>wp_</strong>):
</td><td><input type="text" name="dbprefix" value="<?php

if (isset($postdata['dbprefix'])) {
	echo $postdata['dbprefix'];
}

else { 
	echo 'wp_';
}
 
?>" /></td>
</tr>
<tr><td><h3>Miscellaneous options</h3></td></tr>
<tr><td colspan="2" align="center">
<input type="checkbox" name="sendemailreports" id="sendemailreports" value="true" <?php

if ($postdata['sendemailreports'] == true OR !isset($postdata['dbuser'])) {

	echo 'checked="checked"';

}

?>/>&nbsp;&nbsp;<label for="sendemailreports">Send email error reports?</label>
</td></tr>
<tr><td>
Email address to send error reports (only relevant if you've ticked the above)
</td><td><input type="text" name="email" value="<?php

if (isset($postdata['email'])) {
	echo $postdata['email'];
}

else { 
	echo 'hide@address.com';
}
 
?>" /></td>
</tr>
</table>

<!-- printBigNextButton() will close form -->


<?php

printBigNextButton('button');

} // end showStep1Form()


function showStep2Form($postdata = false, $errors = false) { // builds our form for generating code

?>
<h2>Time to set up your page</h2>
<p>Here, we're going to set the options to use on our page where we want the posts to show up (e.g. <strong>index.php</strong>). Once you've filled in this form, you'll be given a tiny snippet of code to copy and paste.</p>
<?php

if (is_array($errors) AND sizeof($errors) >= 1) { // if there are errors with the form (passed to showStep2Form)

	// show errors
	echo "<p class=\"errors\" style=\"font-weight:bold\">There was a problem generating your code:</p><ul>";
	
	foreach ($errors as $error) { // for every error, do this:

		echo "<li class=\"errors\">".$error."</li>";

	}

	echo "</ul>";


}

?>
<!--<div id="popdates" style="position:absolute; top:230px; left:520px; width:300px;background-color:#ff0000; color:#ffffff; visibility:hidden; margin:0 0; padding:5px">
<a href="javascript:;" onclick="hideLayer('popdates');document.getElementById('selectlistbtn').disabled = false;" class="miniclosebutton">&#215;</a>
<p>Pick a date format for WPGet to use:</p>
<div align="center">
<select id="popdatespopuplist">
<option value="d/m/Y \a\\t H:i">DD/MM/YYYY at hh:mm</option>
<option value="d/m/Y">DD/MM/YYYY</option>
<option value="m/d/Y \a\\t H:i">MM/DD/YYYY at hh:mm</option>
<option value="m/d/Y">MM/DD/YYYY</option>
<option value="Y-m-d">YYYY-MM-DD</option>
<option value="r">RFC 2822 format</option>
</select>
<br /><br />
&nbsp;<input type="button" value=" OK " onclick="document.getElementById('dateformat').value=document.getElementById('popdatespopuplist').options[document.getElementById('popdatespopuplist').selectedIndex].value;hideLayer('popdates');document.getElementById('selectlistbtn').disabled = false;" />
</div>-->
<!--</div>-->
<form id="wpcfgform" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<?php
if (strpos($_SERVER['REQUEST_URI'], '?') != -1) {
	?><input type="hidden" name="firstsubmit" value="true" /><?php
}
?>
<h3>Basic options</h3>
<p><em>These options set the location of wpget.php relative to your web page and your basic options.</em></p>
<table><tr><td>
<input type="hidden" name="formsubmit2" value="true" />
<label for="scriptlocation">Folder where <strong>wpget.php</strong> is (99% chance you can just leave this) without trailing slash:</label></td>
<td><input type="text" id="scriptlocation" name="scriptlocation" value="<?php

if (isset($postdata['scriptlocation'])) {
	echo $postdata['scriptlocation'];
}

else { 
	echo '.';
}

 
?>" /></td></tr>
<tr><td>
<label for="noofposts">Maximum number of posts to show:</label>
</td><td><input type="text" name="noofposts" id="noofposts" value="<?php

if (isset($postdata['noofposts'])) {
	echo $postdata['noofposts'];
}

else { 
	echo '5';
}
 
?>" /></td>
</tr>
<tr><td>
<label for="extracts">Length of post extracts in characters (put <strong>0</strong> for the whole post):</label>
</td><td><input type="text" name="extracts" id="extracts" value="<?php

if (isset($postdata['extracts'])) {
	echo $postdata['extracts'];
}

else { 
	echo '200';
}
 
?>" /></td>
</tr>

<tr><td>
<label for="popdatespopuplist">Date format:</label>
</td><td>
<select id="popdatespopuplist" onchange="javascript:popDates(this);">
<option value="d/m/Y H:i">DD/MM/YYYY hh:mm</option>
<option value="d/m/Y">DD/MM/YYYY</option>
<option value="m/d/Y H:i">MM/DD/YYYY hh:mm</option>
<option value="m/d/Y">MM/DD/YYYY</option>
<option value="Y-m-d">YYYY-MM-DD</option>
<option value="r">RFC 2822 format</option>
<option value="0">---</option>
<option value="_custom">Custom...</option>
</select>

<input type="hidden" name="dateformat" id="dateformat" value="<?php

if (isset($postdata['dateformat'])) {
	echo $postdata['dateformat'];
}

else { 
	?>d/m/Y H:i<?php
}
 
?>" />
<!--<input type="button" id="selectlistbtn" value=" Choose... " onclick="this.disabled = true;showLayer('popdates');" />--></td>
</tr>

</table>
<h3>Post content</h3>
<p><em>The following options define what extra content in your blog posts will be included in WPGet's output.</em></p>

<table>
<tr colspan="2"><td>
<input type="checkbox" name="stripimages" id="stripimages" value="true"<?php
if ($postdata['stripimages'] == 'true') {
	echo ' checked="checked"';
}?>/>
&nbsp;&nbsp;&nbsp;&nbsp;<label for="stripimages">Remove images from posts?</label>
</td>
</tr>

<tr colspan="2"><td>
<input type="checkbox" name="stripembed" id="stripembed" value="true"<?php
if ($postdata['stripembed'] == 'true') {
	echo ' checked="checked"';
}?>/>
&nbsp;&nbsp;&nbsp;&nbsp;<label for="stripembed">Remove embeds (e.g. Flash animations, videos etc.) from posts?</label>
</td>
</tr>
<tr colspan="2"><td>
<input type="checkbox" name="stripscript" id="stripscript" value="true"<?php
if ($postdata['stripscript'] == 'true' OR $_SERVER['QUERY_STRING'] == 'step=2') {
	echo ' checked="checked"';
}?>/>
&nbsp;&nbsp;&nbsp;&nbsp;<label for="stripscript">Remove JavaScript from posts? <strong>Strongly recommended</strong></label>
</td>
</tr>

<tr colspan="2"><td>
<input type="checkbox" name="showcredit" id="showcredit" value="true"<?php
if ($postdata['showcredit'] == 'true' OR $_SERVER['QUERY_STRING'] == 'step=2') {
	echo ' checked="checked"';
}
?>/>
&nbsp;&nbsp;&nbsp;&nbsp;<label for="showcredit">Show credit to me and link to my site in output? (appreciated left on, but not compulsory)</label>
</td>
</tr>
</table>
<h3>Advanced features</h3>
<p><em>Choose a feature to enable it and then choose your options for that feature.</em></p>
<input type="checkbox" id="_internal_style" name="_internal_style" onchange="showHideAdvancedFeatures(this, document.getElementById('formstyle'));" /> <label for="_internal_style">Style</label><br /><br />

<input type="checkbox" id="_internal_cat" name="_internal_cat" onchange="showHideAdvancedFeatures(this, document.getElementById('formcategories'));" /> <label for="_internal_cat">Show posts only from certain WordPress categories</label><br /><br />

<input type="checkbox" id="_internal_tag" name="_internal_tag" onchange="showHideAdvancedFeatures(this, document.getElementById('formtags'));" /> <label for="_internal_tag">Show posts only matching certain WordPress tags</label><br /><br />

<input type="checkbox" id="_internal_single" name="_internal_single" onchange="showHideAdvancedFeatures(this, document.getElementById('formsinglepost'));" /> <label for="_internal_single">Single (static) post</label><br /><br />


<div id="formstyle" style="display:none">
<h3>Style</h3>
<p>Here, you can pick a pre-defined style to automatically have your posts
appear with a nice style. If you want to do the styling yourself (and you're
a CSS wizard), just leave this as Custom/None.</p>
<p>Sorry, there still aren't any predefined styles. If you'd like to <a href="http://peter.upfold.org.uk/contact">donate one</a>...</p>
Choose a style:&nbsp;&nbsp;&nbsp;&nbsp;
<select name="style">
<option value="none">Custom/None</option>
</select>
</div>

<div id="formcategories" style="display:none">
<h3>WordPress Categories</h3>
<p>If you want WPGet only to get posts from a few categories and not show all posts, then enter the slugs of those categories below. If you need more categories then there are boxes, click the Add another category button before you get started.</p>
<p>The category slugs can be found in <strong>Manage</strong> &gt; <strong>Categories</strong> in your WordPress Dashboard.</p>
<p style="font-size:0.75em">This feature requires WordPress 2.3.x or higher and <strong>cannot be used at the same time</strong> as WPGet's WordPress Tags.</p>
<input type="button" value=" Add another category " onclick="document.getElementById('catlist').innerHTML += catnameadd;" /><br /><br />
<div id="catlist">
<input type="text" name="catname[]" value="" /><br /><br />
<input type="text" name="catname[]" value="" /><br /><br />
<input type="text" name="catname[]" value="" /><br /><br />
<input type="text" name="catname[]" value="" /><br /><br />
<input type="text" name="catname[]" value="" /><br /><br />
<input type="text" name="catname[]" value="" /><br /><br />
</div>
</div>

<div id="formtags" style="display:none">
<h3>WordPress Tags</h3>
<p>If you want WPGet only to get posts that match certain tags and not show all posts, then enter the slugs of those tags below. If you need more tags then there are boxes, click the Add another tag button before you get started.</p>
<p>The tag slugs can be found in <strong>Manage</strong> &gt; <strong>Tags</strong> in your WordPress Dashboard.</p>
<p style="font-size:0.75em">This feature requires WordPress 2.3.x or higher and <strong>cannot be used at the same time</strong> as WPGet's WordPress Categories.</p>
<input type="button" value=" Add another tag " onclick="document.getElementById('taglist').innerHTML += tagnameadd;" /><br /><br />
<div id="catlist">
<input type="text" name="tagname[]" value="" /><br /><br />
<input type="text" name="tagname[]" value="" /><br /><br />
<input type="text" name="tagname[]" value="" /><br /><br />
<input type="text" name="tagname[]" value="" /><br /><br />
<input type="text" name="tagname[]" value="" /><br /><br />
<input type="text" name="tagname[]" value="" /><br /><br />
</div>
</div>

<div id="formsinglepost" style="display:none">
<h3>Single (static) Post</h3>
<p>If you only want WPGet to get one single static post, enter the ID of that post here (you can find the ID by looking under the Manage tab on the WordPress Dashboard).</p>
&nbsp;&nbsp;Post ID:&nbsp;&nbsp;<input type="text" name="singlepost" value="" /><br />
</div>


<!-- printBigNextButton will close form -->
<br /><br />


<?php

printBigNextButton('button');

} // end showStep2Form()

function generateStep1Code($dbhost, $dbuser, $dbpass, $dbname, $dbprefix, $email) { // generate and display code



?>
<h2>It's ready!</h2>

<p>Please click the button below to download a fully ready-to-run personalised copy of WPGet. All you need to do is upload it to your web server, and then run Step 2.</p>
<form name="generatedownloadablefile" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>?show=download">
<input type="hidden" name="configcode" value="<?php echo makeConfigCode($dbhost, $dbuser, $dbpass, $dbname, $dbprefix, $email, false); ?>" />
<input type="submit" class="downloadbutton" value=" Download Ready-to-Run Script" />
</form>
<p>Once you've got the file, open up your file transfer program and copy this file onto your web server.</p>
<p><strong>Please note:</strong> it makes it a lot easier to put the <strong>wpget.php</strong> file in the same folder
as the file that will be using it (for example, <strong>index.php</strong>). If you don't do this,
please remember the folder you put it in, as you'll need this information for the next step.</p>
<p>The next step we're going to do is make a little snippet of code you'll paste into the file where you want the posts to appear.</p>
<h2>Done? Good! Click Next below.</h2>
<?php

	printBigNextButton('link', $_SERVER['PHP_SELF'].'?step=2');

} // end generateStep1Code()

function generateStep2Code($scriptlocation, $noofposts, $extracts, $dateformat, $stripimages, $stripembed, $stripscript, $showcredit, $usestyle, $catname, $tagname, $singlepost) { // generate and display code
?>
<h3>Your code is ready!</h3><p>Simply copy and paste this code into the page where you want
the WordPress content to show up. It's really that easy!</p>
<p>Don't forget to reupload your file when you're finished
pasting to enjoy your new WordPress content.</p>

<?php
	echo "<textarea onclick=\"select();\"><"."?"."php\ninclude_once(\"".$scriptlocation."/wpget.php\");\n\$wpget = new wpGet;\n\$wpget->dateformat = \"".$dateformat."\";\n\$wpget->showcredit = ".$showcredit.";";

	if (!empty($usestyle) AND $usestyle != 'none') {

		echo "\n\$wpget->usestyle = '{$usestyle}';";

	}

	if (is_array($catname) AND count($catname) > 0) {

		foreach($catname as $no => $category) {
			if (!empty($category))
				echo "\n\$wpget->categoriestoreturn[{$no}] = \"{$category}\";";
		}

	}

	if (is_array($tagname) AND count ($tagname) > 0) {

		foreach($tagname as $no => $tag) {

			if (!empty($tag))
				echo "\n\$wpget->tagstoreturn[{$no}] = \"{$tag}\";";

		}


	}

	if (empty($singlepost)) {

		// final implementation line
		echo "\n\$wpget->getWordpressEntries(".$noofposts.", ".$extracts.", ".$stripimages.", ".$stripembed.", ".$stripscript.");\n"."?"."></textarea>";

	}

	else {

		// single post
		echo "\n\$wpget->getSinglePost({$singlepost}, {$extracts}, {$stripimages}, {$stripembed}, {$stripscript});\n"."?"."></textarea>";

	}

?>

<h3>All done!</h3>
<p>If you've got more than one page where you want your WordPress stuff to show up, <a href="<?php echo $_SERVER['PHP_SELF'];?>?step=2">click here</a> to do this process again.</p>
</div>

<?php

} // end generateStep2Code()

function makeConfigCode($dbhost, $dbuser, $dbpass, $dbname, $dbprefix, $email, $fortextarea = true) {

	// let's strip out any extraneous double-quotes to prevent PHP choking on them
	$dbhost = str_replace('"', "\\\"", $dbhost);
	$dbuser = str_replace('"', "\\\"", $dbuser);
	$dbpass = str_replace('"', "\\\"", $dbpass);
	$dbname = str_replace('"', "\\\"", $dbname);
	$dbprefix = str_replace('"', "\\\"", $dbprefix);
	$email = str_replace('"', "\\\"", $email);


	$config = "<textarea>/***** CONFIGURATION ****/
var \$mysqluser = \"".$dbuser."\"; // your MySQL username for Wordpress
var \$mysqlpass = \"".$dbpass."\"; // your MySQL password for Wordpress
var \$mysqlhost = \"".$dbhost."\"; // your MySQL host
var \$mysqldb = \"".$dbname."\"; // your MySQL database name for Wordpress
var \$mysqlprefix=\"".$dbprefix."\"; // Wordpress table prefix - always include underscore at end if applicable
";

if ($email == 'false') { // if it's false, remove quotes
	$config .= "var \$errorsto = false; // send error emails to whom?";
}
else {
	$config .= "var \$errorsto = \"".$email."\"; // send error emails to whom?";
}


$config .= "
// set the above to false if you don't want email error notifications

var \$debugmode = false; // set to false when working on a real server so potential nasty people don't see MySQL errors

var \$conn = false; // don't touch!

/********** FINISHED *********/</textarea>";

	if ($fortextarea) { // if this is for the textarea

		return $config; // send it back as it is

	}

	else { // otherwise, strip the textarea boxes, put it through html entities and return
		$config = str_replace("<textarea>", "", $config);
		$config = str_replace("</textarea>", "", $config);
		$config = htmlentities($config);
		return $config;

	}

}


function validateStep1Form($postdata) { // validates form, send $_POST as $postdata

	$errors = array();
	$n = 0;

	if (!isset($postdata['dbhost']) or empty($postdata['dbhost'])) {

		$errors[$n] = "You did not enter anything for the database host.";
		$n++;

	}


	if (!isset($postdata['dbuser']) or empty($postdata['dbuser'])) {

		$errors[$n] = "You did not enter anything for the database username.";
		$n++;

	}

	if (!isset($postdata['dbpass']) or empty($postdata['dbpass'])) {

		if (!$exoverr) {

			$errors[$n] = "You did not enter anything for the database password.";
			$n++;

		}


	}

	if (!isset($postdata['dbname']) or empty($postdata['dbname'])) {

		if (!$exoverr) {

			$errors[$n] = "You did not enter anything for the database name.";
			$n++;

		}


	}

	// remember it's perfectly fine to have no prefix

	if (isset($postdata['sendemailreports']) AND (!isset($postdata['email']) OR empty($postdata['email'])) ) {

		if (!$exoverr) {

			$errors[$n] = "You did not enter anything for the email address. Remember type <strong>false</strong> in the box if you don't want to receive email error reports.";
			$n++;

		}


	} 



	if ($n > 0) { // if there were one or more errors

		showStep1Form($postdata, $errors); // show the form passing in the error array
		return false; // return false for validation

	}

	else { // otherwise all is well!

		if (!isset($postdata['sendemailreports'])) {
			$postdata['email'] = 'false';
		}

		generateStep1Code($postdata['dbhost'], $postdata['dbuser'], $postdata['dbpass'], $postdata['dbname'], $postdata['dbprefix'], $postdata['email']);
		return true; 
		

	} 


} // end validateStep1Form()


function validateStep2Form($postdata) { // validates form, send $_POST as $postdata



	$errors = array();
	$n = 0;

	if (!isset($postdata['scriptlocation']) or empty($postdata['scriptlocation'])) {

		$errors[$n] = "You did not enter anything for the location of <strong>wpget.php</strong>.";
		$n++;

	}

	// argh - ok we need to override the detection if extracts is zero
	// (since zero is a valid value for this, but empty() sees zero and returns true
	// we have to manually override the validation below)
	if ($postdata['extracts'] == '0') {

		$exoverr = true;

	}

	// set no of posts to an integer, will drop any string stuff automagically, no validation then required
	settype($postdata['noofposts'], int);

	// same deal with extract char count
	settype($postdata['extracts'], int);

	// the conversion to integer strips out any string stuff
	// if the result is empty, we display these messages

	if (!isset($postdata['noofposts']) or empty($postdata['noofposts'])) {

		$errors[$n] = "You did not enter anything for the number of posts to display (or you didn't enter a whole number).";
		$n++;

	}

	if (!isset($postdata['extracts']) or empty($postdata['extracts'])) {

		if (!$exoverr) {

			$errors[$n] = "You did not enter anything for the extract length in characters (or you didn't enter a whole number).";
			$n++;

		}


	}

	if (!isset($postdata['dateformat']) or empty($postdata['dateformat'])) {

		if (!$exoverr) {

			$errors[$n] = "You did not enter anything for the date format.";
			$n++;

		}


	}

	if (!isset($postdata['stripimages'])) {

		$postdata['stripimages'] = 'false';

	}

	if (!isset($postdata['stripembed'])) {

		$postdata['stripembed'] = 'false';

	}

	if (!isset($postdata['stripscript'])) {

		$postdata['stripscript'] = 'false';

	}

	if (!isset($postdata['showcredit'])) {

		$postdata['showcredit'] = 'false';

	}

	// categories and tags cannot be used at the same time, so check that they are not being used as such
	// we have to loop through grr

	$catused = false;
	$tagused = false;


	if (is_array($postdata['catname']) AND count($postdata['catname']) > 0) {
		foreach($postdata['catname'] as $key => $cat) {
			if (!empty($cat))
				$catused = true;
		}
	}
	else
		$catused = false;

	if (is_array($postdata['tagname']) AND count($postdata['tagname']) > 0) {

		foreach($postdata['tagname'] as $key => $tag) {

			if (!empty($tag))
				$tagused = true;

		}
	}
	else
		$tagused = false;
	
	if ($tagused AND $catused) {
		
		$errors[$n] = "Support for pulling posts from selected categories and selected tags cannot be used at the same time. Please choose either categories, or tags.";
		$n++;


	}


	
	if ($n > 0) { // if there were one or more errors

		showStep2Form($postdata, $errors); // show the form passing in the error array
		return false; // return false for validation

	}

	else { // otherwise all is well!

		//$scriptlocation, $noofposts, $extracts, $dateformat, $stripimages, $stripembed, $stripscript, $showcredit, $usestyle, $catname, $singlepost

		generateStep2Code($postdata['scriptlocation'], $postdata['noofposts'], $postdata['extracts'], $postdata['dateformat'], $postdata['stripimages'], $postdata['stripembed'], $postdata['stripscript'], $postdata['showcredit'], $postdata['style'], $postdata['catname'], $postdata['tagname'], $postdata['singlepost']);
		return true; 
		

	} 


} // end validateStep2Form()

function windowsInformation() {


	?>
<h2>Attention Windows users</h2>
<p>If you are not using a special code editing program and are using Windows' built-in tools like Notepad,
you may encounter problems when copy and pasting the code (specifically for step 1).</p>

<p>The problem is Windows cannot understand the <strong>wpget.php</strong> file properly, as it uses a different way of signifying a new line than Windows does (Unix line breaks for the geeks reading this). This means opening <strong>wpget.php</strong> in Notepad will cause strange symbols to appear where new lines should be and it will be very difficult to paste the code in from Step 1.</p>
<p>Instead of using Windows Notepad, I recommend using a dedicated code editor which supports the Unix format. I've included a list of a few (Free and free) programs which support this format.</p>
<ul>
<li><a href="http://aptana.com/">Aptana</a></li>
<li><a href="http://syn.sourceforge.net/">Syn Programming Editor</a></li>
<li><a href="http://www.mpsoftware.dk/phpdesigner.php" rel="nofollow">PHP Designer 2007 Personal Edition</a></li>
<!-- non-Free products don't get no link juice -->
<li><a href="http://notepad-plus.sourceforge.net/">Notepad++</a></li>
</ul>

<h2><a href="<?php echo $_SERVER['PHP_SELF'];?>">Head back to Step 1</a></h2>

	<?php


} // end windowsInformation()

function generateDownloadableFile($configsection) {

	/* 	basically I have to include the whole source code of wpget.php here
		to generate the script (avoiding having a dependency on an external file).
		I don't escape it manually, I have a simple script that does that for me
		(if you desparately want the script, it's not /that/ exciting, email me).
	*/

	$wpgetsrc = "<"."?"."php
/*
    WPGet - retrieves WordPress posts from a database for display on a web pge
    Copyright (C) 2006-2008 Peter Upfold.

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
 	======================================================================
 	
 	For more information:
 
 	Email: hide@address.com
 	Web: http://peter.upfold.org.uk/projects/wpget

	VERSION: 0.8
    
*/

class wpGet {

// config


";

$wpgetsrc .= $configsection;


$wpgetsrc .= "
/****** PUBLIC VARIABLES (CAN BE CHANGED AT RUNTIME) *******/

var \$dateformat = \"d/m/Y H:i\";
// date format for post date/time (the default above prints something like \"17/10/2006 at 21:34\" for October 17th)

// see http://www.php.net/date for details on the format

var \$showcredit = true; // boolean
// controls whether the credit and link back to my site is shown (appreciated if you leave it on, but not compulsory)

var \$categoriestoreturn = false; 
// to return posts only from a particular category, turn this var
// into an array of the category names

// for example:
// var \$categoriestoreturn = array();
// \$categoriestoreturn[0] = \"Category Name\"  

var \$tagstoreturn = false;
// return posts only from certain tags. Works just like categoriestoreturn.
//Only use either categories or tags or neither, they do not work both at the same time currently.

var \$showauthor = true;
// show post author in WPGet's output


var \$enablecommentajax = false;
// enable Ajax comment system - off by default

var \$absoluteurldir = \".\";
// if your wpget.php file is in a different directory
// to the file that will call it, specify the full web-accessible
// path (relative to the document root) of wpget.php

var \$usestyle = false;
// use specified style for WPGet's output (or false for no style/custom)


/***** INTERNAL VARIABLES ONLY, DON'T CHANGE THEM (CALLING THEM PRIVATE IS PHP5-SPECIFIC THOUGH) *****/

var \$categorylist = array();

var \$catsearch = array();

var \$taglist = array();

var \$tagsearch = array();

var \$qcount = 0;


/****** START OF CLASS FUNCTION DECLARATIONS *******/



// this function isn't mine - courtesy of mr at bbp dot biz (found at http://uk2.php.net/manual/en/function.substr.php#59719)

function html_substr(\$posttext, \$minimum_length = 200, \$length_offset = 20, \$cut_words = FALSE, \$dots = TRUE) {
  
   // \$minimum_length:
   // The approximate length you want the concatenated text to be 
 

   // \$length_offset:
   // The variation in how long the text can be in this example text
   // length will be between 200 and 200-20=180 characters and the
   // character where the last tag ends

   // Reset tag counter & quote checker
   \$tag_counter = 0;
   \$quotes_on = FALSE;
   // Check if the text is too long
   if (strlen(\$posttext) > \$minimum_length) {
       // Reset the tag_counter and pass through (part of) the entire text
       \$c = 0;
       for (\$i = 0; \$i < strlen(\$posttext); \$i++) {
           // Load the current character and the next one
           // if the string has not arrived at the last character
           \$current_char = substr(\$posttext,\$i,1);
           if (\$i < strlen(\$posttext) - 1) {
               \$next_char = substr(\$posttext,\$i + 1,1);
           }
           else {
               \$next_char = \"\";
           }
           // First check if quotes are on
           if (!\$quotes_on) {
               // Check if it's a tag
               // On a \"<\" add 3 if it's an opening tag (like <a href...)
               // or add only 1 if it's an ending tag (like </a>)
               if (\$current_char == '<') {
                   if (\$next_char == '/') {
                       \$tag_counter += 1;
                   }
                   else {
                       \$tag_counter += 3;
                   }
               }
               // Slash signifies an ending (like </a> or ... />)
               // substract 2
               if (\$current_char == '/' && \$tag_counter <> 0) \$tag_counter -= 2;
               // On a \">\" substract 1
               if (\$current_char == '>') \$tag_counter -= 1;
               // If quotes are encountered, start ignoring the tags
               // (for directory slashes)
               if (\$current_char == '\"') \$quotes_on = TRUE;
           }
           else {
               // IF quotes are encountered again, turn it back off
               if (\$current_char == '\"') \$quotes_on = FALSE;
           }
          
           // Count only the chars outside html tags
           if(\$tag_counter == 2 || \$tag_counter == 0){
               \$c++;
           }         
                          
           // Check if the counter has reached the minimum length yet,
           // then wait for the tag_counter to become 0, and chop the string there
           if (\$c > \$minimum_length - \$length_offset && \$tag_counter == 0 && (\$next_char == ' ' || \$cut_words == TRUE)) {
               \$posttext = substr(\$posttext,0,\$i + 1);             
               if(\$dots){
                   \$posttext .= '...';
               }
               return \$posttext;
           }
       }
   } 
   return \$posttext;
}




function connectToDB() {

	// connects to the database and selects the right db ready for action
	\$this->conn = mysql_connect(\$this->mysqlhost, \$this->mysqluser, \$this->mysqlpass) or die(\$this->friendlyError(mysql_error(), \"{Connect}\"));

	mysql_select_db(\$this->mysqldb) or die (\$this->friendlyError(mysql_error(), \"{Select DB}\"));

} // end connectToDB()

function friendlyError(\$error, \$query, \$line = false, \$file = false) {
	// gives a friendly error should anything go wrong
	echo \"<h1>We've had a problem</h1><p>Sorry, but we've experienced a bit of a problem loading this section of the page.</p>\"; // TODO: make this message better!
	

	if (\$this->debugmode) {

		echo \"<p>MySQL said: <b>\".\$error.\"</b>.</p><p>It was running the following query: <b>\".\$query.\"</b>.</p><p>The query was called on line <b>\".\$line.\"</b> by file <b>\".\$file.\"</b>.\";

	}

	// mail you telling you error details
	else if (\$this->errorsto != false) {

			\$mail = \"Hey there,<br /><br />There was a database problem with the WPGet script on your site running on <b>\".\$_SERVER['HTTP_HOST'].\"</b>.<br /><br />
			A user tried to view the page <b>\".\$_SERVER['REQUEST_URI'].\"</b> <i>(\".\$_SERVER['SCRIPT_FILENAME'].\")</i>. Something went wrong with the database.
			<br /><br />MySQL said:<b> \".\$error.\"</b><br /><br />Query:<b> \".\$query.\"</b>. Called on line <b>\".\$line.\"</b> by file <b>\".\$file.\"</b>.<br /><br />Have a nice day!\";

		 	if (error_log(\$mail, 1, \$errorsto, \"From: wpget@\".\$_SERVER['SERVER_NAME'].\"\nContent-type: text/html\n\")) {
				echo '<p>The site administrator has been notified of this error and should fix it soon.</p>';
			}
			else {
				echo '<p>There was a problem automatically notifying the site administrator. Please contact the person who manages this site and tell them there is a problem with WPGet.</p>';
			}

	}



}// end friendlyError()

function query(\$sql, \$line, \$file) {

	// wrapper function for all SQL queries (new as of 0.7), including new error handling
	// and supression of PHP's errors

	if (!\$conn) {

		\$this->connectToDB();

	}

	\$result = @mysql_query(\$sql, \$this->conn) or die (\$this->friendlyError(mysql_error(), \$sql, \$line, \$file));
	
	\$this->qcount++;

	return \$result;

} // end query()

function crash() {
	
	// crash function

	\$this->query(\"hfduhf\", __LINE__, __FILE__);

} // end crash()

function convert_smart_quotes(\$string) // not mine either - thanks to Chris Shiflett at http://shiflett.org/archive/165
{ 
    \$search = array(chr(145), 
                    chr(146), 
                    chr(147), 
                    chr(148), 
                    chr(151)); 
 
   \$replace = array('‘', 
                 '’', 
                 '“', 
                 '”', 
                 '—'); 
 
 
    return str_replace(\$search, \$replace, \$string); 
} 

function formatWPContent(\$wpdata, \$chars, \$stripimages, \$stripembed, \$stripscript) { 

	if (\$chars > 0) {
		\$content = stripslashes(\$this->html_substr(\$wpdata['post_content'], \$chars, 20));
		\$content = \$this->convert_smart_quotes(\$content);
	}
	else {
		\$content = \$wpdata['post_content'];
		\$content = \$this->convert_smart_quotes(\$content);
	}

	// strip images from posts
	if (\$stripimages) {
		\$content = ereg_replace(\"<img.*/>\", \"<!--strip-->\", \$content);
	}

	if (\$stripembed) {
		// strip embeds from posts
		\$content = ereg_replace(\"<embed.*</embed>\", \"<!--strip-->\", \$content);
	}

	if (\$stripscript) {
		// strip javascript from posts
		\$content = ereg_replace(\"<script.*</script>\", \"<!--strip-->\", \$content);
	}

	?><div class=\"__wpget_singleentry\"><?php

	echo '<h2><a href=\"'.\$wpdata['guid'].'\">'.\$wpdata['post_title'].'</a></h2>'.nl2br(\$content).'<br /><br /><p>Posted on '.date(\$this->dateformat, strtotime(\$wpdata['post_date']));

	if (\$this->showauthor)

		echo ' by '.\$wpdata['display_name']; // print author name
	
	echo '.<br />'.\$wpdata['comment_count'];


	if (\$wpdata['comment_count'] > 0) {
		\$jump = \"#comments\";
	}
	else {
		\$jump = \"#respond\";
	}
	if (\$wpdata['comment_count'] == 1) {
		\$comment = \"comment\";
	}
	else {
		\$comment = \"comments\";
	}

	if (\$this->enablecommentajax) {

		echo ' <a href=\"'.\$wpdata['guid'].\$jump.'\" onclick=\"return __wpget_getListOfComments('.\$wpdata['post_ID'].', \'__wpget_commentdiv_'.\$wpdata['post_ID'].'\');\">'.\$comment.'</a>.</p>';

		// create the comment div
		?><div id=\"__wpget_commentdiv_<?php echo \$wpdata['post_ID'];?>\" class=\"__wpget_commentdiv_global\"></div><?php

	}

	else {

		echo ' <a href=\"'.\$wpdata['guid'].\$jump.'\">'.\$comment.'</a>.</p>';

	}

	?></div><?php

} // end formatWPContent()

function populateCategoryList() {

	// now only compatible with 2.3/2.5.x series or higher.
	// Support for < 2.2 is now dropped.

	// this function populates an array of the available categories
	// and their associated IDs so we can pull only relevant posts

	\$this->connectToDB();

	\$sql = \"SELECT wpg_taxon.`term_taxonomy_id`, `name`, `slug`
	FROM `\".\$this->mysqlprefix.\"terms` AS wpg_terms
	INNER JOIN `\".\$this->mysqlprefix.\"term_taxonomy` AS wpg_taxon ON wpg_terms.`term_id` = wpg_taxon.`term_id`
	WHERE wpg_taxon.`taxonomy` = 'category';\";
	\$q = \$this->query(\$sql, __LINE__, __FILE__);

	

	while (\$ar = mysql_fetch_array(\$q, MYSQL_ASSOC)) {

		\$this->categorylist[\$ar['term_taxonomy_id']] = \$ar['slug'];
		

	} // end while

	
	// now we want to create an array of the category IDs we are looking for

	/* so iterate through all the categories we've been given and 
	   match them to the numeric category IDs in the category list we
	   just created */

	\$i = 0;
	// an array counter for us

	foreach (\$this->categoriestoreturn as \$cat) {

		\$srch = array_search(\$cat, \$this->categorylist);

		if (\$srch === false) { // treble equals to check if it is bool false and not just zero

			// category not found, throw an error and halt execution
			die(\"The category \".\$cat.\" was not found, WPGet cannot get the posts!\");

		}

		else {

			\$this->catsearch[\$i] = \$srch;
			// set the list of categories to search to the ID of the current category
	
			\$i++;
			// increment the counter

		}

	} // end foreach

	

} // end populateCategoryList()

function populateTagList() {

	// pull posts from a set of tags

	//  only compatible with 2.3/2.5.x series or higher.

	\$this->connectToDB();

	\$sql = \"SELECT wpg_taxon.`term_taxonomy_id`, `name`, `slug`
	FROM `\".\$this->mysqlprefix.\"terms` AS wpg_terms
	INNER JOIN `\".\$this->mysqlprefix.\"term_taxonomy` AS wpg_taxon ON wpg_terms.`term_id` = wpg_taxon.`term_id`
	WHERE wpg_taxon.`taxonomy` = 'post_tag';\";
	\$q = \$this->query(\$sql, __LINE__, __FILE__);

	

	while (\$ar = mysql_fetch_array(\$q, MYSQL_ASSOC)) {

		\$this->taglist[\$ar['term_taxonomy_id']] = \$ar['slug'];
		

	} // end while

	
	// now we want to create an array of the category IDs we are looking for

	/* so iterate through all the tags we've been given and 
	   match them to the numeric tags IDs in the tag list we
	   just created */

	\$i = 0;
	// an array counter for us

	foreach (\$this->tagstoreturn as \$tag) {

		\$srch = array_search(\$tag, \$this->taglist);

		if (\$srch === false) { // treble equals to check if it is bool false and not just zero

			// tag not found, throw an error and halt execution
			die(\"The tag \".\$tag.\" was not found, WPGet cannot get the posts!\");

		}

		else {

			\$this->tagsearch[\$i] = \$srch;
			// set the list of tags to search to the ID of the current tag
	
			\$i++;
			// increment the counter

		}

	} // end foreach



} // end populateTagList()

function getWordpressEntries(\$number = 5, \$chars = 300, \$stripimages = true, \$stripembed = true, \$stripscript = true) {

	
	if (is_array(\$this->categoriestoreturn)) { // if we have selective categories on

		// we do it a completely different way

		// so populate the list
		\$this->populateCategoryList();

		// then launch the alternative way to do it
		\$this->getCatWPEntries(\$this->catsearch, \$number, \$chars, \$stripimages, \$stripembed, \$stripscript);

		// and quit out of this function
		return;

	} // end if

	else if (is_array(\$this->tagstoreturn)) { // selected tags are on

		// populate tags
		\$this->populateTagList();

		// launch category pull, passing in the tags
		\$this->getCatWPEntries(\$this->tagsearch, \$number, \$chars, \$stripimages, \$stripembed, \$stripscript);

		return;

	}

	// if we have a style
	if (\$this->usestyle != false) {

		\$this->printStyleCSS(\$this->usestyle);

	}

	// gets \$number of wordpress entries and prints in a friendly format
	\$this->connectToDB();

	\$sql = \"SELECT *
	FROM `\".\$this->mysqlprefix.\"posts` as posts INNER JOIN `\".\$this->mysqlprefix.\"users` as users ON users.ID = posts.post_author
	WHERE posts.`post_status` = 'publish' AND posts.`post_type` = 'post'
	ORDER BY `post_date` DESC LIMIT {\$number};\";

	\$q = \$this->query(\$sql, __LINE__, __FILE__);

	?><div id=\"__wpget_entries\"><?php

	while (\$ar = mysql_fetch_array(\$q)) {
		\$ar['post_ID'] = \$ar[0]; // first row returned is posts.ID

		\$this->formatWPContent(\$ar, \$chars, \$stripimages, \$stripembed, \$stripscript);
		
	}

	// Credit to me can be disabled, see top for details

	if (\$this->showcredit) {
		echo '<p style=\"font-size:0.8em\">WordPress integration powered by <a href=\"http://peter.upfold.org.uk/projects/wpget\">WPGet</a> by Peter Upfold.</p>';
	}

	if (\$this->enablecommentajax) {

		\$this->printAjaxCommentJavaScript(); // write JavaScript required

	}

	?></div><?php


} // end getWordpressEntries()

function getSinglePost(\$postid, \$chars = 0, \$stripimages = true, \$stripembed = true, \$stripscript = true) {

	if (\$this->enablecommentajax) {

		\$this->printAjaxCommentJavaScript(); // write JavaScript required

	}

	// gets the specified post ID
	\$this->connectToDB();

	settype(\$postid, int);
	\$postid = addslashes(\$postid);

	\$sql = \"SELECT *, posts.`ID` as `post_ID`
	FROM `\".\$this->mysqlprefix.\"posts` as posts INNER JOIN `\".\$this->mysqlprefix.\"users` as users ON users.ID = posts.post_author WHERE posts.`post_status` = 'publish' AND posts.`ID` = {\$postid} AND users.`ID` = posts.`post_author`
	ORDER BY `post_date` DESC LIMIT 1;\";

	\$q = \$this->query(\$sql, __LINE__, __FILE__);

	\$ar = mysql_fetch_assoc(\$q);

	?><div id=\"__wpget_entries\"><?php

	\$this->formatWPContent(\$ar, \$chars, \$stripimages, \$stripembed, \$stripscript);
		

	// Credit to me can be disabled, see top for details

	if (\$this->showcredit) {
		echo '<p style=\"font-size:0.8em\">WordPress integration powered by <a href=\"http://peter.upfold.org.uk/projects/wpget\">WPGet</a> by Peter Upfold.</p>';
	}

	?></div><?php


} // end getSinglePost


function getCatWPEntries(\$categories, \$number = 5, \$chars = 300, \$stripimages = true, \$stripembed = true, \$stripscript = true) {

	\$i = 0; // counter

	\$catclause = \"WHERE p2c.`term_taxonomy_id` IN (\";

	\$catclause .= implode(',', \$categories); 
	// implode our array of categories into a comma-delimited list for MySQL's 'IN'

	\$catclause .= ')';

	\$sql = \"SELECT * FROM
		`{\$this->mysqlprefix}posts` AS posts INNER JOIN
		`{\$this->mysqlprefix}term_relationships` AS p2c ON posts.`ID` = p2c.`object_id` INNER JOIN
		`{\$this->mysqlprefix}users` AS users ON users.`ID` = posts.`post_author`
		{\$catclause}
		ORDER BY p2c.`object_id` DESC
		LIMIT {\$number};\";

	\$q = \$this->query(\$sql, __LINE__, __FILE__);

	// duplicate prevention
	\$shownPosts = array();
	\$spc = 0;

	
	while (\$ar = mysql_fetch_array(\$q)) {

		\$ar['post_ID'] = \$ar['object_id']; // for formatWPContent()

		if (!in_array(\$ar['object_id'], \$shownPosts)) {

			\$shownPosts[\$spc] = \$ar['object_id'];
			\$spc++;
			
			\$this->formatWPContent(\$ar, \$chars, \$stripimages, \$stripembed, \$stripscript);

		}
	
	} // end while

	// Credit to me can be disabled, see top for details

	if (\$this->showcredit) {
		echo '<p style=\"font-size:0.8em\">WordPress integration powered by <a href=\"http://peter.upfold.org.uk/projects/wpget\">WPGet</a> by Peter Upfold.</p>';
	}


	if (\$this->enablecommentajax) {

		\$this->printAjaxCommentJavaScript(); // write JavaScript required

	}

} // end getSingleCatWPEntries()


} // end class

"."?".">";

	header("Cache-Control: no-cache");
	header("Pragma: no-cache"); // prevent IE choking on cache stuff
	header("Content-type: text/plain; charset=utf-8"); 
	header("Content-Disposition: attachment; filename=\"wpget.php\""); // make the browser throw a download box


	if (get_magic_quotes_runtime()) { // i hate Magic Quotes

		//$wpgetsrc =str_replace('$', '\$', $wpgetsrc);

	}

	echo $wpgetsrc; // content of the page is the source code


	die(); // and quit execution to prevent any other stuff happening (e.g. executing any more if statements
	       // once we jump out of this function)


}





/**************************** END OF FUNCTION DECLARATIONS, MAIN PROCESSING BODY START ***************************/


if ($_GET['vcheck'] == 'true') {

	versionCheck();
	die();	
	
}

if ($_GET['show'] == "download") {

	if (get_magic_quotes_runtime() OR get_magic_quotes_gpc()) { // if magic quotes is on

		$_POST['configcode'] = stripslashes($_POST['configcode']); // then strip the slashes to prevent it breaking
	}
	// END FIX

	generateDownloadableFile($_POST['configcode']);

}

doHeader();


if ($_GET['show'] == "wininfo") {

	windowsInformation();
	doFooter();
	die();

}


if (isset($_POST['formsubmit1']) AND !empty($_POST['formsubmit1'])) { // if step 1 form has been submitted1

	
	validateStep1Form($_POST);
	

}


if (isset($_POST['formsubmit2']) AND !empty($_POST['formsubmit2'])) { // if step 2 form has been submitted

	validateStep2Form($_POST);
	

}

else if ($_GET['step'] == '2' AND !isset($_POST['formsubmit2'])) { // otherwise display default form

	showStep2Form();

}

else if ($_GET['step'] == '1' AND !isset($_POST['formsubmit2'])) { // otherwise display default form

	showStep1Form();

}


else if (!isset($_GET['step']) AND !isset($_POST['formsubmit2']) AND !isset($_POST['formsubmit1'])) { // otherwise display splash screen

	showSplashPage();

}



doFooter();


?>
Return current item: WPGet