Jump to content

netcarver

PW-Moderators
  • Posts

    2,241
  • Joined

  • Last visited

  • Days Won

    47

Everything posted by netcarver

  1. You might need to do this after the foreach loop... $pageNew->save();
  2. Slight tweak - probably never be needed... if (false !== file_put_contents($file, $data)) { $p->item_images->add($file); unlink($file); } Might save you an error if a file save ever fails.
  3. @jploch I've never used this in a repeater setup and I'm unsure of your field/template structure from that snippet. How have you actually structured things? What's the field called that holds the map markers? Regarding the backend, the address is normally a read-only field that is set either by clicking on the magnifying glass in the top-right corner of the map and entering a description or by simply dragging the marker around. Have you tried moving the marker or using the search feature? If they don't work, it is possible there is a problem with some of the JS not loading properly. Please could you launch you browser dev tools and see if any of the JS assets are not loading.
  4. @simonGG I think Bitpoet is on the right tracks here regarding the need to save the page before adding images. The page does need to be saved before you attempt to add images to it as saving creates the assets directory that the images will eventually be copied into when they are added. IIRC, adding an image, eventually calls PHP's copy() function (look at the changelog section) which does allow adding images via URLs since PHP 4.3.0 provided that fopen wrappers are enabled. I have successfully added remote images to local PW pages before using the URLs of the remote images. However, not saving the page first is not your only issue. Firstly, does the item template have a field called "images"? If not, it needs one. Second - and I'm slightly unsure about this - It looks like you are actually passing in the actual base64 encoded images rather than an array of URLs to the images. Your code expects this line... $item_images = $_GET["item_images"]; ...to give you an array of URLs that you can iterate over - but it seems to be giving you an array of strings that look like the base64 encoded content of the URL (guessing as I can't tell what you are doing here.) I think you will need your $item_images variable to be an array of URLs like https://path/to/some/image.png for this method to work. Sorry I can't be more specific.
  5. @pleini Does this occur only when PW is trying to access those files? Do you have any issues accessing the files from the command line or ftp? My first thought when I read your description is that of possible disk corruption. It doesn't sound like it's a permissions issue as the permissions on the files shouldn't be changing, nor should the user the server process is running as. Sorry I can't be of more help!
  6. @Reid Bramblett Glad that worked out for you. @Mats Thanks for pulling our changes back into your repository - great! I made a few little tweaks to my repo since you did the merge; any chance of getting them pulled over to your repo as well? >PS Nice change to your avatar! I like the look of those T-shirts
  7. Hi Reid, Give this a shot. It's a template file that should do what you want if you are using my fork of the Leaflet module. <!DOCTYPE html><?php // Create our Leaflet map object. We do it here, before the header output, so we can use it to generate includes in the // header itself. $map = $modules->get('MarkupLeafletMap'); ?> <html lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title><?php echo $page->title; ?></title> <link rel="stylesheet" type="text/css" href="<?php echo $config->urls->templates?>styles/main.css" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <?php echo $map->getLeafletMapHeaderLines(); ?> </head> <body> <h1><?php echo $page->title; ?></h1> <?php // Extract the pages that will be turned into markers on the map $items = $pages->find("<YOUR SELECTOR HERE>"); // Update as needed // Setup the options for our map $map_options = array( // This routine formats the marker icon that gets used on the map. 'markerFormatter' => function ($page, $marker_options) { switch ($page->category) { // Update with the fieldname you wish to check as needed // For sleep category markers case 'sleep' : $marker_options['icon'] = 'bed'; $marker_options['markerColor'] = 'orange'; break; // Add other cases as needed // Here's the default marker setup default : $marker_options['icon'] = 'cutlery'; $marker_options['markerColor'] = 'blue'; break; } return $marker_options; } ); // Generate the HTML and JS that will render the map with a marker for each page in the $items page array echo $map->render($items, '<YOUR MAP MARKER FIELDNAME HERE>', $map_options); // Update as needed ?> </body> </html> Please be aware that the icon colours you can choose from are pretty limited. Look at the 'markerColor' row in the table here for your options. Hope that helps.
  8. @Jason Huck Hmmm. So HAProxy is in the mix. Ok, here's a possible scenario that might fit your observations; If HAProxy's server connection times out before Apache finishes, you'll get a 50x error reported (not sure if 502 or 504) in the browser yet the Apache process will probably complete without error behind the dropped connection. Have you looked at the "timeout server" setting (and the other timeout settings) in your HAProxy config file (/etc/haproxy/haproxy.cfg)? I think you'll need to up that beyond where you have the timeout set for the PHP script execution. Edited to add: Have you thought about moving this processing load into a background task?
  9. Is your server running php-fpm by any chance?
  10. @Jason Huck Yikes! Sorry, my mistake - I forgot that realpath() also checks for file existence and needs lots of permissions set up right. Let me try again. $has_image = false; if(startsWith($image_data_raw, '0x')){ $image_data = hex2bin(ltrim($image_data_raw, '0x')); $image_path = wire('config')->paths->templates.'tmp/'.$line[18]; $has_image = file_put_contents($image_path, $image_data); } ... // add image, save page again, and remove temporary image if(false !== $has_image){ if($product->image) { $product->image->deleteAll(); // get rid of anything that's already in there $product->save('image'); // try saving after delete to avoid 502's } $product->image->add($image_path); $product->save('image'); // save just the image field instead of the whole page unlink($image_path); }
  11. @Jason Huck I don't think this will sort out your problem - but you might want to do your realpath() call earlier - before you call file_put_contents() to save the image to tmp storage. You should also check the return value of that call and not try to store the image if it failed to write it to the tmp location. if(startsWith($image_data_raw, '0x')){ $image_data = hex2bin(ltrim($image_data_raw, '0x')); $image_path = realpath(wire('config')->paths->templates.'tmp/'.$line[18]); // Realpath here $has_image = file_put_contents($image_path, $image_data); // Use return value to signal need to add the image } else { $has_image = false; } ...and... // add image, save page again, and remove temporary image if($has_image){ if($product->image) { $product->image->deleteAll(); // get rid of anything that's already in there $product->save('image'); // try saving after delete to avoid 502's } $product->image->add($image_path); $product->save('image'); // save just the image field instead of the whole page unlink($image_path); // Now no need to realpath() here. } Also, have you tried saving the entire product page rather than just the 'image' field? // add image, save page again, and remove temporary image if($has_image){ if($product->image) { $product->image->deleteAll(); $product->save(); } $product->image->add($image_path); $product->save(); unlink($image_path); }
  12. @Jason Huck Could you try using removeAll() rather than deleteAll()?
  13. @ceberlin Thanks for checking that out. Regarding the HERE map series - I'm seeing the same here.
  14. @Juergen If you pull the latest version of my master branch you'll be able to exclude the FontAwesome css file by doing the following: <?php echo $map->getLeafletMapHeaderLines(false); ?> Edited to add: Actually, you can just replace your copy of MarkupLeafletMap.module with the new one from the repository.
  15. Does the DB user you are initially connecting as, have rights/permissions to create/alter/drop tables?
  16. @ceberlin Great to hear that. I've switched my master branch over to Leaflet 0.7.7 from the npmcdn links you posted above. Could you try out the files from the master branch?
  17. @Beluga I just pushed a new leaflet-v1.0.0rc2 branch to my repo - works nicely. @ceberlin If you were referring to my work above, please try out the v1.0.0rc2 branch as it pulls the files in from the npmcdn you referenced in your quote.
  18. @ceberlin Could you describe a little more about which version you are trying - Mats', gebeer's or the one I posted? I did have some trouble initially with getting the Leaflet related files in the right place. Having a script blocker running also broke things for me - once I enabled all JS on my local site things started working a lot better. @Beluga I haven't tried that version - yet. Can't speak for Mats or gebeer. See below.
  19. @houseofdeadleg Gebeer was on the right track when he posted the above. The error is due to the use of single quotes - I ran across it as part of the work I posted about above. If you still want to try the approach gebeer introduced then give this a shot... $options = array(); $safe_title = str_replace("'", "\'", $page->title); $safe_title = str_replace("\n", "<br />", $safe_title); $safe_body = str_replace("'", "\\'", $page->body); $safe_body = str_replace("\n", "<br />", $safe_body); $options["markerPopupContent"] = "<b><a href=\"{$page->url}\">$safe_title</a></b>$safe_body"; // ... more options $map = $modules->get('MarkupLeafletMap'); echo $map->render($items, 'map', $options); We have to make sure that no un-escaped single quotes appear in anything we generate that gets inserted via the JS on the page. That also means we have to use escaped double quotes around the link's href attribute. We also have to prevent newline characters getting through that are part of any field - I do that as shown above rather than use the nl2br() method as nl2br prefixes all newlines with <br/> but does not remove the newlines. Hope that helps! Edited to add: Forgot to say, with the new version of the module you can just do this... <?php $map = $modules->get('MarkupLeafletMap'); $options = array( 'popupFormatter' => function($page) { return $page->body; } ); echo $map->render($items, 'your-marker-field-name', $options); ?> That will append the page body content to the popup window. It also takes care of escaping single quotes and converting newlines into HTML breaks.
  20. @Mats That would be great - thank you! Once you pull the changes can I suggest you bump the version number of FieldtypeLeafletMapMarker.
  21. @Mats @gebeer Thanks to a job I just finished for @dab I have been actively taking your work forward. I have a fork of the project here that... Simplifies getting the needed files used by MarkupLeafletMap into a template's header Integrates the Leaflet.AwesomeMarkers project and the latest FontAwesome icons into the module Adds a callback function for customising the content's of a marker's popup box Adds a callback function for customising the visual appearance of any marker Updates the readme file significantly Provides an example template file to help get folks underway with this module in their projects I based my work on gebeer's extension of your repo Mats, so I have issued a pull request to gebeer - but I'd like to get these changes into your repo if possible as then we can revert to your repo as the master codebase and, hopefully, have the latest goodies straight from the PW module directory. It's now very easy to add fields to the marker pages that let you customise their appearance. Below I have added an Options field, a FieldtypeFontIconPicker and a Text field to control the marker visuals via the added callback. If anyone want's to try it out, here is the link to the zip file.
  22. @bernhard Don't know how I missed your original post about that - looks great, have just added my likes to it. I think it would be a great to try merging the two.
  23. @Pete No worries, thanks for looking anyway.
  24. @Pete Did the list of trimmed features include the ability to mark individual posts as read from the 'All activity' and 'Unread' pages? I miss that feature a lot from the old version, I used to use it in conjunction with the list of all unread posts from the last 24 hours.
  25. Horst and I would like to announce the release of v1.0.0 of the WireQueue suite of modules. There are now drivers for textfiles, redis and SQLite and the interface has been extended to include the isEmpty(), purgeItems() and getItems() methods. Enjoy!
×
×
  • Create New...