| Publicity: |
|---|
| [Public Only | All] |
Provides a variety of non-ACS-specific utilities, including the procs to support the who's online feature.
- Location:
- packages/acs-tcl/tcl/utilities-procs.tcl
- Created:
- 13 April 2000
- Author:
- Various <acs@arsdigita.com>
- CVS Identification:
$Id: utilities-procs.tcl,v 1.116 2009/02/13 20:28:08 jeffd Exp $
NsSettoTclString (public)NsSettoTclString set_id returns a plain text version of the passed ns_set id |
ReturnHeaders (public)ReturnHeaders [ content_type ] We use this when we want to send out just the headers and then do incremental writes with ns_write. This way the user doesn't have to wait for streamed output (useful when doing bulk uploads, installs, etc.). It returns status 200 and all headers including any added to outputheaders. |
ad_block_sql_urls (public)ad_block_sql_urls conn args why Deprecated. |
ad_cache_returnredirect (public)ad_cache_returnredirect url [ persistent ] [ excluded_vars ] An addition to ad_returnredirect. It caches all variables in the redirect except those in excluded_vars and then calls ad_returnredirect with the resultant string. |
ad_call_proc_if_exists (public)ad_call_proc_if_exists proc [ args... ] Calls a procedure with particular arguments, only if the procedure is defined. |
ad_dbclick_check_dml (public)ad_dbclick_check_dml [ -bind bind ] statement_name table_name \
id_column_name generated_id return_url insert_dml
This proc is used for pages using double click protection. table_name is table_name for which we are checking whether the double click occured. id_column_name is the name of the id table column. generated_id is the generated id, which is supposed to have been generated on the previous page. return_url is url to which this procedure will return redirect in the case of successful insertion in the database. insert_sql is the sql insert statement. if data is ok this procedure will insert data into the database in a double click safe manner and will returnredirect to the page specified by return_url. if database insert fails, this procedure will return a sensible error message to the user. |
ad_decode (public)ad_decode [ args... ] this procedure is analogus to sql decode procedure. first parameter is the value we want to decode. this parameter is followed by a list of pairs where first element in the pair is convert from value and second element is convert to value. last value is default value, which will be returned in the case convert from values matches the given value to be decoded |
ad_export_vars (public)ad_export_vars [ -form ] [ -exclude exclude ] [ -override override ] \
[ include ]
Deprecated. |
ad_generate_random_string (public)ad_generate_random_string [ length ] Generates a random string made of numbers and letters |
ad_get_cookie (public)ad_get_cookie [ -include_set_cookies include_set_cookies ] name \
[ default ]
Returns the value of a cookie, or $default if none exists. |
ad_get_tcl_call_stack (public)ad_get_tcl_call_stack [ level ] Returns a stack trace from where the caller was called. See also ad_print_stack_trace which generates a more readable stack trace at the expense of truncating args. |
ad_httpget (public)ad_httpget [ -url url ] [ -headers headers ] [ -timeout timeout ] \
[ -depth depth ]
Just like ns_httpget, but first headers is an ns_set of headers to send during the fetch. ad_httpget also makes use of Conditional GETs (if called with a Last-Modified header). Returns the data in array get form with array elements page status modified. |
ad_ns_set_keys (public)ad_ns_set_keys [ -colon ] [ -exclude exclude ] set_id Returns the keys of a ns_set as a Tcl list, like |
ad_ns_set_to_tcl_vars (public)ad_ns_set_to_tcl_vars [ -duplicates duplicates ] [ -level level ] \
set_id
Takes an ns_set and sets variables in the caller's environment correspondingly, i.e. if key is foo and value is bar, the Tcl var foo is set to bar. |
ad_return_top_of_page (public)ad_return_top_of_page first_part_of_page [ content_type ] Returns HTTP headers plus the top of the user-visible page. |
ad_returnredirect (public)ad_returnredirect [ -message message ] [ -html ] \
[ -allow_complete_url ] target_url
Write the HTTP response required to get the browser to redirect to a different page, to the current connection. This does not cause execution of the current page, including serving an ADP file, to stop. If you want to stop execution of the page, you should call ad_script_abort immediately following this call. |
ad_schedule_proc (public)ad_schedule_proc [ -thread thread ] [ -once once ] [ -debug debug ] \
[ -all_servers all_servers ] [ -schedule_proc schedule_proc ] \
interval proc [ args... ]
Replacement for ns_schedule_proc and friends, allowing us to track what's going on. Can be monitored via /admin/monitoring/schedule-procs.tcl. The procedure defaults to run on only the canonical server unless the all_servers flag is set to true. |
ad_set_cookie (public)ad_set_cookie [ -replace replace ] [ -secure secure ] \
[ -expire expire ] [ -max_age max_age ] [ -domain domain ] \
[ -path path ] name [ value ]
Sets a cookie. |
ad_set_typed_form_variable_filter (public)ad_set_typed_form_variable_filter url_pattern [ args... ] Deprecated. |
ad_tcl_list_list_to_ns_set (public)ad_tcl_list_list_to_ns_set [ -set_id set_id ] [ -put ] kv_pairs Takes a list of lists of key/value pairs and |
ad_tcl_vars_list_to_ns_set (public)ad_tcl_vars_list_to_ns_set [ -set_id set_id ] [ -put ] vars_list Takes a TCL list of variable names and |
ad_tcl_vars_to_ns_set (public)ad_tcl_vars_to_ns_set [ -set_id set_id ] [ -put ] [ args... ] Takes a list of variable names and |
ad_urlencode (public)ad_urlencode string same as ns_urlencode except that dash and underscore are left unencoded. |
ad_var_type_check_dirname_p (public)ad_var_type_check_dirname_p value
|
ad_var_type_check_fail_p (public)ad_var_type_check_fail_p value
|
ad_var_type_check_integer_p (public)ad_var_type_check_integer_p value
|
ad_var_type_check_integerlist_p (public)ad_var_type_check_integerlist_p value
|
ad_var_type_check_nocheck_p (public)ad_var_type_check_nocheck_p [ value ]
|
ad_var_type_check_noquote_p (public)ad_var_type_check_noquote_p value
|
ad_var_type_check_number_p (public)ad_var_type_check_number_p value
|
ad_var_type_check_safefilename_p (public)ad_var_type_check_safefilename_p value
|
ad_var_type_check_third_urlv_integer_p (public)ad_var_type_check_third_urlv_integer_p [ args ]
|
ad_var_type_check_word_p (public)ad_var_type_check_word_p value
|
apply (public)apply func arglist Evaluates the first argument with ARGLIST as its arguments, in the environment of its caller. Analogous to the Lisp function of the same name. |
check_for_form_variable_naughtiness (public)check_for_form_variable_naughtiness name value stuff to process the data that comes back from the users if the form looked like and then after you run this function you'll have Tcl vars $foo and $bar set to whatever the user typed in the form this uses the initially nauseating but ultimately delicious tcl system function "uplevel" that lets a subroutine bash the environment and local vars of its caller. It ain't Common Lisp... This is an ad-hoc check to make sure users aren't trying to pass in "naughty" form variables in an effort to hack the database by passing in SQL. It is called in all instances where a Tcl variable is set from a form variable. Checks the given variable for against known form variable exploits. If it finds anything objectionable, it throws an error. |
db_html_select_options (public)db_html_select_options [ -bind bind ] [ -select_option select_option ] \
stmt_name sql
Generate html option tags for an html selection widget. If select_option is passed, this option will be marked as selected. |
db_html_select_value_options (public)db_html_select_value_options [ -bind bind ] \
[ -select_option select_option ] [ -value_index value_index ] \
[ -option_index option_index ] stmt_name sql
Generate html option tags with values for an html selection widget. if select_option is passed and there exists a value for it in the values list, this option will be marked as selected. select_option can be passed a list, in which case all options matching a value in the list will be marked as selected. |
exists_and_equal (public)exists_and_equal varname value Returns 1 if the variable name exists in the caller's envirnoment and is equal to the given value. |
exists_and_not_null (public)exists_and_not_null varname Returns 1 if the variable name exists in the caller's environment and is not the empty string. Note you should enter the variable name, and not the variable value (varname not $varname which will pass variable varnames value into this function). |
export_entire_form (public)export_entire_form Exports everything in ns_getform to the ns_set. This should generally not be used. It's much better to explicitly name the variables you want to export. export_vars is now the prefered interface. |
export_entire_form_as_url_vars (public)export_entire_form_as_url_vars [ vars_to_passthrough ] export_vars is now the prefered interface. Returns a URL parameter string of name-value pairs of all the form parameters passed to this page. If vars_to_passthrough is given, it should be a list of parameter names that will be the only ones passed through. |
export_form_vars (public)export_form_vars [ -sign ] [ args... ] Deprecated. |
export_ns_set_vars (public)export_ns_set_vars [ format ] [ exclusion_list ] [ setid ] Returns all the params in an ns_set with the exception of those in exclusion_list. If no setid is provide, ns_getform is used. If format = url, a url parameter string will be returned. If format = form, a block of hidden form fragments will be returned. export_vars is now the prefered interface. |
export_url_vars (public)export_url_vars [ -sign ] [ args... ] export_vars is now the prefered interface. Returns a string of key=value pairs suitable for inclusion in a URL; you can pass it any number of variables as arguments. If any are defined in the caller's environment, they are included. See also export_entire_form_as_url_vars. |
export_vars (public)export_vars [ -sign ] [ -form ] [ -url ] [ -quotehtml ] \
[ -entire_form ] [ -no_empty ] [ -base base ] [ -anchor anchor ] \
[ -exclude exclude ] [ -override override ] [ vars ]
Exports variables either in URL or hidden form variable format. It should replace |
get_referrer (public)get_referrer gets the Referer for the headers |
lmap (public)lmaplist proc_name Applies proc_name to each item of the list, appending the result of each call to a new list that is the return value. |
max (public)max[ args... ] Returns the maximum of a list of numbers. Example: |
merge_form_with_query (public)merge_form_with_query [ -bind bind ] form statement_name sql_qry Merges a form with a query string. |
min (public)min[ args... ] Returns the minimum of a list of numbers. Example: |
random (public)random Return a pseudo-random number between 0 and 1. |
randomInit (public)randomInit seed seed the random number generator. |
randomRange (public)randomRange range Returns a pseudo-random number between 0 and range. |
remove_nulls_from_ns_set (public)remove_nulls_from_ns_set old_set_id Creates and returns a new ns_set without any null value fields |
safe_eval (public)safe_eval [ args... ] Version of eval that checks its arguments for brackets that may be used to execute unsafe code. |
util::age_pretty (public)util::age_pretty -timestamp_ansi timestamp_ansi \
-sysdate_ansi sysdate_ansi [ -hours_limit hours_limit ] \
[ -days_limit days_limit ] [ -mode_2_fmt mode_2_fmt ] \
[ -mode_3_fmt mode_3_fmt ] [ -locale locale ]
Formats past time intervals in one of three different modes depending on age. The first mode is "1 hour 3 minutes" and is NOT currently internationalized. The second mode is e.g. "14:10, Thursday" and is internationalized. The third mode is "14:10, 01 Mar 2001" and is internationalized. Both the locale and the exact format string for modes 2 and 3 can be overridden by parameters. (Once mode 1 is i18nd, the following sentence will be true:'In mode 1, only the locale can be overridden.' Until then, move along. These aren't the timestamps you're looking for.) |
util::array_list_spec_pretty (public)util::array_list_spec_pretty list [ indent ] Pretty-format an array-list spec with proper indentation. |
util::backup_file (public)util::backup_file -file_path file_path \
[ -backup_suffix backup_suffix ]
Backs up (move) the file or directory with given path to a file/directory with a backup suffix. Will avoid overwriting old backup files by adding a number to the filename to make it unique. For example, suppose you are backing up /web/my-server/packages/my-package/file.txt and the file has already been backed up to /web/my-server/packages/my-package/file.txt.bak. Invoking this proc will then generate the backup file /web/my-server/packages/my-package/file.txt.bak.2 |
util::catch_exec (public)util::catch_exec command result_var Catch a call to Tcl exec. Handle shell return codes consistently. Works like catch. The result of the exec is put into the variable named in result_var. Inspired by http://wiki.tcl.tk/1039 |
util::cookietime (public)util::cookietime time Return an RFC2109 compliant string for use in "Expires". |
util::external_url_p (public)util::external_url_p url check if this URL is external to the current host or a valid alternative valid alternatives include HTTPS or HTTP protocol change HTTP or HTTPS port number added or removed from current host name |
util::find_all_files (public)util::find_all_files [ -include_dirs include_dirs ] \
[ -max_depth max_depth ] [ -check_file_func check_file_func ] \
[ -extension extension ] -path path
Returns a list of lists with full paths and filename to all files under $path in the directory tree (descending the tree to a depth of up to $max_depth). Clients should not depend on the order of files returned. DOES NOT WORK ON WINDOWS (you have to change the splitter and I don't know how to detect a windows system) |
util::interval_pretty (public)util::interval_pretty [ -seconds seconds ] Takes a number of seconds and returns a pretty interval of the form "3h 49m 13s" |
util::random_list_element (public)util::random_list_element list Returns a random element from the list. |
util::randomize_list (public)util::randomize_list list Returns a random permutation of the list. |
util::roll_server_log (public)util::roll_server_log Invoke the AOLserver ns_logroll command with some bookend log records. This rolls the error log, not the access log. |
util::string_check_urlsafe (public)util::string_check_urlsafe s1 This proc accepts a string and verifies if it is url safe. - make sure there is no space - make sure there is no special characters except '-' or '_' Returns 1 if yes and 0 if not. Meant to be used in the validation section of ad_form. |
util::string_length_compare (public)util::string_length_compare s1 s2 String length comparison function for use with lsort's -command switch. |
util::subst_safe (public)util::subst_safe string Make string safe for subst'ing. |
util::which (public)util::which prog
|
util::word_diff (public)util::word_diff -old old -new new [ -split_by split_by ] \
[ -filter_proc filter_proc ] [ -start_old start_old ] \
[ -end_old end_old ] [ -start_new start_new ] [ -end_new end_new ]
Does a word (or character) diff on two lines of text and indicates text that has been deleted/changed or added by enclosing it in start/end_old/new. |
util_AnsiDatetoPrettyDate (public)util_AnsiDatetoPrettyDate sql_date Converts 1998-09-05 to September 5, 1998 |
util_PrettyTclBoolean (public)util_PrettyTclBoolean zero_or_one Turns a 1 (or anything else that makes a Tcl IF happy) into Yes; anything else into No |
util_ReturnMetaRefresh (public)util_ReturnMetaRefresh url [ seconds_delay ] Ugly workaround to deal with IE5.0 bug handling multipart/form-data using Meta Refresh page instead of a redirect. |
util_absolute_path_p (public)util_absolute_path_p path Check whether the path begins with a slash |
util_background_exec (public)util_background_exec [ -pass_vars pass_vars ] -name name code_chunk Executes a chunk of code in the background. The code is run exclusively, meaning that no two threads with the same name can run at the same time. |
util_background_get_result (public)util_background_get_result -name name Gets the result of a completed background thread execution. |
util_background_reset (public)util_background_reset -name name Gets the result of a completed background thread execution. |
util_background_running_p (public)util_background_running_p -name name
|
util_commify_number (public)util_commify_number num Returns the number with commas inserted where appropriate. Number can be positive or negative and can have a decimal point. e.g. -1465.98 => -1,465.98 |
util_complete_url_p (public)util_complete_url_p string Determine whether string is a complete URL, i.e. wheteher it begins with protocol: where protocol consists of letters only. |
util_current_directory (public)util_current_directory Returns the directory of the current URL. |
util_current_location (public)util_current_location Like ad_conn location - Returns the location string of the current request in the form protocol://hostname[:port] but it looks at the Host header, that is, takes into account the host name the client used although it may be different from the host name from the server configuration file. If the Host header is missing or empty util_current_location falls back to ad_conn location. cro@ncacasi.org 2002-06-07 Note: IE fouls up the Host header if a server is on a non-standard port; it does not change the port number when redirecting to https. So we would get redirects from http://some-host:8000 to https://some-host:8000 |
util_driver_info (public)util_driver_info -array array [ -driver driver ] Returns the protocol and port for the specified driver. |
util_email_unique_p (public)util_email_unique_p email Returns 1 if the email passed in does not yet exist in the system. |
util_email_valid_p (public)util_email_valid_p query_email Returns 1 if an email address has more or less the correct form. The regexp was taken from Jeff Friedls book "Mastering Regular Expressions". |
util_escape_quotes_for_csv (public)util_escape_quotes_for_csv string Returns its argument with double quote replaced by backslash double quote |
util_get_current_url (public)util_get_current_url Returns a URL for re-issuing the current request, with query variables. If a form submission is present, that is converted into query vars as well. |
util_get_http_status (public)util_get_http_status url [ use_get_p ] [ timeout ] Returns the HTTP status code, e.g., 200 for a normal response or 500 for an error, of a URL. By default this uses the GET method instead of HEAD since not all servers will respond properly to a HEAD request even when the URL is perfectly valid. Note that this means AOLserver may be sucking down a lot of bits that it doesn't need. |
util_get_subset_missing (public)util_get_subset_missing list1 list2 Returns the elements in list1 that are not in list2. Ignores duplicates. |
util_get_user_messages (public)util_get_user_messages [ -keep ] -multirow multirow Gets and clears the message to be displayed on the next page load. |
util_http_file_upload (public)util_http_file_upload [ -file file ] [ -data data ] [ -binary ] \
[ -filename filename ] [ -name name ] [ -mime_type mime_type ] \
[ -mode mode ] [ -rqset rqset ] url [ formvars ] [ timeout ] \
[ depth ] [ http_referer ]
Implement client-side HTTP file uploads as multipart/form-data as per RFC 1867. |
util_httpget (public)util_httpget url [ headers ] [ timeout ] [ depth ] util_httpget simply calls ad_httpget which also returns status and last_modfied |
util_httpopen (public)util_httpopen method url [ rqset ] [ timeout ] [ http_referer ] Like ns_httpopen but works for POST as well; called by util_httppost |
util_httppost (public)util_httppost url formvars [ timeout ] [ depth ] [ http_referer ] Returns the result of POSTing to another Web server or -1 if there is an error or timeout. formvars should be in the form \"arg1=value1&arg2=value2\". |
util_link_responding_p (public)util_link_responding_p url [ list_of_bad_codes ] Returns 1 if the URL is responding (generally we think that anything other than 404 (not found) is okay). |
util_list_of_ns_sets_to_list_of_lists (public)util_list_of_ns_sets_to_list_of_lists -list_of_ns_sets list_of_ns_sets Transform a list of ns_sets (most likely produced by db_list_of_ns_sets) into a list of lists that match the array set format in the sublists (key value key value ...) |
util_list_to_ns_set (public)util_list_to_ns_set aList Convert a list in the form "key value key value ..." into a ns_set. |
util_ns_set_to_list (public)util_ns_set_to_list -set set Convert an ns_set into a list suitable for passing in to the "array set" command (key value key value ...). |
util_report_library_entry (public)util_report_library_entry [ extra_message ] Should be called at beginning of private Tcl library files so that it is easy to see in the error log whether or not private Tcl library files contain errors. |
util_report_successful_library_load (public)util_report_successful_library_load [ extra_message ] Should be called at end of private Tcl library files so that it is easy to see in the error log whether or not private Tcl library files contain errors. |
util_search_list_of_lists (public)util_search_list_of_lists list_of_lists query_string \
[ sublist_element_pos ]
Returns position of sublist that contains QUERY_STRING at SUBLIST_ELEMENT_POS. |
util_sets_equal_p (public)util_sets_equal_p list1 list2 Tests whether each unique string in list1 occurs as many times in list1 as in list2 and vice versa (regarless of order). |
util_subset_p (public)util_subset_p list1 list2 Tests whether list1 is a subset of list2. |
util_text_to_url (public)util_text_to_url [ -existing_urls existing_urls ] [ -no_resolve ] \
[ -replacement replacement ] [ -text text ] [ _text ]
Modify a string so that it is suited as a well formatted URL path element. Also, if given a list of existing urls it can catch duplicate or optionally create an unambiguous url by appending a dash and a digit. |
util_unlist (public)util_unlist list [ args... ] Places the nth element of |
util_url_valid_p (public)util_url_valid_p query_url Returns 1 if a URL is a web URL (HTTP, HTTPS or FTP). |
util_user_message (public)util_user_message [ -replace ] [ -html ] [ -message message ] Sets a message to be displayed on the next page request. |
util_wrap_list (public)util_wrap_list [ -eol eol ] [ -indent indent ] [ -length length ] \
items
Wraps text to a particular line length. |
validate_ad_dateentrywidget (public)validate_ad_dateentrywidget field_name column form [ allow_null ] Deprecated. |
validate_integer (public)validate_integer field_name string Deprecated. |
validate_zip_code (public)validate_zip_code field_name zip_string country_code Deprecated. |
value_if_exists (public)value_if_exists var_name If the specified variable exists in the calling environment, returns the value of that variable. Otherwise, returns the empty_string. |
with_catch (public)with_catch error_var body on_error execute code in body with the catch errorMessage in error_var and if there is a non-zero return code from body execute the on_error block. |
with_finally (public)with_finally -code code -finally finally Execute CODE, then execute cleanup code FINALLY. If CODE completes normally, its value is returned after executing FINALLY. If CODE exits non-locally (as with error or return), FINALLY is executed anyway. |
xml_get_child_node_attribute_by_path (public)xml_get_child_node_attribute_by_path node path_list attribute_name Return the attribute of a child node down a give path from the current node. |
xml_get_child_node_content_by_path (public)xml_get_child_node_content_by_path node path_list Return the first non-empty contents of a child node down a given path from the current node. |