Documentation TYPO3 par Ameos

class.tx_ttnews.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 ***************************************************************/
00039 require_once(PATH_t3lib."class.t3lib_xml.php");
00040 require_once(PATH_tslib."class.tslib_pibase.php");
00041 
00042 class tx_ttnews extends tslib_pibase {
00043         var $cObj;              // The backReference to the mother cObj object set at call time
00044 
00045         var $tt_news_uid;
00046         var $conf;
00047         var $config;
00048         var $alternativeLayouts;
00049         var $pid;
00050         var $allowCaching;
00051         var $catExclusive;
00052         var $searchFieldList="short,bodytext,author,keywords,links,imagecaption,title";
00053         var $theCode="";
00054         
00055         var $categories=array();                        // Is initialized with the categories of the shopping system
00056         var $pageArray=array();                         // Is initialized with an array of the pages in the pid-list
00057 
00061         function main_xmlnewsfeed($content,$conf)       {
00062                 $className=t3lib_div::makeInstanceClassName("t3lib_xml");
00063                 $xmlObj = new $className("typo3_xmlnewsfeed");
00064                 $xmlObj->setRecFields("tt_news","title,datetime");      // More fields here...
00065                 $xmlObj->renderHeader();
00066                 $xmlObj->renderRecords("tt_news",$this->getStoriesResult());
00067                 $xmlObj->renderFooter();
00068                 return $xmlObj->getResult();
00069         }
00070         function getStoriesResult() {
00071                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'tt_news', 'pid='.intval($GLOBALS['TSFE']->id).$this->cObj->enableFields('tt_news'), '', 'datetime DESC');
00072                 return $res;
00073         }
00074         
00075 
00076 
00077 
00081         function main_news($content,$conf)      {
00082 
00083 
00084                 $GLOBALS["TSFE"]->set_no_cache();
00085 
00086         
00087                 // *************************************
00088                 // *** getting configuration values:
00089                 // *************************************
00090                 $this->conf = $conf;
00091                 $this->tt_news_uid = intval(t3lib_div::_GP("tt_news"));
00092                 $this->alternativeLayouts = intval($this->conf["alternatingLayouts"])>0 ? intval($this->conf["alternatingLayouts"]) : 2;
00093                         
00094                         // pid_list is the pid/list of pids from where to fetch the news items.
00095                 $this->config["pid_list"] = trim($this->cObj->stdWrap($this->conf["pid_list"],$this->conf["pid_list."]));
00096                 $this->config["pid_list"] = $this->config["pid_list"] ? implode(t3lib_div::intExplode(",",$this->config["pid_list"]),",") : $GLOBALS["TSFE"]->id;
00097                 $this->config["recursive"] = $this->cObj->stdWrap($conf["recursive"],$conf["recursive."]);
00098                 list($pid) = explode(",",$this->config["pid_list"]);
00099                 $this->pid = $pid;
00100 
00101                         // "CODE" decides what is rendered:
00102                 $this->config["code"] = $this->cObj->stdWrap($this->conf["code"],$this->conf["code."]);
00103                 $this->config["limit"] = t3lib_div::intInRange($conf["limit"],0,1000);
00104                 $this->config["limit"] = $this->config["limit"] ? $this->config["limit"] : 50;
00105                 $this->allowCaching = $this->conf["allowCaching"]?1:0;
00106                 
00107                         // If the current record should be displayed.
00108                 $this->config["displayCurrentRecord"] = $this->conf["displayCurrentRecord"];
00109                 if ($this->config["displayCurrentRecord"])      {
00110                         $this->config["code"]="LIST";
00111                         $this->tt_news_uid=$this->cObj->data["uid"];
00112                 }
00113 
00114                         // template is read.
00115                 $this->templateCode = $this->cObj->fileResource($this->conf["templateFile"]);
00116 
00117                         // globally substituted markers, fonts and colors.      
00118                 $splitMark = md5(microtime());
00119                 $globalMarkerArray=array();
00120                 list($globalMarkerArray["###GW1B###"],$globalMarkerArray["###GW1E###"]) = explode($splitMark,$this->cObj->stdWrap($splitMark,$conf["wrap1."]));
00121                 list($globalMarkerArray["###GW2B###"],$globalMarkerArray["###GW2E###"]) = explode($splitMark,$this->cObj->stdWrap($splitMark,$conf["wrap2."]));
00122                 $globalMarkerArray["###GC1###"] = $this->cObj->stdWrap($conf["color1"],$conf["color1."]);
00123                 $globalMarkerArray["###GC2###"] = $this->cObj->stdWrap($conf["color2"],$conf["color2."]);
00124                 $globalMarkerArray["###GC3###"] = $this->cObj->stdWrap($conf["color3"],$conf["color3."]);
00125 
00126                         // Substitute Global Marker Array
00127                 $this->templateCode= $this->cObj->substituteMarkerArray($this->templateCode, $globalMarkerArray);
00128 
00129         
00130                 // *************************************
00131                 // *** doing the things...:
00132                 // *************************************
00133                 $this->enableFields = $this->cObj->enableFields("tt_news");
00134                 $this->dontParseContent = $this->conf["dontParseContent"];
00135                 $this->local_cObj =t3lib_div::makeInstance("tslib_cObj");               // Local cObj.
00136 
00137                 $codes=t3lib_div::trimExplode(",", $this->config["code"]?$this->config["code"]:$this->conf["defaultCode"],1);
00138                 if (!count($codes))     $codes=array("");
00139                 while(list(,$theCode)=each($codes))     {
00140                         list($theCode,$cat,$aFlag) = explode("/",$theCode);
00141                         $this->catExclusive = intval($cat);
00142                         $this->arcExclusive     = intval($aFlag);
00143                         $theCode = (string)strtoupper(trim($theCode));
00144                         $this->theCode = $theCode;
00145                         switch($theCode)        {
00146                                 case "LATEST":
00147                                 case "LIST":
00148                                 case "SINGLE":
00149                                 case "SEARCH":
00150                                         $content.= $this->news_list();
00151                                 break;
00152                                 case "AMENU":
00153                                         $content.= $this->news_archiveMenu();
00154                                 break;
00155                                 default:
00156                                         $langKey = strtoupper($GLOBALS["TSFE"]->config["config"]["language"]);
00157                                         $helpTemplate = $this->cObj->fileResource("EXT:tt_news/pi/news_help.tmpl");
00158 
00159                                                 // Get language version
00160                                         $helpTemplate_lang="";
00161                                         if ($langKey)   {$helpTemplate_lang = $this->cObj->getSubpart($helpTemplate,"###TEMPLATE_".$langKey."###");}
00162                                         $helpTemplate = $helpTemplate_lang ? $helpTemplate_lang : $this->cObj->getSubpart($helpTemplate,"###TEMPLATE_DEFAULT###");
00163 
00164                                                 // Markers and substitution:
00165                                         $markerArray["###CODE###"] = $this->theCode;
00166                                         $content.=$this->cObj->substituteMarkerArray($helpTemplate,$markerArray);
00167                                 break;
00168                         }
00169                 }
00170                 return $content;
00171         }
00172 
00176         function news_archiveMenu()     {
00177                 $this->arcExclusive=1;
00178                 $selectConf = $this->getSelectConf('',1);
00179 
00180                         // Finding maximum and minimum values:
00181                 $selectConf['selectFields'] = 'max(datetime) as maxval, min(datetime) as minval';
00182                 $res = $this->cObj->exec_getQuery("tt_news",$selectConf);
00183                 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
00184 
00185                 if ($row["minval"])     {
00186                         $dateArr = array();
00187                         $arcMode = $this->conf["archiveMode"] ? $this->conf["archiveMode"] : "month";
00188                         $c=0;
00189                         do {
00190                                 switch($arcMode)        {
00191                                         case "month":
00192                                                 $theDate = mktime (0,0,0,date("m",$row["minval"])+$c,1,date("Y",$row["minval"]));
00193                                         break;
00194                                         case "quarter":
00195                                                 $theDate = mktime (0,0,0,floor(date("m",$row["minval"])/3)+1+(3*$c),1,date("Y",$row["minval"]));
00196                                         break;
00197                                         case "year":
00198                                                 $theDate = mktime (0,0,0,1,1,date("Y",$row["minval"])+$c);
00199                                         break;
00200                                 }
00201                                 $dateArr[]=$theDate;
00202                                 $c++;
00203                                 if ($c>1000)    break;
00204                         } while ($theDate<$GLOBALS["SIM_EXEC_TIME"]);
00205         //              array_pop($dateArr);
00206         
00207                         reset($dateArr);
00208                         $periodAccum=array();
00209                         while(list($k,$v)=each($dateArr))       {
00210                                 if (!isset($dateArr[$k+1]))     {break;}
00211                                 $periodInfo=array();
00212                                 $periodInfo["start"] = $dateArr[$k];
00213                                 $periodInfo["stop"] = $dateArr[$k+1]-1;
00214                                 $periodInfo["HRstart"] = date("d-m-Y",$periodInfo["start"]);
00215                                 $periodInfo["HRstop"] = date("d-m-Y",$periodInfo["stop"]);
00216                                 $periodInfo["quarter"] = floor(date("m",$dateArr[$k])/3)+1;
00217         
00218                                         // FInding maximum and minimum values:
00219                                 $selectConf['selectFields'] = 'count(*)';
00220                                 $selectConf['where'].= " AND datetime>=".$periodInfo["start"]." AND datetime<".$periodInfo["stop"];
00221                                 $res = $this->cObj->exec_getQuery("tt_news",$selectConf);
00222                                 $row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
00223                                 $periodInfo["count"]=$row[0];
00224                                 
00225                                 if (!$this->conf["archiveMenuNoEmpty"] || $periodInfo["count"]) {
00226                                         $periodAccum[] = $periodInfo;
00227                                 }
00228                         }
00229                         
00230                         
00231                         
00232         
00233                         $t["total"] = $this->cObj->getSubpart($this->templateCode,$this->spMarker("###TEMPLATE_ARCHIVE###"));
00234                         $t["item"]= $this->getLayouts($t["total"],$this->alternativeLayouts,"MENUITEM");
00235                         $cc=0;
00236         
00237                         $veryLocal_cObj =t3lib_div::makeInstance("tslib_cObj");         // Local cObj.
00238                         reset($periodAccum);
00239                         $itemsOut="";
00240                         while(list(,$pArr)=each($periodAccum))          {
00241                                         // Print Item Title
00242                                 $wrappedSubpartArray=array();
00243                                 $wrappedSubpartArray["###LINK_ITEM###"]= array('<A href="'.$this->getLinkUrl(0).'&pS='.$pArr["start"].'&pL='.($pArr["stop"]-$pArr["start"]).'&arc=1">','</A>'); 
00244         
00245                                 $markerArray = array();
00246                                 $veryLocal_cObj->start($pArr,"");
00247                                 $markerArray["###ARCHIVE_TITLE###"]=$veryLocal_cObj->cObjGetSingle($this->conf["archiveTitleCObject"],$this->conf["archiveTitleCObject."],"archiveTitle");
00248                                 $markerArray["###ARCHIVE_COUNT###"]=$pArr["count"];
00249         
00250                                 $itemsOut.= $this->cObj->substituteMarkerArrayCached($t["item"][($cc%count($t["item"]))],$markerArray,array(),$wrappedSubpartArray);
00251                         }
00252                         
00253                                                 // Reset:
00254                         $subpartArray=array();
00255                         $wrappedSubpartArray=array();
00256                         $markerArray=array();
00257                                 // Set content
00258                         $subpartArray["###CONTENT###"]=$itemsOut;
00259                         $content = $this->cObj->substituteMarkerArrayCached($t["total"],$markerArray,$subpartArray,$wrappedSubpartArray);
00260                 } else {
00261                         $content = $this->cObj->getSubpart($this->templateCode,$this->spMarker("###TEMPLATE_ARCHIVE_NOITEMS###"));
00262                 }
00263                 return $content;
00264         }
00265         
00269         function news_list()    {
00270                 $theCode = $this->theCode;
00271 /*              $this->setPidlist($this->config["pid_list"]);                           // The list of pid's we're operation on. All tt_products records must be in the pidlist in order to be selected.
00272                 $this->initRecursive($this->config["recursive"]);
00273                 $this->initCategories();
00274                 $this->generatePageArray();
00275                 
00276                 debug($this->pageArray);
00277                 debug($this->categories);
00278 
00279 */
00280 
00281                 $this->initCategories();
00282                 switch($theCode)        {
00283                         case "LATEST":  
00284                                 $prefix_display="displayLatest"; 
00285                                 $templateName = "TEMPLATE_LATEST";
00286                                 $this->arcExclusive=-1; // Only latest, non archive news
00287                                 if (intval($this->conf["latestLimit"]))         $this->config["limit"] = intval($this->conf["latestLimit"]);
00288                         break;
00289                         case "LIST": 
00290                         case "SEARCH":  
00291                                 $prefix_display="displayList"; 
00292                                 $templateName = "TEMPLATE_LIST";
00293                         break;
00294                         default:                
00295                                 $prefix_display="displaySingle"; 
00296                                 $templateName = "TEMPLATE_SINGLE";
00297                         break;
00298                 }
00299                 
00300                 if ($this->tt_news_uid) {
00301                                 // performing query:
00302                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'tt_news', 'uid='.intval($this->tt_news_uid).' AND type=0'.$this->enableFields);     // type=0 -> only real news.
00303                         $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
00304 
00305                         if($this->config["displayCurrentRecord"] || is_array($row))             {
00306                                 $this->setPidlist(intval($row["pid"]));
00307                                 $this->generatePageArray();
00308 
00309                                         // Get the subpart code
00310                                 $item ="";
00311                                 if ($this->config["displayCurrentRecord"])      {
00312                                         $row=$this->cObj->data;
00313                                         $item = trim($this->cObj->getSubpart($this->templateCode,$this->spMarker("###TEMPLATE_SINGLE_RECORDINSERT###")));
00314                                 }
00315                                 if (!$item)     {$item = $this->cObj->getSubpart($this->templateCode,$this->spMarker("###TEMPLATE_SINGLE###"));}
00316 
00317                                         // Fill marker arrays
00318                                 $wrappedSubpartArray=array();
00319                                 $wrappedSubpartArray["###LINK_ITEM###"]= array('<A href="'.$this->getLinkUrl($this->conf["backPid"]?$this->conf["backPid"]:t3lib_div::_GP("backPID")).'">','</A>');
00320                                 $markerArray = $this->getItemMarkerArray($row,"displaySingle");
00321                                         // Substitute
00322                                 $content= $this->cObj->substituteMarkerArrayCached($item,$markerArray,array(),$wrappedSubpartArray);
00323                         }
00324                 } elseif ($theCode=="SINGLE") {         
00325                         $content.="Wrong parameters, GET/POST var 'tt_news' was missing.";
00326                 } elseif ($this->arcExclusive>0 && !t3lib_div::_GP("pS") && $theCode!="SEARCH") {                       // periodStart must be set when listing from the archive.
00327                         $content.="";
00328                 } else {                
00329                         $content="";
00330         // List news:
00331                         $where="";                      
00332                         if ($theCode=="SEARCH") {
00333                                         // Get search subpart
00334                                 $t["search"] = $this->cObj->getSubpart($this->templateCode,$this->spMarker("###TEMPLATE_SEARCH###"));
00335                                         // Substitute a few markers
00336                                 $out=$t["search"];                              
00337                                 $out=$this->cObj->substituteMarker($out, "###FORM_URL###", $this->getLinkUrl($this->conf["PIDsearch"]));
00338                                 $out=$this->cObj->substituteMarker($out, "###SWORDS###", htmlspecialchars(t3lib_div::_GP("swords")));
00339                                         // Add to content
00340                                 $content.=$out;
00341                                 if (t3lib_div::_GP("swords"))   {
00342                                         $where = $this->searchWhere(trim(t3lib_div::_GP("swords")));
00343                                 }
00344                         }
00345                         $begin_at=t3lib_div::intInRange(t3lib_div::_GP("begin_at"),0,100000);
00346                         if (($theCode!="SEARCH" && !t3lib_div::_GP("swords")) || $where)        {
00347 
00348                                 $selectConf = $this->getSelectConf($where);
00349 
00350                                         // performing query to count all news (we need to know it for browsing):
00351                                 $selectConf['selectFields'] = 'count(*)';
00352                                 $res = $this->cObj->exec_getQuery("tt_news",$selectConf);
00353                                 $row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
00354                                 $newsCount = $row[0];
00355 
00356                                         // range check to current newsCount
00357                                 $begin_at = t3lib_div::intInRange(($begin_at >= $newsCount) ? ($newsCount-$this->config["limit"]) : $begin_at,0); 
00358 
00359                                         // performing query for display:
00360                                 $selectConf["orderBy"] = "datetime DESC"; 
00361                                 $selectConf['selectFields'] = '*';
00362                                 $selectConf['max'] = intval($this->config["limit"]+1);
00363                                 $selectConf['begin'] = $begin_at;
00364 
00365                                 $res = $this->cObj->exec_getQuery("tt_news",$selectConf);
00366 
00367                                         // Getting elements
00368                                 $itemsOut = "";
00369                                 $t = array();
00370                                 $t["total"] = $this->cObj->getSubpart($this->templateCode,$this->spMarker("###".$templateName."###"));
00371                                 $t["item"] = $this->getLayouts($t["total"],$this->alternativeLayouts,"NEWS");
00372                                 $cc = 0;
00373 
00374                                 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))               {
00375                                                 // Print Item Title
00376                                         $wrappedSubpartArray=array();
00377                                         if ($row["type"]==1 || $row["type"]==2) {
00378                                                 $this->local_cObj->setCurrentVal($row["type"]==1 ? $row["page"] : $row["ext_url"]);
00379                                                 $wrappedSubpartArray["###LINK_ITEM###"]= $this->local_cObj->typolinkWrap($this->conf["pageTypoLink."]);
00380                                         } else {
00381                                                 $wrappedSubpartArray["###LINK_ITEM###"]= array('<A href="'.$this->getLinkUrl($this->conf["PIDitemDisplay"]).'&tt_news='.$row["uid"].'">','</A>'); 
00382                                         }
00383                                         $markerArray = $this->getItemMarkerArray($row,$prefix_display);
00384 
00385                                         $itemsOut.= $this->cObj->substituteMarkerArrayCached($t["item"][($cc%count($t["item"]))],$markerArray,array(),$wrappedSubpartArray);
00386                                         $cc++;
00387                                         if ($cc==$this->config["limit"])        {break;}
00388                                 }
00389                                 $out=$itemsOut;
00390                         }
00391                         if ($out)       {
00392                                 // next / prev:
00393                                 $url = $this->getLinkUrl("","begin_at");
00394                                         // Reset:
00395                                 $subpartArray=array();
00396                                 $wrappedSubpartArray=array();
00397                                 $markerArray=array();
00398                                         
00399                                 if ($newsCount > $begin_at+$this->config["limit"])      {
00400                                         $next = ($begin_at+$this->config["limit"] > $newsCount) ? $newsCount-$this->config["limit"] : $begin_at+$this->config["limit"];
00401                                         $wrappedSubpartArray["###LINK_NEXT###"]=array('<A href="'.$url.'&begin_at='.$next.'">','</A>');
00402                                 } else {
00403                                         $subpartArray["###LINK_NEXT###"]="";
00404                                 }
00405                                 if ($begin_at)  {
00406                                         $prev = ($begin_at-$this->config["limit"] < 0) ? 0 : $begin_at-$this->config["limit"];
00407                                         $wrappedSubpartArray["###LINK_PREV###"]=array('<A href="'.$url.'&begin_at='.$prev.'">','</A>');
00408                                 } else {
00409                                         $subpartArray["###LINK_PREV###"]="";
00410                                 }
00411                                 $markerArray["###BROWSE_LINKS###"]="";
00412                                 if ($newsCount > $this->config["limit"] )       { // there is more than one page, so let's browse
00413                                         for ($i = 0 ; $i < ($newsCount/$this->config["limit"]); $i++)   {
00414                                                 if (($begin_at >= $i*$this->config["limit"]) && ($begin_at < $i*$this->config["limit"]+$this->config["limit"]))         {
00415                                                         $markerArray["###BROWSE_LINKS###"].= ' <b>'.(string)($i+1).'</b> ';
00416                                                         //      you may use this if you want to link to the current page also
00417                                                         //      $markerArray["###BROWSE_LINKS###"].= ' <A href="'.$url.'&begin_at='.(string)($i * $this->config["limit"]).'"><b>'.(string)($i+1).'</b></A> ';
00418                                                 } else {
00419                                                         $markerArray["###BROWSE_LINKS###"].= ' <A href="'.$url.'&begin_at='.(string)($i * $this->config["limit"]).'">'.(string)($i+1).'</A> ';
00420                                                 }
00421                                         }
00422                                 }
00423 
00424                                 $subpartArray["###CONTENT###"]=$out;
00425                                 $markerArray["###CATEGORY_TITLE###"]="";        // Something here later...
00426                                 $wrappedSubpartArray["###LINK_ARCHIVE###"]=$this->local_cObj->typolinkWrap($this->conf["archiveTypoLink."]);
00427 
00428                                 $content.= $this->cObj->substituteMarkerArrayCached($t["total"],$markerArray,$subpartArray,$wrappedSubpartArray);
00429                         } elseif ($where)       {
00430                                 $content.=$this->cObj->getSubpart($this->templateCode,$this->spMarker("###ITEM_SEARCH_EMPTY###"));
00431                         }
00432                 }
00433                 return $content;
00434         }
00435         
00436         function getSelectConf($where,$noPeriod=0)      {
00437                 $this->setPidlist($this->config["pid_list"]);
00438                 $this->initRecursive($this->config["recursive"]);
00439                 $this->generatePageArray();
00440 
00441                         // Get news
00442                 $selectConf = Array();
00443                 $selectConf["pidInList"] = $this->pid_list;
00444                 $selectConf["where"] = "1=1 ".$where;
00445 
00446 
00447                         // Archive
00448                 if (intval(t3lib_div::_GP("arc")))      {
00449                         $this->arcExclusive = intval(t3lib_div::_GP("arc"));
00450                 }
00451                 if ($this->arcExclusive)        {
00452                         if ($this->conf["enableArchiveDate"])   {
00453                                 if ($this->arcExclusive<0)      {       // latest
00454                                         $selectConf["where"].=' AND (archivedate=0 OR archivedate>'.$GLOBALS["SIM_EXEC_TIME"].')';
00455                                 } elseif ($this->arcExclusive>0)        {
00456                                         $selectConf["where"].=' AND archivedate<'.$GLOBALS["SIM_EXEC_TIME"];
00457                                 }
00458                         }
00459                         if ($this->conf["datetimeDaysToArchive"])       {
00460                                 $theTime = $GLOBALS["SIM_EXEC_TIME"]-intval($this->conf["datetimeDaysToArchive"])*3600*24;
00461                                 if ($this->arcExclusive<0)      {       // latest
00462                                         $selectConf["where"].=' AND (datetime=0 OR datetime>'.$theTime.')';
00463                                 } elseif ($this->arcExclusive>0)        {
00464                                         $selectConf["where"].=' AND datetime<'.$theTime;
00465                                 }
00466                         }
00467                 }
00468                         // Category
00469                 if (intval(t3lib_div::_GP("cat")))      {
00470                         $this->catExclusive = intval(t3lib_div::_GP("cat"));
00471                 }
00472                 if ($this->catExclusive)        {
00473                         $selectConf["where"].=" AND category=".$this->catExclusive;
00474                 }
00475                         // Period
00476                 if (!$noPeriod && intval(t3lib_div::_GP("pS"))) {
00477                         $selectConf["where"].=' AND datetime>'.intval(t3lib_div::_GP("pS"));
00478                         if (intval(t3lib_div::_GP("pL")))       {
00479                                 $selectConf["where"].=' AND datetime<'.(intval(t3lib_div::_GP("pS"))+intval(t3lib_div::_GP("pL")));
00480                         }
00481                 }
00482                 return $selectConf;
00483         }
00484         
00485         
00486         
00487         
00488         
00489         
00490         
00491         
00492         
00493         
00494         
00495         
00496 
00497 
00501         function setPidlist($pid_list)  {
00502                 $this->pid_list = $pid_list;
00503         }
00504 
00508         function initRecursive($recursive)      {
00509                 if ($recursive) {               // get pid-list if recursivity is enabled
00510                         $pid_list_arr = explode(",",$this->pid_list);
00511                         $this->pid_list="";
00512                         while(list(,$val)=each($pid_list_arr))  {
00513                                 $this->pid_list.=$val.",".$this->cObj->getTreeList($val,intval($recursive));
00514                         }
00515                         $this->pid_list = ereg_replace(",$","",$this->pid_list);
00516                 }
00517         }
00518 
00522         function initCategories()       {
00523                         // Fetching catagories:
00524                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'tt_news_cat', '1=1'.$this->cObj->enableFields('tt_news_cat'));
00525                 $this->categories = array();
00526                 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))       {
00527                         $this->categories[$row["uid"]] = $row["title"];
00528                 }       
00529         }
00530 
00534         function generatePageArray()    {
00535                         // Get pages (for category titles)              
00536                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('title,uid,author,author_email', 'pages', 'uid IN ('.$this->pid_list.')');
00537                 $this->pageArray = array();
00538                 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))               {
00539                         $this->pageArray[$row["uid"]] = $row;
00540                 }
00541         }
00542 
00546         function getItemMarkerArray ($row,$textRenderObj="displaySingle")       {
00547                         // Returns a markerArray ready for substitution with information for the tt_producst record, $row
00548                         // config to use:
00549                 $lConf = $this->conf[$textRenderObj."."];
00550                 $this->local_cObj->start($row,"tt_news");
00551                 $imageNum = isset($lConf["imageCount"]) ? $lConf["imageCount"] : 1;
00552                 $imageNum = t3lib_div::intInRange($imageNum,0,100);
00553                 $markerArray=array();
00554 
00555 
00556                         // Get and set image:
00557                 $theImgCode="";
00558                 $imgs = t3lib_div::trimExplode(",",$row["image"],1);
00559                 $imgsCaptions = explode(chr(10),$row["imagecaption"]);
00560                 reset($imgs);
00561                 $cc=0;
00562                 while(list(,$val)=each($imgs))  {
00563                         if ($cc==$imageNum)     break;
00564                         if ($val)       {
00565                                 $lConf["image."]["file"] = "uploads/pics/".$val;
00566                         }
00567                         $theImgCode.=$this->local_cObj->IMAGE($lConf["image."]).$this->local_cObj->stdWrap($imgsCaptions[$cc],$lConf["caption_stdWrap."]);
00568                         $cc++;
00569                 }
00570                 $markerArray["###NEWS_IMAGE###"]="";
00571                 if ($cc)        {
00572                         $markerArray["###NEWS_IMAGE###"] = $this->local_cObj->wrap(trim($theImgCode),$lConf["imageWrapIfAny"]); 
00573                 }
00574 
00575                         // Title
00576                 $markerArray["###NEWS_UID###"] = $row["uid"];
00577                 $markerArray["###NEWS_TITLE###"] = $this->local_cObj->stdWrap($row["title"],$lConf["title_stdWrap."]);
00578                 $markerArray["###NEWS_AUTHOR###"] = $this->local_cObj->stdWrap($row["author"],$lConf["author_stdWrap."]);
00579                 $markerArray["###NEWS_EMAIL###"] = $this->local_cObj->stdWrap($row["author_email"],$lConf["email_stdWrap."]);
00580                 $markerArray["###NEWS_DATE###"] = $this->local_cObj->stdWrap($row["datetime"],$lConf["date_stdWrap."]);
00581                 $markerArray["###NEWS_TIME###"] = $this->local_cObj->stdWrap($row["datetime"],$lConf["time_stdWrap."]);
00582                 $markerArray["###NEWS_AGE###"] = $this->local_cObj->stdWrap($row["datetime"],$lConf["age_stdWrap."]);
00583                 $markerArray["###NEWS_SUBHEADER###"] = $this->formatStr($this->local_cObj->stdWrap($row["short"],$lConf["subheader_stdWrap."]));
00584                 $markerArray["###NEWS_CONTENT###"] = $this->formatStr($this->local_cObj->stdWrap($row["bodytext"],$lConf["content_stdWrap."]));
00585                 $markerArray["###NEWS_LINKS###"] = $this->formatStr($this->local_cObj->stdWrap($row["links"],$lConf["links_stdWrap."]));
00586                         // Category fields:
00587                 $markerArray["###NEWS_CATEGORY###"] = $this->local_cObj->stdWrap($this->categories[$row["category"]],$lConf["category_stdWrap."]);
00588                 
00589                         // related
00590                 $markerArray["###NEWS_RELATED###"] = $this->local_cObj->stdWrap($this->getRelated($row["uid"]),$lConf["related_stdWrap."]);
00591 
00592                         // Page fields:
00593                 $markerArray["###PAGE_UID###"] = $row["pid"];
00594                 $markerArray["###PAGE_TITLE###"] = $this->pageArray[$row["pid"]]["title"];
00595                 $markerArray["###PAGE_AUTHOR###"] = $this->local_cObj->stdWrap($this->pageArray[$row["pid"]]["author"],$lConf["author_stdWrap."]);
00596                 $markerArray["###PAGE_AUTHOR_EMAIL###"] = $this->local_cObj->stdWrap($this->pageArray[$row["pid"]]["author_email"],$lConf["email_stdWrap."]);
00597                 
00598                         // Pass to user defined function
00599                 if ($this->conf["itemMarkerArrayFunc"]) {
00600                         $markerArray = $this->userProcess("itemMarkerArrayFunc",$markerArray);
00601                 }
00602 //              debug(array_keys($markerArray));
00603                 return $markerArray;
00604         }
00605 
00609         function getRelated($uid)       {
00610                 $veryLocal_cObj = t3lib_div::makeInstance("tslib_cObj");                // Local cObj.
00611                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,title,short,datetime,archivedate', 'tt_news,tt_news_related_mm AS M', 'tt_news.uid=M.uid_foreign AND M.uid_local='.intval($uid));
00612 
00613                 $lines = array();
00614                 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))       {
00615                         $veryLocal_cObj->start($row,"tt_news");
00616                         $lines[] = $veryLocal_cObj->cObjGetSingle($this->conf["getRelatedCObject"],$this->conf["getRelatedCObject."],"getRelated");
00617                 }
00618                 return implode("",$lines);
00619         }
00620 
00624         function userProcess($mConfKey,$passVar)        {
00625                 if ($this->conf[$mConfKey])     {
00626                         $funcConf = $this->conf[$mConfKey."."];
00627                         $funcConf["parentObj"]=&$this;
00628                         $passVar = $GLOBALS["TSFE"]->cObj->callUserFunction($this->conf[$mConfKey], $funcConf, $passVar);
00629                 }
00630                 return $passVar;
00631         }
00632 
00636         function spMarker($subpartMarker)       {
00637                 $sPBody = substr($subpartMarker,3,-3);
00638                 $altSPM = "";
00639                 if (isset($this->conf["altMainMarkers."]))      {
00640                         $altSPM = trim($this->cObj->stdWrap($this->conf["altMainMarkers."][$sPBody],$this->conf["altMainMarkers."][$sPBody."."]));
00641                         $GLOBALS["TT"]->setTSlogMessage("Using alternative subpart marker for '".$subpartMarker."': ".$altSPM,1);
00642                 }
00643                 return $altSPM ? $altSPM : $subpartMarker;
00644         }
00645 
00649         function getLinkUrl($id="",$excludeList="")     {
00650                 $queryString=array();
00651                 $queryString["id"] = "id=".($id ? $id : $GLOBALS["TSFE"]->id);
00652                 $queryString["type"]= $GLOBALS["TSFE"]->type ? 'type='.$GLOBALS["TSFE"]->type : "";
00653                 $queryString["backPID"]= 'backPID='.$GLOBALS["TSFE"]->id;
00654                 $queryString["begin_at"]= t3lib_div::_GP("begin_at") ? 'begin_at='.t3lib_div::_GP("begin_at") : "";
00655                 $queryString["swords"]= t3lib_div::_GP("swords") ? "swords=".rawurlencode(t3lib_div::_GP("swords")) : "";
00656                 $queryString["pS"]= t3lib_div::_GP("pS") ? "pS=".intval(t3lib_div::_GP("pS")) : "";     // period start
00657                 $queryString["pL"]= t3lib_div::_GP("pL") ? "pL=".intval(t3lib_div::_GP("pL")) : ""; // Period length
00658                 $queryString["arc"]= t3lib_div::_GP("arc") ? "arc=".intval(t3lib_div::_GP("arc")) : ""; // Archive flag: 0 = don't care, -1 = latest, 1 = archive
00659                 $queryString["cat"]= t3lib_div::_GP("cat") ? "cat=".intval(t3lib_div::_GP("cat")) : ""; // Category uid, 0 = any
00660 
00661                 reset($queryString);
00662                 while(list($key,$val)=each($queryString))       {
00663                         if (!$val || ($excludeList && t3lib_div::inList($excludeList,$key)))    {
00664                                 unset($queryString[$key]);
00665                         }
00666                 }
00667                 return $GLOBALS["TSFE"]->absRefPrefix.'index.php?'.implode($queryString,"&");
00668         }
00669 
00673         function searchWhere($sw)       {
00674                 $where=$this->cObj->searchWhere($sw, $this->searchFieldList, 'tt_news');
00675                 return $where;
00676         }
00677 
00681         function formatStr($str)        {
00682                 if (is_array($this->conf["general_stdWrap."]))  {
00683                         $str = $this->local_cObj->stdWrap($str,$this->conf["general_stdWrap."]);
00684                 }
00685                 return $str;
00686         }
00687 
00691         function getLayouts($templateCode,$alternativeLayouts,$marker)  {
00692                 $out=array();
00693                 for($a=0;$a<$alternativeLayouts;$a++)   {
00694                         $m= "###".$marker.($a?"_".$a:"")."###";
00695                         if(strstr($templateCode,$m))    {
00696                                 $out[]=$GLOBALS["TSFE"]->cObj->getSubpart($templateCode, $m);
00697                         } else {
00698                                 break;
00699                         }
00700                 }
00701                 return $out;
00702         }
00703 }
00704 
00705 
00706 if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/tt_news/pi/class.tx_ttnews.php"])      {
00707         include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/tt_news/pi/class.tx_ttnews.php"]);
00708 }
00709 
00710 ?>


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