Jump to content

Sergio

Members
  • Posts

    534
  • Joined

  • Last visited

  • Days Won

    11

Everything posted by Sergio

  1. I may be missing something, but isn't this as simple as: <?php // handle output of 'hreflang' link tags for multi-language // this is good to do for SEO in helping search engines understand // what languages your site is presented in foreach($languages as $language) { // if this page is not viewable in the language, skip it if(!$page->viewable($language)) continue; // get the http URL for this page in the given language $url = $page->localHttpUrl($language); // hreflang code for language uses custom lang_code field $hreflang = $language->lang_code; // /en or /pt in this website // output the <link> tag: note that this assumes your language names are the same as required by hreflang. echo "\n\t<link rel='alternate' hreflang='$hreflang' href='$url' />"; } ?>
  2. Hello fellow PW devs! This is a short story from the server management trenches. These past couple of days trying to solve an unexpected problem: after DigitalOcean patched the droplets in NYC3 region last week, my client's droplet became almost useless and went down a couple of times. The droplet has 2GB RAM and was running Ubuntu 16.04 that was updated to kernel 4.4.0-116 after the patch. The server was provisioned using Forge (forge.laravel.com). After sshing into it, and running "top" I've noticed the cause: "php-fpm7.1" processes (3-5 instances) were spiking the CPU to 100%. This was very odd, as the CPU usually kept around 33% most of the time. The site uses ProCache and markupCache and was getting around 800-1000 visits/day last week. I checked everything on PW's side and nothing seemed out of place, so I went restarting PHP and Nginx but the problem continued. I checked access logs and no suspicious activity shown up. I upgraded PHP to 7.2 to see if anything will changed but the problem continued. My only guess after all that is that the droplet in question got screwed up somehow, because I didn't see any complaints on the web of other people getting the same problem on DO (But I confess that I did a quick Google search only). So in the end I decided to create a new droplet, now with 2 CPU cores and kept the 2GB (1 extra core and $5 cheaper ). Reinstalled PW there and pointed the floating IP to this new server. The installation went smooth but to one issue: error log started to show messages of MySQL showing "to many files" error when the users were searching. I've never encountered this message before, so after reading some StackOverflow posts, I changed mysql.services config file to remove its file limit (https://stackoverflow.com/a/36807137) Everything is normal now, but I think I'll never discover what truly happened. Anyone else had this kind of problem with MySQL before?
  3. Hi Mikael! Yes you can! On the field settings, go to "Access" tab and there you'll have the options to make the field editable per role.
  4. You're welcome! And yes, for multiple values the querystring approach is better.
  5. You can put the filter logic in your articles.php template: // First Approach //Allow URL segments on the articles template // so the url will be example.com/articles/cars/ 1 - $category = $sanitizer->selectorValue($input->urlSegment1); // Second Approach // If you don't want to use segments, you can use querystrings, but getting a less refined approach IMHO // example.com/articles/?cat=cars 2- $category = $sanitizer->entities($input->get->cat); $filtered_articles = pages()->get('/articles/')->children("categories=$category, limit=10");
  6. Do you really need the /en on the URL as it's the default language? I would not recommend that, because it's a pointless redirect IMHO that hurts your page loading time (albeit a little bit).
  7. $bool = $user->isLoggedin(); https://processwire.com/api/ref/user/is-loggedin/
  8. Great hook, @Robin S! I'll use this on a future project. Thank you!
  9. Multiple sorts improve the memory usage or other measurable factor? I really don't know. If yes, great! Regarding the feature limit, liked I said, users can be lazy and leave several itens marked as featured in the page tree. So that's an easy way to filter them when your front end page only accepts one featured item at a time.
  10. Hi Carolyn! No, sorry! They expired months ago.
  11. First contribution, "Yet another sorting of featured and non featured articles" /* * Find the children by date, filter by featured (checkbox) and exclude this filtered item * from the final array so it won't appear repeated on pagination. * If there's more than 1 featured item on Admin, sort them by date. * Useful when the user is lazy and marked several items as featured. */ $children = $page->children("sort=-published_at, limit=10"); $children->prepend($children->find("featured=1, limit=1, sort=-published_at")); $featuredItem = $children->first(); $children = $children->not("$featuredItem"); If there's a better way, let me know!
  12. Developing a mobile app is a lot of pain, trust me, so for the new version of my client's app, we decided to trash our bespoke version (made using Appcelerator Titanium) and sign up for a service that takes this pain away. After comparing features and pricing, the client decided for using GoodBarber.com and is pretty happy (currently paying $48/month). The app is pretty simple but met our objectives. GoodBarber enables push notifications but we not using though, as it doesn't work for our main content: podcasts episodes that came from Soundcloud feed. The app in questions is this one: https://itunes.apple.com/br/app/project-management-connector-with-ricardo-vargas/id385663838?mt=8 https://play.google.com/store/apps/details?id=com.goodbarber.pmconnector
  13. Thanks Adrian! I can understand the decision about it. The problem is that is not clear. If you add a permission "user-admin-all" you expect that the user will be able to add to all users any roles BUT the superuser's. That's why I got confused.
  14. Hi @geekpete, welcome to the forums. As Robin S. said, there are better alternatives. I'd like to suggest @tpr's module Template Latte Replace This is a great template engine that I'm truly happy to use on more complex websites.
  15. Yep, to add "user-admin-all" you must have "user-admin" checked. And I tried adding "user-admin-editor" to see what happens, but this is just a more granular control than "user-admin-all". I followed your tip and created a "user-manager" role, and added to it the user-admin and user-admin-all permissions. Also removed them from the editor role. Now, the user with "editor" role can promote another user to the "editor" role, but cannot promote to "user-manager" role. The thing is, as I see, a user with "user-admin" permissions cannot promote another user to his/her same role level. This appears odd.
  16. I have this "editor" role, that has the "user-admin-all" permission. I tried several times, doing different things sets of permissions, but I can't make a user with this role being able to make another user an "editor" too. PW disables the "editor" checkbox. I read the documentation 3 times that my eyes cannot see what I'm missing anymore. Any clues?
  17. Yes, you can use the database class: https://processwire.com/api/ref/database/ You can create a module (recommended) or do it directly on your template. See this example: public function saveViews(Page $page) { $db = $this->wire('database'); $table = "table-name"; $sql = "SELECT page_id, COUNT(page_id) as total_views FROM $table WHERE page_id=:page_id"; $query = $db->prepare($sql); $query->bindValue(':page_id', $page->id, \PDO::PARAM_INT); try { $query->execute(); while ($set = $query->fetch(\PDO::FETCH_ASSOC)) { $new_views = $set['total_views']; $current_views = $page->page_views; $page->setOutputFormatting(false); $page->page_views = $current_views + $new_views; $page->save('page_views'); $this->wire('log')->save("messages", $new_views.' views imported for page '.$page->title); } } catch(\Exception $e) { // intentionally blank } }
  18. Indeed. I run a medium website in a VPS with 2GB and hardly use more than 70% of the RAM.
  19. Did you install any new module or are you running any complex cron job? Ask the hosting company to send you a log so you can see what's happening. Usually is MySQL the usual suspect of using too much ram, not PW.
  20. I'm with @kongondo! Glad you and your family are ok!
  21. You got me!! Merry Xmas @SamC!!
  22. Beware of the large JS load that comes with Discuss, that's why I load it only if the user clicks the "Comments" button. It's possible to show the current comment count, calling the discuss API, but I didn't want it. Example page: https://ricardo-vargas.com/podcasts/think-about-how-to-connect-your-strategy-design-with-your-ability-to-deliver-or-pay-the-price/
  23. I just bought Crysis (never played it!) and MotoRacer (oh the good memories...). Thanks for the tip @FrancisChung!
  24. My boss is pretty well know in the Project Management sector in many countries, and I built his website in PW: https://ricardo-vargas.com/biography/
×
×
  • Create New...