From 3cc756f3029e5f3b02008dac94a90e168d398c9a Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Sun, 4 Feb 2018 20:42:40 +0100 Subject: remove some never used indices which prevented our item queries to find the right query execution plan in mysql and adjust some queries to optimze the result --- Zotlabs/Module/Channel.php | 6 +++--- Zotlabs/Module/Hq.php | 4 +--- Zotlabs/Module/Network.php | 36 +++++++++++++++++++++++------------- Zotlabs/Module/Ping.php | 19 ++++++++----------- Zotlabs/Module/Pubstream.php | 4 ++-- 5 files changed, 37 insertions(+), 32 deletions(-) (limited to 'Zotlabs/Module') diff --git a/Zotlabs/Module/Channel.php b/Zotlabs/Module/Channel.php index 7c4c900a1..b7e18f954 100644 --- a/Zotlabs/Module/Channel.php +++ b/Zotlabs/Module/Channel.php @@ -239,7 +239,7 @@ class Channel extends \Zotlabs\Web\Controller { if($load || ($checkjs->disabled())) { if($mid) { - $r = q("SELECT distinct parent AS item_id from item where mid like '%s' and uid = %d $item_normal + $r = q("SELECT parent AS item_id from item where mid like '%s' and uid = %d $item_normal AND item_wall = 1 $sql_extra limit 1", dbesc($mid . '%'), intval(\App::$profile['profile_uid']) @@ -249,13 +249,13 @@ class Channel extends \Zotlabs\Web\Controller { } } else { - $r = q("SELECT distinct id AS item_id, created FROM item + $r = q("SELECT id AS item_id FROM item left join abook on item.author_xchan = abook.abook_xchan WHERE uid = %d $item_normal AND item_wall = 1 and item_thread_top = 1 AND (abook_blocked = 0 or abook.abook_flags is null) $sql_extra $sql_extra2 - ORDER BY created DESC $pager_sql ", + ORDER BY created DESC, id $pager_sql ", intval(\App::$profile['profile_uid']) ); } diff --git a/Zotlabs/Module/Hq.php b/Zotlabs/Module/Hq.php index c46695b65..baeba82e8 100644 --- a/Zotlabs/Module/Hq.php +++ b/Zotlabs/Module/Hq.php @@ -51,10 +51,8 @@ class Hq extends \Zotlabs\Web\Controller { $item_normal = item_normal(); $item_normal_update = item_normal_update(); - $use_index = db_use_index('created'); - if(! $item_hash) { - $r = q("SELECT mid FROM item $use_index + $r = q("SELECT mid FROM item WHERE uid = %d $item_normal AND mid = parent_mid ORDER BY created DESC LIMIT 1", diff --git a/Zotlabs/Module/Network.php b/Zotlabs/Module/Network.php index 551303984..70e0048fb 100644 --- a/Zotlabs/Module/Network.php +++ b/Zotlabs/Module/Network.php @@ -209,8 +209,11 @@ class Network extends \Zotlabs\Web\Controller { : ''); $sql_nets = ''; + + $distinct = ''; + $item_thread_top = ' AND item_thread_top = 1 '; - $sql_extra = " AND item.parent IN ( SELECT parent FROM item WHERE item_thread_top = 1 $sql_options ) "; + $sql_extra = $sql_options; if($group) { $contact_str = ''; @@ -226,7 +229,8 @@ class Network extends \Zotlabs\Web\Controller { $contact_str = ' 0 '; info( t('Privacy group is empty')); } - + $distinct = ' distinct '; + $item_thread_top = ''; $sql_extra = " AND item.parent IN ( SELECT DISTINCT parent FROM item WHERE true $sql_options AND (( author_xchan IN ( $contact_str ) OR owner_xchan in ( $contact_str )) or allow_gid like '" . protect_sprintf('%<' . dbesc($group_hash) . '>%') . "' ) and id = parent $item_normal ) "; $x = group_rec_byhash(local_channel(), $group_hash); @@ -250,6 +254,8 @@ class Network extends \Zotlabs\Web\Controller { intval(local_channel()) ); if($r) { + $distinct = ' distinct '; + $item_thread_top = ''; $sql_extra = " AND item.parent IN ( SELECT DISTINCT parent FROM item WHERE true $sql_options AND uid = " . intval(local_channel()) . " AND ( author_xchan = '" . dbesc($r[0]['abook_xchan']) . "' or owner_xchan = '" . dbesc($r[0]['abook_xchan']) . "' ) $item_normal ) "; $title = replace_macros(get_markup_template("section_title.tpl"),array( '$title' => '' . urlencode($r[0]['xchan_name']) . ' ' . $r[0]['xchan_name'] . '' @@ -264,13 +270,15 @@ class Network extends \Zotlabs\Web\Controller { } } elseif($xchan) { - $r = q("select * from xchan where xchan_hash = '%s'", - dbesc($xchan) - ); - if($r) { - $sql_extra = " AND item.parent IN ( SELECT DISTINCT parent FROM item WHERE true $sql_options AND uid = " . intval(local_channel()) . " AND ( author_xchan = '" . dbesc($xchan) . "' or owner_xchan = '" . dbesc($xchan) . "' ) $item_normal ) "; - $title = replace_macros(get_markup_template("section_title.tpl"),array( - '$title' => '' . urlencode($r[0]['xchan_name']) . ' ' . $r[0]['xchan_name'] . '' + $r = q("select * from xchan where xchan_hash = '%s'", + dbesc($xchan) + ); + if($r) { + $distinct = ' distinct '; + $item_thread_top = ''; + $sql_extra = " AND item.parent IN ( SELECT DISTINCT parent FROM item WHERE true $sql_options AND uid = " . intval(local_channel()) . " AND ( author_xchan = '" . dbesc($xchan) . "' or owner_xchan = '" . dbesc($xchan) . "' ) $item_normal ) "; + $title = replace_macros(get_markup_template("section_title.tpl"),array( + '$title' => '' . urlencode($r[0]['xchan_name']) . ' ' . $r[0]['xchan_name'] . '' )); $o = $tabs; $o .= $title; @@ -373,6 +381,8 @@ class Network extends \Zotlabs\Web\Controller { } if($conv) { + $distinct = ' distinct '; + $item_thread_top = ''; $sql_extra .= sprintf(" AND parent IN (SELECT distinct(parent) from item where ( author_xchan like '%s' or item_mentionsme = 1 )) ", dbesc(protect_sprintf($channel['channel_hash'])) ); @@ -448,7 +458,7 @@ class Network extends \Zotlabs\Web\Controller { if($nouveau && $load) { // "New Item View" - show all items unthreaded in reverse created date order - $items = q("SELECT item.*, item.id AS item_id, received FROM item + $items = q("SELECT item.*, item.id AS item_id, received FROM item left join abook on ( item.owner_xchan = abook.abook_xchan $abook_uids ) $net_query WHERE true $uids $item_normal @@ -477,11 +487,11 @@ class Network extends \Zotlabs\Web\Controller { if($load) { // Fetch a page full of parent items for this page - $r = q("SELECT distinct item.id AS item_id, $ordering FROM item + $r = q("SELECT $distinct item.parent AS item_id FROM item left join abook on ( item.owner_xchan = abook.abook_xchan $abook_uids ) $net_query - WHERE true $uids $item_normal - AND item.parent = item.id + WHERE true $uids $item_thread_top $item_normal + AND item.mid = item.parent_mid and (abook.abook_blocked = 0 or abook.abook_flags is null) $sql_extra3 $sql_extra $sql_nets $net_query2 diff --git a/Zotlabs/Module/Ping.php b/Zotlabs/Module/Ping.php index f8399d871..2e86804ac 100644 --- a/Zotlabs/Module/Ping.php +++ b/Zotlabs/Module/Ping.php @@ -149,13 +149,11 @@ class Ping extends \Zotlabs\Web\Controller { $pubs = q("SELECT count(id) as total from item WHERE uid = %d AND author_xchan != '%s' - AND obj_type != '%s' AND item_unseen = 1 AND created > '" . datetime_convert('UTC','UTC',$_SESSION['static_loadtime']) . "' $item_normal", intval($sys['channel_id']), - dbesc(get_observer_hash()), - dbesc(ACTIVITY_OBJ_FILE) + dbesc(get_observer_hash()) ); if($pubs) @@ -320,12 +318,13 @@ class Ping extends \Zotlabs\Web\Controller { if(argc() > 1 && (argv(1) === 'network' || argv(1) === 'home')) { $result = array(); - $use_index = db_use_index('uid_item_unseen'); - - $r = q("SELECT * FROM item $use_index - WHERE item_unseen = 1 and uid = %d $item_normal + $r = q("SELECT * FROM item + WHERE uid = %d AND author_xchan != '%s' - ORDER BY created DESC limit 300", + AND item_unseen = 1 + $item_normal + ORDER BY created DESC, id + LIMIT 300", intval(local_channel()), dbesc($ob_hash) ); @@ -495,9 +494,7 @@ class Ping extends \Zotlabs\Web\Controller { if($vnotify & (VNOTIFY_NETWORK|VNOTIFY_CHANNEL)) { - $use_index = db_use_index('uid_item_unseen'); - - $r = q("SELECT id, item_wall FROM item $use_index + $r = q("SELECT id, item_wall FROM item WHERE item_unseen = 1 and uid = %d $item_normal AND author_xchan != '%s'", diff --git a/Zotlabs/Module/Pubstream.php b/Zotlabs/Module/Pubstream.php index 2c25e2ce0..16a5fdbba 100644 --- a/Zotlabs/Module/Pubstream.php +++ b/Zotlabs/Module/Pubstream.php @@ -196,10 +196,10 @@ class Pubstream extends \Zotlabs\Web\Controller { } else { // Fetch a page full of parent items for this page - $r = q("SELECT distinct item.id AS item_id, $ordering FROM item + $r = q("SELECT item.id AS item_id FROM item left join abook on item.author_xchan = abook.abook_xchan $net_query - WHERE true $uids $item_normal + WHERE item_thread_top = 1 $uids $item_normal AND item.parent = item.id and (abook.abook_blocked = 0 or abook.abook_flags is null) $sql_extra3 $sql_extra $sql_nets $net_query2 -- cgit v1.2.3 From 9d55a254dcd39e2a77a1c24625adba69d16acb7a Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Sun, 4 Feb 2018 22:37:30 +0100 Subject: this will fix the cards query and keep the rest intact --- Zotlabs/Module/Cards.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Module') diff --git a/Zotlabs/Module/Cards.php b/Zotlabs/Module/Cards.php index 8eff6c80d..f87988183 100644 --- a/Zotlabs/Module/Cards.php +++ b/Zotlabs/Module/Cards.php @@ -143,7 +143,7 @@ class Cards extends \Zotlabs\Web\Controller { } $r = q("select * from item - where item.uid = %d and item_type = %d + where uid = %d and item_type = %d $sql_extra order by item.created desc", intval($owner), intval(ITEM_TYPE_CARD) -- cgit v1.2.3 From f15fd93f905520fa7f58e7365c838edd382b227c Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 4 Feb 2018 17:01:59 -0800 Subject: implode can take its arguments in either order, but let's try to be consistent --- Zotlabs/Module/Admin/Security.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'Zotlabs/Module') diff --git a/Zotlabs/Module/Admin/Security.php b/Zotlabs/Module/Admin/Security.php index a1e4bf537..49e1ccf42 100644 --- a/Zotlabs/Module/Admin/Security.php +++ b/Zotlabs/Module/Admin/Security.php @@ -52,24 +52,24 @@ class Security { function get() { $whitesites = get_config('system','whitelisted_sites'); - $whitesites_str = ((is_array($whitesites)) ? implode($whitesites,"\n") : ''); + $whitesites_str = ((is_array($whitesites)) ? implode("\n",$whitesites) : ''); $blacksites = get_config('system','blacklisted_sites'); - $blacksites_str = ((is_array($blacksites)) ? implode($blacksites,"\n") : ''); + $blacksites_str = ((is_array($blacksites)) ? implode("\n",$blacksites) : ''); $whitechannels = get_config('system','whitelisted_channels'); - $whitechannels_str = ((is_array($whitechannels)) ? implode($whitechannels,"\n") : ''); + $whitechannels_str = ((is_array($whitechannels)) ? implode("\n",$whitechannels) : ''); $blackchannels = get_config('system','blacklisted_channels'); - $blackchannels_str = ((is_array($blackchannels)) ? implode($blackchannels,"\n") : ''); + $blackchannels_str = ((is_array($blackchannels)) ? implode("\n",$blackchannels) : ''); $whiteembeds = get_config('system','embed_allow'); - $whiteembeds_str = ((is_array($whiteembeds)) ? implode($whiteembeds,"\n") : ''); + $whiteembeds_str = ((is_array($whiteembeds)) ? implode("\n",$whiteembeds) : ''); $blackembeds = get_config('system','embed_deny'); - $blackembeds_str = ((is_array($blackembeds)) ? implode($blackembeds,"\n") : ''); + $blackembeds_str = ((is_array($blackembeds)) ? implode("\n",$blackembeds) : ''); $embed_coop = intval(get_config('system','embed_coop')); -- cgit v1.2.3 From cadd958339323f5fcf4c2b438f7a5e311e477d52 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 5 Feb 2018 18:06:25 -0800 Subject: remove mobile_detect (outdated and unmaintainable) --- Zotlabs/Module/Connections.php | 2 +- Zotlabs/Module/Connedit.php | 1 - Zotlabs/Module/Settings/Display.php | 26 ++++---------------------- 3 files changed, 5 insertions(+), 24 deletions(-) (limited to 'Zotlabs/Module') diff --git a/Zotlabs/Module/Connections.php b/Zotlabs/Module/Connections.php index f42ff9b84..255731c9c 100644 --- a/Zotlabs/Module/Connections.php +++ b/Zotlabs/Module/Connections.php @@ -232,7 +232,7 @@ class Connections extends \Zotlabs\Web\Controller { if($rr['xchan_url']) { if(($rr['vcard']) && is_array($rr['vcard']['tels']) && $rr['vcard']['tels'][0]['nr']) - $phone = ((\App::$is_mobile || \App::$is_tablet) ? $rr['vcard']['tels'][0]['nr'] : ''); + $phone = $rr['vcard']['tels'][0]['nr']; else $phone = ''; diff --git a/Zotlabs/Module/Connedit.php b/Zotlabs/Module/Connedit.php index e23a751d9..f359175c1 100644 --- a/Zotlabs/Module/Connedit.php +++ b/Zotlabs/Module/Connedit.php @@ -895,7 +895,6 @@ class Connedit extends \Zotlabs\Web\Controller { '$permnote_self' => t('Some permissions may be inherited from your channel\'s privacy settings, which have higher priority than individual settings. You can change those settings here but they wont have any impact unless the inherited setting changes.'), '$lastupdtext' => t('Last update:'), '$last_update' => relative_date($contact['abook_connected']), - '$is_mobile' => ((\App::$is_mobile || \App::$is_tablet) ? true : false), '$profile_select' => contact_profile_assign($contact['abook_profile']), '$multiprofs' => $multiprofs, '$contact_id' => $contact['abook_id'], diff --git a/Zotlabs/Module/Settings/Display.php b/Zotlabs/Module/Settings/Display.php index e1ea0e3e5..340b3c0bb 100644 --- a/Zotlabs/Module/Settings/Display.php +++ b/Zotlabs/Module/Settings/Display.php @@ -21,7 +21,7 @@ class Display { if(! $theme) $theme = 'redbasic'; - $mobile_theme = ((x($_POST,'mobile_theme')) ? notags(trim($_POST['mobile_theme'])) : ''); + $preload_images = ((x($_POST,'preload_images')) ? intval($_POST['preload_images']) : 0); $channel_menu = ((x($_POST,'channel_menu')) ? intval($_POST['channel_menu']) : 0); $user_scalable = ((x($_POST,'user_scalable')) ? intval($_POST['user_scalable']) : 0); @@ -47,11 +47,6 @@ class Display { if($itemspage > 100) $itemspage = 100; - if ($mobile_theme == "---") - del_pconfig(local_channel(),'system','mobile_theme'); - else { - set_pconfig(local_channel(),'system','mobile_theme',$mobile_theme); - } set_pconfig(local_channel(),'system','preload_images',$preload_images); set_pconfig(local_channel(),'system','user_scalable',$user_scalable); @@ -114,10 +109,6 @@ class Display { $theme = (($existing_theme) ? $existing_theme : $default_theme); - $default_mobile_theme = get_config('system','mobile_theme'); - if(! $mobile_default_theme) - $mobile_default_theme = 'none'; - $allowed_themes_str = get_config('system','allowed_themes'); $allowed_themes_raw = explode(',',$allowed_themes_str); $allowed_themes = array(); @@ -135,26 +126,19 @@ class Display { $info = get_theme_info($th); $compatible = check_plugin_versions($info); - if(!$compatible) { - $mobile_themes[$f] = $themes[$f] = sprintf(t('%s - (Incompatible)'), $f); + if(! $compatible) { + $themes[$f] = sprintf(t('%s - (Incompatible)'), $f); continue; } $is_experimental = file_exists('view/theme/' . $th . '/experimental'); $unsupported = file_exists('view/theme/' . $th . '/unsupported'); - $is_mobile = file_exists('view/theme/' . $th . '/mobile'); $is_library = file_exists('view/theme/'. $th . '/library'); - $mobile_themes['---'] = t("No special theme for mobile devices"); if (!$is_experimental or ($is_experimental && (get_config('experimentals','exp_themes')==1 or get_config('experimentals','exp_themes')===false))){ $theme_name = (($is_experimental) ? sprintf(t('%s - (Experimental)'), $f) : $f); if (! $is_library) { - if($is_mobile) { - $mobile_themes[$f] = $themes[$f] = $theme_name . ' (' . t('mobile') . ')'; - } - else { - $mobile_themes[$f] = $themes[$f] = $theme_name; - } + $themes[$f] = $theme_name; } } } @@ -166,7 +150,6 @@ class Display { $theme_selected = explode(':', $theme_selected)[0]; } - $mobile_theme_selected = (!x($_SESSION,'mobile_theme')? $default_mobile_theme : $_SESSION['mobile_theme']); $preload_images = get_pconfig(local_channel(),'system','preload_images'); $preload_images = (($preload_images===false)? '0': $preload_images); // default if not set: 0 @@ -213,7 +196,6 @@ class Display { '$theme' => (($themes) ? array('theme', t('Display Theme:'), $theme_selected, '', $themes, 'preview') : false), '$schema' => array('schema', t('Select scheme'), $existing_schema, '' , $schemas), - '$mobile_theme' => (($mobile_themes) ? array('mobile_theme', t('Mobile Theme:'), $mobile_theme_selected, '', $mobile_themes, '') : false), '$preload_images' => array('preload_images', t("Preload images before rendering the page"), $preload_images, t("The subjective page load time will be longer but the page will be ready when displayed"), $yes_no), '$user_scalable' => array('user_scalable', t("Enable user zoom on mobile devices"), $user_scalable, '', $yes_no), '$ajaxint' => array('browser_update', t("Update browser every xx seconds"), $browser_update, t('Minimum of 10 seconds, no maximum')), -- cgit v1.2.3 From 661c20e452255754bbccadc3b29dc3c598c07ed0 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Thu, 8 Feb 2018 09:47:49 +0100 Subject: more db and queries finetuning --- Zotlabs/Module/Ping.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'Zotlabs/Module') diff --git a/Zotlabs/Module/Ping.php b/Zotlabs/Module/Ping.php index 2e86804ac..96ade22c0 100644 --- a/Zotlabs/Module/Ping.php +++ b/Zotlabs/Module/Ping.php @@ -148,8 +148,8 @@ class Ping extends \Zotlabs\Web\Controller { $pubs = q("SELECT count(id) as total from item WHERE uid = %d - AND author_xchan != '%s' AND item_unseen = 1 + AND author_xchan != '%s' AND created > '" . datetime_convert('UTC','UTC',$_SESSION['static_loadtime']) . "' $item_normal", intval($sys['channel_id']), @@ -166,8 +166,8 @@ class Ping extends \Zotlabs\Web\Controller { $r = q("SELECT * FROM item WHERE uid = %d - AND author_xchan != '%s' AND item_unseen = 1 + AND author_xchan != '%s' AND created > '" . datetime_convert('UTC','UTC',$_SESSION['static_loadtime']) . "' $item_normal ORDER BY created DESC @@ -208,22 +208,22 @@ class Ping extends \Zotlabs\Web\Controller { if(x($_REQUEST, 'markRead') && local_channel()) { switch($_REQUEST['markRead']) { case 'network': - $r = q("update item set item_unseen = 0 where item_unseen = 1 and uid = %d", + $r = q("UPDATE item SET item_unseen = 0 WHERE uid = %d AND item_unseen = 1", intval(local_channel()) ); break; case 'home': - $r = q("update item set item_unseen = 0 where item_unseen = 1 and item_wall = 1 and uid = %d", + $r = q("UPDATE item SET item_unseen = 0 WHERE uid = %d AND item_unseen = 1 AND item_wall = 1", intval(local_channel()) ); break; case 'mail': - $r = q("update mail set mail_seen = 1 where mail_seen = 0 and channel_id = %d ", + $r = q("UPDATE mail SET mail_seen = 1 WHERE channel_id = %d AND mail_seen = 0", intval(local_channel()) ); break; case 'all_events': - $r = q("update event set dismissed = 1 where dismissed = 0 and uid = %d AND dtstart < '%s' AND dtstart > '%s' ", + $r = q("UPDATE event SET dismissed = 1 WHERE uid = %d AND dismissed = 0 AND dtstart < '%s' AND dtstart > '%s' ", intval(local_channel()), dbesc(datetime_convert('UTC', date_default_timezone_get(), 'now + ' . intval($evdays) . ' days')), dbesc(datetime_convert('UTC', date_default_timezone_get(), 'now - 1 days')) @@ -243,9 +243,9 @@ class Ping extends \Zotlabs\Web\Controller { } if(x($_REQUEST, 'markItemRead') && local_channel()) { - $r = q("update item set item_unseen = 0 where parent = %d and uid = %d", - intval($_REQUEST['markItemRead']), - intval(local_channel()) + $r = q("UPDATE item SET item_unseen = 0 WHERE uid = %d AND parent = %d", + intval(local_channel()), + intval($_REQUEST['markItemRead']) ); } @@ -254,7 +254,7 @@ class Ping extends \Zotlabs\Web\Controller { * dropdown menu. */ if(argc() > 1 && argv(1) === 'notify') { - $t = q("select * from notify where uid = %d and seen = 0 order by created desc", + $t = q("SELECT * FROM notify WHERE uid = %d AND seen = 0 ORDER BY CREATED DESC", intval(local_channel()) ); @@ -320,10 +320,10 @@ class Ping extends \Zotlabs\Web\Controller { $r = q("SELECT * FROM item WHERE uid = %d - AND author_xchan != '%s' AND item_unseen = 1 + AND author_xchan != '%s' $item_normal - ORDER BY created DESC, id + ORDER BY created DESC LIMIT 300", intval(local_channel()), dbesc($ob_hash) @@ -495,7 +495,7 @@ class Ping extends \Zotlabs\Web\Controller { if($vnotify & (VNOTIFY_NETWORK|VNOTIFY_CHANNEL)) { $r = q("SELECT id, item_wall FROM item - WHERE item_unseen = 1 and uid = %d + WHERE uid = %d and item_unseen = 1 $item_normal AND author_xchan != '%s'", intval(local_channel()), -- cgit v1.2.3 From 5f229d81e9aaac0e0d82091d2d9089f5fb34bfe8 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Fri, 9 Feb 2018 14:06:59 +0100 Subject: use distinct in channel item query and minor notification cache improvement --- Zotlabs/Module/Channel.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'Zotlabs/Module') diff --git a/Zotlabs/Module/Channel.php b/Zotlabs/Module/Channel.php index b7e18f954..dddca16b4 100644 --- a/Zotlabs/Module/Channel.php +++ b/Zotlabs/Module/Channel.php @@ -249,13 +249,13 @@ class Channel extends \Zotlabs\Web\Controller { } } else { - $r = q("SELECT id AS item_id FROM item + $r = q("SELECT DISTINCT item.parent AS item_id FROM item left join abook on item.author_xchan = abook.abook_xchan - WHERE uid = %d $item_normal - AND item_wall = 1 and item_thread_top = 1 - AND (abook_blocked = 0 or abook.abook_flags is null) + WHERE true and uid = %d $item_normal + AND (abook.abook_blocked = 0 or abook.abook_flags is null) + AND item.item_wall = 1 AND item.item_thread_top AND item.mid = item.parent_mid $sql_extra $sql_extra2 - ORDER BY created DESC, id $pager_sql ", + ORDER BY created DESC $pager_sql ", intval(\App::$profile['profile_uid']) ); } -- cgit v1.2.3 From 6cc32943954124739023751eb377d398a54772d9 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Fri, 9 Feb 2018 20:36:14 +0100 Subject: finally fix channel query --- Zotlabs/Module/Channel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Zotlabs/Module') diff --git a/Zotlabs/Module/Channel.php b/Zotlabs/Module/Channel.php index dddca16b4..3dab85410 100644 --- a/Zotlabs/Module/Channel.php +++ b/Zotlabs/Module/Channel.php @@ -204,7 +204,7 @@ class Channel extends \Zotlabs\Web\Controller { $_SESSION['loadtime'] = datetime_convert(); } else { - $r = q("SELECT distinct parent AS item_id, created from item + $r = q("SELECT distinct parent AS item_id from item left join abook on ( item.owner_xchan = abook.abook_xchan $abook_uids ) WHERE uid = %d $item_normal_update AND item_wall = 1 $simple_update @@ -249,11 +249,11 @@ class Channel extends \Zotlabs\Web\Controller { } } else { - $r = q("SELECT DISTINCT item.parent AS item_id FROM item - left join abook on item.author_xchan = abook.abook_xchan + $r = q("SELECT item.parent AS item_id FROM item + left join abook on ( item.author_xchan = abook.abook_xchan $abook_uids ) WHERE true and uid = %d $item_normal AND (abook.abook_blocked = 0 or abook.abook_flags is null) - AND item.item_wall = 1 AND item.item_thread_top AND item.mid = item.parent_mid + AND item.item_wall = 1 AND item.item_thread_top = 1 $sql_extra $sql_extra2 ORDER BY created DESC $pager_sql ", intval(\App::$profile['profile_uid']) -- cgit v1.2.3 From 5a9ea29614b8620c10d84f67a1a7c93fe537a037 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Fri, 9 Feb 2018 14:08:29 -0800 Subject: hubzilla issue #975 (searching for title as well as body could present a performance issue, so perhaps the tradeoffs should be debated) --- Zotlabs/Module/Search.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Module') diff --git a/Zotlabs/Module/Search.php b/Zotlabs/Module/Search.php index 4d35b59f3..55e0e746f 100644 --- a/Zotlabs/Module/Search.php +++ b/Zotlabs/Module/Search.php @@ -90,7 +90,7 @@ class Search extends \Zotlabs\Web\Controller { } else { $regstr = db_getfunc('REGEXP'); - $sql_extra = sprintf(" AND item.body $regstr '%s' ", dbesc(protect_sprintf(preg_quote($search)))); + $sql_extra = sprintf(" AND (item.title $regstr '%s' OR item.body $regstr '%s') ", dbesc(protect_sprintf(preg_quote($search))), dbesc(protect_sprintf(preg_quote($search)))); } // Here is the way permissions work in the search module... -- cgit v1.2.3 From 07d33a11830e52499842b99ded964b0a934116d7 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 11 Feb 2018 15:34:34 -0800 Subject: use new forum tag style in forum search postings --- Zotlabs/Module/Network.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Module') diff --git a/Zotlabs/Module/Network.php b/Zotlabs/Module/Network.php index 70e0048fb..6e961dc36 100644 --- a/Zotlabs/Module/Network.php +++ b/Zotlabs/Module/Network.php @@ -144,7 +144,7 @@ class Network extends \Zotlabs\Web\Controller { // NOTREACHED } if($_GET['pf'] === '1') - $deftag = '@' . t('forum') . '+' . intval($cid) . '+'; + $deftag = '!' . t('forum') . '+' . intval($cid); else $def_acl = [ 'allow_cid' => '<' . $r[0]['abook_xchan'] . '>', 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => '' ]; } -- cgit v1.2.3 From 63107f5b2f5031a7cc971063b9344592cc2257e3 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 11 Feb 2018 18:17:17 -0800 Subject: second part of hubzilla issue #972 --- Zotlabs/Module/Settings/Channel.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'Zotlabs/Module') diff --git a/Zotlabs/Module/Settings/Channel.php b/Zotlabs/Module/Settings/Channel.php index 5e9e88a6d..fb8284d2e 100644 --- a/Zotlabs/Module/Settings/Channel.php +++ b/Zotlabs/Module/Settings/Channel.php @@ -331,22 +331,21 @@ class Channel { ); $limits = \Zotlabs\Access\PermissionLimits::Get(local_channel()); + $anon_comments = get_config('system','anonymous_comments',true); foreach($global_perms as $k => $perm) { $options = array(); + $can_be_public = ((strstr($k,'view') || ($k === 'post_comments' && $anon_comments)) ? true : false); foreach($perm_opts as $opt) { - if(((! strstr($k,'view')) && $k !== 'post_comments') && $opt[1] == PERMS_PUBLIC) + if($opt[1] == PERMS_PUBLIC && (! $can_be_public)) continue; $options[$opt[1]] = $opt[0]; } $permiss[] = array($k,$perm,$limits[$k],'',$options); } - - + // logger('permiss: ' . print_r($permiss,true)); - - $username = $channel['channel_name']; $nickname = $channel['channel_address']; $timezone = $channel['channel_timezone']; -- cgit v1.2.3 From fd81a4bdc4f1c80d9dd73358452f50bc6422afef Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 12 Feb 2018 21:43:04 -0800 Subject: initial share refactor --- Zotlabs/Module/Item.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'Zotlabs/Module') diff --git a/Zotlabs/Module/Item.php b/Zotlabs/Module/Item.php index db2d64d70..73730bc99 100644 --- a/Zotlabs/Module/Item.php +++ b/Zotlabs/Module/Item.php @@ -39,6 +39,7 @@ class Item extends \Zotlabs\Web\Controller { $uid = local_channel(); $channel = null; $observer = null; + $datarray = []; /** @@ -619,6 +620,21 @@ class Item extends \Zotlabs\Web\Controller { $i++; } } + + + if(preg_match_all('/(\[share=(.*?)\](.*?)\[\/share\])/',$body,$match)) { + // process share by id + + $verb = ACTIVITY_SHARE; + $i = 0; + foreach($match[2] as $mtch) { +// $obj = get_share_activity($mtch); + $datarray['obj'] = $obj['obj']; + $datarray['obj_type'] = $obj['obj']['type']; + $body = str_replace($match[1][$i],$obj['body'],$body); + $i++; + } + } } @@ -720,7 +736,6 @@ class Item extends \Zotlabs\Web\Controller { if(!$thr_parent) $thr_parent = $mid; - $datarray = array(); $item_thread_top = ((! $parent) ? 1 : 0); -- cgit v1.2.3 From d826515ba8d2d1d78abed6701df3c2c3550e87df Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Tue, 13 Feb 2018 11:01:58 +0100 Subject: since we only save the parent mid in notify we must look for thr_parent when dealing with likes --- Zotlabs/Module/Ping.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'Zotlabs/Module') diff --git a/Zotlabs/Module/Ping.php b/Zotlabs/Module/Ping.php index 96ade22c0..eab49d69e 100644 --- a/Zotlabs/Module/Ping.php +++ b/Zotlabs/Module/Ping.php @@ -268,7 +268,18 @@ class Ping extends \Zotlabs\Web\Controller { $mid = basename($tt['link']); - $b64mid = ((strpos($mid, 'b64.' === 0)) ? $mid : 'b64.' . base64url_encode($mid)); + if(in_array($tt['verb'], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) { + // we need the thread parent + $r = q("select thr_parent from item where mid = '%s' and uid = %d limit 1", + dbesc($mid), + intval(local_channel()) + ); + + $b64mid = ((strpos($r[0]['thr_parent'], 'b64.' === 0)) ? $r[0]['thr_parent'] : 'b64.' . base64url_encode($r[0]['thr_parent'])); + } + else { + $b64mid = ((strpos($mid, 'b64.' === 0)) ? $mid : 'b64.' . base64url_encode($mid)); + } $notifs[] = array( 'notify_link' => z_root() . '/notify/view/' . $tt['id'], -- cgit v1.2.3 From 6ca3442ba381a3c5b98cd04f4f9e87e48c55b072 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 13 Feb 2018 12:13:37 -0800 Subject: defperms: bad query --- Zotlabs/Module/Defperms.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Module') diff --git a/Zotlabs/Module/Defperms.php b/Zotlabs/Module/Defperms.php index 422333a50..97d9cfd1d 100644 --- a/Zotlabs/Module/Defperms.php +++ b/Zotlabs/Module/Defperms.php @@ -22,7 +22,7 @@ class Defperms extends \Zotlabs\Web\Controller { $r = q("SELECT abook.*, xchan.* FROM abook left join xchan on abook_xchan = xchan_hash - WHERE abook_self = 1 and abook_id = %d LIMIT 1", + WHERE abook_self = 1 and abook_channel = %d LIMIT 1", intval(local_channel()) ); if($r) { -- cgit v1.2.3 From 64809dd2777ae0064addaff765450cf3f05c3bc4 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 13 Feb 2018 20:07:57 -0800 Subject: turn shares into activities - make certain to pull addons or JSON-LD will chuck a wobbly --- Zotlabs/Module/Item.php | 8 ++++---- Zotlabs/Module/Share.php | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'Zotlabs/Module') diff --git a/Zotlabs/Module/Item.php b/Zotlabs/Module/Item.php index 73730bc99..3f857030b 100644 --- a/Zotlabs/Module/Item.php +++ b/Zotlabs/Module/Item.php @@ -628,10 +628,10 @@ class Item extends \Zotlabs\Web\Controller { $verb = ACTIVITY_SHARE; $i = 0; foreach($match[2] as $mtch) { -// $obj = get_share_activity($mtch); - $datarray['obj'] = $obj['obj']; - $datarray['obj_type'] = $obj['obj']['type']; - $body = str_replace($match[1][$i],$obj['body'],$body); + $reshare = new \Zotlabs\Lib\Share($mtch); + $datarray['obj'] = $reshare->obj(); + $datarray['obj_type'] = $datarray['obj']['type']; + $body = str_replace($match[1][$i],$reshare->bbcode(),$body); $i++; } } diff --git a/Zotlabs/Module/Share.php b/Zotlabs/Module/Share.php index 5c4811c59..7f4d8b1eb 100644 --- a/Zotlabs/Module/Share.php +++ b/Zotlabs/Module/Share.php @@ -14,6 +14,10 @@ class Share extends \Zotlabs\Web\Controller { if(! $post_id) killme(); + + echo '[share=' . $post_id . '][/share]'; + killme(); + if(! (local_channel() || remote_channel())) killme(); -- cgit v1.2.3 From 465d89129caaaa0240229f8d6f81d68f26eb60b0 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 14 Feb 2018 15:32:33 -0800 Subject: provide option to block the public stream unless authenticated, since there could be legal issues with unmoderated content --- Zotlabs/Module/Admin/Site.php | 4 +++- Zotlabs/Module/Pubstream.php | 7 +++---- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'Zotlabs/Module') diff --git a/Zotlabs/Module/Admin/Site.php b/Zotlabs/Module/Admin/Site.php index 52b36e03e..ca181d5f8 100644 --- a/Zotlabs/Module/Admin/Site.php +++ b/Zotlabs/Module/Admin/Site.php @@ -45,6 +45,7 @@ class Site { $force_publish = ((x($_POST,'publish_all')) ? True : False); $disable_discover_tab = ((x($_POST,'disable_discover_tab')) ? False : True); $site_firehose = ((x($_POST,'site_firehose')) ? True : False); + $open_pubstream = ((x($_POST,'open_pubstream')) ? True : False); $login_on_homepage = ((x($_POST,'login_on_homepage')) ? True : False); $enable_context_help = ((x($_POST,'enable_context_help')) ? True : False); $global_directory = ((x($_POST,'directory_submit_url')) ? notags(trim($_POST['directory_submit_url'])) : ''); @@ -139,6 +140,7 @@ class Site { set_config('system','publish_all', $force_publish); set_config('system','disable_discover_tab', $disable_discover_tab); set_config('system','site_firehose', $site_firehose); + set_config('system','open_pubstream', $open_pubstream); set_config('system','force_queue_threshold', $force_queue); if ($global_directory == '') { del_config('system', 'directory_submit_url'); @@ -319,7 +321,7 @@ class Site { '$force_publish' => array('publish_all', t("Force publish"), get_config('system','publish_all'), t("Check to force all profiles on this site to be listed in the site directory.")), '$disable_discover_tab' => array('disable_discover_tab', t('Import Public Streams'), $discover_tab, t('Import and allow access to public content pulled from other sites. Warning: this content is unmoderated.')), '$site_firehose' => array('site_firehose', t('Site only Public Streams'), get_config('system','site_firehose'), t('Allow access to public content originating only from this site if Imported Public Streams are disabled.')), - + '$open_pubstream' => array('open_pubstream', t('Allow anybody on the internet to access the Public streams'), get_config('system','open_pubstream',1), t('Disable to require authentication before viewing. Warning: this content is unmoderated.')), '$login_on_homepage' => array('login_on_homepage', t("Login on Homepage"),((intval($homelogin) || $homelogin === false) ? 1 : '') , t("Present a login box to visitors on the home page if no other content has been configured.")), '$enable_context_help' => array('enable_context_help', t("Enable context help"),((intval($enable_context_help) === 1 || $enable_context_help === false) ? 1 : 0) , t("Display contextual help for the current page when the help button is pressed.")), diff --git a/Zotlabs/Module/Pubstream.php b/Zotlabs/Module/Pubstream.php index 16a5fdbba..afe53eca7 100644 --- a/Zotlabs/Module/Pubstream.php +++ b/Zotlabs/Module/Pubstream.php @@ -12,11 +12,10 @@ class Pubstream extends \Zotlabs\Web\Controller { if($load) $_SESSION['loadtime'] = datetime_convert(); - - if(observer_prohibited(true)) { - return login(); + if((observer_prohibited(true)) || (! (intval(get_config('system','open_pubstream',1))) && get_observer_hash())) { + return login(); } - + $site_firehose = ((intval(get_config('system','site_firehose',0))) ? true : false); $net_firehose = ((get_config('system','disable_discover_tab',1)) ? false : true); -- cgit v1.2.3 From 9e251a1abcc50af0f678a17d3a688f4ba9e4a4fc Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Thu, 15 Feb 2018 19:24:15 +0100 Subject: some more DB tuning. --- Zotlabs/Module/Channel.php | 4 ++-- Zotlabs/Module/Pubstream.php | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'Zotlabs/Module') diff --git a/Zotlabs/Module/Channel.php b/Zotlabs/Module/Channel.php index 3dab85410..231146999 100644 --- a/Zotlabs/Module/Channel.php +++ b/Zotlabs/Module/Channel.php @@ -251,9 +251,9 @@ class Channel extends \Zotlabs\Web\Controller { else { $r = q("SELECT item.parent AS item_id FROM item left join abook on ( item.author_xchan = abook.abook_xchan $abook_uids ) - WHERE true and uid = %d $item_normal + WHERE true and item.uid = %d AND item.item_thread_top = 1 $item_normal AND (abook.abook_blocked = 0 or abook.abook_flags is null) - AND item.item_wall = 1 AND item.item_thread_top = 1 + AND item.item_wall = 1 $sql_extra $sql_extra2 ORDER BY created DESC $pager_sql ", intval(\App::$profile['profile_uid']) diff --git a/Zotlabs/Module/Pubstream.php b/Zotlabs/Module/Pubstream.php index afe53eca7..af7bc7658 100644 --- a/Zotlabs/Module/Pubstream.php +++ b/Zotlabs/Module/Pubstream.php @@ -166,7 +166,8 @@ class Pubstream extends \Zotlabs\Web\Controller { $net_query = (($net) ? " left join xchan on xchan_hash = author_xchan " : ''); $net_query2 = (($net) ? " and xchan_network = '" . protect_sprintf(dbesc($net)) . "' " : ''); - + + $abook_uids = " and abook.abook_channel = " . intval(\App::$profile['profile_uid']) . " "; $simple_update = (($_SESSION['loadtime']) ? " AND item.changed > '" . datetime_convert('UTC','UTC',$_SESSION['loadtime']) . "' " : ''); @@ -185,7 +186,7 @@ class Pubstream extends \Zotlabs\Web\Controller { if($load) { if($mid) { $r = q("SELECT parent AS item_id FROM item - left join abook on item.author_xchan = abook.abook_xchan + left join abook on item.author_xchan = abook.abook_xchan $net_query WHERE mid like '%s' $uids $item_normal and (abook.abook_blocked = 0 or abook.abook_flags is null) @@ -196,10 +197,9 @@ class Pubstream extends \Zotlabs\Web\Controller { else { // Fetch a page full of parent items for this page $r = q("SELECT item.id AS item_id FROM item - left join abook on item.author_xchan = abook.abook_xchan + left join abook on ( item.author_xchan = abook.abook_xchan $abook_uids ) $net_query - WHERE item_thread_top = 1 $uids $item_normal - AND item.parent = item.id + WHERE true $uids and item.item_thread_top = 1 $item_normal and (abook.abook_blocked = 0 or abook.abook_flags is null) $sql_extra3 $sql_extra $sql_nets $net_query2 ORDER BY $ordering DESC $pager_sql " -- cgit v1.2.3 From 27cd26ec1e26b6c389a623395687af5052f0b5a1 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 15 Feb 2018 18:47:56 -0800 Subject: extend the oauth2 storage driver so that we can use our own channel table --- Zotlabs/Module/Authorize.php | 55 +++++++++++++++++++++----------------------- Zotlabs/Module/Token.php | 46 +++++++++++++++++------------------- 2 files changed, 47 insertions(+), 54 deletions(-) (limited to 'Zotlabs/Module') diff --git a/Zotlabs/Module/Authorize.php b/Zotlabs/Module/Authorize.php index 06f66c456..7676b0855 100644 --- a/Zotlabs/Module/Authorize.php +++ b/Zotlabs/Module/Authorize.php @@ -6,41 +6,38 @@ namespace Zotlabs\Module; class Authorize extends \Zotlabs\Web\Controller { - function get() { + function init() { - // workaround for HTTP-auth in CGI mode - if (x($_SERVER, 'REDIRECT_REMOTE_USER')) { - $userpass = base64_decode(substr($_SERVER["REDIRECT_REMOTE_USER"], 6)) ; - if(strlen($userpass)) { - list($name, $password) = explode(':', $userpass); - $_SERVER['PHP_AUTH_USER'] = $name; - $_SERVER['PHP_AUTH_PW'] = $password; - } + // workaround for HTTP-auth in CGI mode + if (x($_SERVER, 'REDIRECT_REMOTE_USER')) { + $userpass = base64_decode(substr($_SERVER["REDIRECT_REMOTE_USER"], 6)) ; + if(strlen($userpass)) { + list($name, $password) = explode(':', $userpass); + $_SERVER['PHP_AUTH_USER'] = $name; + $_SERVER['PHP_AUTH_PW'] = $password; } - - if (x($_SERVER, 'HTTP_AUTHORIZATION')) { - $userpass = base64_decode(substr($_SERVER["HTTP_AUTHORIZATION"], 6)) ; - if(strlen($userpass)) { - list($name, $password) = explode(':', $userpass); - $_SERVER['PHP_AUTH_USER'] = $name; - $_SERVER['PHP_AUTH_PW'] = $password; - } + } + + if (x($_SERVER, 'HTTP_AUTHORIZATION')) { + $userpass = base64_decode(substr($_SERVER["HTTP_AUTHORIZATION"], 6)) ; + if(strlen($userpass)) { + list($name, $password) = explode(':', $userpass); + $_SERVER['PHP_AUTH_USER'] = $name; + $_SERVER['PHP_AUTH_PW'] = $password; } + } + $s = new \Zotlabs\Identity\OAuth2Server(); + $request = \OAuth2\Request::createFromGlobals(); + $response = new \OAuth2\Response(); - - require_once('include/oauth2.php'); - - $request = \OAuth2\Request::createFromGlobals(); - $response = new \OAuth2\Response(); - - // validate the authorize request - if (! $oauth2_server->validateAuthorizeRequest($request, $response)) { - $response->send(); - killme(); - } + // validate the authorize request + if (! $s->server->validateAuthorizeRequest($request, $response)) { + $response->send(); + killme(); + } // display an authorization form if (empty($_POST)) { @@ -55,7 +52,7 @@ class Authorize extends \Zotlabs\Web\Controller { // print the authorization code if the user has authorized your client $is_authorized = ($_POST['authorized'] === 'yes'); - $oauth2_server->handleAuthorizeRequest($request, $response, $is_authorized); + $s->server->handleAuthorizeRequest($request, $response, $is_authorized, local_channel()); if ($is_authorized) { // this is only here so that you get to see your code in the cURL request. Otherwise, // we'd redirect back to the client diff --git a/Zotlabs/Module/Token.php b/Zotlabs/Module/Token.php index e0d9d74d7..5cde58895 100644 --- a/Zotlabs/Module/Token.php +++ b/Zotlabs/Module/Token.php @@ -5,36 +5,32 @@ namespace Zotlabs\Module; class Token extends \Zotlabs\Web\Controller { - - function get() { - - - // workaround for HTTP-auth in CGI mode - if (x($_SERVER, 'REDIRECT_REMOTE_USER')) { - $userpass = base64_decode(substr($_SERVER["REDIRECT_REMOTE_USER"], 6)) ; - if(strlen($userpass)) { - list($name, $password) = explode(':', $userpass); - $_SERVER['PHP_AUTH_USER'] = $name; - $_SERVER['PHP_AUTH_PW'] = $password; - } + function init() { + + // workaround for HTTP-auth in CGI mode + if (x($_SERVER, 'REDIRECT_REMOTE_USER')) { + $userpass = base64_decode(substr($_SERVER["REDIRECT_REMOTE_USER"], 6)) ; + if(strlen($userpass)) { + list($name, $password) = explode(':', $userpass); + $_SERVER['PHP_AUTH_USER'] = $name; + $_SERVER['PHP_AUTH_PW'] = $password; } - - if (x($_SERVER, 'HTTP_AUTHORIZATION')) { - $userpass = base64_decode(substr($_SERVER["HTTP_AUTHORIZATION"], 6)) ; - if(strlen($userpass)) { - list($name, $password) = explode(':', $userpass); - $_SERVER['PHP_AUTH_USER'] = $name; - $_SERVER['PHP_AUTH_PW'] = $password; - } + } + + if (x($_SERVER, 'HTTP_AUTHORIZATION')) { + $userpass = base64_decode(substr($_SERVER["HTTP_AUTHORIZATION"], 6)) ; + if(strlen($userpass)) { + list($name, $password) = explode(':', $userpass); + $_SERVER['PHP_AUTH_USER'] = $name; + $_SERVER['PHP_AUTH_PW'] = $password; } + } + $s = new \Zotlabs\Identity\OAuth2Server(); + $s->server->handleTokenRequest(\OAuth2\Request::createFromGlobals())->send(); - - require_once('include/oauth2.php'); - $oauth2_server->handleTokenRequest(\OAuth2\Request::createFromGlobals())->send(); - - killme(); + killme(); } } \ No newline at end of file -- cgit v1.2.3 From f492f808f4861ae9937dcaf3bf8476513ae1c091 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Fri, 16 Feb 2018 12:42:02 -0800 Subject: refactor of the DB update system. Updates are now stored individually in Zotlabs/Update/_nnnn.php and are objects; so only the pending updates need to be loaded and executed rather than all historical updates. There is one single number (DB_UPDATE_VERSION) representing the current version and it is EQUAL TO the last known update. A dummy update _1201 was created to address the difference in counting behaviour; it will be executed on the next change of DB_UPDATE_VERSION as well as the next update. The database config values are also loaded from disk on every update immediately before setting the update lock in order to reduce timing conflicts and race conditions. --- Zotlabs/Module/Admin/Dbsync.php | 54 ++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 25 deletions(-) (limited to 'Zotlabs/Module') diff --git a/Zotlabs/Module/Admin/Dbsync.php b/Zotlabs/Module/Admin/Dbsync.php index cff8a2484..469af2aa5 100644 --- a/Zotlabs/Module/Admin/Dbsync.php +++ b/Zotlabs/Module/Admin/Dbsync.php @@ -7,36 +7,38 @@ namespace Zotlabs\Module\Admin; class Dbsync { - - function get() { $o = ''; if(argc() > 3 && intval(argv(3)) && argv(2) === 'mark') { - set_config('database', 'update_r' . intval(argv(3)), 'success'); - if(intval(get_config('system','db_version')) <= intval(argv(3))) - set_config('system','db_version',intval(argv(3)) + 1); + // remove the old style config if it exists + del_config('database', 'update_r' . intval(argv(3))); + set_config('database', '_' . intval(argv(3)), 'success'); + if(intval(get_config('system','db_version')) < intval(argv(3))) + set_config('system','db_version',intval(argv(3))); info( t('Update has been marked successful') . EOL); goaway(z_root() . '/admin/dbsync'); } if(argc() > 2 && intval(argv(2))) { - require_once('install/update.php'); - $func = 'update_r' . intval(argv(2)); - if(function_exists($func)) { - $retval = $func(); + $x = intval(argv(2)); + $s = '_' . $x; + $cls = '\\Zotlabs\Update\\' . $s ; + if(class_exists($cls)) { + $c = new $cls(); + $retval = $c->run(); if($retval === UPDATE_FAILED) { - $o .= sprintf( t('Executing %s failed. Check system logs.'), $func); + $o .= sprintf( t('Executing %s failed. Check system logs.'), $s); } elseif($retval === UPDATE_SUCCESS) { - $o .= sprintf( t('Update %s was successfully applied.'), $func); - set_config('database',$func, 'success'); + $o .= sprintf( t('Update %s was successfully applied.'), $s); + set_config('database',$s, 'success'); } else - $o .= sprintf( t('Update %s did not return a status. Unknown if it succeeded.'), $func); + $o .= sprintf( t('Update %s did not return a status. Unknown if it succeeded.'), $s); } else - $o .= sprintf( t('Update function %s could not be found.'), $func); + $o .= sprintf( t('Update function %s could not be found.'), $s); return $o; } @@ -45,23 +47,25 @@ class Dbsync { $r = q("select * from config where cat = 'database' "); if(count($r)) { foreach($r as $rr) { - $upd = intval(substr($rr['k'],8)); + $upd = intval(substr($rr['k'],-4)); if($rr['v'] === 'success') continue; $failed[] = $upd; } } - if(! count($failed)) - return '

' . t('No failed updates.') . '

'; - - $o = replace_macros(get_markup_template('failed_updates.tpl'),array( - '$base' => z_root(), - '$banner' => t('Failed Updates'), - '$desc' => '', - '$mark' => t('Mark success (if update was manually applied)'), - '$apply' => t('Attempt to execute this update step automatically'), - '$failed' => $failed + if(count($failed)) { + $o = replace_macros(get_markup_template('failed_updates.tpl'),array( + '$base' => z_root(), + '$banner' => t('Failed Updates'), + '$desc' => '', + '$mark' => t('Mark success (if update was manually applied)'), + '$apply' => t('Attempt to execute this update step automatically'), + '$failed' => $failed )); + } + else { + return '

' . t('No failed updates.') . '

'; + } return $o; } -- cgit v1.2.3 From 4a5d1076eda66f4d562219468b84dff2bd8de86b Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Sat, 17 Feb 2018 01:49:01 +0100 Subject: Refactor OAuth2Server a bit. --- Zotlabs/Module/Authorize.php | 45 ++++++++++++++++++++++---------------------- Zotlabs/Module/Token.php | 9 +++++---- 2 files changed, 27 insertions(+), 27 deletions(-) (limited to 'Zotlabs/Module') diff --git a/Zotlabs/Module/Authorize.php b/Zotlabs/Module/Authorize.php index 7676b0855..254700b4e 100644 --- a/Zotlabs/Module/Authorize.php +++ b/Zotlabs/Module/Authorize.php @@ -2,13 +2,13 @@ namespace Zotlabs\Module; +use Zotlabs\Identity\OAuth2Storage; -class Authorize extends \Zotlabs\Web\Controller { +class Authorize extends \Zotlabs\Web\Controller { function init() { - // workaround for HTTP-auth in CGI mode if (x($_SERVER, 'REDIRECT_REMOTE_USER')) { $userpass = base64_decode(substr($_SERVER["REDIRECT_REMOTE_USER"], 6)) ; @@ -28,41 +28,40 @@ class Authorize extends \Zotlabs\Web\Controller { } } - $s = new \Zotlabs\Identity\OAuth2Server(); + $s = new \Zotlabs\Identity\OAuth2Server(new OAuth2Storage(\DBA::$dba->db)); $request = \OAuth2\Request::createFromGlobals(); $response = new \OAuth2\Response(); // validate the authorize request - if (! $s->server->validateAuthorizeRequest($request, $response)) { - $response->send(); - killme(); + if (! $s->validateAuthorizeRequest($request, $response)) { + $response->send(); + killme(); } - // display an authorization form - if (empty($_POST)) { + // display an authorization form + if (empty($_POST)) { - return ' + return '

'; - } + } - // print the authorization code if the user has authorized your client - $is_authorized = ($_POST['authorized'] === 'yes'); - $s->server->handleAuthorizeRequest($request, $response, $is_authorized, local_channel()); - if ($is_authorized) { - // this is only here so that you get to see your code in the cURL request. Otherwise, - // we'd redirect back to the client - $code = substr($response->getHttpHeader('Location'), strpos($response->getHttpHeader('Location'), 'code=')+5, 40); - echo("SUCCESS! Authorization Code: $code"); - - } + // print the authorization code if the user has authorized your client + $is_authorized = ($_POST['authorized'] === 'yes'); + $s->handleAuthorizeRequest($request, $response, $is_authorized, local_channel()); + if ($is_authorized) { + // this is only here so that you get to see your code in the cURL request. Otherwise, + // we'd redirect back to the client + $code = substr($response->getHttpHeader('Location'), strpos($response->getHttpHeader('Location'), 'code=')+5, 40); + echo("SUCCESS! Authorization Code: $code"); + } - $response->send(); - killme(); + $response->send(); + killme(); } -} \ No newline at end of file +} diff --git a/Zotlabs/Module/Token.php b/Zotlabs/Module/Token.php index 5cde58895..f7c074233 100644 --- a/Zotlabs/Module/Token.php +++ b/Zotlabs/Module/Token.php @@ -2,6 +2,8 @@ namespace Zotlabs\Module; +use Zotlabs\Identity\OAuth2Storage; + class Token extends \Zotlabs\Web\Controller { @@ -26,11 +28,10 @@ class Token extends \Zotlabs\Web\Controller { } } - - $s = new \Zotlabs\Identity\OAuth2Server(); - $s->server->handleTokenRequest(\OAuth2\Request::createFromGlobals())->send(); + $s = new \Zotlabs\Identity\OAuth2Server(new OAuth2Storage(\DBA::$dba->db)); + $s->handleTokenRequest(\OAuth2\Request::createFromGlobals())->send(); killme(); } -} \ No newline at end of file +} -- cgit v1.2.3 From ce8349662d8c9e309f3faf57114acddb67eb11b7 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 19 Feb 2018 20:12:58 -0800 Subject: Add 'Validate' button to new_channel page and disable submit until validated. This is to get around the issue that clicking submit without ever focusing and blurring the nickname field won't actually submit the form but only provide validation. It needs to be clicked again to submit. The first click processed the blur but remained on the page with no feedback. If somebody has better workarounds, please provide. The goal is to ensure that the name and the nickname are both validated before we can submit. --- Zotlabs/Module/New_channel.php | 1 + 1 file changed, 1 insertion(+) (limited to 'Zotlabs/Module') diff --git a/Zotlabs/Module/New_channel.php b/Zotlabs/Module/New_channel.php index 9f2fea802..548f28c4f 100644 --- a/Zotlabs/Module/New_channel.php +++ b/Zotlabs/Module/New_channel.php @@ -142,6 +142,7 @@ class New_channel extends \Zotlabs\Web\Controller { '$role' => $role, '$default_role' => $default_role, '$nickname' => $nickname, + '$validate' => t('Validate'), '$submit' => t('Create'), '$channel_usage_message' => $channel_usage_message )); -- cgit v1.2.3