From 7e1e9ac94a1cf2fb01a3052f7fd9d0f2049079b5 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 2 Feb 2017 19:12:48 -0800 Subject: rename bb2diaspora.php to markdown.php --- Zotlabs/Module/Item.php | 2 +- doc/hooks.html | 2 +- include/bb2diaspora.php | 532 ------------------------------------------------ include/items.php | 2 +- include/markdown.php | 532 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 535 insertions(+), 535 deletions(-) delete mode 100644 include/bb2diaspora.php create mode 100644 include/markdown.php diff --git a/Zotlabs/Module/Item.php b/Zotlabs/Module/Item.php index 48992a676..4725ecb38 100644 --- a/Zotlabs/Module/Item.php +++ b/Zotlabs/Module/Item.php @@ -523,7 +523,7 @@ class Item extends \Zotlabs\Web\Controller { // // if($uid && $uid == $profile_uid && feature_enabled($uid,'markdown')) { - // require_once('include/bb2diaspora.php'); + // require_once('include/markdown.php'); // $body = escape_tags(trim($body)); // $body = str_replace("\n",'
', $body); // $body = preg_replace_callback('/\[share(.*?)\]/ism','\share_shield',$body); diff --git a/doc/hooks.html b/doc/hooks.html index f4a5a7630..6009127f6 100644 --- a/doc/hooks.html +++ b/doc/hooks.html @@ -1 +1 @@ -

Hooks

FunctionSource FileArg
$a->module . _mod_aftercontentindex.php$arr
$a->module . _mod_contentindex.php$arr
$a->module . _mod_initindex.php$placeholder
$a->module . _mod_postindex.php$_POST
$a->module . _post_ . $selnameinclude/acl_selectors.php$o
$a->module . _post_ . $selnameinclude/acl_selectors.php$o
$a->module . _post_ . $selnameinclude/acl_selectors.php$o
$a->module . _pre_ . $selnameinclude/acl_selectors.php$arr
$a->module . _pre_ . $selnameinclude/acl_selectors.php$arr
$a->module . _pre_ . $selnameinclude/acl_selectors.php$arr
$nameinclude/plugin.php&$data = null
about_hookmod/siteinfo.php$o
accept_followmod/connedit.php$arr
account_downgradeinclude/account.php$ret
account_downgradeinclude/account.php$ret
account_settingsmod/settings.php$account_settings
activity_receivedinclude/zot.php$parr
affinity_labelsinclude/widgets.php$labels
affinity_labelsmod/connedit.php$labels
api_perm_is_allowedinclude/permissions.php$arr
app_menuindex.php$arr
atom_authorinclude/items.php$o
atom_entryinclude/items.php$o
atom_feedinclude/items.php$atom
atom_feed_endinclude/items.php$atom
attach_upload_fileinclude/attach.php$f
authenticateinclude/auth.php$addon_auth
avatar_lookupinclude/network.php$avatar
bb2diasporainclude/bb2diaspora.php$Text
bbcodeinclude/bbcode.php$Text
channel_removeinclude/Contact.php$r[0]
chat_messageinclude/chat.php$arr
chat_postmod/chatsvc.php$arr
check_account_emailinclude/account.php$arr
check_account_inviteinclude/account.php$arr
check_account_passwordinclude/account.php$arr
connect_premiummod/connect.php$arr
connector_settingsmod/settings.php$settings_connectors
construct_pageboot.php$arr
contact_block_endinclude/text.php$arr
contact_editmod/connedit.php$arr
contact_edit_postmod/connedit.php$_POST
contact_select_optionsinclude/acl_selectors.php$x
conversation_startinclude/conversation.php$cb
create_identityinclude/channel.php$newuid
croninclude/cronhooks.php$d
cron_dailyinclude/poller.phpdatetime_convert()
cron_weeklyinclude/poller.phpdatetime_convert()
directory_itemmod/directory.php$arr
discover_by_webbieinclude/network.php$arr
display_iteminclude/ItemObject.php$arr
display_iteminclude/conversation.php$arr
display_settingsmod/settings.php$o
display_settings_postmod/settings.php$_POST
donate_contributorsextend/addon/matrix/donate/donate.php$contributors
donate_pluginextend/addon/matrix/donate/donate.php$o
donate_sponsorsextend/addon/matrix/donate/donate.php$sponsors
dreport_is_storableinclude/zot.php$dr
drop_iteminclude/items.php$arr
enotifyinclude/enotify.php$h
enotify_mailinclude/enotify.php$datarray
enotify_storeinclude/enotify.php$datarray
event_createdinclude/event.php$event[id]
event_updatedinclude/event.php$event[id]
externals_url_selectinclude/externals.php$arr
feature_enabledinclude/features.php$arr
feature_settingsmod/settings.php$settings_addons
feature_settings_postmod/settings.php$_POST
followinclude/follow.php$arr
followinclude/follow.php$arr
follow_allowinclude/follow.php$x
gender_selectorinclude/profile_selectors.php$select
gender_selector_mininclude/profile_selectors.php$select
generate_mapinclude/text.php$arr
generate_named_mapinclude/text.php$arr
get_all_api_permsinclude/permissions.php$arr
get_all_permsinclude/permissions.php$arr
get_featuresinclude/features.php$arr
get_role_permsinclude/permissions.php$ret
get_widgetsboot.php$arr
get_widgetsboot.php$arr
global_permissionsinclude/permissions.php$ret
home_contentmod/home.php$o
home_initmod/home.php$ret
hostxrdmod/hostxrd.php$arr
html2bbcodeinclude/html2bbcode.php$message
identity_basic_exportinclude/channel.php$addon
import_author_xchaninclude/items.php$arr
import_channelmod/import.php$addon
import_directory_profileinclude/zot.php$d
import_xchaninclude/zot.php$arr
item_photo_menuinclude/conversation.php$args
item_storeinclude/items.php$d
item_storeinclude/items.php$arr
item_store_updateinclude/items.php$d
item_translateinclude/items.php$translate
item_translateinclude/items.php$translate
jot_networksinclude/acl_selectors.php$jotnets
jot_networksinclude/conversation.php$jotnets
jot_networksmod/editblock.php$jotnets
jot_networksmod/editpost.php$jotnets
jot_networksmod/editwebpage.php$jotnets
jot_networksmod/editlayout.php$jotnets
jot_toolinclude/conversation.php$jotplugins
jot_toolmod/editblock.php$jotplugins
jot_toolmod/editpost.php$jotplugins
jot_toolmod/editwebpage.php$jotplugins
jot_toolmod/editlayout.php$jotplugins
load_pdlboot.php$arr
local_dir_updateinclude/dir_fns.php$arr
logged_ininclude/oauth.php$a->user
logged_ininclude/api.php$a->user
logged_ininclude/security.php$a->account
logged_ininclude/security.php$user_record
logging_outinclude/auth.php$args
login_hookboot.php$o
magic_authmod/magic.php$arr
magic_auth_openid_successmod/openid.php$arr
magic_auth_openid_successmod/openid.php$arr
magic_auth_successmod/post.php$arr
main_sliderinclude/widgets.php$arr
marital_selectorinclude/profile_selectors.php$select
marital_selector_mininclude/profile_selectors.php$select
module_loadedindex.php$x
mood_verbsinclude/text.php$arr
navinclude/nav.php$x
network_content_initmod/network.php$arr
network_pingmod/ping.php$arr
network_tabsinclude/conversation.php$arr
network_to_nameinclude/contact_selectors.php$nets
notifier_endinclude/notifier.php$target_item
notifier_hubinclude/notifier.php$narr
notifier_normalinclude/deliver_hooks.php$r[0]
obj_verbsinclude/taxonomy.php$arr
oembed_probeinclude/oembed.php$x
page_content_topindex.php$a->page[content]
page_endindex.php$a->page[content]
page_headerinclude/nav.php$a->page[nav]
parse_atominclude/items.php$arr
parse_linkmod/linkinfo.php$arr
pdl_selectorinclude/comanche.php$arr
perm_is_allowedinclude/permissions.php$arr
permissions_createinclude/notifier.php$perm_update
permissions_updateinclude/notifier.php$perm_update
personal_xrdmod/xrd.php$arr
photo_post_endinclude/photos.php$ret
photo_post_endinclude/photos.php$ret
photo_upload_begininclude/attach.php$arr
photo_upload_begininclude/photos.php$args
photo_upload_endinclude/attach.php$ret
photo_upload_endinclude/attach.php$ret
photo_upload_endinclude/attach.php$ret
photo_upload_endinclude/attach.php$ret
photo_upload_endinclude/attach.php$ret
photo_upload_endinclude/photos.php$ret
photo_upload_endinclude/photos.php$ret
photo_upload_endinclude/photos.php$ret
photo_upload_endinclude/photos.php$ret
photo_upload_fileinclude/attach.php$f
photo_upload_fileinclude/photos.php$f
photo_upload_formmod/photos.php$ret
poke_verbsinclude/text.php$arr
post_localinclude/zot.php$arr
post_localinclude/items.php$arr
post_localmod/item.php$datarray
post_local_endinclude/items.php$arr
post_local_endinclude/attach.php$arr
post_local_endinclude/attach.php$arr
post_local_endextend/addon/matrix/randpost/randpost.php$x
post_local_endextend/addon/matrix/randpost/randpost.php$x
post_local_endmod/mood.php$arr
post_local_endmod/like.php$arr
post_local_endmod/item.php$datarray
post_local_endmod/subthread.php$arr
post_local_startmod/item.php$_REQUEST
post_mailinclude/items.php$arr
post_mail_endinclude/items.php$arr
post_remoteinclude/items.php$arr
post_remote_endinclude/items.php$arr
post_remote_updateinclude/items.php$arr
post_remote_update_endinclude/items.php$arr
prepare_bodyinclude/text.php$prep_arr
prepare_body_finalinclude/text.php$prep_arr
prepare_body_initinclude/text.php$item
probe_well_knowninclude/probe.php$ret
proc_runboot.php$arr
process_channel_sync_deliveryinclude/zot.php$addon
profile_advancedmod/profile.php$o
profile_editmod/profiles.php$arr
profile_photo_content_endmod/profile_photo.php$o
profile_postmod/profiles.php$_POST
profile_sidebarinclude/channel.php$arr
profile_sidebar_enterinclude/channel.php$profile
profile_tabsinclude/conversation.php$arr
register_accountinclude/account.php$result
render_locationinclude/conversation.php$locate
replace_macrosinclude/text.php$arr
reverse_magic_authmod/rmagic.php$arr
settings_accountmod/settings.php$_POST
settings_formmod/settings.php$o
settings_postmod/settings.php$_POST
sexpref_selectorinclude/profile_selectors.php$select
sexpref_selector_mininclude/profile_selectors.php$select
smilieinclude/text.php$params
smilieextend/addon/matrix/smileybutton/smileybutton.php$params
taggedinclude/items.php$arr
validate_channelnameinclude/channel.php$arr
webfingermod/wfinger.php$arr
well_knownmod/_well_known.php$arr
zidinclude/channel.php$arr
zid_initinclude/channel.php$arr
zot_fingerinclude/zot.php$ret

Generated Tue Nov 03 21:19:02 PST 2015

\ No newline at end of file +

Hooks

FunctionSource FileArg
$a->module . _mod_aftercontentindex.php$arr
$a->module . _mod_contentindex.php$arr
$a->module . _mod_initindex.php$placeholder
$a->module . _mod_postindex.php$_POST
$a->module . _post_ . $selnameinclude/acl_selectors.php$o
$a->module . _post_ . $selnameinclude/acl_selectors.php$o
$a->module . _post_ . $selnameinclude/acl_selectors.php$o
$a->module . _pre_ . $selnameinclude/acl_selectors.php$arr
$a->module . _pre_ . $selnameinclude/acl_selectors.php$arr
$a->module . _pre_ . $selnameinclude/acl_selectors.php$arr
$nameinclude/plugin.php&$data = null
about_hookmod/siteinfo.php$o
accept_followmod/connedit.php$arr
account_downgradeinclude/account.php$ret
account_downgradeinclude/account.php$ret
account_settingsmod/settings.php$account_settings
activity_receivedinclude/zot.php$parr
affinity_labelsinclude/widgets.php$labels
affinity_labelsmod/connedit.php$labels
api_perm_is_allowedinclude/permissions.php$arr
app_menuindex.php$arr
atom_authorinclude/items.php$o
atom_entryinclude/items.php$o
atom_feedinclude/items.php$atom
atom_feed_endinclude/items.php$atom
attach_upload_fileinclude/attach.php$f
authenticateinclude/auth.php$addon_auth
avatar_lookupinclude/network.php$avatar
bb2diasporainclude/markdown.php$Text
bbcodeinclude/bbcode.php$Text
channel_removeinclude/Contact.php$r[0]
chat_messageinclude/chat.php$arr
chat_postmod/chatsvc.php$arr
check_account_emailinclude/account.php$arr
check_account_inviteinclude/account.php$arr
check_account_passwordinclude/account.php$arr
connect_premiummod/connect.php$arr
connector_settingsmod/settings.php$settings_connectors
construct_pageboot.php$arr
contact_block_endinclude/text.php$arr
contact_editmod/connedit.php$arr
contact_edit_postmod/connedit.php$_POST
contact_select_optionsinclude/acl_selectors.php$x
conversation_startinclude/conversation.php$cb
create_identityinclude/channel.php$newuid
croninclude/cronhooks.php$d
cron_dailyinclude/poller.phpdatetime_convert()
cron_weeklyinclude/poller.phpdatetime_convert()
directory_itemmod/directory.php$arr
discover_by_webbieinclude/network.php$arr
display_iteminclude/ItemObject.php$arr
display_iteminclude/conversation.php$arr
display_settingsmod/settings.php$o
display_settings_postmod/settings.php$_POST
donate_contributorsextend/addon/matrix/donate/donate.php$contributors
donate_pluginextend/addon/matrix/donate/donate.php$o
donate_sponsorsextend/addon/matrix/donate/donate.php$sponsors
dreport_is_storableinclude/zot.php$dr
drop_iteminclude/items.php$arr
enotifyinclude/enotify.php$h
enotify_mailinclude/enotify.php$datarray
enotify_storeinclude/enotify.php$datarray
event_createdinclude/event.php$event[id]
event_updatedinclude/event.php$event[id]
externals_url_selectinclude/externals.php$arr
feature_enabledinclude/features.php$arr
feature_settingsmod/settings.php$settings_addons
feature_settings_postmod/settings.php$_POST
followinclude/follow.php$arr
followinclude/follow.php$arr
follow_allowinclude/follow.php$x
gender_selectorinclude/profile_selectors.php$select
gender_selector_mininclude/profile_selectors.php$select
generate_mapinclude/text.php$arr
generate_named_mapinclude/text.php$arr
get_all_api_permsinclude/permissions.php$arr
get_all_permsinclude/permissions.php$arr
get_featuresinclude/features.php$arr
get_role_permsinclude/permissions.php$ret
get_widgetsboot.php$arr
get_widgetsboot.php$arr
global_permissionsinclude/permissions.php$ret
home_contentmod/home.php$o
home_initmod/home.php$ret
hostxrdmod/hostxrd.php$arr
html2bbcodeinclude/html2bbcode.php$message
identity_basic_exportinclude/channel.php$addon
import_author_xchaninclude/items.php$arr
import_channelmod/import.php$addon
import_directory_profileinclude/zot.php$d
import_xchaninclude/zot.php$arr
item_photo_menuinclude/conversation.php$args
item_storeinclude/items.php$d
item_storeinclude/items.php$arr
item_store_updateinclude/items.php$d
item_translateinclude/items.php$translate
item_translateinclude/items.php$translate
jot_networksinclude/acl_selectors.php$jotnets
jot_networksinclude/conversation.php$jotnets
jot_networksmod/editblock.php$jotnets
jot_networksmod/editpost.php$jotnets
jot_networksmod/editwebpage.php$jotnets
jot_networksmod/editlayout.php$jotnets
jot_toolinclude/conversation.php$jotplugins
jot_toolmod/editblock.php$jotplugins
jot_toolmod/editpost.php$jotplugins
jot_toolmod/editwebpage.php$jotplugins
jot_toolmod/editlayout.php$jotplugins
load_pdlboot.php$arr
local_dir_updateinclude/dir_fns.php$arr
logged_ininclude/oauth.php$a->user
logged_ininclude/api.php$a->user
logged_ininclude/security.php$a->account
logged_ininclude/security.php$user_record
logging_outinclude/auth.php$args
login_hookboot.php$o
magic_authmod/magic.php$arr
magic_auth_openid_successmod/openid.php$arr
magic_auth_openid_successmod/openid.php$arr
magic_auth_successmod/post.php$arr
main_sliderinclude/widgets.php$arr
marital_selectorinclude/profile_selectors.php$select
marital_selector_mininclude/profile_selectors.php$select
module_loadedindex.php$x
mood_verbsinclude/text.php$arr
navinclude/nav.php$x
network_content_initmod/network.php$arr
network_pingmod/ping.php$arr
network_tabsinclude/conversation.php$arr
network_to_nameinclude/contact_selectors.php$nets
notifier_endinclude/notifier.php$target_item
notifier_hubinclude/notifier.php$narr
notifier_normalinclude/deliver_hooks.php$r[0]
obj_verbsinclude/taxonomy.php$arr
oembed_probeinclude/oembed.php$x
page_content_topindex.php$a->page[content]
page_endindex.php$a->page[content]
page_headerinclude/nav.php$a->page[nav]
parse_atominclude/items.php$arr
parse_linkmod/linkinfo.php$arr
pdl_selectorinclude/comanche.php$arr
perm_is_allowedinclude/permissions.php$arr
permissions_createinclude/notifier.php$perm_update
permissions_updateinclude/notifier.php$perm_update
personal_xrdmod/xrd.php$arr
photo_post_endinclude/photos.php$ret
photo_post_endinclude/photos.php$ret
photo_upload_begininclude/attach.php$arr
photo_upload_begininclude/photos.php$args
photo_upload_endinclude/attach.php$ret
photo_upload_endinclude/attach.php$ret
photo_upload_endinclude/attach.php$ret
photo_upload_endinclude/attach.php$ret
photo_upload_endinclude/attach.php$ret
photo_upload_endinclude/photos.php$ret
photo_upload_endinclude/photos.php$ret
photo_upload_endinclude/photos.php$ret
photo_upload_endinclude/photos.php$ret
photo_upload_fileinclude/attach.php$f
photo_upload_fileinclude/photos.php$f
photo_upload_formmod/photos.php$ret
poke_verbsinclude/text.php$arr
post_localinclude/zot.php$arr
post_localinclude/items.php$arr
post_localmod/item.php$datarray
post_local_endinclude/items.php$arr
post_local_endinclude/attach.php$arr
post_local_endinclude/attach.php$arr
post_local_endextend/addon/matrix/randpost/randpost.php$x
post_local_endextend/addon/matrix/randpost/randpost.php$x
post_local_endmod/mood.php$arr
post_local_endmod/like.php$arr
post_local_endmod/item.php$datarray
post_local_endmod/subthread.php$arr
post_local_startmod/item.php$_REQUEST
post_mailinclude/items.php$arr
post_mail_endinclude/items.php$arr
post_remoteinclude/items.php$arr
post_remote_endinclude/items.php$arr
post_remote_updateinclude/items.php$arr
post_remote_update_endinclude/items.php$arr
prepare_bodyinclude/text.php$prep_arr
prepare_body_finalinclude/text.php$prep_arr
prepare_body_initinclude/text.php$item
probe_well_knowninclude/probe.php$ret
proc_runboot.php$arr
process_channel_sync_deliveryinclude/zot.php$addon
profile_advancedmod/profile.php$o
profile_editmod/profiles.php$arr
profile_photo_content_endmod/profile_photo.php$o
profile_postmod/profiles.php$_POST
profile_sidebarinclude/channel.php$arr
profile_sidebar_enterinclude/channel.php$profile
profile_tabsinclude/conversation.php$arr
register_accountinclude/account.php$result
render_locationinclude/conversation.php$locate
replace_macrosinclude/text.php$arr
reverse_magic_authmod/rmagic.php$arr
settings_accountmod/settings.php$_POST
settings_formmod/settings.php$o
settings_postmod/settings.php$_POST
sexpref_selectorinclude/profile_selectors.php$select
sexpref_selector_mininclude/profile_selectors.php$select
smilieinclude/text.php$params
smilieextend/addon/matrix/smileybutton/smileybutton.php$params
taggedinclude/items.php$arr
validate_channelnameinclude/channel.php$arr
webfingermod/wfinger.php$arr
well_knownmod/_well_known.php$arr
zidinclude/channel.php$arr
zid_initinclude/channel.php$arr
zot_fingerinclude/zot.php$ret

Generated Tue Nov 03 21:19:02 PST 2015

\ No newline at end of file diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php deleted file mode 100644 index 1759154f0..000000000 --- a/include/bb2diaspora.php +++ /dev/null @@ -1,532 +0,0 @@ - array('open' => $start_open, 'close' => $start_close), - 'end' => array('open' => $end_open, 'close' => $end_open + strlen('[/' . $name . ']')) ); - if( $start_equal !== false) - $res['start']['equal'] = $start_equal + 1; - - return $res; -} - -function bb_tag_preg_replace($pattern, $replace, $name, $s) { - - $string = $s; - - $occurance = 1; - $pos = get_bb_tag_pos($string, $name, $occurance); - while($pos !== false && $occurance < 1000) { - - $start = substr($string, 0, $pos['start']['open']); - $subject = substr($string, $pos['start']['open'], $pos['end']['close'] - $pos['start']['open']); - $end = substr($string, $pos['end']['close']); - if($end === false) - $end = ''; - - $subject = preg_replace($pattern, $replace, $subject); - $string = $start . $subject . $end; - - $occurance++; - $pos = get_bb_tag_pos($string, $name, $occurance); - } - - return $string; -} - -function share_shield($m) { - return str_replace($m[1],'!=+=+=!' . base64url_encode($m[1]) . '=+!=+!=',$m[0]); -} - -function share_unshield($m) { - $x = str_replace(array('!=+=+=!','=+!=+!='),array('',''),$m[1]); - return str_replace($m[1], base64url_decode($x), $m[0]); -} - - -function diaspora_mention_callback($matches) { - - $webbie = $matches[2] . '@' . $matches[3]; - $link = ''; - if($webbie) { - $r = q("select * from hubloc left join xchan on hubloc_hash = xchan_hash where hubloc_addr = '%s' limit 1", - dbesc($webbie) - ); - if(! $r) { - $x = discover_by_webbie($webbie); - if($x) { - $r = q("select * from hubloc left join xchan on hubloc_hash = xchan_hash where hubloc_addr = '%s' limit 1", - dbesc($webbie) - ); - } - } - if($r) - $link = $r[0]['xchan_url']; - } - if(! $link) - $link = 'https://' . $matches[3] . '/u/' . $matches[2]; - - if($r && $r[0]['hubloc_network'] === 'zot') - return '@[zrl=' . $link . ']' . trim($matches[1]) . ((substr($matches[0],-1,1) === '+') ? '+' : '') . '[/zrl]' ; - else - return '@[url=' . $link . ']' . trim($matches[1]) . ((substr($matches[0],-1,1) === '+') ? '+' : '') . '[/url]' ; - -} - - -/** - * @brief - * - * We don't want to support a bbcode specific markdown interpreter - * and the markdown library we have is pretty good, but provides HTML output. - * So we'll use that to convert to HTML, then convert the HTML back to bbcode, - * and then clean up a few Diaspora specific constructs. - * - * @param string $s - * @param boolean $use_zrl default false - * @return string - */ -function markdown_to_bb($s, $use_zrl = false) { - - $s = str_replace(" ","\r",$s); - $s = str_replace(" \n>","",$s); - - if(is_array($s)) { - btlogger('markdown_to_bb called with array. ' . print_r($s,true), LOGGER_NORMAL, LOG_WARNING); - return ''; - } - - $s = html_entity_decode($s,ENT_COMPAT,'UTF-8'); - - // if empty link text replace with the url - $s = preg_replace("/\[\]\((.*?)\)/ism",'[$1]($1)',$s); - - // first try plustags - - $s = preg_replace_callback('/\@\{(.+?)\; (.+?)\@(.+?)\}\+/','diaspora_mention_callback',$s); - - $s = preg_replace_callback('/\@\{(.+?)\; (.+?)\@(.+?)\}/','diaspora_mention_callback',$s); - - // Escaping the hash tags - doesn't always seem to work - // $s = preg_replace('/\#([^\s\#])/','\\#$1',$s); - // This seems to work - $s = preg_replace('/\#([^\s\#])/','#$1',$s); - - $s = Markdown($s); - - $s = str_replace("\r","",$s); - - $s = str_replace('#','#',$s); - - $s = html2bbcode($s); - - // protect the recycle symbol from turning into a tag, but without unescaping angles and naked ampersands - $s = str_replace('♲',html_entity_decode('♲',ENT_QUOTES,'UTF-8'),$s); - - // Convert everything that looks like a link to a link - if($use_zrl) { - $s = str_replace(array('[img','/img]'),array('[zmg','/zmg]'),$s); - $s = preg_replace("/([^\]\=]|^)(https?\:\/\/)([a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,\(\)]+)/ism", '$1[zrl=$2$3]$2$3[/zrl]',$s); - } - else { - $s = preg_replace("/([^\]\=]|^)(https?\:\/\/)([a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,\(\)]+)/ism", '$1[url=$2$3]$2$3[/url]',$s); - } - - // remove duplicate adjacent code tags - $s = preg_replace("/(\[code\])+(.*?)(\[\/code\])+/ism","[code]$2[/code]", $s); - - // Don't show link to full picture (until it is fixed) - $s = scale_external_images($s, false); - - call_hooks('markdown_to_bb',$s); - - return $s; -} - - -function stripdcode_br_cb($s) { - return '[code]' . str_replace('
', "\n\t", $s[1]) . '[/code]'; -} - - -////////////////////// -// The following "diaspora_ul" and "diaspora_ol" are only appropriate for the -// pre-Markdownify conversion. If Markdownify isn't used, use the non-Markdownify -// versions below -////////////////////// -/* -function diaspora_ul($s) { - // Replace "[*]" followed by any number (including zero) of - // spaces by "* " to match Diaspora's list format - if( strpos($s[0], "[list]") === 0 ) - return ''; - elseif( strpos($s[0], "[ul]") === 0 ) - return ''; - else - return $s[0]; -} - - -function diaspora_ol($s) { - // A hack: Diaspora will create a properly-numbered ordered list even - // if you use '1.' for each element of the list, like: - // 1. First element - // 1. Second element - // 1. Third element - if( strpos($s[0], "[list=1]") === 0 ) - return ''; - elseif( strpos($s[0], "[list=i]") === 0 ) - return ''; - elseif( strpos($s[0], "[list=I]") === 0 ) - return ''; - elseif( strpos($s[0], "[list=a]") === 0 ) - return ''; - elseif( strpos($s[0], "[list=A]") === 0 ) - return ''; - elseif( strpos($s[0], "[ol]") === 0 ) - return ''; - else - return $s[0]; -} -*/ - -////////////////////// -// Non-Markdownify versions of "diaspora_ol" and "diaspora_ul" -////////////////////// -/** - * @brief - * - * Replace "[\\*]" followed by any number (including zero) of - * spaces by "* " to match Diaspora's list format. - * - * @param string $s - * @return string - */ -function diaspora_ul($s) { - return preg_replace("/\[\\\\\*\]( *)/", "* ", $s[1]); -} - -/** - * @brief - * - * A hack: Diaspora will create a properly-numbered ordered list even - * if you use '1.' for each element of the list, like: - * \code - * 1. First element - * 1. Second element - * 1. Third element - * \endcode - * @param string $s - * @return string - */ -function diaspora_ol($s) { - return preg_replace("/\[\\\\\*\]( *)/", "1. ", $s[1]); -} - -function bb2dmention_callback($match) { - - $r = q("select xchan_addr from xchan where xchan_url = '%s'", - dbesc($match[2]) - ); - - if($r) - return '@{' . $match[3] . ' ; ' . $r[0]['xchan_addr'] . '}'; - - return '@' . $match[3]; -} - - -function bb2diaspora_itemwallwall(&$item,$uplink = false) { - - // We will provide wallwall (embedded author on the Diaspora side) if - // 1. It is a wall-to-wall post - // 2. A comment arrived which has no Diaspora signature info - - - $wallwall = false; - $author_exists = true; - - if(! array_key_exists('author',$item)) { - $author_exists = false; - logger('bb2diaspora_itemwallwall: no author'); - $r = q("select * from xchan where xchan_hash = '%s' limit 1", - dbesc($item['author_xchan']) - ); - if($r) - $item['author'] = $r[0]; - } - - $has_meta = false; - if($item['diaspora_meta'] || get_iconfig($item,'diaspora','fields')) - $has_meta = true; - - if($item['author_xchan'] != $item['owner_xchan']) { - if($item['mid'] == $item['parent_mid']) - $wallwall = true; - else { - if(! $has_meta) { - $wallwall = true; - } - } - } - - if($uplink) - $wallwall = true; - - if(($wallwall) && (is_array($item['author'])) && $item['author']['xchan_url'] && $item['author']['xchan_name'] && $item['author']['xchan_photo_s']) { - logger('bb2diaspora_itemwallwall: wall to wall post',LOGGER_DEBUG); - // post will come across with the owner's identity. Throw a preamble onto the post to indicate the true author. - $item['body'] = "\n\n" - . '[quote]' - . '[img]' . $item['author']['xchan_photo_s'] . '[/img]' - . ' ' - . '[url=' . $item['author']['xchan_url'] . '][b]' . $item['author']['xchan_name'] . '[/b][/url]' . "\n\n" - . $item['body'] - . '[/quote]'; - } - - // $item['author'] might cause a surprise further down the line if it wasn't expected to be here. - - if(! $author_exists) - unset($item['author']); -} - - -function bb2diaspora_itembody($item, $force_update = false, $have_channel = false, $uplink = false) { - - - if(! get_iconfig($item,'diaspora','fields')) { - $force_update = true; - } - - $matches = array(); - - if(($item['diaspora_meta']) && (! $force_update)) { - $diaspora_meta = json_decode($item['diaspora_meta'],true); - if($diaspora_meta) { - if(array_key_exists('iv',$diaspora_meta)) { - $key = get_config('system','prvkey'); - $meta = json_decode(crypto_unencapsulate($diaspora_meta,$key),true); - } - else { - $meta = $diaspora_meta; - } - if($meta) { - logger('bb2diaspora_itembody: cached '); - $newitem = $item; - $newitem['body'] = $meta['body']; - return $newitem['body']; - } - } - } - - create_export_photo_body($item); - - $newitem = $item; - - if(array_key_exists('item_obscured',$item) && intval($item['item_obscured'])) { - $key = get_config('system','prvkey'); - $b = json_decode($item['body'],true); - // if called from diaspora_process_outbound, this decoding has already been done. - // Everything else that calls us will not yet be decoded. - if($b && is_array($b) && array_key_exists('iv',$b)) { - $newitem['title'] = (($item['title']) ? crypto_unencapsulate(json_decode($item['title'],true),$key) : ''); - $newitem['body'] = (($item['body']) ? crypto_unencapsulate(json_decode($item['body'],true),$key) : ''); - } - } - - if(! $have_channel) - bb2diaspora_itemwallwall($newitem,$uplink); - - $title = $newitem['title']; - $body = preg_replace('/\#\^http/i', 'http', $newitem['body']); - - // protect tags and mentions from hijacking - - if(intval(get_pconfig($item['uid'],'system','prevent_tag_hijacking'))) { - $new_tag = html_entity_decode('⋕',ENT_COMPAT,'UTF-8'); - $new_mention = html_entity_decode('@',ENT_COMPAT,'UTF-8'); - - // #-tags - $body = preg_replace('/\#\[url/i', $new_tag . '[url', $body); - $body = preg_replace('/\#\[zrl/i', $new_tag . '[zrl', $body); - // @-mentions - $body = preg_replace('/\@\!?\[url/i', $new_mention . '[url', $body); - $body = preg_replace('/\@\!?\[zrl/i', $new_mention . '[zrl', $body); - } - - // remove multiple newlines - do { - $oldbody = $body; - $body = str_replace("\n\n\n", "\n\n", $body); - } while ($oldbody != $body); - - $body = bb2diaspora($body); - - if(strlen($title)) - $body = "## " . $title . "\n\n" . $body; - - if($item['attach']) { - $cnt = preg_match_all('/href=\"(.*?)\"(.*?)title=\"(.*?)\"/ism', $item['attach'], $matches, PREG_SET_ORDER); - if($cnt) { - $body .= "\n" . t('Attachments:') . "\n"; - foreach($matches as $mtch) { - $body .= '[' . $mtch[3] . '](' . $mtch[1] . ')' . "\n"; - } - } - } - -// logger('bb2diaspora_itembody : ' . $body, LOGGER_DATA); - - return html_entity_decode($body); -} - -function bb2diaspora($Text,$preserve_nl = false, $fordiaspora = true) { - - // Re-enabling the converter again. - // The bbcode parser now handles youtube-links (and the other stuff) correctly. - // Additionally the html code is now fixed so that lists are now working. - - /* - * Transform #tags, strip off the [url] and replace spaces with underscore - */ - $Text = preg_replace_callback('/#\[([zu])rl\=(\w+.*?)\](\w+.*?)\[\/[(zu)]rl\]/i', create_function('$match', - 'return \'#\'. str_replace(\' \', \'_\', $match[3]);' - ), $Text); - - $Text = preg_replace('/#\^\[([zu])rl\=(\w+.*?)\](\w+.*?)\[\/([zu])rl\]/i', '[$1rl=$2]$3[/$4rl]', $Text); - - $Text = preg_replace_callback('/\@\!?\[([zu])rl\=(\w+.*?)\](\w+.*?)\[\/([zu])rl\]/i', 'bb2dmention_callback', $Text); - - // strip map tags, as the rendering is performed in bbcode() and the resulting output - // is not compatible with Diaspora (at least in the case of openstreetmap and probably - // due to the inclusion of an html iframe) - - $Text = preg_replace("/\[map\=(.*?)\]/ism", '$1', $Text); - $Text = preg_replace("/\[map\](.*?)\[\/map\]/ism", '$1', $Text); - - // Converting images with size parameters to simple images. Markdown doesn't know it. - $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $Text); - - // the following was added on 10-January-2012 due to an inability of Diaspora's - // new javascript markdown processor to handle links with images as the link "text" - // It is not optimal and may be removed if this ability is restored in the future - //if ($fordiaspora) - // $Text = preg_replace("/\[url\=([^\[\]]*)\]\s*\[img\](.*?)\[\/img\]\s*\[\/url\]/ism", - // "[url]$1[/url]\n[img]$2[/img]", $Text); - - // Convert it to HTML - don't try oembed - $Text = bbcode($Text, $preserve_nl, false); - - // Markdownify does not preserve previously escaped html entities such as <> and &. - - $Text = str_replace(array('<','>','&'),array('&_lt_;','&_gt_;','&_amp_;'),$Text); - - // Now convert HTML to Markdown - $md = new Markdownify(false, false, false); - $Text = $md->parseString($Text); - - - - // It also adds backslashes to our attempt at getting around the html entity preservation for some weird reason. - - $Text = str_replace(array('&\\_lt\\_;','&\\_gt\\_;','&\\_amp\\_;'),array('<','>','&'),$Text); - - // If the text going into bbcode() has a plain URL in it, i.e. - // with no [url] tags around it, it will come out of parseString() - // looking like: , which gets removed by strip_tags(). - // So take off the angle brackets of any such URL - $Text = preg_replace("//is", "http$1", $Text); - - // Remove empty zrl links - $Text = preg_replace("/\[zrl\=\].*?\[\/zrl\]/is", "", $Text); - - // Remove all unconverted tags - $Text = strip_tags($Text); - - // Remove any leading or trailing whitespace, as this will mess up - // the Diaspora signature verification and cause the item to disappear - - $Text = trim($Text); - - call_hooks('bb2diaspora',$Text); - - return $Text; -} - -function unescape_underscores_in_links($m) { - $y = str_replace('\\_','_', $m[2]); - return('[' . $m[1] . '](' . $y . ')'); -} - -function format_event_diaspora($ev) { - - if(! ((is_array($ev)) && count($ev))) - return ''; - - $bd_format = t('l F d, Y \@ g:i A') ; // Friday January 18, 2011 @ 8 AM - - $o = t('$Projectname event notification:') . "\n"; - - $o .= '**' . (($ev['summary']) ? bb2diaspora($ev['summary']) : bb2diaspora($ev['desc'])) . '**' . "\n"; - - $o .= t('Starts:') . ' ' . '[' - . (($ev['adjust']) ? day_translate(datetime_convert('UTC', 'UTC', - $ev['start'] , $bd_format )) - : day_translate(datetime_convert('UTC', 'UTC', - $ev['start'] , $bd_format))) - . '](' . z_root() . '/localtime/?f=&time=' . urlencode(datetime_convert('UTC','UTC',$ev['start'])) . ")\n"; - - if(! $ev['nofinish']) - $o .= t('Finishes:') . ' ' . '[' - . (($ev['adjust']) ? day_translate(datetime_convert('UTC', 'UTC', - $ev['finish'] , $bd_format )) - : day_translate(datetime_convert('UTC', 'UTC', - $ev['finish'] , $bd_format ))) - . '](' . z_root() . '/localtime/?f=&time=' . urlencode(datetime_convert('UTC','UTC',$ev['finish'])) . ")\n"; - - if(strlen($ev['location'])) - $o .= t('Location:') . bb2diaspora($ev['location']) - . "\n"; - - $o .= "\n"; - - return $o; -} diff --git a/include/items.php b/include/items.php index 559992b7f..139c637e5 100755 --- a/include/items.php +++ b/include/items.php @@ -2191,7 +2191,7 @@ function store_diaspora_comment_sig($datarray, $channel, $parent_item, $post_id, // since Diaspora doesn't handle edits we can only do this for the original text and not update it. - require_once('include/bb2diaspora.php'); + require_once('include/markdown.php'); $signed_body = bb2diaspora_itembody($datarray,$walltowall); if($walltowall) { diff --git a/include/markdown.php b/include/markdown.php new file mode 100644 index 000000000..b4656f769 --- /dev/null +++ b/include/markdown.php @@ -0,0 +1,532 @@ + array('open' => $start_open, 'close' => $start_close), + 'end' => array('open' => $end_open, 'close' => $end_open + strlen('[/' . $name . ']')) ); + if( $start_equal !== false) + $res['start']['equal'] = $start_equal + 1; + + return $res; +} + +function bb_tag_preg_replace($pattern, $replace, $name, $s) { + + $string = $s; + + $occurance = 1; + $pos = get_bb_tag_pos($string, $name, $occurance); + while($pos !== false && $occurance < 1000) { + + $start = substr($string, 0, $pos['start']['open']); + $subject = substr($string, $pos['start']['open'], $pos['end']['close'] - $pos['start']['open']); + $end = substr($string, $pos['end']['close']); + if($end === false) + $end = ''; + + $subject = preg_replace($pattern, $replace, $subject); + $string = $start . $subject . $end; + + $occurance++; + $pos = get_bb_tag_pos($string, $name, $occurance); + } + + return $string; +} + +function share_shield($m) { + return str_replace($m[1],'!=+=+=!' . base64url_encode($m[1]) . '=+!=+!=',$m[0]); +} + +function share_unshield($m) { + $x = str_replace(array('!=+=+=!','=+!=+!='),array('',''),$m[1]); + return str_replace($m[1], base64url_decode($x), $m[0]); +} + + +function diaspora_mention_callback($matches) { + + $webbie = $matches[2] . '@' . $matches[3]; + $link = ''; + if($webbie) { + $r = q("select * from hubloc left join xchan on hubloc_hash = xchan_hash where hubloc_addr = '%s' limit 1", + dbesc($webbie) + ); + if(! $r) { + $x = discover_by_webbie($webbie); + if($x) { + $r = q("select * from hubloc left join xchan on hubloc_hash = xchan_hash where hubloc_addr = '%s' limit 1", + dbesc($webbie) + ); + } + } + if($r) + $link = $r[0]['xchan_url']; + } + if(! $link) + $link = 'https://' . $matches[3] . '/u/' . $matches[2]; + + if($r && $r[0]['hubloc_network'] === 'zot') + return '@[zrl=' . $link . ']' . trim($matches[1]) . ((substr($matches[0],-1,1) === '+') ? '+' : '') . '[/zrl]' ; + else + return '@[url=' . $link . ']' . trim($matches[1]) . ((substr($matches[0],-1,1) === '+') ? '+' : '') . '[/url]' ; + +} + + +/** + * @brief + * + * We don't want to support a bbcode specific markdown interpreter + * and the markdown library we have is pretty good, but provides HTML output. + * So we'll use that to convert to HTML, then convert the HTML back to bbcode, + * and then clean up a few Diaspora specific constructs. + * + * @param string $s + * @param boolean $use_zrl default false + * @return string + */ +function markdown_to_bb($s, $use_zrl = false) { + + $s = str_replace(" ","\r",$s); + $s = str_replace(" \n>","",$s); + + if(is_array($s)) { + btlogger('markdown_to_bb called with array. ' . print_r($s,true), LOGGER_NORMAL, LOG_WARNING); + return ''; + } + + $s = html_entity_decode($s,ENT_COMPAT,'UTF-8'); + + // if empty link text replace with the url + $s = preg_replace("/\[\]\((.*?)\)/ism",'[$1]($1)',$s); + + // first try plustags + + $s = preg_replace_callback('/\@\{(.+?)\; (.+?)\@(.+?)\}\+/','diaspora_mention_callback',$s); + + $s = preg_replace_callback('/\@\{(.+?)\; (.+?)\@(.+?)\}/','diaspora_mention_callback',$s); + + // Escaping the hash tags - doesn't always seem to work + // $s = preg_replace('/\#([^\s\#])/','\\#$1',$s); + // This seems to work + $s = preg_replace('/\#([^\s\#])/','#$1',$s); + + $s = Markdown($s); + + $s = str_replace("\r","",$s); + + $s = str_replace('#','#',$s); + + $s = html2bbcode($s); + + // protect the recycle symbol from turning into a tag, but without unescaping angles and naked ampersands + $s = str_replace('♲',html_entity_decode('♲',ENT_QUOTES,'UTF-8'),$s); + + // Convert everything that looks like a link to a link + if($use_zrl) { + $s = str_replace(array('[img','/img]'),array('[zmg','/zmg]'),$s); + $s = preg_replace("/([^\]\=]|^)(https?\:\/\/)([a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,\(\)]+)/ism", '$1[zrl=$2$3]$2$3[/zrl]',$s); + } + else { + $s = preg_replace("/([^\]\=]|^)(https?\:\/\/)([a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,\(\)]+)/ism", '$1[url=$2$3]$2$3[/url]',$s); + } + + // remove duplicate adjacent code tags + $s = preg_replace("/(\[code\])+(.*?)(\[\/code\])+/ism","[code]$2[/code]", $s); + + // Don't show link to full picture (until it is fixed) + $s = scale_external_images($s, false); + + call_hooks('markdown_to_bb',$s); + + return $s; +} + + +function stripdcode_br_cb($s) { + return '[code]' . str_replace('
', "\n\t", $s[1]) . '[/code]'; +} + + +////////////////////// +// The following "diaspora_ul" and "diaspora_ol" are only appropriate for the +// pre-Markdownify conversion. If Markdownify isn't used, use the non-Markdownify +// versions below +////////////////////// +/* +function diaspora_ul($s) { + // Replace "[*]" followed by any number (including zero) of + // spaces by "* " to match Diaspora's list format + if( strpos($s[0], "[list]") === 0 ) + return '
    ' . preg_replace("/\[\*\]( *)/", "* ", $s[1]) . '
'; + elseif( strpos($s[0], "[ul]") === 0 ) + return '
    ' . preg_replace("/\[\*\]( *)/", "* ", $s[1]) . '
'; + else + return $s[0]; +} + + +function diaspora_ol($s) { + // A hack: Diaspora will create a properly-numbered ordered list even + // if you use '1.' for each element of the list, like: + // 1. First element + // 1. Second element + // 1. Third element + if( strpos($s[0], "[list=1]") === 0 ) + return '
    ' . preg_replace("/\[\*\]( *)/", "1. ", $s[1]) . '
'; + elseif( strpos($s[0], "[list=i]") === 0 ) + return '
    ' . preg_replace("/\[\*\]( *)/", "1. ", $s[1]) . '
'; + elseif( strpos($s[0], "[list=I]") === 0 ) + return '
    ' . preg_replace("/\[\*\]( *)/", "1. ", $s[1]) . '
'; + elseif( strpos($s[0], "[list=a]") === 0 ) + return '
    ' . preg_replace("/\[\*\]( *)/", "1. ", $s[1]) . '
'; + elseif( strpos($s[0], "[list=A]") === 0 ) + return '
    ' . preg_replace("/\[\*\]( *)/", "1. ", $s[1]) . '
'; + elseif( strpos($s[0], "[ol]") === 0 ) + return '
    ' . preg_replace("/\[\*\]( *)/", "1. ", $s[1]) . '
'; + else + return $s[0]; +} +*/ + +////////////////////// +// Non-Markdownify versions of "diaspora_ol" and "diaspora_ul" +////////////////////// +/** + * @brief + * + * Replace "[\\*]" followed by any number (including zero) of + * spaces by "* " to match Diaspora's list format. + * + * @param string $s + * @return string + */ +function diaspora_ul($s) { + return preg_replace("/\[\\\\\*\]( *)/", "* ", $s[1]); +} + +/** + * @brief + * + * A hack: Diaspora will create a properly-numbered ordered list even + * if you use '1.' for each element of the list, like: + * \code + * 1. First element + * 1. Second element + * 1. Third element + * \endcode + * @param string $s + * @return string + */ +function diaspora_ol($s) { + return preg_replace("/\[\\\\\*\]( *)/", "1. ", $s[1]); +} + +function bb2dmention_callback($match) { + + $r = q("select xchan_addr from xchan where xchan_url = '%s'", + dbesc($match[2]) + ); + + if($r) + return '@{' . $match[3] . ' ; ' . $r[0]['xchan_addr'] . '}'; + + return '@' . $match[3]; +} + + +function bb2diaspora_itemwallwall(&$item,$uplink = false) { + + // We will provide wallwall (embedded author on the Diaspora side) if + // 1. It is a wall-to-wall post + // 2. A comment arrived which has no Diaspora signature info + + + $wallwall = false; + $author_exists = true; + + if(! array_key_exists('author',$item)) { + $author_exists = false; + logger('bb2diaspora_itemwallwall: no author'); + $r = q("select * from xchan where xchan_hash = '%s' limit 1", + dbesc($item['author_xchan']) + ); + if($r) + $item['author'] = $r[0]; + } + + $has_meta = false; + if($item['diaspora_meta'] || get_iconfig($item,'diaspora','fields')) + $has_meta = true; + + if($item['author_xchan'] != $item['owner_xchan']) { + if($item['mid'] == $item['parent_mid']) + $wallwall = true; + else { + if(! $has_meta) { + $wallwall = true; + } + } + } + + if($uplink) + $wallwall = true; + + if(($wallwall) && (is_array($item['author'])) && $item['author']['xchan_url'] && $item['author']['xchan_name'] && $item['author']['xchan_photo_s']) { + logger('bb2diaspora_itemwallwall: wall to wall post',LOGGER_DEBUG); + // post will come across with the owner's identity. Throw a preamble onto the post to indicate the true author. + $item['body'] = "\n\n" + . '[quote]' + . '[img]' . $item['author']['xchan_photo_s'] . '[/img]' + . ' ' + . '[url=' . $item['author']['xchan_url'] . '][b]' . $item['author']['xchan_name'] . '[/b][/url]' . "\n\n" + . $item['body'] + . '[/quote]'; + } + + // $item['author'] might cause a surprise further down the line if it wasn't expected to be here. + + if(! $author_exists) + unset($item['author']); +} + + +function bb2diaspora_itembody($item, $force_update = false, $have_channel = false, $uplink = false) { + + + if(! get_iconfig($item,'diaspora','fields')) { + $force_update = true; + } + + $matches = array(); + + if(($item['diaspora_meta']) && (! $force_update)) { + $diaspora_meta = json_decode($item['diaspora_meta'],true); + if($diaspora_meta) { + if(array_key_exists('iv',$diaspora_meta)) { + $key = get_config('system','prvkey'); + $meta = json_decode(crypto_unencapsulate($diaspora_meta,$key),true); + } + else { + $meta = $diaspora_meta; + } + if($meta) { + logger('bb2diaspora_itembody: cached '); + $newitem = $item; + $newitem['body'] = $meta['body']; + return $newitem['body']; + } + } + } + + create_export_photo_body($item); + + $newitem = $item; + + if(array_key_exists('item_obscured',$item) && intval($item['item_obscured'])) { + $key = get_config('system','prvkey'); + $b = json_decode($item['body'],true); + // if called from diaspora_process_outbound, this decoding has already been done. + // Everything else that calls us will not yet be decoded. + if($b && is_array($b) && array_key_exists('iv',$b)) { + $newitem['title'] = (($item['title']) ? crypto_unencapsulate(json_decode($item['title'],true),$key) : ''); + $newitem['body'] = (($item['body']) ? crypto_unencapsulate(json_decode($item['body'],true),$key) : ''); + } + } + + if(! $have_channel) + bb2diaspora_itemwallwall($newitem,$uplink); + + $title = $newitem['title']; + $body = preg_replace('/\#\^http/i', 'http', $newitem['body']); + + // protect tags and mentions from hijacking + + if(intval(get_pconfig($item['uid'],'system','prevent_tag_hijacking'))) { + $new_tag = html_entity_decode('⋕',ENT_COMPAT,'UTF-8'); + $new_mention = html_entity_decode('@',ENT_COMPAT,'UTF-8'); + + // #-tags + $body = preg_replace('/\#\[url/i', $new_tag . '[url', $body); + $body = preg_replace('/\#\[zrl/i', $new_tag . '[zrl', $body); + // @-mentions + $body = preg_replace('/\@\!?\[url/i', $new_mention . '[url', $body); + $body = preg_replace('/\@\!?\[zrl/i', $new_mention . '[zrl', $body); + } + + // remove multiple newlines + do { + $oldbody = $body; + $body = str_replace("\n\n\n", "\n\n", $body); + } while ($oldbody != $body); + + $body = bb2diaspora($body); + + if(strlen($title)) + $body = "## " . $title . "\n\n" . $body; + + if($item['attach']) { + $cnt = preg_match_all('/href=\"(.*?)\"(.*?)title=\"(.*?)\"/ism', $item['attach'], $matches, PREG_SET_ORDER); + if($cnt) { + $body .= "\n" . t('Attachments:') . "\n"; + foreach($matches as $mtch) { + $body .= '[' . $mtch[3] . '](' . $mtch[1] . ')' . "\n"; + } + } + } + +// logger('bb2diaspora_itembody : ' . $body, LOGGER_DATA); + + return html_entity_decode($body); +} + +function bb2diaspora($Text,$preserve_nl = false, $fordiaspora = true) { + + // Re-enabling the converter again. + // The bbcode parser now handles youtube-links (and the other stuff) correctly. + // Additionally the html code is now fixed so that lists are now working. + + /* + * Transform #tags, strip off the [url] and replace spaces with underscore + */ + $Text = preg_replace_callback('/#\[([zu])rl\=(\w+.*?)\](\w+.*?)\[\/[(zu)]rl\]/i', create_function('$match', + 'return \'#\'. str_replace(\' \', \'_\', $match[3]);' + ), $Text); + + $Text = preg_replace('/#\^\[([zu])rl\=(\w+.*?)\](\w+.*?)\[\/([zu])rl\]/i', '[$1rl=$2]$3[/$4rl]', $Text); + + $Text = preg_replace_callback('/\@\!?\[([zu])rl\=(\w+.*?)\](\w+.*?)\[\/([zu])rl\]/i', 'bb2dmention_callback', $Text); + + // strip map tags, as the rendering is performed in bbcode() and the resulting output + // is not compatible with Diaspora (at least in the case of openstreetmap and probably + // due to the inclusion of an html iframe) + + $Text = preg_replace("/\[map\=(.*?)\]/ism", '$1', $Text); + $Text = preg_replace("/\[map\](.*?)\[\/map\]/ism", '$1', $Text); + + // Converting images with size parameters to simple images. Markdown doesn't know it. + $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $Text); + + // the following was added on 10-January-2012 due to an inability of Diaspora's + // new javascript markdown processor to handle links with images as the link "text" + // It is not optimal and may be removed if this ability is restored in the future + //if ($fordiaspora) + // $Text = preg_replace("/\[url\=([^\[\]]*)\]\s*\[img\](.*?)\[\/img\]\s*\[\/url\]/ism", + // "[url]$1[/url]\n[img]$2[/img]", $Text); + + // Convert it to HTML - don't try oembed + $Text = bbcode($Text, $preserve_nl, false); + + // Markdownify does not preserve previously escaped html entities such as <> and &. + + $Text = str_replace(array('<','>','&'),array('&_lt_;','&_gt_;','&_amp_;'),$Text); + + // Now convert HTML to Markdown + $md = new Markdownify(false, false, false); + $Text = $md->parseString($Text); + + + + // It also adds backslashes to our attempt at getting around the html entity preservation for some weird reason. + + $Text = str_replace(array('&\\_lt\\_;','&\\_gt\\_;','&\\_amp\\_;'),array('<','>','&'),$Text); + + // If the text going into bbcode() has a plain URL in it, i.e. + // with no [url] tags around it, it will come out of parseString() + // looking like: , which gets removed by strip_tags(). + // So take off the angle brackets of any such URL + $Text = preg_replace("//is", "http$1", $Text); + + // Remove empty zrl links + $Text = preg_replace("/\[zrl\=\].*?\[\/zrl\]/is", "", $Text); + + // Remove all unconverted tags + $Text = strip_tags($Text); + + // Remove any leading or trailing whitespace, as this will mess up + // the Diaspora signature verification and cause the item to disappear + + $Text = trim($Text); + + call_hooks('bb2diaspora',$Text); + + return $Text; +} + +function unescape_underscores_in_links($m) { + $y = str_replace('\\_','_', $m[2]); + return('[' . $m[1] . '](' . $y . ')'); +} + +function format_event_diaspora($ev) { + + if(! ((is_array($ev)) && count($ev))) + return ''; + + $bd_format = t('l F d, Y \@ g:i A') ; // Friday January 18, 2011 @ 8 AM + + $o = t('$Projectname event notification:') . "\n"; + + $o .= '**' . (($ev['summary']) ? bb2diaspora($ev['summary']) : bb2diaspora($ev['desc'])) . '**' . "\n"; + + $o .= t('Starts:') . ' ' . '[' + . (($ev['adjust']) ? day_translate(datetime_convert('UTC', 'UTC', + $ev['start'] , $bd_format )) + : day_translate(datetime_convert('UTC', 'UTC', + $ev['start'] , $bd_format))) + . '](' . z_root() . '/localtime/?f=&time=' . urlencode(datetime_convert('UTC','UTC',$ev['start'])) . ")\n"; + + if(! $ev['nofinish']) + $o .= t('Finishes:') . ' ' . '[' + . (($ev['adjust']) ? day_translate(datetime_convert('UTC', 'UTC', + $ev['finish'] , $bd_format )) + : day_translate(datetime_convert('UTC', 'UTC', + $ev['finish'] , $bd_format ))) + . '](' . z_root() . '/localtime/?f=&time=' . urlencode(datetime_convert('UTC','UTC',$ev['finish'])) . ")\n"; + + if(strlen($ev['location'])) + $o .= t('Location:') . bb2diaspora($ev['location']) + . "\n"; + + $o .= "\n"; + + return $o; +} -- cgit v1.2.3