/** * Generate hash of media-items of incoming map-config. * * This function detect filesize, last file time modify for each * media item of the map. Then concat this values and count md5 hash sum * * Almost function save counted values in buffer. If scripts try * recount media-hash sum again - it's returned from buffer. * * @param array $map_cfg map-config array * * @return string md5 hash value */ public static function get_media_hash($map_cfg) { static $buffer = array(); if (isset($buffer[$map_cfg['id']]) === false) { $media_string = ''; foreach ($map_cfg['objects'] as $media_id => $media_cfg) { list($media_id, $presets, $media_source, $media_cfg) = qpimg_media::parse_media_values($media_id, $media_cfg); $media_string .= "{$media_id}:{$media_source}:"; if (file_exists($media_source) === false) { $media_string .= 'not_exists;'; continue; } $media_string .= filesize($media_source) . ':' . filemtime($media_source) . ';'; } $buffer[$map_cfg['id']] = md5($media_string); } return $buffer[$map_cfg['id']]; }
/** * 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); }