Update lib.php

When installed in a Moodle instance newer than 2.2, the following error is thrown;

get_context_instance() is deprecated, please use context_xxxx::instance() instead.

This code change will stop this error being thrown, using the new function as requested by the error. I have placed the isLoggedIn() check to bypass another error that is thrown when trying to access this new function without being logged in. When you are not logged in, you have a user id of '0' and when passing this to the new function, it calls a Moodle Coding Error and wot display a page.