get_expander_data($expander_id),$user_id,$expander_id,$parameters);
return $expander_data;
}
static function is_on() {
return (defined("AMS_ON") && AMS_ON)?true:false;
}
function css_in_head() {
if(!self::is_on()) {
return;
}
$ams_preferences = AMS_Plugin::get_preferences();
?>
have_posts()) {
while($wp_query->have_posts()) {
$wp_query->the_post();
$id = get_the_ID();
$title = get_the_title();
$arr[]=array("label"=>$id.". ".$title,'value'=>$title,'id'=>$id);
}
}
echo json_encode($arr);
wp_die();
}
function init()
{
$user_id = get_current_user_id();
if(isset($_GET['ams_export'])) {
if( !isset($_REQUEST['ams_export_nonce']) OR !wp_verify_nonce($_REQUEST['ams_export_nonce'],'ams_export_nonce')) {
echo "Nonce failed.";
die;
}
$User = new AMS_User($user_id);
$str = json_encode($User->get_all_data());
//echo $str;
//die;
$handle = fopen("admin_menu_configuration.dat", "w");
fwrite($handle, $str);
fclose($handle);
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename('admin_menu_configuration.dat'));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . strlen($str));
echo $str;
exit;
}
if(isset($_POST['submit_ams_import_file'])) {
if( !isset($_REQUEST['ams_import_nonce']) OR !wp_verify_nonce($_REQUEST['ams_import_nonce'],'ams_import_nonce')) {
echo "Nonce failed.";
die;
}
//#=var_dump($_FILES);
$new_data = file_get_contents($_FILES['ams_import_file']['tmp_name']);
$user_id = get_current_user_id();
$User = new AMS_User($user_id);
$data = json_decode($new_data,true);
$User->save_sorter_data($data['sorter']);
$User->save_expanders($data['expanders']);
$User->save_preferences($data['preferences']);
wp_redirect(admin_url('admin.php?page=ams_import_export&import_success=1'));
wp_die();
}
$ams_on = ams_is_on($user_id);
if($ams_on) {
define("AMS_ON",true);
}
else {
define("AMS_ON",false);
}
if( isset($_POST['ams_preferences_submitted']) && $_POST['ams_preferences_submitted'] ) {
if(!wp_verify_nonce($_REQUEST['preferences_nonce'],'preferences_nonce')) {
echo "Nonce failed.";
die;
}
if(apply_filters("ams_preferences_continue_save",true)) {
$User = new AMS_User($user_id);
$User->save_preferences($_POST);
define("AMS_PREFERENCES_SUCCESS",1);
}
else {
// let filter handle the saving instead.
}
}
if( isset($_POST['ams_global_settings_submitted']) && $_POST['ams_global_settings_submitted'] ) {
if(!wp_verify_nonce($_REQUEST['ams_global_nonce'],'ams_global_nonce')) {
echo "Nonce failed.";
die;
}
update_option("ams_minimum_capability",$_REQUEST['cap']);
define("AMS_PREFERENCES_SUCCESS",1);
}
}
function add_color_picker()
{
wp_enqueue_style('wp-color-picker');
}
function admin_menu()
{
$current_cap = get_option("ams_minimum_capability");
if(!$current_cap)$current_cap="read";
if(!current_user_can("manage_options")):
$user_can_view = apply_filters("amo_current_user_can_view",true);
else:
$user_can_view = true; // if they'
endif;
if(!$user_can_view)return false;
add_menu_page('Admin Menu Organizer', 'Admin Menu Organizer', $current_cap, 'ams_settings', array(
$this,
'ams_sorter_main_page'
), 'dashicons-tickets', 60);
add_submenu_page('ams_settings', 'Admin Menu Organizer User Settings', 'User Settings', $current_cap, 'ams_preferences_page', array(
$this,
'ams_preferences_page'
));
add_submenu_page('ams_settings', 'Import / Export', 'Import / Export', $current_cap, 'ams_import_export', array(
$this,
'ams_import_export_page'
));
add_submenu_page('ams_settings', 'Admin Menu Organizer Global Settings', 'Global Settings', 'manage_options', 'ams_global_settings_page', array(
$this,
'ams_global_settings_page'
));
}
function ams_page_header() {
}
function ams_sorter_main_page()
{
global $title;
print '';
do_action("ams_page_header");
print "
$title
";
$file = __DIR__ . "/admin_pages/sorter.php";
if (file_exists($file))
require $file;
print '';
}
function ams_custom_pages_page()
{
global $title;
print '';
do_action("ams_page_header");
print "
$title
";
$file = __DIR__ . "/admin_pages/custom_pages.php";
if (file_exists($file))
require $file;
print '';
}
function ams_preferences_page()
{
global $title;
print '';
do_action("ams_page_header");
print "
$title
";
$file = __DIR__ . "/admin_pages/preferences.php";
if (file_exists($file))
require $file;
print '';
}
function ams_global_settings_page()
{
if(!current_user_can("manage_options"))return;
global $title;
print '';
do_action("ams_page_header");
print "
$title
";
$file = __DIR__ . "/admin_pages/global.php";
if (file_exists($file))
require $file;
print '';
}
function ams_import_export_page() {
global $title;
print '';
do_action("ams_page_header");
print "
$title
";
$file = __DIR__ . "/admin_pages/import_export.php";
if (file_exists($file))
require $file;
print '';
}
static function get_page_data($page_id) {
$menu_items = apply_filters("ams_filter_menu_global",$GLOBALS[ 'menu' ]);
//echo $page_id;
// echo "
";
$actual_page_id = substr($page_id,11);
// echo $actual_page_id;
// echo "
";
if(is_array($menu_items)) {
foreach($menu_items as $mu) {
if(!isset($mu[5]))continue;
// echo "".$mu[5];
if($mu[5]==$actual_page_id) {
return $mu;
}
}
}
}
function enqueue_admin_scripts()
{
wp_enqueue_script('ams_js', plugin_dir_url(__FILE__) . 'admin-menu-sorter.js', array(
'wp-color-picker',
'jquery',
'jquery-ui-core',
'jquery-ui-widget',
'jquery-ui-mouse',
'jquery-ui-droppable',
'jquery-ui-draggable',
'jquery-ui-sortable',
'jquery-ui-autocomplete',
), '1.0');
wp_localize_script('ams_js', 'ajax_object', array(
'ajax_url' => admin_url('admin-ajax.php')
));
// wp_enqueue_script('jquery');
// wp_enqueue_script('jquery-ui-core');
// wp_enqueue_script("jqueryui");
wp_register_style('ams_admin_css', plugin_dir_url(__FILE__) . 'admin-style.css', false, '1.0.0');
wp_enqueue_style('ams_admin_css');
}
function main_generated_js()
{
if(!self::is_on())return "";
?>
jQuery("#").attr("data-sort-pos","");
jQuery("#ams-sorter-").attr("data-sort-pos","");
2000) {
break;
}
?>
jQuery("#collapse-menu").attr("data-sort-pos","1000");
var $people = jQuery('#adminmenu'),
$peopleli = $people.children('li');
$peopleli.sort(function(a,b){
var an = parseInt(a.getAttribute('data-sort-pos')),
bn = parseInt(b.getAttribute('data-sort-pos'));
if(an > bn) {
return 1;
}
if(an < bn) {
return -1;
}
return 0;
});
$peopleli.appendTo($people);
get_expander_data($expander_id);
//var_dump($expander_data);
//die;
if (is_array($expander_data)) {
$expander_text = $expander_data['e_name'];
$expander_mode = $expander_data['e_mode'];
} else {
$expander_text = "Unnamed Expander";
$expander_mode = 0;
}
if(!$expander_text)$expander_text = "Unnamed Expander";
if ($last_menu_item !== ""):
?>
jQuery("#adminmenu > #").after(' expander- menu-top menu-icon-arrow-down-alt2">">');
jQuery('#adminmenu').children('li').not("#collapse-menu").each(function () {
if(jQuery(this).hasClass("ams-expander")) {
current_expander = jQuery(this).attr("data-expander-id");
}
else {
jQuery(this).appendTo(jQuery("#ams_sub_group_"+current_expander));
jQuery(this).attr("data-expander-id",current_expander);
if(jQuery("#data-expander-"+current_expander).hasClass("ams-default-state-0")) {
}
}
});
0):
$user_id = get_current_user_id();
$expander_data = get_user_meta($user_id, "ams_menu_expander_{$prepend_expander_id_to_menu}_settings", true);
if (is_array($expander_data)) {
$expander_text = $expander_data['e_name'];
$expander_mode = $expander_data['e_mode'];
} else {
$expander_mode = 0;
$expander_text = "Expander $prepend_expander_id_to_menu";
}
?>
jQuery("#adminmenu").prepend(' expander- menu-top menu-icon-arrow--alt2">">');
jQuery("[data-expander-id=]").not(".ams-expander").not(".expander-form-opener").each(function() {
jQuery(this).appendTo(jQuery("#ams_sub_group_"));
});
// wp-not-current-submenu
jQuery(".ams-expander a").click(function() {
ams_side_menu_toggle_menu(jQuery(this).parent().attr("data-expander-id"));
return false;
});
jQuery("#adminmenu").append('');
jQuery("#adminmenu").append('');
/* open the expander if menu item is open */
jQuery(".wp-menu-open").each(function() {
var expander_id = jQuery(this).attr("data-expander-id");
console.log("We should expand"+expander_id+" (menu-open)");
ams_side_menu_toggle_menu(expander_id,1,true);
});
jQuery(".current.menu-top").each(function() {
var expander_id = jQuery(this).attr("data-expander-id");
console.log("We should expand"+expander_id+" (current-menu-top)");
ams_side_menu_toggle_menu(expander_id,1,true);
});
setTimeout(function() {
//jQuery(".ams_menu_loader").hide();
console.log("as menu loading...");
jQuery("#adminmenu").fadeIn();
},1);
});
"P Title",
'menu_title' => "M Title",
'capability' => 'manage_options'
);
$ams_custom_pages = get_option("ams_custom_pages");
if (is_array($ams_custom_pages)) {
foreach ($ams_custom_pages as $key => $menu_page) {
if (!isset($menu_page['ams_cp_page_title']) OR $menu_page['ams_cp_page_title'] == '')
continue;
$slug = "ams{$key}";
$ams_type = (isset($menu_page['ams_cp_type']))?$menu_page['ams_cp_type']:1;
switch($ams_type) {
case 11:
if (isset($menu_page['ams_existing_admin_page']) && $menu_page['ams_existing_admin_page']) {
$slug = $menu_page['ams_existing_admin_page'];
add_menu_page($menu_page['ams_cp_page_title'], $menu_page['ams_cp_menu_title'], $menu_page['ams_cp_cap_required'], $slug, '', "dashicons-" . $menu_page['ams_cp_icon']);
}
break;
case 1:
case 2:
case 3:
case 4:
add_menu_page($menu_page['ams_cp_page_title'],$menu_page['ams_cp_menu_title'], $menu_page['ams_cp_cap_required'], $slug, array(
$this,
"call_page_function_" . $key
), "dashicons-" . $menu_page['ams_cp_icon']);
break;
}
}
}
}
public function __call($name, $arguments = array())
{
$ams_custom_pages = get_option("ams_custom_pages");
if (strpos($name, "call_page_function_") !== false) {
$menu_item_id = substr($name, 19);
switch($ams_custom_pages[$menu_item_id]['ams_cp_type']) {
case 2:
if (isset($ams_custom_pages[$menu_item_id]['ams_post_id'])) {
echo "";
echo "";
$content_post = get_post($ams_custom_pages[$menu_item_id]['ams_post_id']);
$content = $content_post->post_content;
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
echo $content;
echo "
";
return;
}
break;
case 3:
$content = $ams_custom_pages[$menu_item_id]['ams_content'];
echo do_shortcode($content);
return;
break;
case 4:
$content = $ams_custom_pages[$menu_item_id]['ams_iframe_src'];
?>
allcaps;
} else {
return false;
}
return array_combine(array_keys($current_user_caps), array_keys($current_user_caps));
}
function write_select_options(array $arr, $current_val = 0)
{
foreach ($arr as $key => $val) {
?>
get_preferences()));
}
static function populate_missing_keys($arr,$keys,$val="") {
$empty_arr = array_fill_keys($keys,$val);
if(!is_array($arr))$arr = array();
$final_array = array_merge($empty_arr,$arr);
return $final_array;
}
}
new AMS_Plugin();
function ams_is_on($user_id) {
return apply_filters("is_ams_on",get_user_meta( $user_id, 'ams_menu_on' , true ));
}