/**
  * Responds to Ajax POSTs containing new position information of
  * responders/alerter, sends back the location of all of this
  * alert's responders.
  *
  * @global $_POST
  *
  * @todo Should the WP_Buoy_Alert object be responsible for handling
  *       metadata associated with responder location updates? Right
  *       now, this is all just manually updates of postmeta. Not the
  *       best way to this in the long run, methinks.
  *
  * @return void
  */
 public static function handleLocationUpdate()
 {
     check_ajax_referer(self::$prefix . '_incident_nonce', self::$prefix . '_nonce');
     if (isset($_POST['incident_hash'])) {
         $alert = new WP_Buoy_Alert($_POST['incident_hash']);
         if (isset($_POST['pos'])) {
             $alert->set_responder_geo(get_current_user_id(), $_POST['pos']);
             wp_send_json_success($alert->get_incident_state());
         }
     }
     wp_send_json_error();
 }
 /**
  * Retrieves info about this user's last known state associated
  * with an alert that they have responded to.
  *
  * @param int $alert_id
  *
  * @return array
  */
 public function get_incident_response_info($alert_id)
 {
     $alert = new WP_Buoy_Alert($alert_id);
     $r = array('id' => $this->wp_user->ID, 'display_name' => $this->wp_user->display_name, 'avatar_url' => get_avatar_url($this->wp_user->ID, array('size' => 32)), 'geo' => $alert->get_responder_geo($this->wp_user->ID));
     if ($phone = $this->get_phone_number()) {
         $r['call'] = $phone;
     }
     return $r;
 }
 /**
  * Runs whenever an alert is published. Sends notifications to an
  * alerter's response team informing them of the alert.
  *
  * @param int $post_id
  * @param WP_Post $post
  *
  * @return void
  */
 public static function publishAlert($post_id, $post)
 {
     $alert = new WP_Buoy_Alert($post_id);
     $responder_link = admin_url('?page=' . self::$prefix . '_review_alert' . '&' . self::$prefix . '_hash=' . $alert->get_hash());
     $responder_short_link = home_url('?' . self::$prefix . '_alert=' . substr($alert->get_hash(), 0, 8));
     $subject = $post->post_title;
     $alerter = get_userdata($post->post_author);
     $headers = array("From: \"{$alerter->display_name}\" <{$alerter->user_email}>");
     foreach ($alert->get_teams() as $team_id) {
         $team = new WP_Buoy_Team($team_id);
         foreach ($team->get_confirmed_members() as $user_id) {
             $responder = new WP_Buoy_User($user_id);
             // TODO: Write a more descriptive message.
             wp_mail($responder->wp_user->user_email, $subject, $responder_link, $headers);
             $smsemail = $responder->get_sms_email();
             if (!empty($smsemail)) {
                 $sms_max_length = 160;
                 // We need to ensure that SMS notifications fit within the 160 character
                 // limit of SMS transmissions. Since we're using email-to-SMS gateways,
                 // a subject will be wrapped inside of parentheses, making it two chars
                 // longer than whatever its original contents are. Then a space is
                 // inserted between the subject and the message body. The total length
                 // of strlen($subject) + 2 + 1 + strlen($message) must be less than 160.
                 $extra_length = 3;
                 // two parenthesis and a space
                 // but in practice, there seems to be another 7 chars eaten up somewhere?
                 $extra_length += 7;
                 $url_length = strlen($responder_short_link);
                 $full_length = strlen($subject) + $extra_length + $url_length;
                 if ($full_length > $sms_max_length) {
                     // truncate the $subject since the link must be fully included
                     $subject = substr($subject, 0, $sms_max_length - $url_length - $extra_length);
                 }
                 wp_mail($smsemail, $subject, $responder_short_link, $headers);
             }
         }
     }
 }
 /**
  * Renders a chat room.
  *
  * @global $buoy_chat_room
  *
  * @todo Remove this global. Maybe template-ize this a bit better
  *       with actual `load_template()` functions and similar to a
  *       WordPress front-end? That would let theme developers use
  *       their skills to customize the built-in chat room, too.
  *
  * @return void
  */
 public function render()
 {
     global $buoy_chat_room;
     // TODO: This should become a "real" template, but for now, we just
     //       empty the major front-end template hooks so we have a clean
     //       slate from which to define a simple HTML "template."
     remove_all_actions('wp_head');
     remove_all_actions('wp_footer');
     add_action('wp_head', array(__CLASS__, 'renderMetaRefresh'), 10, 2);
     add_action('wp_head', 'wp_print_styles');
     add_action('wp_head', 'wp_print_head_scripts');
     WP_Buoy_Alert::enqueueBootstrapFramework();
     wp_enqueue_style(self::$prefix . '-chat-room', plugins_url('/templates/comments-chat-room.css', __FILE__), array(), null);
     wp_enqueue_script(self::$prefix . '-chat-room', plugins_url('/templates/comments-chat-room.js', __FILE__), array(), null);
     add_filter('body_class', array(__CLASS__, 'filterBodyClass'));
     add_filter('comment_text', array(__CLASS__, 'filterCommentText'), 5);
     // early priority
     require_once dirname(__FILE__) . '/templates/comments-chat-room.php';
     do_action('shutdown');
     exit;
 }
Beispiel #5
0
 /**
  * Loads plugin componentry and calls that component's register()
  * method. Called at the WordPress `init` hook.
  *
  * @uses WP_Buoy_Settings::register()
  * @uses WP_Buoy_Team::register()
  * @uses WP_Buoy_Notification::register()
  * @uses WP_Buoy_User::register()
  * @uses WP_Buoy_Alert::register()
  *
  * @return void
  */
 public static function initialize()
 {
     require_once 'class-buoy-settings.php';
     require_once 'class-buoy-user-settings.php';
     require_once 'class-buoy-team.php';
     require_once 'class-buoy-notification.php';
     require_once 'class-buoy-user.php';
     require_once 'class-buoy-alert.php';
     require_once 'includes/class-wp-screen-help-loader.php';
     WP_Buoy_Settings::register();
     WP_Buoy_Team::register();
     WP_Buoy_Notification::register();
     WP_Buoy_User::register();
     WP_Buoy_Alert::register();
 }
Beispiel #6
0
 /**
  * Loads plugin componentry and calls that component's register()
  * method. Called at the WordPress `init` hook.
  *
  * @uses WP_Buoy_Settings::register()
  * @uses WP_Buoy_Team::register()
  * @uses WP_Buoy_Notification::register()
  * @uses WP_Buoy_User::register()
  * @uses WP_Buoy_Alert::register()
  *
  * @return void
  */
 public static function initialize()
 {
     require_once 'class-buoy-settings.php';
     require_once 'class-buoy-user-settings.php';
     require_once 'class-buoy-team.php';
     require_once 'class-buoy-notification.php';
     require_once 'class-buoy-user.php';
     require_once 'class-buoy-alert.php';
     if (!class_exists('WP_Screen_Help_Loader')) {
         require_once 'includes/vendor/wp-screen-help-loader/class-wp-screen-help-loader.php';
     }
     WP_Buoy_Settings::register();
     WP_Buoy_Team::register();
     WP_Buoy_Notification::register();
     WP_Buoy_User::register();
     WP_Buoy_Alert::register();
 }