/**
  * Check map_id value for allow chars and return map-config array by map_id.
  * 
  * First check if user qpimg_config class has get_map function and 
  * ask data by this function. Otherwise get data from map-array. 
  * Otherwise return false.
  * 
  * @param string $map_id
  * 
  * @return array map-config data or false 
  */
 public static function get_map($map_id)
 {
     $qpimg_config = $GLOBALS['qpimg_config'];
     if (preg_match('/[^a-zA-Z0-9_]/', $map_id) > 0) {
         qpimg_logger::write("QPIMG_WARNING: Used illegal chars in map name '{$map_id}'", __FILE__, __LINE__);
         return false;
     }
     $map_cfg = false;
     if (function_exists('qpimg_user_get_map') === true) {
         $map_cfg = qpimg_user_get_map($map_id);
     }
     if (!$map_cfg) {
         if (isset($qpimg_config['maps']) === false || isset($qpimg_config['maps'][$map_id]) === false) {
             qpimg_logger::write("QPIMG_WARNING: Asked map '{$map_id}' is not exists", __FILE__, __LINE__);
             return false;
         }
         $map_cfg = $qpimg_config['maps'][$map_id];
     }
     $map_cfg['id'] = $map_id;
     if (isset($map_cfg['hash']) === false) {
         $map_cfg['hash'] = qpimg_cache::get_basic_hash($map_cfg);
     }
     return $map_cfg;
 }
 /**
  * Generate path for cache-file by map-config array, extenstion of file and 
  * key-value. 
  * 
  * The struct is:
  * cache-folder/map_id[.map_hash_value][.key].extenstion
  * 'map_hash_value' and 'key' - optional
  * 
  * @param array $map_cfg map-config array
  * 
  * @param string $ext extension of file
  * 
  * @param string $key key value
  * 
  * @param bool $is_url bool value, is need generate PATH(=false) or URL(=true) to file 
  * 
  * @return string cache-file path 
  */
 public static function gen_filename($map_cfg, $ext, $key = null, $is_url = false)
 {
     if ($ext == 'crc') {
         $basedir = qpimg_config::get_option('private_cache_basedir');
     } else {
         $basedir = qpimg_config::get_option($is_url ? 'public_cache_dir_src' : 'public_cache_basedir');
     }
     if ($basedir === false) {
         qpimg_logger::write("QPIMG_ERROR: Cannot detect cache_basedir", __FILE__, __LINE__);
         die;
     }
     return $basedir . $map_cfg['id'] . ($map_cfg['hash'] ? ".{$map_cfg['hash']}" : "") . ($key !== null ? ".{$key}" : "") . ".{$ext}";
 }
 /**
  * Set position of each media-item on result sprite for orientation mode = 'repeat_y'
  * Almost count sprite-width & sprite-height.
  * 
  * @param array $map_cfg map-config array
  * 
  * @param const $mode generate-mode
  * 
  * @return array( media-items array, sprite-width, sprite-height ) 
  */
 private static function set_position_repeat_y($map_cfg, $mode)
 {
     $fmedia_items = self::filter_media_items($map_cfg['objects:items'], $mode);
     if (count($fmedia_items) == 0) {
         return array(array(), 0, 0);
     }
     list($max_img_width, $max_img_height) = self::get_max_sizes($fmedia_items);
     //---------------------------------------------------------------------
     if (isset($map_cfg['map_height']) === true && is_numeric($map_cfg['map_height']) === true) {
         $map_cfg['map_height'] = max((int) $map_cfg['map_height'], $max_img_height);
     } else {
         $map_cfg['map_height'] = $max_img_height;
     }
     if (!($map_cfg['map_height'] > 0 && $map_cfg['map_height'] <= 10000)) {
         qpimg_logger::write("E_USER_NOTICE: Wrong height value '{$map_cfg['map_height']}' for repeat-y-orientation map '{$map_cfg['id']}'", __FILE__, __LINE__);
         $map_cfg['map_width'] = 10000;
     }
     //---------------------------------------------------------------------
     $sprite_img_width = 0;
     $sprite_img_height = $map_cfg['map_height'];
     $result_media_items = array();
     foreach ($fmedia_items as $media_item_key => $media_item) {
         $media_item->set('left', $sprite_img_width);
         $media_item->set('top', 0);
         $media_item->set('space-top', 0);
         $media_item->set('space-bottom', 0);
         $media_item->set('scale-height', $sprite_img_height);
         if ($media_item->get('etalon-height') == 1) {
             $media_item->set('scale-method', 'resize');
         } else {
             $media_item->set('scale-method', 'mosaic');
         }
         $sprite_img_width += $media_item->get('full-width');
         $result_media_items[$media_item_key] = $media_item;
     }
     return array($result_media_items, $sprite_img_width, $sprite_img_height);
 }