We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28471
    • 48 Posts
    Quote from: Mitch at Mar 01, 2006, 04:30 PM

    I recently made a similar snippet for my site to just show filelistings. It has some extra features (and misses some of this one smiley ). I will just list them here for reference. If interested I could put up the code so it can be integrated (code is still a bit messy, but it works).

    - Sort by filename, date, size or extension
    - Sort ascending or descending
    - Show only selected extensions
    - Show icons based on file extension (.doc files will have Word icon, .pdf will have Acrobat icon etc...)
    - Delete files (for selected webgroups)

    I have one pending request from the website manager and that is to have the possibility to rename files. Right now she has to delete the file and upload it again. (I use it in combination with the fileupload snippet posted somewhere else on this forum)

    Yes mitch, this is a great idea, dont worry about the code, that be cleaned up....
      • 28471
      • 48 Posts
      Quote from: kjaebker at Feb 28, 2006, 05:19 PM

      ***** Update 03/01/06 ******
      After seeing the comments here and some of the work done, I have updated the FileDownload Snippet.

      I added the code for usign a template, thanks to Robin for getting that going.
      I also added the ability to get a description from a chunk (Great idea Susan), so you can update the info in the manager.
      The ability to have alternating odd/even row highlighting is still there as well.

      *******************


      One thing with the snippet, the parts with die() should be changed to either return some text or false, so it can still work in with the current modx template.
        • 6726
        • 7,075 Posts
        Yo, sweet changes !

        Thanks guys !!!
          .: COO - Commerce Guys - Community Driven Innovation :.


          MODx est l'outil id
          • 15987
          • 786 Posts
          I will work on getting the die comments taken out.

          Briggsy:

          What version of php are you using. I think the error may be because I pass an array by referance in a foreach loop. I think that was added in php 5. If that is the case I will have to see if there is a way to do this to make it compatible with php4.
            • 4095
            • 372 Posts
            Quote from: kjaebker at Mar 02, 2006, 02:48 PM

            What version of php are you using. I think the error may be because I pass an array by referance in a foreach loop. I think that was added in php 5. If that is the case I will have to see if there is a way to do this to make it compatible with php4.

            v4.4.1, compatiability with pre v5.0 would be good if you have time to do it.

            Cheers.
              [img]http://www.emanz.ac.nz/assets/images/logo/emanz-icon_16x16.gif[/img] Emergency Management Academy of New Zealand [br] http://www.emanz.ac.nz[br][br]MODx Sandbox Login: sandbox Password: castle [br]
              Admin Sandbox Login: sandbox Password: castle
              • 28471
              • 48 Posts
              Quote from: kjaebker at Mar 02, 2006, 02:48 PM

              I will work on getting the die comments taken out.

              Briggsy:

              What version of php are you using. I think the error may be because I pass an array by referance in a foreach loop. I think that was added in php 5. If that is the case I will have to see if there is a way to do this to make it compatible with php4.

              No probs, just substitute foreach loop with a while loop and work directly with the array, than it wont matter what php version your using.

                      foreach ($files as &$fOutput) {
                          if ($fOutput['name'] == $fileInfo[0]) {
                              $fOutput['description'] = $fileInfo[1];
                              break;
              


              No need to pass copy or reference, just work directly with array. Note: I just did this off top of head, may need a minor change.

              reset($files);
              while (list($key, $value) = each($files)) {
                    if ($files[$value]['name'] == $fileinfo[0])
                   {
                       $files[$key]['description'] = $fileinfo[1];
                      break;
                   }
              }
              

                • 4095
                • 372 Posts
                Quote from: stempy at Mar 02, 2006, 07:48 PM

                No probs, just substitute foreach loop with a while loop and work directly with the array, than it wont matter what php version your using.
                No need to pass copy or reference, just work directly with array. Note: I just did this off top of head, may need a minor change.

                I changed that one but it still doesn’t work. I’m not a coder so not sure what else to do, I notice there are other foreach loops but no idea how to alter them.

                foreach ($files as $file) {
                    $tpl2 = $tpl['row'];
                    if ($useHlt) {
                      if ($i++ & 1) {
                        $tpl2 = str_replace("<tr>","<tr class='$oddClass'>",$tpl2);
                      } else {
                        $tpl2 = str_replace("<tr>","<tr class='$evenClass'>",$tpl2);
                      }
                    }


                Probably best I wait till its being updated since I’m in no hurry for it and hope it is made v4 & 5 compatible?
                  [img]http://www.emanz.ac.nz/assets/images/logo/emanz-icon_16x16.gif[/img] Emergency Management Academy of New Zealand [br] http://www.emanz.ac.nz[br][br]MODx Sandbox Login: sandbox Password: castle [br]
                  Admin Sandbox Login: sandbox Password: castle
                  • 15987
                  • 786 Posts
                  Brigsy, that is not where the error was occuring, unless this is another one sad. I have fixed the problem (I think), so if you could download the new version and test it that would be great. I also added support for filetype images. The instructions on how to use images are in the snippet code.

                  Heres a link I found for free filetype images:

                  http://www.zap.org.au/documents/icons/file-icons/
                    • 4095
                    • 372 Posts
                    Thanks, the new code makes it better smiley

                    Having trouble with icons though. I have a PDF icon already called pdf.gif which is in assets/images/icons

                    So I the array says
                    $imgTypes = array(
                                    'jpg' => 'file-image.png',
                                    'png' => 'file-image.png',
                                    'pdf' => 'pdf.gif',
                                    'txt' => 'file-document.png',
                                    'zip' => 'file-archive.png',
                                    'default' => 'file-generic.png',
                                );



                    I am calling the snippet as below (haven’t set up the row classes yet)

                    [!FileDownload1_2? &getFolder=`assets/files/resources` &chkDesc=`FileDownloadDesc` &tplList=`FileDownload` &useHlt=`1` &evenClass=`evenrow` &oddClass=`oddrow` &imgLocat=`assets/images/icons`!]

                    You can see it for yourself. Just log into my MODx Sandbox as per my message footer smiley
                      [img]http://www.emanz.ac.nz/assets/images/logo/emanz-icon_16x16.gif[/img] Emergency Management Academy of New Zealand [br] http://www.emanz.ac.nz[br][br]MODx Sandbox Login: sandbox Password: castle [br]
                      Admin Sandbox Login: sandbox Password: castle
                      • 15987
                      • 786 Posts
                      Brigsy, I looked at the source on your test page and think I found the problem. Did you add the [+image+] placeholder to your template? If not, you need to put that wherever you would like the image to show.

                      Let me know if that helps.

                      Kyle