We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28033
    • 925 Posts
    <?php
    // --------------------
    // SNIPPET: PopUpGuide
    // --------------------
    // Version: 1.0
    // Date: January 6th, 2008
    // Plugin By: Soshite on ModXCMS.com ([email protected])
    // A big thanks goes to...
    // - BobRay (Sr. Member)
    // - sottwell (Documentation Team)
    //
    // This snippet is designed to output a selected guide in a new page.
    // The document that has the snippet call should be a "minimal" template, w/out any formatting.
    // Thus, you could put DIV layers in between the snippet call to create a header+footer for info about the guide author, etc.
    // If you need multiple URL parameters, duplicate this plugin, and change $urlParam.
    // Note that HTML entities are removed when the file is parsed, so there shouldn't be any injection issues. ;)
    
    // CONFIGURATION SETTINGS
    
        // $urlParam [string]
        // By default, the plugin uses "data" for it's the URL parameter, but you can change it here.
        $urlParam = isset($urlParam) ? $urlParam : 'data';
    
    // END CONFIG SETTINGS --- DO NOT EDIT BELOW THIS LINE
    
    $filename = $_GET[$urlParam]; // Grab the url parameter
    
    $text = file_get_contents ($filename);
    $output='<div id="header"><div class="float"><p></p>Hosted by <a href="http://symphonicheaven.com">Symphonic Heaven</a><br />*Permission from the author of this guide was obtained before it was uploaded to the website.*<br><br><b><a href="'.$filename.'">Download Original Version (.txt)</a></b><p></p></div></div><div class="fileOutput">';  // so you can style it
    $output .= '<pre>';
    $output .= htmlentities($text, ENT_QUOTES);
    $output .='</pre>';
    $output .='</div><div id="footer"><div class="float"><p></p>Hosted by <a href="http://symphonicheaven.com">Symphonic Heaven</a><br />*Permission from the author of this guide was obtained before it was uploaded to the website.*<br><br><b><a href="'.$filename.'">Download Original Version (.txt)</a><p></p></div></div>';
    return $output;
    ?>


    Of course, before I put this up, I’ll change some values (like the link to my website) to a "default" value, etc. I just need some help doing some final touches to the script...

    Currently, I have to put in a full URL for the $filename value, such as http://symphonicheaven.com/downloads/guides/walkthroughs/innocence/kouli.txt. How could I change that so it would automatically insert a value that is already defined? Would something like...

    $css = isset($css) ? $css : 'tab3';


    And defining the $_____ value right before $filename work?

    And is there any way for MODx to grab the filesize of the file and return that value? (Not in this script, but in general.) Look at this page...

    http://symphonicheaven.com/nds/innocence/downloads/guides.php

    I want to show the filesize of the file there. I’m guessing I could use a slimmed-down template of FileDownload (w/ just the filesize part)?
      My Snippets
      -> PopUpChunk v1.0
      • 3749
      • 24,544 Posts
      If you’re in a snippet,
      $fSize = filesize ( $filename );

      will work for files less than 2 gig. If they’re bigger than that, it will still work but you need format the output.

      If you’re not in a snippet, you could always create a one-line snipppet like the following:

      [[FileSize? &filename=`myfile`]]


      Snippet code:
      return filesize($filename);

      BTW, maybe you have some reason for doing it the way you are, but normally, the header and footer stuff would be included in the page template so as not to clutter up your snippet. Often, they’d go in chunks and the chunk call would go in the template. I don’t see any reason for including them here, but maybe I’m missing something.

      Bob
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 28033
        • 925 Posts
        I did that so the user wouldn’t have to 1) create a template for it --- let’s say they wanted to include this in normal page, and 2) the link to the original file wouldn’t work outside of the snippet.

        Thanks for the file download solution, btw. smiley

        EDIT: Nvm if you saw the previous edit. I forgot to do a root path to it.
          My Snippets
          -> PopUpChunk v1.0
          • 27708 MODX Staff
          • 2,502 Posts
          Personally, I like when simple snippets have a default template and then the user can play with the snippet without having to create 1, 2 or 3 chunks. The problem on the coding side is that you now need to add variables, a template checker, a template parameter and a placeholder replacer.

          To keep your sanity for this snippet (even though I’ve done the very things I said above in a very small snippet) I would just leave it as is and allow the user to edit the output.

          The only thought would be to use the heredoc syntax instead of the multiline variable declaration so that people don’t break the html part of your template. See below:

          <?php
          $output = <<<EOD
          	
          <div id="header">
          <div class="float">
          <p>Hosted by <a href="http://symphonicheaven.com">Symphonic Heaven</a></p>
          <p>*Permission from the author of this guide was obtained before it was uploaded to the website.*</p>
          <strong><a href="$filename">Download Original Version (.txt)</a></strong>
          </div>
          </div>
          <div class="fileOutput">
          <pre>
          htmlentities($text, ENT_QUOTES)
          </pre>
          </div>
          <div id="footer">
          <div class="float">
          <p>Hosted by <a href="http://symphonicheaven.com">Symphonic Heaven</a></p>
          <p>*Permission from the author of this guide was obtained before it was uploaded to the website.*</p>
          <p><strong><a href="$filename">Download Original Version (.txt)</a></strong></p>
          </div>
          </div>
          EOD;
          ?>
          


          I decided since I was going to post the code I would clean it up. It is not a good practice to use empty paragraphs to space vertical elements nor is it good to use the
          element to space. In addition, I changed the <b> element to <strong> which is the more semantic way to mark up text that should be displayed with "strong" emphasis. If you need to add space to the elements in the built in template you can either use the style property and add spacing to the element or to use a stylesheet.
            Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
            • 3749
            • 24,544 Posts
            Nice cleanup and tips. My only suggestion would be to indent the divs. I’m pretty sure SmashingRed would have done so in "real life." On the forums, it tends to push things off the screen. I’d also put comments in indicating the end of a div since </div> is ambiguous to humans.

            <?php
            $output = <<<EOD
            	
            <div id="header">
                <div class="float">
                    <p>Hosted by <a href="http://symphonicheaven.com">Symphonic Heaven</a></p>
                    <p>*Permission from the author of this guide was obtained before it was uploaded to the website.*</p>
                    <strong><a href="$filename">Download Original Version (.txt)</a></strong>
                </div>  <!-- end of float div -->
            </div>  <!--  end of header div -->
            <div class="fileOutput">
                <pre>
                    htmlentities($text, ENT_QUOTES)
                </pre>
            </div> <!--  end of fileOutput div -->
            <div id="footer">
                <div class="float">
                    <p>Hosted by <a href="http://symphonicheaven.com">Symphonic Heaven</a></p>
                    <p>*Permission from the author of this guide was obtained before it was uploaded to the website.*</p>
                    <p><strong><a href="$filename">Download Original Version (.txt)</a></strong></p>
                </div> <!--  End of float div -->
            </div> <!--  end of footer div -->
            EOD;
            ?>
            


            Bob


              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 27708 MODX Staff
              • 2,502 Posts
              Yes, Bob, I actually posted it with the indents but it looked like hell when I did the preview so I went back and did it all to the left margin. Comments are always a good idea.

              Cheers,

              Jay
                Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
                • 28033
                • 925 Posts
                Hmm..I didn’t know about that EOD thing...*jots that down in his notes*

                Yeah, I hadn’t really had the time yet to do that stuff you guys did to it --- I just was doing it quick to make sure that it actually worked. laugh

                (BTW, what would be the difference between b and strong, semantics-wise?)
                  My Snippets
                  -> PopUpChunk v1.0
                  • 27708 MODX Staff
                  • 2,502 Posts
                  Quote from: Soshite at Jan 10, 2008, 06:40 AM

                  ...(BTW, what would be the difference between b and strong, semantics-wise?)

                  For web standards oriented designers using presentational markup in HTML documents like <b> for bold which means make the text weight bold. Strong means strong emphasis and is less presentational and more informative. While the difference is not apparent to the end user it is to the web designer/developer. (References 1, 2)

                  You will likely find that most Rich Text editors will actually use <strong> and <em> in the markup instead of <b> and <i> even though they use B and I in their toolbars (not including the one here in SMF). You are free to use both <b> and <i> but most standards wonks will shun them.

                  There is a viewpoint (one that I share) that <i> has a place in HTML as it is typographical function. When indicating the title of a book or name of a sailing vessel it is supposed to be presented in italics. In this case it becomes part of the grammar and no longer a presentational element (no more than an exclamation point or a comma).

                  If you are developing Open Source that contains HTML it is best to be as standards compliant as possible to ensure that people don’t have to refactor just to make it valid or semantic.

                  Cheers,

                  Jay
                    Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
                    • 3749
                    • 24,544 Posts
                    I’m lazy and usually use <b> and <i> but Jay is right. Using <i> for specific things that should be in italics like book titles and <em> for other things that you want to emphasize allows you to style the <em> stuff without affecting the book titles.

                    Bob
                      Did I help you? Buy me a beer
                      Get my Book: MODX:The Official Guide
                      MODX info for everyone: http://bobsguides.com/modx.html
                      My MODX Extras
                      Bob's Guides is now hosted at A2 MODX Hosting