diff options
-rw-r--r-- | river_privacy/CHANGES.txt | 7 | ||||
-rw-r--r-- | river_privacy/languages/en.php | 13 | ||||
-rw-r--r-- | river_privacy/manifest.xml | 18 | ||||
-rw-r--r-- | river_privacy/start.php | 30 | ||||
-rw-r--r-- | river_privacy/views/default/plugins/river_privacy/settings.php | 17 | ||||
-rw-r--r-- | river_privacy/views_override/default/page/components/list.php | 86 |
6 files changed, 171 insertions, 0 deletions
diff --git a/river_privacy/CHANGES.txt b/river_privacy/CHANGES.txt new file mode 100644 index 000000000..df26e881d --- /dev/null +++ b/river_privacy/CHANGES.txt @@ -0,0 +1,7 @@ +== Version History == + +x.x: + +1.0 (05/19/2012): + +- Initial Release
\ No newline at end of file diff --git a/river_privacy/languages/en.php b/river_privacy/languages/en.php new file mode 100644 index 000000000..f0cfde2a1 --- /dev/null +++ b/river_privacy/languages/en.php @@ -0,0 +1,13 @@ +<?php + +$english = array( + 'river_privacy' => "River Privacy", + 'river_privacy:hide_old:description' => "Only items that are created after this plugin is enabled + will be set to private. This setting can allow old items to be hidden - this is done at + display time, so it may affect layout (eg. 20 items are expected to be shown, but only 15 are + visible because 5 of them are filtered out by this plugin). + Note that new items created will be private regardless of this setting, this setting is only for old items.", + 'river_privacy:hide_old:label' => "Hide old river entries?", +); + +add_translation("en",$english); diff --git a/river_privacy/manifest.xml b/river_privacy/manifest.xml new file mode 100644 index 000000000..36ed40f92 --- /dev/null +++ b/river_privacy/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>River Privacy</name> + <author>Matt Beckett (matt@clever-name.com)</author> + <version>1.0</version> + <description>Sets non-object oriented river items to private access (eg. friend relationships)</description> + <website>http://landing.athabascau.ca</website> + <copyright>(C) Matt Beckett, 2012</copyright> + <license>GNU Public License version 2</license> + + <!-- All plugins must require either elgg_version or elgg_release. --> + <requires> + <type>elgg_release</type> + <version>1.8</version> + </requires> + + <category>Miscellaneous</category> +</plugin_manifest> diff --git a/river_privacy/start.php b/river_privacy/start.php new file mode 100644 index 000000000..b836ded52 --- /dev/null +++ b/river_privacy/start.php @@ -0,0 +1,30 @@ +<?php + +/** + * River Privacy + * Makes non-object oriented river entries private + * eg. friendships + */ + +function river_privacy_init(){ + if(elgg_get_plugin_setting('hide_old_items', 'river_privacy') != 'no'){ + elgg_set_view_location('page/components/list', elgg_get_plugins_path() . 'river_privacy/views_override/'); + } + + // set the river item to private if it's not an object + elgg_register_plugin_hook_handler('creating', 'river', 'river_privacy_creating_river'); +} + + +// +// hook called before river creation +// return associative array of parameters to create the river entry +function river_privacy_creating_river($hook, $type, $returnvalue, $params){ + if($returnvalue['type'] != 'object'){ + $returnvalue['access_id'] = ACCESS_PRIVATE; + } + + return $returnvalue; +} + +elgg_register_event_handler('init', 'system', 'river_privacy_init');
\ No newline at end of file diff --git a/river_privacy/views/default/plugins/river_privacy/settings.php b/river_privacy/views/default/plugins/river_privacy/settings.php new file mode 100644 index 000000000..661416261 --- /dev/null +++ b/river_privacy/views/default/plugins/river_privacy/settings.php @@ -0,0 +1,17 @@ +<?php + +$options = array( + 'name' => 'params[hide_old_items]', + 'value' => $vars['entity']->hide_old_items ? $vars['entity']->hide_old_items : 'yes', + 'options_values' => array( + 'yes' => elgg_echo('option:yes'), + 'no' => elgg_echo('option:no'), + ), +); + +echo elgg_echo('river_privacy:hide_old:label') . "<br>"; +echo elgg_view('input/dropdown', $options); + +echo "<br><br>" . elgg_echo('river_privacy:hide_old:description'); + +echo "<br><br>";
\ No newline at end of file diff --git a/river_privacy/views_override/default/page/components/list.php b/river_privacy/views_override/default/page/components/list.php new file mode 100644 index 000000000..b34c454a6 --- /dev/null +++ b/river_privacy/views_override/default/page/components/list.php @@ -0,0 +1,86 @@ +<?php +/** + * View a list of items + * + * @package Elgg + * + * @uses $vars['items'] Array of ElggEntity or ElggAnnotation objects + * @uses $vars['offset'] Index of the first list item in complete list + * @uses $vars['limit'] Number of items per page + * @uses $vars['count'] Number of items in the complete list + * @uses $vars['base_url'] Base URL of list (optional) + * @uses $vars['pagination'] Show pagination? (default: true) + * @uses $vars['position'] Position of the pagination: before, after, or both + * @uses $vars['full_view'] Show the full view of the items (default: false) + * @uses $vars['list_class'] Additional CSS class for the <ul> element + * @uses $vars['item_class'] Additional CSS class for the <li> elements + */ + +$items = $vars['items']; +$offset = elgg_extract('offset', $vars); +$limit = elgg_extract('limit', $vars); +$count = elgg_extract('count', $vars); +$base_url = elgg_extract('base_url', $vars, ''); +$pagination = elgg_extract('pagination', $vars, true); +$offset_key = elgg_extract('offset_key', $vars, 'offset'); +$position = elgg_extract('position', $vars, 'after'); + +// remove non-object items for anyone who's not the subject +if(is_array($items) && ($items[0] instanceof ElggRiverItem)){ + foreach($items as $key => $item){ + if($item->type != 'object' && $item->subject_guid != elgg_get_logged_in_user_guid()){ + unset($items[$key]); + } + } +} + +// reset key values +$items = array_merge(array(), $items); + +$list_class = 'elgg-list'; +if (isset($vars['list_class'])) { + $list_class = "$list_class {$vars['list_class']}"; +} + +$item_class = 'elgg-item'; +if (isset($vars['item_class'])) { + $item_class = "$item_class {$vars['item_class']}"; +} + +$html = ""; +$nav = ""; + +if ($pagination && $count) { + $nav .= elgg_view('navigation/pagination', array( + 'base_url' => $base_url, + 'offset' => $offset, + 'count' => $count, + 'limit' => $limit, + 'offset_key' => $offset_key, + )); +} + +if (is_array($items) && count($items) > 0) { + $html .= "<ul class=\"$list_class\">"; + foreach ($items as $item) { + if (elgg_instanceof($item)) { + $id = "elgg-{$item->getType()}-{$item->getGUID()}"; + } else { + $id = "item-{$item->getType()}-{$item->id}"; + } + $html .= "<li id=\"$id\" class=\"$item_class\">"; + $html .= elgg_view_list_item($item, $vars); + $html .= '</li>'; + } + $html .= '</ul>'; +} + +if ($position == 'before' || $position == 'both') { + $html = $nav . $html; +} + +if ($position == 'after' || $position == 'both') { + $html .= $nav; +} + +echo $html; |