We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24648
    • 20 Posts
    Hi!

    I already posted in the General Repository Items Support forum regarding xslt because I simply can’t get rss feeds to display on my site.

    I’m now trying a different approach using a custom php file, which works perfectly when directly opened in the browser, but when I include the same file as a snippet on my site, it just doesn’t want to display the feeds.

    For testing purposes, I put some simple, static text before <?php, which does get displayed, so the call to the file must be working.

    This is the content of the example.php file:

    <p>normal text</p>
    
    <?php include("newsfeed/inc2/id_rss.inc"); ?>
    


    The id_rss.inc is the file I found on the net, and it works, since I can see the feeds if I open the example.php directly.

    But on my site, all it spits out is the normal text:

    <div id="worldnews_content"><p>normal text</p></div>
    


    Template:

    <div id="worldnews_content">[!rss!]</div>
    


    rss snippet:

    <?php
    include("example.php");
    ?>
    


    I just don’t understand why it does that to me :’(

    Can anyone please help?
      • 24648
      • 20 Posts
      thanks for your reply, the url is http://www.omnex.at

      in the top left box you’ll see the texts from the include files, the file example.php outputs rss feeds, as you can see if you go to http://www.omnex.at/example.php

      when looking at the source of index.php, there’s nothing but the normal text, no other tags, no nothing...
        • 24648
        • 20 Posts
        P.S.: is there maybe some kind of security setting in modx that has to be deactivated in order to include remote files or something?

        P.P.S.: is there any other info you need? I can post the whole template or the phpinfo output if that helps (though I doubt that it has something to do with that)?

        thanks again
          • 24648
          • 20 Posts
          thanks for your reply!

          yes, I’m using include() twice, but that’s just for troubleshooting. first time I tried, I included the id_rss.inc directly, which didn’t work either. since it works in the example.php, I thought it must work if I just include the example.php on my site - but to my surprise it doesn’t.

          regarding the paths, since the normal text in those files does show on my site, the paths must be correct - otherwise there would be nothing at all. if you got to the site, you’ll see the
          "text from example.php
          text from id_rss.inc"

          so those files are included, just not the ’dynamic’ content that comes from the feed(s).

          I’ve also already tried putting the included files in the root directory and not use any path, renaming the id_rss.inc to .php and including it directly as a snippet without the example.php, but nothing’s changed.
            • 24648
            • 20 Posts
            I’m sorry but I just don’t understand why the paths can be the problem, if I can prove that the file is included?

            I’ve simplified it now, not using any paths and not using the example.php

            this is the part of the template with the snippet call:

            <div id="worldnews_content">[[rss]]</div>
                    </div>


            this is the snippet:

            <?php
            include("id_rss.php");
            ?>


            this is the content of the id_rss.php file (taken from the net):

            <p>text from id_rss.php</p>
            
            <?php
            
            /*
            Created by SW Designs
            http://www.swdesigns.biz
            */
            
            
            
            $file = "http://rss.orf.at/news.xml";
            
            $rss_channel = array();
            $currently_writing = "";
            $main = "";
            $item_counter = 0;
            
            
            function startElement($parser, $name, $attrs) {
               	global $rss_channel, $currently_writing, $main;
               	switch($name) {
               		case "RSS":
               		case "RDF:RDF":
               		case "ITEMS":
               			$currently_writing = "";
               			break;
               		case "CHANNEL":
               			$main = "CHANNEL";
               			break;
               		case "IMAGE":
               			$main = "IMAGE";
               			$rss_channel["IMAGE"] = array();
               			break;
               		case "ITEM":
               			$main = "ITEMS";
               			break;
               		default:
               			$currently_writing = $name;
               			break;
               	}
            }
            
            function endElement($parser, $name) {
               	global $rss_channel, $currently_writing, $item_counter;
               	$currently_writing = "";
               	if ($name == "ITEM") {
               		$item_counter++;
               	}
            }
            
            function characterData($parser, $data) {
            	global $rss_channel, $currently_writing, $main, $item_counter;
            	if ($currently_writing != "") {
            		switch($main) {
            			case "CHANNEL":
            				if (isset($rss_channel[$currently_writing])) {
            					$rss_channel[$currently_writing] .= $data;
            				} else {
            					$rss_channel[$currently_writing] = $data;
            				}
            				break;
            			case "IMAGE":
            				if (isset($rss_channel[$main][$currently_writing])) {
            					$rss_channel[$main][$currently_writing] .= $data;
            				} else {
            					$rss_channel[$main][$currently_writing] = $data;
            				}
            				break;
            			case "ITEMS":
            				if (isset($rss_channel[$main][$item_counter][$currently_writing])) {
            					$rss_channel[$main][$item_counter][$currently_writing] .= $data;
            				} else {
            					$rss_channel[$main][$item_counter][$currently_writing] = $data;
            				}
            				break;
            		}
            	}
            }
            
            $xml_parser = xml_parser_create(); 
            xml_set_element_handler($xml_parser, "startElement", "endElement"); 
            xml_set_character_data_handler($xml_parser, "characterData"); 
            
            $ch = curl_init(); 
            curl_setopt($ch, CURLOPT_URL, $file); 
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
            $xmldata = curl_exec($ch); 
            curl_close($ch); 
            
            $xmldata = split("\n",$xmldata); 
            
            foreach ($xmldata as $data) { 
                if (!xml_parse($xml_parser, $data)) { 
                    die(sprintf("XML error: %s at line %d", 
                                xml_error_string(xml_get_error_code($xml_parser)), 
                                xml_get_current_line_number($xml_parser))); 
                } 
            }  
            xml_parser_free($xml_parser);
            
            // output HTML
            // print ("<div class=\"channelname\">" . $rss_channel["TITLE"] . "</div>"); 
            
            if (isset($rss_channel["ITEMS"])) {
            	if (count($rss_channel["ITEMS"]) > 0) {
            		for($i = 0;$i < count($rss_channel["ITEMS"]);$i++) {
            			if (isset($rss_channel["ITEMS"][$i]["LINK"])) {
            			print ("\n<div class=\"itemtitle\"><a target=blank href=\"newsfeed/inc2/go.php?url=" . $rss_channel["ITEMS"][$i]["LINK"] . "\">" . $rss_channel["ITEMS"][$i]["TITLE"] . "</a></div>");
            			} else {
            			print ("\n<div class=\"itemtitle\">" . $rss_channel["ITEMS"][$i]["TITLE"] . "</div>");
            			}
            			 print ("<div class=\"itemdescription\">" . $rss_channel["ITEMS"][$i]["DESCRIPTION"] . "</div><br />"); 		}
            	} else {
            		print ("<b>There are no articles in this feed.</b>");
            	}
            }
            
            ?>
            


            and this is the output on my site:

            <div id="worldnews_content"><p>text from id_rss.php</p>
            
            </div>
            


            so, there’s proof that id_rss.php is included correctly, otherwise there would be no "<p>text from id_rss.php</p>"

            or is there something I’m not understanding on a fundamental level?

            (I’m now going to put the php code from id_rss.php directly into the snippet, without including anything)
              • 24648
              • 20 Posts
              as expected, that didn’t change anything, apart from me now being sure that the problem is somewhere in modx - and now that I think of it and looking at the feed output in example.php, I’m guessing that special characters are the problem - since those are german newsfeeds, they’re full of ö, ä, ü,... Do I have to convert those to &auml, etc.?
                • 24648
                • 20 Posts
                I’ve tried around a bit more (sorry for spamming rolleyes )

                using a different feed, from bbc, doesn’t work either, so I’m not sure if special characters are the problem.

                also, to be sure, I copied my template to the example.php to see if maybe the doctype causes problems, but it still works there. it’s also using the same css file, so that can’t be it either...

                so I’m 100% sure now that either modx itself or something in the php code is causing the problem (or to be precise, something in the php code causing a problem in modx).

                any ideas?
                  • 24648
                  • 20 Posts
                  http://omnex.at/phpinfo.php if that helps...
                    • 24648
                    • 20 Posts
                    ok, the problem is solved, thanks to the very helpful modx team, especially ganeshXL who finally got it working!

                    turns out my webhost is causing the problem, so sorry for suspecting modx of causing a problem  undecided

                    thanks again and kudos to the modx team!