From 3cebdee8677687466aa5597026ab4d37c76bba9f Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 29 Nov 2017 20:28:30 -0500 Subject: [PATCH 01/71] Fix mod/admin.php formatting --- mod/admin.php | 586 +++++++++++++++++++++++++------------------------- 1 file changed, 291 insertions(+), 295 deletions(-) diff --git a/mod/admin.php b/mod/admin.php index 4b034b8cc..cdcd688f2 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -1,11 +1,10 @@ argc > 2 && - is_file("addon/".$a->argv[2]."/".$a->argv[2].".php")) { - @include_once("addon/".$a->argv[2]."/".$a->argv[2].".php"); - if (function_exists($a->argv[2].'_plugin_admin_post')) { - $func = $a->argv[2].'_plugin_admin_post'; - $func($a); - } + is_file("addon/" . $a->argv[2] . "/" . $a->argv[2] . ".php")) { + @include_once("addon/" . $a->argv[2] . "/" . $a->argv[2] . ".php"); + if (function_exists($a->argv[2] . '_plugin_admin_post')) { + $func = $a->argv[2] . '_plugin_admin_post'; + $func($a); + } } - goaway('admin/plugins/'.$a->argv[2]); + goaway('admin/plugins/' . $a->argv[2]); return; // NOTREACHED break; case 'themes': @@ -75,7 +75,9 @@ function admin_post(App $a) { $theme = $a->argv[2]; if (is_file("view/theme/$theme/config.php")) { - function __call_theme_admin_post(App $a, $theme) { + + function __call_theme_admin_post(App $a, $theme) + { $orig_theme = $a->theme; $orig_page = $a->page; $orig_session_theme = $_SESSION['theme']; @@ -84,7 +86,7 @@ function admin_post(App $a) { $_SESSION['theme'] = $theme; - $init = $theme."_init"; + $init = $theme . "_init"; if (function_exists($init)) { $init($a); } @@ -103,7 +105,7 @@ function admin_post(App $a) { if (is_ajax()) { return; } - goaway('admin/themes/'.$theme); + goaway('admin/themes/' . $theme); return; break; case 'features': @@ -145,13 +147,14 @@ function admin_post(App $a) { * @param App $a * @return string */ -function admin_content(App $a) { +function admin_content(App $a) +{ if (!is_site_admin()) { return login(false); } - if (x($_SESSION,'submanage') && intval($_SESSION['submanage'])) { + if (x($_SESSION, 'submanage') && intval($_SESSION['submanage'])) { return ""; } @@ -160,7 +163,6 @@ function admin_content(App $a) { // $toDelete = new APCIterator('user', APC_ITER_VALUE); // apc_delete($toDelete); //} - // Header stuff $a->page['htmlhead'] .= replace_macros(get_markup_template('admin_settings_head.tpl'), array()); @@ -171,25 +173,25 @@ function admin_content(App $a) { // array(url, name, extra css classes) // not part of $aside to make the template more adjustable $aside_sub = array( - 'site' => array("admin/site/", t("Site") , "site"), - 'users' => array("admin/users/", t("Users") , "users"), - 'plugins'=> array("admin/plugins/", t("Plugins") , "plugins"), - 'themes' => array("admin/themes/", t("Themes") , "themes"), - 'features' => array("admin/features/", t("Additional features") , "features"), - 'dbsync' => array("admin/dbsync/", t('DB updates'), "dbsync"), - 'queue' => array("admin/queue/", t('Inspect Queue'), "queue"), - 'blocklist' => array("admin/blocklist/", t('Server Blocklist'), "blocklist"), - 'federation' => array("admin/federation/", t('Federation Statistics'), "federation"), - 'deleteitem' => array("admin/deleteitem/", t('Delete Item'), 'deleteitem'), + 'site' => array("admin/site/" , t("Site") , "site"), + 'users' => array("admin/users/" , t("Users") , "users"), + 'plugins' => array("admin/plugins/" , t("Plugins") , "plugins"), + 'themes' => array("admin/themes/" , t("Themes") , "themes"), + 'features' => array("admin/features/" , t("Additional features") , "features"), + 'dbsync' => array("admin/dbsync/" , t('DB updates') , "dbsync"), + 'queue' => array("admin/queue/" , t('Inspect Queue') , "queue"), + 'blocklist' => array("admin/blocklist/" , t('Server Blocklist') , "blocklist"), + 'federation' => array("admin/federation/" , t('Federation Statistics'), "federation"), + 'deleteitem' => array("admin/deleteitem/" , t('Delete Item') , 'deleteitem'), ); /* get plugins admin page */ $r = q("SELECT `name` FROM `addon` WHERE `plugin_admin` = 1 ORDER BY `name`"); - $aside_tools['plugins_admin']=array(); + $aside_tools['plugins_admin'] = array(); foreach ($r as $h) { - $plugin =$h['name']; - $aside_tools['plugins_admin'][] = array("admin/plugins/".$plugin, $plugin, "plugin"); + $plugin = $h['name']; + $aside_tools['plugins_admin'][] = array("admin/plugins/" . $plugin, $plugin, "plugin"); // temp plugins with admin $a->plugins_admin[] = $plugin; } @@ -208,7 +210,7 @@ function admin_content(App $a) { '$logtxt' => t('Logs'), '$diagnosticstxt' => t('diagnostics'), '$h_pending' => t('User registrations waiting for confirmation'), - '$admurl'=> "admin/" + '$admurl' => "admin/" )); @@ -283,15 +285,16 @@ function admin_content(App $a) { * @param App $a * @return string */ -function admin_page_blocklist(App $a) { +function admin_page_blocklist(App $a) +{ $blocklist = Config::get('system', 'blocklist'); $blocklistform = array(); if (is_array($blocklist)) { - foreach($blocklist as $id => $b) { + foreach ($blocklist as $id => $b) { $blocklistform[] = array( 'domain' => array("domain[$id]", t('Blocked domain'), $b['domain'], '', t('The blocked domain'), 'required', '', ''), - 'reason' => array("reason[$id]", t("Reason for the block"), $b['reason'], t('The reason why you blocked this domain.').'('.$b['domain'].')', 'required', '', ''), - 'delete' => array("delete[$id]", t("Delete domain").' ('.$b['domain'].')', False , t("Check to delete this entry from the blocklist")) + 'reason' => array("reason[$id]", t("Reason for the block"), $b['reason'], t('The reason why you blocked this domain.') . '(' . $b['domain'] . ')', 'required', '', ''), + 'delete' => array("delete[$id]", t("Delete domain") . ' (' . $b['domain'] . ')', False, t("Check to delete this entry from the blocklist")) ); } } @@ -313,7 +316,7 @@ function admin_page_blocklist(App $a) { '$entries' => $blocklistform, '$baseurl' => System::baseUrl(true), '$confirm_delete' => t('Delete entry from blocklist?'), - '$form_security_token' => get_form_security_token("admin_blocklist") + '$form_security_token' => get_form_security_token("admin_blocklist") )); } @@ -322,8 +325,9 @@ function admin_page_blocklist(App $a) { * * @param App $a */ -function admin_page_blocklist_post(App $a) { - if (!x($_POST,"page_blocklist_save") && (!x($_POST['page_blocklist_edit']))) { +function admin_page_blocklist_post(App $a) +{ + if (!x($_POST, "page_blocklist_save") && (!x($_POST['page_blocklist_edit']))) { return; } @@ -337,7 +341,7 @@ function admin_page_blocklist_post(App $a) { 'reason' => notags(trim($_POST['newentry_reason'])) ); Config::set('system', 'blocklist', $blocklist); - info(t('Server added to blocklist.').EOL); + info(t('Server added to blocklist.') . EOL); } else { // Edit the entries from blocklist $blocklist = array(); @@ -353,7 +357,7 @@ function admin_page_blocklist_post(App $a) { } } Config::set('system', 'blocklist', $blocklist); - info(t('Site blocklist updated.').EOL); + info(t('Site blocklist updated.') . EOL); } goaway('admin/blocklist'); @@ -370,7 +374,8 @@ function admin_page_blocklist_post(App $a) { * @param App $a * @return string */ -function admin_page_deleteitem(App $a) { +function admin_page_deleteitem(App $a) +{ $t = get_markup_template("admin_deleteitem.tpl"); return replace_macros($t, array( @@ -381,9 +386,10 @@ function admin_page_deleteitem(App $a) { '$intro2' => t('You need to know the GUID of the item. You can find it e.g. by looking at the display URL. The last part of http://example.com/display/123456 is the GUID, here 123456.'), '$deleteitemguid' => array('deleteitemguid', t("GUID"), '', t("The GUID of the item you want to delete."), 'required', 'autofocus'), '$baseurl' => System::baseUrl(), - '$form_security_token' => get_form_security_token("admin_deleteitem") + '$form_security_token' => get_form_security_token("admin_deleteitem") )); } + /** * @brief Process send data from Admin Delete Item Page * @@ -392,7 +398,8 @@ function admin_page_deleteitem(App $a) { * * @param App $a */ -function admin_page_deleteitem_post(App $a) { +function admin_page_deleteitem_post(App $a) +{ if (!x($_POST['page_deleteitem_submit'])) { return; } @@ -404,19 +411,19 @@ function admin_page_deleteitem_post(App $a) { // The GUID should not include a "/", so if there is one, we got an URL // and the last part of it is most likely the GUID. if (strpos($guid, '/')) { - $guid = substr($guid, strrpos($guid, '/')+1); + $guid = substr($guid, strrpos($guid, '/') + 1); } // Now that we have the GUID get all IDs of the associated entries in the // item table of the DB and drop those items, which will also delete the // associated threads. - $r = dba::select('item', array('id'), array('guid'=>$guid)); + $r = dba::select('item', array('id'), array('guid' => $guid)); while ($row = dba::fetch($r)) { drop_item($row['id'], false); } dba::close($r); } - info(t('Item marked for deletion.').EOL); + info(t('Item marked for deletion.') . EOL); goaway('admin/deleteitem'); return; // NOTREACHED } @@ -435,7 +442,8 @@ function admin_page_deleteitem_post(App $a) { * @param App $a * @return string */ -function admin_page_federation(App $a) { +function admin_page_federation(App $a) +{ // get counts on active friendica, diaspora, redmatrix, hubzilla, gnu // social and statusnet nodes this node is knowing // @@ -445,15 +453,17 @@ function admin_page_federation(App $a) { // Add more platforms if you like, when one returns 0 known nodes it is not // displayed on the stats page. $platforms = array('Friendi%%a', 'Diaspora', '%%red%%', 'Hubzilla', 'BlaBlaNet', 'GNU Social', 'StatusNet', 'Mastodon', 'Pleroma'); - $colors = array('Friendi%%a' => '#ffc018', // orange from the logo - 'Diaspora' => '#a1a1a1', // logo is black and white, makes a gray - '%%red%%' => '#c50001', // fire red from the logo - 'Hubzilla' => '#43488a', // blue from the logo - 'BlaBlaNet' => '#3B5998', // blue from the navbar at blablanet-dot-com - 'GNU Social'=> '#a22430', // dark red from the logo - 'StatusNet' => '#789240', // the green from the logo (red and blue have already others - 'Mastodon' => '#1a9df9', // blue from the Mastodon logo - 'Pleroma' => '#E46F0F'); // Orange from the text that is used on Pleroma instances + $colors = array( + 'Friendi%%a' => '#ffc018', // orange from the logo + 'Diaspora' => '#a1a1a1', // logo is black and white, makes a gray + '%%red%%' => '#c50001', // fire red from the logo + 'Hubzilla' => '#43488a', // blue from the logo + 'BlaBlaNet' => '#3B5998', // blue from the navbar at blablanet-dot-com + 'GNU Social' => '#a22430', // dark red from the logo + 'StatusNet' => '#789240', // the green from the logo (red and blue have already others + 'Mastodon' => '#1a9df9', // blue from the Mastodon logo + 'Pleroma' => '#E46F0F' // Orange from the text that is used on Pleroma instances + ); $counts = array(); $total = 0; @@ -480,7 +490,7 @@ function admin_page_federation(App $a) { // to the version string for the displayed list. foreach ($v as $key => $value) { if ($v[$key]['version'] == '') { - $v[$key] = array('total'=>$v[$key]['total'], 'version'=>t('unknown')); + $v[$key] = array('total' => $v[$key]['total'], 'version' => t('unknown')); } } // in the DB the Diaspora versions have the format x.x.x.x-xx the last @@ -503,7 +513,7 @@ function admin_page_federation(App $a) { } } foreach ($newV as $key => $value) { - array_push($newVv, array('total'=>$value, 'version'=>$key)); + array_push($newVv, array('total' => $value, 'version' => $key)); } $v = $newVv; } @@ -517,9 +527,9 @@ function admin_page_federation(App $a) { foreach ($v as $vv) { $newVC = $vv['total']; $newVV = $vv['version']; - $lastDot = strrpos($newVV,'.'); - $len = strlen($newVV)-1; - if (($lastDot == $len-4) && (!strrpos($newVV,'-rc') == $len-3)) { + $lastDot = strrpos($newVV, '.'); + $len = strlen($newVV) - 1; + if (($lastDot == $len - 4) && (!strrpos($newVV, '-rc') == $len - 3)) { $newVV = substr($newVV, 0, $lastDot); } if (isset($newV[$newVV])) { @@ -529,7 +539,7 @@ function admin_page_federation(App $a) { } } foreach ($newV as $key => $value) { - array_push($newVv, array('total'=>$value, 'version'=>$key)); + array_push($newVv, array('total' => $value, 'version' => $key)); } $v = $newVv; } @@ -539,7 +549,7 @@ function admin_page_federation(App $a) { // the 3rd array item is needed for the JavaScript graphs as JS does // not like some characters in the names of variables... - $counts[$p]=array($c[0], $v, str_replace(array(' ','%'),'',$p), $colors[$p]); + $counts[$p] = array($c[0], $v, str_replace(array(' ', '%'), '', $p), $colors[$p]); } // some helpful text @@ -574,7 +584,8 @@ function admin_page_federation(App $a) { * @param App $a * @return string */ -function admin_page_queue(App $a) { +function admin_page_queue(App $a) +{ // get content from the queue table $r = q("SELECT `c`.`name`, `c`.`nurl`, `q`.`id`, `q`.`network`, `q`.`created`, `q`.`last` FROM `queue` AS `q`, `contact` AS `c` @@ -608,10 +619,10 @@ function admin_page_queue(App $a) { * @param App $a * @return string */ -function admin_page_summary(App $a) { +function admin_page_summary(App $a) +{ // are there MyISAM tables in the DB? If so, trigger a warning message - $r = q("SELECT `engine` FROM `information_schema`.`tables` WHERE `engine` = 'myisam' AND `table_schema` = '%s' LIMIT 1", - dbesc(dba::database_name())); + $r = q("SELECT `engine` FROM `information_schema`.`tables` WHERE `engine` = 'myisam' AND `table_schema` = '%s' LIMIT 1", dbesc(dba::database_name())); $showwarning = false; $warningtext = array(); if (DBM::is_result($r)) { @@ -620,8 +631,8 @@ function admin_page_summary(App $a) { } // Check if github.com/friendica/master/VERSION is higher then // the local version of Friendica. Check is opt-in, source may be master or devel branch - if (Config::get('system', 'check_new_version_url', 'none') != 'none' ) { - $gitversion = Config::get('system','git_friendica_version'); + if (Config::get('system', 'check_new_version_url', 'none') != 'none') { + $gitversion = Config::get('system', 'git_friendica_version'); if (version_compare(FRIENDICA_VERSION, $gitversion) < 0) { $warningtext[] = sprintf(t('There is a new version of Friendica available for download. Your current version is %1$s, upstream version is %2$s'), $FRIENDICA_VERSION, $gitversion); $showwarning = true; @@ -656,13 +667,13 @@ function admin_page_summary(App $a) { array(t('Private Forum Account'), 0) ); - $users=0; + $users = 0; foreach ($r as $u) { $accounts[$u['page-flags']][1] = $u['count']; $users+= $u['count']; } - logger('accounts: '.print_r($accounts,true),LOGGER_DATA); + logger('accounts: ' . print_r($accounts, true), LOGGER_DATA); $r = q("SELECT COUNT(`id`) AS `count` FROM `register`"); $pending = $r[0]['count']; @@ -690,7 +701,7 @@ function admin_page_summary(App $a) { '$baseurl' => System::baseUrl(), '$platform' => FRIENDICA_PLATFORM, '$codename' => FRIENDICA_CODENAME, - '$build' => Config::get('system','build'), + '$build' => Config::get('system', 'build'), '$plugins' => array(t('Active plugins'), $a->plugins), '$showwarning' => $showwarning, '$warningtext' => $warningtext @@ -702,7 +713,8 @@ function admin_page_summary(App $a) { * * @param App $a */ -function admin_page_site_post(App $a) { +function admin_page_site_post(App $a) +{ check_form_security_token_redirectOnErr('/admin/site', 'admin_site'); if (!empty($_POST['republish_directory'])) { @@ -710,17 +722,17 @@ function admin_page_site_post(App $a) { return; } - if (!x($_POST,"page_site")) { + if (!x($_POST, "page_site")) { return; } // relocate - if (x($_POST,'relocate') && x($_POST,'relocate_url') && $_POST['relocate_url'] != "") { + if (x($_POST, 'relocate') && x($_POST, 'relocate_url') && $_POST['relocate_url'] != "") { $new_url = $_POST['relocate_url']; - $new_url = rtrim($new_url,"/"); + $new_url = rtrim($new_url, "/"); $parsed = @parse_url($new_url); - if (!$parsed || (!x($parsed,'host') || !x($parsed,'scheme'))) { + if (!$parsed || (!x($parsed, 'host') || !x($parsed, 'scheme'))) { notice(t("Can not parse base url. Must have at least ://")); goaway('admin/site'); } @@ -736,7 +748,8 @@ function admin_page_site_post(App $a) { $new_host = str_replace("http://", "@", normalise_link($new_url)); $old_host = str_replace("http://", "@", normalise_link($old_url)); - function update_table($table_name, $fields, $old_url, $new_url) { + function update_table($table_name, $fields, $old_url, $new_url) + { global $a; $dbold = dbesc($old_url); @@ -754,26 +767,25 @@ function admin_page_site_post(App $a) { $q = sprintf("UPDATE %s SET %s;", $table_name, $upds); $r = q($q); if (!$r) { - notice("Failed updating '$table_name': ".dba::errorMessage()); + notice("Failed updating '$table_name': " . dba::errorMessage()); goaway('admin/site'); } } - // update tables // update profile links in the format "http://server.tld" update_table("profile", array('photo', 'thumb'), $old_url, $new_url); update_table("term", array('url'), $old_url, $new_url); - update_table("contact", array('photo','thumb','micro','url','nurl','alias','request','notify','poll','confirm','poco', 'avatar'), $old_url, $new_url); - update_table("gcontact", array('url','nurl','photo','server_url','notify','alias'), $old_url, $new_url); - update_table("item", array('owner-link','owner-avatar','author-link','author-avatar','body','plink','tag'), $old_url, $new_url); + update_table("contact", array('photo', 'thumb', 'micro', 'url', 'nurl', 'alias', 'request', 'notify', 'poll', 'confirm', 'poco', 'avatar'), $old_url, $new_url); + update_table("gcontact", array('url', 'nurl', 'photo', 'server_url', 'notify', 'alias'), $old_url, $new_url); + update_table("item", array('owner-link', 'owner-avatar', 'author-link', 'author-avatar', 'body', 'plink', 'tag'), $old_url, $new_url); // update profile addresses in the format "user@server.tld" update_table("contact", array('addr'), $old_host, $new_host); - update_table("gcontact", array('connect','addr'), $old_host, $new_host); + update_table("gcontact", array('connect', 'addr'), $old_host, $new_host); // update config $a->set_baseurl($new_url); - Config::set('system','url',$new_url); + Config::set('system', 'url', $new_url); // send relocate $users = q("SELECT `uid` FROM `user` WHERE `account_removed` = 0 AND `account_expired` = 0"); @@ -873,7 +885,7 @@ function admin_page_site_post(App $a) { if ($a->get_path() != "") { $diaspora_enabled = false; } - if ($ssl_policy != intval(Config::get('system','ssl_policy'))) { + if ($ssl_policy != intval(Config::get('system', 'ssl_policy'))) { if ($ssl_policy == SSL_POLICY_FULL) { q("UPDATE `contact` SET `url` = REPLACE(`url` , 'http:' , 'https:'), @@ -912,52 +924,50 @@ function admin_page_site_post(App $a) { ); } } - Config::set('system','ssl_policy',$ssl_policy); - Config::set('system','maxloadavg',$maxloadavg); - Config::set('system','maxloadavg_frontend',$maxloadavg_frontend); - Config::set('system','min_memory',$min_memory); - Config::set('system','optimize_max_tablesize',$optimize_max_tablesize); - Config::set('system','optimize_fragmentation',$optimize_fragmentation); - Config::set('system','poco_completion',$poco_completion); - Config::set('system','poco_requery_days',$poco_requery_days); - Config::set('system','poco_discovery',$poco_discovery); - Config::set('system','poco_discovery_since',$poco_discovery_since); - Config::set('system','poco_local_search',$poco_local_search); - Config::set('system','nodeinfo',$nodeinfo); - Config::set('config','sitename',$sitename); - Config::set('config','hostname',$hostname); - Config::set('config','sender_email', $sender_email); - Config::set('system','suppress_tags',$suppress_tags); - Config::set('system','shortcut_icon',$shortcut_icon); - Config::set('system','touch_icon',$touch_icon); + Config::set('system', 'ssl_policy', $ssl_policy); + Config::set('system', 'maxloadavg', $maxloadavg); + Config::set('system', 'maxloadavg_frontend', $maxloadavg_frontend); + Config::set('system', 'min_memory', $min_memory); + Config::set('system', 'optimize_max_tablesize', $optimize_max_tablesize); + Config::set('system', 'optimize_fragmentation', $optimize_fragmentation); + Config::set('system', 'poco_completion', $poco_completion); + Config::set('system', 'poco_requery_days', $poco_requery_days); + Config::set('system', 'poco_discovery', $poco_discovery); + Config::set('system', 'poco_discovery_since', $poco_discovery_since); + Config::set('system', 'poco_local_search', $poco_local_search); + Config::set('system', 'nodeinfo', $nodeinfo); + Config::set('config', 'sitename', $sitename); + Config::set('config', 'hostname', $hostname); + Config::set('config', 'sender_email', $sender_email); + Config::set('system', 'suppress_tags', $suppress_tags); + Config::set('system', 'shortcut_icon', $shortcut_icon); + Config::set('system', 'touch_icon', $touch_icon); if ($banner == "") { // don't know why, but del_config doesn't work... - q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1", - dbesc("system"), - dbesc("banner") + q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1", dbesc("system"), dbesc("banner") ); } else { - Config::set('system','banner', $banner); + Config::set('system', 'banner', $banner); } if ($info == "") { - Config::delete('config','info'); + Config::delete('config', 'info'); } else { - Config::set('config','info',$info); + Config::set('config', 'info', $info); } - Config::set('system','language', $language); - Config::set('system','theme', $theme); + Config::set('system', 'language', $language); + Config::set('system', 'theme', $theme); if ($theme_mobile == '---') { - Config::delete('system','mobile-theme'); + Config::delete('system', 'mobile-theme'); } else { - Config::set('system','mobile-theme', $theme_mobile); + Config::set('system', 'mobile-theme', $theme_mobile); } if ($singleuser == '---') { - Config::delete('system','singleuser'); + Config::delete('system', 'singleuser'); } else { - Config::set('system','singleuser', $singleuser); + Config::set('system', 'singleuser', $singleuser); } Config::set('system', 'maximagesize', $maximagesize); Config::set('system', 'max_image_length', $maximagelength); @@ -1023,10 +1033,9 @@ function admin_page_site_post(App $a) { Config::set('system', 'frontend_worker', $worker_frontend); Config::set('system', 'rino_encrypt', $rino); - info(t('Site settings updated.').EOL); + info(t('Site settings updated.') . EOL); goaway('admin/site'); return; // NOTREACHED - } /** @@ -1037,15 +1046,15 @@ function admin_page_site_post(App $a) { * @param App $a * @return string */ -function admin_page_site(App $a) { - +function admin_page_site(App $a) +{ /* Installed langs */ $lang_choices = get_available_languages(); - if (strlen(Config::get('system','directory_submit_url')) && - !strlen(Config::get('system','directory'))) { - Config::set('system','directory', dirname(Config::get('system','directory_submit_url'))); - Config::delete('system','directory_submit_url'); + if (strlen(Config::get('system', 'directory_submit_url')) && + !strlen(Config::get('system', 'directory'))) { + Config::set('system', 'directory', dirname(Config::get('system', 'directory_submit_url'))); + Config::delete('system', 'directory_submit_url'); } /* Installed themes */ @@ -1058,8 +1067,9 @@ function admin_page_site(App $a) { $allowed_theme_list = Config::get('system', 'allowed_themes'); foreach ($files as $file) { - if (intval(file_exists($file.'/unsupported'))) + if (intval(file_exists($file . '/unsupported'))) { continue; + } $f = basename($file); @@ -1068,9 +1078,9 @@ function admin_page_site(App $a) { continue; } - $theme_name = ((file_exists($file.'/experimental')) ? sprintf("%s - \x28Experimental\x29", $f) : $f); + $theme_name = ((file_exists($file . '/experimental')) ? sprintf("%s - \x28Experimental\x29", $f) : $f); - if (file_exists($file.'/mobile')) { + if (file_exists($file . '/mobile')) { $theme_choices_mobile[$f] = $theme_name; } else { $theme_choices[$f] = $theme_name; @@ -1083,7 +1093,7 @@ function admin_page_site(App $a) { CP_NO_COMMUNITY_PAGE => t("No community page"), CP_USERS_ON_SERVER => t("Public postings from users of this site"), CP_GLOBAL_COMMUNITY => t("Global community page") - ); + ); /* OStatus conversation poll choices */ $ostatus_poll_choices = array( @@ -1093,21 +1103,21 @@ function admin_page_site(App $a) { "60" => t("Hourly"), "720" => t("Twice daily"), "1440" => t("Daily") - ); + ); $poco_discovery_choices = array( "0" => t("Disabled"), "1" => t("Users"), "2" => t("Users, Global Contacts"), "3" => t("Users, Global Contacts/fallback"), - ); + ); $poco_discovery_since_choices = array( "30" => t("One month"), "91" => t("Three months"), "182" => t("Half a year"), "365" => t("One year"), - ); + ); /* get user names to make the install a personal install of X */ $user_names = array(); @@ -1118,12 +1128,12 @@ function admin_page_site(App $a) { } /* Banner */ - $banner = Config::get('system','banner'); + $banner = Config::get('system', 'banner'); if ($banner == false) { $banner = 'logoFriendica'; } $banner = htmlspecialchars($banner); - $info = Config::get('config','info'); + $info = Config::get('config', 'info'); $info = htmlspecialchars($info); // Automatically create temporary paths @@ -1156,7 +1166,7 @@ function admin_page_site(App $a) { } $diaspora_able = ($a->get_path() == ""); - $optimize_max_tablesize = Config::get('system','optimize_max_tablesize', 100); + $optimize_max_tablesize = Config::get('system', 'optimize_max_tablesize', 100); if ($optimize_max_tablesize < -1) { $optimize_max_tablesize = -1; @@ -1179,7 +1189,7 @@ function admin_page_site(App $a) { '$portable_contacts' => t('Auto Discovered Contact Directory'), '$performance' => t('Performance'), '$worker_title' => t('Worker'), - '$relocate'=> t('Relocate - WARNING: advanced function. Could make this server unreachable.'), + '$relocate' => t('Relocate - WARNING: advanced function. Could make this server unreachable.'), '$baseurl' => System::baseUrl(true), // name, label, value, help string, extra data... '$sitename' => array('sitename', t("Site name"), $a->config['sitename'],''), @@ -1264,9 +1274,7 @@ function admin_page_site(App $a) { '$worker_frontend' => array('worker_frontend', t('Enable frontend worker'), Config::get('system','frontend_worker'), sprintf(t('When enabled the Worker process is triggered when backend access is performed (e.g. messages being delivered). On smaller sites you might want to call %s/worker on a regular basis via an external cron job. You should only enable this option if you cannot utilize cron/scheduled jobs on your server.'), System::baseUrl())), '$form_security_token' => get_form_security_token("admin_site") - )); - } /** @@ -1280,18 +1288,18 @@ function admin_page_site(App $a) { * * @param App $a * @return string - **/ -function admin_page_dbsync(App $a) { - + * */ +function admin_page_dbsync(App $a) +{ $o = ''; if ($a->argc > 3 && intval($a->argv[3]) && $a->argv[2] === 'mark') { - Config::set('database', 'update_'.intval($a->argv[3]), 'success'); - $curr = Config::get('system','build'); + Config::set('database', 'update_' . intval($a->argv[3]), 'success'); + $curr = Config::get('system', 'build'); if (intval($curr) == intval($a->argv[3])) { - Config::set('system','build',intval($curr) + 1); + Config::set('system', 'build', intval($curr) + 1); } - info(t('Update has been marked successful').EOL); + info(t('Update has been marked successful') . EOL); goaway('admin/dbsync'); } @@ -1299,11 +1307,10 @@ function admin_page_dbsync(App $a) { require_once("include/dbstructure.php"); $retval = update_structure(false, true); if (!$retval) { - $o .= sprintf(t("Database structure update %s was successfully applied."), DB_UPDATE_VERSION)."
"; - Config::set('database', 'dbupdate_'.DB_UPDATE_VERSION, 'success'); + $o .= sprintf(t("Database structure update %s was successfully applied."), DB_UPDATE_VERSION) . "
"; + Config::set('database', 'dbupdate_' . DB_UPDATE_VERSION, 'success'); } else { - $o .= sprintf(t("Executing of database structure update %s failed with error: %s"), - DB_UPDATE_VERSION, $retval)."
"; + $o .= sprintf(t("Executing of database structure update %s failed with error: %s"), DB_UPDATE_VERSION, $retval) . "
"; } if ($a->argv[2] === 'check') { return $o; @@ -1311,22 +1318,21 @@ function admin_page_dbsync(App $a) { } if ($a->argc > 2 && intval($a->argv[2])) { - require_once('update.php'); - $func = 'update_'.intval($a->argv[2]); + require_once 'update.php'; + $func = 'update_' . intval($a->argv[2]); if (function_exists($func)) { $retval = $func(); if ($retval === UPDATE_FAILED) { $o .= sprintf(t("Executing %s failed with error: %s"), $func, $retval); - } - elseif ($retval === UPDATE_SUCCESS) { + } elseif ($retval === UPDATE_SUCCESS) { $o .= sprintf(t('Update %s was successfully applied.', $func)); - Config::set('database',$func, 'success'); + Config::set('database', $func, 'success'); } else { $o .= sprintf(t('Update %s did not return a status. Unknown if it succeeded.'), $func); } } else { - $o .= sprintf(t('There was no additional update function %s that needed to be called.'), $func)."
"; - Config::set('database',$func, 'success'); + $o .= sprintf(t('There was no additional update function %s that needed to be called.'), $func) . "
"; + Config::set('database', $func, 'success'); } return $o; } @@ -1335,32 +1341,31 @@ function admin_page_dbsync(App $a) { $r = q("SELECT `k`, `v` FROM `config` WHERE `cat` = 'database' "); if (DBM::is_result($r)) { foreach ($r as $rr) { - $upd = intval(substr($rr['k'],7)); + $upd = intval(substr($rr['k'], 7)); if ($upd < 1139 || $rr['v'] === 'success') { continue; } $failed[] = $upd; } } - if (! count($failed)) { - $o = replace_macros(get_markup_template('structure_check.tpl'),array( - '$base' => System::baseUrl(true), + if (!count($failed)) { + $o = replace_macros(get_markup_template('structure_check.tpl'), array( + '$base' => System::baseUrl(true), '$banner' => t('No failed updates.'), - '$check' => t('Check database structure'), + '$check' => t('Check database structure'), )); } else { - $o = replace_macros(get_markup_template('failed_updates.tpl'),array( - '$base' => System::baseUrl(true), + $o = replace_macros(get_markup_template('failed_updates.tpl'), array( + '$base' => System::baseUrl(true), '$banner' => t('Failed Updates'), - '$desc' => t('This does not include updates prior to 1139, which did not return a status.'), - '$mark' => t('Mark success (if update was manually applied)'), - '$apply' => t('Attempt to execute this update step automatically'), + '$desc' => t('This does not include updates prior to 1139, which did not return a status.'), + '$mark' => t('Mark success (if update was manually applied)'), + '$apply' => t('Attempt to execute this update step automatically'), '$failed' => $failed )); } return $o; - } /** @@ -1368,7 +1373,8 @@ function admin_page_dbsync(App $a) { * * @param App $a */ -function admin_page_users_post(App $a) { +function admin_page_users_post(App $a) +{ $pending = (x($_POST, 'pending') ? $_POST['pending'] : array()); $users = (x($_POST, 'user') ? $_POST['user'] : array()); $nu_name = (x($_POST, 'new_user_name') ? $_POST['new_user_name'] : ''); @@ -1379,11 +1385,11 @@ function admin_page_users_post(App $a) { check_form_security_token_redirectOnErr('/admin/users', 'admin_users'); if (!($nu_name === "") && !($nu_email === "") && !($nu_nickname === "")) { - require_once('include/user.php'); + require_once 'include/user.php'; - $result = create_user(array('username'=>$nu_name, 'email'=>$nu_email, - 'nickname'=>$nu_nickname, 'verified'=>1, 'language'=>$nu_language)); - if (! $result['success']) { + $result = create_user(array('username' => $nu_name, 'email' => $nu_email, + 'nickname' => $nu_nickname, 'verified' => 1, 'language' => $nu_language)); + if (!$result['success']) { notice($result['message']); return; } @@ -1423,34 +1429,32 @@ function admin_page_users_post(App $a) { notification(array( 'type' => SYSTEM_EMAIL, 'to_email' => $nu['email'], - 'subject'=> sprintf(t('Registration details for %s'), $a->config['sitename']), - 'preamble'=> $preamble, + 'subject' => sprintf(t('Registration details for %s'), $a->config['sitename']), + 'preamble' => $preamble, 'body' => $body)); - } - if (x($_POST,'page_users_block')) { + if (x($_POST, 'page_users_block')) { foreach ($users as $uid) { - q("UPDATE `user` SET `blocked` = 1-`blocked` WHERE `uid` = %s", - intval($uid) + q("UPDATE `user` SET `blocked` = 1-`blocked` WHERE `uid` = %s", intval($uid) ); } notice(sprintf(tt("%s user blocked/unblocked", "%s users blocked/unblocked", count($users)), count($users))); } - if (x($_POST,'page_users_delete')) { + if (x($_POST, 'page_users_delete')) { foreach ($users as $uid) { User::remove($uid); } notice(sprintf(tt("%s user deleted", "%s users deleted", count($users)), count($users))); } - if (x($_POST,'page_users_approve')) { + if (x($_POST, 'page_users_approve')) { require_once("mod/regmod.php"); foreach ($pending as $hash) { user_allow($hash); } } - if (x($_POST,'page_users_deny')) { + if (x($_POST, 'page_users_deny')) { require_once("mod/regmod.php"); foreach ($pending as $hash) { user_deny($hash); @@ -1472,35 +1476,33 @@ function admin_page_users_post(App $a) { * @param App $a * @return string */ -function admin_page_users(App $a) { - if ($a->argc>2) { +function admin_page_users(App $a) +{ + if ($a->argc > 2) { $uid = $a->argv[3]; $user = q("SELECT `username`, `blocked` FROM `user` WHERE `uid` = %d", intval($uid)); if (count($user) == 0) { - notice('User not found'.EOL); + notice('User not found' . EOL); goaway('admin/users'); return ''; // NOTREACHED } - switch($a->argv[2]) { + switch ($a->argv[2]) { case "delete": check_form_security_token_redirectOnErr('/admin/users', 'admin_users', 't'); // delete user User::remove($uid); - notice(sprintf(t("User '%s' deleted"), $user[0]['username']).EOL); + notice(sprintf(t("User '%s' deleted"), $user[0]['username']) . EOL); break; case "block": check_form_security_token_redirectOnErr('/admin/users', 'admin_users', 't'); - q("UPDATE `user` SET `blocked` = %d WHERE `uid` = %s", - intval(1-$user[0]['blocked']), - intval($uid) + q("UPDATE `user` SET `blocked` = %d WHERE `uid` = %s", intval(1 - $user[0]['blocked']), intval($uid) ); - notice(sprintf(($user[0]['blocked']?t("User '%s' unblocked"):t("User '%s' blocked")) , $user[0]['username']).EOL); + notice(sprintf(($user[0]['blocked'] ? t("User '%s' unblocked") : t("User '%s' blocked")), $user[0]['username']) . EOL); break; } goaway('admin/users'); return ''; // NOTREACHED - } /* get pending */ @@ -1529,31 +1531,29 @@ function admin_page_users(App $a) { $order = "contact.name"; $order_direction = "+"; - if (x($_GET,'o')) { + if (x($_GET, 'o')) { $new_order = $_GET['o']; if ($new_order[0] === "-") { $order_direction = "-"; - $new_order = substr($new_order,1); + $new_order = substr($new_order, 1); } if (in_array($new_order, $valid_orders)) { $order = $new_order; } - if (x($_GET,'d')) { + if (x($_GET, 'd')) { $new_direction = $_GET['d']; } } - $sql_order = "`".str_replace('.','`.`',$order)."`"; - $sql_order_direction = ($order_direction === "+")?"ASC":"DESC"; + $sql_order = "`" . str_replace('.', '`.`', $order) . "`"; + $sql_order_direction = ($order_direction === "+") ? "ASC" : "DESC"; $users = q("SELECT `user`.*, `contact`.`name`, `contact`.`url`, `contact`.`micro`, `user`.`account_expired`, `contact`.`last-item` AS `lastitem_date` FROM `user` INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self` WHERE `user`.`verified` - ORDER BY $sql_order $sql_order_direction LIMIT %d, %d", - intval($a->pager['start']), - intval($a->pager['itemspage']) - ); + ORDER BY $sql_order $sql_order_direction LIMIT %d, %d", intval($a->pager['start']), intval($a->pager['itemspage']) + ); //echo "
$users"; killme();
 
@@ -1563,7 +1563,7 @@ function admin_page_users(App $a) {
 			t('Normal Account'),
 			t('Automatic Follower Account'),
 			t('Public Forum Account'),
-						t('Automatic Friend Account')
+			t('Automatic Friend Account')
 		);
 		$e['page-flags'] = $accounts[$e['page-flags']];
 		$e['register_date'] = relative_date($e['register_date']);
@@ -1572,7 +1572,7 @@ function admin_page_users(App $a) {
 		//$e['is_admin'] = ($e['email'] === $a->config['admin_email']);
 		$e['is_admin'] = in_array($e['email'], $adminlist);
 		$e['is_deletable'] = (intval($e['uid']) != local_user());
-		$e['deleted'] = ($e['account_removed']?relative_date($e['account_expires_on']):False);
+		$e['deleted'] = ($e['account_removed'] ? relative_date($e['account_expires_on']) : False);
 		return $e;
 	};
 	$users = array_map($_setup_users, $users);
@@ -1587,7 +1587,7 @@ function admin_page_users(App $a) {
 	while (count($users)) {
 		$new_user = array();
 		foreach (array_pop($users) as $k => $v) {
-			$k = str_replace('-','_',$k);
+			$k = str_replace('-', '_', $k);
 			$new_user[$k] = $v;
 		}
 		if ($new_user['deleted']) {
@@ -1602,9 +1602,7 @@ function admin_page_users(App $a) {
 		array_push($users, array_pop($tmp_users));
 	}
 
-	$th_users = array_map(null,
-		array(t('Name'), t('Email'), t('Register date'), t('Last login'), t('Last item'),  t('Account')),
-		$valid_orders
+	$th_users = array_map(null, array(t('Name'), t('Email'), t('Register date'), t('Last login'), t('Last item'), t('Account')), $valid_orders
 	);
 
 	$t = get_markup_template("admin_users.tpl");
@@ -1617,7 +1615,7 @@ function admin_page_users(App $a) {
 		'$h_pending' => t('User registrations waiting for confirm'),
 		'$h_deleted' => t('User waiting for permanent deletion'),
 		'$th_pending' => array(t('Request date'), t('Name'), t('Email')),
-		'$no_pending' =>  t('No registrations.'),
+		'$no_pending' => t('No registrations.'),
 		'$pendingnotetext' => t('Note from the user'),
 		'$approve' => t('Approve'),
 		'$deny' => t('Deny'),
@@ -1653,7 +1651,6 @@ function admin_page_users(App $a) {
 	return $o;
 }
 
-
 /**
  * @brief Plugins admin page
  *
@@ -1670,8 +1667,8 @@ function admin_page_users(App $a) {
  * @param App $a
  * @return string
  */
-function admin_page_plugins(App $a) {
-
+function admin_page_plugins(App $a)
+{
 	/*
 	 * Single plugin
 	 */
@@ -1682,7 +1679,7 @@ function admin_page_plugins(App $a) {
 			return '';
 		}
 
-		if (x($_GET,"a") && $_GET['a']=="t") {
+		if (x($_GET, "a") && $_GET['a'] == "t") {
 			check_form_security_token_redirectOnErr('/admin/plugins', 'admin_themes', 't');
 
 			// Toggle plugin status
@@ -1696,7 +1693,7 @@ function admin_page_plugins(App $a) {
 				install_plugin($plugin);
 				info(sprintf(t("Plugin %s enabled."), $plugin));
 			}
-			Config::set("system","addon", implode(", ",$a->plugins));
+			Config::set("system", "addon", implode(", ", $a->plugins));
 			goaway('admin/plugins');
 			return ''; // NOTREACHED
 		}
@@ -1705,23 +1702,25 @@ function admin_page_plugins(App $a) {
 		require_once('library/markdown.php');
 
 		if (in_array($plugin, $a->plugins)) {
-			$status="on"; $action= t("Disable");
+			$status = "on";
+			$action = t("Disable");
 		} else {
-			$status="off"; $action= t("Enable");
+			$status = "off";
+			$action = t("Enable");
 		}
 
-		$readme=Null;
+		$readme = Null;
 		if (is_file("addon/$plugin/README.md")) {
 			$readme = file_get_contents("addon/$plugin/README.md");
 			$readme = Markdown($readme, false);
 		} elseif (is_file("addon/$plugin/README")) {
-			$readme = "
". file_get_contents("addon/$plugin/README") ."
"; + $readme = "
" . file_get_contents("addon/$plugin/README") . "
"; } - $admin_form=""; + $admin_form = ""; if (is_array($a->plugins_admin) && in_array($plugin, $a->plugins_admin)) { @require_once("addon/$plugin/$plugin.php"); - $func = $plugin.'_plugin_admin'; + $func = $plugin . '_plugin_admin'; $func($a, $admin_form); } @@ -1750,17 +1749,14 @@ function admin_page_plugins(App $a) { )); } - - /* * List plugins */ - - if (x($_GET,"a") && $_GET['a']=="r") { - check_form_security_token_redirectOnErr(System::baseUrl().'/admin/plugins', 'admin_themes', 't'); + if (x($_GET, "a") && $_GET['a'] == "r") { + check_form_security_token_redirectOnErr(System::baseUrl() . '/admin/plugins', 'admin_themes', 't'); reload_plugins(); info("Plugins reloaded"); - goaway(System::baseUrl().'/admin/plugins'); + goaway(System::baseUrl() . '/admin/plugins'); } $plugins = array(); @@ -1768,12 +1764,12 @@ function admin_page_plugins(App $a) { if ($files) { foreach ($files as $file) { if (is_dir($file)) { - list($tmp, $id)=array_map("trim", explode("/",$file)); + list($tmp, $id) = array_map("trim", explode("/", $file)); $info = get_plugin_info($id); $show_plugin = true; // If the addon is unsupported, then only show it, when it is enabled - if ((strtolower($info["status"]) == "unsupported") && !in_array($id, $a->plugins)) { + if ((strtolower($info["status"]) == "unsupported") && !in_array($id, $a->plugins)) { $show_plugin = false; } @@ -1783,7 +1779,7 @@ function admin_page_plugins(App $a) { } if ($show_plugin) { - $plugins[] = array($id, (in_array($id, $a->plugins)?"on":"off") , $info); + $plugins[] = array($id, (in_array($id, $a->plugins) ? "on" : "off"), $info); } } } @@ -1809,14 +1805,14 @@ function admin_page_plugins(App $a) { * @param string $th * @param int $result */ -function toggle_theme(&$themes,$th,&$result) { - for($x = 0; $x < count($themes); $x ++) { +function toggle_theme(&$themes, $th, &$result) +{ + for ($x = 0; $x < count($themes); $x ++) { if ($themes[$x]['name'] === $th) { if ($themes[$x]['allowed']) { $themes[$x]['allowed'] = 0; $result = 0; - } - else { + } else { $themes[$x]['allowed'] = 1; $result = 1; } @@ -1829,13 +1825,13 @@ function toggle_theme(&$themes,$th,&$result) { * @param string $th * @return int */ -function theme_status($themes,$th) { - for($x = 0; $x < count($themes); $x ++) { +function theme_status($themes, $th) +{ + for ($x = 0; $x < count($themes); $x ++) { if ($themes[$x]['name'] === $th) { if ($themes[$x]['allowed']) { return 1; - } - else { + } else { return 0; } } @@ -1843,12 +1839,12 @@ function theme_status($themes,$th) { return 0; } - /** * @param array $themes * @return string */ -function rebuild_theme_table($themes) { +function rebuild_theme_table($themes) +{ $o = ''; if (count($themes)) { foreach ($themes as $th) { @@ -1863,7 +1859,6 @@ function rebuild_theme_table($themes) { return $o; } - /** * @brief Themes admin page * @@ -1880,10 +1875,10 @@ function rebuild_theme_table($themes) { * @param App $a * @return string */ -function admin_page_themes(App $a) { - - $allowed_themes_str = Config::get('system','allowed_themes'); - $allowed_themes_raw = explode(',',$allowed_themes_str); +function admin_page_themes(App $a) +{ + $allowed_themes_str = Config::get('system', 'allowed_themes'); + $allowed_themes_raw = explode(',', $allowed_themes_str); $allowed_themes = array(); if (count($allowed_themes_raw)) { foreach ($allowed_themes_raw as $x) { @@ -1900,16 +1895,16 @@ function admin_page_themes(App $a) { $f = basename($file); // Is there a style file? - $theme_files = glob('view/theme/'.$f.'/style.*'); + $theme_files = glob('view/theme/' . $f . '/style.*'); // If not then quit if (count($theme_files) == 0) { continue; } - $is_experimental = intval(file_exists($file.'/experimental')); - $is_supported = 1-(intval(file_exists($file.'/unsupported'))); - $is_allowed = intval(in_array($f,$allowed_themes)); + $is_experimental = intval(file_exists($file . '/experimental')); + $is_supported = 1 - (intval(file_exists($file . '/unsupported'))); + $is_allowed = intval(in_array($f, $allowed_themes)); if ($is_allowed || $is_supported || Config::get("system", "show_unsupported_themes")) { $themes[] = array('name' => $f, 'experimental' => $is_experimental, 'supported' => $is_supported, 'allowed' => $is_allowed); @@ -1917,7 +1912,7 @@ function admin_page_themes(App $a) { } } - if (! count($themes)) { + if (!count($themes)) { notice(t('No themes found.')); return ''; } @@ -1928,38 +1923,40 @@ function admin_page_themes(App $a) { if ($a->argc == 3) { $theme = $a->argv[2]; - if (! is_dir("view/theme/$theme")) { + if (!is_dir("view/theme/$theme")) { notice(t("Item not found.")); return ''; } - if (x($_GET,"a") && $_GET['a']=="t") { + if (x($_GET, "a") && $_GET['a'] == "t") { check_form_security_token_redirectOnErr('/admin/themes', 'admin_themes', 't'); // Toggle theme status - toggle_theme($themes,$theme,$result); + toggle_theme($themes, $theme, $result); $s = rebuild_theme_table($themes); if ($result) { install_theme($theme); - info(sprintf('Theme %s enabled.',$theme)); + info(sprintf('Theme %s enabled.', $theme)); } else { uninstall_theme($theme); - info(sprintf('Theme %s disabled.',$theme)); + info(sprintf('Theme %s disabled.', $theme)); } - Config::set('system','allowed_themes',$s); + Config::set('system', 'allowed_themes', $s); goaway('admin/themes'); return ''; // NOTREACHED } // display theme details - require_once('library/markdown.php'); + require_once 'library/markdown.php'; - if (theme_status($themes,$theme)) { - $status="on"; $action= t("Disable"); + if (theme_status($themes, $theme)) { + $status = "on"; + $action = t("Disable"); } else { - $status="off"; $action= t("Enable"); + $status = "off"; + $action = t("Enable"); } $readme = Null; @@ -1967,12 +1964,14 @@ function admin_page_themes(App $a) { $readme = file_get_contents("view/theme/$theme/README.md"); $readme = Markdown($readme, false); } elseif (is_file("view/theme/$theme/README")) { - $readme = "
". file_get_contents("view/theme/$theme/README") ."
"; + $readme = "
" . file_get_contents("view/theme/$theme/README") . "
"; } $admin_form = ""; if (is_file("view/theme/$theme/config.php")) { - function __get_theme_admin_form(App $a, $theme) { + + function __get_theme_admin_form(App $a, $theme) + { $orig_theme = $a->theme; $orig_page = $a->page; $orig_session_theme = $_SESSION['theme']; @@ -1981,7 +1980,7 @@ function admin_page_themes(App $a) { $_SESSION['theme'] = $theme; - $init = $theme."_init"; + $init = $theme . "_init"; if (function_exists($init)) { $init($a); } @@ -1998,7 +1997,7 @@ function admin_page_themes(App $a) { } $screenshot = array(get_theme_screenshot($theme), t('Screenshot')); - if (! stristr($screenshot[0],$theme)) { + if (!stristr($screenshot[0], $theme)) { $screenshot = null; } @@ -2026,8 +2025,8 @@ function admin_page_themes(App $a) { // reload active themes - if (x($_GET,"a") && $_GET['a']=="r") { - check_form_security_token_redirectOnErr(System::baseUrl().'/admin/themes', 'admin_themes', 't'); + if (x($_GET, "a") && $_GET['a'] == "r") { + check_form_security_token_redirectOnErr(System::baseUrl() . '/admin/themes', 'admin_themes', 't'); if ($themes) { foreach ($themes as $th) { if ($th['allowed']) { @@ -2037,7 +2036,7 @@ function admin_page_themes(App $a) { } } info("Themes reloaded"); - goaway(System::baseUrl().'/admin/themes'); + goaway(System::baseUrl() . '/admin/themes'); } /* @@ -2047,11 +2046,10 @@ function admin_page_themes(App $a) { $xthemes = array(); if ($themes) { foreach ($themes as $th) { - $xthemes[] = array($th['name'],(($th['allowed']) ? "on" : "off"), get_theme_info($th['name'])); + $xthemes[] = array($th['name'], (($th['allowed']) ? "on" : "off"), get_theme_info($th['name'])); } } - $t = get_markup_template("admin_plugins.tpl"); return replace_macros($t, array( '$title' => t('Administration'), @@ -2069,23 +2067,23 @@ function admin_page_themes(App $a) { )); } - /** * @brief Prosesses data send by Logs admin page * * @param App $a */ -function admin_page_logs_post(App $a) { - if (x($_POST,"page_logs")) { +function admin_page_logs_post(App $a) +{ + if (x($_POST, "page_logs")) { check_form_security_token_redirectOnErr('/admin/logs', 'admin_logs'); $logfile = ((x($_POST,'logfile')) ? notags(trim($_POST['logfile'])) : ''); $debugging = ((x($_POST,'debugging')) ? true : false); $loglevel = ((x($_POST,'loglevel')) ? intval(trim($_POST['loglevel'])) : 0); - Config::set('system','logfile', $logfile); - Config::set('system','debugging', $debugging); - Config::set('system','loglevel', $loglevel); + Config::set('system', 'logfile', $logfile); + Config::set('system', 'debugging', $debugging); + Config::set('system', 'loglevel', $loglevel); } info(t("Log settings updated.")); @@ -2109,8 +2107,8 @@ function admin_page_logs_post(App $a) { * @param App $a * @return string */ -function admin_page_logs(App $a) { - +function admin_page_logs(App $a) +{ $log_choices = array( LOGGER_NORMAL => 'Normal', LOGGER_TRACE => 'Trace', @@ -2133,13 +2131,11 @@ function admin_page_logs(App $a) { '$submit' => t('Save Settings'), '$clear' => t('Clear'), '$baseurl' => System::baseUrl(true), - '$logname' => Config::get('system','logfile'), - + '$logname' => Config::get('system', 'logfile'), // name, label, value, help string, extra data... - '$debugging' => array('debugging', t("Enable Debugging"),Config::get('system','debugging'), ""), - '$logfile' => array('logfile', t("Log file"), Config::get('system','logfile'), t("Must be writable by web server. Relative to your Friendica top-level directory.")), - '$loglevel' => array('loglevel', t("Log level"), Config::get('system','loglevel'), "", $log_choices), - + '$debugging' => array('debugging', t("Enable Debugging"), Config::get('system', 'debugging'), ""), + '$logfile' => array('logfile', t("Log file"), Config::get('system', 'logfile'), t("Must be writable by web server. Relative to your Friendica top-level directory.")), + '$loglevel' => array('loglevel', t("Log level"), Config::get('system', 'loglevel'), "", $log_choices), '$form_security_token' => get_form_security_token("admin_logs"), '$phpheader' => t("PHP logging"), '$phphint' => t("To enable logging of PHP errors and warnings you can add the following to the .htconfig.php file of your installation. The filename set in the 'error_log' line is relative to the friendica top-level directory and must be writeable by the web server. The option '1' for 'log_errors' and 'display_errors' is to enable these options, set to '0' to disable them."), @@ -2166,9 +2162,10 @@ function admin_page_logs(App $a) { * @param App $a * @return string */ -function admin_page_viewlogs(App $a) { +function admin_page_viewlogs(App $a) +{ $t = get_markup_template("admin_viewlogs.tpl"); - $f = Config::get('system','logfile'); + $f = Config::get('system', 'logfile'); $data = ''; if (!file_exists($f)) { @@ -2184,11 +2181,11 @@ function admin_page_viewlogs(App $a) { if ($size > 5000000 || $size < 0) { $size = 5000000; } - $seek = fseek($fp,0-$size,SEEK_END); + $seek = fseek($fp, 0 - $size, SEEK_END); if ($seek === 0) { - $data = escape_tags(fread($fp,$size)); - while (! feof($fp)) { - $data .= escape_tags(fread($fp,4096)); + $data = escape_tags(fread($fp, $size)); + while (!feof($fp)) { + $data .= escape_tags(fread($fp, 4096)); } } } @@ -2199,7 +2196,7 @@ function admin_page_viewlogs(App $a) { '$title' => t('Administration'), '$page' => t('View Logs'), '$data' => $data, - '$logname' => Config::get('system','logfile') + '$logname' => Config::get('system', 'logfile') )); } @@ -2208,11 +2205,11 @@ function admin_page_viewlogs(App $a) { * * @param App $a */ -function admin_page_features_post(App $a) { - +function admin_page_features_post(App $a) +{ check_form_security_token_redirectOnErr('/admin/features', 'admin_manage_features'); - logger('postvars: '.print_r($_POST,true),LOGGER_DATA); + logger('postvars: ' . print_r($_POST, true), LOGGER_DATA); $arr = array(); $features = get_features(false); @@ -2256,8 +2253,8 @@ function admin_page_features_post(App $a) { * @param App $a * @return string */ -function admin_page_features(App $a) { - +function admin_page_features(App $a) +{ if ((argc() > 1) && (argv(1) === 'features')) { $arr = array(); $features = get_features(false); @@ -2265,12 +2262,11 @@ function admin_page_features(App $a) { foreach ($features as $fname => $fdata) { $arr[$fname] = array(); $arr[$fname][0] = $fdata[0]; - foreach (array_slice($fdata,1) as $f) { - + foreach (array_slice($fdata, 1) as $f) { $set = Config::get('feature', $f[0], $f[3]); $arr[$fname][1][] = array( - array('feature_' .$f[0],$f[1],$set,$f[2],array(t('Off'), t('On'))), - array('featurelock_' .$f[0],sprintf(t('Lock feature %s'),$f[1]),(($f[4] !== false) ? "1" : ''),'',array(t('Off'), t('On'))) + array('feature_' . $f[0], $f[1], $set, $f[2], array(t('Off'), t('On'))), + array('featurelock_' . $f[0], sprintf(t('Lock feature %s'), $f[1]), (($f[4] !== false) ? "1" : ''), '', array(t('Off'), t('On'))) ); } } From 84418860bd315bc97de1c0d3aefce2b9f3d9a612 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 1 Dec 2017 00:34:54 -0500 Subject: [PATCH 02/71] Improve dba - Add dba::count - Add support for LIMIT X,X --- include/dba.php | 85 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 73 insertions(+), 12 deletions(-) diff --git a/include/dba.php b/include/dba.php index 684f53ea4..fe191a9e2 100644 --- a/include/dba.php +++ b/include/dba.php @@ -1104,7 +1104,8 @@ class dba { * * $data = dba::select($table, $fields, $condition, $params); */ - public static function select($table, $fields = array(), $condition = array(), $params = array()) { + public static function select($table, array $fields = [], array $condition = [], array $params = []) + { if ($table == '') { return false; } @@ -1115,17 +1116,7 @@ class dba { $select_fields = "*"; } - if (count($condition) > 0) { - $array_element = each($condition); - $array_key = $array_element['key']; - if (is_int($array_key)) { - $condition_string = " WHERE ".array_shift($condition); - } else { - $condition_string = " WHERE `".implode("` = ? AND `", array_keys($condition))."` = ?"; - } - } else { - $condition_string = ""; - } + $condition_string = self::buildCondition($condition); $param_string = ''; $single_row = false; @@ -1147,6 +1138,11 @@ class dba { $single_row = ($params['limit'] == 1); } + if (isset($params['limit']) && is_array($params['limit'])) { + $param_string .= " LIMIT ".intval($params['limit'][0]).", ".intval($params['limit'][1]); + $single_row = ($params['limit'][1] == 1); + } + if (isset($params['only_query']) && $params['only_query']) { $single_row = !$params['only_query']; } @@ -1164,6 +1160,71 @@ class dba { } } + /** + * @brief Counts the rows from a table satisfying the provided condition + * + * @param string $table Table name + * @param array $condition array of fields for condition + * + * @return int + * + * Example: + * $table = "item"; + * + * $condition = ["uid" => 1, "network" => 'dspr']; + * or: + * $condition = ["`uid` = ? AND `network` IN (?, ?)", 1, 'dfrn', 'dspr']; + * + * $count = dba::count($table, $condition); + */ + public static function count($table, array $condition = []) + { + if ($table == '') { + return false; + } + + $condition_string = self::buildCondition($condition); + + $sql = "SELECT COUNT(*) AS `count` FROM `".$table."`".$condition_string; + + $row = self::fetch_first($sql, $condition); + + return $row['count']; + } + + /** + * @brief Returns the SQL condition string built from the provided condition array + * + * This function operates with two modes. + * - Supplied with a filed/value associative array, it builds simple strict + * equality conditions linked by AND. + * - Supplied with a flat list, the first element is the condition string and + * the following arguments are the values to be interpolated + * + * $condition = ["uid" => 1, "network" => 'dspr']; + * or: + * $condition = ["`uid` = ? AND `network` IN (?, ?)", 1, 'dfrn', 'dspr']; + * + * In either case, the provided array is left with the parameters only + * + * @param array $condition + * @return string + */ + private static function buildCondition(array &$condition = []) + { + $condition_string = ''; + if (count($condition) > 0) { + $array_element = each($condition); + $array_key = $array_element['key']; + if (is_int($array_key)) { + $condition_string = " WHERE ".array_shift($condition); + } else { + $condition_string = " WHERE `".implode("` = ? AND `", array_keys($condition))."` = ?"; + } + } + + return $condition_string; + } /** * @brief Fills an array with data from a query From 052ba729d7867f411d8cfd3657bcb502d3a4d17e Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 1 Dec 2017 00:35:40 -0500 Subject: [PATCH 03/71] Improved translation functions - Add built-in vsprintf to t() - Add built-in sprintf to tt() --- include/pgettext.php | 98 ++++++++--- view/templates/admin_aside.tpl | 47 ----- view/templates/admin_blocklist.tpl | 33 ---- view/templates/admin_deleteitem.tpl | 11 -- view/templates/admin_federation.tpl | 58 ------- view/templates/admin_logs.tpl | 22 --- view/templates/admin_plugins.tpl | 22 --- view/templates/admin_plugins_details.tpl | 37 ---- view/templates/admin_queue.tpl | 25 --- view/templates/admin_settings_features.tpl | 21 --- view/templates/admin_settings_head.tpl | 9 - view/templates/admin_site.tpl | 160 ------------------ view/templates/admin_summary.tpl | 48 ------ view/templates/admin_users.tpl | 155 ----------------- view/templates/admin_viewlogs.tpl | 6 - view/theme/frio/templates/admin_aside.tpl | 85 ---------- .../frost-mobile/templates/admin_aside.tpl | 32 ---- .../frost-mobile/templates/admin_site.tpl | 65 ------- .../frost-mobile/templates/admin_users.tpl | 98 ----------- view/theme/frost/templates/admin_aside.tpl | 32 ---- view/theme/frost/templates/admin_site.tpl | 73 -------- view/theme/frost/templates/admin_users.tpl | 98 ----------- view/theme/quattro/templates/admin_users.tpl | 155 ----------------- 23 files changed, 70 insertions(+), 1320 deletions(-) delete mode 100644 view/templates/admin_aside.tpl delete mode 100644 view/templates/admin_blocklist.tpl delete mode 100644 view/templates/admin_deleteitem.tpl delete mode 100644 view/templates/admin_federation.tpl delete mode 100644 view/templates/admin_logs.tpl delete mode 100644 view/templates/admin_plugins.tpl delete mode 100644 view/templates/admin_plugins_details.tpl delete mode 100644 view/templates/admin_queue.tpl delete mode 100644 view/templates/admin_settings_features.tpl delete mode 100644 view/templates/admin_settings_head.tpl delete mode 100644 view/templates/admin_site.tpl delete mode 100644 view/templates/admin_summary.tpl delete mode 100644 view/templates/admin_users.tpl delete mode 100644 view/templates/admin_viewlogs.tpl delete mode 100644 view/theme/frio/templates/admin_aside.tpl delete mode 100644 view/theme/frost-mobile/templates/admin_aside.tpl delete mode 100644 view/theme/frost-mobile/templates/admin_site.tpl delete mode 100644 view/theme/frost-mobile/templates/admin_users.tpl delete mode 100644 view/theme/frost/templates/admin_aside.tpl delete mode 100644 view/theme/frost/templates/admin_site.tpl delete mode 100644 view/theme/frost/templates/admin_users.tpl delete mode 100644 view/theme/quattro/templates/admin_users.tpl diff --git a/include/pgettext.php b/include/pgettext.php index 2e902a6ab..ae1ce009c 100644 --- a/include/pgettext.php +++ b/include/pgettext.php @@ -120,48 +120,90 @@ function load_translation_table($lang) { }} -// translate string if translation exists - -if (! function_exists('t')) { -function t($s) { - +/** + * @brief Return the localized version of the provided string with optional string interpolation + * + * This function takes a english string as parameter, and if a localized version + * exists for the current language, substitutes it before performing an eventual + * string interpolation (sprintf) with additional optional arguments. + * + * Usages: + * - t('This is an example') + * - t('URL %s returned no result', $url) + * - t('Current version: %s, new version: %s', $current_version, $new_version) + * + * @param string $s + * @return string + */ +function t($s) +{ $a = get_app(); - if (x($a->strings,$s)) { + if (x($a->strings, $s)) { $t = $a->strings[$s]; - return is_array($t)?$t[0]:$t; + $s = is_array($t) ? $t[0] : $t; + } + if (func_num_args() > 1) { + $args = array_slice(func_get_args(), 1); + $s = @vsprintf($s, $args); } - return $s; -}} -if (! function_exists('tt')){ -function tt($singular, $plural, $count){ + return $s; +} + +/** + * @brief Return the localized version of a singular/plural string with optional string interpolation + * + * This function takes two english strings as parameters, singular and plural, as + * well as a count. If a localized version exists for the current language, they + * are used instead. Discrimination between singular and plural is done using the + * localized function if any or the default one. Finally, a string interpolation + * is performed using the count as parameter. + * + * Usages: + * - tt('Like', 'Likes', $count) + * - tt("%s user deleted", "%s users deleted", count($users)) + * + * @global type $lang + * @param string $singular + * @param string $plural + * @param int $count + * @return string + */ +function tt($singular, $plural, $count) +{ global $lang; $a = get_app(); - if (x($a->strings,$singular)) { + if (x($a->strings, $singular)) { $t = $a->strings[$singular]; - $f = 'string_plural_select_' . str_replace('-','_',$lang); - if (! function_exists($f)) - $f = 'string_plural_select_default'; - $k = $f($count); - return is_array($t)?$t[$k]:$t; + if (is_array($t)) { + $plural_function = 'string_plural_select_' . str_replace('-', '_', $lang); + if (function_exists($plural_function)) { + $plural_function = 'string_plural_select_default'; + } + $i = $plural_function($count); + $s = $t[$i]; + } else { + $s = $t; + } + } elseif (string_plural_select_default($count)) { + $s = $plural; + } else { + $s = $singular; } - if ($count!=1){ - return $plural; - } else { - return $singular; - } -}} + $s = @sprintf($s, $count); + + return $s; +} // provide a fallback which will not collide with // a function defined in any language file - -if (! function_exists('string_plural_select_default')) { -function string_plural_select_default($n) { - return ($n != 1); -}} +function string_plural_select_default($n) +{ + return $n != 1; +} diff --git a/view/templates/admin_aside.tpl b/view/templates/admin_aside.tpl deleted file mode 100644 index 5c9cce0d0..000000000 --- a/view/templates/admin_aside.tpl +++ /dev/null @@ -1,47 +0,0 @@ - - -

{{$admtxt}}

- - -{{if $admin.update}} - -{{/if}} - - -{{if $admin.plugins_admin}}

{{$plugadmtxt}}

{{/if}} - - - -

{{$logtxt}}

- - -

{{$diagnosticstxt}}

- diff --git a/view/templates/admin_blocklist.tpl b/view/templates/admin_blocklist.tpl deleted file mode 100644 index 1484c987e..000000000 --- a/view/templates/admin_blocklist.tpl +++ /dev/null @@ -1,33 +0,0 @@ - -
-

{{$title}} - {{$page}}

-

{{$intro}}

-

{{$public}}

- -

{{$addtitle}}

-
- - {{include file="field_input.tpl" field=$newdomain}} - {{include file="field_input.tpl" field=$newreason}} -
-
- - {{if $entries}} -

{{$currenttitle}}

-

{{$currentintro}}

-
- - {{foreach $entries as $e}} - {{include file="field_input.tpl" field=$e.domain}} - {{include file="field_input.tpl" field=$e.reason}} - {{include file="field_checkbox.tpl" field=$e.delete}} - {{/foreach}} -
- {{/if}} -
- -
diff --git a/view/templates/admin_deleteitem.tpl b/view/templates/admin_deleteitem.tpl deleted file mode 100644 index cf819dea6..000000000 --- a/view/templates/admin_deleteitem.tpl +++ /dev/null @@ -1,11 +0,0 @@ -
-

{{$title}} - {{$page}}

-

{{$intro1}}

-

{{$intro2}}

-
- -
- - {{include file="field_input.tpl" field=$deleteitemguid}} -
-
diff --git a/view/templates/admin_federation.tpl b/view/templates/admin_federation.tpl deleted file mode 100644 index ee33df09b..000000000 --- a/view/templates/admin_federation.tpl +++ /dev/null @@ -1,58 +0,0 @@ - - -
-

{{$title}} - {{$page}}

-

{{$intro}}

- {{if not $autoactive}} -

{{$hint}}

- {{/if}} -

{{$legendtext}} -

    - {{foreach $counts as $c}} - {{if $c[0]['total'] > 0}} -
  • {{$c[0]['platform']}} ({{$c[0]['total']}})
  • - {{/if}} - {{/foreach}} -
-

-
- - - -{{foreach $counts as $c}} - {{if $c[0]['total'] > 0}} - - - - - - - - {{/if}} -{{/foreach}} -
{{$c[0]['platform']}}{{$c[0]['total']}} - {{$c[0]['network']}}
- - -
    - {{foreach $c[1] as $v}} -
  • {{if ($c[0]['platform']==='Friendica' and $version===$v['version']) }}{{$v['version']}}{{else}}{{$v['version']}}{{/if}} ({{$v['total']}})
  • - {{/foreach}} -
-
diff --git a/view/templates/admin_logs.tpl b/view/templates/admin_logs.tpl deleted file mode 100644 index b2e6357a9..000000000 --- a/view/templates/admin_logs.tpl +++ /dev/null @@ -1,22 +0,0 @@ -
-

{{$title}} - {{$page}}

- -
- - - {{include file="field_checkbox.tpl" field=$debugging}} - {{include file="field_input.tpl" field=$logfile}} - {{include file="field_select.tpl" field=$loglevel}} - -
- -
- -

{{$phpheader}}

-
-

{{$phplogenabled}}

-

{{$phphint}}

-
{{$phplogcode}}
-
- -
diff --git a/view/templates/admin_plugins.tpl b/view/templates/admin_plugins.tpl deleted file mode 100644 index 75565dd2e..000000000 --- a/view/templates/admin_plugins.tpl +++ /dev/null @@ -1,22 +0,0 @@ - -
-

{{$title}} - {{$page}}

- {{if $pcount eq 0}} -
- {{$noplugshint}} -
- {{else}} - {{$reload}} -
    - {{foreach $plugins as $p}} -
  • - - {{$p.2.name}} - {{$p.2.version}} - {{if $p.2.experimental}} {{$experimental}} {{/if}}{{if $p.2.unsupported}} {{$unsupported}} {{/if}} - -
    {{$p.2.description}}
    -
  • - {{/foreach}} -
- {{/if}} -
diff --git a/view/templates/admin_plugins_details.tpl b/view/templates/admin_plugins_details.tpl deleted file mode 100644 index 9def8fc60..000000000 --- a/view/templates/admin_plugins_details.tpl +++ /dev/null @@ -1,37 +0,0 @@ - -
-

{{$title}} - {{$page}}

- -

{{$info.name}} - {{$info.version}} : {{$action}}

-

{{$info.description}}

- -

{{$str_author}} - {{foreach $info.author as $a}} - {{if $a.link}}{{$a.name}}{{else}}{{$a.name}}{{/if}}, - {{/foreach}} -

- -

{{$str_maintainer}} - {{foreach $info.maintainer as $a}} - {{if $a.link}}{{$a.name}}{{else}}{{$a.name}}{{/if}}, - {{/foreach}} -

- - {{if $screenshot}} - {{$screenshot.1}} - {{/if}} - - {{if $admin_form}} -

{{$settings}}

-
- {{$admin_form}} -
- {{/if}} - - {{if $readme}} -

Readme

-
- {{$readme}} -
- {{/if}} -
diff --git a/view/templates/admin_queue.tpl b/view/templates/admin_queue.tpl deleted file mode 100644 index aaca9b014..000000000 --- a/view/templates/admin_queue.tpl +++ /dev/null @@ -1,25 +0,0 @@ -
-

{{$title}} - {{$page}} ({{$count}})

- -

{{$info}}

- - - - - - - - - - {{foreach $entries as $e}} - - - - - - - - - {{/foreach}} -
{{$id_header}}{{$to_header}}{{$url_header}}{{$network_header}}{{$created_header}}{{$last_header}}
{{$e.id}}{{$e.name}}{{$e.nurl}}{{$e.network}}{{$e.created}}{{$e.last}}
-
diff --git a/view/templates/admin_settings_features.tpl b/view/templates/admin_settings_features.tpl deleted file mode 100644 index abcc527d4..000000000 --- a/view/templates/admin_settings_features.tpl +++ /dev/null @@ -1,21 +0,0 @@ -

{{$title}}

- -
- - -{{foreach $features as $g => $f}} -

{{$f.0}}

- -
- {{foreach $f.1 as $fcat}} - {{include file="field_yesno.tpl" field=$fcat.0}} - {{include file="field_yesno.tpl" field=$fcat.1}} - {{/foreach}} - -
- -
-
-{{/foreach}} - -
diff --git a/view/templates/admin_settings_head.tpl b/view/templates/admin_settings_head.tpl deleted file mode 100644 index 25c0f804e..000000000 --- a/view/templates/admin_settings_head.tpl +++ /dev/null @@ -1,9 +0,0 @@ - diff --git a/view/templates/admin_site.tpl b/view/templates/admin_site.tpl deleted file mode 100644 index 9f7b3601e..000000000 --- a/view/templates/admin_site.tpl +++ /dev/null @@ -1,160 +0,0 @@ - -
-

{{$title}} - {{$page}}

- -
- - - {{include file="field_input.tpl" field=$sitename}} - {{include file="field_input.tpl" field=$hostname}} - {{include file="field_input.tpl" field=$sender_email}} - {{include file="field_textarea.tpl" field=$banner}} - {{include file="field_input.tpl" field=$shortcut_icon}} - {{include file="field_input.tpl" field=$touch_icon}} - {{include file="field_textarea.tpl" field=$info}} - {{include file="field_select.tpl" field=$language}} - {{include file="field_select.tpl" field=$theme}} - {{include file="field_select.tpl" field=$theme_mobile}} - {{include file="field_select.tpl" field=$ssl_policy}} - {{if $ssl_policy.2 == 1}}{{include file="field_checkbox.tpl" field=$force_ssl}}{{/if}} - {{include file="field_checkbox.tpl" field=$hide_help}} - {{include file="field_select.tpl" field=$singleuser}} -
- -

{{$registration}}

- {{include file="field_input.tpl" field=$register_text}} - {{include file="field_select.tpl" field=$register_policy}} - {{include file="field_input.tpl" field=$daily_registrations}} - {{include file="field_checkbox.tpl" field=$no_multi_reg}} - {{include file="field_checkbox.tpl" field=$no_openid}} - {{include file="field_checkbox.tpl" field=$no_regfullname}} -
- -

{{$upload}}

- {{include file="field_input.tpl" field=$maximagesize}} - {{include file="field_input.tpl" field=$maximagelength}} - {{include file="field_input.tpl" field=$jpegimagequality}} -
- -

{{$corporate}}

- {{include file="field_input.tpl" field=$allowed_sites}} - {{include file="field_input.tpl" field=$allowed_email}} - {{include file="field_checkbox.tpl" field=$block_public}} - {{include file="field_checkbox.tpl" field=$force_publish}} - {{include file="field_select.tpl" field=$community_page_style}} - {{include file="field_input.tpl" field=$max_author_posts_community_page}} - - {{include file="field_checkbox.tpl" field=$ostatus_disabled}} - {{include file="field_checkbox.tpl" field=$ostatus_full_threads}} - - {{if $diaspora_able}} - {{include file="field_checkbox.tpl" field=$diaspora_enabled}} - {{else}} -
- - {{$diaspora_not_able}} -
- {{/if}} - {{include file="field_checkbox.tpl" field=$dfrn_only}} - {{include file="field_input.tpl" field=$global_directory}} -
- {{include file="field_checkbox.tpl" field=$newuser_private}} - {{include file="field_checkbox.tpl" field=$enotify_no_content}} - {{include file="field_checkbox.tpl" field=$private_addons}} - {{include file="field_checkbox.tpl" field=$disable_embedded}} - {{include file="field_checkbox.tpl" field=$allow_users_remote_self}} -
- -

{{$advanced}}

- {{include file="field_select.tpl" field=$rino}} - {{include file="field_checkbox.tpl" field=$verifyssl}} - {{include file="field_input.tpl" field=$proxy}} - {{include file="field_input.tpl" field=$proxyuser}} - {{include file="field_input.tpl" field=$timeout}} - {{include file="field_input.tpl" field=$maxloadavg_frontend}} - {{include file="field_input.tpl" field=$optimize_max_tablesize}} - {{include file="field_input.tpl" field=$optimize_fragmentation}} - {{include file="field_input.tpl" field=$abandon_days}} - {{include file="field_input.tpl" field=$temppath}} - {{include file="field_input.tpl" field=$basepath}} - {{include file="field_checkbox.tpl" field=$suppress_tags}} - {{include file="field_checkbox.tpl" field=$nodeinfo}} - {{include file="field_select.tpl" field=$check_new_version_url}} -
- -

{{$portable_contacts}}

- {{include file="field_checkbox.tpl" field=$poco_completion}} - {{include file="field_input.tpl" field=$poco_requery_days}} - {{include file="field_select.tpl" field=$poco_discovery}} - {{include file="field_select.tpl" field=$poco_discovery_since}} - {{include file="field_checkbox.tpl" field=$poco_local_search}} -
- -

{{$performance}}

- {{include file="field_checkbox.tpl" field=$only_tag_search}} - {{include file="field_input.tpl" field=$itemcache}} - {{include file="field_input.tpl" field=$itemcache_duration}} - {{include file="field_input.tpl" field=$max_comments}} - {{include file="field_checkbox.tpl" field=$proxy_disabled}} -
- -

{{$worker_title}}

- {{include file="field_input.tpl" field=$maxloadavg}} - {{include file="field_input.tpl" field=$min_memory}} - {{include file="field_input.tpl" field=$worker_queues}} - {{include file="field_checkbox.tpl" field=$worker_dont_fork}} - {{include file="field_checkbox.tpl" field=$worker_fastlane}} - {{include file="field_checkbox.tpl" field=$worker_frontend}} -
- -
- - {{* separate form for relocate... *}} -
- -

{{$relocate}}

- {{include file="field_input.tpl" field=$relocate_url}} - -
-
- -
diff --git a/view/templates/admin_summary.tpl b/view/templates/admin_summary.tpl deleted file mode 100644 index e65014413..000000000 --- a/view/templates/admin_summary.tpl +++ /dev/null @@ -1,48 +0,0 @@ - -
-

{{$title}} - {{$page}}

-{{if $showwarning}} -
- {{foreach $warningtext as $wt}} -

{{$wt}}

- {{/foreach}} -
-{{/if}} - -
-
{{$queues.label}}
-
{{$queues.queue}} - {{$queues.workerq}}
-
-
-
{{$pending.0}}
-
{{$pending.1}} -
- -
-
{{$users.0}}
-
{{$users.1}}
-
- {{foreach $accounts as $p}} -
-
{{$p.0}}
-
{{if $p.1}}{{$p.1}}{{else}}0{{/if}}
-
- {{/foreach}} - - -
-
{{$plugins.0}}
- - {{foreach $plugins.1 as $p}} -
{{$p}}
- {{/foreach}} - -
- -
-
{{$version.0}}
-
{{$platform}} '{{$codename}}' {{$version.1}} - {{$build}} -
- - -
diff --git a/view/templates/admin_users.tpl b/view/templates/admin_users.tpl deleted file mode 100644 index a842d6e36..000000000 --- a/view/templates/admin_users.tpl +++ /dev/null @@ -1,155 +0,0 @@ - - -
-

{{$title}} - {{$page}}

- -
- - -

{{$h_pending}}

- {{if $pending}} - - - - {{foreach $th_pending as $th}}{{/foreach}} - - - - - - {{foreach $pending as $u}} - - - - - - - - - - - {{/foreach}} - -
{{$th}}
{{$u.created}}{{$u.name}} - - -

{{$pendingnotetext}}: {{$u.note}}

- -
- {{else}} -

{{$no_pending}}

- {{/if}} - -

{{$h_users}}

- {{if $users}} - - - - - {{foreach $th_users as $th}} - - {{/foreach}} - - - - - - {{foreach $users as $u}} - - - - - - - - - - {{else}} -   - {{/if}} - - - {{/foreach}} - -
- - {{if $order_users == $th.1}} - {{if $order_direction_users == "+"}} - ↓ - {{else}} - ↑ - {{/if}} - {{else}} - ↕ - {{/if}} - {{$th.0}} -
{{$u.nickname}}{{$u.name}}{{$u.register_date}}{{$u.lastitem_date}} - {{if $u.is_deletable}} - - {{if $u.is_deletable}} - - - {{else}} -   - {{/if}} -
- -
- {{else}} - NO USERS?!? - {{/if}} -
- {{if $deleted}} -

{{$h_deleted}}

- - - - - {{foreach $th_deleted as $th}}{{/foreach}} - - - - {{foreach $deleted as $u}} - - - - - - - - - - {{/foreach}} - -
{{$th}}
{{$u.nickname}}{{$u.name}}{{$u.register_date}}{{$u.lastitem_date}}
- {{/if}} -

{{$h_newuser}}

-
- - - - - - - - - - - - - -
{{include file="field_input.tpl" field=$newusername}}
{{include file="field_input.tpl" field=$newusernickname}}
{{include file="field_input.tpl" field=$newuseremail}}
-
-
-
diff --git a/view/templates/admin_viewlogs.tpl b/view/templates/admin_viewlogs.tpl deleted file mode 100644 index c80264c52..000000000 --- a/view/templates/admin_viewlogs.tpl +++ /dev/null @@ -1,6 +0,0 @@ -
-

{{$title}} - {{$page}}

- -

{{$logname}}

-
{{$data}}
-
diff --git a/view/theme/frio/templates/admin_aside.tpl b/view/theme/frio/templates/admin_aside.tpl deleted file mode 100644 index a90ec6916..000000000 --- a/view/theme/frio/templates/admin_aside.tpl +++ /dev/null @@ -1,85 +0,0 @@ - - -
-

{{$admtxt}}

- - - - {{if $admin.update}} - - {{/if}} -
- -{{if $admin.plugins_admin}} -
-

{{$plugadmtxt}}

-
    - {{foreach $admin.plugins_admin as $name => $item}} - - {{/foreach}} -
-
-{{/if}} - - - - diff --git a/view/theme/frost-mobile/templates/admin_aside.tpl b/view/theme/frost-mobile/templates/admin_aside.tpl deleted file mode 100644 index 74b6cd5f6..000000000 --- a/view/theme/frost-mobile/templates/admin_aside.tpl +++ /dev/null @@ -1,32 +0,0 @@ - - -

{{$admtxt}}

- - -{{if $admin.update}} - -{{/if}} - - -{{if $admin.plugins_admin}}

{{$plugadmtxt}}

{{/if}} - - - -

{{$logtxt}}

- - diff --git a/view/theme/frost-mobile/templates/admin_site.tpl b/view/theme/frost-mobile/templates/admin_site.tpl deleted file mode 100644 index d5b64e58d..000000000 --- a/view/theme/frost-mobile/templates/admin_site.tpl +++ /dev/null @@ -1,65 +0,0 @@ - - -
-

{{$title}} - {{$page}}

- -
- - - {{include file="field_input.tpl" field=$sitename}} - {{include file="field_textarea.tpl" field=$banner}} - {{include file="field_select.tpl" field=$language}} - {{include file="field_select.tpl" field=$theme}} - {{include file="field_select.tpl" field=$theme_mobile}} - {{include file="field_select.tpl" field=$ssl_policy}} - {{include file="field_checkbox.tpl" field=$old_share}} - {{include file="field_checkbox.tpl" field=$hide_help}} - {{include file="field_select.tpl" field=$singleuser}} - -
- -

{{$registration}}

- {{include file="field_input.tpl" field=$register_text}} - {{include file="field_select.tpl" field=$register_policy}} - - {{include file="field_checkbox.tpl" field=$no_multi_reg}} - {{include file="field_checkbox.tpl" field=$no_openid}} - {{include file="field_checkbox.tpl" field=$no_regfullname}} - -
- -

{{$upload}}

- {{include file="field_input.tpl" field=$maximagesize}} - {{include file="field_input.tpl" field=$maximagelength}} - {{include file="field_input.tpl" field=$jpegimagequality}} - -

{{$corporate}}

- {{include file="field_input.tpl" field=$allowed_sites}} - {{include file="field_input.tpl" field=$allowed_email}} - {{include file="field_checkbox.tpl" field=$block_public}} - {{include file="field_checkbox.tpl" field=$force_publish}} - {{include file="field_checkbox.tpl" field=$no_community_page}} - {{include file="field_checkbox.tpl" field=$ostatus_disabled}} - {{include file="field_checkbox.tpl" field=$diaspora_enabled}} - {{include file="field_checkbox.tpl" field=$dfrn_only}} - {{include file="field_input.tpl" field=$global_directory}} - {{include file="field_checkbox.tpl" field=$newuser_private}} - {{include file="field_checkbox.tpl" field=$enotify_no_content}} - {{include file="field_checkbox.tpl" field=$private_addons}} - {{include file="field_checkbox.tpl" field=$disable_embedded}} -
- -

{{$advanced}}

- {{include file="field_checkbox.tpl" field=$verifyssl}} - {{include file="field_input.tpl" field=$proxy}} - {{include file="field_input.tpl" field=$proxyuser}} - {{include file="field_input.tpl" field=$timeout}} - {{include file="field_input.tpl" field=$delivery_interval}} - {{include file="field_input.tpl" field=$poll_interval}} - {{include file="field_input.tpl" field=$maxloadavg}} - {{include file="field_input.tpl" field=$abandon_days}} - -
- -
-
diff --git a/view/theme/frost-mobile/templates/admin_users.tpl b/view/theme/frost-mobile/templates/admin_users.tpl deleted file mode 100644 index f0c4869a7..000000000 --- a/view/theme/frost-mobile/templates/admin_users.tpl +++ /dev/null @@ -1,98 +0,0 @@ - -
-

{{$title}} - {{$page}}

- -
- - -

{{$h_pending}}

- {{if $pending}} - - - - {{foreach $th_pending as $th}}{{/foreach}} - - - - - - {{foreach $pending as $u}} - - - - - - - - {{/foreach}} - -
{{$th}}
{{$u.created}}{{$u.name}} - - -
- -
- {{else}} -

{{$no_pending}}

- {{/if}} - - - - -

{{$h_users}}

- {{if $users}} - - - - - {{foreach $th_users as $th}}{{/foreach}} - - - - - - {{foreach $users as $u}} - - - - - - - - - - {{/if}} - - - {{/foreach}} - -
{{$th}}
{{$u.nickname}}{{$u.name}}{{$u.register_date}}{{$u.lastitem_date}} - {{if $u.is_admin}} -   - {{else}} - - {{if $u.is_admin}} -   - {{else}} - - - {{/if}} -
- -
- {{else}} - NO USERS?!? - {{/if}} -
-
diff --git a/view/theme/frost/templates/admin_aside.tpl b/view/theme/frost/templates/admin_aside.tpl deleted file mode 100644 index 74b6cd5f6..000000000 --- a/view/theme/frost/templates/admin_aside.tpl +++ /dev/null @@ -1,32 +0,0 @@ - - -

{{$admtxt}}

- - -{{if $admin.update}} - -{{/if}} - - -{{if $admin.plugins_admin}}

{{$plugadmtxt}}

{{/if}} - - - -

{{$logtxt}}

- - diff --git a/view/theme/frost/templates/admin_site.tpl b/view/theme/frost/templates/admin_site.tpl deleted file mode 100644 index 8dcfa9129..000000000 --- a/view/theme/frost/templates/admin_site.tpl +++ /dev/null @@ -1,73 +0,0 @@ - - -
-

{{$title}} - {{$page}}

- -
- - - {{include file="field_input.tpl" field=$sitename}} - {{include file="field_textarea.tpl" field=$banner}} - {{include file="field_select.tpl" field=$language}} - {{include file="field_select.tpl" field=$theme}} - {{include file="field_select.tpl" field=$theme_mobile}} - {{include file="field_select.tpl" field=$ssl_policy}} - {{include file="field_checkbox.tpl" field=$old_share}} - {{include file="field_checkbox.tpl" field=$hide_help}} - {{include file="field_select.tpl" field=$singleuser}} - -
- -

{{$registration}}

- {{include file="field_input.tpl" field=$register_text}} - {{include file="field_select.tpl" field=$register_policy}} - {{include file="field_input.tpl" field=$daily_registrations}} - {{include file="field_checkbox.tpl" field=$no_multi_reg}} - {{include file="field_checkbox.tpl" field=$no_openid}} - {{include file="field_checkbox.tpl" field=$no_regfullname}} - -
- -

{{$upload}}

- {{include file="field_input.tpl" field=$maximagesize}} - {{include file="field_input.tpl" field=$maximagelength}} - {{include file="field_input.tpl" field=$jpegimagequality}} - -

{{$corporate}}

- {{include file="field_input.tpl" field=$allowed_sites}} - {{include file="field_input.tpl" field=$allowed_email}} - {{include file="field_checkbox.tpl" field=$block_public}} - {{include file="field_checkbox.tpl" field=$force_publish}} - {{include file="field_checkbox.tpl" field=$no_community_page}} - {{include file="field_checkbox.tpl" field=$ostatus_disabled}} - {{include file="field_checkbox.tpl" field=$diaspora_enabled}} - {{include file="field_checkbox.tpl" field=$dfrn_only}} - {{include file="field_input.tpl" field=$global_directory}} - {{include file="field_checkbox.tpl" field=$newuser_private}} - {{include file="field_checkbox.tpl" field=$enotify_no_content}} - {{include file="field_checkbox.tpl" field=$private_addons}} - {{include file="field_checkbox.tpl" field=$disable_embedded}} -
- -

{{$advanced}}

- {{include file="field_checkbox.tpl" field=$verifyssl}} - {{include file="field_input.tpl" field=$proxy}} - {{include file="field_input.tpl" field=$proxyuser}} - {{include file="field_input.tpl" field=$timeout}} - {{include file="field_input.tpl" field=$delivery_interval}} - {{include file="field_input.tpl" field=$poll_interval}} - {{include file="field_input.tpl" field=$maxloadavg}} - {{include file="field_input.tpl" field=$abandon_days}} - {{include file="field_input.tpl" field=$lockpath}} - {{include file="field_input.tpl" field=$temppath}} - {{include file="field_input.tpl" field=$basepath}} - -

{{$performance}}

- {{include file="field_input.tpl" field=$itemcache}} - {{include file="field_input.tpl" field=$itemcache_duration}} - - -
- -
-
diff --git a/view/theme/frost/templates/admin_users.tpl b/view/theme/frost/templates/admin_users.tpl deleted file mode 100644 index f0c4869a7..000000000 --- a/view/theme/frost/templates/admin_users.tpl +++ /dev/null @@ -1,98 +0,0 @@ - -
-

{{$title}} - {{$page}}

- -
- - -

{{$h_pending}}

- {{if $pending}} - - - - {{foreach $th_pending as $th}}{{/foreach}} - - - - - - {{foreach $pending as $u}} - - - - - - - - {{/foreach}} - -
{{$th}}
{{$u.created}}{{$u.name}} - - -
- -
- {{else}} -

{{$no_pending}}

- {{/if}} - - - - -

{{$h_users}}

- {{if $users}} - - - - - {{foreach $th_users as $th}}{{/foreach}} - - - - - - {{foreach $users as $u}} - - - - - - - - - - {{/if}} - - - {{/foreach}} - -
{{$th}}
{{$u.nickname}}{{$u.name}}{{$u.register_date}}{{$u.lastitem_date}} - {{if $u.is_admin}} -   - {{else}} - - {{if $u.is_admin}} -   - {{else}} - - - {{/if}} -
- -
- {{else}} - NO USERS?!? - {{/if}} -
-
diff --git a/view/theme/quattro/templates/admin_users.tpl b/view/theme/quattro/templates/admin_users.tpl deleted file mode 100644 index ddb395db9..000000000 --- a/view/theme/quattro/templates/admin_users.tpl +++ /dev/null @@ -1,155 +0,0 @@ - - -
-

{{$title}} - {{$page}}

- -
- - -

{{$h_pending}}

- {{if $pending}} - - - - {{foreach $th_pending as $th}}{{/foreach}} - - - - - - {{foreach $pending as $u}} - - - - - - - - - - - {{/foreach}} - -
{{$th}}
{{$u.created}}{{$u.name}} - - -

{{$pendingnotetext}}: {{$u.note}}

- -
- {{else}} -

{{$no_pending}}

- {{/if}} - -

{{$h_users}}

- {{if $users}} - - - - - {{foreach $th_users as $th}} - - {{/foreach}} - - - - - - {{foreach $users as $u}} - - - - - - - - - - {{else}} -   - {{/if}} - - - {{/foreach}} - -
- - {{if $order_users == $th.1}} - {{if $order_direction_users == "+"}} - ↓ - {{else}} - ↑ - {{/if}} - {{else}} - ↕ - {{/if}} - {{$th.0}} -
{{$u.nickname}}{{$u.name}}{{$u.register_date}}{{$u.lastitem_date}} - {{if $u.is_deletable}} - - {{if $u.is_deletable}} - - - {{else}} -   - {{/if}} -
- -
- {{else}} - NO USERS?!? - {{/if}} -
- {{if $deleted}} -

{{$h_deleted}}

- - - - - {{foreach $th_deleted as $th}}{{/foreach}} - - - - {{foreach $deleted as $u}} - - - - - - - - - - {{/foreach}} - -
{{$th}}
{{$u.nickname}}{{$u.name}}{{$u.register_date}}{{$u.lastitem_date}}
- {{/if}} -

{{$h_newuser}}

-
- - - - - - - - - - - - - -
{{include file="field_input.tpl" field=$newusername}}
{{include file="field_input.tpl" field=$newusernickname}}
{{include file="field_input.tpl" field=$newuseremail}}
-
-
-
From 16d0c30328730ceb29442e150f443407df28fe4e Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 1 Dec 2017 00:40:55 -0500 Subject: [PATCH 04/71] Move admin templates to dedicated sub-folder --- mod/admin.php | 39 ++--- view/templates/admin/aside.tpl | 47 +++++ view/templates/admin/blocklist.tpl | 33 ++++ view/templates/admin/deleteitem.tpl | 11 ++ view/templates/admin/federation.tpl | 58 +++++++ view/templates/admin/logs.tpl | 22 +++ view/templates/admin/plugins.tpl | 22 +++ view/templates/admin/plugins_details.tpl | 37 ++++ view/templates/admin/queue.tpl | 25 +++ view/templates/admin/settings_features.tpl | 21 +++ view/templates/admin/settings_head.tpl | 9 + view/templates/admin/site.tpl | 160 ++++++++++++++++++ view/templates/admin/summary.tpl | 48 ++++++ view/templates/admin/users.tpl | 155 +++++++++++++++++ view/templates/admin/viewlogs.tpl | 6 + view/theme/frio/templates/admin/aside.tpl | 85 ++++++++++ .../frost-mobile/templates/admin/aside.tpl | 32 ++++ .../frost-mobile/templates/admin/site.tpl | 65 +++++++ .../frost-mobile/templates/admin/users.tpl | 98 +++++++++++ view/theme/frost/templates/admin/aside.tpl | 32 ++++ view/theme/frost/templates/admin/site.tpl | 73 ++++++++ view/theme/frost/templates/admin/users.tpl | 98 +++++++++++ view/theme/quattro/templates/admin/users.tpl | 155 +++++++++++++++++ 23 files changed, 1309 insertions(+), 22 deletions(-) create mode 100644 view/templates/admin/aside.tpl create mode 100644 view/templates/admin/blocklist.tpl create mode 100644 view/templates/admin/deleteitem.tpl create mode 100644 view/templates/admin/federation.tpl create mode 100644 view/templates/admin/logs.tpl create mode 100644 view/templates/admin/plugins.tpl create mode 100644 view/templates/admin/plugins_details.tpl create mode 100644 view/templates/admin/queue.tpl create mode 100644 view/templates/admin/settings_features.tpl create mode 100644 view/templates/admin/settings_head.tpl create mode 100644 view/templates/admin/site.tpl create mode 100644 view/templates/admin/summary.tpl create mode 100644 view/templates/admin/users.tpl create mode 100644 view/templates/admin/viewlogs.tpl create mode 100644 view/theme/frio/templates/admin/aside.tpl create mode 100644 view/theme/frost-mobile/templates/admin/aside.tpl create mode 100644 view/theme/frost-mobile/templates/admin/site.tpl create mode 100644 view/theme/frost-mobile/templates/admin/users.tpl create mode 100644 view/theme/frost/templates/admin/aside.tpl create mode 100644 view/theme/frost/templates/admin/site.tpl create mode 100644 view/theme/frost/templates/admin/users.tpl create mode 100644 view/theme/quattro/templates/admin/users.tpl diff --git a/mod/admin.php b/mod/admin.php index cdcd688f2..de981bb90 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -149,7 +149,6 @@ function admin_post(App $a) */ function admin_content(App $a) { - if (!is_site_admin()) { return login(false); } @@ -164,7 +163,7 @@ function admin_content(App $a) // apc_delete($toDelete); //} // Header stuff - $a->page['htmlhead'] .= replace_macros(get_markup_template('admin_settings_head.tpl'), array()); + $a->page['htmlhead'] .= replace_macros(get_markup_template('admin/settings_head.tpl'), array()); /* * Side bar links @@ -201,7 +200,7 @@ function admin_content(App $a) $aside_tools['diagnostics_probe'] = array('probe/', t('probe address'), 'probe'); $aside_tools['diagnostics_webfinger'] = array('webfinger/', t('check webfinger'), 'webfinger'); - $t = get_markup_template("admin_aside.tpl"); + $t = get_markup_template('admin/aside.tpl'); $a->page['aside'] .= replace_macros($t, array( '$admin' => $aside_tools, '$subpages' => $aside_sub, @@ -213,11 +212,7 @@ function admin_content(App $a) '$admurl' => "admin/" )); - - - /* - * Page content - */ + // Page content $o = ''; // urls if ($a->argc > 1) { @@ -298,7 +293,7 @@ function admin_page_blocklist(App $a) ); } } - $t = get_markup_template("admin_blocklist.tpl"); + $t = get_markup_template('admin/blocklist.tpl'); return replace_macros($t, array( '$title' => t('Administration'), '$page' => t('Server Blocklist'), @@ -376,7 +371,7 @@ function admin_page_blocklist_post(App $a) */ function admin_page_deleteitem(App $a) { - $t = get_markup_template("admin_deleteitem.tpl"); + $t = get_markup_template('admin/deleteitem.tpl'); return replace_macros($t, array( '$title' => t('Administration'), @@ -557,7 +552,7 @@ function admin_page_federation(App $a) $hint = t('The Auto Discovered Contact Directory feature is not enabled, it will improve the data displayed here.'); // load the template, replace the macros and return the page content - $t = get_markup_template("admin_federation.tpl"); + $t = get_markup_template('admin/federation.tpl'); return replace_macros($t, array( '$title' => t('Administration'), '$page' => t('Federation Statistics'), @@ -592,7 +587,7 @@ function admin_page_queue(App $a) WHERE `c`.`id` = `q`.`cid` ORDER BY `q`.`cid`, `q`.`created`;"); - $t = get_markup_template("admin_queue.tpl"); + $t = get_markup_template('admin/queue.tpl'); return replace_macros($t, array( '$title' => t('Administration'), '$page' => t('Inspect Queue'), @@ -689,7 +684,7 @@ function admin_page_summary(App $a) $queues = array('label' => t('Message queues'), 'queue' => $queue, 'workerq' => $workerqueue); - $t = get_markup_template("admin_summary.tpl"); + $t = get_markup_template('admin/summary.tpl'); return replace_macros($t, array( '$title' => t('Administration'), '$page' => t('Summary'), @@ -1176,7 +1171,7 @@ function admin_page_site(App $a) $optimize_max_tablesize = 100; } - $t = get_markup_template("admin_site.tpl"); + $t = get_markup_template('admin/site.tpl'); return replace_macros($t, array( '$title' => t('Administration'), '$page' => t('Site'), @@ -1605,7 +1600,7 @@ function admin_page_users(App $a) $th_users = array_map(null, array(t('Name'), t('Email'), t('Register date'), t('Last login'), t('Last item'), t('Account')), $valid_orders ); - $t = get_markup_template("admin_users.tpl"); + $t = get_markup_template('admin/users.tpl'); $o = replace_macros($t, array( // strings // '$title' => t('Administration'), @@ -1724,7 +1719,7 @@ function admin_page_plugins(App $a) $func($a, $admin_form); } - $t = get_markup_template("admin_plugins_details.tpl"); + $t = get_markup_template('admin/plugins_details.tpl'); return replace_macros($t, array( '$title' => t('Administration'), @@ -1785,7 +1780,7 @@ function admin_page_plugins(App $a) } } - $t = get_markup_template("admin_plugins.tpl"); + $t = get_markup_template('admin/plugins.tpl'); return replace_macros($t, array( '$title' => t('Administration'), '$page' => t('Plugins'), @@ -2001,7 +1996,7 @@ function admin_page_themes(App $a) $screenshot = null; } - $t = get_markup_template("admin_plugins_details.tpl"); + $t = get_markup_template('admin/plugins_details.tpl'); return replace_macros($t, array( '$title' => t('Administration'), '$page' => t('Themes'), @@ -2050,7 +2045,7 @@ function admin_page_themes(App $a) } } - $t = get_markup_template("admin_plugins.tpl"); + $t = get_markup_template('admin/plugins.tpl'); return replace_macros($t, array( '$title' => t('Administration'), '$page' => t('Themes'), @@ -2123,7 +2118,7 @@ function admin_page_logs(App $a) $phplogenabled = t('PHP log currently disabled.'); } - $t = get_markup_template("admin_logs.tpl"); + $t = get_markup_template('admin/logs.tpl'); return replace_macros($t, array( '$title' => t('Administration'), @@ -2164,7 +2159,7 @@ function admin_page_logs(App $a) */ function admin_page_viewlogs(App $a) { - $t = get_markup_template("admin_viewlogs.tpl"); + $t = get_markup_template('admin/viewlogs.tpl'); $f = Config::get('system', 'logfile'); $data = ''; @@ -2271,7 +2266,7 @@ function admin_page_features(App $a) } } - $tpl = get_markup_template("admin_settings_features.tpl"); + $tpl = get_markup_template('admin/settings_features.tpl'); $o .= replace_macros($tpl, array( '$form_security_token' => get_form_security_token("admin_manage_features"), '$title' => t('Manage Additional Features'), diff --git a/view/templates/admin/aside.tpl b/view/templates/admin/aside.tpl new file mode 100644 index 000000000..5c9cce0d0 --- /dev/null +++ b/view/templates/admin/aside.tpl @@ -0,0 +1,47 @@ + + +

{{$admtxt}}

+ + +{{if $admin.update}} + +{{/if}} + + +{{if $admin.plugins_admin}}

{{$plugadmtxt}}

{{/if}} + + + +

{{$logtxt}}

+ + +

{{$diagnosticstxt}}

+ diff --git a/view/templates/admin/blocklist.tpl b/view/templates/admin/blocklist.tpl new file mode 100644 index 000000000..1484c987e --- /dev/null +++ b/view/templates/admin/blocklist.tpl @@ -0,0 +1,33 @@ + +
+

{{$title}} - {{$page}}

+

{{$intro}}

+

{{$public}}

+ +

{{$addtitle}}

+
+ + {{include file="field_input.tpl" field=$newdomain}} + {{include file="field_input.tpl" field=$newreason}} +
+
+ + {{if $entries}} +

{{$currenttitle}}

+

{{$currentintro}}

+
+ + {{foreach $entries as $e}} + {{include file="field_input.tpl" field=$e.domain}} + {{include file="field_input.tpl" field=$e.reason}} + {{include file="field_checkbox.tpl" field=$e.delete}} + {{/foreach}} +
+ {{/if}} +
+ +
diff --git a/view/templates/admin/deleteitem.tpl b/view/templates/admin/deleteitem.tpl new file mode 100644 index 000000000..cf819dea6 --- /dev/null +++ b/view/templates/admin/deleteitem.tpl @@ -0,0 +1,11 @@ +
+

{{$title}} - {{$page}}

+

{{$intro1}}

+

{{$intro2}}

+
+ +
+ + {{include file="field_input.tpl" field=$deleteitemguid}} +
+
diff --git a/view/templates/admin/federation.tpl b/view/templates/admin/federation.tpl new file mode 100644 index 000000000..ee33df09b --- /dev/null +++ b/view/templates/admin/federation.tpl @@ -0,0 +1,58 @@ + + +
+

{{$title}} - {{$page}}

+

{{$intro}}

+ {{if not $autoactive}} +

{{$hint}}

+ {{/if}} +

{{$legendtext}} +

    + {{foreach $counts as $c}} + {{if $c[0]['total'] > 0}} +
  • {{$c[0]['platform']}} ({{$c[0]['total']}})
  • + {{/if}} + {{/foreach}} +
+

+
+ + + +{{foreach $counts as $c}} + {{if $c[0]['total'] > 0}} + + + + + + + + {{/if}} +{{/foreach}} +
{{$c[0]['platform']}}{{$c[0]['total']}} + {{$c[0]['network']}}
+ + +
    + {{foreach $c[1] as $v}} +
  • {{if ($c[0]['platform']==='Friendica' and $version===$v['version']) }}{{$v['version']}}{{else}}{{$v['version']}}{{/if}} ({{$v['total']}})
  • + {{/foreach}} +
+
diff --git a/view/templates/admin/logs.tpl b/view/templates/admin/logs.tpl new file mode 100644 index 000000000..b2e6357a9 --- /dev/null +++ b/view/templates/admin/logs.tpl @@ -0,0 +1,22 @@ +
+

{{$title}} - {{$page}}

+ +
+ + + {{include file="field_checkbox.tpl" field=$debugging}} + {{include file="field_input.tpl" field=$logfile}} + {{include file="field_select.tpl" field=$loglevel}} + +
+ +
+ +

{{$phpheader}}

+
+

{{$phplogenabled}}

+

{{$phphint}}

+
{{$phplogcode}}
+
+ +
diff --git a/view/templates/admin/plugins.tpl b/view/templates/admin/plugins.tpl new file mode 100644 index 000000000..75565dd2e --- /dev/null +++ b/view/templates/admin/plugins.tpl @@ -0,0 +1,22 @@ + +
+

{{$title}} - {{$page}}

+ {{if $pcount eq 0}} +
+ {{$noplugshint}} +
+ {{else}} + {{$reload}} +
    + {{foreach $plugins as $p}} +
  • + + {{$p.2.name}} - {{$p.2.version}} + {{if $p.2.experimental}} {{$experimental}} {{/if}}{{if $p.2.unsupported}} {{$unsupported}} {{/if}} + +
    {{$p.2.description}}
    +
  • + {{/foreach}} +
+ {{/if}} +
diff --git a/view/templates/admin/plugins_details.tpl b/view/templates/admin/plugins_details.tpl new file mode 100644 index 000000000..9def8fc60 --- /dev/null +++ b/view/templates/admin/plugins_details.tpl @@ -0,0 +1,37 @@ + +
+

{{$title}} - {{$page}}

+ +

{{$info.name}} - {{$info.version}} : {{$action}}

+

{{$info.description}}

+ +

{{$str_author}} + {{foreach $info.author as $a}} + {{if $a.link}}{{$a.name}}{{else}}{{$a.name}}{{/if}}, + {{/foreach}} +

+ +

{{$str_maintainer}} + {{foreach $info.maintainer as $a}} + {{if $a.link}}{{$a.name}}{{else}}{{$a.name}}{{/if}}, + {{/foreach}} +

+ + {{if $screenshot}} + {{$screenshot.1}} + {{/if}} + + {{if $admin_form}} +

{{$settings}}

+
+ {{$admin_form}} +
+ {{/if}} + + {{if $readme}} +

Readme

+
+ {{$readme}} +
+ {{/if}} +
diff --git a/view/templates/admin/queue.tpl b/view/templates/admin/queue.tpl new file mode 100644 index 000000000..aaca9b014 --- /dev/null +++ b/view/templates/admin/queue.tpl @@ -0,0 +1,25 @@ +
+

{{$title}} - {{$page}} ({{$count}})

+ +

{{$info}}

+ + + + + + + + + + {{foreach $entries as $e}} + + + + + + + + + {{/foreach}} +
{{$id_header}}{{$to_header}}{{$url_header}}{{$network_header}}{{$created_header}}{{$last_header}}
{{$e.id}}{{$e.name}}{{$e.nurl}}{{$e.network}}{{$e.created}}{{$e.last}}
+
diff --git a/view/templates/admin/settings_features.tpl b/view/templates/admin/settings_features.tpl new file mode 100644 index 000000000..abcc527d4 --- /dev/null +++ b/view/templates/admin/settings_features.tpl @@ -0,0 +1,21 @@ +

{{$title}}

+ +
+ + +{{foreach $features as $g => $f}} +

{{$f.0}}

+ +
+ {{foreach $f.1 as $fcat}} + {{include file="field_yesno.tpl" field=$fcat.0}} + {{include file="field_yesno.tpl" field=$fcat.1}} + {{/foreach}} + +
+ +
+
+{{/foreach}} + +
diff --git a/view/templates/admin/settings_head.tpl b/view/templates/admin/settings_head.tpl new file mode 100644 index 000000000..25c0f804e --- /dev/null +++ b/view/templates/admin/settings_head.tpl @@ -0,0 +1,9 @@ + diff --git a/view/templates/admin/site.tpl b/view/templates/admin/site.tpl new file mode 100644 index 000000000..9f7b3601e --- /dev/null +++ b/view/templates/admin/site.tpl @@ -0,0 +1,160 @@ + +
+

{{$title}} - {{$page}}

+ +
+ + + {{include file="field_input.tpl" field=$sitename}} + {{include file="field_input.tpl" field=$hostname}} + {{include file="field_input.tpl" field=$sender_email}} + {{include file="field_textarea.tpl" field=$banner}} + {{include file="field_input.tpl" field=$shortcut_icon}} + {{include file="field_input.tpl" field=$touch_icon}} + {{include file="field_textarea.tpl" field=$info}} + {{include file="field_select.tpl" field=$language}} + {{include file="field_select.tpl" field=$theme}} + {{include file="field_select.tpl" field=$theme_mobile}} + {{include file="field_select.tpl" field=$ssl_policy}} + {{if $ssl_policy.2 == 1}}{{include file="field_checkbox.tpl" field=$force_ssl}}{{/if}} + {{include file="field_checkbox.tpl" field=$hide_help}} + {{include file="field_select.tpl" field=$singleuser}} +
+ +

{{$registration}}

+ {{include file="field_input.tpl" field=$register_text}} + {{include file="field_select.tpl" field=$register_policy}} + {{include file="field_input.tpl" field=$daily_registrations}} + {{include file="field_checkbox.tpl" field=$no_multi_reg}} + {{include file="field_checkbox.tpl" field=$no_openid}} + {{include file="field_checkbox.tpl" field=$no_regfullname}} +
+ +

{{$upload}}

+ {{include file="field_input.tpl" field=$maximagesize}} + {{include file="field_input.tpl" field=$maximagelength}} + {{include file="field_input.tpl" field=$jpegimagequality}} +
+ +

{{$corporate}}

+ {{include file="field_input.tpl" field=$allowed_sites}} + {{include file="field_input.tpl" field=$allowed_email}} + {{include file="field_checkbox.tpl" field=$block_public}} + {{include file="field_checkbox.tpl" field=$force_publish}} + {{include file="field_select.tpl" field=$community_page_style}} + {{include file="field_input.tpl" field=$max_author_posts_community_page}} + + {{include file="field_checkbox.tpl" field=$ostatus_disabled}} + {{include file="field_checkbox.tpl" field=$ostatus_full_threads}} + + {{if $diaspora_able}} + {{include file="field_checkbox.tpl" field=$diaspora_enabled}} + {{else}} +
+ + {{$diaspora_not_able}} +
+ {{/if}} + {{include file="field_checkbox.tpl" field=$dfrn_only}} + {{include file="field_input.tpl" field=$global_directory}} +
+ {{include file="field_checkbox.tpl" field=$newuser_private}} + {{include file="field_checkbox.tpl" field=$enotify_no_content}} + {{include file="field_checkbox.tpl" field=$private_addons}} + {{include file="field_checkbox.tpl" field=$disable_embedded}} + {{include file="field_checkbox.tpl" field=$allow_users_remote_self}} +
+ +

{{$advanced}}

+ {{include file="field_select.tpl" field=$rino}} + {{include file="field_checkbox.tpl" field=$verifyssl}} + {{include file="field_input.tpl" field=$proxy}} + {{include file="field_input.tpl" field=$proxyuser}} + {{include file="field_input.tpl" field=$timeout}} + {{include file="field_input.tpl" field=$maxloadavg_frontend}} + {{include file="field_input.tpl" field=$optimize_max_tablesize}} + {{include file="field_input.tpl" field=$optimize_fragmentation}} + {{include file="field_input.tpl" field=$abandon_days}} + {{include file="field_input.tpl" field=$temppath}} + {{include file="field_input.tpl" field=$basepath}} + {{include file="field_checkbox.tpl" field=$suppress_tags}} + {{include file="field_checkbox.tpl" field=$nodeinfo}} + {{include file="field_select.tpl" field=$check_new_version_url}} +
+ +

{{$portable_contacts}}

+ {{include file="field_checkbox.tpl" field=$poco_completion}} + {{include file="field_input.tpl" field=$poco_requery_days}} + {{include file="field_select.tpl" field=$poco_discovery}} + {{include file="field_select.tpl" field=$poco_discovery_since}} + {{include file="field_checkbox.tpl" field=$poco_local_search}} +
+ +

{{$performance}}

+ {{include file="field_checkbox.tpl" field=$only_tag_search}} + {{include file="field_input.tpl" field=$itemcache}} + {{include file="field_input.tpl" field=$itemcache_duration}} + {{include file="field_input.tpl" field=$max_comments}} + {{include file="field_checkbox.tpl" field=$proxy_disabled}} +
+ +

{{$worker_title}}

+ {{include file="field_input.tpl" field=$maxloadavg}} + {{include file="field_input.tpl" field=$min_memory}} + {{include file="field_input.tpl" field=$worker_queues}} + {{include file="field_checkbox.tpl" field=$worker_dont_fork}} + {{include file="field_checkbox.tpl" field=$worker_fastlane}} + {{include file="field_checkbox.tpl" field=$worker_frontend}} +
+ +
+ + {{* separate form for relocate... *}} +
+ +

{{$relocate}}

+ {{include file="field_input.tpl" field=$relocate_url}} + +
+
+ +
diff --git a/view/templates/admin/summary.tpl b/view/templates/admin/summary.tpl new file mode 100644 index 000000000..e65014413 --- /dev/null +++ b/view/templates/admin/summary.tpl @@ -0,0 +1,48 @@ + +
+

{{$title}} - {{$page}}

+{{if $showwarning}} +
+ {{foreach $warningtext as $wt}} +

{{$wt}}

+ {{/foreach}} +
+{{/if}} + +
+
{{$queues.label}}
+
{{$queues.queue}} - {{$queues.workerq}}
+
+
+
{{$pending.0}}
+
{{$pending.1}} +
+ +
+
{{$users.0}}
+
{{$users.1}}
+
+ {{foreach $accounts as $p}} +
+
{{$p.0}}
+
{{if $p.1}}{{$p.1}}{{else}}0{{/if}}
+
+ {{/foreach}} + + +
+
{{$plugins.0}}
+ + {{foreach $plugins.1 as $p}} +
{{$p}}
+ {{/foreach}} + +
+ +
+
{{$version.0}}
+
{{$platform}} '{{$codename}}' {{$version.1}} - {{$build}} +
+ + +
diff --git a/view/templates/admin/users.tpl b/view/templates/admin/users.tpl new file mode 100644 index 000000000..a842d6e36 --- /dev/null +++ b/view/templates/admin/users.tpl @@ -0,0 +1,155 @@ + + +
+

{{$title}} - {{$page}}

+ +
+ + +

{{$h_pending}}

+ {{if $pending}} + + + + {{foreach $th_pending as $th}}{{/foreach}} + + + + + + {{foreach $pending as $u}} + + + + + + + + + + + {{/foreach}} + +
{{$th}}
{{$u.created}}{{$u.name}} + + +

{{$pendingnotetext}}: {{$u.note}}

+ +
+ {{else}} +

{{$no_pending}}

+ {{/if}} + +

{{$h_users}}

+ {{if $users}} + + + + + {{foreach $th_users as $th}} + + {{/foreach}} + + + + + + {{foreach $users as $u}} + + + + + + + + + + {{else}} +   + {{/if}} + + + {{/foreach}} + +
+ + {{if $order_users == $th.1}} + {{if $order_direction_users == "+"}} + ↓ + {{else}} + ↑ + {{/if}} + {{else}} + ↕ + {{/if}} + {{$th.0}} +
{{$u.nickname}}{{$u.name}}{{$u.register_date}}{{$u.lastitem_date}} + {{if $u.is_deletable}} + + {{if $u.is_deletable}} + + + {{else}} +   + {{/if}} +
+ +
+ {{else}} + NO USERS?!? + {{/if}} +
+ {{if $deleted}} +

{{$h_deleted}}

+ + + + + {{foreach $th_deleted as $th}}{{/foreach}} + + + + {{foreach $deleted as $u}} + + + + + + + + + + {{/foreach}} + +
{{$th}}
{{$u.nickname}}{{$u.name}}{{$u.register_date}}{{$u.lastitem_date}}
+ {{/if}} +

{{$h_newuser}}

+
+ + + + + + + + + + + + + +
{{include file="field_input.tpl" field=$newusername}}
{{include file="field_input.tpl" field=$newusernickname}}
{{include file="field_input.tpl" field=$newuseremail}}
+
+
+
diff --git a/view/templates/admin/viewlogs.tpl b/view/templates/admin/viewlogs.tpl new file mode 100644 index 000000000..c80264c52 --- /dev/null +++ b/view/templates/admin/viewlogs.tpl @@ -0,0 +1,6 @@ +
+

{{$title}} - {{$page}}

+ +

{{$logname}}

+
{{$data}}
+
diff --git a/view/theme/frio/templates/admin/aside.tpl b/view/theme/frio/templates/admin/aside.tpl new file mode 100644 index 000000000..a90ec6916 --- /dev/null +++ b/view/theme/frio/templates/admin/aside.tpl @@ -0,0 +1,85 @@ + + +
+

{{$admtxt}}

+ + + + {{if $admin.update}} + + {{/if}} +
+ +{{if $admin.plugins_admin}} +
+

{{$plugadmtxt}}

+
    + {{foreach $admin.plugins_admin as $name => $item}} + + {{/foreach}} +
+
+{{/if}} + + + + diff --git a/view/theme/frost-mobile/templates/admin/aside.tpl b/view/theme/frost-mobile/templates/admin/aside.tpl new file mode 100644 index 000000000..74b6cd5f6 --- /dev/null +++ b/view/theme/frost-mobile/templates/admin/aside.tpl @@ -0,0 +1,32 @@ + + +

{{$admtxt}}

+ + +{{if $admin.update}} + +{{/if}} + + +{{if $admin.plugins_admin}}

{{$plugadmtxt}}

{{/if}} + + + +

{{$logtxt}}

+ + diff --git a/view/theme/frost-mobile/templates/admin/site.tpl b/view/theme/frost-mobile/templates/admin/site.tpl new file mode 100644 index 000000000..d5b64e58d --- /dev/null +++ b/view/theme/frost-mobile/templates/admin/site.tpl @@ -0,0 +1,65 @@ + + +
+

{{$title}} - {{$page}}

+ +
+ + + {{include file="field_input.tpl" field=$sitename}} + {{include file="field_textarea.tpl" field=$banner}} + {{include file="field_select.tpl" field=$language}} + {{include file="field_select.tpl" field=$theme}} + {{include file="field_select.tpl" field=$theme_mobile}} + {{include file="field_select.tpl" field=$ssl_policy}} + {{include file="field_checkbox.tpl" field=$old_share}} + {{include file="field_checkbox.tpl" field=$hide_help}} + {{include file="field_select.tpl" field=$singleuser}} + +
+ +

{{$registration}}

+ {{include file="field_input.tpl" field=$register_text}} + {{include file="field_select.tpl" field=$register_policy}} + + {{include file="field_checkbox.tpl" field=$no_multi_reg}} + {{include file="field_checkbox.tpl" field=$no_openid}} + {{include file="field_checkbox.tpl" field=$no_regfullname}} + +
+ +

{{$upload}}

+ {{include file="field_input.tpl" field=$maximagesize}} + {{include file="field_input.tpl" field=$maximagelength}} + {{include file="field_input.tpl" field=$jpegimagequality}} + +

{{$corporate}}

+ {{include file="field_input.tpl" field=$allowed_sites}} + {{include file="field_input.tpl" field=$allowed_email}} + {{include file="field_checkbox.tpl" field=$block_public}} + {{include file="field_checkbox.tpl" field=$force_publish}} + {{include file="field_checkbox.tpl" field=$no_community_page}} + {{include file="field_checkbox.tpl" field=$ostatus_disabled}} + {{include file="field_checkbox.tpl" field=$diaspora_enabled}} + {{include file="field_checkbox.tpl" field=$dfrn_only}} + {{include file="field_input.tpl" field=$global_directory}} + {{include file="field_checkbox.tpl" field=$newuser_private}} + {{include file="field_checkbox.tpl" field=$enotify_no_content}} + {{include file="field_checkbox.tpl" field=$private_addons}} + {{include file="field_checkbox.tpl" field=$disable_embedded}} +
+ +

{{$advanced}}

+ {{include file="field_checkbox.tpl" field=$verifyssl}} + {{include file="field_input.tpl" field=$proxy}} + {{include file="field_input.tpl" field=$proxyuser}} + {{include file="field_input.tpl" field=$timeout}} + {{include file="field_input.tpl" field=$delivery_interval}} + {{include file="field_input.tpl" field=$poll_interval}} + {{include file="field_input.tpl" field=$maxloadavg}} + {{include file="field_input.tpl" field=$abandon_days}} + +
+ +
+
diff --git a/view/theme/frost-mobile/templates/admin/users.tpl b/view/theme/frost-mobile/templates/admin/users.tpl new file mode 100644 index 000000000..f0c4869a7 --- /dev/null +++ b/view/theme/frost-mobile/templates/admin/users.tpl @@ -0,0 +1,98 @@ + +
+

{{$title}} - {{$page}}

+ +
+ + +

{{$h_pending}}

+ {{if $pending}} + + + + {{foreach $th_pending as $th}}{{/foreach}} + + + + + + {{foreach $pending as $u}} + + + + + + + + {{/foreach}} + +
{{$th}}
{{$u.created}}{{$u.name}} + + +
+ +
+ {{else}} +

{{$no_pending}}

+ {{/if}} + + + + +

{{$h_users}}

+ {{if $users}} + + + + + {{foreach $th_users as $th}}{{/foreach}} + + + + + + {{foreach $users as $u}} + + + + + + + + + + {{/if}} + + + {{/foreach}} + +
{{$th}}
{{$u.nickname}}{{$u.name}}{{$u.register_date}}{{$u.lastitem_date}} + {{if $u.is_admin}} +   + {{else}} + + {{if $u.is_admin}} +   + {{else}} + + + {{/if}} +
+ +
+ {{else}} + NO USERS?!? + {{/if}} +
+
diff --git a/view/theme/frost/templates/admin/aside.tpl b/view/theme/frost/templates/admin/aside.tpl new file mode 100644 index 000000000..74b6cd5f6 --- /dev/null +++ b/view/theme/frost/templates/admin/aside.tpl @@ -0,0 +1,32 @@ + + +

{{$admtxt}}

+ + +{{if $admin.update}} + +{{/if}} + + +{{if $admin.plugins_admin}}

{{$plugadmtxt}}

{{/if}} + + + +

{{$logtxt}}

+ + diff --git a/view/theme/frost/templates/admin/site.tpl b/view/theme/frost/templates/admin/site.tpl new file mode 100644 index 000000000..8dcfa9129 --- /dev/null +++ b/view/theme/frost/templates/admin/site.tpl @@ -0,0 +1,73 @@ + + +
+

{{$title}} - {{$page}}

+ +
+ + + {{include file="field_input.tpl" field=$sitename}} + {{include file="field_textarea.tpl" field=$banner}} + {{include file="field_select.tpl" field=$language}} + {{include file="field_select.tpl" field=$theme}} + {{include file="field_select.tpl" field=$theme_mobile}} + {{include file="field_select.tpl" field=$ssl_policy}} + {{include file="field_checkbox.tpl" field=$old_share}} + {{include file="field_checkbox.tpl" field=$hide_help}} + {{include file="field_select.tpl" field=$singleuser}} + +
+ +

{{$registration}}

+ {{include file="field_input.tpl" field=$register_text}} + {{include file="field_select.tpl" field=$register_policy}} + {{include file="field_input.tpl" field=$daily_registrations}} + {{include file="field_checkbox.tpl" field=$no_multi_reg}} + {{include file="field_checkbox.tpl" field=$no_openid}} + {{include file="field_checkbox.tpl" field=$no_regfullname}} + +
+ +

{{$upload}}

+ {{include file="field_input.tpl" field=$maximagesize}} + {{include file="field_input.tpl" field=$maximagelength}} + {{include file="field_input.tpl" field=$jpegimagequality}} + +

{{$corporate}}

+ {{include file="field_input.tpl" field=$allowed_sites}} + {{include file="field_input.tpl" field=$allowed_email}} + {{include file="field_checkbox.tpl" field=$block_public}} + {{include file="field_checkbox.tpl" field=$force_publish}} + {{include file="field_checkbox.tpl" field=$no_community_page}} + {{include file="field_checkbox.tpl" field=$ostatus_disabled}} + {{include file="field_checkbox.tpl" field=$diaspora_enabled}} + {{include file="field_checkbox.tpl" field=$dfrn_only}} + {{include file="field_input.tpl" field=$global_directory}} + {{include file="field_checkbox.tpl" field=$newuser_private}} + {{include file="field_checkbox.tpl" field=$enotify_no_content}} + {{include file="field_checkbox.tpl" field=$private_addons}} + {{include file="field_checkbox.tpl" field=$disable_embedded}} +
+ +

{{$advanced}}

+ {{include file="field_checkbox.tpl" field=$verifyssl}} + {{include file="field_input.tpl" field=$proxy}} + {{include file="field_input.tpl" field=$proxyuser}} + {{include file="field_input.tpl" field=$timeout}} + {{include file="field_input.tpl" field=$delivery_interval}} + {{include file="field_input.tpl" field=$poll_interval}} + {{include file="field_input.tpl" field=$maxloadavg}} + {{include file="field_input.tpl" field=$abandon_days}} + {{include file="field_input.tpl" field=$lockpath}} + {{include file="field_input.tpl" field=$temppath}} + {{include file="field_input.tpl" field=$basepath}} + +

{{$performance}}

+ {{include file="field_input.tpl" field=$itemcache}} + {{include file="field_input.tpl" field=$itemcache_duration}} + + +
+ +
+
diff --git a/view/theme/frost/templates/admin/users.tpl b/view/theme/frost/templates/admin/users.tpl new file mode 100644 index 000000000..f0c4869a7 --- /dev/null +++ b/view/theme/frost/templates/admin/users.tpl @@ -0,0 +1,98 @@ + +
+

{{$title}} - {{$page}}

+ +
+ + +

{{$h_pending}}

+ {{if $pending}} + + + + {{foreach $th_pending as $th}}{{/foreach}} + + + + + + {{foreach $pending as $u}} + + + + + + + + {{/foreach}} + +
{{$th}}
{{$u.created}}{{$u.name}} + + +
+ +
+ {{else}} +

{{$no_pending}}

+ {{/if}} + + + + +

{{$h_users}}

+ {{if $users}} + + + + + {{foreach $th_users as $th}}{{/foreach}} + + + + + + {{foreach $users as $u}} + + + + + + + + + + {{/if}} + + + {{/foreach}} + +
{{$th}}
{{$u.nickname}}{{$u.name}}{{$u.register_date}}{{$u.lastitem_date}} + {{if $u.is_admin}} +   + {{else}} + + {{if $u.is_admin}} +   + {{else}} + + + {{/if}} +
+ +
+ {{else}} + NO USERS?!? + {{/if}} +
+
diff --git a/view/theme/quattro/templates/admin/users.tpl b/view/theme/quattro/templates/admin/users.tpl new file mode 100644 index 000000000..ddb395db9 --- /dev/null +++ b/view/theme/quattro/templates/admin/users.tpl @@ -0,0 +1,155 @@ + + +
+

{{$title}} - {{$page}}

+ +
+ + +

{{$h_pending}}

+ {{if $pending}} + + + + {{foreach $th_pending as $th}}{{/foreach}} + + + + + + {{foreach $pending as $u}} + + + + + + + + + + + {{/foreach}} + +
{{$th}}
{{$u.created}}{{$u.name}} + + +

{{$pendingnotetext}}: {{$u.note}}

+ +
+ {{else}} +

{{$no_pending}}

+ {{/if}} + +

{{$h_users}}

+ {{if $users}} + + + + + {{foreach $th_users as $th}} + + {{/foreach}} + + + + + + {{foreach $users as $u}} + + + + + + + + + + {{else}} +   + {{/if}} + + + {{/foreach}} + +
+ + {{if $order_users == $th.1}} + {{if $order_direction_users == "+"}} + ↓ + {{else}} + ↑ + {{/if}} + {{else}} + ↕ + {{/if}} + {{$th.0}} +
{{$u.nickname}}{{$u.name}}{{$u.register_date}}{{$u.lastitem_date}} + {{if $u.is_deletable}} + + {{if $u.is_deletable}} + + + {{else}} +   + {{/if}} +
+ +
+ {{else}} + NO USERS?!? + {{/if}} +
+ {{if $deleted}} +

{{$h_deleted}}

+ + + + + {{foreach $th_deleted as $th}}{{/foreach}} + + + + {{foreach $deleted as $u}} + + + + + + + + + + {{/foreach}} + +
{{$th}}
{{$u.nickname}}{{$u.name}}{{$u.register_date}}{{$u.lastitem_date}}
+ {{/if}} +

{{$h_newuser}}

+
+ + + + + + + + + + + + + +
{{include file="field_input.tpl" field=$newusername}}
{{include file="field_input.tpl" field=$newusernickname}}
{{include file="field_input.tpl" field=$newuseremail}}
+
+
+
From 5fd4086fdcc7725dc2eddaf631b4819e84dfb61b Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 1 Dec 2017 00:41:26 -0500 Subject: [PATCH 05/71] Add block/unblock methods to Contact class --- src/Object/Contact.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/Object/Contact.php b/src/Object/Contact.php index 919113672..1aee2c2b5 100644 --- a/src/Object/Contact.php +++ b/src/Object/Contact.php @@ -821,4 +821,30 @@ class Contact extends BaseObject return $account_type; } + + /** + * @brief Blocks a contact + * + * @param int $uid + * @return bool + */ + public static function block($uid) + { + $return = dba::update('contact', ['blocked' => true], ['id' => $uid]); + + return $return; + } + + /** + * @brief Unblocks a contact + * + * @param int $uid + * @return bool + */ + public static function unblock($uid) + { + $return = dba::update('contact', ['blocked' => false], ['id' => $uid]); + + return $return; + } } From dc093196957f9106234e9270161c3bbad1c555f9 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 1 Dec 2017 00:43:39 -0500 Subject: [PATCH 06/71] Add admin/contactblock page - Add page template --- mod/admin.php | 93 +++++++++++++++++++ view/templates/admin/contactblock.tpl | 64 +++++++++++++ .../frio/templates/admin/contactblock.tpl | 63 +++++++++++++ 3 files changed, 220 insertions(+) create mode 100644 view/templates/admin/contactblock.tpl create mode 100644 view/theme/frio/templates/admin/contactblock.tpl diff --git a/mod/admin.php b/mod/admin.php index de981bb90..83ef15f4a 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -11,6 +11,8 @@ use Friendica\Core\Config; use Friendica\Core\Worker; use Friendica\Database\DBM; use Friendica\Model\User; +use Friendica\Network\Probe; +use Friendica\Object\Contact; require_once 'include/enotify.php'; require_once 'include/text.php'; @@ -117,6 +119,9 @@ function admin_post(App $a) case 'dbsync': admin_page_dbsync_post($a); break; + case 'contactblock': + admin_page_contactblock_post($a); + break; case 'blocklist': admin_page_blocklist_post($a); break; @@ -179,6 +184,7 @@ function admin_content(App $a) 'features' => array("admin/features/" , t("Additional features") , "features"), 'dbsync' => array("admin/dbsync/" , t('DB updates') , "dbsync"), 'queue' => array("admin/queue/" , t('Inspect Queue') , "queue"), + 'contactblock' => array("admin/contactblock/", t('Contact Blocklist') , "contactblock"), 'blocklist' => array("admin/blocklist/" , t('Server Blocklist') , "blocklist"), 'federation' => array("admin/federation/" , t('Federation Statistics'), "federation"), 'deleteitem' => array("admin/deleteitem/" , t('Delete Item') , 'deleteitem'), @@ -247,6 +253,9 @@ function admin_content(App $a) case 'federation': $o = admin_page_federation($a); break; + case 'contactblock': + $o = admin_page_contactblock($a); + break; case 'blocklist': $o = admin_page_blocklist($a); break; @@ -359,6 +368,90 @@ function admin_page_blocklist_post(App $a) return; // NOTREACHED } +/** + * @brief Process data send by the contact block admin page + * + * @param App $a + */ +function admin_page_contactblock_post(App $a) +{ + $contact_url = x($_POST, 'contact_url') ? $_POST['contact_url'] : ''; + $contacts = x($_POST, 'contacts') ? $_POST['contacts'] : []; + + check_form_security_token_redirectOnErr('/admin/contactblock', 'admin_contactblock'); + + if (x($_POST, 'page_contactblock_block')) { + $net = Probe::uri($contact_url); + if (in_array($net['network'], array(NETWORK_PHANTOM, NETWORK_MAIL))) { + notice(t('This contact doesn\'t seem to exist.')); + } + $nurl = normalise_link($net['url']); + $r = dba::select('contact', ['id'], ['nurl' => $nurl, 'uid' => 0], ['limit' => 1]); + if (DBM::is_result($r)) { + Contact::block($r['id']); + notice(t('The contact has been blocked from the node')); + } else { + notice(t('Could not find any contact entry for this URL (%s)', $nurl)); + } + } + if (x($_POST, 'page_contactblock_unblock')) { + foreach ($contacts as $uid) { + Contact::unblock($uid); + } + notice(tt("%s contact unblocked", "%s contacts unblocked", count($contacts))); + } + goaway('admin/contactblock'); + return; // NOTREACHED +} + +/** + * @brief Admin panel for server-wide contact block + * + * @param App $a + * @return string + */ +function admin_page_contactblock(App $a) +{ + $condition = ['uid' => 0, 'blocked' => true]; + + $total = dba::count('contact', $condition); + + $a->set_pager_total($total); + $a->set_pager_itemspage(30); + + $statement = dba::select('contact', [], $condition, ['limit' => [$a->pager['start'], $a->pager['itemspage']]]); + + $contacts = dba::inArray($statement); + + $t = get_markup_template('admin/contactblock.tpl'); + $o = replace_macros($t, array( + // strings // + '$title' => t('Administration'), + '$page' => t('Remote Contact Blocklist'), + '$description' => t('This page allows you to prevent any message from a remote contact to reach your node. However, your node must have knowledge of the contact before you can block it.'), + '$submit' => t('Block Remote Contact'), + '$select_all' => t('select all'), + '$select_none' => t('select none'), + '$block' => t('Block'), + '$unblock' => t('Unblock'), + '$no_data' => t('No remote contact is blocked from this node.'), + + '$h_contacts' => t('Blocked Remote Contacts'), + '$h_newblock' => t('Block New Remote Contact'), + '$th_contacts' => [t('Photo'), t('Name'), t('Address'), t('Profile URL')], + + '$form_security_token' => get_form_security_token("admin_contactblock"), + + // values // + '$baseurl' => System::baseUrl(true), + + '$contacts' => $contacts, + '$paginate' => paginate($a), + '$contacturl' => ['contact_url', t("Profile URL"), '', t("URL of the remote contact to block.")], + )); + return $o; +} + /** * @brief Subpage where the admin can delete an item from their node given the GUID * diff --git a/view/templates/admin/contactblock.tpl b/view/templates/admin/contactblock.tpl new file mode 100644 index 000000000..dcd33e879 --- /dev/null +++ b/view/templates/admin/contactblock.tpl @@ -0,0 +1,64 @@ + + +
+

{{$title}} - {{$page}}

+

{{$description}}

+
+ + +

{{$h_contacts}}

+ {{if $contacts}} + + + + + {{foreach $th_contacts as $th}} + + {{/foreach}} + + + + + {{foreach $contacts as $contact}} + + + + + + + + {{/foreach}} + +
+ {{$th}} +
{{$contact.nickname}}{{$contact.name}}{{$contact.addr}}{{$contact.url}}
+

{{$select_all}} | {{$select_none}}

+ {{$paginate}} +
+ {{else}} +

{{$no_data|escape:'html'}}

+ {{/if}} +
+ +

{{$h_newblock}}

+
+ + + + + + + +
{{include file="field_input.tpl" field=$contacturl}}
+
+
+
diff --git a/view/theme/frio/templates/admin/contactblock.tpl b/view/theme/frio/templates/admin/contactblock.tpl new file mode 100644 index 000000000..db0d2ed9d --- /dev/null +++ b/view/theme/frio/templates/admin/contactblock.tpl @@ -0,0 +1,63 @@ + + +
+

{{$title}} - {{$page}}

+

{{$description}}

+
+ + +

{{$h_contacts}}

+ {{if $contacts}} + + + + + {{foreach $th_contacts as $th}} + + {{/foreach}} + + + + + {{foreach $contacts as $contact}} + + + + + + + {{/foreach}} + +
+ {{$th}} +
{{$contact.nickname}}{{$contact.name}}{{$contact.url}}
+

{{$select_all}} | {{$select_none}}

+ {{$paginate}} +
+ {{else}} +

{{$no_data|escape:'html'}}

+ {{/if}} +
+ +

{{$h_newblock}}

+
+ + + + + + + +
{{include file="field_input.tpl" field=$contacturl}}
+
+
+
From 6008e3df111c722e6f2e01be81d197fed33dfd42 Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Fri, 1 Dec 2017 14:41:27 -0500 Subject: [PATCH 07/71] Email to src Create Email class and update/rename functions and function calls. --- include/dbstructure.php | 2 +- include/email.php | 317 -------------------------------------- mod/invite.php | 5 +- mod/item.php | 6 +- mod/settings.php | 7 +- src/Network/Probe.php | 10 +- src/Protocol/Email.php | 333 ++++++++++++++++++++++++++++++++++++++++ src/Util/Emailer.php | 7 +- src/Worker/Delivery.php | 18 +-- src/Worker/OnePoll.php | 20 +-- 10 files changed, 370 insertions(+), 355 deletions(-) delete mode 100644 include/email.php create mode 100644 src/Protocol/Email.php diff --git a/include/dbstructure.php b/include/dbstructure.php index dde3dc6f1..05b2bc07c 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -95,7 +95,7 @@ function update_fail($update_id, $error_message) { )); $subject=sprintf(t('Update Error at %s'), System::baseUrl()); require_once('include/email.php'); - $subject = email_header_encode($subject,'UTF-8'); + $subject = Email::emailHeaderEncode($subject,'UTF-8'); mail($a->config['admin_email'], $subject, $email_msg, 'From: ' . 'Administrator' . '@' . $_SERVER['SERVER_NAME']."\n" .'Content-type: text/plain; charset=UTF-8'."\n" diff --git a/include/email.php b/include/email.php deleted file mode 100644 index b3bd52a66..000000000 --- a/include/email.php +++ /dev/null @@ -1,317 +0,0 @@ - array(array()) is probably redundant now - return ((count($ret)) ? $ret : array()); -} - -function email_msg_headers($mbox,$uid) { - $raw_header = (($mbox && $uid) ? @imap_fetchheader($mbox,$uid,FT_UID) : ''); - $raw_header = str_replace("\r",'',$raw_header); - $ret = array(); - $h = explode("\n",$raw_header); - if (count($h)) - foreach ($h as $line ) { - if (preg_match("/^[a-zA-Z]/", $line)) { - $key = substr($line,0,strpos($line,':')); - $value = substr($line,strpos($line,':')+1); - - $last_entry = strtolower($key); - $ret[$last_entry] = trim($value); - } - else { - $ret[$last_entry] .= ' ' . trim($line); - } - } - return $ret; -} - - -function email_get_msg($mbox,$uid, $reply) { - $ret = array(); - - $struc = (($mbox && $uid) ? @imap_fetchstructure($mbox,$uid,FT_UID) : null); - - if (! $struc) - return $ret; - - if (! $struc->parts) { - $ret['body'] = email_get_part($mbox,$uid,$struc,0, 'html'); - $html = $ret['body']; - - if (trim($ret['body']) == '') - $ret['body'] = email_get_part($mbox,$uid,$struc,0, 'plain'); - else - $ret['body'] = html2bbcode($ret['body']); - } - else { - $text = ''; - $html = ''; - foreach ($struc->parts as $ptop => $p) { - $x = email_get_part($mbox,$uid,$p,$ptop + 1, 'plain'); - if ($x) { - $text .= $x; - } - - $x = email_get_part($mbox,$uid,$p,$ptop + 1, 'html'); - if ($x) { - $html .= $x; - } - } - if (trim($html) != '') { - $ret['body'] = html2bbcode($html); - } else { - $ret['body'] = $text; - } - } - - $ret['body'] = removegpg($ret['body']); - $msg = removesig($ret['body']); - $ret['body'] = $msg['body']; - $ret['body'] = convertquote($ret['body'], $reply); - - if (trim($html) != '') { - $ret['body'] = removelinebreak($ret['body']); - } - - $ret['body'] = unifyattributionline($ret['body']); - - return $ret; -} - -// At the moment - only return plain/text. -// Later we'll repackage inline images as data url's and make the HTML safe - -function email_get_part($mbox,$uid,$p,$partno, $subtype) { - // $partno = '1', '2', '2.1', '2.1.3', etc for multipart, 0 if simple - global $htmlmsg,$plainmsg,$charset,$attachments; - - //echo $partno."\n"; - - // DECODE DATA - $data = ($partno) - ? @imap_fetchbody($mbox,$uid,$partno, FT_UID|FT_PEEK) - : @imap_body($mbox,$uid,FT_UID|FT_PEEK); - - // Any part may be encoded, even plain text messages, so check everything. - if ($p->encoding==4) - $data = quoted_printable_decode($data); - elseif ($p->encoding==3) - $data = base64_decode($data); - - // PARAMETERS - // get all parameters, like charset, filenames of attachments, etc. - $params = array(); - if ($p->parameters) - foreach ($p->parameters as $x) - $params[strtolower($x->attribute)] = $x->value; - if (isset($p->dparameters) && $p->dparameters) - foreach ($p->dparameters as $x) - $params[strtolower($x->attribute)] = $x->value; - - // ATTACHMENT - // Any part with a filename is an attachment, - // so an attached text file (type 0) is not mistaken as the message. - - if ((isset($params['filename']) && $params['filename']) || (isset($params['name']) && $params['name'])) { - // filename may be given as 'Filename' or 'Name' or both - $filename = ($params['filename'])? $params['filename'] : $params['name']; - // filename may be encoded, so see imap_mime_header_decode() - $attachments[$filename] = $data; // this is a problem if two files have same name - } - - // TEXT - if ($p->type == 0 && $data) { - // Messages may be split in different parts because of inline attachments, - // so append parts together with blank row. - if (strtolower($p->subtype)==$subtype) { - $data = iconv($params['charset'], 'UTF-8//IGNORE', $data); - return (trim($data) ."\n\n"); - } else - $data = ''; - - // $htmlmsg .= $data ."

"; - $charset = $params['charset']; // assume all parts are same charset - } - - // EMBEDDED MESSAGE - // Many bounce notifications embed the original message as type 2, - // but AOL uses type 1 (multipart), which is not handled here. - // There are no PHP functions to parse embedded messages, - // so this just appends the raw source to the main message. -// elseif ($p->type==2 && $data) { -// $plainmsg .= $data."\n\n"; -// } - - // SUBPART RECURSION - if (isset($p->parts) && $p->parts) { - $x = ""; - foreach ($p->parts as $partno0=>$p2) { - $x .= email_get_part($mbox,$uid,$p2,$partno . '.' . ($partno0+1), $subtype); // 1.2, 1.2.1, etc. - //if ($x) { - // return $x; - //} - } - return $x; - } -} - - - -function email_header_encode($in_str, $charset) { - $out_str = $in_str; - $need_to_convert = false; - - for ($x = 0; $x < strlen($in_str); $x ++) { - if ((ord($in_str[$x]) == 0) || ((ord($in_str[$x]) > 128))) { - $need_to_convert = true; - } - } - - if (! $need_to_convert) - return $in_str; - - if ($out_str && $charset) { - - // define start delimimter, end delimiter and spacer - $end = "?="; - $start = "=?" . $charset . "?B?"; - $spacer = $end . "\r\n " . $start; - - // determine length of encoded text within chunks - // and ensure length is even - $length = 75 - strlen($start) - strlen($end); - - /* - [EDIT BY danbrown AT php DOT net: The following - is a bugfix provided by (gardan AT gmx DOT de) - on 31-MAR-2005 with the following note: - "This means: $length should not be even, - but divisible by 4. The reason is that in - base64-encoding 3 8-bit-chars are represented - by 4 6-bit-chars. These 4 chars must not be - split between two encoded words, according - to RFC-2047. - */ - $length = $length - ($length % 4); - - // encode the string and split it into chunks - // with spacers after each chunk - $out_str = base64_encode($out_str); - $out_str = chunk_split($out_str, $length, $spacer); - - // remove trailing spacer and - // add start and end delimiters - $spacer = preg_quote($spacer,'/'); - $out_str = preg_replace("/" . $spacer . "$/", "", $out_str); - $out_str = $start . $out_str . $end; - } - return $out_str; -} - -/** - * email_send is used by NETWORK_EMAIL and NETWORK_EMAIL2 code - * (not to notify the user, but to send items to email contacts) - * - * @todo This could be changed to use the Emailer class - */ -function email_send($addr, $subject, $headers, $item) { - //$headers .= 'MIME-Version: 1.0' . "\n"; - //$headers .= 'Content-Type: text/html; charset=UTF-8' . "\n"; - //$headers .= 'Content-Type: text/plain; charset=UTF-8' . "\n"; - //$headers .= 'Content-Transfer-Encoding: 8bit' . "\n\n"; - - $part = uniqid("", true); - - $html = prepare_body($item); - - $headers .= "Mime-Version: 1.0\n"; - $headers .= 'Content-Type: multipart/alternative; boundary="=_'.$part.'"'."\n\n"; - - $body = "\n--=_".$part."\n"; - $body .= "Content-Transfer-Encoding: 8bit\n"; - $body .= "Content-Type: text/plain; charset=utf-8; format=flowed\n\n"; - - $body .= html2plain($html)."\n"; - - $body .= "--=_".$part."\n"; - $body .= "Content-Transfer-Encoding: 8bit\n"; - $body .= "Content-Type: text/html; charset=utf-8\n\n"; - - $body .= ''.$html."\n"; - - $body .= "--=_".$part."--"; - - //$message = '' . $html . ''; - //$message = html2plain($html); - logger('notifier: email delivery to ' . $addr); - mail($addr, $subject, $body, $headers); -} - -function iri2msgid($iri) { - if (!strpos($iri, "@")) - $msgid = preg_replace("/urn:(\S+):(\S+)\.(\S+):(\d+):(\S+)/i", "urn!$1!$4!$5@$2.$3", $iri); - else - $msgid = $iri; - return($msgid); -} - -function msgid2iri($msgid) { - if (strpos($msgid, "@")) - $iri = preg_replace("/urn!(\S+)!(\d+)!(\S+)@(\S+)\.(\S+)/i", "urn:$1:$4.$5:$2:$3", $msgid); - else - $iri = $msgid; - return($iri); -} diff --git a/mod/invite.php b/mod/invite.php index 4f7abf36a..eb1ac8860 100644 --- a/mod/invite.php +++ b/mod/invite.php @@ -11,8 +11,7 @@ use Friendica\App; use Friendica\Core\Config; use Friendica\Core\PConfig; use Friendica\Core\System; - -require_once('include/email.php'); +use Friendica\Protocol\Email; function invite_post(App $a) { @@ -78,7 +77,7 @@ function invite_post(App $a) { $nmessage = $message; } - $res = mail($recip, email_header_encode( t('Please join us on Friendica'),'UTF-8'), + $res = mail($recip, Email::emailHeaderEncode(t('Please join us on Friendica'),'UTF-8'), $nmessage, "From: " . $a->user['email'] . "\n" . 'Content-type: text/plain; charset=UTF-8' . "\n" diff --git a/mod/item.php b/mod/item.php index fbedcd86b..97abce0ef 100644 --- a/mod/item.php +++ b/mod/item.php @@ -24,11 +24,11 @@ use Friendica\Model\GlobalContact; use Friendica\Network\Probe; use Friendica\Object\Contact; use Friendica\Protocol\Diaspora; +use Friendica\Protocol\Email; use Friendica\Util\Emailer; require_once 'include/crypto.php'; require_once 'include/enotify.php'; -require_once 'include/email.php'; require_once 'include/tags.php'; require_once 'include/files.php'; require_once 'include/threads.php'; @@ -1030,9 +1030,9 @@ function item_post(App $a) { $disclaimer .= sprintf( t('You may visit them online at %s'), System::baseUrl() . '/profile/' . $a->user['nickname']) . EOL; $disclaimer .= t('Please contact the sender by replying to this post if you do not wish to receive these messages.') . EOL; if (!$datarray['title']=='') { - $subject = email_header_encode($datarray['title'], 'UTF-8'); + $subject = Email::emailHeaderEncode($datarray['title'], 'UTF-8'); } else { - $subject = email_header_encode('[Friendica]' . ' ' . sprintf( t('%s posted an update.'), $a->user['username']), 'UTF-8'); + $subject = Email::emailHeaderEncode('[Friendica]' . ' ' . sprintf( t('%s posted an update.'), $a->user['username']), 'UTF-8'); } $link = '' . $a->user['username'] . '

'; $html = prepare_body($datarray); diff --git a/mod/settings.php b/mod/settings.php index 8ad82b023..1d7ac9178 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -10,6 +10,7 @@ use Friendica\Core\PConfig; use Friendica\Database\DBM; use Friendica\Model\GlobalContact; use Friendica\Model\User; +use Friendica\Protocol\Email; require_once 'include/group.php'; @@ -259,12 +260,12 @@ function settings_post(App $a) { ); if (DBM::is_result($r)) { $eacct = $r[0]; - require_once('include/email.php'); - $mb = construct_mailbox_name($eacct); + $mb = Email::constructMailboxName($eacct); + if (strlen($eacct['server'])) { $dcrpass = ''; openssl_private_decrypt(hex2bin($eacct['pass']), $dcrpass, $a->user['prvkey']); - $mbox = email_connect($mb, $mail_user, $dcrpass); + $mbox = Email::emailConnect($mb, $mail_user, $dcrpass); unset($dcrpass); if (!$mbox) { $failed = true; diff --git a/src/Network/Probe.php b/src/Network/Probe.php index 6001489ec..2216d7dcc 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -15,6 +15,7 @@ use Friendica\Core\Cache; use Friendica\Core\Config; use Friendica\Database\DBM; use Friendica\Object\Profile; +use Friendica\Protocol\Email; use Friendica\Util\XML; use dba; @@ -22,7 +23,6 @@ use DomXPath; use DOMDocument; require_once 'include/feed.php'; -require_once 'include/email.php'; require_once 'include/network.php'; /** @@ -1517,16 +1517,16 @@ class Probe $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1", intval($uid)); if (DBM::is_result($x) && DBM::is_result($r)) { - $mailbox = construct_mailbox_name($r[0]); + $mailbox = Email::constructMailboxName($r[0]); $password = ''; openssl_private_decrypt(hex2bin($r[0]['pass']), $password, $x[0]['prvkey']); - $mbox = email_connect($mailbox, $r[0]['user'], $password); + $mbox = Email::emailConnect($mailbox, $r[0]['user'], $password); if (!mbox) { return false; } } - $msgs = email_poll($mbox, $uri); + $msgs = Email::emailPoll($mbox, $uri); logger('searching '.$uri.', '.count($msgs).' messages found.', LOGGER_DEBUG); if (!count($msgs)) { @@ -1546,7 +1546,7 @@ class Probe $data["notify"] = 'smtp '.random_string(); $data["poll"] = 'email '.random_string(); - $x = email_msg_meta($mbox, $msgs[0]); + $x = Email::emailMsgMeta($mbox, $msgs[0]); if (stristr($x[0]->from, $uri)) { $adr = imap_rfc822_parse_adrlist($x[0]->from, ''); } elseif (stristr($x[0]->to, $uri)) { diff --git a/src/Protocol/Email.php b/src/Protocol/Email.php new file mode 100644 index 000000000..d147da116 --- /dev/null +++ b/src/Protocol/Email.php @@ -0,0 +1,333 @@ + array(array()) is probably redundant now + return ((count($ret)) ? $ret : array()); + } + + /** + * @brief Check addons, not called from main friendica project + */ + function email_msg_headers($mbox, $uid) { + $raw_header = (($mbox && $uid) ? @imap_fetchheader($mbox,$uid,FT_UID) : ''); + $raw_header = str_replace("\r",'',$raw_header); + $ret = array(); + $h = explode("\n",$raw_header); + if (count($h)) + foreach ($h as $line ) { + if (preg_match("/^[a-zA-Z]/", $line)) { + $key = substr($line,0,strpos($line,':')); + $value = substr($line,strpos($line,':')+1); + + $last_entry = strtolower($key); + $ret[$last_entry] = trim($value); + } + else { + $ret[$last_entry] .= ' ' . trim($line); + } + } + return $ret; + } + + public static function emailGetMsg($mbox, $uid, $reply) + { + $ret = array(); + + $struc = (($mbox && $uid) ? @imap_fetchstructure($mbox,$uid,FT_UID) : null); + + if (! $struc) + return $ret; + + if (! $struc->parts) { + $ret['body'] = self::emailGetPart($mbox,$uid,$struc,0, 'html'); + $html = $ret['body']; + + if (trim($ret['body']) == '') + $ret['body'] = self::emailGetPart($mbox,$uid,$struc,0, 'plain'); + else + $ret['body'] = html2bbcode($ret['body']); + } + else { + $text = ''; + $html = ''; + foreach ($struc->parts as $ptop => $p) { + $x = self::emailGetPart($mbox,$uid,$p,$ptop + 1, 'plain'); + if ($x) { + $text .= $x; + } + + $x = self::emailGetPart($mbox,$uid,$p,$ptop + 1, 'html'); + if ($x) { + $html .= $x; + } + } + if (trim($html) != '') { + $ret['body'] = html2bbcode($html); + } else { + $ret['body'] = $text; + } + } + + $ret['body'] = removegpg($ret['body']); + $msg = removesig($ret['body']); + $ret['body'] = $msg['body']; + $ret['body'] = convertquote($ret['body'], $reply); + + if (trim($html) != '') { + $ret['body'] = removelinebreak($ret['body']); + } + + $ret['body'] = unifyattributionline($ret['body']); + + return $ret; + } + + // At the moment - only return plain/text. + // Later we'll repackage inline images as data url's and make the HTML safe + + private static function emailGetPart($mbox, $uid, $p, $partno, $subtype) + { + // $partno = '1', '2', '2.1', '2.1.3', etc for multipart, 0 if simple + global $htmlmsg,$plainmsg,$charset,$attachments; + + //echo $partno."\n"; + + // DECODE DATA + $data = ($partno) + ? @imap_fetchbody($mbox,$uid,$partno, FT_UID|FT_PEEK) + : @imap_body($mbox,$uid,FT_UID|FT_PEEK); + + // Any part may be encoded, even plain text messages, so check everything. + if ($p->encoding==4) + $data = quoted_printable_decode($data); + elseif ($p->encoding==3) + $data = base64_decode($data); + + // PARAMETERS + // get all parameters, like charset, filenames of attachments, etc. + $params = array(); + if ($p->parameters) + foreach ($p->parameters as $x) + $params[strtolower($x->attribute)] = $x->value; + if (isset($p->dparameters) && $p->dparameters) + foreach ($p->dparameters as $x) + $params[strtolower($x->attribute)] = $x->value; + + // ATTACHMENT + // Any part with a filename is an attachment, + // so an attached text file (type 0) is not mistaken as the message. + + if ((isset($params['filename']) && $params['filename']) || (isset($params['name']) && $params['name'])) { + // filename may be given as 'Filename' or 'Name' or both + $filename = ($params['filename'])? $params['filename'] : $params['name']; + // filename may be encoded, so see imap_mime_header_decode() + $attachments[$filename] = $data; // this is a problem if two files have same name + } + + // TEXT + if ($p->type == 0 && $data) { + // Messages may be split in different parts because of inline attachments, + // so append parts together with blank row. + if (strtolower($p->subtype)==$subtype) { + $data = iconv($params['charset'], 'UTF-8//IGNORE', $data); + return (trim($data) ."\n\n"); + } else + $data = ''; + + // $htmlmsg .= $data ."

"; + $charset = $params['charset']; // assume all parts are same charset + } + + // EMBEDDED MESSAGE + // Many bounce notifications embed the original message as type 2, + // but AOL uses type 1 (multipart), which is not handled here. + // There are no PHP functions to parse embedded messages, + // so this just appends the raw source to the main message. + // elseif ($p->type==2 && $data) { + // $plainmsg .= $data."\n\n"; + // } + + // SUBPART RECURSION + if (isset($p->parts) && $p->parts) { + $x = ""; + foreach ($p->parts as $partno0=>$p2) { + $x .= self::emailGetPart($mbox,$uid,$p2,$partno . '.' . ($partno0+1), $subtype); // 1.2, 1.2.1, etc. + //if ($x) { + // return $x; + //} + } + return $x; + } + } + + public static function emailHeaderEncode($in_str, $charset) + { + $out_str = $in_str; + $need_to_convert = false; + + for ($x = 0; $x < strlen($in_str); $x ++) { + if ((ord($in_str[$x]) == 0) || ((ord($in_str[$x]) > 128))) { + $need_to_convert = true; + } + } + + if (! $need_to_convert) + return $in_str; + + if ($out_str && $charset) { + + // define start delimimter, end delimiter and spacer + $end = "?="; + $start = "=?" . $charset . "?B?"; + $spacer = $end . "\r\n " . $start; + + // determine length of encoded text within chunks + // and ensure length is even + $length = 75 - strlen($start) - strlen($end); + + /* + [EDIT BY danbrown AT php DOT net: The following + is a bugfix provided by (gardan AT gmx DOT de) + on 31-MAR-2005 with the following note: + "This means: $length should not be even, + but divisible by 4. The reason is that in + base64-encoding 3 8-bit-chars are represented + by 4 6-bit-chars. These 4 chars must not be + split between two encoded words, according + to RFC-2047. + */ + $length = $length - ($length % 4); + + // encode the string and split it into chunks + // with spacers after each chunk + $out_str = base64_encode($out_str); + $out_str = chunk_split($out_str, $length, $spacer); + + // remove trailing spacer and + // add start and end delimiters + $spacer = preg_quote($spacer,'/'); + $out_str = preg_replace("/" . $spacer . "$/", "", $out_str); + $out_str = $start . $out_str . $end; + } + return $out_str; + } + + /** + * emailSend is used by NETWORK_EMAIL and NETWORK_EMAIL2 code + * (not to notify the user, but to send items to email contacts) + * + * @todo This could be changed to use the Emailer class + */ + public static function emailSend($addr, $subject, $headers, $item) + { + //$headers .= 'MIME-Version: 1.0' . "\n"; + //$headers .= 'Content-Type: text/html; charset=UTF-8' . "\n"; + //$headers .= 'Content-Type: text/plain; charset=UTF-8' . "\n"; + //$headers .= 'Content-Transfer-Encoding: 8bit' . "\n\n"; + + $part = uniqid("", true); + + $html = prepare_body($item); + + $headers .= "Mime-Version: 1.0\n"; + $headers .= 'Content-Type: multipart/alternative; boundary="=_'.$part.'"'."\n\n"; + + $body = "\n--=_".$part."\n"; + $body .= "Content-Transfer-Encoding: 8bit\n"; + $body .= "Content-Type: text/plain; charset=utf-8; format=flowed\n\n"; + + $body .= html2plain($html)."\n"; + + $body .= "--=_".$part."\n"; + $body .= "Content-Transfer-Encoding: 8bit\n"; + $body .= "Content-Type: text/html; charset=utf-8\n\n"; + + $body .= ''.$html."\n"; + + $body .= "--=_".$part."--"; + + //$message = '' . $html . ''; + //$message = html2plain($html); + logger('notifier: email delivery to ' . $addr); + mail($addr, $subject, $body, $headers); + } + + public static function iri2msgid($iri) + { + if (!strpos($iri, "@")) + $msgid = preg_replace("/urn:(\S+):(\S+)\.(\S+):(\d+):(\S+)/i", "urn!$1!$4!$5@$2.$3", $iri); + else + $msgid = $iri; + return($msgid); + } + + public static function msgid2iri($msgid) + { + if (strpos($msgid, "@")) + $iri = preg_replace("/urn!(\S+)!(\d+)!(\S+)@(\S+)\.(\S+)/i", "urn:$1:$4.$5:$2:$3", $msgid); + else + $iri = $msgid; + return($iri); + } +} diff --git a/src/Util/Emailer.php b/src/Util/Emailer.php index a2be983d6..434c3da79 100644 --- a/src/Util/Emailer.php +++ b/src/Util/Emailer.php @@ -5,8 +5,7 @@ namespace Friendica\Util; use Friendica\Core\PConfig; - -require_once 'include/email.php'; +use Friendica\Protocol\Email; /** * @breif class to handle emailing @@ -38,8 +37,8 @@ class Emailer $email_textonly = PConfig::get($params['uid'], "system", "email_textonly"); } - $fromName = email_header_encode(html_entity_decode($params['fromName'], ENT_QUOTES, 'UTF-8'), 'UTF-8'); - $messageSubject = email_header_encode(html_entity_decode($params['messageSubject'], ENT_QUOTES, 'UTF-8'), 'UTF-8'); + $fromName = Email::emailHeaderEncode(html_entity_decode($params['fromName'], ENT_QUOTES, 'UTF-8'), 'UTF-8'); + $messageSubject = Email::emailHeaderEncode(html_entity_decode($params['messageSubject'], ENT_QUOTES, 'UTF-8'), 'UTF-8'); // generate a mime boundary $mimeBoundary =rand(0, 9)."-" diff --git a/src/Worker/Delivery.php b/src/Worker/Delivery.php index c47e98287..7d800f54f 100644 --- a/src/Worker/Delivery.php +++ b/src/Worker/Delivery.php @@ -12,13 +12,13 @@ use Friendica\Database\DBM; use Friendica\Object\Contact; use Friendica\Protocol\Diaspora; use Friendica\Protocol\DFRN; +use Friendica\Protocol\Email; require_once 'include/queue_fn.php'; require_once 'include/html2plain.php'; require_once 'include/datetime.php'; require_once 'include/items.php'; require_once 'include/bbcode.php'; -require_once 'include/email.php'; /// @todo This is some ugly code that needs to be split into several methods @@ -418,36 +418,36 @@ class Delivery { if ($r1 && $r1[0]['reply_to']) $reply_to = $r1[0]['reply_to']; - $subject = (($it['title']) ? email_header_encode($it['title'],'UTF-8') : t("\x28no subject\x29")) ; + $subject = (($it['title']) ? Email::emailHeaderEncode($it['title'],'UTF-8') : t("\x28no subject\x29")) ; // only expose our real email address to true friends if (($contact['rel'] == CONTACT_IS_FRIEND) && !$contact['blocked']) { if ($reply_to) { - $headers = 'From: '.email_header_encode($local_user[0]['username'],'UTF-8').' <'.$reply_to.'>'."\n"; + $headers = 'From: '.Email::emailHeaderEncode($local_user[0]['username'],'UTF-8').' <'.$reply_to.'>'."\n"; $headers .= 'Sender: '.$local_user[0]['email']."\n"; } else { - $headers = 'From: '.email_header_encode($local_user[0]['username'],'UTF-8').' <'.$local_user[0]['email'].'>'."\n"; + $headers = 'From: '.Email::emailHeaderEncode($local_user[0]['username'],'UTF-8').' <'.$local_user[0]['email'].'>'."\n"; } } else { - $headers = 'From: '. email_header_encode($local_user[0]['username'],'UTF-8') .' <'. t('noreply') .'@'.$a->get_hostname() .'>'. "\n"; + $headers = 'From: '. Email::emailHeaderEncode($local_user[0]['username'],'UTF-8') .' <'. t('noreply') .'@'.$a->get_hostname() .'>'. "\n"; } //if ($reply_to) // $headers .= 'Reply-to: '.$reply_to . "\n"; - $headers .= 'Message-Id: <'. iri2msgid($it['uri']).'>'. "\n"; + $headers .= 'Message-Id: <'. Email::iri2msgid($it['uri']).'>'. "\n"; //logger("Mail: uri: ".$it['uri']." parent-uri ".$it['parent-uri'], LOGGER_DEBUG); //logger("Mail: Data: ".print_r($it, true), LOGGER_DEBUG); //logger("Mail: Data: ".print_r($it, true), LOGGER_DATA); if ($it['uri'] !== $it['parent-uri']) { - $headers .= "References: <".iri2msgid($it["parent-uri"]).">"; + $headers .= "References: <".Email::iri2msgid($it["parent-uri"]).">"; // If Threading is enabled, write down the correct parent if (($it["thr-parent"] != "") && ($it["thr-parent"] != $it["parent-uri"])) - $headers .= " <".iri2msgid($it["thr-parent"]).">"; + $headers .= " <".Email::iri2msgid($it["thr-parent"]).">"; $headers .= "\n"; if (!$it['title']) { @@ -469,7 +469,7 @@ class Delivery { if (strncasecmp($subject,'RE:',3)) $subject = 'Re: '.$subject; } - email_send($addr, $subject, $headers, $it); + Email::emailSend($addr, $subject, $headers, $it); } break; diff --git a/src/Worker/OnePoll.php b/src/Worker/OnePoll.php index 356fce433..3f00454b2 100644 --- a/src/Worker/OnePoll.php +++ b/src/Worker/OnePoll.php @@ -8,6 +8,7 @@ use Friendica\Core\Config; use Friendica\Core\PConfig; use Friendica\Database\DBM; use Friendica\Object\Contact; +use Friendica\Protocol\Email; use Friendica\Protocol\PortableContact; use dba; @@ -20,7 +21,6 @@ Class OnePoll require_once 'include/datetime.php'; require_once 'include/items.php'; - require_once 'include/email.php'; require_once 'include/queue_fn.php'; logger('onepoll: start'); @@ -328,10 +328,10 @@ Class OnePoll $condition = array("`server` != '' AND `uid` = ?", $importer_uid); $mailconf = dba::select('mailacct', array(), $condition, array('limit' => 1)); if (DBM::is_result($x) && DBM::is_result($mailconf)) { - $mailbox = construct_mailbox_name($mailconf); + $mailbox = Email::constructMailboxName($mailconf); $password = ''; openssl_private_decrypt(hex2bin($mailconf['pass']), $password, $x['prvkey']); - $mbox = email_connect($mailbox, $mailconf['user'], $password); + $mbox = Email::emailConnect($mailbox, $mailconf['user'], $password); unset($password); logger("Mail: Connect to " . $mailconf['user']); if ($mbox) { @@ -344,12 +344,12 @@ Class OnePoll } if ($mbox) { - $msgs = email_poll($mbox, $contact['addr']); + $msgs = Email::emailPoll($mbox, $contact['addr']); if (count($msgs)) { logger("Mail: Parsing ".count($msgs)." mails from ".$contact['addr']." for ".$mailconf['user'], LOGGER_DEBUG); - $metas = email_msg_meta($mbox,implode(',', $msgs)); + $metas = Email::emailMsgMeta($mbox,implode(',', $msgs)); if (count($metas) != count($msgs)) { logger("onepoll: for " . $mailconf['user'] . " there are ". count($msgs) . " messages but received " . count($metas) . " metas", LOGGER_DEBUG); } else { @@ -361,10 +361,10 @@ Class OnePoll $datarray = array(); $datarray['verb'] = ACTIVITY_POST; $datarray['object-type'] = ACTIVITY_OBJ_NOTE; - // $meta = email_msg_meta($mbox, $msg_uid); - // $headers = email_msg_headers($mbox, $msg_uid); + // $meta = Email::emailMsgMeta($mbox, $msg_uid); + // $headers = email_msg_headers($mbox, $msg_uid); - $datarray['uri'] = msgid2iri(trim($meta->message_id, '<>')); + $datarray['uri'] = Email::msgid2iri(trim($meta->message_id, '<>')); // Have we seen it before? $fields = array('deleted', 'id'); @@ -416,7 +416,7 @@ Class OnePoll $refs_arr = explode(' ', $raw_refs); if (count($refs_arr)) { for ($x = 0; $x < count($refs_arr); $x ++) { - $refs_arr[$x] = "'" . msgid2iri(str_replace(array('<', '>', ' '),array('', '', ''),dbesc($refs_arr[$x]))) . "'"; + $refs_arr[$x] = "'" . Email::msgid2iri(str_replace(array('<', '>', ' '),array('', '', ''),dbesc($refs_arr[$x]))) . "'"; } } $qstr = implode(',', $refs_arr); @@ -466,7 +466,7 @@ Class OnePoll $datarray['parent-uri'] = $datarray['uri']; } - $r = email_get_msg($mbox, $msg_uid, $reply); + $r = Email::emailGetMsg($mbox, $msg_uid, $reply); if (!$r) { logger("Mail: can't fetch msg ".$msg_uid." for ".$mailconf['user']); continue; From f21feb975db4d47071bc174494c5c0f2a5816664 Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Fri, 1 Dec 2017 14:57:13 -0500 Subject: [PATCH 08/71] Require Cleanup Remove instances of require_once for email.php --- include/dbstructure.php | 4 ++-- include/enotify.php | 1 - include/items.php | 1 - mod/lostpass.php | 9 +++++---- src/Worker/Notifier.php | 1 - 5 files changed, 7 insertions(+), 9 deletions(-) diff --git a/include/dbstructure.php b/include/dbstructure.php index 05b2bc07c..297ada0f8 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -94,8 +94,8 @@ function update_fail($update_id, $error_message) { '$error' => sprintf(t('Update %s failed. See error logs.'), DB_UPDATE_VERSION) )); $subject=sprintf(t('Update Error at %s'), System::baseUrl()); - require_once('include/email.php'); - $subject = Email::emailHeaderEncode($subject,'UTF-8'); + + $subject = Email::emailHeaderEncode($subject,'UTF-8'); // use Friendica\Protocol\Email; mail($a->config['admin_email'], $subject, $email_msg, 'From: ' . 'Administrator' . '@' . $_SERVER['SERVER_NAME']."\n" .'Content-type: text/plain; charset=UTF-8'."\n" diff --git a/include/enotify.php b/include/enotify.php index dc030fa8b..99d5ea0ab 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -8,7 +8,6 @@ use Friendica\Core\System; use Friendica\Database\DBM; use Friendica\Util\Emailer; -require_once 'include/email.php'; require_once 'include/bbcode.php'; require_once 'include/html2bbcode.php'; diff --git a/include/items.php b/include/items.php index d446d2773..7cbcfaaaf 100644 --- a/include/items.php +++ b/include/items.php @@ -22,7 +22,6 @@ require_once 'include/crypto.php'; require_once 'include/tags.php'; require_once 'include/files.php'; require_once 'include/text.php'; -require_once 'include/email.php'; require_once 'include/threads.php'; require_once 'include/plaintext.php'; require_once 'include/feed.php'; diff --git a/mod/lostpass.php b/mod/lostpass.php index 1a30effd4..b3304fda1 100644 --- a/mod/lostpass.php +++ b/mod/lostpass.php @@ -1,12 +1,13 @@ Date: Fri, 1 Dec 2017 18:13:39 -0500 Subject: [PATCH 09/71] Code Cleanup Standards clean up --- include/dbstructure.php | 4 +- mod/invite.php | 6 +- mod/item.php | 4 +- src/Protocol/Email.php | 139 ++++++++++++++++++++++++++++++---------- src/Util/Emailer.php | 2 +- 5 files changed, 113 insertions(+), 42 deletions(-) diff --git a/include/dbstructure.php b/include/dbstructure.php index 297ada0f8..f7a221968 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -1,5 +1,7 @@ array(array()) is probably redundant now - return ((count($ret)) ? $ret : array()); + $ret = (($mbox && $uid) ? @imap_fetch_overview($mbox, $uid, FT_UID) : array(array())); // POSSIBLE CLEANUP --> array(array()) is probably redundant now + return (count($ret)) ? $ret : array(); } /** * @brief Check addons, not called from main friendica project + * I don't see it in addons either */ function email_msg_headers($mbox, $uid) { $raw_header = (($mbox && $uid) ? @imap_fetchheader($mbox,$uid,FT_UID) : ''); @@ -90,34 +114,41 @@ class Email return $ret; } + /** + * @param object $mbox mailbox + * @param integer $uid user id + * @param string $reply reply + * @return array + */ public static function emailGetMsg($mbox, $uid, $reply) { $ret = array(); - $struc = (($mbox && $uid) ? @imap_fetchstructure($mbox,$uid,FT_UID) : null); + $struc = (($mbox && $uid) ? @imap_fetchstructure($mbox, $uid, FT_UID) : null); - if (! $struc) + if (! $struc) { return $ret; + } if (! $struc->parts) { - $ret['body'] = self::emailGetPart($mbox,$uid,$struc,0, 'html'); + $ret['body'] = self::emailGetPart($mbox, $uid, $struc, 0, 'html'); $html = $ret['body']; - if (trim($ret['body']) == '') - $ret['body'] = self::emailGetPart($mbox,$uid,$struc,0, 'plain'); - else + if (trim($ret['body']) == '') { + $ret['body'] = self::emailGetPart($mbox, $uid, $struc, 0, 'plain'); + } else { $ret['body'] = html2bbcode($ret['body']); - } - else { + } + } else { $text = ''; $html = ''; foreach ($struc->parts as $ptop => $p) { - $x = self::emailGetPart($mbox,$uid,$p,$ptop + 1, 'plain'); + $x = self::emailGetPart($mbox, $uid, $p, $ptop + 1, 'plain'); if ($x) { $text .= $x; } - $x = self::emailGetPart($mbox,$uid,$p,$ptop + 1, 'html'); + $x = self::emailGetPart($mbox, $uid, $p, $ptop + 1, 'html'); if ($x) { $html .= $x; } @@ -145,7 +176,14 @@ class Email // At the moment - only return plain/text. // Later we'll repackage inline images as data url's and make the HTML safe - + /** + * @param object $mbox mailbox + * @param integer $uid user id + * @param object $p parts + * @param integer $partno part number + * @param string $subtype sub type + * @return string + */ private static function emailGetPart($mbox, $uid, $p, $partno, $subtype) { // $partno = '1', '2', '2.1', '2.1.3', etc for multipart, 0 if simple @@ -155,24 +193,30 @@ class Email // DECODE DATA $data = ($partno) - ? @imap_fetchbody($mbox,$uid,$partno, FT_UID|FT_PEEK) - : @imap_body($mbox,$uid,FT_UID|FT_PEEK); + ? @imap_fetchbody($mbox, $uid, $partno, FT_UID|FT_PEEK) + : @imap_body($mbox, $uid, FT_UID|FT_PEEK); // Any part may be encoded, even plain text messages, so check everything. - if ($p->encoding==4) + if ($p->encoding==4) { $data = quoted_printable_decode($data); - elseif ($p->encoding==3) + } elseif ($p->encoding==3) { $data = base64_decode($data); + } // PARAMETERS // get all parameters, like charset, filenames of attachments, etc. $params = array(); - if ($p->parameters) - foreach ($p->parameters as $x) + if ($p->parameters) { + foreach ($p->parameters as $x) { $params[strtolower($x->attribute)] = $x->value; - if (isset($p->dparameters) && $p->dparameters) - foreach ($p->dparameters as $x) + } + } + + if (isset($p->dparameters) && $p->dparameters) { + foreach ($p->dparameters as $x) { $params[strtolower($x->attribute)] = $x->value; + } + } // ATTACHMENT // Any part with a filename is an attachment, @@ -192,8 +236,9 @@ class Email if (strtolower($p->subtype)==$subtype) { $data = iconv($params['charset'], 'UTF-8//IGNORE', $data); return (trim($data) ."\n\n"); - } else + } else { $data = ''; + } // $htmlmsg .= $data ."

"; $charset = $params['charset']; // assume all parts are same charset @@ -211,8 +256,8 @@ class Email // SUBPART RECURSION if (isset($p->parts) && $p->parts) { $x = ""; - foreach ($p->parts as $partno0=>$p2) { - $x .= self::emailGetPart($mbox,$uid,$p2,$partno . '.' . ($partno0+1), $subtype); // 1.2, 1.2.1, etc. + foreach ($p->parts as $partno0 => $p2) { + $x .= self::emailGetPart($mbox, $uid, $p2, $partno . '.' . ($partno0+1), $subtype); // 1.2, 1.2.1, etc. //if ($x) { // return $x; //} @@ -221,6 +266,11 @@ class Email } } + /** + * @param string $in_str in string + * @param string $charset character set + * @return string + */ public static function emailHeaderEncode($in_str, $charset) { $out_str = $in_str; @@ -232,11 +282,11 @@ class Email } } - if (! $need_to_convert) + if (! $need_to_convert) { return $in_str; + } if ($out_str && $charset) { - // define start delimimter, end delimiter and spacer $end = "?="; $start = "=?" . $charset . "?B?"; @@ -266,7 +316,7 @@ class Email // remove trailing spacer and // add start and end delimiters - $spacer = preg_quote($spacer,'/'); + $spacer = preg_quote($spacer, '/'); $out_str = preg_replace("/" . $spacer . "$/", "", $out_str); $out_str = $start . $out_str . $end; } @@ -274,9 +324,16 @@ class Email } /** - * emailSend is used by NETWORK_EMAIL and NETWORK_EMAIL2 code + * Function emailSend is used by NETWORK_EMAIL and NETWORK_EMAIL2 code * (not to notify the user, but to send items to email contacts) * + * @param string $addr address + * @param string $subject subject + * @param string $headers headers + * @param array $item item + * + * @return void + * * @todo This could be changed to use the Emailer class */ public static function emailSend($addr, $subject, $headers, $item) @@ -313,21 +370,33 @@ class Email mail($addr, $subject, $body, $headers); } + /** + * @param string $iri string + * @return string + */ public static function iri2msgid($iri) { - if (!strpos($iri, "@")) + if (!strpos($iri, "@")) { $msgid = preg_replace("/urn:(\S+):(\S+)\.(\S+):(\d+):(\S+)/i", "urn!$1!$4!$5@$2.$3", $iri); - else + } else { $msgid = $iri; + } + return($msgid); } + /** + * @param string $msgid msgid + * @return string + */ public static function msgid2iri($msgid) { - if (strpos($msgid, "@")) + if (strpos($msgid, "@")) { $iri = preg_replace("/urn!(\S+)!(\d+)!(\S+)@(\S+)\.(\S+)/i", "urn:$1:$4.$5:$2:$3", $msgid); - else + } else { $iri = $msgid; + } + return($iri); } } diff --git a/src/Util/Emailer.php b/src/Util/Emailer.php index 434c3da79..ec3720400 100644 --- a/src/Util/Emailer.php +++ b/src/Util/Emailer.php @@ -8,7 +8,7 @@ use Friendica\Core\PConfig; use Friendica\Protocol\Email; /** - * @breif class to handle emailing + * @brief class to handle emailing */ class Emailer { From 9a4e741d1ae4fdd0e172c6ee572568ed326793ba Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Fri, 1 Dec 2017 21:05:06 -0500 Subject: [PATCH 10/71] Review Changes renamed some functions and adjusted corresponding calls. --- include/dbstructure.php | 24 ++----------------- mod/invite.php | 2 +- mod/item.php | 4 ++-- mod/settings.php | 2 +- src/Network/Probe.php | 6 ++--- src/Protocol/Email.php | 51 +++++++++++------------------------------ src/Util/Emailer.php | 4 ++-- src/Worker/Delivery.php | 10 ++++---- src/Worker/OnePoll.php | 11 ++++----- 9 files changed, 34 insertions(+), 80 deletions(-) diff --git a/include/dbstructure.php b/include/dbstructure.php index f7a221968..cb2883d40 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -79,30 +79,10 @@ function update_fail($update_id, $error_message) { 'to_email' => $admin['email'], 'preamble' => $preamble, 'body' => $body, - 'language' => $lang, - )); + 'language' => $lang) + ); } - - - - /* - @TODO deprecated code? - $email_tpl = get_intltext_template("update_fail_eml.tpl"); - $email_msg = replace_macros($email_tpl, array( - '$sitename' => $a->config['sitename'], - '$siteurl' => System::baseUrl(), - '$update' => DB_UPDATE_VERSION, - '$error' => sprintf(t('Update %s failed. See error logs.'), DB_UPDATE_VERSION) - )); - $subject=sprintf(t('Update Error at %s'), System::baseUrl()); - - $subject = Email::emailHeaderEncode($subject,'UTF-8'); // use Friendica\Protocol\Email; - mail($a->config['admin_email'], $subject, $email_msg, - 'From: ' . 'Administrator' . '@' . $_SERVER['SERVER_NAME']."\n" - .'Content-type: text/plain; charset=UTF-8'."\n" - .'Content-transfer-encoding: 8bit'); - */ //try the logger logger("CRITICAL: Database structure update failed: ".$retval); } diff --git a/mod/invite.php b/mod/invite.php index 2571bff92..06c0df3b8 100644 --- a/mod/invite.php +++ b/mod/invite.php @@ -75,7 +75,7 @@ function invite_post(App $a) { $nmessage = $message; } - $res = mail($recip, Email::emailHeaderEncode(t('Please join us on Friendica'),'UTF-8'), + $res = mail($recip, Email::encodeHeader(t('Please join us on Friendica'),'UTF-8'), $nmessage, "From: " . $a->user['email'] . "\n" . 'Content-type: text/plain; charset=UTF-8' . "\n" diff --git a/mod/item.php b/mod/item.php index d8ecf50a4..ffac1c8e4 100644 --- a/mod/item.php +++ b/mod/item.php @@ -1032,9 +1032,9 @@ function item_post(App $a) { $disclaimer .= sprintf( t('You may visit them online at %s'), System::baseUrl() . '/profile/' . $a->user['nickname']) . EOL; $disclaimer .= t('Please contact the sender by replying to this post if you do not wish to receive these messages.') . EOL; if (!$datarray['title']=='') { - $subject = Email::emailHeaderEncode($datarray['title'], 'UTF-8'); + $subject = Email::encodeHeader($datarray['title'], 'UTF-8'); } else { - $subject = Email::emailHeaderEncode('[Friendica]' . ' ' . sprintf( t('%s posted an update.'), $a->user['username']), 'UTF-8'); + $subject = Email::encodeHeader('[Friendica]' . ' ' . sprintf( t('%s posted an update.'), $a->user['username']), 'UTF-8'); } $link = '' . $a->user['username'] . '

'; $html = prepare_body($datarray); diff --git a/mod/settings.php b/mod/settings.php index 1d7ac9178..af514e3a9 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -265,7 +265,7 @@ function settings_post(App $a) { if (strlen($eacct['server'])) { $dcrpass = ''; openssl_private_decrypt(hex2bin($eacct['pass']), $dcrpass, $a->user['prvkey']); - $mbox = Email::emailConnect($mb, $mail_user, $dcrpass); + $mbox = Email::connect($mb, $mail_user, $dcrpass); unset($dcrpass); if (!$mbox) { $failed = true; diff --git a/src/Network/Probe.php b/src/Network/Probe.php index 2216d7dcc..500aa7323 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -1520,13 +1520,13 @@ class Probe $mailbox = Email::constructMailboxName($r[0]); $password = ''; openssl_private_decrypt(hex2bin($r[0]['pass']), $password, $x[0]['prvkey']); - $mbox = Email::emailConnect($mailbox, $r[0]['user'], $password); + $mbox = Email::connect($mailbox, $r[0]['user'], $password); if (!mbox) { return false; } } - $msgs = Email::emailPoll($mbox, $uri); + $msgs = Email::poll($mbox, $uri); logger('searching '.$uri.', '.count($msgs).' messages found.', LOGGER_DEBUG); if (!count($msgs)) { @@ -1546,7 +1546,7 @@ class Probe $data["notify"] = 'smtp '.random_string(); $data["poll"] = 'email '.random_string(); - $x = Email::emailMsgMeta($mbox, $msgs[0]); + $x = Email::messageMeta($mbox, $msgs[0]); if (stristr($x[0]->from, $uri)) { $adr = imap_rfc822_parse_adrlist($x[0]->from, ''); } elseif (stristr($x[0]->to, $uri)) { diff --git a/src/Protocol/Email.php b/src/Protocol/Email.php index ceca79cb8..c962de725 100644 --- a/src/Protocol/Email.php +++ b/src/Protocol/Email.php @@ -19,7 +19,7 @@ class Email * @param string $password The password * @return object */ - public static function emailConnect($mailbox, $username, $password) + public static function connect($mailbox, $username, $password) { if (! function_exists('imap_open')) { return false; @@ -35,7 +35,7 @@ class Email * @param string $email_addr email * @return array */ - public static function emailPoll($mbox, $email_addr) + public static function poll($mbox, $email_addr) { if (! ($mbox && $email_addr)) return array(); @@ -83,44 +83,19 @@ class Email * @param integer $uid user id * @return mixed */ - public static function emailMsgMeta($mbox, $uid) + public static function messageMeta($mbox, $uid) { $ret = (($mbox && $uid) ? @imap_fetch_overview($mbox, $uid, FT_UID) : array(array())); // POSSIBLE CLEANUP --> array(array()) is probably redundant now return (count($ret)) ? $ret : array(); } - /** - * @brief Check addons, not called from main friendica project - * I don't see it in addons either - */ - function email_msg_headers($mbox, $uid) { - $raw_header = (($mbox && $uid) ? @imap_fetchheader($mbox,$uid,FT_UID) : ''); - $raw_header = str_replace("\r",'',$raw_header); - $ret = array(); - $h = explode("\n",$raw_header); - if (count($h)) - foreach ($h as $line ) { - if (preg_match("/^[a-zA-Z]/", $line)) { - $key = substr($line,0,strpos($line,':')); - $value = substr($line,strpos($line,':')+1); - - $last_entry = strtolower($key); - $ret[$last_entry] = trim($value); - } - else { - $ret[$last_entry] .= ' ' . trim($line); - } - } - return $ret; - } - /** * @param object $mbox mailbox * @param integer $uid user id * @param string $reply reply * @return array */ - public static function emailGetMsg($mbox, $uid, $reply) + public static function getMessage($mbox, $uid, $reply) { $ret = array(); @@ -131,11 +106,11 @@ class Email } if (! $struc->parts) { - $ret['body'] = self::emailGetPart($mbox, $uid, $struc, 0, 'html'); + $ret['body'] = self::messageGetPart($mbox, $uid, $struc, 0, 'html'); $html = $ret['body']; if (trim($ret['body']) == '') { - $ret['body'] = self::emailGetPart($mbox, $uid, $struc, 0, 'plain'); + $ret['body'] = self::messageGetPart($mbox, $uid, $struc, 0, 'plain'); } else { $ret['body'] = html2bbcode($ret['body']); } @@ -143,12 +118,12 @@ class Email $text = ''; $html = ''; foreach ($struc->parts as $ptop => $p) { - $x = self::emailGetPart($mbox, $uid, $p, $ptop + 1, 'plain'); + $x = self::messageGetPart($mbox, $uid, $p, $ptop + 1, 'plain'); if ($x) { $text .= $x; } - $x = self::emailGetPart($mbox, $uid, $p, $ptop + 1, 'html'); + $x = self::messageGetPart($mbox, $uid, $p, $ptop + 1, 'html'); if ($x) { $html .= $x; } @@ -184,7 +159,7 @@ class Email * @param string $subtype sub type * @return string */ - private static function emailGetPart($mbox, $uid, $p, $partno, $subtype) + private static function messageGetPart($mbox, $uid, $p, $partno, $subtype) { // $partno = '1', '2', '2.1', '2.1.3', etc for multipart, 0 if simple global $htmlmsg,$plainmsg,$charset,$attachments; @@ -257,7 +232,7 @@ class Email if (isset($p->parts) && $p->parts) { $x = ""; foreach ($p->parts as $partno0 => $p2) { - $x .= self::emailGetPart($mbox, $uid, $p2, $partno . '.' . ($partno0+1), $subtype); // 1.2, 1.2.1, etc. + $x .= self::messageGetPart($mbox, $uid, $p2, $partno . '.' . ($partno0+1), $subtype); // 1.2, 1.2.1, etc. //if ($x) { // return $x; //} @@ -271,7 +246,7 @@ class Email * @param string $charset character set * @return string */ - public static function emailHeaderEncode($in_str, $charset) + public static function encodeHeader($in_str, $charset) { $out_str = $in_str; $need_to_convert = false; @@ -324,7 +299,7 @@ class Email } /** - * Function emailSend is used by NETWORK_EMAIL and NETWORK_EMAIL2 code + * Function send is used by NETWORK_EMAIL and NETWORK_EMAIL2 code * (not to notify the user, but to send items to email contacts) * * @param string $addr address @@ -336,7 +311,7 @@ class Email * * @todo This could be changed to use the Emailer class */ - public static function emailSend($addr, $subject, $headers, $item) + public static function send($addr, $subject, $headers, $item) { //$headers .= 'MIME-Version: 1.0' . "\n"; //$headers .= 'Content-Type: text/html; charset=UTF-8' . "\n"; diff --git a/src/Util/Emailer.php b/src/Util/Emailer.php index ec3720400..7d4205ac3 100644 --- a/src/Util/Emailer.php +++ b/src/Util/Emailer.php @@ -37,8 +37,8 @@ class Emailer $email_textonly = PConfig::get($params['uid'], "system", "email_textonly"); } - $fromName = Email::emailHeaderEncode(html_entity_decode($params['fromName'], ENT_QUOTES, 'UTF-8'), 'UTF-8'); - $messageSubject = Email::emailHeaderEncode(html_entity_decode($params['messageSubject'], ENT_QUOTES, 'UTF-8'), 'UTF-8'); + $fromName = Email::encodeHeader(html_entity_decode($params['fromName'], ENT_QUOTES, 'UTF-8'), 'UTF-8'); + $messageSubject = Email::encodeHeader(html_entity_decode($params['messageSubject'], ENT_QUOTES, 'UTF-8'), 'UTF-8'); // generate a mime boundary $mimeBoundary =rand(0, 9)."-" diff --git a/src/Worker/Delivery.php b/src/Worker/Delivery.php index 7d800f54f..f17aa5507 100644 --- a/src/Worker/Delivery.php +++ b/src/Worker/Delivery.php @@ -418,19 +418,19 @@ class Delivery { if ($r1 && $r1[0]['reply_to']) $reply_to = $r1[0]['reply_to']; - $subject = (($it['title']) ? Email::emailHeaderEncode($it['title'],'UTF-8') : t("\x28no subject\x29")) ; + $subject = (($it['title']) ? Email::encodeHeader($it['title'],'UTF-8') : t("\x28no subject\x29")) ; // only expose our real email address to true friends if (($contact['rel'] == CONTACT_IS_FRIEND) && !$contact['blocked']) { if ($reply_to) { - $headers = 'From: '.Email::emailHeaderEncode($local_user[0]['username'],'UTF-8').' <'.$reply_to.'>'."\n"; + $headers = 'From: '.Email::encodeHeader($local_user[0]['username'],'UTF-8').' <'.$reply_to.'>'."\n"; $headers .= 'Sender: '.$local_user[0]['email']."\n"; } else { - $headers = 'From: '.Email::emailHeaderEncode($local_user[0]['username'],'UTF-8').' <'.$local_user[0]['email'].'>'."\n"; + $headers = 'From: '.Email::encodeHeader($local_user[0]['username'],'UTF-8').' <'.$local_user[0]['email'].'>'."\n"; } } else { - $headers = 'From: '. Email::emailHeaderEncode($local_user[0]['username'],'UTF-8') .' <'. t('noreply') .'@'.$a->get_hostname() .'>'. "\n"; + $headers = 'From: '. Email::encodeHeader($local_user[0]['username'],'UTF-8') .' <'. t('noreply') .'@'.$a->get_hostname() .'>'. "\n"; } //if ($reply_to) @@ -469,7 +469,7 @@ class Delivery { if (strncasecmp($subject,'RE:',3)) $subject = 'Re: '.$subject; } - Email::emailSend($addr, $subject, $headers, $it); + Email::send($addr, $subject, $headers, $it); } break; diff --git a/src/Worker/OnePoll.php b/src/Worker/OnePoll.php index 3f00454b2..f7f7bcccf 100644 --- a/src/Worker/OnePoll.php +++ b/src/Worker/OnePoll.php @@ -331,7 +331,7 @@ Class OnePoll $mailbox = Email::constructMailboxName($mailconf); $password = ''; openssl_private_decrypt(hex2bin($mailconf['pass']), $password, $x['prvkey']); - $mbox = Email::emailConnect($mailbox, $mailconf['user'], $password); + $mbox = Email::connect($mailbox, $mailconf['user'], $password); unset($password); logger("Mail: Connect to " . $mailconf['user']); if ($mbox) { @@ -344,12 +344,12 @@ Class OnePoll } if ($mbox) { - $msgs = Email::emailPoll($mbox, $contact['addr']); + $msgs = Email::poll($mbox, $contact['addr']); if (count($msgs)) { logger("Mail: Parsing ".count($msgs)." mails from ".$contact['addr']." for ".$mailconf['user'], LOGGER_DEBUG); - $metas = Email::emailMsgMeta($mbox,implode(',', $msgs)); + $metas = Email::messageMeta($mbox, implode(',', $msgs)); if (count($metas) != count($msgs)) { logger("onepoll: for " . $mailconf['user'] . " there are ". count($msgs) . " messages but received " . count($metas) . " metas", LOGGER_DEBUG); } else { @@ -361,8 +361,7 @@ Class OnePoll $datarray = array(); $datarray['verb'] = ACTIVITY_POST; $datarray['object-type'] = ACTIVITY_OBJ_NOTE; - // $meta = Email::emailMsgMeta($mbox, $msg_uid); - // $headers = email_msg_headers($mbox, $msg_uid); + // $meta = Email::messageMeta($mbox, $msg_uid); $datarray['uri'] = Email::msgid2iri(trim($meta->message_id, '<>')); @@ -466,7 +465,7 @@ Class OnePoll $datarray['parent-uri'] = $datarray['uri']; } - $r = Email::emailGetMsg($mbox, $msg_uid, $reply); + $r = Email::getMessage($mbox, $msg_uid, $reply); if (!$r) { logger("Mail: can't fetch msg ".$msg_uid." for ".$mailconf['user']); continue; From 8826ece55e50c68596bb25062dd31fb643d2163a Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 1 Dec 2017 22:32:24 -0500 Subject: [PATCH 11/71] Use Contact::getIdForURL instead of probing - Add change to mod/admin - Add change to util/global_community_block --- mod/admin.php | 15 ++++------- util/global_community_block.php | 44 +++++++++++++-------------------- 2 files changed, 22 insertions(+), 37 deletions(-) diff --git a/mod/admin.php b/mod/admin.php index 83ef15f4a..1bcbb45e7 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -381,17 +381,12 @@ function admin_page_contactblock_post(App $a) check_form_security_token_redirectOnErr('/admin/contactblock', 'admin_contactblock'); if (x($_POST, 'page_contactblock_block')) { - $net = Probe::uri($contact_url); - if (in_array($net['network'], array(NETWORK_PHANTOM, NETWORK_MAIL))) { - notice(t('This contact doesn\'t seem to exist.')); - } - $nurl = normalise_link($net['url']); - $r = dba::select('contact', ['id'], ['nurl' => $nurl, 'uid' => 0], ['limit' => 1]); - if (DBM::is_result($r)) { - Contact::block($r['id']); + $contact_id = Contact::getIdForURL($contact_url, 0); + if ($contact_id) { + Contact::block($contact_id); notice(t('The contact has been blocked from the node')); } else { - notice(t('Could not find any contact entry for this URL (%s)', $nurl)); + notice(t('Could not find any contact entry for this URL (%s)', $contact_url)); } } if (x($_POST, 'page_contactblock_unblock')) { @@ -428,7 +423,7 @@ function admin_page_contactblock(App $a) // strings // '$title' => t('Administration'), '$page' => t('Remote Contact Blocklist'), - '$description' => t('This page allows you to prevent any message from a remote contact to reach your node. However, your node must have knowledge of the contact before you can block it.'), + '$description' => t('This page allows you to prevent any message from a remote contact to reach your node.'), '$submit' => t('Block Remote Contact'), '$select_all' => t('select all'), '$select_none' => t('select none'), diff --git a/util/global_community_block.php b/util/global_community_block.php index cb6789e45..db68fdb4b 100755 --- a/util/global_community_block.php +++ b/util/global_community_block.php @@ -1,6 +1,5 @@ #!/usr/bin/env php ".$argv[0]." https://example.com/profiles/bob\r\n"; + echo "$> " . $argv[0] . " https://example.com/profiles/bob\r\n"; echo "\r\n"; exit(0); } -use Friendica\Database\DBM; -use Friendica\Network\Probe; +use Friendica\BaseObject; +use Friendica\Object\Contact; require_once 'boot.php'; + +$a = get_app();; +BaseObject::setApp($a); + +require_once '.htconfig.php'; require_once 'include/dba.php'; require_once 'include/text.php'; -$a = get_app(); -require_once '.htconfig.php'; dba::connect($db_host, $db_user, $db_pass, $db_data); unset($db_host, $db_user, $db_pass, $db_data); -/** - * 1. make nurl from last parameter - * 2. check DB (contact) if there is a contact with uid=0 and that nurl, get the ID - * 3. set the flag hidden=1 for the contact entry with the found ID - **/ -$net = Probe::uri($argv[1]); -if (in_array($net['network'], array(NETWORK_PHANTOM, NETWORK_MAIL))) { - echo 'This account seems not to exist.'; +$contact_id = Contact::getIdForURL($argv[1], 0); +if (!$contact_id) { + echo t('Could not find any contact entry for this URL (%s)', $nurl); echo "\r\n"; exit(1); } -$nurl = normalise_link($net['url']); -$r = dba::select('contact', array('id'), array('nurl' => $nurl, 'uid' => 0), array('limit' => 1)); -if (DBM::is_result($r)) { - dba::update('contact', array('blocked' => true), array('id' => $r['id'])); - echo "NOTICE: The account should be blocked from the node now\r\n"; -} else { - echo "NOTICE: Could not find any entry for this URL (".$nurl.")\r\n"; -} - -?> +Contact::block($contact_id); +echo t('The contact has been blocked from the node'); +echo "\r\n"; +exit(0); From 75181322baabc7b99ca0c919131a266d6987aa6d Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 1 Dec 2017 22:33:04 -0500 Subject: [PATCH 12/71] Improve page contacblock for frio theme --- mod/admin.php | 1 + view/templates/admin/contactblock.tpl | 1 - view/theme/frio/js/mod_admin.js | 31 +++++++++++++++++++ .../frio/templates/admin/contactblock.tpl | 27 +++++++--------- 4 files changed, 44 insertions(+), 16 deletions(-) create mode 100644 view/theme/frio/js/mod_admin.js diff --git a/mod/admin.php b/mod/admin.php index 1bcbb45e7..fcd67aa9e 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -441,6 +441,7 @@ function admin_page_contactblock(App $a) '$baseurl' => System::baseUrl(true), '$contacts' => $contacts, + '$total_contacts' => tt('%s total blocked contact', '%s total blocked contacts', $total), '$paginate' => paginate($a), '$contacturl' => ['contact_url', t("Profile URL"), '', t("URL of the remote contact to block.")], )); diff --git a/view/templates/admin/contactblock.tpl b/view/templates/admin/contactblock.tpl index dcd33e879..152550f01 100644 --- a/view/templates/admin/contactblock.tpl +++ b/view/templates/admin/contactblock.tpl @@ -1,4 +1,3 @@ - +

{{$title}} - {{$page}}

{{$description}}

@@ -20,7 +10,7 @@ - + {{foreach $th_contacts as $th}} {{/foreach}} + + + + + +
{{$th}} @@ -39,10 +29,17 @@
+ {{$total_contacts}} +
-

{{$select_all}} | {{$select_none}}

+
{{$paginate}} -
{{else}}

{{$no_data|escape:'html'}}

{{/if}} @@ -58,6 +55,6 @@ -
+
From 4d10f3b3b7223627e9f623d89415a70680560b55 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 2 Dec 2017 08:42:44 -0500 Subject: [PATCH 13/71] Remove unused use statement --- mod/admin.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/mod/admin.php b/mod/admin.php index fcd67aa9e..1e7d90436 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -11,7 +11,6 @@ use Friendica\Core\Config; use Friendica\Core\Worker; use Friendica\Database\DBM; use Friendica\Model\User; -use Friendica\Network\Probe; use Friendica\Object\Contact; require_once 'include/enotify.php'; @@ -33,8 +32,6 @@ require_once 'include/items.php'; */ function admin_post(App $a) { - - if (!is_site_admin()) { return; } From 7bd0ab8360c672638d6a347ff35e4d21a25378fa Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 2 Dec 2017 08:43:13 -0500 Subject: [PATCH 14/71] Move includes around in global_community_block --- util/global_community_block.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/util/global_community_block.php b/util/global_community_block.php index db68fdb4b..ab586b651 100755 --- a/util/global_community_block.php +++ b/util/global_community_block.php @@ -32,14 +32,13 @@ use Friendica\BaseObject; use Friendica\Object\Contact; require_once 'boot.php'; +require_once 'include/dba.php'; +require_once 'include/text.php'; $a = get_app();; BaseObject::setApp($a); require_once '.htconfig.php'; -require_once 'include/dba.php'; -require_once 'include/text.php'; - dba::connect($db_host, $db_user, $db_pass, $db_data); unset($db_host, $db_user, $db_pass, $db_data); From 2b121779a6c782ce0f50b4ef9b7baca82f740a4a Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Sat, 2 Dec 2017 09:32:45 -0500 Subject: [PATCH 15/71] Salmon move to src Salmon class, update function name and function calls. Some standards as well. --- include/crypto.php | 10 +- include/follow.php | 4 +- include/items.php | 1 - include/salmon.php | 185 ------------------------------------ mod/post.php | 39 ++++---- mod/receive.php | 17 ++-- mod/salmon.php | 4 +- src/Object/Contact.php | 4 +- src/Protocol/Salmon.php | 204 ++++++++++++++++++++++++++++++++++++++++ src/Worker/Notifier.php | 6 +- src/Worker/Queue.php | 6 +- 11 files changed, 250 insertions(+), 230 deletions(-) delete mode 100644 include/salmon.php create mode 100644 src/Protocol/Salmon.php diff --git a/include/crypto.php b/include/crypto.php index 703439baa..dfc44c179 100644 --- a/include/crypto.php +++ b/include/crypto.php @@ -91,9 +91,9 @@ function metopem($m, $e) { return $key; } -function pubrsatome($key,&$m,&$e) { - require_once('library/asn1.php'); - require_once('include/salmon.php'); +function pubrsatome($key, &$m, &$e) +{ + require_once 'library/asn1.php'; $lines = explode("\n", $key); unset($lines[0]); @@ -117,8 +117,8 @@ function pemtorsa($key) { return metorsa($m, $e); } -function pemtome($key, &$m, &$e) { - require_once('include/salmon.php'); +function pemtome($key, &$m, &$e) +{ $lines = explode("\n", $key); unset($lines[0]); unset($lines[count($lines)]); diff --git a/include/follow.php b/include/follow.php index ac07c4085..14b9c68ed 100644 --- a/include/follow.php +++ b/include/follow.php @@ -12,9 +12,9 @@ use Friendica\Object\Contact; use Friendica\Protocol\Diaspora; use Friendica\Protocol\OStatus; use Friendica\Protocol\PortableContact; +use Friendica\Protocol\Salmon; require_once 'include/group.php'; -require_once 'include/salmon.php'; function update_contact($id) { /* @@ -268,7 +268,7 @@ function new_contact($uid, $url, $interactive = false, $network = '') { $item['verb'] = ACTIVITY_FOLLOW; $item['follow'] = $contact["url"]; $slap = OStatus::salmon($item, $r[0]); - slapper($r[0], $contact['notify'], $slap); + Salmon::slapper($r[0], $contact['notify'], $slap); } if ($contact['network'] == NETWORK_DIASPORA) { diff --git a/include/items.php b/include/items.php index 7cbcfaaaf..36a7ac2a8 100644 --- a/include/items.php +++ b/include/items.php @@ -17,7 +17,6 @@ use Friendica\Util\Lock; require_once 'include/bbcode.php'; require_once 'include/oembed.php'; -require_once 'include/salmon.php'; require_once 'include/crypto.php'; require_once 'include/tags.php'; require_once 'include/files.php'; diff --git a/include/salmon.php b/include/salmon.php deleted file mode 100644 index 264b92e80..000000000 --- a/include/salmon.php +++ /dev/null @@ -1,185 +0,0 @@ - 0) { - for ($x = 0; $x < count($ret); $x ++) { - if (substr($ret[$x], 0, 5) === 'data:') { - if (strstr($ret[$x], ',')) { - $ret[$x] = substr($ret[$x], strpos($ret[$x], ',') + 1); - } else { - $ret[$x] = substr($ret[$x], 5); - } - } elseif (normalise_link($ret[$x]) == 'http://') { - $ret[$x] = fetch_url($ret[$x]); - } - } - } - - - logger('Key located: ' . print_r($ret, true)); - - if (count($ret) == 1) { - // We only found one one key so we don't care if the hash matches. - // If it's the wrong key we'll find out soon enough because - // message verification will fail. This also covers some older - // software which don't supply a keyhash. As long as they only - // have one key we'll be right. - - return $ret[0]; - } else { - foreach ($ret as $a) { - $hash = base64url_encode(hash('sha256', $a)); - if ($hash == $keyhash) { - return $a; - } - } - } - - return ''; -} - - - -function slapper($owner, $url, $slap) -{ - // does contact have a salmon endpoint? - - if (! strlen($url)) { - return; - } - - if (! $owner['sprvkey']) { - logger(sprintf("user '%s' (%d) does not have a salmon private key. Send failed.", - $owner['username'], $owner['uid'])); - return; - } - - logger('slapper called for '.$url.'. Data: ' . $slap); - - // create a magic envelope - - $data = base64url_encode($slap); - $data_type = 'application/atom+xml'; - $encoding = 'base64url'; - $algorithm = 'RSA-SHA256'; - $keyhash = base64url_encode(hash('sha256', salmon_key($owner['spubkey'])), true); - - $precomputed = '.' . base64url_encode($data_type) . '.' . base64url_encode($encoding) . '.' . base64url_encode($algorithm); - - // GNU Social format - $signature = base64url_encode(rsa_sign($data . $precomputed, $owner['sprvkey'])); - - // Compliant format - $signature2 = base64url_encode(rsa_sign(str_replace('=', '', $data . $precomputed), $owner['sprvkey'])); - - // Old Status.net format - $signature3 = base64url_encode(rsa_sign($data, $owner['sprvkey'])); - - // At first try the non compliant method that works for GNU Social - $xmldata = array("me:env" => array("me:data" => $data, - "@attributes" => array("type" => $data_type), - "me:encoding" => $encoding, - "me:alg" => $algorithm, - "me:sig" => $signature, - "@attributes2" => array("key_id" => $keyhash))); - - $namespaces = array("me" => "http://salmon-protocol.org/ns/magic-env"); - - $salmon = XML::fromArray($xmldata, $xml, false, $namespaces); - - // slap them - post_url($url, $salmon, array( - 'Content-type: application/magic-envelope+xml', - 'Content-length: ' . strlen($salmon) - )); - - $a = get_app(); - $return_code = $a->get_curl_code(); - - // check for success, e.g. 2xx - - if ($return_code > 299) { - logger('GNU Social salmon failed. Falling back to compliant mode'); - - // Now try the compliant mode that normally isn't used for GNU Social - $xmldata = array("me:env" => array("me:data" => $data, - "@attributes" => array("type" => $data_type), - "me:encoding" => $encoding, - "me:alg" => $algorithm, - "me:sig" => $signature2, - "@attributes2" => array("key_id" => $keyhash))); - - $namespaces = array("me" => "http://salmon-protocol.org/ns/magic-env"); - - $salmon = XML::fromArray($xmldata, $xml, false, $namespaces); - - // slap them - post_url($url, $salmon, array( - 'Content-type: application/magic-envelope+xml', - 'Content-length: ' . strlen($salmon) - )); - $return_code = $a->get_curl_code(); - } - - if ($return_code > 299) { - logger('compliant salmon failed. Falling back to old status.net'); - - // Last try. This will most likely fail as well. - $xmldata = array("me:env" => array("me:data" => $data, - "@attributes" => array("type" => $data_type), - "me:encoding" => $encoding, - "me:alg" => $algorithm, - "me:sig" => $signature3, - "@attributes2" => array("key_id" => $keyhash))); - - $namespaces = array("me" => "http://salmon-protocol.org/ns/magic-env"); - - $salmon = XML::fromArray($xmldata, $xml, false, $namespaces); - - // slap them - post_url($url, $salmon, array( - 'Content-type: application/magic-envelope+xml', - 'Content-length: ' . strlen($salmon)) - ); - $return_code = $a->get_curl_code(); - } - - logger('slapper for '.$url.' returned ' . $return_code); - - if (! $return_code) { - return -1; - } - - if (($return_code == 503) && (stristr($a->get_curl_headers(), 'retry-after'))) { - return -1; - } - - return ((($return_code >= 200) && ($return_code < 300)) ? 0 : 1); -} diff --git a/mod/post.php b/mod/post.php index 8e279644b..58d7695d4 100644 --- a/mod/post.php +++ b/mod/post.php @@ -1,54 +1,55 @@ argc == 1) { $bulk_delivery = true; - } - else { + } else { $nickname = $a->argv[2]; - $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' - AND `account_expired` = 0 AND `account_removed` = 0 LIMIT 1", - dbesc($nickname) - ); + $r = dba::select('user', array(), array('nickname' => $nickname, 'account_expired' => 0, 'account_removed' => 0), array('limit' => 1)); if (! DBM::is_result($r)) { http_status_exit(500); } - $importer = $r[0]; + $importer = $r; } $xml = file_get_contents('php://input'); logger('mod-post: new zot: ' . $xml, LOGGER_DATA); - if(! $xml) + if (! $xml) { http_status_exit(500); + } - $msg = zot_decode($importer,$xml); + $msg = zot_decode($importer, $xml); - logger('mod-post: decoded msg: ' . print_r($msg,true), LOGGER_DATA); + logger('mod-post: decoded msg: ' . print_r($msg, true), LOGGER_DATA); - if(! is_array($msg)) + if (! is_array($msg)) { http_status_exit(500); + } $ret = 0; - $ret = zot_incoming($bulk_delivery, $importer,$msg); + $ret = zot_incoming($bulk_delivery, $importer, $msg); http_status_exit(($ret) ? $ret : 200); // NOTREACHED } - diff --git a/mod/receive.php b/mod/receive.php index 8241325bf..467a0d00a 100644 --- a/mod/receive.php +++ b/mod/receive.php @@ -1,7 +1,7 @@ 0) { + for ($x = 0; $x < count($ret); $x ++) { + if (substr($ret[$x], 0, 5) === 'data:') { + if (strstr($ret[$x], ',')) { + $ret[$x] = substr($ret[$x], strpos($ret[$x], ',') + 1); + } else { + $ret[$x] = substr($ret[$x], 5); + } + } elseif (normalise_link($ret[$x]) == 'http://') { + $ret[$x] = fetch_url($ret[$x]); + } + } + } + + + logger('Key located: ' . print_r($ret, true)); + + if (count($ret) == 1) { + // We only found one one key so we don't care if the hash matches. + // If it's the wrong key we'll find out soon enough because + // message verification will fail. This also covers some older + // software which don't supply a keyhash. As long as they only + // have one key we'll be right. + + return $ret[0]; + } else { + foreach ($ret as $a) { + $hash = base64url_encode(hash('sha256', $a)); + if ($hash == $keyhash) { + return $a; + } + } + } + + return ''; + } + + /** + * @param array $owner owner + * @param string $url url + * @param string $slap slap + * @return integer + */ + public static function slapper($owner, $url, $slap) + { + // does contact have a salmon endpoint? + + if (! strlen($url)) { + return; + } + + if (! $owner['sprvkey']) { + logger(sprintf("user '%s' (%d) does not have a salmon private key. Send failed.", + $owner['username'], $owner['uid'])); + return; + } + + logger('slapper called for '.$url.'. Data: ' . $slap); + + // create a magic envelope + + $data = base64url_encode($slap); + $data_type = 'application/atom+xml'; + $encoding = 'base64url'; + $algorithm = 'RSA-SHA256'; + $keyhash = base64url_encode(hash('sha256', salmon_key($owner['spubkey'])), true); + + $precomputed = '.' . base64url_encode($data_type) . '.' . base64url_encode($encoding) . '.' . base64url_encode($algorithm); + + // GNU Social format + $signature = base64url_encode(rsa_sign($data . $precomputed, $owner['sprvkey'])); + + // Compliant format + $signature2 = base64url_encode(rsa_sign(str_replace('=', '', $data . $precomputed), $owner['sprvkey'])); + + // Old Status.net format + $signature3 = base64url_encode(rsa_sign($data, $owner['sprvkey'])); + + // At first try the non compliant method that works for GNU Social + $xmldata = array("me:env" => array("me:data" => $data, + "@attributes" => array("type" => $data_type), + "me:encoding" => $encoding, + "me:alg" => $algorithm, + "me:sig" => $signature, + "@attributes2" => array("key_id" => $keyhash))); + + $namespaces = array("me" => "http://salmon-protocol.org/ns/magic-env"); + + $salmon = XML::fromArray($xmldata, $xml, false, $namespaces); + + // slap them + post_url($url, $salmon, array( + 'Content-type: application/magic-envelope+xml', + 'Content-length: ' . strlen($salmon) + )); + + $a = get_app(); + $return_code = $a->get_curl_code(); + + // check for success, e.g. 2xx + + if ($return_code > 299) { + logger('GNU Social salmon failed. Falling back to compliant mode'); + + // Now try the compliant mode that normally isn't used for GNU Social + $xmldata = array("me:env" => array("me:data" => $data, + "@attributes" => array("type" => $data_type), + "me:encoding" => $encoding, + "me:alg" => $algorithm, + "me:sig" => $signature2, + "@attributes2" => array("key_id" => $keyhash))); + + $namespaces = array("me" => "http://salmon-protocol.org/ns/magic-env"); + + $salmon = XML::fromArray($xmldata, $xml, false, $namespaces); + + // slap them + post_url($url, $salmon, array( + 'Content-type: application/magic-envelope+xml', + 'Content-length: ' . strlen($salmon) + )); + $return_code = $a->get_curl_code(); + } + + if ($return_code > 299) { + logger('compliant salmon failed. Falling back to old status.net'); + + // Last try. This will most likely fail as well. + $xmldata = array("me:env" => array("me:data" => $data, + "@attributes" => array("type" => $data_type), + "me:encoding" => $encoding, + "me:alg" => $algorithm, + "me:sig" => $signature3, + "@attributes2" => array("key_id" => $keyhash))); + + $namespaces = array("me" => "http://salmon-protocol.org/ns/magic-env"); + + $salmon = XML::fromArray($xmldata, $xml, false, $namespaces); + + // slap them + post_url($url, $salmon, array( + 'Content-type: application/magic-envelope+xml', + 'Content-length: ' . strlen($salmon)) + ); + $return_code = $a->get_curl_code(); + } + + logger('slapper for '.$url.' returned ' . $return_code); + + if (! $return_code) { + return -1; + } + + if (($return_code == 503) && (stristr($a->get_curl_headers(), 'retry-after'))) { + return -1; + } + + return (($return_code >= 200) && ($return_code < 300)) ? 0 : 1; + } +} diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index e64351f17..4404b879b 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -11,11 +11,11 @@ use Friendica\Network\Probe; use Friendica\Object\Contact; use Friendica\Protocol\Diaspora; use Friendica\Protocol\OStatus; +use Friendica\Protocol\Salmon; use dba; require_once 'include/queue_fn.php'; require_once 'include/html2plain.php'; -require_once 'include/salmon.php'; require_once 'include/datetime.php'; require_once 'include/items.php'; require_once 'include/bbcode.php'; @@ -505,11 +505,11 @@ class Notifier { // They are especially used for notifications to OStatus users that don't follow us. if ($slap && count($url_recipients) && ($public_message || $push_notify) && $normal_mode) { - if (!Config::get('system','dfrn_only')) { + if (!Config::get('system', 'dfrn_only')) { foreach ($url_recipients as $url) { if ($url) { logger('notifier: urldelivery: ' . $url); - $deliver_status = slapper($owner,$url,$slap); + $deliver_status = Salmon::slapper($owner, $url, $slap); /// @TODO Redeliver/queue these items on failure, though there is no contact record } } diff --git a/src/Worker/Queue.php b/src/Worker/Queue.php index 47f1c8044..cb00addc9 100644 --- a/src/Worker/Queue.php +++ b/src/Worker/Queue.php @@ -1,9 +1,7 @@ '); - $deliver_status = slapper($owner, $contact['notify'], $data); + $deliver_status = Salmon::slapper($owner, $contact['notify'], $data); if ($deliver_status == (-1)) { update_queue_time($q_item['id']); From adf802474b4e544d486fc71eb76276750526d5c4 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 2 Dec 2017 21:57:39 +0000 Subject: [PATCH 16/71] Zot was never really supported, so it is now removed completely --- include/acl_selectors.php | 6 ++--- include/items.php | 4 +-- include/uimport.php | 3 --- mod/hostxrd.php | 4 --- mod/post.php | 55 --------------------------------------- mod/xrd.php | 1 - src/Worker/Cron.php | 7 +++-- update.php | 3 --- 8 files changed, 7 insertions(+), 76 deletions(-) delete mode 100644 mod/post.php diff --git a/include/acl_selectors.php b/include/acl_selectors.php index ef75d416f..5ae30d563 100644 --- a/include/acl_selectors.php +++ b/include/acl_selectors.php @@ -498,10 +498,9 @@ function acl_lookup(App $a, $out_type = 'json') { WHERE `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND `success_update` >= `failure_update` - AND `network` IN ('%s','%s','%s') $sql_extra2" , + AND `network` IN ('%s', '%s') $sql_extra2" , intval(local_user()), dbesc(NETWORK_DFRN), - dbesc(NETWORK_ZOT), dbesc(NETWORK_DIASPORA) ); $contact_count = (int)$r[0]['c']; @@ -593,12 +592,11 @@ function acl_lookup(App $a, $out_type = 'json') { } elseif ($type == 'm') { $r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, `addr` FROM `contact` WHERE `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `pending` AND NOT `archive` - AND `success_update` >= `failure_update` AND `network` IN ('%s','%s','%s') + AND `success_update` >= `failure_update` AND `network` IN ('%s', '%s') $sql_extra2 ORDER BY `name` ASC ", intval(local_user()), dbesc(NETWORK_DFRN), - dbesc(NETWORK_ZOT), dbesc(NETWORK_DIASPORA) ); } elseif ($type == 'a') { diff --git a/include/items.php b/include/items.php index 36a7ac2a8..98149dea5 100644 --- a/include/items.php +++ b/include/items.php @@ -1678,8 +1678,8 @@ function new_follower($importer, $contact, $datarray, $item, $sharing = false) { dbesc($name), dbesc($nick), dbesc($photo), - dbesc(($sharing) ? NETWORK_ZOT : NETWORK_OSTATUS), - intval(($sharing) ? CONTACT_IS_SHARING : CONTACT_IS_FOLLOWER) + dbesc(NETWORK_OSTATUS), + intval(CONTACT_IS_FOLLOWER) ); $r = q("SELECT `id`, `network` FROM `contact` WHERE `uid` = %d AND `url` = '%s' AND `pending` = 1 LIMIT 1", intval($importer['uid']), diff --git a/include/uimport.php b/include/uimport.php index 4e30eabe3..301ab4803 100644 --- a/include/uimport.php +++ b/include/uimport.php @@ -198,9 +198,6 @@ function import_account(App $a, $file) { case NETWORK_DIASPORA: // send relocate message (below) break; - case NETWORK_ZOT: - /// @TODO handle zot network - break; case NETWORK_MAIL2: /// @TODO ? break; diff --git a/mod/hostxrd.php b/mod/hostxrd.php index f31497557..0403945ef 100644 --- a/mod/hostxrd.php +++ b/mod/hostxrd.php @@ -18,15 +18,11 @@ function hostxrd_init(App $a) { Config::set('system','site_pubkey', $res['pubkey']); } - //$tpl = file_get_contents('view/xrd_host.tpl'); - /*echo str_replace(array( - '$zhost','$zroot','$domain','$zot_post','$bigkey'),array($a->get_hostname(),System::baseUrl(),System::baseUrl(),System::baseUrl() . '/post', salmon_key(Config::get('system','site_pubkey'))),$tpl);*/ $tpl = get_markup_template('xrd_host.tpl'); echo replace_macros($tpl, array( '$zhost' => $a->get_hostname(), '$zroot' => System::baseUrl(), '$domain' => System::baseUrl(), - '$zot_post' => System::baseUrl() . '/post', '$bigkey' => salmon_key(Config::get('system','site_pubkey')), )); exit(); diff --git a/mod/post.php b/mod/post.php deleted file mode 100644 index 58d7695d4..000000000 --- a/mod/post.php +++ /dev/null @@ -1,55 +0,0 @@ -argc == 1) { - $bulk_delivery = true; - } else { - $nickname = $a->argv[2]; - $r = dba::select('user', array(), array('nickname' => $nickname, 'account_expired' => 0, 'account_removed' => 0), array('limit' => 1)); - if (! DBM::is_result($r)) { - http_status_exit(500); - } - - $importer = $r; - } - - $xml = file_get_contents('php://input'); - - logger('mod-post: new zot: ' . $xml, LOGGER_DATA); - - if (! $xml) { - http_status_exit(500); - } - - $msg = zot_decode($importer, $xml); - - logger('mod-post: decoded msg: ' . print_r($msg, true), LOGGER_DATA); - - if (! is_array($msg)) { - http_status_exit(500); - } - - $ret = 0; - $ret = zot_incoming($bulk_delivery, $importer, $msg); - http_status_exit(($ret) ? $ret : 200); - // NOTREACHED -} diff --git a/mod/xrd.php b/mod/xrd.php index 9f88d85ea..49fdde254 100644 --- a/mod/xrd.php +++ b/mod/xrd.php @@ -94,7 +94,6 @@ function xrd_xml($a, $uri, $alias, $profile_url, $r) { '$profile_url' => $profile_url, '$hcard_url' => System::baseUrl() . '/hcard/' . $r['nickname'], '$atom' => System::baseUrl() . '/dfrn_poll/' . $r['nickname'], - '$zot_post' => System::baseUrl() . '/post/' . $r['nickname'], '$poco_url' => System::baseUrl() . '/poco/' . $r['nickname'], '$photo' => System::baseUrl() . '/photo/profile/' . $r['uid'] . '.jpg', '$baseurl' => System::baseUrl(), diff --git a/src/Worker/Cron.php b/src/Worker/Cron.php index a5ae466ce..354cb3585 100644 --- a/src/Worker/Cron.php +++ b/src/Worker/Cron.php @@ -156,14 +156,13 @@ Class Cron { $contacts = q("SELECT `contact`.`id` FROM `user` STRAIGHT_JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`rel` IN (%d, %d) AND `contact`.`poll` != '' - AND `contact`.`network` IN ('%s', '%s', '%s', '%s', '%s', '%s') $sql_extra + AND `contact`.`network` IN ('%s', '%s', '%s', '%s', '%s') $sql_extra AND NOT `contact`.`self` AND NOT `contact`.`blocked` AND NOT `contact`.`readonly` AND NOT `contact`.`archive` WHERE NOT `user`.`account_expired` AND NOT `user`.`account_removed` $abandon_sql ORDER BY RAND()", intval(CONTACT_IS_SHARING), intval(CONTACT_IS_FRIEND), dbesc(NETWORK_DFRN), - dbesc(NETWORK_ZOT), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_FEED), dbesc(NETWORK_MAIL), @@ -192,11 +191,11 @@ Class Cron { $contact['last-update'] = NULL_DATE; } - if (in_array($contact['network'], array(NETWORK_DFRN, NETWORK_ZOT, NETWORK_OSTATUS))) { + if (in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS))) { $contact['priority'] = 2; } - if ($contact['subhub'] && in_array($contact['network'], array(NETWORK_DFRN, NETWORK_ZOT, NETWORK_OSTATUS))) { + if ($contact['subhub'] && in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS))) { /* * We should be getting everything via a hub. But just to be sure, let's check once a day. * (You can make this more or less frequent if desired by setting 'pushpoll_frequency' appropriately) diff --git a/update.php b/update.php index ba0867d3a..7fbdec707 100644 --- a/update.php +++ b/update.php @@ -1472,9 +1472,6 @@ function update_1164() { $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)", NETWORK_DFRN, NETWORK_DFRN); - $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)", - NETWORK_ZOT, NETWORK_ZOT); - $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)", NETWORK_OSTATUS, NETWORK_OSTATUS); From 2aca406f52707e2f023a98f940e4f3af489058f9 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Sun, 3 Dec 2017 08:27:15 +0100 Subject: [PATCH 17/71] wrong URL in directory --- mod/admin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod/admin.php b/mod/admin.php index 1e7d90436..d73ac23fd 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -1279,7 +1279,7 @@ function admin_page_site(App $a) '$banner' => array('banner', t("Banner/Logo"), $banner, ""), '$shortcut_icon' => array('shortcut_icon', t("Shortcut icon"), Config::get('system','shortcut_icon'), t("Link to an icon that will be used for browsers.")), '$touch_icon' => array('touch_icon', t("Touch icon"), Config::get('system','touch_icon'), t("Link to an icon that will be used for tablets and mobiles.")), - '$info' => array('info', t('Additional Info'), $info, sprintf(t('For public servers: you can add additional information here that will be listed at %s/siteinfo.'), get_server())), + '$info' => array('info', t('Additional Info'), $info, sprintf(t('For public servers: you can add additional information here that will be listed at %s/servers.'), get_server())), '$language' => array('language', t("System language"), Config::get('system','language'), "", $lang_choices), '$theme' => array('theme', t("System theme"), Config::get('system','theme'), t("Default system theme - may be over-ridden by user profiles - change theme settings"), $theme_choices), '$theme_mobile' => array('theme_mobile', t("Mobile system theme"), Config::get('system', 'mobile-theme', '---'), t("Theme for mobile devices"), $theme_choices_mobile), From cd55c742e8252c91e01520ebecdc1d9fcfe18be3 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 3 Dec 2017 08:59:24 +0000 Subject: [PATCH 18/71] Check Diaspora contacts, don't poll unreachable contacts too often --- src/Worker/Cron.php | 164 +++++++++++++++++++---------------------- src/Worker/OnePoll.php | 55 +++++++++++--- 2 files changed, 123 insertions(+), 96 deletions(-) diff --git a/src/Worker/Cron.php b/src/Worker/Cron.php index 354cb3585..1a7a5784d 100644 --- a/src/Worker/Cron.php +++ b/src/Worker/Cron.php @@ -153,17 +153,20 @@ Class Cron { : '' ); - $contacts = q("SELECT `contact`.`id` FROM `user` + $contacts = q("SELECT `contact`.`id`, `contact`.`nick`, `contact`.`name`, `contact`.`network`, + `contact`.`last-update`, `contact`.`priority`, `contact`.`subhub` + FROM `user` STRAIGHT_JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`rel` IN (%d, %d) AND `contact`.`poll` != '' - AND `contact`.`network` IN ('%s', '%s', '%s', '%s', '%s') $sql_extra + AND `contact`.`network` IN ('%s', '%s', '%s', '%s', '%s', '%s') $sql_extra AND NOT `contact`.`self` AND NOT `contact`.`blocked` AND NOT `contact`.`readonly` AND NOT `contact`.`archive` - WHERE NOT `user`.`account_expired` AND NOT `user`.`account_removed` $abandon_sql ORDER BY RAND()", + WHERE NOT `user`.`account_expired` AND NOT `user`.`account_removed` $abandon_sql", intval(CONTACT_IS_SHARING), intval(CONTACT_IS_FRIEND), dbesc(NETWORK_DFRN), dbesc(NETWORK_OSTATUS), + dbesc(NETWORK_DIASPORA), dbesc(NETWORK_FEED), dbesc(NETWORK_MAIL), dbesc(NETWORK_MAIL2) @@ -173,94 +176,81 @@ Class Cron { return; } - foreach ($contacts as $c) { + foreach ($contacts as $contact) { - $res = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1", - intval($c['id']) - ); - - if (!DBM::is_result($res)) { - continue; + if ($manual_id) { + $contact['last-update'] = NULL_DATE; } - foreach ($res as $contact) { - - $xml = false; - - if ($manual_id) { - $contact['last-update'] = NULL_DATE; - } - - if (in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS))) { - $contact['priority'] = 2; - } - - if ($contact['subhub'] && in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS))) { - /* - * We should be getting everything via a hub. But just to be sure, let's check once a day. - * (You can make this more or less frequent if desired by setting 'pushpoll_frequency' appropriately) - * This also lets us update our subscription to the hub, and add or replace hubs in case it - * changed. We will only update hubs once a day, regardless of 'pushpoll_frequency'. - */ - $poll_interval = Config::get('system', 'pushpoll_frequency'); - $contact['priority'] = (($poll_interval !== false) ? intval($poll_interval) : 3); - } - - if (($contact['priority'] >= 0) && !$force) { - $update = false; - - $t = $contact['last-update']; - - /* - * Based on $contact['priority'], should we poll this site now? Or later? - */ - switch ($contact['priority']) { - case 5: - if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 month")) { - $update = true; - } - break; - case 4: - if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 week")) { - $update = true; - } - break; - case 3: - if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 day")) { - $update = true; - } - break; - case 2: - if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 12 hour")) { - $update = true; - } - break; - case 1: - if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 hour")) { - $update = true; - } - break; - case 0: - default: - if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + ".$min_poll_interval." minute")) { - $update = true; - } - break; - } - if (!$update) { - continue; - } - } - - logger("Polling " . $contact["network"] . " " . $contact["id"] . " " . $contact["nick"] . " " . $contact["name"]); - - if (($contact['network'] == NETWORK_FEED) && ($contact['priority'] <= 3)) { - $priority = PRIORITY_MEDIUM; - } else { - $priority = PRIORITY_LOW; - } - Worker::add(array('priority' => $priority, 'dont_fork' => true), 'OnePoll', (int)$contact['id']); + if (in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS))) { + $contact['priority'] = 2; } + + if ($contact['subhub'] && in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS))) { + /* + * We should be getting everything via a hub. But just to be sure, let's check once a day. + * (You can make this more or less frequent if desired by setting 'pushpoll_frequency' appropriately) + * This also lets us update our subscription to the hub, and add or replace hubs in case it + * changed. We will only update hubs once a day, regardless of 'pushpoll_frequency'. + */ + $poll_interval = Config::get('system', 'pushpoll_frequency'); + $contact['priority'] = (($poll_interval !== false) ? intval($poll_interval) : 3); + } + + if (($contact['priority'] >= 0) && !$force) { + $update = false; + + $t = $contact['last-update']; + + /* + * Based on $contact['priority'], should we poll this site now? Or later? + */ + switch ($contact['priority']) { + case 5: + if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 month")) { + $update = true; + } + break; + case 4: + if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 week")) { + $update = true; + } + break; + case 3: + if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 day")) { + $update = true; + } + break; + case 2: + if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 12 hour")) { + $update = true; + } + break; + case 1: + if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 hour")) { + $update = true; + } + break; + case 0: + default: + if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + ".$min_poll_interval." minute")) { + $update = true; + } + break; + } + if (!$update) { + continue; + } + } + + logger("Polling " . $contact["network"] . " " . $contact["id"] . " " . $contact["nick"] . " " . $contact["name"]); + + if (($contact['network'] == NETWORK_FEED) && ($contact['priority'] <= 3)) { + $priority = PRIORITY_MEDIUM; + } else { + $priority = PRIORITY_LOW; + } + Worker::add(array('priority' => $priority, 'dont_fork' => true), 'OnePoll', (int)$contact['id']); } } } diff --git a/src/Worker/OnePoll.php b/src/Worker/OnePoll.php index f7f7bcccf..c5a62e982 100644 --- a/src/Worker/OnePoll.php +++ b/src/Worker/OnePoll.php @@ -23,7 +23,7 @@ Class OnePoll require_once 'include/items.php'; require_once 'include/queue_fn.php'; - logger('onepoll: start'); + logger('start'); $manual_id = 0; $generation = 0; @@ -36,7 +36,7 @@ Class OnePoll } if (!$contact_id) { - logger('onepoll: no contact'); + logger('no contact'); return; } @@ -88,10 +88,20 @@ Class OnePoll $last_updated = PortableContact::lastUpdated($contact["url"]); $updated = datetime_convert(); if ($last_updated) { + logger('Diaspora contact '.$contact['id'].' had last update on '.$last_updated, LOGGER_DEBUG); + + // The last public item can be older than the last item we got + if ($last_updated < $contact['last-item']) { + $last_updated = $contact['last-item']; + } + $fields = array('last-item' => $last_updated, 'last-update' => $updated, 'success_update' => $updated); dba::update('contact', $fields, array('id' => $contact['id'])); + Contact::unmarkForArchival($contact); } else { dba::update('contact', array('last-update' => $updated, 'failure_update' => $updated), array('id' => $contact['id'])); + Contact::markForArchival($contact); + logger('Diaspora contact '.$contact['id'].' is marked for archival', LOGGER_DEBUG); } } return; @@ -122,12 +132,18 @@ Class OnePoll if (($contact['network'] === NETWORK_OSTATUS) || ($contact['network'] === NETWORK_DIASPORA) || ($contact['network'] === NETWORK_DFRN)) { if (!PortableContact::reachable($contact['url'])) { logger("Skipping probably dead contact ".$contact['url']); + + // set the last-update so we don't keep polling + dba::update('contact', ['last-update' => datetime_convert()], ['id' => $contact['id']]); return; } if (!update_contact($contact["id"])) { Contact::markForArchival($contact); logger('Contact is marked dead'); + + // set the last-update so we don't keep polling + dba::update('contact', ['last-update' => datetime_convert()], ['id' => $contact['id']]); return; } else { Contact::unmarkForArchival($contact); @@ -136,6 +152,9 @@ Class OnePoll if ($importer_uid == 0) { logger('Ignore public contacts'); + + // set the last-update so we don't keep polling + dba::update('contact', ['last-update' => datetime_convert()], ['id' => $contact['id']]); return; } @@ -145,12 +164,15 @@ Class OnePoll if (!DBM::is_result($r)) { logger('No self contact for user '.$importer_uid); + + // set the last-update so we don't keep polling + dba::update('contact', ['last-update' => datetime_convert()], ['id' => $contact['id']]); return; } $importer = $r[0]; - logger("onepoll: poll: ({$contact['id']}) IMPORTER: {$importer['name']}, CONTACT: {$contact['name']}"); + logger("poll: ({$contact['network']}-{$contact['id']}) IMPORTER: {$importer['name']}, CONTACT: {$contact['name']}"); if ($contact['network'] === NETWORK_DFRN) { $idtosend = $orig_id = (($contact['dfrn-id']) ? $contact['dfrn-id'] : $contact['issued-id']); @@ -179,6 +201,9 @@ Class OnePoll $ret = z_fetch_url($url); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { + // set the last-update so we don't keep polling + dba::update('contact', ['last-update' => datetime_convert()], ['id' => $contact['id']]); + Contact::markForArchival($contact); return; } @@ -186,7 +211,7 @@ Class OnePoll $html_code = $a->get_curl_code(); - logger('onepoll: handshake with url ' . $url . ' returns xml: ' . $handshake_xml, LOGGER_DATA); + logger('handshake with url ' . $url . ' returns xml: ' . $handshake_xml, LOGGER_DATA); if (!strlen($handshake_xml) || ($html_code >= 400) || !$html_code) { @@ -201,7 +226,6 @@ Class OnePoll // set the last-update so we don't keep polling $fields = array('last-update' => datetime_convert(), 'failure_update' => datetime_convert()); dba::update('contact', $fields, array('id' => $contact['id'])); - return; } @@ -212,7 +236,6 @@ Class OnePoll $fields = array('last-update' => datetime_convert(), 'failure_update' => datetime_convert()); dba::update('contact', $fields, array('id' => $contact['id'])); - return; } @@ -234,6 +257,8 @@ Class OnePoll } if ((intval($res->status) != 0) || !strlen($res->challenge) || !strlen($res->dfrn_id)) { + // set the last-update so we don't keep polling + dba::update('contact', ['last-update' => datetime_convert()], ['id' => $contact['id']]); return; } @@ -264,8 +289,12 @@ Class OnePoll } if ($final_dfrn_id != $orig_id) { - logger('ID did not decode: ' . $contact['id'] . ' orig: ' . $orig_id . ' final: ' . $final_dfrn_id); // did not decode properly - cannot trust this site + logger('ID did not decode: ' . $contact['id'] . ' orig: ' . $orig_id . ' final: ' . $final_dfrn_id); + + // set the last-update so we don't keep polling + dba::update('contact', ['last-update' => datetime_convert()], ['id' => $contact['id']]); + Contact::markForArchival($contact); return; } @@ -298,6 +327,8 @@ Class OnePoll // Are we allowed to import from this person? if ($contact['rel'] == CONTACT_IS_FOLLOWER || $contact['blocked'] || $contact['readonly']) { + // set the last-update so we don't keep polling + dba::update('contact', ['last-update' => datetime_convert()], ['id' => $contact['id']]); return; } @@ -305,6 +336,9 @@ Class OnePoll $ret = z_fetch_url($contact['poll'], false, $redirects, array('cookiejar' => $cookiejar)); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { + // set the last-update so we don't keep polling + dba::update('contact', ['last-update' => datetime_convert()], ['id' => $contact['id']]); + Contact::markForArchival($contact); return; } @@ -317,6 +351,9 @@ Class OnePoll $mail_disabled = ((function_exists('imap_open') && (! Config::get('system', 'imap_disabled'))) ? 0 : 1); if ($mail_disabled) { + // set the last-update so we don't keep polling + dba::update('contact', ['last-update' => datetime_convert()], ['id' => $contact['id']]); + Contact::markForArchival($contact); return; } @@ -351,7 +388,7 @@ Class OnePoll $metas = Email::messageMeta($mbox, implode(',', $msgs)); if (count($metas) != count($msgs)) { - logger("onepoll: for " . $mailconf['user'] . " there are ". count($msgs) . " messages but received " . count($metas) . " metas", LOGGER_DEBUG); + logger("for " . $mailconf['user'] . " there are ". count($msgs) . " messages but received " . count($metas) . " metas", LOGGER_DEBUG); } else { $msgs = array_combine($msgs, $metas); @@ -560,7 +597,7 @@ Class OnePoll $fields = array('last-update' => datetime_convert(), 'failure_update' => datetime_convert()); dba::update('contact', $fields, array('id' => $contact['id'])); - + Contact::markForArchival($contact); return; } From 6f7510550d190b7704637f056c9482be7b02a567 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 3 Dec 2017 09:19:58 +0000 Subject: [PATCH 19/71] NETWORK_MAIL2 was never finished, so remove it as well --- boot.php | 2 - include/contact_selectors.php | 1 - include/uimport.php | 3 - mod/contacts.php | 6 +- mod/dfrn_request.php | 183 +++----------------------------- src/Worker/Cron.php | 5 +- src/Worker/Delivery.php | 1 - src/Worker/Notifier.php | 5 +- src/Worker/OnePoll.php | 2 +- update.php | 3 - view/templates/auto_request.tpl | 1 - view/templates/dfrn_request.tpl | 1 - 12 files changed, 24 insertions(+), 189 deletions(-) diff --git a/boot.php b/boot.php index 9cdaefb21..fd8110f75 100644 --- a/boot.php +++ b/boot.php @@ -259,7 +259,6 @@ define('NETWORK_OSTATUS', 'stat'); // status.net, identi.ca, GNU-soc define('NETWORK_FEED', 'feed'); // RSS/Atom feeds with no known "post/notify" protocol define('NETWORK_DIASPORA', 'dspr'); // Diaspora define('NETWORK_MAIL', 'mail'); // IMAP/POP -define('NETWORK_MAIL2', 'mai2'); // extended IMAP/POP define('NETWORK_FACEBOOK', 'face'); // Facebook API define('NETWORK_LINKEDIN', 'lnkd'); // LinkedIn define('NETWORK_XMPP', 'xmpp'); // XMPP @@ -290,7 +289,6 @@ $netgroup_ids = array( NETWORK_FEED => (-4), NETWORK_DIASPORA => (-5), NETWORK_MAIL => (-6), - NETWORK_MAIL2 => (-7), NETWORK_FACEBOOK => (-8), NETWORK_LINKEDIN => (-9), NETWORK_XMPP => (-10), diff --git a/include/contact_selectors.php b/include/contact_selectors.php index 1e754ac9f..67d05f307 100644 --- a/include/contact_selectors.php +++ b/include/contact_selectors.php @@ -85,7 +85,6 @@ function network_to_name($s, $profile = "") { NETWORK_LINKEDIN => t('LinkedIn'), NETWORK_XMPP => t('XMPP/IM'), NETWORK_MYSPACE => t('MySpace'), - NETWORK_MAIL2 => t('Email'), NETWORK_GPLUS => t('Google+'), NETWORK_PUMPIO => t('pump.io'), NETWORK_TWITTER => t('Twitter'), diff --git a/include/uimport.php b/include/uimport.php index 301ab4803..7effcd62d 100644 --- a/include/uimport.php +++ b/include/uimport.php @@ -198,9 +198,6 @@ function import_account(App $a, $file) { case NETWORK_DIASPORA: // send relocate message (below) break; - case NETWORK_MAIL2: - /// @TODO ? - break; case NETWORK_FEED: case NETWORK_MAIL: // Nothing to do diff --git a/mod/contacts.php b/mod/contacts.php index 69f188496..9feacaf5e 100644 --- a/mod/contacts.php +++ b/mod/contacts.php @@ -559,7 +559,7 @@ function contacts_content(App $a) { } $lblsuggest = (($contact['network'] === NETWORK_DFRN) ? t('Suggest friends') : ''); - $poll_enabled = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2)); + $poll_enabled = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_FEED, NETWORK_MAIL)); $nettype = sprintf( t('Network type: %s'),network_to_name($contact['network'], $contact["url"])); @@ -586,7 +586,7 @@ function contacts_content(App $a) { '3' => t('Fetch keywords'), '2' => t('Fetch information and keywords'))); } - if (in_array($contact['network'], array(NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2))) + if (in_array($contact['network'], array(NETWORK_FEED, NETWORK_MAIL))) $poll_interval = contact_poll_interval($contact['priority'],(! $poll_enabled)); if ($contact['network'] == NETWORK_DFRN) @@ -994,7 +994,7 @@ function _contact_detail_for_template($rr){ */ function contact_actions($contact) { - $poll_enabled = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_FEED, NETWORK_MAIL, NETWORK_MAIL2)); + $poll_enabled = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_FEED, NETWORK_MAIL)); $contact_action = array(); // Provide friend suggestion only for Friendica contacts diff --git a/mod/dfrn_request.php b/mod/dfrn_request.php index 3c7584318..5962ae204 100644 --- a/mod/dfrn_request.php +++ b/mod/dfrn_request.php @@ -292,15 +292,12 @@ function dfrn_request_post(App $a) { * * Cleanup old introductions that remain blocked. * Also remove the contact record, but only if there is no existing relationship - * Do not remove email contacts as these may be awaiting email verification */ $r = q("SELECT `intro`.*, `intro`.`id` AS `iid`, `contact`.`id` AS `cid`, `contact`.`rel` FROM `intro` LEFT JOIN `contact` on `intro`.`contact-id` = `contact`.`id` WHERE `intro`.`blocked` = 1 AND `contact`.`self` = 0 - AND `contact`.`network` != '%s' - AND `intro`.`datetime` < UTC_TIMESTAMP() - INTERVAL 30 MINUTE ", - dbesc(NETWORK_MAIL2) + AND `intro`.`datetime` < UTC_TIMESTAMP() - INTERVAL 30 MINUTE " ); if (DBM::is_result($r)) { foreach ($r as $rr) { @@ -315,32 +312,6 @@ function dfrn_request_post(App $a) { } } - /* - * - * Cleanup any old email intros - which will have a greater lifetime - */ - - $r = q("SELECT `intro`.*, `intro`.`id` AS `iid`, `contact`.`id` AS `cid`, `contact`.`rel` - FROM `intro` LEFT JOIN `contact` on `intro`.`contact-id` = `contact`.`id` - WHERE `intro`.`blocked` = 1 AND `contact`.`self` = 0 - AND `contact`.`network` = '%s' - AND `intro`.`datetime` < UTC_TIMESTAMP() - INTERVAL 3 DAY ", - dbesc(NETWORK_MAIL2) - ); - if (DBM::is_result($r)) { - foreach ($r as $rr) { - if(! $rr['rel']) { - q("DELETE FROM `contact` WHERE `id` = %d AND NOT `self`", - intval($rr['cid']) - ); - } - q("DELETE FROM `intro` WHERE `id` = %d", - intval($rr['iid']) - ); - } - } - - $email_follow = (x($_POST,'email_follow') ? intval($_POST['email_follow']) : 0); $real_name = (x($_POST,'realname') ? notags(trim($_POST['realname'])) : ''); $url = trim($_POST['dfrn_url']); @@ -351,125 +322,25 @@ function dfrn_request_post(App $a) { $hcard = ''; - if($email_follow) { + // Detect the network + $data = Probe::uri($url); + $network = $data["network"]; - if(! validate_email($url)) { - notice( t('Invalid email address.') . EOL); - return; + // Canonicalise email-style profile locator + $url = Probe::webfingerDfrn($url,$hcard); + + if (substr($url,0,5) === 'stat:') { + + // Every time we detect the remote subscription we define this as OStatus. + // We do this even if it is not OStatus. + // we only need to pass this through another section of the code. + if ($network != NETWORK_DIASPORA) { + $network = NETWORK_OSTATUS; } - $addr = $url; - $name = ($realname) ? $realname : $addr; - $nick = substr($addr,0,strpos($addr,'@')); - $url = 'http://' . substr($addr,strpos($addr,'@') + 1); - $nurl = normalise_url($host); - $poll = 'email ' . random_string(); - $notify = 'smtp ' . random_string(); - $network = NETWORK_MAIL2; - $rel = CONTACT_IS_FOLLOWER; - - $mail_disabled = ((function_exists('imap_open') && (! Config::get('system','imap_disabled'))) ? 0 : 1); - if(Config::get('system','dfrn_only')) - $mail_disabled = 1; - - if(! $mail_disabled) { - $failed = false; - $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1", - intval($uid) - ); - - if (! DBM::is_result($r)) { - notice( t('This account has not been configured for email. Request failed.') . EOL); - return; - } - } - - $r = q("insert into contact ( uid, created, addr, name, nick, url, nurl, poll, notify, blocked, pending, network, rel ) - values( %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', %d ) ", - intval($uid), - dbesc(datetime_convert()), - dbesc($addr), - dbesc($name), - dbesc($nick), - dbesc($url), - dbesc($nurl), - dbesc($poll), - dbesc($notify), - intval($blocked), - intval($pending), - dbesc($network), - intval($rel) - ); - - $r = q("SELECT `id`, `network` FROM `contact` WHERE `poll` = '%s' AND `uid` = %d LIMIT 1", - dbesc($poll), - intval($uid) - ); - if (DBM::is_result($r)) { - $contact_id = $r[0]['id']; - - $def_gid = get_default_group($uid, $r[0]["network"]); - if (intval($def_gid)) - group_add_member($uid, '', $contact_id, $def_gid); - - $photo = avatar_img($addr); - - $r = q("UPDATE `contact` SET - `photo` = '%s', - `thumb` = '%s', - `micro` = '%s', - `name-date` = '%s', - `uri-date` = '%s', - `avatar-date` = '%s', - `hidden` = 0, - WHERE `id` = %d - ", - dbesc($photos[0]), - dbesc($photos[1]), - dbesc($photos[2]), - dbesc(datetime_convert()), - dbesc(datetime_convert()), - dbesc(datetime_convert()), - intval($contact_id) - ); - } - - // contact is created. Now create an introduction - - $hash = random_string(); - - $r = q("INSERT INTO `intro` ( `uid`, `contact-id`, knowyou, note, hash, datetime, blocked ) - VALUES( %d , %d, %d, '%s', '%s', '%s', %d ) ", - intval($uid), - intval($contact_id), - ((x($_POST,'knowyou') && ($_POST['knowyou'] == 1)) ? 1 : 0), - dbesc(notags(trim($_POST['dfrn-request-message']))), - dbesc($hash), - dbesc(datetime_convert()), - 1 - ); - - // Next send an email verify form to the requestor. - + $url = substr($url,5); } else { - // Detect the network - $data = Probe::uri($url); - $network = $data["network"]; - - // Canonicalise email-style profile locator - $url = Probe::webfingerDfrn($url,$hcard); - - if (substr($url,0,5) === 'stat:') { - - // Every time we detect the remote subscription we define this as OStatus. - // We do this even if it is not OStatus. - // we only need to pass this through another section of the code. - if ($network != NETWORK_DIASPORA) - $network = NETWORK_OSTATUS; - - $url = substr($url,5); - } else - $network = NETWORK_DFRN; + $network = NETWORK_DFRN; } logger('dfrn_request: url: ' . $url . ',network=' . $network, LOGGER_DEBUG); @@ -849,27 +720,6 @@ function dfrn_request_content(App $a) { $page_desc = t("Please enter your 'Identity Address' from one of the following supported communications networks:"); - // see if we are allowed to have NETWORK_MAIL2 contacts - - $mail_disabled = ((function_exists('imap_open') && (! Config::get('system','imap_disabled'))) ? 0 : 1); - - if (Config::get('system','dfrn_only')) { - $mail_disabled = 1; - } - - if (! $mail_disabled) { - $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1", - intval($a->profile['uid']) - ); - if (! DBM::is_result($r)) { - $mail_disabled = 1; - } - } - - // "coming soon" is disabled for now - //$emailnet = (($mail_disabled) ? '' : t("Connect as an email follower \x28Coming soon\x29")); - $emailnet = ""; - $invite_desc = sprintf( t('If you are not yet a member of the free social web, follow this link to find a public Friendica site and join us today.'), get_server() @@ -891,7 +741,6 @@ function dfrn_request_content(App $a) { '$diasnote' => sprintf (t(' - please do not use this form. Instead, enter %s into your Diaspora search bar.'),$target_addr), '$your_address' => t('Your Identity Address:'), '$invite_desc' => $invite_desc, - '$emailnet' => $emailnet, '$submit' => t('Submit Request'), '$cancel' => t('Cancel'), '$nickname' => $a->argv[1], diff --git a/src/Worker/Cron.php b/src/Worker/Cron.php index 354cb3585..dd4ca4da2 100644 --- a/src/Worker/Cron.php +++ b/src/Worker/Cron.php @@ -156,7 +156,7 @@ Class Cron { $contacts = q("SELECT `contact`.`id` FROM `user` STRAIGHT_JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`rel` IN (%d, %d) AND `contact`.`poll` != '' - AND `contact`.`network` IN ('%s', '%s', '%s', '%s', '%s') $sql_extra + AND `contact`.`network` IN ('%s', '%s', '%s', '%s') $sql_extra AND NOT `contact`.`self` AND NOT `contact`.`blocked` AND NOT `contact`.`readonly` AND NOT `contact`.`archive` WHERE NOT `user`.`account_expired` AND NOT `user`.`account_removed` $abandon_sql ORDER BY RAND()", @@ -165,8 +165,7 @@ Class Cron { dbesc(NETWORK_DFRN), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_FEED), - dbesc(NETWORK_MAIL), - dbesc(NETWORK_MAIL2) + dbesc(NETWORK_MAIL) ); if (!DBM::is_result($contacts)) { diff --git a/src/Worker/Delivery.php b/src/Worker/Delivery.php index f17aa5507..bb30fc3bf 100644 --- a/src/Worker/Delivery.php +++ b/src/Worker/Delivery.php @@ -376,7 +376,6 @@ class Delivery { break; case NETWORK_MAIL: - case NETWORK_MAIL2: if (Config::get('system','dfrn_only')) { break; diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index 4404b879b..a3a03055e 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -447,7 +447,7 @@ class Notifier { // It only makes sense to distribute answers to OStatus messages to Friendica and OStatus - but not Diaspora $sql_extra = " AND `network` IN ('".NETWORK_OSTATUS."', '".NETWORK_DFRN."')"; } else { - $sql_extra = " AND `network` IN ('".NETWORK_OSTATUS."', '".NETWORK_DFRN."', '".NETWORK_DIASPORA."', '".NETWORK_MAIL."', '".NETWORK_MAIL2."')"; + $sql_extra = " AND `network` IN ('".NETWORK_OSTATUS."', '".NETWORK_DFRN."', '".NETWORK_DIASPORA."', '".NETWORK_MAIL."')"; } } else { $public_message = false; @@ -537,9 +537,8 @@ class Notifier { } $r2 = q("SELECT `id`, `name`,`network` FROM `contact` - WHERE `network` in ('%s', '%s') AND `uid` = %d AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND `rel` != %d", + WHERE `network` in ('%s') AND `uid` = %d AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND `rel` != %d", dbesc(NETWORK_DFRN), - dbesc(NETWORK_MAIL2), intval($owner['uid']), intval(CONTACT_IS_SHARING) ); diff --git a/src/Worker/OnePoll.php b/src/Worker/OnePoll.php index f7f7bcccf..439997be6 100644 --- a/src/Worker/OnePoll.php +++ b/src/Worker/OnePoll.php @@ -311,7 +311,7 @@ Class OnePoll $xml = $ret['body']; unlink($cookiejar); - } elseif ($contact['network'] === NETWORK_MAIL || $contact['network'] === NETWORK_MAIL2) { + } elseif ($contact['network'] === NETWORK_MAIL) { logger("Mail: Fetching for ".$contact['addr'], LOGGER_DEBUG); diff --git a/update.php b/update.php index 7fbdec707..326c08414 100644 --- a/update.php +++ b/update.php @@ -1484,9 +1484,6 @@ function update_1164() { $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)", NETWORK_MAIL, NETWORK_MAIL); - $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)", - NETWORK_MAIL2, NETWORK_MAIL2); - $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)", NETWORK_FACEBOOK, NETWORK_FACEBOOK); diff --git a/view/templates/auto_request.tpl b/view/templates/auto_request.tpl index d6abde030..78736c7e8 100644 --- a/view/templates/auto_request.tpl +++ b/view/templates/auto_request.tpl @@ -7,7 +7,6 @@
  • {{$friendica}}
  • {{$diaspora}} {{$diasnote}}
  • {{$statusnet}}
  • -{{if $emailnet}}
  • {{$emailnet}}
  • {{/if}}

    diff --git a/view/templates/dfrn_request.tpl b/view/templates/dfrn_request.tpl index 5225bd60b..34e4074df 100644 --- a/view/templates/dfrn_request.tpl +++ b/view/templates/dfrn_request.tpl @@ -8,7 +8,6 @@

  • {{$friendica}}
  • {{$diaspora}} {{$diasnote}}
  • {{$statusnet}}
  • -{{if $emailnet}}
  • {{$emailnet}}
  • {{/if}} {{$invite_desc}}

    From ffd04fed85cbfda0d91d3528ccb5c33f714bf5ad Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Sun, 3 Dec 2017 10:26:26 +0100 Subject: [PATCH 20/71] missing word --- mod/install.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod/install.php b/mod/install.php index 803d7f196..0da8ec040 100755 --- a/mod/install.php +++ b/mod/install.php @@ -318,7 +318,7 @@ function check_php(&$phpath, &$checks) { $help = ""; if (!$passed) { $help .= t('Could not find a command line version of PHP in the web server PATH.'). EOL; - $help .= t("If you don't have a command line version of PHP installed on server, you will not be able to run the background processing. See 'Setup the worker'") . EOL; + $help .= t("If you don't have a command line version of PHP installed on your server, you will not be able to run the background processing. See 'Setup the worker'") . EOL; $help .= EOL . EOL; $tpl = get_markup_template('field_input.tpl'); $help .= replace_macros($tpl, array( From 0b752324b537b764c3147142dbc14e7e52bf8248 Mon Sep 17 00:00:00 2001 From: hoergen Date: Sun, 3 Dec 2017 13:39:56 +0100 Subject: [PATCH 21/71] plusminus - removed blockquote borders, adjusted font size on several elements and classes --- view/theme/vier/plusminus.css | 46 ++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/view/theme/vier/plusminus.css b/view/theme/vier/plusminus.css index 77e8d3895..0b694c95f 100644 --- a/view/theme/vier/plusminus.css +++ b/view/theme/vier/plusminus.css @@ -1,5 +1,7 @@ /* Modifications by https://horche.demkontinuum.de/profile/hoergen */ +body { background-color: whitesmoke; } + h1 { font-size: 18px; color: blue; @@ -247,16 +249,22 @@ div.pager, ul.tabs { /* Post content */ .wall-item-content blockquote { - border-left: 2px solid #D2D2D2; + border-left: 0px; margin-top: 10px; margin-bottom:10px; padding-left: 5px; } +.wall-item-container .wall-item-content { + font-size: 14px; +} + .wall-item-content strong { color:#565656; } .wall-item-network { font-size:10px; } +.shared-time { font-size: 10px; } + .mention { font-size:12px;} .tag { font-size:12px; } @@ -268,16 +276,31 @@ div.pager, ul.tabs { padding-top: 5px; padding-bottom: 5px; margin-top: 20px; + margin-bottom: 20px; } .type-link blockquote{ - border-left: 2px solid #D2D2D2; + border-left: 0px; margin-top: 10px; margin-bottom:10px; - padding-left: 5px; + padding-left: 0px; font-size:12px; } +.type-link .oembed, .type-video .oembed { + font-size: 14px; + font-weight: 300; + line-height: normal; +} + +.shared_header { + min-height: 32px;; + color: #999; + border-top: 0px; + padding-top: 5px; + margin-top: 5px; +} + /* Post footer */ .wall-item-like { font-size:12px; } @@ -314,6 +337,10 @@ div.pager, ul.tabs { .wall-item-bottom { font-size: 14px; } +.icon::before { + width: 10px; +} + /* comments */ .wall-item-like { font-size:10px; } @@ -421,5 +448,16 @@ select { } .field label { - width: 300px; + width: 300px; } + +/* popup */ + +ul.menu-popup { + width: 16em; +} + +ul.menu-popup a { + padding: 0 0 0 5px; +} + From df89e0384da155a6ea9441893d731726f8839dee Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 3 Dec 2017 13:26:52 +0000 Subject: [PATCH 22/71] Added description to networks, renaming some network names --- boot.php | 16 ++++++++-------- mod/admin.php | 2 +- mod/dfrn_request.php | 6 +++--- mod/install.php | 2 +- mod/notice.php | 2 +- view/templates/auto_request.tpl | 6 +++--- view/templates/dfrn_request.tpl | 6 +++--- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/boot.php b/boot.php index fd8110f75..04e14ac4d 100644 --- a/boot.php +++ b/boot.php @@ -254,24 +254,24 @@ define('PROTOCOL_SPLITTED_CONV', 6); * @{ */ define('NETWORK_DFRN', 'dfrn'); // Friendica, Mistpark, other DFRN implementations -define('NETWORK_ZOT', 'zot!'); // Zot! -define('NETWORK_OSTATUS', 'stat'); // status.net, identi.ca, GNU-social, other OStatus implementations +define('NETWORK_ZOT', 'zot!'); // Zot! - Currently unsupported +define('NETWORK_OSTATUS', 'stat'); // GNU-social, Pleroma, Mastodon, other OStatus implementations define('NETWORK_FEED', 'feed'); // RSS/Atom feeds with no known "post/notify" protocol define('NETWORK_DIASPORA', 'dspr'); // Diaspora define('NETWORK_MAIL', 'mail'); // IMAP/POP define('NETWORK_FACEBOOK', 'face'); // Facebook API define('NETWORK_LINKEDIN', 'lnkd'); // LinkedIn -define('NETWORK_XMPP', 'xmpp'); // XMPP -define('NETWORK_MYSPACE', 'mysp'); // MySpace +define('NETWORK_XMPP', 'xmpp'); // XMPP - Currently unsupported +define('NETWORK_MYSPACE', 'mysp'); // MySpace - Currently unsupported define('NETWORK_GPLUS', 'goog'); // Google+ define('NETWORK_PUMPIO', 'pump'); // pump.io define('NETWORK_TWITTER', 'twit'); // Twitter define('NETWORK_DIASPORA2', 'dspc'); // Diaspora connector define('NETWORK_STATUSNET', 'stac'); // Statusnet connector -define('NETWORK_APPNET', 'apdn'); // app.net -define('NETWORK_NEWS', 'nntp'); // Network News Transfer Protocol -define('NETWORK_ICALENDAR', 'ical'); // iCalendar -define('NETWORK_PNUT', 'pnut'); // pnut.io +define('NETWORK_APPNET', 'apdn'); // app.net - Dead protocol +define('NETWORK_NEWS', 'nntp'); // Network News Transfer Protocol - Currently unsupported +define('NETWORK_ICALENDAR', 'ical'); // iCalendar - Currently unsupported +define('NETWORK_PNUT', 'pnut'); // pnut.io - Currently unsupported define('NETWORK_PHANTOM', 'unkn'); // Place holder /** * @} diff --git a/mod/admin.php b/mod/admin.php index 1e7d90436..d73ac23fd 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -1279,7 +1279,7 @@ function admin_page_site(App $a) '$banner' => array('banner', t("Banner/Logo"), $banner, ""), '$shortcut_icon' => array('shortcut_icon', t("Shortcut icon"), Config::get('system','shortcut_icon'), t("Link to an icon that will be used for browsers.")), '$touch_icon' => array('touch_icon', t("Touch icon"), Config::get('system','touch_icon'), t("Link to an icon that will be used for tablets and mobiles.")), - '$info' => array('info', t('Additional Info'), $info, sprintf(t('For public servers: you can add additional information here that will be listed at %s/siteinfo.'), get_server())), + '$info' => array('info', t('Additional Info'), $info, sprintf(t('For public servers: you can add additional information here that will be listed at %s/servers.'), get_server())), '$language' => array('language', t("System language"), Config::get('system','language'), "", $lang_choices), '$theme' => array('theme', t("System theme"), Config::get('system','theme'), t("Default system theme - may be over-ridden by user profiles - change theme settings"), $theme_choices), '$theme_mobile' => array('theme_mobile', t("Mobile system theme"), Config::get('system', 'mobile-theme', '---'), t("Theme for mobile devices"), $theme_choices_mobile), diff --git a/mod/dfrn_request.php b/mod/dfrn_request.php index 5962ae204..67395a9fc 100644 --- a/mod/dfrn_request.php +++ b/mod/dfrn_request.php @@ -727,7 +727,7 @@ function dfrn_request_content(App $a) { $o = replace_macros($tpl,array( '$header' => t('Friend/Connection Request'), - '$desc' => t('Examples: jojo@demo.friendica.com, http://demo.friendica.com/profile/jojo, testuser@identi.ca'), + '$desc' => t('Examples: jojo@demo.friendica.com, http://demo.friendica.com/profile/jojo, testuser@gnusocial.de'), '$pls_answer' => t('Please answer the following:'), '$does_know_you' => array('knowyou', sprintf(t('Does %s know you?'),$a->profile['name']), false, '', array(t('No'), t('Yes'))), /*'$does_know' => sprintf( t('Does %s know you?'),$a->profile['name']), @@ -736,8 +736,8 @@ function dfrn_request_content(App $a) { '$add_note' => t('Add a personal note:'), '$page_desc' => $page_desc, '$friendica' => t('Friendica'), - '$statusnet' => t('StatusNet/Federated Social Web'), - '$diaspora' => t('Diaspora'), + '$statusnet' => t('GNU Social (Pleroma, Mastodon)'), + '$diaspora' => t('Diaspora (Socialhome, Hubzilla)'), '$diasnote' => sprintf (t(' - please do not use this form. Instead, enter %s into your Diaspora search bar.'),$target_addr), '$your_address' => t('Your Identity Address:'), '$invite_desc' => $invite_desc, diff --git a/mod/install.php b/mod/install.php index 803d7f196..0da8ec040 100755 --- a/mod/install.php +++ b/mod/install.php @@ -318,7 +318,7 @@ function check_php(&$phpath, &$checks) { $help = ""; if (!$passed) { $help .= t('Could not find a command line version of PHP in the web server PATH.'). EOL; - $help .= t("If you don't have a command line version of PHP installed on server, you will not be able to run the background processing. See 'Setup the worker'") . EOL; + $help .= t("If you don't have a command line version of PHP installed on your server, you will not be able to run the background processing. See 'Setup the worker'") . EOL; $help .= EOL . EOL; $tpl = get_markup_template('field_input.tpl'); $help .= replace_macros($tpl, array( diff --git a/mod/notice.php b/mod/notice.php index 54618bdf8..95d16f2dd 100644 --- a/mod/notice.php +++ b/mod/notice.php @@ -1,6 +1,6 @@ friendica items permanent-url compatibility */ +/* GNU Social -> friendica items permanent-url compatibility */ use Friendica\App; use Friendica\Core\System; diff --git a/view/templates/auto_request.tpl b/view/templates/auto_request.tpl index 78736c7e8..c7e10482e 100644 --- a/view/templates/auto_request.tpl +++ b/view/templates/auto_request.tpl @@ -4,9 +4,9 @@

    {{$page_desc}}

    diff --git a/view/templates/dfrn_request.tpl b/view/templates/dfrn_request.tpl index 34e4074df..8e686c33d 100644 --- a/view/templates/dfrn_request.tpl +++ b/view/templates/dfrn_request.tpl @@ -5,9 +5,9 @@

    {{$page_desc}}

    {{$invite_desc}}

    From 3359f3f5c7ecc4b6a34c4fcfc095ab4dd5fab0f1 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 3 Dec 2017 08:36:39 -0500 Subject: [PATCH 23/71] Fix formatting in mod/settings --- mod/settings.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/mod/settings.php b/mod/settings.php index af514e3a9..6ac3af285 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -348,7 +348,6 @@ function settings_post(App $a) { } } - $r = q("UPDATE `user` SET `theme` = '%s' WHERE `uid` = %d", dbesc($theme), intval(local_user()) @@ -370,7 +369,6 @@ function settings_post(App $a) { call_hooks('settings_post', $_POST); if (x($_POST, 'password') || x($_POST, 'confirm')) { - $newpass = $_POST['password']; $confirm = $_POST['confirm']; @@ -385,9 +383,8 @@ function settings_post(App $a) { $err = true; } - // check if the old password was supplied correctly before - // changing it to the new value if (User::authenticate(intval(local_user()), $_POST['opassword'])) { + // check if the old password was supplied correctly before changing it to the new value notice(t('Wrong password.') . EOL); $err = true; } @@ -398,14 +395,14 @@ function settings_post(App $a) { dbesc($password), intval(local_user()) ); - if ($r) + if ($r) { info(t('Password changed.') . EOL); - else + } else { notice(t('Password update failed. Please try again.') . EOL); + } } } - $username = ((x($_POST, 'username')) ? notags(trim($_POST['username'])) : ''); $email = ((x($_POST, 'email')) ? notags(trim($_POST['email'])) : ''); $timezone = ((x($_POST, 'timezone')) ? notags(trim($_POST['timezone'])) : ''); From 1eb8355ac8321c937ae8e884f857f676ab72e609 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 3 Dec 2017 08:37:01 -0500 Subject: [PATCH 24/71] Fix wrong condition Grmbl --- mod/settings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod/settings.php b/mod/settings.php index 6ac3af285..9af354a9b 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -383,8 +383,8 @@ function settings_post(App $a) { $err = true; } - if (User::authenticate(intval(local_user()), $_POST['opassword'])) { // check if the old password was supplied correctly before changing it to the new value + if (!User::authenticate(intval(local_user()), $_POST['opassword'])) { notice(t('Wrong password.') . EOL); $err = true; } From 4395c2067941f9052eb2ccf009eed0adb8e05cf9 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 3 Dec 2017 22:15:31 -0500 Subject: [PATCH 25/71] Fix formatting and add documentation - mod/register - mod/regmod - Model/User - Worker/CronJobs --- mod/register.php | 4 +-- mod/regmod.php | 43 +++++++++++++++----------------- src/Model/User.php | 13 ++++++++++ src/Worker/CronJobs.php | 54 ++++++++++++++++++++++------------------- 4 files changed, 63 insertions(+), 51 deletions(-) diff --git a/mod/register.php b/mod/register.php index cd6385144..8645ecb9c 100644 --- a/mod/register.php +++ b/mod/register.php @@ -6,9 +6,9 @@ use Friendica\Core\PConfig; use Friendica\Core\System; use Friendica\Core\Worker; -require_once('include/enotify.php'); -require_once('include/bbcode.php'); require_once('include/user.php'); +require_once 'include/enotify.php'; +require_once 'include/bbcode.php'; if(! function_exists('register_post')) { function register_post(App $a) { diff --git a/mod/regmod.php b/mod/regmod.php index 6d76e7ea7..7fce6914f 100644 --- a/mod/regmod.php +++ b/mod/regmod.php @@ -6,11 +6,12 @@ use Friendica\Core\System; use Friendica\Core\Worker; use Friendica\Database\DBM; -require_once('include/enotify.php'); require_once('include/user.php'); -function user_allow($hash) { +require_once 'include/enotify.php'; +function user_allow($hash) +{ $a = get_app(); $register = q("SELECT * FROM `register` WHERE `hash` = '%s' LIMIT 1", @@ -18,7 +19,7 @@ function user_allow($hash) { ); - if (! DBM::is_result($register)) { + if (!DBM::is_result($register)) { return false; } @@ -26,7 +27,7 @@ function user_allow($hash) { intval($register[0]['uid']) ); - if (! DBM::is_result($user)) { + if (!DBM::is_result($user)) { killme(); } @@ -44,7 +45,7 @@ function user_allow($hash) { ); if (DBM::is_result($r) && $r[0]['net-publish']) { $url = System::baseUrl() . '/profile/' . $user[0]['nickname']; - if ($url && strlen(Config::get('system','directory'))) { + if ($url && strlen(Config::get('system', 'directory'))) { Worker::add(PRIORITY_LOW, "Directory", $url); } } @@ -60,20 +61,17 @@ function user_allow($hash) { pop_lang(); - if($res) { - info( t('Account approved.') . EOL ); + if ($res) { + info(t('Account approved.') . EOL); return true; } - } - // This does not have to go through user_remove() and save the nickname // permanently against re-registration, as the person was not yet // allowed to have friends on this system - -function user_deny($hash) { - +function user_deny($hash) +{ $register = q("SELECT * FROM `register` WHERE `hash` = '%s' LIMIT 1", dbesc($hash) ); @@ -91,23 +89,22 @@ function user_deny($hash) { notice(sprintf(t('Registration revoked for %s'), $user[0]['username']) . EOL); return true; - } -function regmod_content(App $a) { - +function regmod_content(App $a) +{ global $lang; $_SESSION['return_url'] = $a->cmd; - if (! local_user()) { - info( t('Please login.') . EOL); + if (!local_user()) { + info(t('Please login.') . EOL); $o .= '

    ' . login(($a->config['register_policy'] == REGISTER_CLOSED) ? 0 : 1); return $o; } - if ((!is_site_admin()) || (x($_SESSION,'submanage') && intval($_SESSION['submanage']))) { - notice( t('Permission denied.') . EOL); + if ((!is_site_admin()) || (x($_SESSION, 'submanage') && intval($_SESSION['submanage']))) { + notice(t('Permission denied.') . EOL); return ''; } @@ -115,20 +112,18 @@ function regmod_content(App $a) { killme(); } - $cmd = $a->argv[1]; + $cmd = $a->argv[1]; $hash = $a->argv[2]; - - if ($cmd === 'deny') { user_deny($hash); - goaway(System::baseUrl()."/admin/users/"); + goaway(System::baseUrl() . "/admin/users/"); killme(); } if ($cmd === 'allow') { user_allow($hash); - goaway(System::baseUrl()."/admin/users/"); + goaway(System::baseUrl() . "/admin/users/"); killme(); } } diff --git a/src/Model/User.php b/src/Model/User.php index b2beb8e19..398cd19b4 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -20,6 +20,19 @@ require_once 'include/plugin.php'; */ class User { + /** + * @brief Authenticate a user with a clear text password + * + * User info can be any of the following: + * - User DB object + * - User Id + * - User email or username or nickname + * - User array with at least the uid and the hashed password + * + * @param mixed $user_info + * @param string $password + * @return boolean + */ public static function authenticate($user_info, $password) { if (is_object($user_info)) { diff --git a/src/Worker/CronJobs.php b/src/Worker/CronJobs.php index cbfa86ed8..a59cd4f9f 100644 --- a/src/Worker/CronJobs.php +++ b/src/Worker/CronJobs.php @@ -1,4 +1,5 @@ '%s' @@ -120,9 +124,9 @@ class CronJobs { * * @param App $a */ - private static function clearCache(App $a) { - - $last = Config::get('system','cache_last_cleared'); + private static function clearCache(App $a) + { + $last = Config::get('system', 'cache_last_cleared'); if ($last) { $next = $last + (3600); // Once per hour @@ -142,16 +146,16 @@ class CronJobs { clear_cache(); // clear cache for photos - clear_cache($a->get_basepath(), $a->get_basepath()."/photo"); + clear_cache($a->get_basepath(), $a->get_basepath() . "/photo"); // clear smarty cache - clear_cache($a->get_basepath()."/view/smarty3/compiled", $a->get_basepath()."/view/smarty3/compiled"); + clear_cache($a->get_basepath() . "/view/smarty3/compiled", $a->get_basepath() . "/view/smarty3/compiled"); // clear cache for image proxy if (!Config::get("system", "proxy_disabled")) { - clear_cache($a->get_basepath(), $a->get_basepath()."/proxy"); + clear_cache($a->get_basepath(), $a->get_basepath() . "/proxy"); - $cachetime = Config::get('system','proxy_cache_time'); + $cachetime = Config::get('system', 'proxy_cache_time'); if (!$cachetime) { $cachetime = PROXY_DEFAULT_TIME; } @@ -166,13 +170,13 @@ class CronJobs { dba::delete('parsed_url', array("`created` < NOW() - INTERVAL 3 MONTH")); // Maximum table size in megabyte - $max_tablesize = intval(Config::get('system','optimize_max_tablesize')) * 1000000; + $max_tablesize = intval(Config::get('system', 'optimize_max_tablesize')) * 1000000; if ($max_tablesize == 0) { $max_tablesize = 100 * 1000000; // Default are 100 MB } if ($max_tablesize > 0) { // Minimum fragmentation level in percent - $fragmentation_level = intval(Config::get('system','optimize_fragmentation')) / 100; + $fragmentation_level = intval(Config::get('system', 'optimize_fragmentation')) / 100; if ($fragmentation_level == 0) { $fragmentation_level = 0.3; // Default value is 30% } @@ -194,7 +198,7 @@ class CronJobs { // Calculate fragmentation $fragmentation = $table["Data_free"] / ($table["Data_length"] + $table["Index_length"]); - logger("Table ".$table["Name"]." - Fragmentation level: ".round($fragmentation * 100, 2), LOGGER_DEBUG); + logger("Table " . $table["Name"] . " - Fragmentation level: " . round($fragmentation * 100, 2), LOGGER_DEBUG); // Don't optimize tables that needn't to be optimized if ($fragmentation < $fragmentation_level) { @@ -202,12 +206,12 @@ class CronJobs { } // So optimize it - logger("Optimize Table ".$table["Name"], LOGGER_DEBUG); + logger("Optimize Table " . $table["Name"], LOGGER_DEBUG); q("OPTIMIZE TABLE `%s`", dbesc($table["Name"])); } } - Config::set('system','cache_last_cleared', time()); + Config::set('system', 'cache_last_cleared', time()); } /** @@ -215,8 +219,8 @@ class CronJobs { * * @param App $a */ - private static function repairDiaspora(App $a) { - + private static function repairDiaspora(App $a) + { $starttime = time(); $r = q("SELECT `id`, `url` FROM `contact` @@ -241,7 +245,7 @@ class CronJobs { continue; } - logger("Repair contact ".$contact["id"]." ".$contact["url"], LOGGER_DEBUG); + logger("Repair contact " . $contact["id"] . " " . $contact["url"], LOGGER_DEBUG); q("UPDATE `contact` SET `batch` = '%s', `notify` = '%s', `poll` = '%s', pubkey = '%s' WHERE `id` = %d", dbesc($data["batch"]), dbesc($data["notify"]), dbesc($data["poll"]), dbesc($data["pubkey"]), intval($contact["id"])); @@ -252,15 +256,15 @@ class CronJobs { * @brief Do some repairs in database entries * */ - private static function repairDatabase() { - + private static function repairDatabase() + { // Sometimes there seem to be issues where the "self" contact vanishes. // We haven't found the origin of the problem by now. $r = q("SELECT `uid` FROM `user` WHERE NOT EXISTS (SELECT `uid` FROM `contact` WHERE `contact`.`uid` = `user`.`uid` AND `contact`.`self`)"); if (DBM::is_result($r)) { foreach ($r AS $user) { - logger('Create missing self contact for user '.$user['uid']); user_create_self_contact($user['uid']); + logger('Create missing self contact for user ' . $user['uid']); } } From b0dcfc2724188c309a70ce5281e94fdf6a733498 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 3 Dec 2017 22:27:49 -0500 Subject: [PATCH 26/71] Add class methods derived from include/user functions - Add User::create - Add User::sendRegisterPendingEmail - Add User::sendRegisterOpenEmail - Add Contact::createSelfFromUserId --- src/Model/User.php | 429 ++++++++++++++++++++++++++++++++++++++++- src/Object/Contact.php | 46 +++++ 2 files changed, 474 insertions(+), 1 deletion(-) diff --git a/src/Model/User.php b/src/Model/User.php index 398cd19b4..72e3aea93 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -7,14 +7,23 @@ namespace Friendica\Model; +use Friendica\Core\Config; use Friendica\Core\System; use Friendica\Core\Worker; use Friendica\Database\DBM; +use Friendica\Object\Contact; +use Friendica\Object\Photo; use dba; require_once 'boot.php'; +require_once 'include/crypto.php'; +require_once 'include/enotify.php'; +require_once 'include/group.php'; +require_once 'include/network.php'; +require_once 'library/openid.php'; +require_once 'include/pgettext.php'; require_once 'include/plugin.php'; - +require_once 'include/text.php'; /** * @brief This class handles User related functions */ @@ -79,6 +88,424 @@ class User return $user['uid']; } + /** + * @brief Catch-all user creation function + * + * Creates a user from the provided data array, either form fields or OpenID. + * Required: { username, nickname, email } or { openid_url } + * + * Performs the following: + * - Sends to the OpenId auth URL (if relevant) + * - Creates new key pairs for crypto + * - Create self-contact + * - Create profile image + * + * @param array $data + * @return string + */ + public static function create(array $data) + { + $a = get_app(); + $result = array('success' => false, 'user' => null, 'password' => '', 'message' => ''); + + $using_invites = Config::get('system', 'invitation_only'); + $num_invites = Config::get('system', 'number_invites'); + + $invite_id = x($data, 'invite_id') ? notags(trim($data['invite_id'])) : ''; + $username = x($data, 'username') ? notags(trim($data['username'])) : ''; + $nickname = x($data, 'nickname') ? notags(trim($data['nickname'])) : ''; + $email = x($data, 'email') ? notags(trim($data['email'])) : ''; + $openid_url = x($data, 'openid_url') ? notags(trim($data['openid_url'])) : ''; + $photo = x($data, 'photo') ? notags(trim($data['photo'])) : ''; + $password = x($data, 'password') ? trim($data['password']) : ''; + $password1 = x($data, 'password1') ? trim($data['password1']) : ''; + $confirm = x($data, 'confirm') ? trim($data['confirm']) : ''; + $blocked = x($data, 'blocked') ? intval($data['blocked']) : 0; + $verified = x($data, 'verified') ? intval($data['verified']) : 0; + + $publish = x($data, 'profile_publish_reg') && intval($data['profile_publish_reg']) ? 1 : 0; + $netpublish = strlen(Config::get('system', 'directory')) ? $publish : 0; + + if ($password1 != $confirm) { + $result['message'] .= t('Passwords do not match. Password unchanged.') . EOL; + return $result; + } elseif ($password1 != "") { + $password = $password1; + } + + $tmp_str = $openid_url; + + if ($using_invites) { + if (!$invite_id) { + $result['message'] .= t('An invitation is required.') . EOL; + return $result; + } + $r = q("SELECT * FROM `register` WHERE `hash` = '%s' LIMIT 1", dbesc($invite_id)); + if (!results($r)) { + $result['message'] .= t('Invitation could not be verified.') . EOL; + return $result; + } + } + + if (!x($username) || !x($email) || !x($nickname)) { + if ($openid_url) { + if (!validate_url($tmp_str)) { + $result['message'] .= t('Invalid OpenID url') . EOL; + return $result; + } + $_SESSION['register'] = 1; + $_SESSION['openid'] = $openid_url; + + $openid = new LightOpenID; + $openid->identity = $openid_url; + $openid->returnUrl = System::baseUrl() . '/openid'; + $openid->required = array('namePerson/friendly', 'contact/email', 'namePerson'); + $openid->optional = array('namePerson/first', 'media/image/aspect11', 'media/image/default'); + try { + $authurl = $openid->authUrl(); + } catch (Exception $e) { + $result['message'] .= t("We encountered a problem while logging in with the OpenID you provided. Please check the correct spelling of the ID.") . EOL . EOL . t("The error message was:") . $e->getMessage() . EOL; + return $result; + } + goaway($authurl); + // NOTREACHED + } + + notice(t('Please enter the required information.') . EOL); + return; + } + + if (!validate_url($tmp_str)) { + $openid_url = ''; + } + + $err = ''; + + // collapse multiple spaces in name + $username = preg_replace('/ +/', ' ', $username); + + if (mb_strlen($username) > 48) { + $result['message'] .= t('Please use a shorter name.') . EOL; + } + if (mb_strlen($username) < 3) { + $result['message'] .= t('Name too short.') . EOL; + } + + // So now we are just looking for a space in the full name. + + $loose_reg = Config::get('system', 'no_regfullname'); + if (!$loose_reg) { + $username = mb_convert_case($username, MB_CASE_TITLE, 'UTF-8'); + if (!strpos($username, ' ')) { + $result['message'] .= t("That doesn't appear to be your full \x28First Last\x29 name.") . EOL; + } + } + + + if (!allowed_email($email)) { + $result['message'] .= t('Your email domain is not among those allowed on this site.') . EOL; + } + + if (!valid_email($email) || !validate_email($email)) { + $result['message'] .= t('Not a valid email address.') . EOL; + } + + // Disallow somebody creating an account using openid that uses the admin email address, + // since openid bypasses email verification. We'll allow it if there is not yet an admin account. + + $adminlist = explode(",", str_replace(" ", "", strtolower($a->config['admin_email']))); + + //if((x($a->config,'admin_email')) && (strcasecmp($email,$a->config['admin_email']) == 0) && strlen($openid_url)) { + if (x($a->config, 'admin_email') && in_array(strtolower($email), $adminlist) && strlen($openid_url)) { + $r = q("SELECT * FROM `user` WHERE `email` = '%s' LIMIT 1", + dbesc($email) + ); + if (DBM::is_result($r)) { + $result['message'] .= t('Cannot use that email.') . EOL; + } + } + + $nickname = $data['nickname'] = strtolower($nickname); + + if (!preg_match("/^[a-z0-9][a-z0-9\_]*$/", $nickname)) { + $result['message'] .= t('Your "nickname" can only contain "a-z", "0-9" and "_".') . EOL; + } + + $r = q("SELECT `uid` FROM `user` + WHERE `nickname` = '%s' LIMIT 1", + dbesc($nickname) + ); + if (DBM::is_result($r)) { + $result['message'] .= t('Nickname is already registered. Please choose another.') . EOL; + } + + // Check deleted accounts that had this nickname. Doesn't matter to us, + // but could be a security issue for federated platforms. + + $r = q("SELECT * FROM `userd` + WHERE `username` = '%s' LIMIT 1", + dbesc($nickname) + ); + if (DBM::is_result($r)) { + $result['message'] .= t('Nickname was once registered here and may not be re-used. Please choose another.') . EOL; + } + + if (strlen($result['message'])) { + return $result; + } + + $new_password = strlen($password) ? $password : autoname(6) . mt_rand(100, 9999); + $new_password_encoded = hash('whirlpool', $new_password); + + $result['password'] = $new_password; + + $keys = new_keypair(4096); + + if ($keys === false) { + $result['message'] .= t('SERIOUS ERROR: Generation of security keys failed.') . EOL; + return $result; + } + + $prvkey = $keys['prvkey']; + $pubkey = $keys['pubkey']; + + // Create another keypair for signing/verifying salmon protocol messages. + $sres = new_keypair(512); + $sprvkey = $sres['prvkey']; + $spubkey = $sres['pubkey']; + + $r = q("INSERT INTO `user` (`guid`, `username`, `password`, `email`, `openid`, `nickname`, + `pubkey`, `prvkey`, `spubkey`, `sprvkey`, `register_date`, `verified`, `blocked`, `timezone`, `default-location`) + VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, 'UTC', '')", + dbesc(generate_user_guid()), + dbesc($username), + dbesc($new_password_encoded), + dbesc($email), + dbesc($openid_url), + dbesc($nickname), + dbesc($pubkey), + dbesc($prvkey), + dbesc($spubkey), + dbesc($sprvkey), + dbesc(datetime_convert()), + intval($verified), + intval($blocked) + ); + + if ($r) { + $r = q("SELECT * FROM `user` + WHERE `username` = '%s' AND `password` = '%s' LIMIT 1", + dbesc($username), + dbesc($new_password_encoded) + ); + if (DBM::is_result($r)) { + $u = $r[0]; + $newuid = intval($r[0]['uid']); + } + } else { + $result['message'] .= t('An error occurred during registration. Please try again.') . EOL; + return $result; + } + + /** + * if somebody clicked submit twice very quickly, they could end up with two accounts + * due to race condition. Remove this one. + */ + $r = q("SELECT `uid` FROM `user` + WHERE `nickname` = '%s' ", + dbesc($nickname) + ); + if (DBM::is_result($r) && count($r) > 1 && $newuid) { + $result['message'] .= t('Nickname is already registered. Please choose another.') . EOL; + dba::delete('user', array('uid' => $newuid)); + return $result; + } + + if (x($newuid) !== false) { + $r = q("INSERT INTO `profile` ( `uid`, `profile-name`, `is-default`, `name`, `photo`, `thumb`, `publish`, `net-publish` ) + VALUES ( %d, '%s', %d, '%s', '%s', '%s', %d, %d ) ", + intval($newuid), + t('default'), + 1, + dbesc($username), + dbesc(System::baseUrl() . "/photo/profile/{$newuid}.jpg"), + dbesc(System::baseUrl() . "/photo/avatar/{$newuid}.jpg"), + intval($publish), + intval($netpublish) + ); + if ($r === false) { + $result['message'] .= t('An error occurred creating your default profile. Please try again.') . EOL; + // Start fresh next time. + dba::delete('user', array('uid' => $newuid)); + return $result; + } + + // Create the self contact + Contact::createSelfFromUserId($newuid); + + // Create a group with no members. This allows somebody to use it + // right away as a default group for new contacts. + + group_add($newuid, t('Friends')); + + $r = q("SELECT `id` FROM `group` WHERE `uid` = %d AND `name` = '%s'", + intval($newuid), + dbesc(t('Friends')) + ); + if (DBM::is_result($r)) { + $def_gid = $r[0]['id']; + + q("UPDATE `user` SET `def_gid` = %d WHERE `uid` = %d", + intval($r[0]['id']), + intval($newuid) + ); + } + + if (Config::get('system', 'newuser_private') && $def_gid) { + q("UPDATE `user` SET `allow_gid` = '%s' WHERE `uid` = %d", + dbesc("<" . $def_gid . ">"), + intval($newuid) + ); + } + } + + // if we have no OpenID photo try to look up an avatar + if (!strlen($photo)) { + $photo = avatar_img($email); + } + + // unless there is no avatar-plugin loaded + if (strlen($photo)) { + $photo_failure = false; + + $filename = basename($photo); + $img_str = fetch_url($photo, true); + // guess mimetype from headers or filename + $type = Photo::guessImageType($photo, true); + + + $img = new Photo($img_str, $type); + if ($img->isValid()) { + $img->scaleImageSquare(175); + + $hash = photo_new_resource(); + + $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 4); + + if ($r === false) { + $photo_failure = true; + } + + $img->scaleImage(80); + + $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 5); + + if ($r === false) { + $photo_failure = true; + } + + $img->scaleImage(48); + + $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 6); + + if ($r === false) { + $photo_failure = true; + } + + if (!$photo_failure) { + q("UPDATE `photo` SET `profile` = 1 WHERE `resource-id` = '%s' ", + dbesc($hash) + ); + } + } + } + + call_hooks('register_account', $newuid); + + $result['success'] = true; + $result['user'] = $u; + return $result; + } + + /** + * @brief Sends pending registration confiŕmation email + * + * @param string $email + * @param string $sitename + * @param string $username + * @return NULL|boolean from notification() and email() inherited + */ + public static function sendRegisterPendingEmail($email, $sitename, $username) + { + $body = deindent(t(' + Dear %1$s, + Thank you for registering at %2$s. Your account is pending for approval by the administrator. + ')); + + $body = sprintf($body, $username, $sitename); + + return notification(array( + 'type' => SYSTEM_EMAIL, + 'to_email' => $email, + 'subject'=> sprintf( t('Registration at %s'), $sitename), + 'body' => $body)); + } + + /** + * @brief Sends registration confirmation + * + * It's here as a function because the mail is sent from different parts + * + * @param string $email + * @param string $sitename + * @param string $siteurl + * @param string $username + * @param string $password + * @return NULL|boolean from notification() and email() inherited + */ + public static function sendRegisterOpenEmail($email, $sitename, $siteurl, $username, $password) + { + $preamble = deindent(t(' + Dear %1$s, + Thank you for registering at %2$s. Your account has been created. + ')); + $body = deindent(t(' + The login details are as follows: + Site Location: %3$s + Login Name: %1$s + Password: %5$s + + You may change your password from your account "Settings" page after logging + in. + + Please take a few moments to review the other account settings on that page. + + You may also wish to add some basic information to your default profile + (on the "Profiles" page) so that other people can easily find you. + + We recommend setting your full name, adding a profile photo, + adding some profile "keywords" (very useful in making new friends) - and + perhaps what country you live in; if you do not wish to be more specific + than that. + + We fully respect your right to privacy, and none of these items are necessary. + If you are new and do not know anybody here, they may help + you to make some new and interesting friends. + + + Thank you and welcome to %2$s.')); + + $preamble = sprintf($preamble, $username, $sitename); + $body = sprintf($body, $email, $sitename, $siteurl, $username, $password); + + return notification(array( + 'type' => SYSTEM_EMAIL, + 'to_email' => $email, + 'subject'=> sprintf( t('Registration details for %s'), $sitename), + 'preamble'=> $preamble, + 'body' => $body)); + } + /** * @param object $uid user to remove * @return void diff --git a/src/Object/Contact.php b/src/Object/Contact.php index 34519401c..fc1b26aba 100644 --- a/src/Object/Contact.php +++ b/src/Object/Contact.php @@ -28,6 +28,52 @@ require_once 'include/text.php'; */ class Contact extends BaseObject { + /** + * Creates the self-contact for the provided user id + * + * @param int $uid + * @return bool Operation success + */ + public static function createSelfFromUserId($uid) + { + // Only create the entry if it doesn't exist yet + if (dba::exists('contact', ['uid' => intval($uid), 'self'])) { + return true; + } + + $user = dba::select('user', ['uid', 'username', 'nickname'], ['uid' => intval($uid)], ['limit' => 1]); + if (!DBM::is_result($user)) { + return false; + } + + $return = dba::insert('contact', [ + 'uid' => $user['uid'], + 'created' => datetime_convert(), + 'self' => 1, + 'name' => $user['username'], + 'nick' => $user['nickname'], + 'photo' => System::baseUrl() . '/photo/profile/' . $user['uid'] . '.jpg', + 'thumb' => System::baseUrl() . '/photo/avatar/' . $user['uid'] . '.jpg', + 'micro' => System::baseUrl() . '/photo/micro/' . $user['uid'] . '.jpg', + 'blocked' => 0, + 'pending' => 0, + 'url' => System::baseUrl() . '/profile/' . $user['nickname'], + 'nurl' => normalise_link(System::baseUrl() . '/profile/' . $user['nickname']), + 'addr' => $user['nickname'] . '@' . substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3), + 'request' => System::baseUrl() . '/dfrn_request/' . $user['nickname'], + 'notify' => System::baseUrl() . '/dfrn_notify/' . $user['nickname'], + 'poll' => System::baseUrl() . '/dfrn_poll/' . $user['nickname'], + 'confirm' => System::baseUrl() . '/dfrn_confirm/' . $user['nickname'], + 'poco' => System::baseUrl() . '/poco/' . $user['nickname'], + 'name-date' => datetime_convert(), + 'uri-date' => datetime_convert(), + 'avatar-date' => datetime_convert(), + 'closeness' => 0 + ]); + + return $return; + } + /** * @brief Marks a contact for removal * From 27212c7f3904d42308686bf82b9b300be3d8dc7c Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 3 Dec 2017 22:29:06 -0500 Subject: [PATCH 27/71] Update function calls to use Model\User and Object\Contact --- mod/admin.php | 4 +--- mod/register.php | 8 ++++---- mod/regmod.php | 4 +--- src/Worker/CronJobs.php | 3 ++- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/mod/admin.php b/mod/admin.php index d73ac23fd..1b6975ab8 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -1466,9 +1466,7 @@ function admin_page_users_post(App $a) check_form_security_token_redirectOnErr('/admin/users', 'admin_users'); if (!($nu_name === "") && !($nu_email === "") && !($nu_nickname === "")) { - require_once 'include/user.php'; - - $result = create_user(array('username' => $nu_name, 'email' => $nu_email, + $result = User::create(array('username' => $nu_name, 'email' => $nu_email, 'nickname' => $nu_nickname, 'verified' => 1, 'language' => $nu_language)); if (!$result['success']) { notice($result['message']); diff --git a/mod/register.php b/mod/register.php index 8645ecb9c..4f6dedd24 100644 --- a/mod/register.php +++ b/mod/register.php @@ -5,8 +5,8 @@ use Friendica\Core\Config; use Friendica\Core\PConfig; use Friendica\Core\System; use Friendica\Core\Worker; +use Friendica\Model\User; -require_once('include/user.php'); require_once 'include/enotify.php'; require_once 'include/bbcode.php'; @@ -61,7 +61,7 @@ function register_post(App $a) { $arr['verified'] = $verified; $arr['language'] = get_browser_language(); - $result = create_user($arr); + $result = User::create($arr); if(! $result['success']) { notice($result['message']); @@ -89,7 +89,7 @@ function register_post(App $a) { // Only send a password mail when the password wasn't manually provided if (!x($_POST,'password1') || !x($_POST,'confirm')) { - $res = send_register_open_eml( + $res = User::sendRegisterOpenEmail( $user['email'], $a->config['sitename'], System::baseUrl(), @@ -159,7 +159,7 @@ function register_post(App $a) { )); } // send notification to the user, that the registration is pending - send_register_pending_eml( + User::sendRegisterPendingEmail( $user['email'], $a->config['sitename'], $user['username']); diff --git a/mod/regmod.php b/mod/regmod.php index 7fce6914f..2c5d61059 100644 --- a/mod/regmod.php +++ b/mod/regmod.php @@ -6,8 +6,6 @@ use Friendica\Core\System; use Friendica\Core\Worker; use Friendica\Database\DBM; -require_once('include/user.php'); - require_once 'include/enotify.php'; function user_allow($hash) @@ -52,7 +50,7 @@ function user_allow($hash) push_lang($register[0]['language']); - send_register_open_eml( + User::sendRegisterOpenEmail( $user[0]['email'], $a->config['sitename'], System::baseUrl(), diff --git a/src/Worker/CronJobs.php b/src/Worker/CronJobs.php index a59cd4f9f..7df7d030c 100644 --- a/src/Worker/CronJobs.php +++ b/src/Worker/CronJobs.php @@ -12,6 +12,7 @@ use Friendica\Core\Config; use Friendica\Database\DBM; use Friendica\Model\GlobalContact; use Friendica\Network\Probe; +use Friendica\Object\Contact; use Friendica\Protocol\PortableContact; use dba; @@ -263,8 +264,8 @@ class CronJobs $r = q("SELECT `uid` FROM `user` WHERE NOT EXISTS (SELECT `uid` FROM `contact` WHERE `contact`.`uid` = `user`.`uid` AND `contact`.`self`)"); if (DBM::is_result($r)) { foreach ($r AS $user) { - user_create_self_contact($user['uid']); logger('Create missing self contact for user ' . $user['uid']); + Contact::createSelfFromUserId($user['uid']); } } From 85f6d6b7ed518a32fd939335fa646f959f0d636d Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 3 Dec 2017 22:29:13 -0500 Subject: [PATCH 28/71] Remove include/user --- include/user.php | 453 ----------------------------------------------- 1 file changed, 453 deletions(-) delete mode 100644 include/user.php diff --git a/include/user.php b/include/user.php deleted file mode 100644 index 356f10ad0..000000000 --- a/include/user.php +++ /dev/null @@ -1,453 +0,0 @@ - false, 'user' => null, 'password' => '', 'message' => ''); - - $using_invites = Config::get('system','invitation_only'); - $num_invites = Config::get('system','number_invites'); - - - $invite_id = ((x($arr,'invite_id')) ? notags(trim($arr['invite_id'])) : ''); - $username = ((x($arr,'username')) ? notags(trim($arr['username'])) : ''); - $nickname = ((x($arr,'nickname')) ? notags(trim($arr['nickname'])) : ''); - $email = ((x($arr,'email')) ? notags(trim($arr['email'])) : ''); - $openid_url = ((x($arr,'openid_url')) ? notags(trim($arr['openid_url'])) : ''); - $photo = ((x($arr,'photo')) ? notags(trim($arr['photo'])) : ''); - $password = ((x($arr,'password')) ? trim($arr['password']) : ''); - $password1 = ((x($arr,'password1')) ? trim($arr['password1']) : ''); - $confirm = ((x($arr,'confirm')) ? trim($arr['confirm']) : ''); - $blocked = ((x($arr,'blocked')) ? intval($arr['blocked']) : 0); - $verified = ((x($arr,'verified')) ? intval($arr['verified']) : 0); - - $publish = ((x($arr,'profile_publish_reg') && intval($arr['profile_publish_reg'])) ? 1 : 0); - $netpublish = ((strlen(Config::get('system','directory'))) ? $publish : 0); - - if ($password1 != $confirm) { - $result['message'] .= t('Passwords do not match. Password unchanged.') . EOL; - return $result; - } elseif ($password1 != "") - $password = $password1; - - $tmp_str = $openid_url; - - if($using_invites) { - if(! $invite_id) { - $result['message'] .= t('An invitation is required.') . EOL; - return $result; - } - $r = q("SELECT * FROM `register` WHERE `hash` = '%s' LIMIT 1", dbesc($invite_id)); - if(! results($r)) { - $result['message'] .= t('Invitation could not be verified.') . EOL; - return $result; - } - } - - if((! x($username)) || (! x($email)) || (! x($nickname))) { - if($openid_url) { - if(! validate_url($tmp_str)) { - $result['message'] .= t('Invalid OpenID url') . EOL; - return $result; - } - $_SESSION['register'] = 1; - $_SESSION['openid'] = $openid_url; - require_once('library/openid.php'); - $openid = new LightOpenID; - $openid->identity = $openid_url; - $openid->returnUrl = System::baseUrl() . '/openid'; - $openid->required = array('namePerson/friendly', 'contact/email', 'namePerson'); - $openid->optional = array('namePerson/first','media/image/aspect11','media/image/default'); - try { - $authurl = $openid->authUrl(); - } catch (Exception $e){ - $result['message'] .= t("We encountered a problem while logging in with the OpenID you provided. Please check the correct spelling of the ID."). EOL . EOL . t("The error message was:") . $e->getMessage() . EOL; - return $result; - } - goaway($authurl); - // NOTREACHED - } - - notice( t('Please enter the required information.') . EOL ); - return; - } - - if(! validate_url($tmp_str)) - $openid_url = ''; - - - $err = ''; - - // collapse multiple spaces in name - $username = preg_replace('/ +/',' ',$username); - - if(mb_strlen($username) > 48) - $result['message'] .= t('Please use a shorter name.') . EOL; - if(mb_strlen($username) < 3) - $result['message'] .= t('Name too short.') . EOL; - - // So now we are just looking for a space in the full name. - - $loose_reg = Config::get('system','no_regfullname'); - if(! $loose_reg) { - $username = mb_convert_case($username,MB_CASE_TITLE,'UTF-8'); - if(! strpos($username,' ')) - $result['message'] .= t("That doesn't appear to be your full \x28First Last\x29 name.") . EOL; - } - - - if(! allowed_email($email)) - $result['message'] .= t('Your email domain is not among those allowed on this site.') . EOL; - - if((! valid_email($email)) || (! validate_email($email))) - $result['message'] .= t('Not a valid email address.') . EOL; - - // Disallow somebody creating an account using openid that uses the admin email address, - // since openid bypasses email verification. We'll allow it if there is not yet an admin account. - - $adminlist = explode(",", str_replace(" ", "", strtolower($a->config['admin_email']))); - - //if((x($a->config,'admin_email')) && (strcasecmp($email,$a->config['admin_email']) == 0) && strlen($openid_url)) { - if((x($a->config,'admin_email')) && in_array(strtolower($email), $adminlist) && strlen($openid_url)) { - $r = q("SELECT * FROM `user` WHERE `email` = '%s' LIMIT 1", - dbesc($email) - ); - if (DBM::is_result($r)) - $result['message'] .= t('Cannot use that email.') . EOL; - } - - $nickname = $arr['nickname'] = strtolower($nickname); - - if(! preg_match("/^[a-z0-9][a-z0-9\_]*$/",$nickname)) - $result['message'] .= t('Your "nickname" can only contain "a-z", "0-9" and "_".') . EOL; - - $r = q("SELECT `uid` FROM `user` - WHERE `nickname` = '%s' LIMIT 1", - dbesc($nickname) - ); - if (DBM::is_result($r)) - $result['message'] .= t('Nickname is already registered. Please choose another.') . EOL; - - // Check deleted accounts that had this nickname. Doesn't matter to us, - // but could be a security issue for federated platforms. - - $r = q("SELECT * FROM `userd` - WHERE `username` = '%s' LIMIT 1", - dbesc($nickname) - ); - if (DBM::is_result($r)) - $result['message'] .= t('Nickname was once registered here and may not be re-used. Please choose another.') . EOL; - - if(strlen($result['message'])) { - return $result; - } - - $new_password = ((strlen($password)) ? $password : autoname(6) . mt_rand(100,9999)); - $new_password_encoded = hash('whirlpool',$new_password); - - $result['password'] = $new_password; - - require_once('include/crypto.php'); - - $keys = new_keypair(4096); - - if($keys === false) { - $result['message'] .= t('SERIOUS ERROR: Generation of security keys failed.') . EOL; - return $result; - } - - $prvkey = $keys['prvkey']; - $pubkey = $keys['pubkey']; - - // Create another keypair for signing/verifying salmon protocol messages. - $sres = new_keypair(512); - $sprvkey = $sres['prvkey']; - $spubkey = $sres['pubkey']; - - $r = q("INSERT INTO `user` (`guid`, `username`, `password`, `email`, `openid`, `nickname`, - `pubkey`, `prvkey`, `spubkey`, `sprvkey`, `register_date`, `verified`, `blocked`, `timezone`, `default-location`) - VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, 'UTC', '')", - dbesc(generate_user_guid()), - dbesc($username), - dbesc($new_password_encoded), - dbesc($email), - dbesc($openid_url), - dbesc($nickname), - dbesc($pubkey), - dbesc($prvkey), - dbesc($spubkey), - dbesc($sprvkey), - dbesc(datetime_convert()), - intval($verified), - intval($blocked) - ); - - if ($r) { - $r = q("SELECT * FROM `user` - WHERE `username` = '%s' AND `password` = '%s' LIMIT 1", - dbesc($username), - dbesc($new_password_encoded) - ); - if (DBM::is_result($r)) { - $u = $r[0]; - $newuid = intval($r[0]['uid']); - } - } - else { - $result['message'] .= t('An error occurred during registration. Please try again.') . EOL ; - return $result; - } - - /** - * if somebody clicked submit twice very quickly, they could end up with two accounts - * due to race condition. Remove this one. - */ - - $r = q("SELECT `uid` FROM `user` - WHERE `nickname` = '%s' ", - dbesc($nickname) - ); - if ((DBM::is_result($r)) && (count($r) > 1) && $newuid) { - $result['message'] .= t('Nickname is already registered. Please choose another.') . EOL; - dba::delete('user', array('uid' => $newuid)); - return $result; - } - - if(x($newuid) !== false) { - $r = q("INSERT INTO `profile` ( `uid`, `profile-name`, `is-default`, `name`, `photo`, `thumb`, `publish`, `net-publish` ) - VALUES ( %d, '%s', %d, '%s', '%s', '%s', %d, %d ) ", - intval($newuid), - t('default'), - 1, - dbesc($username), - dbesc(System::baseUrl() . "/photo/profile/{$newuid}.jpg"), - dbesc(System::baseUrl() . "/photo/avatar/{$newuid}.jpg"), - intval($publish), - intval($netpublish) - - ); - if ($r === false) { - $result['message'] .= t('An error occurred creating your default profile. Please try again.') . EOL; - // Start fresh next time. - dba::delete('user', array('uid' => $newuid)); - return $result; - } - - // Create the self contact - user_create_self_contact($newuid); - - // Create a group with no members. This allows somebody to use it - // right away as a default group for new contacts. - - require_once('include/group.php'); - group_add($newuid, t('Friends')); - - $r = q("SELECT `id` FROM `group` WHERE `uid` = %d AND `name` = '%s'", - intval($newuid), - dbesc(t('Friends')) - ); - if (DBM::is_result($r)) { - $def_gid = $r[0]['id']; - - q("UPDATE `user` SET `def_gid` = %d WHERE `uid` = %d", - intval($r[0]['id']), - intval($newuid) - ); - } - - if(Config::get('system', 'newuser_private') && $def_gid) { - q("UPDATE `user` SET `allow_gid` = '%s' WHERE `uid` = %d", - dbesc("<" . $def_gid . ">"), - intval($newuid) - ); - } - - } - - // if we have no OpenID photo try to look up an avatar - if(! strlen($photo)) - $photo = avatar_img($email); - - // unless there is no avatar-plugin loaded - if (strlen($photo)) { - $photo_failure = false; - - $filename = basename($photo); - $img_str = fetch_url($photo, true); - // guess mimetype from headers or filename - $type = Photo::guessImageType($photo, true); - - - $img = new Photo($img_str, $type); - if ($img->isValid()) { - $img->scaleImageSquare(175); - - $hash = photo_new_resource(); - - $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 4); - - if ($r === false) { - $photo_failure = true; - } - - $img->scaleImage(80); - - $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 5 ); - - if ($r === false) { - $photo_failure = true; - } - - $img->scaleImage(48); - - $r = $img->store($newuid, 0, $hash, $filename, t('Profile Photos'), 6 ); - - if ($r === false) { - $photo_failure = true; - } - - if (! $photo_failure) { - q("UPDATE `photo` SET `profile` = 1 WHERE `resource-id` = '%s' ", - dbesc($hash) - ); - } - } - } - - call_hooks('register_account', $newuid); - - $result['success'] = true; - $result['user'] = $u; - return $result; - -} - -/** - * @brief create the "self" contact from data from the user table - * - * @param integer $uid - */ -function user_create_self_contact($uid) { - - // Only create the entry if it doesn't exist yet - $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `self`", intval($uid)); - if (DBM::is_result($r)) { - return; - } - - $r = q("SELECT `uid`, `username`, `nickname` FROM `user` WHERE `uid` = %d", intval($uid)); - if (!DBM::is_result($r)) { - return; - } - - $user = $r[0]; - - q("INSERT INTO `contact` (`uid`, `created`, `self`, `name`, `nick`, `photo`, `thumb`, `micro`, `blocked`, `pending`, `url`, `nurl`, - `addr`, `request`, `notify`, `poll`, `confirm`, `poco`, `name-date`, `uri-date`, `avatar-date`, `closeness`) - VALUES (%d, '%s', 1, '%s', '%s', '%s', '%s', '%s', 0, 0, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', 0)", - intval($user['uid']), - datetime_convert(), - dbesc($user['username']), - dbesc($user['nickname']), - dbesc(System::baseUrl()."/photo/profile/".$user['uid'].".jpg"), - dbesc(System::baseUrl()."/photo/avatar/".$user['uid'].".jpg"), - dbesc(System::baseUrl()."/photo/micro/".$user['uid'].".jpg"), - dbesc(System::baseUrl()."/profile/".$user['nickname']), - dbesc(normalise_link(System::baseUrl()."/profile/".$user['nickname'])), - dbesc($user['nickname'].'@'.substr(System::baseUrl(), strpos(System::baseUrl(),'://') + 3)), - dbesc(System::baseUrl()."/dfrn_request/".$user['nickname']), - dbesc(System::baseUrl()."/dfrn_notify/".$user['nickname']), - dbesc(System::baseUrl()."/dfrn_poll/".$user['nickname']), - dbesc(System::baseUrl()."/dfrn_confirm/".$user['nickname']), - dbesc(System::baseUrl()."/poco/".$user['nickname']), - dbesc(datetime_convert()), - dbesc(datetime_convert()), - dbesc(datetime_convert()) - ); -} - -/** - * @brief send registration confiŕmation with the intormation that reg is pending - * - * @param string $email - * @param string $sitename - * @param string $username - * @return NULL|boolean from notification() and email() inherited - */ -function send_register_pending_eml($email, $sitename, $username) { - $body = deindent(t(' - Dear %1$s, - Thank you for registering at %2$s. Your account is pending for approval by the administrator. - ')); - - $body = sprintf($body, $username, $sitename); - - return notification(array( - 'type' => SYSTEM_EMAIL, - 'to_email' => $email, - 'subject'=> sprintf( t('Registration at %s'), $sitename), - 'body' => $body)); -} - -/* - * send registration confirmation. - * It's here as a function because the mail is sent - * from different parts - */ -function send_register_open_eml($email, $sitename, $siteurl, $username, $password){ - $preamble = deindent(t(' - Dear %1$s, - Thank you for registering at %2$s. Your account has been created. - ')); - $body = deindent(t(' - The login details are as follows: - Site Location: %3$s - Login Name: %1$s - Password: %5$s - - You may change your password from your account "Settings" page after logging - in. - - Please take a few moments to review the other account settings on that page. - - You may also wish to add some basic information to your default profile - (on the "Profiles" page) so that other people can easily find you. - - We recommend setting your full name, adding a profile photo, - adding some profile "keywords" (very useful in making new friends) - and - perhaps what country you live in; if you do not wish to be more specific - than that. - - We fully respect your right to privacy, and none of these items are necessary. - If you are new and do not know anybody here, they may help - you to make some new and interesting friends. - - - Thank you and welcome to %2$s.')); - - $preamble = sprintf($preamble, $username, $sitename); - $body = sprintf($body, $email, $sitename, $siteurl, $username, $password); - - return notification(array( - 'type' => SYSTEM_EMAIL, - 'to_email' => $email, - 'subject'=> sprintf( t('Registration details for %s'), $sitename), - 'preamble'=> $preamble, - 'body' => $body)); -} From ad8c290c2b0050f4bf9ae437d6bdbe5e51aad0c8 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 4 Dec 2017 06:54:08 +0000 Subject: [PATCH 29/71] Improved vitality check for followers, feeds and OStatus contacts --- src/Worker/Cron.php | 4 +--- src/Worker/OnePoll.php | 35 +++++++++-------------------------- 2 files changed, 10 insertions(+), 29 deletions(-) diff --git a/src/Worker/Cron.php b/src/Worker/Cron.php index 43c33103b..5814c0548 100644 --- a/src/Worker/Cron.php +++ b/src/Worker/Cron.php @@ -157,13 +157,11 @@ Class Cron { `contact`.`last-update`, `contact`.`priority`, `contact`.`subhub` FROM `user` STRAIGHT_JOIN `contact` - ON `contact`.`uid` = `user`.`uid` AND `contact`.`rel` IN (%d, %d) AND `contact`.`poll` != '' + ON `contact`.`uid` = `user`.`uid` AND `contact`.`poll` != '' AND `contact`.`network` IN ('%s', '%s', '%s', '%s', '%s') $sql_extra AND NOT `contact`.`self` AND NOT `contact`.`blocked` AND NOT `contact`.`readonly` AND NOT `contact`.`archive` WHERE NOT `user`.`account_expired` AND NOT `user`.`account_removed` $abandon_sql", - intval(CONTACT_IS_SHARING), - intval(CONTACT_IS_FRIEND), dbesc(NETWORK_DFRN), dbesc(NETWORK_OSTATUS), dbesc(NETWORK_DIASPORA), diff --git a/src/Worker/OnePoll.php b/src/Worker/OnePoll.php index 64c533f82..0cf261a6e 100644 --- a/src/Worker/OnePoll.php +++ b/src/Worker/OnePoll.php @@ -42,30 +42,12 @@ Class OnePoll $d = datetime_convert(); - // Only poll from those with suitable relationships, - // and which have a polling address and ignore Diaspora since - // we are unable to match those posts with a Diaspora GUID and prevent duplicates. - - $contacts = q("SELECT `contact`.* FROM `contact` - WHERE (`rel` = %d OR `rel` = %d) AND `poll` != '' - AND NOT `network` IN ('%s', '%s') - AND `contact`.`id` = %d - AND `self` = 0 AND `contact`.`blocked` = 0 AND `contact`.`readonly` = 0 - AND `contact`.`archive` = 0 LIMIT 1", - intval(CONTACT_IS_SHARING), - intval(CONTACT_IS_FRIEND), - dbesc(NETWORK_FACEBOOK), - dbesc(NETWORK_PUMPIO), - intval($contact_id) - ); - - if (!count($contacts)) { + $contact = dba::select('contact', [], ['id' => $contact_id], ['limit' => 1]); + if (!DBM::is_result($contact)) { logger('Contact not found or cannot be used.'); return; } - $contact = $contacts[0]; - $importer_uid = $contact['uid']; // load current friends if possible. @@ -81,14 +63,13 @@ Class OnePoll } } - /// @TODO Check why we don't poll the Diaspora feed at the moment (some guid problem in the items?) - /// @TODO Check whether this is possible with Redmatrix - if ($contact["network"] == NETWORK_DIASPORA) { + // Diaspora users and followers we only check if they still exist. + if (($contact["network"] == NETWORK_DIASPORA) || ($contact["rel"] == CONTACT_IS_FOLLOWER)) { if (PortableContact::updateNeeded($contact["created"], $contact["last-item"], $contact["failure_update"], $contact["success_update"])) { $last_updated = PortableContact::lastUpdated($contact["url"]); $updated = datetime_convert(); if ($last_updated) { - logger('Diaspora contact '.$contact['id'].' had last update on '.$last_updated, LOGGER_DEBUG); + logger('Contact '.$contact['id'].' had last update on '.$last_updated, LOGGER_DEBUG); // The last public item can be older than the last item we got if ($last_updated < $contact['last-item']) { @@ -101,7 +82,7 @@ Class OnePoll } else { dba::update('contact', array('last-update' => $updated, 'failure_update' => $updated), array('id' => $contact['id'])); Contact::markForArchival($contact); - logger('Diaspora contact '.$contact['id'].' is marked for archival', LOGGER_DEBUG); + logger('Contact '.$contact['id'].' is marked for archival', LOGGER_DEBUG); } } return; @@ -334,6 +315,7 @@ Class OnePoll $cookiejar = tempnam(get_temppath(), 'cookiejar-onepoll-'); $ret = z_fetch_url($contact['poll'], false, $redirects, array('cookiejar' => $cookiejar)); + unlink($cookiejar); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { // set the last-update so we don't keep polling @@ -344,7 +326,6 @@ Class OnePoll $xml = $ret['body']; - unlink($cookiejar); } elseif ($contact['network'] === NETWORK_MAIL) { logger("Mail: Fetching for ".$contact['addr'], LOGGER_DEBUG); @@ -643,11 +624,13 @@ Class OnePoll dba::update('contact', array('last-update' => $updated, 'success_update' => $updated), array('id' => $contact['id'])); dba::update('gcontact', array('last_contact' => $updated), array('nurl' => $contact['nurl'])); + Contact::unmarkForArchival($contact); } elseif (in_array($contact["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS, NETWORK_FEED))) { $updated = datetime_convert(); dba::update('contact', array('last-update' => $updated, 'failure_update' => $updated), array('id' => $contact['id'])); dba::update('gcontact', array('last_failure' => $updated), array('nurl' => $contact['nurl'])); + Contact::markForArchival($contact); } else { dba::update('contact', array('last-update' => $updated), array('id' => $contact['id'])); } From 2f0da29c753b870866d90e229237ace7e864769c Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Mon, 4 Dec 2017 08:33:49 -0500 Subject: [PATCH 30/71] Features to src Move Features to class in Friendica\Content namespace. Update function calls and references. --- boot.php | 1 - include/acl_selectors.php | 7 +- include/api.php | 3 +- include/contact_widgets.php | 11 ++- include/conversation.php | 7 +- include/event.php | 5 +- include/features.php | 144 ---------------------------------- include/identity.php | 7 +- include/items.php | 3 +- include/nav.php | 7 +- include/tags.php | 7 +- include/text.php | 7 +- mod/admin.php | 6 +- mod/cal.php | 4 +- mod/editpost.php | 7 +- mod/network.php | 15 ++-- mod/photos.php | 7 +- mod/ping.php | 5 +- mod/profiles.php | 7 +- mod/search.php | 15 ++-- mod/settings.php | 7 +- src/Content/Features.php | 148 +++++++++++++++++++++++++++++++++++ src/Content/ForumManager.php | 5 +- src/Object/Item.php | 17 ++-- 24 files changed, 241 insertions(+), 211 deletions(-) delete mode 100644 include/features.php create mode 100644 src/Content/Features.php diff --git a/boot.php b/boot.php index 04e14ac4d..15dfec48b 100644 --- a/boot.php +++ b/boot.php @@ -36,7 +36,6 @@ require_once 'include/text.php'; require_once 'include/datetime.php'; require_once 'include/pgettext.php'; require_once 'include/nav.php'; -require_once 'include/features.php'; require_once 'include/identity.php'; require_once 'update.php'; require_once 'include/dbstructure.php'; diff --git a/include/acl_selectors.php b/include/acl_selectors.php index 5ae30d563..50c733e34 100644 --- a/include/acl_selectors.php +++ b/include/acl_selectors.php @@ -1,10 +1,9 @@ t('Permissions'), '$aclModalDismiss' => t('Close'), '$features' => array( - 'aclautomention' => (feature_enabled($user['uid'], "aclautomention") ? "true" : "false") + 'aclautomention' => (Features::isEnabled($user['uid'], "aclautomention") ? "true" : "false") ), )); diff --git a/include/api.php b/include/api.php index 12380f4b8..4055f2b4c 100644 --- a/include/api.php +++ b/include/api.php @@ -6,6 +6,7 @@ * @todo Automatically detect if incoming data is HTML or BBCode */ use Friendica\App; +use Friendica\Content\Features; use Friendica\Core\System; use Friendica\Core\Config; use Friendica\Core\NotificationsManager; @@ -5100,7 +5101,7 @@ function api_friendica_profile_show($type) $profileid = (x($_REQUEST, 'profile_id') ? $_REQUEST['profile_id'] : 0); // retrieve general information about profiles for user - $multi_profiles = feature_enabled(api_user(), 'multi_profiles'); + $multi_profiles = Features::isEnabled(api_user(), 'multi_profiles'); $directory = Config::get('system', 'directory'); // get data of the specified profile id or all profiles of the user if not specified diff --git a/include/contact_widgets.php b/include/contact_widgets.php index 5108eaf72..af63de767 100644 --- a/include/contact_widgets.php +++ b/include/contact_widgets.php @@ -1,5 +1,8 @@ profile['profile_uid'], 'categories')) { + if (! Features::isEnabled($a->profile['profile_uid'], 'categories')) { return ''; } diff --git a/include/conversation.php b/include/conversation.php index bba852e7a..b32a98426 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -3,6 +3,7 @@ * @file include/conversation.php */ use Friendica\App; +use Friendica\Content\Features; use Friendica\Core\Config; use Friendica\Core\PConfig; use Friendica\Core\System; @@ -915,7 +916,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { '$mode' => $mode, '$user' => $a->user, '$threads' => $threads, - '$dropping' => ($page_dropping && feature_enabled(local_user(), 'multi_delete') ? t('Delete Selected Items') : False), + '$dropping' => ($page_dropping && Features::isEnabled(local_user(), 'multi_delete') ? t('Delete Selected Items') : False), )); return $o; @@ -1305,7 +1306,7 @@ function status_editor(App $a, $x, $notes_cid = 0, $popup = false) { '$title' => $x['title'], '$placeholdertitle' => t('Set title'), '$category' => $x['category'], - '$placeholdercategory' => (feature_enabled(local_user(), 'categories') ? t('Categories (comma-separated list)') : ''), + '$placeholdercategory' => (Features::isEnabled(local_user(), 'categories') ? t('Categories (comma-separated list)') : ''), '$wait' => t('Please wait'), '$permset' => t('Permission settings'), '$shortpermset' => t('permissions'), @@ -1321,7 +1322,7 @@ function status_editor(App $a, $x, $notes_cid = 0, $popup = false) { '$lockstate' => $x['lockstate'], '$bang' => $x['bang'], '$profile_uid' => $x['profile_uid'], - '$preview' => ((feature_enabled($x['profile_uid'],'preview')) ? t('Preview') : ''), + '$preview' => ((Features::isEnabled($x['profile_uid'],'preview')) ? t('Preview') : ''), '$jotplugins' => $jotplugins, '$notes_cid' => $notes_cid, '$sourceapp' => t($a->sourcename), diff --git a/include/event.php b/include/event.php index a0509aa0f..07b90f249 100644 --- a/include/event.php +++ b/include/event.php @@ -5,6 +5,7 @@ */ use Friendica\App; +use Friendica\Content\Features; use Friendica\Core\PConfig; use Friendica\Core\System; use Friendica\Database\DBM; @@ -899,7 +900,7 @@ function widget_events() { * for exporting the cal is enabled (otherwise the widget would appear for logged in users * on foreigen profile pages even if the widget is disabled). */ - if (intval($owner_uid) && local_user() !== $owner_uid && ! feature_enabled($owner_uid, "export_calendar")) { + if (intval($owner_uid) && local_user() !== $owner_uid && ! Features::isEnabled($owner_uid, "export_calendar")) { return; } @@ -907,7 +908,7 @@ function widget_events() { * If it's a kind of profile page (intval($owner_uid)) return if the user not logged in and * export feature isn't enabled. */ - if (intval($owner_uid) && ! local_user() && ! feature_enabled($owner_uid, "export_calendar")) { + if (intval($owner_uid) && ! local_user() && ! Features::isEnabled($owner_uid, "export_calendar")) { return; } diff --git a/include/features.php b/include/features.php deleted file mode 100644 index e03dc4a5b..000000000 --- a/include/features.php +++ /dev/null @@ -1,144 +0,0 @@ - $uid, 'feature' => $feature, 'enabled' => $x); - call_hooks('feature_enabled',$arr); - return($arr['enabled']); -} - -/** - * @brief check if feature is enabled or disabled by default - * - * @param string $feature - * @return boolean - */ -function get_feature_default($feature) { - $f = get_features(); - foreach ($f as $cat) { - foreach ($cat as $feat) { - if (is_array($feat) && $feat[0] === $feature) - return $feat[3]; - } - } - return false; -} - -/** - * @brief Get a list of all available features - * - * The array includes the setting group, the setting name, - * explainations for the setting and if it's enabled or disabled - * by default - * - * @param bool $filtered True removes any locked features - * - * @return array - */ -function get_features($filtered = true) { - - $arr = array( - - // General - 'general' => array( - t('General Features'), - //array('expire', t('Content Expiration'), t('Remove old posts/comments after a period of time')), - array('multi_profiles', t('Multiple Profiles'), t('Ability to create multiple profiles'), false, Config::get('feature_lock','multi_profiles', false)), - array('photo_location', t('Photo Location'), t('Photo metadata is normally stripped. This extracts the location (if present) prior to stripping metadata and links it to a map.'), false, Config::get('feature_lock','photo_location', false)), - array('export_calendar', t('Export Public Calendar'), t('Ability for visitors to download the public calendar'), false, Config::get('feature_lock','export_calendar', false)), - ), - - // Post composition - 'composition' => array( - t('Post Composition Features'), - array('preview', t('Post Preview'), t('Allow previewing posts and comments before publishing them'), false, Config::get('feature_lock','preview', false)), - array('aclautomention', t('Auto-mention Forums'), t('Add/remove mention when a forum page is selected/deselected in ACL window.'), false, Config::get('feature_lock','aclautomention', false)), - ), - - // Network sidebar widgets - 'widgets' => array( - t('Network Sidebar Widgets'), - array('archives', t('Search by Date'), t('Ability to select posts by date ranges'), false, Config::get('feature_lock','archives', false)), - array('forumlist_widget', t('List Forums'), t('Enable widget to display the forums your are connected with'), true, Config::get('feature_lock','forumlist_widget', false)), - array('groups', t('Group Filter'), t('Enable widget to display Network posts only from selected group'), false, Config::get('feature_lock','groups', false)), - array('networks', t('Network Filter'), t('Enable widget to display Network posts only from selected network'), false, Config::get('feature_lock','networks', false)), - array('savedsearch', t('Saved Searches'), t('Save search terms for re-use'), false, Config::get('feature_lock','savedsearch', false)), - ), - - // Network tabs - 'net_tabs' => array( - t('Network Tabs'), - array('personal_tab', t('Network Personal Tab'), t('Enable tab to display only Network posts that you\'ve interacted on'), false, Config::get('feature_lock','personal_tab', false)), - array('new_tab', t('Network New Tab'), t('Enable tab to display only new Network posts (from the last 12 hours)'), false, Config::get('feature_lock','new_tab', false)), - array('link_tab', t('Network Shared Links Tab'), t('Enable tab to display only Network posts with links in them'), false, Config::get('feature_lock','link_tab', false)), - ), - - // Item tools - 'tools' => array( - t('Post/Comment Tools'), - array('multi_delete', t('Multiple Deletion'), t('Select and delete multiple posts/comments at once'), false, Config::get('feature_lock','multi_delete', false)), - array('edit_posts', t('Edit Sent Posts'), t('Edit and correct posts and comments after sending'), false, Config::get('feature_lock','edit_posts', false)), - array('commtag', t('Tagging'), t('Ability to tag existing posts'), false, Config::get('feature_lock','commtag', false)), - array('categories', t('Post Categories'), t('Add categories to your posts'), false, Config::get('feature_lock','categories', false)), - array('filing', t('Saved Folders'), t('Ability to file posts under folders'), false, Config::get('feature_lock','filing', false)), - array('dislike', t('Dislike Posts'), t('Ability to dislike posts/comments'), false, Config::get('feature_lock','dislike', false)), - array('star_posts', t('Star Posts'), t('Ability to mark special posts with a star indicator'), false, Config::get('feature_lock','star_posts', false)), - array('ignore_posts', t('Mute Post Notifications'), t('Ability to mute notifications for a thread'), false, Config::get('feature_lock','ignore_posts', false)), - ), - - // Advanced Profile Settings - 'advanced_profile' => array( - t('Advanced Profile Settings'), - array('forumlist_profile', t('List Forums'), t('Show visitors public community forums at the Advanced Profile Page'), false, Config::get('feature_lock','forumlist_profile', false)), - array('tagadelic', t('Tag Cloud'), t('Provide a personal tag cloud on your profile page'), false, Config::get('feature_lock', 'tagadelic', false)), - ), - ); - - // removed any locked features and remove the entire category if this makes it empty - - if ($filtered) { - foreach ($arr as $k => $x) { - $has_items = false; - $kquantity = count($arr[$k]); - for ($y = 0; $y < $kquantity; $y ++) { - if (is_array($arr[$k][$y])) { - if ($arr[$k][$y][4] === false) { - $has_items = true; - } else { - unset($arr[$k][$y]); - } - } - } - if (! $has_items) { - unset($arr[$k]); - } - } - } - - call_hooks('get_features',$arr); - return $arr; -} diff --git a/include/identity.php b/include/identity.php index 3066b7113..a12d28d1d 100644 --- a/include/identity.php +++ b/include/identity.php @@ -4,6 +4,7 @@ */ use Friendica\App; +use Friendica\Content\Features; use Friendica\Content\ForumManager; use Friendica\Core\Cache; use Friendica\Core\Config; @@ -309,7 +310,7 @@ function profile_sidebar($profile, $block = 0) } // show edit profile to yourself - if (!$is_contact && $profile['uid'] == local_user() && feature_enabled(local_user(), 'multi_profiles')) { + if (!$is_contact && $profile['uid'] == local_user() && Features::isEnabled(local_user(), 'multi_profiles')) { $profile['edit'] = array(System::baseUrl(). '/profiles', t('Profiles'),"", t('Manage/edit profiles')); $r = q( "SELECT * FROM `profile` WHERE `uid` = %d", @@ -336,7 +337,7 @@ function profile_sidebar($profile, $block = 0) } } } - if (!$is_contact && $profile['uid'] == local_user() && !feature_enabled(local_user(), 'multi_profiles')) { + if (!$is_contact && $profile['uid'] == local_user() && !Features::isEnabled(local_user(), 'multi_profiles')) { $profile['edit'] = array(System::baseUrl(). '/profiles/'.$profile['id'], t('Edit profile'),"", t('Edit profile')); $profile['menu'] = array( 'chg_photo' => t('Change profile photo'), @@ -790,7 +791,7 @@ function advanced_profile(App $a) } //show subcribed forum if it is enabled in the usersettings - if (feature_enabled($uid, 'forumlist_profile')) { + if (Features::isEnabled($uid, 'forumlist_profile')) { $profile['forumlist'] = array( t('Forums:'), ForumManager::profileAdvanced($uid)); } diff --git a/include/items.php b/include/items.php index 98149dea5..22df80907 100644 --- a/include/items.php +++ b/include/items.php @@ -4,6 +4,7 @@ */ use Friendica\App; use Friendica\ParseUrl; +use Friendica\Content\Features; use Friendica\Core\Config; use Friendica\Core\PConfig; use Friendica\Core\Worker; @@ -2355,7 +2356,7 @@ function posted_dates($uid, $wall) { function posted_date_widget($url, $uid, $wall) { $o = ''; - if (! feature_enabled($uid, 'archives')) { + if (! Features::isEnabled($uid, 'archives')) { return $o; } diff --git a/include/nav.php b/include/nav.php index 411f0ac5d..2de1a1560 100644 --- a/include/nav.php +++ b/include/nav.php @@ -1,6 +1,9 @@ profile['profile_uid'], 'tagadelic')) { + if(Features::isEnabled($a->profile['profile_uid'], 'tagadelic')) { $owner_id = Contact::getIdForURL($a->profile['url']); if(!$owner_id) { diff --git a/include/text.php b/include/text.php index 9a3d24bd1..b3f75370e 100644 --- a/include/text.php +++ b/include/text.php @@ -1,6 +1,9 @@ $url, '$search_label' => t('Search'), '$save_label' => t('Save'), - '$savedsearch' => feature_enabled(local_user(),'savedsearch'), + '$savedsearch' => Features::isEnabled(local_user(),'savedsearch'), '$search_hint' => t('@name, !forum, #tags, content'), ); diff --git a/mod/admin.php b/mod/admin.php index 1b6975ab8..16cc31c7b 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -1,11 +1,11 @@ $fdata) { foreach (array_slice($fdata, 1) as $f) { @@ -2336,7 +2336,7 @@ function admin_page_features(App $a) { if ((argc() > 1) && (argv(1) === 'features')) { $arr = array(); - $features = get_features(false); + $features = Features::get(false); foreach ($features as $fname => $fdata) { $arr[$fname] = array(); diff --git a/mod/cal.php b/mod/cal.php index 170e7ea4c..4ee2efd58 100644 --- a/mod/cal.php +++ b/mod/cal.php @@ -5,8 +5,8 @@ * This calendar is for profile visitors and contains only the events * of the profile owner */ - use Friendica\App; +use Friendica\Content\Features; use Friendica\Core\Config; use Friendica\Core\PConfig; use Friendica\Core\System; @@ -301,7 +301,7 @@ function cal_content(App $a) { // Test permissions // Respect the export feature setting for all other /cal pages if it's not the own profile - if( ((local_user() !== intval($owner_uid))) && ! feature_enabled($owner_uid, "export_calendar")) { + if( ((local_user() !== intval($owner_uid))) && ! Features::isEnabled($owner_uid, "export_calendar")) { notice( t('Permission denied.') . EOL); goaway('cal/' . $nick); } diff --git a/mod/editpost.php b/mod/editpost.php index 57c933904..9285a4604 100644 --- a/mod/editpost.php +++ b/mod/editpost.php @@ -1,6 +1,9 @@ htmlspecialchars($itm[0]['title']), '$placeholdertitle' => t('Set title'), '$category' => file_tag_file_to_list($itm[0]['file'], 'category'), - '$placeholdercategory' => (feature_enabled(local_user(),'categories') ? t('Categories (comma-separated list)') : ''), + '$placeholdercategory' => (Features::isEnabled(local_user(),'categories') ? t('Categories (comma-separated list)') : ''), '$emtitle' => t('Example: bob@example.com, mary@example.com'), '$lockstate' => $lockstate, '$acl' => '', // populate_acl((($group) ? $group_acl : $a->user)), diff --git a/mod/network.php b/mod/network.php index e74df1633..c0a3c29b1 100644 --- a/mod/network.php +++ b/mod/network.php @@ -3,6 +3,7 @@ * @file mod/network.php */ use Friendica\App; +use Friendica\Content\Features; use Friendica\Content\ForumManager; use Friendica\Core\System; use Friendica\Core\Config; @@ -156,8 +157,8 @@ function network_init(App $a) { $a->page['aside'] = ''; } - $a->page['aside'] .= (feature_enabled(local_user(),'groups') ? group_side('network/0','network','standard',$group_id) : ''); - $a->page['aside'] .= (feature_enabled(local_user(), 'forumlist_widget') ? ForumManager::widget(local_user(), $cid) : ''); + $a->page['aside'] .= (Features::isEnabled(local_user(),'groups') ? group_side('network/0','network','standard',$group_id) : ''); + $a->page['aside'] .= (Features::isEnabled(local_user(), 'forumlist_widget') ? ForumManager::widget(local_user(), $cid) : ''); $a->page['aside'] .= posted_date_widget('network',local_user(),false); $a->page['aside'] .= networks_widget('network',(x($_GET, 'nets') ? $_GET['nets'] : '')); $a->page['aside'] .= saved_searches($search); @@ -166,7 +167,7 @@ function network_init(App $a) { function saved_searches($search) { - if (!feature_enabled(local_user(),'savedsearch')) { + if (!Features::isEnabled(local_user(),'savedsearch')) { return ''; } @@ -918,7 +919,7 @@ function network_tabs(App $a) ), ); - if (feature_enabled(local_user(),'personal_tab')) { + if (Features::isEnabled(local_user(),'personal_tab')) { $tabs[] = array( 'label' => t('Personal'), 'url' => str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&conv=1', @@ -929,7 +930,7 @@ function network_tabs(App $a) ); } - if (feature_enabled(local_user(),'new_tab')) { + if (Features::isEnabled(local_user(),'new_tab')) { $tabs[] = array( 'label' => t('New'), 'url' => 'network/new' . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : ''), @@ -940,7 +941,7 @@ function network_tabs(App $a) ); } - if (feature_enabled(local_user(),'link_tab')) { + if (Features::isEnabled(local_user(),'link_tab')) { $tabs[] = array( 'label' => t('Shared Links'), 'url' => str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&bmark=1', @@ -951,7 +952,7 @@ function network_tabs(App $a) ); } - if (feature_enabled(local_user(),'star_posts')) { + if (Features::isEnabled(local_user(),'star_posts')) { $tabs[] = array( 'label' => t('Starred'), 'url' => str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&star=1', diff --git a/mod/photos.php b/mod/photos.php index 504f0ff14..a9ba835cf 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -3,6 +3,7 @@ * @file mod/photos.php */ use Friendica\App; +use Friendica\Content\Features; use Friendica\Core\System; use Friendica\Core\Config; use Friendica\Core\Worker; @@ -895,7 +896,7 @@ function photos_post(App $a) { /// @TODO merge these 2 if() into one? if ($exif && $exif['GPS']) { - if (feature_enabled($channel_id,'photo_location')) { + if (Features::isEnabled($channel_id,'photo_location')) { $lat = getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']); $lon = getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']); } @@ -1584,7 +1585,7 @@ function photos_content(App $a) { $likebuttons = replace_macros($like_tpl, array( '$id' => $link_item['id'], '$likethis' => t("I like this \x28toggle\x29"), - '$nolike' => (feature_enabled(local_user(), 'dislike') ? t("I don't like this \x28toggle\x29") : ''), + '$nolike' => (Features::isEnabled(local_user(), 'dislike') ? t("I don't like this \x28toggle\x29") : ''), '$wait' => t('Please wait'), '$return_path' => $a->query_string, )); @@ -1735,7 +1736,7 @@ function photos_content(App $a) { $response_verbs = array('like'); - if (feature_enabled($owner_uid, 'dislike')) { + if (Features::isEnabled($owner_uid, 'dislike')) { $response_verbs[] = 'dislike'; } $responses = get_responses($conv_responses,$response_verbs, '', $link_item); diff --git a/mod/ping.php b/mod/ping.php index 99d5777ea..4bb1ffe00 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -3,6 +3,7 @@ * @file include/ping.php */ use Friendica\App; +use Friendica\Content\Features; use Friendica\Content\ForumManager; use Friendica\Core\Cache; use Friendica\Core\System; @@ -149,7 +150,7 @@ function ping_init(App $a) } if ($network_count) { - if (intval(feature_enabled(local_user(), 'groups'))) { + if (intval(Features::isEnabled(local_user(), 'groups'))) { // Find out how unseen network posts are spread across groups $group_counts = groups_count_unseen(); if (DBM::is_result($group_counts)) { @@ -161,7 +162,7 @@ function ping_init(App $a) } } - if (intval(feature_enabled(local_user(), 'forumlist_widget'))) { + if (intval(Features::isEnabled(local_user(), 'forumlist_widget'))) { $forum_counts = ForumManager::countUnseenItems(); if (DBM::is_result($forums_counts)) { foreach ($forums_counts as $forum_count) { diff --git a/mod/profiles.php b/mod/profiles.php index 75023beb6..eb17f34db 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -3,6 +3,7 @@ * @file mod/profiles.php */ use Friendica\App; +use Friendica\Content\Features; use Friendica\Core\Config; use Friendica\Core\PConfig; use Friendica\Core\System; @@ -673,10 +674,10 @@ function profiles_content(App $a) { array(t('No'), t('Yes')) //Off - On strings ), - '$multi_profiles' => feature_enabled(local_user(), 'multi_profiles'), + '$multi_profiles' => Features::isEnabled(local_user(), 'multi_profiles'), '$form_security_token' => get_form_security_token("profile_edit"), '$form_security_token_photo' => get_form_security_token("profile_photo"), - '$profile_clone_link' => ((feature_enabled(local_user(), 'multi_profiles')) ? 'profiles/clone/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_clone") : ""), + '$profile_clone_link' => ((Features::isEnabled(local_user(), 'multi_profiles')) ? 'profiles/clone/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_clone") : ""), '$profile_drop_link' => 'profiles/drop/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_drop"), '$profile_action' => t('Profile Actions'), @@ -754,7 +755,7 @@ function profiles_content(App $a) { return $o; } else { // If we don't support multi profiles, don't display this list. - if (!feature_enabled(local_user(), 'multi_profiles')) { + if (!Features::isEnabled(local_user(), 'multi_profiles')) { $r = q("SELECT * FROM `profile` WHERE `uid` = %d AND `is-default`=1", local_user() ); diff --git a/mod/search.php b/mod/search.php index 984167fd7..3d9236055 100644 --- a/mod/search.php +++ b/mod/search.php @@ -1,20 +1,23 @@ t('Additional features'), 'url' => 'settings/features', @@ -784,12 +785,12 @@ function settings_content(App $a) { if (($a->argc > 1) && ($a->argv[1] === 'features')) { $arr = array(); - $features = get_features(); + $features = Features::get(); foreach ($features as $fname => $fdata) { $arr[$fname] = array(); $arr[$fname][0] = $fdata[0]; foreach (array_slice($fdata,1) as $f) { - $arr[$fname][1][] = array('feature_' .$f[0], $f[1],((intval(feature_enabled(local_user(), $f[0]))) ? "1" : ''), $f[2],array(t('Off'), t('On'))); + $arr[$fname][1][] = array('feature_' .$f[0], $f[1],((intval(Features::isEnabled(local_user(), $f[0]))) ? "1" : ''), $f[2],array(t('Off'), t('On'))); } } diff --git a/src/Content/Features.php b/src/Content/Features.php new file mode 100644 index 000000000..91216c91d --- /dev/null +++ b/src/Content/Features.php @@ -0,0 +1,148 @@ + $uid, 'feature' => $feature, 'enabled' => $x); + call_hooks('isEnabled',$arr); + return($arr['enabled']); + } + + /** + * @brief check if feature is enabled or disabled by default + * + * @param string $feature + * @return boolean + */ + private static function getDefault($feature) { + $f = self::get(); + foreach ($f as $cat) { + foreach ($cat as $feat) { + if (is_array($feat) && $feat[0] === $feature) + return $feat[3]; + } + } + return false; + } + + /** + * @brief Get a list of all available features + * + * The array includes the setting group, the setting name, + * explainations for the setting and if it's enabled or disabled + * by default + * + * @param bool $filtered True removes any locked features + * + * @return array + */ + public static function get($filtered = true) { + + $arr = array( + + // General + 'general' => array( + t('General Features'), + //array('expire', t('Content Expiration'), t('Remove old posts/comments after a period of time')), + array('multi_profiles', t('Multiple Profiles'), t('Ability to create multiple profiles'), false, Config::get('feature_lock','multi_profiles', false)), + array('photo_location', t('Photo Location'), t('Photo metadata is normally stripped. This extracts the location (if present) prior to stripping metadata and links it to a map.'), false, Config::get('feature_lock','photo_location', false)), + array('export_calendar', t('Export Public Calendar'), t('Ability for visitors to download the public calendar'), false, Config::get('feature_lock','export_calendar', false)), + ), + + // Post composition + 'composition' => array( + t('Post Composition Features'), + array('preview', t('Post Preview'), t('Allow previewing posts and comments before publishing them'), false, Config::get('feature_lock','preview', false)), + array('aclautomention', t('Auto-mention Forums'), t('Add/remove mention when a forum page is selected/deselected in ACL window.'), false, Config::get('feature_lock','aclautomention', false)), + ), + + // Network sidebar widgets + 'widgets' => array( + t('Network Sidebar Widgets'), + array('archives', t('Search by Date'), t('Ability to select posts by date ranges'), false, Config::get('feature_lock','archives', false)), + array('forumlist_widget', t('List Forums'), t('Enable widget to display the forums your are connected with'), true, Config::get('feature_lock','forumlist_widget', false)), + array('groups', t('Group Filter'), t('Enable widget to display Network posts only from selected group'), false, Config::get('feature_lock','groups', false)), + array('networks', t('Network Filter'), t('Enable widget to display Network posts only from selected network'), false, Config::get('feature_lock','networks', false)), + array('savedsearch', t('Saved Searches'), t('Save search terms for re-use'), false, Config::get('feature_lock','savedsearch', false)), + ), + + // Network tabs + 'net_tabs' => array( + t('Network Tabs'), + array('personal_tab', t('Network Personal Tab'), t('Enable tab to display only Network posts that you\'ve interacted on'), false, Config::get('feature_lock','personal_tab', false)), + array('new_tab', t('Network New Tab'), t('Enable tab to display only new Network posts (from the last 12 hours)'), false, Config::get('feature_lock','new_tab', false)), + array('link_tab', t('Network Shared Links Tab'), t('Enable tab to display only Network posts with links in them'), false, Config::get('feature_lock','link_tab', false)), + ), + + // Item tools + 'tools' => array( + t('Post/Comment Tools'), + array('multi_delete', t('Multiple Deletion'), t('Select and delete multiple posts/comments at once'), false, Config::get('feature_lock','multi_delete', false)), + array('edit_posts', t('Edit Sent Posts'), t('Edit and correct posts and comments after sending'), false, Config::get('feature_lock','edit_posts', false)), + array('commtag', t('Tagging'), t('Ability to tag existing posts'), false, Config::get('feature_lock','commtag', false)), + array('categories', t('Post Categories'), t('Add categories to your posts'), false, Config::get('feature_lock','categories', false)), + array('filing', t('Saved Folders'), t('Ability to file posts under folders'), false, Config::get('feature_lock','filing', false)), + array('dislike', t('Dislike Posts'), t('Ability to dislike posts/comments'), false, Config::get('feature_lock','dislike', false)), + array('star_posts', t('Star Posts'), t('Ability to mark special posts with a star indicator'), false, Config::get('feature_lock','star_posts', false)), + array('ignore_posts', t('Mute Post Notifications'), t('Ability to mute notifications for a thread'), false, Config::get('feature_lock','ignore_posts', false)), + ), + + // Advanced Profile Settings + 'advanced_profile' => array( + t('Advanced Profile Settings'), + array('forumlist_profile', t('List Forums'), t('Show visitors public community forums at the Advanced Profile Page'), false, Config::get('feature_lock','forumlist_profile', false)), + array('tagadelic', t('Tag Cloud'), t('Provide a personal tag cloud on your profile page'), false, Config::get('feature_lock', 'tagadelic', false)), + ), + ); + + // removed any locked features and remove the entire category if this makes it empty + + if ($filtered) { + foreach ($arr as $k => $x) { + $has_items = false; + $kquantity = count($arr[$k]); + for ($y = 0; $y < $kquantity; $y ++) { + if (is_array($arr[$k][$y])) { + if ($arr[$k][$y][4] === false) { + $has_items = true; + } else { + unset($arr[$k][$y]); + } + } + } + if (! $has_items) { + unset($arr[$k]); + } + } + } + + call_hooks('get',$arr); + return $arr; + } +} diff --git a/src/Content/ForumManager.php b/src/Content/ForumManager.php index e5d153f75..8df416e33 100644 --- a/src/Content/ForumManager.php +++ b/src/Content/ForumManager.php @@ -6,6 +6,7 @@ namespace Friendica\Content; use Friendica\App; +use Friendica\Content\Features; use Friendica\Core\System; use Friendica\Database\DBM; use dba; @@ -82,7 +83,7 @@ class ForumManager */ public static function widget($uid, $cid = 0) { - if (! intval(feature_enabled(local_user(), 'forumlist_widget'))) { + if (! intval(Features::isEnabled(local_user(), 'forumlist_widget'))) { return; } @@ -141,7 +142,7 @@ class ForumManager */ public static function profileAdvanced($uid) { - $profile = intval(feature_enabled($uid, 'forumlist_profile')); + $profile = intval(Features::isEnabled($uid, 'forumlist_profile')); if (! $profile) { return; } diff --git a/src/Object/Item.php b/src/Object/Item.php index cd05b91cf..d9a376a50 100644 --- a/src/Object/Item.php +++ b/src/Object/Item.php @@ -5,6 +5,7 @@ namespace Friendica\Object; use Friendica\BaseObject; +use Friendica\Content\Features; use Friendica\Core\Config; use Friendica\Core\PConfig; use Friendica\Database\DBM; @@ -161,7 +162,7 @@ class Item extends BaseObject $drop = array( 'dropping' => $dropping, - 'pagedrop' => ((feature_enabled($conv->getProfileOwner(), 'multi_delete')) ? $item['pagedrop'] : ''), + 'pagedrop' => ((Features::isEnabled($conv->getProfileOwner(), 'multi_delete')) ? $item['pagedrop'] : ''), 'select' => t('Select'), 'delete' => t('Delete'), ); @@ -279,7 +280,7 @@ class Item extends BaseObject } $tagger = ''; - if (feature_enabled($conv->getProfileOwner(), 'commtag')) { + if (Features::isEnabled($conv->getProfileOwner(), 'commtag')) { $tagger = array( 'add' => t("add tag"), 'class' => "", @@ -293,7 +294,7 @@ class Item extends BaseObject if ($conv->isWritable()) { $buttons = array( 'like' => array( t("I like this \x28toggle\x29"), t("like")), - 'dislike' => ((feature_enabled($conv->getProfileOwner(), 'dislike')) ? array( t("I don't like this \x28toggle\x29"), t("dislike")) : ''), + 'dislike' => ((Features::isEnabled($conv->getProfileOwner(), 'dislike')) ? array( t("I don't like this \x28toggle\x29"), t("dislike")) : ''), ); if ($shareable) { $buttons['share'] = array( t('Share this'), t('share')); @@ -378,12 +379,12 @@ class Item extends BaseObject 'owner_photo' => $a->remove_baseurl(proxy_url($item['owner-thumb'], false, PROXY_SIZE_THUMB)), 'owner_name' => htmlentities($owner_name_e), 'plink' => get_plink($item), - 'edpost' => ((feature_enabled($conv->getProfileOwner(), 'edit_posts')) ? $edpost : ''), + 'edpost' => ((Features::isEnabled($conv->getProfileOwner(), 'edit_posts')) ? $edpost : ''), 'isstarred' => $isstarred, - 'star' => ((feature_enabled($conv->getProfileOwner(), 'star_posts')) ? $star : ''), - 'ignore' => ((feature_enabled($conv->getProfileOwner(), 'ignore_posts')) ? $ignore : ''), + 'star' => ((Features::isEnabled($conv->getProfileOwner(), 'star_posts')) ? $star : ''), + 'ignore' => ((Features::isEnabled($conv->getProfileOwner(), 'ignore_posts')) ? $ignore : ''), 'tagger' => $tagger, - 'filer' => ((feature_enabled($conv->getProfileOwner(), 'filing')) ? $filer : ''), + 'filer' => ((Features::isEnabled($conv->getProfileOwner(), 'filing')) ? $filer : ''), 'drop' => $drop, 'vote' => $buttons, 'like' => $responses['like']['output'], @@ -791,7 +792,7 @@ class Item extends BaseObject '$edimg' => t('Image'), '$edurl' => t('Link'), '$edvideo' => t('Video'), - '$preview' => ((feature_enabled($conv->getProfileOwner(), 'preview')) ? t('Preview') : ''), + '$preview' => ((Features::isEnabled($conv->getProfileOwner(), 'preview')) ? t('Preview') : ''), '$indent' => $indent, '$sourceapp' => t($a->sourcename), '$ww' => (($conv->getMode() === 'network') ? $ww : ''), From 6e5471def3477e84473bc237e10c7c75c9e6e853 Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Mon, 4 Dec 2017 09:01:27 -0500 Subject: [PATCH 31/71] Rename to singular Rename and update references. Standards and a require_once. --- include/acl_selectors.php | 2 +- include/api.php | 2 +- include/contact_widgets.php | 6 +++--- include/conversation.php | 6 +++--- include/event.php | 4 ++-- include/identity.php | 6 +++--- include/items.php | 2 +- include/nav.php | 2 +- include/tags.php | 2 +- include/text.php | 2 +- mod/admin.php | 4 ++-- mod/cal.php | 2 +- mod/editpost.php | 2 +- mod/network.php | 14 +++++++------- mod/photos.php | 6 +++--- mod/ping.php | 4 ++-- mod/profiles.php | 6 +++--- mod/search.php | 2 +- mod/settings.php | 6 +++--- src/Content/{Features.php => Feature.php} | 15 +++++++++------ src/Content/ForumManager.php | 4 ++-- src/Object/Item.php | 16 ++++++++-------- 22 files changed, 59 insertions(+), 56 deletions(-) rename src/Content/{Features.php => Feature.php} (96%) diff --git a/include/acl_selectors.php b/include/acl_selectors.php index 50c733e34..7d7c3e1ae 100644 --- a/include/acl_selectors.php +++ b/include/acl_selectors.php @@ -377,7 +377,7 @@ function populate_acl($user = null, $show_jotnets = false) { '$aclModalTitle' => t('Permissions'), '$aclModalDismiss' => t('Close'), '$features' => array( - 'aclautomention' => (Features::isEnabled($user['uid'], "aclautomention") ? "true" : "false") + 'aclautomention' => (Feature::isEnabled($user['uid'], "aclautomention") ? "true" : "false") ), )); diff --git a/include/api.php b/include/api.php index 4055f2b4c..320a00d50 100644 --- a/include/api.php +++ b/include/api.php @@ -5101,7 +5101,7 @@ function api_friendica_profile_show($type) $profileid = (x($_REQUEST, 'profile_id') ? $_REQUEST['profile_id'] : 0); // retrieve general information about profiles for user - $multi_profiles = Features::isEnabled(api_user(), 'multi_profiles'); + $multi_profiles = Feature::isEnabled(api_user(), 'multi_profiles'); $directory = Config::get('system', 'directory'); // get data of the specified profile id or all profiles of the user if not specified diff --git a/include/contact_widgets.php b/include/contact_widgets.php index af63de767..0c5244579 100644 --- a/include/contact_widgets.php +++ b/include/contact_widgets.php @@ -108,7 +108,7 @@ function networks_widget($baseurl, $selected = '') { return ''; } - if (!Features::isEnabled(local_user(), 'networks')) { + if (!Feature::isEnabled(local_user(), 'networks')) { return ''; } @@ -147,7 +147,7 @@ function fileas_widget($baseurl, $selected = '') { return ''; } - if (! Features::isEnabled(local_user(), 'filing')) { + if (! Feature::isEnabled(local_user(), 'filing')) { return ''; } @@ -181,7 +181,7 @@ function categories_widget($baseurl, $selected = '') { $a = get_app(); - if (! Features::isEnabled($a->profile['profile_uid'], 'categories')) { + if (! Feature::isEnabled($a->profile['profile_uid'], 'categories')) { return ''; } diff --git a/include/conversation.php b/include/conversation.php index b32a98426..1fea1219e 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -916,7 +916,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { '$mode' => $mode, '$user' => $a->user, '$threads' => $threads, - '$dropping' => ($page_dropping && Features::isEnabled(local_user(), 'multi_delete') ? t('Delete Selected Items') : False), + '$dropping' => ($page_dropping && Feature::isEnabled(local_user(), 'multi_delete') ? t('Delete Selected Items') : False), )); return $o; @@ -1306,7 +1306,7 @@ function status_editor(App $a, $x, $notes_cid = 0, $popup = false) { '$title' => $x['title'], '$placeholdertitle' => t('Set title'), '$category' => $x['category'], - '$placeholdercategory' => (Features::isEnabled(local_user(), 'categories') ? t('Categories (comma-separated list)') : ''), + '$placeholdercategory' => (Feature::isEnabled(local_user(), 'categories') ? t('Categories (comma-separated list)') : ''), '$wait' => t('Please wait'), '$permset' => t('Permission settings'), '$shortpermset' => t('permissions'), @@ -1322,7 +1322,7 @@ function status_editor(App $a, $x, $notes_cid = 0, $popup = false) { '$lockstate' => $x['lockstate'], '$bang' => $x['bang'], '$profile_uid' => $x['profile_uid'], - '$preview' => ((Features::isEnabled($x['profile_uid'],'preview')) ? t('Preview') : ''), + '$preview' => ((Feature::isEnabled($x['profile_uid'],'preview')) ? t('Preview') : ''), '$jotplugins' => $jotplugins, '$notes_cid' => $notes_cid, '$sourceapp' => t($a->sourcename), diff --git a/include/event.php b/include/event.php index 07b90f249..ce974bd50 100644 --- a/include/event.php +++ b/include/event.php @@ -900,7 +900,7 @@ function widget_events() { * for exporting the cal is enabled (otherwise the widget would appear for logged in users * on foreigen profile pages even if the widget is disabled). */ - if (intval($owner_uid) && local_user() !== $owner_uid && ! Features::isEnabled($owner_uid, "export_calendar")) { + if (intval($owner_uid) && local_user() !== $owner_uid && ! Feature::isEnabled($owner_uid, "export_calendar")) { return; } @@ -908,7 +908,7 @@ function widget_events() { * If it's a kind of profile page (intval($owner_uid)) return if the user not logged in and * export feature isn't enabled. */ - if (intval($owner_uid) && ! local_user() && ! Features::isEnabled($owner_uid, "export_calendar")) { + if (intval($owner_uid) && ! local_user() && ! Feature::isEnabled($owner_uid, "export_calendar")) { return; } diff --git a/include/identity.php b/include/identity.php index a12d28d1d..68b6b4be1 100644 --- a/include/identity.php +++ b/include/identity.php @@ -310,7 +310,7 @@ function profile_sidebar($profile, $block = 0) } // show edit profile to yourself - if (!$is_contact && $profile['uid'] == local_user() && Features::isEnabled(local_user(), 'multi_profiles')) { + if (!$is_contact && $profile['uid'] == local_user() && Feature::isEnabled(local_user(), 'multi_profiles')) { $profile['edit'] = array(System::baseUrl(). '/profiles', t('Profiles'),"", t('Manage/edit profiles')); $r = q( "SELECT * FROM `profile` WHERE `uid` = %d", @@ -337,7 +337,7 @@ function profile_sidebar($profile, $block = 0) } } } - if (!$is_contact && $profile['uid'] == local_user() && !Features::isEnabled(local_user(), 'multi_profiles')) { + if (!$is_contact && $profile['uid'] == local_user() && !Feature::isEnabled(local_user(), 'multi_profiles')) { $profile['edit'] = array(System::baseUrl(). '/profiles/'.$profile['id'], t('Edit profile'),"", t('Edit profile')); $profile['menu'] = array( 'chg_photo' => t('Change profile photo'), @@ -791,7 +791,7 @@ function advanced_profile(App $a) } //show subcribed forum if it is enabled in the usersettings - if (Features::isEnabled($uid, 'forumlist_profile')) { + if (Feature::isEnabled($uid, 'forumlist_profile')) { $profile['forumlist'] = array( t('Forums:'), ForumManager::profileAdvanced($uid)); } diff --git a/include/items.php b/include/items.php index 22df80907..3e502aac5 100644 --- a/include/items.php +++ b/include/items.php @@ -2356,7 +2356,7 @@ function posted_dates($uid, $wall) { function posted_date_widget($url, $uid, $wall) { $o = ''; - if (! Features::isEnabled($uid, 'archives')) { + if (! Feature::isEnabled($uid, 'archives')) { return $o; } diff --git a/include/nav.php b/include/nav.php index 2de1a1560..60b8cb66c 100644 --- a/include/nav.php +++ b/include/nav.php @@ -193,7 +193,7 @@ function nav_info(App $a) $nav['settings'] = array('settings', t('Settings'), '', t('Account settings')); - if (Features::isEnabled(local_user(), 'multi_profiles')) { + if (Feature::isEnabled(local_user(), 'multi_profiles')) { $nav['profiles'] = array('profiles', t('Profiles'), '', t('Manage/Edit Profiles')); } diff --git a/include/tags.php b/include/tags.php index 145f10968..55168b624 100644 --- a/include/tags.php +++ b/include/tags.php @@ -305,7 +305,7 @@ function tagcloud_wall_widget($limit = 50) { return ""; } - if(Features::isEnabled($a->profile['profile_uid'], 'tagadelic')) { + if(Feature::isEnabled($a->profile['profile_uid'], 'tagadelic')) { $owner_id = Contact::getIdForURL($a->profile['url']); if(!$owner_id) { diff --git a/include/text.php b/include/text.php index b3f75370e..f5a47c9a9 100644 --- a/include/text.php +++ b/include/text.php @@ -1049,7 +1049,7 @@ function search($s, $id = 'search-box', $url = 'search', $save = false, $aside = '$action_url' => $url, '$search_label' => t('Search'), '$save_label' => t('Save'), - '$savedsearch' => Features::isEnabled(local_user(),'savedsearch'), + '$savedsearch' => Feature::isEnabled(local_user(),'savedsearch'), '$search_hint' => t('@name, !forum, #tags, content'), ); diff --git a/mod/admin.php b/mod/admin.php index 16cc31c7b..2e5ba8ba7 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -2291,7 +2291,7 @@ function admin_page_features_post(App $a) logger('postvars: ' . print_r($_POST, true), LOGGER_DATA); $arr = array(); - $features = Features::get(false); + $features = Feature::get(false); foreach ($features as $fname => $fdata) { foreach (array_slice($fdata, 1) as $f) { @@ -2336,7 +2336,7 @@ function admin_page_features(App $a) { if ((argc() > 1) && (argv(1) === 'features')) { $arr = array(); - $features = Features::get(false); + $features = Feature::get(false); foreach ($features as $fname => $fdata) { $arr[$fname] = array(); diff --git a/mod/cal.php b/mod/cal.php index 4ee2efd58..633fe5408 100644 --- a/mod/cal.php +++ b/mod/cal.php @@ -301,7 +301,7 @@ function cal_content(App $a) { // Test permissions // Respect the export feature setting for all other /cal pages if it's not the own profile - if( ((local_user() !== intval($owner_uid))) && ! Features::isEnabled($owner_uid, "export_calendar")) { + if( ((local_user() !== intval($owner_uid))) && ! Feature::isEnabled($owner_uid, "export_calendar")) { notice( t('Permission denied.') . EOL); goaway('cal/' . $nick); } diff --git a/mod/editpost.php b/mod/editpost.php index 9285a4604..a2e58239a 100644 --- a/mod/editpost.php +++ b/mod/editpost.php @@ -134,7 +134,7 @@ function editpost_content(App $a) { '$title' => htmlspecialchars($itm[0]['title']), '$placeholdertitle' => t('Set title'), '$category' => file_tag_file_to_list($itm[0]['file'], 'category'), - '$placeholdercategory' => (Features::isEnabled(local_user(),'categories') ? t('Categories (comma-separated list)') : ''), + '$placeholdercategory' => (Feature::isEnabled(local_user(),'categories') ? t('Categories (comma-separated list)') : ''), '$emtitle' => t('Example: bob@example.com, mary@example.com'), '$lockstate' => $lockstate, '$acl' => '', // populate_acl((($group) ? $group_acl : $a->user)), diff --git a/mod/network.php b/mod/network.php index c0a3c29b1..a320fafd3 100644 --- a/mod/network.php +++ b/mod/network.php @@ -157,8 +157,8 @@ function network_init(App $a) { $a->page['aside'] = ''; } - $a->page['aside'] .= (Features::isEnabled(local_user(),'groups') ? group_side('network/0','network','standard',$group_id) : ''); - $a->page['aside'] .= (Features::isEnabled(local_user(), 'forumlist_widget') ? ForumManager::widget(local_user(), $cid) : ''); + $a->page['aside'] .= (Feature::isEnabled(local_user(),'groups') ? group_side('network/0','network','standard',$group_id) : ''); + $a->page['aside'] .= (Feature::isEnabled(local_user(), 'forumlist_widget') ? ForumManager::widget(local_user(), $cid) : ''); $a->page['aside'] .= posted_date_widget('network',local_user(),false); $a->page['aside'] .= networks_widget('network',(x($_GET, 'nets') ? $_GET['nets'] : '')); $a->page['aside'] .= saved_searches($search); @@ -167,7 +167,7 @@ function network_init(App $a) { function saved_searches($search) { - if (!Features::isEnabled(local_user(),'savedsearch')) { + if (!Feature::isEnabled(local_user(),'savedsearch')) { return ''; } @@ -919,7 +919,7 @@ function network_tabs(App $a) ), ); - if (Features::isEnabled(local_user(),'personal_tab')) { + if (Feature::isEnabled(local_user(),'personal_tab')) { $tabs[] = array( 'label' => t('Personal'), 'url' => str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&conv=1', @@ -930,7 +930,7 @@ function network_tabs(App $a) ); } - if (Features::isEnabled(local_user(),'new_tab')) { + if (Feature::isEnabled(local_user(),'new_tab')) { $tabs[] = array( 'label' => t('New'), 'url' => 'network/new' . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : ''), @@ -941,7 +941,7 @@ function network_tabs(App $a) ); } - if (Features::isEnabled(local_user(),'link_tab')) { + if (Feature::isEnabled(local_user(),'link_tab')) { $tabs[] = array( 'label' => t('Shared Links'), 'url' => str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&bmark=1', @@ -952,7 +952,7 @@ function network_tabs(App $a) ); } - if (Features::isEnabled(local_user(),'star_posts')) { + if (Feature::isEnabled(local_user(),'star_posts')) { $tabs[] = array( 'label' => t('Starred'), 'url' => str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&star=1', diff --git a/mod/photos.php b/mod/photos.php index a9ba835cf..47227a1ce 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -896,7 +896,7 @@ function photos_post(App $a) { /// @TODO merge these 2 if() into one? if ($exif && $exif['GPS']) { - if (Features::isEnabled($channel_id,'photo_location')) { + if (Feature::isEnabled($channel_id,'photo_location')) { $lat = getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']); $lon = getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']); } @@ -1585,7 +1585,7 @@ function photos_content(App $a) { $likebuttons = replace_macros($like_tpl, array( '$id' => $link_item['id'], '$likethis' => t("I like this \x28toggle\x29"), - '$nolike' => (Features::isEnabled(local_user(), 'dislike') ? t("I don't like this \x28toggle\x29") : ''), + '$nolike' => (Feature::isEnabled(local_user(), 'dislike') ? t("I don't like this \x28toggle\x29") : ''), '$wait' => t('Please wait'), '$return_path' => $a->query_string, )); @@ -1736,7 +1736,7 @@ function photos_content(App $a) { $response_verbs = array('like'); - if (Features::isEnabled($owner_uid, 'dislike')) { + if (Feature::isEnabled($owner_uid, 'dislike')) { $response_verbs[] = 'dislike'; } $responses = get_responses($conv_responses,$response_verbs, '', $link_item); diff --git a/mod/ping.php b/mod/ping.php index 4bb1ffe00..3a5959c52 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -150,7 +150,7 @@ function ping_init(App $a) } if ($network_count) { - if (intval(Features::isEnabled(local_user(), 'groups'))) { + if (intval(Feature::isEnabled(local_user(), 'groups'))) { // Find out how unseen network posts are spread across groups $group_counts = groups_count_unseen(); if (DBM::is_result($group_counts)) { @@ -162,7 +162,7 @@ function ping_init(App $a) } } - if (intval(Features::isEnabled(local_user(), 'forumlist_widget'))) { + if (intval(Feature::isEnabled(local_user(), 'forumlist_widget'))) { $forum_counts = ForumManager::countUnseenItems(); if (DBM::is_result($forums_counts)) { foreach ($forums_counts as $forum_count) { diff --git a/mod/profiles.php b/mod/profiles.php index eb17f34db..7d8d0c3d1 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -674,10 +674,10 @@ function profiles_content(App $a) { array(t('No'), t('Yes')) //Off - On strings ), - '$multi_profiles' => Features::isEnabled(local_user(), 'multi_profiles'), + '$multi_profiles' => Feature::isEnabled(local_user(), 'multi_profiles'), '$form_security_token' => get_form_security_token("profile_edit"), '$form_security_token_photo' => get_form_security_token("profile_photo"), - '$profile_clone_link' => ((Features::isEnabled(local_user(), 'multi_profiles')) ? 'profiles/clone/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_clone") : ""), + '$profile_clone_link' => ((Feature::isEnabled(local_user(), 'multi_profiles')) ? 'profiles/clone/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_clone") : ""), '$profile_drop_link' => 'profiles/drop/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_drop"), '$profile_action' => t('Profile Actions'), @@ -755,7 +755,7 @@ function profiles_content(App $a) { return $o; } else { // If we don't support multi profiles, don't display this list. - if (!Features::isEnabled(local_user(), 'multi_profiles')) { + if (!Feature::isEnabled(local_user(), 'multi_profiles')) { $r = q("SELECT * FROM `profile` WHERE `uid` = %d AND `is-default`=1", local_user() ); diff --git a/mod/search.php b/mod/search.php index 3d9236055..900b9cba5 100644 --- a/mod/search.php +++ b/mod/search.php @@ -17,7 +17,7 @@ function search_saved_searches() { $o = ''; - if (! Features::isEnabled(local_user(),'savedsearch')) + if (! Feature::isEnabled(local_user(),'savedsearch')) return $o; $r = q("SELECT `id`,`term` FROM `search` WHERE `uid` = %d", diff --git a/mod/settings.php b/mod/settings.php index f81c76bdc..1fde749d8 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -53,7 +53,7 @@ function settings_init(App $a) { ), ); - if (Features::get()) { + if (Feature::get()) { $tabs[] = array( 'label' => t('Additional features'), 'url' => 'settings/features', @@ -785,12 +785,12 @@ function settings_content(App $a) { if (($a->argc > 1) && ($a->argv[1] === 'features')) { $arr = array(); - $features = Features::get(); + $features = Feature::get(); foreach ($features as $fname => $fdata) { $arr[$fname] = array(); $arr[$fname][0] = $fdata[0]; foreach (array_slice($fdata,1) as $f) { - $arr[$fname][1][] = array('feature_' .$f[0], $f[1],((intval(Features::isEnabled(local_user(), $f[0]))) ? "1" : ''), $f[2],array(t('Off'), t('On'))); + $arr[$fname][1][] = array('feature_' .$f[0], $f[1],((intval(Feature::isEnabled(local_user(), $f[0]))) ? "1" : ''), $f[2],array(t('Off'), t('On'))); } } diff --git a/src/Content/Features.php b/src/Content/Feature.php similarity index 96% rename from src/Content/Features.php rename to src/Content/Feature.php index 91216c91d..12515387b 100644 --- a/src/Content/Features.php +++ b/src/Content/Feature.php @@ -1,6 +1,6 @@ $dropping, - 'pagedrop' => ((Features::isEnabled($conv->getProfileOwner(), 'multi_delete')) ? $item['pagedrop'] : ''), + 'pagedrop' => ((Feature::isEnabled($conv->getProfileOwner(), 'multi_delete')) ? $item['pagedrop'] : ''), 'select' => t('Select'), 'delete' => t('Delete'), ); @@ -280,7 +280,7 @@ class Item extends BaseObject } $tagger = ''; - if (Features::isEnabled($conv->getProfileOwner(), 'commtag')) { + if (Feature::isEnabled($conv->getProfileOwner(), 'commtag')) { $tagger = array( 'add' => t("add tag"), 'class' => "", @@ -294,7 +294,7 @@ class Item extends BaseObject if ($conv->isWritable()) { $buttons = array( 'like' => array( t("I like this \x28toggle\x29"), t("like")), - 'dislike' => ((Features::isEnabled($conv->getProfileOwner(), 'dislike')) ? array( t("I don't like this \x28toggle\x29"), t("dislike")) : ''), + 'dislike' => ((Feature::isEnabled($conv->getProfileOwner(), 'dislike')) ? array( t("I don't like this \x28toggle\x29"), t("dislike")) : ''), ); if ($shareable) { $buttons['share'] = array( t('Share this'), t('share')); @@ -379,12 +379,12 @@ class Item extends BaseObject 'owner_photo' => $a->remove_baseurl(proxy_url($item['owner-thumb'], false, PROXY_SIZE_THUMB)), 'owner_name' => htmlentities($owner_name_e), 'plink' => get_plink($item), - 'edpost' => ((Features::isEnabled($conv->getProfileOwner(), 'edit_posts')) ? $edpost : ''), + 'edpost' => ((Feature::isEnabled($conv->getProfileOwner(), 'edit_posts')) ? $edpost : ''), 'isstarred' => $isstarred, - 'star' => ((Features::isEnabled($conv->getProfileOwner(), 'star_posts')) ? $star : ''), - 'ignore' => ((Features::isEnabled($conv->getProfileOwner(), 'ignore_posts')) ? $ignore : ''), + 'star' => ((Feature::isEnabled($conv->getProfileOwner(), 'star_posts')) ? $star : ''), + 'ignore' => ((Feature::isEnabled($conv->getProfileOwner(), 'ignore_posts')) ? $ignore : ''), 'tagger' => $tagger, - 'filer' => ((Features::isEnabled($conv->getProfileOwner(), 'filing')) ? $filer : ''), + 'filer' => ((Feature::isEnabled($conv->getProfileOwner(), 'filing')) ? $filer : ''), 'drop' => $drop, 'vote' => $buttons, 'like' => $responses['like']['output'], @@ -792,7 +792,7 @@ class Item extends BaseObject '$edimg' => t('Image'), '$edurl' => t('Link'), '$edvideo' => t('Video'), - '$preview' => ((Features::isEnabled($conv->getProfileOwner(), 'preview')) ? t('Preview') : ''), + '$preview' => ((Feature::isEnabled($conv->getProfileOwner(), 'preview')) ? t('Preview') : ''), '$indent' => $indent, '$sourceapp' => t($a->sourcename), '$ww' => (($conv->getMode() === 'network') ? $ww : ''), From b1d16fbdf7db1ec67179ad3f3869af4d16e0a38d Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Mon, 4 Dec 2017 09:04:36 -0500 Subject: [PATCH 32/71] Update use statements update use statements for rename to singular. --- include/acl_selectors.php | 2 +- include/api.php | 2 +- include/contact_widgets.php | 2 +- include/conversation.php | 2 +- include/event.php | 2 +- include/identity.php | 2 +- include/items.php | 2 +- include/nav.php | 2 +- include/tags.php | 2 +- include/text.php | 2 +- mod/admin.php | 2 +- mod/cal.php | 2 +- mod/editpost.php | 2 +- mod/network.php | 2 +- mod/photos.php | 2 +- mod/ping.php | 2 +- mod/profiles.php | 2 +- mod/search.php | 2 +- mod/settings.php | 2 +- src/Content/ForumManager.php | 2 +- src/Object/Item.php | 2 +- 21 files changed, 21 insertions(+), 21 deletions(-) diff --git a/include/acl_selectors.php b/include/acl_selectors.php index 7d7c3e1ae..f971d462b 100644 --- a/include/acl_selectors.php +++ b/include/acl_selectors.php @@ -3,7 +3,7 @@ * @file include/acl_selectors.php */ use Friendica\App; -use Friendica\Content\Features; +use Friendica\Content\Feature; use Friendica\Core\Config; use Friendica\Database\DBM; use Friendica\Model\GlobalContact; diff --git a/include/api.php b/include/api.php index 320a00d50..ea804b18b 100644 --- a/include/api.php +++ b/include/api.php @@ -6,7 +6,7 @@ * @todo Automatically detect if incoming data is HTML or BBCode */ use Friendica\App; -use Friendica\Content\Features; +use Friendica\Content\Feature; use Friendica\Core\System; use Friendica\Core\Config; use Friendica\Core\NotificationsManager; diff --git a/include/contact_widgets.php b/include/contact_widgets.php index 0c5244579..31e57ea83 100644 --- a/include/contact_widgets.php +++ b/include/contact_widgets.php @@ -2,7 +2,7 @@ /** * @file include/contact_widgets.php */ -use Friendica\Content\Features; +use Friendica\Content\Feature; use Friendica\Core\System; use Friendica\Core\Config; use Friendica\Core\PConfig; diff --git a/include/conversation.php b/include/conversation.php index 1fea1219e..4b9459a3f 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -3,7 +3,7 @@ * @file include/conversation.php */ use Friendica\App; -use Friendica\Content\Features; +use Friendica\Content\Feature; use Friendica\Core\Config; use Friendica\Core\PConfig; use Friendica\Core\System; diff --git a/include/event.php b/include/event.php index ce974bd50..4795867b1 100644 --- a/include/event.php +++ b/include/event.php @@ -5,7 +5,7 @@ */ use Friendica\App; -use Friendica\Content\Features; +use Friendica\Content\Feature; use Friendica\Core\PConfig; use Friendica\Core\System; use Friendica\Database\DBM; diff --git a/include/identity.php b/include/identity.php index 68b6b4be1..a3a007cc1 100644 --- a/include/identity.php +++ b/include/identity.php @@ -4,7 +4,7 @@ */ use Friendica\App; -use Friendica\Content\Features; +use Friendica\Content\Feature; use Friendica\Content\ForumManager; use Friendica\Core\Cache; use Friendica\Core\Config; diff --git a/include/items.php b/include/items.php index 3e502aac5..cbc7af565 100644 --- a/include/items.php +++ b/include/items.php @@ -4,7 +4,7 @@ */ use Friendica\App; use Friendica\ParseUrl; -use Friendica\Content\Features; +use Friendica\Content\Feature; use Friendica\Core\Config; use Friendica\Core\PConfig; use Friendica\Core\Worker; diff --git a/include/nav.php b/include/nav.php index 60b8cb66c..f2bf161f9 100644 --- a/include/nav.php +++ b/include/nav.php @@ -3,7 +3,7 @@ * @file include/nav.php */ use Friendica\App; -use Friendica\Content\Features; +use Friendica\Content\Feature; use Friendica\Core\Config; use Friendica\Core\System; use Friendica\Database\DBM; diff --git a/include/tags.php b/include/tags.php index 55168b624..45a17f9c9 100644 --- a/include/tags.php +++ b/include/tags.php @@ -3,7 +3,7 @@ * @file include/tags.php */ use Friendica\App; -use Friendica\Content\Features; +use Friendica\Content\Feature; use Friendica\Core\System; use Friendica\Database\DBM; use Friendica\Object\Contact; diff --git a/include/text.php b/include/text.php index f5a47c9a9..b2e0ac30d 100644 --- a/include/text.php +++ b/include/text.php @@ -3,7 +3,7 @@ * @file include/text.php */ use Friendica\App; -use Friendica\Content\Features; +use Friendica\Content\Feature; use Friendica\Content\Smilies; use Friendica\Core\Config; use Friendica\Core\PConfig; diff --git a/mod/admin.php b/mod/admin.php index 2e5ba8ba7..29e10bda8 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -5,7 +5,7 @@ * @brief Friendica admin */ use Friendica\App; -use Friendica\Content\Features; +use Friendica\Content\Feature; use Friendica\Core\System; use Friendica\Core\Config; use Friendica\Core\Worker; diff --git a/mod/cal.php b/mod/cal.php index 633fe5408..7eb31905b 100644 --- a/mod/cal.php +++ b/mod/cal.php @@ -6,7 +6,7 @@ * of the profile owner */ use Friendica\App; -use Friendica\Content\Features; +use Friendica\Content\Feature; use Friendica\Core\Config; use Friendica\Core\PConfig; use Friendica\Core\System; diff --git a/mod/editpost.php b/mod/editpost.php index a2e58239a..a9cdfe9bb 100644 --- a/mod/editpost.php +++ b/mod/editpost.php @@ -3,7 +3,7 @@ * @file mod/editpost.php */ use Friendica\App; -use Friendica\Content\Features; +use Friendica\Content\Feature; use Friendica\Core\Config; use Friendica\Core\System; use Friendica\Database\DBM; diff --git a/mod/network.php b/mod/network.php index a320fafd3..7e61d083f 100644 --- a/mod/network.php +++ b/mod/network.php @@ -3,7 +3,7 @@ * @file mod/network.php */ use Friendica\App; -use Friendica\Content\Features; +use Friendica\Content\Feature; use Friendica\Content\ForumManager; use Friendica\Core\System; use Friendica\Core\Config; diff --git a/mod/photos.php b/mod/photos.php index 47227a1ce..3e2c44e3c 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -3,7 +3,7 @@ * @file mod/photos.php */ use Friendica\App; -use Friendica\Content\Features; +use Friendica\Content\Feature; use Friendica\Core\System; use Friendica\Core\Config; use Friendica\Core\Worker; diff --git a/mod/ping.php b/mod/ping.php index 3a5959c52..0f2a9584b 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -3,7 +3,7 @@ * @file include/ping.php */ use Friendica\App; -use Friendica\Content\Features; +use Friendica\Content\Feature; use Friendica\Content\ForumManager; use Friendica\Core\Cache; use Friendica\Core\System; diff --git a/mod/profiles.php b/mod/profiles.php index 7d8d0c3d1..eca13bf10 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -3,7 +3,7 @@ * @file mod/profiles.php */ use Friendica\App; -use Friendica\Content\Features; +use Friendica\Content\Feature; use Friendica\Core\Config; use Friendica\Core\PConfig; use Friendica\Core\System; diff --git a/mod/search.php b/mod/search.php index 900b9cba5..c17b11c5d 100644 --- a/mod/search.php +++ b/mod/search.php @@ -3,7 +3,7 @@ * @file mod/search.php */ use Friendica\App; -use Friendica\Content\Features; +use Friendica\Content\Feature; use Friendica\Core\Cache; use Friendica\Core\Config; use Friendica\Database\DBM; diff --git a/mod/settings.php b/mod/settings.php index 1fde749d8..778a1d8a7 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -3,7 +3,7 @@ * @file mod/settings.php */ use Friendica\App; -use Friendica\Content\Features; +use Friendica\Content\Feature; use Friendica\Core\System; use Friendica\Core\Worker; use Friendica\Core\Config; diff --git a/src/Content/ForumManager.php b/src/Content/ForumManager.php index fb64aed6f..d619db42b 100644 --- a/src/Content/ForumManager.php +++ b/src/Content/ForumManager.php @@ -6,7 +6,7 @@ namespace Friendica\Content; use Friendica\App; -use Friendica\Content\Features; +use Friendica\Content\Feature; use Friendica\Core\System; use Friendica\Database\DBM; use dba; diff --git a/src/Object/Item.php b/src/Object/Item.php index 597982165..1533908ae 100644 --- a/src/Object/Item.php +++ b/src/Object/Item.php @@ -5,7 +5,7 @@ namespace Friendica\Object; use Friendica\BaseObject; -use Friendica\Content\Features; +use Friendica\Content\Feature; use Friendica\Core\Config; use Friendica\Core\PConfig; use Friendica\Database\DBM; From 4af9616b178aabbb7383bc150c41f6ec36afbaf2 Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Mon, 4 Dec 2017 09:16:15 -0500 Subject: [PATCH 33/71] Standards Standards clean up. --- src/Content/Feature.php | 53 ++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/src/Content/Feature.php b/src/Content/Feature.php index 12515387b..864c07a0d 100644 --- a/src/Content/Feature.php +++ b/src/Content/Feature.php @@ -15,6 +15,8 @@ class Feature /** * @brief check if feature is enabled * + * @param integer $uid user id + * @param string $feature feature * @return boolean */ public static function isEnabled($uid, $feature) @@ -32,14 +34,14 @@ class Feature } $arr = array('uid' => $uid, 'feature' => $feature, 'enabled' => $x); - call_hooks('isEnabled',$arr); + call_hooks('isEnabled', $arr); return($arr['enabled']); } /** * @brief check if feature is enabled or disabled by default * - * @param string $feature + * @param string $feature feature * @return boolean */ private static function getDefault($feature) @@ -47,8 +49,9 @@ class Feature $f = self::get(); foreach ($f as $cat) { foreach ($cat as $feat) { - if (is_array($feat) && $feat[0] === $feature) + if (is_array($feat) && $feat[0] === $feature) { return $feat[3]; + } } } return false; @@ -73,53 +76,53 @@ class Feature 'general' => array( t('General Features'), //array('expire', t('Content Expiration'), t('Remove old posts/comments after a period of time')), - array('multi_profiles', t('Multiple Profiles'), t('Ability to create multiple profiles'), false, Config::get('feature_lock','multi_profiles', false)), - array('photo_location', t('Photo Location'), t('Photo metadata is normally stripped. This extracts the location (if present) prior to stripping metadata and links it to a map.'), false, Config::get('feature_lock','photo_location', false)), - array('export_calendar', t('Export Public Calendar'), t('Ability for visitors to download the public calendar'), false, Config::get('feature_lock','export_calendar', false)), + array('multi_profiles', t('Multiple Profiles'), t('Ability to create multiple profiles'), false, Config::get('feature_lock', 'multi_profiles', false)), + array('photo_location', t('Photo Location'), t('Photo metadata is normally stripped. This extracts the location (if present) prior to stripping metadata and links it to a map.'), false, Config::get('feature_lock', 'photo_location', false)), + array('export_calendar', t('Export Public Calendar'), t('Ability for visitors to download the public calendar'), false, Config::get('feature_lock', 'export_calendar', false)), ), // Post composition 'composition' => array( t('Post Composition Features'), - array('preview', t('Post Preview'), t('Allow previewing posts and comments before publishing them'), false, Config::get('feature_lock','preview', false)), - array('aclautomention', t('Auto-mention Forums'), t('Add/remove mention when a forum page is selected/deselected in ACL window.'), false, Config::get('feature_lock','aclautomention', false)), + array('preview', t('Post Preview'), t('Allow previewing posts and comments before publishing them'), false, Config::get('feature_lock', 'preview', false)), + array('aclautomention', t('Auto-mention Forums'), t('Add/remove mention when a forum page is selected/deselected in ACL window.'), false, Config::get('feature_lock', 'aclautomention', false)), ), // Network sidebar widgets 'widgets' => array( t('Network Sidebar Widgets'), - array('archives', t('Search by Date'), t('Ability to select posts by date ranges'), false, Config::get('feature_lock','archives', false)), - array('forumlist_widget', t('List Forums'), t('Enable widget to display the forums your are connected with'), true, Config::get('feature_lock','forumlist_widget', false)), - array('groups', t('Group Filter'), t('Enable widget to display Network posts only from selected group'), false, Config::get('feature_lock','groups', false)), - array('networks', t('Network Filter'), t('Enable widget to display Network posts only from selected network'), false, Config::get('feature_lock','networks', false)), - array('savedsearch', t('Saved Searches'), t('Save search terms for re-use'), false, Config::get('feature_lock','savedsearch', false)), + array('archives', t('Search by Date'), t('Ability to select posts by date ranges'), false, Config::get('feature_lock', 'archives', false)), + array('forumlist_widget', t('List Forums'), t('Enable widget to display the forums your are connected with'), true, Config::get('feature_lock', 'forumlist_widget', false)), + array('groups', t('Group Filter'), t('Enable widget to display Network posts only from selected group'), false, Config::get('feature_lock', 'groups', false)), + array('networks', t('Network Filter'), t('Enable widget to display Network posts only from selected network'), false, Config::get('feature_lock', 'networks', false)), + array('savedsearch', t('Saved Searches'), t('Save search terms for re-use'), false, Config::get('feature_lock', 'savedsearch', false)), ), // Network tabs 'net_tabs' => array( t('Network Tabs'), - array('personal_tab', t('Network Personal Tab'), t('Enable tab to display only Network posts that you\'ve interacted on'), false, Config::get('feature_lock','personal_tab', false)), - array('new_tab', t('Network New Tab'), t('Enable tab to display only new Network posts (from the last 12 hours)'), false, Config::get('feature_lock','new_tab', false)), - array('link_tab', t('Network Shared Links Tab'), t('Enable tab to display only Network posts with links in them'), false, Config::get('feature_lock','link_tab', false)), + array('personal_tab', t('Network Personal Tab'), t('Enable tab to display only Network posts that you\'ve interacted on'), false, Config::get('feature_lock', 'personal_tab', false)), + array('new_tab', t('Network New Tab'), t('Enable tab to display only new Network posts (from the last 12 hours)'), false, Config::get('feature_lock', 'new_tab', false)), + array('link_tab', t('Network Shared Links Tab'), t('Enable tab to display only Network posts with links in them'), false, Config::get('feature_lock', 'link_tab', false)), ), // Item tools 'tools' => array( t('Post/Comment Tools'), - array('multi_delete', t('Multiple Deletion'), t('Select and delete multiple posts/comments at once'), false, Config::get('feature_lock','multi_delete', false)), - array('edit_posts', t('Edit Sent Posts'), t('Edit and correct posts and comments after sending'), false, Config::get('feature_lock','edit_posts', false)), - array('commtag', t('Tagging'), t('Ability to tag existing posts'), false, Config::get('feature_lock','commtag', false)), - array('categories', t('Post Categories'), t('Add categories to your posts'), false, Config::get('feature_lock','categories', false)), - array('filing', t('Saved Folders'), t('Ability to file posts under folders'), false, Config::get('feature_lock','filing', false)), - array('dislike', t('Dislike Posts'), t('Ability to dislike posts/comments'), false, Config::get('feature_lock','dislike', false)), - array('star_posts', t('Star Posts'), t('Ability to mark special posts with a star indicator'), false, Config::get('feature_lock','star_posts', false)), - array('ignore_posts', t('Mute Post Notifications'), t('Ability to mute notifications for a thread'), false, Config::get('feature_lock','ignore_posts', false)), + array('multi_delete', t('Multiple Deletion'), t('Select and delete multiple posts/comments at once'), false, Config::get('feature_lock', 'multi_delete', false)), + array('edit_posts', t('Edit Sent Posts'), t('Edit and correct posts and comments after sending'), false, Config::get('feature_lock', 'edit_posts', false)), + array('commtag', t('Tagging'), t('Ability to tag existing posts'), false, Config::get('feature_lock', 'commtag', false)), + array('categories', t('Post Categories'), t('Add categories to your posts'), false, Config::get('feature_lock', 'categories', false)), + array('filing', t('Saved Folders'), t('Ability to file posts under folders'), false, Config::get('feature_lock', 'filing', false)), + array('dislike', t('Dislike Posts'), t('Ability to dislike posts/comments'), false, Config::get('feature_lock', 'dislike', false)), + array('star_posts', t('Star Posts'), t('Ability to mark special posts with a star indicator'), false, Config::get('feature_lock', 'star_posts', false)), + array('ignore_posts', t('Mute Post Notifications'), t('Ability to mute notifications for a thread'), false, Config::get('feature_lock', 'ignore_posts', false)), ), // Advanced Profile Settings 'advanced_profile' => array( t('Advanced Profile Settings'), - array('forumlist_profile', t('List Forums'), t('Show visitors public community forums at the Advanced Profile Page'), false, Config::get('feature_lock','forumlist_profile', false)), + array('forumlist_profile', t('List Forums'), t('Show visitors public community forums at the Advanced Profile Page'), false, Config::get('feature_lock', 'forumlist_profile', false)), array('tagadelic', t('Tag Cloud'), t('Provide a personal tag cloud on your profile page'), false, Config::get('feature_lock', 'tagadelic', false)), ), ); From 4a96f7b45892da9f2a972d05ecfb3a421644d6ec Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Mon, 4 Dec 2017 13:12:22 -0500 Subject: [PATCH 34/71] Pidfile to src Move pidfile to Friendica\Util namespace --- include/pidfile.php | 40 ------------------------ src/Util/Pidfile.php | 72 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 40 deletions(-) delete mode 100644 include/pidfile.php create mode 100644 src/Util/Pidfile.php diff --git a/include/pidfile.php b/include/pidfile.php deleted file mode 100644 index 7157a6e59..000000000 --- a/include/pidfile.php +++ /dev/null @@ -1,40 +0,0 @@ -_file = "$dir/$name.pid"; - - if (file_exists($this->_file)) { - $pid = trim(@file_get_contents($this->_file)); - if (($pid != "") && posix_kill($pid, 0)) { - $this->_running = true; - } - } - - if (! $this->_running) { - $pid = getmypid(); - file_put_contents($this->_file, $pid); - } - } - - public function __destruct() { - if ((! $this->_running) && file_exists($this->_file)) { - @unlink($this->_file); - } - } - - public function is_already_running() { - return $this->_running; - } - - public function running_time() { - return(time() - @filectime($this->_file)); - } - - public function kill() { - if (file_exists($this->_file)) - return(posix_kill(file_get_contents($this->_file), SIGTERM)); - } -} diff --git a/src/Util/Pidfile.php b/src/Util/Pidfile.php new file mode 100644 index 000000000..a5d1171e7 --- /dev/null +++ b/src/Util/Pidfile.php @@ -0,0 +1,72 @@ +_file = "$dir/$name.pid"; + + if (file_exists($this->_file)) { + $pid = trim(@file_get_contents($this->file)); + if (($pid != "") && posix_kill($pid, 0)) { + $this->running = true; + } + } + + if (! $this->running) { + $pid = getmypid(); + file_put_contents($this->file, $pid); + } + } + + /** + * @return void + */ + public function __destruct() + { + if ((! $this->running) && file_exists($this->file)) { + @unlink($this->file); + } + } + + /** + * @return boolean + */ + public static function isRunning() + { + return self::$running; + } + + /** + * @return object + */ + public static function runningTime() + { + return time() - @filectime(self::$file); + } + + /** + * @return boolean + */ + public static function kill() + { + if (file_exists(self::$file)) { + return posix_kill(file_get_contents(self::$file), SIGTERM); + } + } +} From ca41e9154d147317ab315cdac8592fb1a1ffae66 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 4 Dec 2017 19:04:50 +0000 Subject: [PATCH 35/71] Archive and unarchive contacts --- include/items.php | 4 ++++ src/Object/Contact.php | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/items.php b/include/items.php index 98149dea5..73a5ad9cc 100644 --- a/include/items.php +++ b/include/items.php @@ -1165,6 +1165,10 @@ function item_set_last_item($arr) { if ($update) { dba::update('contact', array('success_update' => $arr['received'], 'last-item' => $arr['received']), array('id' => $arr['contact-id'])); + $contact = dba::select('contact', [], ['id' => $arr['contact-id']], ['limit' => 1]); + if ($contact['term-date'] > NULL_DATE) { + Contact::unmarkForArchival($contact); + } } // Now do the same for the system wide contacts with uid=0 if (!$arr['private']) { diff --git a/src/Object/Contact.php b/src/Object/Contact.php index 34519401c..56204395c 100644 --- a/src/Object/Contact.php +++ b/src/Object/Contact.php @@ -99,7 +99,7 @@ class Contact extends BaseObject if ($contact['archive']) { return; } - +logger('Blubb-m: '.$contact['id'].' - '.System::callstack()); if ($contact['term-date'] <= NULL_DATE) { dba::update('contact', array('term-date' => datetime_convert()), array('id' => $contact['id'])); @@ -139,6 +139,7 @@ class Contact extends BaseObject */ public static function unmarkForArchival(array $contact) { +//logger('Blubb-m: '.$contact['id'].' - '.System::callstack()); $condition = array('`id` = ? AND (`term-date` > ? OR `archive`)', $contact[`id`], NULL_DATE); $exists = dba::exists('contact', $condition); From b991d8ff77b2837cc17f83c3f682c57c4a1043f6 Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Mon, 4 Dec 2017 14:09:23 -0500 Subject: [PATCH 36/71] Separate and move classes OAuth to src --- include/oauth.php | 184 ------------------------------ src/Protocol/FKOAuth1.php | 77 +++++++++++++ src/Protocol/FKOAuthDataStore.php | 150 ++++++++++++++++++++++++ 3 files changed, 227 insertions(+), 184 deletions(-) delete mode 100644 include/oauth.php create mode 100644 src/Protocol/FKOAuth1.php create mode 100644 src/Protocol/FKOAuthDataStore.php diff --git a/include/oauth.php b/include/oauth.php deleted file mode 100644 index 8834b9355..000000000 --- a/include/oauth.php +++ /dev/null @@ -1,184 +0,0 @@ - - * - */ - -use Friendica\App; -use Friendica\Core\Config; -use Friendica\Core\PConfig; -use Friendica\Core\System; -use Friendica\Database\DBM; - -define('REQUEST_TOKEN_DURATION', 300); -define('ACCESS_TOKEN_DURATION', 31536000); - -require_once("library/OAuth1.php"); -require_once("library/oauth2-php/lib/OAuth2.inc"); - -class FKOAuthDataStore extends OAuthDataStore { - function gen_token(){ - return md5(base64_encode(pack('N6', mt_rand(), mt_rand(), mt_rand(), mt_rand(), mt_rand(), uniqid()))); - } - - function lookup_consumer($consumer_key) { - logger(__function__.":".$consumer_key); - //echo "
    "; var_dump($consumer_key); killme();
    -
    -		$r = q("SELECT client_id, pw, redirect_uri FROM clients WHERE client_id='%s'",
    -			dbesc($consumer_key)
    -		);
    -		if (DBM::is_result($r))
    -			return new OAuthConsumer($r[0]['client_id'],$r[0]['pw'],$r[0]['redirect_uri']);
    -		return null;
    -  }
    -
    -  function lookup_token($consumer, $token_type, $token) {
    -		logger(__function__.":".$consumer.", ". $token_type.", ".$token);
    -		$r = q("SELECT id, secret,scope, expires, uid  FROM tokens WHERE client_id='%s' AND scope='%s' AND id='%s'",
    -			dbesc($consumer->key),
    -			dbesc($token_type),
    -			dbesc($token)
    -		);
    -		if (DBM::is_result($r)){
    -			$ot=new OAuthToken($r[0]['id'],$r[0]['secret']);
    -			$ot->scope=$r[0]['scope'];
    -			$ot->expires = $r[0]['expires'];
    -			$ot->uid = $r[0]['uid'];
    -			return $ot;
    -		}
    -		return null;
    -  }
    -
    -  function lookup_nonce($consumer, $token, $nonce, $timestamp) {
    -		//echo __file__.":".__line__."
    "; var_dump($consumer,$key); killme();
    -		$r = q("SELECT id, secret  FROM tokens WHERE client_id='%s' AND id='%s' AND expires=%d",
    -			dbesc($consumer->key),
    -			dbesc($nonce),
    -			intval($timestamp)
    -		);
    -		if (DBM::is_result($r))
    -			return new OAuthToken($r[0]['id'],$r[0]['secret']);
    -		return null;
    -  }
    -
    -  function new_request_token($consumer, $callback = null) {
    -		logger(__function__.":".$consumer.", ". $callback);
    -		$key = $this->gen_token();
    -		$sec = $this->gen_token();
    -
    -		if ($consumer->key){
    -			$k = $consumer->key;
    -		} else {
    -			$k = $consumer;
    -		}
    -
    -		$r = q("INSERT INTO tokens (id, secret, client_id, scope, expires) VALUES ('%s','%s','%s','%s', UNIX_TIMESTAMP()+%d)",
    -				dbesc($key),
    -				dbesc($sec),
    -				dbesc($k),
    -				'request',
    -				intval(REQUEST_TOKEN_DURATION));
    -		if (!$r) return null;
    -		return new OAuthToken($key,$sec);
    -  }
    -
    -  function new_access_token($token, $consumer, $verifier = null) {
    -    logger(__function__.":".$token.", ". $consumer.", ". $verifier);
    -
    -    // return a new access token attached to this consumer
    -    // for the user associated with this token if the request token
    -    // is authorized
    -    // should also invalidate the request token
    -
    -    $ret=Null;
    -
    -    // get user for this verifier
    -    $uverifier = Config::get("oauth", $verifier);
    -    logger(__function__.":".$verifier.",".$uverifier);
    -    if (is_null($verifier) || ($uverifier!==false)){
    -
    -		$key = $this->gen_token();
    -		$sec = $this->gen_token();
    -		$r = q("INSERT INTO tokens (id, secret, client_id, scope, expires, uid) VALUES ('%s','%s','%s','%s', UNIX_TIMESTAMP()+%d, %d)",
    -				dbesc($key),
    -				dbesc($sec),
    -				dbesc($consumer->key),
    -				'access',
    -				intval(ACCESS_TOKEN_DURATION),
    -				intval($uverifier));
    -		if ($r)
    -			$ret = new OAuthToken($key,$sec);
    -	}
    -
    -
    -	dba::delete('tokens', array('id' => $token->key));
    -
    -
    -	if (!is_null($ret) && $uverifier!==false){
    -		Config::delete("oauth", $verifier);
    -	/*	$apps = PConfig::get($uverifier, "oauth", "apps");
    -		if ($apps===false) $apps=array();
    -		$apps[] = $consumer->key;
    -		PConfig::set($uverifier, "oauth", "apps", $apps);*/
    -	}
    -
    -    return $ret;
    -
    -  }
    -}
    -
    -class FKOAuth1 extends OAuthServer {
    -	function __construct() {
    -		parent::__construct(new FKOAuthDataStore());
    -		$this->add_signature_method(new OAuthSignatureMethod_PLAINTEXT());
    -		$this->add_signature_method(new OAuthSignatureMethod_HMAC_SHA1());
    -	}
    -
    -	function loginUser($uid){
    -		logger("FKOAuth1::loginUser $uid");
    -		$a = get_app();
    -		$r = q("SELECT * FROM `user` WHERE uid=%d AND `blocked` = 0 AND `account_expired` = 0 AND `account_removed` = 0 AND `verified` = 1 LIMIT 1",
    -			intval($uid)
    -		);
    -		if (DBM::is_result($r)){
    -			$record = $r[0];
    -		} else {
    -		   logger('FKOAuth1::loginUser failure: ' . print_r($_SERVER,true), LOGGER_DEBUG);
    -		    header('HTTP/1.0 401 Unauthorized');
    -		    die('This api requires login');
    -		}
    -		$_SESSION['uid'] = $record['uid'];
    -		$_SESSION['theme'] = $record['theme'];
    -		$_SESSION['mobile-theme'] = PConfig::get($record['uid'], 'system', 'mobile_theme');
    -		$_SESSION['authenticated'] = 1;
    -		$_SESSION['page_flags'] = $record['page-flags'];
    -		$_SESSION['my_url'] = System::baseUrl() . '/profile/' . $record['nickname'];
    -		$_SESSION['addr'] = $_SERVER['REMOTE_ADDR'];
    -		$_SESSION["allow_api"] = true;
    -
    -		//notice( t("Welcome back ") . $record['username'] . EOL);
    -		$a->user = $record;
    -
    -		if (strlen($a->user['timezone'])) {
    -			date_default_timezone_set($a->user['timezone']);
    -			$a->timezone = $a->user['timezone'];
    -		}
    -
    -		$r = q("SELECT * FROM `contact` WHERE `uid` = %s AND `self` = 1 LIMIT 1",
    -			intval($_SESSION['uid']));
    -		if (DBM::is_result($r)) {
    -			$a->contact = $r[0];
    -			$a->cid = $r[0]['id'];
    -			$_SESSION['cid'] = $a->cid;
    -		}
    -		q("UPDATE `user` SET `login_date` = '%s' WHERE `uid` = %d",
    -			dbesc(datetime_convert()),
    -			intval($_SESSION['uid'])
    -		);
    -
    -		call_hooks('logged_in', $a->user);
    -	}
    -
    -}
    diff --git a/src/Protocol/FKOAuth1.php b/src/Protocol/FKOAuth1.php
    new file mode 100644
    index 000000000..5d0e9e52b
    --- /dev/null
    +++ b/src/Protocol/FKOAuth1.php
    @@ -0,0 +1,77 @@
    +add_signature_method(new OAuthSignatureMethod_PLAINTEXT());
    +		$this->add_signature_method(new OAuthSignatureMethod_HMAC_SHA1());
    +	}
    +
    +	function loginUser($uid)
    +	{
    +		logger("FKOAuth1::loginUser $uid");
    +		$a = get_app();
    +		$r = q("SELECT * FROM `user` WHERE uid=%d AND `blocked` = 0 AND `account_expired` = 0 AND `account_removed` = 0 AND `verified` = 1 LIMIT 1",
    +			intval($uid)
    +		);
    +		if (DBM::is_result($r)){
    +			$record = $r[0];
    +		} else {
    +		   logger('FKOAuth1::loginUser failure: ' . print_r($_SERVER,true), LOGGER_DEBUG);
    +		    header('HTTP/1.0 401 Unauthorized');
    +		    die('This api requires login');
    +		}
    +		$_SESSION['uid'] = $record['uid'];
    +		$_SESSION['theme'] = $record['theme'];
    +		$_SESSION['mobile-theme'] = PConfig::get($record['uid'], 'system', 'mobile_theme');
    +		$_SESSION['authenticated'] = 1;
    +		$_SESSION['page_flags'] = $record['page-flags'];
    +		$_SESSION['my_url'] = System::baseUrl() . '/profile/' . $record['nickname'];
    +		$_SESSION['addr'] = $_SERVER['REMOTE_ADDR'];
    +		$_SESSION["allow_api"] = true;
    +
    +		//notice( t("Welcome back ") . $record['username'] . EOL);
    +		$a->user = $record;
    +
    +		if (strlen($a->user['timezone'])) {
    +			date_default_timezone_set($a->user['timezone']);
    +			$a->timezone = $a->user['timezone'];
    +		}
    +
    +		$r = q("SELECT * FROM `contact` WHERE `uid` = %s AND `self` = 1 LIMIT 1",
    +			intval($_SESSION['uid']));
    +		if (DBM::is_result($r)) {
    +			$a->contact = $r[0];
    +			$a->cid = $r[0]['id'];
    +			$_SESSION['cid'] = $a->cid;
    +		}
    +		q("UPDATE `user` SET `login_date` = '%s' WHERE `uid` = %d",
    +			dbesc(datetime_convert()),
    +			intval($_SESSION['uid'])
    +		);
    +
    +		call_hooks('logged_in', $a->user);
    +	}
    +}
    diff --git a/src/Protocol/FKOAuthDataStore.php b/src/Protocol/FKOAuthDataStore.php
    new file mode 100644
    index 000000000..08c32df21
    --- /dev/null
    +++ b/src/Protocol/FKOAuthDataStore.php
    @@ -0,0 +1,150 @@
    +
    + *
    + */
    +namespace Friendica\Protocol;
    +
    +use Friendica\App;
    +use Friendica\Core\Config;
    +use Friendica\Core\System;
    +use Friendica\Database\DBM;
    +use dba;
    +
    +define('REQUEST_TOKEN_DURATION', 300);
    +define('ACCESS_TOKEN_DURATION', 31536000);
    +
    +require_once "library/OAuth1.php";
    +require_once "library/oauth2-php/lib/OAuth2.inc";
    +
    +/**
    + * @brief OAuthDataStore class
    + */
    +class FKOAuthDataStore extends OAuthDataStore
    +{
    +	function gen_token()
    +	{
    +		return md5(base64_encode(pack('N6', mt_rand(), mt_rand(), mt_rand(), mt_rand(), mt_rand(), uniqid())));
    +	}
    +
    +	function lookup_consumer($consumer_key)
    +	{
    +		logger(__function__.":".$consumer_key);
    +		
    +		$r = q("SELECT client_id, pw, redirect_uri FROM clients WHERE client_id='%s'",
    +			dbesc($consumer_key)
    +		);
    +
    +		if (DBM::is_result($r)) {
    +			return new OAuthConsumer($r[0]['client_id'], $r[0]['pw'], $r[0]['redirect_uri']);
    +		}
    +
    +		return null;
    +	}
    +
    +	function lookup_token($consumer, $token_type, $token)
    +	{
    +		logger(__function__.":".$consumer.", ". $token_type.", ".$token);
    +		$r = q("SELECT id, secret,scope, expires, uid  FROM tokens WHERE client_id='%s' AND scope='%s' AND id='%s'",
    +			dbesc($consumer->key),
    +			dbesc($token_type),
    +			dbesc($token)
    +		);
    +		if (DBM::is_result($r)) {
    +			$ot=new OAuthToken($r[0]['id'], $r[0]['secret']);
    +			$ot->scope=$r[0]['scope'];
    +			$ot->expires = $r[0]['expires'];
    +			$ot->uid = $r[0]['uid'];
    +			return $ot;
    +		}
    +		return null;
    +	}
    +
    +	function lookup_nonce($consumer, $token, $nonce, $timestamp)
    +	{
    +		//echo __file__.":".__line__."
    "; var_dump($consumer,$key); killme();
    +		$r = q("SELECT id, secret  FROM tokens WHERE client_id='%s' AND id='%s' AND expires=%d",
    +			dbesc($consumer->key),
    +			dbesc($nonce),
    +			intval($timestamp)
    +		);
    +		
    +		if (DBM::is_result($r)) {
    +			return new OAuthToken($r[0]['id'], $r[0]['secret']);
    +		}
    +
    +		return null;
    +	}
    +
    +	function new_request_token($consumer, $callback = null)
    +	{
    +		logger(__function__.":".$consumer.", ". $callback);
    +		$key = $this->gen_token();
    +		$sec = $this->gen_token();
    +
    +		if ($consumer->key) {
    +			$k = $consumer->key;
    +		} else {
    +			$k = $consumer;
    +		}
    +
    +		$r = q("INSERT INTO tokens (id, secret, client_id, scope, expires) VALUES ('%s','%s','%s','%s', UNIX_TIMESTAMP()+%d)",
    +			dbesc($key),
    +			dbesc($sec),
    +			dbesc($k),
    +			'request',
    +			intval(REQUEST_TOKEN_DURATION)
    +		);
    +
    +		if (!$r) {
    +			return null;
    +		}
    +
    +		return new OAuthToken($key, $sec);
    +	}
    +
    +	function new_access_token($token, $consumer, $verifier = null)
    +	{
    +		logger(__function__.":".$token.", ". $consumer.", ". $verifier);
    +
    +		// return a new access token attached to this consumer
    +		// for the user associated with this token if the request token
    +		// is authorized
    +		// should also invalidate the request token
    +
    +		$ret = null;
    +
    +		// get user for this verifier
    +		$uverifier = Config::get("oauth", $verifier);
    +		logger(__function__.":".$verifier.",".$uverifier);
    +
    +		if (is_null($verifier) || ($uverifier!==false)) {
    +			$key = $this->gen_token();
    +			$sec = $this->gen_token();
    +			$r = q("INSERT INTO tokens (id, secret, client_id, scope, expires, uid) VALUES ('%s','%s','%s','%s', UNIX_TIMESTAMP()+%d, %d)",
    +				dbesc($key),
    +				dbesc($sec),
    +				dbesc($consumer->key),
    +				'access',
    +				intval(ACCESS_TOKEN_DURATION),
    +				intval($uverifier)
    +			);
    +
    +			if ($r) {
    +				$ret = new OAuthToken($key, $sec);
    +			}
    +		}
    +
    +
    +		dba::delete('tokens', array('id' => $token->key));
    +
    +
    +		if (!is_null($ret) && $uverifier !== false) {
    +			Config::delete("oauth", $verifier);
    +		}
    +
    +		return $ret;
    +	}
    +}
    
    From 360e39ca5b9d6a816106a23b52b477d7a058b003 Mon Sep 17 00:00:00 2001
    From: Michael 
    Date: Mon, 4 Dec 2017 19:36:08 +0000
    Subject: [PATCH 37/71] unmark for archival
    
    ---
     include/items.php      | 8 ++++----
     src/Object/Contact.php | 4 +---
     2 files changed, 5 insertions(+), 7 deletions(-)
    
    diff --git a/include/items.php b/include/items.php
    index f0470feb7..e49eadd86 100644
    --- a/include/items.php
    +++ b/include/items.php
    @@ -1151,6 +1151,10 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f
      * @param array $arr Contains the just posted item record
      */
     function item_set_last_item($arr) {
    +	$contact = dba::select('contact', [], ['id' => $arr['contact-id']], ['limit' => 1]);
    +	if ($contact['term-date'] > NULL_DATE) {
    +		 Contact::unmarkForArchival($contact);
    +	}
     
     	$update = (!$arr['private'] && (($arr["author-link"] === $arr["owner-link"]) || ($arr["parent-uri"] === $arr["uri"])));
     
    @@ -1166,10 +1170,6 @@ function item_set_last_item($arr) {
     	if ($update) {
     		dba::update('contact', array('success_update' => $arr['received'], 'last-item' => $arr['received']),
     			array('id' => $arr['contact-id']));
    -		$contact = dba::select('contact', [], ['id' => $arr['contact-id']], ['limit' => 1]);
    -		if ($contact['term-date'] > NULL_DATE) {
    -			 Contact::unmarkForArchival($contact);
    -		}
     	}
     	// Now do the same for the system wide contacts with uid=0
     	if (!$arr['private']) {
    diff --git a/src/Object/Contact.php b/src/Object/Contact.php
    index af8489958..f0299603e 100644
    --- a/src/Object/Contact.php
    +++ b/src/Object/Contact.php
    @@ -145,7 +145,6 @@ class Contact extends BaseObject
     		if ($contact['archive']) {
     			return;
     		}
    -logger('Blubb-m: '.$contact['id'].' - '.System::callstack());
     		if ($contact['term-date'] <= NULL_DATE) {
     			dba::update('contact', array('term-date' => datetime_convert()), array('id' => $contact['id']));
     
    @@ -185,8 +184,7 @@ logger('Blubb-m: '.$contact['id'].' - '.System::callstack());
     	 */
     	public static function unmarkForArchival(array $contact)
     	{
    -//logger('Blubb-m: '.$contact['id'].' - '.System::callstack());
    -		$condition = array('`id` = ? AND (`term-date` > ? OR `archive`)', $contact[`id`], NULL_DATE);
    +		$condition = array('`id` = ? AND (`term-date` > ? OR `archive`)', $contact['id'], NULL_DATE);
     		$exists = dba::exists('contact', $condition);
     
     		// We don't need to update, we never marked this contact for archival
    
    From a206f6d832a24aa58ebc90115537005a084aacaa Mon Sep 17 00:00:00 2001
    From: Michael 
    Date: Mon, 4 Dec 2017 19:37:36 +0000
    Subject: [PATCH 38/71] Only a newline
    
    ---
     src/Object/Contact.php | 1 +
     1 file changed, 1 insertion(+)
    
    diff --git a/src/Object/Contact.php b/src/Object/Contact.php
    index f0299603e..bd7cee7fb 100644
    --- a/src/Object/Contact.php
    +++ b/src/Object/Contact.php
    @@ -145,6 +145,7 @@ class Contact extends BaseObject
     		if ($contact['archive']) {
     			return;
     		}
    +
     		if ($contact['term-date'] <= NULL_DATE) {
     			dba::update('contact', array('term-date' => datetime_convert()), array('id' => $contact['id']));
     
    
    From dc32553a1d94db877580b8bfbf08f825cc7262a1 Mon Sep 17 00:00:00 2001
    From: Michael 
    Date: Mon, 4 Dec 2017 19:50:32 +0000
    Subject: [PATCH 39/71] Better usew the author
    
    ---
     include/items.php | 3 ++-
     1 file changed, 2 insertions(+), 1 deletion(-)
    
    diff --git a/include/items.php b/include/items.php
    index e49eadd86..f334990d7 100644
    --- a/include/items.php
    +++ b/include/items.php
    @@ -1151,7 +1151,8 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f
      * @param array $arr Contains the just posted item record
      */
     function item_set_last_item($arr) {
    -	$contact = dba::select('contact', [], ['id' => $arr['contact-id']], ['limit' => 1]);
    +	// Unarchive the author
    +	$contact = dba::select('contact', [], ['id' => $arr["author-link"]], ['limit' => 1]);
     	if ($contact['term-date'] > NULL_DATE) {
     		 Contact::unmarkForArchival($contact);
     	}
    
    From 9c7b6d9d5f3660fa37d9978bf2e89cdfbe2c8847 Mon Sep 17 00:00:00 2001
    From: Adam Magness 
    Date: Mon, 4 Dec 2017 14:52:04 -0500
    Subject: [PATCH 40/71] Functions and Standards
    
    Standards and convert to dba functions where possible.
    ---
     include/api.php                   |  13 ++--
     src/Protocol/FKOAuth1.php         |  33 +++++-----
     src/Protocol/FKOAuthDataStore.php | 106 +++++++++++++++++++-----------
     3 files changed, 91 insertions(+), 61 deletions(-)
    
    diff --git a/include/api.php b/include/api.php
    index ea804b18b..e55af1ae9 100644
    --- a/include/api.php
    +++ b/include/api.php
    @@ -25,12 +25,12 @@ use Friendica\Network\HTTPException\TooManyRequestsException;
     use Friendica\Object\Contact;
     use Friendica\Object\Photo;
     use Friendica\Protocol\Diaspora;
    +use Friendica\Protocol\FKOAuth1;
     use Friendica\Util\XML;
     
     require_once 'include/bbcode.php';
     require_once 'include/datetime.php';
     require_once 'include/conversation.php';
    -require_once 'include/oauth.php';
     require_once 'include/html2plain.php';
     require_once 'mod/share.php';
     require_once 'mod/item.php';
    @@ -159,10 +159,9 @@ function api_login(App $a)
     {
     	// login with oauth
     	try {
    -		$oauth = new FKOAuth1();
    -		list($consumer,$token) = $oauth->verify_request(OAuthRequest::from_request());
    +		list($consumer, $token) = FKOAuth1::verify_request(OAuthRequest::from_request());
     		if (!is_null($token)) {
    -			$oauth->loginUser($token->uid);
    +			FKOAuth1::loginUser($token->uid);
     			call_hooks('logged_in', $a->user);
     			return;
     		}
    @@ -3365,8 +3364,7 @@ api_register_func('api/direct_messages', 'api_direct_messages_inbox', true);
     function api_oauth_request_token($type)
     {
     	try {
    -		$oauth = new FKOAuth1();
    -		$r = $oauth->fetch_request_token(OAuthRequest::from_request());
    +		$r = FKOAuth1::fetch_request_token(OAuthRequest::from_request());
     	} catch (Exception $e) {
     		echo "error=" . OAuthUtil::urlencode_rfc3986($e->getMessage());
     		killme();
    @@ -3378,8 +3376,7 @@ function api_oauth_request_token($type)
     function api_oauth_access_token($type)
     {
     	try {
    -		$oauth = new FKOAuth1();
    -		$r = $oauth->fetch_access_token(OAuthRequest::from_request());
    +		$r = FKOAuth1::fetch_access_token(OAuthRequest::from_request());
     	} catch (Exception $e) {
     		echo "error=". OAuthUtil::urlencode_rfc3986($e->getMessage());
     		killme();
    diff --git a/src/Protocol/FKOAuth1.php b/src/Protocol/FKOAuth1.php
    index 5d0e9e52b..710097ae0 100644
    --- a/src/Protocol/FKOAuth1.php
    +++ b/src/Protocol/FKOAuth1.php
    @@ -29,19 +29,22 @@ class FKOAuth1 extends OAuthServer
     		$this->add_signature_method(new OAuthSignatureMethod_HMAC_SHA1());
     	}
     
    -	function loginUser($uid)
    +	/**
    +	 * @param string $uid user id
    +	 * @return void
    +	 */
    +	public static function loginUser($uid)
     	{
     		logger("FKOAuth1::loginUser $uid");
     		$a = get_app();
    -		$r = q("SELECT * FROM `user` WHERE uid=%d AND `blocked` = 0 AND `account_expired` = 0 AND `account_removed` = 0 AND `verified` = 1 LIMIT 1",
    -			intval($uid)
    -		);
    -		if (DBM::is_result($r)){
    -			$record = $r[0];
    +		$r = dba::select('user', array(), array('uid' => $uid, 'blocked' => 0, 'account_expired' => 0, 'account_removed' => 0, 'verified' => 1), array('limit' => 1));
    +
    +		if (DBM::is_result($r)) {
    +			$record = $r;
     		} else {
    -		   logger('FKOAuth1::loginUser failure: ' . print_r($_SERVER,true), LOGGER_DEBUG);
    -		    header('HTTP/1.0 401 Unauthorized');
    -		    die('This api requires login');
    +			logger('FKOAuth1::loginUser failure: ' . print_r($_SERVER, true), LOGGER_DEBUG);
    +			header('HTTP/1.0 401 Unauthorized');
    +			die('This api requires login');
     		}
     		$_SESSION['uid'] = $record['uid'];
     		$_SESSION['theme'] = $record['theme'];
    @@ -52,7 +55,6 @@ class FKOAuth1 extends OAuthServer
     		$_SESSION['addr'] = $_SERVER['REMOTE_ADDR'];
     		$_SESSION["allow_api"] = true;
     
    -		//notice( t("Welcome back ") . $record['username'] . EOL);
     		$a->user = $record;
     
     		if (strlen($a->user['timezone'])) {
    @@ -60,14 +62,15 @@ class FKOAuth1 extends OAuthServer
     			$a->timezone = $a->user['timezone'];
     		}
     
    -		$r = q("SELECT * FROM `contact` WHERE `uid` = %s AND `self` = 1 LIMIT 1",
    -			intval($_SESSION['uid']));
    +		$r = dba::select('contact', array(), array('uid' => $_SESSION['uid'], 'self' => 1), array('limit' => 1));
    +		
     		if (DBM::is_result($r)) {
    -			$a->contact = $r[0];
    -			$a->cid = $r[0]['id'];
    +			$a->contact = $r;
    +			$a->cid = $r['id'];
     			$_SESSION['cid'] = $a->cid;
     		}
    -		q("UPDATE `user` SET `login_date` = '%s' WHERE `uid` = %d",
    +
    +		dba::q("UPDATE `user` SET `login_date` = '%s' WHERE `uid` = %d",
     			dbesc(datetime_convert()),
     			intval($_SESSION['uid'])
     		);
    diff --git a/src/Protocol/FKOAuthDataStore.php b/src/Protocol/FKOAuthDataStore.php
    index 08c32df21..dc4b774b9 100644
    --- a/src/Protocol/FKOAuthDataStore.php
    +++ b/src/Protocol/FKOAuthDataStore.php
    @@ -24,18 +24,24 @@ require_once "library/oauth2-php/lib/OAuth2.inc";
      */
     class FKOAuthDataStore extends OAuthDataStore
     {
    -	function gen_token()
    +	/**
    +	 * @return string
    +	 */
    +	private static function genToken()
     	{
     		return md5(base64_encode(pack('N6', mt_rand(), mt_rand(), mt_rand(), mt_rand(), mt_rand(), uniqid())));
     	}
     
    -	function lookup_consumer($consumer_key)
    +	/**
    +	 * @param string $consumer_key key
    +	 * @return mixed
    +	 */
    +	public static function lookup_consumer($consumer_key)
     	{
     		logger(__function__.":".$consumer_key);
     		
    -		$r = q("SELECT client_id, pw, redirect_uri FROM clients WHERE client_id='%s'",
    -			dbesc($consumer_key)
    -		);
    +		$s = dba::select('clients', array('client_id', 'pw', 'redirect_uri'), array('client_id' => $consumer_key));
    +		$r = dba::inArray($r);
     
     		if (DBM::is_result($r)) {
     			return new OAuthConsumer($r[0]['client_id'], $r[0]['pw'], $r[0]['redirect_uri']);
    @@ -44,32 +50,41 @@ class FKOAuthDataStore extends OAuthDataStore
     		return null;
     	}
     
    -	function lookup_token($consumer, $token_type, $token)
    +	/**
    +	 * @param string $consumer   consumer
    +	 * @param string $token_type type
    +	 * @param string $token      token
    +	 * @return mixed
    +	 */
    +	public static function lookup_token($consumer, $token_type, $token)
     	{
     		logger(__function__.":".$consumer.", ". $token_type.", ".$token);
    -		$r = q("SELECT id, secret,scope, expires, uid  FROM tokens WHERE client_id='%s' AND scope='%s' AND id='%s'",
    -			dbesc($consumer->key),
    -			dbesc($token_type),
    -			dbesc($token)
    -		);
    +		
    +		$s = dba::select('tokens', array('id', 'secret', 'scope', 'expires', 'uid'), array('client_id' => $consumer->key, 'scope' => $token_type, 'id' => $token));
    +		$r = dba::inArray($s);
    +
     		if (DBM::is_result($r)) {
     			$ot=new OAuthToken($r[0]['id'], $r[0]['secret']);
    -			$ot->scope=$r[0]['scope'];
    +			$ot->scope = $r[0]['scope'];
     			$ot->expires = $r[0]['expires'];
     			$ot->uid = $r[0]['uid'];
     			return $ot;
     		}
    +
     		return null;
     	}
     
    -	function lookup_nonce($consumer, $token, $nonce, $timestamp)
    +	/**
    +	 * @param string $consumer  consumer
    +	 * @param string $token     token
    +	 * @param string $nonce     nonce
    +	 * @param string $timestamp timestamp
    +	 * @return mixed
    +	 */
    +	public static function lookup_nonce($consumer, $token, $nonce, $timestamp)
     	{
    -		//echo __file__.":".__line__."
    "; var_dump($consumer,$key); killme();
    -		$r = q("SELECT id, secret  FROM tokens WHERE client_id='%s' AND id='%s' AND expires=%d",
    -			dbesc($consumer->key),
    -			dbesc($nonce),
    -			intval($timestamp)
    -		);
    +		$s = dba::select('tokens', array('id', 'secret'), array('client_id' => $consumer->key, 'id' => $nonce, 'expires' => $timestamp));
    +		$r = dba::inArray($s);
     		
     		if (DBM::is_result($r)) {
     			return new OAuthToken($r[0]['id'], $r[0]['secret']);
    @@ -78,11 +93,16 @@ class FKOAuthDataStore extends OAuthDataStore
     		return null;
     	}
     
    -	function new_request_token($consumer, $callback = null)
    +	/**
    +	 * @param string $consumer consumer
    +	 * @param string $callback optional, default null
    +	 * @return mixed
    +	 */
    +	public static function new_request_token($consumer, $callback = null)
     	{
     		logger(__function__.":".$consumer.", ". $callback);
    -		$key = $this->gen_token();
    -		$sec = $this->gen_token();
    +		$key = self::genToken();
    +		$sec = self::genToken();
     
     		if ($consumer->key) {
     			$k = $consumer->key;
    @@ -90,12 +110,14 @@ class FKOAuthDataStore extends OAuthDataStore
     			$k = $consumer;
     		}
     
    -		$r = q("INSERT INTO tokens (id, secret, client_id, scope, expires) VALUES ('%s','%s','%s','%s', UNIX_TIMESTAMP()+%d)",
    -			dbesc($key),
    -			dbesc($sec),
    -			dbesc($k),
    -			'request',
    -			intval(REQUEST_TOKEN_DURATION)
    +		$r = dba::insert(
    +			'tokens',
    +			array(
    +				'id' => $key,
    +				'secret' => $sec,
    +				'client_id' => $k,
    +				'scope' => 'request',
    +				'expires' => UNIX_TIMESTAMP() + REQUEST_TOKEN_DURATION)
     		);
     
     		if (!$r) {
    @@ -105,7 +127,13 @@ class FKOAuthDataStore extends OAuthDataStore
     		return new OAuthToken($key, $sec);
     	}
     
    -	function new_access_token($token, $consumer, $verifier = null)
    +	/**
    +	 * @param string $token    token
    +	 * @param string $consumer consumer
    +	 * @param string $verifier optional, defult null
    +	 * @return object
    +	 */
    +	public static function new_access_token($token, $consumer, $verifier = null)
     	{
     		logger(__function__.":".$token.", ". $consumer.", ". $verifier);
     
    @@ -121,15 +149,17 @@ class FKOAuthDataStore extends OAuthDataStore
     		logger(__function__.":".$verifier.",".$uverifier);
     
     		if (is_null($verifier) || ($uverifier!==false)) {
    -			$key = $this->gen_token();
    -			$sec = $this->gen_token();
    -			$r = q("INSERT INTO tokens (id, secret, client_id, scope, expires, uid) VALUES ('%s','%s','%s','%s', UNIX_TIMESTAMP()+%d, %d)",
    -				dbesc($key),
    -				dbesc($sec),
    -				dbesc($consumer->key),
    -				'access',
    -				intval(ACCESS_TOKEN_DURATION),
    -				intval($uverifier)
    +			$key = self::genToken();
    +			$sec = self::genToken();
    +			$r = dba::insert(
    +				'tokens',
    +				array(
    +					'id' => $key,
    +					'secret' => $sec,
    +					'client_id' => $consumer->key,
    +					'scope' => 'access',
    +					'expires' => UNIX_TIMESTAMP() + ACCESS_TOKEN_DURATION,
    +					'uid' => $uverifier)
     			);
     
     			if ($r) {
    
    From 2bbfc0640f411f99e37d82763ce57af5c0c18bd9 Mon Sep 17 00:00:00 2001
    From: Adam Magness 
    Date: Mon, 4 Dec 2017 15:59:21 -0500
    Subject: [PATCH 41/71] Move to Network
    
    Move to network namespace. Get rid of q() and try to get used to [ ] instead of array()
    ---
     src/{Protocol => Network}/FKOAuth1.php         | 9 +++------
     src/{Protocol => Network}/FKOAuthDataStore.php | 2 +-
     2 files changed, 4 insertions(+), 7 deletions(-)
     rename src/{Protocol => Network}/FKOAuth1.php (90%)
     rename src/{Protocol => Network}/FKOAuthDataStore.php (99%)
    
    diff --git a/src/Protocol/FKOAuth1.php b/src/Network/FKOAuth1.php
    similarity index 90%
    rename from src/Protocol/FKOAuth1.php
    rename to src/Network/FKOAuth1.php
    index 710097ae0..a323f5cd5 100644
    --- a/src/Protocol/FKOAuth1.php
    +++ b/src/Network/FKOAuth1.php
    @@ -2,13 +2,13 @@
     /**
      * @file src/Protocol/OAuth1.php
      */
    -namespace Friendica\Protocol;
    +namespace Friendica\Network;
     
     use Friendica\App;
     use Friendica\Core\PConfig;
     use Friendica\Core\System;
     use Friendica\Database\DBM;
    -use Friendica\Protocol\FKOAuthDataStore;
    +use Friendica\Network\FKOAuthDataStore;
     use dba;
     
     require_once "library/OAuth1.php";
    @@ -70,10 +70,7 @@ class FKOAuth1 extends OAuthServer
     			$_SESSION['cid'] = $a->cid;
     		}
     
    -		dba::q("UPDATE `user` SET `login_date` = '%s' WHERE `uid` = %d",
    -			dbesc(datetime_convert()),
    -			intval($_SESSION['uid'])
    -		);
    +		dba::update('user', ['login_date' => datetime_convert()], ['uid' => $_SESSION['uid']]);
     
     		call_hooks('logged_in', $a->user);
     	}
    diff --git a/src/Protocol/FKOAuthDataStore.php b/src/Network/FKOAuthDataStore.php
    similarity index 99%
    rename from src/Protocol/FKOAuthDataStore.php
    rename to src/Network/FKOAuthDataStore.php
    index dc4b774b9..007908b99 100644
    --- a/src/Protocol/FKOAuthDataStore.php
    +++ b/src/Network/FKOAuthDataStore.php
    @@ -5,7 +5,7 @@
      * Based on oauth2-php 
      *
      */
    -namespace Friendica\Protocol;
    +namespace Friendica\Network;
     
     use Friendica\App;
     use Friendica\Core\Config;
    
    From 547e24b443a44bffa5f2a0fa742f59f60335a89a Mon Sep 17 00:00:00 2001
    From: Adam Magness 
    Date: Mon, 4 Dec 2017 16:33:10 -0500
    Subject: [PATCH 42/71] Review
    
    updates based on review.
    ---
     src/Network/FKOAuth1.php         | 6 ++----
     src/Network/FKOAuthDataStore.php | 5 ++---
     2 files changed, 4 insertions(+), 7 deletions(-)
    
    diff --git a/src/Network/FKOAuth1.php b/src/Network/FKOAuth1.php
    index a323f5cd5..768cae7d1 100644
    --- a/src/Network/FKOAuth1.php
    +++ b/src/Network/FKOAuth1.php
    @@ -37,11 +37,9 @@ class FKOAuth1 extends OAuthServer
     	{
     		logger("FKOAuth1::loginUser $uid");
     		$a = get_app();
    -		$r = dba::select('user', array(), array('uid' => $uid, 'blocked' => 0, 'account_expired' => 0, 'account_removed' => 0, 'verified' => 1), array('limit' => 1));
    +		$record = dba::select('user', array(), array('uid' => $uid, 'blocked' => 0, 'account_expired' => 0, 'account_removed' => 0, 'verified' => 1), array('limit' => 1));
     
    -		if (DBM::is_result($r)) {
    -			$record = $r;
    -		} else {
    +		if (!DBM::is_result($record)) {
     			logger('FKOAuth1::loginUser failure: ' . print_r($_SERVER, true), LOGGER_DEBUG);
     			header('HTTP/1.0 401 Unauthorized');
     			die('This api requires login');
    diff --git a/src/Network/FKOAuthDataStore.php b/src/Network/FKOAuthDataStore.php
    index 007908b99..0fcd01fc5 100644
    --- a/src/Network/FKOAuthDataStore.php
    +++ b/src/Network/FKOAuthDataStore.php
    @@ -83,9 +83,8 @@ class FKOAuthDataStore extends OAuthDataStore
     	 */
     	public static function lookup_nonce($consumer, $token, $nonce, $timestamp)
     	{
    -		$s = dba::select('tokens', array('id', 'secret'), array('client_id' => $consumer->key, 'id' => $nonce, 'expires' => $timestamp));
    -		$r = dba::inArray($s);
    -		
    +		$r = dba::select('tokens', ['id', 'secret'], ['client_id' => $consumer->key, 'id' => $nonce, 'expires' => $timestamp], ['limit' => 1]);
    +				
     		if (DBM::is_result($r)) {
     			return new OAuthToken($r[0]['id'], $r[0]['secret']);
     		}
    
    From d3473f9999e107a936882f5dce89d45f0b6db2e9 Mon Sep 17 00:00:00 2001
    From: Adam Magness 
    Date: Mon, 4 Dec 2017 18:30:18 -0500
    Subject: [PATCH 43/71] Update use
    
    Forgot to update a use statement.
    ---
     include/api.php | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/include/api.php b/include/api.php
    index e55af1ae9..740abf1e2 100644
    --- a/include/api.php
    +++ b/include/api.php
    @@ -13,6 +13,7 @@ use Friendica\Core\NotificationsManager;
     use Friendica\Core\Worker;
     use Friendica\Database\DBM;
     use Friendica\Model\User;
    +use Friendica\Network\FKOAuth1;
     use Friendica\Network\HTTPException;
     use Friendica\Network\HTTPException\BadRequestException;
     use Friendica\Network\HTTPException\ForbiddenException;
    @@ -25,7 +26,6 @@ use Friendica\Network\HTTPException\TooManyRequestsException;
     use Friendica\Object\Contact;
     use Friendica\Object\Photo;
     use Friendica\Protocol\Diaspora;
    -use Friendica\Protocol\FKOAuth1;
     use Friendica\Util\XML;
     
     require_once 'include/bbcode.php';
    
    From 9f4be62d3de8ac5819a2b39892cf5423416f9c35 Mon Sep 17 00:00:00 2001
    From: Adam Magness 
    Date: Mon, 4 Dec 2017 20:30:10 -0500
    Subject: [PATCH 44/71] Use statement
    
    ---
     src/Network/FKOAuth1.php | 1 +
     1 file changed, 1 insertion(+)
    
    diff --git a/src/Network/FKOAuth1.php b/src/Network/FKOAuth1.php
    index 768cae7d1..31960a91d 100644
    --- a/src/Network/FKOAuth1.php
    +++ b/src/Network/FKOAuth1.php
    @@ -10,6 +10,7 @@ use Friendica\Core\System;
     use Friendica\Database\DBM;
     use Friendica\Network\FKOAuthDataStore;
     use dba;
    +use OAuthServer;
     
     require_once "library/OAuth1.php";
     require_once "include/plugin.php";
    
    From 448598495cc4cee10e333d17a161c52549478cfa Mon Sep 17 00:00:00 2001
    From: Adam Magness 
    Date: Mon, 4 Dec 2017 21:00:47 -0500
    Subject: [PATCH 45/71] Static
    
    remove static
    ---
     src/Network/FKOAuthDataStore.php | 10 +++++-----
     1 file changed, 5 insertions(+), 5 deletions(-)
    
    diff --git a/src/Network/FKOAuthDataStore.php b/src/Network/FKOAuthDataStore.php
    index 0fcd01fc5..6cb080ba7 100644
    --- a/src/Network/FKOAuthDataStore.php
    +++ b/src/Network/FKOAuthDataStore.php
    @@ -36,7 +36,7 @@ class FKOAuthDataStore extends OAuthDataStore
     	 * @param string $consumer_key key
     	 * @return mixed
     	 */
    -	public static function lookup_consumer($consumer_key)
    +	public function lookup_consumer($consumer_key)
     	{
     		logger(__function__.":".$consumer_key);
     		
    @@ -56,7 +56,7 @@ class FKOAuthDataStore extends OAuthDataStore
     	 * @param string $token      token
     	 * @return mixed
     	 */
    -	public static function lookup_token($consumer, $token_type, $token)
    +	public function lookup_token($consumer, $token_type, $token)
     	{
     		logger(__function__.":".$consumer.", ". $token_type.", ".$token);
     		
    @@ -81,7 +81,7 @@ class FKOAuthDataStore extends OAuthDataStore
     	 * @param string $timestamp timestamp
     	 * @return mixed
     	 */
    -	public static function lookup_nonce($consumer, $token, $nonce, $timestamp)
    +	public function lookup_nonce($consumer, $token, $nonce, $timestamp)
     	{
     		$r = dba::select('tokens', ['id', 'secret'], ['client_id' => $consumer->key, 'id' => $nonce, 'expires' => $timestamp], ['limit' => 1]);
     				
    @@ -97,7 +97,7 @@ class FKOAuthDataStore extends OAuthDataStore
     	 * @param string $callback optional, default null
     	 * @return mixed
     	 */
    -	public static function new_request_token($consumer, $callback = null)
    +	public function new_request_token($consumer, $callback = null)
     	{
     		logger(__function__.":".$consumer.", ". $callback);
     		$key = self::genToken();
    @@ -132,7 +132,7 @@ class FKOAuthDataStore extends OAuthDataStore
     	 * @param string $verifier optional, defult null
     	 * @return object
     	 */
    -	public static function new_access_token($token, $consumer, $verifier = null)
    +	public function new_access_token($token, $consumer, $verifier = null)
     	{
     		logger(__function__.":".$token.", ". $consumer.", ". $verifier);
     
    
    From e997128c9fd896aac26a9305e725a69e673e0530 Mon Sep 17 00:00:00 2001
    From: Adam Magness 
    Date: Mon, 4 Dec 2017 21:03:39 -0500
    Subject: [PATCH 46/71] Static
    
    ---
     src/Network/FKOAuth1.php | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/src/Network/FKOAuth1.php b/src/Network/FKOAuth1.php
    index 31960a91d..9197d1aec 100644
    --- a/src/Network/FKOAuth1.php
    +++ b/src/Network/FKOAuth1.php
    @@ -34,7 +34,7 @@ class FKOAuth1 extends OAuthServer
     	 * @param string $uid user id
     	 * @return void
     	 */
    -	public static function loginUser($uid)
    +	public function loginUser($uid)
     	{
     		logger("FKOAuth1::loginUser $uid");
     		$a = get_app();
    
    From 0c48b4188bf7f68dbb28f7ebc9754aa4fd827475 Mon Sep 17 00:00:00 2001
    From: Adam Magness 
    Date: Mon, 4 Dec 2017 21:10:54 -0500
    Subject: [PATCH 47/71] Non Static calls
    
    update calls to non static
    ---
     include/api.php | 11 +++++++----
     1 file changed, 7 insertions(+), 4 deletions(-)
    
    diff --git a/include/api.php b/include/api.php
    index 740abf1e2..b5799d478 100644
    --- a/include/api.php
    +++ b/include/api.php
    @@ -157,11 +157,12 @@ function api_register_func($path, $func, $auth = false, $method = API_METHOD_ANY
      */
     function api_login(App $a)
     {
    +	$oauth1 = new FKOAuth1();
     	// login with oauth
     	try {
    -		list($consumer, $token) = FKOAuth1::verify_request(OAuthRequest::from_request());
    +		list($consumer, $token) = $oauth1->verify_request(OAuthRequest::from_request());
     		if (!is_null($token)) {
    -			FKOAuth1::loginUser($token->uid);
    +			$oauth1->loginUser($token->uid);
     			call_hooks('logged_in', $a->user);
     			return;
     		}
    @@ -3363,8 +3364,9 @@ api_register_func('api/direct_messages', 'api_direct_messages_inbox', true);
     
     function api_oauth_request_token($type)
     {
    +	$oauth1 = new FKOAuth1();
     	try {
    -		$r = FKOAuth1::fetch_request_token(OAuthRequest::from_request());
    +		$r = $oauth1->fetch_request_token(OAuthRequest::from_request());
     	} catch (Exception $e) {
     		echo "error=" . OAuthUtil::urlencode_rfc3986($e->getMessage());
     		killme();
    @@ -3375,8 +3377,9 @@ function api_oauth_request_token($type)
     
     function api_oauth_access_token($type)
     {
    +	$oauth1 = new FKOAuth1();
     	try {
    -		$r = FKOAuth1::fetch_access_token(OAuthRequest::from_request());
    +		$r = $oauth1->fetch_access_token(OAuthRequest::from_request());
     	} catch (Exception $e) {
     		echo "error=". OAuthUtil::urlencode_rfc3986($e->getMessage());
     		killme();
    
    From f1a5560804748e124f0c74b9d3d294b485b2864c Mon Sep 17 00:00:00 2001
    From: Adam Magness 
    Date: Mon, 4 Dec 2017 21:13:58 -0500
    Subject: [PATCH 48/71] Use statement
    
    missing use
    ---
     src/Network/FKOAuthDataStore.php | 1 +
     1 file changed, 1 insertion(+)
    
    diff --git a/src/Network/FKOAuthDataStore.php b/src/Network/FKOAuthDataStore.php
    index 6cb080ba7..b836a4d01 100644
    --- a/src/Network/FKOAuthDataStore.php
    +++ b/src/Network/FKOAuthDataStore.php
    @@ -12,6 +12,7 @@ use Friendica\Core\Config;
     use Friendica\Core\System;
     use Friendica\Database\DBM;
     use dba;
    +use OAuthDataStore;
     
     define('REQUEST_TOKEN_DURATION', 300);
     define('ACCESS_TOKEN_DURATION', 31536000);
    
    From e32b4ed670b5ca3f0e8f3dbb735e3fef376c952c Mon Sep 17 00:00:00 2001
    From: Adam Magness 
    Date: Mon, 4 Dec 2017 21:18:48 -0500
    Subject: [PATCH 49/71] More use
    
    more missing use
    ---
     src/Network/FKOAuth1.php | 2 ++
     1 file changed, 2 insertions(+)
    
    diff --git a/src/Network/FKOAuth1.php b/src/Network/FKOAuth1.php
    index 9197d1aec..ce2d4a6b8 100644
    --- a/src/Network/FKOAuth1.php
    +++ b/src/Network/FKOAuth1.php
    @@ -11,6 +11,8 @@ use Friendica\Database\DBM;
     use Friendica\Network\FKOAuthDataStore;
     use dba;
     use OAuthServer;
    +use OAuthSignatureMethod_PLAINTEXT;
    +use OAuthSignatureMethod_HMAC_SHA1;
     
     require_once "library/OAuth1.php";
     require_once "include/plugin.php";
    
    From c258df0f0a4856c92a396cf3805442b07f757685 Mon Sep 17 00:00:00 2001
    From: Tobias Diekershoff 
    Date: Tue, 5 Dec 2017 07:13:55 +0100
    Subject: [PATCH 50/71] removed x-permission
    
    ---
     include/oembed.php     | 0
     mod/install.php        | 0
     mod/like.php           | 0
     mod/repair_ostatus.php | 0
     4 files changed, 0 insertions(+), 0 deletions(-)
     mode change 100755 => 100644 include/oembed.php
     mode change 100755 => 100644 mod/install.php
     mode change 100755 => 100644 mod/like.php
     mode change 100755 => 100644 mod/repair_ostatus.php
    
    diff --git a/include/oembed.php b/include/oembed.php
    old mode 100755
    new mode 100644
    diff --git a/mod/install.php b/mod/install.php
    old mode 100755
    new mode 100644
    diff --git a/mod/like.php b/mod/like.php
    old mode 100755
    new mode 100644
    diff --git a/mod/repair_ostatus.php b/mod/repair_ostatus.php
    old mode 100755
    new mode 100644
    
    From e61402263448cfc7dd877fd4db6c83767cda6e4c Mon Sep 17 00:00:00 2001
    From: Tobias Diekershoff 
    Date: Tue, 5 Dec 2017 07:21:21 +0100
    Subject: [PATCH 51/71] added some x permissions to scripts
    
    ---
     util/config               | 0
     util/createdoxygen.php    | 0
     util/vagrant_provision.sh | 0
     util/vagrant_vhost.sh     | 0
     4 files changed, 0 insertions(+), 0 deletions(-)
     mode change 100644 => 100755 util/config
     mode change 100644 => 100755 util/createdoxygen.php
     mode change 100644 => 100755 util/vagrant_provision.sh
     mode change 100644 => 100755 util/vagrant_vhost.sh
    
    diff --git a/util/config b/util/config
    old mode 100644
    new mode 100755
    diff --git a/util/createdoxygen.php b/util/createdoxygen.php
    old mode 100644
    new mode 100755
    diff --git a/util/vagrant_provision.sh b/util/vagrant_provision.sh
    old mode 100644
    new mode 100755
    diff --git a/util/vagrant_vhost.sh b/util/vagrant_vhost.sh
    old mode 100644
    new mode 100755
    
    From db4d44748be9e8df7da3a5b4493ef80cbea67e5f Mon Sep 17 00:00:00 2001
    From: Tobias Diekershoff 
    Date: Tue, 5 Dec 2017 07:26:02 +0100
    Subject: [PATCH 52/71] another -x
    
    ---
     view/smarty3/.gitignore | 0
     1 file changed, 0 insertions(+), 0 deletions(-)
     mode change 100755 => 100644 view/smarty3/.gitignore
    
    diff --git a/view/smarty3/.gitignore b/view/smarty3/.gitignore
    old mode 100755
    new mode 100644
    
    From 5f9e87ea5ae7f0aaa308120bc7933f3d22af9f9d Mon Sep 17 00:00:00 2001
    From: Michael 
    Date: Tue, 5 Dec 2017 07:08:20 +0000
    Subject: [PATCH 53/71] Some cleanup for archiving/unarchiving contacts
    
    ---
     src/Protocol/Diaspora.php |  4 ----
     src/Protocol/OStatus.php  |  3 ---
     src/Worker/OnePoll.php    | 27 +++++++++++++++++++--------
     3 files changed, 19 insertions(+), 15 deletions(-)
    
    diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php
    index 26412e270..cd4e5b6f0 100644
    --- a/src/Protocol/Diaspora.php
    +++ b/src/Protocol/Diaspora.php
    @@ -1339,10 +1339,6 @@ class Diaspora
     		if ($r) {
     			$cid = $r[0]["id"];
     			$network = $r[0]["network"];
    -
    -			// We are receiving content from a user that possibly is about to be terminated
    -			// This means the user is vital, so we remove a possible termination date.
    -			Contact::unmarkForArchival($r[0]);
     		} else {
     			$cid = $contact["id"];
     			$network = NETWORK_DIASPORA;
    diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php
    index 47538faa8..9a2eaeb5b 100644
    --- a/src/Protocol/OStatus.php
    +++ b/src/Protocol/OStatus.php
    @@ -151,11 +151,8 @@ class OStatus
     
     		// Only update the contacts if it is an OStatus contact
     		if ($r && ($r['id'] > 0) && !$onlyfetch && ($contact["network"] == NETWORK_OSTATUS)) {
    -			// This contact is vital, so we awake it from the dead
    -			Contact::unmarkForArchival($contact);
     
     			// Update contact data
    -
     			$current = $contact;
     			unset($current['name-date']);
     
    diff --git a/src/Worker/OnePoll.php b/src/Worker/OnePoll.php
    index 0cf261a6e..9c8cdb81d 100644
    --- a/src/Worker/OnePoll.php
    +++ b/src/Worker/OnePoll.php
    @@ -77,10 +77,10 @@ Class OnePoll
     					}
     
     					$fields = array('last-item' => $last_updated, 'last-update' => $updated, 'success_update' => $updated);
    -					dba::update('contact', $fields, array('id' => $contact['id']));
    +					self::updateContact($contact, $fields);
     					Contact::unmarkForArchival($contact);
     				} else {
    -					dba::update('contact', array('last-update' => $updated, 'failure_update' => $updated), array('id' => $contact['id']));
    +					self::updateContact($contact, array('last-update' => $updated, 'failure_update' => $updated));
     					Contact::markForArchival($contact);
     					logger('Contact '.$contact['id'].' is marked for archival', LOGGER_DEBUG);
     				}
    @@ -206,7 +206,7 @@ Class OnePoll
     
     				// set the last-update so we don't keep polling
     				$fields = array('last-update' => datetime_convert(), 'failure_update' => datetime_convert());
    -				dba::update('contact', $fields, array('id' => $contact['id']));
    +				self::updateContact($contact, $fields);
     				return;
     			}
     
    @@ -216,7 +216,7 @@ Class OnePoll
     				Contact::markForArchival($contact);
     
     				$fields = array('last-update' => datetime_convert(), 'failure_update' => datetime_convert());
    -				dba::update('contact', $fields, array('id' => $contact['id']));
    +				self::updateContact($contact, $fields);
     				return;
     			}
     
    @@ -229,7 +229,7 @@ Class OnePoll
     				// we may not be friends anymore. Will keep trying for one month.
     				// set the last-update so we don't keep polling
     				$fields = array('last-update' => datetime_convert(), 'failure_update' => datetime_convert());
    -				dba::update('contact', $fields, array('id' => $contact['id']));
    +				self::updateContact($contact, $fields);
     
     				Contact::markForArchival($contact);
     			} elseif ($contact['term-date'] > NULL_DATE) {
    @@ -577,7 +577,7 @@ Class OnePoll
     				logger('post_handshake: response from ' . $url . ' did not contain XML.');
     
     				$fields = array('last-update' => datetime_convert(), 'failure_update' => datetime_convert());
    -				dba::update('contact', $fields, array('id' => $contact['id']));
    +				self::updateContact($contact, $fields);
     				Contact::markForArchival($contact);
     				return;
     			}
    @@ -622,13 +622,13 @@ Class OnePoll
     
     			$updated = datetime_convert();
     
    -			dba::update('contact', array('last-update' => $updated, 'success_update' => $updated), array('id' => $contact['id']));
    +			self::updateContact($contact, array('last-update' => $updated, 'success_update' => $updated));
     			dba::update('gcontact', array('last_contact' => $updated), array('nurl' => $contact['nurl']));
     			Contact::unmarkForArchival($contact);
     		} elseif (in_array($contact["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS, NETWORK_FEED))) {
     			$updated = datetime_convert();
     
    -			dba::update('contact', array('last-update' => $updated, 'failure_update' => $updated), array('id' => $contact['id']));
    +			self::updateContact($contact, array('last-update' => $updated, 'failure_update' => $updated));
     			dba::update('gcontact', array('last_failure' => $updated), array('nurl' => $contact['nurl']));
     			Contact::markForArchival($contact);
     		} else {
    @@ -645,4 +645,15 @@ Class OnePoll
     
     		return $subject;
     	}
    +
    +	/**
    +	 * @brief Updates a personal contact entry and the public contact entry
    +	 *
    +	 * @param array $contact The personal contact entry
    +	 * @param array $fields The fields that are updated
    +	 */
    +	private static function updateContact($contact, $fields) {
    +			dba::update('contact', $fields, array('id' => $contact['id']));
    +			dba::update('contact', $fields, array('uid' => 0, 'nurl' => $contact['nurl']));
    +	}
     }
    
    From 115d71e8415d95693bf968703c9fb7357ed1248d Mon Sep 17 00:00:00 2001
    From: Michael 
    Date: Tue, 5 Dec 2017 09:34:43 +0000
    Subject: [PATCH 54/71] One tab too much
    
    ---
     src/Worker/OnePoll.php | 4 ++--
     1 file changed, 2 insertions(+), 2 deletions(-)
    
    diff --git a/src/Worker/OnePoll.php b/src/Worker/OnePoll.php
    index 9c8cdb81d..2d742fc56 100644
    --- a/src/Worker/OnePoll.php
    +++ b/src/Worker/OnePoll.php
    @@ -653,7 +653,7 @@ Class OnePoll
     	 * @param array $fields The fields that are updated
     	 */
     	private static function updateContact($contact, $fields) {
    -			dba::update('contact', $fields, array('id' => $contact['id']));
    -			dba::update('contact', $fields, array('uid' => 0, 'nurl' => $contact['nurl']));
    +		dba::update('contact', $fields, array('id' => $contact['id']));
    +		dba::update('contact', $fields, array('uid' => 0, 'nurl' => $contact['nurl']));
     	}
     }
    
    From 22a3c7ad7d5205382961fa4e569b1af3a4d585d7 Mon Sep 17 00:00:00 2001
    From: Adam Magness 
    Date: Tue, 5 Dec 2017 06:58:57 -0500
    Subject: [PATCH 55/71] remove index
    
    remove unneeded index
    ---
     src/Network/FKOAuthDataStore.php | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/src/Network/FKOAuthDataStore.php b/src/Network/FKOAuthDataStore.php
    index b836a4d01..126f140bd 100644
    --- a/src/Network/FKOAuthDataStore.php
    +++ b/src/Network/FKOAuthDataStore.php
    @@ -87,7 +87,7 @@ class FKOAuthDataStore extends OAuthDataStore
     		$r = dba::select('tokens', ['id', 'secret'], ['client_id' => $consumer->key, 'id' => $nonce, 'expires' => $timestamp], ['limit' => 1]);
     				
     		if (DBM::is_result($r)) {
    -			return new OAuthToken($r[0]['id'], $r[0]['secret']);
    +			return new OAuthToken($r['id'], $r['secret']);
     		}
     
     		return null;
    
    From e5c2b7a2435ff72803dd23668eeb65b3446afb60 Mon Sep 17 00:00:00 2001
    From: Michael 
    Date: Tue, 5 Dec 2017 21:29:33 +0000
    Subject: [PATCH 56/71] Don't archive "self" contacts
    
    ---
     include/items.php      | 8 ++++++++
     src/Object/Contact.php | 8 ++++----
     2 files changed, 12 insertions(+), 4 deletions(-)
    
    diff --git a/include/items.php b/include/items.php
    index f334990d7..63c321819 100644
    --- a/include/items.php
    +++ b/include/items.php
    @@ -1157,6 +1157,14 @@ function item_set_last_item($arr) {
     		 Contact::unmarkForArchival($contact);
     	}
     
    +	// Unarchive the contact if it is a toplevel posting
    +	if ($arr["parent-uri"] === $arr["uri"]) {
    +		$contact = dba::select('contact', [], ['id' => $arr["contact-id"]], ['limit' => 1]);
    +		if ($contact['term-date'] > NULL_DATE) {
    +			 Contact::unmarkForArchival($contact);
    +		}
    +	}
    +
     	$update = (!$arr['private'] && (($arr["author-link"] === $arr["owner-link"]) || ($arr["parent-uri"] === $arr["uri"])));
     
     	// Is it a forum? Then we don't care about the rules from above
    diff --git a/src/Object/Contact.php b/src/Object/Contact.php
    index bd7cee7fb..64e61b9ce 100644
    --- a/src/Object/Contact.php
    +++ b/src/Object/Contact.php
    @@ -141,8 +141,8 @@ class Contact extends BaseObject
     	 */
     	public static function markForArchival(array $contact)
     	{
    -		// Contact already archived, nothing to do
    -		if ($contact['archive']) {
    +		// Contact already archived or "self" contact? => nothing to do
    +		if ($contact['archive'] || $contact['self']) {
     			return;
     		}
     
    @@ -150,7 +150,7 @@ class Contact extends BaseObject
     			dba::update('contact', array('term-date' => datetime_convert()), array('id' => $contact['id']));
     
     			if ($contact['url'] != '') {
    -				dba::update('contact', array('term-date' => datetime_convert()), array('`nurl` = ? AND `term-date` <= ?', normalise_link($contact['url']), NULL_DATE));
    +				dba::update('contact', array('term-date' => datetime_convert()), array('`nurl` = ? AND `term-date` <= ? AND NOT `self`', normalise_link($contact['url']), NULL_DATE));
     			}
     		} else {
     			/* @todo
    @@ -169,7 +169,7 @@ class Contact extends BaseObject
     				dba::update('contact', array('archive' => 1), array('id' => $contact['id']));
     
     				if ($contact['url'] != '') {
    -					dba::update('contact', array('archive' => 1), array('nurl' => normalise_link($contact['url'])));
    +					dba::update('contact', array('archive' => 1), array('nurl' => normalise_link($contact['url']), 'self' => false));
     				}
     			}
     		}
    
    From 9ffde01fc16f5c5ffa58a79a6b4ae51b3762ef4d Mon Sep 17 00:00:00 2001
    From: Michael 
    Date: Tue, 5 Dec 2017 21:30:38 +0000
    Subject: [PATCH 57/71] DBClean now works with the conversation table as well
    
    ---
     boot.php                |  4 ++--
     database.sql            |  5 +++--
     include/dbstructure.php |  1 +
     src/Worker/DBClean.php  | 44 ++++++++++++++++++++++++++++++-----------
     update.php              |  2 +-
     5 files changed, 40 insertions(+), 16 deletions(-)
    
    diff --git a/boot.php b/boot.php
    index 15dfec48b..eda8a4037 100644
    --- a/boot.php
    +++ b/boot.php
    @@ -44,7 +44,7 @@ define('FRIENDICA_PLATFORM',     'Friendica');
     define('FRIENDICA_CODENAME',     'Asparagus');
     define('FRIENDICA_VERSION',      '3.6-dev');
     define('DFRN_PROTOCOL_VERSION',  '2.23');
    -define('DB_UPDATE_VERSION',      1235);
    +define('DB_UPDATE_VERSION',      1236);
     
     /**
      * @brief Constant with a HTML line break.
    @@ -686,7 +686,7 @@ function update_db(App $a)
     				// Compare the current structure with the defined structure
     
     				$t = Config::get('database', 'dbupdate_' . DB_UPDATE_VERSION);
    -				if ($t !== false) {
    +				if (!is_null($t)) {
     					return;
     				}
     
    diff --git a/database.sql b/database.sql
    index e4e891e48..09f1a83cc 100644
    --- a/database.sql
    +++ b/database.sql
    @@ -1,6 +1,6 @@
     -- ------------------------------------------
     -- Friendica 3.6-dev (Asparagus)
    --- DB_UPDATE_VERSION 1235
    +-- DB_UPDATE_VERSION 1236
     -- ------------------------------------------
     
     
    @@ -216,7 +216,8 @@ CREATE TABLE IF NOT EXISTS `conversation` (
     	`source` mediumtext,
     	`received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
     	 PRIMARY KEY(`item-uri`),
    -	 INDEX `conversation-uri` (`conversation-uri`)
    +	 INDEX `conversation-uri` (`conversation-uri`),
    +	 INDEX `received` (`received`)
     ) DEFAULT COLLATE utf8mb4_general_ci;
     
     --
    diff --git a/include/dbstructure.php b/include/dbstructure.php
    index cb2883d40..3c620d7d7 100644
    --- a/include/dbstructure.php
    +++ b/include/dbstructure.php
    @@ -831,6 +831,7 @@ function db_definition() {
     			"indexes" => array(
     					"PRIMARY" => array("item-uri"),
     					"conversation-uri" => array("conversation-uri"),
    +					"received" => array("received"),
     					)
     			);
     	$database["event"] = array(
    diff --git a/src/Worker/DBClean.php b/src/Worker/DBClean.php
    index 7030081dc..dc2075f9a 100644
    --- a/src/Worker/DBClean.php
    +++ b/src/Worker/DBClean.php
    @@ -21,10 +21,10 @@ class DBClean {
     		$days = Config::get('system', 'dbclean-expire-days', 0);
     
     		if ($stage == 0) {
    -			for ($i = 1; $i <= 9; $i++) {
    +			for ($i = 1; $i <= 10; $i++) {
     				// Execute the background script for a step when it isn't finished.
     				// Execute step 8 and 9 only when $days is defined.
    -				if (!Config::get('system', 'finished-dbclean-'.$i, false) && (($i < 8) || ($days > 0))) {
    +				if (!Config::get('system', 'finished-dbclean-'.$i, false) && (($i < 8) || ($i > 9) || ($days > 0))) {
     					Worker::add(PRIORITY_LOW, 'DBClean', $i);
     				}
     			}
    @@ -39,15 +39,16 @@ class DBClean {
     	 *
     	 * Values for $stage:
     	 * ------------------
    -	 * 1:	Old global item entries from item table without user copy.
    -	 * 2:	Items without parents.
    -	 * 3:	Orphaned data from thread table.
    -	 * 4:	Orphaned data from notify table.
    -	 * 5:	Orphaned data from notify-threads table.
    -	 * 6:	Orphaned data from sign table.
    -	 * 7:	Orphaned data from term table.
    -	 * 8:	Expired threads.
    -	 * 9:	Old global item entries from expired threads
    +	 *  1:	Old global item entries from item table without user copy.
    +	 *  2:	Items without parents.
    +	 *  3:	Orphaned data from thread table.
    +	 *  4:	Orphaned data from notify table.
    +	 *  5:	Orphaned data from notify-threads table.
    +	 *  6:	Orphaned data from sign table.
    +	 *  7:	Orphaned data from term table.
    +	 *  8:	Expired threads.
    +	 *  9:	Old global item entries from expired threads.
    +	 * 10:	Old conversations.
     	 */
     	private static function removeOrphans($stage = 0) {
     		global $db;
    @@ -293,6 +294,27 @@ class DBClean {
     			logger("Done deleting ".$count." old global item entries from expired threads. Last ID: ".$last_id);
     
     			Config::set('system', 'dbclean-last-id-9', $last_id);
    +		} elseif ($stage == 10) {
    +			$last_id = Config::get('system', 'dbclean-last-id-10', 0);
    +
    +			logger("Deleting old conversations. Last created: ".$last_id);
    +			$r = dba::p("SELECT `received`, `item-uri` FROM `conversation`
    +					WHERE `received` < UTC_TIMESTAMP() - INTERVAL 90 DAY
    +					ORDER BY `received` LIMIT ".intval($limit));
    +			$count = dba::num_rows($r);
    +			if ($count > 0) {
    +				logger("found old conversations: ".$count);
    +				while ($orphan = dba::fetch($r)) {
    +					$last_id = $orphan["received"];
    +					dba::delete('conversation', array('item-uri' => $orphan["item-uri"]));
    +				}
    +			} else {
    +				logger("No old conversations found");
    +			}
    +			dba::close($r);
    +			logger("Done deleting ".$count." conversations. Last created: ".$last_id);
    +
    +			Config::set('system', 'dbclean-last-id-10', $last_id);
     		}
     
     		// Call it again if not all entries were purged
    diff --git a/update.php b/update.php
    index 326c08414..12a04995c 100644
    --- a/update.php
    +++ b/update.php
    @@ -1,6 +1,6 @@
     
    Date: Tue, 5 Dec 2017 21:54:13 +0000
    Subject: [PATCH 58/71] Removed some unused tables and functions
    
    ---
     database.sql            | 23 -----------------------
     include/dbstructure.php | 23 -----------------------
     include/fcontact.php    | 33 ---------------------------------
     3 files changed, 79 deletions(-)
     delete mode 100644 include/fcontact.php
    
    diff --git a/database.sql b/database.sql
    index 09f1a83cc..c058c06f5 100644
    --- a/database.sql
    +++ b/database.sql
    @@ -274,29 +274,6 @@ CREATE TABLE IF NOT EXISTS `fcontact` (
     	 UNIQUE INDEX `url` (`url`(190))
     ) DEFAULT COLLATE utf8mb4_general_ci;
     
    ---
    --- TABLE ffinder
    ---
    -CREATE TABLE IF NOT EXISTS `ffinder` (
    -	`id` int(10) unsigned NOT NULL auto_increment,
    -	`uid` int(10) unsigned NOT NULL DEFAULT 0,
    -	`cid` int(10) unsigned NOT NULL DEFAULT 0,
    -	`fid` int(10) unsigned NOT NULL DEFAULT 0,
    -	 PRIMARY KEY(`id`)
    -) DEFAULT COLLATE utf8mb4_general_ci;
    -
    ---
    --- TABLE fserver
    ---
    -CREATE TABLE IF NOT EXISTS `fserver` (
    -	`id` int(11) NOT NULL auto_increment,
    -	`server` varchar(255) NOT NULL DEFAULT '',
    -	`posturl` varchar(255) NOT NULL DEFAULT '',
    -	`key` text,
    -	 PRIMARY KEY(`id`),
    -	 INDEX `server` (`server`(32))
    -) DEFAULT COLLATE utf8mb4_general_ci;
    -
     --
     -- TABLE fsuggest
     --
    diff --git a/include/dbstructure.php b/include/dbstructure.php
    index 3c620d7d7..1e47ee9ed 100644
    --- a/include/dbstructure.php
    +++ b/include/dbstructure.php
    @@ -888,29 +888,6 @@ function db_definition() {
     					"url" => array("UNIQUE", "url(190)"),
     					)
     			);
    -	$database["ffinder"] = array(
    -			"fields" => array(
    -					"id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
    -					"uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
    -					"cid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
    -					"fid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("fcontact" => "id")),
    -					),
    -			"indexes" => array(
    -					"PRIMARY" => array("id"),
    -					)
    -			);
    -	$database["fserver"] = array(
    -			"fields" => array(
    -					"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
    -					"server" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
    -					"posturl" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
    -					"key" => array("type" => "text"),
    -					),
    -			"indexes" => array(
    -					"PRIMARY" => array("id"),
    -					"server" => array("server(32)"),
    -					)
    -			);
     	$database["fsuggest"] = array(
     			"fields" => array(
     					"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
    diff --git a/include/fcontact.php b/include/fcontact.php
    deleted file mode 100644
    index 7e93d067f..000000000
    --- a/include/fcontact.php
    +++ /dev/null
    @@ -1,33 +0,0 @@
    - $nurl, 'name' => $name, 'photo' => $photo));
    -
    -	if (DBM::is_result($r)) {
    -		$r = q("SELECT `id` FROM `fcontact` WHERE `url` = '%s' LIMIT 1",
    -			dbesc($nurl)
    -		);
    -		if (DBM::is_result($r))
    -			return $r[0]['id'];
    -	}
    -
    -	return 0;
    -}
    -
    -function ffinder_store($uid,$cid,$fid) {
    -	$r = dba::insert('ffinder', array('uid' => $uid, 'cid' => $cid, 'fid' => $fid));
    -	return $r;
    -}
    -
    
    From 45227a12a677d4fc4a83a105eb420070c340b091 Mon Sep 17 00:00:00 2001
    From: Michael 
    Date: Tue, 5 Dec 2017 22:20:49 +0000
    Subject: [PATCH 59/71] "item_id" and "spam" aren't used
    
    ---
     database.sql            | 16 ----------------
     include/dbstructure.php | 33 ---------------------------------
     include/items.php       |  1 -
     3 files changed, 50 deletions(-)
    
    diff --git a/database.sql b/database.sql
    index c058c06f5..b41c0bc54 100644
    --- a/database.sql
    +++ b/database.sql
    @@ -535,22 +535,6 @@ CREATE TABLE IF NOT EXISTS `item` (
     	 INDEX `uid_ownerlink` (`uid`,`owner-link`(190))
     ) DEFAULT COLLATE utf8mb4_general_ci;
     
    ---
    --- TABLE item_id
    ---
    -CREATE TABLE IF NOT EXISTS `item_id` (
    -	`id` int(11) NOT NULL auto_increment,
    -	`iid` int(11) NOT NULL DEFAULT 0,
    -	`uid` int(11) NOT NULL DEFAULT 0,
    -	`sid` varchar(255) NOT NULL DEFAULT '',
    -	`service` varchar(255) NOT NULL DEFAULT '',
    -	 PRIMARY KEY(`id`),
    -	 INDEX `uid` (`uid`),
    -	 INDEX `sid` (`sid`(32)),
    -	 INDEX `service` (`service`(32)),
    -	 INDEX `iid` (`iid`)
    -) DEFAULT COLLATE utf8mb4_general_ci;
    -
     --
     -- TABLE locks
     --
    diff --git a/include/dbstructure.php b/include/dbstructure.php
    index 1e47ee9ed..dae54835f 100644
    --- a/include/dbstructure.php
    +++ b/include/dbstructure.php
    @@ -1149,22 +1149,6 @@ function db_definition() {
     					"uid_ownerlink" => array("uid","owner-link(190)"),
     					)
     			);
    -	$database["item_id"] = array(
    -			"fields" => array(
    -					"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
    -					"iid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("item" => "id")),
    -					"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
    -					"sid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
    -					"service" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
    -					),
    -			"indexes" => array(
    -					"PRIMARY" => array("id"),
    -					"uid" => array("uid"),
    -					"sid" => array("sid(32)"),
    -					"service" => array("service(32)"),
    -					"iid" => array("iid"),
    -					)
    -			);
     	$database["locks"] = array(
     			"fields" => array(
     					"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
    @@ -1539,23 +1523,6 @@ function db_definition() {
     					"iid" => array("UNIQUE", "iid"),
     					)
     			);
    -	$database["spam"] = array(
    -			"fields" => array(
    -					"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
    -					"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
    -					"spam" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
    -					"ham" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
    -					"term" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
    -					"date" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
    -					),
    -			"indexes" => array(
    -					"PRIMARY" => array("id"),
    -					"uid" => array("uid"),
    -					"spam" => array("spam"),
    -					"ham" => array("ham"),
    -					"term" => array("term(32)"),
    -					)
    -			);
     	$database["term"] = array(
     			"fields" => array(
     					"tid" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
    diff --git a/include/items.php b/include/items.php
    index 63c321819..61a9c7a1f 100644
    --- a/include/items.php
    +++ b/include/items.php
    @@ -2233,7 +2233,6 @@ function drop_item($id, $interactive = true) {
     
     		// Now delete them
     		if ($parentid != "") {
    -			$r = q("DELETE FROM `item_id` WHERE `iid` IN (%s)", dbesc($parentid));
     			$r = q("DELETE FROM `sign` WHERE `iid` IN (%s)", dbesc($parentid));
     		}
     
    
    From 0fb6150fae94c6787f767ba60572cd24986a10d9 Mon Sep 17 00:00:00 2001
    From: Michael 
    Date: Tue, 5 Dec 2017 22:22:21 +0000
    Subject: [PATCH 60/71] Updated database.sql
    
    ---
     database.sql | 17 -----------------
     1 file changed, 17 deletions(-)
    
    diff --git a/database.sql b/database.sql
    index b41c0bc54..1ff770641 100644
    --- a/database.sql
    +++ b/database.sql
    @@ -909,23 +909,6 @@ CREATE TABLE IF NOT EXISTS `sign` (
     	 UNIQUE INDEX `iid` (`iid`)
     ) DEFAULT COLLATE utf8mb4_general_ci;
     
    ---
    --- TABLE spam
    ---
    -CREATE TABLE IF NOT EXISTS `spam` (
    -	`id` int(11) NOT NULL auto_increment,
    -	`uid` int(11) NOT NULL DEFAULT 0,
    -	`spam` int(11) NOT NULL DEFAULT 0,
    -	`ham` int(11) NOT NULL DEFAULT 0,
    -	`term` varchar(255) NOT NULL DEFAULT '',
    -	`date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
    -	 PRIMARY KEY(`id`),
    -	 INDEX `uid` (`uid`),
    -	 INDEX `spam` (`spam`),
    -	 INDEX `ham` (`ham`),
    -	 INDEX `term` (`term`(32))
    -) DEFAULT COLLATE utf8mb4_general_ci;
    -
     --
     -- TABLE term
     --
    
    From 418365b30e126565643ca3139c938e462cac10d8 Mon Sep 17 00:00:00 2001
    From: Michael 
    Date: Wed, 6 Dec 2017 14:22:03 +0000
    Subject: [PATCH 61/71] DBClean now runs as long as there are entries to be
     deleted
    
    ---
     src/Worker/DBClean.php | 39 ++++++++++++++++++++++++++++-----------
     1 file changed, 28 insertions(+), 11 deletions(-)
    
    diff --git a/src/Worker/DBClean.php b/src/Worker/DBClean.php
    index dc2075f9a..391c590b4 100644
    --- a/src/Worker/DBClean.php
    +++ b/src/Worker/DBClean.php
    @@ -21,18 +21,25 @@ class DBClean {
     		$days = Config::get('system', 'dbclean-expire-days', 0);
     
     		if ($stage == 0) {
    -			for ($i = 1; $i <= 10; $i++) {
    -				// Execute the background script for a step when it isn't finished.
    -				// Execute step 8 and 9 only when $days is defined.
    -				if (!Config::get('system', 'finished-dbclean-'.$i, false) && (($i < 8) || ($i > 9) || ($days > 0))) {
    -					Worker::add(PRIORITY_LOW, 'DBClean', $i);
    -				}
    -			}
    +			self::forkCleanProcess();
     		} else {
     			self::removeOrphans($stage);
     		}
     	}
     
    +	/**
    +	 * @brief Fork the different DBClean processes
    +	 */
    +	private static function forkCleanProcess() {
    +		for ($i = 1; $i <= 10; $i++) {
    +			// Execute the background script for a step when it isn't finished.
    +			// Execute step 8 and 9 only when $days is defined.
    +			if (!Config::get('system', 'finished-dbclean-'.$i, false) && (($i < 8) || ($i > 9) || ($days > 0))) {
    +				Worker::add(PRIORITY_LOW, 'DBClean', $i);
    +			}
    +		}
    +	}
    +
     	/**
     	 * @brief Remove orphaned database entries
     	 * @param integer $stage What should be deleted?
    @@ -50,7 +57,7 @@ class DBClean {
     	 *  9:	Old global item entries from expired threads.
     	 * 10:	Old conversations.
     	 */
    -	private static function removeOrphans($stage = 0) {
    +	private static function removeOrphans($stage) {
     		global $db;
     
     		$count = 0;
    @@ -76,6 +83,7 @@ class DBClean {
     					$last_id = $orphan["id"];
     					dba::delete('item', array('id' => $orphan["id"]));
     				}
    +				Worker::add(PRIORITY_MEDIUM, 'DBClean', 1, $last_id);
     			} else {
     				logger("No global item orphans found");
     			}
    @@ -97,6 +105,7 @@ class DBClean {
     					$last_id = $orphan["id"];
     					dba::delete('item', array('id' => $orphan["id"]));
     				}
    +				Worker::add(PRIORITY_MEDIUM, 'DBClean', 2, $last_id);
     			} else {
     				logger("No item orphans without parents found");
     			}
    @@ -122,6 +131,7 @@ class DBClean {
     					$last_id = $orphan["iid"];
     					dba::delete('thread', array('iid' => $orphan["iid"]));
     				}
    +				Worker::add(PRIORITY_MEDIUM, 'DBClean', 3, $last_id);
     			} else {
     				logger("No thread orphans found");
     			}
    @@ -147,6 +157,7 @@ class DBClean {
     					$last_id = $orphan["id"];
     					dba::delete('notify', array('iid' => $orphan["iid"]));
     				}
    +				Worker::add(PRIORITY_MEDIUM, 'DBClean', 4, $last_id);
     			} else {
     				logger("No notify orphans found");
     			}
    @@ -172,6 +183,7 @@ class DBClean {
     					$last_id = $orphan["id"];
     					dba::delete('notify-threads', array('id' => $orphan["id"]));
     				}
    +				Worker::add(PRIORITY_MEDIUM, 'DBClean', 5, $last_id);
     			} else {
     				logger("No notify-threads orphans found");
     			}
    @@ -197,6 +209,7 @@ class DBClean {
     					$last_id = $orphan["id"];
     					dba::delete('sign', array('iid' => $orphan["iid"]));
     				}
    +				Worker::add(PRIORITY_MEDIUM, 'DBClean', 6, $last_id);
     			} else {
     				logger("No sign orphans found");
     			}
    @@ -222,6 +235,7 @@ class DBClean {
     					$last_id = $orphan["tid"];
     					dba::delete('term', array('oid' => $orphan["oid"]));
     				}
    +				Worker::add(PRIORITY_MEDIUM, 'DBClean', 7, $last_id);
     			} else {
     				logger("No term orphans found");
     			}
    @@ -260,6 +274,7 @@ class DBClean {
     					$last_id = $thread["iid"];
     					dba::delete('thread', array('iid' => $thread["iid"]));
     				}
    +				Worker::add(PRIORITY_MEDIUM, 'DBClean', 8, $last_id);
     			} else {
     				logger("No expired threads found");
     			}
    @@ -287,6 +302,7 @@ class DBClean {
     					$last_id = $orphan["id"];
     					dba::delete('item', array('id' => $orphan["id"]));
     				}
    +				Worker::add(PRIORITY_MEDIUM, 'DBClean', 9, $last_id);
     			} else {
     				logger("No global item entries from expired threads");
     			}
    @@ -308,6 +324,7 @@ class DBClean {
     					$last_id = $orphan["received"];
     					dba::delete('conversation', array('item-uri' => $orphan["item-uri"]));
     				}
    +				Worker::add(PRIORITY_MEDIUM, 'DBClean', 10, $last_id);
     			} else {
     				logger("No old conversations found");
     			}
    @@ -318,8 +335,8 @@ class DBClean {
     		}
     
     		// Call it again if not all entries were purged
    -		if (($stage != 0) && ($count > 0)) {
    -			Worker::add(PRIORITY_MEDIUM, 'dbclean');
    -		}
    +		//if ($count > 0) {
    +		//	Worker::add(PRIORITY_MEDIUM, 'DBClean');
    +		//}
     	}
     }
    
    From ad5c263dbf9f0806d0d6c674dd5be13484a3eb23 Mon Sep 17 00:00:00 2001
    From: Michael 
    Date: Wed, 6 Dec 2017 14:23:38 +0000
    Subject: [PATCH 62/71] Reduced "dbclean" calls
    
    ---
     src/Worker/Cron.php    | 27 ++++++++++++++++++++-------
     src/Worker/OnePoll.php | 36 +++++++++++++++++-------------------
     2 files changed, 37 insertions(+), 26 deletions(-)
    
    diff --git a/src/Worker/Cron.php b/src/Worker/Cron.php
    index 5814c0548..db0d518cc 100644
    --- a/src/Worker/Cron.php
    +++ b/src/Worker/Cron.php
    @@ -153,14 +153,13 @@ Class Cron {
     			: ''
     		);
     
    -		$contacts = q("SELECT `contact`.`id`, `contact`.`nick`, `contact`.`name`, `contact`.`network`,
    -					`contact`.`last-update`, `contact`.`priority`, `contact`.`subhub`
    +		$contacts = q("SELECT `contact`.`id`, `contact`.`nick`, `contact`.`name`, `contact`.`network`, `contact`.`archive`,
    +					`contact`.`last-update`, `contact`.`priority`, `contact`.`rel`, `contact`.`subhub`
     				FROM `user`
     				STRAIGHT_JOIN `contact`
     				ON `contact`.`uid` = `user`.`uid` AND `contact`.`poll` != ''
     					AND `contact`.`network` IN ('%s', '%s', '%s', '%s', '%s') $sql_extra
    -					AND NOT `contact`.`self` AND NOT `contact`.`blocked` AND NOT `contact`.`readonly`
    -					AND NOT `contact`.`archive`
    +					AND NOT `contact`.`self` AND NOT `contact`.`blocked`
     				WHERE NOT `user`.`account_expired` AND NOT `user`.`account_removed` $abandon_sql",
     			dbesc(NETWORK_DFRN),
     			dbesc(NETWORK_OSTATUS),
    @@ -179,6 +178,7 @@ Class Cron {
     				$contact['last-update'] = NULL_DATE;
     			}
     
    +			// Friendica and OStatus are checked once a day
     			if (in_array($contact['network'], array(NETWORK_DFRN, NETWORK_OSTATUS))) {
     				$contact['priority'] = 2;
     			}
    @@ -191,7 +191,17 @@ Class Cron {
     				 * changed. We will only update hubs once a day, regardless of 'pushpoll_frequency'.
     				 */
     				$poll_interval = Config::get('system', 'pushpoll_frequency');
    -				$contact['priority'] = (($poll_interval !== false) ? intval($poll_interval) : 3);
    +				$contact['priority'] = (!is_null($poll_interval) ? intval($poll_interval) : 3);
    +			}
    +
    +			// Check Diaspora contacts or followers once a week
    +			if (($contact["network"] == NETWORK_DIASPORA) || ($contact["rel"] == CONTACT_IS_FOLLOWER)) {
    +				$contact['priority'] = 4;
    +			}
    +
    +			// Check archived contacts once a month
    +			if ($contact['archive']) {
    +				$contact['priority'] = 5;
     			}
     
     			if (($contact['priority'] >= 0) && !$force) {
    @@ -240,13 +250,16 @@ Class Cron {
     				}
     			}
     
    -			logger("Polling " . $contact["network"] . " " . $contact["id"] . " " . $contact["nick"] . " " . $contact["name"]);
    -
     			if (($contact['network'] == NETWORK_FEED) && ($contact['priority'] <= 3)) {
     				$priority = PRIORITY_MEDIUM;
    +			} elseif ($contact['archive']) {
    +				$priority = PRIORITY_NEGLIGIBLE;
     			} else {
     				$priority = PRIORITY_LOW;
     			}
    +
    +			logger("Polling " . $contact["network"] . " " . $contact["id"] . " " . $contact['priority'] . " " . $contact["nick"] . " " . $contact["name"]);
    +
     			Worker::add(array('priority' => $priority, 'dont_fork' => true), 'OnePoll', (int)$contact['id']);
     		}
     	}
    diff --git a/src/Worker/OnePoll.php b/src/Worker/OnePoll.php
    index 2d742fc56..c1fb5350c 100644
    --- a/src/Worker/OnePoll.php
    +++ b/src/Worker/OnePoll.php
    @@ -63,27 +63,25 @@ Class OnePoll
     			}
     		}
     
    -		// Diaspora users and followers we only check if they still exist.
    -		if (($contact["network"] == NETWORK_DIASPORA) || ($contact["rel"] == CONTACT_IS_FOLLOWER)) {
    -			if (PortableContact::updateNeeded($contact["created"], $contact["last-item"], $contact["failure_update"], $contact["success_update"])) {
    -				$last_updated = PortableContact::lastUpdated($contact["url"]);
    -				$updated = datetime_convert();
    -				if ($last_updated) {
    -					logger('Contact '.$contact['id'].' had last update on '.$last_updated, LOGGER_DEBUG);
    +		// Diaspora users, archived users and followers are only checked if they still exist.
    +		if ($contact['archive'] || ($contact["network"] == NETWORK_DIASPORA) || ($contact["rel"] == CONTACT_IS_FOLLOWER)) {
    +			$last_updated = PortableContact::lastUpdated($contact["url"]);
    +			$updated = datetime_convert();
    +			if ($last_updated) {
    +				logger('Contact '.$contact['id'].' had last update on '.$last_updated, LOGGER_DEBUG);
     
    -					// The last public item can be older than the last item we got
    -					if ($last_updated < $contact['last-item']) {
    -						$last_updated = $contact['last-item'];
    -					}
    -
    -					$fields = array('last-item' => $last_updated, 'last-update' => $updated, 'success_update' => $updated);
    -					self::updateContact($contact, $fields);
    -					Contact::unmarkForArchival($contact);
    -				} else {
    -					self::updateContact($contact, array('last-update' => $updated, 'failure_update' => $updated));
    -					Contact::markForArchival($contact);
    -					logger('Contact '.$contact['id'].' is marked for archival', LOGGER_DEBUG);
    +				// The last public item can be older than the last item we got
    +				if ($last_updated < $contact['last-item']) {
    +					$last_updated = $contact['last-item'];
     				}
    +
    +				$fields = array('last-item' => $last_updated, 'last-update' => $updated, 'success_update' => $updated);
    +				self::updateContact($contact, $fields);
    +				Contact::unmarkForArchival($contact);
    +			} else {
    +				self::updateContact($contact, array('last-update' => $updated, 'failure_update' => $updated));
    +				Contact::markForArchival($contact);
    +				logger('Contact '.$contact['id'].' is marked for archival', LOGGER_DEBUG);
     			}
     			return;
     		}
    
    From f1f222c63307303c28cce755924b71481c84d734 Mon Sep 17 00:00:00 2001
    From: Michael 
    Date: Wed, 6 Dec 2017 14:30:07 +0000
    Subject: [PATCH 63/71] Removed unused code
    
    ---
     src/Worker/DBClean.php | 5 -----
     1 file changed, 5 deletions(-)
    
    diff --git a/src/Worker/DBClean.php b/src/Worker/DBClean.php
    index 391c590b4..40883d513 100644
    --- a/src/Worker/DBClean.php
    +++ b/src/Worker/DBClean.php
    @@ -333,10 +333,5 @@ class DBClean {
     
     			Config::set('system', 'dbclean-last-id-10', $last_id);
     		}
    -
    -		// Call it again if not all entries were purged
    -		//if ($count > 0) {
    -		//	Worker::add(PRIORITY_MEDIUM, 'DBClean');
    -		//}
     	}
     }
    
    From 7099a54b3d209bd5eb04613010ac3484563f0c45 Mon Sep 17 00:00:00 2001
    From: Michael 
    Date: Wed, 6 Dec 2017 16:50:52 +0000
    Subject: [PATCH 64/71] Cut and paste is always fun
    
    ---
     src/Worker/DBClean.php | 6 +++---
     1 file changed, 3 insertions(+), 3 deletions(-)
    
    diff --git a/src/Worker/DBClean.php b/src/Worker/DBClean.php
    index 40883d513..45a080400 100644
    --- a/src/Worker/DBClean.php
    +++ b/src/Worker/DBClean.php
    @@ -17,9 +17,6 @@ class DBClean {
     			return;
     		}
     
    -		// Get the expire days for step 8 and 9
    -		$days = Config::get('system', 'dbclean-expire-days', 0);
    -
     		if ($stage == 0) {
     			self::forkCleanProcess();
     		} else {
    @@ -31,6 +28,9 @@ class DBClean {
     	 * @brief Fork the different DBClean processes
     	 */
     	private static function forkCleanProcess() {
    +		// Get the expire days for step 8 and 9
    +		$days = Config::get('system', 'dbclean-expire-days', 0);
    +
     		for ($i = 1; $i <= 10; $i++) {
     			// Execute the background script for a step when it isn't finished.
     			// Execute step 8 and 9 only when $days is defined.
    
    From cadfef63c417e0c75994da58d8f95a9993803d20 Mon Sep 17 00:00:00 2001
    From: Adam Magness 
    Date: Wed, 6 Dec 2017 14:57:06 -0500
    Subject: [PATCH 65/71] Update false evaluations
    
    === false and !== false to is_null where appropriate.
    ---
     boot.php                         | 2 +-
     include/nav.php                  | 2 +-
     include/network.php              | 2 ++
     src/Content/Feature.php          | 8 +++++---
     src/Network/FKOAuthDataStore.php | 2 +-
     src/Worker/OnePoll.php           | 2 +-
     view/theme/vier/theme.php        | 4 ++--
     7 files changed, 13 insertions(+), 9 deletions(-)
    
    diff --git a/boot.php b/boot.php
    index eda8a4037..c6f7b1e20 100644
    --- a/boot.php
    +++ b/boot.php
    @@ -742,7 +742,7 @@ function run_update_function($x)
     		// delete the config entry to try again.
     
     		$t = Config::get('database', 'update_' . $x);
    -		if ($t !== false) {
    +		if (!is_null($t)) {
     			return false;
     		}
     		Config::set('database', 'update_' . $x, time());
    diff --git a/include/nav.php b/include/nav.php
    index f2bf161f9..58ec150e7 100644
    --- a/include/nav.php
    +++ b/include/nav.php
    @@ -209,7 +209,7 @@ function nav_info(App $a)
     
     	// Provide a banner/logo/whatever
     	$banner = Config::get('system', 'banner');
    -	if ($banner === false) {
    +	if (is_null($banner)) {
     		$banner = 'logoFriendica';
     	}
     
    diff --git a/include/network.php b/include/network.php
    index 52e340957..06649554b 100644
    --- a/include/network.php
    +++ b/include/network.php
    @@ -126,6 +126,7 @@ function z_fetch_url($url, $binary = false, &$redirects = 0, $opts = array())
     	if (x($opts, 'timeout')) {
     		@curl_setopt($ch, CURLOPT_TIMEOUT, $opts['timeout']);
     	} else {
    +		// if Config::get returns null, intval will be 0 which will also evaluate to false
     		$curl_time = intval(Config::get('system', 'curl_timeout'));
     		@curl_setopt($ch, CURLOPT_TIMEOUT, (($curl_time !== false) ? $curl_time : 60));
     	}
    @@ -302,6 +303,7 @@ function post_url($url, $params, $headers = null, &$redirects = 0, $timeout = 0)
     	if (intval($timeout)) {
     		curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
     	} else {
    +		// if Config::get returns null, intval will be 0 which will also evaluate to false
     		$curl_time = intval(Config::get('system', 'curl_timeout'));
     		curl_setopt($ch, CURLOPT_TIMEOUT, (($curl_time !== false) ? $curl_time : 60));
     	}
    diff --git a/src/Content/Feature.php b/src/Content/Feature.php
    index 864c07a0d..f17b649ee 100644
    --- a/src/Content/Feature.php
    +++ b/src/Content/Feature.php
    @@ -23,13 +23,15 @@ class Feature
     	{
     		$x = Config::get('feature_lock', $feature, false);
     
    -		if ($x === false) {
    +		if (is_null($x)) {
     			$x = PConfig::get($uid, 'feature', $feature, false);
     		}
    -		if ($x === false) {
    +
    +		if (is_null($x)) {
     			$x = Config::get('feature', $feature, false);
     		}
    -		if ($x === false) {
    +
    +		if (is_null($x)) {
     			$x = self::getDefault($feature);
     		}
     
    diff --git a/src/Network/FKOAuthDataStore.php b/src/Network/FKOAuthDataStore.php
    index 126f140bd..d7fa14518 100644
    --- a/src/Network/FKOAuthDataStore.php
    +++ b/src/Network/FKOAuthDataStore.php
    @@ -171,7 +171,7 @@ class FKOAuthDataStore extends OAuthDataStore
     		dba::delete('tokens', array('id' => $token->key));
     
     
    -		if (!is_null($ret) && $uverifier !== false) {
    +		if (!is_null($ret) && !is_null($uverifier)) {
     			Config::delete("oauth", $verifier);
     		}
     
    diff --git a/src/Worker/OnePoll.php b/src/Worker/OnePoll.php
    index c1fb5350c..c3528b623 100644
    --- a/src/Worker/OnePoll.php
    +++ b/src/Worker/OnePoll.php
    @@ -92,7 +92,7 @@ Class OnePoll
     
     		if ($contact['subhub']) {
     			$poll_interval = Config::get('system', 'pushpoll_frequency');
    -			$contact['priority'] = (($poll_interval !== false) ? intval($poll_interval) : 3);
    +			$contact['priority'] = ((!is_null($poll_interval)) ? intval($poll_interval) : 3);
     			$hub_update = false;
     
     			if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 day")) {
    diff --git a/view/theme/vier/theme.php b/view/theme/vier/theme.php
    index a8654f743..0f8120089 100644
    --- a/view/theme/vier/theme.php
    +++ b/view/theme/vier/theme.php
    @@ -110,13 +110,13 @@ EOT;
     function get_vier_config($key, $default = false, $admin = false) {
     	if (local_user() && !$admin) {
     		$result = PConfig::get(local_user(), "vier", $key);
    -		if ($result !== false) {
    +		if (!is_null($result)) {
     			return $result;
     		}
     	}
     
     	$result = Config::get("vier", $key);
    -	if ($result !== false) {
    +	if (!is_null($result)) {
     		return $result;
     	}
     
    
    From 925c03fda8e6e14b68011570968c88f40605da5d Mon Sep 17 00:00:00 2001
    From: Michael 
    Date: Wed, 6 Dec 2017 20:09:59 +0000
    Subject: [PATCH 66/71] Retrieve data about Mastodon servers
    
    ---
     doc/htconfig.md                  |  1 +
     src/Protocol/PortableContact.php | 19 +++++++++++--------
     2 files changed, 12 insertions(+), 8 deletions(-)
    
    diff --git a/doc/htconfig.md b/doc/htconfig.md
    index 3f5b28b91..10536141c 100644
    --- a/doc/htconfig.md
    +++ b/doc/htconfig.md
    @@ -46,6 +46,7 @@ Example: To set the directory value please add this line to your .htconfig.php:
     * **frontend_worker_timeout** - Value in minutes after we think that a frontend task was killed by the webserver. Default value is 10.
     * **hsts** (Boolean) - Enables the sending of HTTP Strict Transport Security headers
     * **ignore_cache** (Boolean) - For development only. Disables the item cache.
    +* **instances_social_key** - Key to the API of https://instances.social which retrieves data about mastodon servers.
     * **ipv4_resolve** (Boolean) - Resolve IPV4 addresses only. Don't resolve to IPV6. Default value is false.
     * **like_no_comment** (Boolean) - Don't update the "commented" value of an item when it is liked.
     * **local_block** (Boolean) - Used in conjunction with "block_public".
    diff --git a/src/Protocol/PortableContact.php b/src/Protocol/PortableContact.php
    index feb4dfdc8..84bfd4c4f 100644
    --- a/src/Protocol/PortableContact.php
    +++ b/src/Protocol/PortableContact.php
    @@ -1343,14 +1343,17 @@ class PortableContact
     
     		// Disvover Mastodon servers
     		if (!Config::get('system', 'ostatus_disabled')) {
    -			$serverdata = fetch_url("https://instances.mastodon.xyz/instances.json");
    -
    -			if ($serverdata) {
    -				$servers = json_decode($serverdata);
    -
    -				foreach ($servers as $server) {
    -					$url = (is_null($server->https_score) ? 'http' : 'https').'://'.$server->name;
    -					Worker::add(PRIORITY_LOW, "DiscoverPoCo", "server", $url);
    +			$accesstoken = Config::get('system', 'instances_social_key');
    +			if (!empty($accesstoken)) {
    +				$api = 'https://instances.social/api/1.0/instances/list?count=0';
    +				$header = array('Authorization: Bearer '.$accesstoken);
    +				$serverdata = z_fetch_url($api, false, $redirects, ['headers' => $header]);
    +				if ($serverdata['success']) {
    +				        $servers = json_decode($serverdata['body']);
    +				        foreach ($servers->instances as $server) {
    +						$url = (is_null($server->https_score) ? 'http' : 'https').'://'.$server->name;
    +						Worker::add(PRIORITY_LOW, "DiscoverPoCo", "server", $url);
    +					}
     				}
     			}
     		}
    
    From 3e5a518591fb73b28bf5f8e0fac44e8440ae3c40 Mon Sep 17 00:00:00 2001
    From: Adam Magness 
    Date: Wed, 6 Dec 2017 15:18:45 -0500
    Subject: [PATCH 67/71] Undo changes to Feature
    
    the evaluations were correct before.
    ---
     src/Content/Feature.php | 6 +++---
     1 file changed, 3 insertions(+), 3 deletions(-)
    
    diff --git a/src/Content/Feature.php b/src/Content/Feature.php
    index f17b649ee..c98a53c54 100644
    --- a/src/Content/Feature.php
    +++ b/src/Content/Feature.php
    @@ -23,15 +23,15 @@ class Feature
     	{
     		$x = Config::get('feature_lock', $feature, false);
     
    -		if (is_null($x)) {
    +		if ($x === false) {
     			$x = PConfig::get($uid, 'feature', $feature, false);
     		}
     
    -		if (is_null($x)) {
    +		if ($x === false) {
     			$x = Config::get('feature', $feature, false);
     		}
     
    -		if (is_null($x)) {
    +		if ($x === false) {
     			$x = self::getDefault($feature);
     		}
     
    
    From e272a5b8470bb9f3e75f63cbbb2fbe300c84d96b Mon Sep 17 00:00:00 2001
    From: Michael 
    Date: Wed, 6 Dec 2017 20:23:39 +0000
    Subject: [PATCH 68/71] Added documentation
    
    ---
     doc/htconfig.md | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/doc/htconfig.md b/doc/htconfig.md
    index 10536141c..b78cf7fe3 100644
    --- a/doc/htconfig.md
    +++ b/doc/htconfig.md
    @@ -46,7 +46,7 @@ Example: To set the directory value please add this line to your .htconfig.php:
     * **frontend_worker_timeout** - Value in minutes after we think that a frontend task was killed by the webserver. Default value is 10.
     * **hsts** (Boolean) - Enables the sending of HTTP Strict Transport Security headers
     * **ignore_cache** (Boolean) - For development only. Disables the item cache.
    -* **instances_social_key** - Key to the API of https://instances.social which retrieves data about mastodon servers.
    +* **instances_social_key** - Key to the API of https://instances.social which retrieves data about mastodon servers. See https://instances.social/api/token for getting an API key.
     * **ipv4_resolve** (Boolean) - Resolve IPV4 addresses only. Don't resolve to IPV6. Default value is false.
     * **like_no_comment** (Boolean) - Don't update the "commented" value of an item when it is liked.
     * **local_block** (Boolean) - Used in conjunction with "block_public".
    
    From 71911a69898a9b42192406ff4b8c2b58f07b2e1a Mon Sep 17 00:00:00 2001
    From: Adam Magness 
    Date: Wed, 6 Dec 2017 15:25:36 -0500
    Subject: [PATCH 69/71] Use default value
    
    use the default value parameter correctly!
    ---
     include/network.php    | 10 ++++------
     src/Worker/OnePoll.php |  4 ++--
     2 files changed, 6 insertions(+), 8 deletions(-)
    
    diff --git a/include/network.php b/include/network.php
    index 06649554b..45f5d4e79 100644
    --- a/include/network.php
    +++ b/include/network.php
    @@ -126,9 +126,8 @@ function z_fetch_url($url, $binary = false, &$redirects = 0, $opts = array())
     	if (x($opts, 'timeout')) {
     		@curl_setopt($ch, CURLOPT_TIMEOUT, $opts['timeout']);
     	} else {
    -		// if Config::get returns null, intval will be 0 which will also evaluate to false
    -		$curl_time = intval(Config::get('system', 'curl_timeout'));
    -		@curl_setopt($ch, CURLOPT_TIMEOUT, (($curl_time !== false) ? $curl_time : 60));
    +		$curl_time = Config::get('system', 'curl_timeout', 60);
    +		@curl_setopt($ch, CURLOPT_TIMEOUT, intval($curl_time));
     	}
     
     	// by default we will allow self-signed certs
    @@ -303,9 +302,8 @@ function post_url($url, $params, $headers = null, &$redirects = 0, $timeout = 0)
     	if (intval($timeout)) {
     		curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
     	} else {
    -		// if Config::get returns null, intval will be 0 which will also evaluate to false
    -		$curl_time = intval(Config::get('system', 'curl_timeout'));
    -		curl_setopt($ch, CURLOPT_TIMEOUT, (($curl_time !== false) ? $curl_time : 60));
    +		$curl_time = Config::get('system', 'curl_timeout', 60);
    +		curl_setopt($ch, CURLOPT_TIMEOUT, intval($curl_time));
     	}
     
     	if (defined('LIGHTTPD')) {
    diff --git a/src/Worker/OnePoll.php b/src/Worker/OnePoll.php
    index c3528b623..1190c77f5 100644
    --- a/src/Worker/OnePoll.php
    +++ b/src/Worker/OnePoll.php
    @@ -91,8 +91,8 @@ Class OnePoll
     		$t = $contact['last-update'];
     
     		if ($contact['subhub']) {
    -			$poll_interval = Config::get('system', 'pushpoll_frequency');
    -			$contact['priority'] = ((!is_null($poll_interval)) ? intval($poll_interval) : 3);
    +			$poll_interval = Config::get('system', 'pushpoll_frequency', 3);
    +			$contact['priority'] = intval($poll_interval);
     			$hub_update = false;
     
     			if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 day")) {
    
    From 4268f424123765f82b05d4665b3834514549c951 Mon Sep 17 00:00:00 2001
    From: Michael 
    Date: Wed, 6 Dec 2017 20:26:33 +0000
    Subject: [PATCH 70/71] Grammar ...
    
    ---
     doc/htconfig.md | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/doc/htconfig.md b/doc/htconfig.md
    index b78cf7fe3..4d7816f49 100644
    --- a/doc/htconfig.md
    +++ b/doc/htconfig.md
    @@ -46,7 +46,7 @@ Example: To set the directory value please add this line to your .htconfig.php:
     * **frontend_worker_timeout** - Value in minutes after we think that a frontend task was killed by the webserver. Default value is 10.
     * **hsts** (Boolean) - Enables the sending of HTTP Strict Transport Security headers
     * **ignore_cache** (Boolean) - For development only. Disables the item cache.
    -* **instances_social_key** - Key to the API of https://instances.social which retrieves data about mastodon servers. See https://instances.social/api/token for getting an API key.
    +* **instances_social_key** - Key to the API of https://instances.social which retrieves data about mastodon servers. See https://instances.social/api/token to get an API key.
     * **ipv4_resolve** (Boolean) - Resolve IPV4 addresses only. Don't resolve to IPV6. Default value is false.
     * **like_no_comment** (Boolean) - Don't update the "commented" value of an item when it is liked.
     * **local_block** (Boolean) - Used in conjunction with "block_public".
    
    From 90292d761dd9691e4b74c092e414149f80193125 Mon Sep 17 00:00:00 2001
    From: hoergen 
    Date: Thu, 7 Dec 2017 01:56:21 +0100
    Subject: [PATCH 71/71] customized and colored buttons
    
    ---
     view/theme/vier/plusminus.css | 45 +++++++++++++++++++++++++++++++++++
     1 file changed, 45 insertions(+)
    
    diff --git a/view/theme/vier/plusminus.css b/view/theme/vier/plusminus.css
    index 0b694c95f..1be216f87 100644
    --- a/view/theme/vier/plusminus.css
    +++ b/view/theme/vier/plusminus.css
    @@ -263,6 +263,10 @@ div.pager, ul.tabs {
     
     .wall-item-network { font-size:10px; }
     
    +.contact-photo-wrapper .mframe .p-author .h-card {
    +  width: 65px;
    +}
    +
     .shared-time { font-size: 10px; }
     
     .mention { font-size:12px;}
    @@ -461,3 +465,44 @@ ul.menu-popup a {
       padding: 0 0 0 5px;
     }
     
    +/* Growl Popup */
    +
    +.jGrowl, .notice * {
    +  color: white;
    +}
    +
    +/* Buttons */
    +
    +input[type=submit] {
    +  padding:0px 20px; 
    +  color:white;
    +  background:#6c82ff; 
    +  border:1px solid darkgrey;
    +  cursor:pointer;
    +  -webkit-border-radius: 5px;
    +  border-radius: 5px; 
    +  -webkit-transition-duration: 0.4s; /* Safari */
    +  transition-duration: 0.4s;
    +  box-shadow: 2px 2px 15px 0 rgba(0,0,0,0.24);
    +}
    +
    +input[type=submit]:hover {
    +  background:#0026ff; 
    +
    +}
    +
    +input[type=text], input[type=password], input[type=email], input[type=url] {
    +  padding:2px 2px; 
    +  background:white; 
    +  border:1px solid darkgrey;
    +  cursor:pointer;
    +  -webkit-border-radius: 5px;
    +  border-radius: 5px; 
    +  -webkit-transition-duration: 0.4s; /* Safari */
    +  transition-duration: 0.4s;
    +}
    +
    +input[type=text]:focus, input[type=password]:focus, input[type=email]:focus, input[type=url]:focus {
    +  background-color:#eef3ff;
    +}
    +