Created
February 11, 2013 19:58
-
-
Save govza/4757102 to your computer and use it in GitHub Desktop.
Get first Image from modx content and add to firstImageTV
This file contains 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
<?php | |
//OnDocFormSave | |
$img_path = $modx->getOption('imagesPath',$scriptProperties, MODX_ASSETS_URL."static/images/"); | |
$imgName = $modx->getOption('ImageName',$scriptProperties,'default.png'); | |
$TvValue = $modx->getOption('TV',$scriptProperties,'firstImage'); | |
$def_img = $img_path.$imgName; | |
$img = $resource->GetTVValue($TvValue); | |
$text = $resource->content; | |
if(empty($img)) { | |
if (preg_match_all( '|<img.*?src=[\'"](.*?)[\'"].*?>|i',$text , $matches )!=0) | |
{ | |
$img = $matches[1][0]; | |
} | |
else{ | |
$img = $def_img; | |
} | |
} | |
$resource->setTVValue($TvValue,$img); | |
//$modx->event->output('внимание: '.$output); | |
$resource->save(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment