function index($params)
 {
     $tpl = new template("includes/v");
     $tpl->load("configs.html", true, true);
     $tpl->setv("formtitle", "Редактирование настроек");
     $json = new Services_JSON();
     $config = $json->decode(file::load("data/config.ini"));
     $tpl->setv(array("itemnum" => $config->itemnum, "daynum" => $config->daynum, "email" => $config->email, "emailpassword" => $config->emailpassword, "emailserver" => $config->emailserver, "outputdir" => $config->outputdir, "numthumbs" => $config->numthumbs, "logemail" => $config->logemail));
     $tpl->show();
 }
 function proc($params)
 {
     require_once "MailGrabber.php";
     print "<pre>";
     if (str::isempty($params["id"])) {
         die("<b>Ошибка: Фильтр не выбран</b>\n");
     }
     set_time_limit(0);
     $json = new Services_JSON();
     $mailgrabber = new MailGrabber();
     $mailgrabber->run($json->decode(file::load("data/config.ini")), true, $params["id"]);
 }
Пример #3
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();
}
Пример #4
0
             // output content
             header('Connection: close');
             //$image = core_http_request($_REQUEST['image']);
             $image = file_get_contents($_REQUEST['image']);
             file_put_contents($targetDir . '/' . $_REQUEST['id'] . '.pixlr', $image);
             if (file_exists($targetDir . '/' . $_REQUEST['id'] . '.pixlr')) {
                 if (filesize($targetDir . '/' . $_REQUEST['id'] . '.pixlr') != $size) {
                     @unlink($targetDir . '/' . $_REQUEST['id'] . '.pixlr');
                 } else {
                     unlink($targetDir . '/' . $_REQUEST['id']);
                     rename($targetDir . '/' . $_REQUEST['id'] . '.pixlr', $targetDir . '/' . $_REQUEST['id']);
                     // update file info and remove old thumbnails
                     $DB = new database();
                     $DB->connect();
                     $file = new file();
                     $file->load($_REQUEST['id']);
                     $file->refresh();
                     $DB->disconnect();
                     core_terminate();
                 }
             }
         }
     }
     echo false;
     core_terminate();
 } else {
     if ($_REQUEST['engine'] == 'tinymce') {
         $DB = new database();
         $DB->connect();
         $file = file::register_upload($_FILES['file']['tmp_name'], $_FILES['file']['name'], 0, NULL, true);
         if (!empty($file)) {
Пример #5
0
<?php

require_once "prepend.php";
require_once "PagesGenerator.php";
require_once "JSON.php";
$json = new Services_JSON();
PagesGenerator::run($json->decode(file::load("data/config.ini")));
Пример #6
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;
 }
Пример #7
0
 public static function embed($provider, $reference, $extra = "")
 {
     $out = '';
     if (($provider == 'file' || empty($provider)) && is_numeric($reference)) {
         $file = new file();
         $file->load($reference);
         $reference = $file;
     }
     if (is_object($reference)) {
         $vsrc = NVWEB_OBJECT . '?type=file&id=' . $reference->id . '&disposition=inline';
         $out = '
             <video id="video-file-' . $reference->id . '" ' . $extra . ' controls="controls" preload="metadata" poster="">
                 <source src="' . $vsrc . '" type="' . $reference->mime . '" />
                 <p>Error loading video</p>
             </video>
         ';
     } else {
         if ($provider == 'youtube') {
             $out = '<iframe src="https://www.youtube.com/embed/' . $reference . '?feature=oembed&rel=0&modestbranding=1" frameborder="0" allowfullscreen ' . $extra . '></iframe>';
         } else {
             if ($provider == 'vimeo') {
                 $out = '<iframe src="https://player.vimeo.com/video/' . $reference . '?" frameborder="0" allowfullscreen ' . $extra . '></iframe>';
             }
         }
     }
     return $out;
 }
Пример #8
0
function nvweb_gallery_image_caption($image, $gallery)
{
    global $current;
    $image_title = "";
    $image_description = "";
    if (is_array($gallery)) {
        $image_title = $gallery[$image][$current['lang']];
        $image_description = $gallery[$image][$current['lang']];
    }
    if (empty($image_title)) {
        // retrieve title and description from file
        $image_selected_obj = new file();
        $image_selected_obj->load($image);
        if (isset($image_selected_obj->description[$current['lang']])) {
            $image_description = $image_selected_obj->description[$current['lang']];
        }
        if (isset($image_selected_obj->title[$current['lang']])) {
            $image_title = $image_selected_obj->title[$current['lang']];
        }
    }
    return array($image_title, $image_description);
}
 function isNew($msg)
 {
     static $sanswered = "";
     if (strlen($sanswered) == 0) {
         $sanswered = file_exists("data/answered") ? file::load("data/answered") : "";
     }
     return !preg_match("{" . preg_quote($msg->message_id) . "}s", $sanswered);
 }
Пример #10
0
if (empty($_REQUEST['id'])) {
    exit;
}
// create database connection
$DB = new database();
if (!$DB->connect()) {
    exit;
}
if (empty($_SESSION['APP_USER#' . APP_UNIQUE])) {
    exit;
}
$item = new file();
$id = $_REQUEST['id'];
if (!empty($_REQUEST['id'])) {
    if (is_int($id)) {
        $item->load($id);
    } else {
        $item->load($_REQUEST['id']);
    }
}
if (!$item->id) {
    echo 'Error: no item found with id ' . $_REQUEST['id'] . '.';
    session_write_close();
    $DB->disconnect();
    // we don't need the database anymore (we'll see)
    exit;
}
$website = new Website();
if (!empty($_GET['wid'])) {
    $website->load(intval($_GET['wid']));
} else {
Пример #11
0
<?php

require_once "prepend.php";
require_once "MailGrabber.php";
require_once "JSON.php";
set_time_limit(0);
$json = new Services_JSON();
$mailgrabber = new MailGrabber();
$mailgrabber->run($json->decode(file::load("data/config.ini")), true);
Пример #12
0
function nvweb_list_parse_tag($tag, $item, $source = 'item', $item_relative_position, $item_absolute_position, $total)
{
    global $current;
    global $website;
    global $structure;
    global $DB;
    $out = '';
    switch ($tag['attributes']['source']) {
        // special condition, return direct query result values
        case 'query':
            $out = $item->_query->{$tag}['attributes']['value'];
            break;
            // special: return element position in list
        // special: return element position in list
        case 'position':
            $position = $item_relative_position;
            if ($tag['attributes']['absolute'] == 'true') {
                $position = $item_absolute_position;
            }
            switch ($tag['attributes']['type']) {
                case 'alphabetic':
                    $out = number2alphabet($position);
                    break;
                case 'numeric':
                default:
                    $out = $position + 1;
                    // first element is 1, but in list is zero
                    break;
            }
            break;
            // NOTE: the following refers to structure information of an ITEM, useless if the source are categories!
        // NOTE: the following refers to structure information of an ITEM, useless if the source are categories!
        case 'structure':
        case 'category':
            nvweb_menu_load_dictionary();
            // load menu translations if not already done
            nvweb_menu_load_routes();
            // load menu paths if not already done
            switch ($tag['attributes']['value']) {
                case 'title':
                    if ($source == 'structure' || $source == 'category') {
                        $out = $structure['dictionary'][$item->id];
                    } else {
                        $out = $structure['dictionary'][$item->category];
                    }
                    if (!empty($tag['attributes']['length'])) {
                        $out = core_string_cut($out, $tag['attributes']['length'], '&hellip;');
                    }
                    break;
                case 'slug':
                    if ($source == 'structure' || $source == 'category') {
                        $out = $structure['dictionary'][$item->id];
                    } else {
                        $out = $structure['dictionary'][$item->category];
                    }
                    // remove spaces, special chars, etc.
                    $out = core_string_clean($out);
                    $out = slug($out);
                    break;
                case 'property':
                    $id = $item->id;
                    if ($source != 'structure' && $source != 'category') {
                        $id = $item->category;
                    }
                    $nvweb_properties_parameters = array_replace($tag['attributes'], array('mode' => !isset($tag['attributes']['mode']) ? 'structure' : $tag['attributes']['mode'], 'id' => $id, 'property' => !empty($tag['attributes']['property']) ? $tag['attributes']['property'] : $tag['attributes']['name']));
                    $out = nvweb_properties($nvweb_properties_parameters);
                    break;
                case 'url':
                case 'path':
                    if ($source == 'structure' || $source == 'category') {
                        $out = $structure['routes'][$item->id];
                    } else {
                        $out = $structure['routes'][$item->category];
                    }
                    $out = nvweb_prepare_link($out);
                    break;
                case 'id':
                    if ($source == 'structure' || $source == 'category') {
                        $out = $item->id;
                    } else {
                        // source = 'item'?
                        $out = $item->category;
                    }
                    break;
                default:
                    break;
            }
            break;
            // ITEM comments
        // ITEM comments
        case 'comment':
        case 'comments':
            switch ($tag['attributes']['value']) {
                case 'id':
                    $out = $item->id;
                    break;
                case 'avatar':
                    $size = '48';
                    $extra = '';
                    if (!empty($tag['attributes']['size'])) {
                        $size = intval($tag['attributes']['size']);
                    }
                    if (!empty($tag['attributes']['border'])) {
                        $extra .= '&border=' . $tag['attributes']['border'];
                    }
                    if (!empty($item->avatar)) {
                        $out = '<img class="' . $tag['attributes']['class'] . '" src="' . NVWEB_OBJECT . '?type=image' . $extra . '&id=' . $item->avatar . '" width="' . $size . 'px" height="' . $size . 'px"/>';
                    } else {
                        if (!empty($tag['attributes']['default'])) {
                            // the comment creator has not an avatar, but the template wants to show a default one
                            // 3 cases:
                            //  numerical   ->  ID of the avatar image file in Navigate CMS
                            //  absolute path (http://www...)
                            //  relative path (/img/avatar.png) -> path to the avatar file included in the THEME used
                            if (is_numeric($tag['attributes']['default'])) {
                                $out = '<img class="' . $tag['attributes']['class'] . '" src="' . NVWEB_OBJECT . '?type=image' . $extra . '&id=' . $tag['attributes']['default'] . '" width="' . $size . 'px" height="' . $size . 'px"/>';
                            } else {
                                if (strpos($tag['attributes']['default'], 'http://') === 0) {
                                    $out = '<img class="' . $tag['attributes']['class'] . '" src="' . $tag['attributes']['default'] . '" width="' . $size . 'px" height="' . $size . 'px"/>';
                                } else {
                                    if ($tag['attributes']['default'] == 'none') {
                                        $out = '';
                                    } else {
                                        $out = '<img class="' . $tag['attributes']['class'] . '"src="' . NAVIGATE_URL . '/themes/' . $website->theme . '/' . $tag['attributes']['default'] . '" width="' . $size . 'px" height="' . $size . 'px"/>';
                                    }
                                }
                            }
                        } else {
                            $gravatar_hash = "";
                            $gravatar_default = 'blank';
                            if (!empty($tag['attributes']['gravatar_default'])) {
                                $gravatar_default = $tag['attributes']['gravatar_default'];
                            }
                            if (!empty($item->email)) {
                                $gravatar_hash = md5(strtolower(trim($item->email)));
                            } else {
                                if (!empty($item->user)) {
                                    $email = $DB->query_single('email', 'nv_webusers', 'id = ' . protect($item->user));
                                    if (!empty($email)) {
                                        $gravatar_hash = md5(strtolower(trim($item->email)));
                                    }
                                }
                            }
                            if (!empty($gravatar_hash) && $gravatar_default != 'none') {
                                // gravatar real url: https://www.gravatar.com/avatar/
                                // we use libravatar to get more userbase
                                $gravatar_url = 'https://seccdn.libravatar.org/avatar/' . $gravatar_hash . '?s=' . $size . '&d=' . $gravatar_default;
                                $out = '<img class="' . $tag['attributes']['class'] . '" src="' . $gravatar_url . '" width="' . $size . 'px" height="' . $size . 'px"/>';
                            } else {
                                $out = '<img class="' . $tag['attributes']['class'] . '" src="data:image/gif;base64,R0lGODlhAQABAPAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" width="' . $size . 'px" height="' . $size . 'px"/>';
                            }
                        }
                    }
                    if ($tag['attributes']['linked'] == 'true' && !empty($out)) {
                        if (!empty($item->url)) {
                            $comment_link = $item->url;
                        } else {
                            if (!empty($item->user)) {
                                $wu = new webuser();
                                $wu->load($item->user);
                                $comment_link = $wu->social_website;
                            }
                        }
                        if (!empty($comment_link)) {
                            $out = '<a href="' . $comment_link . '" target="_blank">' . $out . '</a>';
                        }
                    }
                    break;
                case 'username':
                    $out = !empty($item->username) ? $item->username : $item->name;
                    if ($tag['attributes']['linked'] == 'true' && !empty($out)) {
                        if (!empty($item->url)) {
                            $comment_link = $item->url;
                        } else {
                            if (!empty($item->user)) {
                                $wu = new webuser();
                                $wu->load($item->user);
                                $comment_link = $wu->social_website;
                            }
                        }
                        if (!empty($comment_link)) {
                            $out = '<a href="' . $comment_link . '" target="_blank">' . $out . '</a>';
                        }
                    }
                    break;
                case 'website':
                    if (!empty($item->url)) {
                        $out = $item->url;
                    } else {
                        if (!empty($item->user)) {
                            $wu = new webuser();
                            $wu->load($item->user);
                            $out = $wu->social_website;
                        }
                    }
                    if (empty($out)) {
                        $out = '#';
                    }
                    break;
                case 'message':
                    if (!empty($tag['attributes']['length'])) {
                        $out = core_string_cut($item->message, $tag['attributes']['length'], '&hellip;');
                    } else {
                        $out = nl2br($item->message);
                    }
                    break;
                case 'date':
                    // Navigate CMS 1.6.6 compatibility
                    if (empty($tag['attributes']['format']) && !empty($tag['attributes']['date_format'])) {
                        $tag['attributes']['format'] = $tag['attributes']['date_format'];
                    }
                    if (!empty($tag['attributes']['format'])) {
                        // custom date format
                        $out = nvweb_content_date_format($tag['attributes']['format'], $item->date_created);
                    } else {
                        $out = date($website->date_format . ' H:i', $item->date_created);
                    }
                    break;
                case 'item_url':
                    $out = nvweb_source_url('item', $item->item, $current['lang']);
                    break;
                case 'item_title':
                    $out = $item->item_title;
                    break;
                case 'reply_to':
                    $out = $item->reply_to;
                    break;
                case 'depth':
                    $c = new comment();
                    $c->load_from_resultset(array($item));
                    $out = $c->depth();
                    break;
                case 'property':
                    $c = new comment();
                    $c->load_from_resultset(array($item));
                    // pass all nvlist tag parameters to properties nvweb, but some attribute/values take preference
                    $nvweb_properties_parameters = array_replace($tag['attributes'], array('mode' => 'comment', 'id' => $c->id, 'template' => $c->element_template(), 'property' => !empty($tag['attributes']['property']) ? $tag['attributes']['property'] : $tag['attributes']['name']));
                    $out = nvweb_properties($nvweb_properties_parameters);
                    break;
            }
            break;
        case 'block':
            switch ($tag['attributes']['value']) {
                case 'id':
                    $out = $item->id;
                    break;
                    // only for blocks in a block group!
                // only for blocks in a block group!
                case 'uid':
                    $out = $item->uid;
                    break;
                case 'block':
                    // generate the full block code
                    if ($item->type == "extension") {
                        if (function_exists('nvweb_' . $item->extension . '_' . $item->id)) {
                            // load extension block property values
                            $item->properties = property::load_properties(NULL, $item->id, "extension_block", NULL, $item->uid);
                            $out = call_user_func('nvweb_' . $item->extension . '_' . $item->id, $item);
                        }
                    } else {
                        $out = nvweb_blocks_render($item->type, $item->trigger, $item->action, NULL, NULL, $tag['attributes']);
                    }
                    break;
                    // not for extension_blocks
                // not for extension_blocks
                case 'title':
                    $out = $item->dictionary[$current['lang']]['title'];
                    if (!empty($tag['attributes']['length'])) {
                        $out = core_string_cut($out, $tag['attributes']['length'], '&hellip;');
                    }
                    break;
                case 'content':
                    if ($item->type == "extension") {
                        if (function_exists('nvweb_' . $item->extension . '_' . $item->id)) {
                            // load extension block property values
                            $item->properties = property::load_properties(NULL, $item->id, "extension_block", NULL, $item->uid);
                            $out = call_user_func('nvweb_' . $item->extension . '_' . $item->id, $item);
                        }
                    } else {
                        $out = nvweb_blocks_render($item->type, $item->trigger, $item->action, 'content', $item, $tag['attributes']);
                    }
                    break;
                    // not for extension_blocks
                // not for extension_blocks
                case 'url':
                case 'path':
                    $out = nvweb_blocks_render_action($item->action, '', $current['lang'], true);
                    if (empty($out)) {
                        $out = '#';
                    } else {
                        $out = nvweb_prepare_link($out);
                    }
                    break;
                    // not for extension_blocks
                // not for extension_blocks
                case 'target':
                    if ($item->action['action-type'][$current['lang']] == 'web-n') {
                        $out = '_blank';
                    } else {
                        $out = '_self';
                    }
                    break;
                    // not for extension_blocks (only for standard blocks and block group blocks)
                // not for extension_blocks (only for standard blocks and block group blocks)
                case 'property':
                    $properties_mode = 'block';
                    if (!is_numeric($item->id)) {
                        $properties_mode = 'block_group_block';
                    }
                    $nvweb_properties_parameters = array_replace($tag['attributes'], array('mode' => !isset($tag['attributes']['mode']) ? $properties_mode : $tag['attributes']['mode'], 'id' => $item->id, 'property' => !empty($tag['attributes']['property']) ? $tag['attributes']['property'] : $tag['attributes']['name'], 'uid' => @$item->uid));
                    $out = nvweb_properties($nvweb_properties_parameters);
                    break;
                    // not for extension_blocks
                // not for extension_blocks
                case 'poll_answers':
                    $out = nvweb_blocks_render_poll($item);
                    break;
                default:
                    break;
            }
            break;
        case 'block_link':
            switch ($tag['attributes']['value']) {
                case 'id':
                    $out = $item->id;
                    break;
                case 'title':
                    $out = $item->title;
                    if (!empty($tag['attributes']['length'])) {
                        $out = core_string_cut($out, $tag['attributes']['length'], '&hellip;');
                    }
                    break;
                case 'url':
                case 'path':
                    $out = $item->link;
                    if (empty($out)) {
                        $out = '#';
                    } else {
                        $out = nvweb_prepare_link($out);
                    }
                    break;
                case 'target':
                    if ($item->new_window == 1) {
                        $out = '_blank';
                    } else {
                        $out = '_self';
                    }
                    break;
                case 'icon':
                    $out = @$item->icon;
                    break;
                default:
                    break;
            }
            break;
        case 'block_type':
            switch ($tag['attributes']['value']) {
                case 'title':
                    $title_obj = json_decode($item->title, true);
                    if (empty($title_obj)) {
                        // not json
                        $out = $item->title;
                    } else {
                        $out = $title_obj[$current['lang']];
                    }
                    break;
            }
            break;
        case 'gallery':
            switch ($tag['attributes']['value']) {
                case 'url':
                case 'path':
                    $out = NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $item['file'] . '&amp;disposition=inline';
                    break;
                case 'thumbnail':
                case 'thumbnail_url':
                    $thumbnail_url = NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $item['file'] . '&amp;disposition=inline&amp;width=' . $tag['attributes']['width'] . '&amp;height=' . $tag['attributes']['height'] . '&amp;border=' . $tag['attributes']['border'];
                    if ($tag['attributes']['value'] == 'thumbnail_url' || @$tag['attributes']['return'] == 'url') {
                        $out = $thumbnail_url;
                    } else {
                        $out = '<img src="' . $thumbnail_url . '" alt="' . $item[$current['lang']] . '" title="' . $item[$current['lang']] . '" />';
                    }
                    break;
                case 'title':
                    $f = new file();
                    $f->load($item['file']);
                    $out = $f->title[$current['lang']];
                    break;
                case 'alt':
                case 'description':
                    $f = new file();
                    $f->load($item['file']);
                    $out = $f->description[$current['lang']];
                    break;
                default:
                    $out = '<a href="' . NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $item['file'] . '&amp;disposition=inline">
                                <img src="' . NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $item['file'] . '&amp;disposition=inline&amp;width=' . $tag['attributes']['width'] . '&amp;height=' . $tag['attributes']['height'] . '&amp;border=' . $tag['attributes']['border'] . '"
									 alt="' . $item[$current['lang']] . '" title="' . $item[$current['lang']] . '" />
                            </a>';
                    break;
            }
            break;
        case 'item':
            // useful also for source="structure" (but some are nonsense: title, comments, etc)
        // useful also for source="structure" (but some are nonsense: title, comments, etc)
        default:
            switch ($tag['attributes']['value']) {
                case 'id':
                    $out = $item->id;
                    break;
                case 'slug':
                    $lang = $current['lang'];
                    if (!empty($tag['attributes']['lang'])) {
                        $lang = $tag['attributes']['lang'];
                    }
                    $out = $item->dictionary[$lang]['title'];
                    // remove spaces, special chars, etc.
                    $out = core_string_clean($out);
                    $out = slug($out);
                    break;
                case 'title':
                    $lang = $current['lang'];
                    if (!empty($tag['attributes']['lang'])) {
                        $lang = $tag['attributes']['lang'];
                    }
                    $out = $item->dictionary[$lang]['title'];
                    if (!empty($tag['attributes']['length'])) {
                        $out = core_string_cut($out, $tag['attributes']['length'], '&hellip;', $tag['attributes']['length']);
                    }
                    break;
                case 'author':
                    if (!empty($item->author)) {
                        $nu = new user();
                        $nu->load($item->author);
                        $out = $nu->username;
                        unset($nu);
                    }
                    if (empty($out)) {
                        $out = $website->name;
                    }
                    break;
                case 'date':
                case 'date_post':
                    if (!empty($tag['attributes']['format'])) {
                        // custom date format
                        $out = nvweb_content_date_format($tag['attributes']['format'], $item->date_to_display);
                    } else {
                        $out = date($website->date_format, $item->date_to_display);
                    }
                    break;
                case 'content':
                case 'section':
                    if ($source == 'structure' && $tag['attributes']['source'] == 'item') {
                        $items = nvweb_content_items($item->id, true, 1, false, 'priority');
                        // we force finding the first non-embedded item ordered by priority
                        if (empty($items)) {
                            $items = nvweb_content_items($item->id, true, 1, true, 'priority');
                        }
                        // find the first embedded item ordered by priority
                        $item = $items[0];
                    }
                    $section = $tag['attributes']['section'];
                    if (empty($section)) {
                        $section = 'main';
                    }
                    $out = $item->dictionary[$current['lang']]['section-' . $section];
                    if (!empty($tag['attributes']['length'])) {
                        $allowed_tags = '';
                        if (!empty($tag['attributes']['allowed_tags'])) {
                            $allowed_tags = explode(',', $tag['attributes']['allowed_tags']);
                        }
                        $out = core_string_cut($out, $tag['attributes']['length'], '&hellip;', $allowed_tags);
                    }
                    break;
                case 'comments':
                    $out = nvweb_content_comments_count($item->id);
                    break;
                case 'gallery':
                    $params = array('item' => $item->id);
                    $params = array_merge($params, $tag['attributes']);
                    $out = nvweb_gallery($params);
                    break;
                case 'image':
                case 'photo':
                    $photo = @array_shift(array_keys($item->galleries[0]));
                    if (empty($photo)) {
                        $out = NVWEB_OBJECT . '?type=transparent';
                    } else {
                        $out = NVWEB_OBJECT . '?wid=' . $website->id . '&id=' . $photo . '&amp;disposition=inline&amp;width=' . $tag['attributes']['width'] . '&amp;height=' . $tag['attributes']['height'] . '&amp;border=' . $tag['attributes']['border'];
                    }
                    break;
                case 'url':
                case 'path':
                    // rss -> full url
                    // item -> relative url
                    // embedded item -> category url
                    if ($item->embedding == 1 && $item->association == 'category') {
                        nvweb_menu_load_routes();
                        // load menu paths if not already done
                        $out = nvweb_prepare_link($structure['routes'][$item->category]);
                    } else {
                        $path = $item->paths[$current['lang']];
                        if (empty($path)) {
                            $path = '/node/' . $item->id;
                        }
                        $out = nvweb_prepare_link($path);
                    }
                    break;
                case 'tags':
                    // pass all nvlist tag parameters to the content nvweb, but some attribute/values take preference
                    $nvweb_parameters = array_replace($tag['attributes'], array('mode' => 'tags', 'id' => $item->id));
                    $out = nvweb_content($nvweb_parameters);
                    break;
                case 'score':
                    $out = nvweb_votes_calc($item, $tag['attributes']['round'], $tag['attributes']['half'], $tag['attributes']['min'], $tag['attributes']['max']);
                    break;
                case 'votes':
                    $out = intval($item->votes);
                    break;
                case 'views':
                    $out = intval($item->views);
                    break;
                case 'property':
                    if ($source == 'structure' && $tag['attributes']['source'] == 'item') {
                        $items = nvweb_content_items($item->id, true, 1, false, 'priority');
                        // we force finding the first non-embedded item ordered by priority
                        if (empty($items)) {
                            $items = nvweb_content_items($item->id, true, 1, true, 'priority');
                        }
                        // find the first embedded item ordered by priority
                        $item = $items[0];
                        $source = "item";
                    }
                    // pass all nvlist tag parameters to properties nvweb, but some attribute/values take preference
                    $nvweb_properties_parameters = array_replace($tag['attributes'], array('mode' => $source == 'structure' || $source == 'category' ? 'structure' : 'item', 'id' => $item->id, 'template' => $item->template, 'property' => !empty($tag['attributes']['property']) ? $tag['attributes']['property'] : $tag['attributes']['name']));
                    $out = nvweb_properties($nvweb_properties_parameters);
                    break;
                default:
                    // maybe a special tag not related to a source? (unimplemented)
            }
            break;
    }
    return $out;
}
Пример #13
0
function nvweb_properties_render($property, $vars)
{
    global $website;
    global $current;
    global $DB;
    global $session;
    global $theme;
    global $structure;
    $out = '';
    setlocale(LC_ALL, $website->languages[$session['lang']]['system_locale']);
    // if this property is null (no value assigned (null), (empty) is a value!)
    // get the default value
    if (!isset($property->value)) {
        $property->value = $property->dvalue;
    }
    // check multilanguage properties, where the value can be saved in a language but may be (null) in another language
    if (in_array($property->type, array("text", "textarea", "rich_textarea", "link")) || $property->multilanguage == 'true') {
        // cast variable as array
        if (is_object($property->value)) {
            $property->value = (array) $property->value;
        }
        if (!isset($property->value) || !isset($property->value[$current['lang']])) {
            if (isset($property->dvalue->{$current['lang']})) {
                $property->value[$current['lang']] = $property->dvalue->{$current['lang']};
            } else {
                if (!is_array($property->value)) {
                    $property->value = array();
                }
                $property->value[$current['lang']] = $property->dvalue;
            }
        }
    }
    switch ($property->type) {
        case 'value':
            $out = $property->value;
            break;
        case 'decimal':
            $out = $property->value;
            if (isset($vars['precision'])) {
                $out = number_format($property->value, $vars['precision']);
            }
            break;
        case 'boolean':
            $out = $property->value;
            break;
        case 'option':
            $options = mb_unserialize($property->options);
            $options = (array) $options;
            switch (@$vars['return']) {
                case 'value':
                    $out = $property->value;
                    break;
                default:
                    $out = $theme->t($options[$property->value]);
            }
            break;
        case 'moption':
            $options = mb_unserialize($property->options);
            $selected = explode(",", $property->value);
            switch (@$vars['return']) {
                case 'value':
                case 'values':
                    $out = $property->value;
                    break;
                default:
                    $buffer = array();
                    foreach ($selected as $seloption) {
                        $buffer[] = '<span>' . $theme->t($options[$seloption]) . '</span>';
                    }
                    $out .= implode(', ', $buffer);
            }
            break;
        case 'text':
            $out = htmlspecialchars($property->value[$current['lang']]);
            break;
        case 'textarea':
            $out = nl2br(htmlspecialchars($property->value[$current['lang']]));
            break;
        case 'rich_textarea':
            $out = $property->value[$current['lang']];
            break;
        case 'source_code':
            if (@$property->multilanguage == 'true' || $property->multilanguage == '1') {
                $out = $property->value[$current['lang']];
            } else {
                $out = $property->value;
            }
            break;
        case 'date':
            if (!empty($vars['format'])) {
                $out = Encoding::toUTF8(strftime($vars['format'], $property->value));
            } else {
                $out = date($website->date_format, $property->value);
            }
            break;
        case 'datetime':
            if (!empty($vars['format'])) {
                $out = Encoding::toUTF8(strftime($vars['format'], $property->value));
            } else {
                $out = date($website->date_format . ' H:i', $property->value);
            }
            break;
        case 'link':
            // split title and link
            $link = explode('##', $property->value[$current['lang']]);
            if (is_array($link)) {
                $target = @$link[2];
                $title = @$link[1];
                $link = $link[0];
                if (empty($title)) {
                    $title = $link;
                }
            } else {
                $title = $property->value[$current['lang']];
                $link = $property->value[$current['lang']];
                $target = '_self';
            }
            if (strpos($link, '://') === false) {
                $link = $website->absolute_path() . $link;
            }
            if ($vars['link'] === 'false') {
                $out = $link;
            } else {
                if (isset($vars['return'])) {
                    if ($vars['return'] == 'title') {
                        $out = $title;
                    } else {
                        if ($vars['return'] == 'link' || $vars['return'] == 'url') {
                            $out = $link;
                        } else {
                            if ($vars['return'] == 'target') {
                                $out = $target;
                            }
                        }
                    }
                } else {
                    $out = '<a href="' . $link . '" target="' . $target . '">' . $title . '</a>';
                }
            }
            break;
        case 'image':
            $add = '';
            $extra = '';
            if (@$property->multilanguage == 'true' || $property->multilanguage == '1') {
                $image_id = $property->value[$session['lang']];
            } else {
                $image_id = $property->value;
            }
            if (isset($vars['width'])) {
                $add .= ' width="' . $vars['width'] . '" ';
                $extra .= '&width=' . $vars['width'];
            }
            if (isset($vars['height'])) {
                $add .= ' height="' . $vars['height'] . '" ';
                $extra .= '&height=' . $vars['height'];
            }
            if (isset($vars['border'])) {
                $extra .= '&border=' . $vars['border'];
            }
            if (isset($vars['quality'])) {
                $extra .= '&quality=' . $vars['quality'];
            }
            $img_url = NVWEB_OBJECT . '?type=image&id=' . $image_id . $extra;
            if (empty($image_id)) {
                $out = '';
            } else {
                if ($vars['return'] == 'url') {
                    $out = $img_url;
                } else {
                    // retrieve additional info (title/alt), if available
                    if (is_numeric($image_id)) {
                        $f = new file();
                        $f->load($image_id);
                        $ftitle = $f->title[$current['lang']];
                        $falt = $f->description[$current['lang']];
                        if (!empty($ftitle)) {
                            $add .= ' title="' . $ftitle . '" ';
                        }
                        if (!empty($falt)) {
                            $add .= ' alt="' . $falt . '" ';
                        }
                    }
                    $out = '<img class="' . $vars['class'] . '" src="' . $img_url . '" ' . $add . ' />';
                }
            }
            break;
        case 'file':
            if (!empty($property->value)) {
                $file = $DB->query_single('name', 'nv_files', ' id = ' . protect($property->value) . ' AND website = ' . $website->id);
                if ($vars['return'] == 'url' || $vars['return'] == 'url-download') {
                    $out = NVWEB_OBJECT . '?type=file&id=' . $property->value . '&disposition=attachment';
                } else {
                    if ($vars['return'] == 'url-inline') {
                        $out = NVWEB_OBJECT . '?type=file&id=' . $property->value . '&disposition=inline';
                    } else {
                        $out = '<a href="' . NVWEB_OBJECT . '?type=file&id=' . $property->value . '&disposition=attachment">' . $file . '</a>';
                    }
                }
            }
            break;
        case 'comment':
            $out = $property->value;
            break;
        case 'coordinates':
            $coordinates = explode('#', $property->value);
            $out = implode(',', $coordinates);
            break;
        case 'rating':
            // half stars are always enabled (ratings fixed to 0..10)
            $out = $property->value;
            // we want nearest integer down
            if ($vars['option'] == 'floor') {
                $out = floor($out / 2);
            }
            break;
        case 'color':
            $out = $property->value;
            break;
        case 'video':
            // value may be a numeric file ID or a provider#id structure, f.e. youtube#3MteSlpxCpo
            // compatible providers: file,youtube,vimeo
            if (@$property->multilanguage == 'true' || $property->multilanguage == '1') {
                $video_id = $property->value[$session['lang']];
            } else {
                $video_id = $property->value;
            }
            $provider = '';
            $reference = '';
            $add = '';
            if (isset($vars['width'])) {
                $add .= ' width="' . $vars['width'] . '" ';
            }
            if (isset($vars['height'])) {
                $add .= ' height="' . $vars['height'] . '" ';
            }
            $url_add = '&type=image';
            if (isset($vars['width'])) {
                $url_add .= '&width=' . $vars['width'] . '';
            }
            if (isset($vars['height'])) {
                $url_add .= '&height=' . $vars['height'] . '';
            }
            if (isset($vars['border'])) {
                $url_add .= '&border=' . $vars['border'] . '';
            }
            if (strpos($video_id, '#') !== false) {
                list($provider, $reference) = explode("#", $video_id);
            }
            if ($provider == 'file') {
                $video_id = $reference;
            }
            $file = new file();
            if (is_numeric($video_id)) {
                $file->load($video_id);
                $embed = file::embed('file', $file, $add);
            } else {
                if ($provider == 'youtube') {
                    $embed = file::embed('youtube', $reference, $add);
                    if (!empty($vars['part']) || $vars['part'] != 'embed') {
                        $file->load_from_youtube($reference);
                    }
                } else {
                    if ($provider == 'vimeo') {
                        $embed = file::embed('vimeo', $reference, $add);
                        if (!empty($vars['part']) || $vars['part'] != 'embed') {
                            $file->load_from_vimeo($reference);
                        }
                    }
                }
            }
            switch (@$vars['return']) {
                case 'title':
                    $out = $file->title;
                    break;
                case 'mime':
                    $out = $file->mime;
                    break;
                case 'author':
                    if (is_numeric($file->uploaded_by)) {
                        $out = $website->name;
                    } else {
                        $out = $file->uploaded_by;
                    }
                    break;
                case 'path':
                case 'url':
                    $out = $file->extra['link'];
                    break;
                case 'thumbnail_url':
                    $out = file::file_url($file->extra['thumbnail_cache']) . $url_add;
                    break;
                case 'thumbnail':
                    $out = '<img src="' . file::file_url($file->extra['thumbnail_cache']) . $url_add . '" class="' . $vars['class'] . '" ' . $add . ' />';
                    break;
                case 'reference':
                    $out = $reference;
                    break;
                case 'provider':
                    $out = $provider;
                    break;
                case 'embed':
                default:
                    $out = $embed;
            }
            break;
        case 'article':
            // TO DO
            break;
        case 'category':
            $return = @$vars['return'];
            switch ($return) {
                case 'title':
                case 'name':
                    nvweb_menu_load_dictionary();
                    $out = $structure['dictionary'][$property->value];
                    break;
                case 'url':
                case 'link':
                    $out = nvweb_source_url('structure', $property->value);
                    break;
                default:
                    $out = $property->value;
            }
            break;
        case 'categories':
            $return = @$vars['return'];
            $value = explode(",", $property->value);
            $position = intval(@vars['position']) + 0;
            switch ($return) {
                case 'title':
                case 'name':
                    nvweb_menu_load_dictionary();
                    $out = $structure['dictionary'][$value[$position]];
                    break;
                case 'url':
                case 'link':
                    $out = nvweb_source_url('structure', $value[$position]);
                    break;
                default:
                    $out = $property->value;
            }
            break;
        case 'country':
            $return = @$vars['return'];
            switch ($return) {
                case 'name':
                    $countries = property::countries();
                    $out = $countries[$property->value];
                    break;
                case 'id':
                case 'code':
                default:
                    $out = $property->value;
                    break;
            }
            break;
        case 'elements':
            $out = $property->value;
            break;
        case 'element':
        case 'item':
            // deprecated
            $return = @$vars['return'];
            switch ($return) {
                case 'title':
                    $item = new item();
                    $item->load($property->value);
                    $out = $item->dictionary[$current['lang']]['title'];
                    break;
                case 'url':
                case 'path':
                    $out = nvweb_source_url('item', $property->value, $current['lang']);
                    break;
                case 'section':
                    $item = new item();
                    $item->load($property->value);
                    $out = $item->dictionary[$current['lang']]['section-' . $vars['section']];
                    break;
                case 'property':
                    $params = array();
                    foreach ($vars as $attr_name => $attr_value) {
                        if (strpos($attr_name, 'element-property-') === 0) {
                            $attr_name = str_replace('element-property-', '', $attr_name);
                            $params[$attr_name] = $attr_value;
                        } else {
                            if ($attr_name == 'element-property') {
                                $params['property'] = $attr_value;
                            }
                        }
                    }
                    //  default parameters
                    $params['mode'] = 'item';
                    $params['id'] = $property->value;
                    $out = nvweb_properties($params);
                    break;
                case 'id':
                default:
                    $out = $property->value;
                    break;
            }
            break;
        default:
    }
    return $out;
}
Пример #14
0
    public function dropbox($name, $value = 0, $media = "", $disabled = false, $default_value = null, $options = array(), $website_id = null)
    {
        global $layout;
        global $website;
        global $theme;
        if (empty($website_id)) {
            $website_id = $website->id;
        }
        $out = array();
        $out[] = '<div id="' . $name . '-droppable-wrapper" class="navigate-droppable-wrapper">';
        $out[] = '<input type="hidden" id="' . $name . '" name="' . $name . '" value="' . $value . '" />';
        $out[] = '<div id="' . $name . '-droppable" class="navigate-droppable ui-corner-all" data-media="' . $media . '">';
        if (!empty($value)) {
            if ($media == 'image') {
                $f = new file();
                $f->load($value);
                $out[] = '<img title="' . $f->name . '" src="' . NAVIGATE_DOWNLOAD . '?wid=' . $website_id . '&id=' . $f->id . '&amp;disposition=inline&amp;width=75&amp;height=75" />';
            } else {
                if ($media == 'video') {
                    $layout->add_script('
                    $(window).load(function() { navigate_dropbox_load_video("' . $name . '", "' . $value . '"); });
                ');
                    $out[] = '<figure class="navigatecms_loader"></figure>';
                } else {
                    $f = new file();
                    $f->load($value);
                    $out[] = '<img title="' . $f->name . '" src="' . navibrowse::mimeIcon($f->mime, $f->type) . '" width="50" height="50" /><br />' . $f->name;
                }
            }
        } else {
            $out[] = '	<img src="img/icons/misc/dropbox.png" vspace="18" />';
        }
        $out[] = '</div>';
        // set parent row as overflow:visible to let the whole contextmenu appear
        $layout->add_script('
            $(".navigate-droppable-wrapper").parent().css("overflow", "visible");
        ');
        $contextmenu = false;
        if (!$disabled) {
            $out[] = '<div class="navigate-droppable-cancel"><img src="img/icons/silk/cancel.png" /></div>';
            if ($media == 'image') {
                if ($options == 'a:0:{}') {
                    $options = array();
                }
                if (empty($options) && !empty($default_value)) {
                    $options = array($default_value => t(199, "Default value"));
                } else {
                    $options = (array) $options;
                }
                if (!empty($options)) {
                    $out[] = '
                        <div class="navigate-droppable-create">
                            <img src="img/icons/silk/add.png" />
                        </div>
                    ';
                    // "create" context menu actions (image picker)
                    $ws = new website();
                    if ($website_id == $website->id) {
                        $ws = $website;
                    } else {
                        $ws->load($website_id);
                    }
                    $ws_theme = new theme();
                    if ($website_id == $website->id) {
                        $ws_theme = $theme;
                    } else {
                        $ws_theme->load($ws->theme);
                    }
                    $layout->add_content('
                        <ul id="' . $name . '-image_picker" class="navigate-image-picker navi-ui-widget-shadow">
                            ' . implode("\n", array_map(function ($k, $v) use($website_id, $ws_theme) {
                        if (!empty($ws_theme)) {
                            $v = $ws_theme->t($v);
                        }
                        return '
                                        <li data-value="' . $k . '" data-src="' . NAVIGATE_DOWNLOAD . '?wid=' . $website_id . '&id=' . $k . '&amp;disposition=inline&amp;width=75&amp;height=75">
                                            <a href="#">
                                                <img title="' . $v . '" src="' . NAVIGATE_DOWNLOAD . '?wid=' . $website_id . '&id=' . $k . '&amp;disposition=inline&amp;width=48&amp;height=48" />
                                                <span>' . $v . '</span>
                                            </a>
                                        </li>
                                    ';
                    }, array_keys($options), array_values($options))) . '
                        </ul>
                    ');
                    $layout->add_script('
                        $("#' . $name . '-droppable").parent().find(".navigate-droppable-create").on(
                        "click",
                        function(ev)
				        {
                            navigate_hide_context_menus();
                            setTimeout(function()
                            {
                                $("#' . $name . '-image_picker").menu();
                                $("#' . $name . '-image_picker").css({left: ev.pageX, top: ev.pageY});
                                $("#' . $name . '-image_picker").show();
                                
                                if($("#' . $name . '-image_picker").position().top + $("#' . $name . '-image_picker").height() > $(window).height())                    
                                    $("#' . $name . '-image_picker").css("top", $(window).height() - $("#' . $name . '-image_picker").height() - 8);

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

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

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

                            menu_el_clone.menu();

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

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

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

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

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

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

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

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

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

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

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

                        menu_el.menu();

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

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

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

						$("#' . $name . '-droppable").parent().find(".navigate-droppable-cancel").show();
					    $("#' . $name . '-droppable").parent().find(".navigate-droppable-create").hide();
                        $("#' . $name . '-droppable-info").find(".navigate-droppable-info-title").html("");
                        $("#' . $name . '-droppable-info").find(".navigate-droppable-info-provider").html("");
                        $("#' . $name . '-droppable-info").find(".navigate-droppable-info-extra").html("");
					}
				});
			');
            if (empty($value) && $contextmenu) {
                $layout->add_script('
                    $("#' . $name . '-droppable").parent().find(".navigate-droppable-create").show();
                    $("#' . $name . '-droppable").parent().find(".navigate-droppable-cancel").hide();
                ');
            } else {
                if (!empty($value)) {
                    $layout->add_script('
                    $("#' . $name . '-droppable").parent().find(".navigate-droppable-cancel").show();
                    $("#' . $name . '-droppable").parent().find(".navigate-droppable-create").hide();
                ');
                }
            }
        }
        $out[] = '<div id="' . $name . '-droppable-info" class="navigate-droppable-info">';
        $out[] = '  <div class="navigate-droppable-info-title"></div>';
        $out[] = '  <div class="navigate-droppable-info-extra"></div>';
        $out[] = '  <div class="navigate-droppable-info-provider"></div>';
        $out[] = '</div>';
        $out[] = '</div>';
        // close droppable wrapper
        return implode("\n", $out);
    }
Пример #15
0
function run()
{
    global $user;
    global $layout;
    global $DB;
    global $website;
    $out = '';
    $item = new file();
    switch ($_REQUEST['act']) {
        case 1:
            // json retrieval & operations
        // json retrieval & operations
        case "json":
            if ($_REQUEST['op'] == 'upload') {
                $tmp_name = $_REQUEST['tmp_name'];
                if ($tmp_name == "{{BASE64}}") {
                    $tmp_name = base64_encode($_REQUEST['name']);
                }
                $file = file::register_upload($tmp_name, $_REQUEST['name'], $_REQUEST['parent']);
                if (!empty($file)) {
                    echo json_encode(array('id' => $file->id, 'name' => $file->name));
                } else {
                    echo json_encode(false);
                }
            }
            switch ($_REQUEST['op']) {
                case 'create_folder':
                    file::create_folder($_REQUEST['name'], $_REQUEST['mime'], $_REQUEST['parent']);
                    echo json_encode(true);
                    break;
                case 'edit_folder':
                    $f = new file();
                    $f->load(intval($_REQUEST['id']));
                    $f->name = $_REQUEST['name'];
                    $f->mime = $_REQUEST['mime'];
                    $ok = $f->save();
                    echo json_encode($ok);
                    break;
                case 'edit_file':
                    $f = new file();
                    $f->load(intval($_REQUEST['id']));
                    $f->name = $_REQUEST['name'];
                    $ok = $f->save();
                    echo json_encode($ok);
                    break;
                case 'duplicate_file':
                    //error_reporting(~0);
                    //ini_set('display_errors', 1);
                    $status = false;
                    $f = new file();
                    $f->load(intval($_REQUEST['id']));
                    $f->id = 0;
                    $f->insert();
                    if (!empty($f->id)) {
                        $done = copy(NAVIGATE_PRIVATE . '/' . $website->id . '/files/' . intval($_REQUEST['id']), NAVIGATE_PRIVATE . '/' . $website->id . '/files/' . $f->id);
                        $status = "true";
                        if (!$done) {
                            $f->delete();
                            $status = t(56, "Unexpected error");
                        }
                    }
                    echo $status;
                    break;
                case 'move':
                    if (is_array($_REQUEST['item'])) {
                        $ok = true;
                        for ($i = 0; $i < count($_REQUEST['item']); $i++) {
                            unset($item);
                            $item = new file();
                            $item->load($_REQUEST['item'][$i]);
                            $item->parent = $_REQUEST['folder'];
                            $ok = $ok & $item->update();
                        }
                        echo json_encode($ok ? true : false);
                    } else {
                        $item->load($_REQUEST['item']);
                        $item->parent = $_REQUEST['folder'];
                        echo json_encode($item->update());
                    }
                    break;
                case 'delete':
                    try {
                        $item->load($_REQUEST['id']);
                        $status = $item->delete();
                        echo json_encode($status);
                    } catch (Exception $e) {
                        echo $e->getMessage();
                    }
                    break;
                case 'permissions':
                    $item->load($_REQUEST['id']);
                    if (!empty($_POST)) {
                        $item->access = intval($_POST['access']);
                        $item->permission = intval($_POST['permission']);
                        $item->enabled = intval($_POST['enabled']);
                        $item->groups = $_POST['groups'];
                        if ($item->access < 3) {
                            $item->groups = array();
                        }
                        $status = $item->save();
                        echo json_encode($status);
                    } else {
                        echo json_encode(array('access' => $item->access, 'groups' => $item->groups, 'permission' => $item->permission, 'enabled' => $item->enabled));
                    }
                    break;
                case 'description':
                    $item->load($_REQUEST['id']);
                    if (!empty($_POST)) {
                        $item->title = array();
                        $item->description = array();
                        foreach ($website->languages as $language) {
                            $lcode = $language['code'];
                            if (!isset($_REQUEST['titles'][$lcode])) {
                                break;
                            }
                            $item->title[$lcode] = $_REQUEST['titles'][$lcode];
                            $item->description[$lcode] = $_REQUEST['descriptions'][$lcode];
                        }
                        $status = $item->save();
                        echo json_encode($status);
                    } else {
                        // return file title and description (alt)
                        $data = array('title' => $item->title, 'description' => $item->description);
                        echo json_encode($data);
                    }
                    break;
                case 'focalpoint':
                    $item->load($_REQUEST['id']);
                    if (!empty($_POST)) {
                        $item->focalpoint = $_REQUEST['top'] . '#' . $_REQUEST['left'];
                        $status = $item->save();
                        // remove cached thumbnails
                        file::thumbnails_remove($item->id);
                        echo json_encode($status);
                    } else {
                        if (empty($item->focalpoint)) {
                            $item->focalpoint = '50#50';
                            $item->save();
                            // remove cached thumbnails
                            file::thumbnails_remove($item->id);
                        }
                        echo $item->focalpoint;
                    }
                    break;
                case 'video_info':
                    if ($_REQUEST['provider'] == 'youtube') {
                        $item->load_from_youtube($_REQUEST['reference'], false);
                        // force cache reload
                    } else {
                        if ($_REQUEST['provider'] == 'vimeo') {
                            $item->load_from_vimeo($_REQUEST['reference'], false);
                            // force cache reload
                        } else {
                            if (!empty($_REQUEST['reference']) && is_numeric($_REQUEST['reference'])) {
                                $item->load($_REQUEST['reference']);
                            } else {
                                if (is_numeric($_REQUEST['provider'])) {
                                    $item->load($_REQUEST['provider']);
                                } else {
                                    unset($item);
                                }
                            }
                            if (!empty($item)) {
                                // add some extra data
                                $item->extra = array('reference' => $item->id, 'link' => '', 'thumbnail' => 'img/icons/ricebowl/mimetypes/video.png', 'thumbnail_big' => 'img/icons/ricebowl/mimetypes/video.png', 'thumbnail_url' => 'img/icons/ricebowl/mimetypes/video.png', 'duration' => '', 'embed_code' => '<video src="' . file::file_url($item->id, 'inline') . '></video>');
                            }
                        }
                    }
                    if (!empty($item)) {
                        echo json_encode($item);
                    } else {
                        echo false;
                    }
                    break;
            }
            session_write_close();
            $DB->disconnect();
            exit;
            break;
        case 2:
            // show/edit item properties
        // show/edit item properties
        case "edit":
            $item->load($_REQUEST['id']);
            if (isset($_REQUEST['form-sent'])) {
                $item->load_from_post();
                try {
                    $item->save();
                    unset($item);
                    $item = new file();
                    $item->load($_REQUEST['id']);
                    $layout->navigate_notification(t(53, "Data saved successfully."), false, false, 'fa fa-check');
                } catch (Exception $e) {
                    $layout->navigate_notification($e->getMessage(), true, true);
                }
            }
            $out = files_item_properties($item);
            break;
        case 10:
        case 'media_browser':
            files_media_browser($_GET['limit'], $_GET['offset']);
            break;
        case 92:
            // pixlr (image editor) overlay remover
        // pixlr (image editor) overlay remover
        case 'pixlr_exit':
            ob_clean();
            file::thumbnails_remove(intval($_GET['id']));
            echo '
			<html>
			<head></head>
			<body>
			<script language="javascript" type="text/javascript">
				//window.parent.eval("$(\'#thumbnail-cache\').attr(\'src\', $(\'#thumbnail-cache\').attr(\'src\') + \'&refresh=\' + new Date().getTime());");
				window.parent.eval(\'$("#image-preview").attr("src", $("#image-preview").attr("src") + "&refresh=" + new Date().getTime());\');
				window.parent.eval("pixlr.overlay.hide();");
			</script>
			</body>
			</html>	
			';
            core_terminate();
            break;
            /*	
            case 91: // picnik editing
            	ob_clean();
            	
            	// $strPicnikUrl is the URL that we use to launch Picnik.
            	$strPicnikUrl = "http://www.picnik.com/service";	
            	// $aPicnikParams collects together all the params we'll give Picnik.  Start with an API key
            	$aPicnikParams['_apikey'] = $website->picnik_api_key;
            	// tell Picnik where to send the exported image
            	$aPicnikParams['_export'] = NAVIGATE_URL.'/navigate_upload.php?wid='.$website->id.'&engine=picnik&id='.$_REQUEST['id'].'&engine=picnik&session_id='.session_id();
            	// give the export button a title
            	$aPicnikParams['_export_title'] = t(34, 'Save');
            	// turn on the close button, and tell it to come back here
            	//$aPicnikParams['_close_target'] = $strRoot;
            	// send in the previous "king" image in case the user feels like decorating it
            	$aPicnikParams['_import'] = NAVIGATE_DOWNLOAD.'?wid='.$website->id.'&id='.$_REQUEST['id'].'&disposition=attachment&sid='.session_id();	
            	// tell Picnik to redirect the user to the following URL after the HTTP POST instead of just redirecting to _export
            	$aPicnikParams['_redirect'] = NAVIGATE_DOWNLOAD.'?wid='.$website->id.'&id='.$_REQUEST['id'].'&disposition=inline&ts='.core_time(); //'javascript: return false;';
            
            	// tell Picnik our name.  It'll use it in a few places as appropriate
            	$aPicnikParams['_host_name'] = 'Navigate';
            	// turn off the "Save &amp; Share" tab so users don't get confused
            	$aPicnikParams['_exclude'] = "out";
            
            	echo '<html><head></head><body>';
            
            	echo '<form id="picnik_form" method="POST" action="'.$strPicnikUrl.'" style=" visibility: hidden; ">';
            	
            	// put all the API parameters into the form as hidden inputs
            	foreach( $aPicnikParams as $key => $value ) {
            		echo "<input type='hidden' name='$key' value='$value'/>\n";
            	}
            	
            	//echo "<input type='text' name='address' value='Your Majesty'/>\n";
            	echo "<input type='submit' value='Picnik'/>\n";
            	echo "</form>";
            	echo '<script language="javascript" type="text/javascript">
            			document.forms[0].submit();
            		  </script>';
            	echo '</body></html>';
            
            	core_terminate();
            	break;
            */
        /*	
        case 91: // picnik editing
        	ob_clean();
        	
        	// $strPicnikUrl is the URL that we use to launch Picnik.
        	$strPicnikUrl = "http://www.picnik.com/service";	
        	// $aPicnikParams collects together all the params we'll give Picnik.  Start with an API key
        	$aPicnikParams['_apikey'] = $website->picnik_api_key;
        	// tell Picnik where to send the exported image
        	$aPicnikParams['_export'] = NAVIGATE_URL.'/navigate_upload.php?wid='.$website->id.'&engine=picnik&id='.$_REQUEST['id'].'&engine=picnik&session_id='.session_id();
        	// give the export button a title
        	$aPicnikParams['_export_title'] = t(34, 'Save');
        	// turn on the close button, and tell it to come back here
        	//$aPicnikParams['_close_target'] = $strRoot;
        	// send in the previous "king" image in case the user feels like decorating it
        	$aPicnikParams['_import'] = NAVIGATE_DOWNLOAD.'?wid='.$website->id.'&id='.$_REQUEST['id'].'&disposition=attachment&sid='.session_id();	
        	// tell Picnik to redirect the user to the following URL after the HTTP POST instead of just redirecting to _export
        	$aPicnikParams['_redirect'] = NAVIGATE_DOWNLOAD.'?wid='.$website->id.'&id='.$_REQUEST['id'].'&disposition=inline&ts='.core_time(); //'javascript: return false;';
        
        	// tell Picnik our name.  It'll use it in a few places as appropriate
        	$aPicnikParams['_host_name'] = 'Navigate';
        	// turn off the "Save &amp; Share" tab so users don't get confused
        	$aPicnikParams['_exclude'] = "out";
        
        	echo '<html><head></head><body>';
        
        	echo '<form id="picnik_form" method="POST" action="'.$strPicnikUrl.'" style=" visibility: hidden; ">';
        	
        	// put all the API parameters into the form as hidden inputs
        	foreach( $aPicnikParams as $key => $value ) {
        		echo "<input type='hidden' name='$key' value='$value'/>\n";
        	}
        	
        	//echo "<input type='text' name='address' value='Your Majesty'/>\n";
        	echo "<input type='submit' value='Picnik'/>\n";
        	echo "</form>";
        	echo '<script language="javascript" type="text/javascript">
        			document.forms[0].submit();
        		  </script>';
        	echo '</body></html>';
        
        	core_terminate();
        	break;
        */
        case 0:
            // list / search result
        // list / search result
        default:
            // show requested folder or search
            $out = files_browser($_REQUEST['parent'], $_REQUEST['navigate-quicksearch']);
            users_log::action($_REQUEST['fid'], intval($_REQUEST['parent']), 'list', '', json_encode($_REQUEST));
            break;
    }
    return $out;
}
Пример #16
0
function nvweb_object($ignoreEnabled = false, $ignorePermissions = false)
{
    global $website;
    global $DB;
    session_write_close();
    ob_end_clean();
    $item = new file();
    header('Cache-Control: private');
    header('Pragma: private');
    $type = @$_REQUEST['type'];
    $id = @$_REQUEST['id'];
    if (!empty($id)) {
        if (is_numeric($id)) {
            $item->load($id);
        } else {
            $item->load($_REQUEST['id']);
        }
    }
    if (empty($type) && !empty($item->type)) {
        $type = $item->type;
    }
    // if the type requested is not a special type, check its access permissions
    if (!in_array($type, array("blank", "transparent", "flag"))) {
        $enabled = nvweb_object_enabled($item);
        if (!$enabled && !$ignorePermissions) {
            $type = 'not_allowed';
        }
    }
    switch ($type) {
        case 'not_allowed':
            header("HTTP/1.0 405 Method Not Allowed");
            break;
        case 'blank':
        case 'transparent':
            $path = NAVIGATE_PATH . '/img/transparent.gif';
            header('Content-Disposition: attachment; filename="transparent.gif"');
            header('Content-Type: image/gif');
            header('Content-Disposition: inline; filename="transparent.gif"');
            header("Content-Transfer-Encoding: binary\n");
            $etag = base64_encode($path . filemtime($path));
            header('ETag: "' . $etag . '"');
            // check the browser cache and stop downloading again the file
            $cached = file::cacheHeaders(filemtime($path), $etag);
            if (!$cached) {
                readfile($path);
            }
            break;
        case 'flag':
            if ($_REQUEST['code'] == 'ca') {
                $_REQUEST['code'] = 'catalonia';
            }
            header('Content-Disposition: attachment; filename="' . $_REQUEST['code'] . '.png"');
            header('Content-Type: image/png');
            header('Content-Disposition: inline; filename="' . $_REQUEST['code'] . '.png"');
            header("Content-Transfer-Encoding: binary\n");
            $path = NAVIGATE_PATH . '/img/icons/flags/' . $_REQUEST['code'] . '.png';
            if (!file_exists($path)) {
                $path = NAVIGATE_PATH . '/img/transparent.gif';
            }
            $etag = base64_encode($path . filemtime($path));
            header('ETag: "' . $etag . '"');
            // check the browser cache and stop downloading again the file
            $cached = file::cacheHeaders(filemtime($path), $etag);
            if (!$cached) {
                readfile($path);
            }
            break;
        case 'image':
        case 'img':
            if (!$item->enabled && !$ignoreEnabled) {
                nvweb_clean_exit();
            }
            $path = $item->absolute_path();
            $etag_add = '';
            // calculate aspect ratio if width or height are given...
            $width = intval(@$_REQUEST['width']) + 0;
            $height = intval(@$_REQUEST['height']) + 0;
            // check size requested and ignore the empty values (or equal to zero)
            if (empty($width)) {
                $width = "";
            }
            if (empty($height)) {
                $height = "";
            }
            // get target quality (only for jpeg thumbnails!)
            $quality = $_REQUEST['quality'];
            if (empty($quality)) {
                $quality = 95;
            }
            $resizable = true;
            if ($item->mime == 'image/gif') {
                $resizable = !file::is_animated_gif($path);
            }
            if ((!empty($width) || !empty($height)) && ($resizable || @$_REQUEST['force_resize'] == 'true')) {
                $border = $_REQUEST['border'] == 'false' ? false : true;
                $path = file::thumbnail($item, $width, $height, $border, NULL, $quality);
                if (empty($path)) {
                    die;
                }
                $etag_add = '-' . $width . '-' . $height . '-' . $border . '-' . $quality;
                $item->name = $width . 'x' . $height . '-' . $item->name;
                $item->size = filesize($path);
                $item->mime = 'image/png';
                if (strpos(basename($path), '.jpg') !== false) {
                    $item->mime = 'image/jpeg';
                }
            }
            $etag = base64_encode($item->id . '-' . $item->name . '-' . $item->date_added . '-' . filesize($path) . '-' . filemtime($path) . '-' . $item->permission . $etag_add);
            header('ETag: "' . $etag . '"');
            header('Content-type: ' . $item->mime);
            header("Content-Length: " . $item->size);
            if (empty($_REQUEST['disposition'])) {
                $_REQUEST['disposition'] = 'inline';
            }
            header('Content-Disposition: ' . $_REQUEST['disposition'] . '; filename="' . $item->name . '"');
            // check the browser cache and stop downloading again the file
            $cached = file::cacheHeaders(filemtime($path), $etag);
            if (!$cached) {
                readfile($path);
            }
            break;
        case 'archive':
        case 'video':
        case 'file':
        default:
            if (!$item->enabled && !$ignoreEnabled) {
                nvweb_clean_exit();
            }
            $path = NAVIGATE_PRIVATE . '/' . $website->id . '/files/' . $item->id;
            $etag_add = '';
            clearstatcache();
            $etag = base64_encode($item->id . '-' . $item->name . '-' . $item->date_added . '-' . filemtime($path) . '-' . $item->permission . $etag_add);
            header('ETag: "' . $etag . '"');
            header('Content-type: ' . $item->mime);
            header("Accept-Ranges: bytes");
            if (empty($_REQUEST['disposition'])) {
                $_REQUEST['disposition'] = 'attachment';
            }
            header('Content-Disposition: ' . $_REQUEST['disposition'] . '; filename="' . $item->name . '"');
            // check the browser cache and stop downloading again the file
            $cached = file::cacheHeaders(filemtime($path), $etag);
            if (!$cached) {
                $range = 0;
                $size = filesize($path);
                if (isset($_SERVER['HTTP_RANGE'])) {
                    list($a, $range) = explode("=", $_SERVER['HTTP_RANGE']);
                    str_replace($range, "-", $range);
                    $size2 = $size - 1;
                    $new_length = $size - $range;
                    header("HTTP/1.1 206 Partial Content");
                    header("Content-Length: {$new_length}");
                    header("Content-Range: bytes {$range}{$size2}/{$size}");
                } else {
                    $size2 = $size - 1;
                    header("Content-Range: bytes 0-{$size2}/{$size}");
                    header("Content-Length: " . $size);
                }
                $fp = fopen($path, "rb");
                if (is_resource($fp)) {
                    @fseek($fp, $range);
                    while (!@feof($fp) && connection_status() == 0) {
                        set_time_limit(0);
                        print @fread($fp, 1024 * 1024);
                        // 1 MB per second
                        flush();
                        ob_flush();
                        sleep(1);
                    }
                    fclose($fp);
                }
            }
            break;
    }
    session_write_close();
    if ($DB) {
        $DB->disconnect();
    }
    exit;
}