| 1 |
<?php |
| 2 |
|
| 3 |
namespace passster; |
| 4 |
|
| 5 |
class PS_Conditional |
| 6 |
{ |
| 7 |
/** |
| 8 |
* Check if valid authentication exists. |
| 9 |
* |
| 10 |
* @param array $atts array of attributes. |
| 11 |
* @return boolean |
| 12 |
*/ |
| 13 |
public static function is_valid( $atts ) |
| 14 |
{ |
| 15 |
// valid user. |
| 16 |
if ( self::is_user_valid( $atts ) ) { |
| 17 |
return true; |
| 18 |
} |
| 19 |
// valid link. |
| 20 |
if ( self::is_link_valid( $atts ) ) { |
| 21 |
return true; |
| 22 |
} |
| 23 |
// is Cookie set? |
| 24 |
if ( !isset( $_COOKIE['passster'] ) || empty($_COOKIE['passster']) ) { |
| 25 |
return false; |
| 26 |
} |
| 27 |
$input = base64_decode( $_COOKIE['passster'] ); |
| 28 |
// Deactivate encryption? |
| 29 |
$base_encryption = apply_filters( 'passster_disable_base_encryption', false ); |
| 30 |
if ( $base_encryption ) { |
| 31 |
$input = $_COOKIE['passster']; |
| 32 |
} |
| 33 |
// password. |
| 34 |
if ( isset( $atts['password'] ) ) { |
| 35 |
if ( $input == $atts['password'] ) { |
| 36 |
return true; |
| 37 |
} |
| 38 |
} |
| 39 |
// passwords. |
| 40 |
|
| 41 |
if ( isset( $atts['passwords'] ) ) { |
| 42 |
$passwords = explode( ',', str_replace( ' ', '', $atts['passwords'] ) ); |
| 43 |
if ( !empty($passwords) && in_array( $input, $passwords, true ) ) { |
| 44 |
return true; |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
// password lists. |
| 49 |
|
| 50 |
if ( isset( $atts['password_list'] ) ) { |
| 51 |
$passwords_in_list = get_post_meta( $atts['password_list'], 'passster_passwords', true ); |
| 52 |
$passwords_in_list = explode( ',', $passwords_in_list ); |
| 53 |
$expire = get_post_meta( $atts['password_list'], 'passster_expire_passwords', true ); |
| 54 |
|
| 55 |
if ( in_array( $input, $passwords_in_list ) ) { |
| 56 |
self::maybe_expire_password_from_list( $input, $passwords_in_list, $atts['password_list'] ); |
| 57 |
return true; |
| 58 |
} |
| 59 |
|
| 60 |
} |
| 61 |
|
| 62 |
// captcha. |
| 63 |
if ( isset( $atts['captcha'] ) ) { |
| 64 |
if ( 'captcha' == $input ) { |
| 65 |
return true; |
| 66 |
} |
| 67 |
} |
| 68 |
// recaptcha. |
| 69 |
if ( isset( $atts['recaptcha'] ) ) { |
| 70 |
if ( 'recaptcha' == $input ) { |
| 71 |
return true; |
| 72 |
} |
| 73 |
} |
| 74 |
// if nothing was correct. |
| 75 |
return false; |
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* Return user name and role as array |
| 80 |
* |
| 81 |
* @param array $atts added attributes. |
| 82 |
* @return boolean |
| 83 |
*/ |
| 84 |
public static function is_user_valid( $atts ) |
| 85 |
{ |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Check if link is valid. |
| 90 |
* |
| 91 |
* @param array $atts array of attributes. |
| 92 |
* @return boolean |
| 93 |
*/ |
| 94 |
public static function is_link_valid( $atts ) |
| 95 |
{ |
| 96 |
} |
| 97 |
|
| 98 |
/** |
| 99 |
* Maybe expire an password from a list by usage or time. |
| 100 |
* |
| 101 |
* @param string $password given password. |
| 102 |
* @param array $passwords_in_list passwords from list. |
| 103 |
* @return void |
| 104 |
*/ |
| 105 |
public static function maybe_expire_password_from_list( $password, $passwords_in_list, $list_id ) |
| 106 |
{ |
| 107 |
} |
| 108 |
|
| 109 |
} |