Vy, I needed YUI loading from the header file, therefore I changed your function. I hope that is ok.
My changes are in CVS.
I added a second parameter. If it is set to 1 and an array of YUI names is set, the function returns the loading strings only for those YUI libs which have not already been loaded in a previous empty call.
a) within Moodle only require_js ($lib[]) is called to collect libraries
b) print_header calls require_js() to output the library links
c) from header.html you call require_js($lib[], 1) to add library links not yet set
I commented your original lines out , so you can easily see what I have changed.
One note from www.php.net: If you use array_push() to add one element to the array it's better to use $array[] = because in that way there is no overhead of calling a function. I changed that part.
I needed to replace your recursive call with a foreach loop. I don't know if the recursive call of require_js is slower than a foreach loop??? Do you know?
I've checked in changes to require_js(), into HEAD. It basically behaves like the require_once() PHP function. You can give the (www) path of the JavaScript library you want loaded, or you can pass an array of paths. You an also give it the short names of some of the common library files (mostly YUI stuff). If a file is not found, we error() out.
Used without arguments, require_js() will return the html needed to load the JS files. print_header() in weblib now calls require_js().