From 5476da53aa0251ac8dc419da8e3e9695cdb6b1fe Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 21 Apr 2018 04:09:45 -0400 Subject: [PATCH 001/123] Move Content\BBCode::toPlaintext() to Model\Item::getPlaintextPost() --- src/Content/Text/BBCode.php | 156 ----------------------------------- src/Model/Item.php | 160 ++++++++++++++++++++++++++++++++++++ 2 files changed, 160 insertions(+), 156 deletions(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 3755593465..e22306fc8d 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -342,162 +342,6 @@ class BBCode extends BaseObject return $post; } - /** - * @brief Convert a message into plaintext for connectors to other networks - * - * @param array $b The message array that is about to be posted - * @param int $limit The maximum number of characters when posting to that network - * @param bool $includedlinks Has an attached link to be included into the message? - * @param int $htmlmode This triggers the behaviour of the bbcode conversion - * @param string $target_network Name of the network where the post should go to. - * - * @return string The converted message - */ - public static function toPlaintext($b, $limit = 0, $includedlinks = false, $htmlmode = 2, $target_network = "") - { - // Remove the hash tags - $URLSearchString = "^\[\]"; - $body = preg_replace("/([#@])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$1$3', $b["body"]); - - // Add an URL element if the text contains a raw link - $body = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1[url]$2[/url]', $body); - - // Remove the abstract - $body = self::stripAbstract($body); - - // At first look at data that is attached via "type-..." stuff - // This will hopefully replaced with a dedicated bbcode later - //$post = self::getAttachedData($b["body"]); - $post = self::getAttachedData($body, $b); - - if (($b["title"] != "") && ($post["text"] != "")) { - $post["text"] = trim($b["title"]."\n\n".$post["text"]); - } elseif ($b["title"] != "") { - $post["text"] = trim($b["title"]); - } - - $abstract = ""; - - // Fetch the abstract from the given target network - if ($target_network != "") { - $default_abstract = self::getAbstract($b["body"]); - $abstract = self::getAbstract($b["body"], $target_network); - - // If we post to a network with no limit we only fetch - // an abstract exactly for this network - if (($limit == 0) && ($abstract == $default_abstract)) { - $abstract = ""; - } - } else {// Try to guess the correct target network - switch ($htmlmode) { - case 8: - $abstract = self::getAbstract($b["body"], NETWORK_TWITTER); - break; - case 7: - $abstract = self::getAbstract($b["body"], NETWORK_STATUSNET); - break; - case 6: - $abstract = self::getAbstract($b["body"], NETWORK_APPNET); - break; - default: // We don't know the exact target. - // We fetch an abstract since there is a posting limit. - if ($limit > 0) { - $abstract = self::getAbstract($b["body"]); - } - } - } - - if ($abstract != "") { - $post["text"] = $abstract; - - if ($post["type"] == "text") { - $post["type"] = "link"; - $post["url"] = $b["plink"]; - } - } - - $html = self::convert($post["text"].$post["after"], false, $htmlmode); - $msg = HTML::toPlaintext($html, 0, true); - $msg = trim(html_entity_decode($msg, ENT_QUOTES, 'UTF-8')); - - $link = ""; - if ($includedlinks) { - if ($post["type"] == "link") { - $link = $post["url"]; - } elseif ($post["type"] == "text") { - $link = $post["url"]; - } elseif ($post["type"] == "video") { - $link = $post["url"]; - } elseif ($post["type"] == "photo") { - $link = $post["image"]; - } - - if (($msg == "") && isset($post["title"])) { - $msg = trim($post["title"]); - } - - if (($msg == "") && isset($post["description"])) { - $msg = trim($post["description"]); - } - - // If the link is already contained in the post, then it neeedn't to be added again - // But: if the link is beyond the limit, then it has to be added. - if (($link != "") && strstr($msg, $link)) { - $pos = strpos($msg, $link); - - // Will the text be shortened in the link? - // Or is the link the last item in the post? - if (($limit > 0) && ($pos < $limit) && (($pos + 23 > $limit) || ($pos + strlen($link) == strlen($msg)))) { - $msg = trim(str_replace($link, "", $msg)); - } elseif (($limit == 0) || ($pos < $limit)) { - // The limit has to be increased since it will be shortened - but not now - // Only do it with Twitter (htmlmode = 8) - if (($limit > 0) && (strlen($link) > 23) && ($htmlmode == 8)) { - $limit = $limit - 23 + strlen($link); - } - - $link = ""; - - if ($post["type"] == "text") { - unset($post["url"]); - } - } - } - } - - if ($limit > 0) { - // Reduce multiple spaces - // When posted to a network with limited space, we try to gain space where possible - while (strpos($msg, " ") !== false) { - $msg = str_replace(" ", " ", $msg); - } - - // Twitter is using its own limiter, so we always assume that shortened links will have this length - if (iconv_strlen($link, "UTF-8") > 0) { - $limit = $limit - 23; - } - - if (iconv_strlen($msg, "UTF-8") > $limit) { - if (($post["type"] == "text") && isset($post["url"])) { - $post["url"] = $b["plink"]; - } elseif (!isset($post["url"])) { - $limit = $limit - 23; - $post["url"] = $b["plink"]; - // Which purpose has this line? It is now uncommented, but left as a reminder - //} elseif (strpos($b["body"], "[share") !== false) { - // $post["url"] = $b["plink"]; - } elseif (PConfig::get($b["uid"], "system", "no_intelligent_shortening")) { - $post["url"] = $b["plink"]; - } - $msg = Plaintext::shorten($msg, $limit); - } - } - - $post["text"] = trim($msg); - - return($post); - } - public static function scaleExternalImages($srctext, $include_link = true, $scale_replace = false) { // Suppress "view full size" diff --git a/src/Model/Item.php b/src/Model/Item.php index bdb85af441..11594486ea 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -7,6 +7,7 @@ namespace Friendica\Model; use Friendica\BaseObject; +use Friendica\Content\Text; use Friendica\Core\Addon; use Friendica\Core\Config; use Friendica\Core\L10n; @@ -1553,6 +1554,165 @@ class Item extends BaseObject return $ret; } + /** + * @brief Convert a message into plaintext for connectors to other networks + * + * @param array $item The message array that is about to be posted + * @param int $limit The maximum number of characters when posting to that network + * @param bool $includedlinks Has an attached link to be included into the message? + * @param int $htmlmode This controls the behavior of the BBCode conversion + * @param string $target_network Name of the network where the post should go to. + * + * @see \Friendica\Content\Text\BBCode::getAttachedData + * + * @return array Same array structure than \Friendica\Content\Text\BBCode::getAttachedData + */ + public static function getPlaintextPost($item, $limit = 0, $includedlinks = false, $htmlmode = 2, $target_network = '') + { + // Remove hashtags + $URLSearchString = '^\[\]'; + $body = preg_replace("/([#@])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$1$3', $item['body']); + + // Add an URL element if the text contains a raw link + $body = preg_replace('/([^\]\=\'"]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism', + '$1[url]$2[/url]', $body); + + // Remove the abstract + $body = Text\BBCode::stripAbstract($body); + + // At first look at data that is attached via "type-..." stuff + // This will hopefully replaced with a dedicated bbcode later + //$post = self::getAttachedData($b['body']); + $post = Text\BBCode::getAttachedData($body, $item); + + if (($item['title'] != '') && ($post['text'] != '')) { + $post['text'] = trim($item['title'] . "\n\n" . $post['text']); + } elseif ($item['title'] != '') { + $post['text'] = trim($item['title']); + } + + $abstract = ''; + + // Fetch the abstract from the given target network + if ($target_network != '') { + $default_abstract = Text\BBCode::getAbstract($item['body']); + $abstract = Text\BBCode::getAbstract($item['body'], $target_network); + + // If we post to a network with no limit we only fetch + // an abstract exactly for this network + if (($limit == 0) && ($abstract == $default_abstract)) { + $abstract = ''; + } + } else {// Try to guess the correct target network + switch ($htmlmode) { + case 8: + $abstract = Text\BBCode::getAbstract($item['body'], NETWORK_TWITTER); + break; + case 7: + $abstract = Text\BBCode::getAbstract($item['body'], NETWORK_STATUSNET); + break; + case 6: + $abstract = Text\BBCode::getAbstract($item['body'], NETWORK_APPNET); + break; + default: // We don't know the exact target. + // We fetch an abstract since there is a posting limit. + if ($limit > 0) { + $abstract = Text\BBCode::getAbstract($item['body']); + } + } + } + + if ($abstract != '') { + $post['text'] = $abstract; + + if ($post['type'] == 'text') { + $post['type'] = 'link'; + $post['url'] = $item['plink']; + } + } + + $html = Text\BBCode::convert($post['text'] . $post['after'], false, $htmlmode); + $msg = Text\HTML::toPlaintext($html, 0, true); + $msg = trim(html_entity_decode($msg, ENT_QUOTES, 'UTF-8')); + + $link = ''; + if ($includedlinks) { + if ($post['type'] == 'link') { + $link = $post['url']; + } elseif ($post['type'] == 'text') { + $link = $post['url']; + } elseif ($post['type'] == 'video') { + $link = $post['url']; + } elseif ($post['type'] == 'photo') { + $link = $post['image']; + } + + if (($msg == '') && isset($post['title'])) { + $msg = trim($post['title']); + } + + if (($msg == '') && isset($post['description'])) { + $msg = trim($post['description']); + } + + // If the link is already contained in the post, then it neeedn't to be added again + // But: if the link is beyond the limit, then it has to be added. + if (($link != '') && strstr($msg, $link)) { + $pos = strpos($msg, $link); + + // Will the text be shortened in the link? + // Or is the link the last item in the post? + if (($limit > 0) && ($pos < $limit) && (($pos + 23 > $limit) || ($pos + strlen($link) == strlen($msg)))) { + $msg = trim(str_replace($link, '', $msg)); + } elseif (($limit == 0) || ($pos < $limit)) { + // The limit has to be increased since it will be shortened - but not now + // Only do it with Twitter (htmlmode = 8) + if (($limit > 0) && (strlen($link) > 23) && ($htmlmode == 8)) { + $limit = $limit - 23 + strlen($link); + } + + $link = ''; + + if ($post['type'] == 'text') { + unset($post['url']); + } + } + } + } + + if ($limit > 0) { + // Reduce multiple spaces + // When posted to a network with limited space, we try to gain space where possible + while (strpos($msg, ' ') !== false) { + $msg = str_replace(' ', ' ', $msg); + } + + // Twitter is using its own limiter, so we always assume that shortened links will have this length + if (iconv_strlen($link, 'UTF-8') > 0) { + $limit = $limit - 23; + } + + if (iconv_strlen($msg, 'UTF-8') > $limit) { + if (($post['type'] == 'text') && isset($post['url'])) { + $post['url'] = $item['plink']; + } elseif (!isset($post['url'])) { + $limit = $limit - 23; + $post['url'] = $item['plink']; + // Which purpose has this line? It is now uncommented, but left as a reminder + //} elseif (strpos($b['body'], '[share') !== false) { + // $post['url'] = $b['plink']; + } elseif (PConfig::get($item['uid'], 'system', 'no_intelligent_shortening')) { + $post['url'] = $item['plink']; + } + $msg = Text\Plaintext::shorten($msg, $limit); + } + } + + $post['text'] = trim($msg); + + return $post; + } + public static function expire($uid, $days, $network = "", $force = false) { if (!$uid || ($days < 1)) { From ec9baef96840efd28fd34747f2045a690a701c3f Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 21 Apr 2018 04:10:25 -0400 Subject: [PATCH 002/123] Add new Content\BBCode::toPlaintext() --- src/Content/Text/BBCode.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index e22306fc8d..96c8eceb70 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -342,6 +342,23 @@ class BBCode extends BaseObject return $post; } + /** + * @brief Converts a BBCode text into plaintext + * + * @param bool $keep_urls Whether to keep URLs in the resulting plaintext + * + * @return string + */ + public static function toPlaintext($text, $keep_urls = true) + { + $naked_text = preg_replace('/\[(.+?)\]/','', $text); + if (!$keep_urls) { + $naked_text = preg_replace('#https?\://[^\s<]+[^\s\.\)]#i', '', $naked_text); + } + + return $naked_text; + } + public static function scaleExternalImages($srctext, $include_link = true, $scale_replace = false) { // Suppress "view full size" From abc50eb3aed2ed2a6fef207cfaea033689e0779e Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 21 Apr 2018 04:11:32 -0400 Subject: [PATCH 003/123] Improve Model\Item::addLanguageInPostopts() - Use Content\BBCode::toPlaintext method - Rename $arr parameter to $item - Rename $lng variable to $languages --- src/Model/Item.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Model/Item.php b/src/Model/Item.php index 11594486ea..db6ba89105 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -978,35 +978,35 @@ class Item extends BaseObject * if possible and not already present. * Expects "body" element to exist in $arr. */ - private static function addLanguageInPostopts(&$arr) + private static function addLanguageInPostopts(&$item) { - if (x($arr, 'postopts')) { - if (strstr($arr['postopts'], 'lang=')) { + if (!empty($item['postopts'])) { + if (strstr($item['postopts'], 'lang=')) { // do not override return; } - $postopts = $arr['postopts']; + $postopts = $item['postopts']; } else { $postopts = ""; } - $naked_body = preg_replace('/\[(.+?)\]/','', $arr['body']); - $l = new Text_LanguageDetect(); - $lng = $l->detect($naked_body, 3); + $naked_body = Text\BBCode::toPlaintext($item['body'], false); - if (sizeof($lng) > 0) { - if ($postopts != "") { + $languages = (new Text_LanguageDetect())->detect($naked_body, 3); + + if (sizeof($languages) > 0) { + if ($postopts != '') { $postopts .= '&'; // arbitrary separator, to be reviewed } $postopts .= 'lang='; $sep = ""; - foreach ($lng as $language => $score) { + foreach ($languages as $language => $score) { $postopts .= $sep . $language . ";" . $score; $sep = ':'; } - $arr['postopts'] = $postopts; + $item['postopts'] = $postopts; } } From 1e67c3214251b27d4d4570224db13197127cd386 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 21 Apr 2018 04:38:27 -0400 Subject: [PATCH 004/123] Fix BBCode::getAbstract scope --- src/Content/Text/BBCode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 96c8eceb70..6c441bac6f 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -1808,7 +1808,7 @@ class BBCode extends BaseObject * @param string $addon The addon for which the abstract is meant for * @return string The abstract */ - private static function getAbstract($text, $addon = "") + public static function getAbstract($text, $addon = "") { $abstract = ""; $abstracts = []; From e61ed380f7ba3129f1981b1500d8371921c9a5c6 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 21 Apr 2018 09:55:41 +0000 Subject: [PATCH 005/123] Reworked dfrn_notify endpoint, added public endpoint --- mod/dfrn_notify.php | 185 +++++++++++++++++++++++++------------------- 1 file changed, 106 insertions(+), 79 deletions(-) diff --git a/mod/dfrn_notify.php b/mod/dfrn_notify.php index 7eddd4f3d5..9bd06c6748 100644 --- a/mod/dfrn_notify.php +++ b/mod/dfrn_notify.php @@ -25,41 +25,23 @@ function dfrn_notify_post(App $a) { $data = json_decode($postdata); if (is_object($data)) { $nick = defaults($a->argv, 1, ''); - $user = dba::selectFirst('user', [], ['nickname' => $nick, 'account_expired' => false, 'account_removed' => false]); - if (!DBM::is_result($user)) { - System::httpExit(500); + $public = empty($nick); + if (!$public) { + $user = dba::selectFirst('user', [], ['nickname' => $nick, 'account_expired' => false, 'account_removed' => false]); + if (!DBM::is_result($user)) { + System::httpExit(500); + } + } else { + // We don't need the user with public posts + $user = []; } $msg = Diaspora::decodeRaw($user, $postdata); - // Check if the user has got this contact - $cid = Contact::getIdForURL($msg['author'], $user['uid']); - if (!$cid) { - // Otherwise there should be a public contact - $cid = Contact::getIdForURL($msg['author']); - if (!$cid) { - logger('Contact not found for address ' . $msg['author']); - System::xmlExit(3, 'Contact not found'); - } + if ($public) { + dfrn_dispatch_public($msg); + } else { + dfrn_dispatch_private($user, $msg); } - - // We now have some contact, so we fetch it - $importer = dba::fetch_first("SELECT *, `name` as `senderName` - FROM `contact` - WHERE NOT `blocked` AND `id` = ? LIMIT 1", - $cid); - - // This should never fail - if (!DBM::is_result($importer)) { - logger('Contact not found for address ' . $msg['author']); - System::xmlExit(3, 'Contact not found'); - } - - // Set the user id. This is important if this is a public contact - $importer['importer_uid'] = $user['uid']; - - // Now we should be able to import it - $ret = DFRN::import($msg['message'], $importer); - System::xmlExit($ret, 'Done'); } else { require_once 'mod/salmon.php'; salmon_post($a, $postdata); @@ -91,19 +73,12 @@ function dfrn_notify_post(App $a) { $dfrn_id = substr($dfrn_id, 2); } - $r = q("SELECT * FROM `challenge` WHERE `dfrn-id` = '%s' AND `challenge` = '%s' LIMIT 1", - dbesc($dfrn_id), - dbesc($challenge) - ); - if (! DBM::is_result($r)) { - logger('dfrn_notify: could not match challenge to dfrn_id ' . $dfrn_id . ' challenge=' . $challenge); + if (!dba::exists('challenge', ['dfrn-id' => $dfrn_id, 'challenge' => $challenge])) { + logger('could not match challenge to dfrn_id ' . $dfrn_id . ' challenge=' . $challenge); System::xmlExit(3, 'Could not match challenge'); } - $r = q("DELETE FROM `challenge` WHERE `dfrn-id` = '%s' AND `challenge` = '%s'", - dbesc($dfrn_id), - dbesc($challenge) - ); + dba::delete('challenge', ['dfrn-id' => $dfrn_id, 'challenge' => $challenge]); // find the local user who owns this relationship. @@ -143,8 +118,8 @@ function dfrn_notify_post(App $a) { dbesc($a->argv[1]) ); - if (! DBM::is_result($r)) { - logger('dfrn_notify: contact not found for dfrn_id ' . $dfrn_id); + if (!DBM::is_result($r)) { + logger('contact not found for dfrn_id ' . $dfrn_id); System::xmlExit(3, 'Contact not found'); //NOTREACHED } @@ -153,15 +128,11 @@ function dfrn_notify_post(App $a) { $importer = $r[0]; - logger("Remote rino version: ".$rino_remote." for ".$importer["url"], LOGGER_DEBUG); - if ((($writable != (-1)) && ($writable != $importer['writable'])) || ($importer['forum'] != $forum) || ($importer['prv'] != $prv)) { - q("UPDATE `contact` SET `writable` = %d, forum = %d, prv = %d WHERE `id` = %d", - intval(($writable == (-1)) ? $importer['writable'] : $writable), - intval($forum), - intval($prv), - intval($importer['id']) - ); + $fields = ['writable' => ($writable == (-1)) ? $importer['writable'] : $writable, + 'forum' => $forum, 'prv' => $prv]; + dba::update('contact', $fields, ['id' => $importer['id']]); + if ($writable != (-1)) { $importer['writable'] = $writable; } @@ -173,8 +144,7 @@ function dfrn_notify_post(App $a) { $importer = Contact::updateSslPolicy($importer, $ssl_policy); - logger('dfrn_notify: received notify from ' . $importer['name'] . ' for ' . $importer['username']); - logger('dfrn_notify: data: ' . $data, LOGGER_DATA); + logger('data: ' . $data, LOGGER_DATA); if ($dissolve == 1) { // Relationship is dissolved permanently @@ -186,8 +156,6 @@ function dfrn_notify_post(App $a) { $rino = Config::get('system', 'rino_encrypt'); $rino = intval($rino); - logger("Local rino version: " . $rino, LOGGER_DEBUG); - if (strlen($key)) { // if local rino is lower than remote rino, abort: should not happen! @@ -198,24 +166,25 @@ function dfrn_notify_post(App $a) { } $rawkey = hex2bin(trim($key)); - logger('rino: md5 raw key: ' . md5($rawkey)); + logger('rino: md5 raw key: ' . md5($rawkey), LOGGER_DATA); + $final_key = ''; if ($dfrn_version >= 2.1) { - if ((($importer['duplex']) && strlen($importer['cprvkey'])) || (! strlen($importer['cpubkey']))) { + if (($importer['duplex'] && strlen($importer['cprvkey'])) || !strlen($importer['cpubkey'])) { openssl_private_decrypt($rawkey, $final_key, $importer['cprvkey']); } else { openssl_public_decrypt($rawkey, $final_key, $importer['cpubkey']); } } else { - if ((($importer['duplex']) && strlen($importer['cpubkey'])) || (! strlen($importer['cprvkey']))) { + if (($importer['duplex'] && strlen($importer['cpubkey'])) || !strlen($importer['cprvkey'])) { openssl_public_decrypt($rawkey, $final_key, $importer['cpubkey']); } else { openssl_private_decrypt($rawkey, $final_key, $importer['cprvkey']); } } - switch($rino_remote) { + switch ($rino_remote) { case 0: case 1: // we got a key. old code send only the key, without RINO version. @@ -230,16 +199,80 @@ function dfrn_notify_post(App $a) { logger('rino: decrypted data: ' . $data, LOGGER_DATA); } + logger('Importing post from ' . $importer['addr'] . ' to ' . $importer['nickname'] . ' with the RINO ' . $rino_remote . ' encryption.', LOGGER_DEBUG); + $ret = DFRN::import($data, $importer); System::xmlExit($ret, 'Processed'); // NOTREACHED } +function dfrn_dispatch_public($msg) +{ + // Fetch the corresponding public contact + $contact = getDetailsByAddr($msg['author'], 0); + if (!$contact) { + logger('Contact not found for address ' . $msg['author']); + System::xmlExit(3, 'Contact not found'); + } + + // We now have some contact, so we fetch it + $importer = dba::fetch_first("SELECT *, `name` as `senderName` + FROM `contact` + WHERE NOT `blocked` AND `id` = ? LIMIT 1", + $cid); + + // This should never fail + if (!DBM::is_result($importer)) { + logger('Contact not found for address ' . $msg['author']); + System::xmlExit(3, 'Contact not found'); + } + + logger('Importing post from ' . $msg['author'] . ' with the public envelope.', LOGGER_DEBUG); + + // Now we should be able to import it + $ret = DFRN::import($msg['message'], $importer); + System::xmlExit($ret, 'Done'); +} + +function dfrn_dispatch_private($user, $msg) +{ + // Check if the user has got this contact + $cid = Contact::getIdForURL($msg['author'], $user['uid']); + if (!$cid) { + // Otherwise there should be a public contact + $cid = Contact::getIdForURL($msg['author']); + if (!$cid) { + logger('Contact not found for address ' . $msg['author']); + System::xmlExit(3, 'Contact not found'); + } + } + + // We now have some contact, so we fetch it + $importer = dba::fetch_first("SELECT *, `name` as `senderName` + FROM `contact` + WHERE NOT `blocked` AND `id` = ? LIMIT 1", + $cid); + + // This should never fail + if (!DBM::is_result($importer)) { + logger('Contact not found for address ' . $msg['author']); + System::xmlExit(3, 'Contact not found'); + } + + // Set the user id. This is important if this is a public contact + $importer['importer_uid'] = $user['uid']; + + logger('Importing post from ' . $msg['author'] . ' to ' . $user['nickname'] . ' with the private envelope.', LOGGER_DEBUG); + + // Now we should be able to import it + $ret = DFRN::import($msg['message'], $importer); + System::xmlExit($ret, 'Done'); +} function dfrn_notify_content(App $a) { - if(x($_GET,'dfrn_id')) { + if (x($_GET,'dfrn_id')) { /* * initial communication from external contact, $direction is their direction. @@ -252,10 +285,10 @@ function dfrn_notify_content(App $a) { $type = ""; $last_update = ""; - logger('dfrn_notify: new notification dfrn_id=' . $dfrn_id); + logger('new notification dfrn_id=' . $dfrn_id); $direction = (-1); - if(strpos($dfrn_id,':') == 1) { + if (strpos($dfrn_id,':') == 1) { $direction = intval(substr($dfrn_id,0,1)); $dfrn_id = substr($dfrn_id,2); } @@ -264,23 +297,18 @@ function dfrn_notify_content(App $a) { $status = 0; - $r = q("DELETE FROM `challenge` WHERE `expire` < " . intval(time())); + dba::delete('challenge', ["`expire` < ?", time()]); - $r = q("INSERT INTO `challenge` ( `challenge`, `dfrn-id`, `expire` , `type`, `last_update` ) - VALUES( '%s', '%s', %d, '%s', '%s' ) ", - dbesc($hash), - dbesc($dfrn_id), - intval(time() + 90 ), - dbesc($type), - dbesc($last_update) - ); + $fields = ['challenge' => $hash, 'dfrn-id' => $dfrn_id, 'expire' => time() + 90, + 'type' => $type, 'last_update' => $last_update]; + dba::insert('challenge', $fields); - logger('dfrn_notify: challenge=' . $hash, LOGGER_DEBUG); + logger('challenge=' . $hash, LOGGER_DATA); $sql_extra = ''; switch($direction) { case (-1): - $sql_extra = sprintf(" AND ( `issued-id` = '%s' OR `dfrn-id` = '%s' ) ", dbesc($dfrn_id), dbesc($dfrn_id)); + $sql_extra = sprintf(" AND (`issued-id` = '%s' OR `dfrn-id` = '%s') ", dbesc($dfrn_id), dbesc($dfrn_id)); $my_id = $dfrn_id; break; case 0: @@ -302,11 +330,11 @@ function dfrn_notify_content(App $a) { dbesc($a->argv[1]) ); - if (! DBM::is_result($r)) { + if (!DBM::is_result($r)) { $status = 1; } - logger("Remote rino version: ".$rino_remote." for ".$r[0]["url"], LOGGER_DEBUG); + logger("Remote rino version: ".$rino_remote." for ".$r[0]["url"], LOGGER_DATA); $challenge = ''; $encrypted_id = ''; @@ -316,7 +344,7 @@ function dfrn_notify_content(App $a) { $pub_key = trim($r[0]['pubkey']); $dplx = intval($r[0]['duplex']); - if ((($dplx) && (strlen($prv_key))) || ((strlen($prv_key)) && (!(strlen($pub_key))))) { + if (($dplx && strlen($prv_key)) || (strlen($prv_key) && !strlen($pub_key))) { openssl_private_encrypt($hash, $challenge, $prv_key); openssl_private_encrypt($id_str, $encrypted_id, $prv_key); } elseif (strlen($pub_key)) { @@ -334,7 +362,7 @@ function dfrn_notify_content(App $a) { $rino = Config::get('system', 'rino_encrypt'); $rino = intval($rino); - logger("Local rino version: ". $rino, LOGGER_DEBUG); + logger("Local rino version: ". $rino, LOGGER_DATA); // if requested rino is lower than enabled local rino, lower local rino version // if requested rino is higher than enabled local rino, reply with local rino @@ -342,7 +370,7 @@ function dfrn_notify_content(App $a) { $rino = $rino_remote; } - if((($r[0]['rel']) && ($r[0]['rel'] != CONTACT_IS_SHARING)) || ($r[0]['page-flags'] == PAGE_COMMUNITY)) { + if (($r[0]['rel'] && ($r[0]['rel'] != CONTACT_IS_SHARING)) || ($r[0]['page-flags'] == PAGE_COMMUNITY)) { $perm = 'rw'; } else { $perm = 'r'; @@ -362,5 +390,4 @@ function dfrn_notify_content(App $a) { killme(); } - } From 4285cd5dc78f26cbcaab470215240f3300de2e66 Mon Sep 17 00:00:00 2001 From: rabuzarus Date: Sat, 21 Apr 2018 14:05:40 +0200 Subject: [PATCH 006/123] frio - fix image upload for prv messages --- view/theme/frio/js/filebrowser.js | 1 - view/theme/frio/js/modal.js | 1 + view/theme/frio/js/theme.js | 12 ++++++++++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/view/theme/frio/js/filebrowser.js b/view/theme/frio/js/filebrowser.js index 92f1412911..270172072d 100644 --- a/view/theme/frio/js/filebrowser.js +++ b/view/theme/frio/js/filebrowser.js @@ -231,7 +231,6 @@ var FileBrowser = { $(".fbrowser .fbswitcher [data-mode=" + FileBrowser.type + "]").addClass("active"); // We need to add the AjaxUpload to the button FileBrowser.uploadButtons(); - }, // Load new content (e.g. change photo album) diff --git a/view/theme/frio/js/modal.js b/view/theme/frio/js/modal.js index 2b60049f1d..56df75d7b6 100644 --- a/view/theme/frio/js/modal.js +++ b/view/theme/frio/js/modal.js @@ -152,6 +152,7 @@ Dialog._load = function(url) { var jsbrowser = function() { FileBrowser.init(nickname, type, hash); }; + loadScript("view/js/ajaxupload.js"); loadScript("view/theme/frio/js/filebrowser.js", jsbrowser); }; diff --git a/view/theme/frio/js/theme.js b/view/theme/frio/js/theme.js index a8787a6eb5..859df01613 100644 --- a/view/theme/frio/js/theme.js +++ b/view/theme/frio/js/theme.js @@ -446,8 +446,16 @@ function justifyPhotosAjax() { $('#photo-album-contents').justifiedGallery('norewind').on('jg.complete', function(e){ justifiedGalleryActive = false; }); } +// Load a js script to the html head. function loadScript(url, callback) { - // Adding the script tag to the head as suggested before + // Check if the script is already in the html head. + var oscript = $('head script[src="' + url + '"]'); + + // Delete the old script from head. + if (oscript.length > 0) { + oscript.remove(); + } + // Adding the script tag to the head as suggested before. var head = document.getElementsByTagName('head')[0]; var script = document.createElement('script'); script.type = 'text/javascript'; @@ -458,7 +466,7 @@ function loadScript(url, callback) { script.onreadystatechange = callback; script.onload = callback; - // Fire the loading + // Fire the loading. head.appendChild(script); } From 346697d771e2656b4bcd12a5e84045710e9b2b55 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Sat, 21 Apr 2018 14:10:53 +0200 Subject: [PATCH 007/123] Moved .htconfig file Extracted install business functions to new Class `Install.php` --- INSTALL.txt | 14 +- bin/auth_ejabberd.php | 2 +- bin/daemon.php | 2 +- bin/dev/vagrant_provision.sh | 2 +- bin/worker.php | 2 +- htconfig.php => config/htconfig.php | 0 doc/Install.md | 4 +- doc/Update.md | 2 +- doc/Vagrant.md | 2 +- doc/de/FAQ.md | 2 +- doc/de/Install.md | 4 +- include/dba.php | 1 + index.php | 4 +- mod/install.php | 301 +----------------- src/Core/Console/Config.php | 2 +- src/Core/Console/DatabaseStructure.php | 2 +- src/Core/Console/GlobalCommunityBlock.php | 2 +- src/Core/Console/GlobalCommunitySilence.php | 2 +- src/Core/Console/Maintenance.php | 2 +- src/Core/Console/NewPassword.php | 2 +- src/Core/Install.php | 318 ++++++++++++++++++++ util/Doxyfile | 2 +- 22 files changed, 350 insertions(+), 324 deletions(-) rename htconfig.php => config/htconfig.php (100%) create mode 100644 src/Core/Install.php diff --git a/INSTALL.txt b/INSTALL.txt index 9340927f40..aadd0c0079 100644 --- a/INSTALL.txt +++ b/INSTALL.txt @@ -77,7 +77,7 @@ password, database name). - Please check the additional notes if running on MySQ 5.7.17 or newer 4. If you know in advance that it will be impossible for the web server to -write or create files in your web directory, create an empty file called +write or create files in your web directory, create an empty file in config/ called .htconfig.php and make it writable by the web server. 5. Visit your website with a web browser and follow the instructions. Please @@ -92,8 +92,8 @@ so in the host name setting for the database. 6. *If* the automated installation fails for any reason, check the following: - - ".htconfig.php" exists - If not, edit htconfig.php and change system settings. Rename + - "config/.htconfig.php" exists + If not, edit config/htconfig.php and change system settings. Rename to .htconfig.php - Database is populated. If not, import the contents of "database.sql" with phpmyadmin @@ -148,7 +148,7 @@ Bad things will happen. Let there be a hardware failure, a corrupted database or whatever you can think of. So once the installation of your Friendica node is done, you should make yoursef a backup plan. -The most important file is the `.htconfig.php` file in the base directory. +The most important file is the `.htconfig.php` file in the `config/` directory. As it stores all your data, you should also have a recent dump of your Friendica database at hand, should you have to recover your node. @@ -252,14 +252,14 @@ due to permissions issues: create an empty file with that name and give it world-write permission. For Linux: -% touch .htconfig.php -% chmod 777 .htconfig.php +% touch config/.htconfig.php +% chmod 777 config/.htconfig.php Retry the installation. As soon as the database has been created, ******* this is important ********* -% chmod 755 .htconfig.php +% chmod 755 config/.htconfig.php ##################################################################### - Some configurations with "suhosin" security are configured without diff --git a/bin/auth_ejabberd.php b/bin/auth_ejabberd.php index 06d8488df8..901d4a4ceb 100755 --- a/bin/auth_ejabberd.php +++ b/bin/auth_ejabberd.php @@ -57,7 +57,7 @@ require_once "include/dba.php"; $a = new App(dirname(__DIR__)); BaseObject::setApp($a); -@include ".htconfig.php"; +@include "config/.htconfig.php"; dba::connect($db_host, $db_user, $db_pass, $db_data); unset($db_host, $db_user, $db_pass, $db_data); diff --git a/bin/daemon.php b/bin/daemon.php index 6b0e377a3a..d0f57d44d0 100755 --- a/bin/daemon.php +++ b/bin/daemon.php @@ -38,7 +38,7 @@ if (substr($directory, 0, 1) != "/") { } $directory = realpath($directory."/.."); -@include($directory."/.htconfig.php"); +@include($directory."/config/.htconfig.php"); if (!isset($pidfile)) { die('Please specify a pid file in the variable $pidfile in the .htconfig.php. For example:'."\n". diff --git a/bin/dev/vagrant_provision.sh b/bin/dev/vagrant_provision.sh index fc3e266f2e..4419ea7382 100755 --- a/bin/dev/vagrant_provision.sh +++ b/bin/dev/vagrant_provision.sh @@ -86,7 +86,7 @@ cd /var/www php bin/composer.phar install # initial config file for friendica in vagrant -cp /vagrant/util/htconfig.vagrant.php /vagrant/.htconfig.php +cp /vagrant/util/htconfig.vagrant.php /vagrant/config/.htconfig.php # create the friendica database echo "create database friendica DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci" | $MYSQL -u root -proot diff --git a/bin/worker.php b/bin/worker.php index b4b265283c..ad8c2a7c4e 100755 --- a/bin/worker.php +++ b/bin/worker.php @@ -29,7 +29,7 @@ require_once "include/dba.php"; $a = new App(dirname(__DIR__)); BaseObject::setApp($a); -require_once ".htconfig.php"; +require_once "config/.htconfig.php"; dba::connect($db_host, $db_user, $db_pass, $db_data); unset($db_host, $db_user, $db_pass, $db_data); diff --git a/htconfig.php b/config/htconfig.php similarity index 100% rename from htconfig.php rename to config/htconfig.php diff --git a/doc/Install.md b/doc/Install.md index b9b2debb42..a994b4b71a 100644 --- a/doc/Install.md +++ b/doc/Install.md @@ -89,7 +89,7 @@ If you need to specify a port for the connection to the database, you can do so *If* the automated installation fails for any reason, check the following: -* Does ".htconfig.php" exist? If not, edit htconfig.php and change the system settings. Rename to .htconfig.php +* Does ".htconfig.php" in "config/" exist? If not, edit htconfig.php and change the system settings. Rename to .htconfig.php * Is the database is populated? If not, import the contents of "database.sql" with phpmyadmin or mysql command line. At this point visit your website again, and register your personal account. @@ -125,5 +125,5 @@ Bad things will happen. Let there be a hardware failure, a corrupted database or whatever you can think of. So once the installation of your Friendica node is done, you should make yourself a backup plan. -The most important file is the `.htconfig.php` file in the base directory. +The most important file is the `.htconfig.php` file in the `config/` directory. As it stores all your data, you should also have a recent dump of your Friendica database at hand, should you have to recover your node. diff --git a/doc/Update.md b/doc/Update.md index 9e9324da94..801fda65be 100644 --- a/doc/Update.md +++ b/doc/Update.md @@ -7,7 +7,7 @@ Updating Friendica If you installed Friendica in the ``path/to/friendica`` folder: 1. Unpack the new Friendica archive in ``path/to/friendica_new``. -2. Copy ``.htconfig.php``, ``photo/`` and ``proxy/`` from ``path/to/friendica`` to ``path/to/friendica_new``. +2. Copy ``config/.htconfig.php``, ``photo/`` and ``proxy/`` from ``path/to/friendica`` to ``path/to/friendica_new``. 3. Rename the ``path/to/friendica`` folder to ``path/to/friendica_old``. 4. Rename the ``path/to/friendica_new`` folder to ``path/to/friendica``. 5. Check your site. Note: it may go into maintenance mode to update the database schema. diff --git a/doc/Vagrant.md b/doc/Vagrant.md index a224ebafc2..a50d24b138 100644 --- a/doc/Vagrant.md +++ b/doc/Vagrant.md @@ -42,7 +42,7 @@ This will not delete the virtual machine. 9. To ultimately delete the virtual machine run $> vagrant destroy - $> rm /vagrant/.htconfig.php + $> rm /vagrant/config/.htconfig.php to make sure that you can start from scratch with another "vagrant up". diff --git a/doc/de/FAQ.md b/doc/de/FAQ.md index b52aa3d396..773cf7d41b 100644 --- a/doc/de/FAQ.md +++ b/doc/de/FAQ.md @@ -199,7 +199,7 @@ Admin Ja, das ist möglich. Es ist allerdings nicht möglich, eine Datenbank durch zwei Domains zu nutzen. -Solange Du Deine .htconfig.php allerdings so einrichtest, dass das System nicht versucht, eine Installation durchzuführen, kannst Du die richtige Config-Datei in include/$hostname/.htconfig.php hinterlegen. +Solange Du Deine .htconfig.php allerdings so einrichtest, dass das System nicht versucht, eine Installation durchzuführen, kannst Du die richtige Config-Datei in include/$hostname/config/.htconfig.php hinterlegen. Alle Cache-Aspekte und der Zugriffsschutz können pro Instanz konfiguriert werden. diff --git a/doc/de/Install.md b/doc/de/Install.md index 1842306c58..5e82fd75bb 100644 --- a/doc/de/Install.md +++ b/doc/de/Install.md @@ -78,7 +78,7 @@ Friendica benötigt die Berechtigungen um neue Felder in dieser Datenbank zu ert 5. *Wenn* die automatisierte Installation aus irgendeinem Grund fehlschlägt, dann prüfe das Folgende: - - ".htconfig.php" existiert ... wenn nicht, bearbeite die „htconfig.php“ und ändere die Systemeinstellungen. Benenne sie um in „.htconfig.php" + - "config/.htconfig.php" existiert ... wenn nicht, bearbeite die „config/htconfig.php“ und ändere die Systemeinstellungen. Benenne sie um in „.htconfig.php" “ - die Datenbank beinhaltet Daten. ... wenn nicht, importiere den Inhalt der Datei "database.sql" mit phpmyadmin oder per mysql-Kommandozeile. @@ -106,5 +106,5 @@ Es werden schlimme Dinge geschehen. Sei es nun ein Hardwareversage oder eine korrumpierte Datenbank. Deshalb solltest du dir nachdem die Installation deines Friendica Knotens abgeschlossen ist einen Backup Plan erstellen. -Die wichtigste Datei ist die `.htconfig.php` im Stammverzeichnis deiner Friendica Installation. +Die wichtigste Datei ist die `.htconfig.php` im `config/`-Verzeicnhis deiner Friendica Installation. Und da alle Daten in der Datenbank gespeichert werden, solltest du einen nicht all zu alten Dump der Friendica Datenbank zur Hand haben, solltest du deinen Knoten wieder herstellen müssen. diff --git a/include/dba.php b/include/dba.php index 586fc092fb..2f0e431f8a 100644 --- a/include/dba.php +++ b/include/dba.php @@ -92,6 +92,7 @@ class dba { // No suitable SQL driver was found. if (!self::$connected) { + self::$driver = null; self::$db = null; } $a->save_timestamp($stamp1, "network"); diff --git a/index.php b/index.php index e3ab16469b..8bfc3a1f29 100644 --- a/index.php +++ b/index.php @@ -37,11 +37,11 @@ $a->backend = false; * installation mode. */ -$install = ((file_exists('.htconfig.php') && filesize('.htconfig.php')) ? false : true); +$install = ((file_exists('config/.htconfig.php') && filesize('config/.htconfig.php')) ? false : true); // Only load config if found, don't surpress errors if (!$install) { - include ".htconfig.php"; + include "config/.htconfig.php"; } /** diff --git a/mod/install.php b/mod/install.php index eb740c7b64..49d03abcd3 100644 --- a/mod/install.php +++ b/mod/install.php @@ -5,11 +5,9 @@ use Friendica\App; use Friendica\Core\L10n; +use Friendica\Core\Install; use Friendica\Core\System; use Friendica\Database\DBM; -use Friendica\Database\DBStructure; -use Friendica\Object\Image; -use Friendica\Util\Network; use Friendica\Util\Temporal; $install_wizard_pass = 1; @@ -72,34 +70,7 @@ function install_post(App $a) { // connect to db dba::connect($dbhost, $dbuser, $dbpass, $dbdata, true); - $tpl = get_markup_template('htconfig.tpl'); - $txt = replace_macros($tpl,[ - '$dbhost' => $dbhost, - '$dbuser' => $dbuser, - '$dbpass' => $dbpass, - '$dbdata' => $dbdata, - '$timezone' => $timezone, - '$language' => $language, - '$urlpath' => $urlpath, - '$phpath' => $phpath, - '$adminmail' => $adminmail, - '$rino' => $rino - ]); - - - $result = file_put_contents('.htconfig.php', $txt); - if (! $result) { - $a->data['txt'] = $txt; - } - - $errors = load_database(); - - - if ($errors) { - $a->data['db_failed'] = $errors; - } else { - $a->data['db_installed'] = true; - } + Install::install($urlpath, $dbhost, $dbuser, $dbpass, $dbdata, $phpath, $timezone, $language, $adminmail, $rino); return; break; @@ -167,37 +138,11 @@ function install_content(App $a) { switch ($install_wizard_pass) { case 1: { // System check - - $checks = []; - - check_funcs($checks); - - check_imagik($checks); - - check_htconfig($checks); - - check_smarty3($checks); - - check_keys($checks); - if (x($_POST, 'phpath')) { $phpath = notags(trim($_POST['phpath'])); } - check_php($phpath, $checks); - - check_htaccess($checks); - - /// @TODO Maybe move this out? - function check_passed($v, $c) { - if ($c['required']) { - $v = $v && $c['status']; - } - return $v; - } - $checkspassed = array_reduce($checks, "check_passed", true); - - + list($checks, $checkspassed) = Install::check($phpath); $tpl = get_markup_template('install_checks.tpl'); $o .= replace_macros($tpl, [ @@ -296,241 +241,9 @@ function install_content(App $a) { } } -/** - * checks : array passed to template - * title : string - * status : boolean - * required : boolean - * help : string optional - */ -function check_add(&$checks, $title, $status, $required, $help) { - $checks[] = [ - 'title' => $title, - 'status' => $status, - 'required' => $required, - 'help' => $help, - ]; -} - -function check_php(&$phpath, &$checks) { - $passed = $passed2 = $passed3 = false; - if (strlen($phpath)) { - $passed = file_exists($phpath); - } else { - $phpath = trim(shell_exec('which php')); - $passed = strlen($phpath); - } - $help = ""; - if (!$passed) { - $help .= L10n::t('Could not find a command line version of PHP in the web server PATH.'). EOL; - $help .= L10n::t("If you don't have a command line version of PHP installed on your server, you will not be able to run the background processing. See 'Setup the worker'") . EOL; - $help .= EOL . EOL; - $tpl = get_markup_template('field_input.tpl'); - $help .= replace_macros($tpl, [ - '$field' => ['phpath', L10n::t('PHP executable path'), $phpath, L10n::t('Enter full path to php executable. You can leave this blank to continue the installation.')], - ]); - $phpath = ""; - } - - check_add($checks, L10n::t('Command line PHP').($passed?" ($phpath)":""), $passed, false, $help); - - if ($passed) { - $cmd = "$phpath -v"; - $result = trim(shell_exec($cmd)); - $passed2 = ( strpos($result, "(cli)") !== false); - list($result) = explode("\n", $result); - $help = ""; - if (!$passed2) { - $help .= L10n::t("PHP executable is not the php cli binary \x28could be cgi-fgci version\x29"). EOL; - $help .= L10n::t('Found PHP version: ')."$result"; - } - check_add($checks, L10n::t('PHP cli binary'), $passed2, true, $help); - } - - - if ($passed2) { - $str = autoname(8); - $cmd = "$phpath testargs.php $str"; - $result = trim(shell_exec($cmd)); - $passed3 = $result == $str; - $help = ""; - if (!$passed3) { - $help .= L10n::t('The command line version of PHP on your system does not have "register_argc_argv" enabled.'). EOL; - $help .= L10n::t('This is required for message delivery to work.'); - } - check_add($checks, L10n::t('PHP register_argc_argv'), $passed3, true, $help); - } - - -} - -function check_keys(&$checks) { - - $help = ''; - - $res = false; - - if (function_exists('openssl_pkey_new')) { - $res = openssl_pkey_new([ - 'digest_alg' => 'sha1', - 'private_key_bits' => 4096, - 'encrypt_key' => false - ]); - } - - // Get private key - - if (! $res) { - $help .= L10n::t('Error: the "openssl_pkey_new" function on this system is not able to generate encryption keys'). EOL; - $help .= L10n::t('If running under Windows, please see "http://www.php.net/manual/en/openssl.installation.php".'); - } - check_add($checks, L10n::t('Generate encryption keys'), $res, true, $help); - -} - - -function check_funcs(&$checks) { - $ck_funcs = []; - check_add($ck_funcs, L10n::t('libCurl PHP module'), true, true, ""); - check_add($ck_funcs, L10n::t('GD graphics PHP module'), true, true, ""); - check_add($ck_funcs, L10n::t('OpenSSL PHP module'), true, true, ""); - check_add($ck_funcs, L10n::t('PDO or MySQLi PHP module'), true, true, ""); - check_add($ck_funcs, L10n::t('mb_string PHP module'), true, true, ""); - check_add($ck_funcs, L10n::t('XML PHP module'), true, true, ""); - check_add($ck_funcs, L10n::t('iconv PHP module'), true, true, ""); - check_add($ck_funcs, L10n::t('POSIX PHP module'), true, true, ""); - - if (function_exists('apache_get_modules')) { - if (! in_array('mod_rewrite',apache_get_modules())) { - check_add($ck_funcs, L10n::t('Apache mod_rewrite module'), false, true, L10n::t('Error: Apache webserver mod-rewrite module is required but not installed.')); - } else { - check_add($ck_funcs, L10n::t('Apache mod_rewrite module'), true, true, ""); - } - } - - if (! function_exists('curl_init')) { - $ck_funcs[0]['status'] = false; - $ck_funcs[0]['help'] = L10n::t('Error: libCURL PHP module required but not installed.'); - } - if (! function_exists('imagecreatefromjpeg')) { - $ck_funcs[1]['status'] = false; - $ck_funcs[1]['help'] = L10n::t('Error: GD graphics PHP module with JPEG support required but not installed.'); - } - if (! function_exists('openssl_public_encrypt')) { - $ck_funcs[2]['status'] = false; - $ck_funcs[2]['help'] = L10n::t('Error: openssl PHP module required but not installed.'); - } - if (! function_exists('mysqli_connect') && !class_exists('pdo')) { - $ck_funcs[3]['status'] = false; - $ck_funcs[3]['help'] = L10n::t('Error: PDO or MySQLi PHP module required but not installed.'); - } - if (!function_exists('mysqli_connect') && class_exists('pdo') && !in_array('mysql', PDO::getAvailableDrivers())) { - $ck_funcs[3]['status'] = false; - $ck_funcs[3]['help'] = L10n::t('Error: The MySQL driver for PDO is not installed.'); - } - if (! function_exists('mb_strlen')) { - $ck_funcs[4]['status'] = false; - $ck_funcs[4]['help'] = L10n::t('Error: mb_string PHP module required but not installed.'); - } - if (! function_exists('iconv_strlen')) { - $ck_funcs[6]['status'] = false; - $ck_funcs[6]['help'] = L10n::t('Error: iconv PHP module required but not installed.'); - } - if (! function_exists('posix_kill')) { - $ck_funcs[7]['status'] = false; - $ck_funcs[7]['help'] = L10n::t('Error: POSIX PHP module required but not installed.'); - } - - $checks = array_merge($checks, $ck_funcs); - - // check for XML DOM Documents being able to be generated - try { - $xml = new DOMDocument(); - } catch (Exception $e) { - $ck_funcs[5]['status'] = false; - $ck_funcs[5]['help'] = L10n::t('Error, XML PHP module required but not installed.'); - } -} - - -function check_htconfig(&$checks) { - $status = true; - $help = ""; - if ((file_exists('.htconfig.php') && !is_writable('.htconfig.php')) || - (!file_exists('.htconfig.php') && !is_writable('.'))) { - - $status = false; - $help = L10n::t('The web installer needs to be able to create a file called ".htconfig.php" in the top folder of your web server and it is unable to do so.') .EOL; - $help .= L10n::t('This is most often a permission setting, as the web server may not be able to write files in your folder - even if you can.').EOL; - $help .= L10n::t('At the end of this procedure, we will give you a text to save in a file named .htconfig.php in your Friendica top folder.').EOL; - $help .= L10n::t('You can alternatively skip this procedure and perform a manual installation. Please see the file "INSTALL.txt" for instructions.').EOL; - } - - check_add($checks, L10n::t('.htconfig.php is writable'), $status, false, $help); - -} - -function check_smarty3(&$checks) { - $status = true; - $help = ""; - if (!is_writable('view/smarty3')) { - - $status = false; - $help = L10n::t('Friendica uses the Smarty3 template engine to render its web views. Smarty3 compiles templates to PHP to speed up rendering.') .EOL; - $help .= L10n::t('In order to store these compiled templates, the web server needs to have write access to the directory view/smarty3/ under the Friendica top level folder.').EOL; - $help .= L10n::t("Please ensure that the user that your web server runs as \x28e.g. www-data\x29 has write access to this folder.").EOL; - $help .= L10n::t("Note: as a security measure, you should give the web server write access to view/smarty3/ only--not the template files \x28.tpl\x29 that it contains.").EOL; - } - - check_add($checks, L10n::t('view/smarty3 is writable'), $status, true, $help); - -} - -function check_htaccess(&$checks) { - $status = true; - $help = ""; - if (function_exists('curl_init')) { - $test = Network::fetchUrl(System::baseUrl()."/install/testrewrite"); - - if ($test != "ok") { - $test = Network::fetchUrl(normalise_link(System::baseUrl()."/install/testrewrite")); - } - - if ($test != "ok") { - $status = false; - $help = L10n::t('Url rewrite in .htaccess is not working. Check your server configuration.'); - } - check_add($checks, L10n::t('Url rewrite is working'), $status, true, $help); - } else { - // cannot check modrewrite if libcurl is not installed - /// @TODO Maybe issue warning here? - } -} - -function check_imagik(&$checks) { - $imagick = false; - $gif = false; - - if (class_exists('Imagick')) { - $imagick = true; - $supported = Image::supportedTypes(); - if (array_key_exists('image/gif', $supported)) { - $gif = true; - } - } - if ($imagick == false) { - check_add($checks, L10n::t('ImageMagick PHP extension is not installed'), $imagick, false, ""); - } else { - check_add($checks, L10n::t('ImageMagick PHP extension is installed'), $imagick, false, ""); - if ($imagick) { - check_add($checks, L10n::t('ImageMagick supports GIF'), $gif, false, ""); - } - } -} - function manual_config(App $a) { $data = htmlentities($a->data['txt'],ENT_COMPAT, 'UTF-8'); - $o = L10n::t('The database configuration file ".htconfig.php" could not be written. Please use the enclosed text to create a configuration file in your web server root.'); + $o = L10n::t('The database configuration file ".htconfig.php" could not be written. Please use the enclosed text to create a configuration file in your web server "config/".'); $o .= ""; return $o; } @@ -544,12 +257,6 @@ function load_database_rem($v, $i) { } } -function load_database() { - $errors = DBStructure::update(false, true, true); - - return $errors; -} - function what_next() { $baseurl = System::baseUrl(); return diff --git a/src/Core/Console/Config.php b/src/Core/Console/Config.php index 306e1c275e..fa7410af23 100644 --- a/src/Core/Console/Config.php +++ b/src/Core/Console/Config.php @@ -92,7 +92,7 @@ HELP; throw new CommandArgsException('Too many arguments'); } - require_once '.htconfig.php'; + require_once 'config/.htconfig.php'; $result = dba::connect($db_host, $db_user, $db_pass, $db_data); unset($db_host, $db_user, $db_pass, $db_data); diff --git a/src/Core/Console/DatabaseStructure.php b/src/Core/Console/DatabaseStructure.php index eb4c6df998..0d039a844e 100644 --- a/src/Core/Console/DatabaseStructure.php +++ b/src/Core/Console/DatabaseStructure.php @@ -56,7 +56,7 @@ HELP; throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments'); } - require_once '.htconfig.php'; + require_once 'config/.htconfig.php'; $result = \dba::connect($db_host, $db_user, $db_pass, $db_data); unset($db_host, $db_user, $db_pass, $db_data); diff --git a/src/Core/Console/GlobalCommunityBlock.php b/src/Core/Console/GlobalCommunityBlock.php index 26c5d13131..6c2453307e 100644 --- a/src/Core/Console/GlobalCommunityBlock.php +++ b/src/Core/Console/GlobalCommunityBlock.php @@ -56,7 +56,7 @@ HELP; throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments'); } - require_once '.htconfig.php'; + require_once 'config/.htconfig.php'; $result = \dba::connect($db_host, $db_user, $db_pass, $db_data); unset($db_host, $db_user, $db_pass, $db_data); diff --git a/src/Core/Console/GlobalCommunitySilence.php b/src/Core/Console/GlobalCommunitySilence.php index 72d5a4f881..a1fba2dc79 100644 --- a/src/Core/Console/GlobalCommunitySilence.php +++ b/src/Core/Console/GlobalCommunitySilence.php @@ -64,7 +64,7 @@ HELP; throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments'); } - require_once '.htconfig.php'; + require_once 'config/.htconfig.php'; $result = \dba::connect($db_host, $db_user, $db_pass, $db_data); unset($db_host, $db_user, $db_pass, $db_data); diff --git a/src/Core/Console/Maintenance.php b/src/Core/Console/Maintenance.php index 6638e4bfe1..7627adeae6 100644 --- a/src/Core/Console/Maintenance.php +++ b/src/Core/Console/Maintenance.php @@ -64,7 +64,7 @@ HELP; throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments'); } - require_once '.htconfig.php'; + require_once 'config/.htconfig.php'; $result = \dba::connect($db_host, $db_user, $db_pass, $db_data); unset($db_host, $db_user, $db_pass, $db_data); diff --git a/src/Core/Console/NewPassword.php b/src/Core/Console/NewPassword.php index d44286d28f..49cf2e984e 100644 --- a/src/Core/Console/NewPassword.php +++ b/src/Core/Console/NewPassword.php @@ -58,7 +58,7 @@ HELP; throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments'); } - require_once '.htconfig.php'; + require_once 'config/.htconfig.php'; $result = \dba::connect($db_host, $db_user, $db_pass, $db_data); unset($db_host, $db_user, $db_pass, $db_data); diff --git a/src/Core/Install.php b/src/Core/Install.php new file mode 100644 index 0000000000..791377fc8e --- /dev/null +++ b/src/Core/Install.php @@ -0,0 +1,318 @@ + $dbhost, + '$dbuser' => $dbuser, + '$dbpass' => $dbpass, + '$dbdata' => $dbdata, + '$timezone' => $timezone, + '$language' => $language, + '$urlpath' => $urlpath, + '$phpath' => $phpath, + '$adminmail' => $adminmail, + '$rino' => $rino + ]); + + + $result = file_put_contents('config/.htconfig.php', $txt); + if (! $result) { + self::getApp()->data['txt'] = $txt; + } + + $errors = self::loadDatabase(); + + if ($errors) { + self::getApp()->data['db_failed'] = $errors; + } else { + self::getApp()->data['db_installed'] = true; + } + } + + /** + * checks : array passed to template + * title : string + * status : boolean + * required : boolean + * help : string optional + */ + private static function addCheck(&$checks, $title, $status, $required, $help) { + $checks[] = [ + 'title' => $title, + 'status' => $status, + 'required' => $required, + 'help' => $help, + ]; + } + + private static function checkPHP(&$phpath, &$checks) { + $passed = $passed2 = $passed3 = false; + if (strlen($phpath)) { + $passed = file_exists($phpath); + } else { + $phpath = trim(shell_exec('which php')); + $passed = strlen($phpath); + } + $help = ""; + if (!$passed) { + $help .= L10n::t('Could not find a command line version of PHP in the web server PATH.'). EOL; + $help .= L10n::t("If you don't have a command line version of PHP installed on your server, you will not be able to run the background processing. See 'Setup the worker'") . EOL; + $help .= EOL . EOL; + $tpl = get_markup_template('field_input.tpl'); + $help .= replace_macros($tpl, [ + '$field' => ['phpath', L10n::t('PHP executable path'), $phpath, L10n::t('Enter full path to php executable. You can leave this blank to continue the installation.')], + ]); + $phpath = ""; + } + + self::addCheck($checks, L10n::t('Command line PHP').($passed?" ($phpath)":""), $passed, false, $help); + + if ($passed) { + $cmd = "$phpath -v"; + $result = trim(shell_exec($cmd)); + $passed2 = ( strpos($result, "(cli)") !== false); + list($result) = explode("\n", $result); + $help = ""; + if (!$passed2) { + $help .= L10n::t("PHP executable is not the php cli binary \x28could be cgi-fgci version\x29"). EOL; + $help .= L10n::t('Found PHP version: ')."$result"; + } + self::addCheck($checks, L10n::t('PHP cli binary'), $passed2, true, $help); + } + + + if ($passed2) { + $str = autoname(8); + $cmd = "$phpath testargs.php $str"; + $result = trim(shell_exec($cmd)); + $passed3 = $result == $str; + $help = ""; + if (!$passed3) { + $help .= L10n::t('The command line version of PHP on your system does not have "register_argc_argv" enabled.'). EOL; + $help .= L10n::t('This is required for message delivery to work.'); + } + self::addCheck($checks, L10n::t('PHP register_argc_argv'), $passed3, true, $help); + } + + + } + + private static function checkKeys(&$checks) { + + $help = ''; + + $res = false; + + if (function_exists('openssl_pkey_new')) { + $res = openssl_pkey_new([ + 'digest_alg' => 'sha1', + 'private_key_bits' => 4096, + 'encrypt_key' => false + ]); + } + + // Get private key + + if (! $res) { + $help .= L10n::t('Error: the "openssl_pkey_new" function on this system is not able to generate encryption keys'). EOL; + $help .= L10n::t('If running under Windows, please see "http://www.php.net/manual/en/openssl.installation.php".'); + } + self::addCheck($checks, L10n::t('Generate encryption keys'), $res, true, $help); + + } + + + private static function checkFunctions(&$checks) { + $ck_funcs = []; + self::addCheck($ck_funcs, L10n::t('libCurl PHP module'), true, true, ""); + self::addCheck($ck_funcs, L10n::t('GD graphics PHP module'), true, true, ""); + self::addCheck($ck_funcs, L10n::t('OpenSSL PHP module'), true, true, ""); + self::addCheck($ck_funcs, L10n::t('PDO or MySQLi PHP module'), true, true, ""); + self::addCheck($ck_funcs, L10n::t('mb_string PHP module'), true, true, ""); + self::addCheck($ck_funcs, L10n::t('XML PHP module'), true, true, ""); + self::addCheck($ck_funcs, L10n::t('iconv PHP module'), true, true, ""); + self::addCheck($ck_funcs, L10n::t('POSIX PHP module'), true, true, ""); + + if (function_exists('apache_get_modules')) { + if (! in_array('mod_rewrite',apache_get_modules())) { + self::addCheck($ck_funcs, L10n::t('Apache mod_rewrite module'), false, true, L10n::t('Error: Apache webserver mod-rewrite module is required but not installed.')); + } else { + self::addCheck($ck_funcs, L10n::t('Apache mod_rewrite module'), true, true, ""); + } + } + + if (! function_exists('curl_init')) { + $ck_funcs[0]['status'] = false; + $ck_funcs[0]['help'] = L10n::t('Error: libCURL PHP module required but not installed.'); + } + if (! function_exists('imagecreatefromjpeg')) { + $ck_funcs[1]['status'] = false; + $ck_funcs[1]['help'] = L10n::t('Error: GD graphics PHP module with JPEG support required but not installed.'); + } + if (! function_exists('openssl_public_encrypt')) { + $ck_funcs[2]['status'] = false; + $ck_funcs[2]['help'] = L10n::t('Error: openssl PHP module required but not installed.'); + } + if (! function_exists('mysqli_connect') && !class_exists('pdo')) { + $ck_funcs[3]['status'] = false; + $ck_funcs[3]['help'] = L10n::t('Error: PDO or MySQLi PHP module required but not installed.'); + } + if (!function_exists('mysqli_connect') && class_exists('pdo') && !in_array('mysql', PDO::getAvailableDrivers())) { + $ck_funcs[3]['status'] = false; + $ck_funcs[3]['help'] = L10n::t('Error: The MySQL driver for PDO is not installed.'); + } + if (! function_exists('mb_strlen')) { + $ck_funcs[4]['status'] = false; + $ck_funcs[4]['help'] = L10n::t('Error: mb_string PHP module required but not installed.'); + } + if (! function_exists('iconv_strlen')) { + $ck_funcs[6]['status'] = false; + $ck_funcs[6]['help'] = L10n::t('Error: iconv PHP module required but not installed.'); + } + if (! function_exists('posix_kill')) { + $ck_funcs[7]['status'] = false; + $ck_funcs[7]['help'] = L10n::t('Error: POSIX PHP module required but not installed.'); + } + + $checks = array_merge($checks, $ck_funcs); + + // check for XML DOM Documents being able to be generated + try { + $xml = new DOMDocument(); + } catch (Exception $e) { + $ck_funcs[5]['status'] = false; + $ck_funcs[5]['help'] = L10n::t('Error, XML PHP module required but not installed.'); + } + } + + + private static function checkHtConfig(&$checks) { + $status = true; + $help = ""; + if ((file_exists('config/.htconfig.php') && !is_writable('.htconfig.php')) || + (!file_exists('config/.htconfig.php') && !is_writable('.'))) { + + $status = false; + $help = L10n::t('The web installer needs to be able to create a file called ".htconfig.php" in the "config/" folder of your web server and it is unable to do so.') .EOL; + $help .= L10n::t('This is most often a permission setting, as the web server may not be able to write files in your folder - even if you can.').EOL; + $help .= L10n::t('At the end of this procedure, we will give you a text to save in a file named .htconfig.php in your Friendica "config/" folder.').EOL; + $help .= L10n::t('You can alternatively skip this procedure and perform a manual installation. Please see the file "INSTALL.txt" for instructions.').EOL; + } + + self::addCheck($checks, L10n::t('config/.htconfig.php is writable'), $status, false, $help); + + } + + private static function checkSmarty3(&$checks) { + $status = true; + $help = ""; + if (!is_writable('view/smarty3')) { + + $status = false; + $help = L10n::t('Friendica uses the Smarty3 template engine to render its web views. Smarty3 compiles templates to PHP to speed up rendering.') .EOL; + $help .= L10n::t('In order to store these compiled templates, the web server needs to have write access to the directory view/smarty3/ under the Friendica top level folder.').EOL; + $help .= L10n::t("Please ensure that the user that your web server runs as \x28e.g. www-data\x29 has write access to this folder.").EOL; + $help .= L10n::t("Note: as a security measure, you should give the web server write access to view/smarty3/ only--not the template files \x28.tpl\x29 that it contains.").EOL; + } + + self::addCheck($checks, L10n::t('view/smarty3 is writable'), $status, true, $help); + + } + + private static function checkHtAccess(&$checks) { + $status = true; + $help = ""; + if (function_exists('curl_init')) { + $test = Network::fetchUrl(System::baseUrl()."/install/testrewrite"); + + if ($test != "ok") { + $test = Network::fetchUrl(normalise_link(System::baseUrl()."/install/testrewrite")); + } + + if ($test != "ok") { + $status = false; + $help = L10n::t('Url rewrite in .htaccess is not working. Check your server configuration.'); + } + self::addCheck($checks, L10n::t('Url rewrite is working'), $status, true, $help); + } else { + // cannot check modrewrite if libcurl is not installed + /// @TODO Maybe issue warning here? + } + } + + private static function checkImagik(&$checks) { + $imagick = false; + $gif = false; + + if (class_exists('Imagick')) { + $imagick = true; + $supported = Image::supportedTypes(); + if (array_key_exists('image/gif', $supported)) { + $gif = true; + } + } + if ($imagick == false) { + self::addCheck($checks, L10n::t('ImageMagick PHP extension is not installed'), $imagick, false, ""); + } else { + self::addCheck($checks, L10n::t('ImageMagick PHP extension is installed'), $imagick, false, ""); + if ($imagick) { + self::addCheck($checks, L10n::t('ImageMagick supports GIF'), $gif, false, ""); + } + } + } + + private static function loadDatabase() { + $errors = DBStructure::update(false, true, true); + + return $errors; + } +} \ No newline at end of file diff --git a/util/Doxyfile b/util/Doxyfile index 373d172558..9326a13235 100644 --- a/util/Doxyfile +++ b/util/Doxyfile @@ -2,7 +2,7 @@ INPUT = README.md index.php boot.php testargs.php update.php mod/ object/ includ RECURSIVE = YES PROJECT_NAME = "Friendica" PROJECT_LOGO = images/friendica-64.jpg -EXCLUDE = .htconfig.php library/ doc/ .git/ log/ util/zotsh/easywebdav/ addon/ report/ privacy_image_cache/ photo/ proxy/ local/ +EXCLUDE = config/.htconfig.php library/ doc/ .git/ log/ util/zotsh/easywebdav/ addon/ report/ privacy_image_cache/ photo/ proxy/ local/ EXCLUDE_PATTERNS = *smarty3* *strings.php*.log *.out *test* OUTPUT_DIRECTORY = doc GENERATE_HTML = YES From 54c3efccabd8e3902fa1cc799b4bb983de13c2a2 Mon Sep 17 00:00:00 2001 From: rabuzarus Date: Sat, 21 Apr 2018 14:27:57 +0200 Subject: [PATCH 008/123] frio - don't show the "insert image" button in modals (because it doesn't work at the current state) --- view/theme/frio/css/style.css | 5 ++++- view/theme/frio/templates/comment_item.tpl | 2 +- view/theme/frio/templates/event_form.tpl | 4 ++-- view/theme/frio/templates/prv_message.tpl | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/view/theme/frio/css/style.css b/view/theme/frio/css/style.css index 6f2a71ca44..4295ecec62 100644 --- a/view/theme/frio/css/style.css +++ b/view/theme/frio/css/style.css @@ -2409,10 +2409,13 @@ ul li:hover .contact-wrapper .contact-action-link:hover { height: 48px; width: 48px; } - #prvmail-end { clear:both; } +#modal #prvmail-text-edit-bb .bb-img { + display: none; +} + /* photos */ .photo-album-actions { margin-bottom: 10px; diff --git a/view/theme/frio/templates/comment_item.tpl b/view/theme/frio/templates/comment_item.tpl index 8729f487f0..8d90394d58 100644 --- a/view/theme/frio/templates/comment_item.tpl +++ b/view/theme/frio/templates/comment_item.tpl @@ -33,7 +33,7 @@ {{/if}}