. */ $agca = new AGCA(); class AGCA{ private $colorizer=""; private $agca_version; private $agca_debug = false; private $admin_capabilities; private $context = ""; private $saveAfterImport = false; private $templateCustomizations = ""; private $templates_ep = "http://wordpressadminpanel.com/configuration.php"; public function __construct() { add_action('init', array(&$this,'init')); } function init(){ $this->reloadScript(); $this->checkPOST(); $this->checkGET(); if(function_exists("add_filter")){ add_filter('admin_title', array(&$this,'change_title'), 10, 2); add_filter('plugin_row_meta', array(&$this,'jk_filter_plugin_links'), 10, 2); } add_action('admin_init', array(&$this,'agca_register_settings')); add_action('admin_init', array(&$this,'agca_init_session')); add_action('admin_head', array(&$this,'print_admin_css')); add_action('login_head', array(&$this,'print_login_head')); add_action('admin_menu', array(&$this,'agca_create_menu')); add_action('wp_head', array(&$this,'print_page')); add_action( 'wp_before_admin_bar_render', array(&$this,'admin_bar_changes') ); add_action( 'plugins_loaded', array(&$this,'load_plugin_textdomain') ); register_deactivation_hook(__FILE__, array(&$this,'agca_deactivate')); add_action( 'customize_controls_enqueue_scripts', array(&$this,'agca_customizer_php') ); /* wp_localize_script( 'agca-script',//use agca enqueued script 'agca_string', $this->get_language_strings() );*/ /*Initialize properties*/ $this->colorizer = $this->jsonMenuArray(get_option('ag_colorizer_json'),'colorizer'); $this->agca_version = "5.6.2"; //TODO:upload images programmatically } function load_plugin_textdomain() { load_plugin_textdomain( 'ag-custom-admin', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' ); } // Add donate and support information function jk_filter_plugin_links($links, $file) { if ( $file == plugin_basename(__FILE__) ) { if(!is_network_admin()){ $links[] = '' . __('Settings', 'ag-custom-admin') . ''; $links[] = '' . __('Admin Themes', 'ag-custom-admin') . ''; } $links[] = '' . __('Support', 'ag-custom-admin') . ''; $links[] = '' . __('Upgrade', 'ag-custom-admin') . ''; $links[] = '' . __('Donate', 'ag-custom-admin') . ''; } return $links; } function change_admin_color(){ return 'default'; } function agca_customizer_php(){ $this->agca_get_includes(); } function agca_init_session(){ if (!session_id()) session_start(); } function checkGET(){ if(isset($_GET['agca_action'])){ if($_GET['agca_action'] =="remove_templates"){ $this->delete_template_images_all(); update_option('agca_templates', ""); update_option('agca_selected_template', ""); } } if(isset($_GET['agca_debug'])){ if($_GET['agca_debug'] =="true"){ $this->agca_debug = true; }else{ $this->agca_debug = false; } } } function checkPOST(){ if(isset($_POST['_agca_save_template'])){ $this->verifyPostRequest(); //print_r($_POST); $data = $_POST['templates_data']; $parts = explode("|||",$data); $common_data = $parts [0]; $admin_js = $parts [1]; $admin_css = $parts [2]; $login_js = $parts [3]; $login_css = $parts [4]; $settings = $parts [5]; $images = $parts [6]; $template_name = $_POST['templates_name']; update_option('agca_selected_template', $template_name); $templates = get_option( 'agca_templates' ); if($templates == ""){ $templates = array(); } $templates[$template_name] = array( 'common'=>$common_data, 'admin'=>"", 'adminjs'=>$admin_js, 'admincss'=>$admin_css, 'login'=>"", 'loginjs'=>$login_js, 'logincss'=>$login_css, 'images'=>$images, 'settings'=>$settings ); update_option('agca_templates', $templates); $_POST = array(); }else if(isset($_POST['_agca_templates_session'])){ $this->verifyPostRequest(); $this->agcaAdminSession(); if($_POST['template'] !="") $_SESSION["AGCA"]["Templates"][$_POST['template']] = array("license"=>$_POST['license']); //print_r($_SESSION); echo "_agca_templates_session:OK"; exit; }else if(isset($_POST['_agca_templates_session_remove_license'])){ $this->verifyPostRequest(); $this->agcaAdminSession(); if($_POST['template'] !="") $_SESSION["AGCA"]["Templates"][$_POST['template']] = null; print_r($_SESSION); echo "_agca_templates_session_remove_license:OK"; exit; }else if(isset($_POST['_agca_get_templates'])){ $this->verifyPostRequest(); $templates = get_option( 'agca_templates' ); if($templates == "") $templates = array(); $results = array(); foreach($templates as $key=>$val){ $results[]=$key; } echo json_encode($results); exit; }else if(isset($_POST['_agca_activate_template'])){ $this->verifyPostRequest(); update_option('agca_selected_template', $_POST['_agca_activate_template']); $_POST = array(); //unset($_POST); exit; }else if(isset($_POST['_agca_template_settings'])){ $this->verifyPostRequest(); $settings = $_POST['_agca_template_settings']; $templates = get_option( 'agca_templates' ); if($templates == ""){ $templates = array(); } $template_name = $_POST["_agca_current_template"]; $templates[$template_name]["settings"] = $settings; update_option('agca_templates', $templates); $_POST = array(); //print_r($templates); exit; }else if(isset($_POST['_agca_upload_image'])){ $this->verifyPostRequest(); function my_sideload_image() { $remoteurl = $_POST['_agca_upload_image']; $file = media_sideload_image( $remoteurl, 0 ,__("AG Custom Admin theme image (do not delete)", 'ag-custom-admin')); try{ $fileparts = explode("src='", $file); $url=explode("'",$fileparts[1]); echo $url[0]; }catch (\Exception $e){} exit; } add_action( 'admin_init', 'my_sideload_image' ); }else if(isset($_POST['_agca_remove_template_images'])){ $this->verifyPostRequest(); $this->delete_template_images($_POST['_agca_remove_template_images']); exit; } } function verifyPostRequest(){ if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (!is_admin()) { _e('Not allowed. This action is allowed exclusively in admin panel', 'ag-custom-admin'); exit; } //In case of problems with saving AGCA settings on MS disable verification temporary if(get_option('agca_disable_postver')){ return; } if (is_multisite()) { $blog_id = get_current_blog_id(); $user_id = get_current_user_id(); $msError = __('Please try temporary disabling POST verification. Go to AG Custom Admin -> Advanced -> Temporary disable POST verification. Do not forget to un-check this option once you are done with customizations.', 'ag-custom-admin'); if (is_user_member_of_blog($user_id, $blog_id)) { if (!current_user_can('manage_options')) { _e('Multi-site: Current user is not recognized as administrator.', 'ag-custom-admin'); echo ' '.$msError; exit; } } else { printf( /*translators: 1: User Id 2: Blog Id*/ __('Multi-site: User (%1$s) does not have access to this blog (%2$s).', 'ag-custom-admin'), $user_id, $blog_id ); echo ' '. $msError; exit; } } else { include_once(ABSPATH . 'wp-includes/pluggable.php'); if (!is_user_logged_in() || !current_user_can('manage_options')) { echo !is_user_logged_in() ? __('User is not logged in.', 'ag-custom-admin').' ' : ''; echo !current_user_can('manage_options') ? __('User can not manage options.', 'ag-custom-admin').' ' : ''; exit; } } if (!wp_verify_nonce($_POST['_agca_token'], 'agca_form')) { echo __('Nonce verification failed.', 'ag-custom-admin'); exit; } } } function get_language_strings() { $strings = array( ); return $strings; } function admin_bar_changes(){ if( current_user_can( 'manage_options' )){ global $wp_admin_bar; if(!is_network_admin()){ $wp_admin_bar->add_menu( array( 'id' => 'agca-admin-themes', 'title' => ''.__( 'Admin Themes', 'agca-custom-admin' ), 'href' => 'tools.php?page=ag-custom-admin/plugin.php#ag-templates' )); } } } function delete_template_images_all(){ $templates = get_option('agca_templates'); if($templates != null && $templates != ""){ foreach($templates as $template){ if($template != null && $template['images'] != null && $template['images'] != ""){ //print_r($template['images']); $imgs = explode(',',$template['images']); foreach($imgs as $imageSrc){ $this->delete_attachment_by_src($imageSrc); } //print_r($imgs); } } } //print_r($templates); } function delete_template_images($template_name){ $templates = get_option('agca_templates'); if($templates != null && $templates != ""){ $template = $templates[$template_name]; if($template != null && $template['images'] != null && $template['images'] != ""){ //print_r($template['images']); exit; $imgs = explode(',',$template['images']); foreach($imgs as $imageSrc){ $this->delete_attachment_by_src($imageSrc); } //print_r($imgs); } } //print_r($templates); } function delete_attachment_by_src ($image_src) { global $wpdb; $query = "SELECT ID FROM {$wpdb->posts} WHERE guid='$image_src'"; $id = $wpdb->get_var($query); wp_delete_attachment( $id, $true ); } function get_installed_agca_templates(){ $templates = get_option( 'agca_templates' ); if($templates == "")return '[]'; $results = array(); foreach($templates as $key=>$val){ $results[]=$key; } return json_encode($results); } function isGuest(){ global $user_login; if($user_login) { return false; }else{ return true; } } function change_title($admin_title, $title){ //return get_bloginfo('name').' - '.$title; if(get_option('agca_custom_title')!=""){ $blog = get_bloginfo('name'); $page = $title; $customTitle = get_option('agca_custom_title'); $customTitle = str_replace('%BLOG%',$blog,$customTitle); $customTitle = str_replace('%PAGE%',$page,$customTitle); return $customTitle; }else{ return $admin_title; } } function agca_get_includes() { ?> " /> context == "login"){ ?> templateCustomizations; if(!((get_option('agca_role_allbutadmin')==true) and (current_user_can($this->admin_capability())))){ ?> agca_version ); } function WPSPluginIsLoginPage(){ $WPSPluginName = 'wps-hide-login/wps-hide-login.php'; if(is_multisite()){ if ( ! function_exists( 'is_plugin_active_for_network' ) ) require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); if(!$this->isPluginActiveForNetwork($WPSPluginName)){ return ''; } }else{ if(!$this->isPluginActive($WPSPluginName)){ return ''; } } if ( $slug = get_option( 'whl_page' ) ) { return $slug; } else if ( ( is_multisite() && $this->isPluginActiveForNetwork($WPSPluginName) && ( $slug = get_site_option( 'whl_page', 'login' ) ) ) ) { return $slug; } else if ( $slug = 'login' ) { return $slug; } $requestURI = $_SERVER['REQUEST_URI']; return $this->startsWith('/'.$slug.'/', $requestURI); } function reloadScript(){ $isAdmin = false; if(defined('WP_ADMIN') && WP_ADMIN == 1){ $isAdmin = true; } if(in_array((isset($GLOBALS['pagenow'])?$GLOBALS['pagenow']:""), array('wp-login.php', 'wp-register.php')) || $isAdmin || $this->WPSPluginIsLoginPage()){ $this->agca_enqueue_scripts(); } } function agca_register_settings() { register_setting( 'agca-options-group', 'agca_role_allbutadmin' ); register_setting( 'agca-options-group', 'agca_screen_options_menu' ); register_setting( 'agca-options-group', 'agca_help_menu' ); register_setting( 'agca-options-group', 'agca_logout' ); register_setting( 'agca-options-group', 'agca_remove_your_profile' ); register_setting( 'agca-options-group', 'agca_logout_only' ); register_setting( 'agca-options-group', 'agca_custom_title' ); register_setting( 'agca-options-group', 'agca_howdy' ); register_setting( 'agca-options-group', 'agca_header' ); register_setting( 'agca-options-group', 'agca_header_show_logout' ); register_setting( 'agca-options-group', 'agca_footer' ); register_setting( 'agca-options-group', 'agca_privacy_options' ); register_setting( 'agca-options-group', 'agca_header_logo' ); register_setting( 'agca-options-group', 'agca_header_logo_custom' ); register_setting( 'agca-options-group', 'agca_wp_logo_custom' ); register_setting( 'agca-options-group', 'agca_remove_site_link' ); register_setting( 'agca-options-group', 'agca_wp_logo_custom_link' ); register_setting( 'agca-options-group', 'agca_site_heading' ); register_setting( 'agca-options-group', 'agca_custom_site_heading' ); register_setting( 'agca-options-group', 'agca_update_bar' ); register_setting( 'agca-options-group', 'agca_footer_left' ); register_setting( 'agca-options-group', 'agca_footer_left_hide' ); register_setting( 'agca-options-group', 'agca_footer_right' ); register_setting( 'agca-options-group', 'agca_footer_right_hide' ); register_setting( 'agca-options-group', 'agca_login_banner' ); register_setting( 'agca-options-group', 'agca_login_banner_text' ); register_setting( 'agca-options-group', 'agca_login_photo_remove' ); register_setting( 'agca-options-group', 'agca_login_photo_url' ); register_setting( 'agca-options-group', 'agca_login_photo_href' ); register_setting( 'agca-options-group', 'agca_login_round_box' ); register_setting( 'agca-options-group', 'agca_login_round_box_size' ); register_setting( 'agca-options-group', 'agca_dashboard_icon' ); register_setting( 'agca-options-group', 'agca_dashboard_text' ); register_setting( 'agca-options-group', 'agca_dashboard_text_paragraph' ); register_setting( 'agca-options-group', 'agca_dashboard_widget_welcome' ); register_setting( 'agca-options-group', 'agca_dashboard_widget_activity' ); register_setting( 'agca-options-group', 'agca_dashboard_widget_il' ); register_setting( 'agca-options-group', 'agca_dashboard_widget_plugins' ); register_setting( 'agca-options-group', 'agca_dashboard_widget_qp' ); register_setting( 'agca-options-group', 'agca_dashboard_widget_rn' ); register_setting( 'agca-options-group', 'agca_dashboard_widget_rd' ); register_setting( 'agca-options-group', 'agca_dashboard_widget_primary' ); register_setting( 'agca-options-group', 'agca_dashboard_widget_secondary' ); //WP3.3 register_setting( 'agca-options-group', 'agca_admin_bar_comments' ); register_setting( 'agca-options-group', 'agca_admin_bar_new_content' ); register_setting( 'agca-options-group', 'agca_admin_bar_new_content_post' ); register_setting( 'agca-options-group', 'agca_admin_bar_new_content_link' ); register_setting( 'agca-options-group', 'agca_admin_bar_new_content_page' ); register_setting( 'agca-options-group', 'agca_admin_bar_new_content_user' ); register_setting( 'agca-options-group', 'agca_admin_bar_new_content_media' ); register_setting( 'agca-options-group', 'agca_admin_bar_update_notifications' ); register_setting( 'agca-options-group', 'agca_admin_bar_admin_themes' ); register_setting( 'agca-options-group', 'agca_remove_top_bar_dropdowns' ); register_setting( 'agca-options-group', 'agca_admin_bar_frontend' ); register_setting( 'agca-options-group', 'agca_admin_bar_frontend_hide' ); register_setting( 'agca-options-group', 'agca_login_register_remove' ); register_setting( 'agca-options-group', 'agca_login_register_href' ); register_setting( 'agca-options-group', 'agca_login_lostpassword_remove' ); register_setting( 'agca-options-group', 'agca_admin_capability' ); register_setting( 'agca-options-group', 'agca_disablewarning' ); register_setting( 'agca-template-group', 'agca_selected_template' ); register_setting( 'agca-template-group', 'agca_templates' ); //delete_option( 'agca_templates' ); /*Admin menu*/ register_setting( 'agca-options-group', 'agca_admin_menu_turnonoff' ); register_setting( 'agca-options-group', 'agca_admin_menu_agca_button_only' ); register_setting( 'agca-options-group', 'agca_admin_menu_separators' ); register_setting( 'agca-options-group', 'agca_admin_menu_icons' ); register_setting( 'agca-options-group', 'agca_admin_menu_collapse_button' ); register_setting( 'agca-options-group', 'agca_admin_menu_arrow' ); register_setting( 'agca-options-group', 'agca_admin_menu_submenu_round' ); register_setting( 'agca-options-group', 'agca_admin_menu_submenu_round_size' ); register_setting( 'agca-options-group', 'agca_admin_menu_brand' ); register_setting( 'agca-options-group', 'agca_admin_menu_brand_link' ); register_setting( 'agca-options-group', 'agca_admin_menu_autofold' ); register_setting( 'agca-options-group', 'ag_edit_adminmenu_json' ); register_setting( 'agca-options-group', 'ag_edit_adminmenu_json_new' ); register_setting( 'agca-options-group', 'ag_add_adminmenu_json' ); register_setting( 'agca-options-group', 'ag_colorizer_json' ); register_setting( 'agca-options-group', 'agca_colorizer_turnonoff' ); register_setting( 'agca-options-group', 'agca_custom_js' ); register_setting( 'agca-options-group', 'agca_custom_css' ); register_setting( 'agca-options-group', 'agca_disable_postver' ); register_setting( 'agca-options-group', 'agca_menu_remove_client_profile' ); if(!empty($_POST)){ if(isset($_POST['_agca_import_settings']) && $_POST['_agca_import_settings']=="true"){ $this->verifyPostRequest(); if(isset($_FILES) && isset($_FILES['settings_import_file']) ){ if($_FILES["settings_import_file"]["error"] > 0){ }else{ $file = $_FILES['settings_import_file']; if($this->startsWith($file['name'],'AGCA_Settings')){ if (file_exists($file['tmp_name'])) { $fh = fopen($file['tmp_name'], 'r'); $theData = ""; if(filesize($file['tmp_name']) > 0){ $theData = fread($fh,filesize($file['tmp_name'])); } fclose($fh); $this->importSettings($theData); } } } } }else if(isset($_POST['_agca_export_settings']) && $_POST['_agca_export_settings']=="true"){ $this->verifyPostRequest(); $this->exportSettings(); } } if(isset($_GET['agca_action'])){ if($_GET['agca_action'] == "disablewarning"){ update_option('agca_disablewarning', true); } } } function agca_deactivate() { } function getOptions(){ return Array( 'agca_role_allbutadmin', 'agca_admin_bar_frontend', 'agca_admin_bar_frontend_hide', 'agca_login_register_remove', 'agca_login_register_href', 'agca_login_lostpassword_remove', 'agca_admin_capability', 'agca_screen_options_menu', 'agca_help_menu', 'agca_logout', 'agca_remove_your_profile', 'agca_logout_only', 'agca_custom_title', 'agca_howdy', 'agca_header', 'agca_header_show_logout', 'agca_footer', 'agca_privacy_options', 'agca_header_logo', 'agca_header_logo_custom', 'agca_remove_site_link', 'agca_wp_logo_custom', 'agca_wp_logo_custom_link', 'agca_site_heading', 'agca_custom_site_heading', 'agca_update_bar', 'agca_footer_left', 'agca_footer_left_hide', 'agca_footer_right', 'agca_footer_right_hide', 'agca_login_banner', 'agca_login_banner_text', 'agca_login_photo_remove', 'agca_login_photo_url', 'agca_login_photo_href', 'agca_login_round_box', 'agca_login_round_box_size', 'agca_dashboard_icon', 'agca_dashboard_text', 'agca_dashboard_text_paragraph', 'agca_dashboard_widget_welcome', 'agca_dashboard_widget_activity', 'agca_dashboard_widget_il', 'agca_dashboard_widget_plugins', 'agca_dashboard_widget_qp', 'agca_dashboard_widget_rn', 'agca_dashboard_widget_rd', 'agca_dashboard_widget_primary', 'agca_dashboard_widget_secondary', 'agca_admin_bar_comments', 'agca_admin_bar_new_content', 'agca_admin_bar_new_content_post', 'agca_admin_bar_new_content_link', 'agca_admin_bar_new_content_page', 'agca_admin_bar_new_content_user', 'agca_admin_bar_new_content_media', 'agca_admin_bar_update_notifications', 'agca_admin_bar_admin_themes', 'agca_remove_top_bar_dropdowns', 'agca_admin_menu_turnonoff', 'agca_admin_menu_agca_button_only', 'agca_admin_menu_separators', 'agca_admin_menu_icons', 'agca_admin_menu_arrow', 'agca_admin_menu_submenu_round', 'agca_admin_menu_submenu_round_size', 'agca_admin_menu_brand', 'agca_admin_menu_brand_link', 'agca_admin_menu_autofold', 'agca_admin_menu_collapse_button', 'ag_edit_adminmenu_json', 'ag_edit_adminmenu_json_new', 'ag_add_adminmenu_json', 'ag_colorizer_json', 'agca_colorizer_turnonof', 'agca_custom_js', 'agca_custom_css', 'agca_colorizer_turnonoff', 'agca_disablewarning', 'agca_disable_postver', 'agca_menu_remove_client_profile', 'agca_selected_template', 'agca_templates', ); } function getTextEditor($name){ $settings = array( 'textarea_name' => $name, 'media_buttons' => true, 'tinymce' => array( 'theme_advanced_buttons1' => 'formatselect,|,bold,italic,underline,|,' . 'bullist,blockquote,|,justifyleft,justifycenter' . ',justifyright,justifyfull,|,link,unlink,|' . ',spellchecker,wp_fullscreen,wp_adv' ) ); wp_editor( get_option($name), $name, $settings ); } function importSettings($settings){ $exploaded = explode("|^|^|", $settings); // $str = "EEE: "; $str = ''; $savedOptions = array(); foreach ($exploaded as $setting){ $key = current(explode(':', $setting)); $value = substr($setting, strlen($key)+1); $cleanedValue = str_replace('|^|^|','',$value); $savedOptions[$key] = $cleanedValue; } // print_r($savedOptions); $optionNames = $this->getOptions(); foreach ($optionNames as $optionName){ $optionValue = ""; $optionValue = $savedOptions[$optionName]; if($optionName == "ag_edit_adminmenu_json" || "ag_edit_adminmenu_json_new"|| $optionName == "ag_add_adminmenu_json" ||$optionName == "ag_colorizer_json"){ $optionValue = str_replace("\\\"", "\"", $optionValue); $optionValue = str_replace("\\\'", "\'", $optionValue); }else if($optionName == "agca_custom_js" || $optionName == "agca_custom_css"){ //fb($optionValue); $optionValue = htmlspecialchars_decode($optionValue); $optionValue = str_replace("\'", '"', $optionValue); $optionValue = str_replace('\"', "'", $optionValue); //fb($optionValue); }else{ } update_option($optionName, $optionValue); $str.="/".$optionName."/".$optionValue."\n"; } //Migration from 1.2.6. to 1.2.5.1 - remove in later versions //agca_script_css // // fb($savedOptions); if($savedOptions['agca_script_css'] != null){ $optionValue = ""; $optionValue = str_replace("\'", '"', $savedOptions['agca_script_css']); $optionValue = str_replace('\"', "'", $optionValue); update_option('agca_custom_css', $optionValue); } if($savedOptions['agca_script_js'] != null){ $optionValue = ""; $optionValue = str_replace("\'", '"', $savedOptions['agca_script_js']); $optionValue = str_replace('\"', "'", $optionValue); update_option('agca_custom_js', $optionValue); } //echo $str; //save imported settings $this->saveAfterImport = true; } function exportSettings(){ $str = ""; $include_menu_settings = false; if(isset($_POST['export_settings_include_admin_menu'])){ if($_POST['export_settings_include_admin_menu'] == 'on'){ $include_menu_settings = true; } } foreach ($_POST as $key => $value) { if ($this->startsWith($key,'ag')||$this->startsWith($key,'color')) { if($this->startsWith($key,'ag_edit_adminmenu')){ if($include_menu_settings) $str .=$key. ":".$value."|^|^|"; }else{ $str .=$key. ":".$value."|^|^|"; } } } $filename = __('AGCA_Settings', 'ag-custom-admin').'_'.date("Y-M-d_H-i-s").'.agca'; header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=$filename"); header("Content-Type: text/plain; "); header("Content-Transfer-Encoding: binary"); echo $str; die(); } function startsWith($haystack, $needle) { $length = strlen($needle); return (substr($haystack, 0, $length) === $needle); } function agca_create_menu() { add_management_page('AG Custom Admin', 'AG Custom Admin', 'administrator', __FILE__, array(&$this,'agca_admin_page') ); } function agca_create_admin_button($name,$arr) { $href = $arr["value"]; $target =$arr["target"]; $button ="
AG Custom Admin (vagca_version; ?>)