Move some of the common functionality from CodeViewer/basic.php

Some of the functionality in CodeViewer is useful in DuggaSys as well. This moves it out to the shared folder.

We should probably perform additional review to make sure that it doesn't break anything for CodeViewer.