To increase performance, several functions that are not used on every call are not loaded. Instead, only an interface file with such functions is called to set up their possible use - only by explicitly calling a function, the file is loaded/parsed, thus reducing load times overall.
The interface, located at
sys/LazyDummy/lazyinterface.php defines a singleton class
LazyDummy (which is aliased to
LD) which defines the interface of all functions. Each function have its own separate php file inside the
sys/LazyDummy/ folder. To call any of these functions, just precede it with
LazyDummy::, below is a complete list of such functions (these are the interface definitions, do not copy&paste to use as they include conditional variables and reference pointers ... we all assume you are not as Dummy on PHP, only in Dummy framework!) :
readFile ( $file, $removeBOM = true )- simply reads a local file and return its contents. It will remove the UTF8
BOMmarker from start of the file if one is present.
writeFile ($file, $content, $append=false, $binary=false )- writes a local file with the defined content. If you don't want to replace but rather append into the file, set
$append=true. To prevent end-of-line conversions, use
serveFile ( &$Dummy, $file, $ext="", $exit=true, $filename="", $forceAttach = false, $cachetime=6000 )- will output a given local file to the user. The extension is usually derived from the file but you can force another extension treatment by setting it on
$ext. The filename is also from the file, but you can force another filename to be served setting
$filename(with extension). The default serving mode is inline (will try to display on the browser), but you can force a download by setting
$forceAttach. Finally, a cache tag will be sent by headers, default to 6000 minutes (100 hours), which again you can override. If $exit is set (default), the script will end after the file is served.
removeSimbols ($data, $separator="_")- will remove all characters other than non western letters and numbers, changing them into the specified
$separator, good to transform a filename to be stored in the local filesystem.
safe_mkdir ( $path, $mode=0777 )- creates a folder and sets its umask. Note the umask number must be preceded by a "0" like in the function interface. This function is usually called internally.
truncate ($content, $size=50, $final="…", $stripHTML=false, $preserveEOL=false )- truncates a string at the defined length and appends the final ellipsis (or any other string). The resulting string will never exceed
$size, so if it is truncated, it will further truncate the length of $final to fit. This is utf8 safe (note that the ellipsis is a utf8 single character). You can further request all HTML to be stripped, and to preserve End Of Lines (
</p>will be converted/kept to HTML
stripHTML ($str, $preserveEndOfLine=false)- removes HTML code from the string, including scripts and styles. It will properly parse even if a script or style tag is not finished. Setting
htmlentities_ex ( $str )- uses htmlentities but also converts some latin characters to their appropriate amp codes.
utf8_truncate ( $str, $size )- truncates a UTF8 string safely. It will try to use
mb_strimwidthif possible. Basically called by truncate function.
listFiles ($path, $eregfilter='', $orddata = false, $ordname = false, $recurse = false )- returns an array with all files that match the $eregfilter in the defined path. Optionally you can request the list to be ordered by data or name, and to recurse (will return sub-folders contents)
loadURL ( $url, $agent="PHP", $method="get", $retry=1, $timeout=100 )- loads a remote URL using either GET or POST, supports authentication by URL, multiple retries and custom timeout. It does basically what fopen with some different options. Returns false on fail, or the string on success.
getYoutubeViews ( $code, $getLikes=false, $retry=1 )- uses loadURL to load an Youtube video ($code should only be the video code, not the full url) and returns an array of data about the video (basically all the
meta itemprop). If
$getLikesis specified, will try to get the number of likes the video has in "likes" (as of now, it looks for the text "like this video along with XX people" since like count is not inside any tag. It will also return "views", which is just an alias for "interactionCount". Returns false if it fails to open the URL or the
meta itempropfails, an array otherwise. This function allows gathering of a video data without the need of an Youtube API key.
checkQuery ( $queryArray )- A fast way to validade
$_REQUESTvariables. Check if the variables in the
$queryArrayarray are present. If you start a variable with "#", it will also validate it is numeric. Returns true if all variables are present in
$_REQUEST(and the ones started with # are numeric), false if anyone is missing (or not numeric)
captcha ( $tag ,$checkStage=false)- This function works in two modes defined by
$checkStageis false, it will generate a new captcha number (4 digits), store in session and replace the template tag of same name with the captcha (a simple mix of tags - this is really a very basic captcha). Note this function works only for the Dummy framework since it uses the
$Dummyobject internally. If
$checkStageis true, will check if the captcha of same name (tag) is present and correct from
$_REQUEST. If it is correct, it will keep the
$_GETvariables set, otherwise it will unset them. The code should check for the presence of either of them to determine if the captcha was correct (if they are unset, it basically means they weren't)
isMail ( $mail, $Allowextended=false)- Uses a
$Allowextendedis set, will also validate mail in the format "Name <mail>"
getMime ( $ext )- simply returns the mime-type (string) for the file extension provided. Used mostly by the serveFile.
getMimeMode ($ext, $viewMode=false)- Returns true if the extension can (usually) be displayed on a browser, false if not. For formats that can be seen but you might like it rather have it downloaded, will use the specified in $viewMode (for instance, a video file). Used mostly by the serveFile.
sendMail ( $mailto ,$subject, $mail, $mailFrom="", $header="", $isHTML=true, $attach="")- basically an extension of default php
$mailFrom(which, if not set, is defined as the same address as
$mailto). It supports UTF-8 subjects (also in
$mailFrom) if not set, and allows mails to be sent on either HTML or simple text. It supports attachments (
$attachshould be a local file), at which point turns the mail in a
multipartformat by default. Also, it accepts
$Dummy->viewobject as the mail content (or plain text), and will try sending mail using the
-f(first try) or
-rmail modes. Returns true or false depending on success of submitting.
getBrowser()- Returns an array with the user agent browser. The array contents are as follows: Browser name (string), true|false for legacy mode (old browser), true|false for mobile browser, Operating System (string), Browser Code (2-character string: IE, FF, OP, AN, CH, SA, MO, KO, UN for respectively Internet Explorer (or Edge), Firefox, Opera, Android Browser, Chrome, Safari, Konqueror, Mobile Browser and Unknown Browser - usually a bot) and Browser version. It will always return UN type if it is a known bot from the
CONS_BOT_WHITELISTlist. The Operating System can be "Windows", "Android", "Linux", "Mac OS" (for iPhone, iPad or Macs) and "??". Note that a MO code is used for Blackberry, SonyEricsson, MOBILE/ and any known valid mobile browser, while the mobile flag (3° array item) will be set to true or false depending on settings on the browser, but is always true for these.
getVideoFrame( $code, $w=640, $h=480, $class="" )- returns a string of an
IFRAMEthat creates a valid player window for Youtube or Vimeo.
$codeis the video code (vimeo codes are always numeric, thus the ease of switching between both).
$classis applied in the
IFRAMEobject, which always have the allow-full-screen tag set.
storeFile ( $file, &$destination, $type="", $completeDebug=false )- a complete function for file uploads (or virtual file uploads). It will store a file (index of
$_FILES) into the destination (by reference because it returns the local file it actually stored, should arrive without extension). It accepts multiple types and will process the file accordingly:
auto - any file
image - any known image file format
html - any known HTML file format
docs - any known document file like docs, xml, rtf and so on
udef: - allows user-defined file formats in the form of udef:format,format,....
It allows virtual uploads, in which a file was not actually sent as an upload but you rather want to use this function facilities. To do so, just fill the
$_FILES[$file]variable with the proper array with
tmp_namewith current file location and
virtual=trueto enable virtual handling.
The function will test if the uploaded file matches the type (for images, it will even open the file and gather internal data to be sure). It will also validate .ZIP and .RAR files. After a successful upload, type-testing and copying, it will set chmod 0775.
If $completeDebug is set, will echo error messages during processing. The function will return a numeric error code as follows:
0 - Upload ok (see $destination for file with extension)
1 - Error, file larger than server-side permission
2 - Error, file larger than client-side permission (MAX_FILE_SIZE)
3 - Incomplete download (might be triggered if your upload form did not have a multipart encode, or there is no write permission on server). Dot files are not allowed and will usually trigger this error.
4 - No file sent
5 - Invalid extension
7 - File contents differs from extension (images, zip or rar are internally tested)
Important: as default, this function will not allow scripts to be uploaded. They will be renamed to .html
resizeImageCond ( $image, $maxw=500, $maxh=500, $watermarkArray=array(), $bg="FFFFFF", $forceJPG=false)
This function will only reduce images, and will only do any function at all if the image is larger than specified by
As with other image editing functions, this will accept a
$watermarkArrayfor adding layers (see documentation on watermark function), and a default background
$bgif the image is transparent but you force the new image to JPG with
resizeImage ( $original, $miniature, $desiredW=100, $desiredH=100, $quality=0, $watermarkArray=array(), $bgcolor="FFFFFF", $forceJPG=false )
$originalfile into a
$miniaturefile. Notice that the $miniature should be passed as reference because a new name (with extension) will be returned in this variable.
$desiredHare about the miniature size, but note this function will preserve proportions, thus these dimensions are "desired", the end image might have one different (smaller) dimension, unless you send the crop flag (see below). You can then specify the JPG
$watermarkArrayof changed (see watermark function), a default
$bgcolorif a transparent image turns opaque during the watermark process or by your own setting to force the output for JPG in
Note that, for this function only, if the first item in the
$watermarkArrayis string "C" (Crop flag), the miniature will adhere to the
$desiredHand perform a crop to fit. The crop is always centered, so if a crop is required to fit the dimensions, it will either crop (same size) top and bottom, or left and right.
watermark ( $sourceFile, $watermarkArray, $destination, $quality=0, $bgcolor="FFFFFF", $forcejpg=false)
Adds files (watermarks) on the
$watermarkArrayand outputs into
$destination. You can specify the JPG
$quality(if the image being processed is an JPG), a
$bgcolorif the image is transparent but the output isn't (possibly due to forcing the output with
The watermarkArray is an array of changes to be made on the image. Each item is an Array in the following format:
'filename' = name of the filename that will be watermarked up or down;
'position' = array(x,y) for where this image will be put. Use negative values to start from right or bottom;
'resample' = array(width,height) will resize the watermark to this set values (optional);
'isBack' = will use this image as a background, rather than a watermark, so the current working file will be on top. Will resize to match the working file (thus, ignores position and resample)
cleanString ($data, $ishtml=false, $allowadv=false, $dbo=false )
This function cleans up a string usually for use in SQL queries, though it can be used for any purpose.
$ishtmlis specified, it will remove most tags that cannot come inside the <body> of a HTML file (thus, beware), or simply break all tags by replacing < with <. While you allow
$ishtml, you can also disable or not advanced tags that could insert content into your site, like scripts, iframes, forms, embed and others by setting
After parsing the HTML as stated above, it will call the database's escape function (thus you need to send the database object in
$dbo) to properly escape the function (if you don't have a database object, it will use addslashes), and further remove single and double quotes (single quotes into ' and double quotes to ")
Other LazyDummy functions are used internally by optional features like statistics and the administrative pane.