codeKey = CODE_KEY; for ($i = 0; $i < $rand; $i++) { $this->codeKey = str_shuffle($this->codeKey); } $this->scrambleSeed = rand(1, 200); $this->browserNeedsHide = ($sniffer->property("long_name") == "netscape" && $sniffer->property("maj_ver") < 5); } function getCodeKey() { return $this->codeKey; } function getScrambleSeed() { return $this->scrambleSeed; } function setCodeKey($value) { $this->codeKey = $value; } function setScrambleSeed($value) { $this->scrambleSeed = $value; } function EncodeEmail($email) { // find the @ symbol and the following . // if neither exists we don't have a valid email address and don't need to encode it $atSymbol = strpos($email, "@"); if ($atSymbol === false) { $atSymbol = 0; } $stopAt = strrpos($email, "."); if ($stopAt === false || $stopAt < $atSymbol) { $stopAt = strlen($email); } return $this->Encode(substr($email, 0, $stopAt)) . substr($email, $stopAt); } function Encode($s, $codeKey = "", $baseNum = "") { $subtract = true; $scramble = ToCharArray($s); if (!$codeKey) $codeKey = $this->codeKey; if (!$baseNum) $baseNum = $this->scrambleSeed; for ($i = 0; $i < count($scramble); $i++) { // find each character in the code key $char = $scramble[$i]; $index = strpos($codeKey, $char); // if char doesn't exist, skip it if ($index === false) { continue; } // encode the character $index += ($subtract) ? -$baseNum : $baseNum; $baseNum -= ($subtract) ? -$i : $i; while ($index < 0) { $index += strlen($codeKey); } $index %= strlen($codeKey); $scramble[$i] = $codeKey[$index]; $subtract = !$subtract; } // return encoded string $encoded = implode("", $scramble); return $encoded; } function Decode($s, $codeKey = "", $baseNum = "") { $subtract = true; $unscramble = ToCharArray($s); if (!$codeKey) $codeKey = $this->codeKey; if (!$baseNum) $baseNum = $this->scrambleSeed; for ($i = 0; $i < count($unscramble); $i++) { // find each character in the code key $char = $unscramble[$i]; $index = strpos($codeKey, $char); // if char doesn't exist, skip it if ($index === false) { continue; } // Decode the character $index -= ($subtract) ? -$baseNum : $baseNum; $baseNum -= ($subtract) ? -$i : $i; while ($index < 0) { $index += strlen($codeKey); } $index %= strlen($codeKey); $unscramble[$i] = $codeKey[$index]; $subtract = !$subtract; } // return decoded string $decoded = implode("", $unscramble); return $decoded; } function RegisterEmailDecodeScript() { if (!$this->browserNeedsHide) { $storeInnerHtml = << -1) { storeText = storeText.substring(0, findEm) + emAdd + storeText.substring(findEm + emAdd.length, storeText.length); findEm = storeText.indexOf(scramble); } link.innerHTML = storeText; END; } print << function NoSpamEmailHyperlink_DecodeScript(link, seed) { // This is the decoding key for all NoSpamEmailHyperlink_FieldNames objects var ky = "{$this->codeKey}"; $storeInnerHtml // Initialize variables var baseNum = parseInt(seed); var atSym = link.href.indexOf("@"); if (atSym == -1) atSym = 0; var dotidx = link.href.lastIndexOf("."); if (dotidx == -1 || dotidx < atSym) dotidx = link.href.length; var scramble = link.href.substring(7, dotidx); var unscramble = ""; var su = true; // Go through the scrambled section of the address for (i=0; i < scramble.length; i++) { // Find each character in the scramble key string var ch = scramble.substring(i,i + 1); var idx = ky.indexOf(ch); // If it isn't there then add the character // directly to the unscrambled email address if (idx < 0) { unscramble = unscramble + ch; continue; } // Decode the character idx -= (su ? -baseNum : baseNum); baseNum -= (su ? -i : i); while (idx < 0) idx += ky.length; idx %= ky.length; // ... and add it to the unscrambled email address unscramble = unscramble + ky.substring(idx,idx + 1); su = !su; } // Adjust the href property of the link var emAdd = unscramble + link.href.substring(dotidx, link.href.length + 1); link.href = "mailto:" + emAdd; $replaceInnerEmail } var decodeSeed = {$this->scrambleSeed}; END; } } ?>