The Red Matrix
 All Classes Namespaces Files Functions Variables Pages
text.php File Reference

Functions

 replace_macros ($s, $r)
 
 random_string ($size=64, $type=RANDOM_STRING_HEX)
 
 notags ($string)
 
 escape_tags ($string)
 
 z_input_filter ($channel_id, $s, $type= 'text/bbcode')
 
 purify_html ($s)
 
 autoname ($len)
 
 xmlify ($str)
 
 unxmlify ($s)
 
if(!function_exists('hex2bin')) paginate (&$a)
 
 alt_pager (&$a, $i, $more= '', $less= '')
 
 expand_acl ($s)
 
 sanitise_acl (&$item)
 
 perms2str ($p)
 
 item_message_id ()
 
 photo_new_resource ()
 
 attribute_contains ($attr, $s)
 
 logger ($msg, $level=0)
 
 dlogger ($msg, $level=0)
 
 profiler ($t1, $t2, $label)
 
 activity_match ($haystack, $needle)
 
 get_tags ($s)
 
 tag_sort_length ($a, $b)
 
 strip_zids ($s)
 
 qp ($s)
 
 get_mentions ($item, $tags)
 
 contact_block ()
 
 chanlink_hash ($s)
 
 chanlink_url ($s)
 
 chanlink_cid ($d)
 
 magiclink_url ($observer, $myaddr, $url)
 
 micropro ($contact, $redirect=false, $class= '', $textmode=false)
 
 search ($s, $id='search-box', $url='/search', $save=false)
 
 searchbox ($s, $id='search-box', $url='/search', $save=false)
 
 valid_email ($x)
 
 linkify ($s)
 
 sslify ($s)
 
 get_poke_verbs ()
 
 get_mood_verbs ()
 
 smilies ($s, $sample=false)
 
 smile_shield ($m)
 
 smile_unshield ($m)
 
 preg_heart ($x)
 
 day_translate ($s)
 
 normalise_link ($url)
 
 link_compare ($a, $b)
 
 unobscure (&$item)
 
 theme_attachments (&$item)
 
 format_categories (&$item, $writeable)
 
 format_hashtags (&$item)
 
 format_filer (&$item)
 
 prepare_body (&$item, $attach=false)
 
 prepare_text ($text, $content_type= 'text/bbcode')
 
 zidify_callback ($match)
 
 zidify_img_callback ($match)
 
 zidify_links ($s)
 
 feed_hublinks ()
 
 feed_salmonlinks ($nick)
 
 get_plink ($item, $conversation_mode=true)
 
 unamp ($s)
 
 layout_select ($channel_id, $current= '')
 
 mimetype_select ($channel_id, $current= 'text/bbcode')
 
 lang_selector ()
 
 return_bytes ($size_str)
 
 base64url_encode ($s, $strip_padding=true)
 
 base64url_decode ($s)
 
 cleardiv ()
 
 bb_translate_video ($s)
 
 html2bb_video ($s)
 
 array_xmlify ($val)
 
 reltoabs ($text, $base)
 
 item_post_type ($item)
 
 undo_post_tagging ($s)
 
 fix_mce_lf ($s)
 
 protect_sprintf ($s)
 
 is_a_date_arg ($s)
 
 legal_webbie ($s)
 
 check_webbie ($arr)
 
 ids_to_querystr ($arr, $idx= 'id')
 
 xchan_query (&$items, $abook=true)
 
 xchan_mail_query (&$item)
 
 find_xchan_in_array ($xchan, $arr)
 
 get_rel_link ($j, $rel)
 
 magic_link ($s)
 
 stringify_array_elms (&$arr, $escape=false)
 
 jindent ($json)
 
 json_decode_plus ($s)
 
 design_tools ()
 
 in_arrayi ($needle, $haystack)
 
 normalise_openid ($s)
 

Variables

const RANDOM_STRING_HEX 0x00
 
const RANDOM_STRING_TEXT 0x01
 

Function Documentation

alt_pager ( $a,
  $i,
  $more = '',
  $less = '' 
)
array_xmlify (   $val)

apply xmlify() to all values of array $val, recursively

Referenced by api_apply_template(), and poco_init().

attribute_contains (   $attr,
  $s 
)
autoname (   $len)

generate a string that's random, but usually pronounceable. used to generate initial passwords

Parameters
int$len
Returns
string

Referenced by check_php(), invite_post(), and lostpass_content().

bb_translate_video (   $s)

Referenced by item_post().

chanlink_cid (   $d)
chanlink_hash (   $s)
check_webbie (   $arr)
cleardiv ( )

Referenced by common_content(), and match_content().

contact_block ( )

Referenced by profile_sidebar().

design_tools ( )

Referenced by widget_design_tools().

dlogger (   $msg,
  $level = 0 
)
escape_tags (   $string)
expand_acl (   $s)
feed_hublinks ( )

return atom link elements for all of our hubs

feed_salmonlinks (   $nick)
fix_mce_lf (   $s)

Referenced by item_post(), mail_post(), and profiles_post().

format_categories ( $item,
  $writeable 
)

Referenced by prepare_body().

format_filer ( $item)

Referenced by prepare_body().

format_hashtags ( $item)

Referenced by prepare_body().

get_mentions (   $item,
  $tags 
)
get_mood_verbs ( )

Referenced by mood_content(), and mood_init().

get_plink (   $item,
  $conversation_mode = true 
)
get_poke_verbs ( )

Referenced by poke_content(), and poke_init().

get_rel_link (   $j,
  $rel 
)
get_tags (   $s)

Referenced by item_post(), and photos_post().

html2bb_video (   $s)
ids_to_querystr (   $arr,
  $idx = 'id' 
)
in_arrayi (   $needle,
  $haystack 
)
is_a_date_arg (   $s)

Referenced by channel_content(), and network_content().

item_post_type (   $item)

Referenced by notification().

jindent (   $json)

Indents a flat JSON string to make it more human-readable.

Parameters
string$jsonThe original JSON string to process.
Returns
string Indented version of the original JSON string.
lang_selector ( )

Referenced by lang_content().

layout_select (   $channel_id,
  $current = '' 
)

Referenced by editwebpage_content().

legal_webbie (   $s)

Referenced by check_webbie(), and new_channel_init().

link_compare (   $a,
  $b 
)

Compare two URLs to see if they are the same, but ignore slight but hopefully insignificant differences such as if one is https and the other isn't, or if one is www.something and the other isn't - and also ignore case differences.

Return true if the URLs match, otherwise false.

Referenced by consume_feed(), like_puller(), tag_deliver(), tgroup_check(), and zid().

linkify (   $s)

Function: linkify

Replace naked text hyperlink with HTML formatted hyperlink

Referenced by advanced_profile(), dirprofile_init(), and profile_activity().

logger (   $msg,
  $level = 0 
)

Referenced by RedDirectory\__construct(), RedFile\__construct(), account_remove(), account_verify_password(), Item\add_child(), Conversation\add_thread(), admin_content(), admin_page_hubloc_post(), admin_post(), advanced_profile(), aes_encapsulate(), allowed_public_recips(), api_call(), api_channel_stream(), api_export_basic(), api_favorites(), api_get_user(), api_login(), api_oauth_request_token(), api_statuses_destroy(), api_statuses_mediap(), api_statuses_repeat(), api_statuses_show(), api_statuses_update(), api_statuses_user_timeline(), attach_mkdir(), avatar_img(), base64url_decode(), blog_install(), blog_uninstall(), bookmark_add(), bookmarks_init(), build_sync_packet(), chanman_remove_everything_from_network(), channel_remove(), chanview_content(), check_config(), check_form_security_token_ForbiddenOnErr(), check_form_security_token_redirectOnErr(), RedDirectory\childExists(), cloud_init(), consume_feed(), conversation(), create_account(), create_identity(), RedDirectory\createDirectory(), RedDirectory\createFile(), cronhooks_run(), datetime_convert(), delete_imported_item(), deliver_run(), detect_language(), dir_parse_query(), directory_content(), directory_run(), dirprofile_init(), downgrade_accounts(), email_send(), encode_item(), expire_run(), externals_run(), feed_init(), fetch_lrdd_template(), filer_content(), filerm_content(), fix_private_photos(), fix_system_urls(), RedFile\get(), get_atom_elements(), get_item_elements(), get_language_name(), Conversation\get_template_data(), RedDirectory\getChild(), RedDirectory\getChildren(), RedDirectory\getDir(), RedDirectory\getName(), RedFile\getName(), group_content(), guess_image_type(), head_set_icon(), http_status_exit(), import_author_rss(), import_author_zot(), import_channel_photo(), import_directory_profile(), import_post(), import_profile_photo(), import_site(), import_xchan(), install_plugin(), item_post(), item_store(), item_store_update(), like_content(), limit_body_size(), load_plugin(), local_dir_update(), localize_item(), RedDirectory\log(), RedBasicAuth\log(), FKOAuth1\loginUser(), FKOAuthDataStore\lookup_consumer(), FKOAuthDataStore\lookup_token(), magic_init(), mail_post(), mail_store(), menu_edit(), mini_group_select(), mood_init(), FKOAuthDataStore\new_access_token(), new_contact(), new_keypair(), FKOAuthDataStore\new_request_token(), notes_init(), notification(), notifier_run(), onedirsync_run(), onepoll_run(), openid_content(), parse_url_content(), parse_xml_string(), photo_init(), photo_upload(), photos_post(), ping_init(), poco_init(), poco_load(), poke_init(), poller_run(), post_activity_item(), post_init(), post_post(), private_messages_list(), process_channel_sync_delivery(), process_delivery(), process_mail_delivery(), process_profile_delivery(), profile_load(), profile_sidebar(), prune_hub_reinstalls(), public_recips(), RedFile\put(), dba_mysql\q(), dba_mysqli\q(), q(), queue_run(), rbmark_post(), red_item_new(), RedChannelList(), RedCollectionData(), RedFileData(), register_content(), reload_plugins(), Item\remove_child(), remove_community_tag(), remove_queue_item(), scale_external_images(), search_ac_init(), enotify\send(), send_reg_approval_email(), Conversation\set_mode(), RedFile\setName(), stream_perms_api_uids(), stream_perms_xchans(), subthread_content(), sync_directories(), tag_deliver(), tagger_content(), tgroup_check(), uninstall_plugin(), unload_plugin(), update_directory_entry(), update_imported_item(), update_queue_time(), RedBasicAuth\validateUserPass(), webfinger(), webfinger_dfrn(), xml2array(), xml_status(), z_fetch_url(), z_post_url(), zfinger_init(), zid_init(), zot_build_packet(), zot_feed(), zot_fetch(), zot_finger(), zot_gethub(), zot_import(), zot_process_response(), zot_refresh(), zot_register_hub(), and zotfeed_init().

magic_link (   $s)
magiclink_url (   $observer,
  $myaddr,
  $url 
)
micropro (   $contact,
  $redirect = false,
  $class = '',
  $textmode = false 
)

Referenced by contact_block().

mimetype_select (   $channel_id,
  $current = 'text/bbcode' 
)
normalise_openid (   $s)

Referenced by openid_content().

notags (   $string)

This is our primary input filter.

The high bit hack only involved some old IE browser, forget which (IE5/Mac?) that had an XSS attack vector due to stripping the high-bit on an 8-bit character after cleansing, and angle chars with the high bit set could get through as markup.

This is now disabled because it was interfering with some legitimate unicode sequences and hopefully there aren't a lot of those browsers left.

Use this on any text input where angle chars are not valid or permitted They will be replaced with safer brackets. This may be filtered further if these are not allowed either.

Parameters
string$stringInput string
Returns
string Filtered string

Referenced by admin_page_logs_post(), admin_page_site_post(), channel_content(), connections_content(), conversation(), create_account(), directory_content(), filestorage_post(), follow_init(), get_atom_elements(), group_post(), help_content(), invite_post(), item_post(), item_store(), item_store_update(), like_content(), lostpass_post(), mail_post(), mail_store(), mood_init(), network_content(), oexchange_content(), openid_content(), photos_post(), poco_init(), poke_init(), profiles_post(), register_post(), sanitise_acl(), settings_post(), setup_content(), setup_post(), subthread_content(), tagger_content(), and xrd_init().

if (!function_exists('hex2bin')) paginate ( $a)
photo_new_resource ( )
preg_heart (   $x)
prepare_body ( $item,
  $attach = false 
)
profiler (   $t1,
  $t2,
  $label 
)

Referenced by conversation(), and network_content().

purify_html (   $s)
qp (   $s)
reltoabs (   $text,
  $base 
)

Referenced by get_atom_elements().

replace_macros (   $s,
  $r 
)

This is our template processor

Parameters
string | FriendicaSmarty$sthe string requiring macro substitution, or an instance of FriendicaSmarty
array$rkey value pairs (search => replace)
Returns
string substituted string

Referenced by admin_content(), admin_page_channels(), admin_page_dbsync(), admin_page_hubloc(), admin_page_logs(), admin_page_plugins(), admin_page_site(), admin_page_summary(), admin_page_themes(), admin_page_users(), advanced_profile(), alt_pager(), api_apply_template(), api_content(), apps_content(), apw_form(), blocks_content(), blogtheme_form(), App\build_pagehead(), categories_widget(), channel_content(), chanview_content(), chat_content(), check_config(), check_php(), common_content(), common_friends_visitor_widget(), connect_content(), connections_content(), connedit_content(), construct_page(), contact_block(), conversation(), delegate_content(), design_tools(), dir_safe_mode(), dir_sort_links(), directory_content(), dirprofile_init(), display_content(), editblock_content(), editlayout_content(), editpost_content(), editwebpage_content(), events_content(), fbrowser_content(), field_timezone(), fileas_widget(), filer_content(), filestorage_content(), findpeople_widget(), format_categories(), format_filer(), get_birthdays(), Item\get_comment_box(), get_events(), get_feed_for(), group_content(), group_side(), help_content(), hostxrd_init(), import_content(), invite_content(), lang_selector(), layouts_content(), login(), lostpass_content(), lostpass_post(), mail_content(), manage_content(), match_content(), menu_content(), menu_render(), message_content(), micropro(), mini_group_select(), mitem_content(), mood_content(), nav(), network_content(), new_channel_content(), notification(), notifications_content(), notify_content(), oembed_format_object(), oexchange_init(), opensearch_init(), pagelist_widget(), pdledit_content(), photos_album_widget(), photos_content(), poco_init(), poke_content(), populate_acl(), profile_sidebar(), profiles_content(), rbmark_content(), redbasic_form(), register_content(), removeme_content(), rmagic_content(), rpost_content(), search_content(), send_reg_approval_email(), send_verification_email(), setup_content(), setup_post(), siteinfo_content(), sources_content(), suggest_content(), theme_attachments(), thing_content(), user_allow(), vcard_from_xchan(), viewconnections_content(), vote_content(), webpages_content(), widget_affinity(), widget_archive(), widget_bookmarkedchats(), widget_chatroom_list(), widget_filer(), widget_follow(), widget_mailmenu(), widget_notes(), widget_savedsearch(), widget_settings_menu(), widget_suggestedchats(), widget_suggestions(), writepages_widget(), and xrd_init().

return_bytes (   $size_str)
sanitise_acl ( $item)
search (   $s,
  $id = 'search-box',
  $url = '/search',
  $save = false 
)

Referenced by search_content().

searchbox (   $s,
  $id = 'search-box',
  $url = '/search',
  $save = false 
)

Referenced by widget_savedsearch().

smile_shield (   $m)
smile_unshield (   $m)
smilies (   $s,
  $sample = false 
)

Function: smilies

Description: Replaces text emoticons with graphical images

: string $s

Returns string

It is expected that this function will be called using HTML text. We will escape text between HTML pre and code blocks, and HTML attributes (such as urls) from being processed.

At a higher level, the bbcode [nosmile] tag can be used to prevent this function from being executed by the prepare_text() routine when preparing bbcode source for HTML display

Referenced by chatsvc_content(), mail_content(), message_content(), and smilies_content().

sslify (   $s)

sslify($s) Replace media element using http url with https to a local redirector if using https locally

Parameters
string$sLooks for HTML tags containing src elements that are http when we're viewing an https page Typically this throws an insecure content violation in the browser. So we redirect them to a local redirector which uses https and which redirects to the selected content
Returns
string

Referenced by prepare_body().

stringify_array_elms ( $arr,
  $escape = false 
)
strip_zids (   $s)

Referenced by cloud_init(), and red_zrl_callback().

tag_sort_length (   $a,
  $b 
)
theme_attachments ( $item)

Referenced by mail_content(), and prepare_body().

unamp (   $s)
undo_post_tagging (   $s)
unxmlify (   $s)

Referenced by filer_content(), and get_atom_elements().

valid_email (   $x)
xchan_mail_query ( $item)

Referenced by notifier_run().

xmlify (   $str)
z_input_filter (   $channel_id,
  $s,
  $type = 'text/bbcode' 
)
zidify_callback (   $match)

zidify_callback() and zidify_links() work together to turn any HTML a tags with class="zrl" into zid links These will typically be generated by a bbcode '[zrl]' tag. This is done inside prepare_text() rather than bbcode() because the latter is used for general purpose conversions and the former is used only when preparing text for immediate display.

Issues: Currently the order of HTML parameters in the text is somewhat rigid and inflexible. We assume it looks like and will not work if zrl and href appear in a different order.

zidify_img_callback (   $match)
zidify_links (   $s)

Referenced by notification().

Variable Documentation

const RANDOM_STRING_HEX 0x00
const RANDOM_STRING_TEXT 0x01

Referenced by aes_encapsulate(), and random_string().