Skip to content
Browse files

first

  • Loading branch information...
0 parents commit 5cf3e3752c0dc6555f4e525b61eb81c073af0c6a @mrclay committed Jan 27, 2012
Showing with 85 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +1 −0 README.md
  3. +26 −0 actions/quiet_deprecation/settings/save.php
  4. +11 −0 manifest.xml
  5. +25 −0 start.php
  6. +20 −0 views/default/plugins/quiet_deprecation/settings.php
2 .gitignore
@@ -0,0 +1,2 @@
+.DS_Store
+.idea/
1 README.md
@@ -0,0 +1 @@
+Note: Name this folder "quiet_deprecation" inside your Elgg mod folder.
26 actions/quiet_deprecation/settings/save.php
@@ -0,0 +1,26 @@
+<?php
+
+$plugin = elgg_get_plugin_from_id('quiet_deprecation');
+/* @var ElggPlugin $plugin */
+$plugin_name = $plugin->getManifest()->getName();
+$params = get_input('params');
+$members = get_input('members');
+
+$user_whitelist_guids = '';
+if (is_array($members) && $members) {
+ $user_whitelist_guids = implode(',', $members);
+}
+$plugin->setSetting('user_whitelist_guids', $user_whitelist_guids);
+
+// whatever else gets passed as params
+foreach ($params as $k => $v) {
+ $result = $plugin->setSetting($k, $v);
+ if (!$result) {
+ register_error(elgg_echo('plugins:settings:save:fail', array($plugin_name)));
+ forward(REFERER);
+ exit;
+ }
+}
+
+system_message(elgg_echo('plugins:settings:save:ok', array($plugin_name)));
+forward(REFERER);
11 manifest.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<plugin_manifest xmlns="http://www.elgg.org/plugin_manifest/1.8">
+ <name>Quiet Deprecation</name>
+ <author>Steve Clay</author>
+ <version>1.0</version>
+ <description>Allows admins to set a whitelist of users that will see deprecation notices. The notices still occur for all admins (in 1.8.3+), but are stripped from the rendered view with regexp.</description>
+ <requires>
+ <type>elgg_version</type>
+ <version>2011032200</version>
+ </requires>
+</plugin_manifest>
25 start.php
@@ -0,0 +1,25 @@
+<?php
+
+elgg_register_event_handler('init', 'system', 'quiet_deprecation_init');
+
+function quiet_deprecation_init() {
+ if (elgg_is_admin_logged_in()) {
+ elgg_register_plugin_hook_handler('view', 'page/default', '_quiet_deprecation_alter_views');
+ elgg_register_plugin_hook_handler('view', 'page/admin', '_quiet_deprecation_alter_views');
+ }
+
+ elgg_register_action('quiet_deprecation/settings/save', __DIR__ . '/actions/quiet_deprecation/settings/save.php');
+}
+
+function _quiet_deprecation_alter_views($hook, $type, $returnValue, $params) {
+ if ($params['viewtype'] !== 'default') {
+ return $returnValue;
+ }
+ $haystack = ',' . elgg_get_plugin_setting('user_whitelist_guids', 'quiet_deprecation') . ',';
+ $needle = "," . elgg_get_logged_in_user_guid() . ",";
+ if (false === strpos($haystack, $needle)) {
+ // strip notices
+ $returnValue = preg_replace('@<pre>Deprecated in \\d[^<]+</pre>@', '', $returnValue);
+ }
+ return $returnValue;
+}
20 views/default/plugins/quiet_deprecation/settings.php
@@ -0,0 +1,20 @@
+<?php
+
+$plugin = $vars['entity'];
+/* @var ElggPlugin $plugin */
+
+$user_whitelist_guids = $plugin->getSetting('user_whitelist_guids');
+if ($user_whitelist_guids) {
+ $user_whitelist_guids = explode(',', $user_whitelist_guids);
+} else {
+ $user_whitelist_guids = array();
+}
+
+$plus = elgg_is_active_plugin('userpicker_plus') ? '_plus' : '';
+$input = elgg_view("input/userpicker$plus", array(
+ 'value' => $user_whitelist_guids,
+));
+
+echo "<h4>Whitelist</h4>";
+echo "<p>Deprecation notices will only be visible to admins in this list:</p>";
+echo "<div style='border:1px solid #ccc;padding:1em; margin:1em'>$input</div>";

0 comments on commit 5cf3e37

Please sign in to comment.
Something went wrong with that request. Please try again.