resource_functions.php
Table of Contents
Functions
- get_resource_path() : string
- Get resource path / resource URL / download URL for this resource
- get_resource_data() : mixed
- get_resource_data_batch() : array<string|int, mixed>
- get_resource_data_batch - get data from resource table for all resource IDs
- put_resource_data() : bool
- Updates $resource with the name/value pairs in $data - this relates to the resource table column, not metadata.
- create_resource() : mixed
- create_resource
- update_hitcount() : mixed
- save_resource_data() : true|array<string|int, mixed>
- Save resource data
- set_resource_defaults() : bool
- Set resource defaults. Optional, a list of field IDs can be passed on to only update certain fields.
- save_resource_data_multi() : true|array<string|int, mixed>
- Batch save resources in a collection
- update_field() : bool
- Updates resource field. Works out the previous value, so this is not efficient if we already know what this previous value is (hence it is not used for edit where multiple fields are saved)
- email_resource() : mixed
- delete_resource() : mixed
- get_resource_type_field() : bool|array<string|int, mixed>
- Returns field data from resource_type_field for the given field
- get_resource_field_data() : array<string|int, mixed>|bool
- get_resource_field_data
- get_resource_field_data_batch() : array<string|int, mixed>
- get_resource_field_data_batch - Get all resource data for the given resources
- get_resource_types() : array<string|int, mixed>
- Return an array of resource types that this user has access to
- get_all_resource_types() : array<string|int, mixed>
- Returns all resources types
- clear_resource_data() : mixed
- copy_resource() : bool|int
- Create a new resource, copying all data from the resource with reference $from.
- resource_log() : int
- Log resource activity
- get_resource_log() : array<string|int, mixed>
- Get resource log records. The standard field titles are translated using $lang. Custom field titles are i18n translated.
- get_resource_type_name() : mixed
- get_resource_custom_access() : mixed
- get_resource_custom_access_users_usergroups() : array<string|int, mixed>
- Retrieves custom access settings for users and user groups associated with a specific resource.
- save_resource_custom_access() : void
- Saves custom access settings for a specific resource.
- get_custom_access() : mixed
- Lookup custom access value for a resource
- get_themes_by_resource() : array<string|int, mixed>
- Determine the featured collections and public collections a resource is associated with.
- update_resource_type() : mixed
- get_exiftool_fields() : array<string|int, mixed>
- Returns a list of exiftool fields, which are basically fields with an 'exiftool field' set.
- createTempFile() : bool|string
- Create a temporary copy of the file in the tmp folder (ie. the usual filestore/tmp/)
- stripMetadata() : bool|string
- Strips metadata from file
- write_metadata() : string|bool
- Writes metadata to a specified file using ExifTool.
- delete_exif_tmpfile() : mixed
- Delete Exif temp file
- update_resource() : int|bool
- Updates a resource with a new file and its associated metadata.
- import_resource() : int|bool
- Imports a resource from the specified path and updates its details.
- get_alternative_files() : array<string|int, mixed>|bool
- Retrieves alternative files associated with a specified resource.
- get_alternative_files_by_filename() : array<string|int, mixed>
- Search the alternative file records for matching filenames Alternative files can be optionally filtered by the Resource ID or by collection
- add_alternative_file() : int
- Add alternative file
- delete_alternative_file() : bool
- delete_alternative_file
- get_alternative_file() : array<string|int, mixed>|bool
- Retrieves a specific alternative file associated with a given resource.
- save_alternative_file() : void
- Updates the details of an alternative file in the database.
- user_rating_save() : void
- Saves a user rating for a given resource.
- get_field() : bool|array<string|int, mixed>
- A standard field title is translated using $lang. A custom field title is i18n translated.
- get_keyword_from_option() : string
- Retrieves the keyword that will be indexed for a given field option.
- get_resource_access() : int
- Retrieves the access level for the currently logged-in user for a specified resource.
- get_custom_access_user() : mixed
- Retrieves the custom access level for a specific user on a given resource.
- edit_resource_external_access() : bool
- Edits the external access settings for a given resource.
- resource_download_allowed() : bool
- For the given resource and size, can the current user download it? resource type and access may already be available in the case of search, so pass them along to get_resource_access to avoid extra queries $resource can be a resource-specific search result array.
- get_edit_access() : bool
- Check if current user has edit access to a resource. Checks the edit permissions (e0, e-1 etc.) and also the group edit filter which filters edit access based on resource metadata.
- filter_match() : int
- In the given filter string, does name/value match? Returns: 0 = no match for name 1 = matched name but value was not present 2 = matched name and value was correct
- log_diff() : string
- Check changes made to a metadata field and create a nice user friendly summary
- get_metadata_templates() : array<string|int, mixed>
- Retrieves a list of all metadata templates for a specified resource type.
- get_resource_collections() : array<string|int, mixed>
- Retrieves a list of collections that a resource is used in for the specified resource reference.
- download_summary() : array<string|int, mixed>
- Retrieves a summary of downloads for a given resource, categorized by usage type.
- check_use_watermark() : mixed
- autocomplete_blank_fields() : bool|array<string|int, mixed>
- Fill in any blank fields for the resource.
- get_page_count() : mixed
- update_disk_usage() : bool
- Updates the disk usage for a specified resource by calculating the total size of the files in the resource's directory and storing the result in the resource table.
- update_disk_usage_cron() : bool|void
- Update disk usage for all resources that have not yet been updated or have not been updated in the past 30 days.
- get_total_disk_usage() : int
- Returns the total disk space used by all resources on the system
- overquota() : array<string|int, mixed>|bool
- Calculate if the quota set by $disksize in the configuration has been exceeded.
- get_original_imagesize() : array<string|int, mixed>|bool
- Get size of specified image file
- generate_resource_access_key() : string|bool
- Generates an external access key for a resource, allowing specified access to a user or group.
- get_resource_external_access() : array<string|int, mixed>
- Retrieves all external access keys granted for a specific resource.
- delete_resource_access_key() : mixed
- resource_type_config_override() : mixed
- update_archive_status() : void
- Update the archive state of resource(s) and log this
- delete_resources_in_collection() : mixed
- update_related_resource() : bool
- Update related resources - add new related resource(s) or delete existing
- can_share_resource() : bool
- Check if sharing of resource is permitted
- delete_resource_custom_access_usergroups() : mixed
- Delete all usergroup specific access to resource $ref
- truncate_join_field_value() : string
- Truncate the field for insertion into the main resource table field
- get_video_snapshots() : array<string|int, mixed>|int
- Check whether a resource (of a video type) has any snapshots created.
- resource_file_readonly() : bool
- Check if resource file is read-only because it's part of the filestore template threshold
- delete_resource_custom_user_access() : mixed
- get_video_info() : mixed
- copyAllDataToResource() : bool
- Provides the ability to copy any metadata field data from one resource to another.
- copy_locked_data() : array<string|int, mixed>
- Update resource data for 'locked' fields from last edited resource. Used for upload_then_edit
- copy_locked_fields() : void
- Update resource metadata for 'locked' fields from last edited resource.
- copyRelatedResources() : void
- Copy related resources from one resource to another
- process_edit_form() : mixed
- update_timestamp() : mixed
- get_extension() : string
- Get resource file extension from the database or use JPG, for download
- get_last_resource_edit_array() : array<string|int, mixed>|false
- Obtain details of the last resource edited in the given array of resource ids
- get_default_archive_state() : int
- Get the default archive state for new resources
- save_original_file_as_alternative() : bool|int
- Save the original file being replaced, as an alternative file
- replace_resource_file() : bool
- Replace the primary resource file with the file located at the path specified
- get_resource_all_image_sizes() : array<string|int, mixed>
- Return all sizes available for a specific resource. Multi page resources should have each page size included as well in the output.
- sanitize_date_field_input() : mixed
- download_link_generate_key() : string
- Create a temporary download key for a specific user or key and resource combination Used when both $watermark_open and $terms_download are enabled
- download_link_check_key() : string
- Check the download key for a specific user/resource combination
- filter_check() : bool
- Check if a given set of nodes meets the conditions set for the provided filter NOte that all resource_nodes for a resource should be passed to check if a filter is matched
- update_node_hitcount_from_search() : mixed
- copy_hitcount_to_live() : mixed
- get_image_sizes() : array<string|int, mixed>
- Returns a table of available image sizes for resource $ref. The standard image sizes are translated using $lang. Custom image sizes are i18n translated.
- get_related_resources() : array<string|int, mixed>
- Return an array of resource references that are related to resource $ref
- get_field_options() : array<string|int, mixed>|bool
- Get available options for fixed list field types
- get_data_by_field() : string|array<string|int, mixed>|Generator
- Get the resource data value for a field and a specific resource or get the specified field for all resources in the system
- get_all_image_sizes() : mixed
- image_size_restricted_access() : mixed
- get_fields() : array<string|int, mixed>
- Returns a list of fields with refs matching the supplied field refs.
- get_hidden_indexed_fields() : mixed
- get_OR_fields() : mixed
- get_nopreview_html() : string
- Returns the HTML necessary to represent a resource with the given extension when no image preview exists.
- get_resource_type_fields() : array<string|int, mixed>
- Gets all metadata fields, optionally for a specified array of resource types
- notify_resource_change() : mixed
- add_verbatim_keywords() : mixed
- metadata_field_edit_access() : bool
- Check the current user's edit access to given metadata field ID
- get_download_filename() : string
- Work out the filename to use, based on the download_filename_format configuration option, when downloading the specified resource file with the given settings
- get_resource_type_from_extension() : int
- Get resource type ID based on extension $mappings = array(resource_type_id => array(allowed_extensions));
- canSeePreviewTools() : bool
- Helper function for Preview tools feature. Checks all necessary permissions or options in order to tell the system whether PreviewTools panel should be displayed
- canSeeAnnotationsFields() : array<string|int, mixed>
- Helper function to determine if annotations are to be displayed.
- alt_is_ffmpeg_alternative() : bool
- Determine if a video alternative was created from $ffmpeg_alternatives settings.
- create_resource_type_field() : bool|int
- Create a new resource type field with the specified name of the required type
- metadata_field_view_access() : bool
- Check if user has view access to metadata field
- get_workflow_states() : array<string|int, mixed>
- Utility to get all workflow states available in the system.
- get_workflow_state_names() : array<string|int, mixed>
- delete_resource_type_field() : bool|string
- Delete the specified metadata field. Also delets any node or resource_data rows associated with that field
- get_resource_table_joins() : mixed
- update_resource_lock() : mixed
- get_resource_lock_message() : mixed
- get_external_shares() : array<string|int, mixed>
- Get details of external shares
- get_video_duration() : float
- Get video duration
- relate_all_resources() : bool
- Relate all resources in the passed array with each other
- update_resource_type_field_order() : void
- Apply new order to metadata fields
- update_resource_type_order() : void
- Apply a new order to resource types
- allow_in_browser() : bool
- Check if file can be rendered in browser via download.php
- update_resource_field_column() : bool
- Update the value of the fieldXX field on resource table
- data_joins_field_value_translate_and_csv() : string|null
- Convert $data_joins (ie fieldX column) value to a user friendly version.
- process_resource_data_joins_values() : array<string|int, mixed>
- Process resource data_joins (ie fieldX columns) values
- resource_has_access_denied_by_RT_size() : bool
- Check if resource has access denied by its type and for a size.
- revert_resource_file() : bool
- Revert primary resource file based on log entry data
- apply_resource_default() : void
- When changing resource type, new resource type specific fields may become available. This function will apply any resource default values for resource type specific fields that were not previously available (i.e. not containing user data). This is used by upload then edit mode after switching resource types and also when locking the resource type with save and next.
- related_resource_pull() : array<string|int, mixed>|bool
- Get a related resource to pull images from
- get_resource_preview() : array<string|int, mixed>|bool
- Get the largest available preview URL for the given resource and the given array of sizes
- check_resources() : array<string|int, mixed>
- Check integrity of primary resource files
- get_resources_to_validate() : array<string|int, mixed>
- Get an array of all resources that require files to be validated
- acl_can_edit_resource_of_type() : bool
- Access control check that user can edit (a resource) of a particular Resource Type (RT). Main use is to hide inapplicable RTs.
- can_upload_preview_image() : bool
- Check if current user can upload a preview image
- resource_has_preview_source() : bool
- Check if a resource has a file to derive previews from.
- acl_can_edit_contributed_by() : bool
- Access control check that user can edit a resources 'Contributed by' field
Functions
get_resource_path()
Get resource path / resource URL / download URL for this resource
get_resource_path(int $ref, bool $getfilepath[, string|null $size = '' ][, bool $generate = true ][, string|null $extension = 'jpg' ][, bool $scramble = true ][, int $page = 1 ][, bool $watermarked = false ][, string|null $file_modified = '' ][, int $alternative = -1 ][, bool $includemodified = true ]) : string
IMPORTANT: the download URL should always be used client side (public) whilst filstore path is private for internal use only
Parameters
- $ref : int
-
Resource ID
- $getfilepath : bool
-
Set to TRUE to get the filestore (physical) path
- $size : string|null = ''
-
Specify which size of the resource should be returned. Use '' for original file
- $generate : bool = true
-
Generate folder if not found
- $extension : string|null = 'jpg'
-
Extension of the file we are looking for. For original file, this would be the file extension, otherwise use the preview extension (e.g image preview will have JPG while video preview can have MP4 or others)
- $scramble : bool = true
-
Set to TRUE to get the scrambled folder (requires scramble key for it to work)
- $page : int = 1
-
For documents, use the page number we are trying to get the preview of.
- $watermarked : bool = false
-
Get the watermark version?
- $file_modified : string|null = ''
-
Specify when the file was last modified as a Unix timestamp
- $alternative : int = -1
-
ID of the alternative file
- $includemodified : bool = true
-
Show when the file was last modified
Tags
Return values
string —resource path / resource URL / download URL
get_resource_data()
get_resource_data(mixed $ref[, mixed $cache = true ]) : mixed
Parameters
- $ref : mixed
- $cache : mixed = true
Tags
get_resource_data_batch()
get_resource_data_batch - get data from resource table for all resource IDs
get_resource_data_batch(mixed $refs) : array<string|int, mixed>
Parameters
- $refs : mixed
-
- array of resource IDs
Return values
array<string|int, mixed>put_resource_data()
Updates $resource with the name/value pairs in $data - this relates to the resource table column, not metadata.
put_resource_data(int $resource, array<string|int, mixed> $data) : bool
Parameters
- $resource : int
-
ID of resource
- $data : array<string|int, mixed>
-
Array of data to be applied to resource
Return values
boolcreate_resource()
create_resource
create_resource(int $resource_type[, int $archive = 999 ][, int $user = -1 ][, string $origin = '' ][, string $file_extension = '' ][, bool $run_macro = true ]) : mixed
Parameters
- $resource_type : int
-
ID of target resource type
- $archive : int = 999
-
ID of target archive state, 999 if archived
- $user : int = -1
-
User ID, -1 for current user
- $origin : string = ''
-
Source of resource, should not be blank
- $file_extension : string = ''
-
If specified
- $run_macro : bool = true
-
Run autocomplete macros, can be disabled if they are run later in process
Return values
mixed —false if invalid inputs given, integer of resource reference if resource is created
update_hitcount()
update_hitcount(mixed $ref) : mixed
Parameters
- $ref : mixed
save_resource_data()
Save resource data
save_resource_data(int $ref, bool $multi[, string|int $autosave_field = "" ]) : true|array<string|int, mixed>
IMPORTANT: inactive nodes should be left alone (don't add/remove) except when processing fixed list field types that only hold one value (dropdown, radio). Plugins should determine this based on their use cases when hooking.
Parameters
- $ref : int
- $multi : bool
- $autosave_field : string|int = ""
Return values
true|array<string|int, mixed> —List of errors if unsuccessful, true otherwise
set_resource_defaults()
Set resource defaults. Optional, a list of field IDs can be passed on to only update certain fields.
set_resource_defaults(int $ref[, array<string|int, mixed> $specific_fields = array() ]) : bool
IMPORTANT: this function will always set the resource defaults if any are found. The "client code" is where developers decide whether this should happen
Parameters
- $ref : int
-
Resource ID
- $specific_fields : array<string|int, mixed> = array()
-
Specific field ID(s) to update
Return values
boolsave_resource_data_multi()
Batch save resources in a collection
save_resource_data_multi(int $collection[, array<string|int, mixed> $editsearch = array() ][, array<string|int, mixed> $postvals = [] ]) : true|array<string|int, mixed>
IMPORTANT: inactive nodes should be left alone (don't add/remove) except when processing fixed list field types that only hold one value (dropdown, radio). Plugins should determine this based on their use cases when hooking.
Parameters
- $collection : int
- $editsearch : array<string|int, mixed> = array()
- $postvals : array<string|int, mixed> = []
Return values
true|array<string|int, mixed> —List of errors if unsuccessful, true otherwise
update_field()
Updates resource field. Works out the previous value, so this is not efficient if we already know what this previous value is (hence it is not used for edit where multiple fields are saved)
update_field(int $resource, int $field, string $value[, array<string|int, mixed> &$errors = array() ][, bool $log = true ][, bool $nodevalues = false ]) : bool
Parameters
- $resource : int
-
Resource ID
- $field : int
-
Field ID
- $value : string
-
The new value
- $errors : array<string|int, mixed> = array()
-
Any errors that may occur during update
- $log : bool = true
-
Log this change in the resource log?
- $nodevalues : bool = false
-
Set to TRUE to process the value as a comma separated list of node IDs
Tags
Return values
boolemail_resource()
email_resource(mixed $resource, mixed $resourcename, mixed $fromusername, mixed $userlist, mixed $message[, mixed $access = -1 ][, mixed $expires = "" ][, mixed $sharepwd = "" ][, mixed $useremail = "" ][, mixed $from_name = "" ][, mixed $cc = "" ][, mixed $list_recipients = false ][, mixed $open_internal_access = false ][, mixed $useraccess = 2 ][, mixed $group = "" ]) : mixed
Parameters
- $resource : mixed
- $resourcename : mixed
- $fromusername : mixed
- $userlist : mixed
- $message : mixed
- $access : mixed = -1
- $expires : mixed = ""
- $sharepwd : mixed = ""
- $useremail : mixed = ""
- $from_name : mixed = ""
- $cc : mixed = ""
- $list_recipients : mixed = false
- $open_internal_access : mixed = false
- $useraccess : mixed = 2
- $group : mixed = ""
delete_resource()
delete_resource(mixed $ref) : mixed
Parameters
- $ref : mixed
get_resource_type_field()
Returns field data from resource_type_field for the given field
get_resource_type_field(int $field) : bool|array<string|int, mixed>
Parameters
- $field : int
-
Resource type field ID
Tags
Return values
bool|array<string|int, mixed>get_resource_field_data()
get_resource_field_data
get_resource_field_data(int $ref[, bool $multi = false ][, bool $use_permissions = true ][, int $originalref = null ][, bool $external_access = false ][, bool $ord_by = false ][, bool $forcsv = false ][, bool $translate_value = true ]) : array<string|int, mixed>|bool
Parameters
- $ref : int
-
Resource ID
- $multi : bool = false
-
Get all fields? False by default (only fields that apply to the given resource type)
- $use_permissions : bool = true
-
Honour user permissions e.g. field access. TRUE by default
- $originalref : int = null
-
Original resource ID to get data for. NULL by default
- $external_access : bool = false
-
Only get data permitted to view externally. FALSE by default
- $ord_by : bool = false
-
Use field order_by setting. FALSE by default (order is by resource type first)
- $forcsv : bool = false
-
Get data for CSV export (uses \ separator for category tree nodes). FALSE by default
- $translate_value : bool = true
-
Field value will be translated with i18n_get_translated() unless FALSE supplied.
Tags
Return values
array<string|int, mixed>|boolget_resource_field_data_batch()
get_resource_field_data_batch - Get all resource data for the given resources
get_resource_field_data_batch(array<string|int, mixed> $resources[, bool $use_permissions = true ][, bool $external_access = false ][, bool $ord_by = false ][, mixed $exportoptions = array() ]) : array<string|int, mixed>
Returns a multidimensional array with resource IDs as top level keys, then fields (order determined by $ord_by setting) IMPORTANT: This differs from get_resource_field_data() in that only fields containing data will be returned.
e.g. Array ( [119912] => array ( [0] => Array ( [resource] => 119912 [value] => This is the title of resource 119912 [resource_type_field] => 8 [ref] => 8 [name] => title [title] => Title [field_constraint] => 0 [type] => 1)) ....
Parameters
- $resources : array<string|int, mixed>
-
(either an array of resource ids or an array returned from search results)
- $use_permissions : bool = true
-
Honour user permissions e.g. field access. TRUE by default
- $external_access : bool = false
-
Only get data permitted to view externally. FALSE by default
- $ord_by : bool = false
-
Use field order_by setting. FALSE by default (order is by resource type first)
- $exportoptions : mixed = array()
-
Array of options as below "csvexport" (bool) - get data for CSV export (uses \ separator for category tree nodes) "personal" (bool) - include data in fields marked as personal "alldata" (bool) - include data in all fields, including technical metadata
Return values
array<string|int, mixed> —Array of resource data organised by resource then metadata field ID
get_resource_types()
Return an array of resource types that this user has access to
get_resource_types([string $types = "" ][, bool $translate = true ][, bool $ignore_access = false ][, bool $usecache = false ]) : array<string|int, mixed>
Parameters
- $types : string = ""
-
Comma separated list to limit the types that are returned by ref, blank string returns all available types
- $translate : bool = true
-
Flag to translate the resource types before returning
- $ignore_access : bool = false
-
Return all resource types regardless of access?#
- $usecache : bool = false
-
Return cached result?
Return values
array<string|int, mixed> —Array of resource types limited by T* permissions and optionally by $types
get_all_resource_types()
Returns all resources types
get_all_resource_types() : array<string|int, mixed>
No permissions are checked or applied, do not expose this function to the API
Return values
array<string|int, mixed> —Array of resource types ordered by 'order_by' then 'ref'
clear_resource_data()
clear_resource_data(mixed $resource) : mixed
Parameters
- $resource : mixed
copy_resource()
Create a new resource, copying all data from the resource with reference $from.
copy_resource(int $from[, int $resource_type = -1 ][, string $origin = '' ]) : bool|int
Note this copies only the data and not any attached file. It's very unlikely the same file would be in the system twice, however users may want to clone an existing resource to avoid reentering data if the resource is very similar. If $resource_type if specified then the resource type for the new resource will be set to $resource_type rather than simply copied from the $from resource.
Parameters
- $from : int
-
ID of resource
- $resource_type : int = -1
-
ID of resource type
- $origin : string = ''
-
Origin of resource when uploading, leave blank if not an upload
Return values
bool|intresource_log()
Log resource activity
resource_log(int $resource, string $type, int $field[, string $notes = "" ][, mixed $fromvalue = "" ][, mixed $tovalue = "" ][, int $usage = -1 ][, int $alt_ref = -1 ]) : int
Parameters
- $resource : int
-
- resource ref -- resource_log.resource
- $type : string
-
- log code defined in include/definitions.php -- resource_log.type
- $field : int
-
- resource type field -- resource_log.resource_type_field
- $notes : string = ""
-
- text notes -- resource_log.notes
- $fromvalue : mixed = ""
-
- original value (int or string) -- resource_log.previous_value
- $tovalue : mixed = ""
-
- new value (int or string)
- $usage : int = -1
-
-- resource_log.usageoption
- $alt_ref : int = -1
-
- ref of alt file -- resource_log.alt_ref
Tags
Return values
int —(or false)
get_resource_log()
Get resource log records. The standard field titles are translated using $lang. Custom field titles are i18n translated.
get_resource_log(int $resource[, int $fetchrows = -1 ][, array<string|int, mixed> $filters = array() ]) : array<string|int, mixed>
Parameters
- $resource : int
-
Resource ID - set to NULL and specify r.ref=>[id] in the $filters array to retrieve a specific log entry by log ref
- $fetchrows : int = -1
-
If $fetchrows is set we don't have to loop through all the returned rows. @see ps_query()
- $filters : array<string|int, mixed> = array()
-
List of filters to include in the where clause. The key of the array is linked to the available columns in the sql statement so they must match!
Return values
array<string|int, mixed>get_resource_type_name()
get_resource_type_name(mixed $type) : mixed
Parameters
- $type : mixed
get_resource_custom_access()
get_resource_custom_access(mixed $resource) : mixed
Parameters
- $resource : mixed
get_resource_custom_access_users_usergroups()
Retrieves custom access settings for users and user groups associated with a specific resource.
get_resource_custom_access_users_usergroups(int $resource) : array<string|int, mixed>
This function performs a database query to return a list of custom access rows for a given resource, including the names of user groups and users, the access level, and expiration details.
Parameters
- $resource : int
-
The resource reference ID for which to retrieve custom access settings.
Return values
array<string|int, mixed> —The result set containing user groups, users, access levels, and expiration information.
save_resource_custom_access()
Saves custom access settings for a specific resource.
save_resource_custom_access(int $resource) : void
This function retrieves custom access groups associated with the given resource, deletes existing custom access records for that resource, and then inserts new access settings based on user input.
Parameters
- $resource : int
-
The resource reference ID for which custom access is being set.
get_custom_access()
Lookup custom access value for a resource
get_custom_access(int $resource, int $usergroup[, bool $return_default = true ]) : mixed
Parameters
- $resource : int
-
Resource ID.
- $usergroup : int
-
User group ID.
- $return_default : bool = true
-
Return default custom access value RESOURCE_ACCESS_CONFIDENTIAL
Return values
mixed —False if custom access is disabled or there is no custom access value set for this resource. Int representing custom access level if set; 0 - open, 1 - restricted, 2 - confidential.
get_themes_by_resource()
Determine the featured collections and public collections a resource is associated with.
get_themes_by_resource(int $ref) : array<string|int, mixed>
Parameters
- $ref : int
-
Resource ref
Return values
array<string|int, mixed>update_resource_type()
update_resource_type(mixed $ref, mixed $type) : mixed
Parameters
- $ref : mixed
- $type : mixed
Tags
get_exiftool_fields()
Returns a list of exiftool fields, which are basically fields with an 'exiftool field' set.
get_exiftool_fields(int $resource_type[, string $option_separator = "," ][, bool $skip_translation = false ]) : array<string|int, mixed>
Parameters
- $resource_type : int
- $option_separator : string = ","
-
String to separate the node options returned for fixed list fields
- Recommended NODE_NAME_STRING_SEPARATOR
- Defaults to comma for backwards compatibility
- $skip_translation : bool = false
-
Set to true to return the entire untranslated node value rather than the appropriate translation only.
Return values
array<string|int, mixed>createTempFile()
Create a temporary copy of the file in the tmp folder (ie. the usual filestore/tmp/)
createTempFile(string $path, string $uniqid, string $filename) : bool|string
Parameters
- $path : string
-
File path
- $uniqid : string
-
If a uniqid is provided, create a folder within tmp. See get_temp_dir() for more information.
- $filename : string
-
Filename of the new file
Tags
Return values
bool|string —Returns FALSE or the file path of the temporary file
stripMetadata()
Strips metadata from file
stripMetadata(string $file_path) : bool|string
Parameters
- $file_path : string
-
Physical path to file that will have metadata stripped. Use NULL to just get the exiftool command returned instead of running the command on the file
Tags
Return values
bool|string —Returns TRUE or the Exiftool command for stripping metadata
write_metadata()
Writes metadata to a specified file using ExifTool.
write_metadata(string $path, int $ref[, string $uniqid = "" ]) : string|bool
Parameters
- $path : string
-
The file path where the metadata will be written.
- $ref : int
-
The reference ID of the resource associated with the file.
- $uniqid : string = ""
-
A unique identifier for the temporary file location (optional).
Return values
string|bool —The path to the temporary file if successful, false otherwise.
delete_exif_tmpfile()
Delete Exif temp file
delete_exif_tmpfile(string $tmpfile) : mixed
Parameters
- $tmpfile : string
-
Exif temp file to be deleted
update_resource()
Updates a resource with a new file and its associated metadata.
update_resource(int $r, string $path, string $type, string $title[, bool $ingest = false ][, bool $createPreviews = true ][, string $extension = '' ][, bool $after_upload_processing = false ]) : int|bool
Parameters
- $r : int
-
The resource ID to update.
- $path : string
-
The file path of the new resource.
- $type : string
-
The type of the resource.
- $title : string
-
The title for the resource.
- $ingest : bool = false
-
Indicates if the resource is being ingested.
- $createPreviews : bool = true
-
Flag to create previews.
- $extension : string = ''
-
The file extension of the new resource.
- $after_upload_processing : bool = false
-
Indicates if the update is after upload processing.
Return values
int|bool —The resource ID if successful, false otherwise.
import_resource()
Imports a resource from the specified path and updates its details.
import_resource(string $path, string $type, string $title[, bool $ingest = false ][, string $extension = '' ]) : int|bool
This function is used to import resources into the system, particularly through staticsync.php It creates a new resource entry and updates it with the provided file details.
Parameters
- $path : string
-
The file path of the resource to import.
- $type : string
-
The type of the resource being imported.
- $title : string
-
The title for the imported resource.
- $ingest : bool = false
-
Indicates if the resource is being ingested (default is false).
- $extension : string = ''
-
The file extension of the resource (optional).
Return values
int|bool —The newly created resource ID if successful, false otherwise.
get_alternative_files()
Retrieves alternative files associated with a specified resource.
get_alternative_files(int $resource[, string $order_by = "" ][, string $sort = "" ][, string $type = "" ]) : array<string|int, mixed>|bool
Parameters
- $resource : int
-
The resource ID for which to fetch alternative files.
- $order_by : string = ""
-
The field to order the results by (optional).
- $sort : string = ""
-
The sorting direction (ASC or DESC) for the order_by field (optional).
- $type : string = ""
-
The type of alternative file to filter by (optional).
Return values
array<string|int, mixed>|bool —An array of alternative files if successful, false otherwise.
get_alternative_files_by_filename()
Search the alternative file records for matching filenames Alternative files can be optionally filtered by the Resource ID or by collection
get_alternative_files_by_filename(string $filename, int $collection, int $min, int $max) : array<string|int, mixed>
Parameters
- $filename : string
-
Filename of the alternative file(s) to search for
- $collection : int
-
Collection ID to filter resources, use 0 to ignore
- $min : int
-
Minimum Resource ID to consider, use 0 to ignore
- $max : int
-
Maximum Resource ID to consider, use 0 to ignore
Return values
array<string|int, mixed> —All matching alternative file records with corresponding: resource ID, filename, file size, extension, name, and description
add_alternative_file()
Add alternative file
add_alternative_file(int $resource, string $name[, string $description = "" ][, string $file_name = "" ][, string $file_extension = "" ][, int $file_size = 0 ][, string $alt_type = '' ]) : int
Parameters
- $resource : int
- $name : string
- $description : string = ""
- $file_name : string = ""
- $file_extension : string = ""
- $file_size : int = 0
- $alt_type : string = ''
Return values
intdelete_alternative_file()
delete_alternative_file
delete_alternative_file(int $resource, int $ref) : bool
Parameters
- $resource : int
-
Resource id.
- $ref : int
-
Alternative file id.
Return values
boolget_alternative_file()
Retrieves a specific alternative file associated with a given resource.
get_alternative_file(int $resource, int $ref) : array<string|int, mixed>|bool
Parameters
- $resource : int
-
The resource ID associated with the alternative file.
- $ref : int
-
The reference ID of the alternative file to retrieve.
Tags
Return values
array<string|int, mixed>|bool —An associative array containing the alternative file details if found, false otherwise.
save_alternative_file()
Updates the details of an alternative file in the database.
save_alternative_file(int $resource, int $ref[, array<string|int, mixed> $data = [] ]) : void
Parameters
- $resource : int
-
The resource ID associated with the alternative file.
- $ref : int
-
The reference ID of the alternative file to update.
- $data : array<string|int, mixed> = []
-
Array of data in name=>value format, where name is the resource_alt_files column name. If a column is to be left as is then it must not be included in the array
user_rating_save()
Saves a user rating for a given resource.
user_rating_save(int $userref, int $ref, int $rating) : void
Parameters
- $userref : int
-
The reference ID of the user rating the resource.
- $ref : int
-
The reference ID of the resource being rated.
- $rating : int
-
The rating value to be saved (0 to remove rating).
get_field()
A standard field title is translated using $lang. A custom field title is i18n translated.
get_field(int $field) : bool|array<string|int, mixed>
Parameters
- $field : int
-
Resource type field ID
Return values
bool|array<string|int, mixed> —Returns FALSE or record data (array)
get_keyword_from_option()
Retrieves the keyword that will be indexed for a given field option.
get_keyword_from_option(string $option) : string
This function splits the provided option into keywords and applies stemming if enabled.
Parameters
- $option : string
-
The field option to process.
Return values
string —The keyword to be indexed.
get_resource_access()
Retrieves the access level for the currently logged-in user for a specified resource.
get_resource_access(int|array<string|int, mixed> $resource) : int
The access levels returned are:
- 0 = Full Access (download all sizes)
- 1 = Restricted Access (download only those sizes that are set to allow restricted downloads)
- 2 = Confidential (no access)
Parameters
- $resource : int|array<string|int, mixed>
-
The reference ID of the resource or a resource data array.
Tags
Return values
int —The access level for the resource.
get_custom_access_user()
Retrieves the custom access level for a specific user on a given resource.
get_custom_access_user(int $resource, int $user) : mixed
This function checks the resource_custom_access table to see if the user has any custom access
permissions for the specified resource. It returns the access level if found and still valid;
otherwise, it returns false.
Parameters
- $resource : int
-
The resource ID to check access for.
- $user : int
-
The user ID to check for custom access.
Return values
mixed —The access level if found; false otherwise.
edit_resource_external_access()
Edits the external access settings for a given resource.
edit_resource_external_access(string $key[, int $access = -1 ][, string $expires = "" ][, string $group = "" ][, string $sharepwd = "" ]) : bool
Parameters
- $key : string
-
The external access key to edit.
- $access : int = -1
-
The new access level; defaults to -1 for no change.
- $expires : string = ""
-
The expiration date for the access key; optional.
- $group : string = ""
-
The user group to share with; defaults to the current user group if not specified.
- $sharepwd : string = ""
-
The password for accessing the resource; "(unchanged)" means no change.
Return values
bool —Returns true if the operation was successful; false if the key is empty.
resource_download_allowed()
For the given resource and size, can the current user download it? resource type and access may already be available in the case of search, so pass them along to get_resource_access to avoid extra queries $resource can be a resource-specific search result array.
resource_download_allowed(int $resource, string $size, int $resource_type[, int $alternative = -1 ][, bool $usecache = false ]) : bool
Parameters
- $resource : int
-
ID of resource
- $size : string
-
ID of size
- $resource_type : int
-
ID of resource type
- $alternative : int = -1
-
Use alternative?
- $usecache : bool = false
-
Use cached result if available?
Return values
boolget_edit_access()
Check if current user has edit access to a resource. Checks the edit permissions (e0, e-1 etc.) and also the group edit filter which filters edit access based on resource metadata.
get_edit_access(int $resource[, int $status = -999 ][, array<string|int, mixed> &$resourcedata = [] ]) : bool
Parameters
- $resource : int
-
Resource ID
- $status : int = -999
-
Archive status ID. Use -999 to use the one from resourcedata argument
- $resourcedata : array<string|int, mixed> = []
Return values
boolfilter_match()
In the given filter string, does name/value match? Returns: 0 = no match for name 1 = matched name but value was not present 2 = matched name and value was correct
filter_match(string $filter, string $name, string $value) : int
Parameters
- $filter : string
-
Sring to for which filtering is to be applied
- $name : string
-
Name to match
- $value : string
-
Value to match
Return values
intlog_diff()
Check changes made to a metadata field and create a nice user friendly summary
log_diff(string $fromvalue, string $tovalue) : string
Parameters
- $fromvalue : string
-
- if nodes then values will be separated by NODE_NAME_STRING_SEPARATOR
- $tovalue : string
-
- if nodes then values will be separated by NODE_NAME_STRING_SEPARATOR
Tags
Return values
stringget_metadata_templates()
Retrieves a list of all metadata templates for a specified resource type.
get_metadata_templates() : array<string|int, mixed>
Return values
array<string|int, mixed> —An array of metadata templates, each containing the resource reference and its title.
get_resource_collections()
Retrieves a list of collections that a resource is used in for the specified resource reference.
get_resource_collections(int $ref) : array<string|int, mixed>
Parameters
- $ref : int
-
The resource reference for which to retrieve associated collections.
Return values
array<string|int, mixed> —An array of collections associated with the resource, including user information and resource count.
download_summary()
Retrieves a summary of downloads for a given resource, categorized by usage type.
download_summary(int $resource) : array<string|int, mixed>
This function queries the resource log to count the number of downloads for the specified resource, grouping the results by the usage option.
Parameters
- $resource : int
-
The resource reference for which to retrieve the download summary.
Return values
array<string|int, mixed> —An array of download summaries, each containing the usage option and the corresponding count.
check_use_watermark()
check_use_watermark([mixed $download_key = "" ][, mixed $resource = "" ]) : mixed
Parameters
- $download_key : mixed = ""
- $resource : mixed = ""
autocomplete_blank_fields()
Fill in any blank fields for the resource.
autocomplete_blank_fields(int $resource, bool $force_run[, bool $return_changes = false ][, int $field_ref = 0 ]) : bool|array<string|int, mixed>
IMPORTANT: Auto completing blank fields with inactive options should be allowed (possibly a system misconfiguration). This function will NOT exclude inactive nodes because, for required fields, you might end up having no value after processing the field.
Parameters
- $resource : int
-
Resource ID
- $force_run : bool
-
Allow code to force running this function and update the fields even if there is data.
- $return_changes : bool = false
-
When true an array of fields changed by autocomplete is returned. For example:
- when creating a resource, autocomplete_blank_fields() should always be triggered regardless if user has data in its user template.
- when copying resource/ extracting embedded metadata, autocomplete_blank_fields() should not overwrite if there is data for that field as at this point you probably have the expected data for your field.
- $field_ref : int = 0
-
Optional parameter to specify which metadata field should be processed. Left blank, all fields will be processed (default behaviour).
Return values
bool|array<string|int, mixed> —Success/fail or array of changes made
get_page_count()
get_page_count(mixed $resource[, mixed $alternative = -1 ]) : mixed
Parameters
- $resource : mixed
- $alternative : mixed = -1
Tags
update_disk_usage()
Updates the disk usage for a specified resource by calculating the total size of the files in the resource's directory and storing the result in the resource table.
update_disk_usage(int $resource) : bool
This function first checks for the size of the primary resource file and then scans the associated folder to compute the total disk usage, excluding any files in staticsync locations.
Parameters
- $resource : int
-
The resource reference whose disk usage is to be updated.
Return values
bool —Returns true on success, or false if the directory does not exist.
update_disk_usage_cron()
Update disk usage for all resources that have not yet been updated or have not been updated in the past 30 days.
update_disk_usage_cron() : bool|void
Limit to a reasonable amount so that this process is spread over several cron intervals for large data sets.
Return values
bool|voidget_total_disk_usage()
Returns the total disk space used by all resources on the system
get_total_disk_usage() : int
Return values
intoverquota()
Calculate if the quota set by $disksize in the configuration has been exceeded.
overquota() : array<string|int, mixed>|bool
Return values
array<string|int, mixed>|bool —True if the system is over quota
get_original_imagesize()
Get size of specified image file
get_original_imagesize([int $ref = "" ][, string $path = "" ][, string $extension = "jpg" ][, bool $forcefromfile = false ]) : array<string|int, mixed>|bool
Parameters
- $ref : int = ""
-
Resource ID
- $path : string = ""
-
File path
- $extension : string = "jpg"
-
File extension
- $forcefromfile : bool = false
-
Get info from file instead of database cache
Tags
Return values
array<string|int, mixed>|bool —File size info. Returns false if not available
generate_resource_access_key()
Generates an external access key for a resource, allowing specified access to a user or group.
generate_resource_access_key(int $resource, int $userref, int $access, string|null $expires, string $email[, string $group = "" ][, string $sharepwd = "" ]) : string|bool
This function creates a unique access key and stores it in the database along with information about the resource, the user, the type of access granted, expiration date, email, and user group. It also hashes the share password if provided.
Parameters
- $resource : int
-
The resource reference for which the access key is being generated.
- $userref : int
-
The user reference for the user to whom access is granted.
- $access : int
-
The level of access granted (e.g., full access, restricted).
- $expires : string|null
-
The expiration date of the access key, formatted as 'Y-m-d'.
- $email : string
-
The email address associated with the user receiving the access key.
- $group : string = ""
-
The user group associated with the access, defaults to the current user group if not specified.
- $sharepwd : string = ""
-
The share password, if any, used to secure access.
Return values
string|bool —Returns the generated access key on success, or false if permissions are insufficient.
get_resource_external_access()
Retrieves all external access keys granted for a specific resource.
get_resource_external_access(int $resource) : array<string|int, mixed>
This function returns a list of all external access details for the given resource, including users and emails associated with each access key. If the user does not have the elevated 'v' permission, the function will only return access keys associated with the current user. The results are grouped by access key, allowing for multiple users or emails to be returned as comma-separated values.
Parameters
- $resource : int
-
The reference ID of the resource for which external access is being retrieved.
Return values
array<string|int, mixed> —An array of access details, including access keys, users, emails, expiration dates, and other related information for the specified resource.
delete_resource_access_key()
delete_resource_access_key(mixed $resource, mixed $access_key) : mixed
Parameters
- $resource : mixed
- $access_key : mixed
resource_type_config_override()
resource_type_config_override(mixed $resource_type[, mixed $only_onchange = true ]) : mixed
Parameters
- $resource_type : mixed
- $only_onchange : mixed = true
update_archive_status()
Update the archive state of resource(s) and log this
update_archive_status(mixed $resource, int $archive[, int|array<string|int, mixed> $existingstates = array() ][, int $collection = 0 ][, mixed $more_notes = "" ]) : void
Parameters
- $resource : mixed
- $archive : int
-
- Destination archive state
- $existingstates : int|array<string|int, mixed> = array()
-
- existing archive state or array of corresponding existing archive states
- $collection : int = 0
-
- optional id of collection containing resources
- $more_notes : mixed = ""
Tags
delete_resources_in_collection()
delete_resources_in_collection(mixed $collection) : mixed
Parameters
- $collection : mixed
update_related_resource()
Update related resources - add new related resource(s) or delete existing
update_related_resource(int $ref, mixed $related[, bool $add = true ]) : bool
Parameters
- $ref : int
-
ID of primary resource
- $related : mixed
- $add : bool = true
-
Add relationship? If false this will delete the specified relationships
Return values
boolcan_share_resource()
Check if sharing of resource is permitted
can_share_resource(int $ref[, int $access = "" ]) : bool
Parameters
- $ref : int
-
ID of resource
- $access : int = ""
-
Level of resource access (0 - Open 1 - Restricted 2 - Confidential)
Return values
booldelete_resource_custom_access_usergroups()
Delete all usergroup specific access to resource $ref
delete_resource_custom_access_usergroups(int $ref) : mixed
Parameters
- $ref : int
-
ID of resource
truncate_join_field_value()
Truncate the field for insertion into the main resource table field
truncate_join_field_value(string $value) : string
Parameters
- $value : string
Return values
stringget_video_snapshots()
Check whether a resource (of a video type) has any snapshots created.
get_video_snapshots(int $resource_id[, bool $file_path = false ][, bool $count_only = false ][, mixed $includemodified = false ]) : array<string|int, mixed>|int
Snapshots are being created using config option $ffmpeg_snapshot_frames
Parameters
- $resource_id : int
-
Resource unique ref
- $file_path : bool = false
-
Specify whether the return value should be the file path. Default is FALSE
- $count_only : bool = false
-
Set to true if we are only interested in how many snapshots we have. Default is FALSE
- $includemodified : mixed = false
Tags
Return values
array<string|int, mixed>|int —Array of all file paths found or number of files found
resource_file_readonly()
Check if resource file is read-only because it's part of the filestore template threshold
resource_file_readonly(int|numeric-string $ref) : bool
Parameters
- $ref : int|numeric-string
-
Resource ID
Return values
booldelete_resource_custom_user_access()
delete_resource_custom_user_access(mixed $resource, mixed $user) : mixed
Parameters
- $resource : mixed
- $user : mixed
get_video_info()
get_video_info(mixed $file) : mixed
Parameters
- $file : mixed
Tags
copyAllDataToResource()
Provides the ability to copy any metadata field data from one resource to another.
copyAllDataToResource(int $from, int $to[, mixed $resourcedata = false ]) : bool
Parameters
- $from : int
-
Resource we are copying data from
- $to : int
-
The Resource ID that needs updating
- $resourcedata : mixed = false
Return values
boolcopy_locked_data()
Update resource data for 'locked' fields from last edited resource. Used for upload_then_edit
copy_locked_data(array<string|int, mixed> $resource, array<string|int, mixed> $locked_fields, int $lastedited[, bool $save = false ]) : array<string|int, mixed>
Parameters
- $resource : array<string|int, mixed>
-
- existing resource data
- $locked_fields : array<string|int, mixed>
-
- array of locked data columns (may also include field ids which are handled by copy_locked_fields)
- $lastedited : int
-
- last edited resource to copy data from
- $save : bool = false
-
- if true, save data to database (as opposed to just updating the $resource array e.g. for edit page)
Tags
Return values
array<string|int, mixed> —$resource - modified resource data array
copy_locked_fields()
Update resource metadata for 'locked' fields from last edited resource.
copy_locked_fields(int $ref, array<string|int, mixed> &$fields, array<string|int, mixed> &$all_selected_nodes, array<string|int, mixed> $locked_fields, int $lastedited[, bool $save = false ]) : void
NB: $fields and $all_selected_nodes are passed by reference
Parameters
- $ref : int
-
- resource id being updated
- $fields : array<string|int, mixed>
-
- resource $fields array
- $all_selected_nodes : array<string|int, mixed>
-
- array of existing resource nodes
- $locked_fields : array<string|int, mixed>
-
- array of locked data columns (may also include resource table columns - handled by copy_locked_data)
- $lastedited : int
-
- last edited resource to copy data from
- $save : bool = false
-
- save data to database (as opposed to just updating the $fields array e.g. for edit page)
Tags
copyRelatedResources()
Copy related resources from one resource to another
copyRelatedResources(int $from, mixed $to) : void
Parameters
- $from : int
-
Resource we are copying related resources from
- $to : mixed
Tags
process_edit_form()
process_edit_form(mixed $ref, mixed $resource) : mixed
Parameters
- $ref : mixed
- $resource : mixed
update_timestamp()
update_timestamp(mixed $resource) : mixed
Parameters
- $resource : mixed
get_extension()
Get resource file extension from the database or use JPG, for download
get_extension(array<string|int, mixed> $resource, string $size) : string
Parameters
- $resource : array<string|int, mixed>
- $size : string
-
Preview size as defined in the system
Tags
Return values
stringget_last_resource_edit_array()
Obtain details of the last resource edited in the given array of resource ids
get_last_resource_edit_array([array<string|int, mixed> $resources = array() ]) : array<string|int, mixed>|false
Parameters
- $resources : array<string|int, mixed> = array()
-
Array of resource IDs
Return values
array<string|int, mixed>|false —Array containing details of last edit (resource ID, timestamp and username of user who performed edit)
get_default_archive_state()
Get the default archive state for new resources
get_default_archive_state([int $requestedstate = "" ]) : int
Parameters
- $requestedstate : int = ""
-
(optional) ID of requested archive state
Return values
int —ID of valid user requested archive state, may differ from that requested
save_original_file_as_alternative()
Save the original file being replaced, as an alternative file
save_original_file_as_alternative(int $ref) : bool|int
Parameters
- $ref : int
-
(required) ID of original resource
Return values
bool|int —int = id of new alternative file; false = file not saved
replace_resource_file()
Replace the primary resource file with the file located at the path specified
replace_resource_file(int $ref, mixed $file_location[, mixed $no_exif = false ][, mixed $autorotate = false ][, mixed $keep_original = true ]) : bool
Parameters
- $ref : int
-
Resource ID to replace
- $file_location : mixed
- $no_exif : mixed = false
- $autorotate : mixed = false
- $keep_original : mixed = true
Return values
boolget_resource_all_image_sizes()
Return all sizes available for a specific resource. Multi page resources should have each page size included as well in the output.
get_resource_all_image_sizes(int $ref) : array<string|int, mixed>
Parameters
- $ref : int
-
Resource ID
Tags
Return values
array<string|int, mixed>sanitize_date_field_input()
sanitize_date_field_input(mixed $date[, mixed $validate = false ]) : mixed
Parameters
- $date : mixed
- $validate : mixed = false
download_link_generate_key()
Create a temporary download key for a specific user or key and resource combination Used when both $watermark_open and $terms_download are enabled
download_link_generate_key(string $id, int $resource) : string
Parameters
- $id : string
-
Key identifier e.g. user ID or external access key
- $resource : int
-
Resource ID
Return values
stringdownload_link_check_key()
Check the download key for a specific user/resource combination
download_link_check_key(string $download_key, int $resource) : string
Parameters
- $download_key : string
-
Download key
- $resource : int
-
Resource ID
Return values
stringfilter_check()
Check if a given set of nodes meets the conditions set for the provided filter NOte that all resource_nodes for a resource should be passed to check if a filter is matched
filter_check(mixed $filterid, array<string|int, mixed> $nodes) : bool
Parameters
- $filterid : mixed
- $nodes : array<string|int, mixed>
-
Array of nodes
Return values
boolupdate_node_hitcount_from_search()
update_node_hitcount_from_search(mixed $resource, mixed $search) : mixed
Parameters
- $resource : mixed
- $search : mixed
copy_hitcount_to_live()
copy_hitcount_to_live() : mixed
get_image_sizes()
Returns a table of available image sizes for resource $ref. The standard image sizes are translated using $lang. Custom image sizes are i18n translated.
get_image_sizes(int $ref[, bool $internal = false ][, string $extension = "jpg" ][, bool $onlyifexists = true ]) : array<string|int, mixed>
The original image file assumes the name of the 'nearest size (up)' in the table
Parameters
- $ref : int
-
ID of resource
- $internal : bool = false
- $extension : string = "jpg"
-
File extension of image
- $onlyifexists : bool = true
Tags
Return values
array<string|int, mixed> —$return
get_related_resources()
Return an array of resource references that are related to resource $ref
get_related_resources(int $ref) : array<string|int, mixed>
Parameters
- $ref : int
-
ID of resource
Return values
array<string|int, mixed>get_field_options()
Get available options for fixed list field types
get_field_options(int $ref[, bool $nodeinfo = false ][, bool $skip_translation = false ]) : array<string|int, mixed>|bool
Parameters
- $ref : int
-
Metadata field ref
- $nodeinfo : bool = false
-
Get full node details?
- $skip_translation : bool = false
-
Do not translate node name. Only relevant if $nodeinfo=false
Return values
array<string|int, mixed>|bool —Array of field options, either as a simple array or with full node details
get_data_by_field()
Get the resource data value for a field and a specific resource or get the specified field for all resources in the system
get_data_by_field(int $resource, int|string $field[, bool $flatten = true ]) : string|array<string|int, mixed>|Generator
Parameters
- $resource : int
-
Resource ID. Use NULL to retrieve all resources records for the specified field
- $field : int|string
-
Resource type field ID. Can also be a shortname.
- $flatten : bool = true
-
Should a fixed list field value be flatten to a simple string? Set to FALSE to get the list of nodes
Tags
Return values
string|array<string|int, mixed>|Generator —Generator is returned for the old behaviour of returning field data for all resources (for performance). Shouldn't be an issue as long as it's used in foreach loops
get_all_image_sizes()
get_all_image_sizes([mixed $internal = false ][, mixed $restricted = false ]) : mixed
Parameters
- $internal : mixed = false
- $restricted : mixed = false
image_size_restricted_access()
image_size_restricted_access(mixed $id) : mixed
Parameters
- $id : mixed
get_fields()
Returns a list of fields with refs matching the supplied field refs.
get_fields(array<string|int, mixed> $field_refs[, bool $order_by_passed_refs = false ]) : array<string|int, mixed>
Parameters
- $field_refs : array<string|int, mixed>
-
Array of field refs
- $order_by_passed_refs : bool = false
Return values
array<string|int, mixed>get_hidden_indexed_fields()
get_hidden_indexed_fields() : mixed
get_OR_fields()
get_OR_fields() : mixed
get_nopreview_html()
Returns the HTML necessary to represent a resource with the given extension when no image preview exists.
get_nopreview_html(string $extension[, int $resource_type = null ]) : string
Parameters
- $extension : string
-
File extension
- $resource_type : int = null
-
Optional, the resource type of the resource, used to find an icon at the resource type level if an icon for this extension is not defined.
Return values
stringget_resource_type_fields()
Gets all metadata fields, optionally for a specified array of resource types
get_resource_type_fields([array<string|int, mixed> $restypes = "" ][, string $field_order_by = "ref" ][, string $field_sort = "asc" ][, string $find = "" ][, array<string|int, mixed> $fieldtypes = array() ][, bool $include_inactive = false ]) : array<string|int, mixed>
Parameters
- $restypes : array<string|int, mixed> = ""
-
Optional array of resource types to check
- $field_order_by : string = "ref"
-
Order by column
- $field_sort : string = "asc"
-
Sort order
- $find : string = ""
-
Parameter value to search for
- $fieldtypes : array<string|int, mixed> = array()
-
List of field types to include
- $include_inactive : bool = false
-
Should inactive resources be checked, default is false
Return values
array<string|int, mixed>notify_resource_change()
notify_resource_change(mixed $resource) : mixed
Parameters
- $resource : mixed
add_verbatim_keywords()
add_verbatim_keywords(mixed &$keywords, mixed $string, mixed $resource_type_field[, mixed $called_from_search = false ]) : mixed
Parameters
- $keywords : mixed
- $string : mixed
- $resource_type_field : mixed
- $called_from_search : mixed = false
Tags
metadata_field_edit_access()
Check the current user's edit access to given metadata field ID
metadata_field_edit_access(int $field) : bool
Parameters
- $field : int
Return values
boolget_download_filename()
Work out the filename to use, based on the download_filename_format configuration option, when downloading the specified resource file with the given settings
get_download_filename(int $ref, string $size, int $alternative, string $ext) : string
Parameters
- $ref : int
-
Resource ID
- $size : string
-
size code
- $alternative : int
-
Alternative file ID
- $ext : string
-
File extension
Return values
string —Filename to use
get_resource_type_from_extension()
Get resource type ID based on extension $mappings = array(resource_type_id => array(allowed_extensions));
get_resource_type_from_extension(string $extension, array<string|int, mixed> $resource_type_extension_mapping, int $default) : int
Example of mapping array: $mappings = array(2 => array('pdf', 'doc', 'docx', 'epub', 'ppt', 'pptx', 'odt', 'ods', 'tpl'));
Parameters
- $extension : string
-
Extension we search by (ie. "mp4")
- $resource_type_extension_mapping : array<string|int, mixed>
-
Maps between resource types and extensions
- $default : int
-
The default value to use in case we can't find it the mappings
Return values
int —Resource type ID
canSeePreviewTools()
Helper function for Preview tools feature. Checks all necessary permissions or options in order to tell the system whether PreviewTools panel should be displayed
canSeePreviewTools(array<string|int, mixed> $resource) : bool
Parameters
- $resource : array<string|int, mixed>
-
Resource data structure
Return values
boolcanSeeAnnotationsFields()
Helper function to determine if annotations are to be displayed.
canSeeAnnotationsFields() : array<string|int, mixed>
Return values
array<string|int, mixed> —Array of annotation fields that can be viewed.
alt_is_ffmpeg_alternative()
Determine if a video alternative was created from $ffmpeg_alternatives settings.
alt_is_ffmpeg_alternative(array<string|int, mixed> $alternative) : bool
Places in this file because get_resource_path relies on it
Parameters
- $alternative : array<string|int, mixed>
-
Record line from resource_alt_files
Return values
bool —True means alternative was created from $ffmpeg_alternatives settings
create_resource_type_field()
Create a new resource type field with the specified name of the required type
create_resource_type_field(string $name[, int|array<string|int, mixed> $restype = 0 ][, int $type = FIELD_TYPE_TEXT_BOX_SINGLE_LINE ][, string $shortname = "" ][, bool $index = false ]) : bool|int
Parameters
- $name : string
-
- name of new field
- $restype : int|array<string|int, mixed> = 0
-
- resource type - resource type(s) that field applies to (0 = global, single value = one type, array = multiple types)
- $type : int = FIELD_TYPE_TEXT_BOX_SINGLE_LINE
-
- field type - refer to include/definitions.php
- $shortname : string = ""
-
- shortname of new field
- $index : bool = false
-
- should new field be indexed?
Return values
bool|int —- ref of new field, false if unsuccessful
metadata_field_view_access()
Check if user has view access to metadata field
metadata_field_view_access(int $field) : bool
Parameters
- $field : int
-
Field ref
Tags
Return values
boolget_workflow_states()
Utility to get all workflow states available in the system.
get_workflow_states() : array<string|int, mixed>
IMPORTANT: No permissions are being honoured on purpose! If you need to honour permissions @see get_editable_states()
Tags
Return values
array<string|int, mixed>get_workflow_state_names()
get_workflow_state_names() : array<string|int, mixed>
Return values
array<string|int, mixed>delete_resource_type_field()
Delete the specified metadata field. Also delets any node or resource_data rows associated with that field
delete_resource_type_field(int $ref) : bool|string
Parameters
- $ref : int
-
Metadata field id (ref from resource_type_field)
Return values
bool|string —Returns true on success or text on failure describing error
get_resource_table_joins()
get_resource_table_joins() : mixed
update_resource_lock()
update_resource_lock(mixed $ref, mixed $lockaction[, mixed $newlockuser = null ][, mixed $accesschecked = false ]) : mixed
Parameters
- $ref : mixed
- $lockaction : mixed
- $newlockuser : mixed = null
- $accesschecked : mixed = false
get_resource_lock_message()
get_resource_lock_message(mixed $lockuser) : mixed
Parameters
- $lockuser : mixed
get_external_shares()
Get details of external shares
get_external_shares(array<string|int, mixed> $filteropts) : array<string|int, mixed>
Parameters
- $filteropts : array<string|int, mixed>
-
Array of options to filter shares returned "share_group" - (int) Usergroup ref 'shared as' "share_user" - (int) user ID of share creator "share_order_by" - (string) order by column "share_sort" - (string) sortorder (ASC or DESC) "share_type" - (int) 0=view, 1=upload "share_collection" - (int) Collection ID "share_resource" - (int) Resource ID "access_key" - (string) Access key "ignore_permissions"- (bool) Show all shares, irrespective of permissions
Return values
array<string|int, mixed>get_video_duration()
Get video duration
get_video_duration(string $file_path) : float
Parameters
- $file_path : string
-
Path to video file
Tags
Return values
floatrelate_all_resources()
Relate all resources in the passed array with each other
relate_all_resources([array<string|int, mixed> $related = [] ]) : bool
Parameters
- $related : array<string|int, mixed> = []
-
Array of resource IDs
Return values
boolupdate_resource_type_field_order()
Apply new order to metadata fields
update_resource_type_field_order(array<string|int, mixed> $neworder) : void
Parameters
- $neworder : array<string|int, mixed>
-
Field IDs in new order
update_resource_type_order()
Apply a new order to resource types
update_resource_type_order(array<string|int, mixed> $neworder) : void
Parameters
- $neworder : array<string|int, mixed>
-
Resource type IDs in new order
allow_in_browser()
Check if file can be rendered in browser via download.php
allow_in_browser(string $path) : bool
Parameters
- $path : string
-
Path to file
Return values
boolupdate_resource_field_column()
Update the value of the fieldXX field on resource table
update_resource_field_column(int $resource, int $field, string $value) : bool
Parameters
- $resource : int
-
- Resource ID
- $field : int
-
- Metadata field ID
- $value : string
-
- Value
Return values
booldata_joins_field_value_translate_and_csv()
Convert $data_joins (ie fieldX column) value to a user friendly version.
data_joins_field_value_translate_and_csv(string|null $value) : string|null
IMPORTANT: csv in this context simply means user defined separator values (relies on $field_column_string_separator).
Text value will be:-
- split by the configued separator $field_column_string_separator;
- have all parts translated; (note: to correctly translate tree paths, a part will also be broken into path elements)
- glued back using the same separator
Parameters
- $value : string|null
-
Text to be processed
Return values
string|nullprocess_resource_data_joins_values()
Process resource data_joins (ie fieldX columns) values
process_resource_data_joins_values(array<string|int, mixed> $resource, array<string|int, mixed> $resource_table_joins) : array<string|int, mixed>
Parameters
- $resource : array<string|int, mixed>
-
A resource table record
- $resource_table_joins : array<string|int, mixed>
-
List of refs for the resource table data_joins. get_resource_table_joins()
Return values
array<string|int, mixed> —Returns the resource record with updated data_joins (ie fieldX columns) values
resource_has_access_denied_by_RT_size()
Check if resource has access denied by its type and for a size.
resource_has_access_denied_by_RT_size(int $resource_type, string $size) : bool
Parameters
- $resource_type : int
-
Resource type ref
- $size : string
-
Preview size ID (not ref).
Return values
boolrevert_resource_file()
Revert primary resource file based on log entry data
revert_resource_file(int $resource, array<string|int, mixed> $logentry[, bool $createpreviews = true ]) : bool
Parameters
- $resource : int
-
Resource ID
- $logentry : array<string|int, mixed>
-
Log data from get_resource_log(). Requires rse_version plugin to be enabled
- $createpreviews : bool = true
-
Create previews?
Return values
boolapply_resource_default()
When changing resource type, new resource type specific fields may become available. This function will apply any resource default values for resource type specific fields that were not previously available (i.e. not containing user data). This is used by upload then edit mode after switching resource types and also when locking the resource type with save and next.
apply_resource_default(int $old_resource_type, int $new_resource_type, int $resource) : void
Parameters
- $old_resource_type : int
-
Original resource type.
- $new_resource_type : int
-
Resource type being switched to.
- $resource : int
-
Resource id.
related_resource_pull()
Get a related resource to pull images from
related_resource_pull(array<string|int, mixed> $resource) : array<string|int, mixed>|bool
Parameters
- $resource : array<string|int, mixed>
-
Array of resource data from do_search()
Return values
array<string|int, mixed>|bool —$resdata Array of alternative resource data to use, or false if not configured or no resource image found
get_resource_preview()
Get the largest available preview URL for the given resource and the given array of sizes
get_resource_preview(array<string|int, mixed> $resource[, array<string|int, mixed> $sizes = [] ][, int $access = -1 ][, bool $watermark = false ][, int $page = 1 ][, bool $try_pulled_resource = true ][, int $alt = -1 ]) : array<string|int, mixed>|bool
Parameters
- $resource : array<string|int, mixed>
-
Array of resource data from get_resource_data() or search results
- $sizes : array<string|int, mixed> = []
-
Array of size IDs to look through, in order of size. If not provided will use all sizes
- $access : int = -1
-
Resource access
- $watermark : bool = false
-
Look for watermarked versions?
- $page : int = 1
-
Page to look for
- $try_pulled_resource : bool = true
-
Should we try to use an image from a pulled resource if the current resource doesn't have a usable preview
- $alt : int = -1
-
Int ref of alternative file
Return values
array<string|int, mixed>|bool —array, or false if no image is found
check_resources()
Check integrity of primary resource files
check_resources([array<string|int, mixed> $resources = [] ][, bool $presenceonly = false ]) : array<string|int, mixed>
Parameters
- $resources : array<string|int, mixed> = []
-
Array of resource data e.g. from search results
- $presenceonly : bool = false
-
Check for file presence only? If false (and if $file_checksums is enabled) then file checksums will be checked
Return values
array<string|int, mixed> —Array of resource IDs that have failed to verify
get_resources_to_validate()
Get an array of all resources that require files to be validated
get_resources_to_validate([int $days = 0 ]) : array<string|int, mixed>
Parameters
- $days : int = 0
-
Return only resources not validated in the last X number of days
Return values
array<string|int, mixed>acl_can_edit_resource_of_type()
Access control check that user can edit (a resource) of a particular Resource Type (RT). Main use is to hide inapplicable RTs.
acl_can_edit_resource_of_type(int $ref) : bool
Parameters
- $ref : int
-
Resource type ID
Return values
boolcan_upload_preview_image()
Check if current user can upload a preview image
can_upload_preview_image(int $ref) : bool
Parameters
- $ref : int
-
Resource ID
Return values
boolresource_has_preview_source()
Check if a resource has a file to derive previews from.
resource_has_preview_source(int $ref, string $extension[, int $alternative = -1 ]) : bool
Parameters
- $ref : int
-
Resource ID
- $extension : string
-
Resource file extension
- $alternative : int = -1
-
Alternative file record ID
Return values
boolacl_can_edit_contributed_by()
Access control check that user can edit a resources 'Contributed by' field
acl_can_edit_contributed_by() : bool