private function replaceMediaPath($matches) { $path = $matches[0]; $aPath = Tool::getActualPath($path); if (isset($this->map['media'][$aPath])) { trigger('js_replace', $this, $aPath); return Tool::addCdn($this->map['media'][$aPath]); } return $path; }
private function getBackgroundUrlData($url, $merge = null) { $ret = array('url' => $url, 'config' => null); $newUrl = $url; if (!$url || strpos($url, 'data:') !== false || strpos($url, 'about:') !== false || strpos($url, '://') !== false) { return $ret; } $url = Tool::getActualPath($url); $mask = 0; $mask += !is_null($merge); $mask += $mask > 0 && isset($this->spriteConfig[$merge]); $mask += $mask > 1 && isset($this->spriteConfig[$merge]['config'][$url]); $mask <<= 1; $mask += isset($this->map['media'][$url]); if (($mask & 6) === 6) { $sprite = $this->spriteConfig[$merge]['attr']['filename']; if (isset($this->map['media'][$sprite])) { $newUrl = $this->map['media'][$sprite]; } else { mark('找不到合图文件' . $sprite . '的去向,请确定该合图已编译', 'error'); return $ret; } $ret['config'] = $this->spriteConfig[$merge]['config'][$url]; trigger('css_background_change', $this, $sprite); } else { if (($mask & 1) === 1) { $newUrl = $this->map['media'][$url]; } trigger('css_background_change', $this, $url); // 依然将合图加入依赖关系表中,万一某天心血来潮又合图了,依然可以进行增量编译 if ($mask > 1) { trigger('css_background_change', $this, $merge . C('SPRITE_SUFFIX') . '.png'); } // 5中异常情况 switch ($mask) { case 0: mark('文件“' . $this->path . '”中引用了“' . $url . '”,但该图片不存在!', 'warn'); return $ret; case 1: // 正常情况 break; case 2: mark('文件“' . $this->path . '”中存在未知合图类型“' . $merge . '”,并且图片“' . $url . '”也不存在', 'warn'); return $ret; case 3: mark('文件“' . $this->path . '”中存在未知合图类型“' . $merge . '”,将用小图地址代替', 'warn'); break; case 4: mark('文件“' . $this->path . '”中引用了合图“' . $merge . '”,但该合图类型中不存在“' . $url . '”的配置信息,并且该图片也不存在', 'warn'); return $ret; case 5: mark('文件“' . $this->path . '”中引用了合图“' . $merge . '”,但该合图类型中不存在“' . $url . '”的配置信息,将用小图地址代替', 'warn'); break; default: mark('文件“' . $this->path . '”中引用了“' . $url . '”,未知错误码:' . $mask, 'error'); return $ret; } } $ret['url'] = Tool::addCdn($newUrl); return $ret; }
/** * 进行地址替换 * @param $type * @param $key * @param $orgValue */ private function replacePath($type, &$key, $prop) { $value = $key->{$prop}; // 去掉queryString $pos = strpos($value, '?'); if ($pos !== false) { $value = substr($value, 0, $pos); } $value = Tool::getActualPath($value); if (isset($this->map[$type][$value])) { $key->{$prop} = Tool::addCdn($this->map[$type][$value]); trigger('html_href_change', $this, $value); } }