/var/www/hkosl.com/aga/wp-content/plugins/foogallery/freemius/includes/class-fs-admin-notices.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
<?php
    
/**
     * @package     Freemius
     * @copyright   Copyright (c) 2015, Freemius, Inc.
     * @license     https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3
     * @since       2.0.0
     */

    
if ( ! defined'ABSPATH' ) ) {
        exit;
    }

    
/**
     * WP Admin notices manager both for site level and network level.
     *
     * Class FS_Admin_Notices
     */
    
class FS_Admin_Notices {
        
/**
         * @since 1.2.2
         *
         * @var string
         */
        
protected $_module_unique_affix;
        
/**
         * @var string
         */
        
protected $_id;
        
/**
         * @var string
         */
        
protected $_title;
        
/**
         * @var FS_Admin_Notice_Manager
         */
        
protected $_notices;
        
/**
         * @var FS_Admin_Notice_Manager
         */
        
protected $_network_notices;
        
/**
         * @var int The ID of the blog that is associated with the current site level options.
         */
        
private $_blog_id 0;
        
/**
         * @var bool
         */
        
private $_is_multisite;
        
/**
         * @var FS_Admin_Notices[]
         */
        
private static $_instances = array();

        
/**
         * @param string $id
         * @param string $title
         * @param string $module_unique_affix
         * @param bool   $is_network_and_blog_admins Whether or not the message should be shown both on network and
         *                                           blog admin pages.
         *
         * @return FS_Admin_Notices
         */
        
static function instance$id$title ''$module_unique_affix ''$is_network_and_blog_admins false ) {
            if ( ! isset( 
self::$_instances$id ] ) ) {
                
self::$_instances$id ] = new FS_Admin_Notices$id$title$module_unique_affix$is_network_and_blog_admins );
            }

            return 
self::$_instances$id ];
        }

        
/**
         * @param string $id
         * @param string $title
         * @param string $module_unique_affix
         * @param bool   $is_network_and_blog_admins Whether or not the message should be shown both on network and
         *                                           blog admin pages.
         */
        
protected function __construct$id$title ''$module_unique_affix ''$is_network_and_blog_admins false ) {
            
$this->_id                  $id;
            
$this->_title               $title;
            
$this->_module_unique_affix $module_unique_affix;
            
$this->_is_multisite        is_multisite();

            if ( 
$this->_is_multisite ) {
                
$this->_blog_id get_current_blog_id();

                
$this->_network_notices FS_Admin_Notice_Manager::instance(
                    
$id,
                    
$title,
                    
$module_unique_affix,
                    
$is_network_and_blog_admins,
                    
true
                
);
            }

            
$this->_notices FS_Admin_Notice_Manager::instance(
                
$id,
                
$title,
                
$module_unique_affix,
                
false,
                
$this->_blog_id
            
);
        }

        
/**
         * Add admin message to admin messages queue, and hook to admin_notices / all_admin_notices if not yet hooked.
         *
         * @author Vova Feldman (@svovaf)
         * @since  1.0.4
         *
         * @param string   $message
         * @param string   $title
         * @param string   $type
         * @param bool     $is_sticky
         * @param string   $id Message ID
         * @param bool     $store_if_sticky
         * @param int|null $network_level_or_blog_id
         *
         * @uses   add_action()
         */
        
function add(
            
$message,
            
$title '',
            
$type 'success',
            
$is_sticky false,
            
$id '',
            
$store_if_sticky true,
            
$network_level_or_blog_id null
        
) {
            if ( 
$this->should_use_network_notices$id$network_level_or_blog_id ) ) {
                
$notices $this->_network_notices;
            } else {
                
$notices $this->get_site_notices$network_level_or_blog_id );
            }

            
$notices->add(
                
$message,
                
$title,
                
$type,
                
$is_sticky,
                
$id,
                
$store_if_sticky
            
);
        }

        
/**
         * @author Vova Feldman (@svovaf)
         * @since  1.0.7
         *
         * @param string|string[] $ids
         * @param int|null        $network_level_or_blog_id
         */
        
function remove_sticky$ids$network_level_or_blog_id null ) {
            if ( ! 
is_array$ids ) ) {
                
$ids = array( $ids );
            }

            if ( 
$this->should_use_network_notices$ids[0], $network_level_or_blog_id ) ) {
                
$notices $this->_network_notices;
            } else {
                
$notices $this->get_site_notices$network_level_or_blog_id );
            }

            return 
$notices->remove_sticky$ids );
        }

        
/**
         * Check if sticky message exists by id.
         *
         * @author Vova Feldman (@svovaf)
         * @since  1.0.9
         *
         * @param string   $id
         * @param int|null $network_level_or_blog_id
         *
         * @return bool
         */
        
function has_sticky$id$network_level_or_blog_id null ) {
            if ( 
$this->should_use_network_notices$id$network_level_or_blog_id ) ) {
                
$notices $this->_network_notices;
            } else {
                
$notices $this->get_site_notices$network_level_or_blog_id );
            }

            return 
$notices->has_sticky$id );
        }

        
/**
         * Adds sticky admin notification.
         *
         * @author Vova Feldman (@svovaf)
         * @since  1.0.7
         *
         * @param string      $message
         * @param string      $id Message ID
         * @param string      $title
         * @param string      $type
         * @param int|null    $network_level_or_blog_id
         * @param number|null $wp_user_id
         * @param string|null $plugin_title
         * @param bool        $is_network_and_blog_admins Whether or not the message should be shown both on network and
         *                                                blog admin pages.
         */
        
function add_sticky(
            
$message,
            
$id,
            
$title '',
            
$type 'success',
            
$network_level_or_blog_id null,
            
$wp_user_id null,
            
$plugin_title null,
            
$is_network_and_blog_admins false
        
) {
            if ( 
$this->should_use_network_notices$id$network_level_or_blog_id ) ) {
                
$notices $this->_network_notices;
            } else {
                
$notices $this->get_site_notices$network_level_or_blog_id );
            }

            
$notices->add_sticky$message$id$title$type$wp_user_id$plugin_title$is_network_and_blog_admins );
        }

        
/**
         * Clear all sticky messages.
         *
         * @author Vova Feldman (@svovaf)
         * @since  2.0.0
         *
         * @param int|null $network_level_or_blog_id
         */
        
function clear_all_sticky$network_level_or_blog_id null ) {
            if ( ! 
$this->_is_multisite ||
                 
false === $network_level_or_blog_id ||
                 
== $network_level_or_blog_id ||
                 
is_null$network_level_or_blog_id )
            ) {
                
$notices $this->get_site_notices$network_level_or_blog_id );
                
$notices->clear_all_sticky();
            }

            if ( 
$this->_is_multisite &&
                 ( 
true === $network_level_or_blog_id || is_null$network_level_or_blog_id ) )
            ) {
                
$this->_network_notices->clear_all_sticky();
            }
        }

        
/**
         * Add admin message to all admin messages queue, and hook to all_admin_notices if not yet hooked.
         *
         * @author Vova Feldman (@svovaf)
         * @since  1.0.4
         *
         * @param string $message
         * @param string $title
         * @param string $type
         * @param bool   $is_sticky
         * @param string $id Message ID
         */
        
function add_all$message$title ''$type 'success'$is_sticky false$id '' ) {
            
$this->add$message$title$type$is_stickytrue$id );
        }

        
#--------------------------------------------------------------------------------
        #region Helper Methods
        #--------------------------------------------------------------------------------

        /**
         * @author Vova Feldman (@svovaf)
         * @since  2.0.0
         *
         * @param int $blog_id
         *
         * @return FS_Admin_Notice_Manager
         */
        
private function get_site_notices$blog_id ) {
            if ( 
== $blog_id || $blog_id == $this->_blog_id ) {
                return 
$this->_notices;
            }

            return 
FS_Admin_Notice_Manager::instance(
                
$this->_id,
                
$this->_title,
                
$this->_module_unique_affix,
                
false,
                
$blog_id
            
);
        }

        
/**
         * Check if the network notices should be used.
         *
         * @author Vova Feldman (@svovaf)
         * @since  2.0.0
         *
         * @param string        $id
         * @param null|bool|int $network_level_or_blog_id When an integer, use the given blog storage. When `true` use the multisite notices (if there's a network). When `false`, use the current context blog notices. When `null`, the decision which notices manager to use (MS vs. Current S) will be handled internally and determined based on the $id and the context admin (blog admin vs. network level admin).
         *
         * @return bool
         */
        
private function should_use_network_notices$id ''$network_level_or_blog_id null ) {
            if ( ! 
$this->_is_multisite ) {
                
// Not a multisite environment.
                
return false;
            }

            if ( 
is_numeric$network_level_or_blog_id ) ) {
                
// Explicitly asked to use a specified blog storage.
                
return false;
            }

            if ( 
is_bool$network_level_or_blog_id ) ) {
                
// Explicitly specified whether should use the network or blog level storage.
                
return $network_level_or_blog_id;
            }

            return 
fs_is_network_admin();
        }

        
#endregion
    
}