diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/checksites.php | 5 | ||||
-rw-r--r-- | include/deliver.php | 19 | ||||
-rw-r--r-- | include/dir_fns.php | 13 | ||||
-rw-r--r-- | include/externals.php | 5 | ||||
-rw-r--r-- | include/hubloc.php | 4 | ||||
-rwxr-xr-x | include/items.php | 6 | ||||
-rw-r--r-- | include/language.php | 16 | ||||
-rw-r--r-- | include/photo/photo_driver.php | 108 | ||||
-rw-r--r-- | include/queue.php | 16 | ||||
-rw-r--r-- | include/security.php | 42 | ||||
-rw-r--r-- | include/text.php | 4 | ||||
-rw-r--r-- | include/widgets.php | 4 | ||||
-rw-r--r-- | include/zot.php | 51 |
13 files changed, 207 insertions, 86 deletions
diff --git a/include/checksites.php b/include/checksites.php index e14837255..e9c08c202 100644 --- a/include/checksites.php +++ b/include/checksites.php @@ -25,8 +25,9 @@ function checksites_run($argv, $argc){ if($days < 1) $days = 30; - $r = q("select * from site where site_dead = 0 and site_update < %s - INTERVAL %s $sql_options ", - db_utcnow(), db_quoteinterval($days . ' DAY') + $r = q("select * from site where site_dead = 0 and site_update < %s - INTERVAL %s and site_type = %d $sql_options ", + db_utcnow(), db_quoteinterval($days . ' DAY'), + intval(SITE_TYPE_ZOT) ); if(! $r) diff --git a/include/deliver.php b/include/deliver.php index 82a1ac6df..86fc90b3f 100644 --- a/include/deliver.php +++ b/include/deliver.php @@ -53,16 +53,33 @@ function deliver_run($argv, $argc) { continue; } } + else { + + // zot sites should all have a site record, unless they've been dead for as long as + // your site has existed. Since we don't know for sure what these sites are, + // call them unknown + + q("insert into site (site_url, site_update, site_dead, site_type) values ('%s','%s',0,%d) ", + dbesc($base), + dbesc(datetime_convert()), + intval(($r[0]['outq_driver'] === 'post') ? SITE_TYPE_NOTZOT : SITE_TYPE_UNKNOWN) + ); + } } } // "post" queue driver - used for diaspora and friendica-over-diaspora communications. if($r[0]['outq_driver'] === 'post') { + + $result = z_post_url($r[0]['outq_posturl'],$r[0]['outq_msg']); if($result['success'] && $result['return_code'] < 300) { logger('deliver: queue post success to ' . $r[0]['outq_posturl'], LOGGER_DEBUG); - + q("update site set site_update = '%s', site_dead = 0 where site_url = '%s' ", + dbesc(datetime_convert()), + dbesc($site_url) + ); q("update dreport set status = '%s', dreport_time = '%s' where dreport_queue = '%s' limit 1", dbesc('accepted for delivery'), dbesc(datetime_convert()), diff --git a/include/dir_fns.php b/include/dir_fns.php index 38c92dd94..e466b7404 100644 --- a/include/dir_fns.php +++ b/include/dir_fns.php @@ -151,16 +151,18 @@ function sync_directories($dirmode) { $realm = get_directory_realm(); if ($realm == DIRECTORY_REALM) { - $r = q("select * from site where (site_flags & %d) > 0 and site_url != '%s' and ( site_realm = '%s' or site_realm = '') ", + $r = q("select * from site where (site_flags & %d) > 0 and site_url != '%s' and site_type = %d and ( site_realm = '%s' or site_realm = '') ", intval(DIRECTORY_MODE_PRIMARY|DIRECTORY_MODE_SECONDARY), dbesc(z_root()), + intval(SITE_TYPE_ZOT), dbesc($realm) ); } else { - $r = q("select * from site where (site_flags & %d) > 0 and site_url != '%s' and site_realm like '%s' ", + $r = q("select * from site where (site_flags & %d) > 0 and site_url != '%s' and site_realm like '%s' and site_type = %d ", intval(DIRECTORY_MODE_PRIMARY|DIRECTORY_MODE_SECONDARY), dbesc(z_root()), - dbesc(protect_sprintf('%' . $realm . '%')) + dbesc(protect_sprintf('%' . $realm . '%')), + intval(SITE_TYPE_ZOT) ); } @@ -187,9 +189,10 @@ function sync_directories($dirmode) { intval($r[0]['site_valid']) ); - $r = q("select * from site where (site_flags & %d) > 0 and site_url != '%s'", + $r = q("select * from site where (site_flags & %d) > 0 and site_url != '%s' and site_type = %d ", intval(DIRECTORY_MODE_PRIMARY|DIRECTORY_MODE_SECONDARY), - dbesc(z_root()) + dbesc(z_root()), + intval(SITE_TYPE_ZOT) ); } if (! $r) diff --git a/include/externals.php b/include/externals.php index 3b6d170d5..18c034bb2 100644 --- a/include/externals.php +++ b/include/externals.php @@ -28,9 +28,10 @@ function externals_run($argv, $argc){ } else { $randfunc = db_getfunc('RAND'); - $r = q("select site_url, site_pull from site where site_url != '%s' and site_flags != %d order by $randfunc limit 1", + $r = q("select site_url, site_pull from site where site_url != '%s' and site_flags != %d and site_type = %d order by $randfunc limit 1", dbesc(z_root()), - intval(DIRECTORY_MODE_STANDALONE) + intval(DIRECTORY_MODE_STANDALONE), + intval(SITE_TYPE_ZOT) ); if($r) $url = $r[0]['site_url']; diff --git a/include/hubloc.php b/include/hubloc.php index 674a3885f..a1171b0e2 100644 --- a/include/hubloc.php +++ b/include/hubloc.php @@ -16,7 +16,9 @@ function is_matrix_url($url) { function prune_hub_reinstalls() { - $r = q("select site_url from site where true"); + $r = q("select site_url from site where site_type = %d", + intval(SITE_TYPE_ZOT) + ); if($r) { foreach($r as $rr) { $x = q("select count(*) as t, hubloc_sitekey, max(hubloc_connected) as c from hubloc where hubloc_url = '%s' group by hubloc_sitekey order by c", diff --git a/include/items.php b/include/items.php index 7793d1fb2..e7cc02579 100755 --- a/include/items.php +++ b/include/items.php @@ -3522,11 +3522,17 @@ function mail_store($arr) { dbesc($arr['mid']), intval($arr['channel_id']) ); + if($r) { logger('mail_store: duplicate item ignored. ' . print_r($arr,true)); return 0; } + if(! $r && $arr['mail_recalled'] == 1) { + logger('mail_store: recalled item not found. ' . print_r($arr,true)); + return 0; + } + call_hooks('post_mail',$arr); if(x($arr,'cancel')) { diff --git a/include/language.php b/include/language.php index 7dbe3dd02..59979aa85 100644 --- a/include/language.php +++ b/include/language.php @@ -120,7 +120,11 @@ function load_translation_table($lang, $install = false) { global $a; $a->strings = array(); - if(file_exists("view/$lang/strings.php")) { + + if(file_exists("view/$lang/hstrings.php")) { + include("view/$lang/hstrings.php"); + } + elseif(file_exists("view/$lang/strings.php")) { include("view/$lang/strings.php"); } @@ -129,7 +133,10 @@ function load_translation_table($lang, $install = false) { if ($plugins !== false) { foreach($plugins as $p) { $name = $p['name']; - if(file_exists("addon/$name/lang/$lang/strings.php")) { + if(file_exists("addon/$name/lang/$lang/hstrings.php")) { + include("addon/$name/lang/$lang/hstrings.php"); + } + elseif(file_exists("addon/$name/lang/$lang/strings.php")) { include("addon/$name/lang/$lang/strings.php"); } } @@ -139,7 +146,10 @@ function load_translation_table($lang, $install = false) { // Allow individual strings to be over-ridden on this site // Either for the default language or for all languages - if(file_exists("view/local-$lang/strings.php")) { + if(file_exists("view/local-$lang/hstrings.php")) { + include("view/local-$lang/hstrings.php"); + } + elseif(file_exists("view/local-$lang/strings.php")) { include("view/local-$lang/strings.php"); } } diff --git a/include/photo/photo_driver.php b/include/photo/photo_driver.php index 2a7d1ae01..32b9bd302 100644 --- a/include/photo/photo_driver.php +++ b/include/photo/photo_driver.php @@ -591,67 +591,85 @@ function import_xchan_photo($photo,$xchan,$thing = false) { if(! $type) $type = 'image/jpeg'; + $result = z_fetch_url($photo,true); - if($result['success']) + if($result['success']) { $img_str = $result['body']; - } - - $img = photo_factory($img_str, $type); - if($img->is_valid()) { - $width = $img->getWidth(); - $height = $img->getHeight(); - - if($width && $height) { - if(($width / $height) > 1.2) { - // crop out the sides - $margin = $width - $height; - $img->cropImage(300,($margin / 2),0,$height,$height); - } - elseif(($height / $width) > 1.2) { - // crop out the bottom - $margin = $height - $width; - $img->cropImage(300,0,0,$width,$width); + $h = explode("\n",$result['header']); + if($h) { + foreach($h as $hl) { + if(stristr($hl,'content-type:')) { + if(! stristr($hl,'image/')) { + $photo_failure = true; + } + } + } } - else { - $img->scaleImageSquare(300); - } - } - else - $photo_failure = true; + } + else { + $photo_failure = true; + } - $p = array('xchan' => $xchan,'resource_id' => $hash, 'filename' => basename($photo), 'album' => $album, 'photo_usage' => $flags, 'scale' => 4); + if(! $photo_failure) { + $img = photo_factory($img_str, $type); + if($img->is_valid()) { + $width = $img->getWidth(); + $height = $img->getHeight(); + + if($width && $height) { + if(($width / $height) > 1.2) { + // crop out the sides + $margin = $width - $height; + $img->cropImage(300,($margin / 2),0,$height,$height); + } + elseif(($height / $width) > 1.2) { + // crop out the bottom + $margin = $height - $width; + $img->cropImage(300,0,0,$width,$width); - $r = $img->save($p); + } + else { + $img->scaleImageSquare(300); + } - if($r === false) - $photo_failure = true; + } + else + $photo_failure = true; - $img->scaleImage(80); - $p['scale'] = 5; + $p = array('xchan' => $xchan,'resource_id' => $hash, 'filename' => basename($photo), 'album' => $album, 'photo_usage' => $flags, 'scale' => 4); - $r = $img->save($p); + $r = $img->save($p); - if($r === false) - $photo_failure = true; + if($r === false) + $photo_failure = true; - $img->scaleImage(48); - $p['scale'] = 6; + $img->scaleImage(80); + $p['scale'] = 5; + + $r = $img->save($p); - $r = $img->save($p); + if($r === false) + $photo_failure = true; + + $img->scaleImage(48); + $p['scale'] = 6; + + $r = $img->save($p); - if($r === false) - $photo_failure = true; + if($r === false) + $photo_failure = true; - $photo = $a->get_baseurl() . '/photo/' . $hash . '-4'; - $thumb = $a->get_baseurl() . '/photo/' . $hash . '-5'; - $micro = $a->get_baseurl() . '/photo/' . $hash . '-6'; - } - else { - logger('import_xchan_photo: invalid image from ' . $photo); - $photo_failure = true; + $photo = $a->get_baseurl() . '/photo/' . $hash . '-4'; + $thumb = $a->get_baseurl() . '/photo/' . $hash . '-5'; + $micro = $a->get_baseurl() . '/photo/' . $hash . '-6'; + } + else { + logger('import_xchan_photo: invalid image from ' . $photo); + $photo_failure = true; + } } if($photo_failure) { $photo = $a->get_baseurl() . '/' . get_default_profile_photo(); diff --git a/include/queue.php b/include/queue.php index 7d2ad3b2d..18c8c5fa2 100644 --- a/include/queue.php +++ b/include/queue.php @@ -22,6 +22,22 @@ function queue_run($argv, $argc){ logger('queue: start'); + + $r = q("select outq_posturl from outq where outq_created < %s - INTERVAL %s", + db_utcnow(), db_quoteinterval('3 DAY') + ); + if($r) { + foreach($r as $rr) { + $site_url = ''; + $h = parse_url($rr['outq_posturl']); + $desturl = $h['scheme'] . '://' . $h['host'] . (($h['port']) ? ':' . $h['port'] : ''); + q("update site set site_dead = 1 where site_dead = 0 and site_url = '%s' and site_update < %s - INTERVAL %s", + dbesc($desturl), + db_utcnow(), db_quoteinterval('1 MONTH') + ); + } + } + $r = q("DELETE FROM outq WHERE outq_created < %s - INTERVAL %s", db_utcnow(), db_quoteinterval('3 DAY') ); diff --git a/include/security.php b/include/security.php index 380505a79..9a25d9e0e 100644 --- a/include/security.php +++ b/include/security.php @@ -245,6 +245,9 @@ function item_permissions_sql($owner_id, $remote_observer = null) { $observer = (($remote_observer) ? $remote_observer : get_observer_hash()); if($observer) { + + $s = scopes_sql($owner_id,$observer); + $groups = init_groups_visitor($observer); $gs = '<<>>'; // should be impossible to match @@ -255,9 +258,9 @@ function item_permissions_sql($owner_id, $remote_observer = null) { } $regexop = db_getfunc('REGEXP'); $sql = sprintf( - " AND ( NOT (deny_cid like '%s' OR deny_gid $regexop '%s') - AND ( allow_cid like '%s' OR allow_gid $regexop '%s' OR ( allow_cid = '' AND allow_gid = '' AND item_private = 0 ) ) - ) + " AND (( NOT (deny_cid like '%s' OR deny_gid $regexop '%s') + AND ( allow_cid like '%s' OR allow_gid $regexop '%s' OR ( allow_cid = '' AND allow_gid = '' AND item_private = 0 )) + ) OR ( item_private = 1 $s )) ", dbesc(protect_sprintf( '%<' . $observer . '>%')), dbesc($gs), @@ -271,6 +274,39 @@ function item_permissions_sql($owner_id, $remote_observer = null) { } /** + * Remote visitors also need to be checked against the public_scope parameter if item_private is set. + * This function checks the various permutations of that field for any which apply to this observer. + * + */ + + + +function scopes_sql($uid,$observer) { + $str = " and ( public_policy = 'authenticated' "; + if(! is_foreigner($observer)) + $str .= " or public_policy = 'network: red' "; + if(local_channel()) + $str .= " or public_policy = 'site: " . get_app()->get_hostname() . "' "; + + $ab = q("select * from abook where abook_xchan = '%s' and abook_channel = %d limit 1", + dbesc($observer), + intval($uid) + ); + if(! $ab) + return $str . " ) "; + if($ab[0]['abook_pending']) + $str .= " or public_policy = 'any connections' "; + $str .= " or public_policy = 'contacts' ) "; + return $str; +} + + + + + + + +/** * @param string $observer_hash * * @return string additional SQL where statement diff --git a/include/text.php b/include/text.php index 4d9670806..b1af62fc5 100644 --- a/include/text.php +++ b/include/text.php @@ -1686,14 +1686,14 @@ function mimetype_select($channel_id, $current = 'text/bbcode') { function lang_selector() { global $a; - $langs = glob('view/*/strings.php'); + $langs = glob('view/*/hstrings.php'); $lang_options = array(); $selected = ""; if(is_array($langs) && count($langs)) { $langs[] = ''; - if(! in_array('view/en/strings.php',$langs)) + if(! in_array('view/en/hstrings.php',$langs)) $langs[] = 'view/en/'; asort($langs); foreach($langs as $l) { diff --git a/include/widgets.php b/include/widgets.php index 9f8b88d54..9c8596a66 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -637,6 +637,7 @@ function widget_conversations($arr) { foreach($r as $rr) { $messages[] = array( + 'mailbox' => $mailbox, 'id' => $rr['id'], 'from_name' => $rr['from']['xchan_name'], 'from_url' => chanlink_hash($rr['from_xchan']), @@ -648,7 +649,8 @@ function widget_conversations($arr) { 'delete' => t('Delete conversation'), 'body' => $rr['body'], 'date' => datetime_convert('UTC',date_default_timezone_get(),$rr['created'], t('D, d M Y - g:i A')), - 'seen' => $rr['seen'] + 'seen' => $rr['seen'], + 'selected' => ((argv(2)) ? (argv(2) == $rr['id']) : ($r[0]['id'] == $rr['id'])) ); } diff --git a/include/zot.php b/include/zot.php index 9bddb520d..ef9f325d0 100644 --- a/include/zot.php +++ b/include/zot.php @@ -398,11 +398,6 @@ function zot_refresh($them, $channel = null, $force = false) { } } - $r = q("select * from abook where abook_xchan = '%s' and abook_channel = %d and abook_self = 0 limit 1", - dbesc($x['hash']), - intval($channel['channel_id']) - ); - if(array_key_exists('profile',$j) && array_key_exists('next_birthday',$j['profile'])) { $next_birthday = datetime_convert('UTC','UTC',$j['profile']['next_birthday']); } @@ -410,8 +405,15 @@ function zot_refresh($them, $channel = null, $force = false) { $next_birthday = NULL_DATE; } + $r = q("select * from abook where abook_xchan = '%s' and abook_channel = %d and abook_self = 0 limit 1", + dbesc($x['hash']), + intval($channel['channel_id']) + ); + if($r) { + // connection exists + // if the dob is the same as what we have stored (disregarding the year), keep the one // we have as we may have updated the year after sending a notification; and resetting // to the one we just received would cause us to create duplicated events. @@ -453,6 +455,9 @@ function zot_refresh($them, $channel = null, $force = false) { } } else { + + // new connection + $role = get_pconfig($channel['channel_id'],'system','permissions_role'); if($role) { $xx = get_role_perms($role); @@ -1582,14 +1587,11 @@ function process_delivery($sender, $arr, $deliveries, $relay, $public = false, $ $channel = $r[0]; $DR->addto_recipient($channel['channel_name'] . ' <' . $channel['channel_address'] . '@' . get_app()->get_hostname() . '>'); - -// uncomment this once we find out what's stopping the clone sync of the item from working -// if($d['hash'] === $sender['hash']) { -// $DR->update('self delivery ignored'); -// $result[] = $DR->get(); -// continue; -// } - + if($d['hash'] === $sender['hash']) { + $DR->update('self delivery ignored'); + $result[] = $DR->get(); + continue; + } // allow public postings to the sys channel regardless of permissions, but not // for comments travelling upstream. Wait and catch them on the way down. @@ -2738,7 +2740,7 @@ function import_site($arr, $pubkey) { // logger('import_site: input: ' . print_r($arr,true)); // logger('import_site: stored: ' . print_r($siterecord,true)); - $r = q("update site set site_dead = 0, site_location = '%s', site_flags = %d, site_access = %d, site_directory = '%s', site_register = %d, site_update = '%s', site_sellpage = '%s', site_realm = '%s' + $r = q("update site set site_dead = 0, site_location = '%s', site_flags = %d, site_access = %d, site_directory = '%s', site_register = %d, site_update = '%s', site_sellpage = '%s', site_realm = '%s', site_type = %d where site_url = '%s'", dbesc($site_location), intval($site_directory), @@ -2748,6 +2750,7 @@ function import_site($arr, $pubkey) { dbesc(datetime_convert()), dbesc($sellpage), dbesc($site_realm), + intval(SITE_TYPE_ZOT), dbesc($url) ); if(! $r) { @@ -2764,7 +2767,7 @@ function import_site($arr, $pubkey) { } else { $update = true; - $r = q("insert into site ( site_location, site_url, site_access, site_flags, site_update, site_directory, site_register, site_sellpage, site_realm ) + $r = q("insert into site ( site_location, site_url, site_access, site_flags, site_update, site_directory, site_register, site_sellpage, site_realm, site_type ) values ( '%s', '%s', %d, %d, '%s', '%s', %d, '%s', '%s' )", dbesc($site_location), dbesc($url), @@ -2774,7 +2777,8 @@ function import_site($arr, $pubkey) { dbesc($directory_url), intval($register_policy), dbesc($sellpage), - dbesc($site_realm) + dbesc($site_realm), + intval(SITE_TYPE_ZOT) ); if(! $r) { logger('import_site: record create failed. ' . print_r($arr,true)); @@ -2816,6 +2820,9 @@ function build_sync_packet($uid = 0, $packet = null, $groups_changed = false) { $channel = $r[0]; + if(intval($channel['channel_removed'])) + return; + $h = q("select * from hubloc where hubloc_hash = '%s' and hubloc_deleted = 0", dbesc($channel['channel_hash']) ); @@ -2866,7 +2873,7 @@ function build_sync_packet($uid = 0, $packet = null, $groups_changed = false) { // don't pass these elements, they should not be synchronised - $disallowed = array('channel_id','channel_account_id','channel_primary','channel_prvkey','channel_address'); + $disallowed = array('channel_id','channel_account_id','channel_primary','channel_prvkey','channel_address','channel_deleted','channel_removed','channel_system'); if(in_array($k,$disallowed)) continue; @@ -2993,10 +3000,12 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) { // These flags cannot be sync'd. // remove the bits from the incoming flags. - if($arr['channel_pageflags'] & 0x8000) - $arr['channel_pageflags'] = $arr['channel_pageflags'] - 0x8000; - if($arr['channel_pageflags'] & 0x1000) - $arr['channel_pageflags'] = $arr['channel_pageflags'] - 0x1000; + // These correspond to PAGE_REMOVED and PAGE_SYSTEM on redmatrix + + if($arr['channel']['channel_pageflags'] & 0x8000) + $arr['channel']['channel_pageflags'] = $arr['channel']['channel_pageflags'] - 0x8000; + if($arr['channel']['channel_pageflags'] & 0x1000) + $arr['channel']['channel_pageflags'] = $arr['channel']['channel_pageflags'] - 0x1000; } |