Jump to content

dragan

Members
  • Content Count

    1,800
  • Joined

  • Last visited

  • Days Won

    20

Posts posted by dragan


  1. @hollyvalero

    I tried it as well (hook is also in site/ready.php), and everything works just fine. Just copy-and-pasted the hook, and used the list example, and adjusted the selector. It even works within a partial I load via include_once() and cache the output with MarkupCache 🙂

    Do you run an ancient PHP version, by any chance? See Ryan's note about PHP < 5.3

    Also, did you find any hints with Tracy Debugger?


  2. @Marco Ro If you would draw a little sketch, and show exactly what you want to do, and how it's supposed to look like visually (it's still not clear to me from your description), maybe there is a way with CSS only. And perhaps also show what it looks out now, out of the box, for comparison.

    e.g. if all you want is to place the label on the left, and the input on the right, you could do it easily with flexbox: https://codepen.io/dragan1700/pen/JjdRYVE


  3. I agree too that this should be added to the styleguide, and I also configured my IDE to strip trailing whitespace on save.

    However, if we're talking about diff tools, it's just as easy to configure them to ignore whitespace (and even empty lines).

    diff-options.PNG.4e7096f391dbf611afb1aa5bf7641092.PNG

    PHPStorm

    Git has the option --ignore-whitespace you can use.

    VSCode: File => Preferences => Settings => Diff Editor => Ignore Trim Whitespace.

    • Like 2

  4. @wesp

    Well, that ain't so easy. If you wanted to make it behave like that - and make sure you don't break user's back-button in the process, and make sure people actually scroll to the section if they share/bookmark such a pseudo-link - you should use an SPA framework like Vue instead, where you have such custom routing functionality already built-in.

    otoh, it's quite easy to hide / remove the #section1 completely from the location bar - but that's not what you're after.

    • Like 2

  5. @wesp You don't need the Functions API for the functionality you asked for - it's just the syntax Zeka used that requires it, e.g. pages() instead of $pages etc.

    I have tried this combination here, and it works fine:

    // at the very top of home.php
    if ($input->urlSegment1) {
        $pagename = $input->urlSegment1;
        $match = $pages->findOne("template=article, name=$pagename");
        if (!$match->id) {
            throw new Wire404Exception();
        }
        echo $match->render();
        return $this->halt();
    }
    // site/ready.php
    // taken from this great case study: https://processwire.com/talk/topic/3987-cmscritic-development-case-study/
    wire()->addHookBefore('Page::path', function($event) {
        $page = $event->object;
        if($page->template == 'article') {
            $event->replace = true;
            $event->return = "/$page->name/";
        }
    });

    If you copy-and-paste, pls note that my template is called 'article', not 'article-page' 🙂

    Attached also the home template URL segment settings.

    Screenshot_2020-02-13 Edit Template Home (home) • pwbig test.png

    • Like 1
    • Thanks 1

  6. @nabo

    What's your use-case? From a security point of view it's not a good idea to allow everything. Surely you have an idea what kind of file-types will be used?

    I found another forum thread where basically the same question was asked, and the gist of it was: No, you can't. Leaving the allowed extension config list empty makes it unusable, and just entering a wildcard * won't work either. @ryan takes security matters very seriously, and personally, I wouldn't want to have such a "everything goes" option built-in the core, too.

    If you have to, for some reason, import data from another system, and create / populate fields via API (batch actions), you can temporarily allow each file extension that comes your way, and then switch back to a "normal" default set after save. But I guess you were asking about using the GUI options.

    • Like 5

  7. basic example / ideas:

    document.addEventListener("DOMContentLoaded", function (event) {
        const trackedLinks = document.querySelectorAll("#content a"); // adjust selector as needed
        trackedLinks.forEach(function (n) {
            n.addEventListener("click", function (e) {
                e.preventDefault();
                const href = e.target.getAttribute('href');
                console.log(href);
                // api = special page with tpl and URL-segments enabled:
                fetch(`/api/linktracker/?url=${href}` , {
                    method: "GET"
                })
                window.location = href;
            });
        });
    });

    (That's vanilla JS / ES6)

     

    if ($input->urlSegment1 === 'linktracker' && isset($_GET['url'])) {
    
        $url = trim($_GET['url'];
    
        // save to a textarea inside PW:
        $pg = $pages->get("123");
        $pg->of(false);
        $pg->linktracker = $pg->linktracker . "\n" . $url);
        $pg->save();
    
        // save to a custom DB table:
        $myDB = new PDO("mysql:dbname=linktracker;host=localhost", "root", "******",
            array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'"));
        $trackLinkQuery = "UPDATE tablename SET click_count = click_count + 1 WHERE url=`$url`";
        $query = $myDB->prepare($trackLinkQuery);
        $query->execute();
    
        // udpate a text-file
        file_put_contents('path/to/file.log', $url);
    
        // if those links are saved inside repeaters or similar, add one int field that you can increment / update:
        $pg = $pages->get("123");
        $pg->of(false);
        $pg->linktracker = $pg->linktracker +1; // or whatever / wherever your field is....
        $pg->save();
    
    }

    These are 4 basic ways how you could handle it - there are certainly more 🙂

    Hope that gives you some ideas.

    • Like 2

  8. 5 minutes ago, ceberlin said:

    Parent pages with thousands of children do not open for editing in backend. They timeout with Error 500.

    Indeed. It once took me ages to find out why. Since then I keep it installed, but only activated for certain templates 🙂

    • Like 2

  9. 32 minutes ago, manlio said:

    Actually I wanna build a fancy dashboard but not integrated in PW admin

    Well, you can build just about anything with any (or without) frameworks.

    33 minutes ago, manlio said:

    and I should use PW just to send Json files

    Now I'm even more confused. You certainly don't need PW just to "send JSON files".

    Perhaps you'll get more productive tips and pointers if you describe what it is that you are actually trying to achieve.

    12 hours ago, manlio said:

    I need to rebuild a backend (with messages management,profile, ecc...)

    That's as vague as it can get. So it's now PW, but... what?

    Perhaps you should take some time and describe what you actually need to accomplish. And what this "backend" looks like (technically).


  10. @manlio

    If you want to enhance PW's backend, you're free to use whatever you find useful. Depending on the actual task / use-case, adding Vue.js or a similar SPA framework may be overkill. But if you need to build a fancy dashboard / complicated admin pages, then Vue can perhaps add some nice extras.

    8 hours ago, manlio said:

    some advice about file structures

    Care to elaborate on this? You mean "where should these extra frontend assets be stored?" Typically under site/templates. Static assets maybe rather in site/assets/.

    Make sure to check out @bernhard's epic tutorial about building your own PW module / dashboard. There's a lot of stuff "under the hood" to discover, with functionalities already available out of the box. So if you think about building something along those lines, adding a big JS framework might be overkill, too. Generally speaking it's best to get a solid grasp of vanilla JS. Frameworks tend to make you lazy - e.g. when you're using frameworks to solve problems that vanilla JS can solve just fine by itself.

    A little recommendation: Here's an excellent tutorial where you learn (among other things):

    • Nuxt
    • Vue.js
    • Dynamic routing (pages, categories)
    • Axios
    • Frontend communicating with a headless CMS (I have re-written the relevant code-bits to work with PW instead of Cockpit)
    • Dynamically setting title tag + meta (stuff that some frontend devs often don't care about - but your customer surely will)
    • Deployment on Netlify (not that I would actually need that - but I guess it's nice to know what the fuss is all about)

    I skipped several parts... Markdown, Tailwind... and I'm only done with half of it. But it's fun to see how easy it is to have PW generate one or two JSON files, and you're good to go (especially when you have a PW site already with lots of content to play around with). It depends if you really want to learn about all these things ("Developing website is not my primary job"), but it can't hurt.

    • Like 4

  11. 23 minutes ago, Gadgetto said:

    very constructive critic!

    Sorry, I know it's beta, I read (and can only imagine) how much work was involved. And as I stated before, it really is a nice touch to have that luxury of installing a few test pages instead of having to create them manually from scratch - just with a few clicks. And I was seriously impressed by the feature-set, the dashboard etc. However, uninstalling a PW module (no matter how big, if free or commercial) shouldn't be something that takes more than 2-3 minutes. I'm probably spoiled, but I just thought I'd mention it here anyway.


  12. @Gadgetto OK, since I don't really need any kind of shop solution, I decided to uninstall SnipWire. That was... an unpleasant experience. This took me about half an hour. The regular module uninstall routine didn't work for anything SnipWire-related. There were warning about pages or fields or templates having the system-flag. The page under admin > setup was undeleteable. In the end I had to delete two pages that were in the trash directly in the database. I hope there is nothing else left in the PW installation now in some hidden corners...


  13. @tpr I don't remember if I have posted this already some time ago... The option "disable all admin animations" practically makes the vec-dialogs unusable. The dialog will appear, but won't disappear when you choose either of the options. You then have no choice than to hard-reload the page. Maybe a word of caution would be nice in the settings. I stumbled over this a long time ago, and recently forget how to fix it.

    • Like 1

  14. hmmm, so I rewrote the templates, and made sure the three required frontend assets are loaded (Snipcart JS + CSS  + jQuery), but it looks completely un-styled, and there is no quantity-stepper anywhere.

    1957351695_Screenshot_2020-02-07AxolotlJuicer.thumb.png.aaf349c6ef6f45f7816c5ac40561eccc.png

    582391400_Screenshot_2020-02-07AxolotlJuicer(1).png.030abcec2b0703a9b9829e19538b7fd5.png

    I've even added UIKit CSS + JS now... it looks a bit different, but still... far from the screens you posted. Maybe I'll try on a new PW installation with the regular profile. While it's certainly nice that you provided such a test-setup with templates and dummy products, I think it shouldn't be dependant on what site profile you used when installing PW. If I inspect certain elements that have classed, I don't see any style definitions.

    But maybe the problem is elsewhere... here are the (probably) relevant settings on the product page:

    593721225_Screenshot_2020-02-07EditPageAxolotlJuicerpwbigtest.thumb.png.f83e22820a36ca63431ea84d47f10fd6.png

    But I guess what I see is "stackable" variety... When I inspect the button, I see:

    <button class="snipcart-add-item uk-button uk-button-primary" title="Add to cart" aria-label="Add item to cart" data-item-name="Axolotl Juicer" data-item-id="JUICER_123" data-item-price="{&quot;chf&quot;:&quot;10&quot;,&quot;eur&quot;:&quot;8.50&quot;,&quot;usd&quot;:&quot;10&quot;}" data-item-url="http://pw.test/en/snipcart-shop/axolotl-juicer/" data-item-description="Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur." data-item-image="http://pw.test/site/assets/files/23131/beer3.65x65-hidpi.jpg" data-item-metadata="{&quot;id&quot;:23131,&quot;created&quot;:1581076192,&quot;modified&quot;:1581078285,&quot;published&quot;:1581076192,&quot;created_users_id&quot;:41,&quot;modified_users_id&quot;:41}" data-item-quantity="1" data-item-quantity-step="1" data-item-stackable="false" data-item-taxable="true" data-item-taxes="CH" data-item-has-taxes-included="true" data-item-shippable="true"><span uk-icon="icon: cart" class="uk-icon"></span> Add to cart</button>

    but no quantity stepper markup anywhere.


  15. @Gadgetto First of all a big thank you for creating such a module!

    I have installed it just now for the first time. I followed the installation / configuration steps, defined templates etc. But in the frontend I get an error when trying to access mysite.com/snipcart-shop/

    1743277425_Screenshot_2020-02-07ErrorCalltoundefinedfunctionProcessWireukIcon().thumb.png.07d7e5be5916178130e7f01c95d74d1c.png

    Any ideas what went wrong? I'm using latest PW dev, and AdminTheme UIKit is installed + active.

×
×
  • Create New...