We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 44922
    • 131 Posts
    We're using EventsX - not sure it's still supported but it looks a reasonably simple-to-use calendar plug in. The issue we're having is that the hyperlinks to the events from the calendar aren't working correctly. We're using Friendly URLs and the Event Page link which is output is calendarupcomingevents.htmlTest+Event/1. The EventsX event created is called Test Event and looking in the snippet we see

     $event['url'] = $modx->makeUrl($eventsPage).urlencode($event['name']).'/'.$event['id'];
    .

    Just not sure what format EventsX is expecting $modx->makeUrl($eventsPage) to be in in order to append '/'.$event['id'];

    This question has been answered by lancipoos. See the first response.

      • 44922
      • 131 Posts
      Since posting, came across a couple of things:
      https://docs.modx.com/extras/revo/eventsx says
      4. Create a resource for the events calendar (or add it to your template(s))
      5. Create a resource for the upcoming events list (see template example below)
      6. Create a resource below that for a single event (see template example below)

      See on '6' it says 'below that'. It means a child page of 5. Missed that.

      We also came across a post from Wallaco from 3 years back:
      https://forums.modx.com/thread/97779/onpagenotfound-not-firing-unless-debug-added-for-eventsx
      Seems like the same issue. As mentioned there, URLs should be in the format:
      Summary resource URL: http://domain.com/events/
      Detail resource URL: http://domain.com/events/Some+Event/2
      with the detail resource then using
      $modx->sendForward($eventPage);
      to forward the request URL and parameters to the single event page.

      We found a couple of things. As the other post says, the plugin uses a OnPageNotFound.
      if ($modx->event->name == 'OnPageNotFound' && preg_match('/'.$jsonURI.'\?.*$/', $_SERVER['REQUEST_URI']))

      works fine and spits out a calendar page.
      After the 'if' comes an elseif for the events pages
      elseif ($modx->event->name == 'OnPageNotFound' && preg_match('/'.$eventsPageRegex.'\/.*\/[0-9]+$/', $_SERVER['REQUEST_URI']))

      This doesn't work and comes up with an error
      PHP warning: preg_match(): Unknown modifier 'c'

      If you override the elseif with a straight forward 'else'
      else { $modx->sendForward($eventPage);
      }

      that fires, but the 'Some+Event/2' get stripped from http://domain.com/events/Some+Event/2 link and you just end up seeing the resource URL: http://domain.com/events/

      Any ideas, folks?
        • 3749
        • 24,544 Posts
        Can you post the code with the preg_match() error? The file and line number should be in the error message.
          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
          • 18373 ☆ A M B ☆
          • 3,141 Posts
          Just not sure what format EventsX is expecting $modx->makeUrl($eventsPage) to be in in order to append '/'.$event['id'];

          You've already found the partial answer to that in the instruction #6, but that line expects your $eventsPage to be a resource container, so that the friendly url ends in / instead of .html
            Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

            Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
            • 44922
            • 131 Posts
            Hi Bob

            Modx error log shows:
            public_html/core/cache/includes/elements/modplugin/18.include.cache.php : 62) PHP warning: preg_match(): Unknown modifier 'c' 


            Line 62 being:
            elseif ($modx->event->name == 'OnPageNotFound' && preg_match('/'.$eventsPageRegex.'\/.*\/[0-9]+$/', $_SERVER['REQUEST_URI']))
            


            Server access logs show:
             "GET /calendar-test-page/calendarupcomingevents/TestEvent/1 HTTP/1.1" 404 24521 


            Checking server PHP version, it's old
            PHP 5.5.9-1ubuntu4.22

            Thanks
              • 3749
              • 24,544 Posts
              Did you see Mark Hamstra's answer? It looks promising to me.

              The key may be the value of $eventsPageRegex. If it has an unescaped forward slash followed by the letter 'c', that would explain the error message you're getting.
                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
                • 44922
                • 131 Posts
                Seen Mark's reply, good point, thanks. Did that when making resource '6' a child of '5' as in my 2nd post. No joy.

                I wonder whether your comment on the other post 3 years ago might be the way to go, use some other method & just redirect to the event detail directly.
                  • 3749
                  • 24,544 Posts
                  As a diagnostic, You might add this somewhere above the error line, but after the value of $eventsPageRegex is set:

                  $modx->log(modX::LOG_LEVEL_ERROR, 'EVENTS PAGE REGEX: ' . $eventsPageRegex);


                  Then check the error log for a value with a slash followed by the letter c.
                    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
                  • discuss.answer
                    • 44922
                    • 131 Posts
                    Hi Bob, the error log just gave
                    PHP warning: preg_match(): Unknown modifier 'c'
                    like I posted before.

                    Personally I'm no expert with preg_match, but it turns out the / at the beginning and end of the regular expression are causing the issue. Using # as a delimiter instead fixes the issue.

                    In the Plugin 'EventsX, changing
                    elseif ($modx->event->name == 'OnPageNotFound' && preg_match('/'.$eventsPageRegex.'\/.*\/[0-9]+$/', $_SERVER['REQUEST_URI']))

                    to
                    elseif ($modx->event->name == 'OnPageNotFound' && preg_match('#'.$eventsPageRegex.'\/.*\/[0-9]+$#', $_SERVER['REQUEST_URI']))


                    and in the evxEvent snippet, changing
                    if(preg_match('/'.$eventsPageRegex.'\/.*\/[0-9]+$/', $_SERVER['REQUEST_URI']))

                    to
                    if(preg_match('#'.$eventsPageRegex.'\/.*\/[0-9]+$#', $_SERVER['REQUEST_URI']))


                    sorts it. Now it all works!!

                    Trying to solve this has highlighted a whole bunch of preg_match errors thrown by the Glossary extra mentioned half a year ago in this post
                    https://forums.modx.com/thread/104497/how-to-sort-snippet-array-alphabetically#dis-post-562109
                    so maybe that might fix the error there too.

                      • 3749
                      • 24,544 Posts
                      Right. As I suggested, if the delimiter is a '/', any '/' characters in the pattern have to be escaped with a backslash so they won't be interpreted as the final delimiter. Changing the delimiter can also work, but you have to make sure that the character you use will never appear in the pattern, or escape it.

                      The fact that you still saw the preg_match() error means that the error-log code I suggested is not above the first bad preg_match() code. If it were, the error log would show the $eventsPageRegex value, which we now know contains '/c' since changing the delimiter solved things.
                        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