Esempio n. 1
0
function rijkshuisstijl_create_object_handler($event, $type, ElggObject $object)
{
    if (empty($object)) {
        return;
    }
    if (!elgg_is_active_plugin("content_subscriptions")) {
        return;
    }
    if (!elgg_instanceof($object, "object", "question")) {
        return;
    }
    $user = elgg_get_logged_in_user_entity();
    if (!$user) {
        return;
    }
    content_subscriptions_subscribe($object->guid, $user->guid);
}
Esempio n. 2
0
    $users = elgg_get_entities_from_relationship($options);
    foreach ($users as $user) {
        $error_counter = 0;
        $subscription_options = array("relationship" => CONTENT_SUBSCRIPTIONS_SUBSCRIPTION, "relationship_guid" => $user->getGUID(), "limit" => false);
        $batch = new ElggBatch("elgg_get_entities_from_relationship", $subscription_options);
        $batch->setIncrementOffset(false);
        foreach ($batch as $entity) {
            // for some reason you can't subscribe
            if (!content_subscriptions_can_subscribe($entity, $user->getGUID())) {
                if (!remove_entity_relationship($user->getGUID(), CONTENT_SUBSCRIPTIONS_SUBSCRIPTION, $entity->getGUID())) {
                    $error_counter++;
                }
                continue;
            }
            // subscribe the new way
            content_subscriptions_subscribe($entity->getGUID(), $user->getGUID());
            // remove old link
            if (!remove_entity_relationship($user->getGUID(), CONTENT_SUBSCRIPTIONS_SUBSCRIPTION, $entity->getGUID())) {
                $error_counter++;
            }
        }
        if ($error_counter > 0) {
            $error_count++;
        } else {
            $success_count++;
        }
    }
}
access_show_hidden_entities($access_status);
// replace events and hooks
_elgg_services()->events = $original_events;
/**
 * Automaticly subscribe to the updates of an entity if the user didn't block this
 *
 * @param int $entity_guid the content entity to subscribe to
 * @param int $user_guid   the user to subscribe (defaults to current user)
 *
 * @return bool
 */
function content_subscriptions_autosubscribe($entity_guid, $user_guid = 0)
{
    $result = false;
    $entity_guid = sanitise_int($entity_guid, false);
    $user_guid = sanitise_int($user_guid, false);
    if (empty($user_guid)) {
        $user_guid = elgg_get_logged_in_user_guid();
    }
    // check if the user blocked the subscription
    if (!content_subscriptions_check_block_subscription($entity_guid, $user_guid)) {
        $entity = get_entity($entity_guid);
        // check if this is not the content owner
        if ($entity->getOwnerGUID() != $user_guid) {
            // no, so subscribe
            $result = content_subscriptions_subscribe($entity_guid, $user_guid);
        }
    }
    return $result;
}