From f68bbffb640e7e2100bf089f1d0a29d174609af5 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 9 Jul 2014 20:44:12 +0200 Subject: [PATCH 01/10] Adding preview value to "prepare_body" hook. (Will be used in addons for network related previews) --- include/conversation.php | 5 +++-- include/text.php | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/conversation.php b/include/conversation.php index ddb01ec9b..95792640e 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -620,7 +620,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { $likebuttons = false; $shareable = false; - $body = prepare_body($item,true); + $body = prepare_body($item,true, $preview); list($categories, $folders) = get_cats_and_terms($item); @@ -685,7 +685,8 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { 'like' => '', 'dislike' => '', 'comment' => '', - 'conv' => (($preview) ? '' : array('href'=> $a->get_baseurl($ssl_state) . '/display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))), + //'conv' => (($preview) ? '' : array('href'=> $a->get_baseurl($ssl_state) . '/display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))), + 'conv' => (($preview) ? '' : array('href'=> $a->get_baseurl($ssl_state) . '/display/'.$item['guid'], 'title'=> t('View in context'))), 'previewing' => $previewing, 'wait' => t('Please wait'), 'thread_level' => 1, diff --git a/include/text.php b/include/text.php index 2490bf402..4d6aa8697 100644 --- a/include/text.php +++ b/include/text.php @@ -1293,7 +1293,7 @@ if(! function_exists('prepare_body')) { * @hook prepare_body ('item'=>item array, 'html'=>body string) after first bbcode to html * @hook prepare_body_final ('item'=>item array, 'html'=>body string) after attach icons and blockquote special case handling (spoiler, author) */ -function prepare_body(&$item,$attach = false) { +function prepare_body(&$item,$attach = false, $preview = false) { $a = get_app(); call_hooks('prepare_body_init', $item); @@ -1353,7 +1353,7 @@ function prepare_body(&$item,$attach = false) { } - $prep_arr = array('item' => $item, 'html' => $s); + $prep_arr = array('item' => $item, 'html' => $s, 'preview' => $preview); call_hooks('prepare_body', $prep_arr); $s = $prep_arr['html']; From 660bd39efad52b1c69bd8dd0ca27141b81f84ca5 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 9 Jul 2014 20:48:34 +0200 Subject: [PATCH 02/10] Let an item be accssible via the GUI (additionally to uid and item id) --- include/items.php | 13 +++++++++++ mod/display.php | 55 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/include/items.php b/include/items.php index 6bec078bc..d71c0e203 100644 --- a/include/items.php +++ b/include/items.php @@ -1011,6 +1011,19 @@ function item_store($arr,$force_parent = false) { } } + // If there is no guid then take the same guid that was taken before for the same uri + if ((trim($arr['guid']) == "") AND (trim($arr['uri']) != "")) { + logger('item_store: checking for an existing guid for uri '.$arr['uri'], LOGGER_DEBUG); + $r = q("SELECT `guid` FROM `item` WHERE `uri` = '%s' AND `guid` != '' LIMIT 1", + dbesc(trim($arr['uri'])) + ); + + if(count($r)) { + $arr['guid'] = $r[0]["guid"]; + logger('item_store: found guid '.$arr['guid'].' for uri '.$arr['uri'], LOGGER_DEBUG); + } + } + // Shouldn't happen but we want to make absolutely sure it doesn't leak from a plugin. // Deactivated, since the bbcode parser can handle with it - and it destroys posts with some smileys that contain "<" //if((strpos($arr['body'],'<') !== false) || (strpos($arr['body'],'>') !== false)) diff --git a/mod/display.php b/mod/display.php index 5c6277e34..e0a7912a2 100644 --- a/mod/display.php +++ b/mod/display.php @@ -1,6 +1,5 @@ argc > 1) ? $a->argv[1] : ''); + + // If there is only one parameter, then check if this parameter could be a guid + if ($a->argc == 2) { + $nick = ""; + + // Does the local user have this item? + if (local_user()) { + $r = q("SELECT `id` FROM `item` + WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0 + AND `guid` = '%s' AND `uid` = %d", $a->argv[1], local_user()); + if (count($r)) + $nick = $a->user["nickname"]; + } + + // Or is it anywhere on the server? + if ($nick == "") { + $r = q("SELECT `user`.`nickname` FROM `item` INNER JOIN `user` ON `user`.`uid` = `item`.`uid` + WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0 + AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' + AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' + AND `item`.`private` = 0 AND `item`.`wall` = 1 + AND `item`.`guid` = '%s'", $a->argv[1]); + if (count($r)) + $nick = $r[0]["nickname"]; + } + } + profile_load($a,$nick); } @@ -44,6 +70,33 @@ function display_content(&$a, $update = 0) { } else { $item_id = (($a->argc > 2) ? $a->argv[2] : 0); + + if ($a->argc == 2) { + $nick = ""; + + if (local_user()) { + $r = q("SELECT `id` FROM `item` + WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0 + AND `guid` = '%s' AND `uid` = %d", $a->argv[1], local_user()); + if (count($r)) { + $item_id = $r[0]["id"]; + $nick = $a->user["nickname"]; + } + } + + if ($nick == "") { + $r = q("SELECT `user`.`nickname`, `item`.`id` FROM `item` INNER JOIN `user` ON `user`.`uid` = `item`.`uid` + WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0 + AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' + AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' + AND `item`.`private` = 0 AND `item`.`wall` = 1 + AND `item`.`guid` = '%s'", $a->argv[1]); + if (count($r)) { + $item_id = $r[0]["id"]; + $nick = $r[0]["nickname"]; + } + } + } } if(! $item_id) { From fe71272e1e86b1e692b499c2daa0ef525fba26ff Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 9 Jul 2014 21:28:42 +0200 Subject: [PATCH 03/10] Plaintext: The function now returns images from video links as well. --- include/plaintext.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/plaintext.php b/include/plaintext.php index 3d30a3299..4bbca636c 100644 --- a/include/plaintext.php +++ b/include/plaintext.php @@ -95,6 +95,12 @@ function get_attached_data($body) { $post["type"] = "text"; $post["text"] = trim($body); } + } elseif (isset($post["url"]) AND ($post["type"] == "video")) { + require_once("mod/parse_url.php"); + $data = parseurl_getsiteinfo($post["url"], true); + + if (isset($data["images"][0])) + $post["image"] = $data["images"][0]["src"]; } return($post); From c980e6d20d08b6addb2938bd2e51bd599ae71d1d Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 9 Jul 2014 21:32:32 +0200 Subject: [PATCH 04/10] Possibility to disable the automatic reload of the network page --- mod/item.php | 4 ++++ mod/like.php | 8 +++++++- mod/settings.php | 6 ++++++ mod/update_network.php | 8 +++++++- view/templates/settings_display.tpl | 1 + 5 files changed, 25 insertions(+), 2 deletions(-) diff --git a/mod/item.php b/mod/item.php index 20f7f2957..cf79913eb 100644 --- a/mod/item.php +++ b/mod/item.php @@ -907,6 +907,10 @@ function item_post(&$a) { call_hooks('post_local_end', $datarray); + // if no auto update is enabled, then disable it temporarily + if (get_pconfig($profile_uid, "system", "no_auto_update") == 1) + set_pconfig($profile_uid, "system", "no_auto_update", -1); + if(strlen($emailcc) && $profile_uid == local_user()) { $erecips = explode(',', $emailcc); if(count($erecips)) { diff --git a/mod/like.php b/mod/like.php index a2f51b074..5ed58245a 100755 --- a/mod/like.php +++ b/mod/like.php @@ -136,6 +136,9 @@ function like_content(&$a) { // Save the author information for the unlike in case we need to relay to Diaspora store_diaspora_like_retract_sig($activity, $item, $like_item, $contact); + // if no auto update is enabled, then disable it temporarily + if (get_pconfig($owner_uid, "system", "no_auto_update") == 1) + set_pconfig($owner_uid, "system", "no_auto_update", -1); // proc_run('php',"include/notifier.php","like","$post_id"); // $post_id isn't defined here! $like_item_id = $like_item['id']; @@ -148,7 +151,7 @@ function like_content(&$a) { $uri = item_new_uri($a->get_hostname(),$owner_uid); $post_type = (($item['resource-id']) ? t('photo') : t('status')); - $objtype = (($item['resource-id']) ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE ); + $objtype = (($item['resource-id']) ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE ); $link = xmlify('' . "\n") ; $body = $item['body']; @@ -219,6 +222,9 @@ EOT; // Save the author information for the like in case we need to relay to Diaspora store_diaspora_like_sig($activity, $post_type, $contact, $post_id); + // if no auto update is enabled, then disable it temporarily + if (get_pconfig($owner_uid, "system", "no_auto_update") == 1) + set_pconfig($owner_uid, "system", "no_auto_update", -1); $arr['id'] = $post_id; diff --git a/mod/settings.php b/mod/settings.php index 4edd62f67..c00ecc2e3 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -268,6 +268,7 @@ function settings_post(&$a) { $nosmile = ((x($_POST,'nosmile')) ? intval($_POST['nosmile']) : 0); $noinfo = ((x($_POST,'noinfo')) ? intval($_POST['noinfo']) : 0); $infinite_scroll = ((x($_POST,'infinite_scroll')) ? intval($_POST['infinite_scroll']) : 0); + $no_auto_update = ((x($_POST,'no_auto_update')) ? intval($_POST['no_auto_update']) : 0); $browser_update = ((x($_POST,'browser_update')) ? intval($_POST['browser_update']) : 0); $browser_update = $browser_update * 1000; if($browser_update < 10000) @@ -291,6 +292,7 @@ function settings_post(&$a) { set_pconfig(local_user(),'system','no_smilies',$nosmile); set_pconfig(local_user(),'system','ignore_info',$noinfo); set_pconfig(local_user(),'system','infinite_scroll',$infinite_scroll); + set_pconfig(local_user(),'system','no_auto_update',$no_auto_update); if ($theme == $a->user['theme']){ @@ -859,6 +861,9 @@ function settings_content(&$a) { $infinite_scroll = get_pconfig(local_user(),'system','infinite_scroll'); $infinite_scroll = (($infinite_scroll===false)? '0': $infinite_scroll); // default if not set: 0 + $no_auto_update = get_pconfig(local_user(),'system','no_auto_update'); + $no_auto_update = (($no_auto_update===false)? '0': $no_auto_update); // default if not set: 0 + $theme_config = ""; if( ($themeconfigfile = get_theme_config_file($theme_selected)) != null){ require_once($themeconfigfile); @@ -881,6 +886,7 @@ function settings_content(&$a) { '$nosmile' => array('nosmile', t("Don't show emoticons"), $nosmile, ''), '$noinfo' => array('noinfo', t("Don't show notices"), $noinfo, ''), '$infinite_scroll' => array('infinite_scroll', t("Infinite scroll"), $infinite_scroll, ''), + '$no_auto_update' => array('no_auto_update', t("Disable automatic network update"), $no_auto_update, ''), '$theme_config' => $theme_config, )); diff --git a/mod/update_network.php b/mod/update_network.php index 0dfe0a73f..65366d137 100644 --- a/mod/update_network.php +++ b/mod/update_network.php @@ -13,8 +13,14 @@ function update_network_content(&$a) { echo "\r\n"; echo (($_GET['msie'] == 1) ? '
' : '
'); + $no_auto_update = get_pconfig($profile_uid, "system", "no_auto_update"); + if ($no_auto_update <= 0) { + $text = network_content($a,$profile_uid); + if ($no_auto_update < 0) + set_pconfig($profile_uid, "system", "no_auto_update", 1); + } else + $text = ""; - $text = network_content($a,$profile_uid); $pattern = "/]*) src=\"([^\"]*)\"/"; $replace = " From 6e67d39241897f1c21fa8e4f033e82a291dc4a12 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 9 Jul 2014 21:36:20 +0200 Subject: [PATCH 05/10] Relocate the site now relocates adresses in the "unique_contacts" table as well. --- mod/admin.php | 65 ++++++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/mod/admin.php b/mod/admin.php index 3b22811d1..a7e66876c 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -33,7 +33,7 @@ function admin_post(&$a){ admin_page_users_post($a); break; case 'plugins': - if ($a->argc > 2 && + if ($a->argc > 2 && is_file("addon/".$a->argv[2]."/".$a->argv[2].".php")){ @include_once("addon/".$a->argv[2]."/".$a->argv[2].".php"); if(function_exists($a->argv[2].'_plugin_admin_post')) { @@ -122,7 +122,7 @@ function admin_content(&$a) { $t = get_markup_template("admin_aside.tpl"); $a->page['aside'] .= replace_macros( $t, array( - '$admin' => $aside, + '$admin' => $aside, '$admtxt' => t('Admin'), '$plugadmtxt' => t('Plugin Features'), '$logtxt' => t('Logs'), @@ -168,13 +168,13 @@ function admin_content(&$a) { } if(is_ajax()) { - echo $o; + echo $o; killme(); return ''; } else { return $o; } -} +} /** @@ -242,35 +242,35 @@ function admin_page_site_post(&$a){ if (x($_POST,'relocate') && x($_POST,'relocate_url') && $_POST['relocate_url']!=""){ $new_url = $_POST['relocate_url']; $new_url = rtrim($new_url,"/"); - + $parsed = @parse_url($new_url); if (!$parsed || (!x($parsed,'host') || !x($parsed,'scheme'))) { notice(t("Can not parse base url. Must have at least ://")); goaway($a->get_baseurl(true) . '/admin/site' ); } - + /* steps: * replace all "baseurl" to "new_url" in config, profile, term, items and contacts * send relocate for every local user * */ - + $old_url = $a->get_baseurl(true); - + function update_table($table_name, $fields, $old_url, $new_url) { global $db, $a; - + $dbold = dbesc($old_url); $dbnew = dbesc($new_url); - + $upd = array(); foreach ($fields as $f) { $upd[] = "`$f` = REPLACE(`$f`, '$dbold', '$dbnew')"; } - + $upds = implode(", ", $upd); - - - + + + $q = sprintf("UPDATE %s SET %s;", $table_name, $upds); $r = q($q); if (!$r) { @@ -278,30 +278,31 @@ function admin_page_site_post(&$a){ goaway($a->get_baseurl(true) . '/admin/site' ); } } - + // update tables update_table("profile", array('photo', 'thumb'), $old_url, $new_url); update_table("term", array('url'), $old_url, $new_url); update_table("contact", array('photo','thumb','micro','url','nurl','request','notify','poll','confirm','poco'), $old_url, $new_url); + update_table("unique_contacts", array('url'), $old_url, $new_url); update_table("item", array('owner-link','owner-avatar','author-name','author-link','author-avatar','body','plink','tag'), $old_url, $new_url); // update config $a->set_baseurl($new_url); set_config('system','url',$new_url); - + // send relocate $users = q("SELECT uid FROM user WHERE account_removed = 0 AND account_expired = 0"); - + foreach ($users as $user) { proc_run('php', 'include/notifier.php', 'relocate', $user['uid']); } info("Relocation started. Could take a while to complete."); - + goaway($a->get_baseurl(true) . '/admin/site' ); } // end relocate - + $sitename = ((x($_POST,'sitename')) ? notags(trim($_POST['sitename'])) : ''); $banner = ((x($_POST,'banner')) ? trim($_POST['banner']) : false); $info = ((x($_POST,'info')) ? trim($_POST['info']) : false); @@ -374,14 +375,14 @@ function admin_page_site_post(&$a){ `poco` = replace(`poco` , 'http:' , 'https:') where `self` = 1" ); - q("update `profile` set + q("update `profile` set `photo` = replace(`photo` , 'http:' , 'https:'), `thumb` = replace(`thumb` , 'http:' , 'https:') where 1 " ); } elseif($ssl_policy == SSL_POLICY_SELFSIGN) { - q("update `contact` set + q("update `contact` set `url` = replace(`url` , 'https:' , 'http:'), `photo` = replace(`photo` , 'https:' , 'http:'), `thumb` = replace(`thumb` , 'https:' , 'http:'), @@ -393,7 +394,7 @@ function admin_page_site_post(&$a){ `poco` = replace(`poco` , 'https:' , 'http:') where `self` = 1" ); - q("update `profile` set + q("update `profile` set `photo` = replace(`photo` , 'https:' , 'http:'), `thumb` = replace(`thumb` , 'https:' , 'http:') where 1 " @@ -566,7 +567,7 @@ function admin_page_site(&$a) { REGISTER_CLOSED => t("Closed"), REGISTER_APPROVE => t("Requires approval"), REGISTER_OPEN => t("Open") - ); + ); $ssl_choices = array( SSL_POLICY_NONE => t("No SSL policy, links will track page SSL state"), @@ -670,7 +671,7 @@ function admin_page_dbsync(&$a) { if(function_exists($func)) { $retval = $func(); if($retval === UPDATE_FAILED) { - $o .= sprintf( t('Executing %s failed. Check system logs.'), $func); + $o .= sprintf( t('Executing %s failed. Check system logs.'), $func); } elseif($retval === UPDATE_SUCCESS) { $o .= sprintf( t('Update %s was successfully applied.', $func)); @@ -918,9 +919,9 @@ function admin_page_users(&$a){ '$delete' => t('Delete'), '$block' => t('Block'), '$unblock' => t('Unblock'), - '$siteadmin' => t('Site admin'), - '$accountexpired' => t('Account expired'), - + '$siteadmin' => t('Site admin'), + '$accountexpired' => t('Account expired'), + '$h_users' => t('Users'), '$h_newuser' => t('New User'), '$th_deleted' => array( t('Name'), t('Email'), t('Register date'), t('Last login'), t('Last item'), t('Deleted since') ), @@ -929,7 +930,7 @@ function admin_page_users(&$a){ '$confirm_delete_multi' => t('Selected users will be deleted!\n\nEverything these users had posted on this site will be permanently deleted!\n\nAre you sure?'), '$confirm_delete' => t('The user {0} will be deleted!\n\nEverything this user has posted on this site will be permanently deleted!\n\nAre you sure?'), - '$form_security_token' => get_form_security_token("admin_users"), + '$form_security_token' => get_form_security_token("admin_users"), // values // '$baseurl' => $a->get_baseurl(true), @@ -937,9 +938,9 @@ function admin_page_users(&$a){ '$pending' => $pending, 'deleted' => $deleted, '$users' => $users, - '$newusername' => array('new_user_name', t("Name"), '', t("Name of the new user.")), - '$newusernickname' => array('new_user_nickname', t("Nickname"), '', t("Nickname of the new user.")), - '$newuseremail' => array('new_user_email', t("Email"), '', t("Email address of the new user.")), + '$newusername' => array('new_user_name', t("Name"), '', t("Name of the new user.")), + '$newusernickname' => array('new_user_nickname', t("Nickname"), '', t("Nickname of the new user.")), + '$newuseremail' => array('new_user_email', t("Email"), '', t("Email address of the new user.")), )); $o .= paginate($a); return $o; @@ -1280,7 +1281,7 @@ function admin_page_themes(&$a){ * * @param App $a */ - + function admin_page_logs_post(&$a) { if (x($_POST,"page_logs")) { check_form_security_token_redirectOnErr('/admin/logs', 'admin_logs'); From c7f1f2e4f27034d31e8090e84207a3c665a9640c Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 9 Jul 2014 21:44:12 +0200 Subject: [PATCH 06/10] Diaspora: Possibility to disable the checking of the signature of likes. This is a workaround for the known problem of not receiving likes from Diaspora. --- include/diaspora.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/include/diaspora.php b/include/diaspora.php index 51e4a0bbf..6df7f4baf 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -1868,8 +1868,12 @@ function diaspora_like($importer,$xml,$msg) { $parent_author_signature = base64_decode($parent_author_signature); if(! rsa_verify($signed_data,$parent_author_signature,$key,'sha256')) { - logger('diaspora_like: top-level owner verification failed.'); - return; + if (intval(get_config('system','ignore_diaspora_like_signature'))) + logger('diaspora_like: top-level owner verification failed. Proceeding anyway.'); + else { + logger('diaspora_like: top-level owner verification failed.'); + return; + } } } else { @@ -1881,8 +1885,12 @@ function diaspora_like($importer,$xml,$msg) { $author_signature = base64_decode($author_signature); if(! rsa_verify($signed_data,$author_signature,$key,'sha256')) { - logger('diaspora_like: like creator verification failed.'); - return; + if (intval(get_config('system','ignore_diaspora_like_signature'))) + logger('diaspora_like: like creator verification failed. Proceeding anyway'); + else { + logger('diaspora_like: like creator verification failed.'); + return; + } } } From c32735cde6d888d8b309c9e4227e4ed29385d1a5 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 9 Jul 2014 23:33:38 +0200 Subject: [PATCH 07/10] bbcode: Use shorter method for shared content to networks where size matters. --- include/bbcode.php | 318 +++++++-------------------------------------- 1 file changed, 49 insertions(+), 269 deletions(-) diff --git a/include/bbcode.php b/include/bbcode.php index 63748ef45..be7535ace 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -381,245 +381,6 @@ function bb_replace_images($body, $images) { return $newbody; }} -/* -function bb_ShareAttributes($match) { - - $attributes = $match[1]; - - $author = ""; - preg_match("/author='(.*?)'/ism", $attributes, $matches); - if ($matches[1] != "") - $author = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8'); - - preg_match('/author="(.*?)"/ism', $attributes, $matches); - if ($matches[1] != "") - $author = $matches[1]; - - $link = ""; - preg_match("/link='(.*?)'/ism", $attributes, $matches); - if ($matches[1] != "") - $link = $matches[1]; - - preg_match('/link="(.*?)"/ism', $attributes, $matches); - if ($matches[1] != "") - $link = $matches[1]; - - $avatar = ""; - preg_match("/avatar='(.*?)'/ism", $attributes, $matches); - if ($matches[1] != "") - $avatar = $matches[1]; - - preg_match('/avatar="(.*?)"/ism', $attributes, $matches); - if ($matches[1] != "") - $avatar = $matches[1]; - - $profile = ""; - preg_match("/profile='(.*?)'/ism", $attributes, $matches); - if ($matches[1] != "") - $profile = $matches[1]; - - preg_match('/profile="(.*?)"/ism', $attributes, $matches); - if ($matches[1] != "") - $profile = $matches[1]; - - $posted = ""; - - $itemcache = get_itemcachepath(); - - // relative dates only make sense when they aren't cached - if ($itemcache == "") { - preg_match("/posted='(.*?)'/ism", $attributes, $matches); - if ($matches[1] != "") - $posted = $matches[1]; - - preg_match('/posted="(.*?)"/ism', $attributes, $matches); - if ($matches[1] != "") - $posted = $matches[1]; - - $reldate = (($posted) ? " " . relative_date($posted) : ''); - } - - $headline = '
'; - //$headline = '
'; - - if ($avatar != "") - $headline .= ''; - - $headline .= sprintf(t('%s wrote the following post'.$reldate.':'), $profile, $author, $link); - - $headline .= "
"; - - $text = $headline.'
'.trim($match[2])."
"; - - return($text); -} - -// Escpecially for Diaspora (there mustn't be links in the share information) -function bb_ShareAttributesDiaspora($match) { - - $attributes = $match[2]; - - $author = ""; - preg_match("/author='(.*?)'/ism", $attributes, $matches); - if ($matches[1] != "") - $author = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8'); - - preg_match('/author="(.*?)"/ism', $attributes, $matches); - if ($matches[1] != "") - $author = $matches[1]; - - $profile = ""; - preg_match("/profile='(.*?)'/ism", $attributes, $matches); - if ($matches[1] != "") - $profile = $matches[1]; - - preg_match('/profile="(.*?)"/ism', $attributes, $matches); - if ($matches[1] != "") - $profile = $matches[1]; - - $link = ""; - preg_match("/link='(.*?)'/ism", $attributes, $matches); - if ($matches[1] != "") - $link = $matches[1]; - - preg_match('/link="(.*?)"/ism', $attributes, $matches); - if ($matches[1] != "") - $link = $matches[1]; - - $userid = GetProfileUsername($profile,$author); - - $headline = '
'; - $headline .= ''.html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8').$userid.':'; - $headline .= "
"; - - $text = trim($match[1]); - - if ($text != "") - $text .= "
"; - - $text .= $headline.'
'.trim($match[3])."

"; - - if ($link != "") - $text .= '
[l]'; - - // $text .= '
'.t("Link").' [l]'; - - return($text); -} - -// Optimized for Libertree, Wordpress, Tumblr, ... -function bb_ShareAttributesForExport($match) { - - $attributes = $match[2]; - - $author = ""; - preg_match("/author='(.*?)'/ism", $attributes, $matches); - if ($matches[1] != "") - $author = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8'); - - preg_match('/author="(.*?)"/ism', $attributes, $matches); - if ($matches[1] != "") - $author = $matches[1]; - - $profile = ""; - preg_match("/profile='(.*?)'/ism", $attributes, $matches); - if ($matches[1] != "") - $profile = $matches[1]; - - preg_match('/profile="(.*?)"/ism', $attributes, $matches); - if ($matches[1] != "") - $profile = $matches[1]; - - $link = ""; - preg_match("/link='(.*?)'/ism", $attributes, $matches); - if ($matches[1] != "") - $link = $matches[1]; - - preg_match('/link="(.*?)"/ism', $attributes, $matches); - if ($matches[1] != "") - $link = $matches[1]; - - if ($link == "") - $link = $profile; - - $userid = GetProfileUsername($profile,$author); - - $headline = '
'; - $headline .= ''.html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8'); - $headline .= sprintf(t('%2$s %3$s'), $link, $userid, $posted); - $headline .= ":
"; - - $text = trim($match[1]); - - if ($text != "") - $text .= "
"; - - $text .= $headline.'
'.trim($match[3])."

"; - - return($text); -} - -// Still in use? -function bb_ShareAttributesSimple($match) { - - $attributes = $match[1]; - - $author = ""; - preg_match("/author='(.*?)'/ism", $attributes, $matches); - if ($matches[1] != "") - $author = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8'); - - preg_match('/author="(.*?)"/ism', $attributes, $matches); - if ($matches[1] != "") - $author = $matches[1]; - - $profile = ""; - preg_match("/profile='(.*?)'/ism", $attributes, $matches); - if ($matches[1] != "") - $profile = $matches[1]; - - preg_match('/profile="(.*?)"/ism', $attributes, $matches); - if ($matches[1] != "") - $profile = $matches[1]; - - $userid = GetProfileUsername($profile,$author); - - $text = "
".html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8').' '.$userid.":
»".$match[2]."«"; - - return($text); -} - -// Used for text exports (Twitter, Facebook, Google+) -function bb_ShareAttributesSimple2($match) { - - $attributes = $match[1]; - - $author = ""; - preg_match("/author='(.*?)'/ism", $attributes, $matches); - if ($matches[1] != "") - $author = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8'); - - preg_match('/author="(.*?)"/ism', $attributes, $matches); - if ($matches[1] != "") - $author = $matches[1]; - - $profile = ""; - preg_match("/profile='(.*?)'/ism", $attributes, $matches); - if ($matches[1] != "") - $profile = $matches[1]; - - preg_match('/profile="(.*?)"/ism', $attributes, $matches); - if ($matches[1] != "") - $profile = $matches[1]; - - $userid = GetProfileUsername($profile,$author); - - //$text = "
".html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8').' '.$userid.":
".$match[2]; - $text = "
".html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8').' '.$userid.":
".$match[2]; - - return($text); -} -*/ function bb_ShareAttributes($share, $simplehtml) { $attributes = $share[2]; @@ -676,7 +437,8 @@ function bb_ShareAttributes($share, $simplehtml) { $reldate = (($posted) ? " " . relative_date($posted) : ''); } - $userid = GetProfileUsername($profile,$author); + $userid = GetProfileUsername($profile,$author, false); + $userid_compact = GetProfileUsername($profile,$author, true); $preshare = trim($share[1]); @@ -688,7 +450,7 @@ function bb_ShareAttributes($share, $simplehtml) { $text = $preshare.html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8').' '.$userid.":
»".$share[3]."«"; break; case 2: - $text = $preshare.html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8').' '.$userid.":
".$share[3]; + $text = $preshare.html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8').' '.$userid_compact.":
".$share[3]; break; case 3: $headline = '
'; @@ -720,10 +482,16 @@ function bb_ShareAttributes($share, $simplehtml) { break; case 5: - $text = $preshare.html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8').' '.$userid.":
".$share[3]; + $text = $preshare.html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8').' '.$userid_compact.":
".$share[3]; break; case 6: - $text = $preshare.">> ".$userid.":
".$share[3]; + $text = $preshare.">> ".$userid_compact.":
".$share[3]; + break; + case 7: + $text = $preshare."RD ".$userid_compact." ".$share[3]; + break; + case 8: + $text = $preshare."RT ".$userid_compact." ".$share[3]; break; default: $headline = trim($share[1]).'
'; @@ -738,27 +506,43 @@ function bb_ShareAttributes($share, $simplehtml) { return($text); } -function GetProfileUsername($profile, $username) { +function GetProfileUsername($profile, $username, $compact = false) { $twitter = preg_replace("=https?://twitter.com/(.*)=ism", "$1@twitter.com", $profile); - if ($twitter != $profile) - return($username." (".$twitter.")"); + if ($twitter != $profile) { + if ($compact) + return($twitter); + else + return($username." (".$twitter.")"); + } $appnet = preg_replace("=https?://alpha.app.net/(.*)=ism", "$1@alpha.app.net", $profile); - if ($appnet != $profile) - return($username." (".$appnet.")"); + if ($appnet != $profile) { + if ($compact) + return($appnet); + else + return($username." (".$appnet.")"); + } $gplus = preg_replace("=https?://plus.google.com/(.*)=ism", "$1@plus.google.com", $profile); if ($gplus != $profile) return($username." (".$gplus.")"); $friendica = preg_replace("=https?://(.*)/profile/(.*)=ism", "$2@$1", $profile); - if ($friendica != $profile) - return($username." (".$friendica.")"); + if ($friendica != $profile) { + if ($compact) + return($friendica); + else + return($username." (".$friendica.")"); + } $diaspora = preg_replace("=https?://(.*)/u/(.*)=ism", "$2@$1", $profile); - if ($diaspora != $profile) - return($username." (".$diaspora.")"); + if ($diaspora != $profile) { + if ($compact) + return($diaspora); + else + return($username." (".$diaspora.")"); + } $StatusnetHost = preg_replace("=https?://(.*)/user/(.*)=ism", "$1", $profile); if ($StatusnetHost != $profile) { @@ -766,8 +550,12 @@ function GetProfileUsername($profile, $username) { if ($StatusnetUser != $profile) { $UserData = fetch_url("http://".$StatusnetHost."/api/users/show.json?user_id=".$StatusnetUser); $user = json_decode($UserData); - if ($user) - return($username." (".$user->screen_name."@".$StatusnetHost.")"); + if ($user) { + if ($compact) + return($user->screen_name."@".$StatusnetHost); + else + return($username." (".$user->screen_name."@".$StatusnetHost.")"); + } } } @@ -775,8 +563,12 @@ function GetProfileUsername($profile, $username) { $rest = preg_replace("=https?://([\.\w]+)/([\.\w]+)(.*)=ism", "$3", $profile); if ($rest == "") { $pumpio = preg_replace("=https?://([\.\w]+)/([\.\w]+)(.*)=ism", "$2@$1", $profile); - if ($pumpio != $profile) - return($username." (".$pumpio.")"); + if ($pumpio != $profile) { + if ($compact) + return($pumpio); + else + return($username." (".$pumpio.")"); + } } return($username); @@ -979,7 +771,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal $Text = preg_replace("/#\[url\=[$URLSearchString]*\]\^\[\/url\]\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/i", "[bookmark=$1]$2[/bookmark]", $Text); - if (in_array($simplehtml, array(2, 6))) { + if (in_array($simplehtml, array(2, 6, 7, 8))) { $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); @@ -1160,18 +952,6 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal function ($match) use ($simplehtml){ return(bb_ShareAttributes($match, $simplehtml)); },$Text); -/* - if (!$simplehtml) - $Text = preg_replace_callback("/\[share(.*?)\](.*?)\[\/share\]/ism","bb_ShareAttributes",$Text); - elseif ($simplehtml == 1) - $Text = preg_replace_callback("/\[share(.*?)\](.*?)\[\/share\]/ism","bb_ShareAttributesSimple",$Text); - elseif (($simplehtml == 2) OR ($simplehtml == 5)) - $Text = preg_replace_callback("/\[share(.*?)\](.*?)\[\/share\]/ism","bb_ShareAttributesSimple2",$Text); - elseif ($simplehtml == 3) - $Text = preg_replace_callback("/(.*?)\[share(.*?)\](.*?)\[\/share\]/ism","bb_ShareAttributesDiaspora",$Text); - elseif ($simplehtml == 4) - $Text = preg_replace_callback("/(.*?)\[share(.*?)\](.*?)\[\/share\]/ism","bb_ShareAttributesForExport",$Text); -*/ $Text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism",'
' . t('Encrypted content') . '
', $Text); $Text = preg_replace("/\[crypt(.*?)\](.*?)\[\/crypt\]/ism",'
' . t('Encrypted content') . '
', $Text); From d9f6f5181f801e3a54d66801462b19da6788d4cd Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 10 Jul 2014 00:00:09 +0200 Subject: [PATCH 08/10] Using @ before username when repeating messages to twitter and statusnet --- include/bbcode.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/bbcode.php b/include/bbcode.php index be7535ace..90d5e9358 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -488,10 +488,10 @@ function bb_ShareAttributes($share, $simplehtml) { $text = $preshare.">> ".$userid_compact.":
".$share[3]; break; case 7: - $text = $preshare."RD ".$userid_compact." ".$share[3]; + $text = $preshare."RD @".$userid_compact." ".$share[3]; break; case 8: - $text = $preshare."RT ".$userid_compact." ".$share[3]; + $text = $preshare."RT @".$userid_compact." ".$share[3]; break; default: $headline = trim($share[1]).'
'; From 31dbf23c47d8b50e5c57dd2ec6b3de7f657379f7 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 10 Jul 2014 00:12:12 +0200 Subject: [PATCH 09/10] bbcode: Shared posts to app.net will now have an @ before the username. --- include/bbcode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/bbcode.php b/include/bbcode.php index 90d5e9358..1937955e5 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -485,7 +485,7 @@ function bb_ShareAttributes($share, $simplehtml) { $text = $preshare.html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8').' '.$userid_compact.":
".$share[3]; break; case 6: - $text = $preshare.">> ".$userid_compact.":
".$share[3]; + $text = $preshare.">> @".$userid_compact.":
".$share[3]; break; case 7: $text = $preshare."RD @".$userid_compact." ".$share[3]; From 431a4d40ebd266af892c62f05f3f5082c3a16b69 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 10 Jul 2014 00:16:03 +0200 Subject: [PATCH 10/10] using the recycle sign instead of "RD" for statusnet. --- include/bbcode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/bbcode.php b/include/bbcode.php index 1937955e5..cea1dbdcc 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -488,7 +488,7 @@ function bb_ShareAttributes($share, $simplehtml) { $text = $preshare.">> @".$userid_compact.":
".$share[3]; break; case 7: - $text = $preshare."RD @".$userid_compact." ".$share[3]; + $text = $preshare.html_entity_decode("♲ ", ENT_QUOTES, 'UTF-8')." @".$userid_compact." ".$share[3]; break; case 8: $text = $preshare."RT @".$userid_compact." ".$share[3];