Documentation TYPO3 par Ameos |
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 1999-2004 Kasper Skaarhoj (kasperYYYY@typo3.com) 00006 * All rights reserved 00007 * 00008 * This script is part of the TYPO3 project. The TYPO3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * A copy is found in the textfile GPL.txt and important notices to the license 00017 * from the author is found in LICENSE.txt distributed with these scripts. 00018 * 00019 * 00020 * This script is distributed in the hope that it will be useful, 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 * GNU General Public License for more details. 00024 * 00025 * This copyright notice MUST APPEAR in all copies of the script! 00026 ***************************************************************/ 00031 require_once(PATH_t3lib."class.t3lib_extobjbase.php"); 00032 00033 class tx_cmsplaintextimport_webfunc extends t3lib_extobjbase { 00034 function modMenu() { 00035 return array ( 00036 "import_function" => array( 00037 0 => "[ SELECT TYPE ]", 00038 "txt" => "Import Plain Text", 00039 ), 00040 "import_txt_format" => array( 00041 0 => "Plain", 00042 1 => htmlspecialchars("---new_page---/---new_section---") 00043 ), 00044 "import_source" => array( 00045 "direct" => "Direct Input" 00046 ), 00047 "import_txt_trimWhiteSpace" => "", 00048 ); 00049 } 00050 function main() { 00051 global $SOBE,$BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS; 00052 00053 $extension = $this->pObj->MOD_SETTINGS["import_function"]; 00054 $sourceData = t3lib_div::_GP("directInput"); 00055 if (strcmp(trim($sourceData),"")) { 00056 $theData = Array(); 00057 switch($this->pObj->MOD_SETTINGS["import_txt_format"]) { 00058 case 0: 00059 if ($this->pObj->MOD_SETTINGS["import_txt_trimWhiteSpace"]) {$sourceData = trim($sourceData);} 00060 $pageKey=$this->pObj->id; 00061 $theData[$pageKey][uniqid("NEW")]["bodytext"]=$sourceData; 00062 break; 00063 case 1: 00064 $pages = split(sql_regcase("---new_page---"), $sourceData); 00065 00066 while(list($theKey,$theVal)=each($pages)) { 00067 if (trim($theVal)) { 00068 if ($theKey) { // If $theKey, then it's a new page. Otherwise it's the current page 00069 $pageKey = uniqid("NEW"); 00070 } else { 00071 $pageKey=$this->pObj->id; 00072 } 00073 $sections = split(sql_regcase("---new_section---"), $theVal); 00074 // debug($sections); 00075 while(list($c,$theContent)=each($sections)) { 00076 $secId = uniqid("NEW"); 00077 $theContent=$this->cleanEnds($theContent); 00078 if ($this->pObj->MOD_SETTINGS["import_txt_trimWhiteSpace"]) {$theContent = trim($theContent);} 00079 if ($theKey && !$c) { // A new page-header is created. 00080 $parts = split(chr(10),$theContent,3); 00081 $theData[$pageKey]["title"]=trim($parts[0]) ? trim($parts[0]) : "[NO TITLE]"; 00082 $theData[$pageKey]["subtitle"]=trim($parts[1]); 00083 // If there are more than the two lines, then a new section is created by setting the content-var again 00084 if (trim($parts[2])) { 00085 $theContent= $this->pObj->MOD_SETTINGS["import_txt_trimWhiteSpace"] ? trim($parts[2]) : $parts[2]; 00086 $theContent= chr(10).$theContent; // The header is set to "" by adding a single linebreak... 00087 } else { 00088 $theContent=""; 00089 } 00090 } 00091 if (trim($theContent)) { 00092 $parts = split(chr(10),$theContent,2); 00093 // If the first line is longer than (80) chars, then it's regarded a part of the content. 00094 if (strlen($parts[0])>80) { 00095 $parts[1]=$parts[0].chr(10).$parts[1]; 00096 $parts[0]=""; 00097 } 00098 // Prepends "http://" and "mailto:" to all webadresses starting with www and all email-adresses. 00099 $parts[1]=" ".$parts[1]; // Add space in the beginning (because of the regexes... 00100 $parts[1]=ereg_replace("([ ".chr(10).chr(13)."])(".sql_regcase("www")."\.)","\\1http://\\2",$parts[1]); 00101 $parts[1]=ereg_replace("([ ".chr(10).chr(13)."])([^ ]*@)","\\1mailto:\\2",$parts[1]); 00102 $parts[1]=substr($parts[1],1); // Strip the space in the beginning. 00103 // If a paragraph starts with "-" then it's regarded as a quote and set in italics 00104 $lines = explode(chr(10),$parts[1]); 00105 while(list($a,$b)=each($lines)) { 00106 if (substr(trim($b),0,1)=="-") { 00107 $lines[$a]='<i>'.$lines[$a].'</i>'; 00108 } 00109 } 00110 $parts[1]=implode($lines,chr(10)); 00111 // putting the content 00112 $theData[$pageKey][$secId]["header"]=$parts[0]; 00113 $theData[$pageKey][$secId]["bodytext"]=$parts[1]; 00114 } 00115 } 00116 } 00117 } 00118 break; 00119 } 00120 00121 $output = ""; 00122 reset($theData); 00123 while(list($key,$val)=each($theData)) { 00124 $output.="<HR><b>PAGE: ".$key."</b><BR>"; 00125 if (!t3lib_div::testInt($key)) { 00126 $output.='<input type="hidden" name="data[pages]['.$key.'][pid]" value="'.$this->pObj->pageinfo["uid"].'">'; 00127 $output.='<input type="hidden" name="data[pages]['.$key.'][hidden]" value="0">'; 00128 $output.='Title:<BR><input type="text" size=50 name="data[pages]['.$key.'][title]" value="'.htmlspecialchars($val["title"]).'"><BR>'; 00129 $output.='Subtitle:<BR><input type="text"'.$GLOBALS["TBE_TEMPLATE"]->formWidth().' name="data[pages]['.$key.'][subtitle]" value="'.htmlspecialchars($val["subtitle"]).'"><BR>'; 00130 } 00131 while(list($theSectionKey,$theSectionVal)=each($val)) { 00132 if (strstr($theSectionKey,"NEW")) { 00133 $output.='<input type="hidden" name="data[tt_content]['.$theSectionKey.'][pid]" value="'.$key.'">'; 00134 $output.='Header:<BR><input type="text"'.$GLOBALS["TBE_TEMPLATE"]->formWidth().' name="data[tt_content]['.$theSectionKey.'][header]" value="'.htmlspecialchars($theSectionVal["header"]).'"><BR>'; 00135 $output.='Bodytext:<BR><textarea'.$GLOBALS["TBE_TEMPLATE"]->formWidthText().' rows=6 name="data[tt_content]['.$theSectionKey.'][bodytext]">'.t3lib_div::formatForTextarea($theSectionVal["bodytext"]).'</textarea><BR>'; 00136 } 00137 } 00138 } 00139 00140 $output='</form><form action="'.$BACK_PATH.'tce_db.php" method="POST" name="editform">'.$output; 00141 $output.='<input type="Submit" name="submit" value="SAVE"><input type="hidden" name="flags[reverseOrder]" value="1">'; 00142 $output.='<input type="Hidden" name="redirect" value="'.htmlspecialchars(t3lib_div::linkThisUrl(t3lib_div::getIndpEnv("REQUEST_URI"),array("id"=>$this->pObj->id))).'">'; 00143 $output.=' <input type="Submit" value="Abort" onClick="jumpToUrl(\'index.php?id='.$this->pObj->id.'\'); return false;">'; 00144 00145 $theOutput.=$this->pObj->doc->section("Edit:",$output); 00146 } else { 00147 if (!$extension) $extension="txt"; 00148 switch($extension) { 00149 case "txt": 00150 $Nmenu=array(); 00151 $Nmenu[]= array(fw("Format:"), t3lib_BEfunc::getFuncMenu($this->pObj->id,"SET[import_txt_format]",$this->pObj->MOD_SETTINGS["import_txt_format"],$this->pObj->MOD_MENU["import_txt_format"])); 00152 00153 $Nmenu[]= array(fw("Trim whitespace:"),t3lib_BEfunc::getFuncCheck($this->pObj->id,"SET[import_txt_trimWhiteSpace]",$this->pObj->MOD_SETTINGS["import_txt_trimWhiteSpace"])); 00154 00155 $theOutput.=$this->pObj->doc->section("Select options:",$this->pObj->doc->menuTable($Nmenu)); 00156 $theOutput.=$this->pObj->doc->divider(5); 00157 break; 00158 default: 00159 $extension = ""; 00160 break; 00161 } 00162 if ($extension) { 00163 $Nmenu= "Source: ".t3lib_BEfunc::getFuncMenu($this->pObj->id,"SET[import_source]",$this->pObj->MOD_SETTINGS["import_source"],$this->pObj->MOD_MENU["import_source"]); 00164 $theOutput.=$this->pObj->doc->section("Select file source:",'<NOBR>'.$Nmenu.'</NOBR><BR><BR>'.$this->printMenu($this->pObj->MOD_SETTINGS["import_source"],$extension)); 00165 } 00166 } 00167 return $theOutput; 00168 } 00169 function cleanEnds($string) { 00170 $parts = explode(chr(10),$string); 00171 if (!trim($parts[(count($parts)-1)])) unset($parts[(count($parts)-1)]); 00172 if (!trim($parts[0])) unset($parts[0]); 00173 return implode($parts,chr(10)); 00174 } 00175 function printMenu($kind, $ext) { 00176 $content = ""; // If set, then this function returns content and not a menu 00177 00178 switch($kind) { 00179 case "direct": 00180 // Direct Input 00181 $output.= '<table border=0 cellpadding=0 cellspacing=0 width=460>'; 00182 $output.= '<tr><td class="bgColor5"><b>'.fw('Direct Input').'</b></td></tr>'; 00183 $output.= '<tr><td><textarea name="directInput"'.$this->pObj->doc->formWidthText().' rows=20 ></textarea><BR><input type="Submit" name="submit" value="Send Direct Input"></td></tr>'; 00184 $output.= '</table>'; 00185 break; 00186 } 00187 00188 return $output; 00189 } 00190 } 00191 00192 if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/cms_plaintext_import/class.tx_cmsplaintextimport_webfunc.php"]) { 00193 include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/cms_plaintext_import/class.tx_cmsplaintextimport_webfunc.php"]); 00194 } 00195 00196 ?>