diff --git a/boot.php b/boot.php index 7be7063eb..199ca0555 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'); @@ -619,10 +618,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 +653,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,63 +670,46 @@ function check_url(App $a) function update_db(App $a) { $build = Config::get('system', 'build'); - if (!x($build)) { - $build = Config::set('system', 'build', DB_UPDATE_VERSION); + + if (empty($build)) { + Config::set('system', 'build', DB_UPDATE_VERSION); + $build = DB_UPDATE_VERSION; } if ($build != DB_UPDATE_VERSION) { + require_once 'update.php'; + $stored = intval($build); $current = intval(DB_UPDATE_VERSION); 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 + 1; $x <= $current; $x++) { + $r = run_update_function($x); + if (!$r) { + break; } } } @@ -996,7 +985,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 +1040,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/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 diff --git a/doc/api.md b/doc/api.md index d756e81a4..3306c7d4d 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 @@ -686,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 @@ -1199,8 +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 -* account/update_profile_background_image * blocks/ids * users/show * users/search @@ -1234,7 +1255,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..e8e2295b8 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 @@ -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"); } @@ -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'); @@ -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 */ @@ -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"); @@ -399,7 +400,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) { @@ -742,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]['about'])) { + $description = $profile[0]['about']; + } 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'], @@ -946,12 +961,10 @@ 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) { - $a = get_app(); - switch ($type) { case "atom": case "rss": @@ -973,7 +986,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) { @@ -1014,11 +1029,13 @@ 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); /** * Get data from $_POST or $_GET + * + * @param string $k */ function requestdata($k) { @@ -1031,7 +1048,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(); @@ -1075,6 +1098,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) { @@ -1246,10 +1277,18 @@ 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); +/** + * 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(); @@ -1285,9 +1324,15 @@ 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); +/** + * + * @param string $type Return type (atom, rss, xml, json) + * + * @return array|string + */ function api_status_show($type) { $a = get_app(); @@ -1392,7 +1437,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) { @@ -1478,6 +1525,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(); @@ -1496,7 +1551,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; @@ -1525,8 +1580,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 +1612,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) { @@ -1610,11 +1663,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) { @@ -1711,6 +1767,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(); @@ -1741,7 +1804,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() . " @@ -1770,7 +1834,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` @@ -1809,6 +1874,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 @@ -1841,7 +1908,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() . " @@ -1878,7 +1946,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 +2021,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) { @@ -2013,10 +2088,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)) { @@ -2034,7 +2111,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) { @@ -2112,7 +2193,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) { @@ -2149,8 +2234,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) { @@ -2236,11 +2324,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) { @@ -2324,14 +2415,16 @@ function api_statuses_user_timeline($type) return api_format_data("statuses", $type, $data); } -/// @TODO move to top of file or somwhere better -api_register_func('api/statuses/user_timeline','api_statuses_user_timeline', true); +/// @TODO move to top of file or somewhere better +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) { @@ -2376,7 +2469,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()); @@ -2399,10 +2492,17 @@ 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); +/** + * 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; @@ -2474,9 +2574,17 @@ 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); +/** + * + * @param array $item + * @param array $recipient + * @param array $sender + * + * @return array + */ function api_format_messages($item, $recipient, $sender) { // standard meta information @@ -2521,6 +2629,12 @@ function api_format_messages($item, $recipient, $sender) return $ret; } +/** + * + * @param array $item + * + * @return array + */ function api_convert_item($item) { $body = $item['body']; @@ -2590,6 +2704,12 @@ function api_convert_item($item) ); } +/** + * + * @param string $body + * + * @return array|false + */ function api_get_attachments(&$body) { $text = $body; @@ -2621,13 +2741,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"); @@ -2696,14 +2819,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); @@ -2722,8 +2846,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; @@ -2732,8 +2857,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)) { @@ -2783,6 +2909,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( @@ -2801,7 +2935,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) @@ -2827,8 +2961,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") @@ -2884,8 +3020,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; } @@ -2950,9 +3087,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") { @@ -3053,12 +3191,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; @@ -3066,6 +3205,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") { @@ -3091,9 +3237,16 @@ 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); +/** + * 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') { @@ -3105,9 +3258,15 @@ 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); +/** + * + * @param string $type Return type (atom, rss, xml, json) + * + * @return array|string + */ function api_lists($type) { $ret = array(); @@ -3115,9 +3274,17 @@ 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); +/** + * 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(); @@ -3125,15 +3292,15 @@ 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); /** - * @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 @@ -3167,10 +3334,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)); } @@ -3218,6 +3385,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 @@ -3235,7 +3404,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 * @@ -3263,7 +3434,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 +3455,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) { @@ -3305,6 +3474,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(); @@ -3317,7 +3493,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()) : ''); @@ -3344,6 +3520,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 @@ -3357,9 +3539,13 @@ 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) +function api_ff_ids($type, $qtype) { $a = get_app(); @@ -3369,17 +3555,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( @@ -3405,11 +3580,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'); @@ -3419,14 +3610,26 @@ 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) { $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); @@ -3481,17 +3684,19 @@ function api_direct_messages_new($type) } return api_format_data("direct-messages", $type, $data); - } /// @TODO move to top of file or somewhere better 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) { @@ -3560,12 +3765,19 @@ 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 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(); @@ -3657,24 +3869,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"); @@ -3687,6 +3927,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(); @@ -3700,6 +3946,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(); @@ -3742,8 +3996,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 @@ -4074,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) { @@ -4096,10 +4351,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) { @@ -4213,7 +4472,47 @@ 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 = api_user(); + $api_user = api_get_user(get_app()); + 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 (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']]); + } + + Worker::add(PRIORITY_LOW, 'ProfileUpdate', $local_user); + // Update global directory in background + if ($api_user['url'] && strlen(Config::get('system', 'directory'))) { + Worker::add(PRIORITY_LOW, "Directory", $api_user['url']); + } + + 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 + */ function check_acl_input($acl_string) { if ($acl_string == null || $acl_string == " ") { @@ -4239,6 +4538,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; @@ -4279,7 +4593,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 @@ -4288,7 +4603,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)"); } @@ -4386,6 +4701,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 @@ -4431,6 +4756,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))); @@ -4551,8 +4884,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."); @@ -4562,26 +4895,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; } @@ -4597,10 +4926,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 ); @@ -4611,7 +4940,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) { @@ -4682,8 +5011,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] != "") { @@ -4705,16 +5035,18 @@ function api_share_as_retweet(&$item) $reshared_item["edited"] = $posted; 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( @@ -4789,6 +5121,12 @@ function api_get_nick($profile) return false; } +/** + * + * @param array $item + * + * @return array + */ function api_in_reply_to($item) { $in_reply_to = array(); @@ -4800,9 +5138,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']); @@ -4812,7 +5152,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']) @@ -4844,6 +5185,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"); @@ -4874,62 +5221,85 @@ 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; } +/** + * + * @param array $contacts + * + * @return array + */ 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; @@ -4938,12 +5308,20 @@ 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(); - if (api_user() === false) throw new ForbiddenException(); + if (api_user() === false) { + throw new ForbiddenException(); + } // params $user_info = api_get_user($a); @@ -4958,8 +5336,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", @@ -4993,7 +5372,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(); @@ -5049,12 +5434,20 @@ 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(); - if (api_user() === false) throw new ForbiddenException(); + if (api_user() === false) { + throw new ForbiddenException(); + } // params $user_info = api_get_user($a); @@ -5064,8 +5457,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( @@ -5074,8 +5468,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( @@ -5084,8 +5479,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); @@ -5106,9 +5502,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; } @@ -5122,12 +5518,20 @@ 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(); - if (api_user() === false) throw new ForbiddenException(); + if (api_user() === false) { + throw new ForbiddenException(); + } // params $user_info = api_get_user($a); @@ -5138,12 +5542,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); @@ -5185,11 +5591,19 @@ 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(); - if (api_user() === false) throw new ForbiddenException(); + if (api_user() === false) { + throw new ForbiddenException(); + } $verb = strtolower($a->argv[3]); $verb = preg_replace("|\..*$|", "", $verb); @@ -5209,7 +5623,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); @@ -5231,16 +5645,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; } @@ -5249,10 +5668,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 */ @@ -5260,14 +5679,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') { @@ -5289,7 +5714,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); @@ -5347,14 +5772,14 @@ 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); /** * @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) */ @@ -5410,7 +5835,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); /** @@ -5490,18 +5915,49 @@ 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 + */ +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']) + ); + } + + dba::close($terms); + + return api_format_data("terms", $type, array('terms' => $result)); +} + +/// @TODO move to top of file or somewhere better +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 (?) diff --git a/include/identity.php b/include/identity.php index 9a0900dc1..8f515580f 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)))); + $split_name = Diaspora::splitName($profile['name']); + $firstname = $split_name['first']; + $lastname = $split_name['last']; if ($profile['guid'] != "") { $diaspora = array( 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; diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 8828324c5..a0d99959b 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" + */ + public 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)))); + + $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'; $small = System::baseUrl().'/photo/custom/50/' .$profile['uid'].'.jpg'; 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; 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."); + } } /** diff --git a/update.php b/update.php index a968451e3..352092ec2 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"); +function update_1178() { + require_once 'mod/profiles.php'; $profiles = q("SELECT `uid`, `about`, `locality`, `pub_keywords`, `gender` FROM `profile` WHERE `is-default`"); @@ -1633,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); @@ -1643,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"); @@ -1651,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'))) { @@ -1662,9 +79,9 @@ function update_1188() { return UPDATE_SUCCESS; } -function update_1190() { +function update_1191() { - require_once('include/plugin.php'); + require_once 'include/plugin.php'; Config::set('system', 'maintenance', 1); @@ -1726,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)); }