Geo_Preferences::GetIconsInfo PHP Method

GetIconsInfo() public static method

Gets info on marker icons
public static GetIconsInfo ( string $p_htmlDir, string $p_websiteUrl ) : array
$p_htmlDir string
$p_websiteUrl string
return array
    public static function GetIconsInfo($p_htmlDir, $p_websiteUrl)
    {
        global $Campsite;
        $cnf_html_dir = $Campsite['HTML_DIR'];
        $cnf_website_url = $Campsite['WEBSITE_URL'];
        $preferencesService = \Zend_Registry::get('container')->getService('system_preferences_service');
        if ('' != $p_htmlDir) {
            $cnf_html_dir = $p_htmlDir;
        }
        if ('' != $p_websiteUrl) {
            $cnf_website_url = $p_websiteUrl;
        }
        $no_arr = array('json_obj' => array('webdir' => '', 'default' => '', 'icons' => array()));
        $use_icons = array();
        $icons_subpath = $preferencesService->MapMarkerDirectory;
        if (!$icons_subpath) {
            $icons_subpath = '/js/geocoding/markers';
        }
        $icons_subdir = $cnf_html_dir . $icons_subpath;
        $icons_webdir = $cnf_website_url . $icons_subpath;
        if (!is_dir($icons_subdir)) {
            return $no_arr;
        }
        $icons_default_name = $preferencesService->MapMarkerSourceDefault;
        if (!$icons_default_name) {
            $icons_default_name = '';
        }
        $img_suffixes = array('png', 'gif', 'jpg', 'jpe', 'jpeg', 'svg', 'pbm', 'bmp', 'xpm', 'xbm', 'tif', 'tiff');
        $offset_x_names = array('offsetx', 'offset_x', 'offset x', 'width offset');
        $offset_y_names = array('offsety', 'offset_y', 'offset y', 'height offset');
        $icons_first_name = '';
        $icons_default_name_exists = false;
        $icons_arr_unknown = array();
        $icons_arr_unknown[] = 'special/unknown.png';
        $icons_arr = array_merge($icons_arr_unknown, scandir($icons_subdir));
        foreach ($icons_arr as $one_name) {
            $img_label_arr = explode('.', $one_name);
            if (2 != count($img_label_arr)) {
                continue;
            }
            // we expect that regular image files shall be icon_name.suffix
            $img_label = $img_label_arr[0] . ' (' . $img_label_arr[1] . ')';
            $web_path = $icons_webdir . '/' . $one_name;
            $one_path = $icons_subdir . '/' . $one_name;
            if (is_file($one_path)) {
                $one_name_parts = explode('.', $one_path);
                $one_name_size = count($one_name_parts);
                if (2 > $one_name_size) {
                    continue;
                }
                if (!in_array($one_name_parts[$one_name_size - 1], $img_suffixes)) {
                    continue;
                }
                $img_info = getimagesize($one_path);
                if (!$img_info) {
                    continue;
                }
                $img_width_value = 0 + $img_info[0];
                $img_height_value = 0 + $img_info[1];
                $img_width = '' . $img_info[0];
                $img_height = '' . $img_info[1];
                $img_width_off = '-' . floor($img_info[0] / 2);
                $img_height_off = '-' . ($img_info[1] - 0);
                $one_name_parts[$one_name_size - 1] = 'ini';
                $one_name_desc = implode('.', $one_name_parts);
                $one_file_desc = fopen($one_name_desc, 'r');
                if (!$one_file_desc) {
                    $one_name_parts[$one_name_size - 1] = 'txt';
                    $one_name_desc = implode('.', $one_name_parts);
                    $one_file_desc = fopen($one_name_desc, 'r');
                }
                if ($one_file_desc) {
                    while (true) {
                        $one_img_info = fgets($one_file_desc);
                        if (!$one_img_info) {
                            break;
                        }
                        $one_img_info = trim($one_img_info);
                        if (0 == strlen($one_img_info)) {
                            continue;
                        }
                        if ('#' == $one_img_info[0]) {
                            continue;
                        }
                        $info_arr = explode(':', $one_img_info);
                        if (2 > count($info_arr)) {
                            $info_arr = explode(',', $one_img_info);
                        }
                        if (2 > count($info_arr)) {
                            continue;
                        }
                        $one_param = strtolower(trim($info_arr[0]));
                        $one_value = trim($info_arr[1]);
                        if (in_array($one_param, $offset_x_names)) {
                            if (is_numeric($one_value)) {
                                $img_width_off = '' . ($one_value - $img_width_value);
                            }
                        }
                        if (in_array($one_param, $offset_y_names)) {
                            if (is_numeric($one_value)) {
                                $img_height_off = '' . ($one_value - $img_height_value);
                            }
                        }
                    }
                    fclose($one_file_desc);
                }
                $use_icons[] = array('label' => $img_label, 'name' => $one_name, 'path' => $web_path, 'width_off' => $img_width_off, 'height_off' => $img_height_off, 'width' => $img_width, 'height' => $img_height);
                if ('' == $icons_first_name) {
                    $icons_first_name = $one_name;
                }
                if ($one_name == $icons_default_name) {
                    $icons_default_name_exists = true;
                }
            }
        }
        if (!$icons_default_name_exists) {
            if ('' != $icons_first_name) {
                $icons_default_name = $icons_first_name;
            }
        }
        $res_icons_info = array('webdir' => $icons_webdir, 'default' => $icons_default_name, 'icons' => $use_icons);
        return array('json_obj' => $res_icons_info);
    }

Usage Example

Example #1
0
$map_article_spec = '' . $f_article_number . '_' . $f_language_id;
if (!Input::IsValid()) {
    camp_html_display_error(getGS('Invalid input: $1', Input::GetErrorString()), $_SERVER['REQUEST_URI'], true);
    exit;
}
$articleObj = new Article($f_language_id, $f_article_number);
$cnf_html_dir = $Campsite['HTML_DIR'];
$cnf_website_url = $Campsite['WEBSITE_URL'];
$geo_map_info = Geo_Preferences::GetMapInfo($cnf_html_dir, $cnf_website_url);
$geo_map_incl = Geo_Preferences::PrepareMapIncludes($geo_map_info['incl_obj']);
$geo_map_json = "";
$geo_map_json .= json_encode($geo_map_info['json_obj']);
$geo_map_usage = Geo_Map::ReadMapInfo('article', $f_article_number);
$geo_map_usage_json = "";
$geo_map_usage_json .= json_encode($geo_map_usage);
$geo_icons_info = Geo_Preferences::GetIconsInfo($cnf_html_dir, $cnf_website_url);
$geo_icons_json = "";
$geo_icons_json .= json_encode($geo_icons_info['json_obj']);
$geo_popups_info = Geo_Preferences::GetPopupsInfo($cnf_html_dir, $cnf_website_url);
$geo_popups_json = "";
$geo_popups_json .= json_encode($geo_popups_info['json_obj']);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta http-equiv="Expires" content="now" />
    <title><?php 
putGS('Setting Map Locations');
?>
</title>
All Usage Examples Of Geo_Preferences::GetIconsInfo