-
-
Save exside/5073304 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ($debug) { | |
$modx->setLogLevel(modx::LOG_LEVEL_DEBUG); | |
$mtime = microtime(); | |
$mtime = explode(" ", $mtime); | |
$mtime = $mtime[1] + $mtime[0]; | |
$tstart = $mtime; | |
} | |
$createdon = array(); | |
$clear = false; | |
//$permalinkTV | |
//$authorTV | |
//$descriptionTV | |
include_once(MODX_CORE_PATH . 'components/rssGrabber/includes/SimplePie/SimplePieAutoloader.php'); | |
$childs = $modx->getCollection('modResource', array('parent' => $parent)); | |
if (count($childs) > 0) { | |
foreach ($childs as $child) { | |
$createdon[] = strtotime($child->get('createdon')); | |
} | |
} | |
$urls = preg_split('/\r\n|\r|\n/', $urls); | |
$feed = new SimplePie(); | |
$feed->set_feed_url($urls); | |
$feed->enable_cache(false); | |
$success = $feed->init(); | |
if (!$success) { | |
$modx->log(modX::LOG_LEVEL_ERROR, '[rssGrabber] Failed to initialize SimplePie'); | |
return ''; | |
} | |
foreach ($feed->get_items() as $item) { | |
$pagetitle = $item->get_title(); | |
$date = $item->get_date('U'); | |
$author = $item->get_author(); | |
$author_name = $author->get_name(); | |
$permalink = $item->get_link(); | |
$description = $item->get_description(); | |
$content = $item->get_content(); | |
$tvs = array( | |
$permalinkTV => $permalink, | |
$descriptionTV => $description, | |
$authorTV => $author_name | |
); | |
if (!in_array($date, $createdon)) { | |
$resourse = $modx->newObject('modResource', array( | |
'parent' => $parent | |
, 'template' => $template | |
, 'pagetitle' => $pagetitle | |
//, 'introtext' => $description | |
, 'createdon' => $date | |
, 'publishedon' => $date | |
, 'content' => $content | |
) | |
); | |
$resourse->save(); | |
foreach ($tvs as $tv => $value) { | |
if ($tv = $modx->getObject('modTemplateVar', array('name' => $tv))) { | |
$tv->setValue($resourse->get('id'), $value); | |
$tv->save(); | |
} | |
} | |
$clear = true; | |
} | |
} | |
if ($clear) { | |
$modx->cacheManager->clearCache(); | |
$modx->log(LOG_LEVEL_DEBUG, '[rssGrabber] clearCache'); | |
} | |
if ($debug) { | |
$mtime = microtime(); | |
$mtime = explode(" ", $mtime); | |
$mtime = $mtime[1] + $mtime[0]; | |
$tend = $mtime; | |
$totalTime = ($tend - $tstart); | |
$totalTime = sprintf("%2.4f s", $totalTime); | |
$modx->log(modX::LOG_LEVEL_DEBUG, '[rssGrabber] Execution time: ' . $totalTime); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment