diff options
author | Mario <mario@mariovavti.com> | 2020-10-31 20:30:36 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2020-10-31 20:30:36 +0000 |
commit | b55c7f794b06d45f3b9cdb2f8a4ce7d99aaf8902 (patch) | |
tree | 95ed2e76d040e856a7ec72abf0c1079542661107 /include | |
parent | 5580fc1954a63f861644e2de3773fbb3adfa8f2c (diff) | |
parent | 205279f7f877c10abf80715c55db83d2c2852eab (diff) | |
download | volse-hubzilla-b55c7f794b06d45f3b9cdb2f8a4ce7d99aaf8902.tar.gz volse-hubzilla-b55c7f794b06d45f3b9cdb2f8a4ce7d99aaf8902.tar.bz2 volse-hubzilla-b55c7f794b06d45f3b9cdb2f8a4ce7d99aaf8902.zip |
Merge branch 'dev' into 5.0RC
Diffstat (limited to 'include')
-rw-r--r-- | include/attach.php | 6 | ||||
-rw-r--r-- | include/contact_widgets.php | 49 | ||||
-rw-r--r-- | include/network.php | 32 | ||||
-rw-r--r-- | include/taxonomy.php | 93 | ||||
-rw-r--r-- | include/text.php | 23 |
5 files changed, 124 insertions, 79 deletions
diff --git a/include/attach.php b/include/attach.php index 80f71b9ea..c9649a4ce 100644 --- a/include/attach.php +++ b/include/attach.php @@ -2807,6 +2807,12 @@ function save_chunk($channel,$start,$end,$len) { $new_path = $new_base . '/' . $_FILES['files']['name']; + if(file_exists($new_path) && intval($start) === 0) { + $result['partial'] = true; + $result['length'] = intval(filesize($new_path)); + return $result; + } + if(! file_exists($new_path)) { rename($tmp_path,$new_path); } diff --git a/include/contact_widgets.php b/include/contact_widgets.php index 6ad276b00..626a825b2 100644 --- a/include/contact_widgets.php +++ b/include/contact_widgets.php @@ -1,6 +1,6 @@ <?php /** @file */ - +use Zotlabs\Lib\Cache; function findpeople_widget() { @@ -59,6 +59,7 @@ function fileas_widget($baseurl,$selected = '') { )); } + function categories_widget($baseurl,$selected = '') { if(! feature_enabled(App::$profile['profile_uid'],'categories')) @@ -70,25 +71,36 @@ function categories_widget($baseurl,$selected = '') { $item_normal = item_normal(); + $key = __FUNCTION__ . "-" . App::$profile['profile_uid']; + $content = Cache::get($key, '5 MINUTE'); + + if (! $content) { + $r = q("select distinct(term.term) from term join item on term.oid = item.id + where item.uid = %d + and term.uid = item.uid + and term.ttype = %d + and term.otype = %d + and item.owner_xchan = '%s' + and item.item_wall = 1 + and item.verb != '%s' + $item_normal + $sql_extra + order by term.term asc", + intval(App::$profile['profile_uid']), + intval(TERM_CATEGORY), + intval(TERM_OBJ_POST), + dbesc(App::$profile['channel_hash']), + dbesc(ACTIVITY_UPDATE) + ); + } + else + $r = unserialize($content); + $terms = array(); - $r = q("select distinct(term.term) from term join item on term.oid = item.id - where item.uid = %d - and term.uid = item.uid - and term.ttype = %d - and term.otype = %d - and item.owner_xchan = '%s' - and item.item_wall = 1 - and item.verb != '%s' - $item_normal - $sql_extra - order by term.term asc", - intval(App::$profile['profile_uid']), - intval(TERM_CATEGORY), - intval(TERM_OBJ_POST), - dbesc(App::$profile['channel_hash']), - dbesc(ACTIVITY_UPDATE) - ); if($r && count($r)) { + + Cache::set($key, serialize($r)); + foreach($r as $rr) $terms[] = array('name' => $rr['term'], 'selected' => (($selected == $rr['term']) ? 'selected' : '')); @@ -104,6 +116,7 @@ function categories_widget($baseurl,$selected = '') { return ''; } + function cardcategories_widget($baseurl,$selected = '') { if(! feature_enabled(App::$profile['profile_uid'],'categories')) diff --git a/include/network.php b/include/network.php index 4457f59bc..9d4c00ee8 100644 --- a/include/network.php +++ b/include/network.php @@ -1333,14 +1333,15 @@ function fetch_xrd_links($url) { */ function scrape_feed($url) { - require_once('library/HTML5/Parser.php'); $ret = array(); $level = 0; $x = z_fetch_url($url,false,$level,array('novalidate' => true)); - if(! $x['success']) + if(! $x['success']) { + logger('ERROR fetching URL'); return $ret; + } $headers = $x['header']; $code = $x['return_code']; @@ -1374,17 +1375,16 @@ function scrape_feed($url) { } } + $dom = new DOMDocument(); try { - $dom = HTML5_Parser::parse($s); + $dom->loadHTML( $s); } catch (DOMException $e) { - logger('Parse error: ' . $e); - } - - if(! $dom) { - logger('Failed to parse.'); + logger('Feed parse error: ' . $e); + // logger('Feed parse ERROR: ' . libxml_get_last_error()->message); return $ret; } + $head = $dom->getElementsByTagName('base'); if($head) { foreach($head as $head0) { @@ -1846,15 +1846,15 @@ function probe_api_path($host) { function scrape_vcard($url) { - require_once('library/HTML5/Parser.php'); - $ret = array(); logger('url=' . $url); $x = z_fetch_url($url); - if(! $x['success']) + if(! $x['success']) { + logger('ERROR fetching URL'); return $ret; + } $s = $x['body']; @@ -1871,14 +1871,14 @@ function scrape_vcard($url) { } } + $dom = new DOMDocument(); try { - $dom = HTML5_Parser::parse($s); + $dom->loadHTML( $s); } catch (DOMException $e) { - logger('Parse error: ' . $e); - } - - if(! $dom) + logger('hCard parse error: ' . $e); + // logger('hCard fetch ERROR: ' . libxml_get_last_error()->message); return $ret; + } // Pull out hCard profile elements diff --git a/include/taxonomy.php b/include/taxonomy.php index b0304de5b..e06568d19 100644 --- a/include/taxonomy.php +++ b/include/taxonomy.php @@ -5,6 +5,9 @@ // and save to file categories in square brackets. // To do this we need to escape these characters if they appear in our tag. +use Zotlabs\Lib\Cache; + + function file_tag_encode($s) { return str_replace(array('<','>','[',']'),array('%3c','%3e','%5b','%5d'),$s); } @@ -327,50 +330,56 @@ function pubtagblock($net,$site,$limit,$recent = 0,$safemode = 1, $type = TERM_H return $o; } -function pub_tagadelic($net,$site,$limit,$recent,$safemode,$type) { - - - $item_normal = item_normal(); - $count = intval($limit); - - if($site) { - $uids = " and item.uid in ( " . stream_perms_api_uids(PERMS_PUBLIC) . " ) and item_private = 0 and item_wall = 1 "; - } - else { - $sys = get_sys_channel(); - $uids = " and item.uid = " . intval($sys['channel_id']) . " "; - $sql_extra = " and item_private = 0 "; - } - - if($recent) - $sql_extra .= " and item.created > '" . datetime_convert('UTC','UTC', 'now - ' . intval($recent) . ' days ') . "' "; +function pub_tagadelic($net,$site,$limit,$recent,$safemode,$type) { - if($safemode) { - $unsafetags = get_config('system','unsafepubtags', [ 'boobs', 'bot', 'rss', 'girl','girls', 'nsfw', 'sexy', 'nude' ]); - if($unsafetags) { - $sql_extra .= " and not term.term in ( " . stringify_array($unsafetags,true) . ") "; - } - } - - - // Fetch tags - $r = q("select term, count(term) as total from term left join item on term.oid = item.id - where term.ttype = %d - and otype = %d and item_type = %d - $sql_extra $uids $item_normal - group by term order by total desc %s", - intval($type), - intval(TERM_OBJ_POST), - intval(ITEM_TYPE_POST), - ((intval($count)) ? "limit $count" : '') - ); - - if(! $r) - return array(); - - return Zotlabs\Text\Tagadelic::calc($r); - + $item_normal = item_normal(); + $count = intval($limit); + + if($site) + $uids = " and item.uid in ( " . stream_perms_api_uids(PERMS_PUBLIC) . " ) and item_private = 0 and item_wall = 1 "; + else { + $sys = get_sys_channel(); + $uids = " and item.uid = " . intval($sys['channel_id']) . " "; + $sql_extra = " and item_private = 0 "; + } + + if($recent) + $sql_extra .= " and item.created > '" . datetime_convert('UTC','UTC', 'now - ' . intval($recent) . ' days ') . "' "; + + + if($safemode) { + $unsafetags = get_config('system','unsafepubtags', [ 'boobs', 'bot', 'rss', 'girl','girls', 'nsfw', 'sexy', 'nude' ]); + if($unsafetags) { + $sql_extra .= " and not term.term in ( " . stringify_array($unsafetags,true) . ") "; + } + } + + + $key = __FUNCTION__ . "-" . md5($site . $recent . $safemode . $limit . $type); + $content = Cache::get($key, '1 MINUTE'); + + if(! $content) { + // Fetch tags + $r = q("SELECT term, count(term) AS total FROM term LEFT JOIN item ON term.oid = item.id + where term.ttype = %d + and otype = %d and item_type = %d + $sql_extra $uids $item_normal + group by term order by total desc %s", + intval($type), + intval(TERM_OBJ_POST), + intval(ITEM_TYPE_POST), + ((intval($count)) ? "limit $count" : '') + ); + } else + $r = unserialize($content); + + if(! $r) + return array(); + else + Cache::set($key, serialize($r)); + + return Zotlabs\Text\Tagadelic::calc($r); } diff --git a/include/text.php b/include/text.php index 237202283..b3ed2eb31 100644 --- a/include/text.php +++ b/include/text.php @@ -659,6 +659,26 @@ function hz_syslog($msg, $priority = LOG_INFO) { closelog(); } +/** + * @brief like hz_syslog() but with a function backtrace to pinpoint certain classes + * of problems which show up deep in the calling stack. + * + * @param string $msg Message to log + * @param int $priority - compatible with syslog + */ +function bt_syslog($msg, $priority = LOG_INFO) { + $stack = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); + if($stack) { + for($x = 1; $x < count($stack); $x ++) { + $s = 'stack: ' . basename($stack[$x]['file']) . ':' . $stack[$x]['line'] . ':' . $stack[$x]['function'] . '()'; + openlog("bt-log", LOG_PID | LOG_PERROR, LOG_LOCAL0); + syslog($priority, $msg); + closelog(); + } + } +} + + /** * @brief Logging function for Hubzilla. @@ -742,9 +762,6 @@ function btlogger($msg, $level = LOGGER_NORMAL, $priority = LOG_INFO, $syslog = for($x = 1; $x < count($stack); $x ++) { $s = 'stack: ' . basename($stack[$x]['file']) . ':' . $stack[$x]['line'] . ':' . $stack[$x]['function'] . '()'; logger($s,$level, $priority); - if($syslog) { - hz_syslog(print_r($s,true)); - } if(file_exists(BTLOGGER_DEBUG_FILE) && is_writable(BTLOGGER_DEBUG_FILE)) { @file_put_contents(BTLOGGER_DEBUG_FILE, $s . PHP_EOL, FILE_APPEND); } |