Created
December 30, 2011 12:30
-
-
Save Zauberfisch/1539635 to your computer and use it in GitHub Desktop.
[Silverstripe] add <a href="big.png"> to all <img class"popup" src="small.png"> to allow opening full image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Page extends SiteTree { | |
... | |
function Content() { | |
$content = $this->Content; | |
// move class to the beginning right after <img | |
$pattern[0] = '/(<img)([^>]*?)(class=(\'|")([^>]*?)(\'|"))([^>]*?>)/i'; | |
$replacement[0] = '$1 $3$2$7'; | |
// add <a> to all images with class popup and a src having _resampled | |
$pattern[1] = '/(<img[^>]*?class=("|\')[^>]*?popup[^>]*?("|\')[^>]*?src=("|\')([^>]*?)_resampled\/[^\->]*?-([^>]*?)("|\')[^>]*?>)/i'; | |
$replacement[1] = '<a href="$4$6">$1</a>'; | |
return preg_replace($pattern, $replacement, $content); | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NOTE: one might want to test it before using it (: