From 30cb37cda5e347bca8634c8222d90ef136a3b833 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Tue, 19 Dec 2017 14:20:32 +0100 Subject: [PATCH 01/37] Implement saved_searches/list API --- doc/api.md | 7 ++++++- include/api.php | 30 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/doc/api.md b/doc/api.md index d756e81a4..3a2740764 100644 --- a/doc/api.md +++ b/doc/api.md @@ -615,6 +615,12 @@ This is an alias for `search`. --- +### saved_searches/list (*; AUTH) + +This call does not have any parameter. + +--- + ### users/search (*) #### Parameters @@ -1234,7 +1240,6 @@ The following API calls from the Twitter API are not implemented in either Frien * lists/subscriptions * lists/members/destroy_all * lists/ownerships -* saved_searches/list * saved_searches/show/:id * saved_searches/create * saved_searches/destroy/:id diff --git a/include/api.php b/include/api.php index a7853ed32..659f23b58 100644 --- a/include/api.php +++ b/include/api.php @@ -5490,6 +5490,36 @@ function api_friendica_profile_show($type) } api_register_func('api/friendica/profile/show', 'api_friendica_profile_show', true, API_METHOD_GET); +/** + * Returns a list of saved searches. + * + * @see https://developer.twitter.com/en/docs/accounts-and-users/manage-account-settings/api-reference/get-saved_searches-list + * + * @param string $type Return format: json or xml + * + * @return string|array + * @throws UnauthorizedException + */ +function api_saved_searches_list($type) +{ + $terms = dba::select('search', array('id', 'term'), array('uid' => local_user())); + + $result = array(); + while ($term = $terms->fetch()) { + $result[] = array( + 'name' => $term['term'], + 'query' => $term['term'], + 'id_str' => $term['id'], + 'id' => intval($term['id']) + ); + } + + return api_format_data("terms", $type, array('terms' => $result)); +} + +/// @TODO move to top of file or somwhere better +api_register_func('api/saved_searches/list', 'api_saved_searches_list', true); + /* @TODO Maybe open to implement? To.Do: From e44da4a49825ed575e0168e8d2f5644c14bbc524 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Tue, 19 Dec 2017 14:42:13 +0100 Subject: [PATCH 02/37] Close DB connection in api_saved_searches_list --- include/api.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/api.php b/include/api.php index 659f23b58..13c652feb 100644 --- a/include/api.php +++ b/include/api.php @@ -5514,6 +5514,8 @@ function api_saved_searches_list($type) ); } + dba::close($terms); + return api_format_data("terms", $type, array('terms' => $result)); } From 890cda11ed2d4bfe88773df09238132b4e1894b5 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Tue, 19 Dec 2017 14:52:46 +0100 Subject: [PATCH 03/37] Only use "@throws" in phpdoc if the function explicitely throws an exception --- include/api.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/include/api.php b/include/api.php index 13c652feb..07c83f862 100644 --- a/include/api.php +++ b/include/api.php @@ -1525,8 +1525,7 @@ api_register_func('api/users/search', 'api_users_search'); * @param string $type Return format: json or xml * * @return array|string - * @throws UnauthorizedException - * @throws NotFoundException + * @throws NotFoundException if the results are empty. */ function api_users_lookup($type) { @@ -1558,8 +1557,7 @@ api_register_func('api/users/lookup', 'api_users_lookup', true); * @param string $type Return format: json, xml, atom, rss * * @return array|string - * @throws UnauthorizedException - * @throws BadRequestException + * @throws BadRequestException if the "q" parameter is missing. */ function api_search($type) { @@ -3263,7 +3261,6 @@ api_register_func('api/statuses/followers', 'api_statuses_followers', true); * @param string $type Either "json" or "xml" * * @return boolean|string|array - * @throws UnauthorizedException */ function api_blocks_list($type) { @@ -3285,7 +3282,6 @@ api_register_func('api/blocks/list', 'api_blocks_list', true); * @param string $type Either "json" or "xml" * * @return boolean|string|array - * @throws UnauthorizedException */ function api_friendships_incoming($type) { @@ -5498,7 +5494,6 @@ api_register_func('api/friendica/profile/show', 'api_friendica_profile_show', tr * @param string $type Return format: json or xml * * @return string|array - * @throws UnauthorizedException */ function api_saved_searches_list($type) { From fb88d78862530566ec69615c71cdcad02769484c Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 20 Dec 2017 20:31:25 +0000 Subject: [PATCH 04/37] Split the first name and last name so that they fit into the length restrictions of Diaspora --- src/Protocol/Diaspora.php | 65 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 4 deletions(-) diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 8828324c5..67167ac93 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -3963,6 +3963,62 @@ class Diaspora return self::buildAndTransmit($owner, $contact, $type, $message, false, $item["guid"]); } + /** + * @brief Split a name into first name and last name + * + * @param string $name The name + * + * @return array The array with "first" and "last" + */ + private static function splitName($name) { + $name = trim($name); + + // Is the name longer than 64 characters? Then cut the rest of it. + if (strlen($name) > 64) { + if ((strpos($name, ' ') <= 64) && (strpos($name, ' ') !== false)) { + $name = trim(substr($name, 0, strrpos(substr($name, 0, 65), ' '))); + } else { + $name = substr($name, 0, 64); + } + } + + // Take the first word as first name + $first = ((strpos($name, ' ') ? trim(substr($name, 0, strpos($name, ' '))) : $name)); + $last = (($first === $name) ? '' : trim(substr($name, strlen($first)))); + if ((strlen($first) < 32) && (strlen($last) < 32)) { + return ['first' => $first, 'last' => $last]; + } + + // Take the last word as last name + $first = ((strrpos($name, ' ') ? trim(substr($name, 0, strrpos($name, ' '))) : $name)); + $last = (($first === $name) ? '' : trim(substr($name, strlen($first)))); + + if ((strlen($first) < 32) && (strlen($last) < 32)) { + return ['first' => $first, 'last' => $last]; + } + + // Take the first 32 characters if there is no space in the first 32 characters + if ((strpos($name, ' ') > 32) || (strpos($name, ' ') === false)) { + $first = substr($name, 0, 32); + $last = substr($name, 32); + return ['first' => $first, 'last' => $last]; + } + + $first = trim(substr($name, 0, strrpos(substr($name, 0, 33), ' '))); + $last = (($first === $name) ? '' : trim(substr($name, strlen($first)))); + + // Check if the last name is longer than 32 characters + if (strlen($last) > 32) { + if (strpos($last, ' ') <= 32) { + $last = trim(substr($last, 0, strrpos(substr($last, 0, 33), ' '))); + } else { + $last = substr($last, 0, 32); + } + } + + return ['first' => $first, 'last' => $last]; + } + /** * @brief Create profile data * @@ -3986,11 +4042,12 @@ class Diaspora } $profile = $r[0]; - $handle = $profile["addr"]; - $first = ((strpos($profile['name'], ' ') - ? trim(substr($profile['name'], 0, strpos($profile['name'], ' '))) : $profile['name'])); - $last = (($first === $profile['name']) ? '' : trim(substr($profile['name'], strlen($first)))); + + $splitted_name = self::splitName($profile['name']); + $first = $splitted_name['first']; + $last = $splitted_name['last']; + $large = System::baseUrl().'/photo/custom/300/'.$profile['uid'].'.jpg'; $medium = System::baseUrl().'/photo/custom/100/'.$profile['uid'].'.jpg'; $small = System::baseUrl().'/photo/custom/50/' .$profile['uid'].'.jpg'; From 008c97c570ea62749a3f486b42c424365863d627 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 20 Dec 2017 21:15:13 +0000 Subject: [PATCH 05/37] Split the name in the hcard --- include/identity.php | 7 ++++--- src/Protocol/Diaspora.php | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/identity.php b/include/identity.php index 9a0900dc1..eebb8fe51 100644 --- a/include/identity.php +++ b/include/identity.php @@ -13,6 +13,7 @@ use Friendica\Core\System; use Friendica\Core\Worker; use Friendica\Database\DBM; use Friendica\Model\Contact; +use Friendica\Protocol\Diaspora; require_once 'include/bbcode.php'; require_once 'mod/proxy.php'; @@ -374,9 +375,9 @@ function profile_sidebar($profile, $block = 0) $location = $pdesc = $gender = $marital = $homepage = $about = false; } - $firstname = ((strpos($profile['name'], ' ')) - ? trim(substr($profile['name'], 0, strpos($profile['name'], ' '))) : $profile['name']); - $lastname = (($firstname === $profile['name']) ? '' : trim(substr($profile['name'], strlen($firstname)))); + $splitted_name = Diaspora::splitName($profile['name']); + $firstname = $splitted_name['first']; + $lastname = $splitted_name['last']; if ($profile['guid'] != "") { $diaspora = array( diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 67167ac93..09899ffa6 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -3970,7 +3970,7 @@ class Diaspora * * @return array The array with "first" and "last" */ - private static function splitName($name) { + public static function splitName($name) { $name = trim($name); // Is the name longer than 64 characters? Then cut the rest of it. From 8c2d455b98126d9817dc62b20fbe07d8140958e3 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 21 Dec 2017 04:53:57 +0000 Subject: [PATCH 06/37] Better english --- include/identity.php | 6 +++--- src/Protocol/Diaspora.php | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/identity.php b/include/identity.php index eebb8fe51..8f515580f 100644 --- a/include/identity.php +++ b/include/identity.php @@ -375,9 +375,9 @@ function profile_sidebar($profile, $block = 0) $location = $pdesc = $gender = $marital = $homepage = $about = false; } - $splitted_name = Diaspora::splitName($profile['name']); - $firstname = $splitted_name['first']; - $lastname = $splitted_name['last']; + $split_name = Diaspora::splitName($profile['name']); + $firstname = $split_name['first']; + $lastname = $split_name['last']; if ($profile['guid'] != "") { $diaspora = array( diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 09899ffa6..a0d99959b 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -4044,9 +4044,9 @@ class Diaspora $profile = $r[0]; $handle = $profile["addr"]; - $splitted_name = self::splitName($profile['name']); - $first = $splitted_name['first']; - $last = $splitted_name['last']; + $split_name = self::splitName($profile['name']); + $first = $split_name['first']; + $last = $split_name['last']; $large = System::baseUrl().'/photo/custom/300/'.$profile['uid'].'.jpg'; $medium = System::baseUrl().'/photo/custom/100/'.$profile['uid'].'.jpg'; From 23178a17a7b922829baa79ac98eae297408bc258 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 21 Dec 2017 07:27:20 +0000 Subject: [PATCH 07/37] Only locally used methods should always be private --- src/Protocol/PortableContact.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Protocol/PortableContact.php b/src/Protocol/PortableContact.php index b39533767..1ff0594ca 100644 --- a/src/Protocol/PortableContact.php +++ b/src/Protocol/PortableContact.php @@ -575,7 +575,7 @@ class PortableContact return true; } - public static function toBoolean($val) + private static function toBoolean($val) { if (($val == "true") || ($val == 1)) { return true; @@ -592,7 +592,7 @@ class PortableContact * @param object $data POCO data * @return array Server data */ - public static function detectPocoData($data) + private static function detectPocoData($data) { $server = false; @@ -629,7 +629,7 @@ class PortableContact * @param string $server_url address of the server * @return array Server data */ - public static function fetchNodeinfo($server_url) + private static function fetchNodeinfo($server_url) { $serverret = z_fetch_url($server_url."/.well-known/nodeinfo"); if (!$serverret["success"]) { @@ -746,7 +746,7 @@ class PortableContact * @param string $body Front page of the server * @return array Server data */ - public static function detectServerType($body) + private static function detectServerType($body) { $server = false; @@ -1292,7 +1292,7 @@ class PortableContact * * @param string $poco URL to the POCO endpoint */ - public static function fetchServerlist($poco) + private static function fetchServerlist($poco) { $serverret = z_fetch_url($poco."/@server"); if (!$serverret["success"]) { @@ -1315,7 +1315,7 @@ class PortableContact } } - public static function discoverFederation() + private static function discoverFederation() { $last = Config::get('poco', 'last_federation_discovery'); @@ -1470,7 +1470,7 @@ class PortableContact } } - public static function discoverServerUsers($data, $server) + private static function discoverServerUsers($data, $server) { if (!isset($data->entry)) { return; @@ -1501,7 +1501,7 @@ class PortableContact } } - public static function discoverServer($data, $default_generation = 0) + private static function discoverServer($data, $default_generation = 0) { if (!isset($data->entry) || !count($data->entry)) { return false; From 1e7e83510a91c7aabd802b178a094c6bed0c27b8 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 22 Dec 2017 14:48:29 +0000 Subject: [PATCH 08/37] Old stuff had been removed from the update routine --- boot.php | 85 ++- update.php | 1610 +--------------------------------------------------- 2 files changed, 50 insertions(+), 1645 deletions(-) diff --git a/boot.php b/boot.php index 7be7063eb..0fb8c01b9 100644 --- a/boot.php +++ b/boot.php @@ -619,10 +619,17 @@ function is_ajax() function check_db($via_worker) { $build = Config::get('system', 'build'); - if (!x($build)) { + + if (empty($build)) { Config::set('system', 'build', DB_UPDATE_VERSION); $build = DB_UPDATE_VERSION; } + + // We don't support upgrading from very old versions anymore + if ($build < NEW_UPDATE_ROUTINE_VERSION) { + die('You try to update from a version prior to database version 1170. The direct upgrade path is not supported. Please update to version 3.5.4 before updating to this version.'); + } + if ($build != DB_UPDATE_VERSION) { // When we cannot execute the database update via the worker, we will do it directly if (!Worker::add(PRIORITY_CRITICAL, 'DBUpdate') && $via_worker) { @@ -647,7 +654,7 @@ function check_url(App $a) // and www.example.com vs example.com. // We will only change the url to an ip address if there is no existing setting - if (!x($url)) { + if (empty($url)) { $url = Config::set('system', 'url', System::baseUrl()); } if ((!link_compare($url, System::baseUrl())) && (!preg_match("/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/", $a->get_hostname))) { @@ -664,7 +671,8 @@ function check_url(App $a) function update_db(App $a) { $build = Config::get('system', 'build'); - if (!x($build)) { + + if (empty($build)) { $build = Config::set('system', 'build', DB_UPDATE_VERSION); } @@ -674,53 +682,32 @@ function update_db(App $a) if ($stored < $current) { Config::load('database'); - // We're reporting a different version than what is currently installed. - // Run any existing update scripts to bring the database up to current. - // make sure that boot.php and update.php are the same release, we might be - // updating right this very second and the correct version of the update.php - // file may not be here yet. This can happen on a very busy site. + // Compare the current structure with the defined structure + $t = Config::get('database', 'dbupdate_' . DB_UPDATE_VERSION); + if (!is_null($t)) { + return; + } - if (DB_UPDATE_VERSION == UPDATE_VERSION) { - // Compare the current structure with the defined structure + Config::set('database', 'dbupdate_' . DB_UPDATE_VERSION, time()); - $t = Config::get('database', 'dbupdate_' . DB_UPDATE_VERSION); - if (!is_null($t)) { - return; - } + // run update routine + // it update the structure in one call + $retval = DBStructure::update(false, true); + if ($retval) { + DBStructure::updateFail( + DB_UPDATE_VERSION, + $retval + ); + return; + } else { + Config::set('database', 'dbupdate_' . DB_UPDATE_VERSION, 'success'); + } - Config::set('database', 'dbupdate_' . DB_UPDATE_VERSION, time()); - - // run old update routine (wich could modify the schema and - // conflits with new routine) - for ($x = $stored; $x < NEW_UPDATE_ROUTINE_VERSION; $x++) { - $r = run_update_function($x); - if (!$r) { - break; - } - } - if ($stored < NEW_UPDATE_ROUTINE_VERSION) { - $stored = NEW_UPDATE_ROUTINE_VERSION; - } - - // run new update routine - // it update the structure in one call - $retval = DBStructure::update(false, true); - if ($retval) { - DBStructure::updateFail( - DB_UPDATE_VERSION, - $retval - ); - return; - } else { - Config::set('database', 'dbupdate_' . DB_UPDATE_VERSION, 'success'); - } - - // run any left update_nnnn functions in update.php - for ($x = $stored; $x < $current; $x ++) { - $r = run_update_function($x); - if (!$r) { - break; - } + // run any left update_nnnn functions in update.php + for ($x = $stored; $x < $current; $x ++) { + $r = run_update_function($x); + if (!$r) { + break; } } } @@ -996,7 +983,7 @@ function remote_user() if (local_user()) { return false; } - if ((x($_SESSION, 'authenticated')) && (x($_SESSION, 'visitor_id'))) { + if (x($_SESSION, 'authenticated') && x($_SESSION, 'visitor_id')) { return intval($_SESSION['visitor_id']); } return false; @@ -1051,7 +1038,7 @@ function info($s) function get_max_import_size() { $a = get_app(); - return ((x($a->config, 'max_import_size')) ? $a->config['max_import_size'] : 0 ); + return (x($a->config, 'max_import_size') ? $a->config['max_import_size'] : 0); } diff --git a/update.php b/update.php index a968451e3..6c1785885 100644 --- a/update.php +++ b/update.php @@ -1,7 +1,5 @@ false )); - $sprvkey = ''; - openssl_pkey_export($sres, $sprvkey); - $spkey = openssl_pkey_get_details($sres); - $spubkey = $spkey["key"]; - $r = q("UPDATE `user` SET `spubkey` = '%s', `sprvkey` = '%s' - WHERE `uid` = %d", - dbesc($spubkey), - dbesc($sprvkey), - intval($rr['uid']) - ); - } - } -} - -function update_1007() { - q("ALTER TABLE `user` ADD `page-flags` INT NOT NULL DEFAULT '0' AFTER `notify-flags`"); - q("ALTER TABLE `user` ADD INDEX ( `nickname` )"); -} - -function update_1008() { - q("ALTER TABLE `profile` ADD `with` TEXT NOT NULL AFTER `marital` "); -} - -function update_1009() { - q("ALTER TABLE `user` ADD `allow_location` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `default-location` "); -} - -function update_1010() { - q("ALTER TABLE `contact` ADD `lrdd` CHAR( 255 ) NOT NULL AFTER `url` "); -} - -function update_1011() { - q("ALTER TABLE `contact` ADD `nick` CHAR( 255 ) NOT NULL AFTER `name` "); - $r = q("SELECT * FROM `contact` WHERE 1"); - if (DBM::is_result($r)) { - foreach ($r as $rr) { - q("UPDATE `contact` SET `nick` = '%s' WHERE `id` = %d", - dbesc(basename($rr['url'])), - intval($rr['id']) - ); - } - } -} - -function update_1012() { - q("ALTER TABLE `item` ADD `inform` MEDIUMTEXT NOT NULL AFTER `tag` "); -} - -function update_1013() { - q("ALTER TABLE `item` ADD `target-type` CHAR( 255 ) NOT NULL - AFTER `object` , ADD `target` TEXT NOT NULL AFTER `target-type`"); -} - -function update_1014() -{ - q("ALTER TABLE `contact` ADD `micro` TEXT NOT NULL AFTER `thumb` "); - $r = q("SELECT * FROM `photo` WHERE `scale` = 4"); - if (DBM::is_result($r)) { - foreach ($r as $rr) { - $Image = new Image($rr['data']); - if ($Image->isValid()) { - $Image->scaleDown(48); - Photo::store($Image, $rr['uid'],$rr['contact-id'],$rr['resource-id'],$rr['filename'],$rr['album'],6,(($rr['profile']) ? 1 : 0)); - } - } - } - $r = q("SELECT * FROM `contact` WHERE 1"); - if (DBM::is_result($r)) { - foreach ($r as $rr) { - if(stristr($rr['thumb'],'avatar')) - q("UPDATE `contact` SET `micro` = '%s' WHERE `id` = %d", - dbesc(str_replace('avatar','micro',$rr['thumb'])), - intval($rr['id'])); - else - q("UPDATE `contact` SET `micro` = '%s' WHERE `id` = %d", - dbesc(str_replace('5.jpg','6.jpg',$rr['thumb'])), - intval($rr['id'])); - } - } -} - -function update_1015() { - q("ALTER TABLE `item` CHANGE `body` `body` mediumtext NOT NULL"); -} - -function update_1016() { - q("ALTER TABLE `user` ADD `openid` CHAR( 255 ) NOT NULL AFTER `email` "); -} - -function update_1017() { - - q(" CREATE TABLE IF NOT EXISTS `clients` ( -`client_id` VARCHAR( 20 ) NOT NULL , -`pw` VARCHAR( 20 ) NOT NULL , -`redirect_uri` VARCHAR( 200 ) NOT NULL , -PRIMARY KEY ( `client_id` ) -) ENGINE = MYISAM DEFAULT CHARSET=utf8 "); - - q(" CREATE TABLE IF NOT EXISTS `tokens` ( -`id` VARCHAR( 40 ) NOT NULL , -`client_id` VARCHAR( 20 ) NOT NULL , -`expires` INT NOT NULL , -`scope` VARCHAR( 200 ) NOT NULL , -PRIMARY KEY ( `id` ) -) ENGINE = MYISAM DEFAULT CHARSET=utf8 "); - - q("CREATE TABLE IF NOT EXISTS `auth_codes` ( -`id` VARCHAR( 40 ) NOT NULL , -`client_id` VARCHAR( 20 ) NOT NULL , -`redirect_uri` VARCHAR( 200 ) NOT NULL , -`expires` INT NOT NULL , -`scope` VARCHAR( 250 ) NOT NULL , -PRIMARY KEY ( `id` ) -) ENGINE = MYISAM DEFAULT CHARSET=utf8 "); - -} - -function update_1018() { - q("CREATE TABLE IF NOT EXISTS `queue` ( -`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , -`cid` INT NOT NULL , -`created` DATETIME NOT NULL , -`last` DATETIME NOT NULL , -`content` MEDIUMTEXT NOT NULL -) ENGINE = MYISAM DEFAULT CHARSET=utf8 "); -} - -function update_1019() { - q("ALTER TABLE `mail` DROP `delivered`"); - q("ALTER TABLE `profile` ADD `showwith` TINYINT(1) NOT NULL DEFAULT '0' AFTER `marital` "); -} - -function update_1020() { - q("ALTER TABLE `profile` DROP `showwith`"); - q("ALTER TABLE `item` ADD `thr-parent` CHAR( 255 ) NOT NULL AFTER `parent-uri` "); -} - -function update_1021() { - q("ALTER TABLE `profile_check` ADD `sec` CHAR( 255 ) NOT NULL AFTER `dfrn_id` "); - q("ALTER TABLE `profile_check` ADD `cid` INT(10) unsigned NOT NULL DEFAULT '0' AFTER `uid`"); - q("ALTER TABLE `item` ADD `private` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `deny_gid` "); -} - -function update_1022() { - q("CREATE TABLE `pconfig` ( - `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , - `uid` INT NOT NULL DEFAULT '0', - `cat` CHAR( 255 ) NOT NULL , - `k` CHAR( 255 ) NOT NULL , - `v` MEDIUMTEXT NOT NULL - ) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci "); -} - -function update_1023() { - q("ALTER TABLE `user` ADD `register_date` DATETIME NOT NULL DEFAULT '0001-01-01 00:00:00' AFTER `timezone` , - ADD `login_date` DATETIME NOT NULL DEFAULT '0001-01-01 00:00:00' AFTER `register_date` "); -} - -function update_1024() { - q("ALTER TABLE `profile` ADD `keywords` TEXT NOT NULL AFTER `religion` "); -} - -function update_1025() { - q("ALTER TABLE `user` ADD `maxreq` int(11) NOT NULL DEFAULT '10' AFTER `pwdreset` "); -} - -function update_1026() { - q("CREATE TABLE IF NOT EXISTS `hook` ( - `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , - `hook` CHAR( 255 ) NOT NULL , - `file` CHAR( 255 ) NOT NULL , - `function` CHAR( 255 ) NOT NULL - ) ENGINE = MYISAM DEFAULT CHARSET=utf8 "); -} - - -function update_1027() { - q("CREATE TABLE IF NOT EXISTS `addon` ( - `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , - `name` CHAR( 255 ) NOT NULL , - `version` CHAR( 255 ) NOT NULL , - `installed` TINYINT( 1 ) NOT NULL DEFAULT '0' - ) ENGINE = MYISAM DEFAULT CHARSET=utf8 "); -} - -function update_1028() { - q("ALTER TABLE `user` ADD `openidserver` text NOT NULL AFTER `deny_gid` "); -} - -function update_1029() { - q("ALTER TABLE `contact` ADD `info` MEDIUMTEXT NOT NULL AFTER `reason` "); -} - -function update_1030() { - q("ALTER TABLE `contact` ADD `bdyear` CHAR( 4 ) NOT NULL COMMENT 'birthday notify flag' AFTER `profile-id` "); - - q("CREATE TABLE IF NOT EXISTS `event` ( - `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , - `uid` INT NOT NULL , - `cid` INT NOT NULL , - `created` DATETIME NOT NULL , - `edited` DATETIME NOT NULL , - `start` DATETIME NOT NULL , - `finish` DATETIME NOT NULL , - `desc` TEXT NOT NULL , - `location` TEXT NOT NULL , - `type` CHAR( 255 ) NOT NULL , - `adjust` TINYINT( 1 ) NOT NULL DEFAULT '1', - `allow_cid` MEDIUMTEXT NOT NULL , - `allow_gid` MEDIUMTEXT NOT NULL , - `deny_cid` MEDIUMTEXT NOT NULL , - `deny_gid` MEDIUMTEXT NOT NULL - ) ENGINE = MYISAM DEFAULT CHARSET=utf8 "); - - -} - -function update_1031() { - // Repair any bad links that slipped into the item table - $r = q("SELECT `id`, `object` FROM `item` WHERE `object` != '' "); - if (DBM::is_result($r)) { - foreach ($r as $rr) { - if (strstr($rr['object'],'type="http')) { - q("UPDATE `item` SET `object` = '%s' WHERE `id` = %d", - dbesc(str_replace('type="http','href="http',$rr['object'])), - intval($rr['id']) - ); - } - } - } -} - -function update_1032() { - q("ALTER TABLE `profile` ADD `pdesc` CHAR( 255 ) NOT NULL AFTER `name` "); -} - -function update_1033() { - q("CREATE TABLE IF NOT EXISTS `cache` ( - `k` CHAR( 255 ) NOT NULL PRIMARY KEY , - `v` TEXT NOT NULL, - `updated` DATETIME NOT NULL - ) DEFAULT CHARSET=utf8 "); -} - - -function update_1034() { - - /* - * If you have any of these parent-less posts they can cause problems, and - * we need to delete them. You can't see them anyway. - * Legitimate items will usually get re-created on the next - * pull from the hub. - * But don't get rid of a post that may have just come in - * and may not yet have the parent id set. - */ - q("DELETE FROM `item` WHERE `parent` = 0 AND `created` < UTC_TIMESTAMP() - INTERVAL 2 MINUTE"); - -} - - -function update_1035() { - - q("ALTER TABLE `contact` ADD `success_update` DATETIME NOT NULL DEFAULT '0001-01-01 00:00:00' AFTER `last-update` "); - -} - -function update_1036() { - - $r = dbq("SELECT * FROM `contact` WHERE `network` = 'dfrn' AND `photo` LIKE '%include/photo%' "); - if (DBM::is_result($r)) { - foreach ($r as $rr) { - q("UPDATE `contact` SET `photo` = '%s', `thumb` = '%s', `micro` = '%s' WHERE `id` = %d", - dbesc(str_replace('include/photo','photo',$rr['photo'])), - dbesc(str_replace('include/photo','photo',$rr['thumb'])), - dbesc(str_replace('include/photo','photo',$rr['micro'])), - intval($rr['id'])); - } - } -} - -function update_1037() { - - q("ALTER TABLE `contact` CHANGE `lrdd` `alias` CHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL "); - -} - -function update_1038() { - q("ALTER TABLE `item` ADD `plink` CHAR( 255 ) NOT NULL AFTER `target` "); -} - -function update_1039() { - q("ALTER TABLE `addon` ADD `timestamp` BIGINT NOT NULL DEFAULT '0'"); -} - - -function update_1040() { - - q("CREATE TABLE IF NOT EXISTS `fcontact` ( - `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , - `url` CHAR( 255 ) NOT NULL , - `name` CHAR( 255 ) NOT NULL , - `photo` CHAR( 255 ) NOT NULL - ) ENGINE = MYISAM DEFAULT CHARSET=utf8 "); - - q("CREATE TABLE IF NOT EXISTS `ffinder` ( - `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , - `uid` INT UNSIGNED NOT NULL , - `cid` INT UNSIGNED NOT NULL , - `fid` INT UNSIGNED NOT NULL - ) ENGINE = MYISAM DEFAULT CHARSET=utf8 "); - -} - -function update_1041() { - q("ALTER TABLE `profile` CHANGE `keywords` `prv_keywords` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL "); - q("ALTER TABLE `profile` ADD `pub_keywords` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL AFTER `religion` "); -} - -function update_1042() { - q("ALTER TABLE `user` ADD `expire` INT UNSIGNED NOT NULL DEFAULT '0' AFTER `maxreq` "); -} - - -function update_1043() { - q("ALTER TABLE `user` ADD `blockwall` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `blocked` "); -} - -function update_1044() { - q("ALTER TABLE `profile` ADD FULLTEXT ( `pub_keywords` ) "); - q("ALTER TABLE `profile` ADD FULLTEXT ( `prv_keywords` ) "); -} - -function update_1045() { - q("ALTER TABLE `user` ADD `language` CHAR( 16 ) NOT NULL DEFAULT 'en' AFTER `timezone` "); -} - -function update_1046() { - q("ALTER TABLE `item` ADD `attach` MEDIUMTEXT NOT NULL AFTER `tag` "); -} - -function update_1047() { - q("ALTER TABLE `contact` ADD `writable` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `readonly` "); -} - -function update_1048() { - q("UPDATE `contact` SET `writable` = 1 WHERE `network` = 'stat' AND `notify` != '' "); -} - -function update_1049() { - q("CREATE TABLE `mailacct` ( - `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , - `uid` INT NOT NULL, - `server` CHAR( 255 ) NOT NULL , - `user` CHAR( 255 ) NOT NULL , - `pass` CHAR( 255 ) NOT NULL , - `reply_to` CHAR( 255 ) NOT NULL , - `last_check` DATETIME NOT NULL DEFAULT '0001-01-01 00:00:00' - ) ENGINE = MYISAM "); -} - -function update_1050() { - q("CREATE TABLE `attach` ( - `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , - `uid` INT NOT NULL , - `filetype` CHAR( 64 ) NOT NULL , - `filesize` INT NOT NULL , - `data` LONGBLOB NOT NULL , - `created` DATETIME NOT NULL DEFAULT '0001-01-01 00:00:00', - `edited` DATETIME NOT NULL DEFAULT '0001-01-01 00:00:00', - `allow_cid` MEDIUMTEXT NOT NULL , - `allow_gid` MEDIUMTEXT NOT NULL , - `deny_cid` MEDIUMTEXT NOT NULL , - `deny_gid` MEDIUMTEXT NOT NULL - ) ENGINE = MYISAM "); - -} - -function update_1051() { - q("ALTER TABLE `mailacct` ADD `port` INT NOT NULL AFTER `server` , - ADD `ssltype` CHAR( 16 ) NOT NULL AFTER `port` , - ADD `mailbox` CHAR( 255 ) NOT NULL AFTER `ssltype` "); - - q("ALTER TABLE `contact` ADD `addr` CHAR( 255 ) NOT NULL AFTER `url` "); -} - -function update_1052() { - q("ALTER TABLE `mailacct` CHANGE `pass` `pass` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL"); - q("ALTER TABLE `mailacct` ADD `pubmail` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `reply_to` "); - q("ALTER TABLE `item` ADD `pubmail` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `private` "); -} - - -function update_1053() { - q("ALTER TABLE `item` ADD `extid` CHAR( 255 ) NOT NULL AFTER `parent-uri` , ADD INDEX ( `extid` ) "); -} - -function update_1054() { - q("ALTER TABLE `register` ADD `language` CHAR( 16 ) NOT NULL AFTER `password` "); -} - -function update_1055() { - q("ALTER TABLE `profile` ADD `hidewall` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `hide-friends` "); -} - -function update_1056() { - q("ALTER TABLE `attach` ADD `hash` CHAR( 64 ) NOT NULL AFTER `uid` "); -} - -function update_1057() { - q("ALTER TABLE `attach` ADD `filename` CHAR( 255 ) NOT NULL AFTER `hash` "); -} - -function update_1058() { - q("ALTER TABLE `item` ADD `event-id` INT NOT NULL AFTER `resource-id` "); -} - -function update_1059() { - q("ALTER TABLE `queue` ADD `network` CHAR( 32 ) NOT NULL AFTER `cid` "); -} - -function update_1060() { - q("ALTER TABLE `event` ADD `uri` CHAR( 255 ) NOT NULL AFTER `cid` "); -} - -function update_1061() { - q("ALTER TABLE `event` ADD `nofinish` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `type` "); -} - -function update_1062() { - q("ALTER TABLE `user` ADD `prvnets` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `page-flags` "); -} -function update_1063() { - q("ALTER TABLE `addon` ADD `plugin_admin` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `timestamp` "); -} - -function update_1064() { - q("ALTER TABLE `item` ADD `app` CHAR( 255 ) NOT NULL AFTER `body` "); -} - -function update_1065() { - q("ALTER TABLE `intro` ADD `fid` INT NOT NULL DEFAULT '0' AFTER `uid`"); -} - -function update_1066() { - $r = q("ALTER TABLE `item` ADD `received` DATETIME NOT NULL DEFAULT '0001-01-01 00:00:00' AFTER `edited` "); - if($r) - q("ALTER TABLE `item` ADD INDEX ( `received` ) "); - - $r = q("UPDATE `item` SET `received` = `edited` WHERE 1"); -} - -function update_1067() { - q("ALTER TABLE `ffinder` ADD `type` CHAR( 16 ) NOT NULL AFTER `id` , - ADD `note` TEXT NOT NULL AFTER `type` "); -} - -function update_1068() { - // 1067 was short-sighted. Undo it. - q("ALTER TABLE `ffinder` DROP `type` , DROP `note` "); - - // and do this instead. - - q("CREATE TABLE IF NOT EXISTS `fsuggest` ( - `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , - `uid` INT NOT NULL , - `cid` INT NOT NULL , - `name` CHAR( 255 ) NOT NULL , - `url` CHAR( 255 ) NOT NULL , - `photo` CHAR( 255 ) NOT NULL , - `note` TEXT NOT NULL , - `created` DATETIME NOT NULL - ) ENGINE = MYISAM DEFAULT CHARSET=utf8"); - -} - -function update_1069() { - q("ALTER TABLE `fsuggest` ADD `request` CHAR( 255 ) NOT NULL AFTER `url` "); - q("ALTER TABLE `fcontact` ADD `request` CHAR( 255 ) NOT NULL AFTER `photo` "); -} - -// mail body needs to accomodate private photos - -function update_1070() { - q("ALTER TABLE `mail` CHANGE `body` `body` MEDIUMTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL "); -} - -function update_1071() { - q("ALTER TABLE `photo` ADD INDEX ( `uid` ) "); - q("ALTER TABLE `photo` ADD INDEX ( `resource-id` ) "); - q("ALTER TABLE `photo` ADD INDEX ( `album` ) "); - q("ALTER TABLE `photo` ADD INDEX ( `scale` ) "); - q("ALTER TABLE `photo` ADD INDEX ( `profile` ) "); - -} - -function update_1072() { - q("ALTER TABLE `item` ADD `starred` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `visible` "); - q("ALTER TABLE `item` ADD INDEX ( `starred` ) "); -} - -function update_1073() { - q("ALTER TABLE `contact` ADD `remote_self` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `self` "); -} - -function update_1074() { - q("ALTER TABLE `user` ADD `hidewall` TINYINT( 1) NOT NULL DEFAULT '0' AFTER `blockwall` "); - $r = q("SELECT `uid` FROM `profile` WHERE `is-default` = 1 AND `hidewall` = 1"); - if (DBM::is_result($r)) { - foreach($r as $rr) - q("UPDATE `user` SET `hidewall` = 1 WHERE `uid` = %d", - intval($rr['uid']) - ); - } - q("ALTER TABLE `profile` DROP `hidewall`"); -} - -function update_1075() { - q("ALTER TABLE `user` ADD `guid` CHAR( 16 ) NOT NULL AFTER `uid` "); - $r = q("SELECT `uid` FROM `user` WHERE 1"); - if (DBM::is_result($r)) { - foreach ($r as $rr) { - $found = true; - do { - $guid = random_string(16); - $x = q("SELECT `uid` FROM `user` WHERE `guid` = '%s' LIMIT 1", - dbesc($guid) - ); - if(! count($x)) - $found = false; - } while ($found == true ); - - q("UPDATE `user` SET `guid` = '%s' WHERE `uid` = %d", - dbesc($guid), - intval($rr['uid']) - ); - } - } -} - -function update_1076() { - q("CREATE TABLE `guid` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , - `guid` CHAR( 16 ) NOT NULL , INDEX ( `guid` ) ) ENGINE = MYISAM "); - -} - -// There was a typo in 1076 so we'll try again in 1077 to make sure -// We'll also make it big enough to allow for future growth, I seriously -// doubt Diaspora will be able to leave guids at 16 bytes, -// and we can also use the same structure for our own larger guids - -function update_1077() { - q("CREATE TABLE IF NOT EXISTS `guid` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , - `guid` CHAR( 16 ) NOT NULL , INDEX ( `guid` ) ) ENGINE = MYISAM "); - - q("ALTER TABLE `guid` CHANGE `guid` `guid` CHAR( 64 ) NOT NULL"); -} - -function update_1078() { - q("ALTER TABLE `item` ADD `guid` CHAR( 64 ) NOT NULL AFTER `id` , ADD INDEX ( `guid` ) "); -} - -function update_1079() { - q("CREATE TABLE IF NOT EXISTS `sign` ( - `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , - `iid` INT UNSIGNED NOT NULL , - `signed_text` MEDIUMTEXT NOT NULL , - `signature` TEXT NOT NULL , - `signer` CHAR( 255 ) NOT NULL , - INDEX ( `iid` ) - ) ENGINE = MYISAM "); - - q("ALTER TABLE `fcontact` ADD `nick` CHAR( 255 ) NOT NULL , - ADD `addr` CHAR( 255 ) NOT NULL , - ADD `notify` CHAR( 255 ) NOT NULL , - ADD `poll` CHAR( 255 ) NOT NULL , - ADD `confirm` CHAR( 255 ) NOT NULL , - ADD `priority` TINYINT( 1 ) NOT NULL , - ADD `network` CHAR( 32 ) NOT NULL , - ADD `alias` CHAR( 255 ) NOT NULL , - ADD `pubkey` TEXT NOT NULL , - ADD INDEX ( `addr` ) , - ADD INDEX ( `network` ) "); - -} - -function update_1080() { - q("ALTER TABLE `fcontact` ADD `updated` DATETIME NOT NULL DEFAULT '0001-01-01 00:00:00'"); -} - -function update_1081() { - // there was a typo in update 1081 so it was corrected and moved up to 1082 -} - -function update_1082() { - q("ALTER TABLE `photo` ADD `guid` CHAR( 64 ) NOT NULL AFTER `contact-id`, - ADD INDEX ( `guid` ) "); - // make certain the following code is only executed once - $r = q("select `id` from `photo` where `guid` != '' limit 1"); - if (DBM::is_result($r)) - return; - $r = q("SELECT distinct(`resource-id`) FROM `photo` WHERE 1 group by `id`"); - if (DBM::is_result($r)) { - foreach ($r as $rr) { - $guid = get_guid(); - q("update `photo` set `guid` = '%s' where `resource-id` = '%s'", - dbesc($guid), - dbesc($rr['resource-id']) - ); - } - } -} - -function update_1083() { - q("CREATE TABLE IF NOT EXISTS `deliverq` ( - `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , - `cmd` CHAR( 32 ) NOT NULL , - `item` INT NOT NULL , - `contact` INT NOT NULL - ) ENGINE = MYISAM "); - -} - -function update_1084() { - q("ALTER TABLE `contact` ADD `attag` CHAR( 255 ) NOT NULL AFTER `nick` "); -} - -function update_1085() { - q("CREATE TABLE IF NOT EXISTS `search` ( - `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , - `uid` INT NOT NULL , - `term` CHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, - INDEX ( `uid` ), - INDEX ( `term` ) - ) ENGINE = MYISAM "); -} - -function update_1086() { - q("ALTER TABLE `item` ADD `bookmark` tinyint(1) NOT NULL DEFAULT '0' AFTER `starred` "); -} - -function update_1087() { - q("ALTER TABLE `item` ADD `commented` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' AFTER `edited` "); - - $r = q("SELECT `id` FROM `item` WHERE `parent` = `id` "); - if (DBM::is_result($r)) { - foreach ($r as $rr) { - $x = q("SELECT max(`created`) AS `cdate` FROM `item` WHERE `parent` = %d LIMIT 1", - intval($rr['id']) - ); - if(count($x)) - q("UPDATE `item` SET `commented` = '%s' WHERE `id` = %d", - dbesc($x[0]['cdate']), - intval($rr['id']) - ); - } - } -} - -function update_1088() { - q("ALTER TABLE `user` ADD `account_expired` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `expire` , - ADD `account_expires_on` DATETIME NOT NULL DEFAULT '0001-01-01 00:00:00' AFTER `account_expired` , - ADD `expire_notification_sent` DATETIME NOT NULL DEFAULT '0001-01-01 00:00:00' AFTER `account_expires_on` "); -} - -function update_1089() { - q("ALTER TABLE `user` ADD `blocktags` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `hidewall` "); -} - -function update_1090() { - q("ALTER TABLE `contact` ADD `batch` char(255) NOT NULL AFTER `prvkey` "); - - q("UPDATE `contact` SET `batch` = concat(substring_index(`url`,'/',3),'/receive/public') WHERE `network` = 'dspr' "); - -} - -function update_1091() { - - // catch a few stragglers that may have crept in before we added this on remote connects - q("UPDATE `contact` SET `batch` = concat(substring_index(`url`,'/',3),'/receive/public') WHERE `network` = 'dspr' AND `batch` = '' "); - q("ALTER TABLE `queue` ADD `batch` TINYINT( 1 ) NOT NULL DEFAULT '0' "); - q("ALTER TABLE `fcontact` ADD `batch` char(255) NOT NULL AFTER `addr` "); - -} - -function update_1092() { - q("ALTER TABLE `user` ADD INDEX ( `login_date` ) "); - q("ALTER TABLE `user` ADD INDEX ( `account_expired` ) "); -} - -function update_1093() { - q("CREATE TABLE IF NOT EXISTS `fserver` ( - `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , - `server` CHAR( 255 ) NOT NULL , - `posturl` CHAR( 255 ) NOT NULL , - `key` TEXT NOT NULL, - INDEX ( `server` ) - ) ENGINE = MYISAM "); - - q("ALTER TABLE `group` ADD `visible` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `uid` "); - -} - -function update_1094() { - q("ALTER TABLE `item` ADD `postopts` TEXT NOT NULL AFTER `target` "); -} - -function update_1095() { - q("ALTER TABLE `contact` ADD `bd` DATE NOT NULL AFTER `bdyear` "); -} - -function update_1096() { - q("ALTER TABLE `item` ADD `origin` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `deleted` , ADD INDEX ( `origin` ) "); -} - -function update_1097() { - q("ALTER TABLE `queue` - ADD INDEX (`cid`), - ADD INDEX (`created`), - ADD INDEX (`last`), - ADD INDEX (`network`), - ADD INDEX (`batch`) - "); -} - -function update_1098() { - q("ALTER TABLE `contact` - ADD INDEX (`network`), - ADD INDEX (`name`), - ADD INDEX (`nick`), - ADD INDEX (`attag`), - ADD INDEX (`url`), - ADD INDEX (`addr`), - ADD INDEX (`batch`) - "); -} - -function update_1099() { - q("CREATE TABLE IF NOT EXISTS `gcontact` ( - `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , - `name` CHAR( 255 ) NOT NULL , - `url` CHAR( 255 ) NOT NULL , - `nurl` CHAR( 255 ) NOT NULL , - `photo` CHAR( 255 ) NOT NULL - ) ENGINE = MYISAM "); - - q("CREATE TABLE IF NOT EXISTS `glink` ( - `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , - `cid` INT NOT NULL , - `uid` INT NOT NULL , - `gcid` INT NOT NULL, - `updated` DATETIME NOT NULL - ) ENGINE = MYISAM "); - - q("ALTER TABLE `gcontact` ADD INDEX (`nurl`) "); - q("ALTER TABLE `glink` ADD INDEX (`cid`), ADD INDEX (`uid`), ADD INDEX (`gcid`), ADD INDEX (`updated`) "); - - q("ALTER TABLE `contact` ADD `poco` TEXT NOT NULL AFTER `confirm` "); - -} - -function update_1100() { - q("ALTER TABLE `contact` ADD `nurl` CHAR( 255 ) NOT NULL AFTER `url` "); - q("alter table contact add index (`nurl`) "); - - require_once('include/text.php'); - - $r = q("select id, url from contact where url != '' and nurl = '' "); - if (DBM::is_result($r)) { - foreach ($r as $rr) { - q("update contact set nurl = '%s' where id = %d", - dbesc(normalise_link($rr['url'])), - intval($rr['id']) - ); - } - } -} - - -function update_1101() { - q("CREATE TABLE IF NOT EXISTS `gcign` ( - `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , - `uid` INT NOT NULL , - `gcid` INT NOT NULL - ) ENGINE = MYISAM "); - - q("ALTER TABLE `gcign` ADD INDEX (`uid`), ADD INDEX (`gcid`) "); -} - -function update_1102() { - q("ALTER TABLE `clients` ADD `name` TEXT NULL DEFAULT NULL AFTER `redirect_uri` "); - q("ALTER TABLE `clients` ADD `icon` TEXT NULL DEFAULT NULL AFTER `name` "); - q("ALTER TABLE `clients` ADD `uid` INT NOT NULL DEFAULT 0 AFTER `icon` "); - - q("ALTER TABLE `tokens` ADD `secret` TEXT NOT NULL AFTER `id` "); - q("ALTER TABLE `tokens` ADD `uid` INT NOT NULL AFTER `scope` "); -} - - -function update_1103() { -// q("ALTER TABLE `item` ADD INDEX ( `wall` ) "); - q("ALTER TABLE `item` ADD FULLTEXT ( `tag` ) "); - q("ALTER TABLE `contact` ADD INDEX ( `pending` ) "); - q("ALTER TABLE `user` ADD INDEX ( `hidewall` ) "); - q("ALTER TABLE `user` ADD INDEX ( `blockwall` ) "); - q("ALTER TABLE `user` ADD INDEX ( `blocked` ) "); - q("ALTER TABLE `user` ADD INDEX ( `verified` ) "); - -} - -function update_1104() { - q("ALTER TABLE `item` ADD `forum_mode` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `origin` , ADD INDEX ( `forum_mode` ) "); - -} - -function update_1105() { - q("ALTER TABLE `mail` ADD `convid` INT NOT NULL AFTER `contact-id` "); - q("ALTER TABLE `mail` ADD `guid` CHAR( 64 ) NOT NULL AFTER `uid` "); - - q("CREATE TABLE IF NOT EXISTS `conv` ( - `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , - `guid` CHAR( 64 ) NOT NULL , - `recips` MEDIUMTEXT NOT NULL , - `uid` INT NOT NULL - ) ENGINE = MYISAM "); -} - - -function update_1106() { - q("ALTER TABLE `item` ADD INDEX ( `author-link` ) "); - -} - -function update_1107() { - q("ALTER TABLE `item` ADD INDEX ( `bookmark` ) "); - -} - -function update_1108() { - q("ALTER TABLE `contact` ADD `hidden` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `writable` , -ADD INDEX ( `hidden` ) "); - -} - -function update_1109() { - q("ALTER TABLE `conv` ADD `creator` CHAR( 255 ) NOT NULL , - ADD `created` DATETIME NOT NULL DEFAULT '0001-01-01 00:00:00', - ADD `updated` DATETIME NOT NULL DEFAULT '0001-01-01 00:00:00', - ADD `subject` MEDIUMTEXT NOT NULL, - ADD INDEX ( `created` ), ADD INDEX ( `updated` ) "); -} - -function update_1110() { - q("ALTER TABLE `mail` ADD `reply` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `seen`, - ADD INDEX ( `reply` ), ADD INDEX ( `uid` ), ADD INDEX ( `guid` ), ADD INDEX ( `seen` ), - ADD INDEX ( `uri` ), ADD INDEX ( `parent-uri`), ADD INDEX ( `created` ), ADD INDEX ( `convid` ) "); - -} - -function update_1111() { - q("ALTER TABLE `gcontact` ADD `connect` CHAR( 255 ) NOT NULL "); -} - - -function update_1112() { - - q("CREATE TABLE IF NOT EXISTS `notify` ( -`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , -`type` INT( 11 ) NOT NULL , -`name` CHAR( 255 ) NOT NULL , -`url` CHAR( 255 ) NOT NULL , -`photo` CHAR( 255 ) NOT NULL , -`date` DATETIME NOT NULL , -`msg` MEDIUMTEXT NOT NULL , -`uid` INT NOT NULL , -`link` CHAR( 255 ) NOT NULL , -`seen` TINYINT( 1 ) NOT NULL DEFAULT '0' -) ENGINE = MYISAM "); - - q("ALTER TABLE `notify` ADD INDEX ( `type` ), ADD INDEX ( `uid`), ADD INDEX (`seen`), ADD INDEX (`date`) "); - -} - -function update_1113() { - q("ALTER TABLE `notify` ADD `verb` CHAR( 255 ) NOT NULL , -ADD `otype` CHAR( 16 ) NOT NULL"); -} - -function update_1114() { - q("CREATE TABLE IF NOT EXISTS `item_id` ( -`iid` INT NOT NULL , -`uid` INT NOT NULL , -`face` CHAR( 255 ) NOT NULL , -`dspr` CHAR( 255 ) NOT NULL , -`twit` CHAR( 255 ) NOT NULL , -`stat` CHAR( 255 ) NOT NULL , -PRIMARY KEY ( `iid` ), -INDEX ( `uid` ), -INDEX ( `face` ), -INDEX ( `dspr` ), -INDEX ( `twit` ), -INDEX ( `stat` ) -) ENGINE = MYISAM "); - -} - -function update_1115() { - q("ALTER TABLE `item` ADD `moderated` - TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `pubmail`, - ADD INDEX (`moderated`) "); -} - -function update_1116() { - //typo! corrected update was rolled forward -} - -function update_1117() { -q("create table if not exists `manage` ( -`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , -`uid` INT NOT NULL , -`mid` INT NOT NULL, -INDEX ( `uid` ), -INDEX ( `mid` ) -) ENGINE = MYISAM "); - -} - -function update_1118() { - // rolled forward -} - -function update_1119() { -q("ALTER TABLE `contact` ADD `closeness` TINYINT( 2 ) NOT NULL DEFAULT '99' AFTER `reason` , ADD INDEX (`closeness`) "); -q("update contact set closeness = 0 where self = 1"); -q("ALTER TABLE `item` ADD `spam` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `visible` , ADD INDEX (`spam`) "); -} - - -function update_1120() { - - // item table update from 1119 did not get into database.sql file. - // might be missing on new installs. We'll check. - - $r = q("describe item"); - if (DBM::is_result($r)) { - foreach($r as $rr) - if($rr['Field'] == 'spam') - return; - } - q("ALTER TABLE `item` ADD `spam` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `visible` , ADD INDEX (`spam`) "); - -} - -function update_1121() { - q("CREATE TABLE IF NOT EXISTS `poll_result` ( - `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , - `poll_id` INT NOT NULL , - `choice` INT NOT NULL , - INDEX ( `poll_id` ), - INDEX ( `choice` ) - ) ENGINE = MYISAM "); - - q("CREATE TABLE IF NOT EXISTS `poll` ( - `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , - `uid` INT NOT NULL , - `q0` MEDIUMTEXT NOT NULL , - `q1` MEDIUMTEXT NOT NULL , - `q2` MEDIUMTEXT NOT NULL , - `q3` MEDIUMTEXT NOT NULL , - `q4` MEDIUMTEXT NOT NULL , - `q5` MEDIUMTEXT NOT NULL , - `q6` MEDIUMTEXT NOT NULL , - `q7` MEDIUMTEXT NOT NULL , - `q8` MEDIUMTEXT NOT NULL , - `q9` MEDIUMTEXT NOT NULL , - INDEX ( `uid` ) - ) ENGINE = MYISAM "); - -} - -function update_1122() { -q("ALTER TABLE `notify` ADD `hash` CHAR( 64 ) NOT NULL AFTER `id` , -ADD INDEX ( `hash` ) "); -} - -function update_1123() { -Config::set('system','allowed_themes','dispy,quattro,testbubble,vier,darkbubble,darkzero,duepuntozero,greenzero,purplezero,quattro-green,slackr'); -} - -function update_1124() { -q("alter table item add index (`author-name`) "); -} - -function update_1125() { - q("CREATE TABLE IF NOT EXISTS `notify-threads` ( - `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , - `notify-id` INT NOT NULL, - `master-parent-item` INT( 10 ) unsigned NOT NULL DEFAULT '0', - `parent-item` INT( 10 ) unsigned NOT NULL DEFAULT '0', - `receiver-uid` INT NOT NULL, - INDEX ( `master-parent-item` ), - INDEX ( `receiver-uid` ) - ) ENGINE = MyISAM DEFAULT CHARSET=utf8"); -} - -function update_1126() { - q("ALTER TABLE `mailacct` ADD `action` INT NOT NULL AFTER `pass`, - ADD `movetofolder` CHAR(255) NOT NULL AFTER `action`"); -} - -function update_1127() { - q("CREATE TABLE IF NOT EXISTS `spam` ( - `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , - `uid` INT NOT NULL, - `spam` INT NOT NULL DEFAULT '0', - `ham` INT NOT NULL DEFAULT '0', - `term` CHAR(255) NOT NULL, - INDEX ( `uid` ), - INDEX ( `spam` ), - INDEX ( `ham` ), - INDEX ( `term` ) - ) ENGINE = MyISAM DEFAULT CHARSET=utf8"); -} - - -function update_1128() { - q("alter table spam add `date` DATETIME NOT NULL DEFAULT '0001-01-01 00:00:00' AFTER `term` "); -} - -function update_1129() { - q("ALTER TABLE `notify` ADD `parent` INT NOT NULL AFTER `link` , ADD INDEX ( `parent` ), ADD INDEX ( `link` ), ADD INDEX ( `otype` ) "); -} - -function update_1130() { - q("ALTER TABLE `item` ADD `file` MEDIUMTEXT NOT NULL AFTER `inform`, ADD FULLTEXT KEY (`file`) "); -} - -function update_1131() { - q("ALTER TABLE `contact` ADD `forum` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `writable` , ADD INDEX ( `forum` ) "); -} - - -function update_1132() { - q("CREATE TABLE IF NOT EXISTS `userd` ( -`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , -`username` CHAR( 255 ) NOT NULL, -INDEX ( `username` ) -) ENGINE = MYISAM "); - -} - -function update_1133() { -q("ALTER TABLE `user` ADD `unkmail` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `blocktags` , ADD INDEX ( `unkmail` ) "); -q("ALTER TABLE `user` ADD `cntunkmail` INT NOT NULL DEFAULT '10' AFTER `unkmail` , ADD INDEX ( `cntunkmail` ) "); -q("ALTER TABLE `mail` ADD `unknown` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `replied` , ADD INDEX ( `unknown` ) "); -} - -function update_1134() { - // faulty update merged forward - // had a hardwired tablename of 'friendica' which isn't the right name on most systems -} - -function update_1135() { - //there can't be indexes with more than 1000 bytes in mysql, - //so change charset to be smaller - q("ALTER TABLE `config` CHANGE `cat` `cat` CHAR( 255 ) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL , -CHANGE `k` `k` CHAR( 255 ) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL"); - - //same thing for pconfig - q("ALTER TABLE `pconfig` CHANGE `cat` `cat` CHAR( 255 ) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL , - CHANGE `k` `k` CHAR( 255 ) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL"); - // faulty update merged forward. Bad update in 1134 caused duplicate k,cat pairs - // these have to be cleared before the unique keys can be added. -} - -function update_1136() { - - $arr = array(); - - // order in reverse so that we save the newest entry - - $r = q("select * from config where 1 order by id desc"); - if (DBM::is_result($r)) { - foreach ($r as $rr) { - $found = false; - foreach($arr as $x) { - if($x['cat'] == $rr['cat'] && $x['k'] == $rr['k']) { - $found = true; - q("delete from config where id = %d", - intval($rr['id']) - ); - } - } - if(! $found) { - $arr[] = $rr; - } - } - } - - $arr = array(); - $r = q("select * from pconfig where 1 order by id desc"); - if (DBM::is_result($r)) { - foreach ($r as $rr) { - $found = false; - foreach($arr as $x) { - if($x['uid'] == $rr['uid'] && $x['cat'] == $rr['cat'] && $x['k'] == $rr['k']) { - $found = true; - q("delete from pconfig where id = %d", - intval($rr['id']) - ); - } - } - if(! $found) { - $arr[] = $rr; - } - } - } - q("ALTER TABLE `config` ADD UNIQUE `access` ( `cat` , `k` ) "); - q("ALTER TABLE `pconfig` ADD UNIQUE `access` ( `uid` , `cat` , `k` )"); - -} - - -function update_1137() { - q("alter table item_id DROP `face` , DROP `dspr` , DROP `twit` , DROP `stat` "); - q("ALTER TABLE `item_id` ADD `sid` CHAR( 255 ) NOT NULL AFTER `uid` , ADD `service` CHAR( 255 ) NOT NULL AFTER `sid` , add index (`sid`), add index ( `service`) "); -} - -function update_1138() { - q("alter table contact add archive tinyint(1) not null default '0' after hidden, add index (archive)"); -} - -function update_1139() { - $r = q("alter table user add account_removed tinyint(1) not null default '0' after expire, add index(account_removed) "); - if(! $r) - return UPDATE_FAILED ; - return UPDATE_SUCCESS ; -} - -function update_1140() { - $r = q("alter table addon add hidden tinyint(1) not null default '0' after installed, add index(hidden) "); - if(! $r) - return UPDATE_FAILED ; - return UPDATE_SUCCESS ; -} - -function update_1141() { - $r = q("alter table glink add zcid int(11) not null after gcid, add index(zcid) "); - if(! $r) - return UPDATE_FAILED ; - return UPDATE_SUCCESS ; -} - - -function update_1142() { - $r = q("alter table user add service_class char(32) not null after expire_notification_sent, add index(service_class) "); - if(! $r) - return UPDATE_FAILED ; - return UPDATE_SUCCESS ; -} - -function update_1143() { - $r = q("alter table user add def_gid int(11) not null default '0' after service_class"); - if(! $r) - return UPDATE_FAILED ; - return UPDATE_SUCCESS ; -} - -function update_1144() { - $r = q("alter table contact add prv tinyint(1) not null default '0' after forum"); - if(! $r) - return UPDATE_FAILED ; - return UPDATE_SUCCESS ; -} - -function update_1145() { - $r = q("alter table profile add howlong datetime not null default '0001-01-01 00:00:00' after `with`"); - if(! $r) - return UPDATE_FAILED ; - return UPDATE_SUCCESS ; -} - -function update_1146() { - $r = q("alter table profile add hometown char(255) not null after `country-name`, add index ( `hometown` ) "); - if(! $r) - return UPDATE_FAILED ; - return UPDATE_SUCCESS ; -} - -function update_1147() { - $r1 = q("ALTER TABLE `sign` ALTER `iid` SET DEFAULT '0'"); - $r2 = q("ALTER TABLE `sign` ADD `retract_iid` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER `iid`"); - $r3 = q("ALTER TABLE `sign` ADD INDEX ( `retract_iid` )"); - if((! $r1) || (! $r2) || (! $r3)) - return UPDATE_FAILED ; - return UPDATE_SUCCESS ; -} - -function update_1148() { - $r = q("ALTER TABLE photo ADD type CHAR(128) NOT NULL DEFAULT 'image/jpeg' AFTER filename"); - if (!$r) - return UPDATE_FAILED; - return UPDATE_SUCCESS; -} - - -function update_1149() { - $r1 = q("ALTER TABLE profile ADD likes text NOT NULL after prv_keywords"); - $r2 = q("ALTER TABLE profile ADD dislikes text NOT NULL after likes"); - if (! ($r1 && $r2)) - return UPDATE_FAILED; - return UPDATE_SUCCESS; -} - - -function update_1150() { - $r = q("ALTER TABLE event ADD summary text NOT NULL after finish, add index ( uid ), add index ( cid ), add index ( uri ), add index ( `start` ), add index ( finish ), add index ( `type` ), add index ( adjust ) "); - if(! $r) - return UPDATE_FAILED; - return UPDATE_SUCCESS; -} - - -function update_1151() { - $r = q("CREATE TABLE IF NOT EXISTS locks ( - id INT NOT NULL AUTO_INCREMENT PRIMARY KEY , - name CHAR( 128 ) NOT NULL , - locked TINYINT( 1 ) NOT NULL DEFAULT '0' - ) ENGINE = MYISAM DEFAULT CHARSET=utf8 "); - if (!$r) - return UPDATE_FAILED; - return UPDATE_SUCCESS; -} - -function update_1152() { - $r = q("CREATE TABLE IF NOT EXISTS `term` ( - `tid` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , - `oid` INT UNSIGNED NOT NULL , - `otype` TINYINT( 3 ) UNSIGNED NOT NULL , - `type` TINYINT( 3 ) UNSIGNED NOT NULL , - `term` CHAR( 255 ) NOT NULL , - `url` CHAR( 255 ) NOT NULL, - KEY `oid` ( `oid` ), - KEY `otype` ( `otype` ), - KEY `type` ( `type` ), - KEY `term` ( `term` ) - ) ENGINE = MYISAM DEFAULT CHARSET=utf8 "); - if (!$r) - return UPDATE_FAILED; - return UPDATE_SUCCESS; -} - -function update_1153() { - $r = q("ALTER TABLE `hook` ADD `priority` INT(11) UNSIGNED NOT NULL DEFAULT '0'"); - - if(!$r) return UPDATE_FAILED; - return UPDATE_SUCCESS; -} - -function update_1154() { - $r = q("ALTER TABLE `event` ADD `ignore` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0' AFTER `adjust` , ADD INDEX ( `ignore` )"); - - if(!$r) return UPDATE_FAILED; - return UPDATE_SUCCESS; -} - -function update_1155() { - $r1 = q("ALTER TABLE `item_id` DROP PRIMARY KEY"); - $r2 = q("ALTER TABLE `item_id` ADD `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST"); - $r3 = q("ALTER TABLE `item_id` ADD INDEX ( `iid` ) "); - - if($r1 && $r2 && $r3) - return UPDATE_SUCCESS; - - return UPDATE_FAILED; -} - -function update_1156() { - $r = q("ALTER TABLE `photo` ADD `datasize` INT UNSIGNED NOT NULL DEFAULT '0' AFTER `width` , -ADD INDEX ( `datasize` ) "); - - if(!$r) return UPDATE_FAILED; - return UPDATE_SUCCESS; -} - -function update_1157() { - $r = q("CREATE TABLE IF NOT EXISTS `dsprphotoq` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `uid` int(11) NOT NULL, - `msg` mediumtext NOT NULL, - `attempt` tinyint(4) NOT NULL, - PRIMARY KEY (`id`) - ) ENGINE=MyISAM DEFAULT CHARSET=utf8" - ); - - if($r) - return UPDATE_SUCCESS; -} - -function update_1158() { - Config::set('system', 'maintenance', 1); - - // Wait for 15 seconds for current requests to - // clear before locking up the database - sleep(15); - - $r = q("CREATE INDEX event_id ON item(`event-id`)"); - Config::set('system', 'maintenance', 0); - - if($r) - return UPDATE_SUCCESS; - - return UPDATE_FAILED; -} - -function update_1159() { - $r = q("ALTER TABLE `term` ADD `aid` int(10) unsigned NOT NULL DEFAULT '0', - ADD `uid` int(10) unsigned NOT NULL DEFAULT '0', - ADD INDEX (`uid`), - ADD INDEX (`aid`)"); - - if(!$r) - return UPDATE_FAILED; - - return UPDATE_SUCCESS; -} - -function update_1160() { - Config::set('system', 'maintenance', 1); - - // Wait for 15 seconds for current requests to - // clear before locking up the database - sleep(15); - - $r = q("ALTER TABLE `item` ADD `mention` TINYINT(1) NOT NULL DEFAULT '0', ADD INDEX (`mention`)"); - Config::set('system', 'maintenance', 0); - - if(!$r) - return UPDATE_FAILED; - - return UPDATE_SUCCESS; -} - -function update_1161() { - $r = q("ALTER TABLE `pconfig` ADD INDEX (`cat`)"); - - if(!$r) - return UPDATE_FAILED; - - return UPDATE_SUCCESS; -} - -function update_1162() { - require_once('include/tags.php'); - update_items(); - - return UPDATE_SUCCESS; -} - -function update_1163() { - Config::set('system', 'maintenance', 1); - - $r = q("ALTER TABLE `item` ADD `network` char(32) NOT NULL"); - - Config::set('system', 'maintenance', 0); - if(!$r) - return UPDATE_FAILED; - - return UPDATE_SUCCESS; -} -function update_1164() { - Config::set('system', 'maintenance', 1); - - $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '' AND `contact`.`uid` = `item`.`uid`)", - 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_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_OSTATUS, NETWORK_OSTATUS); - - $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)", - NETWORK_FEED, NETWORK_FEED); - - $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)", - NETWORK_DIASPORA, NETWORK_DIASPORA); - - $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_FACEBOOK, NETWORK_FACEBOOK); - - $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)", - NETWORK_LINKEDIN, NETWORK_LINKEDIN); - - $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)", - NETWORK_XMPP, NETWORK_XMPP); - - $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)", - NETWORK_MYSPACE, NETWORK_MYSPACE); - - $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)", - NETWORK_GPLUS, NETWORK_GPLUS); - - $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)", - NETWORK_PUMPIO, NETWORK_PUMPIO); - - $r = q("UPDATE `item` SET `network`='%s' WHERE `contact-id` IN (SELECT `id` FROM`contact` WHERE `network` = '%s' AND `contact`.`uid` = `item`.`uid`)", - NETWORK_TWITTER, NETWORK_TWITTER); - - Config::set('system', 'maintenance', 0); - - return UPDATE_SUCCESS; -} - -function update_1165() { - $r = q("CREATE TABLE IF NOT EXISTS `push_subscriber` ( - `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - `uid` INT NOT NULL, - `callback_url` CHAR( 255 ) NOT NULL, - `topic` CHAR( 255 ) NOT NULL, - `nickname` CHAR( 255 ) NOT NULL, - `push` INT NOT NULL, - `last_update` DATETIME NOT NULL, - `secret` CHAR( 255 ) NOT NULL - ) ENGINE = MYISAM DEFAULT CHARSET=utf8 "); - if (!$r) - return UPDATE_FAILED; - - return UPDATE_SUCCESS; -} - -function update_1166() { - $r = q("CREATE TABLE IF NOT EXISTS `unique_contacts` ( - `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, - `url` CHAR(255) NOT NULL, - `nick` CHAR(255) NOT NULL, - `name` CHAR(255) NOT NULL, - `avatar` CHAR(255) NOT NULL, - INDEX (`url`) - ) ENGINE = MYISAM DEFAULT CHARSET=utf8 "); - if (!$r) - return UPDATE_FAILED; - - return UPDATE_SUCCESS; -} - -function update_1167() { - $r = q("ALTER TABLE `contact` ADD `notify_new_posts` TINYINT(1) NOT NULL DEFAULT '0'"); - if (!$r) - return UPDATE_FAILED; - - return UPDATE_SUCCESS; -} - -function update_1168() { - $r = q("ALTER TABLE `contact` ADD `fetch_further_information` TINYINT(1) NOT NULL DEFAULT '0'"); - if (!$r) - return UPDATE_FAILED; - - return UPDATE_SUCCESS; -} - -function update_1169() { - $r = q("CREATE TABLE IF NOT EXISTS `thread` ( - `iid` int(10) unsigned NOT NULL DEFAULT '0', - `uid` int(10) unsigned NOT NULL DEFAULT '0', - `contact-id` int(11) unsigned NOT NULL DEFAULT '0', - `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00', - `edited` datetime NOT NULL DEFAULT '0001-01-01 00:00:00', - `commented` datetime NOT NULL DEFAULT '0001-01-01 00:00:00', - `received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00', - `changed` datetime NOT NULL DEFAULT '0001-01-01 00:00:00', - `wall` tinyint(1) NOT NULL DEFAULT '0', - `private` tinyint(1) NOT NULL DEFAULT '0', - `pubmail` tinyint(1) NOT NULL DEFAULT '0', - `moderated` tinyint(1) NOT NULL DEFAULT '0', - `visible` tinyint(1) NOT NULL DEFAULT '0', - `spam` tinyint(1) NOT NULL DEFAULT '0', - `starred` tinyint(1) NOT NULL DEFAULT '0', - `bookmark` tinyint(1) NOT NULL DEFAULT '0', - `unseen` tinyint(1) NOT NULL DEFAULT '1', - `deleted` tinyint(1) NOT NULL DEFAULT '0', - `origin` tinyint(1) NOT NULL DEFAULT '0', - `forum_mode` tinyint(1) NOT NULL DEFAULT '0', - `mention` tinyint(1) NOT NULL DEFAULT '0', - `network` char(32) NOT NULL, - PRIMARY KEY (`iid`), - KEY `created` (`created`), - KEY `commented` (`commented`), - KEY `uid_network_commented` (`uid`,`network`,`commented`), - KEY `uid_network_created` (`uid`,`network`,`created`), - KEY `uid_contactid_commented` (`uid`,`contact-id`,`commented`), - KEY `uid_contactid_created` (`uid`,`contact-id`,`created`), - KEY `wall_private_received` (`wall`,`private`,`received`), - KEY `uid_created` (`uid`,`created`), - KEY `uid_commented` (`uid`,`commented`) - ) ENGINE=MyISAM DEFAULT CHARSET=utf8;"); - if (!$r) - return UPDATE_FAILED; - - Worker::add(PRIORITY_LOW, "ThreadUpdate"); - - return UPDATE_SUCCESS; -} - -/* -========== -ATTENTION! -========== - -All following update functions are ONLY for jobs that need to run AFTER the database changes are applied. - -Database changes are ONLY applied in the file src/Database/DBStructure.php. -*/ - function update_1177() { - require_once("mod/profiles.php"); + require_once 'mod/profiles.php'; $profiles = q("SELECT `uid`, `about`, `locality`, `pub_keywords`, `gender` FROM `profile` WHERE `is-default`"); @@ -1664,7 +82,7 @@ function update_1188() { function update_1190() { - require_once('include/plugin.php'); + require_once 'include/plugin.php'; Config::set('system', 'maintenance', 1); From 2e2a2b8040af4261a1132a3dd4c068ec61a0d301 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 22 Dec 2017 14:51:50 +0000 Subject: [PATCH 09/37] Corrected wrong handling of the return value --- boot.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/boot.php b/boot.php index 0fb8c01b9..245fdc903 100644 --- a/boot.php +++ b/boot.php @@ -673,7 +673,8 @@ function update_db(App $a) $build = Config::get('system', 'build'); if (empty($build)) { - $build = Config::set('system', 'build', DB_UPDATE_VERSION); + Config::set('system', 'build', DB_UPDATE_VERSION); + $build = DB_UPDATE_VERSION; } if ($build != DB_UPDATE_VERSION) { From 00c6261daeb01a2972f16234b62c8e73da9e6c38 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 22 Dec 2017 14:56:40 +0000 Subject: [PATCH 10/37] Only include the update.php, when really needed --- boot.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/boot.php b/boot.php index 245fdc903..4571e0aa3 100644 --- a/boot.php +++ b/boot.php @@ -37,7 +37,6 @@ require_once 'include/datetime.php'; require_once 'include/pgettext.php'; require_once 'include/nav.php'; require_once 'include/identity.php'; -require_once 'update.php'; define('FRIENDICA_PLATFORM', 'Friendica'); define('FRIENDICA_CODENAME', 'Asparagus'); @@ -678,6 +677,8 @@ function update_db(App $a) } if ($build != DB_UPDATE_VERSION) { + require_once 'update.php'; + $stored = intval($build); $current = intval(DB_UPDATE_VERSION); if ($stored < $current) { From a614b17ed57f22c7a85113ab204380fcfc66ff31 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 22 Dec 2017 20:06:15 +0000 Subject: [PATCH 11/37] Grammar correction --- update.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/update.php b/update.php index 6c1785885..eb91baf3a 100644 --- a/update.php +++ b/update.php @@ -16,7 +16,7 @@ use Friendica\Object\Image; * * Database structure changes are done in src/Database/DBStructure.php * - * If there is a need for a post procession to a structure change, update this file + * If there is a need for a post process to a structure change, update this file * by adding a new function at the end with the number of the current DB_UPDATE_VERSION. * * The DB_UPDATE_VERSION will always be at least one greater than the last From 3fdfc2e4257ecc6e02fb7d6d5e9d9f774c7eee8b Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 22 Dec 2017 21:31:32 +0000 Subject: [PATCH 12/37] Hopefully this is now clearer --- boot.php | 2 +- update.php | 23 +++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/boot.php b/boot.php index 4571e0aa3..199ca0555 100644 --- a/boot.php +++ b/boot.php @@ -706,7 +706,7 @@ function update_db(App $a) } // run any left update_nnnn functions in update.php - for ($x = $stored; $x < $current; $x ++) { + for ($x = $stored + 1; $x <= $current; $x++) { $r = run_update_function($x); if (!$r) { break; diff --git a/update.php b/update.php index eb91baf3a..352092ec2 100644 --- a/update.php +++ b/update.php @@ -17,20 +17,19 @@ use Friendica\Object\Image; * Database structure changes are done in src/Database/DBStructure.php * * If there is a need for a post process to a structure change, update this file - * by adding a new function at the end with the number of the current DB_UPDATE_VERSION. + * by adding a new function at the end with the number of the new DB_UPDATE_VERSION. * - * The DB_UPDATE_VERSION will always be at least one greater than the last - * numbered script in this file. + * The numbered script in this file has to be exactly like the DB_UPDATE_VERSION * * Example: * You are currently on version 4711 and you are preparing changes that demand an update script. * - * - Create a function "update_4711()" here in the update.php - * - Apply the needed structural changes in src/Database/DBStructure.php - * - Set DB_UPDATE_VERSION in boot.php to 4712. + * 1. Create a function "update_4712()" here in the update.php + * 2. Apply the needed structural changes in src/Database/DBStructure.php + * 3. Set DB_UPDATE_VERSION in boot.php to 4712. */ -function update_1177() { +function update_1178() { require_once 'mod/profiles.php'; $profiles = q("SELECT `uid`, `about`, `locality`, `pub_keywords`, `gender` FROM `profile` WHERE `is-default`"); @@ -51,7 +50,7 @@ function update_1177() { } } -function update_1178() { +function update_1179() { if (Config::get('system','no_community_page')) Config::set('system','community_page_style', CP_NO_COMMUNITY_PAGE); @@ -61,7 +60,7 @@ function update_1178() { return UPDATE_SUCCESS; } -function update_1180() { +function update_1181() { // Fill the new fields in the term table. Worker::add(PRIORITY_LOW, "TagUpdate"); @@ -69,7 +68,7 @@ function update_1180() { return UPDATE_SUCCESS; } -function update_1188() { +function update_1189() { if (strlen(Config::get('system','directory_submit_url')) && !strlen(Config::get('system','directory'))) { @@ -80,7 +79,7 @@ function update_1188() { return UPDATE_SUCCESS; } -function update_1190() { +function update_1191() { require_once 'include/plugin.php'; @@ -144,7 +143,7 @@ function update_1190() { } -function update_1202() { +function update_1203() { $r = q("UPDATE `user` SET `account-type` = %d WHERE `page-flags` IN (%d, %d)", dbesc(ACCOUNT_TYPE_COMMUNITY), dbesc(PAGE_COMMUNITY), dbesc(PAGE_PRVGROUP)); } From e982d683700339545b2776e142cacb17116751cf Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Fri, 22 Dec 2017 23:56:13 +0100 Subject: [PATCH 13/37] Update api.md account/update_profile_background_image was listed twice --- doc/api.md | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/api.md b/doc/api.md index 3a2740764..c565d8699 100644 --- a/doc/api.md +++ b/doc/api.md @@ -1206,7 +1206,6 @@ The following API calls from the Twitter API are not implemented in either Frien * account/settings * account/update_delivery_device * account/update_profile -* account/update_profile_background_image * blocks/ids * users/show * users/search From a309d3c7333381af9cbd4c82aebd8261b962222c Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 22 Dec 2017 23:00:49 +0000 Subject: [PATCH 14/37] Bugfix for the api call for remoteauth --- include/api.php | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/include/api.php b/include/api.php index 07c83f862..0c9ef0d62 100644 --- a/include/api.php +++ b/include/api.php @@ -4547,8 +4547,8 @@ function prepare_photo_data($type, $scale, $photo_id) */ function api_friendica_remoteauth() { - $url = ((x($_GET, 'url')) ? $_GET['url'] : ''); - $c_url = ((x($_GET, 'c_url')) ? $_GET['c_url'] : ''); + $url = (x($_GET, 'url') ? $_GET['url'] : ''); + $c_url = (x($_GET, 'c_url') ? $_GET['c_url'] : ''); if ($url === '' || $c_url === '') { throw new BadRequestException("Wrong parameters."); @@ -4558,26 +4558,22 @@ function api_friendica_remoteauth() // traditional DFRN - $r = q( - "SELECT * FROM `contact` WHERE `id` = %d AND `nurl` = '%s' LIMIT 1", - dbesc($c_url), - intval(api_user()) - ); + $r = dba::select('contact', [], ['uid' => api_user(), 'nurl' => $c_url], ['limit' => 1]); - if ((! DBM::is_result($r)) || ($r[0]['network'] !== NETWORK_DFRN)) { + if (!DBM::is_result($r) || ($r['network'] !== NETWORK_DFRN)) { throw new BadRequestException("Unknown contact"); } - $cid = $r[0]['id']; + $cid = $r['id']; - $dfrn_id = $orig_id = (($r[0]['issued-id']) ? $r[0]['issued-id'] : $r[0]['dfrn-id']); + $dfrn_id = $orig_id = (($r['issued-id']) ? $r['issued-id'] : $r['dfrn-id']); - if ($r[0]['duplex'] && $r[0]['issued-id']) { - $orig_id = $r[0]['issued-id']; + if ($r['duplex'] && $r['issued-id']) { + $orig_id = $r['issued-id']; $dfrn_id = '1:' . $orig_id; } - if ($r[0]['duplex'] && $r[0]['dfrn-id']) { - $orig_id = $r[0]['dfrn-id']; + if ($r['duplex'] && $r['dfrn-id']) { + $orig_id = $r['dfrn-id']; $dfrn_id = '0:' . $orig_id; } @@ -4593,10 +4589,10 @@ function api_friendica_remoteauth() intval(time() + 45) ); - logger($r[0]['name'] . ' ' . $sec, LOGGER_DEBUG); - $dest = (($url) ? '&destination_url=' . $url : ''); + logger($r['name'] . ' ' . $sec, LOGGER_DEBUG); + $dest = ($url ? '&destination_url=' . $url : ''); goaway( - $r[0]['poll'] . '?dfrn_id=' . $dfrn_id + $r['poll'] . '?dfrn_id=' . $dfrn_id . '&dfrn_version=' . DFRN_PROTOCOL_VERSION . '&type=profile&sec=' . $sec . $dest . $quiet ); From 1fc399399081fad0b058344c3b40dffa7cd34d72 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 22 Dec 2017 23:10:32 +0000 Subject: [PATCH 15/37] Code cleaning --- include/api.php | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/include/api.php b/include/api.php index 0c9ef0d62..7cdb448c4 100644 --- a/include/api.php +++ b/include/api.php @@ -217,7 +217,7 @@ function api_login(App $a) */ call_hooks('authenticate', $addon_auth); - if (($addon_auth['authenticated']) && (count($addon_auth['user_record']))) { + if ($addon_auth['authenticated'] && count($addon_auth['user_record'])) { $record = $addon_auth['user_record']; } else { $user_id = User::authenticate(trim($user), trim($password)); @@ -226,7 +226,7 @@ function api_login(App $a) } } - if ((! $record) || (! count($record))) { + if (!$record || !count($record)) { logger('API_login failure: ' . print_r($_SERVER, true), LOGGER_DEBUG); header('WWW-Authenticate: Basic realm="Friendica"'); //header('HTTP/1.0 401 Unauthorized'); @@ -2694,14 +2694,15 @@ function api_get_entitities(&$text, $bbcode) foreach ($ordered_urls as $url) { if ((substr($url["title"], 0, 7) != "http://") && (substr($url["title"], 0, 8) != "https://") && !strpos($url["title"], "http://") && !strpos($url["title"], "https://") - ) + ) { $display_url = $url["title"]; - else { + } else { $display_url = str_replace(array("http://www.", "https://www."), array("", ""), $url["url"]); $display_url = str_replace(array("http://", "https://"), array("", ""), $display_url); - if (strlen($display_url) > 26) + if (strlen($display_url) > 26) { $display_url = substr($display_url, 0, 25)."…"; + } } //$start = strpos($text, $url, $offset); @@ -3051,12 +3052,13 @@ function api_format_items($r, $user_info, $filter_user = false, $type = "json") if ($item["coord"] != "") { $coords = explode(' ', $item["coord"]); if (count($coords) == 2) { - if ($type == "json") + if ($type == "json") { $status["geo"] = array('type' => 'Point', 'coordinates' => array((float) $coords[0], (float) $coords[1])); - else // Not sure if this is the official format - if someone founds a documentation we can check + } else {// Not sure if this is the official format - if someone founds a documentation we can check $status["georss:point"] = $item["coord"]; + } } } $ret[] = $status; @@ -4284,7 +4286,7 @@ function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $ } // check against max upload size within Friendica instance $maximagesize = Config::get('system', 'maximagesize'); - if (($maximagesize) && ($filesize > $maximagesize)) { + if ($maximagesize && ($filesize > $maximagesize)) { $formattedBytes = formatBytes($maximagesize); throw new InternalServerErrorException("image size exceeds Friendica config setting (uploaded size: $formattedBytes)"); } @@ -4866,20 +4868,20 @@ function api_clean_attachments($body) { $data = get_attachment_data($body); - if (!$data) + if (!$data) { return $body; - + } $body = ""; - if (isset($data["text"])) + if (isset($data["text"])) { $body = $data["text"]; - - if (($body == "") && (isset($data["title"]))) + } + if (($body == "") && isset($data["title"])) { $body = $data["title"]; - - if (isset($data["url"])) + } + if (isset($data["url"])) { $body .= "\n".$data["url"]; - + } $body .= $data["after"]; return $body; @@ -5098,9 +5100,9 @@ function api_friendica_group_create($type) intval($cid), intval($uid) ); - if (count($contact)) + if (count($contact)) { $result = Group::addMember($gid, $cid); - else { + } else { $erroraddinguser = true; $errorusers[] = $cid; } From 0691d83bbc2d6d28ee2f4e9dd4e8fc11ff644939 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Sat, 23 Dec 2017 01:23:20 +0100 Subject: [PATCH 16/37] Typo --- include/api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/api.php b/include/api.php index 07c83f862..e561f397c 100644 --- a/include/api.php +++ b/include/api.php @@ -399,7 +399,7 @@ function api_call(App $a) * * @param string $type Return type (xml, json, rss, as) * @param object $e HTTPException Error object - * @return strin error message formatted as $type + * @return string error message formatted as $type */ function api_error($type, $e) { From 37aef324406498445770f41f7d5b921ad6599b77 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Sat, 23 Dec 2017 01:23:28 +0100 Subject: [PATCH 17/37] Remove unused variable --- include/api.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/api.php b/include/api.php index e561f397c..724568279 100644 --- a/include/api.php +++ b/include/api.php @@ -950,8 +950,6 @@ function api_create_xml($data, $root_element) */ function api_format_data($root_element, $type, $data) { - $a = get_app(); - switch ($type) { case "atom": case "rss": From b4cf27e76731556c2b4d2941f51b74e1935e0ba7 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Sat, 23 Dec 2017 01:25:43 +0100 Subject: [PATCH 18/37] api_format_data can also return an array --- include/api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/api.php b/include/api.php index 724568279..b6181ea1a 100644 --- a/include/api.php +++ b/include/api.php @@ -946,7 +946,7 @@ function api_create_xml($data, $root_element) * @param string $type Return type (atom, rss, xml, json) * @param array $data JSON style array * - * @return (string|object) XML data or JSON data + * @return (string|object|array) XML data or JSON data */ function api_format_data($root_element, $type, $data) { From 521d4b09b6b1ef6f3d35529f562a3e0cd2ee1c99 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Sat, 23 Dec 2017 01:27:17 +0100 Subject: [PATCH 19/37] Unused argument --- include/api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/api.php b/include/api.php index b6181ea1a..c9c227daa 100644 --- a/include/api.php +++ b/include/api.php @@ -1494,7 +1494,7 @@ function api_users_search($type) if (DBM::is_result($r)) { $k = 0; foreach ($r as $user) { - $user_info = api_get_user($a, $user["id"], "json"); + $user_info = api_get_user($a, $user["id"]); if ($type == "xml") { $userlist[$k++.":user"] = $user_info; From 70ab9dc9bea07a90fa19937a0f4ae8606ced21fa Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Sat, 23 Dec 2017 01:30:50 +0100 Subject: [PATCH 20/37] Undefined variable --- include/api.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/api.php b/include/api.php index c9c227daa..d7e383d53 100644 --- a/include/api.php +++ b/include/api.php @@ -3163,10 +3163,10 @@ function api_statuses_f($qtype) return false; } + $sql_extra = ''; if ($qtype == 'friends') { $sql_extra = sprintf(" AND ( `rel` = %d OR `rel` = %d ) ", intval(CONTACT_IS_SHARING), intval(CONTACT_IS_FRIEND)); - } - if ($qtype == 'followers') { + } elseif ($qtype == 'followers') { $sql_extra = sprintf(" AND ( `rel` = %d OR `rel` = %d ) ", intval(CONTACT_IS_FOLLOWER), intval(CONTACT_IS_FRIEND)); } From da6a7b1fced470f2ac47118862d51d6674b718cb Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Sat, 23 Dec 2017 01:32:47 +0100 Subject: [PATCH 21/37] Typo --- include/api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/api.php b/include/api.php index d7e383d53..deb6a76da 100644 --- a/include/api.php +++ b/include/api.php @@ -3311,7 +3311,7 @@ function api_statusnet_config($type) $private = ((Config::get('system', 'block_public')) ? 'true' : 'false'); $textlimit = (string) (($a->config['max_import_size']) ? $a->config['max_import_size'] : 200000); if ($a->config['api_import_size']) { - $texlimit = string($a->config['api_import_size']); + $textlimit = (string) $a->config['api_import_size']; } $ssl = ((Config::get('system', 'have_ssl')) ? 'true' : 'false'); $sslserver = (($ssl === 'true') ? str_replace('http:', 'https:', System::baseUrl()) : ''); From f2758d00fb133ad5524ecd84e40437db457a6253 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Sat, 23 Dec 2017 01:34:12 +0100 Subject: [PATCH 22/37] Unused variable --- include/api.php | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/include/api.php b/include/api.php index deb6a76da..f44afd3a4 100644 --- a/include/api.php +++ b/include/api.php @@ -3363,17 +3363,6 @@ function api_ff_ids($type,$qtype) $user_info = api_get_user($a); - if ($qtype == 'friends') { - $sql_extra = sprintf(" AND ( `rel` = %d OR `rel` = %d ) ", intval(CONTACT_IS_SHARING), intval(CONTACT_IS_FRIEND)); - } - if ($qtype == 'followers') { - $sql_extra = sprintf(" AND ( `rel` = %d OR `rel` = %d ) ", intval(CONTACT_IS_FOLLOWER), intval(CONTACT_IS_FRIEND)); - } - - if (!$user_info["self"]) { - $sql_extra = " AND false "; - } - $stringify_ids = (x($_REQUEST, 'stringify_ids') ? $_REQUEST['stringify_ids'] : false); $r = q( From ca73ec5cbbd286cf902c128322d7d6a0e0fabc3e Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Sat, 23 Dec 2017 01:36:55 +0100 Subject: [PATCH 23/37] Incorrect return type --- include/api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/api.php b/include/api.php index f44afd3a4..42937b3aa 100644 --- a/include/api.php +++ b/include/api.php @@ -4594,7 +4594,7 @@ api_register_func('api/friendica/remoteauth', 'api_friendica_remoteauth', true); * @brief Return the item shared, if the item contains only the [share] tag * * @param array $item Sharer item - * @return array Shared item or false if not a reshare + * @return array|false Shared item or false if not a reshare */ function api_share_as_retweet(&$item) { From 0305aa2d8218a0919526a08910ffaebfdc5bb2c5 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Sun, 24 Dec 2017 00:27:45 +0100 Subject: [PATCH 24/37] Lint api.php --- include/api.php | 198 +++++++++++++++++++++++++++++++----------------- 1 file changed, 128 insertions(+), 70 deletions(-) diff --git a/include/api.php b/include/api.php index 002f807fb..9580afa86 100644 --- a/include/api.php +++ b/include/api.php @@ -186,7 +186,7 @@ function api_login(App $a) } if (!x($_SERVER, 'PHP_AUTH_USER')) { - logger('API_login: ' . print_r($_SERVER,true), LOGGER_DEBUG); + logger('API_login: ' . print_r($_SERVER, true), LOGGER_DEBUG); header('WWW-Authenticate: Basic realm="Friendica"'); throw new UnauthorizedException("This API requires login"); } @@ -367,12 +367,13 @@ function api_call(App $a) break; case "json": header("Content-Type: application/json"); - foreach ($r as $rr) + foreach ($r as $rr) { $json = json_encode($rr); - if (x($_GET, 'callback')) { - $json = $_GET['callback'] . "(" . $json . ")"; - } - return $json; + } + if (x($_GET, 'callback')) { + $json = $_GET['callback'] . "(" . $json . ")"; + } + return $json; break; case "rss": header("Content-Type: application/rss+xml"); @@ -1737,7 +1738,8 @@ function api_statuses_public_timeline($type) $sql_extra = 'AND `thread`.`iid` <= ' . intval($max_id); } - $r = dba::p("SELECT " . item_fieldlists() . " + $r = dba::p( + "SELECT " . item_fieldlists() . " FROM `thread` STRAIGHT_JOIN `item` ON `item`.`id` = `thread`.`iid` " . item_joins() . " @@ -1766,7 +1768,8 @@ function api_statuses_public_timeline($type) $sql_extra .= ' AND `item`.`parent` = ' . intval($conversation_id); } - $r = dba::p("SELECT " . item_fieldlists() . " + $r = dba::p( + "SELECT " . item_fieldlists() . " FROM `item` " . item_joins() . " STRAIGHT_JOIN `user` ON `user`.`uid` = `item`.`uid` @@ -1837,7 +1840,8 @@ function api_statuses_networkpublic_timeline($type) $sql_extra = 'AND `thread`.`iid` <= ' . intval($max_id); } - $r = dba::p("SELECT " . item_fieldlists() . " + $r = dba::p( + "SELECT " . item_fieldlists() . " FROM `thread` STRAIGHT_JOIN `item` ON `item`.`id` = `thread`.`iid` " . item_joins() . " @@ -2009,10 +2013,12 @@ function api_conversation_show($type) AND `item`.`uid` = %d AND `item`.`verb` = '%s' AND `item`.`id`>%d $sql_extra ORDER BY `item`.`id` DESC LIMIT %d ,%d", - intval($id), intval(api_user()), + intval($id), + intval(api_user()), dbesc(ACTIVITY_POST), intval($since_id), - intval($start), intval($count) + intval($start), + intval($count) ); if (!DBM::is_result($r)) { @@ -2321,7 +2327,7 @@ function api_statuses_user_timeline($type) } /// @TODO move to top of file or somwhere better -api_register_func('api/statuses/user_timeline','api_statuses_user_timeline', true); +api_register_func('api/statuses/user_timeline', 'api_statuses_user_timeline', true); /** * Star/unstar an item @@ -2372,7 +2378,7 @@ function api_favorites_create_destroy($type) throw new BadRequestException("Invalid action ".$action); } - $r = q("UPDATE item SET starred=%d WHERE id=%d AND uid=%d", $item[0]['starred'], $itemid, api_user()); + $r = q("UPDATE item SET starred=%d WHERE id=%d AND uid=%d", $item[0]['starred'], $itemid, api_user()); q("UPDATE thread SET starred=%d WHERE iid=%d AND uid=%d", $item[0]['starred'], $itemid, api_user()); @@ -2719,8 +2725,9 @@ function api_get_entitities(&$text, $bbcode) foreach ($images[1] as $image) { //$start = strpos($text, $url, $offset); $start = iconv_strpos($text, $image, 0, "UTF-8"); - if (!($start === false)) + if (!($start === false)) { $ordered_images[$start] = $image; + } } //$entities["media"] = array(); $offset = 0; @@ -2729,8 +2736,9 @@ function api_get_entitities(&$text, $bbcode) $display_url = str_replace(array("http://www.", "https://www."), array("", ""), $url); $display_url = str_replace(array("http://", "https://"), array("", ""), $display_url); - if (strlen($display_url) > 26) + if (strlen($display_url) > 26) { $display_url = substr($display_url, 0, 25)."…"; + } $start = iconv_strpos($text, $url, $offset, "UTF-8"); if (!($start === false)) { @@ -2881,8 +2889,9 @@ function api_format_items_activities(&$item, $type = "json") $xml_activities["friendica:".$k] = $v; // add user data into xml output $k_user = 0; - foreach ($v as $user) + foreach ($v as $user) { $xml_activities["friendica:".$k][$k_user++.":user"] = $user; + } } $activities = $xml_activities; } @@ -3355,7 +3364,7 @@ api_register_func('api/statusnet/version', 'api_statusnet_version', false); /** * @todo use api_format_data() to return data */ -function api_ff_ids($type,$qtype) +function api_ff_ids($type, $qtype) { $a = get_app(); @@ -3409,9 +3418,13 @@ function api_direct_messages_new($type) $a = get_app(); - if (api_user() === false) throw new ForbiddenException(); + if (api_user() === false) { + throw new ForbiddenException(); + } - if (!x($_POST, "text") || (!x($_POST, "screen_name") && !x($_POST, "user_id"))) return; + if (!x($_POST, "text") || (!x($_POST, "screen_name") && !x($_POST, "user_id"))) { + return; + } $sender = api_get_user($a); @@ -3466,7 +3479,6 @@ function api_direct_messages_new($type) } return api_format_data("direct-messages", $type, $data); - } /// @TODO move to top of file or somewhere better @@ -3545,7 +3557,6 @@ function api_direct_messages_destroy($type) } } /// @todo return JSON data like Twitter API not yet implemented - } /// @TODO move to top of file or somewhere better @@ -3727,8 +3738,9 @@ function api_fr_photoalbum_delete($type) intval(api_user()), dbesc($album) ); - if (!DBM::is_result($r)) + if (!DBM::is_result($r)) { throw new BadRequestException("album not available"); + } // function for setting the items to "deleted = 1" which ensures that comments, likes etc. are not shown anymore // to the user and the contacts of the users (drop_items() performs the federation of the deletion to other networks @@ -4264,7 +4276,8 @@ function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $ } logger( "File upload src: " . $src . " - filename: " . $filename . - " - size: " . $filesize . " - type: " . $filetype, LOGGER_DEBUG + " - size: " . $filesize . " - type: " . $filetype, + LOGGER_DEBUG ); // check if there was a php upload error @@ -4663,8 +4676,9 @@ function api_share_as_retweet(&$item) $posted = ""; preg_match("/posted='(.*?)'/ism", $attributes, $matches); - if ($matches[1] != "") + if ($matches[1] != "") { $posted = $matches[1]; + } preg_match('/posted="(.*?)"/ism', $attributes, $matches); if ($matches[1] != "") { @@ -4686,7 +4700,6 @@ function api_share_as_retweet(&$item) $reshared_item["edited"] = $posted; return $reshared_item; - } function api_get_nick($profile) @@ -4781,9 +4794,11 @@ function api_in_reply_to($item) $in_reply_to['screen_name'] = null; if (($item['thr-parent'] != $item['uri']) && (intval($item['parent']) != intval($item['id']))) { - $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' LIMIT 1", + $r = q( + "SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' LIMIT 1", intval($item['uid']), - dbesc($item['thr-parent'])); + dbesc($item['thr-parent']) + ); if (DBM::is_result($r)) { $in_reply_to['status_id'] = intval($r[0]['id']); @@ -4793,7 +4808,8 @@ function api_in_reply_to($item) $in_reply_to['status_id_str'] = (string) intval($in_reply_to['status_id']); - $r = q("SELECT `contact`.`nick`, `contact`.`name`, `contact`.`id`, `contact`.`url` FROM item + $r = q( + "SELECT `contact`.`nick`, `contact`.`name`, `contact`.`id`, `contact`.`url` FROM item STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`author-id` WHERE `item`.`id` = %d LIMIT 1", intval($in_reply_to['status_id']) @@ -4878,39 +4894,56 @@ function api_best_nickname(&$contacts) { $best_contact = array(); - if (count($contact) == 0) + if (count($contact) == 0) { return; + } - foreach ($contacts as $contact) + foreach ($contacts as $contact) { if ($contact["network"] == "") { $contact["network"] = "dfrn"; $best_contact = array($contact); } + } - if (sizeof($best_contact) == 0) - foreach ($contacts as $contact) - if ($contact["network"] == "dfrn") + if (sizeof($best_contact) == 0) { + foreach ($contacts as $contact) { + if ($contact["network"] == "dfrn") { $best_contact = array($contact); + } + } + } - if (sizeof($best_contact) == 0) - foreach ($contacts as $contact) - if ($contact["network"] == "dspr") + if (sizeof($best_contact) == 0) { + foreach ($contacts as $contact) { + if ($contact["network"] == "dspr") { $best_contact = array($contact); + } + } + } - if (sizeof($best_contact) == 0) - foreach ($contacts as $contact) - if ($contact["network"] == "stat") + if (sizeof($best_contact) == 0) { + foreach ($contacts as $contact) { + if ($contact["network"] == "stat") { $best_contact = array($contact); + } + } + } - if (sizeof($best_contact) == 0) - foreach ($contacts as $contact) - if ($contact["network"] == "pump") + if (sizeof($best_contact) == 0) { + foreach ($contacts as $contact) { + if ($contact["network"] == "pump") { $best_contact = array($contact); + } + } + } - if (sizeof($best_contact) == 0) - foreach ($contacts as $contact) - if ($contact["network"] == "twit") + if (sizeof($best_contact) == 0) { + foreach ($contacts as $contact) { + if ($contact["network"] == "twit") { $best_contact = array($contact); + } + } + } if (sizeof($best_contact) == 1) { $contacts = $best_contact; @@ -4924,7 +4957,9 @@ function api_friendica_group_show($type) { $a = get_app(); - if (api_user() === false) throw new ForbiddenException(); + if (api_user() === false) { + throw new ForbiddenException(); + } // params $user_info = api_get_user($a); @@ -4939,8 +4974,9 @@ function api_friendica_group_show($type) intval($gid) ); // error message if specified gid is not in database - if (!DBM::is_result($r)) + if (!DBM::is_result($r)) { throw new BadRequestException("gid not available"); + } } else { $r = q( "SELECT * FROM `group` WHERE `deleted` = 0 AND `uid` = %d", @@ -5035,7 +5071,9 @@ function api_friendica_group_create($type) { $a = get_app(); - if (api_user() === false) throw new ForbiddenException(); + if (api_user() === false) { + throw new ForbiddenException(); + } // params $user_info = api_get_user($a); @@ -5045,8 +5083,9 @@ function api_friendica_group_create($type) $users = $json['user']; // error if no name specified - if ($name == "") + if ($name == "") { throw new BadRequestException('group name not specified'); + } // get data of the specified group name $rname = q( @@ -5055,8 +5094,9 @@ function api_friendica_group_create($type) dbesc($name) ); // error message if specified group name already exists - if (DBM::is_result($rname)) + if (DBM::is_result($rname)) { throw new BadRequestException('group name already exists'); + } // check if specified group name is a deleted group $rname = q( @@ -5065,8 +5105,9 @@ function api_friendica_group_create($type) dbesc($name) ); // error message if specified group name already exists - if (DBM::is_result($rname)) + if (DBM::is_result($rname)) { $reactivate_group = true; + } // create group $ret = Group::create($uid, $name); @@ -5108,7 +5149,9 @@ function api_friendica_group_update($type) { $a = get_app(); - if (api_user() === false) throw new ForbiddenException(); + if (api_user() === false) { + throw new ForbiddenException(); + } // params $user_info = api_get_user($a); @@ -5119,12 +5162,14 @@ function api_friendica_group_update($type) $users = $json['user']; // error if no name specified - if ($name == "") + if ($name == "") { throw new BadRequestException('group name not specified'); + } // error if no gid specified - if ($gid == "") + if ($gid == "") { throw new BadRequestException('gid not specified'); + } // remove members $members = Contact::getByGroupId($gid); @@ -5170,7 +5215,9 @@ function api_friendica_activity($type) { $a = get_app(); - if (api_user() === false) throw new ForbiddenException(); + if (api_user() === false) { + throw new ForbiddenException(); + } $verb = strtolower($a->argv[3]); $verb = preg_replace("|\..*$|", "", $verb); @@ -5212,16 +5259,21 @@ function api_friendica_notification($type) { $a = get_app(); - if (api_user() === false) throw new ForbiddenException(); - if ($a->argc!==3) throw new BadRequestException("Invalid argument count"); + if (api_user() === false) { + throw new ForbiddenException(); + } + if ($a->argc!==3) { + throw new BadRequestException("Invalid argument count"); + } $nm = new NotificationsManager(); $notes = $nm->getAll(array(), "+seen -date", 50); if ($type == "xml") { $xmlnotes = array(); - foreach ($notes as $note) + foreach ($notes as $note) { $xmlnotes[] = array("@attributes" => $note); + } $notes = $xmlnotes; } @@ -5241,14 +5293,20 @@ function api_friendica_notification_seen($type) { $a = get_app(); - if (api_user() === false) throw new ForbiddenException(); - if ($a->argc!==4) throw new BadRequestException("Invalid argument count"); + if (api_user() === false) { + throw new ForbiddenException(); + } + if ($a->argc!==4) { + throw new BadRequestException("Invalid argument count"); + } $id = (x($_REQUEST, 'id') ? intval($_REQUEST['id']) : 0); $nm = new NotificationsManager(); $note = $nm->getByID($id); - if (is_null($note)) throw new BadRequestException("Invalid argument"); + if (is_null($note)) { + throw new BadRequestException("Invalid argument"); + } $nm->setSeen($note); if ($note['otype']=='item') { @@ -5505,15 +5563,15 @@ api_register_func('api/saved_searches/list', 'api_saved_searches_list', true); /* @TODO Maybe open to implement? To.Do: - [pagename] => api/1.1/statuses/lookup.json - [id] => 605138389168451584 - [include_cards] => true - [cards_platform] => Android-12 - [include_entities] => true - [include_my_retweet] => 1 - [include_rts] => 1 - [include_reply_count] => true - [include_descendent_reply_count] => true + [pagename] => api/1.1/statuses/lookup.json + [id] => 605138389168451584 + [include_cards] => true + [cards_platform] => Android-12 + [include_entities] => true + [include_my_retweet] => 1 + [include_rts] => 1 + [include_reply_count] => true + [include_descendent_reply_count] => true (?) From 833815bff5c25c12be4b12434d0df94232ec68a9 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Sun, 24 Dec 2017 00:39:42 +0100 Subject: [PATCH 25/37] Lint doc/Developers-Intro.md --- doc/Developers-Intro.md | 53 +++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/doc/Developers-Intro.md b/doc/Developers-Intro.md index f40186f1d..044599435 100644 --- a/doc/Developers-Intro.md +++ b/doc/Developers-Intro.md @@ -1,5 +1,6 @@ -Where to get started to help improve Friendica? -=============================================== +# Where to get started to help improve Friendica + + * [Home](help) @@ -10,29 +11,25 @@ A project like Friendica is the sum of many different contributions. We are looking for helpers in all areas, whether you write text or code, whether you spread the word to convince people or design new icons. Whether you feel like an expert or like a newbie - join us with your ideas! -Contact us ---- +## Contact us The discussion of Friendica development takes place in the following Friendica forums: * The main [forum for Friendica development](https://forum.friendi.ca/profile/developers) * The [forum for Friendica theme development](https://friendica.eu/profile/ftdevs) -Help other users ---- +## Help other users Remember the questions you had when you first tried Friendica? A good place to start can be to help new people find their way around Friendica in the [general support forum](https://forum.friendi.ca/prufile/helpers). Welcome them, answer their questions, point them to documentation or ping other helpers directly if you can't help but think you know who can. -Translation ---- +## Translation The documentation contains help on how to translate Friendica [at Transifex](/help/translations) where the UI is translated. If you don't want to translate the UI, or it is already done to your satisfaction, you might want to work on the translation of the /help files? -Design ---- +## Design Are you good at designing things? If you have seen Friendica you probably have ideas to improve it, haven't you? @@ -40,11 +37,10 @@ If you have seen Friendica you probably have ideas to improve it, haven't you? * If you would like to work with us on enhancing the user interface, please join the [UX Watchdogs forum](https://fc.oscp.info/profile/ux-watchdogs) * Make plans for a better Friendica interface design and share them with us. * Tell us if you are able to realize your ideas or what kind of help you need. -We can't promise we have the right skills in the group but we'll try. + We can't promise we have the right skills in the group but we'll try. * Choose a thing to start with, e.g. work on the icon set of your favorite theme -Programming ---- +## Programming ### Composer @@ -60,13 +56,14 @@ It's a command-line tool that downloads required libraries into the `vendor` fol For the sake of consistency between contribution and general code readability, Friendica follows the widespread [PSR-2 coding standards](http://www.php-fig.org/psr/psr-2/) to the exception of a few rules. Here's a few primers if you are new to Friendica or to the PSR-2 coding standards: - * Indentation is tabs, period (not PSR-2). - * By default, strings are enclosed in single quotes, but feel free to use double quotes if it makes more sense (SQL queries, adding tabs and line feeds). - * Operators are wrapped by spaces, e.g. `$var === true`, `$var = 1 + 2` and `'string' . $concat . 'enation'` - * Braces are mandatory in conditions - * Boolean operators are `&&` and `||` for PHP conditions, `AND` and `OR` for SQL queries - * No closing PHP tag - * No trailing spaces + +* Indentation is tabs, period (not PSR-2). +* By default, strings are enclosed in single quotes, but feel free to use double quotes if it makes more sense (SQL queries, adding tabs and line feeds). +* Operators are wrapped by spaces, e.g. `$var === true`, `$var = 1 + 2` and `'string' . $concat . 'enation'` +* Braces are mandatory in conditions +* Boolean operators are `&&` and `||` for PHP conditions, `AND` and `OR` for SQL queries +* No closing PHP tag +* No trailing spaces Don't worry, you don't have to know by heart the PSR-2 coding standards to start contributing to Friendica. There are a few tools you can use to check or fix your files before you commit. @@ -100,7 +97,7 @@ If you are interested in having the documentation of the Friendica code outside The configuration file for Doxygen is located in the `util` directory of the project sources. Run - $> doxygen util/Doxyfile + $> doxygen util/Doxyfile to generate the files which will be located in the `doc/html` subdirectory in the Friendica directory. You can browse these files with any browser. @@ -111,11 +108,11 @@ If you find missing documentation, don't hesitate to contact us and write it dow Have a look at our [issue tracker](https://github.com/friendica/friendica) on github! - * Try to reproduce a bug that needs more inquiries and write down what you find out. - * If a bug looks fixed, ask the bug reporters for feedback to find out if the bug can be closed. - * Fix a bug if you can. Please make the pull request against the *develop* branch of the repository. - * There is a *Junior Job* label for issues we think might be a good point to start with. - But you don't have to limit yourself to those issues. +* Try to reproduce a bug that needs more inquiries and write down what you find out. +* If a bug looks fixed, ask the bug reporters for feedback to find out if the bug can be closed. +* Fix a bug if you can. Please make the pull request against the *develop* branch of the repository. +* There is a *Junior Job* label for issues we think might be a good point to start with. + But you don't have to limit yourself to those issues. ### Web interface @@ -124,10 +121,10 @@ This is a piece of work! If you want to get involved here: * Look at the first steps that were made (e.g. the clean theme). -Ask us to find out whom to talk to about their experiences. + Ask us to find out whom to talk to about their experiences. * Talk to design people if you know any. * Let us know about your plans [in the dev forum](https://forum.friendi.ca/profile/developers) or the [theme developer forum](https://friendica.eu/profile/ftdevs). -Do not worry about cross-posting. + Do not worry about cross-posting. ### Client software From e848e376b89a6aaf35054c178c1662d4a23035fa Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 24 Dec 2017 11:51:38 +0000 Subject: [PATCH 26/37] Fix for issue 4121 - now the description isn't empty --- include/api.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/include/api.php b/include/api.php index 9580afa86..eb3ef796d 100644 --- a/include/api.php +++ b/include/api.php @@ -743,13 +743,27 @@ function api_get_user(App $a, $contact_id = null) $pcontact_id = Contact::getIdForURL($uinfo[0]['url'], 0, true); + if (!empty($profile[0]['pdesc'])) { + $description = $profile[0]['pdesc']; + } else { + $description = $uinfo[0]["about"]; + } + + if (!empty($usr[0]['default-location'])) { + $location = $usr[0]['default-location']; + } elseif (!empty($uinfo[0]["location"])) { + $location = $uinfo[0]["location"]; + } else { + $location = network_name; + } + $ret = array( 'id' => intval($pcontact_id), 'id_str' => (string) intval($pcontact_id), 'name' => (($uinfo[0]['name']) ? $uinfo[0]['name'] : $uinfo[0]['nick']), 'screen_name' => (($uinfo[0]['nick']) ? $uinfo[0]['nick'] : $uinfo[0]['name']), - 'location' => ($usr) ? $usr[0]['default-location'] : $network_name, - 'description' => (($profile) ? $profile[0]['pdesc'] : null), + 'location' => $location, + 'description' => $description, 'profile_image_url' => $uinfo[0]['micro'], 'profile_image_url_https' => $uinfo[0]['micro'], 'url' => $uinfo[0]['url'], From 37eecad8ccfaebc7b74b3b3ef976f836a94b01cb Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Sun, 24 Dec 2017 03:20:50 +0100 Subject: [PATCH 27/37] Add missing doc in api.php --- include/api.php | 443 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 389 insertions(+), 54 deletions(-) diff --git a/include/api.php b/include/api.php index 9580afa86..dcd594ead 100644 --- a/include/api.php +++ b/include/api.php @@ -1,8 +1,8 @@ ". * Some clients doesn't send a source param, we support ones we know * (only Twidere, atm) * + * @brief Get source name from API client + * * @return string * Client source name, default to "api" if unset/unknown */ @@ -110,9 +110,9 @@ function api_date($str) } /** - * @brief Register API endpoint + * Register a function to be the endpoint for defined API path. * - * Register a function to be the endpont for defined API path. + * @brief Register API endpoint * * @param string $path API URL path, relative to System::baseUrl() * @param string $func Function name to call on path request @@ -142,11 +142,11 @@ function api_register_func($path, $func, $auth = false, $method = API_METHOD_ANY } /** - * @brief Login API user - * * Log in user via OAuth1 or Simple HTTP Auth. * Simple Auth allow username in form of
user@server
, ignoring server part * + * @brief Login API user + * * @param object $a App * @hook 'authenticate' * array $addon_auth @@ -242,12 +242,12 @@ function api_login(App $a) } /** - * @brief Check HTTP method of called API - * * API endpoints can define which HTTP method to accept when called. * This function check the current HTTP method agains endpoint * registered method. * + * @brief Check HTTP method of called API + * * @param string $method Required methods, uppercase, separated by comma * @return bool */ @@ -260,10 +260,10 @@ function api_check_method($method) } /** - * @brief Main API entry point - * * Authenticate user, call registered API function, set HTTP headers * + * @brief Main API entry point + * * @param object $a App * @return string API call result */ @@ -972,7 +972,9 @@ function api_format_data($root_element, $type, $data) /** * Returns an HTTP 200 OK response code and a representation of the requesting user if authentication was successful; * returns a 401 status code and an error message if not. - * http://developer.twitter.com/doc/get/account/verify_credentials + * @see https://developer.twitter.com/en/docs/accounts-and-users/manage-account-settings/api-reference/get-account-verify_credentials + * + * @param string $type Return type (atom, rss, xml, json) */ function api_account_verify_credentials($type) { @@ -1018,6 +1020,8 @@ api_register_func('api/account/verify_credentials', 'api_account_verify_credenti /** * Get data from $_POST or $_GET + * + * @param string $k */ function requestdata($k) { @@ -1030,7 +1034,13 @@ function requestdata($k) return null; } -/*Waitman Gobble Mod*/ +/** + * Waitman Gobble Mod + * + * @param string $type Return type (atom, rss, xml, json) + * + * @return array|string + */ function api_statuses_mediap($type) { $a = get_app(); @@ -1074,6 +1084,14 @@ function api_statuses_mediap($type) /// @TODO move this to top of file or somewhere better! api_register_func('api/statuses/mediap', 'api_statuses_mediap', true, API_METHOD_POST); +/** + * Updates the user’s current status. + * + * @param string $type Return type (atom, rss, xml, json) + * + * @return array|string + * @see https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-statuses-update + */ function api_statuses_update($type) { @@ -1249,6 +1267,14 @@ function api_statuses_update($type) api_register_func('api/statuses/update', 'api_statuses_update', true, API_METHOD_POST); api_register_func('api/statuses/update_with_media', 'api_statuses_update', true, API_METHOD_POST); +/** + * Uploads an image to Friendica. + * + * @param string $type Return type (atom, rss, xml, json) + * + * @return array + * @see https://developer.twitter.com/en/docs/media/upload-media/api-reference/post-media-upload + */ function api_media_upload($type) { $a = get_app(); @@ -1287,6 +1313,12 @@ function api_media_upload($type) /// @TODO move to top of file or somwhere better api_register_func('api/media/upload', 'api_media_upload', true, API_METHOD_POST); +/** + * + * @param string $type Return type (atom, rss, xml, json) + * + * @return array|string + */ function api_status_show($type) { $a = get_app(); @@ -1391,7 +1423,9 @@ function api_status_show($type) /** * Returns extended information of a given user, specified by ID or screen name as per the required id parameter. * The author's most recent status will be returned inline. - * http://developer.twitter.com/doc/get/users/show + * + * @param string $type Return type (atom, rss, xml, json) + * @see https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-users-show */ function api_users_show($type) { @@ -1477,6 +1511,14 @@ function api_users_show($type) api_register_func('api/users/show', 'api_users_show'); api_register_func('api/externalprofile/show', 'api_users_show'); +/** + * Search a public user account. + * + * @param string $type Return type (atom, rss, xml, json) + * + * @return array|string + * @see https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-users-search + */ function api_users_search($type) { $a = get_app(); @@ -1607,11 +1649,14 @@ api_register_func('api/search/tweets', 'api_search', true); api_register_func('api/search', 'api_search', true); /** + * Returns the most recent statuses posted by the user and the users they follow. * - * http://developer.twitter.com/doc/get/statuses/home_timeline + * @see https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-home_timeline * - * TODO: Optional parameters - * TODO: Add reply info + * @param string $type Return type (atom, rss, xml, json) + * + * @todo Optional parameters + * @todo Add reply info */ function api_statuses_home_timeline($type) { @@ -1708,6 +1753,13 @@ function api_statuses_home_timeline($type) api_register_func('api/statuses/home_timeline', 'api_statuses_home_timeline', true); api_register_func('api/statuses/friends_timeline', 'api_statuses_home_timeline', true); +/** + * Returns the most recent statuses from public users. + * + * @param string $type Return type (atom, rss, xml, json) + * + * @return array|string + */ function api_statuses_public_timeline($type) { $a = get_app(); @@ -1808,6 +1860,8 @@ function api_statuses_public_timeline($type) api_register_func('api/statuses/public_timeline', 'api_statuses_public_timeline', true); /** + * Returns the most recent statuses posted by users this node knows about. + * * @brief Returns the list of public federated posts this node knows about * * @param string $type Return format: json, xml, atom, rss @@ -1878,7 +1932,11 @@ function api_statuses_networkpublic_timeline($type) api_register_func('api/statuses/networkpublic_timeline', 'api_statuses_networkpublic_timeline', true); /** - * @TODO nothing to say? + * Returns a single status. + * + * @param string $type Return type (atom, rss, xml, json) + * + * @see https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/get-statuses-show-id */ function api_statuses_show($type) { @@ -1949,7 +2007,10 @@ function api_statuses_show($type) api_register_func('api/statuses/show', 'api_statuses_show', true); /** - * @TODO nothing to say? + * + * @param string $type Return type (atom, rss, xml, json) + * + * @todo nothing to say? */ function api_conversation_show($type) { @@ -2036,7 +2097,11 @@ api_register_func('api/conversation/show', 'api_conversation_show', true); api_register_func('api/statusnet/conversation', 'api_conversation_show', true); /** - * @TODO nothing to say? + * Repeats a status. + * + * @param string $type Return type (atom, rss, xml, json) + * + * @see https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-statuses-retweet-id */ function api_statuses_repeat($type) { @@ -2114,7 +2179,11 @@ function api_statuses_repeat($type) api_register_func('api/statuses/retweet', 'api_statuses_repeat', true, API_METHOD_POST); /** - * @TODO nothing to say? + * Destroys a specific status. + * + * @param string $type Return type (atom, rss, xml, json) + * + * @see https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-statuses-destroy-id */ function api_statuses_destroy($type) { @@ -2151,8 +2220,11 @@ function api_statuses_destroy($type) api_register_func('api/statuses/destroy', 'api_statuses_destroy', true, API_METHOD_DELETE); /** - * @TODO Nothing more than an URL to say? - * http://developer.twitter.com/doc/get/statuses/mentions + * Returns the most recent mentions. + * + * @param string $type Return type (atom, rss, xml, json) + * + * @see http://developer.twitter.com/doc/get/statuses/mentions */ function api_statuses_mentions($type) { @@ -2238,11 +2310,14 @@ api_register_func('api/statuses/mentions', 'api_statuses_mentions', true); api_register_func('api/statuses/replies', 'api_statuses_mentions', true); /** + * Returns the most recent statuses posted by the user. + * * @brief Returns a user's public timeline * * @param string $type Either "json" or "xml" * @return string|array * @throws ForbiddenException + * @see https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-user_timeline */ function api_statuses_user_timeline($type) { @@ -2330,10 +2405,12 @@ function api_statuses_user_timeline($type) api_register_func('api/statuses/user_timeline', 'api_statuses_user_timeline', true); /** - * Star/unstar an item + * Star/unstar an item. * param: id : id of the item * - * api v1 : https://web.archive.org/web/20131019055350/https://dev.twitter.com/docs/api/1/post/favorites/create/%3Aid + * @param string $type Return type (atom, rss, xml, json) + * + * @see https://web.archive.org/web/20131019055350/https://dev.twitter.com/docs/api/1/post/favorites/create/%3Aid */ function api_favorites_create_destroy($type) { @@ -2405,6 +2482,13 @@ function api_favorites_create_destroy($type) api_register_func('api/favorites/create', 'api_favorites_create_destroy', true, API_METHOD_POST); api_register_func('api/favorites/destroy', 'api_favorites_create_destroy', true, API_METHOD_DELETE); +/** + * Returns the most recent favorite statuses. + * + * @param string $type Return type (atom, rss, xml, json) + * + * @return string|array + */ function api_favorites($type) { global $called_api; @@ -2479,6 +2563,14 @@ function api_favorites($type) /// @TODO move to top of file or somwhere better api_register_func('api/favorites', 'api_favorites', true); +/** + * + * @param array $item + * @param array $recipient + * @param array $sender + * + * @return array + */ function api_format_messages($item, $recipient, $sender) { // standard meta information @@ -2523,6 +2615,12 @@ function api_format_messages($item, $recipient, $sender) return $ret; } +/** + * + * @param array $item + * + * @return array + */ function api_convert_item($item) { $body = $item['body']; @@ -2592,6 +2690,12 @@ function api_convert_item($item) ); } +/** + * + * @param string $body + * + * @return array + */ function api_get_attachments(&$body) { $text = $body; @@ -2623,13 +2727,16 @@ function api_get_attachments(&$body) return $attachments; } +/** + * + * @param string $text + * @param string $bbcode + * + * @return array + * @todo Links at the first character of the post + */ function api_get_entitities(&$text, $bbcode) { - /* - To-Do: - * Links at the first character of the post - */ - $a = get_app(); $include_entities = strtolower(x($_REQUEST, 'include_entities') ? $_REQUEST['include_entities'] : "false"); @@ -2788,6 +2895,14 @@ function api_get_entitities(&$text, $bbcode) return $entities; } + +/** + * + * @param array $item + * @param string $text + * + * @return string + */ function api_format_items_embeded_images(&$item, $text) { $text = preg_replace_callback( @@ -2806,7 +2921,7 @@ function api_format_items_embeded_images(&$item, $text) * * @param string $txt text * @return array - * name => 'name' + * 'name' => 'name', * 'url => 'url' */ function api_contactlink_to_array($txt) @@ -2832,8 +2947,10 @@ function api_contactlink_to_array($txt) * @brief return likes, dislikes and attend status for item * * @param array $item array + * @param string $type Return type (atom, rss, xml, json) + * * @return array - * likes => int count + * likes => int count, * dislikes => int count */ function api_format_items_activities(&$item, $type = "json") @@ -2956,9 +3073,10 @@ function api_format_items_profiles(&$profile = null, $type = "json") /** * @brief format items to be returned by api * - * @param array $r array of items - * @param array $user_info - * @param bool $filter_user filter items by $user_info + * @param array $r array of items + * @param array $user_info + * @param bool $filter_user filter items by $user_info + * @param string $type Return type (atom, rss, xml, json) */ function api_format_items($r, $user_info, $filter_user = false, $type = "json") { @@ -3073,6 +3191,13 @@ function api_format_items($r, $user_info, $filter_user = false, $type = "json") return $ret; } +/** + * Returns the remaining number of API requests available to the user before the API limit is reached. + * + * @param string $type Return type (atom, rss, xml, json) + * + * @return array|string + */ function api_account_rate_limit_status($type) { if ($type == "xml") { @@ -3101,6 +3226,13 @@ function api_account_rate_limit_status($type) /// @TODO move to top of file or somwhere better api_register_func('api/account/rate_limit_status', 'api_account_rate_limit_status', true); +/** + * Returns the string "ok" in the requested format with a 200 OK HTTP status code. + * + * @param string $type Return type (atom, rss, xml, json) + * + * @return array|string + */ function api_help_test($type) { if ($type == 'xml') { @@ -3115,6 +3247,12 @@ function api_help_test($type) /// @TODO move to top of file or somwhere better api_register_func('api/help/test', 'api_help_test', false); +/** + * + * @param string $type Return type (atom, rss, xml, json) + * + * @return array|string + */ function api_lists($type) { $ret = array(); @@ -3125,6 +3263,14 @@ function api_lists($type) /// @TODO move to top of file or somwhere better api_register_func('api/lists', 'api_lists', true); +/** + * Returns all lists the user subscribes to. + * + * @param string $type Return type (atom, rss, xml, json) + * + * @return array|string + * @see https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/get-lists-list + */ function api_lists_list($type) { $ret = array(); @@ -3136,11 +3282,11 @@ function api_lists_list($type) api_register_func('api/lists/list', 'api_lists_list', true); /** - * @brief Returns either the friends of the follower list - * - * Note: Considers friends and followers lists to be private and won't return + * Considers friends and followers lists to be private and won't return * anything if any user_id parameter is passed. * + * @brief Returns either the friends of the follower list + * * @param string $qtype Either "friends" or "followers" * @return boolean|array * @throws ForbiddenException @@ -3225,6 +3371,8 @@ function api_statuses_f($qtype) /** + * Returns the user's friends. + * * @brief Returns the list of friends of the provided user * * @deprecated By Twitter API in favor of friends/list @@ -3242,7 +3390,9 @@ function api_statuses_friends($type) } /** - * @brief Returns the list of friends of the provided user + * Returns the user's followers. + * + * @brief Returns the list of followers of the provided user * * @deprecated By Twitter API in favor of friends/list * @@ -3310,6 +3460,13 @@ function api_friendships_incoming($type) /// @TODO move to top of file or somewhere better api_register_func('api/friendships/incoming', 'api_friendships_incoming', true); +/** + * Returns the instance's configuration information. + * + * @param string $type Return type (atom, rss, xml, json) + * + * @return array|string + */ function api_statusnet_config($type) { $a = get_app(); @@ -3349,6 +3506,12 @@ function api_statusnet_config($type) api_register_func('api/gnusocial/config', 'api_statusnet_config', false); api_register_func('api/statusnet/config', 'api_statusnet_config', false); +/** + * + * @param string $type Return type (atom, rss, xml, json) + * + * @return array|string + */ function api_statusnet_version($type) { // liar @@ -3362,6 +3525,10 @@ api_register_func('api/gnusocial/version', 'api_statusnet_version', false); api_register_func('api/statusnet/version', 'api_statusnet_version', false); /** + * + * @param string $type Return type (atom, rss, xml, json) + * @param string $qtype + * * @todo use api_format_data() to return data */ function api_ff_ids($type, $qtype) @@ -3399,11 +3566,27 @@ function api_ff_ids($type, $qtype) return api_format_data("ids", $type, array('id' => $ids)); } +/** + * Returns the ID of every user the user is following. + * + * @param string $type Return type (atom, rss, xml, json) + * + * @return array|string + * @see https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-friends-ids + */ function api_friends_ids($type) { return api_ff_ids($type, 'friends'); } +/** + * Returns the ID of every user following the user. + * + * @param string $type Return type (atom, rss, xml, json) + * + * @return array|string + * @see https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-followers-ids + */ function api_followers_ids($type) { return api_ff_ids($type, 'followers'); @@ -3413,6 +3596,14 @@ function api_followers_ids($type) api_register_func('api/friends/ids', 'api_friends_ids', true); api_register_func('api/followers/ids', 'api_followers_ids', true); +/** + * Sends a new direct message. + * + * @param string $type Return type (atom, rss, xml, json) + * + * @return array|string + * @see https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/new-message + */ function api_direct_messages_new($type) { @@ -3485,10 +3676,13 @@ function api_direct_messages_new($type) api_register_func('api/direct_messages/new', 'api_direct_messages_new', true, API_METHOD_POST); /** + * Destroys a direct message. + * * @brief delete a direct_message from mail table through api * * @param string $type Known types are 'atom', 'rss', 'xml' and 'json' * @return string + * @see https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/delete-message */ function api_direct_messages_destroy($type) { @@ -3562,6 +3756,14 @@ function api_direct_messages_destroy($type) /// @TODO move to top of file or somewhere better api_register_func('api/direct_messages/destroy', 'api_direct_messages_destroy', true, API_METHOD_DELETE); +/** + * + * @param string $type Return type (atom, rss, xml, json) + * @param string $box + * @param string $verbose + * + * @return array|string + */ function api_direct_messages_box($type, $box, $verbose) { $a = get_app(); @@ -3653,24 +3855,52 @@ function api_direct_messages_box($type, $box, $verbose) return api_format_data("direct-messages", $type, $data); } +/** + * Returns the most recent direct messages sent by the user. + * + * @param string $type Return type (atom, rss, xml, json) + * + * @return array|string + * @see https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/get-sent-message + */ function api_direct_messages_sentbox($type) { $verbose = (x($_GET, 'friendica_verbose') ? strtolower($_GET['friendica_verbose']) : "false"); return api_direct_messages_box($type, "sentbox", $verbose); } +/** + * Returns the most recent direct messages sent to the user. + * + * @param string $type Return type (atom, rss, xml, json) + * + * @return array|string + * @see https://developer.twitter.com/en/docs/direct-messages/sending-and-receiving/api-reference/get-messages + */ function api_direct_messages_inbox($type) { $verbose = (x($_GET, 'friendica_verbose') ? strtolower($_GET['friendica_verbose']) : "false"); return api_direct_messages_box($type, "inbox", $verbose); } +/** + * + * @param string $type Return type (atom, rss, xml, json) + * + * @return array|string + */ function api_direct_messages_all($type) { $verbose = (x($_GET, 'friendica_verbose') ? strtolower($_GET['friendica_verbose']) : "false"); return api_direct_messages_box($type, "all", $verbose); } +/** + * + * @param string $type Return type (atom, rss, xml, json) + * + * @return array|string + */ function api_direct_messages_conversation($type) { $verbose = (x($_GET, 'friendica_verbose') ? strtolower($_GET['friendica_verbose']) : "false"); @@ -3683,6 +3913,12 @@ api_register_func('api/direct_messages/all', 'api_direct_messages_all', true); api_register_func('api/direct_messages/sent', 'api_direct_messages_sentbox', true); api_register_func('api/direct_messages', 'api_direct_messages_inbox', true); +/** + * Returns an OAuth Request Token. + * + * @param string $type Return type (atom, rss, xml, json) + * @see https://oauth.net/core/1.0/#auth_step1 + */ function api_oauth_request_token($type) { $oauth1 = new FKOAuth1(); @@ -3696,6 +3932,14 @@ function api_oauth_request_token($type) killme(); } +/** + * Returns an OAuth Access Token. + * + * @param string $type Return type (atom, rss, xml, json) + * + * @return array|string + * @see https://oauth.net/core/1.0/#auth_step3 + */ function api_oauth_access_token($type) { $oauth1 = new FKOAuth1(); @@ -4093,10 +4337,14 @@ function api_fr_photo_detail($type) /** + * Updates the user’s profile image. + * * @brief updates the profile image for the user (either a specified profile or the default profile) * * @param string $type Known types are 'atom', 'rss', 'xml' and 'json' + * * @return string + * @see https://developer.twitter.com/en/docs/accounts-and-users/manage-account-settings/api-reference/post-account-update_profile_image */ function api_account_update_profile_image($type) { @@ -4210,7 +4458,10 @@ api_register_func('api/friendica/photo/delete', 'api_fr_photo_delete', true, API api_register_func('api/friendica/photo', 'api_fr_photo_detail', true); api_register_func('api/account/update_profile_image', 'api_account_update_profile_image', true, API_METHOD_POST); - +/** + * + * @param string $acl_string + */ function check_acl_input($acl_string) { if ($acl_string == null || $acl_string == " ") { @@ -4236,6 +4487,21 @@ function check_acl_input($acl_string) return $contact_not_found; } +/** + * + * @param string $mediatype + * @param array $media + * @param string $type + * @param string $album + * @param string $allow_cid + * @param string $deny_cid + * @param string $allow_gid + * @param string $deny_gid + * @param string $desc + * @param integer $profile + * @param boolean $visibility + * @param string $photo_id + */ function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $deny_cid, $allow_gid, $deny_gid, $desc, $profile = 0, $visibility = false, $photo_id = null) { $visitor = 0; @@ -4384,6 +4650,16 @@ function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $ } } +/** + * + * @param string $hash + * @param string $allow_cid + * @param string $deny_cid + * @param string $allow_gid + * @param string $deny_gid + * @param string $filetype + * @param boolean $visibility + */ function post_photo_item($hash, $allow_cid, $deny_cid, $allow_gid, $deny_gid, $filetype, $visibility = false) { // get data about the api authenticated user @@ -4429,6 +4705,14 @@ function post_photo_item($hash, $allow_cid, $deny_cid, $allow_gid, $deny_gid, $f item_store($arr); } +/** + * + * @param string $type + * @param int $scale + * @param string $photo_id + * + * @return array + */ function prepare_photo_data($type, $scale, $photo_id) { $scale_sql = ($scale === false ? "" : sprintf("AND scale=%d", intval($scale))); @@ -4702,13 +4986,16 @@ function api_share_as_retweet(&$item) return $reshared_item; } +/** + * + * @param string $profile + * + * @return string|false + * @todo remove trailing junk from profile url + * @todo pump.io check has to check the website + */ function api_get_nick($profile) { - /* To-Do: - - remove trailing junk from profile url - - pump.io check has to check the website - */ - $nick = ""; $r = q( @@ -4783,6 +5070,12 @@ function api_get_nick($profile) return false; } +/** + * + * @param array $item + * + * @return array + */ function api_in_reply_to($item) { $in_reply_to = array(); @@ -4841,6 +5134,12 @@ function api_in_reply_to($item) return $in_reply_to; } +/** + * + * @param string $Text + * + * @return string + */ function api_clean_plain_items($Text) { $include_entities = strtolower(x($_REQUEST, 'include_entities') ? $_REQUEST['include_entities'] : "false"); @@ -4890,6 +5189,12 @@ function api_clean_attachments($body) return $body; } +/** + * + * @param array $contacts + * + * @return array + */ function api_best_nickname(&$contacts) { $best_contact = array(); @@ -4952,7 +5257,13 @@ function api_best_nickname(&$contacts) } } -// return all or a specified group of the user with the containing contacts +/** + * Return all or a specified group of the user with the containing contacts. + * + * @param string $type Return type (atom, rss, xml, json) + * + * @return array|string + */ function api_friendica_group_show($type) { $a = get_app(); @@ -5010,7 +5321,13 @@ function api_friendica_group_show($type) api_register_func('api/friendica/group_show', 'api_friendica_group_show', true); -// delete the specified group of the user +/** + * Delete the specified group of the user. + * + * @param string $type Return type (atom, rss, xml, json) + * + * @return array|string + */ function api_friendica_group_delete($type) { $a = get_app(); @@ -5066,7 +5383,13 @@ function api_friendica_group_delete($type) api_register_func('api/friendica/group_delete', 'api_friendica_group_delete', true, API_METHOD_DELETE); -// create the specified group with the posted array of contacts +/** + * Create the specified group with the posted array of contacts. + * + * @param string $type Return type (atom, rss, xml, json) + * + * @return array|string + */ function api_friendica_group_create($type) { $a = get_app(); @@ -5144,7 +5467,13 @@ function api_friendica_group_create($type) api_register_func('api/friendica/group_create', 'api_friendica_group_create', true, API_METHOD_POST); -// update the specified group with the posted array of contacts +/** + * Update the specified group with the posted array of contacts. + * + * @param string $type Return type (atom, rss, xml, json) + * + * @return array|string + */ function api_friendica_group_update($type) { $a = get_app(); @@ -5211,6 +5540,12 @@ function api_friendica_group_update($type) api_register_func('api/friendica/group_update', 'api_friendica_group_update', true, API_METHOD_POST); +/** + * + * @param string $type Return type (atom, rss, xml, json) + * + * @return array|string + */ function api_friendica_activity($type) { $a = get_app(); @@ -5282,10 +5617,10 @@ function api_friendica_notification($type) } /** - * @brief Set notification as seen and returns associated item (if possible) - * * POST request with 'id' param as notification id * + * @brief Set notification as seen and returns associated item (if possible) + * * @param string $type Known types are 'atom', 'rss', 'xml' and 'json' * @return string */ @@ -5393,7 +5728,7 @@ api_register_func('api/friendica/direct_messages_setseen', 'api_friendica_direct * @brief search for direct_messages containing a searchstring through api * * @param string $type Known types are 'atom', 'rss', 'xml' and 'json' - * @return string (success: success=true if found and search_result contains found messages + * @return string (success: success=true if found and search_result contains found messages, * success=false if nothing was found, search_result='nothing found', * error: result=error with error message) */ From 3873d4863fa7e73467f34c8f3db9fee9387f8502 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Sun, 24 Dec 2017 16:08:34 +0100 Subject: [PATCH 28/37] add Socialhome to the federation stats --- mod/admin.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mod/admin.php b/mod/admin.php index f5bd1d4f5..9408aa31c 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -534,7 +534,7 @@ function admin_page_federation(App $a) // off one % two of them are needed in the query // 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'); + $platforms = array('Friendi%%a', 'Diaspora', '%%red%%', 'Hubzilla', 'BlaBlaNet', 'GNU Social', 'StatusNet', 'Mastodon', 'Pleroma', 'socialhome'); $colors = array( 'Friendi%%a' => '#ffc018', // orange from the logo 'Diaspora' => '#a1a1a1', // logo is black and white, makes a gray @@ -544,7 +544,8 @@ function admin_page_federation(App $a) '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 + 'Pleroma' => '#E46F0F', // Orange from the text that is used on Pleroma instances + 'socialhome' => '#52056b' // lilac from the Django Image used at the Socialhome homepage ); $counts = array(); $total = 0; From ba4329da61492e6369005dc54c86da4e7618179c Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 24 Dec 2017 23:07:14 +0000 Subject: [PATCH 29/37] Fixed typo --- include/api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/api.php b/include/api.php index eb3ef796d..790c94c51 100644 --- a/include/api.php +++ b/include/api.php @@ -754,7 +754,7 @@ function api_get_user(App $a, $contact_id = null) } elseif (!empty($uinfo[0]["location"])) { $location = $uinfo[0]["location"]; } else { - $location = network_name; + $location = $network_name; } $ret = array( From 0475fc1fce4965e660332cd538a43c1c82b7df6c Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 25 Dec 2017 05:39:11 +0000 Subject: [PATCH 30/37] API: Better use "about" instead of "pdesc" --- include/api.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/api.php b/include/api.php index 790c94c51..84ad2a94b 100644 --- a/include/api.php +++ b/include/api.php @@ -743,8 +743,8 @@ function api_get_user(App $a, $contact_id = null) $pcontact_id = Contact::getIdForURL($uinfo[0]['url'], 0, true); - if (!empty($profile[0]['pdesc'])) { - $description = $profile[0]['pdesc']; + if (!empty($profile[0]['about'])) { + $description = $profile[0]['about']; } else { $description = $uinfo[0]["about"]; } From de5dae07513fbc9323b0d2a45394fbae628e5436 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Sat, 23 Dec 2017 00:46:01 +0100 Subject: [PATCH 31/37] Basic support for account/update_profile API (fixes #4094) --- doc/api.md | 18 +++++++++++++++++- include/api.php | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/doc/api.md b/doc/api.md index c565d8699..3306c7d4d 100644 --- a/doc/api.md +++ b/doc/api.md @@ -692,6 +692,23 @@ On error: --- +### account/update_profile (POST; AUTH) + +#### Parameters + +* name (optional): full name of the user +* description (optional): a description of the user + +#### Unsupported parameters + +* url +* location +* profile_link_color +* include_entities +* skip_status + +--- + ### friendships/incoming (*; AUTH) #### Unsupported parameters @@ -1205,7 +1222,6 @@ The following API calls from the Twitter API are not implemented in either Frien * friendships/lookup * account/settings * account/update_delivery_device -* account/update_profile * blocks/ids * users/show * users/search diff --git a/include/api.php b/include/api.php index 0b401f6df..46b7cd3de 100644 --- a/include/api.php +++ b/include/api.php @@ -4472,6 +4472,39 @@ api_register_func('api/friendica/photo/delete', 'api_fr_photo_delete', true, API api_register_func('api/friendica/photo', 'api_fr_photo_detail', true); api_register_func('api/account/update_profile_image', 'api_account_update_profile_image', true, API_METHOD_POST); +/** + * Update user profile + * + * @param string $type Known types are 'atom', 'rss', 'xml' and 'json' + * + * @return array|string + */ +function api_account_update_profile($type) +{ + $local_user = local_user(); + $api_user = api_get_user(get_app()); + + if (x($_POST['name'])) { + dba::update('profile', ['name' => $_POST['name']], ['uid' => $local_user]); + dba::update('user', ['username' => $_POST['name']], ['uid' => $local_user]); + dba::update('contact', ['name' => $_POST['name']], ['uid' => $local_user, 'self' => 1]); + dba::update('contact', ['name' => $_POST['name']], ['id' => $api_user['id']]); + } + + if (x($_POST['description'])) { + dba::update('profile', ['about' => $_POST['description']], ['uid' => $local_user]); + dba::update('contact', ['about' => $_POST['description']], ['uid' => $local_user, 'self' => 1]); + dba::update('contact', ['about' => $_POST['description']], ['id' => $api_user['id']]); + } + + Worker::add(PRIORITY_LOW, 'ProfileUpdate', api_user()); + + return api_account_verify_credentials($type); +} + +/// @TODO move to top of file or somewhere better +api_register_func('api/account/update_profile', 'api_account_update_profile', true, API_METHOD_POST); + /** * * @param string $acl_string From ee5301018aad22a522304b07d8fa096c0c4d0ef3 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Mon, 25 Dec 2017 21:12:08 +0100 Subject: [PATCH 32/37] Fix typo --- include/api.php | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/include/api.php b/include/api.php index 0b401f6df..edc9376e8 100644 --- a/include/api.php +++ b/include/api.php @@ -1029,7 +1029,7 @@ function api_account_verify_credentials($type) return api_format_data("user", $type, array('user' => $user_info)); } -/// @TODO move to top of file or somwhere better +/// @TODO move to top of file or somewhere better api_register_func('api/account/verify_credentials', 'api_account_verify_credentials', true); /** @@ -1277,7 +1277,7 @@ function api_statuses_update($type) return api_status_show($type); } -/// @TODO move to top of file or somwhere better +/// @TODO move to top of file or somewhere better api_register_func('api/statuses/update', 'api_statuses_update', true, API_METHOD_POST); api_register_func('api/statuses/update_with_media', 'api_statuses_update', true, API_METHOD_POST); @@ -1324,7 +1324,7 @@ function api_media_upload($type) return array("media" => $returndata); } -/// @TODO move to top of file or somwhere better +/// @TODO move to top of file or somewhere better api_register_func('api/media/upload', 'api_media_upload', true, API_METHOD_POST); /** @@ -2415,7 +2415,7 @@ function api_statuses_user_timeline($type) return api_format_data("statuses", $type, $data); } -/// @TODO move to top of file or somwhere better +/// @TODO move to top of file or somewhere better api_register_func('api/statuses/user_timeline', 'api_statuses_user_timeline', true); /** @@ -2492,7 +2492,7 @@ function api_favorites_create_destroy($type) return api_format_data("status", $type, $data); } -/// @TODO move to top of file or somwhere better +/// @TODO move to top of file or somewhere better api_register_func('api/favorites/create', 'api_favorites_create_destroy', true, API_METHOD_POST); api_register_func('api/favorites/destroy', 'api_favorites_create_destroy', true, API_METHOD_DELETE); @@ -2574,7 +2574,7 @@ function api_favorites($type) return api_format_data("statuses", $type, $data); } -/// @TODO move to top of file or somwhere better +/// @TODO move to top of file or somewhere better api_register_func('api/favorites', 'api_favorites', true); /** @@ -3237,7 +3237,7 @@ function api_account_rate_limit_status($type) return api_format_data('hash', $type, array('hash' => $hash)); } -/// @TODO move to top of file or somwhere better +/// @TODO move to top of file or somewhere better api_register_func('api/account/rate_limit_status', 'api_account_rate_limit_status', true); /** @@ -3258,7 +3258,7 @@ function api_help_test($type) return api_format_data('ok', $type, array("ok" => $ok)); } -/// @TODO move to top of file or somwhere better +/// @TODO move to top of file or somewhere better api_register_func('api/help/test', 'api_help_test', false); /** @@ -3274,7 +3274,7 @@ function api_lists($type) return api_format_data('lists', $type, array("lists_list" => $ret)); } -/// @TODO move to top of file or somwhere better +/// @TODO move to top of file or somewhere better api_register_func('api/lists', 'api_lists', true); /** @@ -3292,7 +3292,7 @@ function api_lists_list($type) return api_format_data('lists', $type, array("lists_list" => $ret)); } -/// @TODO move to top of file or somwhere better +/// @TODO move to top of file or somewhere better api_register_func('api/lists/list', 'api_lists_list', true); /** @@ -5586,7 +5586,7 @@ function api_friendica_activity($type) } } -/// @TODO move to top of file or somwhere better +/// @TODO move to top of file or somewhere better api_register_func('api/friendica/activity/like', 'api_friendica_activity', true, API_METHOD_POST); api_register_func('api/friendica/activity/dislike', 'api_friendica_activity', true, API_METHOD_POST); api_register_func('api/friendica/activity/attendyes', 'api_friendica_activity', true, API_METHOD_POST); @@ -5677,7 +5677,7 @@ function api_friendica_notification_seen($type) return api_format_data('result', $type, array('result' => "success")); } -/// @TODO move to top of file or somwhere better +/// @TODO move to top of file or somewhere better api_register_func('api/friendica/notification/seen', 'api_friendica_notification_seen', true, API_METHOD_POST); api_register_func('api/friendica/notification', 'api_friendica_notification', true, API_METHOD_GET); @@ -5735,7 +5735,7 @@ function api_friendica_direct_messages_setseen($type) } } -/// @TODO move to top of file or somwhere better +/// @TODO move to top of file or somewhere better api_register_func('api/friendica/direct_messages_setseen', 'api_friendica_direct_messages_setseen', true); /** @@ -5798,7 +5798,7 @@ function api_friendica_direct_messages_search($type) return api_format_data("direct_message_search", $type, array('$result' => $success)); } -/// @TODO move to top of file or somwhere better +/// @TODO move to top of file or somewhere better api_register_func('api/friendica/direct_messages_search', 'api_friendica_direct_messages_search', true); /** @@ -5906,7 +5906,7 @@ function api_saved_searches_list($type) return api_format_data("terms", $type, array('terms' => $result)); } -/// @TODO move to top of file or somwhere better +/// @TODO move to top of file or somewhere better api_register_func('api/saved_searches/list', 'api_saved_searches_list', true); /* From 8c17b9674959159b2b756e2a90fb04e162b40e2a Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Mon, 25 Dec 2017 21:14:02 +0100 Subject: [PATCH 33/37] Missing return types in docblocks --- include/api.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/api.php b/include/api.php index edc9376e8..a7941a979 100644 --- a/include/api.php +++ b/include/api.php @@ -2708,7 +2708,7 @@ function api_convert_item($item) * * @param string $body * - * @return array + * @return array|false */ function api_get_attachments(&$body) { @@ -4329,7 +4329,7 @@ function api_fr_photo_delete($type) * @brief returns the details of a specified photo id, if scale is given, returns the photo data in base 64 * * @param string $type Known types are 'atom', 'rss', 'xml' and 'json' - * @return string + * @return string|array */ function api_fr_photo_detail($type) { From 869af9f323ac8254a8c75b14cd772a5a48c455dd Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 25 Dec 2017 23:03:14 +0000 Subject: [PATCH 34/37] Some more logging for auth_ejabberd --- src/Util/ExAuth.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Util/ExAuth.php b/src/Util/ExAuth.php index 054b87aad..555ab861b 100644 --- a/src/Util/ExAuth.php +++ b/src/Util/ExAuth.php @@ -310,6 +310,7 @@ class ExAuth $lockpath = Config::get('jabber', 'lockpath'); if (is_null($lockpath)) { + $this->writeLog(LOG_INFO, 'No lockpath defined.'); return; } @@ -325,6 +326,9 @@ class ExAuth // Now it is safe to create the pid file PidFile::create($file); + if (!file_exists($file)) { + $this->writeLog(LOG_WARNING, 'Logfile ' . $file . " couldn't be created."); + } } /** From 94244024aca2840913ba43992350505a3115c232 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Tue, 26 Dec 2017 01:05:00 +0100 Subject: [PATCH 35/37] Improve conditions in api_account_update_profile --- include/api.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/api.php b/include/api.php index 46b7cd3de..59317fcd3 100644 --- a/include/api.php +++ b/include/api.php @@ -4481,17 +4481,17 @@ api_register_func('api/account/update_profile_image', 'api_account_update_profil */ function api_account_update_profile($type) { - $local_user = local_user(); + $local_user = api_user(); $api_user = api_get_user(get_app()); - if (x($_POST['name'])) { + if (!empty($_POST['name'])) { dba::update('profile', ['name' => $_POST['name']], ['uid' => $local_user]); dba::update('user', ['username' => $_POST['name']], ['uid' => $local_user]); dba::update('contact', ['name' => $_POST['name']], ['uid' => $local_user, 'self' => 1]); dba::update('contact', ['name' => $_POST['name']], ['id' => $api_user['id']]); } - if (x($_POST['description'])) { + if (isset($_POST['description'])) { dba::update('profile', ['about' => $_POST['description']], ['uid' => $local_user]); dba::update('contact', ['about' => $_POST['description']], ['uid' => $local_user, 'self' => 1]); dba::update('contact', ['about' => $_POST['description']], ['id' => $api_user['id']]); From c490a718acbbb8eb34d1c7f8e49806148a33380e Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Tue, 26 Dec 2017 01:08:51 +0100 Subject: [PATCH 36/37] Update profile in directory when calling api_account_update_profile --- include/api.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/api.php b/include/api.php index 59317fcd3..e2d35d59d 100644 --- a/include/api.php +++ b/include/api.php @@ -4498,6 +4498,11 @@ function api_account_update_profile($type) } Worker::add(PRIORITY_LOW, 'ProfileUpdate', api_user()); + // Update global directory in background + $url = $_SESSION['my_url']; + if ($url && strlen(Config::get('system', 'directory'))) { + Worker::add(PRIORITY_LOW, "Directory", $url); + } return api_account_verify_credentials($type); } From 8b10bfe3a815676e269570405035e93ff7c230bf Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Tue, 26 Dec 2017 21:49:43 +0100 Subject: [PATCH 37/37] Cleaner way to get user URL in api_account_update_profile --- include/api.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/include/api.php b/include/api.php index e2d35d59d..f52b664aa 100644 --- a/include/api.php +++ b/include/api.php @@ -4497,11 +4497,10 @@ function api_account_update_profile($type) dba::update('contact', ['about' => $_POST['description']], ['id' => $api_user['id']]); } - Worker::add(PRIORITY_LOW, 'ProfileUpdate', api_user()); + Worker::add(PRIORITY_LOW, 'ProfileUpdate', $local_user); // Update global directory in background - $url = $_SESSION['my_url']; - if ($url && strlen(Config::get('system', 'directory'))) { - Worker::add(PRIORITY_LOW, "Directory", $url); + if ($api_user['url'] && strlen(Config::get('system', 'directory'))) { + Worker::add(PRIORITY_LOW, "Directory", $api_user['url']); } return api_account_verify_credentials($type);