Exemplo n.º 1
0
<?php

/**
 * Remove a page
 *
 * Subpages are not deleted but are moved up a level in the tree
 *
 * @package ElggPages
 */
$guid = get_input('guid');
$page = get_entity($guid);
if (pages_is_page($page)) {
    elgg_load_library('elgg:pages');
    // only allow owners and admin to delete
    if (elgg_is_admin_logged_in() || elgg_get_logged_in_user_guid() == $page->getOwnerGuid() || pages_can_delete_page($page)) {
        $container = get_entity($page->container_guid);
        // Bring all child elements forward
        $parent = $page->parent_guid;
        $children = elgg_get_entities_from_metadata(array('metadata_name' => 'parent_guid', 'metadata_value' => $page->getGUID()));
        if ($children) {
            $db_prefix = elgg_get_config('dbprefix');
            $subtype_id = (int) get_subtype_id('object', 'page_top');
            $newentity_cache = is_memcache_available() ? new ElggMemcache('new_entity_cache') : null;
            foreach ($children as $child) {
                if ($parent) {
                    $child->parent_guid = $parent;
                } else {
                    // If no parent, we need to transform $child to a page_top
                    $child_guid = (int) $child->guid;
                    update_data("UPDATE {$db_prefix}entities\n\t\t\t\t\t\tSET subtype = {$subtype_id} WHERE guid = {$child_guid}");
                    elgg_delete_metadata(array('guid' => $child_guid, 'metadata_name' => 'parent_guid'));
Exemplo n.º 2
0
Arquivo: start.php Projeto: elgg/pages
/**
 * Add links/info to entity menu particular to pages plugin
 */
function pages_entity_menu_setup($hook, $type, $return, $params)
{
    if (elgg_in_context('widgets')) {
        return $return;
    }
    elgg_load_library('elgg:pages');
    $entity = $params['entity'];
    $handler = elgg_extract('handler', $params, false);
    if ($handler != 'pages') {
        return $return;
    }
    // remove delete if not owner or admin
    if (!elgg_is_admin_logged_in() && elgg_get_logged_in_user_guid() != $entity->getOwnerGuid() && !pages_can_delete_page($entity)) {
        foreach ($return as $index => $item) {
            if ($item->getName() == 'delete') {
                unset($return[$index]);
            }
        }
    }
    $options = array('name' => 'history', 'text' => elgg_echo('pages:history'), 'href' => "pages/history/{$entity->guid}", 'priority' => 150);
    $return[] = ElggMenuItem::factory($options);
    return $return;
}
Exemplo n.º 3
0
Arquivo: delete.php Projeto: elgg/elgg
<?php

/**
 * Remove a page
 *
 * Subpages are not deleted but are moved up a level in the tree
 *
 * @package ElggPages
 */
$guid = get_input('guid');
$page = get_entity($guid);
/* @var ElggObject $page */
elgg_load_library('elgg:pages');
if (!pages_is_page($page) || !pages_can_delete_page($page)) {
    register_error(elgg_echo('pages:delete:failure'));
    forward(REFERER);
}
$container = $page->getContainerEntity();
// Bring all child elements forward
$parent = $page->parent_guid;
$children = new ElggBatch('elgg_get_entities_from_metadata', ['metadata_name' => 'parent_guid', 'metadata_value' => $page->guid, 'limit' => 0]);
$db_prefix = elgg_get_config('dbprefix');
$subtype_id = (int) get_subtype_id('object', 'page_top');
foreach ($children as $child) {
    if ($parent) {
        $child->parent_guid = $parent;
        continue;
    }
    // If no parent, we need to transform $child to a page_top
    $child_guid = (int) $child->guid;
    update_data("\n\t\tUPDATE {$db_prefix}entities\n\t\tSET subtype = {$subtype_id}\n\t\tWHERE guid = {$child_guid}\n\t");