Anveto Push Notifications

This plugin stores tokens from apps used for push notifications. It creates an api endpoint which your app can send tokens to and also supports a key to make the url unique.

API Url: api/anveto//(udid)

API Url: api/anveto/(udid)

Replace the (udid) portion of the url with the token you wish to store. The token will be stored in the database along with a timestamp.

Currently the app stores all UDIDs in the prefix_anveto_pushnotification table in your wordpress database.

Set a API key)
prefix . 'anveto_pushnotification'; $charset_collate = $wpdb->get_charset_collate(); $sql = "CREATE TABLE $table_name ( id mediumint(9) NOT NULL AUTO_INCREMENT, time TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, token VARCHAR(300) NOT NULL, UNIQUE KEY id (id) ) $charset_collate;"; require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); dbDelta( $sql ); add_option( 'anveto_pushnotification_db_version', $anveto_pushnotification_db_version ); } register_activation_hook( __FILE__, 'anveto_pushnotification_install' ); function anveto_pushnotification_add_query_vars($vars) { $vars[] = 'anveto_push_api'; $vars[] = 'payload'; if (get_option('anveto-notifications-key') !== false && get_option('anveto-notifications-key') != "") { $vars[] = 'key'; } return $vars; } function anveto_pushnotification_add_endpoint(){ //settings_fields('anveto-settingsGroup'); //do_settings_sections('anveto-settingsGroup'); if (get_option('anveto-notifications-key') !== false && get_option('anveto-notifications-key') != "") { add_rewrite_rule('^api/anveto/' . get_option('anveto-notifications-key') . '/?([^/]*)?/?', 'index.php?anveto_push_api=1&key='.get_option('anveto-notifications-key').'&payload=$matches[1]', 'top'); } else { add_rewrite_rule('^api/anveto/?([^/]*)?/?', 'index.php?anveto_push_api=1&payload=$matches[1]', 'top'); } } function anveto_pushnotification_sniff_requests() { global $wp; if (get_option('anveto-notifications-key') !== false && get_option('anveto-notifications-key') != "") { if (isset($wp->query_vars['key']) && $wp->query_vars['key'] == get_option('anveto-notifications-key')) { anveto_pushnotification_handle_request(); exit; } } else { if (isset($wp->query_vars['anveto_push_api'])) { anveto_pushnotification_handle_request(); exit; } } } function anveto_pushnotification_handle_request() { global $wp; global $wpdb; $key = $wp->query_vars['key']; $payload = trim($wp->query_vars['payload']); $table_name = $wpdb->prefix . 'anveto_pushnotification'; $results = $wpdb->get_results($wpdb->prepare("SELECT * FROM $table_name WHERE token='$payload'"), ARRAY_A); if (count($results) == 0) { $wpdb->insert( $table_name, array( 'token' => $payload ) ); $response = array('response' => 'stored'); echo json_encode($response) . "\n"; } else { $response = array('response' => 'exists'); echo json_encode($response) . "\n"; } } add_filter('query_vars', 'anveto_pushnotification_add_query_vars', 0); add_action('parse_request', 'anveto_pushnotification_sniff_requests', 0); add_action('init', 'anveto_pushnotification_add_endpoint', 0);