Compare commits
	
		
			6 Commits
		
	
	
		
			087b4a128e
			...
			cb8c786284
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| cb8c786284 | |||
| 306efa3769 | |||
| 1c86051997 | |||
| 2f68acdfc1 | |||
| 43bc39d425 | |||
| 711bd49048 | 
							
								
								
									
										32
									
								
								.git.template
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								.git.template
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,32 @@ | |||||||
|  | # If applied, this commit will ... | ||||||
|  |  | ||||||
|  | # Why was this change necessary? Improvements brought about by the | ||||||
|  | # change. | ||||||
|  |  | ||||||
|  | # End | ||||||
|  |  | ||||||
|  | # Format | ||||||
|  | # -------------------- | ||||||
|  | # (If applied, this commit will...) <subject> (Max 72 char) | ||||||
|  | # |<----   Preferably using up to 50 chars   --->|<------------------->| | ||||||
|  | # Example: | ||||||
|  | # Implement automated commit messages | ||||||
|  |  | ||||||
|  | # (Optional) Explain why this change is being made | ||||||
|  | # |<----   Try To Limit Each Line to a Maximum Of 72 Characters   ---->| | ||||||
|  |  | ||||||
|  | # (Optional) Provide links or keys to any relevant tickets, articles or other resources | ||||||
|  | # Example: Github issue #23 | ||||||
|  |  | ||||||
|  | # --- COMMIT END --- | ||||||
|  | # | ||||||
|  | # Remember to: | ||||||
|  | #   * Capitalize the subject line | ||||||
|  | #   * Use the imperative mood in the subject line | ||||||
|  | #   * Do not end the subject line with a period | ||||||
|  | #   * Separate subject from body with a blank line | ||||||
|  | #   * Use the body to explain what and why vs. how | ||||||
|  | #   * Can use multiple lines with "-" or "*" for bullet points in body | ||||||
|  | # -------------------- | ||||||
|  |  | ||||||
|  | # Continuous integration messages | ||||||
							
								
								
									
										2
									
								
								.gitattributes
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								.gitattributes
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,2 @@ | |||||||
|  | *.php text eol=lf diff=php | ||||||
|  | *.css text eol=lf diff=css | ||||||
							
								
								
									
										71
									
								
								MD_STD.php
									
									
									
									
									
								
							
							
						
						
									
										71
									
								
								MD_STD.php
									
									
									
									
									
								
							| @@ -340,4 +340,75 @@ final class MD_STD { | |||||||
| 
 | 
 | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /** | ||||||
|  |      * Function for minimizing HTML, trimming each line. | ||||||
|  |      * | ||||||
|  |      * @param string $input Input. | ||||||
|  |      * | ||||||
|  |      * @return string | ||||||
|  |      */ | ||||||
|  |     public static function minimizeHTMLString(string $input):string { | ||||||
|  | 
 | ||||||
|  |         $input = \explode(PHP_EOL, $input); | ||||||
|  |         $output = ""; | ||||||
|  |         foreach ($input as $line) $output .= \trim($line) . PHP_EOL; | ||||||
|  |         return $output; | ||||||
|  | 
 | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * This function cuts down a string and adds a period in case it's longer | ||||||
|  |      * than length to create a snippet. | ||||||
|  |      * | ||||||
|  |      * @param string  $string Input text to cut down. | ||||||
|  |      * @param integer $length Length of the snippet to create. | ||||||
|  |      * | ||||||
|  |      * @return string | ||||||
|  |      */ | ||||||
|  |     public static function createTextSnippet(string $string, int $length = 180):string { | ||||||
|  | 
 | ||||||
|  |         if (\mb_strlen($string) > $length) { | ||||||
|  |             $string  = \mb_substr($string, 0, $length); | ||||||
|  |             if (($lastWhitespace = \mb_strrpos($string, ' ')) !== false) { | ||||||
|  |                 $string = \mb_substr($string, 0, $lastWhitespace); | ||||||
|  |             } | ||||||
|  |             $string .= '...'; | ||||||
|  |         } | ||||||
|  |         return $string; | ||||||
|  | 
 | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Checks if a file exists, with one of the expected mime types. | ||||||
|  |      * | ||||||
|  |      * @param string   $filepath          File path of the file that needs to exist. | ||||||
|  |      * @param string[] $accepted_mimetype Mime type the file should have. | ||||||
|  |      * | ||||||
|  |      * @return void | ||||||
|  |      */ | ||||||
|  |     public static function ensure_file(string $filepath, array $accepted_mimetype = []) { | ||||||
|  | 
 | ||||||
|  |         if (!\file_exists($filepath)) { | ||||||
|  |             throw new MDFileDoesNotExist("File " . basename($filepath) . " does not exist"); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         // Check for mime type follows. If no check is to be done, ignore this.
 | ||||||
|  |         if (empty($accepted_mimetype)) { | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         if (!($finfo = \finfo_open(FILEINFO_MIME_TYPE))) { | ||||||
|  |             throw new Exception("Cannot open finfo context"); | ||||||
|  |         } | ||||||
|  |         if (!($mime_type = finfo_file($finfo, $filepath))) { | ||||||
|  |             throw new MDWrongFileType("Cannot get mime type of file: " . basename($filepath)); | ||||||
|  |         } | ||||||
|  |         \finfo_close($finfo); | ||||||
|  | 
 | ||||||
|  |         if (!\in_array($mime_type, $accepted_mimetype, true)) { | ||||||
|  |             throw new MDWrongFileType("Incorrect mime type of file " . \basename($filepath) . ". Mime type is " . \mime_content_type($filepath) . ", accepted any of ['" . \implode("', '", $accepted_mimetype) . "']"); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |     } | ||||||
|  | 
 | ||||||
| } | } | ||||||
|   | |||||||
| @@ -107,7 +107,7 @@ final class MD_STD_IN { | |||||||
|         else $output = self::sanitize_text($default); |         else $output = self::sanitize_text($default); | ||||||
| 
 | 
 | ||||||
|         if (!empty($allowed) and !\in_array($output, $allowed, true)) { |         if (!empty($allowed) and !\in_array($output, $allowed, true)) { | ||||||
|             Throw new MDpageParameterNotFromListException("Parameter `{$var_name}` must be any of the allowed values: " . implode(', ', $allowed)); |             Throw new MDpageParameterNotFromListException("Parameter `{$var_name}` must be any of the allowed values: '" . implode('\', \'', $allowed) . "'"); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         return $output; |         return $output; | ||||||
| @@ -132,7 +132,7 @@ final class MD_STD_IN { | |||||||
|         else $output = self::sanitize_text($default); |         else $output = self::sanitize_text($default); | ||||||
| 
 | 
 | ||||||
|         if (!empty($allowed) and !\in_array($output, $allowed, true)) { |         if (!empty($allowed) and !\in_array($output, $allowed, true)) { | ||||||
|             Throw new MDpageParameterNotFromListException("Parameter `{$var_name}` must be any of the allowed values: " . implode(', ', $allowed)); |             Throw new MDpageParameterNotFromListException("Parameter `{$var_name}` must be any of the allowed values: '" . implode('\', \'', $allowed) . "'"); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         return $output; |         return $output; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user