-
-
Notifications
You must be signed in to change notification settings - Fork 529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Load feeds on dashboard with AJAX instead of on page render #13507
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
/** | ||
* Class modDashboardWidgetFeedProcessor | ||
* | ||
* Used to load the news and security feeds on the dashboard over AJAX. The processed feed content | ||
* (i.e. HTML) is returned in object->html. | ||
*/ | ||
class modDashboardWidgetFeedProcessor extends modProcessor | ||
{ | ||
/** | ||
* @var modRSSParser | ||
*/ | ||
protected $rss; | ||
|
||
public function process() | ||
{ | ||
$feed = $this->getProperty('feed', 'news'); | ||
if (!in_array($feed, array('news', 'security'), true)) { | ||
return $this->failure('Invalid feed type'); | ||
} | ||
|
||
$enabled = $this->modx->getOption('feed_modx_' . $feed . '_enabled', null, true); | ||
if (!$enabled) { | ||
return $this->failure(); | ||
} | ||
|
||
$url = $this->modx->getOption('feed_modx_' . $feed); | ||
// Check if the domain is valid before attempting to load it | ||
$feedHost = parse_url($url, PHP_URL_HOST); | ||
if ($feedHost && function_exists('checkdnsrr') && !checkdnsrr($feedHost, 'A')) { | ||
return $this->failure(); | ||
} | ||
|
||
return $this->loadFeed($url); | ||
} | ||
|
||
public function loadFeed($url) | ||
{ | ||
$this->modx->loadClass('xmlrss.modRSSParser','',false,true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No particular reason. Mostly just copied the old code from the widgets into the processor, and that used it like this... getService is probably cleaner though. |
||
$this->rss = new modRSSParser($this->modx); | ||
|
||
$o = array(); | ||
$rss = $this->rss->parse($url); | ||
if (is_object($rss)) { | ||
foreach (array_keys($rss->items) as $key) { | ||
$item= &$rss->items[$key]; | ||
$item['pubdate'] = strftime('%c',$item['date_timestamp']); | ||
$o[] = $this->getFileChunk('dashboard/rssitem.tpl',$item); | ||
} | ||
} | ||
return $this->success('', array('html' => implode("\n",$o))); | ||
} | ||
|
||
/** | ||
* @param string $tpl | ||
* @param array $placeholders | ||
* @return string | ||
*/ | ||
public function getFileChunk($tpl,array $placeholders = array()) { | ||
$output = ''; | ||
$file = $tpl; | ||
if (!file_exists($file)) { | ||
$file = $this->modx->getOption('manager_path').'templates/'.$this->modx->getOption('manager_theme',null,'default').'/'.$tpl; | ||
} | ||
if (!file_exists($file)) { | ||
$file = $this->modx->getOption('manager_path').'templates/default/'.$tpl; | ||
} | ||
if (file_exists($file)) { | ||
/** @var modChunk $chunk */ | ||
$chunk = $this->modx->newObject('modChunk'); | ||
$chunk->setCacheable(false); | ||
$tplContent = file_get_contents($file); | ||
$chunk->setContent($tplContent); | ||
$output = $chunk->process($placeholders); | ||
} | ||
return $output; | ||
} | ||
} | ||
|
||
return 'modDashboardWidgetFeedProcessor'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really a failure ? Seems perfectly legit to have those disabled.
Or maybe is that because the request should have never occurred ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah... i should have reviewed the whole diff first!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this shouldn't actually trigger. Was tempted to take it out, and happy to do so if you think that's better ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, i'm fine with it (we can never assume only core components would use it).
I was just concerned about the "failure" semantic...