We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33372
    • 1,611 Posts
    strpos(strtolower($_SERVER[’HTTP_USER_AGENT’]),$key) would be faster.
      "Things are not what they appear to be; nor are they otherwise." - Buddha

      "Well, gee, Buddha - that wasn't very helpful..." - ZAP

      Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
      • 20413
      • 2,877 Posts
      Thanks for suggestions!! But thanks for the work!! The idea!!

      I dont have this working YET. Snippet runs and return my default css. User agent is showing when echo. filenames and typos checked.
      Cached cleared, different browsers used.

      Im going through the whole thing at php.net (and this is good practise for me), but Im really eager getting this snippet to
      work. This snippet totally rocks so I have to get it work!! cool

      Well, anyone install and get it going, let me know!
        @hawproductions | http://mrhaw.com/

        Infograph: MODX Advanced Install in 7 steps:
        http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

        Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
        http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
        • 6726
        • 7,075 Posts
        Very cool discussion and tips, thanks guys !
          .: COO - Commerce Guys - Community Driven Innovation :.


          MODx est l'outil id
          • 33372
          • 1,611 Posts
          Quote from: mrhaw at Dec 29, 2008, 02:54 AM

          I dont have this working YET. Snippet runs and return my default css. User agent is showing when echo. filenames and typos checked.
          Cached cleared, different browsers used.
          I haven’t tried this particular code, but it looks fine to me (and I use similar code to set dynamic CSS all the time). Can you post all of your snippet code? If for example you left off a closing comment tag above the part that checks the user agent string then it might be getting closed after that block at the next comment.
            "Things are not what they appear to be; nor are they otherwise." - Buddha

            "Well, gee, Buddha - that wasn't very helpful..." - ZAP

            Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
            • 20413
            • 2,877 Posts
            laugh laugh laugh

            Several times I messed with the code and went back to copy it clean...
            When I finally let site_url just be instead of changing it to base_url IT WORKED.

            Stubbornly I blamed the code... Stubbornly I didn’t accept the truth. I WAS THE ERROR!! tongue

            THANK YOU ALL!! THIS IS A SMALL STEP FOR MANKIND BUT A BIG FOR ME!!
              @hawproductions | http://mrhaw.com/

              Infograph: MODX Advanced Install in 7 steps:
              http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

              Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
              http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
              • 19132
              • 199 Posts
              I’ve been the error, too. I got this working. Now I just need to bone up on my CSS layout skills for mobile.

              @BobRay
              Can this snippet be repurposed to display a chunk instead? While switching to custom CSS is very useful, I would rather have it switch to a template instead.
                MySQL: 5.0.45
                PHP: 5.2.6
                Linux 2.6.9-023stab048.6-enterprise #1
                cURL enabled
                PDO enabled
                FFox Apple 3.6.8
                Firebug DIS-abled
                • 3749
                • 24,544 Posts
                Quote from: MDi at Jun 23, 2009, 09:10 AM

                I’ve been the error, too. I got this working. Now I just need to bone up on my CSS layout skills for mobile.

                @BobRay
                Can this snippet be repurposed to display a chunk instead? While switching to custom CSS is very useful, I would rather have it switch to a template instead.

                Sure, just select a chunk name from the array rather than a file name and use $modx->getChunk(chunk_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
                  • 16034
                  • 107 Posts
                  This check for a string in a string is not always working.

                  Quote from: BobRay at Dec 28, 2008, 11:09 PM

                  <?php
                  if (strpos($_SERVER['HTTP_USER_AGENT'],$key)) {
                  ...
                  }
                  


                  If the string you are searching for is at position 0. strpos will return a 0, and 0 == false in PHP. Changing the check to strpos(...)!==false should do the trick, since !== and === checks for type and value.

                  For more info, check the manual: http://dk.php.net/function.strpos
                    MODx snippet-glossary 101:
                    Ditto = Content Lister -- Wayfinder == Menu Builder -- Jot = Comment Control
                    • 3749
                    • 24,544 Posts
                    Quote from: Kleist at Jun 24, 2009, 02:16 AM

                    This check for a string in a string is not always working.

                    Quote from: BobRay at Dec 28, 2008, 11:09 PM

                    <?php
                    if (strpos($_SERVER['HTTP_USER_AGENT'],$key)) {
                    ...
                    }
                    


                    If the string you are searching for is at position 0. strpos will return a 0, and 0 == false in PHP. Changing the check to strpos(...)!==false should do the trick, since !== and === checks for type and value.

                    For more info, check the manual: http://dk.php.net/function.strpos

                    Not my code, but I should have spotted that. Good catch. smiley

                    I think this would be slightly faster and easier to read:

                    if (strstr($_SERVER['HTTP_USER_AGENT'],$key))

                      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
                      • 19132
                      • 199 Posts
                      select a chunk name from the array rather than a file name and use $modx->getChunk(chunk_name)
                      I’m afraid you’re going to have to hold my hand on this. It’s an easy switch for you, but not so for me.

                      <?php
                      /* Snippet Title: CustomChunk  */
                      
                      $output = '';
                      $cssBase = $modx->config['site_url'] . 'assets/templates/catalytic2/css/';   /* or wherever you keep your css files */
                      
                      /* array of browser agent names and their respective chunk templates */
                      [color=red]/* select a chunk name from the array rather than a file name and use $modx->getChunk(chunk_name) WHERE TO USE getChunk?? */
                      /* And how does one name a chunk in this code without the chunk's curlybrackets invoking the chunk?*/[/color]
                      $browserArray = array(
                           'iPhone' => 'mobile.css',
                           'SymbianOS/9.1' => 'symbian.css',
                           'anotherbrowser' => 'otherbrowser.css',
                           'yetanother browser' => 'stillotherbrowser.css'
                      );
                      
                      /* see if we recognize one */
                      foreach ($browserArray as $key => $value) {
                          if (strstr($_SERVER['HTTP_USER_AGENT'],$key)) {
                              $output .= $cssBase . $value;
                              break;
                          }
                      }
                      
                      /* if we didn't find one, use the default css file */
                      [color=red]/* better: get a default chunk (non-mobile template) */[/color]
                      if ($output == '') {
                          $output = $cssBase . 'template_css.css';
                      [color=red]/* we don't need to output a file location. How do we output a chunk instead?*/[/color]
                      }
                      
                      return $output;
                      ?>
                        MySQL: 5.0.45
                        PHP: 5.2.6
                        Linux 2.6.9-023stab048.6-enterprise #1
                        cURL enabled
                        PDO enabled
                        FFox Apple 3.6.8
                        Firebug DIS-abled