| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: PilotPress |
| 4 |
Plugin URI: http://ontraport.com/ |
| 5 |
Description: OfficeAutoPilot / ONTRAPORT WordPress integration plugin. |
| 6 |
Version: 1.9.3 |
| 7 |
Author: ONTRAPORT Inc. |
| 8 |
Author URI: http://ontraport.com/ |
| 9 |
Text Domain: pilotpress |
| 10 |
Copyright: 2013, Ontraport |
| 11 |
*/ |
| 12 |
|
| 13 |
if(defined("ABSPATH")) { |
| 14 |
include_once(ABSPATH.WPINC.'/class-http.php'); |
| 15 |
global $wp_version; |
| 16 |
if (version_compare($wp_version,"3.1","<")) |
| 17 |
{ |
| 18 |
include_once(ABSPATH.WPINC.'/registration.php'); |
| 19 |
} |
| 20 |
register_activation_hook(__FILE__, "enable_pilotpress"); |
| 21 |
register_deactivation_hook(__FILE__, "disable_pilotpress"); |
| 22 |
$pilotpress = new PilotPress; |
| 23 |
//create and load up the PilotPress Text Widget statically |
| 24 |
add_action( 'widgets_init',array( 'PilotPress_Widget', 'register' ) ); |
| 25 |
//Hook into the admin footer so as to load this JS |
| 26 |
add_action( 'admin_footer-widgets.php' , "pilotpress_widget_js" ); |
| 27 |
} |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
class PilotPress { |
| 32 |
|
| 33 |
const VERSION = "1.9.3"; |
| 34 |
const WP_MIN = "3.0"; |
| 35 |
const NSPACE = "_pilotpress_"; |
| 36 |
const URL_JQCSS = "https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/smoothness/jquery-ui.css"; |
| 37 |
const AUTH_SALT = "M!E%VxpKvuQHn!PTPOTohtLbnOl&)5&0mb(Uj^c#Zz!-0898yfS#7^xttNW(x1ia"; |
| 38 |
|
| 39 |
public $system_pages = array(); |
| 40 |
|
| 41 |
public static $brand = "OfficeAutoPilot"; |
| 42 |
public static $brand_url = "OfficeAutoPilot.com"; |
| 43 |
public static $url_api = "https://www1.moon-ray.com/api.php"; |
| 44 |
public static $backup_url_api = "https://web.moon-ray.com/api.php"; |
| 45 |
public static $url_tjs = "https://www1.moon-ray.com/tracking.js"; |
| 46 |
public static $url_jswpcss = "https://forms.moon-ray.com/v2.4/include/scripts/moonrayJS/moonrayJS-only-wp-forms.css"; |
| 47 |
public static $url_mrcss = "https://forms.moon-ray.com/v2.4/include/minify/?g=moonrayCSS"; |
| 48 |
|
| 49 |
/* Various runtime, shared variables */ |
| 50 |
private $uri; |
| 51 |
private $metaboxes; |
| 52 |
private $settings; |
| 53 |
private $status = 0; |
| 54 |
private $do_login = false; |
| 55 |
private $homepage_url; |
| 56 |
private $incrementalnumber = 1; |
| 57 |
private $tagsSequences; |
| 58 |
|
| 59 |
//Global ppprotect-category reference |
| 60 |
private $ppp; |
| 61 |
|
| 62 |
function __construct() { |
| 63 |
|
| 64 |
// Includes new ppprotect class that has enhanced protections for things like categories etc. |
| 65 |
require_once( plugin_dir_path( __FILE__ ) . 'ppprotect-categories.php'); |
| 66 |
$this->ppp = new PPProtect(); |
| 67 |
|
| 68 |
$this->bind_hooks(); /* hook into WP */ |
| 69 |
$this->start_session(); /* use sessions, controversial but easy */ |
| 70 |
|
| 71 |
$this->ppp->ppprotectHooks(); |
| 72 |
|
| 73 |
/* Used for keeping a record of the current shortcodes to be merged */ |
| 74 |
$this->shortcodeFields = array(); |
| 75 |
|
| 76 |
/* use this var, it's handy */ |
| 77 |
$this->uri = get_option('siteurl').'/wp-content/plugins/'.dirname(plugin_basename(__FILE__)); |
| 78 |
|
| 79 |
/* the various Centers */ |
| 80 |
$this->centers = array( |
| 81 |
"customer_center" => array( |
| 82 |
"title" => "Customer Center", |
| 83 |
"slug" => "customer-center", |
| 84 |
"content" => "This content will be replaced by the Customer Center" |
| 85 |
), |
| 86 |
"affiliate_center" => array( |
| 87 |
"title" => "Partner Center", |
| 88 |
"slug" => "affiliate-center", |
| 89 |
"content" => "This content will be replaced by the Partner Center" |
| 90 |
), |
| 91 |
); |
| 92 |
} |
| 93 |
|
| 94 |
/* this function loads up runtime settings from API or transient caches for both plugin and user (if logged in) */ |
| 95 |
function load_settings() { |
| 96 |
|
| 97 |
global $wpdb; |
| 98 |
|
| 99 |
$this->system_pages = $this->get_system_pages(); |
| 100 |
|
| 101 |
if($this->get_setting("disablecaching") && get_transient('pilotpress_cache') && !isset($_SESSION["rehash"])) { |
| 102 |
$this->settings = get_transient('pilotpress_cache'); |
| 103 |
if(get_transient("usertags_".$this->get_setting("contact_id", "user"))) { |
| 104 |
$tags = get_transient("usertags_".$this->get_setting("contact_id", "user")); |
| 105 |
if(is_array($tags["tags"])) { |
| 106 |
$this->settings["user"]["tags"] = $tags["tags"]; |
| 107 |
} |
| 108 |
} |
| 109 |
$this->status = 1; |
| 110 |
} else { |
| 111 |
|
| 112 |
if(isset($_SESSION["rehash"])) { |
| 113 |
unset($_SESSION["rehash"]); |
| 114 |
} |
| 115 |
|
| 116 |
$this->settings["wp"] = array(); |
| 117 |
$this->settings["wp"]["post_types"] = array(); |
| 118 |
$this->settings["wp"]["permalink"] = get_option('permalink_structure'); |
| 119 |
$this->settings["wp"]["template"] = get_option('template'); |
| 120 |
$this->settings["wp"]["plugins"] = get_option('active_plugins'); |
| 121 |
$this->settings["wp"]["post_types"] = get_post_types(); |
| 122 |
|
| 123 |
$this->settings["pilotpress"] = get_option("pilotpress-settings"); |
| 124 |
|
| 125 |
$this->api_version = get_option("pilotpress_api_version"); |
| 126 |
|
| 127 |
if($this->get_setting("usehome")) { |
| 128 |
$this->homepage_url = home_url(); |
| 129 |
} else { |
| 130 |
$this->homepage_url = site_url(); |
| 131 |
} |
| 132 |
|
| 133 |
$this->settings["pilotpress"]["error_redirect_field"] = 'select-keyvalue'; |
| 134 |
$this->settings["pilotpress"]["error_redirect_message"] = "Redirect to THIS page on error."; |
| 135 |
|
| 136 |
$results = $wpdb->get_results("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_pilotpress_show_in_nav'", ARRAY_A); |
| 137 |
foreach($results as $index => $page) { |
| 138 |
$this->settings["pilotpress"]["show_in_nav"][] = $page["post_id"]; |
| 139 |
} |
| 140 |
|
| 141 |
if($this->get_setting("api_key") && $this->get_setting("app_id")) { |
| 142 |
|
| 143 |
$app_id = explode("_", $this->get_setting("app_id")); |
| 144 |
if(count($app_id) == 3) { |
| 145 |
if($app_id[1] > 20000 || $this->api_version ) { |
| 146 |
self::$brand = "ONTRAPORT"; |
| 147 |
self::$brand_url = "ontraport.com"; |
| 148 |
|
| 149 |
self::$url_api = "https://api.ontraport.com/pilotpress.php"; |
| 150 |
self::$backup_url_api = "https://api.ontraport.com/pilotpress.php"; |
| 151 |
|
| 152 |
self::$url_tjs = "https://optassets.ontraport.com/tracking.js"; |
| 153 |
self::$url_jswpcss = "https://forms.ontraport.com/v2.4/include/scripts/moonrayJS/moonrayJS-only-wp-forms.css"; |
| 154 |
self::$url_mrcss = "https://forms.ontraport.com/v2.4/include/minify/?g=moonrayCSS"; |
| 155 |
} |
| 156 |
|
| 157 |
// for debugging |
| 158 |
if(is_file(ABSPATH . "/pp_debug_include.php")) |
| 159 |
{ |
| 160 |
include_once(ABSPATH . "/pp_debug_include.php"); |
| 161 |
} |
| 162 |
} |
| 163 |
|
| 164 |
//check if these are stored in the cache first |
| 165 |
$pilotPressTrackingURL = get_transient("pilotpress_tracking_url"); |
| 166 |
$pilotPressTracking = get_transient("pilotpress_tracking"); |
| 167 |
$getSiteSettings = true; |
| 168 |
|
| 169 |
if ($pilotPressTrackingURL !== false && $pilotPressTracking !== false) |
| 170 |
{ |
| 171 |
$this->settings["oap"]["tracking_url"] = $pilotPressTrackingURL; |
| 172 |
$this->settings["oap"]["tracking"] = $pilotPressTracking; |
| 173 |
$getSiteSettings = false; |
| 174 |
} |
| 175 |
|
| 176 |
//Check to make sure we really need to even make this API call... |
| 177 |
if (is_user_logged_in() || $getSiteSettings ) |
| 178 |
{ |
| 179 |
//Only make use of cookie if not an admin user. |
| 180 |
if(isset($_COOKIE["contact_id"]) && !current_user_can('manage_options')) { |
| 181 |
global $current_user; |
| 182 |
get_currentuserinfo(); |
| 183 |
$username = $current_user->user_login; |
| 184 |
$api_result = $this->api_call("get_site_settings", array("site" => site_url(), "contact_id" => $_COOKIE["contact_id"], "username" => $username , "version"=>self::VERSION )); |
| 185 |
} |
| 186 |
else { |
| 187 |
$api_result = $this->api_call("get_site_settings", array("site" => site_url() , "version"=>self::VERSION )); |
| 188 |
} |
| 189 |
|
| 190 |
if(is_array($api_result)) { |
| 191 |
$this->settings["oap"] = $api_result; |
| 192 |
|
| 193 |
if(isset($this->settings["user"])) { |
| 194 |
unset($this->settings["user"]); |
| 195 |
} |
| 196 |
|
| 197 |
$this->ppp->ppprotectSetPPMemLevels($api_result["membership_levels"]); |
| 198 |
|
| 199 |
if(!$this->get_setting("disablecaching")) { |
| 200 |
set_transient('pilotpress_cache', $this->settings, 60 * 60 * 12); |
| 201 |
} |
| 202 |
|
| 203 |
$_SESSION["default_fields"] = $this->settings["oap"]["default_fields"]; |
| 204 |
|
| 205 |
|
| 206 |
if(isset($api_result["membership_level"])) { |
| 207 |
$_SESSION["user_levels"] = $api_result["membership_level"]; |
| 208 |
if(!empty($username)) |
| 209 |
{ |
| 210 |
$_SESSION["user_name"] = $username; |
| 211 |
} |
| 212 |
} |
| 213 |
$this->status = 1; |
| 214 |
|
| 215 |
|
| 216 |
//Lets store the API version into their options table if available |
| 217 |
if (isset($api_result["pilotpress_api_version"])) |
| 218 |
{ |
| 219 |
update_option("pilotpress_api_version" , $api_result["pilotpress_api_version"]); |
| 220 |
} |
| 221 |
|
| 222 |
|
| 223 |
//Cache the tracking link and custom domain so we can avoid calling this every page load |
| 224 |
if (isset($api_result["tracking_url"])) |
| 225 |
{ |
| 226 |
set_transient('pilotpress_tracking_url', $api_result["tracking_url"],60 * 60 * 24); |
| 227 |
} |
| 228 |
|
| 229 |
|
| 230 |
if (isset($api_result["tracking_url"])) |
| 231 |
{ |
| 232 |
set_transient('pilotpress_tracking', $api_result["tracking"],60 * 60 * 24); |
| 233 |
} |
| 234 |
|
| 235 |
} |
| 236 |
} |
| 237 |
} else { |
| 238 |
$this->status = 0; |
| 239 |
} |
| 240 |
|
| 241 |
$this->settings["user"] = $this->get_user_settings(); |
| 242 |
|
| 243 |
if($this->get_setting("contact_id", "user")) { |
| 244 |
if(get_transient("usertags_".$this->get_setting("contact_id", "user"))) { |
| 245 |
$tags = get_transient("usertags_".$this->get_setting("contact_id", "user")); |
| 246 |
} else { |
| 247 |
$tags = $this->api_call("get_contact_tags", array("contact_id" => $this->get_setting("contact_id", "user"))); |
| 248 |
if(!$this->get_setting("disablecaching")) { |
| 249 |
set_transient('usertags_'.$this->get_setting("contact_id", "user"), $tags, 60 * 60 * 12); |
| 250 |
} |
| 251 |
} |
| 252 |
|
| 253 |
if(is_array($tags["tags"])) { |
| 254 |
$this->settings["user"]["tags"] = $tags["tags"]; |
| 255 |
} |
| 256 |
|
| 257 |
} |
| 258 |
} |
| 259 |
} |
| 260 |
|
| 261 |
/* what protocol? */ |
| 262 |
static function get_protocol() { |
| 263 |
if(isset($_SERVER["HTTPS"])) { |
| 264 |
if(!empty($_SERVER["HTTPS"])) { |
| 265 |
return "https://"; |
| 266 |
} |
| 267 |
} |
| 268 |
return "http://"; |
| 269 |
} |
| 270 |
|
| 271 |
/* add metaboxes to said post types */ |
| 272 |
function update_post_types() { |
| 273 |
|
| 274 |
$exclude = array("attachment","revision","nav_menu_item"); |
| 275 |
$array = $this->get_setting("post_types","wp"); |
| 276 |
|
| 277 |
$post_types = get_post_types('','names'); |
| 278 |
foreach($post_types as $post_type) { |
| 279 |
if(!in_array($post_type, $array) && !in_array($post_type, $exclude)) { |
| 280 |
$array[] = $post_type; |
| 281 |
} |
| 282 |
} |
| 283 |
|
| 284 |
$this->settings["wp"]["post_types"] = $array; |
| 285 |
|
| 286 |
} |
| 287 |
|
| 288 |
function get_setting($key, $type = "pilotpress", $array = false) { |
| 289 |
if(isset($this->settings[$type][$key])) { |
| 290 |
if(!is_array($this->settings[$type][$key]) && $array) { |
| 291 |
return array($this->settings[$type][$key]); |
| 292 |
} else { |
| 293 |
return $this->settings[$type][$key]; |
| 294 |
} |
| 295 |
} else { |
| 296 |
if($array) { |
| 297 |
return array(); |
| 298 |
} else { |
| 299 |
return false; |
| 300 |
} |
| 301 |
} |
| 302 |
} |
| 303 |
|
| 304 |
/* ditto getter is also handy */ |
| 305 |
function get_field($key) { |
| 306 |
foreach($this->get_setting("fields", "user", true) as $group => $fields) { |
| 307 |
if(isset($fields[$key])) |
| 308 |
{ |
| 309 |
return $fields[$key]; |
| 310 |
} |
| 311 |
else if (isset($fields[html_entity_decode($key)])) |
| 312 |
{ |
| 313 |
return $fields[html_entity_decode($key)]; |
| 314 |
} |
| 315 |
|
| 316 |
} |
| 317 |
|
| 318 |
foreach($this->get_setting("default_fields", "oap", true) as $group => $fields) { |
| 319 |
if(isset($fields[$key])) |
| 320 |
{ |
| 321 |
return $fields[$key]; |
| 322 |
} |
| 323 |
else if (isset($fields[html_entity_decode($key)])) |
| 324 |
{ |
| 325 |
return $fields[html_entity_decode($key)]; |
| 326 |
} |
| 327 |
} |
| 328 |
return ""; |
| 329 |
} |
| 330 |
|
| 331 |
function is_setup() { |
| 332 |
if($this->status != 0) { |
| 333 |
return true; |
| 334 |
} else { |
| 335 |
return false; |
| 336 |
} |
| 337 |
} |
| 338 |
|
| 339 |
/* this is a fancy getter, for user settings */ |
| 340 |
function get_user_settings() { |
| 341 |
$return = array(); |
| 342 |
|
| 343 |
if (isset($_SESSION['contact_id'])) { |
| 344 |
$return["contact_id"] = $_SESSION["contact_id"]; |
| 345 |
} |
| 346 |
|
| 347 |
if(isset($_SESSION["user_levels"])) { |
| 348 |
$return["name"] = $_SESSION["user_name"]; |
| 349 |
$return["username"] = $_SESSION["user_name"]; |
| 350 |
$return["nickname"] = $_SESSION["nickname"]; |
| 351 |
$return["levels"] = $_SESSION["user_levels"]; |
| 352 |
} |
| 353 |
return $return; |
| 354 |
} |
| 355 |
|
| 356 |
/* finally some fun: this sets up the admin edit page! */ |
| 357 |
function settings_init() { |
| 358 |
|
| 359 |
$_SESSION["rehash"] = 1; |
| 360 |
|
| 361 |
add_options_page('PilotPress Settings' , 'PilotPress', 'manage_options', 'pilotpress-settings', array(&$this, 'settings_page')); |
| 362 |
register_setting('pilotpress-settings', 'pilotpress-settings', array(&$this, 'settings_validate')); |
| 363 |
|
| 364 |
add_settings_section('pilotpress-settings-general', __('General Settings', 'pilotpress'), array(&$this, 'settings_section_general'), 'pilotpress-settings'); |
| 365 |
add_settings_field('pilotpress_app_id', __('Application ID', 'pilotpress'), array(&$this, 'display_settings_app_id'), 'pilotpress-settings', 'pilotpress-settings-general'); |
| 366 |
add_settings_field('pilotpress_api_key', __('API Key', 'pilotpress'), array(&$this, 'display_settings_api_key'), 'pilotpress-settings', 'pilotpress-settings-general'); |
| 367 |
add_settings_field('wp_userlockout', __('Lock all users without Admin role out of profile editor', 'pilotpress'), array(&$this, 'display_settings_userlockout'), 'pilotpress-settings', 'pilotpress-settings-general'); |
| 368 |
|
| 369 |
add_settings_section('settings_section_oap', __(self::$brand . ' Integration Settings', 'pilotpress'), array(&$this, 'settings_section_oap'), 'pilotpress-settings'); |
| 370 |
add_settings_field('customer_center', __('Enable Customer Center', 'pilotpress'), array(&$this, 'display_settings_cc'), 'pilotpress-settings', 'settings_section_oap'); |
| 371 |
add_settings_field('affiliate_center', __('Enable Partner Center', 'pilotpress'), array(&$this, 'display_settings_ac'), 'pilotpress-settings', 'settings_section_oap'); |
| 372 |
|
| 373 |
add_settings_section('pilotpress-redirect-display', __('Post Login Redirect Settings', 'pilotpress'), array(&$this, 'settings_section_redirect'), 'pilotpress-settings'); |
| 374 |
add_settings_field('pilotpress_customer_plr', __('Customers Redirect To', 'pilotpress'), array(&$this, 'display_settings_customer_plr'), 'pilotpress-settings', 'pilotpress-redirect-display'); |
| 375 |
add_settings_field('pilotpress_affiliate_plr', __('Partners Redirect To', 'pilotpress'), array(&$this, 'display_settings_affiliate_plr'), 'pilotpress-settings', 'pilotpress-redirect-display'); |
| 376 |
|
| 377 |
//Add the Customer Center Settings |
| 378 |
add_settings_section('pilotpress-customer-center-display', __('Customer Center Settings', 'pilotpress'), array(&$this, 'settings_section_customer_settings'), 'pilotpress-settings'); |
| 379 |
add_settings_field('pilotpress_customer_center_header_image', __('Custom Header Image', 'pilotpress'), array(&$this, 'display_settings_customer_center_header_image'), 'pilotpress-settings', 'pilotpress-customer-center-display'); |
| 380 |
add_settings_field('pilotpress_customer_center_primary_color', __('Primary Color', 'pilotpress'), array(&$this, 'display_settings_customer_center_primary_color'), 'pilotpress-settings', 'pilotpress-customer-center-display'); |
| 381 |
add_settings_field('pilotpress_customer_center_secondary_color', __('Secondary (Background) Color', 'pilotpress'), array(&$this, 'display_settings_customer_center_secondary_color'), 'pilotpress-settings', 'pilotpress-customer-center-display'); |
| 382 |
|
| 383 |
//Add the New User Register Settings |
| 384 |
add_settings_section('pilotpress-new-user-display', __('New User Register Settings', 'pilotpress'), array(&$this, 'settings_section_new_user_settings'), 'pilotpress-settings'); |
| 385 |
add_settings_field('pilotpress_add_newly_registered_users', __('Add newly registered WordPress users to your ONTRAPORT contacts', 'pilotpress'), array(&$this, 'display_settings_add_newly_registered_users'), 'pilotpress-settings', 'pilotpress-new-user-display'); |
| 386 |
add_settings_field('pilotpress_newly_registered_tags', __('What tags should they have?', 'pilotpress'), array(&$this, 'display_settings_newly_registered_tags'), 'pilotpress-settings', 'pilotpress-new-user-display'); |
| 387 |
add_settings_field('pilotpress_newly_registered_sequences', __('What sequences should they be on?', 'pilotpress'), array(&$this, 'display_settings_newly_registered_sequences'), 'pilotpress-settings', 'pilotpress-new-user-display'); |
| 388 |
|
| 389 |
|
| 390 |
//Add the Logout Settings |
| 391 |
add_settings_section('pilotpress-logout-users-display', __('Logout Settings', 'pilotpress'), array(&$this, 'settings_section_logout_settings'), 'pilotpress-settings'); |
| 392 |
add_settings_field('pilotpress_logout_users', __('Would you like to keep user\'s logged into your site longer than normal? <br /> <br /> <i>(*Please note that if the browser is closed for a long period the user will have to log in again.</i>) ', 'pilotpress'), array(&$this, 'display_settings_logout_users'), 'pilotpress-settings', 'pilotpress-logout-users-display'); |
| 393 |
|
| 394 |
|
| 395 |
add_settings_section('pilotpress-settings-advanced', __('Advanced Settings', 'pilotpress'), array(&$this, 'settings_section_advanced'), 'pilotpress-settings'); |
| 396 |
add_settings_field('pp_use_cache', __('Disable API Caching', 'pilotpress'), array(&$this, 'display_settings_disablecaching'), 'pilotpress-settings', 'pilotpress-settings-advanced'); |
| 397 |
add_settings_field('pp_sslverify', __('Disable Verify Host SSL', 'pilotpress'), array(&$this, 'display_settings_disablesslverify'), 'pilotpress-settings', 'pilotpress-settings-advanced'); |
| 398 |
add_settings_field('pp_use_home', __('Use WordPress URL instead of Site URL', 'pilotpress'), array(&$this, 'display_settings_usehome'), 'pilotpress-settings', 'pilotpress-settings-advanced'); |
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
} |
| 404 |
|
| 405 |
/* WP is sometimes silly, this is a function to echo a checkbox and have it registered.. annoying but easy */ |
| 406 |
function display_settings_cc() { |
| 407 |
echo "<input type='checkbox' name='pilotpress-settings[customer_center]'"; |
| 408 |
if($this->get_setting("customer_center")) { |
| 409 |
echo " checked"; |
| 410 |
} |
| 411 |
echo ">"; |
| 412 |
} |
| 413 |
|
| 414 |
/* ditto */ |
| 415 |
function display_settings_ac() { |
| 416 |
echo "<input type='checkbox' name='pilotpress-settings[affiliate_center]'"; |
| 417 |
if($this->get_setting("affiliate_center")) { |
| 418 |
echo " checked"; |
| 419 |
} |
| 420 |
echo ">"; |
| 421 |
} |
| 422 |
|
| 423 |
/* customer center settings */ |
| 424 |
function display_settings_customer_plr() { |
| 425 |
|
| 426 |
$setting = $this->get_setting("pilotpress_customer_plr"); |
| 427 |
if(!$setting) { |
| 428 |
$setting = "-1"; |
| 429 |
} |
| 430 |
|
| 431 |
$pages = $this->get_routeable_pages(array("-2")); |
| 432 |
echo "<select name='pilotpress-settings[pilotpress_customer_plr]'>"; |
| 433 |
foreach($pages as $id => $title) { |
| 434 |
echo "<option value='{$id}'"; |
| 435 |
if($id == $setting) { |
| 436 |
echo " selected"; |
| 437 |
} |
| 438 |
echo ">{$title}</option>"; |
| 439 |
} |
| 440 |
echo "</select>"; |
| 441 |
} |
| 442 |
|
| 443 |
/* ditto, but for affil center */ |
| 444 |
function display_settings_affiliate_plr() { |
| 445 |
|
| 446 |
$setting = $this->get_setting("pilotpress_affiliate_plr"); |
| 447 |
if(!$setting) { |
| 448 |
$setting = "-1"; |
| 449 |
} |
| 450 |
|
| 451 |
$pages = $this->get_routeable_pages(array("-2")); |
| 452 |
echo "<select name='pilotpress-settings[pilotpress_affiliate_plr]'>"; |
| 453 |
foreach($pages as $id => $title) { |
| 454 |
echo "<option value='{$id}'"; |
| 455 |
if($id == $setting) { |
| 456 |
echo " selected"; |
| 457 |
} |
| 458 |
echo ">{$title}</option>"; |
| 459 |
} |
| 460 |
echo "</select>"; |
| 461 |
} |
| 462 |
|
| 463 |
/** @brief settings hook for showing the customer center header image */ |
| 464 |
function display_settings_customer_center_header_image() |
| 465 |
{ |
| 466 |
$setting = $this->get_setting("pilotpress_customer_center_header_image"); |
| 467 |
if (!$setting){ |
| 468 |
$setting = ""; |
| 469 |
} |
| 470 |
|
| 471 |
$output = "<input name='pilotpress-settings[pilotpress_customer_center_header_image]' class='pilotpress_customer_center_header_image_url' type='text' name='header_logo' size='60' value='$setting'> |
| 472 |
<a href='#' class='button pilotpress_header_logo_upload'>Upload</a>"; |
| 473 |
|
| 474 |
echo $output; |
| 475 |
|
| 476 |
} |
| 477 |
|
| 478 |
/** @brief settings hook for showing the customer center primary color */ |
| 479 |
function display_settings_customer_center_primary_color() |
| 480 |
{ |
| 481 |
$setting = $this->get_setting("pilotpress_customer_center_primary_color"); |
| 482 |
if (!$setting){ |
| 483 |
$setting = ""; |
| 484 |
} |
| 485 |
$output = "<input type='text' name='pilotpress-settings[pilotpress_customer_center_primary_color]' id='primary-color' value='".$setting."' data-default-color='#ffffff' class='pilotpress-color-picker' />"; |
| 486 |
|
| 487 |
echo $output; |
| 488 |
|
| 489 |
} |
| 490 |
|
| 491 |
/** @brief settings hook for showing the customer center secondary (background) color */ |
| 492 |
function display_settings_customer_center_secondary_color() |
| 493 |
{ |
| 494 |
$setting = $this->get_setting("pilotpress_customer_center_secondary_color"); |
| 495 |
if (!$setting){ |
| 496 |
$setting = ""; |
| 497 |
} |
| 498 |
$output = "<input type='text' name='pilotpress-settings[pilotpress_customer_center_secondary_color]' id='secondary-color' value='".$setting."' data-default-color='#ffffff' class='pilotpress-color-picker' />"; |
| 499 |
|
| 500 |
echo $output; |
| 501 |
} |
| 502 |
|
| 503 |
/** @brief displays the setting for the option to add new registered users to ONTRAPORT */ |
| 504 |
function display_settings_add_newly_registered_users() |
| 505 |
{ |
| 506 |
$setting = $this->get_setting("pilotpress_add_newly_registered_users"); |
| 507 |
if (!$setting){ |
| 508 |
$setting = "-1"; |
| 509 |
} |
| 510 |
echo "<select name=pilotpress-settings[pilotpress_add_newly_registered_users]>"; |
| 511 |
echo "<option value='0' ".selected( $setting, 0 ).">No</option>"; |
| 512 |
echo "<option value='1' ".selected( $setting, 1 ).">Yes</option>"; |
| 513 |
echo "</select>"; |
| 514 |
} |
| 515 |
|
| 516 |
/** @brief displays the setting for the sequences that should be added to the new user */ |
| 517 |
function display_settings_newly_registered_sequences() |
| 518 |
{ |
| 519 |
$setting = $this->get_setting("pilotpress_newly_registered_sequences"); |
| 520 |
if (!$setting){ |
| 521 |
$setting = "-1"; |
| 522 |
} |
| 523 |
$output = "<select multiple name=pilotpress-settings[pilotpress_newly_registered_sequences][]>"; |
| 524 |
$sequences = json_decode($this->tagsSequences["sequences"] ,true ); |
| 525 |
foreach($sequences as $sequence) |
| 526 |
{ |
| 527 |
$selected = ""; |
| 528 |
if(is_array($setting)) |
| 529 |
{ |
| 530 |
if (in_array($sequence["drip_id"] , $setting)) |
| 531 |
{ |
| 532 |
$selected = "selected='selected'"; |
| 533 |
} |
| 534 |
} |
| 535 |
$output .= "<option value='".$sequence["drip_id"]."' ".$selected . ">".$sequence["name"]."</option>"; |
| 536 |
} |
| 537 |
$output .= "</select>"; |
| 538 |
echo $output; |
| 539 |
} |
| 540 |
|
| 541 |
/** @brief displays the setting for the tags to be added to new users */ |
| 542 |
function display_settings_newly_registered_tags() |
| 543 |
{ |
| 544 |
$setting = $this->get_setting("pilotpress_newly_registered_tags"); |
| 545 |
if (!$setting){ |
| 546 |
$setting = ""; |
| 547 |
} |
| 548 |
$output = "<select multiple name=pilotpress-settings[pilotpress_newly_registered_tags][]>"; |
| 549 |
$tags = json_decode($this->tagsSequences["tags"] , true ); |
| 550 |
foreach($tags as $tag) |
| 551 |
{ |
| 552 |
$selected = ""; |
| 553 |
if(is_array($setting)) |
| 554 |
{ |
| 555 |
if (in_array($tag["tag_name"] , $setting)) |
| 556 |
{ |
| 557 |
$selected = "selected='selected'"; |
| 558 |
} |
| 559 |
} |
| 560 |
$output .= "<option value='".$tag["tag_name"]."' ".$selected.">".$tag["tag_name"]."</option>"; |
| 561 |
} |
| 562 |
$output .= "</select>"; |
| 563 |
echo $output; |
| 564 |
} |
| 565 |
|
| 566 |
/** @brief displays the setting for enabling or disabling logout duration settings */ |
| 567 |
function display_settings_logout_users() |
| 568 |
{ |
| 569 |
$setting = $this->get_setting("pilotpress_logout_users"); |
| 570 |
if (!$setting){ |
| 571 |
$setting = "-1"; |
| 572 |
} |
| 573 |
echo "<select name=pilotpress-settings[pilotpress_logout_users]>"; |
| 574 |
echo "<option value='0' ".selected( $setting, 0 ).">No</option>"; |
| 575 |
echo "<option value='1' ".selected( $setting, 1 ).">Yes</option>"; |
| 576 |
echo "</select>"; |
| 577 |
} |
| 578 |
|
| 579 |
/* section output, blank for austerity */ |
| 580 |
function settings_section_customer_settings() {} |
| 581 |
function settings_section_new_user_settings() {} |
| 582 |
function settings_section_logout_settings() {} |
| 583 |
function settings_section_general() {} |
| 584 |
function settings_section_oap() {} |
| 585 |
function settings_section_redirect() {} |
| 586 |
function settings_section_advanced() { |
| 587 |
echo "<span class='pilotpress-advanced-warning'><b>WARNING:</b> these settings affect the core functionality of the PilotPress plugin, proceed with caution.</span>"; |
| 588 |
} |
| 589 |
|
| 590 |
/* notices! this is where the magic nags happen */ |
| 591 |
function display_notice() { |
| 592 |
|
| 593 |
global $post, $wp_version; |
| 594 |
|
| 595 |
if(basename($_SERVER["SCRIPT_NAME"]) == "post.php" && $_GET["action"] == "edit" && in_array($post->ID, $this->system_pages)) { |
| 596 |
echo '<div class="updated"><p>This page is used by the <b>PilotPress</b> plugin. You can edit the content but not delete the page itself.</p></div>'; |
| 597 |
} |
| 598 |
|
| 599 |
if($wp_version < self::WP_MIN) { |
| 600 |
echo '<div class="error" style="padding-top: 5px; padding-bottom: 5px;">'; |
| 601 |
_e('PilotPress requires WordPress '.self::WP_MIN.' or higher. Please de-activate the PilotPress plugin, upgrade to WordPress '.self::WP_MIN.' or higher then activate PilotPress again.', 'pilotpress'); |
| 602 |
echo '</div>'; |
| 603 |
} |
| 604 |
|
| 605 |
if (!$this->get_setting('api_key') || !$this->get_setting('app_id')) { |
| 606 |
|
| 607 |
echo '<div class="error" style="padding-top: 5px; padding-bottom: 5px;">'; |
| 608 |
_e('PilotPress must be configured with an ' . self::$brand . ' API Key and App ID.', 'pilotpress'); |
| 609 |
|
| 610 |
if($_GET['page'] != 'pilotpress-settings') { |
| 611 |
_e(sprintf('Go to the <a href="%s" title="PilotPress Admin Page">PilotPress Admin Page</a> to finish setting up your site!', 'options-general.php?page=pilotpress-settings'), 'pilotpress'); |
| 612 |
echo ' ' ; |
| 613 |
_e(sprintf('You need an <a href="%s" title="Visit '. self::$brand_url .'">' . self::$brand . '</a> account to use this plugin.', 'http://' . self::$brand_url)); |
| 614 |
echo ' '; |
| 615 |
_e('Don\'t have one yet?', 'pilotpress'); |
| 616 |
echo ' '; |
| 617 |
_e(sprintf('<a href="%s" title="' . self::$brand . ' SignUp">Sign up</a> now!', 'http://' . self::$brand_url, 'pilotpress')); |
| 618 |
} |
| 619 |
|
| 620 |
echo '</div>'; |
| 621 |
} |
| 622 |
|
| 623 |
if(!$this->is_setup() && $this->get_setting('api_key') && $this->get_setting('app_id')) { |
| 624 |
echo '<div class="error" style="padding-top: 5px; padding-bottom: 5px;">'; |
| 625 |
_e('Either this site <b>'.str_replace("http://","",(string)site_url()).'</b> is not configured in ' . self::$brand . ' or the <a href="options-general.php?page=pilotpress-settings">API Key / App Id settings</a> are incorrect. ', 'pilotpress'); |
| 626 |
_e('Most PilotPress features are disabled until this is configured. Please <a href="'.$this->get_setting("setup_url", "oap").'">click here</a> to set it up or visit the <a href="'.$this->get_setting("help_url", "oap").'">online help</a> for more information.', 'pilotpress'); |
| 627 |
echo '</div>'; |
| 628 |
} |
| 629 |
|
| 630 |
} |
| 631 |
|
| 632 |
function display_settings_api_key() { |
| 633 |
?> |
| 634 |
<input size="50" name="pilotpress-settings[api_key]" id="pilotpress_api_key" type="text" class="code" value="<?php echo $this->get_setting('api_key'); ?>" /> |
| 635 |
<?php |
| 636 |
} |
| 637 |
|
| 638 |
function display_settings_app_id() { |
| 639 |
?> |
| 640 |
<input size="50" name="pilotpress-settings[app_id]" id="pilotpress_app_id" type="text" class="code" value="<?php echo $this->get_setting('app_id'); ?>" /> |
| 641 |
<?php |
| 642 |
} |
| 643 |
|
| 644 |
function display_settings_userlockout() { |
| 645 |
echo "<input type='checkbox' name='pilotpress-settings[wp_userlockout]'"; |
| 646 |
if($this->get_setting("wp_userlockout")) { |
| 647 |
echo " checked"; |
| 648 |
} |
| 649 |
echo ">"; |
| 650 |
} |
| 651 |
|
| 652 |
function display_settings_disablecaching() { |
| 653 |
echo "<input type='checkbox' name='pilotpress-settings[disablecaching]'"; |
| 654 |
if($this->get_setting("disablecaching")) { |
| 655 |
echo " checked"; |
| 656 |
} |
| 657 |
echo ">"; |
| 658 |
} |
| 659 |
|
| 660 |
function display_settings_disablesslverify() { |
| 661 |
echo "<input type='checkbox' name='pilotpress-settings[disablesslverify]'"; |
| 662 |
if($this->get_setting("disablesslverify")) { |
| 663 |
echo " checked"; |
| 664 |
} |
| 665 |
echo ">"; |
| 666 |
} |
| 667 |
|
| 668 |
function display_settings_disableprotected() { |
| 669 |
echo "<input type='checkbox' name='pilotpress-settings[disableprotected]'"; |
| 670 |
if($this->get_setting("disableprotected")) { |
| 671 |
echo " checked"; |
| 672 |
} |
| 673 |
echo ">"; |
| 674 |
} |
| 675 |
|
| 676 |
function display_settings_usehome() { |
| 677 |
echo "<input type='checkbox' name='pilotpress-settings[usehome]'"; |
| 678 |
if($this->get_setting("usehome")) { |
| 679 |
echo " checked"; |
| 680 |
} |
| 681 |
echo ">"; |
| 682 |
} |
| 683 |
|
| 684 |
/* finally, we register the settings page itself. */ |
| 685 |
function settings_page() { |
| 686 |
|
| 687 |
//get the sequences and tags... |
| 688 |
$this->tagsSequences = $this->api_call("get_tags_sequences", array("site" => site_url())); |
| 689 |
|
| 690 |
?> |
| 691 |
<div class="wrap"><h2><?php _e('PilotPress Settings', 'pilotpress'); ?></h2><?php |
| 692 |
|
| 693 |
?><form name="pilotpress-settings" method="post" action="options.php"><?php |
| 694 |
|
| 695 |
settings_fields('pilotpress-settings'); |
| 696 |
do_settings_sections('pilotpress-settings'); |
| 697 |
|
| 698 |
?> |
| 699 |
|
| 700 |
<p class="submit"><input type="submit" class="button-primary" name="save" value="<?php _e('Save Changes', 'pilotpress'); ?>" /> <input type="button" class="button-secondary" name="advanced" value="<?php _e('Advanced Settings', 'pilotpress'); ?>"></p></form></div> |
| 701 |
|
| 702 |
<script type="text/javascript"> |
| 703 |
jQuery(document).ready(function() { |
| 704 |
jQuery(document).find("[name=pilotpress-settings] h3:eq(6)").toggle(); |
| 705 |
jQuery(document).find(".pilotpress-advanced-warning").toggle(); |
| 706 |
jQuery(document).find("[name=pilotpress-settings] table:eq(6)").toggle(); |
| 707 |
jQuery(document).find("[name=advanced]").click(function() { |
| 708 |
jQuery(document).find("[name=pilotpress-settings] h3:eq(6)").toggle(); |
| 709 |
jQuery(document).find(".pilotpress-advanced-warning").toggle(); |
| 710 |
jQuery(document).find("[name=pilotpress-settings] table:eq(6)").toggle(); |
| 711 |
}); |
| 712 |
|
| 713 |
//media uploader |
| 714 |
jQuery('.pilotpress_header_logo_upload').click(function(e) { |
| 715 |
e.preventDefault(); |
| 716 |
|
| 717 |
var custom_uploader = wp.media({ |
| 718 |
title: 'Customer Center Header Image', |
| 719 |
button: { |
| 720 |
text: 'Upload Image' |
| 721 |
}, |
| 722 |
multiple: false // Set this to true to allow multiple files to be selected |
| 723 |
}) |
| 724 |
.on('select', function() { |
| 725 |
var attachment = custom_uploader.state().get('selection').first().toJSON(); |
| 726 |
jQuery('.pilotpress_customer_center_header_image').attr('src', attachment.url); |
| 727 |
jQuery('.pilotpress_customer_center_header_image_url').val(attachment.url); |
| 728 |
|
| 729 |
}) |
| 730 |
.open(); |
| 731 |
}); |
| 732 |
//primary color picker init |
| 733 |
jQuery('#primary-color.pilotpress-color-picker').iris(); |
| 734 |
jQuery('#primary-color.pilotpress-color-picker').iris({ change: function(event, ui) |
| 735 |
{ |
| 736 |
var colorpickervar = jQuery("#primary-color.pilotpress-color-picker").val() |
| 737 |
jQuery("#primary-color.pilotpress-color-picker").siblings('.iris-border').css('background-color', colorpickervar); |
| 738 |
} |
| 739 |
}); |
| 740 |
|
| 741 |
//secondary color picker init |
| 742 |
jQuery('#secondary-color.pilotpress-color-picker').iris(); |
| 743 |
jQuery('#secondary-color.pilotpress-color-picker').iris({ change: function(event, ui) |
| 744 |
{ |
| 745 |
var colorpickervar = jQuery("#secondary-color.pilotpress-color-picker").val() |
| 746 |
jQuery("#secondary-color.pilotpress-color-picker").siblings('.iris-border').css('background-color', colorpickervar); |
| 747 |
} |
| 748 |
}); |
| 749 |
}); |
| 750 |
|
| 751 |
</script> |
| 752 |
|
| 753 |
<?php |
| 754 |
} |
| 755 |
|
| 756 |
/* use this to validate input, for now it simply creates the pages and/or resets cache */ |
| 757 |
function settings_validate($input) { |
| 758 |
|
| 759 |
if(isset($input["customer_center"])) { |
| 760 |
$this->create_system_page("customer_center"); |
| 761 |
} else { |
| 762 |
$this->delete_system_page("customer_center"); |
| 763 |
} |
| 764 |
|
| 765 |
if(isset($input["affiliate_center"])) { |
| 766 |
$this->create_system_page("affiliate_center"); |
| 767 |
} else { |
| 768 |
$this->delete_system_page("affiliate_center"); |
| 769 |
} |
| 770 |
|
| 771 |
$_SESSION["rehash"] = 1; |
| 772 |
return $input; |
| 773 |
} |
| 774 |
|
| 775 |
/* OH YEAH! this is the API call method, wraps the static function as some other plugins may call via their own behalf */ |
| 776 |
function api_call($method, $data) { |
| 777 |
return self::api_call_static($method, $data, $this->get_setting("app_id"), $this->get_setting("api_key"), $this->get_setting("disablesslverify")); |
| 778 |
} |
| 779 |
|
| 780 |
/* this is the real function of the above, for errors... try dumping $post */ |
| 781 |
static function api_call_static($method, $data, $app_id, $api_key, $ssl_verify = false) { |
| 782 |
|
| 783 |
$post = array('body' => array("app_id" => $app_id, |
| 784 |
"api_key" => $api_key, |
| 785 |
"data" => json_encode($data)), 'timeout' => 500); |
| 786 |
|
| 787 |
if($ssl_verify) { |
| 788 |
$post["sslverify"] = 0; |
| 789 |
} |
| 790 |
|
| 791 |
$endpoint = sprintf(self::$url_api.'/%s/%s/%s', "json", "pilotpress", $method); |
| 792 |
$response = wp_remote_post($endpoint, $post); |
| 793 |
if(is_object($response)) |
| 794 |
{ |
| 795 |
if ($response->errors['http_request_failed']){ |
| 796 |
$endpoint = sprintf(self::$backup_url_api.'/%s/%s/%s', "json", "pilotpress", $method); |
| 797 |
$response = wp_remote_post($endpoint, $post); |
| 798 |
} |
| 799 |
} |
| 800 |
|
| 801 |
if(is_wp_error($response) || $response['response']['code'] == 500) { |
| 802 |
return false; |
| 803 |
} else { |
| 804 |
$body = json_decode(trim($response['body']), true); |
| 805 |
} |
| 806 |
|
| 807 |
if(isset($body["type"]) && $body["type"] == "error") { |
| 808 |
return false; |
| 809 |
} else { |
| 810 |
return $body["pilotpress"]; |
| 811 |
} |
| 812 |
|
| 813 |
} |
| 814 |
|
| 815 |
/* all WP binding happens here, mostly. consolidated for your pleasure */ |
| 816 |
private function bind_hooks() { |
| 817 |
|
| 818 |
/* hitup the API or grab transient */ |
| 819 |
add_action("init", array(&$this, "load_settings") , 1); |
| 820 |
add_action("init", array(&$this, "load_scripts") , 10); |
| 821 |
add_action('init', array(&$this,'sessionslap_ping')); |
| 822 |
add_action('wp_print_styles', array(&$this, 'stylesheets')); |
| 823 |
add_action('wp_print_footer_scripts', array(&$this, 'tracking')); |
| 824 |
add_action('retrieve_password', array(&$this, 'retrieve_password')); |
| 825 |
add_action('profile_update', array(&$this, 'profile_update')); |
| 826 |
|
| 827 |
add_action("wp_ajax_pp_update_aff_details", array(&$this, 'update_aff_details')); |
| 828 |
add_action("wp_ajax_pp_update_cc_details", array(&$this, 'update_cc_details')); |
| 829 |
|
| 830 |
if(is_admin()) { |
| 831 |
add_action('admin_menu', array(&$this, 'settings_init')); |
| 832 |
add_filter('admin_init', array(&$this, 'clean_meta')); |
| 833 |
add_filter('admin_init', array(&$this, 'flush_rewrite_rules')); |
| 834 |
add_filter('admin_init', array(&$this, 'user_lockout')); |
| 835 |
add_action('admin_enqueue_scripts', array(&$this, 'admin_load_scripts')); |
| 836 |
add_action('admin_notices', array(&$this, 'display_notice')); |
| 837 |
|
| 838 |
add_action('admin_menu', array(&$this, 'metabox_add')); |
| 839 |
add_action('pre_post_update', array(&$this, 'metabox_save')); |
| 840 |
|
| 841 |
add_action('media_buttons', array(&$this, 'media_button_add'), 20); |
| 842 |
add_action('media_upload_forms', array(&$this, 'media_upload_forms')); |
| 843 |
add_action('media_upload_images', array(&$this, 'media_upload_images')); |
| 844 |
add_action('media_upload_videos', array(&$this, 'media_upload_videos')); |
| 845 |
add_action('media_upload_fields', array(&$this, 'media_upload_fields')); |
| 846 |
add_action('wp_ajax_pp_insert_form', array(&$this, 'get_insert_form_html')); |
| 847 |
add_action('wp_ajax_pp_insert_video', array(&$this, 'get_insert_video_html')); |
| 848 |
add_action("wp_ajax_pp_get_aff_report", array(&$this, 'get_aff_report')); |
| 849 |
|
| 850 |
add_filter('tiny_mce_before_init', array(&$this, 'mce_valid_elements')); |
| 851 |
add_filter('tiny_mce_version', array(&$this, 'tiny_mce_version') ); |
| 852 |
add_filter("mce_external_plugins", array(&$this, "mce_external_plugins")); |
| 853 |
add_filter('mce_buttons_3', array(&$this, 'mce_buttons')); |
| 854 |
|
| 855 |
add_filter('manage_posts_columns', array(&$this, 'page_list_col')); |
| 856 |
add_action('manage_posts_custom_column', array(&$this, 'page_list_col_value'), 10, 2); |
| 857 |
add_filter('manage_pages_columns', array(&$this, 'page_list_col')); |
| 858 |
add_action('manage_pages_custom_column', array(&$this, 'page_list_col_value'), 10, 2); |
| 859 |
add_filter('user_has_cap', array(&$this, 'lock_delete'), 0, 3); |
| 860 |
add_filter('media_upload_tabs', array(&$this, 'modify_media_tab')); |
| 861 |
add_action('wp_loaded', array(&$this, 'update_post_types')); |
| 862 |
|
| 863 |
// For login_form |
| 864 |
add_action('admin_head', array(&$this, 'include_form_admin_options')); |
| 865 |
|
| 866 |
//add_action('admin_print_footer_scripts', array(&$this, 'tinymce_autop'), 50); |
| 867 |
|
| 868 |
} else { |
| 869 |
add_filter('rewrite_rules_array', array(&$this, 'filter_rewrite_rules')); |
| 870 |
add_action('wp', array(&$this, 'post_process')); |
| 871 |
add_filter('get_pages', array(&$this, 'get_pages')); |
| 872 |
add_filter("wp_nav_menu", array(&$this, 'get_nav_menus')); |
| 873 |
add_filter("wp_nav_menu_objects", array(&$this, 'get_nav_menu_objects')); |
| 874 |
add_filter('posts_where', array(&$this, 'posts_where')); |
| 875 |
add_filter('query_vars', array(&$this, 'filter_query_vars')); |
| 876 |
add_filter('the_content', array(&$this, 'content_process')); |
| 877 |
add_filter('login_message', array(&$this, 'content_process')); |
| 878 |
|
| 879 |
add_shortcode('protected', array(&$this, 'shortcode_show_if')); |
| 880 |
add_shortcode('show_if', array(&$this, 'shortcode_show_if')); |
| 881 |
add_shortcode('login_page', array(&$this, 'login_page')); |
| 882 |
add_shortcode('field', array(&$this, 'shortcode_field')); |
| 883 |
|
| 884 |
add_shortcode('pilotpress_protected', array(&$this, 'shortcode_show_if')); |
| 885 |
add_shortcode('pilotpress_show_if', array(&$this, 'shortcode_show_if')); |
| 886 |
add_shortcode('pilotpress_login_page', array(&$this, 'login_page')); |
| 887 |
add_shortcode('pilotpress_field', array(&$this, 'shortcode_field')); |
| 888 |
} |
| 889 |
|
| 890 |
add_action('wp_authenticate', array(&$this, 'user_login'), 1, 2); |
| 891 |
add_action("wp_login_failed", array(&$this, 'user_login_failed')); |
| 892 |
add_action("lostpassword_post", array(&$this, 'user_lostpassword')); |
| 893 |
add_action('wp_logout', array(&$this, 'user_logout')); |
| 894 |
add_action('init', array(&$this, 'pp_login_button')); |
| 895 |
add_action('user_register', array(&$this, 'add_new_register_user_to_ONTRAPORT') , 10, 1); |
| 896 |
|
| 897 |
} |
| 898 |
|
| 899 |
function retrieve_password($name) { |
| 900 |
$return = $this->api_call("retrieve_password", array("site" => site_url(), "username" => $name)); |
| 901 |
} |
| 902 |
|
| 903 |
/* update a persons profile */ |
| 904 |
function profile_update($user_id) { |
| 905 |
if(isset($_POST['first_name']) && isset($_POST['last_name']) && isset($_POST['nickname']) && isset($_POST['pass1'])) { |
| 906 |
$user = get_userdata($user_id); |
| 907 |
|
| 908 |
$details = array(); |
| 909 |
$details["site"] = site_url(); |
| 910 |
$details["username"] = $user->user_login; |
| 911 |
$details["firstname"] = $_POST['first_name']; |
| 912 |
$details["lastname"] = $_POST['last_name']; |
| 913 |
$details["nickname"] = $_POST['nickname']; |
| 914 |
$details["password"] = $_POST["pass1"]; |
| 915 |
|
| 916 |
$return = $this->api_call("profile_update", $details); |
| 917 |
} |
| 918 |
} |
| 919 |
|
| 920 |
function user_lockout() { |
| 921 |
global $current_user; |
| 922 |
if(!current_user_can('manage_options') && $this->get_setting("wp_userlockout") && !isset($_POST["action"])) { |
| 923 |
|
| 924 |
$customer = $this->get_setting("pilotpress_customer_plr"); |
| 925 |
if(!empty($customer) && $customer != "-1") { |
| 926 |
self::redirect(get_permalink($customer)); |
| 927 |
} else { |
| 928 |
self::redirect($this->homepage_url); |
| 929 |
} |
| 930 |
die; |
| 931 |
} |
| 932 |
} |
| 933 |
|
| 934 |
/* please load scripts here vs. printing. it's so much healthier */ |
| 935 |
function load_scripts() { |
| 936 |
wp_enqueue_script("jquery"); |
| 937 |
wp_register_script("mr_tracking", self::$url_tjs, array(), false, true); |
| 938 |
wp_enqueue_script("mr_tracking"); |
| 939 |
} |
| 940 |
|
| 941 |
/* |
| 942 |
@brief only load these scripts if in the admin dashboard |
| 943 |
|
| 944 |
*/ |
| 945 |
function admin_load_scripts() |
| 946 |
{ |
| 947 |
// Here to determine if the automattic color picker 'iris' is included with wordpress... if not, include and use it |
| 948 |
$version = get_bloginfo('version'); |
| 949 |
if ($version < 3.5) |
| 950 |
{ |
| 951 |
wp_register_style('irisstyle', plugins_url( '/js/iris.css' , __FILE__ )); |
| 952 |
wp_enqueue_style('irisstyle'); |
| 953 |
wp_register_style('jquery-ui', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery.ui.all.css'); |
| 954 |
wp_enqueue_style('jquery-ui'); |
| 955 |
|
| 956 |
wp_deregister_script('jquery-color'); |
| 957 |
wp_register_script('jquery-color', plugins_url( 'color.js' , __FILE__ )); |
| 958 |
wp_enqueue_script('jquery-color'); |
| 959 |
wp_enqueue_script('jquery-ui-core'); |
| 960 |
wp_enqueue_script('jquery-ui-draggable'); |
| 961 |
wp_enqueue_script('jquery-ui-slider'); |
| 962 |
wp_enqueue_script('jquery-ui-widget'); |
| 963 |
wp_enqueue_script('jquery-ui-mouse'); |
| 964 |
wp_enqueue_script('jquery-ui-tabs'); |
| 965 |
wp_register_script('iris', plugins_url( '/js/iris.js' , __FILE__ ), array( 'jquery', 'jquery-color', 'jquery-ui-core', 'jquery-ui-widget', 'jquery-ui-draggable', 'jquery-ui-slider', 'jquery-ui-mouse', 'jquery-ui-tabs' )); |
| 966 |
wp_enqueue_script('iris'); |
| 967 |
} |
| 968 |
else |
| 969 |
{ |
| 970 |
wp_register_style('jquery-ui', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery.ui.all.css'); |
| 971 |
wp_enqueue_style('jquery-ui'); |
| 972 |
wp_enqueue_script('jquery-ui-tabs'); |
| 973 |
wp_enqueue_style( 'wp-color-picker' ); |
| 974 |
wp_enqueue_script('iris'); |
| 975 |
} |
| 976 |
if(function_exists( 'wp_enqueue_media' )){ |
| 977 |
wp_enqueue_media(); |
| 978 |
}else{ |
| 979 |
wp_enqueue_style('thickbox'); |
| 980 |
wp_enqueue_script('media-upload'); |
| 981 |
wp_enqueue_script('thickbox'); |
| 982 |
} |
| 983 |
|
| 984 |
} |
| 985 |
|
| 986 |
function stylesheets() { |
| 987 |
|
| 988 |
wp_register_style("mrjswp", self::$url_jswpcss); |
| 989 |
wp_enqueue_style("mrjswp"); |
| 990 |
|
| 991 |
wp_register_style("mrcss", self::$url_mrcss); |
| 992 |
wp_enqueue_style("mrcss"); |
| 993 |
|
| 994 |
wp_register_style("jqcss", self::URL_JQCSS); |
| 995 |
wp_enqueue_style("jqcss"); |
| 996 |
} |
| 997 |
|
| 998 |
/* except this one. */ |
| 999 |
function tracking() { |
| 1000 |
echo "<script>_mri = \"".$this->get_setting('tracking','oap')."\";_mr_domain = \"" . $this->get_setting('tracking_url', 'oap') . "\"; mrtracking();</script>"; |
| 1001 |
} |
| 1002 |
|
| 1003 |
/* first of a few tinymce functions, this registers some of our buttons */ |
| 1004 |
function mce_buttons($buttons) { |
| 1005 |
array_push($buttons, "separator", "merge_fields"); |
| 1006 |
return $buttons; |
| 1007 |
} |
| 1008 |
|
| 1009 |
/* load up our marshalled plugin code (see comment prefixed: Xevious) */ |
| 1010 |
function mce_external_plugins($plugin_array) { |
| 1011 |
global $wp_version; |
| 1012 |
$version = 3.9; |
| 1013 |
//test for wordpress version to load proper plugin scripts |
| 1014 |
if ( version_compare( $wp_version, $version, '>=' ) ) { |
| 1015 |
$plugin_array['pilotpress'] = plugins_url('/' . plugin_basename(__FILE__) . '?ping=js39'); |
| 1016 |
} |
| 1017 |
else |
| 1018 |
{ |
| 1019 |
$plugin_array['pilotpress'] = plugins_url('/' . plugin_basename(__FILE__) . '?ping=js'); |
| 1020 |
} |
| 1021 |
|
| 1022 |
return $plugin_array; |
| 1023 |
} |
| 1024 |
|
| 1025 |
/* i forget what this did, but it is important */ |
| 1026 |
function tiny_mce_version($version) { |
| 1027 |
return ++$version; |
| 1028 |
} |
| 1029 |
|
| 1030 |
/* right so... lets just make most useful elements avaliable */ |
| 1031 |
function mce_valid_elements($in) { |
| 1032 |
$em = '#p[*],p[*],form[*],div[*],span[*],script[*],link[*]'; |
| 1033 |
|
| 1034 |
if(!is_array($in)) |
| 1035 |
{ |
| 1036 |
$in = array(); |
| 1037 |
} |
| 1038 |
|
| 1039 |
if(isset($in["extended_valid_elements"])) |
| 1040 |
{ |
| 1041 |
$in["extended_valid_elements"] .= ','; |
| 1042 |
$in["extended_valid_elements"] .= $em; |
| 1043 |
} else { |
| 1044 |
$in["extended_valid_elements"] = $em; |
| 1045 |
} |
| 1046 |
|
| 1047 |
if (isset($in['valid_children'])) |
| 1048 |
{ |
| 1049 |
$in['valid_children'] .= ',+body[link]'; |
| 1050 |
} |
| 1051 |
else |
| 1052 |
{ |
| 1053 |
$in['valid_children'] = '+body[link]'; |
| 1054 |
} |
| 1055 |
|
| 1056 |
$in["entity_encoding"] = "raw"; |
| 1057 |
|
| 1058 |
return $in; |
| 1059 |
} |
| 1060 |
|
| 1061 |
/* horrible but it gets the job done. WP said they'd fix this in 3.3, but they lied */ |
| 1062 |
function lock_delete($allcaps, $caps, $args) { |
| 1063 |
|
| 1064 |
global $wp_post; |
| 1065 |
|
| 1066 |
if(is_array($this->system_pages)) { |
| 1067 |
if(isset($_GET["post"])) { |
| 1068 |
if(in_array($_GET["post"], $this->system_pages)) { |
| 1069 |
if(is_array($allcaps)) { |
| 1070 |
foreach($allcaps as $cap => $value) { |
| 1071 |
if(strpos($cap, "delete") !== false) { |
| 1072 |
$allcaps[$cap] = 0; |
| 1073 |
} |
| 1074 |
} |
| 1075 |
} |
| 1076 |
} |
| 1077 |
} |
| 1078 |
} |
| 1079 |
return $allcaps; |
| 1080 |
} |
| 1081 |
|
| 1082 |
/* adds a column to the post list view */ |
| 1083 |
function page_list_col($cols) { |
| 1084 |
$_cols = array(); |
| 1085 |
if(is_array($cols)) { |
| 1086 |
foreach($cols as $col => $value) { |
| 1087 |
if($col == "author") { |
| 1088 |
$_cols["pilotpress"] = "PilotPress Levels"; |
| 1089 |
} |
| 1090 |
$_cols[$col] = $value; |
| 1091 |
} |
| 1092 |
} |
| 1093 |
return $_cols; |
| 1094 |
} |
| 1095 |
|
| 1096 |
/* prints value of above */ |
| 1097 |
function page_list_col_value($column_name, $id) { |
| 1098 |
if ($column_name == "pilotpress") { |
| 1099 |
if(in_array($id, $this->system_pages)) { |
| 1100 |
echo '<img src="' .$this->get_setting("mr_url", "oap"). 'static/lock-icon-pp.png" width="16" height="16" alt="Locked" /> System'; |
| 1101 |
} else { |
| 1102 |
$levels = get_post_meta($id, self::NSPACE.'level', false); |
| 1103 |
if(!empty($levels)) { |
| 1104 |
if(count($levels) == 1) { |
| 1105 |
echo $levels[0]; |
| 1106 |
} else { |
| 1107 |
echo implode(', ', $levels); |
| 1108 |
} |
| 1109 |
} |
| 1110 |
else if ( $catLevels = $this->ppp->ppprotectCheckForProtection( $id ) ) { |
| 1111 |
echo 'Category Protection - ' . $catLevels; |
| 1112 |
} |
| 1113 |
else { |
| 1114 |
echo '(not set)'; |
| 1115 |
} |
| 1116 |
} |
| 1117 |
} |
| 1118 |
} |
| 1119 |
|
| 1120 |
/* handy ajax call for Affiliate Center */ |
| 1121 |
function get_aff_report() { |
| 1122 |
$return = $this->api_call("get_aff_report", $_POST); |
| 1123 |
echo($return["report"]); |
| 1124 |
die(); |
| 1125 |
} |
| 1126 |
|
| 1127 |
/* same but for aff details (setter) */ |
| 1128 |
function update_aff_details() { |
| 1129 |
$return = $this->api_call("update_aff_details", $_POST); |
| 1130 |
echo($return["update"]); |
| 1131 |
die(); |
| 1132 |
} |
| 1133 |
|
| 1134 |
/* same but for cc details (setter) */ |
| 1135 |
function update_cc_details() { |
| 1136 |
global $wpdb; |
| 1137 |
|
| 1138 |
if(wp_verify_nonce($_POST['nonce'], basename(__FILE__))) { |
| 1139 |
|
| 1140 |
|
| 1141 |
if(($_POST["oguser"] != $_POST["username"]) && username_exists($_POST["username"])) { |
| 1142 |
echo "display_notice('Error: That username is taken. Please try another username.');"; |
| 1143 |
die(); |
| 1144 |
} |
| 1145 |
|
| 1146 |
$current_user = wp_get_current_user(); |
| 1147 |
$return = $this->api_call("update_cc_details", $_POST); |
| 1148 |
if(isset($return["updateUser"])) { |
| 1149 |
$wpdb->query("UPDATE {$wpdb->users} SET user_login = '" . $wpdb->escape($_POST["username"]) . "' WHERE ID = '".$current_user->ID."'"); |
| 1150 |
if($_POST["nickname"] == $_POST["oguser"]) { |
| 1151 |
wp_update_user(array("ID" => $current_user->ID, "nickname" => $_POST["username"], "display_name" => $_POST["username"])); |
| 1152 |
} |
| 1153 |
$this->end_session(); |
| 1154 |
} |
| 1155 |
else { |
| 1156 |
wp_update_user(array("ID" => $current_user->ID, "user_pass" => $_POST["password"])); |
| 1157 |
} |
| 1158 |
|
| 1159 |
echo($return["update"]); |
| 1160 |
die(); |
| 1161 |
} |
| 1162 |
} |
| 1163 |
|
| 1164 |
/* grabs form insert code, disables that pesky wpautop */ |
| 1165 |
function get_insert_form_html(){ |
| 1166 |
if(isset($_POST["form_id"])) { |
| 1167 |
remove_filter('the_content', 'wpautop'); |
| 1168 |
$api_result = $this->api_call("get_form", array("form_id" => $_POST["form_id"])); |
| 1169 |
echo $api_result["code"]; |
| 1170 |
die; |
| 1171 |
} |
| 1172 |
} |
| 1173 |
|
| 1174 |
/* grabs video code */ |
| 1175 |
function get_insert_video_html(){ |
| 1176 |
if(isset($_POST["video_id"])) { |
| 1177 |
$api_result = $this->api_call("get_video", array( |
| 1178 |
"video_id" => $_POST["video_id"], |
| 1179 |
"width" => '480', |
| 1180 |
"height" => "320", |
| 1181 |
"player" => $_POST["use_player"], |
| 1182 |
"autoplay" => $_POST["use_autoplay"], |
| 1183 |
"viral" => $_POST["use_viral"], |
| 1184 |
"omit_flowplayerjs" => ($_POST["omit_flowplayerjs"] == "true" ? true : false) |
| 1185 |
)); |
| 1186 |
echo $api_result["code"]; |
| 1187 |
die; |
| 1188 |
} |
| 1189 |
} |
| 1190 |
|
| 1191 |
/* does media insert form itself*/ |
| 1192 |
function media_upload_type_forms() { |
| 1193 |
|
| 1194 |
global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types; |
| 1195 |
|
| 1196 |
media_upload_header(); |
| 1197 |
|
| 1198 |
?> |
| 1199 |
<script type="text/javascript"> |
| 1200 |
|
| 1201 |
var $ = jQuery; |
| 1202 |
|
| 1203 |
function insertForm(the_form_id) { |
| 1204 |
|
| 1205 |
$.post("<?php echo $this->homepage_url; ?>/wp-admin/admin-ajax.php", { action:"pp_insert_form", form_id: the_form_id, 'cookie': encodeURIComponent(document.cookie) }, |
| 1206 |
function(str){ |
| 1207 |
|
| 1208 |
if(typeof top.tinyMCE != 'undefined' && (ed = top.tinyMCE.activeEditor)) { |
| 1209 |
|
| 1210 |
ed = top.tinyMCE.activeEditor; |
| 1211 |
ed.focus(); |
| 1212 |
|
| 1213 |
if(top.tinymce.isIE) { |
| 1214 |
ed.selection.moveToBookmark(top.tinymce.EditorManager.activeEditor.windowManager.bookmark); |
| 1215 |
} |
| 1216 |
|
| 1217 |
ed.execCommand('mceInsertContent', false, str); |
| 1218 |
top.tb_remove(); |
| 1219 |
} else { |
| 1220 |
top.send_to_editor(str); |
| 1221 |
top.tb_remove(); |
| 1222 |
} |
| 1223 |
|
| 1224 |
}); |
| 1225 |
} |
| 1226 |
|
| 1227 |
|
| 1228 |
</script> |
| 1229 |
<?php |
| 1230 |
|
| 1231 |
$forms_list = $this->api_call("get_form_list",""); |
| 1232 |
|
| 1233 |
if(is_array($forms_list)) { |
| 1234 |
foreach($forms_list as $group => $forms) { |
| 1235 |
echo "<div style='padding: 5px; line-height: 16px;'>"; |
| 1236 |
echo "<h2>{$group}</h2>"; |
| 1237 |
if(is_array($forms)) { |
| 1238 |
echo "<table>"; |
| 1239 |
foreach($forms as $idx => $name) { |
| 1240 |
echo "<tr><td><b><a href='JavaScript:insertForm({$idx});' title='form_{$idx}'>{$name}</a></b></td></tr>"; |
| 1241 |
} |
| 1242 |
echo "</table>"; |
| 1243 |
} |
| 1244 |
echo "</div>"; |
| 1245 |
} |
| 1246 |
} |
| 1247 |
|
| 1248 |
} |
| 1249 |
|
| 1250 |
|
| 1251 |
/* same but for videos */ |
| 1252 |
function media_upload_type_videos() { |
| 1253 |
media_upload_header(); |
| 1254 |
|
| 1255 |
$api_result = $this->api_call("get_video_list",""); |
| 1256 |
|
| 1257 |
?> |
| 1258 |
|
| 1259 |
<style type="text/css"> |
| 1260 |
div.img |
| 1261 |
{ |
| 1262 |
background: #EFEFEF; |
| 1263 |
margin:2px; |
| 1264 |
border:1px solid #CCC; |
| 1265 |
height:auto; |
| 1266 |
width:auto; |
| 1267 |
float:left; |
| 1268 |
} |
| 1269 |
div.img img |
| 1270 |
{ |
| 1271 |
display:inline; |
| 1272 |
margin:3px; |
| 1273 |
border:1px solid #ffffff; |
| 1274 |
} |
| 1275 |
div.desc |
| 1276 |
{ |
| 1277 |
font-size: 10px; |
| 1278 |
width:200px; |
| 1279 |
margin:2px; |
| 1280 |
} |
| 1281 |
div.controls |
| 1282 |
{ |
| 1283 |
font-size: 10px; |
| 1284 |
} |
| 1285 |
div.control_button img { |
| 1286 |
padding: 0px; |
| 1287 |
margin: 0px; |
| 1288 |
} |
| 1289 |
div.control_button { |
| 1290 |
padding: 0px; |
| 1291 |
margin: 0px; |
| 1292 |
border: 1px solid #CCC; |
| 1293 |
} |
| 1294 |
</style> |
| 1295 |
|
| 1296 |
<script> |
| 1297 |
var $ = jQuery; |
| 1298 |
|
| 1299 |
function toggle_autoplay(the_video_id) { |
| 1300 |
if($('#autoplay_'+the_video_id).val() != 0) { |
| 1301 |
$('#autoplay_'+the_video_id).val(0); |
| 1302 |
$('#autoplaybtn_'+the_video_id).css('background-color','#EEE'); |
| 1303 |
} else { |
| 1304 |
$('#autoplay_'+the_video_id).val(1); |
| 1305 |
$('#autoplaybtn_'+the_video_id).css('background-color','#CCC'); |
| 1306 |
} |
| 1307 |
} |
| 1308 |
|
| 1309 |
function toggle_viral(the_video_id) { |
| 1310 |
if($('#viral_'+the_video_id).val() != 0) { |
| 1311 |
$('#viral_'+the_video_id).val(0); |
| 1312 |
$('#viralbtn_'+the_video_id).css('background-color','#EEE'); |
| 1313 |
} else { |
| 1314 |
$('#viral_'+the_video_id).val(1); |
| 1315 |
$('#viralbtn_'+the_video_id).css('background-color','#CCC'); |
| 1316 |
} |
| 1317 |
} |
| 1318 |
|
| 1319 |
function insertVideo(the_video_id) { |
| 1320 |
|
| 1321 |
var player = $('#player_'+the_video_id).val(); |
| 1322 |
var autoplay = $('#autoplay_'+the_video_id).val(); |
| 1323 |
var viral = $('#viral_'+the_video_id).val(); |
| 1324 |
var omit_flowplayerjs = false; |
| 1325 |
|
| 1326 |
if($("textarea.wp-editor-area", top.document).val().indexOf("oap_flow/flowplayer") !== -1) { |
| 1327 |
omit_flowplayerjs = true; |
| 1328 |
} |
| 1329 |
|
| 1330 |
$.post("<?php echo $this->homepage_url; ?>/wp-admin/admin-ajax.php", { action: "pp_insert_video", video_id: the_video_id, use_viral: viral, use_player: player, use_autoplay: autoplay, 'cookie': encodeURIComponent(document.cookie), "omit_flowplayerjs": omit_flowplayerjs }, |
| 1331 |
function(str){ |
| 1332 |
var ed; |
| 1333 |
if(typeof top.tinyMCE != 'undefined' && (ed = top.tinyMCE.activeEditor)) { |
| 1334 |
|
| 1335 |
ed = top.tinyMCE.activeEditor; |
| 1336 |
ed.focus(); |
| 1337 |
|
| 1338 |
if(top.tinymce.isIE) { |
| 1339 |
ed.selection.moveToBookmark(top.tinymce.EditorManager.activeEditor.windowManager.bookmark); |
| 1340 |
} |
| 1341 |
|
| 1342 |
ed.execCommand('mceInsertContent', false, str); |
| 1343 |
top.tb_remove(); |
| 1344 |
} else { |
| 1345 |
top.send_to_editor(str); |
| 1346 |
top.tb_remove(); |
| 1347 |
} |
| 1348 |
|
| 1349 |
}); |
| 1350 |
} |
| 1351 |
</script> |
| 1352 |
|
| 1353 |
<?php |
| 1354 |
|
| 1355 |
if(is_array($api_result["list"]) && count($api_result["list"]) > 0) { |
| 1356 |
echo "<div style='padding: 5px; line-height: 16px;'>"; |
| 1357 |
echo "<h2>Videos</h2>"; |
| 1358 |
foreach($api_result["list"] as $video) { |
| 1359 |
|
| 1360 |
if(empty($api_result["thumb_url"]) OR $api_result["thumb_url"] == "") { |
| 1361 |
$thumb = $api_result["default_thumb"]; |
| 1362 |
} else { |
| 1363 |
$thumb = $api_result["thumb_url"].$video["thumb_filename"]; |
| 1364 |
} |
| 1365 |
|
| 1366 |
echo "<div class='img' style=\"cursor: pointer;\"><div onClick='insertVideo({$video["video_id"]})'><img width='200' src='{$thumb}'></div>"; |
| 1367 |
echo "<div class='desc'>{$video["name"]} <span>({$video["duration"]})</span></div>"; |
| 1368 |
echo "<table><tr><td><select id='player_{$video["video_id"]}' name='player_{$video["video_id"]}'><option value='0'>Hidden</option><option value='1' selected>Player 1</option><option value='2'>Player 2</option><option value='3'>Player 3</option></select></td>"; |
| 1369 |
echo "<td><input type='hidden' id='autoplay_{$video["video_id"]}' name='autoplay_{$video["video_id"]}' value='0'><div id='autoplaybtn_{$video["video_id"]}' onClick='toggle_autoplay({$video["video_id"]})' style=\"cursor: pointer;\" class=\"control_button floatLeft\"><img title=\"Autoplay\" src=\"".$this->get_setting("mr_url", "oap")."include/images/boxes/autoplay_ico.gif\"></div></td>"; |
| 1370 |
echo "<td><input type='hidden' id='viral_{$video["video_id"]}' name='viral_{$video["video_id"]}' value='0'><div id='viralbtn_{$video["video_id"]}' onClick='toggle_viral({$video["video_id"]})' style=\"cursor: pointer;\" class=\"control_button floatLeft\"><img title=\"Viral Features\" src=\"".$this->get_setting("mr_url", "oap")."include/images/boxes/viral_vid_ico.gif\"></div></td></tr></table>"; |
| 1371 |
echo "</div>"; |
| 1372 |
} |
| 1373 |
echo "</div>"; |
| 1374 |
} |
| 1375 |
|
| 1376 |
} |
| 1377 |
|
| 1378 |
|
| 1379 |
|
| 1380 |
|
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
/* headers for images.. never happened */ |
| 1385 |
function media_upload_type_images() { |
| 1386 |
media_upload_header(); |
| 1387 |
echo "<div style='padding: 5px; line-height: 16px;'>"; |
| 1388 |
echo "<h2>Images</h2>"; |
| 1389 |
echo "</div>"; |
| 1390 |
} |
| 1391 |
|
| 1392 |
/* binds tab! */ |
| 1393 |
function modify_media_tab($tabs) { |
| 1394 |
$new_tabs = array( |
| 1395 |
'forms' => __('Forms', 'wp-media-oapforms'), |
| 1396 |
'videos' => __('Videos', 'wp-media-oapvideos') |
| 1397 |
); |
| 1398 |
return array_merge($new_tabs, $tabs); |
| 1399 |
} |
| 1400 |
|
| 1401 |
/* shows tab */ |
| 1402 |
function media_upload_forms() { |
| 1403 |
wp_iframe(array($this, 'media_upload_type_forms')); |
| 1404 |
} |
| 1405 |
|
| 1406 |
function media_upload_images() { |
| 1407 |
wp_iframe(array($this, 'media_upload_type_images')); |
| 1408 |
} |
| 1409 |
|
| 1410 |
function media_upload_videos() { |
| 1411 |
wp_iframe(array($this, 'media_upload_type_videos')); |
| 1412 |
} |
| 1413 |
|
| 1414 |
/* this function is disabled for now as it screws up HTML view tidyness... should be an advanced setting in the future */ |
| 1415 |
function tinymce_autop() { |
| 1416 |
?> |
| 1417 |
<script type="text/javascript"> |
| 1418 |
//<![CDATA[ |
| 1419 |
jQuery('body').bind('afterPreWpautop', function(e, o){ |
| 1420 |
o.data = o.unfiltered |
| 1421 |
.replace(/caption\]\[caption/g, 'caption] [caption') |
| 1422 |
.replace(/<object[\s\S]+?<\/object>/g, function(a) { |
| 1423 |
return a.replace(/[\r\n]+/g, ' '); |
| 1424 |
}); |
| 1425 |
|
| 1426 |
}).bind('afterWpautop', function(e, o){ |
| 1427 |
o.data = o.unfiltered; |
| 1428 |
}); |
| 1429 |
//]]> |
| 1430 |
</script> |
| 1431 |
<?php |
| 1432 |
} |
| 1433 |
|
| 1434 |
function modify_tinymce() {} |
| 1435 |
|
| 1436 |
/* south side rockers */ |
| 1437 |
function media_button_add() { |
| 1438 |
|
| 1439 |
global $post_ID, $temp_ID; |
| 1440 |
|
| 1441 |
if($this->is_setup()) { |
| 1442 |
$uploading_iframe_ID = (int) (0 == $post_ID ? $temp_ID : $post_ID); |
| 1443 |
$media_upload_iframe_src = "media-upload.php?post_id=$uploading_iframe_ID"; |
| 1444 |
$media_oap_iframe_src = apply_filters('media_oap_iframe_src', "$media_upload_iframe_src&tab=forms"); |
| 1445 |
$media_oap_title = __('Add ' . self::$brand . ' Media', 'wp-media-oapform'); |
| 1446 |
echo "<a href=\"{$media_oap_iframe_src}&TB_iframe=true&height=500&width=640\" class=\"thickbox\" title=\"$media_oap_title\"><img src=\"".$this->get_setting("mr_url", "oap")."static/media-button-pp.gif\" alt=\"$media_oap_title\" /></a>"; |
| 1447 |
} |
| 1448 |
} |
| 1449 |
|
| 1450 |
/* this function adds the metaboxes defined in construct() to the WP admin */ |
| 1451 |
function metabox_add() { |
| 1452 |
if($this->is_setup()) { |
| 1453 |
$this->load_metaboxes(); |
| 1454 |
foreach($this->metaboxes as $id => $details) { |
| 1455 |
$types = array(); |
| 1456 |
foreach($this->get_setting("post_types","wp") as $type) { |
| 1457 |
add_meta_box($details['id'], $details['title'], array($this, "metabox_display"), $type, $details['context'], $details['priority']); |
| 1458 |
array_push($types, $type); |
| 1459 |
} |
| 1460 |
if ( !in_array( 'ontrapage', $types ) ) |
| 1461 |
{ |
| 1462 |
add_meta_box($details['id'], $details['title'], array($this, "metabox_display"), 'ontrapage', $details['context'], $details['priority']); |
| 1463 |
} |
| 1464 |
} |
| 1465 |
} |
| 1466 |
} |
| 1467 |
|
| 1468 |
/* loop through and save some stuff for us */ |
| 1469 |
function metabox_save($post_id) { |
| 1470 |
|
| 1471 |
if (!wp_verify_nonce($_POST[self::NSPACE.'nonce'], basename(__FILE__))) { |
| 1472 |
return $post_id; |
| 1473 |
} |
| 1474 |
|
| 1475 |
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { |
| 1476 |
return $post_id; |
| 1477 |
} |
| 1478 |
|
| 1479 |
if ('page' == $_POST['post_type']) { |
| 1480 |
if(!current_user_can('edit_page', $post_id)) { |
| 1481 |
return $post_id; |
| 1482 |
} |
| 1483 |
} elseif (!current_user_can('edit_post', $post_id)) { |
| 1484 |
return $post_id; |
| 1485 |
} |
| 1486 |
|
| 1487 |
foreach($_POST[self::NSPACE."metaboxes"] as $metabox) { |
| 1488 |
foreach ($this->metaboxes[$metabox]["fields"] as $field) { |
| 1489 |
|
| 1490 |
if(empty($_POST[$field['id']])) { |
| 1491 |
delete_post_meta($post_id, $field['id']); |
| 1492 |
} |
| 1493 |
|
| 1494 |
if(is_array($_POST[$field['id']])) { |
| 1495 |
delete_post_meta($post_id, $field["id"]); |
| 1496 |
foreach($_POST[$field['id']] as $new) { |
| 1497 |
add_post_meta($post_id, $field['id'], $new); |
| 1498 |
} |
| 1499 |
} else { |
| 1500 |
if(!empty($_POST[$field['id']])) { |
| 1501 |
update_post_meta($post_id, $field['id'], $_POST[$field['id']]); |
| 1502 |
} |
| 1503 |
} |
| 1504 |
} |
| 1505 |
} |
| 1506 |
} |
| 1507 |
|
| 1508 |
|
| 1509 |
function metabox_display($post_ref, $pass_thru) { |
| 1510 |
|
| 1511 |
global $post; |
| 1512 |
|
| 1513 |
echo '<input type="hidden" name="'.self::NSPACE.'nonce" value="', wp_create_nonce(basename(__FILE__)), '" />'; |
| 1514 |
echo '<input type="hidden" name="'.self::NSPACE.'metaboxes[]" value="'.$pass_thru["id"].'" />'; |
| 1515 |
echo '<table class="form-table">'; |
| 1516 |
|
| 1517 |
foreach ($this->metaboxes[$pass_thru["id"]]['fields'] as $field) { |
| 1518 |
|
| 1519 |
$meta = get_post_meta($post->ID, $field['id']); |
| 1520 |
|
| 1521 |
if(is_array($meta) && count($meta) < 2 && array_key_exists(0, $meta)) { |
| 1522 |
$meta = $meta[0]; |
| 1523 |
} |
| 1524 |
|
| 1525 |
if(empty($meta)) { |
| 1526 |
$meta = array(); |
| 1527 |
} |
| 1528 |
|
| 1529 |
if($field["type"] != "single-checkbox") { |
| 1530 |
echo '<tr><td><label for="', $field['id'], '"><b>', $field['name'], '</b></label><br/>'; |
| 1531 |
} |
| 1532 |
|
| 1533 |
switch ($field['type']) { |
| 1534 |
|
| 1535 |
case "text": |
| 1536 |
echo "<input type='text' name='{$field['id']}' id='{$field['id']}'"; |
| 1537 |
if(!empty($meta)) { |
| 1538 |
if(is_array($meta)) { |
| 1539 |
echo " value='{$meta[0]}'"; |
| 1540 |
} else { |
| 1541 |
echo " value='{$meta}'"; |
| 1542 |
} |
| 1543 |
} |
| 1544 |
echo "><br/>"; |
| 1545 |
break; |
| 1546 |
|
| 1547 |
case 'select': |
| 1548 |
echo '<select name="', $field['id'], '" id="', $field['id'], '">'; |
| 1549 |
foreach ($field['options'] as $option) { |
| 1550 |
echo '<option', $meta == $option ? ' selected="selected"' : '', '>', $option, '</option>'; |
| 1551 |
} |
| 1552 |
echo '</select><br/>'; |
| 1553 |
break; |
| 1554 |
|
| 1555 |
case 'select-keyvalue': |
| 1556 |
|
| 1557 |
if($field["id"] == self::NSPACE."redirect_location") { |
| 1558 |
$field["options"] = $this->get_routeable_pages(array($post->ID)); |
| 1559 |
} |
| 1560 |
|
| 1561 |
echo '<select name="', $field['id'], '" id="', $field['id'], '">'; |
| 1562 |
foreach ($field['options'] as $key => $option) { |
| 1563 |
echo '<option value="'.$key.'" ', $meta == $key ? ' selected="selected"' : '', '>', $option, '</option>'; |
| 1564 |
} |
| 1565 |
echo '</select><br/>'; |
| 1566 |
|
| 1567 |
break; |
| 1568 |
|
| 1569 |
case 'multi-checkbox': |
| 1570 |
if(in_array($post->ID, $this->system_pages)) { |
| 1571 |
echo "<b style='color: green;'>N/A</b><br/>"; |
| 1572 |
} else { |
| 1573 |
if(is_array($field["options"]) && count($field["options"]) > 0) { |
| 1574 |
foreach ($field['options'] as $key => $option) { |
| 1575 |
if(is_array($meta)) { |
| 1576 |
echo '<label class="pp-access-level"><input type="checkbox" name="'.$field['id'].'[]" value="'.$option.'" ', in_array($option, $meta) ? ' checked' : '', ' /><span class="pp-access-level-label"> ', $option, '</span></label>'; |
| 1577 |
} else { |
| 1578 |
echo '<label class="pp-access-level"><input type="checkbox" name="'.$field['id'].'[]" value="'.$option.'" ', $option == $meta ? ' checked' : '', ' /><span class="pp-access-level-label"> ', $option, '</span></label>'; |
| 1579 |
} |
| 1580 |
} |
| 1581 |
} |
| 1582 |
} |
| 1583 |
|
| 1584 |
break; |
| 1585 |
case 'radio': |
| 1586 |
foreach ($field['options'] as $option) { |
| 1587 |
echo '<input type="radio" name="', $field['id'], '" value="', $option['value'], '"', $meta == $option['value'] ? ' checked="checked"' : '', ' /> ', $option['name']; |
| 1588 |
echo " "; |
| 1589 |
} |
| 1590 |
break; |
| 1591 |
case 'single-checkbox': |
| 1592 |
echo '<tr><td><input type="checkbox" name="', $field['id'], '" id="', $field['id'], '"', $meta ? ' checked="checked"' : '', ' /> <label for="', $field['id'], '"><b>', $field['name'], '</b></label>'; |
| 1593 |
echo ''; |
| 1594 |
break; |
| 1595 |
} |
| 1596 |
|
| 1597 |
if($field["id"] != self::NSPACE."redirect_location") { |
| 1598 |
|
| 1599 |
} else { |
| 1600 |
|
| 1601 |
} |
| 1602 |
|
| 1603 |
if($field["desc"]) { |
| 1604 |
echo '<span class="pp-access-level-note">'.$field["desc"].'</span>'; |
| 1605 |
} |
| 1606 |
|
| 1607 |
echo '</tr>'; |
| 1608 |
} |
| 1609 |
|
| 1610 |
echo '</table>'; |
| 1611 |
} |
| 1612 |
|
| 1613 |
|
| 1614 |
|
| 1615 |
|
| 1616 |
/* ok, time for some seriousness... this does the login. see additional comments inline */ |
| 1617 |
function user_login($username, $password) { |
| 1618 |
if(isset($_POST["wp-submit"])) { |
| 1619 |
|
| 1620 |
//Wordpress trims trailing and leading spaces before authenticating, lets do the same. |
| 1621 |
$password = trim($password); |
| 1622 |
|
| 1623 |
$hashed_password = $username . self::VERSION . $password . self::AUTH_SALT; |
| 1624 |
|
| 1625 |
$supported_algos = hash_algos(); |
| 1626 |
if (in_array("sha256", $supported_algos)) |
| 1627 |
{ |
| 1628 |
$algo = "sha256"; |
| 1629 |
$hash = hash("sha256", $hashed_password); |
| 1630 |
} |
| 1631 |
else |
| 1632 |
{ |
| 1633 |
$algo = "md5"; |
| 1634 |
$hash = md5($hashed_password); |
| 1635 |
} |
| 1636 |
|
| 1637 |
$api_result = $this->api_call("authenticate_user", array("site" => site_url(), "username" => $username, "password" => $hash, "version" => self::VERSION, "algo" => $algo)); |
| 1638 |
|
| 1639 |
/* user does exist */ |
| 1640 |
if(is_array($api_result)) { |
| 1641 |
|
| 1642 |
if(!username_exists($username) && $api_result["status"] != 0) { |
| 1643 |
|
| 1644 |
/* if their email is used (might have been a blog user before OAP perhaps), use alternate name */ |
| 1645 |
if(email_exists($api_result["email"])) { |
| 1646 |
$email = $api_result["email_alt"]; |
| 1647 |
$email_alt = $api_result["email"]; |
| 1648 |
} else { |
| 1649 |
$email = $api_result["email"]; |
| 1650 |
$email_alt = $api_result["email_alt"]; |
| 1651 |
} |
| 1652 |
|
| 1653 |
/* scary WP create user */ |
| 1654 |
$create_user = wp_create_user($username, $password, $email); |
| 1655 |
|
| 1656 |
/* if this errors, tell us! */ |
| 1657 |
if(isset($create_user->errors) && isset($create_user->errors["existing_user_email"])) { |
| 1658 |
unset($create_user); |
| 1659 |
$create_user = wp_create_user($username, $password, $email_alt); |
| 1660 |
} |
| 1661 |
|
| 1662 |
if(isset($create_user->errors)) { |
| 1663 |
$this->api_call("create_user_error", array("message" => site_url())); |
| 1664 |
return false; |
| 1665 |
} |
| 1666 |
|
| 1667 |
if(isset($api_result["nickname"])) { |
| 1668 |
wp_update_user(array("ID" => $create_user, "nickname" => $api_result["nickname"], "display_name" => $api_result["nickname"])); |
| 1669 |
} |
| 1670 |
|
| 1671 |
} else { |
| 1672 |
|
| 1673 |
/* this user does exist, so log us in */ |
| 1674 |
$user = get_userdatabylogin($username); |
| 1675 |
|
| 1676 |
if($user) { |
| 1677 |
/* ruhroh, this person is no longer welcomed! */ |
| 1678 |
if($api_result["status"] == 0) { |
| 1679 |
include_once(ABSPATH.'wp-admin/includes/user.php'); |
| 1680 |
wp_delete_user($user->ID); |
| 1681 |
return; |
| 1682 |
} else if($user->user_level != 10) { |
| 1683 |
/* ghetto "sync" of password... saves alot of scary stuff as they are already authenticated.. */ |
| 1684 |
wp_set_password($password , $user->ID); |
| 1685 |
} |
| 1686 |
else { |
| 1687 |
return false; |
| 1688 |
} |
| 1689 |
} else { |
| 1690 |
|
| 1691 |
return false; |
| 1692 |
} |
| 1693 |
} |
| 1694 |
|
| 1695 |
/* store where the user logged in from for redirection after logout */ |
| 1696 |
$referrer = $_SERVER['HTTP_REFERER']; |
| 1697 |
if(!empty($referrer)) $_SESSION["loginURL"] = $referrer; |
| 1698 |
|
| 1699 |
$user = get_userdatabylogin($username); |
| 1700 |
|
| 1701 |
//User is not the admin user... admin doesnt get to have their session set. |
| 1702 |
if($user->user_level != 10) { |
| 1703 |
|
| 1704 |
/* this person is not an admit, so lets make this person special */ |
| 1705 |
if(defined("COOKIE_DOMAIN") && COOKIE_DOMAIN == "") { |
| 1706 |
$cookie_domain = str_replace($this->get_protocol(),"",site_url()); |
| 1707 |
} else { |
| 1708 |
$cookie_domain = COOKIE_DOMAIN; |
| 1709 |
} |
| 1710 |
|
| 1711 |
setcookie("contact_id", $api_result["contact_id"], (time() + 2419200), COOKIEPATH, $cookie_domain, false); |
| 1712 |
|
| 1713 |
$user_id = $user->ID; |
| 1714 |
$remember = false; |
| 1715 |
if (!empty($_POST["rememberme"])) |
| 1716 |
{ |
| 1717 |
$remember = true; |
| 1718 |
} |
| 1719 |
wp_set_current_user($user_id, $username); |
| 1720 |
wp_set_auth_cookie($user_id ,$remember); |
| 1721 |
do_action('wp_login', $username , $user); |
| 1722 |
|
| 1723 |
if(!isset($_SESSION["user_name"])) { |
| 1724 |
|
| 1725 |
$this->start_session(); |
| 1726 |
|
| 1727 |
|
| 1728 |
foreach($api_result as $key => $value) { |
| 1729 |
$_SESSION[$key] = $value; |
| 1730 |
} |
| 1731 |
$_SESSION["user_name"] = $api_result["username"]; |
| 1732 |
$_SESSION["nickname"] = $api_result["nickname"]; |
| 1733 |
$_SESSION["user_levels"] = $api_result["membership_level"]; |
| 1734 |
$_SESSION["rehash"] = true; |
| 1735 |
} |
| 1736 |
|
| 1737 |
/* where to go from here */ |
| 1738 |
if(isset($_SESSION["redirect_to"]) && !empty($_SESSION["redirect_to"])) { |
| 1739 |
$redirect_to = $_SESSION["redirect_to"]; |
| 1740 |
|
| 1741 |
if(is_numeric($redirect_to)) { |
| 1742 |
$redirect_to = get_permalink($redirect_to); |
| 1743 |
} |
| 1744 |
|
| 1745 |
unset($_SESSION["redirect_to"]); |
| 1746 |
self::redirect($redirect_to); |
| 1747 |
die; |
| 1748 |
} |
| 1749 |
|
| 1750 |
/* this person is an affiliate, put them somewhere nice */ |
| 1751 |
if(isset($api_result["program_id"])) { |
| 1752 |
$aff_plr = $this->get_setting("pilotpress_affiliate_plr"); |
| 1753 |
if($aff_plr && $aff_plr != "-1") { |
| 1754 |
self::redirect(get_permalink($aff_plr)); |
| 1755 |
die; |
| 1756 |
exit; |
| 1757 |
} else { |
| 1758 |
self::redirect(site_url()); |
| 1759 |
die; |
| 1760 |
} |
| 1761 |
} else { |
| 1762 |
|
| 1763 |
$cust_plr = $this->get_setting("pilotpress_customer_plr"); |
| 1764 |
if($cust_plr && $cust_plr != "-1") { |
| 1765 |
self::redirect(get_permalink($cust_plr)); |
| 1766 |
die; |
| 1767 |
} else { |
| 1768 |
self::redirect(site_url()); |
| 1769 |
die; |
| 1770 |
} |
| 1771 |
} |
| 1772 |
die; |
| 1773 |
} |
| 1774 |
} |
| 1775 |
} |
| 1776 |
} |
| 1777 |
|
| 1778 |
/* redirect the user to a failed login page */ |
| 1779 |
function user_login_failed() { |
| 1780 |
$referrer = $_SERVER['HTTP_REFERER']; |
| 1781 |
if(!empty($referrer) && !strstr($referrer, "wp-login") && !strstr($referrer, "wp-admin") ) { |
| 1782 |
$_SESSION["loginFailed"] = true; |
| 1783 |
self::redirect($referrer); |
| 1784 |
die; |
| 1785 |
} |
| 1786 |
} |
| 1787 |
|
| 1788 |
function user_lostpassword() { |
| 1789 |
$api_result = $this->api_call("user_lostpassword", array("site" => site_url(), "username" => $_POST['user_login'])); |
| 1790 |
|
| 1791 |
if(!is_array($api_result)) |
| 1792 |
{ |
| 1793 |
/* display invalid username or e-mail message*/ |
| 1794 |
$_POST['user_login'] = ""; |
| 1795 |
} |
| 1796 |
else |
| 1797 |
{ |
| 1798 |
/* notify user of e-mail, end the rest of WP's processing */ |
| 1799 |
self::redirect(site_url() . "/wp-login.php?checkemail=confirm"); |
| 1800 |
die; |
| 1801 |
} |
| 1802 |
} |
| 1803 |
|
| 1804 |
function user_logout() { |
| 1805 |
$this->end_session(true); |
| 1806 |
} |
| 1807 |
|
| 1808 |
/** @brief if possible add th enew user to ONTRAPORT when registered in WordPress */ |
| 1809 |
function add_new_register_user_to_ONTRAPORT($user_id) { |
| 1810 |
|
| 1811 |
$bAddUser = $this->get_setting("pilotpress_add_newly_registered_users"); |
| 1812 |
if (!$bAddUser) |
| 1813 |
{ |
| 1814 |
return; |
| 1815 |
} |
| 1816 |
|
| 1817 |
$appid = $this->get_setting("app_id"); |
| 1818 |
$key = $this->get_setting("api_key"); |
| 1819 |
$tagList = $this->get_setting("pilotpress_newly_registered_tags"); |
| 1820 |
$sequenceList = $this->get_setting("pilotpress_newly_registered_sequences"); |
| 1821 |
$user = get_userdata($user_id); |
| 1822 |
$userData = array( |
| 1823 |
"firstname"=>$user->user_firstname, |
| 1824 |
"lastname"=>$user->user_lastname, |
| 1825 |
"email"=>$user->user_email, |
| 1826 |
"tags"=>$tagList, |
| 1827 |
"sequences"=>$sequenceList |
| 1828 |
); |
| 1829 |
|
| 1830 |
$api_result = $this->api_call("add_newly_registered_contact", $userData); |
| 1831 |
} |
| 1832 |
|
| 1833 |
static function start_session() { |
| 1834 |
ob_start(); |
| 1835 |
if(!session_id()) { |
| 1836 |
session_start(); |
| 1837 |
} |
| 1838 |
ob_end_clean(); |
| 1839 |
} |
| 1840 |
|
| 1841 |
static function end_session($logout = false) { |
| 1842 |
|
| 1843 |
if($logout) { |
| 1844 |
/* redirect the user to where they logged in from */ |
| 1845 |
if(isset($_SESSION["loginURL"])) |
| 1846 |
self::redirect($_SESSION["loginURL"]); |
| 1847 |
else |
| 1848 |
self::redirect(site_url()); |
| 1849 |
} |
| 1850 |
|
| 1851 |
ob_start(); |
| 1852 |
if(session_id()) { |
| 1853 |
delete_transient("pilotpress_cache"); |
| 1854 |
if(isset($_SESSION["contact_id"])) { |
| 1855 |
delete_transient("usertags_".$_SESSION["contact_id"]); |
| 1856 |
} |
| 1857 |
unset($_SESSION); |
| 1858 |
session_destroy(); |
| 1859 |
} |
| 1860 |
ob_end_clean(); |
| 1861 |
|
| 1862 |
if($logout) die; |
| 1863 |
} |
| 1864 |
|
| 1865 |
function filter_query_vars($vars) { |
| 1866 |
return $vars; |
| 1867 |
} |
| 1868 |
|
| 1869 |
function filter_rewrite_rules($rules) { |
| 1870 |
global $wp_rewrite; |
| 1871 |
$newRule = array('ref/(.+)' => 'index.php?ref='.$wp_rewrite->preg_index(1)); |
| 1872 |
$newRules = $newRule + $rules; |
| 1873 |
return $newRules; |
| 1874 |
} |
| 1875 |
|
| 1876 |
function flush_rewrite_rules() { |
| 1877 |
global $wp_rewrite; |
| 1878 |
$wp_rewrite->flush_rules(); |
| 1879 |
} |
| 1880 |
|
| 1881 |
function clean_meta() { |
| 1882 |
global $wpdb; |
| 1883 |
$wpdb->query("DELETE FROM $wpdb->postmeta WHERE meta_key = '_pilotpress_level' AND meta_value = ''"); |
| 1884 |
} |
| 1885 |
|
| 1886 |
/* Load up the membership level meta boxes but after we have gotten the levels */ |
| 1887 |
function load_metaboxes() { |
| 1888 |
|
| 1889 |
/* metaboxes in admin */ |
| 1890 |
$this->metaboxes[self::NSPACE."page_box"] = array( |
| 1891 |
'id' => self::NSPACE.'page_box', |
| 1892 |
'title' => 'PilotPress Options', |
| 1893 |
'context' => 'side', |
| 1894 |
'priority' => 'high', |
| 1895 |
'fields' => array( |
| 1896 |
array( |
| 1897 |
'name' => 'Access Levels', |
| 1898 |
'desc' => '(Leave blank to allow access to all users.)', |
| 1899 |
'id' => self::NSPACE.'level', |
| 1900 |
'type' => 'multi-checkbox', |
| 1901 |
'options' => $this->get_setting("membership_levels", "oap") |
| 1902 |
), |
| 1903 |
array( |
| 1904 |
'name' => 'Show in Navigation', |
| 1905 |
'desc' => false, |
| 1906 |
'id' => self::NSPACE.'show_in_nav', |
| 1907 |
'type' => 'single-checkbox' |
| 1908 |
), |
| 1909 |
array( |
| 1910 |
'name' => 'On Error', |
| 1911 |
'desc' => $this->get_setting("error_redirect_message"), |
| 1912 |
'id' => self::NSPACE.'redirect_location', |
| 1913 |
'type' => $this->get_setting("error_redirect_field"), |
| 1914 |
'options' => array() |
| 1915 |
) |
| 1916 |
) |
| 1917 |
); |
| 1918 |
|
| 1919 |
} |
| 1920 |
|
| 1921 |
/* shortcodes for conditional ifs */ |
| 1922 |
function shortcode_show_if($atts, $content = null) { |
| 1923 |
|
| 1924 |
if(isset($atts[0]) && $atts[0] == "not_contact") { |
| 1925 |
if(!$this->get_setting("contact_id","user")) { |
| 1926 |
return '<span class="pilotpress_protected">'.do_shortcode($content).'</span>'; |
| 1927 |
} |
| 1928 |
} |
| 1929 |
//make cookie check befor login check to bypass it |
| 1930 |
if ( isset($atts[0]) && $atts[0] == "is_cookied_contact") |
| 1931 |
{ |
| 1932 |
if (isset($_SESSION["contact_id"])) |
| 1933 |
{ |
| 1934 |
return '<span class="pilotpress_prtoected">'.do_shortcode($content) . '</span>'; |
| 1935 |
} |
| 1936 |
} |
| 1937 |
|
| 1938 |
if (isset($atts[0]) && $atts[0] == "not_cookied_contact") |
| 1939 |
{ |
| 1940 |
if (!isset($_SESSION["contact_id"])) |
| 1941 |
{ |
| 1942 |
return '<span class="pilotpress_prtoected">'.do_shortcode($content) . '</span>'; |
| 1943 |
} |
| 1944 |
} |
| 1945 |
if(!is_user_logged_in()) { |
| 1946 |
return; |
| 1947 |
} |
| 1948 |
|
| 1949 |
if ($found = self::DoShortcodeMagic($atts,$content)) |
| 1950 |
{ |
| 1951 |
return $found; |
| 1952 |
} |
| 1953 |
|
| 1954 |
//if we fail to find something lets make sure Wordpress hasnt encoded the tags and membership levels. |
| 1955 |
foreach ($atts as $key => $att) |
| 1956 |
{ |
| 1957 |
$atts[$key] = html_entity_decode($atts[$key]); |
| 1958 |
} |
| 1959 |
//process shortcodes with decoded entities |
| 1960 |
return self::DoShortcodeMagic($atts,$content); |
| 1961 |
} |
| 1962 |
|
| 1963 |
/* |
| 1964 |
* @brief Process additional shortcode logic here |
| 1965 |
* |
| 1966 |
**/ |
| 1967 |
function DoShortcodeMagic($atts,$content) |
| 1968 |
{ |
| 1969 |
$user_levels = $this->get_setting("levels","user", true); |
| 1970 |
|
| 1971 |
if(!is_array($user_levels)) { |
| 1972 |
$user_levels = array(); |
| 1973 |
} |
| 1974 |
|
| 1975 |
if(isset($atts["level"])) { |
| 1976 |
if(in_array($atts["level"], $user_levels)) { |
| 1977 |
return '<span class="pilotpress_protected">'.do_shortcode($content).'</span>'; |
| 1978 |
} |
| 1979 |
} else { |
| 1980 |
|
| 1981 |
if(isset($atts["has_one"])) { |
| 1982 |
$content_levels = explode(",", $atts["has_one"]); |
| 1983 |
foreach($user_levels as $level) { |
| 1984 |
if(in_array(ltrim(rtrim($level)), $content_levels)) { |
| 1985 |
return '<span class="pilotpress_protected">'.do_shortcode($content).'</span>'; |
| 1986 |
} |
| 1987 |
} |
| 1988 |
} |
| 1989 |
|
| 1990 |
if(isset($atts["has_all"])) { |
| 1991 |
$content_levels = explode(",", $atts["has_all"]); |
| 1992 |
foreach($content_levels as $level) { |
| 1993 |
if(!in_array(ltrim(rtrim($level)), $user_levels)) { |
| 1994 |
return false; |
| 1995 |
} |
| 1996 |
} |
| 1997 |
return '<span class="pilotpress_protected">'.do_shortcode($content).'</span>'; |
| 1998 |
} |
| 1999 |
|
| 2000 |
if(isset($atts["not_one"])) { |
| 2001 |
$content_levels = explode(",", $atts["not_one"]); |
| 2002 |
foreach($content_levels as $level) { |
| 2003 |
if(in_array(ltrim(rtrim($level)), $user_levels)) { |
| 2004 |
return false; |
| 2005 |
} |
| 2006 |
} |
| 2007 |
return '<span class="pilotpress_protected">'.do_shortcode($content).'</span>'; |
| 2008 |
} |
| 2009 |
|
| 2010 |
if(isset($atts["not_any"])) { |
| 2011 |
$content_levels = explode(",", $atts["not_any"]); |
| 2012 |
foreach($user_levels as $level) { |
| 2013 |
if(!in_array(ltrim(rtrim($level)), $content_levels)) { |
| 2014 |
return '<span class="pilotpress_protected">'.do_shortcode($content).'</span>'; |
| 2015 |
} |
| 2016 |
} |
| 2017 |
} |
| 2018 |
|
| 2019 |
if(isset($atts[0]) && $atts[0] == "is_contact") { |
| 2020 |
if($this->get_setting("contact_id","user")) { |
| 2021 |
return '<span class="pilotpress_protected">'.do_shortcode($content).'</span>'; |
| 2022 |
} |
| 2023 |
} |
| 2024 |
|
| 2025 |
if(isset($atts["has_tag"])) { |
| 2026 |
$tags = $this->get_setting("tags", "user"); |
| 2027 |
if(is_array($tags)) { |
| 2028 |
if(in_array($atts["has_tag"], $tags)) { |
| 2029 |
return '<span class="pilotpress_protected">'.do_shortcode($content).'</span>'; |
| 2030 |
} |
| 2031 |
} |
| 2032 |
} |
| 2033 |
|
| 2034 |
if(isset($atts[0]) && in_array($atts[0], $user_levels)) { |
| 2035 |
return '<span class="pilotpress_protected">'.do_shortcode($content).'</span>'; |
| 2036 |
} |
| 2037 |
} |
| 2038 |
} |
| 2039 |
|
| 2040 |
function shortcode_field($atts, $content = null) { |
| 2041 |
|
| 2042 |
extract(shortcode_atts(array("name" => "All"), $atts)); |
| 2043 |
|
| 2044 |
if(isset($atts["name"])) { |
| 2045 |
return $this->get_field($atts["name"]); |
| 2046 |
} |
| 2047 |
|
| 2048 |
} |
| 2049 |
|
| 2050 |
/* the big nasty content hiding function... tread carefully */ |
| 2051 |
function post_process () |
| 2052 |
{ |
| 2053 |
global $wp, $wpdb, $post; |
| 2054 |
|
| 2055 |
if (isset($post->ID)) |
| 2056 |
{ |
| 2057 |
$id = $post->ID; |
| 2058 |
} |
| 2059 |
else |
| 2060 |
{ |
| 2061 |
$id = $this->get_postid_by_url(); |
| 2062 |
if (empty($id) && get_option('show_on_front') == 'page') |
| 2063 |
{ |
| 2064 |
$id = get_option('page_on_front'); |
| 2065 |
} |
| 2066 |
} |
| 2067 |
|
| 2068 |
if (!$this->is_viewable($id) && !is_home()) |
| 2069 |
{ |
| 2070 |
$redirect = get_post_meta($id, self::NSPACE."redirect_location", true); |
| 2071 |
if (!empty($redirect)) |
| 2072 |
{ |
| 2073 |
if ($redirect == "-1") |
| 2074 |
{ |
| 2075 |
return self::redirect(site_url()); |
| 2076 |
} |
| 2077 |
else if ($redirect == "-2") |
| 2078 |
{ |
| 2079 |
if (!empty($id)) |
| 2080 |
{ |
| 2081 |
$_SESSION["redirect_to"] = $id; |
| 2082 |
} |
| 2083 |
} |
| 2084 |
return self::redirect(get_permalink($redirect)); |
| 2085 |
} |
| 2086 |
else |
| 2087 |
{ |
| 2088 |
return self::redirect($this->homepage_url); |
| 2089 |
} |
| 2090 |
} |
| 2091 |
} |
| 2092 |
|
| 2093 |
/* is this a special page? if so render such */ |
| 2094 |
function content_process($content) { |
| 2095 |
global $post; |
| 2096 |
|
| 2097 |
if($this->do_login == true) { |
| 2098 |
if(!is_user_logged_in()) { |
| 2099 |
$content = $this->login_page(array(), 1); |
| 2100 |
} else { |
| 2101 |
$content = $this->login_page(array(), 2); |
| 2102 |
} |
| 2103 |
$this->do_login = false; |
| 2104 |
} else { |
| 2105 |
if(isset($_SESSION["loginFailed"])) { |
| 2106 |
$login_page = $this->login_page(array(), 3); |
| 2107 |
$content = str_replace("[login_page]", $login_page, $content, $count); |
| 2108 |
if($count == 0) { |
| 2109 |
$content = $login_page; |
| 2110 |
} |
| 2111 |
unset($_SESSION["loginFailed"]); |
| 2112 |
} |
| 2113 |
else { |
| 2114 |
if(is_page() && in_array($post->ID, $this->system_pages)) { |
| 2115 |
$content = $this->do_system_page($post->ID); |
| 2116 |
} |
| 2117 |
|
| 2118 |
if (has_shortcode($content, "pilotpress_field") || has_shortcode($content, "field")) |
| 2119 |
{ |
| 2120 |
// Lets grab all the fields here with the API call and store them later |
| 2121 |
// Since the shortcode hook runs after this one it is a safe spot to check and make if needed. |
| 2122 |
$this->get_merge_field_settings($content); |
| 2123 |
} |
| 2124 |
} |
| 2125 |
} |
| 2126 |
|
| 2127 |
return $content; |
| 2128 |
} |
| 2129 |
|
| 2130 |
|
| 2131 |
/** |
| 2132 |
* @brief Make api call to grab merge fields that are only present in the content |
| 2133 |
* |
| 2134 |
* @param String $content the string to check if merge fields are present |
| 2135 |
* |
| 2136 |
*/ |
| 2137 |
function get_merge_field_settings($content , $makeApiCall = true) |
| 2138 |
{ |
| 2139 |
$pattern = get_shortcode_regex(); |
| 2140 |
|
| 2141 |
preg_match_all('/'.$pattern.'/uis', $content, $matches); |
| 2142 |
|
| 2143 |
for ( $i=0; $i < count($matches[0]); $i++ ) |
| 2144 |
{ |
| 2145 |
$fields = shortcode_parse_atts($matches[3][$i]); |
| 2146 |
|
| 2147 |
if ( isset( $matches[2][$i] ) && ($matches[2][$i] == "pilotpress_field" || $matches[2][$i] == "field") ) |
| 2148 |
{ |
| 2149 |
$this->shortcodeFields[$fields["name"]] = 1; |
| 2150 |
} |
| 2151 |
elseif (!empty($matches[5][$i])) |
| 2152 |
{ |
| 2153 |
//call this recursively so we can process shortcodes inside shortcodes |
| 2154 |
$this->get_merge_field_settings($matches[5][$i] , false); |
| 2155 |
} |
| 2156 |
} |
| 2157 |
|
| 2158 |
//Since this can be called recursively lets make sure when it does call it we only make this at the initial call of the function |
| 2159 |
if ($makeApiCall) |
| 2160 |
{ |
| 2161 |
//make API call now as well if needed! |
| 2162 |
if (!empty($this->shortcodeFields) && is_array($this->shortcodeFields) && !empty($_SESSION["user_name"])) |
| 2163 |
{ |
| 2164 |
$data = array( |
| 2165 |
"username" => $_SESSION["user_name"], |
| 2166 |
"fields" => $this->shortcodeFields, |
| 2167 |
"site" => site_url() |
| 2168 |
); |
| 2169 |
|
| 2170 |
$api_result = $this->api_call("get_contact_merge_fields" , $data); |
| 2171 |
|
| 2172 |
if(isset($api_result["fields"])) |
| 2173 |
{ |
| 2174 |
// In order for the get_field() to work later on we need to add these fields to the group list of known merged fields. |
| 2175 |
$_SESSION["user_fields"]["--merged fields--"] = $api_result["fields"]; |
| 2176 |
$this->settings["user"]["fields"]["--merged fields--"] = $api_result["fields"]; |
| 2177 |
} |
| 2178 |
} |
| 2179 |
} |
| 2180 |
} |
| 2181 |
|
| 2182 |
/* this is arguably the nastiest part of PilotPress, but unfortunately WP has consistently decided to not allow non-theme based manipulation of viewable pages */ |
| 2183 |
function get_routeable_pages($exclude = "") { |
| 2184 |
|
| 2185 |
global $post, $wpdb; |
| 2186 |
|
| 2187 |
$array = array('-1' => "(homepage)", "-2" => "(login page)"); |
| 2188 |
|
| 2189 |
$query = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts WHERE post_status = 'publish' AND (post_type = 'page' OR post_type ='oaplesson') AND post_title != ''"); |
| 2190 |
|
| 2191 |
foreach($query as $index => $page) { |
| 2192 |
$array[$page->ID] = $page->post_title; |
| 2193 |
} |
| 2194 |
|
| 2195 |
if(is_array($exclude)) { |
| 2196 |
foreach($exclude as $id) { |
| 2197 |
unset($array[$id]); |
| 2198 |
} |
| 2199 |
} |
| 2200 |
|
| 2201 |
return apply_filters("pilotpress_get_routeable_pages",$array); |
| 2202 |
} |
| 2203 |
|
| 2204 |
/* this is where we part the seas: if something isn't routable, then tree falls in the woods to no fuss */ |
| 2205 |
function posts_where($where) { |
| 2206 |
global $wpdb; |
| 2207 |
|
| 2208 |
if(current_user_can('manage_options')) { |
| 2209 |
return $where; |
| 2210 |
} |
| 2211 |
|
| 2212 |
$level_in = ""; |
| 2213 |
$user_levels = $this->get_setting("levels","user",true); |
| 2214 |
|
| 2215 |
$id = $this->get_postid_by_url(); |
| 2216 |
if (empty($id) && get_option('show_on_front') == 'page') |
| 2217 |
{ |
| 2218 |
$id = get_option('page_on_front'); |
| 2219 |
} |
| 2220 |
if(!empty($id)) { |
| 2221 |
if($this->is_viewable($id)) { |
| 2222 |
return $where; |
| 2223 |
} else { |
| 2224 |
$redirect = get_post_meta($id, self::NSPACE."redirect_location", true); |
| 2225 |
if($redirect == "-2") { |
| 2226 |
$this->do_login = $id; |
| 2227 |
return $where; |
| 2228 |
} |
| 2229 |
} |
| 2230 |
} |
| 2231 |
|
| 2232 |
if(is_array($user_levels)) { |
| 2233 |
foreach($user_levels as $level) { |
| 2234 |
if(!in_array($level, $this->get_setting("membership_levels", "oap", true))) { |
| 2235 |
$level_in .= "'".addslashes($level)."',"; |
| 2236 |
} |
| 2237 |
} |
| 2238 |
} |
| 2239 |
|
| 2240 |
$level_in = rtrim($level_in,","); |
| 2241 |
if(!empty($level_in)) { |
| 2242 |
$where .= " AND ID NOT IN (SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = '_pilotpress_level' AND meta_value IN (" . $level_in . "){$post_extra})"; |
| 2243 |
} |
| 2244 |
return $where; |
| 2245 |
} |
| 2246 |
|
| 2247 |
/* filters nav menu objects */ |
| 2248 |
function get_pages($pages) { |
| 2249 |
global $wpdb; |
| 2250 |
|
| 2251 |
$show_in_nav = $this->get_setting("show_in_nav", "pilotpress", true); |
| 2252 |
|
| 2253 |
$filtered = array(); |
| 2254 |
foreach($pages as $page) { |
| 2255 |
if($this->is_viewable($page->ID) OR in_array($page->ID, $show_in_nav)) { |
| 2256 |
$filtered[] = $page; |
| 2257 |
} |
| 2258 |
} |
| 2259 |
return $filtered; |
| 2260 |
} |
| 2261 |
|
| 2262 |
function get_nav_menu_objects($menus) { |
| 2263 |
$show_in_nav = $this->get_setting("show_in_nav", "pilotpress", true); |
| 2264 |
$new_menus = array(); |
| 2265 |
foreach($menus as $id => $object) { |
| 2266 |
$object_id = $object->object_id; |
| 2267 |
if($this->is_viewable($object_id)) { |
| 2268 |
$new_menus[] = $object; |
| 2269 |
} else { |
| 2270 |
if(in_array($object_id, $show_in_nav)) { |
| 2271 |
$new_menus[] = $object; |
| 2272 |
} |
| 2273 |
} |
| 2274 |
} |
| 2275 |
return $new_menus; |
| 2276 |
} |
| 2277 |
|
| 2278 |
/* really returns filtered menus */ |
| 2279 |
function get_nav_menus($menus) { |
| 2280 |
|
| 2281 |
$show_in_nav = $this->get_setting("show_in_nav", "pilotpress", true); |
| 2282 |
|
| 2283 |
$excludes = array(); |
| 2284 |
$output = $menus; |
| 2285 |
$xml = @simplexml_load_string($menus); |
| 2286 |
|
| 2287 |
if(is_object($xml)) { |
| 2288 |
if(isset($xml->ul->li)) { |
| 2289 |
foreach($xml->ul->li as $obj) { |
| 2290 |
$post_id = url_to_postid((string)$obj->a->attributes()->href); |
| 2291 |
if(!$post_id){ |
| 2292 |
$pages = preg_replace('#^.+/([^/]+)/*$#','$1',(string)$obj->a->attributes()->href); |
| 2293 |
$query = new WP_Query('pagename='.$pages); |
| 2294 |
|
| 2295 |
if( $query->is_page && isset($query->queried_object) ) { |
| 2296 |
$post_id = $query->queried_object->ID; |
| 2297 |
} |
| 2298 |
} |
| 2299 |
|
| 2300 |
if(!$this->is_viewable($post_id) AND !in_array($post_id, $show_in_nav)) { |
| 2301 |
$excludes[] = (string)$obj->attributes()->id; |
| 2302 |
} |
| 2303 |
} |
| 2304 |
} |
| 2305 |
|
| 2306 |
if(count($excludes) > 0) { |
| 2307 |
$output = "<style type='text/css'>"; |
| 2308 |
foreach($excludes as $index => $id) { |
| 2309 |
$output .= '#'.$id." { display: none; }\n"; |
| 2310 |
} |
| 2311 |
$output .= "</style>"; |
| 2312 |
$output .= $menus; |
| 2313 |
} |
| 2314 |
} |
| 2315 |
|
| 2316 |
return $output; |
| 2317 |
} |
| 2318 |
|
| 2319 |
/* i take it back, this is horrible. at the time of writing, WP cannot find what page(s) are being displayed, so this finds it by URL. */ |
| 2320 |
function get_postid_by_url() { |
| 2321 |
|
| 2322 |
global $wp, $wpdb; |
| 2323 |
|
| 2324 |
if(isset($wp->query_vars["page_id"])) { |
| 2325 |
return $wp->query_vars["page_id"]; |
| 2326 |
} |
| 2327 |
|
| 2328 |
if(isset($wp->query_vars["p"])) { |
| 2329 |
return $wp->query_vars["p"]; |
| 2330 |
} else { |
| 2331 |
|
| 2332 |
if(!empty($wp->query_vars["pagename"])) { |
| 2333 |
$subpage = explode("/",$wp->query_vars["pagename"]); |
| 2334 |
if(count($subpage) > 1) { |
| 2335 |
$wp->query_vars["name"] = $subpage[1]; |
| 2336 |
} else { |
| 2337 |
$wp->query_vars["name"] = $wp->query_vars["pagename"]; |
| 2338 |
} |
| 2339 |
} |
| 2340 |
|
| 2341 |
if(!empty($wp->query_vars["name"])) { |
| 2342 |
$id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name = '" . $wpdb->escape($wp->query_vars["name"]) . "'"); |
| 2343 |
if(!empty($id)) { |
| 2344 |
return $id; |
| 2345 |
} else { |
| 2346 |
return false; |
| 2347 |
} |
| 2348 |
} else { |
| 2349 |
return false; |
| 2350 |
} |
| 2351 |
} |
| 2352 |
} |
| 2353 |
|
| 2354 |
/* the most important function for content hiding. this finally decides if something can be seen or not. */ |
| 2355 |
function is_viewable($id) { |
| 2356 |
global $wpdb, $post; |
| 2357 |
|
| 2358 |
$ref = get_query_var("ref"); |
| 2359 |
if($ref) { |
| 2360 |
switch($ref) { |
| 2361 |
case "customer_center": |
| 2362 |
$page_id = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_pilotpress_system_page' AND meta_value = 'customer_center'", ARRAY_A); |
| 2363 |
if($page_id) { |
| 2364 |
self::redirect(get_permalink($page_id)); |
| 2365 |
die; |
| 2366 |
} |
| 2367 |
break; |
| 2368 |
case "affiliate_center": |
| 2369 |
$page_id = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_pilotpress_system_page' AND meta_value = 'affiliate_center'", ARRAY_A); |
| 2370 |
if($page_id) { |
| 2371 |
self::redirect(get_permalink($page_id)); |
| 2372 |
die; |
| 2373 |
} |
| 2374 |
break; |
| 2375 |
default: |
| 2376 |
break; |
| 2377 |
} |
| 2378 |
} |
| 2379 |
|
| 2380 |
|
| 2381 |
if(current_user_can('manage_options')) { |
| 2382 |
return true; |
| 2383 |
} |
| 2384 |
|
| 2385 |
$page_levels = get_post_meta($id, "_pilotpress_level"); |
| 2386 |
$user_levels = $this->get_setting("levels","user",true); |
| 2387 |
|
| 2388 |
if(!is_array($user_levels)) { |
| 2389 |
$user_levels = array($user_levels); |
| 2390 |
} |
| 2391 |
|
| 2392 |
if(in_array($id, $this->system_pages)) { |
| 2393 |
if(!is_user_logged_in()) { |
| 2394 |
return false; |
| 2395 |
} else { |
| 2396 |
return true; |
| 2397 |
} |
| 2398 |
} |
| 2399 |
|
| 2400 |
if(count($page_levels) == 0 OR empty($page_levels)) { |
| 2401 |
return true; |
| 2402 |
} |
| 2403 |
|
| 2404 |
if(count($page_levels) > 0) { |
| 2405 |
if(count($user_levels) == 0) { |
| 2406 |
return false; |
| 2407 |
} else { |
| 2408 |
foreach($user_levels as $level) { |
| 2409 |
if(in_array($level, $page_levels)) { |
| 2410 |
return true; |
| 2411 |
} |
| 2412 |
} |
| 2413 |
return false; |
| 2414 |
} |
| 2415 |
} |
| 2416 |
} |
| 2417 |
|
| 2418 |
/* simple getter */ |
| 2419 |
function get_system_pages() { |
| 2420 |
global $wpdb; |
| 2421 |
$return = array(); |
| 2422 |
$results = $wpdb->get_results("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_pilotpress_system_page'", ARRAY_A); |
| 2423 |
if(is_array($results)) { |
| 2424 |
foreach($results as $q_post) { |
| 2425 |
$return[] = $q_post["post_id"]; |
| 2426 |
} |
| 2427 |
} |
| 2428 |
return $return; |
| 2429 |
} |
| 2430 |
|
| 2431 |
/* renders a system page */ |
| 2432 |
function do_system_page($id) { |
| 2433 |
|
| 2434 |
$type = get_post_meta($id, self::NSPACE."system_page", true); |
| 2435 |
//send over our colors to style the pages nicely |
| 2436 |
$styles["primary_color"] = $this->get_setting("pilotpress_customer_center_primary_color"); |
| 2437 |
$styles["secondary_color"] = $this->get_setting("pilotpress_customer_center_secondary_color"); |
| 2438 |
$styles["header_image"] = $this->get_setting("pilotpress_customer_center_header_image"); |
| 2439 |
|
| 2440 |
if(!is_user_logged_in()) { |
| 2441 |
$return = $this->login_page(array(), 1); |
| 2442 |
return $return; |
| 2443 |
} |
| 2444 |
|
| 2445 |
if($type == "affiliate_center") { |
| 2446 |
$api_result = $this->api_call("get_".$type, array("username" => $_SESSION["user_name"], "program_id" => $_SESSION["program_id"], "site" => site_url() , "styles"=>$styles )); |
| 2447 |
} |
| 2448 |
|
| 2449 |
if($type == "customer_center"){ |
| 2450 |
$api_result = $this->api_call("get_".$type, array("username" => $_SESSION["user_name"], "site" => site_url(), "nonce" => wp_create_nonce(basename(__FILE__)) , "styles"=>$styles , "version"=>self::VERSION )); |
| 2451 |
} |
| 2452 |
|
| 2453 |
if($api_result) { |
| 2454 |
if($api_result["code"] != "0") { |
| 2455 |
return $api_result["code"]; |
| 2456 |
} else { |
| 2457 |
$return = $this->login_page(array(), 2); |
| 2458 |
return $return; |
| 2459 |
} |
| 2460 |
} |
| 2461 |
} |
| 2462 |
|
| 2463 |
/* creates a system page in a post somewhere */ |
| 2464 |
function create_system_page($name) { |
| 2465 |
global $wpdb; |
| 2466 |
$pages = $wpdb->get_results("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_pilotpress_system_page' AND meta_value = '{$name}'", ARRAY_A); |
| 2467 |
if(count($pages) == 0) { |
| 2468 |
$post = array( |
| 2469 |
'post_title' => "{$this->centers[$name]["title"]}", |
| 2470 |
'slug' => "{$this->centers[$name]["slug"]}", |
| 2471 |
'post_status' => 'publish', |
| 2472 |
'post_type' => 'page', |
| 2473 |
'comment_status' => "closed", |
| 2474 |
'visibility' => "public", |
| 2475 |
'ping_status' => "closed", |
| 2476 |
'post_category' => array(1), |
| 2477 |
'post_content' => "{$this->centers[$name]["content"]}"); |
| 2478 |
$post_id = wp_insert_post($post); |
| 2479 |
add_post_meta($post_id, PilotPress::NSPACE."system_page", $name); |
| 2480 |
add_post_meta($post_id, PilotPress::NSPACE."redirect_location", "-2"); |
| 2481 |
$wpdb->query("DELETE FROM $wpdb->posts WHERE post_status = 'trash' AND post_name = '" . $wpdb->escape($name) . "'"); |
| 2482 |
$wpdb->query("UPDATE $wpdb->posts SET post_name = '{$name}' WHERE ID = '" . $wpdb->escape($post_id) . "'"); |
| 2483 |
$this->flush_rewrite_rules(); |
| 2484 |
} |
| 2485 |
} |
| 2486 |
|
| 2487 |
/* banished. */ |
| 2488 |
function delete_system_page($name) { |
| 2489 |
global $wpdb; |
| 2490 |
$pages = $wpdb->get_results("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_pilotpress_system_page' AND meta_value = '" . $wpdb->escape($name) . "'", ARRAY_A); |
| 2491 |
if(!empty($pages)) { |
| 2492 |
foreach($pages as $page) { |
| 2493 |
delete_post_meta($page["post_id"], "_pilotpress_system_page"); |
| 2494 |
wp_delete_post($page["post_id"], true); |
| 2495 |
} |
| 2496 |
} |
| 2497 |
} |
| 2498 |
|
| 2499 |
/** |
| 2500 |
* Ping Logic |
| 2501 |
* |
| 2502 |
* Imports jQuery logic to head which can then be utilized |
| 2503 |
* to send ajax calls to the same file to update the PilotPress |
| 2504 |
* session. |
| 2505 |
* |
| 2506 |
* |
| 2507 |
* @uses add_action() |
| 2508 |
*/ |
| 2509 |
function sessionslap_ping(){ |
| 2510 |
// Register JavaScript |
| 2511 |
wp_enqueue_script('jquery'); |
| 2512 |
|
| 2513 |
require_once( plugin_dir_path( __FILE__ ) . "/ping.php"); |
| 2514 |
|
| 2515 |
// Append dynamic js to both admin and regular users head. |
| 2516 |
add_action( "admin_head", "pilotpress_sessionslap_face" ); |
| 2517 |
add_action( "wp_head", "pilotpress_sessionslap_face" ); |
| 2518 |
|
| 2519 |
} |
| 2520 |
|
| 2521 |
/* renders cute login page */ |
| 2522 |
function login_page ($atts, $message = false) |
| 2523 |
{ |
| 2524 |
// Allows shortcodes to be put in text widgets |
| 2525 |
add_filter('widget_text', 'do_shortcode'); |
| 2526 |
|
| 2527 |
global $wpdb; |
| 2528 |
// This section allows the users to add custom styling by adding custom attributes to the shortcode [login_page] |
| 2529 |
// Form general styling options |
| 2530 |
if ( isset($atts['width']) ) |
| 2531 |
{ |
| 2532 |
$width = $atts['width']; |
| 2533 |
$width = 'max-width: '.$width.'!important;'; |
| 2534 |
} |
| 2535 |
else |
| 2536 |
{ |
| 2537 |
$width = 'max-width: 320px;'; |
| 2538 |
} |
| 2539 |
|
| 2540 |
if ( isset($atts['formalign']) ) |
| 2541 |
{ |
| 2542 |
$formalign = $atts['formalign']; |
| 2543 |
|
| 2544 |
if ( $formalign == 'left' ) |
| 2545 |
{ |
| 2546 |
$formalign = 'margin: 30px 30px 30px 0px; float: left;'; |
| 2547 |
} |
| 2548 |
else if ( $formalign == 'center' ) |
| 2549 |
{ |
| 2550 |
$formalign = 'margin: 30px auto!important;'; |
| 2551 |
} |
| 2552 |
else if ( $formalign == 'right' ) |
| 2553 |
{ |
| 2554 |
$formalign = 'margin: 30px 0px 30px 30px; float: right;'; |
| 2555 |
} |
| 2556 |
else |
| 2557 |
{ |
| 2558 |
$formalign = 'margin: 30px 0px;'; |
| 2559 |
} |
| 2560 |
} |
| 2561 |
else |
| 2562 |
{ |
| 2563 |
$formalign = 'margin: 30px 0px; width: 100%;'; |
| 2564 |
} |
| 2565 |
|
| 2566 |
if ( isset($atts['bgcolor']) ) |
| 2567 |
{ |
| 2568 |
$bgcolor = $atts['bgcolor']; |
| 2569 |
$bgcolor = 'background-color: '.$bgcolor.'!important;'; |
| 2570 |
} |
| 2571 |
else |
| 2572 |
{ |
| 2573 |
$bgcolor = 'background-color: #fff;'; |
| 2574 |
} |
| 2575 |
|
| 2576 |
if ( isset($atts['textcolor']) ) |
| 2577 |
{ |
| 2578 |
$textcolor = $atts['textcolor']; |
| 2579 |
$textcolor = 'color: '.$textcolor.'!important;'; |
| 2580 |
} |
| 2581 |
else |
| 2582 |
{ |
| 2583 |
$textcolor = ''; |
| 2584 |
} |
| 2585 |
|
| 2586 |
// Header Text styling |
| 2587 |
if ( isset($atts['headertextalignment']) ) |
| 2588 |
{ |
| 2589 |
$headertextalignment = $atts['headertextalignment']; |
| 2590 |
$headertextalignment = 'text-align: '.$headertextalignment.'!important;'; |
| 2591 |
} |
| 2592 |
else |
| 2593 |
{ |
| 2594 |
$headertextalignment = ''; |
| 2595 |
} |
| 2596 |
|
| 2597 |
if ( isset($atts['headertextfont']) ) |
| 2598 |
{ |
| 2599 |
$headertextfont = $atts['headertextfont']; |
| 2600 |
$headertextfont = 'font-family: '.$headertextfont.'!important;'; |
| 2601 |
} |
| 2602 |
else |
| 2603 |
{ |
| 2604 |
$headertextfont = ''; |
| 2605 |
} |
| 2606 |
|
| 2607 |
if ( isset($atts['headertextfontsize']) ) |
| 2608 |
{ |
| 2609 |
$headertextfontsize = $atts['headertextfontsize']; |
| 2610 |
$headertextfontsize = 'font-size: '.$headertextfontsize.'!important;'; |
| 2611 |
} |
| 2612 |
else |
| 2613 |
{ |
| 2614 |
$headertextfontsize = 'font-size: 20pt;'; |
| 2615 |
} |
| 2616 |
|
| 2617 |
if ( isset($atts['headertextfontcolor']) ) |
| 2618 |
{ |
| 2619 |
$headertextfontcolor = $atts['headertextfontcolor']; |
| 2620 |
$headertextfontcolor = 'color: '.$headertextfontcolor.'!important;'; |
| 2621 |
} |
| 2622 |
else |
| 2623 |
{ |
| 2624 |
$headertextfontcolor = 'color: #222;'; |
| 2625 |
} |
| 2626 |
|
| 2627 |
// Supporting Text styling |
| 2628 |
if ( isset($atts['supportingtextfont']) ) |
| 2629 |
{ |
| 2630 |
$supportingtextfont = $atts['supportingtextfont']; |
| 2631 |
$supportingtextfont = 'font-family: '.$supportingtextfont.'!important;'; |
| 2632 |
} |
| 2633 |
else |
| 2634 |
{ |
| 2635 |
$supportingtextfont = ''; |
| 2636 |
} |
| 2637 |
|
| 2638 |
if ( isset($atts['supportingtextfontsize']) ) |
| 2639 |
{ |
| 2640 |
$supportingtextfontsize = $atts['supportingtextfontsize']; |
| 2641 |
$supportingtextfontsize = 'font-size: '.$supportingtextfontsize.'!important;'; |
| 2642 |
} |
| 2643 |
else |
| 2644 |
{ |
| 2645 |
$supportingtextfontsize = 'font-size: 12pt;'; |
| 2646 |
} |
| 2647 |
|
| 2648 |
if ( isset($atts['supportingtextfontcolor']) ) |
| 2649 |
{ |
| 2650 |
$supportingtextfontcolor = $atts['supportingtextfontcolor']; |
| 2651 |
$supportingtextfontcolor = 'color: '.$supportingtextfontcolor.'!important;'; |
| 2652 |
} |
| 2653 |
else |
| 2654 |
{ |
| 2655 |
$supportingtextfontcolor = 'color: #555;'; |
| 2656 |
} |
| 2657 |
|
| 2658 |
// Form Input styling |
| 2659 |
if ( isset($atts['inputcolor']) ) |
| 2660 |
{ |
| 2661 |
$inputcolor = $atts['inputcolor']; |
| 2662 |
$inputcolor = 'background-color: '.$inputcolor.'!important;'; |
| 2663 |
} |
| 2664 |
else |
| 2665 |
{ |
| 2666 |
$inputcolor = ''; |
| 2667 |
} |
| 2668 |
|
| 2669 |
if ( isset($atts['inputtextcolor']) ) |
| 2670 |
{ |
| 2671 |
$inputtextcolor = $atts['inputtextcolor']; |
| 2672 |
$inputtextcolor = 'color: '.$inputtextcolor.'!important;'; |
| 2673 |
} |
| 2674 |
else |
| 2675 |
{ |
| 2676 |
$inputtextcolor = ''; |
| 2677 |
} |
| 2678 |
|
| 2679 |
if ( isset($atts['inputbordercolor']) ) |
| 2680 |
{ |
| 2681 |
$inputbordercolor = $atts['inputbordercolor']; |
| 2682 |
$inputbordercolor = 'border: 1px solid '.$inputbordercolor.'!important;'; |
| 2683 |
} |
| 2684 |
else |
| 2685 |
{ |
| 2686 |
$inputbordercolor = ''; |
| 2687 |
} |
| 2688 |
|
| 2689 |
if ( isset($atts['inputfieldsize']) ) |
| 2690 |
{ |
| 2691 |
$inputfieldsize = $atts['inputfieldsize']; |
| 2692 |
if ( $inputfieldsize == 'large' ) |
| 2693 |
{ |
| 2694 |
$inputfieldsize = 'padding: 16px!important; font-size: 15pt;'; |
| 2695 |
} |
| 2696 |
if ( $inputfieldsize == 'medium' ) |
| 2697 |
{ |
| 2698 |
$inputfieldsize = 'padding: 9px!important; font-size: 12pt;'; |
| 2699 |
} |
| 2700 |
if ( $inputfieldsize == 'small' ) |
| 2701 |
{ |
| 2702 |
$inputfieldsize = 'padding: 6px!important; font-size: 10pt;'; |
| 2703 |
} |
| 2704 |
} |
| 2705 |
else |
| 2706 |
{ |
| 2707 |
$inputfieldsize = 'padding: 6px!important; font-size: 10pt;'; |
| 2708 |
} |
| 2709 |
|
| 2710 |
// Form Button styling |
| 2711 |
if ( isset($atts['buttonbgcolor']) ) |
| 2712 |
{ |
| 2713 |
$buttonbgcolor = $atts['buttonbgcolor']; |
| 2714 |
$buttonbgcolor = 'background-color: '.$buttonbgcolor.'!important; background-image: none!important;'; |
| 2715 |
} |
| 2716 |
else |
| 2717 |
{ |
| 2718 |
$buttonbgcolor = ''; |
| 2719 |
} |
| 2720 |
|
| 2721 |
if ( isset($atts['buttontextcolor']) ) |
| 2722 |
{ |
| 2723 |
$buttontextcolor = $atts['buttontextcolor']; |
| 2724 |
$buttontextcolor = 'color: '.$buttontextcolor.'!important;'; |
| 2725 |
} |
| 2726 |
else |
| 2727 |
{ |
| 2728 |
$buttontextcolor = ''; |
| 2729 |
} |
| 2730 |
|
| 2731 |
if ( isset($atts['buttonbordercolor']) ) |
| 2732 |
{ |
| 2733 |
$buttonbordercolor = $atts['buttonbordercolor']; |
| 2734 |
$buttonbordercolor = 'border: 1px solid '.$buttonbordercolor.'!important;'; |
| 2735 |
} |
| 2736 |
else |
| 2737 |
{ |
| 2738 |
$buttonbordercolor = ''; |
| 2739 |
} |
| 2740 |
|
| 2741 |
if ( isset($atts['buttonfont']) ) |
| 2742 |
{ |
| 2743 |
$buttonfont = $atts['buttonfont']; |
| 2744 |
$buttonfont = 'font-family: '.$buttonfont.'!important;'; |
| 2745 |
} |
| 2746 |
else |
| 2747 |
{ |
| 2748 |
$buttonfont = ''; |
| 2749 |
} |
| 2750 |
|
| 2751 |
if ( isset($atts['buttonfontsize']) ) |
| 2752 |
{ |
| 2753 |
$buttonfontsize = $atts['buttonfontsize']; |
| 2754 |
$buttonfontsize = 'font-size: '.$buttonfontsize.'!important;'; |
| 2755 |
} |
| 2756 |
else |
| 2757 |
{ |
| 2758 |
$buttonfontsize = 'font-size: 11pt;'; |
| 2759 |
} |
| 2760 |
|
| 2761 |
if ( isset($atts['buttonhovertextcolor']) ) |
| 2762 |
{ |
| 2763 |
$buttonhovertextcolor = $atts['buttonhovertextcolor']; |
| 2764 |
$buttonhovertextcolor = 'color: '.$buttonhovertextcolor.'!important;'; |
| 2765 |
} |
| 2766 |
else |
| 2767 |
{ |
| 2768 |
$buttonhovertextcolor = ''; |
| 2769 |
} |
| 2770 |
|
| 2771 |
if ( isset($atts['buttonhoverbgcolor']) ) |
| 2772 |
{ |
| 2773 |
$buttonhoverbgcolor = $atts['buttonhoverbgcolor']; |
| 2774 |
$buttonhoverbgcolor = 'background-color: '.$buttonhoverbgcolor.'!important;'; |
| 2775 |
} |
| 2776 |
else |
| 2777 |
{ |
| 2778 |
$buttonhoverbgcolor = ''; |
| 2779 |
} |
| 2780 |
|
| 2781 |
if ( isset($atts['buttonhoverbordercolor']) ) |
| 2782 |
{ |
| 2783 |
$buttonhoverbordercolor = $atts['buttonhoverbordercolor']; |
| 2784 |
$buttonhoverbordercolor = 'border: 1px solid '.$buttonhoverbordercolor.'!important;'; |
| 2785 |
} |
| 2786 |
else |
| 2787 |
{ |
| 2788 |
$buttonhoverbordercolor = ''; |
| 2789 |
} |
| 2790 |
|
| 2791 |
if ( isset($atts['buttonsize']) ) |
| 2792 |
{ |
| 2793 |
$buttonsize = $atts['buttonsize']; |
| 2794 |
switch ($buttonsize) |
| 2795 |
{ |
| 2796 |
case 'extralarge': |
| 2797 |
$buttonsize = 'padding: 25px!important; font-size: 23pt;'; |
| 2798 |
break; |
| 2799 |
|
| 2800 |
case 'large': |
| 2801 |
$buttonsize = 'padding: 18px!important; font-size: 18pt;'; |
| 2802 |
break; |
| 2803 |
|
| 2804 |
case 'medium': |
| 2805 |
$buttonsize = 'padding: 10px!important; font-size: 13pt;'; |
| 2806 |
break; |
| 2807 |
|
| 2808 |
case 'small': |
| 2809 |
$buttonsize = 'padding: 6px!important; font-size: 10pt;'; |
| 2810 |
break; |
| 2811 |
} |
| 2812 |
} |
| 2813 |
else |
| 2814 |
{ |
| 2815 |
$buttonsize = 'padding: 10px!important; font-size: 13pt;'; |
| 2816 |
} |
| 2817 |
|
| 2818 |
// Form Style - Responsible for the full width or side by side form style |
| 2819 |
$default = '#pp-loginform .login-username LABEL |
| 2820 |
{ |
| 2821 |
max-width: 100%!important; |
| 2822 |
width: 100%!important; |
| 2823 |
} |
| 2824 |
#pp-loginform .login-username INPUT |
| 2825 |
{ |
| 2826 |
max-width: 100%!important; |
| 2827 |
width: 100%!important; |
| 2828 |
} |
| 2829 |
#pp-loginform .login-password LABEL |
| 2830 |
{ |
| 2831 |
max-width: 100%!important; |
| 2832 |
width: 100%!important; |
| 2833 |
} |
| 2834 |
#pp-loginform .login-password INPUT |
| 2835 |
{ |
| 2836 |
max-width: 100%!important; |
| 2837 |
width: 100%!important; |
| 2838 |
}'; |
| 2839 |
|
| 2840 |
if ( isset($atts['style']) ) |
| 2841 |
{ |
| 2842 |
$style = $atts['style']; |
| 2843 |
|
| 2844 |
if ( $style == 'default' ) |
| 2845 |
{ |
| 2846 |
$style = $default; |
| 2847 |
} |
| 2848 |
else if ( $style == 'fullwidth' ) |
| 2849 |
{ |
| 2850 |
$style = $default . '.op-login-form { max-width: 100%!important; }'; |
| 2851 |
} |
| 2852 |
} |
| 2853 |
else |
| 2854 |
{ |
| 2855 |
$style = $default; |
| 2856 |
} |
| 2857 |
|
| 2858 |
|
| 2859 |
// TEXT - Options to change the form text |
| 2860 |
if ( isset($atts['headertext']) ) |
| 2861 |
{ |
| 2862 |
$headertext = $atts['headertext']; |
| 2863 |
} |
| 2864 |
else |
| 2865 |
{ |
| 2866 |
$headertext = ''; |
| 2867 |
} |
| 2868 |
|
| 2869 |
if ( isset($atts['supportingtext']) ) |
| 2870 |
{ |
| 2871 |
$supportingtext = $atts['supportingtext']; |
| 2872 |
} |
| 2873 |
else |
| 2874 |
{ |
| 2875 |
$supportingtext = ''; |
| 2876 |
} |
| 2877 |
|
| 2878 |
if ( isset($atts['usernametext']) ) |
| 2879 |
{ |
| 2880 |
$usernametext = $atts['usernametext']; |
| 2881 |
$usernametext = __($usernametext); |
| 2882 |
} |
| 2883 |
else |
| 2884 |
{ |
| 2885 |
$usernametext = __('Username'); |
| 2886 |
} |
| 2887 |
|
| 2888 |
if ( isset($atts['passwordtext']) ) |
| 2889 |
{ |
| 2890 |
$passwordtext = $atts['passwordtext']; |
| 2891 |
$passwordtext = __($passwordtext); |
| 2892 |
} |
| 2893 |
else |
| 2894 |
{ |
| 2895 |
$passwordtext = __('Password'); |
| 2896 |
} |
| 2897 |
|
| 2898 |
if ( isset($atts['remembertext']) ) |
| 2899 |
{ |
| 2900 |
$remembertext = $atts['remembertext']; |
| 2901 |
$remembertext = __($remembertext); |
| 2902 |
} |
| 2903 |
else |
| 2904 |
{ |
| 2905 |
$remembertext = __('Remember me'); |
| 2906 |
} |
| 2907 |
|
| 2908 |
if ( isset($atts['buttontext']) ) |
| 2909 |
{ |
| 2910 |
$buttontext = $atts['buttontext']; |
| 2911 |
$buttontext = __($buttontext); |
| 2912 |
} |
| 2913 |
else |
| 2914 |
{ |
| 2915 |
$buttontext = __('Log In'); |
| 2916 |
} |
| 2917 |
|
| 2918 |
|
| 2919 |
// New style for the [login_page] forms with variables for user customization |
| 2920 |
$output = "<style type='text/css'> |
| 2921 |
.op-login-form-".$this->incrementalnumber." |
| 2922 |
{ |
| 2923 |
".$formalign." |
| 2924 |
padding: 30px; |
| 2925 |
box-sizing: border-box; |
| 2926 |
-webkit-box-sizing: border-box; |
| 2927 |
-moz-box-sizing: border-box; |
| 2928 |
-moz-box-shadow: 0px 0px 2px 1px rgba(51,51,51,0.27); |
| 2929 |
-webkit-box-shadow: 0px 0px 2px 1px rgba(51,51,51,0.27); |
| 2930 |
box-shadow: 0px 0px 2px 1px rgba(51, 51, 51, 0.27); |
| 2931 |
-ms-filter: 'progid:DXImageTransform.Microsoft.Glow(Color=#ff333333,Strength=3)'; |
| 2932 |
filter: progid:DXImageTransform.Microsoft.Glow(Color=#ff333333,Strength=3); |
| 2933 |
".$bgcolor." |
| 2934 |
".$width." |
| 2935 |
} |
| 2936 |
.op-login-form-".$this->incrementalnumber." .op-header-text-container |
| 2937 |
{ |
| 2938 |
margin-bottom: 25px; |
| 2939 |
width: 100%; |
| 2940 |
".$headertextalignment." |
| 2941 |
} |
| 2942 |
.op-login-form-".$this->incrementalnumber." .op-header-text |
| 2943 |
{ |
| 2944 |
line-height: 1.2!important; |
| 2945 |
margin-bottom: 4px;".$headertextfont.$headertextfontsize.$headertextfontcolor." |
| 2946 |
} |
| 2947 |
.op-login-form-".$this->incrementalnumber." .op-supporting-text |
| 2948 |
{ |
| 2949 |
line-height: 1.2!important;".$supportingtextfont.$supportingtextfontsize.$supportingtextfontcolor." |
| 2950 |
} |
| 2951 |
.op-login-form-".$this->incrementalnumber." #pp-loginform P |
| 2952 |
{ |
| 2953 |
width: 100%; |
| 2954 |
display: table; |
| 2955 |
margin: 0px 0px 4px; |
| 2956 |
padding: 0px; |
| 2957 |
} |
| 2958 |
.op-login-form-".$this->incrementalnumber." LABEL, |
| 2959 |
.op-login-form-".$this->incrementalnumber." INPUT |
| 2960 |
{ |
| 2961 |
display: table-cell; |
| 2962 |
box-sizing: border-box; |
| 2963 |
-webkit-box-sizing: border-box; |
| 2964 |
-moz-box-sizing: border-box; |
| 2965 |
line-height: 1.3; |
| 2966 |
} |
| 2967 |
.op-login-form-".$this->incrementalnumber." .login-username |
| 2968 |
{ |
| 2969 |
position: relative; |
| 2970 |
} |
| 2971 |
.op-login-form-".$this->incrementalnumber." .login-username LABEL |
| 2972 |
{ |
| 2973 |
width: 100%; |
| 2974 |
max-width: 25%; |
| 2975 |
min-width: 90px; |
| 2976 |
padding-right: 3%; |
| 2977 |
float: left;".$textcolor." |
| 2978 |
} |
| 2979 |
.op-login-form-".$this->incrementalnumber." .login-username INPUT |
| 2980 |
{ |
| 2981 |
width: 100%; |
| 2982 |
max-width: 72%; |
| 2983 |
float: right; |
| 2984 |
border-radius: 3px;".$inputcolor.$inputtextcolor.$inputbordercolor.$inputfieldsize." |
| 2985 |
} |
| 2986 |
.op-login-form-".$this->incrementalnumber." .login-password LABEL |
| 2987 |
{ |
| 2988 |
width: 100%; |
| 2989 |
max-width: 25%; |
| 2990 |
min-width: 90px; |
| 2991 |
padding-right: 3%; |
| 2992 |
float: left;".$textcolor." |
| 2993 |
} |
| 2994 |
.op-login-form-".$this->incrementalnumber." .login-password INPUT |
| 2995 |
{ |
| 2996 |
width: 100%; |
| 2997 |
max-width: 72%; |
| 2998 |
float: right; |
| 2999 |
border-radius: 3px;".$inputcolor.$inputtextcolor.$inputbordercolor.$inputfieldsize." |
| 3000 |
} |
| 3001 |
.op-login-form-".$this->incrementalnumber." .login-remember |
| 3002 |
{ |
| 3003 |
text-align: right; |
| 3004 |
font-style: italic; |
| 3005 |
cursor: pointer;".$textcolor." |
| 3006 |
} |
| 3007 |
.op-login-form-".$this->incrementalnumber." .login-remember INPUT |
| 3008 |
{ |
| 3009 |
float: right; |
| 3010 |
margin-left: 10px; |
| 3011 |
margin-top: 5px; |
| 3012 |
cursor: pointer; |
| 3013 |
} |
| 3014 |
.op-login-form-".$this->incrementalnumber." .login-remember LABEL |
| 3015 |
{ |
| 3016 |
cursor: pointer;".$textcolor." |
| 3017 |
} |
| 3018 |
.op-login-form-".$this->incrementalnumber." #wp-submit |
| 3019 |
{ |
| 3020 |
width: 100%; |
| 3021 |
padding: 10px; |
| 3022 |
margin-top: 15px; |
| 3023 |
margin-bottom: 0px; |
| 3024 |
white-space: pre-wrap; |
| 3025 |
border-radius: 3px;".$buttonbgcolor.$buttontextcolor.$buttonbordercolor.$buttonfont.$buttonfontsize.$buttonsize." |
| 3026 |
} |
| 3027 |
.op-login-form-".$this->incrementalnumber." #wp-submit:hover |
| 3028 |
{ |
| 3029 |
transition: background-color 1s ease, color 1s ease; |
| 3030 |
-moz-transition: background-color 1s ease, color 1s ease; |
| 3031 |
-webkit-transition: background-color 1s ease, color 1s ease;".$buttonhovertextcolor.$buttonhoverbgcolor.$buttonhoverbordercolor." |
| 3032 |
} |
| 3033 |
.op-login-form-".$this->incrementalnumber." .login_box |
| 3034 |
{ |
| 3035 |
margin-top: 6px; |
| 3036 |
padding: 5px; |
| 3037 |
border: 1px solid #E6D855; |
| 3038 |
background-color: #FFFFE0; |
| 3039 |
box-sizing: border-box; |
| 3040 |
-webkit-box-sizing: border-box; |
| 3041 |
-moz-box-sizing: border-box; |
| 3042 |
} |
| 3043 |
@media screen and (max-width: 480px) |
| 3044 |
{ |
| 3045 |
.op-login-form-".$this->incrementalnumber." .login-username LABEL |
| 3046 |
{ |
| 3047 |
max-width: 100%!important; |
| 3048 |
} |
| 3049 |
.op-login-form-".$this->incrementalnumber." .login-username INPUT |
| 3050 |
{ |
| 3051 |
max-width: 100%!important; |
| 3052 |
} |
| 3053 |
.op-login-form-".$this->incrementalnumber." .login-password LABEL |
| 3054 |
{ |
| 3055 |
max-width: 100%!important; |
| 3056 |
} |
| 3057 |
.op-login-form-".$this->incrementalnumber." .login-password INPUT |
| 3058 |
{ |
| 3059 |
max-width: 100%!important; |
| 3060 |
} |
| 3061 |
} |
| 3062 |
".$style." |
| 3063 |
</style>"; |
| 3064 |
|
| 3065 |
// Start Form output |
| 3066 |
$output .= '<div class="op-login-form-'.$this->incrementalnumber.'">'; |
| 3067 |
|
| 3068 |
// Setting header text |
| 3069 |
if ( isset($atts['headertext']) || isset($atts['supporting']) ) |
| 3070 |
{ |
| 3071 |
$output .= '<div class="op-header-text-container"><div class="op-header-text">'.$headertext.'</div><div class="op-supporting-text">'.$supportingtext.'</div></div>'; |
| 3072 |
} |
| 3073 |
|
| 3074 |
if(!empty($message)) |
| 3075 |
{ |
| 3076 |
switch($message) |
| 3077 |
{ |
| 3078 |
case "1": |
| 3079 |
$output_message = "Must be logged in to see this page."; |
| 3080 |
break; |
| 3081 |
case "2": |
| 3082 |
$output_message = "You do not have sufficient access to view this page."; |
| 3083 |
break; |
| 3084 |
case "3": |
| 3085 |
$output_message = "Invalid Username or Password."; |
| 3086 |
break; |
| 3087 |
default: |
| 3088 |
$output_message = $message; |
| 3089 |
break; |
| 3090 |
} |
| 3091 |
$output .= "<p class='login_box' id='login_message_normal'>{$output_message}</p>"; |
| 3092 |
} |
| 3093 |
|
| 3094 |
if ( isset($atts['redirect']) ) |
| 3095 |
{ |
| 3096 |
$redirect = $atts['redirect']; |
| 3097 |
} |
| 3098 |
else |
| 3099 |
{ |
| 3100 |
if(isset($_SESSION["redirect_to"]) && !empty($_SESSION["redirect_to"])) |
| 3101 |
{ |
| 3102 |
$redirect = get_permalink($_SESSION["redirect_to"]); |
| 3103 |
} |
| 3104 |
else |
| 3105 |
{ |
| 3106 |
$redirect = site_url($_SERVER['REQUEST_URI']); |
| 3107 |
} |
| 3108 |
} |
| 3109 |
|
| 3110 |
$args = array( |
| 3111 |
'echo' => false, |
| 3112 |
'redirect' => $redirect, |
| 3113 |
'form_id' => 'pp-loginform', |
| 3114 |
'label_username' => $usernametext, |
| 3115 |
'label_password' => $passwordtext, |
| 3116 |
'label_remember' => $remembertext, |
| 3117 |
'label_log_in' => $buttontext, |
| 3118 |
'id_username' => 'user_login', |
| 3119 |
'id_password' => 'user_pass', |
| 3120 |
'id_remember' => 'rememberme', |
| 3121 |
'id_submit' => 'wp-submit', |
| 3122 |
'remember' => true, |
| 3123 |
'value_username' => NULL, |
| 3124 |
'value_remember' => true); |
| 3125 |
$output .= wp_login_form($args); |
| 3126 |
|
| 3127 |
// Adds functionality for Lost Passwords |
| 3128 |
if ( isset($atts['forgotpw']) && $atts['forgotpw'] == 'true' ) |
| 3129 |
{ |
| 3130 |
$output .= '<div class="pp-lf-forgot-username" style="text-align: right;"><a id="pp-lf-forgotpw" href="javascript://">Forgotten password?</a></div>'; |
| 3131 |
|
| 3132 |
$output .= '<script> |
| 3133 |
jQuery(".op-login-form-'.$this->incrementalnumber.' #pp-lf-forgotpw").click(function() |
| 3134 |
{ |
| 3135 |
jQuery(".op-login-form-'.$this->incrementalnumber.' .login-password, .op-login-form-'.$this->incrementalnumber.' .login-remember").hide(300); |
| 3136 |
jQuery(".op-login-form-'.$this->incrementalnumber.' #pp-loginform").attr( "action", "'.site_url().'/wp-login.php?action=lostpassword"); |
| 3137 |
jQuery(".op-login-form-'.$this->incrementalnumber.' .login-username label").text("Enter your Username or Email"); |
| 3138 |
jQuery(".op-login-form-'.$this->incrementalnumber.' .login-username input").attr("name", "user_login"); |
| 3139 |
jQuery(".op-login-form-'.$this->incrementalnumber.' #wp-submit").attr("value", "Send me my Password!"); |
| 3140 |
}); |
| 3141 |
</script>'; |
| 3142 |
} |
| 3143 |
|
| 3144 |
$output .= '</div>'; |
| 3145 |
|
| 3146 |
$this->incrementalnumber++; |
| 3147 |
|
| 3148 |
return $output; |
| 3149 |
|
| 3150 |
} |
| 3151 |
|
| 3152 |
public function include_form_admin_options () |
| 3153 |
{ |
| 3154 |
include_once(plugin_dir_path(__FILE__) . "/login-button.php"); |
| 3155 |
} |
| 3156 |
|
| 3157 |
public function register_login_button ( $buttons ) |
| 3158 |
{ |
| 3159 |
array_push( $buttons, "|", "addloginform" ); |
| 3160 |
return $buttons; |
| 3161 |
} |
| 3162 |
|
| 3163 |
public function add_login_button ( $plugin_array ) |
| 3164 |
{ |
| 3165 |
$plugin_array['addloginform'] = plugins_url( '/js/login-button.js' , __FILE__ ); |
| 3166 |
return $plugin_array; |
| 3167 |
} |
| 3168 |
|
| 3169 |
public function pp_login_button () |
| 3170 |
{ |
| 3171 |
if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') ) |
| 3172 |
{ |
| 3173 |
return; |
| 3174 |
} |
| 3175 |
if ( get_user_option('rich_editing') == 'true' ) |
| 3176 |
{ |
| 3177 |
add_filter( 'mce_external_plugins', array(&$this, 'add_login_button') ); |
| 3178 |
add_filter( 'mce_buttons_3', array(&$this, 'register_login_button') ); |
| 3179 |
} |
| 3180 |
} |
| 3181 |
|
| 3182 |
|
| 3183 |
/* the first process... enable the plugin create some values and cleanup "older" PilotPress metadata. could probably do with a redo. */ |
| 3184 |
public function do_enable() { |
| 3185 |
|
| 3186 |
global $wpdb; |
| 3187 |
|
| 3188 |
$data = array(); |
| 3189 |
$data["site"] = site_url(); |
| 3190 |
$data["version"] = self::VERSION; |
| 3191 |
$data["url"] = $this->uri."/".basename(__FILE__); |
| 3192 |
$api_result = $this->api_call("enable_pilotpress", $data); |
| 3193 |
|
| 3194 |
$um = array(); |
| 3195 |
$user = get_userdatabylogin("pilotpress-user"); |
| 3196 |
if(isset($user->ID)) { |
| 3197 |
wp_delete_user($user->ID); |
| 3198 |
} |
| 3199 |
|
| 3200 |
$meta = $wpdb->get_results("SELECT meta_id, post_id, meta_key, meta_value FROM $wpdb->postmeta WHERE meta_key LIKE '".PilotPress::NSPACE."%'"); |
| 3201 |
foreach($meta as $result) { |
| 3202 |
|
| 3203 |
if($result->meta_key == "_pilotpress_system_page" && $result->meta_value == "1") { |
| 3204 |
delete_post_meta($result->post_id, $result->meta_key); |
| 3205 |
} |
| 3206 |
|
| 3207 |
if($result->meta_key == "_pilotpress_affiliate_center") { |
| 3208 |
$ac_exists = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_pilotpress_system_page' AND meta_value = 'affiliate_center'"); |
| 3209 |
|
| 3210 |
if(empty($ac_exists)) { |
| 3211 |
delete_post_meta($result->post_id, $result->meta_key); |
| 3212 |
add_post_meta($post_id, PilotPress::NSPACE."system_page", "affiliate_center"); |
| 3213 |
wp_update_post(array("ID" => $post_id, "post_content" => "This content will be replaced by the Partner Center.")); |
| 3214 |
} |
| 3215 |
} |
| 3216 |
|
| 3217 |
if($result->meta_key == "_pilotpress_customer_center") { |
| 3218 |
$cc_exists = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_pilotpress_system_page' AND meta_value = 'customer_center'"); |
| 3219 |
|
| 3220 |
if(empty($cc_exists)) { |
| 3221 |
delete_post_meta($result->post_id, $result->meta_key); |
| 3222 |
add_post_meta($post_id, PilotPress::NSPACE."system_page", "customer_center"); |
| 3223 |
wp_update_post(array("ID" => $post_id, "post_content" => "This content will be replaced by the Customer Center.")); |
| 3224 |
} |
| 3225 |
} |
| 3226 |
|
| 3227 |
if($result->meta_key == "_pilotpress_user_level") { |
| 3228 |
if($result->meta_value == "All") { |
| 3229 |
delete_post_meta($result->post_id, $result->meta_key); |
| 3230 |
} else { |
| 3231 |
$um[$result->meta_value][] = $result->post_id; |
| 3232 |
} |
| 3233 |
} |
| 3234 |
} |
| 3235 |
|
| 3236 |
if(isset($api_result["upgrade"])) { |
| 3237 |
$levels = $this->get_setting("membership_levels", "oap"); |
| 3238 |
$keys = array_flip($levels); |
| 3239 |
if(count($um) > 0) { |
| 3240 |
foreach($keys as $level => $pos) { |
| 3241 |
$rec = array_slice($levels, $pos); |
| 3242 |
if(isset($um[$level])) { |
| 3243 |
foreach($um[$level] as $idx => $post_id) { |
| 3244 |
foreach($rec as $value) { |
| 3245 |
add_post_meta($post_id, PilotPress::NSPACE."level", $value); |
| 3246 |
} |
| 3247 |
delete_post_meta($post_id, PilotPress::NSPACE."user_level"); |
| 3248 |
} |
| 3249 |
} |
| 3250 |
} |
| 3251 |
} |
| 3252 |
} |
| 3253 |
} |
| 3254 |
|
| 3255 |
/* let us know */ |
| 3256 |
public function do_disable() { |
| 3257 |
$data = array(); |
| 3258 |
$data["site"] = site_url(); |
| 3259 |
$data["version"] = self::VERSION; |
| 3260 |
$data["url"] = $this->uri."/".basename(__FILE__); |
| 3261 |
$return = $this->api_call("disable_pilotpress", $data); |
| 3262 |
} |
| 3263 |
|
| 3264 |
public static function redirect($url) { |
| 3265 |
// Workaround for trac bug #21602 |
| 3266 |
$current_url = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]; |
| 3267 |
|
| 3268 |
if(substr($current_url, -1) == "/") { |
| 3269 |
$current_url = substr($current_url, 0, -1); |
| 3270 |
} |
| 3271 |
$compare_url = str_replace("https://", "", $url); |
| 3272 |
$compare_url = str_replace("http://", "", $compare_url); |
| 3273 |
|
| 3274 |
if($current_url != $compare_url) { |
| 3275 |
return wp_redirect($url); |
| 3276 |
} |
| 3277 |
} |
| 3278 |
|
| 3279 |
/* used by external plugins: get items available to this account */ |
| 3280 |
static function get_oap_items() { |
| 3281 |
$options = get_option("pilotpress-settings"); |
| 3282 |
if(!empty($options)) { |
| 3283 |
if(isset($options["app_id"]) && isset($options["api_key"])) { |
| 3284 |
$return = array(); |
| 3285 |
$return["files"] = PilotPress::api_call_static("get_files_list", "", $options["app_id"], $options["api_key"], $options["disablesslverify"]); |
| 3286 |
$return["videos"] = PilotPress::api_call_static("get_video_list", "", $options["app_id"], $options["api_key"], $options["disablesslverify"]); |
| 3287 |
return $return; |
| 3288 |
} |
| 3289 |
} |
| 3290 |
return false; |
| 3291 |
} |
| 3292 |
|
| 3293 |
/* grab some video code! also for external plugins */ |
| 3294 |
static function get_oap_video($video_id) { |
| 3295 |
$options = get_option("pilotpress-settings"); |
| 3296 |
if(!empty($options)) { |
| 3297 |
if(isset($options["app_id"]) && isset($options["api_key"])) { |
| 3298 |
$return= PilotPress::api_call_static("get_video", |
| 3299 |
array( |
| 3300 |
"video_id" => $video_id, |
| 3301 |
"width" => '480', |
| 3302 |
"height" => "320", |
| 3303 |
"player" => 1, |
| 3304 |
"autoplay" => 0, |
| 3305 |
"viral" => 0 |
| 3306 |
), |
| 3307 |
$options["app_id"], |
| 3308 |
$options["api_key"], |
| 3309 |
$options["disablesslverify"]); |
| 3310 |
return $return; |
| 3311 |
} |
| 3312 |
} |
| 3313 |
return false; |
| 3314 |
} |
| 3315 |
|
| 3316 |
} |
| 3317 |
|
| 3318 |
|
| 3319 |
//Since we ping this file independent of the WordPress bootstrap lets make sure the class exists... |
| 3320 |
if (class_exists("WP_Widget")) |
| 3321 |
{ |
| 3322 |
// Creating the widget |
| 3323 |
class Pilotpress_Widget extends WP_Widget { |
| 3324 |
|
| 3325 |
//Registers the widget with the WordPress Widget API. |
| 3326 |
public static function register() { |
| 3327 |
register_widget( __CLASS__ ); |
| 3328 |
} |
| 3329 |
|
| 3330 |
public function __construct() { |
| 3331 |
|
| 3332 |
parent::__construct( |
| 3333 |
// Base ID of your widget |
| 3334 |
'pilotpress_widget', |
| 3335 |
|
| 3336 |
// Widget name will appear in UI |
| 3337 |
__('PilotPress Text', 'pilotpress_widget_domain'), |
| 3338 |
|
| 3339 |
// Widget description |
| 3340 |
array( |
| 3341 |
'description' => __( 'An enhanced text area widget that helps you display your ONTRAPORT merge fields', 'pilotpress_widget_domain' ) |
| 3342 |
) |
| 3343 |
); |
| 3344 |
} |
| 3345 |
|
| 3346 |
// Creating widget front-end |
| 3347 |
public function widget( $args, $instance ) { |
| 3348 |
global $pilotpress; |
| 3349 |
$title = apply_filters( 'widget_title', $instance['title'] ); |
| 3350 |
|
| 3351 |
$textarea = $instance["textarea"]; |
| 3352 |
// before and after widget arguments are defined by themes |
| 3353 |
echo $args['before_widget']; |
| 3354 |
if ( ! empty( $title ) ) |
| 3355 |
{ |
| 3356 |
echo $args['before_title'] . $title . $args['after_title']; |
| 3357 |
} |
| 3358 |
//Lets check and process merge fields if we need too! |
| 3359 |
if (has_shortcode( $textarea , "pilotpress_field") || has_shortcode( $textarea ,"field") ) |
| 3360 |
{ |
| 3361 |
$pilotpress->get_merge_field_settings($textarea); |
| 3362 |
} |
| 3363 |
//Apply the default filter in case they have somehting to make PHP work... |
| 3364 |
echo apply_filters( 'widget_text' , do_shortcode($textarea) ); |
| 3365 |
|
| 3366 |
echo $args['after_widget']; |
| 3367 |
} |
| 3368 |
|
| 3369 |
// Widget Backend |
| 3370 |
public function form( $instance ) { |
| 3371 |
global $pilotpress; |
| 3372 |
|
| 3373 |
//Handle merge codes |
| 3374 |
$mergeFieldDropDown = "<p>"; |
| 3375 |
$mergeFieldDropDown .= "<label for='" . $this->get_field_id( "merge-codes" ) ."'>" . __("Merge Fields:", "pilotpress_widget_domain") . "</label>"; |
| 3376 |
$mergeFieldDropDown .= "<select id='" . $this->get_field_id( "merge-codes" ) . "' class='op-merge-codes__select' name='" . $this->get_field_id( "merge-codes" ) . "'>"; |
| 3377 |
$mergeFieldDropDown .= "</p>"; |
| 3378 |
|
| 3379 |
foreach($pilotpress->get_setting("default_fields", "oap", true) as $group => $fields) { |
| 3380 |
|
| 3381 |
$mergeFieldDropDown .= "<option value=''> " . $group . "</option>"; |
| 3382 |
foreach ($fields as $key => $field) |
| 3383 |
{ |
| 3384 |
|
| 3385 |
$mergeFieldDropDown .= "<option value='[pilotpress_field name=\"{$key}\"]'> " . $key . "</option>"; |
| 3386 |
} |
| 3387 |
} |
| 3388 |
|
| 3389 |
$mergeFieldDropDown .= "</select>"; |
| 3390 |
|
| 3391 |
if ( isset( $instance[ 'title' ] ) ) { |
| 3392 |
$title = $instance[ 'title' ]; |
| 3393 |
} |
| 3394 |
else { |
| 3395 |
$title = __( '', 'pilotpress_widget_domain' ); |
| 3396 |
} |
| 3397 |
|
| 3398 |
if (isset( $instance[ 'textarea' ] )) { |
| 3399 |
$textarea = $instance[ 'textarea' ]; |
| 3400 |
} |
| 3401 |
else { |
| 3402 |
$textarea = __( '', 'pilotpress_widget_domain' ); |
| 3403 |
} |
| 3404 |
|
| 3405 |
$titleText = "<p>"; |
| 3406 |
$titleText .= "<label for='" . $this->get_field_id( 'title' ) ."'>". __( 'Title:' ) ."</label>"; |
| 3407 |
$titleText .= "<input class='widefat' id='". $this->get_field_id( 'title' ) ."' name='". $this->get_field_name( 'title' )."' type='text' value='". esc_attr( $title )."' />"; |
| 3408 |
$titleText .= "</p>"; |
| 3409 |
|
| 3410 |
$textAreaText = "<p>"; |
| 3411 |
$textAreaText .= "<textarea class='widefat' id='". $this->get_field_id( 'textarea' )."' name='" . $this->get_field_name( 'textarea' ) ."' rows='16' cols='20'>". esc_attr( $textarea ) ."</textarea>"; |
| 3412 |
$textAreaText .= "</p>"; |
| 3413 |
|
| 3414 |
//echo out the actual widget content block |
| 3415 |
echo $mergeFieldDropDown; |
| 3416 |
echo $titleText; |
| 3417 |
echo $textAreaText; |
| 3418 |
|
| 3419 |
} |
| 3420 |
|
| 3421 |
// Updating widget replacing old instances with new |
| 3422 |
public function update( $new_instance, $old_instance ) { |
| 3423 |
$instance = array(); |
| 3424 |
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : ''; |
| 3425 |
$instance['textarea'] = ( ! empty( $new_instance['textarea'] ) ) ? $new_instance['textarea'] : ''; |
| 3426 |
return $instance; |
| 3427 |
} |
| 3428 |
} // Class pilotpress_widget ends here |
| 3429 |
|
| 3430 |
} |
| 3431 |
|
| 3432 |
function pilotpress_widget_js() { |
| 3433 |
$widgetJavascript = " |
| 3434 |
<script type='text/javascript'> |
| 3435 |
jQuery( document ).ready( function(){ |
| 3436 |
jQuery( 'body' ).on( 'change', 'select.op-merge-codes__select', function( ev ) { |
| 3437 |
var textarea = jQuery(this).closest( 'form' ).find( 'textarea' ); |
| 3438 |
textarea.val(textarea.val() + jQuery(this).val()); |
| 3439 |
} ); |
| 3440 |
} ); |
| 3441 |
</script> |
| 3442 |
"; |
| 3443 |
echo $widgetJavascript; |
| 3444 |
} |
| 3445 |
|
| 3446 |
|
| 3447 |
|
| 3448 |
function enable_pilotpress() { |
| 3449 |
$pilotpress = new PilotPress; |
| 3450 |
$pilotpress->do_enable(); |
| 3451 |
} |
| 3452 |
|
| 3453 |
function disable_pilotpress() { |
| 3454 |
$pilotpress = new PilotPress; |
| 3455 |
$pilotpress->do_disable(); |
| 3456 |
} |
| 3457 |
/* remember Xevious? this is it... render some JS for the tinymce plugin! */ |
| 3458 |
if(isset($_GET["ping"])) { |
| 3459 |
switch($_GET["ping"]) { |
| 3460 |
case "s": |
| 3461 |
echo json_encode(array("version" => PilotPress::VERSION)); |
| 3462 |
break; |
| 3463 |
case "js39": |
| 3464 |
|
| 3465 |
PilotPress::start_session(); |
| 3466 |
header("Content-Type: text/javascript"); |
| 3467 |
|
| 3468 |
?> |
| 3469 |
|
| 3470 |
tinymce.PluginManager.add('pilotpress', function(editor, url) |
| 3471 |
{ |
| 3472 |
|
| 3473 |
editor.addButton('merge_fields', { |
| 3474 |
type: 'listbox', |
| 3475 |
|
| 3476 |
text: 'Merge Fields', |
| 3477 |
icon: false, |
| 3478 |
classes: 'fixed-width btn widget', |
| 3479 |
onselect: function(e) { |
| 3480 |
if (this.value() != "" ) |
| 3481 |
{ |
| 3482 |
editor.insertContent("[pilotpress_field name='"+this.value()+"']"); |
| 3483 |
} |
| 3484 |
}, |
| 3485 |
values: [ |
| 3486 |
<?php |
| 3487 |
$fields = $_SESSION["default_fields"]; |
| 3488 |
if(!empty($fields) && is_array($fields)) |
| 3489 |
{ |
| 3490 |
foreach($fields as $group => $items) |
| 3491 |
{ |
| 3492 |
echo json_encode(array( "text" => $group , "value" => "") ) . " , "; |
| 3493 |
foreach($items as $key => $value) |
| 3494 |
{ |
| 3495 |
echo json_encode( array( "text" => " + " . $key , "value" => $key) ) . " , "; |
| 3496 |
} |
| 3497 |
|
| 3498 |
} |
| 3499 |
} |
| 3500 |
?> |
| 3501 |
], |
| 3502 |
onPostRender: function() { |
| 3503 |
// Select the second item by default |
| 3504 |
} |
| 3505 |
}); |
| 3506 |
}); |
| 3507 |
|
| 3508 |
<?php |
| 3509 |
|
| 3510 |
|
| 3511 |
break; |
| 3512 |
case "js": |
| 3513 |
|
| 3514 |
PilotPress::start_session(); |
| 3515 |
header("Content-Type: text/javascript"); |
| 3516 |
|
| 3517 |
?> |
| 3518 |
(function(){ |
| 3519 |
|
| 3520 |
tinymce.PluginManager.requireLangPack('pilotpress'); |
| 3521 |
|
| 3522 |
tinymce.create('tinymce.plugins.pilotpress', { |
| 3523 |
|
| 3524 |
init : function(ed, url){ |
| 3525 |
}, |
| 3526 |
createControl : function(n, cm){ |
| 3527 |
switch(n) { |
| 3528 |
case "merge_fields": |
| 3529 |
var mlb = cm.createListBox('merge_fields', { |
| 3530 |
title : 'Merge Fields', |
| 3531 |
onselect : function(v) { |
| 3532 |
if(v!="") { |
| 3533 |
tinyMCE.activeEditor.execCommand('mceInsertContent', false, '[pilotpress_field name=\''+v+'\']'); |
| 3534 |
} |
| 3535 |
} |
| 3536 |
}); |
| 3537 |
|
| 3538 |
|
| 3539 |
<?php |
| 3540 |
$fields = $_SESSION["default_fields"]; |
| 3541 |
if(!empty($fields) && is_array($fields)) |
| 3542 |
{ |
| 3543 |
foreach($fields as $group => $items) |
| 3544 |
{ |
| 3545 |
echo " "; |
| 3546 |
echo "mlb.add('".addslashes($group)."', '');\n"; |
| 3547 |
foreach($items as $key => $value) |
| 3548 |
{ |
| 3549 |
echo " "; |
| 3550 |
echo "mlb.add(' + ".addslashes($key)."', '".addslashes($key)."');\n"; |
| 3551 |
} |
| 3552 |
} |
| 3553 |
} |
| 3554 |
?> |
| 3555 |
|
| 3556 |
return mlb; |
| 3557 |
|
| 3558 |
|
| 3559 |
break; |
| 3560 |
} |
| 3561 |
return null; |
| 3562 |
}, |
| 3563 |
|
| 3564 |
getInfo : function(){ |
| 3565 |
return { |
| 3566 |
longname: 'PilotPress', |
| 3567 |
author: 'Ontraport Inc.', |
| 3568 |
authorurl: 'http://<?php echo PilotPress::$brand_url ?>', |
| 3569 |
infourl: 'http://<?php echo PilotPress::$brand_url ?>/', |
| 3570 |
version: "<?php echo PilotPress::VERSION; ?>" |
| 3571 |
}; |
| 3572 |
} |
| 3573 |
}); |
| 3574 |
tinymce.PluginManager.add('pilotpress', tinymce.plugins.pilotpress); |
| 3575 |
})(); |
| 3576 |
<?php |
| 3577 |
|
| 3578 |
break; |
| 3579 |
default: |
| 3580 |
echo "goodPing();"; |
| 3581 |
die; |
| 3582 |
break; |
| 3583 |
} |
| 3584 |
die; |
| 3585 |
} |
| 3586 |
|