diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/contact_widgets.php | 4 | ||||
-rw-r--r-- | include/conversation.php | 4 | ||||
-rw-r--r-- | include/dba/dba_pdo.php | 7 | ||||
-rw-r--r-- | include/feedutils.php | 4 | ||||
-rw-r--r-- | include/hubloc.php | 11 | ||||
-rw-r--r-- | include/items.php | 10 | ||||
-rw-r--r-- | include/text.php | 51 | ||||
-rw-r--r-- | include/zid.php | 2 |
8 files changed, 81 insertions, 12 deletions
diff --git a/include/contact_widgets.php b/include/contact_widgets.php index 875a519a5..1ae8b17c5 100644 --- a/include/contact_widgets.php +++ b/include/contact_widgets.php @@ -100,6 +100,10 @@ function categories_widget($baseurl,$selected = '') { \Zotlabs\Daemon\Master::Summon([ 'Cache_query', $key, base64_encode(json_encode($arr)) ]); } + if (!$content) { + return EMPTY_STR; + } + $r = unserialize($content); $terms = []; diff --git a/include/conversation.php b/include/conversation.php index 17367856c..c0238b8ae 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -558,7 +558,7 @@ function conversation($items, $mode, $update, $page_mode = 'traditional', $prepa $page_writeable = ($profile_owner == local_channel()); if (!$update) { - $tab = notags(trim($_GET['tab'])); + $tab = notags(trim((string)$_GET['tab'])); if ($tab === 'posts') { // This is ugly, but we can't pass the profile_uid through the session to the ajax updater, // because browser prefetching might change it on us. We have to deliver it with the page. @@ -974,7 +974,7 @@ function best_link_url($item) { } } if(! $best_url) { - if(strlen($item['author-link'])) + if($item['author-link']) $best_url = $item['author-link']; else $best_url = $item['url']; diff --git a/include/dba/dba_pdo.php b/include/dba/dba_pdo.php index 49f741601..2137ca0cc 100644 --- a/include/dba/dba_pdo.php +++ b/include/dba/dba_pdo.php @@ -27,6 +27,13 @@ class dba_pdo extends dba_driver { $dsn .= ';dbname=' . $db; + if ($this->driver_dbtype === 'mysql') { + $dsn .= ';charset=utf8mb4'; + } + else { + $dsn .= ";options='--client_encoding=UTF8'"; + } + try { $this->db = new PDO($dsn,$user,$pass); $this->db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); diff --git a/include/feedutils.php b/include/feedutils.php index d31836983..1c653325d 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -1180,7 +1180,7 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { else { $name = $author['author_name']; } - $x = import_author_unknown(array('name' => $name,'url' => $author['author_link'],'photo' => array('src' => $author['author_photo']))); + $x = import_author_rss(array('name' => $name,'url' => $author['author_link'],'photo' => array('src' => $author['author_photo']))); if($x) $datarray['author_xchan'] = $x; } @@ -1440,7 +1440,7 @@ function consume_feed($xml, $importer, &$contact, $pass = 0) { else { $name = $author['author_name']; } - $x = import_author_unknown(array('name' => $name,'url' => $author['author_link'],'photo' => array('src' => $author['author_photo']))); + $x = import_author_rss(array('name' => $name,'url' => $author['author_link'],'photo' => array('src' => $author['author_photo']))); if($x) $datarray['author_xchan'] = $x; } diff --git a/include/hubloc.php b/include/hubloc.php index 2cce7a725..6401d1f0d 100644 --- a/include/hubloc.php +++ b/include/hubloc.php @@ -16,6 +16,8 @@ use Zotlabs\Daemon\Master; */ function hubloc_store_lowlevel($arr) { + $update = ((array_key_exists('hubloc_id',$arr) && $arr['hubloc_id']) ? 'hubloc_id = ' . intval($arr['hubloc_id']) : false); + $store = [ 'hubloc_guid' => ((array_key_exists('hubloc_guid',$arr)) ? $arr['hubloc_guid'] : ''), 'hubloc_guid_sig' => ((array_key_exists('hubloc_guid_sig',$arr)) ? $arr['hubloc_guid_sig'] : ''), @@ -40,7 +42,7 @@ function hubloc_store_lowlevel($arr) { 'hubloc_deleted' => ((array_key_exists('hubloc_deleted',$arr)) ? $arr['hubloc_deleted'] : 0) ]; - return create_table_from_array('hubloc', $store); + return (($update) ? update_table_from_array('hubloc', $store, $update) : create_table_from_array('hubloc', $store)); } function site_store_lowlevel($arr) { @@ -283,6 +285,13 @@ function hubloc_change_primary($hubloc) { return true; } +function hubloc_delete($hubloc) { + if (is_array($hubloc) && array_key_exists('hubloc_id', $hubloc)) { + q("UPDATE hubloc SET hubloc_deleted = 1 WHERE hubloc_id = %d", + intval($hubloc['hubloc_id']) + ); + } +} /** * @brief Mark a hubloc as down. diff --git a/include/items.php b/include/items.php index 822e2d88b..0b33d876d 100644 --- a/include/items.php +++ b/include/items.php @@ -1446,7 +1446,7 @@ function activity_sanitise($arr) { if(is_array($x)) $ret[$k] = activity_sanitise($x); else - $ret[$k] = htmlspecialchars($x, ENT_COMPAT, 'UTF-8', false); + $ret[$k] = htmlspecialchars((string)$x, ENT_COMPAT, 'UTF-8', false); } return $ret; } @@ -1625,9 +1625,9 @@ function item_store($arr, $allow_exec = false, $deliver = true) { return $ret; } - $arr['title'] = ((array_key_exists('title',$arr) && strlen($arr['title'])) ? trim($arr['title']) : ''); - $arr['summary'] = ((array_key_exists('summary',$arr) && strlen($arr['summary'])) ? trim($arr['summary']) : ''); - $arr['body'] = ((array_key_exists('body',$arr) && strlen($arr['body'])) ? trim($arr['body']) : ''); + $arr['title'] = ((array_key_exists('title',$arr) && $arr['title']) ? trim($arr['title']) : ''); + $arr['summary'] = ((array_key_exists('summary',$arr) && $arr['summary']) ? trim($arr['summary']) : ''); + $arr['body'] = ((array_key_exists('body',$arr) && $arr['body']) ? trim($arr['body']) : ''); $arr['allow_cid'] = ((x($arr,'allow_cid')) ? trim($arr['allow_cid']) : ''); $arr['allow_gid'] = ((x($arr,'allow_gid')) ? trim($arr['allow_gid']) : ''); @@ -4438,7 +4438,7 @@ function items_fetch($arr,$channel = null,$observer_hash = null,$client_mode = C ); } - if(strlen($arr['file'])) { + if($arr['file']) { $sql_extra .= term_query('item',$arr['files'],TERM_FILE); } diff --git a/include/text.php b/include/text.php index aea8790fc..29a2ab3b1 100644 --- a/include/text.php +++ b/include/text.php @@ -417,6 +417,9 @@ function xmlify($str) { //$buffer = ''; + if (!$str) + return EMPTY_STR; + if(is_array($str)) { // allow to fall through so we ge a PHP error, as the log statement will @@ -482,6 +485,9 @@ function unxmlify($s) { return $ret; */ + if (!$s) + return EMPTY_STR; + if(is_array($s)) { // allow to fall through so we ge a PHP error, as the log statement will @@ -840,7 +846,7 @@ function activity_match($haystack,$needle) { if($needle) { foreach($needle as $n) { - if(($haystack === $n) || (strtolower(basename($n)) === strtolower(basename($haystack)))) { + if(($haystack === $n) || (strtolower(basename((string)$n)) === strtolower(basename((string)$haystack)))) { return true; } } @@ -1492,6 +1498,10 @@ function day_translate($s) { * @return string */ function normalise_link($url) { + if (!$url) { + return EMPTY_STR; + } + $ret = str_replace(array('https:', '//www.'), array('http:', '//'), $url); return(rtrim($ret, '/')); @@ -3588,6 +3598,45 @@ function create_table_from_array($table, $arr, $binary_fields = []) { return $r; } + +function update_table_from_array($table, $arr, $where, $binary_fields = []) { + + if (! ($arr && $table)) { + return false; + } + + $columns = db_columns($table); + + $clean = []; + foreach ($arr as $k => $v) { + if (! in_array($k, $columns)) { + continue; + } + + $matches = false; + if (preg_match('/([^a-zA-Z0-9\-\_\.])/', $k, $matches)) { + return false; + } + if (in_array($k, $binary_fields)) { + $clean[$k] = dbescbin($v); + } else { + $clean[$k] = dbesc($v); + } + } + + $sql = "UPDATE " . TQUOT . $table . TQUOT . " SET "; + + foreach ($clean as $k => $v) { + $sql .= TQUOT . $k . TQUOT . ' = "' . $v . '",'; + } + + $sql = rtrim($sql,','); + + $r = dbq($sql . " WHERE " . $where); + + return $r; +} + function share_shield($m) { return str_replace($m[1],'!=+=+=!' . base64url_encode($m[1]) . '=+!=+!=',$m[0]); } diff --git a/include/zid.php b/include/zid.php index e462f8357..ae7d9e252 100644 --- a/include/zid.php +++ b/include/zid.php @@ -37,7 +37,7 @@ function is_matrix_url($url) { * @return string */ function zid($s, $address = '') { - if (! strlen($s) || strpos($s,'zid=')) + if (!$s || strpos($s,'zid=')) return $s; $m = parse_url($s); |