Quantcast
Viewing all articles
Browse latest Browse all 2443

Extension Writers Discussion • Questions from a beginner: porting custom coding into extension

Hello.

I am someone who hasn't really written an Extension before. Some custom coding in the php and html files, but never a full fledged extension.


Basically, I am trying to alter how search.php behaves when someone does not have permission to search the board and is not logged in. ie. presenting a login box to guests instead of the error massage.

The default code in search.php is this:

Code:

// Is user able to search? Has search been disabled?if (!$auth->acl_get('u_search') || !$auth->acl_getf_global('f_search') || !$config['load_search']){$template->assign_var('S_NO_SEARCH', true);trigger_error('NO_SEARCH');}
The custom code that does what I want is this:

Code:

// Is user able to search? Has search been disabled?if (!$auth->acl_get('u_search') || !$auth->acl_getf_global('f_search') || !$config['load_search']){// Is the user logged in but unable to search? If so, they will get an error message. if ($user->data['user_id'] != ANONYMOUS){$template->assign_var('S_NO_SEARCH', true); trigger_error('NO_SEARCH');}// If the user is a guest and cannot search, they will recieve a login page.                      login_box('', ((isset($user->lang['LOGIN_EXPLAIN_' . strtoupper($mode)])) ? $user->lang['LOGIN_EXPLAIN_' . strtoupper($mode)] : $user->lang['LOGIN_EXPLAIN_SEARCH']));}
In addition to adding this to common.php:

Code:

'LOGIN_EXPLAIN_SEARCH'=> 'In order to search the board you have to be registered and logged in.',

This code does work, but basically, I am trying to convert this MOD to an Extension, as most people are certainly not going to want to edit core files and for good reason.

I am a beginner when it comes to making Extensions and I haven't had much luck making them in the past, especially since I do not think the needed php event exists for this and I do not have the skills required to make one.


---------

I'm making an attempt to create an event. Am I even close to doing what I need to do? I'm trying to bypass the default "not authorized" behavior as shown in the uppermost code box, but I have no experience and am probably doing a bunch of things wrong.

Code:

$vars = array('Auth','config','template',);extract($phpbb_dispatcher->trigger_event('core.search_modify_permissions_before', compact($vars)));

Statistics: Posted by [Dimetrodon] — Wed Oct 16, 2024 10:23 pm



Viewing all articles
Browse latest Browse all 2443

Trending Articles