parent = $parent;
$this->db = $this->parent->db;
add_action('admin_menu', array(&$this, 'init_admin_menu'));
//Loading Styles and Scripts for admin
add_action( 'admin_enqueue_scripts', array(&$this, 'load_admin_scripts_styles'), 100);
// Adding Setting Link to plugins list at "Installed Plugins" page
add_filter('plugin_action_links_ads-management/ads-management.php', array(&$this, 'add_plugin_settings_link'));
}
function init_admin_menu() {
global $wpdb;
$var_manage_authority = $this->parent->msbd_adsmp_options_obj->get_option('msbd_adsmp_manage_authority');
$var_view_authority = $this->parent->msbd_adsmp_options_obj->get_option('msbd_adsmp_manage_authority');
add_menu_page(
'Management Advertisement',
'Management Advertisement',
$var_view_authority,
'msbd_adsmp_manage',
array(&$this, 'render_adsmp_manage_page'),
MSBD_ADSMP_URL.'images/msbd_favicon_16.png',
'89.92'
);
add_submenu_page(
'msbd_adsmp_manage', // ID of menu with which to register this submenu
'Add New', //text to display in browser when selected
'Add New', // the text for this item
$var_manage_authority, // which type of users can see this menu
'msbd_adsmp_add_edit', // unique ID (the slug) for this menu item
array(&$this, 'render_adsmp_add_edit_page') // callback function
);
add_submenu_page(
'msbd_adsmp_manage',
'Settings',
'Settings',
$var_manage_authority,
'msbd_adsmp_settings',
array(&$this, 'render_adsmp_settings_page')
);
add_submenu_page(
'msbd_adsmp_manage',
'Instructions',
'Instructions',
$var_view_authority,
'msbd_adsmp_instructions',
array(&$this, 'render_adsmp_instructions_page')
);
}
function load_admin_scripts_styles() {
wp_enqueue_style( "msbd-adsmp-admin", MSBD_ADSMP_URL . 'css/msbd-adsmp-admin.css', false, false );
wp_enqueue_script( "msbd-adsm-admin-script", MSBD_ADSMP_URL ."js/msbd-adsm-admin-script.js", "jquery", false, true);
}
function wrap_admin_page($page = null) {
$page_header = '';
switch($page) {
case 'main':
$page_header = $this->parent->plugin_name.' Dashboard';
break;
case 'add_edit':
$page_header = $this->parent->plugin_name.' Form';
break;
case 'settings':
$page_header = $this->parent->plugin_name.' Settings';
break;
case 'instructions':
$page_header = $this->parent->plugin_name.' Instructions';
break;
}
echo '
';
echo '
'.$page_header.'
';
echo '
';
MsbdAdsMAdminHelper::render_container_open('content-container');
if ($page == 'main') {
MsbdAdsMAdminHelper::render_postbox_open('Dashboard');
echo $this->render_adsmp_manage_page(TRUE);
MsbdAdsMAdminHelper::render_postbox_close();
}
if ($page == 'add_edit') {
MsbdAdsMAdminHelper::render_postbox_open('Add/Edit Form');
echo $this->render_adsmp_add_edit_page(TRUE);
MsbdAdsMAdminHelper::render_postbox_close();
}
if ($page == 'settings') {
MsbdAdsMAdminHelper::render_postbox_open('Settings');
echo $this->render_adsmp_settings_page(TRUE);
MsbdAdsMAdminHelper::render_postbox_close();
}
if ($page == 'instructions') {
MsbdAdsMAdminHelper::render_postbox_open('Instructions');
echo $this->render_adsmp_instructions_page(TRUE);
MsbdAdsMAdminHelper::render_postbox_close();
}
MsbdAdsMAdminHelper::render_container_close();
MsbdAdsMAdminHelper::render_container_open('sidebar-container');
MsbdAdsMAdminHelper::render_sidebar();
MsbdAdsMAdminHelper::render_container_close();
echo '
'; /* .adsmp-body-content */
echo '
'; /* .wrap msbd-adsmp */
}
function render_adsmp_manage_page($wrapped = false) {
if (!$wrapped) {
$this->wrap_admin_page('main');
return;
}
require_once('msbd-adsm-admin-tables.php');
$adsmp_table = new Msbd_Adsm_Table();
$adsmp_table->prepare_items('all');
echo '';
}
function render_adsmp_add_edit_page($wrapped) {
if (!$wrapped) {
$this->wrap_admin_page('add_edit');
return;
}
$var_manage_authority = $this->parent->adsmp_options['msbd_adsmp_manage_authority'];
if (!current_user_can($var_manage_authority)) {
wp_die( __('You do not have sufficient permissions to access this page.') );
}
$view = new MsbdAdsAdminAddEdit($this->parent);
}
function render_adsmp_settings_page($wrapped = false) {
$options = $this->parent->msbd_adsmp_options_obj->get_option();
if (!$wrapped) {
$this->wrap_admin_page('settings');
return;
}
//Check User Permission
$var_manage_authority = $this->parent->adsmp_options['msbd_adsmp_manage_authority'];
if (!current_user_can($var_manage_authority)) {
wp_die( __('You do not have sufficient permissions to access this page.') );
}
?>
wrap_admin_page('instructions');
return;
}
$output = '
Currently we are peoviding only a single shortcode [manage_adv] to to show advertisement on diffenent place where shortcode tag is allowed by wordpress.
Supported attributes for [manage_adv] shortcode are:
- width : number (default 468)
- height : number (default 60)
- size : string (default banner)
- sponsor : enum value as adsense, amazon (default adsense)
- type : enum value as mix, image, text (default mix)
- wrap_class : text as style class (default empty)
width & height combination or only size should use to detect ad size. If width & height combination are provided then the size parameter will be ignored!
Few examles: the following examples are same. because of the default value set by the plugin.
[manage_adv]
[manage_adv width="468" height="60" sponsor="adsense" type="mix"]
[manage_adv size="banner" sponsor="adsense" type="mix"]
';
echo $output;
}
function add_plugin_settings_link($links) {
$settings_link = 'Settings';
array_unshift($links, $settings_link);
return $links;
}
function get_option($opt_name = '') {
$options = get_option($this->parent->fp_admin_options);
// maybe return the whole options array?
if ($opt_name == '') {
return $options;
}
// are the options already set at all?
if ($options == FALSE) {
return $options;
}
// the options are set, let's see if the specific one exists
if (! isset($options[$opt_name])) {
return FALSE;
}
// the options are set, that specific option exists. return it
return $options[$opt_name];
}
function update_option($opt_name, $opt_val = '') {
// allow a function override where we just use a key/val array
if (is_array($opt_name) && $opt_val == '') {
foreach ($opt_name as $real_opt_name => $real_opt_value) {
$this->update_option($real_opt_name, $real_opt_value);
}
} else {
$current_options = $this->get_option();
// make sure we at least start with blank options
if ($current_options == FALSE) {
$current_options = array();
}
$new_option = array($opt_name => $opt_val);
update_option($this->parent->fp_admin_options, array_merge($current_options, $new_option));
}
}
}
/* end of file msbd-adsm-admin.php */