I'm using mod_feed. I'm calling in an RSS feed from the Joomla! security strike team http://feeds.joomla.org/JoomlaSecurityNews. I want to show certain parts of that feed on our Joomla! User Group site.

The variable is $text and echoing that fires out some HTML. That is the default action of mod_feeds. If I copy and paste the outputted HTML it works well. See below.


As soon as I use $text it stops working. But if I then copy the HTML into the file and set that as $text it works.

Why won't it work with the HTML that Joomla! creates?


        $doc = new DOMDocument();
        $xpath = new DOMXPath($doc);
        $feed_items = $xpath->query('//div[contains(@class, "newsfeed")]');

        foreach ($feed_items as $feed_item) {
            $impact_node = $xpath->query('*/li[contains(string(), "Impact:")]', $feed_item);
            $impact = preg_replace('/Impact:\W*/', '', $impact_node->item(0)->textContent);
            echo "Impact: " . $impact . "\n";
            $severity_node = $xpath->query('*/li[contains(string(), "Severity:")]', $feed_item);
            $severity = preg_replace('/Severity:\W*/u', '', $severity_node->item(0)->textContent);
            echo "Severity: " . $severity . "\n";
  • Are you able to sniff out what is causing the breakage? stackoverflow.com/q/1759069/2943403 have you inspected the text with var_dump() to see if there is any hidden characters? Have you tried libxml_use_internal_errors(true); (ex. stackoverflow.com/a/50407779/2943403) Not a solution, but an alternative processing snippet: 3v4l.org/R1A7i
    – mickmackusa
    Jan 17 '20 at 22:58
  • I don't really understand what the var_dump() is doing to help me. dev.joomlalondon.co.uk it's on this page at the moment. I don't really know what I'm looking for. I did libxml_use_internal_errors(true), again I don't know what to expect to see. I had a look at the other posts, I set up the function suggested, that has changed nothing. I tried your alternate syntax, still nothing I'm afraid.
    – Eoin
    Jan 17 '20 at 23:40
  • There are no qualifying nodes in the $text that you are using. IOW, no tag with the required class in your first first xpath->query(). 3v4l.org/uoaSJ Do I misunderstand the point where $text is being declared/used?
    – mickmackusa
    Jan 18 '20 at 0:35
  • Oh man, what an idiot! Thanks! The .newsfeed class is in the div before it. MUPPET!
    – Eoin
    Jan 18 '20 at 1:02
  • How shall we resolve this page then? Do you want to retract or shall I try to answer? I'm not fussed either way. Did you perform a preparation step upon $text that is not shown? You can of course answer if you wish. You are demonstrating some good DOMDocument and XPath techniques here.
    – mickmackusa
    Jan 18 '20 at 1:02

As indicated by your iterated var_dump() outputs on your dev page, the HTML strings that are in $text do not contain the class value required in your first $xpath->query().

There are no generated errors, just a logical hiccup. The parent div that you expected was not included in the string -- so the foreach() is never entered.

This is one of your $text strings:

<li><strong>Project:</strong> Joomla!</li>
<li><strong>SubProject:</strong> CMS</li>
<li><strong>Impact:</strong> Low</li>
<li><strong>Severity:</strong> <span class="label label-info">Low</span></li>
<li><strong>Versions:</strong> 3.8.0 - 3.9.13</li>
<li><strong>Exploit type:</strong> Path Disclosure</li>
<li><strong>Reported Date:</strong> 2019-November-22</li>
<li><strong>Fixed Date:</strong> 2019-December-17</li>
<li><strong>CVE Number:</strong> <a href="https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2019-19845">CVE-2019-19845</a></li>
<p>Missing access check in framework files could lead to a path disclosure.</p>
<h3>Affected Installs</h3>
<p>Joomla! CMS versions 3.8.0 - 3.9.13</p>
<p>Upgrade to version 3.9.14</p>
<p>The JSST at the <a title="Contact the JSST" href="https://developer.joomla.org/security-centre.html">Joomla! Security Centre</a>.</p>
<div class="alert alert-info"><strong>Reported By: </strong>Lee Thao, Viettel Cyber Security</div><div class="feedflare">
<a href="https://feeds.joomla.org/~ff/JoomlaSecurityNews?a=_fWsZ57Sw7g:uVTwWaDiNQ0:yIl2AUoC8zA"></a>

You can use my snippet below to process the html string: (Demo)

$doc = new DOMDocument();
$xpath = new DOMXPath($doc);
$impact_node = $xpath->query('//li[contains(string(), "Impact:")]');
echo "Impact: " . str_replace('Impact: ', '', $impact_node->item(0)->textContent);
echo "\n";
$severity_node = $xpath->query('//li[contains(string(), "Severity:")]/span[contains(@class, "label-info")]');
echo "Severity: " . $severity_node->item(0)->textContent . "\n";


Impact: Low
Severity: Low
  • But I still need to do a foreach on the <ul>. is there a way to target the UL without a class? I tried $feed_items = $xpath->query('//ul'); and also $feed_items = $doc->getElementsbyTagName("ul");
    – Eoin
    Jan 18 '20 at 11:02
  • 1
    Pass me the entire html string as a 3v4l demo and I'll parse the whole thing for you ...when I get a chance (just left Elton John).
    – mickmackusa
    Jan 18 '20 at 12:01
  • Nice! I assume you mean a concert and not his house :) Actually now I look at it, the HTML you have just repeats. I think the easiest way would be to append a containing div with a class, which I can do myself and use the existing code. Woohoo.
    – Eoin
    Jan 18 '20 at 12:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.