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