News:

Wondering if this will always be free?  See why free is better.

Main Menu

What does this code tell me?

Started by Biology Forums, March 02, 2011, 11:11:13 PM

Previous topic - Next topic

Biology Forums

There's a file in a folder within the main directory of my forum /public_html/subs/ipn.php. In ipn.php, it states the following:

// Start things rolling by getting SMF alive...
require_once('./../SSI.php');
require_once($sourcedir . '/ManagePaid.php');
loadLanguage('ManagePaid');


I know my SSI.php file is in /public_html/ so does './../SSI.php' accurately represent that? In other words, does './../SSI.php' mean go back 1 directory into the /public_html/ directory?

Bigguy

SSI.php is located in the root of your SMF install. Where settings.php is.

Biology Forums

So should I change './../SSI.php' to '/../SSI.php' or to '/SSI.php' ? ... Remember that this is being called from a directory in the /public_html/ main directory. Or should I leave it as './../SSI.php' ?

Bigguy

If you installed a mod like paid subscriptions or treasury then the mod should have everything set up for you already.

Biology Forums

Quote from: Bigguy on March 02, 2011, 11:20:19 PM
If you installed a mod like paid subscriptions or treasury then the mod should have everything set up for you already.

I installed paid subscription, but I just want to know what './../SSI.php' means. Does it mean /Public_html/ssi.php ? If so, what is that extra dot './'

Also, in index.template.php, it is written like this:

require_once('SSI.php');

Why is it different than require_once('./../SSI.php')?

Bigguy

I would think it all depends on where the file is that is calling SSI.php. I'm not quite sure though myself. It could be this:

./../SSI.php

If SSI.php is in the public_html directory then

the ./../

would be

/public_html/subs/


Bigguy


Biology Forums

Perhaps I could use:

require_once($forum_dir . '/SSI.php')

Bigguy

Is the mod not working for you. ??? What version of SMF do you have. ???

Matthew K.

$sourcedir needs to be globalized...
Code (Find) Select
// Start things rolling by getting SMF alive...
require_once('./../SSI.php');
require_once($sourcedir . '/ManagePaid.php');
loadLanguage('ManagePaid');

Code (Replace) Select
// Start things rolling by getting SMF alive...
require_once('./../SSI.php');
global $sourcedir;
require_once($sourcedir . '/ManagePaid.php');
loadLanguage('ManagePaid');


Matthew K.

I updated my post for you. That should work.

Biology Forums

Quote from: Labradoodle-360 on March 03, 2011, 12:16:05 AM
I updated my post for you. That should work.

Are you sure Labradoodle-360? This came straight from the mod...

<?php
/******************************************************************************
* ipn.php                                                                     *
*******************************************************************************
* SMF: Simple Machines Forum                                                  *
* Open-Source Project Inspired by Zef Hemel ([email protected])                *
* =========================================================================== *
* Software Version:           SMF 1.1                                         *
* Software by:                Simple Machines (http://www.simplemachines.org) *
* Copyright 2001-2006 by:     Lewis Media (http://www.lewismedia.com)         *
* Support, News, Updates at:  http://www.simplemachines.org                   *
*******************************************************************************
* This program is free software; you may redistribute it and/or modify it     *
* under the terms of the provided license as published by Lewis Media.        *
*                                                                             *
* This program is distributed in the hope that it is and will be useful,      *
* but WITHOUT ANY WARRANTIES; without even any implied warranty of            *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                        *
*                                                                             *
* See the "license.txt" file for details of the Simple Machines license.      *
* The latest version can always be found at http://www.simplemachines.org.    *
******************************************************************************/

// Start things rolling by getting SMF alive...
require_once('./../SSI.php');
require_once(
$sourcedir '/ManagePaid.php');
loadLanguage('ManagePaid');

// If there's literally nothing coming in, escape!
if (empty($_POST))
exit;

// I assume we're even active?
if (empty($modSettings['paid_enabled']))
exit;

// Verify the incoming string is something we can deal with.
if ((isset($_POST['txn_type']) || isset($_POST['payment_status'])) && !empty($modSettings['paypal_email']) && ((isset($_POST['business']) && $modSettings['paypal_email'] == $_POST['business']) || (isset($_POST['receiver_email']) && $modSettings['paypal_email'] == $_POST['receiver_email'])))
{
if (!isset($_POST['business']))
$_POST['business'] = $_POST['receiver_email'];

$txnType 'paypal';
if (!isset($_POST['txn_type']))
$_POST['txn_type'] = '';
}
elseif (!empty(
$_POST['callbackPW']) && !empty($worldpay_pw) && $_POST['callbackPW'] == $worldpay_pw)
$txnType 'worldpay';
elseif (!empty(
$_POST['x_response_code']) && !empty($modSettings['authorize_id']))
$txnType 'authorize';
// Otherwise hope it's 2co...
elseif (!empty($_POST['x_MD5_Hash']) && !empty($modSettings['2co_id']))
$txnType '2co';
// Or new just in - nochex!
elseif (!empty($_POST['order_id']) && !empty($modSettings['nochex_email']))
$txnType 'nochex';

// Nothing else? EXIT!
else
generateError($txt['paid_unknown_transaction_type']);

if (!
file_exists($txnType '.php'))
generateError(sprintf($txt['paid_missing_transaction_type'], $txnType));

// Create an instance of the class.
require_once($txnType '.php');

// If this is 2co we need to remove the 2!
if ($txnType == '2co')
$txnType 'twoco';
$payType = new $txnType();

// Get the ID_SUB and ID_MEMBER amoungst others...
@list ($ID_SUB$ID_MEMBER) = $payType->precheck();

// This would be bad...
if (empty($ID_MEMBER))
generateError($txt['paid_empty_member']);

// Integer these just incase.
$ID_SUB = (int) $ID_SUB;
$ID_MEMBER = (int) $ID_MEMBER;

// Verify the member.
$request db_query("
SELECT ID_MEMBER, memberName, realName, emailAddress
FROM 
{$db_prefix}members
WHERE ID_MEMBER = 
$ID_MEMBER"__FILE____LINE__);
// Didn't find them?
if (mysql_num_rows($request) == 0)
generateError(sprintf($txt['paid_could_not_find_member'], $ID_MEMBER));
list (
$ID_MEMBER$username$name$email) = mysql_fetch_row($request);
mysql_free_result($request);

// Get the subscription details.
$request db_query("
SELECT cost, active, length, Name, email_complete
FROM 
{$db_prefix}subscriptions
WHERE ID_SUBSCRIBE = 
$ID_SUB"__FILE____LINE__);

// Didn't find it?
if (mysql_num_rows($request) == 0)
generateError(sprintf($txt['paid_count_not_find_subscription'], $ID_MEMBER$ID_SUB));

list (
$cost$active$length$subname$emaildata) = mysql_fetch_row($request);
mysql_free_result($request);

// Is this a refund etc?
if ($payType->isRefund())
{
// Delete user subscription.
removeSubscription($ID_SUB$ID_MEMBER);

db_query("
DELETE FROM 
{$db_prefix}log_subscribed
WHERE ID_SUBSCRIBE = 
$ID_SUB
AND ID_MEMBER = 
$ID_MEMBER
AND status = 0"
__FILE____LINE__);

// Receipt?
if (!empty($modSettings['paid_email']) && $modSettings['paid_email'] == 2)
{
$emailbody $txt['paid_delete_sub_body'];
$emailbody .= "\n\n\t";
$emailbody .= $txt['paid_new_sub_body_sub'] . ' ' $subname;
$emailbody .= "\n\t" $txt['paid_new_sub_body_name'] . ' ' $name ' (' $username ')';
$emailbody .= "\n\t" $txt['paid_new_sub_body_date'] . ' ' timeformat(time(), false);

paidAdminEmail($txt['paid_delete_sub_subject'], $emailbody);
}

}
// Otherwise is it what we want, a purchase?
elseif ($payType->isPayment() || $payType->isSubscription())
{
$cost unserialize($cost);
$totalCost $payType->getCost();
$notify false;

// Is this flexible?
if ($length == 'F')
{
$foundDuration 0;
// This is a little harder, can we find the right duration?
foreach ($cost as $duration => $value)
{
if ($duration == 'fixed')
continue;
elseif ((float) $value == (float) $totalCost)
$foundDuration strtoupper(substr($duration01));
}

// If we have the duration then we're done.
if ($foundDuration !== 0)
{
$notify true;
addSubscription($ID_SUB$ID_MEMBER$foundDuration);
}
}
else
{
$actual_cost $cost['fixed'];
// It must be at least the right amount.
if ($totalCost != && $totalCost >= $actual_cost)
{
// Add the subscription.
$notify true;
addSubscription($ID_SUB$ID_MEMBER);
}
}

// Send a receipt?
if (!empty($modSettings['paid_email']) && $modSettings['paid_email'] == && $notify)
{
$emailbody $txt['paid_new_sub_body'];
$emailbody .= "\n\n\t";
$emailbody .= $txt['paid_new_sub_body_sub'] . ' ' $subname;
$emailbody .= "\n\t" $txt['paid_new_sub_body_price'] . ' ' sprintf($modSettings['currency_symbol'], $totalCost);
$emailbody .= "\n\t" $txt['paid_new_sub_body_name'] . ' ' $name ' (' $username ')';
$emailbody .= "\n\t" $txt['paid_new_sub_body_email'] . ' ' $email;
$emailbody .= "\n\t" $txt['paid_new_sub_body_date'] . ' ' timeformat(time(), false);
$emailbody .= "\n" $txt['paid_new_sub_body_link'] . ":\n\t" $scripturl '?action=profile;u=' $ID_MEMBER;

paidAdminEmail($txt['paid_new_sub_subject'], $emailbody);
}

// Email the user?
if (strlen($emaildata 10) && strpos($emaildata"\n") !== false)
{
$subject substr($emaildata0strpos($emaildata"\n") - 1);
$body substr($emaildatastrpos($emaildata"\n") + 1);

$search = array('{NAME}''{FORUM}');
$replace = array($name$mbname);

$subject str_replace($search$replace$subject);
$body str_replace($search$replace$body);

require_once($sourcedir '/Subs-Post.php');
sendmail($email$subject$body);
}
}

// Incase we have anything specific to do.
$payType->close();

// Log an error then die.
function generateError($text$notify true)
{
global $modSettings$sourcedir$db_prefix$txt;

// Send an email?
if (!empty($modSettings['paid_email']))
paidAdminEmail($txt['paid_error_subject'], $txt['paid_error_body'] . "\n"  "---------------------------------------------\n" $text);

// Otherwise log and die.
log_error($text);
exit;
}

// Send an email to admins.
function paidAdminEmail($subject$body)
{
global $sourcedir$db_prefix$mbname$modSettings;

require_once($sourcedir '/Subs-Post.php');
$request db_query("
SELECT emailAddress, realName
FROM 
{$db_prefix}members
WHERE ID_GROUP = 1"
__FILE____LINE__);
while ($row mysql_fetch_assoc($request))
sendmail($row['emailAddress'], $subject$row['realName'] . "\n\n" $body "\n\n" $mbname);
mysql_free_result($request);

if (!empty($modSettings['paid_email_to']))
{
foreach (explode(','$modSettings['paid_email_to']) as $email)
sendmail(trim($email), $subject$body "\n\n" $mbname);
}
}

?>


Bigguy

Is the mod working for you right now. ???

Matthew K.

You should be fine to change the require for SSI to just "SSI.php"

Biology Forums

Quote from: Bigguy on March 03, 2011, 12:19:25 AM
Is the mod working for you right now. ???

Haven't tried :p, but I would have to make a donation to myself, which is not possible. :S

So...


// Start things rolling by getting SMF alive...
require_once('SSI.php');
require_once($sourcedir . '/ManagePaid.php');
loadLanguage('ManagePaid');


?

Bigguy

There is a test area is there not to test out ipn.php, or I maybe thinking of the treasury mod.


Bigguy

That must be in the other mod then, sorry about that. :) Did Labradoodle's suggestion work for you. ???

Biology Forums

Quote from: Bigguy on March 03, 2011, 12:34:50 AM
That must be in the other mod then, sorry about that. :) Did Labradoodle's suggestion work for you. ???

Working on it right now. Thanks.

Matthew K.

No problem. Be sure to let us know.

Biology Forums

I tried every possible way using the sandbox test and nothing worked :(

Arantor

If you're in public_html/subs/ipn.php and there's a request for ./../SSI.php, that means 'start at the current directory, go up a level, then load SSI.php' so it was right to start with.

This means it will fetch SSI.php from public_html not public_html/subs, and if you have just SSI.php being called from the current directory, you either need to move the IPN file into the top directory where SSI.php is or it'll fail, which is almost certainly what's happening now.

Oh, and when you're in that situation, $sourcedir is global because that's global scope being not inside a function.

Biology Forums

Quote from: Arantor on March 03, 2011, 03:42:18 AM
If you're in public_html/subs/ipn.php and there's a request for ./../SSI.php, that means 'start at the current directory, go up a level, then load SSI.php' so it was right to start with.

This means it will fetch SSI.php from public_html not public_html/subs, and if you have just SSI.php being called from the current directory, you either need to move the IPN file into the top directory where SSI.php is or it'll fail, which is almost certainly what's happening now.

Oh, and when you're in that situation, $sourcedir is global because that's global scope being not inside a function.

So I should leave the following code the way it is and move ipn.php to the main directory, so /public_html/ipn.php ?

// Start things rolling by getting SMF alive...
require_once('./../SSI.php');
require_once($sourcedir . '/ManagePaid.php');
loadLanguage('ManagePaid');


Thanks so much Arantor

Arantor

No, you should leave it where it is in the subs directory and leave the path alone because it was correct before it was touched.

Bigguy


Biology Forums

Quote from: Arantor on March 03, 2011, 06:08:38 PM
No, you should leave it where it is in the subs directory and leave the path alone because it was correct before it was touched.

Then why isn't it sending me a IPN when I test the mode using PayPal sandbox?

Arantor

Is the IPN address set correctly in PayPal?

Biology Forums

Quote from: Arantor on March 03, 2011, 06:36:34 PM
Is the IPN address set correctly in PayPal?

Yes, here is a screenshot of PayPal sandbox. I changed the IPN to the original. After I press send in the sandbox, it should have sent an email, but it didn't :(

Arantor

Does the mod accept sandbox notifications? The implementation in 2.0 as a core feature requires you to explicitly turn it on to use sandbox mode...

Biology Forums

Quote from: Arantor on March 03, 2011, 07:12:53 PM
Does the mod accept sandbox notifications? The implementation in 2.0 as a core feature requires you to explicitly turn it on to use sandbox mode...

Yes, it says:

Enable test mode:

This puts the paid subscriptions mod into "test" mode, which will, whereever possible, use sandbox payment methods in paypal etc. Do not enable unless you know what you are doing!

And I check the button.

I just have a hard time comprehending why it won't work :( Could it be that the sandbox feature isn't working, but in actuality the mod would work with real payments?

Arantor

That seems very likely. Have a read of the mod's thread, see if anyone else has the same problem.

Biology Forums

Quote from: Arantor on March 03, 2011, 07:30:29 PM
That seems very likely. Have a read of the mod's thread, see if anyone else has the same problem.

Yes, one other person, but that was a month ago and he/she only has 2 replies, so I doubt they would reply.

http://www.simplemachines.org/community/index.php?topic=105532.940

Bigguy


Biology Forums

Quote from: Bigguy on April 02, 2011, 06:32:01 PM
Quote from: Bigguy on March 03, 2011, 12:34:50 AM
Did Labradoodle's suggestion work for you. ???

No, the damn mod doesn't work even though its installed properly

Rumbaar

Quote from: shuban on April 04, 2011, 02:55:21 PMNo, the damn mod doesn't work even though its installed properly
Sorry as this relates to a supposedly non working mod, there is little we can do.  Also with the implementation of the subscription into the core of SMF 2 I guess there is little chance it will be fixed.  If it is in fact an issue with the coding and integration into Paypal.

I suggest you plan to upgrade to SMF 2 if you want to implement a subscription option into your forum.
"An important reward for a job well done is a personal sense of worthwhile achievement."

[ Themes ]

Advertisement: