/** * Checks if a user can subscribe to a content item * * @param ElggEntity $entity the entity to check * @param int $user_guid the user to check (default: current user) * * @return bool */ function content_subscriptions_can_subscribe(ElggEntity $entity, $user_guid = 0) { $user_guid = sanitise_int($user_guid, false); if (empty($user_guid)) { $user_guid = elgg_get_logged_in_user_guid(); } if (empty($user_guid) || !$entity instanceof ElggEntity) { return false; } if ($entity->getOwnerGUID() === $user_guid) { // owner cant subscribe to own content return false; } $supported_entity_types = content_subscriptions_get_supported_entity_types(); if (empty($supported_entity_types)) { return false; } $type = $entity->getType(); if (!isset($supported_entity_types[$type])) { return false; } $subtype = $entity->getSubtype(); if (!empty($subtype)) { return in_array($subtype, $supported_entity_types[$type]); } return true; }
/** * Checks if a user can subscribe to a content item * * @param ElggEntity $entity the entity to check * @param int $user_guid the user to check (default: current user) * * @return bool */ function content_subscriptions_can_subscribe(ElggEntity $entity, $user_guid = 0) { $result = false; $user_guid = sanitise_int($user_guid, false); if (empty($user_guid)) { $user_guid = elgg_get_logged_in_user_guid(); } if (!empty($user_guid) && !empty($entity) && elgg_instanceof($entity)) { if ($entity->getOwnerGUID() != $user_guid) { $supported_entity_types = content_subscriptions_get_supported_entity_types(); if (!empty($supported_entity_types)) { $type = $entity->getType(); if (isset($supported_entity_types[$type])) { $subtype = $entity->getSubtype(); if (!empty($subtype)) { $result = in_array($subtype, $supported_entity_types[$type]); } else { $result = true; } } } } } return $result; }