-
Posts
2,233 -
Joined
-
Last visited
-
Days Won
47
Everything posted by netcarver
-
Add Image from input type="file" possible - or must it be WireUpload?
netcarver replied to simonGG's topic in General Support
@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. -
@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!
-
@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
-
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.
-
Deleting file field's files via API not working or timing out
netcarver replied to hellomoto's topic in General Support
@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? -
Deleting file field's files via API not working or timing out
netcarver replied to hellomoto's topic in General Support
Is your server running php-fpm by any chance? -
Deleting file field's files via API not working or timing out
netcarver replied to hellomoto's topic in General Support
@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); } -
Deleting file field's files via API not working or timing out
netcarver replied to hellomoto's topic in General Support
@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); } -
Deleting file field's files via API not working or timing out
netcarver replied to hellomoto's topic in General Support
@Jason Huck Could you try using removeAll() rather than deleteAll()? -
@ceberlin Thanks for checking that out. Regarding the HERE map series - I'm seeing the same here.
-
@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.
-
Does the DB user you are initially connecting as, have rights/permissions to create/alter/drop tables?
-
@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?
-
@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.
-
@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.
-
@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.
-
@Mats That would be great - thank you! Once you pull the changes can I suggest you bump the version number of FieldtypeLeafletMapMarker.
-
@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.
-
@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.
-
Please bring back the "Mark as solved" button
netcarver replied to dotnetic's topic in Wishlist & Roadmap
@Pete No worries, thanks for looking anyway. -
Please bring back the "Mark as solved" button
netcarver replied to dotnetic's topic in Wishlist & Roadmap
@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. -
Module Wire Queue, basic implementation of simple queues
netcarver replied to horst's topic in Modules/Plugins
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!- 28 replies
-
- 12
-
Bump. @Krlos, did you get this working?
-
@Krlos, just writing to acknowledge your post. Please could you send me your site/ready.php file via the forum message system so I could have a look at it tonight? (Please don't post it here.)
-
@mrkhan You are not handling the uploads correctly at the moment, take a close look at the first comment on the page horst pointed you to. It shows you what you need to know about handling file uploads. You should not trust the file-name supplied by the upload so that example shows you how to validate that the file was supplied via an upload (using the move_uploaded_file() function) how to name it without having to trust the supplied file name how to validate the mime type of the file how to append the extension that represents the file type of the uploaded file You just need to remember the name you gave it when you moved it and attach that to your outgoing email. I've updated part of the code from the comment I linked to so that you can see how you might generate the new name and extension. // You should name it uniquely. // DO NOT USE $_FILES['upfile']['name'] WITHOUT ANY VALIDATION !! // On this example, obtain safe unique name from its binary data. $new_name = "./uploads/" . sha1_file($_FILES['upfile']['tmp_name'] . ".$ext"; if (!move_uploaded_file($_FILES['upfile']['tmp_name'], $new_name))) { throw new RuntimeException('Failed to move uploaded file.'); } // Now attach the uploaded, validated & renamed file to your email. $mail->attachment($new_name); You'll need to tailor the code to do the needed validation on both of the files you want your users to upload of course. Don't forget to change where you want the files copied to as well.