diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/bbcode.php | 19 | ||||
-rwxr-xr-x | include/items.php | 19 | ||||
-rw-r--r-- | include/markdown.php | 2 | ||||
-rw-r--r-- | include/network.php | 110 | ||||
-rw-r--r-- | include/photo/photo_driver.php | 13 | ||||
-rw-r--r-- | include/queue_fn.php | 4 | ||||
-rw-r--r-- | include/text.php | 11 | ||||
-rw-r--r-- | include/zot.php | 69 |
8 files changed, 93 insertions, 154 deletions
diff --git a/include/bbcode.php b/include/bbcode.php index c5d6ef998..7531bd774 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -326,22 +326,11 @@ function bb_ShareAttributes($match) { $auth = is_matrix_url($profile); } - // message_id is never used, do we still need it? - $message_id = ""; - preg_match("/message_id='(.*?)'/ism", $attributes, $matches); - if ($matches[1] != "") - $message_id = $matches[1]; - - if(! $message_id) { - preg_match("/guid='(.*?)'/ism", $attributes, $matches); - if ($matches[1] != "") - $message_id = $matches[1]; - } - + $rnd = mt_rand(); $reldate = '<span class="autotime" title="' . datetime_convert('UTC', date_default_timezone_get(), $posted, 'c') . '" >' . datetime_convert('UTC', date_default_timezone_get(), $posted, 'r') . '</span>'; - $headline = '<div class="shared_container"> <div class="shared_header">'; + $headline = '<div id="shared_container_' . $rnd . '" class="shared_container"> <div id="shared_header_' . $rnd . '" class="shared_header">'; if ($avatar != "") $headline .= '<a href="' . (($auth) ? zid($profile) : $profile) . '" ><img src="' . $avatar . '" alt="' . $author . '" height="32" width="32" /></a>'; @@ -363,7 +352,7 @@ function bb_ShareAttributes($match) { $headline .= '<span>' . $fmt . '</span></div>'; - $text = $headline . '<div class="reshared-content">' . trim($match[2]) . '</div></div>'; + $text = $headline . '<div id="reshared-content-' . $rnd . '" class="reshared-content">' . trim($match[2]) . '</div></div>'; return $text; } @@ -1021,7 +1010,7 @@ function bbcode($Text, $options = []) { } // Check for colored text if (strpos($Text,'[/hl]') !== false) { - $Text = preg_replace("(\[hl\](.*?)\[\/hl\])ism", "<span style=\"background-color: yellow;\">$1</span>", $Text); + $Text = preg_replace("(\[hl\](.*?)\[\/hl\])ism", "<span class=\"default-highlight\">$1</span>", $Text); $Text = preg_replace("(\[hl=(.*?)\](.*?)\[\/hl\])ism", "<span style=\"background-color: $1;\">$2</span>", $Text); } diff --git a/include/items.php b/include/items.php index 02d31fcb5..e5f2be003 100755 --- a/include/items.php +++ b/include/items.php @@ -95,9 +95,24 @@ function collect_recipients($item, &$private_envelope,$include_groups = true) { //$sys = get_sys_channel(); if(array_key_exists('public_policy',$item) && $item['public_policy'] !== 'self') { - $r = q("select abook_xchan, xchan_network from abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d and abook_self = 0 and abook_pending = 0 and abook_archived = 0 ", + + $hookinfo = [ + 'recipients' => [], + 'item' => $item, + 'private_envelope' => $private_envelope, + 'include_groups' => $include_groups + ]; + + call_hooks('collect_public_recipients',$hookinfo); + + if ($hookinfo['recipients']) { + $r = $hookinfo['recipients']; + } else { + $r = q("select abook_xchan, xchan_network from abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d and abook_self = 0 and abook_pending = 0 and abook_archived = 0 ", intval($item['uid']) - ); + ); + } + if($r) { // filter out restrictive public_policy settings from remote networks diff --git a/include/markdown.php b/include/markdown.php index 64f0a0854..2513a7d77 100644 --- a/include/markdown.php +++ b/include/markdown.php @@ -91,8 +91,6 @@ function markdown_to_bb($s, $use_zrl = false, $options = []) { // remove duplicate adjacent code tags $s = preg_replace("/(\[code\])+(.*?)(\[\/code\])+/ism","[code]$2[/code]", $s); - // Don't show link to full picture (until it is fixed) - $s = scale_external_images($s, false); /** * @hooks markdown_to_bb diff --git a/include/network.php b/include/network.php index df59a30e6..8ac71011e 100644 --- a/include/network.php +++ b/include/network.php @@ -120,13 +120,8 @@ function z_fetch_url($url, $binary = false, $redirects = 0, $opts = array()) { @curl_setopt($ch, CURLOPT_USERPWD, $opts['http_auth']); } - if(array_key_exists('http_version',$opts)) { + if(array_key_exists('http_version',$opts)) @curl_setopt($ch,CURLOPT_HTTP_VERSION,$opts['http_version']); - } - else { - @curl_setopt($ch,CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_1); - } - if(x($opts,'cookiejar')) @curl_setopt($ch, CURLOPT_COOKIEJAR, $opts['cookiejar']); @@ -165,7 +160,7 @@ function z_fetch_url($url, $binary = false, $redirects = 0, $opts = array()) { // Pull out multiple headers, e.g. proxy and continuation headers // allow for HTTP/2.x without fixing code - while(preg_match('/^HTTP\/[1-3].+? [1-5][0-9][0-9]/',$base)) { + while(preg_match('/^HTTP\/[1-3](\.\d)? [1-5][0-9][0-9]/',$base)) { $chunk = substr($base,0,strpos($base,"\r\n\r\n")+4); $header .= $chunk; $base = substr($base,strlen($chunk)); @@ -298,12 +293,8 @@ function z_post_url($url, $params, $redirects = 0, $opts = array()) { @curl_setopt($ch, CURLOPT_USERPWD, $opts['http_auth']); } - if(array_key_exists('http_version',$opts)) { + if(array_key_exists('http_version',$opts)) @curl_setopt($ch,CURLOPT_HTTP_VERSION,$opts['http_version']); - } - else { - @curl_setopt($ch,CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_1); - } if(x($opts,'cookiejar')) @curl_setopt($ch, CURLOPT_COOKIEJAR, $opts['cookiejar']); @@ -338,7 +329,7 @@ function z_post_url($url, $params, $redirects = 0, $opts = array()) { // Pull out multiple headers, e.g. proxy and continuation headers // allow for HTTP/2.x without fixing code - while(preg_match('/^HTTP\/[1-3].+? [1-5][0-9][0-9]/',$base)) { + while(preg_match('/^HTTP\/[1-3](\.\d)? [1-5][0-9][0-9]/',$base)) { $chunk = substr($base,0,strpos($base,"\r\n\r\n")+4); $header .= $chunk; $base = substr($base,strlen($chunk)); @@ -710,99 +701,6 @@ function sxml2array ( $xmlObject, $out = array () ) /** - * @brief Scales an external image. - * - * @param string $s - * @param string $include_link default true - * @param string $scale_replace default false - * @return string - */ -function scale_external_images($s, $include_link = true, $scale_replace = false) { - - // Picture addresses can contain special characters - $s = htmlspecialchars_decode($s, ENT_COMPAT); - - $matches = null; - $c = preg_match_all('/\[([zi])mg(.*?)\](.*?)\[\/[zi]mg\]/ism', $s, $matches, PREG_SET_ORDER); - if($c) { - require_once('include/photo/photo_driver.php'); - - foreach($matches as $mtch) { - logger('data: ' . $mtch[2] . ' ' . $mtch[3]); - - if(substr($mtch[2],0,1) == '=') { - $owidth = intval(substr($mtch[2],1)); - if($owidth > 0 && $owidth < 1024) - continue; - } - - $hostname = str_replace('www.','',substr(z_root(),strpos(z_root(),'://')+3)); - if(stristr($mtch[3],$hostname)) - continue; - - // $scale_replace, if passed, is an array of two elements. The - // first is the name of the full-size image. The second is the - // name of a remote, scaled-down version of the full size image. - // This allows Friendica to display the smaller remote image if - // one exists, while still linking to the full-size image - if($scale_replace) - $scaled = str_replace($scale_replace[0], $scale_replace[1], $mtch[3]); - else - $scaled = $mtch[3]; - - if(! strpbrk(substr($scaled, 0, 1), 'zhfmt')) - continue; - - $i = z_fetch_url($scaled, true); - - $cache = get_config('system', 'itemcache'); - if (($cache != '') and is_dir($cache)) { - $cachefile = $cache . '/' . hash('md5', $scaled); - file_put_contents($cachefile, $i['body']); - } - - // guess mimetype from headers or filename - - $type = guess_image_type($mtch[3], $i['header']); - if(strpos($type, 'image') === false) - continue; - - if($i['success']) { - $ph = photo_factory($i['body'], $type); - - if(! is_object($ph)) - continue; - - if($ph->is_valid()) { - $orig_width = $ph->getWidth(); - $orig_height = $ph->getHeight(); - - if($orig_width > 1024 || $orig_height > 1024) { - $tag = (($match[1] == 'z') ? 'zmg' : 'img'); - $linktag = (($match[1] == 'z') ? 'zrl' : 'url'); - $ph->scaleImage(1024); - $new_width = $ph->getWidth(); - $new_height = $ph->getHeight(); - logger('data: ' . $orig_width . '->' . $new_width . 'w ' . $orig_height . '->' . $new_height . 'h' . ' match: ' . $mtch[0], LOGGER_DEBUG); - $s = str_replace($mtch[0],'[' . $tag . '=' . $new_width . 'x' . $new_height. ']' . $scaled . '[/' . $tag . ']' - . "\n" . (($include_link) - ? '[' . $linktag . '=' . $mtch[3] . ']' . t('view full size') . '[/' . $linktag . ']' . "\n" - : ''),$s); - logger('new string: ' . $s, LOGGER_DEBUG); - } - } - } - } - } - - // replace the special char encoding - - $s = htmlspecialchars($s, ENT_COMPAT, 'UTF-8'); - - return $s; -} - -/** * @brief xml2array() will convert the given XML text to an array in the XML structure. * * Link: http://www.bin-co.com/php/scripts/xml2array/ diff --git a/include/photo/photo_driver.php b/include/photo/photo_driver.php index 9aeb2ef17..5c8ed9bdc 100644 --- a/include/photo/photo_driver.php +++ b/include/photo/photo_driver.php @@ -482,7 +482,6 @@ function guess_image_type($filename, $headers = '') { // logger('Photo: guess_image_type: '.$filename . ($headers?' from curl headers':''), LOGGER_DEBUG); $type = null; if ($headers) { - $hdrs=array(); $h = explode("\n",$headers); foreach ($h as $l) { @@ -490,11 +489,16 @@ function guess_image_type($filename, $headers = '') { $hdrs[strtolower($k)] = $v; } logger('Curl headers: '.var_export($hdrs, true), LOGGER_DEBUG); - if (array_key_exists('content-type', $hdrs)) - $type = $hdrs['content-type']; + if (array_key_exists('content-type', $hdrs)) { + $ph = photo_factory(''); + $types = $ph->supportedTypes(); + + if(array_key_exists($hdrs['content-type'], $types)) + $type = $hdrs['content-type']; + } } - if (is_null($type)){ + if (is_null($type)){ $ignore_imagick = get_config('system', 'ignore_imagick'); // Guessing from extension? Isn't that... dangerous? if(class_exists('Imagick') && file_exists($filename) && is_readable($filename) && !$ignore_imagick) { @@ -638,7 +642,6 @@ function import_xchan_photo($photo,$xchan,$thing = false,$force = false) { $img_str = $result['body']; $type = guess_image_type($photo, $result['header']); $modified = gmdate('Y-m-d H:i:s', (preg_match('/last-modified: (.+) \S+/i', $result['header'], $o) ? strtotime($o[1] . 'Z') : time())); - if(is_null($type)) $photo_failure = true; } diff --git a/include/queue_fn.php b/include/queue_fn.php index f7e2922c6..85f98aaf9 100644 --- a/include/queue_fn.php +++ b/include/queue_fn.php @@ -13,7 +13,7 @@ function update_queue_item($id, $add_priority = 0) { return; - $y = q("select min(outq_created) as earliest from outq where outq_posturl = '%s'", + $y = q("select outq_created as earliest from outq where outq_posturl = '%s' order by earliest limit 1", dbesc($x[0]['outq_posturl']) ); @@ -311,4 +311,4 @@ function queue_deliver($outq, $immediate = false) { return; } -}
\ No newline at end of file +} diff --git a/include/text.php b/include/text.php index bd0d8048d..26cb61977 100644 --- a/include/text.php +++ b/include/text.php @@ -1691,7 +1691,14 @@ function prepare_body(&$item,$attach = false,$opts = false) { if(local_channel() == $item['uid']) $filer = format_filer($item); - $s = sslify($s); + if($s) + $s = sslify($s); + + if($photo) + $photo = sslify($photo); + + if($event) + $event = sslify($event); $prep_arr = array( 'item' => $item, @@ -3305,8 +3312,6 @@ function cleanup_bbcode($body) { $body = preg_replace('/\[\/code\]\s*\[code\]/ism',"\n",$body); - $body = scale_external_images($body, false); - return $body; } diff --git a/include/zot.php b/include/zot.php index 9934dae07..bc2187f91 100644 --- a/include/zot.php +++ b/include/zot.php @@ -1100,6 +1100,8 @@ function zot_process_response($hub, $arr, $outq) { return; } + $dreport = true; + $x = json_decode($arr['body'], true); if(! $x) { @@ -1116,31 +1118,44 @@ function zot_process_response($hub, $arr, $outq) { } if(! (is_array($x['delivery_report']) && count($x['delivery_report']))) { logger('encrypted delivery report could not be decrypted'); - return; + $dreport = false; } } - foreach($x['delivery_report'] as $xx) { - call_hooks('dreport_process',$xx); - if(is_array($xx) && array_key_exists('message_id',$xx) && DReport::is_storable($xx)) { - q("insert into dreport ( dreport_mid, dreport_site, dreport_recip, dreport_name, dreport_result, dreport_time, dreport_xchan ) values ( '%s', '%s','%s','%s','%s','%s','%s' ) ", - dbesc($xx['message_id']), - dbesc($xx['location']), - dbesc($xx['recipient']), - dbesc($xx['name']), - dbesc($xx['status']), - dbesc(datetime_convert('UTC','UTC',$xx['date'])), - dbesc($xx['sender']) - ); + if($dreport) { + foreach($x['delivery_report'] as $xx) { + call_hooks('dreport_process',$xx); + if(is_array($xx) && array_key_exists('message_id',$xx) && DReport::is_storable($xx)) { + + // legacy zot recipients add a space and their name to the xchan. split those if true. + $legacy_recipient = strpos($xx['recipient'], ' '); + if($legacy_recipient !== false) { + $legacy_recipient_parts = explode(' ', $xx['recipient'], 2); + $xx['recipient'] = $legacy_recipient_parts[0]; + $xx['name'] = $legacy_recipient_parts[1]; + } + + q("insert into dreport ( dreport_mid, dreport_site, dreport_recip, dreport_name, dreport_result, dreport_time, dreport_xchan ) values ( '%s', '%s','%s','%s','%s','%s','%s' ) ", + dbesc($xx['message_id']), + dbesc($xx['location']), + dbesc($xx['recipient']), + dbesc($xx['name']), + dbesc($xx['status']), + dbesc(datetime_convert('UTC','UTC',$xx['date'])), + dbesc($xx['sender']) + ); + } } } } - // we have a more descriptive delivery report, so discard the per hub 'queued' report. - q("delete from dreport where dreport_queue = '%s' ", - dbesc($outq['outq_hash']) - ); + if($dreport) { + // we have a more descriptive delivery report, so discard the per hub 'queued' report. + q("delete from dreport where dreport_queue = '%s' ", + dbesc($outq['outq_hash']) + ); + } // update the timestamp for this site @@ -4924,12 +4939,13 @@ function zot_reply_pickup($data) { /* * Everything is good if we made it here, so find all messages that are going to this location - * and send them all. + * and send them all - or a reasonable number if there are a lot so we don't overflow memory. */ - $r = q("select * from outq where outq_posturl = '%s'", + $r = q("select * from outq where outq_posturl = '%s' limit 100", dbesc($data['callback']) ); + if($r) { logger('mod_zot: successful pickup message received from ' . $data['callback'] . ' ' . count($r) . ' message(s) picked up', LOGGER_DEBUG); @@ -4955,6 +4971,19 @@ function zot_reply_pickup($data) { } } + // It's possible that we have more than 100 messages waiting to be sent. + + // See if there are any more messages in the queue. + $x = q("select * from outq where outq_posturl = '%s' order by outq_created limit 1", + dbesc($data['callback']) + ); + + // If so, kick off a new delivery notification for the next batch + if ($x) { + logger("Send additional pickup request.", LOGGER_DEBUG); + queue_deliver($x[0],true); + } + // this is a bit of a hack because we don't have the hubloc_url here, only the callback url. // worst case is we'll end up using aes256cbc if they've got a different post endpoint @@ -4966,6 +4995,8 @@ function zot_reply_pickup($data) { $encrypted = crypto_encapsulate(json_encode($ret),$sitekey,$algorithm); json_return_and_die($encrypted); + // @FIXME: There is a possibility that the transmission will get interrupted + // and fail - in which case this packet of messages will be lost. /* pickup: end */ } |