Ejemplo n.º 1
0
/**
 * Add feature/unfeature menu items
 *
 * @param string         $hook   "register"
 * @param string         $type   "menu:entity"
 * @param ElggMenuItem[] $return Menu
 * @param array          $params Hook params
 * @return ElggMenuitem[]
 */
function actions_feature_entity_menu_setup($hook, $type, $return, $params)
{
    $entity = elgg_extract('entity', $params);
    if (!$entity instanceof ElggEntity || !actions_feature_can_feature($entity)) {
        return;
    }
    $featured = $entity->featured || $entity->featured_group == 'yes';
    $return[] = ElggMenuItem::factory(['name' => 'feature', 'text' => elgg_echo("actions:feature"), 'href' => "action/feature?guid={$entity->guid}", 'is_action' => true, 'priority' => 300, 'item_class' => $featured ? 'hidden' : '']);
    $return[] = ElggMenuItem::factory(['name' => 'unfeature', 'text' => elgg_echo("actions:unfeature"), 'href' => "action/unfeature?guid={$entity->guid}", 'is_action' => true, 'priority' => 300, 'item_class' => $featured ? '' : 'hidden']);
    return $return;
}
<?php

$guid = get_input('guid');
$entity = get_entity($guid);
if (!$entity instanceof ElggEntity) {
    register_error(elgg_echo('actions:feature:item_not_found'));
    forward(REFERRER);
}
if (!actions_feature_can_feature($entity)) {
    register_error(elgg_echo('actions:feature:permission_denied'));
    forward(REFERRER);
}
// determine what name to show on success
$display_name = $entity->getDisplayName();
if (!$display_name) {
    $display_name = elgg_echo('actions:feature:item');
}
if (empty($entity->featured) && $entity->featured_group != 'yes') {
    register_error(elgg_echo('actions:unfeature:error', [$display_name]));
    forward(REFERRER);
}
$entity->featured = false;
if ($entity instanceof ElggGroup) {
    // compatibility with the group plugin
    $entity->featured_group = 'no';
}
elgg_trigger_event('unfeatured', $entity->getType(), $entity);
system_message(elgg_echo('actions:unfeature:success', [$display_name]));
forward(REFERRER);