Ejemplo n.º 1
0
	/**
	 * Interprets the currency-code given as parameter
	 * and defaults to default currency if none.
	 *
	 * @param  string  $currency
	 * @return string
	 */
	public function currency( $currency ) {
		if ( $currency == '' ) {
			$currency					=	$this->params->get( 'currency_code', 'USD' );
		}
		if ( $currency == '' ) {
			$currency					=	'USD';
		}
		return $currency;
	}
 /**
  * USED by XML interface ONLY !!! Renders main currency conversion rates
  *
  * @param  string           $value
  * @param  ParamsInterface  $params
  * @return string                    HTML to display
  */
 public function renderMainRate($value, $params)
 {
     $textCurrency = $params->get('currency_code', 'USD');
     $textSecondaryCurrency = $params->get('secondary_currency_code');
     $price = 1.0;
     // $priceText					=	$this->renderPrice( $price, $textCurrency, true );
     if ($textSecondaryCurrency && $textSecondaryCurrency != $textCurrency) {
         $_CBPAY_CURRENCIES = cbpaidApp::getCurrenciesConverter();
         $secondaryPrice = $_CBPAY_CURRENCIES->convertCurrency($textCurrency, $textSecondaryCurrency, $price);
         if ($secondaryPrice !== null) {
             // we do not want roundings here:
             // $secondaryPriceText	=	$this->renderPrice( $secondaryPrice, $textSecondaryCurrency, true );
             // return $secondaryPriceText . ' / ' . $priceText;
             return sprintf('%s %0.2f / %s %0.2f', $textSecondaryCurrency, $secondaryPrice, $textCurrency, $price);
         } else {
             $error = $_CBPAY_CURRENCIES->getError();
             return '<span style="color:red">' . $error . '</span>';
         }
     }
     return null;
 }
Ejemplo n.º 3
0
	/**
	 * Returns formatted time period ( xxx weeks , or xxx years xxx months xxx days xxx hours xxx minutes xxx seconds
	 *
	 * @param  array|string  $ycdhmsArray  array  of int = list( $years, $months, $days, $hours, $minutes, $seconds ) or SQL DATETIME string
	 * @param  int           $occurrences  [default: 1] multiply period by the occurrences before displaying
	 * @param  boolean       $displayOne   [default: true] displays also if only 1 unit of something
	 * @param  string        $prefix       text between number and period, e.g. 3 calendar months
	 * @return string
	 */
	public function renderPeriod( $ycdhmsArray, $occurrences = 1, $displayOne = true, $prefix = '' ) {
		$text = '';
		if ( $prefix ) {
			$prefix		=	$prefix . ' ';
		}
		if ( ! is_array( $ycdhmsArray ) ) {
			$ycdhmsArray	=	sscanf( $ycdhmsArray, '%d-%d-%d %d:%d:%d');
		}
		list($y, $c, $d, $h, $m, $s) = $ycdhmsArray;

		if ( $occurrences != 1 ) {
			$s *= $occurrences;
			$m *= $occurrences;
			$h *= $occurrences;
			$d *= $occurrences;
			$c *= $occurrences;
			$y *= $occurrences;
			if ( $c && ( ( $c % 12 ) == 0 ) ) {
				$y += $c / 12;
				$c = 0;
			}
		}

		if ( ( $y == 0 ) && ( $c == 0 ) && ( ( $d != 0 ) && ( ( $d % 7 ) == 0 ) ) && ( $h == 0 ) && ( $m == 0 ) && ( $s == 0 )  ) {
			$w = $d / 7;
			if ( $w == 1 ) {
				if ( $displayOne ) {
					$text = $w . ' ';
				}
				$text .= $prefix . CBPTXT::T("week") . ' ';
			} else {
				$text = $w . ' ' . $prefix . CBPTXT::T("weeks") . ' ';
			}
		} else {
			$text  = $y ? ( $y . ' ' . $prefix . ( $y == 1 ? CBPTXT::T("year")	: CBPTXT::T("years")	) ) . ' ' : '';
			$text .= $c ? ( $c . ' ' . $prefix . ( $c == 1 ? CBPTXT::T("month")  : CBPTXT::T("months")  ) ) . ' ' : '';
			$text .= $d ? ( $d . ' ' . $prefix . ( $d == 1 ? CBPTXT::T("day")	: CBPTXT::T("days")	) ) . ' ' : '';
			$text .= $h ? ( $h . ' ' . $prefix . ( $h == 1 ? CBPTXT::T("hour")	: CBPTXT::T("hours")	) ) . ' ' : '';
			$text .= $m ? ( $m . ' ' . $prefix . ( $m == 1 ? CBPTXT::T("minute") : CBPTXT::T("minutes") ) ) . ' ' : '';
			$text .= $s ? ( $s . ' ' . $prefix . ( $s == 1 ? CBPTXT::T("second") : CBPTXT::T("seconds") ) ) . ' ' : '';
			if ($text == '') {
				$text = CBPTXT::T( $this->params->get( 'regtextLifetime', "Lifetime subscription" ) );
			} elseif ( ! $displayOne ) {
				if ( ( ( $y + $c + $d + $h + $m + $s ) == 1 ) && ( substr( $text, 0, 2 ) == '1 ' ) ) {
					$text = substr( $text, 2 );
				}
			}
		}
		return trim( $text );
	}
 /**
  * USED by XML interface ONLY !!! Renders url for the product
  *
  * @param  string           $value    Variable value ( 'massexpire' )
  * @param  ParamsInterface  $params
  * @return string                     HTML to display
  */
 public function renderUrlOfAutoExpiry($value, $params)
 {
     $url = 'index.php?option=com_comprofiler&amp;task=pluginclass&amp;plugin=cbpaidsubscriptions&amp;do=' . htmlspecialchars($value) . '&amp;key=' . md5($params->get('license_number'));
     $url = cbSef($url, true, 'raw');
     return '<a href="' . $url . '" target="_blank">' . $url . '</a>';
 }
 /**
  * USED by XML interface ONLY !!! Renders main currency + amount
  *
  * @param  string           $price
  * @param  ParamsInterface  $params
  * @return string                    HTML to display
  */
 public function renderCurrencyAmount($price, $params)
 {
     return $params->get('currency_code') . '&nbsp;' . $this->renderAmount($price, $params);
 }
	/**
	 * USED by XML interface ONLY !!! Renders amount
	 *
	 * @param  string           $price
	 * @param  ParamsInterface  $params
	 * @return string                    HTML to display
	 */
	public function renderAmount( $price, &$params ) {
		if ( $price ) {
			$cbpaidMoney			=&	cbpaidMoney::getInstance();
			$priceRoundings			=	$params->get('price_roundings', 100 );
			$priceRounded			=	$cbpaidMoney->renderNumber( round( $price * $priceRoundings ) / $priceRoundings );
		} else {
			$priceRounded			= '-';
		}
		return $priceRounded;
	}
 /**
  * View for <param  type="private" class="cbpaidParamsExt" method="opensslstatus">...
  *
  * @param  string              $value                  Stored Data of Model Value associated with the element
  * @param  ParamsInterface     $pluginParams           Main settigns parameters of the plugin
  * @param  string              $name                   Name attribute
  * @param  CBSimpleXMLElement  $param                  This XML node
  * @param  string              $control_name           Name of the control
  * @param  string              $control_name_name      css id-encode of the names of the controls surrounding this node
  * @param  boolean             $view                   TRUE: view, FALSE: edit
  * @param  cbpaidTable         $modelOfData            Data of the Model corresponding to this View
  * @param  cbpaidTable[]       $modelOfDataRows        Displayed Rows if it is a table
  * @param  int                 $modelOfDataRowsNumber  Total Number of rows
  * @return null|string
  */
 public function opensslstatus($value, &$pluginParams, $name, &$param, $control_name, $control_name_name, $view, &$modelOfData, &$modelOfDataRows, &$modelOfDataRowsNumber)
 {
     $return = '';
     $openSSLloaded = extension_loaded('openssl') && defined('OPENSSL_VERSION_TEXT');
     $php430 = version_compare(phpversion(), '4.3.0', '>');
     $openssl_found = false;
     // warning: this is also in base class function _httpsRequest for use
     $path = null;
     if ($php430 && !$openSSLloaded) {
         if (function_exists('is_executable')) {
             $configPath = $pluginParams->get('openssl_exec_path', '/usr/bin/openssl');
             $paths = array('/usr/bin/openssl', '/usr/local/bin/openssl', 'openssl');
             if ($configPath) {
                 array_unshift($paths, $configPath);
             }
             foreach ($paths as $path) {
                 if (@is_executable($path)) {
                     $openssl_found = true;
                     break;
                 }
             }
         }
     }
     $error = null;
     $openssl_version = null;
     if ($openssl_found) {
         $openssl_cmd = $path . ' version';
         $descriptors = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w'));
         $pipes = null;
         $process = @proc_open($openssl_cmd, $descriptors, $pipes);
         // PHP 4.3.0 required for this !
         if (is_resource($process)) {
             //	@fwrite( $pipes[0], $cleartext );
             //	@fflush( $pipes[0] );
             @fclose($pipes[0]);
             $output = '';
             while (!feof($pipes[1])) {
                 $output .= @fgets($pipes[1]);
             }
             $error = '';
             while (!feof($pipes[2])) {
                 $error .= @fgets($pipes[2]);
             }
             $error = trim($error);
             @fclose($pipes[1]);
             @fclose($pipes[2]);
             @proc_close($process);
             $openssl_version = trim($output);
         } else {
             $openssl_found = false;
             $error = "proc_open failed on " . $openssl_cmd;
         }
     }
     if ($openSSLloaded) {
         $return .= $this->_outputGreenRed("OpenSSL PHP module is available with openSSL extension and OpenSSL version: " . OPENSSL_VERSION_TEXT, $openSSLloaded);
     } elseif ($php430 && $openssl_found) {
         $return .= $this->_outputGreenRed(sprintf("openssl executable found at %s, and could be executed: openssl version: %s.", $path, $openssl_version), true, '');
         if ($error) {
             $return .= $this->_outputGreenRed(sprintf("Error during openssl version execution: %s.", $error), false, '', '');
         }
     } else {
         $return .= '<div>--- ' . "All of this:" . ' ---</div>';
         $return .= $this->_outputGreenRed("PHP openSSL module", extension_loaded('openssl'), "loaded", "not available" . ':' . "see PHP manual page for " . '<a href="http://www.php.net/openssl" target="_blank">OpenSSL module</a>');
         $return .= $this->_outputGreenRed("openSSL application library", $openSSLloaded, "found: " . (defined('OPENSSL_VERSION_TEXT') ? constant('OPENSSL_VERSION_TEXT') : "but unknown version"), "not available or not configured. Link for OpenSSL application library: " . '<a href="http://www.openssl.org/" target="_blank">www.openssl.org</a>.' . "See also PHP manual page for " . '<a href="http://www.php.net/openssl" target="_blank">configuring OpenSSL module</a>');
         $return .= '<div>--- ' . "or this:" . ' ---</div>';
         $return .= $this->_outputGreenRed("PHP version is " . phpversion(), $php430, '', "which does not allow proc_open() for executing openssl");
         $return .= $this->_outputGreenRed("openssl executable", $openssl_found, 'found', "not available or not configured. Link for download: " . '<a href="http://www.openssl.org/" target="_blank">http://www.openssl.org/</a>.');
         $return .= '<div>--- ' . "should all be green, for encrypted and signed PayPal payment buttons using X.509 certificates (it will still be working and is not a major security issue)" . ' ---</div>';
     }
     return $return;
 }
Ejemplo n.º 8
0
	/**
	 * USED by XML interface ONLY !!! Renders main currency + amount
	 *
	 * @param  string              $price
	 * @param  ParamsInterface     $params
	 * @param  string              $name    The name of the form element
	 * @param  CBSimpleXMLElement  $node    The xml element for the parameter
	 * @return string                       HTML to display
	 */
	public function renderCurrencyAmount( $price, &$params, /** @noinspection PhpUnusedParameterInspection */ $name, $node ) {
		$currency			=	$node->attributes( 'value' );
		if ( $currency ) {
			$currencyCode	=	$currency;
		} else {
			$currencyCode	=	$params->get( 'currency_code' );
		}
		$renderedAmount		=	$this->renderAmount( $price, $params );
		if ( $renderedAmount != '-' ) {
			return $currencyCode . '&nbsp;' . $renderedAmount;
		} else {
			return '-';
		}
	}
Ejemplo n.º 9
0
	/**
	 * Called at each change of user subscription state due to a plan activation or deactivation
	 *
	 * @param  UserTable        $user
	 * @param  string           $status
	 * @param  int              $planId
	 * @param  int              $replacedPlanId
	 * @param  ParamsInterface  $integrationParams
	 * @param  string           $cause            'PaidSubscription' (first activation only), 'SubscriptionActivated' (renewals, cancellation reversals), 'SubscriptionDeactivated', 'Denied'
	 * @param  string           $reason           'N' new subscription, 'R' renewal, 'U'=update )
	 * @param  int              $now              Unix time
	 * @param  cbpaidSomething  $subscription     Subscription/Donation/Merchandise record
	 * @param  int              $autorenewed      0: not auto-renewing (manually renewed), 1: automatically renewed (if $reason == 'R')
	 */
	public function onCPayUserStateChange( &$user, $status, /** @noinspection PhpUnusedParameterInspection */ $planId, /** @noinspection PhpUnusedParameterInspection */ $replacedPlanId, &$integrationParams, /** @noinspection PhpUnusedParameterInspection */ $cause, /** @noinspection PhpUnusedParameterInspection */ $reason, /** @noinspection PhpUnusedParameterInspection */ $now, &$subscription, /** @noinspection PhpUnusedParameterInspection */ $autorenewed ) {
		if ( ! is_object( $user ) ) {
			return;
		}

		$cbUser							=&	CBuser::getInstance( $user->id );

		if ( ! $cbUser ) {
			$cbUser						=&	CBuser::getInstance( null );
		}

		$extraStrings					=	$subscription->substitutionStrings( false );
		
		for ( $i = 1; $i <= 10; $i++ ) {
			$fieldId					=	$integrationParams->get( 'cbfields_fieldid' . $i, 0 );
			$increment					=	$integrationParams->get( 'cbfields_increment' . $i, 0 );
			$fieldContent				=	$cbUser->replaceUserVars( $integrationParams->get( 'cbfields_contentoffield' . $i, null ), false, false, $extraStrings, false );
			$fieldRemoveOnDeact			=	$integrationParams->get( 'cbfields_removeondeact' . $i, 1 );
			$fieldRemoveContent			=	$integrationParams->get( 'cbfields_removecontent' . $i, 1 );
			$field						=	$this->_getFieldInfo( $fieldId );
			if ( $field !== null ) {
				if ( ( ( $field->type != 'integer' ) && in_array( $increment, array( 1, 2, 3, 4 ) ) ) || ( in_array( $field->type, array( 'multiselect', 'multicheckbox' ) ) && in_array( $increment, array( 5, 6 ) ) ) ) {
					$increment			=	0;
				}

				if ( $status == 'A' ) {
					$this->_addField( $user, $field, $fieldContent, $increment );
				} else {
					if ( $fieldRemoveOnDeact ) {
						$this->_removeField( $user, $field, $fieldContent, $increment, $fieldRemoveContent );
					}
				}
			}
		}
	}
Ejemplo n.º 10
0
 /**
  * Gets table state for items in $rows
  *
  * @param  ParamsInterface  $input  The user form input
  * @param  array            $rows   IN+OUT
  * @return void
  *
  * @throws \UnexpectedValueException
  */
 protected function _getTableStateItems($input, &$rows = array())
 {
     foreach ($rows as $name => $value) {
         $postedValueRaw = $input->get($this->name . '.' . $name, null, GetterInterface::RAW);
         if ($postedValueRaw !== null) {
             $postedValue = null;
             if (!is_array($postedValueRaw)) {
                 $postedValue = $input->get($this->name . '.' . $name, null, GetterInterface::STRING);
             }
             if ($rows[$name]['type'] != 'field_show_only_if_selected' && $rows[$name]['selectValues']) {
                 if (is_array($postedValueRaw)) {
                     // 'field' type:
                     $subInputs = $input->subTree($this->name . '.' . $name);
                     if (!$subInputs->count()) {
                         continue;
                     }
                     $subInputsArray = $subInputs->asArray();
                     if (is_array(array_shift($subInputsArray))) {
                         // Parse Repeat usage:
                         $rows[$name]['valuefield'] = array();
                         $rows[$name]['table'] = array();
                         $rows[$name]['table_key'] = array();
                         $rows[$name]['operator'] = array();
                         $rows[$name]['internalvalue'] = array();
                         $rows[$name]['value'] = array();
                         foreach ($subInputs as $inputColOpVal) {
                             if (!$inputColOpVal instanceof ParamsInterface) {
                                 throw new \UnexpectedValueException('Unexpected inputs in _getTableStateItems');
                             }
                             $column = $inputColOpVal->get('column', null, GetterInterface::STRING);
                             $operator = $inputColOpVal->get('operator', null, GetterInterface::RAW);
                             $value = $inputColOpVal->get('value', null, GetterInterface::STRING);
                             if ($column == '' || $operator == '') {
                                 continue;
                             }
                             if (!in_array($operator, $this->possibleOperators)) {
                                 throw new \UnexpectedValueException('Unexpected operator in _getTableStateItems' . var_dump($_REQUEST[$this->name]));
                             }
                             $internalValue = $value;
                             if (in_array($operator, array('IN', 'NOT IN||ISNULL'))) {
                                 $internalValue = explode(',', $internalValue);
                             }
                             if (in_array($operator, array('LIKE', 'NOT LIKE||ISNULL'))) {
                                 $internalValue = '%' . addcslashes($internalValue, '%_') . '%';
                             }
                             foreach ($rows[$name]['selectValues'] as $selObj) {
                                 if ($column === $selObj->value) {
                                     $rows[$name]['valuefield'][] = isset($selObj->index) ? $selObj->index : $selObj->value;
                                     $rows[$name]['table'] = $selObj->table;
                                     $rows[$name]['table_key'] = $selObj->table_key;
                                     $rows[$name]['operator'][] = $operator;
                                     $rows[$name]['internalvalue'][] = $internalValue;
                                     $rows[$name]['value'][] = array('column' => $column, 'operator' => $operator, 'value' => $value);
                                     break;
                                 }
                             }
                         }
                     } else {
                         // Pase multiselect usage:
                         $values = array();
                         $internalValues = array();
                         // Make sure the values selected are actaully available to the input:
                         foreach ($subInputs as $inputVal) {
                             foreach ($rows[$name]['selectValues'] as $selObj) {
                                 if ($inputVal != '' && $inputVal === $selObj->value) {
                                     $values[] = $selObj->value;
                                     if (isset($selObj->internalvalue) && $selObj->internalvalue !== null) {
                                         $internalValues[] = $selObj->internalvalue;
                                     } else {
                                         $internalValues[] = $selObj->value;
                                     }
                                     break;
                                 }
                             }
                         }
                         $rows[$name]['value'] = $values;
                         $rows[$name]['internalvalue'] = $internalValues;
                     }
                     continue;
                 }
                 // check if value is in possible values list:
                 foreach ($rows[$name]['selectValues'] as $selObj) {
                     if ($postedValue === $selObj->value) {
                         $rows[$name]['value'] = $selObj->value;
                         if (isset($selObj->internalvalue) && $selObj->internalvalue !== null) {
                             $rows[$name]['internalvalue'] = $selObj->internalvalue;
                         } else {
                             $rows[$name]['internalvalue'] = $selObj->value;
                         }
                         if (isset($selObj->operator) && $selObj->operator !== null) {
                             $rows[$name]['operator'] = $selObj->operator;
                         }
                         break;
                     }
                 }
             } else {
                 if (is_array($postedValueRaw)) {
                     // Remove empty string and null as neither are acceptable multiselect filter values:
                     $postedValueRaw = array_filter($postedValueRaw, function ($k) {
                         return $k != '';
                     });
                     $rows[$name]['value'] = $postedValueRaw;
                 } elseif ($rows[$name]['basetype'] == 'int') {
                     $rows[$name]['value'] = (int) $postedValue;
                 } elseif ($rows[$name]['basetype'] == 'float') {
                     $rows[$name]['value'] = (double) $postedValue;
                 } else {
                     $rows[$name]['value'] = $postedValue;
                 }
                 $rows[$name]['internalvalue'] = $rows[$name]['value'];
             }
         }
     }
 }
 /**
  * Cleans the field value by type in a secure way for SQL
  *
  * @param  mixed                          $fieldValue
  * @param  string                         $type           const,sql,param : string,int,float,datetime,formula
  * @param  ParamsInterface                $pluginParams
  * @param  CBdatabase|null                $db
  * @param  array|null                     $extDataModels
  * @return string|boolean                                 STRING: sql-safe value, Quoted or type-casted to int or float, or FALSE in case of type error
  */
 public static function sqlCleanQuote($fieldValue, $type, $pluginParams, &$db = null, $extDataModels = null)
 {
     if ($db === null) {
         global $_CB_database;
         $db =& $_CB_database;
     }
     $typeArray = explode(':', $type, 3);
     if (count($typeArray) < 2) {
         $typeArray = array('const', $type);
     }
     if ($typeArray[0] == 'param') {
         $fieldValue = $pluginParams->get($fieldValue);
     } elseif (in_array($typeArray[0], array('request', 'get', 'post', 'cookie', 'cbcookie', 'session', 'server', 'env'))) {
         $fieldValue = self::_globalConv($typeArray[0], $fieldValue);
     } elseif ($typeArray[0] == 'ext') {
         if (isset($typeArray[2]) && $extDataModels && isset($extDataModels[$typeArray[2]])) {
             if (is_object($extDataModels[$typeArray[2]])) {
                 if (isset($extDataModels[$typeArray[2]]->{$fieldValue})) {
                     $fieldValue = $extDataModels[$typeArray[2]]->{$fieldValue};
                 }
             } elseif (is_array($extDataModels[$typeArray[2]])) {
                 if (isset($extDataModels[$typeArray[2]][$fieldValue])) {
                     $fieldValue = $extDataModels[$typeArray[2]][$fieldValue];
                 }
             } else {
                 $fieldValue = $extDataModels[$typeArray[2]];
             }
         } else {
             trigger_error('SQLXML::sqlCleanQuote: ERROR: ext valuetype "' . htmlspecialchars($type) . '" has not been setExternalDataTypeValues.', E_USER_NOTICE);
         }
         // } elseif ( ( $typeArray[0] == 'const' ) || ( $cnt_valtypeArray[0] == 'sql' ) {
         //	$fieldValue	=	$fieldValue;
     }
     switch ($typeArray[1]) {
         case 'int':
             $value = (int) $fieldValue;
             break;
         case 'float':
             $value = (double) $fieldValue;
             break;
         case 'formula':
             $value = $fieldValue;
             break;
         case 'datetime':
             if (preg_match('/[0-9]{4}-[01][0-9]-[0-3][0-9] [0-2][0-9](:[0-5][0-9]){2}/', $fieldValue)) {
                 $value = $db->Quote($fieldValue);
             } else {
                 $value = "''";
             }
             break;
         case 'date':
             if (preg_match('/[0-9]{4}-[01][0-9]-[0-3][0-9]/', $fieldValue)) {
                 $value = $db->Quote($fieldValue);
             } else {
                 $value = "''";
             }
             break;
         case 'time':
             if (preg_match('/-?[0-9]{1,3}(:[0-5][0-9]){2}/', $fieldValue)) {
                 $value = $db->Quote($fieldValue);
             } else {
                 $value = "''";
             }
             break;
         case 'string':
             $value = $db->Quote($fieldValue);
             break;
         case 'null':
             $value = 'NULL';
             break;
         default:
             trigger_error('SQLXML::sqlCleanQuote: ERROR_UNKNOWN_TYPE: ' . htmlspecialchars($type), E_USER_NOTICE);
             $value = $db->Quote($fieldValue);
             // false;
             break;
     }
     return $value;
 }
Ejemplo n.º 12
0
	/**
	 * Called at each change of user subscription state due to a plan activation or deactivation
	 *
	 * @param  UserTable        $user               The user owning the $subscription with that $planId
	 * @param  string           $status             New status: 'A'=Active, 'X'=Expired, 'C'=Cancelled
	 * @param  int              $planId             Plan Id which is changing status
	 * @param  int              $replacedPlanId     Replaced Plan Id in case of an upgrade
	 * @param  ParamsInterface  $integrationParams  Integration parameters for that plan $planId
	 * @param  string           $cause              'PaidSubscription' (first activation only), 'SubscriptionActivated' (renewals, cancellation reversals), 'SubscriptionDeactivated', 'Denied'
	 * @param  string           $reason             'N' new subscription, 'R' renewal, 'U'=update )
	 * @param  int              $now                Unix time
	 * @param  cbpaidSomething  $subscription       Subscription/Donation/Merchandise record
	 * @param  int              $autorenewed        0: not auto-renewing (manually renewed), 1: automatically renewed (if $reason == 'R')
	 * @return void
	 */
	public function onCPayUserStateChange( $user, $status, /** @noinspection PhpUnusedParameterInspection */ $planId, /** @noinspection PhpUnusedParameterInspection */ $replacedPlanId, $integrationParams, $cause, $reason, /** @noinspection PhpUnusedParameterInspection */ $now, $subscription, $autorenewed ) {
		if ( ! is_object( $user ) ) {
			return;
		}

		$event			=	null;

		if ( ( $status == 'A' ) && ( $cause == 'PaidSubscription' ) && ( $reason != 'R' ) ) {
			$event		=	'activation';
		} elseif ( ( $status == 'A' ) && ( $cause == 'PaidSubscription' ) && ( $reason == 'R' ) && ( $autorenewed == 0 ) ) {
			$event		=	'renewal';
		} elseif ( ( $status == 'A' ) && ( $cause == 'PaidSubscription' ) && ( $reason == 'R' ) && ( $autorenewed == 1 ) ) {
			$event		=	'autorenewal';
		} elseif ( ( $status == 'X' ) && ( $cause != 'Pending' ) ) {
			$event		=	'expired';
		} elseif ( ( $status == 'C' ) && ( $cause != 'Pending' ) ) {
			$event		=	'deactivation';
		} elseif ( ( $cause == 'Pending' ) && ( $reason != 'R' ) && ( $autorenewed == 0 ) ) {
			$event		=	'pendingfirst';
		} elseif ( ( $cause == 'Pending' ) && ( $reason == 'R' ) && ( $autorenewed == 0 ) ) {
			$event		=	'pendingrenewal';
		}

		if ( $event ) {
			$fromName		=	$integrationParams->get( 'cbemail_name_' . $event, null );
			$fromEmail		=	$integrationParams->get( 'cbemail_address_' . $event, null );
			$aTo			=	$integrationParams->get( 'cbemail_to_' . $event, null );
			$aCC			=	$integrationParams->get( 'cbemail_cc_' . $event, null );
			$aBCC			=	$integrationParams->get( 'cbemail_bcc_' . $event, null );
			$aSub			=	$integrationParams->get( 'cbemail_sub_' . $event, null );
			$aMsg			=	$integrationParams->get( 'cbemail_msg_' . $event, null );
			$aAtch			=	$integrationParams->get( 'cbemail_atch_' . $event, null );
			$aType			=	(int) $integrationParams->get( 'cbemail_type_' . $event, 0 );
			$extraStrings	=	$subscription->substitutionStrings( $aType == 1 );
			$this->sendMail( $user, $fromEmail, $fromName, $aTo, $aSub, $aMsg, $aType, $aCC, $aBCC, $aAtch, $extraStrings );
		}
	}
Ejemplo n.º 13
0
	/**
	 * Loads stream default params (from a standardized format) from a params object to override globals
	 *
	 * @param StreamInterface $stream
	 * @param ParamsInterface $params
	 * @param string          $prefix
	 */
	static public function loadStreamDefaults( &$stream, $params, $prefix = null )
	{
		if ( $stream instanceof ActivityInterface ) {
			// Activity
			$paging								=	(string) $params->get( $prefix . 'paging', '' );

			if ( $paging != '' ) {
				$stream->set( 'paging', (int) $paging );
			}

			$limit								=	(string) $params->get( $prefix . 'limit', '' );

			if ( $limit != '' ) {
				$stream->set( 'limit', (int) $limit );
			}

			$createAccess						=	(string) $params->get( $prefix . 'create_access', '' );

			if ( $createAccess != '' ) {
				$stream->set( 'create_access', (int) $createAccess );
			}

			$messageLimit						=	(string) $params->get( $prefix . 'message_limit', '' );

			if ( $messageLimit != '' ) {
				$stream->set( 'message_limit', (int) $messageLimit );
			}

			// Actions
			$actions							=	(string) $params->get( $prefix . 'actions', '' );

			if ( $actions != '' ) {
				$stream->set( 'actions', (int) $actions );
			}

			$actionsMessageLimit				=	(string) $params->get( $prefix . 'actions_message_limit', '' );

			if ( $actionsMessageLimit != '' ) {
				$stream->set( 'actions_message_limit', (int) $actionsMessageLimit );
			}

			// Locations
			$locations							=	(string) $params->get( $prefix . 'locations', '' );

			if ( $locations != '' ) {
				$stream->set( 'locations', (int) $locations );
			}

			$locationsAddressLimit				=	(string) $params->get( $prefix . 'locations_address_limit', '' );

			if ( $locationsAddressLimit != '' ) {
				$stream->set( 'locations_address_limit', (int) $locationsAddressLimit );
			}

			// Links
			$links								=	(string) $params->get( $prefix . 'links', '' );

			if ( $links != '' ) {
				$stream->set( 'links', (int) $links );
			}

			$linksLinkLimit						=	(string) $params->get( $prefix . 'links_link_limit', '' );

			if ( $linksLinkLimit != '' ) {
				$stream->set( 'links_link_limit', (int) $linksLinkLimit );
			}

			// Tags
			$tags								=	(string) $params->get( $prefix . 'tags', '' );

			if ( $tags != '' ) {
				$stream->set( 'tags', (int) $tags );
			}

			// Comments
			$comments							=	(string) $params->get( $prefix . 'comments', '' );

			if ( $comments != '' ) {
				$stream->set( 'comments', (int) $comments );
			}

			$commentsPaging						=	(string) $params->get( $prefix . 'comments_paging', '' );

			if ( $commentsPaging != '' ) {
				$stream->set( 'comments_paging', (int) $commentsPaging );
			}

			$commentsLimit						=	(string) $params->get( $prefix . 'comments_limit', '' );

			if ( $commentsLimit != '' ) {
				$stream->set( 'comments_limit', (int) $commentsLimit );
			}

			$commentsCreateAccess				=	(string) $params->get( $prefix . 'comments_create_access', '' );

			if ( $commentsCreateAccess != '' ) {
				$stream->set( 'comments_create_access', (int) $commentsCreateAccess );
			}

			$commentsMessageLimit				=	(string) $params->get( $prefix . 'comments_message_limit', '' );

			if ( $commentsMessageLimit != '' ) {
				$stream->set( 'comments_message_limit', (int) $commentsMessageLimit );
			}

			// Comment Replies
			$commentsReplies					=	(string) $params->get( $prefix . 'comments_replies', '' );

			if ( $commentsReplies != '' ) {
				$stream->set( 'comments_replies', (int) $commentsReplies );
			}

			$commentsRepliesPaging				=	(string) $params->get( $prefix . 'comments_replies_paging', '' );

			if ( $commentsRepliesPaging != '' ) {
				$stream->set( 'comments_replies_paging', (int) $commentsRepliesPaging );
			}

			$commentsRepliesLimit				=	(string) $params->get( $prefix . 'comments_replies_limit', '' );

			if ( $commentsRepliesLimit != '' ) {
				$stream->set( 'comments_replies_limit', (int) $commentsRepliesLimit );
			}

			$commentsRepliesCreateAccess		=	(string) $params->get( $prefix . 'comments_replies_create_access', '' );

			if ( $commentsRepliesCreateAccess != '' ) {
				$stream->set( 'comments_replies_create_access', (int) $commentsRepliesCreateAccess );
			}

			$commentsRepliesMessageLimit		=	(string) $params->get( $prefix . 'comments_replies_message_limit', '' );

			if ( $commentsRepliesMessageLimit != '' ) {
				$stream->set( 'comments_replies_message_limit', (int) $commentsRepliesMessageLimit );
			}
		} elseif ( $stream instanceof CommentsInterface ) {
			// Comments
			$paging								=	(string) $params->get( $prefix . 'paging', '' );

			if ( $paging != '' ) {
				$stream->set( 'paging', (int) $paging );
			}

			$limit								=	(string) $params->get( $prefix . 'limit', '' );

			if ( $limit != '' ) {
				$stream->set( 'limit', (int) $limit );
			}

			$createAccess						=	(string) $params->get( $prefix . 'create_access', '' );

			if ( $createAccess != '' ) {
				$stream->set( 'create_access', (int) $createAccess );
			}

			$messageLimit						=	(string) $params->get( $prefix . 'message_limit', '' );

			if ( $messageLimit != '' ) {
				$stream->set( 'message_limit', (int) $messageLimit );
			}

			// Comment Replies
			$replies							=	(string) $params->get( $prefix . 'replies', '' );

			if ( $replies != '' ) {
				$stream->set( 'replies', (int) $replies );
			}

			$repliesPaging						=	(string) $params->get( $prefix . 'replies_paging', '' );

			if ( $repliesPaging != '' ) {
				$stream->set( 'replies_paging', (int) $repliesPaging );
			}

			$repliesLimit						=	(string) $params->get( $prefix . 'replies_limit', '' );

			if ( $repliesLimit != '' ) {
				$stream->set( 'replies_limit', (int) $repliesLimit );
			}

			$repliesCreateAccess				=	(string) $params->get( $prefix . 'replies_create_access', '' );

			if ( $repliesCreateAccess != '' ) {
				$stream->set( 'replies_create_access', (int) $repliesCreateAccess );
			}

			$repliesMessageLimit				=	(string) $params->get( $prefix . 'replies_message_limit', '' );

			if ( $repliesMessageLimit != '' ) {
				$stream->set( 'replies_message_limit', (int) $repliesMessageLimit );
			}
		}
	}
Ejemplo n.º 14
0
	/**
	 * Called at each change of user subscription state due to a plan activation or deactivation
	 *
	 * @param  UserTable        $user
	 * @param  string           $status
	 * @param  int              $planId
	 * @param  int              $replacedPlanId
	 * @param  ParamsInterface  $integrationParams
	 * @param  string           $cause              'PaidSubscription' (first activation only), 'SubscriptionActivated' (renewals, cancellation reversals), 'SubscriptionDeactivated', 'Denied'
	 * @param  string           $reason             'N' new subscription, 'R' renewal, 'U'=update
	 * @param  int              $now                Unix time
	 * @param cbpaidSomething   $subscription
	 */
	public function onCPayUserStateChange( &$user, $status, $planId, $replacedPlanId, &$integrationParams, $cause, $reason, /** @noinspection PhpUnusedParameterInspection */ $now, &$subscription ) {
		global $_CB_framework;
		
		if ( ! $user ) {
			return;
		}
		
		$event		=	null;
		
		if ( ( $status == 'A' ) && ( $cause == 'PaidSubscription' ) && ( $reason != 'R' ) ) {
			$event	=	'activation';
		} elseif ( ( $status == 'A' ) && ( $cause == 'PaidSubscription' ) && ( $reason == 'R' ) ) {
			$event	=	'renewal';
		} elseif ( ( $status == 'X' ) && ( $cause != 'Pending' ) ) {
			$event	=	'expiration';
		} elseif ( ( $status == 'C' ) && ( $cause != 'Pending' ) ) {
			$event	=	'deactivation';
		}
		
		if ( $event ) {
			$path									=	$integrationParams->get( 'url_path_' . $event, null );
			$method									=	$integrationParams->get( 'url_method_' . $event, 'GET' );
			$results								=	$integrationParams->get( 'url_results_' . $event, 0 );
			
			if ( $path ) {

				// add substitutions for: [plan_id], [replaced_plan_id], [subscription_id], [parent_plan_id], [parent_subscription_id]
				$extraStringsLocal					=	array(
													'plan_id'					=>	(int) $planId,
													'replaced_plan_id'			=>	(int) $replacedPlanId,
													'subscription_id'			=>	(int) $subscription->id,
													'parent_plan_id'			=>	(int) $subscription->parent_plan,
													'parent_subscription_id'	=>	(int) $subscription->parent_subscription
													);
				$extraStrings						=	array_merge( $subscription->substitutionStrings( false ), $extraStringsLocal );

				cbimport( 'cb.snoopy' );
				
				$cbUser								=&	CBuser::getInstance( $user->id );
				
				if ( ! $cbUser ) {
					return;
				}
				
				$path								=	trim( $cbUser->replaceUserVars( $path, array( $this, '_urlencode' ), false, $extraStrings, false ) );
				$snoopy								=	new CBSnoopy();
				$snoopy->read_timeout				=	30;
				
				switch ($method ) {
					case 'POST':
						$post						=	$integrationParams->get( 'url_post_' . $event, null );
						$formvar					=	array();

						if ( $post ) {
							$formvars				=	explode( "\n", $post );
							foreach ( $formvars as $vars ) {
								$var				=	explode( '=', trim( $vars ), 2 );
								if ( count( $var ) == 2 ) {
									$key			=	trim( $var[0] );
									$value			=	trim( $cbUser->replaceUserVars( $var[1], false, false, $extraStrings, false ) );
									$formvar[$key]	=	$value;
								}
							}
						}
						
						$snoopy->submit( $path, $formvar );
						break;

					case 'XML':
						$xmlText					=	$integrationParams->get( 'url_xml_' . $event, null );
						$xmlText					=	trim( $cbUser->replaceUserVars( $xmlText, array( $this, '_htmlspecialchars' ), false, $extraStrings, false ) );
						$formvar					=	array( 'xml' => $xmlText );
						$snoopy->set_submit_xml();
						$snoopy->submit( $path, $formvar );
						break;

					case 'GET':
					default:
						$snoopy->fetch( $path );
						break;
				}

				if ( $results && ( ! $snoopy->error ) && ( $snoopy->status == 200 ) && $snoopy->results && ( $_CB_framework->getUi() == 1 ) ) {
					// display only in frontend:
					echo '<div class="CBSubsURL_Results_' . (int) $planId . '">' . $snoopy->results . '</div>';
				}
			}
		}
	}