File: /home/dreamlan/public_html/wp-content/plugins/dreamland-nepal/admin/class-dreamland-nepal-admin.php
<?php
class Dreamland_Nepal_Admin {
/**
* The ID of this plugin.
*
* @since 1.0.0
* @access private
* @var string $plugin_name The ID of this plugin.
*/
private $plugin_name;
/**
* The version of this plugin.
*
* @since 1.0.0
* @access private
* @var string $version The current version of this plugin.
*/
private $version;
/**
* Initialize the class and set its properties.
*
* @since 1.0.0
* @param string $plugin_name The name of this plugin.
* @param string $version The version of this plugin.
*/
public function __construct( $plugin_name, $version ) {
$this->plugin_name = $plugin_name;
$this->version = $version;
add_action( 'admin_menu', array($this, 'addMenu') );
add_action('wp_ajax_your_delete_action', array($this,'delete_row'));
add_action( 'wp_ajax_nopriv_your_delete_action', array($this, 'delete_row'));
add_action('wp_ajax_your_json_action', array($this,'createJson'));
add_action( 'wp_ajax_nopriv_your_json_action', array($this, 'createJson'));
add_action('wp_ajax_insert_into_post',array($this,'post_creator'));
add_action('wp_ajax_nopriv_insert_into_post',array($this,'post_creator'));
add_action('wp_ajax_bulk_Import_Excel',array($this,'ImporterBulk'));
add_action('wp_ajax_nopriv_bulk_Import_Excel',array($this,'ImporterBulk'));
add_shortcode( 'njengah_contact_form', array($this,'map_shortcode'));
add_action('init',array($this,'custom_post_DreamlandNepalPost'));
add_action('rest_api_init', function () {
register_rest_route( 'w1/v1', 'dreamland-nepals/(?P<id>\d+)',array(
'methods' => 'GET',
'callback' => array($this,'get_wardss'),
'permission_callback' => function() { return ''; }
));
});
}
function ImporterBulk(){
$file = $_POST['file_url'];
global $wpdb;
$goodtogo = true;
$post_content = '';
$table_name = $wpdb->prefix . $_POST['table_name'];
require_once plugin_dir_path( dirname(__FILE__) ) . 'includes/SimpleXLSX.php';
if ( $xlsx = SimpleXLSX::parseData( file_get_contents($file) ) ) {
// if ( $xlsx = SimpleXLSX::parse($file) ) {
ob_start();
foreach($xlsx->rows() as $index=>$value){
switch($_POST['table_name']){
case 'province_table':
$post_content = $value[6];
case 'district_table':
$post_content = $value[5];
case 'municipality_table':
$post_content = $value[6];
case 'ward_table':
$goodtogo = false;
default:
break;
}
// Add Product
if($goodtogo){
$new_post = array(
'post_title' => wp_strip_all_tags( $value[0]),
'post_author' => 1,
'post_content' => $post_content,
'post_content_filtered' => '',
'post_excerpt' => '',
'post_status' => 'publish',
'post_type' => 'dreamlandnepalposts',
'comment_status' => '',
'supports' => array( 'thumbnail','title', 'editor' ),
'ping_status' => '',
'post_password' => '',
'to_ping' => '',
'pinged' => '',
'post_parent' => 0,
'menu_order' => 0,
'guid' => '',
'import_id' => 0,
'context' => '',
);
// Catch post ID
$pid = wp_insert_post( $new_post,false);
}
switch($_POST['table_name']){
case 'province_table':
$temp = array(
'name' => $value[0],
'nepali' => $value[1],
'coordinate' => $value[2],
'latitude' => $value[3],
'longitude' => $value[4],
'color' => $value[5],
'content' => $pid
);
$wpdb->insert($table_name, $temp);
case 'district_table':
$temp = array(
'name' => $value[0],
'nepali' => $value[1],
'coordinate' => $value[2],
'province' => $value[3],
'province_id' => $value[4],
'content' => $pid
);
$wpdb->insert($table_name, $temp);
case 'municipality_table':
$temp = array(
'name' => $value[0],
'nepali' => $value[1],
'type' => $value[2],
'coordinate' => $value[3],
'district' => $value[4],
'district_id' => $value[5],
'content' => $pid
);
$wpdb->insert($table_name, $temp);
case 'ward_table':
$temp = array(
'No' => $value[0],
'name' => $value[1],
'nepali' => $value[2],
'population' => $value[3],
'area' => $value[4],
'municipality' => $value[5],
'municipality_id' => $value[6]
);
$wpdb->insert($table_name, $temp);
default:
break;
}
}
ob_end_clean();
echo "done";
} else {
echo SimpleXLSX::parseError();
}
die();
}
function post_creator(){
global $wpdb;
$post_title = $_POST['post_name'];
$post_id = $_POST['post_id'];
$table_name = $_POST['table'];
// Add Product
$new_post = array(
'post_title' => wp_strip_all_tags( $post_title),
'post_author' => 1,
'post_content' => 'test',
'post_content_filtered' => '',
'post_excerpt' => '',
'post_status' => 'publish',
'post_type' => 'dreamlandnepalposts',
'comment_status' => '',
'supports' => array( 'thumbnail','title', 'editor'),
'ping_status' => '',
'post_password' => '',
'to_ping' => '',
'pinged' => '',
'post_parent' => 0,
'menu_order' => 0,
'guid' => '',
'import_id' => 0,
'context' => '',
);
// Catch post ID
$pid = wp_insert_post( $new_post,false);
ob_start();
$wpdb->update($table_name, array("content"=>$pid) ,array('id'=>$post_id));
ob_end_clean();
echo $pid;
die();
// if (is_wp_error($post_id))
// {
// $errors = $post_id->get_error_messages();
// return $errors;
// }
// return $wp_error;
}
function custom_post_DreamlandNepalPost() {
$labels = array(
'name' => _x( 'DreamlandNepalPosts', 'Post Type General Name', '' ),
'singular_name' => _x( 'DreamlandNepalPost', 'Post Type Singular Name', '' ),
'menu_name' => __( 'DreamlandNepalPosts', '' ),
'parent_item_colon' => __( 'Parent DreamlandNepalPost', '' ),
'all_items' => __( 'All DreamlandNepalPosts', '' ),
'view_item' => __( 'View DreamlandNepalPost', '' ),
'add_new_item' => __( 'Add New DreamlandNepalPost', '' ),
'add_new' => __( 'Add New', '' ),
'edit_item' => __( 'Edit DreamlandNepalPost', '' ),
'update_item' => __( 'Update DreamlandNepalPost', '' ),
'search_items' => __( 'Search DreamlandNepalPost', '' ),
'not_found' => __( 'Not Found', '' ),
'not_found_in_trash' => __( 'Not found in Trash', '' ),
);
// Set other options for Custom Post Type
$args = array(
'label' => __( 'DreamlandNepalPosts', '' ),
'description' => __( 'DreamlandNepalPost news and reviews', '' ),
'labels' => $labels,
// Features this CPT supports in Post Editor
'supports' => array( 'title', 'editor', 'content' ),
// You can associate this CPT with a taxonomy or custom taxonomy.
'taxonomies' => array( 'genres' ),
/* A hierarchical CPT is like Pages and can have
* Parent and child items. A non-hierarchical CPT
* is like Posts.
*/
'hierarchical' => false,
'supports' => array( 'thumbnail', 'title', 'editor' ),
'public' => true,
'show_ui' => true,
'show_in_menu' => false,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
'show_in_rest' => true,
);
// Registering your Custom Post Type
register_post_type( 'DreamlandNepalPosts', $args );
}
function get_wardss($data){
$plugin_dir = ABSPATH . 'wp-content/plugins/dreamland-nepal/';
require_once $plugin_dir .'admin/partials/helpers/db.php';
return getWardsfromId(intval($data['id']));
// require_once plugin_dir_path( dirname(__FILE__) ) . 'admin/partials/helpers/api.php';
}
/**
* Register the stylesheets for the admin area.
*
* @since 1.0.0
*/
public function enqueue_styles() {
/**
* This function is provided for demonstration purposes only.
*
* An instance of this class should be passed to the run() function
* defined in Dreamland_Nepal_Loader as all of the hooks are defined
* in that particular class.
*
* The Dreamland_Nepal_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/dreamland-nepal-admin.css', array(), $this->version, 'all' );
}
/**
* Register the JavaScript for the admin area.
*
* @since 1.0.0
*/
public function enqueue_scripts() {
/**
* This function is provided for demonstration purposes only.
*
* An instance of this class should be passed to the run() function
* defined in Dreamland_Nepal_Loader as all of the hooks are defined
* in that particular class.
*
* The Dreamland_Nepal_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
if ( ! did_action( 'wp_enqueue_media' ) ) {
wp_enqueue_media();
}
wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/dreamland-nepal-admin.js', array( 'jquery' ), $this->version, false );
}
function delete_row() {
$id = explode('_', $_POST['element_id']);
$table_name = $_POST['table_name'];
if (wp_verify_nonce($id[2], $id[0] . '_' . $id[1])) {
global $wpdb;
$table = $wpdb->prefix . $table_name;
$wpdb->delete( $table, array( 'id' => $id[1] ) );
echo 'Deleted post';
die;
} else {
echo 'Nonce not verified';
die;
}
}
function map_shortcode(){
?>
<div id="mapBigwapper" class="tredt">
<div id="mapid"></div>
<div id="mapid-content">
<div class="fire-close">
<span></span>
<span></span>
</div>
<div class="mapid-content-inner">
</div>
</div>
<div id="mapinner-content">
<div class="fire-close">
<span></span>
<span></span>
</div>
<div class="inner-content-box">
<div class="nasc-loader-wrapper">
<div class="nasc-loader"></div>
</div>
<div class="inner-content-box-inner"></div>
</div>
</div>
</div>
<?php
}
function createJson(){
require_once plugin_dir_path( dirname(__FILE__) ) . 'admin/partials/helpers/jsoncreateor.php';
}
/* Hook into the 'init' action so that the function
* Containing our post type registration is not
* unnecessarily executed.
*/
public function addMenu() {
add_menu_page("Dreamland Nepal", "Dreamland Nepal", "edit_posts",
"dreamlandnepal", array($this,"displayPage"), null, 1);
add_submenu_page(
'dreamlandnepal',
'All Provinces',
'All Provinces',
'manage_options',
'dreamlandnepal/provinces',
array($this, 'displayPageProvince')
);
add_submenu_page(
'dreamlandnepal',
'Add Province',
'Add Province',
'manage_options',
'dreamlandnepal/province/add',
array($this,'addPageProvince')
);
//adding for district
add_submenu_page(
'dreamlandnepal',
'All Districts',
'All Districts',
'manage_options',
'dreamlandnepal/districts',
array($this, 'displayPageDistrict')
);
add_submenu_page(
'dreamlandnepal',
'Add District',
'Add District',
'manage_options',
'dreamlandnepal/district/add',
array($this,'addPageDistrict')
);
//adding for municipality
add_submenu_page(
'dreamlandnepal',
'All Municiplaity',
'All Municipality',
'manage_options',
'dreamlandnepal/municipalities',
array($this, 'displayPageMunicipality')
);
add_submenu_page(
'dreamlandnepal',
'Add Municiplaity',
'Add Municipality',
'manage_options',
'dreamlandnepal/municipality/add',
array($this,'addPageMunicipality')
);
//adding for ward
add_submenu_page(
'dreamlandnepal',
'All Wards',
'All Wards',
'manage_options',
'dreamlandnepal/wards',
array($this, 'displayPageWard')
);
add_submenu_page(
'dreamlandnepal',
'Add Ward',
'Add Ward',
'manage_options',
'dreamlandnepal/ward/add',
array($this,'addPageWard')
);
}
public function displayPage(){
require_once plugin_dir_path( dirname(__FILE__) ) . 'admin/partials/display_top_menu.php';
}
public function displayPageProvince(){
require_once plugin_dir_path( dirname(__FILE__) ) . 'admin/partials/display_province.php';
}
public function addPageProvince(){
require_once plugin_dir_path( dirname(__FILE__) ) .'admin/partials/add_province.php';
}
public function displayPageDistrict(){
require_once plugin_dir_path( dirname(__FILE__) ) . 'admin/partials/display_district.php';
}
public function addPageDistrict(){
require_once plugin_dir_path( dirname(__FILE__) ) .'admin/partials/add_district.php';
}
public function displayPageMunicipality(){
require_once plugin_dir_path( dirname(__FILE__) ) . 'admin/partials/display_municipality.php';
}
public function addPageMunicipality(){
require_once plugin_dir_path( dirname(__FILE__) ) .'admin/partials/add_municipality.php';
}
public function displayPageWard(){
require_once plugin_dir_path( dirname(__FILE__) ) . 'admin/partials/display_ward.php';
}
public function addPageWard(){
require_once plugin_dir_path( dirname(__FILE__) ) .'admin/partials/add_ward.php';
}
}