[ Index ]
 

Code source de b2evolution 2.1.0-beta

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/blogs/inc/_core/ -> _misc.funcs.php (sommaire)

This file implements general purpose functions. This file is part of the evoCore framework - {@link http://evocore.net/} See also {@link http://sourceforge.net/projects/evocms/}.

Author: cafelog (team)
Author: blueyed: Daniel HAHLER.
Author: fplanque: Francois PLANQUE.
Author: jeffbearer: Jeff BEARER.
Author: sakichan: Nobuo SAKIYAMA.
Author: vegarg: Vegar BERG GULDAL.
Author: mbruneau: Marc BRUNEAU / PROGIDISTRI
Copyright: (c)2003-2007 by Francois PLANQUE - {@link http://fplanque.net/}
Version: $Id: _misc.funcs.php,v 1.7 2007/11/03 21:04:25 fplanque Exp $
Poids: 3184 lignes (92 kb)
Inclus ou requis:0 fois
Référencé: 0 fois
Nécessite: 0 fichiers

Définit 71 fonctions

  format_to_output()
  format_to_post()
  autobrize()
  unautobrize()
  zeroise()
  convert_chars()
  callback_on_non_matching_blocks()
  make_clickable()
  make_clickable_callback()
  date2mysql()
  mysql2timestamp()
  mysql2datestamp()
  mysql2localedate()
  mysql2localetime()
  mysql2localedatetime()
  mysql2localedatetime_spans()
  mysql2date()
  date_i18n()
  date_sprintf()
  date_sprintf_callback()
  get_start_date_for_week()
  get_weekstartend()
  is_email()
  is_windows()
  xmlrpc_getposttitle()
  xmlrpc_getpostcategory()
  xmlrpc_getpostcategories()
  xmlrpc_removepostdata()
  xmlrpc_displayresult()
  xmlrpc_logresult()
  debug_fopen()
  debug_fwrite()
  debug_fclose()
  balanceTags()
  pre_dump()
  debug_get_backtrace()
  debug_die()
  bad_request_die()
  debug_info()
  send_mail()
  disp_cond()
  action_icon()
  get_icon()
  form_date()
  bullet()
  get_ip_list()
  get_base_domain()
  generate_random_key()
  generate_random_passwd()
  header_nocache()
  header_redirect()
  is_create_action()
  get_link_showhide()
  jsspecialchars()
  compact_date()
  decompact_date()
  format_phone()
  format_french_phone()
  get_manual_link()
  get_field_attribs_as_string()
  is_admin_page()
  implode_with_and()
  base_tag()
  display_list()
  display_param_link()
  resolve_link_params()
  hash_link_params()
  generate_link_from_params()
  url_rel_to_same_host()
  url_absolute()
  make_rel_links_abs()

Fonctions
Fonctions qui ne font pas partie d'une Classe:

format_to_output( $content, $format = 'htmlbody' )   X-Ref
Format a string/content for being output

author: fplanque
param: string raw text
param: string format, can be one of the following
return: string formatted text

format_to_post( $content, $autobr = 0, $is_comment = 0, $encoding = NULL )   X-Ref
Format raw HTML input to cleaned up and validated HTML.

param: string The content to format
param: integer Create automated <br /> tags? (Deprecated??!)
param: integer Is this a comment? (Used for balanceTags(), SafeHtmlChecker()'s URI scheme, styling restrictions)
param: string Encoding (used for SafeHtmlChecker() only!); defaults to $io_charset
return: string

autobrize($content)   X-Ref
Pas de description

unautobrize($content)   X-Ref
Pas de description

zeroise($number, $threshold)   X-Ref
Pas de description

convert_chars( $content, $flag='html' )   X-Ref
Convert all non ASCII chars (except if UTF-8, GB2312 or CP1251) to &#nnnn; unicode references.
Also convert entities to &#nnnn; unicode references if output is not HTML (eg XML)

Preserves < > and quotes.

fplanque: simplified
sakichan: pregs instead of loop

callback_on_non_matching_blocks( $text, $pattern, $callback, $params = array()   X-Ref
Split $text into blocks by using $pattern and call $callback on the non-matching blocks.

The non-matching block's text is the first param to $callback and additionally $params gets passed.

This gets used to make links clickable or replace smilies.

E.g., to replace only in non-HTML tags, call it like:
<code>callback_on_non_matching_blocks( $text, '~<[^>]*>~s', 'your_callback' );</code>

{@internal This function gets tested in misc.funcs.simpletest.php.}}

param: string Text to handle
param: string Regular expression pattern that defines blocks to exclude.
param: callback Function name or object/method array to use as callback.
param: array Of additional ("static") params to $callback.
return: string

make_clickable( $text, $moredelim = '&amp;' )   X-Ref
Make links clickable in a given text.

It replaces only text which is not between <a> tags already.

return: string

make_clickable_callback( & $text, $moredelim = '&amp;' )   X-Ref
Callback function for {@link make_clickable()}.

return: string The clickable text.

date2mysql( $ts )   X-Ref
Pas de description

mysql2timestamp( $m )   X-Ref
Convert a MYSQL date to a UNIX timestamp


mysql2datestamp( $m )   X-Ref
Convert a MYSQL date -- WITHOUT the time -- to a UNIX timestamp


mysql2localedate( $mysqlstring )   X-Ref
Format a MYSQL date to current locale date format.

param: string MYSQL date YYYY-MM-DD HH:MM:SS

mysql2localetime( $mysqlstring )   X-Ref
Pas de description

mysql2localedatetime( $mysqlstring )   X-Ref
Pas de description

mysql2localedatetime_spans( $mysqlstring )   X-Ref
Pas de description

mysql2date( $dateformatstring, $mysqlstring, $useGM = false )   X-Ref
Format a MYSQL date.

param: string enhanced format string
param: string MYSQL date YYYY-MM-DD HH:MM:SS
param: boolean true to use GM time

date_i18n( $dateformatstring, $unixtimestamp, $useGM = false )   X-Ref
Date internationalization: same as date() formatting but with i18n support

param: string enhanced format string
param: integer UNIX timestamp
param: boolean true to use GM time

date_sprintf( $string, $timestamp )   X-Ref
Format dates into a string in a way similar to sprintf()


date_sprintf_callback( $matches )   X-Ref
Pas de description

get_start_date_for_week( $year, $week, $startofweek )   X-Ref

param: integer year
param: integer month (0-53)
param: integer 0 for sunday, 1 for monday

get_weekstartend( $date, $startOfWeek )   X-Ref
Get start and end day of a week, based on week number and start-of-week

Used by Calendar

fp>> I'd really like someone to comment the magic of that thing...

param: date
param: integer 0 for Sunday, 1 for Monday

is_email( $email, $format = 'simple', $return_match = false )   X-Ref
Check that email address looks valid.

param: string email address to check
param: string Format to use ('simple', 'rfc')
param: boolean Return the match or boolean
return: bool|array Either true/false or the match (see {@link $return_match})

is_windows()   X-Ref
Are we running on a Windows server?


xmlrpc_getposttitle($content)   X-Ref
Pas de description

xmlrpc_getpostcategory($content)   X-Ref
Also used by post by mail


xmlrpc_getpostcategories($content)   X-Ref
Extract categories out of "<category>" tag from $content.

NOTE: w.bloggar sends something like "<category>00000013,00000001,00000004,</category>" to
blogger.newPost.

return: false|array

xmlrpc_removepostdata($content)   X-Ref
Pas de description

xmlrpc_displayresult( $result, $display = true, $log = '' )   X-Ref
Echo the XML-RPC call Result and optionally log into file

param: object XMLRPC response object
param: boolean true to echo
param: mixed File resource or == '' for no file logging.

xmlrpc_logresult( $result, & $message_Log )   X-Ref
Log the XML-RPC call Result into LOG object

param: object XMLRPC response object
param: Log object to add messages to
return: boolean true = success, false = error

debug_fopen($filename, $mode)   X-Ref
Pas de description

debug_fwrite($fp, $string)   X-Ref
Pas de description

debug_fclose($fp)   X-Ref
Pas de description

balanceTags($text)   X-Ref
Pas de description

pre_dump( $var__var__var__var__ )   X-Ref
Wrap pre tag around {@link var_dump()} for better debugging.

param: $var__var__var__var__,... mixed variable(s) to dump

debug_get_backtrace( $limit_to_last = NULL, $ignore_from = array( 'function' => 'debug_get_backtrace' )   X-Ref
Get a function trace from {@link debug_backtrace()} as html table.

Adopted from {@link http://us2.php.net/manual/de/function.debug-backtrace.php#47644}.

param: integer|NULL Get the last x entries from the stack (after $ignore_from is applied). Anything non-numeric means "all".
param: array After a key/value pair matches a stack entry, this and the rest is ignored.
param: integer Number of stack entries to include, after $ignore_from matches.
return: string HTML table

debug_die( $additional_info = '' )   X-Ref
Outputs Unexpected Error message. When in debug mode it also prints a backtrace.

This should be used instead of die() everywhere.
This should NOT be used instead of exit() anywhere.
Dying means the application has encontered and unexpected situation,
i-e: something that should never occur during normal operation.
Examples: database broken, user changed URL by hand...

param: string Message to output

bad_request_die( $additional_info = '' )   X-Ref
Outputs Bad request Error message. When in debug mode it also prints a backtrace.

This should be used when a bad user input is detected?

param: string Message to output

debug_info( $force = false )   X-Ref
Outputs debug info, according to {@link $debug} or $force param. This gets called typically at the end of the page.

param: boolean true to force output regardless of {@link $debug}

send_mail( $to, $subject, $message, $from = NULL, $headers = array()   X-Ref
Sends a mail, wrapping PHP's mail() function.

{@link $current_locale} will be used to set the charset.

Note: we use a single \n as line ending, though it does not comply to
{@link http://www.faqs.org/rfcs/rfc2822 RFC2822}, but seems to be safer,
because some mail transfer agents replace \n by \r\n automatically.

param: string Recipient, either email only or in "Name <example@example.com>" format (RFC2822).
param: string Subject of the mail
param: string The message text
param: string From address, being added to headers (we'll prevent injections);
param: array Additional headers ( headername => value ). Take care of injection!
return: boolean True if mail could be sent (not necessarily delivered!), false if not - (return value of {@link mail()})

disp_cond( $var, $disp_one, $disp_more = NULL, $disp_none = NULL )   X-Ref
If first parameter evaluates to true printf() gets called using the first parameter
as args and the second parameter as print-pattern

param: mixed variable to test and output if it's true or $disp_none is given
param: string printf-pattern to use (%s gets replaced by $var)
param: string printf-pattern to use, if $var is numeric and > 1 (%s gets replaced by $var)
param: string printf-pattern to use if $var evaluates to false (%s gets replaced by $var)

action_icon( $title, $icon, $url, $word = NULL, $icon_weight = 4, $word_weight = 1, $link_attribs = array()   X-Ref
Create IMG tag for an action icon.

param: string TITLE text (IMG and A link)
param: string icon code for {@link get_icon()}
param: string URL where the icon gets linked to (empty to not wrap the icon in a link)
param: string word to be displayed after icon
param: integer 1-5: weight of the icon. the icon will be displayed only if its weight is >= than the user setting threshold
param: integer 1-5: weight of the word. the word will be displayed only if its weight is >= than the user setting threshold
param: array Additional attributes to the A tag. The values must be properly encoded for html output (e.g. quotes).
return: string The generated action icon link.

get_icon( $iconKey, $what = 'imgtag', $params = NULL, $include_in_legend = false )   X-Ref
Get properties of an icon.

Note: to get a file type icon, use {@link File::get_icon()} instead.

param: string icon for what? (key)
param: string what to return for that icon ('imgtag', 'alt', 'legend', 'file', 'url', 'size' {@link imgsize()})
param: array additional params (
param: boolean true to include this icon into the legend at the bottom of the page (works for 'imgtag' only)

form_date( $date, $time = '' )   X-Ref

param: string date (YYYY-MM-DD)
param: string time

bullet( $bool )   X-Ref
Displays an empty or a full bullet based on boolean

param: boolean true for full bullet, false for empty bullet

get_ip_list( $firstOnly = false )   X-Ref
Get list of client IP addresses from REMOTE_ADDR and HTTP_X_FORWARDED_FOR,
in this order. '' is used when no IP could be found.

param: boolean True, to get only the first IP (probably REMOTE_ADDR)
return: array|string Depends on first param.

get_base_domain( $url )   X-Ref
Get the base domain (without protocol and any subdomain) of an URL.

Gets a max of 3 domain parts (x.y.tld)

param: string URL
return: string the base domain (may become empty, if found invalid)

generate_random_key( $length = 32, $keychars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' )   X-Ref
Generate a valid key of size $length.

param: integer length of key
param: string chars to use in generated key
return: string key

generate_random_passwd( $length = 8 )   X-Ref
Generate a random password with no ambiguous chars

param: integer length of password
return: string password

header_nocache()   X-Ref
Sends HTTP headers to avoid caching of the page.


header_redirect( $redirect_to = NULL, $permanent = false )   X-Ref
Sends HTTP header to redirect to the previous location (which
can be given as function parameter, GET parameter (redirect_to),
is taken from {@link Hit::$referer} or {@link $baseurl}).

{@link $Debuglog} and {@link $Messages} get stored in {@link $Session}, so they
are available after the redirect.

NOTE: This function {@link exit() exits} the php script execution.

param: string URL to redirect to (overrides detection)
param: boolean is this a permanent redirect? if true, send a 301; otherwise a 303

is_create_action( $action )   X-Ref
Pas de description

get_link_showhide( $link_id, $target_id, $text_when_displayed, $text_when_hidden, $display_hidden = true )   X-Ref
Generate a link that toggles display of an element on clicking.

param: string ID (html) of the link
param: string ID (html) of the target to toggle displaying
return: string

jsspecialchars($s)   X-Ref
Escape a string to be used in Javascript.

param: string
return: string

compact_date( $date )   X-Ref
Compact a date in a number keeping only integer value of the string

param: string date

decompact_date( $date )   X-Ref
Decompact a date in a date format ( Y-m-d h:m:s )

param: string date

format_phone( $phone, $hide_country_dialing_code_if_same_as_locale = true )   X-Ref
Check the format of the phone number param and
format it in a french number if it is.

param: string phone number

format_french_phone( $phone )   X-Ref
Format a string in a french phone number

param: string phone number

get_manual_link( $topic )   X-Ref
Generate a link to a online help resource.
testing the concept of online help (aka webhelp).
this function should be relocated somewhere better if it is taken onboard by the project

param: string Topic
return: string

get_field_attribs_as_string( $field_attribs, $format_to_output = true )   X-Ref
Build a string out of $field_attribs, with each attribute
prefixed by a space character.

param: array Array of field attributes.
param: boolean Use format_to_output() for the attributes?
return: string

is_admin_page()   X-Ref
Is the current page an admin/backoffice page?

return: boolean

implode_with_and( $arr, $implode_by = ', ', $implode_last = ' &amp; ' )   X-Ref
Implode array( 'x', 'y', 'z' ) to something like 'x, y and z'. Useful for displaying list to the end user.

If there's one element in the table, it is returned.
If there are at least two elements, the last one is concatenated using $implode_last, while the ones before are imploded using $implode_by.

return: string

base_tag( $url, $target = NULL )   X-Ref
Returns a "<base />" tag and remembers that we've used it ({@link regenerate_url()} needs this).

param: string URL to use (this gets used as base URL for all relative links on the HTML page)
return: string

display_list( $items, $list_start = '<ul>', $list_end = '</ul>', $item_separator = '', $item_start = '<li>', $item_end = '</li>', $force_hash = NULL )   X-Ref
Display an array as a list:

param: array
param: string
param: string
param: string
param: string
param: string

display_param_link( $params )   X-Ref
Pas de description

resolve_link_params( $item, $force_hash = NULL )   X-Ref
Resolve a link based on params

param: array
return: string

hash_link_params( $link_array, $force_hash = NULL )   X-Ref
Get a link line, based url hash combined with probability percentage in first column

param: array of arrays

generate_link_from_params( $link_params )   X-Ref
Generate a link from params


url_rel_to_same_host( $url, $target_url )   X-Ref
Try to make $url relative to $target_url, if scheme, host, user and pass matches.

This is useful for redirect_to params, to keep them short and avoid mod_security
rejecting the request as "Not Acceptable" (whole URL as param).

param: string URL to handle
param: string URL where we want to make $url relative to
return: string

url_absolute( $url, $host = NULL )   X-Ref
Make an $url absolute according to $host, if it is not absolute yet.

param: string URL
param: string Host (including protocol, e.g. 'http://example.com'); defaults to {@link $ReqHost}
return: string

make_rel_links_abs( $s, $host = NULL )   X-Ref
Make links in $s absolute.

It searches for "src" and "href" HTML tag attributes and makes the absolute.

param: string content
param: string Hostname including scheme, e.g. http://example.com; defaults to $ReqHost
return: string



Généré le : Thu Nov 29 23:58:50 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics