Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401] [Versions 401 and 402] [Versions 401 and 403]

(no description)

Author: Nicola Asuni
Version: 1.1.2
File Size: 2670 lines (111 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: TCPDF_STATIC  - X-Ref


getTCPDFVersion()   X-Ref
Return the current TCPDF version.

return: string TCPDF version string

getTCPDFProducer()   X-Ref
Return the current TCPDF producer.

return: string TCPDF producer string

set_mqr($mqr)   X-Ref
Sets the current active configuration setting of magic_quotes_runtime (if the set_magic_quotes_runtime function exist)

param: boolean $mqr FALSE for off, TRUE for on.

get_mqr()   X-Ref
Gets the current active configuration setting of magic_quotes_runtime (if the get_magic_quotes_runtime function exist)

return: int Returns 0 if magic quotes runtime is off or get_magic_quotes_runtime doesn't exist, 1 otherwise.

isValidURL($url)   X-Ref
Check if the URL exist.

param: string $url URL to check.
return: boolean true if the URl exist, false otherwise.

removeSHY($txt='', $unicode=true)   X-Ref
Removes SHY characters from text.
Unicode Data:<ul>
<li>Name : SOFT HYPHEN, commonly abbreviated as SHY</li>
<li>HTML Entity (decimal): "&amp;#173;"</li>
<li>HTML Entity (hex): "&amp;#xad;"</li>
<li>HTML Entity (named): "&amp;shy;"</li>
<li>How to type in Microsoft Windows: [Alt +00AD] or [Alt 0173]</li>
<li>UTF-8 (hex): 0xC2 0xAD (c2ad)</li>
<li>UTF-8 character: chr(194).chr(173)</li>
</ul>

param: string $txt input string
param: boolean $unicode True if we are in unicode mode, false otherwise.
return: string without SHY characters.

getBorderMode($brd, $position='start', $opencell=true)   X-Ref
Get the border mode accounting for multicell position (opens bottom side of multicell crossing pages)

param: string|array|int $brd Indicates if borders must be drawn around the cell block. The value can be a number:<ul><li>0: no border (default)</li><li>1: frame</li></ul>or a string containing some or all of the following characters (in any order):<ul><li>L: left</li><li>T: top</li><li>R: right</li><li>B: bottom</li></ul> or an array of line styles for each border group: array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
param: string $position multicell position: 'start', 'middle', 'end'
param: boolean $opencell True when the cell is left open at the page bottom, false otherwise.
return: array border mode array

empty_string($str)   X-Ref
Determine whether a string is empty.

param: string $str string to be checked
return: bool true if string is empty

getObjFilename($type='tmp', $file_id='')   X-Ref
Returns a temporary filename for caching object on filesystem.

param: string $type Type of file (name of the subdir on the tcpdf cache folder).
param: string $file_id TCPDF file_id.
return: string filename.

_escape($s)   X-Ref
Add "\" before "\", "(" and ")"

param: string $s string to escape.
return: string escaped string.

_escapeXML($str)   X-Ref
Escape some special characters (&lt; &gt; &amp;) for XML output.

param: string $str Input string to convert.
return: string converted string

objclone($object)   X-Ref
Creates a copy of a class object

param: object $object class object to be cloned
return: object cloned object

sendOutputData($data, $length)   X-Ref
Output input data and compress it if possible.

param: string $data Data to output.
param: int $length Data length in bytes.

replacePageNumAliases($page, $replace, $diff=0)   X-Ref
Replace page number aliases with number.

param: string $page Page content.
param: array $replace Array of replacements (array keys are replacement strings, values are alias arrays).
param: int $diff If passed, this will be set to the total char number difference between alias and replacements.
return: array replaced page content and updated $diff parameter as array.

getTimestamp($date)   X-Ref
Returns timestamp in seconds from formatted date-time.

param: string $date Formatted date-time.
return: int seconds.

getFormattedDate($time)   X-Ref
Returns a formatted date-time.

param: int $time Time in seconds.
return: string escaped date string.

getRandomSeed($seed='')   X-Ref
Returns a string containing random data to be used as a seed for encryption methods.

param: string $seed starting seed value
author: Nicola Asuni
return: string containing random data

_md5_16($str)   X-Ref
Encrypts a string using MD5 and returns it's value as a binary string.

param: string $str input string
return: string MD5 encrypted binary string

_AES($key, $text)   X-Ref
Returns the input text encrypted using AES algorithm and the specified key.
This method requires openssl or mcrypt. Text is padded to 16bytes blocks

param: string $key encryption key
param: string $text input text to be encrypted
author: Nicola Asuni
return: string encrypted text

_AESnopad($key, $text)   X-Ref
Returns the input text encrypted using AES algorithm and the specified key.
This method requires openssl or mcrypt. Text is not padded

param: string $key encryption key
param: string $text input text to be encrypted
author: Nicola Asuni
return: string encrypted text

_RC4($key, $text, &$last_enc_key, &$last_enc_key_c)   X-Ref
Returns the input text encrypted using RC4 algorithm and the specified key.
RC4 is the standard encryption algorithm used in PDF format

param: string $key Encryption key.
param: string $text Input text to be encrypted.
param: string $last_enc_key Reference to last RC4 key encrypted.
param: string $last_enc_key_c Reference to last RC4 computed key.
author: Klemen Vodopivec, Nicola Asuni
return: string encrypted text

getUserPermissionCode($permissions, $mode=0)   X-Ref
Return the permission code used on encryption (P value).

param: array $permissions the set of permissions (specify the ones you want to block).
param: int $mode encryption strength: 0 = RC4 40 bit; 1 = RC4 128 bit; 2 = AES 128 bit; 3 = AES 256 bit.
author: Nicola Asuni

convertHexStringToString($bs)   X-Ref
Convert hexadecimal string to string

param: string $bs byte-string to convert
author: Nicola Asuni
return: string

convertStringToHexString($s)   X-Ref
Convert string to hexadecimal string (byte string)

param: string $s string to convert
author: Nicola Asuni
return: string byte string

getEncPermissionsString($protection)   X-Ref
Convert encryption P value to a string of bytes, low-order byte first.

param: string $protection 32bit encryption permission value (P value)
author: Nicola Asuni
return: string

encodeNameObject($name)   X-Ref
Encode a name object.

param: string $name Name object to encode.
author: Nicola Asuni
return: string Encoded name object.

getAnnotOptFromJSProp($prop, &$spot_colors, $rtl=false)   X-Ref
Convert JavaScript form fields properties array to Annotation Properties array.

param: array $prop javascript field properties. Possible values are described on official Javascript for Acrobat API reference.
param: array $spot_colors Reference to spot colors array.
param: boolean $rtl True if in Right-To-Left text direction mode, false otherwise.
author: Nicola Asuni
return: array of annotation properties

formatPageNumber($num)   X-Ref
Format the page numbers.
This method can be overridden for custom formats.

param: int $num page number
return: string

formatTOCPageNumber($num)   X-Ref
Format the page numbers on the Table Of Content.
This method can be overridden for custom formats.

param: int $num page number
return: string

extractCSSproperties($cssdata)   X-Ref
Extracts the CSS properties from a CSS string.

param: string $cssdata string containing CSS definitions.
author: Nicola Asuni
return: array An array where the keys are the CSS selectors and the values are the CSS properties.

fixHTMLCode($html, $default_css, $tagvs, $tidy_options, &$tagvspaces)   X-Ref
Cleanup HTML code (requires HTML Tidy library).

param: string $html htmlcode to fix
param: string $default_css CSS commands to add
param: array|null $tagvs parameters for setHtmlVSpace method
param: array|null $tidy_options options for tidy_parse_string function
param: array $tagvspaces Array of vertical spaces for tags.
author: Nicola Asuni
return: string XHTML code cleaned up

isValidCSSSelectorForTag($dom, $key, $selector)   X-Ref
Returns true if the CSS selector is valid for the selected HTML tag

param: array $dom array of HTML tags and properties
param: int $key key of the current HTML tag
param: string $selector CSS selector string
return: true if the selector is valid, false otherwise

getCSSdataArray($dom, $key, $css)   X-Ref
Returns the styles array that apply for the selected HTML tag.

param: array $dom array of HTML tags and properties
param: int $key key of the current HTML tag
param: array $css array of CSS properties
return: array containing CSS properties

getTagStyleFromCSSarray($css)   X-Ref
Compact CSS data array into single string.

param: array $css array of CSS properties
return: string containing merged CSS properties

intToRoman($number)   X-Ref
Returns the Roman representation of an integer number

param: int $number number to convert
return: string roman representation of the specified number

revstrpos($haystack, $needle, $offset = 0)   X-Ref
Find position of last occurrence of a substring in a string

param: string $haystack The string to search in.
param: string $needle substring to search.
param: int $offset May be specified to begin searching an arbitrary number of characters into the string.
return: int|false Returns the position where the needle exists. Returns FALSE if the needle was not found.

getHyphenPatternsFromTEX($file)   X-Ref
Returns an array of hyphenation patterns.

param: string $file TEX file containing hypenation patterns. TEX patterns can be downloaded from http://www.ctan.org/tex-archive/language/hyph-utf8/tex/generic/hyph-utf8/patterns/
author: Nicola Asuni
return: array of hyphenation patterns

getPathPaintOperator($style, $default='S')   X-Ref
Get the Path-Painting Operators.

param: string $style Style of rendering. Possible values are:
param: string $default default style
author: Nicola Asuni
return: string

getTransformationMatrixProduct($ta, $tb)   X-Ref
Get the product of two SVG tranformation matrices

param: array $ta first SVG tranformation matrix
param: array $tb second SVG tranformation matrix
author: Nicola Asuni
return: array transformation array

getSVGTransformMatrix($attribute)   X-Ref
Get the tranformation matrix from SVG transform attribute

param: string $attribute transformation
author: Nicola Asuni
return: array of transformations

getVectorsAngle($x1, $y1, $x2, $y2)   X-Ref
Returns the angle in radiants between two vectors

param: int $x1 X coordinate of first vector point
param: int $y1 Y coordinate of first vector point
param: int $x2 X coordinate of second vector point
param: int $y2 Y coordinate of second vector point
author: Nicola Asuni

pregSplit($pattern, $modifiers, $subject, $limit=NULL, $flags=NULL)   X-Ref
Split string by a regular expression.
This is a wrapper for the preg_split function to avoid the bug: https://bugs.php.net/bug.php?id=45850

param: string $pattern The regular expression pattern to search for without the modifiers, as a string.
param: string $modifiers The modifiers part of the pattern,
param: string $subject The input string.
param: int $limit If specified, then only substrings up to limit are returned with the rest of the string being placed in the last substring. A limit of -1, 0 or NULL means "no limit" and, as is standard across PHP, you can use NULL to skip to the flags parameter.
param: int $flags The flags as specified on the preg_split PHP function.
author: Nicola Asuni
return: array Returns an array containing substrings of subject split along boundaries matched by pattern.modifier

fopenLocal($filename, $mode)   X-Ref
Wrapper to use fopen only with local files

param: string $filename Name of the file to open
param: string $mode
return: resource|false Returns a file pointer resource on success, or FALSE on error.

url_exists($url)   X-Ref
Check if the URL exist.

param: string $url URL to check.
return: bool Returns TRUE if the URL exists; FALSE otherwise.

encodeUrlQuery($url)   X-Ref
Encode query params in URL

param: string $url
return: string

file_exists($filename)   X-Ref
Wrapper for file_exists.
Checks whether a file or directory exists.
Only allows some protocols and local files.

param: string $filename Path to the file or directory.
return: bool Returns TRUE if the file or directory specified by filename exists; FALSE otherwise.

fileGetContents($file)   X-Ref
Reads entire file into a string.
The file can be also an URL.

param: string $file Name of the file or URL to read.
author: Nicola Asuni
return: string|false The function returns the read data or FALSE on failure.

_getULONG($str, $offset)   X-Ref
Get ULONG from string (Big Endian 32-bit unsigned integer).

param: string $str string from where to extract value
param: int $offset point from where to read the data
author: Nicola Asuni
return: int 32 bit value

_getUSHORT($str, $offset)   X-Ref
Get USHORT from string (Big Endian 16-bit unsigned integer).

param: string $str string from where to extract value
param: int $offset point from where to read the data
author: Nicola Asuni
return: int 16 bit value

_getSHORT($str, $offset)   X-Ref
Get SHORT from string (Big Endian 16-bit signed integer).

param: string $str String from where to extract value.
param: int $offset Point from where to read the data.
author: Nicola Asuni
return: int 16 bit value

_getFWORD($str, $offset)   X-Ref
Get FWORD from string (Big Endian 16-bit signed integer).

param: string $str String from where to extract value.
param: int $offset Point from where to read the data.
author: Nicola Asuni
return: int 16 bit value

_getUFWORD($str, $offset)   X-Ref
Get UFWORD from string (Big Endian 16-bit unsigned integer).

param: string $str string from where to extract value
param: int $offset point from where to read the data
author: Nicola Asuni
return: int 16 bit value

_getFIXED($str, $offset)   X-Ref
Get FIXED from string (32-bit signed fixed-point number (16.16).

param: string $str string from where to extract value
param: int $offset point from where to read the data
author: Nicola Asuni
return: int 16 bit value

_getBYTE($str, $offset)   X-Ref
Get BYTE from string (8-bit unsigned integer).

param: string $str String from where to extract value.
param: int $offset Point from where to read the data.
author: Nicola Asuni
return: int 8 bit value

rfread($handle, $length)   X-Ref
Binary-safe and URL-safe file read.
Reads up to length bytes from the file pointer referenced by handle. Reading stops as soon as one of the following conditions is met: length bytes have been read; EOF (end of file) is reached.

param: resource $handle
param: int $length
author: Nicola Asuni
return: string|false Returns the read string or FALSE in case of error.

_freadint($f)   X-Ref
Read a 4-byte (32 bit) integer from file.

param: resource $f file resource.
return: int 4-byte integer

getPageSizeFromFormat($format)   X-Ref
Get page dimensions from format name.

param: mixed $format The format name @see self::$page_format<ul>
return: array containing page width and height in points

setPageBoxes($page, $type, $llx, $lly, $urx, $ury, $points, $k, $pagedim=array()   X-Ref
Set page boundaries.

param: int $page page number
param: string $type valid values are: <ul><li>'MediaBox' : the boundaries of the physical medium on which the page shall be displayed or printed;</li><li>'CropBox' : the visible region of default user space;</li><li>'BleedBox' : the region to which the contents of the page shall be clipped when output in a production environment;</li><li>'TrimBox' : the intended dimensions of the finished page after trimming;</li><li>'ArtBox' : the page's meaningful content (including potential white space).</li></ul>
param: float $llx lower-left x coordinate in user units.
param: float $lly lower-left y coordinate in user units.
param: float $urx upper-right x coordinate in user units.
param: float $ury upper-right y coordinate in user units.
param: boolean $points If true uses user units as unit of measure, otherwise uses PDF points.
param: float $k Scale factor (number of points in user unit).
param: array $pagedim Array of page dimensions.
return: array pagedim array of page dimensions.

swapPageBoxCoordinates($page, $pagedim)   X-Ref
Swap X and Y coordinates of page boxes (change page boxes orientation).

param: int $page page number
param: array $pagedim Array of page dimensions.
return: array pagedim array of page dimensions.

getPageLayoutMode($layout='SinglePage')   X-Ref
Get the canonical page layout mode.

param: string $layout The page layout. Possible values are:<ul><li>SinglePage Display one page at a time</li><li>OneColumn Display the pages in one column</li><li>TwoColumnLeft Display the pages in two columns, with odd-numbered pages on the left</li><li>TwoColumnRight Display the pages in two columns, with odd-numbered pages on the right</li><li>TwoPageLeft (PDF 1.5) Display the pages two at a time, with odd-numbered pages on the left</li><li>TwoPageRight (PDF 1.5) Display the pages two at a time, with odd-numbered pages on the right</li></ul>
return: string Canonical page layout name.

getPageMode($mode='UseNone')   X-Ref
Get the canonical page layout mode.

param: string $mode A name object specifying how the document should be displayed when opened:<ul><li>UseNone Neither document outline nor thumbnail images visible</li><li>UseOutlines Document outline visible</li><li>UseThumbs Thumbnail images visible</li><li>FullScreen Full-screen mode, with no menu bar, window controls, or any other window visible</li><li>UseOC (PDF 1.5) Optional content group panel visible</li><li>UseAttachments (PDF 1.6) Attachments panel visible</li></ul>
return: string Canonical page mode name.