BIM #6 – Learning weblib.php

It’s been a while since I last did some work on BIM, various other tasks getting in the way. The main mid-term KPI is the delivery of a working prototype of BIM working within Moodle. That’s what I started in the last bit of work.

The aim here is to get into weblib.php enough so I can get most/much of the prototype in place. weblib.php contains PHP functions used in Moodle to generate output. I could just output HTML but using weblib.php will make it easy for the prototype to look like Moodle. weblib.php also brings other benefits, so better to start using it now, rather than later. Just another step in learning Moodle.

weblib.php

The following is an attempt to understand and internalise the model/approach that underpins weblib.php – defined in the comments as

Library of all general-purpose Moodle PHP functions and constants that produce HTML output

First, I’m simply going through the library file and getting a feel for the functions there. The following is a list of those functions, in the order that they currently appear with some light categorisation applied. On the surface it’s a mindless exercise, but it helps me see the “lay of the land”.

  • Utility functions:
    • s|p($var, $strip=false) – add quotes to HTML characters
    • addslashes_js( $var ) – quote javascript
    • strip_querystring( $url ) – remove the query string from url
    • get_referer( $stripquery=true ) – return HTTP_REFERER
    • me() – return name of current script with querystring
    • qualified_me – me with a full URL
  • class moodle_url – useful for dealing with URLs with multiple parameters. Apparently mostly for pages that link to themselves.
  • More utility functions
    • data_submitted( $url=” ) – is there form data waiting to be processed
    • stripslashes_safe($mixed) – removes backslashes from string
    • stripslashes_recursive( $var ) – used on arrays/objects
    • addslashes_recursive( $var ) – reverse of above
    • break_up_long_words( $string, $maxsize=20, $cutchar=”) – break up text …
    • str_ireplace( $find, $replace, $string ) – search&replace
    • stripos($haystack, $needle, $offset=0 ) – find location of string.
  • Popup windows
    • element_to_popup_window(…..) – the description is harder to understand than the function name. I’m assuming it displays something that leads to a popup window
    • link_to_popup_window(….) — seems to be a trend developing
    • button_to_popup_window(…)
    • close_window_button( …. )
    • close_window($delay=0)
  • Form elements
    • choose_from_menu(…) – take an array and output HTML for select element
    • choose_from_menu_yesno(…)
    • choose_from_menu_nested(…)
    • choose_from_radio(….) – group of radio buttons
    • print_checkbox(…) – display html checkbox with optional label
    • print_textfield(…)
    • popup_form(…) – little popup form
  • Misc utility functions
    • formerr($error) – print some red text
    • validate_email($address )
    • get_file_argument( $scriptname) — extract file argument
    • get_slash_arguments – get them from the environment variables
    • parse_slash_arguments – get the PATHINFO stuff at end of URL?
  • text formats –
    • format_text_menu() – return array of text formats that can be used in a popup menu
    • format_text(….) – take text in a variety of format codings and return it as safe HTML.
    • text_format_name( $key ) – get the name of the Moodle text format of a given selection of text in that format.
    • reset_text_filters_cache()
    • format_string(….) – take a string, return string after processing. Used for activity titles, post subjects etc.
    • format_text_email(…) – given text in variety of formats return it as normal text ready for email
    • filter_text( $text, $courseid=NULL) – HTML text is run through filters
    • filter_string( $string, $courseid=NULL )
  • Trusted text
    • trusttext_present( $text ) – is this text marked as trusted?
    • trusttext_strip( $text ) – called before clearning…??
    • trusttext_mark( $text ) – mark text as trusted – without doing anything on it???
    • trusttext_after_edit(…)
    • trusttext_prepare_edit(…)
  • cleaning up text and other stuff
    • clean_text( $text, $format ) – take raw text and remove nasty tags
    • purify_html( $text ) – cleaning function using HTML purifier
    • cleanAttributes() – clean attributes of tags
    • cleanAttributes2() – another one?
    • replace_smilies() – replace text smilies with image one
  • text conversion
    • text_to_html(…)
    • markdown_to_html(..)
    • html_to_text()
    • convert_urls_into_links(..)
  • Misc other
    • highligh(…) – highlight words in a given string
    • highlightfast(…) – faster
    • get_html_lang() – return lang attributes in HTML
    • skip_main_destination() – an accessibility think to skip to main content
  • standard web page parts
    • print_header(……) – header of HTML
    • require_js – include javascript libraries
    • get_require_js_code(..) – not called directly
    • force_strict_header($output) – debugging aid
    • print_header_simple
    • print_footer
    • current_theme – what’s the current theme
    • current_category_theme
    • style_sheet_setup – called by style sheets
    • theme_setup
    • user_login_string – indicates login status of user
    • check_theme_arrows – have they been set?
    • link_arrow_right(…) – return the HTML for..
    • link_arrow_left(…)
    • get_accesshide(….)
    • get_separator(..) – return breadcrumb separator
    • print_navigation(…) – print breadcrumbs
    • build_navigation(…) – used by print_header etc.
    • print_headline(…) – retained for backward compatbility
    • print_heading($text, $align=”,$size=2,$class=’main’,$return=false) – print text formatted for a heding
    • print_heading_with_help – centered heading with help button
    • print_heading_block(…)
    • print_continue( $link, $return) – print link to continue on another page
    • print_box($message, $classes, $ids, $return ) – print a message in a standard themed box
    • print_box_start(…) – starts a box with divs
    • print_box_end()
    • print_container(…) – print message in standard themed container
    • print_container_start|_end
    • open_containers – return # of open containers
    • print_container_end_all – close ’em all
    • print_single_button(…) – self-contained form with single submit
    • print_spacer(…) – print spacer image
    • print_file_picture(…) – include picture from file/url
    • print_user_picture(…) – print user’s avatar
    • print_user(…) – print summary of user in a little box (uses a table to get the box!!!)
    • print_group_picture(..) – show the group’s avatar.
    • print_png – show png image
    • print_table( $table, $return=false ) – show nicely formatted table
    • print_recent_activity_note(….)
    • print_textarea(…)
    • use_html_editor(…) on all textareas in the current page
    • print_editor_config(…)
    • update_course_icon( $courseid) – show the edit button for courses
    • switchroles_form(…)
    • update_mymoodle_icon..
    • update_tag_button
    • update_module_button
    • update_categories_search_button
    • navmenu – return popup menu with course activity modules
    • navmenulist – similar to above</li
    • print_date_selector – print form items for date entry
    • print_time_selector –
    • print_timer_selector
    • print_grade_menu
    • print_scale_menu
    • print_scale_menu_helpbutton
    • print_error – error page
    • editorhelpbutton() – print help icon linked to help page on a number of topics
    • helpbutton(….) print a help button
    • emoticonhelpbutton
    • editorshortcutshelpbutton
    • notice( … ) print a message and exist
    • notice_yesno(….) print a message with yes or no options
    • redirect(…) – print notice and redirect
    • notify(…) message in bold in optional colour
    • obfuscate_email(..)
    • obfuscate_text()
    • obfuscate_mailto()
    • print_paging_bar(…)
    • print_side_block(..)/print_side_block_start|end
    • print_speller_code – code for spellchecking
    • print_speller_button
    • print_maintenance_message
    • adjust_allowed_tags
    • class tabobject ??
    • print_tabs
    • page_doc_link – string contining link to user docs
    • doc_link(..)
    • debugging/disable_debugging
    • frametarget
    • print_location_comment
    • print-arrow(…) – used to show up/down arrow for column sorting, can be given language string to save on dbase access
    • right_to_left – true if language is right to left

Some questions that arise out of that:

  • What’s the difference between container and box?
    Haven’t found an answer to that one….only a quick check. From experiments, the container is a HTML container – doesn’t necessarily look like anything. While the box is visual.

Getting into it

Time to get some hard-coded HTML in place. Work on the default view for students that shows their details, blog posts and other stuff. Working, alright for first step. More next week.

BIM student details

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s