We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 15871
    • 105 Posts
    OK, so here’s the deal.

    We’ve built this print designer inspiration site. One of the categories displays pages of a brochure using a simple jQuery to pull thumbnails and link to images.

    http://printspiration.com/direct-access-partners-brochure

    What we want to do is add a link to a popup that displays a new page with a Flash-based pageflip that lets the users flip through the brochure. All the images for the brochure are sitting in a folder on the server under the document id of the refering page (the link above) (i.e. /assets/pageimages/66/normal/). The pageflip reads from an XML file to function and I have setup an XML document in MODx with a snippet that creates an XML file on the fly but I can’t figure how to pass in the document ID.

    Here’s the code of the snippet:
    <?php
    // This snippet will generate an XML file used for the Free Page Flip software
    // Set the default variables
    
    $referer = (isset ($referer)) ? $referer : $modx->getDocument($_SESSION['referrer'],'*',1) //Trying to get the document ID of the referer here
    $docID = (isset ($docID)) ? $docID : $referer;// setting that to docID so I can use it int he script
    $filter = (isset ($filter)) ? $filter : '.jpg'; // Set the  filetype filter
    $width = (isset ($width)) ? $width : $modx->getTemplateVar($pageWidth, '*', $docID); // Get the page width of the piece from the refering document
    $height = (isset ($height)) ? $height : $modx->getTemplateVar($pageHeight, '*', $docID); // Get the page height of the piece from the refering document
    $directory = (isset ($directory)) ? $directory : 'assets/pageimgs/'.$docID.'/normal/'; // Where to look for images
    
    //Convert dimensions to pixels
    $tvWidth = ($width * 72) * 2; // This sets the toal width
    $tvHeight = $height * 72;
    
    // read through the directory and filter files to an array
    
    $d = dir($directory);
    if ($d) {
    while($entry=$d->read()) {
    $ps = strpos(strtolower($entry), $filter);
    if (!($ps === false)) {
    $items[] = $entry;
    }
    }
    $d->close();
    sort($items);
    }
    
    // Add an xml header and the opening tags
    header("content-type:text/xml;charset=utf-8");
    
    echo '<?xml version="1.0" encoding="utf-8"?>';
    
    // Load in the configuration settings for the pageflip
    echo '<content width="'.$tvWidth.'" height="'.$tvHeight.'" bgcolor="cccccc" loadercolor="ffffff" panelcolor="5d5d61" buttoncolor="5d5d61" textcolor="ffffff">';
    
    // now, loop through the file list
    
    for($i=0; $i<sizeof($items); $i++) {;
    echo ' <page src="'.$directory.''.$items[$i].'" />';
    }
    
    echo '</content>';
    ?>
    


    Of course, this renders a blank page. BUT, when I hard code the docID (to ’66’) it works.

    So the question is, how do I pass the documentID of the page linked above (66) and pass it to the next page which houses the Flash file which will then load up the XML file (http://printspiration.com/pageflip.xml) and pass that document ID down so the file renders correctly?

    Thoughts?
      • 10449
      • 956 Posts
      the link to the flash-popup could look something like this in the template:
      <a href="[~123~]?docid=[*id*]" target="_blank">click me!</a>


      modx doc 123 would be your pageflip page that houses the snippet which takes care of the SWF markup etc.

      This snippet would simply retrieve that query string:

      $docid = (int) $_GET["docid"];
      if($docid < 1) {
      exit("no valid document id received - aborting script");
      }
      
      // rest of your code here, for your XML etc.
      


      btw: you can set document headers within MODx, instead of within your snippet. Just use template = (blank) and in the 2nd tab, choose XML as filetype.
      For an extra little security measure, you could add a path-check somewhere in your code, to see if the passed id/folder actually exists:
      if(file_exists(...))
        • 15871
        • 105 Posts
        @ganeshXL

        Thanks for the info it got me in the right direction. I was able to get it to work correctly linking to the XML file directly. However I am using the SWFObject snippet to embed the Flash and I tried passing the FlashVars through but the were not rendering in the SWFObject all.

        [!SWFObject? &flashParam=`quality:"high", bgcolor:"0x000000"` &flashVars=`xmlconfig:"pageflip.xml",docID:"[*docID*]",pageWidth:"[*pageWidth*]",pageHeight:"[*pageHeight*]",bgImage:"assets/images/bg.jpg"` &mode=`static` &flashVersion=`8.0.0` &objId=`flippingBook` &swfFile=`assets/flash/flippingBook.swf` !]
        


        None of the variables are rendering. The XML file is being pulled, but the variables are not making into the URL string. Here’s the link that is generated dynamically on the refering page (http://printspiration.com/direct-access-partners-brochure) - look at the "test" links at the bottom of the second column.

        http://printspiration.com/pageflip?docID=66&pageWidth=9.5&pageHeight=7.5

        You’ll see that the code outputs like so:
                 <object id="flippingBook" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="600" height="400">
          <param name="movie" value="assets/flash/flippingBook.swf" />
          <param name="quality" value="high" />
          <param name="bgcolor" value="0x000000" />
          <param name="flashvars" value="xmlconfig=pageflip.xml&docID=&pageWidth=&pageHeight=&bgImage=assets/images/bg.jpg" />
          <!--[if !IE]>-->
          <object type="application/x-shockwave-flash" data="assets/flash/flippingBook.swf" width="600" height="400">
          <param name="quality" value="high" />
        
          <param name="bgcolor" value="0x000000" />
          <param name="flashvars" value="xmlconfig=pageflip.xml&docID=&pageWidth=&pageHeight=&bgImage=assets/images/bg.jpg" />
          <!--<![endif]-->
        <p>Please download Flash player <a href="http://www.adobe.com/go/getflashplayer">here</a>.</p>
          <!--[if !IE]>-->
          </object>
          <!--<![endif]-->
        </object>
        


        As you can see the variables don’t render. I tried making a snippet that used the $GET code, but that produced no results.

        Any ideas?

        Tnx
          • 33372
          • 1,611 Posts
          I haven’t read through all lof your code, but...

          Have you tried just alternating your cache settings? Sometimes the way that the MODx parser loops through nested snippet calls (in your case you have TVs nested inside the snippet call) can produce unexpected results when it doesn’t do it in the order that you expect. Usually I find that changing one of the cache settings (e.g., whether the page is cached or the snippet call is cached) reverses the order of the nested elements and makes everything work magically again.

          Also keep in mind that you can’t use the characters & or ? in snippet calls, so that’s probably why the GET method you tried didn’t work. If it’s possible that you’ll have those characters in your TV values then you might not want to use the TVs in the call in this way. I generally try to avoid nested calls like this now because I’ve been burned by this in the past (everything worked fine until one of the values passed in the call had an illegal character). You can use getTemplateVarOutput() within the snippet itself to get the values of those TVs, so you don’t actually need to pass them in the snippet call. I find this to be much less likely to produce headaches with dynamic content (content that can be generated once and cached is rarely a problem either way).
            "Things are not what they appear to be; nor are they otherwise." - Buddha

            "Well, gee, Buddha - that wasn&#39;t very helpful..." - ZAP

            Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
            • 15871
            • 105 Posts
            @ZAP

            Your post took me in a different direction. I figured out how to get the docID in to populate the variable for the XML attribute. So I now have the docid coming into the XML file correctly. but I can’t get the snippet to render out the Template Vars. Here’s the code:

            <?php
            $pID = (int) $_GET["docID"];
            if($pID < 1) {
            exit("no valid document id received - aborting script");
            }
            $tvSize = $modx->getTemplateVarOutput(array("pageWidth","pageHeight"),$docid='$pID');
            $width = $tvSize['pageWidth'];
            $height = $tvSize['pageHeight'];
            
            $filter = (isset ($filter)) ? $filter : '.jpg'; // Set the  filetype filter
            $directory = (isset ($directory)) ? $directory : 'assets/pageimgs/'.$pID.'/normal/'; // Where to look for images
            
            //Convert dimensions to pixels
            $tvWidth = ($width * 72) * 2; // This sets the total width
            $tvHeight = $height * 72;
            
            // read through the directory and filter files to an array
            
            $d = dir($directory);
            if ($d) {
            while($entry=$d->read()) {
            $ps = strpos(strtolower($entry), $filter);
            if (!($ps === false)) {
            $items[] = $entry;
            }
            }
            $d->close();
            sort($items);
            }
            
            // Add an xml header and the opening tags
            header("content-type:text/xml;charset=utf-8");
            
            echo '<?xml version="1.0" encoding="utf-8"?>';
            // Load in the configuration settings for the pageflip
            echo '<FlippingBook>';
            echo '<width>'.$tvWidth.'</width>';
            echo '<height>'.$tvHeight.'</height>';
            echo '<scaleContent>false</scaleContent>';
            echo '<firstPage>0</firstPage>';
            echo '<alwaysOpened> false </alwaysOpened>';
            echo '<autoFlip> 50 </autoFlip>';
            echo '<flipOnClick> true </flipOnClick>';
            echo '<staticShadowsDepth> 1 </staticShadowsDepth>';
            echo '<dynamicShadowsDepth> 2 </dynamicShadowsDepth>';
            echo '<moveSpeed> 2 </moveSpeed>';
            echo '<closeSpeed> 3 </closeSpeed>';
            echo '<flipSound>assets/media/01.mp3</flipSound>';
            echo '<pageBack> 0x1C90CB </pageBack>';
            echo '<loadOnDemand> true </loadOnDemand>';
            echo '<cachePages> true </cachePages>';
            echo '<cacheSize> 10 </cacheSize>';
            echo '<preloaderType> Progress Bar </preloaderType>';
            echo '<pages>';
            
            // now, loop through the file list
            
            for($i=0; $i<sizeof($items); $i++) {;
            echo ' <page>'.$directory.''.$items[$i].'</page>';
            }
            
            echo '</pages>';
            echo '</FlippingBook>';
            ?>
            


            This is the generate XML file link: http://printspiration.com/pageflip.xml&docID=66

            The ID pages in correctly, because the page’s directories are correct.

            Thoughts?
              • 33372
              • 1,611 Posts
              I think this line should be:
              $tvSize = $modx->getTemplateVarOutput(array("pageWidth","pageHeight"),$pID);
                "Things are not what they appear to be; nor are they otherwise." - Buddha

                "Well, gee, Buddha - that wasn&#39;t very helpful..." - ZAP

                Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
                • 15871
                • 105 Posts
                OK that worked. Now I just need to get the Flash file displaying correctly. Stay tuned...
                  • 33372
                  • 1,611 Posts
                  I’ll be interested to see it once you’re finished. People always ask us to do flip books for them, and I’ve never found one that works with an XML file before. I haven’t done one in a while, however.
                    "Things are not what they appear to be; nor are they otherwise." - Buddha

                    "Well, gee, Buddha - that wasn&#39;t very helpful..." - ZAP

                    Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
                    • 16545
                    • 358 Posts
                    Is This PageFlip flash script from flashpageflip.com?
                      • 10449
                      • 956 Posts
                      I think it’s this one: http://flippingbook.com/