diff options
author | mrjive <mrjive@mrjive.it> | 2015-09-29 08:01:51 +0200 |
---|---|---|
committer | mrjive <mrjive@mrjive.it> | 2015-09-29 08:01:51 +0200 |
commit | 11c1573b55f278a664a90a2872d06a40b3ac3026 (patch) | |
tree | 4061879d490fec39ab01d3feeb575b86586fb7f8 /include | |
parent | 006ca4421a7027ccee4612beb99a1f9976146070 (diff) | |
parent | b3525b865784ff5d2d5a76b913b8c86d139cc0f3 (diff) | |
download | volse-hubzilla-11c1573b55f278a664a90a2872d06a40b3ac3026.tar.gz volse-hubzilla-11c1573b55f278a664a90a2872d06a40b3ac3026.tar.bz2 volse-hubzilla-11c1573b55f278a664a90a2872d06a40b3ac3026.zip |
Merge pull request #5 from redmatrix/master
updating from original codebase
Diffstat (limited to 'include')
-rw-r--r-- | include/checksites.php | 5 | ||||
-rw-r--r-- | include/deliver.php | 25 | ||||
-rw-r--r-- | include/deliver_hooks.php | 29 | ||||
-rw-r--r-- | include/dir_fns.php | 13 | ||||
-rw-r--r-- | include/event.php | 21 | ||||
-rw-r--r-- | include/externals.php | 5 | ||||
-rw-r--r-- | include/hubloc.php | 4 | ||||
-rw-r--r-- | include/identity.php | 4 | ||||
-rw-r--r-- | include/language.php | 16 | ||||
-rw-r--r-- | include/message.php | 34 | ||||
-rw-r--r-- | include/nav.php | 8 | ||||
-rw-r--r-- | include/notifier.php | 37 | ||||
-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 | 99 | ||||
-rw-r--r-- | include/zot.php | 53 |
18 files changed, 400 insertions, 123 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 7a43e3d47..86fc90b3f 100644 --- a/include/deliver.php +++ b/include/deliver.php @@ -53,18 +53,43 @@ 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()), + dbesc($argv[$x]) + ); + $y = q("delete from outq where outq_hash = '%s'", dbesc($argv[$x]) ); + } else { logger('deliver: queue post returned ' . $result['return_code'] . ' from ' . $r[0]['outq_posturl'],LOGGER_DEBUG); diff --git a/include/deliver_hooks.php b/include/deliver_hooks.php new file mode 100644 index 000000000..f0d6ba1b1 --- /dev/null +++ b/include/deliver_hooks.php @@ -0,0 +1,29 @@ +<?php + + +require_once('include/cli_startup.php'); +require_once('include/zot.php'); + + +function deliver_hooks_run($argv, $argc) { + + cli_startup(); + + $a = get_app(); + + if($argc < 2) + return; + + + $r = q("select * from item where id = '%d'", + intval($argv[1]) + ); + if($r) + call_hooks('notifier_normal',$r[0]); + +} + +if (array_search(__file__,get_included_files())===0){ + deliver_hooks_run($argv,$argc); + killme(); +} 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/event.php b/include/event.php index 44c172e98..e303ad232 100644 --- a/include/event.php +++ b/include/event.php @@ -526,13 +526,17 @@ function event_import_ical($ical, $uid) { // logger('dtstart: ' . var_export($dtstart,true)); - if(($dtstart->timezone_type == 2) || (($dtstart->timezone_type == 3) && ($dtstart->timezone === 'UTC'))) { - $ev['adjust'] = 1; - } - else { - $ev['adjust'] = 0; + + switch($dtstart->timezone_type) { + case VObject\Property\DateTime::UTC : + $ev['adjust'] = 0; + break; + case VObject\Property\DateTime::LOCALTZ : + default: + $ev['adjust'] = 1; + break; } - + $ev['start'] = datetime_convert((($ev['adjust']) ? 'UTC' : date_default_timezone_get()),'UTC', $dtstart->format(\DateTime::W3C)); @@ -751,12 +755,15 @@ function event_store_item($arr, $event) { } } + + $item_arr = array(); $prefix = ''; // $birthday = false; if($event['type'] === 'birthday') { - $prefix = t('This event has been added to your calendar.'); + if(! is_sys_channel($arr['uid'])) + $prefix = t('This event has been added to your calendar.'); // $birthday = true; // The event is created on your own site by the system, but appears to belong 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/identity.php b/include/identity.php index b5235e7ff..47738a8fa 100644 --- a/include/identity.php +++ b/include/identity.php @@ -616,6 +616,10 @@ function identity_basic_export($channel_id, $items = false) { } } + $addon = array('channel_id' => $channel_id,'data' => $ret); + call_hooks('identity_basic_export',$addon); + $ret = $addon['data']; + if(! $items) return $ret; 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/message.php b/include/message.php index efe1a7710..4b0236db8 100644 --- a/include/message.php +++ b/include/message.php @@ -262,18 +262,30 @@ function private_messages_list($uid, $mailbox = '', $start = 0, $numitems = 0) { ); if(! $x) return array(); - if($mailbox === 'inbox') - $where = " and sender_xchan != '" . dbesc($x[0]['channel_hash']) . "' "; - elseif($mailbox === 'outbox') - $where = " and sender_xchan = '" . dbesc($x[0]['channel_hash']) . "' "; + + $channel_hash = dbesc($x[0]['channel_hash']); + $local_channel = intval(local_channel()); + + switch($mailbox) { + + case 'inbox': + $sql = "SELECT * FROM mail WHERE channel_id = $local_channel AND from_xchan != '$channel_hash' ORDER BY created DESC $limit"; + break; + + case 'outbox': + $sql = "SELECT * FROM mail WHERE channel_id = $local_channel AND from_xchan = '$channel_hash' ORDER BY created DESC $limit"; + break; + + case 'combined': + $sql = "SELECT * FROM ( SELECT * FROM mail WHERE channel_id = $local_channel ORDER BY created DESC $limit ) AS temp_table GROUP BY parent_mid ORDER BY created DESC"; + break; + + } + } - // For different orderings, consider applying usort on the results. We thought of doing that - // inside this function or having some preset sorts, but don't wish to limit app developers. - - $r = q("SELECT * from mail WHERE channel_id = %d $where order by created desc $limit", - intval(local_channel()) - ); + $r = q($sql); + if(! $r) { return array(); } @@ -437,4 +449,4 @@ function private_messages_fetch_conversation($channel_id, $messageitem_id, $upda return $messages; -}
\ No newline at end of file +} diff --git a/include/nav.php b/include/nav.php index 972795e83..1630c4731 100644 --- a/include/nav.php +++ b/include/nav.php @@ -185,11 +185,11 @@ EOT; $nav['notifications']['all']=array('notifications/system', t('See all notifications'), "", ""); $nav['notifications']['mark'] = array('', t('Mark all system notifications seen'), '',''); - $nav['messages'] = array('message', t('Mail'), "", t('Private mail'),'mail_nav_btn'); - $nav['messages']['all']=array('message', t('See all private messages'), "", ""); + $nav['messages'] = array('mail/combined', t('Mail'), "", t('Private mail'),'mail_nav_btn'); + $nav['messages']['all']=array('mail/combined', t('See all private messages'), "", ""); $nav['messages']['mark'] = array('', t('Mark all private messages seen'), '',''); - $nav['messages']['inbox'] = array('message', t('Inbox'), "", t('Inbox')); - $nav['messages']['outbox']= array('message/sent', t('Outbox'), "", t('Outbox')); + $nav['messages']['inbox'] = array('mail/inbox', t('Inbox'), "", t('Inbox')); + $nav['messages']['outbox']= array('mail/outbox', t('Outbox'), "", t('Outbox')); $nav['messages']['new'] = array('mail/new', t('New Message'), "", t('New Message')); diff --git a/include/notifier.php b/include/notifier.php index fd95d53e2..3b29229cf 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -579,7 +579,7 @@ function notifier_run($argv, $argc){ if($deliveries_per_process <= 0) $deliveries_per_process = 1; - $deliver = array(); + $deliveries = array(); foreach($dhubs as $hub) { @@ -675,27 +675,38 @@ function notifier_run($argv, $argc){ ); } } - $deliver[] = $hash; - if(count($deliver) >= $deliveries_per_process) { - proc_run('php','include/deliver.php',$deliver); - $deliver = array(); - if($interval) - @time_sleep_until(microtime(true) + (float) $interval); + $deliveries[] = $hash; + } + + if($normal_mode) { + $x = q("select * from hook where hook = 'notifier_normal'"); + if($x) + proc_run('php','deliver_hooks.php', $target_item['id']); + } + + if($deliveries) { + $deliver = array(); + + foreach($deliveries as $d) { + + $deliver[] = $d; + + if(count($deliver) >= $deliveries_per_process) { + proc_run('php','include/deliver.php',$deliver); + $deliver = array(); + if($interval) + @time_sleep_until(microtime(true) + (float) $interval); + } } } // catch any stragglers - if(count($deliver)) { + if($deliver) proc_run('php','include/deliver.php',$deliver); - } logger('notifier: basic loop complete.', LOGGER_DEBUG); - - if($normal_mode) - call_hooks('notifier_normal',$target_item); - call_hooks('notifier_end',$target_item); 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 5e40bf54a..9c8596a66 100644 --- a/include/widgets.php +++ b/include/widgets.php @@ -562,14 +562,30 @@ function widget_mailmenu($arr) { return; $a = get_app(); + return replace_macros(get_markup_template('message_side.tpl'), array( - '$title' => t('Messages'), - '$tabs'=> array(), + '$title' => t('Private Mail Menu'), '$check'=>array( 'label' => t('Check Mail'), - 'url' => $a->get_baseurl(true) . '/message', + 'url' => $a->get_baseurl(true) . '/mail/combined', 'sel' => (argv(1) == ''), ), + + '$combined'=>array( + 'label' => t('Combined View'), + 'url' => $a->get_baseurl(true) . '/mail/combined', + 'sel' => (argv(1) == 'combined'), + ), + '$inbox'=>array( + 'label' => t('Inbox'), + 'url' => $a->get_baseurl(true) . '/mail/inbox', + 'sel' => (argv(1) == 'inbox'), + ), + '$outbox'=>array( + 'label' => t('Outbox'), + 'url' => $a->get_baseurl(true) . '/mail/outbox', + 'sel' => (argv(1) == 'outbox'), + ), '$new'=>array( 'label' => t('New Message'), 'url' => $a->get_baseurl(true) . '/mail/new', @@ -578,6 +594,80 @@ function widget_mailmenu($arr) { )); } + +function widget_conversations($arr) { + if (! local_channel()) + return; + + $a = get_app(); + + if(argc() > 1) { + + switch(argv(1)) { + case 'combined': + $mailbox = 'combined'; + $header = t('Conversations'); + break; + case 'inbox': + $mailbox = 'inbox'; + $header = t('Received Messages'); + break; + case 'outbox': + $mailbox = 'outbox'; + $header = t('Sent Messages'); + break; + default: + $mailbox = 'combined'; + $header = t('Conversations'); + break; + } + + require_once('include/message.php'); + + // private_messages_list() can do other more complicated stuff, for now keep it simple + $r = private_messages_list(local_channel(), $mailbox, $a->pager['start'], $a->pager['itemspage']); + + if(! $r) { + info( t('No messages.') . EOL); + return $o; + } + + $messages = array(); + + foreach($r as $rr) { + + $messages[] = array( + 'mailbox' => $mailbox, + 'id' => $rr['id'], + 'from_name' => $rr['from']['xchan_name'], + 'from_url' => chanlink_hash($rr['from_xchan']), + 'from_photo' => $rr['from']['xchan_photo_s'], + 'to_name' => $rr['to']['xchan_name'], + 'to_url' => chanlink_hash($rr['to_xchan']), + 'to_photo' => $rr['to']['xchan_photo_s'], + 'subject' => (($rr['seen']) ? $rr['title'] : '<strong>' . $rr['title'] . '</strong>'), + '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'], + 'selected' => ((argv(2)) ? (argv(2) == $rr['id']) : ($r[0]['id'] == $rr['id'])) + ); + } + + $tpl = get_markup_template('mail_head.tpl'); + $o .= replace_macros($tpl, array( + '$header' => $header, + '$messages' => $messages + )); + + $o .= alt_pager($a,count($r)); + + } + + return $o; +} + + function widget_design_tools($arr) { $a = get_app(); @@ -594,6 +684,7 @@ function widget_design_tools($arr) { return design_tools(); } + function widget_findpeople($arr) { return findpeople_widget(); } @@ -1135,4 +1226,4 @@ function widget_admin($arr) { return $o; -}
\ No newline at end of file +} diff --git a/include/zot.php b/include/zot.php index 288493b07..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; } @@ -3319,6 +3328,8 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) { if(array_key_exists('item_id',$arr) && $arr['item_id']) sync_items($channel,$arr['item_id']); + $addon = array('channel' => $channel,'data' => $arr); + call_hooks('process_channel_sync_delivery',$addon); // we should probably do this for all items, but usually we only send one. |