Esempio n. 1
0
function files_browser($parent, $search = "")
{
    global $layout;
    global $DB;
    global $website;
    global $events;
    global $user;
    global $current_version;
    $navibars = new navibars();
    $naviforms = new naviforms();
    $navibrowse = new navibrowse('files');
    $navibars->title(t(89, 'Files'));
    // we attach an event to "files" which will be fired by navibars to put an extra button (if necessary)
    $extra_actions = array();
    $events->add_actions('files', array('navibrowse' => &$navibrowse, 'navibars' => &$navibars), $extra_actions);
    $navibars->add_actions(array('<a href="#" onclick="navigate_files_uploader();"><img height="16" align="absmiddle" width="16" src="img/icons/silk/page_white_get.png"> ' . t(140, 'Upload') . '</a>', '<a href="#" onclick="navigate_files_edit_folder();"><img height="16" align="absmiddle" width="16" src="img/icons/silk/folder_add.png"> ' . t(141, 'Folder') . '</a>', $user->permission("files.delete") == 'true' ? '<a href="#" onclick="navigate_files_remove();"><img height="16" align="absmiddle" width="16" src="img/icons/silk/cancel.png"> ' . t(35, 'Delete') . '</a>' : ''));
    $navibars->add_actions(array('<a href="?fid=' . $_REQUEST['fid'] . '&act=0"><img height="16" align="absmiddle" width="16" src="img/icons/silk/folder_home.png"> ' . t(18, 'Home') . '</a>', 'search_form'));
    if (!empty($search)) {
        $path = '/' . t(41, 'Search') . ': ' . $search;
        $parent = 0;
        $previous = 0;
        $files = file::filesBySearch($search);
    } else {
        if (empty($parent)) {
            $parent = 0;
            $previous = 0;
            $path = '/';
        } else {
            $previous = $DB->query_single('parent', 'nv_files', ' id = ' . intval($parent) . ' AND website = ' . $website->id);
            $path = file::getFullPathTo($parent);
        }
        $files = file::filesOnPath($parent);
    }
    $navibrowse->items($files);
    $navibrowse->path($path, $parent, $previous);
    $navibrowse->setUrl('?fid=' . $_REQUEST['fid'] . '&parent=');
    $navibrowse->onDblClick('navigate_files_dblclick');
    $navibrowse->onRightClick('navigate_files_contextmenu');
    $navibrowse->onMove('navigate_files_move');
    $navibrowse_hierarchy = $navibrowse->generate();
    $navibars->add_content($navibrowse_hierarchy);
    $layout->add_script('
        navigate_file_drop(
            ".navibrowse",
            "' . $parent . '",
            {
                afterAll: function()
                {
                    location.replace("' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=files&parent=' . $parent . '");
                }
            },
            true
        );
    ');
    // CONTEXT MENU
    // extensions: add new contextmenu functions
    $extra_contextmenu_actions = array();
    $events->trigger("files", "contextmenu", array('navibars' => &$navibars, 'actions' => &$extra_contextmenu_actions));
    if (!empty($extra_contextmenu_actions)) {
        array_unshift($extra_contextmenu_actions, '<hr />');
    }
    $navibars->add_content('
        <ul id="navigate-files-contextmenu" style="display: none;">
            <li action="open"><a href="#"><span class="ui-icon ui-icon-arrowreturnthick-1-e"></span>' . t(499, "Open") . '</a></li>
            <li action="rename"><a href="#"><span class="ui-icon ui-icon-pencil"></span>' . t(500, "Rename") . '</a></li>
            <li action="duplicate"><a href="#"><span class="ui-icon ui-icon-copy"></span>' . t(477, "Duplicate") . '</a></li>
            ' . ($user->permission("files.delete") == "true" ? '<li action="delete"><a href="#"><span class="ui-icon ui-icon-trash"></span>' . t(35, 'Delete') . '</a></li>' : '') . '
            ' . implode("\n", $extra_contextmenu_actions) . '
        </ul>
    ');
    if ($user->permission("files.upload") == "true") {
        // PLUPLOAD
        $navibars->add_content('<div id="navigate-files-uploader"></div>');
        $layout->add_script('
			plupload.addI18n(
			{
				"Select files" : "' . t(142, 'Select files') . '",
				"Add files to the upload queue and click the start button." : "' . t(143, 'Add files to the upload queue and click the start button.') . '",
				"Filename" : "' . t(144, 'Filename') . '",
				"Status" : "' . t(68, 'Status') . '",
				"Size" : "' . t(145, 'Size') . '",
				"Add files" : "' . t(146, 'Select files') . '",
				"Start upload":"' . t(147, 'Start upload') . '",
				"Stop current upload" : "' . t(148, 'Stop current upload') . '",
				"Start uploading queue" : "' . t(149, 'Start uploading queue') . '",
				"Drag files here." : "' . t(150, 'Drag files here.') . '",
				"Uploaded %d/%d files": "' . t(338, 'Uploaded %d/%d files') . '",
				"N/A": "' . t(339, 'N/A') . '",
				"File extension error.": "' . t(340, 'File extension error') . '",
				"File size error.": "' . t(341, 'File size error') . '",
				"Init error.": "' . t(342, 'Init error') . '",
				"HTTP Error.": "' . t(343, 'HTTP Error') . '",
				"Security error.": "' . t(344, 'Security error') . '",
				"Generic error.": "' . t(345, 'Generic error') . '",
				"IO error.": "' . t(346, 'IO error') . '",
				"Stop Upload": "' . t(347, 'Stop upload') . '",
				"Add Files": "' . t(348, 'Add files') . '",
				"Start Upload": "' . t(349, 'Start upload') . '",
				"%d files queued": "' . t(350, '%d files queued') . '"
			});
		');
        $layout->add_script('
			function navigate_files_uploader()
			{
				$("#navigate-files-uploader").plupload(
				{
					// General settings
			        runtimes : "html5,flash,silverlight",
					url : "' . NAVIGATE_URL . '/navigate_upload.php?session_id=' . session_id() . '",
					max_file_size : "' . NAVIGATE_UPLOAD_MAX_SIZE . 'mb",
					chunk_size : "384kb",
					unique_names: false,
					sortable: false,
					rename: true,
					preinit: attachCallbacks,
					flash_swf_url: "' . NAVIGATE_URL . '/lib/external/plupload/js/Moxie.swf",
			        silverlight_xap_url: "' . NAVIGATE_URL . '/lib/external/plupload/js/Moxie.xap"
				});

				function attachCallbacks(Uploader)
				{
					Uploader.bind("FileUploaded", function(Up, File, Response)
					{
						$.ajax(
						{
							async: true,
							url: "' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=files&act=json&op=upload",
							success: function(data)
							{

							},
							type: "post",
							dataType: "json",
							data: {
							    tmp_name: "{{BASE64}}",
							    name: File.name,
							    parent: ' . $parent . '
							}
						});
					});
				}

	            $("#navigate-files-uploader").dialog(
	            {
	                title: "' . t(142, 'Select files') . '",
	                height: 355,
	                width: 650,
	                modal: true,
	                close: function()
	                {
	                    window.location.reload();
	                }
	            });

	            $(".plupload_wrapper").removeClass("plupload_scroll");

	            $("#navigate-files-uploader").on("mouseenter", function()
	            {
	                $("div.plupload input").css("z-index","99999");
	            });
		    }');
    }
    $layout->add_script('
		function navigate_files_remove(elements)
		{
		    if(!elements || elements=="" || elements==undefined || $(elements).length == 0)
		        var elements = $(".ui-selected img").parent();

			if($(elements).length > 0)
			{
				$("<div>' . t(151, 'These items will be permanently deleted and cannot be recovered. Are you sure?') . '</div>").dialog(
				{
					title: "' . t(59, 'Confirmation') . '",
					resizable: false,
					height:140,
					modal: true,
					buttons:
					{
						"' . t(152, 'Continue') . '": function()
						{
							$(elements).each(function()
							{
							    if(!$(this) || !$(this).attr) return;
								var itemId = $(this).attr("id").substring(5);

								$.ajax(
								{
									async: false,
									url: "' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=' . $_REQUEST['fid'] . '&act=json&op=delete&id=" + itemId,
									success: function(data)
									{
										$("#item-"+itemId).remove();
									}
								});
							});
							$(this).dialog("close");
						},
						"' . t(58, 'Cancel') . '": function()
						{
							$(this).dialog("close");
						}
					}
				});
			}
		}
	');
    $navibars->add_content('
		<div id="navigate-edit-folder" style=" display: none; ">
            <form action="#" onsubmit="return false;">
                <input type="submit" value="" style=" display: none; " />
                <div class="navigate-form-row">
                    <label>' . t(159, 'Name') . '</label>
                    ' . $naviforms->textfield('folder-name', '') . '
                </div>
                <div class="navigate-form-row">
                    <label>' . t(160, 'Type') . '</label>
                    ' . $naviforms->selectfield('folder-mime', array(0 => 'folder/generic', 1 => 'folder/images', 2 => 'folder/audio', 3 => 'folder/video', 4 => 'folder/flash', 5 => 'folder/documents'), array(0 => t(161, 'Generic'), 1 => t(29, 'Images'), 2 => t(31, 'Audio'), 3 => t(30, 'Video'), 4 => t(186, 'Adobe Flash'), 5 => t(32, 'Documents')), 'folder/generic') . '
                </div>
            </form>
		</div>

		<div id="navigate-edit-file" style=" display: none; ">
            <form action="#" onsubmit="return false;">
                <input type="submit" value="" style=" display: none; " />
                <div class="navigate-form-row">
                    <label>' . t(159, 'Name') . '</label>
                    ' . $naviforms->textfield('file-name', '') . '
                </div>
            </form>
		</div>
	');
    $layout->add_script('
		function navigate_files_edit_folder(id, name, mime)
		{
			$("#navigate-edit-folder").dialog(
			{
				title: "' . t(141, 'Folder') . '",
				resizable: false,
				height: 200,
				width: 625,
				modal: true,
				buttons:
				{
					"' . t(152, 'Continue') . '": function()
					{
					    var op = "edit_folder";
						if(!id)
						    op = "create_folder";

						$.ajax(
						{
							async: false,
							type: "post",
							data: {
								name: $("#folder-name").val(),
								mime: $("#folder-mime").val(),
								parent: "' . $parent . '"
							},
							url: "' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=' . $_REQUEST['fid'] . '&act=json&id=" + id + "&op=" + op,
							success: function(data)
							{
								$("#navigate-edit-folder").dialog("close");
								window.location.reload();
							}
						});
					},
					"' . t(58, 'Cancel') . '": function()
					{
						$("#navigate-edit-folder").dialog("close");
					}
				}
			});

			$("#folder-name").val(name);
			$("#folder-mime").val(mime).trigger("change");
		}
	');
    $layout->add_script('
		$.getScript("lib/packages/files/files.js?r=' . $current_version->revision . '", function()
		{
            navigate_files_onload();
		});
	');
    return $navibars->generate();
}