We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Can someone doublecheck my work please

Development and Programming

DarkScythe's avatar
DarkScythe
36 posts
17 years ago
DarkScythe's avatar DarkScythe

Hello,

Going ahead with my site redesign, I felt a need to think ahead and make sure if any content unsuitable for minors ever came up, I had access to it covered. To that end, I’ve managed to use an extension to make birthdays required and removed the ability for users to change it afterwards. All that’s left is to create a conditional that says not to load a specific set of categories/posts for members under a certain age, or unregistered users.

Unfortunately, it doesn’t seem like there is any built-in functionality to find the ages of users. It’s odd considering the custom field variable {age} is mentioned several times throughout the EE docs.

Anyway, there was an old plugin that did this, but it seemed to only work when supplied a very specific birthday format. I decided to brush off my old Learning PHP book and give it a try myself.

I’ve ended up with something that SEEMS to work.. but I’m not sure by any means, and I would like someone to doublecheck it for me. I made this really because I had absolutely no idea how to interpret the age calculation scripts other people made, and I designed this one around how humans normally calculate age.

$rawdob = "May 15, 1950";
$rmob = explode(' ', $rawdob);
$mob = date("m", strtotime($rmob['0']));
$dob = intval($rmob['1']);
$yob = $rmob['2'];
$curtime = explode(' ', date("m d Y", time()));
$dobday = "$mob"."$dob";
$today = "$curtime[0]"."$curtime[1]";
$dobyear = "$yob";
$thisyear = "$curtime[2]";
if ($today < $dobday) {
    $age = ($thisyear - $dobyear) - 1;
    }
elseif ($today >= $dobday) {
    $age = $thisyear - $dobyear;
    }
else {
    $age = 'ERRROR';
    }
echo "$age";

I wanted to avoid using time() as much as possible due to its inherent flaws when starting from a date before 1970, so I came up with that method. The rawdob format is what seems to be provided by EE’s native {birthday} variable - something the other age plugin couldn’t seem to cope with. I can’t seem to find a way to get the current date without using time() though.

As it’s quite simple I’m wondering if I should package it into a plugin as well, I just need a way to get the {birthday} information into the $rawdob variable somehow.

Reading up on plugin development, I probably could have avoided much trouble by accessing the database and calling up those already-numeric fields directly, but I think it’s a waste of a connection for something that small, unless you guys think it’s OK to do so.

Anyway, sorry for the long post, but if anyone can help me out I’d appreciate it.

Thanks in advance.

       
DarkScythe's avatar
DarkScythe
36 posts
17 years ago
DarkScythe's avatar DarkScythe

Well, I’ll assume since no one’s said anything yet, there’s nothing too wrong with it.. I’m probably just thinking too much.

Anyway, I’m thinking it would be easiest to turn this into a full fledged plugin so the code is more mobile. There’s a guide in the docs I can try to follow, but I can’t see to find out how to get a plugin to accept EE-parsed data. Would the {Birthday} tag work inside the plugin, or would I need to make it so that it takes it within the EE tag.. something like {exp:age:calc {birthday} >= 18} [categories] {/exp:age:calc:}?

       
DarkScythe's avatar
DarkScythe
36 posts
17 years ago
DarkScythe's avatar DarkScythe

Okay..

I don’t know what I am doing wrong here.

I’ve followed the plugin making guide in the EE docs to the letter, but when I upload the plugin file into the plugins folder and try to visit the Plugins Manager in the CP, it just renders a blank page. When I remove the plugin, it renders the page just fine.. What’s going on here? Have I missed something?

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.