Jump to content

EyeDentify

Members
  • Posts

    146
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by EyeDentify

  1. Well it seems to work so far as i can tell. i Declear this solved. Will reopen if things changes.
  2. Quick update. I checked all the templates cache setting and it is not enabled so it can´t be the cache ? Maybe session related ?
  3. Thank you for all your tips. For some reason it now seems to be working. I am going to keep an eye on it. Could it be cache related and the cache was cleared after a while and now it works ?
  4. Hello all the nice PW people. I am trying to work out why the following code of my visit counter: <?PHP /* simple code for recording current page visit count to its visit_counter field of "integer" type. But only if the visitor is not currently logged in. */ if($user->isLoggedin()) { /* if the user is logged in do not count visits */ } else { /* if the user is NOT logged in and not counted */ /* turn of output formating so PW do not give an error when we change the value */ $page->of(false); /* increment the current integer plus one */ $page->visit_counter = $page->visit_counter + 1; /* save the visitor_counter field */ $page->save('visit_counter'); /* turn on output formating so PW work as it should */ $page->of(true); } ?> Do not work in my 3.0.8 installation of ProcessWire. It works in another website where i run 2.7.2 very well. The field name is visit_counter and the type is Integer. And the field is added to all the relevant templates. Also tested editing the field in a page via admin and that updates and works. But not via the API it seems. I include it at the top of my template files just under the BODY tag. Have i missed anything ? I am greatfull for all suggestions have gone a bit stir crazy trying to figure this out.
  5. You can create so to speak an empty template without an uploaded template file by going to the Admin > setup > templates > add And not choose a template file. Then a empty template is created unless you choose to have fields included from another template. You can use this template When creating pages just like templates with files connected to them. Hope it helps.
  6. Well thats my way of coding it's a mather of preference i guess.
  7. Ofcourse Your right.... How did i miss that ... guess sometimes you go blind.... Thank you pwired.
  8. Hello Everyone. I have previous posted a tutorial in the Tutorial section about a counter system for counting visits to a page in PW. The code works an all is fine and dandy. Now i am trying something fancy pants... and making the code count a visitor once per session. This seems however not be the case and the visit is counted again on every page load. I must have done something wrong somewhere. I maybe have gone a little blind looking at this code. Am i wrong in testing this code by: Login to admin Then visit the page Check if count goes up ? no it does not so that works. Log out from Admin then visit page again and reload a few times Once again log into admin, and yes... all the reloads are counted... damit. Is my session reset somehow from me logging in and out of admin ? Any pointers or tips would be helpfull. <?PHP /* simple code for recording current page visit count to its visit_counter field of "integer" type. But only if the visitor is not currently logged in. */ /* set a counter flag to use with the counter */ $session->set('visit_counter_flag', 0); if($user->isLoggedin()) { /* if the user is logged in */ } else { /* check if the flag is set to 1, if so then do not count the visit */ if($session->get('visit_counter_flag') === 0) { /* if the user is NOT logged in and not counted */ /* turn of output formating so PW do not give an error when we change the value */ $page->of(false); /* increment the current integer plus one */ $page->visit_counter++; /* save the visitor_counter field */ $page->save('visit_counter'); /* turn on output formating so PW work as it should */ $page->of(true); /* set a visit counter flag to 1 so next load do not count */ $session->set('visit_counter_flag', 1); } } ?> Thank you in advance.
  9. Thanks for reminding me. One could read about the various licenses here: http://flickity.metafizzy.co/#license
  10. Hello again. Thought i share my way of creating sliders in my ProcessWire websites, by using the images field type and some HTML, JavaScript, CSS and a pinch of love. Step One: Go to http://flickity.metafizzy.co/ and download Flickity slider. They also have a CDN option for thoose who prefere that. Also have the page handy cause it has alot of usefull info for configuring the slider and such. Note: In my example i use jQuery to initialize Flickity but you can use it without, see the website for more info. So you need to load jQuery before flickity in the header section for my example to work. Step Two: Here is an example of how you could write some code and HTML for your template file where the slider should render. This code assumes your images field is named images. <div class="slider-container"> <?PHP /* check if there is any images to display */ if(count($page->images) > 0) { /* render out the images and resize to 700 pixel width */ foreach($page->images AS $key => $image) { echo('<img src="' . $image->width(700)->url . '" class="slider-container-item" alt="' . $image->description . '">'); } } else { echo('<p>Houston we have a problem...there are no images to see here...</p>'); } ?> </div> Also lets put together some simple CSS for our container and items. Alter it to your own needs and preference. For the Flickitys sliders default CSS and configuring see the website. .slider-container { position: relative; display: block; overflow: hidden; width: 100%; max-width: 700px; padding: 0; margin-bottom: 15px; clear: both; } .slider-container-item { position: relative; display: block; width: 100%; height: auto; max-width: 700px; } Step Three: Put the default CSS and also Flickitys JS files and load jQuery before Flickity in the header of your site so that flickity works as intended. Or use the CDN option mentioned on the flickity website. <link rel="stylesheet" href="/path/to/flickity.css" media="screen"> <script src="/path/to/jquery.js"></script> <script src="/path/to/flickity.pkgd.min.js"></script> Don´t forget to put the Flickity JavaScript initalization code at the bottom of the template file. For all the Options and configuration see the website: http://flickity.metafizzy.co/ In the example code below i use just a few of the many options. <script type="text/javascript"> /* initiate Flickity Slider JS */ $(document).ready(function(e){ $('.slider-container').flickity({ // options cellSelector: '.slider-container-item', cellAlign: 'center', imagesLoaded: true, percentPosition: true, contain: true }); }); </script> Note: This is my prefered way of doing it. But there are alternative ways to initialize Flickity if you read the info on the website. This should be enough to get you started. And with a little imagination i think you could see the potential. Good luck with all your Slider making dreams
  11. Hello Krlos. Welcome to PW community. I hope you will persist and learn PHP because its worth it and a wonderfull language once you get the hang of it. I would suggest you have a look at the: http://www.php.net and also another good source with alot of valuable info is: http://www.phptherightway.com/ PHP the Right Way might be tough to for beginners but they teach good concept and worth a read. Good luck and don´t be afraid to ask questions.
  12. Just adding my two cents here. Or "kronor" in my case cause i am from sweden. Anyways... I have allways made my own Slider implementation using the excellent Flickity slider from http://flickity.metafizzy.co/ It´s really great and easy to work with. Many config options and great support. I would just render out each image from the image field type and then use the built in crop or resize methods for thumbnails.
  13. Aha. So your saying that if the Session var is set then there is no counting ? And if there is no such Session var it is set and the count goes up one ? Just so i understand.
  14. Thanks for the tip @pwired. Had not thought about that before but it makes sens.
  15. Hello Everyone. This is not Strictly just about Processwire, but its something i use with a Processwire website that i created. It´s just a simple little Anti-spam protection system i use to make it more difficult for simple bots to mess around with a contact form on the said website. it seems to be working pretty well. The system is very simple, let me explain. Step 1 In the template file for the contact form have this code: <?PHP /* create a random integer.*/ $sendFormInteger = mt_rand(1000,9999); /* save the integer to session var using PW API or just go PHP vanilla */ $session->set('antispam_code', $sendFormInteger); ?> As you can see we just create a 4 digit integer and save it to a session var using Processwire $session API. https://processwire.com/api/variables/session/ Step two Also in your form have for example a label that display the code we created above, so the poster has to manually fill it out in a form field. For example like this: <label for="antispam_code">Anti spam code: <strong><?PHP echo($session->get('antispam_code')); ?></strong></label> <input type="text" name="antispam_code" value="" class="" placeholder="Fill in antispam code here" /> We simply echo out the code we saved in the session var into the label so the user can read it and then fill it out into our form field below the label. Step Three In the file or template that receives the form data put in a simple check like bellow: <?PHP /* sanitize our data and make sure its a integer */ $antispam_code = $sanitizer->int($input->post->antispam_code); /* check if the code we saved in the session var is equal to the one filled in the form and sent to us */ if($session->get('antispam_code') == $antispam_code) { /* if antispam code correct then delete it and go on */ $session->remove('antispam_code'); } else { /* if code is NOT correct then do something else */ } ?> More info on $sanitizer API: https://processwire.com/api/variables/sanitizer/ Just thought i share this technique with you all. I have no doubt that you could easily come up with something more advanced then a 4 digit integer that i use. My anti-spam system is set up so that it creates a new code everytime the form template is loaded. So it should be hard to guess unless they make the bot read the HTML and find the code in the label and make the bot fill out the correct form field before sending it. Happy coding.
  16. Hello Videokid. Thank you for your contribution. I would like however a little explanation how your version is different from mine so i could learn from it. I see the use of the $session API variable, but what use has it in your code example ? what does it do ? Thank you again.
  17. I would like to thank all the Nice people giving me likes for this post. It realy gives me encuragement to come up with future tutorials when i have something usefull to share.
  18. @cstevensjr thank you sir for the link. I have some good info to work with.
  19. Hello Everyone. My question is to the superior minds and Processwire gurus and developers here if it would be safe to straight up upgrade a 2.7.2 installation to the latest 3.x.x Dev version ? If so, any special things i should consider ? I have no third party modules installed. Its all core and vanilla Processwire. Thank you in advance.
  20. Thank you sir. I must say that i fell in love with Processwire when i discovered it by chance. My Autism makes it difficult for me to grasp concepts sometimes and with Wordpress i had a tough time. Put Processwire changed everything for me. It sounds silly byt its like a dream come true. Processwire totaly make sens to me and the way the API works and as a fan of jQuery i love the route Ryan Cramer took with it.
  21. Hello all PW fans. I wanted to contribute with a simple but short tutorial on how i created a simple visitor counter to have a rough estimate on what pages got visits on my website. This tutorial assumes that you have setup a field on your page template that you want to monitor with a name of visit_counter of the field type integer. I put this simple code together by reading some answers by the Excelent Ryan Cramer here on the forums and decided to make a few changes to his implementation. This is because i did not want the code to count my visits to the site if i was logged in. Instead the code shows the current pages visits if i am logged in, and hides it if i am not. Enough talking. Here is the code: <?PHP /* simple code for recording current page visit count to its visit_counter field of "integer" type. But only if the visitor is not currently logged in. */ if($user->isLoggedin()) { /* if the user is logged in */ echo("<p>Visits: {$page->visit_counter} st.</p>"); } else { /* if the user is NOT logged in */ /* get current visit counts and save them plus one */ /* turn of output formating so PW do not give an error when we change the value */ $page->of(false); /* increment the current integer plus one */ $page->visit_counter++; /* save the visitor_counter field */ $page->save('visit_counter'); /* turn on output formating so PW work as it should */ $page->of(true); } ?> I also put this code in a PHP file by itself and named it _visit_counter.php so that i could easily include it in whatever page i want to monitor. You could potentialy expand this and make it more advanced. i would look at the "roles" and "user" section of the: http://cheatsheet.processwire.com Bonus Tip, in the PW admin go to your template that you have the field setup in and on the "advanced" tab look for the "List of fields to display in the admin Pagelist" section and in that field put: {title} - Visits: {visit_counter} This again assumes the fields name is visit_counter . Now in my page list in admin i can see the title followed by the number of visits. Handy This is my first post to these forums. And i will try to help out where i feel my abilites come to the rescue. Hope this helps anyone out there working with Processwire.
×
×
  • Create New...