Jump to content

Search the Community

Showing results for tags 'regex'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to ProcessWire
    • News & Announcements
    • Showcase
    • Wishlist & Roadmap
  • Community Support
    • Getting Started
    • Tutorials
    • FAQs
    • General Support
    • API & Templates
    • Modules/Plugins
    • Themes and Profiles
    • Multi-Language Support
    • Security
    • Jobs
  • Off Topic
    • Pub
    • Dev Talk

Product Groups

  • Form Builder
  • ProFields
  • ProCache
  • ProMailer
  • Login Register Pro
  • ProDrafts
  • ListerPro
  • ProDevTools
  • Likes
  • Custom Development

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests

Found 4 results

  1. Hey all, I've been building a new feature on our PW site and the URL hooks are exactly what the doctor ordered. I am developing a RESTful web API to allow external platforms to integrate with our site. The API endpoints are namespaced at /api/v1. I am having trouble making use of the named route parameter using regex. I have a hook for /api/v1/offline-events that gets all Offline Event pages. The next route to be defined is /api/v1/offline-events/{event ID}. The event ID is using a custom string (not the Page ID) that is a 15 character alphanumeric string like this: E4LxQRXZadgjstw. However when I use a PCRE compliant regular expression (tested on regexr.com) I get an error. Here is my hook code for reference and the error produced: <?php namespace ProcessWire; $wire->addHook('/api/v1/offline-events/{eventId:#(?=.{15}$)([A-Za-z0-9])\w+#}/?', function($e) { // ommitted for brevity }); // Error thrown: Warning: preg_match(): Unknown modifier '(' in /wire/core/WireHooks.php on line 1170 I've tried using all delimiters in the documentation (!@#%) but no change in the outcome. The second question is how do I create a wildcard capture for all 404s that occur after the /api endpoint? Currently it is loading the website 404 page. Many thanks!
  2. Some context: I want to use PHP variables in my CSS (more info below) and found a solution on CSS-tricks that looks fairly elegant and somewhat solid to me. It's pretty simple, I created a file style.css.php inside the site/templates/ directory and load that in my page head. In style.css.php is the following: <?php header("Content-type: text/css; charset: UTF-8"); header("Charset:utf-8"); if ($homepage->hero_image) { echo <<<CSS .hero { background: url($homepage->hero_image->url) no-repeat; } CSS; } ?> Because of the following RewriteCond (line 373) in the htaccess file the server sends a 403 error back when the file is requested: # Block access to any PHP or markup files in /site/templates/ or /site-*/templates/ RewriteCond %{REQUEST_URI} (^|/)(site|site-[^/]+)/templates($|/|/.*\.(php|html?|tpl|inc))($|/) [NC,OR] (My htaccess file is @version 3.0 and @htaccessVersion 301) This is how I thought I could fix that (based on these answers on stack overflow) but it does not work: # Block access to any PHP or markup files in /site/templates/ or /site-*/templates/ RewriteCond %{REQUEST_URI} (^|/)(site|site-[^/]+)/templates($|/|/((?!style\.css).)*\.(php|html?|tpl|inc))($|/) [NC,OR] I tested the rule with htacess tester and htaccess check and both worked for me, but on my site I still get a 403 instead of the file. I'm working on localhost, using MAMP (not sure if that's relevant). A bit more about what I want to do achieve specifically: I want to use an image as a background-image for an element, not place it as an image. This image is provided by the user via a field and can therefore change. I know I can achieve this like this: echo "<section class='hero' style='background-image: url($page->hero_image->url)'></section>"; But I would prefer a method other than inlining because of scalability and cleanliness. (I admit the extra link in the page head is not ideal either) P.s. this is my first post here, I hope it's submitted in the right forum and my explanation is clear.
  3. I really would like to see a sanitzer that uses a regex!! $sanitize->regex($value, $regex); Simply return empty if the value doesn't match. It would be even better if we got an extra option for replacements and or callback functions. If i have seen it right, there are even sanitizer that use HTMLpurifier so why is there no regex implemented as its one of PHP's most powerfull features ? Sanitizer since PW 2.6.14 integrates nicely whith $input and so on , so using a seperate preg_match()/preg_replace() isn't as elegant as using sanitizer.
  4. Hi foks (Not sure if this would make more sense in the dev forum, feel free to move if necessary...) I am trying to do the following... In $page->introtext (a textfield with markdown parser) 1. find the link in which the href matches my $current_urlsegment var 2. Change the href to $link_to_overview 3. Add a ".active" CSS class to it 4. Get the whole thing back into the array 5. Output the array. To add a bit of context: - This is for a text that contains links to segments of a page. When a user clicks on a link (selects a segment), the surrounding text is faded out, and the selected link turns into a "back to overview" button, so to say. (Sounds even more insane, but could work quite intuitively in practice) - So far, I did all of this with js, using a custom data attribute with the current segment to match against the links, but long story short it would be much easier if no js would be involved. As far as I understand it should be rather simple to do this with regex, but I'm struggling with the logic of it. I started with the following: $text = $page->txt_projects_intro; $currentsegment = '/projects/' + $sanitizer->pageName($input->urlSegment1) + '/'; $reg_ex_anchor = '/<a [^>]*\bhref\s*=\s*"\K[^"]*' + $currentsegment + '[^"]*/'; $reg_ex_onlyanchorpath = '[^>]*\bhref\s*=\s*"\K[^"]*' + $currentsegment + '[^"]*'; if(preg_match($reg_ex_anchor, $text, ...)) { $content .= preg_replace... // brain melts } Which is when I realized that I have now googled myself way out of my coding league So: Is the above going into the right direction? Is there an easier way, maybe even involving PW selectors that I don't know about? Cheers Guys!
×
×
  • Create New...