Пример #1
0
 /**
  * Add a menu option to the page menu of groups
  *
  * @param string          $hook         the name of the hook
  * @param string          $type         the type of the hook
  * @param \ElggMenuItem[] $return_value current return value
  * @param array           $params       supplied params
  *
  * @return void|\ElggMenuItem[]
  */
 public static function pageMenu($hook, $type, $return_value, $params)
 {
     if (!elgg_is_logged_in()) {
         return;
     }
     $page_owner = elgg_get_page_owner_entity();
     if (!$page_owner instanceof \ElggGroup || !elgg_in_context('groups')) {
         return;
     }
     if (!group_tools_group_mail_enabled($page_owner) && !group_tools_group_mail_members_enabled($page_owner)) {
         return;
     }
     $return_value[] = \ElggMenuItem::factory(['name' => 'mail', 'text' => elgg_echo('group_tools:menu:mail'), 'href' => "groups/mail/{$page_owner->getGUID()}"]);
     return $return_value;
 }
Пример #2
0
<?php

/**
 * Mail all the members of a group
 */
$group_guid = (int) get_input('group_guid', 0);
$user_guids = (array) get_input('user_guids');
$subject = get_input('title');
$body = get_input('description');
array_walk($user_guids, 'sanitise_int');
if (empty($group_guid) || empty($body) || empty($user_guids)) {
    register_error(elgg_echo('error:missing_data'));
    forward(REFERER);
}
elgg_entity_gatekeeper($group_guid, 'group');
$group = get_entity($group_guid);
if (!group_tools_group_mail_enabled($group) && !group_tools_group_mail_members_enabled($group)) {
    register_error(elgg_echo('actionunauthorized'));
    forward($group->getURL());
}
$group_mail = new GroupMail();
$group_mail->container_guid = $group_guid;
$group_mail->title = $subject;
$group_mail->description = $body;
$group_mail->setRecipients($user_guids);
$group_mail->enqueue();
system_message(elgg_echo('group_tools:action:mail:success'));
forward($group->getURL());
Пример #3
0
/**
 * Check if group mail is enabled for members
 *
 * @param ElggGroup $group The group to check (can be empty to check plugin setting)
 *
 * @return bool
 */
function group_tools_group_mail_members_enabled(ElggGroup $group = null)
{
    static $mail_members_enabled;
    if (!isset($mail_members_enabled)) {
        $mail_members_enabled = false;
        $setting = elgg_get_plugin_setting('mail_members', 'group_tools');
        if ($setting === 'yes') {
            $mail_members_enabled = true;
        }
    }
    // quick return if mail members is not allowed
    if (!group_tools_group_mail_enabled()) {
        return false;
    }
    if (!$mail_members_enabled) {
        return false;
    }
    if (empty($group) || !$group instanceof ElggGroup) {
        return true;
    }
    if ($group->canEdit()) {
        // group owners and admin can mail
        return true;
    }
    if ($group->isMember() && $group->mail_members_enable === 'yes') {
        return true;
    }
    return false;
}