Start ::
Developers Corner ::
Module Development ::
A better way to modify core files? /includes/pnUser.php
Moderated by: Support Team
-
- rank:
-
Helper
- registered:
- May 2004
- Status:
- offline
- last visit:
- 17.04.08
- Posts:
- 204
I have a requirement for two functions that determine similar user status information to the functions used to display the "Login"/Logout" link and the "Create free account/Your Profile" link in many themes. In my case they are membership related.
You can see what I'm talking about by looking at the top of my website where you'll see something like :
[ Create free account | Join the Club | Log-in ]
I currently have two new functions appended to the /includes/pnUser.php file and the "Join the Club" bit is determined by a return from one of these.
I'm also in the process of upgrading from 0.750 to 0.762 and wondered whether there's a better way than substantially adding to this core PN file (which I realise is generally discouraged) so I don't need to tweak too much when I upgrade every time.
Would it be better to seperate my two functions out to a new /includes/membership.php file and then include that from pnUser.php or are their even better ways to achieve what I want?
A block is not the answer BTW or if it is you could argue that the current "create account/login/logout/your profile" functions should also be part of a block. -
- rank:
-
Moderator
- registered:
- March 2002
- Status:
- offline
- last visit:
- 26.08.08
- Posts:
- 7720
A smarty plugin would probably be the best way - assuming that your theme is a xanthia based one. You then just drop the plugin tag into the theme template(s) where you want the output to appear.
-Mark -
- rank:
-
Helper
- registered:
- May 2004
- Status:
- offline
- last visit:
- 17.04.08
- Posts:
- 204
-
- rank:
-
Helper
- registered:
- May 2004
- Status:
- offline
- last visit:
- 17.04.08
- Posts:
- 204
I already have a complicated module that these particular functions are used in relation to.
I already use two Smarty plugins:
/modules/pnRender/plugins/function.pnusermemberstatus.php
to see simply whether somebody is a member or not (I use this in my HTML module templates to only show members member stuff) and
/modules/Xanthia/plugins/function.membershiplinks.php
to determine the actual membership status and generate the links this particular thread started off talking about.
I think what I need to know is; in a Smarty plugin how do I call a function from a PHP script that's not part of the PN core like pnUser.php
Is it simply a case of including:
at the start of my plugin?
While we're on it, what's the difference between the pnRender and Xanthia plugin directories? -
- rank:
-
Professional
- registered:
- December 2002
- Status:
- offline
- last visit:
- 24.08.08
- Posts:
- 1588
yes, but if the functions are loaded already you will get an error.
It is my opinion that pnRender plugins are for core and module functionality whilst xanthia plugins are concerned with theme related functionality.
-Lobos
-----
-Lobos
Professional PHP Framework Services: Concept, Development and Deployment -
- rank:
-
Steering Committee
- registered:
- December 2002
- Status:
- online
- Posts:
- 13408
I take it then that your module isn't API compliant - because this would make it easier.
Anyway, include_once('/modules/Membership/newFunctions.php'); will do the trick.
-----
Regards,
Simon
itbegins.co.uk - Zikula Consulting
Please read the Support Guide -
- rank:
-
Moderator
- registered:
- March 2002
- Status:
- offline
- last visit:
- 26.08.08
- Posts:
- 7720
I agree with Lobos. These functions belong in the module getting called using pnMod(API)Func - this is, after all, the point of having a module based system. Perhaps your API functions might actually be useful elsewhere too?
The difference between the two plugin directories is now a little arbitrary but originally the idea was that the Xanthia (now Theme) plugins directory would be plugins for use in theme templates (for example those that generate dynamic values for the header ->) where as those in pnRender would be plugins that interfaced to the pnAPI or other core functionality. The boundaries have blurred quite considerably since we introduced XTE and there are some good arguments for simply putting these two directories together.
Additional .8x note. In this release you also have a plugins directory in /config/plugins. This can be used to hold your own site wide plugins without having to add them to either the Xanthia (Theme) or pnRender modules.
-Mark -
- rank:
-
Helper
- registered:
- May 2004
- Status:
- offline
- last visit:
- 17.04.08
- Posts:
- 204
My module is API compliant. I think my original problem was that I was trying to duplicate functionality held in a core module, so just added it to the end of that core module.
I'll have a play over the next few days and post the solution here for future reference.
Thanks for all the assistance. -
- rank:
-
Helper
- registered:
- May 2004
- Status:
- offline
- last visit:
- 17.04.08
- Posts:
- 204
Here's what I did and why.
I wanted to remove some changes I'd made to the core file /includes/pnUser.php to support some Xanthia plugins used in my templates and by the HTML module (i.e. not just used by the module to which they relate). This would make my upgrade route from .750 to .762 and beyond easier.
I removed the functions from /includes/pnUser.php and placed them in the pnuserapi.php script for "mymodule" to which they relate. I had to rename them to fit in with the standards of my API module.
Then I changed the plugins to include the following:
I left the two plugins where they were. One in /modules/pnRender/plugins as it's used by the HTML Module and one in /modules/Xanthia/plugins as it's used by my site's theme. It sounds like it doesn't really matter where they are, as long as I remember to put them back after an upgrade. To this end I'd highly recommend anybody who dabbles to make sure each changed/new file contains your name so you can find them it easily. I just used an elaborate find/grep combo
When .8 comes along I guess I can move my plugins into the new /config/plugins directory.
edited by: dunx, May 02, 2006 - 10:36 PM
Start ::
Developers Corner ::
Module Development ::
A better way to modify core files? /includes/pnUser.php
