Code Duplication    Length = 31-31 lines in 2 locations

typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php 2 locations

@@ 5587-5617 (lines=31) @@
5584
     * @param mixed  $type - either "ascii" or a number between -10 and 10, taken from config.spamProtectEmailAddresses
5585
     * @return string encoded version of $string
5586
     */
5587
    protected function encryptEmail($string, $type)
5588
    {
5589
        $out = '';
5590
        // obfuscates using the decimal HTML entity references for each character
5591
        if ($type === 'ascii') {
5592
            $stringLength = strlen($string);
5593
            for ($a = 0; $a < $stringLength; $a++) {
5594
                $out .= '&#' . ord(substr($string, $a, 1)) . ';';
5595
            }
5596
        } else {
5597
            // like str_rot13() but with a variable offset and a wider character range
5598
            $len = strlen($string);
5599
            $offset = (int)$type;
5600
            for ($i = 0; $i < $len; $i++) {
5601
                $charValue = ord($string[$i]);
5602
                // 0-9 . , - + / :
5603
                if ($charValue >= 43 && $charValue <= 58) {
5604
                    $out .= $this->encryptCharcode($charValue, 43, 58, $offset);
5605
                } elseif ($charValue >= 64 && $charValue <= 90) {
5606
                    // A-Z @
5607
                    $out .= $this->encryptCharcode($charValue, 64, 90, $offset);
5608
                } elseif ($charValue >= 97 && $charValue <= 122) {
5609
                    // a-z
5610
                    $out .= $this->encryptCharcode($charValue, 97, 122, $offset);
5611
                } else {
5612
                    $out .= $string[$i];
5613
                }
5614
            }
5615
        }
5616
        return $out;
5617
    }
5618
5619
    /**
5620
     * Decryption of email addresses for <A>-tags See the spam protection setup in TS 'config.'
@@ 5626-5656 (lines=31) @@
5623
     * @param mixed  $type - either "ascii" or a number between -10 and 10 taken from config.spamProtectEmailAddresses
5624
     * @return string decoded version of $string
5625
     */
5626
    protected function decryptEmail($string, $type)
5627
    {
5628
        $out = '';
5629
        // obfuscates using the decimal HTML entity references for each character
5630
        if ($type === 'ascii') {
5631
            $stringLength = strlen($string);
5632
            for ($a = 0; $a < $stringLength; $a++) {
5633
                $out .= '&#' . ord(substr($string, $a, 1)) . ';';
5634
            }
5635
        } else {
5636
            // like str_rot13() but with a variable offset and a wider character range
5637
            $len = strlen($string);
5638
            $offset = (int)$type * -1;
5639
            for ($i = 0; $i < $len; $i++) {
5640
                $charValue = ord($string[$i]);
5641
                // 0-9 . , - + / :
5642
                if ($charValue >= 43 && $charValue <= 58) {
5643
                    $out .= $this->encryptCharcode($charValue, 43, 58, $offset);
5644
                } elseif ($charValue >= 64 && $charValue <= 90) {
5645
                    // A-Z @
5646
                    $out .= $this->encryptCharcode($charValue, 64, 90, $offset);
5647
                } elseif ($charValue >= 97 && $charValue <= 122) {
5648
                    // a-z
5649
                    $out .= $this->encryptCharcode($charValue, 97, 122, $offset);
5650
                } else {
5651
                    $out .= $string[$i];
5652
                }
5653
            }
5654
        }
5655
        return $out;
5656
    }
5657
5658
    /**
5659
     * Encryption (or decryption) of a single character.