Ejemplo n.º 1
0
/**
 * make group digest
 * 
 * @param ElggGroup $group
 * @param ElggUser $user
 * @param string $interval
 * @return true (mail sent successfull) || false (some error) || -1 (no content)
 */
function digest_group(ElggGroup $group, ElggUser $user, $interval)
{
    global $SESSION;
    global $interval_ts_upper;
    global $interval_ts_lower;
    global $is_admin;
    static $custom_text_header;
    static $custom_text_footer;
    $result = false;
    // check if group digest is enabled
    if (digest_group_enabled()) {
        if (!empty($group) && elgg_instanceof($group, "group", null, "ElggGroup") && !empty($user) && elgg_instanceof($user, "user", null, "ElggUser")) {
            // remove some view extensions
            digest_prepare_run();
            // set timestamps for interval
            digest_set_interval_timestamps($interval);
            // store current user
            $current_user = elgg_get_logged_in_user_entity();
            // impersonate new user
            $SESSION["user"] = $user;
            $SESSION["username"] = $user->username;
            $SESSION["name"] = $user->name;
            $SESSION["guid"] = $user->getGUID();
            $SESSION["id"] = $user->getGUID();
            // prepare some vars for the different views
            $vars = array("user" => $user, "group" => $group, "ts_lower" => $interval_ts_lower, "ts_upper" => $interval_ts_upper, "interval" => $interval);
            // get data for user
            $userdata = elgg_view("digest/elements/group", $vars);
            if (!empty($userdata)) {
                // check if there are custom header/footer texts
                if (!isset($custom_text_header)) {
                    $custom_text_header = "";
                    if ($text = elgg_get_plugin_setting("custom_text_group_header", "digest")) {
                        $custom_text_header = elgg_view_module("digest", "", "<div class='elgg-output'>" . $text . "</div>");
                    }
                }
                if (!isset($custom_text_footer)) {
                    $custom_text_footer = "";
                    if ($text = elgg_get_plugin_setting("custom_text_group_footer", "digest")) {
                        $custom_text_footer = elgg_view_module("digest", "", "<div class='elgg-output'>" . $text . "</div>");
                    }
                }
                // there is content so send it to the user
                $params = array("title" => elgg_get_site_entity()->name, "content" => $custom_text_header . $userdata . $custom_text_footer, "footer" => elgg_view("digest/elements/footer", $vars), "digest_header" => elgg_view("digest/elements/header", $vars), "digest_online" => elgg_view("digest/elements/online", $vars), "digest_unsubscribe" => elgg_view("digest/elements/unsubscribe", $vars));
                // link to online view
                $digest_online_url = digest_get_online_url($vars);
                // message_subject
                $message_subject = elgg_echo("digest:message:title:group", array(elgg_get_site_entity()->name, $group->name, elgg_echo("digest:interval:" . $interval)));
                // message body
                $message_body = elgg_view_layout("digest", $params);
                // send message
                // if succesfull mail return true
                $result = digest_send_mail($user, $message_subject, $message_body, $digest_online_url);
            } else {
                // no data is still succesful
                $result = -1;
            }
            // save memory
            unset($userdata);
            // restore current user
            $SESSION["user"] = $current_user;
            if (elgg_is_logged_in()) {
                $SESSION["username"] = $current_user->username;
                $SESSION["name"] = $current_user->name;
                $SESSION["guid"] = $current_user->getGUID();
                $SESSION["id"] = $current_user->getGUID();
            } else {
                unset($SESSION["username"]);
                unset($SESSION["name"]);
                unset($SESSION["guid"]);
                unset($SESSION["id"]);
            }
            // save memory
            unset($current_user);
        }
    }
    return $result;
}
Ejemplo n.º 2
0
<?php

/**
 * Show a single digest
 */
gatekeeper();
$ts_lower = (int) get_input("ts_lower");
$ts_upper = (int) get_input("ts_upper");
$interval = get_input("interval");
if (empty($ts_lower) || empty($ts_upper) || empty($interval)) {
    register_error(elgg_echo("digest:show:error:input"));
    forward();
}
// remove some view extensions
digest_prepare_run();
// get group guid
$group_guid = (int) get_input("group_guid");
$vars = array("user" => elgg_get_logged_in_user_entity(), "ts_lower" => $ts_lower, "ts_upper" => $ts_upper, "interval" => $interval);
// check if we need to display a group
if (!empty($group_guid)) {
    $group = get_entity($group_guid);
    if (!empty($group) && elgg_instanceof($group, "group", null, "ElggGroup")) {
        $vars["group"] = $group;
        $content = elgg_view("digest/elements/group", $vars);
    }
}
// did we have a valid group, or display site digest
if (!isset($vars["group"])) {
    $content = elgg_view("digest/elements/site", $vars);
}
if (!empty($content)) {