示例#1
0
function nvweb_breadcrumbs_parent($category_id)
{
    $category = new structure();
    $category->load($category_id);
    return $category->parent;
}
示例#2
0
 function metaWeblog_getPost($args)
 {
     global $DB;
     global $session;
     $out = array();
     list($post_id, $username, $password) = $args;
     $item = new item();
     $item->load(intval($post_id));
     $website_id = $item->website;
     $website = new website();
     $website->load($website_id);
     // check auth
     if (metaWeblog_userAllowed($username, $password, $website_id)) {
         if ($item->embedding == 1) {
             $link = nvweb_source_url('structure', $item->category, $session['lang']);
         } else {
             $link = $item->link($session['lang']);
         }
         $category = new structure();
         $category->load($item->category);
         $content = $item->dictionary[$session['lang']]['section-main'];
         $content = nvweb_template_fix_download_paths($content);
         if (empty($item->date_to_display)) {
             $item->date_to_display = $item->date_created;
         }
         $out = array("postid" => $item->id, "userid" => $item->author, "dateCreated" => new IXR_Date($item->date_to_display), "category" => $item->category, "title" => $item->dictionary[$session['lang']]['title'], "description" => $content, "url" => $link, "permalink" => $link, "mt_keywords" => $item->dictionary[$session['lang']]['tags']);
     } else {
         $out = new IXR_Error(401, "User not allowed.");
     }
     return $out;
 }
示例#3
0
 public static function export_sample($a_categories, $a_items, $a_block_groups, $a_blocks, $a_comments, $folder)
 {
     global $website;
     global $theme;
     global $DB;
     @set_time_limit(0);
     $categories = array();
     $items = array();
     $blocks = array();
     $block_groups = array();
     $comments = array();
     $properties = array();
     $files = array();
     $settings = array();
     // structure
     for ($c = 0; $c < count($a_categories); $c++) {
         $tmp = new structure();
         $tmp->load($a_categories[$c]);
         //$properties['structure'][$tmp->id] = property::load_properties_associative('structure', $tmp->template, 'structure', $tmp->id);
         $properties['structure'][$tmp->id] = property::load_properties('structure', $tmp->template, 'structure', $tmp->id);
         $categories[$tmp->id] = $tmp;
         // add files referenced in properties
         if (is_array($properties['structure'][$tmp->id])) {
             foreach ($properties['structure'][$tmp->id] as $property) {
                 if ($property->type == 'image' || $property->type == 'file') {
                     $files[] = $property->value;
                 }
             }
         }
     }
     // comments
     for ($c = 0; $c < count($a_comments); $c++) {
         $tmp = new comment();
         $tmp->load($a_comments[$c]);
         $comments[$tmp->id] = $tmp;
     }
     // items
     for ($i = 0; $i < count($a_items); $i++) {
         $tmp = new item();
         $tmp->load($a_items[$i]);
         $template_id = $tmp->template;
         if ($tmp->association != "free" && $tmp->embedding == 1) {
             // we have to get the template set in the category of the item
             $template_id = $DB->query_single('template', 'nv_structure', ' id = ' . protect($tmp->category) . ' AND website = ' . $website->id);
         }
         $properties['item'][$tmp->id] = property::load_properties('item', $template_id, 'item', $tmp->id);
         list($tmp->dictionary, $files) = theme::export_sample_parse_dictionary($tmp->dictionary, $files);
         // add files referenced in properties
         if (is_array($properties['item'][$tmp->id])) {
             foreach ($properties['item'][$tmp->id] as $property) {
                 if ($property->type == 'image' || $property->type == 'file') {
                     $files[] = $property->value;
                 }
             }
         }
         // add files referenced in gallery
         if (is_array($tmp->galleries[0])) {
             $gallery_images = array_keys($tmp->galleries[0]);
             $files = array_merge($files, $gallery_images);
         }
         $items[$tmp->id] = $tmp;
     }
     // block_groups
     for ($i = 0; $i < count($a_block_groups); $i++) {
         $tmp = new block_group();
         $tmp->load($a_block_groups[$i]);
         $block_groups[$tmp->id] = $tmp;
         if (is_array($tmp->blocks)) {
             foreach ($tmp->blocks as $bgb) {
                 if ($bgb['type'] == 'block_group_block') {
                     $properties['block_group_block'][$a_block_groups[$i]][$bgb['uid']] = property::load_properties($bgb['id'], $tmp->code, 'block_group_block', $bgb['id'], $bgb['uid']);
                 } else {
                     if ($bgb['type'] == 'extension') {
                         $properties['block_group_block'][$a_block_groups[$i]][$bgb['uid']] = property::load_properties(NULL, $bgb['id'], "extension_block", NULL, $bgb['uid']);
                     }
                 }
             }
         }
         // note: maybe not all blocks in the group have been selected in the "blocks" tab
         // here we only export the block group definition, the block group blocks properties and the extension blocks properties, not adding anything else to export
     }
     // blocks
     for ($i = 0; $i < count($a_blocks); $i++) {
         $tmp = new block();
         $tmp->load($a_blocks[$i]);
         $properties['block'][$tmp->id] = property::load_properties('block', $tmp->type, 'block', $tmp->id);
         list($tmp->dictionary, $files) = theme::export_sample_parse_dictionary($tmp->dictionary, $files);
         list($tmp->trigger['trigger-content'], $files) = theme::export_sample_parse_array($tmp->trigger['trigger-content'], $files);
         list($tmp->trigger['trigger-html'], $files) = theme::export_sample_parse_array($tmp->trigger['trigger-html'], $files);
         if (!empty($tmp->trigger['trigger-image'])) {
             $files = array_merge($files, array_values($tmp->trigger['trigger-image']));
         }
         if (!empty($tmp->trigger['trigger-rollover'])) {
             $files = array_merge($files, array_values($tmp->trigger['trigger-rollover']));
         }
         if (!empty($tmp->trigger['trigger-rollover-active'])) {
             $files = array_merge($files, array_values($tmp->trigger['trigger-rollover-active']));
         }
         if (!empty($tmp->trigger['trigger-flash'])) {
             $files = array_merge($files, array_values($tmp->trigger['trigger-flash']));
         }
         if (!empty($tmp->action['action-image'])) {
             $files = array_merge($files, array_values($tmp->action['action-image']));
         }
         if (!empty($tmp->action['action-file'])) {
             $files = array_merge($files, array_values($tmp->action['action-file']));
         }
         // add files referenced in properties
         if (is_array($properties['block'][$tmp->id])) {
             foreach ($properties['block'][$tmp->id] as $property) {
                 if ($property->type == 'image' || $property->type == 'file') {
                     $files[] = $property->value;
                 }
             }
         }
         $blocks[$tmp->id] = $tmp;
     }
     // folders
     // save references and get their files list
     $folders = array();
     $folders_to_check = array();
     if (!empty($folder)) {
         array_push($folders_to_check, $folder);
         while (!empty($folders_to_check)) {
             $f = array_shift($folders_to_check);
             $f = file::filesOnPath($f);
             foreach ($f as $file) {
                 if ($file->type == 'folder') {
                     array_push($folders_to_check, $file->id);
                     array_push($folders, $file);
                 } else {
                     $files[] = $file->id;
                 }
             }
         }
     }
     // add files selected as theme_options
     foreach ($theme->options as $to) {
         if ($to->type == 'image' || $to->type == 'file') {
             $to_value = $website->theme_options->{$to->id};
             if (is_array($to_value)) {
                 $files = array_merge($files, $to_value);
             } else {
                 $files[] = $to_value;
             }
         }
     }
     // include favicon in file list
     if (!empty($website->favicon)) {
         $files[] = $website->favicon;
     }
     // files
     $files = array_unique($files);
     for ($f = 0; $f < count($files); $f++) {
         $file = new file();
         $file->load($files[$f]);
         $files[$f] = $file;
     }
     // settings
     $settings['homepage'] = $website->homepage;
     $settings['favicon'] = $website->favicon;
     $zip = new zipfile();
     $zip->addFile(var_export($website->languages, true), 'languages.var_export');
     $zip->addFile(var_export($website->theme_options, true), 'theme_options.var_export');
     $zip->addFile(var_export($categories, true), 'structure.var_export');
     $zip->addFile(var_export($items, true), 'items.var_export');
     $zip->addFile(var_export($block_groups, true), 'block_groups.var_export');
     $zip->addFile(var_export($blocks, true), 'blocks.var_export');
     $zip->addFile(var_export($comments, true), 'comments.var_export');
     $zip->addFile(var_export($files, true), 'files.var_export');
     $zip->addFile(var_export($folders, true), 'folders.var_export');
     $zip->addFile(var_export($properties, true), 'properties.var_export');
     $zip->addFile(var_export($settings, true), 'settings.var_export');
     foreach ($files as $file) {
         $zip->addFile(file_get_contents($file->absolute_path()), 'files/' . $file->id);
     }
     $contents = $zip->file();
     header('Content-Disposition: attachment; filename="' . $website->theme . '_sample.zip"');
     header("Content-type: application/octet-stream");
     header('Content-Length: ' . strlen($contents));
     echo $contents;
 }
示例#4
0
function items_form($item)
{
    global $user;
    global $DB;
    global $website;
    global $layout;
    global $theme;
    global $events;
    global $current_version;
    $navibars = new navibars();
    $naviforms = new naviforms();
    $layout->navigate_media_browser();
    // we can use media browser in this function
    $extra_actions = array();
    if (empty($item->id)) {
        $navibars->title(t(22, 'Items') . ' / ' . t(38, 'Create'));
    } else {
        $navibars->title(t(22, 'Items') . ' / ' . t(170, 'Edit') . ' [' . $item->id . ']');
    }
    $navibars->add_actions(array('<a href="#" onclick="javascript: navigate_media_browser();" title="Ctrl+M">
				<img height="16" align="absmiddle" width="16" src="img/icons/silk/images.png"> ' . t(36, 'Media') . '
			</a>'));
    if (empty($item->id)) {
        $navibars->add_actions(array($user->permission('items.create') == 'true' ? '<a href="#" onclick="navigate_items_tabform_submit(1);" title="Ctrl+S">
					<img height="16" align="absmiddle" width="16" src="img/icons/silk/accept.png"> ' . t(34, 'Save') . '
				</a>' : ""));
    } else {
        $navibars->add_actions(array($user->permission('items.edit') == 'true' || $item->author == $user->id ? '<a href="#" onclick="navigate_items_tabform_submit(1);" title="Ctrl+S">
					<img height="16" align="absmiddle" width="16" src="img/icons/silk/accept.png"> ' . t(34, 'Save') . '
				</a>' : "", $user->permission("items.delete") == 'true' ? '<a href="#" onclick="navigate_delete_dialog();">
					<img height="16" align="absmiddle" width="16" src="img/icons/silk/cancel.png"> ' . t(35, 'Delete') . '
				</a>' : ""));
        $extra_actions[] = '<a href="#" onclick="navigate_items_preview();"><img height="16" align="absmiddle" width="16" src="img/icons/silk/monitor.png"> ' . t(274, 'Preview') . '</a>';
        if ($user->permission("items.create") != 'false') {
            $extra_actions[] = '<a href="?fid=items&act=duplicate&id=' . $item->id . '"><img height="16" align="absmiddle" width="16" src="img/icons/silk/page_copy.png"> ' . t(477, 'Duplicate') . '</a>';
        }
        $layout->add_script('
            function navigate_delete_dialog()
            {
                navigate_confirmation_dialog(
                    function() { window.location.href = "?fid=items&act=delete&id=' . $item->id . '"; }, 
                    null, null, "' . t(35, 'Delete') . '"
                );
            }
        ');
    }
    if (!empty($item->id)) {
        $notes = grid_notes::comments('item', $item->id);
        $navibars->add_actions(array('<a href="#" onclick="javascript: navigate_display_notes_dialog();">
					<span class="navigate_grid_notes_span" style=" width: 20px; line-height: 16px; ">' . count($notes) . '</span>
					<img src="img/skins/badge.png" width="20px" height="18px" style="margin-top: -2px;" class="grid_note_edit" align="absmiddle" /> ' . t(168, 'Notes') . '
				</a>'));
    }
    if (!empty($item->id)) {
        // we attach an event to "items" which will be fired by navibars to put an extra button
        $events->add_actions('items', array('item' => &$item, 'navibars' => &$navibars), $extra_actions);
    }
    if (!empty($item->id)) {
        $layout->navigate_notes_dialog('item', $item->id);
    }
    $navibars->add_actions(array(!empty($item->id) ? '<a href="?fid=items&act=edit"><img height="16" align="absmiddle" width="16" src="img/icons/silk/add.png"> ' . t(38, 'Create') . '</a>' : '', '<a href="?fid=items&act=list"><img height="16" align="absmiddle" width="16" src="img/icons/silk/application_view_list.png"> ' . t(39, 'List') . '</a>', 'search_form'));
    // languages
    $ws_languages = $website->languages();
    $navibars->form('', 'fid=items&act=edit&id=' . $item->id);
    $layout->add_script("\r\n        \$(document).on('keydown.ctrl_s', function (evt) { navigate_items_tabform_submit(1); return false; } );\r\n        \$(document).on('keydown.ctrl_m', function (evt) { navigate_media_browser(); return false; } );\r\n    ");
    $layout->add_script('
		var template_sections = [];	
	');
    $navibars->add_tab(t(43, "Main"));
    // tab #0
    $navibars->add_tab_content($naviforms->hidden('form-sent', 'true'));
    $navibars->add_tab_content($naviforms->hidden('id', $item->id));
    $navibars->add_tab_content_row(array('<label>ID</label>', '<span>' . (!empty($item->id) ? $item->id : t(52, '(new)')) . '</span>'));
    if (empty($item->id)) {
        $item->date_to_display = core_time();
    }
    $navibars->add_tab_content_row(array('<label>' . t(551, 'Date to display') . '</label>', $naviforms->datefield('date_to_display', $item->date_to_display, true)));
    $navibars->add_tab_content_row(array('<label>' . t(85, 'Date published') . '</label>', $naviforms->datefield('date_published', $item->date_published, true)));
    $navibars->add_tab_content_row(array('<label>' . t(90, 'Date unpublished') . '</label>', $naviforms->datefield('date_unpublish', $item->date_unpublish, true)));
    $navibars->add_tab_content_row(array('<label>' . t(364, 'Access') . '</label>', $naviforms->selectfield('access', array(0 => 0, 1 => 2, 2 => 1, 3 => 3), array(0 => t(254, 'Everybody'), 1 => t(362, 'Not signed in'), 2 => t(361, 'Web users only'), 3 => t(512, 'Selected web user groups')), $item->access, 'navigate_webuser_groups_visibility($(this).val());', false, array(1 => t(363, 'Users who have not yet signed in')))));
    $webuser_groups = webuser_group::all_in_array();
    $navibars->add_tab_content_row(array('<label>' . t(506, "Groups") . '</label>', $naviforms->multiselect('groups', array_keys($webuser_groups), array_values($webuser_groups), $item->groups)), 'webuser-groups-field');
    $layout->add_script('
        function navigate_webuser_groups_visibility(access_value)
        {
            if(access_value==3)
                $("#webuser-groups-field").show();
            else
                $("#webuser-groups-field").hide();
        }

        navigate_webuser_groups_visibility(' . $item->access . ');
    ');
    $permission_options = array(0 => t(69, 'Published'), 1 => t(70, 'Private'), 2 => t(81, 'Hidden'));
    if ($user->permission("items.publish") == 'false') {
        if (!isset($item->permission)) {
            $item->permission = 1;
        }
        $navibars->add_tab_content_row(array('<label>' . t(68, 'Status') . '</label>', $permission_options[$item->permission], $naviforms->hidden("permission", $item->permission)));
    } else {
        $navibars->add_tab_content_row(array('<label>' . t(68, 'Status') . '</label>', $naviforms->selectfield('permission', array_keys($permission_options), array_values($permission_options), $item->permission, '', false, array(0 => t(360, 'Visible to everybody'), 1 => t(359, 'Visible only to Navigate CMS users'), 2 => t(358, 'Hidden to everybody'))), '<span id="status_info" class="ui-icon ui-icon-alert"
                       data-message="' . t(618, 'Change the status to Published to see the item on the future publication date currently assigned', false, true) . '"
					   style="display: none; float: none; vertical-align: middle; "></span>'));
    }
    if (empty($item->id)) {
        $item->author = $user->id;
    }
    $author_webuser = $DB->query_single('username', 'nv_users', ' id = ' . $item->author);
    $navibars->add_tab_content($naviforms->hidden('item-author', $item->author));
    $navibars->add_tab_content_row(array('<label>' . t(266, 'Author') . '</label>', $naviforms->textfield('item-author-text', $author_webuser)));
    // script#1
    if ($item->date_modified > 0) {
        $navibars->add_tab_content_row(array('<label>' . t(227, 'Date modified') . '</label>', core_ts2date($item->date_modified, true)));
    }
    if ($item->date_created > 0) {
        $navibars->add_tab_content_row(array('<label>' . t(226, 'Date created') . '</label>', core_ts2date($item->date_created, true)));
    }
    $navibars->add_tab_content_row(array('<label>' . t(280, 'Page views') . '</label>', $item->views), "div_page_views");
    $navibars->add_tab(t(87, "Association"));
    // tab #1
    $navibars->add_tab_content_row(array('<label>' . t(87, "Association") . '</label>', $naviforms->buttonset('association', array('free' => t(100, 'Free'), 'category' => t(78, 'Category')), empty($item->id) ? 'category' : $item->association, "navigate_change_association(this);")));
    $hierarchy = structure::hierarchy(0);
    $categories_list = structure::hierarchyList($hierarchy, $item->category);
    if (empty($categories_list)) {
        $categories_list = '<ul><li value="0">' . t(428, '(no category)') . '</li></ul>';
    }
    $navibars->add_tab_content_row(array('<label>' . t(78, 'Category') . '</label>', $naviforms->dropdown_tree('category', $categories_list, $item->category, 'navigate_item_category_change')), 'div_category_tree');
    $layout->add_script('
        function navigate_item_category_change(id)
        {
            $.ajax(
            {
                url: NAVIGATE_APP + "?fid=" + navigate_query_parameter("fid") + "&act=96&id=" + id,
                dataType: "json",
                data: {},
                success: function(data, textStatus, xhr)
                {
                    item_category_path = data;
                }
            });
        }
    ');
    $navibars->add_tab_content_row(array('<label>' . t(162, 'Embedding') . '</label>', $naviforms->buttonset('embedding', array('1' => t(163, 'Embedded'), '0' => t(164, 'Own path')), empty($item->id) ? '1' : intval($item->embedding), "navigate_change_association();"), '<span id="embedding_info" class="ui-icon ui-icon-info"
			        data-message-title-1="' . t(163, 'Embedded', false, true) . '"
					data-message-content-1="' . t(165, 'Full content is shown on category page. Ex. "Who we are?"', false, true) . '"
					data-message-title-2="' . t(164, 'Own path', false, true) . '"
					data-message-content-2="' . t(166, 'The content is accessed through its own url. Ex. "News"', false, true) . '" 
					style="float: left; margin-left: -4px;">
			</span>'), 'div_category_embedded');
    $navibars->add_tab_content_row(array('<label>' . t(22, 'Elements') . '</label>', '<button style="float: left;">' . t(171, 'Order') . '</button>', '<span id="order_info" class="ui-icon ui-icon-info"
 				   data-message="' . t(425, 'Order elements of a category (unless the template forces other sorting)', false, true) . '"
				   style="float: left; margin-left: 2px;">				   
			</span>', '<div id="items_order_window" style="display: none;"></div>'), 'div_category_order');
    $layout->add_script('
	    $("#div_category_order button").button(
	    {
	        icons:
	        {
                primary: "ui-icon-arrowthick-2-n-s"
            }
	    }).on("click", function(e)
	    {
	        e.stopPropagation();
	        e.preventDefault();
	        navigate_status(navigate_t(6, "Loading") + "...", "loader");

	        $("#items_order_window").load("?fid=items&act=items_order&category=" + $("#category").val() + "&_bogus=" + new Date().getTime(), function()
	        {
	            navigate_status(navigate_t(42, "Ready"), "ready");
                $("#items_order_window").dialog({
                    modal: true,
                    title: "' . t(171, 'Order') . '",
                    width: 600,
                    height: 500,
                    buttons:
                    {
                        "' . t(58, 'Cancel') . '": function()
                        {
                            $(this).dialog("destroy");
                        },
                        "' . t(190, 'Ok') . '": function()
                        {
                            var dialog = this;
                            // save
                            $.post(
                                "?fid=items&act=items_order&category=" + $("#category").val() + "&_bogus=" + new Date().getTime(),
                                {
                                    "items-order": $("#items-order").val()
                                },
                                function(response)
                                {
                                    if(response=="true")
                                    {
                                        $(dialog).dialog("destroy");
                                    }
                                    else
                                    {
                                        $("<div>"+response+"</div>").dialog({
                                            modal: true,
                                            title: "' . t(56, "Unexpected error") . '"
                                        });
                                    }
                                }
                            );
                        }
                    }
                });
            });
	    });
	');
    $templates = template::elements('element');
    $template_select = $naviforms->select_from_object_array('template', $templates, 'id', 'title', $item->template);
    $navibars->add_tab_content_row(array('<label>' . t(79, 'Template') . '</label>', $template_select, '<span id="template_info" class="ui-icon ui-icon-alert"
 				   data-message="' . t(619, "Template changed, please Save now to see the changes in the next tabs", false, true) . '"
				   style="display: none; float: none; vertical-align: middle; "></span>'), 'div_template_select');
    $layout->add_script('
		var last_check = [];
		var active_languages = ["' . implode('", "', array_keys($ws_languages)) . '"];
		$("#div_template_select").hide();
	');
    // script#3
    if (!empty($item->id)) {
        $navibars->add_tab(t(9, "Content"));
        // tab #2
        $navibars->add_tab_content_row(array('<label>' . t(63, 'Languages') . '</label>', $naviforms->buttonset('language_selector', $ws_languages, $website->languages_list[0], "navigate_items_select_language(this);")));
        $template = $item->load_template();
        $translate_extensions = extension::list_installed('translate', false);
        foreach ($website->languages_list as $lang) {
            $navibars->add_tab_content('<div class="language_fields" id="language_fields_' . $lang . '" style=" display: none; ">');
            $navibars->add_tab_content_row(array('<label>' . t(67, 'Title') . '</label>', $naviforms->textfield('title-' . $lang, @$item->dictionary[$lang]['title'])));
            $open_live_site = '';
            if (!empty($item->paths[$lang])) {
                $open_live_site = ' <a target="_blank" href="' . $website->absolute_path(true) . $item->paths[$lang] . '"><img src="img/icons/silk/world_go.png" align="absmiddle" /></a>';
            }
            $navibars->add_tab_content_row(array('<label>' . t(75, 'Path') . $open_live_site . '</label>', $naviforms->textfield('path-' . $lang, @$item->paths[$lang], NULL, 'navigate_items_path_check(this, event);'), '<span>&nbsp;</span>'), 'div_path_' . $lang);
            if (!isset($template->sections)) {
                $template->sections[] = array(0 => array('id' => 'main', 'name' => '#main#', 'editor' => 'tinymce', 'width' => '960px'));
            }
            if (!is_array($template->sections)) {
                $template->sections = array();
            }
            // compatibility fix: auto-correct template sections with missing ID (only "code" provided)
            for ($s = 0; $s < count($template->sections); $s++) {
                if (!isset($template->sections[$s]['id'])) {
                    $template->sections[$s]['id'] = $template->sections[$s]['code'];
                }
            }
            foreach ($template->sections as $section) {
                if (is_object($section)) {
                    $section = (array) $section;
                }
                // ignore empty sections
                if (empty($section)) {
                    continue;
                }
                if ($section['editor'] == 'tinymce') {
                    $translate_menu = '';
                    if (!empty($translate_extensions)) {
                        $translate_extensions_titles = array();
                        $translate_extensions_actions = array();
                        foreach ($translate_extensions as $te) {
                            if ($te['enabled'] == '0') {
                                continue;
                            }
                            $translate_extensions_titles[] = $te['title'];
                            $translate_extensions_actions[] = 'javascript: navigate_tinymce_translate_' . $te['code'] . '(\'section-' . $section['id'] . '-' . $lang . '\', \'' . $lang . '\');';
                        }
                        if (!empty($translate_extensions_actions)) {
                            $translate_menu = $naviforms->splitbutton('translate_' . $lang, '<img src="img/icons/silk/comment.png" align="absmiddle"> ' . t(188, 'Translate'), $translate_extensions_actions, $translate_extensions_titles);
                        }
                    }
                    $navibars->add_tab_content_row(array('<label>' . template::section_name($section['name']) . '<span class="editor_selector" for="section-' . $section['id'] . '-' . $lang . '">' . '<i class="fa fa-border fa-fw fa-lg fa-file-text-o active" data-action="tinymce" title="' . t(614, "Edit with TinyMCE") . '"></i> ' . '<i class="fa fa-border fa-fw fa-lg fa-code" data-action="html" title="' . t(615, "Edit as source code") . '"></i> ' . '<i class="fa fa-border fa-fw fa-lg fa-eraser" data-action="clear" title="' . t(208, "Remove all content") . '"></i>' . '</span>' . '</label>', $naviforms->editorfield('section-' . $section['id'] . '-' . $lang, @$item->dictionary[$lang]['section-' . $section['id']], $section['width'] + 48 . 'px', $lang), '<div style="clear:both; margin-top:5px; float:left; margin-bottom: 10px;">', '<label>&nbsp;</label>', $translate_menu, '<button onclick="navigate_items_copy_from_dialog(\'section-' . $section['id'] . '-' . $lang . '\'); return false;"><img src="img/icons/silk/page_white_copy.png" align="absmiddle"> ' . t(189, 'Copy from') . '...</button> ', '<button onclick="navigate_items_copy_from_history_dialog(\'section-' . $section['id'] . '-' . $lang . '\', \'' . $section['id'] . '\', \'' . $lang . '\', \'' . $section['editor'] . '\'); return false;"><img src="img/icons/silk/time_green.png" align="absmiddle"> ' . t(40, 'History') . '</button> ', !empty($theme->content_samples) ? '<button onclick="navigate_items_copy_from_theme_samples(\'section-' . $section['id'] . '-' . $lang . '\', \'' . $section['id'] . '\', \'' . $lang . '\', \'' . $section['editor'] . '\'); return false;"><img src="img/icons/silk/rainbow.png" align="absmiddle"> ' . t(553, 'Fragments') . ' | ' . $theme->title . '</button> ' : '', '</div>', '<br />'), '', 'lang="' . $lang . '"');
                } else {
                    if ($section['editor'] == 'html') {
                        $navibars->add_tab_content_row(array('<label>' . template::section_name($section['name']) . '</label>', $naviforms->scriptarea('section-' . $section['id'] . '-' . $lang, @$item->dictionary[$lang]['section-' . $section['id']], 'html', ' width: ' . $section['width'] . 'px'), '<div style="clear:both; margin-top:5px; float:left; margin-bottom: 10px;">', '<label>&nbsp;</label>', '<button onclick="navigate_items_copy_from_history_dialog(\'section-' . $section['id'] . '-' . $lang . '\', \'' . $section['id'] . '\', \'' . $lang . '\', \'' . $section['editor'] . '\'); return false;"><img src="img/icons/silk/time_green.png" align="absmiddle"> ' . t(40, 'History') . '</button> ', !empty($theme->content_samples) ? '<button onclick="navigate_items_copy_from_theme_samples(\'section-' . $section['id'] . '-' . $lang . '\', \'' . $section['id'] . '\', \'' . $lang . '\', \'' . $section['editor'] . '\'); return false;"><img src="img/icons/silk/rainbow.png" align="absmiddle"> ' . t(553, 'Fragments') . ' | ' . $theme->title . '</button> ' : '', '</div>', '<br />'), '', 'lang="' . $lang . '"');
                    } else {
                        $translate_menu = '';
                        if (!empty($translate_extensions)) {
                            $translate_extensions_titles = array();
                            $translate_extensions_actions = array();
                            foreach ($translate_extensions as $te) {
                                if ($te['enabled'] == '0') {
                                    continue;
                                }
                                $translate_extensions_titles[] = $te['title'];
                                $translate_extensions_actions[] = 'javascript: navigate_textarea_translate_' . $te['code'] . '(\'section-' . $section['id'] . '-' . $lang . '\', \'' . $lang . '\');';
                            }
                            if (!empty($translate_extensions_actions)) {
                                $translate_menu = $naviforms->splitbutton('translate_' . $lang, '<img src="img/icons/silk/comment.png" align="absmiddle"> ' . t(188, 'Translate'), $translate_extensions_actions, $translate_extensions_titles);
                            }
                        }
                        $navibars->add_tab_content_row(array('<label>' . template::section_name($section['name']) . '</label>', $naviforms->textarea('section-' . $section['id'] . '-' . $lang, @$item->dictionary[$lang]['section-' . $section['id']], 8, 48, ' width: ' . $section['width'] . 'px'), '<div style="clear:both; margin-top:5px; margin-bottom: 10px; ">', '<label>&nbsp;</label>', $translate_menu, '<button onclick="navigate_items_copy_from_history_dialog(\'section-' . $section['id'] . '-' . $lang . '\', \'' . $section['id'] . '\', \'' . $lang . '\', \'' . $section['editor'] . '\'); return false;"><img src="img/icons/silk/time_green.png" align="absmiddle"> ' . t(40, 'History') . '</button> ', !empty($theme->content_samples) ? '<button onclick="navigate_items_copy_from_theme_samples(\'section-' . $section['id'] . '-' . $lang . '\', \'' . $section['id'] . '\', \'' . $lang . '\', \'' . $section['editor'] . '\'); return false;"><img src="img/icons/silk/rainbow.png" align="absmiddle"> ' . t(553, 'Fragments') . ' | ' . $theme->title . '</button> ' : '', '</div>'), '', 'lang="' . $lang . '"');
                    }
                }
            }
            if ($template->tags == 1 || $template->tags == 'true') {
                $tags_copy_select = '';
                $tags_copy_select_pre = '';
                $tags_copy_select_after = '';
                // allow copying tags between languages?
                if (count($website->languages_list) > 1) {
                    $tags_copy_select = $naviforms->selectfield('', array_keys($ws_languages), array_values($ws_languages), '', '', false, '', ' width: auto; position: absolute; margin-top: 1px; ', false);
                    $tags_copy_select = '
						<div style=" position: relative; margin-left: 600px; margin-top: -57px; width: 200px; height: 68px; ">
							<a href="#" class="uibutton" title="' . t(189, "Copy from") . '…"
							   onclick=" navigate_items_tags_copy_from_language($(this).next().val(), \'' . $lang . '\'); return false; ">
								<img src="img/icons/silk/page_white_copy.png" width="16" height="16" align="absmiddle" style=" cursor: pointer; " />
							</a>&nbsp;' . $tags_copy_select . '
						</div>
					';
                }
                $tags_top_list = '
					<div style=" position: relative; margin-left: 600px; margin-top: -93px; width: 200px; height: 92px; ">
						<a href="#" class="uibutton" onclick=" navigate_items_tags_ranking(\'' . $lang . '\', this); return false; ">
							<img src="img/icons/silk/award_star_gold_3.png" width="16" height="16" align="absmiddle" style=" cursor: pointer; " />
							' . t(613, "Most used") . '
						</a>
					</div>
				';
                $navibars->add_tab_content_row(array('<label>' . t(265, 'Tags') . '</label>', $naviforms->textfield('tags-' . $lang, @$item->dictionary[$lang]['tags']), $tags_top_list, $tags_copy_select));
            }
            $layout->add_script('			                
                $("#tags-' . $lang . '").tagit({
                    removeConfirmation: true,
                    allowSpaces: true,
                    singleField: true,
                    singleFieldDelimiter: ",",
                    placeholderText: "+",
                    autocomplete: 
                    {
                        delay: 0, 
                        minLength: 1,
                        source: "?fid=items&act=json_tags_search&lang=' . $lang . '"
                    },
                    afterTagAdded: function(event, ui)
                    {
                        var tags = $(this).tagit("assignedTags");
                        if(tags.length > 0)
                            tags = tags.join(",");
                        else
                            tags = "";
                            
                        $("#tags-' . $lang . '")
                            .val(tags)
                            .trigger("change");
                    },
                    afterTagRemoved: function(event, ui)
                    {                    
                        var tags = $(this).tagit("assignedTags");
                        if(tags.length > 0)
                            tags = tags.join(",");
                        else
                            tags = "";
                            
                        $("#tags-' . $lang . '")
                            .val(tags)
                            .trigger("change");
                    }
                });
                
                $("#tags-' . $lang . '").next().sortable({
                    items: ">li:not(.tagit-new)",
                    update: function(ui, event)
                    {
                        var tags = [];
                        
                        $("#tags-' . $lang . '").next().find("span.tagit-label").each(function()
                        {
                            if($(this).text() != "")
                                tags.push($(this).text());
                        });
                        if(tags.length > 0) tags = tags.join(",");
                        else                tags = "";
                                                    
                        $("#tags-' . $lang . '").val(tags);
                        $("#tags-' . $lang . '").trigger("change");                                                
                    }
                });                
			');
            // script#4
            $navibars->add_tab_content('</div>');
        }
        // translate content_samples titles
        if (is_array($theme->content_samples)) {
            for ($i = 0; $i < count($theme->content_samples); $i++) {
                $theme->content_samples[$i]->title = $theme->t($theme->content_samples[$i]->title);
            }
        }
        $layout->add_script('
			var template_sections = ' . json_encode($template->sections) . ';
		    var theme_content_samples = ' . json_encode($theme->content_samples) . ';
		    var website_theme = "' . $website->theme . '";
		');
        $category = new structure();
        $category->paths = array();
        if (!empty($item->category)) {
            $category->load($item->category);
        }
        $layout->add_script('
			var item_category_path = ' . json_encode($category->paths) . ';
			var item_id = "' . $item->id . '";
		');
        // script#5
        // select the first language of the website as the default origin when copying content
        $default_language = array_keys($ws_languages);
        $default_language = $default_language[0];
        $layout->add_content('
			<div id="navigate_items_copy_from" style=" display: none; ">
				<div class="navigate-form-row">
					<label>' . t(191, 'Source') . '</label>
					' . $naviforms->buttonset('navigate_items_copy_from_type', array('language' => t(46, 'Language'), 'item' => t(180, 'Item')), '0', "navigate_items_copy_from_change_origin(this);") . '
				</div>
				<div class="navigate-form-row" style=" display: none; ">
					<label>' . t(46, 'Language') . '</label>
					' . $naviforms->selectfield('navigate_items_copy_from_language_selector', array_keys($ws_languages), array_values($ws_languages), $default_language) . '
				</div>
				<div class="navigate-form-row" style=" display: none; ">
					<label>' . t(79, 'Template') . '</label>
					' . $naviforms->select_from_object_array('navigate_items_copy_from_template', $templates, 'id', 'title', '', '') . '
				</div>			
				<div class="navigate-form-row" style=" display: none; ">		
					<label>' . t(67, 'Title') . '</label>			
					' . $naviforms->textfield('navigate_items_copy_from_title') . '
					' . $naviforms->hidden('navigate_items_copy_from_item_id', '') . '
				</div>
				<div class="navigate-form-row" style=" display: none; ">
					<label>' . t(239, 'Section') . '</label>
					' . $naviforms->select_from_object_array('navigate_items_copy_from_section', array(), 'id', 'name', '') . '
				</div>			
			</div>
			
			<div id="navigate_items_copy_from_history" style=" display: none; ">
				<div class="navigate-form-row">
					<label>' . t(196, 'Date & time') . '</label>
					<select id="navigate_items_copy_from_history_options" 
							name="navigate_items_copy_from_history_options" 
							onchange="navigate_items_copy_from_history_preview(this.value, $(this).attr(\'type\'));">
					</select>
					<a href="#" onclick="navigate_items_copy_from_history_remove();"><img src="img/icons/silk/cancel.png" align="absmiddle"></a>
				</div>			
				<div class="navigate-form-row">
					<!--<div id="navigate_items_copy_from_history_text"
						 name="navigate_items_copy_from_history_text"
						 style="border: 1px solid #CCCCCC; float: left; height: auto; min-height: 20px; overflow: auto; width: 97%; padding: 3px; background: #f7f7f7;">
					</div>
					-->
					<textarea style="display: none;" id="navigate_items_copy_from_history_stylesheets">' . $website->content_stylesheets('link_tag') . '</textarea>
					<iframe id="navigate_items_copy_from_history_text"
						 name="navigate_items_copy_from_history_text"
						 src="about:blank"
						 style="border: 1px solid #CCCCCC; float: left; height: 300px; min-height: 20px; overflow: auto; width: 97%; padding: 3px; ">
					</iframe>
					<div id="navigate_items_copy_from_history_text_raw" style=" display: none; "></div>
				</div>			
			</div>

			<div id="navigate_items_copy_from_theme_samples" style=" display: none; ">
				<div class="navigate-form-row">
					<label>' . t(79, 'Template') . '</label>
					<select id="navigate_items_copy_from_theme_samples_options"
							name="navigate_items_copy_from_theme_samples_options"
							onchange="navigate_items_copy_from_theme_samples_preview(this.value, $(this).attr(\'type\'), $(this).find(\'option:selected\').attr(\'source\'));">
					</select>
				</div>
				<div class="navigate-form-row">
					<div id="navigate_items_copy_from_theme_samples_text"
						 name="navigate_items_copy_from_theme_samples_text"
						 style="border: 1px solid #CCCCCC; float: left; height: auto; min-height: 20px; overflow: auto; width: 97%; padding: 3px; background: #f7f7f7;">
					</div>
					<div id="navigate_items_copy_from_theme_samples_text_raw" style=" display: none; "></div>
				</div>
			</div>
		');
        // script will be bound to onload event at the end of this php function (after getScript is done)
        $onload_language = $_REQUEST['tab_language'];
        if (empty($onload_language)) {
            $onload_language = $website->languages_list[0];
        }
        $layout->add_script('
			function navigate_items_onload()
			{
				navigate_items_select_language("' . $onload_language . '");
				navigate_change_association("' . (empty($item->id) ? 'category' : $item->association) . '");
				setTimeout(function()
				{
					$(navigate_codemirror_instances).each(function() { this.refresh(); } );
				}, 500);
			};
		');
        /* IMAGE GALLERIES */
        if ($template->gallery === 'true' || $template->gallery > 0) {
            $navibars->add_tab(t(210, "Gallery"));
            // tab #3
            $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') . '" />');
            if (!is_array($item->galleries[0])) {
                $item->galleries[0] = array();
            }
            $gallery_elements_order = implode('#', array_keys($item->galleries[0]));
            $navibars->add_tab_content($naviforms->hidden('items-gallery-elements-order', $gallery_elements_order));
            $gallery = '<ul id="items-gallery-elements" class="items-gallery">';
            $ids = array_keys($item->galleries[0]);
            //$default_img = 'data:image/gif;base64,R0lGODlhAQABAPAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='; // transparent pixel
            $default_img = 'img/icons/ricebowl/mimetypes/image.png';
            for ($g = 0; $g < count($ids); $g++) {
                $f = new file();
                $f->load($ids[$g]);
                $gallery .= '
				    <li>
                        <div id="items-gallery-item-' . $ids[$g] . '-droppable" class="navigate-droppable ui-corner-all" data-file-id="' . $f->id . '">
                            <div class="file-access-icons">' . $access[$f->access] . $permissions[$f->permission] . '</div>
                            <img title="' . $ids[$g] . '" src="' . $default_img . '" data-src="' . NAVIGATE_DOWNLOAD . '?wid=' . $website->id . '&id=' . $ids[$g] . '&amp;disposition=inline&amp;width=75&amp;height=75" width="75" height="75" />
                        </div>
                        <div class="navigate-droppable-cancel" style="display: block;"><img src="img/icons/silk/cancel.png" /></div>
                    </li>
                ';
            }
            // empty element
            $gallery .= '
                <li class="gallery-item-empty-droppable">
                    <div id="items-gallery-item-empty-droppable" class="navigate-droppable ui-corner-all">
                        <img src="img/icons/misc/dropbox.png" vspace="18" />
                    </div>
                </li>
            ';
            $gallery .= '</ul>';
            // now the image captions
            foreach ($item->galleries[0] as $image_id => $image_dictionary) {
                if (!is_array($image_dictionary)) {
                    $image_dictionary = array();
                }
                foreach ($website->languages_list as $lang) {
                    $gallery .= $naviforms->hidden('items-gallery-item-' . $image_id . '-dictionary-' . $lang, $image_dictionary[$lang]);
                }
            }
            $navibars->add_tab_content_row(array('<label>' . t(210, 'Gallery') . '</label>', '<div>' . $gallery . '</div>'));
            $layout->add_content('
				<ul id="contextmenu-gallery-items" style="display: none" class="ui-corner-all">
	                <li id="contextmenu-gallery-items-properties"><a href="#"><span class="ui-icon ui-icon-contact"></span>' . t(213, "Image caption") . '</a></li>
	                <li id="contextmenu-gallery-items-permissions"><a href="#"><span class="ui-icon ui-icon-key"></span>' . t(17, "Permissions") . '</a></li>
	                <li id="contextmenu-gallery-items-focalpoint"><a href="#"><span class="ui-icon ui-icon-image"></span>' . t(540, "Focal point") . '</a></li>
	                <li id="contextmenu-gallery-items-description"><a href="#"><span class="ui-icon ui-icon-comment"></span>' . t(334, 'Description') . '</a></li>
	                <li><!--divider--></li>
	                <li id="contextmenu-gallery-items-remove"><a href="#"><span class="ui-icon ui-icon-minus"></span>' . t(627, 'Remove') . '</a></li>
	                <li id="contextmenu-gallery-items-move-beginning"><a href="#"><span class="ui-icon ui-icon-arrowthickstop-1-n"></span>' . t(628, 'Move to the beginning') . '</a></li>
	                <li id="contextmenu-gallery-items-move-end"><a href="#"><span class="ui-icon ui-icon-arrowthickstop-1-s"></span>' . t(629, 'Move to the end') . '</a></li>
	            </ul>
			');
            // script#6
            $layout->add_script('
				$(window).on("load", function()
				{
					new LazyLoad({
					    threshold: 200,
					    container: $("#items-gallery-elements-order").parent()[0],
					    elements_selector: "#items-gallery-elements img",
					    throttle: 40,
					    data_src: "src",
					    show_while_loading: true
					});
				});
			');
            $captions_form = '
				<div id="navigate_items_gallery_captions_form" style=" display: none; ">
					<div class="navigate-form-row">
						<label>' . t(157, 'Image') . '</label>
						' . $naviforms->dropbox('navigate_items_gallery_captions_form_image', '', 'image', true) . '
					</div>
			';
            $caption_langs = array_values($website->languages_list);
            foreach ($caption_langs as $caption_language) {
                $captions_form .= '
					<div class="navigate-form-row">
						<label>' . language::name_by_code($caption_language) . '</label>
						' . $naviforms->textfield('navigate_items_gallery_captions_form_image_' . $caption_language, '') . '
					</div>
				';
            }
            $captions_form .= '
				</div>
			';
            $layout->add_content($captions_form);
        }
        // Properties TAB (only if needed)
        $properties_html = '';
        if ($item->association == 'free' && !empty($item->template) && $item->template != '0') {
            // we already know the properties to show: template is set on item
            $properties_html = navigate_property_layout_form('item', $item->template, 'item', $item->id);
        } else {
            if ($item->association == 'category' && $item->embedding == 0 && !empty($item->template)) {
                // we already know the properties to show: template is set on item
                $properties_html = navigate_property_layout_form('item', $item->template, 'item', $item->id);
            } else {
                if ($item->association == 'category' && $item->category > 0) {
                    // we have to get the template set in the category of the item
                    $template_id = $DB->query_single('template', 'nv_structure', ' id = ' . protect($item->category) . ' AND website = ' . $website->id);
                    $properties_html = navigate_property_layout_form('item', $template_id, 'item', $item->id);
                }
            }
        }
        if (!empty($properties_html)) {
            $navibars->add_tab(t(77, "Properties"));
            // tab #4
            $navibars->add_tab_content($properties_html);
        }
        if ($template->comments > 0 || $template->comments == 'true' || $template->comments === true || is_object($template->comments)) {
            $navibars->add_tab(t(250, "Comments"));
            // tab #5
            $navibars->add_tab_content_row(array('<label>' . t(252, 'Comments enabled to') . '</label>', $naviforms->selectfield('item-comments_enabled_to', array(0 => 0, 1 => 1, 2 => 2), array(0 => t(253, 'Nobody'), 1 => t(24, 'Registered users'), 2 => t(254, 'Everyone')), $item->comments_enabled_to)));
            $moderator_id = '';
            if (!empty($item->comments_moderator)) {
                $moderator_username = $DB->query_single('username', 'nv_users', ' id = ' . $item->comments_moderator);
                if (!empty($moderator_username)) {
                    $moderator_username = array($moderator_username);
                    $moderator_id = array($item->comments_moderator);
                }
            }
            $navibars->add_tab_content_row(array('<label>' . t(255, 'Moderator') . '</label>', $naviforms->selectfield('item-comments_moderator', $moderator_id, $moderator_username, $item->comments_moderator, null, false, null, null, false), '<span style="display: none;" id="item-comments_moderator-helper">' . t(535, "Find user by name") . '</span>', '<div class="subcomment"><img align="absmiddle" src="' . NAVIGATE_URL . '/img/icons/silk/information.png" /> ' . t(256, 'Leave blank to accept all comments') . '</div>'));
            // script#7
            // comments list
            // removed filter: AND nvwu.website = nvc.website ... reason: the webuser could be from another website if sharing webusers is enabled
            // TODO: retrieve comments by AJAX call to avoid memory issues. right now we just retrieve the first 500 comments
            $DB->query('SELECT nvc.*, nvwu.username, nvwu.avatar
						  FROM nv_comments nvc
						 LEFT OUTER JOIN nv_webusers nvwu 
						 			  ON nvwu.id = nvc.user
						 WHERE nvc.website = ' . protect($website->id) . '
						   AND nvc.item = ' . protect($item->id) . '
						ORDER BY nvc.date_created ASC
						LIMIT 500');
            $comments = $DB->result();
            $comments_total = count($comments);
            for ($c = 0; $c < $comments_total; $c++) {
                if ($comments[$c]->status == 2) {
                    $comment_status = 'hidden';
                } else {
                    if ($comments[$c]->status == 1) {
                        $comment_status = 'private';
                    } else {
                        if ($comments[$c]->status == -1) {
                            $comment_status = 'new';
                        } else {
                            $comment_status = 'public';
                        }
                    }
                }
                $navibars->add_tab_content_row(array('<span class="items-comment-label">' . core_ts2date($comments[$c]->date_created, true) . '<br />' . '<strong>' . (empty($comments[$c]->username) ? $comments[$c]->name : $comments[$c]->username) . '</strong>' . '<br />' . $comments[$c]->ip . '</span>', '<div id="items-comment-' . $comments[$c]->id . '" class="items-comment-message items-comment-status-' . $comment_status . '">' . nl2br($comments[$c]->message) . '</div>', empty($comments[$c]->avatar) ? '' : '<img style=" margin-left: 5px; " src="' . NAVIGATE_DOWNLOAD . '?wid=' . $website->id . '&id=' . $comments[$c]->avatar . '&amp;disposition=inline&amp;width=46&amp;height=46" />'));
            }
            $navibars->add_tab_content('
				<div id="items-comments-toolbar">
					<img id="items-comments-toolbar-publish" src="' . NAVIGATE_URL . '/img/icons/silk/accept.png" title="' . t(258, 'Publish') . '" />
					<img id="items-comments-toolbar-unpublish" src="' . NAVIGATE_URL . '/img/icons/silk/delete.png" title="' . t(259, 'Unpublish') . '" />
					<img id="items-comments-toolbar-delete" src="' . NAVIGATE_URL . '/img/icons/silk/decline.png" title="' . t(35, 'Delete') . '" />				
				</div>
			');
            // script#8
            // comments moderation
        }
        if ($item->votes > 0) {
            $navibars->add_tab(t(352, "Votes"));
            // tab #6
            $score = $item->score / $item->votes;
            $navibars->add_tab_content_panel('<img src="img/icons/silk/chart_pie.png" align="absmiddle" /> ' . t(337, 'Summary'), array('<div class="navigate-panels-summary ui-corner-all"><h2>' . $item->votes . '</h2><br />' . t(352, 'Votes') . '</div>', '<div class="navigate-panels-summary ui-corner-all""><h2>' . $score . '</h2><br />' . t(353, 'Score') . '</div>', '<div style=" float: left; margin-left: 8px; "><a href="#" class="uibutton" id="items_votes_webuser">' . t(15, 'Users') . '</a></div>', '<div style=" float: right; margin-right: 8px; "><a href="#" class="uibutton" id="items_votes_reset">' . t(354, 'Reset') . '</a></div>', '<div id="items_votes_webuser_window" style=" display: none; width: 600px; height: 350px; "></div>'), 'navigate-panel-web-summary', '385px', '200px');
            $layout->add_script('
				$("#items_votes_reset").on("click", function()
				{
				    navigate_confirmation_dialog(
				        function()
                        {                         
                            $.post("?fid=items&act=votes_reset&id=' . $item->id . '", function(data)
                            {
                                $("#navigate-panel-web-summary").addClass("ui-state-disabled");
                                navigate_notification("' . t(355, 'Votes reset') . '");
                            });
                        },
                        "' . t(497, "Do you really want to erase this data?") . '",
                        null,
				        "' . t(354, 'Reset') . '"
                    );					    
				});
				
				$("#items_votes_webuser").on("click", function()
				{
					$( "#items_votes_webuser_window" ).dialog(
					{
						title: "' . t(357, 'User votes') . '",
						width: 700,
						height: 400,
						modal: true,
						open: function()
						{
							$( "#items_votes_webuser_window" ).html("<table id=\\"items_votes_webuser_grid\\"></table>");
							$( "#items_votes_webuser_window" ).append("<div id=\\"items_votes_webuser_grid_pager\\"></div>");
							
							jQuery("#items_votes_webuser_grid").jqGrid(
							{
							  url: "?fid=' . $_REQUEST['fid'] . '&act=votes_by_webuser&id=' . $item->id . '",
							  editurl: "?fid=' . $_REQUEST['fid'] . '&act=votes_by_webuser&id=' . $item->id . '",
							  datatype: "json",
							  mtype: "GET",
							  pager: "#items_votes_webuser_grid_pager",	
							  colNames:["ID", "' . t(86, 'Date') . '", "' . t(1, 'Username') . '"],
							  colModel:[
								{name:"id", index:"id", width: 75, align: "left", sortable:true, editable:false, hidden: true},
								{name:"date",index:"date", width: 180, align: "center", sortable:true, editable:false},
								{name:"username", index:"username", align: "left", width: 380, sortable:true, editable:false}
								
							  ],
							  scroll: 1,
							  loadonce: false,
							  autowidth: true,
							  forceFit: true,
							  rowNum: 12,
							  rowList: [12],	
							  viewrecords: true,
							  multiselect: true,		  
							  sortname: "date",
							  sortorder: "desc"
							});	
							
							$("#items_votes_webuser_grid").jqGrid(	
							    "navGrid", 
								"#items_votes_webuser_grid_pager", 
								{
								    add: false,
									edit: false,
									del: true,
									search: false
                                }
                            );
						}
					});
				});				
			');
            $navibars->add_tab_content_panel('<img src="img/icons/silk/chart_line.png" align="absmiddle" /> ' . t(353, 'Score'), array('<div id="navigate-panel-web-score-graph" style=" margin: 8px; height: 150px; width: 360px; "></div>'), 'navigate-panel-web-score', '385px', '200px');
            $votes_by_score = webuser_vote::object_votes_by_score('item', $item->id);
            $gdata = array();
            $colors = array('#0a2f42', '#62bbe8', '#1d8ec7', '#44aee4', '#bbe1f5');
            foreach ($votes_by_score as $vscore) {
                $gdata[] = (object) array('label' => $vscore->value, 'data' => (int) $vscore->votes, 'color' => $colors[$vscore->value % count($colors)]);
            }
            $navibars->add_tab_content('
                <div class="hidden" id="navigate-panel-web-data-score">' . json_encode($gdata) . '</div>
            ');
            $navibars->add_tab_content_panel('<img src="img/icons/silk/chart_line.png" align="absmiddle" /> ' . t(352, 'Votes') . ' (' . t(356, 'last 90 days') . ')', array('<div id="navigate-panel-web-votes-graph" style=" margin: 8px; height: 150px; width: 360px; "></div>'), 'navigate-panel-web-votes', '385px', '200px');
            $votes_by_date = webuser_vote::object_votes_by_date('item', $item->id, 90);
            $navibars->add_tab_content('
                <div class="hidden" id="navigate-panel-web-data-votes_by_date">' . json_encode($votes_by_date) . '</div>
            ');
            // script#9
        }
        $nvweb_preview = NAVIGATE_PARENT . NAVIGATE_FOLDER . '/web/nvweb.php?preview=true&wid=' . $website->id . '&route=';
        $layout->add_script('
			function navigate_items_preview()
			{
				// navigate_items_disable_spellcheck(); not needed in tinymce 4?
				navigate_periodic_event_delegate(); // force saving current data in history
				var url = "' . $nvweb_preview . '";
				var active_language = $("input[name=\'language_selector[]\']:checked").val();

				if($("#template").parent().css("display")=="block")
					url = url + "node/' . $item->id . '&lang=" + active_language + "&template=" + $("#template").val();
			    else // category URL
			        url = url + item_category_path[active_language].slice(1);

				setTimeout(function() { window.open(url); }, 1000);
			}
		');
        $events->trigger('items', 'edit', array('item' => &$item, 'navibars' => &$navibars, 'naviforms' => &$naviforms));
    }
    $layout->add_script('
		$.getScript("lib/packages/items/items.js?r=' . $current_version->revision . '", function()
		{
			if(typeof navigate_items_onload == "function")
				navigate_items_onload();
		});
	');
    return $navibars->generate();
}
function navigate_property_layout_field($property, $object = "", $website_id = "")
{
    global $website;
    global $layout;
    global $theme;
    global $user;
    global $DB;
    $ws = $website;
    $ws_theme = $theme;
    if (!empty($website_id) && $website_id != $website->id) {
        $ws = new website();
        $ws->load($website_id);
        $ws_theme = new theme();
        $ws_theme->load($ws->theme);
    }
    // object used for translations (theme or extension)
    if (empty($object)) {
        $object = $ws_theme;
    }
    $naviforms = new naviforms();
    $langs = $ws->languages_list;
    $field = array();
    if (!isset($property->value)) {
        $property->value = $property->dvalue;
    }
    if (!isset($property->multilanguage)) {
        $property->multilanguage = 'false';
    }
    $property_name = $property->name;
    if (!empty($object)) {
        $property_name = $object->t($property_name);
    }
    if (in_array($property->type, array("text", "textarea", "rich_textarea", "link")) || $property->multilanguage == 'true') {
        if (!isset($property->multilanguage) || $property->multilanguage !== false || $property->multilanguage == "false") {
            $property->multilanguage = 'true';
        } else {
            $property->multilanguage = 'false';
        }
        if (is_object($property->value)) {
            $property->value = (array) $property->value;
        }
        if (!is_array($property->value)) {
            $property->value = array();
        }
        foreach ($langs as $lang) {
            if (!isset($property->value[$lang]) && isset($property->dvalue)) {
                $property->value[$lang] = $property->dvalue;
            }
        }
    }
    // auto show/hide properties by other properties values --> "conditional": [ { "source_property_id" : [value1,"value2"] } ]
    if (!empty($property->conditional)) {
        foreach ($property->conditional as $conditional) {
            foreach ($conditional as $conditional_property => $conditional_values) {
                if (!is_array($conditional_values)) {
                    $conditional_values = array($conditional_values);
                }
                $conditional_values = '["' . implode('", "', $conditional_values) . '"]';
                $layout->add_script('
                    navigate_tabform_conditional_property("' . $property->id . '", "' . $conditional_property . '", ' . $conditional_values . ');
                ');
            }
        }
    }
    switch ($property->type) {
        case 'value':
            $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
            $field[] = '<label>' . $property_name . '</label>';
            $field[] = $naviforms->textfield("property-" . $property->id, $property->value);
            if (!empty($property->helper)) {
                $helper_text = $property->helper;
                if (!empty($object)) {
                    $helper_text = $object->t($helper_text);
                }
                $field[] = '<div class="subcomment">' . $helper_text . '</div>';
            }
            $field[] = '</div>';
            break;
        case 'decimal':
            $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
            $field[] = '<label>' . $property_name . '</label>';
            $field[] = $naviforms->decimalfield("property-" . $property->id, $property->value, $property->precision, $user->decimal_separator, $user->thousands_separator, @$property->prefix, @$property->suffix);
            if (!empty($property->helper)) {
                $helper_text = $property->helper;
                if (!empty($object)) {
                    $helper_text = $object->t($helper_text);
                }
                $field[] = '<div class="subcomment">' . $helper_text . '</div>';
            }
            $field[] = '</div>';
            break;
        case 'rating':
            $default = explode('#', $property->dvalue);
            $stars = $default[1];
            if (empty($stars)) {
                $stars = 5;
            }
            $inputs = $stars * 2;
            // half stars ALWAYS enabled
            if ($property->value == $property->dvalue) {
                $property->value = intval($default[0]) * 2;
            }
            $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '" style=" height: 18px; ">';
            $field[] = '<label>' . $property_name . '</label>';
            for ($i = 1; $i <= $inputs; $i++) {
                $checked = '';
                if ($property->value == $i) {
                    $checked = ' checked="checked" ';
                }
                $field[] = '<input type="radio" name="property-' . $property->id . '" class="star {split:2}" value="' . $i . '" ' . $checked . ' />';
            }
            if (!empty($property->helper)) {
                $helper_text = $property->helper;
                if (!empty($object)) {
                    $helper_text = $object->t($helper_text);
                }
                $field[] = '<div class="subcomment">' . $helper_text . '</div>';
            }
            $field[] = '</div>';
            break;
        case 'boolean':
            $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
            $field[] = '<label>' . $property_name . '</label>';
            $field[] = $naviforms->checkbox("property-" . $property->id, $property->value == '1');
            if (!empty($property->helper)) {
                $helper_text = $property->helper;
                if (!empty($object)) {
                    $helper_text = $object->t($helper_text);
                }
                $field[] = '<div class="subcomment">' . $helper_text . '</div>';
            }
            $field[] = '</div>';
            break;
        case 'option':
            $options = $property->options;
            if (is_string($options)) {
                $options = mb_unserialize($options);
            } else {
                if (is_object($options)) {
                    $options = (array) $options;
                }
            }
            // translate each option text
            if (!empty($object) && !empty($options)) {
                foreach ($options as $value => $text) {
                    $options[$value] = $object->t($text);
                }
            }
            if (!isset($property->option_html)) {
                $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
                $field[] = '<label>' . $property_name . '</label>';
                $field[] = $naviforms->selectfield("property-" . $property->id, array_keys($options), array_values($options), $property->value);
                if (!empty($property->helper)) {
                    $helper_text = $property->helper;
                    if (!empty($object)) {
                        $helper_text = $object->t($helper_text);
                    }
                    $field[] = '<div class="subcomment">' . $helper_text . '</div>';
                }
                $field[] = '</div>';
            } else {
                // each option formatted in a specific html fragment
                if (isset($property->stylesheet)) {
                    $custom_stylesheet = $property->stylesheet;
                    if (strpos($custom_stylesheet, 'http') === false) {
                        $custom_stylesheet = NAVIGATE_URL . '/themes/' . $ws->theme . '/' . $custom_stylesheet . '?bogus=' . time();
                    }
                    $layout->add_style_tag($custom_stylesheet, false);
                    if (empty($options)) {
                        $custom_stylesheet_contents = file_get_contents(NAVIGATE_PATH . '/themes/' . $ws->theme . '/' . $property->stylesheet);
                        $custom_stylesheet_contents = stylesheet_parse($custom_stylesheet_contents);
                        $options = array();
                        if (is_array($custom_stylesheet_contents)) {
                            foreach ($custom_stylesheet_contents as $rule => $rule_content) {
                                if (in_array(substr($rule, 0, 1), array('.', '#'))) {
                                    $rule = str_replace(array('.', '#', ':before', ':after', ':focus', ':visited'), '', $rule);
                                    $options[$rule] = $rule;
                                    if (!empty($object)) {
                                        $options[$rule] = $object->t($rule);
                                    }
                                }
                            }
                        }
                    }
                }
                $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
                $field[] = '<label>' . $property_name . '</label>';
                $field[] = $naviforms->selectfield("property-" . $property->id, array_keys($options), array_values($options), $property->value, NULL, false, NULL, NULL, false, false);
                $layout->add_script('
					$("#property-' . $property->id . '").select2(
				        {
				            selectOnBlur: true,
				            minimumResultsForSearch: 6,
							escapeMarkup: function (markup)
					        {
					            return markup; // let our custom formatter work
					        },
					        templateSelection: function(row)
					        {					        
					            var option_html = "' . str_replace('"', '\\"', $property->option_html) . '";
					            option_html = option_html.replace(/{{VALUE}}/g, row.id);
					            option_html = option_html.replace(/{{TEXT}}/g, row.text);
					        
					            if(row.id)
					                return option_html;
					            else
					                return "("  + navigate_t(581, "None") + ")";
					        },
					        templateResult: function(data)
					        {
					            var option_html = "' . str_replace('"', '\\"', $property->option_html) . '";
					            option_html = option_html.replace(/{{VALUE}}/g, data.id);
					            option_html = option_html.replace(/{{TEXT}}/g, data.text);
					        
					            if(data.id)
					                return option_html;
					            else
					                return "("  + navigate_t(581, "None") + ")";
					        }
				        }
				    );
			    ');
                if (!empty($property->helper)) {
                    $helper_text = $property->helper;
                    if (!empty($object)) {
                        $helper_text = $object->t($helper_text);
                    }
                    $field[] = '<div class="subcomment">' . $helper_text . '</div>';
                }
                $field[] = '</div>';
            }
            break;
        case 'moption':
            $options = $property->options;
            if (is_string($options)) {
                $options = mb_unserialize($options);
            } else {
                if (is_object($options)) {
                    $options = (array) $options;
                }
            }
            // translate each option text
            if (!empty($object)) {
                foreach ($options as $value => $text) {
                    $options[$value] = $object->t($text);
                }
            }
            $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
            $field[] = '<label>' . $property_name . '</label>';
            $field[] = $naviforms->selectfield("property-" . $property->id, array_keys($options), array_values($options), explode(',', $property->value), "", true);
            if (!empty($property->helper)) {
                $helper_text = $property->helper;
                if (!empty($object)) {
                    $helper_text = $object->t($helper_text);
                }
                $field[] = '<div class="subcomment">' . $helper_text . '</div>';
            }
            $field[] = '</div>';
            break;
        case 'country':
            $options = property::countries();
            $country_codes = array_keys($options);
            $country_names = array_values($options);
            // include "country not defined" item
            array_unshift($country_codes, '');
            array_unshift($country_names, '(' . t(307, "Unspecified") . ')');
            $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
            $field[] = '<label>' . $property_name . '</label>';
            $field[] = $naviforms->selectfield("property-" . $property->id, $country_codes, $country_names, strtoupper($property->value));
            if (!empty($property->helper)) {
                $helper_text = $property->helper;
                if (!empty($object)) {
                    $helper_text = $object->t($helper_text);
                }
                $field[] = '<div class="subcomment">' . $helper_text . '</div>';
            }
            $field[] = '</div>';
            break;
        case 'coordinates':
            $coordinates = explode('#', $property->value);
            $latitude = @$coordinates[0];
            $longitude = @$coordinates[1];
            $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
            $field[] = '<label>' . $property_name . '</label>';
            $field[] = $naviforms->textfield("property-" . $property->id . '-latitude', $latitude, '182px');
            $field[] = $naviforms->textfield("property-" . $property->id . '-longitude', $longitude, '182px');
            $field[] = '<img src="img/icons/silk/map_magnify.png" align="absmiddle" hspace="3px" id="property-' . $property->id . '-show" />';
            $field[] = '<div id="property-' . $property->id . '-map-container" style=" display: none; ">';
            $field[] = '	<div class="navigate-form-row" id="property-' . $property->id . '-search" style=" width: 278px; height: 24px; margin-top: 9px; margin-left: 40px; position: absolute; z-index: 1000; opacity: 0.95; ">';
            $field[] = '		<input type="text" name="property-' . $property->id . '-search-text" style=" width: 240px; " /> ';
            $field[] = '		<img class="ui-widget ui-button ui-state-default ui-corner-all" sprite="false" style=" cursor: pointer; padding: 3px; " src="' . NAVIGATE_URL . '/img/icons/silk/zoom.png" align="right" />';
            $field[] = '	</div>';
            $field[] = '	<div id="property-' . $property->id . '-map" style=" width: 400px; height: 200px; "></div>';
            $field[] = '</div>';
            if (!empty($property->helper)) {
                $helper_text = $property->helper;
                if (!empty($object)) {
                    $helper_text = $object->t($helper_text);
                }
                $field[] = '<div class="subcomment">' . $helper_text . '</div>';
            }
            $field[] = '</div>';
            $layout->add_script('
                // auto parse standard Google Maps URLs when pasting them in the latitude field
                $("#property-' . $property->id . '-latitude").on("keyup", function()
                {
                    var value = $(this).val();                                        
                    if(value.indexOf("https://www.google")==0)
                    {                    
                        // locate the @ symbol
                        value = value.substr(value.indexOf("@")+1);
                        value = value.substr(0, value.indexOf("z"));
                        value = value.split(",");
                                                                        
                        if(value.length == 3) // parsed values seem fine
                        {
                            $("#property-' . $property->id . '-latitude").val(value[0]);                            
                            $("#property-' . $property->id . '-longitude").val(value[1]);                            
                        }
                    }
                });
            ');
            $layout->add_script('
				var property_' . $property->id . '_lmap = null;
			    var marker = null;
			    
			    L.Icon.Default.imagePath = "' . NAVIGATE_URL . '/lib/external/leaflet/images";
			    
			    // initialize leaflet map
                property_' . $property->id . '_lmap = L.map(
                    "property-' . $property->id . '-map",
                    {
                        doubleClickZoom: false
                    }
                );					    
                
                // create the tile layer with correct attribution
                var osmUrl = "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png";
                var osmAttrib = "Map data © <a href=\\"http://openstreetmap.org\\">OpenStreetMap</a> contributors";
                var osm = new L.TileLayer(osmUrl, {minZoom: 0, maxZoom: 19, attribution: osmAttrib });
                
                property_' . $property->id . '_lmap.addLayer(osm);
							
				$("#property-' . $property->id . '-search input").on("keyup", function(e)
				{	if(e.keyCode == 13)	property' . $property->id . 'search();	});
				
				$("#property-' . $property->id . '-search img").on("click", property' . $property->id . 'search);
				
				$("#property-' . $property->id . '-show").on("click", function()
				{
					var myLatlng = new L.LatLng(
					    $("#property-' . $property->id . '-latitude").val(),
					    $("#property-' . $property->id . '-longitude").val()
					);																
												
                    property_' . $property->id . '_lmap.setView(myLatlng, 17);
	                
	                marker = L.marker(myLatlng).addTo(property_' . $property->id . '_lmap);
	                
	                property_' . $property->id . '_lmap.on("dblclick", function(e)
	                {	                    
                        $("#property-' . $property->id . '-latitude").val(e.latlng.lat);
						$("#property-' . $property->id . '-longitude").val(e.latlng.lng)
	                    
	                    marker.remove();
	                    marker = L.marker(e.latlng).addTo(property_' . $property->id . '_lmap);                        
	                });
					                    
					$("#property-' . $property->id . '-map-container").dialog(
					{
						width: 600,
						height: 400,
						title: "' . t(300, 'Map') . ': ' . t(301, 'Double click a place to set the coordinates') . '",
						resize: property' . $property->id . 'resize,
						open: function()
						{
						    $(this).css("padding", 0);
						    property_' . $property->id . '_lmap.invalidateSize();
                        }
                    }).dialogExtend(
					{
						maximizable: true,
						"maximize" : property' . $property->id . 'resize,
						"restore" : property' . $property->id . 'resize
					});
					
					property' . $property->id . 'resize();

				}).css("cursor", "pointer");	
				
				function property' . $property->id . 'resize()
				{
					$("#property-' . $property->id . '-map").width($("#property-' . $property->id . '-map-container").width()); 
					$("#property-' . $property->id . '-map").height($("#property-' . $property->id . '-map-container").height());	
					property_' . $property->id . '_lmap.invalidateSize();
				}
				
				function property' . $property->id . 'search()
				{				
					var address = $("#property-' . $property->id . '-search input").val();

                    $.getJSON("http://services.gisgraphy.com/geocoding/geocode?format=json&callback=?&address="+address, function(data)
                    {                                    
                        if(!data.result || data.result.length < 1)
                            alert("Geocode was not successful for the following reason: " + status);
                        else
                        {
                            property_' . $property->id . '_lmap.setView([data.result[0].lat, data.result[0].lng], 19);
                        }
                    });						        

					return false;
				}		
                
			');
            break;
        case 'text':
            foreach ($langs as $lang) {
                if (!is_array($property->value)) {
                    $ovalue = $property->value;
                    $property->value = array();
                    foreach ($langs as $lang_value) {
                        $property->value[$lang_value] = $ovalue;
                    }
                }
                $language_info = '<span class="navigate-form-row-language-info" title="' . language::name_by_code($lang) . '"><img src="img/icons/silk/comment.png" align="absmiddle" />' . $lang . '</span>';
                $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '" lang="' . $lang . '">';
                $field[] = '<label>' . $property_name . ' ' . $language_info . '</label>';
                $field[] = $naviforms->textfield("property-" . $property->id . "-" . $lang, $property->value[$lang]);
                if (!empty($property->helper)) {
                    $helper_text = $property->helper;
                    if (!empty($object)) {
                        $helper_text = $object->t($helper_text);
                    }
                    $field[] = '<div class="subcomment">' . $helper_text . '</div>';
                }
                $field[] = '</div>';
            }
            break;
        case 'textarea':
            foreach ($langs as $lang) {
                if (!is_array($property->value)) {
                    $ovalue = $property->value;
                    $property->value = array();
                    foreach ($langs as $lang_value) {
                        $property->value[$lang_value] = $ovalue;
                    }
                }
                $style = "";
                if (!empty($property->width)) {
                    $style = ' width: ' . $property->width . 'px; ';
                }
                $language_info = '<span class="navigate-form-row-language-info" title="' . language::name_by_code($lang) . '"><img src="img/icons/silk/comment.png" align="absmiddle" />' . $lang . '</span>';
                if ($property->multilanguage == 'false') {
                    $language_info = '';
                }
                $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '" lang="' . $lang . '">';
                $field[] = '<label>' . $property_name . ' ' . $language_info . '</label>';
                $field[] = $naviforms->textarea("property-" . $property->id . "-" . $lang, $property->value[$lang], 4, 48, $style);
                $field[] = '<button class="navigate-form-row-property-action" data-field="property-' . $property->id . '-' . $lang . '" data-action="copy-from" title="' . t(189, 'Copy from') . '…"><img src="img/icons/silk/page_white_copy.png" align="absmiddle"></button>';
                if (!empty($property->helper)) {
                    $helper_text = $property->helper;
                    if (!empty($object)) {
                        $helper_text = $object->t($helper_text);
                    }
                    $field[] = '<div class="subcomment">' . $helper_text . '</div>';
                }
                $field[] = '</div>';
                if ($property->multilanguage == 'false') {
                    break;
                }
            }
            break;
        case 'rich_textarea':
            foreach ($langs as $lang) {
                if (!is_array($property->value)) {
                    $ovalue = $property->value;
                    $property->value = array();
                    foreach ($langs as $lang_value) {
                        $property->value[$lang_value] = $ovalue;
                    }
                }
                $language_info = '<span class="navigate-form-row-language-info" title="' . language::name_by_code($lang) . '"><img src="img/icons/silk/comment.png" align="absmiddle" />' . $lang . '</span>';
                if ($property->multilanguage == 'false') {
                    $language_info = '';
                }
                $width = NULL;
                if (!empty($property->width)) {
                    $width = $property->width . 'px';
                }
                $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '" lang="' . $lang . '">';
                $field[] = '<label>' . $property_name . ' ' . $language_info . '</label>';
                $field[] = $naviforms->editorfield("property-" . $property->id . "-" . $lang, $property->value[$lang], $width, NULL, $website_id);
                if (!empty($property->helper)) {
                    $helper_text = $property->helper;
                    if (!empty($object)) {
                        $helper_text = $object->t($helper_text);
                    }
                    $field[] = '<div class="subcomment">' . $helper_text . '</div>';
                }
                // additional control buttons
                $translate_menu = '';
                if (!empty($translate_extensions)) {
                    $translate_extensions_titles = array();
                    $translate_extensions_actions = array();
                    foreach ($translate_extensions as $te) {
                        if ($te['enabled'] == '0') {
                            continue;
                        }
                        $translate_extensions_titles[] = $te['title'];
                        $translate_extensions_actions[] = 'javascript: navigate_tinymce_translate_' . $te['code'] . '(\'property-' . $property->id . '-' . $lang . '\', \'' . $lang . '\');';
                    }
                    if (!empty($translate_extensions_actions)) {
                        $translate_menu = $naviforms->splitbutton('translate_' . $lang, '<img src="img/icons/silk/comment.png" align="absmiddle"> ' . t(188, 'Translate'), $translate_extensions_actions, $translate_extensions_titles);
                    }
                }
                $field[] = '<div style="clear:both; margin-top:5px; float:left; margin-bottom: 10px;">';
                $field[] = '<label>&nbsp;</label>';
                $field[] = $translate_menu;
                $field[] = '<button class="navigate-form-row-property-action" data-field="property-' . $property->id . '-' . $lang . '" data-action="copy-from"><img src="img/icons/silk/page_white_copy.png" align="absmiddle">' . t(189, 'Copy from') . '...</button> ';
                $field[] = !empty($theme->content_samples) ? '<button onclick="navigate_items_copy_from_theme_samples(\'property-' . $property->id . '-' . $lang . '\', \'' . $property->id . '\', \'' . $lang . '\', \'tinymce\'); return false;"><img src="img/icons/silk/rainbow.png" align="absmiddle"> ' . t(553, 'Fragments') . ' | ' . $theme->title . '</button> ' : '';
                $field[] = '</div>';
                $field[] = '</div>';
                // divformrow
                if ($property->multilanguage == 'false') {
                    break;
                }
            }
            break;
        case 'color':
            $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
            $field[] = '<label>' . $property_name . '</label>';
            $field[] = $naviforms->colorfield("property-" . $property->id, $property->value, @$property->options);
            if (!empty($property->helper)) {
                $helper_text = $property->helper;
                if (!empty($object)) {
                    $helper_text = $object->t($helper_text);
                }
                $field[] = '<div class="subcomment">' . $helper_text . '</div>';
            }
            $field[] = '</div>';
            break;
        case 'date':
            $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
            $field[] = '<label>' . $property_name . '</label>';
            $field[] = $naviforms->datefield("property-" . $property->id, $property->value, false);
            if (!empty($property->helper)) {
                $helper_text = $property->helper;
                if (!empty($object)) {
                    $helper_text = $object->t($helper_text);
                }
                $field[] = '<div class="subcomment">' . $helper_text . '</div>';
            }
            $field[] = '</div>';
            break;
        case 'datetime':
            $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
            $field[] = '<label>' . $property_name . '</label>';
            $field[] = $naviforms->datefield("property-" . $property->id, $property->value, true);
            if (!empty($property->helper)) {
                $helper_text = $property->helper;
                if (!empty($object)) {
                    $helper_text = $object->t($helper_text);
                }
                $field[] = '<div class="subcomment">' . $helper_text . '</div>';
            }
            $field[] = '</div>';
            break;
        case 'source_code':
            if ($property->multilanguage != 'true' && $property->multilanguage != '1') {
                $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
                $field[] = '<label>' . $property_name . '</label>';
                $field[] = $naviforms->scriptarea("property-" . $property->id, $property->value);
                $field[] = '&nbsp;<button class="navigate-form-row-property-action" data-field="property-' . $property->id . '-' . $lang . '" data-action="copy-from" title="' . t(189, 'Copy from') . '…"><img src="img/icons/silk/page_white_copy.png" align="absmiddle"></button>';
                if (!empty($property->helper)) {
                    $helper_text = $property->helper;
                    if (!empty($object)) {
                        $helper_text = $object->t($helper_text);
                    }
                    $field[] = '<div class="subcomment">' . $helper_text . '</div>';
                }
                $field[] = '</div>';
            } else {
                foreach ($langs as $lang) {
                    if (!is_array($property->value)) {
                        $ovalue = $property->value;
                        $property->value = array();
                        foreach ($langs as $lang_value) {
                            $property->value[$lang_value] = $ovalue;
                        }
                    }
                    $language_info = '<span class="navigate-form-row-language-info" title="' . language::name_by_code($lang) . '"><img src="img/icons/silk/comment.png" align="absmiddle" />' . $lang . '</span>';
                    $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '" lang="' . $lang . '">';
                    $field[] = '<label>' . $property_name . ' ' . $language_info . '</label>';
                    $field[] = $naviforms->scriptarea("property-" . $property->id . "-" . $lang, $property->value[$lang]);
                    $field[] = '&nbsp;<button class="navigate-form-row-property-action" data-field="property-' . $property->id . '-' . $lang . '" data-action="copy-from" title="' . t(189, 'Copy from') . '…"><img src="img/icons/silk/page_white_copy.png" align="absmiddle"></button>';
                    if (!empty($property->helper)) {
                        $helper_text = $property->helper;
                        if (!empty($object)) {
                            $helper_text = $object->t($helper_text);
                        }
                        $field[] = '<div class="subcomment">' . $helper_text . '</div>';
                    }
                    $field[] = '</div>';
                }
            }
            break;
        case 'link':
            foreach ($langs as $lang) {
                if (!is_array($property->value)) {
                    $ovalue = $property->value;
                    $property->value = array();
                    foreach ($langs as $lang_value) {
                        $property->value[$lang_value] = $ovalue;
                    }
                }
                $link = explode('##', $property->value[$lang]);
                if (is_array($link)) {
                    $target = @$link[2];
                    $title = @$link[1];
                    $link = $link[0];
                    if (empty($title)) {
                        $title = $link;
                    }
                } else {
                    $title = $property->value[$lang];
                    $link = $property->value[$lang];
                    $target = '_self';
                }
                $language_info = '<span class="navigate-form-row-language-info" title="' . language::name_by_code($lang) . '"><img src="img/icons/silk/comment.png" align="absmiddle" />' . $lang . '</span>';
                if ($property->multilanguage == 'false') {
                    $language_info = '';
                }
                $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '" lang="' . $lang . '" style="margin-bottom: 0px;">';
                $field[] = '<label>' . $property_name . ' ' . $language_info . '</label>';
                $field[] = $naviforms->textfield("property-" . $property->id . "-" . $lang . "-title", $title);
                $field[] = '<span class="navigate-form-row-info">' . t(67, 'Title') . '</span>';
                $field[] = '</div>';
                $field[] = '<div class="navigate-form-row" lang="' . $lang . '" style="margin-bottom: 0px;" nv_property="' . $property->id . '" >';
                $field[] = '<label>&nbsp;</label>';
                $field[] = $naviforms->textfield("property-" . $property->id . "-" . $lang . "-link", $link);
                $field[] = '<span class="navigate-form-row-info">' . t(197, 'Link') . '</span>';
                $field[] = '</div>';
                $field[] = '<div class="navigate-form-row" lang="' . $lang . '" nv_property="' . $property->id . '" >';
                $field[] = '<label>&nbsp;</label>';
                $field[] = $naviforms->selectfield("property-" . $property->id . "-" . $lang . "-target", array('_self', '_blank'), array(t(173, "Follow URL"), t(174, "Open URL (new window)")), $target);
                $field[] = '<span class="navigate-form-row-info">' . t(172, 'Action') . '</span>';
                if (!empty($property->helper)) {
                    $helper_text = $property->helper;
                    if (!empty($object)) {
                        $helper_text = $object->t($helper_text);
                    }
                    $field[] = '<div class="subcomment">' . $helper_text . '</div>';
                }
                $field[] = '</div>';
                if ($property->multilanguage == 'false') {
                    break;
                }
            }
            break;
        case 'image':
            if ($property->multilanguage != 'true' && $property->multilanguage != '1') {
                $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
                $field[] = '<label>' . $property_name . '</label>';
                $field[] = $naviforms->dropbox("property-" . $property->id, $property->value, "image", false, @$property->dvalue, @$property->options, $website_id);
                if (!empty($property->helper)) {
                    $helper_text = $property->helper;
                    if (!empty($object)) {
                        $helper_text = $object->t($helper_text);
                    }
                    $field[] = '<div class="subcomment">' . $helper_text . '</div>';
                }
                $field[] = '</div>';
            } else {
                foreach ($langs as $lang) {
                    if (!is_array($property->value)) {
                        $ovalue = $property->value;
                        $property->value = array();
                        foreach ($langs as $lang_value) {
                            $property->value[$lang_value] = $ovalue;
                        }
                    }
                    $language_info = '<span class="navigate-form-row-language-info" title="' . language::name_by_code($lang) . '"><img src="img/icons/silk/comment.png" align="absmiddle" />' . $lang . '</span>';
                    $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '" lang="' . $lang . '">';
                    $field[] = '<label>' . $property_name . ' ' . $language_info . '</label>';
                    $field[] = $naviforms->dropbox("property-" . $property->id . "-" . $lang, $property->value[$lang], "image", false, @$property->dvalue, $website_id);
                    if (!empty($property->helper)) {
                        $helper_text = $property->helper;
                        if (!empty($object)) {
                            $helper_text = $object->t($helper_text);
                        }
                        $field[] = '<div class="subcomment">' . $helper_text . '</div>';
                    }
                    $field[] = '</div>';
                }
            }
            break;
        case 'video':
            if ($property->multilanguage != 'true' && $property->multilanguage != '1') {
                $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
                $field[] = '<label>' . $property_name . '</label>';
                $field[] = $naviforms->dropbox("property-" . $property->id, $property->value, "video", false, $property->dvalue, $website_id);
                if (!empty($property->helper)) {
                    $helper_text = $property->helper;
                    if (!empty($object)) {
                        $helper_text = $object->t($helper_text);
                    }
                    $field[] = '<div class="subcomment">' . $helper_text . '</div>';
                }
                $field[] = '</div>';
            } else {
                foreach ($langs as $lang) {
                    if (!is_array($property->value)) {
                        $ovalue = $property->value;
                        $property->value = array();
                        foreach ($langs as $lang_value) {
                            $property->value[$lang_value] = $ovalue;
                        }
                    }
                    $language_info = '<span class="navigate-form-row-language-info" title="' . language::name_by_code($lang) . '"><img src="img/icons/silk/comment.png" align="absmiddle" />' . $lang . '</span>';
                    $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
                    $field[] = '<label>' . $property_name . ' ' . $language_info . '</label>';
                    $field[] = $naviforms->dropbox("property-" . $property->id . "-" . $lang, $property->value[$lang], "video", false, $property->dvalue, $website_id);
                    if (!empty($property->helper)) {
                        $helper_text = $property->helper;
                        if (!empty($object)) {
                            $helper_text = $object->t($helper_text);
                        }
                        $field[] = '<div class="subcomment">' . $helper_text . '</div>';
                    }
                    $field[] = '</div>';
                }
            }
            break;
        case 'file':
            $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
            $field[] = '<label>' . $property_name . '</label>';
            $field[] = $naviforms->dropbox("property-" . $property->id, $property->value, NULL, NULL, NULL, NULL, $website_id);
            if (!empty($property->helper)) {
                $helper_text = $property->helper;
                if (!empty($object)) {
                    $helper_text = $object->t($helper_text);
                }
                $field[] = '<div class="subcomment">' . $helper_text . '</div>';
            }
            $field[] = '</div>';
            break;
        case 'comment':
            $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
            $field[] = '<label>' . $property_name . '</label>';
            $comment_text = $property->value;
            if (!empty($object)) {
                $comment_text = $object->t($property->value);
            }
            $field[] = '<div class="subcomment" style="clear: none;">' . $comment_text . '</div>';
            $field[] = '</div>';
            break;
        case 'category':
            $hierarchy = structure::hierarchy(0, $website_id);
            $categories_list = structure::hierarchyList($hierarchy, $property->value);
            if (empty($categories_list)) {
                $categories_list = '<ul><li value="0">' . t(428, '(no category)') . '</li></ul>';
            }
            $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
            $field[] = '<label>' . $property_name . '</label>';
            $field[] = $naviforms->dropdown_tree("property-" . $property->id, $categories_list, $property->value);
            if (!empty($property->helper)) {
                $helper_text = $property->helper;
                if (!empty($object)) {
                    $helper_text = $object->t($helper_text);
                }
                $field[] = '<div class="subcomment">' . $helper_text . '</div>';
            }
            $field[] = '</div>';
            break;
        case 'categories':
            $hierarchy = structure::hierarchy(0, $website_id);
            $selected = explode(',', $property->value);
            if (!is_array($selected)) {
                $selected = array($property->value);
            }
            $categories_list = structure::hierarchyList($hierarchy, $selected);
            $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
            $field[] = '<label>' . $property_name . '</label>';
            $field[] = '<div class="category_tree" id="categories-tree-property-' . $property->id . '">
                            <img src="img/icons/silk/world.png" align="absmiddle" /> ' . $ws->name . '<div class="tree_ul">' . $categories_list . '</div>' . '</div>';
            $field[] = $naviforms->hidden('property-' . $property->id, $property->value);
            $field[] = '<label>&nbsp;</label>';
            $field[] = '<button id="categories_tree_select_all_categories-property-' . $property->id . '">' . t(481, 'Select all') . '</button>';
            if (!empty($property->helper)) {
                $helper_text = $property->helper;
                if (!empty($object)) {
                    $helper_text = $object->t($helper_text);
                }
                $field[] = '<div class="subcomment">' . $helper_text . '</div>';
            }
            $field[] = '</div>';
            $layout->add_script('              
                $("#categories-tree-property-' . $property->id . ' .tree_ul").jstree({
                    plugins: ["changed", "types", "checkbox"],
                    "types" :
                    {
                        "default":  {   "icon": "img/icons/silk/folder.png"    },
                        "leaf":     {   "icon": "img/icons/silk/page_white.png"      }
                    },
                    "checkbox":
                    {
                        three_state: false,
                        cascade: "undetermined"
                    },
                    "core":
                    {
                        dblclick_toggle: false
                    }
                })
                .on("dblclick.jstree", function(e)
                {
                    e.preventDefault();
                    e.stopPropagation();
                
                    var li = $(e.target).closest("li");
                    $("#categories-tree-property-' . $property->id . ' .tree_ul").jstree("open_node", "#" + li[0].id);
                
                    var children_nodes = new Array();
                    children_nodes.push(li);
                    $(li).find("li").each(function() {
                        children_nodes.push("#" + $(this)[0].id);
                    });
                
                    $("#categories-tree-property-' . $property->id . ' .tree_ul").jstree("select_node", children_nodes);
                
                    return false;
                })
                .on("changed.jstree", function(e, data)
                {
                    var i, j, r = [];
                    var categories = new Array();
                    $("#property-' . $property->id . '").val("");       
                
                    for(i = 0, j = data.selected.length; i < j; i++)
                    {
                        var id = data.instance.get_node(data.selected[i]).data.nodeId;
                        categories.push(id);
                    }
                    
                    if(categories.length > 0)
                        $("#property-' . $property->id . '").val(categories);                                                                
                });

                $("#categories_tree_select_all_categories-property-' . $property->id . '").on("click", function(e)
                {
                    e.stopPropagation();
                    e.preventDefault();
                    $("#categories-tree-property-' . $property->id . ' .tree_ul").jstree("select_all");
                    return false;
                });                                
            ');
            break;
        case 'element':
        case 'item':
            $property_item_title = '';
            $property_item_id = '';
            if (!empty($property->value)) {
                $property_item_title = $DB->query_single('text', 'nv_webdictionary', '   node_type = "item" AND
                        website = "' . $ws->id . '" AND
                        node_id = "' . $property->value . '" AND
                        subtype = "title" AND
                        lang = "' . $ws->languages_published[0] . '"');
                $property_item_title = array($property_item_title);
                $property_item_id = array($property->value);
            }
            $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
            $field[] = '<label>' . $property_name . '</label>';
            $field[] = $naviforms->selectfield("property-" . $property->id, $property_item_id, $property_item_title, $property->value, null, false, null, null, false);
            if (!empty($property->helper)) {
                $helper_text = $property->helper;
                if (!empty($object)) {
                    $helper_text = $object->t($helper_text);
                }
                $field[] = '<div class="subcomment">' . $helper_text . '</div>';
            }
            $field[] = '</div>';
            $template_filter = @$property->element_template;
            if (empty($template_filter)) {
                $template_filter = $property->item_template;
            }
            $layout->add_script('
                $("#property-' . $property->id . '").select2(
                {
                    placeholder: "' . t(533, "Find element by title") . '",
                    minimumInputLength: 1,
                    ajax: {
                        url: "' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=items&act=json_find_item",
                        dataType: "json",
                        delay: 100,
                        data: function(params)
                        {
	                        return {
				                title: params.term,
				                template: "' . $template_filter . '",
				                nd: new Date().getTime(),
				                page_limit: 30, // page size
				                page: params.page // page number
				            };
                        },
                        processResults: function (data, params)
				        {
				            params.page = params.page || 1;
				            return {
								results: data.items,
								pagination: { more: (params.page * 30) < data.total_count }
							};
				        }
                    },
                    templateSelection: function(row)
					{
						if(row.id)
							return row.text + " <helper style=\'opacity: .5;\'>#" + row.id + "</helper>";
						else
							return row.text;
					},
					escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
                    triggerChange: true,
                    allowClear: true
                });
            ');
            break;
        case 'elements':
            $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
            $field[] = '<label>' . $property_name . '</label>';
            $field[] = $naviforms->textfield("property-" . $property->id);
            if (!empty($property->helper)) {
                $helper_text = $property->helper;
                if (!empty($object)) {
                    $helper_text = $object->t($helper_text);
                }
                $field[] = '<div class="subcomment">' . $helper_text . '</div>';
            }
            $field[] = '</div>';
            $template_filter = @$property->element_template;
            if (empty($template_filter)) {
                $template_filter = $property->item_template;
            }
            $layout->add_script('			                
                $("#property-' . $property->id . '").tagit({
                    removeConfirmation: true,
                    allowSpaces: true,
                    singleField: true,
                    singleFieldDelimiter: ",",
                    placeholderText: "+",
                    autocompleteOnly: true,
                    autocomplete: {
                        delay: 0, 
                        minLength: 1,
                        source: "' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=items&act=json_find_item&format=tagit&page_limit=10&template=' . $template_filter . '"
                    },
                    afterTagAdded: function(event, ui)
                    {                           
                        var tags = $(this).tagit("assignedValues");
                        if(tags.length > 0) tags = tags.join(",");
                        else                tags = "";
                            
                        $("#property-' . $property->id . '").val(tags).trigger("change");
                    },
                    afterTagRemoved: function(event, ui)
                    {
                        var tags = $(this).tagit("assignedValues");
                        if(tags.length > 0) tags = tags.join(",");
                        else                tags = "";

                        $("#property-' . $property->id . '").val(tags).trigger("change");
                    }
                });
                                
                $("#property-' . $property->id . '").next().sortable(
                {
                    items: ">li:not(.tagit-new)",
                    update: function(ui, event)
                    {
                        var tags = $("#property-' . $property->id . '").tagit("assignedValues");
                        if(tags.length > 0) tags = tags.join(",");
                        else                tags = "";

                        $("#property-' . $property->id . '").val(tags).trigger("change");
                    }
                });    
			');
            if (!empty($property->value)) {
                $values = explode(",", $property->value);
                $values = array_filter($values);
                foreach ($values as $cid) {
                    $content_title = $DB->query_single('text', 'nv_webdictionary', '   node_type = "item" AND
                        website = "' . $ws->id . '" AND
                        node_id = ' . protect($cid) . ' AND
                        subtype = "title" AND
                        lang = "' . $ws->languages_published[0] . '"');
                    $layout->add_script('
                        $("#property-' . $property->id . '").tagit("createTag", "' . $content_title . '", "", "", "' . $cid . '");                
                    ');
                }
                $layout->add_script('
                    $("#property-' . $property->id . '").trigger("change");
                ');
            }
            break;
        case 'webuser_groups':
            $webuser_groups = webuser_group::all_in_array();
            // to get the array of groups first we remove the "g" character
            $property->value = str_replace('g', '', $property->value);
            $property->value = explode(',', $property->value);
            $field[] = '<div class="navigate-form-row" nv_property="' . $property->id . '">';
            $field[] = '<label>' . $property_name . '</label>';
            $field[] = $naviforms->multiselect('property-' . $property->id, array_keys($webuser_groups), array_values($webuser_groups), $property->value);
            if (!empty($property->helper)) {
                $helper_text = $property->helper;
                if (!empty($object)) {
                    $helper_text = $object->t($helper_text);
                }
                $field[] = '<div class="subcomment">' . $helper_text . '</div>';
            }
            $field[] = '</div>';
            break;
        case 'product':
            // TO DO (when navigate has products!)
            break;
        default:
    }
    return implode("\n", $field);
}
示例#6
0
function blocks_form($item)
{
    global $user;
    global $DB;
    global $website;
    global $layout;
    global $events;
    global $theme;
    $current_version = $_SESSION['current_version'];
    $navibars = new navibars();
    $naviforms = new naviforms();
    $layout->navigate_media_browser();
    // we can use media browser in this function
    if (empty($item->id)) {
        $navibars->title(t(23, 'Blocks') . ' / ' . t(38, 'Create'));
    } else {
        $navibars->title(t(23, 'Blocks') . ' / ' . t(170, 'Edit') . ' [' . $item->id . ']');
    }
    $navibars->add_actions(array('<a href="#" onclick="javascript: navigate_media_browser();" title="Ctrl+M">
				<img height="16" align="absmiddle" width="16" src="img/icons/silk/images.png"> ' . t(36, 'Media') . '
			</a>'));
    $layout->add_script("\r\n        \$(document).on('keydown.ctrl_s', function (evt) { navigate_tabform_submit(1); return false; } );\r\n        \$(document).on('keydown.ctrl_m', function (evt) { navigate_media_browser(); return false; } );\r\n    ");
    if (!empty($item->id)) {
        $notes = grid_notes::comments('block', $item->id);
        $navibars->add_actions(array('<a href="#" onclick="javascript: navigate_display_notes_dialog();"><span class="navigate_grid_notes_span" style=" width: 20px; line-height: 16px; ">' . count($notes) . '</span><img src="img/skins/badge.png" width="20px" height="18px" style="margin-top: -2px;" class="grid_note_edit" align="absmiddle" /> ' . t(168, 'Notes') . '</a>'));
    }
    if (empty($item->id)) {
        $navibars->add_actions(array($user->permission('blocks.create') == 'true' ? '<a href="#" onclick="navigate_tabform_submit(1);" title="Ctrl+S">
					<img height="16" align="absmiddle" width="16" src="img/icons/silk/accept.png"> ' . t(34, 'Save') . '
				</a>' : ""));
    } else {
        $navibars->add_actions(array($user->permission('blocks.edit') == 'true' ? '<a href="#" onclick="navigate_tabform_submit(1);" title="Ctrl+S">
					<img height="16" align="absmiddle" width="16" src="img/icons/silk/accept.png"> ' . t(34, 'Save') . '
				</a>' : "", $user->permission("blocks.delete") == 'true' ? '<a href="#" onclick="navigate_delete_dialog();">
					<img height="16" align="absmiddle" width="16" src="img/icons/silk/cancel.png"> ' . t(35, 'Delete') . '
				</a>' : ""));
        $layout->add_script('
            function navigate_delete_dialog()
            {
                navigate_confirmation_dialog(
                    function() { window.location.href = "?fid=blocks&act=delete&id=' . $item->id . '"; }, 
                    null, null, "' . t(35, 'Delete') . '"
                );
            }
        ');
    }
    $group_blocks_links = array();
    list($bg_rs, $bg_total) = block_group::paginated_list(0, 10, 'title', 'desc');
    if ($bg_total > 0 && $bg_total <= 10) {
        foreach ($bg_rs as $bg) {
            $group_blocks_links[] = '<a href="?fid=' . $_REQUEST['fid'] . '&act=block_group_edit&id=' . $bg['id'] . '"><i class="fa fa-fw fa-caret-right"></i> ' . $bg['title'] . '</a>';
        }
        $events->add_actions('blocks', array('item' => null, 'navibars' => &$navibars), $group_blocks_links, '<a class="content-actions-submenu-trigger" href="?fid=' . $_REQUEST['fid'] . '&act=block_groups_list"><img height="16" align="absmiddle" width="16" src="img/icons/silk/bricks.png"> ' . t(506, 'Groups') . ' &#9662;</a>');
    }
    $navibars->add_actions(array(!empty($group_blocks_links) ? '' : '<a href="?fid=' . $_REQUEST['fid'] . '&act=block_groups_list"><img height="16" align="absmiddle" width="16" src="img/icons/silk/bricks.png"> ' . t(506, 'Groups') . '</a>', '<a href="?fid=' . $_REQUEST['fid'] . '&act=block_types_list"><img height="16" align="absmiddle" width="16" src="img/icons/silk/brick_edit.png"> ' . t(167, 'Types') . '</a>'));
    $navibars->add_actions(array(!empty($item->id) ? '<a href="?fid=' . $_REQUEST['fid'] . '&act=2"><img height="16" align="absmiddle" width="16" src="img/icons/silk/add.png"> ' . t(38, 'Create') . '</a>' : '', '<a href="?fid=' . $_REQUEST['fid'] . '&act=0"><img height="16" align="absmiddle" width="16" src="img/icons/silk/application_view_list.png"> ' . t(39, 'List') . '</a>', 'search_form'));
    if (!empty($item->id)) {
        $layout->navigate_notes_dialog('block', $item->id);
    }
    $navibars->form();
    $navibars->add_content('
        <script type="text/javascript" src="lib/packages/blocks/blocks.js?r=' . $current_version->revision . '"></script>
    ');
    $navibars->add_tab(t(43, "Main"));
    $navibars->add_tab_content($naviforms->hidden('form-sent', 'true'));
    $navibars->add_tab_content($naviforms->hidden('id', $item->id));
    $navibars->add_tab_content_row(array('<label>ID</label>', '<span>' . (!empty($item->id) ? $item->id : t(52, '(new)')) . '</span>'));
    $block_types = block::types();
    $block_types_keys = array();
    $block_types_info = array();
    for ($i = 0; $i < count($block_types); $i++) {
        if ($item->type == $block_types[$i]['code']) {
            $block_type_width = $block_types[$i]['width'];
        }
        $block_size_helper = '';
        if (!empty($block_types[$i]['width']) || !empty($block_types[$i]['height'])) {
            if (empty($block_types[$i]['width'])) {
                $block_types[$i]['width'] = '***';
            }
            if (empty($block_types[$i]['height'])) {
                $block_types[$i]['height'] = '***';
            }
            $block_size_helper = ' (' . $block_types[$i]['width'] . ' x ' . $block_types[$i]['height'] . ' px)';
        }
        if (is_numeric($block_types[$i]['id'])) {
            $block_types_keys[] = $block_types[$i]['code'];
        } else {
            $block_types_keys[] = $block_types[$i]['id'];
        }
        // block described in theme definition
        $block_types_info[] = $block_types[$i]['title'] . $block_size_helper;
    }
    $navibars->add_tab_content_row(array('<label>' . t(160, 'Type') . '</label>', $naviforms->selectfield('type', $block_types_keys, $block_types_info, $item->type)));
    $navibars->add_tab_content_row(array('<label>' . t(85, 'Date published') . '</label>', $naviforms->datefield('date_published', $item->date_published, true)));
    $navibars->add_tab_content_row(array('<label>' . t(90, 'Date unpublished') . '</label>', $naviforms->datefield('date_unpublish', $item->date_unpublish, true)));
    // Notes field is deprecated, but we keep on showing the existing Notes
    if (!empty($item->notes)) {
        $navibars->add_tab_content_row(array('<label>' . t(168, 'Notes') . '</label>', $naviforms->textarea('notes', $item->notes)));
    }
    $navibars->add_tab_content_row(array('<label>' . t(364, 'Access') . '</label>', $naviforms->selectfield('access', array(0 => 0, 1 => 2, 2 => 1, 3 => 3), array(0 => t(254, 'Everybody'), 1 => t(362, 'Not signed in'), 2 => t(361, 'Web users only'), 3 => t(512, 'Selected web user groups')), $item->access, 'navigate_webuser_groups_visibility($(this).val());', false, array(1 => t(363, 'Users who have not yet signed in')))));
    $webuser_groups = webuser_group::all_in_array();
    $navibars->add_tab_content_row(array('<label>' . t(506, "Groups") . '</label>', $naviforms->multiselect('groups', array_keys($webuser_groups), array_values($webuser_groups), $item->groups)), 'webuser-groups-field');
    $layout->add_script('
        function navigate_webuser_groups_visibility(access_value)
        {
            if(access_value==3)
                $("#webuser-groups-field").show();
            else
                $("#webuser-groups-field").hide();
        }

        navigate_webuser_groups_visibility(' . $item->access . ');
    ');
    if (empty($item->id)) {
        $item->enabled = true;
    }
    $navibars->add_tab_content_row(array('<label>' . t(65, 'Enabled') . '</label>', $naviforms->checkbox('enabled', $item->enabled)));
    if ($item->date_modified > 0) {
        $navibars->add_tab_content_row(array('<label>' . t(227, 'Date modified') . '</label>', core_ts2date($item->date_modified, true)));
    }
    $navibars->add_tab(t(9, "Content"));
    switch ($item->class) {
        case 'poll':
            $options = array();
            foreach ($website->languages_list as $lang) {
                $options[$lang] = language::name_by_code($lang);
            }
            $navibars->add_tab_content_row(array('<label>' . t(63, 'Languages') . '</label>', $naviforms->buttonset('language_selector', $options, $website->languages_list[0], "navigate_items_select_language(this);")));
            foreach ($website->languages_list as $lang) {
                $navibars->add_tab_content('
                    <div class="language_fields" id="language_fields_' . $lang . '" style=" display: none; ">
                ');
                $navibars->add_tab_content_row(array('<label>' . t(558, 'Question') . '</label>', $naviforms->textfield('title-' . $lang, @$item->dictionary[$lang]['title']), ''));
                // Poll options
                $table = new naviorderedtable("poll_answers_table_" . $lang);
                $table->setWidth("330px");
                $table->setHiddenInput("poll-answers-table-order-" . $lang);
                $navibars->add_tab_content($naviforms->hidden("poll-answers-table-order-" . $lang, ""));
                $table->addHeaderColumn(t(67, 'Title'), 200);
                //$table->addHeaderColumn(t(237, 'Code'), 120);
                $table->addHeaderColumn(t(352, 'Votes'), 80);
                $table->addHeaderColumn(t(35, 'Remove'), 50);
                if (!empty($item->trigger[$lang])) {
                    $poll_answers = $item->trigger[$lang];
                    foreach ($poll_answers as $pa) {
                        $uid = uniqid();
                        $table->addRow("poll-answers-table-row-" . $uid, array(array('content' => '<input type="text" name="poll-answers-table-title-' . $lang . '[' . $uid . ']" value="' . $pa['title'] . '" style="width: 200px;" />', 'align' => 'left'), array('content' => '<input type="text" name="poll-answers-table-votes-' . $lang . '[' . $uid . ']" value="' . intval($pa['votes']) . '" style="width: 80px;" />', 'align' => 'left'), array('content' => '<img src="' . NAVIGATE_URL . '/img/icons/silk/cancel.png" style="cursor: pointer;" onclick="navigate_blocks_poll_answers_table_row_remove(this);" />', 'align' => 'center')));
                    }
                }
                $uid = uniqid();
                $table->addRow("poll-answers-table-row-model-" . $lang, array(array('content' => '<input type="text" name="poll-answers-table-title-' . $lang . '[' . $uid . ']" value="" style="width: 200px;" />', 'align' => 'left'), array('content' => '<input type="text" name="poll-answers-table-votes-' . $lang . '[' . $uid . ']" value="0" style="width: 80px;" />', 'align' => 'left'), array('content' => '<img src="' . NAVIGATE_URL . '/img/icons/silk/cancel.png" style="cursor: pointer;" onclick="navigate_blocks_poll_answers_table_row_remove(this);" />', 'align' => 'center')));
                $navibars->add_tab_content_row(array('<label>' . t(559, "Answers") . '</label>', '<div id="poll-answers-' . $lang . '">' . $table->generate() . '</div>', '<label>&nbsp;</label>', '<button id="poll-answers-table-add-' . $lang . '" data-lang="' . $lang . '"><img src="img/icons/silk/add.png" align="absmiddle" style="cursor:pointer;" /> ' . t(472, 'Add') . '</button>'));
                $navibars->add_tab_content('
                    </div>
                ');
            }
            foreach ($website->languages_list as $alang) {
                $layout->add_script('
                    $(window).on("load", function()
                    {
                        poll_answers_table_row_models["' . $alang . '"] = $("#poll-answers-table-row-model-' . $alang . '").html();
                        if($("#poll_answers_table_' . $alang . '").find("tr").not(".nodrag").length > 1)
                            $("#poll-answers-table-row-model-' . $alang . '").hide();
                        navigate_naviorderedtable_poll_answers_table_' . $alang . '_reorder();
                    });
                ');
            }
            $layout->add_script('
                var active_languages = ["' . implode('", "', array_keys($options)) . '"];
                navigate_items_select_language("' . $website->languages_list[0] . '");
            ');
            break;
        case 'block':
        case 'theme':
        default:
            $options = array();
            foreach ($website->languages_list as $lang) {
                $options[$lang] = language::name_by_code($lang);
            }
            $navibars->add_tab_content_row(array('<label>' . t(63, 'Languages') . '</label>', $naviforms->buttonset('language_selector', $options, $website->languages_list[0], "navigate_items_select_language(this);")));
            foreach ($website->languages_list as $lang) {
                $navibars->add_tab_content('<div class="language_fields" id="language_fields_' . $lang . '" style=" display: none; ">');
                $navibars->add_tab_content_row(array('<label>' . t(67, 'Title') . '</label>', $naviforms->textfield('title-' . $lang, @$item->dictionary[$lang]['title']), ''));
                $block_trigger_types = array('' => t(181, 'Hidden'), 'title' => t(67, 'Title'), 'content' => t(9, 'Content'), 'image' => t(157, 'Image'), 'rollover' => t(182, 'Rollover'), 'video' => t(272, 'Video'), 'html' => 'HTML', 'links' => t(549, 'Links'), 'flash' => 'Flash');
                // check block trigger restrictions in theme definition
                if (is_array($theme->blocks)) {
                    foreach ($theme->blocks as $tb) {
                        if ($tb->code == $item->type && isset($tb->trigger)) {
                            if (!is_array($tb->trigger)) {
                                $tb->trigger = array($tb->trigger);
                            }
                            foreach ($block_trigger_types as $btt_key => $btt_val) {
                                if (empty($btt_key) || in_array($btt_key, $tb->trigger)) {
                                    continue;
                                }
                                unset($block_trigger_types[$btt_key]);
                            }
                            $block_trigger_types = array_filter($block_trigger_types);
                        }
                    }
                }
                $navibars->add_tab_content_row(array('<label>' . t(160, 'Type') . '</label>', $naviforms->selectfield('trigger-type-' . $lang, array_keys($block_trigger_types), array_values($block_trigger_types), $item->trigger['trigger-type'][$lang], "navigate_blocks_trigger_change('" . $lang . "', this);")));
                $navibars->add_tab_content_row(array('<label>' . t(157, 'Image') . '</label>', $naviforms->dropbox('trigger-image-' . $lang, @$item->trigger['trigger-image'][$lang], 'image')));
                $navibars->add_tab_content_row(array('<label>' . t(182, 'Rollover') . ' (off / on)</label>', $naviforms->dropbox('trigger-rollover-' . $lang, @$item->trigger['trigger-rollover'][$lang], 'image'), $naviforms->dropbox('trigger-rollover-active-' . $lang, @$item->trigger['trigger-rollover-active'][$lang], 'image'), ''));
                $navibars->add_tab_content_row(array('<label>' . t(272, 'Video') . '</label>', $naviforms->dropbox('trigger-video-' . $lang, @$item->trigger['trigger-video'][$lang], 'video')));
                $navibars->add_tab_content_row(array('<label>Flash (SWF)</label>', $naviforms->dropbox('trigger-flash-' . $lang, @$item->trigger['trigger-flash'][$lang], 'flash'), ''));
                /* links list */
                // check if navigate must show an icon selector
                $links_icons = '';
                if (!empty($theme) && !empty($theme->blocks)) {
                    foreach ($theme->blocks as $tb) {
                        if ($item->type == $tb->id) {
                            $links_icons = @$tb->icons;
                            break;
                        }
                    }
                }
                $table = new naviorderedtable("trigger_links_table_" . $lang);
                $table->setWidth("776px");
                $table->setHiddenInput("trigger-links-table-order-" . $lang);
                $navibars->add_tab_content($naviforms->hidden("trigger-links-table-order-" . $lang, ""));
                $table->addHeaderColumn(t(242, 'Icon'), 50);
                $table->addHeaderColumn(t(67, 'Title'), 200);
                $table->addHeaderColumn(t(197, 'Link'), 390);
                $table->addHeaderColumn('<i class="fa fa-external-link" title="' . t(324, 'New window') . '"></i>', 16);
                $table->addHeaderColumn(t(35, 'Remove'), 50);
                if (empty($item->trigger['trigger-links'][$lang]['link'])) {
                    // create a default entry
                    $item->trigger['trigger-links'][$lang] = array('order' => '', 'icon' => '', 'title' => array('0' => ''), 'link' => array('0' => ''));
                }
                if (!empty($item->trigger['trigger-links'][$lang])) {
                    $tlinks = $item->trigger['trigger-links'][$lang];
                    foreach ($tlinks['link'] as $key => $link) {
                        $uid = uniqid();
                        $table->addRow(uniqid('trigger-links-table-row-'), array(empty($links_icons) ? array('content' => '-', 'align' => 'center') : array('content' => '<select name="trigger-links-table-icon-' . $lang . '[' . $uid . ']" data-select2-value="' . $tlinks['icon'][$key] . '"  data-role="icon" style="width: 190px;"></select>', 'align' => 'left'), array('content' => '<input type="text" name="trigger-links-table-title-' . $lang . '[' . $uid . ']" value="' . $tlinks['title'][$key] . '" data-role="title" style="width: 250px;" />', 'align' => 'left'), array('content' => '<input type="text" name="trigger-links-table-link-' . $lang . '[' . $uid . ']" value="' . $tlinks['link'][$key] . '" data-role="link" style="width: 260px;" />' . '<a class="uibutton nv_block_nv_link_trigger"><i class="fa fa-sitemap"></i></a>', 'align' => 'left', 'style' => 'white-space: nowrap;'), array('content' => '<input type="checkbox" name="trigger-links-table-new_window-' . $lang . '[' . $uid . ']" data-role="target" id="trigger-links-table-new_window-' . $lang . '[' . $uid . ']" value="1" ' . ($tlinks['new_window'][$key] == '1' ? 'checked="checked"' : '') . ' />
                                                    <label for="trigger-links-table-new_window-' . $lang . '[' . $uid . ']" />', 'align' => 'left'), array('content' => '<img src="' . NAVIGATE_URL . '/img/icons/silk/cancel.png" style="cursor: pointer;" onclick="navigate_blocks_trigger_links_table_row_remove(this);" />', 'align' => 'center')));
                    }
                }
                $uid = uniqid();
                $table->addRow("trigger-links-table-row-model-" . $lang, array(empty($links_icons) ? array('content' => '-', 'align' => 'center') : array('content' => '<select name="trigger-links-table-icon-' . $lang . '[' . $uid . ']" data-select2-value="" data-role="icon" style="width: 190px;"></select>', 'align' => 'left'), array('content' => '<input type="text" name="trigger-links-table-title-' . $lang . '[' . $uid . ']" value="" data-role="title" style="width: 250px;" />', 'align' => 'left'), array('content' => '<input type="text" name="trigger-links-table-link-' . $lang . '[' . $uid . ']" value="" data-role="link" style="width: 260px;" />' . '<a class="uibutton nv_block_nv_link_trigger"><i class="fa fa-sitemap"></i></a>', 'align' => 'left'), array('content' => '<input type="checkbox" name="trigger-links-table-new_window-' . $lang . '[' . $uid . ']"  data-role="target" id="trigger-links-table-new_window-' . $lang . '[' . $uid . ']" value="1" />
                                            <label for="trigger-links-table-new_window-' . $lang . '[' . $uid . ']" />', 'align' => 'left'), array('content' => '<img src="' . NAVIGATE_URL . '/img/icons/silk/cancel.png" style="cursor: pointer;" onclick="navigate_blocks_trigger_links_table_row_remove(this);" />', 'align' => 'center')));
                $navibars->add_tab_content_row(array('<label>' . t(549, "Links") . '</label>', '<div id="trigger-links-' . $lang . '">' . $table->generate() . '</div>', '<label>&nbsp;</label>', '<button id="trigger-links-table-add-' . $lang . '" data-lang="' . $lang . '"><img src="img/icons/silk/add.png" align="absmiddle" style="cursor:pointer;" /> ' . t(472, 'Add') . '</button>'));
                $navibars->add_tab_content_row(array('<label>HTML</label>', $naviforms->scriptarea('trigger-html-' . $lang, @$item->trigger['trigger-html'][$lang]), ''));
                $editor_width = "";
                if (!empty($block_type_width)) {
                    if ($block_type_width > 500) {
                        $editor_width = $block_type_width . 'px';
                    } else {
                        $editor_width = '500px';
                    }
                }
                $translate_menu = '';
                if (!empty($translate_extensions)) {
                    $translate_extensions_titles = array();
                    $translate_extensions_actions = array();
                    foreach ($translate_extensions as $te) {
                        if ($te['enabled'] == '0') {
                            continue;
                        }
                        $translate_extensions_titles[] = $te['title'];
                        $translate_extensions_actions[] = 'javascript: navigate_tinymce_translate_' . $te['code'] . '(\'trigger-content-' . $lang . '-' . $lang . '\', \'' . $lang . '\');';
                    }
                    if (!empty($translate_extensions_actions)) {
                        $translate_menu = $naviforms->splitbutton('translate_' . $lang, '<img src="img/icons/silk/comment.png" align="absmiddle"> ' . t(188, 'Translate'), $translate_extensions_actions, $translate_extensions_titles);
                    }
                }
                $navibars->add_tab_content_row(array('<label>' . t(9, "Content") . '
							<span class="editor_selector" for="trigger-content-' . $lang . '">' . '<i class="fa fa-border fa-fw fa-lg fa-file-text-o active" data-action="tinymce" title="' . t(614, "Edit with TinyMCE") . '"></i> ' . '<i class="fa fa-border fa-fw fa-lg fa-code" data-action="html" title="' . t(615, "Edit as source code") . '"></i> ' . '<i class="fa fa-border fa-fw fa-lg fa-eraser" data-action="clear" title="' . t(208, "Remove all content") . '"></i>' . '</span>' . '</label>', $naviforms->editorfield('trigger-content-' . $lang, @$item->trigger['trigger-content'][$lang], $editor_width, $lang), '<div style="clear:both; margin-top:5px; float:left; margin-bottom: 10px;">', '<label>&nbsp;</label>', $translate_menu, !empty($theme->content_samples) ? '<button onclick="navigate_blocks_copy_from_theme_samples(\'trigger-content-' . $lang . '\', \'trigger\', \'' . $lang . '\', \'' . "tinymce" . '\'); return false;"><img src="img/icons/silk/rainbow.png" align="absmiddle"> ' . t(553, 'Fragments') . ' | ' . $theme->title . '</button> ' : '', '</div>', '<br />'), '', 'lang="' . $lang . '"');
                $navibars->add_tab_content_row(array('<label>' . t(172, 'Action') . '</label>', $naviforms->selectfield('action-type-' . $lang, array(0 => '', 1 => 'web', 2 => 'web-n', 3 => 'javascript', 4 => 'file', 5 => 'image'), array(0 => t(183, 'Do nothing'), 1 => t(173, 'Open URL'), 2 => t(174, 'Open URL (new window)'), 3 => 'Javascript', 4 => t(175, 'Download file'), 5 => t(176, 'View image')), $item->action['action-type'][$lang], "navigate_blocks_action_change('" . $lang . "', this);")));
                /* show/hide appropiate row type by action */
                $selected_link_title = '';
                if (!empty($item->action['action-web'][$lang])) {
                    $path = explode('/', $item->action['action-web'][$lang]);
                    if (count($path) > 0 && $path[0] == 'nv:') {
                        if ($path[2] == 'structure') {
                            $tmp = new structure();
                            $tmp->load($path[3]);
                            $selected_link_title = $tmp->dictionary[$lang]['title'];
                            $layout->add_script('
                                $(".nv_block_nv_link_info[data-lang=' . $lang . ']").find("img[data-type=structure]").removeClass("hidden");
                            ');
                        } else {
                            if ($path[2] == 'element') {
                                $tmp = new item();
                                $tmp->load($path[3]);
                                $selected_link_title = $tmp->dictionary[$lang]['title'];
                                $layout->add_script('
                                $(".nv_block_nv_link_info[data-lang=' . $lang . ']").find("img[data-type=element]").removeClass("hidden");
                            ');
                            }
                        }
                    }
                }
                $navibars->add_tab_content_row(array('<label>' . t(184, 'Webpage') . '</label>', $naviforms->autocomplete('action-web-' . $lang, @$item->action['action-web'][$lang], '?fid=' . $_REQUEST['fid'] . '&act=path'), '<a class="uibutton nv_block_nv_link_trigger"><i class="fa fa-sitemap"></i></a>', '<div class="subcomment nv_block_nv_link_info" data-lang="' . $lang . '">
                            <img src="img/icons/silk/sitemap_color.png" class="hidden" data-type="structure" sprite="false" />
                            <img src="img/icons/silk/page.png" class="hidden" data-type="element" sprite="false" /> ' . '<span>' . $selected_link_title . '</span>' . '</div>'));
                $layout->add_script('
                    $("input[name=action-web-' . $lang . ']").on("keydown", function()
                    {
                        var div_info = $(this).parent().find(".nv_block_nv_link_info");
                        $(div_info).find("span").text("");
                        $(div_info).find("img").addClass("hidden");
                    });
                ');
                $navibars->add_tab_content_row(array('<label>Javascript</label>', $naviforms->textfield('action-javascript-' . $lang, @$item->action['action-javascript'][$lang], NULL, "navigate_blocks_action_javascript_clean_quotes('action-javascript-" . $lang . "');"), '<div class="subcomment"><img src="img/icons/silk/information.png" align="absmiddle" /> ' . t(606, 'Double quotes not allowed, use single quotes only') . '</div>'));
                $layout->add_script('
					function navigate_blocks_action_javascript_clean_quotes(id)
		            {
		                var content = $("#" + id).val();
		                content = content.replace(\'"\', "\'");
		                $("#" + id).val(content);
		            }
	            ');
                $navibars->add_tab_content_row(array('<label>' . t(82, 'File') . '</label>', $naviforms->dropbox('action-file-' . $lang, @$item->action['action-file'][$lang]), ''));
                $navibars->add_tab_content_row(array('<label>' . t(157, 'Image') . '</label>', $naviforms->dropbox('action-image-' . $lang, @$item->action['action-image'][$lang], 'image'), ''));
                // copy from other language
                if (count($website->languages) > 1) {
                    $block_copyfrom_titles = array();
                    $block_copyfrom_actions = array();
                    foreach ($website->languages as $bcpl) {
                        if ($bcpl['language'] == $lang) {
                            continue;
                        }
                        $block_copyfrom_titles[] = language::name_by_code($bcpl['language']);
                        $block_copyfrom_actions[] = 'javascript: navigate_blocks_copy_from_language(\'' . $bcpl['language'] . '\', \'' . $lang . '\');';
                    }
                    $copy_from_menu = $naviforms->splitbutton('block_copyfrom_' . $lang, '<img src="img/icons/silk/comment.png" align="absmiddle"> ' . t(189, 'Copy from') . '...', $block_copyfrom_actions, $block_copyfrom_titles);
                    $navibars->add_tab_content_row('<label>&nbsp;</label>' . $copy_from_menu);
                }
                $navibars->add_tab_content('</div>');
            }
            $layout->add_script('
				function navigate_blocks_copy_from_language(from, to)
				{
					// copy title (if destination is empty)
					if($("#title-" + to).val()=="")
						$("#title-" + to).val($("#title-" + from).val());

					// copy trigger type
					$("#trigger-type-" + to)
						.val($("#trigger-type-" + from).val())
						.trigger("change");

					// copy trigger value, depending on the trigger type
					switch($("#trigger-type-" + to).val())
					{
						case "image":
							navigate_dropbox_clone_value("trigger-image-" + from, "trigger-image-" + to);
							break;

						case "rollover":
							navigate_dropbox_clone_value("trigger-rollover-" + from, "trigger-rollover-" + to);
							navigate_dropbox_clone_value("trigger-rollover-active-" + from, "trigger-rollover-active-" + to);
							break;

						case "video":
							navigate_dropbox_clone_value("trigger-video-" + from, "trigger-video-" + to);
							break;

						case "flash":
							navigate_dropbox_clone_value("trigger-flash-" + from, "trigger-flash-" + to);
							break;

						case "html":
							// ncid: navigate codemirror instance destination
							// ncio: navigate codemirror instance destination
							for(ncid in navigate_codemirror_instances)
							{
								if($(navigate_codemirror_instances[ncid].getTextArea()).attr("id") == "trigger-html-" + to)
								{
									for(ncio in navigate_codemirror_instances)
									{
										if($(navigate_codemirror_instances[ncio].getTextArea()).attr("id") == "trigger-html-" + from)
										{
											navigate_codemirror_instances[ncid].setValue(navigate_codemirror_instances[ncio].getValue());
										}
									}
								}
							}
							$(navigate_codemirror_instances).each(function() { this.refresh(); } );
							break;

						case "links":
							// remove previous links (if any)
							$("#trigger-links-" + to).find("tr").not("#trigger-links-table-row-model-" + to).not(":first").remove();

							// copy each link in the origin language
							$("#trigger-links-" + from).find("tr").not("#trigger-links-table-row-model-" + from).not(":first").each(function()
							{
								// add a row
								$("#trigger-links-table-add-" + to).trigger("click");
								$(this).find("td").each(function(i)
								{
									if($(this).find(".select2-container").length > 0)
									{
										// select2 field

										var input_name = $("#trigger_links_table_" + to).find("tr:visible:last").find("td").eq(i).find("select").attr("name");
										var input_value = $(this).find("select").val();

										if(input_name)
											$("select[name=\\""+input_name+"\\"]").val(input_value).trigger("change");
									}
									else
									{
										// standard input or checkbox field
										$("#trigger_links_table_" + to).find("tr:visible:last").find("td").eq(i).find("input").val($(this).find("input").val());
										if($(this).find("input").attr("checked"))
											$("#trigger_links_table_" + to).find("tr:visible:last").find("td").eq(i).find("input").attr("checked", "checked");
									}
								});
							});
							break;

						case "content":
							tinyMCE.get("trigger-content-" + to).setContent(
								tinyMCE.get("trigger-content-" + from).getContent()
							);
							break;

						case "title":
						case "":
						default:
							// nothing to do
							break;
					}

					// copy action type
					$("#action-type-" + to)
						.val($("#action-type-" + from).val())
						.trigger("change");

					// copy action value
					switch($("#action-type-" + to).val())
					{
						case "web":
						case "web-n":
							$("#action-web-" + to).val($("#action-web-" + from).val());
							break;

						case "javascript":
							$("#action-javascript-" + to).val($("#action-javascript-" + from).val());
							break;

						case "file":
							navigate_dropbox_clone_value("action-file-" + from, "action-file-" + to);
							break;

						case "image":
							navigate_dropbox_clone_value("action-image-" + from, "action-image-" + to);
							break;

						case "":
						default:
							// nothing to do
							break;
					}
				}
			');
            // right now, only fontawesome icon set is supported
            $fontawesome_classes = '';
            if ($links_icons == 'fontawesome') {
                $fontawesome_classes = block::fontawesome_list();
                $fontawesome_classes = array_map(function ($v) {
                    $x = new stdClass();
                    $x->id = $v;
                    if (!empty($v)) {
                        $x->text = substr($v, 3);
                    }
                    return $x;
                }, $fontawesome_classes);
            }
            $layout->add_script('
                var active_languages = ["' . implode('", "', array_keys($options)) . '"];
                navigate_items_select_language("' . $website->languages_list[0] . '");
                navigate_fontawesome_classes = ' . json_encode($fontawesome_classes) . ';
            ');
            foreach ($website->languages_list as $alang) {
                $layout->add_script('
					$(window).on("load", function()
					{
						$("#trigger-type-' . $alang . '").val("' . $item->trigger['trigger-type'][$alang] . '");
						$("#action-type-' . $alang . '").val("' . $item->action['action-type'][$alang] . '");
						navigate_blocks_trigger_change("' . $alang . '", $("<input type=\\"hidden\\" value=\\"' . $item->trigger['trigger-type'][$alang] . '\\" />"));

						links_table_row_models["' . $alang . '"] = $("#trigger-links-table-row-model-' . $alang . '").html();
						if($("#trigger_links_table_' . $alang . '").find("tr").not(".nodrag").length > 1)
							$("#trigger-links-table-row-model-' . $alang . '").hide();

						// prepare select2 to select icons
						if(' . ($links_icons == 'fontawesome' ? 'true' : 'false') . ')
						{
							$("[id^=trigger_links_table_").find("tr").each(function(i, tr)
							{
								// do not apply select2 to head row
								if(!$(tr).find("select"))
									return;

								// do not apply select2 to model row
								if($(tr).attr("id") && ($(this).attr("id")).indexOf("table-row-model") > 0)
									return;

								navigate_blocks_trigger_links_table_icon_selector(tr);
							});
						}
					});
            	');
            }
            $layout->add_content('           
                <div id="navigate_blocks_copy_from_theme_samples" style=" display: none; ">
                    <div class="navigate-form-row">
                        <label>' . t(79, 'Template') . '</label>
                        <select id="navigate_blocks_copy_from_theme_samples_options"
                                name="navigate_blocks_copy_from_theme_samples_options"
                                onchange="navigate_blocks_copy_from_theme_samples_preview(this.value, $(this).attr(\'type\'), $(this).find(\'option:selected\').attr(\'source\'));">
                        </select>
                    </div>
                    <div class="navigate-form-row">
                        <div id="navigate_blocks_copy_from_theme_samples_text"
                             name="navigate_blocks_copy_from_theme_samples_text"
                             style="border: 1px solid #CCCCCC; float: left; height: auto; min-height: 20px; overflow: auto; width: 97%; padding: 3px; background: #f7f7f7;">
                        </div>
                        <div id="navigate_blocks_copy_from_theme_samples_text_raw" style=" display: none; "></div>
                    </div>
                </div>
            ');
            $layout->add_script('
                var theme_content_samples = ' . json_encode($theme->content_samples) . ';
                var website_theme = "' . $website->theme . '";
            ');
            break;
    }
    if (!empty($item->type)) {
        // we need to know if the block is defined in the active theme or in the database (numeric ID)
        foreach ($block_types as $bt) {
            if ($bt['code'] == $item->type) {
                $block_type_id = $bt['id'];
                break;
            }
        }
        $properties_html = navigate_property_layout_form('block', $block_type_id, 'block', $item->id);
        if (!empty($properties_html)) {
            $navibars->add_tab(t(77, "Properties"));
            $navibars->add_tab_content($properties_html);
        }
    }
    $navibars->add_tab(t(336, "Display"));
    $default_value = 1;
    if (!empty($item->categories)) {
        $default_value = 0;
    } else {
        if (!empty($item->exclusions)) {
            $default_value = 2;
        }
    }
    $navibars->add_tab_content_row(array('<label>' . t(330, 'Categories') . '</label>', $naviforms->buttonset('all_categories', array('1' => t(396, 'All categories'), '0' => t(405, 'Selection'), '2' => t(552, 'Exclusions')), $default_value)));
    $hierarchy = structure::hierarchy(0);
    $categories_list = structure::hierarchyList($hierarchy, $item->categories);
    $exclusions_list = structure::hierarchyList($hierarchy, $item->exclusions);
    $navibars->add_tab_content_row(array('<label>&nbsp;</label>', '<div class="category_tree" id="category-tree-parent">
                <img src="img/icons/silk/world.png" align="absmiddle" /> ' . $website->name . '<div class="tree_ul">' . $categories_list . '</div>' . '</div>'));
    $navibars->add_tab_content_row(array('<label>&nbsp;</label>', '<div class="category_tree" id="exclusions-tree-parent">
                <img src="img/icons/silk/world.png" align="absmiddle" /> ' . $website->name . '<div class="tree_ul">' . $exclusions_list . '</div>' . '</div>'));
    if (!is_array($item->categories)) {
        $item->categories = array();
    }
    if (!is_array($item->exclusions)) {
        $item->exclusions = array();
    }
    $navibars->add_tab_content($naviforms->hidden('categories', implode(',', $item->categories)));
    $navibars->add_tab_content($naviforms->hidden('exclusions', implode(',', $item->exclusions)));
    $elements_display = "all";
    if (!empty($item->elements['exclusions'])) {
        $elements_display = "exclusions";
    } else {
        if (!empty($item->elements['selection'])) {
            $elements_display = "selection";
        }
    }
    $navibars->add_tab_content_row(array('<label>' . t(22, 'Elements') . ' ' . t(428, '(no category)') . '</label>', $naviforms->buttonset('elements_display', array('all' => t(443, 'All'), 'selection' => t(405, 'Selection'), 'exclusions' => t(552, 'Exclusions')), $elements_display, "navigate_blocks_elements_display_change(this)")));
    $layout->add_script('
		function navigate_blocks_elements_display_change(el)
		{
			el = $(el).prev();
			if($(el).val()=="all")
				$("#elements_selection_wrapper").hide();
			else
				$("#elements_selection_wrapper").show();
		}

		navigate_blocks_elements_display_change($("label[for=elements_display_' . $elements_display . ']"));
	');
    if (!is_array($item->elements)) {
        $item->elements = array();
    }
    $items_ids = array_values($item->elements);
    $items_ids = $items_ids[0];
    if (empty($items_ids)) {
        $items_ids = array();
    }
    $items_titles = array();
    for ($i = 0; $i < count($items_ids); $i++) {
        $item_title = $DB->query_single('text', 'nv_webdictionary', '   node_type = "item" AND
                website = "' . $website->id . '" AND
                node_id = "' . $items_ids[$i] . '" AND
                subtype = "title" AND
                lang = "' . $website->languages_published[0] . '"');
        $items_titles[$i] = $item_title;
    }
    $navibars->add_tab_content_row(array('<label>&nbsp;</label>', $naviforms->selectfield("elements_selection", $items_ids, $items_titles, $items_ids, null, true, null, null, false)), "elements_selection_wrapper");
    $layout->add_script('
		$("#elements_selection").select2({
			placeholder: "' . t(533, "Find element by title") . '",
	        minimumInputLength: 1,
	        ajax: {
	            url: "' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=items&act=json_find_item",
	            dataType: "json",
	            delay: 100,

	            data: function(params)
	            {
	                return {
		                title: params.term,
		                //association: "free",
		                embedding: 0,
		                nd: new Date().getTime(),
		                page_limit: 30, // page size
		                page: params.page // page number
		            };
	            },
	            processResults: function (data, params)
		        {
		            params.page = params.page || 1;
		            return {
						results: data.items,
						pagination: { more: (params.page * 30) < data.total_count }
					};
		        }
	        },
	        templateSelection: function(row)
			{
				if(row.id)
					return row.text + " <helper style=\'opacity: .5;\'>#" + row.id + "</helper>";
				else
					return row.text;
			},
			escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
	        triggerChange: true
		});
		
		$("#elements_selection_wrapper").find(".select2-search__field").css("width", "408px");		
		$("#elements_selection_wrapper").find("li.select2-search").css("width", "auto");
	');
    if (!empty($item->type)) {
        $navibars->add_tab(t(171, 'Order'));
        // order blocs of the same type
        $DB->query('SELECT b.id as id, d.text as title, b.fixed as fixed
					  FROM nv_blocks b, nv_webdictionary d
					 WHERE b.type = "' . $item->type . '"
					   AND d.node_type = "block"
					   AND d.subtype = "title"
					   AND d.lang = "' . $website->languages_list[0] . '"
					   AND d.node_id = b.id
					   AND d.website = ' . $website->id . '
					   AND b.website = ' . $website->id . '
					ORDER BY b.position ASC');
        $block_ids = $DB->result('id');
        $blocks = $DB->result();
        $navibars->add_tab_content($naviforms->hidden('blocks-order', implode('#', $block_ids)));
        $table = new naviorderedtable("blocks_order_table");
        $table->setWidth("408px");
        $table->setHiddenInput("blocks-order");
        $table->addHeaderColumn('ID', 50);
        $table->addHeaderColumn(t(67, 'Title'), 350);
        $table->addHeaderColumn('<div style=" text-align: center; ">' . t(394, 'Fixed') . '</div>', 50);
        foreach ($blocks as $block) {
            $table->addRow($block->id, array(array('content' => $block->id, 'align' => 'left'), array('content' => $block->title, 'align' => 'left'), array('content' => '<span class="checkbox-wrapper">
                                        <input type="checkbox" name="blocks-order-fixed[' . $block->id . ']" id="blocks-order-fixed[' . $block->id . ']" value="1" ' . ($block->fixed == '1' ? 'checked="checked"' : '') . ' />
                                        <label for="blocks-order-fixed[' . $block->id . ']" />
                                    </span>', 'align' => 'center')));
        }
        $navibars->add_tab_content_row(array('<label>' . t(23, 'Blocks') . '</label>', '<div>' . $table->generate() . '</div>', '<div class="subcomment"><img src="img/icons/silk/information.png" align="absmiddle" /> ' . t(72, 'Drag any row to assign priorities') . '</div>', '<div class="subcomment"><span class="ui-icon ui-icon-lightbulb" style=" float: left; margin-right: 4px; "></span> ' . t(395, '"Fixed" assigns a static position when the order is random') . '</div>'));
    }
    return $navibars->generate();
}
 public static function hierarchyListClasses($hierarchy, $level = 1)
 {
     $html = array();
     if (!is_array($hierarchy)) {
         $hierarchy = array();
     }
     foreach ($hierarchy as $node) {
         $post_html = structure::hierarchyListClasses($node->children, $level + 1);
         if (empty($html) && $level == 1) {
             $html[] = '<ul>';
         }
         $extra = '';
         if (!empty($post_html)) {
             $extra = 'group';
         }
         $html[] = '<li class="level' . $level . ' ' . $extra . '" data-value="' . $node->id . '"><span>' . $node->label . '</span>';
         $html[] = $post_html;
         $html[] = '</li>';
     }
     if (!empty($html) && $level == 1) {
         $html[] = '</ul>';
     }
     return implode("\n", $html);
 }
示例#8
0
function structure_form($item)
{
    global $user;
    global $DB;
    global $website;
    global $layout;
    global $events;
    $navibars = new navibars();
    $naviforms = new naviforms();
    $layout->navigate_media_browser();
    // we can use media browser in this function
    if (empty($item->id)) {
        $navibars->title(t(16, 'Structure') . ' / ' . t(38, 'Create'));
    } else {
        $navibars->title(t(16, 'Structure') . ' / ' . t(170, 'Edit') . ' [' . $item->id . ']');
    }
    $navibars->add_actions(array('<a href="#" onclick="javascript: navigate_media_browser();"><img height="16" align="absmiddle" width="16" src="img/icons/silk/images.png"> ' . t(36, 'Media') . '</a>'));
    if (empty($item->id)) {
        $navibars->add_actions(array('<a href="#" onclick="navigate_tabform_submit(1);"><img height="16" align="absmiddle" width="16" src="img/icons/silk/accept.png"> ' . t(34, 'Save') . '</a>'));
    } else {
        $navibars->add_actions(array('<a href="#" onclick="navigate_tabform_submit(1);"><img height="16" align="absmiddle" width="16" src="img/icons/silk/accept.png"> ' . t(34, 'Save') . '</a>', '<a href="#" onclick="navigate_delete_dialog();"><img height="16" align="absmiddle" width="16" src="img/icons/silk/cancel.png"> ' . t(35, 'Delete') . '</a>'));
        $delete_html = array();
        $delete_html[] = '<div id="navigate-delete-dialog" class="hidden">' . t(57, 'Do you really want to delete this item?') . '</div>';
        $delete_html[] = '<script language="javascript" type="text/javascript">';
        $delete_html[] = 'function navigate_delete_dialog()';
        $delete_html[] = '{';
        $delete_html[] = '$("#navigate-delete-dialog").removeClass("hidden");';
        $delete_html[] = '$("#navigate-delete-dialog").dialog({
							resizable: true,
							height: 150,
							width: 300,
							modal: true,
							title: "' . t(59, 'Confirmation') . '",
							buttons: {
								"' . t(58, 'Cancel') . '": function() {
									$(this).dialog("close");
								},
								"' . t(35, 'Delete') . '": function() {
									$(this).dialog("close");
									window.location.href = "?fid=' . $_REQUEST['fid'] . '&act=4&id=' . $item->id . '";
								}
							}
						});';
        $delete_html[] = '}';
        $delete_html[] = '</script>';
        $navibars->add_content(implode("\n", $delete_html));
    }
    $extra_actions = array();
    if (!empty($item->id)) {
        $DB->query('
            SELECT s.id, wd.text as title, s.position
              FROM nv_structure s, nv_webdictionary wd
             WHERE s.website = ' . $item->website . '
               AND s.parent = ' . $item->parent . '
               AND wd.website  = ' . $item->website . '
               AND wd.node_type = "structure"
               AND wd.lang = "' . $website->languages_list[0] . '"
               AND wd.subtype = "title"
               AND wd.node_id = s.id
          ORDER BY s.position ASC, s.id ASC
        ');
        $brothers = $DB->result();
        $previous_brother = NULL;
        $next_brother = NULL;
        for ($b = 0; $b < count($brothers); $b++) {
            if ($brothers[$b]->id == $item->id) {
                $previous_brother = @$brothers[$b - 1]->id;
                $previous_brother_title = @$brothers[$b - 1]->title;
                $next_brother = @$brothers[$b + 1]->id;
                $next_brother_title = @$brothers[$b + 1]->title;
            }
        }
        if (!empty($item->parent)) {
            $parent = new structure();
            $parent->load($item->parent);
            $extra_actions[] = '    <a href="?fid=structure&act=edit&id=' . $parent->id . '">
                                        <img height="16" align="absmiddle" width="16" src="img/icons/silk/resultset_first.png"> 
                                        <small>(' . strtolower(t(84, 'Parent')) . ')</small> ' . $parent->dictionary[$website->languages_list[0]]["title"] . '</a>';
        }
        if (!empty($previous_brother)) {
            $extra_actions[] = '    <a href="?fid=structure&act=edit&id=' . $previous_brother . '">
                                        <img height="16" align="absmiddle" width="16" src="img/icons/silk/resultset_previous.png"> 
                                        <small>(' . strtolower(t(501, 'Previous')) . ')</small> ' . $previous_brother_title . '</a>';
        }
        if (!empty($next_brother)) {
            $extra_actions[] = '    <a href="?fid=structure&act=edit&id=' . $next_brother . '">
                                        <img height="16" align="absmiddle" width="16" src="img/icons/silk/resultset_next.png"> 
                                        <small>(' . strtolower(t(502, 'Next')) . ')</small> ' . $next_brother_title . '</a>';
        }
    }
    $events->add_actions('structure', array('item' => &$item, 'navibars' => &$navibars), $extra_actions);
    $navibars->add_actions(array(!empty($item->id) ? '<a href="?fid=structure&act=edit&parent=' . $item->parent . '&template=' . $item->template . '"><img height="16" align="absmiddle" width="16" src="img/icons/silk/add.png"> ' . t(38, 'Create') . '</a>' : '', '<a href="?fid=structure&act=0"><img height="16" align="absmiddle" width="16" src="img/icons/silk/sitemap_color.png"> ' . t(61, 'Tree') . '</a>', 'search_form'));
    $navibars->form();
    $navibars->add_tab(t(43, "Main"));
    $navibars->add_tab_content($naviforms->hidden('form-sent', 'true'));
    $navibars->add_tab_content_row(array('<label>ID</label>', '<span>' . (!empty($item->id) ? $item->id : t(52, '(new)')) . '</span>'));
    if (empty($item->id)) {
        $item->parent = $_GET['parent'];
    }
    $navibars->add_tab_content($naviforms->hidden('id', $item->id));
    //$navibars->add_tab_content($naviforms->hidden('parent', $item->parent));
    $hierarchy = structure::hierarchy(0);
    $categories_list = structure::hierarchyList($hierarchy, $item->parent);
    if (empty($categories_list)) {
        $categories_list = '<ul><li value="0">' . t(428, '(no category)') . '</li></ul>';
    }
    $navibars->add_tab_content_row(array('<label>' . t(84, 'Parent') . '</label>', $naviforms->dropdown_tree('parent', $categories_list, $item->parent, 'navigate_parent_category_change')), 'category_tree');
    $layout->add_script('
        function navigate_parent_category_change(id)
        {
            $.ajax(
            {
                url: NAVIGATE_APP + "?fid=structure&act=category_path&id=" + id,
                dataType: "json",
                data: {},
                success: function(data, textStatus, xhr)
                {
                    item_category_path = data;
                }
            });
        }
    ');
    if (empty($item->template) && isset($_GET['template'])) {
        $item->template = $_GET['template'];
    }
    $templates = template::elements('structure');
    $template_select = $naviforms->select_from_object_array('template', $templates, 'id', 'title', $item->template);
    $navibars->add_tab_content_row(array('<label>' . t(79, 'Template') . '</label>', $template_select));
    $navibars->add_tab_content_row(array('<label>' . t(85, 'Date published') . '</label>', $naviforms->datefield('date_published', $item->date_published, true)));
    $navibars->add_tab_content_row(array('<label>' . t(90, 'Date unpublished') . '</label>', $naviforms->datefield('date_unpublish', $item->date_unpublish, true)));
    $navibars->add_tab_content_row(array('<label>' . t(364, 'Access') . '</label>', $naviforms->selectfield('access', array(0 => 0, 1 => 2, 2 => 1, 3 => 3), array(0 => t(254, 'Everybody'), 1 => t(362, 'Not signed in'), 2 => t(361, 'Web users only'), 3 => t(512, 'Selected web user groups')), $item->access, 'navigate_webuser_groups_visibility($(this).val());', false, array(1 => t(363, 'Users who have not yet signed in')))));
    $webuser_groups = webuser_group::all_in_array();
    $navibars->add_tab_content_row(array('<label>' . t(506, "Groups") . '</label>', $naviforms->multiselect('groups', array_keys($webuser_groups), array_values($webuser_groups), $item->groups)), 'webuser-groups-field');
    $layout->add_script('
        function navigate_webuser_groups_visibility(access_value)
        {
            if(access_value==3)
                $("#webuser-groups-field").show();
            else
                $("#webuser-groups-field").hide();
        }

        navigate_webuser_groups_visibility(' . $item->access . ');
    ');
    $navibars->add_tab_content_row(array('<label>' . t(68, 'Status') . '</label>', $naviforms->selectfield('permission', array(0 => 0, 1 => 1, 2 => 2), array(0 => t(69, 'Published'), 1 => t(70, 'Private'), 2 => t(81, 'Hidden')), $item->permission, '', false, array(0 => t(360, 'Visible to everybody'), 1 => t(359, 'Visible only to Navigate CMS users'), 2 => t(358, 'Hidden to everybody')))));
    $navibars->add_tab_content_row(array('<label>' . t(283, 'Shown in menus') . '</label>', $naviforms->checkbox('visible', $item->visible)));
    if ($item->views > 0) {
        $navibars->add_tab_content_row(array('<label>' . t(280, 'Page views') . '</label>', $item->views));
    }
    $navibars->add_tab(t(54, "Text") . ' / ' . t(74, "Paths"));
    $lang_selector = array();
    $lang_selector[] = '<div class="buttonset">';
    $checked = ' checked="checked" ';
    foreach ($website->languages_list as $lang_code) {
        $lang_selector[] = '<input type="radio" id="language_selector_' . $lang_code . '" name="language_selector" value="' . $lang_code . '" ' . $checked . ' />
							<label for="language_selector_' . $lang_code . '"  onclick="navigate_structure_select_language(\'' . $lang_code . '\');">' . language::name_by_code($lang_code) . '</label>';
        $checked = "";
    }
    $lang_selector[] = '</div>';
    $navibars->add_tab_content_row(array('<label>' . t(63, 'Languages') . '</label>', implode("\n", $lang_selector)));
    foreach ($website->languages_list as $lang_code) {
        $navibars->add_tab_content('<div class="language_fields" id="language_fields_' . $lang_code . '" style=" display: none; ">');
        $navibars->add_tab_content_row(array('<label>' . t(67, 'Title') . '</label>', $naviforms->textfield('title-' . $lang_code, @$item->dictionary[$lang_code]['title'])));
        $open_live_site = '';
        if (!empty($item->paths[$lang_code])) {
            $open_live_site = ' <a target="_blank" href="' . $website->absolute_path(true) . $item->paths[$lang_code] . '"><img src="img/icons/silk/world_go.png" align="absmiddle" /></a>';
        }
        $navibars->add_tab_content_row(array('<label>' . t(75, 'Path') . $open_live_site . '</label>', $naviforms->textfield('path-' . $lang_code, @$item->paths[$lang_code], NULL, 'navigate_structure_path_check(this);'), '<span>&nbsp;</span>'));
        /*									
        $navibars->add_tab_content_row(array(	'<label>&nbsp;</label>',
        										'<div class="subcomment"><sup>*</sup> '.t(83, 'Leave blank to disable this item').'</div>',
        									));		
        */
        $navibars->add_tab_content_row(array('<label>' . t(172, 'Action') . '</label>', $naviforms->selectfield('action-type-' . $lang_code, array(0 => 'url', 1 => 'jump-branch', 2 => 'jump-item', 3 => 'do-nothing'), array(0 => t(173, 'Open URL'), 1 => t(322, 'Jump to another branch'), 2 => t(323, 'Jump to an element'), 3 => t(183, 'Do nothing')), $item->dictionary[$lang_code]['action-type'], "navigate_structure_action_change('" . $lang_code . "', this);")));
        // load item title if action was "jump to an element"
        $jump_item_id = '';
        $jump_item_title = '';
        if (!empty($item->dictionary[$lang_code]['action-jump-item'])) {
            $tmp = new Item();
            $tmp->load($item->dictionary[$lang_code]['action-jump-item']);
            $jump_item_title = array($tmp->dictionary[$lang_code]['title']);
            $jump_item_id = array($item->dictionary[$lang_code]['action-jump-item']);
        }
        $navibars->add_tab_content_row(array('<label>' . t(180, 'Item') . ' [' . t(67, 'Title') . ']</label>', $naviforms->selectfield('action-jump-item-' . $lang_code, $jump_item_id, $jump_item_title, $item->dictionary[$lang_code]['action-jump-item'], null, false, null, null, false), '<div class="subcomment"><span class="ui-icon ui-icon-info" style=" float: left; margin-left: -3px; "></span> ' . t(534, "You can only select elements which have their own path (no category embedded elements)") . '</div>'));
        $categories_list = structure::hierarchyList($hierarchy, $item->dictionary[$lang_code]['action-jump-branch'], $lang_code);
        $navibars->add_tab_content_row(array('<label>' . t(325, 'Branch') . '</label>', '<div class="category_tree" id="category_tree_jump_branch_' . $lang_code . '">
				        <img src="img/icons/silk/world.png" align="absmiddle" /> ' . $website->name . '<div class="category_tree_ul">' . $categories_list . '</div>' . '</div>', $naviforms->hidden('action-jump-branch-' . $lang_code, $item->dictionary[$lang_code]['action-jump-branch'])));
        $navibars->add_tab_content_row(array('<label>' . t(324, 'New window') . '</label>', $naviforms->checkbox('action-new-window-' . $lang_code, $item->dictionary[$lang_code]['action-new-window'])));
        $navibars->add_tab_content('</div>');
    }
    $parent = new structure();
    $parent->paths = array();
    if (!empty($item->parent)) {
        $parent->load($item->parent);
    }
    $layout->add_script('
		function navigate_structure_select_language(code)
		{
			$(".language_fields").css("display", "none");
			$("#language_fields_" + code).css("display", "block");
		}
		
		var active_languages = ["' . implode('", "', $website->languages_list) . '"];
		var last_check = [];
		var item_category_path = ' . json_encode($parent->paths) . ';
		
		function navigate_structure_path_generate(el)
		{
			var language = $(el).attr("id").substr(5);
			var surl = "";
			if(item_category_path[language] && item_category_path[language]!="")
				surl = item_category_path[language];
			else
				surl = "/" + language;
			var title = $("#title-"+language).val();
            title = title.replace(/([\'"“”«»?:\\+\\&!¿#\\\\])/g, "");
			title = title.replace(/[.\\s]+/g, navigate["word_separator"]);

			surl += "/" + title;
			$(el).val(surl.toLowerCase());
			navigate_structure_path_check(el);
		}		
		
		function navigate_structure_path_check(el)		
		{
		    var caret_position = null;
            if($(el).is("input") && $(el).is(":focus"))
                caret_position = $(el).caret();

			var path = $(el).val();
			
			if(path=="") return;			
			if(path==last_check[$(el).id]) return;
			if(path.indexOf("http")==0) return; // ignore paths starting with http/https

            path = path.replace(/([\'"“”«»?:\\+\\&!¿#\\\\])/g, "");
			path = path.replace(/[.\\s]+/g, navigate["word_separator"]);

			$(el).val(path);
			
			last_check[$(el).id] = path;
			
			$(el).next().html("<img src=\\"' . NAVIGATE_URL . '/img/loader.gif\\" align=\\"absmiddle\\" />");
			
			$.ajax({
			  url: "' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=' . $_REQUEST['fid'] . '&act=95",
			  dataType: "json",
			  data: "id=' . $item->id . '&path=" + $(el).val(),
			  type: "get",
			  success: function(data, textStatus)
			  {
				  var free = true;

				  if(data && data.length==1)
				  {
					 // same element?
					 if( data[0].object_id != "' . $item->id . '" ||
						 data[0].type != "structure" )
					 {
						free = false; 
					 }
				  }
				  else if(data && data.length > 1)
				  {
					  free = false;
				  }
				  
				  if(free)	free = "<img src=\\"' . NAVIGATE_URL . '/img/icons/silk/tick.png\\" align=\\"absmiddle\\" />";
				  else		free = "<img src=\\"' . NAVIGATE_URL . '/img/icons/silk/cancel.png\\" align=\\"absmiddle\\" />";

                  free += "<img class=\\"erase_path\\" src=\\"" + NAVIGATE_URL + "/img/icons/silk/erase.png\\" align=\\"absmiddle\\" />";
                  $(el).next().find(".erase_path").off();
                  $(el).next().html(free);
                  $(el).next().find(".erase_path").on("click", function()
                  {
                    $(el).focus();
                    $(el).val("");
                  }).css("cursor", "pointer");
			  }
			});

            if($(el).is("input") && $(el).is(":focus"))
            $(el).caret(caret_position)
		}
				
		function navigate_structure_action_change(language, element)
		{			
			$("#action-new-window-" + language).parent().hide();
			$("#action-jump-item-" + language).parent().hide();
			$("#action-jump-branch-" + language).parent().hide();			
			
			switch(jQuery(element).val())
			{
				case "do-nothing":
				
					break;
					
				case "jump-branch":
					$("#action-new-window-" + language).parent().show();
					$("#action-jump-branch-" + language).parent().show();
					
					$("#category_tree_jump_branch_" + language+ " .category_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("changed.jstree", function(e, data) 
					{
                        var i, j, r = [];
                        for(i = 0, j = data.selected.length; i < j; i++) 
                        {
                            var selected_node = data.instance.get_node(data.selected[i]).data.nodeId;
                            $("#action-jump-branch-" + language).val(selected_node);
                        }
                    });                    
					break;
					
				case "jump-item":
					$("#action-new-window-" + language).parent().show();
					$("#action-jump-item-" + language).parent().show();
					break;
					
				case "url":
					$("#action-new-window-" + language).parent().show();
					break;
			}
	
		}
		
		$(window).on("load", function()
		{
			for(al in active_languages)
			{
				navigate_structure_path_check($("#path-" + active_languages[al]));
				
				$("#path-" + active_languages[al]).on("focus", function()
				{
					if($(this).val() == "")
						navigate_structure_path_generate($(this));
				});

                $("#action-jump-item-" + active_languages[al]).select2(
                {
                    placeholder: "' . t(533, "Find element by title") . '",
                    minimumInputLength: 1,
                    ajax: {
                        url: NAVIGATE_APP + "?fid=" + navigate_query_parameter(\'fid\') + "&act=json_find_item",
                        dataType: "json",
                        delay: 100,
                        data: function(params)
                        {
	                        return {
				                title: params.term,
				                lang: $("input[name=\\"language_selector\\"]:checked").val(),
				                nd: new Date().getTime(),
				                page_limit: 30, // page size
				                page: params.page // page number
				            };
                        },
                        processResults: function (data, params)
				        {
				            params.page = params.page || 1;
				            return {
								results: data.items,
								pagination: { more: (params.page * 30) < data.total_count }
							};
				        }
                    },
                    templateSelection: function(row)
					{
						if(row.id)
							return row.text + " <helper style=\'opacity: .5;\'>#" + row.id + "</helper>";
						else
							return row.text;
					},
					escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
                    triggerChange: true,
                    allowClear: true
                });

				navigate_structure_action_change(active_languages[al], $("#action-type-" + active_languages[al]));
			}
		});
				
	');
    $layout->add_script('navigate_structure_select_language("' . $website->languages_list[0] . '")');
    if (!empty($item->template)) {
        $properties_html = navigate_property_layout_form('structure', $item->template, 'structure', $item->id);
        if (!empty($properties_html)) {
            $navibars->add_tab(t(77, "Properties"));
            $navibars->add_tab_content($properties_html);
        }
    }
    if ($item->votes > 0) {
        $navibars->add_tab(t(352, "Votes"));
        $score = $item->score / $item->votes;
        $navibars->add_tab_content_panel('<img src="img/icons/silk/chart_pie.png" align="absmiddle" /> ' . t(337, 'Summary'), array('<div class="navigate-panels-summary ui-corner-all"><h2>' . $item->votes . '</h2><br />' . t(352, 'Votes') . '</div>', '<div class="navigate-panels-summary ui-corner-all""><h2>' . $score . '</h2><br />' . t(353, 'Score') . '</div>', '<div style=" float: left; margin-left: 8px; "><a href="#" class="uibutton" id="items_votes_webuser">' . t(15, 'Users') . '</a></div>', '<div style=" float: right; margin-right: 8px; "><a href="#" class="uibutton" id="items_votes_reset">' . t(354, 'Reset') . '</a></div>', '<div id="items_votes_webuser_window" style=" display: none; width: 600px; height: 350px; "></div>'), 'navigate-panel-web-summary', '385px', '200px');
        $layout->add_script('
			$("#items_votes_reset").bind("click", function()
			{
				$.post("?fid=' . $_REQUEST['fid'] . '&act=votes_reset&id=' . $item->id . '", function(data)
				{
					$("#navigate-panel-web-summary").addClass("ui-state-disabled");
					navigate_notification("' . t(355, 'Votes reset') . '");
				});
			});
			
			$("#items_votes_webuser").bind("click", function()
			{
				$( "#items_votes_webuser_window" ).dialog(
				{
					title: "' . t(357, 'User votes') . '",
					width: 700,
					height: 400,
					modal: true,
					open: function()
					{
						$( "#items_votes_webuser_window" ).html("<table id=\\"items_votes_webuser_grid\\"></table>");
						$( "#items_votes_webuser_window" ).append("<div id=\\"items_votes_webuser_grid_pager\\"></div>");
						
						jQuery("#items_votes_webuser_grid").jqGrid(
						{
						  url: "?fid=' . $_REQUEST['fid'] . '&act=votes_by_webuser&id=' . $item->id . '",
						  editurl: "?fid=' . $_REQUEST['fid'] . '&act=votes_by_webuser&id=' . $item->id . '",
						  datatype: "json",
						  mtype: "GET",
						  pager: "#items_votes_webuser_grid_pager",	
						  colNames:["ID", "' . t(86, 'Date') . '", "' . t(1, 'Username') . '"],
						  colModel:[
							{name:"id", index:"id", width: 75, align: "left", sortable:true, editable:false, hidden: true},
							{name:"date",index:"date", width: 180, align: "center", sortable:true, editable:false},
							{name:"username", index:"username", align: "left", width: 380, sortable:true, editable:false}
							
						  ],
						  scroll: 1,
						  loadonce: false,
						  autowidth: true,
						  forceFit: true,
						  rowNum: 12,
						  rowList: [12],	
						  viewrecords: true,
						  multiselect: true,		  
						  sortname: "date",
						  sortorder: "desc"
						});	
						
						$("#items_votes_webuser_grid").jqGrid(	"navGrid", 
																"#items_votes_webuser_grid_pager", 
																{
																	add: false,
																	edit: false,
																	del: true,
																	search: false
																}
															);
					}
				});
			});				
		');
        $navibars->add_tab_content_panel('<img src="img/icons/silk/chart_line.png" align="absmiddle" /> ' . t(353, 'Score'), array('<div id="navigate-panel-web-score-graph" style=" height: 171px; width: 385px; "></div>'), 'navigate-panel-web-score', '385px', '200px');
        $votes_by_score = webuser_vote::object_votes_by_score('structure', $item->id);
        $gdata = array();
        $colors = array('#0a2f42', '#62bbe8', '#1d8ec7', '#44aee4', '#bbe1f5');
        foreach ($votes_by_score as $vscore) {
            $gdata[] = (object) array('label' => $vscore->value, 'data' => (int) $vscore->votes, 'color' => $colors[$vscore->value % count($colors)]);
        }
        $layout->add_script('
			$(document).ready(function()
			{		
				var gdata = ' . json_encode($gdata) . ';				
			
				$.plot($("#navigate-panel-web-score-graph"), gdata,
				{						
						series: 
						{
							pie: 
							{
								show: true,
								radius: 1,
								tilt: 0.5,
								startAngle: 3/4,
								label: 
								{
									show: true,
									formatter: function(label, series)
									{
										return \'<div style="font-size:12px;text-align:center;padding:2px;color:#fff;"><span style="font-size: 20px; font-weight: bold; ">\'+label+\'</span><br/>\'+Math.round(series.percent)+\'% (\'+series.data[0][1]+\')</div>\';
									},
									background: { opacity: 0.6 }
								},
								stroke: 
								{
									color: "#F2F5F7",
									width: 4
								},
							}
						},
						legend: 
						{
							show: false
						}
				});
		');
        $navibars->add_tab_content_panel('<img src="img/icons/silk/chart_line.png" align="absmiddle" /> ' . t(352, 'Votes') . ' (' . t(356, 'last 90 days') . ')', array('<div id="navigate-panel-web-votes-graph" style=" height: 171px; width: 385px; "></div>'), 'navigate-panel-web-votes', '385px', '200px');
        $votes_by_date = webuser_vote::object_votes_by_date('structure', $item->id, 90);
        $layout->add_script('
								
				var plot = $.plot(
					$("#navigate-panel-web-votes-graph"), 
					[' . json_encode($votes_by_date) . '], 
					{
						series:
						{
							points: { show: true, radius: 3 }
						},
						xaxis: 
						{ 
							mode: "time", 
							tickLength: 5
						},
						yaxis:
						{
							tickDecimals: 0,
							zoomRange: false,
							panRange: false
						},
						grid: 
						{ 
							markings: function (axes) 
							{
								var markings = [];
								var d = new Date(axes.xaxis.min);
								// go to the first Saturday
								d.setUTCDate(d.getUTCDate() - ((d.getUTCDay() + 1) % 7))
								d.setUTCSeconds(0);
								d.setUTCMinutes(0);
								d.setUTCHours(0);
								var i = d.getTime();
								do {
									// when we dont set yaxis, the rectangle automatically
									// extends to infinity upwards and downwards
									markings.push({ xaxis: { from: i, to: i + 2 * 24 * 60 * 60 * 1000 } });
									i += 7 * 24 * 60 * 60 * 1000;
								} while (i < axes.xaxis.max);
						
								return markings;
							},
							markingsColor: "#e7f5fc"								
						},
						zoom: 
						{
							interactive: true
						},
						pan: 
						{
							interactive: true
						}
					});

				});					
		
		');
    }
    $elements = $item->elements();
    if (count($elements) > 0) {
        $ids = array();
        $navibars->add_tab(t(22, "Elements"));
        $table = new naviorderedtable("structure_elements");
        $table->setDblclickCallback("structure_elements_open");
        $table->setHiddenInput('elements-order');
        $table->addHeaderColumn('ID', 24);
        $table->addHeaderColumn(t(486, 'Title'), 500);
        foreach ($elements as $element) {
            $table->addRow($element->id, array(array('content' => $element->id, 'align' => 'left'), array('content' => $element->dictionary[$website->languages_list[0]]['title'], 'align' => 'left')));
            $ids[] = $element->id;
        }
        $navibars->add_tab_content_row(array('<label>' . t(22, 'Elements') . '</label>', '<div>' . $table->generate() . '</div>', '<div class="subcomment">
                    <input type="hidden" name="elements-order" id="elements-order" value="' . implode("#", $ids) . '" />
                    <img src="img/icons/silk/information.png" align="absmiddle" /> ' . t(72, 'Drag any row to assign priorities') . '
                </div>'));
        $layout->add_script('
            function structure_elements_open(element)
            {
                window.location.replace("?fid=items&act=edit&id=" + $(element).attr("id") );
            }
        ');
    }
    $events->trigger('structure', 'edit', array('item' => &$item, 'navibars' => &$navibars, 'naviforms' => &$naviforms));
    return $navibars->generate();
}
示例#9
0
function nvweb_list_parse_conditional($tag, $item, $item_html, $position, $total)
{
    global $current;
    $out = '';
    if ($tag['attributes']['by'] == 'property') {
        if (empty($item)) {
            return '';
        }
        // can't parse values of empty objects
        $property_name = $tag['attributes']['property_id'];
        if (empty($property_name)) {
            $property_name = $tag['attributes']['property_name'];
        }
        if (!method_exists($item, 'property')) {
            return "";
        }
        $property_value = $item->property($property_name);
        $property_definition = $item->property_definition($property_name);
        $condition_value = $tag['attributes']['property_value'];
        if (in_array($property_definition->type, array('image', "file"))) {
            if ($property_value == '0') {
                $property_value = "";
            }
        }
        // process special comparing values
        switch ($property_definition->type) {
            case 'date':
                if ($condition_value == 'today') {
                    $now = getdate(core_time());
                    $condition_value = mktime(0, 0, 0, $now['mon'], $now['mday'], $now['year']);
                } else {
                    if ($condition_value == 'now') {
                        $condition_value = core_time();
                    }
                }
                break;
            case 'boolean':
                if ($property_value == "" && isset($property_definition->dvalue)) {
                    $property_value = $property_definition->dvalue;
                }
                break;
        }
        $condition = false;
        if (isset($tag['attributes']['property_empty'])) {
            // special case: for multilanguage properties check the active language
            if ($property_definition->type == 'text' && is_array($property_value)) {
                $property_value = $property_value[$current['lang']];
            }
            if ($tag['attributes']['property_empty'] == 'true' && empty($property_value) || $tag['attributes']['property_empty'] == 'false' && !empty($property_value)) {
                $condition = true;
            }
        } else {
            switch ($tag['attributes']['property_compare']) {
                case '>':
                case 'gt':
                    $condition = $property_value > $condition_value;
                    break;
                case '<':
                case 'lt':
                    $condition = $property_value < $condition_value;
                    break;
                case '>=':
                case '=>':
                case 'gte':
                    $condition = $property_value >= $condition_value;
                    break;
                case '<=':
                case '=<':
                case 'lte':
                    $condition = $property_value <= $condition_value;
                    break;
                case 'in':
                    $condition_values = explode(",", $condition_value);
                    $condition = in_array($property_value, $condition_values);
                    break;
                case 'nin':
                    $condition_values = explode(",", $condition_value);
                    $condition = !in_array($property_value, $condition_values);
                    break;
                case '!=':
                case 'neq':
                    if (is_numeric($property_value)) {
                        if ($condition_value == 'true' || $condition_value === true) {
                            $condition_value = '1';
                        } else {
                            if ($condition_value == 'false' || $condition_value === false) {
                                $condition_value = '0';
                            }
                        }
                    }
                    $condition = $property_value != $condition_value;
                    break;
                case '=':
                case '==':
                case 'eq':
                default:
                    if (is_numeric($property_value)) {
                        if ($condition_value == 'true' || $condition_value === true) {
                            $condition_value = '1';
                        } else {
                            if ($condition_value == 'false' || $condition_value === false) {
                                $condition_value = '0';
                            }
                        }
                    }
                    $condition = $property_value == $condition_value;
                    break;
            }
        }
        if ($condition) {
            // parse the contents of this condition on this round
            $out = $item_html;
        } else {
            // remove this conditional html code on this round
            $out = '';
        }
    } else {
        if ($tag['attributes']['by'] == 'template' || $tag['attributes']['by'] == 'templates') {
            if (empty($item)) {
                return '';
            }
            // can't parse values of empty objects
            $templates = array();
            if (isset($tag['attributes']['templates'])) {
                $templates = explode(",", $tag['attributes']['templates']);
            } else {
                if (isset($tag['attributes']['template'])) {
                    $templates = array($tag['attributes']['template']);
                }
            }
            if (empty($item->template)) {
                // check if the item is embedded in a category, so we have to get the template from the category, not the item
                if (get_class($item) == 'item' && $item->association == 'category' && $item->embedding == 1) {
                    // assign template from its category
                    $item_category = new structure();
                    $item_category->load($item->category);
                    $item->template = $item_category->template;
                }
            }
            if (in_array($item->template, $templates)) {
                // the template matches the condition, apply
                $out = $item_html;
            } else {
                // remove this conditional html code on this round
                $out = '';
            }
        } else {
            if ($tag['attributes']['by'] == 'position') {
                if (empty($item)) {
                    return '';
                }
                // can't parse values of empty objects
                if (isset($tag['attributes']['each'])) {
                    if ($position % $tag['attributes']['each'] == 0) {
                        // condition applies
                        $out = $item_html;
                    } else {
                        // remove the full nvlist_conditional tag, doesn't apply here
                        $out = '';
                    }
                } else {
                    if (isset($tag['attributes']['range'])) {
                        list($pos_min, $pos_max) = explode('-', $tag['attributes']['range']);
                        if ($position + 1 >= $pos_min && $position + 1 <= $pos_max) {
                            $out = $item_html;
                        } else {
                            $out = '';
                        }
                    } else {
                        if (isset($tag['attributes']['position'])) {
                            switch ($tag['attributes']['position']) {
                                case 'first':
                                    if ($position == 0) {
                                        $out = $item_html;
                                    } else {
                                        $out = '';
                                    }
                                    break;
                                case 'not_first':
                                    if ($position > 0) {
                                        $out = $item_html;
                                    } else {
                                        $out = '';
                                    }
                                    break;
                                case 'last':
                                    if ($position == $total - 1) {
                                        $out = $item_html;
                                    } else {
                                        $out = '';
                                    }
                                    break;
                                case 'not_last':
                                    if ($position != $total - 1) {
                                        $out = $item_html;
                                    } else {
                                        $out = '';
                                    }
                                    break;
                                default:
                                    // position "x"?
                                    if ($tag['attributes']['position'] === '0') {
                                        $tag['attributes']['position'] = 1;
                                    }
                                    if ($position + 1 == $tag['attributes']['position']) {
                                        $out = $item_html;
                                    } else {
                                        $out = '';
                                    }
                                    break;
                            }
                        }
                    }
                }
            } else {
                if ($tag['attributes']['by'] == 'block') {
                    if (empty($item)) {
                        return '';
                    }
                    // can't parse values of empty objects
                    // $item may be a block object or a block group block type
                    if (isset($tag['attributes']['type'])) {
                        if ($tag['attributes']['type'] == $item->type || $tag['attributes']['type'] == $item->id) {
                            $out = $item_html;
                        } else {
                            // no match, discard this conditional
                            $out = '';
                        }
                    }
                    // does the block have a link defined?
                    if (isset($tag['attributes']['linked'])) {
                        $block_has_link = in_array($item->action['action-type'][$current['lang']], array("web", "web-n", "file", "image", "javascript"));
                        if ($tag['attributes']['linked'] == "true" && $block_has_link) {
                            $out = $item_html;
                        } else {
                            if ($tag['attributes']['linked'] == "false" && !$block_has_link) {
                                $out = $item_html;
                            } else {
                                // no match, discard this conditional
                                $out = '';
                            }
                        }
                    }
                } else {
                    if ($tag['attributes']['by'] == 'block_type') {
                        if (empty($item)) {
                            return '';
                        }
                        // can't parse values of empty objects
                        // $item is a block type defined in a block group (to add a title before listing blocks of that kind)
                        if (isset($tag['attributes']['type']) && $item->_object_type == "block_group_block_type") {
                            if ($tag['attributes']['type'] == $item->type || $tag['attributes']['type'] == $item->id) {
                                $out = $item_html;
                            } else {
                                // no match, discard this conditional
                                $out = '';
                            }
                        } else {
                            $out = '';
                        }
                    } else {
                        if ($tag['attributes']['by'] == 'access') {
                            if (empty($item)) {
                                return '';
                            }
                            // can't parse values of empty objects
                            $access = 0;
                            switch ($tag['attributes']['access']) {
                                case 3:
                                case 'webuser_groups':
                                    $access = 3;
                                    break;
                                case 2:
                                case 'not_signed_in':
                                    $access = 2;
                                    break;
                                case 1:
                                case 'signed_in':
                                    $access = 1;
                                    break;
                                case 0:
                                case 'everyone':
                                default:
                                    $access = 0;
                                    break;
                            }
                            if ($item->access == $access) {
                                $out = $item_html;
                            } else {
                                $out = '';
                            }
                        } else {
                            if ($tag['attributes']['by'] == 'gallery') {
                                if (empty($item)) {
                                    return '';
                                }
                                // can't parse values of empty objects
                                if ($tag['attributes']['empty'] == 'true') {
                                    if (empty($item->galleries[0])) {
                                        $out = $item_html;
                                    }
                                } else {
                                    if ($tag['attributes']['empty'] == 'false') {
                                        if (!empty($item->galleries[0])) {
                                            $out = $item_html;
                                        }
                                    }
                                }
                            } else {
                                if ($tag['attributes']['by'] == 'tags') {
                                    if (empty($item)) {
                                        return '';
                                    }
                                    // can't parse values of empty objects
                                    if ($tag['attributes']['empty'] == 'true') {
                                        if (empty($item->dictionary[$current['lang']]['tags'])) {
                                            $out = $item_html;
                                        }
                                    } else {
                                        if ($tag['attributes']['empty'] == 'false') {
                                            if (!empty($item->dictionary[$current['lang']]['tags'])) {
                                                $out = $item_html;
                                            }
                                        }
                                    }
                                } else {
                                    if ($tag['attributes']['by'] == 'structure') {
                                        if (empty($item)) {
                                            return '';
                                        }
                                        // can't parse values of empty objects
                                        if (isset($tag['attributes']['show_in_menus']) && isset($item->visible)) {
                                            if ($item->visible == 1 && in_array($tag['attributes']['show_in_menus'], array(1, true, "true"))) {
                                                $out = $item_html;
                                            } else {
                                                if ($item->visible != 1 && !in_array($tag['attributes']['show_in_menus'], array(1, true, "true"))) {
                                                    $out = $item_html;
                                                } else {
                                                    $out = "";
                                                }
                                            }
                                        } else {
                                            // no match, discard this conditional
                                            $out = '';
                                        }
                                    } else {
                                        if ($tag['attributes']['by'] == 'count') {
                                            // check the number of results found
                                            // note: this is called also WHEN resultset is empty
                                            if ($tag['attributes']['value'] == $total || $tag['attributes']['value'] == "empty" && $total == 0) {
                                                $out = $item_html;
                                            } else {
                                                $out = '';
                                            }
                                        } else {
                                            $out = '';
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return $out;
}
示例#10
0
define('PATH_TPL', 'xml/templates/');
define('PATH_USERS', 'xml/users.xml');
//пути к файлам относительно корня сайта (используются в XML урлах)
define('ABS_PATH_SITE', 'xml/site.xml');
define('ABS_PATH_STRUCT_CLIENT', 'xml/structure.xml');
define('ABS_PATH_DATA_CLIENT', 'xml/data/');
define('ABS_PATH_TPL_CLIENT', 'xml/templates/');
define('ABS_PATH_DATA_AP', 'ap/xml/data/');
define('ABS_PATH_USERS', 'ap/xml/users.xml');
//пути к файлам клиентской части относительно текущей папки
define('PATH_ROOT', '../');
define('PATH_STRUCT_CLIENT', PATH_ROOT . ABS_PATH_STRUCT_CLIENT);
define('PATH_TPL_CLIENT', PATH_ROOT . ABS_PATH_TPL_CLIENT);
try {
    $_site = new site('../xml/site.xml');
    $_struct = new structure('xml/structure.xml', 'xml/data', 'xml/templates');
    $_out = new out();
    $_events = new events('xml/events.xml');
    $_events->addEvent('SectionReady');
    $_events->addEvent('PageReady');
    $_site->setModules(new modules($_site, 'apModules'));
    $modules = $_site->getModules();
    if (!$modules->hasModule('ap')) {
        $modules->move($modules->add('ap'), 1);
    }
    $modules->run();
    $_sec = $_struct->getCurrentSection();
    $_events->happen('SectionReady');
    $_sec->getModules()->run();
    $_out->xmlInclude($_struct);
    $_out->xmlInclude($_site);
function navigate_permissions_structure_selector($ws_id, $ws_name)
{
    global $layout;
    $hierarchy = structure::hierarchy(0, $ws_id);
    $hierarchy_html = structure::hierarchyList($hierarchy, null, null, true);
    $out = '
		<div id="navigate_permissions_structure_selector_website_' . $ws_id . '" data-title="' . t(16, "Structure") . '" style="display: none;">
			<div class="navigate-form-row">
				<label>' . t(16, 'Structure') . '</label>
				<div class="category_tree">
				    <img src="img/icons/silk/world.png" align="absmiddle" /> ' . $ws_name . '<div class="tree_ul">' . $hierarchy_html . '</div>' . '</div>
				<input type="hidden"
				       data-website="' . $ws_id . '"
				       data-permission-name=""
					   id="navigate_permissions_structure_selector_website_' . $ws_id . '_categories"
					   value=""
			    />
			</div>
		</div>
	';
    $layout->add_script('		
		$("#navigate_permissions_structure_selector_website_' . $ws_id . ' .tree_ul").jstree({
            plugins: ["changed", "types", "checkbox"],
            "types" :
            {
                "default":  {   "icon": "img/icons/silk/folder.png"    },
                "leaf":     {   "icon": "img/icons/silk/page_white.png"      }
            },
            "checkbox":
            {
                three_state: false,
                cascade: "undetermined"
            },
            "core":
            {
                dblclick_toggle: false
            }
        })
        .on("dblclick.jstree", function(e)
        {
            e.preventDefault();
            e.stopPropagation();
        
            var li = $(e.target).closest("li");
            $("#navigate_permissions_structure_selector_website_' . $ws_id . ' .tree_ul").jstree("open_node", "#" + li[0].id);
        
            var children_nodes = new Array();
            children_nodes.push(li);
            $(li).find("li").each(function() {
                children_nodes.push("#" + $(this)[0].id);
            });
        
            $("#navigate_permissions_structure_selector_website_' . $ws_id . ' .tree_ul").jstree("select_node", children_nodes);
        
            return false;
        })
        .on("changed.jstree", function(e, data)
        {
            var i, j, r = [];
            var categories = new Array();
            $("#navigate_permissions_structure_selector_website_' . $ws_id . '_categories").val("");       
        
            for(i = 0, j = data.selected.length; i < j; i++)
            {
                var id = data.instance.get_node(data.selected[i]).data.nodeId;
                categories.push(id);
            }
            
            if(categories.length > 0)
                $("#navigate_permissions_structure_selector_website_' . $ws_id . '_categories").val(categories);                                

            var permission_name = $("#navigate_permissions_structure_selector_website_' . $ws_id . '_categories").data("permission-name");
            if(permission_name)
            {
                // update changes into the variable which controls the values of the modified permissions
                navigate_permissions_changes["wid' . $ws_id . '." + permission_name] = categories;
                navigate_permissions_update();

                $("#permissions_list_website_' . $ws_id . '")
                    .find("button[data-permission-name=\'" + permission_name + "\']")
                    .attr("title", categories.length);
            }                
        });
	');
    return $out;
}
示例#12
0
function feeds_form($item)
{
    global $user;
    global $DB;
    global $website;
    global $layout;
    $navibars = new navibars();
    $naviforms = new naviforms();
    $layout->navigate_media_browser();
    // we can use media browser in this function
    if (empty($item->id)) {
        $navibars->title(t(326, 'Feeds') . ' / ' . t(38, 'Create'));
    } else {
        $navibars->title(t(326, 'Feeds') . ' / ' . t(170, 'Edit') . ' [' . $item->id . ']');
    }
    $navibars->add_actions(array('<a href="#" onclick="javascript: navigate_media_browser();"><img height="16" align="absmiddle" width="16" src="img/icons/silk/images.png"> ' . t(36, 'Media') . '</a>'));
    if (empty($item->id)) {
        $navibars->add_actions(array('<a href="#" onclick="navigate_tabform_submit(1);"><img height="16" align="absmiddle" width="16" src="img/icons/silk/accept.png"> ' . t(34, 'Save') . '</a>'));
    } else {
        $navibars->add_actions(array('<a href="#" onclick="navigate_tabform_submit(1);"><img height="16" align="absmiddle" width="16" src="img/icons/silk/accept.png"> ' . t(34, 'Save') . '</a>', '<a href="#" onclick="navigate_delete_dialog();"><img height="16" align="absmiddle" width="16" src="img/icons/silk/cancel.png"> ' . t(35, 'Delete') . '</a>'));
        $delete_html = array();
        $delete_html[] = '<div id="navigate-delete-dialog" class="hidden">' . t(57, 'Do you really want to delete this item?') . '</div>';
        $delete_html[] = '<script language="javascript" type="text/javascript">';
        $delete_html[] = 'function navigate_delete_dialog()';
        $delete_html[] = '{';
        $delete_html[] = '$("#navigate-delete-dialog").removeClass("hidden");';
        $delete_html[] = '$("#navigate-delete-dialog").dialog({
							resizable: true,
							height: 150,
							width: 300,
							modal: true,
							title: "' . t(59, 'Confirmation') . '",
							buttons: {
								"' . t(58, 'Cancel') . '": function() {
									$(this).dialog("close");
								},
								"' . t(35, 'Delete') . '": function() {
									$(this).dialog("close");
									window.location.href = "?fid=' . $_REQUEST['fid'] . '&act=4&id=' . $item->id . '";
								}
							}
						});';
        $delete_html[] = '}';
        $delete_html[] = '</script>';
        $navibars->add_content(implode("\n", $delete_html));
    }
    $navibars->add_actions(array(!empty($item->id) ? '<a href="?fid=feeds&act=2"><img height="16" align="absmiddle" width="16" src="img/icons/silk/add.png"> ' . t(38, 'Create') . '</a>' : '', '<a href="?fid=feeds&act=0"><img height="16" align="absmiddle" width="16" src="img/icons/silk/application_view_list.png"> ' . t(39, 'List') . '</a>', 'search_form'));
    $navibars->form();
    $navibars->add_tab(t(43, "Main"));
    $navibars->add_tab_content($naviforms->hidden('form-sent', 'true'));
    $navibars->add_tab_content($naviforms->hidden('id', $item->id));
    $navibars->add_tab_content_row(array('<label>ID</label>', '<span>' . (!empty($item->id) ? $item->id : t(52, '(new)')) . '</span>'));
    $navibars->add_tab_content_row(array('<label>' . t(331, 'Format') . '</label>', $naviforms->selectfield('format', array(0 => 'RSS2.0', 1 => 'RSS0.91', 2 => 'ATOM', 3 => 'ATOM0.3', 4 => 'OPML', 5 => 'MBOX', 6 => 'HTML'), array(0 => 'RSS 2.0 (' . t(333, 'Recommended') . ')', 1 => 'RSS 0.91', 2 => 'ATOM', 3 => 'ATOM 0.3', 4 => 'OPML', 5 => 'mBox', 6 => 'HTML'), $item->format)));
    $navibars->add_tab_content_row(array('<label>' . t(335, 'Entries') . '</label>', $naviforms->selectfield('entries', array(0 => 10, 1 => 15, 2 => 20, 3 => 25, 4 => 50), array(0 => 10, 1 => 15, 2 => 20, 3 => 25, 4 => 50), $item->entries)));
    $navibars->add_tab_content_row(array('<label>' . t(336, 'Display') . '</label>', $naviforms->selectfield('content', array(0 => 'title', 1 => 'resume', 2 => 'content'), array(0 => t(67, 'Title'), 1 => t(337, 'Summary'), 2 => t(9, 'Content')), $item->content)));
    $navibars->add_tab_content_row(array('<label>' . t(157, 'Image') . '</label>', $naviforms->dropbox('image', $item->image, 'image')));
    $navibars->add_tab_content_row(array('<label>' . t(68, 'Status') . '</label>', $naviforms->selectfield('permission', array(0 => 0, 1 => 1, 2 => 2), array(0 => t(69, 'Published'), 1 => t(70, 'Private'), 2 => t(81, 'Hidden')), $item->permission, '', false, array(0 => t(360, 'Visible to everybody'), 1 => t(359, 'Visible only to Navigate CMS users'), 2 => t(358, 'Hidden to everybody')))));
    $navibars->add_tab_content_row(array('<label>' . t(65, 'Enabled') . '</label>', $naviforms->checkbox('enabled', $item->enabled)));
    $navibars->add_tab_content_row(array('<label>' . t(332, 'Views') . '</label>', intval($item->views)));
    $navibars->add_tab(t(54, "Text") . ' / ' . t(74, "Paths"));
    $lang_selector = array();
    $lang_selector[] = '<div class="buttonset">';
    $checked = ' checked="checked" ';
    foreach ($website->languages_list as $lang_code) {
        $lang_selector[] = '<input type="radio" id="language_selector_' . $lang_code . '" name="language_selector" value="' . $lang_code . '" ' . $checked . ' />
							<label for="language_selector_' . $lang_code . '"  onclick="navigate_feeds_select_language(\'' . $lang_code . '\');">' . language::name_by_code($lang_code) . '</label>';
        $checked = "";
    }
    $lang_selector[] = '</div>';
    $navibars->add_tab_content_row(array('<label>' . t(63, 'Languages') . '</label>', implode("\n", $lang_selector)));
    foreach ($website->languages_list as $lang_code) {
        $navibars->add_tab_content('<div class="language_fields" id="language_fields_' . $lang_code . '" style=" display: none; ">');
        $navibars->add_tab_content_row(array('<label>' . t(67, 'Title') . '</label>', $naviforms->textfield('title-' . $lang_code, @$item->dictionary[$lang_code]['title'])));
        $open_live_site = '';
        if (!empty($item->paths[$lang_code])) {
            $open_live_site = ' <a target="_blank" href="' . $website->absolute_path(true) . $item->paths[$lang_code] . '"><img src="img/icons/silk/world_go.png" align="absmiddle" /></a>';
        }
        $navibars->add_tab_content_row(array('<label>' . t(75, 'Path') . $open_live_site . '</label>', $naviforms->textfield('path-' . $lang_code, @$item->paths[$lang_code], NULL, 'navigate_feeds_path_check(this);'), '<span>&nbsp;</span>'));
        $navibars->add_tab_content_row(array('<div class="subcomment"><span class="ui-icon ui-icon-info" style=" float: left; margin-left: -3px; "></span>
				' . t(83, 'Leave blank to disable this item') . '</div>'));
        $navibars->add_tab_content_row(array('<label>' . t(334, 'Description') . '</label>', $naviforms->textarea('description-' . $lang_code, @$item->dictionary[$lang_code]['description'])));
        $navibars->add_tab_content('</div>');
    }
    $layout->add_script('
		function navigate_feeds_select_language(code)
		{
			$(".language_fields").css("display", "none");
			$("#language_fields_" + code).css("display", "block");			
		}
		
		var active_languages = ["' . implode('", "', $website->languages_list) . '"];
		var last_check = [];
		
		function navigate_feeds_path_generate(el)
		{
			var language = $(el).attr("id").substr(5);
			var surl = "";
			surl = "/" + language;
			var title = $("#title-"+language).val();
            title = title.replace(/([\'"“”«»?:\\+\\&!¿#\\\\])/g, "");            
			title = title.replace(/[.\\s]+/g, navigate["word_separator"]);

			surl += "/" + title;
			$(el).val(surl.toLowerCase());
			navigate_feeds_path_check(el);
		}		
		
		function navigate_feeds_path_check(el)
		{
		    var caret_position = null;
            if($(el).is("input") && $(el).is(":focus"))
                caret_position = $(el).caret();

			var path = $(el).val();
			
			if(path=="") return;			
			if(path==last_check[$(el).id]) return;

			path = path.replace(/([\'"“”«»?:\\+\\&!¿#\\\\])/g, "");
			path = path.replace(/[.\\s]+/g, navigate["word_separator"]);

			$(el).val(path);
			
			last_check[$(el).id] = path;
			
			$(el).next().html("<img src=\\"' . NAVIGATE_URL . '/img/loader.gif\\" align=\\"absmiddle\\" />");
			
			$.ajax({
			  url: "' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=' . $_REQUEST['fid'] . '&act=path_check",
			  dataType: "json",
			  data: "id=' . $item->id . '&path=" + $(el).val(),
			  type: "get",
			  success: function(data, textStatus)
			  {
				  var free = true;

				  if(data && data.length==1)
				  {
					 // same element?
					 if( data[0].object_id != "' . $item->id . '" ||
						 data[0].type != "feed" )
					 {
						free = false; 
					 }
				  }
				  else if(data && data.length > 1)
				  {
					  free = false;
				  }
				  
				  if(free)	free = "<img src=\\"' . NAVIGATE_URL . '/img/icons/silk/tick.png\\" align=\\"absmiddle\\" />";
				  else		free = "<img src=\\"' . NAVIGATE_URL . '/img/icons/silk/cancel.png\\" align=\\"absmiddle\\" />";

                  free += "<img class=\\"erase_path\\" src=\\"" + NAVIGATE_URL + "/img/icons/silk/erase.png\\" align=\\"absmiddle\\" />";
                  $(el).next().find(".erase_path").off();
                  $(el).next().html(free);
                  $(el).next().find(".erase_path").on("click", function()
                  {
                    $(el).focus();
                    $(el).val("");
                  }).css("cursor", "pointer");
			  }
			});

            if($(el).is("input") && $(el).is(":focus"))
            $(el).caret(caret_position)
		}
		
		$(window).bind("load", function()
		{
			for(al in active_languages)
			{
				navigate_feeds_path_check($("#path-" + active_languages[al]));
				
				$("#path-" + active_languages[al]).bind("focus", function()
				{
					if($(this).val() == "")
						navigate_feeds_path_generate($(this));
				});
			}

		});
				
	');
    $layout->add_script('navigate_feeds_select_language("' . $website->languages_list[0] . '")');
    $navibars->add_tab(t(330, "Categories"));
    $hierarchy = structure::hierarchy(0);
    $categories_list = structure::hierarchyList($hierarchy, $item->categories);
    $navibars->add_tab_content_row(array('<label>' . t(330, 'Categories') . '</label>', '<div class="category_tree" id="category-tree-parent"><img src="img/icons/silk/world.png" align="absmiddle" /> ' . $website->name . '<div class="tree_ul">' . $categories_list . '</div>' . '</div>'));
    if (!is_array($item->categories)) {
        $item->categories = array();
    }
    $navibars->add_tab_content($naviforms->hidden('categories', implode(',', $item->categories)));
    $layout->add_script('		
		$("#category-tree-parent .tree_ul").jstree({
            plugins: ["changed", "types", "checkbox"],
            "types" :
            {
                "default":  {   "icon": "img/icons/silk/folder.png"    },
                "leaf":     {   "icon": "img/icons/silk/page_white.png"      }
            },
            "checkbox":
            {
                three_state: false,
                cascade: "undetermined"
            },
            "core":
            {
                dblclick_toggle: false
            }
        })
        .on("dblclick.jstree", function(e)
        {
            e.preventDefault();
            e.stopPropagation();
        
            var li = $(e.target).closest("li");
            $("#category-tree-parent .tree_ul").jstree("open_node", "#" + li[0].id);
        
            var children_nodes = new Array();
            children_nodes.push(li);
            $(li).find("li").each(function() {
                children_nodes.push("#" + $(this)[0].id);
            });
        
            $("#category-tree-parent .tree_ul").jstree("select_node", children_nodes);
        
            return false;
        })
        .on("changed.jstree", function(e, data)
        {
            var i, j, r = [];
            var categories = new Array();
            $("#categories").val("");
        
            for(i = 0, j = data.selected.length; i < j; i++)
            {
                var id = data.instance.get_node(data.selected[i]).data.nodeId;
                categories.push(id);
            }
            if(categories.length > 0)
                $("#categories").val(categories);
        });		
	');
    return $navibars->generate();
}
示例#13
0
    public function navigate_editorfield_link_dialog()
    {
        global $website;
        if (in_array('link_dialog', $this->parts_added)) {
            return;
        }
        array_push($this->parts_added, 'link_dialog');
        $naviforms = new naviforms();
        $html = array();
        $html[] = '<div class="navigate-form-row">';
        $html[] = '<label>' . t(191, 'Source') . '</label>';
        $html[] = $naviforms->buttonset('nv_link_dialog_source', array('structure' => t(16, 'Structure'), 'element' => t(180, 'Item')), 'structure', 'nv_link_dialog_source_change()');
        $html[] = '</div>';
        $hierarchy = structure::hierarchy(0);
        $categories_list = structure::hierarchyList($hierarchy);
        $html[] = '<div class="navigate-form-row hidden">';
        $html[] = '<label>' . t(78, 'Category') . '</label>';
        $html[] = '<div class="category_tree" id="nv_link_dialog_category">
						<img src="img/icons/silk/world.png" align="absmiddle" /> ' . $website->name . '<div class="tree_ul">' . $categories_list . '</div>
					</div>';
        $html[] = '</div>';
        $html[] = '<div class="navigate-form-row hidden">';
        $html[] = '<label>' . t(630, 'Element') . '</label>';
        $html[] = $naviforms->selectfield("nv_link_dialog_element", null, null, null, null, false, null, null, false);
        $html[] = '</div>';
        $html[] = '<div class="navigate-form-row hidden">';
        $html[] = '<label>' . t(75, 'Path') . '</label>';
        $html[] = '<div id="nv_link_dialog_real_path">' . $website->absolute_path(true) . '<span>?</span></div>';
        $html[] = '</div>';
        $html[] = '<div class="navigate-form-row hidden">';
        $html[] = '<label>' . t(631, "Dynamic URL") . '</label>';
        $html[] = '<div id="nv_link_dialog_dynamic_path"><strong>?</strong></div>';
        $html[] = '</div>';
        $html[] = '<div class="navigate-form-row hidden">';
        $html[] = '<label>' . t(632, 'Replace text') . '</label>';
        $html[] = $naviforms->checkbox("nv_link_dialog_replace_text", true);
        $html[] = '<input type="hidden" id="nv_link_dialog_title" value="" />';
        $html[] = '</div>';
        $this->add_content('
			<div id="nv_link_dialog" title="' . t(631, "Dynamic URL") . '" class="hidden">
				' . implode("\n", $html) . '
			</div>
		');
        $this->add_script('		
			function nv_link_dialog_source_change()
			{
				setTimeout(function()
				{			
					var source = $(\'#nv_link_dialog_source_structure:checked,#nv_link_dialog_source_element:checked\').val();
													
					$("#nv_link_dialog_real_path").parent().addClass("hidden");
					$("#nv_link_dialog_dynamic_path").parent().addClass("hidden");
					$("#nv_link_dialog_replace_text").parent().addClass("hidden");
					
					$("#nv_link_dialog_element").parent().addClass("hidden");
					$("#nv_link_dialog_category").parent().addClass("hidden");
					
					if(source == "element")
					{
						$("#nv_link_dialog_element").parent().removeClass("hidden");
					}
					else if(source == "structure")
					{
						$("#nv_link_dialog_category").parent().removeClass("hidden");
					}
				}, 100);
			}
		
		    $("#nv_link_dialog_category .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("changed.jstree", function(e, data) 
            {                               
                if(data.selected.length > 0)
                {				
                    var node = data.instance.get_node(data.selected[0]);
                    var id = node.data.nodeId;
                    var text = $(node.text).text();
                                        
                    $("#nv_link_dialog_dynamic_path strong").html("nv://structure/" + id);
                            
                    $("#nv_link_dialog_dynamic_path").parent().removeClass("hidden");
                    $("#nv_link_dialog_replace_text").parent().removeClass("hidden");
                    $("#nv_link_dialog_title").val(text);
                }
                else
                {
                    $("#nv_link_dialog_real_path").parent().addClass("hidden");
                    $("#nv_link_dialog_dynamic_path").parent().addClass("hidden");
                    $("#nv_link_dialog_replace_text").parent().addClass("hidden");
                    $("#nv_link_dialog_title").val("");
                }		
            });				   

			$("#nv_link_dialog_element").select2(
                {
                    placeholder: "' . t(533, "Find element by title") . '",
                    minimumInputLength: 1,
                    ajax: {
                        url: "' . NAVIGATE_URL . '/' . NAVIGATE_MAIN . '?fid=items&act=json_find_item",
                        dataType: "json",
                        delay: 100,
                        data: function(params)
                        {
	                        return {
				                title: params.term,
				                embedding: 0,
				                nd: new Date().getTime(),
				                page_limit: 30, // page size
				                page: params.page // page number
				            };
                        },
                        processResults: function (data, params)
				        {
				            params.page = params.page || 1;
				            return {
								results: data.items,
								pagination: { more: (params.page * 30) < data.total_count }
							};
				        }
                    },
                    templateSelection: function(row)
					{
						if(row.id)
						{
							$("#nv_link_dialog_real_path span").html(row.path);
							$("#nv_link_dialog_dynamic_path strong").html("nv://element/" + row.id);
							
							$("#nv_link_dialog_real_path").parent().removeClass("hidden");
							$("#nv_link_dialog_dynamic_path").parent().removeClass("hidden");
							$("#nv_link_dialog_replace_text").parent().removeClass("hidden");
							$("#nv_link_dialog_title").val(row.text);
							
							return row.text + " <helper style=\'opacity: .5;\'>#" + row.id + "</helper>";
						}
						else
						{
							$("#nv_link_dialog_real_path").parent().addClass("hidden");
							$("#nv_link_dialog_dynamic_path").parent().addClass("hidden");
							$("#nv_link_dialog_replace_text").parent().addClass("hidden");
							$("#nv_link_dialog_title").val("");
							return row.text;
						}
					},
					escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
                    triggerChange: true,
                    allowClear: true
                });
                
			nv_link_dialog_source_change(); // auto-select structure on load			
		');
    }
示例#14
0
function nvweb_route_parse($route = "")
{
    global $website;
    global $DB;
    global $current;
    global $session;
    global $theme;
    global $events;
    global $dictionary;
    // node route types
    if (substr($route, 0, 5) == 'node/') {
        $node = substr($route, 5);
        $route = 'node';
    }
    switch ($route) {
        case 'object':
            nvweb_object();
            nvweb_clean_exit();
            break;
        case 'nvajax':
            nvweb_ajax();
            nvweb_clean_exit();
            break;
        case 'nvtags':
        case 'nvsearch':
            $current['template'] = 'search';
            break;
        case 'nv.webuser/verify':
            $hash = $_REQUEST['hash'];
            $email = filter_var($_REQUEST['email'], FILTER_VALIDATE_EMAIL);
            if (!empty($hash) && !empty($email)) {
                $ok = webuser::email_verification($email, $hash);
                if ($ok) {
                    $session['nv.webuser/verify:email_confirmed'] = time();
                }
            }
            nvweb_clean_exit(NVWEB_ABSOLUTE . $website->homepage());
            break;
        case 'node':
            if ($node > 0) {
                $current['id'] = $node;
                $DB->query('SELECT * FROM nv_items 
							 WHERE id = ' . protect($current['id']) . '
							   AND website = ' . $website->id);
                $current['object'] = $DB->first();
                // let's count a hit (except admin)
                if ($current['navigate_session'] != 1 && !nvweb_is_bot()) {
                    $DB->execute(' UPDATE nv_items SET views = views + 1 
								   WHERE id = ' . $current['id'] . ' 
									 AND website = ' . $website->id);
                }
                $current['type'] = 'item';
                $current['template'] = $current['object']->template;
                if ($current['navigate_session'] == 1 && !empty($_REQUEST['template'])) {
                    $current['template'] = $_REQUEST['template'];
                }
            }
            break;
        case 'sitemap.xml':
            nvweb_webget_load('sitemap');
            echo nvweb_sitemap(array('mode' => 'xml'));
            nvweb_clean_exit();
            break;
            // redirect to home page of the current website
        // redirect to home page of the current website
        case 'nvweb.home':
        case 'nv.home':
            header('location: ' . NVWEB_ABSOLUTE . $website->homepage());
            nvweb_clean_exit();
            break;
            // webservice endpoint via XML-RPC calls
        // webservice endpoint via XML-RPC calls
        case 'xmlrpc':
            $events->trigger('nvweb', 'xmlrpc', array('route' => '/' . $route));
            // if no extension processes the call, use the integrated XML-RPC parser
            nvweb_xmlrpc();
            nvweb_clean_exit();
            break;
            // empty path
        // empty path
        case '':
        case '/':
        case 'nv.empty':
            if ($website->empty_path_action == 'homepage_noredirect') {
                $route = $website->homepage();
                if (strpos($route, '/') === 0) {
                    $route = substr($route, 1);
                }
            } else {
                $route = "";
                $website->wrong_path_action = $website->empty_path_action;
            }
            // do NOT break this case, continue processing as wrong_path action
            // no special route (or already processed), look for the path on navigate routing table
        // do NOT break this case, continue processing as wrong_path action
        // no special route (or already processed), look for the path on navigate routing table
        default:
            $DB->query('SELECT * FROM nv_paths 
						 WHERE path = ' . protect('/' . $route) . ' 
						   AND website = ' . $website->id . '
						 ORDER BY id DESC');
            $rs = $DB->result();
            if (empty($rs)) {
                // no valid route found
                switch ($website->wrong_path_action) {
                    case 'homepage':
                    case 'homepage_redirect':
                        header('location: ' . NVWEB_ABSOLUTE . $website->homepage());
                        nvweb_clean_exit();
                        break;
                    case 'http_404':
                        header("HTTP/1.0 404 Not Found");
                        nvweb_clean_exit();
                        break;
                    case 'theme_404':
                        $current['template'] = 'not_found';
                        $current['type'] = 'structure';
                        $current['id'] = 0;
                        $current['object'] = new structure();
                        return;
                        break;
                    case 'website_path':
                        $redirect_url = nvweb_template_convert_nv_paths($website->wrong_path_redirect);
                        header('location: ' . $redirect_url);
                        nvweb_clean_exit();
                        break;
                    case 'blank':
                    default:
                        nvweb_clean_exit();
                        break;
                }
            } else {
                // route found!
                // let's count a hit (except admin)
                if ($current['navigate_session'] != 1 && !nvweb_is_bot()) {
                    $DB->execute(' UPDATE nv_paths SET views = views + 1 
								   WHERE id = ' . $rs[0]->id . ' 
								     AND website = ' . $website->id);
                }
                // set the properties found
                // set the default language for this route
                if (!isset($_REQUEST['lang'])) {
                    $current['lang'] = $rs[0]->lang;
                    $session['lang'] = $rs[0]->lang;
                    // force reloading the dictionary
                    $dictionary = nvweb_dictionary_load();
                }
                $current['type'] = $rs[0]->type;
                $current['id'] = $rs[0]->object_id;
                // look for the template associated with this item
                if ($current['type'] == 'structure') {
                    $obj = new structure();
                    $obj->load($current['id']);
                    // check if it is a direct access to a "jump to another branch" path
                    if ($obj->dictionary[$current['lang']]['action-type'] == 'jump-branch') {
                        $current['id'] = $obj->dictionary[$current['lang']]['action-jump-branch'];
                        $obj = new structure();
                        $obj->load($current['id']);
                        header('location: ' . NVWEB_ABSOLUTE . $obj->paths[$current['lang']]);
                        nvweb_clean_exit();
                    } else {
                        if ($obj->dictionary[$current['lang']]['action-type'] == 'jump-item') {
                            $current['id'] = $obj->dictionary[$current['lang']]['action-jump-item'];
                            $obj = new item();
                            $obj->load($current['id']);
                            header('location: ' . NVWEB_ABSOLUTE . $obj->paths[$current['lang']]);
                            nvweb_clean_exit();
                        }
                    }
                    $current['object'] = $obj;
                    $current['category'] = $current['id'];
                    if ($current['navigate_session'] != 1 && !nvweb_is_bot()) {
                        $DB->execute(' UPDATE nv_structure SET views = views + 1 
									    WHERE id = ' . protect($current['id']) . ' 
										  AND website = ' . $website->id);
                    }
                } else {
                    if ($current['type'] == 'item') {
                        $DB->query('SELECT * FROM nv_items 
								 WHERE id = ' . protect($current['id']) . '
								   AND website = ' . $website->id);
                        $current['object'] = $DB->first();
                        // let's count a hit (except admin)
                        if ($current['navigate_session'] != 1 && !nvweb_is_bot()) {
                            $DB->execute(' UPDATE nv_items SET views = views + 1 
									   WHERE id = ' . $current['id'] . ' 
									     AND website = ' . $website->id);
                        }
                    } else {
                        if ($current['type'] == 'feed') {
                            $out = feed::generate_feed($current['id']);
                            if ($current['navigate_session'] != 1 && !nvweb_is_bot()) {
                                $DB->execute(' UPDATE nv_feeds SET views = views + 1
                                           WHERE id = ' . $current['id'] . '
                                             AND website = ' . $website->id);
                            }
                            echo $out;
                            nvweb_clean_exit();
                        } else {
                            // path exists, but the object type is unknown
                            // maybe the path belongs to an extension?
                            $events->trigger('nvweb', 'routes', array('path' => $rs[0]));
                        }
                    }
                }
                $current['template'] = $current['object']->template;
            }
            break;
    }
}
示例#15
0
function themes_sample_content_export_form()
{
    // templates, blocks, files, properties
    global $user;
    global $DB;
    global $website;
    global $layout;
    global $theme;
    $navibars = new navibars();
    $naviforms = new naviforms();
    $navibars->title(t(367, 'Themes') . ' / ' . t(480, 'Export sample content'));
    $layout->navigate_media_browser();
    // we can use media browser in this function
    $navibars->add_actions(array('<a href="#" onclick="javascript: navigate_media_browser();" title="Ctrl+M"><img height="16" align="absmiddle" width="16" src="img/icons/silk/images.png"> ' . t(36, 'Media') . '</a>'));
    $navibars->add_actions(array('<a href="#" onclick="navigate_tabform_submit(0);"><img height="16" align="absmiddle" width="16" src="img/icons/silk/accept.png"> ' . t(34, 'Save') . '</a>'));
    $navibars->form();
    /*
    $navibars->add_tab(t(43, "Main"));
    
    $navibars->add_tab_content_row(array(
        '<label>'.t(67, 'Title').'</label>',
        $naviforms->textfield('theme-title', $website->name)
    ));
    */
    $navibars->add_tab(t(16, "Structure"));
    // select structure points to export
    $hierarchy = structure::hierarchy(0);
    $categories_list = structure::hierarchyList($hierarchy);
    $navibars->add_tab_content_row(array('<label>' . t(330, 'Categories') . '<br /></label>', '<div class="category_tree" id="category-tree-parent">
            <img src="img/icons/silk/world.png" align="absmiddle" /> ' . $website->name . '<div class="tree_ul">' . $categories_list . '</div>' . '</div>', '<label>&nbsp;</label>', '<button id="theme_export_sample_content_select_all_categories">' . t(481, 'Select all') . '</button>'));
    $navibars->add_tab_content($naviforms->hidden('categories', ''));
    $layout->add_script('        
        $("#category-tree-parent .tree_ul").jstree({
            plugins: ["changed", "types", "checkbox"],
            "types" :
            {
                "default":  {   "icon": "img/icons/silk/folder.png"    },
                "leaf":     {   "icon": "img/icons/silk/page_white.png"      }
            },
            "checkbox":
            {
                three_state: false,
                cascade: "undetermined"
            },
            "core":
            {
                dblclick_toggle: false
            }
        })
        .on("dblclick.jstree", function(e)
        {
            e.preventDefault();
            e.stopPropagation();
        
            var li = $(e.target).closest("li");
            $("#category-tree-parent .tree_ul").jstree("open_node", "#" + li[0].id);
        
            var children_nodes = new Array();
            children_nodes.push(li);
            $(li).find("li").each(function() {
                children_nodes.push("#" + $(this)[0].id);
            });
        
            $("#category-tree-parent .tree_ul").jstree("select_node", children_nodes);
        
            return false;
        })
        .on("changed.jstree", function(e, data)
        {        
            var i, j, r = [];
            var categories = new Array();
            $("#categories").val("");       
        
            for(i = 0, j = data.selected.length; i < j; i++)
            {
                var id = data.instance.get_node(data.selected[i]).data.nodeId;
                categories.push(id);
            }
            
            if(categories.length > 0)
                $("#categories").val(categories);                                                                
        });

        $("#theme_export_sample_content_select_all_categories").on("click", function(e)
        {
            e.stopPropagation();
            e.preventDefault();
            $("#category-tree-parent .tree_ul").jstree("select_all");
            return false;
        });
	');
    $navibars->add_tab(t(22, "Elements"));
    // select elements to export
    $navitable_items = new navitable("items_list");
    $navitable_items->setURL('?fid=items&act=1');
    $navitable_items->sortBy('date_modified', 'DESC');
    $navitable_items->setDataIndex('id');
    $navitable_items->max_rows = 9999999;
    $navitable_items->addCol("ID", 'id', "40", "true", "left");
    $navitable_items->addCol(t(67, 'Title'), 'title', "350", "true", "left");
    $navitable_items->addCol(t(309, 'Social'), 'comments', "80", "true", "center");
    $navitable_items->addCol(t(78, 'Category'), 'category', "150", "true", "center");
    $navitable_items->addCol(t(266, 'Author'), 'author_username', "100", "true", "left");
    $navitable_items->addCol(t(85, 'Date published'), 'dates', "100", "true", "center");
    $navitable_items->addCol(t(80, 'Permission'), 'permission', "80", "true", "center");
    $navitable_items->after_select_callback = ' $("#elements").val(navitable_items_list_selected_rows); ';
    $navitable_items->setLoadCallback('
        if(!themes_export_first_select_elements) 
        {
            $("#cb_items_list").trigger("click");
            themes_export_first_select_elements = true; 
        }
    ');
    $navibars->add_tab_content($naviforms->hidden('elements', ''));
    $navibars->add_tab_content($navitable_items->generate());
    $navibars->add_tab(t(544, "Block groups"));
    // select blocks to export
    $navitable_block_groups = new navitable("block_groups_list");
    $navitable_block_groups->setURL('?fid=blocks&act=block_groups_json');
    $navitable_block_groups->sortBy('id', 'DESC');
    $navitable_block_groups->setDataIndex('id');
    $navitable_items->max_rows = 9999999;
    $navitable_block_groups->addCol("ID", 'id', "80", "true", "left");
    $navitable_block_groups->addCol(t(237, 'Code'), 'code', "120", "true", "left");
    $navitable_block_groups->addCol(t(67, 'Title'), 'title', "200", "true", "left");
    $navitable_block_groups->addCol(t(23, 'Blocks'), 'blocks', "80", "true", "left");
    $navitable_block_groups->after_select_callback = ' $("#block_groups").val(navitable_block_groups_list_selected_rows); ';
    $navitable_block_groups->setLoadCallback('
        if(!themes_export_first_select_blockgrp) 
        {
            $("#cb_block_groups_list").trigger("click");
            themes_export_first_select_blockgrp = true; 
        }
    ');
    $navibars->add_tab_content($naviforms->hidden('block_groups', ''));
    $navibars->add_tab_content($navitable_block_groups->generate());
    $navibars->add_tab(t(23, "Blocks"));
    // select blocks to export
    $navitable_blocks = new navitable("blocks_list");
    $navitable_blocks->setURL('?fid=blocks&act=1');
    $navitable_blocks->sortBy('id', 'DESC');
    $navitable_blocks->setDataIndex('id');
    $navitable_items->max_rows = 9999999;
    $navitable_blocks->addCol("ID", 'id', "40", "true", "left");
    $navitable_blocks->addCol(t(160, 'Type'), 'type', "120", "true", "center");
    $navitable_blocks->addCol(t(67, 'Title'), 'title', "400", "true", "left");
    $navitable_blocks->addCol(t(85, 'Date published'), 'dates', "100", "true", "center");
    $navitable_blocks->addCol(t(364, 'Access'), 'access', "40", "true", "center");
    $navitable_blocks->addCol(t(65, 'Enabled'), 'enabled', "40", "true", "center");
    $navitable_blocks->after_select_callback = ' $("#blocks").val(navitable_blocks_list_selected_rows); ';
    $navitable_blocks->setLoadCallback('
        if(!themes_export_first_select_blocks) 
        {
            $("#cb_blocks_list").trigger("click"); 
            themes_export_first_select_blocks = true; 
        }
    ');
    $navibars->add_tab_content($naviforms->hidden('blocks', ''));
    $navibars->add_tab_content($navitable_blocks->generate());
    $navibars->add_tab(t(250, "Comments"));
    // select comments to export
    $navitable_comments = new navitable("comments_list");
    $navitable_comments->setURL('?fid=comments&act=1');
    $navitable_comments->sortBy('date_created', 'desc');
    $navitable_comments->setDataIndex('id');
    $navitable_items->max_rows = 9999999;
    $navitable_comments->addCol("ID", 'id', "80", "true", "left");
    $navitable_comments->addCol(t(180, 'Item'), 'item', "200", "true", "left");
    $navitable_comments->addCol(t(226, 'Date created'), 'date_created', "100", "true", "left");
    $navitable_comments->addCol(t(1, 'User'), 'user', "100", "true", "left");
    $navitable_comments->addCol(t(54, 'Text'), 'message', "200", "true", "left");
    $navitable_comments->addCol(t(68, 'Status'), 'status', "80", "true", "center");
    $navitable_comments->after_select_callback = ' $("#comments").val(navitable_comments_list_selected_rows); ';
    $navitable_comments->setLoadCallback('
        if(!themes_export_first_select_comments) 
        {
            $("#cb_comments_list").trigger("click"); 
            themes_export_first_select_comments = true; 
        }
    ');
    $navibars->add_tab_content($naviforms->hidden('comments', ''));
    $navibars->add_tab_content($navitable_comments->generate());
    $navibars->add_tab(t(89, "Files"));
    $navibars->add_tab_content_row(array('<label>' . t(141, 'Folder') . '</label>', $naviforms->dropbox('folder', 0, 'folder')));
    $navibars->add_tab_content_row('<div class="subcomment"><span class="ui-icon ui-icon-info" style="float: left;"></span> ' . t(482, 'All sample files should be placed in a folder. Navigate CMS will also add files used in contents.') . '</div>');
    // auto-select everything on load
    $layout->add_script('
        themes_export_first_select_elements = false;
        themes_export_first_select_blockgrp = false;
        themes_export_first_select_blocks   = false;
        themes_export_first_select_comments = false;

        $("#theme_export_sample_content_select_all_categories").trigger("click");               
    ');
    return $navibars->generate();
}
示例#16
0
 public function update()
 {
     global $DB;
     global $website;
     global $events;
     global $user;
     if (!is_null($user)) {
         if ($user->permission("items.edit") == 'false' && $this->author != $user->id) {
             throw new Exception(t(610, "Sorry, you are not allowed to execute this function."));
         }
         if (!structure::category_allowed($this->category)) {
             throw new Exception(t(610, "Sorry, you are not allowed to execute this function."));
         }
     }
     $this->date_modified = core_time();
     $groups = '';
     if (is_array($this->groups)) {
         $this->groups = array_unique($this->groups);
         // remove duplicates
         $this->groups = array_filter($this->groups);
         // remove empty
         if (!empty($this->groups)) {
             $groups = 'g' . implode(',g', $this->groups);
         }
     }
     if ($groups == 'g') {
         $groups = '';
     }
     $ok = $DB->execute(' 
         UPDATE nv_items
         SET 
             association	= :association,
             category	=   :category,
             embedding	= 	:embedding,
             template	=   :template,
             date_to_display	=  :date_to_display,
             date_published	=  :date_published,
             date_unpublish	=  :date_unpublish,
             date_modified	=  :date_modified,
             author		=   :author,
             galleries	=  :galleries,
             comments_enabled_to = :comments_enabled_to,
             comments_moderator = :comments_moderator,
             access	 	=  :access,
             groups      =  :groups,
             permission 	=  :permission,
             views 	=  :views,
             votes 	=  :votes,
             score 	=  :score,
             position = :position
         WHERE id = :id
           AND website = :website', array(":association" => $this->association, ":category" => $this->category, ":embedding" => $this->embedding, ":template" => $this->template, ":date_to_display" => value_or_default($this->date_to_display, 0), ":date_published" => value_or_default($this->date_published, 0), ":date_unpublish" => value_or_default($this->date_unpublish, 0), ":date_modified" => $this->date_modified, ":author" => $this->author, ":galleries" => serialize($this->galleries), ":comments_enabled_to" => value_or_default($this->comments_enabled_to, 0), ":comments_moderator" => value_or_default($this->comments_moderator, 0), ":access" => $this->access, ":groups" => $groups, ":permission" => $this->permission, ":views" => $this->views, ":votes" => $this->votes, ":score" => $this->score, ":position" => value_or_default($this->position, 0), ":id" => $this->id, ":website" => $this->website));
     if (!$ok) {
         throw new Exception($DB->get_last_error());
     }
     webdictionary::save_element_strings('item', $this->id, $this->dictionary, $this->website);
     webdictionary_history::save_element_strings('item', $this->id, $this->dictionary, false, $this->website);
     path::saveElementPaths('item', $this->id, $this->paths, $this->website);
     $events->trigger('item', 'save', array('item' => $this));
     return true;
 }
示例#17
0
    $_struct = new structure('xml/structure.xml');
    $_out = new out();
    $_sec = $_struct->getCurrentSection();
    $m = new modules($_site, 'modules');
    $m->run();
    $_sec->getModules()->run();
    $_out->xmlInclude($_struct);
    $_out->xmlInclude($_site->getSiteInfo());
    $_tpl = $_sec->getTemplate();
    //$_out->save('temp.xml');
    echo $_tpl->transform($_out);
} catch (Exception $e) {
    switch ($e->getCode()) {
        case EXCEPTION_404:
            header("HTTP/1.0 404 Not Found");
            $_site = new site('xml/site.xml');
            $_struct = new structure('xml/structure.xml');
            $_out = new out();
            $_out->setMeta('title', '404 Page not found');
            $_sec = $_struct->addSection('error404', '404');
            $_sec->setSelected(true);
            $_out->xmlInclude($_struct);
            $_out->xmlInclude($_site->getSiteInfo());
            $_tpl = new template($_struct->getTemplatePath() . 'default.xsl');
            $_tpl->addTemplate($_struct->getTemplatePath() . '404.xsl');
            echo $_tpl->transform($_out);
            break;
        default:
            echo 'Exception: ' . $e->getMessage();
    }
}