Documentation TYPO3 par Ameos

class.tx_ttguest.php

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 ***************************************************************/
00043 require_once(PATH_tslib."class.tslib_pibase.php");
00044 require_once(t3lib_extMgm::extPath('tt_guest').'pi/class.recordnavigator.php');
00045 
00046 
00047 class tx_ttguest extends tslib_pibase {
00048         var $cObj;              // The backReference to the mother cObj object set at call time
00049 
00050         var $enableFields ="";          // The enablefields of the tt_board table.
00051         var $dontParseContent=0;        
00052         
00053         var $orig_templateCode="";
00054 
00058         function main_guestbook($content,$conf) {
00059                 $this->conf = $conf;
00060 
00061                 $content="";
00062         
00063                 // *************************************
00064                 // *** getting configuration values:
00065                 // *************************************
00066                 $alternativeLayouts = intval($conf["alternatingLayouts"])>0 ? intval($conf["alternatingLayouts"]) : 2;
00067                         
00068                         // pid_list is the pid/list of pids from where to fetch the guest items.
00069                 $config["pid_list"] = trim($this->cObj->stdWrap($conf["pid_list"],$conf["pid_list."]));
00070                 $config["pid_list"] = $config["pid_list"] ? implode(t3lib_div::intExplode(",",$config["pid_list"]),",") : $GLOBALS["TSFE"]->id;
00071                 list($pid) = explode(",",$config["pid_list"]);
00072         
00073                         // "CODE" decides what is rendered:
00074                 $config["code"] = $this->cObj->stdWrap($conf["code"],$conf["code."]);
00075         
00076                         // template is read.
00077                 $this->orig_templateCode = $this->cObj->fileResource($conf["templateFile"]);
00078         
00079 
00080                         // globally substituted markers, fonts and colors.      
00081                 $splitMark = md5(microtime());
00082                 $globalMarkerArray=array();
00083                 list($globalMarkerArray["###GW1B###"],$globalMarkerArray["###GW1E###"]) = explode($splitMark,$this->cObj->stdWrap($splitMark,$conf["wrap1."]));
00084                 list($globalMarkerArray["###GW2B###"],$globalMarkerArray["###GW2E###"]) = explode($splitMark,$this->cObj->stdWrap($splitMark,$conf["wrap2."]));
00085                 $globalMarkerArray["###GC1###"] = $this->cObj->stdWrap($conf["color1"],$conf["color1."]);
00086                 $globalMarkerArray["###GC2###"] = $this->cObj->stdWrap($conf["color2"],$conf["color2."]);
00087                 $globalMarkerArray["###GC3###"] = $this->cObj->stdWrap($conf["color3"],$conf["color3."]);
00088 
00089                 $this->recordCount = $this->getRecordCount($pid);
00090                 $globalMarkerArray["###PREVNEXT###"] = $this->getPrevNext();
00091 
00092 
00093                         // Substitute Global Marker Array
00094                 $this->orig_templateCode= $this->cObj->substituteMarkerArray($this->orig_templateCode, $globalMarkerArray);
00095 
00096                         // If the current record should be displayed.
00097                 $config["displayCurrentRecord"] = $conf["displayCurrentRecord"];
00098                 if ($config["displayCurrentRecord"])    {
00099                         $config["code"]="GUESTBOOK";
00100                 }
00101                         
00102 
00103                 // *************************************
00104                 // *** doing the things...:
00105                 // *************************************
00106                 $this->init($this->cObj->enableFields("tt_guest"));
00107                 $this->dontParseContent = $conf["dontParseContent"];
00108                 $cObj =t3lib_div::makeInstance("tslib_cObj");   // Initiate new cObj, because we're loading the data-array
00109                 
00110                 $codes=t3lib_div::trimExplode(",", $config["code"]?$config["code"]:$conf["defaultCode"],1);
00111                 if (!count($codes))     $codes=array("");
00112                 while(list(,$theCode)=each($codes))     {
00113                         $theCode = (string)strtoupper(trim($theCode));
00114                         switch($theCode)        {
00115                                 case "POSTFORM":
00116                                         $lConf = $conf["postform."];
00117                                         $content.=$cObj->FORM($lConf);
00118                                 break;
00119                                 case "GUESTBOOK":
00120                                         $lConf=$conf;
00121                                 
00122                                         if (!$lConf["subpartMarker"])   {
00123                                                 $lConf["subpartMarker"]="TEMPLATE_GUESTBOOK";
00124                                         }
00125         
00126                                                 // Getting template subpart from file.
00127                                         $templateCode = $cObj->getSubpart($this->orig_templateCode, "###".$lConf["subpartMarker"]."###");
00128                                         if ($templateCode)      {
00129                                                         // Getting the specific parts of the template
00130                                                 $postHeader=$this->getLayouts($templateCode,$alternativeLayouts,"POST");
00131 
00132                                                         // Fetching the guest book item(s) to display:
00133                                                 if ($config["displayCurrentRecord"])    {
00134                                                         $recentPosts=array();
00135                                                         $recentPosts[] = $this->cObj->data;     
00136                                                 } else {
00137                                                         $recentPosts = $this->getItems($pid);
00138                                                 }
00139                                                         // Traverse the items and display them:
00140                                                 reset($recentPosts);
00141                                                 $c_post=0;
00142                                                 $subpartContent="";
00143                                                 while(list(,$recentPost)=each($recentPosts))    {
00144                                                                 // Passing data through stdWrap and into the markerArray
00145                                                         $cObj->start($recentPost);              // Set this->data to the current record tt_guest record.
00146                                                         $markerArray=array();
00147                                                         $markerArray["###POST_TITLE###"] = $cObj->stdWrap($this->formatStr($recentPost["title"]), $conf["title_stdWrap."]);
00148                                                         $markerArray["###POST_CONTENT###"] = $cObj->stdWrap($this->formatStr($recentPost["note"]), $conf["note_stdWrap."]);
00149                                                         $markerArray["###POST_AUTHOR###"] = $cObj->stdWrap($this->formatStr($recentPost["cr_name"]), $conf["author_stdWrap."]);
00150                                                         $markerArray["###POST_EMAIL###"] = $cObj->stdWrap($this->formatStr($recentPost["cr_email"]), $conf["email_stdWrap."]);
00151                                                         $markerArray["###POST_WWW###"] = $cObj->stdWrap($this->formatStr($recentPost["www"]), $conf["www_stdWrap."]);
00152                                                         $markerArray["###POST_DATE###"] = $cObj->stdWrap($recentPost["crdate"],$conf["date_stdWrap."]);
00153                                                         $markerArray["###POST_TIME###"] = $cObj->stdWrap($recentPost["crdate"],$conf["time_stdWrap."]);
00154                                                         $markerArray["###POST_AGE###"] = $cObj->stdWrap($recentPost["crdate"],$conf["age_stdWrap."]);
00155                                                                 // Substitute the markerArray in the proper template code (POST subparts, alternating)
00156                                                         $out=$postHeader[$c_post%count($postHeader)];
00157                                                         $c_post++;
00158                                                         $subpartContent.=$cObj->substituteMarkerArrayCached($out,$markerArray);
00159                                                 }
00160                                                 
00161                                                         // Total Substitution:
00162                                                 if ($lConf["requireRecords"] && !count($recentPosts))   {
00163                                                         $content.= "";
00164                                                 } else {
00165                                                         $content.= $cObj->substituteSubpart($templateCode,"###CONTENT###",$subpartContent) ;
00166                                                 }
00167                                         } else {
00168                                                 debug("No template code for the subpart maker ###".$lConf["subpartMarker"]."###"); 
00169                                         }
00170                         
00171                                 break;
00172                                 default:
00173                                         $langKey = strtoupper($GLOBALS["TSFE"]->config["config"]["language"]);
00174                                         $helpTemplate = $this->cObj->fileResource("EXT:tt_guest/pi/guest_help.tmpl");
00175 
00176                                                 // Get language version
00177                                         $helpTemplate_lang="";
00178                                         if ($langKey)   {$helpTemplate_lang = $this->cObj->getSubpart($helpTemplate,"###TEMPLATE_".$langKey."###");}
00179                                         $helpTemplate = $helpTemplate_lang ? $helpTemplate_lang : $this->cObj->getSubpart($helpTemplate,"###TEMPLATE_DEFAULT###");
00180 
00181                                                 // Markers and substitution:
00182                                         $markerArray["###CODE###"] = $theCode;
00183                                         $content.=$this->cObj->substituteMarkerArray($helpTemplate,$markerArray);
00184                                 break;
00185                         }
00186                 }
00187                 return $content;
00188         }
00189         
00193         function init($enableFields)    {
00194                 $this->enableFields = $enableFields;
00195         }
00196 
00200         function getLayouts($templateCode,$alternativeLayouts,$marker)  {
00201                 $out=array();
00202                 for($a=0;$a<$alternativeLayouts;$a++)   {
00203                         $m= "###".$marker.($a?"_".$a:"")."###";
00204                         if(strstr($templateCode,$m))    {
00205                                 $out[]=$GLOBALS["TSFE"]->cObj->getSubpart($templateCode, $m);
00206                         } else {
00207                                 break;
00208                         }
00209                 }
00210                 return $out;
00211         }
00212 
00216         function getItems($pid) {
00217                 
00218                 if(!isset($_REQUEST['offset']))
00219                 {
00220                         $offset = 0;
00221                 }
00222                 else
00223                 {
00224                         $offset = (int) $_REQUEST['offset'];
00225                 }
00226         
00227                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00228                         '*', 
00229                         'tt_guest', 
00230                         'pid IN ('.$pid.')'.$this->enableFields, 
00231                         '', 
00232                         'crdate DESC',
00233                         "{$offset}, {$this->conf['limit']}"
00234                 );
00235                 
00236                 $out = array();
00237                 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))       {
00238                         $out[] = $row;
00239                 }
00240                 return $out;
00241         }
00242 
00246         function formatStr($str)        {
00247                 if (!$this->dontParseContent)   {
00248                         return nl2br(htmlspecialchars($str));
00249                 } else {
00250                         return $str;
00251                 }
00252         }
00253 
00254         function getRecordCount($pid)
00255         {
00256                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00257                         'COUNT(*) AS thecount', 
00258                         'tt_guest', 
00259                         'pid IN ('.$pid.')'.$this->enableFields, 
00260                         '', 
00261                         '',
00262                         ''
00263                 );
00264 
00265                 list($thecount) = mysql_fetch_row($res);
00266 
00267                 return $thecount;
00268         }
00269         
00270         function getPrevNext()
00271         {
00272                 $nav = new RecordNavigator(
00273                         $this->recordCount, 
00274                         $_REQUEST['offset'], 
00275                         $this->conf['limit'], 
00276                         '?pid='.$GLOBALS['TSFE']->id
00277                 );
00278                 $nav->createSequence();
00279                 $nav->createPrevNext($this->conf['previousLabel'], $this->conf['nextLabel']);
00280                 return $nav->getNavigator();
00281         }
00282 }
00283 
00284 
00285 if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/tt_guest/pi/class.tx_ttguest.php"])    {
00286         include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/tt_guest/pi/class.tx_ttguest.php"]);
00287 }
00288 
00289 ?>


Généré par Les experts TYPO3 avec  doxygen 1.4.6