2010-07-01 23:48:07 +00:00
|
|
|
<?php
|
2018-02-04 23:44:42 +00:00
|
|
|
/**
|
2022-01-02 07:27:47 +00:00
|
|
|
* @copyright Copyright (C) 2010-2022, the Friendica project
|
2020-02-09 15:18:46 +00:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2016-04-03 11:48:31 +00:00
|
|
|
*
|
2015-12-24 00:31:17 +00:00
|
|
|
* Friendica is a communications platform for integrated social communications
|
|
|
|
* utilising decentralised communications and linkage to several indie social
|
|
|
|
* projects - as well as popular mainstream providers.
|
2016-04-03 11:48:31 +00:00
|
|
|
*
|
2015-12-24 00:31:17 +00:00
|
|
|
* Our mission is to free our friends and families from the clutches of
|
|
|
|
* data-harvesting corporations, and pave the way to a future where social
|
|
|
|
* communications are free and open and flow between alternate providers as
|
|
|
|
* easily as email does today.
|
|
|
|
*/
|
2010-07-01 23:48:07 +00:00
|
|
|
|
2018-01-25 02:08:45 +00:00
|
|
|
use Friendica\Model\Contact;
|
2017-01-17 19:21:46 +00:00
|
|
|
|
2017-11-09 16:05:18 +00:00
|
|
|
define('FRIENDICA_PLATFORM', 'Friendica');
|
2022-06-11 08:01:00 +00:00
|
|
|
define('FRIENDICA_CODENAME', 'Giant Rhubarb');
|
2022-06-11 08:06:02 +00:00
|
|
|
define('FRIENDICA_VERSION', '2022.09-dev');
|
2017-11-09 16:05:18 +00:00
|
|
|
define('DFRN_PROTOCOL_VERSION', '2.23');
|
2021-01-17 20:32:13 +00:00
|
|
|
define('NEW_TABLE_STRUCTURE_VERSION', 1288);
|
2017-12-14 21:13:02 +00:00
|
|
|
|
2015-12-25 17:36:13 +00:00
|
|
|
/**
|
2020-01-19 06:05:23 +00:00
|
|
|
* Constant with a HTML line break.
|
2015-12-25 17:36:13 +00:00
|
|
|
*
|
|
|
|
* Contains a HTML line break (br) element and a real carriage return with line
|
|
|
|
* feed for the source.
|
|
|
|
* This can be used in HTML and JavaScript where needed a line break.
|
|
|
|
*/
|
2017-11-09 16:05:18 +00:00
|
|
|
define('EOL', "<br />\r\n");
|
2011-08-17 03:05:02 +00:00
|
|
|
|
2015-12-25 17:36:13 +00:00
|
|
|
/**
|
2015-12-25 19:58:26 +00:00
|
|
|
* @name CP
|
2016-10-02 03:29:30 +00:00
|
|
|
*
|
2015-12-25 17:36:13 +00:00
|
|
|
* Type of the community page
|
2015-12-25 19:58:26 +00:00
|
|
|
* @{
|
2015-12-25 17:36:13 +00:00
|
|
|
*/
|
2018-04-23 11:14:25 +00:00
|
|
|
define('CP_NO_INTERNAL_COMMUNITY', -2);
|
|
|
|
define('CP_NO_COMMUNITY_PAGE', -1);
|
|
|
|
define('CP_USERS_ON_SERVER', 0);
|
|
|
|
define('CP_GLOBAL_COMMUNITY', 1);
|
|
|
|
define('CP_USERS_AND_GLOBAL', 2);
|
2017-11-09 16:05:18 +00:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
2015-02-08 19:35:40 +00:00
|
|
|
|
2010-12-10 12:04:35 +00:00
|
|
|
/**
|
2015-12-25 19:58:26 +00:00
|
|
|
* @name Gravity
|
2016-10-02 03:29:30 +00:00
|
|
|
*
|
2015-12-25 19:58:26 +00:00
|
|
|
* Item weight for query ordering
|
|
|
|
* @{
|
2010-12-10 12:04:35 +00:00
|
|
|
*/
|
2017-11-09 16:05:18 +00:00
|
|
|
define('GRAVITY_PARENT', 0);
|
2018-06-27 18:09:33 +00:00
|
|
|
define('GRAVITY_ACTIVITY', 3);
|
2017-11-09 16:05:18 +00:00
|
|
|
define('GRAVITY_COMMENT', 6);
|
2018-06-27 18:09:33 +00:00
|
|
|
define('GRAVITY_UNKNOWN', 9);
|
2015-12-25 19:58:26 +00:00
|
|
|
/* @}*/
|
|
|
|
|
2016-08-01 05:48:43 +00:00
|
|
|
/**
|
|
|
|
* @name Priority
|
|
|
|
*
|
|
|
|
* Process priority for the worker
|
|
|
|
* @{
|
|
|
|
*/
|
2017-11-09 16:05:18 +00:00
|
|
|
define('PRIORITY_UNDEFINED', 0);
|
|
|
|
define('PRIORITY_CRITICAL', 10);
|
|
|
|
define('PRIORITY_HIGH', 20);
|
|
|
|
define('PRIORITY_MEDIUM', 30);
|
|
|
|
define('PRIORITY_LOW', 40);
|
|
|
|
define('PRIORITY_NEGLIGIBLE', 50);
|
2020-12-08 21:58:32 +00:00
|
|
|
define('PRIORITIES', [PRIORITY_CRITICAL, PRIORITY_HIGH, PRIORITY_MEDIUM, PRIORITY_LOW, PRIORITY_NEGLIGIBLE]);
|
2016-08-01 05:48:43 +00:00
|
|
|
/* @}*/
|
|
|
|
|
2016-05-22 10:31:32 +00:00
|
|
|
// Normally this constant is defined - but not if "pcntl" isn't installed
|
2017-03-19 08:04:04 +00:00
|
|
|
if (!defined("SIGTERM")) {
|
2016-05-22 10:31:32 +00:00
|
|
|
define("SIGTERM", 15);
|
2017-03-19 08:04:04 +00:00
|
|
|
}
|
2017-05-03 02:42:29 +00:00
|
|
|
|
2017-06-03 19:46:19 +00:00
|
|
|
/**
|
|
|
|
* Depending on the PHP version this constant does exist - or not.
|
|
|
|
* See here: http://php.net/manual/en/curl.constants.php#117928
|
|
|
|
*/
|
|
|
|
if (!defined('CURLE_OPERATION_TIMEDOUT')) {
|
2017-11-09 16:05:18 +00:00
|
|
|
define('CURLE_OPERATION_TIMEDOUT', CURLE_OPERATION_TIMEOUTED);
|
2017-06-03 19:46:19 +00:00
|
|
|
}
|
2010-11-24 07:42:45 +00:00
|
|
|
|
2021-11-04 20:29:59 +00:00
|
|
|
if (!function_exists('exif_imagetype')) {
|
|
|
|
function exif_imagetype($file)
|
|
|
|
{
|
|
|
|
$size = getimagesize($file);
|
|
|
|
return $size[2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-24 00:31:17 +00:00
|
|
|
/**
|
2020-01-19 06:05:23 +00:00
|
|
|
* Returns the user id of locally logged in user or false.
|
2016-10-02 03:29:30 +00:00
|
|
|
*
|
2015-12-24 00:31:17 +00:00
|
|
|
* @return int|bool user id or false
|
|
|
|
*/
|
2017-11-09 16:05:18 +00:00
|
|
|
function local_user()
|
|
|
|
{
|
2018-07-10 12:27:56 +00:00
|
|
|
if (!empty($_SESSION['authenticated']) && !empty($_SESSION['uid'])) {
|
2015-12-24 00:31:17 +00:00
|
|
|
return intval($_SESSION['uid']);
|
2017-03-06 10:06:05 +00:00
|
|
|
}
|
2015-12-24 00:31:17 +00:00
|
|
|
return false;
|
2012-04-09 12:04:49 +00:00
|
|
|
}
|
2010-07-01 23:48:07 +00:00
|
|
|
|
2017-03-06 10:06:05 +00:00
|
|
|
/**
|
2020-01-19 06:05:23 +00:00
|
|
|
* Returns the public contact id of logged in user or false.
|
2017-03-06 10:06:05 +00:00
|
|
|
*
|
|
|
|
* @return int|bool public contact id or false
|
|
|
|
*/
|
2017-11-09 16:05:18 +00:00
|
|
|
function public_contact()
|
|
|
|
{
|
2017-03-06 10:06:05 +00:00
|
|
|
static $public_contact_id = false;
|
|
|
|
|
2018-11-30 14:06:22 +00:00
|
|
|
if (!$public_contact_id && !empty($_SESSION['authenticated'])) {
|
|
|
|
if (!empty($_SESSION['my_address'])) {
|
2017-03-06 10:06:05 +00:00
|
|
|
// Local user
|
2020-07-15 21:08:42 +00:00
|
|
|
$public_contact_id = intval(Contact::getIdForURL($_SESSION['my_address'], 0, false));
|
2018-11-30 14:06:22 +00:00
|
|
|
} elseif (!empty($_SESSION['visitor_home'])) {
|
2017-03-06 10:06:05 +00:00
|
|
|
// Remote user
|
2020-07-15 21:08:42 +00:00
|
|
|
$public_contact_id = intval(Contact::getIdForURL($_SESSION['visitor_home'], 0, false));
|
2017-03-06 10:06:05 +00:00
|
|
|
}
|
2018-11-30 14:06:22 +00:00
|
|
|
} elseif (empty($_SESSION['authenticated'])) {
|
2017-03-06 10:06:05 +00:00
|
|
|
$public_contact_id = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $public_contact_id;
|
|
|
|
}
|
|
|
|
|
2015-12-24 00:31:17 +00:00
|
|
|
/**
|
2020-08-05 02:44:42 +00:00
|
|
|
* Returns public contact id of authenticated site visitor or false
|
2016-10-02 03:29:30 +00:00
|
|
|
*
|
2015-12-24 00:31:17 +00:00
|
|
|
* @return int|bool visitor_id or false
|
|
|
|
*/
|
2019-09-28 09:59:08 +00:00
|
|
|
function remote_user()
|
2017-11-09 16:05:18 +00:00
|
|
|
{
|
2019-09-23 22:13:20 +00:00
|
|
|
if (empty($_SESSION['authenticated'])) {
|
2018-07-10 12:27:56 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-09-28 09:59:08 +00:00
|
|
|
if (!empty($_SESSION['visitor_id'])) {
|
2015-12-24 00:31:17 +00:00
|
|
|
return intval($_SESSION['visitor_id']);
|
2017-01-26 13:28:43 +00:00
|
|
|
}
|
2019-09-23 22:13:20 +00:00
|
|
|
|
2015-12-24 00:31:17 +00:00
|
|
|
return false;
|
2012-04-09 12:04:49 +00:00
|
|
|
}
|
2010-07-01 23:48:07 +00:00
|
|
|
|
2015-12-24 00:31:17 +00:00
|
|
|
/**
|
2020-01-19 06:05:23 +00:00
|
|
|
* Show an error message to user.
|
2015-12-24 00:31:17 +00:00
|
|
|
*
|
|
|
|
* This function save text in session, to be shown to the user at next page load
|
|
|
|
*
|
|
|
|
* @param string $s - Text of notice
|
|
|
|
*/
|
2017-11-09 16:05:18 +00:00
|
|
|
function notice($s)
|
|
|
|
{
|
2018-07-15 18:36:20 +00:00
|
|
|
if (empty($_SESSION)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-30 14:06:22 +00:00
|
|
|
if (empty($_SESSION['sysmsg'])) {
|
2018-01-15 13:05:12 +00:00
|
|
|
$_SESSION['sysmsg'] = [];
|
2017-01-26 13:28:43 +00:00
|
|
|
}
|
2021-07-24 10:09:39 +00:00
|
|
|
|
|
|
|
$_SESSION['sysmsg'][] = $s;
|
2012-04-09 12:04:49 +00:00
|
|
|
}
|
2014-04-26 00:22:30 +00:00
|
|
|
|
2015-12-24 00:31:17 +00:00
|
|
|
/**
|
2020-01-19 06:05:23 +00:00
|
|
|
* Show an info message to user.
|
2015-12-24 00:31:17 +00:00
|
|
|
*
|
|
|
|
* This function save text in session, to be shown to the user at next page load
|
|
|
|
*
|
|
|
|
* @param string $s - Text of notice
|
|
|
|
*/
|
2017-11-09 16:05:18 +00:00
|
|
|
function info($s)
|
|
|
|
{
|
2021-07-24 10:09:39 +00:00
|
|
|
if (empty($_SESSION)) {
|
|
|
|
return;
|
|
|
|
}
|
2014-04-26 00:22:30 +00:00
|
|
|
|
2018-11-30 14:06:22 +00:00
|
|
|
if (empty($_SESSION['sysmsg_info'])) {
|
2018-01-15 13:05:12 +00:00
|
|
|
$_SESSION['sysmsg_info'] = [];
|
2017-01-26 13:28:43 +00:00
|
|
|
}
|
2021-07-24 10:09:39 +00:00
|
|
|
|
|
|
|
$_SESSION['sysmsg_info'][] = $s;
|
2015-12-24 00:31:17 +00:00
|
|
|
}
|