Esempio n. 1
0
 function emojifyHTML($text)
 {
     $elementsOpen = array();
     $elementsDepth = 0;
     while (true) {
         $elementFound = preg_match("/<\\s*?([\\/!]?\\w*)(.*?)\\s*?\\>/s", $text, $matches, PREG_OFFSET_CAPTURE, $offsetBytes);
         $element = $matches[0][0];
         $elementName = $matches[1][0];
         $elementText = $matches[2][0];
         $elementOffsetBytes = $elementFound ? $matches[0][1] : strlenb($text);
         $string = substrb($text, $offsetBytes, $elementOffsetBytes - $offsetBytes);
         if ($elementsDepth == 0) {
             $string = $this->emojifyText($string);
         }
         $output .= $string;
         if (!$elementFound) {
             break;
         }
         if (!empty($elementName) && substru($elementText, -1) != '/' && !preg_match("/^(area|br|col|hr|img|input|col|param|!)/i", $elementName)) {
             if ($elementName[0] != '/') {
                 $elementsDepth += $this->isFixedElement($elementName);
                 array_push($elementsOpen, $elementName);
             } else {
                 $elementsDepth -= $this->isFixedElement($elementsOpen[count($elementsOpen) - 1]);
                 array_pop($elementsOpen);
             }
         }
         $output .= $element;
         $offsetBytes = $elementOffsetBytes + strlenb($element);
     }
     return $output;
 }
Esempio n. 2
0
 function verifyHash($text, $algorithm, $hash)
 {
     $hashCalculated = "";
     switch ($algorithm) {
         case "bcrypt":
             if (substrb($hash, 0, 4) == "\$2y\$" || substrb($hash, 0, 4) == "\$2a\$") {
                 $hashCalculated = crypt($text, $hash);
             }
             break;
         case "sha256":
             if (substrb($hash, 0, 4) == "\$5y\$") {
                 $prefix = substrb($hash, 0, 4);
                 $salt = substrb($hash, 4, 32);
                 $hashCalculated = "{$prefix}{$salt}" . hash("sha256", $salt . $text);
             }
             break;
     }
     $ok = !empty($hashCalculated) && strlenb($hashCalculated) == strlenb($hash);
     if ($ok) {
         for ($i = 0; $i < strlenb($hashCalculated); ++$i) {
             $ok &= $hashCalculated[$i] == $hash[$i];
         }
     }
     return $ok;
 }