-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfrontlinesms.php
More file actions
125 lines (101 loc) · 3.62 KB
/
frontlinesms.php
File metadata and controls
125 lines (101 loc) · 3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/*
* Plugin Name: WP-FrontlineSMS
* Plugin URI: https://github.com/pr4ka5a/wp-frontlinesms/
* Description: Plugin for fetch messages from Frontline SMS
* Author: Kaka E. Prakasa
* Version: 0.1
* Author URI: http://pr4ka5a.wordpress.com
*/
?>
<?
function frontlinesms_install()
{
global $wpdb;
$table = $wpdb->prefix."frontlinesms";
$structure = "CREATE TABLE $table (
id INT(9) NOT NULL AUTO_INCREMENT,
FRONTLINE_key VARCHAR(8),
sender_number VARCHAR(15) NOT NULL,
message_content VARCHAR(800),
dt datetime NOT NULL default '0000-00-00',
UNIQUE KEY id (id)
);";
$wpdb->query($structure);
}
register_activation_hook(__FILE__,'frontlinesms_install');
function frontlinesms()
{
include('frontlinesms_admin.php');
}
function frontlinesms_admin_menu()
{
add_options_page('frontlineSMS','frontlineSMS',1,'frontlineSMS','frontlineSMS');
}
add_action('admin_menu', 'frontlinesms_admin_menu');
//to retrieve from message database
function ambil()
{
global $wpdb;
$table = $wpdb->prefix."frontlinesms";
$results = $wpdb->get_results("SELECT sender_number, message_content FROM $table ORDER BY dt DESC LIMIT 5",ARRAY_N);
for($i=1; $i<count($results); $i++)
{
echo $results[$i][0]." --> ".$results[$i][1]."<br>";
}
}
//Widget plugins sidebar
error_reporting(E_ALL);
add_action("widgets_init", array('FrontlineSMS_widget', 'register'));
class FrontlineSMS_widget {
function control(){
echo 'FrontlineSMS Widget control panel';
}
function widget($args){
echo $args['before_widget'];
echo $args['before_title'] . 'SMS Message' . $args['after_title'];
echo ambil();
echo $args['after_widget'];
}
function register(){
register_sidebar_widget('FrontlineSMS Widget', array('FrontlineSMS_widget', 'widget'));
register_widget_control('FrontlineSMS Widget', array('FrontlineSMS_widget', 'control'));
}
}
//Retrieve post from frontlinesms
function frontline_post($args)
{
if (isset($_SERVER['QUERY_STRING']))
{
global $wpdb;
$table = $wpdb->prefix."frontlinesms";
$default = array (
'ss' => '',
'mm' => '',
'kk' => '',
'lewat' => TRUE
);
$dt = date("Y-m-d H:i:s");
//Melewatkan argumen yang datang dan memasukkannya dalam $default
$args = wp_parse_args( $args, $default);
//Mendeklarasikan setiap item pada $args menjadi variabel
extract( $args, EXTR_SKIP);
$frontlinesms_key = $wpdb->get_var($wpdb->prepare("SELECT FRONTLINE_key FROM $table"));
if(!empty($ss) AND !empty($mm) AND !empty($kk))
{
if($kk==$frontlinesms_key){
/*$send = "INSERT INTO $table( FRONTLINE_key, sender_number, message_content, dt) VALUES( '%s', '%d', '%s', $dt)";
$wpdb->query($wpdb->prepare($send, $kk, $ss, $mm));
*/
$wpdb->insert($table, array('FRONTLINE_key' => $kk,
'sender_number' => $ss,
'message_content' => $mm,
'dt' => $dt ));
$wpdb->show_errors();
//echo $kk;
}
}
}
}
frontline_post($_SERVER['QUERY_STRING'])
?>