PluginProbe ʕ •ᴥ•ʔ
Email Encoder – Protect Email Addresses and Phone Numbers / 2.0.5
Email Encoder – Protect Email Addresses and Phone Numbers v2.0.5
2.5.0 2.4.8 trunk 0.10 0.11 0.12 0.20 0.21 0.22 0.30 0.31 0.32 0.40 0.41 0.42 0.50 0.60 0.70 0.71 0.80 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.5 1.5.2 1.51 1.53 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.10 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7
email-encoder-bundle / core / includes / classes / class-email-encoder-bundle-helpers.php
email-encoder-bundle / core / includes / classes Last commit date
class-email-encoder-bundle-ajax.php 6 years ago class-email-encoder-bundle-helpers.php 6 years ago class-email-encoder-bundle-run-admin.php 6 years ago class-email-encoder-bundle-run.php 6 years ago class-email-encoder-bundle-settings.php 6 years ago class-email-encoder-bundle-validate.php 6 years ago index.php 6 years ago
class-email-encoder-bundle-helpers.php
197 lines
1 <?php
2
3 /**
4 * Email_Encoder_Helpers Class
5 *
6 * This class contains all of the available helper functions
7 *
8 * @since 2.0.0
9 */
10
11 /**
12 * The helpers of the plugin.
13 *
14 * @since 2.0.0
15 * @package EEB
16 * @author Ironikus <info@ironikus.com>
17 */
18 class Email_Encoder_Helpers {
19
20 /**
21 * Checks if the parsed param is available on the current site
22 *
23 * @param $param
24 * @return bool
25 */
26 public function is_page( $param ){
27 if( empty( $param ) ){
28 return false;
29 }
30
31 if( isset( $_GET['page'] ) ){
32 if( $_GET['page'] == $param ){
33 return true;
34 }
35 }
36
37 return false;
38 }
39
40 /**
41 * Creates a formatted admin notice
42 *
43 * @param $content - notice content
44 * @param string $type - Status of the specified notice
45 * @param bool $is_dismissible - If the message should be dismissible
46 * @return string - The formatted admin notice
47 */
48 public function create_admin_notice($content, $type = 'info', $is_dismissible = true){
49 if(empty($content))
50 return '';
51
52 /**
53 * Block an admin notice based onn the specified values
54 */
55 $throwit = apply_filters('eeb/helpers/throw_admin_notice', true, $content, $type, $is_dismissible);
56 if(!$throwit)
57 return '';
58
59 if($is_dismissible !== true){
60 $isit = '';
61 } else {
62 $isit = 'is-dismissible';
63 }
64
65
66 switch($type){
67 case 'info':
68 $notice = 'notice-info';
69 break;
70 case 'success':
71 $notice = 'notice-success';
72 break;
73 case 'warning':
74 $notice = 'notice-warning';
75 break;
76 case 'error':
77 $notice = 'notice-error';
78 break;
79 default:
80 $notice = 'notice-info';
81 break;
82 }
83
84 if( is_array( $content ) ){
85 $validated_content = sprintf( __( $content[0], 'email-encoder-bundle' ), $content[1] );
86 } else {
87 $validated_content = __( $content, 'email-encoder-bundle' );
88 }
89
90 ob_start();
91 ?>
92 <div class="notice <?php echo $notice; ?> <?php echo $isit; ?>">
93 <p><?php echo $validated_content; ?></p>
94 </div>
95 <?php
96 $res = ob_get_clean();
97
98 return $res;
99 }
100
101 /**
102 * Formats a specific date to datetime
103 *
104 * @param $date
105 * @return DateTime
106 */
107 public function get_datetime($date){
108 $date_new = date('Y-m-d H:i:s', strtotime($date));
109 $date_new_formatted = new DateTime($date_new);
110
111 return $date_new_formatted;
112 }
113
114 /**
115 * Builds an url out of the mai values
116 *
117 * @param $url - the default url to set the params to
118 * @param $args - the available args
119 * @return string - the url
120 */
121 public function built_url( $url, $args ){
122 if(!empty($args)){
123 $url .= '?' . http_build_query($args);
124 }
125
126 return $url;
127 }
128
129 /**
130 * Get Parameters from URL string
131 *
132 * @param $url - the url
133 *
134 * @return array - the parameters of the url
135 */
136 public function get_parameters_from_url( $url ){
137
138 $parts = parse_url($url);
139
140 parse_str($parts['query'], $url_parameter);
141
142 return empty( $url_parameter ) ? array() : $url_parameter;
143
144 }
145
146 /**
147 * Builds an url out of the main values
148 *
149 * @param $url - the default url to set the params to
150 * @param $args - the available args
151 * @return string - the url
152 */
153 public function get_current_url($with_args = true){
154
155 $current_url = ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] == 'on' ) ? 'https://' : 'http://';
156
157 $host_part = $_SERVER['SERVER_NAME'];
158 if( strpos( $host_part, $_SERVER['HTTP_HOST'] ) === false ){
159
160 //Validate against HTTP_HOST in case SERVER_NAME has no "www" set
161 if( strpos( $_SERVER['HTTP_HOST'], '://www.' ) !== false && strpos( $host_part, '://www.' ) === false ){
162 $host_part = str_replace( '://', '://www.', $host_part );
163 }
164
165 }
166
167 $current_url .= sanitize_text_field( $host_part ) . sanitize_text_field( $_SERVER['REQUEST_URI'] );
168
169 if($with_args){
170 return $current_url;
171 } else {
172 return strtok( $current_url, '?' );
173 }
174 }
175
176 /**
177 * This is the opponent of JavaScripts decodeURIComponent()
178 * @link http://stackoverflow.com/questions/1734250/what-is-the-equivalent-of-javascripts-encodeuricomponent-in-php
179 * @param string $str
180 * @return string
181 */
182 public function encode_uri_components( $content ) {
183 $revert = array( '%21'=>'!', '%2A'=>'*', '%27'=>"'", '%28'=>'(', '%29'=>')' );
184 return strtr( rawurlencode( $content ), $revert );
185 }
186
187 /**
188 * Generate a random bool value
189 *
190 * @return bool
191 */
192 public function get_random_bool(){
193 return ( rand(0,1) == 1 ) ? true : false;
194 }
195
196 }
197