|
I just installed a PHPRunner 6 project onto a WordPress 3.3.1 site with a custom Template successfully. I followed these instructions, for the most part, but I had to do work arounds. First of all, the IFRAME plugin mentioned in this article, the latest version of it with the recommended code change in this tutorial still did not function. The iFrame insisted on mirroring back the same page.. So I had a page within a page when I used a Page with the IFrame plugin shortcode. So, I gave up trying to use the IFrame plugin. I did install the rootCookie plugin and it worked fine without any special changes. It auto-detected the necessary structure and when I saved it in the configuration window it seemed to work fine. In other words, it allowed permissions to extend all the way into my PHPRunner code folders. The instructions here about what to add to the "After application initialized" file are a bit unclear because the code example used for the login.php is now outdated if you are using PHPRunner 6. I have updated it in the following example to reflect what PHPRunner 6 produces. [b]I should also point out that despite the code that does this -- // check if username exists in the database
The user does NOT have to be logged in to the WordPress function when used as I used it. The Login that applies is the one that PHPRunner uses. In my case I hard-coded some login usernames and passwords. Here is the complete code I added that created no errors when put into PHPRUNNER 6 Events : After application initialized[/b] (I left a long modified version of a "Auth key" as an example):
define('AUTH_KEY', '$mCv%IR#)-1KT888<!Q.987YV4-XaHA&Rh3yLPlN[;Qa:SNM.YX)+ooF;OxSOAfHs6MDSd5');
$wpconn=db_connect();
function get_option($option){
global $wpconn;
$ret="";
$rs=db_query("select option_value from wp_options where option_name='$option'",$wpconn);
$data=db_fetch_array($rs);
if($data) {
$ret = $data["option_value"];
}
return $ret;
}if ( !function_exists('hash_hmac') ):function hash_hmac($algo, $data, $key, $raw_output = false)
{
return _hash_hmac($algo, $data, $key, $raw_output);
}
endif;
function _hash_hmac($algo, $data, $key, $raw_output = false) {
$packs = array('md5' => 'H32', 'sha1' => 'H40');
if ( !isset($packs[$algo]) )
return false;
$pack = $packs[$algo];
if (strlen($key) > 64)
$key = pack($pack, $algo($key));
$key = str_pad($key, 64, chr(0));
$ipad = (substr($key, 0, 64) ^ str_repeat(chr(0x36), 64));
$opad = (substr($key, 0, 64) ^ str_repeat(chr(0x5C), 64));
$hmac = $algo($opad . pack($pack, $algo($ipad . $data)));
if ( $raw_output )
return pack( $pack, $hmac );
return $hmac;}function wp_salt($scheme = 'auth')
{
$salt=get_option('auth_salt');
return $salt;}// get wordpress username from cookies
$cookie_key = "wordpress_" . md5(get_option('siteurl'));
foreach ($_COOKIE as $key=>$value){ if (substr($key,0,strlen($cookie_key))==$cookie_key)
{
$cookie = $value;
}}$logged=true;// parse cookie
$cookie_elements = explode('|', $cookie);
if ( count($cookie_elements) == 3 )
{
$username=$cookie_elements[0];
$expiration=$cookie_elements[1];
$hmac=$cookie_elements[2];
// Quick check to see if an honest cookie has expired
if ( $expiration < time() )
{
$logged=false;
}
}
else
$logged=false;
// check if username exists in the database
if ($logged){
$rs=db_query("SELECT * FROM `wp_users` u inner join wp_usermeta m on u.ID=m.user_id
where meta_key='wp_capabilities' and user_login='$username'",$wpconn);
$data=db_fetch_array($rs);
if($data)
{
$pass_frag = substr($data["user_pass"], 8, 4);
$salt = wp_salt();
$key = hash_hmac('md5', $username . $pass_frag . '|' . $expiration, $salt);
$hash = hash_hmac('md5', $username . '|' . $expiration, $key);
if ( $hmac != $hash )
{
$logged=false;
}
else
{
$meta=$data["meta_value"];
preg_match('/"([^}]+)"/', $meta , $matches);
$group=$matches[1];
}
}}if ($logged){
$_SESSION["UserID"] = $username;
$_SESSION["GroupID"] = $group;
if ($group=='administrator')
$_SESSION["AccessLevel"] = ACCESS_LEVEL_ADMIN;
else
$_SESSION["AccessLevel"] = ACCESS_LEVEL_USER;}else{ $_SESSION["UserID"] = "";
$_SESSION["AccessLevel"] = "";
$_SESSION["GroupID"] = "";
} $_SESSION["AccessLevel"] = ACCESS_LEVEL_USER; if($auditObj) { $auditObj->LogLogin($pUsername); $auditObj->LoginSuccessful();
} if($globalEvents->exists("AfterSuccessfulLogin"))
{
$dummy=array();
$globalEvents->AfterSuccessfulLogin($pUsername,$pPassword,$dummy);
}
Then, I created a Wordpress template to ReDirect any page using this Template to the PhpRunner 6 project in another folder on the same site. I uploaded this so that I could use it as a template when I created a new page.
<?php
/*
Template Name: RedirectPHPrunner
*/
?>
<?php header('Location: http://www.awebsiteexample.com/wp-content/themes/TemplateinUse/Phprunner/login.php';);
die();
?>
I Added a new page, selected Page Template "RedirectPHPrunner", gave it a title to use as a menu link name such as "Reporting", wrote no content, SAVED to PUBLISH and Public. In the main menu of the WordPress website when I clicked on the link "Reporting" it instantly loaded the LOGIN page for my PHPRunner project. At this point I was not using the WordPress headers and footers, simply the PHPRunner 6 headers and footers. If I wanted to simulate the look of the Wordpress site I could have modified the PHPRunner templates during the project build phase, but I elected not to do that. What I appreciated was that I did not get errors! Thank you, Sergey for the tutorial. If you can get the IFrame component to work in WordPress 3.3.1 then please update us on that accomplishment!
|