本文整理汇总了PHP中bbtoevent函数的典型用法代码示例。如果您正苦于以下问题:PHP bbtoevent函数的具体用法?PHP bbtoevent怎么用?PHP bbtoevent使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了bbtoevent函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: event_addtocal
function event_addtocal($item_id, $uid)
{
$c = q("select * from channel where channel_id = %d limit 1", intval($uid));
if (!$c) {
return false;
}
$channel = $c[0];
$r = q("select * from item where id = %d and uid = %d limit 1", intval($item_id), intval($channel['channel_id']));
if (!$r || $r[0]['obj_type'] !== ACTIVITY_OBJ_EVENT) {
return false;
}
$item = $r[0];
$ev = bbtoevent($r[0]['body']);
if (x($ev, 'summary') && x($ev, 'start')) {
$ev['event_xchan'] = $item['author_xchan'];
$ev['uid'] = $channel['channel_id'];
$ev['account'] = $channel['channel_account_id'];
$ev['edited'] = $item['edited'];
$ev['mid'] = $item['mid'];
$ev['private'] = $item['item_private'];
// is this an edit?
if ($item['resource_type'] === 'event') {
$ev['event_hash'] = $item['resource_id'];
}
$event = event_store_event($ev);
if ($event) {
$r = q("update item set resource_id = '%s', resource_type = 'event' where id = %d and uid = %d", dbesc($event['event_hash']), intval($item['id']), intval($channel['channel_id']));
$item['resource_id'] = $event['event_hash'];
$item['resource_type'] = 'event';
$i = array($item);
xchan_query($i);
$sync_item = fetch_post_tags($i);
$z = q("select * from event where event_hash = '%s' and uid = %d limit 1", dbesc($event['event_hash']), intval($channel['channel_id']));
if ($z) {
build_sync_packet($channel['channel_id'], array('event_item' => array(encode_item($sync_item[0], true)), 'event' => $z));
}
return true;
}
}
return false;
}
示例2: local_delivery
//.........这里部分代码省略.........
}
}
}
}
$posted_id = item_store($datarray);
// find out if our user is involved in this conversation and wants to be notified.
if (!x($datarray['type']) || $datarray['type'] != 'activity') {
$myconv = q("SELECT `author-link`, `author-avatar`, `parent` FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d AND `parent` != 0 AND `deleted` = 0", dbesc($top_uri), intval($importer['importer_uid']));
if (count($myconv)) {
$importer_url = $a->get_baseurl() . '/profile/' . $importer['nickname'];
// first make sure this isn't our own post coming back to us from a wall-to-wall event
if (!link_compare($datarray['author-link'], $importer_url)) {
foreach ($myconv as $conv) {
// now if we find a match, it means we're in this conversation
if (!link_compare($conv['author-link'], $importer_url)) {
continue;
}
require_once 'include/enotify.php';
$conv_parent = $conv['parent'];
notification(array('type' => NOTIFY_COMMENT, 'notify_flags' => $importer['notify-flags'], 'language' => $importer['language'], 'to_name' => $importer['username'], 'to_email' => $importer['email'], 'uid' => $importer['importer_uid'], 'item' => $datarray, 'link' => $a->get_baseurl() . '/display/' . urlencode(get_item_guid($posted_id)), 'source_name' => stripslashes($datarray['author-name']), 'source_link' => $datarray['author-link'], 'source_photo' => link_compare($datarray['author-link'], $importer['url']) ? $importer['thumb'] : $datarray['author-avatar'], 'verb' => ACTIVITY_POST, 'otype' => 'item', 'parent' => $conv_parent, 'parent_uri' => $parent_uri));
// only send one notification
break;
}
}
}
}
continue;
}
} else {
// Head post of a conversation. Have we seen it? If not, import it.
$item_id = $item->get_id();
$datarray = get_atom_elements($feed, $item);
if (x($datarray, 'object-type') && $datarray['object-type'] === ACTIVITY_OBJ_EVENT) {
$ev = bbtoevent($datarray['body']);
if ((x($ev, 'desc') || x($ev, 'summary')) && x($ev, 'start')) {
$ev['cid'] = $importer['id'];
$ev['uid'] = $importer['uid'];
$ev['uri'] = $item_id;
$ev['edited'] = $datarray['edited'];
$ev['private'] = $datarray['private'];
$ev['guid'] = $datarray['guid'];
$r = q("SELECT * FROM `event` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($item_id), intval($importer['uid']));
if (count($r)) {
$ev['id'] = $r[0]['id'];
}
$xyz = event_store($ev);
continue;
}
}
$r = q("SELECT `uid`, `last-child`, `edited`, `body` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($item_id), intval($importer['importer_uid']));
// Update content if 'updated' changes
if (count($r)) {
if (edited_timestamp_is_newer($r[0], $datarray)) {
// do not accept (ignore) an earlier edit than one we currently have.
if (datetime_convert('UTC', 'UTC', $datarray['edited']) < $r[0]['edited']) {
continue;
}
$r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `tag` = '%s', `edited` = '%s', `changed` = '%s' WHERE `uri` = '%s' AND `uid` = %d", dbesc($datarray['title']), dbesc($datarray['body']), dbesc($datarray['tag']), dbesc(datetime_convert('UTC', 'UTC', $datarray['edited'])), dbesc(datetime_convert()), dbesc($item_id), intval($importer['importer_uid']));
create_tags_from_itemuri($item_id, $importer['importer_uid']);
update_thread_uri($item_id, $importer['importer_uid']);
}
// update last-child if it changes
$allow = $item->get_item_tags(NAMESPACE_DFRN, 'comment-allow');
if ($allow && $allow[0]['data'] != $r[0]['last-child']) {
$r = q("UPDATE `item` SET `last-child` = %d , `changed` = '%s' WHERE `uri` = '%s' AND `uid` = %d", intval($allow[0]['data']), dbesc(datetime_convert()), dbesc($item_id), intval($importer['importer_uid']));
}
示例3: bbcode
function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = false, $forplaintext = false)
{
$a = get_app();
// Hide all [noparse] contained bbtags by spacefying them
// POSSIBLE BUG --> Will the 'preg' functions crash if there's an embedded image?
$Text = preg_replace_callback("/\\[noparse\\](.*?)\\[\\/noparse\\]/ism", 'bb_spacefy', $Text);
$Text = preg_replace_callback("/\\[nobb\\](.*?)\\[\\/nobb\\]/ism", 'bb_spacefy', $Text);
$Text = preg_replace_callback("/\\[pre\\](.*?)\\[\\/pre\\]/ism", 'bb_spacefy', $Text);
// Move all spaces out of the tags
$Text = preg_replace("/\\[(\\w*)\\](\\s*)/ism", '$2[$1]', $Text);
$Text = preg_replace("/(\\s*)\\[\\/(\\w*)\\]/ism", '[/$2]$1', $Text);
// Extract the private images which use data urls since preg has issues with
// large data sizes. Stash them away while we do bbcode conversion, and then put them back
// in after we've done all the regex matching. We cannot use any preg functions to do this.
$extracted = bb_extract_images($Text);
$Text = $extracted['body'];
$saved_image = $extracted['images'];
// If we find any event code, turn it into an event.
// After we're finished processing the bbcode we'll
// replace all of the event code with a reformatted version.
$ev = bbtoevent($Text);
// Replace any html brackets with HTML Entities to prevent executing HTML or script
// Don't use strip_tags here because it breaks [url] search by replacing & with amp
$Text = str_replace("<", "<", $Text);
$Text = str_replace(">", ">", $Text);
// remove some newlines before the general conversion
$Text = preg_replace("/\\s?\\[share(.*?)\\]\\s?(.*?)\\s?\\[\\/share\\]\\s?/ism", "[share\$1]\$2[/share]", $Text);
$Text = preg_replace("/\\s?\\[quote(.*?)\\]\\s?(.*?)\\s?\\[\\/quote\\]\\s?/ism", "[quote\$1]\$2[/quote]", $Text);
$Text = preg_replace("/\n\\[code\\]/ism", "[code]", $Text);
$Text = preg_replace("/\\[\\/code\\]\n/ism", "[/code]", $Text);
// Rearrange shares to attachments
$Text = preg_replace_callback("((.*?)\\[class=(.*?)\\](.*?)\\[\\/class\\])ism", "bb_rearrange_share", $Text);
// when the content is meant exporting to other systems then remove the avatar picture since this doesn't really look good on these systems
if (!$tryoembed) {
$Text = preg_replace("/\\[share(.*?)avatar\\s?=\\s?'.*?'\\s?(.*?)\\]\\s?(.*?)\\s?\\[\\/share\\]\\s?/ism", "\n[share\$1\$2]\$3[/share]", $Text);
}
// Convert new line chars to html <br /> tags
// nlbr seems to be hopelessly messed up
// $Text = nl2br($Text);
// We'll emulate it.
$Text = trim($Text);
$Text = str_replace("\r\n", "\n", $Text);
// removing multiplicated newlines
if (get_config("system", "remove_multiplicated_lines")) {
$search = array("\n\n\n", "\n ", " \n", "[/quote]\n\n", "\n[/quote]", "[/li]\n", "\n[li]", "\n[ul]", "[/ul]\n", "\n\n[share ", "[/attachment]\n", "\n[h1]", "[/h1]\n", "\n[h2]", "[/h2]\n", "\n[h3]", "[/h3]\n", "\n[h4]", "[/h4]\n", "\n[h5]", "[/h5]\n", "\n[h6]", "[/h6]\n");
$replace = array("\n\n", "\n", "\n", "[/quote]\n", "[/quote]", "[/li]", "[li]", "[ul]", "[/ul]", "\n[share ", "[/attachment]", "[h1]", "[/h1]", "[h2]", "[/h2]", "[h3]", "[/h3]", "[h4]", "[/h4]", "[h5]", "[/h5]", "[h6]", "[/h6]");
do {
$oldtext = $Text;
$Text = str_replace($search, $replace, $Text);
} while ($oldtext != $Text);
}
// Handle attached links or videos
$Text = bb_attachment($Text, $simplehtml, $tryoembed);
$Text = str_replace(array("\r", "\n"), array('<br />', '<br />'), $Text);
if ($preserve_nl) {
$Text = str_replace(array("\n", "\r"), array('', ''), $Text);
}
// Set up the parameters for a URL search string
$URLSearchString = "^\\[\\]";
// Set up the parameters for a MAIL search string
$MAILSearchString = $URLSearchString;
// Remove all hashtag addresses
if ((!$tryoembed or $simplehtml) and !in_array($simplehtml, array(3, 7))) {
$Text = preg_replace("/([#@])\\[url\\=([{$URLSearchString}]*)\\](.*?)\\[\\/url\\]/ism", '$1$3', $Text);
} elseif ($simplehtml == 3) {
$Text = preg_replace("/([@])\\[url\\=([{$URLSearchString}]*)\\](.*?)\\[\\/url\\]/ism", '$1<a href="$2">$3</a>', $Text);
} elseif ($simplehtml == 7) {
$Text = preg_replace("/([@])\\[url\\=([{$URLSearchString}]*)\\](.*?)\\[\\/url\\]/ism", '$1<span class="vcard"><a href="$2" class="url" title="$3"><span class="fn nickname mention">$3</span></a></span>', $Text);
}
// Bookmarks in red - will be converted to bookmarks in friendica
$Text = preg_replace("/#\\^\\[url\\]([{$URLSearchString}]*)\\[\\/url\\]/ism", '[bookmark=$1]$1[/bookmark]', $Text);
$Text = preg_replace("/#\\^\\[url\\=([{$URLSearchString}]*)\\](.*?)\\[\\/url\\]/ism", '[bookmark=$1]$2[/bookmark]', $Text);
$Text = preg_replace("/#\\[url\\=[{$URLSearchString}]*\\]\\^\\[\\/url\\]\\[url\\=([{$URLSearchString}]*)\\](.*?)\\[\\/url\\]/i", "[bookmark=\$1]\$2[/bookmark]", $Text);
if (in_array($simplehtml, array(2, 6, 7, 8, 9))) {
$Text = preg_replace_callback("/([^#@])\\[url\\=([^\\]]*)\\](.*?)\\[\\/url\\]/ism", "bb_expand_links", $Text);
//$Text = preg_replace("/[^#@]\[url\=([^\]]*)\](.*?)\[\/url\]/ism",' $2 [url]$1[/url]',$Text);
$Text = preg_replace("/\\[bookmark\\=([^\\]]*)\\](.*?)\\[\\/bookmark\\]/ism", ' $2 [url]$1[/url]', $Text);
}
if ($simplehtml == 5) {
$Text = preg_replace("/[^#@]\\[url\\=([{$URLSearchString}]*)\\](.*?)\\[\\/url\\]/ism", '[url]$1[/url]', $Text);
}
// Perform URL Search
if ($tryoembed) {
$Text = preg_replace_callback("/\\[bookmark\\=([^\\]]*)\\](.*?)\\[\\/bookmark\\]/ism", 'tryoembed', $Text);
}
if ($simplehtml == 5) {
$Text = preg_replace("/\\[bookmark\\=([^\\]]*)\\](.*?)\\[\\/bookmark\\]/ism", '[url]$1[/url]', $Text);
} else {
$Text = preg_replace("/\\[bookmark\\=([^\\]]*)\\](.*?)\\[\\/bookmark\\]/ism", '[url=$1]$2[/url]', $Text);
}
// Handle Diaspora posts
$Text = preg_replace_callback("&\\[url=/posts/([^\\[\\]]*)\\](.*)\\[\\/url\\]&Usi", 'bb_DiasporaLinks', $Text);
// if the HTML is used to generate plain text, then don't do this search, but replace all URL of that kind to text
// if ($simplehtml != 7) {
if (!$forplaintext) {
$Text = preg_replace("/([^\\]\\='" . '"' . "]|^)(https?\\:\\/\\/[a-zA-Z0-9\\:\\/\\-\\?\\&\\;\\.\\=\\_\\~\\#\\%\$\\!\\+\\,]+)/ism", '$1<a href="$2" target="_blank">$2</a>', $Text);
} else {
$Text = preg_replace("(\\[url\\]([{$URLSearchString}]*)\\[\\/url\\])ism", " \$1 ", $Text);
$Text = preg_replace_callback("&\\[url=([^\\[\\]]*)\\]\\[img\\](.*)\\[\\/img\\]\\[\\/url\\]&Usi", 'bb_RemovePictureLinks', $Text);
}
//.........这里部分代码省略.........
示例4: bbtovcal
function bbtovcal($s)
{
$o = '';
$ev = bbtoevent($s);
if ($ev['desc']) {
$o = format_event_html($ev);
}
return $o;
}
示例5: bbcode
function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false)
{
// Hide all [noparse] contained bbtags by spacefying them
if (strpos($Text, '[noparse]') !== false) {
$Text = preg_replace_callback("/\\[noparse\\](.*?)\\[\\/noparse\\]/ism", 'bb_spacefy', $Text);
}
if (strpos($Text, '[nobb]') !== false) {
$Text = preg_replace_callback("/\\[nobb\\](.*?)\\[\\/nobb\\]/ism", 'bb_spacefy', $Text);
}
if (strpos($Text, '[pre]') !== false) {
$Text = preg_replace_callback("/\\[pre\\](.*?)\\[\\/pre\\]/ism", 'bb_spacefy', $Text);
}
// If we find any event code, turn it into an event.
// After we're finished processing the bbcode we'll
// replace all of the event code with a reformatted version.
$ev = bbtoevent($Text);
// process [observer] tags before we do anything else because we might
// be stripping away stuff that then doesn't need to be worked on anymore
if ($cache) {
$observer = false;
} else {
$observer = App::get_observer();
}
if (strpos($Text, '[/observer]') !== false || strpos($Text, '[/rpost]') !== false) {
if ($observer) {
$Text = preg_replace("/\\[observer\\=1\\](.*?)\\[\\/observer\\]/ism", '$1', $Text);
$Text = preg_replace("/\\[observer\\=0\\].*?\\[\\/observer\\]/ism", '', $Text);
$Text = preg_replace_callback("/\\[rpost(=(.*?))?\\](.*?)\\[\\/rpost\\]/ism", 'rpost_callback', $Text);
} else {
$Text = preg_replace("/\\[observer\\=1\\].*?\\[\\/observer\\]/ism", '', $Text);
$Text = preg_replace("/\\[observer\\=0\\](.*?)\\[\\/observer\\]/ism", '$1', $Text);
$Text = preg_replace("/\\[rpost(=.*?)?\\](.*?)\\[\\/rpost\\]/ism", '', $Text);
}
}
if ($cache) {
$channel = false;
} else {
$channel = App::get_channel();
}
if (strpos($Text, '[/channel]') !== false) {
if ($channel) {
$Text = preg_replace("/\\[channel\\=1\\](.*?)\\[\\/channel\\]/ism", '$1', $Text);
$Text = preg_replace("/\\[channel\\=0\\].*?\\[\\/channel\\]/ism", '', $Text);
} else {
$Text = preg_replace("/\\[channel\\=1\\].*?\\[\\/channel\\]/ism", '', $Text);
$Text = preg_replace("/\\[channel\\=0\\](.*?)\\[\\/channel\\]/ism", '$1', $Text);
}
}
$x = bb_extract_images($Text);
$Text = $x['body'];
$saved_images = $x['images'];
$Text = str_replace(array('[baseurl]', '[sitename]'), array(z_root(), get_config('system', 'sitename')), $Text);
// Replace any html brackets with HTML Entities to prevent executing HTML or script
// Don't use strip_tags here because it breaks [url] search by replacing & with amp
$Text = str_replace("<", "<", $Text);
$Text = str_replace(">", ">", $Text);
// Convert new line chars to html <br /> tags
// nlbr seems to be hopelessly messed up
// $Text = nl2br($Text);
// We'll emulate it.
$Text = str_replace("\r\n", "\n", $Text);
$Text = str_replace(array("\r", "\n"), array('<br />', '<br />'), $Text);
if ($preserve_nl) {
$Text = str_replace(array("\n", "\r"), array('', ''), $Text);
}
$Text = str_replace(array("\t", " "), array(" ", " "), $Text);
// Set up the parameters for a URL search string
$URLSearchString = "^\\[\\]";
// Set up the parameters for a MAIL search string
$MAILSearchString = $URLSearchString;
// replace [observer.baseurl]
if ($observer) {
$s1 = '<span class="bb_observer" title="' . t('Different viewers will see this text differently') . '">';
$s2 = '</span>';
$obsBaseURL = $observer['xchan_connurl'];
$obsBaseURL = preg_replace("/\\/poco\\/.*\$/", '', $obsBaseURL);
$Text = str_replace('[observer.baseurl]', $obsBaseURL, $Text);
$Text = str_replace('[observer.url]', $observer['xchan_url'], $Text);
$Text = str_replace('[observer.name]', $s1 . $observer['xchan_name'] . $s2, $Text);
$Text = str_replace('[observer.address]', $s1 . $observer['xchan_addr'] . $s2, $Text);
$Text = str_replace('[observer.webname]', substr($observer['xchan_addr'], 0, strpos($observer['xchan_addr'], '@')), $Text);
$Text = str_replace('[observer.photo]', $s1 . '[zmg]' . $observer['xchan_photo_l'] . '[/zmg]' . $s2, $Text);
} else {
$Text = str_replace('[observer.baseurl]', '', $Text);
$Text = str_replace('[observer.url]', '', $Text);
$Text = str_replace('[observer.name]', '', $Text);
$Text = str_replace('[observer.address]', '', $Text);
$Text = str_replace('[observer.webname]', '', $Text);
$Text = str_replace('[observer.photo]', '', $Text);
}
// Perform URL Search
$urlchars = '[a-zA-Z0-9\\:\\/\\-\\?\\&\\;\\.\\=\\@\\_\\~\\#\\%\\$\\!\\+\\,\\@]';
if (strpos($Text, 'http') !== false) {
$Text = preg_replace("/([^\\]\\='" . '"' . "\\/]|^|\\#\\^)(https?\\:\\/\\/{$urlchars}+)/ism", '$1<a href="$2" target="_blank" >$2</a>', $Text);
}
if (strpos($Text, '[/share]') !== false) {
$Text = preg_replace_callback("/\\[share(.*?)\\](.*?)\\[\\/share\\]/ism", 'bb_ShareAttributes', $Text);
}
if ($tryoembed) {
if (strpos($Text, '[/url]') !== false) {
//.........这里部分代码省略.........
示例6: local_delivery
//.........这里部分代码省略.........
$r = q("select * from item where `uri` = '%s' AND `uid` = %d limit 1", dbesc($xt->id), intval($importer['importer_uid']));
if (!count($r)) {
continue;
}
// extract tag, if not duplicate, add to parent item
if ($xo->content) {
if (!stristr($r[0]['tag'], trim($xo->content))) {
q("UPDATE item SET tag = '%s' WHERE id = %d LIMIT 1", dbesc($r[0]['tag'] . (strlen($r[0]['tag']) ? ',' : '') . '#[url=' . $xo->id . ']' . $xo->content . '[/url]'), intval($r[0]['id']));
}
}
}
}
$posted_id = item_store($datarray);
// find out if our user is involved in this conversation and wants to be notified.
if ($datarray['type'] != 'activity' && $importer['notify-flags'] & NOTIFY_COMMENT) {
$myconv = q("SELECT `author-link`, `author-avatar` FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d AND `parent` != 0 ", dbesc($parent_uri), intval($importer['importer_uid']));
if (count($myconv)) {
$importer_url = $a->get_baseurl() . '/profile/' . $importer['nickname'];
foreach ($myconv as $conv) {
if (!link_compare($conv['author-link'], $importer_url)) {
continue;
}
push_lang($importer['language']);
require_once 'bbcode.php';
$from = stripslashes($datarray['author-name']);
// name of the automated email sender
$msg['notificationfromname'] = stripslashes($datarray['author-name']);
// noreply address to send from
$msg['notificationfromemail'] = t('noreply') . '@' . $a->get_hostname();
// text version
// process the message body to display properly in text mode
$msg['textversion'] = html_entity_decode(strip_tags(bbcode(stripslashes($datarray['body']))), ENT_QUOTES, 'UTF-8');
// html version
// process the message body to display properly in text mode
$msg['htmlversion'] = html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r", "\\n\\n", "\\n"), "<br />\n", $datarray['body']))));
$imgtouse = link_compare($datarray['author-link'], $importer['url']) ? $importer['thumb'] : $datarray['author-avatar'];
// load the template for private message notifications
$tpl = get_intltext_template('cmnt_received_html_body_eml.tpl');
$email_html_body_tpl = replace_macros($tpl, array('$username' => $importer['username'], '$sitename' => $a->config['sitename'], '$siteurl' => $a->get_baseurl(), '$thumb' => $imgtouse, '$url' => $datarray['author-link'], '$from' => $from, '$body' => $msg['htmlversion'], '$display' => $a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $posted_id));
// load the template for private message notifications
$tpl = get_intltext_template('cmnt_received_text_body_eml.tpl');
$email_text_body_tpl = replace_macros($tpl, array('$username' => $importer['username'], '$sitename' => $a->config['sitename'], '$siteurl' => $a->get_baseurl(), '$thumb' => $imgtouse, '$url' => $datarray['author-link'], '$from' => $from, '$body' => $msg['textversion'], '$display' => $a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $posted_id));
// use the EmailNotification library to send the message
require_once "include/EmailNotification.php";
EmailNotification::sendTextHtmlEmail($msg['notificationfromname'], t("Administrator@") . $a->get_hostname(), t("noreply") . '@' . $a->get_hostname(), $importer['email'], sprintf(t('%s commented on an item at %s'), $from, $a->config['sitename']), $email_html_body_tpl, $email_text_body_tpl);
pop_lang();
break;
}
}
}
continue;
}
} else {
// Head post of a conversation. Have we seen it? If not, import it.
$item_id = $item->get_id();
$datarray = get_atom_elements($feed, $item);
if (x($datarray, 'object-type') && $datarray['object-type'] === ACTIVITY_OBJ_EVENT) {
$ev = bbtoevent($datarray['body']);
if (x($ev, 'desc') && x($ev, 'start')) {
$ev['cid'] = $importer['id'];
$ev['uid'] = $importer['uid'];
$ev['uri'] = $item_id;
$ev['edited'] = $datarray['edited'];
$ev['private'] = $datarray['private'];
$r = q("SELECT * FROM `event` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($item_id), intval($importer['uid']));
if (count($r)) {
$ev['id'] = $r[0]['id'];
}
$xyz = event_store($ev);
continue;
}
}
$r = q("SELECT `uid`, `last-child`, `edited`, `body` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($item_id), intval($importer['importer_uid']));
// Update content if 'updated' changes
if (count($r)) {
if (x($datarray, 'edited') !== false && datetime_convert('UTC', 'UTC', $datarray['edited']) !== $r[0]['edited']) {
$r = q("UPDATE `item` SET `body` = '%s', `edited` = '%s' WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($datarray['body']), dbesc(datetime_convert('UTC', 'UTC', $datarray['edited'])), dbesc($item_id), intval($importer['importer_uid']));
}
// update last-child if it changes
$allow = $item->get_item_tags(NAMESPACE_DFRN, 'comment-allow');
if ($allow && $allow[0]['data'] != $r[0]['last-child']) {
$r = q("UPDATE `item` SET `last-child` = %d , `changed` = '%s' WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", intval($allow[0]['data']), dbesc(datetime_convert()), dbesc($item_id), intval($importer['importer_uid']));
}
continue;
}
// This is my contact on another system, but it's really me.
// Turn this into a wall post.
if ($contact['remote_self']) {
$datarray['wall'] = 1;
}
$datarray['parent-uri'] = $item_id;
$datarray['uid'] = $importer['importer_uid'];
$datarray['contact-id'] = $importer['id'];
$r = item_store($datarray);
continue;
}
}
return 0;
// NOTREACHED
}
示例7: local_delivery
//.........这里部分代码省略.........
}
}
if ($datarray['verb'] === ACTIVITY_TAG && $datarray['object-type'] === ACTIVITY_OBJ_TAGTERM) {
$xo = parse_xml_string($datarray['object'], false);
$xt = parse_xml_string($datarray['target'], false);
if ($xt->type == ACTIVITY_OBJ_NOTE) {
$r = q("select * from item where `uri` = '%s' AND `uid` = %d limit 1", dbesc($xt->id), intval($importer['importer_uid']));
if (!count($r)) {
continue;
}
// extract tag, if not duplicate, add to parent item
if ($xo->content) {
if (!stristr($r[0]['tag'], trim($xo->content))) {
q("UPDATE item SET tag = '%s' WHERE id = %d LIMIT 1", dbesc($r[0]['tag'] . (strlen($r[0]['tag']) ? ',' : '') . '#[url=' . $xo->id . ']' . $xo->content . '[/url]'), intval($r[0]['id']));
}
}
}
}
$posted_id = item_store($datarray);
// find out if our user is involved in this conversation and wants to be notified.
if (!x($datarray['type']) || $datarray['type'] != 'activity') {
$myconv = q("SELECT `author-link`, `author-avatar`, `parent` FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d AND `parent` != 0 AND `deleted` = 0", dbesc($parent_uri), intval($importer['importer_uid']));
if (count($myconv)) {
$importer_url = $a->get_baseurl() . '/profile/' . $importer['nickname'];
// first make sure this isn't our own post coming back to us from a wall-to-wall event
if (!link_compare($datarray['author-link'], $importer_url)) {
foreach ($myconv as $conv) {
// now if we find a match, it means we're in this conversation
if (!link_compare($conv['author-link'], $importer_url)) {
continue;
}
require_once 'include/enotify.php';
$conv_parent = $conv['parent'];
notification(array('type' => NOTIFY_COMMENT, 'notify_flags' => $importer['notify-flags'], 'language' => $importer['language'], 'to_name' => $importer['username'], 'to_email' => $importer['email'], 'uid' => $importer['importer_uid'], 'item' => $datarray, 'link' => $a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $posted_id, 'source_name' => stripslashes($datarray['author-name']), 'source_link' => $datarray['author-link'], 'source_photo' => link_compare($datarray['author-link'], $importer['url']) ? $importer['thumb'] : $datarray['author-avatar'], 'verb' => ACTIVITY_POST, 'otype' => 'item', 'parent' => $conv_parent));
// only send one notification
break;
}
}
}
}
continue;
}
} else {
// Head post of a conversation. Have we seen it? If not, import it.
$item_id = $item->get_id();
$datarray = get_atom_elements($feed, $item);
if (x($datarray, 'object-type') && $datarray['object-type'] === ACTIVITY_OBJ_EVENT) {
$ev = bbtoevent($datarray['body']);
if (x($ev, 'desc') && x($ev, 'start')) {
$ev['cid'] = $importer['id'];
$ev['uid'] = $importer['uid'];
$ev['uri'] = $item_id;
$ev['edited'] = $datarray['edited'];
$ev['private'] = $datarray['private'];
$r = q("SELECT * FROM `event` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($item_id), intval($importer['uid']));
if (count($r)) {
$ev['id'] = $r[0]['id'];
}
$xyz = event_store($ev);
continue;
}
}
$r = q("SELECT `uid`, `last-child`, `edited`, `body` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($item_id), intval($importer['importer_uid']));
// Update content if 'updated' changes
if (count($r)) {
if (x($datarray, 'edited') !== false && datetime_convert('UTC', 'UTC', $datarray['edited']) !== $r[0]['edited']) {
$r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `tag` = '%s', `edited` = '%s' WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($datarray['title']), dbesc($datarray['body']), dbesc($datarray['tag']), dbesc(datetime_convert('UTC', 'UTC', $datarray['edited'])), dbesc($item_id), intval($importer['importer_uid']));
}
// update last-child if it changes
$allow = $item->get_item_tags(NAMESPACE_DFRN, 'comment-allow');
if ($allow && $allow[0]['data'] != $r[0]['last-child']) {
$r = q("UPDATE `item` SET `last-child` = %d , `changed` = '%s' WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", intval($allow[0]['data']), dbesc(datetime_convert()), dbesc($item_id), intval($importer['importer_uid']));
}
continue;
}
// This is my contact on another system, but it's really me.
// Turn this into a wall post.
if ($importer['remote_self']) {
$datarray['wall'] = 1;
}
$datarray['parent-uri'] = $item_id;
$datarray['uid'] = $importer['importer_uid'];
$datarray['contact-id'] = $importer['id'];
if (!link_compare($datarray['owner-link'], $contact['url'])) {
// The item owner info is not our contact. It's OK and is to be expected if this is a tgroup delivery,
// but otherwise there's a possible data mixup on the sender's system.
// the tgroup delivery code called from item_store will correct it if it's a forum,
// but we're going to unconditionally correct it here so that the post will always be owned by our contact.
logger('local_delivery: Correcting item owner.', LOGGER_DEBUG);
$datarray['owner-name'] = $importer['senderName'];
$datarray['owner-link'] = $importer['url'];
$datarray['owner-avatar'] = $importer['thumb'];
}
$r = item_store($datarray);
continue;
}
}
return 0;
// NOTREACHED
}
示例8: bbcode
function bbcode($Text, $preserve_nl = false)
{
// Extract a single private image which uses data url's since preg has issues with
// large data sizes. Stash it away while we do bbcode conversion, and then put it back
// in after we've done all the regex matching. We cannot use any preg functions to do this.
$saved_image = '';
$img_start = strpos($Text, '[img]data:');
$img_end = strpos($Text, '[/img]');
if ($img_start !== false && $img_end !== false && $img_end > $img_start) {
$start_fragment = substr($Text, 0, $img_start);
$img_start += strlen('[img]');
$saved_image = substr($Text, $img_start, $img_end - $img_start);
$end_fragment = substr($Text, $img_end + strlen('[/img]'));
// logger('saved_image: ' . $saved_image,LOGGER_DEBUG);
$Text = $start_fragment . '[$#saved_image#$]' . $end_fragment;
}
// If we find any event code, turn it into an event.
// After we're finished processing the bbcode we'll
// replace all of the event code with a reformatted version.
$ev = bbtoevent($Text);
// Replace any html brackets with HTML Entities to prevent executing HTML or script
// Don't use strip_tags here because it breaks [url] search by replacing & with amp
$Text = str_replace("<", "<", $Text);
$Text = str_replace(">", ">", $Text);
// Convert new line chars to html <br /> tags
$Text = nl2br($Text);
if ($preserve_nl) {
$Text = str_replace(array("\n", "\r"), array('', ''), $Text);
}
// Set up the parameters for a URL search string
$URLSearchString = "^\\[\\]";
// Set up the parameters for a MAIL search string
$MAILSearchString = $URLSearchString;
// Perform URL Search
$Text = preg_replace("/([^\\]\\=]|^)(https?\\:\\/\\/[a-zA-Z0-9\\:\\/\\-\\?\\&\\;\\.\\=\\_\\~\\#\\%\$\\!\\+\\,]+)/ism", '$1<a href="$2" target="external-link">$2</a>', $Text);
$Text = preg_replace_callback("/\\[bookmark\\=([^\\]]*)\\].*?\\[\\/bookmark\\]/ism", 'tryoembed', $Text);
$Text = preg_replace("/\\[bookmark\\=([^\\]]*)\\](.*?)\\[\\/bookmark\\]/ism", '[url=$1]$2[/url]', $Text);
$Text = preg_replace_callback("/\\[url\\]([{$URLSearchString}]*)\\[\\/url\\]/ism", 'tryoembed', $Text);
$Text = preg_replace("/\\[url\\]([{$URLSearchString}]*)\\[\\/url\\]/ism", '<a href="$1" target="external-link">$1</a>', $Text);
$Text = preg_replace("/\\[url\\=([{$URLSearchString}]*)\\](.*?)\\[\\/url\\]/ism", '<a href="$1" target="external-link">$2</a>', $Text);
//$Text = preg_replace("/\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[\/url\]/ism", '<a href="$1" target="_blank">$2</a>', $Text);
// Perform MAIL Search
$Text = preg_replace("/\\[mail\\]([{$MAILSearchString}]*)\\[\\/mail\\]/", '<a href="mailto:$1">$1</a>', $Text);
$Text = preg_replace("/\\[mail\\=([{$MAILSearchString}]*)\\](.*?)\\[\\/mail\\]/", '<a href="mailto:$1">$2</a>', $Text);
// Check for bold text
$Text = preg_replace("(\\[b\\](.*?)\\[\\/b\\])ism", '<strong>$1</strong>', $Text);
// Check for Italics text
$Text = preg_replace("(\\[i\\](.*?)\\[\\/i\\])ism", '<em>$1</em>', $Text);
// Check for Underline text
$Text = preg_replace("(\\[u\\](.*?)\\[\\/u\\])ism", '<u>$1</u>', $Text);
// Check for strike-through text
$Text = preg_replace("(\\[s\\](.*?)\\[\\/s\\])ism", '<strike>$1</strike>', $Text);
// Check for over-line text
$Text = preg_replace("(\\[o\\](.*?)\\[\\/o\\])ism", '<span class="overline">$1</span>', $Text);
// Check for colored text
$Text = preg_replace("(\\[color=(.*?)\\](.*?)\\[\\/color\\])ism", "<span style=\"color: \$1;\">\$2</span>", $Text);
// Check for sized text
$Text = preg_replace("(\\[size=(.*?)\\](.*?)\\[\\/size\\])ism", "<span style=\"font-size: \$1;\">\$2</span>", $Text);
// Check for list text
if (stristr($Text, '[/list]')) {
$Text = str_replace("[*]", "<li>", $Text);
}
if (stristr($Text, '[/list]')) {
$Text = str_replace("[*]", "<li>", $Text);
}
$Text = preg_replace("/\\[list\\](.*?)\\[\\/list\\]/ism", '<ul class="listbullet" style="list-style-type: circle;">$1</ul>', $Text);
$Text = preg_replace("/\\[list=\\](.*?)\\[\\/list\\]/ism", '<ul class="listnone" style="list-style-type: none;">$1</ul>', $Text);
$Text = preg_replace("/\\[list=1\\](.*?)\\[\\/list\\]/ism", '<ul class="listdecimal" style="list-style-type: decimal;">$1</ul>', $Text);
$Text = preg_replace("/\\[list=i\\](.*?)\\[\\/list\\]/sm", '<ul class="listlowerroman" style="list-style-type: lower-roman;">$1</ul>', $Text);
$Text = preg_replace("/\\[list=I\\](.*?)\\[\\/list\\]/sm", '<ul class="listupperroman" style="list-style-type: upper-roman;">$1</ul>', $Text);
$Text = preg_replace("/\\[list=a\\](.*?)\\[\\/list\\]/sm", '<ul class="listloweralpha" style="list-style-type: lower-alpha;">$1</ul>', $Text);
$Text = preg_replace("/\\[list=A\\](.*?)\\[\\/list\\]/sm", '<ul class="listupperalpha" style="list-style-type: upper-alpha;">$1</ul>', $Text);
$Text = preg_replace("/\\[li\\](.*?)\\[\\/li\\]/sm", '<li>$1</li>', $Text);
$Text = preg_replace("/\\[td\\](.*?)\\[\\/td\\]/sm", '<td>$1</td>', $Text);
$Text = preg_replace("/\\[tr\\](.*?)\\[\\/tr\\]/sm", '<tr>$1</tr>', $Text);
$Text = preg_replace("/\\[table\\](.*?)\\[\\/table\\]/sm", '<table>$1</table>', $Text);
$Text = preg_replace("/\\[table border=1\\](.*?)\\[\\/table\\]/sm", '<table border="1" >$1</table>', $Text);
$Text = preg_replace("/\\[table border=0\\](.*?)\\[\\/table\\]/sm", '<table border="0" >$1</table>', $Text);
// Check for font change text
$Text = preg_replace("/\\[font=(.*?)\\](.*?)\\[\\/font\\]/sm", "<span style=\"font-family: \$1;\">\$2</span>", $Text);
// Declare the format for [code] layout
$Text = preg_replace_callback("/\\[code\\](.*?)\\[\\/code\\]/ism", 'stripcode_br_cb', $Text);
$CodeLayout = '<code>$1</code>';
// Check for [code] text
$Text = preg_replace("/\\[code\\](.*?)\\[\\/code\\]/ism", "{$CodeLayout}", $Text);
// Declare the format for [quote] layout
$QuoteLayout = '<blockquote>$1</blockquote>';
// Check for [quote] text
$Text = preg_replace("/\\[quote\\](.*?)\\[\\/quote\\]/ism", "{$QuoteLayout}", $Text);
// [img=widthxheight]image source[/img]
$Text = preg_replace("/\\[img\\=([0-9]*)x([0-9]*)\\](.*?)\\[\\/img\\]/ism", '<img src="$3" style="height: $2px; width: $1px;" >', $Text);
// Images
// [img]pathtoimage[/img]
$Text = preg_replace("/\\[img\\](.*?)\\[\\/img\\]/ism", '<img src="$1" alt="' . t('Image/photo') . '" />', $Text);
// Try to Oembed
$Text = preg_replace_callback("/\\[video\\](.*?)\\[\\/video\\]/ism", 'tryoembed', $Text);
$Text = preg_replace_callback("/\\[audio\\](.*?)\\[\\/audio\\]/ism", 'tryoembed', $Text);
// html5 video and audio
$Text = preg_replace("/\\[video\\](.*?)\\[\\/video\\]/ism", '<video src="$1" controls="controls" width="425" height="350"><a href="$1">$1</a></video>', $Text);
$Text = preg_replace("/\\[audio\\](.*?)\\[\\/audio\\]/ism", '<audio src="$1" controls="controls"><a href="$1">$1</a></audio>', $Text);
//.........这里部分代码省略.........
示例9: bb2diaspora
function bb2diaspora($Text, $preserve_nl = false)
{
$ev = bbtoevent($Text);
// Replace any html brackets with HTML Entities to prevent executing HTML or script
// Don't use strip_tags here because it breaks [url] search by replacing & with amp
$Text = str_replace("<", "<", $Text);
$Text = str_replace(">", ">", $Text);
// If we find any event code, turn it into an event.
// After we're finished processing the bbcode we'll
// replace all of the event code with a reformatted version.
if ($preserve_nl) {
$Text = str_replace(array("\n", "\r"), array('', ''), $Text);
}
// Set up the parameters for a URL search string
$URLSearchString = "^\\[\\]";
// Set up the parameters for a MAIL search string
$MAILSearchString = $URLSearchString;
// Perform URL Search
// [img]pathtoimage[/img]
$Text = preg_replace("/\\[bookmark\\]([{$URLSearchString}]*)\\[\\/bookmark\\]/ism", '[$1]($1)', $Text);
$Text = preg_replace("/\\[bookmark\\=([{$URLSearchString}]*)\\](.*?)\\[\\/bookmark\\]/ism", '[$2]($1)', $Text);
$Text = preg_replace("/\\[url\\]([{$URLSearchString}]*)\\[\\/url\\]/ism", '[$1]($1)', $Text);
$Text = preg_replace("/\\#\\[url\\=([{$URLSearchString}]*)\\](.*?)\\[\\/url\\]/ism", '[#$2]($1)', $Text);
$Text = preg_replace("/\\[url\\=([{$URLSearchString}]*)\\](.*?)\\[\\/url\\]/ism", '[$2]($1)', $Text);
$Text = preg_replace("/\\[img\\](.*?)\\[\\/img\\]/", '![' . t('image/photo') . '](' . '$1' . ')', $Text);
// Perform MAIL Search
$Text = preg_replace("(\\[mail\\]([{$MAILSearchString}]*)\\[/mail\\])", '[$1](mailto:$1)', $Text);
$Text = preg_replace("/\\[mail\\=([{$MAILSearchString}]*)\\](.*?)\\[\\/mail\\]/", '[$2](mailto:$1)', $Text);
$Text = str_replace('*', '\\*', $Text);
$Text = str_replace('_', '\\_', $Text);
$Text = str_replace('`', '\\`', $Text);
// Check for bold text
$Text = preg_replace("(\\[b\\](.*?)\\[\\/b\\])is", '**$1**', $Text);
// Check for Italics text
$Text = preg_replace("(\\[i\\](.*?)\\[\\/i\\])is", '_$1_', $Text);
// Check for Underline text
// $Text = preg_replace("(\[u\](.*?)\[\/u\])is",'<u>$1</u>',$Text);
// Check for strike-through text
// $Text = preg_replace("(\[s\](.*?)\[\/s\])is",'<strike>$1</strike>',$Text);
// Check for over-line text
// $Text = preg_replace("(\[o\](.*?)\[\/o\])is",'<span class="overline">$1</span>',$Text);
// Check for colored text
// $Text = preg_replace("(\[color=(.*?)\](.*?)\[\/color\])is","<span style=\"color: $1;\">$2</span>",$Text);
// Check for sized text
// $Text = preg_replace("(\[size=(.*?)\](.*?)\[\/size\])is","<span style=\"font-size: $1;\">$2</span>",$Text);
// Check for list text
// $Text = preg_replace("/\[list\](.*?)\[\/list\]/is", '<ul class="listbullet">$1</ul>' ,$Text);
// $Text = preg_replace("/\[list=1\](.*?)\[\/list\]/is", '<ul class="listdecimal">$1</ul>' ,$Text);
// $Text = preg_replace("/\[list=i\](.*?)\[\/list\]/s",'<ul class="listlowerroman">$1</ul>' ,$Text);
// $Text = preg_replace("/\[list=I\](.*?)\[\/list\]/s", '<ul class="listupperroman">$1</ul>' ,$Text);
// $Text = preg_replace("/\[list=a\](.*?)\[\/list\]/s", '<ul class="listloweralpha">$1</ul>' ,$Text);
// $Text = preg_replace("/\[list=A\](.*?)\[\/list\]/s", '<ul class="listupperalpha">$1</ul>' ,$Text);
// $Text = preg_replace("/\[li\](.*?)\[\/li\]/s", '<li>$1</li>' ,$Text);
// $Text = preg_replace("/\[td\](.*?)\[\/td\]/s", '<td>$1</td>' ,$Text);
// $Text = preg_replace("/\[tr\](.*?)\[\/tr\]/s", '<tr>$1</tr>' ,$Text);
// $Text = preg_replace("/\[table\](.*?)\[\/table\]/s", '<table>$1</table>' ,$Text);
// $Text = preg_replace("/\[table border=1\](.*?)\[\/table\]/s", '<table border="1" >$1</table>' ,$Text);
// $Text = preg_replace("/\[table border=0\](.*?)\[\/table\]/s", '<table border="0" >$1</table>' ,$Text);
// $Text = str_replace("[*]", "<li>", $Text);
// Check for font change text
// $Text = preg_replace("(\[font=(.*?)\](.*?)\[\/font\])","<span style=\"font-family: $1;\">$2</span>",$Text);
$Text = preg_replace_callback("/\\[code\\](.*?)\\[\\/code\\]/is", 'stripdcode_br_cb', $Text);
// Check for [code] text
$Text = preg_replace("/(\\[code\\])+(.*?)(\\[\\/code\\])+/is", "\t\$2\n", $Text);
// Declare the format for [quote] layout
// $QuoteLayout = '<blockquote>$1</blockquote>';
// Check for [quote] text
$Text = preg_replace("/\\[quote\\](.*?)\\[\\/quote\\]/is", ">\$1\n\n", $Text);
// Images
// html5 video and audio
// $Text = preg_replace("/\[video\](.*?)\[\/video\]/", '<video src="$1" controls="controls" width="425" height="350"><a href="$1">$1</a></video>', $Text);
// $Text = preg_replace("/\[audio\](.*?)\[\/audio\]/", '<audio src="$1" controls="controls"><a href="$1">$1</a></audio>', $Text);
// $Text = preg_replace("/\[iframe\](.*?)\[\/iframe\]/", '<iframe src="$1" width="425" height="350"><a href="$1">$1</a></iframe>', $Text);
// [img=widthxheight]image source[/img]
// $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/", '<img src="$3" style="height:{$2}px; width:{$1}px;" >', $Text);
$Text = preg_replace("/\\[youtube\\]https?:\\/\\/www.youtube.com\\/watch\\?v\\=(.*?)\\[\\/youtube\\]/ism", 'http://www.youtube.com/watch?v=$1', $Text);
$Text = preg_replace("/\\[youtube\\]https?:\\/\\/www.youtube.com\\/embed\\/(.*?)\\[\\/youtube\\]/ism", 'http://www.youtube.com/watch?v=$1', $Text);
$Text = preg_replace("/\\[youtube\\]https?:\\/\\/youtu.be\\/(.*?)\\[\\/youtube\\]/ism", 'http://www.youtube.com/watch?v=$1', $Text);
$Text = preg_replace("/\\[youtube\\]([A-Za-z0-9\\-_=]+)(.*?)\\[\\/youtube\\]/ism", 'http://www.youtube.com/watch?v=$1', $Text);
$Text = preg_replace("/\\[vimeo\\]https?:\\/\\/player.vimeo.com\\/video\\/([0-9]+)(.*?)\\[\\/vimeo\\]/ism", 'http://vimeo.com/$1', $Text);
$Text = preg_replace("/\\[vimeo\\]https?:\\/\\/vimeo.com\\/([0-9]+)(.*?)\\[\\/vimeo\\]/ism", 'http://vimeo.com/$1', $Text);
$Text = preg_replace("/\\[vimeo\\]([0-9]+)(.*?)\\[\\/vimeo\\]/ism", 'http://vimeo.com/$1', $Text);
// oembed tag
// $Text = oembed_bbcode2html($Text);
// If we found an event earlier, strip out all the event code and replace with a reformatted version.
if (x($ev, 'desc') && x($ev, 'start')) {
$sub = format_event_diaspora($ev);
$Text = preg_replace("/\\[event\\-description\\](.*?)\\[\\/event\\-description\\]/is", $sub, $Text);
$Text = preg_replace("/\\[event\\-start\\](.*?)\\[\\/event\\-start\\]/is", '', $Text);
$Text = preg_replace("/\\[event\\-finish\\](.*?)\\[\\/event\\-finish\\]/is", '', $Text);
$Text = preg_replace("/\\[event\\-location\\](.*?)\\[\\/event\\-location\\]/is", '', $Text);
$Text = preg_replace("/\\[event\\-adjust\\](.*?)\\[\\/event\\-adjust\\]/is", '', $Text);
}
$Text = preg_replace("/\\<(.*?)(src|href)=(.*?)\\&\\;(.*?)\\>/ism", '<$1$2=$3&$4>', $Text);
$Text = preg_replace('/\\[(.*?)\\]\\((.*?)\\\\_(.*?)\\)/ism', '[$1]($2_$3)', $Text);
call_hooks('bb2diaspora', $Text);
return $Text;
}
示例10: bbcode
function bbcode($Text, $preserve_nl = false, $tryoembed = true)
{
$a = get_app();
// Move all spaces out of the tags
// ....Uhm why?
// This is basically doing a trim() on the stuff in between tags, but it messes up
// carefully crafted bbcode and especially other pre-formatted code.
// Commenting out until we come up with a use case where it's needed. Then let's try and
// special case rather than a heavy-handed approach like this.
// $Text = preg_replace("/\[(\w*)\](\s*)/ism", '$2[$1]', $Text);
// $Text = preg_replace("/(\s*)\[\/(\w*)\]/ism", '[/$2]$1', $Text);
// Hide all [noparse] contained bbtags by spacefying them
if (strpos($Text, '[noparse]') !== false) {
$Text = preg_replace_callback("/\\[noparse\\](.*?)\\[\\/noparse\\]/ism", 'bb_spacefy', $Text);
}
if (strpos($Text, '[nobb]') !== false) {
$Text = preg_replace_callback("/\\[nobb\\](.*?)\\[\\/nobb\\]/ism", 'bb_spacefy', $Text);
}
if (strpos($Text, '[pre]') !== false) {
$Text = preg_replace_callback("/\\[pre\\](.*?)\\[\\/pre\\]/ism", 'bb_spacefy', $Text);
}
// Not yet implemented - thinking this should display a map or perhaps be a map directive
// if (strpos($Text,'[location]') !== false) {
// $Text = preg_replace_callback("/\[location\](.*?)\[\/location\]/ism", 'bb_location',$Text);
// }
// If we find any event code, turn it into an event.
// After we're finished processing the bbcode we'll
// replace all of the event code with a reformatted version.
$ev = bbtoevent($Text);
// process [observer] tags before we do anything else because we might
// be stripping away stuff that then doesn't need to be worked on anymore
$observer = $a->get_observer();
if (strpos($Text, '[/observer]') !== false || strpos($Text, '[/rpost]') !== false) {
if ($observer) {
$Text = preg_replace("/\\[observer\\=1\\](.*?)\\[\\/observer\\]/ism", '$1', $Text);
$Text = preg_replace("/\\[observer\\=0\\].*?\\[\\/observer\\]/ism", '', $Text);
$Text = preg_replace_callback("/\\[rpost(=(.*?))?\\](.*?)\\[\\/rpost\\]/ism", 'rpost_callback', $Text);
} else {
$Text = preg_replace("/\\[observer\\=1\\].*?\\[\\/observer\\]/ism", '', $Text);
$Text = preg_replace("/\\[observer\\=0\\](.*?)\\[\\/observer\\]/ism", '$1', $Text);
$Text = preg_replace("/\\[rpost(=.*?)?\\](.*?)\\[\\/rpost\\]/ism", '', $Text);
}
}
$channel = $a->get_channel();
if (strpos($Text, '[/channel]') !== false) {
if ($channel) {
$Text = preg_replace("/\\[channel\\=1\\](.*?)\\[\\/channel\\]/ism", '$1', $Text);
$Text = preg_replace("/\\[channel\\=0\\].*?\\[\\/channel\\]/ism", '', $Text);
} else {
$Text = preg_replace("/\\[channel\\=1\\].*?\\[\\/channel\\]/ism", '', $Text);
$Text = preg_replace("/\\[channel\\=0\\](.*?)\\[\\/channel\\]/ism", '$1', $Text);
}
}
$Text = str_replace(array('[baseurl]', '[sitename]'), array(z_root(), get_config('system', 'sitename')), $Text);
// Replace any html brackets with HTML Entities to prevent executing HTML or script
// Don't use strip_tags here because it breaks [url] search by replacing & with amp
$Text = str_replace("<", "<", $Text);
$Text = str_replace(">", ">", $Text);
// Convert new line chars to html <br /> tags
// nlbr seems to be hopelessly messed up
// $Text = nl2br($Text);
// We'll emulate it.
$Text = str_replace("\r\n", "\n", $Text);
$Text = str_replace(array("\r", "\n"), array('<br />', '<br />'), $Text);
if ($preserve_nl) {
$Text = str_replace(array("\n", "\r"), array('', ''), $Text);
}
$Text = str_replace(array("\t", " "), array(" ", " "), $Text);
// Set up the parameters for a URL search string
$URLSearchString = "^\\[\\]";
// Set up the parameters for a MAIL search string
$MAILSearchString = $URLSearchString;
// replace [observer.baseurl]
if ($observer) {
$obsBaseURL = $observer['xchan_connurl'];
$obsBaseURL = preg_replace("/\\/poco\\/.*\$/", '', $obsBaseURL);
$Text = str_replace('[observer.baseurl]', $obsBaseURL, $Text);
$Text = str_replace('[observer.url]', $observer['xchan_url'], $Text);
$Text = str_replace('[observer.name]', $observer['xchan_name'], $Text);
$Text = str_replace('[observer.address]', $observer['xchan_addr'], $Text);
$Text = str_replace('[observer.webname]', substr($observer['xchan_addr'], 0, strpos($observer['xchan_addr'], '@')), $Text);
$Text = str_replace('[observer.photo]', '[zmg]' . $observer['xchan_photo_l'] . '[/zmg]', $Text);
} else {
$Text = str_replace('[observer.baseurl]', '', $Text);
$Text = str_replace('[observer.url]', '', $Text);
$Text = str_replace('[observer.name]', '', $Text);
$Text = str_replace('[observer.address]', '', $Text);
$Text = str_replace('[observer.webname]', '', $Text);
$Text = str_replace('[observer.photo]', '', $Text);
}
// Perform URL Search
$urlchars = '[a-zA-Z0-9\\:\\/\\-\\?\\&\\;\\.\\=\\@\\_\\~\\#\\%\\$\\!\\+\\,]';
if (strpos($Text, 'http') !== false) {
$Text = preg_replace("/([^\\]\\='" . '"' . "]|^)(https?\\:\\/\\/{$urlchars}+)/ism", '$1<a href="$2" >$2</a>', $Text);
}
if (strpos($Text, '[/qr]') !== false) {
$Text = preg_replace_callback("/\\[qr\\](.*?)\\[\\/qr\\]/ism", "bb_qr", $Text);
}
if (strpos($Text, '[/share]') !== false) {
$Text = preg_replace_callback("/\\[share(.*?)\\](.*?)\\[\\/share\\]/ism", "bb_ShareAttributes", $Text);
//.........这里部分代码省略.........
示例11: bbcode
function bbcode($Text, $preserve_nl = false)
{
$a = get_app();
// Hide all [noparse] contained bbtags spacefying them
$Text = preg_replace_callback("/\\[noparse\\](.*?)\\[\\/noparse\\]/ism", 'bb_spacefy', $Text);
$Text = preg_replace_callback("/\\[nobb\\](.*?)\\[\\/nobb\\]/ism", 'bb_spacefy', $Text);
$Text = preg_replace_callback("/\\[pre\\](.*?)\\[\\/pre\\]/ism", 'bb_spacefy', $Text);
// Extract a single private image which uses data url's since preg has issues with
// large data sizes. Stash it away while we do bbcode conversion, and then put it back
// in after we've done all the regex matching. We cannot use any preg functions to do this.
$saved_image = '';
$img_start = strpos($Text, '[img]data:');
$img_end = strpos($Text, '[/img]');
if ($img_start !== false && $img_end !== false && $img_end > $img_start) {
$start_fragment = substr($Text, 0, $img_start);
$img_start += strlen('[img]');
$saved_image = substr($Text, $img_start, $img_end - $img_start);
$end_fragment = substr($Text, $img_end + strlen('[/img]'));
// logger('saved_image: ' . $saved_image,LOGGER_DEBUG);
$Text = $start_fragment . '[$#saved_image#$]' . $end_fragment;
}
// If we find any event code, turn it into an event.
// After we're finished processing the bbcode we'll
// replace all of the event code with a reformatted version.
$ev = bbtoevent($Text);
// Replace any html brackets with HTML Entities to prevent executing HTML or script
// Don't use strip_tags here because it breaks [url] search by replacing & with amp
$Text = str_replace("<", "<", $Text);
$Text = str_replace(">", ">", $Text);
// Convert new line chars to html <br /> tags
$Text = nl2br($Text);
if ($preserve_nl) {
$Text = str_replace(array("\n", "\r"), array('', ''), $Text);
}
// Set up the parameters for a URL search string
$URLSearchString = "^\\[\\]";
// Set up the parameters for a MAIL search string
$MAILSearchString = $URLSearchString;
// Perform URL Search
$Text = preg_replace("/([^\\]\\=]|^)(https?\\:\\/\\/[a-zA-Z0-9\\:\\/\\-\\?\\&\\;\\.\\=\\_\\~\\#\\%\$\\!\\+\\,]+)/ism", '$1<a href="$2" target="external-link">$2</a>', $Text);
$Text = preg_replace_callback("/\\[bookmark\\=([^\\]]*)\\].*?\\[\\/bookmark\\]/ism", 'tryoembed', $Text);
$Text = preg_replace("/\\[bookmark\\=([^\\]]*)\\](.*?)\\[\\/bookmark\\]/ism", '[url=$1]$2[/url]', $Text);
$Text = preg_replace_callback("/\\[url\\]([{$URLSearchString}]*)\\[\\/url\\]/ism", 'tryoembed', $Text);
$Text = preg_replace("/\\[url\\]([{$URLSearchString}]*)\\[\\/url\\]/ism", '<a href="$1" target="external-link">$1</a>', $Text);
$Text = preg_replace("/\\[url\\=([{$URLSearchString}]*)\\](.*?)\\[\\/url\\]/ism", '<a href="$1" target="external-link">$2</a>', $Text);
//$Text = preg_replace("/\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[\/url\]/ism", '<a href="$1" target="_blank">$2</a>', $Text);
// we may need to restrict this further if it picks up too many strays
// link acct:user@host to a webfinger profile redirector
$Text = preg_replace('/acct:(.*?)@(.*?)([ ,])/', '<a href="' . $a->get_baseurl() . '/acctlink?addr=' . "\$1@\$2" . '" target="extlink" >acct:' . "\$1@\$2\$3" . '</a>', $Text);
// Perform MAIL Search
$Text = preg_replace("/\\[mail\\]([{$MAILSearchString}]*)\\[\\/mail\\]/", '<a href="mailto:$1">$1</a>', $Text);
$Text = preg_replace("/\\[mail\\=([{$MAILSearchString}]*)\\](.*?)\\[\\/mail\\]/", '<a href="mailto:$1">$2</a>', $Text);
// Check for bold text
$Text = preg_replace("(\\[b\\](.*?)\\[\\/b\\])ism", '<strong>$1</strong>', $Text);
// Check for Italics text
$Text = preg_replace("(\\[i\\](.*?)\\[\\/i\\])ism", '<em>$1</em>', $Text);
// Check for Underline text
$Text = preg_replace("(\\[u\\](.*?)\\[\\/u\\])ism", '<u>$1</u>', $Text);
// Check for strike-through text
$Text = preg_replace("(\\[s\\](.*?)\\[\\/s\\])ism", '<strike>$1</strike>', $Text);
// Check for over-line text
$Text = preg_replace("(\\[o\\](.*?)\\[\\/o\\])ism", '<span class="overline">$1</span>', $Text);
// Check for colored text
$Text = preg_replace("(\\[color=(.*?)\\](.*?)\\[\\/color\\])ism", "<span style=\"color: \$1;\">\$2</span>", $Text);
// Check for sized text
// [size=50] --> font-size: 50px (with the unit).
$Text = preg_replace("(\\[size=(\\d*?)\\](.*?)\\[\\/size\\])ism", "<span style=\"font-size: \$1px;\">\$2</span>", $Text);
$Text = preg_replace("(\\[size=(.*?)\\](.*?)\\[\\/size\\])ism", "<span style=\"font-size: \$1;\">\$2</span>", $Text);
// Check for centered text
$Text = preg_replace("(\\[center\\](.*?)\\[\\/center\\])ism", "<div style=\"text-align:center;\">\$1</div>", $Text);
// Check for list text
$Text = str_replace("[*]", "<li>", $Text);
$Text = preg_replace("/\\[li\\](.*?)\\[\\/li\\]/ism", '<li>$1</li>', $Text);
// handle nested lists
$endlessloop = 0;
while (strpos($Text, "[/list]") !== false and strpos($Text, "[list") !== false and ++$endlessloop < 20) {
$Text = preg_replace("/\\[list\\](.*?)\\[\\/list\\]/ism", '<ul class="listbullet" style="list-style-type: circle;">$1</ul>', $Text);
$Text = preg_replace("/\\[list=\\](.*?)\\[\\/list\\]/ism", '<ul class="listnone" style="list-style-type: none;">$1</ul>', $Text);
$Text = preg_replace("/\\[list=1\\](.*?)\\[\\/list\\]/ism", '<ul class="listdecimal" style="list-style-type: decimal;">$1</ul>', $Text);
$Text = preg_replace("/\\[list=((?-i)i)\\](.*?)\\[\\/list\\]/ism", '<ul class="listlowerroman" style="list-style-type: lower-roman;">$2</ul>', $Text);
$Text = preg_replace("/\\[list=((?-i)I)\\](.*?)\\[\\/list\\]/ism", '<ul class="listupperroman" style="list-style-type: upper-roman;">$2</ul>', $Text);
$Text = preg_replace("/\\[list=((?-i)a)\\](.*?)\\[\\/list\\]/ism", '<ul class="listloweralpha" style="list-style-type: lower-alpha;">$2</ul>', $Text);
$Text = preg_replace("/\\[list=((?-i)A)\\](.*?)\\[\\/list\\]/ism", '<ul class="listupperalpha" style="list-style-type: upper-alpha;">$2</ul>', $Text);
}
$Text = preg_replace("/\\[ul\\](.*?)\\[\\/ul\\]/ism", '<ul class="listbullet" style="list-style-type: circle;">$1</ul>', $Text);
$Text = preg_replace("/\\[ol\\](.*?)\\[\\/ol\\]/ism", '<ul class="listdecimal" style="list-style-type: decimal;">$1</ul>', $Text);
$Text = preg_replace("/\\[th\\](.*?)\\[\\/th\\]/sm", '<th>$1</th>', $Text);
$Text = preg_replace("/\\[td\\](.*?)\\[\\/td\\]/sm", '<td>$1</td>', $Text);
$Text = preg_replace("/\\[tr\\](.*?)\\[\\/tr\\]/sm", '<tr>$1</tr>', $Text);
$Text = preg_replace("/\\[table\\](.*?)\\[\\/table\\]/sm", '<table>$1</table>', $Text);
$Text = preg_replace("/\\[table border=1\\](.*?)\\[\\/table\\]/sm", '<table border="1" >$1</table>', $Text);
$Text = preg_replace("/\\[table border=0\\](.*?)\\[\\/table\\]/sm", '<table border="0" >$1</table>', $Text);
$Text = str_replace('[hr]', '<hr />', $Text);
// This is actually executed in prepare_body()
$Text = str_replace('[nosmile]', '', $Text);
// Check for font change text
$Text = preg_replace("/\\[font=(.*?)\\](.*?)\\[\\/font\\]/sm", "<span style=\"font-family: \$1;\">\$2</span>", $Text);
// Declare the format for [code] layout
$Text = preg_replace_callback("/\\[code\\](.*?)\\[\\/code\\]/ism", 'stripcode_br_cb', $Text);
$CodeLayout = '<code>$1</code>';
//.........这里部分代码省略.........
示例12: event_addtocal
function event_addtocal($item_id, $uid)
{
$c = q("select * from channel where channel_id = %d limit 1", intval($uid));
if (!$c) {
return false;
}
$channel = $c[0];
$r = q("select * from item where id = %d and uid = %d limit 1", intval($item_id), intval($channel['channel_id']));
if (!$r || $r[0]['obj_type'] !== ACTIVITY_OBJ_EVENT) {
return false;
}
$item = $r[0];
$ev = bbtoevent($r[0]['body']);
if (x($ev, 'summary') && x($ev, 'start')) {
$ev['event_xchan'] = $item['author_xchan'];
$ev['uid'] = $channel['channel_id'];
$ev['account'] = $channel['channel_account_id'];
$ev['edited'] = $item['edited'];
$ev['mid'] = $item['mid'];
$ev['private'] = $item['item_private'];
// is this an edit?
if ($item['resource_type'] === 'event') {
$ev['event_hash'] = $item['resource_id'];
}
$event = event_store_event($ev);
if ($event) {
$r = q("update item set resource_id = '%s', resource_type = 'event' where id = %d and uid = %d limit 1", dbesc($event['event_hash']), intval($item['id']), intval($channel['channel_id']));
return true;
}
}
return false;
}