PluginProbe
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions / 110710
s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions v110710
260913 260909 260829 260814 260805 110710 110731 110812 110815 110912 110913 110915 110926 110927 111002 111003 111011 111017 111029 111105 111206 111216 111220 120213 120219 All 188 releases
s2member / includes / classes / utilities.inc.php

utilities.inc.php in s2Member – Excellent for All Kinds of Memberships, Content Restriction Paywalls & Member Access Subscriptions 110710, at includes/classes/utilities.inc.php

140 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * General utilities.
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\Utilities
15 * @since 3.5
16 */
17 if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"]))
18 exit ("Do not access this file directly.");
19 /**/
20 if (!class_exists ("c_ws_plugin__s2member_utilities"))
21 {
22 /**
23 * General utilities.
24 *
25 * @package s2Member\Utilities
26 * @since 3.5
27 */
28 class c_ws_plugin__s2member_utilities
29 {
30 /**
31 * Evaluates PHP code, and "returns" output.
32 *
33 * @package s2Member\Utilities
34 * @since 3.5
35 *
36 * @param str $code A string of data, possibly with embedded PHP code.
37 * @return str Output after PHP evaluation.
38 */
39 public static function evl ($code = FALSE)
40 {
41 ob_start (); /* Output buffer. */
42 /**/
43 eval ("?>" . trim ($code));
44 /**/
45 return ob_get_clean ();
46 }
47 /**
48 * Buffers ( gets ) function output.
49 *
50 * A variable length of additional arguments are possible.
51 * Additional parameters get passed into the ``$function``.
52 *
53 * @package s2Member\Utilities
54 * @since 3.5
55 *
56 * @param str $function Name of a function to call upon.
57 * @return str Output after call to function.
58 * Any output is buffered and returned.
59 */
60 public static function get ($function = FALSE)
61 {
62 $args = func_get_args ();
63 $function = array_shift ($args);
64 /**/
65 if (is_string ($function) && $function)
66 {
67 ob_start ();
68 /**/
69 if (is_array ($args) && !empty ($args))
70 {
71 $return = call_user_func_array ($function, $args);
72 }
73 else /* There are no additional arguments to pass. */
74 {
75 $return = call_user_func ($function);
76 }
77 /**/
78 $echo = ob_get_clean ();
79 /**/
80 return (!strlen ($echo) && strlen ($return)) ? $return : $echo;
81 }
82 else /* Else return null. */
83 return;
84 }
85 /**
86 * Builds a version checksum for this installation.
87 *
88 * @package s2Member\Utilities
89 * @since 3.5
90 *
91 * @return str String with `[version]-[pro version]-[consolidated checksum]`.
92 */
93 public static function ver_checksum ()
94 {
95 $checksum = WS_PLUGIN__S2MEMBER_VERSION; /* Software version string. */
96 $checksum .= (defined ("WS_PLUGIN__S2MEMBER_PRO_VERSION")) ? "-" . WS_PLUGIN__S2MEMBER_PRO_VERSION : ""; /* Pro version string? */
97 $checksum .= "-" . abs (crc32 ($GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["checksum"] . $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["options_checksum"] . $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["options_version"]));
98 /**/
99 return $checksum; /* ( i.e. version-pro version-checksum ) */
100 }
101 /**
102 * String with all version details *( for WordPress® and s2Member )*.
103 *
104 * @package s2Member\Utilities
105 * @since 3.5
106 *
107 * @return str String with `WordPress® vX.XX :: s2Member® vX.XX :: s2Member® Pro vX.XX`.
108 */
109 public static function ver_details ()
110 {
111 $details = "WordPress® v" . get_bloginfo ("version") . " :: s2Member® v" . WS_PLUGIN__S2MEMBER_VERSION;
112 $details .= (defined ("WS_PLUGIN__S2MEMBER_PRO_VERSION")) ? " :: s2Member® Pro v" . WS_PLUGIN__S2MEMBER_PRO_VERSION : "";
113 /**/
114 return $details; /* Return all details. */
115 }
116 /**
117 * Generates s2Member Security Badge.
118 *
119 * @package s2Member\Utilities
120 * @since 3.5
121 *
122 * @param str $v A variation number to display. Defaults to `1`.
123 * @param bool $no_cache Defaults to false. If true, the HTML markup will contain query string params that prevent caching.
124 * @param bool $display_on_failure. Defaults to false. True if we need to display the "NOT yet verified" version inside admin panels.
125 * @return str HTML markup for display of s2Member Security Badge.
126 */
127 public static function s_badge_gen ($v = "1", $no_cache = FALSE, $display_on_failure = FALSE)
128 {
129 if ($v && file_exists (($template = dirname (dirname (__FILE__)) . "/templates/badges/s-badge.html")))
130 {
131 $badge = preg_replace ("/%%site_url%%/i", urlencode (site_url ()), preg_replace ("/%%v%%/i", (string)$v, file_get_contents ($template)));
132 $badge = preg_replace ("/%%no_cache%%/i", (($no_cache) ? "&amp;no_cache=" . urlencode (mt_rand (0, PHP_INT_MAX)) : ""), $badge);
133 $badge = preg_replace ("/%%display_on_failure%%/i", (($display_on_failure) ? "&amp;display_on_failure=1" : ""), $badge);
134 }
135 /**/
136 return (!empty ($badge)) ? $badge : ""; /* Return Security Badge. */
137 }
138 }
139 }
140 ?>