/**
  * Ensures the drop-down list of available responders outputs the correct values.
  *
  * @ticket 121
  */
 public function test_add_team_member_meta_box_datalist_option_value_matches_user_login()
 {
     $post = $this->factory->post->create_and_get();
     $admin = $this->factory->user->create_and_get(array('role' => 'administrator'));
     $user = $this->factory->user->create_and_get(array('role' => 'subscriber'));
     wp_set_current_user($admin->ID);
     WP_Buoy_Team::renderAddTeamMemberMetaBox($post->ID);
     $this->expectOutputRegex('/<option value="' . $user->user_login . '"\\s*\\/>/');
 }
 /**
  * Checks whether a user is allowed to respond to this alert.
  *
  * A user is allowed to respond to an alert if they are listed as
  * a "confirmed" member in one of the teams associated with this
  * alert.
  *
  * @todo
  * Currently, an alert dynamically looks up who is on the
  * teams associated with it. This should be changed so it
  * keeps a snapshotted list of the confirmed team members
  * at the time the alert was created. This will prevent a
  * user from being added to a team (and thus granted access
  * to an alert) *after* the alert has been sent out.
  *
  * @uses WP_Buoy_Team::get_confirmed_members()
  *
  * @param int $user_id
  *
  * @return bool
  */
 public function can_respond($user_id)
 {
     foreach ($this->get_teams() as $team_id) {
         $team = new WP_Buoy_Team($team_id);
         if (in_array($user_id, $team->get_confirmed_members())) {
             return true;
         }
     }
     return false;
 }
    /**
     * Returns the HTML for a Bootstrap Panel of the user's teams.
     *
     * @return string
     */
    public function renderChooseTeamsPanelHtml()
    {
        $teams = $this->get_teams();
        ?>
<div class="panel panel-default">
    <div class="panel-heading" role="tab" id="">
        <h3 class="panel-title">
            <?php 
        esc_html_e('Choose teams', 'buoy');
        ?>
        </h3>
    </div>
    <div class="panel-body">
        <table class="table" summary="<?php 
        esc_attr_e('Your teams with responders', 'buoy');
        ?>
">
            <thead>
                <tr>
                    <th></th>
                    <th><?php 
        esc_html_e('Team name', 'buoy');
        ?>
</th>
                    <th><?php 
        esc_html_e('Responders', 'buoy');
        ?>
</th>
                </tr>
            </thead>
            <tbody>
<?php 
        foreach ($teams as $team_id) {
            $team = new WP_Buoy_Team($team_id);
            if (!$team->has_responder()) {
                continue;
            }
            ?>
                <tr>
                    <td>
                        <input type="checkbox"
                            id="<?php 
            print esc_attr(self::$prefix);
            ?>
_team-<?php 
            print esc_attr($team_id);
            ?>
"
                            name="<?php 
            print esc_attr(self::$prefix);
            ?>
_teams[]"
                            <?php 
            checked($team->is_default());
            ?>
                            value="<?php 
            print esc_attr($team_id);
            ?>
"
                        />
                    </td>
                    <td>
                        <label for="<?php 
            print esc_attr(self::$prefix);
            ?>
_team-<?php 
            print esc_attr($team_id);
            ?>
">
                            <?php 
            print esc_html($team->wp_post->post_title);
            ?>
                        </label>
                    </td>
                    <td>
                        <?php 
            print esc_html(count($team->get_confirmed_members()));
            ?>
                    </td>
                </tr>
<?php 
        }
        ?>
            </tbody>
        </table>
    </div>
</div>
<?php 
    }
 /**
  * Adds a user to teams they were invited to join before they had
  * created an account.
  *
  * @param int $user_id
  *
  * @return void
  */
 public static function checkInvitations($user_id)
 {
     $user = get_userdata($user_id);
     $team_posts = self::getAllTeamPosts();
     foreach ($team_posts as $post) {
         $team = new WP_Buoy_Team($post->ID);
         if (in_array($user->user_email, $team->get_invited_members())) {
             $team->remove_member($user->user_email);
             // removes the invitation
             $team->add_member($user_id, false);
             // then adds the user
         }
     }
 }
 /**
  * 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);
             }
         }
     }
 }
Example #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';
     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();
 }
Example #7
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();
 }
<table class="form-table" summary="">
    <tbody>
        <tr>
            <th>
                <?php 
esc_html_e('Remove team members', 'buoy');
?>
            </th>
            <td>
                <ul>
<?php 
$team = new WP_Buoy_Team($post->ID);
$states = $team->get_members_in_states();
foreach ($states as $state => $users) {
    ?>
                    <li class="<?php 
    print sanitize_html_class($state);
    ?>
"><ul>
<?php 
    foreach ($users as $user_id) {
        if (is_email($user_id)) {
            $display_name = $user_id;
        } else {
            $wp_user = get_userdata($user_id);
            $display_name = $wp_user->display_name;
        }
        ?>
                    <li>
                        <label>
                            <input