Skip to content

Commit

Permalink
chore(customizations): Merge in community_customizations
Browse files Browse the repository at this point in the history
There's no good reason for this plugin to live a separate life.
It just adds overhead.
  • Loading branch information
ewinslow committed Aug 5, 2015
1 parent 28d6c98 commit 18e8fe2
Show file tree
Hide file tree
Showing 11 changed files with 347 additions and 74 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Features
========

* Turns a message board widget into a send a private message widget. Spammers
were leaving messages on their message boards and we would rather have
public conversation occur in the forums
* Forcing sizes on avatars since Twitter avatars do not fit our desired sizes
* Delete private messages sent from deleted users
* Add APC cache flush button to admin control panel widget
* Filter out friending and new bookmarks from the river
13 changes: 13 additions & 0 deletions actions/admin/flush_apc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
/**
* Flush the APC opcode cache
*/

if (function_exists('apc_clear_cache')) {
if (apc_clear_cache('opcode')) {
system_message(elgg_echo('apc:flush:success'));
forward(REFERER);
}
}

register_error(elgg_echo('apc:flush:fail'));
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"brettp/elgg-registration-randomizer": "dev-no-mysql-2.0",
"brettp/stale_users": "dev-master",
"elgg/ban": "dev-master",
"elgg/community_customizations": "dev-master",
"elgg/community_groups": "dev-master",
"elgg/community_plugins": "dev-master",
"elgg/community_solr": "dev-master",
Expand Down
48 changes: 5 additions & 43 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions languages/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,22 @@
// Must use longer array format for Transifex to work
return array(
'menus:site:items:home:label' => "Home",

'customizations:widget:pm' => 'Send private message',
'customizations:widget:pm:desc' => 'Enables users to send private messages to you from your profile',
'customizations:pm:logged_out' => 'You must be logged in to send a private message.',
'customizations:pm:subject' => 'Message from %s',

'pages:welcomemessage' => 'Welcome to the pages tool of %s. Use this tool for creating documentation related to Elgg.
If you are looking for help, please post in the
<a href="http://community.elgg.org/pg/groups/179063/elgg-technical-support/">technical support group</a>.
If you are looking for the main Elgg documentation page, go to <a href="http://docs.elgg.org/">our wiki</a>.',

'apc:flush:success' => 'APC opcode cache flushed',
'apc:flush:fail' => 'Failed to flush APC opcode cache',
'apc:flush' => 'Flush APC',
'messages:fly' => "Send Message",
'customizations:comments:disable:fix' => "There are %s enabled comments in the system with containers that are disabled. %s",
'customizations:comments:fix' => 'Fix comments',
'customizations:comments:fixed' => "Comments have been fixed",
);
117 changes: 87 additions & 30 deletions start.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
<?php
namespace Elgg\Www;

elgg_register_event_handler('init', 'system', __NAMESPACE__ . '\init');

function init() {
elgg_register_plugin_hook_handler('container_permissions_check', 'object', __NAMESPACE__ . '\only_admins_can_post_blogs');
elgg_register_event_handler('init', 'system', function() {
// Only admins can post blogs
elgg_register_plugin_hook_handler('container_permissions_check', 'object', function($hook, $type, $return, $params) {
if ($params['subtype'] == 'blog') {
return $params['user']->isAdmin();
}
});

elgg_register_plugin_hook_handler('register', 'menu:title', __NAMESPACE__ . '\remove_discussion_add_button');
// Remove the duplicate add button for dicussions
elgg_register_plugin_hook_handler('register', 'menu:title', function($hook, $type, $menu) {
if (elgg_get_context() == 'discussion') {
foreach ($menu as $index => $item) {
if ($item->getName() == 'add') {
unset($menu[$index]);
}
}
}
return $menu;
});

// Support for some very old URLs
elgg_register_page_handler('requirements.php', function() {
http_response_code(301);
forward('http://learn.elgg.org/en/latest/intro/install.html#requirements');
Expand All @@ -22,31 +35,75 @@ function init() {
http_response_code(301);
forward('http://learn.elgg.org/en/latest/intro/license.html');
});
}

function only_admins_can_post_blogs($hook, $type, $return, $params) {
if ($params['subtype'] == 'blog') {
return $params['user']->isAdmin();
elgg_register_css('widgets/messageboard/content', elgg_get_simplecache_url('widgets/messageboard/content.css'));
if (function_exists("elgg_ws_unexpose_function")) {
elgg_ws_unexpose_function('auth.gettoken');
}
}

/**
* Remove the duplicate add button for dicussions
*
* @param string $hook Hook name
* @param string $type Hook type
* @param array $menu Array of ElggMenuItem objects
*
* @return array
*/
function remove_discussion_add_button($hook, $type, $menu) {
if (elgg_get_context() == 'discussion') {
foreach ($menu as $index => $item) {
if ($item->getName() == 'add') {
unset($menu[$index]);

// filter new friendships and new bookmarks from river
elgg_register_plugin_hook_handler('creating', 'river', function($hook, $type, $item) {
$view = $item['view'];
switch ($view) {
case 'river/relationship/friend/create':
case 'river/object/bookmarks/create':
return false;
break;
}
});

// Delete messages from a user who is being deleted
// TODO(ewinslow): Move to Elgg core??
elgg_register_event_handler('delete', 'user', function($event, $type, $user) {

// make sure we delete them all
$entity_disable_override = access_get_show_hidden_status();
access_show_hidden_entities(true);

$messages = elgg_get_entities_from_metadata(array(
'type' => 'object',
'subtype' => 'messages',
'metadata_name' => 'fromId',
'metadata_value' => $user->getGUID(),
'limit' => 0,
));

if ($messages) {
foreach ($messages as $e) {
$e->delete();
}
}
}
return $menu;
}

access_show_hidden_entities($entity_disable_override);
});

// convert messageboard to private message interface
elgg_register_widget_type('messageboard', elgg_echo("customizations:widget:pm"), elgg_echo("customizations:widget:pm:desc"), array("profile"));

// Forward to referrer if posting PM from a widget
elgg_register_plugin_hook_handler('forward', 'system', function() {
if (get_input('pm_widget') == true) {
return $_SERVER['HTTP_REFERER'];
}
});

// do not want the pages link in hover menu
elgg_unextend_view('profile/menu/links', 'pages/menu');

// button for flushing apc cache
elgg_register_plugin_hook_handler('register', 'menu:admin_control_panel', function($hook, $type, $menu, $params) {
$options = array(
'name' => 'flush_apc',
'text' => elgg_echo('apc:flush'),
'href' => 'action/admin/flush_apc',
'is_action' => true,
'link_class' => 'elgg-button elgg-button-action',
);
$menu[] = ElggMenuItem::factory($options);
return $menu;
});

$actions = __DIR__ . "/actions";
elgg_register_action('admin/flush_apc', "$actions/admin/flush_apc.php", 'admin');
});
58 changes: 58 additions & 0 deletions views/default/discussion/replies.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
/**
* List replies with optional add form
*
* @mod If not showing the form because they can't reply, show a message why.
*
* @uses $vars['entity'] ElggEntity
* @uses $vars['show_add_form'] Display add form or not
*/

$show_add_form = elgg_extract('show_add_form', $vars, true);
$topic = elgg_extract('topic', $vars);

echo '<div id="group-replies" class="mtl">';

$replies = elgg_list_entities(array(
'type' => 'object',
'subtype' => 'discussion_reply',
'container_guid' => $topic->getGUID(),
'reverse_order_by' => true,
));

if ($replies) {
echo '<h3>' . elgg_echo('group:replies') . '</h3>';
echo $replies;
}

if ($show_add_form) {
$form_vars = array('class' => 'mtm');
echo elgg_view_form('discussion/reply/save', $form_vars, $vars);
} elseif ($topic->status != 'closed') {
$group = $topic->getContainerEntity();

// if not a member
if (!elgg_is_logged_in()) {
$log_in = elgg_view('output/url', array(
'href' => '/login',
'text' => 'log in'
));

echo "<div class=\"elgg-box elgg-state-notice\">";
echo "You must $log_in to post replies.";
echo "</div>";
} elseif (!$group->isMember()) {
// @todo override action to redirect back to thread.
$url = current_page_url();
$join_group = elgg_view('output/confirmlink', array(
'href' => '/action/groups/join?group_guid=' . $group->getGUID(),
'text' => 'join this group',
'confirm' => 'Join this group?'
));
echo "<div class=\"elgg-box elgg-state-notice\">";
echo "You must $join_group to post replies.";
echo "</div>";
}
}

echo '</div>';
Loading

0 comments on commit 18e8fe2

Please sign in to comment.