Plugin Directory

Changeset 3083859


Ignore:
Timestamp:
05/09/2024 10:31:57 AM (21 months ago)
Author:
xtoool
Message:

add custom ads

Location:
xtoool-ads-box/trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • xtoool-ads-box/trunk/lib/AdsbxAdmin.php

    r3059542 r3083859  
    1515        add_action('wp_ajax_adsbx_ads_list', [$this, 'adsbx_ads_list']);
    1616        add_action('wp_ajax_adsbx_delete_ads', [$this, 'adsbx_delete_ads']);
     17
     18        add_action('wp_ajax_adsbx_save_custom_ads', [$this, 'adsbx_save_custom_ads']);
     19        add_action('wp_ajax_adsbx_custom_ads_list', [$this, 'adsbx_ads_custom_list']);
     20        add_action('wp_ajax_adsbx_delete_custom_ads', [$this, 'adsbx_delete_custom_ads']);
    1721    }
    1822
     
    146150    }
    147151
     152    public function add_custom_ad(){
     153        $id = intval(sanitize_text_field(isset($_GET['id']) ? $_GET['id'] : 0));
     154        $data = [];
     155        if($id){
     156            $sql = 'select * from ' . $this->obj->db->prefix . 'xtl_custom_ads where id = %d limit 1';
     157            $sql_pre = $this->obj->db->prepare($sql, $id);
     158            $data = $this->obj->db->get_row($sql_pre, ARRAY_A);
     159        }
     160        include_once XTPLB_DIR . '/template/add_custom_ads.php';
     161    }
     162
     163    public function custom_list(){
     164        include_once XTPLB_DIR . '/template/list_custom_ads.php';
     165    }
     166
     167    public function adsbx_delete_custom_ads(){
     168        $code = 0;
     169        $msg = '';
     170        $data = '';
     171        $id = intval(sanitize_text_field($_POST['id']));
     172        if(! $id){
     173            $msg =  __('params error', 'xt-adsbx');
     174            return wp_send_json(
     175                [
     176                    'code'   => $code,
     177                    'msg'  => $msg,
     178                    'data' => $data
     179                ]
     180            );
     181        }
     182        $res = $this->obj->db->delete($this->obj->db->prefix . 'xtl_custom_ads', ['id' => $id]);
     183        if($res !== false){
     184            $code =  1;
     185        }else{
     186            $msg = __('delete failed', 'xt-adsbx');
     187        }
     188        return wp_send_json(
     189            [
     190                'code'   => $code,
     191                'msg'  => $msg,
     192                'data' => $data
     193            ]
     194        );
     195    }
     196
     197    public function adsbx_ads_custom_list(){
     198        $code = 0;
     199        $msg = '';
     200        $data = '';
     201        $where = '';
     202        $keyword = trim(addslashes(sanitize_text_field($_POST['keyword'])));
     203        if($keyword){
     204            $where .= ' and name like "%' . $keyword . '%"';
     205        }
     206
     207        $pre = $this->obj->db->prefix;
     208
     209        $sql_count = 'select count(*) as count from ' . $pre . 'xtl_custom_ads where 1=1 ' . $where;
     210        $count = $this->obj->db->get_var($sql_count);
     211        $sql = 'select * from ' . $pre . 'xtl_custom_ads where 1=1 ' . $where . ' order by id desc';
     212        $list = $this->obj->db->get_results($sql, ARRAY_A);
     213
     214        return wp_send_json(
     215            [
     216                'code'   => $code,
     217                'msg'  => $msg,
     218                'count' => $count,
     219                'data' => $list
     220            ]
     221        );
     222
     223    }
     224
     225    public function xtplb_expanded_alowed_tags() {
     226        $my_allowed = wp_kses_allowed_html( 'post' );
     227        // iframe
     228        $my_allowed['iframe'] = array(
     229            'src'             => array(),
     230            'height'          => array(),
     231            'width'           => array(),
     232            'frameborder'     => array(),
     233            'allowfullscreen' => array(),
     234        );
     235        // form fields - input
     236        $my_allowed['input'] = array(
     237            'class' => array(),
     238            'id'    => array(),
     239            'name'  => array(),
     240            'value' => array(),
     241            'type'  => array(),
     242        );
     243        // select
     244        $my_allowed['select'] = array(
     245            'class'  => array(),
     246            'id'     => array(),
     247            'name'   => array(),
     248            'value'  => array(),
     249            'type'   => array(),
     250        );
     251        // select options
     252        $my_allowed['option'] = array(
     253            'selected' => array(),
     254            'value' => []
     255        );
     256        // style
     257        $my_allowed['style'] = array(
     258            'types' => array(),
     259        );
     260   
     261        return $my_allowed;
     262    }
     263
     264    public function adsbx_save_custom_ads(){
     265        $code = 0;
     266        $msg = '';
     267        $data = '';
     268        $id = intval(sanitize_text_field($_POST['id']));
     269        $name = sanitize_text_field($_POST['name']);
     270        $content = html_entity_decode($_POST['content']);
     271       
     272        $code = uniqid();
     273        $shotcode = '[xt-ads-custom code="' . $code . '"]';
     274        $data = [
     275            'name' => $name,
     276            'content' => $content
     277        ];
     278        $pre = $this->obj->db->prefix;
     279        $user_id = get_current_user_id();
     280        $date = date('Y-m-d H:i:s');
     281        if($id){
     282           
     283            $data['updated_by'] = $user_id;
     284            $data['updated_date'] = $date;
     285            $res = $this->obj->db->update($pre . 'xtl_custom_ads', $data, ['id' => $id]);
     286        }else{
     287            $data['code'] = $code;
     288            $data['shotcode'] = $shotcode;
     289            $data['added_by'] = $user_id;
     290            $data['added_date'] = $date;
     291            $res = $this->obj->db->insert($pre . 'xtl_custom_ads', $data);
     292        }
     293        if($res){
     294            $code = 1;
     295            $msg = 'Save Success';
     296        }
     297
     298        return wp_send_json(
     299            [
     300                'code'   => $code,
     301                'msg'  => $msg,
     302                'data' => ''
     303            ]
     304        );
     305
     306    }
     307
    148308
    149309}
  • xtoool-ads-box/trunk/lib/Shortcode.php

    r3067528 r3083859  
    1313        // [xt-ads-banner id="4444"]
    1414        add_shortcode('xt-ads-banner', [$this, 'showBanner']);
     15        add_shortcode('xt-ads-custom', [$this, 'showCustom']);
     16    }
     17
     18    public function showCustom($attr){
     19        if(! isset($attr['code'])){
     20            return '';
     21        }
     22        $id = $attr['code'];
     23        if(! $id){
     24            return '';
     25        }
     26        $sql = 'select content from ' . $this->obj->db->prefix . 'xtl_custom_ads where `code` = %s limit 1';
     27        $sql_pre = $this->obj->db->prepare($sql, $id);
     28        $temp = $this->obj->db->get_var($sql_pre);
     29        if(! $temp){
     30            return '';
     31        }
     32        ob_start();
     33        echo $temp;
     34        $data = ob_get_clean();
     35        return $data;
    1536    }
    1637
  • xtoool-ads-box/trunk/xtoool-ads-box.php

    r3067528 r3083859  
    4040    private static $instance = null;
    4141    public $db;
    42     const XTPLB_VERSION = '1.0.6';
     42    const XTPLB_VERSION = '1.0.7';
    4343    public $AdsbxAdmin_obj = null;
    4444
     
    6060        add_action( 'upgrader_process_complete', [$this, 'my_upgrate_function'], 10, 2);
    6161
     62        // test hook
     63        // do_action('upgrader_process_complete', null, ['action' => 'update', 'type' => 'plugin', 'plugins' => ['xtoool-ads-box/xtoool-ads-box.php']]);
     64
    6265        $this->_initScript();
    6366
     
    7881        }
    7982
    80         if(self::XTPLB_VERSION == '1.0.2'){
    81             $this->_update_1_0_3();
    82         }
    83 
     83        if($this->_checkUpdate()){
     84            $this->_update_1_0_7();
     85        }
     86
     87    }
     88
     89    private function _checkUpdate(){
     90        if(str_replace('.', '', self::XTPLB_VERSION) <= 107){
     91            return true;
     92        }else{
     93            return false;
     94        }
    8495    }
    8596
     
    104115 
    105116  PRIMARY KEY (`id`)
     117) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;';
     118        $wpdb->query($sql4);
     119    }
     120
     121    private function _update_1_0_7(){
     122        $this->_update_1_0_3();
     123
     124        global $wpdb;
     125        $sql4 = 'CREATE TABLE if not exists `' . $wpdb->prefix . 'xtl_custom_ads` (
     126            `id` int(11) NOT NULL AUTO_INCREMENT,
     127  `name` varchar(255) NOT NULL default "",
     128  `shotcode` varchar(255) NOT NULL default "",
     129  `code` varchar(255) NOT NULL default "",
     130  `content` text default null,
     131  `added_by` int(11) not null default 0,
     132  `added_date` datetime default null,
     133  `updated_by` int(11) not null default 0,
     134  `updated_date` datetime default null,
     135 
     136  PRIMARY KEY (`id`),
     137  unique key(shotcode),
     138  unique key(`code`)
    106139) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;';
    107140        $wpdb->query($sql4);
     
    343376        add_submenu_page( 'product_list', 'products List', 'products List', 'manage_options', 'products_list_show', [&$this, 'productsShowList'] );
    344377        add_submenu_page( 'product_list', 'Add products List', 'Add products list', 'manage_options', 'add_products_list', [&$this, 'addProductsList'] );
     378        add_submenu_page( 'product_list', 'Custom Ad', 'Custom Ad', 'manage_options', 'custom_list', [$this->AdsbxAdmin_obj, 'custom_list'] );
     379        add_submenu_page( 'product_list', 'Add Custom Ad', 'Add Custom Ad', 'manage_options', 'add_custom_ad', [$this->AdsbxAdmin_obj, 'add_custom_ad'] );
    345380    }
    346381
Note: See TracChangeset for help on using the changeset viewer.