-
Notifications
You must be signed in to change notification settings - Fork 1
/
snapengage.php
136 lines (129 loc) · 4.49 KB
/
snapengage.php
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
126
127
128
129
130
131
132
133
134
135
136
<?php
/*
Plugin Name: SnapEngage
Plugin URI: http://www.SnapEngage.com/wordpress
Description: Enables SnapEngage on your web site.
Version: 1.0
Author: Phill Kenoyer - Orange Room Software
Author URI: http://www.OrangeRoomSoftware.com/
License: Public Domain
*/
/**
* Initialize Options and Options page
*/
add_action( 'admin_init', 'snapengage_options_init' );
function snapengage_options_init(){
register_setting( 'snapengage_options', 'snapengage' );
}
/**
* Set defaults on activation
*/
register_activation_hook(__FILE__, 'snapengage_defaults');
function snapengage_defaults()
{
$defaults = array(
'api_key' => '',
'button_type' => 0,
'position' => 0,
'offset' => '55',
'offset_units' => '%',
);
update_option( 'snapengage', $defaults );
}
/**
* Add menu item
*/
add_action( 'admin_menu', 'snapengage_options_add_page' );
function snapengage_options_add_page() {
add_options_page(
'SnapEngage Options',
'SnapEngage',
'manage_options',
'snapengage_options',
'snapengage_options_do_page');
}
/**
* Draw the options page
*/
function snapengage_options_do_page() {
?>
<div class="wrap">
<h2>SnapEngage Options</h2>
<form method="post" action="options.php">
<?php settings_fields('snapengage_options'); ?>
<?php $options = get_option('snapengage'); ?>
<table class="form-table">
<tr valign="top"><th scope="row">API Key</th>
<td>
<input type="text" name="snapengage[api_key]" size="55" maxlength="100" value="<?php echo $options['api_key']; ?>" />
</td>
</tr>
<tr><td><br/></td></tr>
<tr valign="top"><th scope="row">Button Type</th>
<td>
<select name="snapengage[button_type]">
<option value='0' <?php selected( $options['button_type'], 0 ); ?>>Default</option>
<option value='1' <?php selected( $options['button_type'], 1 ); ?>>Dynamic Live Chat</option>
<option value='2' <?php selected( $options['button_type'], 2 ); ?>>No Button</option>
</select>
</td>
</tr>
<tr valign="top"><th scope="row">Align button to the</th>
<td>
<select name="snapengage[position]">
<option value='0' <?php selected( $options['position'], 0 ); ?>>Left</option>
<option value='1' <?php selected( $options['position'], 1 ); ?>>Right</option>
<option value='2' <?php selected( $options['position'], 2 ); ?>>Top</option>
<option value='3' <?php selected( $options['position'], 3 ); ?>>Bottom</option>
</select>
</td>
</tr>
<tr valign="top"><th scope="row">With an offset of</th>
<td>
<input type="text" name="snapengage[offset]" size="3" maxlength="5" value="<?php echo $options['offset']; ?>" />
<select name="snapengage[offset_units]">
<option value='%' <?php selected( $options['offset_units'], '%' ); ?>>%</option>
<option value='px' <?php selected( $options['offset_units'], 'px' ); ?>>px</option>
</select> from the top
</td>
</tr>
</table>
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
</p>
</form>
</div>
<?php
}
/**
* Remote Javascript
*/
function snapengage_remote_js() {
$s = 'http://www.snapengage.com'; if ($_SERVER["HTTPS"] == "on") $s = 'https://snapengage.appspot.com';
wp_enqueue_script('snapengage', "$s/snapabug.js", false, null, true);
}
/**
* Footer script
*/
function snapengage_js() {
$snapengage_options = get_option('snapengage');
print "<script type='text/javascript'>";
switch ($snapengage_options['button_type']) {
case 2:
print "SnapABug.init('".$snapengage_options['api_key']."');";
break;
case 1:
print "SnapABug.addButton('".$snapengage_options['api_key']."', '".$snapengage_options['position']."', '".$snapengage_options['offset']."".$snapengage_options['offset_units']."', true);";
break;
case 0:
print "SnapABug.addButton('".$snapengage_options['api_key']."', '".$snapengage_options['position']."', '".$snapengage_options['offset']."".$snapengage_options['offset_units']."');";
}
print "</script>";
}
/**
* When not in Admin load scripts
*/
if (!is_admin()) {
add_action('wp_print_scripts', 'snapengage_remote_js', 20);
add_action('wp_footer', 'snapengage_js', 30);
}