Jump to content

authorise plugin manipulation help?


samoht

Recommended Posts

Hello all,

 

I am trying to manipulate a plugin for membership restriction on a wp blog. The plugin works fine but servers up a whole custom page for blocking access. I want to send the restriction message within the site itself - so that the header footer and side bar still show.

 

here is the function that protects the posts

	function aMemberProtect()
{

	if (empty($this->amprotectamroot))  return;

	global $post;

	global $_product_id;

	//
	// Do not lock out the home page or archives if a protected post is on it...
	//

	if (!is_single() && !is_page()) return;

	//
	// OK, this is a post or a page...does it want protecting?...
	//

	$post_id = intval($post->ID);

	//
	// Get product ids from the old way of storing them...
	//

	$post_custom = get_post_custom($post_id);

	if (!empty($post_custom) && !empty($post_custom['amember_products']))
	{

		$amember_products = trim($post_custom['amember_products'][0]);

		if (!empty($amember_products))
		{

			$_product_id = explode(",",$amember_products);

		}

	} // end if need to protect with the old way

	//
	// Protect with the new method
	//

 	$amproducts = get_post_meta($post_id, 'amprotect_amproducts', true);

	if (empty($amproducts) || !is_array($amproducts)) return;

	//
	// Ok, we need to protect this page with the aMember products specified...
	//

	foreach ($amproducts as $key=>$value)
		$_product_id[] = $key;

	$_product_id = array_unique($_product_id);

	if (empty($_product_id)) return;							// not a protected post or page

	//
	// Set up the URL to this post or page...
	//

	$redirect2me  = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
	$redirect2mee = urlencode($redirect2me);

	//
	// Check the aMember SESSION variables to see if this person is logged in or not.
	//

	$amemberuser = $_SESSION['_amember_user'];

	if (empty($amemberuser))
	{

		//
		// Not logged in so redirect to login screen and then back to this post...
		//

		unset($_SESSION['_amember_user']);
		unset($_SESSION['_amember_product_ids']);
		unset($_SESSION['_amember_products']);
		unset($_SESSION['_amember_links']);
		unset($_SESSION['_amember_subscriptions']);

		header('Location:'.$this->amprotectamroot.'login.php?amember_redirect_url='.$redirect2mee);

		exit();

	} else {

		//
		// Logged in so check products to see if member should be allowed access
		//

		$block = true;

		if (in_array('all',$_product_id))
		{

			$block=false;										// no need to check the rest

		} else {

			$numprods  = 0;
			$prodnames = '';

			foreach ($amemberuser['data']['status'] as $key=>$value)
				if ($value == 1 && in_array($key,$_product_id))
					$block=false;

		} // end if all members can access or just those with certain products

		if ($block)
		{

			//
			// Build the link(s) to the products that the visitor is going to need to purchase
			//

			$alltheproducts = $this->amGetProducts($allthepricegroups);		// get info out of amember about all the products

			$productnames   = '<center><table><tr><td><ul>'."\n";			// list of products that can view this content
			$show2all       = false;										// are one of the products the "all" flag?
			$numcanview     = 0;											// the number of products that can view this post

			foreach ($_product_id as $pid)
			{

				$pid = trim(strtolower($pid));								// make sure no extra spaces and not "ALL" or something

				if ($pid=="all")
				{

					$show2all = true;										// used later

				} else {

					$purl = $this->amprotectamroot.'member.php?price_group='.$allthepricegroups[$pid].'&product_id='.$pid;

					$productnames .= '<li><a href="'.$purl.'">'.$alltheproducts[$pid].'</a></li>'."\n";

					$numcanview++;

				}

			} // end checking products

			$productnames .= '</ul></td></table></center>'."\n";

			// echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"'."\n";
			// echo '   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n";
			// echo '<html xmlns="http://www.w3.org/1999/xhtml">'."\n";
			// echo '<head>'."\n";
			// echo '<title>Members Only</title>'."\n";
			// echo '<style type="text/css">'."\n";
			// echo '<!--'."\n";
			// echo '* { margin: 0; 	padding: 0; }'."\n";
			// echo 'body { font-family: Georgia, Arial, Helvetica, Sans Serif; font-size: 100%; }'."\n";
			// echo 'a { color: #08658F; font-weight:bold; }'."\n";
			// echo 'a:hover { color: #0092BF; }'."\n";
			// echo 'h1, h2 { color: #08658F; }'."\n";
			// echo 'h1 { font-size: 300%; padding: .5em 0; }'."\n";
			// echo 'hr { background-color: #08658F; max-width:600px; }'."\n";
			// echo '-->'."\n";
			// echo '</style>'."\n";
			// echo '</head>'."\n";
			// echo '<body>'."\n";
			echo '<center><div id="accessdenied">'."\n";
			echo '<h1>Members Only:</h1>'."\n";
			echo '<a href="'.$redirect2me.'">'.$redirect2me.'</a>'."\n";
			echo '<br /> <br /><hr /><br />'."\n";
			echo '<table>'."\n";
			echo '<tr><td align="center">'."\n";
			echo 'Access to this web page is not allowed with your current active membership.<br /> <br />'."\n";
			echo 'Please go to your <a href="'.$this->amprotectamroot.'member.php">Membership Information Page</a> to add or renew';
			if ($numcanview < 1 || $show2all)
			{
				echo '.'."\n";
			} else {
				echo ' : <br /> <br />'.$productnames.'</a>.'."\n";
			}
			echo '</td></tr></table>'."\n";
			echo '</div></center>'."\n";
			echo '</body>'."\n";
			echo '</html>'."\n";

			exit();												// do not show anything else

		} // end if access is not allowed

	} // end if member is signed in or not

} // end function aMemberProtect

 

I tried just adding an include(header.php) right into this code but that did not help it just gave me a blank page.

 

Any Ideas?

 

Link to comment
https://forums.phpfreaks.com/topic/177795-authorise-plugin-manipulation-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.