Permalink
Browse files

Initial commit.

  • Loading branch information...
0 parents commit 5f4fac8afa2f22d132f02c6a82b8455be1226c69 Phill Kenoyer committed Mar 7, 2011
Showing with 138 additions and 0 deletions.
  1. +138 −0 snapengage.php
@@ -0,0 +1,138 @@
+<?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()
+{
+ $options = array(
+ 'button_type' => 0,
+ 'position' => 0,
+ 'offset' => '55',
+ 'offset_units' => '%',
+ );
+
+ foreach ( $options as $k => $v )
+ {
+ update_option($k, $v);
+ }
+}
+
+/**
+ * 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
+}
+
+/**
+ * Javascripts (Load in footer)
+ */
+function snap_javascripts() {
+ wp_enqueue_script('snapengage', 'http://www.snapengage.com/snapabug.js', false, null, true);
+}
+
+/**
+ * Footer script
+ */
+function snapengage_footer_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', 'snap_javascripts', 20);
+ add_action('wp_footer', 'snapengage_footer_js', 30);
+}

0 comments on commit 5f4fac8

Please sign in to comment.