cash/ban — pull request #1 by lianglee (2011-12-05 06:02:38+00:00)
Title: Migrate start.php to 1.8

/// Resister Elgg actions
$action_path = "{$CONFIG->pluginspath}ban/actions";
elgg_register_action('ban', "$action_path/ban.php");
elgg_register_action('/admin/user/unban', "$action_path/unban.php");
}

// Ban Page handler
function ban_page_handler($page) {

set_context('admin');
admin_gatekeeper();

switch ($page[0]) {
case "user":
$user = get_user_by_username($page[1]);
$title = sprintf(elgg_echo('ban:add:title'), $user->name);
$content = elgg_view('ban/add', array('user' => $user));
break;
case "list":
$title = elgg_echo('ban:list:title');
$content = elgg_view('ban/list');
break;
}

$content = elgg_view_title($title) . $content;
$body = elgg_view_layout('two_column_left_sidebar', '', $content);
page_draw($title, $body);
}
/**
* Add Ban user hover menu for admins
*
* @param string $hook
* @param string $type
* @param array $menu
* @param array $params
*/
function ban_user_hover_menu($hook, $type, $menu, $params) {
$user = $params['entity'];
$logged_in_user = elgg_get_logged_in_user_entity();

// don't ban admin himself
if ($logged_in_user == $user) {
return $menu;
}

$url = "/ban/user/{$params['entity']->username}/guid";
$menu[] = ElggMenuItem::factory(array(
'name' => 'ban',
'text' => elgg_echo('ban:menu'),
'href' => $url,
'is_action' => true,
'section' => 'admin'
));

return $menu;
}

/**
* Rewrite ban link to use our code
*
* @param string $hook Hook name
* @param string $type Hook type
* @param string $return The current view string
* @param array $params Parameters from elgg_view()
* @return string
*/
function ban_cron() {
global $CONFIG;

elgg_set_ignore_access();

$params = array(
'type' => 'user',
'annotation_names' => array('ban_release'),
'joins' => array("JOIN {$CONFIG->dbprefix}users_entity u on e.guid = u.guid"),
'wheres' => array("u.banned='yes'"),
);

$now = time();
$users = elgg_get_entities_from_annotations($params);

foreach ($users as $user) {
$releases = elgg_get_annotations($user->guid, '', '', 'ban_release', '', 0, 1, 0, 'desc');

foreach ($releases as $release) {
if ($release->value < $now) {
if ($user->unban()) {
$release->delete();
}
}
}
}

elgg_set_ignore_access(false);
}