Subscribe: RSS
  • Here is my snippet for generating easy gallery tree for TV. It’s based on original goldsky _getfolderoptions function.

    The idea of this snippet is very similar to this one:
    http://wiki.modxcms.com/index.php/Create_TV-Based_Chunks

    It’s a simple way to give your end users quite intuitive method to choose gallery to display inside a specific document.


    First create a new snippet and name it e.g. ’getE2GTree’:
    <?php
     /**
         * get folders structure for DropDown List Menu TV
    */
    
    isset($parentid) ? "" : $parentid = 0;
    
    		$selectdir = 'SELECT parent_id, cat_id, cat_name, cat_level '
                    .'FROM '.$modx->db->config['table_prefix'].'easy2_dirs '
                    .'WHERE parent_id='.$parentid.' '
            ;
    
            $querydir = mysql_query($selectdir);
            $numdir = @mysql_num_rows($querydir);
    
            $childrendirs = array();
            if ($querydir) {
                while ($l = mysql_fetch_array($querydir, MYSQL_ASSOC)) {
                    $childrendirs[$l['cat_id']]['parent_id'] = $l['parent_id'];
                    $childrendirs[$l['cat_id']]['cat_id'] = $l['cat_id'];
                    $childrendirs[$l['cat_id']]['cat_name'] = $l['cat_name'];
                    $childrendirs[$l['cat_id']]['cat_level'] = $l['cat_level'];
                }
            }
            mysql_free_result($querydir);
    
            $output = (isset($output)?$output:'');
            foreach ($childrendirs as $childdir) {
                // DISPLAY
    
                // **************** ONLY START MARGIN **************** //
                for ($k=1; $k<$childdir['cat_level'] ; $k++) {
                    if ($k==1) $output .= '   ';
                    else $output .= ' |  ';
                }
                for ($k=1; $k<$childdir['cat_level'] ; $k++) {
                    if ($k==1) $output .= ' |';
                }
                if ($childdir['cat_level'] > 1) $output .= '--';
                // ***************** ONLY END MARGIN ***************** //
    
                $output .= ' '.$childdir['cat_name'].' [id:'.$childdir['cat_id'].']=='.$childdir['cat_id'].'||';
    
                /*********************************************************/
                // GET SUB-FOLDERS
                $selectsub = 'SELECT parent_id, cat_id, cat_name '
                        .'FROM '.$modx->db->config['table_prefix'].'easy2_dirs '
                        .'WHERE parent_id='.$childdir['cat_id'].' '
                        .'ORDER BY cat_name ASC'
                ;
                $querysub = mysql_query($selectsub);
                if ($querysub) {
                    $numsub = @mysql_num_rows($querysub);
                    if ($numsub > 0) {
                        $output .= $modx->runSnippet('getE2GTree',array('parentid'=>$childdir['cat_id']));
                    }
                }
                mysql_free_result($querysub);
                /*********************************************************/
            }
    		
            return $output;
    ?>
    


    Now create TV. Name it e.g. ’e2g-galleries’. Choose ’DropDown List Menu’ as an input type. In ’Input Option Values’ paste this:
    @EVAL return $modx->runSnippet('getE2GTree');
    


    In your document you should see now TV with dropdown menu with all your e2g galleries.

    Now you could use it like this:
    [!easy2? &gid=`[*e2g-galleries*]` &showonly=`images`!]
    


    That’s all. Hopefully someone find it useful smiley

    Goldsky what do you think? Should that be included to e2g?
    • Very nice! One thing I really like about E2G is that it isn’t tied to a specific resource. On the other hand, sometimes that has advantages. This gives the best of both worlds!
      • Ups. There was a bug in my code. Sorry. Please be aware about that line of code:
        <?php //highlight
        $output .= $modx->runSnippet('getE2GTree',array('parentid'=>$childdir['cat_id']));
        


        If you change the name of your snippet you should change it’s name in the runSnippet method too.

        Is there any method for recurrent snippet run? Or just getting the name of currently executing snippet?

        Quote from: sottwell at Jun 14, 2010, 09:19 AM

        Very nice! One thing I really like about E2G is that it isn’t tied to a specific resource. On the other hand, sometimes that has advantages. This gives the best of both worlds!
        That’s true. When you need to share galleries between different parts of your site this is a perfect option. But of course there are things to do... e.g. unicode. I think I’m done with it. But I must test it better before I’ll send my code.
        • And when you do, be assured I’ll beat it to death on the four-language site I’m working on... English, Hebrew, Russian and French. YAMS, of course cool
          • Evo 1.0.4

            Module installation errors:
            Warning: fopen(/home/domains/xxx/public_html/assets/modules/easy2/includes/configs/config.easy2gallery.php) [function.fopen]: failed to open stream: Permission denied in /home/domains/xxx/public_html/assets/modules/easy2/index.php on line 64

            Warning: fwrite(): supplied argument is not a valid stream resource in /home/domains/xxx/public_html/assets/modules/easy2/index.php on line 83

            Warning: fclose(): supplied argument is not a valid stream resource in /home/domains/xxx/public_html/assets/modules/easy2/index.php on line 84
            • Hello guys,
              Sorry for my ignorance for sometimes.
              I needed more concentration for bugfixing the disturbing behavior of pagination. And it’s done.
              The update of Easy 2 Gallery 1.4.0-RC1 revision 196 is now available in the package download area.
              You can download the ’module...’ only, if you have already had the javascript libraries inside the libs/ folder.

              So, here are the changes:

              **** SNIPPET ****
              Bug fixes on:

              **** MODULE ****

              • Now with BATCH tagging, both adding and removing. Go ahead, play with it for some time.
              • Since then, there is also the TAG explorer
              • Lastly, the config inside module contains the snippet parameter for the fields, so you can figure out the different snippet call in the run-time if you need to.
              See attachments below.


              @labasus,
              make sure your host allows the fopen & fwrite command. See your Apache’s error logs for details.

              @sottwell,
              Quote from: sottwell at Jun 14, 2010, 04:35 PM

              And when you do, be assured I’ll beat it to death on the four-language site I’m working on... English, Hebrew, Russian and French. YAMS, of course cool
              Hehe.. you know that i’m working on it. tongue

              @fixedmachine,
              Thanks for the TV enhancement.

              Quote from: fixedmachine at Jun 12, 2010, 12:36 AM

              Goldsky, you can’t rely on mb_detect_encoding. Sometimes it could return false, and we end up with error:
              Warning: Argument 2 passed to UTF8::convert_to() must be an string, boolean given, called in /home/domains/domain.net/public_html/assets/modules/easy2/includes/classes/e2g.public.class.php on line 58 and defined in /home/domains/domain.net/public_html/assets/modules/easy2/includes/UTF8-2.1.0/UTF8.php on line 1546 in /home/domains/domain.net/public_html/assets/modules/easy2/includes/UTF8-2.1.0/ReflectionTypehint.php  on line 70
              


              So in e2g.public.class.php we can’t have:
              <?php> // highlighting
              $converted_text = UTF8::convert_to($text,mb_detect_encoding($text));
              


              Anyway. We’ve got a mess with encoding. There is too much ’e2g_decode’ and ’e2g_encode’ where we don’t need it.

              We need to rebuild that functionality.

              I think that the general procedure should look like this:
              1. UPLOAD - we detect encoding of uploaded file name and if it’s different than UTF-8 -> convert it to UTF-8.
              2. SAVE - save file with UTF-8 encoded file name
              3. DISPLAY - because we know that our file name could contain non-ASCII characters we must URI encode all paths to them (http://www.w3.org/International/O-URL-code.html)

              This is the base. Of course we need to consider synchronization and downloading(zip).

              Did I miss something?

              I’ll try to fix that things.

              The ’e2g_decode’ and ’e2g_encode’ were supposed to bridging the different encoding of each of machines.
              Like I usually said, since I don’t use irregular character (of Latin-1) in my country, I only test this against Iñtërnâtiônàlizætiøn text.
              Go ahead, post your fixes on this. I’ll include that into the package.

              Anyway,
              I believe, this encoding should also applies the set_locale variable.
              I’ve dug the MODx’s charset (in manager/includes/charsets.php), it realizes me that I should include the set_locale option in the language files.

              What do you think.
                Rico
                Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
                MODx is great, but knowing how to use it well makes it perfect!

                Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets | IE 6 must die ! | Tutorial links

                Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan

                PING ME ON TWITTER @_goldsky
              • Bug fix for Easy 2 Gallery 1.4.0-RC1 revision 196, e2g.snippet.class.php, line 715
                <?php // highlighting
                
                //'gid='.$static_gid
                'gid='.$gid
                


                There will be more bug fixings for this revision# . But that’s the most important one.
                  Rico
                  Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
                  MODx is great, but knowing how to use it well makes it perfect!

                  Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets | IE 6 must die ! | Tutorial links

                  Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan

                  PING ME ON TWITTER @_goldsky
                • Spaces in the filename breaking the download filename again... wink
                  • Oops...
                    Updated the package again: e2g-1.4.0-rc1-r202.zip (without space tongue)
                      Rico
                      Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
                      MODx is great, but knowing how to use it well makes it perfect!

                      Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets | IE 6 must die ! | Tutorial links

                      Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan

                      PING ME ON TWITTER @_goldsky
                    • More for the translation,
                      If you dig the e2g_encode/e2g_decode, the function have been added the $callback variable.
                      We can use that var for further function if you need to.

                      eg:
                      <?php // highlighting
                      
                      protected function e2g_encode($text, $callback=false) {
                      // ... more codes ...
                      
                              if ($e2g_encode == 'UTF-8') {
                                  if ($callback==false) {
                                      $converted_text=utf8_encode($text);
                                  }
                                  // http://bytes.com/topic/php/answers/444382-ucfirst-utf-8-setlocale#post1693669
                                  if ($callback=='ucfirst') {
                                      $fc = mb_strtoupper(mb_substr($text, 0, 1, 'UTF-8'), 'UTF-8');
                                      $converted_text = $fc.mb_substr($text, 1, mb_strlen($text, 'UTF-8'), 'UTF-8');
                                  }
                      
                                  // if no matching criteria, just display plain text
                                  if ($converted_text==false) $converted_text=$text;
                                  
                                  return $converted_text;
                              }
                      
                      // ... more codes ...
                      }
                      


                      So the basic usage is not changed, but we can add new callback like:
                      <?php
                      echo $this->_e2g_encode($lng['foobar'],'strtolower');
                      
                        Rico
                        Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
                        MODx is great, but knowing how to use it well makes it perfect!

                        Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets | IE 6 must die ! | Tutorial links

                        Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan

                        PING ME ON TWITTER @_goldsky