예제 #1
0
/**
 * Executes a Navigate CMS function taking the 'fid' url parameter
 * fid can be the name of the package (p.e. "dashboard") or its numeric assignment (p.e. "6")
 * note: if no "fid" is found, then loads the first available menu function
 *
 * @return mixed Navigate CMS package output
 */
function core_run()
{
    global $layout;
    global $menu_layout;
    $content = "";
    $fid = 'dashboard';
    // default function
    if (isset($_REQUEST['fid'])) {
        $fid = $_REQUEST['fid'];
    }
    $f = core_load_function($fid);
    if (empty($f) && ($fid == "dashboard" || empty($fid))) {
        // load first function available
        $fid = $menu_layout->menus[0]->items[0]->codename;
        if (empty($fid)) {
            $fid = "unknown";
        } else {
            header('location: ' . NAVIGATE_MAIN . '?fid=' . $fid);
            core_terminate();
        }
    }
    if (file_exists('lib/packages/' . $f->codename . '/' . $f->codename . '.php')) {
        include 'lib/packages/' . $f->codename . '/' . $f->codename . '.php';
        $content = run();
    } else {
        $content = 'function ' . $fid . ': <strong>' . $f->codename . '</strong> has not been found!';
    }
    return $content;
}
예제 #2
0
    public static function action($function, $item = '', $action = '', $item_title = '', $data = '')
    {
        global $DB;
        global $website;
        global $user;
        $encoded_data = '';
        if ($action == 'save' && function_exists('gzencode')) {
            $encoded_data = gzencode($data);
        }
        // a blank (new) form requested
        if ($action == 'load' && empty($item)) {
            return true;
        }
        $wid = $website->id;
        if (empty($wid)) {
            $wid = 0;
        }
        $uid = $user->id;
        if (empty($uid)) {
            $uid = 0;
        }
        if (!is_numeric($function)) {
            $func = core_load_function($function);
            $function = $func->id;
        }
        // prepared statement
        $ok = $DB->execute(' 
 			INSERT INTO nv_users_log
				(id, `date`, user, website, `function`, item, action, item_title, data)
			VALUES 
				( ?, ?, ?, ?, ?, ?, ?, ?, ?	)', array(0, core_time(), $uid, $wid, $function, value_or_default($item, ""), value_or_default($action, ""), value_or_default((string) $item_title, ""), value_or_default($encoded_data, "")));
        if (!$ok) {
            throw new Exception($DB->get_last_error());
        }
        return true;
    }
예제 #3
0
    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);
    }