Jump to content

Liam88

Members
  • Posts

    64
  • Joined

  • Last visited

Everything posted by Liam88

  1. Thanks @flydev ??, it looks like it may by this line: "This enables you to have a separate page (or perhaps a sidebar on every page) that [for example] shows the user bookmarks of pages they liked" However, I'm not sure it would match the full desired behaviour with the below: "FieldtypeLikes is not connected with the user system, and may be used anonymously via any page on your site." I want the liked page to be connected to the user so it can be outputted in a "profile" area. Think Pinterest or even more relevant "follow" on here. So I'm looking to. Have a save button on a page. If the user is logged in then save the page if not then fire a modal with the LRP register execution. Probably could be done with a check whether a user is logged in. However, I was hoping there would be a simple way to just have a connection between user id and page id. Maybe something like clicking save would add the page id to a repeater but feels quite clumsy and probably slow. Overall, not sure on the best practice or best direction to achieve this. The joys of using a side project to learn more. Any thoughts from your side @ryan on whether likes module would work is appreciated. Thanks
  2. Thanks @AndZyk Trying this snip is also firing a 404. If I remove access management set in the template then I can get it to work. Taking your snip as an example I get this. It would just mean I would have to do access management within the PHP (e.g $u->isLoggedIn()) and not leave PW to it. However, that feels against the reasons for it being within PW. So the summarise, it seems this is an access issue and not a recognising role issue. Unless it's the access control not recognising the role. Who knows haha.
  3. Hey @AndZyk Thank you for your reply. I use the pro module.module. I'm not looking to use the login-register/profile? areas but just use it for user management. So that would be create account, change password etc. I then have a dedicated user area under /profile/ which does all the custom bits for users. Think Pinterest style where you have an area that shows posts and boards. So in that /profile/ I then use URL segments to grab the relevant posts and boards linked to their user id. So /profile/user-id/ So the snip I inserted above takes URL seg 1 and then would action based on the behaviour I dictate. The template settings are all set up to do this so I shouldn't need bits like is logged in etc. So access management all done via PW. The screenrecord is just to show that I'm logged in and have a login-register role but get a 404 when viewing the /profile/ page. hope that helps explain better on why and the intention.
  4. Hello, Just wondering if anyone has come across URL segments not working. I have the login register module and creating a dedicated user area for a better user experience. So I am using website.com/profile/user-id/ as the user profile page. This is set to only show for those with a login-register user role and access is all done through PW. Here is the basic snip to just do something if user id in url or not and with or without role. $userId = $input->urlSegment1; if(ctype_digit($userId)) { // display profile of user matching id in urlSegment1 $u = $users->get((int) $userId); if($u->id && $u->hasRole('login-register')) { echo "<h1>User $user->name info:</h1>"; // output any fields from user } else{ echo '<h1>Unknown or unavailable user</h1>'; } } else if($userId) { wire404(); // something other than user ID in urlSegment1 } else { // no urlSegment1 present // display links for user profiles? foreach($users->get('roles=login-register, sort=name') as $u) { echo "<li><a href='$u->id/'>$u->name</a></li>"; } } However, all the test profiles I have created that have 'login-register' roles just get 404. If I change it to only show for 'superuser' then I can get mine to show. Here is an example. pw_segment_issue.mp4 You will see when logged in it shows within the /login-register/ area. Eventually, it would redirect to /profile/user-id/ but kept it like this to show that user is logged in but 404 on profile. The screenshots below confirm set up is correct. Any direction on this is appreciated. I'm stuck on why this would be happening. It's like it's not recognising the role. I have added a handful of users to test between behaviours with none working.
  5. Thanks @DaveP I'm using loginregisterpro so I have a lot covered with that. I'll take a look at the links you popped in. appreciate the direction.
  6. Hello all, Looking for input on the best way to implement a Pinterest like save button. Aim: I want logged in users to be able to save posts to their profile for future accessibility. I would like them to be able to give it a subject, in other words the ability to bucket them into groups. Does anyone have a suggestion or an example of something similar? I would say my main hurdle is implementing a front end button that would then add a page id into the back end. Guessing that db element would have a page ID and user ID so I can then filter page IDs relevant to User ID. TIA.
  7. Thank you Andreas. Definitely noticing more issues since moving from live to local. Little elements like I have <? instead of <?php which worked on live but not in local. Would you say that anything like the img example above should be within ifs to reduce errors?
  8. Thank you. I have now changed this out. Interestingly I didn't have this flag as an error when live. I have also sorted the depreciated error by using Xampp with php 7. Although that error is sorted (and there may be a few more I'll pick up) I'm mainly getting these ones below everywhere. All of these were working correctly on live and even on the old local. This is line 28
  9. Hello all, Ended my hosting and want to move my site back to local. I have downloaded my DB and relevant folders. I'm just using Xampp for this which is up and running correctly. Tested with a fresh install of PW. Done the following process: installed fresh PW with created DB Replaced folder items with existing website dropped installation DB tables Imported website DB Adjusted config DB credentials to match. Any direction on what these are? Unfortunately, little knowledge on these elements so direction is much appreciated. TIA
  10. Hello, I have a separate sort dropdown and filter section. This is very similar to the processwire demo - https://demo.processwire.com/search/?sort=parent.name I also have the same "issue" if you would call it that where i can sort or I can filter, but I can not do both. This is because the url changes. So a sort URL may look like: website.com/subpage/?sort=random and a filter like: website.com/subpage/?placement=x&channel=y_z I'm looking to be able to sort and filter. So if I change the sort, it won't remove the current filter and vice versa. I have the sort dropdown running off one bit of JS and the filter on another with examples of both below: This is sort JS $(document).ready(function() { $(".sort-select").on("change", function() { document.location.href = location.pathname+"?sort="+$(this).val(); //console.log(location.pathname+"?sort="+$(this).val()) //console.log(location.search) }); }); This is filter JS document.querySelector("form").onsubmit=ev=>{ ev.preventDefault(); let o={}; let noPage = window.location.pathname.split("/").slice(0,-2).join("/") + "/"; ev.target.querySelectorAll("[name]:checked").forEach(el=>{ (o[el.name]=o[el.name]||[]).push(el.value)}) if(noPage.length > 1){ document.location.href = noPage+"?"+Object.entries(o).map(([v,f])=>v+"="+f.join("_")).join("&"); }else{ document.location.href = location.pathname+"?"+Object.entries(o).map(([v,f])=>v+"="+f.join("_")).join("&"); } } This is my input build within the func.php doc: $selector = ''; // Get the inputs, sanitize and whitelist. Then create an array, then replace _ for | in array for selector filter. Output selector if($input->get->sort){ $sorted = $input->get->text('sort'); $input->whitelist('sort', $sorted); //$selector = $selector .= ",sort=$sorted"; } if($input->get->channel){ $channel = $input->get->text('channel'); $input->whitelist('channel', $channel); $chanArray = explode("_", $channel); $chan = $channel = str_replace('_', '|', $channel); $selector = $selector .= ",ab_channels=$chan"; } if($input->get->content){ $content = $input->get->text('content'); $input->whitelist('content', $content); $contArray = explode("_", $content); $cont = $content = str_replace('_', '|', $content); $selector = $selector .= ",ab_content=$cont"; } if($input->get->brand){ $brands = $input->get->text('brand'); $input->whitelist('brand', $brands); $brandArray = explode("_", $brands); $brand = $brands = str_replace('_', '|', $brands); $selector = $selector .= ",ab_brand=$brand"; } if($input->get->style){ $styles = $input->get->text('style'); $input->whitelist('style', $styles); $styleArray = explode("_", $styles); $style = $styles = str_replace('_', '|', $styles); $selector = $selector .= ",ab_creative_style=$style"; } if($input->get->ugc){ $ugcs = $input->get->text('ugc'); $input->whitelist('ugc', $ugcs); $ugcArray = explode("_", $ugcs); $ugc = $ugcs = str_replace('_', '|', $ugcs); $selector = $selector .= ",ab_influencer=$ugc"; } if($input->get->place){ $placement = $input->get->text('place'); $input->whitelist('place', $placement); $placeArray = explode("_", $placement); $place = $placement = str_replace('_', '|', $placement); $selector = $selector .= ",ab_placement=$place"; } if($page->template == 'adbank_brand_page'){ $brand = $page->title; $selector = $selector .= ",adbank_brands=$brand"; } $selector = "template='adbank_pages',limit=12,sort={$sorted} " . trim($selector, ", "); Any direction on how to combine these would be really appreciate. I know AJAX may be the best route overall but I don't know how to action that and for time sake trying to get these to both work with page refresh feels more accessible... TIA
  11. Amazing, thank you. I noticed that when I first did it and changed it to check if count was > etc. Now changed to the above.
  12. Hey, thank you for the reply and direction. I'm going to take a moment to digest the ajax part. In the meantime I did update the input part to the below just after doing this post. It would be good to get your view whether this is a better way. //Default selector to get ALL products $baseSelector = "template='adbank_pages',sort=-created,include=all,limit=12"; $selector = "template='adbank_pages',sort=-created,include=all,limit=12"; // Get the inputs, sanitize and whitelist. Then create an array, then replace _ for | in array for selector filter. Output selector if($input->get->channel){ $channel = $input->get->text('channel'); $input->whitelist('channel', $channel); $chanArray = explode("_", $channel); $chan = $channel = str_replace('_', '|', $channel); $selector = $selector .= ",ab_channels=$chan"; } if($input->get->content){ $content = $input->get->text('content'); $input->whitelist('content', $content); $contArray = explode("_", $content); $cont = $content = str_replace('_', '|', $content); $selector = $selector .= ",ab_content=$cont"; } if($input->get->brand){ $brands = $input->get->text('brand'); $input->whitelist('brand', $brands); $brandArray = explode("_", $brands); $brand = $brands = str_replace('_', '|', $brands); $selector = $selector .= ",ab_brand=$brand"; }
  13. SOLVED: So I added in the whitelisting just after the $input get. if($input->get->channel){ $channel = $input->get->text('channel'); $input->whitelist('channel', $channel);// This is what I was missing. $chanArray = explode("_", $channel); $chan = $channel = str_replace('_', '|', $channel); $selector = $selector .= ",ab_channels=$chan"; } I had the whitelist but needed to add it after the $input->get. I also added $input->get->text('') to help sanitize according to the docs.
  14. Hi, After years of just playing around with Processwire I have asked 3 q's in the same week. It's all about working with forms, parameters etc and so I'm hoping this ordeal is nearly over! I currently have a checkbox filter: <form id="abFilter" method="get" role="form" action="'.$page->url().'"> <div class="list-group"> <h3>Content Type</h3>'; $cont = $fields->get('ab_content'); $contents = $cont->type->getOptions($cont); foreach($contents as $ab_cont){ echo' <div class="list-group-item checkbox"> <input type="checkbox" class="" id="'.$ab_cont->title.'" name="content" value="'.$ab_cont->title.'"'; if (in_array($ab_cont->title, $contArray)){ echo "checked"; } echo'> <label for="'.$ab_cont->title.'">'.$ab_cont->title.'</label> </div>'; } echo' </div>'; //end of filter 1 //start of filter 2 echo' <div class="list-group"> <h3>Channels</h3>'; $chan = $fields->get('ab_channels'); $channel = $chan->type->getOptions($chan); foreach($channel as $ab_chan){ echo' <div class="list-group-item checkbox"> <input type="checkbox" class="" id="'.$ab_chan->title.'" name="channel" value="'.$ab_chan->title.'"'; if (in_array($ab_chan->title, $chanArray)){ echo "checked"; } echo'> <label for="'.$ab_chan->title.'">'.$ab_chan->title.'</label> </div>'; } echo' </div>'; ?> <button id="select">Get Checked Checkboxes</button> </form><!-- end of form --> I also have a piece of script which selects all the checkboxes and then outputs them into readable parameters for the URL which then passes into the $inputs. The reason for the script is to not have duplicate filters like ?ab=1&ab=2 and the script changes it to ab=1_2 which on the input gets exploded into an array. document.querySelector("form").onsubmit=ev=>{ ev.preventDefault(); let o={}; ev.target.querySelectorAll("[name]:checked").forEach(el=>{ (o[el.name]=o[el.name]||[]).push(el.value)}) console.log(location.pathname+"?"+Object.entries(o).map(([v,f])=>v+"="+f.join("_")).join("&")); document.location.href = location.pathname+"?"+Object.entries(o).map(([v,f])=>v+"="+f.join("_")).join("&"); } Here is $inputs and so on on the page: //Default selector to get ALL products $baseSelector = "template='adbank_pages',sort=published,include=all,status!=hidden,limit=2"; $selector = "template='adbank_pages',sort=published,include=all,status!=hidden,limit=2"; $input->whitelist('channel',explode("_", $channel)); // Use this to append to the $items filter if($channel){ $chanArray = explode("_", $channel); $chan = $channel = str_replace('_', '|', $channel); $selector = $selector .= ",ab_channels=$chan"; } $test = $pages->find($selector); // This is just testing if the $selector choise returns and if not use page filter without filters. if(count($test) > 0){ $items = $pages->find($selector); // $items with the parameter filter // Example - "template='adbank_pages',sort=published,include=all,status!=hidden,limit=2,ab_channels=facebook-ads" // Example (multi choice) - "template='adbank_pages',sort=published,include=all,status!=hidden,limit=2,ab_channels=facebook-ads|instagram-ads" // Example (with other filters) - "template='adbank_pages',sort=published,include=all,status!=hidden,limit=2,ab_channels=facebook-ads,ab_content=video|static" }else{ $items = $pages->find($baseSelector); // Example - "template='adbank_pages',sort=published,include=all,status!=hidden,limit=2" } $total = $items->getTotal(); I have stripped out a few of the other filters from the above to try keep it a little more concise (haha). Now I appreciate the post may be long but here we are at the end! The URL I get on page 1 of the filter results would look like: example.com/blog/?channel=facebook-ads_instagram-ads If I click page 2 the url changes to - example.com/blog/page2/?channel= If I then click back to page 1 it changes to - example.com/blog/?channel= So I'm hoping you can see my problem and hoping someone can assist. I need to work out how to keep the parameters in the url but also if I remove that filter for that parameter to remove. This whole process works without pagination but with pagination it has a different behaviour. Thank you in advance
  15. SORTED: So I changed item's to be the first query which featured then works off and now the pagination renders and works.
  16. Just to add that no pagination renders which is odd. I have read many posts that have the render but have URL issues.
  17. Hi, Thank you for the reply I get what you are thinking but I have the $all rule to then push into the two queries and neither $featured or $items reference each other. The pagination is only referencing the $items which are the main posts below. I have put an image below to show the layout which may help. Also, just to say I have removed the $featured query and the block above the breadcrumb and pagination still doesn't work. I have also removed the limit on $featured and use a count instead. Above the breadcrumb is $featured and below is $items
  18. Hoping someone can help. I have pagination all set up with the usual steps: Make sure "markuppagernav" is installed Allow page numbers on the template Create a page query that selects a limited number of items. renderpager the items query. <?php namespace ProcessWire; $all = $page->children("template='blog-post', sort=-published"); $featured = $all->find("limit=4, check_featured!={$page->check_featured}"); $items = $all->find("limit=6"); ?> I have more than 6 posts to ensure it would show. <?php echo $items->renderPager([ 'listMarkup' => '<nav aria-label="navigation"><ul class="pagination">{out}</ul></nav>', 'itemMarkup' => '<li class="page-item {class}">{out}</li>', 'linkMarkup' => '<a class="page-link" href="{url}">{out}</a>', 'currentLinkMarkup' => '<a class="page-link" href="{url}">{out}</a>', 'currentItemClass' => "active" ]); ?> Then the above at the bottom of the page. As mentioned the page numbers are enabled: If I manually add in example.com/blog/page2/ then I just get the same output like example.com/blog/ Where am I going wrong? TIA
  19. Hi, I'm really struggling with this as it's something not in my wheelhouse. I'm creating a blog style page (a grid of cards) which has attributes. I have a snip of javascript which grabs values from checkboxes which are put into a value like the below: ?content=static_video&channel=facebook-ads_instagram-ads document.querySelector("form").onsubmit=ev=>{ ev.preventDefault(); let o={}; ev.target.querySelectorAll("[name]:checked").forEach(el=>{ (o[el.name]=o[el.name]||[]).push(el.value)}) console.log(location.pathname+"?"+ Object.entries(o).map(([v,f])=> v+"="+f.join("_")).join("&") ); document.location.href = location.pathname+"?"+ Object.entries(o).map(([v,f])=> v+"="+f.join("_")).join("&"); } As I'm currently refeshing the page on button click with those values the end result includes the location but can easily remove this. I then use this value in "input->get" to get the values which I then append to a find() rule. See code below: $selector = "template='adbank_pages',sort=published,include=all,status!=hidden"; // Get the channel and content inputs $channel = $input->get->channel; $content = $input->get->content; if($channel){ // Grab the channel string, explode into an array for checkbox checking and then replace _ with | to create or rules in the selector. $chanArray = explode("_", $channel); $chan = $channel = str_replace('_', '|', $channel); $selector = $selector .= ",ab_channels=$chan"; } if($content){ // Grab the content string, explode into an array for checkbox checking and then replace _ with | to create or rules in the selector. $contArray = explode("_", $content); $cont = $content = str_replace('_', '|', $content); $selector = $selector .= ",ab_content=$cont"; } if($input->get){ // If a valid input result $all = $pages->find($selector); } }else{ // If no input show them all $all = $page->children("template='adbank_pages',sort=-published,include=all,status!=hidden"); } $items = $all->find("limit=12"); // Limit the output and use pagination As mentioned above I currently refresh the page to adjust the $selector filter within the $all with a fallback $all if there are no results. I know I need to use AJAX to filter the content without refresh but I am really struggling with the set up. I have read multiple posts including the original by Ryan but still confused. If anyone can direct/help on this it would be appreciated. Thank you
  20. Just an update to this post. it seems I had a missing </div> which caused the error.
  21. Hey, yes all the same setup. it's a wierd one as it never used to flag up with this before.
  22. Hey all, Hoping someone may be able to advise why. I noticed recently that my doctype is not rendering when checking in inspect element. This is only happening on certain sub pages like blog whilst shows on home. I have it within my main doc with all other needed bits, but this just isn't showing. Thank you in advance.
  23. Hi all, Quick question as I haven't found anything from my Googling. I have a blog on the site which utilises pagination. On the standard blog page I have a custom header which has featured posts. Below that I then have recent posts like mosts blogs. Now if i click to page two or three I want the header to disappear and just show a continuation of the standard posts. I'm not sure how to go about this so any direction would be helpful. Thanks
  24. Just to say huge thanks and your version worked. Really enjoying learning this CMS!
×
×
  • Create New...