| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: MembershipWorks - Membership, Events & Directory |
| 4 |
Plugin URI: https://membershipworks.com |
| 5 |
Description: Membership Works plugin |
| 6 |
Version: 6.6 |
| 7 |
Author: MembershipWorks |
| 8 |
Author URI: https://membershipworks.com |
| 9 |
License: GPL2 |
| 10 |
*/ |
| 11 |
|
| 12 |
/* Copyright 2013-2020 SOURCEFOUND INC. (email : info@sourcefound.com) |
| 13 |
|
| 14 |
This program is free software; you can redistribute it and/or modify |
| 15 |
it under the terms of the GNU General Public License, version 2, as |
| 16 |
published by the Free Software Foundation. |
| 17 |
|
| 18 |
This program is distributed in the hope that it will be useful, |
| 19 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 |
GNU General Public License for more details. |
| 22 |
|
| 23 |
You should have received a copy of the GNU General Public License |
| 24 |
along with this program; if not, write to the Free Software |
| 25 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 26 |
*/ |
| 27 |
|
| 28 |
$SF_widgetid=0; |
| 29 |
$SF_dat=false; |
| 30 |
$SF_css=false; |
| 31 |
|
| 32 |
function sf_api($con,$act,$fn,$param) { |
| 33 |
if ($act!='GET') |
| 34 |
return array('error'=>'Not supported'); |
| 35 |
$q=array(); |
| 36 |
foreach($param as $k=>$v) { |
| 37 |
if (is_array($v)) { |
| 38 |
foreach($v as $i=>$x) $v[$i]=urlencode($x); |
| 39 |
$q[]=$k.'='.implode(',',$v); |
| 40 |
} else { |
| 41 |
$q[]=$k.'='.urlencode($v); |
| 42 |
} |
| 43 |
} |
| 44 |
//$ctx=stream_context_create(array('http'=>array('method'=>'GET','header'=>"From: ".(isset($_SERVER['HTTP_X_FORWARDED_FOR'])?$_SERVER['HTTP_X_FORWARDED_FOR']:$_SERVER['REMOTE_ADDR']),'user_agent'=>$_SERVER['HTTP_USER_AGENT']))); |
| 45 |
//$rsp=file_get_contents($con.'://api.membershipworks.com/'.$fn.'?'.implode('&',$q),false,$ctx); |
| 46 |
//if (empty($rsp)) |
| 47 |
// return array('error'=>'No response'); |
| 48 |
//else |
| 49 |
// return json_decode($rsp,true); |
| 50 |
$args=array('headers'=>array('from'=>isset($_SERVER['HTTP_X_FORWARDED_FOR'])?$_SERVER['HTTP_X_FORWARDED_FOR']:$_SERVER['REMOTE_ADDR']),'user-agent'=>$_SERVER['HTTP_USER_AGENT']); |
| 51 |
for($try=0;$try<3;$try++) { |
| 52 |
$rsp=wp_remote_get($con.'://api.membershipworks.com/'.$fn.'?'.implode('&',$q),$args); |
| 53 |
if (is_wp_error($rsp)) usleep(100000); else break; |
| 54 |
} |
| 55 |
if (is_wp_error($rsp)) |
| 56 |
return array('error'=>$rsp->get_error_message()); |
| 57 |
else if (empty($rsp['body'])) |
| 58 |
return array('error'=>'No response'); |
| 59 |
else |
| 60 |
return json_decode($rsp['body'],true); |
| 61 |
} |
| 62 |
|
| 63 |
function sf_admin_menu() { |
| 64 |
add_menu_page('MembershipWorks Admin','Membership Works','edit_users','sf_admin_page','sf_admin_page','data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBzdGFuZGFsb25lPSJubyI/Pgo8IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDIwMDEwOTA0Ly9FTiIKICJodHRwOi8vd3d3LnczLm9yZy9UUi8yMDAxL1JFQy1TVkctMjAwMTA5MDQvRFREL3N2ZzEwLmR0ZCI+CjxzdmcgdmVyc2lvbj0iMS4wIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiB2aWV3Qm94PSIwIDAgNDY2IDQ2NiI+CjxnIHRyYW5zZm9ybT0idHJhbnNsYXRlKDAuMDAwMDAwLDQ2Ni4wMDAwMDApIHNjYWxlKDAuMTAwMDAwLC0wLjEwMDAwMCkiCmZpbGw9IiNGRkZGRkYiIHN0cm9rZT0ibm9uZSI+CjxwYXRoIGQ9Ik0xNzU1IDQxMjQgYy0yNyAtMiAtOTAgLTkgLTE0MCAtMTUgLTU3OSAtNzEgLTEwMDggLTQ2MyAtMTEyMSAtMTAyNAotMjEgLTEwNyAtMjkgLTM1OCAtMTUgLTQ3OCBsMTEgLTk2IC0yNDYgLTUxMSBjLTEzNSAtMjgxIC0yNDQgLTUxMyAtMjQxIC01MTYKMyAtMyAyOSAyNyA1OSA2OCAzMCA0MCAzMDMgNDEzIDYwOCA4MjggMzA0IDQxNSA1NTggNzYxIDU2NSA3NjggOSAxMCAzMCAtNzcKOTUgLTQwNSA0NiAtMjMwIDg2IC00MjEgODkgLTQyNSA0IC00IDE0NSAxODEgMzE1IDQxMiAxNjkgMjMxIDMxMSA0MjAgMzE1CjQyMCA2IDAgMzMzIC0xNjMwIDMzMSAtMTY1MyAwIC00IC04NCAtNiAtMTg3IC01IGwtMTg3IDMgLTg0IDQyOCBjLTQ3IDIzNQotODcgNDI3IC05MSA0MjcgLTMgMCAtMTQ1IC0xOTEgLTMxNiAtNDI0IC0xNzAgLTIzMyAtMzEyIC00MjIgLTMxNCAtNDIwIC0yIDIKLTQxIDE5MSAtODYgNDE5IC00NSAyMjggLTg0IDQxNyAtODcgNDIxIC01IDUgLTM4OCAtMzExIC0zODggLTMyMCAwIC0xMSA2OQotMTUzIDEwMyAtMjExIDM1MCAtNjA5IDk1NSAtMTA3MCAxNjA4IC0xMjI1IDIxMSAtNTAgNTEzIC02NSA3MDQgLTM2IDYwMCA5MgoxMDEzIDQ4OSAxMTA5IDEwNjUgMTggMTA3IDIxIDM1OCA2IDQ2MyBsLTEwIDY2IDI1MCA1MTggYzEzNyAyODUgMjQ3IDUyMCAyNDUKNTIzIC02IDUgOTIgMTM4IC02MzEgLTg0OCBsLTYxOSAtODQ0IC04NSA0MjcgYy00NiAyMzQgLTg4IDQyNSAtOTIgNDI0IC0zIC0yCi0xNDYgLTE5MyAtMzE2IC00MjYgLTIyMCAtMjk4IC0zMTIgLTQxNyAtMzE2IC00MDUgLTggMjcgLTMyNiAxNjM3IC0zMjYgMTY1MQowIDkgNDUgMTIgMTg3IDEwIGwxODggLTMgODQgLTQzMiBjNDcgLTIzOCA4OCAtNDMzIDkxIC00MzMgMyAwIDE0NSAxOTEgMzE1CjQyNCAxNzEgMjMzIDMxMyA0MjEgMzE2IDQxNyA0IC0zIDQzIC0xOTIgODcgLTQyMCA0NSAtMjI3IDgzIC00MTYgODYgLTQxOCA2Ci02IDM4NiAzMTYgMzg2IDMyOCAwIDMxIC0xMzQgMjcwIC0yMjQgMzk5IC0xMzAgMTg4IC0zMzQgNDA2IC01MDYgNTQ0IC0zNDYKMjc2IC03NzAgNDY3IC0xMTU2IDUyMCAtMTE2IDE2IC0yODcgMjUgLTM2OSAyMHoiLz4KPC9nPgo8L3N2Zz4K','2.99'); |
| 65 |
add_submenu_page('sf_admin_page','Members','Members','edit_users','sf_admin_members','sf_admin_page'); |
| 66 |
add_submenu_page('sf_admin_page','Folders','Folders','edit_users','sf_admin_folders','sf_admin_page'); |
| 67 |
add_submenu_page('sf_admin_page','Labels','Labels & Membership','edit_users','sf_admin_labels','sf_admin_page'); |
| 68 |
add_submenu_page('sf_admin_page','Event List','Event List','edit_users','sf_admin_event-list','sf_admin_page'); |
| 69 |
add_submenu_page('sf_admin_page','Event Calendar','Event Calendar','edit_users','sf_admin_calendar','sf_admin_page'); |
| 70 |
add_submenu_page('sf_admin_page','Forms Carts Donations','Forms Carts Donations','edit_users','sf_admin_forms','sf_admin_page'); |
| 71 |
add_submenu_page('sf_admin_page','Customization','Customization','edit_users','sf_admin_custom','sf_admin_page'); |
| 72 |
add_submenu_page('sf_admin_page','Help','Help','edit_users','sf_admin_help','sf_admin_page'); |
| 73 |
add_submenu_page('sf_admin_page','Organization Settings','Organization Settings','edit_users','sf_admin_account','sf_admin_page'); |
| 74 |
add_submenu_page('sf_admin_page','Plugin Settings','Plugin Settings','manage_options','sf_admin_options','sf_admin_options'); |
| 75 |
} |
| 76 |
|
| 77 |
function sf_admin_init() { |
| 78 |
register_setting('sf_admin_group','sf_set','sf_admin_validate'); |
| 79 |
} |
| 80 |
|
| 81 |
if (is_admin()) { |
| 82 |
add_action('admin_init','sf_admin_init'); |
| 83 |
add_action('admin_menu','sf_admin_menu'); |
| 84 |
} |
| 85 |
|
| 86 |
function sf_admin_options() { |
| 87 |
if (!current_user_can('manage_options')) { |
| 88 |
wp_die(__('You do not have sufficient permissions to access this page.')); |
| 89 |
} |
| 90 |
echo '<div class="wrap"><h1>MembershipWorks Plugin Settings</h1>' |
| 91 |
.'<form action="options.php" method="post">'; |
| 92 |
settings_fields("sf_admin_group"); |
| 93 |
$set=get_option('sf_set'); |
| 94 |
echo '<table class="form-table">' |
| 95 |
.'<tr valign="top"><th scope="row">Organization ID</th><td><input type="text" name="sf_set[org]" value="'.esc_attr(isset($set['org'])?$set['org']:'').'" /></td></tr>' |
| 96 |
.'<tr valign="top"><th scope="row">Facebook API key (optional)</th><td><input type="text" name="sf_set[fbk]" value="'.esc_attr(isset($set['fbk'])?$set['fbk']:'').'" /></td></tr>' |
| 97 |
.'<tr valign="top"><th scope="row">Google Maps API key (optional)</th><td><input type="text" name="sf_set[map]" value="'.esc_attr(isset($set['map'])?$set['map']:'').'" /></td></tr>' |
| 98 |
.'<tr valign="top"><th scope="row">Display contact name on cards in directory</th><td><input type="checkbox" name="sf_set[ctc]"'.(empty($set['ctc'])?'':' checked="1"').' /></td></tr>' |
| 99 |
.'<tr valign="top"><th scope="row">Customize text for directory search button</th><td><input type="text" name="sf_set[fnd]" value="'.esc_textarea(empty($set['fnd'])?'Search':$set['fnd']).'" /></td></tr>' |
| 100 |
.'<tr valign="top"><th scope="row">Customize text for directory group email button</th><td><input type="text" name="sf_set[rsp]" placeholder="disabled" value="'.esc_textarea(isset($set['rsp'])?$set['rsp']:'').'" /></td></tr>' |
| 101 |
.'<tr valign="top"><th scope="row">Disable social share buttons</th><td><input type="checkbox" name="sf_set[scl]"'.(empty($set['scl'])?'':' checked="1"').' /></td></tr>' |
| 102 |
.'<tr valign="top"><th scope="row">Open directory profile links in new tab (referral information not passed)</th><td><input type="checkbox" name="sf_set[wgo]"'.(empty($set['wgo'])?'':' checked="1"').' /></td></tr>' |
| 103 |
.'<tr valign="top"><th scope="row">Load js/css inline</th><td><input type="checkbox" name="sf_set[htm]"'.(empty($set['htm'])?'':' checked="1"').' /></td></tr>' |
| 104 |
.'<tr valign="top"><th scope="row">URL redirect upon signing out</th><td><input type="text" name="sf_set[out]" value="'.esc_attr(empty($set['out'])?'':$set['out']).'" /></td></tr>' |
| 105 |
.'<tr valign="top"><th scope="row">Page top offset (pixels)</th><td><input type="text" name="sf_set[top]" value="'.esc_attr(empty($set['top'])?'':$set['top']).'" /></td></tr>' |
| 106 |
.'<tr valign="top"><th scope="row">Member only content login required message</th><td><textarea name="sf_set[mol]" style="width:500px">'.esc_textarea(empty($set['mol'])?'The following content is accessible for members only, please sign in.':$set['mol']).'</textarea></td></tr>' |
| 107 |
.'<tr valign="top"><th scope="row">Member only content membership past due message</th><td><textarea name="sf_set[moe]" style="width:500px">'.esc_textarea(empty($set['moe'])?'The following content is not accessible because your membership has expired.':$set['moe']).'</textarea></td></tr>' |
| 108 |
.'<tr valign="top"><th scope="row">Member only content account no access message</th><td><textarea name="sf_set[mon]" style="width:500px">'.esc_textarea(empty($set['mon'])?'The following content is not accessible for your account.':$set['mon']).'</textarea></td></tr>' |
| 109 |
.'<tr valign="top"><th scope="row">Member only content session expired message</th><td><textarea name="sf_set[moi]" style="width:500px">'.esc_textarea(empty($set['moi'])?'Your session has expired, please sign in again.':$set['moi']).'</textarea></td></tr>' |
| 110 |
.'<tr valign="top"><th scope="row">MembershipWorks data connection</th><td><select name="sf_set[ssl]"><option value=""'.(empty($set['ssl'])?' selected':'').'>Connect via HTTPS</option><option value="1"'.(!empty($set['ssl'])&&$set['ssl']!='2'?' selected':'').'>Connect via HTTP for public data</option><option value="2"'.(!empty($set['ssl'])&&$set['ssl']=='2'?' selected':'').'>Connect via HTTP ** INSECURE ** MAY COMPROMISE MEMBER PASSWORDS AND DATA</option></td></tr>' |
| 111 |
.'</table>' |
| 112 |
//.(empty($set['wpl'])?'':('<input type="hidden" name="sf_set[wpl]" value="'.$set['wpl'].'" />')) |
| 113 |
.'<p class="submit"><input type="submit" name="submit" id="submit" class="button-primary" value="Save Changes"></p>' |
| 114 |
.'</form></div>'; |
| 115 |
} |
| 116 |
|
| 117 |
function sf_admin_validate($in) { |
| 118 |
$in['org']=intval($in['org']); |
| 119 |
$in['org']=($in['org']?strval($in['org']):''); |
| 120 |
if (!empty($in['fbk'])) $in['fbk']=trim($in['fbk']); |
| 121 |
if (!empty($in['map'])) $in['map']=empty($in['map'])?'':trim($in['map']); |
| 122 |
if (!empty($in['fnd'])) $in['fnd']=trim($in['fnd']); |
| 123 |
if (isset($in['adv'])) $in['adv']=trim($in['adv']); |
| 124 |
if (!empty($in['rsp'])) $in['rsp']=trim($in['rsp']); |
| 125 |
if (!empty($in['scl'])) $in['scl']='1'; else unset($in['scl']); |
| 126 |
if (!empty($in['htm'])) $in['htm']='1'; else unset($in['htm']); |
| 127 |
if (!empty($in['ctc'])) $in['ctc']='1'; else unset($in['ctc']); |
| 128 |
if (empty($in['ssl'])) unset($in['ssl']); |
| 129 |
return $in; // preserve other fields for $in including wpl |
| 130 |
} |
| 131 |
|
| 132 |
function sf_admin_page() { |
| 133 |
global $plugin_page; |
| 134 |
$set=get_option('sf_set'); |
| 135 |
switch (substr($plugin_page,9)) { |
| 136 |
case 'members': $ini='folder/Members'; $hme='folder/Members'; break; |
| 137 |
case 'labels': $ini='labels'; $hme='labels'; break; |
| 138 |
case 'folders': $ini='folders'; $hme='folders'; break; |
| 139 |
case 'event-list': $ini='!event-list'; $hme='!event-list'; break; |
| 140 |
case 'calendar': $ini='!calendar'; $hme='!calendar'; break; |
| 141 |
case 'forms': $ini='forms'; $hme='forms'; break; |
| 142 |
case 'custom': $ini='custom'; $hme='custom'; break; |
| 143 |
case 'help': $ini='!help'; $hme='!help'; break; |
| 144 |
case 'account': $ini='account/manage'; $hme='account'; break; |
| 145 |
default: $ini='dashboard'; $hme='dashboard'; break; |
| 146 |
} |
| 147 |
echo '<div id="SFctr" class="SF" data-org="10000" data-hme="'.esc_attr($hme).'" data-ini="'.esc_attr($ini).'"'.(empty($set)||empty($set['map'])?'':(' data-map="'.esc_attr($set['map']).'"')).' data-typ="org" data-wpo="options.php" style="position:relative;padding:30px 20px 20px;"></div>' |
| 148 |
.'<script>function sf_admin(){' |
| 149 |
.'var t=document.getElementById("toplevel_page_sf_admin_page");' |
| 150 |
.'if (!t) return;' |
| 151 |
.'var a=t.querySelectorAll(".wp-submenu a"),i,x,n;' |
| 152 |
.'for(i=0;n=a[i];i++){' |
| 153 |
.'x=n.href.split("sf_admin_")[1];' |
| 154 |
.'n.parentNode.className="";' |
| 155 |
.'if (x=="options") continue;' |
| 156 |
.'else if (x=="page"){n.innerHTML="Dashboard";n.parentNode.id="SFhdrdbd";n.href="#dashboard";}' |
| 157 |
.'else if (x=="members"){n.parentNode.id="SFhdrdem";n.href="#folder/Members";}' |
| 158 |
.'else if (x=="labels"){n.parentNode.id="SFhdrlbl";n.href="#labels";}' |
| 159 |
.'else if (x=="folders"){n.parentNode.id="SFhdrdek";n.href="#folders";}' |
| 160 |
.'else if (x=="event-list"){n.parentNode.id="SFhdrevl";n.href="#!event-list";}' |
| 161 |
.'else if (x=="calendar"){n.parentNode.id="SFhdrevc";n.href="#!calendar";}' |
| 162 |
.'else if (x=="forms"){n.parentNode.id="SFhdrfrm";n.href="#forms";}' |
| 163 |
.'else if (x=="help"){n.parentNode.id="SFhdrhlp";n.href="#help";}' |
| 164 |
.'else if (x=="custom"){n.parentNode.id="SFhdrtpl";n.href="#custom";}' |
| 165 |
.'else if (x=="account"){n.parentNode.id="SFhdracc";n.href="#account";}' |
| 166 |
.'}' |
| 167 |
.'}sf_admin();</script>' |
| 168 |
.'<script type="text/javascript" src="https://cdn.membershipworks.com/all.js"></script>' |
| 169 |
.'<script>SF.init();</script>'; |
| 170 |
if ($set===false||empty($set['org'])) { |
| 171 |
echo '<form id="SFwpo" style="display:none" action="options.php" method="post">'; |
| 172 |
settings_fields("sf_admin_group"); |
| 173 |
echo '</form>'; |
| 174 |
} |
| 175 |
} |
| 176 |
|
| 177 |
function sf_enqueue_mfm_script() { |
| 178 |
global $SF_css; |
| 179 |
wp_register_script('sf-mfm','https://cdn.membershipworks.com/mfm.js',array(),null); |
| 180 |
if (!empty($SF_css)||!empty($SF_dat)) { |
| 181 |
wp_register_style('sf-css','https://cdn.membershipworks.com/all.css'); |
| 182 |
wp_enqueue_style('sf-css'); |
| 183 |
} |
| 184 |
} |
| 185 |
add_action('wp_enqueue_scripts','sf_enqueue_mfm_script'); |
| 186 |
|
| 187 |
function sf_mfm_init() { |
| 188 |
global $post,$SF_dat,$SF_css; |
| 189 |
if (empty($post)||!is_object($post)) return; |
| 190 |
$arg=func_get_args(); |
| 191 |
$set=get_option('sf_set'); |
| 192 |
if (empty($set['org'])) return; |
| 193 |
for ($x=false,$i=0,$l=strlen($post->post_content),$mat=array();$i<$l&&(($x=strpos($post->post_content,'[memberfindme open=',$i))!==false||($x=strpos($post->post_content,'[mw open=',$i))!==false);$i=$x+1) { |
| 194 |
$y=strpos($post->post_content,']',$x); |
| 195 |
if ((!$x||substr($post->post_content,$x-1,1)!='[')&&$y!==false) break; // not escaped shortcode and shortcode is closed |
| 196 |
} |
| 197 |
if ($x!==false&&empty($set['htm'])) |
| 198 |
$SF_css=true; |
| 199 |
if ($x!==false&&(isset($_GET['_escaped_fragment_'])||preg_match("/slurp|msnbot|facebook/i",$_SERVER['HTTP_USER_AGENT'])>0)) { |
| 200 |
$str=substr($post->post_content,$x+1,$y-$x-1); |
| 201 |
$mat=array(); |
| 202 |
$opt=array(); |
| 203 |
if (preg_match_all('/\s([a-z\-]*)(=("|“|”|&[^;]*;)+.*?("|“|”|&[^;]*;))?/',$str,$mat,PREG_PATTERN_ORDER)&&!empty($mat)&&!empty($mat[1])) |
| 204 |
foreach ($mat[1] as $key=>$val) $opt[$val]=empty($mat[2][$key])?'':trim(preg_replace('/^=("|“|”|&[^;]*;)*|("|“|”|&[^;]*;)*$/','',$mat[2][$key])); |
| 205 |
if (isset($_GET['_escaped_fragment_'])) { |
| 206 |
$pne=$_GET['_escaped_fragment_']; |
| 207 |
remove_action('wp_head','jetpack_og_tags'); |
| 208 |
add_filter('jetpack_enable_open_graph','__return_false',99); |
| 209 |
add_filter('jetpack_disable_twitter_cards','__return_true',99); |
| 210 |
if (defined('WPSEO_VERSION')) { // Yoast SEO |
| 211 |
global $wpseo_front; |
| 212 |
if (!empty($wpseo_front)) |
| 213 |
$tmp=$wpseo_front; |
| 214 |
else if (class_exists('WPSEO_Frontend')&&method_exists('WPSEO_Frontend','get_instance')) |
| 215 |
$tmp=WPSEO_Frontend::get_instance(); |
| 216 |
else |
| 217 |
$tmp=false; |
| 218 |
if (!empty($tmp)) { |
| 219 |
remove_action('wp_head',array($tmp,'head'),1); |
| 220 |
add_filter('wpseo_title','__return_empty_string'); |
| 221 |
if (method_exists($tmp,'flush_cache')&&remove_action('wp_footer',array($tmp,'flush_cache'),-1)) |
| 222 |
ob_end_flush(); |
| 223 |
} |
| 224 |
} else if (defined('AIOSEOP_VERSION')) { // All in One SEO |
| 225 |
global $aiosp; |
| 226 |
if (!empty($aiosp)) |
| 227 |
remove_action('wp_head',array($aiosp,'wp_head'),apply_filters('aioseop_wp_head_priority',1)); |
| 228 |
} |
| 229 |
remove_action('wp_head','rel_canonical'); |
| 230 |
remove_action('wp_head','index_rel_link'); |
| 231 |
remove_action('wp_head','start_post_rel_link'); |
| 232 |
remove_action('wp_head','adjacent_posts_rel_link_wp_head'); |
| 233 |
add_action('wp_head','sf_head',0); |
| 234 |
} else if (!empty($opt['open'])) { |
| 235 |
$pne=$opt['open']; |
| 236 |
} else { |
| 237 |
$pne=false; |
| 238 |
} |
| 239 |
if (!empty($pne)) { |
| 240 |
$qry=array('org'=>$set['org'],'hdr'=>'','dtl'=>'','url'=>get_permalink(),'pne'=>$pne); |
| 241 |
if (!empty($set['ctc'])) $qry['ctc']=1; |
| 242 |
if (!empty($opt['lbl'])) $qry['lbl']=$opt['lbl']; else if (!empty($opt['labels'])) $qry['lbl']=$opt['labels']; |
| 243 |
if (!empty($opt['folder'])) $qry['dek']=$opt['folder']; |
| 244 |
if (isset($opt['evg'])) $qry['evg']=$opt['evg']; |
| 245 |
$SF_dat=sf_api('http','GET','api',$qry); |
| 246 |
if (empty($SF_dat)||!empty($SF_dat['error'])) |
| 247 |
$SF_dat=false; |
| 248 |
else |
| 249 |
$SF_dat['set']=$set; |
| 250 |
} |
| 251 |
} |
| 252 |
if (!empty($SF_dat)||strpos($post->post_content,'[memberonly')!==false) { |
| 253 |
if (!defined('DONOTCACHEPAGE')) define('DONOTCACHEPAGE',true); |
| 254 |
nocache_headers(); |
| 255 |
setcookie('wordpress_donotcache',time()); |
| 256 |
} |
| 257 |
} |
| 258 |
add_action('wp','sf_mfm_init'); |
| 259 |
|
| 260 |
function sf_title() { |
| 261 |
global $SF_dat; |
| 262 |
$arg=func_get_args(); |
| 263 |
if (empty($SF_dat)||empty($SF_dat['ttl'])) |
| 264 |
return empty($arg)?'':$arg[0]; |
| 265 |
if (!empty($arg)&&!empty($arg[2])) |
| 266 |
return ($arg[2]=='left'?($arg[0].' '.(empty($arg[1])?'':($arg[1].' '))):'').$SF_dat['ttl'].($arg[2]=='right'?((empty($arg[1])?'':(' '.$arg[1])).' '.$arg[0]):''); |
| 267 |
return $SF_dat['ttl']; |
| 268 |
} |
| 269 |
add_filter('wp_title','sf_title',20,3); |
| 270 |
|
| 271 |
function sf_document_title_parts($title) { |
| 272 |
global $SF_dat; |
| 273 |
if (!empty($SF_dat)&&!empty($SF_dat['ttl'])) |
| 274 |
$title['title']=$SF_dat['ttl']; |
| 275 |
return $title; |
| 276 |
} |
| 277 |
add_filter('document_title_parts','sf_document_title_parts',20,2); |
| 278 |
|
| 279 |
function sf_head() { |
| 280 |
global $SF_dat; |
| 281 |
if (!empty($SF_dat)) { |
| 282 |
$out=array(); |
| 283 |
if (isset($SF_dat['sum'])) |
| 284 |
$out[]='<meta name="description" content="'.str_replace('"','"',$SF_dat['sum']).'" />'; |
| 285 |
if (isset($SF_dat['ttl'])) { |
| 286 |
$out[]='<meta property="og:site_name" content="'.str_replace('"','"',get_bloginfo('name')).'" />'; |
| 287 |
$out[]='<meta property="og:title" content="'.str_replace('"','"',$SF_dat['ttl']).'" />'; |
| 288 |
} |
| 289 |
if (isset($SF_dat['img'])) { |
| 290 |
$out[]='<meta property="og:image" content="'.$SF_dat['img'].'" />'; |
| 291 |
$out[]='<meta property="og:image:secure_url" content="'.str_replace('http://','https://',$SF_dat['img']).'" />'; |
| 292 |
} |
| 293 |
if (isset($SF_dat['sum'])) { |
| 294 |
$out[]='<meta property="og:description" content="'.str_replace('"','"',$SF_dat['sum']).'" />'; |
| 295 |
} |
| 296 |
if (isset($_GET['_escaped_fragment_'])&&isset($SF_dat['rel'])) { |
| 297 |
$out[]='<meta property="og:url" content="'.$SF_dat['rel'].'" />'; |
| 298 |
$out[]='<link rel="canonical" href="'.$SF_dat['rel'].'" />'; |
| 299 |
} |
| 300 |
if (isset($SF_dat['nxt'])) |
| 301 |
$out[]='<link rel="next" href="'.$SF_dat['nxt'].'" />'; |
| 302 |
if (isset($SF_dat['prv'])) |
| 303 |
$out[]='<link rel="prev" href="'.$SF_dat['prv'].'" />'; |
| 304 |
echo implode("\r\n",$out).(count($out)?"\r\n":''); |
| 305 |
} |
| 306 |
} |
| 307 |
|
| 308 |
function sf_shortcode($content) { |
| 309 |
global $SF_dat; |
| 310 |
$opn=false; |
| 311 |
$set=get_option('sf_set'); |
| 312 |
$wpl=defined('SF_WPL')?preg_replace('/^http[s]?:\\/\\/[^\\/]*/','',SF_WPL>=3?admin_url('admin-ajax.php'):site_url('wp-login.php','login_post')):(empty($set['wpl'])?'':$set['wpl']); |
| 313 |
$lbl=array(); |
| 314 |
$dek=array(); |
| 315 |
// process memberonly shortcodes - first pass - eliminate admins, obtain labels to test for |
| 316 |
if (!defined('SF_WPL')||SF_WPL>=5) for ($i=0;$i<strlen($content)&&($x=strpos($content,'[memberonly',$i))!==false;) { |
| 317 |
$y=strpos($content,']',$x); |
| 318 |
if (($x>0&&substr($content,$x-1,1)=='[')||$y===false) { $i=$x+1; continue; } // escaped shortcode or shortcode not closed |
| 319 |
if (!defined('DONOTCACHEPAGE')) |
| 320 |
define('DONOTCACHEPAGE',true); |
| 321 |
if (($z=strpos($content,'[/memberonly]',$y))===false) { $z=strlen($content); $l=$z-$y-1; } else { $l=$z-$y-1; $z+=13; } |
| 322 |
$str=substr($content,$x+1,$y-$x-1); |
| 323 |
$mat=array(); |
| 324 |
$opt=array(); |
| 325 |
if (preg_match_all('/\s([a-z\-]*)(=("|“|”|&[^;]*;)+.*?("|“|”|&[^;]*;))?/',$str,$mat,PREG_PATTERN_ORDER)&&!empty($mat)&&!empty($mat[1])) foreach($mat[1] as $key=>$val) |
| 326 |
$opt[$val]=empty($mat[2][$key])?'':trim(preg_replace('/^=("|“|”|&[^;]*;)*|("|“|”|&[^;]*;)*$/','',$mat[2][$key])); |
| 327 |
if (empty($set)||empty($set['org'])) { |
| 328 |
$out='Organization key not setup. Please update settings.'; |
| 329 |
} else if (current_user_can('edit_post',get_the_ID())) { |
| 330 |
$tmp=array(); |
| 331 |
foreach ($opt as $key=>$val) $tmp[]=$key.'="'.$val.'"'; |
| 332 |
$out='[administrator notice: content below memberonly '.implode(' ',$tmp).']' |
| 333 |
.substr($content,$y+1,$l); |
| 334 |
} else { |
| 335 |
if (!empty($opt['label'])||!empty($opt['level'])) { |
| 336 |
$arr=explode(',',empty($opt['label'])?$opt['level']:$opt['label']); |
| 337 |
foreach ($arr as $val) if (trim(urldecode($val))) $lbl[]=strtolower(trim(urldecode($val))); |
| 338 |
} else if (!empty($opt['folder'])||!empty($opt['folders'])) { |
| 339 |
$arr=explode(',',empty($opt['folder'])?$opt['folders']:$opt['folder']); |
| 340 |
foreach ($arr as $val) if (trim(urldecode($val))) $dek[]=strtolower(trim(urldecode($val))); |
| 341 |
} else { |
| 342 |
$dek[]='members'; |
| 343 |
} |
| 344 |
$i=$z+1; |
| 345 |
continue; |
| 346 |
} |
| 347 |
$content=substr_replace($content,$out,$x,$z-$x); |
| 348 |
$i=$x+strlen($out); |
| 349 |
} |
| 350 |
// check if user has required labels |
| 351 |
if (!empty($_SERVER)&&!empty($_SERVER['HTTP_COOKIE'])&&preg_match('/^SFSF=[^;]*|\\sSFSF=[^;]*/',$_SERVER['HTTP_COOKIE'],$_sf)) |
| 352 |
$_sf=preg_replace('/\\s|\\+/','',substr($_sf[0],strpos($_sf[0],'=')+1)); |
| 353 |
else if (!empty($_COOKIE['SFSF'])) |
| 354 |
$_sf=strlen($_COOKIE['SFSF'])<2?'':$_COOKIE['SFSF']; |
| 355 |
else |
| 356 |
$_sf=''; |
| 357 |
if (!$_sf||(empty($lbl)&&empty($dek))) { |
| 358 |
$usr=false; |
| 359 |
} else { |
| 360 |
$tmp=array('org'=>$set['org'],'sfsf'=>$_sf); |
| 361 |
if (!empty($lbl)) $tmp['lbl']=array_values(array_unique($lbl)); |
| 362 |
if (!empty($dek)) $tmp['dek']=array_values(array_unique($dek)); |
| 363 |
$usr=sf_api(empty($set['ssl'])||$set['ssl']!='2'?'https':'http','GET','v1/lbl',$tmp); |
| 364 |
if (empty($usr)) |
| 365 |
$usr=array('error'=>true); |
| 366 |
else if (!empty($usr['uid'])&&isset($_GET['uid'])&&$usr['uid']!=$_GET['uid']) |
| 367 |
$usr=false; |
| 368 |
else if (!empty($usr['lbl'])) { |
| 369 |
foreach($usr['lbl'] as $i=>$x) { |
| 370 |
if ($x['typ']==1) |
| 371 |
$usr['_dek'][]=strtolower($x['lbl']); |
| 372 |
else |
| 373 |
$usr['_lbl'][]=strtolower($x['lbl']); |
| 374 |
} |
| 375 |
} |
| 376 |
} |
| 377 |
// process memberonly shortcodes - second pass |
| 378 |
if (!empty($lbl)||!empty($dek)) for ($i=0;$i<strlen($content)&&($x=strpos($content,'[memberonly',$i))!==false;) { |
| 379 |
$y=strpos($content,']',$x); |
| 380 |
if (($x>0&&substr($content,$x-1,1)=='[')||$y===false) { $i=$x+1; continue; } // escaped shortcode or shortcode not closed |
| 381 |
if (($z=strpos($content,'[/memberonly]',$y))===false) { $z=strlen($content); $l=$z-$y-1; } else { $l=$z-$y-1; $z+=13; } |
| 382 |
$str=substr($content,$x+1,$y-$x-1); |
| 383 |
$mat=array(); |
| 384 |
$opt=array(); |
| 385 |
if (preg_match_all('/\s([a-z\-]*)(=("|“|”|&[^;]*;)+.*?("|“|”|&[^;]*;))?/',$str,$mat,PREG_PATTERN_ORDER)&&!empty($mat)&&!empty($mat[1])) foreach($mat[1] as $key=>$val) |
| 386 |
$opt[$val]=empty($mat[2][$key])?'':trim(preg_replace('/^=("|“|”|&[^;]*;)*|("|“|”|&[^;]*;)*$/','',$mat[2][$key])); |
| 387 |
if (!empty($usr)&&!empty($usr['error'])&&$usr['error']!='No response') { |
| 388 |
$out=$usr['error']; |
| 389 |
} else { |
| 390 |
if (empty($usr)) { |
| 391 |
$msg=isset($opt['message'])?$opt['message']:(empty($set['mol'])?'The following content is accessible for members only, please sign in.':$set['mol']); |
| 392 |
} else if (!empty($usr['error'])) { |
| 393 |
$msg=isset($opt['message'])?$opt['message']:(empty($set['moi'])?'Your session has expired, please sign in again.':$set['moi']); |
| 394 |
} else if (!empty($usr['end'])) { |
| 395 |
$msg=isset($opt['message'])?$opt['message']:(empty($set['moe'])?'The following content is not accessible because your membership has expired.':$set['moe']); |
| 396 |
} else { |
| 397 |
$msg=isset($opt['message'])?$opt['message']:(empty($set['mon'])?'The following content is not accessible for your account.':$set['mon']); |
| 398 |
if (!empty($opt['label'])||!empty($opt['level'])) { |
| 399 |
$arr=explode(',',empty($opt['label'])?$opt['level']:$opt['label']); |
| 400 |
foreach ($arr as $key=>$val) $arr[$key]=strtolower(trim(urldecode($val))); |
| 401 |
if (!empty($usr['_lbl'])&&count(array_intersect($usr['_lbl'],$arr))) $msg=false; |
| 402 |
} else if (!empty($opt['folder'])||!empty($opt['folders'])) { |
| 403 |
$arr=explode(',',empty($opt['folder'])?$opt['folders']:$opt['folder']); |
| 404 |
foreach ($arr as $key=>$val) $arr[$key]=strtolower(trim(urldecode($val))); |
| 405 |
if (!empty($usr['_dek'])&&count(array_intersect($usr['_dek'],$arr))) $msg=false; |
| 406 |
} else { |
| 407 |
if (!empty($usr['_dek'])&&in_array('members',$usr['_dek'])) $msg=false; |
| 408 |
} |
| 409 |
} |
| 410 |
if ($msg===false&&isset($opt['false'])) { |
| 411 |
$out=''; |
| 412 |
} else if ($msg===false||isset($opt['false'])) { |
| 413 |
$out=trim(preg_replace('/^<br(\\s\\/)?>|<br(\\s\\/)?>$/','',substr($content,$y+1,$l))); |
| 414 |
} else if (is_singular()&&!empty($opt['nonmember-redirect'])) { |
| 415 |
$out=(isset($opt['nomessage'])?'':('<span class="memberonly">'.__($msg).'</span>')) |
| 416 |
.'<script>setTimeout(\'window.location="'.esc_url($opt['nonmember-redirect']).'"\',2000);</script>'; |
| 417 |
$opn=true; |
| 418 |
} else if (is_singular()&&!$opn&&!empty($opt['nonmember'])) { |
| 419 |
$out=(isset($opt['nomessage'])?'':('<div class="memberonly" style="margin-bottom:20px">'.__($msg).'</div>')) |
| 420 |
.'[mw open="'.$opt['nonmember'].'"]'; |
| 421 |
} else if (is_singular()&&!$opn&&(empty($usr)||!empty($usr['error']))&&!isset($opt['nologin'])) { |
| 422 |
$out='<div class="memberonlywrapper" style="padding:40px 0 0;margin:40px 0;border-top:1px solid #ddd;border-bottom:1px solid #ddd">' |
| 423 |
.(isset($opt['nomessage'])?'':('<div class="memberonly" style="margin-bottom:20px">'.__($msg).'</div>')) |
| 424 |
.'<div id="SFctr" class="SF" data-sfi="1" data-org="'.$set['org'].'" data-ini="myaccount" data-zzz="'.esc_url(get_permalink()).'"' |
| 425 |
.(empty($wpl)?'':' data-wpl="'.esc_url($wpl).'"') |
| 426 |
.' style="position:relative;height:auto;margin-bottom:40px">' |
| 427 |
.'<div id="SFpne" style="position:relative"><div class="SFpne">Loading...</div></div>' |
| 428 |
.'<div style="clear:both"></div>' |
| 429 |
.(empty($set['htm'])?'':'<script type="text/javascript" src="https://cdn.membershipworks.com/mfm.js" defer="defer"></script>') |
| 430 |
.'</div></div>'; |
| 431 |
if (empty($set['htm'])) |
| 432 |
wp_enqueue_script('sf-mfm'); |
| 433 |
$opn=true; |
| 434 |
} else { |
| 435 |
$out=(isset($opt['nomessage'])?'':('<span class="memberonly">'.__($msg).'</span>')); |
| 436 |
} |
| 437 |
} |
| 438 |
$content=substr_replace($content,$out,$x,$z-$x); |
| 439 |
$i=$x+strlen($out); |
| 440 |
} |
| 441 |
// process mw shortcodes |
| 442 |
for ($i=0;$i<strlen($content)&&(($x=strpos($content,'[memberfindme ',$i))!==false||($x=strpos($content,'[mw ',$i))!==false);) { |
| 443 |
$y=strpos($content,']',$x); |
| 444 |
if (($x>0&&substr($content,$x-1,1)=='[')||$y===false) { $i=$x+1; continue; } // escaped shortcode or shortcode not closed |
| 445 |
$str=substr($content,$x+1,$y-$x-1); |
| 446 |
$mat=array(); |
| 447 |
$opt=array(); |
| 448 |
if (!preg_match_all('/\s([a-z\-]*)(=("|“|”|&[^;]*;)+.*?("|“|”|&[^;]*;))?/',$str,$mat,PREG_PATTERN_ORDER)||empty($mat)||empty($mat[1])) { $i=$x+1; continue; } |
| 449 |
foreach ($mat[1] as $key=>$val) $opt[$val]=empty($mat[2][$key])?'':trim(preg_replace('/^=("|“|”|&[^;]*;)*|("|“|”|&[^;]*;)*$/','',$mat[2][$key])); |
| 450 |
// create output |
| 451 |
if (empty($set)||empty($set['org'])) { |
| 452 |
$out='Organization key not setup. Please update settings'; |
| 453 |
} else if (!$opn&&isset($opt['open'])) { |
| 454 |
$out=(empty($set['htm'])?'':'<div style="display:none"><script>if(typeof(SF)=="object"&&SF.close)SF.close();</script></div>') |
| 455 |
.'<div id="SFctr" class="SF" data-org="'.$set['org'].'" data-ini="'.$opt['open'].'"' |
| 456 |
.(empty($set['pay'])?'':(' data-pay="'.$set['pay'].'"')) |
| 457 |
.(empty($set['map'])?'':(' data-map="'.$set['map'].'"')) |
| 458 |
.(empty($set['fbk'])?'':(' data-fbk="'.$set['fbk'].'"')) |
| 459 |
.(empty($set['fnd'])?'':(' data-fnd="'.$set['fnd'].'"')) |
| 460 |
.(empty($set['rsp'])?'':(' data-rsp="'.$set['rsp'].'"')) |
| 461 |
.(empty($set['ctc'])?'':(' data-ctc="1"')) |
| 462 |
.(empty($set['scl'])&&empty($opt['noshare'])?'':(' data-scl="0"')) |
| 463 |
.(empty($set['wgo'])?'':(' data-wgo="1"')) |
| 464 |
.(empty($set['out'])?'':(' data-out="'.$set['out'].'"')) |
| 465 |
.(empty($set['top'])?'':(' data-top="'.$set['top'].'"')) |
| 466 |
.(empty($wpl)?'':' data-wpl="'.esc_url($wpl).'"') |
| 467 |
.(empty($opt['lbl'])&&empty($opt['labels'])?'':(' data-lbl="'.esc_attr(empty($opt['lbl'])?$opt['labels']:$opt['lbl']).'"')) |
| 468 |
.(empty($opt['folder'])?'':(' data-dek="'.esc_attr($opt['folder']).'"')) |
| 469 |
.(empty($opt['levels'])?'':(' data-lvl="'.esc_attr($opt['levels']).'"')) |
| 470 |
.(isset($opt['evg'])?(' data-evg="'.esc_attr($opt['evg']).'"'):'') |
| 471 |
.(isset($opt['viewport'])&&$opt['viewport']=='fixed'?(' data-ofy="1"'):'') |
| 472 |
.(isset($opt['redirect'])?(' data-zzz="'.$opt['redirect'].'"'):'') |
| 473 |
.(isset($opt['checkout'])?(' data-zgo="'.$opt['checkout'].'"'):'') |
| 474 |
.(isset($opt['ini'])&&$opt['ini']=='0'?'':' data-sfi="1"') |
| 475 |
.' style="'.(isset($opt['style'])?$opt['style']:'position:relative;height:auto').'">' |
| 476 |
.'<div id="SFpne" style="position:relative">' |
| 477 |
.(empty($SF_dat)?(isset($opt['ini'])&&$opt['ini']=='0'?'':'<div class="SFpne">Loading...</div>'):$SF_dat['dtl']) |
| 478 |
.'</div>' |
| 479 |
.'<div id="SFfin" style="clear:both"></div>' |
| 480 |
.(empty($set['htm'])?'':'<script type="text/javascript" src="https://cdn.membershipworks.com/mfm.js"></script>') |
| 481 |
.'</div>'; |
| 482 |
if (empty($set['htm'])) |
| 483 |
wp_enqueue_script('sf-mfm'); |
| 484 |
if (!defined('DONOTCACHEPAGE')) |
| 485 |
define('DONOTCACHEPAGE',true); |
| 486 |
$opn=true; |
| 487 |
} else if (isset($opt['button'])) { |
| 488 |
$out=(isset($opt['type'])?('<'.$opt['type']):'<button') |
| 489 |
.(isset($opt['type'])&&$opt['type']=='img'&&isset($opt['src'])?(' src="'.$opt['src'].'"'):'') |
| 490 |
.(isset($opt['class'])?(' class="'.$opt['class'].'"'):'') |
| 491 |
.(isset($opt['style'])?(' style="'.$opt['style'].'"'):' style="cursor:pointer;"') |
| 492 |
.($opt['button']=='account'?(' onmouseout="if(typeof(SF)!=\'undefined\')SF.usr.account(event,this);" onmouseover="if(typeof(SF)!=\'undefined\')SF.usr.account(event,this);" onclick="if(typeof(SF)!=\'undefined\')SF.usr.account(event,this);">'.(isset($opt['text'])?$opt['text']:'My Account')):'') |
| 493 |
.($opt['button']=='join'?(' onclick="if(typeof(SF)!=\'undefined\')SF.open(\'account/join\');">'.(isset($opt['text'])?$opt['text']:'Join')):'') |
| 494 |
.(isset($opt['type'])?($opt['type']=='img'?'':('</'.$opt['type'].'>')):'</button>'); |
| 495 |
} else if (isset($opt['join'])) { |
| 496 |
$out=(isset($opt['type'])?('<'.$opt['type']):'<a') |
| 497 |
.(isset($opt['type'])&&$opt['type']=='img'&&isset($opt['src'])?(' src="'.$opt['src'].'"'):'') |
| 498 |
.(isset($opt['class'])?(' class="'.$opt['class'].'"'):'') |
| 499 |
.(isset($opt['style'])?(' style="'.$opt['style'].'"'):' style="cursor:pointer;"') |
| 500 |
.(isset($opt['type'])&&$opt['type']!='a'?(' onclick="window.location.hash=\'account/join/'.$opt['join'].'\';if(typeof(SF)!=\'undefined\')setTimeout(\'SF.init()\',50);">'):(' onclick="if(typeof(SF)!=\'undefined\')setTimeout(\'SF.init()\',50)" href="#account/join/'.$opt['join'].'">')) |
| 501 |
.(isset($opt['text'])?$opt['text']:'Join') |
| 502 |
.(isset($opt['type'])?($opt['type']=='img'?'':('</'.$opt['type'].'>')):'</a>'); |
| 503 |
} else if (isset($opt['name'])||isset($opt['check'])) { |
| 504 |
if (!isset($usl)) |
| 505 |
$usl=!empty($wpl)&&is_user_logged_in()&&get_user_meta(get_current_user_id(),'SF_ID',true)?wp_get_current_user():false; |
| 506 |
$out=(isset($opt['name'])?'<span class="SFnam">'.(empty($usl)?'':$usl->display_name).'</span>':'') |
| 507 |
.($opn||(isset($opt['name'])&&!empty($usl))?'':'<script>(function(){var i,j,a,x;try{x=localStorage.getItem("SF_nam");}catch(e){x="";}try{for(a=document.querySelectorAll(".SFnam"),i=a.length-1;i>=0;i--)a[i].innerHTML=x?x:"";}catch(e){}try{for(a=document.querySelectorAll(".SF_li"),i=a.length-1;i>=0;i--)a[i].style.display=x?"":"none";}catch(e){}try{for(a=document.querySelectorAll(".SF_lo"),i=a.length-1;i>=0;i--)a[i].style.display=x?"none":"";}catch(e){}})();</script>'); |
| 508 |
if (!defined('DONOTCACHEPAGE')) |
| 509 |
define('DONOTCACHEPAGE',true); |
| 510 |
} else if (isset($opt['listlabel'])||isset($opt['listfolder'])) { |
| 511 |
$dat=sf_api(empty($set['ssl'])?'https':'http','GET','v1/dek',array('org'=>$set['org'],'wem'=>1,'typ'=>isset($opt['listlabel'])?3:1,'lbl'=>isset($opt['listlabel'])?$opt['listlabel']:$opt['listfolder'])); |
| 512 |
if (!empty($dat)&&!empty($dat['error'])) |
| 513 |
$out=$dat['error']; |
| 514 |
else { |
| 515 |
$out=array(); |
| 516 |
if (!empty($dat)) foreach($dat as $usr) |
| 517 |
$out[]='<li><a href="'.$usr['url'].'">'.$usr['nam'].'</a></li>'; |
| 518 |
$out='<ul class="sf_list">'.implode('',$out).'</ul>'; |
| 519 |
} |
| 520 |
} else if (isset($opt['listevents'])) { |
| 521 |
$dat=sf_api(empty($set['ssl'])?'https':'http','GET','v1/evt',array('org'=>$set['org'],'wee'=>1,'grp'=>$opt['listevents'],'cnt'=>isset($opt['count'])?$opt['count']:'5','sdp'=>time())); |
| 522 |
if (!empty($dat)&&!empty($dat['error'])) |
| 523 |
$out=$dat['error']; |
| 524 |
else { |
| 525 |
$out=array(); |
| 526 |
if (!empty($dat)) foreach ($dat as $evt) { |
| 527 |
$te=explode(',',$evt['ezp']); |
| 528 |
$ts=explode(',',$evt['szp']); |
| 529 |
if (!empty($evt['ezp'])&&$te[0]==$ts[0]) $evt['ezp']=trim($te[1]); |
| 530 |
$out[]='<li><a href="'.$evt['url'].'">'.$evt['ttl'].'</a><div class="event-when"><span class="event-start">'.$evt['szp'].'</span>'.(isset($evt['ezp'])&&$evt['ezp']?('<span class="event-sep"> - </span><span class="event-end">'.$evt['ezp'].'</span>'):'').'</div></li>'; |
| 531 |
} |
| 532 |
$out='<ul class="sf_list">'.implode('',$out).'</ul>'; |
| 533 |
} |
| 534 |
} else if (isset($opt['eventwidget'])) { |
| 535 |
$out=sf_widget_event_do(array_merge($opt,array('org'=>$set['org'])),$set); |
| 536 |
} else if (isset($opt['folderwidget'])) { |
| 537 |
$out=sf_widget_folder_do(array_merge($opt,array('org'=>$set['org'])),$set); |
| 538 |
} else { |
| 539 |
$out=''; |
| 540 |
} |
| 541 |
$content=substr_replace($content,$out,$x,$y-$x+1); |
| 542 |
$i=$x+strlen($out); |
| 543 |
} |
| 544 |
if (!$opn&&!empty($SF_dat)&&($x=strpos($content,'<div id="SFpne" style="position:relative">'))!==false&&($y=strpos($content,'<div id="SFfin" style="clear:both">'))!==false) { |
| 545 |
// replace again in case wp_autop mucks things up |
| 546 |
$content=substr_replace($content,'<div id="SFpne" style="position:relative">'.$SF_dat['dtl'].'</div>',$x,$y-$x); |
| 547 |
} |
| 548 |
return $content; |
| 549 |
} |
| 550 |
add_filter('the_content','sf_shortcode',9); |
| 551 |
add_filter('the_content','sf_shortcode',99); |
| 552 |
add_filter('widget_text','sf_shortcode',1); |
| 553 |
|
| 554 |
function sf_widget_event_do($instance,$set) { |
| 555 |
if (empty($instance['org'])) |
| 556 |
return '<div>No organization ID</div>'; |
| 557 |
$instance=wp_parse_args($instance,array('grp'=>'','cnt'=>'3')); |
| 558 |
$dat=sf_api(empty($set)||empty($set['ssl'])?'https':'http','GET','v1/evt',array('org'=>$instance['org'],'wee'=>1,'grp'=>$instance['grp'],'cnt'=>$instance['cnt'],'sdp'=>time())); |
| 559 |
if (empty($dat)) |
| 560 |
return '<div>No current events</div>'; |
| 561 |
if (!empty($dat)&&!empty($dat['error'])) |
| 562 |
return '<div>'.$dat['error'].'</div>'; |
| 563 |
$out=array(); |
| 564 |
foreach ($dat as $x) { |
| 565 |
$ts=explode(',',$x['szp']); |
| 566 |
if (empty($instance['szp'])&&!empty($x['ezp'])) { |
| 567 |
$te=explode(',',$x['ezp']); |
| 568 |
if ($te[0]==$ts[0]) $x['ezp']=trim($te[1]); |
| 569 |
} |
| 570 |
$out[]='<li class="event-item">' |
| 571 |
.'<a class="event-link" href="'.esc_url($x['url']).'">' |
| 572 |
.(empty($x['lgo'])||empty($instance['lgo'])?'':('<img class="event-thumb" src="//d1tif55lvfk8gc.cloudfront.net/'.$x['_id'].'s.jpg?'.$x['lgo'].'" style="max-width:100%"/>')) |
| 573 |
.$x['ttl'] |
| 574 |
.'</a>' |
| 575 |
.(empty($instance['szp'])||(empty($instance['exp'])&&!empty($x['ezp']))?('<div class="event-when">' |
| 576 |
.(empty($instance['szp'])?('<span class="event-start">'.$x['szp'].'</span>'):'') |
| 577 |
.(empty($instance['szp'])&&empty($instance['ezp'])&&!empty($x['ezp'])?'<span class="event-sep"> - </span>':'') |
| 578 |
.(empty($instance['ezp'])&&!empty($x['ezp'])?('<span class="event-end">'.$x['ezp'].'</span>'):'') |
| 579 |
.'</div>'):'') |
| 580 |
.(empty($instance['adn'])||empty($x['adn'])?'':('<div class="event-where">'.$x['adn'].'</div>')) |
| 581 |
.'</li>'; |
| 582 |
} |
| 583 |
return '<ul class="sf_widget_event_list" style="display:block;position:relative">'.implode($out).'</ul>'; |
| 584 |
} |
| 585 |
|
| 586 |
class sf_widget_event extends WP_Widget { |
| 587 |
public function __construct() { |
| 588 |
parent::__construct('sf_widget_event','Upcoming Events',array('description'=>'Upcoming events from your MembershipWorks calendar')); |
| 589 |
} |
| 590 |
public function widget($args,$instance ) { |
| 591 |
extract($args); |
| 592 |
$set=get_option('sf_set'); |
| 593 |
$title=apply_filters('widget_title',$instance['title']); |
| 594 |
if (empty($title)) |
| 595 |
echo str_replace('widget_sf_widget_event','widget_sf_widget_event widget_no_title',$before_widget); |
| 596 |
else |
| 597 |
echo $before_widget.$before_title.$title.$after_title; |
| 598 |
echo sf_widget_event_do(array_merge($instance,array('org'=>$set['org'])),$set); |
| 599 |
echo $after_widget; |
| 600 |
} |
| 601 |
public function update($new_instance,$old_instance ) { |
| 602 |
$instance=$old_instance; |
| 603 |
$instance['title']=strip_tags($new_instance['title']); |
| 604 |
$instance['grp']=isset($new_instance['grp'])?$new_instance['grp']:''; |
| 605 |
$instance['cnt']=$new_instance['cnt']?strval(intval($new_instance['cnt'])):'0'; |
| 606 |
if (empty($new_instance['lgo'])) unset($instance['lgo']); else $instance['lgo']=1; |
| 607 |
if (empty($new_instance['adn'])) unset($instance['adn']); else $instance['adn']=1; |
| 608 |
if (empty($new_instance['szp'])) $instance['szp']=1; else unset($instance['szp']); |
| 609 |
if (empty($new_instance['ezp'])) $instance['ezp']=1; else unset($instance['ezp']); |
| 610 |
return $instance; |
| 611 |
} |
| 612 |
public function form($instance) { |
| 613 |
$instance=wp_parse_args($instance,array('title'=>'','grp'=>'','cnt'=>'3')); |
| 614 |
$title=strip_tags($instance['title']); |
| 615 |
$grp=$instance['grp']; |
| 616 |
$cnt=intval($instance['cnt']); |
| 617 |
echo '<p><label for="'.esc_attr($this->get_field_id('title')).'">Title:</label> <input class="widefat" id="'.esc_attr($this->get_field_id('title')).'" name="'.esc_attr($this->get_field_name('title')).'" type="text" value="'.esc_attr($title).'" /></p>' |
| 618 |
.'<p><label for="'.esc_attr($this->get_field_id('grp')).'">Category number (blank=all):</label> <input id="'.esc_attr($this->get_field_id('grp')).'" name="'.esc_attr($this->get_field_name('grp')).'" type="text" value="'.esc_attr($grp).'" size="3"/></p>' |
| 619 |
.'<p><label for="'.esc_attr($this->get_field_id('cnt')).'">Number of events to show:</label> <input id="'.esc_attr($this->get_field_id('cnt')).'" name="'.esc_attr($this->get_field_name('cnt')).'" type="text" value="'.esc_attr($cnt).'" size="3"/></p>' |
| 620 |
.'<p><label for="'.esc_attr($this->get_field_id('lgo')).'">Display images:</label> <input id="'.esc_attr($this->get_field_id('lgo')).'" name="'.esc_attr($this->get_field_name('lgo')).'" type="checkbox" value="1"'.(empty($instance['lgo'])?'':' checked').'/></p>' |
| 621 |
.'<p><label for="'.esc_attr($this->get_field_id('adn')).'">Display location:</label> <input id="'.esc_attr($this->get_field_id('adn')).'" name="'.esc_attr($this->get_field_name('adn')).'" type="checkbox" value="1"'.(empty($instance['adn'])?'':' checked').'/></p>' |
| 622 |
.'<p><label for="'.esc_attr($this->get_field_id('szp')).'">Display start date/time:</label> <input id="'.esc_attr($this->get_field_id('szp')).'" name="'.esc_attr($this->get_field_name('szp')).'" type="checkbox" value="1"'.(empty($instance['szp'])?' checked':'').'/></p>' |
| 623 |
.'<p><label for="'.esc_attr($this->get_field_id('ezp')).'">Display end date/time:</label> <input id="'.esc_attr($this->get_field_id('ezp')).'" name="'.esc_attr($this->get_field_name('ezp')).'" type="checkbox" value="1"'.(empty($instance['ezp'])?' checked':'').'/></p>'; |
| 624 |
} |
| 625 |
} |
| 626 |
|
| 627 |
function sf_widget_folder_do($instance,$set) { |
| 628 |
global $SF_widgetid; |
| 629 |
if (empty($instance['org'])) |
| 630 |
return '<div>No organization ID</div>'; |
| 631 |
$instance=wp_parse_args($instance,array('typ'=>'1','lbl'=>'Members','act'=>'0','delay'=>'10','nam'=>'')); |
| 632 |
$dat=sf_api(empty($set)||empty($set['ssl'])?'https':'http','GET','v1/dek',array('org'=>$instance['org'],'wem'=>1,'typ'=>empty($instance['typ'])?'1':$instance['typ'],'lbl'=>$instance['lbl'])); |
| 633 |
if (!empty($dat)&&!empty($dat['error'])) |
| 634 |
return '<div>'.$dat['error'].'</div>'; |
| 635 |
$out=array(); |
| 636 |
if (!empty($dat)) foreach($dat as $x) { |
| 637 |
if ($instance['act']=='1') |
| 638 |
$out[]='<li style="display:none;background-color:white;text-align:center;height:148px;padding:0;margin:0;table-layout:fixed;width:100%;"><a href="'.esc_url($x['url']).'" style="display:table-cell;vertical-align:middle;padding:10px;text-decoration:none;">' |
| 639 |
.(empty($x['lgo'])?'':('<div class="member-image"><img src="https://cdn.membershipworks.com/u/'.$x['_id'].'_lgl.jpg?'.$x['lgo'].'" alt="'.esc_attr($x['nam']).'" onerror="this.parentNode.innerHTML=this.alt;" style="display:block;margin:0 auto;max-width:100%;max-height:75px;"></div>')) |
| 640 |
.(empty($x['lgo'])||!empty($instance['nam'])?('<div class="member-name" style="display:block;width:100%;font-size:'.($x['lgo']?'1.1em':'1.5em').'">'.esc_html(html_entity_decode($x['nam'],ENT_HTML5|ENT_QUOTES)).'</div>'):'') |
| 641 |
.(empty($x['cnm'])?'':('<small class="member-tagline" style="display:block;padding:10px;">'.esc_html(html_entity_decode($x['cnm'],ENT_HTML5|ENT_QUOTES)).'</small>')) |
| 642 |
.'</a></li>'; |
| 643 |
else |
| 644 |
$out[]='<li><a href="'.esc_url($x['url']).'">' |
| 645 |
.(empty($x['lgo'])||empty($instance['lgo'])?'':('<div class="member-image"><img src="https://cdn.membershipworks.com/u/'.$x['_id'].'_lgl.jpg?'.$x['lgo'].'" alt="'.esc_attr($x['nam']).'" onerror="this.parentNode.innerHTML=this.alt;" style="display:block;margin:0 auto;max-width:100%;max-height:75px;"></div>')) |
| 646 |
.'<span class="member-name">'.esc_html(html_entity_decode($x['nam'],ENT_HTML5|ENT_QUOTES)).'</span>' |
| 647 |
.(empty($x['cnm'])?'':('<small class="member-tagline" style="display:block;">'.esc_html(html_entity_decode($x['cnm'],ENT_HTML5|ENT_QUOTES)).'</small>')) |
| 648 |
.'</a></li>'; |
| 649 |
} |
| 650 |
$id=empty($instance['wid'])?('sf-widget-'.($SF_widgetid++)):$instance['wid']; |
| 651 |
if ($instance['act']=='1') { |
| 652 |
$delay=intval($instance['delay'])*1000; |
| 653 |
$fn=str_replace('-','_',$id); |
| 654 |
return '<ul id="'.$id.'" class="sf_widget_folder_logos" style="list-style:none;margin:0;padding:5px">'.implode($out).'</ul>' |
| 655 |
.(empty($out)?'':('<script>'.$fn.'_animate=function(){var r=document.getElementById("'.$id.'"),x=r.querySelector(\'li[style*="table;"]\');if(x){x.style.display="none";x=(x.nextSibling?x.nextSibling:r.firstChild);}else x=r.childNodes[Math.round(Math.random()*(r.childNodes.length-1))];if(x)x.style.display="table";setTimeout('.$fn.'_animate,'.($delay?$delay:10000).');};'.$fn.'_animate();</script>')); |
| 656 |
} else { |
| 657 |
return '<ul id="'.$id.'" class="sf_widget_folder_list">'.implode($out).'</ul>'; |
| 658 |
} |
| 659 |
} |
| 660 |
|
| 661 |
class sf_widget_folder extends WP_Widget { |
| 662 |
public function __construct() { |
| 663 |
parent::__construct('sf_widget_folder','Members/Folder Widget',array('description'=>'Display contacts from your MembershipWorks folder or label')); |
| 664 |
} |
| 665 |
public function widget($args,$instance ) { |
| 666 |
extract($args); |
| 667 |
$set=get_option('sf_set'); |
| 668 |
$title=apply_filters('widget_title',$instance['title']); |
| 669 |
if (empty($title)) |
| 670 |
echo str_replace('widget_sf_widget_folder','widget_sf_widget_folder widget_no_title',$before_widget); |
| 671 |
else |
| 672 |
echo $before_widget.$before_title.$title.$after_title; |
| 673 |
echo sf_widget_folder_do(array_merge($instance,array('org'=>$set['org'],'wid'=>($this->id).'-list')),$set); |
| 674 |
echo $after_widget; |
| 675 |
} |
| 676 |
public function update($new_instance,$old_instance ) { |
| 677 |
$instance=$old_instance; |
| 678 |
$instance['title']=strip_tags($new_instance['title']); |
| 679 |
$instance['lbl']=trim($new_instance['lbl']); |
| 680 |
$instance['typ']=strval(intval($new_instance['typ'])); |
| 681 |
$instance['act']=strval(intval($new_instance['act'])); |
| 682 |
$instance['delay']=strval(intval($new_instance['delay'])); |
| 683 |
if (empty($new_instance['nam'])) |
| 684 |
unset($instance['nam']); |
| 685 |
else |
| 686 |
$instance['nam']=1; |
| 687 |
return $instance; |
| 688 |
} |
| 689 |
public function form($instance) { |
| 690 |
$instance=wp_parse_args($instance,array('title'=>'','typ'=>'1','lbl'=>'Members','act'=>'0','delay'=>'10','nam'=>'')); |
| 691 |
$title=strip_tags($instance['title']); |
| 692 |
echo '<p><label for="'.esc_attr($this->get_field_id('title')).'">Title:</label> <input class="widefat" id="'.esc_attr($this->get_field_id('title')).'" name="'.esc_attr($this->get_field_name('title')).'" type="text" value="'.esc_attr($title).'" /></p>' |
| 693 |
.'<p><label for="'.esc_attr($this->get_field_id('lbl')).'">Folder/label name:</label> <input class="widefat" id="'.esc_attr($this->get_field_id('lbl')).'" name="'.esc_attr($this->get_field_name('lbl')).'" type="text" value="'.esc_attr($instance['lbl']).'" /></p>' |
| 694 |
.'<p><label for="'.esc_attr($this->get_field_id('typ')).'">Type:</label> <select id="'.esc_attr($this->get_field_id('typ')).'" name="'.esc_attr($this->get_field_name('typ')).'">' |
| 695 |
.'<option value="1"'.($instance['typ']=='1'?' selected="selected"':'').'>Public folder</option>' |
| 696 |
.'<option value="3"'.($instance['typ']=='3'?' selected="selected"':'').'>Publicly searchable label</option>' |
| 697 |
.'</select></p>' |
| 698 |
.'<p><label for="'.esc_attr($this->get_field_id('act')).'">Display:</label> <select id="'.esc_attr($this->get_field_id('act')).'" name="'.esc_attr($this->get_field_name('act')).'" onchange="this.parentNode.nextSibling.style.display=(this.value==\'1\'?\'\':\'none\');">' |
| 699 |
.'<option value="0"'.($instance['act']=='0'?' selected="selected"':'').'>List</option>' |
| 700 |
.'<option value="1"'.($instance['act']=='1'?' selected="selected"':'').'>Slideshow</option>' |
| 701 |
.'</select></p>' |
| 702 |
.'<div'.($instance['act']=='1'?'>':' style="display:none;">') |
| 703 |
.'<p><label for="'.esc_attr($this->get_field_id('delay')).'">Seconds between slides:</label> <input id="'.esc_attr($this->get_field_id('delay')).'" name="'.esc_attr($this->get_field_name('delay')).'" type="text" value="'.esc_attr($instance['delay']).'" size="3"/></p>' |
| 704 |
.'<p><label for="'.esc_attr($this->get_field_id('nam')).'">Always display name:</label> <input id="'.esc_attr($this->get_field_id('nam')).'" name="'.esc_attr($this->get_field_name('nam')).'" type="checkbox" value="1"'.(empty($instance['nam'])?'':' checked').'/></p>' |
| 705 |
.'</div>'; |
| 706 |
} |
| 707 |
} |
| 708 |
|
| 709 |
function sf_widgets_init() { |
| 710 |
register_widget('sf_widget_event'); |
| 711 |
register_widget('sf_widget_folder'); |
| 712 |
} |
| 713 |
add_action('widgets_init','sf_widgets_init'); |
| 714 |
|
| 715 |
?> |