function file_tools_init() { // extend CSS elgg_extend_view("css/elgg", "file_tools/css/site"); if (file_tools_use_folder_structure()) { elgg_extend_view("groups/edit", "file_tools/group_settings"); } // extend js elgg_extend_view("js/elgg", "file_tools/js/site"); // register JS libraries $vendors = elgg_get_site_url() . "mod/file_tools/vendors/"; elgg_register_js("jquery.tree", $vendors . "jstree/jquery.tree.min.js"); elgg_register_css("jquery.tree", $vendors . "jstree/themes/default/style.css"); elgg_register_js("jquery.hashchange", $vendors . "hashchange/jquery.hashchange.js"); // register page handler for nice URL's elgg_register_page_handler("file_tools", "file_tools_page_handler"); // make our own URLs for folders elgg_register_entity_url_handler("object", "file", "file_tools_url_handler"); elgg_register_entity_url_handler("object", FILE_TOOLS_SUBTYPE, "file_tools_folder_url_handler"); // make our own URLs for folder icons elgg_register_plugin_hook_handler("entity:icon:url", "object", "file_tools_folder_icon_hook"); // register group option to allow management of file tree structure add_group_tool_option("file_tools_structure_management", elgg_echo("file_tools:group_tool_option:structure_management")); // register group option to allow group members to overwrite all their files add_group_tool_option("file_tools_file_management", elgg_echo("file_tools:group_tool_option:file_management"), false); // register widgets // add folder widget // need to keep file_tree for the widget name to be compatible with previous filetree plugin users elgg_register_widget_type("file_tree", elgg_echo("widgets:file_tree:title"), elgg_echo("widgets:file_tree:description"), "dashboard,profile,groups", true); // group files elgg_register_widget_type("group_files", elgg_echo("file:group"), elgg_echo("widgets:group_files:description"), "groups"); // index files elgg_register_widget_type("index_file", elgg_echo("file"), elgg_echo("widgets:index_file:description"), "index", true); // register events elgg_register_event_handler("create", "object", "file_tools_object_handler"); elgg_register_event_handler("update", "object", "file_tools_object_handler"); elgg_register_event_handler("delete", "object", "file_tools_object_handler_delete"); elgg_register_event_handler("upgrade", "system", "file_tools_upgrade_handler"); // register hooks elgg_register_plugin_hook_handler("register", "menu:entity", "file_tools_entity_menu_hook"); elgg_register_plugin_hook_handler("permissions_check", "object", "file_tools_can_edit_metadata_hook"); elgg_register_plugin_hook_handler("route", "file", "file_tools_file_route_hook"); elgg_register_plugin_hook_handler("widget_url", "widget_manager", "file_tools_widget_url_hook"); elgg_register_plugin_hook_handler("register", "menu:file_tools_folder_breadcrumb", "file_tools_folder_breadcrumb_hook"); elgg_register_plugin_hook_handler("register", "menu:file_tools_folder_sidebar_tree", "file_tools_folder_sidebar_tree_hook"); // register actions elgg_register_action("file_tools/folder/edit", dirname(__FILE__) . "/actions/folder/edit.php"); elgg_register_action("file_tools/folder/delete", dirname(__FILE__) . "/actions/folder/delete.php"); elgg_register_action("file_tools/folder/reorder", dirname(__FILE__) . "/actions/folder/reorder.php"); elgg_register_action("file_tools/folder/delete", dirname(__FILE__) . "/actions/folder/delete.php"); elgg_register_action("file_tools/file/hide", dirname(__FILE__) . "/actions/file/hide.php"); elgg_register_action("file_tools/file/upload", dirname(__FILE__) . "/actions/file/upload.php"); elgg_register_action("file_tools/file/delete", dirname(__FILE__) . "/actions/file/delete.php"); elgg_register_action("file/move", dirname(__FILE__) . "/actions/file/move.php"); elgg_register_action("file/bulk_delete", dirname(__FILE__) . "/actions/file/bulk_delete.php"); elgg_register_action("file_tools/groups/save_sort", dirname(__FILE__) . "/actions/groups/save_sort.php"); }
/** * Add the folder management option to groups (if enabled) * * @param string $hook the name of the hook * @param string $type the type of the hook * @param array $return_value current return value * @param arary $params supplied params * * @return void|array */ public static function tools($hook, $type, $return_value, $params) { if (!file_tools_use_folder_structure()) { return; } $folder_management = new \stdClass(); $folder_management->name = 'file_tools_structure_management'; $folder_management->label = elgg_echo('file_tools:group_tool_option:structure_management'); $folder_management->default_on = true; $return_value[] = $folder_management; return $return_value; }
function file_tools_file_route_hook($hook, $type, $returnvalue, $params) { $result = $returnvalue; if (!empty($returnvalue) && is_array($returnvalue)) { $page = elgg_extract("segments", $returnvalue); switch ($page[0]) { case "view": if (!elgg_is_logged_in() && isset($page[1])) { if (!get_entity($page[1])) { gatekeeper(); } } break; case "owner": if (file_tools_use_folder_structure()) { $result = false; include dirname(dirname(__FILE__)) . "/pages/list.php"; } break; case "group": if (file_tools_use_folder_structure()) { $result = false; include dirname(dirname(__FILE__)) . "/pages/list.php"; } break; case "add": $result = false; include dirname(dirname(__FILE__)) . "/pages/file/new.php"; break; case "zip": if (isset($page[1])) { $result = false; elgg_set_page_owner_guid($page[1]); register_error(elgg_echo("changebookmark")); forward("file/add/" . $page[1] . "?upload_type=zip"); } break; case "bulk_download": $result = false; include dirname(dirname(__FILE__)) . "/pages/file/download.php"; break; } } return $result; }
/** * Listen to the /file pagehandler * * @param string $hook the name of the hook * @param string $type the type of the hook * @param array $return_value current return value * @param array $params supplied params * * @return void|false */ public static function file($hook, $type, $return_value, $params) { $page = elgg_extract('segments', $return_value, []); switch (elgg_extract(0, $page)) { case 'owner': if (file_tools_use_folder_structure()) { echo elgg_view_resource('file_tools/file/list'); return false; } break; case 'group': if (file_tools_use_folder_structure()) { echo elgg_view_resource('file_tools/file/list'); return false; } break; case 'bulk_download': echo elgg_view_resource('file_tools/file/bulk_download'); return false; break; } }
<?php echo elgg_view('input/longtext', array('name' => 'description', 'value' => $desc)); ?> </div> <div> <label><?php echo elgg_echo('tags'); ?> </label> <?php echo elgg_view('input/tags', array('name' => 'tags', 'value' => $tags)); ?> </div> <?php if (elgg_is_active_plugin('file_tools')) { if (file_tools_use_folder_structure()) { $parent_guid = 0; if ($file = elgg_extract("entity", $vars)) { if ($folders = $file->getEntitiesFromRelationship(FILE_TOOLS_RELATIONSHIP, true, 1)) { $parent_guid = $folders[0]->getGUID(); } } ?> <div> <label><?php echo elgg_echo("file_tools:forms:edit:parent"); ?> <br /> <?php echo elgg_view("input/folder_select", array("name" => "folder_guid", "value" => $parent_guid)); ?>
/** * Route file * * @param string $hook the name of the hook * @param string $type the type of the hook * @param array $return_value current return value * @param array $params supplied params * * @return array|false */ function theme_haarlem_intranet_file_route_handler($hook, $type, $return_value, $params) { if (empty($return_value) || !is_array($return_value)) { return $return_value; } $page = elgg_extract('segments', $return_value); switch ($page[0]) { case "owner": case "group": if (elgg_is_active_plugin('file_tools') && file_tools_use_folder_structure()) { $return_value = false; include dirname(dirname(__FILE__)) . "/pages/file/list.php"; } break; } return $return_value; }
} $guid = elgg_extract('guid', $vars, null); $parent_guid = (int) get_input('folder_guid', 0); if ($guid) { $file_label = elgg_echo("file:replace"); $submit_label = elgg_echo('save'); // get current parent_guid $file = get_entity($guid); $folders = $file->getEntitiesFromRelationship(['relationship' => FILE_TOOLS_RELATIONSHIP, 'inverse_relationship' => true, 'limit' => 1]); if (!empty($folders)) { $parent_guid = $folders[0]->getGUID(); } } else { $file_label = elgg_echo("file:file"); $submit_label = elgg_echo('upload'); } // Get post_max_size and upload_max_filesize $post_max_size = elgg_get_ini_setting_in_bytes('post_max_size'); $upload_max_filesize = elgg_get_ini_setting_in_bytes('upload_max_filesize'); // Determine the correct value $max_upload = $upload_max_filesize > $post_max_size ? $post_max_size : $upload_max_filesize; $upload_limit = elgg_echo('file:upload_limit', array(elgg_format_bytes($max_upload))); $fields = [['type' => 'file', 'name' => 'upload', 'label' => $file_label, 'help' => $upload_limit, 'value' => $guid, 'required' => !$guid], ['type' => 'text', 'name' => 'title', 'value' => $title, 'label' => elgg_echo('title')], ['type' => 'longtext', 'name' => 'description', 'value' => $desc, 'label' => elgg_echo('description')], ['type' => 'tags', 'name' => 'tags', 'value' => $tags, 'label' => elgg_echo('tags')], ['type' => 'folder_select', 'name' => 'folder_guid', 'value' => $parent_guid, 'label' => elgg_echo('file_tools:forms:edit:parent')], ['type' => 'access', 'name' => 'access_id', 'value' => $access_id, 'entity' => get_entity($guid), 'entity_type' => 'object', 'entity_subtype' => 'file', 'label' => elgg_echo('access')], ['type' => 'hidden', 'name' => 'container_guid', 'value' => $container_guid], ['type' => 'hidden', 'name' => 'file_guid', 'value' => $guid], ['type' => 'submit', 'value' => $submit_label, 'field_class' => 'elgg-foot']]; foreach ($fields as $field) { $type = elgg_extract('type', $field, 'text'); unset($field['type']); if ($type == 'folder_select' && !file_tools_use_folder_structure()) { continue; } echo elgg_view_input($type, $field); }