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);
}