Permalink
Browse files

feature(likes): Entities are no longer likable by default

BREAKING CHANGE:
To allow likes on your content you must permit the annotation to be created.
Likes provides a new hook “likes:is_likable” to allow easily registering entities
by type:subtype.

Fixes #5996
  • Loading branch information...
jdalsem authored and mrclay committed Jul 1, 2015
1 parent e50a985 commit cb6ebcc9703ab6c979cff22ca3a6a92025d5eee2
@@ -481,6 +481,15 @@ HTMLawed
**config, htmlawed**
Filter the HTMLawed config array.
+Likes
+-----
+
+**likes:is_likable, <type>:<subtype>**
+ This is called to set the default permissions for whether to display/allow likes on an entity of type
+ ``<type>`` and subtype ``<subtype>``.
+
+ .. note:: The callback ``'Elgg\Values::getTrue'`` is a useful handler for this hook.
+
Members
-------
View
@@ -386,6 +386,18 @@ The following views received ``label`` elements around some of the input fields.
- views/default/forms/admin/plugins/sort.php
- views/default/forms/login.php
+Plugin Likes
+------------
+
+Objects are no longer likable by default. To support liking, you can register a handler to permit the annotation,
+or more simply register for the hook ``["likes:is_likable", "<type>:<subtype>"]`` and return true. E.g.
+
+.. code:: php
+
+ elgg_register_plugin_hook_handler('likes:is_likable', 'object:mysubtype', 'Elgg\Values::getTrue');
+
+Just as before, the ``permissions_check:annotate`` hook is still called and may be used to override default behavior.
+
Plugin Messages
---------------
View
@@ -26,6 +26,8 @@ function _elgg_comments_init() {
elgg_register_page_handler('comment', '_elgg_comments_page_handler');
elgg_register_ajax_view('core/ajax/edit_comment');
+
+ elgg_register_plugin_hook_handler('likes:is_likable', 'object:comment', 'Elgg\Values::getTrue');
}
/**
View
@@ -68,6 +68,9 @@ function blog_init() {
// ecml
elgg_register_plugin_hook_handler('get_views', 'ecml', 'blog_ecml_views_hook');
+
+ // allow to be liked
+ elgg_register_plugin_hook_handler('likes:is_likable', 'object:blog', 'Elgg\Values::getTrue');
}
/**
View
@@ -67,6 +67,9 @@ function bookmarks_init() {
// Groups
add_group_tool_option('bookmarks', elgg_echo('bookmarks:enablebookmarks'), true);
elgg_extend_view('groups/tool_latest', 'bookmarks/group_module');
+
+ // allow to be liked
+ elgg_register_plugin_hook_handler('likes:is_likable', 'object:bookmarks', 'Elgg\Values::getTrue');
}
/**
@@ -61,6 +61,10 @@ function discussion_init() {
// allow ecml in discussion
elgg_register_plugin_hook_handler('get_views', 'ecml', 'discussion_ecml_views_hook');
+
+ // allow to be liked
+ elgg_register_plugin_hook_handler('likes:is_likable', 'object:discussion', 'Elgg\Values::getTrue');
+ elgg_register_plugin_hook_handler('likes:is_likable', 'object:discussion_reply', 'Elgg\Values::getTrue');
}
/**
View
@@ -88,6 +88,9 @@ function file_init() {
elgg_register_menu_item('embed', $item);
elgg_extend_view('theme_sandbox/icons', 'file/theme_sandbox/icons/files');
+
+ // allow to be liked
+ elgg_register_plugin_hook_handler('likes:is_likable', 'object:file', 'Elgg\Values::getTrue');
}
/**
View
@@ -2,6 +2,11 @@
/**
* Likes plugin
*
+ * To make your content likable, use the likes:is_likable hook to register your type:subtype. E.g.
+ *
+ * <code>
+ * elgg_register_plugin_hook_handler('likes:is_likable', 'object:mysubtype', 'Elgg\Values::getTrue');
+ * </code>
*/
elgg_register_event_handler('init', 'system', 'likes_init');
@@ -18,7 +23,8 @@ function likes_init() {
elgg_register_plugin_hook_handler('register', 'menu:river', 'likes_river_menu_setup', 400);
elgg_register_plugin_hook_handler('register', 'menu:entity', 'likes_entity_menu_setup', 400);
elgg_register_plugin_hook_handler('permissions_check', 'annotation', 'likes_permissions_check');
-
+ elgg_register_plugin_hook_handler('permissions_check:annotate', 'all', 'likes_permissions_check_annotate', 0);
+
$actions_base = __DIR__ . '/actions/likes';
elgg_register_action('likes/add', "$actions_base/add.php");
elgg_register_action('likes/delete', "$actions_base/delete.php");
@@ -28,12 +34,12 @@ function likes_init() {
/**
* Only allow annotation owner (or someone who can edit the owner, like an admin) to delete like
- *
+ *
* @param string $hook "permissions_check"
* @param string $type "annotation"
* @param array $return Current value
* @param array $params Hook parameters
- *
+ *
* @return bool
*/
function likes_permissions_check($hook, $type, $return, $params) {
@@ -51,6 +57,34 @@ function likes_permissions_check($hook, $type, $return, $params) {
return $owner->canEdit();
}
+/**
+ * Sets the default for whether to allow liking/viewing likes on an entity
+ *
+ * @param string $hook "permissions_check:annotate"
+ * @param string $type "object"|"user"|"group"|"site"
+ * @param array $return Current value
+ * @param array $params Hook parameters
+ *
+ * @return bool
+ */
+function likes_permissions_check_annotate($hook, $type, $return, $params) {
+ if (elgg_extract('annotation_name', $params) !== 'likes') {
+ return;
+ }
+
+ $user = elgg_extract('user', $params);
+ $entity = elgg_extract('entity', $params);
+
+ if (!$user || !$entity instanceof ElggEntity) {
+ return false;
+ }
+
+ $type = $entity->type;
+ $subtype = $entity->getSubtype();
+
+ return (bool)elgg_trigger_plugin_hook('likes:is_likable', "$type:$subtype", [], false);
+}
+
/**
* Add likes to entity menu at end of the menu
*/
@@ -115,11 +149,6 @@ function likes_river_menu_setup($hook, $type, $return, $params) {
return;
}
- // don't like users #4116
- if ($item->type == "user") {
- return;
- }
-
if ($item->annotation_id != 0) {
return;
}
View
@@ -90,6 +90,10 @@ function pages_init() {
// register ecml views to parse
elgg_register_plugin_hook_handler('get_views', 'ecml', 'pages_ecml_views_hook');
+
+ // allow to be liked
+ elgg_register_plugin_hook_handler('likes:is_likable', 'object:page', 'Elgg\Values::getTrue');
+ elgg_register_plugin_hook_handler('likes:is_likable', 'object:page_top', 'Elgg\Values::getTrue');
}
/**
View
@@ -62,6 +62,9 @@ function thewire_init() {
elgg_register_action("thewire/add", "$action_base/add.php");
elgg_register_action("thewire/delete", "$action_base/delete.php");
+ // allow to be liked
+ elgg_register_plugin_hook_handler('likes:is_likable', 'object:thewire', 'Elgg\Values::getTrue');
+
elgg_register_plugin_hook_handler('unit_test', 'system', 'thewire_test');
elgg_register_event_handler('upgrade', 'system', 'thewire_run_upgrades');

0 comments on commit cb6ebcc

Please sign in to comment.