Replacing weblib moodlelib phplib functions

Re: Replacing mod/forum/lib.php function Frugal Forum Format

by Bruno Vernier -
Number of replies: 3
this library function replacement concept applies to the lib.php files found in each mod (module type)

some colleagues and I prefer a more frugal look and feel when reading postings in forum... we wanted to have the edit/delete/reply and ratings widgets on the head of each posting at the far right instead of at the bottom of each posting ... resulting in a significant reduction of the size of longish conversations, especially conversations with lots of short postings

so I modified one function called forum_print_post from mod/forum/lib.php and put it in lib_local.php

1. I added include('lib_local.php'); at the bottom on lib.php

2. we cannot declare the same function twice, so either we rename the original function so it won't get used anymore, or we call the new function directly from the old one at the start of the function with return new_function(parameters)

i've attached the lib_local.php in case you want to check it out (it contains exact instructions at the top)

I call this the Frugal Forum Format smile

note: the attached file gets filtered a bit ... and I am not sure why... the extra PRE at the start should not be there and there is no closing ?> ...

In reply to Bruno Vernier

Re: Replacing mod/forum/lib.php function Frugal Forum Format

by Chris Luther -

we cannot declare the same function twice, so either we rename the original function so it won't get used anymore, or we call the new function directly from the old one at the start of the function with return new_function(parameters)

Hmmm.  Why not?  Won't declaring it in your local file obliterate the standard definition?  Last one declared wins!  Or at least that is what happens for me. smile  When you redefine in your local function I think it is unnecessay to rename the original function.

In reply to Chris Luther

Re: Replacing mod/forum/lib.php function Frugal Forum Format

by Bruno Vernier -
Chris,

 using PHP 4.3.3, I get an error message about not being allowed to re-declare function



In reply to Bruno Vernier

Re: Replacing mod/forum/lib.php function Frugal Forum Format

by Chris Luther -

OK, I stand corrected.  But the reason why is that the LIBS are included using Require_Once().  From the PHP docs....

require_once() should be used in cases where the same file might be included and evaluated more than once during a particular execution of a script, and you want to be sure that it is included exactly once to avoid problems with function redefinitions, variable value reassignments, etc.

So the decison has to be made if we want to change Require_Once() to Require() when bringing in these resources.  That will enable quick enablement of function modifications. But I need to test more to see if it wacks out something else. 

====================

And to correct my earlier correction smile If we can get this to work the end statement should read:

include($CFG->dirroot.'\lib\weblib-custom.php');