PluginProbe
Passster – Password Protect Pages and Content / 4.0
Passster – Password Protect Pages and Content v4.0
4.3.15 4.3.14 4.3.12 4.3.13 4.3.11 4.3.10 4.3.9 4.3.8 4.3.7 4.3.6 4.3.5 trunk 3.5.4 3.5.5.2 3.5.5.8 3.5.5.9 4.0 4.1.4 4.2.10 4.2.11 4.2.12 4.2.13 4.2.14 4.2.15 4.2.16 All 47 releases
content-protector / inc / class-ps-helper.php

class-ps-helper.php in Passster – Password Protect Pages and Content 4.0, at inc/class-ps-helper.php

54 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 }