/**
  * Replaces [fieldname] by the content of the user row (except for [password])
  *
  * @param  string               $msg
  * @param  UserTable|\stdClass  $row
  * @param  boolean|array        $htmlspecialchars  on replaced values only: FALSE : no htmlspecialchars, TRUE: do htmlspecialchars, ARRAY: callback method
  * @param  boolean              $menuStats
  * @param  array                $extraStrings
  * @param  boolean              $translateLanguage  on $msg only
  * @return string
  */
 function cbReplaceVars($msg, $row, $htmlspecialchars = true, $menuStats = true, $extraStrings = null, $translateLanguage = true)
 {
     if ($extraStrings === null) {
         $extraStrings = array();
     }
     if (isset($row->id) && is_object($row) && $row instanceof UserTable) {
         $cbUser =& CBuser::getInstance($row->id);
     } else {
         $cbUser = new CBuser();
         $cbUser->loadCbRow($row);
     }
     return $cbUser->replaceUserVars($msg, $htmlspecialchars, $menuStats, $extraStrings, $translateLanguage);
 }
/**
 * Replaces [fieldname] by the content of the user row (except for [password])
 *
 * @param  string         $msg
 * @param  stdClass       $row
 * @param  boolean|array  $htmlspecialchars  on replaced values only: FALSE : no htmlspecialchars, TRUE: do htmlspecialchars, ARRAY: callback method
 * @param  boolean        $menuStats
 * @param  array          $extraStrings
 * @param  boolean        $translateLanguage  on $msg only
 * @return string
 */
function cbReplaceVars($msg, &$row, $htmlspecialchars = true, $menuStats = true, $extraStrings = null, $translateLanguage = true)
{
    if ($extraStrings === null) {
        $extraStrings = array();
    }
    if (isset($row->id) && is_object($row) && strtolower(get_class($row)) == 'moscomprofileruser') {
        $cbUser =& CBuser::getInstance($row->id);
    } else {
        $cbUser = new CBuser();
        $cbUser->loadCbRow($row);
    }
    return $cbUser->replaceUserVars($msg, $htmlspecialchars, $menuStats, $extraStrings, $translateLanguage);
}
Exemplo n.º 3
0
 /**
  * Private storage holder of the instances of CBuser
  *
  * @param  int|int[]|UserTable|null   $userOrValidId
  * @return CBuser|null
  */
 private static function &_getOrSetInstance(&$userOrValidId)
 {
     /** @var CBuser[] $instances */
     static $instances = array();
     if (is_int($userOrValidId) && $userOrValidId !== 0) {
         if (!isset($instances[$userOrValidId])) {
             cbimport('cb.tabs');
             if (count(self::$idsToLoad) == 0) {
                 $instances[$userOrValidId] = new CBuser();
                 if (!$instances[$userOrValidId]->load($userOrValidId)) {
                     unset($instances[$userOrValidId]);
                     $null = null;
                     return $null;
                 }
             } else {
                 // Add user to load to list if not already there:
                 self::advanceNoticeOfUsersNeeded(array($userOrValidId));
                 // Loads all users from list:
                 self::loadUsersMatchingIdIntoList(self::$idsToLoad, $instances);
                 self::$idsToLoad = array();
                 if (!isset($instances[$userOrValidId])) {
                     $null = null;
                     return $null;
                 }
             }
         }
         return $instances[$userOrValidId];
     } elseif (is_object($userOrValidId) && isset($userOrValidId->id) && $userOrValidId->id) {
         // overwrite on purpose previous cached user, if any:
         $instances[(int) $userOrValidId->id] = new CBuser();
         $instances[(int) $userOrValidId->id]->loadCbRow($userOrValidId);
         return $instances[(int) $userOrValidId->id];
     } elseif (is_array($userOrValidId)) {
         // Clear cache internal function to free memory in heavy tasks:
         foreach ($userOrValidId as $id) {
             unset($instances[(int) $id]->_cbuser);
             unset($instances[(int) $id]->_cbtabs);
             unset($instances[(int) $id]);
         }
         $null = null;
         return $null;
     } else {
         cbimport('cb.tabs');
         $cbUser = new CBuser();
         if ($userOrValidId instanceof UserTable && !$userOrValidId->get('id')) {
             // Already prepared guest user object; no need to build a new one:
             $cbUser->loadCbRow($userOrValidId);
         } else {
             $cbUser->_cbuser = new UserTable($cbUser->_db);
         }
         return $cbUser;
     }
 }
Exemplo n.º 4
0
	/**
	 * Checks if $this plan matches conditions for $reason
	 *
	 * @param  UserTable  $user             reflecting the user being registered
	 * @param  string     $reason           payment reason: 'N'=new subscription (default), 'R'=renewal, 'U'=update
	 * @param  array      $selectedPlanIds
	 * @return boolean
	 */
	public function checkActivateConditions( $user, $reason, $selectedPlanIds ) {
		global $_POST;

		if ( $this->upgrade_conds && ( $reason == 'U' ) ) {

			if ( $this->upgrade_conds_plans_required && ! self::_anyArrInArr( $selectedPlanIds, self::_cbexplode( $this->upgrade_conds_plans_required ) ) ) {
				// none of required plans is selected simultaneously:
				return false;
			}
			if ( $this->upgrade_conds_plans_disallowing && self::_anyArrInArr( $selectedPlanIds, self::_cbexplode( $this->upgrade_conds_plans_disallowing ) ) ) {
				// any of the plans that are not allowed is selected simultaneously:
				return false;
			}

		} elseif ( $this->reg_conds && ( $reason == 'N' ) ) {

			if ( $this->reg_conds_plans_required && ! self::_anyArrInArr( $selectedPlanIds, self::_cbexplode( $this->reg_conds_plans_required ) ) ) {
				// none of required plans is selected simultaneously:
				return false;
			}
			if ( $this->reg_conds_plans_not_required && self::_anyArrInArr( $selectedPlanIds, self::_cbexplode( $this->reg_conds_plans_not_required ) ) ) {
				// any of the plans that are not allowed is selected simultaneously:
				return false;
			}

			if ( $user ) {
				// display of registration form does not pass $user. But no need to check fields there.
				if ( $user->id ) {
					$cbUser		=	CBuser::getInstance( $user->id );
				} else {
					$cbUser		=	new CBuser();
					$cbUser->loadCbRow( $user );
				}
				if ( $this->reg_conds_fields_required && ! self::_allFieldsInArr( $cbUser, self::_cbexplode( $this->reg_conds_fields_required ) ) ) {
					// not all of required fields are filled-in:
					return false;
				}
				if ( $this->reg_conds_fields_not_required && self::_anyFieldsInArr( $cbUser, self::_cbexplode( $this->reg_conds_fields_not_required ) ) ) {
					// any field that needed to remain empty is not:
					return false;
				}

				$reg_conds_value_1				=	$this->reg_conds_value_1;
				if ( $this->reg_conds_cbfield_1 ) {
					$fieldValue					=	self::_getFieldValue( $cbUser, (int) $this->reg_conds_cbfield_1 );
					$pregStr					=	preg_quote( $reg_conds_value_1, '/' );
					switch ( $this->reg_conds_cbfield_1_operator ) {
						case '=':
							$regexp				=	'/^' . $pregStr . '$/';
							break;
						case '!=':
							$regexp				=	'/^(?!' . $pregStr . ')$/';
							break;
						case '<':
							if ( ( $fieldValue === '' ) || ( $fieldValue === null ) ) {
								return false;
							}
							if ( ! ( $fieldValue < $reg_conds_value_1 ) ) {
								return false;
							}
							$regexp				=	false;
							break;
						case '>':
							if ( ( $fieldValue === '' ) || ( $fieldValue === null ) ) {
								return false;
							}
							if ( ! ( $fieldValue > $reg_conds_value_1 ) ) {
								return false;
							}
							$regexp				=	false;
							break;
						case 'E':
							$regexp				=	'/' . $pregStr . '/';
							break;
						case '!E':
							$regexp				=	'/(?!' . $pregStr . ')/';
							break;
						case 'regexp':
							$regexp				=	$reg_conds_value_1;
							break;
						case '!regexp':
							$regexp				=	preg_replace( '/^\\/(.*)\\/(.*)$/', '/^(?!\\1)$/\\2', $reg_conds_value_1 );
							break;
						case '':
						default:
							$regexp				=	null;
							break;
					}
					if ( $regexp ) {
						if ( ! preg_match( $regexp, $fieldValue ) ) {
							return false;
						}
					}
				}
			}
		}
		return true;
	}