We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17233
    • 15 Posts
    I use MODx Revolution 2.0.0-pl now, and have a problem with getting the values from snippets parameter

    example

    Snippet parameter:
    [[!snipp? &dir=`../files`]]

    ---------------------------------------------

    Inn the snippet code to get the values:
    dir = isset ($file)?$file:$_GET[’file’];


    I did not find any information about any change
    Please help

    Lisa
      • 28215
      • 4,149 Posts
      That’s because your passing $dir, not $file.
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 17233
        • 15 Posts
        sorry I wrote wrong

        Snippet parameter:
        [[!snipp? &dir=`../files`]]

        ---------------------------------------------

        Inn the snippet code to get the values:
        dir = isset ($dir)?$dir:$_GET[’dir’];

        please any
          • 28215
          • 4,149 Posts
          That should work.
            shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
            • 17233
            • 15 Posts
            no not on revolution 2.0.0 here

            if I change to dir = "dirfolder";
            in the code, it works

            I want to write the dir in the snippet parameter
            and since I change to modx 2.0.0 it does not work

              • 3749
              • 24,544 Posts
              Lisa, Snippet parameters definitely work in Revolution. All of us use them all the time.

              dir is the name of a PHP function. You should never use it (or any other PHP reserved word) for a parameter name.

                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
                • 17233
                • 15 Posts
                Dir is only an example, i could call it Lisa = `../files`, the point is, I can not get the value (../files) in the code in the snippet file.
                Let me post the code


                let make a document named
                Simpledownload

                parameters is:


                [[!simplefiledownload? &webgroup=`download_1`&`download_2`,&fileFolderURL=`../simplefiledownload/`,

                &file=`test.zip`,&file1=`test1.zip`,&file2=`simpledownload.zip`,&file3=``,&file4=``,&file5=``,&file6=``,&file7=``,

                &file8=``,&file9=``,&file10=``,&file11=``,&file12=``,&file13=``,&file14=``,&file15=``,

                &file16=``,&file17=``,&file18=``,&file19=``,&file20=``]]


                -----------------------------------------------------

                I make a outside snippet with links like these
                $snipFolder = isset($snipFolder)?$snipFolder:’simplefiledownload’;
                $snipPath = $modx->config["base_path"].’assets/snippets/’.$snipFolder.’/simplefiledownload.php’;
                include_once($snipPath);

                or

                $snipFolder = isset($snipFolder)?$snipFolder:’simplefiledownload’;
                $snipPath = $modx->config["base_path"].’core/components/’.$snipFolder.’/simplefiledownload.php’;
                include_once($snipPath);

                ---------------------------------------------------------------

                and the php file in snippet folder is

                <?php
                //gets inputs from snippet
                $webgroup = isset ($webgroup)?$webgroup:$_GET[’webgroup’];
                //gets inputs from snippet
                $fileFolderURL = isset ($fileFolderURL )?$fileFolderURL :$_GET[’fileFolderURL ’];

                # List of downloads, function for compare arrays --- start
                function array_isearch($str, $array) {
                $found = array();
                foreach($array as $k => $v)
                if(strtolower($v) == strtolower($str)) $found[] = $k;
                return $found;
                }
                # List of downloads, function for compare arrays --- end


                # array for download files --- start
                $Array_req = array();
                //gets inputs from snippet
                $Array_req[] = $file = isset ($file)?$file:$_GET[’file’];
                $Array_req[] = $file1 = isset ($file1)?$file1:$_GET[’file1’];
                $Array_req[] = $file2 = isset ($file2)?$file2:$_GET[’file2’];
                $Array_req[] = $file3 = isset ($file3)?$file3:$_GET[’file3’];
                $Array_req[] = $file4 = isset ($file4)?$file4:$_GET[’file4’];
                $Array_req[] = $file5 = isset ($file5)?$file5:$_GET[’file5’];
                $Array_req[] = $file6 = isset ($file6)?$file6:$_GET[’file6’];
                $Array_req[] = $file7 = isset ($file7)?$file7:$_GET[’file7’];
                $Array_req[] = $file8 = isset ($file8)?$file8:$_GET[’file8’];
                $Array_req[] = $file9 = isset ($file9)?$file9:$_GET[’file9’];
                $Array_req[] = $file10 = isset ($file10)?$file10:$_GET[’file10’];
                $Array_req[] = $file11 = isset ($file11)?$file11:$_GET[’file11’];
                $Array_req[] = $file12 = isset ($file12)?$file12:$_GET[’file12’];
                $Array_req[] = $file13 = isset ($file13)?$file13:$_GET[’file13’];
                $Array_req[] = $file14 = isset ($file14)?$file14:$_GET[’file14’];
                $Array_req[] = $file15 = isset ($file15)?$file15:$_GET[’file15’];
                $Array_req[] = $file16 = isset ($file16)?$file16:$_GET[’file16’];
                $Array_req[] = $file17 = isset ($file17)?$file17:$_GET[’file17’];
                $Array_req[] = $file18 = isset ($file18)?$file18:$_GET[’file18’];
                $Array_req[] = $file19 = isset ($file19)?$file19:$_GET[’file19’];
                $Array_req[] = $file20 = isset ($file20)?$file20:$_GET[’file20’];
                # array for download files --- end


                # Get page URL --- start
                function curPageURL() {
                $isHTTPS = (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on");
                $port = (isset($_SERVER["SERVER_PORT"]) && ((!$isHTTPS && $_SERVER["SERVER_PORT"] != "80") || ($isHTTPS && $_SERVER["SERVER_PORT"] != "443")));
                $port = ($port) ? ’:’.$_SERVER["SERVER_PORT"] : ’’;
                $url = ($isHTTPS ? ’https://’ : ’http://’).$_SERVER["SERVER_NAME"].$port.$_SERVER["REQUEST_URI"];
                return $url;
                }
                # Get page URL --- end



                # Download file --- start
                $getfilename = isset ($f)?$f:$_GET[’f’];

                if ($getfilename){
                // set this to the path where your zipped files are located
                $filepath = $fileFolderURL.$getfilename;
                // a little security
                //if(strpos($getfilename, ’..’) !== false || realpath($filepath) != $filepath) die();
                if (file_exists($filepath)){
                // make sure the browser knows what it’s getting, and what to do with it
                header(’Cache-Control: public’);
                header(’Content-Type: application/zip’);
                header(’Content-Disposition: attachment; filename=’.$getfilename);
                readfile($filepath);
                die();
                } else {
                //echo "no file";
                die(’Error: File not found.’);
                }
                }
                # Download file --- end



                # List of downloads --- start
                $area = $modx->isMemberOfWebGroup(array($webgroup));
                if ($area === true) {
                //echo ’Is a member of the group’;

                // open connection to folder
                if ($handle = opendir($fileFolderURL)) {
                // check if any files in folder
                while (false !== ($stored = readdir($handle))) {
                //unpack array
                $stored = explode(" ", $stored);
                //$Array_req = explode("&", $Array_req);
                //loop
                foreach($stored as $store) {
                //compare in function
                $results = array_isearch($store,$Array_req);
                //loops out result
                foreach($results as $key => $result){
                //print result in hyperlink
                echo "<a href=".curPageURL()."?f=".$Array_req[$result].">".$Array_req[$result]."</a>
                ";
                }//end foreach
                }//end foreach

                }//end while

                }//end opendir
                # List of downloads --- end



                } else {
                echo ’No access for you!’;
                }


                ?>

                --------------------------------------------

                simplefiledownload folder is outside public_HTML with zip files

                --------------------------------------------


                It workes in 1.3 and change tags [!!] to these for revolution to this
                [[!simplefiledownload? &webgroup=`download_1`&`download_2`,&fileFolderURL=`../simplefiledownload/`,

                &file=`test.zip`,&file1=`test1.zip`,&file2=`simpledownload.zip`,&file3=``,&file4=``,&file5=``,&file6=``,&file7=``,

                &file8=``,&file9=``,&file10=``,&file11=``,&file12=``,&file13=``,&file14=``,&file15=``,

                &file16=``,&file17=``,&file18=``,&file19=``,&file20=``]]


                for the test I took out the webgroup security

                but values does not show in phpfile


                any help would be great

                thanks
                  • 3749
                  • 24,544 Posts
                  Quote from: Lisa at Aug 11, 2010, 01:11 PM

                  Dir is only an example, i could call it Lisa = `../files`, the point is, I can not get the value (../files) in the code in the snippet file.
                  I don’t see anything wrong with your code, but I’m 99.9% sure that getting the parameter in the snippet is not the problem.

                  To make sure, put
                  &Lisa=`../files` 

                  as a parameter in the snippet tag and then put the following code at the top of the snippet, you should see that the parameter is coming through fine:

                  return $Lisa;


                  Then you can check &dir and &file to see if it makes any difference.
                    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
                    • 17233
                    • 15 Posts
                    ok I found the problem aahahahh

                    do not use those ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, grin

                    it works with this

                    [[!simplefiledownload? &fileFolderURL=`../simplefiledownload`
                    &file=`test.zip` &file1=`test1.zip` &file2=`simpledownload.zip` ]]

                    many thanks to you all

                    se you later grin
                      • 3749
                      • 24,544 Posts
                      Glad you got it worked out. smiley
                        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