Antwort
 
LinkBack (1) Themen-Optionen Thema durchsuchen Thema bewerten Ansicht
  #1  
Alt 19.11.05, 12:31
Benutzerbild von mic_jan
TYPO3 Forum Team
Administrator
 
Registriert seit: 05.09.04
Ort: Köln
Beiträge: 1.401
Direct_Mail und tt_news/ eigene lib mit Fehler

Hi,

ich weiss, es ist ein sehr kryptischer Threadtitel, aber ich erkläre das mal.

Ich möchte gerne DirectMail in Verbindung mit tt_news benutzen. Das einzige Problem macht da die Plaintext-Version.

Also da die PlaintextLib tt_news erstmal nicht unterstützt, habe ich diesen Code aus dem www.typo3forum.de genommen:
PHP-Code:
<?php
/***************************************************************
* Copyright notice
*
* (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* Generating plain text content of content elements for Direct Mails
*
* $Id: plaintextLib.inc,v 1.9 2005/04/01 14:37:15 typo3 Exp $
* Revised for TYPO3 3.6 June/2003 by Kasper Skaarhoj
*
* @author Kasper Skaarhoj <kasperyyyy@typo3.com>
*/
/**
* [CLASS/FUNCTION INDEX of SCRIPT]
*
*
*
* 123: class user_plaintext
* 137: function main_plaintext($content,$conf)
* 209: function getMenuSitemap()
* 220: function getShortcut()
* 231: function getHTML($str=array())
* 241: function getHeader()
* 251: function getImages()
* 262: function parseBody($str)
* 284: function renderUploads($str,$upload_path='uploads/media/')
* 302: function renderHeader($str,$type=0)
* 353: function pad($lines,$preLineChar,$len)
* 369: function breakContent($str)
* 385: function breakBulletlist($str)
* 416: function breakTable($str)
* 472: function addDiv($messure,$content,$divChar,$joinChar,$cols)
* 488: function traverseTable($tableLines)
* 515: function renderImages($str,$links,$caption,$upload_path='uploads/pics/')
* 554: function getLink($ll)
* 571: function breakLines($str,$implChar="\n",$charWidth=0)
* 583: function getString($str)
* 595: function userProcess($mConfKey,$passVar)
* 613: function atag_to_http($content,$conf)
* 632: function typolist($content,$conf)
* 647: function typohead($content,$conf)
* 666: function typocode($content,$conf)
*
* TOTAL FUNCTIONS: 24
* (This index is automatically created/updated by the extension "extdeveval")
*
*/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/**
* Alternative rendering of content elements for Plain Text emails. That means text-only output. No HTML at all. Used by the Direct Mail extension.
* Normally the plain text output should appear with type=99.
* To use this library you can include the static template "plugin.alt.plaintext"
*
* ## Insert DMailer Boundaries for all elements.
* config.insertDmailerBoundaries = 1
* includeLibs.plaintextLib = media/scripts/plaintextLib.inc
*
* ## Set up page/type number:
* alt_plaintext >
* alt_plaintext = PAGE
* alt_plaintext.typeNum=99
* alt_plaintext.config.disableAllHeaderCode = 1
* alt_plaintext.10 = TEMPLATE
* alt_plaintext.10 {
* template = FILE
* template.file = {$plugin.alt.plaintext.file.template}
* marks.CONTENT < styles.content.get
* marks.CONTENT.renderObj = < lib.alt_plaintext.renderObj
* marks.DATE = TEXT
* marks.DATE.data = date:U
* marks.DATE.strftime = %e. %B %Y
* }
*
* (And then also "lib.alt_plaintext.renderObj" is configured extensively - basically with the TypoScript options passed to this class. See the static template "plugin.alt.plaintext")
*
* @author Kasper Skaarhoj <kasperyyyy@typo3.com>
* @package TYPO3
* @subpackage tslib
* @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=398&cHash=e3024de334
*/
 
 
 
class user_plaintext {
var 
$cObj;
var 
$conf=array();
var 
$charWidth=76;
 
/**
* Main function, called from TypoScript
* A content object that renders "tt_content" records. See the comment to this class for TypoScript example of how to trigger it.
* This detects the CType of the current content element and renders it accordingly. Only wellknown types are rendered.
*
* @param string Empty, ignore.
* @param array TypoScript properties for this content object/function call
* @return string Plain text content
*/
function main_plaintext($content,$conf) {
$this->pi_initPIflexForm();
$this->conf $conf;
$this->siteUrl=$conf['siteUrl'];
$lines = array();
$CType= (string)$this->cObj->data['CType'];
switch(
$CType) {
case 
'header':
$lines[]=$this->getHeader();
if (
$this->cObj->data['subheader']) {
$lines[]=$this->breakContent(strip_tags($this->cObj->data['subheader']));
}
break;
case 
'text':
$lines[]=$this->getHeader();
$lines[]=$this->breakContent(strip_tags($this->parseBody($this->cObj->data['bodytext'])));
break;
case 
'textpic':
$lines[]=$this->getHeader();
if (
$CType=='textpic' && !($this->cObj->data['imageorient']&24)) {
$lines[]=$this->getImages();
$lines[]='';
}
$lines[]=$this->breakContent(strip_tags($this->parseBody($this->cObj->data['bodytext'])));
if (
$CType=='textpic' && ($this->cObj->data['imageorient']&24)) {
$lines[]='';
$lines[]=$this->getImages();
}
break;
case 
'image':
$lines[]=$this->getHeader();
$lines[]=$this->getImages();
break;
case 
'uploads':
$lines[]=$this->getHeader();
$lines[]=$this->renderUploads($this->cObj->data['media']);
break;
case 
'menu':
$lines[]=$this->getHeader();
$lines[]=$this->getMenuSitemap();
break;
case 
'shortcut':
$lines[]=$this->getShortcut();
break;
case 
'bullets':
$lines[]=$this->getHeader();
$lines[]=$this->breakBulletlist(strip_tags($this->parseBody($this->cObj->data['bodytext'])));
break;
case 
'table':
$lines[]=$this->getHeader();
$lines[]=$this->breakTable(strip_tags($this->parseBody($this->cObj->data['bodytext'])));
break;
case 
'html':
$lines[]=$this->getHTML();
break;
case 
'list':
if(
$this->cObj->data["list_type"]==9){// 9 = tt_news
$lines[]=$this->getHeader();
$lines[]=$this->getNews();
}
if(
$this->cObj->data["list_type"]=="jw_calendar_pi1"){
$lines[]=$this->getHeader();
$lines[]=$this->getJWCalendar();
}
break;
default:
$defaultOutput $this->getString($this->conf['defaultOutput']);
if (
$defaultOutput) {
$lines[]=str_replace('###CType###',$CType,$defaultOutput);
}
break;
}
 
$lines[]=''// First break.
$content implode(chr(10),$lines);
 
// User processing:
$content=$this->userProcess('userProc',$content);
return 
$content;
}
 
 
/*******************************
*
* FlexForms related functions
*
*******************************/
 
/**
* Converts $this->cObj->data['pi_flexform'] from XML string to flexForm array.
*
* @return void
*/
function pi_initPIflexForm() {
// Converting flexform data into array:
if (!is_array($this->cObj->data['pi_flexform']) && $this->cObj->data['pi_flexform']) {
$this->cObj->data['pi_flexform'] = t3lib_div::xml2array($this->cObj->data['pi_flexform']);
if (!
is_array($this->cObj->data['pi_flexform'])) $this->cObj->data['pi_flexform']=array();
}
}
 
/**
* Return value from somewhere inside a FlexForm structure
*
* @param array FlexForm data
* @param string Field name to extract. Can be given like "test/el/2/test/el/field_templateObject" where each part will dig a level deeper in the FlexForm data.
* @param string Sheet pointer, eg. "sDEF"
* @param string Language pointer, eg. "lDEF"
* @param string Value pointer, eg. "vDEF"
* @return string The content.
*/
function pi_getFFvalue($T3FlexForm_array,$fieldName,$sheet='sDEF',$lang='lDEF',$value='vDEF') {
$sheetArray is_array($T3FlexForm_array) ? $T3FlexForm_array['data'][$sheet][$lang] : '';
 
if (
is_array($sheetArray)) {
return 
$this->pi_getFFvalueFromSheetArray($sheetArray,explode('/',$fieldName),$value);
}
}
 
/**
* Returns part of $sheetArray pointed to by the keys in $fieldNameArray
*
* @param array Multidimensiona array, typically FlexForm contents
* @param array Array where each value points to a key in the FlexForms content - the input array will have the value returned pointed to by these keys. All integer keys will not take their integer counterparts, but rather traverse the current position in the array an return element number X (whether this is right behavior is not settled yet...)
* @param string Value for outermost key, typ. "vDEF" depending on language.
* @return mixed The value, typ. string.
* @access private
* @see pi_getFFvalue()
*/
function pi_getFFvalueFromSheetArray($sheetArray,$fieldNameArr,$value) {
 
$tempArr=$sheetArray;
foreach(
$fieldNameArr as $k => $v) {
if (
t3lib_div::testInt($v)) {
if (
is_array($tempArr)) {
$c=0;
foreach(
$tempArr as $values) {
if (
$c==$v) {
#debug($values);
$tempArr=$values;
break;
}
$c++;
}
}
} else {
$tempArr $tempArr[$v];
}
}
return 
$tempArr[$value];
}
 
 
/**
* Creates tt_news depending on type "LATEST" or "LIST"
*
* @return string Content
*/
function getJWCalendar(){
 
$cat$this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'categorySelection','sDEF');
$mode$this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'viewmode','sDEF');
 
if(!
$mode){
$content="No or wrong jw_calendar mode";
}
else{
$where_clause='event.hidden = 0 AND event.deleted = 0';
if(
$cat)$where_clause.=' AND event.category = '.$cat;
$where_clause.=' AND event.location_id=location.uid AND event.organizer_id=organizer.uid';
 
if(
$mode=='LIST'){
$twoweeksago=time()-(14*24*3600);
$where_clause.=' AND event.begin >='.$twoweeksago;
}
 
$res$GLOBALS['TYPO3_DB']->exec_SELECTquery('event.title,event.teaser,event.description,event.begin,event.end,location.location,location.name,location.zip,location.street,location.city,location.phone,location.email,organizer.name AS o_name,organizer.phone AS o_phone,organizer.email AS o_email','tx_jwcalendar_events AS event,tx_jwcalendar_location AS location,tx_jwcalendar_organizer AS organizer',$where_clause,$groupBy='',$orderBy='begin DESC',$limit);
 
while (
$row $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$content.=$this->breakContent(html_entity_decode($row[title])).chr(10).chr(10);
$content.=$this->breakContent(html_entity_decode($row[teaser])).chr(10).chr(10);
$content.=$this->breakContent(html_entity_decode($row[description])).chr(10).chr(10);
$content.='Beginn: ';
$content.=strftime("%A, %d.%m.%Y %H:%M",$row[begin]).chr(10);
$content.='Ende : ';
$content.=strftime("%A, %d.%m.%Y %H:%M",$row[end]).chr(10).chr(10);
$content.='Ort: '.chr(10);
$content.=$row[location].chr(10);
$content.=$row[street].chr(10);
$content.=$row[zip].' ';
$content.=$row[city].chr(10);
$content.='Tel.: '.$row[phone].chr(10);
$content.='Email: '.$row[email].chr(10).chr(10);
$content.='Veranstalter: '.chr(10);
$content.=$row[o_name].chr(10);
$content.='Tel.: '.$row[o_phone].chr(10);
$content.='Email: '.$row[o_email].chr(10).chr(10);
$content.='----------------------------------------------------------------------------'.chr(10);
}
if(!
$content)$content='Keine Termine jünger als 14 Tage!';
}
 
return 
$content;
}
 
 
/**
* Creates tt_news depending on type "LATEST" or "LIST"
*
* @return string Content
*/
function getNews(){
 
$cat$this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'categorySelection','sDEF');
$mode$this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'what_to_display','sDEF');
 
if(!
$mode){
$content="No or wrong tt_news mode";
}
else{
 
$where_clause='news.hidden = 0 AND cat.uid_foreign = '.$cat.' AND cat.uid_local = news.uid';
if(
$mode=='LATEST')$limit='1';
if(
$mode=='LIST'){
$limit='1,10';
$twoweeksago=time()-(14*24*3600);
$where_clause.=' AND news.datetime >='.$twoweeksago;
}
$res
$GLOBALS['TYPO3_DB']->exec_SELECTquery('news.title,news.bodytext,news.datetime','tt_news AS news,tt_news_cat_mm AS cat',$where_clause,$groupBy='',$orderBy='news.datetime DESC',$limit);
while (
$row $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$content.=strftime("%A, %d.%m.%Y %H:%M",$row[datetime]).chr(10);
$content.=$this->breakContent(html_entity_decode($row[title])).chr(10).chr(10);
$content.=$this->breakContent(html_entity_decode($row[bodytext])).chr(10);
$content.='----------------------------------------------------------------------------'.chr(10);
}
if(!
$content)$content='Keine weiteren Meldungen jünger als 14 Tage!';
}
 
return 
$content;
}
 
/**
* Creates a menu/sitemap
*
* @return string Content
*/
function getMenuSitemap() {
$str $this->cObj->cObjGetSingle($this->conf['menu'],$this->conf['menu.']);
$str $this->breakBulletlist(trim(strip_tags(eregi_replace('<br[>',chr(10),$this->parseBody($str)))));
return 
$str;
}
 
/**
* Creates a shortcut ("Insert Records")
*
* @return string Content
*/
function getShortcut() {
$str $this->cObj->cObjGetSingle($this->conf['shortcut'],$this->conf['shortcut.']);
return 
$str;
}
 
/**
* Creates an HTML element (stripping tags of course)
*
* @param string HTML content to process. If not passed along, the bodytext field is used.
* @return string Content
*/
function getHTML($str=array()) {
return 
$this->breakContent(strip_tags(eregi_replace('<br[>',chr(10),$this->parseBody(is_string($str)?$str:$this->cObj->data['bodytext']))));
}
 
/**
* Creates a header (used for most elements)
*
* @return string Content
* @see renderHeader()
*/
function getHeader() {
// links...
return $this->renderHeader($this->cObj->data['header'],$this->cObj->data['header_layout']);
}
 
/**
* Get images found in the "image" field of "tt_content"
*
* @return string Content
*/
function getImages() {
$images $this->renderImages($this->cObj->data['image'],!$this->cObj->data['image_zoom']?$this->cObj->data['image_link']:'',$this->cObj->data['imagecaption']);
return 
$images;
}
 
/**
* Parsing the bodytext field content, removing typical entities and tags.
*
* @param string Field content from "bodytext"
* @return string Processed content
*/
function parseBody($str) {
// First, regular parsing:
$str eregi_replace('<br>',' ',$str);
$str $this->cObj->stdWrap($str,$this->conf['bodytext.']['stdWrap.']);
// Then all a-tags:
$aConf = array();
$aConf['parseFunc.']['tags.']['a']='USER';
$aConf['parseFunc.']['tags.']['a.']['userFunc']='user_plaintext->atag_to_http';
$aConf['parseFunc.']['tags.']['a.']['siteUrl'] = $this->siteUrl;
 
$str $this->cObj->stdWrap($str,$aConf);
$str str_replace(' ',' ',t3lib_div::htmlspecialchars_decode($str));
return 
$str;
}
 
/**
* Creates a list of links to uploaded files.
*
* @param string List of uploaded filenames from "uploads/media/" (or $upload_path)
* @param string Alternative path value
* @return string Content
*/
function renderUploads($str,$upload_path='uploads/media/') {
$files explode(',',$str);
reset($files);
$lines=array();
if (
$this->conf['uploads.']['header']) {$lines[]=$this->getString($this->conf['uploads.']['header']);}
while(list(
$k,$file)=each($files)) {
$lines[]=$this->siteUrl.$upload_path.$file;
}
return 
implode(chr(10),$lines);
}
 
/**
* Renders a content element header, observing the layout type giving different header formattings
*
* @param string The header string
* @param integer The layout type of the header (in the content element)
* @return string Content
*/
function renderHeader($str,$type=0) {
if (
$str) {
$hConf $this->conf['header.'];
$defaultType t3lib_div::intInRange($hConf['defaultType'],1,5);
$type=t3lib_div::intInRange($type,0,6);
if (!
$type$type=$defaultType;
if (
$type!=6) { // not hidden
$tConf $hConf[$type.'.'];
 
$lines=array();
 
$blanks t3lib_div::intInRange($tConf['preBlanks'],0,1000);
if (
$blanks) {
$lines[]=str_pad(''$blanks-1chr(10));
}
 
$lines=$this->pad($lines,$tConf['preLineChar'],$tConf['preLineLen']);
 
$blanks t3lib_div::intInRange($tConf['preLineBlanks'],0,1000);
if (
$blanks) {$lines[]=str_pad(''$blanks-1chr(10));}
 
if (
$this->cObj->data['date']) {$lines[] = $this->getString($hConf['datePrefix']).date($hConf['date']?$hConf['date']:'d-m-Y',$this->cObj->data['date']);}
$prefix='';
$str=$this->getString($tConf['prefix']).$str;
if (
$tConf['autonumber']) $str=$this->cObj->parentRecordNumber.$str;
if (
$this->cObj->data['header_position']=='right') {$prefix=str_pad(' ',($this->charWidth-strlen($str)));}
if (
$this->cObj->data['header_position']=='center') {$prefix=str_pad(' ',floor(($this->charWidth-strlen($str))/2));}
$lines[]=$this->cObj->stdWrap($prefix.$str,$tConf['stdWrap.']);
if (
$this->cObj->data['header_link']) {$lines[] = $this->getString($hConf['linkPrefix']).$this->getLink($this->cObj->data['header_link']);}
 
$blanks t3lib_div::intInRange($tConf['postLineBlanks'],0,1000);
if (
$blanks) {$lines[]=str_pad(''$blanks-1chr(10));}
 
$lines=$this->pad($lines,$tConf['postLineChar'],$tConf['postLineLen']);
 
$blanks t3lib_div::intInRange($tConf['postBlanks'],0,1000);
if (
$blanks) {$lines[]=str_pad(''$blanks-1chr(10));}
return 
implode(chr(10),$lines);
}
}
}
 
/**
* Function used to repeat a char pattern in head lines (like if you want "********" above/below a header)
*
* @param array Array of existing lines to which the new char-pattern should be added
* @param string The character pattern to repeat. Default is "-"
* @param integer The length of the line. $preLineChar will be repeated to fill in this length.
* @return array The input array with a new line added.
* @see renderHeader()
*/
function pad($lines,$preLineChar,$len) {
$strPad t3lib_div::intInRange($len,0,1000);
$strPadChar $preLineChar?$preLineChar:'-';
if (
$strPad) {
$lines[]=str_pad(''$strPad$strPadChar);
}
return 
$lines;
}
 
/**
* Function used to wrap the bodytext field content (or image caption) into lines of a max length of
*
* @param string The content to break
* @return string Processed value.
* @see main_plaintext(), breakLines()
*/
function breakContent($str) {
$cParts explode(chr(10),$str);
reset($cParts);
$lines=array();
while(list(,
$substrs)=each($cParts)) {
$lines[]=$this->breakLines($substrs);
}
return 
implode(chr(10),$lines);
}
 
/**
* Breaks content lines into a bullet list
*
* @param string Content string to make into a bullet list
* @return string Processed value
*/
function breakBulletlist($str) {
$type $this->cObj->data['layout'];
$type=t3lib_div::intInRange($type,0,3);
 
$tConf $this->conf['bulletlist.'][$type.'.'];
 
$cParts explode(chr(10),$str);
reset($cParts);
$lines=array();
$c=0;
while(list(,
$substrs)=each($cParts)) {
$c++;
$bullet $tConf['bullet'] ? $this->getString($tConf['bullet']) : ' - ';
$bLen=strlen($bullet);
$bullet substr(str_replace('#',$c,$bullet),0,$bLen);
$secondRow substr($tConf['secondRow']?$this->getString($tConf['secondRow']:sad:str_pad('',strlen($bullet),' '),0,$bLen);
 
$lines[]=$bullet.$this->breakLines($substrs,chr(10).$secondRow,$this->charWidth-$bLen);
 
$blanks t3lib_div::intInRange($tConf['blanks'],0,1000);
if (
$blanks) {$lines[]=str_pad(''$blanks-1chr(10));}
}
return 
implode(chr(10),$lines);
}
 
/**
* Formatting a table in plain text (based on the paradigm of lines being content rows and cells separated by "|")
*
* @param string Content string
* @return string Processed value
*/
function breakTable($str) {
$cParts explode(chr(10),$str);
reset($cParts);
$lines=array();
$cols intval($this->conf['cols']) ? intval($this->conf['cols']) : ;
$c=0;
while(list(,
$substrs)=each($cParts)) {
$c++;
if (
trim($substrs)) {
$lineParts=explode('|',$substrs);
if (!
$cols$cols=count($lineParts);
 
for (
$a=0;$a<$cols;$a++) {
$jdu explode(chr(10),$this->breakLines($lineParts[$a],chr(10),ceil($this->charWidth/$cols)));
$lines[$c][$a]=$jdu;
}
}
}
$messure $this->traverseTable($lines);
 
 
$divChar='-';
$joinChar='+';
$colChar='|';
 
// Make table:
$outLines = array();
$outLines[]=$this->addDiv($messure,'',$divChar,$joinChar,$cols);
 
reset($lines);
while(list(
$k,$v)=each($lines)) {
$top intval($messure[1][$k]);
for (
$aa=0;$aa<$top;$aa++) {
$tempArr=array();
for (
$bb=0;