コード例 #1
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);
    }
コード例 #2
0
ファイル: items.php プロジェクト: NavigateCMS/Navigate-CMS
function run()
{
    global $layout;
    global $DB;
    global $website;
    global $theme;
    global $user;
    $out = '';
    $item = new item();
    switch ($_REQUEST['act']) {
        case 'json':
        case 1:
            // json data retrieval & operations
            switch ($_REQUEST['oper']) {
                case 'del':
                    // remove rows
                    $ids = $_REQUEST['ids'];
                    foreach ($ids as $id) {
                        $item->load($id);
                        $item->delete();
                    }
                    echo json_encode(true);
                    break;
                default:
                    // list or search
                    // translation of request search & order fields
                    switch ($_REQUEST['searchField']) {
                        case 'id':
                            $_REQUEST['searchField'] = 'i.id';
                            break;
                        case 'title':
                            $_REQUEST['searchField'] = 'd.text';
                            break;
                        case 'language':
                            $_REQUEST['searchField'] = 'd.lang';
                            break;
                        case 'category':
                            $_REQUEST['searchField'] = 'i.category';
                            break;
                        case 'dates':
                            $_REQUEST['searchField'] = 'i.date_published';
                            break;
                        case 'permission':
                            $_REQUEST['searchField'] = 'i.permission';
                            break;
                        default:
                    }
                    if ($_REQUEST['sidx'] == 'dates') {
                        $_REQUEST['sidx'] = 'i.date_published';
                    }
                    $page = intval($_REQUEST['page']);
                    $max = intval($_REQUEST['rows']);
                    $offset = ($page - 1) * $max;
                    $orderby = $_REQUEST['sidx'] . ' ' . $_REQUEST['sord'];
                    $where = ' i.website = ' . $website->id;
                    if ($_REQUEST['_search'] == 'true' || isset($_REQUEST['quicksearch'])) {
                        if (isset($_REQUEST['quicksearch'])) {
                            $where .= $item->quicksearch($_REQUEST['quicksearch']);
                        } else {
                            if (isset($_REQUEST['filters'])) {
                                if (is_array($_REQUEST['filters'])) {
                                    $filters = json_decode(json_encode($_REQUEST['filters']), FALSE);
                                } else {
                                    $filters = json_decode($_REQUEST['filters']);
                                }
                                for ($r = 0; $r < count($filters->rules); $r++) {
                                    switch ($filters->rules[$r]->field) {
                                        case 'id':
                                            $filters->rules[$r]->field = 'i.id';
                                            break;
                                        case 'title':
                                            $filters->rules[$r]->field = 'd.text';
                                            break;
                                        case 'language':
                                            $filters->rules[$r]->field = 'd.lang';
                                            break;
                                        case 'category':
                                            $filters->rules[$r]->field = 'i.category';
                                            break;
                                        case 'dates':
                                            $filters->rules[$r]->field = 'i.date_published';
                                            break;
                                        case 'permission':
                                            $filters->rules[$r]->field = 'i.permission';
                                            break;
                                        default:
                                    }
                                }
                                $where .= navitable::jqgridsearch(json_encode($filters));
                            } else {
                                // single search
                                $where .= ' AND ' . navitable::jqgridcompare($_REQUEST['searchField'], $_REQUEST['searchOper'], $_REQUEST['searchString']);
                            }
                        }
                    }
                    $sql = ' SELECT SQL_CALC_FOUND_ROWS
					                i.*, d.text as title, d.lang as language,
                                    u.username as author_username,
                                    (   SELECT COUNT(*)
                                        FROM nv_comments cm
                                        WHERE cm.item = i.id
                                          AND cm.website = ' . $website->id . '
                                    ) as comments
							   FROM nv_items i
						  LEFT JOIN nv_webdictionary d
						  		 	 ON i.id = d.node_id
								 	AND d.node_type = "item"
									AND d.subtype = "title"
									AND d.lang = "' . $website->languages_list[0] . '"
									AND d.website = ' . $website->id . '
						  LEFT JOIN nv_users u
						  			 ON u.id = i.author
							  WHERE ' . $where . '	
						   GROUP BY i.id, d.text, d.lang, u.username						   
						   ORDER BY ' . $orderby . ' 
							  LIMIT ' . $max . '
							 OFFSET ' . $offset;
                    if (!$DB->query($sql, 'array')) {
                        throw new Exception($DB->get_last_error());
                    }
                    $dataset = $DB->result();
                    $total = $DB->foundRows();
                    $dataset = grid_notes::summary($dataset, 'item', 'id');
                    $access = array(0 => '<img src="img/icons/silk/page_white_go.png" align="absmiddle" title="' . t(254, 'Everybody') . '" />', 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 => '<img src="img/icons/silk/world.png" align="absmiddle" /> ' . t(69, 'Published'), 1 => '<img src="img/icons/silk/world_dawn.png" align="absmiddle" /> ' . t(70, 'Private'), 2 => '<img src="img/icons/silk/world_night.png" align="absmiddle" /> ' . t(81, 'Hidden'));
                    $hierarchy = structure::hierarchy(0);
                    // we need to format the values and retrieve the needed strings from the dictionary
                    $out = array();
                    for ($i = 0; $i < count($dataset); $i++) {
                        if (empty($dataset[$i])) {
                            continue;
                        }
                        if (empty($dataset[$i]['date_published'])) {
                            $dataset[$i]['date_published'] = '&infin;';
                        } else {
                            $dataset[$i]['date_published'] = core_ts2date($dataset[$i]['date_published'], false);
                        }
                        if (empty($dataset[$i]['date_unpublish'])) {
                            $dataset[$i]['date_unpublish'] = '&infin;';
                        } else {
                            $dataset[$i]['date_unpublish'] = core_ts2date($dataset[$i]['date_unpublish'], false);
                        }
                        if (empty($dataset[$i]['date_to_display'])) {
                            $dataset[$i]['date_to_display'] = '';
                        } else {
                            $dataset[$i]['date_to_display'] = core_ts2date($dataset[$i]['date_to_display'], false);
                        }
                        if ($dataset[$i]['category'] > 0) {
                            $category_path = structure::hierarchyPath($hierarchy, $dataset[$i]['category']);
                            if (is_array($category_path)) {
                                $dataset[$i]['category_path'] = implode(' › ', $category_path);
                            } else {
                                $dataset[$i]['category_path'] = $category_path;
                            }
                        }
                        $category_text = '';
                        if ($dataset[$i]['association'] == 'free') {
                            $category_text = '[ ' . strtolower(t(100, 'Free')) . ' ]';
                        } else {
                            $category_text = $dataset[$i]['category_path'];
                        }
                        $item_views = $dataset[$i]['views'];
                        if ($item_views > 1000) {
                            $item_views = round($item_views / 1000) . "K";
                        }
                        $item_comments = $dataset[$i]['comments'];
                        if ($item_comments > 1000) {
                            $item_comments = round($item_comments / 1000) . "K";
                        }
                        //$social_rating = '<img src="img/icons/silk/star.png" align="absmiddle" width="12px" height="12px" /> '.
                        //    '<span style="font-size: 90%;">'.$dataset[$i]['score'].' ('.$dataset[$i]['votes'].')</span>';
                        //$social_rating = '<i class="fa fa-fw fa-eye" /> <span style="font-size: 90%;">'.$dataset[$i]['views'].'</span>';
                        $social_rating = '<img src="img/icons/silk/eye.png" align="absmiddle" width="12px" height="12px" /> ' . '<span style="font-size: 90%;">' . $item_views . '</span>';
                        //$social_comments = '<i class="fa fa-fw fa-comments-o" /> <span style="font-size: 90%;">'.$dataset[$i]['comments'].'</span>';
                        $social_comments = '<img src="img/icons/silk/comments.png" align="absmiddle" width="12px" height="12px" /> ' . '<span style="font-size: 90%;">' . $item_comments . '</span>';
                        if (empty($dataset[$i]['title'])) {
                            // if title is empty for the default language,
                            // try to load the title in another language
                            $DB->query('
                                SELECT lang, text
                                  FROM nv_webdictionary
                                 WHERE website = ' . $website->id . ' AND
                                        node_type = "item" AND
                                        subtype="title" AND
                                        node_id = ' . $dataset[$i]['id'] . ' AND
                                        text != ""
                                ORDER BY id ASC');
                            $titles = $DB->result();
                            if (!empty($titles)) {
                                $dataset[$i]['title'] = '<img src="img/icons/silk/comment.png" align="absmiddle" />';
                                $dataset[$i]['title'] .= '<small>' . $titles[0]->lang . '</small>&nbsp;&nbsp;';
                                $dataset[$i]['title'] .= $titles[0]->text;
                            }
                        }
                        $out[$i] = array(0 => $dataset[$i]['id'], 1 => '<div class="list-row" data-permission="' . $dataset[$i]['permission'] . '">' . $dataset[$i]['title'] . '</div>', 2 => $social_rating . '&nbsp;&nbsp;' . $social_comments, 3 => $category_text, 4 => $dataset[$i]['date_to_display'], 5 => $dataset[$i]['date_published'] . ' - ' . $dataset[$i]['date_unpublish'], 6 => $access[$dataset[$i]['access']] . ' ' . $permissions[$dataset[$i]['permission']], 7 => $dataset[$i]['_grid_notes_html']);
                    }
                    navitable::jqgridJson($out, $page, $offset, $max, $total);
                    break;
            }
            core_terminate();
            break;
        case 'load':
        case 'create':
        case 'edit':
        case 2:
            // edit/new form
            if (!empty($_REQUEST['id'])) {
                $item->load(intval($_REQUEST['id']));
                if ($user->permission("items.edit") == "false" && $item->author != $user->id) {
                    $layout->navigate_notification(t(610, "Sorry, you are not allowed to execute the requested function"), true);
                    $_REQUEST['act'] = 'list';
                    return run();
                }
                // check if the current user can edit this item
                if ($item->association == 'category' && !empty($item->category)) {
                    if (!structure::category_allowed($item->category)) {
                        $layout->navigate_notification(t(610, "Sorry, you are not allowed to execute the requested function"), true);
                        $_REQUEST['act'] = 'list';
                        return run();
                    }
                }
            }
            if (isset($_REQUEST['form-sent'])) {
                $item->load_from_post();
                try {
                    $item->save();
                    property::save_properties_from_post('item', $item->id);
                    if (!empty($_REQUEST['items-order'])) {
                        item::reorder($_REQUEST['items-order']);
                    }
                    $layout->navigate_notification(t(53, "Data saved successfully."), false, false, 'fa fa-check');
                    $item->load($item->id);
                    users_log::action($_REQUEST['fid'], $item->id, 'save', $item->dictionary[$website->languages_list[0]]['title'], json_encode($_REQUEST));
                } catch (Exception $e) {
                    $layout->navigate_notification($e->getMessage(), true, true);
                }
            } else {
                users_log::action($_REQUEST['fid'], $item->id, 'load', $item->dictionary[$website->languages_list[0]]['title']);
            }
            $out = items_form($item);
            break;
        case 'delete':
        case 4:
            // remove
            if (!empty($_REQUEST['id'])) {
                $item->load(intval($_REQUEST['id']));
                try {
                    if (!empty($item->id)) {
                        $deleted = $item->delete() > 0;
                        if ($deleted) {
                            $layout->navigate_notification(t(55, 'Item removed successfully.'), false);
                            $out = items_list();
                            users_log::action($_REQUEST['fid'], $item->id, 'remove', $item->dictionary[$website->languages_list[0]]['title'], json_encode($_REQUEST));
                        }
                    }
                    if (!$deleted) {
                        $layout->navigate_notification(t(56, 'Unexpected error.'), false);
                        if (!empty($item->id)) {
                            $out = items_form($item);
                        } else {
                            $out = items_list();
                        }
                    }
                } catch (Exception $e) {
                    $layout->navigate_notification($e->getMessage(), true);
                    if (!empty($item->id)) {
                        $out = items_form($item);
                    }
                }
            }
            break;
        case 'duplicate':
            if (!empty($_REQUEST['id'])) {
                $item->load(intval($_REQUEST['id']));
                if ($item->association == 'category' && $item->embedding == 1) {
                    // get structure template
                    $category = new structure();
                    $category->load($item->category);
                    $properties = property::load_properties_associative('structure', $category->template, 'item', $item->id);
                } else {
                    $properties = property::load_properties_associative('item', $item->template, 'item', $item->id);
                }
                // try to duplicate
                $item->id = 0;
                $ok = $item->insert();
                if ($ok) {
                    // duplicate item properties too (but don't duplicate comments)
                    if ($item->association == 'category' && $item->embedding == 1) {
                        $ok = property::save_properties_from_array('item', $item->id, $category->template, $properties);
                    } else {
                        $ok = property::save_properties_from_array('item', $item->id, $item->template, $properties);
                    }
                }
                if ($ok) {
                    $layout->navigate_notification(t(478, 'Item duplicated successfully.'), false, false, 'fa fa-check');
                    $out = items_form($item);
                } else {
                    $layout->navigate_notification(t(56, 'Unexpected error.'), false);
                    $item = new item();
                    $item->load(intval($_REQUEST['id']));
                    $out = items_form($item);
                }
                users_log::action($_REQUEST['fid'], $item->id, 'duplicate', $item->dictionary[$website->languages_list[0]]['title'], json_encode($_REQUEST));
            }
            break;
        case 89:
            if (!empty($_REQUEST['id'])) {
                $DB->execute('DELETE FROM nv_webdictionary_history WHERE id = ' . intval($_REQUEST['id']) . ' LIMIT 1');
                echo 'true';
            } else {
                echo 'false';
            }
            core_terminate();
            break;
        case 90:
            $DB->query('SELECT id, date_created, autosave
						  FROM nv_webdictionary_history
						 WHERE node_type = "item"
						   AND subtype = ' . protect('section-' . $_REQUEST['section']) . '
						   AND lang = ' . protect($_GET['lang']) . '
						   AND node_id = ' . protect($_REQUEST['id']) . '
						   AND website = ' . $website->id . ' 
				      ORDER BY date_created DESC', 'array');
            $result = $DB->result();
            if (!is_array($result)) {
                $result = array();
            }
            for ($i = 0; $i < count($result); $i++) {
                $result[$i]['date'] = core_ts2date($result[$i]['date_created'], true);
                if ($result[$i]['autosave'] == 1) {
                    $result[$i]['date'] .= ' (' . t(273, 'Autosave') . ')';
                }
            }
            echo json_encode($result);
            core_terminate();
            break;
        case "search_by_title":
        case 91:
            // json search title request (for "copy from" dialog)
            $DB->query('
				SELECT node_id as id, text as label, text as value
				  FROM nv_webdictionary
				 WHERE node_type = "item"
				   AND subtype = "title"
				   AND lang = ' . protect($_REQUEST['lang']) . '
				   AND website = ' . $website->id . '
				   AND text LIKE ' . protect('%' . $_REQUEST['title'] . '%') . '
		      ORDER BY text ASC
			     LIMIT 20', 'array');
            echo json_encode($DB->result());
            core_terminate();
            break;
        case "raw_zone_content":
            // return raw item contents
            if (empty($_REQUEST['section'])) {
                $_REQUEST['section'] = 'main';
            }
            if ($_REQUEST['history'] == 'true') {
                $DB->query('SELECT text
							  FROM nv_webdictionary_history
							 WHERE node_type = "item"
							   AND website = ' . $website->id . ' 
							   AND id = ' . protect($_REQUEST['id']), 'array');
                $data = $DB->first();
                echo $data['text'];
            } else {
                if ($_REQUEST['zone'] == 'section') {
                    $DB->query('SELECT text
							  FROM nv_webdictionary
							 WHERE node_type = "item"
							   AND subtype = ' . protect('section-' . $_REQUEST['section']) . '
							   AND lang = ' . protect($_REQUEST['lang']) . '
							   AND website = ' . $website->id . ' 
							   AND node_id = ' . protect($_REQUEST['node_id']), 'array');
                    $data = $DB->first();
                    echo $data['text'];
                } else {
                    if ($_REQUEST['zone'] == 'property') {
                        $DB->query('SELECT text
							  FROM nv_webdictionary
							 WHERE node_type = "property-item"
							   AND subtype = ' . protect('property-' . $_REQUEST['section'] . '-' . $_REQUEST['lang']) . '
							   AND lang = ' . protect($_REQUEST['lang']) . '
							   AND website = ' . $website->id . '
							   AND node_id = ' . protect($_REQUEST['node_id']), 'array');
                        $data = $DB->first();
                        echo $data['text'];
                    }
                }
            }
            core_terminate();
            break;
            // return raw template content
        // return raw template content
        case 93:
            $DB->query('SELECT file
						  FROM nv_templates
						 WHERE enabled = 1
						   AND id = ' . protect($_REQUEST['id']) . '
						   AND website = ' . $website->id, 'array');
            $data = $DB->first();
            echo @file_get_contents(NAVIGATE_PRIVATE . '/' . $website->id . '/templates/' . $data['file']);
            core_terminate();
            break;
        case "copy_from_template_zones":
            // return template sections and (textarea) properties for a content id
            $item = new item();
            $item->load(intval($_REQUEST['id']));
            $template = $item->load_template();
            $zones = array();
            for ($ts = 0; $ts < count($template->sections); $ts++) {
                $title = $template->sections[$ts]['name'];
                if (!empty($theme)) {
                    $title = $theme->t($title);
                }
                if ($title == '#main#') {
                    $title = t(238, 'Main content');
                }
                $zones[] = array('type' => 'section', 'id' => $template->sections[$ts]['id'], 'title' => $title);
            }
            for ($ps = 0; $ps < count($template->properties); $ps++) {
                // ignore structure properties
                if (isset($template->properties[$ps]->element) && $template->properties[$ps]->element != 'item') {
                    continue;
                }
                // ignore non-textual properties
                if (!in_array($template->properties[$ps]->type, array("text", "textarea", "rich_textarea"))) {
                    continue;
                }
                $title = $template->properties[$ps]->name;
                if (!empty($theme)) {
                    $title = $theme->t($title);
                }
                $zones[] = array('type' => 'property', 'id' => $template->properties[$ps]->id, 'title' => $title);
            }
            echo json_encode($zones);
            core_terminate();
            break;
        case 95:
            // free path checking
            $path = $_REQUEST['path'];
            $id = $_REQUEST['id'];
            $DB->query('SELECT type, object_id, lang
	 					  FROM nv_paths
						 WHERE path = ' . protect($path) . '
						   AND website = ' . $website->id);
            $rs = $DB->result();
            echo json_encode($rs);
            core_terminate();
            break;
        case 96:
            // return category paths
            echo json_encode(path::loadElementPaths('structure', intval($_REQUEST['id'])));
            core_terminate();
            break;
        case 'json_find_user':
            // json find user by name request (for "moderator" autocomplete)
            $DB->query('
				SELECT id, username as text
				  FROM nv_users
				 WHERE username LIKE ' . protect('%' . $_REQUEST['username'] . '%') . '
		      ORDER BY username ASC
			     LIMIT 30', 'array
			');
            $rows = $DB->result();
            $total = $DB->foundRows();
            echo json_encode(array('items' => $rows, 'total_count' => $total));
            core_terminate();
            break;
        case 'json_find_item':
            // find items by its title
            // any language
            $template_filter = '';
            if (!empty($_REQUEST['template'])) {
                $template_filter = ' AND nvi.template = ' . protect($_REQUEST['template']) . ' ';
            }
            if (!empty($_REQUEST['association'])) {
                $template_filter = ' AND nvi.association = ' . protect($_REQUEST['association']) . ' ';
            }
            if (isset($_REQUEST['embedding'])) {
                $template_filter = ' AND nvi.embedding = ' . protect($_REQUEST['embedding']) . ' ';
            }
            $text = $_REQUEST['title'];
            if (!empty($_REQUEST['term'])) {
                // tagit request
                $text = $_REQUEST['term'];
            }
            $DB->query('
				SELECT SQL_CALC_FOUND_ROWS DISTINCT nvw.node_id as id, nvw.text as text
				  FROM nv_webdictionary nvw, nv_items nvi
				 WHERE nvw.node_type = "item"
				   AND nvw.node_id = nvi.id
				   ' . $template_filter . '
				   AND nvw.subtype = "title"
				   AND nvw.website = ' . $website->id . '
				   AND nvw.website = nvi.website
				   AND nvw.text LIKE ' . protect('%' . $text . '%') . '
		        GROUP BY nvw.node_id, nvw.text
		        ORDER BY nvw.text ASC
			     LIMIT ' . intval($_REQUEST['page_limit']) . '
			     OFFSET ' . max(0, intval($_REQUEST['page_limit']) * (intval($_REQUEST['page']) - 1)), 'array');
            $rows = $DB->result();
            $total = $DB->foundRows();
            if ($_REQUEST['association'] == 'free') {
                for ($i = 0; $i < count($rows); $i++) {
                    $rows[$i]['path'] = $DB->query_single('path', 'nv_paths', '	website = ' . protect($website->id) . ' AND 
							type="item" AND 
							object_id="' . $rows[$i]['id'] . '" AND 
							lang="' . $website->languages_list[0] . '"
						');
                    if (empty($rows[$i]['path'])) {
                        $rows[$i]['path'] = '/node/' . $rows[$i]['id'];
                    }
                }
            }
            if (empty($_REQUEST['format']) || $_REQUEST['format'] == 'select2') {
                echo json_encode(array('items' => $rows, 'totalCount' => $total));
            } else {
                if ($_REQUEST['format'] == 'tagit') {
                    $tags_json = array();
                    foreach ($rows as $row) {
                        $tags_json[] = json_decode('{ "id": "' . $row['id'] . '", "label": "' . $row['text'] . '", "value": "' . $row['text'] . '" }');
                    }
                    echo json_encode($tags_json);
                }
            }
            core_terminate();
            break;
        case 98:
            // change comment status
            if (empty($_REQUEST['id'])) {
                echo "false";
                core_terminate();
            }
            switch ($_REQUEST['opt']) {
                case 'publish':
                    $DB->execute('
						UPDATE nv_comments
						   SET status = 0
						 WHERE website = ' . $website->id . ' AND
						       id = ' . $_REQUEST['id']);
                    break;
                case 'unpublish':
                    $DB->execute('
						UPDATE nv_comments
						   SET status = 1
						 WHERE website = ' . $website->id . ' AND
						       id = ' . $_REQUEST['id']);
                    break;
                case 'delete':
                    $DB->execute('
						DELETE FROM nv_comments
						 WHERE website = ' . $website->id . ' AND
							   id = ' . $_REQUEST['id']);
                    break;
            }
            $error = $DB->get_last_error();
            if (empty($error)) {
                echo 'true';
            } else {
                echo 'false';
            }
            core_terminate();
            break;
        case 'autosave':
            if (!empty($_REQUEST['id'])) {
                $iDictionary = array();
                foreach ($_REQUEST as $key => $value) {
                    if (strpos($key, 'section-') === 0) {
                        $lang = substr($key, -2, 2);
                        $kname = substr($key, 0, strlen($key) - 3);
                        $iDictionary[$lang][$kname] = $value;
                    }
                }
                $changed = webdictionary_history::save_element_strings('item', intval($_REQUEST['id']), $iDictionary, true);
                if ($changed) {
                    echo 'changes_saved';
                } else {
                    echo 'no_changes';
                }
                core_terminate();
            }
            echo 'false';
            core_terminate();
            break;
        case 'votes_reset':
            webuser_vote::remove_object_votes('item', intval($_REQUEST['id']));
            echo 'true';
            core_terminate();
            break;
        case 'votes_by_webuser':
            if ($_POST['oper'] == 'del') {
                $ids = explode(',', $_POST['id']);
                for ($i = 0; $i < count($ids); $i++) {
                    if ($ids[$i] > 0) {
                        $vote = new webuser_vote();
                        $vote->load($ids[$i]);
                        $vote->delete();
                    }
                }
                webuser_vote::update_object_score('item', $vote->object_id);
                echo 'true';
                core_terminate();
            }
            $max = intval($_GET['rows']);
            $page = intval($_GET['page']);
            $offset = ($page - 1) * $max;
            if ($_REQUEST['_search'] == 'false') {
                list($dataset, $total) = webuser_vote::object_votes_by_webuser('item', intval($_REQUEST['id']), $_REQUEST['sidx'] . ' ' . $_REQUEST['sord'], $offset, $max);
            }
            $out = array();
            for ($i = 0; $i < count($dataset); $i++) {
                if (empty($dataset[$i])) {
                    continue;
                }
                $out[$i] = array(0 => $dataset[$i]['id'], 1 => core_ts2date($dataset[$i]['date'], true), 2 => $dataset[$i]['username']);
            }
            navitable::jqgridJson($out, $page, $offset, $max, $total);
            core_terminate();
            break;
        case 'items_order':
            if (!empty($_POST['items-order'])) {
                // save new order
                $response = item::reorder($_POST['items-order']);
                if ($response !== true) {
                    echo $response['error'];
                } else {
                    echo 'true';
                }
            } else {
                // show ordered list
                echo items_order($_REQUEST['category']);
            }
            core_terminate();
            break;
        case 'json_tags_search':
            $tags = nvweb_tags_retrieve(null, null, 'top', $_REQUEST['term'], $_REQUEST['lang']);
            $tags_json = array();
            foreach (array_keys($tags) as $tag) {
                $tags_json[] = json_decode('{ "id": "' . $tag . '", "label": "' . $tag . '", "value": "' . $tag . '" }');
            }
            echo json_encode($tags_json);
            core_terminate();
            break;
        case 'json_tags_ranking':
            $tags = nvweb_tags_retrieve(100, null, 'top', null, $_REQUEST['lang']);
            $tags = array_keys($tags);
            echo json_encode($tags);
            core_terminate();
            break;
        case 'list':
        case 0:
            // list / search result
        // list / search result
        default:
            $out = items_list();
            break;
    }
    return $out;
}
コード例 #3
0
ファイル: webusers.php プロジェクト: NavigateCMS/Navigate-CMS
function run()
{
    global $user;
    global $layout;
    global $DB;
    global $website;
    $out = '';
    $item = new webuser();
    switch ($_REQUEST['act']) {
        // json data retrieval & operations
        case 'json':
        case 1:
            switch ($_REQUEST['oper']) {
                case 'del':
                    // remove rows
                    $ids = $_REQUEST['ids'];
                    foreach ($ids as $id) {
                        $item->load($id);
                        $item->delete();
                    }
                    echo json_encode(true);
                    break;
                default:
                    // list or search
                    $page = intval($_REQUEST['page']);
                    $max = intval($_REQUEST['rows']);
                    $offset = ($page - 1) * $max;
                    $orderby = $_REQUEST['sidx'] . ' ' . $_REQUEST['sord'];
                    $where = ' website = ' . $website->id;
                    if ($_REQUEST['_search'] == 'true' || isset($_REQUEST['quicksearch'])) {
                        if (isset($_REQUEST['quicksearch'])) {
                            $where .= $item->quicksearch($_REQUEST['quicksearch']);
                        } else {
                            if (isset($_REQUEST['filters'])) {
                                $filters = $_REQUEST['filters'];
                                if (is_array($filters)) {
                                    $filters = json_encode($filters);
                                }
                                $where .= navitable::jqgridsearch($filters);
                            } else {
                                // single search
                                $where .= ' AND ' . navitable::jqgridcompare($_REQUEST['searchField'], $_REQUEST['searchOper'], $_REQUEST['searchString']);
                            }
                        }
                    }
                    $DB->queryLimit('id,avatar,username,email,fullname,groups,joindate,access,access_begin,access_end', 'nv_webusers', $where, $orderby, $offset, $max);
                    $dataset = $DB->result();
                    $total = $DB->foundRows();
                    $dataset = grid_notes::summary($dataset, 'webuser', 'id');
                    global $webusers_groups_all;
                    $webusers_groups_all = webuser_group::all_in_array();
                    //echo $DB->get_last_error();
                    $out = array();
                    for ($i = 0; $i < count($dataset); $i++) {
                        $wug = str_replace('g', '', $dataset[$i]['groups']);
                        $wug = explode(',', $wug);
                        $wug = array_map(function ($in) {
                            global $webusers_groups_all;
                            if (empty($in)) {
                                return;
                            }
                            return $webusers_groups_all[$in];
                        }, $wug);
                        $blocked = 1;
                        if ($dataset[$i]['access'] == 0 || $dataset[$i]['access'] == 2 && ($dataset[$i]['access_begin'] == 0 || $dataset[$i]['access_begin'] < time()) && ($dataset[$i]['access_end'] == 0 || $dataset[$i]['access_end'] > time())) {
                            $blocked = 0;
                        }
                        $out[$i] = array(0 => $dataset[$i]['id'], 1 => empty($dataset[$i]['avatar']) ? '' : '<img title="' . $dataset[$i]['username'] . '" src="' . NAVIGATE_DOWNLOAD . '?wid=' . $website->id . '&id=' . urlencode($dataset[$i]['avatar']) . '&amp;disposition=inline&amp;width=32&amp;height=32" />', 2 => '<div class="list-row" data-blocked="' . $blocked . '" title="' . $dataset[$i]['email'] . '">' . $dataset[$i]['username'] . '</div>', 3 => $dataset[$i]['fullname'], 4 => implode("<br />", $wug), 5 => core_ts2date($dataset[$i]['joindate'], true), 6 => $blocked == 0 ? '<img src="img/icons/silk/accept.png" />' : '<img src="img/icons/silk/cancel.png" />', 7 => $dataset[$i]['_grid_notes_html']);
                    }
                    navitable::jqgridJson($out, $page, $offset, $max, $total);
                    break;
            }
            session_write_close();
            exit;
            break;
        case 2:
            // edit/new form
        // edit/new form
        case 'create':
        case 'edit':
            if (!empty($_REQUEST['id'])) {
                $item->load(intval($_REQUEST['id']));
            }
            if (isset($_REQUEST['form-sent'])) {
                $item->load_from_post();
                try {
                    $item->save();
                    property::save_properties_from_post('webuser', $item->id);
                    $layout->navigate_notification(t(53, "Data saved successfully."), false, false, 'fa fa-check');
                } catch (Exception $e) {
                    $layout->navigate_notification($e->getMessage(), true, true);
                }
                if (!empty($item->id)) {
                    users_log::action($_REQUEST['fid'], $item->id, 'save', $item->username, json_encode($_REQUEST));
                }
            } else {
                if (!empty($item->id)) {
                    users_log::action($_REQUEST['fid'], $item->id, 'load', $item->username);
                }
            }
            $out = webusers_form($item);
            break;
        case 4:
            // remove
        // remove
        case 'remove':
            if (!empty($_REQUEST['id'])) {
                $item->load(intval($_REQUEST['id']));
                if ($item->delete() > 0) {
                    $layout->navigate_notification(t(55, 'Item removed successfully.'), false);
                    $out = webusers_list();
                    users_log::action($_REQUEST['fid'], $item->id, 'remove', $item->username, json_encode($_REQUEST));
                } else {
                    $layout->navigate_notification(t(56, 'Unexpected error.'), false);
                    $out = webusers_form($item);
                }
            }
            break;
        case 90:
            // json request: timezones by country
            $timezones = property::timezones($_REQUEST['country']);
            if (empty($timezones)) {
                $timezones = property::timezones();
            }
            echo json_encode($timezones);
            core_terminate();
            break;
        case 'export':
            // export web users list to a CSV file
            users_log::action($_REQUEST['fid'], 0, 'export', "all", json_encode($_REQUEST));
            webuser::export();
            break;
        case 'webuser_groups_list':
            $out = webuser_groups_list();
            break;
        case 'webuser_groups_json':
            $page = intval($_REQUEST['page']);
            $max = intval($_REQUEST['rows']);
            $offset = ($page - 1) * $max;
            $rs = webuser_group::all($_REQUEST['sidx'], $_REQUEST['sord']);
            $dataset = array();
            foreach ($rs as $row) {
                $dataset[] = array('id' => $row->id, 'code' => $row->code, 'name' => $row->name);
            }
            $total = count($dataset);
            navitable::jqgridJson($dataset, $page, $offset, $max, $total, 'id');
            session_write_close();
            exit;
            break;
        case 'webuser_group_edit':
            $webuser_group = new webuser_group();
            if (!empty($_REQUEST['id'])) {
                $webuser_group->load(intval($_REQUEST['id']));
            }
            if (isset($_REQUEST['form-sent'])) {
                $webuser_group->load_from_post();
                try {
                    $ok = $webuser_group->save();
                    $layout->navigate_notification(t(53, "Data saved successfully."), false, false, 'fa fa-check');
                    users_log::action($_REQUEST['fid'], $webuser_group->id, 'save_webuser_group', $webuser_group->name, json_encode($_REQUEST));
                } catch (Exception $e) {
                    $layout->navigate_notification($e->getMessage(), true, true);
                }
            } else {
                users_log::action($_REQUEST['fid'], $webuser_group->id, 'load_webuser_group', $webuser_group->name, json_encode($_REQUEST));
            }
            $out = webuser_groups_form($webuser_group);
            break;
        case 'webuser_group_delete':
            $webuser_group = new webuser_group();
            if (!empty($_REQUEST['id'])) {
                $webuser_group->load(intval($_REQUEST['id']));
            }
            try {
                $webuser_group->delete();
                $layout->navigate_notification(t(55, 'Item removed successfully.'), false);
                $out = webuser_groups_list();
                users_log::action($_REQUEST['fid'], $webuser_group->id, 'remove_webuser_group', $webuser_group->name, json_encode($_REQUEST));
            } catch (Exception $e) {
                $out = $layout->navigate_message("error", t(24, 'Web users') . ' / ' . t(506, 'Groups'), t(56, 'Unexpected error.'));
            }
            break;
        case 0:
            // list / search result
        // list / search result
        case 'list':
        default:
            $out = webusers_list();
            break;
    }
    return $out;
}
コード例 #4
0
ファイル: blocks.php プロジェクト: NavigateCMS/Navigate-CMS
function run()
{
    global $layout;
    global $DB;
    global $website;
    $out = '';
    $item = new block();
    switch ($_REQUEST['act']) {
        case 'json':
        case 1:
            // json data retrieval & operations
            switch ($_REQUEST['oper']) {
                case 'del':
                    // remove rows
                    $ids = $_REQUEST['ids'];
                    foreach ($ids as $id) {
                        $item->load($id);
                        $item->delete();
                    }
                    echo json_encode(true);
                    break;
                default:
                    // list or search
                    // translation of request search & order fields
                    switch ($_REQUEST['searchField']) {
                        case 'id':
                            $_REQUEST['searchField'] = 'b.id';
                            break;
                        case 'type':
                            $_REQUEST['searchField'] = 'b.type';
                            break;
                        case 'title':
                            $_REQUEST['searchField'] = 'd.text';
                            break;
                        case 'category':
                            $_REQUEST['searchField'] = 'b.category';
                            break;
                        case 'dates':
                            $_REQUEST['searchField'] = 'b.date_published';
                            break;
                        case 'enabled':
                            $_REQUEST['searchField'] = 'b.enabled';
                            break;
                        case 'date_modified':
                        default:
                            $_REQUEST['searchField'] = 'b.date_modified';
                    }
                    if ($_REQUEST['sidx'] == 'dates') {
                        $_REQUEST['sidx'] = 'b.date_published';
                    }
                    $page = intval($_REQUEST['page']);
                    $max = intval($_REQUEST['rows']);
                    $offset = ($page - 1) * $max;
                    $orderby = $_REQUEST['sidx'] . ' ' . $_REQUEST['sord'];
                    $where = " 1=1 ";
                    if ($_REQUEST['_search'] == 'true' || isset($_REQUEST['quicksearch'])) {
                        if (isset($_REQUEST['quicksearch'])) {
                            $where .= $item->quicksearch($_REQUEST['quicksearch']);
                        } else {
                            if (isset($_REQUEST['filters'])) {
                                $where .= navitable::jqgridsearch($_REQUEST['filters']);
                                // special case
                                if (strpos($where, 'title LIKE') !== false) {
                                    $where = substr_replace($where, 'd.text', strpos($where, 'title LIKE'), 5);
                                }
                            } else {
                                // single search
                                $where .= ' AND ' . navitable::jqgridcompare($_REQUEST['searchField'], $_REQUEST['searchOper'], $_REQUEST['searchString']);
                            }
                        }
                    }
                    $sql = ' SELECT SQL_CALC_FOUND_ROWS b.*, d.text as title 
							   FROM nv_blocks b
						  LEFT JOIN nv_webdictionary d
						  		 	 ON b.id = d.node_id
								 	AND d.node_type = "block"
									AND d.subtype = "title"
									AND d.lang = "' . $website->languages_list[0] . '"
									AND d.website = ' . $website->id . '
							  WHERE ' . $where . '
							    AND b.website = ' . $website->id . ' 
						   ORDER BY ' . $orderby . ' 
							  LIMIT ' . $max . '
							 OFFSET ' . $offset;
                    if (!$DB->query($sql, 'array')) {
                        throw new Exception($DB->get_last_error());
                    }
                    $dataset = $DB->result();
                    $total = $DB->foundRows();
                    $block_types = block::types();
                    $block_types_list = array();
                    for ($i = 0; $i < count($block_types); $i++) {
                        if (is_numeric($block_types[$i]['id'])) {
                            $block_types_list[$block_types[$i]['code']] = $block_types[$i]['title'];
                        } else {
                            $block_types_list[$block_types[$i]['id']] = $block_types[$i]['title'];
                        }
                    }
                    $dataset = grid_notes::summary($dataset, 'block', 'id');
                    // we need to format the values and retrieve the needed strings from the dictionary
                    $out = array();
                    for ($i = 0; $i < count($dataset); $i++) {
                        if (empty($dataset[$i])) {
                            continue;
                        }
                        $access = array(0 => '<img src="img/icons/silk/page_white_go.png" align="absmiddle" title="' . t(254, 'Everybody') . '" />', 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") . '" />');
                        if (empty($dataset[$i]['date_published'])) {
                            $dataset[$i]['date_published'] = '&infin;';
                        } else {
                            $dataset[$i]['date_published'] = core_ts2date($dataset[$i]['date_published'], false);
                        }
                        if (empty($dataset[$i]['date_unpublish'])) {
                            $dataset[$i]['date_unpublish'] = '&infin;';
                        } else {
                            $dataset[$i]['date_unpublish'] = core_ts2date($dataset[$i]['date_unpublish'], false);
                        }
                        if ($dataset[$i]['category'] > 0) {
                            $dataset[$i]['category'] = $DB->query_single('text', 'nv_webdictionary', ' 	node_type = "structure" AND
                                    node_id = "' . $dataset[$i]['category'] . '" AND
                                    subtype = "title" AND
                                    lang = "' . $website->languages_list[0] . '"
                                ');
                        }
                        $out[$i] = array(0 => $dataset[$i]['id'], 1 => $block_types_list[$dataset[$i]['type']], 2 => '<div class="list-row" data-enabled="' . $dataset[$i]['enabled'] . '">' . $dataset[$i]['title'] . '</div>', 3 => $dataset[$i]['date_published'] . ' - ' . $dataset[$i]['date_unpublish'], 4 => $access[$dataset[$i]['access']], 5 => $dataset[$i]['enabled'] == 1 ? '<img src="img/icons/silk/accept.png" />' : '<img src="img/icons/silk/cancel.png" />', 6 => $dataset[$i]['_grid_notes_html']);
                    }
                    navitable::jqgridJson($out, $page, $offset, $max, $total);
                    break;
            }
            session_write_close();
            exit;
            break;
        case 'load':
        case 'edit':
        case 2:
            // edit/new form
            if (!empty($_REQUEST['id'])) {
                $item->load(intval($_REQUEST['id']));
            }
            if (isset($_REQUEST['form-sent'])) {
                $item->load_from_post();
                try {
                    $item->save();
                    property::save_properties_from_post('block', $item->id);
                    $id = $item->id;
                    // set block order
                    if (!empty($item->type) && !empty($_REQUEST['blocks-order'])) {
                        block::reorder($item->type, $_REQUEST['blocks-order'], $_REQUEST['blocks-order-fixed']);
                    }
                    unset($item);
                    $item = new block();
                    $item->load($id);
                    $layout->navigate_notification(t(53, "Data saved successfully."), false, false, 'fa fa-check');
                } catch (Exception $e) {
                    $layout->navigate_notification($e->getMessage(), true, true);
                }
                users_log::action($_REQUEST['fid'], $item->id, 'save', $item->dictionary[$website->languages_list[0]]['title'], json_encode($_REQUEST));
            } else {
                users_log::action($_REQUEST['fid'], $item->id, 'load', $item->dictionary[$website->languages_list[0]]['title']);
            }
            $out = blocks_form($item);
            break;
        case 'delete':
        case 4:
            // remove
            if (!empty($_REQUEST['id'])) {
                $item->load(intval($_REQUEST['id']));
                if ($item->delete() > 0) {
                    $layout->navigate_notification(t(55, 'Item removed successfully.'), false);
                    $out = blocks_list();
                } else {
                    $layout->navigate_notification(t(56, 'Unexpected error.'), false);
                    $out = blocks_form($item);
                }
                users_log::action($_REQUEST['fid'], $item->id, 'remove', $item->dictionary[$website->languages_list[0]]['title']);
            }
            break;
        case 'path':
        case 5:
            // search an existing path
            $DB->query('SELECT path as id, path as label, path as value
						  FROM nv_paths
						 WHERE path LIKE ' . protect('%' . $_REQUEST['term'] . '%') . ' 
						   AND website = ' . $website->id . '
				      ORDER BY path ASC
					     LIMIT 10', 'array');
            echo json_encode($DB->result());
            core_terminate();
            break;
        case 'block_groups_list':
            $out = block_groups_list();
            break;
        case 'block_groups_json':
            // block groups: json data retrieval
            $page = intval($_REQUEST['page']);
            $max = intval($_REQUEST['rows']);
            $offset = ($page - 1) * $max;
            list($rs, $total) = block_group::paginated_list($offset, $max, $_REQUEST['sidx'], $_REQUEST['sord']);
            $rs = grid_notes::summary($rs, 'block_group', 'id');
            // translate $rs to an array of ordered fields
            foreach ($rs as $row) {
                if (substr($row['blocks'], 0, 2) == 'a:') {
                    // nv < 2.1
                    $row['blocks'] = mb_unserialize($row['blocks']);
                } else {
                    // nv >= 2.1
                    $row['blocks'] = json_decode($row['blocks'], true);
                }
                $dataset[] = array('id' => $row['id'], 'code' => $row['code'], 'title' => $row['title'], 'blocks' => count($row['blocks']), 'notes' => $row['_grid_notes_html']);
            }
            navitable::jqgridJson($dataset, $page, $offset, $max, $total, 'id');
            session_write_close();
            exit;
            break;
        case 'block_group_edit':
            $item = new block_group();
            if (!empty($_REQUEST['id'])) {
                $item->load(intval($_REQUEST['id']));
            }
            if (isset($_REQUEST['form-sent'])) {
                $item->load_from_post();
                try {
                    $item->save();
                    $layout->navigate_notification(t(53, "Data saved successfully."), false, false, 'fa fa-check');
                } catch (Exception $e) {
                    $layout->navigate_notification($e->getMessage(), true, true);
                }
                users_log::action($_REQUEST['fid'], $item->id, 'save', $item->title, json_encode($_REQUEST));
            } else {
                if (!empty($_REQUEST['id'])) {
                    users_log::action($_REQUEST['fid'], $item->id, 'edit', $item->title);
                }
            }
            $out = block_group_form($item);
            break;
        case 'block_group_delete':
            $item = new block_group();
            if (!empty($_REQUEST['id'])) {
                $item->load(intval($_REQUEST['id']));
                if ($item->delete() > 0) {
                    $layout->navigate_notification(t(55, 'Item removed successfully.'), false);
                    $out = block_groups_list();
                } else {
                    $layout->navigate_notification(t(56, 'Unexpected error.'), false);
                    $out = block_group_form($item);
                }
                users_log::action($_REQUEST['fid'], $item->id, 'remove', $item->title);
            }
            break;
        case 'block_types_list':
            $out = blocks_types_list();
            break;
        case 'block_types_json':
            // block types: json data retrieval
            $page = intval($_REQUEST['page']);
            $max = intval($_REQUEST['rows']);
            $offset = ($page - 1) * $max;
            $rs = block::types($_REQUEST['sidx'], $_REQUEST['sord']);
            $block_modes = block::modes();
            // translate $rs to an array of ordered fields
            foreach ($rs as $row) {
                $dataset[] = array('id' => $row['id'], 'type' => $block_modes[$row['type']], 'code' => $row['code'], 'title' => $row['title'], 'width' => $row['width'], 'height' => $row['height']);
            }
            $total = count($dataset);
            navitable::jqgridJson($dataset, $page, $offset, $max, $total, 'id');
            session_write_close();
            exit;
            break;
        case 'block_type_edit':
        case 82:
            // edit/create block type
            $item = NULL;
            $position = NULL;
            $max_id = 0;
            $dataset = block::custom_types();
            for ($i = 0; $i < count($dataset); $i++) {
                if ($dataset[$i]['id'] > $max_id) {
                    $max_id = $dataset[$i]['id'];
                }
                if ($dataset[$i]['id'] == $_REQUEST['id']) {
                    $item = $dataset[$i];
                    $position = $i;
                }
            }
            if (empty($item)) {
                $layout->navigate_notification(t(599, "Sorry, can't display a theme block type info."));
                $out = blocks_types_list();
            } else {
                if (isset($_REQUEST['form-sent'])) {
                    if (empty($item)) {
                        $item = array('id' => $max_id + 1);
                    }
                    $item['type'] = $_REQUEST['type'];
                    $item['title'] = $_REQUEST['title'];
                    $item['code'] = $_REQUEST['code'];
                    $item['width'] = $_REQUEST['width'];
                    $item['height'] = $_REQUEST['height'];
                    $item['order'] = $_REQUEST['order'];
                    $item['maximum'] = $_REQUEST['maximum'];
                    $item['notes'] = pquotes($_REQUEST['notes']);
                    if (!is_null($position)) {
                        $dataset[$position] = $item;
                    } else {
                        $dataset[] = $item;
                    }
                    try {
                        // save
                        $ok = block::types_update($dataset);
                        $layout->navigate_notification(t(53, "Data saved successfully."), false, false, 'fa fa-check');
                    } catch (Exception $e) {
                        $layout->navigate_notification($e->getMessage(), true, true);
                    }
                }
                $out = blocks_type_form($item);
            }
            break;
        case 'block_type_delete':
        case 84:
            // remove block type
            $dataset = block::custom_types();
            $item = NULL;
            for ($i = 0; $i < count($dataset); $i++) {
                if ($dataset[$i]['id'] == $_REQUEST['id']) {
                    unset($dataset[$i]);
                    break;
                }
            }
            try {
                block::types_update($dataset);
                $layout->navigate_notification(t(55, 'Item removed successfully.'), false);
                $out = blocks_types_list();
            } catch (Exception $e) {
                $out = $layout->navigate_message("error", t(23, 'Blocks'), t(56, 'Unexpected error.'));
            }
            break;
        case 'block_property_load':
            $property = new property();
            if (!empty($_REQUEST['id'])) {
                if (is_numeric($_REQUEST['id'])) {
                    $property->load(intval($_REQUEST['id']));
                } else {
                    $property->load_from_theme($_REQUEST['id'], null, 'block', $_REQUEST['block']);
                }
            }
            header('Content-type: text/json');
            $types = property::types();
            $property->type_text = $types[$property->type];
            echo json_encode($property);
            session_write_close();
            exit;
            break;
        case 'block_property_save':
            // save property details
            $property = new property();
            if (!empty($_REQUEST['property-id'])) {
                $property->load(intval($_REQUEST['property-id']));
            }
            $property->load_from_post();
            $property->save();
            header('Content-type: text/json');
            $types = property::types();
            $property->type_text = $types[$property->type];
            echo json_encode($property);
            session_write_close();
            exit;
            break;
        case 'block_property_remove':
            // remove property
            $property = new property();
            if (!empty($_REQUEST['property-id'])) {
                $property->load(intval($_REQUEST['property-id']));
            }
            $property->delete();
            session_write_close();
            exit;
            break;
        case 'block_group_block_options':
            $status = null;
            $block_group = $_REQUEST['block_group'];
            $block_code = $_REQUEST['code'];
            $block_uid = $_REQUEST['block_uid'];
            if (isset($_REQUEST['form-sent'])) {
                $status = property::save_properties_from_post('block_group_block', $block_code, $block_group, $block_code, $block_uid);
            }
            $out = block_group_block_options($block_group, $block_code, $block_uid, $status);
            echo $out;
            core_terminate();
            break;
        case 'block_group_extension_block_options':
            $status = null;
            $block_group = $_REQUEST['block_group'];
            // block_group type
            $block_id = $_REQUEST['block_id'];
            // extension block id (type)
            $block_uid = $_REQUEST['block_uid'];
            // extension block unique id
            $block_extension = $_REQUEST['block_extension'];
            // extension name
            if (isset($_REQUEST['form-sent'])) {
                $status = property::save_properties_from_post('extension_block', $block_group, $block_id, null, $block_uid);
            }
            $out = block_group_extension_block_options($block_group, $block_extension, $block_id, $block_uid, $status);
            echo $out;
            core_terminate();
            break;
        case 0:
            // list / search result
        // list / search result
        default:
            $out = blocks_list();
            break;
    }
    return $out;
}
コード例 #5
0
ファイル: websites.php プロジェクト: NavigateCMS/Navigate-CMS
function run()
{
    global $user;
    global $layout;
    global $DB;
    global $website;
    $out = '';
    $item = new website();
    switch ($_REQUEST['act']) {
        case 'json':
        case 1:
            // json data retrieval & operations
            switch ($_REQUEST['oper']) {
                case 'search_links':
                    // active website only!
                    $text = $_REQUEST['text'];
                    $lang = $_REQUEST['lang'];
                    if (empty($lang)) {
                        $lang = array_keys($website->languages)[0];
                    }
                    $DB->query('
						SELECT p.path, d.text
						  FROM nv_paths p, nv_webdictionary d
						 WHERE p.website = ' . protect($website->id) . ' AND
						       p.lang = ' . protect($lang) . ' AND
						       d.website = p.website AND
						       d.node_type = p.type AND
						       d.node_id = p.object_id AND
						       d.lang = p.lang AND
						       d.subtype = "title" AND 
						       (    
						            p.path LIKE ' . protect('%' . $text . '%') . '  OR  
									d.text LIKE ' . protect('%' . $text . '%') . ' 
						       )
						 ORDER BY d.id DESC
						 LIMIT 10
					');
                    $result = $DB->result();
                    echo json_encode($result);
                    core_terminate();
                    break;
                case 'del':
                    // remove rows
                    if ($user->permission('websites.delete') == 'true') {
                        $ids = $_REQUEST['ids'];
                        foreach ($ids as $id) {
                            $item->load($id);
                            $item->delete();
                        }
                        echo json_encode(true);
                    }
                    core_terminate();
                    break;
                default:
                    // list or search
                    $page = intval($_REQUEST['page']);
                    $max = intval($_REQUEST['rows']);
                    $offset = ($page - 1) * $max;
                    $orderby = $_REQUEST['sidx'] . ' ' . $_REQUEST['sord'];
                    $where = " 1=1 ";
                    if ($_REQUEST['_search'] == 'true' || isset($_REQUEST['quicksearch'])) {
                        if (isset($_REQUEST['quicksearch'])) {
                            $where .= $item->quicksearch($_REQUEST['quicksearch']);
                        } else {
                            if (isset($_REQUEST['filters'])) {
                                $where .= navitable::jqgridsearch($_REQUEST['filters']);
                            } else {
                                // single search
                                $where .= ' AND ' . navitable::jqgridcompare($_REQUEST['searchField'], $_REQUEST['searchOper'], $_REQUEST['searchString']);
                            }
                        }
                    }
                    $DB->queryLimit('id,name,subdomain,domain,folder,homepage,permission,favicon', 'nv_websites', $where, $orderby, $offset, $max);
                    $dataset = $DB->result();
                    $total = $DB->foundRows();
                    //echo $DB->get_last_error();
                    $out = array();
                    $permissions = array(0 => '<img src="img/icons/silk/world.png" align="absmiddle" /> ' . t(69, 'Published'), 1 => '<img src="img/icons/silk/world_dawn.png" align="absmiddle" /> ' . t(70, 'Private'), 2 => '<img src="img/icons/silk/world_night.png" align="absmiddle" /> ' . t(81, 'Hidden'));
                    for ($i = 0; $i < count($dataset); $i++) {
                        $homepage = 'http://';
                        $homepage_relative_url = $dataset[$i]['homepage'];
                        if (is_numeric($homepage_relative_url)) {
                            $homepage_relative_url = path::loadElementPaths('structure', $homepage_relative_url);
                            $homepage_relative_url = array_shift($homepage_relative_url);
                        }
                        if (!empty($dataset[$i]['subdomain'])) {
                            $homepage .= $dataset[$i]['subdomain'] . '.';
                        }
                        $homepage .= $dataset[$i]['domain'] . $dataset[$i]['folder'] . $homepage_relative_url;
                        $favicon = '';
                        if (!empty($dataset[$i]['favicon'])) {
                            $favicon = '<img src="' . NVWEB_OBJECT . '?type=img&id=' . $dataset[$i]['favicon'] . '&width=16&height=16" align="absmiddle" height="16" />';
                        }
                        $out[$i] = array(0 => $dataset[$i]['id'], 1 => $favicon, 2 => $dataset[$i]['name'], 3 => '<a href="' . $homepage . '" target="_blank"><img align="absmiddle" src="' . NAVIGATE_URL . '/img/icons/silk/house_link.png"></a> ' . $homepage, 4 => $permissions[$dataset[$i]['permission']]);
                    }
                    navitable::jqgridJson($out, $page, $offset, $max, $total);
                    break;
            }
            session_write_close();
            exit;
            break;
        case 'edit':
        case 2:
            // edit/new form
            if (!empty($_REQUEST['id'])) {
                $item->load(intval($_REQUEST['id']));
            }
            if (isset($_REQUEST['form-sent']) && $user->permission('websites.edit') == 'true') {
                $item->load_from_post();
                try {
                    $item->save();
                    $id = $item->id;
                    unset($item);
                    $item = new website();
                    $item->load($id);
                    $layout->navigate_notification(t(53, "Data saved successfully."), false, false, 'fa fa-check');
                } catch (Exception $e) {
                    $layout->navigate_notification($e->getMessage(), true, true);
                }
                if (!empty($item->id)) {
                    users_log::action($_REQUEST['fid'], $item->id, 'save', $item->name, json_encode($_REQUEST));
                }
            } else {
                if (!empty($item->id)) {
                    users_log::action($_REQUEST['fid'], $item->id, 'load', $item->name);
                }
            }
            $out = websites_form($item);
            break;
        case 'remove':
        case 4:
            if (!empty($_REQUEST['id']) && $user->permission('websites.delete') == 'true') {
                $item->load(intval($_REQUEST['id']));
                if ($item->delete() > 0) {
                    $layout->navigate_notification(t(55, 'Item removed successfully.'), false);
                    if (!empty($item->id)) {
                        users_log::action($_REQUEST['fid'], $item->id, 'remove', $item->name, json_encode($_REQUEST));
                    }
                    // if we don't have any websites, tell user a new one will be created
                    $test = $DB->query_single('id', 'nv_websites');
                    if (empty($test) || !$test) {
                        $layout->navigate_notification(t(520, 'No website found; a default one has been created.'), false, true);
                        $nwebsite = new website();
                        $nwebsite->create_default();
                    }
                    $out = websites_list();
                } else {
                    $layout->navigate_notification(t(56, 'Unexpected error.'), false);
                    $out = websites_form($item);
                }
            }
            break;
        case 5:
            // search an existing path
            $DB->query('SELECT path as id, path as label, path as value
						  FROM nv_paths
						 WHERE path LIKE ' . protect('%' . $_REQUEST['term'] . '%') . '
						   AND website = ' . protect($_REQUEST['wid']) . '
				      ORDER BY path ASC
					     LIMIT 30', 'array');
            echo json_encode($DB->result());
            core_terminate();
            break;
        case 'email_test':
            $website->mail_mailer = $_REQUEST['mail_mailer'];
            $website->mail_server = $_REQUEST['mail_server'];
            $website->mail_port = $_REQUEST['mail_port'];
            $website->mail_address = $_REQUEST['mail_address'];
            $website->mail_user = $_REQUEST['mail_user'];
            $website->mail_security = $_REQUEST['mail_security'] == "true" || $_REQUEST['mail_security'] == "1" ? "1" : "0";
            if (!empty($_REQUEST['mail_password'])) {
                $website->mail_password = $_REQUEST['mail_password'];
            }
            $ok = navigate_send_email(APP_NAME, APP_NAME . '<br /><br />' . NAVIGATE_URL, $_REQUEST['send_to']);
            echo json_encode($ok);
            core_terminate();
            break;
        case 'reset_statistics':
            if ($user->permission('websites.edit') == 'true') {
                $website_id = trim($_REQUEST['website']);
                $website_id = intval($website_id);
                $DB->execute('UPDATE nv_items SET views = 0 WHERE website = ' . $website_id);
                $DB->execute('UPDATE nv_paths SET views = 0 WHERE website = ' . $website_id);
                $DB->execute('UPDATE nv_structure SET views = 0 WHERE website = ' . $website_id);
                echo 'true';
                users_log::action($_REQUEST['fid'], $website_id, 'reset_statistics', "", json_encode($_REQUEST));
            }
            core_terminate();
            break;
        case 'replace_urls':
            $old = trim($_REQUEST['old']);
            $new = trim($_REQUEST['new']);
            $website_id = trim($_REQUEST['website']);
            if (!empty($old) && !empty($new)) {
                // replace occurrences in nv_webdictionary
                $ok = $DB->execute('
					UPDATE nv_webdictionary
					   SET text = replace(text, :old, :new)
					 WHERE website = :wid', array(':old' => $old, ':new' => $new, ':wid' => $website_id));
                // replace occurrences in nv_blocks (triggers & actions)
                $ok = $DB->execute('
					UPDATE nv_blocks
					   SET `trigger` = replace(`trigger`, :old, :new),
					   	   `action` = replace(`action`, :old, :new)
					 WHERE website = :wid', array(':old' => $old, ':new' => $new, ':wid' => $website_id));
                echo $ok ? 'true' : 'false';
                if ($ok) {
                    users_log::action($_REQUEST['fid'], $website_id, 'replace_urls', "", json_encode($_REQUEST));
                }
            } else {
                echo 'false';
            }
            core_terminate();
            break;
        case 'remove_content':
            $website_id = trim($_REQUEST['website']);
            $website_id = intval($website_id);
            $password = trim($_REQUEST['password']);
            $authenticated = $user->authenticate($user->username, $password);
            if ($authenticated) {
                // remove all content except Webusers and Files
                @set_time_limit(0);
                $ok = $DB->execute('
					DELETE FROM nv_blocks WHERE website = ' . $website_id . ';
					DELETE FROM nv_block_groups WHERE website = ' . $website_id . ';
					DELETE FROM nv_comments WHERE website = ' . $website_id . ';
					DELETE FROM nv_structure WHERE website = ' . $website_id . ';
					DELETE FROM nv_feeds WHERE website = ' . $website_id . ';
					DELETE FROM nv_items WHERE website = ' . $website_id . ';
					DELETE FROM nv_notes WHERE website = ' . $website_id . ';
					DELETE FROM nv_paths WHERE website = ' . $website_id . ';
					DELETE FROM nv_properties WHERE website = ' . $website_id . ';
					DELETE FROM nv_properties_items WHERE website = ' . $website_id . ';
					DELETE FROM nv_search_log WHERE website = ' . $website_id . ';
					DELETE FROM nv_webdictionary WHERE website = ' . $website_id . ';
					DELETE FROM nv_webdictionary_history WHERE website = ' . $website_id . ';
				');
                if ($ok) {
                    users_log::action($_REQUEST['fid'], $website_id, 'remove_content', "", json_encode($_REQUEST));
                }
                echo $ok ? 'true' : $DB->error();
            } else {
                echo '';
            }
            core_terminate();
            break;
        case 0:
            // list / search result
        // list / search result
        default:
            $out = websites_list();
            break;
    }
    return $out;
}
コード例 #6
0
ファイル: login.php プロジェクト: NavigateCMS/Navigate-CMS
if (!empty($_POST['login-username']) && !empty($_POST['login-password'])) {
    $error = !$user->authenticate($_POST['login-username'], $_POST['login-password']);
    if (empty($error) && $user->blocked == '1') {
        $error = true;
    }
    if (!$error) {
        $_SESSION['APP_USER#' . APP_UNIQUE] = $user->id;
        if ($_REQUEST['login-remember'] == '1') {
            $user->set_cookie();
        } else {
            $user->remove_cookie();
        }
        $login_request_uri = $_SESSION["login_request_uri"];
        $website->load();
        // load first website available (needed in the users log)
        users_log::action(0, $user->id, 'login', $user->username);
        $_SESSION["login_request_uri"] = '';
        setcookie('navigate-session-id', session_id(), time() + 60, '/');
        // 60 seconds
        session_write_close();
        header('location: ' . NAVIGATE_MAIN . '?' . $login_request_uri);
        exit;
    }
}
/* CHECK USER BROWSER LANGUAGE PREFERENCES */
$language_default = 'en';
$DB->query('SELECT code 
			FROM nv_languages
			WHERE nv_dictionary != ""', 'array');
$languages_available = $DB->result('code');
$langs = array();
コード例 #7
0
ファイル: files.php プロジェクト: NavigateCMS/Navigate-CMS
function run()
{
    global $user;
    global $layout;
    global $DB;
    global $website;
    $out = '';
    $item = new file();
    switch ($_REQUEST['act']) {
        case 1:
            // json retrieval & operations
        // json retrieval & operations
        case "json":
            if ($_REQUEST['op'] == 'upload') {
                $tmp_name = $_REQUEST['tmp_name'];
                if ($tmp_name == "{{BASE64}}") {
                    $tmp_name = base64_encode($_REQUEST['name']);
                }
                $file = file::register_upload($tmp_name, $_REQUEST['name'], $_REQUEST['parent']);
                if (!empty($file)) {
                    echo json_encode(array('id' => $file->id, 'name' => $file->name));
                } else {
                    echo json_encode(false);
                }
            }
            switch ($_REQUEST['op']) {
                case 'create_folder':
                    file::create_folder($_REQUEST['name'], $_REQUEST['mime'], $_REQUEST['parent']);
                    echo json_encode(true);
                    break;
                case 'edit_folder':
                    $f = new file();
                    $f->load(intval($_REQUEST['id']));
                    $f->name = $_REQUEST['name'];
                    $f->mime = $_REQUEST['mime'];
                    $ok = $f->save();
                    echo json_encode($ok);
                    break;
                case 'edit_file':
                    $f = new file();
                    $f->load(intval($_REQUEST['id']));
                    $f->name = $_REQUEST['name'];
                    $ok = $f->save();
                    echo json_encode($ok);
                    break;
                case 'duplicate_file':
                    //error_reporting(~0);
                    //ini_set('display_errors', 1);
                    $status = false;
                    $f = new file();
                    $f->load(intval($_REQUEST['id']));
                    $f->id = 0;
                    $f->insert();
                    if (!empty($f->id)) {
                        $done = copy(NAVIGATE_PRIVATE . '/' . $website->id . '/files/' . intval($_REQUEST['id']), NAVIGATE_PRIVATE . '/' . $website->id . '/files/' . $f->id);
                        $status = "true";
                        if (!$done) {
                            $f->delete();
                            $status = t(56, "Unexpected error");
                        }
                    }
                    echo $status;
                    break;
                case 'move':
                    if (is_array($_REQUEST['item'])) {
                        $ok = true;
                        for ($i = 0; $i < count($_REQUEST['item']); $i++) {
                            unset($item);
                            $item = new file();
                            $item->load($_REQUEST['item'][$i]);
                            $item->parent = $_REQUEST['folder'];
                            $ok = $ok & $item->update();
                        }
                        echo json_encode($ok ? true : false);
                    } else {
                        $item->load($_REQUEST['item']);
                        $item->parent = $_REQUEST['folder'];
                        echo json_encode($item->update());
                    }
                    break;
                case 'delete':
                    try {
                        $item->load($_REQUEST['id']);
                        $status = $item->delete();
                        echo json_encode($status);
                    } catch (Exception $e) {
                        echo $e->getMessage();
                    }
                    break;
                case 'permissions':
                    $item->load($_REQUEST['id']);
                    if (!empty($_POST)) {
                        $item->access = intval($_POST['access']);
                        $item->permission = intval($_POST['permission']);
                        $item->enabled = intval($_POST['enabled']);
                        $item->groups = $_POST['groups'];
                        if ($item->access < 3) {
                            $item->groups = array();
                        }
                        $status = $item->save();
                        echo json_encode($status);
                    } else {
                        echo json_encode(array('access' => $item->access, 'groups' => $item->groups, 'permission' => $item->permission, 'enabled' => $item->enabled));
                    }
                    break;
                case 'description':
                    $item->load($_REQUEST['id']);
                    if (!empty($_POST)) {
                        $item->title = array();
                        $item->description = array();
                        foreach ($website->languages as $language) {
                            $lcode = $language['code'];
                            if (!isset($_REQUEST['titles'][$lcode])) {
                                break;
                            }
                            $item->title[$lcode] = $_REQUEST['titles'][$lcode];
                            $item->description[$lcode] = $_REQUEST['descriptions'][$lcode];
                        }
                        $status = $item->save();
                        echo json_encode($status);
                    } else {
                        // return file title and description (alt)
                        $data = array('title' => $item->title, 'description' => $item->description);
                        echo json_encode($data);
                    }
                    break;
                case 'focalpoint':
                    $item->load($_REQUEST['id']);
                    if (!empty($_POST)) {
                        $item->focalpoint = $_REQUEST['top'] . '#' . $_REQUEST['left'];
                        $status = $item->save();
                        // remove cached thumbnails
                        file::thumbnails_remove($item->id);
                        echo json_encode($status);
                    } else {
                        if (empty($item->focalpoint)) {
                            $item->focalpoint = '50#50';
                            $item->save();
                            // remove cached thumbnails
                            file::thumbnails_remove($item->id);
                        }
                        echo $item->focalpoint;
                    }
                    break;
                case 'video_info':
                    if ($_REQUEST['provider'] == 'youtube') {
                        $item->load_from_youtube($_REQUEST['reference'], false);
                        // force cache reload
                    } else {
                        if ($_REQUEST['provider'] == 'vimeo') {
                            $item->load_from_vimeo($_REQUEST['reference'], false);
                            // force cache reload
                        } else {
                            if (!empty($_REQUEST['reference']) && is_numeric($_REQUEST['reference'])) {
                                $item->load($_REQUEST['reference']);
                            } else {
                                if (is_numeric($_REQUEST['provider'])) {
                                    $item->load($_REQUEST['provider']);
                                } else {
                                    unset($item);
                                }
                            }
                            if (!empty($item)) {
                                // add some extra data
                                $item->extra = array('reference' => $item->id, 'link' => '', 'thumbnail' => 'img/icons/ricebowl/mimetypes/video.png', 'thumbnail_big' => 'img/icons/ricebowl/mimetypes/video.png', 'thumbnail_url' => 'img/icons/ricebowl/mimetypes/video.png', 'duration' => '', 'embed_code' => '<video src="' . file::file_url($item->id, 'inline') . '></video>');
                            }
                        }
                    }
                    if (!empty($item)) {
                        echo json_encode($item);
                    } else {
                        echo false;
                    }
                    break;
            }
            session_write_close();
            $DB->disconnect();
            exit;
            break;
        case 2:
            // show/edit item properties
        // show/edit item properties
        case "edit":
            $item->load($_REQUEST['id']);
            if (isset($_REQUEST['form-sent'])) {
                $item->load_from_post();
                try {
                    $item->save();
                    unset($item);
                    $item = new file();
                    $item->load($_REQUEST['id']);
                    $layout->navigate_notification(t(53, "Data saved successfully."), false, false, 'fa fa-check');
                } catch (Exception $e) {
                    $layout->navigate_notification($e->getMessage(), true, true);
                }
            }
            $out = files_item_properties($item);
            break;
        case 10:
        case 'media_browser':
            files_media_browser($_GET['limit'], $_GET['offset']);
            break;
        case 92:
            // pixlr (image editor) overlay remover
        // pixlr (image editor) overlay remover
        case 'pixlr_exit':
            ob_clean();
            file::thumbnails_remove(intval($_GET['id']));
            echo '
			<html>
			<head></head>
			<body>
			<script language="javascript" type="text/javascript">
				//window.parent.eval("$(\'#thumbnail-cache\').attr(\'src\', $(\'#thumbnail-cache\').attr(\'src\') + \'&refresh=\' + new Date().getTime());");
				window.parent.eval(\'$("#image-preview").attr("src", $("#image-preview").attr("src") + "&refresh=" + new Date().getTime());\');
				window.parent.eval("pixlr.overlay.hide();");
			</script>
			</body>
			</html>	
			';
            core_terminate();
            break;
            /*	
            case 91: // picnik editing
            	ob_clean();
            	
            	// $strPicnikUrl is the URL that we use to launch Picnik.
            	$strPicnikUrl = "http://www.picnik.com/service";	
            	// $aPicnikParams collects together all the params we'll give Picnik.  Start with an API key
            	$aPicnikParams['_apikey'] = $website->picnik_api_key;
            	// tell Picnik where to send the exported image
            	$aPicnikParams['_export'] = NAVIGATE_URL.'/navigate_upload.php?wid='.$website->id.'&engine=picnik&id='.$_REQUEST['id'].'&engine=picnik&session_id='.session_id();
            	// give the export button a title
            	$aPicnikParams['_export_title'] = t(34, 'Save');
            	// turn on the close button, and tell it to come back here
            	//$aPicnikParams['_close_target'] = $strRoot;
            	// send in the previous "king" image in case the user feels like decorating it
            	$aPicnikParams['_import'] = NAVIGATE_DOWNLOAD.'?wid='.$website->id.'&id='.$_REQUEST['id'].'&disposition=attachment&sid='.session_id();	
            	// tell Picnik to redirect the user to the following URL after the HTTP POST instead of just redirecting to _export
            	$aPicnikParams['_redirect'] = NAVIGATE_DOWNLOAD.'?wid='.$website->id.'&id='.$_REQUEST['id'].'&disposition=inline&ts='.core_time(); //'javascript: return false;';
            
            	// tell Picnik our name.  It'll use it in a few places as appropriate
            	$aPicnikParams['_host_name'] = 'Navigate';
            	// turn off the "Save &amp; Share" tab so users don't get confused
            	$aPicnikParams['_exclude'] = "out";
            
            	echo '<html><head></head><body>';
            
            	echo '<form id="picnik_form" method="POST" action="'.$strPicnikUrl.'" style=" visibility: hidden; ">';
            	
            	// put all the API parameters into the form as hidden inputs
            	foreach( $aPicnikParams as $key => $value ) {
            		echo "<input type='hidden' name='$key' value='$value'/>\n";
            	}
            	
            	//echo "<input type='text' name='address' value='Your Majesty'/>\n";
            	echo "<input type='submit' value='Picnik'/>\n";
            	echo "</form>";
            	echo '<script language="javascript" type="text/javascript">
            			document.forms[0].submit();
            		  </script>';
            	echo '</body></html>';
            
            	core_terminate();
            	break;
            */
        /*	
        case 91: // picnik editing
        	ob_clean();
        	
        	// $strPicnikUrl is the URL that we use to launch Picnik.
        	$strPicnikUrl = "http://www.picnik.com/service";	
        	// $aPicnikParams collects together all the params we'll give Picnik.  Start with an API key
        	$aPicnikParams['_apikey'] = $website->picnik_api_key;
        	// tell Picnik where to send the exported image
        	$aPicnikParams['_export'] = NAVIGATE_URL.'/navigate_upload.php?wid='.$website->id.'&engine=picnik&id='.$_REQUEST['id'].'&engine=picnik&session_id='.session_id();
        	// give the export button a title
        	$aPicnikParams['_export_title'] = t(34, 'Save');
        	// turn on the close button, and tell it to come back here
        	//$aPicnikParams['_close_target'] = $strRoot;
        	// send in the previous "king" image in case the user feels like decorating it
        	$aPicnikParams['_import'] = NAVIGATE_DOWNLOAD.'?wid='.$website->id.'&id='.$_REQUEST['id'].'&disposition=attachment&sid='.session_id();	
        	// tell Picnik to redirect the user to the following URL after the HTTP POST instead of just redirecting to _export
        	$aPicnikParams['_redirect'] = NAVIGATE_DOWNLOAD.'?wid='.$website->id.'&id='.$_REQUEST['id'].'&disposition=inline&ts='.core_time(); //'javascript: return false;';
        
        	// tell Picnik our name.  It'll use it in a few places as appropriate
        	$aPicnikParams['_host_name'] = 'Navigate';
        	// turn off the "Save &amp; Share" tab so users don't get confused
        	$aPicnikParams['_exclude'] = "out";
        
        	echo '<html><head></head><body>';
        
        	echo '<form id="picnik_form" method="POST" action="'.$strPicnikUrl.'" style=" visibility: hidden; ">';
        	
        	// put all the API parameters into the form as hidden inputs
        	foreach( $aPicnikParams as $key => $value ) {
        		echo "<input type='hidden' name='$key' value='$value'/>\n";
        	}
        	
        	//echo "<input type='text' name='address' value='Your Majesty'/>\n";
        	echo "<input type='submit' value='Picnik'/>\n";
        	echo "</form>";
        	echo '<script language="javascript" type="text/javascript">
        			document.forms[0].submit();
        		  </script>';
        	echo '</body></html>';
        
        	core_terminate();
        	break;
        */
        case 0:
            // list / search result
        // list / search result
        default:
            // show requested folder or search
            $out = files_browser($_REQUEST['parent'], $_REQUEST['navigate-quicksearch']);
            users_log::action($_REQUEST['fid'], intval($_REQUEST['parent']), 'list', '', json_encode($_REQUEST));
            break;
    }
    return $out;
}
コード例 #8
0
ファイル: comments.php プロジェクト: NavigateCMS/Navigate-CMS
function run()
{
    global $user;
    global $layout;
    global $DB;
    global $website;
    $out = '';
    $item = new comment();
    switch ($_REQUEST['act']) {
        case 'json':
        case 1:
            // json data retrieval & operations
            switch ($_REQUEST['oper']) {
                case 'del':
                    // remove rows
                    $ids = $_REQUEST['ids'];
                    foreach ($ids as $id) {
                        $item->load($id);
                        $item->delete();
                    }
                    echo json_encode(true);
                    break;
                default:
                    // list or search
                    $page = intval($_REQUEST['page']);
                    $max = intval($_REQUEST['rows']);
                    $offset = ($page - 1) * $max;
                    $orderby = $_REQUEST['sidx'] . ' ' . $_REQUEST['sord'];
                    $where = ' website = ' . $website->id;
                    if ($_REQUEST['_search'] == 'true' || isset($_REQUEST['quicksearch'])) {
                        if (isset($_REQUEST['quicksearch'])) {
                            $where .= $item->quicksearch($_REQUEST['quicksearch']);
                        } else {
                            if (isset($_REQUEST['filters'])) {
                                $where .= navitable::jqgridsearch($_REQUEST['filters']);
                            } else {
                                // single search
                                $where .= ' AND ' . navitable::jqgridcompare($_REQUEST['searchField'], $_REQUEST['searchOper'], $_REQUEST['searchString']);
                            }
                        }
                    }
                    $DB->queryLimit('id,item,user,email,date_created,status,message', 'nv_comments', $where, $orderby, $offset, $max);
                    $dataset = $DB->result();
                    $total = $DB->foundRows();
                    //echo $DB->get_last_error();
                    $out = array();
                    $permissions = array(-1 => '<img src="img/icons/silk/new.png" align="absmiddle" /> ' . t(257, 'To review'), 0 => '<img src="img/icons/silk/world.png" align="absmiddle" /> ' . t(64, 'Published'), 1 => '<img src="img/icons/silk/world_dawn.png" align="absmiddle" /> ' . t(251, 'Private'), 2 => '<img src="img/icons/silk/world_night.png" align="absmiddle" /> ' . t(181, 'Hidden'), 3 => '<img src="img/icons/silk/error.png" align="absmiddle" /> ' . t(466, 'Spam'));
                    for ($i = 0; $i < count($dataset); $i++) {
                        if (empty($dataset[$i])) {
                            continue;
                        }
                        // retrieve webuser name
                        $webuser = $DB->query_single('username', 'nv_webusers', ' id = ' . $dataset[$i]['user']);
                        // retrieve item title
                        $item = new item();
                        $item->load($dataset[$i]['item']);
                        $title = $item->dictionary[$website->languages_list[0]]['title'];
                        $message = core_string_clean($dataset[$i]['message']);
                        $message = core_string_cut($message, 60, '&hellip;');
                        $out[$i] = array(0 => $dataset[$i]['id'], 1 => $title, 2 => core_ts2date($dataset[$i]['date_created'], true), 3 => empty($dataset[$i]['user']) ? $dataset[$i]['email'] : $webuser, 4 => strip_tags($message), 5 => $permissions[$dataset[$i]['status']]);
                    }
                    navitable::jqgridJson($out, $page, $offset, $max, $total);
                    break;
            }
            session_write_close();
            exit;
            break;
        case 2:
            // edit/new form
        // edit/new form
        case 'edit':
            if (!empty($_REQUEST['id'])) {
                $item->load(intval($_REQUEST['id']));
            }
            if (isset($_REQUEST['form-sent'])) {
                $item->load_from_post();
                try {
                    $item->save();
                    property::save_properties_from_post('comment', $item->id);
                    $layout->navigate_notification(t(53, "Data saved successfully."), false, false, 'fa fa-check');
                } catch (Exception $e) {
                    $layout->navigate_notification($e->getMessage(), true, true);
                }
                if (!empty($item->id)) {
                    users_log::action($_REQUEST['fid'], $item->id, 'save', $item->name, json_encode($_REQUEST));
                }
            } else {
                if (!empty($item->id)) {
                    users_log::action($_REQUEST['fid'], $item->id, 'load', $item->name);
                }
            }
            $out = comments_form($item);
            break;
        case 4:
            // remove
        // remove
        case 'remove':
            if (!empty($_REQUEST['id'])) {
                $item->load(intval($_REQUEST['id']));
                if ($item->delete() > 0) {
                    $layout->navigate_notification(t(55, 'Item removed successfully.'), false);
                    $out = comments_list();
                    if (!empty($item->id)) {
                        users_log::action($_REQUEST['fid'], $item->id, 'remove', $item->name, json_encode($_REQUEST));
                    }
                } else {
                    $layout->navigate_notification(t(56, 'Unexpected error.'), false);
                    $out = comments_form($item);
                }
            }
            break;
        case 'remove_spam':
            $count = comment::remove_spam();
            $layout->navigate_notification(t(524, 'Items removed successfully') . ': <strong>' . $count . '</strong>', false);
            $out = comments_list();
            users_log::action($_REQUEST['fid'], $website->id, 'remove_spam', "", json_encode($_REQUEST));
            break;
        case 'json_find_webuser':
            // json find webuser by name (for "user" autocomplete)
            $DB->query('SELECT id, username as text
						  FROM nv_webusers
						 WHERE username LIKE ' . protect('%' . $_REQUEST['username'] . '%') . '
				      ORDER BY username ASC
					     LIMIT 30', 'array');
            $rows = $DB->result();
            $total = $DB->foundRows();
            echo json_encode(array('items' => $rows, 'totalCount' => $total));
            core_terminate();
            break;
        case 'json_find_comment':
            // json find comment by text search (for "in reply to" autocomplete)
            $DB->query('SELECT c.id, c.date_created, c.name, u.username, c.message
						  FROM nv_comments c
						  LEFT JOIN nv_webusers u ON c.user = u.id
						 WHERE
						    c.website = ' . $website->id . ' AND
						    c.item = ' . $_REQUEST['node_id'] . ' AND
						    c.date_created <= ' . $_REQUEST['maxdate'] . ' AND
						    c.id <> ' . $_REQUEST['exclude'] . ' AND						     
						    (   c.name LIKE ' . protect('%' . $_REQUEST['search'] . '%') . ' OR
						        c.message LIKE ' . protect('%' . $_REQUEST['search'] . '%') . ' OR
						        u.username LIKE ' . protect('%' . $_REQUEST['search'] . '%') . '
                            )                          
				      ORDER BY c.date_created DESC
					     LIMIT 30', 'array');
            $rows = $DB->result();
            $total = $DB->foundRows();
            for ($r = 0; $r < count($rows); $r++) {
                $rows[$r]['text'] = '<span title="' . core_string_cut($rows[$r]['message'], 100) . '"><i class="fa fa-user"></i> ' . $rows[$r]['name'] . $rows[$r]['username'] . ' <i class="fa fa-clock-o"></i> ' . core_ts2date($rows[$r]['date_created'], true) . '</span>';
            }
            echo json_encode(array('items' => $rows, 'totalCount' => $total));
            core_terminate();
            break;
        case 91:
            // json search title request (for "item" autocomplete)
            $DB->query('SELECT DISTINCT node_id as id, text as label, text as value
						  FROM nv_webdictionary
						 WHERE node_type = "item"
						   AND subtype = "title"
						   AND website = ' . $website->id . ' 
						   AND text LIKE ' . protect('%' . $_REQUEST['title'] . '%') . '
				      ORDER BY text ASC
					     LIMIT 30', 'array');
            // AND lang = '.protect($_REQUEST['lang']).'
            echo json_encode($DB->result());
            session_write_close();
            exit;
            break;
        case 0:
            // list / search result
        // list / search result
        default:
            $out = comments_list();
            break;
    }
    return $out;
}
コード例 #9
0
function run()
{
    global $user;
    switch (@$_REQUEST['act']) {
        case 'json':
            switch ($_REQUEST['oper']) {
                case 'settings_panels':
                    // save dashboard panels state
                    $dashboard_panels = $_REQUEST['dashboard_panels'];
                    $user->setting('dashboard-panels', json_encode($dashboard_panels));
                    echo json_encode(true);
                    core_terminate();
                    break;
                case 'feed':
                    $feed = new feed_parser();
                    $feed->set_cache(4 * 3600);
                    // once update each 4 hours
                    $feed->load($_REQUEST['url']);
                    list($channel, $articles, $count) = $feed->parse(0, $_REQUEST['limit'], 'newest');
                    $items = item::convert_from_rss($articles);
                    $display_language = $_REQUEST['language'];
                    if (!empty($items)) {
                        $feed_html = '';
                        for ($c = 0; $c < count($items); $c++) {
                            if (empty($items[$c])) {
                                break;
                            }
                            if (!isset($items[$c]->dictionary[$display_language])) {
                                // requested language not available, get the first available in the feed
                                $feed_languages = array_keys($items[$c]->dictionary);
                                $display_language = $feed_languages[0];
                            }
                            $tmp = array('<div class="navigate-panel-body-title ui-corner-all">' . '<a href="' . $items[$c]->paths[$display_language] . '" target="_blank">' . core_ts2date($items[$c]->date_to_display, true) . ' ' . '<strong>' . $items[$c]->dictionary[$display_language]['title'] . '</strong>' . '</a>' . '</div>', '<div id="navigatecms-feed-item-' . $items[$c]->id . '" class="navigate-panel-recent-feed-element">' . $items[$c]->dictionary[$display_language]['section-main'] . '</div>');
                            $feed_html .= implode("\n", $tmp);
                        }
                    }
                    echo $feed_html;
                    core_terminate();
                    break;
                default:
                    // list or search
            }
            break;
        case 'recent_items':
            $ri = users_log::recent_items(value_or_default($_REQUEST['limit']), 10);
            if (!is_array($ri)) {
                $ri = array();
            }
            for ($i = 0; $i < count($ri); $i++) {
                $action = $ri[$i];
                $ri[$i]->_url = '?fid=' . $action->function . '&wid=' . $action->website . '&act=load&id=' . $action->item;
                $ri[$i]->_link = '<a href="' . $ri[$i]->_url . '" title="' . htmlspecialchars($action->item_title) . ' | ' . htmlspecialchars(t($action->function_title, $action->function_title)) . '"><img src="' . $action->function_icon . '" align="absmiddle" /> ' . core_string_cut($action->item_title, 33) . '</a>';
            }
            echo json_encode($ri);
            core_terminate();
            break;
        default:
            $out = dashboard_create();
    }
    return $out;
}
コード例 #10
0
function run()
{
    global $user;
    global $layout;
    global $DB;
    global $website;
    global $theme;
    $out = '';
    $item = new structure();
    switch ($_REQUEST['act']) {
        case 'load':
        case 'edit':
        case 2:
            // edit/new form
            if (!empty($_REQUEST['id'])) {
                $item->load(intval($_REQUEST['id']));
            }
            if (isset($_REQUEST['form-sent'])) {
                $item->load_from_post();
                try {
                    $item->save();
                    property::save_properties_from_post('structure', $item->id);
                    $item = $item->reload();
                    // reorder associated category elements
                    if (!empty($_POST['elements-order'])) {
                        $response = item::reorder($_POST['elements-order']);
                        if ($response !== true) {
                            throw new Exception($response);
                        }
                    }
                    $layout->navigate_notification(t(53, "Data saved successfully."), false, false, 'fa fa-check');
                } catch (Exception $e) {
                    $layout->navigate_notification($e->getMessage(), true, true);
                }
                if (!empty($item->id)) {
                    users_log::action($_REQUEST['fid'], $item->id, 'save', $item->dictionary[$website->languages_list[0]]['title'], json_encode($_REQUEST));
                }
            } else {
                if (!empty($item->id)) {
                    users_log::action($_REQUEST['fid'], $item->id, 'load', $item->dictionary[$website->languages_list[0]]['title']);
                }
            }
            $out = structure_form($item);
            break;
        case 3:
        case "reorder":
            $ok = structure::reorder($_REQUEST['parent'], $_REQUEST['children_order']);
            echo json_encode($ok);
            core_terminate();
            break;
        case "homepager":
            $node = $_REQUEST['node'];
            $website->homepage = $node;
            $ok = $website->save();
            echo json_encode($ok);
            core_terminate();
            break;
        case 4:
        case "remove":
            if (!empty($_REQUEST['id'])) {
                $item->load(intval($_REQUEST['id']));
                if ($item->delete() > 0) {
                    $layout->navigate_notification(t(55, 'Item removed successfully.'), false);
                    $structure = structure::hierarchy(-1);
                    // root level (0) including Web node (-1)
                    $out = structure_tree($structure);
                    users_log::action($_REQUEST['fid'], $item->id, 'remove');
                } else {
                    $layout->navigate_notification(t(56, 'Unexpected error.'), false);
                    $out = structure_form($item);
                }
            }
            break;
        case 95:
            // free path checking
            $path = $_REQUEST['path'];
            $id = $_REQUEST['id'];
            $DB->query('SELECT type, object_id, lang
	 					  FROM nv_paths
						 WHERE path = ' . protect($path) . '
						   AND website = ' . $website->id);
            $rs = $DB->result();
            echo json_encode($rs);
            core_terminate();
            break;
        case "category_path":
            // return category paths
            echo json_encode(path::loadElementPaths('structure', intval($_REQUEST['id'])));
            core_terminate();
            break;
        case 'json_find_item':
            // find items by its title
            // the items must have its own path (free OR not embedded to a category)
            $DB->query('
				SELECT SQL_CALC_FOUND_ROWS nvw.node_id as id, nvw.text as text
				  FROM nv_webdictionary nvw, nv_items nvi
				 WHERE nvw.node_type = "item"
				   AND nvw.node_id = nvi.id
				   AND nvw.subtype = "title"
				   AND (	nvi.association = "free" OR
				            (nvi.association = "category" AND nvi.embedding=0)
				   )
				   AND nvw.lang = ' . protect($_REQUEST['lang']) . '
				   AND nvw.website = ' . $website->id . '
				   AND nvw.website = nvi.website
				   AND nvw.text LIKE ' . protect('%' . $_REQUEST['title'] . '%') . '
		      ORDER BY nvw.text ASC
			     LIMIT ' . intval($_REQUEST['page_limit']) . '
			     OFFSET ' . max(0, intval($_REQUEST['page_limit']) * (intval($_REQUEST['page']) - 1)), 'array');
            $rows = $DB->result();
            $total = $DB->foundRows();
            echo json_encode(array('items' => $rows, 'totalCount' => $total));
            core_terminate();
            break;
        case "search_by_title":
            // json search title request (for "copy from" properties dialog)
            $DB->query('
				SELECT node_id as id, text as label, text as value
					  FROM nv_webdictionary
					 WHERE node_type = "structure"
					   AND subtype = "title"
					   AND lang = ' . protect($_REQUEST['lang']) . '
					   AND website = ' . $website->id . '
					   AND text LIKE ' . protect('%' . $_REQUEST['title'] . '%') . '
			      ORDER BY text ASC
				     LIMIT 30', 'array');
            echo json_encode($DB->result());
            core_terminate();
            break;
        case "copy_from_template_zones":
            // return template properties for a structure id
            $item = new structure();
            $item->load(intval($_REQUEST['id']));
            $template = new template();
            $template->load($item->template);
            $zones = array();
            for ($ps = 0; $ps < count($template->properties); $ps++) {
                // ignore non structure properties
                if (!isset($template->properties[$ps]->element) || $template->properties[$ps]->element != 'structure') {
                    continue;
                }
                // ignore non-textual properties
                if (!in_array($template->properties[$ps]->type, array("text", "textarea", "rich_textarea"))) {
                    continue;
                }
                $title = $template->properties[$ps]->name;
                if (!empty($theme)) {
                    $title = $theme->t($title);
                }
                $zones[] = array('type' => 'property', 'code' => $template->properties[$ps]->id, 'title' => $title);
            }
            echo json_encode($zones);
            core_terminate();
            break;
        case "raw_zone_content":
            // return raw item contents
            if ($_REQUEST['zone'] == 'property') {
                $DB->query('SELECT text
							  FROM nv_webdictionary
							 WHERE node_type = "property-structure"
							   AND subtype = ' . protect('property-' . $_REQUEST['section'] . '-' . $_REQUEST['lang']) . '
							   AND lang = ' . protect($_REQUEST['lang']) . '
							   AND website = ' . $website->id . '
							   AND node_id = ' . protect($_REQUEST['node_id']), 'array');
                $data = $DB->first();
                echo $data['text'];
            }
            core_terminate();
            break;
        case 'votes_reset':
            webuser_vote::remove_object_votes('structure', intval($_REQUEST['id']));
            echo 'true';
            core_terminate();
            break;
        case 'votes_by_webuser':
            if ($_POST['oper'] == 'del') {
                $ids = explode(',', $_POST['id']);
                for ($i = 0; $i < count($ids); $i++) {
                    if ($ids[$i] > 0) {
                        $vote = new webuser_vote();
                        $vote->load($ids[$i]);
                        $vote->delete();
                    }
                }
                webuser_vote::update_object_score('structure', $vote->object_id);
                echo 'true';
                core_terminate();
            }
            $max = intval($_GET['rows']);
            $page = intval($_GET['page']);
            $offset = ($page - 1) * $max;
            if ($_REQUEST['_search'] == 'false') {
                list($dataset, $total) = webuser_vote::object_votes_by_webuser('structure', intval($_REQUEST['id']), $_REQUEST['sidx'] . ' ' . $_REQUEST['sord'], $offset, $max);
            }
            $out = array();
            for ($i = 0; $i < count($dataset); $i++) {
                if (empty($dataset[$i])) {
                    continue;
                }
                $out[$i] = array(0 => $dataset[$i]['id'], 1 => core_ts2date($dataset[$i]['date'], true), 2 => $dataset[$i]['username']);
            }
            navitable::jqgridJson($out, $page, $offset, $max, $total);
            core_terminate();
            break;
        case 0:
            // tree / search result
        // tree / search result
        default:
            $structure = structure::hierarchy(-1);
            // root level (0) including Web node (-1)
            $out = structure_tree($structure);
            break;
    }
    return $out;
}
コード例 #11
0
function run()
{
    global $user;
    global $layout;
    global $DB;
    global $website;
    $out = '';
    $item = new template();
    switch ($_REQUEST['act']) {
        case 'json':
        case 1:
            // json data retrieval & operations
            switch ($_REQUEST['oper']) {
                case 'del':
                    // remove rows
                    $ids = $_REQUEST['ids'];
                    foreach ($ids as $id) {
                        $item->load($id);
                        $item->delete();
                    }
                    echo json_encode(true);
                    break;
                default:
                    // list or search
                    // we have to merge the theme templates with the custom private templates (which are defined in the DB)
                    // as we don't expect a lot of templates, we will always return the whole dataset
                    // for this reason, paginate is useless
                    $orderby = $_REQUEST['sidx'] . ' ' . $_REQUEST['sord'];
                    if (isset($_REQUEST['quicksearch'])) {
                        $dataset = template::search($orderby, array('quicksearch' => $_REQUEST['quicksearch']));
                    } else {
                        $dataset = template::search($orderby);
                    }
                    $total = count($dataset);
                    $out = array();
                    $permissions = array(0 => '<img src="img/icons/silk/world.png" align="absmiddle" /> ' . t(69, 'Published'), 1 => '<img src="img/icons/silk/world_dawn.png" align="absmiddle" /> ' . t(70, 'Private'), 2 => '<img src="img/icons/silk/world_night.png" align="absmiddle" /> ' . t(81, 'Hidden'));
                    if (empty($dataset)) {
                        $rows = 0;
                    } else {
                        $rows = count($dataset);
                    }
                    for ($i = 0; $i < $rows; $i++) {
                        $out[$i] = array(0 => $dataset[$i]['id'], 1 => $dataset[$i]['title'], 2 => $dataset[$i]['theme'], 3 => $permissions[$dataset[$i]['permission']], 4 => $dataset[$i]['enabled'] == 1 ? '<img src="img/icons/silk/accept.png" />' : '<img src="img/icons/silk/cancel.png" />');
                    }
                    navitable::jqgridJson($out, 1, 0, PHP_INT_MAX, $total);
                    break;
            }
            core_terminate();
            break;
        case 'load':
        case 2:
            // edit/new form
            if (!empty($_REQUEST['id'])) {
                if (is_numeric($_REQUEST['id'])) {
                    $item->load(intval($_REQUEST['id']));
                } else {
                    $item->load_from_theme($_REQUEST['id']);
                }
            }
            if (isset($_REQUEST['form-sent'])) {
                $item->load_from_post();
                try {
                    $item->save();
                    if (!empty($_REQUEST['property-enabled'])) {
                        $enableds = array_values($_REQUEST['property-enabled']);
                    } else {
                        $enableds = array();
                    }
                    property::reorder("template", $item->id, $_REQUEST['template-properties-order'], $enableds);
                    $layout->navigate_notification(t(53, "Data saved successfully."), false, false, 'fa fa-check');
                } catch (Exception $e) {
                    $layout->navigate_notification($e->getMessage(), true, true);
                }
                users_log::action($_REQUEST['fid'], $item->id, 'save', $item->title, json_encode($_REQUEST));
            } else {
                users_log::action($_REQUEST['fid'], $item->id, 'load', $item->title);
            }
            $out = templates_form($item);
            break;
        case 'save_template_file':
            // save template html
            if (!empty($_REQUEST['id'])) {
                $item->load(intval($_REQUEST['id']));
            }
            $data = $_REQUEST['templates-file-edit-area'];
            $data = str_replace("\r\n", "\r", $data);
            $x = file_put_contents(NAVIGATE_PRIVATE . '/' . $website->id . '/templates/' . $item->file, $data);
            echo json_encode($x > 0);
            session_write_close();
            exit;
            break;
        case 4:
            // remove
            if (!empty($_REQUEST['id'])) {
                $item->load(intval($_REQUEST['id']));
                if ($item->delete() > 0) {
                    $layout->navigate_notification(t(55, 'Item removed successfully.'), false);
                    $out = templates_list();
                } else {
                    $layout->navigate_notification(t(56, 'Unexpected error.'), false);
                    $out = webdictionary_list();
                }
                users_log::action($_REQUEST['fid'], $item->id, $item->title, 'remove');
            }
            break;
        case 'template_property_load':
            $property = new property();
            if (!empty($_REQUEST['id'])) {
                if (is_numeric($_REQUEST['id'])) {
                    $property->load(intval($_REQUEST['id']));
                } else {
                    $property->load_from_theme($_REQUEST['id'], null, 'template', $_REQUEST['template']);
                }
            }
            header('Content-type: text/json');
            $types = property::types();
            $property->type_text = $types[$property->type];
            echo json_encode($property);
            session_write_close();
            exit;
            break;
        case 'template_property_save':
            // save property details
            $property = new property();
            if (!empty($_REQUEST['property-id'])) {
                $property->load(intval($_REQUEST['property-id']));
            }
            $property->load_from_post();
            $property->save();
            header('Content-type: text/json');
            $types = property::types();
            $property->type_text = $types[$property->type];
            echo json_encode($property);
            session_write_close();
            exit;
            break;
        case 'template_property_remove':
            // remove property
            $property = new property();
            if (!empty($_REQUEST['property-id'])) {
                $property->load(intval($_REQUEST['property-id']));
            }
            $property->delete();
            session_write_close();
            exit;
            break;
        case 0:
            // list / search result
        // list / search result
        default:
            $out = templates_list();
            break;
    }
    return $out;
}