Jump to content

kixe

Members
  • Posts

    803
  • Joined

  • Last visited

  • Days Won

    10

Posts posted by kixe

  1. @adrian Thanks for pointing on this. I added a fallback to the standard dechex() function for 64-bit systems.

    In the rare case that neither the BCMath extension is installed nor the system can handle 64-bit integers, the module is not installable.

    • Like 1
  2. On 8/7/2018 at 11:21 PM, Guy Incognito said:

    Ah ok - that's interesting thanks. So are all Processwire object accessible like this within hook context?

    Just to clarify:
    Usually there is only one instance/ object of ProcessWire which is the ProcessWire boot object represented by the variable $wire.
    ProcessWire is a child class of Wire.

    Assuming you are talking about all Wire objects the answer is YES and more:

    // Access to a wire object from inside a wire derived class:
    $pages = $this->wire('pages');
    
    // Access to the current ProcessWire instance:
    $wire = $this->wire();
    
    // Create new wire object inside your ready.php
    $this->wire('ferry', '/site/translations.php');

    Read more: https://processwire.com/api/ref/wire/wire/

    • Like 2
  3. Tried to add an item to an array, which is a page property. The common way doesn't work. Is there a PHP expert out there who can explain that to me? Thanks.

    $page->prop = array('a','b','c');
    $page->prop[] = 'd';
    var_dump($page->prop);
    // output: array(3) { [0]=> string(1) "a" [1]=> string(1) "b" [2]=> string(1) "c" }
    
    $page->prop = array('a','b','c');
    $page->prop = array_merge($page->prop, array('d'));
    var_dump($page->prop);
    // output: array(4) { [0]=> string(1) "a" [1]=> string(1) "b" [2]=> string(1) "c" [3]=> string(1) "d" }

     

  4. If you need this for the backend (result available in frontend too) you can use FieldtypeMarkup for the result. Grab the code from here: https://github.com/kixe/FieldtypeMarkup

    Create a hook with your formula and place the code in /site/ready.php
    The result will be populated after saving the page.
     

        /**
         * https://github.com/kixe/FieldtypeMarkup
         * FieldypeMarkup as concat field with formula
         * EXAMPLE 
         *
         */
        $wire->addHookAfter('FieldtypeMarkup::formatValue', function($e) {
            $page = $e->arguments[0];
            $field = $e->arguments[1];
    
            // quick exit
            if ($field->name != 'result') return;
    		if ($page->template != 'calculator') return;
    
            $value1 = $page->inputfield1;
            $value2 = $page->inputfield2;
            $value3 = $page->inputfield3;
            $value4 = $pages->get(12345)->inputfield1; // get value from another page
    
            $result = $value3 * ($value2 - $value3) / $value4; // formula
    
            $e->return = $result;
        });

     

     

    • Like 3
  5. Set up a page which just return the cookie banner, put it in an iframe and add it to the other sites. You would have to change (loosen) the x-frame options in your .htaccess file of the framed page to get this work. All-in-all not the best solution.

  6. You can change the module service url in your config.php file.

    $config->moduleServiceURL = 'http://modules.processwire.com/export-json/';
    $config->moduleServiceKey = (__NAMESPACE__ ? 'pw300' : 'pw280');

    Format of the complete url: {moduleServiceURL}/{moduleClassName}/?apikey={moduleServiceKey}

    Example: http://modules.processwire.com/export-json/MarkupCookieConsent/?apikey=pw300
     

    If you provide this service (json format) for your module by your own you could hook in ProcessModule::execute

    if ($input->get->update) {
        $this->addHookBefore('ProcessModule::execute', function($e) {
            $moduleClassName = $this->wire('sanitizer')->name($this->wire('input')->get->update);
            if ($moduleClassName != 'MySuperPrivateModule') return;
    
            // change service url here
            $this->wire('config')->moduleServiceURL = 'http://example.com/export-json/';
        });
    }


    Another solution: Symlink your module if all sites using this module are hosted on the same server.

    • Like 7
  7. @wbmnfktr

    54 minutes ago, wbmnfktr said:

    Not a reason but a scenario for this error message.

    The reason is the invalid token: https://github.com/processwire/processwire/blob/bdaf8810cbb71944820c45e0b297d0b75f1e60be/wire/core/SessionCSRF.php#L176-L191

    1 hour ago, wbmnfktr said:

    At least it happens to me regularly on different PW sites.

    Make sure that the session cookie is set and valid and that the current valid token is sent with the form.

  8. All forms in the backend of processwire are secured against CSRF attacks by assigning them a one-time token. This will ensure that the page and the current session that generates the form is the same as the one that receives the form. E. g. The error message appears when a backend page (also Login) is open and the session has expired, or the session cookie has been deleted from the browser or could not be set in the browser.

    • Like 1
    • Thanks 1
  9. Try this hook in hook

    $this->addHookBefore('PageRender::renderPage', function($e) {
        $event = $e->arguments[0];
        $page = $event->object;
        $user = $this->wire('user');
    
        // QUICK EXIT
        if ($user->isSuperuser()) return; // superuser
        if (!empty($page->template) && $page->template->id == 2) return; // backend
        if ($user->language->isDefault()) return; // default language
    
        $language = $user->language;
        $currentLanguageStatus = $page->get("status$language");
        if ($currentLanguageStatus == 0) {
            $otherPage = $this->wire('pages')->get(1234); // get page to be rendered instead
            $event = new HookEvent(array('object' => $otherPage));
            $e->arguments(0, $event);
        }
    });

     

    • Like 3
  10. The banner is always displayed at the bottom of the page. You can limit the appearance to certain pages via module settings. e. g.

    1264856490_Bildschirmfoto2018-05-18um19_48_30.thumb.jpg.85ad6cc8befeb6e2edd6b97a1bc55bc7.jpg

    Do you use iframes for your forms? If yes, each iframe has its own body tag. The banner is prepended to each closing body tag. Disable the banner by module settings (using selectors) for the framed pages.

×
×
  • Create New...