Пример #1
0
    public function dropbox($name, $value = 0, $media = "", $disabled = false, $default_value = null, $options = array(), $website_id = null)
    {
        global $layout;
        global $website;
        global $theme;
        if (empty($website_id)) {
            $website_id = $website->id;
        }
        $out = array();
        $out[] = '<div id="' . $name . '-droppable-wrapper" class="navigate-droppable-wrapper">';
        $out[] = '<input type="hidden" id="' . $name . '" name="' . $name . '" value="' . $value . '" />';
        $out[] = '<div id="' . $name . '-droppable" class="navigate-droppable ui-corner-all" data-media="' . $media . '">';
        if (!empty($value)) {
            if ($media == 'image') {
                $f = new file();
                $f->load($value);
                $out[] = '<img title="' . $f->name . '" src="' . NAVIGATE_DOWNLOAD . '?wid=' . $website_id . '&id=' . $f->id . '&amp;disposition=inline&amp;width=75&amp;height=75" />';
            } else {
                if ($media == 'video') {
                    $layout->add_script('
                    $(window).load(function() { navigate_dropbox_load_video("' . $name . '", "' . $value . '"); });
                ');
                    $out[] = '<figure class="navigatecms_loader"></figure>';
                } else {
                    $f = new file();
                    $f->load($value);
                    $out[] = '<img title="' . $f->name . '" src="' . navibrowse::mimeIcon($f->mime, $f->type) . '" width="50" height="50" /><br />' . $f->name;
                }
            }
        } else {
            $out[] = '	<img src="img/icons/misc/dropbox.png" vspace="18" />';
        }
        $out[] = '</div>';
        // set parent row as overflow:visible to let the whole contextmenu appear
        $layout->add_script('
            $(".navigate-droppable-wrapper").parent().css("overflow", "visible");
        ');
        $contextmenu = false;
        if (!$disabled) {
            $out[] = '<div class="navigate-droppable-cancel"><img src="img/icons/silk/cancel.png" /></div>';
            if ($media == 'image') {
                if ($options == 'a:0:{}') {
                    $options = array();
                }
                if (empty($options) && !empty($default_value)) {
                    $options = array($default_value => t(199, "Default value"));
                } else {
                    $options = (array) $options;
                }
                if (!empty($options)) {
                    $out[] = '
                        <div class="navigate-droppable-create">
                            <img src="img/icons/silk/add.png" />
                        </div>
                    ';
                    // "create" context menu actions (image picker)
                    $ws = new website();
                    if ($website_id == $website->id) {
                        $ws = $website;
                    } else {
                        $ws->load($website_id);
                    }
                    $ws_theme = new theme();
                    if ($website_id == $website->id) {
                        $ws_theme = $theme;
                    } else {
                        $ws_theme->load($ws->theme);
                    }
                    $layout->add_content('
                        <ul id="' . $name . '-image_picker" class="navigate-image-picker navi-ui-widget-shadow">
                            ' . implode("\n", array_map(function ($k, $v) use($website_id, $ws_theme) {
                        if (!empty($ws_theme)) {
                            $v = $ws_theme->t($v);
                        }
                        return '
                                        <li data-value="' . $k . '" data-src="' . NAVIGATE_DOWNLOAD . '?wid=' . $website_id . '&id=' . $k . '&amp;disposition=inline&amp;width=75&amp;height=75">
                                            <a href="#">
                                                <img title="' . $v . '" src="' . NAVIGATE_DOWNLOAD . '?wid=' . $website_id . '&id=' . $k . '&amp;disposition=inline&amp;width=48&amp;height=48" />
                                                <span>' . $v . '</span>
                                            </a>
                                        </li>
                                    ';
                    }, array_keys($options), array_values($options))) . '
                        </ul>
                    ');
                    $layout->add_script('
                        $("#' . $name . '-droppable").parent().find(".navigate-droppable-create").on(
                        "click",
                        function(ev)
				        {
                            navigate_hide_context_menus();
                            setTimeout(function()
                            {
                                $("#' . $name . '-image_picker").menu();
                                $("#' . $name . '-image_picker").css({left: ev.pageX, top: ev.pageY});
                                $("#' . $name . '-image_picker").show();
                                
                                if($("#' . $name . '-image_picker").position().top + $("#' . $name . '-image_picker").height() > $(window).height())                    
                                    $("#' . $name . '-image_picker").css("top", $(window).height() - $("#' . $name . '-image_picker").height() - 8);

                                $("#' . $name . '-image_picker li").off().on("click", function()
                                {
                                    $("#' . $name . '").val($(this).data("value"));
                                    $("#' . $name . '-droppable").html("<img src=\\"" + $(this).data("src") + "\\" />");
                                    $("#' . $name . '-droppable").parent().find(".navigate-droppable-cancel").show();
                                    $("#' . $name . '-droppable").parent().find(".navigate-droppable-create").hide();
                                });
                            }, 100);
                        });
                    ');
                    $contextmenu = true;
                }
                // images: add context menu over the image itself to define focal point, description and title...
                $out[] = '
                    <ul class="navigate-droppable-edit-contextmenu" style="display: none;">
                        <li action="permissions"><a href="#"><span class="ui-icon ui-icon-key"></span>' . t(17, "Permissions") . '</a></li>
                        <li action="focalpoint"><a href="#"><span class="ui-icon ui-icon-image"></span>' . t(540, "Focal point") . '</a></li>
                        <li action="description"><a href="#"><span class="ui-icon ui-icon-comment"></span>' . t(334, 'Description') . '</a></li>
                    </ul>
                ';
                $layout->add_script('
                    $("#' . $name . '-droppable").on("contextmenu", function(ev)
                    {
                        ev.preventDefault();
                        navigate_hide_context_menus();
                        var file_id = $("#' . $name . '").val();
                        if(!file_id || file_id=="" || file_id==0) return;

                        setTimeout(function()
                        {
                            var menu_el = $("#' . $name . '-droppable").parent().find(".navigate-droppable-edit-contextmenu");

							var menu_el_clone = menu_el.clone();
							menu_el_clone.appendTo("body");

                            menu_el_clone.menu();

                            menu_el_clone.css({
                                "z-index": 100000,
                                "position": "absolute",
                                "left": ev.clientX,
                                "top": ev.clientY
                            }).addClass("navi-ui-widget-shadow").show();

	                        menu_el_clone.find("a").on("click", function(ev)
		                    {
		                        ev.preventDefault();
		                        var action = $(this).parent().attr("action");
		                        var file_id = $("#' . $name . '").val();

		                        switch(action)
		                        {
		                            case "permissions":
		                            navigate_contextmenu_permissions_dialog(file_id);
		                            break;

		                            case "focalpoint":
		                            navigate_media_browser_focalpoint(file_id);
		                            break;

		                            case "description":
		                            $.get(
		                                NAVIGATE_APP + "?fid=files&act=json&op=description&id=" + file_id,
		                                function(data)
		                                {
		                                    data = $.parseJSON(data);
		                                    navigate_contextmenu_description_dialog(file_id, $("#' . $name . '-droppable"), data.title, data.description);
		                                }
		                            );
		                            break;
		                        }
		                    });
                        }, 100);
                    });
                ');
            } else {
                if ($media == 'video') {
                    $out[] = '
                    <div class="navigate-droppable-create">
                        <img src="img/icons/silk/add.png" />
                        <ul class="navigate-droppable-create-contextmenu" data-field-id="' . $name . '">
                            <li action="default" value="' . $default_value . '"><a href="#"><span class="fa fa-lg fa-eraser"></span> ' . t(199, "Default value") . '</a></li>
                            <li action="youtube_url"><a href="#"><span class="fa fa-lg fa-youtube-square fa-align-center"></span> Youtube URL</a></li>
                            <li action="vimeo_url"><a href="#"><span class="fa fa-lg fa-vimeo-square fa-align-center"></span> Vimeo URL</a></li>
                        </ul>
                    </div>
                ';
                    // context menu actions
                    $layout->add_script('
                    if(' . (empty($default_value) ? 'true' : 'false') . ')
                        $("#' . $name . '-droppable").parent().find(".navigate-droppable-create-contextmenu li[action=default]").remove();

                    $("#' . $name . '-droppable").parent()
                        .find(".navigate-droppable-create")
                        .find(".navigate-droppable-create-contextmenu li")
                        .on("click", function()
                        {
                            setTimeout(function() { navigate_hide_context_menus(); }, 100);

                            switch($(this).attr("action"))
                            {
                                case "default":
                                    $("#' . $name . '-droppable").html(\'<figure class="navigatecms_loader"></figure>\');
                                    navigate_dropbox_load_video("' . $name . '", "' . $default_value . '");
                                    break;

                                case "youtube_url":
                                    $("<div><form action=\\"#\\" onsubmit=\\"return false;\\"><input type=\\"text\\" name=\\"url\\" value=\\"\\" style=\\"width: 100%;\\" /></form></div>").dialog({
                                        "title": "Youtube URL",
                                        "modal": true,
                                        "width": 500,
                                        "height": 120,
                                        "buttons": {
                                            "' . t(190, "Ok") . '": function(e, ui)
                                            {
                                                var reference = navigate_youtube_reference_from_url($(this).find("input").val());
                                                if(reference && reference!="")
                                                {
                                                    $("#' . $name . '-droppable").html(\'<figure class="navigatecms_loader"></figure>\');
                                                    navigate_dropbox_load_video("' . $name . '", "youtube#" + reference);
                                                }
                                                $(this).dialog("close");
                                            },
                                            "' . t(58, "Cancel") . '": function() { $(this).dialog("close"); }
                                        }
                                    });
                                    break;

                                case "vimeo_url":
                                    $("<div><form action=\\"#\\" onsubmit=\\"return false;\\"><input type=\\"text\\" name=\\"url\\" value=\\"\\" style=\\"width: 100%;\\" /></form></div>").dialog({
                                        "title": "Vimeo URL",
                                        "modal": true,
                                        "width": 500,
                                        "height": 120,
                                        "buttons": {
                                            "' . t(190, "Ok") . '": function(e, ui)
                                            {
                                                var reference = navigate_vimeo_reference_from_url($(this).find("input").val());
                                                if(reference && reference!="")
                                                {
                                                    $("#' . $name . '-droppable").html(\'<figure class="navigatecms_loader"></figure>\');
                                                    navigate_dropbox_load_video("' . $name . '", "vimeo#" + reference);
                                                }
                                                $(this).dialog("close");
                                            },
                                            "' . t(58, "Cancel") . '": function() { $(this).dialog("close"); }
                                        }
                                    });
                                    break;
                            }
                        }
                    );
                ');
                    $contextmenu = true;
                }
            }
            $layout->add_script('
				$("#' . $name . '-droppable").parent().find(".navigate-droppable-cancel").on("click", function()
				{
					$("#' . $name . '").val("0");
					$("#' . $name . '-droppable").html(\'<img src="img/icons/misc/dropbox.png" vspace="18" />\');
					$("#' . $name . '-droppable").parent().find(".navigate-droppable-cancel").hide();
					$("#' . $name . '-droppable").parent().find(".navigate-droppable-create").show();
					$("#' . $name . '-droppable-info").children().html("");
					navigate_media_browser_refresh_files_used();
				});

				$("#' . $name . '-droppable").parent().find(".navigate-droppable-create").on("click", function(ev)
				{
                    navigate_hide_context_menus();
                    $("ul[data-context-menu-temporary-clone=true]").remove();

                    setTimeout(function()
                    {
                        var menu_el = $("#' . $name . '-droppable").parent().find(".navigate-droppable-create-contextmenu");

                        menu_el.menu();

                        menu_el.css({
                            "z-index": 100000,
                            "position": "absolute"
                        }).addClass("navi-ui-widget-shadow").show();
                    }, 100);
				});
			');
            if (!empty($media)) {
                $accept = 'accept: ".draggable-' . $media . '",';
            }
            $layout->add_script('
				$("#' . $name . '-droppable").droppable(
				{
					' . $accept . '
					hoverClass: "navigate-droppable-hover",
					drop: function(event, ui) 
					{
						var file_id = $(ui.draggable).attr("id").substring(5);
						$("#' . $name . '").val(file_id);
						var draggable_content = $(ui.draggable);

						if($(draggable_content).find(".file-image-wrapper").length > 0)
						{
						    draggable_content = $(draggable_content).find(".file-image-wrapper").html();
                        }
                        else
                        {
                            draggable_content = $(ui.draggable).html();
                        }

						$(this).html(draggable_content);
						$(this).find("div.file-access-icons").remove();

						$("#' . $name . '-droppable").parent().find(".navigate-droppable-cancel").show();
					    $("#' . $name . '-droppable").parent().find(".navigate-droppable-create").hide();
                        $("#' . $name . '-droppable-info").find(".navigate-droppable-info-title").html("");
                        $("#' . $name . '-droppable-info").find(".navigate-droppable-info-provider").html("");
                        $("#' . $name . '-droppable-info").find(".navigate-droppable-info-extra").html("");
					}
				});
			');
            if (empty($value) && $contextmenu) {
                $layout->add_script('
                    $("#' . $name . '-droppable").parent().find(".navigate-droppable-create").show();
                    $("#' . $name . '-droppable").parent().find(".navigate-droppable-cancel").hide();
                ');
            } else {
                if (!empty($value)) {
                    $layout->add_script('
                    $("#' . $name . '-droppable").parent().find(".navigate-droppable-cancel").show();
                    $("#' . $name . '-droppable").parent().find(".navigate-droppable-create").hide();
                ');
                }
            }
        }
        $out[] = '<div id="' . $name . '-droppable-info" class="navigate-droppable-info">';
        $out[] = '  <div class="navigate-droppable-info-title"></div>';
        $out[] = '  <div class="navigate-droppable-info-extra"></div>';
        $out[] = '  <div class="navigate-droppable-info-provider"></div>';
        $out[] = '</div>';
        $out[] = '</div>';
        // close droppable wrapper
        return implode("\n", $out);
    }
Пример #2
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;
}