PHP Classes

File: wpgcfg.php

Recommend this page to a friend!
  Classes of Peter Upfold   WPGet   wpgcfg.php   Download  
File: wpgcfg.php
Role: Configuration script
Content type: text/plain
Description: WPGet Installer - generates copy and pastable code for you
Class: WPGet
Retrieve posts from a Wordpress 2.0 database
Author: By
Last change: PHP 4 support dropped, switched over to Perl regular expressions for forwards compatibility, ability to show posts only in a specified date range, ability to show posts only matching a certain search term, support for stripping links from WPGet’s output. Bump to version 1.0!
Date: 14 years ago
Size: 65,979 bytes
 

Contents

Class file image Download
<?php /* WPGet - retrieves WordPress posts from a database for display on a web pge Copyright (C) 2006-2010 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: peter@upfold.org.uk Web: http://peter.upfold.org.uk/projects/wpget VERSION: 1.0 REVISION: $Rev: 22 $ */ // 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', '1.0'); /**************************** 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-2010 <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 a sprinkling of unicorn tears.</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 'your@email.address'; } ?>" /></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="Y-m-d">YYYY-MM-DD</option> <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="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="Y-m-d">YYYY-MM-DD</option> <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="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="striplinks" id="striplinks" value="true"<?php if ($postdata['striplinks'] == 'true') { echo ' checked="checked"'; }?>/> &nbsp;&nbsp;&nbsp;&nbsp;<label for="striplinks">Remove links from posts?</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_daterange" name="_internal_daterange" onchange="showHideAdvancedFeatures(this, document.getElementById('formdaterange'));" /> <label for="_internal_daterange">Show posts only inside a specified date range</label><br /><br /> <input type="checkbox" id="_internal_search" name="_internal_search" onchange="showHideAdvancedFeatures(this, document.getElementById('formsearch'));" /> <label for="_internal_search">Show posts only matching a post title/content search</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="formdaterange" style="display:none"> <h3>Date Range</h3> <p>If you want WPGet to only show posts that are in a specified date range, enter the start and end date below. The date and time should be in a format that will be recognised by <a href="http://www.php.net/strtotime" target="_blank">strtotime()</a> (YYYY-MM-DD is ideal).</p> &nbsp;&nbsp;Start Date:&nbsp;&nbsp;<input type="text" name="daterange_start" value="" /><br /> &nbsp;&nbsp;End Date:&nbsp;&nbsp;&nbsp;<input type="text" name="daterange_end" value="" /><br /> </div> <div id="formsearch" style="display:none"> <h3>Search</h3> <p>If you want WPGet to only show posts that match a specific post title and post content search term, enter that search term below.</p> &nbsp;&nbsp;Search Term:&nbsp;&nbsp;&nbsp;<input type="text" name="searchterm" value="" /><br /> </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, $striplinks, $showcredit, $usestyle, $catname, $tagname, $daterange_start, $daterange_end, $searchterm, $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 ($daterange_start != false && $daterange_end != false) { echo "\n\$wpget->daterange_start = \"{$daterange_start}\";"; echo "\n\$wpget->daterange_end = \"{$daterange_end}\";"; } if ($searchterm != false) { echo "\n\$wpget->searchtoreturn = \"{$searchterm}\";"; } if (empty($singlepost)) { // final implementation line echo "\n\$wpget->getWordpressEntries(".$noofposts.", ".$extracts.", ".$stripimages.", ".$stripembed.", ".$stripscript.", ".$striplinks.");\n"."?"."></textarea>"; } else { // single post echo "\n\$wpget->getSinglePost({$singlepost}, {$extracts}, {$stripimages}, {$stripembed}, {$stripscript}, {$striplinks});\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 ****/ private \$mysqluser = \"".$dbuser."\"; // your MySQL username for Wordpress private \$mysqlpass = \"".$dbpass."\"; // your MySQL password for Wordpress private \$mysqlhost = \"".$dbhost."\"; // your MySQL host private \$mysqldb = \"".$dbname."\"; // your MySQL database name for Wordpress private \$mysqlprefix=\"".$dbprefix."\"; // Wordpress table prefix - always include underscore at end if applicable "; if ($email == 'false') { // if it's false, remove quotes $config .= "private \$errorsto = false; // send error emails to whom?"; } else { $config .= "private \$errorsto = \"".$email."\"; // send error emails to whom?"; } $config .= " // set the above to false if you don't want email error notifications private \$debugmode = false; // set to false when working on a real server so potential nasty people don't see MySQL errors private \$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['striplinks'])) { $postdata['striplinks'] = '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 (empty($postdata['daterange_start']) && !empty($postdata['daterange_end'])) { $postdata['daterange_start'] = false; $postdata['daterange_end'] = false; } if (empty($postdata['searchterm'])) { $postdata['searchterm'] = false; } 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['striplinks'], $postdata['showcredit'], $postdata['style'], $postdata['catname'], $postdata['tagname'], $postdata['daterange_start'], $postdata['daterange_end'], $postdata['searchterm'], $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-2010 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: peter@upfold.org.uk Web: http://peter.upfold.org.uk/projects/wpget VERSION: 1.0 */ class wpGet { // config "; $wpgetsrc .= $configsection; $wpgetsrc .= <<<EOT /********** STOP PASTING YOUR CONFIG HERE *********/ /****** PUBLIC VARIABLES (CAN BE CHANGED AT RUNTIME) *******/ public __%VAR%__dateformat = "Y-m-d 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 public __%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) public __%VAR%__categoriestoreturn = false; // to return posts only from a particular category, turn this var // into an array of the category names // for example: // var __%VAR%__categoriestoreturn = array(); // __%VAR%__categoriestoreturn[0] = "Category Name" public __%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. public __%VAR%__daterange_start = false; // Unix timestamp of the start of a daterange from which you would like to retrieve // WordPress posts. Only posts within this var and daterange_end will be included // in WPGet's output. Set to false to show posts regardless of date. public __%VAR%__daterange_end = false; // Unix timestamp of the end of a daterange from which you would like to retrieve // WordPress posts. Only posts within daterange_start and this var will be included // in WPGet's output. Set to false to show posts regardless of date. public __%VAR%__searchtoreturn = false; // Only return posts matching this search term. The post title and post content will // be searched for this string. Only posts which match will be shown in WPGet's output. // Leave as false to disable searching. public __%VAR%__showauthor = true; // show post author in WPGet's output public __%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 public __%VAR%__usestyle = false; // use specified style for WPGet's output (or false for no style/custom) /***** INTERNAL VARIABLES ONLY, DON'T CHANGE THEM *****/ private __%VAR%__categorylist = array(); private __%VAR%__catsearch = array(); private __%VAR%__taglist = array(); private __%VAR%__tagsearch = array(); private __%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(__%VAR%__posttext, __%VAR%__minimum_length = 200, __%VAR%__length_offset = 20, __%VAR%__cut_words = FALSE, __%VAR%__dots = TRUE) { // __%VAR%__minimum_length: // The approximate length you want the concatenated text to be // __%VAR%__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 __%VAR%__tag_counter = 0; __%VAR%__quotes_on = FALSE; // Check if the text is too long if (strlen(__%VAR%__posttext) > __%VAR%__minimum_length) { // Reset the tag_counter and pass through (part of) the entire text __%VAR%__c = 0; for (__%VAR%__i = 0; __%VAR%__i < strlen(__%VAR%__posttext); __%VAR%__i++) { // Load the current character and the next one // if the string has not arrived at the last character __%VAR%__current_char = substr(__%VAR%__posttext,__%VAR%__i,1); if (__%VAR%__i < strlen(__%VAR%__posttext) - 1) { __%VAR%__next_char = substr(__%VAR%__posttext,__%VAR%__i + 1,1); } else { __%VAR%__next_char = ""; } // First check if quotes are on if (!__%VAR%__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 (__%VAR%__current_char == '<') { if (__%VAR%__next_char == '/') { __%VAR%__tag_counter += 1; } else { __%VAR%__tag_counter += 3; } } // Slash signifies an ending (like </a> or ... />) // substract 2 if (__%VAR%__current_char == '/' && __%VAR%__tag_counter <> 0) __%VAR%__tag_counter -= 2; // On a ">" substract 1 if (__%VAR%__current_char == '>') __%VAR%__tag_counter -= 1; // If quotes are encountered, start ignoring the tags // (for directory slashes) if (__%VAR%__current_char == '"') __%VAR%__quotes_on = TRUE; } else { // IF quotes are encountered again, turn it back off if (__%VAR%__current_char == '"') __%VAR%__quotes_on = FALSE; } // Count only the chars outside html tags if(__%VAR%__tag_counter == 2 || __%VAR%__tag_counter == 0){ __%VAR%__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 (__%VAR%__c > __%VAR%__minimum_length - __%VAR%__length_offset && __%VAR%__tag_counter == 0 && (__%VAR%__next_char == ' ' || __%VAR%__cut_words == TRUE)) { __%VAR%__posttext = substr(__%VAR%__posttext,0,__%VAR%__i + 1); if(__%VAR%__dots){ __%VAR%__posttext .= '...'; } return __%VAR%__posttext; } } } return __%VAR%__posttext; } function connectToDB() { if (!__%VAR%__this->conn) { // connects to the database and selects the right db ready for action __%VAR%__this->conn = mysql_connect(__%VAR%__this->mysqlhost, __%VAR%__this->mysqluser, __%VAR%__this->mysqlpass) or die(__%VAR%__this->friendlyError(mysql_error(), "{Connect}")); mysql_select_db(__%VAR%__this->mysqldb) or die (__%VAR%__this->friendlyError(mysql_error(), "{Select DB}")); } } // end connectToDB() function friendlyError(__%VAR%__error, __%VAR%__query, __%VAR%__line = false, __%VAR%__file = false) { // gives a friendly error should anything go wrong echo "<h1>Error Loading This Page</h1><p>Please contact the site administrator and let them know that there is a configuration issue with WPGet.</p>"; if (__%VAR%__this->debugmode) { echo "<p>MySQL said: <b>".__%VAR%__error."</b>.</p><p>It was running the following query: <b>".__%VAR%__query."</b>.</p><p>The query was called on line <b>".__%VAR%__line."</b> by file <b>".__%VAR%__file."</b>."; } // mail you telling you error details else if (__%VAR%__this->errorsto != false) { __%VAR%__mail = "Hey there,<br /><br />There was a database problem with the WPGet script on your site running on <b>".__%VAR%___SERVER['HTTP_HOST']."</b>.<br /><br /> A user tried to view the page <b>".__%VAR%___SERVER['REQUEST_URI']."</b> <i>(".__%VAR%___SERVER['SCRIPT_FILENAME'].")</i>. Something went wrong with the database. <br /><br />MySQL said:<b> ".__%VAR%__error."</b><br /><br />Query:<b> ".__%VAR%__query."</b>. Called on line <b>".__%VAR%__line."</b> by file <b>".__%VAR%__file."</b>.<br /><br />Have a nice day!"; if (error_log(__%VAR%__mail, 1, __%VAR%__errorsto, "From: wpget@".__%VAR%___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(__%VAR%__sql, __%VAR%__line, __%VAR%__file) { // wrapper function for all SQL queries (new as of 0.7), including new error handling // and supression of PHP's errors if (!__%VAR%__conn) { __%VAR%__this->connectToDB(); } __%VAR%__result = @mysql_query(__%VAR%__sql, __%VAR%__this->conn) or die (__%VAR%__this->friendlyError(mysql_error(), __%VAR%__sql, __%VAR%__line, __%VAR%__file)); __%VAR%__this->qcount++; return __%VAR%__result; } // end query() function crash() { // crash function __%VAR%__this->query("hfduhf", __LINE__, __FILE__); } // end crash() function convert_smart_quotes(__%VAR%__string) // not mine either - thanks to Chris Shiflett at http://shiflett.org/archive/165 { __%VAR%__search = array(chr(145), chr(146), chr(147), chr(148), chr(151)); __%VAR%__replace = array('&lsquo;', '&rsquo;', '&ldquo;', '&rdquo;', '&mdash;'); return str_replace(__%VAR%__search, __%VAR%__replace, __%VAR%__string); } function formatWPContent(__%VAR%__wpdata, __%VAR%__chars, __%VAR%__stripimages, __%VAR%__stripembed, __%VAR%__stripscript, __%VAR%__striplinks) { if (__%VAR%__chars > 0) { __%VAR%__content = stripslashes(__%VAR%__this->html_substr(__%VAR%__wpdata['post_content'], __%VAR%__chars, 20)); __%VAR%__content = __%VAR%__this->convert_smart_quotes(__%VAR%__content); } else { __%VAR%__content = __%VAR%__wpdata['post_content']; __%VAR%__content = __%VAR%__this->convert_smart_quotes(__%VAR%__content); } // strip images from posts if (__%VAR%__stripimages) { __%VAR%__content = preg_replace('#</?img[^>]*>#is', '<!--img-->', __%VAR%__content); } if (__%VAR%__stripembed) { // strip embeds from posts __%VAR%__content = preg_replace('#</?embed[^>]*>(.+</embed[^>]*>|)#is', '<!--embed-->', __%VAR%__content); } if (__%VAR%__stripscript) { // strip javascript from posts __%VAR%__content = preg_replace('#</?script[^>]*>(.+</script[^>]*>|)#is', '<!--script-->', __%VAR%__content); } if (__%VAR%__striplinks) { // strip any links (or other <a> tagged content) from posts __%VAR%__content = preg_replace('#</?a[^>]*>#is', '<!--link-->', __%VAR%__content); __%VAR%__content = preg_replace('#</?\/a[^>]*>#is', '<!--endlink-->', __%VAR%__content); } ?><div class="__wpget_singleentry"><?php echo '<h2><a href="'.__%VAR%__wpdata['guid'].'">'.__%VAR%__wpdata['post_title'].'</a></h2>'.nl2br(__%VAR%__content).'<br /><br /><p>Posted on '.date(__%VAR%__this->dateformat, strtotime(__%VAR%__wpdata['post_date'])); if (__%VAR%__this->showauthor) echo ' by '.__%VAR%__wpdata['display_name']; // print author name echo '.<br />'.__%VAR%__wpdata['comment_count']; if (__%VAR%__wpdata['comment_count'] > 0) { __%VAR%__jump = "#comments"; } else { __%VAR%__jump = "#respond"; } if (__%VAR%__wpdata['comment_count'] == 1) { __%VAR%__comment = "comment"; } else { __%VAR%__comment = "comments"; } echo ' <a href="'.__%VAR%__wpdata['guid'].__%VAR%__jump.'">'.__%VAR%__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 __%VAR%__this->connectToDB(); __%VAR%__sql = "SELECT wpg_taxon.`term_taxonomy_id`, `name`, `slug` FROM `".__%VAR%__this->mysqlprefix."terms` AS wpg_terms INNER JOIN `".__%VAR%__this->mysqlprefix."term_taxonomy` AS wpg_taxon ON wpg_terms.`term_id` = wpg_taxon.`term_id` WHERE wpg_taxon.`taxonomy` = 'category';"; __%VAR%__q = __%VAR%__this->query(__%VAR%__sql, __LINE__, __FILE__); while (__%VAR%__ar = mysql_fetch_array(__%VAR%__q, MYSQL_ASSOC)) { __%VAR%__this->categorylist[__%VAR%__ar['term_taxonomy_id']] = __%VAR%__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 */ __%VAR%__i = 0; // an array counter for us foreach (__%VAR%__this->categoriestoreturn as __%VAR%__cat) { __%VAR%__srch = array_search(__%VAR%__cat, __%VAR%__this->categorylist); if (__%VAR%__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 ".__%VAR%__cat." was not found, WPGet cannot get the posts!"); } else { __%VAR%__this->catsearch[__%VAR%__i] = __%VAR%__srch; // set the list of categories to search to the ID of the current category __%VAR%__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. __%VAR%__this->connectToDB(); __%VAR%__sql = "SELECT wpg_taxon.`term_taxonomy_id`, `name`, `slug` FROM `".__%VAR%__this->mysqlprefix."terms` AS wpg_terms INNER JOIN `".__%VAR%__this->mysqlprefix."term_taxonomy` AS wpg_taxon ON wpg_terms.`term_id` = wpg_taxon.`term_id` WHERE wpg_taxon.`taxonomy` = 'post_tag';"; __%VAR%__q = __%VAR%__this->query(__%VAR%__sql, __LINE__, __FILE__); while (__%VAR%__ar = mysql_fetch_array(__%VAR%__q, MYSQL_ASSOC)) { __%VAR%__this->taglist[__%VAR%__ar['term_taxonomy_id']] = __%VAR%__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 */ __%VAR%__i = 0; // an array counter for us foreach (__%VAR%__this->tagstoreturn as __%VAR%__tag) { __%VAR%__srch = array_search(__%VAR%__tag, __%VAR%__this->taglist); if (__%VAR%__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 ".__%VAR%__tag." was not found, WPGet cannot get the posts!"); } else { __%VAR%__this->tagsearch[__%VAR%__i] = __%VAR%__srch; // set the list of tags to search to the ID of the current tag __%VAR%__i++; // increment the counter } } // end foreach } // end populateTagList() function getWordpressEntries(__%VAR%__number = 5, __%VAR%__chars = 300, __%VAR%__stripimages = true, __%VAR%__stripembed = true, __%VAR%__stripscript = true, __%VAR%__striplinks = false) { if (is_array(__%VAR%__this->categoriestoreturn)) { // if we have selective categories on // we do it a completely different way // so populate the list __%VAR%__this->populateCategoryList(); // then launch the alternative way to do it __%VAR%__this->getCatWPEntries(__%VAR%__this->catsearch, __%VAR%__number, __%VAR%__chars, __%VAR%__stripimages, __%VAR%__stripembed, __%VAR%__stripscript); // and quit out of this function return; } // end if else if (is_array(__%VAR%__this->tagstoreturn)) { // selected tags are on // populate tags __%VAR%__this->populateTagList(); // launch category pull, passing in the tags __%VAR%__this->getCatWPEntries(__%VAR%__this->tagsearch, __%VAR%__number, __%VAR%__chars, __%VAR%__stripimages, __%VAR%__stripembed, __%VAR%__stripscript); return; } __%VAR%__dateRangeClause = ''; __%VAR%__searchClause = ''; // if date range is set if (__%VAR%__this->daterange_start !== false && __%VAR%__this->daterange_end !== false) { // get both start and end as Unix timestamps if ((int) __%VAR%__this->daterange_start === __%VAR%__this->daterange_start) { // assume a timestamp __%VAR%__start = (int) __%VAR%__this->daterange_start; } else { __%VAR%__start = (int) strtotime(__%VAR%__this->daterange_start); } if ((int) __%VAR%__this->daterange_end === __%VAR%__this->daterange_end) { // assume a timestamp __%VAR%__end = (int) __%VAR%__this->daterange_end; } else { __%VAR%__end = (int) strtotime(__%VAR%__this->daterange_end); } if (__%VAR%__start == 0 || __%VAR%__end == 0) { // there is a problem with the date ranges echo 'Invalid WPGet date ranges specified.'; if (__%VAR%__this->debugmode) { echo ' on line '.__LINE__.' of '.__FILE__; } return false; } __%VAR%__dateRangeClause = "AND UNIX_TIMESTAMP(posts.`post_date`) > {__%VAR%__start} AND UNIX_TIMESTAMP(posts.`post_date`) < {__%VAR%__end}"; } if (__%VAR%__this->searchtoreturn !== false) { // do a post title/post content search -- only return posts which match the search __%VAR%__this->connectToDB(); __%VAR%__search = mysql_real_escape_string(__%VAR%__this->searchtoreturn); __%VAR%__searchClause = "AND ((posts.post_title LIKE '%{__%VAR%__search}%') OR (posts.post_content LIKE '%{__%VAR%__search}%'))"; } // if we have a style if (__%VAR%__this->usestyle != false) { __%VAR%__this->printStyleCSS(__%VAR%__this->usestyle); } // gets __%VAR%__number of wordpress entries and prints in a friendly format __%VAR%__this->connectToDB(); __%VAR%__sql = "SELECT * FROM `".__%VAR%__this->mysqlprefix."posts` as posts INNER JOIN `".__%VAR%__this->mysqlprefix."users` as users ON users.ID = posts.post_author WHERE posts.`post_status` = 'publish' AND posts.`post_type` = 'post' {__%VAR%__dateRangeClause} {__%VAR%__searchClause} ORDER BY `post_date` DESC LIMIT {__%VAR%__number};"; __%VAR%__q = __%VAR%__this->query(__%VAR%__sql, __LINE__, __FILE__); ?><div id="__wpget_entries"><?php while (__%VAR%__ar = mysql_fetch_array(__%VAR%__q)) { __%VAR%__ar['post_ID'] = __%VAR%__ar[0]; // first row returned is posts.ID __%VAR%__this->formatWPContent(__%VAR%__ar, __%VAR%__chars, __%VAR%__stripimages, __%VAR%__stripembed, __%VAR%__stripscript, __%VAR%__striplinks); } // Credit to me can be disabled, see top for details if (__%VAR%__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 getWordpressEntries() function getSinglePost(__%VAR%__postid, __%VAR%__chars = 0, __%VAR%__stripimages = true, __%VAR%__stripembed = true, __%VAR%__stripscript = true, __%VAR%__striplinks = false) { // gets the specified post ID __%VAR%__this->connectToDB(); settype(__%VAR%__postid, int); __%VAR%__postid = addslashes(__%VAR%__postid); __%VAR%__sql = "SELECT *, posts.`ID` as `post_ID` FROM `".__%VAR%__this->mysqlprefix."posts` as posts INNER JOIN `".__%VAR%__this->mysqlprefix."users` as users ON users.ID = posts.post_author WHERE posts.`post_status` = 'publish' AND posts.`ID` = {__%VAR%__postid} AND users.`ID` = posts.`post_author` ORDER BY `post_date` DESC LIMIT 1;"; __%VAR%__q = __%VAR%__this->query(__%VAR%__sql, __LINE__, __FILE__); __%VAR%__ar = mysql_fetch_assoc(__%VAR%__q); ?><div id="__wpget_entries"><?php __%VAR%__this->formatWPContent(__%VAR%__ar, __%VAR%__chars, __%VAR%__stripimages, __%VAR%__stripembed, __%VAR%__stripscript, __%VAR%__striplinks); // Credit to me can be disabled, see top for details if (__%VAR%__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(__%VAR%__categories, __%VAR%__number = 5, __%VAR%__chars = 300, __%VAR%__stripimages = true, __%VAR%__stripembed = true, __%VAR%__stripscript = true, __%VAR%__striplinks = false) { __%VAR%__i = 0; // counter __%VAR%__catclause = "WHERE p2c.`term_taxonomy_id` IN ("; __%VAR%__catclause .= implode(',', __%VAR%__categories); // implode our array of categories into a comma-delimited list for MySQL's 'IN' __%VAR%__catclause .= ')'; __%VAR%__dateRangeClause = ''; __%VAR%__searchClause = ''; // if date range is set if (__%VAR%__this->daterange_start !== false && __%VAR%__this->daterange_end !== false) { // get both start and end as Unix timestamps if ((int) __%VAR%__this->daterange_start === __%VAR%__this->daterange_start) { // assume a timestamp __%VAR%__start = (int) __%VAR%__this->daterange_start; } else { __%VAR%__start = (int) strtotime(__%VAR%__this->daterange_start); } if ((int) __%VAR%__this->daterange_end === __%VAR%__this->daterange_end) { // assume a timestamp __%VAR%__end = (int) __%VAR%__this->daterange_end; } else { __%VAR%__end = (int) strtotime(__%VAR%__this->daterange_end); } if (__%VAR%__start == 0 || __%VAR%__end == 0) { // there is a problem with the date ranges echo 'Invalid WPGet date ranges specified.'; if (__%VAR%__this->debugmode) { echo ' on line '.__LINE__.' of '.__FILE__; } return false; } __%VAR%__dateRangeClause = "AND UNIX_TIMESTAMP(posts.`post_date`) > {__%VAR%__start} AND UNIX_TIMESTAMP(posts.`post_date`) < {__%VAR%__end}"; } if (__%VAR%__this->searchtoreturn !== false) { // do a post title/post content search -- only return posts which match the search __%VAR%__this->connectToDB(); __%VAR%__search = mysql_real_escape_string(__%VAR%__this->searchtoreturn); __%VAR%__searchClause = "AND ((posts.post_title LIKE '%{__%VAR%__search}%') OR (posts.post_content LIKE '%{__%VAR%__search}%'))"; } __%VAR%__sql = "SELECT * FROM `{__%VAR%__this->mysqlprefix}posts` AS posts INNER JOIN `{__%VAR%__this->mysqlprefix}term_relationships` AS p2c ON posts.`ID` = p2c.`object_id` INNER JOIN `{__%VAR%__this->mysqlprefix}users` AS users ON users.`ID` = posts.`post_author` {__%VAR%__catclause} {__%VAR%__dateRangeClause} {__%VAR%__searchClause} AND posts.`post_status` = 'publish' AND posts.`post_type` = 'post' ORDER BY p2c.`object_id` DESC LIMIT {__%VAR%__number};"; __%VAR%__q = __%VAR%__this->query(__%VAR%__sql, __LINE__, __FILE__); // duplicate prevention __%VAR%__shownPosts = array(); __%VAR%__spc = 0; while (__%VAR%__ar = mysql_fetch_array(__%VAR%__q)) { __%VAR%__ar['post_ID'] = __%VAR%__ar['object_id']; // for formatWPContent() if (!in_array(__%VAR%__ar['object_id'], __%VAR%__shownPosts)) { __%VAR%__shownPosts[__%VAR%__spc] = __%VAR%__ar['object_id']; __%VAR%__spc++; __%VAR%__this->formatWPContent(__%VAR%__ar, __%VAR%__chars, __%VAR%__stripimages, __%VAR%__stripembed, __%VAR%__stripscript, __%VAR%__striplinks); } } // end while // Credit to me can be disabled, see top for details if (__%VAR%__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>'; } } // end getCatWPEntries() } // end class ?> EOT; $wpgetsrc = str_replace('__%VAR%__', '$', $wpgetsrc); 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(); ?>