functions

Once you start building applications, you will add PHP code to events. Below is a list of pre-set functions you can use

functiondescriptionprototypereturnsNotes
clean_htmlClean HTML string removing all element attributes and elements which are not in the provided whitelist (but keeping their allowed children).function clean_html($html, array $whitelist)sanitized htmlbased upon https://github.com/alixaxel/phunction/blob/master/phunction/HTML.php
closeSessionCloses the session by unsetting it, destroying it, closes the write buffer and clears the session cookie.function closeSession()nothing
getGUIDRetrieves a unique stringfunction getGUID()stringReturns a string that can be used for validation situations, i.e. for confirming credentials etc. In PHsPeed this string is used to let users validate their account.
getProtocolReturns the used protocol as HTTP: or HTTPS: function getProtocol()HTTP: or HTTPS:
inPostStateTests if the form has received form data or is in it's initials statefunction inPostState();true or falseif(inPostState() ){…}
getSessionVarGets a session variablefunction getSessionVar($theVar, $default='')stringThis function gets a session variable that is maintained over the same session. If the variable does not exists it returns the default value. I.e. getSessionVar('myVar', 'nothing');
isAjaxTests if the current module takes part in an Ajax handlerfunction isAjax()true or falseif(isAjax()) { … }
isHTTPSTests if the URL runs under httpsfunction isHTTPS()true or falseif(isHTTPS()) { …}
isLoggedOnTestst if the current users is logged onfunction isLoggedOn()true or falseif(isLoggedOn()) { … }
isTrueTest if a value is true or false. The function returns 'true' if the given parameter has one of the folowing values: 't','T','y','Y','true','TRUE','yes','YES'function isTrue($string)true or falseif(isTrue('Y')) {…}
phspCryptEncrypts and Decrypts data.function phspCrypt($string, $mode)stringavailable modes are: 'e' for encryption and 'd' for description. The key and salt used is setup in the project properties. This function is used by PHsPeed to store database credentials, emailing options etc. Once set in the IDE then do not change as this will make the encrypted files unreadable.

Sample: $mystr=phspCrypt($enc, 'e');
phspCreateLinkCreates a link that can be used for redirecting to other modules. It automatically appends the phspeed token for security and the result is encrypted. Parameters become available as session variables in the requested application.function phspCreateLink($url, $parms)nothingSample: hspCreateLink('myapp.php', 'name=abc';
phspHashreturns hash.function phspHashB64($str, $algo='sha256')string
phspHashB64returns base64 encoded hashfunction phspHashB64($str, $algo='sha256')string
phspHMacreturn hmac hashfunction phspHMac($str, $algo='sha256')string
phspRedirectRedirects current form to another page. See phspCreateLink. for details.function phspRedirect($url, $origin, $parms)nothingRedirects to another module. Origin is optionas and can be used to pass the current module as a recepient.
rtrCmd()Returns application commandfunction rtrCmd()stringUsed to retrieve commands from the application.
rtrSender()Returns the sending applicationfunction rtrSender()string
rtrSubmitBtnRetrieves the id of the button clickedfunction rtrSubmitBtn();stringThis function will return the button clicked. It is only to be used in the submit process and is not usable in ajax events. If you have more buttons on the form and want to take action depending on the submit button clicked then this function is useful.
Sample:

$key=rtrSubmitBtn();
if($key=='mail_btn_1') { …. }

The name of the button is the name that is used in its constructor (#module _ #name). So if the PHP modules name is 'myapp' and the button is called 'mybtn' then the function would return 'myapp_mybtn';
session_stopReleases session variables and closes current sessionfunction session_stop()nothingThis function will prevent data to be saved in a reusable session cookie after termination of the application.
setLoggedOffLogs a user off, clears internal buffersfunction setLoggedOff()nothing
setLoggedOnSet the logon status for a certain user (depending on RBA module)function setLoggedOn($usernum='generic')true/false
setSessionVarSets a session variablefunction setSessionVar($theVar, $theVal)nothingThis function sets a session variable that is maintained over the same session. I.e. setSessionVar('myVar', $value);
sessionVarExistsChecks if the session variable exists.function sessionVarExists($theVar) {true or false
unsetSessionVarClears the variable and removes it from the sessionstack.function unsetSessionVar($theVar)nothing
functiondescriptionprototypereturnsNotes
showMessageDisplays a modal messageshowMessage($msg)nothing
In general this function can be used to submit and in ajax stage to display a popup message, but only on events that passes the $app object.

Example: $app→showMessage('process complete');

See also macro notation (@@showMessage('…');
setSessionVarSets a session variablefunction setSessionVar($theVar, $value)nothingThis function sets a session variable that is maintained over the same session.
functiondescriptionprototypereturnsNotes
@@login(…)will be translated to $app→login(…) For some commonly used functions, it is more convenient to use the @@ notation as PHsPeed will 'know' in what module the function resides. So you don't have to remember that login is part of the $app.
@@showMessagewill be translated to $app>showMessage(…)


  • functions.txt
  • Last modified: 2020/07/15 14:19
  • by aducomadmin