Jump to content

a-ok

Members
  • Posts

    812
  • Joined

  • Last visited

Posts posted by a-ok

  1. I know these posts have been created a lot and I've trawled through a bunch and can't seem to find a solution for my current problem.

    I moved a PW site from my own DigitalOcean droplet > it's own Droplet and the homepage works fine but every other page gets stuck in a 301 redirect loop.

    I used curl to debug it a bit:

    curl http://159.65.162.128/products/ -vvv
    *   Trying 159.65.162.128...
    * TCP_NODELAY set
    * Connected to 159.65.162.128 (159.65.162.128) port 80 (#0)
    > GET /products/ HTTP/1.1
    > Host: 159.65.162.128
    > User-Agent: curl/7.54.0
    > Accept: */*
    > 
    < HTTP/1.1 301 Moved Permanently
    < Date: Tue, 12 Nov 2019 12:03:55 GMT
    < Server: Apache/2.4.41 (Ubuntu)
    < Expires: Thu, 19 Nov 1981 08:52:00 GMT
    < Cache-Control: no-store, no-cache, must-revalidate
    < Pragma: no-cache
    < X-Powered-By: ProcessWire CMS
    < Set-Cookie: wire=de9ifnvlqr75l546fg66a1tkrd; path=/; HttpOnly
    < Upgrade: h2,h2c
    < Connection: Upgrade
    < Location: /products/
    < Content-Length: 0
    < Content-Type: text/html; charset=utf-8
    < 
    * Connection #0 to host 159.65.162.128 left intact

    And in the Network tab in Chrome it seems to just keep redirecting to the same page and then eventually errors out.

    862364673_Screenshot2019-11-12at12_14_13.thumb.jpg.a68d8eda13e2897f79c67bb1347aafc3.jpg

    My .htaccess file is exactly how it was on the other DigitalOcean droplet and I have no idea where to go to now. I don't have any SSL set up yet either so no modifications to any vhosts files.

    Any immediate thoughts or has anyone had this issue before?

  2. 2 minutes ago, bernhard said:

    Yes. That were 2 different questions, the more interesting being WHY you want to use AJAX for site navigation ? 

    Page transitions etc and I guess barba is just an alternative to that. I see what you’re getting at but as I’d still have this issue with barba then the issue still stands ?

  3. I'm looking for some best practice advice.

    A standard setup for me is to have a head.inc and a foot.inc and then everything in-between is updated via AJAX calls with some transition. Getting a bit boring but that's currently how it is. The issue I have is most of the time the main site nav/menu, which is in the head.inc, is contextual and will change based on the page being view. This can cause a lot of duplication of code as 1) I write it with PW in PHP so if the page is visited directly it is reflected and 2) I also have to do the same in JS if the page is visited via an AJAX call. You see the dilemma.

    What I've started to do recently is build a PHP array in an include file for the menu, and also `json_encode` it so I have an array, of the same code, one for PHP to use and one for the JS to use. Something like the below...

    $menuArray = array();
    
    $menuLeft = $pages->find("template=work|news, sort=sort");
    $menuRight = $pages->find("template=clients|about, sort=sort");
    
    if ($page->id !== 1) {
        $menuLeft->filter("id={$page->id}");
        $menuRight->filter("id={$page->id}");
    }
    
    foreach ($menuLeft as $item) {
    
        $menuArray['left'][] = array(
            'id' => $item->id,
            'name' => $item->name,
            'url' => $item->url,
            'title' => $item->title,
            'x' => '100%'
        );
    
        // If current page then prepend 'Close'
        if ($page->template->name == $item->name) {
            array_push($menuArray['left'], array(
                'name' => 'close',
                'url' => $pages->get(1)->url,
                'title' => 'Close',
                'x' => '100%'
            ));
        }
    
    }
    
    foreach ($menuRight as $item) {
    
        $menuArray['right'][] = array(
            'id' => $item->id,
            'name' => $item->name,
            'url' => $item->url,
            'title' => $item->title,
            'x' => '100%'
        );
    
        // If current page then append 'Close'
        if ($page->template->name == $item->name) {
            array_unshift($menuArray['right'], array(
                'name' => 'close',
                'url' => $pages->get(1)->url,
                'title' => 'Close',
                'x' => '100%'
            ));
        }
    
    }
    
    // Return JSON for JS (PHP can grab $menuArray directly)
    $menuJSON = json_encode($menuArray);
    
    if ($config->ajax) {
        echo '<script id="menuJSON">';
            echo "menuJSON = {$menuJSON}";
        echo '</script>';
    }

    Then in the head.inc loop through `$menuArray` and in the JS loop through, on AJAX changes, `menuJSON`.

    updateMenu: function(e) {
        
        var $header = document.querySelector('header.main'),
            headerContent = '';
    
        for (var menu in menuJSON) {
            headerContent += '<ul class="menu --' + menu + '">';
            menuJSON[menu].forEach(function(item) {
                headerContent += '<li data-template-name="' + item.name + '"><a data-ajax data-x="' + item.x + '>" href="' + item.url + '">' + item.title + '</a></li>';
            });
            headerContent += '</ul>';
        }
        $header.innerHTML = headerContent;
    
    }

    The issue I'm having is I have no idea if this is the best way to work with something like this and wondered if anyone had any input?

    It also feels weird echo'ing out script tag with PHP then relying on the JS finding it in the DOM. You know?

    Anyway... I'll put this out there and see what happens ?

  4. 2 hours ago, dragan said:

    Are you using image compression at all?

    Are you seriously going to use 18 variations in a live site? Or is this just a test?

    Not to my knowledge. I have this in my config.php file:

    $config->imageSizerOptions('sharpening', 'none');
    $config->imageSizerOptions('quality', 100);
    $config->imageSizerOptions('defaultGamma', -1);

    And yes just a test ?

  5. I'm resizing my images for img srcset using a helper function:

    function getSrcsetImages($image, $variations, $sizes) {
    	$srcset = array();
    	if (empty($variations)) {
    		$srcsetSizes = array(100, 200, 300, 400, 500, 640, 750, 828, 1024, 1125, 1242, 1280, 1400, 1500, 1600, 1700, 1800, 1920);
    	} else {
    		$srcsetSizes = explode(", ", $variations);
    	}
    	foreach ($srcsetSizes as $s) {
    		if ($s <= ceil($image->width())) {
    			$srcset[] = $image->width($s)->url() . " {$s}w";
    		}
    	}
    	$srcset = implode(", ", $srcset);
    	echo "src=\"{$image->url}\" data-srcset=\"{$srcset}\" sizes=\"{$sizes}\"";
    }
    
    <img <?php getSrcsetImages($image, null, "auto"); ?> class="--lazy" />

    This works in theory but in my assets folder why are the variations, on average, larger than the original? Feels like I should just use one image at this point?

    190412416_Screenshot2019-10-11at20_57_34.thumb.jpg.f6ae822bed7adf70889ee8fe898e8472.jpg

    Any thoughts on what I'm doing wrong?

  6. Is it possible to skip the Page Add step when creating a child page that fills in both the title and name? I've used the template specific setting https://processwire.com/docs/modules/guides/process-template/ but this still requires the user to set a title.

    Any thoughts? I thought about using a hook https://processwire.com/talk/topic/13058-set-page-title-automatically/ but this doesn't skip the Page Add step.

  7. Thanks everyone.

    Do you think it's possible to filename sanitize a folder of images on my local? I'm guessing that's what @Robin S meant when he said:

    10 hours ago, Robin S said:

    4. Add all the unorganised images to the new page. Personally I would do this using the API together with glob or DirectoryIterator but you might be able to do it via the admin if you allow a lot of memory and a set a long max execution time. This step will sanitize the image filenames.

    I'll look into it!

  8. Thanks so much, @Robin S

    Using Automator for Mac I'm going to open a finder file (the .csv) then run a bash script that would create a folder for each ID and move the corresponding image to that folder. A folder can have multiple images.

    As the DB is all intact it’s only the image links that are missing so this, in theory, should work. I just need to run something on all the images to sanitize them as PW did when the user uploaded them.

    Would you say using the API, as you’ve kindly shared, is a better approach and more effective and fool proof?

    My bash script:

    cd "${1%/*}"
    
    while read line         
    
    do         
    
         FolderName=${line%,*}
    
         ImageName=${line#*,}
    
         mkdir "$FolderName"
    
         mv "$ImageName" "$FolderName"
    
    done < "$1"
    
  9. This is slightly related to PW but also in need of some advice/help.

    I stupidly accidentally managed to rm -rf the LIVE assets folder on a site that has over 2 years worth of data. Let's not go there. I had a cronjob set up every night to back everything up (and keep the latest 7) but the .tar.gz files all error out with truncated tar archive and unexpected end of file

    I've managed to export off the image fields from the database as .csvs and my plan would be to combine them all into one .csv where you have two columns (ID and image filename). I then have a large unorganised dump of ALL the images but they:

    1. Haven't had their filenames sanitised by the PW uploading and
    2. Are all in one directory and thus not attached to any page ID

    My question is... how likely do you think it would be to use PW's API to:

    1. Sanitise all the filenames in a directory (and if anyone knows what type of sanitising images use) and
    2. Execute some sort of query (I'm on OSX) that would match the filename in the CSV with the filename in a directory (the image dump) and move the image to that folder with the same ID (this is a long shot)

    Any advice is appreciated.

  10. 1 hour ago, bernhard said:

    What happens if you replace this with the hardcoded url in the tracy example?

    Just replace block after block with working snippets and you'll find the problem or can at least narrow down where it is and tell us more about it ? 

    Thanks, @bernhard – I did this and it added the images (visible in the folders within assets) but upon visiting it in the backend they were removed with the same message 'Pageimages: Removed 'images' temp file(s) for..'

×
×
  • Create New...