HTML Logo by World Wide Web Consortium (www.w3.org). Click to learn more about our commitment to accessibility and standards.

ocPortal Developer's Guide: Core support functions (2)

» Return to Contents



support.php contains further support functions, which are shared between the installer and the main installation (i.e. global.php and global2.php are not used by the installer, and the installer emulates these functions functionality via minikernel.php).

sources/support.php

Global_functions_support.php

Function summary

void init__support ()
?array find_template_place (ID_TEXT codename, ?LANGUAGE_NAME lang, ID_TEXT theme, string suffix, string type)
BINARY is_wide_high ()
BINARY is_wide ()
integer ocp_mb_strlen (string in)
~string ocp_mb_substr (string in, integer from, ?integer amount, boolean force)
string ocp_mb_strtolower (string in)
string ocp_mb_strtoupper (string in)
boolean is_writable_wrap (PATH path)
void intelligent_write_error (PATH path)
tempcode intelligent_write_error_inline (PATH path)
boolean fractional_edit ()
integer strlen_sort (string a, string b)
boolean has_no_forum ()
boolean addon_installed (ID_TEXT addon)
string float_to_raw_string (float num, integer decs_wanted, boolean only_needed_decs)
string float_format (float val, integer frac_digits)
string integer_format (integer val)
integer multi_sort (array a, array b)
void ocf_require_all_forum_stuff ()
tempcode globalise (tempcode middle, ?mixed message, string type, boolean include_header_and_footer)
~string ocp_tempnam (string prefix)
object make_xhtml_strict (object global)
mixed array_peek (array array, integer depth_down)
string fix_id (string param)
boolean match_key_match (string match_tag, boolean support_post)
ID_TEXT get_page_name ()
array list_to_map (string map_value, array list)
array collapse_2d_complexity (string key, string value, array list)
array collapse_1d_complexity (string key, array list)
string ocp_srv (string key)
boolean is_valid_ip (IP ip)
IP get_ip_address (integer amount)
string get_browser_string ()
string get_os_string ()
boolean cron_installed ()
?string geolocate_ip (?IP ip)
boolean compare_ip_address (string wild, IP full)
boolean compare_ip_address_ip4 (string wild, array full_parts)
boolean compare_ip_address_ip6 (string wild, array full_parts)
tempcode get_flagrant ()
void log_it (ID_TEXT type, ?SHORT_TEXT a, ?SHORT_TEXT b)
void syndicate_described_activity (string a_language_string_code, string a_label_1, string a_label_2, string a_label_3, string a_pagelink_1, string a_pagelink_2, string a_pagelink_3, string a_addon, BINARY a_is_public, ?MEMBER a_member_id, boolean sitewide_too, ?MEMBER also_involving)
boolean has_external_site_wide_syndication ()
tempcode get_syndication_option_fields ()
string php_addslashes (string in)
array remove_duplicate_rows (array rows, string id_field)
void member_tracking_update ()
?array get_members_viewing (?ID_TEXT page, ?ID_TEXT type, ?SHORT_TEXT id, boolean forum_layer)
boolean is_invisible ()
integer get_num_users_site ()
integer get_num_users_peak ()
string escape_html (mixed string)
URLPATH brand_base_url ()
boolean browser_matches (string code)
boolean is_mobile (?string user_agent, boolean truth)
?string get_bot_type ()
SHORT_TEXT read_multi_code (ID_TEXT param)
string flatten_slashed_array (array array)
string wordfilter_text (string text)
string xmlentities (string string, integer quote_style)
boolean has_cookies ()
boolean has_js ()
string get_rand_password ()
?mixed mixed ()
array seo_meta_get_for (ID_TEXT type, ID_TEXT id)
void seo_meta_load_for (ID_TEXT type, ID_TEXT id, ?string title)
tempcode get_loaded_tags (?ID_TEXT limit_to, ?array the_tags)
ID_TEXT get_zone_default_page (ID_TEXT zone_name)
SHORT_TEXT best_hash (SHORT_TEXT to_hash, SHORT_TEXT salt)
boolean check_master_password (SHORT_TEXT password_given)
ID_TEXT produce_salt ()
ID_TEXT get_site_salt ()
string titleify (ID_TEXT boring)

void init__support()

Standard code module initialisation function.

Parameters…

(No return value)


Return to the function index for this class Expand: View the source code to this function

?array find_template_place(ID_TEXT codename, ?LANGUAGE_NAME lang, ID_TEXT theme, string suffix, string type)

Search for a template.

Parameters…

Name codename
Description The codename of the template being loaded
Type ID_TEXT

Name lang
Description The language to load the template in (templates can embed language references) (NULL: users own language)
Type ?LANGUAGE_NAME

Name theme
Description The theme to use
Type ID_TEXT

Name suffix
Description File type suffix of template file (e.g. .tpl)
Type string

Name type
Description Subdirectory type to look in
Type string
Values restricted to templates css

Returns…

Description List of parameters needed for the _do_template function to be able to load the template (NULL: could not find the template)
Type ?array

Return to the function index for this class Expand: View the source code to this function

BINARY is_wide_high()

Find whether panels and the header/footer areas won't be shown.

Parameters…

Returns…

Description Result.
Type BINARY

Return to the function index for this class Expand: View the source code to this function

BINARY is_wide()

Find whether panels will be shown.

Parameters…

Returns…

Description Result.
Type BINARY

Return to the function index for this class Expand: View the source code to this function

integer ocp_mb_strlen(string in)

Get string length, with utf-8 awareness where possible/required.

Parameters…

Name in
Description The string to get the length of.
Type string

Returns…

Description The string length.
Type integer

Return to the function index for this class Expand: View the source code to this function

~string ocp_mb_substr(string in, integer from, ?integer amount, boolean force)

Return part of a string, with utf-8 awareness where possible/required.

Parameters…

Name in
Description The subject.
Type string

Name from
Description The start position.
Type integer

Name amount
Description The length to extract (NULL: all remaining).
Default value
Type ?integer

Name force
Description Whether to force unicode as on.
Default value boolean-false
Type boolean

Returns…

Description String part (false: $start was over the end of the string).
Type ~string

Return to the function index for this class Expand: View the source code to this function

string ocp_mb_strtolower(string in)

Make a string lowercase, with utf-8 awareness where possible/required.

Parameters…

Name in
Description Subject.
Type string

Returns…

Description Result.
Type string

Return to the function index for this class Expand: View the source code to this function

string ocp_mb_strtoupper(string in)

Make a string uppercase, with utf-8 awareness where possible/required.

Parameters…

Name in
Description Subject.
Type string

Returns…

Description Result.
Type string

Return to the function index for this class Expand: View the source code to this function

boolean is_writable_wrap(PATH path)

Find whether a file/directory is writeable. This function is designed to get past that the PHP is_writable function does not work properly on Windows.

Parameters…

Name path
Description The file path
Type PATH

Returns…

Description Whether the file is writeable
Type boolean

Return to the function index for this class Expand: View the source code to this function

void intelligent_write_error(PATH path)

Discern the cause of a file-write error, and show an appropriate error message.

Parameters…

Name path
Description File path that could not be written
Type PATH

(No return value)


Return to the function index for this class Expand: View the source code to this function

tempcode intelligent_write_error_inline(PATH path)

Discern the cause of a file-write error, and return an appropriate error message.

Parameters…

Name path
Description File path that could not be written
Type PATH

Returns…

Description Message
Type tempcode

Return to the function index for this class Expand: View the source code to this function

boolean fractional_edit()

Find whether a fractional edit is underway.

Parameters…

Returns…

Description Whether a fractional edit is underway
Type boolean

Return to the function index for this class Expand: View the source code to this function

integer strlen_sort(string a, string b)

Helper function for usort to sort a list by string length.

Parameters…

Name a
Description The first string to compare
Type string

Name b
Description The second string to compare
Type string

Returns…

Description The comparison result (0 for equal, -1 for less, 1 for more)
Type integer

Return to the function index for this class Expand: View the source code to this function

boolean has_no_forum()

Find whether we have no forum on this website.

Parameters…

Returns…

Description Whether we have no forum on this website
Type boolean

Return to the function index for this class Expand: View the source code to this function

boolean addon_installed(ID_TEXT addon)

Check to see if an addon is installed. This only works with addons written with addon_registry hooks, which is all the bundled ocPortal addons; it is unlikely to work with third-party addons.

Parameters…

Name addon
Description The module name
Type ID_TEXT

Returns…

Description Whether it is
Type boolean

Return to the function index for this class Expand: View the source code to this function

string float_to_raw_string(float num, integer decs_wanted, boolean only_needed_decs)

Convert a float to a "technical string representation of a float".

Parameters…

Name num
Description The number
Type float

Name decs_wanted
Description The number of decimals to keep
Default value 2
Type integer

Name only_needed_decs
Description Whether to trim trailing zeros
Default value boolean-false
Type boolean

Returns…

Description The string converted
Type string

Return to the function index for this class Expand: View the source code to this function

string float_format(float val, integer frac_digits)

Format the given float number as a nicely formatted string.

Parameters…

Name val
Description The value to format
Type float

Name frac_digits
Description The number of fractional digits
Default value 2
Type integer

Returns…

Description Nicely formatted string
Type string

Return to the function index for this class Expand: View the source code to this function

string integer_format(integer val)

Format the given integer number as a nicely formatted string.

Parameters…

Name val
Description The value to format
Type integer

Returns…

Description Nicely formatted string
Type string

Return to the function index for this class Expand: View the source code to this function

integer multi_sort(array a, array b)

Helper function to sort a list of maps by the value at $key in each of those maps.

Parameters…

Name a
Description The first to compare
Type array

Name b
Description The second to compare
Type array

Returns…

Description The comparison result (0 for equal, -1 for less, 1 for more)
Type integer

Return to the function index for this class Expand: View the source code to this function

void ocf_require_all_forum_stuff()

Require all code relating to the OCF forum

Parameters…

(No return value)


Return to the function index for this class Expand: View the source code to this function

tempcode globalise(tempcode middle, ?mixed message, string type, boolean include_header_and_footer)

Turn the tempcode lump into a standalone page (except for header/footer which is assumed already handled elsewhere).

Parameters…

Name middle
Description The tempcode to put into a nice frame
Type tempcode

Name message
Description 'Additional' message (NULL: none)
Default value
Type ?mixed

Name type
Description The type of special message
Default value
Type string
Values restricted to inform warn ""

Name include_header_and_footer
Description Whether to automatically include the header and footer templates
Default value boolean-false
Type boolean

Returns…

Description Standalone page
Type tempcode

Return to the function index for this class Expand: View the source code to this function

~string ocp_tempnam(string prefix)

Create file with unique file name, but works around compatibility issues between servers.

Parameters…

Name prefix
Description The prefix of the temporary file name.
Type string

Returns…

Description The name of the temporary file (false: error).
Type ~string

Return to the function index for this class Expand: View the source code to this function

object make_xhtml_strict(object global)

Take a Tempcode object and run some hackerish code to make it XHTML-strict.

Parameters…

Name global
Description Tempcode object
Type object

Returns…

Description Tempcode object (no longer cache safe)
Type object

Return to the function index for this class Expand: View the source code to this function

mixed array_peek(array array, integer depth_down)

Peek at a stack element.

Parameters…

Name array
Description The stack to peek in
Type array

Name depth_down
Description The depth into the stack we are peaking
Default value 1
Type integer

Returns…

Description The result of the peeking
Type mixed

Return to the function index for this class Expand: View the source code to this function

string fix_id(string param)

Make a value suitable for use in an XML ID.

Parameters…

Name param
Description The value to escape
Type string

Returns…

Description The escaped value
Type string

Return to the function index for this class Expand: View the source code to this function

boolean match_key_match(string match_tag, boolean support_post)

See if the current URL matches the given ocPortal match tags.

Parameters…

Name match_tag
Description Match tags
Type string

Name support_post
Description Check against POSTed data too
Default value boolean-false
Type boolean

Returns…

Description Whether there is a match
Type boolean

Return to the function index for this class Expand: View the source code to this function

ID_TEXT get_page_name()

Get the name of the current page

Parameters…

Returns…

Description The current page name
Type ID_TEXT

Return to the function index for this class Expand: View the source code to this function

array list_to_map(string map_value, array list)

Take a list of maps, and make one of the values of each array the index of a map to the map

Parameters…

Name map_value
Description The key key of our maps that reside in our map
Type string

Name list
Description The list of maps
Type array

Returns…

Description The collapsed map
Type array

Return to the function index for this class Expand: View the source code to this function

array collapse_2d_complexity(string key, string value, array list)

Take a list of maps of just two elements, and make it into a single map

Parameters…

Name key
Description The key key of our maps that reside in our map
Type string

Name value
Description The value key of our maps that reside in our map
Type string

Name list
Description The map of maps
Type array

Returns…

Description The collapsed map
Type array

Return to the function index for this class Expand: View the source code to this function

array collapse_1d_complexity(string key, array list)

Take a list of maps of just one element, and make it into a single map

Parameters…

Name key
Description The key of our maps that reside in our map
Type string

Name list
Description The map of maps
Type array

Returns…

Description The collapsed map
Type array

Return to the function index for this class Expand: View the source code to this function

string ocp_srv(string key)

Get server environment variables.

Parameters…

Name key
Description The variable name
Type string

Returns…

Description The variable value ('' means unknown)
Type string

Return to the function index for this class Expand: View the source code to this function

boolean is_valid_ip(IP ip)

Find whether an IP address is valid

Parameters…

Name ip
Description IP address to check.
Type IP

Returns…

Description Whether the IP address is valid.
Type boolean

Return to the function index for this class Expand: View the source code to this function

IP get_ip_address(integer amount)

Attempt to get the IP address of the current user

Parameters…

Name amount
Description The number of groups to include in the IP address (rest will be replaced with *'s). For IP6, this is doubled.
Default value 4
Type integer
Values restricted to 1 2 3 4

Returns…

Description The users IP address (blank: could not find a valid one)
Type IP

Return to the function index for this class Expand: View the source code to this function

string get_browser_string()

Get a string of the users web browser

Parameters…

Returns…

Description The web browser string
Type string

Return to the function index for this class Expand: View the source code to this function

string get_os_string()

Get the user's operating system

Parameters…

Returns…

Description The operating system string
Type string

Return to the function index for this class Expand: View the source code to this function

boolean cron_installed()

Find if Cron is installed

Parameters…

Returns…

Description Whether Cron is installed
Type boolean

Return to the function index for this class Expand: View the source code to this function

?string geolocate_ip(?IP ip)

Find the country an IP address long is located in

Parameters…

Name ip
Description The IP to geolocate (NULL: current user's IP)
Default value
Type ?IP

Returns…

Description The country initials (NULL: unknown)
Type ?string

Return to the function index for this class Expand: View the source code to this function

boolean compare_ip_address(string wild, IP full)

Compare two IP addresses for potential correlation. Not as simple as equality due to '*' syntax.

Parameters…

Name wild
Description The general IP address that is potentially wildcarded
Type string

Name full
Description The specific IP address we are checking
Type IP

Returns…

Description Whether the IP addresses correlate
Type boolean

Return to the function index for this class Expand: View the source code to this function

boolean compare_ip_address_ip4(string wild, array full_parts)

Compare two IP addresses for potential correlation. Not as simple as equality due to '*' syntax. IP4-only variant

Parameters…

Name wild
Description The general IP address that is potentially wildcarded
Type string

Name full_parts
Description The exploded parts of the specific IP address we are checking
Type array

Returns…

Description Whether the IP addresses correlate
Type boolean

Return to the function index for this class Expand: View the source code to this function

boolean compare_ip_address_ip6(string wild, array full_parts)

Compare two IP addresses for potential correlation. Not as simple as equality due to '*' syntax. IP6-only variant

Parameters…

Name wild
Description The general IP address that is potentially wildcarded
Type string

Name full_parts
Description The exploded parts of the specific IP address we are checking
Type array

Returns…

Description Whether the IP addresses correlate
Type boolean

Return to the function index for this class Expand: View the source code to this function

tempcode get_flagrant()

Get the XHTML for the flagrant text message.

Parameters…

Returns…

Description The flagrant text message
Type tempcode

Return to the function index for this class Expand: View the source code to this function

void log_it(ID_TEXT type, ?SHORT_TEXT a, ?SHORT_TEXT b)

Log an action

Parameters…

Name type
Description The type of activity just carried out (a lang string)
Type ID_TEXT

Name a
Description The most important parameter of the activity (e.g. id) (NULL: none)
Default value
Type ?SHORT_TEXT

Name b
Description A secondary (perhaps, human readable) parameter of the activity (e.g. caption) (NULL: none)
Default value
Type ?SHORT_TEXT

(No return value)


Return to the function index for this class Expand: View the source code to this function

void syndicate_described_activity(string a_language_string_code, string a_label_1, string a_label_2, string a_label_3, string a_pagelink_1, string a_pagelink_2, string a_pagelink_3, string a_addon, BINARY a_is_public, ?MEMBER a_member_id, boolean sitewide_too, ?MEMBER also_involving)

Syndicate human-intended descriptions of activities performed to the internal wall, and external listeners.

Parameters…

Name a_language_string_code
Description Language string code
Default value
Type string

Name a_label_1
Description Label 1 (given as a parameter to the language string code)
Default value
Type string

Name a_label_2
Description Label 2 (given as a parameter to the language string code)
Default value
Type string

Name a_label_3
Description Label 3 (given as a parameter to the language string code)
Default value
Type string

Name a_pagelink_1
Description Page link 1
Default value
Type string

Name a_pagelink_2
Description Page link 2
Default value
Type string

Name a_pagelink_3
Description Page link 3
Default value
Type string

Name a_addon
Description Addon that caused the event
Default value
Type string

Name a_is_public
Description Whether this post should be public or friends-only
Default value 1
Type BINARY

Name a_member_id
Description Member being written for (NULL: current member)
Default value
Type ?MEMBER

Name sitewide_too
Description Whether to push this out as a site event if user requested
Default value boolean-false
Type boolean

Name also_involving
Description Member also 'intimately' involved, such as a content submitter who is a friend (NULL: none)
Default value
Type ?MEMBER

(No return value)


Return to the function index for this class Expand: View the source code to this function

boolean has_external_site_wide_syndication()

Detect whether we have external site-wide syndication support somewhere.

Parameters…

Returns…

Description Whether we do
Type boolean

Return to the function index for this class Expand: View the source code to this function

tempcode get_syndication_option_fields()

Get syndication field UI.

Parameters…

Returns…

Description Syndication fields (or empty)
Type tempcode

Return to the function index for this class Expand: View the source code to this function

string php_addslashes(string in)

Escape a string to fit within PHP double quotes.

Parameters…

Name in
Description String in
Type string

Returns…

Description Resultant string
Type string

Return to the function index for this class Expand: View the source code to this function

array remove_duplicate_rows(array rows, string id_field)

Remove any duplication inside the list of rows (each row being a map). Duplication is defined by rows with correspinding IDs.

Parameters…

Name rows
Description The rows to remove duplication of
Type array

Name id_field
Description The ID field
Default value id
Type string

Returns…

Description The filtered rows
Type array

Return to the function index for this class Expand: View the source code to this function

void member_tracking_update()

Update the member tracker for the currently viewing user.

Parameters…

(No return value)


Return to the function index for this class Expand: View the source code to this function

?array get_members_viewing(?ID_TEXT page, ?ID_TEXT type, ?SHORT_TEXT id, boolean forum_layer)

Get a map of members viewing the specified ocPortal location.

Parameters…

Name page
Description The page they need to be viewing (NULL: don't care)
Default value
Type ?ID_TEXT

Name type
Description The page-type they need to be viewing (NULL: don't care)
Default value
Type ?ID_TEXT

Name id
Description The type-id they need to be viewing (NULL: don't care)
Default value
Type ?SHORT_TEXT

Name forum_layer
Description Whether this has to be done over the forum driver (multi site network)
Default value boolean-false
Type boolean

Returns…

Description A map of member-ids to rows about them (NULL: Too many)
Type ?array

Return to the function index for this class Expand: View the source code to this function

boolean is_invisible()

Find whether the current user is invisible.

Parameters…

Returns…

Description Whether the current user is invisible
Type boolean

Return to the function index for this class Expand: View the source code to this function

integer get_num_users_site()

Get the number of users on the site in the last 5 minutes. The function also maintains the statistic via the sessions table.

Parameters…

Returns…

Description The number of users on the site
Type integer

Return to the function index for this class Expand: View the source code to this function

integer get_num_users_peak()

Get the largest amount of users ever to be on the site at the same time.

Parameters…

Returns…

Description The number of peak users
Type integer

Return to the function index for this class Expand: View the source code to this function

string escape_html(mixed string)

Get the specified string, but with all characters escaped.

Parameters…

Name string
Description The input string
Type mixed

Returns…

Description The escaped string
Type string

Return to the function index for this class Expand: View the source code to this function

URLPATH brand_base_url()

Find the base URL for documentation.

Parameters…

Returns…

Description The base URL for documentation
Type URLPATH

Return to the function index for this class Expand: View the source code to this function

boolean browser_matches(string code)

See's if the current browser matches some special property code. Assumes users are keeping up on newish browsers (except for IE users, who are 6+)

Parameters…

Name code
Description The property code
Type string
Values restricted to android ios wysiwyg windows mac linux odd_os mobile opera ie_decent ie_new ie ie_old gecko konqueror safari odd_browser has_artificial_monopoly has_fanboys quirk__internalised_list_indent quirk__quirk__list_indent_in_ul_instead_of_li chrome ie5 ie6 ie7+ ie8+ ie9+

Returns…

Description Whether there is a match
Type boolean

Return to the function index for this class Expand: View the source code to this function

boolean is_mobile(?string user_agent, boolean truth)

Look at the user's browser, and decide if they are viewing on a mobile device or not.

Parameters…

Name user_agent
Description The user agent (NULL: get from environment, current user's browser)
Default value
Type ?string

Name truth
Description Whether to always tell the truth (even if the current page does not have mobile support)
Default value boolean-false
Type boolean

Returns…

Description Whether the user is using a mobile device
Type boolean

Return to the function index for this class Expand: View the source code to this function

?string get_bot_type()

Get the name of a webcrawler bot, or NULL if no bot detected

Parameters…

Returns…

Description Webcrawling bot name (NULL: not a bot)
Type ?string

Return to the function index for this class Expand: View the source code to this function

SHORT_TEXT read_multi_code(ID_TEXT param)

Read a multi code from a named parameter stub.

Parameters…

Name param
Description The parameter stub (stub of a series of POST parameters, made by ocf_get_forum_multi_code_field's field or similar).
Type ID_TEXT

Returns…

Description The multi code.
Type SHORT_TEXT

Return to the function index for this class Expand: View the source code to this function

string flatten_slashed_array(array array)

Turn an array into a humanely readable string.

Parameters…

Name array
Description Array to convert
Type array

Returns…

Description A humanely readable version of the array.
Type string

Return to the function index for this class Expand: View the source code to this function

string wordfilter_text(string text)

Get a word-filtered version of the specified text.

Parameters…

Name text
Description Text to filter
Type string

Returns…

Description Filtered version of the input text
Type string

Return to the function index for this class Expand: View the source code to this function

string xmlentities(string string, integer quote_style)

XML escape the input string.

Parameters…

Name string
Description Input string
Type string

Name quote_style
Description Quote style
Default value 2
Type integer

Returns…

Description Escaped version of input string
Type string

Return to the function index for this class Expand: View the source code to this function

boolean has_cookies()

Determine whether the user's browser supports cookies or not.Unfortunately this function will only return true once a user has been to the site more than once… ocPortal will set a cookie, and if it perseveres, that indicates cookies work.

Parameters…

Returns…

Description Whether the user has definitely got cookies
Type boolean

Return to the function index for this class Expand: View the source code to this function

boolean has_js()

Determine whether the user's browser supports JavaScript or not.Unfortunately this function will only return true once a user has been to the site more than once… Javascript will set a cookie, indicating it works.

Parameters…

Returns…

Description Whether the user has definitely got Javascript
Type boolean

Return to the function index for this class Expand: View the source code to this function

string get_rand_password()

Get a randomised password.

Parameters…

Returns…

Description The randomised password
Type string

Return to the function index for this class Expand: View the source code to this function

?mixed mixed()

Assign this to explicitly declare that a variable may be of mixed type, and initialise to NULL.

Parameters…

Returns…

Description Of mixed type (NULL: default)
Type ?mixed

Return to the function index for this class Expand: View the source code to this function

array seo_meta_get_for(ID_TEXT type, ID_TEXT id)

Get meta information for specified resource

Parameters…

Name type
Description The type of resource (e.g. download)
Type ID_TEXT

Name id
Description The ID of the resource
Type ID_TEXT

Returns…

Description The first element is the meta keyword string for the specified resource, and the other is the meta description string.
Type array

Return to the function index for this class Expand: View the source code to this function

void seo_meta_load_for(ID_TEXT type, ID_TEXT id, ?string title)

Load the specified resource's meta information into the system for use on this page.Also, if the title is specified then this is used for the page title.

Parameters…

Name type
Description The type of resource (e.g. download)
Type ID_TEXT

Name id
Description The ID of the resource
Type ID_TEXT

Name title
Description The page-specific title to use, in Comcode or plain-text format with possible HTML entities included [Comcode will later be stripped] (NULL: none)
Default value
Type ?string

(No return value)


Return to the function index for this class Expand: View the source code to this function

tempcode get_loaded_tags(?ID_TEXT limit_to, ?array the_tags)

Get Tempcode for tags, based on loaded up from SEO keywords (seo_meta_load_for).

Parameters…

Name limit_to
Description The search code for this tag content (e.g. downloads) (NULL: there is none)
Default value
Type ?ID_TEXT

Name the_tags
Description Explicitly pass a list of tags instead (NULL: use loaded ones)
Default value
Type ?array

Returns…

Description Loaded tag output (or blank if there are none)
Type tempcode

Return to the function index for this class Expand: View the source code to this function

ID_TEXT get_zone_default_page(ID_TEXT zone_name)

Get the default page for a zone.

Parameters…

Name zone_name
Description Zone name
Type ID_TEXT

Returns…

Description Default page
Type ID_TEXT

Return to the function index for this class Expand: View the source code to this function

SHORT_TEXT best_hash(SHORT_TEXT to_hash, SHORT_TEXT salt)

Hash something as well as possible. Only use this function if the hash is for short-term use, because long-term we don't know if the best hash function will change or not.

Parameters…

Name to_hash
Description What to hash
Type SHORT_TEXT

Name salt
Description Salt
Type SHORT_TEXT

Returns…

Description Hashed result
Type SHORT_TEXT

Return to the function index for this class Expand: View the source code to this function

boolean check_master_password(SHORT_TEXT password_given)

Check the given master password is valid.

Parameters…

Name password_given
Description Given master password
Type SHORT_TEXT

Returns…

Description Whether it is valid
Type boolean

Return to the function index for this class Expand: View the source code to this function

ID_TEXT produce_salt()

Get a decent randomised salt.

Parameters…

Returns…

Description The salt
Type ID_TEXT

Return to the function index for this class Expand: View the source code to this function

ID_TEXT get_site_salt()

Get the site-wide salt. It should be something hard for a hacker to get, so we depend on data gathered both from the database and file-system.

Parameters…

Returns…

Description The salt
Type ID_TEXT

Return to the function index for this class Expand: View the source code to this function

string titleify(ID_TEXT boring)

Turn a boring codename, into a "pretty" title.

Parameters…

Name boring
Description The codename
Type ID_TEXT

Returns…

Description The title
Type string

Return to the function index for this class Expand: View the source code to this function

sources/files.php

Global_functions_files.php

Function summary

void init__files ()
boolean is_suexec_like ()
integer php_return_bytes (string val)
string get_file_size (URLPATH url)
string clean_file_size (integer bytes)
string get_file_extension (string name)
array better_parse_ini_file (?PATH filename, ?string file)
boolean should_ignore_file (string filepath, integer bitmask)
void deldir_contents (PATH dir, boolean default_preserve, boolean just_files)
void fix_permissions (PATH path, integer perms)
?string http_download_file (URLPATH url, ?integer byte_limit, boolean trigger_error, boolean no_redirect, string ua, ?array post_params, ?array cookies, ?string accept, ?string accept_charset, ?string accept_language, ?resource write_to_file, ?string referer, ?array auth, float timeout, boolean is_xml, ?array files)

void init__files()

Standard code module initialisation function.

Parameters…

(No return value)


Return to the function index for this class Expand: View the source code to this function

boolean is_suexec_like()

Find whether we can get away with natural file access, not messing with AFMs, world-writability, etc.

Parameters…

Returns…

Description Whether we have this
Type boolean

Return to the function index for this class Expand: View the source code to this function

integer php_return_bytes(string val)

Get the number of bytes for a PHP config option. Code taken from the PHP manual.

Parameters…

Name val
Description PHP config option value.
Type string

Returns…

Description Number of bytes.
Type integer

Return to the function index for this class Expand: View the source code to this function

string get_file_size(URLPATH url)

Get a formatted-string filesize for the specified file. It is formatted as such: x Mb/Kb/Bytes (or unknown). It is assumed that the file exists.

Parameters…

Name url
Description The URL that the file size of is being worked out for. Should be local.
Type URLPATH

Returns…

Description The formatted-string file size
Type string

Return to the function index for this class Expand: View the source code to this function

string clean_file_size(integer bytes)

Format the specified filesize.

Parameters…

Name bytes
Description The number of bytes the file has
Type integer

Returns…

Description The formatted-string file size
Type string

Return to the function index for this class Expand: View the source code to this function

string get_file_extension(string name)

Get the file extension of the specified file. It returns without a dot.

Parameters…

Name name
Description The filename
Type string

Returns…

Description The filename extension (no dot)
Type string

Return to the function index for this class Expand: View the source code to this function

array better_parse_ini_file(?PATH filename, ?string file)

Parse the specified INI file, and get an array of what it found.

Parameters…

Name filename
Description The path to the ini file to open (NULL: given contents in $file instead)
Type ?PATH

Name file
Description The contents of the file (NULL: the file needs opening)
Default value
Type ?string

Returns…

Description A map of the contents of the ini files
Type array

Return to the function index for this class Expand: View the source code to this function

boolean should_ignore_file(string filepath, integer bitmask)

Find whether a file is known to be something that should/could be there but isn't an ocPortal distribution file, or for some other reason should be ignored.

Parameters…

Name filepath
Description File path
Type string

Name bitmask
Description Bitmask of extra stuff to ignore (see IGNORE_* constants)
Default value 0
Type integer

Returns…

Description Whether it should be ignored
Type boolean

Return to the function index for this class Expand: View the source code to this function

void deldir_contents(PATH dir, boolean default_preserve, boolean just_files)

Delete all the contents of a directory, and any subdirectories of that specified directory (recursively).

Parameters…

Name dir
Description The pathname to the directory to delete
Type PATH

Name default_preserve
Description Whether to preserve files there by default
Default value boolean-false
Type boolean

Name just_files
Description Whether to just delete files
Default value boolean-false
Type boolean

(No return value)


Return to the function index for this class Expand: View the source code to this function

void fix_permissions(PATH path, integer perms)

Ensure that the specified file/folder is writeable for the FTP user (so that it can be deleted by the system), and should be called whenever a file is uploaded/created, or a folder is made. We call this function assuming we are giving world permissions

Parameters…

Name path
Description The full pathname to the file/directory
Type PATH

Name perms
Description The permissions to make (not the permissions are reduced if the function finds that the file is owned by the web user [doesn't need world permissions then])
Default value 438
Type integer

(No return value)


Return to the function index for this class Expand: View the source code to this function

?string http_download_file(URLPATH url, ?integer byte_limit, boolean trigger_error, boolean no_redirect, string ua, ?array post_params, ?array cookies, ?string accept, ?string accept_charset, ?string accept_language, ?resource write_to_file, ?string referer, ?array auth, float timeout, boolean is_xml, ?array files)

Return the file in the URL by downloading it over HTTP. If a byte limit is given, it will only download that many bytes. It outputs warnings, returning NULL, on error.

Parameters…

Name url
Description The URL to download
Type URLPATH

Name byte_limit
Description The number of bytes to download. This is not a guarantee, it is a minimum (NULL: all bytes)
Default value
Type ?integer
Value range 1 max

Name trigger_error
Description Whether to throw an ocPortal error, on error
Default value boolean-true
Type boolean

Name no_redirect
Description Whether to block redirects (returns NULL when found)
Default value boolean-false
Type boolean

Name ua
Description The user-agent to identify as
Default value ocPortal
Type string

Name post_params
Description An optional array of POST parameters to send; if this is NULL, a GET request is used (NULL: none)
Default value
Type ?array

Name cookies
Description An optional array of cookies to send (NULL: none)
Default value
Type ?array

Name accept
Description 'accept' header value (NULL: don't pass one)
Default value
Type ?string

Name accept_charset
Description 'accept-charset' header value (NULL: don't pass one)
Default value
Type ?string

Name accept_language
Description 'accept-language' header value (NULL: don't pass one)
Default value
Type ?string

Name write_to_file
Description File handle to write to (NULL: do not do that)
Default value
Type ?resource

Name referer
Description The HTTP referer (NULL: none)
Default value
Type ?string

Name auth
Description A pair: authentication username and password (NULL: none)
Default value
Type ?array

Name timeout
Description The timeout
Default value 6
Type float

Name is_xml
Description Whether to treat the POST parameters as a raw POST (rather than using MIME)
Default value boolean-false
Type boolean

Name files
Description Files to send. Map between field to file path (NULL: none)
Default value
Type ?array

Returns…

Description The data downloaded (NULL: error)
Type ?string

Return to the function index for this class Expand: View the source code to this function