diff options
-rw-r--r-- | README | 8 | ||||
-rw-r--r-- | actions/favorites/add.php | 17 | ||||
-rw-r--r-- | actions/favorites/remove.php | 17 | ||||
-rw-r--r-- | languages/de.php | 21 | ||||
-rw-r--r-- | languages/en.php | 22 | ||||
-rw-r--r-- | languages/es.php | 22 | ||||
-rw-r--r-- | manifest.xml | 18 | ||||
-rw-r--r-- | start.php | 83 | ||||
-rw-r--r-- | views/default/favorites/button.php | 46 | ||||
-rw-r--r-- | views/default/favorites/sidebar.php | 13 | ||||
-rw-r--r-- | views/default/favorites/sidebar/groups.php | 24 | ||||
-rw-r--r-- | views/default/favorites/sidebar/users.php | 13 | ||||
-rw-r--r-- | views/default/favorites/view.php | 15 | ||||
-rw-r--r-- | views/default/js/favorites.php | 55 | ||||
-rwxr-xr-x | views/default/widgets/favorites/content.php | 36 | ||||
-rwxr-xr-x | views/default/widgets/favorites/edit.php | 17 |
16 files changed, 427 insertions, 0 deletions
@@ -0,0 +1,8 @@ +Favorites Plugin +Oct 2012 - occam@lorea.org + +This is a rewrite of the flagged items plugin for elgg 1.7 + +For better compability the database relationship type "flags_content" remains +the same. + diff --git a/actions/favorites/add.php b/actions/favorites/add.php new file mode 100644 index 000000000..bee00c291 --- /dev/null +++ b/actions/favorites/add.php @@ -0,0 +1,17 @@ +<?php + $entity_guid = (int) get_input('guid'); + $user_guid = elgg_get_logged_in_user_guid(); + if (($entity_guid > 0) && + ($user_guid > 0) && + !check_entity_relationship($user_guid ,'flags_content', $entity_guid)) { + if (add_entity_relationship($user_guid ,'flags_content', $entity_guid)) { + // elgg_dump("Notice: Added flag relationship between $user_guid and $entity_guid. ", FALSE, 'NOTICE'); + system_message(elgg_echo('favorites:added')); + } else { + // elgg_dump("Could not add flag / fav relation between $user_guid and $entity_guid.", FALSE, 'WARN'); + register_error(elgg_echo('favorites:addfailed')); + } + } + if (!elgg_is_xhr()) { + forward($_SERVER['HTTP_REFERER']); + } diff --git a/actions/favorites/remove.php b/actions/favorites/remove.php new file mode 100644 index 000000000..1dd771650 --- /dev/null +++ b/actions/favorites/remove.php @@ -0,0 +1,17 @@ +<?php + $entity_guid = (int) get_input('guid'); + $user_guid = elgg_get_logged_in_user_guid(); + if (($entity_guid > 0) && + ($user_guid > 0) && + check_entity_relationship($user_guid ,'flags_content', $entity_guid)) { + if (remove_entity_relationship($user_guid ,'flags_content', $entity_guid)) { + // elgg_dump("Notice: Removed flag relationship between $user_guid and $entity_guid. ", FALSE, 'NOTICE'); + system_message(elgg_echo('favorites:removed')); + } else { + // elgg_dump("Could not add flag / fav relation between $user_guid and $entity_guid.", FALSE, 'WARN'); + register_error(elgg_echo('favorites:removefailed')); + } + } + if (!elgg_is_xhr()) { + forward($_SERVER['HTTP_REFERER']); + } diff --git a/languages/de.php b/languages/de.php new file mode 100644 index 000000000..a82c68eee --- /dev/null +++ b/languages/de.php @@ -0,0 +1,21 @@ +<?php
+/**
+ * Nie wieder Deutschland
+ */
+
+$german = array(
+ 'favorites:items' => 'Favoriten',
+ 'favorites:menu' => 'Favoriten',
+ 'favorites:groups' => 'Gruppen',
+ 'favorites:add' => 'Zu den Favoriten hinzufügen',
+ 'favorites:remove' => 'Aus den Favoriten entfernen',
+ 'favorites:widget:title' => 'Favoriten',
+ 'favorites:widget:description' => 'Auflistung der aktuellen Favoriten',
+ 'favorites:removed' => 'Das Element wurde aus den Favoriten entfernt',
+ 'favorites:removefailed' => 'Das Element konnte nicht aus den Favoriten enfernt werden',
+ 'favorites:added' => 'Das Element wurde zu den Favoriten hinzugefügt',
+ 'favorites:addfailed' => 'Das Element konnte nicht zu den Favoriten hinzugefügt werden',
+ 'favorites:numbertodisplay' => 'Anzahl der Favoriten zur Anzeige'
+);
+
+add_translation("de", $german);
diff --git a/languages/en.php b/languages/en.php new file mode 100644 index 000000000..4acaad130 --- /dev/null +++ b/languages/en.php @@ -0,0 +1,22 @@ +<?php
+/**
+ * English favorites translations
+ */
+
+$english = array(
+ 'favorites:items' => 'Favorites',
+ 'favorites:menu' => 'Favorites',
+ 'favorites:groups' => 'Favorite Groups',
+ 'favorites:users' => 'Favorite Inhabitants',
+ 'favorites:add' => 'Click to mark as Favorite',
+ 'favorites:remove' => 'Click to remove from Favorites',
+ 'favorites:widget:title' => 'Favorites',
+ 'favorites:widget:description' => 'Shows the recent Favorites',
+ 'favorites:removed' => 'Item removed from Favorites',
+ 'favorites:removefailed' => 'Could not remove item from Favorites',
+ 'favorites:added' => 'Item added to Favorites',
+ 'favorites:addfailed' => 'Could not add item to Favorites',
+ 'favorites:numbertodisplay' => 'Select the number of Favorites to display'
+);
+
+add_translation("en",$english);
diff --git a/languages/es.php b/languages/es.php new file mode 100644 index 000000000..9cb0ad486 --- /dev/null +++ b/languages/es.php @@ -0,0 +1,22 @@ +<?php
+/**
+ * Spanish favorites translations
+ */
+
+$es = array(
+ 'favorites:items' => 'Elementos de trabajo',
+ 'favorites:menu' => 'Elementos de trabajo',
+ 'favorites:groups' => 'Grupos Favoritos',
+ 'favorites:users' => 'Habitantes favoritos',
+ 'favorites:add' => 'Clickea para agregar un elemento de trabajo',
+ 'favorites:remove' => 'Clickea para eliminar de los elementos de trabajo',
+ 'favorites:widget:title' => 'Elementos de trabajo',
+ 'favorites:widget:description' => 'Muestra los elementos de trabajo recientes',
+ 'favorites:removed' => 'Elemento eliminado de los elementos de trabajo',
+ 'favorites:removefailed' => 'No se pudo eliminar el elemento de los favoritos',
+ 'favorites:added' => 'Elemento agregado a los elementos de trabajo',
+ 'favorites:addfailed' => 'No se pudo agregar el elemento a los elementos de trabajo',
+ 'favorites:numbertodisplay' => 'Selecciona el número de elementos a mostrar'
+);
+
+add_translation("es", $es);
diff --git a/manifest.xml b/manifest.xml new file mode 100644 index 000000000..cedba4d95 --- /dev/null +++ b/manifest.xml @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="UTF-8"?> +<plugin_manifest xmlns="http://www.elgg.org/plugin_manifest/1.8"> + <name>Favorites</name> + <author>Lorea Faeries</author> + <version>0.1.0</version> + <category>lorea</category> + <description> + Allow to star items and provide a overview of such. + (The plugin formerly known as flagged) + </description> + <website>https://lorea.org/plugins/favorites</website> + <license>GNU Affero General Public License version 3 or later</license> + <requires> + <type>elgg_release</type> + <version>1.8</version> + </requires> + <activate_on_install>true</activate_on_install> +</plugin_manifest> diff --git a/start.php b/start.php new file mode 100644 index 000000000..77b7ff8bc --- /dev/null +++ b/start.php @@ -0,0 +1,83 @@ +<?php +/** + * Elgg Lorea Favorites Plugin + */ + +elgg_register_event_handler('init','system','favorites_init'); + +function favorites_init(){ + + elgg_register_page_handler('favorites','favorites_page_handler'); + elgg_extend_view("js/elgg", "js/favorites"); + elgg_extend_view("page/elements/sidebar", "favorites/sidebar"); + + if ( elgg_is_logged_in() ) { + elgg_register_menu_item( + 'site', + array( + 'name' => 'favorites', + 'text' => elgg_echo('favorites:menu'), + 'href' => "favorites/view/" + ) + ); + } + + $plugin_path = elgg_get_plugins_path(); + + elgg_register_action( + "favorites/add", + $plugin_path . "favorites/actions/favorites/add.php" + ); + + elgg_register_action( + "favorites/remove", + $plugin_path . "favorites/actions/favorites/remove.php" + ); + + elgg_register_plugin_hook_handler( + 'register', + 'menu:entity', + 'favorites_entity_menu_setup' + ); + elgg_register_widget_type( + 'favorites', + elgg_echo('favorites:widget:title'), + elgg_echo('favorites:widget:description') + ); +} + +function favorites_page_handler($page) { + echo elgg_view_page( + elgg_echo("favorites:items"), + elgg_view_layout( + 'one_sidebar', + array( + 'title' => elgg_echo("favorites:items"), + 'content' => elgg_view('favorites/view'), + 'sidebar' => elgg_view('favorites/sidebar'), + ) + ) + ); + return true; +} + +function favorites_entity_menu_setup($hook, $type, $return, $params) { + if (elgg_in_context('widgets')) { + return $return; + } + if ( elgg_is_logged_in() ) { + + $entity = $params['entity']; + + if ($entity instanceof ElggEntity) { + $options = array( + 'name' => 'favorite', + 'text' => elgg_view('favorites/button', array('entity' => $entity)), + 'is_action' => true, + 'is_trusted' => true + ); + $return[] = ElggMenuItem::factory($options); + } + } + return $return; +} diff --git a/views/default/favorites/button.php b/views/default/favorites/button.php new file mode 100644 index 000000000..bc355d595 --- /dev/null +++ b/views/default/favorites/button.php @@ -0,0 +1,46 @@ +<?php +/** + * Elgg Lorea Favorites Plugin + * + * @package ElggFavorites + */ + +if (!isset($vars['entity'])) { + return true; +} + +if (!elgg_is_logged_in()) { + return true; +} + +$fav_entity_guid = $vars['entity']->getGUID(); +$fav_user_guid = elgg_get_logged_in_user_guid(); + +if (!check_entity_relationship($fav_user_guid ,'flags_content', $fav_entity_guid)) { + + $fav_url = elgg_get_site_url() . "action/favorites/add/?guid={$fav_entity_guid}"; + $fav_params = array( + 'href' => $fav_url, + 'text' => elgg_view_icon('star-empty'), + 'title' => elgg_echo('favorites:add'), + 'class' => 'favorites-add', + 'is_action' => true, + 'is_trusted' => true, + ); + $fav_button = elgg_view('output/url', $fav_params); + +} else { + + $fav_url = elgg_get_site_url() . "action/favorites/remove/?guid={$fav_entity_guid}"; + $fav_params = array( + 'href' => $fav_url, + 'text' => elgg_view_icon('star'), + 'title' => elgg_echo('favorites:remove'), + 'class' => 'favorites-remove', + 'is_action' => true, + 'is_trusted' => true, + ); + $fav_button = elgg_view('output/url', $fav_params); +} + +echo $fav_button; diff --git a/views/default/favorites/sidebar.php b/views/default/favorites/sidebar.php new file mode 100644 index 000000000..6e2e94f47 --- /dev/null +++ b/views/default/favorites/sidebar.php @@ -0,0 +1,13 @@ +<?php +if (elgg_is_logged_in()) { + if (elgg_get_context() == 'groups') + { + echo elgg_view("favorites/sidebar/groups", $vars); + + + } + elseif (elgg_get_context() == 'members') { + echo elgg_view('favorites/sidebar/users', $vars); + } +} +?> diff --git a/views/default/favorites/sidebar/groups.php b/views/default/favorites/sidebar/groups.php new file mode 100644 index 000000000..89d21b022 --- /dev/null +++ b/views/default/favorites/sidebar/groups.php @@ -0,0 +1,24 @@ +<?php + +elgg_push_context('widgets'); + +$fav_group_params = array( + 'type' => 'group', + 'relationship_guid' => elgg_get_logged_in_user_guid(), + 'relationship' => 'flags_content', + 'limit' => 0, + 'pagination' => false, + 'list_type' => 'gallery', + 'gallery_class' => 'elgg-gallery-groups', + 'full_view' => false +); + +$fav_group_params['count'] = true; +if(elgg_get_entities_from_relationship($fav_group_params) == 0) { + return true; +} +$fav_group_params['count'] = false; + +$fav_group_body = elgg_list_entities_from_relationship($fav_group_params); + +echo elgg_view_module('aside', elgg_echo('favorites:groups'), $fav_group_body); diff --git a/views/default/favorites/sidebar/users.php b/views/default/favorites/sidebar/users.php new file mode 100644 index 000000000..681a7728f --- /dev/null +++ b/views/default/favorites/sidebar/users.php @@ -0,0 +1,13 @@ +<?php + +$fav_user_body = elgg_list_entities_from_relationship(array( + 'relationship' => 'flags_content', + 'relationship_guid' => elgg_get_logged_in_user_guid(), + 'type' => 'user', + 'list_type' => 'gallery', + 'gallery_class' => 'elgg-gallery-users', + 'pagination' => false, +)); +if ($fav_user_body) { + echo elgg_view_module('aside', elgg_echo('favorites:users'), $fav_user_body); +} diff --git a/views/default/favorites/view.php b/views/default/favorites/view.php new file mode 100644 index 000000000..53e322f39 --- /dev/null +++ b/views/default/favorites/view.php @@ -0,0 +1,15 @@ +<?php + +if (!elgg_is_logged_in()) { + return; +} + +$fav_options = array( + 'type' => 'object', + 'relationship_guid' => elgg_get_logged_in_user_guid(), + 'relationship' => 'flags_content', + 'full_view' => FALSE, + 'view_type_toggle' => FALSE, +); + +echo elgg_list_entities_from_relationship($fav_options); diff --git a/views/default/js/favorites.php b/views/default/js/favorites.php new file mode 100644 index 000000000..cc364f2ed --- /dev/null +++ b/views/default/js/favorites.php @@ -0,0 +1,55 @@ +<?php +/** + * Favorites JS. + */ +?> + +elgg.provide('elgg.favorites'); + +elgg.favorites.init = function() { + $('.elgg-menu-item-favorite .favorites-add').live('click', elgg.favorites.add); + $('.elgg-menu-item-favorite .favorites-remove').live('click', elgg.favorites.remove); +}; + +elgg.favorites.add = function(event) { + event.preventDefault(); + var $link = $(this); + var $actionParam = $link.attr("href").split("/").pop(); + var $postGuid = $link.attr("href").match(/guid=([^&]+)/)[1]; + + elgg.action('favorites/add', { + data: { + guid: $postGuid + }, + success: function(json) { + $link.attr('href', elgg.config.wwwroot + 'action/favorites/remove/' + $actionParam); + $link.attr('class', '.elgg-menu-item-favorite .favorites-remove'); + $link.children('span').attr('class','elgg-icon elgg-icon-star'); + $link.unbind('click'); + $link.click(elgg.favorites.remove); + } + }); +}; + +elgg.favorites.remove = function(event) { + event.preventDefault(); + var $link = $(this); + var $actionParam = $link.attr("href").split("/").pop(); + var $postGuid = $link.attr("href").match(/guid=([^&]+)/)[1]; + + elgg.action('favorites/remove', { + data: { + guid: $postGuid + }, + success: function(json) { + $link.attr("href", elgg.config.wwwroot + 'action/favorites/add/' + $actionParam); + $link.attr('class', '.elgg-menu-item-favorite .favorites-add'); + $link.children('span').attr('class','elgg-icon elgg-icon-star-empty'); + $link.unbind('click'); + $link.click(elgg.favorites.add); + } + }); +}; + +elgg.register_hook_handler('init', 'system', elgg.favorites.init); + diff --git a/views/default/widgets/favorites/content.php b/views/default/widgets/favorites/content.php new file mode 100755 index 000000000..32453b25c --- /dev/null +++ b/views/default/widgets/favorites/content.php @@ -0,0 +1,36 @@ +<?php + +$fav_pages_num = (int) $vars['entity']->pages_num; +if (!$fav_pages_num) { + $fav_pages_num = 4; +} + +$fav_user_guid = elgg_get_page_owner_guid(); +$fav_offset = 0; + +$fav_options = array( + 'relationship_guid' => $fav_user_guid, + 'relationship'=>'flags_content', + 'limit' => $fav_pages_num, + 'full_view' => FALSE, + 'view_type_toggle' => FALSE, + 'pagination' => FALSE, + 'order_by'=>'e.time_updated desc', + 'direction'=>'ASC', + 'offset'=>$fav_offset, + 'type'=>'object' +); + +$fav_entities = elgg_get_entities_from_relationship($fav_options); +$fav_count = elgg_get_entities_from_relationship_count($fav_options); +$fav_title = elgg_view_title(elgg_echo("favorites:items")); + +echo elgg_view_entity_list( + $fav_entities, + $fav_count, + $fav_offset, + $fav_options['limit'], + $fav_options['full_view'], + $fav_options['view_type_toggle'], + $fav_options['pagination'] +); diff --git a/views/default/widgets/favorites/edit.php b/views/default/widgets/favorites/edit.php new file mode 100755 index 000000000..3394f22c2 --- /dev/null +++ b/views/default/widgets/favorites/edit.php @@ -0,0 +1,17 @@ +<?php +if (!isset($vars['entity']->pages_num)) { + $vars['entity']->pages_num = 4; +} + +$params = array( + 'name' => 'params[pages_num]', + 'value' => $vars['entity']->pages_num, + 'options' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), +); +$dropdown = elgg_view('input/dropdown', $params); + +?> +<div> + <?php echo elgg_echo('favorites:numbertodisplay'); ?>: + <?php echo $dropdown; ?> +</div> |