/** * Callback function for sorting an array of objects on a key * * @param array &$a An array of objects * @param array &$b An array of objects * * @return integer Comparison status * * @see JArrayHelper::sortObjects() * @since 11.1 */ protected static function _sortObjects(&$a, &$b) { $key = self::$sortKey; for ($i = 0, $count = count($key); $i < $count; $i++) { if (isset(self::$sortDirection[$i])) { $direction = self::$sortDirection[$i]; } if (isset(self::$sortCase[$i])) { $caseSensitive = self::$sortCase[$i]; } if (isset(self::$sortLocale[$i])) { $locale = self::$sortLocale[$i]; } $va = $a->{$key[$i]}; $vb = $b->{$key[$i]}; if ((is_bool($va) || is_numeric($va)) && (is_bool($vb) || is_numeric($vb))) { $cmp = $va - $vb; } elseif ($caseSensitive) { $cmp = JString::strcmp($va, $vb, $locale); } else { $cmp = JString::strcasecmp($va, $vb, $locale); } if ($cmp > 0) { return $direction; } if ($cmp < 0) { return -$direction; } } return 0; }
/** * @group String * @covers JString::strcmp * @dataProvider strcmpData */ public function testStrcmp($string1, $string2, $locale, $expect) { if (substr(php_uname(), 0, 6) == 'Darwin' && $locale != false) { $this->markTestSkipped('Darwin bug prevents foreign conversion from working properly'); } else { $actual = JString::strcmp($string1, $string2, $locale); if ($actual != 0) { $actual = $actual / abs($actual); } $this->assertEquals($expect, $actual); } }
/** * Callback function for sorting an array of objects on a key * * @param array $a An array of objects * @param array $b An array of objects * * @return integer Comparison status * @since 11.1 * @see JArrayHelper::sortObjects() */ protected static function _sortObjects(&$a, &$b) { $params = $GLOBALS['JAH_so']; for ($i = 0, $count = count($params['key']); $i < $count; $i++) { if (isset($params['direction'][$i])) { $direction = $params['direction'][$i]; } if (isset($params['casesensitive'][$i])) { $casesensitive = $params['casesensitive'][$i]; } if (isset($params['locale'][$i])) { $locale = $params['locale'][$i]; } $va = $a->{$params}['key'][$i]; $vb = $b->{$params}['key'][$i]; if ((is_bool($va) or is_numeric($va)) and (is_bool($vb) or is_numeric($vb))) { $cmp = $va - $vb; } elseif ($casesensitive) { $cmp = JString::strcmp($va, $vb, $locale); } else { $cmp = JString::strcasecmp($va, $vb, $locale); } if ($cmp > 0) { return $direction; } if ($cmp < 0) { return -$direction; } } return 0; }
/** * Part of horrible hack for translating non-English words back * to something MySQL will understand. * * @param string $month Original month name * @param bool $abbr Is the month abbreviated * * @return string English month name */ private function _monthToEnglish($month, $abbr = false) { if ($abbr) { if (JString::strcmp($month, FText::_('JANUARY_SHORT')) === 0) { return 'Jan'; } if (JString::strcmp($month, FText::_('FEBRUARY_SHORT')) === 0) { return 'Feb'; } if (JString::strcmp($month, FText::_('MARCH_SHORT')) === 0) { return 'Mar'; } if (JString::strcmp($month, FText::_('APRIL_SHORT')) === 0) { return 'Apr'; } if (JString::strcmp($month, FText::_('MAY_SHORT')) === 0) { return 'May'; } if (JString::strcmp($month, FText::_('JUNE_SHORT')) === 0) { return 'Jun'; } if (JString::strcmp($month, FText::_('JULY_SHORT')) === 0) { return 'Jul'; } if (JString::strcmp($month, FText::_('AUGUST_SHORT')) === 0) { return 'Aug'; } if (JString::strcmp($month, FText::_('SEPTEMBER_SHORT')) === 0) { return 'Sep'; } if (JString::strcmp($month, FText::_('OCTOBER_SHORT')) === 0) { return 'Oct'; } if (JString::strcmp($month, FText::_('NOVEMBER_SHORT')) === 0) { return 'Nov'; } if (JString::strcmp($month, FText::_('DECEMBER_SHORT')) === 0) { return 'Dec'; } } else { if (JString::strcmp($month, FText::_('JANUARY')) === 0) { return 'January'; } if (JString::strcmp($month, FText::_('FEBRUARY')) === 0) { return 'February'; } if (JString::strcmp($month, FText::_('MARCH')) === 0) { return 'March'; } if (JString::strcmp($month, FText::_('APRIL')) === 0) { return 'April'; } if (JString::strcmp($month, FText::_('MAY')) === 0) { return 'May'; } if (JString::strcmp($month, FText::_('JUNE')) === 0) { return 'June'; } if (JString::strcmp($month, FText::_('JULY')) === 0) { return 'July'; } if (JString::strcmp($month, FText::_('AUGUST')) === 0) { return 'August'; } if (JString::strcmp($month, FText::_('SEPTEMBER')) === 0) { return 'September'; } if (JString::strcmp($month, FText::_('OCTOBER')) === 0) { return 'October'; } if (JString::strcmp($month, FText::_('NOVEMBER')) === 0) { return 'November'; } if (JString::strcmp($month, FText::_('DECEMBER')) === 0) { return 'December'; } } return $month; }
/** * Called from paypal at the end of the transaction * * @return void */ public function onIpn() { $config = JFactory::getConfig(); JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_fabrik/tables'); $log = FabTable::getInstance('log', 'FabrikTable'); $log->referring_url = $_SERVER['REQUEST_URI']; $log->message_type = 'fabrik.ipn.start'; $log->message = json_encode($_REQUEST); $log->store(); // Lets try to load in the custom returned value so we can load up the form and its parameters $custom = JRequest::getVar('custom'); list($formid, $rowid, $ipn_value) = explode(":", $custom); // Pretty sure they are added but double add JModel::addIncludePath(COM_FABRIK_FRONTEND . '/models'); $formModel = JModel::getInstance('Form', 'FabrikFEModel'); $formModel->setId($formid); $listModel = $formModel->getlistModel(); $params = $formModel->getParams(); $table = $listModel->getTable(); $db = $listModel->getDb(); $query = $db->getQuery(true); /* $$$ hugh * @TODO shortColName won't handle joined data, need to fix this to use safeColName * (don't forget to change quoteName stuff later on as well) */ $renderOrder = JRequest::getInt('renderOrder'); $ipn_txn_field = (array) $params->get('paypal_ipn_txn_id_element', array()); $ipn_txn_field = FabrikString::shortColName($ipn_txn_field[$renderOrder]); $ipn_payment_field = (array) $params->get('paypal_ipn_payment_element', array()); $ipn_payment_field = FabrikString::shortColName($ipn_payment_field[$renderOrder]); $ipn_field = (array) $params->get('paypal_ipn_element', array()); $ipn_field = FabrikString::shortColName($ipn_field[$renderOrder]); $ipn_status_field = (array) $params->get('paypal_ipn_status_element', array()); $ipn_status_field = FabrikString::shortColName($ipn_status_field[$renderOrder]); $ipn_address_field = (array) $params->get('paypal_ipn_address_element', array()); $ipn_address_field = FabrikString::shortColName($ipn_address_field[$renderOrder]); $w = new FabrikWorker(); $ipn_value = str_replace('[', '{', $ipn_value); $ipn_value = str_replace(']', '}', $ipn_value); $ipn_value = $w->parseMessageForPlaceHolder($ipn_value, $_POST); $email_from = $admin_email = $config->get('mailfrom'); // Read the post from PayPal system and add 'cmd' $req = 'cmd=_notify-validate'; foreach ($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&{$key}={$value}"; } // Post back to PayPal system to validate $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n"; $header .= "Host: www.paypal.com:443\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " . JString::strlen($req) . "\r\n\r\n"; if ($_POST['test_ipn'] == 1) { $paypalurl = 'ssl://www.sandbox.paypal.com'; } else { $paypalurl = 'ssl://www.paypal.com'; } // Assign posted variables to local variables $item_name = JRequest::getVar('item_name'); $item_number = JRequest::getVar('item_number'); $payment_status = JRequest::getVar('payment_status'); $payment_amount = JRequest::getVar('mc_gross'); $payment_currency = JRequest::getVar('mc_currency'); $txn_id = JRequest::getVar('txn_id'); $txn_type = JRequest::getVar('txn_type'); $receiver_email = JRequest::getVar('receiver_email'); $payer_email = JRequest::getVar('payer_email'); $buyer_address = JRequest::getVar('address_status') . ' - ' . JRequest::getVar('address_street') . ' ' . JRequest::getVar('address_zip') . ' ' . JRequest::getVar('address_state') . ' ' . JRequest::getVar('address_city') . ' ' . JRequest::getVar('address_country_code'); $status = 'ok'; $err_msg = ''; if (empty($formid) || empty($rowid)) { $status = 'form.paypal.ipnfailure.custom_error'; $err_msg = "formid or rowid empty in custom: {$custom}"; } else { // @TODO implement a curl alternative as fsockopen is not always available $fp = fsockopen($paypalurl, 443, $errno, $errstr, 30); if (!$fp) { $status = 'form.paypal.ipnfailure.fsock_error'; $err_msg = "fsock error: {$errno};{$errstr}"; } else { fputs($fp, $header . $req); while (!feof($fp)) { $res = fgets($fp, 1024); /* paypal steps (from their docs): * check the payment_status is Completed * check that txn_id has not been previously processed * check that receiver_email is your Primary PayPal email * check that payment_amount/payment_currency are correct * process payment */ if (JString::strcmp($res, "VERIFIED") == 0) { // $$tom This block Paypal from updating the IPN field if the payment status evolves (e.g. from Pending to Completed) // $$$ hugh - added check of status, so only barf if there is a status field, and it is Completed for this txn_id if (!empty($ipn_txn_field) && !empty($ipn_status_field)) { $query->clear(); $query->select($ipn_status_field)->from($table->db_table_name)->where($db->quoteName($ipn_txn_field) . ' = ' . $db->quote($txn_id)); $db->setQuery($query); $txn_result = $db->loadResult(); if (!empty($txn_result)) { if ($txn_result == 'Completed') { if ($payment_status != 'Reversed' && $payment_status != 'Refunded') { $status = 'form.paypal.ipnfailure.txn_seen'; $err_msg = "transaction id already seen as Completed, new payment status makes no sense: {$txn_id}, {$payment_status}"; } } elseif ($txn_result == 'Reversed') { if ($payment_status != 'Canceled_Reversal') { $status = 'form.paypal.ipnfailure.txn_seen'; $err_msg = "transaction id already seen as Reversed, new payment status makes no sense: {$txn_id}, {$payment_status}"; } } } } if ($status == 'ok') { $set_list = array(); if (!empty($ipn_field)) { if (empty($ipn_value)) { $ipn_value = $txn_id; } $set_list[$ipn_field] = $ipn_value; } if (!empty($ipn_txn_field)) { $set_list[$ipn_txn_field] = $txn_id; } if (!empty($ipn_payment_field)) { $set_list[$ipn_payment_field] = $payment_amount; } if (!empty($ipn_status_field)) { $set_list[$ipn_status_field] = $payment_status; } if (!empty($ipn_address_field)) { $set_list[$ipn_address_field] = $buyer_address; } $ipn = $this->getIPNHandler($params, $renderOrder); if ($ipn !== false) { $request = $_REQUEST; $ipn_function = 'payment_status_' . $payment_status; if (method_exists($ipn, $ipn_function)) { $status = $ipn->{$ipn_function}($listModel, $request, $set_list, $err_msg); if ($status != 'ok') { break; } } $txn_type_function = "txn_type_" . $txn_type; if (method_exists($ipn, $txn_type_function)) { $status = $ipn->{$txn_type_function}($listModel, $request, $set_list, $err_msg); if ($status != 'ok') { break; } } } if (!empty($set_list)) { $set_array = array(); foreach ($set_list as $set_field => $set_value) { $set_value = $db->quote($set_value); $set_field = $db->quoteName($set_field); $set_array[] = "{$set_field} = {$set_value}"; } $query->clear(); $query->update($table->db_table_name)->set(implode(',', $set_array))->where($table->db_primary_key . ' = ' . $db->quote($rowid)); $db->setQuery($query); if (!$db->query()) { $status = 'form.paypal.ipnfailure.query_error'; $err_msg = 'sql query error: ' . $db->getErrorMsg(); } } } } elseif (JString::strcmp($res, "INVALID") == 0) { $status = 'form.paypal.ipnfailure.invalid'; $err_msg = 'paypal postback failed with INVALID'; } } fclose($fp); } } $receive_debug_emails = (array) $params->get('paypal_receive_debug_emails'); $receive_debug_emails = $receive_debug_emails[$renderOrder]; $send_default_email = (array) $params->get('paypal_send_default_email'); $send_default_email = $send_default_email[$renderOrder]; if ($status != 'ok') { foreach ($_POST as $key => $value) { $emailtext .= $key . " = " . $value . "\n\n"; } if ($receive_debug_emails == '1') { $subject = $config->get('sitename') . ": Error with PayPal IPN from Fabrik"; JUtility::sendMail($email_from, $email_from, $admin_email, $subject, $emailtext, false); } $log->message_type = $status; $log->message = $emailtext . "\n//////////////\n" . $res . "\n//////////////\n" . $req . "\n//////////////\n" . $err_msg; if ($send_default_email == '1') { $payer_emailtext = "There was an error processing your PayPal payment. The administrator of this site has been informed."; JUtility::sendMail($email_from, $email_from, $payer_email, $subject, $payer_emailtext, false); } } else { foreach ($_POST as $key => $value) { $emailtext .= $key . " = " . $value . "\n\n"; } if ($receive_debug_emails == '1') { $subject = $config->get('sitename') . ': IPN ' . $payment_status; JUtility::sendMail($email_from, $email_from, $admin_email, $subject, $emailtext, false); } $log->message_type = 'form.paypal.ipn.' . $payment_status; $query = $db->getQuery(); $log->message = $emailtext . "\n//////////////\n" . $res . "\n//////////////\n" . $req . "\n//////////////\n" . $query; if ($send_default_email == '1') { $payer_subject = "PayPal success"; $payer_emailtext = "Your PayPal payment was succesfully processed. The PayPal transaction id was {$txn_id}"; JUtility::sendMail($email_from, $email_from, $payer_email, $payer_subject, $payer_emailtext, false); } } $log->message .= "\n IPN custom function = {$ipn_function}"; $log->message .= "\n IPN custom transaction function = {$txn_type_function}"; $log->store(); jexit(); }
/** * @return array * * @dataProvider getStrcmpData * @since 11.2 * @covers JString::strcmp */ public function testStrcmp($string1, $string2, $locale, $expect) { if (substr(php_uname(), 0, 6) == 'Darwin' && $locale != false) { $this->markTestSkipped('Darwin bug prevents foreign conversion from working properly'); } elseif ($locale != false && !setlocale(LC_COLLATE, $locale)) { // If the locale is not available, we can't have to transcode the string and can't reliably compare it. $this->markTestSkipped("Locale {$locale} is not available."); } else { $actual = JString::strcmp($string1, $string2, $locale); if ($actual != 0) { $actual = $actual / abs($actual); } $this->assertEquals($expect, $actual); } }
/** * Called from subscriptions at the end of the transaction * * @return void */ public function onIpn() { $config = JFactory::getConfig(); $log = FabTable::getInstance('log', 'FabrikTable'); $log->referring_url = $_SERVER['REQUEST_URI']; $log->message_type = 'fabrik.ipn.start'; $log->message = json_encode($_REQUEST); $log->store(); // Lets try to load in the custom returned value so we can load up the form and its parameters $custom = JRequest::getVar('custom'); list($formid, $rowid) = explode(":", $custom); // Pretty sure they are added but double add JModel::addIncludePath(COM_FABRIK_FRONTEND . '/models'); $formModel = JModel::getInstance('Form', 'FabrikFEModel'); $formModel->setId($formid); $listModel = $formModel->getlistModel(); $params = $formModel->getParams(); $table = $listModel->getTable(); $db = $listModel->getDb(); $renderOrder = JRequest::getInt('renderOrder'); $ipn_txn_field = 'pp_txn_id'; $ipn_payment_field = 'amount'; $ipn_status_field = 'pp_payment_status'; $w = $this->getWorker(); $email_from = $admin_email = $config->get('mailfrom'); // Read the post from Subscriptions system and add 'cmd' $req = 'cmd=_notify-validate'; foreach ($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $req .= '&' . $key . '=' . $value; } // Post back to Subscriptions system to validate $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n"; $header .= "Host: www.paypal.com:443\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " . JString::strlen($req) . "\r\n\r\n"; /* $test = '{"option":"com_fabrik","task":"plugin.pluginAjax","formid":"22","g":"form","plugin":"subscriptions","method":"ipn","XDEBUG_SESSION_START":"shiny","renderOrder":"2","txn_type":"subscr_signup","subscr_id":"I-YU0M7L86HA4T","last_name":"User","residence_country":"GB","mc_currency":"EUR","item_name":"fabrikar.com Monthly Professional User: professional-recurring-monthly (professional-recurring-monthly)","business":"*****@*****.**","recurring":"1","address_street":"1 Main Terrace","verify_sign":"A4ffosV9eZnI9PfOxrUT6ColxyFXA.HeejgAGPEcuVvbmovNY04R-Or-","payer_status":"unverified","test_ipn":"1","payer_email":"*****@*****.**","address_status":"confirmed","first_name":"Test","receiver_email":"*****@*****.**","address_country_code":"GB","payer_id":"TUCWSC3SURGAN","invoice":"503df6ec03b469.74349485","address_city":"Wolverhampton","reattempt":"1","address_state":"West Midlands","subscr_date":"04:03:28 Aug 29, 2012 PDT","address_zip":"W12 4LQ","custom":"22:6703","charset":"windows-1252","notify_version":"3.5","period3":"1 M","address_country":"United Kingdom","mc_amount3":"40.00","address_name":"Test User","ipn_track_id":"a20981d869e98","Itemid":"77","view":"plugin"}'; $test = JArrayHelper::fromObject(json_decode($test)); echo "<pre>";print_r($test);exit; */ $subscriptionsurl = $_POST['test_ipn'] == 1 ? 'ssl://www.sandbox.paypal.com' : 'ssl://www.paypal.com'; // Assign posted variables to local variables $item_name = JRequest::getVar('item_name'); $item_number = JRequest::getVar('item_number'); $payment_status = JRequest::getVar('payment_status'); $payment_amount = JRequest::getVar('mc_gross'); $payment_currency = JRequest::getVar('mc_currency'); $txn_id = JRequest::getVar('txn_id'); $txn_type = JRequest::getVar('txn_type'); $receiver_email = JRequest::getVar('receiver_email'); $payer_email = JRequest::getVar('payer_email'); $status = 'ok'; $err_msg = ''; if (empty($formid) || empty($rowid)) { $status = 'form.subscriptions.ipnfailure.custom_error'; $err_msg = "formid or rowid empty in custom: {$custom}"; } else { // @TODO implement a curl alternative as fsockopen is not always available $fp = fsockopen($subscriptionsurl, 443, $errno, $errstr, 30); if (!$fp) { $status = 'form.subscriptions.ipnfailure.fsock_error'; $err_msg = "fsock error: {$errno};{$errstr}"; } else { fputs($fp, $header . $req); while (!feof($fp)) { $res = fgets($fp, 1024); /*subscriptions steps (from their docs): * check the payment_status is Completed * check that txn_id has not been previously processed * check that receiver_email is your Primary Subscriptions email * check that payment_amount/payment_currency are correct * process payment */ if (JString::strcmp($res, "VERIFIED") == 0) { $query = $db->getQuery(true); $query->select($ipn_status_field)->from('#__fabrik_subs_invoices')->where($db->quoteName($ipn_txn_field) . ' = ' . $db->quote($txn_id)); $db->setQuery($query); $txn_result = $db->loadResult(); if (!empty($txn_result)) { if ($txn_result == 'Completed') { if ($payment_status != 'Reversed' && $payment_status != 'Refunded') { $status = 'form.subscriptions.ipnfailure.txn_seen'; $err_msg = "transaction id already seen as Completed, new payment status makes no sense: {$txn_id}, {$payment_status}"; } } elseif ($txn_result == 'Reversed') { if ($payment_status != 'Canceled_Reversal') { $status = 'form.subscriptions.ipnfailure.txn_seen'; $err_msg = "transaction id already seen as Reversed, new payment status makes no sense: {$txn_id}, {$payment_status}"; } } } if ($status == 'ok') { $set_list = array(); $set_list[$ipn_txn_field] = $txn_id; $set_list[$ipn_payment_field] = $payment_amount; $set_list[$ipn_status_field] = $payment_status; $ipn = $this->getIPNHandler($params, $renderOrder); if ($ipn !== false) { $request = $_REQUEST; $ipn_function = 'payment_status_' . $payment_status; if (method_exists($ipn, $ipn_function)) { $status = $ipn->{$ipn_function}($listModel, $request, $set_list, $err_msg); if ($status != 'ok') { break; } } $txn_type_function = 'txn_type_' . $txn_type; if (method_exists($ipn, $txn_type_function)) { $status = $ipn->{$txn_type_function}($listModel, $request, $set_list, $err_msg); if ($status != 'ok') { break; } } } if (!empty($set_list)) { $set_array = array(); foreach ($set_list as $set_field => $set_value) { $set_value = $db->quote($set_value); $set_field = $db->quoteName($set_field); $set_array[] = "{$set_field} = {$set_value}"; } $query = $db->getQuery(true); $query->update('#__fabrik_subs_invoices')->set(implode(',', $set_array))->where('id = ' . $db->quote($rowid)); $db->setQuery($query); if (!$db->query()) { $status = 'form.subscriptions.ipnfailure.query_error'; $err_msg = 'sql query error: ' . $db->getErrorMsg(); } } } } elseif (JString::strcmp($res, "INVALID") == 0) { $status = 'form.subscriptions.ipnfailure.invalid'; $err_msg = 'subscriptions postback failed with INVALID'; } } fclose($fp); } } $receive_debug_emails = (array) $params->get('subscriptions_receive_debug_emails'); $receive_debug_emails = $receive_debug_emails[$renderOrder]; $send_default_email = (array) $params->get('subscriptions_send_default_email'); $send_default_email = $send_default_email[$renderOrder]; if ($status != 'ok') { foreach ($_POST as $key => $value) { $emailtext .= $key . " = " . $value . "\n\n"; } if ($receive_debug_emails == '1') { $subject = $config->get('sitename') . ": Error with Fabrik Subscriptions IPN"; JUtility::sendMail($email_from, $email_from, $admin_email, $subject, $emailtext, false); } $log->message_type = $status; $log->message = $emailtext . "\n//////////////\n" . $res . "\n//////////////\n" . $req . "\n//////////////\n" . $err_msg; if ($send_default_email == '1') { $payer_emailtext = "There was an error processing your Subscriptions payment. The administrator of this site has been informed."; JUtility::sendMail($email_from, $email_from, $payer_email, $subject, $payer_emailtext, false); } } else { foreach ($_POST as $key => $value) { $emailtext .= $key . " = " . $value . "\n\n"; } if ($receive_debug_emails == '1') { $subject = $config->get('sitename') . ': IPN ' . $payment_status; JUtility::sendMail($email_from, $email_from, $admin_email, $subject, $emailtext, false); } $log->message_type = 'form.subscriptions.ipn.' . $payment_status; $query = $db->getQuery(); $log->message = $emailtext . "\n//////////////\n" . $res . "\n//////////////\n" . $req . "\n//////////////\n" . $query; if ($send_default_email == '1') { $payer_subject = "Subscriptions success"; $payer_emailtext = "Your Subscriptions payment was succesfully processed. The Subscriptions transaction id was {$txn_id}"; JUtility::sendMail($email_from, $email_from, $payer_email, $payer_subject, $payer_emailtext, false); } } $log->message .= "\n IPN custom function = {$ipn_function}"; $log->message .= "\n IPN custom transaction function = {$txn_type_function}"; $log->store(); jexit(); }
/** * Check for valid payment gateway. * * @param string $gateway * * @return bool */ protected function isValidPaymentGateway($gateway) { $value1 = \JString::strtolower($this->serviceAlias); $value2 = \JString::strtolower($gateway); return (bool) (\JString::strcmp($value1, $value2) === 0); }
<?php $leadingcount = 0; $date = ""; $date_to_print = ""; ?> <?php if (!empty($this->lead_items)) { ?> <?php foreach ($this->lead_items as &$item) { ?> <?php $this->item =& $item; $date_to_print = JString::strcmp($this->item->publish_down, '0000-00-00 00:00:00') == 0 ? $this->item->publish_up : $this->item->publish_down; if (JString::strcmp($date, JHtml::_('date', $date_to_print, JText::_('d/m/Y'))) != 0) { ?> <div class="row"> <div class="col-xs-12 date-line"> <p class="h3"><?php echo JHtml::_('date', $date_to_print, JText::_('d l')); ?> </p> </div> </div> <?php } $date = JHtml::_('date', $date_to_print, JText::_('d/m/Y')); echo $this->loadTemplate('item'); ?> <?php
/** * Called from paypal at the end of the transaction * * @return void */ public function onIpn() { //header('HTTP/1.1 200 OK'); $input = $this->app->input; $mail = JFactory::getMailer(); JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_fabrik/tables'); $this->doLog('fabrik.ipn.start', json_encode($_REQUEST)); // Lets try to load in the custom returned value so we can load up the form and its parameters $custom = $input->get('custom', '', 'string'); list($formId, $rowId, $ipnValue) = explode(":", $custom); // Pretty sure they are added but double add JModelLegacy::addIncludePath(COM_FABRIK_FRONTEND . '/models'); /** @var FabrikFEModelForm $formModel */ $formModel = JModelLegacy::getInstance('Form', 'FabrikFEModel'); $formModel->setId($formId); $listModel = $formModel->getlistModel(); $params = $formModel->getParams(); $table = $listModel->getTable(); $db = $listModel->getDb(); $query = $db->getQuery(true); $testMode = $params->get('paypal_testmode', false); /* $$$ hugh * @TODO shortColName won't handle joined data, need to fix this to use safeColName * (don't forget to change quoteName stuff later on as well) */ $renderOrder = $input->getInt('renderOrder'); $ipnTxnField = (array) $params->get('paypal_ipn_txn_id_element', array()); $ipnTxnField = FabrikString::shortColName($ipnTxnField[$renderOrder]); $ipnPaymentField = (array) $params->get('paypal_ipn_payment_element', array()); $ipnPaymentField = FabrikString::shortColName($ipnPaymentField[$renderOrder]); $ipnField = (array) $params->get('paypal_ipn_element', array()); $ipnField = FabrikString::shortColName($ipnField[$renderOrder]); $ipnStatusField = (array) $params->get('paypal_ipn_status_element', array()); $ipnStatusField = FabrikString::shortColName($ipnStatusField[$renderOrder]); $ipnAddressField = (array) $params->get('paypal_ipn_address_element', array()); $ipnAddressField = FabrikString::shortColName($ipnAddressField[$renderOrder]); $ipnSubscriberIDField = (array) $params->get('paypal_ipn_subscr_id_element', array()); $ipnSubscriberIDField = FabrikString::shortColName($ipnSubscriberIDField[$renderOrder]); $w = new FabrikWorker(); $ipnValue = str_replace('[', '{', $ipnValue); $ipnValue = str_replace(']', '}', $ipnValue); $ipnValue = $w->parseMessageForPlaceHolder($ipnValue, $_POST); $emailFrom = $admin_email = $this->config->get('mailfrom'); // Read the post from PayPal system and add 'cmd' $req = 'cmd=_notify-validate'; foreach ($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&{$key}={$value}"; } if ($_POST['test_ipn'] == 1) { $paypalHost = 'www.sandbox.paypal.com'; } else { $paypalHost = 'www.paypal.com'; } $paypalUrl = 'ssl://' . $paypalHost; // Post back to PayPal system to validate $header = "POST /cgi-bin/webscr HTTP/1.1\r\n"; $header .= "Host: " . $paypalHost . "\r\n"; $header .= "Connection: close\r\n"; $header .= "User-Agent: Fabrik Joomla Plugin\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " . JString::strlen($req) . "\r\n\r\n"; // Assign posted variables to local variables $item_name = $input->get('item_name', '', 'string'); $item_number = $input->get('item_number', '', 'string'); $payment_status = $input->get('payment_status', '', 'string'); $payment_amount = $input->get('mc_gross', '', 'string'); $payment_currency = $input->get('mc_currency', '', 'string'); $txn_id = $input->get('txn_id', '', 'string'); $txn_type = $input->get('txn_type', '', 'string'); $receiver_email = $input->get('receiver_email', '', 'string'); $payer_email = $input->get('payer_email', '', 'string'); $subscr_id = $input->get('subscr_id', '', 'string'); $buyer_address = $input->get('address_status', '', 'string') . ' - ' . $input->get('address_street', '', 'string') . ' ' . $input->get('address_zip', '', 'string') . ' ' . $input->get('address_state', '', 'string') . ' ' . $input->get('address_city', '', 'string') . ' ' . $input->get('address_country_code', '', 'string'); $status = 'form.paypal.ipnfailure.empty'; $errMsg = ''; $fullResponse = array(); if (empty($formId)) { $status = 'form.paypal.ipnfailure.custom_error'; $errMsg = "formid or rowid empty in custom: {$custom}"; } else { // @TODO implement a curl alternative as fsockopen is not always available $fp = fsockopen($paypalUrl, 443, $errno, $errstr, 30); if (!$fp) { $status = 'form.paypal.ipnfailure.fsock_error'; $errMsg = "fsock error: {$errno};{$errstr}"; } else { fputs($fp, $header . $req); while (!feof($fp)) { $res = fgets($fp, 1024); $tres = trim($res); /* paypal steps (from their docs): * check the payment_status is Completed * check that txn_id has not been previously processed * check that receiver_email is your Primary PayPal email * check that payment_amount/payment_currency are correct * process payment */ if (JString::strcmp($tres, "VERIFIED") === 0) { $status = 'ok'; // $$tom This block Paypal from updating the IPN field if the payment status evolves (e.g. from Pending to Completed) // $$$ hugh - added check of status, so only barf if there is a status field, and it is Completed for this txn_id // $$$ hugh - added check for empty $txn_id, which happens on subscr_foo transaction types if (!empty($ipnTxnField) && !empty($ipnStatusField)) { if (!empty($txn_id)) { $query->clear(); $query->select($ipnStatusField)->from($table->db_table_name)->where($db->qn($ipnTxnField) . ' = ' . $db->q($txn_id)); $db->setQuery($query); $txn_result = $db->loadResult(); if (!empty($txn_result)) { if ($txn_result == 'Completed') { if ($payment_status != 'Reversed' && $payment_status != 'Refunded') { $status = 'form.paypal.ipnfailure.txn_seen'; $errMsg = "transaction id already seen as Completed, new payment status makes no sense: {$txn_id}, {$payment_status}"; $this->doLog($status, $errMsg); } } elseif ($txn_result == 'Reversed') { if ($payment_status != 'Canceled_Reversal') { $status = 'form.paypal.ipnfailure.txn_seen'; $errMsg = "transaction id already seen as Reversed, new payment status makes no sense: {$txn_id}, {$payment_status}"; $this->doLog($status, $errMsg); } } } } } else { $this->doLog('form.paypal.ipndebug.ipn_no_txn_fields', "No IPN txn or status fields specified, can't test for reversed, refunded or cancelled"); } if ($status == 'ok') { $set_list = array(); if (!empty($ipnField)) { if (empty($ipnValue)) { $ipnValue = $txn_id; } $set_list[$ipnField] = $ipnValue; } if (!empty($ipnTxnField)) { $set_list[$ipnTxnField] = $txn_id; } if (!empty($ipnPaymentField)) { $set_list[$ipnPaymentField] = $payment_amount; } if (!empty($ipnStatusField)) { $set_list[$ipnStatusField] = $payment_status; } if (!empty($ipnAddressField)) { $set_list[$ipnAddressField] = $buyer_address; } if (!empty($ipnSubscriberIDField)) { $set_list[$ipnSubscriberIDField] = $subscr_id; } $ipn = $this->getIPNHandler($params, $renderOrder); if ($ipn !== false) { $request = $_REQUEST; $ipnFunction = 'payment_status_' . $payment_status; if (method_exists($ipn, $ipnFunction)) { $status = $ipn->{$ipnFunction}($listModel, $request, $set_list, $errMsg); if ($status != 'ok') { $this->doLog('form.paypal.ipndebug.ipn_function_not_ok', "The IPN function {$ipnFunction} did not return ok"); break; } } $txnTypeFunction = "txn_type_" . $txn_type; if (method_exists($ipn, $txnTypeFunction)) { $status = $ipn->{$txnTypeFunction}($listModel, $request, $set_list, $errMsg); if ($status != 'ok') { $this->doLog('form.paypal.ipndebug.ipn_txn_type_function_not_ok', "The IPN txn type function {$txnTypeFunction} did not return ok"); break; } } } else { $this->doLog('form.paypal.ipndebug.ipn_cannot_load', "Can't load the custom IPN handler class"); } if (!empty($set_list)) { /** * The txn_id can be empty if this is a subscription update, in which case * don't do any automagic updating, user has to deal with it in custom IPN handler */ if (!empty($txn_id)) { $setArray = array(); foreach ($set_list as $setField => $setValue) { $setValue = $db->q($setValue); $setField = $db->qn($setField); $setArray[] = "{$setField} = {$setValue}"; } $query->clear(); $query->update($table->db_table_name)->set(implode(',', $setArray))->where($table->db_primary_key . ' = ' . $db->q($rowId)); $db->setQuery($query); if (!$db->execute()) { $this->doLog($status, $errMsg); } else { if ($testMode == 1) { $this->doLog('form.paypal.ipndebug.ipn_query', "IPN query: " . $query); } } } } else { $status = 'form.paypal.ipnfailure.set_list_empty'; $errMsg = 'no IPN status fields found on form for rowid: ' . $rowId; $this->doLog($status, $errMsg); } } } elseif (JString::strcmp($tres, "INVALID") === 0) { $status = 'form.paypal.ipnfailure.invalid'; $errMsg = 'paypal postback failed with INVALID'; $this->doLog($status, $errMsg); } $fullResponse[] = $res; } fclose($fp); } } $receive_debug_emails = (array) $params->get('paypal_receive_debug_emails'); $receive_debug_emails = $receive_debug_emails[$renderOrder]; $send_default_email = (array) $params->get('paypal_send_default_email'); $send_default_email = $send_default_email[$renderOrder]; $emailText = ''; $logMsgType = ''; $logMsg = ''; if (!strstr($status, 'silent')) { if ($status !== 'ok') { if ($receive_debug_emails == '1') { foreach ($_POST as $key => $value) { $emailText .= $key . " = " . $value . "\n\n"; } $subject = $this->config->get('sitename') . ": Error with PayPal IPN from Fabrik"; $mail->sendMail($emailFrom, $emailFrom, $admin_email, $subject, $emailText, false); } $logMsgType = $status; $logMsg = $emailText . "\n//////////////\n" . implode("", $fullResponse) . "\n//////////////\n" . $req . "\n//////////////\n" . $errMsg; if ($send_default_email == '1') { $subject = $this->config->get('sitename') . ": Error with PayPal IPN from Fabrik"; $payerEmailText = FText::_('PLG_FORM_PAYPAL_ERR_PROCESSING_PAYMENT'); $mail->sendMail($emailFrom, $emailFrom, $payer_email, $subject, $payerEmailText, false); } } else { if ($receive_debug_emails == '1') { foreach ($_POST as $key => $value) { $emailText .= $key . " = " . $value . "\n\n"; } $subject = $this->config->get('sitename') . ': IPN ' . $payment_status; $mail->sendMail($emailFrom, $emailFrom, $admin_email, $subject, $emailText, false); } $logMsgType = 'form.paypal.ipn.'; $logMsgType .= empty($payment_status) ? $txn_type : $payment_status; $query = $db->getQuery(); $logMsg = $emailText . "\n//////////////\n" . $res . "\n//////////////\n" . $req . "\n//////////////\n" . $query; if ($send_default_email == '1') { $payer_subject = "PayPal success"; $payerEmailText = "Your PayPal payment was succesfully processed. The PayPal transaction id was {$txn_id}"; $mail->sendMail($emailFrom, $emailFrom, $payer_email, $payer_subject, $payerEmailText, false); } } } $logMsg .= "\n IPN custom function = {$ipnFunction}"; $logMsg .= "\n IPN custom transaction function = {$txnTypeFunction}"; $this->doLog($logMsgType, $logMsg); jexit(); }
public static function isDefaultLanguage() { $lang = JFactory::getLanguage(); if (JString::strcmp($lang->getDefault(), $lang->getTag()) === 0) { return true; } return false; }
/** * @group String * @covers JString::strcmp * @dataProvider strcmpData */ public function testStrcmp($string1, $string2, $locale, $expect) { $actual = JString::strcmp ($string1, $string2, $locale); if ($actual != 0) { $actual = $actual/abs($actual); } $this->assertEquals($expect, $actual); }
/** * Called from subscriptions at the end of the transaction * * TO test the IPN you can login to your paypal acc, and go to history -> IPN History * then use the 'Notification URL' along with the 'IPN Message' as the querystring * PLUS "&fakeit=1" * * @return void */ public function onIpn() { $input = $this->app->input; JLog::add($input->server->getString('REQUEST_URI') . ' ' . http_build_query($_REQUEST), JLog::INFO, 'fabrik.ipn.start'); // Lets try to load in the custom returned value so we can load up the form and its parameters $custom = $input->get('custom', '', 'string'); list($formId, $invoiceId) = explode(':', $custom); $input->set('invoiceid', $invoiceId); $mail = JFactory::getMailer(); // Pretty sure they are added but double add JModelLegacy::addIncludePath(COM_FABRIK_FRONTEND . '/models'); $formModel = JModelLegacy::getInstance('Form', 'FabrikFEModel'); $formModel->setId($formId); $listModel = $formModel->getlistModel(); $params = $formModel->getParams(); $table = $listModel->getTable(); $db = $listModel->getDb(); $renderOrder = $input->getInt('renderOrder'); $ipn_txn_field = 'pp_txn_id'; $ipn_payment_field = 'amount'; $ipn_status_field = 'pp_payment_status'; $w = $this->getWorker(); $email_from = $adminEmail = $this->config->get('mailfrom'); // Read the post from Subscriptions system and add 'cmd' $req = 'cmd=_notify-validate'; // For $fake = $input->getInt('fakeit'); if ($fake == 1) { $request = $_GET; } else { $request = $_POST; } foreach ($request as $key => $value) { if ($key !== 'fakeit') { $value = urlencode(stripslashes($value)); $req .= '&' . $key . '=' . $value; } } $sandBox = $input->get('test_ipn') == 1; // Post back to Paypal to validate $header = "POST /cgi-bin/webscr HTTP/1.0\r\n"; $header .= $sandBox ? "Host: www.sandbox.paypal.com:443\r\n" : "Host: www.paypal.com:443\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " . JString::strlen($req) . "\r\n\r\n"; $subscriptionsurl = $sandBox ? 'ssl://www.sandbox.paypal.com' : 'ssl://www.paypal.com'; // Assign posted variables to local variables $item_name = $input->get('item_name', '', 'string'); $item_number = $input->get('item_number', '', 'string'); $payment_status = $input->get('payment_status', '', 'string'); $payment_amount = $input->get('mc_gross', '', 'string'); $payment_currency = $input->get('mc_currency', '', 'string'); $txn_id = $input->get('txn_id', '', 'string'); $txn_type = $input->get('txn_type', '', 'string'); $receiver_email = $input->get('receiver_email', '', 'string'); $payer_email = $input->get('payer_email', '', 'string'); $status = true; $res = 'IPN never fired'; $err_msg = ''; $err_title = ''; if (empty($formId) || empty($invoiceId)) { $status = false; $err_title = 'form.subscriptions.ipnfailure.custom_error'; $err_msg = "formid or rowid empty in custom: {$custom}"; } else { // @TODO implement a curl alternative as fsockopen is not always available $fp = fsockopen($subscriptionsurl, 443, $errno, $errstr, 30); if (!$fp) { $status = false; $err_title = 'form.subscriptions.ipnfailure.fsock_error'; $err_msg = "fsock error: {$errno};{$errstr}"; } else { fputs($fp, $header . $req); while (!feof($fp)) { $res = fgets($fp, 1024); /*subscriptions steps (from their docs): * check the payment_status is Completed * check that txn_id has not been previously processed * check that receiver_email is your Primary Subscriptions email * check that payment_amount/payment_currency are correct * process payment */ if (JString::strcmp(strtoupper($res), "VERIFIED") == 0) { $query = $db->getQuery(true); $query->select($ipn_status_field)->from('#__fabrik_subs_invoices')->where($db->quoteName($ipn_txn_field) . ' = ' . $db->quote($txn_id)); $db->setQuery($query); $txn_result = $db->loadResult(); if ($txn_type == 'subscr_signup') { // Just a notification - no payment yet } else { if (!empty($txn_result) && $txn_type != 'subscr_signup') { if ($txn_result == 'Completed') { if ($payment_status != 'Reversed' && $payment_status != 'Refunded') { $status = false; $err_title = 'form.subscriptions.ipnfailure.txn_seen'; $err_msg = "transaction id already seen as Completed, new payment status makes no sense: {$txn_id}, {$payment_status}" . (string) $query; } } elseif ($txn_result == 'Reversed') { if ($payment_status != 'Canceled_Reversal') { $status = false; $err_title = 'form.subscriptions.ipnfailure.txn_seen'; $err_msg = "transaction id already seen as Reversed, new payment status makes no sense: {$txn_id}, {$payment_status}"; } } } if ($status) { $set_list = array(); $set_list[$ipn_txn_field] = $txn_id; $set_list[$ipn_payment_field] = $payment_amount; $set_list[$ipn_status_field] = $payment_status; $ipn = $this->getIPNHandler($params, $renderOrder); if ($ipn !== false) { $request = $_REQUEST; $ipn_function = 'payment_status_' . $payment_status; if (method_exists($ipn, $ipn_function)) { $status = $ipn->{$ipn_function}($listModel, $request, $set_list, $err_msg); if ($status == false) { break; } } else { $txn_type_function = 'txn_type_' . $txn_type; if (method_exists($ipn, $txn_type_function)) { $status = $ipn->{$txn_type_function}($listModel, $request, $set_list, $err_msg); if ($status == false) { break; } } } } if (!empty($set_list)) { $set_array = array(); foreach ($set_list as $set_field => $set_value) { $set_value = $db->quote($set_value); $set_field = $db->quoteName($set_field); $set_array[] = "{$set_field} = {$set_value}"; } $query = $db->getQuery(true); $query->update('#__fabrik_subs_invoices')->set(implode(',', $set_array))->where('id = ' . $db->quote($invoiceId)); $db->setQuery($query); if (!$db->execute()) { $status = false; $err_title = 'form.subscriptions.ipnfailure.query_error'; $err_msg = 'sql query error: ' . $db->getErrorMsg(); } } } } } elseif (JString::strcmp($res, "INVALID") == 0) { $status = false; $err_title = 'form.subscriptions.ipnfailure.invalid'; $err_msg = 'subscriptions postback failed with INVALID'; } } fclose($fp); } } $receive_debug_emails = (array) $params->get('subscriptions_receive_debug_emails'); $send_default_email = (array) $params->get('subscriptions_send_default_email'); $emailtext = ''; foreach ($_POST as $key => $value) { $emailtext .= $key . " = " . $value . "\n\n"; } $logLevel = JLog::INFO; $logMessage = "transaction type: {$txn_type} \n///////////////// \n emailtext: " . $emailtext . "\n//////////////\nres= " . $res . "\n//////////////\n" . $req . "\n//////////////\n"; if ($status == false) { $logLevel = JLog::CRITICAL; $subject = $this->config->get('sitename') . ": Error with Fabrik Subscriptions IPN"; $logMessageTitle = $err_title; $logMessage .= $err_msg; $payer_emailtext = "There was an error processing your Subscriptions payment. The administrator of this site has been informed."; } else { $subject = $this->config->get('sitename') . ': IPN ' . $payment_status; $logMessageTitle = 'form.subscriptions.ipn.' . $payment_status; $payer_subject = "Subscriptions success"; $payer_emailtext = "Your Subscriptions payment was successfully processed. The Subscriptions transaction id was {$txn_id}"; } if ($receive_debug_emails == '1') { $mail->sendMail($email_from, $email_from, $adminEmail, $subject, $emailtext, false); } if ($send_default_email == '1') { $mail->sendMail($email_from, $email_from, $payer_email, $payer_subject, $payer_emailtext, false); } if (isset($ipn_function)) { $logMessage .= "\n IPN custom function = {$ipn_function}"; } else { $logMessage .= "\n No IPN custom function"; } if (isset($txn_type_function)) { $logMessage .= "\n IPN custom transaction function = {$txn_type_function}"; } else { $logMessage .= "\n No IPN custom transaction function "; } JLog::add($logMessage, $logLevel, $logMessageTitle); jexit(); }
<?php /** * @package Joomla.Site * @subpackage Layout * * @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; // Create a shortcut for params. $params = $this->item->params; $images = json_decode($this->item->images); $urls = json_decode($this->item->urls); $date_to_print = JString::strcmp($this->item->publish_down, '0000-00-00 00:00:00') == 0 ? $this->item->publish_up : $this->item->publish_down; ?> <div class="list-course row"> <div class="col-xs-12 col-sm-2 time"> <p class="h4"><time datetime="<?php echo JHtml::_('date', $date_to_print, 'c'); ?> " itemprop="datePublished"> <?php echo JHtml::_('date', $date_to_print, JText::_('H:i')); ?> </time></p> </div> <div class="col-xs-12 col-sm-6 title"> <p class="h4"><?php echo $this->item->title;