We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9549
    • 93 Posts
    I was looking for the latest PHx version and found 2.1.2... now that’s fresh! laugh However, PHx seems to cause some problems to the eForm &fromname param. When I disabled PHx the from name displays just fine, but when PHx is enabled, my host’s name stands as sender. Huh? undecided
      • 30128
      • 78 Posts
      I’m using FeedX to receive some comic strip feeds, and now I need to use PHx to modify some of the placeholders. Specifically, I receive this string:
      <img src="http://www.somedomain.tld/path/anotherpath/image.gif" border="0" />
      and need to strip it so I only have
      http://www.somedomain.tld/path/anotherpath/image.gif
      left.

      I’ve written a snippet phx:imgsrc:
      <?php
      $pattern = '\"(.+?)\"';
      if (preg_match ($pattern,$output,$matches)) {
          return $matches[0];
      } else {
          return "no_image_src_found_from_match"; #debug
      }
      ?>
      .

      I’ve tested this regexp in Komodo Rx Toolkit and it matches.

      In my FeedX template then I use the placeholder like this: [+DESCRIPTION:imgsrc+] but can’t get it to work any way I write my regexp. So far I’ve only got blank in return, not even my "debug" string. I’m not even sure I need to use regexp - maybe MODx or PHx have some higher-level functions to do this? Basically I just need to get the content inside a double quote, in a lazy way in case the image tag have several attributes.

      So I guess this is more a problem of my lacking regexp / python skills, but figured you guys know a thingy or two about parsing anyway, so...

      Any help appreciated smiley
        • 4971
        • 964 Posts
        Try :

        $myurl = explode('"', $output);
        return = $myurl[1];
        


        as your phx:snippet and it should work...

          Website: www.mercologia.com
          MODX Revo Tutorials:  www.modxperience.com

          MODX Professional Partner
          • 4971
          • 964 Posts
          Does :math= only supports + - * / operations?
          Could we use MOD and INT?
          Can these two be implemented?

          Thanks...
            Website: www.mercologia.com
            MODX Revo Tutorials:  www.modxperience.com

            MODX Professional Partner
            • 7923
            • 4,213 Posts
            You can do a custom phx modifier to do what you want with the php math functions, or do your own math functions in the modifier or use some existing library/class.


              "He can have a lollipop any time he wants to. That's what it means to be a programmer."
              • 4971
              • 964 Posts
              Yes thanks, that is true... my problem is that I am using the following...

              [+phx:if=`[+TM:min+]`:gt=`[+SUNR:min+]`:and:lt=`[+SUNS:min+]`:then=:math=`([+SUNS:min+]-[+TM:min+])/60`:else=`DARK`+]</li>
              


              the "min" custom phx modifier converts to minutes the time in xx:yy PM format.
              I need to get the hours and minutes based on the [+SUNS:min+]-[+TM:min+] difference.
              A custom phx modifier only accepts a value as input ($output) so I think I cannot use another
              custom modifier...

              I do not know how to input the [+SUNS:min+] and [+TM:min+] values in a snippet to process them...
              there must be a way but I do not know it...
                Website: www.mercologia.com
                MODX Revo Tutorials:  www.modxperience.com

                MODX Professional Partner
                • 7923
                • 4,213 Posts
                Why don’t you simply do a snippet for that..

                eg: [[yourSnippet? &tm=`[+TM+]` &sunr=`[+SUNR+]` &suns=`[+SUNS+]`]]

                <?php
                $tmStamp = strtotime($tm);
                $sunrStamp = strtotime($sunr);
                $sunsStamp = strtotime($suns);
                
                if ($tmStamp > $sunrStamp && $tmStamp < $sunsStamp) {
                   return strftime('%H', ($sunsStamp - ($sunsStamp - $tmStamp)));
                } else {
                   return 'DARK';
                }
                ?>


                Or something along that line..


                  "He can have a lollipop any time he wants to. That's what it means to be a programmer."
                  • 4971
                  • 964 Posts
                  Yes, thanks doze, that makes more sense. I did not know that I could input a placeholder
                  as an argument to a snippet... that would do, thanks again...
                    Website: www.mercologia.com
                    MODX Revo Tutorials:  www.modxperience.com

                    MODX Professional Partner
                    • 18830
                    • 161 Posts
                    I want to change the background image at the header section with help of the parents ID.

                    The site structure looks like this.

                    de (ID1)
                    ..item1
                    ..subitem1.1

                    en (ID2)
                    ..item1
                    ..subitem1.1


                    With help of the UlitmateParent snippet I can get the items ID.

                    When I try this on a document under the "de"-folder everything works fine:

                    [+phx:if=`[[UltimateParent]]`:is=`1`:then=`id="header_[[UltimateParent?  &top=`1`]]"`:else=``+]
                    


                    But after adding a second line like this

                    [+phx:if=`[[UltimateParent]]`:is=`2`:then=`id="header_[[UltimateParent?  &top=`2`]]"`:else=``+]
                    


                    the page won’t load.

                    What am I doing wrong?

                    I’m using PHx 2.1.1 and MODx 0.95

                    Update: The problem is solved. There was a bug in UltimateParent 1.2 that could trigger infinite loops if parent never equals $top. 1.3 fixes this bug.
                      • 7455
                      • 2,204 Posts
                      Is there an elseif option? I was looking for it but could not find it, I like to make a call like this:
                      [+phx:if=`[*template*]`:is=`2`:then=`this is template 2`:elseif=`[*template*]`:is=`3`:then=`this is template 3`:else=`I have no idea what template is used`+]
                      



                      Would it be posible to do a thing like this without making a seperate pice of code?

                      Dimmy
                        follow me on twitter: @dimmy01

                      This discussion is closed to further replies. Keep calm and carry on.