/** * Private function generate basic hash by incoming map-config array. * Basic means: serialize map-config array and count md5 hash sum. * * @param array $map_cfg map-config array * @param bool $is_root_cfg flag that show is incoming $map_cfg is main map. * If true -> then will check attach maps. * If false -> then attach maps will ignore. * * @return string md5 hash value */ private static function get_basic_hash_inner($map_cfg, $is_root_cfg) { unset($map_cfg['hash']); if ($is_root_cfg && isset($map_cfg['attach']) && is_array($map_cfg['attach'])) { $map_cfg['attach:hash'] = array(); foreach ($map_cfg['attach'] as $attach_map_id) { $attach_map_cfg = qpimg_config::get_map($attach_map_id); $attach_map_hash = $attach_map_cfg ? self::get_basic_hash_inner($attach_map_cfg, false) : false; $map_cfg['attach:hash'][$attach_map_id] = $attach_map_hash; } } ksort($map_cfg); return md5(serialize($map_cfg)); }
/** * Base generate function. Detect all using maps (incoming map_id & it's attach * and sub-sub-...-attach maps). Check validate of cache files. Then if need * generate data and make redirect to CSS-file. * If $get_link is true then return path to file * * @param string $map_id * * @param bool $get_link * * @return bool global execute status */ public static function execute($map_id, $get_link = FALSE) { list($map_id) = explode(':', $map_id); $need_get_maps_stack = array($map_id); $valid_maps_stack = array(); $invalid_maps_stack = array(); while (count($need_get_maps_stack) > 0) { $one_map_id = array_shift($need_get_maps_stack); $one_map_cfg = qpimg_config::get_map($one_map_id); if ($one_map_cfg === false) { return false; } if (isset($one_map_cfg['attach']) === true) { if (is_array($one_map_cfg['attach']) === false) { $one_map_cfg['attach'] = array($one_map_cfg['attach']); } foreach ($one_map_cfg['attach'] as $attach_map_id) { if (isset($valid_maps_stack[$attach_map_id]) === false && isset($invalid_maps_stack[$attach_map_id]) === false) { $need_get_maps_stack[] = $attach_map_id; } } } //--------------------------------------------------------------------- // Check for data in cache if (qpimg_cache::validate($one_map_cfg) === true) { $valid_maps_stack[$one_map_id] = $one_map_cfg; } else { if (qpimg_cache::clean($one_map_cfg) === false) { return false; } $invalid_maps_stack[$one_map_id] = $one_map_cfg; } if ($map_id == $one_map_id) { $map_cfg = $one_map_cfg; } } if (count($invalid_maps_stack) > 0) { if (isset($invalid_maps_stack[$map_id]) === false) { $invalid_maps_stack[$map_id] = $valid_maps_stack[$map_id]; unset($valid_maps_stack[$map_id]); } //--------------------------------------------------------------------- // Generate data foreach ($invalid_maps_stack as $one_map_id => $one_map_cfg) { if (qpimg_media::pack($one_map_cfg) === false) { return false; } $valid_maps_stack[$one_map_id] = $invalid_maps_stack[$one_map_id]; } qpimg_cache::clean($one_map_cfg, true); if (qpimg_media::pack_grouper_css($map_cfg, $valid_maps_stack) === false) { return false; } //--------------------------------------------------------------------- } return $get_link ? qpimg_cache::get_valid_css_source($map_cfg, isset($map_cfg['attach'])) : qpimg_cache::redirect($map_cfg); }