public static function getFullPathTo($parent)
 {
     $path = "";
     if ($parent > 0) {
         $folder = new file();
         $folder->load($parent);
         $path = file::getFullPathTo($folder->parent);
         $path .= '/' . $folder->name;
     }
     return $path;
 }
    public function generate()
    {
        global $layout;
        global $website;
        $html = array();
        $access = array(0 => '', 1 => '<img src="img/icons/silk/lock.png" align="absmiddle" title="' . t(361, 'Web users only') . '" />', 2 => '<img src="img/icons/silk/user_gray.png" align="absmiddle" title="' . t(363, 'Users who have not yet signed up or signed in') . '" />', 3 => '<img src="img/icons/silk/group_key.png" align="absmiddle" title="' . t(512, "Selected web user groups") . '" />');
        $permissions = array(0 => '', 1 => '<img src="img/icons/silk/world_dawn.png" align="absmiddle" title="' . t(70, 'Private') . '" />', 2 => '<img src="img/icons/silk/world_night.png" align="absmiddle" title="' . t(81, 'Hidden') . '" />');
        $html[] = '<div class="navigate-content-safe ui-corner-all" id="navigate-content-safe">';
        $html[] = '<div class="navibrowse" id="' . $this->id . '">';
        $html[] = '<div class="navibrowse-path ui-corner-all">';
        $html[] = '	<a href="?fid=' . $_REQUEST['fid'] . '"><img src="img/icons/silk/folder_home.png" width="16px" height="16px" align="absbottom" /> ' . t(18, 'Home') . '</a>';
        if ($this->parent > 0) {
            $html[] = '	<a href="?fid=' . $_REQUEST['fid'] . '&parent=' . $this->previous . '"><img src="img/icons/silk/folder_up.png" width="16px" height="16px" align="absbottom" /> ' . t(139, 'Back') . '</a>';
        }
        // recent folders
        $function_id = $_REQUEST['fid'];
        if (!is_numeric($function_id)) {
            $f = core_load_function($_REQUEST['fid']);
            $function_id = $f->id;
        }
        $actions = users_log::recent_actions($function_id, 'list', 8);
        if (!empty($actions)) {
            $html[] = '	<a href="#" id="navigate-navibrowse-recent-items-link"><img src="img/icons/silk/folder_bell.png" width="16px" height="16px" align="absbottom" /> ' . t(275, 'Recent elements') . ' <span style=" float: right; " class="ui-icon ui-icon-triangle-1-s"></span></i></a>';
            $layout->add_content('<ul id="navigate-navibrowse-recent-items" class="hidden">' . implode("\n", array_map(function ($action) {
                return '<li>' . '<a href="?fid=' . $_REQUEST['fid'] . '&parent=' . $action->item . '">' . '<img src="img/icons/silk/folder.png" style="vertical-align: text-bottom;" /> ' . file::getFullPathTo($action->item) . '</a>' . '</li>';
            }, $actions)) . '</ul>');
            $layout->add_script('
				$("#navigate-navibrowse-recent-items-link").on("click", function(e)
				{
					e.preventDefault();
					e.stopPropagation();
					
					$("#navigate-navibrowse-recent-items").css({
						position: "absolute",
						top: $("#navigate-navibrowse-recent-items-link").offset().top + 26,
						left: $("#navigate-navibrowse-recent-items-link").offset().left,
						zIndex: 10,
						"min-width": $("#navigate-navibrowse-recent-items-link").width() + "px"
					});
					$("#navigate-navibrowse-recent-items").addClass("navi-ui-widget-shadow");
					$("#navigate-navibrowse-recent-items").removeClass("hidden");
					$("#navigate-navibrowse-recent-items").menu().show();
					
					return false;
				});
			');
        }
        // folders hierarchy
        $html[] = '	<a href="#" onclick="navibrowse_folder_tree_dialog(' . $this->parent . ');"><img src="img/icons/silk/application_side_tree.png" width="16px" height="16px" align="absbottom" /> ' . t(75, 'Path') . ': ' . $this->path . '</a>';
        $html[] = '
			<div style="float: right;">
				<i class="fa fa-filter"></i>
	            <select id="navibrowse-filter-type" name="navibrowse-filter-type">
					<option value="" selected="selected">(' . t(443, "All") . ')</option>
					<option value="folder">' . t(141, "Folder") . '</option>
					<option value="image">' . t(157, 'Image') . '</option>
					<option value="audio">' . t(31, 'Audio') . '</option>
					<option value="document">' . t(539, 'Document') . '</option>
					<option value="video">' . t(30, 'Video') . '</option>
				</select>
			</div>
		';
        $layout->add_script('
			$("#navibrowse-filter-type")
				.select2(
				{
				    placeholder: "' . t(160, "Type") . '",
				    allowClear: true,
			        minimumResultsForSearch: Infinity,
			        width: 150,
			        templateResult: navibrowse_filter_type_render,
			        templateSelection: navibrowse_filter_type_render
			    })
		        .on("select2:unselecting", function(e)
			    {
			        $(this).select2("val", "");
			        $(this).val("");
			        e.preventDefault();
			        $(this).trigger("change");
			    });

		    function navibrowse_filter_type_render(opt)
	        {
				if(!opt.id) { return opt.text; }

				var icon = "fa-file";
				switch(opt.element.value)
				{
					case "folder":      icon = "fa-folder-o";       break;
					case "image":       icon = "fa-image";          break;
					case "audio":       icon = "fa-music";          break;
					case "document":    icon = "fa-file-text-o";    break;
					case "video":       icon = "fa-video-camera";   break;
				}

				var html = $(\'<span><i class="fa fa-fw \'+icon+\'"></i> \' + opt.text + \'</span>\');
				return html;
	        }

		    $("#navibrowse-filter-type").on("change", function () {
				$(".navibrowse-items > div").show();
				if($("#navibrowse-filter-type").val() != "")
				{
					$(".navibrowse-items > div").each(function()
					{
						if($(this).data("file-type") == $("#navibrowse-filter-type").val())
							$(this).show();
						else
							$(this).hide();
					});
				}
		    });
		');
        $html[] = '</div>';
        $html[] = '<div class="navibrowse-items">';
        if ($this->parent > 0) {
            $icon = $this->mimeIcon('folder/back');
            $html[] = '<div class="navibrowse-folder navibrowse-back ui-corner-all" id="item-' . $this->previous . '">';
            $html[] = '		<img src="' . $icon . '" width="' . $this->icon_size . '" height="' . $this->icon_size . '" />';
            $html[] = '		<div class="navibrowse-item-name">' . t(139, 'Back') . '</div>';
            $html[] = '</div>';
        }
        if (empty($this->items)) {
            $this->items = array();
        }
        foreach ($this->items as $item) {
            $icon = $this->mimeIcon($item->mime, $item->type);
            $thumbnail = '';
            if ($item->type == 'image') {
                $thumbnail = NAVIGATE_DOWNLOAD . '?wid=' . $website->id . '&id=' . $item->id . '&disposition=inline&width=' . intval($this->icon_size) . '&height=' . intval($this->icon_size);
            }
            if ($item->type == 'folder') {
                $html[] = '<div class="navibrowse-folder ui-corner-all" mime="' . $item->mime . '" id="item-' . $item->id . '" data-file-type="' . $item->type . '" data-file-id="' . $item->id . '">';
                $html[] = '		<img src="' . $icon . '" width="' . $this->icon_size . '" height="' . $this->icon_size . '" />';
                $html[] = '		<div class="navibrowse-item-name">' . $item->name . '</div>';
                $html[] = '</div>';
            } else {
                $html[] = '<div class="navibrowse-file ui-corner-all" mime="' . $item->mime . '" id="item-' . $item->id . '" data-file-type="' . $item->type . '" data-file-id="' . $item->id . '">';
                $html[] = '     <div class="navibrowse-file-access-icons">' . $permissions[$item->permission] . $access[$item->access] . '</div>';
                $html[] = '		<img src="' . $icon . '" data-src="' . $thumbnail . '"  width="' . $this->icon_size . '" height="' . $this->icon_size . '" />';
                $html[] = '		<div class="navibrowse-item-name">' . $item->name . '</div>';
                $html[] = '</div>';
            }
        }
        $html[] = '<div class="clearer">&nbsp;</div>';
        $html[] = '</div>';
        $html[] = '</div>';
        $html[] = '</div>';
        $hierarchy = file::hierarchy(0);
        $folders_tree = file::hierarchyList($hierarchy, $item->parent);
        $html[] = '
			<div id="navibrowse-folder-tree-dialog" class="hidden">			
				<div class="navibrowse_folder_tree" style=" width: 90%; ">
				    <img src="img/icons/silk/folder_home.png" align="absmiddle" />  ' . t(18, 'Home') . '<div class="tree_ul">' . $folders_tree . '</div>
                </div>
			</div>
		';
        $html[] = '<script language="javascript" type="text/javascript">';
        // replace placeholder images by real thumbnails after document is ready
        $html[] = '
			$(window).on("load", function()
			{
				new LazyLoad({
				    threshold: 200,
				    container: document.getElementById("navigate-content-safe"),
				    elements_selector: ".navibrowse-file img",
				    throttle: 40,
				    data_src: "src",
				    show_while_loading: true
				});
			});
		';
        //		$html[] = '$(".navibrowse-file, .navibrowse-folder").on("mouseover", function() { $(this).css("opacity", 0.7); });';
        //		$html[] = '$(".navibrowse-file, .navibrowse-folder").on("mouseout", function() { $(this).css("opacity", 1); });';
        $html[] = '$(".navibrowse-path a").button();';
        $html[] = '$(".navibrowse-items").children().on("click", function(e)
				   {
					   if(e.ctrlKey)
					   {
							// just add or remove the item as selected  
							if($(this).hasClass("ui-selected"))
							{
								$(this).removeClass("ui-selected ui-selectee");
								$(this).children().removeClass("ui-selected ui-selectee");
							}
							else
								$(this).addClass("ui-selected ui-selectee");

							navibrowse_selected = $("div.navibrowse-file.ui-selected, div.navibrowse-folder.ui-selected");
					   }
					   else
					   {
						   // deselect everything except the new selected item
							$(".navibrowse-items div").removeClass("ui-selectee ui-selected");
							$(".navibrowse-items img").removeClass("ui-selectee ui-selected");						
							$(this).addClass("ui-selected ui-selectee");
					   }
					   
					   e.stopPropagation();
						
				   });';
        $html[] = '$(".navibrowse-folder").on("dblclick", function()
				   {
						window.location.href = "' . $this->url . '" + this.id.substring(5);
				   });';
        if (!empty($this->onDblClick)) {
            $html[] = '$(".navibrowse-file").on("dblclick", function()
			    	   {
				    		' . $this->onDblClick . '(this);
				    });';
        }
        $html[] = '$(".navibrowse-items").on("click", function()
					{
						$(".ui-selectee, .ui-selected").removeClass("ui-selectee ui-selected");
					});';
        if (!empty($this->onRightClick)) {
            $html[] = '$(".navibrowse-items").children().on("contextmenu", function(e)
			    		{
			    		    if($(this).attr("id")=="item-0")
			    		        return;

                            e.preventDefault();
                            e.stopPropagation();
                            //$(".ui-selectee, .ui-selected").removeClass("ui-selectee ui-selected");

			    		    var ev = e;
			    		    var trigger = this;

			    		    setTimeout(function()
			    		    {
				    	        ' . $this->onRightClick . '(trigger, ev);
                            }, 150);
					    });';
        }
        $html[] = '$(".navibrowse-items").selectable(
					{
						distance: 10,
						selecting: function(event, ui)
						{
							$(".navibrowse-back").removeClass("ui-selectee ui-selected");	
						},
						selected: function(event, ui)	
						{
							$(".navibrowse-back").removeClass("ui-selectee ui-selected");
							$(".navibrowse-back").children().removeClass("ui-selectee ui-selected");							
							$(".clearer").removeClass("ui-selectee ui-selected");
							navibrowse_selected = $("div.navibrowse-file.ui-selected, div.navibrowse-folder.ui-selected");
						}
					});';
        $html[] = '				
            $(".navibrowse_folder_tree .tree_ul").jstree({
                plugins: ["changed", "types"],
                "types" : 
                {
                    "default":  {   "icon": "img/icons/silk/folder.png"    },
                    "leaf":     {   "icon": "img/icons/silk/page_white.png"      }
                },
                "core" : 
                {
                    "multiple" : false
                }
            }).on("dblclick.jstree", function(e, data)
            {
                var node = $(e.target).closest("li");
                window.location.href = "?fid=' . $_REQUEST['fid'] . '&parent=" + $(node).attr("value");
            });
				
			
			$("#navibrowse-folder-tree-dialog").hide();
		
			function navibrowse_folder_tree_dialog(current)
		    {
		        $("#navibrowse-folder-tree-dialog").removeClass("hidden");
                $("#navibrowse-folder-tree-dialog").dialog(
                {
                    resizable: true,
                    height: 350,
                    width: 500,
                    modal: true,
                    title: "' . t(221, 'Jump to') . '…",
                    buttons: 
                    {
                        "' . t(58, 'Cancel') . '": function() 
                        {
                            $(this).dialog("close");
                        }
                    }
                });
		    }
		';
        // drag'n'drop support
        if (!empty($this->onMove)) {
            $html[] = '
				var navibrowse_selected;
				$(".navibrowse-items").children().not(".navibrowse-back").draggable(
				{
					opacity: 0.8,
					zIndex: 1000,
					revert: true, //"invalid",
					start: function(event, ui)
					{
						if(navibrowse_selected && navibrowse_selected.length < 1)
						{
							$(".navibrowse-items div").removeClass("ui-selectee ui-selected");
							$(".navibrowse-items img").removeClass("ui-selectee ui-selected");							
						}
						$(this).addClass("ui-selected");
						navibrowse_selected = $("div.navibrowse-file.ui-selected, div.navibrowse-folder.ui-selected");

						if(navibrowse_selected.length > 1)
							$(ui.helper).append("<div id=\\"navibrowse-item-badge\\">" + navibrowse_selected.length + "</div>");
					},
					stop: function()
					{
						navibrowse_selected = $("div.navibrowse-file.ui-selected, div.navibrowse-folder.ui-selected");
						$("#navibrowse-item-badge").remove();
					}
				});
			';
            $html[] = '
			    $(".navibrowse-folder").droppable(
                {
                    hoverClass: "ui-selected",
                    tolerance: "pointer",
                    drop: function(event, ui)
                    {
                        if(navibrowse_selected!=null && navibrowse_selected.length > 1)
                        {
                            var folder = $(this).attr("id").substring(5);
                            var ids = [];

                            $(navibrowse_selected).each(function()
                            {
                                if($(this).attr("id").substring(5) != folder)
                                    ids.push($(this).attr("id").substring(5));
                            });

                            navibrowse_selected = jQuery.grep(navibrowse_selected, function(value)
                            {
                                return $(value).attr("id").substring(5) != folder;
                            });
                            ' . $this->onMove . '(ids, folder, navibrowse_selected);
                        }
                        else
                        {
                            var folder = $(this).attr("id").substring(5);
                            var item = $(ui.draggable).attr("id").substring(5);
                            ' . $this->onMove . '(item, folder, ui.draggable);
                        }

                        $(".navibrowse-items div").removeClass("ui-selectee ui-selected");
                        $(".navibrowse-items img").removeClass("ui-selectee ui-selected");
                    }
                });
            ';
        }
        $html[] = '</script>';
        return implode("\n", $html);
    }
Beispiel #3
0
function files_media_browser($limit = 50, $offset = 0)
{
    global $DB;
    global $website;
    global $user;
    // access & permissions string helpers
    $access = array(0 => '', 1 => '<img src="img/icons/silk/lock.png" align="absmiddle" title="' . t(361, 'Web users only') . '" />', 2 => '<img src="img/icons/silk/user_gray.png" align="absmiddle" title="' . t(363, 'Users who have not yet signed up or signed in') . '" />', 3 => '<img src="img/icons/silk/group_key.png" align="absmiddle" title="' . t(512, "Selected web user groups") . '" />');
    $permissions = array(0 => '', 1 => '<img src="img/icons/silk/world_dawn.png" align="absmiddle" title="' . t(70, 'Private') . '" />', 2 => '<img src="img/icons/silk/world_night.png" align="absmiddle" title="' . t(81, 'Hidden') . '" />');
    $wid = $_REQUEST['website'];
    $ws = new website();
    if (empty($wid)) {
        $ws = $website;
        $wid = $website->id;
    } else {
        $ws->load($wid);
        // check if the current user is allowed to access the website files
        if (!empty($user->websites) && !in_array($wid, $user->websites)) {
            $ws->share_files_media_browser = false;
        }
    }
    // check if the chosen website allows sharing its files (or it's the current website)
    if ($ws->id == $website->id || $ws->share_files_media_browser == '1') {
        $media = empty($_REQUEST['media']) ? 'image' : $_REQUEST['media'];
        $text = $_REQUEST['text'];
        $out = array();
        $limit = $offset + $limit;
        $offset = 0;
        $total = 0;
        $order = $_REQUEST['order'];
        switch ($order) {
            case 'name_ASC':
                $order = ' name ASC';
                break;
            case 'name_DESC':
                $order = ' name DESC';
                break;
            case 'date_added_ASC':
                $order = ' date_added ASC';
                break;
            case 'date_added_DESC':
            default:
                $order = ' date_added DESC';
        }
        if ($media == 'folder') {
            $parent = 0;
            $files = file::filesOnPath($_REQUEST['parent'], $wid, $order);
            if ($_REQUEST['parent'] > 0) {
                $previous = $DB->query_single('parent', 'nv_files', ' id = ' . $_REQUEST['parent'] . ' AND website = ' . $wid);
                array_unshift($files, json_decode('{"id":"' . $previous . '","type":"folder","name":"' . t(139, 'Back') . '","mime":"folder\\/back","navipath":"/foo"}'));
            }
            $total = count($files);
            $files_shown = array();
            for ($i = $offset; $i + $offset < $limit; $i++) {
                if (empty($files[$i])) {
                    break;
                }
                // search by text in a folder
                if (!empty($text)) {
                    if (stripos($files[$i]->name, $text) === false) {
                        continue;
                    }
                }
                $files_shown[] = $files[$i];
            }
        } else {
            if ($media == 'youtube') {
                //list($files_shown, $total) = files_youtube_search($offset, $limit, $text, $order);
            } else {
                list($files_shown, $total) = file::filesByMedia($media, $offset, $limit, $wid, $text, $order);
            }
        }
        foreach ($files_shown as $f) {
            $website_root = $ws->absolute_path(true) . '/object';
            if (empty($website_root)) {
                $website_root = NVWEB_OBJECT;
            }
            $download_link = $website_root . '?id=' . $f->id . '&disposition=attachment';
            if ($f->type == 'image') {
                $f->title = json_decode($f->title, true);
                $f->description = json_decode($f->description, true);
                $icon = NAVIGATE_DOWNLOAD . '?wid=' . $wid . '&id=' . $f->id . '&disposition=inline&width=75&height=75';
                $out[] = '<div class="ui-corner-all draggable-' . $f->type . '"
				               mediatype="' . $f->type . '"
				               mimetype="' . $f->mime . '"
				               image-width="' . $f->width . '"
				               image-height="' . $f->height . '"
				               image-title="' . base64_encode(json_encode($f->title, JSON_HEX_QUOT | JSON_HEX_APOS)) . '"
				               image-description="' . base64_encode(json_encode($f->description, JSON_HEX_QUOT | JSON_HEX_APOS)) . '"
				               download-link="' . $download_link . '"
				               data-file-id="' . $f->id . '"
				               id="file-' . $f->id . '">
				               <div class="file-access-icons">' . $access[$f->access] . $permissions[$f->permission] . '</div>
				               <div class="file-image-wrapper"><img src="' . $icon . '" title="' . $f->name . '" /></div>
	                      </div>';
            } else {
                if ($f->type == 'youtube') {
                    $out[] = '<div class="ui-corner-all draggable-' . $f->type . '"
				               mediatype="' . $f->type . '"
				               mimetype="' . $f->mime . '"
				               image-width="' . $f->width . '"
				               image-height="' . $f->height . '"
				               image-title="' . base64_encode(json_encode($f->title, JSON_HEX_QUOT | JSON_HEX_APOS)) . '"
				               image-description="' . base64_encode(json_encode($f->description, JSON_HEX_QUOT | JSON_HEX_APOS)) . '"
				               download-link="' . $download_link . '"
				               data-file-id="' . $f->id . '"
				               id="file-youtube#' . $f->id . '">
				               <img src="' . $f->thumbnail->url . '" title="' . $f->title . '" width="75" height="53" />
				               <span>' . $f->title . '</span>
	                      </div>';
                } else {
                    $icon = navibrowse::mimeIcon($f->mime, $f->type);
                    $navipath = file::getFullPathTo($f->id);
                    $out[] = '<div class="ui-corner-all draggable-' . $f->type . '"
				               mediatype="' . $f->type . '"
				               mimetype="' . $f->mime . '"
				               navipath="' . $navipath . '"
				               download-link="' . $download_link . '"
				               data-file-id="' . $f->id . '"
				               id="file-' . $f->id . '">
				               <div class="file-access-icons">' . $access[$f->access] . $permissions[$f->permission] . '</div>
				               <div class="file-icon-wrapper"><img src="' . $icon . '" width="50" height="50" title="' . $f->name . '" /></div>
	                           <span style="clear: both; display: block; height: 0px;"></span>' . $f->name . '
	                       </div>';
                }
            }
        }
        if ($total > $limit + $offset) {
            $out[] = '<div class="ui-corner-all" id="file-more">
	                    <img src="' . NAVIGATE_URL . '/img/icons/ricebowl/actions/forward.png" width="32" height="32"  style="margin-top: 14px;" />' . t(234, 'More elements') . '
	                  </div>';
        }
        echo implode("\n", $out);
    }
    session_write_close();
    $DB->disconnect();
    exit;
}