PHPDevShell Utilities
2010-01-25 22:57:53   来源:   评论:0 点击:


Put your file(s) inside the "includes" folder, then list them in the configuration as follow:

$configuration['functions'] = array('utils.php');

From now on, all listed files will be included automatically, therefore any functions (and classes) defined in theses files will be available in every script.



URL related

These functions are made to make building URL easier, specifically the GET values. The parameters can be seen as an associative array (as the superglobal $_GET), into which you can add/change pairs and from which you can delete elements. The functions then concatenates the content into a string which can be use inside a URL.


function PU_BuildGET ($includeInGet = null, $excludeFromGet = null, $glue = '&')
Actually concatenates a string based on the current content of $_GET, which the pairs from $includeInGet included, and the list from $excludeFromGet removed, bound together which the $glue string. Note that the default glue ('&') is adapted to HTML, if you want to use for example in JavaScript, you should set it to a single '&'. Note also that the resulting string is prefixed with '?' (to be concatenated to an address part of the URL) if needed, which means an empty result would give an empty string (not a single '?').


function PU_BuildURL ($target = null, $includeInGet = null, $excludeFromGet = null, $glue = '&')
This function builds on the previous one and deal with the address part. The target is supposed to be raw URL of the targeted script (not related to the "target" parameter of HTML links), and defaults to the current script. It's handy even in the simplest form:
would give a complete URL pointing to the current script, keeping all current GET parameters along (useful for script handling forms).


function PU_BuildHREF ($label, $includeInGet = null, $excludeFromGet = null, $target = null)
This function is an extention of the previous one; it does the same job but also encapsulate inside HTML link tag ('<a>'), with $label being the underlined word.


Let's say the current script is


code result
PU_BuildGET(null, 'action') ?id=123456
PU_BuildGET(null, array('action', 'id)) (empty string)
PU_BuildGET(array('cancel'), 'action') ?id=123456&cancel
PU_BuildGET(array('cancel' => true), 'action') ?id=123456&cancel=true
PU_BuildURL(null, null, 'action')
PU_BuildURL('/check_id.html', null, 'action') /check_id.html?id=123456
PU_BuildHREF('Check me', '/check_id.html', null, 'action') <a href="/check_id.html?id=123456">Check me<a>


string related

Building a HTML page is simple as it is a long text; however, not being careful with the string you include in that text can lead to non-functional pages, visual quirks, or even security failures. Theses function will help you secure your HTML.


function PU_CleanString ($string, $clean_htlm = false)
This function cleans a string be removing so-called "escape characters" (namely single and double quotes, and backslashes). If asked, it will also removed any XML marking (ie anything between < and >). The resulting string can then be included into a form, for example. Please note the bad parts are actually REMOVED, not converted.


function PU_MakeString ($string, $htmlize = false)
This function converts a latin or UTF string into a UTF8 string. Useful when you're not sure which encoding the input string is in. If $htmlize is true, the content is also converted to HTML, so it appears correctly in the page.


AJAX related

PHPDevShell tries to make ajax support easier. The same way you can have a single page for form display and handling, you can have a single page HTML and AJAX with this call:

function PU_isAJAX ($json = false)
This function returns true is the page is requested the AJAX way. If $json is true, is also flushes all current HTML in the buffers, and sets the headers so you then just "print" json data.


上一篇:PHPDevShell Database access
下一篇:PHPDevShell Templates and Typography

分享到: 收藏