Liam88
Members-
Posts
64 -
Joined
-
Last visited
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
Liam88's Achievements
Full Member (4/6)
13
Reputation
-
Adding multiple pages to page reference field within a foreach php
Liam88 replied to Liam88's topic in Getting Started
ok, interesting because when I just removed the page-edit access it wouldn't create the tags and save them. It shows as guest within the logs which is likely the issue. I'm guessing I need to ensure it has it down as the user that is making the action. Here's an example of the log, going to try make it so it's the actual user and not the guest Date/Time User URL Text 18 seconds ago 2024-09-29 21:22:23 guest /api/ad-review/ AI processing completed successfully. 18 seconds ago 2024-09-29 21:22:23 guest /api/ad-review/ content_tags field is not editable by the current user. -
Adding multiple pages to page reference field within a foreach php
Liam88 replied to Liam88's topic in Getting Started
Thank you all for the help. In the end it was two things: field was not editable the second was a silly mistake of creating the tag pages as template = content-tags, instead of content-tag Can confirm up and working correctly now. The silliest things seem to be the biggest time sucker 🤣 -
Adding multiple pages to page reference field within a foreach php
Liam88 replied to Liam88's topic in Getting Started
Stupidly I think I may have found the issue. So I did a check if field is editable and it returned no. Going to adjust access and try again. -
Adding multiple pages to page reference field within a foreach php
Liam88 replied to Liam88's topic in Getting Started
Yeah page reference allows creation and the tagPages are being created and saved. I was thinking should I save after each tag is added or add all then save. Will give your suggestion a go. Appreciate it. -
Adding multiple pages to page reference field within a foreach php
Liam88 replied to Liam88's topic in Getting Started
Good spot, oversight from me. I don't use them on my other section either. Yeah all the tagPages are created and saved before, but will triple check. -
Hey Having a struggle with this one. My project sends content to openAI, it sends back tags. Where the tags aren't an existing page, it creates them. I then want to add those tag pages to the content. assetPage is the content content_tags is the page reference within that page content-tag is the template for the tag pages added. I'm getting it to say it's adding the pages to content_tags, but in any form I'm trying it doesn't add them. I have popped my example php below and here are an example log. You will see it gets stuck at attempting to save. Any advice on where I am going wrong in adding multiple pages to a page reference field at once would be amazing. Is it the way I'm trying to save? Date/Time User URL Text 10 seconds ago 2024-09-27 17:35:13 guest /api/ad-review/ Inside try block - attempting to save. 10 seconds ago 2024-09-27 17:35:13 guest /api/ad-review/ Attempting to save the asset page with updated content_tags. if (!empty($tags)) { $log->save('ad-review', 'Processing tags to create or find corresponding pages.'); $tagPages = processTags($tags, $log); // Log the tag pages returned from processTags $log->save('ad-review', 'Tag pages found or created: ' . implode(', ', array_map(function ($page) { return $page->title; }, $tagPages))); // Log the current state of content_tags $currentTags = $assetPage->{'content_tags'}->explode('id'); $log->save('ad-review', 'Current content_tags IDs before update: ' . implode(', ', $currentTags)); // Ensure output formatting is disabled $assetPage->of(false); // Check if the content_tags field exists and is accessible if (!$assetPage->getField('content_tags')) { $log->save('ad-review', 'Field content_tags does not exist or is not accessible on the asset page.'); return; // Exit if the field is not found } else { $log->save('ad-review', 'Field content_tags exists on the asset page and is ready for update.'); } // Add each tag page to the content_tags field using add() foreach ($tagPages as $tagPage) { if ($tagPage && $tagPage->id) { try { // Add the tag page directly using the add() method $log->save('ad-review', 'Adding tag page to content_tags: ' . $tagPage->title . ' - ' . $tagPage->id); $assetPage->{'content_tags'}->add($tagPage->id); } catch (Exception $e) { $log->save('ad-review', 'Error adding tag page to content_tags: ' . $tagPage->title . '. Error: ' . $e->getMessage()); } } else { $log->save('ad-review', 'Failed to add tag page: ' . ($tagPage ? $tagPage->title : 'Unknown')); } } // Additional logging before save attempt $log->save('ad-review', 'Attempting to save the asset page with updated content_tags.'); // Explicitly try saving the asset page try { // Another log entry just before the save method is called $log->save('ad-review', 'Inside try block - attempting to save.'); // Execute the save operation if ($assetPage->save()) { $log->save('ad-review', 'Asset page saved successfully with updated content_tags.'); // Re-fetch and log the content_tags after saving to confirm $savedTags = $assetPage->{'content_tags'}->explode('id'); $log->save('ad-review', 'Content_tags IDs after save: ' . implode(', ', $savedTags)); } else { $log->save('ad-review', 'Save method returned false, indicating save was not successful.'); } } catch (Exception $e) { $log->save('ad-review', 'Failed to save asset page with updated content_tags. Error: ' . $e->getMessage()); } } else { $log->save('ad-review', 'No tags to process.'); }
-
Amazing, thank you @Robin S I have TD installed and debug true but found I wasn't getting any logs.
-
Looking for some advice. I need to create a page, insert some basic info, create a repeater and save either a video or image. This is where I'm at so far. I'm finding that the repeater doesn't save. So when I access the main page after the process, there is no repeater inside. The logging gets stuck on video uploading to repeater This is an example url - https://video-lhr6-2.xx.fbcdn.net/v/t42.1790-2/359544611_1299622917599542_1081641833156909957_n.mp4?_nc_cat=104&ccb=1-7&_nc_sid=c53f8f&_nc_ohc=v3DnXymDRrMQ7kNvgGY2g0m&_nc_ht=video-lhr6-2.xx&_nc_gid=Avf0ALrpn8YGUKRdqZmpwGi&oh=00_AYCqXW4qteSLwgQKol8SbVAgvR-O3-9R1QVqmDjjZwiUjw&oe=66ECD5B4 Any advise would be welcomed. // Continue handling the data if everything is present $mediaUrl = $data['media_url']; $mediaType = $data['media_type']; $description = isset($data['description']) ? $data['description'] : ''; $title = 'Test Ad Title'; try { // 1. Create the main page $page = new Page(); $page->template = 'asset'; // Use the correct template $page->parent_id = 1029; // Adjust this ID for the correct parent page $page->title = $title; $page->content_type = $mediaType; // Assuming 'content_type' is a valid field $page->save(); // Log the creation of the page $log->save('save-ad', 'Created new page with title: ' . $title); // 2. Create a repeater item for the "content" repeater field $log->save('save-ad', 'Creating a new repeater item.'); $contentRepeater = $page->content->getNew(); // Create a new repeater item if (!$contentRepeater) { $log->save('save-ad', 'Error: Failed to create new repeater item.'); echo json_encode(['status' => 'error', 'message' => 'Failed to create repeater item.']); exit; } // 3. Handle media file and add it to the correct field in the repeater $filename = basename($mediaUrl); // Extract the filename from the URL // Prepare the file to be added if ($mediaType == 'video') { $log->save('save-ad', 'Adding video file to repeater.'); // Add the file directly to the file field 'video_1' $contentRepeater->video_1->add($mediaUrl); // Assuming 'video_1' is the field $log->save('save-ad', 'Video file added successfully.'); } elseif ($mediaType == 'image') { $log->save('save-ad', 'Adding image file to repeater.'); // Add the image directly to the image field 'image_1' $contentRepeater->image_1->add($mediaUrl); // Assuming 'image_1' is the field $log->save('save-ad', 'Image file added successfully.'); } else { $log->save('save-ad', 'Error: Unsupported media type: ' . $mediaType); echo json_encode(['status' => 'error', 'message' => 'Unsupported media type: ' . $mediaType]); exit; } // 4. Save the repeater item $log->save('save-ad', 'Saving repeater item.'); $contentRepeater->save(); // 5. Add the repeater item to the main page $page->content->add($contentRepeater); // Add the repeater item to the page // 6. Save the main page with the repeater $page->save(); $log->save('save-ad', 'Repeater item added to page and page saved successfully.'); // Log success $log->save('save-ad', 'Media saved successfully to page.'); echo json_encode(['status' => 'success', 'message' => 'Ad saved successfully!']);
-
Showing downloaded html file within an iframe and getting 403 response
Liam88 replied to Liam88's topic in Getting Started
I'd prefer to not use iframe but when searching it was flagged as the best option. Any suggestions instead of iframe. I'm not a dev so just learn as I go, so any direction to go would be appreciated. -
Showing downloaded html file within an iframe and getting 403 response
Liam88 replied to Liam88's topic in Getting Started
Yeah the purpose is to have a page but without the function. However, it will still adjust to device etc. Like you said, I may need to rethink it as I can't find distinct yes or no's on this usage. -
Showing downloaded html file within an iframe and getting 403 response
Liam88 replied to Liam88's topic in Getting Started
I was able to get it to work within a basic index.html file and referencing the file in an iframe. I'm guessing it's due to server settings then. -
I'm hoping someone may be able to guide on this. One of my side projects stores ads for ecommerce brands for inspiration. I want to now add in their landing pages. I have used SingleFile to get a download of a page and then uploaded it to the page as a file. I am then looking to output as an iframe with the expectation this won't interfere with any css/html on my page. This leads to a basic output of this <iframe src='<?=$page->landing_page_html?>' width='100%' height='600px'></iframe> However, I'm getting a 403 response on the page. Does anyone have any guidance if my method is on the right path or should I leave this for another? I'm guessing it's wrong as no other site like awwwards or say Shopify templates do this and lean on a screenshot that links to the page. I have attached an example file for context. Big thank you in advance. Collagenic Burn Elite – Obvi (11_04_2024 17_38_24).html
-
Hey, I have the usual CKeditor set up with the insert image(s) button. I have done some googling but struggling to find a way to add video support in that bar. Does anyone have any advice they could offer. Thanks
-
Suggestions on implementing a Pinterest like save button
Liam88 replied to Liam88's topic in Getting Started
Yeah I'll have to search if there are any other threads for markup regions strat. Getting the same output with the suggestion above so did a bit of searching and found this - https://processwire.com/blog/posts/processwire-2.6.8-brings-new-version-of-reno-admin-theme-and-more/#new-this-gt-halt-method-for-use-in-template-files Adding $this->halt to the end of each case prevents the continued render when using it within _init.php (the prepended file). This does not work if just adding to _main.php. This is the action area now - <?php if($config->ajax && $input->post->bookmark){ bd($input->post->bookmark); // debug with tracy, uncomment if you have it $bookmarkid = $sanitizer->int($input->post->bookmark); $action = $sanitizer->name($input->post->action); $bookmarks = $user->getUnformatted('bookmarks'); switch($action) { case 'save': // save logic if(!$bookmarks->has($bookmarkid /* this was bookmark, now bookmarkid */)) { // add bookmark $bookmarks->add($bookmarkid /* same change here */); $user->setAndSave('bookmarks', $bookmarks); $message = 'Borat saved bookmark "'. $bookmark->id .'" ?'; $this->halt(); } else { $message = 'Nothing done'; } $success = true; break; case 'remove': // remove logic if($bookmarks->has($bookmarkid)) { $bookmarks->remove($bookmarkid); $user->setAndSave('bookmarks', $bookmarks); $message = 'Borat removed bookmark "'. $bookmark->id .'" ❌'; $this->halt(); } else { $message = 'Nothing done'; } $success = true; break; default: $message = 'error'; $success = false; } $json = array( 'id' => $bookmarkid, 'action' => $action, 'message' => $message, 'success' => $success ); header('Content-Type: text/json; charset=utf-8'); echo json_encode($json); return; } ?> Now I get this within preview: and FINALLY it now saves into the user area. A huge thank you @flydev ??. Learnt so much through this thread and hoping it helps others! I'll even keep in borat in recognition of your input. -
Suggestions on implementing a Pinterest like save button
Liam88 replied to Liam88's topic in Getting Started
So another update Script looks like this - jQuery(document).ready(function($) { // when clicked, send ajax request to server $('button.bookmark').on('click', function(e) { var btn = $(this).hasClass('clicked') ? false : $(this).addClass('clicked'); if (!btn) { console.warn(`⚠️ Bookmark already saved to profile`); return false; } $.post('<?=$pages->get('/')->url?>', { action: $(this).val(), bookmark: btn.data('id') }) .done(function(data) { console.log(data, "? response from ajax req"); console.info(`✅ Bookmark id => ${data.id} ${data.action} `); }); }); }); I have put this in _main.php (all template is appended to this via config.) at the top so before anything. I just included it within the namespace opening within the template. I left out the if user is logged in as this feature will only be available for logged in users. <?php namespace ProcessWire; if($config->ajax && $input->post->bookmark){ bd($input->post->bookmark); // debug with tracy, uncomment if you have it $bookmarkid = $sanitizer->int($input->post->bookmark); $action = $sanitizer->name($input->post->action); $bookmarks = $user->getUnformatted('bookmarks'); switch($action) { case 'save': // save logic if(!$bookmarks->has($bookmark)) { // add bookmark $bookmarks->add($bookmark); $user->setAndSave('bookmarks', $bookmark); $message = 'Borat saved bookmark "'. $bookmark->id .'" ?'; } else { $message = 'Nothing done'; } $success = true; break; case 'remove': // remove logic if($bookmarks->has($bookmark)) { $bookmarks->remove($bookmark); $user->setAndSave('bookmarks', $bookmarks); $message = 'Borat removed bookmark "'. $bookmark->id .'" ❌'; } else { $message = 'Nothing done'; } $success = true; break; default: $message = 'error'; $success = false; } // build the response data array that will be returned in `data` from `.done(function(data) {` $json = array( 'id' => $bookmarkid, 'action' => $action, 'message' => $message, 'success' => $success ); // convert data and send as JSON header('Content-Type: text/json; charset=utf-8'); // forgot this line echo json_encode($json); return; } ?> So now I get this within preview (video below). Still full html render output (Any thoughts why would this be?) but now the JSON is appended. I have also tried placing the if AJAX within the _init.php file. This just prepends it (expected) to before the HTML output. So I suppose my issue is I'm rendering the full HTML output as the JSON just shows as part of it. Untitled (6).mp4