function _preCompile($sData) { $aContinentCodes = MAX_limitationsGetAFromS($sData); $aCountries = array(); foreach ($aContinentCodes as $continentCode) { $aContinentCountries = $this->res[$continentCode]; unset($aContinentCountries[0]); // Remove the name of the continent $aCountries = array_merge($aCountries, $aContinentCountries); } return parent::_preCompile(MAX_limitationsGetSFromA($aCountries)); }
/** * Check to see if this impression contains the valid latitude/longitude. * * @param string $limitation The latitude/longitude limitation * @param string $op The operator (either '==' or '!=') * @param array $aParams An array of additional parameters to be checked * @return boolean Whether this impression's latitude/longitude passes this limitation's test. */ function MAX_checkGeo_Latlong($limitation, $op, $aParams = array()) { if (empty($aParams)) { $aParams = $GLOBALS['_MAX']['CLIENT_GEO']; } if ($aParams && isset($aParams['latitude']) && isset($aParams['longitude'])) { $aRegion = MAX_geoReplaceEmptyWithZero(MAX_limitationsGetAFromS($limitation)); $result = MAX_geoIsPlaceInRegion($aParams['latitude'], $aParams['longitude'], $aRegion); if ($op == '==') { return $result; } else { return !$result; } } else { return $op != '=='; } }
/** * Check to see if this impression contains the valid language. * * @param string $limitation The language limitation * @param string $op The operator * @param array $aParams An array of additional parameters to be checked * @return boolean Whether this impression's language passes this limitation's test. */ function MAX_checkClient_Language($limitation, $op, $aParams = array()) { if (empty($aParams)) { $language = $_SERVER['HTTP_ACCEPT_LANGUAGE']; } else { $language = $aParams['language']; } if ($limitation == '' || empty($language)) { return true; } // Strip off q=X if present $language = preg_replace('/;q=[0-9\\.]+$/', '', $language); $aLimitation = MAX_limitationsGetAFromS($limitation); $aLanguages = MAX_limitationsGetAFromS($language); $aMatchedValues = array_intersect($aLimitation, $aLanguages); if ('=~' == $op) { return !empty($aMatchedValues); } else { return empty($aMatchedValues); } }
/** * An utility function which checks if the array specified in the $value * matches the limitation specified in the $limitation and $op variables. * The $value is supposed to be a single string and $limitation is * a list of values separated by `,' character. * * The function returns true if the $value matches the limitation, * false otherwise. * * The meaning of $op is the following: * <ul> * <li>==: true iff $limitation consists of single value and this value * is exactly the same as $value.</li> * <li>=~: true iff $value is a member of the $limitation array.</li> * <li>!~: true iff $value is not a member of the $limitation array.</li> * </ul> * * @param string $value Value to check against the limitation. * @param string $limitation The limitation specification as a string. * @param string $op The operator to use to apply the limitation. * @return boolean True if the $value matches the limitation, * false otherwise. */ function MAX_limitationsMatchArrayValue($value, $limitation, $op) { $limitation = strtolower($limitation); $value = strtolower($value); $aLimitation = MAX_limitationsGetAFromS($limitation); if ($op == '==') { return count($aLimitation) == 1 && $value == $aLimitation[0]; } elseif ($op == '=~') { return in_array($value, $aLimitation); } else { return !in_array($value, $aLimitation); } }
/** * Returns the compiledlimitation string for this limitation * * @return string */ function compile() { switch ($this->comparison) { case '==': $join = ' && '; break; case '=~': $join = ' || '; break; case '!~': $join = ' || '; break; } $aChannelIds = MAX_limitationsGetAFromS($this->data); if (empty($aChannelIds)) { return 'true'; } $compile = array(); foreach ($aChannelIds as $channelId) { $compile[] = $this->compileData($channelId); } $result .= '(' . implode($join, $compile) . ')'; if ('!~' == $this->comparison) { $result = '!' . $result; } return $result; }
/** * A private method to "expand" a delivery limitation from the string format that * is saved in the database (ie. in the acls or acls_channel table) into its * "expanded" form. * * Expands the string format into an array with the country code in the first * element, and the region codes in the remaining elements. * * @access private * @param string $data An optional, flat form delivery limitation data string. * @return mixed The delivery limitation data in expanded format. */ function _expandData($data = null) { if (is_null($data)) { $data = $this->data; } if (!is_array($data)) { $aData = strlen($data) ? explode('|', $data) : array(); $aRegions = MAX_limitationsGetAFromS($aData[1]); return array_merge(array($aData[0]), $aRegions); } return $data; }
/** * A private method to pre-compile limitaions. * * @access private * @param mixed $data An optional, expanded form delivery limitation. * @return string The delivery limitation in pre-compiled form, with any changes to the format * of the data stored in the database having been made, ready to be used for * either compiling the limitation into final form, or converting the limitation * into SQL form. */ function _preCompile($sData) { $aData = MAX_limitationsGeoCityUnserialize($sData); $sCountry = MAX_limitationsGetCountry($aData); MAX_limitationsSetCountry($aData, MAX_limitationsGetPreprocessedString($sCountry)); $sCities = MAX_limitationsGetSCities($aData); $aCities = MAX_limitationsGetAFromS($sCities); $aCities = MAX_limitationsGetPreprocessedArray($aCities); MAX_limitationsSetSCities($aData, MAX_limitationsGetSFromA($aCities)); return MAX_limitationsGeoCitySerialize($aData); }
function testMax_limitationsGetAFromS() { $this->assertEqual(array('ab', 'cd', 'ef'), MAX_limitationsGetAFromS('ab,cd,ef')); $this->assertEqual(array(), MAX_limitationsGetAFromS('')); $this->assertEqual(array(), MAX_limitationsGetAFromS(null)); }