| 1 |
<?php |
| 2 |
|
| 3 |
namespace passster; |
| 4 |
|
| 5 |
use Exception; |
| 6 |
class PS_Helper { |
| 7 |
/** |
| 8 |
* Get string between two strings. |
| 9 |
* |
| 10 |
* @param string $string string to find. |
| 11 |
* @param string $start start string. |
| 12 |
* @param string $end end string. |
| 13 |
* |
| 14 |
* @return string |
| 15 |
*/ |
| 16 |
public static function get_string_between( string $string, string $start, string $end ) : string { |
| 17 |
$string = ' ' . $string; |
| 18 |
$ini = strpos( $string, $start ); |
| 19 |
if ( $ini == 0 ) { |
| 20 |
return ''; |
| 21 |
} |
| 22 |
$ini += strlen( $start ); |
| 23 |
$len = strpos( $string, $end, $ini ) - $ini; |
| 24 |
return substr( $string, $ini, $len ); |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* Preg matches shortcode and return cleaned output. |
| 29 |
* |
| 30 |
* @param string $content given content. |
| 31 |
* |
| 32 |
* @return string |
| 33 |
*/ |
| 34 |
public static function get_shortcode_content( string $content, $password ) : string { |
| 35 |
preg_match( '/\\[passster.*password="' . $password . '".*?\\]/', $content, $matches ); |
| 36 |
$string = ''; |
| 37 |
if ( isset( $matches ) && !empty( $matches ) ) { |
| 38 |
foreach ( $matches as $match ) { |
| 39 |
$string = self::get_string_between( $content, $match, '[/passster]' ); |
| 40 |
} |
| 41 |
} |
| 42 |
return $string; |
| 43 |
} |
| 44 |
|
| 45 |
} |
| 46 |
|