PageRenderTime 53ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/s2member/includes/classes/admin-notices.inc.php

https://gitlab.com/Gashler/dp
PHP | 167 lines | 88 code | 21 blank | 58 comment | 28 complexity | 91e7720021d8a05e41581aa3f76ea431 MD5 | raw file
  1. <?php
  2. /**
  3. * Enqueues/displays administrative notices.
  4. *
  5. * Copyright: © 2009-2011
  6. * {@link http://www.websharks-inc.com/ WebSharks, Inc.}
  7. * (coded in the USA)
  8. *
  9. * Released under the terms of the GNU General Public License.
  10. * You should have received a copy of the GNU General Public License,
  11. * along with this software. In the main directory, see: /licensing/
  12. * If not, see: {@link http://www.gnu.org/licenses/}.
  13. *
  14. * @package s2Member\Admin_Notices
  15. * @since 3.5
  16. */
  17. if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"]))
  18. exit("Do not access this file directly.");
  19. if (!class_exists ("c_ws_plugin__s2member_admin_notices"))
  20. {
  21. /**
  22. * Enqueues/displays administrative notices.
  23. *
  24. * @package s2Member\Admin_Notices
  25. * @since 3.5
  26. */
  27. class c_ws_plugin__s2member_admin_notices
  28. {
  29. /**
  30. * Enqueues administrative notices.
  31. *
  32. * @package s2Member\Admin_Notices
  33. * @since 3.5
  34. *
  35. * @param str $notice String value of actual notice *(i.e. the message)*.
  36. * @param str|array $on_pages Optional. Defaults to any page. String or array of pages to display this notice on.
  37. * @param bool $error Optional. True if this notice is regarding an error. Defaults to false.
  38. * @param int $time Optional. Unix timestamp indicating when this notice will be displayed.
  39. * @param bool $dismiss Optional. If true, the notice will remain persistent, until dismissed. Defaults to false.
  40. * @return null
  41. */
  42. public static function enqueue_admin_notice ($notice = FALSE, $on_pages = FALSE, $error = FALSE, $time = FALSE, $dismiss = FALSE)
  43. {
  44. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  45. do_action ("ws_plugin__s2member_before_enqueue_admin_notice", get_defined_vars ());
  46. unset /* Unset defined __refs, __v. */ ($__refs, $__v);
  47. if /* If we have a valid string. */(is_string ($notice) && $notice)
  48. {
  49. $notices = (array)get_option ("ws_plugin__s2member_notices");
  50. array_push ($notices, array ("notice" => $notice, "on_pages" => $on_pages, "error" => $error, "time" => $time, "dismiss" => $dismiss));
  51. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  52. do_action ("ws_plugin__s2member_during_enqueue_admin_notice", get_defined_vars ());
  53. unset /* Unset defined __refs, __v. */ ($__refs, $__v);
  54. update_option ("ws_plugin__s2member_notices", c_ws_plugin__s2member_utils_arrays::array_unique ($notices));
  55. }
  56. do_action ("ws_plugin__s2member_after_enqueue_admin_notice", get_defined_vars ());
  57. return /* Return for uniformity. */;
  58. }
  59. /**
  60. * Displays an administrative notice.
  61. *
  62. * @package s2Member\Admin_Notices
  63. * @since 3.5
  64. *
  65. * @param str $notice String value of actual notice *(i.e. the message)*.
  66. * @param bool $error Optional. True if this notice is regarding an error. Defaults to false.
  67. * @param bool $dismiss Optional. If true, the notice will be displayed with a dismissal link. Defaults to false.
  68. * @return null
  69. */
  70. public static function display_admin_notice ($notice = FALSE, $error = FALSE, $dismiss = FALSE)
  71. {
  72. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  73. do_action ("ws_plugin__s2member_before_display_admin_notice", get_defined_vars ());
  74. unset /* Unset defined __refs, __v. */ ($__refs, $__v);
  75. if /* Slightly different/special format for errors. */ (is_string ($notice) && $notice && $error)
  76. {
  77. $notice .= ($dismiss) ? ' [ <a href="' . esc_attr(add_query_arg ("ws-plugin--s2member-dismiss-admin-notice", urlencode (md5 ($notice)), $_SERVER["REQUEST_URI"])) . '">dismiss message</a> ]' : '';
  78. echo /* Error. */ '<div class="error fade"><p>' . $notice . '</p></div>';
  79. }
  80. else if (is_string ($notice) && $notice)
  81. {
  82. $notice .= ($dismiss) ? ' [ <a href="' . esc_attr(add_query_arg ("ws-plugin--s2member-dismiss-admin-notice", urlencode (md5 ($notice)), $_SERVER["REQUEST_URI"])) . '">dismiss message</a> ]' : '';
  83. echo '<div class="updated fade"><p>' . $notice . '</p></div>';
  84. }
  85. do_action ("ws_plugin__s2member_after_display_admin_notice", get_defined_vars ());
  86. return /* Return for uniformity. */;
  87. }
  88. /**
  89. * Processes all administrative notices.
  90. *
  91. * @package s2Member\Admin_Notices
  92. * @since 3.5
  93. *
  94. * @attaches-to ``add_action("admin_notices");``
  95. * @attaches-to ``add_action("user_admin_notices");``
  96. * @attaches-to ``add_action("network_admin_notices");``
  97. * @todo Update to ``add_action("all_admin_notices");``.
  98. *
  99. * @return null
  100. */
  101. public static function admin_notices ()
  102. {
  103. global /* This holds the current page filename. */ $pagenow;
  104. do_action ("ws_plugin__s2member_before_admin_notices", get_defined_vars ());
  105. if (is_admin () && is_array ($notices = get_option ("ws_plugin__s2member_notices")) && !empty ($notices))
  106. {
  107. $a = (is_blog_admin ()) ? "blog" : $a;
  108. $a = (is_user_admin ()) ? "user" : $a;
  109. $a = (is_network_admin ()) ? "network" : $a;
  110. $a = /* Default Blog Admin. */(!$a) ? "blog" : $a;
  111. foreach /* Check several things about each Notice. */ ($notices as $i => $notice)
  112. foreach (((!$notice["on_pages"]) ? array ("*"): (array)$notice["on_pages"]) as $page)
  113. {
  114. if /* NO prefix? */ (!preg_match ("/^(.+?)\:/", $page))
  115. $page = /* `blog:` */ "blog:" . ltrim ($page, ":");
  116. $adms = preg_split ("/\|/", preg_replace ("/\:(.*)$/i", "", $page));
  117. $page = preg_replace ("/^([^\:]*)\:/i", "", $page);
  118. if (empty ($adms) || in_array ("*", $adms) || in_array ($a, $adms))
  119. if (!$page || "*" === $page || $pagenow === $page || $_GET["page"] === $page)
  120. {
  121. if /* Time to show it? */ (strtotime ("now") >= (int)$notice["time"])
  122. {
  123. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  124. do_action ("ws_plugin__s2member_during_admin_notices_before_display", get_defined_vars ());
  125. unset /* Unset defined __refs, __v. */ ($__refs, $__v);
  126. if (!$notice["dismiss"] || (!empty ($_GET["ws-plugin--s2member-dismiss-admin-notice"]) && $_GET["ws-plugin--s2member-dismiss-admin-notice"] === md5 ($notice["notice"])))
  127. unset /* Clear this administrative notice now? */($notices[$i]);
  128. if (!$notice["dismiss"] || empty ($_GET["ws-plugin--s2member-dismiss-admin-notice"]) || $_GET["ws-plugin--s2member-dismiss-admin-notice"] !== md5 ($notice["notice"]))
  129. c_ws_plugin__s2member_admin_notices::display_admin_notice ($notice["notice"], $notice["error"], $notice["dismiss"]);
  130. do_action ("ws_plugin__s2member_during_admin_notices_after_display", get_defined_vars ());
  131. }
  132. continue /* This Notice processed; continue. */ 2;
  133. }
  134. }
  135. $notices = /* Re-index array. */array_merge ($notices);
  136. foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;
  137. do_action ("ws_plugin__s2member_during_admin_notices", get_defined_vars ());
  138. unset /* Unset defined __refs, __v. */ ($__refs, $__v);
  139. update_option ("ws_plugin__s2member_notices", $notices);
  140. }
  141. do_action ("ws_plugin__s2member_after_admin_notices", get_defined_vars ());
  142. return /* Return for uniformity. */;
  143. }
  144. }
  145. }
  146. ?>