We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32525
    • 27 Posts
    Hi all, this is a really simple snippet called XmlExporter that I created to use ModX with a new Flash site I’m building. Just thought I’d share what I have here, not planning on expanding it much but feel free to let me know what you think:

    <?php
    /*
    
       XmlExporter
        v1.0
        By: Jim Hill @ Wiseguy Digital
        URL: http://www.wiseguydigital.com
    
        A very simple script to output a page's content as XML given a page id through the URL
        
        Parameters:
        ** Requires a get variable called 'pageId' to be set in the address bar e.g. http://www.mysite.com/xmlexporterpage.xml?pageId=5 **
        
        - allowedIPs
        Send through a list of allowed IP addresses to access the data
    
        Example call:
        [!FlashXmlExporter? &allowedIPs = `123.456.789.101,123.789.987.125`!] 
    
        EASY STEPS:
        1. Create your xml page. Make sure to set the output as XML and use blank as the template.
        2. Add the snippet call to this page.
        3. In your browser open up the page and add the GET variable in the address bar by adding this at the end:
            ?pageId=2
    
    */
    $allowedIPs = (isset($allowedIPs))? $allowedIPs : '' ;
    
    // Check for a page ID
    if (!isset($_GET['pageId'])) die ('You need an ID');
    
    // Check they are allowed
    if ($allowedIPs != '')
    {
        $match = false;
        $IPs = explode(',' , $allowedIPs);
        foreach ($IPs as $IP)
        {
            if ($IP == $_SERVER['REMOTE_ADDR']) $match = true;
        }
        if (!$match) die ('You are not authorised to view this page');
    }
    
    $xml = '';
    $nl = "\n";
    $tab = "\t";
    
    $xml .= '<?xml version="1.0"?>' . $nl;
    $xml .= '<pagedata>' . $nl;
    
    // Get the document's information
    $doc = $modx->getDocumentObject('id', $_GET['pageId']);
    foreach ($doc as $key => $value)
    {
         $xml .= $tab . '<' . $key . '><![CDATA[' . $value . ']]></' . $key . '>' . $nl;
    }
    
    $xml .= '</pagedata>' . $nl;
    
    return $xml;
    ?>