Changeset View
Changeset View
Standalone View
Standalone View
branches/5.2.x/units/articles/articles_event_handler.php
Show First 20 Lines • Show All 205 Lines • ▼ Show 20 Line(s) | |||||
break; | break; | ||||
} | } | ||||
} | } | ||||
if (!$article_node) { | if (!$article_node) { | ||||
return false; | return false; | ||||
} | } | ||||
$category_id = $event->getEventParam('category_id'); | |||||
$backup_category_id = $this->Application->GetVar('m_cat_id'); | |||||
$this->Application->SetVar('m_cat_id', $category_id); | |||||
switch ($feed_type) { | switch ($feed_type) { | ||||
case 'rss_2.0': | case 'rss_2.0': | ||||
$this->parseRssFeed($article_node, $event); | $this->parseRssFeed($article_node, $event); | ||||
break; | break; | ||||
case 'atom': | case 'atom': | ||||
$this->parseAtomFeed($article_node, $event); | $this->parseAtomFeed($article_node, $event); | ||||
break; | break; | ||||
} | } | ||||
$this->Application->SetVar('m_cat_id', $backup_category_id); | |||||
} | } | ||||
/** | /** | ||||
* Returns ML field names for article record | * Returns ML field names for article record | ||||
* | * | ||||
* @param kCatDBItem $object | * @param kCatDBItem $object | ||||
* @return Array | * @return Array | ||||
*/ | */ | ||||
Show All 28 Lines | |||||
function parseRssFeed(&$root_node, $event) | function parseRssFeed(&$root_node, $event) | ||||
{ | { | ||||
$current_node = $root_node->firstChild; | $current_node = $root_node->firstChild; | ||||
$feed_articles = $this->getFeedArticles($event); | $feed_articles = $this->getFeedArticles($event); | ||||
$object = $this->Application->recallObject($event->Prefix.'.-item', null, Array('skip_autoload' => true)); | $object = $this->Application->recallObject($event->Prefix.'.-item', null, Array('skip_autoload' => true)); | ||||
/* @var $object kDBItem */ | /* @var $object kDBItem */ | ||||
$category_id = $event->getEventParam('category_id'); | |||||
list ($title_field, $body_field) = $this->_getMLFields($object); | list ($title_field, $body_field) = $this->_getMLFields($object); | ||||
do { | do { | ||||
// IMAGE is information about channel and is not useful here | // IMAGE is information about channel and is not useful here | ||||
if ($current_node->Name != 'ITEM') continue; | if ($current_node->Name != 'ITEM') continue; | ||||
// collect item data | // collect item data | ||||
$data = Array(); | $data = Array(); | ||||
$sub_node =& $current_node->firstChild; | $sub_node =& $current_node->firstChild; | ||||
Show All 13 Lines | |||||
$article_id = getArrayValue($feed_articles, $article_crc); | $article_id = getArrayValue($feed_articles, $article_crc); | ||||
if ($article_id) { | if ($article_id) { | ||||
$object->Load($article_id); | $object->Load($article_id); | ||||
} | } | ||||
else { | else { | ||||
$object->Clear(); | $object->Clear(); | ||||
} | } | ||||
$object->SetDBField('CategoryId', $category_id); | |||||
$object->SetDBField($title_field, $data['TITLE']); | $object->SetDBField($title_field, $data['TITLE']); | ||||
$object->SetDBField('cust_RssOriginalURL', $data['LINK']); | $object->SetDBField('cust_RssOriginalURL', $data['LINK']); | ||||
$object->SetDBField('cust_RssArticleCRC', $article_crc); | $object->SetDBField('cust_RssArticleCRC', $article_crc); | ||||
$object->SetDBField($body_field, !array_key_exists('DESCRIPTION', $data) ? $data['ATOM:SUMMARY'] : $data['DESCRIPTION']); | $object->SetDBField($body_field, !array_key_exists('DESCRIPTION', $data) ? $data['ATOM:SUMMARY'] : $data['DESCRIPTION']); | ||||
$expiration_time = adodb_mktime() + $event->getEventParam('life_time'); | $expiration_time = adodb_mktime() + $event->getEventParam('life_time'); | ||||
$object->SetDBField('EndOn_date', $expiration_time); | $object->SetDBField('EndOn_date', $expiration_time); | ||||
$object->SetDBField('EndOn_time', $expiration_time); | $object->SetDBField('EndOn_time', $expiration_time); | ||||
$object->SetDBField('Status', STATUS_ACTIVE); | $object->SetDBField('Status', STATUS_ACTIVE); | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | |||||
function parseAtomFeed(&$root_node, $event) | function parseAtomFeed(&$root_node, $event) | ||||
{ | { | ||||
$current_node = $root_node->firstChild; | $current_node = $root_node->firstChild; | ||||
$feed_articles = $this->getFeedArticles($event); | $feed_articles = $this->getFeedArticles($event); | ||||
$object = $this->Application->recallObject($event->Prefix.'.-item', null, Array('skip_autoload' => true)); | $object = $this->Application->recallObject($event->Prefix.'.-item', null, Array('skip_autoload' => true)); | ||||
/* @var $object kDBItem */ | /* @var $object kDBItem */ | ||||
$category_id = $event->getEventParam('category_id'); | |||||
list ($title_field, $body_field) = $this->_getMLFields($object); | list ($title_field, $body_field) = $this->_getMLFields($object); | ||||
do { | do { | ||||
if ($current_node->Name != 'ENTRY') continue; | if ($current_node->Name != 'ENTRY') continue; | ||||
// collect item data | // collect item data | ||||
$data = Array(); | $data = Array(); | ||||
$sub_node =& $current_node->firstChild; | $sub_node =& $current_node->firstChild; | ||||
/* @var $sub_node kXMLNode */ | /* @var $sub_node kXMLNode */ | ||||
Show All 17 Lines | |||||
$article_id = getArrayValue($feed_articles, $article_crc); | $article_id = getArrayValue($feed_articles, $article_crc); | ||||
if ($article_id) { | if ($article_id) { | ||||
$object->Load($article_id); | $object->Load($article_id); | ||||
} | } | ||||
else { | else { | ||||
$object->Clear(); | $object->Clear(); | ||||
} | } | ||||
$object->SetDBField('CategoryId', $category_id); | |||||
$object->SetDBField($title_field, $data['TITLE']); | $object->SetDBField($title_field, $data['TITLE']); | ||||
$object->SetDBField('cust_RssOriginalURL', $data['LINK']); | $object->SetDBField('cust_RssOriginalURL', $data['LINK']); | ||||
$object->SetDBField('cust_RssArticleCRC', $article_crc); | $object->SetDBField('cust_RssArticleCRC', $article_crc); | ||||
$object->SetDBField($body_field, !array_key_exists('CONTENT', $data) ? $data['SUMMARY'] : $data['CONTENT']); | $object->SetDBField($body_field, !array_key_exists('CONTENT', $data) ? $data['SUMMARY'] : $data['CONTENT']); | ||||
$expiration_time = adodb_mktime() + $event->getEventParam('life_time'); | $expiration_time = adodb_mktime() + $event->getEventParam('life_time'); | ||||
$object->SetDBField('EndOn_date', $expiration_time); | $object->SetDBField('EndOn_date', $expiration_time); | ||||
$object->SetDBField('EndOn_time', $expiration_time); | $object->SetDBField('EndOn_time', $expiration_time); | ||||
$object->SetDBField('Status', STATUS_ACTIVE); | $object->SetDBField('Status', STATUS_ACTIVE); | ||||
▲ Show 20 Lines • Show All 174 Lines • Show Last 20 Lines |