diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/bbcode.php | 17 | ||||
-rw-r--r-- | include/event.php | 17 | ||||
-rw-r--r-- | include/follow.php | 2 | ||||
-rw-r--r-- | include/help.php | 26 | ||||
-rw-r--r-- | include/import.php | 5 | ||||
-rwxr-xr-x | include/items.php | 19 | ||||
-rw-r--r-- | include/photo/photo_driver.php | 13 | ||||
-rwxr-xr-x | include/plugin.php | 72 | ||||
-rw-r--r-- | include/queue_fn.php | 4 | ||||
-rw-r--r-- | include/text.php | 9 | ||||
-rw-r--r-- | include/zid.php | 6 | ||||
-rw-r--r-- | include/zot.php | 69 |
12 files changed, 156 insertions, 103 deletions
diff --git a/include/bbcode.php b/include/bbcode.php index 817986da0..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; } diff --git a/include/event.php b/include/event.php index a34250e7a..fdb9e1415 100644 --- a/include/event.php +++ b/include/event.php @@ -6,6 +6,10 @@ use Sabre\VObject; +use Ramsey\Uuid\Uuid; +use Ramsey\Uuid\Exception\UnsatisfiedDependencyException; + + require_once('include/bbcode.php'); /** @@ -463,8 +467,13 @@ function event_store_event($arr) { $hash = $arr['external_id']; elseif(array_key_exists('event_hash',$arr)) $hash = $arr['event_hash']; - else - $hash = random_string() . '@' . App::get_hostname(); + else { + try { + $hash = Uuid::uuid4()->toString(); + } catch (UnsatisfiedDependencyException $e) { + $hash = random_string(48); + } + } $r = q("INSERT INTO event ( uid,aid,event_xchan,event_hash,created,edited,dtstart,dtend,summary,description,location,etype, adjust,nofinish, event_status, event_status_date, event_percent, event_repeat, event_sequence, event_priority, event_vdata, allow_cid,allow_gid,deny_cid,deny_gid) @@ -1126,8 +1135,8 @@ function event_store_item($arr, $event) { } if(! $arr['mid']) { - $arr['uuid'] = item_message_id(); - $arr['mid'] = z_root() . '/item/' . $arr['uuid']; + $arr['uuid'] = $event['event_hash']; + $arr['mid'] = z_root() . '/event/' . $event['event_hash']; } $item_arr['aid'] = $z[0]['channel_account_id']; diff --git a/include/follow.php b/include/follow.php index 038e6e9c0..db77a0160 100644 --- a/include/follow.php +++ b/include/follow.php @@ -190,7 +190,7 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) return $result; } - $allowed = (($is_zot || $r[0]['xchan_network'] === 'rss') ? 1 : 0); + $allowed = (($is_zot || in_array($r[0]['xchan_network'],['rss','zot6'])) ? 1 : 0); $x = array('channel_id' => $uid, 'follow_address' => $url, 'xchan' => $r[0], 'allowed' => $allowed, 'singleton' => 0); diff --git a/include/help.php b/include/help.php index f2aa4add3..61dbc7bb3 100644 --- a/include/help.php +++ b/include/help.php @@ -12,12 +12,12 @@ use \Michelf\MarkdownExtra; function get_help_fullpath($path,$suffix=null) { $docroot = (\App::$override_helproot) ? \App::$override_helproot : 'doc/'; - $docroot = (substr($docroot,-1)!='/') ? $docroot .= '/' : $docroot; + $docroot = (substr($docroot,-1)!='/') ? $docroot .= '/' : $docroot; // Determine the language and modify the path accordingly $x = determine_help_language(); $lang = $x['language']; - $url_idx = ($x['from_url'] ? 1 : 0); + // The English translation is at the root of /doc/. Other languages are in // subfolders named by the language code such as "de", "es", etc. if($lang !== 'en') { @@ -53,15 +53,14 @@ function get_help_fullpath($path,$suffix=null) { * @return string|unknown */ function get_help_content($tocpath = false) { - global $lang; $doctype = 'markdown'; $text = ''; $path = (($tocpath !== false) ? $tocpath : ''); - $docroot = (\App::$override_helproot) ? \App::$override_helproot : 'doc/'; - $docroot = (substr($docroot,-1)!='/') ? $docroot .= '/' : $docroot; + $docroot = (\App::$override_helproot) ? \App::$override_helproot : 'doc/'; + $docroot = (substr($docroot,-1)!='/') ? $docroot .= '/' : $docroot; if($tocpath === false && argc() > 1) { $path = ''; @@ -74,7 +73,7 @@ function get_help_content($tocpath = false) { if($path) { - $fullpath = get_help_fullpath($path); + $fullpath = get_help_fullpath($path); $title = basename($path); if(! $tocpath) \App::$page['title'] = t('Help:') . ' ' . ucwords(str_replace('-',' ',notags($title))); @@ -88,10 +87,10 @@ function get_help_content($tocpath = false) { load_doc_file($fullpath . '.md') === '' && load_doc_file($fullpath . '.bb') === '' && load_doc_file($fullpath . '.html') === '' - ) { + ) { $path = $title; } - $fullpath = get_help_fullpath($path); + $fullpath = get_help_fullpath($path); $text = load_doc_file($fullpath . '.md'); if(! $text) { @@ -111,15 +110,15 @@ function get_help_content($tocpath = false) { if($tocpath === false) { if(! $text) { - $path = 'Site'; - $fullpath = get_help_fullpath($path,'.md'); + $path = 'Site'; + $fullpath = get_help_fullpath($path,'.md'); $text = load_doc_file($fullpath . '.md'); \App::$page['title'] = t('Help'); } if(! $text) { $doctype = 'bbcode'; - $path = 'main'; - $fullpath = get_help_fullpath($path,'.md'); + $path = 'main'; + $fullpath = get_help_fullpath($path,'.md'); $text = load_doc_file($fullpath . '.bb'); goaway('/help/about/about'); \App::$page['title'] = t('Help'); @@ -219,7 +218,6 @@ function find_doc_file($s) { */ function search_doc_files($s) { - \App::set_pager_itemspage(60); $pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval(\App::$pager['itemspage']), intval(\App::$pager['start'])); @@ -351,7 +349,7 @@ function store_doc_file($s) { $x = item_store_update($item); } else { - $item['uuid'] = $item_message_id(); + $item['uuid'] = item_message_id(); $item['mid'] = $item['parent_mid'] = z_root() . '/item/' . $item['uuid']; $x = item_store($item); } diff --git a/include/import.php b/include/import.php index 53b21c317..3bd8b4105 100644 --- a/include/import.php +++ b/include/import.php @@ -1035,8 +1035,9 @@ function import_mail($channel, $mails, $sync = false) { if(! $m) continue; - $m['aid'] = $channel['channel_account_id']; - $m['uid'] = $channel['channel_id']; + $m['account_id'] = $channel['channel_account_id']; + $m['channel_id'] = $channel['channel_id']; + $mail_id = mail_store($m); if($sync && $mail_id) { Zotlabs\Daemon\Master::Summon(array('Notifier','single_mail',$mail_id)); 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/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/plugin.php b/include/plugin.php index 7eeb39ce8..ec14fd945 100755 --- a/include/plugin.php +++ b/include/plugin.php @@ -213,8 +213,8 @@ function reload_plugins() { try { $func(); } catch (Exception $e) { - handleerrors_plugin($plugin,"","UNLOAD FAILED (uninstalling) : ".$e->getMessage(),true); - continue; + handleerrors_plugin($pl, '', 'UNLOAD FAILED (uninstalling) : ' . $e->getMessage(),true); + continue; } } if(function_exists($pl . '_load')) { @@ -222,8 +222,8 @@ function reload_plugins() { try { $func(); } catch (Exception $e) { - handleerrors_plugin($plugin,"","LOAD FAILED (uninstalling): ".$e->getMessage(),true); - continue; + handleerrors_plugin($pl, '', 'LOAD FAILED (uninstalling): ' . $e->getMessage(),true); + continue; } } q("UPDATE addon SET tstamp = %d WHERE id = %d", @@ -305,7 +305,7 @@ function plugins_sync() { * @return array */ function visible_plugin_list() { - + $r = q("select * from addon where hidden = 0 order by aname asc"); $x = (($r) ? ids_to_array($r,'aname') : array()); $y = []; @@ -315,7 +315,7 @@ function visible_plugin_list() { $y[] = $xv; } } - } + } return $y; } @@ -456,21 +456,21 @@ function insert_hook($hook, $fn, $version = 0, $priority = 0) { function call_hooks($name, &$data = null) { $a = 0; - if (isset(App::$hooks[$name])) { + if (isset(App::$hooks[$name])) { foreach(App::$hooks[$name] as $hook) { if ($name != 'permit_hook') { // avoid looping $checkhook = [ - 'name'=>$name, - 'hook'=>$hook, - 'data'=>$data, + 'name'=>$name, + 'hook'=>$hook, + 'data'=>$data, // Note: Since PHP uses COPY-ON-WRITE - // for variables, there is no cost to + // for variables, there is no cost to // passing the $data structure (unless // the permit_hook processors change the // information it contains. - 'permit'=>true - ]; + 'permit'=>true + ]; call_hooks('permit_hook',$checkhook); if (!$checkhook['permit']) { continue; @@ -618,7 +618,7 @@ function get_widget_info($widget){ } } - if(! ($widget_found && $f)) + if(! ($widget_found && $f)) return $info; $f = escape_tags($f); @@ -1041,7 +1041,7 @@ function get_intltext_template($s, $root = '') { if (isset(\App::$override_intltext_templates[$testroot][$s]["content"])) { return \App::$override_intltext_templates[$testroot][$s]["content"]; } else { - if (isset(\App::$override_intltext_templates[$testroot][$s]["root"]) && + if (isset(\App::$override_intltext_templates[$testroot][$s]["root"]) && isset(\App::$override_intltext_templates[$testroot][$s]["file"])) { $s = \App::$override_intltext_templates[$testroot][$s]["file"]; $root = \App::$override_intltext_templates[$testroot][$s]["root"]; @@ -1058,30 +1058,30 @@ function get_intltext_template($s, $root = '') { } function get_markup_template($s, $root = '') { - $testroot = ($root=='') ? $testroot = "ROOT" : $root; + $testroot = ($root=='') ? $testroot = "ROOT" : $root; - $t = App::template_engine(); + $t = App::template_engine(); - if (isset(\App::$override_markup_templates[$testroot][$s]["content"])) { - return \App::$override_markup_templates[$testroot][$s]["content"]; - } else { - if (isset(\App::$override_markup_templates[$testroot][$s]["root"]) && - isset(\App::$override_markup_templates[$testroot][$s]["file"])) { - $root = \App::$override_markup_templates[$testroot][$s]["root"]; - $s = \App::$override_markup_templates[$testroot][$s]["file"]; - $template = $t->get_markup_template($s, $root); - } elseif (\App::$override_templateroot) { - $newroot = \App::$override_templateroot; - if ($newroot != '' && substr($newroot,-1) != '/' ) { - $newroot .= '/'; - } - $newroot .= $root; - $template = $t->get_markup_template($s, $newroot); - } else { - $template = $t->get_markup_template($s, $root); + if (isset(\App::$override_markup_templates[$testroot][$s]["content"])) { + return \App::$override_markup_templates[$testroot][$s]["content"]; + } else { + if (isset(\App::$override_markup_templates[$testroot][$s]["root"]) && + isset(\App::$override_markup_templates[$testroot][$s]["file"])) { + $root = \App::$override_markup_templates[$testroot][$s]["root"]; + $s = \App::$override_markup_templates[$testroot][$s]["file"]; + $template = $t->get_markup_template($s, $root); + } elseif (\App::$override_templateroot) { + $newroot = \App::$override_templateroot; + if ($newroot != '' && substr($newroot,-1) != '/' ) { + $newroot .= '/'; + } + $newroot .= $root; + $template = $t->get_markup_template($s, $newroot); + } else { + $template = $t->get_markup_template($s, $root); } - return $template; - } + return $template; + } } /** 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 7d253e3d7..b50170553 100644 --- a/include/text.php +++ b/include/text.php @@ -1694,7 +1694,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, diff --git a/include/zid.php b/include/zid.php index fe06948ba..a37ebe1f6 100644 --- a/include/zid.php +++ b/include/zid.php @@ -70,9 +70,9 @@ function zid($s, $address = '') { $zurl .= '#' . $fragment; $arr = [ - 'url' => $s, - 'zid' => urlencode($myaddr), - 'result' => $zurl + 'url' => $s, + 'zid' => urlencode($myaddr), + 'result' => $zurl ]; /** * @hooks zid 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 */ } |