예제 #1
0
/**
 * Flush menu tree cache for root page
 *
 * @param string     $event  the name of the event
 * @param string     $type   the type of the event
 * @param ElggObject $object the object affected
 *
 * @return void
 */
function pages_tools_cache_handler($event, $type, ElggObject $object)
{
    if (!pages_tools_is_valid_page($object)) {
        return;
    }
    $ia = elgg_set_ignore_access(true);
    $root_page = pages_tools_get_root_page($object);
    pages_tools_flush_tree_html_cache($root_page);
    elgg_set_ignore_access($ia);
}
예제 #2
0
function pages_tools_permissions_comment_hook($hook, $type, $return_value, $params)
{
    $result = $return_value;
    if (!empty($params) && is_array($params)) {
        $entity = elgg_extract("entity", $params);
        if (pages_tools_is_valid_page($entity)) {
            if ($entity->allow_comments == "no") {
                $result = false;
            }
        }
    }
    return $result;
}
예제 #3
0
function pages_tools_get_root_page(ElggObject $entity)
{
    $result = false;
    if (pages_tools_is_valid_page($entity)) {
        if (elgg_instanceof($entity, "object", "page_top")) {
            $result = $entity;
        } elseif (isset($entity->parent_guid)) {
            $parent = get_entity($entity->parent_guid);
            $result = pages_tools_get_root_page($parent);
        }
    }
    return $result;
}
예제 #4
0
/**
 * Get the children selector options for the edit form
 *
 * @param ElggEntity $entity              the page entity to get the children options for
 * @param int        $current_entity_guid the current edited page GUID
 * @param int        $depth               depth of the tree
 *
 * @return array
 */
function pages_tools_get_parent_selector_children(ElggEntity $entity, $current_entity_guid, $depth = 0)
{
    if (!pages_tools_is_valid_page($entity)) {
        return array();
    }
    $current_entity_guid = sanitise_int($current_entity_guid, false);
    $children = pages_tools_get_ordered_children($entity);
    if (empty($children)) {
        return array();
    }
    $result = array();
    foreach ($children as $child) {
        if ($child->getGUID() === $current_entity_guid) {
            continue;
        }
        $result[$child->getGUID()] = str_repeat('-', $depth + 1) . ' ' . $child->title;
        $result += pages_tools_get_parent_selector_children($child, $current_entity_guid, $depth + 1);
    }
    return $result;
}
예제 #5
0
<?php

/**
 * Export a page (and subpages) to PDF
 */
$guid = (int) get_input("guid");
$format = strtolower(get_input("format", "a4"));
$font = get_input("font", "times");
$include_subpages = (int) get_input("include_children");
$include_index = (int) get_input("include_index");
if (empty($guid)) {
    register_error(elgg_echo("InvalidParameterException:MissingParameter"));
    forward(REFERER);
}
$page = get_entity($guid);
if (!pages_tools_is_valid_page($page)) {
    register_error(elgg_echo("InvalidParameterException:GUIDNotFound", array($guid)));
    forward(REFERER);
}
// this could take a while
set_time_limit(0);
// begin of output
$html = "";
// make index
if (!empty($include_index)) {
    $html .= "<h3>" . elgg_echo("pages_tools:export:index") . "</h3>";
    $html .= "<ul>";
    $html .= "<li>" . elgg_view("output/url", array("text" => $page->title, "href" => "#page_" . $page->getGUID(), "title" => $page->title)) . "</li>";
    // include subpages
    if (!empty($include_subpages) && ($sub_index = pages_tools_render_index($page))) {
        $html .= $sub_index;
예제 #6
0
<?php

/**
 * jQuery action to update the timestamp to show someone is editing a page
 */
$guid = (int) get_input("guid");
if (empty($guid)) {
    forward(REFERER);
}
$entity = get_entity($guid);
if (empty($entity) || !$entity->canEdit()) {
    forward(REFERER);
}
if (pages_tools_is_valid_page($entity)) {
    $entity->setPrivateSetting("edit_notice", time());
} else {
    register_error(elgg_echo("ClassException:ClassnameNotClass", array($guid, elgg_echo("item:object:page"))));
}
forward(REFERER);
예제 #7
0
<?php

/**
 * Navigation menu for a user's or a group's pages
 *
 * @uses $vars['page'] Page object if manually setting selected item
 */
$page_guid = (int) get_input("guid");
$page = false;
if (!empty($page_guid)) {
    $page = get_entity($page_guid);
}
$selected_page = elgg_extract("page", $vars, $page);
// do we have a selected page
if (pages_tools_is_valid_page($selected_page)) {
    // make the navigation tree
    if (pages_tools_register_navigation_tree($selected_page)) {
        $title = elgg_echo("pages:navigation");
        $title .= "<span " . elgg_format_attributes(array("class" => "float-alt", "title" => elgg_echo("pages_tools:navigation:tooltip"))) . ">";
        $title .= elgg_view_icon("info");
        $title .= "</span>";
        // get the navigation menu
        $menu = "<div id='pages-tools-navigation' class='hidden'>";
        $menu .= elgg_view_menu("pages_nav", array("class" => "pages-nav", "sort_by" => "priority"));
        $menu .= "</div>";
        $menu .= elgg_view("graphics/ajax_loader", array("hidden" => false));
        // load the correct JS/css
        elgg_load_js("jquery.tree");
        elgg_load_css("jquery.tree");
        // draw everything
        echo elgg_view_module("aside", $title, $menu);
예제 #8
0
<?php

/**
 * jQuery action to reorder the pages in a tree
 */
$parent_guid = (int) get_input("parent_guid");
$order = get_input("order");
if (empty($parent_guid) || empty($order)) {
    register_error(elgg_echo("InvalidParameterException:MissingParameter"));
    forward(REFERER);
}
if (!is_array($order)) {
    $order = array($order);
}
$parent = get_entity($parent_guid);
if (!pages_tools_is_valid_page($parent)) {
    register_error(elgg_echo("InvalidParameterException:GUIDNotFound", array($parent_guid)));
    forward(REFERER);
}
if (!$parent->canEdit()) {
    register_error(elgg_echo("InvalidParameterException:NoEntityFound"));
    forward(REFERER);
}
$options = array("type" => "object", "subtypes" => array("page", "page_top"), "guids" => $order, "limit" => false);
$sub_pages = elgg_get_entities($options);
if (empty($sub_pages)) {
    register_error(elgg_echo("pages_tools:actions:reorder:error:subpages"));
    forward(REFERER);
}
foreach ($sub_pages as $sub_page) {
    $pos = array_search($sub_page->getGUID(), $order) + 1;
예제 #9
0
<?php

$parent_guid = (int) get_input("parent_guid");
$order = get_input("order");
if (!empty($parent_guid) && !empty($order)) {
    if (!is_array($order)) {
        $order = array($order);
    }
    if (($parent = get_entity($parent_guid)) && pages_tools_is_valid_page($parent)) {
        if ($parent->canEdit()) {
            $options = array("guids" => $order, "limit" => false);
            var_dump($options);
            if ($sub_pages = elgg_get_entities($options)) {
                foreach ($sub_pages as $sub_page) {
                    $pos = array_search($sub_page->getGUID(), $order) + 1;
                    $sub_page->order = $pos;
                    $sub_page->parent_guid = $parent->getGUID();
                    $sub_page->save();
                }
                system_message(elgg_echo("pages_tools:actions:reorder:success"));
            } else {
                register_error(elgg_echo("pages_tools:actions:reorder:error:subpages"));
            }
        } else {
            register_error(elgg_echo("InvalidParameterException:NoEntityFound"));
        }
    } else {
        register_error(elgg_echo("InvalidParameterException:GUIDNotFound", array($parent_guid)));
    }
} else {
    register_error(elgg_echo("InvalidParameterException:MissingParameter"));
예제 #10
0
<?php

$guid = (int) get_input("guid");
$format = strtolower(get_input("format", "a4"));
$font = get_input("font", "times");
$include_subpages = (int) get_input("include_children");
$include_index = (int) get_input("include_index");
if (!empty($guid)) {
    if (($page = get_entity($guid)) && pages_tools_is_valid_page($page)) {
        // this could take a while
        set_time_limit(0);
        // begin of output
        $html = "";
        // make index
        if (!empty($include_index)) {
            $html .= "<h3>" . elgg_echo("pages_tools:export:index") . "</h3>";
            $html .= "<ul>";
            $html .= "<li>" . elgg_view("output/url", array("text" => $page->title, "href" => "#page_" . $page->getGUID(), "title" => $page->title)) . "</li>";
            // include subpages
            if (!empty($include_subpages) && ($sub_index = pages_tools_render_index($page))) {
                $html .= $sub_index;
            }
            $html .= "</ul>";
            $html .= "<p style='page-break-after:always;'></p>";
        }
        // print page
        $html .= "<h3>" . elgg_view("output/url", array("text" => $page->title, "href" => false, "name" => "page_" . $page->getgUID())) . "</h3>";
        $html .= elgg_view("output/longtext", array("value" => $page->description));
        $html .= "<p style='page-break-after:always;'></p>";
        // print subpages
        if (!empty($include_subpages) && ($child_pages = pages_tools_render_childpages($page))) {
예제 #11
0
/**
 * (Dis)allow comments
 *
 * @param string $hook         the name of the hook
 * @param string $type         the type of the hook
 * @param bool   $return_value current return value
 * @param array  $params       supplied params
 *
 * @return void|false
 */
function pages_tools_permissions_comment_hook($hook, $type, $return_value, $params)
{
    if (empty($params) || !is_array($params)) {
        return;
    }
    $entity = elgg_extract("entity", $params);
    if (!pages_tools_is_valid_page($entity)) {
        return;
    }
    if ($entity->allow_comments == "no") {
        return false;
    }
}
예제 #12
0
    }
}
// Get guids
$page_guid = (int) get_input("page_guid");
$container_guid = (int) get_input("container_guid");
$parent_guid = (int) get_input("parent_guid");
// allow comments
$allow_comments = get_input("allow_comments", "yes");
elgg_make_sticky_form("page");
if (!$input["title"]) {
    register_error(elgg_echo("pages:error:no_title"));
    forward(REFERER);
}
if (!empty($page_guid)) {
    $page = get_entity($page_guid);
    if (!pages_tools_is_valid_page($page) || !$page->canEdit()) {
        register_error(elgg_echo("pages:error:no_save"));
        forward(REFERER);
    }
    $new_page = false;
} else {
    $page = new ElggObject();
    if ($parent_guid) {
        $page->subtype = "page";
    } else {
        $page->subtype = "page_top";
    }
    $new_page = true;
}
if (sizeof($input) > 0) {
    // don't change access if not an owner/admin