[TYPO3-english] tt_news xml rss addon not show news date

Baber baber.ahmed at wisetiger.co.uk
Wed Oct 20 16:41:38 CEST 2010


Hi All,

I am using an addon to tt_news to bring an rss feed to my typo3 site, but
for some reason the addon does not show the date. I checked the tt_news data
table and there seems tobe no crdate for the rss records inserted by
"xml_ttnews_import" and "cc_rdf_news_import". Please see below for the
function that interacts with tt_news db table.

------------------------------------- code
--------------------------------------------------

 function processRSSRecord($item)
    {
            t3lib_div::devLog('RSS descriptor opened successfully',
'xml_ttnews_import'); 
            // initialize counters
            $this->ItemsCounter = 0;
            $this->ChannelSkipHoursCount = 0;
            $this->ChannelSkipDaysCount = 0; 
            // get data from the net
            $xmlData = $this->getrdf($item["url"], 5); 
            $error = $this->parse($xmlData, false); 
            // if there was an error we output the old cached data
            if (!$this->ItemsCounter OR $xmlData == "" OR $error != "") {
                // $query = "UPDATE tx_ccrdfnewsimport SET lastError='" .
addslashes($error) . "', errors='" . ($item["errors"]+1) . "' WHERE uid = ("
.$item["uid"]. ")";
                // $res = mysql(TYPO3_db,$query);
                // echo mysql_error();
                t3lib_div::devLog('No XML returned from URL ' .
$item['url'], 'xml_ttnews_import');
                $RSScontent .= 'No XML returned from URL ' . $item['url'] .
'<br>Error:'.$error.'<br>';
            } else {
                t3lib_div::devLog('Processing ' . $this->ItemsCounter . '
items', 'xml_ttnews_import');
                $RSScontent .= $this->ItemsCounter . ' items have been
processed from stream:<br /> ' . $item['url'] . ' ' . $item['url'] . ' <br
/>';
                $rendered = '<table
border=1><tr><td><strong>title</strong></td><td><strong>unid</strong></td><td><strong>status</strong></td></tr>'; 
                // render the items from the rdf channel and write them to
tt_news records
                $renderedItems = "";
                $count = 0;

                while ($count < $this->ItemsCounter) {
                    // Set the news record with imported values
                   
//t3lib_div::devLog('Categories:'.print_r($this->Items[$count]["Categories"],
true), 'xml_ttnews_import');
                    $newsRecord = array('pid' =>
($item['tx_xmlttnewsimport_targetpid'])?$item['tx_xmlttnewsimport_targetpid']:$item['pid'],
// By default, Id of current page
                        'tstamp' => time(),
                        // **OS 11.8.2006 -6 instead of -9
                        'crdate' =>
strtotime(substr($this->Items[$count]["Date"], 0, -6)),
                        'datetime' =>
strtotime(substr($this->Items[$count]["Date"], 0, -6)),
                        'title' => $this->Items[$count]["Title"],
                        'short' => $this->Items[$count]["Description"],
                        'type' => '2', // Type is External URL
                        'ext_url' => $this->Items[$count]["Link"],
                        'tx_xmlttnewsimport_xmlunid' => substr
($this->Items[$count]["Link"], strpos($this->Items[$count]["Link"],
"/index/") + 7),
                        'bodytext' => '',
                        );

                    // See if this record already exists in tt_news
                    $fields = '*';
                    $tables = 'tt_news';
                    $where = 'pid=' . $newsRecord['pid'] . ' AND deleted=0
AND tx_xmlttnewsimport_xmlunid="' . substr($this->Items[$count]["Link"],
strpos($this->Items[$count]["Link"], "/index/") + 7) . '"';
                    // t3lib_div::devLog('searching tt_news record where ' .
$where, 'xml_ttnews_import');
                    $nresults =
$GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, $tables, $where, '', '',
'');
                    $nitem =
$GLOBALS['TYPO3_DB']->sql_fetch_assoc($nresults); // Should be only one
record
                    if (is_array($nitem)) {
                        // update the existing record in tt_news
                        unset($newsRecord['crdate']); // Don't change item's
creation date
                        unset($newsRecord['type']); // Don't change item's
type (in case it has been further edited)
                        unset($newsRecord['bodytext']); // Don't change
item's bodytext
                        $tmp =
$GLOBALS['TYPO3_DB']->exec_UPDATEquery($tables, $where, $newsRecord);
                        if ($tmp) {
                            //t3lib_div::devLog('tt_news record ' .
$this->Items[$count]["Unid"] . ' updated<br />', 'xml_ttnews_import');
                            $rendered .= '<tr><td>' . $newsRecord['title'] .
'</td><td>' . $newsRecord['tx_xmlttnewsimport_xmlunid'] .
'</td><td>updated</td></tr>';
                        } else {
                            $RSScontent .= 'tt_news record ' .
$this->Items[$count]["Unid"] . ' NOT updated<br />';
                            t3lib_div::devLog('tt_news record ' .
$this->Items[$count]["Unid"] . ' NOT updated<br />', 'xml_ttnews_import');
                        }
                        $n_uid = $nitem[0]["uid"];
                    } else {
                        // If it has been asked for, get the body text
                        //t3lib_div::devLog('Import
body:'.$item['tx_xmlttnewsimport_import_body'], 'xml_ttnews_import');
                        if ($item['tx_xmlttnewsimport_import_body']) {
                            // Import the body text
                            $newscontentxml =
t3lib_div::getURL(str_replace('/index/', '/xml_index/',
$this->Items[$count]["Link"]));
                            $newscontent = substr($newscontentxml,
strpos($newscontentxml, '<body>') + 6);
                            $newscontent = substr($newscontent, 0 , -
(strlen($newscontent) - strpos($newscontent, '</body>'))); 
                            $convObj = t3lib_div::makeInstance('t3lib_cs');
                            $newscontent =
$convObj->conv($newscontent,'utf-8','iso-8859-1','1') ;
                            $parseObj =
t3lib_div::makeInstance('t3lib_parsehtml_proc');
                            $newscontent =
str_replace("œ","oe",$newscontent);
                            $newscontent = str_replace(array("\r\n", "\n",
"\r"),"",$newscontent);
                            $newscontent =
$parseObj->TS_transform_db($newscontent,true);
                            // t3lib_div::devLog('Body
text:'.print_r($newscontent, true), 'xml_ttnews_import');
                            $newsRecord['bodytext'] = $newscontent;
                            $newsRecord['type'] = '0';
                        } else {
                            unset($newsRecord['bodytext']);
                        } 
                        // Create a new record in tt_news
                        $tmp =
$GLOBALS['TYPO3_DB']->exec_INSERTquery($tables, $newsRecord);
						//die(var_dump($newsRecord));
                        if ($tmp) {
                            // t3lib_div::devLog('Inserted new tt_news
record ' . $this->Items[$count]["Unid"], 'xml_ttnews_import');
                            $rendered .= '<tr><td>' . $newsRecord['title'] .
'</td><td>' . $newsRecord['tx_xmlttnewsimport_xmlunid'] .
'</td><td>inserted</td></tr>';
                            $n_uid = $GLOBALS['TYPO3_DB']->sql_insert_id();
                            
                            // Now add categories
                            $n_categ=1; 
                            foreach ($this->Items[$count]["Categories"] as
$tmp_categ) {
                              $cat_where = 'title=\''.$tmp_categ.'\' AND
deleted=0';
                              $cat_search =
$GLOBALS['TYPO3_DB']->exec_SELECTquery ('*', 'tt_news_cat',
$cat_where,'','','');
                              $cat_record =
$GLOBALS['TYPO3_DB']->sql_fetch_assoc($cat_search);
                              if (is_array($cat_record)) {
                                  $mm_rec = array( 
                                    'uid_local' => $n_uid,
                                    'uid_foreign' => $cat_record['uid'],
                                    'sorting' => $n_categ++,
                                  );
                                  $tmp2 =
$GLOBALS['TYPO3_DB']->exec_INSERTquery('tt_news_cat_mm', $mm_rec);
                                  if (! $tmp2) {
                                    t3lib_div::devLog('Could not add the
tt_news_cat_mm relation.', 'xml_ttnews_import');
                                  }
                              } else {
                                  t3lib_div::devLog('The category ' .
$tmp_categ.' does not exist in tt_news_cat.', 'xml_ttnews_import');
                              }           
                            }
                             
                        } else {
                            $RSScontent .= 'Could not insert new tt_news
record ' . $this->Items[$count]["Unid"] . '<br />';
                            t3lib_div::devLog('Could not insert new tt_news
record ' . $this->Items[$count]["Unid"], 'xml_ttnews_import');
                        } 
                    }                

                    $count++;
                } // end while
                $rendered .= '</tr></table><br><br>';
                $RSScontent .= $rendered;
            }
            return $RSScontent; 
    }

---------------------------------------------------------------------------------------------

I would be greatful for any help with this
Bob
-- 
View this message in context: http://old.nabble.com/tt_news-xml-rss-addon-not-show-news-date-tp30010600p30010600.html
Sent from the TYPO3 English mailing list archive at Nabble.com.



More information about the TYPO3-english mailing list