Jump to content

Dennis Spohr

Members
  • Posts

    52
  • Joined

  • Last visited

Posts posted by Dennis Spohr

  1. Ah okay, then it makes sense! I thought that functionality was built in.

    If anyone needs this: I created the following to detecting the language:
    (The second one I got from https://stackoverflow.com/a/25749660)

    function LanguageDetection(array $available_languages)
    {
        $session = wire('session');
        $page = wire('page');
        $user = wire('user');
        $config = wire('config');
        $languages = wire('languages');
        
        if ($page->id == $config->rootPageID && !$session->languageDetected)
        {
            foreach (DetectPreferedLanguages($available_languages) as $language => $prio)
            {
                $user->language = $languages->get($language);
                break;
            }
    
            $session->languageDetected = true;
            $session->redirect($page->localUrl($user->language));
        }    
        $session->languageDetected = true;
    }
    
    function DetectPreferedLanguages(array $available_languages) {
    
        $available_languages = array_flip($available_languages);
        $langs = [];
    
        if (!isset($_SERVER["HTTP_ACCEPT_LANGUAGE"]))
            return $langs;
    
        preg_match_all('~([\w-]+)(?:[^,\d]+([\d.]+))?~', strtolower($_SERVER["HTTP_ACCEPT_LANGUAGE"]), $matches, PREG_SET_ORDER);
    
        foreach($matches as $match)
        {
            list($a, $b) = explode('-', $match[1]) + array('', '');
            $value = isset($match[2]) ? (float) $match[2] : 1.0;
    
            if (isset($available_languages[$match[1]]))
            {
                $langs[$match[1]] = $value;
                continue;
            }
    
            if (isset($available_languages[$a]))
                $langs[$a] = $value - 0.1;
        }
    
        arsort($langs);
        return $langs;
    }

     

    Now on the load of every page I just called my method like this (in my case at the $config->prependTemplateFile):

    LanguageDetection(['de']);

     

    On my site it seems to work with ProCache as well. I guess it depends on the settings in ProCache?

  2. Hi all,

    I have a multi-language site with 2 languages: the default one (English) and German.

    But if I load my root-page, the language of my guest ($user->language) is always the default one (English).
    My browser (Firefox in this case) is in German - so the $user->language should be set to German in this case, right?

    Shouldn't I define the German language somewhere with "DE" oder "DE-de"? How does the system knows actually that this is suppose to be the German translations?

    I already translated the C in
    wire--modules--languagesupport--languagesupport-module
    into de_DE.UTF-8 already.

    Any idea why this is not working?

    Thanks!
    Dennis

  3. $pages->parents()->rebuildAll() took around 16 seconds on our dev-server.

    For now we switched back to pw 3.0.148 and it seems that the error is not happening anymore.
    Also changing the parent is not as slow anymore.

    So there's definetely something going on with this new pages_parents table, but we were not able to reproduce the error with $page->find() on purpose.
    It randomly happened and for sure the pages_parents table was not correct anymore. But somehow fixed after seconds or minutes.

  4. I am running PW 3.0.165, the latest master version. 
    Unfortunately I can’t tell if it was faster before migrating to this version. Sometimes it was kind of slow, but I didn’t look into this in detail before.

    Today we figured out another problem with parents. When using $page->find() sometimes it doesn’t find an existing page (with $pages->find() it’s there). In this case it has to be something with the has_parent selector. After at least 20 minutes of testing and debugging, it was finally working without us changing anything.

    Probably the pages_parent table is not working correctly or is created/updated too late. But this doesn’t fix the first issue regarding the performance.

    Something strange is going on.

  5. Hi all,

    when I update the parent of an existing page, this process takes extremely long (20-30 seconds).

    $page->of(false);
    $page->parent = $trash;
    $page->save();

    Sometimes these tested pages doesn't even have a single child-page.

    Our database is quite large (but with a very fast server):

    • 900.000 entries in the pages table.
    • 90.000 entries in the pages_parents table.

    Is there any other way to change the parent or does anybody now where this could come from?

    We have multiple places where this is happening now.

    Thanks!
    Dennis

  6. Hi guys,

    yesterday I did an upgrade from ProcessWire 3.0.148 to 3.0.165. On the front-end part everything went fine.

    But on the Backend the CKEditor is just not loading anymore.

    In the console I can see the following errors:

    image.thumb.png.80323522926fc0531338ca8fe04294a7.png

    Any idea where this comes from?

    Thanks!
    Dennis

  7. I have to reopen this thread, because I still have these problems.

    I am absolutely sure that my user-name is valid and unique.
    Still, if using $users->add($name) I'm getting a NullPage back, but just sometimes.
    I couldn't find a way to reproduce this error on our test-server.

    Our database is huge, we have some traffic and probably sometimes users are created nearly simultaneously (but definitely with unique names)
    Currently we have more than 150k user-accounts in the system.
    Do you think that could be a problem?

    The solution of @Noel Boss is interesting. How will the user-name be generated in this case?

    Any help is really appreciated! Thank you!

  8. I created a tool where users can design their individual landingpage. Lately users want to implement their own html- and/or javascript code, for example for loading an iframe or custom tracking codes.

    If I give them an textarea, where they can paste their custom html or javascript code - is this secure?
    I would use $sanitizer->text to prevent sql injections.

    But is this a safe way? I don't (really) know which code they would save (and load).

    I would like to get an idea and your thoughts.

    Thanks and greetings from Malta,
    Dennis

  9. Finally I was able to reproduce the problem on the clean install of ProcessWire. It seems to be a problem with a SelectOptions-FIeld, when no value is set.

    I did the following on the clean install:

    • Create a new SelectOptions-Field with some values in it.
    • Assign the field to a template
    • Create a new Page of this template using the API:
    $mypage = new Page();
    $mypage->template = 'basic-page';
    $mypage->parent = $pages->get(1);
    $mypage->title = 'TEST';
    $mypage->save();
    
    print ($mypage->id);
    • Copy the ID of the new page and do the following:
    $mypage = $pages->get(1042);
    $pages->clone($mypage);
    • While doing this I get this exception:
    Quote

    Error: Exception: Can’t save page 0: /test-1/: Call $page->of(false); before getting/setting values that will be modified and saved. [Page::statusCorrupted] fields: images, selectoptions (in D:\xampp\htdocs\pw-test\wire\core\PagesEditor.php line 515)

    selectoptions is the name of my SelectOptions-Field. Settings $page->selectoptions = ''; seems to create the same problem (no value set).

    I don't think this should be the expected behavior?

  10. I have another weird behavior on this.

    If I use $pages->clone($mypage) I get this error:

    Quote

    Exception: Can’t save page 0: /ma/.../video/: Call $page->of(false); before getting/setting values that will be modified and saved. [Page::statusCorrupted] fields: align, textalign, position

    Looks like somehow something is corrupt. But I don't have any idea why and how to fix it.

  11. Hi all,

    I have a weird behavior. I'm using the following code to clone one of my pages:

    $block = $salespage->children("id={$duplicate_id},include=all")->first();
    $block->of(false);
    
    if ($block && $block->id)
    {
      $newone = $pages->clone($block);
    }

    Problem: the page itself gets cloned, but on of the fields (a repeater) does not get cloned. It's empty.

    If I do the same in the ProcessWire-Admin via the PageTree, it works fine. The repeater-field gets cloned there as well.

    What could be the problem?

    Thanks,
    Dennis

×
×
  • Create New...