public function get_api_setting() { self::$apisetting = get_option('smpush_options'); self::$apisetting = array_map('stripslashes', self::$apisetting); }
public function __construct() { parent::__construct(); }
public static function tokens() { global $wpdb; self::load_jsplugins(); $pageurl = admin_url() . 'admin.php?page=smpush_tokens'; $pagname = 'smpush_tokens'; if (!empty($_POST['device_type'])) { if (empty($_POST['device_token'])) { self::jsonPrint(0, 'Field `Device Token` is required.'); } if ($_POST['id'] > 0) { self::$pushdb->query(self::parse_query("UPDATE {tbname} SET {id_name}='{$_POST['id']}',{token_name}='{$_POST['device_token']}',{type_name}='{$_POST['device_type']}',{info_name}='{$_POST['information']}',{active_name}='{$_POST['active']}' WHERE {id_name}='{$_POST['id']}'")); $tokenid = $_POST['id']; } else { self::$pushdb->query(self::parse_query("INSERT INTO {tbname} ({token_name},{type_name},{info_name},{active_name}) VALUES ('{$_POST['device_token']}','{$_POST['device_type']}','{$_POST['information']}','{$_POST['active']}')")); $tokenid = self::$pushdb->insert_id; $wpdb->query("UPDATE " . $wpdb->prefix . "push_connection SET counter=counter+1 WHERE id='" . self::$apisetting['def_connection'] . "'"); } if (!empty($_POST['channels'])) { $_POST['channels'] = implode(',', $_POST['channels']); smpush_api::editSubscribedChannels($tokenid, $_POST['channels']); } echo 1; exit; } elseif (isset($_GET['remove_duplicates'])) { self::$pushdb->query(self::parse_query("CREATE TABLE {tbname_temp} AS SELECT * FROM {tbname} GROUP BY {token_name}")); if (empty(self::$pushdb->last_error)) { self::$pushdb->query(self::parse_query("ALTER TABLE {tbname_temp} ADD PRIMARY KEY({id_name})")); self::$pushdb->query(self::parse_query("ALTER TABLE {tbname_temp} CHANGE {id_name} {id_name} INT(11) NOT NULL AUTO_INCREMENT")); self::$pushdb->query(self::parse_query("ALTER TABLE {tbname_temp} ADD INDEX ({token_name})")); self::$pushdb->query(self::parse_query("DROP TABLE {tbname}")); self::$pushdb->query(self::parse_query("RENAME TABLE {tbname_temp} TO {tbname}")); parent::update_counters(); wp_redirect($pageurl); } else { wp_die('An error has occurred, the system stopped and rolled back the changes.'); } } elseif (isset($_GET['delete'])) { self::$pushdb->query(self::parse_query("DELETE FROM {tbname} WHERE {id_name}='{$_GET['id']}'")); $wpdb->query("DELETE FROM " . $wpdb->prefix . "push_relation WHERE token_id='{$_GET['id']}' AND connection_id='" . self::$apisetting['def_connection'] . "'"); parent::update_counters(); exit; } elseif (isset($_GET['id'])) { $channels = $wpdb->get_results("SELECT id,title FROM " . $wpdb->prefix . "push_channels ORDER BY title ASC"); $types_name = $wpdb->get_row("SELECT ios_name,android_name FROM " . $wpdb->prefix . "push_connection WHERE id='" . self::$apisetting['def_connection'] . "'"); if ($_GET['id'] == -1) { $token = array('id' => 0, 'device_token' => '', 'device_type' => '', 'information' => '', 'channels' => array(), 'active' => 1); } else { $subschannels = $wpdb->get_results("SELECT channel_id FROM " . $wpdb->prefix . "push_relation WHERE token_id='{$_GET['id']}' AND connection_id='" . self::$apisetting['def_connection'] . "'"); $token = self::$pushdb->get_row(self::parse_query("SELECT {id_name} AS id,{token_name} AS device_token,{type_name} AS device_type,{info_name} AS information,{active_name} AS active FROM {tbname} WHERE {id_name}='{$_GET['id']}'"), 'ARRAY_A'); $token = array_map('stripslashes', $token); $token['channels'] = array(); if ($subschannels) { foreach ($subschannels as $subschannel) { $token['channels'][] = $subschannel->channel_id; } } } include smpush_dir . '/pages/token_form.php'; exit; } else { $types_name = $wpdb->get_row("SELECT dbtype,ios_name,android_name FROM " . $wpdb->prefix . "push_connection WHERE id='" . self::$apisetting['def_connection'] . "'"); $channels = $wpdb->get_results("SELECT id,title FROM " . $wpdb->prefix . "push_channels ORDER BY title ASC"); $where = array(); $inner = ''; $order = 'ORDER BY {tbname}.{id_name} DESC'; if (!empty($_GET['query'])) { $where[] = "({tbname}.{token_name}='{$_GET['query']}' OR {tbname}.{info_name} LIKE '%{$_GET['query']}%')"; $order = ''; } if (!empty($_GET['device_type'])) { $where[] = "{tbname}.{type_name}='{$_GET['device_type']}'"; } else { $_GET['device_type'] = ''; } if (!empty($_GET['status'])) { if ($_GET['status'] == 2) { $status = 0; } else { $status = 1; } $where[] = "{tbname}.{active_name}='{$status}'"; } else { $_GET['status'] = '-1'; } if (!empty($_GET['channel_id'])) { $table = $wpdb->prefix . 'push_relation'; $inner = "INNER JOIN {$table} ON({$table}.token_id={tbname}.{id_name} AND {$table}.connection_id='" . self::$apisetting['def_connection'] . "')"; $where[] = "{$table}.channel_id='{$_GET['channel_id']}'"; $order = 'GROUP BY {tbname}.{id_name} DESC'; } else { $_GET['channel_id'] = ''; } if (count($where) > 0) { $where = 'WHERE ' . implode(' AND ', $where); } else { $where = ''; } if (!empty($_GET['apply'])) { if (!empty($_GET['doaction'])) { $doaction = $_GET['doaction']; } elseif (!empty($_GET['doaction2'])) { $doaction = $_GET['doaction2']; } $ids = implode(',', $_GET['device']); if ($doaction == 'activate') { self::$pushdb->query(self::parse_query("UPDATE {tbname} SET {active_name}='1' WHERE {id_name} IN({$ids})")); } elseif ($doaction == 'deactivate') { self::$pushdb->query(self::parse_query("UPDATE {tbname} SET {active_name}='0' WHERE {id_name} IN({$ids})")); } elseif ($doaction == 'delete') { self::$pushdb->query(self::parse_query("DELETE FROM {tbname} WHERE {id_name} IN({$ids})")); $wpdb->query("DELETE FROM " . $wpdb->prefix . "push_relation WHERE token_id IN({$ids}) AND connection_id='" . self::$apisetting['def_connection'] . "'"); parent::update_counters(); } wp_redirect($pageurl); } elseif (!empty($_GET['applytoall'])) { if (!empty($_GET['doaction'])) { $doaction = $_GET['doaction']; } elseif (!empty($_GET['doaction2'])) { $doaction = $_GET['doaction2']; } $tokens = self::$pushdb->get_results(self::parse_query("SELECT {tbname}.{id_name} AS id FROM {tbname} {$inner} {$where} GROUP BY {tbname}.{id_name}")); if ($tokens) { foreach ($tokens as $token) { if ($doaction == 'activate') { self::$pushdb->query(self::parse_query("UPDATE {tbname} SET {active_name}='1' WHERE {id_name}='" . $token->id . "'")); } elseif ($doaction == 'deactivate') { self::$pushdb->query(self::parse_query("UPDATE {tbname} SET {active_name}='0' WHERE {id_name}='" . $token->id . "'")); } elseif ($doaction == 'delete') { self::$pushdb->query(self::parse_query("DELETE FROM {tbname} WHERE {id_name}='" . $token->id . "'")); $wpdb->query("DELETE FROM " . $wpdb->prefix . "push_relation WHERE token_id='" . $token->id . "' AND connection_id='" . self::$apisetting['def_connection'] . "'"); parent::update_counters(); } } } wp_redirect($pageurl); } $sql = self::Paging(self::parse_query("SELECT {tbname}.{id_name} AS id,{tbname}.{token_name} AS device_token,{tbname}.{type_name} AS device_type\r\n ,{tbname}.{info_name} AS information,{tbname}.{active_name} AS active FROM {tbname} {$inner} {$where} {$order}"), self::$pushdb); $tokens = self::$pushdb->get_results($sql); $paging_args = array('base' => preg_replace('/&?callpage=([0-9]+)/', '', $_SERVER['REQUEST_URI']) . '%_%', 'format' => '&callpage=%#%', 'total' => self::$paging['pages'], 'current' => self::$paging['page'], 'show_all' => false, 'end_size' => 3, 'mid_size' => 2, 'prev_next' => true, 'prev_text' => __('« Previous'), 'next_text' => __('Next »')); include smpush_dir . '/pages/token_manage.php'; } }