Skip to content

Instantly share code, notes, and snippets.

@govza
Created February 11, 2013 21:37
Show Gist options
  • Save govza/4757842 to your computer and use it in GitHub Desktop.
Save govza/4757842 to your computer and use it in GitHub Desktop.
Modx Revo plugin, strip content and set it to introtext
<?php
//OnBeforeDocFormSave
$introlength = $modx->getOption('IntrotextOptions',$scriptProperties,'400');
$introtext= $resource ->introtext;
$text =$modx->stripTags($resource->content);
if(empty($introtext)){
if (strlen($text) > $introlength) {
$cuttext = mb_substr($text, 0, $introlength,"UTF-8");
$pos = mb_strrpos($cuttext, ' ',"UTF-8");
$output = mb_substr($cuttext, 0, $pos,"UTF-8");
}
else{
$output = $text;
}
$resource->set('introtext',$output);
}
$resource->save();
//$modx->event->output('внимание: '.$pos);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment