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
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;
00049
00050 var $enableFields ="";
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
00065
00066 $alternativeLayouts = intval($conf["alternatingLayouts"])>0 ? intval($conf["alternatingLayouts"]) : 2;
00067
00068
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
00074 $config["code"] = $this->cObj->stdWrap($conf["code"],$conf["code."]);
00075
00076
00077 $this->orig_templateCode = $this->cObj->fileResource($conf["templateFile"]);
00078
00079
00080
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
00094 $this->orig_templateCode= $this->cObj->substituteMarkerArray($this->orig_templateCode, $globalMarkerArray);
00095
00096
00097 $config["displayCurrentRecord"] = $conf["displayCurrentRecord"];
00098 if ($config["displayCurrentRecord"]) {
00099 $config["code"]="GUESTBOOK";
00100 }
00101
00102
00103
00104
00105
00106 $this->init($this->cObj->enableFields("tt_guest"));
00107 $this->dontParseContent = $conf["dontParseContent"];
00108 $cObj =t3lib_div::makeInstance("tslib_cObj");
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
00127 $templateCode = $cObj->getSubpart($this->orig_templateCode, "###".$lConf["subpartMarker"]."###");
00128 if ($templateCode) {
00129
00130 $postHeader=$this->getLayouts($templateCode,$alternativeLayouts,"POST");
00131
00132
00133 if ($config["displayCurrentRecord"]) {
00134 $recentPosts=array();
00135 $recentPosts[] = $this->cObj->data;
00136 } else {
00137 $recentPosts = $this->getItems($pid);
00138 }
00139
00140 reset($recentPosts);
00141 $c_post=0;
00142 $subpartContent="";
00143 while(list(,$recentPost)=each($recentPosts)) {
00144
00145 $cObj->start($recentPost);
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
00156 $out=$postHeader[$c_post%count($postHeader)];
00157 $c_post++;
00158 $subpartContent.=$cObj->substituteMarkerArrayCached($out,$markerArray);
00159 }
00160
00161
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
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
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 ?>