We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6726
    • 7,075 Posts
    How did I miss that embarrassed !

    I’ll try with the right path...
      .: COO - Commerce Guys - Community Driven Innovation :.


      MODx est l'outil id
      • 6726
      • 7,075 Posts
      OK both work

      Now I’ll add function size_readable see if that works too...
      And it works.

      http://ns29452.ovh.net/~secusol/test_filesize.php

      What does it mean.
      It works outside MaxiGallery but not in it huh

      It works for GaneshXL and not for me, but then again I should test displaying the filesize on the image page, not the list galeries page, remember I am inserting the placeholder in gallerypicturetpl.html, not picturetpl.html, maybe this is the cause ?

        .: COO - Commerce Guys - Community Driven Innovation :.


        MODx est l'outil id
        • 7923
        • 4,213 Posts
        Hello and sorry for late participation to this topic, I was on a holiday all week.. Anyhow..

        I think it would be better to just create a new snippet (or a phx custom modifier if you want) and not to modify MaxiGallery code directly.

        You could create a snippet called "myfilesize" with following content (untested!):

        $mfz_path = (isset($mfz_path)) ? $mfz_path : ""; //path to the file
        
        if(!function_exists(size_readable)) {
        		function size_readable($size, $retstring = null) {
        		        // adapted from code at http://aidanlister.com/repos/v/function.size_readable.php
        		        $sizes = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
        		        if ($retstring === null) { $retstring = '%01.2f %s'; }
        		        $lastsizestring = end($sizes);
        		        foreach ($sizes as $sizestring) {
        		                if ($size < 1024) { break; }
        		                if ($sizestring != $lastsizestring) { $size /= 1024; }
        		        }
        		        if ($sizestring == $sizes[0]) { $retstring = '%01d %s'; } // Bytes aren't normally fractional
        		        return sprintf($retstring, $size, $sizestring);
        		}
        }
        return size_readable(filesize($mfz_path));
        


        And in maxigallery gallerypicturetpl use [[myfilesize? &mfz_path=`[(base_path)][+maxigallery.path_to_gal+][+maxigallery.picture.filename+]`]]


          "He can have a lollipop any time he wants to. That's what it means to be a programmer."
          • 6726
          • 7,075 Posts
          Wow great Doze thanks a lot I’ll try it out tomorrow and report, it’s getting late !
            .: COO - Commerce Guys - Community Driven Innovation :.


            MODx est l&#39;outil id
            • 6726
            • 7,075 Posts
            Okay Doze, well it doesn’t work but probably because I am trying to get the bigimg filesize from the child gallery list ?

            I inserted [[myfilesize? &mfz_path=`[(base_path)][+maxigallery.path_to_gal+]_big[+maxigallery.picture.filename+]`]]

            in gallerypicturetpl, this way :

            <img src="[(base_url)][+maxigallery.path_to_gal+]tn_[+maxigallery.picture.filename+]" class="thumbnail" title="[+maxigallery.picture_width_big+] x [+maxigallery.picture_height_big+] Taille du fichier : [[MG_File_Size? &mfz_path=`[(base_path)][+maxigallery.path_to_gal+]big_[+maxigallery.picture.filename+]`]]" alt="[+maxigallery.picture.filename+]" />


            I was careful to call MaxiGallery uncached since I have a cached snippet in the template... FYI I tried using the FileDetails snippet in the MaxiGallery template but it didn’t work either...

            Here is the MaxiGallery call :

            [!MaxiGallery? &view_gallery=`833` &manage_target=`833` &lang=`fr` &display=`embedded` &embedtype=`external` &pics_per_row=`2` &max_thumb_size=`200` &max_pic_size=`500` &max_big_size=`0` &keep_bigimg=`1` &titles_in_overview=`1` &keep_bigimg=`1` &pics_per_page=`4`!]


            I switched to a "static" ID for testing because I didn’t want to add the Ditto factor into this.

            What did I overlook ?
            Thanks !
              .: COO - Commerce Guys - Community Driven Innovation :.


              MODx est l&#39;outil id
              • 7923
              • 4,213 Posts
              Hmm.. your calls seems to be ok..

              Try calling the MG_File_Size snippet by it self on a document with a static path to some image file to see if the snippet works at all..

              If it works, try the snippet again in maxigallery template and replace the:

              return size_readable(filesize($mfz_path));

              with

              return $mfz_path;

              in the end of MG_File_Size snippet to see if the path to the picture is sent to it correctly. If it works single, but not in maxigallery template, then I would guess that PHx parses it out somehow, but we’ll take it from there then..


                "He can have a lollipop any time he wants to. That's what it means to be a programmer."
                • 6726
                • 7,075 Posts
                I’ll check... might just be that : I use PHx a LOT for this website... quite a few conditionnals I am afraid, to reduce the template number...

                Yeah it works outside MG, just like FileDetails did, and the test GaneshXL had me do with the filesize function... Is there any method to escape PHx parsing just for the snippet call ?
                  .: COO - Commerce Guys - Community Driven Innovation :.


                  MODx est l&#39;outil id
                  • 6726
                  • 7,075 Posts
                  I am wondering something... could I use the filesize table you help me add here and "inject" the result of the filesize into the filesize custom MG field ?

                  I hope I make sense here...
                    .: COO - Commerce Guys - Community Driven Innovation :.


                    MODx est l&#39;outil id
                    • 7923
                    • 4,213 Posts
                    Quote from: davidm at Feb 18, 2008, 03:05 PM

                    I am wondering something... could I use the filesize table you help me add here and "inject" the result of the filesize into the filesize custom MG field ?

                    I hope I make sense here...
                    You can add the size_readable function in to maxigallery class in maxigallery.class.inc.php and then find this:

                    		if($modx->getLoginUserID()!="" && $modx->getLoginUserType()=='web'){ //if web user is posting picture, put owner id
                    			$rs1=$modx->db->query("INSERT INTO " . $this->pics_tbl . "(id, gal_id, filename, title, date, own_id) VALUES(NULL,'" . $this->pageinfo['id'] . "','" . $name . "',''," . $pic_date . ",'".$modx->getLoginUserID()."')");
                    		}else{
                    			$rs1=$modx->db->query("INSERT INTO " . $this->pics_tbl . "(id, gal_id, filename, title, date) VALUES(NULL,'" . $this->pageinfo['id'] . "','" . $name . "',''," . $pic_date . ")");
                    		}
                    


                    and replace it with:


                    		if($modx->getLoginUserID()!="" && $modx->getLoginUserType()=='web'){ //if web user is posting picture, put owner id
                    			$rs1=$modx->db->query("INSERT INTO " . $this->pics_tbl . "(id, gal_id, filename, title, date, own_id, filesize) VALUES(NULL,'" . $this->pageinfo['id'] . "','" . $name . "',''," . $pic_date . ",'".$modx->getLoginUserID()."','". $this->size_readable(filesize($this->path_to_gal."big_".$name)) . "')");
                    		}else{
                    			$rs1=$modx->db->query("INSERT INTO " . $this->pics_tbl . "(id, gal_id, filename, title, date, filesize) VALUES(NULL,'" . $this->pageinfo['id'] . "','" . $name . "',''," . $pic_date . ",'". $this->size_readable(filesize($this->path_to_gal."big_".$name)) . "')");
                    		}
                    


                      "He can have a lollipop any time he wants to. That's what it means to be a programmer."
                      • 6726
                      • 7,075 Posts
                      Awesome Doze, I’ll try that !
                        .: COO - Commerce Guys - Community Driven Innovation :.


                        MODx est l&#39;outil id