PluginProbe
Passster – Password Protect Pages and Content / 4.2.13
Passster – Password Protect Pages and Content v4.2.13
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.2.13, at inc/class-ps-helper.php

46 lines 1.3 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 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