| 1 |
<?php |
| 2 |
|
| 3 |
namespace passster; |
| 4 |
|
| 5 |
class PS_Helper |
| 6 |
{ |
| 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 |
{ |
| 18 |
$string = ' ' . $string; |
| 19 |
$ini = strpos( $string, $start ); |
| 20 |
if ( $ini == 0 ) { |
| 21 |
return ''; |
| 22 |
} |
| 23 |
$ini += strlen( $start ); |
| 24 |
$len = strpos( $string, $end, $ini ) - $ini; |
| 25 |
return substr( $string, $ini, $len ); |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Preg matches shortcode and return cleaned output. |
| 30 |
* |
| 31 |
* @param string $content given content. |
| 32 |
* |
| 33 |
* @return string |
| 34 |
*/ |
| 35 |
public static function get_shortcode_content( string $content, $password ) : string |
| 36 |
{ |
| 37 |
preg_match( '/\\[passster+.*.".*' . $password . '.*".*?[\\]]/', $content, $matches ); |
| 38 |
preg_match( '/\\[passster+.*."true".*?[\\]]/', $content, $captcha_matches ); |
| 39 |
$string = ''; |
| 40 |
|
| 41 |
if ( isset( $matches ) && !empty($matches) ) { |
| 42 |
foreach ( $matches as $match ) { |
| 43 |
$string = self::get_string_between( $content, $match, '[/passster]' ); |
| 44 |
} |
| 45 |
} elseif ( isset( $captcha_matches ) && !empty($captcha_matches) ) { |
| 46 |
foreach ( $captcha_matches as $ca_match ) { |
| 47 |
$string = self::get_string_between( $content, $ca_match, '[/passster]' ); |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
return $string; |
| 52 |
} |
| 53 |
|
| 54 |
} |