最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

更新php的搜索Skydrive图片的正则表达式,使得WordPress的Retina主题中的缩略图再次生效

WordPress crifan 1941浏览 0评论

【背景】

之前已经给wordpress的retina主题添加了对于skydrive上面的图片的缩略图的支持,但是后来由于给InsertSkydriveFiles插件添加了target="_blank"的支持,导致在WLW中发布到wordpress上面的帖子源码中,对应的skydrive图片的地址,从:

<p><a href="http://storage.live.com/items/9A8B8BF501A38A36!2484?filename=large%20small%20normal.png"><img style="xxx" title="large small normal" xxx src="http://storage.live.com/items/9A8B8BF501A38A36!2484?filename=large%20small%20normal.png" width="644" height="437" /></a></p>

变为:

<p><a href="http://storage.live.com/items/9A8B8BF501A38A36!2484?filename=large%20small%20normal.png" target="_blank"><img style="xxx" title="large small normal" xxx src="http://storage.live.com/items/9A8B8BF501A38A36!2484?filename=large%20small%20normal.png" width="644" height="437" /></a></p>

这就导致之前在retina\lib\functions\image.php中添加的正则表达式:

$pattern = '#<a href="(?P<picUrl>http://storage.live.com/items/.+?filename=.+?\.['.$picSufChars.']{3,4})"><img.+?src="(?P=picUrl)".+?/></a>#';

失效了,找不到新html源码中的skydrive类型的图片地址了,因此retina的缩略图,也就失效了。

结果也就变成,旧的帖子是有缩略图的,新的帖子没了缩略图:

old has new not has

现在需要去更新对应的正则表达式,使得可以找到skydrive的图片,以恢复retina的缩略图。

 

【解决过程】

1.找到原先的代码

wordpress\wp-content\themes\retina\lib\functions\image.php

经过一番调试,将原先代码:

        # current support valid pic suffiex: 'bmp', 'gif', 'jpeg', 'jpg', 'jpe', 'png', 'tiff', 'tif'
        $picSufChars = "befgijmnptBEFGIJMNPT";
        //$pattern = '#<a href="(?P<picUrl>http://storage.live.com/items/.+?filename=.+?\.jpg)"><img.+?src="(?P=picUrl)".+?/></a>#';
        $pattern = '#<a href="(?P<picUrl>http://storage.live.com/items/.+?filename=.+?\.['.$picSufChars.']{3,4})"><img.+?src="(?P=picUrl)".+?/></a>#';

改为:

        /* $picSufChars = "befgijmnptBEFGIJMNPT"; */
        /* $pattern = '#<a href="(?P<picUrl>http://storage.live.com/items/.+?filename=.+?\.jpg)"><img.+?src="(?P=picUrl)".+?/></a>#'; */
        /* $pattern = '#<a(\s+?\w+="?.+?"?)*? href="(?P<picUrl>http://storage.live.com/items/.+?filename=.+?\.['.$picSufChars.']{3,4})"(\s+?\w+="?.+?"?)*?><img.+?src="(?P=picUrl)".+?/></a>#'; */
        
        $pattern = '#<a(\s+?\w+="?.+?"?)*? href="(?P<picUrl>http://storage.live.com/items/.+?)"(\s+?\w+="?.+?"?)*?><img.+?src="(?P=picUrl)".+?/></a>#';

即可。

其中,多添加的:

(\s+?\w+="?.+?"?)*?

是为了匹配,0或多个,(现在和将来 可能出现的 和已经出现的)target="_target"之类的属性,而写的。

如此,之前帖子本身包含图片,但没有缩略图的帖子:

prev no thumbnail

现在就可以正常显示出缩略图了:

now has thumbnail

 

【总结】

其实还是正则表达式的引用而已。更新php中对应的正则即可。

 

关于正则表达式,感兴趣的可以去看看我的总结:

正则表达式学习心得

转载请注明:在路上 » 更新php的搜索Skydrive图片的正则表达式,使得WordPress的Retina主题中的缩略图再次生效

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
90 queries in 0.187 seconds, using 22.14MB memory