Documentation TYPO3 par Ameos

wapversionLib.inc

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 ***************************************************************/
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;              // The backReference to the mother cObj object set at call time
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                         // Creating top level object
00150                 $xmlObj->WAPHeader();
00151 
00152                         // Creating back button:
00153                 $xmlObj->WAPback();
00154 
00155                 $pageRec = $GLOBALS['TSFE']->page;
00156                 if ($GLOBALS['TSFE']->idParts[1])       {
00157                                 // Creating content card:
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                                 // Creating menu card:
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                         // Footer
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                                 // Header:
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                                 // Bodytext:
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);        // No & in WAP docs??? --> or maybe just htmlspecialchar() things as the LAST thing instead!)
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                         // Hierarchy menu
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                         // Current page menu:
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 // AND HERE just some debugging content: Basically a valid WML deck.
00435 
00436                 /*
00437 switch($id)     {
00438         case 1:
00439                 <wml>
00440                         <card id="Hallo" ontimer="#Login" title="wapportal.dk">
00441                                 <timer value="35"/>
00442                                 <p>
00443                                         <img src="/images/logo.wbmp" alt="WAPPORTAL"/>
00444                                         asf asdf asdf
00445                                 </p>
00446                         </card>
00447                         <card id="Login" title="wapportal.dk" newcontext="true">
00448                                 <p>Mobil nr:
00449                                         <input name="Login" title="Mobil nr:" value="" format="*N" size="15"/>Kodeord:
00450                                         <input name="Passwd" title="Kodeord:" value="" type="password" format="*N" size="12"/>
00451                                         <anchor>Login !<go href="/wap/portal/DeckPortal/menu.wml?sid=FGBNRru&amp;rnd=107915&amp;login=$(Login:u)&amp;pwd=$(Passwd:u)"/></anchor>
00452                                         <br/>
00453                                         <anchor>G&#xe6;st<go href="/wap/portal/DeckPortal/menu.wml?sid=FGBNRru&amp;rnd=107916&amp;login=visitor&amp;pwd=visitor"></go></anchor>
00454                                 </p>
00455                         </card>
00456                 </wml>
00457         break;
00458         default:
00459                 <wml>
00460                 <template>
00461                         <do type="accept" label="Back"><prev/></do>
00462                 </template>
00463                 <card id="index1" title="Hovedside">
00464                         <p>Hej Kasper.
00465                         Dette er noget
00466                         <img src="/images/logo.wbmp" alt="WAPPORTAL"/>
00467                          tekst.</p>
00468 
00469                 </card>
00470                 </wml>
00471         break;
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 ?>


Généré par TYPO3 Ameos avec  doxygen 1.4.6