We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13284
    • 95 Posts
    Greetings everyone,

    My site is at: http://www.tapanime.com/cms/

    I’m trying to get a news feed to work on MODx I don’t know if I can do it the way I’m trying or if there is something else I have to do. I use to just run the code on my php page in an iframe on my regular site and of course I’m switching over to MODx once I learn and install what I need to make it work.

    To the point here is the code as I have it now:

    // Connect to database
    $mysql_connection = mysql_connect("localhost", "tapanime_newstes", "yes");
    if (!$mysql_connection) die("mysql_connect() failed");
    if (!mysql_select_db("tapanime_newstest", $mysql_connection))
       die("mysql_select_db() failed");
    
    // Fetch the stored news
    $result = mysql_query("SELECT * FROM annNews");
    if (!$result) die(mysql_error());
    $annNews = mysql_fetch_array($result);
    
    // If the news were last updated more than one hour ago, re-update them
    if ($annNews['last_query'] < time() - 3600 or trim($annNews['news']) == "")
    {
       // Fetch the news from ANN
       // You need to put your own username and password here
       $a = file("http://animenewsnetwork.com/newsfeed/getnews.php?u=jinto76&p=newstest");
       $n = addslashes(trim(implode("", $a)));
    
       // Save the news to the database
       $query = "UPDATE annNews SET last_query=UNIX_TIMESTAMP()";
       if ($n)
       {  $query .= ", news='$n'";
          $annNews['news'] = stripslashes($n);
       }
       mysql_query($query);
    }
    
    // Display the news
    echo $annNews['news'];
    


    Originally on my current site it has the: <? ?> If I keep those in I get this error:

    Parse error: parse error, unexpected '<' in /home/tapanime/public_html/cms/manager/includes/document.parser.class.inc.php(705) : eval()'d code on line 1


    The call I’m using on the index.php is: [!ann-news!] so it is uncached.

    In the source cache section I see this I don’t know if it means anything:
    <?php die('Unauthorized access.'); ?>

    I don’t see why it would since my current site still pulls the news.

    Any thoughts on how to get this to work in MODx?

    INFO
    Webserver:
    PHP version - 4.3.11
    MySQL version - 4.1.21-standard
    Operating System and version - Linux and Apache 1.3.33

    Browser name and version - FireFox 1.5.0.7
    Operating System and version - Windows XP Home and added SP1

    Website: http://www.tapanime.com
    MODx Test Site: http://www.tapanime.com/cms/
      • 22303 MODX Staff
      • 10,725 Posts
      @Izumi
      You cannot use PHP tags (i.e. <? or <?php or ?>) within a MODx snippet. Think of a snippet as a PHP function that gets called, potentially multiple times per page, a function that is pure PHP code only; enforcing this separation of PHP logic and the output is at the heart of the MODx philosophy.

      From what I can tell though you don’t need them at all, so just remove them and it should work fine.

      Plus, just a side note, you don’t really want to call die() in your snippet, as that will stop generation of the entire MODx page so that nothing is output but the message in the call to die(). Not really a smooth way to handle an error when coding for a CMS engine at all.
        • 13284
        • 95 Posts
        Thanks for the reply OpenGeek,

        I currently don’t have the

        <? ?>


        There still isn’t any news being generated, so it seems it might be the die command?

        As for the die I didn’t do the code this is the code they told me to use so what should I remove for that die command? Could that be the reason why it might not be getting the news?

        Thanks for the help
          • 13284
          • 95 Posts
          Well that was interesting.

          I think I accidentally messed up the code I did a quick recopy and bam there it all is.

          Tons of Thanks OpenGeek for you time.