Jump to content

Xonox

Members
  • Posts

    95
  • Joined

  • Last visited

Everything posted by Xonox

  1. Hi, @Zeka Thanks for your reply. Unfortunately the page cloning wasn't going through that page. It just cloned the existing page and displayed it in the tree. Apparently, there's some problem about the permissions. SOLUTION: Instead of giving Clone Permissions to just the templates you want to allow to clone, you should authorize page-clone for all editable templates and revoke all the templates except the ones you want to allow. This allowed the users to go through the clone page and select which options they want.
  2. Update: Clearly, the problem happens only with pages that have sub pages. Is there anyway I can clone a page, without cloning sub-pages?
  3. It looks that pages that have subpages can't be cloned?!?! Is there anyway that I can circumvent this? I would like to clone a page without the subpages.
  4. After some years with a website working perfectly, Page Clone started to display some strange behaviour: 1. When cloning some pages, it takes forever. The waiting icon is displayed but the page never appears. Only after I refresh the tree page, the new page appears: 2. The other thing is that some pages can't be copied. The pages have the same templates but the users are able to copy some and other don't. It gives this error: (the URL is .../page/clone/?id=76376&login=1) Does someone have a clue why this is happening. I can't find any real difference between the pages that I'm trying to copy. One more thing: If the user is a super user, he's able to copy every page without problems. I think both errors might be related. Thanks!
  5. Changing table to InnoDB solved it! Hi, that's what worked, for me, changing that one table (pages) into InnoDB. Because it was an issue that needed time, to see if it would happen again, I didn't update this issue. Hope this helps you!
  6. Update: If the field is outside a repeater, it works fine! In my dev server, everything works fine inside the repeater. In production server, the field inside the repeater doesn't work as it should. Inside repeater, I can't even edit image descriptions. Field outside the repeater works fine on both machines. I just remembered that I had this problem before, on another site, but never got solved: This is getting a bit annoying! ?
  7. It looks related, but I still can't get it to work. There are some new inputs: 1. The field is inside a repeater; 2. Despite the field being set to have only one image, in some cases it has more than one that I can't delete; 3. Tried to change files' permissions but it still doesn't work; 4. It's impossible to delete the images, but when I load a new one, it replaces one of the old ones. I'm a bit lost with this one. ?
  8. Update: I also can´t delete the slide_image_mobile images, which should be unique (only one image). It keeps adding images despite the field being set with only one image and "One element null if empty".
  9. I checked and it looks fine. To clarify: slide_image - is detected and used; slide_image_mobile - site behaves as it doesn't exist! Both have same permissions. I changed the code to the following to force the use of slide_image_mobile: foreach($page->home_slides as $slide) { $slide_image_mobile = $slide->slide_image_mobile->size(1048,800); ?> <img src="<?php echo $slide_image_mobile->url; ?>" class="img-fluid d-block d-md-none" title="<?php echo $slide->slide_title; ?>" alt="<?php echo $slide->slide_title; ?>" /> <?php } Which gives a Fatal Error (Call to a member function size() on null) which makes sense. But the image is there! ?
  10. Hi, There's something happening in ProcessWire that doesn't compute abd it has to do with images. Situation: On the homepage template there's a repeater that takes two images to build a slider: slide_image: A wide image for desktops slide_image_mobile: A more "verticalized" image for small screens Now I have this code: foreach($page->home_slides as $slide) { // Create desktop slide if(isset($slide->slide_image)) { // Create desktop slide $slide_image = $slide->slide_image->size(1170,400); // Create mobile slide if(isset($slide->slide_image_mobile)) { $slide_image_mobile = $slide->slide_image_mobile->size(1048,800); } else { $slide_image_mobile = $slide->slide_image->size(1048,800); } ?> <div class="slide-content"> <a href="<?php echo $slide->link; ?>" class="slide"> <img src="<?php echo $slide_image->url; ?>" class="img-fluid d-none d-md-block" title="<?php echo $slide->slide_title; ?>" alt="<?php echo $slide->slide_title; ?>" /> <img src="<?php echo $slide_image_mobile->url; ?>" class="img-fluid d-block d-md-none" title="<?php echo $slide->slide_title; ?>" alt="<?php echo $slide->slide_title; ?>" /> </a> </div> <?php } } On my dev server, the small image is detected and placed in content, however in my production server this doesn't happen. I've double checked fields names and the fields contain images. I've even imported the database into the Dev Server. I don't have any clue why it works locally and not in server. Can anyone shed som light? Thank you!
  11. Bingo! In case someone needs it: // Activity form if($page->template == 'activity') { $forms->addHookBefore('FormBuilderProcessor::renderReady', function($e) { $form = $e->arguments(0); if($form->name == 'activity_form') { $page = wire('page'); // IS THIS RIGHT? $selected = array(); // IS THIS RIGHT? $selected['selected'] = 'selected'; // IS THIS RIGHT? // Get Atividade field $inputfield = $form->getChildByName('atividade'); // Get InputfieldPage $select_field = $inputfield->getInputField(); // Get the correspondent InputfieldSelect $select_field->addOption($page->id, $page->title, $selected); // Add current page as selected option } }); $activity_form = $forms->render('activity_form'); } Thanks for your help @elabx, it made all the difference!
  12. So close and yet so far! if($form->name == 'activity_form') { // Get Atividade field $inputfield = $form->getChildByName('atividade'); $page = wire('page'); $inputfield->addOption($page->id, $page->title, array('selected')); } Two problems: 1 - $page = wire('page'); is this the best way to have access to the page id and title inside the hook? Is there a performance issue? 2 - Error on addOption: Error: Exception: Method InputfieldPage::addOption does not exist or is not callable in this context (in E:\WebServer\clinicadasconchas.pt\wire\core\Wire.php line 519) #0 E:\WebServer\clinicadasconchas.pt\wire\core\Wire.php(386): ProcessWire\Wire->___callUnknown('addOption', Array) #1 E:\WebServer\clinicadasconchas.pt\wire\core\WireHooks.php(723): ProcessWire\Wire->_callMethod('___callUnknown', Array) #2 E:\WebServer\clinicadasconchas.pt\wire\core\Wire.php(442): ProcessWire\WireHooks->runHooks(Object(ProcessWire\InputfieldPage), 'callUnknown', Array) #3 E:\WebServer\clinicadasconchas.pt\wire\core\Wire.php(445): ProcessWire\Wire->__call('callUnknown', Array) #4 E:\WebServer\clinicadasconchas.pt\site\assets\cache\FileCompiler\site\templates\_init.php(31): ProcessWire\Wire->__call('addOption', Array) #5 E:\WebServer\clinicadasconchas.pt\wire\core\WireHooks.php(813): ProcessWire\TemplateFile->{closure}(Object(ProcessWire\HookEvent)) #6 E:\WebServer\clinicadasconchas.pt\wire\core\Wire.php(442): ProcessWire\WireHooks->ru It looks like it is a InputfieldPage field, and this doesn't have addOption method.
  13. Thinking about this alternative. This might work better. So now I have a working code inside _init.php: // Activity form if($page->template == 'activity') { $forms->addHookBefore('FormBuilderProcessor::renderReady', function($e) { $form = $e->arguments(0); if($form->name == 'activity_form') { // Get Atividade field $inputfield = $form->getChildByName('atividade'); // I NEED TO INSERT A SELECTED OPTION HERE // something something = $page->id; } }); $activity_form = $forms->render('activity_form'); } Getting close. Can someone help?
  14. Hi @elabx, Thanks for your reply. I really need some help here, working with Hooks. First, watching the function you showed me, I believe that the responsible bit for not having the self page in the selector is the last part. So it's not a bug, but a feature (not sure why). This are the lines I need to override.: if($children && $children->has($page)) { $children->remove($page); // don't allow page being edited to be selected } I was playing around with the hooks but I couldn't figure it out. Form builder doesn't have a InputFieldPage Hook, so how am I supposed to hook into it? The code below must be completely wrong, my apologies, but I'm completely lost here (I have this inside _init.php): if($page->template == 'activity') { // This hook will make sure that the list of pages include self page $this->addHookBefore('InputfieldPage::getSelectablePages', function($event) { $children = $pages->get('parent=1066'); return $children; }); $activity_form = $forms->render('activity_form'); } Can someone point me to the right direction? Thanks! Alternative When rendering the select field, add current page and make it selected. Is this possible?
  15. Hi, I'm having a problem with a page selection field. I have the following tree set up: Activities - Activity 1 - Activity 2 - Activity 3 - Activity 4 So I created a form where you can select one of the activities on which you would like to participate. For usability purposes, the form is inserted in each Activity page, so that the user doesn't have to click to get to a form. I have two problems (let's say the user is inside the "Activity 2" page); 1. Inside the form, where the user can select the activity, the current page is not listed, so the user can select "Activity 1", "Activity 3" and "Activity 4", but not the one in which he is. This one might be a bug. 2. It would be nice that the activity in which he is - Activity 2 - Would be selected by default. Is there any way that I can accomplish this without a custom markup form? Thank you.
  16. @adrian, thanks for your help. The examples given weren't really helping because the file name wasn't kept. For each time de file was replace it would add "-1", "-2" etc. to the file name. I managed to make it work and I am posting the code, in case someone needs something like this. foreach($files as $file) { if(substr($file, 0, 1) != '.' && $file != '.' && $file != '..') { // Get SKU $file_sku = substr($file, 0, 9); // Check for book $book = $pages->get('sku=' . $file_sku); if(!$book->id) { // Book doesn't exist } else { // Check if image already exists $replace = false; foreach($book->book_images as $image){ // Replace image if($file == $image) { $book->book_images->delete($image); $book->save(); $book->book_images->add($upload_directory . '/' . $file); $book->save(); // Place image in the right position: after previous or as first if(isset($previous_image)) { $old_item = $book->book_images->get($previous_image); $new_item = $book->book_images->last(); $book->book_images->insertAfter($new_item, $old_item); } else { $old_item = $book->book_images->first(); $new_item = $book->book_images->last(); $book->book_images->insertBefore($new_item, $old_item); } $replace = true; } $previous_image = $image; } // Add image to book if(!$replace) { $book->book_images->add($upload_directory . '/' . $file); } // Save book $book->save(); // Delete processed file unlink($upload_directory . '/' . $file); } } }
  17. @adrian thank you very much for your help, so far. However, it doesn't seems to be working: $book->book_images->replace($book->book_images->path . $image, $upload_directory . '/' . $file); Doesn't return any error but it doesn't replace the image! ?
  18. Hi, Thank you for your help. Here's what I've got so far and working: foreach($files as $file) { if(substr($file, 0, 1) != '.' && $file != '.' && $file != '..') { // Get SKU $file_sku = substr($file, 0, 9); // Check for book $book = $pages->get('sku=' . $file_sku); if(!$book->id) { // Book doesn't exist } else { // Check if image already exists foreach($book->book_images as $image){ // Remove existing image if($file == $image) { $book->book_images->remove($image); $book->save(); } } // Add new image $book->book_images->add($upload_directory . '/' . $file); } // Save book if($book->id) $book->save(); } } The only problem with this code, is that the new image doesn't keep the same order. It's always added at the end. Is there any way to make it load into the same position?
  19. Hi, I'm trying to upload images from a folder into a page. I need to replace the images instead of adding. The image field already has the replace existing images turned on, but it doesn't seem to be enough. My code: foreach($files as $file) { if(substr($file, 0, 1) != '.' && $file != '.' && $file != '..') { // Get SKU $file_sku = substr($file, 0, 9); // Check for book $book = $pages->get('sku=' . $file_sku); if(!$book->id) { // Book doesn't exist } else { // Upload image into book !!! THIS CODE ADDS FILE INSTEAD OF REPLACING. HOW CAN I REPLACE? $book->book_images->add($upload_directory . '/' . $file); // Delete file unlink($upload_directory . '/' . $file); } // Save book if($book->id) $book->save(); } } What am I missing?
  20. Hi, I tried to use the same technique and it's not working. I checked the image field to overwrite but the API keeps adding files, with "-1", "-2", "-3" appended to the filename. Here's my code: foreach($files as $file) { if(substr($file, 0, 1) != '.' && $file != '.' && $file != '..') { // Get SKU $file_sku = substr($file, 0, 9); // Check for book $book = $pages->get('sku=' . $file_sku); if(!$book->id) { // Book doesn't exist } else { // Upload image into book $book->book_images->add($upload_directory . '/' . $file); // Delete file unlink($upload_directory . '/' . $file); } // Save book if($book->id) $book->save(); } } I don't know what's missing.
  21. Hi, I'm trying to figure what's happening here. Objective The site administrator uploads, via FTP, a group of book images. Then, by running a tool in the admin area all the images will be assigned to each book through the SKU in the file name. This is a standalone tool with PW bootstrapped. Working code: // Get SKU $file_sku = substr($file, 0, 9); // Check for book $book = $pages->get('sku=' . $file_sku); if(!$book->id) { // Book doesn't exist } else { // Upload image into book $book->book_images->add($upload_directory . '/' . $file); // Delete file unlink($upload_directory . '/' . $file); } // Save book if($book->id) $book->save(); Problem This code adds to existing files. So when the administrator wants to replace files, instead of replacing it just keeps adding them to existing books. Alternative Using WireUpload. I've never used it before, but I think this might be right: // Get SKU $file_sku = substr($file, 0, 9); echo 'SKU: ' . $file_sku . '<br />'; // Check for book $book = $pages->get('sku=' . $file_sku); if(!$book->id) { // Book doesn't exist } else { // Upload image into book $u = new WireUpload('book_images'); $u->setMaxFiles(1); $u->setOverwrite(false); $u->setDestinationPath($book->files->path()); $u->setValidExtensions(array('jpg', 'jpeg', 'gif', 'png')); foreach($u->execute() as $filename) $book->files->add($filename); // Delete file unlink($upload_directory . '/' . $file); } // Save book if($book->id) $book->save(); Error! With this code I get the following error: Fatal error: Uncaught Error: Class 'WireUpload' not found in E:\WebServer\sadacosta.com\site\modules\Tools\process-book-images.php:35 Stack trace: #0 E:\WebServer\sadacosta.com\tools-process-book-images.php(4): include() #1 {main} thrown in E:\WebServer\sadacosta.com\site\modules\Tools\process-book-images.php on line 35 What's missing? Is there any other way to do this? Thanks,
  22. The page is not online (unpublished), it's a new template. Everything else is working fine. I have other repeater fields in place, with images that are working fine (the fade in logo on the homepage comes from a repeater field). Maybe if I create a new field it will solve the issue.
  23. Hi, I did some more experiments and updated the post (see Clue 1). It looks like a PW problem, in my opinion. I don't get a server response because the image doesn't even tries to be loaded. Thanks for your suggestion.
  24. I added $config->pagefileSecure = false; to the config.php and I still couldn't get it to work! Thanks for the suggestion.
×
×
  • Create New...