00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00061 require_once (PATH_t3lib.'class.t3lib_xml.php');
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00129 class user_wapversion {
00130 var $cObj;
00131
00132 var $idx=0;
00133
00141 function main_wapversion($content,$conf) {
00142 $GLOBALS['TSFE']->set_no_cache();
00143
00144
00145 $className=t3lib_div::makeInstanceClassName('t3lib_xml');
00146 $xmlObj = new $className('wml');
00147 $xmlObj->XMLdebug=$conf['debug'];
00148
00149
00150 $xmlObj->WAPHeader();
00151
00152
00153 $xmlObj->WAPback();
00154
00155 $pageRec = $GLOBALS['TSFE']->page;
00156 if ($GLOBALS['TSFE']->idParts[1]) {
00157
00158 $xmlObj->newLevel('card',1,array(
00159 'id' => 'content',
00160 'title' => ($conf['preTitle']?$conf['preTitle'].': ':'').$pageRec['title']
00161 ));
00162
00163 $cParts = $this->contentAll();
00164 $pointer = t3lib_div::intInRange($GLOBALS['TSFE']->idParts[1],1,10000);
00165
00166 $msg='';
00167 if ($pointer-1) {$msg.=$this->navLink(htmlspecialchars($conf['navLabels.']['prev']),$pointer-1).' ';}
00168 $msg.=$this->navLink(htmlspecialchars($conf['navLabels.']['up']),0).' ';
00169 if ($pointer<count($cParts)) {$msg.=$this->navLink(htmlspecialchars($conf['navLabels.']['next']),$pointer+1).' ';}
00170 $msg.= '['.$pointer.'/'.count($cParts).']<br/>';
00171
00172 $xmlObj->lines[] = $this->paragraph($msg);
00173 $xmlObj->lines[] = $this->paragraph($cParts[$pointer-1]);
00174 $xmlObj->lines[] = $this->paragraph('<br/>'.$msg);
00175
00176 $xmlObj->newLevel('card',0);
00177 } else {
00178
00179 $xmlObj->newLevel('card',1,array(
00180 'id' => 'menu',
00181 'title' => ($conf['preTitle']?$conf['preTitle'].': ':'').$pageRec['title']
00182 ));
00183 $xmlObj->lines[] = $this->contentAbstract();
00184 $xmlObj->lines[] = '<p><br/>'.$this->bold('Menu:').'</p>';
00185 $xmlObj->lines[] = $this->menuCurrentLevel($xmlObj->Icode);
00186 $xmlObj->newLevel('card',0);
00187 }
00188
00189
00190 $xmlObj->renderFooter();
00191 return $xmlObj->getResult();
00192
00193 }
00194
00200 function contentAbstract() {
00201 $res = $this->getContentResult('tt_content');
00202 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
00203 $out = $this->bold(t3lib_div::fixed_lgd(htmlspecialchars($row['header']),20)).'<br/>';
00204 $out.= t3lib_div::fixed_lgd(htmlspecialchars($row['bodytext']),50);
00205 $out = '<p>'.$out.' <a href="'.htmlspecialchars('?id='.$GLOBALS['TSFE']->id.',1.'.$GLOBALS['TSFE']->type).'">[more]</a></p>';
00206 return $out;
00207 }
00208
00217 function contentAll($chunkLgd=850) {
00218 $res = $this->getContentResult('tt_content');
00219 $overlap=5;
00220 $idx=0;
00221 $out=array();
00222 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00223
00224 $get = '<br/>'.$this->cHeader($row['header']).'<br/>';
00225 if (strlen($out[$idx].$get)>$chunkLgd) {
00226 $idx++;
00227 }
00228 $out[$idx].=$get;
00229
00230 switch($row['CType']) {
00231 case 'text':
00232 case 'bullets':
00233 case 'table':
00234 $bodyText = $row['bodytext'];
00235 break;
00236 case 'textpic':
00237 case 'image':
00238 if ($row['CType']!='image') {$bodyText = $row['bodytext'];}
00239 $bodyText.= chr(10).'['.count(explode(',',$row['image'])).'images, caption: '.$row['imagecaption'].']';
00240 break;
00241 case 'header':
00242 $bodyText=$row['subheader'];
00243 break;
00244 default:
00245 $bodyText = '[Un-rendered element, '.$row['CType'].']';
00246 break;
00247 }
00248
00249
00250 $get = $this->cBodytext($bodyText).'<br/>';
00251 $diff = $chunkLgd - strlen($out[$idx]);
00252
00253 if ($diff>strlen($get)) {
00254 $out[$idx].=$get;
00255 } else {
00256 $out[$idx].=$this->cBodytext($bodyText,0,$diff+$overlap).'<br/>';
00257
00258 $safe=0;
00259 do {
00260 $idx++;
00261 $out[$idx].=$this->cBodytext($bodyText,$diff+($safe*$chunkLgd)-$overlap,$chunkLgd+$overlap).'<br/>';
00262 $safe++;
00263 if ($safe>100) break;
00264 } while (strlen($out[$idx])>$chunkLgd);
00265 }
00266 }
00267 return $out;
00268 }
00269
00277 function cHeader($str) {
00278 $out = $this->bold(htmlspecialchars(strip_tags($str)));
00279 return $out;
00280 }
00281
00291 function cBodytext($str,$start=0,$max=0) {
00292 $out = t3lib_div::fixed_lgd(($start?'...':'').substr($this->nl2br(htmlspecialchars(strip_tags($str))),$start),($max?$max:100000));
00293 $out = str_replace('&','',$out);
00294 return $out;
00295 }
00296
00303 function nl2br($str) {
00304 return ereg_replace(chr(10),'<br/>',$str);
00305 }
00306
00314 function getContentResult($table) {
00315 global $TCA;
00316 if ($TCA[$table]) {
00317 $orderBy = $TCA[$table]['ctrl']['sortby'] ? 'ORDER BY '.$TCA[$table]['ctrl']['sortby'] : $TCA[$table]['ctrl']['default_sortby'];
00318 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $table, 'pid='.intval($GLOBALS['TSFE']->id).$this->cObj->enableFields($table), '', $GLOBALS['TYPO3_DB']->stripOrderBy($orderBy));
00319 return $res;
00320 }
00321 }
00322
00329 function bold($str) {
00330 return strtoupper($str);
00331 }
00332
00339 function paragraph($str) {
00340 return '<p>'.$str.'</p>';
00341 }
00342
00349 function line($str) {
00350 return $str.'<br/>';
00351 }
00352
00360 function navLink($str,$pointer) {
00361 return '<a href="'.htmlspecialchars('?id='.$GLOBALS['TSFE']->id.','.$pointer.'.'.$GLOBALS['TSFE']->type).'">'.$str.'</a>';
00362 }
00363
00370 function menuCurrentLevel($indent) {
00371 $rL = $GLOBALS['TSFE']->config['rootLine'];
00372 reset($rL);
00373 $preSpace='';
00374 $out=array();
00375
00376 while(list($level,$data)=each($rL)) {
00377 $preSign = count($rL)-1 > $level ? '-' : '>';
00378 $menuItem = htmlspecialchars($preSign.' '.$data['title']);
00379 $menuItem = $this->link($preSpace.$menuItem,$data['uid']);
00380 $out[]=$indent.$this->line($menuItem);
00381 $preSpace.='..';
00382 }
00383
00384 $menu = $this->cleanMenuArray($GLOBALS['TSFE']->sys_page->getMenu($GLOBALS['TSFE']->id));
00385 reset($menu);
00386 while(list(,$data)=each($menu)) {
00387 $preSign = count($this->cleanMenuArray($GLOBALS['TSFE']->sys_page->getMenu($data['uid']))) ? '+' : '*';
00388 $menuItem = htmlspecialchars($preSign.' '.$data['title']);
00389 $menuItem = $this->link($preSpace.$menuItem,$data['uid']);
00390 $out[]=$indent.$this->line($menuItem);
00391 }
00392 return $this->paragraph(implode(chr(10),$out));
00393 }
00394
00405 function link($str,$id,$deck='') {
00406 if ($GLOBALS['TSFE']->id==$id && $deck) {
00407 $out = '<a href="#'.$deck.'">'.$str.'</a>';
00408 } else {
00409 $type = $GLOBALS['TSFE']->type;
00410 $out = '<a href="'.htmlspecialchars('?id='.$id.','.($GLOBALS['TSFE']->id==$id?1:$this->idx).'.'.$type).'">'.$str.'</a>';
00411 }
00412 return $out;
00413 }
00414
00421 function cleanMenuArray($menu) {
00422 reset($menu);
00423 $newMenu=array();
00424 while(list(,$data)=each($menu)) {
00425 if ($data['doktype']!=5 && !$data['nav_hide']) {
00426 $newMenu[]=$data;
00427 }
00428 }
00429 return $newMenu;
00430 }
00431 }
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['media/scripts/wapversionLib.inc']) {
00479 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['media/scripts/wapversionLib.inc']);
00480 }
00481
00482
00483 ?>