[ Index ]

MailPress 544

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]     [ Statistics ]    

title

Body

[close]

/mp-includes/class/ -> MP_Html2txt.class.php (source)

   1  <?php
   2  /* based on http://www.chuggnutt.com/html2text.php */
   3  class MP_Html2txt extends MP_html2txt_
   4  {
   5      var   $files = array();
   6  
   7  	function __construct( $files = false, $args_file = 'args', $path = false , $debug = false )
   8      {
   9      // path for xml files
  10          $this->path = ($path) ? $path : MP_CONTENT_DIR . 'advanced/html2txt/';
  11  
  12      // debug
  13          $this->debug = $debug;
  14  
  15      // _parms
  16          $xml = $this->get_xml( $args_file );
  17  
  18          if (isset($xml->width))     $this->width = (int) $xml->width;
  19          if (!isset($this->width))    $this->width = (isset($this->default_width)) ? $this->default_width : 80;
  20  
  21          if (!$files && isset($xml->files)) foreach($xml->files->file as $file) $files[] = (string) $file;
  22  
  23          $this->s = $this->r = array();
  24          $xml2 = $this->get_xml($files);
  25          foreach($xml2->item as $item) foreach($item as $k => $v) $this->{$k}[] = (string) $v;
  26          unset($xml, $xml2);
  27      }
  28  
  29  	function get_text( $text, $width = false)
  30      {
  31          if (empty($text)) return $text;
  32  
  33          if (false === $width)    $width = $this->width;
  34  
  35          switch ($this->debug)
  36          {
  37              case 1 :
  38                  foreach($this->s as $k => $v)
  39                  {
  40                      $debug_text = preg_replace( $this->s[$k], $this->r[$k], $text, -1, $count) ;
  41                      if ( $count ) file_put_contents($this->path . "_gen_repl_.txt" , "\n$@$ | $k | ($count) | {$this->s[$k]} | {$this->r[$k]} |\n\n**before** | $text \n\n**after ** | $debug_text \n", FILE_APPEND);
  42                      $text = $debug_text;
  43                  }
  44              break;
  45              case 2 :
  46                  echo '<div><table>';
  47                  foreach($this->s as $k => $v)
  48                  {
  49                      $debug_text = preg_replace( $this->s[$k], $this->r[$k], $text, -1, $count) ;
  50                      if ( $count ) echo "<tr><td>$@$<b>$k</b> ($count)</td><td><b>" . htmlentities($this->s[$k]) . "</b><td><b>" . htmlentities($this->r[$k]) . "</b></td></tr><tr><td colspan='3'>" . wp_text_diff( $text, $debug_text ) . "<br /><hr /></td></tr>"; 
  51                      flush();
  52                      $text = $debug_text;
  53                  }
  54                  echo '</table></div>';
  55              break;
  56              default :
  57                  $text = preg_replace($this->s, $this->r, $text);
  58              break;
  59          }
  60  
  61          $text = ($width) ? wordwrap($text, $width) : $text;
  62  
  63          if ($this->debug) file_put_contents($this->path . '_gen_text.txt' , $text, FILE_APPEND);
  64  
  65          return $text;
  66      }
  67  
  68  // get xml file
  69  
  70  	function get_xml( $files = false )
  71      {
  72          if (!is_array($files)) $files = array($files);
  73  
  74          $x = '';
  75          foreach($files as $file)
  76          {
  77              if (!is_file($this->path . "$file.xml")) continue;
  78              ob_start();
  79                  include( $this->path . "$file.xml" );
  80                  $x .= trim(ob_get_contents());
  81              ob_end_clean();
  82          }
  83          $x = '<?xml version="1.0" encoding="UTF-8"?><mailpress>' . $x . '</mailpress>';
  84  
  85          if ($this->debug) file_put_contents($this->path . '_gen_xml_.txt', $x, FILE_APPEND);
  86  
  87          return simplexml_load_string( $x, 'SimpleXMLElement', LIBXML_NOCDATA );
  88      }
  89  }


Generated: Thu Apr 28 18:38:52 2016 Cross-referenced by PHPXref 0.7.1