function osm_apply_menu($menu_ref_arr)
{
    global $template, $page, $conf;
    $menu =& $menu_ref_arr[0];
    if (($block = $menu->get_block('mbLinks')) != null) {
        include_once dirname(__FILE__) . '/include/functions.php';
        include_once dirname(__FILE__) . '/include/functions_map.php';
        osm_load_language();
        load_language('plugin.lang', OSM_PATH);
        // Comment are used only with this condition index.php l294
        if ($page['start'] == 0 and !isset($page['chronology_field'])) {
            $js_data = osm_get_items($page);
            if ($js_data != array()) {
                $local_conf = array();
                $local_conf['contextmenu'] = 'false';
                $local_conf['control'] = true;
                $local_conf['img_popup'] = false;
                $local_conf['popup'] = 2;
                $local_conf['center_lat'] = 0;
                $local_conf['center_lng'] = 0;
                $local_conf['zoom'] = 2;
                $local_conf['autocenter'] = 1;
                $local_conf['divname'] = 'mapmenu';
                $local_conf['paths'] = osm_get_gps($page);
                $height = isset($conf['osm_conf']['main_menu']['height']) ? $conf['osm_conf']['main_menu']['height'] : '200';
                $js = osm_get_js($conf, $local_conf, $js_data);
                $template->set_template_dir(dirname(__FILE__) . '/template/');
                $template->assign(array('OSM_PATH' => embellish_url(get_gallery_home_url() . OSM_PATH), 'OSMJS' => $js, 'HEIGHT' => $height));
                $block->template = 'osm-menu.tpl';
            }
        }
    }
}
function osm_render_category()
{
    global $template, $page, $conf, $filter;
    include_once dirname(__FILE__) . '/include/functions.php';
    include_once dirname(__FILE__) . '/include/functions_map.php';
    osm_load_language();
    load_language('plugin.lang', OSM_PATH);
    // TF, 20160102: pass config as parameter
    $js_data = osm_get_items($conf, $page);
    if ($js_data != array()) {
        $local_conf = array();
        $local_conf['contextmenu'] = 'false';
        $local_conf['control'] = true;
        $local_conf['img_popup'] = false;
        $local_conf['popup'] = 1;
        $local_conf['center_lat'] = 0;
        $local_conf['center_lng'] = 0;
        $local_conf['zoom'] = 2;
        $local_conf['auto_center'] = 1;
        // TF, 20160102: pass config as parameter
        $local_conf['paths'] = osm_get_gps($conf, $page);
        $height = isset($conf['osm_conf']['category_description']['height']) ? $conf['osm_conf']['category_description']['height'] : '200';
        $width = isset($conf['osm_conf']['category_description']['width']) ? $conf['osm_conf']['category_description']['width'] : 'auto';
        $js = osm_get_js($conf, $local_conf, $js_data);
        $template->set_filename('map', dirname(__FILE__) . '/template/osm-category.tpl');
        $template->assign(array('CONTENT_ENCODING' => get_pwg_charset(), 'OSM_PATH' => embellish_url(get_gallery_home_url() . OSM_PATH), 'HOME' => make_index_url(), 'HOME_PREV' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : get_absolute_root_url(), 'HOME_NAME' => l10n("Home"), 'HOME_PREV_NAME' => l10n("Previous"), 'OSMJS' => $js, 'HEIGHT' => $height, 'WIDTH' => $width));
        $osm_content = $template->parse('map', true);
        //$osm_content = '<div id="osmmap"><div class="map_title">'.l10n('EDIT_MAP').'</div>' . $osm_content . '</div>';
        $index = isset($conf['osm_conf']['category_description']['index']) ? $conf['osm_conf']['category_description']['index'] : 0;
        // 0 - PLUGIN_INDEX_CONTENT_BEGIN
        // 1 - PLUGIN_INDEX_CONTENT_COMMENT
        // 2 - PLUGIN_INDEX_CONTENT_END
        if ($index <= 1) {
            // From index category comment at L300
            if ($page['start'] == 0 and !isset($page['chronology_field'])) {
                if (empty($page['comment'])) {
                    $page['comment'] = $osm_content;
                } else {
                    if ($index == 0) {
                        $page['comment'] = '<div>' . $osm_content . $page['comment'] . '</div>';
                    } else {
                        $page['comment'] = '<div>' . $page['comment'] . $osm_content . '</div>';
                    }
                }
            }
        } else {
            $osm_content = '<div id="osmmap">' . $osm_content . '</div>';
            $template->concat('PLUGIN_INDEX_CONTENT_END', "\n" . $osm_content);
        }
    }
}
$tokens = explode('/', preg_replace('#^/#', '', $section));
$next_token = 0;
$result = osm_parse_map_data_url($tokens, $next_token);
$page = array_merge($page, $result);
if (isset($page['category'])) {
    check_restrictions($page['category']['id']);
}
/* If the config include parameters get them */
$zoom = isset($conf['osm_conf']['left_menu']['zoom']) ? $conf['osm_conf']['left_menu']['zoom'] : 2;
$center = isset($conf['osm_conf']['left_menu']['center']) ? $conf['osm_conf']['left_menu']['center'] : '0,0';
$center_arr = preg_split('/,/', $center);
$center_lat = isset($center_arr) ? $center_arr[0] : 0;
$center_lng = isset($center_arr) ? $center_arr[1] : 0;
/* If we have zoom and center coordonate, set it otherwise fallback default */
$zoom = isset($_GET['zoom']) ? $_GET['zoom'] : $zoom;
$center_lat = isset($_GET['center_lat']) ? $_GET['center_lat'] : $center_lat;
$center_lng = isset($_GET['center_lng']) ? $_GET['center_lng'] : $center_lng;
$local_conf = array();
$local_conf['zoom'] = $zoom;
$local_conf['center_lat'] = $center_lat;
$local_conf['center_lng'] = $center_lng;
$local_conf['contextmenu'] = 'false';
$local_conf['control'] = true;
$local_conf['img_popup'] = false;
// TF, 20160102: pass config as parameter
$local_conf['paths'] = osm_get_gps($conf, $page);
$local_conf = $local_conf + $conf['osm_conf']['map'] + $conf['osm_conf']['left_menu'];
// TF, 20160102: pass config as parameter
$js_data = osm_get_items($conf, $page);
$js = osm_get_js($conf, $local_conf, $js_data);
osm_gen_template($conf, $js, $js_data, 'osm-map.tpl', $template);
}
// deleting first "/" if displayed
$tokens = explode('/', preg_replace('#^/#', '', $section));
$next_token = 0;
$result = osm_parse_map_data_url($tokens, $next_token);
$page = array_merge($page, $result);
if (isset($page['category'])) {
    check_restrictions($page['category']['id']);
}
/* If the config include parameters get them */
$zoom = isset($conf['osm_conf']['left_menu']['zoom']) ? $conf['osm_conf']['left_menu']['zoom'] : 2;
$center = isset($conf['osm_conf']['left_menu']['center']) ? $conf['osm_conf']['left_menu']['center'] : '0,0';
$center_arr = preg_split('/,/', $center);
$center_lat = isset($center_arr) ? $center_arr[0] : 0;
$center_lng = isset($center_arr) ? $center_arr[1] : 0;
/* If we have zoom and center coordonate, set it otherwise fallback default */
$zoom = isset($_GET['zoom']) ? $_GET['zoom'] : $zoom;
$center_lat = isset($_GET['center_lat']) ? $_GET['center_lat'] : $center_lat;
$center_lng = isset($_GET['center_lng']) ? $_GET['center_lng'] : $center_lng;
$local_conf = array();
$local_conf['zoom'] = $zoom;
$local_conf['center_lat'] = $center_lat;
$local_conf['center_lng'] = $center_lng;
$local_conf['contextmenu'] = 'true';
$local_conf['control'] = true;
$local_conf['img_popup'] = false;
$local_conf['paths'] = osm_get_gps($page);
$local_conf = $local_conf + $conf['osm_conf']['map'] + $conf['osm_conf']['left_menu'];
$js_data = osm_get_items($page);
$js = osm_get_js($conf, $local_conf, $js_data);
osm_gen_template($conf, $js, $js_data, 'osm-map2.tpl', $template);
function osm_render_element_content()
{
    global $template, $picture, $page, $conf;
    load_language('plugin.lang', OSM_PATH);
    if (empty($page['image_id'])) {
        return;
    }
    // Load coordinates from picture
    $query = 'SELECT latitude,longitude FROM ' . IMAGES_TABLE . ' WHERE id = \'' . $page['image_id'] . '\' ;';
    //FIXME LIMIT 1 ?
    $result = pwg_query($query);
    $row = pwg_db_fetch_assoc($result);
    if (!$row or !$row['latitude'] or empty($row['latitude'])) {
        return;
    }
    $lat = $row['latitude'];
    $lon = $row['longitude'];
    // Load parameter, fallback to default if unset
    $height = isset($conf['osm_conf']['right_panel']['height']) ? $conf['osm_conf']['right_panel']['height'] : '200';
    $zoom = isset($conf['osm_conf']['right_panel']['zoom']) ? $conf['osm_conf']['right_panel']['zoom'] : '12';
    $osmname = isset($conf['osm_conf']['right_panel']['link']) ? $conf['osm_conf']['right_panel']['link'] : 'Location';
    $osmnamecss = isset($conf['osm_conf']['right_panel']['linkcss']) ? $conf['osm_conf']['right_panel']['linkcss'] : '';
    $showosm = isset($conf['osm_conf']['right_panel']['showosm']) ? $conf['osm_conf']['right_panel']['showosm'] : 'true';
    if (strlen($osmnamecss) != 0) {
        $osmnamecss = "style='" . $osmnamecss . "'";
    }
    $osmlink = "https://openstreetmap.org/?mlat=" . $lat . "&amp;mlon=" . $lon . "&zoom=12&layers=M";
    $local_conf = array();
    $local_conf['contextmenu'] = 'false';
    $local_conf['control'] = false;
    $local_conf['img_popup'] = false;
    $local_conf['popup'] = 2;
    $local_conf['center_lat'] = $lat;
    $local_conf['center_lng'] = $lon;
    $local_conf['zoom'] = $zoom;
    // TF, 20160102: pass config as parameter
    $js_data = osm_get_items($conf, $page);
    $js = osm_get_js($conf, $local_conf, $js_data);
    // Select the template
    $template->set_filenames(array('osm_content' => dirname(__FILE__) . "/template/osm-picture.tpl"));
    // Assign the template variables
    $template->assign(array('HEIGHT' => $height, 'OSMJS' => $js, 'OSM_PATH' => embellish_url(get_gallery_home_url() . OSM_PATH), 'OSMNAME' => $osmname, 'OSMNAMECSS' => $osmnamecss, 'SHOWOSM' => $showosm, 'OSMLINK' => $osmlink));
    // Return the rendered html
    $osm_content = $template->parse('osm_content', true);
    return $osm_content;
}