We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 51020
    • 670 Posts
    Quote from: Tyreal2012 at Apr 27, 2016, 09:47 AM
    Cant help you there i'm afraid, I had a look to see if i still had the script in my mail but doesnt look like it sorry sad

    No worries - thanks for trying!
      • 3749
      • 24,544 Posts
      I think I wrote a blog post on this, but I can't find it. wink

      Basically, your snippet would send the publishedon or createdon field as a property and the snippet would return the correct class.

      This would go in the row Tpl chunk where you want the class to appear:

      class="[[!RecentCheck? &interval=`1 week` &publishedon=`[[+publishedon]]`]]"


      Here's the snippet code (untested):

      <?php
      /* RecentCheck snippet */
      $output = 'non_recent';
      
      $interval = $modx->getOption('interval', $scriptProperties, '1 week');
      $pd = $modx->getOption('publishedon', $scriptProperties, '');
      
      $cutoffTime = strtotime('now - ' . $interval);
       
      if ($cutoffTime === false) {
          $output = '[RecentCheck] Invalid interval';
      } else {
          $ptime = strtotime($pd);
      
          $currentTime = time();
      
          if ($ptime > $cutoffTime) {
              /* Yes, it's recent -- Set the return value */
                  $output = 'recent';
          }
      
      }
      return $output;
        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
        • 51020
        • 670 Posts
        Quote from: BobRay at Apr 27, 2016, 01:34 PM
        I think I wrote a blog post on this, but I can't find it. wink

        Basically, your snippet would send the publishedon or createdon field as a property and the snippet would return the correct class.

        This would go in the row Tpl chunk where you want the class to appear:

        class="[[!RecentCheck? &interval=`1 week` &publishedon=`[[+publishedon]]`]]"


        Here's the snippet code (untested):

        <!--?php
        /* RecentCheck snippet */
        $output = 'non_recent';
        
        $interval = $modx--->getOption('interval', $scriptProperties, '1 week');
        $pd = $modx->getOption('publishedon', $scriptProperties, '');
        
        $cutoffTime = strtotime('now - ' . $interval);
         
        if ($cutoffTime === false) {
            $output = '[RecentCheck] Invalid interval';
        } else {
            $ptime = strtotime($pd);
        
            $currentTime = time();
        
            if ($ptime > $cutoffTime) {
                /* Yes, it's recent -- Set the return value */
                    $output = 'recent';
            }
        
        }
        return $output;

        Thanks bob - I think I found the blog post in question!

        http://bobsguides.com/blog.html/2015/03/09/modx-snippet-development-iii/

        Will give it a try!!

        Thanks

        • discuss.answer
          • 51020
          • 670 Posts
          Quote from: BobRay at Apr 27, 2016, 01:34 PM
          I think I wrote a blog post on this, but I can't find it. wink

          Basically, your snippet would send the publishedon or createdon field as a property and the snippet would return the correct class.

          This would go in the row Tpl chunk where you want the class to appear:

          class="[[!RecentCheck? &interval=`1 week` &publishedon=`[[+publishedon]]`]]"


          Here's the snippet code (untested):

          <!--?php
          /* RecentCheck snippet */
          $output = 'non_recent';
          
          $interval = $modx--->getOption('interval', $scriptProperties, '1 week');
          $pd = $modx->getOption('publishedon', $scriptProperties, '');
          
          $cutoffTime = strtotime('now - ' . $interval);
           
          if ($cutoffTime === false) {
              $output = '[RecentCheck] Invalid interval';
          } else {
              $ptime = strtotime($pd);
          
              $currentTime = time();
          
              if ($ptime > $cutoffTime) {
                  /* Yes, it's recent -- Set the return value */
                      $output = 'recent';
              }
          
          }
          return $output;

          Bob - you are a genius. It's official.
          I implemented the above untested code, and it worked right out of the box!
          I have tried to fathom out how it works, and I'll be honest and say i have no idea, but it does.
          I get most of it, but don't understand how it knows the terminology '1 week' - I changed it to '2 weeks' and this extends the period, and works fine! I assume I need to change the internal JUST in the chunk?

          Thanks again for you help.
            • 3749
            • 24,544 Posts
            It's part of PHP's strtotime() function, which converts a human-readable date into a Unix timestamp (a huge number of seconds). strtotime() understands lots of interesting text descriptions like "+ 1 week," "-3 months", "now - 2 days", "next thursday," "last friday," etc.
              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
              • 51020
              • 670 Posts
              Quote from: BobRay at Apr 28, 2016, 02:57 PM
              It's part of PHP's strtotime() function, which converts a human-readable date into a Unix timestamp (a huge number of seconds). strtotime() understands lots of interesting text descriptions like "+ 1 week," "-3 months", "now - 2 days", "next thursday," "last friday," etc.

              Ah I see, I will read up on it. Thanks again.