PluginProbe ʕ •ᴥ•ʔ
Products Compare for WooCommerce / 3.6.2.6
Products Compare for WooCommerce v3.6.2.6
3.6.2.8 3.6.2.7 trunk 1.0.1 1.0.10 1.0.10.1 1.0.11 1.0.11.1 1.0.12 1.0.13 1.0.13.1 1.0.2 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 3.5 3.5.0.1 3.5.0.2 3.5.1 3.5.1.1 3.5.1.2 3.5.1.3 3.5.1.4 3.5.1.5 3.5.1.6 3.5.1.7 3.5.2 3.5.2.1 3.5.2.2 3.5.2.3 3.5.3 3.5.4 3.5.5 3.5.6 3.5.7 3.5.7.1 3.5.7.2 3.5.7.3 3.5.7.4 3.5.7.5 3.5.7.6 3.5.7.7 3.5.7.8 3.5.7.9 3.5.8 3.5.9 3.6.0 3.6.1 3.6.2 3.6.2.1 3.6.2.2 3.6.2.3 3.6.2.4 3.6.2.5 3.6.2.6
products-compare-for-woocommerce / berocket / includes / information_notices.php
products-compare-for-woocommerce / berocket / includes Last commit date
admin 2 months ago custom_post 2 months ago admin_notices.php 2 months ago conditions.php 2 months ago custom_post.php 2 months ago error_notices.php 2 months ago functions.php 2 months ago ico.png 2 months ago information_notices.php 2 months ago libraries.php 2 months ago plugin-variation.php 2 months ago settings_fields.php 2 months ago updater.php 2 months ago widget.php 2 months ago
information_notices.php
199 lines
1 <?php
2 /*new berocket_information_notices(array(
3 'start' => 1497880000, // timestamp when notice start
4 'end' => 1497885000, // timestamp when notice end
5 'name' => 'name', //notice name must be unique for this time period
6 'html' => '', //text or html code as content of notice
7 'righthtml' => '<a class="berocket_no_thanks">No thanks</a>', //content in the right block, this is default value. This html code must be added to all notices
8 'rightwidth' => 80, //width of right content is static and will be as this value. berocket_no_thanks block is 60px and 20px is additional
9 'nothankswidth' => 60, //berocket_no_thanks width. set to 0 if block doesn't uses. Or set to any other value if uses other text inside berocket_no_thanks
10 'contentwidth' => 400, //width that uses for mediaquery is image_width + contentwidth + rightwidth
11 'subscribe' => false, //add subscribe form to the righthtml
12 'priority' => 20, //priority of notice. 1-5 is main priority and displays on settings page always
13 'height' => 50, //height of notice. image will be scaled
14 'repeat' => false, //repeat notice after some time. time can use any values that accept function strtotime
15 'repeatcount' => 1, //repeat count. how many times notice will be displayed after close
16 'image' => array(
17 'global' => 'http://berocket.com/images/logo-2.png', //image URL from other site. Image will be copied to uploads folder if it possible
18 //'local' => 'http://wordpress-site.com/wp-content/uploads/logo-2.png', //notice will be used this image directly
19 ),
20 ));*/
21 //delete_option('berocket_information_notices'); //remove all notice information
22 //delete_option('berocket_last_close_notices_time'); //remove wait time before next notice
23 //delete_option('berocket_admin_notices_rate_stars');
24 if ( ! class_exists( 'berocket_information_notices' ) ) {
25 /**
26 * Class berocket_information_notices
27 */
28 class berocket_information_notices {
29 public static $notice_index = 10000;
30 public static $default_notice_options = array(
31 'name' => 'sale',
32 'html' => '',
33 'type' => 'info',
34 'righthtml' => '<span class="berocket-notice-dismiss notice-dismiss berocket_no_thanks" role="button" tabindex="0">
35 <span class="screen-reader-text">
36 <input class="berocket-notice-dismiss-check" type="checkbox" value="1">Dismiss this notice.
37 </span>
38 </span>',
39 'rightwidth' => 80,
40 'nothankswidth' => 60,
41 'contentwidth' => 400,
42 'closed' => '0',
43 'priority' => 20,
44 'height' => 50,
45 'image' => array(
46 'global' => ''
47 ),
48 );
49
50 function __construct( $options = array() ) {
51 if ( ! is_admin() ) {
52 return;
53 }
54 $options = array_merge( self::$default_notice_options, $options );
55 self::set_notice_by_path( $options );
56 }
57
58 public static function set_notice_by_path( $options, $replace = false, $find_names = false ) {
59 $notices = get_option( 'berocket_information_notices' );
60 if ( ! is_array( $notices ) ) {
61 $notices = array();
62 }
63
64 if ( empty( $options['image'] ) || ( empty( $options['image']['local'] ) && empty( $options['image']['global'] ) ) ) {
65 $options['image'] = array( 'width' => 0, 'height' => 0, 'scale' => 0 );
66 } else {
67 $file_exist = false;
68 if ( ! $file_exist ) {
69 if ( ! empty( $options['image']['local'] ) ) {
70 $img_local = $options['image']['local'];
71 $img_local = str_replace( site_url( '/' ), '', $img_local );
72 $img_local = ABSPATH . $img_local;
73 $file_exist = ( file_exists( $img_local ) );
74 } else {
75 $file_exist = false;
76 }
77 }
78 if ( $file_exist ) {
79 $check_size = true;
80 if ( isset( $current_notice['image']['local'] ) && $current_notice['image']['local'] == $options['image']['local'] ) {
81 if ( isset( $current_notice['image']['width'] ) && isset( $current_notice['image']['height'] ) ) {
82 $options['image']['width'] = $current_notice['image']['width'];
83 $options['image']['height'] = $current_notice['image']['height'];
84 $check_size = false;
85 }
86 }
87 if ( $check_size ) {
88 $image_size = @ getimagesize( $options['image']['local'] );
89 if ( ! empty( $image_size[0] ) && ! empty( $image_size[1] ) ) {
90 $options['image']['width'] = $image_size[0];
91 $options['image']['height'] = $image_size[1];
92 } else {
93 $options['image']['width'] = $options['height'];
94 $options['image']['height'] = $options['height'];
95 }
96 }
97 $options['image']['scale'] = $options['height'] / $options['image']['height'];
98 } else {
99 $options['image'] = array( 'width' => 0, 'height' => 0, 'scale' => 0 );
100 }
101 }
102 $notices[ $options['name'] ] = $options;
103 update_option( 'berocket_information_notices', $notices );
104
105 return true;
106 }
107
108 public static function get_notices() {
109 $notices = get_option( 'berocket_information_notices' );
110
111 return $notices;
112 }
113
114 public static function display_notice() {
115 $notices = self::get_notices();
116 $settings_page = apply_filters( 'is_berocket_settings_page', false );
117
118 if ( is_array( $notices ) && count( $notices ) > 0 ) {
119 foreach ( $notices as $notice ) {
120 if ( is_array( $notice ) and ( $settings_page or $notice['priority'] <= 20 ) ) {
121 self::echo_notice( $notice );
122 }
123 }
124 }
125 }
126
127 public static function echo_notice( $notice ) {
128 $notice = array_merge( self::$default_notice_options, $notice );
129 self::$notice_index++;
130 $notice_data = array(
131 'name' => $notice['name'],
132 );
133 if ( ! empty( $notice['subscribe'] ) ) {
134 $user_email = wp_get_current_user();
135 if ( isset( $user_email->user_email ) ) {
136 $user_email = $user_email->user_email;
137 } else {
138 $user_email = '';
139 }
140 $notice['righthtml'] =
141 '<form class="berocket_subscribe_form" method="POST" action="' . admin_url( 'admin-ajax.php' ) . '">
142 <input type="hidden" name="berocket_action" value="berocket_subscribe_email">
143 <input type="hidden" name="wp_nonce" value="' . wp_create_nonce( 'berocket_subscribe_email' ) . '">
144 <input class="berocket_subscribe_email" type="email" name="email" value="' . $user_email . '">
145 <input type="submit" class="button-primary button berocket_notice_submit" value="Subscribe">
146 </form>' . $notice['righthtml'];
147 $notice['rightwidth'] += 300;
148 }
149 echo '
150 <div class="notice berocket-notice notice-' . $notice['type'] . ' berocket_admin_notice berocket_admin_notice_', self::$notice_index, '" data-notice=\'', json_encode( $notice_data ), '\' data-nonce="' . wp_create_nonce( 'berocket_information_close_notice' ) . '">',
151 ( empty( $notice['image']['local'] ) ? '' : '<img class="berocket_notice_img" src="' . $notice['image']['local'] . '">' ),
152 ( empty( $notice['righthtml'] ) ? '' :
153 '<div class="berocket_notice_right_content">
154 <div class="berocket_notice_content">' . $notice['righthtml'] . '</div>
155 <div class="berocket_notice_after_content"></div>
156 </div>' ),
157 '<div class="berocket_notice_content_wrap">
158 <div class="berocket_notice_content">', $notice['html'], '</div>
159 <div class="berocket_notice_after_content"></div>
160 </div></div>';
161 echo '
162 <script>
163 jQuery(document).ready(function() {
164 jQuery(document).on("click", ".berocket_admin_notice.berocket_admin_notice_', self::$notice_index, ' .berocket_no_thanks", function(event){
165 event.preventDefault();
166 var notice = jQuery(this).parents(".berocket_admin_notice.berocket_admin_notice_', self::$notice_index, '").data("notice");
167 var nonce = jQuery(this).parents(".berocket_admin_notice.berocket_admin_notice_', self::$notice_index, '").data("nonce");
168 jQuery.post(ajaxurl, {action:"berocket_information_close_notice", notice:notice, wp_nonce:nonce}, function(data){});
169 jQuery(this).parents(".berocket_admin_notice.berocket_admin_notice_', self::$notice_index, '").hide();
170 });
171 });';
172 echo '</script>';
173 berocket_admin_notices::echo_styles();
174 berocket_admin_notices::echo_jquery_functions();
175 }
176
177 public static function close_notice( $notice = false ) {
178 $wp_nonce = ( empty( $_POST['wp_nonce'] ) ? '' : $_POST['wp_nonce'] );
179 if ( ! current_user_can( 'manage_options' ) || ! wp_verify_nonce( $wp_nonce, 'berocket_information_close_notice' ) ) {
180 echo __( 'Do not have access for this feature', 'BeRocket_domain' );
181 wp_die();
182 }
183 if ( ( $notice == false || ! is_array( $notice ) ) && ! empty( $_POST['notice'] ) ) {
184 $notice = sanitize_textarea_field( $_POST['notice'] );
185 }
186 $notices = self::get_notices();
187 if ( empty( $notice ) || empty( $notice['name'] ) ) {
188 $notices = array();
189 } elseif ( isset( $notices[ $notice['name'] ] ) ) {
190 unset( $notices[ $notice['name'] ] );
191 }
192 update_option( 'berocket_information_notices', $notices );
193 wp_die();
194 }
195 }
196
197 add_action( 'admin_notices', array( 'berocket_information_notices', 'display_notice' ) );
198 add_action( 'wp_ajax_berocket_information_close_notice', array( 'berocket_information_notices', 'close_notice' ) );
199 }