[Typo3-dev] Re: Crop on HTML contents

Davide Principi d.principi at provincia.ps.it
Wed Mar 9 13:48:51 CET 2005


Ok I'm new to Typo3 API. An answer was in typo3 Core Api documentation:
splitIntoBlockRecursiveProc!
The following class seems to work. The question is: is it correct
calling the function with a regexp argument?

class user_html_crop {
  var $cObj;
  var $parseObj;
  var $cropLimit = 10000;
  var $progress = 0;
  var $cropped = 0;
  var $hellip = "...";

  function process($content, $conf) {

    $this->parseObj = t3lib_div::makeInstance('t3lib_parsehtml');
    $this->progress = 0;
    $this->cropped = 0;

    if ($conf['crop']) {
      $this->cropLimit = $conf['crop'];
    }

    $out = $this->parseObj->splitIntoBlockRecursiveProc("([A-Za-z]+[0-9]?)",
                             $content,
                             $this,
                             'callBackContent',
                             null);
    return $out;
  }

  function callBackContent($str, $level) {
    if ($this->cropped) {
      return "";
    }

    $strLen = strlen($str);
    if (($this->progress + $strLen) > $this->cropLimit) {
      $str = substr($str, 0, $this->cropLimit - $this->progress);
      $str .= $this->hellip;
      $this->cropped = 1;
    }
    $this->progress = $this->progress + strlen($str);
    //debug($str, $this);
    return $str;
  }
}





More information about the TYPO3-dev mailing list