| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | namespace w3l\Holt45; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 4 |  |  | trait Strings { | 
            
                                                                        
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 6 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 7 |  |  |      * Obfuscate string (url-safe and somewhat hard to guess). | 
            
                                                                        
                            
            
                                    
            
            
                | 8 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 9 |  |  |      * @param string $input The text that should be obfuscated | 
            
                                                                        
                            
            
                                    
            
            
                | 10 |  |  |      * @return string Obfuscated string | 
            
                                                                        
                            
            
                                    
            
            
                | 11 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     public static function obfuscateString($input) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |         return bin2hex(base64_encode(strrev($input))); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 15 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |      * Deobfuscate string | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |      * @param string $input Obfuscated string | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |      * @return string Deobfuscated string | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     public static function deobfuscateString($input) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         return strrev(base64_decode(hex2bin($input))); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 26 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |      * Convert <textarea> to [textarea]. | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |      * @param string $html | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |      * @return string | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     public static function textareaEncode($html) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         return preg_replace("/<textarea(.*?)>(.*?)<\/textarea>/is", "[textarea$1]$2[/textarea]", $html); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 37 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |      * Convert [textarea] to <textarea>. | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |      * @param string $html | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |      * @return string | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     public static function textareaDecode($html) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         return preg_replace("/\[textarea(.*?)\](.*?)\[\/textarea\]/is", "<textarea$1>$2</textarea>", $html); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 48 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |      * To replace "Hallo [@var] world" with $value. | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |      * @example replace_string($string, array("val1" => "foo", "val2" => "bar")) | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |      * @param string $langString String containing placeholder. | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |      * @param array $dynamicContent key->value array. | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |      * @return string String with placeholder replaced. | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     public static function replaceString($langString, $dynamicContent = array()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         foreach ($dynamicContent as $k => $v) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |             $langString = str_replace("[@".$k."]", $v, $langString); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         return $langString; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 65 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |      * Creates rainbow-colored text. | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |      * @param string $text Text wanted coloured. | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |      * @return string String with span-tags with color. | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     public static function rainbowText($text) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         $colorsBase = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         array(255, 0, 0), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         array(255, 102, 0), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         array(255, 238, 0), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         array(0, 255, 0), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         array(0, 153, 255), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         array(68, 0, 255), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         array(153, 0, 255) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         $colorsBuild = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         $strlenText = strlen($text); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         if ($strlenText > 7) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |             while (count($colorsBuild) < $strlenText) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |                 for ($i = 0, $size = count($colorsBase); $i < $size; $i++) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |                     $colorsBuild[] = $colorsBase[$i]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |                     if (count($colorsBuild) >= $strlenText) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |                         continue 2; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |                     if ($i < count($colorsBase)-1) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |                         $colorsBuild[] = self::colorBlend($colorsBase[$i], $colorsBase[$i+1]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |                         if (count($colorsBuild) >= $strlenText) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |                             continue 2; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |                         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |                 $colorsBase = $colorsBuild; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |                 $colorsBuild = array(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |         } elseif ($strlenText <= 7) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |             $colorsBuild = $colorsBase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |         $arrayText = str_split($text); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |         $returnText = ""; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |         for ($i = 0, $size = count($arrayText); $i < $size; $i++) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |             $returnText .= '<span style="color: #'.self::rgbhex($colorsBuild[$i]).';">'.$arrayText[$i].'</span>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |         return $returnText; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 121 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 122 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 123 |  |  |  | 
            
                        
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.