admin_url('admin-ajax.php'), 'img_base' => $imgLocationBase) ); wp_localize_script( 'smart_layer_modal_script', 'smartlayer_param', array('ajax_url'=> admin_url('admin-ajax.php')) ); } } add_action('admin_menu','smart_layer_admin_menu'); function smart_layer_admin_actions() { at_smart_layer_is_pro_user(); update_option('smart_layer_activated', '1'); add_options_page("AddThis Smart Layers", "AddThis Smart Layers", 'manage_options', basename(__FILE__), "smart_layer_admin"); } add_action('admin_menu', 'smart_layer_admin_actions'); add_action("wp_ajax_save_smart_layer_settings", "save_smart_layer_settings"); function strip_if_needed($value) { if (get_magic_quotes_gpc()) { $value = stripslashes($value); } return $value; } function save_settings() { if (current_user_can('manage_options')) { $value = isset($_POST['value']) ? strip_if_needed($_POST['value']) : ''; $id = isset($_POST['profileId']) ? $_POST['profileId'] : ''; if (!at_smart_layer_is_pro_user($id)) { if ( !$value ) { update_option('smart_layer_settings', "{}"); } else { update_option('smart_layer_settings', "$value"); } } global $addthis_addjs; $addthis_addjs['profile'] = $id; update_option('smart_layer_profile', "$id"); die('{"value":"' . $value . '"}'); } } function save_smart_layer_settings() { //Wait till plugabble.php is loaded to check user capability add_action('plugins_loaded', 'save_settings'); } function save_custom_layer_settings($value, $id) { $value = strip_if_needed($value); if (!at_smart_layer_is_pro_user($id)) { if ( !$value ) { update_option('smart_layer_settings', "{}"); } else { update_option('smart_layer_settings', "$value"); } } update_option('smart_layer_profile', "$id"); } function smart_layer_deactivate() { update_option( 'smart_layer_activated', '0' ); update_option( 'smart_layer_settings', '{}' ); update_option( 'smart_layer_settings_advanced', '0' ); } if(isset($_POST['action'])) { if($_POST['action'] == 'save_smart_layer_settings') { save_smart_layer_settings($_POST['value']); } } if (isset($_POST['save_my_smart_layer'])) { if($_POST['save_my_smart_layer'] == 'save_my_smart_layer') { $value = $_POST['smart_layer_settings']; $id = $_POST['addthis_profile']; save_custom_layer_settings($value, $id); } } // Setup our shared resources early add_action('init', 'smart_layer_early', 1); function smart_layer_early(){ global $addthis_addjs; if (! isset($addthis_addjs)){ require('views/includes/addthis_addjs.php'); $addthis_options = get_option('addthis_settings'); $addthis_addjs = new AddThis_addjs($addthis_options); } elseif (! method_exists( $addthis_addjs, 'getAtPluginPromoText')){ require('views/includes/addthis_addjs_extender.php'); $addthis_addjs = new AddThis_addjs_extender($addthis_options); } } // check for pro user function at_smart_layer_is_pro_user($id = null) { $isPro = false; if ($id) { $profile = $id; } else { $profile = get_option('smart_layer_profile'); } $options = get_option('addthis_settings'); $share_profile = $options['profile']; if ($profile || $share_profile) { $smart_layer_pro = get_option('smart_layer_pro'); if ($profile) { $request = wp_remote_get( "http://q.addthis.com/feeds/1.0/config.json?pubid=" . $profile ); } else { $request = wp_remote_get( "http://q.addthis.com/feeds/1.0/config.json?pubid=" . $share_profile ); } $server_output = wp_remote_retrieve_body( $request ); $array = json_decode($server_output); // check for pro user if (is_array($array) && array_key_exists('_default', $array)){ if ($smart_layer_pro) { // update pro user settings update_option('smart_layer_pro', true); update_option('smart_layer_pro_setting', $server_output); } else { // add pro user settings add_option('smart_layer_pro', true); add_option('smart_layer_pro_setting', $server_output); } $isPro = true; } else { if ($smart_layer_pro) { // update pro user settings delete_option('smart_layer_pro'); delete_option('smart_layer_pro_setting'); } $isPro = false; } } return $isPro; } function AddThisSmartLayersEulaText($buttonName = 'Save') { $eula = 'By clicking "'.$buttonName.'", you certify that you are at least 13 years old, and agree to the AddThis Privacy Policy and Terms of Service.'; return $eula; } ?>