Пример #1
0
<?php

/**
 * Delete a QuickLinks item
 */
$guid = (int) get_input('guid');
$url = get_input('url');
if (empty($guid) && empty($url)) {
    register_error(elgg_echo('error:missing_data'));
    forward(REFERER);
}
$entity = false;
if (!empty($guid)) {
    $entity = get_entity($guid);
} else {
    $url = htmlspecialchars_decode($url, ENT_QUOTES);
    $entity = quicklinks_check_url($url, true);
}
if (!$entity instanceof QuickLink || !$entity->canEdit()) {
    register_error(elgg_echo('quicklinks:action:delete:error'));
    forward(REFERER);
}
if ($entity->delete()) {
    system_message(elgg_echo('quicklinks:action:delete:success'));
} else {
    register_error(elgg_echo('quicklinks:action:delete:error'));
}
forward(REFERER);
Пример #2
0
/**
 * Get menu items to toggle quicklink
 *
 * @param array $params supplied params, supports
 *  - entity => an ElggEntity to toggle
 *  - title => to create for a random name (url is required)
 *  - url => to create for a random url (title is suggested)
 *
 * @return false|ElggMenuItem
 */
function quicklinks_get_toggle_menu_items($params = [])
{
    if (empty($params) || !is_array($params)) {
        return false;
    }
    $items = [];
    $entity = elgg_extract('entity', $params);
    if ($entity instanceof ElggEntity && $entity->getGUID()) {
        // do it the easy way
        // is linked?
        $linked = quicklinks_check_relationship($entity->getGUID());
        // build menu items
        $items[] = \ElggMenuItem::factory(['name' => 'quicklinks', 'text' => elgg_view_icon('star-empty'), 'href' => "action/quicklinks/toggle?guid={$entity->getGUID()}", 'title' => elgg_echo('quicklinks:menu:entity:title'), 'is_action' => true, 'item_class' => $linked ? 'hidden' : '']);
        $items[] = \ElggMenuItem::factory(['name' => 'quicklinks_remove', 'text' => elgg_view_icon('star-hover'), 'href' => "action/quicklinks/toggle?guid={$entity->getGUID()}", 'title' => elgg_echo('quicklinks:menu:entity:title'), 'is_action' => true, 'item_class' => $linked ? '' : 'hidden']);
        return $items;
    }
    $url = elgg_extract('url', $params);
    if (empty($url)) {
        return false;
    }
    $linked = quicklinks_check_url($url);
    // not linked
    $add_href = elgg_http_add_url_query_elements('action/quicklinks/edit', ['title' => elgg_extract('title', $params), 'url' => $url]);
    $items[] = \ElggMenuItem::factory(['name' => 'quicklinks', 'text' => elgg_view_icon('star-empty'), 'href' => $add_href, 'title' => elgg_echo('quicklinks:menu:entity:title'), 'is_action' => true, 'item_class' => $linked ? 'hidden' : '']);
    // linked
    $remove_href = elgg_http_add_url_query_elements('action/quicklinks/delete', ['url' => $url]);
    $items[] = \ElggMenuItem::factory(['name' => 'quicklinks_remove', 'text' => elgg_view_icon('star-hover'), 'href' => $remove_href, 'title' => elgg_echo('quicklinks:menu:entity:title'), 'is_action' => true, 'item_class' => $linked ? '' : 'hidden']);
    return $items;
}