Merge remote-tracking branch 'upstream/develop' into 1706-ostatus-attach
Conflicts: include/text.php
This commit is contained in:
commit
181947f774
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -54,3 +54,6 @@ venv/
|
|||
|
||||
#ignore git projects in vendor
|
||||
vendor/**/.git
|
||||
|
||||
#ignore config files from JetBrains
|
||||
/.idea
|
23
INSTALL.txt
23
INSTALL.txt
|
@ -71,9 +71,14 @@ write or create files in your web directory, create an empty file called
|
|||
.htconfig.php and make it writable by the web server.
|
||||
|
||||
5. Visit your website with a web browser and follow the instructions. Please
|
||||
note any error messages and correct these before continuing. If you are using
|
||||
SSL with a known signature authority (recommended), use the https: link to your
|
||||
website. If you are using a self-signed cert or no cert, use the http: link.
|
||||
note any error messages and correct these before continuing.
|
||||
|
||||
If you are using SSL with a known signature authority (recommended), use the
|
||||
https: link to your website. If you are using a self-signed cert or no cert,
|
||||
use the http: link.
|
||||
|
||||
If you need to specify a port for the connection to the database, you can do
|
||||
so in the host name setting for the database.
|
||||
|
||||
6. *If* the automated installation fails for any reason, check the following:
|
||||
|
||||
|
@ -135,7 +140,17 @@ $a->config['system']['addon'] = 'js_upload,poormancron';
|
|||
|
||||
and save your changes.
|
||||
|
||||
9. (Optional) Reverse-proxying and HTTPS
|
||||
9. (Recommended) Set up a backup plan
|
||||
|
||||
Bad things will happen. Let there be a hardware failure, a corrupted
|
||||
database or whatever you can think of. So once the installation of your
|
||||
Friendica node is done, you should make yoursef a backup plan.
|
||||
|
||||
The most important file is the `.htconfig.php` file in the base directory.
|
||||
As it stores all your data, you should also have a recent dump of your
|
||||
Friendica database at hand, should you have to recover your node.
|
||||
|
||||
10. (Optional) Reverse-proxying and HTTPS
|
||||
|
||||
Friendica looks for some well-known HTTP headers indicating a reverse-proxy
|
||||
terminating an HTTPS connection. While the standard from RFC 7239 specifies
|
||||
|
|
2
Vagrantfile
vendored
2
Vagrantfile
vendored
|
@ -47,7 +47,7 @@ Vagrant.configure(2) do |config|
|
|||
|
||||
######################################################################
|
||||
# Share a folder between host and guest
|
||||
config.vm.synced_folder "./", "/vagrant/", owner: "www-data", group: "vagrant"
|
||||
config.vm.synced_folder ".", "/vagrant", id: "vagrant-root", owner: "www-data", group: "vagrant"
|
||||
|
||||
|
||||
# Provider-specific configuration so you can fine-tune various
|
||||
|
|
124
boot.php
124
boot.php
|
@ -22,6 +22,7 @@ require_once(__DIR__ . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'a
|
|||
|
||||
use Friendica\App;
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Util\Lock;
|
||||
|
||||
require_once 'include/config.php';
|
||||
require_once 'include/network.php';
|
||||
|
@ -35,12 +36,13 @@ require_once 'include/features.php';
|
|||
require_once 'include/identity.php';
|
||||
require_once 'update.php';
|
||||
require_once 'include/dbstructure.php';
|
||||
require_once 'include/poller.php';
|
||||
|
||||
define ( 'FRIENDICA_PLATFORM', 'Friendica');
|
||||
define ( 'FRIENDICA_CODENAME', 'Asparagus');
|
||||
define ( 'FRIENDICA_VERSION', '3.5.3dev' );
|
||||
define ( 'FRIENDICA_VERSION', '3.5.3-dev' );
|
||||
define ( 'DFRN_PROTOCOL_VERSION', '2.23' );
|
||||
define ( 'DB_UPDATE_VERSION', 1227 );
|
||||
define ( 'DB_UPDATE_VERSION', 1232 );
|
||||
|
||||
/**
|
||||
* @brief Constant with a HTML line break.
|
||||
|
@ -992,7 +994,7 @@ function notice($s) {
|
|||
function info($s) {
|
||||
$a = get_app();
|
||||
|
||||
if (local_user() AND get_pconfig(local_user(), 'system', 'ignore_info')) {
|
||||
if (local_user() && get_pconfig(local_user(), 'system', 'ignore_info')) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1062,12 +1064,13 @@ function proc_run($cmd) {
|
|||
$arr = array('args' => $args, 'run_cmd' => true);
|
||||
|
||||
call_hooks("proc_run", $arr);
|
||||
if (!$arr['run_cmd'] OR ! count($args)) {
|
||||
if (!$arr['run_cmd'] || ! count($args)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$priority = PRIORITY_MEDIUM;
|
||||
$dont_fork = get_config("system", "worker_dont_fork");
|
||||
$created = datetime_convert();
|
||||
|
||||
if (is_int($run_parameter)) {
|
||||
$priority = $run_parameter;
|
||||
|
@ -1075,6 +1078,9 @@ function proc_run($cmd) {
|
|||
if (isset($run_parameter['priority'])) {
|
||||
$priority = $run_parameter['priority'];
|
||||
}
|
||||
if (isset($run_parameter['created'])) {
|
||||
$created = $run_parameter['created'];
|
||||
}
|
||||
if (isset($run_parameter['dont_fork'])) {
|
||||
$dont_fork = $run_parameter['dont_fork'];
|
||||
}
|
||||
|
@ -1084,10 +1090,10 @@ function proc_run($cmd) {
|
|||
array_shift($argv);
|
||||
|
||||
$parameters = json_encode($argv);
|
||||
$found = dba::select('workerqueue', array('id'), array('parameter' => $parameters), array('limit' => 1));
|
||||
$found = dba::select('workerqueue', array('id'), array('parameter' => $parameters, 'done' => false), array('limit' => 1));
|
||||
|
||||
if (!dbm::is_result($found)) {
|
||||
dba::insert('workerqueue', array('parameter' => $parameters, 'created' => datetime_convert(), 'priority' => $priority));
|
||||
dba::insert('workerqueue', array('parameter' => $parameters, 'created' => $created, 'priority' => $priority));
|
||||
}
|
||||
|
||||
// Should we quit and wait for the poller to be called as a cronjob?
|
||||
|
@ -1095,18 +1101,16 @@ function proc_run($cmd) {
|
|||
return;
|
||||
}
|
||||
|
||||
// Checking number of workers
|
||||
$workers = q("SELECT COUNT(*) AS `workers` FROM `workerqueue` WHERE `executed` > '%s'", dbesc(NULL_DATE));
|
||||
|
||||
// Get number of allowed number of worker threads
|
||||
$queues = intval(get_config("system", "worker_queues"));
|
||||
|
||||
if ($queues == 0) {
|
||||
$queues = 4;
|
||||
// If there is a lock then we don't have to check for too much worker
|
||||
if (!Lock::set('poller_worker', 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If there are already enough workers running, don't fork another one
|
||||
if ($workers[0]["workers"] >= $queues) {
|
||||
$quit = poller_too_much_workers();
|
||||
Lock::remove('poller_worker');
|
||||
|
||||
if ($quit) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1388,6 +1392,43 @@ function get_server() {
|
|||
return($server);
|
||||
}
|
||||
|
||||
function get_temppath() {
|
||||
$a = get_app();
|
||||
|
||||
$temppath = get_config("system", "temppath");
|
||||
|
||||
if (($temppath != "") && App::directory_usable($temppath)) {
|
||||
// We have a temp path and it is usable
|
||||
return $temppath;
|
||||
}
|
||||
|
||||
// We don't have a working preconfigured temp path, so we take the system path.
|
||||
$temppath = sys_get_temp_dir();
|
||||
|
||||
// Check if it is usable
|
||||
if (($temppath != "") && App::directory_usable($temppath)) {
|
||||
// To avoid any interferences with other systems we create our own directory
|
||||
$new_temppath = $temppath . "/" . $a->get_hostname();
|
||||
if (!is_dir($new_temppath)) {
|
||||
/// @TODO There is a mkdir()+chmod() upwards, maybe generalize this (+ configurable) into a function/method?
|
||||
mkdir($new_temppath);
|
||||
}
|
||||
|
||||
if (App::directory_usable($new_temppath)) {
|
||||
// The new path is usable, we are happy
|
||||
set_config("system", "temppath", $new_temppath);
|
||||
return $new_temppath;
|
||||
} else {
|
||||
// We can't create a subdirectory, strange.
|
||||
// But the directory seems to work, so we use it but don't store it.
|
||||
return $temppath;
|
||||
}
|
||||
}
|
||||
|
||||
// Reaching this point means that the operating system is configured badly.
|
||||
return '';
|
||||
}
|
||||
|
||||
function get_cachefile($file, $writemode = true) {
|
||||
$cache = get_itemcachepath();
|
||||
|
||||
|
@ -1416,7 +1457,7 @@ function clear_cache($basepath = "", $path = "") {
|
|||
$path = $basepath;
|
||||
}
|
||||
|
||||
if (($path == "") OR (!is_dir($path))) {
|
||||
if (($path == "") || (!is_dir($path))) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1433,10 +1474,10 @@ function clear_cache($basepath = "", $path = "") {
|
|||
if ($dh = opendir($path)) {
|
||||
while (($file = readdir($dh)) !== false) {
|
||||
$fullpath = $path . "/" . $file;
|
||||
if ((filetype($fullpath) == "dir") and ($file != ".") and ($file != "..")) {
|
||||
if ((filetype($fullpath) == "dir") && ($file != ".") && ($file != "..")) {
|
||||
clear_cache($basepath, $fullpath);
|
||||
}
|
||||
if ((filetype($fullpath) == "file") and (filectime($fullpath) < (time() - $cachetime))) {
|
||||
if ((filetype($fullpath) == "file") && (filectime($fullpath) < (time() - $cachetime))) {
|
||||
unlink($fullpath);
|
||||
}
|
||||
}
|
||||
|
@ -1453,7 +1494,7 @@ function get_itemcachepath() {
|
|||
}
|
||||
|
||||
$itemcache = get_config('system', 'itemcache');
|
||||
if (($itemcache != "") AND App::directory_usable($itemcache)) {
|
||||
if (($itemcache != "") && App::directory_usable($itemcache)) {
|
||||
return $itemcache;
|
||||
}
|
||||
|
||||
|
@ -1480,7 +1521,7 @@ function get_itemcachepath() {
|
|||
*/
|
||||
function get_spoolpath() {
|
||||
$spoolpath = get_config('system', 'spoolpath');
|
||||
if (($spoolpath != "") AND App::directory_usable($spoolpath)) {
|
||||
if (($spoolpath != "") && App::directory_usable($spoolpath)) {
|
||||
// We have a spool path and it is usable
|
||||
return $spoolpath;
|
||||
}
|
||||
|
@ -1510,43 +1551,6 @@ function get_spoolpath() {
|
|||
return "";
|
||||
}
|
||||
|
||||
function get_temppath() {
|
||||
$a = get_app();
|
||||
|
||||
$temppath = get_config("system", "temppath");
|
||||
|
||||
if (($temppath != "") AND App::directory_usable($temppath)) {
|
||||
// We have a temp path and it is usable
|
||||
return $temppath;
|
||||
}
|
||||
|
||||
// We don't have a working preconfigured temp path, so we take the system path.
|
||||
$temppath = sys_get_temp_dir();
|
||||
|
||||
// Check if it is usable
|
||||
if (($temppath != "") AND App::directory_usable($temppath)) {
|
||||
// To avoid any interferences with other systems we create our own directory
|
||||
$new_temppath = $temppath . "/" . $a->get_hostname();
|
||||
if (!is_dir($new_temppath)) {
|
||||
/// @TODO There is a mkdir()+chmod() upwards, maybe generalize this (+ configurable) into a function/method?
|
||||
mkdir($new_temppath);
|
||||
}
|
||||
|
||||
if (App::directory_usable($new_temppath)) {
|
||||
// The new path is usable, we are happy
|
||||
set_config("system", "temppath", $new_temppath);
|
||||
return $new_temppath;
|
||||
} else {
|
||||
// We can't create a subdirectory, strange.
|
||||
// But the directory seems to work, so we use it but don't store it.
|
||||
return $temppath;
|
||||
}
|
||||
}
|
||||
|
||||
// Reaching this point means that the operating system is configured badly.
|
||||
return '';
|
||||
}
|
||||
|
||||
/// @deprecated
|
||||
function set_template_engine(App $a, $engine = 'internal') {
|
||||
/// @note This function is no longer necessary, but keep it as a wrapper to the class method
|
||||
|
@ -1647,7 +1651,7 @@ function argv($x) {
|
|||
function infinite_scroll_data($module) {
|
||||
|
||||
if (get_pconfig(local_user(), 'system', 'infinite_scroll')
|
||||
AND ($module == "network") AND ($_GET["mode"] != "minimal")) {
|
||||
&& ($module == "network") && ($_GET["mode"] != "minimal")) {
|
||||
|
||||
// get the page number
|
||||
if (is_string($_GET["page"])) {
|
||||
|
@ -1660,12 +1664,12 @@ function infinite_scroll_data($module) {
|
|||
|
||||
// try to get the uri from which we load the content
|
||||
foreach ($_GET AS $param => $value) {
|
||||
if (($param != "page") AND ($param != "q")) {
|
||||
if (($param != "page") && ($param != "q")) {
|
||||
$reload_uri .= "&" . $param . "=" . urlencode($value);
|
||||
}
|
||||
}
|
||||
|
||||
if (($a->page_offset != "") AND ! strstr($reload_uri, "&offset=")) {
|
||||
if (($a->page_offset != "") && ! strstr($reload_uri, "&offset=")) {
|
||||
$reload_uri .= "&offset=" . urlencode($a->page_offset);
|
||||
}
|
||||
|
||||
|
|
11
database.sql
11
database.sql
|
@ -1,6 +1,6 @@
|
|||
-- ------------------------------------------
|
||||
-- Friendica 3.5.2-rc (Asparagus)
|
||||
-- DB_UPDATE_VERSION 1227
|
||||
-- Friendica 3.5.3-dev (Asparagus)
|
||||
-- DB_UPDATE_VERSION 1231
|
||||
-- ------------------------------------------
|
||||
|
||||
|
||||
|
@ -580,7 +580,7 @@ CREATE TABLE IF NOT EXISTS `locks` (
|
|||
`id` int(11) NOT NULL auto_increment,
|
||||
`name` varchar(128) NOT NULL DEFAULT '',
|
||||
`locked` tinyint(1) NOT NULL DEFAULT 0,
|
||||
`created` datetime DEFAULT '0001-01-01 00:00:00',
|
||||
`pid` int(10) unsigned NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY(`id`)
|
||||
) DEFAULT COLLATE utf8mb4_general_ci;
|
||||
|
||||
|
@ -1114,8 +1114,11 @@ CREATE TABLE IF NOT EXISTS `workerqueue` (
|
|||
`created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
|
||||
`pid` int(11) NOT NULL DEFAULT 0,
|
||||
`executed` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
|
||||
`done` tinyint(1) NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY(`id`),
|
||||
INDEX `pid` (`pid`),
|
||||
INDEX `priority_created` (`priority`,`created`)
|
||||
INDEX `parameter` (`parameter`(64)),
|
||||
INDEX `priority_created` (`priority`,`created`),
|
||||
INDEX `executed` (`executed`)
|
||||
) DEFAULT COLLATE utf8mb4_general_ci;
|
||||
|
||||
|
|
|
@ -89,7 +89,10 @@ A ['Tips for New Members'](newmember) link will show up on your network and home
|
|||
Retrieving Personal Data
|
||||
---
|
||||
|
||||
You can export a copy of your personal data in XML format from the "Export personal data" link at the top of your settings page.
|
||||
You can export a copy of your personal data in JSON format from the "Export personal data" link at the top of your settings page.
|
||||
|
||||
You need this file to relocate your Friendica account to another node.
|
||||
This might be necessary, e.g. if your node suffers a severe hardware problem and is not recoverable.
|
||||
|
||||
See Also
|
||||
---
|
||||
|
|
|
@ -64,6 +64,7 @@ Here's a few primers if you are new to Friendica or to the PSR-2 coding standard
|
|||
* 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
|
||||
|
||||
|
|
|
@ -82,6 +82,8 @@ Restart mysql and you should be fine.
|
|||
Point your web browser to the new site and follow the instructions.
|
||||
Please note any error messages and correct these before continuing.
|
||||
|
||||
If you need to specify a port for the connection to the database, you can do so in the host name setting for the database.
|
||||
|
||||
*If* the automated installation fails for any reason, check the following:
|
||||
|
||||
* Does ".htconfig.php" exist? If not, edit htconfig.php and change the system settings. Rename to .htconfig.php
|
||||
|
@ -142,3 +144,11 @@ The addon tree has to be updated separately like so:
|
|||
|
||||
cd mywebsite/addon
|
||||
git pull
|
||||
|
||||
###Set up a backup plan
|
||||
Bad things will happen.
|
||||
Let there be a hardware failure, a corrupted database or whatever you can think of.
|
||||
So once the installation of your Friendica node is done, you should make yoursef a backup plan.
|
||||
|
||||
The most important file is the `.htconfig.php` file in the base directory.
|
||||
As it stores all your data, you should also have a recent dump of your Friendica database at hand, should you have to recover your node.
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
Table locks
|
||||
===========
|
||||
|
||||
| Field | Description | Type | Null | Key | Default | Extra |
|
||||
|---------|------------------|--------------|------|-----|---------------------|----------------|
|
||||
| id | sequential ID | int(11) | NO | PRI | NULL | auto_increment |
|
||||
| name | | varchar(128) | NO | | | |
|
||||
| locked | | tinyint(1) | NO | | 0 | |
|
||||
| created | | datetime | YES | | 0001-01-01 00:00:00 | |
|
||||
| Field | Description | Type | Null | Key | Default | Extra |
|
||||
|---------|------------------|------------------|------|-----|---------------------|----------------|
|
||||
| id | sequential ID | int(11) | NO | PRI | NULL | auto_increment |
|
||||
| name | | varchar(128) | NO | | | |
|
||||
| locked | | tinyint(1) | NO | | 0 | |
|
||||
| pid | Process ID | int(10) unsigned | NO | | 0 | |
|
||||
|
||||
Return to [database documentation](help/database)
|
||||
|
|
|
@ -9,5 +9,6 @@ Table workerqueue
|
|||
| created | | datetime | NO | MUL | 0001-01-01 00:00:00 | |
|
||||
| pid | | int(11) | NO | | 0 | |
|
||||
| executed | | datetime | NO | | 0001-01-01 00:00:00 | |
|
||||
| done | set to 1 if done | tinyint(1) | NO | | 0 | |
|
||||
|
||||
Return to [database documentation](help/database)
|
||||
|
|
|
@ -95,9 +95,11 @@ Ein ['Tipp für neue Mitglieder'](newmember)-Link zeigt sich in den ersten beide
|
|||
|
||||
**Persönliche Daten exportieren**
|
||||
|
||||
Du kannst eine Kopie Deiner persönlichen Daten in einer XML-Datei exportieren.
|
||||
Du kannst eine Kopie Deiner persönlichen Daten in einer JSON-Datei exportieren.
|
||||
Gehe hierzu in Deinen Einstellungen auf "Persönliche Daten exportieren".
|
||||
|
||||
Dies ist z.B. dann nützlich wenn du mit deinem Account auf einen anderen Friendica Knoten umziehen möchstest.
|
||||
Ein Grund hierfür könnte sein, dass der Server auf dem dieser Friendica Knoten läuft dauerhaft wegen eines Hardware Problems ausfällt.
|
||||
|
||||
**Schau Dir ebenfalls folgende Seiten an**
|
||||
|
||||
|
|
|
@ -108,3 +108,11 @@ Du kannst auch weitere Addons/Plugins ergänzen. Ändere den Eintrag folgenderma
|
|||
`$a->config['system']['addon'] = 'js_upload,poormancron';`
|
||||
|
||||
und speichere deine Änderungen.
|
||||
|
||||
###Erstelle einen Backup Plan
|
||||
Es werden schlimme Dinge geschehen.
|
||||
Sei es nun ein Hardwareversage oder eine korrumpierte Datenbank.
|
||||
Deshalb solltest du dir nachdem die Installation deines Friendica Knotens abgeschlossen ist einen Backup Plan erstellen.
|
||||
|
||||
Die wichtigste Datei ist die `.htconfig.php` im Stammverzeichnis deiner Friendica Installation.
|
||||
Und da alle Daten in der Datenbank gespeichert werden, solltest du einen nicht all zu alten Dump der Friendica Datenbank zur Hand haben, solltest du deinen Knoten wieder herstellen müssen.
|
||||
|
|
|
@ -35,8 +35,8 @@ Example: To set the directory value please add this line to your .htconfig.php:
|
|||
* **db_loglimit_index_high** - Number of index rows to be logged anyway (for any index)
|
||||
* **db_log_index_blacklist** - Blacklist of indexes that shouldn't be watched
|
||||
* **dbclean** (Boolean) - Enable the automatic database cleanup process
|
||||
* **dbclean-expire-days** (Integer) - Days after which remote items will be deleted. Own items, and marked or filed items are kept.
|
||||
* **default_service_class** -
|
||||
* **delivery_batch_count** - Number of deliveries per process. Default value is 1. (Disabled when using the worker)
|
||||
* **diaspora_test** (Boolean) - For development only. Disables the message transfer.
|
||||
* **directory** - The path to global directory. If not set then "http://dir.friendica.social" is used.
|
||||
* **disable_email_validation** (Boolean) - Disables the check if a mail address is in a valid format and can be resolved via DNS.
|
||||
|
@ -67,6 +67,8 @@ Example: To set the directory value please add this line to your .htconfig.php:
|
|||
* **ostatus_poll_timeframe** - Defines how old an item can be to try to complete the conversation with it.
|
||||
* **paranoia** (Boolean) - Log out users if their IP address changed.
|
||||
* **permit_crawling** (Boolean) - Restricts the search for not logged in users to one search per minute.
|
||||
* **worker_debug** (Boolean) - If enabled, it prints out the number of running processes split by priority.
|
||||
* **worker_fetch_limit** - Number of worker tasks that are fetched in a single query. Default is 5.
|
||||
* **profiler** (Boolean) - Enable internal timings to help optimize code. Needed for "rendertime" addon. Default is false.
|
||||
* **free_crawls** - Number of "free" searches when "permit_crawling" is activated (Default value is 10)
|
||||
* **crawl_permit_period** - Period in seconds between allowed searches when the number of free searches is reached and "permit_crawling" is activated (Default value is 60)
|
||||
|
@ -116,3 +118,10 @@ If more then one account should be able to access the admin panel, seperate the
|
|||
If you want to have a more personalized closing line for the notification emails you can set a variable for the admin_name.
|
||||
|
||||
$a->config['admin_name'] = "Marvin";
|
||||
|
||||
## Database Settings
|
||||
|
||||
The configuration variables db_host, db_user, db_pass and db_data are holding your credentials for the database connection.
|
||||
If you need to specify a port to access the database, you can do so by appending ":portnumber" to the db_host variable.
|
||||
|
||||
$db_host = 'your.mysqlhost.com:123456';
|
||||
|
|
|
@ -262,33 +262,33 @@ function get_contact_details_by_url($url, $uid = -1, $default = array()) {
|
|||
$profile = $default;
|
||||
}
|
||||
|
||||
if (($profile["photo"] == "") AND isset($default["photo"])) {
|
||||
if (($profile["photo"] == "") && isset($default["photo"])) {
|
||||
$profile["photo"] = $default["photo"];
|
||||
}
|
||||
|
||||
if (($profile["name"] == "") AND isset($default["name"])) {
|
||||
if (($profile["name"] == "") && isset($default["name"])) {
|
||||
$profile["name"] = $default["name"];
|
||||
}
|
||||
|
||||
if (($profile["network"] == "") AND isset($default["network"])) {
|
||||
if (($profile["network"] == "") && isset($default["network"])) {
|
||||
$profile["network"] = $default["network"];
|
||||
}
|
||||
|
||||
if (($profile["thumb"] == "") AND isset($profile["photo"])) {
|
||||
if (($profile["thumb"] == "") && isset($profile["photo"])) {
|
||||
$profile["thumb"] = $profile["photo"];
|
||||
}
|
||||
|
||||
if (($profile["micro"] == "") AND isset($profile["thumb"])) {
|
||||
if (($profile["micro"] == "") && isset($profile["thumb"])) {
|
||||
$profile["micro"] = $profile["thumb"];
|
||||
}
|
||||
|
||||
if ((($profile["addr"] == "") OR ($profile["name"] == "")) AND ($profile["gid"] != 0) AND
|
||||
if ((($profile["addr"] == "") || ($profile["name"] == "")) && ($profile["gid"] != 0) &&
|
||||
in_array($profile["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) {
|
||||
proc_run(PRIORITY_LOW, "include/update_gcontact.php", $profile["gid"]);
|
||||
}
|
||||
|
||||
// Show contact details of Diaspora contacts only if connected
|
||||
if (($profile["cid"] == 0) AND ($profile["network"] == NETWORK_DIASPORA)) {
|
||||
if (($profile["cid"] == 0) && ($profile["network"] == NETWORK_DIASPORA)) {
|
||||
$profile["location"] = "";
|
||||
$profile["about"] = "";
|
||||
$profile["gender"] = "";
|
||||
|
@ -517,7 +517,7 @@ function contacts_not_grouped($uid,$start = 0,$count = 0) {
|
|||
* @return integer Contact ID
|
||||
*/
|
||||
function get_contact($url, $uid = 0, $no_update = false) {
|
||||
logger("Get contact data for url ".$url." and user ".$uid." - ".App::callstack(), LOGGER_DEBUG);;
|
||||
logger("Get contact data for url ".$url." and user ".$uid." - ".App::callstack(), LOGGER_DEBUG);
|
||||
|
||||
$data = array();
|
||||
$contact_id = 0;
|
||||
|
@ -527,39 +527,28 @@ function get_contact($url, $uid = 0, $no_update = false) {
|
|||
}
|
||||
|
||||
// We first try the nurl (http://server.tld/nick), most common case
|
||||
$contacts = q("SELECT `id`, `avatar-date` FROM `contact`
|
||||
WHERE `nurl` = '%s'
|
||||
AND `uid` = %d",
|
||||
dbesc(normalise_link($url)),
|
||||
intval($uid));
|
||||
|
||||
$contact = dba::select('contact', array('id', 'avatar-date'), array('nurl' => normalise_link($url), 'uid' => $uid), array('limit' => 1));
|
||||
|
||||
// Then the addr (nick@server.tld)
|
||||
if (! dbm::is_result($contacts)) {
|
||||
$contacts = q("SELECT `id`, `avatar-date` FROM `contact`
|
||||
WHERE `addr` = '%s'
|
||||
AND `uid` = %d",
|
||||
dbesc($url),
|
||||
intval($uid));
|
||||
if (!dbm::is_result($contact)) {
|
||||
$contact = dba::select('contact', array('id', 'avatar-date'), array('addr' => $url, 'uid' => $uid), array('limit' => 1));
|
||||
}
|
||||
|
||||
// Then the alias (which could be anything)
|
||||
if (! dbm::is_result($contacts)) {
|
||||
$contacts = q("SELECT `id`, `avatar-date` FROM `contact`
|
||||
WHERE `alias` IN ('%s', '%s')
|
||||
AND `uid` = %d",
|
||||
dbesc($url),
|
||||
dbesc(normalise_link($url)),
|
||||
intval($uid));
|
||||
if (!dbm::is_result($contact)) {
|
||||
$r = dba::p("SELECT `id`, `avatar-date` FROM `contact` WHERE `alias` IN (?, ?) AND `uid` = ? LIMIT 1",
|
||||
$url, normalise_link($url), $uid);
|
||||
$contact = dba::fetch($r);
|
||||
dba::close($r);
|
||||
}
|
||||
|
||||
if (dbm::is_result($contacts)) {
|
||||
$contact_id = $contacts[0]["id"];
|
||||
if (dbm::is_result($contact)) {
|
||||
$contact_id = $contact["id"];
|
||||
|
||||
// Update the contact every 7 days
|
||||
$update_photo = ($contacts[0]['avatar-date'] < datetime_convert('','','now -7 days'));
|
||||
$update_contact = ($contact['avatar-date'] < datetime_convert('','','now -7 days'));
|
||||
|
||||
if (!$update_photo OR $no_update) {
|
||||
if (!$update_contact || $no_update) {
|
||||
return $contact_id;
|
||||
}
|
||||
} elseif ($uid != 0) {
|
||||
|
@ -576,45 +565,29 @@ function get_contact($url, $uid = 0, $no_update = false) {
|
|||
}
|
||||
|
||||
// Get data from the gcontact table
|
||||
$gcontacts = q("SELECT `name`, `nick`, `url`, `photo`, `addr`, `alias`, `network` FROM `gcontact` WHERE `nurl` = '%s'",
|
||||
dbesc(normalise_link($url)));
|
||||
if (!$gcontacts) {
|
||||
$gcontacts = dba::select('gcontact', array('name', 'nick', 'url', 'photo', 'addr', 'alias', 'network'),
|
||||
array('nurl' => normalise_link($url)), array('limit' => 1));
|
||||
if (!dbm::is_result($gcontacts)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$data = $gcontacts[0];
|
||||
$data = array_merge($data, $gcontacts);
|
||||
}
|
||||
|
||||
$url = $data["url"];
|
||||
|
||||
if (!$contact_id) {
|
||||
q("INSERT INTO `contact` (`uid`, `created`, `url`, `nurl`, `addr`, `alias`, `notify`, `poll`,
|
||||
`name`, `nick`, `photo`, `network`, `pubkey`, `rel`, `priority`,
|
||||
`batch`, `request`, `confirm`, `poco`, `name-date`, `uri-date`,
|
||||
`writable`, `blocked`, `readonly`, `pending`)
|
||||
VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', 1, 0, 0, 0)",
|
||||
intval($uid),
|
||||
dbesc(datetime_convert()),
|
||||
dbesc($data["url"]),
|
||||
dbesc(normalise_link($data["url"])),
|
||||
dbesc($data["addr"]),
|
||||
dbesc($data["alias"]),
|
||||
dbesc($data["notify"]),
|
||||
dbesc($data["poll"]),
|
||||
dbesc($data["name"]),
|
||||
dbesc($data["nick"]),
|
||||
dbesc($data["photo"]),
|
||||
dbesc($data["network"]),
|
||||
dbesc($data["pubkey"]),
|
||||
intval(CONTACT_IS_SHARING),
|
||||
intval($data["priority"]),
|
||||
dbesc($data["batch"]),
|
||||
dbesc($data["request"]),
|
||||
dbesc($data["confirm"]),
|
||||
dbesc($data["poco"]),
|
||||
dbesc(datetime_convert()),
|
||||
dbesc(datetime_convert())
|
||||
);
|
||||
dba::insert('contact', array('uid' => $uid, 'created' => datetime_convert(), 'url' => $data["url"],
|
||||
'nurl' => normalise_link($data["url"]), 'addr' => $data["addr"],
|
||||
'alias' => $data["alias"], 'notify' => $data["notify"], 'poll' => $data["poll"],
|
||||
'name' => $data["name"], 'nick' => $data["nick"], 'photo' => $data["photo"],
|
||||
'keywords' => $data["keywords"], 'location' => $data["location"], 'about' => $data["about"],
|
||||
'network' => $data["network"], 'pubkey' => $data["pubkey"],
|
||||
'rel' => CONTACT_IS_SHARING, 'priority' => $data["priority"],
|
||||
'batch' => $data["batch"], 'request' => $data["request"],
|
||||
'confirm' => $data["confirm"], 'poco' => $data["poco"],
|
||||
'name-date' => datetime_convert(), 'uri-date' => datetime_convert(),
|
||||
'avatar-date' => datetime_convert(), 'writable' => 1, 'blocked' => 0,
|
||||
'readonly' => 0, 'pending' => 0));
|
||||
|
||||
$contacts = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d ORDER BY `id` LIMIT 2",
|
||||
dbesc(normalise_link($data["url"])),
|
||||
|
@ -626,49 +599,65 @@ function get_contact($url, $uid = 0, $no_update = false) {
|
|||
$contact_id = $contacts[0]["id"];
|
||||
|
||||
// Update the newly created contact from data in the gcontact table
|
||||
$gcontacts = q("SELECT `location`, `about`, `keywords`, `gender` FROM `gcontact` WHERE `nurl` = '%s'",
|
||||
dbesc(normalise_link($data["url"])));
|
||||
if (dbm::is_result($gcontacts)) {
|
||||
logger("Update contact " . $data["url"] . ' from gcontact');
|
||||
q("UPDATE `contact` SET `location` = '%s', `about` = '%s', `keywords` = '%s', `gender` = '%s' WHERE `id` = %d",
|
||||
dbesc($gcontacts[0]["location"]), dbesc($gcontacts[0]["about"]), dbesc($gcontacts[0]["keywords"]),
|
||||
dbesc($gcontacts[0]["gender"]), intval($contact_id));
|
||||
$gcontact = dba::select('gcontact', array('location', 'about', 'keywords', 'gender'),
|
||||
array('nurl' => normalise_link($data["url"])), array('limit' => 1));
|
||||
if (dbm::is_result($gcontact)) {
|
||||
// Only use the information when the probing hadn't fetched these values
|
||||
if ($data['keywords'] != '') {
|
||||
unset($gcontact['keywords']);
|
||||
}
|
||||
if ($data['location'] != '') {
|
||||
unset($gcontact['location']);
|
||||
}
|
||||
if ($data['about'] != '') {
|
||||
unset($gcontact['about']);
|
||||
}
|
||||
dba::update('contact', $gcontact, array('id' => $contact_id));
|
||||
}
|
||||
}
|
||||
|
||||
if (count($contacts) > 1 AND $uid == 0 AND $contact_id != 0 AND $url != "") {
|
||||
q("DELETE FROM `contact` WHERE `nurl` = '%s' AND `id` != %d AND NOT `self`",
|
||||
dbesc(normalise_link($url)),
|
||||
intval($contact_id));
|
||||
if (count($contacts) > 1 && $uid == 0 && $contact_id != 0 && $data["url"] != "") {
|
||||
dba::e("DELETE FROM `contact` WHERE `nurl` = ? AND `uid` = 0 AND `id` != ? AND NOT `self`",
|
||||
normalise_link($data["url"]), $contact_id);
|
||||
}
|
||||
}
|
||||
|
||||
require_once "Photo.php";
|
||||
|
||||
update_contact_avatar($data["photo"], $uid, $contact_id);
|
||||
|
||||
$contacts = q("SELECT `addr`, `alias`, `name`, `nick` FROM `contact` WHERE `id` = %d", intval($contact_id));
|
||||
$contact = dba::select('contact', array('addr', 'alias', 'name', 'nick', 'keywords', 'location', 'about', 'avatar-date'),
|
||||
array('id' => $contact_id), array('limit' => 1));
|
||||
|
||||
// This condition should always be true
|
||||
if (!dbm::is_result($contacts)) {
|
||||
if (!dbm::is_result($contact)) {
|
||||
return $contact_id;
|
||||
}
|
||||
|
||||
// Only update if there had something been changed
|
||||
if ($data["addr"] != $contacts[0]["addr"] OR
|
||||
$data["alias"] != $contacts[0]["alias"] OR
|
||||
$data["name"] != $contacts[0]["name"] OR
|
||||
$data["nick"] != $contacts[0]["nick"]) {
|
||||
q("UPDATE `contact` SET `addr` = '%s', `alias` = '%s', `name` = '%s', `nick` = '%s',
|
||||
`name-date` = '%s', `uri-date` = '%s' WHERE `id` = %d",
|
||||
dbesc($data["addr"]),
|
||||
dbesc($data["alias"]),
|
||||
dbesc($data["name"]),
|
||||
dbesc($data["nick"]),
|
||||
dbesc(datetime_convert()),
|
||||
dbesc(datetime_convert()),
|
||||
intval($contact_id)
|
||||
);
|
||||
$updated = array('addr' => $data['addr'],
|
||||
'alias' => $data['alias'],
|
||||
'name' => $data['name'],
|
||||
'nick' => $data['nick']);
|
||||
|
||||
if ($data['keywords'] != '') {
|
||||
$updated['keywords'] = $data['keywords'];
|
||||
}
|
||||
if ($data['location'] != '') {
|
||||
$updated['location'] = $data['location'];
|
||||
}
|
||||
if ($data['about'] != '') {
|
||||
$updated['about'] = $data['about'];
|
||||
}
|
||||
|
||||
if (($data["addr"] != $contact["addr"]) || ($data["alias"] != $contact["alias"])) {
|
||||
$updated['uri-date'] = datetime_convert();
|
||||
}
|
||||
if (($data["name"] != $contact["name"]) || ($data["nick"] != $contact["nick"])) {
|
||||
$updated['name-date'] = datetime_convert();
|
||||
}
|
||||
|
||||
$updated['avatar-date'] = datetime_convert();
|
||||
|
||||
dba::update('contact', $updated, array('id' => $contact_id), $contact);
|
||||
|
||||
return $contact_id;
|
||||
}
|
||||
|
@ -769,7 +758,7 @@ function formatted_location($profile) {
|
|||
if($profile['locality'])
|
||||
$location .= $profile['locality'];
|
||||
|
||||
if($profile['region'] AND ($profile['locality'] != $profile['region'])) {
|
||||
if($profile['region'] && ($profile['locality'] != $profile['region'])) {
|
||||
if($location)
|
||||
$location .= ', ';
|
||||
|
||||
|
|
|
@ -512,7 +512,7 @@ class NotificationsManager {
|
|||
$myurl = substr($myurl,strpos($myurl,'://')+3);
|
||||
$myurl = str_replace(array('www.','.'),array('','\\.'),$myurl);
|
||||
$diasp_url = str_replace('/profile/','/u/',$myurl);
|
||||
$sql_extra = sprintf(" AND ( `item`.`author-link` regexp '%s' or `item`.`tag` regexp '%s' or `item`.`tag` regexp '%s' ) ",
|
||||
$sql_extra = sprintf(" AND ( `item`.`author-link` regexp '%s' OR `item`.`tag` regexp '%s' OR `item`.`tag` regexp '%s' ) ",
|
||||
dbesc($myurl . '$'),
|
||||
dbesc($myurl . '\\]'),
|
||||
dbesc($diasp_url . '\\]')
|
||||
|
|
|
@ -785,7 +785,7 @@ function update_contact_avatar($avatar, $uid, $cid, $force = false) {
|
|||
$data = array($r[0]["photo"], $r[0]["thumb"], $r[0]["micro"]);
|
||||
}
|
||||
|
||||
if (($r[0]["avatar"] != $avatar) OR $force) {
|
||||
if (($r[0]["avatar"] != $avatar) || $force) {
|
||||
$photos = import_profile_photo($avatar, $uid, $cid, true);
|
||||
|
||||
if ($photos) {
|
||||
|
@ -825,7 +825,7 @@ function import_profile_photo($photo, $uid, $cid, $quit_on_error = false) {
|
|||
$filename = basename($photo);
|
||||
$img_str = fetch_url($photo, true);
|
||||
|
||||
if ($quit_on_error AND ($img_str == "")) {
|
||||
if ($quit_on_error && ($img_str == "")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -883,7 +883,7 @@ function import_profile_photo($photo, $uid, $cid, $quit_on_error = false) {
|
|||
$photo_failure = true;
|
||||
}
|
||||
|
||||
if ($photo_failure AND $quit_on_error) {
|
||||
if ($photo_failure && $quit_on_error) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -902,7 +902,7 @@ function get_photo_info($url) {
|
|||
|
||||
$data = Cache::get($url);
|
||||
|
||||
if (is_null($data) OR !$data OR !is_array($data)) {
|
||||
if (is_null($data) || !$data || !is_array($data)) {
|
||||
$img_str = fetch_url($url, true, $redirects, 4);
|
||||
$filesize = strlen($img_str);
|
||||
|
||||
|
@ -996,7 +996,7 @@ function store_photo(App $a, $uid, $imagedata = "", $url = "") {
|
|||
/// $default_cid = $r[0]['id'];
|
||||
/// $community_page = (($r[0]['page-flags'] == PAGE_COMMUNITY) ? true : false);
|
||||
|
||||
if ((strlen($imagedata) == 0) AND ($url == "")) {
|
||||
if ((strlen($imagedata) == 0) && ($url == "")) {
|
||||
logger("No image data and no url provided", LOGGER_DEBUG);
|
||||
return(array());
|
||||
} elseif (strlen($imagedata) == 0) {
|
||||
|
@ -1102,7 +1102,7 @@ function store_photo(App $a, $uid, $imagedata = "", $url = "") {
|
|||
}
|
||||
}
|
||||
|
||||
if ($width > 160 AND $height > 160) {
|
||||
if ($width > 160 && $height > 160) {
|
||||
$x = 0;
|
||||
$y = 0;
|
||||
|
||||
|
|
|
@ -209,7 +209,7 @@ function contact_select($selname, $selclass, $preselected = false, $size = 4, $p
|
|||
|
||||
$tabindex = ($tabindex > 0 ? "tabindex=\"$tabindex\"" : "");
|
||||
|
||||
if ($privmail AND $preselected) {
|
||||
if ($privmail && $preselected) {
|
||||
$sql_extra .= " AND `id` IN (".implode(",", $preselected).")";
|
||||
$hidepreselected = ' style="display: none;"';
|
||||
} else {
|
||||
|
@ -261,7 +261,7 @@ function contact_select($selname, $selclass, $preselected = false, $size = 4, $p
|
|||
|
||||
$o .= "</select>\r\n";
|
||||
|
||||
if ($privmail AND $preselected) {
|
||||
if ($privmail && $preselected) {
|
||||
$o .= implode(", ", $receiverlist);
|
||||
}
|
||||
|
||||
|
@ -388,6 +388,9 @@ function populate_acl($user = null, $show_jotnets = false) {
|
|||
}
|
||||
|
||||
function construct_acl_data(App $a, $user) {
|
||||
// This function is now deactivated. It seems as if the generated data isn't used anywhere.
|
||||
/// @todo Remove this function and all function calls before releasing Friendica 3.5.3
|
||||
return;
|
||||
|
||||
// Get group and contact information for html ACL selector
|
||||
$acl_data = acl_lookup($a, 'html');
|
||||
|
|
|
@ -483,7 +483,7 @@ $called_api = null;
|
|||
logger("api_get_user: Fetching user data for user ".$contact_id, LOGGER_DEBUG);
|
||||
|
||||
// Searching for contact URL
|
||||
if (!is_null($contact_id) AND (intval($contact_id) == 0)) {
|
||||
if (!is_null($contact_id) && (intval($contact_id) == 0)) {
|
||||
$user = dbesc(normalise_link($contact_id));
|
||||
$url = $user;
|
||||
$extra_query = "AND `contact`.`nurl` = '%s' ";
|
||||
|
@ -493,7 +493,7 @@ $called_api = null;
|
|||
}
|
||||
|
||||
// Searching for contact id with uid = 0
|
||||
if (!is_null($contact_id) AND (intval($contact_id) != 0)) {
|
||||
if (!is_null($contact_id) && (intval($contact_id) != 0)) {
|
||||
$user = dbesc(api_unique_id_to_url($contact_id));
|
||||
|
||||
if ($user == "") {
|
||||
|
@ -538,7 +538,7 @@ $called_api = null;
|
|||
}
|
||||
}
|
||||
|
||||
if (is_null($user) AND ($a->argc > (count($called_api) - 1)) AND (count($called_api) > 0)) {
|
||||
if (is_null($user) && ($a->argc > (count($called_api) - 1)) && (count($called_api) > 0)) {
|
||||
$argid = count($called_api);
|
||||
list($user, $null) = explode(".", $a->argv[$argid]);
|
||||
if (is_numeric($user)) {
|
||||
|
@ -600,7 +600,7 @@ $called_api = null;
|
|||
$network_name = network_to_name($r[0]['network'], $r[0]['url']);
|
||||
|
||||
// If no nick where given, extract it from the address
|
||||
if (($r[0]['nick'] == "") OR ($r[0]['name'] == $r[0]['nick'])) {
|
||||
if (($r[0]['nick'] == "") || ($r[0]['name'] == $r[0]['nick'])) {
|
||||
$r[0]['nick'] = api_get_nick($r[0]["url"]);
|
||||
}
|
||||
|
||||
|
@ -716,7 +716,7 @@ $called_api = null;
|
|||
$starred = 0;
|
||||
|
||||
// Add a nick if it isn't present there
|
||||
if (($uinfo[0]['nick'] == "") OR ($uinfo[0]['name'] == $uinfo[0]['nick'])) {
|
||||
if (($uinfo[0]['nick'] == "") || ($uinfo[0]['name'] == $uinfo[0]['nick'])) {
|
||||
$uinfo[0]['nick'] = api_get_nick($uinfo[0]["url"]);
|
||||
}
|
||||
|
||||
|
@ -749,7 +749,7 @@ $called_api = null;
|
|||
'contributors_enabled' => false,
|
||||
'is_translator' => false,
|
||||
'is_translation_enabled' => false,
|
||||
'following' => (($uinfo[0]['rel'] == CONTACT_IS_FOLLOWER) OR ($uinfo[0]['rel'] == CONTACT_IS_FRIEND)),
|
||||
'following' => (($uinfo[0]['rel'] == CONTACT_IS_FOLLOWER) || ($uinfo[0]['rel'] == CONTACT_IS_FRIEND)),
|
||||
'follow_request_sent' => false,
|
||||
'statusnet_blocking' => false,
|
||||
'notifications' => false,
|
||||
|
@ -777,10 +777,10 @@ $called_api = null;
|
|||
|
||||
$status_user = api_get_user($a, $item["author-link"]);
|
||||
|
||||
$status_user["protected"] = (($item["allow_cid"] != "") OR
|
||||
($item["allow_gid"] != "") OR
|
||||
($item["deny_cid"] != "") OR
|
||||
($item["deny_gid"] != "") OR
|
||||
$status_user["protected"] = (($item["allow_cid"] != "") ||
|
||||
($item["allow_gid"] != "") ||
|
||||
($item["deny_cid"] != "") ||
|
||||
($item["deny_gid"] != "") ||
|
||||
$item["private"]);
|
||||
|
||||
if ($item['thr-parent'] == $item['uri']) {
|
||||
|
@ -1305,9 +1305,9 @@ $called_api = null;
|
|||
$status_info["entities"] = $converted["entities"];
|
||||
}
|
||||
|
||||
if (($lastwall['item_network'] != "") AND ($status["source"] == 'web')) {
|
||||
if (($lastwall['item_network'] != "") && ($status["source"] == 'web')) {
|
||||
$status_info["source"] = network_to_name($lastwall['item_network'], $user_info['url']);
|
||||
} elseif (($lastwall['item_network'] != "") AND (network_to_name($lastwall['item_network'], $user_info['url']) != $status_info["source"])) {
|
||||
} elseif (($lastwall['item_network'] != "") && (network_to_name($lastwall['item_network'], $user_info['url']) != $status_info["source"])) {
|
||||
$status_info["source"] = trim($status_info["source"].' ('.network_to_name($lastwall['item_network'], $user_info['url']).')');
|
||||
}
|
||||
|
||||
|
@ -1393,11 +1393,11 @@ $called_api = null;
|
|||
$user_info["status"]["entities"] = $converted["entities"];
|
||||
}
|
||||
|
||||
if (($lastwall['item_network'] != "") AND ($user_info["status"]["source"] == 'web')) {
|
||||
if (($lastwall['item_network'] != "") && ($user_info["status"]["source"] == 'web')) {
|
||||
$user_info["status"]["source"] = network_to_name($lastwall['item_network'], $user_info['url']);
|
||||
}
|
||||
|
||||
if (($lastwall['item_network'] != "") AND (network_to_name($lastwall['item_network'], $user_info['url']) != $user_info["status"]["source"])) {
|
||||
if (($lastwall['item_network'] != "") && (network_to_name($lastwall['item_network'], $user_info['url']) != $user_info["status"]["source"])) {
|
||||
$user_info["status"]["source"] = trim($user_info["status"]["source"] . ' (' . network_to_name($lastwall['item_network'], $user_info['url']) . ')');
|
||||
}
|
||||
|
||||
|
@ -2178,7 +2178,7 @@ $called_api = null;
|
|||
`contact`.`id` AS `cid`
|
||||
FROM `item`, `contact`
|
||||
WHERE `item`.`uid` = %d
|
||||
AND `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0
|
||||
AND `item`.`visible` = 1 AND `item`.`moderated` = 0 AND `item`.`deleted` = 0
|
||||
AND `item`.`starred` = 1
|
||||
AND `contact`.`id` = `item`.`contact-id`
|
||||
AND (NOT `contact`.`blocked` OR `contact`.`pending`)
|
||||
|
@ -2263,13 +2263,13 @@ $called_api = null;
|
|||
|
||||
$statustitle = trim($item['title']);
|
||||
|
||||
if (($statustitle != '') and (strpos($statusbody, $statustitle) !== false)) {
|
||||
if (($statustitle != '') && (strpos($statusbody, $statustitle) !== false)) {
|
||||
$statustext = trim($statusbody);
|
||||
} else {
|
||||
$statustext = trim($statustitle."\n\n".$statusbody);
|
||||
}
|
||||
|
||||
if (($item["network"] == NETWORK_FEED) and (strlen($statustext)> 1000)) {
|
||||
if (($item["network"] == NETWORK_FEED) && (strlen($statustext)> 1000)) {
|
||||
$statustext = substr($statustext, 0, 1000)."... \n".$item["plink"];
|
||||
}
|
||||
|
||||
|
@ -2402,8 +2402,8 @@ $called_api = null;
|
|||
$offset = 0;
|
||||
//foreach ($urls[1] AS $id=>$url) {
|
||||
foreach ($ordered_urls AS $url) {
|
||||
if ((substr($url["title"], 0, 7) != "http://") AND (substr($url["title"], 0, 8) != "https://") AND
|
||||
!strpos($url["title"], "http://") AND !strpos($url["title"], "https://"))
|
||||
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 {
|
||||
$display_url = str_replace(array("http://www.", "https://www."), array("", ""), $url["url"]);
|
||||
|
@ -2455,7 +2455,7 @@ $called_api = null;
|
|||
$scale = scale_image($image[0], $image[1], 150);
|
||||
$sizes["thumb"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit");
|
||||
|
||||
if (($image[0] > 150) OR ($image[1] > 150)) {
|
||||
if (($image[0] > 150) || ($image[1] > 150)) {
|
||||
$scale = scale_image($image[0], $image[1], 340);
|
||||
$sizes["small"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit");
|
||||
}
|
||||
|
@ -2463,7 +2463,7 @@ $called_api = null;
|
|||
$scale = scale_image($image[0], $image[1], 600);
|
||||
$sizes["medium"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit");
|
||||
|
||||
if (($image[0] > 600) OR ($image[1] > 600)) {
|
||||
if (($image[0] > 600) || ($image[1] > 600)) {
|
||||
$scale = scale_image($image[0], $image[1], 1024);
|
||||
$sizes["large"] = array("w" => $scale["width"], "h" => $scale["height"], "resize" => "fit");
|
||||
}
|
||||
|
@ -2668,7 +2668,7 @@ $called_api = null;
|
|||
list($status_user, $owner_user) = api_item_get_user($a, $item);
|
||||
|
||||
// Look if the posts are matching if they should be filtered by user id
|
||||
if ($filter_user AND ($status_user["id"] != $user_info["id"])) {
|
||||
if ($filter_user && ($status_user["id"] != $user_info["id"])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -2712,9 +2712,9 @@ $called_api = null;
|
|||
$status["entities"] = $converted["entities"];
|
||||
}
|
||||
|
||||
if (($item['item_network'] != "") AND ($status["source"] == 'web')) {
|
||||
if (($item['item_network'] != "") && ($status["source"] == 'web')) {
|
||||
$status["source"] = network_to_name($item['item_network'], $user_info['url']);
|
||||
} elseif (($item['item_network'] != "") AND (network_to_name($item['item_network'], $user_info['url']) != $status["source"])) {
|
||||
} elseif (($item['item_network'] != "") && (network_to_name($item['item_network'], $user_info['url']) != $status["source"])) {
|
||||
$status["source"] = trim($status["source"].' ('.network_to_name($item['item_network'], $user_info['url']).')');
|
||||
}
|
||||
|
||||
|
@ -2723,7 +2723,7 @@ $called_api = null;
|
|||
// It doesn't work reliable with the link if its a feed
|
||||
//$IsRetweet = ($item['owner-link'] != $item['author-link']);
|
||||
//if ($IsRetweet)
|
||||
// $IsRetweet = (($item['owner-name'] != $item['author-name']) OR ($item['owner-avatar'] != $item['author-avatar']));
|
||||
// $IsRetweet = (($item['owner-name'] != $item['author-name']) || ($item['owner-avatar'] != $item['author-avatar']));
|
||||
|
||||
|
||||
if ($item["id"] == $item["parent"]) {
|
||||
|
@ -3022,7 +3022,7 @@ $called_api = null;
|
|||
|
||||
if (api_user() === false) throw new ForbiddenException();
|
||||
|
||||
if (!x($_POST, "text") OR (!x($_POST,"screen_name") AND !x($_POST,"user_id"))) return;
|
||||
if (!x($_POST, "text") || (!x($_POST,"screen_name") && !x($_POST,"user_id"))) return;
|
||||
|
||||
$sender = api_get_user($a);
|
||||
|
||||
|
@ -3982,7 +3982,7 @@ $called_api = null;
|
|||
}
|
||||
|
||||
function prepare_photo_data($type, $scale, $photo_id) {
|
||||
$scale_sql = ($scale === false ? "" : sprintf("and scale=%d", intval($scale)));
|
||||
$scale_sql = ($scale === false ? "" : sprintf("AND scale=%d", intval($scale)));
|
||||
$data_sql = ($scale === false ? "" : "data, ");
|
||||
|
||||
// added allow_cid, allow_gid, deny_cid, deny_gid to output as string like stored in database
|
||||
|
@ -4334,7 +4334,7 @@ $called_api = null;
|
|||
$in_reply_to['user_id_str'] = NULL;
|
||||
$in_reply_to['screen_name'] = NULL;
|
||||
|
||||
if (($item['thr-parent'] != $item['uri']) AND (intval($item['parent']) != intval($item['id']))) {
|
||||
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",
|
||||
intval($item['uid']),
|
||||
dbesc($item['thr-parent']));
|
||||
|
@ -4415,7 +4415,7 @@ $called_api = null;
|
|||
if (isset($data["text"]))
|
||||
$body = $data["text"];
|
||||
|
||||
if (($body == "") AND (isset($data["title"])))
|
||||
if (($body == "") && (isset($data["title"])))
|
||||
$body = $data["title"];
|
||||
|
||||
if (isset($data["url"]))
|
||||
|
|
|
@ -29,7 +29,7 @@ if (isset($_COOKIE["Friendica"])) {
|
|||
new_cookie($authcookiedays*24*60*60, $r[0]);
|
||||
|
||||
// Do the authentification if not done by now
|
||||
if (!isset($_SESSION) OR !isset($_SESSION['authenticated'])) {
|
||||
if (!isset($_SESSION) || !isset($_SESSION['authenticated'])) {
|
||||
authenticate_success($r[0]);
|
||||
|
||||
if (get_config('system','paranoia'))
|
||||
|
|
|
@ -89,7 +89,7 @@ class exAuth {
|
|||
|
||||
// Open the logfile if the logfile name is defined
|
||||
if ($this->sLogFile != '')
|
||||
$this->rLogFile = fopen($this->sLogFile, "a") or die("Error opening log file: ". $this->sLogFile);
|
||||
$this->rLogFile = fopen($this->sLogFile, "a") || die("Error opening log file: ". $this->sLogFile);
|
||||
|
||||
$this->writeLog("[exAuth] start");
|
||||
|
||||
|
|
|
@ -188,7 +188,7 @@ function bb2diaspora($Text, $preserve_nl = false, $fordiaspora = true) {
|
|||
$Text = $converter->convert($Text);
|
||||
|
||||
// unmask the special chars back to HTML
|
||||
$Text = str_replace(array('&_lt_;', '&_gt_;', '&_amp_;'), array('<', '>', '&'), $Text);
|
||||
$Text = str_replace(array('&\_lt\_;', '&\_gt\_;', '&\_amp\_;'), array('<', '>', '&'), $Text);
|
||||
|
||||
$a->save_timestamp($stamp1, "parser");
|
||||
|
||||
|
|
|
@ -49,14 +49,14 @@ function bb_attachment($Text, $simplehtml = false, $tryoembed = true) {
|
|||
$data["title"] = str_replace(array("http://", "https://"), "", $data["title"]);
|
||||
}
|
||||
|
||||
if (((strpos($data["text"], "[img=") !== false) OR (strpos($data["text"], "[img]") !== false)) AND ($data["image"] != "")) {
|
||||
if (((strpos($data["text"], "[img=") !== false) || (strpos($data["text"], "[img]") !== false)) && ($data["image"] != "")) {
|
||||
$data["preview"] = $data["image"];
|
||||
$data["image"] = "";
|
||||
}
|
||||
|
||||
if ($simplehtml == 7) {
|
||||
$text = style_url_for_mastodon($data["url"]);
|
||||
} elseif (($simplehtml != 4) AND ($simplehtml != 0)) {
|
||||
} elseif (($simplehtml != 4) && ($simplehtml != 0)) {
|
||||
$text = sprintf('<a href="%s" target="_blank">%s</a><br>', $data["url"], $data["title"]);
|
||||
} else {
|
||||
$text = sprintf('<span class="type-%s">', $data["type"]);
|
||||
|
@ -71,13 +71,13 @@ function bb_attachment($Text, $simplehtml = false, $tryoembed = true) {
|
|||
if (strstr(strtolower($oembed), "<iframe ")) {
|
||||
$text = $oembed;
|
||||
} else {
|
||||
if (($data["image"] != "") AND !strstr(strtolower($oembed), "<img ")) {
|
||||
if (($data["image"] != "") && !strstr(strtolower($oembed), "<img ")) {
|
||||
$text .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-image" /></a><br />', $data["url"], proxy_url($data["image"]), $data["title"]);
|
||||
} elseif (($data["preview"] != "") AND !strstr(strtolower($oembed), "<img ")) {
|
||||
} elseif (($data["preview"] != "") && !strstr(strtolower($oembed), "<img ")) {
|
||||
$text .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-preview" /></a><br />', $data["url"], proxy_url($data["preview"]), $data["title"]);
|
||||
}
|
||||
|
||||
if (($data["type"] == "photo") AND ($data["url"] != "") AND ($data["image"] != "")) {
|
||||
if (($data["type"] == "photo") && ($data["url"] != "") && ($data["image"] != "")) {
|
||||
$text .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-image" /></a>', $data["url"], proxy_url($data["image"]), $data["title"]);
|
||||
} else {
|
||||
$text .= $oembed;
|
||||
|
@ -103,25 +103,25 @@ function bb_remove_share_information($Text, $plaintext = false, $nolink = false)
|
|||
|
||||
$title = htmlentities($data["title"], ENT_QUOTES, 'UTF-8', false);
|
||||
$text = htmlentities($data["text"], ENT_QUOTES, 'UTF-8', false);
|
||||
if ($plaintext OR (($title != "") AND strstr($text, $title))) {
|
||||
if ($plaintext || (($title != "") && strstr($text, $title))) {
|
||||
$data["title"] = $data["url"];
|
||||
} elseif (($text != "") AND strstr($title, $text)) {
|
||||
} elseif (($text != "") && strstr($title, $text)) {
|
||||
$data["text"] = $data["title"];
|
||||
$data["title"] = $data["url"];
|
||||
}
|
||||
|
||||
if (($data["text"] == "") AND ($data["title"] != "") AND ($data["url"] == "")) {
|
||||
if (($data["text"] == "") && ($data["title"] != "") && ($data["url"] == "")) {
|
||||
return $data["title"] . $data["after"];
|
||||
}
|
||||
|
||||
// If the link already is included in the post, don't add it again
|
||||
if (($data["url"] != "") AND strpos($data["text"], $data["url"])) {
|
||||
if (($data["url"] != "") && strpos($data["text"], $data["url"])) {
|
||||
return $data["text"] . $data["after"];
|
||||
}
|
||||
|
||||
$text = $data["text"];
|
||||
|
||||
if (($data["url"] != "") AND ($data["title"] != "")) {
|
||||
if (($data["url"] != "") && ($data["title"] != "")) {
|
||||
$text .= "\n[url=" . $data["url"] . "]" . $data["title"] . "[/url]";
|
||||
} elseif (($data["url"] != "")) {
|
||||
$text .= "\n" . $data["url"];
|
||||
|
@ -147,7 +147,7 @@ function cleancss($input) {
|
|||
for ($i = 0; $i < strlen($input); $i++) {
|
||||
$char = substr($input, $i, 1);
|
||||
|
||||
if (($char >= "a") and ($char <= "z")) {
|
||||
if (($char >= "a") && ($char <= "z")) {
|
||||
$cleaned .= $char;
|
||||
}
|
||||
|
||||
|
@ -167,7 +167,7 @@ function cleancss($input) {
|
|||
function bb_style_url($match) {
|
||||
$url = $match[1];
|
||||
|
||||
if (isset($match[2]) AND ($match[1] != $match[2])) {
|
||||
if (isset($match[2]) && ($match[1] != $match[2])) {
|
||||
return $match[0];
|
||||
}
|
||||
|
||||
|
@ -485,20 +485,20 @@ function bb_ShareAttributes($share, $simplehtml) {
|
|||
|
||||
$data = get_contact_details_by_url($profile);
|
||||
|
||||
if (isset($data["name"]) AND ($data["name"] != "") AND isset($data["addr"]) AND ($data["addr"] != ""))
|
||||
if (isset($data["name"]) && ($data["name"] != "") && isset($data["addr"]) && ($data["addr"] != ""))
|
||||
$userid_compact = $data["name"]." (".$data["addr"].")";
|
||||
else
|
||||
$userid_compact = GetProfileUsername($profile,$author, true);
|
||||
|
||||
if (isset($data["addr"]) AND ($data["addr"] != ""))
|
||||
if (isset($data["addr"]) && ($data["addr"] != ""))
|
||||
$userid = $data["addr"];
|
||||
else
|
||||
$userid = GetProfileUsername($profile,$author, false);
|
||||
|
||||
if (isset($data["name"]) AND ($data["name"] != ""))
|
||||
if (isset($data["name"]) && ($data["name"] != ""))
|
||||
$author = $data["name"];
|
||||
|
||||
if (isset($data["micro"]) AND ($data["micro"] != ""))
|
||||
if (isset($data["micro"]) && ($data["micro"] != ""))
|
||||
$avatar = $data["micro"];
|
||||
|
||||
$preshare = trim($share[1]);
|
||||
|
@ -744,7 +744,7 @@ function bb_RemovePictureLinks($match) {
|
|||
}
|
||||
|
||||
function bb_expand_links($match) {
|
||||
if (($match[3] == "") OR ($match[2] == $match[3]) OR stristr($match[2], $match[3])) {
|
||||
if (($match[3] == "") || ($match[2] == $match[3]) || stristr($match[2], $match[3])) {
|
||||
return ($match[1] . "[url]" . $match[2] . "[/url]");
|
||||
} else {
|
||||
return ($match[1] . $match[3] . " [url]" . $match[2] . "[/url]");
|
||||
|
@ -930,7 +930,7 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = fa
|
|||
$MAILSearchString = $URLSearchString;
|
||||
|
||||
// Remove all hashtag addresses
|
||||
if ((!$tryoembed OR $simplehtml) AND !in_array($simplehtml, array(3, 7))) {
|
||||
if ((!$tryoembed || $simplehtml) && !in_array($simplehtml, array(3, 7))) {
|
||||
$Text = preg_replace("/([#@])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$1$3', $Text);
|
||||
} elseif ($simplehtml == 3) {
|
||||
$Text = preg_replace("/([@])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",
|
||||
|
@ -1126,7 +1126,7 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = fa
|
|||
// Check for [spoiler] text
|
||||
// handle nested quotes
|
||||
$endlessloop = 0;
|
||||
while ((strpos($Text, "[/spoiler]") !== false) and (strpos($Text, "[spoiler]") !== false) and (++$endlessloop < 20)) {
|
||||
while ((strpos($Text, "[/spoiler]") !== false) && (strpos($Text, "[spoiler]") !== false) && (++$endlessloop < 20)) {
|
||||
$Text = preg_replace("/\[spoiler\](.*?)\[\/spoiler\]/ism", "$SpoilerLayout", $Text);
|
||||
}
|
||||
|
||||
|
@ -1136,7 +1136,7 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = fa
|
|||
|
||||
// handle nested quotes
|
||||
$endlessloop = 0;
|
||||
while ((strpos($Text, "[/spoiler]")!== false) and (strpos($Text, "[spoiler=") !== false) and (++$endlessloop < 20)) {
|
||||
while ((strpos($Text, "[/spoiler]")!== false) && (strpos($Text, "[spoiler=") !== false) && (++$endlessloop < 20)) {
|
||||
$Text = preg_replace("/\[spoiler=[\"\']*(.*?)[\"\']*\](.*?)\[\/spoiler\]/ism",
|
||||
"<br /><strong class=".'"spoiler"'.">" . $t_wrote . "</strong><blockquote class=".'"spoiler"'.">$2</blockquote>",
|
||||
$Text);
|
||||
|
@ -1148,7 +1148,7 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = fa
|
|||
// Check for [quote] text
|
||||
// handle nested quotes
|
||||
$endlessloop = 0;
|
||||
while ((strpos($Text, "[/quote]") !== false) and (strpos($Text, "[quote]") !== false) and (++$endlessloop < 20)) {
|
||||
while ((strpos($Text, "[/quote]") !== false) && (strpos($Text, "[quote]") !== false) && (++$endlessloop < 20)) {
|
||||
$Text = preg_replace("/\[quote\](.*?)\[\/quote\]/ism", "$QuoteLayout", $Text);
|
||||
}
|
||||
|
||||
|
@ -1158,7 +1158,7 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = fa
|
|||
|
||||
// handle nested quotes
|
||||
$endlessloop = 0;
|
||||
while ((strpos($Text, "[/quote]")!== false) and (strpos($Text, "[quote=") !== false) and (++$endlessloop < 20)) {
|
||||
while ((strpos($Text, "[/quote]")!== false) && (strpos($Text, "[quote=") !== false) && (++$endlessloop < 20)) {
|
||||
$Text = preg_replace("/\[quote=[\"\']*(.*?)[\"\']*\](.*?)\[\/quote\]/ism",
|
||||
"<br /><strong class=".'"author"'.">" . $t_wrote . "</strong><blockquote>$2</blockquote>",
|
||||
$Text);
|
||||
|
@ -1319,7 +1319,7 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = fa
|
|||
// Clean up the HTML by loading and saving the HTML with the DOM.
|
||||
// Bad structured html can break a whole page.
|
||||
// For performance reasons do it only with ativated item cache or at export.
|
||||
if (!$tryoembed OR (get_itemcachepath() != "")) {
|
||||
if (!$tryoembed || (get_itemcachepath() != "")) {
|
||||
$doc = new DOMDocument();
|
||||
$doc->preserveWhiteSpace = false;
|
||||
|
||||
|
|
|
@ -172,35 +172,35 @@ class Cache {
|
|||
set_config("system", "cache_cleared_day", time());
|
||||
}
|
||||
|
||||
if (($max_level <= CACHE_HOUR) AND (get_config("system", "cache_cleared_hour")) < time() - self::duration(CACHE_HOUR)) {
|
||||
if (($max_level <= CACHE_HOUR) && (get_config("system", "cache_cleared_hour")) < time() - self::duration(CACHE_HOUR)) {
|
||||
q("DELETE FROM `cache` WHERE `updated` < '%s' AND `expire_mode` = %d",
|
||||
dbesc(datetime_convert('UTC','UTC',"now - 1 hours")), intval(CACHE_HOUR));
|
||||
|
||||
set_config("system", "cache_cleared_hour", time());
|
||||
}
|
||||
|
||||
if (($max_level <= CACHE_HALF_HOUR) AND (get_config("system", "cache_cleared_half_hour")) < time() - self::duration(CACHE_HALF_HOUR)) {
|
||||
if (($max_level <= CACHE_HALF_HOUR) && (get_config("system", "cache_cleared_half_hour")) < time() - self::duration(CACHE_HALF_HOUR)) {
|
||||
q("DELETE FROM `cache` WHERE `updated` < '%s' AND `expire_mode` = %d",
|
||||
dbesc(datetime_convert('UTC','UTC',"now - 30 minutes")), intval(CACHE_HALF_HOUR));
|
||||
|
||||
set_config("system", "cache_cleared_half_hour", time());
|
||||
}
|
||||
|
||||
if (($max_level <= CACHE_QUARTER_HOUR) AND (get_config("system", "cache_cleared_quarter_hour")) < time() - self::duration(CACHE_QUARTER_HOUR)) {
|
||||
if (($max_level <= CACHE_QUARTER_HOUR) && (get_config("system", "cache_cleared_quarter_hour")) < time() - self::duration(CACHE_QUARTER_HOUR)) {
|
||||
q("DELETE FROM `cache` WHERE `updated` < '%s' AND `expire_mode` = %d",
|
||||
dbesc(datetime_convert('UTC','UTC',"now - 15 minutes")), intval(CACHE_QUARTER_HOUR));
|
||||
|
||||
set_config("system", "cache_cleared_quarter_hour", time());
|
||||
}
|
||||
|
||||
if (($max_level <= CACHE_FIVE_MINUTES) AND (get_config("system", "cache_cleared_five_minute")) < time() - self::duration(CACHE_FIVE_MINUTES)) {
|
||||
if (($max_level <= CACHE_FIVE_MINUTES) && (get_config("system", "cache_cleared_five_minute")) < time() - self::duration(CACHE_FIVE_MINUTES)) {
|
||||
q("DELETE FROM `cache` WHERE `updated` < '%s' AND `expire_mode` = %d",
|
||||
dbesc(datetime_convert('UTC','UTC',"now - 5 minutes")), intval(CACHE_FIVE_MINUTES));
|
||||
|
||||
set_config("system", "cache_cleared_five_minute", time());
|
||||
}
|
||||
|
||||
if (($max_level <= CACHE_MINUTE) AND (get_config("system", "cache_cleared_minute")) < time() - self::duration(CACHE_MINUTE)) {
|
||||
if (($max_level <= CACHE_MINUTE) && (get_config("system", "cache_cleared_minute")) < time() - self::duration(CACHE_MINUTE)) {
|
||||
q("DELETE FROM `cache` WHERE `updated` < '%s' AND `expire_mode` = %d",
|
||||
dbesc(datetime_convert('UTC','UTC',"now - 1 minutes")), intval(CACHE_MINUTE));
|
||||
|
||||
|
|
|
@ -100,7 +100,7 @@ function network_to_name($s, $profile = "") {
|
|||
|
||||
$networkname = str_replace($search, $replace, $s);
|
||||
|
||||
if ((in_array($s, array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) AND ($profile != "")) {
|
||||
if ((in_array($s, array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) && ($profile != "")) {
|
||||
$r = q("SELECT `gserver`.`platform` FROM `gcontact`
|
||||
INNER JOIN `gserver` ON `gserver`.`nurl` = `gcontact`.`server_url`
|
||||
WHERE `gcontact`.`nurl` = '%s' AND `platform` != ''",
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\Core\Config;
|
||||
|
||||
function follow_widget($value = "") {
|
||||
|
||||
|
@ -18,6 +19,7 @@ function findpeople_widget() {
|
|||
require_once 'include/Contact.php';
|
||||
|
||||
$a = get_app();
|
||||
$global_dir = Config::get('system', 'directory');
|
||||
|
||||
if (get_config('system', 'invitation_only')) {
|
||||
$x = get_pconfig(local_user(), 'system', 'invites_remaining');
|
||||
|
@ -37,7 +39,9 @@ function findpeople_widget() {
|
|||
'$suggest' => t('Friend Suggestions'),
|
||||
'$similar' => t('Similar Interests'),
|
||||
'$random' => t('Random Profile'),
|
||||
'$inv' => t('Invite Friends')
|
||||
'$inv' => t('Invite Friends'),
|
||||
'$directory' => t('View Global Directory'),
|
||||
'$global_dir' => $global_dir
|
||||
));
|
||||
|
||||
}
|
||||
|
@ -51,7 +55,7 @@ function unavailable_networks() {
|
|||
$networks[] = NETWORK_APPNET;
|
||||
}
|
||||
|
||||
if (!plugin_enabled("fbpost") AND !plugin_enabled("facebook")) {
|
||||
if (!plugin_enabled("fbpost") && !plugin_enabled("facebook")) {
|
||||
$networks[] = NETWORK_FACEBOOK;
|
||||
}
|
||||
|
||||
|
|
|
@ -712,7 +712,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
|
|||
$profile_link = zrl($profile_link);
|
||||
}
|
||||
|
||||
if (!x($item, 'author-thumb') OR ($item['author-thumb'] == "")) {
|
||||
if (!x($item, 'author-thumb') || ($item['author-thumb'] == "")) {
|
||||
$author_contact = get_contact_details_by_url($item['author-link'], $profile_owner);
|
||||
if ($author_contact["thumb"]) {
|
||||
$item['author-thumb'] = $author_contact["thumb"];
|
||||
|
@ -721,7 +721,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
|
|||
}
|
||||
}
|
||||
|
||||
if (!isset($item['owner-thumb']) OR ($item['owner-thumb'] == "")) {
|
||||
if (!isset($item['owner-thumb']) || ($item['owner-thumb'] == "")) {
|
||||
$owner_contact = get_contact_details_by_url($item['owner-link'], $profile_owner);
|
||||
if ($owner_contact["thumb"]) {
|
||||
$item['owner-thumb'] = $owner_contact["thumb"];
|
||||
|
@ -1013,7 +1013,7 @@ function item_photo_menu($item) {
|
|||
$menu[t("Poke")] = $poke_link;
|
||||
}
|
||||
|
||||
if ((($cid == 0) OR ($rel == CONTACT_IS_FOLLOWER)) AND
|
||||
if ((($cid == 0) || ($rel == CONTACT_IS_FOLLOWER)) &&
|
||||
in_array($item['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA))) {
|
||||
$menu[t('Connect/Follow')] = 'follow?url=' . urlencode($item['author-link']);
|
||||
}
|
||||
|
|
|
@ -82,6 +82,9 @@ function cron_run(&$argv, &$argc){
|
|||
proc_run(PRIORITY_MEDIUM, 'include/dbclean.php');
|
||||
|
||||
proc_run(PRIORITY_LOW, "include/cronjobs.php", "update_photo_albums");
|
||||
|
||||
// Delete all done workerqueue entries
|
||||
dba::e('DELETE FROM `workerqueue` WHERE `done` AND `executed` < UTC_TIMESTAMP() - INTERVAL 12 HOUR');
|
||||
}
|
||||
|
||||
// Poll contacts
|
||||
|
@ -186,7 +189,7 @@ function cron_poll_contacts($argc, $argv) {
|
|||
$contact['priority'] = 2;
|
||||
}
|
||||
|
||||
if ($contact['subhub'] AND in_array($contact['network'], array(NETWORK_DFRN, NETWORK_ZOT, NETWORK_OSTATUS))) {
|
||||
if ($contact['subhub'] && in_array($contact['network'], array(NETWORK_DFRN, NETWORK_ZOT, NETWORK_OSTATUS))) {
|
||||
/*
|
||||
* We should be getting everything via a hub. But just to be sure, let's check once a day.
|
||||
* (You can make this more or less frequent if desired by setting 'pushpoll_frequency' appropriately)
|
||||
|
@ -197,7 +200,7 @@ function cron_poll_contacts($argc, $argv) {
|
|||
$contact['priority'] = (($poll_interval !== false) ? intval($poll_interval) : 3);
|
||||
}
|
||||
|
||||
if (($contact['priority'] >= 0) AND !$force) {
|
||||
if (($contact['priority'] >= 0) && !$force) {
|
||||
$update = false;
|
||||
|
||||
$t = $contact['last-update'];
|
||||
|
@ -245,11 +248,12 @@ function cron_poll_contacts($argc, $argv) {
|
|||
|
||||
logger("Polling " . $contact["network"] . " " . $contact["id"] . " " . $contact["nick"] . " " . $contact["name"]);
|
||||
|
||||
if (($contact['network'] == NETWORK_FEED) AND ($contact['priority'] <= 3)) {
|
||||
proc_run(PRIORITY_MEDIUM, 'include/onepoll.php', intval($contact['id']));
|
||||
if (($contact['network'] == NETWORK_FEED) && ($contact['priority'] <= 3)) {
|
||||
$priority = PRIORITY_MEDIUM;
|
||||
} else {
|
||||
proc_run(PRIORITY_LOW, 'include/onepoll.php', intval($contact['id']));
|
||||
$priority = PRIORITY_LOW;
|
||||
}
|
||||
proc_run(array('priority' => $priority, 'dont_fork' => true), 'include/onepoll.php', (int)$contact['id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ function cronhooks_run(&$argv, &$argc) {
|
|||
|
||||
require_once 'include/datetime.php';
|
||||
|
||||
if (($argc == 2) AND is_array($a->hooks) AND array_key_exists("cron", $a->hooks)) {
|
||||
if (($argc == 2) && is_array($a->hooks) && array_key_exists("cron", $a->hooks)) {
|
||||
foreach ($a->hooks["cron"] as $hook) {
|
||||
if ($hook[1] == $argv[1]) {
|
||||
logger("Calling cron hook '" . $hook[1] . "'", LOGGER_DEBUG);
|
||||
|
@ -38,7 +38,7 @@ function cronhooks_run(&$argv, &$argc) {
|
|||
|
||||
$d = datetime_convert();
|
||||
|
||||
if (is_array($a->hooks) AND array_key_exists("cron", $a->hooks)) {
|
||||
if (is_array($a->hooks) && array_key_exists("cron", $a->hooks)) {
|
||||
foreach ($a->hooks["cron"] as $hook) {
|
||||
logger("Calling cronhooks for '" . $hook[1] . "'", LOGGER_DEBUG);
|
||||
proc_run(PRIORITY_MEDIUM, "include/cronhooks.php", $hook[1]);
|
||||
|
|
148
include/dba.php
148
include/dba.php
|
@ -21,6 +21,8 @@ class dba {
|
|||
private $driver;
|
||||
public $connected = false;
|
||||
public $error = false;
|
||||
public $errorno = 0;
|
||||
public $affected_rows = 0;
|
||||
private $_server_info = '';
|
||||
private static $in_transaction = false;
|
||||
private static $dbo;
|
||||
|
@ -183,17 +185,17 @@ class dba {
|
|||
|
||||
foreach ($r AS $row) {
|
||||
if ((intval($a->config["system"]["db_loglimit_index"]) > 0)) {
|
||||
$log = (in_array($row['key'], $watchlist) AND
|
||||
$log = (in_array($row['key'], $watchlist) &&
|
||||
($row['rows'] >= intval($a->config["system"]["db_loglimit_index"])));
|
||||
} else {
|
||||
$log = false;
|
||||
}
|
||||
|
||||
if ((intval($a->config["system"]["db_loglimit_index_high"]) > 0) AND ($row['rows'] >= intval($a->config["system"]["db_loglimit_index_high"]))) {
|
||||
if ((intval($a->config["system"]["db_loglimit_index_high"]) > 0) && ($row['rows'] >= intval($a->config["system"]["db_loglimit_index_high"]))) {
|
||||
$log = true;
|
||||
}
|
||||
|
||||
if (in_array($row['key'], $blacklist) OR ($row['key'] == "")) {
|
||||
if (in_array($row['key'], $blacklist) || ($row['key'] == "")) {
|
||||
$log = false;
|
||||
}
|
||||
|
||||
|
@ -363,7 +365,7 @@ class dba {
|
|||
// PDO doesn't return "true" on successful operations - like mysqli does
|
||||
// Emulate this behaviour by checking if the query returned data and had columns
|
||||
// This should be reliable enough
|
||||
if (($this->driver == 'pdo') AND (count($r) == 0) AND ($columns == 0)) {
|
||||
if (($this->driver == 'pdo') && (count($r) == 0) && ($columns == 0)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -490,7 +492,7 @@ class dba {
|
|||
static private function replace_parameters($sql, $args) {
|
||||
$offset = 0;
|
||||
foreach ($args AS $param => $value) {
|
||||
if (is_int($args[$param]) OR is_float($args[$param])) {
|
||||
if (is_int($args[$param]) || is_float($args[$param])) {
|
||||
$replace = intval($args[$param]);
|
||||
} else {
|
||||
$replace = "'".self::$dbo->escape($args[$param])."'";
|
||||
|
@ -520,7 +522,7 @@ class dba {
|
|||
unset($args[0]);
|
||||
|
||||
// When the second function parameter is an array then use this as the parameter array
|
||||
if ((count($args) > 0) AND (is_array($args[1]))) {
|
||||
if ((count($args) > 0) && (is_array($args[1]))) {
|
||||
$params = $args[1];
|
||||
} else {
|
||||
$params = $args;
|
||||
|
@ -533,7 +535,7 @@ class dba {
|
|||
$args[++$i] = $param;
|
||||
}
|
||||
|
||||
if (!self::$dbo OR !self::$dbo->connected) {
|
||||
if (!self::$dbo || !self::$dbo->connected) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -551,6 +553,7 @@ class dba {
|
|||
|
||||
self::$dbo->error = '';
|
||||
self::$dbo->errorno = 0;
|
||||
self::$dbo->affected_rows = 0;
|
||||
|
||||
switch (self::$dbo->driver) {
|
||||
case 'pdo':
|
||||
|
@ -573,6 +576,7 @@ class dba {
|
|||
$retval = false;
|
||||
} else {
|
||||
$retval = $stmt;
|
||||
self::$dbo->affected_rows = $retval->rowCount();
|
||||
}
|
||||
break;
|
||||
case 'mysqli':
|
||||
|
@ -612,6 +616,7 @@ class dba {
|
|||
} else {
|
||||
$stmt->store_result();
|
||||
$retval = $stmt;
|
||||
self::$dbo->affected_rows = $retval->affected_rows;
|
||||
}
|
||||
break;
|
||||
case 'mysql':
|
||||
|
@ -620,13 +625,39 @@ class dba {
|
|||
if (mysql_errno(self::$dbo->db)) {
|
||||
self::$dbo->error = mysql_error(self::$dbo->db);
|
||||
self::$dbo->errorno = mysql_errno(self::$dbo->db);
|
||||
} else {
|
||||
self::$dbo->affected_rows = mysql_affected_rows($retval);
|
||||
|
||||
// Due to missing mysql_* support this here wasn't tested at all
|
||||
// See here: http://php.net/manual/en/function.mysql-num-rows.php
|
||||
if (self::$dbo->affected_rows <= 0) {
|
||||
self::$dbo->affected_rows = mysql_num_rows($retval);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (self::$dbo->errorno != 0) {
|
||||
logger('DB Error '.self::$dbo->errorno.': '.self::$dbo->error."\n".
|
||||
$a->callstack(8))."\n".self::replace_parameters($sql, $args);
|
||||
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3);
|
||||
|
||||
if (isset($trace[2])) {
|
||||
$called_from = $trace[2];
|
||||
} else {
|
||||
// We use just something that is defined to avoid warnings
|
||||
$called_from = $trace[0];
|
||||
}
|
||||
// We are having an own error logging in the function "e"
|
||||
if ($called_from['function'] != 'e') {
|
||||
// We have to preserve the error code, somewhere in the logging it get lost
|
||||
$error = self::$dbo->error;
|
||||
$errorno = self::$dbo->errorno;
|
||||
|
||||
logger('DB Error '.self::$dbo->errorno.': '.self::$dbo->error."\n".
|
||||
$a->callstack(8)."\n".self::replace_parameters($sql, $params));
|
||||
|
||||
self::$dbo->error = $error;
|
||||
self::$dbo->errorno = $errorno;
|
||||
}
|
||||
}
|
||||
|
||||
$a->save_timestamp($stamp1, 'database');
|
||||
|
@ -662,18 +693,45 @@ class dba {
|
|||
|
||||
$args = func_get_args();
|
||||
|
||||
$stmt = call_user_func_array('self::p', $args);
|
||||
// In a case of a deadlock we are repeating the query 20 times
|
||||
$timeout = 20;
|
||||
|
||||
if (is_bool($stmt)) {
|
||||
$retval = $stmt;
|
||||
} elseif (is_object($stmt)) {
|
||||
$retval = true;
|
||||
} else {
|
||||
$retval = false;
|
||||
do {
|
||||
$stmt = call_user_func_array('self::p', $args);
|
||||
|
||||
if (is_bool($stmt)) {
|
||||
$retval = $stmt;
|
||||
} elseif (is_object($stmt)) {
|
||||
$retval = true;
|
||||
} else {
|
||||
$retval = false;
|
||||
}
|
||||
|
||||
self::close($stmt);
|
||||
|
||||
} while ((self::$dbo->errorno == 1213) && (--$timeout > 0));
|
||||
|
||||
if (self::$dbo->errorno != 0) {
|
||||
// We have to preserve the error code, somewhere in the logging it get lost
|
||||
$error = self::$dbo->error;
|
||||
$errorno = self::$dbo->errorno;
|
||||
|
||||
array_shift($args);
|
||||
|
||||
// When the second function parameter is an array then use this as the parameter array
|
||||
if ((count($args) > 0) && (is_array($args[0]))) {
|
||||
$params = $args[0];
|
||||
} else {
|
||||
$params = $args;
|
||||
}
|
||||
|
||||
logger('DB Error '.self::$dbo->errorno.': '.self::$dbo->error."\n".
|
||||
$a->callstack(8)."\n".self::replace_parameters($sql, $params));
|
||||
|
||||
self::$dbo->error = $error;
|
||||
self::$dbo->errorno = $errorno;
|
||||
}
|
||||
|
||||
self::close($stmt);
|
||||
|
||||
$a->save_timestamp($stamp, "database_write");
|
||||
|
||||
return $retval;
|
||||
|
@ -723,6 +781,15 @@ class dba {
|
|||
return $retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the number of affected rows of the last statement
|
||||
*
|
||||
* @return int Number of rows
|
||||
*/
|
||||
static public function affected_rows() {
|
||||
return self::$dbo->affected_rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the number of rows of a statement
|
||||
*
|
||||
|
@ -806,6 +873,41 @@ class dba {
|
|||
return self::e($sql, $param);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Locks a table for exclusive write access
|
||||
*
|
||||
* This function can be extended in the future to accept a table array as well.
|
||||
*
|
||||
* @param string $table Table name
|
||||
*
|
||||
* @return boolean was the lock successful?
|
||||
*/
|
||||
static public function lock($table) {
|
||||
// See here: https://dev.mysql.com/doc/refman/5.7/en/lock-tables-and-transactions.html
|
||||
self::e("SET autocommit=0");
|
||||
$success = self::e("LOCK TABLES `".self::$dbo->escape($table)."` WRITE");
|
||||
if (!$success) {
|
||||
self::e("SET autocommit=1");
|
||||
} else {
|
||||
self::$in_transaction = true;
|
||||
}
|
||||
return $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Unlocks all locked tables
|
||||
*
|
||||
* @return boolean was the unlock successful?
|
||||
*/
|
||||
static public function unlock() {
|
||||
// See here: https://dev.mysql.com/doc/refman/5.7/en/lock-tables-and-transactions.html
|
||||
self::e("COMMIT");
|
||||
$success = self::e("UNLOCK TABLES");
|
||||
self::e("SET autocommit=1");
|
||||
self::$in_transaction = false;
|
||||
return $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Starts a transaction
|
||||
*
|
||||
|
@ -913,7 +1015,7 @@ class dba {
|
|||
|
||||
// When the search field is the relation field, we don't need to fetch the rows
|
||||
// This is useful when the leading record is already deleted in the frontend but the rest is done in the backend
|
||||
if ((count($param) == 1) AND ($field == array_keys($param)[0])) {
|
||||
if ((count($param) == 1) && ($field == array_keys($param)[0])) {
|
||||
foreach ($rel_def AS $rel_table => $rel_fields) {
|
||||
foreach ($rel_fields AS $rel_field) {
|
||||
$retval = self::delete($rel_table, array($rel_field => array_values($param)[0]), true, $callstack);
|
||||
|
@ -956,7 +1058,7 @@ class dba {
|
|||
$sql = "DELETE FROM `".$command['table']."` WHERE `".
|
||||
implode("` = ? AND `", array_keys($command['param']))."` = ?";
|
||||
|
||||
logger(dba::replace_parameters($sql, $command['param']), LOGGER_DATA);
|
||||
logger(self::replace_parameters($sql, $command['param']), LOGGER_DATA);
|
||||
|
||||
if (!self::e($sql, $command['param'])) {
|
||||
if ($do_transaction) {
|
||||
|
@ -986,7 +1088,7 @@ class dba {
|
|||
$sql = "DELETE FROM `".$table."` WHERE `".$field."` IN (".
|
||||
substr(str_repeat("?, ", count($field_values)), 0, -2).");";
|
||||
|
||||
logger(dba::replace_parameters($sql, $field_values), LOGGER_DATA);
|
||||
logger(self::replace_parameters($sql, $field_values), LOGGER_DATA);
|
||||
|
||||
if (!self::e($sql, $field_values)) {
|
||||
if ($do_transaction) {
|
||||
|
@ -1075,7 +1177,7 @@ class dba {
|
|||
}
|
||||
}
|
||||
|
||||
if (!$do_update OR (count($fields) == 0)) {
|
||||
if (!$do_update || (count($fields) == 0)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1155,7 +1257,7 @@ class dba {
|
|||
|
||||
$result = self::p($sql, $condition);
|
||||
|
||||
if (is_bool($result) OR !$single_row) {
|
||||
if (is_bool($result) || !$single_row) {
|
||||
return $result;
|
||||
} else {
|
||||
$row = self::fetch($result);
|
||||
|
|
|
@ -14,18 +14,19 @@ $objDDDBLResultHandler = new DataObjectPool('Result-Handler');
|
|||
*
|
||||
**/
|
||||
$cloPDOStatementResultHandler = function(Queue $objQueue) {
|
||||
$objPDO = $objQueue->getState()->get('PDOStatement');
|
||||
$objQueue->getState()->update(array('result' => $objPDO));
|
||||
|
||||
$objPDO = $objQueue->getState()->get('PDOStatement');
|
||||
$objQueue->getState()->update(array('result' => $objPDO));
|
||||
|
||||
# delete handler which closes the PDOStatement-cursor
|
||||
# this will be done manual if using this handler
|
||||
$objQueue->deleteHandler(QUEUE_CLOSE_CURSOR_POSITION);
|
||||
|
||||
/*
|
||||
* delete handler which closes the PDOStatement-cursor
|
||||
* this will be done manual if using this handler
|
||||
*/
|
||||
$objQueue->deleteHandler(QUEUE_CLOSE_CURSOR_POSITION);
|
||||
};
|
||||
|
||||
$objDDDBLResultHandler->add('PDOStatement', array('HANDLER' => $cloPDOStatementResultHandler));
|
||||
|
||||
if (! class_exists('dba')) {
|
||||
/**
|
||||
*
|
||||
* MySQL database class
|
||||
|
@ -36,8 +37,6 @@ $objDDDBLResultHandler->add('PDOStatement', array('HANDLER' => $cloPDOStatementR
|
|||
* the debugging stream is safe to view within both terminals and web pages.
|
||||
*
|
||||
*/
|
||||
|
||||
if (! class_exists('dba')) {
|
||||
class dba {
|
||||
|
||||
private $debug = 0;
|
||||
|
@ -146,16 +145,17 @@ class dba {
|
|||
|
||||
$a->save_timestamp($stamp1, "database");
|
||||
|
||||
/// @TODO really check $a->config for 'system'? it is very generic and should be there
|
||||
if (x($a->config, 'system') && x($a->config['system'], 'db_log')) {
|
||||
if (($duration > $a->config["system"]["db_loglimit"])) {
|
||||
$duration = round($duration, 3);
|
||||
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
|
||||
@file_put_contents($a->config["system"]["db_log"], datetime_convert()."\t".$duration."\t".
|
||||
basename($backtrace[1]["file"])."\t".
|
||||
$backtrace[1]["line"]."\t".$backtrace[2]["function"]."\t".
|
||||
substr($sql, 0, 2000)."\n", FILE_APPEND);
|
||||
}
|
||||
/*
|
||||
* Check if the configuration group 'system' and db_log is there. The
|
||||
* extra first check needs to be done to avoid endless loop.
|
||||
*/
|
||||
if (x($a->config, 'system') && x($a->config['system'], 'db_log') && ($duration > $a->config["system"]["db_loglimit"])) {
|
||||
$duration = round($duration, 3);
|
||||
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
|
||||
@file_put_contents($a->config["system"]["db_log"], datetime_convert()."\t".$duration."\t".
|
||||
basename($backtrace[1]["file"])."\t".
|
||||
$backtrace[1]["line"]."\t".$backtrace[2]["function"]."\t".
|
||||
substr($sql, 0, 2000)."\n", FILE_APPEND);
|
||||
}
|
||||
|
||||
if ($intErrorCode) {
|
||||
|
@ -190,20 +190,23 @@ class dba {
|
|||
* regardless of any logging that may or may nor be in effect.
|
||||
* These usually indicate SQL syntax errors that need to be resolved.
|
||||
*/
|
||||
if (isset($result) AND ($result === false)) {
|
||||
if (isset($result) && ($result === false)) {
|
||||
logger('dba: ' . printable($sql) . ' returned false.' . "\n" . $this->error);
|
||||
if (file_exists('dbfail.out')) {
|
||||
file_put_contents('dbfail.out', datetime_convert() . "\n" . printable($sql) . ' returned false' . "\n" . $this->error . "\n", FILE_APPEND);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($result) AND (($result === true) || ($result === false))) {
|
||||
if (isset($result) && (($result === true) || ($result === false))) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
if ($onlyquery) {
|
||||
$this->result = $r; # this will store an PDOStatement Object in result
|
||||
$this->result->execute(); # execute the Statement, to get its result
|
||||
// this will store an PDOStatement Object in result
|
||||
$this->result = $r;
|
||||
|
||||
// execute the Statement, to get its result
|
||||
$this->result->execute();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -262,7 +265,8 @@ function printable($s) {
|
|||
return $s;
|
||||
}}
|
||||
|
||||
// Procedural functions
|
||||
// --- Procedural functions ---
|
||||
|
||||
if (! function_exists('dbg')) {
|
||||
function dbg($state) {
|
||||
global $db;
|
||||
|
@ -273,18 +277,20 @@ function dbg($state) {
|
|||
if (! function_exists('dbesc')) {
|
||||
function dbesc($str) {
|
||||
global $db;
|
||||
if ($db && $db->connected)
|
||||
return($db->escape($str));
|
||||
else
|
||||
return(str_replace("'","\\'",$str));
|
||||
|
||||
if ($db && $db->connected) {
|
||||
return $db->escape($str);
|
||||
} else {
|
||||
return str_replace("'","\\'",$str);
|
||||
}
|
||||
}}
|
||||
|
||||
if (! function_exists('q')) {
|
||||
/**
|
||||
/*
|
||||
* Function: q($sql,$args);
|
||||
* Description: execute SQL query with printf style args.
|
||||
* Example: $r = q("SELECT * FROM `%s` WHERE `uid` = %d",
|
||||
* 'user', 1);
|
||||
* 'user', 1);
|
||||
*/
|
||||
function q($sql) {
|
||||
|
||||
|
@ -301,23 +307,19 @@ function q($sql) {
|
|||
return $db->q($stmt);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
/*
|
||||
* This will happen occasionally trying to store the
|
||||
* session data after abnormal program termination
|
||||
*
|
||||
*/
|
||||
logger('dba: no database: ' . print_r($args,true));
|
||||
return false;
|
||||
|
||||
}}
|
||||
|
||||
if (! function_exists('dbq')) {
|
||||
/**
|
||||
/*
|
||||
* Raw db query, no arguments
|
||||
*/
|
||||
function dbq($sql) {
|
||||
|
||||
global $db;
|
||||
if ($db && $db->connected) {
|
||||
$ret = $db->q($sql);
|
||||
|
@ -327,15 +329,14 @@ function dbq($sql) {
|
|||
return $ret;
|
||||
}}
|
||||
|
||||
|
||||
/*
|
||||
* Caller is responsible for ensuring that any integer arguments to
|
||||
* dbesc_array are actually integers and not malformed strings containing
|
||||
* SQL injection vectors. All integer array elements should be specifically
|
||||
* cast to int to avoid trouble.
|
||||
*/
|
||||
if (! function_exists('dbesc_array_cb')) {
|
||||
function dbesc_array_cb(&$item, $key) {
|
||||
/*
|
||||
* Caller is responsible for ensuring that any integer arguments to
|
||||
* dbesc_array are actually integers and not malformed strings containing
|
||||
* SQL injection vectors. All integer array elements should be specifically
|
||||
* cast to int to avoid trouble.
|
||||
*/
|
||||
if (is_string($item)) {
|
||||
$item = dbesc($item);
|
||||
}
|
||||
|
|
|
@ -17,9 +17,14 @@ function dbclean_run(&$argv, &$argc) {
|
|||
$stage = 0;
|
||||
}
|
||||
|
||||
// Get the expire days for step 8 and 9
|
||||
$days = Config::get('system', 'dbclean-expire-days', 0);
|
||||
|
||||
if ($stage == 0) {
|
||||
for ($i = 1; $i <= 7; $i++) {
|
||||
if (!Config::get('system', 'finished-dbclean-'.$i, false)) {
|
||||
for ($i = 1; $i <= 9; $i++) {
|
||||
// Execute the background script for a step when it isn't finished.
|
||||
// Execute step 8 and 9 only when $days is defined.
|
||||
if (!Config::get('system', 'finished-dbclean-'.$i, false) && (($i < 8) || ($days > 0))) {
|
||||
proc_run(PRIORITY_LOW, 'include/dbclean.php', $i);
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +35,19 @@ function dbclean_run(&$argv, &$argc) {
|
|||
|
||||
/**
|
||||
* @brief Remove orphaned database entries
|
||||
* @param integer $stage What should be deleted?
|
||||
*
|
||||
* Values for $stage:
|
||||
* ------------------
|
||||
* 1: Old global item entries from item table without user copy.
|
||||
* 2: Items without parents.
|
||||
* 3: Orphaned data from thread table.
|
||||
* 4: Orphaned data from notify table.
|
||||
* 5: Orphaned data from notify-threads table.
|
||||
* 6: Orphaned data from sign table.
|
||||
* 7: Orphaned data from term table.
|
||||
* 8: Expired threads.
|
||||
* 9: Old global item entries from expired threads
|
||||
*/
|
||||
function remove_orphans($stage = 0) {
|
||||
global $db;
|
||||
|
@ -39,6 +57,9 @@ function remove_orphans($stage = 0) {
|
|||
// We split the deletion in many small tasks
|
||||
$limit = 1000;
|
||||
|
||||
// Get the expire days for step 8 and 9
|
||||
$days = Config::get('system', 'dbclean-expire-days', 0);
|
||||
|
||||
if ($stage == 1) {
|
||||
$last_id = Config::get('system', 'dbclean-last-id-1', 0);
|
||||
|
||||
|
@ -61,11 +82,6 @@ function remove_orphans($stage = 0) {
|
|||
logger("Done deleting ".$count." old global item entries from item table without user copy. Last ID: ".$last_id);
|
||||
|
||||
Config::set('system', 'dbclean-last-id-1', $last_id);
|
||||
|
||||
// We will eventually set this value when we found a good way to delete these items in another way.
|
||||
// if ($count < $limit) {
|
||||
// Config::set('system', 'finished-dbclean-1', true);
|
||||
// }
|
||||
} elseif ($stage == 2) {
|
||||
$last_id = Config::get('system', 'dbclean-last-id-2', 0);
|
||||
|
||||
|
@ -216,11 +232,71 @@ function remove_orphans($stage = 0) {
|
|||
if ($count < $limit) {
|
||||
Config::set('system', 'finished-dbclean-7', true);
|
||||
}
|
||||
} elseif ($stage == 8) {
|
||||
if ($days <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$last_id = Config::get('system', 'dbclean-last-id-8', 0);
|
||||
|
||||
logger("Deleting expired threads. Last ID: ".$last_id);
|
||||
$r = dba::p("SELECT `thread`.`iid` FROM `thread`
|
||||
INNER JOIN `contact` ON `thread`.`contact-id` = `contact`.`id` AND NOT `notify_new_posts`
|
||||
WHERE `thread`.`received` < UTC_TIMESTAMP() - INTERVAL ? DAY
|
||||
AND NOT `thread`.`mention` AND NOT `thread`.`starred`
|
||||
AND NOT `thread`.`wall` AND NOT `thread`.`origin`
|
||||
AND `thread`.`uid` != 0 AND `thread`.`iid` >= ?
|
||||
AND NOT `thread`.`iid` IN (SELECT `parent` FROM `item`
|
||||
WHERE (`item`.`starred` OR (`item`.`resource-id` != '')
|
||||
OR (`item`.`file` != '') OR (`item`.`event-id` != '')
|
||||
OR (`item`.`attach` != '') OR `item`.`wall` OR `item`.`origin`)
|
||||
AND `item`.`parent` = `thread`.`iid`)
|
||||
ORDER BY `thread`.`iid` LIMIT 1000", $days, $last_id);
|
||||
$count = dba::num_rows($r);
|
||||
if ($count > 0) {
|
||||
logger("found expired threads: ".$count);
|
||||
while ($thread = dba::fetch($r)) {
|
||||
$last_id = $thread["iid"];
|
||||
dba::delete('thread', array('iid' => $thread["iid"]));
|
||||
}
|
||||
} else {
|
||||
logger("No expired threads found");
|
||||
}
|
||||
dba::close($r);
|
||||
logger("Done deleting ".$count." expired threads. Last ID: ".$last_id);
|
||||
|
||||
Config::set('system', 'dbclean-last-id-8', $last_id);
|
||||
} elseif ($stage == 9) {
|
||||
if ($days <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$last_id = Config::get('system', 'dbclean-last-id-9', 0);
|
||||
$till_id = Config::get('system', 'dbclean-last-id-8', 0);
|
||||
|
||||
logger("Deleting old global item entries from expired threads from ID ".$last_id." to ID ".$till_id);
|
||||
$r = dba::p("SELECT `id` FROM `item` WHERE `uid` = 0 AND
|
||||
NOT EXISTS (SELECT `guid` FROM `item` AS `i` WHERE `item`.`guid` = `i`.`guid` AND `i`.`uid` != 0) AND
|
||||
`received` < UTC_TIMESTAMP() - INTERVAL 90 DAY AND `id` >= ? AND `id` <= ?
|
||||
ORDER BY `id` LIMIT ".intval($limit), $last_id, $till_id);
|
||||
$count = dba::num_rows($r);
|
||||
if ($count > 0) {
|
||||
logger("found global item entries from expired threads: ".$count);
|
||||
while ($orphan = dba::fetch($r)) {
|
||||
$last_id = $orphan["id"];
|
||||
dba::delete('item', array('id' => $orphan["id"]));
|
||||
}
|
||||
} else {
|
||||
logger("No global item entries from expired threads");
|
||||
}
|
||||
dba::close($r);
|
||||
logger("Done deleting ".$count." old global item entries from expired threads. Last ID: ".$last_id);
|
||||
|
||||
Config::set('system', 'dbclean-last-id-9', $last_id);
|
||||
}
|
||||
|
||||
// Call it again if not all entries were purged
|
||||
if (($stage != 0) AND ($count > 0)) {
|
||||
if (($stage != 0) && ($count > 0)) {
|
||||
proc_run(PRIORITY_MEDIUM, 'include/dbclean.php');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ class dbm {
|
|||
|
||||
if (is_bool($value)) {
|
||||
$value = ($value ? 'true' : 'false');
|
||||
} elseif (is_float($value) OR is_integer($value)) {
|
||||
} elseif (is_float($value) || is_integer($value)) {
|
||||
$value = (string)$value;
|
||||
} else {
|
||||
$value = "'".dbesc($value)."'";
|
||||
|
|
|
@ -30,7 +30,7 @@ function convert_to_innodb() {
|
|||
$sql = sprintf("ALTER TABLE `%s` engine=InnoDB;", dbesc($table['TABLE_NAME']));
|
||||
echo $sql."\n";
|
||||
|
||||
$result = @$db->q($sql);
|
||||
$result = $db->q($sql);
|
||||
if (!dbm::is_result($result)) {
|
||||
print_update_error($db, $sql);
|
||||
}
|
||||
|
@ -85,6 +85,7 @@ function update_fail($update_id, $error_message) {
|
|||
|
||||
|
||||
/*
|
||||
@TODO deprecated code?
|
||||
$email_tpl = get_intltext_template("update_fail_eml.tpl");
|
||||
$email_msg = replace_macros($email_tpl, array(
|
||||
'$sitename' => $a->config['sitename'],
|
||||
|
@ -133,7 +134,7 @@ function table_structure($table) {
|
|||
// On utf8mb4 a varchar index can only have a length of 191
|
||||
// The "show index" command sometimes returns this value although this value wasn't added manually.
|
||||
// Because we don't want to add this number to every index, we ignore bigger numbers
|
||||
if (($index["Sub_part"] != "") AND (($index["Sub_part"] < 191) OR ($index["Key_name"] == "PRIMARY"))) {
|
||||
if (($index["Sub_part"] != "") && (($index["Sub_part"] < 191) || ($index["Key_name"] == "PRIMARY"))) {
|
||||
$column .= "(".$index["Sub_part"].")";
|
||||
}
|
||||
|
||||
|
@ -232,7 +233,7 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
|
|||
}
|
||||
|
||||
// MySQL >= 5.7.4 doesn't support the IGNORE keyword in ALTER TABLE statements
|
||||
if ((version_compare($db->server_info(), '5.7.4') >= 0) AND
|
||||
if ((version_compare($db->server_info(), '5.7.4') >= 0) &&
|
||||
!(strpos($db->server_info(), 'MariaDB') !== false)) {
|
||||
$ignore = '';
|
||||
} else {
|
||||
|
@ -381,7 +382,7 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
|
|||
$field_definition = $database[$name]["fields"][$fieldname];
|
||||
|
||||
// Define the default collation if not given
|
||||
if (!isset($parameters['Collation']) AND !is_null($field_definition['Collation'])) {
|
||||
if (!isset($parameters['Collation']) && !is_null($field_definition['Collation'])) {
|
||||
$parameters['Collation'] = 'utf8mb4_general_ci';
|
||||
} else {
|
||||
$parameters['Collation'] = null;
|
||||
|
@ -389,7 +390,7 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
|
|||
|
||||
if ($field_definition['Collation'] != $parameters['Collation']) {
|
||||
$sql2 = db_modify_table_field($fieldname, $parameters);
|
||||
if (($sql3 == "") OR (substr($sql3, -2, 2) == "; ")) {
|
||||
if (($sql3 == "") || (substr($sql3, -2, 2) == "; ")) {
|
||||
$sql3 .= "ALTER" . $ignore . " TABLE `".$temp_name."` ".$sql2;
|
||||
} else {
|
||||
$sql3 .= ", ".$sql2;
|
||||
|
@ -513,7 +514,7 @@ function db_field_command($parameters, $create = true) {
|
|||
if ($parameters["extra"] != "")
|
||||
$fieldstruct .= " ".$parameters["extra"];
|
||||
|
||||
/*if (($parameters["primary"] != "") AND $create)
|
||||
/*if (($parameters["primary"] != "") && $create)
|
||||
$fieldstruct .= " PRIMARY KEY";*/
|
||||
|
||||
return($fieldstruct);
|
||||
|
@ -530,7 +531,7 @@ function db_create_table($name, $fields, $verbose, $action, $indexes=null) {
|
|||
$primary_keys = array();
|
||||
foreach ($fields AS $fieldname => $field) {
|
||||
$sql_rows[] = "`".dbesc($fieldname)."` ".db_field_command($field);
|
||||
if (x($field,'primary') and $field['primary']!='') {
|
||||
if (x($field,'primary') && $field['primary']!='') {
|
||||
$primary_keys[] = $fieldname;
|
||||
}
|
||||
}
|
||||
|
@ -1205,7 +1206,7 @@ function db_definition() {
|
|||
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
|
||||
"name" => array("type" => "varchar(128)", "not null" => "1", "default" => ""),
|
||||
"locked" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
|
||||
"created" => array("type" => "datetime", "default" => NULL_DATE),
|
||||
"pid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
|
||||
),
|
||||
"indexes" => array(
|
||||
"PRIMARY" => array("id"),
|
||||
|
@ -1739,11 +1740,14 @@ function db_definition() {
|
|||
"created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
|
||||
"pid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
|
||||
"executed" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
|
||||
"done" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
|
||||
),
|
||||
"indexes" => array(
|
||||
"PRIMARY" => array("id"),
|
||||
"pid" => array("pid"),
|
||||
"parameter" => array("parameter(64)"),
|
||||
"priority_created" => array("priority", "created"),
|
||||
"executed" => array("executed"),
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -1762,10 +1766,10 @@ function dbstructure_run(&$argv, &$argc) {
|
|||
}
|
||||
|
||||
if (is_null($db)) {
|
||||
@include(".htconfig.php");
|
||||
require_once("include/dba.php");
|
||||
@include ".htconfig.php";
|
||||
require_once "include/dba.php";
|
||||
$db = new dba($db_host, $db_user, $db_pass, $db_data);
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
}
|
||||
|
||||
if ($argc == 2) {
|
||||
|
|
|
@ -91,7 +91,7 @@ function delivery_run(&$argv, &$argc){
|
|||
$uid = $item_id;
|
||||
} else {
|
||||
// find ancestors
|
||||
$r = q("SELECT * FROM `item` WHERE `id` = %d and visible = 1 and moderated = 0 LIMIT 1",
|
||||
$r = q("SELECT * FROM `item` WHERE `id` = %d AND visible = 1 AND moderated = 0 LIMIT 1",
|
||||
intval($item_id)
|
||||
);
|
||||
|
||||
|
@ -105,7 +105,7 @@ function delivery_run(&$argv, &$argc){
|
|||
$updated = $r[0]['edited'];
|
||||
|
||||
$items = q("SELECT `item`.*, `sign`.`signed_text`,`sign`.`signature`,`sign`.`signer`
|
||||
FROM `item` LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id` WHERE `parent` = %d and visible = 1 and moderated = 0 ORDER BY `id` ASC",
|
||||
FROM `item` LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id` WHERE `parent` = %d AND visible = 1 AND moderated = 0 ORDER BY `id` ASC",
|
||||
intval($parent_id)
|
||||
);
|
||||
|
||||
|
@ -339,7 +339,7 @@ function delivery_run(&$argv, &$argc){
|
|||
|
||||
// If we are setup as a soapbox we aren't accepting top level posts from this person
|
||||
|
||||
if (($x[0]['page-flags'] == PAGE_SOAPBOX) AND $top_level) {
|
||||
if (($x[0]['page-flags'] == PAGE_SOAPBOX) && $top_level) {
|
||||
break;
|
||||
}
|
||||
logger('mod-delivery: local delivery');
|
||||
|
@ -453,7 +453,7 @@ function delivery_run(&$argv, &$argc){
|
|||
$headers .= "References: <".iri2msgid($it["parent-uri"]).">";
|
||||
|
||||
// If Threading is enabled, write down the correct parent
|
||||
if (($it["thr-parent"] != "") and ($it["thr-parent"] != $it["parent-uri"]))
|
||||
if (($it["thr-parent"] != "") && ($it["thr-parent"] != $it["parent-uri"]))
|
||||
$headers .= " <".iri2msgid($it["thr-parent"]).">";
|
||||
$headers .= "\n";
|
||||
|
||||
|
@ -462,14 +462,14 @@ function delivery_run(&$argv, &$argc){
|
|||
dbesc($it['parent-uri']),
|
||||
intval($uid));
|
||||
|
||||
if (dbm::is_result($r) AND ($r[0]['title'] != '')) {
|
||||
if (dbm::is_result($r) && ($r[0]['title'] != '')) {
|
||||
$subject = $r[0]['title'];
|
||||
} else {
|
||||
$r = q("SELECT `title` FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d LIMIT 1",
|
||||
dbesc($it['parent-uri']),
|
||||
intval($uid));
|
||||
|
||||
if (dbm::is_result($r) AND ($r[0]['title'] != ''))
|
||||
if (dbm::is_result($r) && ($r[0]['title'] != ''))
|
||||
$subject = $r[0]['title'];
|
||||
}
|
||||
}
|
||||
|
|
104
include/dfrn.php
104
include/dfrn.php
|
@ -245,7 +245,7 @@ class dfrn {
|
|||
/// @TODO This hook can't work anymore
|
||||
// call_hooks('atom_feed', $atom);
|
||||
|
||||
if (!dbm::is_result($items) OR $onlyheader) {
|
||||
if (!dbm::is_result($items) || $onlyheader) {
|
||||
$atom = trim($doc->saveXML());
|
||||
|
||||
call_hooks('atom_feed_end', $atom);
|
||||
|
@ -284,6 +284,62 @@ class dfrn {
|
|||
return $atom;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Generate an atom entry for a given item id
|
||||
*
|
||||
* @param int $item_id The item id
|
||||
*
|
||||
* @return string DFRN feed entry
|
||||
*/
|
||||
public static function itemFeed($item_id) {
|
||||
$r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
|
||||
`contact`.`name`, `contact`.`network`, `contact`.`photo`, `contact`.`url`,
|
||||
`contact`.`name-date`, `contact`.`uri-date`, `contact`.`avatar-date`,
|
||||
`contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
|
||||
`sign`.`signed_text`, `sign`.`signature`, `sign`.`signer`
|
||||
FROM `item`
|
||||
STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
|
||||
AND (NOT `contact`.`blocked` OR `contact`.`pending`)
|
||||
LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id`
|
||||
WHERE `item`.`id` = %d AND `item`.`visible` AND NOT `item`.`moderated` AND `item`.`parent` != 0
|
||||
AND `item`.`wall` AND NOT `item`.`private`",
|
||||
intval($item_id)
|
||||
);
|
||||
|
||||
if (!dbm::is_result($r)) {
|
||||
killme();
|
||||
}
|
||||
|
||||
$item = $r[0];
|
||||
|
||||
$r = q("SELECT `contact`.*, `user`.`nickname`, `user`.`timezone`, `user`.`page-flags`, `user`.`account-type`
|
||||
FROM `contact` INNER JOIN `user` ON `user`.`uid` = `contact`.`uid`
|
||||
WHERE `contact`.`self` AND `user`.`uid` = %d LIMIT 1",
|
||||
intval($item['uid'])
|
||||
);
|
||||
|
||||
if (!dbm::is_result($r)) {
|
||||
killme();
|
||||
}
|
||||
|
||||
$owner = $r[0];
|
||||
|
||||
$doc = new DOMDocument('1.0', 'utf-8');
|
||||
$doc->formatOutput = true;
|
||||
|
||||
$alternatelink = $owner['url'];
|
||||
|
||||
$root = self::add_header($doc, $owner, 'dfrn:owner', $alternatelink, true);
|
||||
|
||||
$type = 'html';
|
||||
|
||||
$entry = self::entry($doc, $type, $item, $owner, true);
|
||||
$root->appendChild($entry);
|
||||
|
||||
$atom = trim($doc->saveXML());
|
||||
return $atom;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Create XML text for DFRN mails
|
||||
*
|
||||
|
@ -508,7 +564,7 @@ class dfrn {
|
|||
|
||||
$attributes = array();
|
||||
|
||||
if (!$public OR !$hidewall) {
|
||||
if (!$public || !$hidewall) {
|
||||
$attributes = array("dfrn:updated" => $namdate);
|
||||
}
|
||||
|
||||
|
@ -519,7 +575,7 @@ class dfrn {
|
|||
$attributes = array("rel" => "photo", "type" => "image/jpeg",
|
||||
"media:width" => 175, "media:height" => 175, "href" => $owner['photo']);
|
||||
|
||||
if (!$public OR !$hidewall) {
|
||||
if (!$public || !$hidewall) {
|
||||
$attributes["dfrn:updated"] = $picdate;
|
||||
}
|
||||
|
||||
|
@ -921,7 +977,7 @@ class dfrn {
|
|||
|
||||
if (count($tags)) {
|
||||
foreach ($tags as $t) {
|
||||
if (($type != 'html') OR ($t[0] != "@")) {
|
||||
if (($type != 'html') || ($t[0] != "@")) {
|
||||
xml::add_element($doc, $entry, "category", "", array("scheme" => "X-DFRN:".$t[0].":".$t[1], "term" => $t[2]));
|
||||
}
|
||||
}
|
||||
|
@ -940,7 +996,7 @@ class dfrn {
|
|||
intval($owner["uid"]),
|
||||
dbesc(normalise_link($mention)));
|
||||
|
||||
if (dbm::is_result($r) AND ($r[0]["forum"] OR $r[0]["prv"])) {
|
||||
if (dbm::is_result($r) && ($r[0]["forum"] || $r[0]["prv"])) {
|
||||
xml::add_element($doc, $entry, "link", "", array("rel" => "mentioned",
|
||||
"ostatus:object-type" => ACTIVITY_OBJ_GROUP,
|
||||
"href" => $mention));
|
||||
|
@ -1323,7 +1379,7 @@ class dfrn {
|
|||
$contact["avatar-date"] = $attributes->textContent;
|
||||
}
|
||||
}
|
||||
if (($width > 0) AND ($href != "")) {
|
||||
if (($width > 0) && ($href != "")) {
|
||||
$avatarlist[$width] = $href;
|
||||
}
|
||||
}
|
||||
|
@ -1332,7 +1388,7 @@ class dfrn {
|
|||
$author["avatar"] = current($avatarlist);
|
||||
}
|
||||
|
||||
if (dbm::is_result($r) AND !$onlyfetch) {
|
||||
if (dbm::is_result($r) && !$onlyfetch) {
|
||||
logger("Check if contact details for contact " . $r[0]["id"] . " (" . $r[0]["nick"] . ") have to be updated.", LOGGER_DEBUG);
|
||||
|
||||
$poco = array("url" => $contact["url"]);
|
||||
|
@ -1774,7 +1830,7 @@ class dfrn {
|
|||
$relocate["poll"] = $xpath->query("dfrn:poll/text()", $relocation)->item(0)->nodeValue;
|
||||
$relocate["sitepubkey"] = $xpath->query("dfrn:sitepubkey/text()", $relocation)->item(0)->nodeValue;
|
||||
|
||||
if (($relocate["avatar"] == "") AND ($relocate["photo"] != "")) {
|
||||
if (($relocate["avatar"] == "") && ($relocate["photo"] != "")) {
|
||||
$relocate["avatar"] = $relocate["photo"];
|
||||
}
|
||||
|
||||
|
@ -1902,7 +1958,7 @@ class dfrn {
|
|||
return false;
|
||||
}
|
||||
|
||||
$r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `tag` = '%s', `edited` = '%s', `changed` = '%s' WHERE `uri` = '%s' AND `uid` = %d",
|
||||
$r = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `tag` = '%s', `edited` = '%s', `changed` = '%s' WHERE `uri` = '%s' AND `uid` IN (0, %d)",
|
||||
dbesc($item["title"]),
|
||||
dbesc($item["body"]),
|
||||
dbesc($item["tag"]),
|
||||
|
@ -1922,13 +1978,13 @@ class dfrn {
|
|||
}
|
||||
|
||||
// update last-child if it changes
|
||||
if ($item["last-child"] AND ($item["last-child"] != $current["last-child"])) {
|
||||
$r = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
|
||||
if ($item["last-child"] && ($item["last-child"] != $current["last-child"])) {
|
||||
$r = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` IN (0, %d)",
|
||||
dbesc(datetime_convert()),
|
||||
dbesc($item["parent-uri"]),
|
||||
intval($importer["importer_uid"])
|
||||
);
|
||||
$r = q("UPDATE `item` SET `last-child` = %d , `changed` = '%s' WHERE `uri` = '%s' AND `uid` = %d",
|
||||
$r = q("UPDATE `item` SET `last-child` = %d , `changed` = '%s' WHERE `uri` = '%s' AND `uid` IN (0, %d)",
|
||||
intval($item["last-child"]),
|
||||
dbesc(datetime_convert()),
|
||||
dbesc($item["uri"]),
|
||||
|
@ -2206,7 +2262,7 @@ class dfrn {
|
|||
$title = $attributes->textContent;
|
||||
}
|
||||
}
|
||||
if (($rel != "") AND ($href != "")) {
|
||||
if (($rel != "") && ($href != "")) {
|
||||
switch ($rel) {
|
||||
case "alternate":
|
||||
$item["plink"] = $href;
|
||||
|
@ -2254,7 +2310,7 @@ class dfrn {
|
|||
);
|
||||
|
||||
// Is there an existing item?
|
||||
if (dbm::is_result($current) AND edited_timestamp_is_newer($current[0], $item) AND
|
||||
if (dbm::is_result($current) && edited_timestamp_is_newer($current[0], $item) &&
|
||||
(datetime_convert("UTC","UTC",$item["edited"]) < $current[0]["edited"])) {
|
||||
logger("Item ".$item["uri"]." already existed.", LOGGER_DEBUG);
|
||||
return;
|
||||
|
@ -2328,7 +2384,7 @@ class dfrn {
|
|||
}
|
||||
|
||||
$notice_info = $xpath->query("statusnet:notice_info", $entry);
|
||||
if ($notice_info AND ($notice_info->length > 0)) {
|
||||
if ($notice_info && ($notice_info->length > 0)) {
|
||||
foreach ($notice_info->item(0)->attributes AS $attributes) {
|
||||
if ($attributes->name == "source") {
|
||||
$item["app"] = strip_tags($attributes->textContent);
|
||||
|
@ -2378,9 +2434,9 @@ class dfrn {
|
|||
}
|
||||
}
|
||||
|
||||
if (($term != "") AND ($scheme != "")) {
|
||||
if (($term != "") && ($scheme != "")) {
|
||||
$parts = explode(":", $scheme);
|
||||
if ((count($parts) >= 4) AND (array_shift($parts) == "X-DFRN")) {
|
||||
if ((count($parts) >= 4) && (array_shift($parts) == "X-DFRN")) {
|
||||
$termhash = array_shift($parts);
|
||||
$termurl = implode(":", $parts);
|
||||
|
||||
|
@ -2440,7 +2496,7 @@ class dfrn {
|
|||
$item["contact-id"] = $owner["contact-id"];
|
||||
}
|
||||
|
||||
if (($item["network"] != $owner["network"]) AND ($owner["network"] != "")) {
|
||||
if (($item["network"] != $owner["network"]) && ($owner["network"] != "")) {
|
||||
$item["network"] = $owner["network"];
|
||||
}
|
||||
|
||||
|
@ -2448,7 +2504,7 @@ class dfrn {
|
|||
$item["contact-id"] = $author["contact-id"];
|
||||
}
|
||||
|
||||
if (($item["network"] != $author["network"]) AND ($author["network"] != "")) {
|
||||
if (($item["network"] != $author["network"]) && ($author["network"] != "")) {
|
||||
$item["network"] = $author["network"];
|
||||
}
|
||||
|
||||
|
@ -2548,7 +2604,7 @@ class dfrn {
|
|||
);
|
||||
}
|
||||
|
||||
if ($posted_id AND $parent AND ($entrytype == DFRN_REPLY_RC)) {
|
||||
if ($posted_id && $parent && ($entrytype == DFRN_REPLY_RC)) {
|
||||
logger("Notifying followers about comment ".$posted_id, LOGGER_DEBUG);
|
||||
proc_run(PRIORITY_HIGH, "include/notifier.php", "comment-import", $posted_id);
|
||||
}
|
||||
|
@ -2613,7 +2669,7 @@ class dfrn {
|
|||
$when = datetime_convert("UTC", "UTC", "now", "Y-m-d H:i:s");
|
||||
}
|
||||
|
||||
if (!$uri OR !$importer["id"]) {
|
||||
if (!$uri || !$importer["id"]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -2688,7 +2744,7 @@ class dfrn {
|
|||
if ($entrytype == DFRN_TOP_LEVEL) {
|
||||
$r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s',
|
||||
`body` = '', `title` = ''
|
||||
WHERE `parent-uri` = '%s' AND `uid` = %d",
|
||||
WHERE `parent-uri` = '%s' AND `uid` IN (0, %d)",
|
||||
dbesc($when),
|
||||
dbesc(datetime_convert()),
|
||||
dbesc($uri),
|
||||
|
@ -2700,7 +2756,7 @@ class dfrn {
|
|||
} else {
|
||||
$r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s',
|
||||
`body` = '', `title` = ''
|
||||
WHERE `uri` = '%s' AND `uid` = %d",
|
||||
WHERE `uri` = '%s' AND `uid` IN (0, %d)",
|
||||
dbesc($when),
|
||||
dbesc(datetime_convert()),
|
||||
dbesc($uri),
|
||||
|
@ -2711,7 +2767,7 @@ class dfrn {
|
|||
update_thread_uri($uri, $importer["importer_uid"]);
|
||||
if ($item["last-child"]) {
|
||||
// ensure that last-child is set in case the comment that had it just got wiped.
|
||||
q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d ",
|
||||
q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` IN (0, %d)",
|
||||
dbesc(datetime_convert()),
|
||||
dbesc($item["parent-uri"]),
|
||||
intval($item["uid"])
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
* @brief The implementation of the diaspora protocol
|
||||
*
|
||||
* The new protocol is described here: http://diaspora.github.io/diaspora_federation/index.html
|
||||
* Currently this implementation here interprets the old and the new protocol and sends the old one.
|
||||
* This will change in the future.
|
||||
* This implementation here interprets the old and the new protocol and sends the new one.
|
||||
* In the future we will remove most stuff from "valid_posting" and interpret only the new protocol.
|
||||
*/
|
||||
|
||||
use Friendica\App;
|
||||
|
@ -416,7 +416,7 @@ class Diaspora {
|
|||
$fields = $postdata['fields'];
|
||||
|
||||
// Is it a an action (comment, like, ...) for our own post?
|
||||
if (isset($fields->parent_guid) AND !$postdata["relayed"]) {
|
||||
if (isset($fields->parent_guid) && !$postdata["relayed"]) {
|
||||
$guid = notags(unxmlify($fields->parent_guid));
|
||||
$importer = self::importer_for_guid($guid);
|
||||
if (is_array($importer)) {
|
||||
|
@ -612,9 +612,9 @@ class Diaspora {
|
|||
}
|
||||
}
|
||||
|
||||
if (($fieldname == "author_signature") AND ($entry != ""))
|
||||
if (($fieldname == "author_signature") && ($entry != ""))
|
||||
$author_signature = base64_decode($entry);
|
||||
elseif (($fieldname == "parent_author_signature") AND ($entry != ""))
|
||||
elseif (($fieldname == "parent_author_signature") && ($entry != ""))
|
||||
$parent_author_signature = base64_decode($entry);
|
||||
elseif (!in_array($fieldname, array("author_signature", "parent_author_signature", "target_author_signature"))) {
|
||||
if ($signed_data != "") {
|
||||
|
@ -624,7 +624,7 @@ class Diaspora {
|
|||
|
||||
$signed_data .= $entry;
|
||||
}
|
||||
if (!in_array($fieldname, array("parent_author_signature", "target_author_signature")) OR
|
||||
if (!in_array($fieldname, array("parent_author_signature", "target_author_signature")) ||
|
||||
($orig_type == "relayable_retraction"))
|
||||
xml::copy($entry, $fields, $fieldname);
|
||||
}
|
||||
|
@ -714,13 +714,13 @@ class Diaspora {
|
|||
$update = true;
|
||||
}
|
||||
|
||||
if (!$person OR $update) {
|
||||
if (!$person || $update) {
|
||||
logger("create or refresh", LOGGER_DEBUG);
|
||||
$r = probe_url($handle, PROBE_DIASPORA);
|
||||
|
||||
// Note that Friendica contacts will return a "Diaspora person"
|
||||
// if Diaspora connectivity is enabled on their server
|
||||
if ($r AND ($r["network"] === NETWORK_DIASPORA)) {
|
||||
if ($r && ($r["network"] === NETWORK_DIASPORA)) {
|
||||
self::add_fcontact($r, $update);
|
||||
$person = $r;
|
||||
}
|
||||
|
@ -880,11 +880,14 @@ class Diaspora {
|
|||
if (dbm::is_result($r)) {
|
||||
return $r[0];
|
||||
} else {
|
||||
// We haven't found it?
|
||||
// We use another function for it that will possibly create a contact entry
|
||||
/*
|
||||
* We haven't found it?
|
||||
* We use another function for it that will possibly create a contact entry.
|
||||
*/
|
||||
$cid = get_contact($handle, $uid);
|
||||
|
||||
if ($cid > 0) {
|
||||
/// @TODO Contact retrieval should be encapsulated into an "entity" class like `Contact`
|
||||
$r = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1", intval($cid));
|
||||
|
||||
if (dbm::is_result($r)) {
|
||||
|
@ -919,9 +922,11 @@ class Diaspora {
|
|||
*/
|
||||
private static function post_allow($importer, $contact, $is_comment = false) {
|
||||
|
||||
// perhaps we were already sharing with this person. Now they're sharing with us.
|
||||
// That makes us friends.
|
||||
// Normally this should have handled by getting a request - but this could get lost
|
||||
/*
|
||||
* Perhaps we were already sharing with this person. Now they're sharing with us.
|
||||
* That makes us friends.
|
||||
* Normally this should have handled by getting a request - but this could get lost
|
||||
*/
|
||||
if ($contact["rel"] == CONTACT_IS_FOLLOWER && in_array($importer["page-flags"], array(PAGE_FREELOVE))) {
|
||||
q("UPDATE `contact` SET `rel` = %d, `writable` = 1 WHERE `id` = %d AND `uid` = %d",
|
||||
intval(CONTACT_IS_FRIEND),
|
||||
|
@ -934,16 +939,19 @@ class Diaspora {
|
|||
|
||||
// We don't seem to like that person
|
||||
if ($contact["blocked"] || $contact["readonly"] || $contact["archive"]) {
|
||||
// Maybe blocked, don't accept.
|
||||
return false;
|
||||
// We are following this person? Then it is okay
|
||||
// We are following this person?
|
||||
} elseif (($contact["rel"] == CONTACT_IS_SHARING) || ($contact["rel"] == CONTACT_IS_FRIEND)) {
|
||||
// Yes, then it is fine.
|
||||
return true;
|
||||
// Is it a post to a community? That's good
|
||||
// Is it a post to a community?
|
||||
} elseif (($contact["rel"] == CONTACT_IS_FOLLOWER) && ($importer["page-flags"] == PAGE_COMMUNITY)) {
|
||||
// That's good
|
||||
return true;
|
||||
}
|
||||
// Messages for the global users and comments are always accepted
|
||||
if (($importer["uid"] == 0) || $is_comment) {
|
||||
// Is the message a global user or a comment?
|
||||
} elseif (($importer["uid"] == 0) || $is_comment) {
|
||||
// Messages for the global users and comments are always accepted
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1143,7 +1151,7 @@ class Diaspora {
|
|||
// Fetch the author - for the old and the new Diaspora version
|
||||
if ($source_xml->post->status_message->diaspora_handle)
|
||||
$author = (string)$source_xml->post->status_message->diaspora_handle;
|
||||
elseif ($source_xml->author AND ($source_xml->getName() == "status_message"))
|
||||
elseif ($source_xml->author && ($source_xml->getName() == "status_message"))
|
||||
$author = (string)$source_xml->author;
|
||||
|
||||
// If this isn't a "status_message" then quit
|
||||
|
@ -1463,7 +1471,7 @@ class Diaspora {
|
|||
}
|
||||
|
||||
// If we are the origin of the parent we store the original data and notify our followers
|
||||
if ($message_id AND $parent_item["origin"]) {
|
||||
if ($message_id && $parent_item["origin"]) {
|
||||
|
||||
// Formerly we stored the signed text, the signature and the author in different fields.
|
||||
// We now store the raw data so that we are more flexible.
|
||||
|
@ -1521,6 +1529,8 @@ class Diaspora {
|
|||
|
||||
$person = self::person_by_handle($msg_author);
|
||||
|
||||
dba::lock('mail');
|
||||
|
||||
$r = q("SELECT `id` FROM `mail` WHERE `guid` = '%s' AND `uid` = %d LIMIT 1",
|
||||
dbesc($msg_guid),
|
||||
intval($importer["uid"])
|
||||
|
@ -1548,6 +1558,8 @@ class Diaspora {
|
|||
dbesc($msg_created_at)
|
||||
);
|
||||
|
||||
dba::unlock();
|
||||
|
||||
q("UPDATE `conv` SET `updated` = '%s' WHERE `id` = %d",
|
||||
dbesc(datetime_convert()),
|
||||
intval($conversation["id"])
|
||||
|
@ -1767,7 +1779,7 @@ class Diaspora {
|
|||
}
|
||||
|
||||
// If we are the origin of the parent we store the original data and notify our followers
|
||||
if ($message_id AND $parent_item["origin"]) {
|
||||
if ($message_id && $parent_item["origin"]) {
|
||||
|
||||
// Formerly we stored the signed text, the signature and the author in different fields.
|
||||
// We now store the raw data so that we are more flexible.
|
||||
|
@ -1824,6 +1836,12 @@ class Diaspora {
|
|||
return false;
|
||||
}
|
||||
|
||||
$body = diaspora2bb($text);
|
||||
|
||||
$body = self::replace_people_guid($body, $person["url"]);
|
||||
|
||||
dba::lock('mail');
|
||||
|
||||
$r = q("SELECT `id` FROM `mail` WHERE `guid` = '%s' AND `uid` = %d LIMIT 1",
|
||||
dbesc($guid),
|
||||
intval($importer["uid"])
|
||||
|
@ -1833,10 +1851,6 @@ class Diaspora {
|
|||
return false;
|
||||
}
|
||||
|
||||
$body = diaspora2bb($text);
|
||||
|
||||
$body = self::replace_people_guid($body, $person["url"]);
|
||||
|
||||
q("INSERT INTO `mail` (`uid`, `guid`, `convid`, `from-name`,`from-photo`,`from-url`,`contact-id`,`title`,`body`,`seen`,`reply`,`uri`,`parent-uri`,`created`)
|
||||
VALUES ( %d, '%s', %d, '%s', '%s', '%s', %d, '%s', '%s', %d, %d, '%s','%s','%s')",
|
||||
intval($importer["uid"]),
|
||||
|
@ -1855,6 +1869,8 @@ class Diaspora {
|
|||
dbesc($created_at)
|
||||
);
|
||||
|
||||
dba::unlock();
|
||||
|
||||
q("UPDATE `conv` SET `updated` = '%s' WHERE `id` = %d",
|
||||
dbesc(datetime_convert()),
|
||||
intval($conversation["id"])
|
||||
|
@ -2116,7 +2132,7 @@ class Diaspora {
|
|||
// perhaps we were already sharing with this person. Now they're sharing with us.
|
||||
// That makes us friends.
|
||||
if ($contact) {
|
||||
if ($following AND $sharing) {
|
||||
if ($following && $sharing) {
|
||||
logger("Author ".$author." (Contact ".$contact["id"].") wants to have a bidirectional conection.", LOGGER_DEBUG);
|
||||
self::receive_request_make_friend($importer, $contact);
|
||||
|
||||
|
@ -2139,17 +2155,17 @@ class Diaspora {
|
|||
}
|
||||
}
|
||||
|
||||
if (!$following AND $sharing AND in_array($importer["page-flags"], array(PAGE_SOAPBOX, PAGE_NORMAL))) {
|
||||
if (!$following && $sharing && in_array($importer["page-flags"], array(PAGE_SOAPBOX, PAGE_NORMAL))) {
|
||||
logger("Author ".$author." wants to share with us - but doesn't want to listen. Request is ignored.", LOGGER_DEBUG);
|
||||
return false;
|
||||
} elseif (!$following AND !$sharing) {
|
||||
} elseif (!$following && !$sharing) {
|
||||
logger("Author ".$author." doesn't want anything - and we don't know the author. Request is ignored.", LOGGER_DEBUG);
|
||||
return false;
|
||||
} elseif (!$following AND $sharing) {
|
||||
} elseif (!$following && $sharing) {
|
||||
logger("Author ".$author." wants to share with us.", LOGGER_DEBUG);
|
||||
} elseif ($following AND $sharing) {
|
||||
} elseif ($following && $sharing) {
|
||||
logger("Author ".$author." wants to have a bidirectional conection.", LOGGER_DEBUG);
|
||||
} elseif ($following AND !$sharing) {
|
||||
} elseif ($following && !$sharing) {
|
||||
logger("Author ".$author." wants to listen to us.", LOGGER_DEBUG);
|
||||
}
|
||||
|
||||
|
@ -2227,9 +2243,9 @@ class Diaspora {
|
|||
// but if our page-type is PAGE_COMMUNITY or PAGE_SOAPBOX
|
||||
// we are going to change the relationship and make them a follower.
|
||||
|
||||
if (($importer["page-flags"] == PAGE_FREELOVE) AND $sharing AND $following)
|
||||
if (($importer["page-flags"] == PAGE_FREELOVE) && $sharing && $following)
|
||||
$new_relation = CONTACT_IS_FRIEND;
|
||||
elseif (($importer["page-flags"] == PAGE_FREELOVE) AND $sharing)
|
||||
elseif (($importer["page-flags"] == PAGE_FREELOVE) && $sharing)
|
||||
$new_relation = CONTACT_IS_SHARING;
|
||||
else
|
||||
$new_relation = CONTACT_IS_FOLLOWER;
|
||||
|
@ -2452,7 +2468,7 @@ class Diaspora {
|
|||
intval($r[0]["parent"]));
|
||||
|
||||
// Only delete it if the parent author really fits
|
||||
if (!link_compare($p[0]["author-link"], $contact["url"]) AND !link_compare($r[0]["author-link"], $contact["url"])) {
|
||||
if (!link_compare($p[0]["author-link"], $contact["url"]) && !link_compare($r[0]["author-link"], $contact["url"])) {
|
||||
logger("Thread author ".$p[0]["author-link"]." and item author ".$r[0]["author-link"]." don't fit to expected contact ".$contact["url"], LOGGER_DEBUG);
|
||||
return false;
|
||||
}
|
||||
|
@ -2489,7 +2505,7 @@ class Diaspora {
|
|||
$target_type = notags(unxmlify($data->target_type));
|
||||
|
||||
$contact = self::contact_by_handle($importer["uid"], $sender);
|
||||
if (!$contact AND (in_array($target_type, array("Contact", "Person")))) {
|
||||
if (!$contact && (in_array($target_type, array("Contact", "Person")))) {
|
||||
logger("cannot find contact for sender: ".$sender." and user ".$importer["uid"]);
|
||||
return false;
|
||||
}
|
||||
|
@ -2499,7 +2515,7 @@ class Diaspora {
|
|||
switch ($target_type) {
|
||||
case "Comment":
|
||||
case "Like":
|
||||
case "Post": // "Post" will be supported in a future version
|
||||
case "Post":
|
||||
case "Reshare":
|
||||
case "StatusMessage":
|
||||
return self::item_retraction($importer, $contact, $data);
|
||||
|
@ -2617,7 +2633,7 @@ class Diaspora {
|
|||
$datarray["location"] = $address["address"];
|
||||
}
|
||||
|
||||
if (isset($address["lat"]) AND isset($address["lng"])) {
|
||||
if (isset($address["lat"]) && isset($address["lng"])) {
|
||||
$datarray["coord"] = $address["lat"]." ".$address["lng"];
|
||||
}
|
||||
|
||||
|
@ -2659,15 +2675,54 @@ class Diaspora {
|
|||
return $nick."@".substr(App::get_baseurl(), strpos(App::get_baseurl(),"://") + 3);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Creates the envelope for the "fetch" endpoint
|
||||
* @brief Creates the data for a private message in the new format
|
||||
*
|
||||
* @param string $msg The message that is to be transmitted
|
||||
* @param array $user The record of the sender
|
||||
* @param array $contact Target of the communication
|
||||
* @param string $prvkey The private key of the sender
|
||||
* @param string $pubkey The public key of the receiver
|
||||
*
|
||||
* @return string The encrypted data
|
||||
*/
|
||||
public static function encode_private_data($msg, $user, $contact, $prvkey, $pubkey) {
|
||||
|
||||
logger("Message: ".$msg, LOGGER_DATA);
|
||||
|
||||
// without a public key nothing will work
|
||||
if (!$pubkey) {
|
||||
logger("pubkey missing: contact id: ".$contact["id"]);
|
||||
return false;
|
||||
}
|
||||
|
||||
$aes_key = openssl_random_pseudo_bytes(32);
|
||||
$b_aes_key = base64_encode($aes_key);
|
||||
$iv = openssl_random_pseudo_bytes(16);
|
||||
$b_iv = base64_encode($iv);
|
||||
|
||||
$ciphertext = self::aes_encrypt($aes_key, $iv, $msg);
|
||||
|
||||
$json = json_encode(array("iv" => $b_iv, "key" => $b_aes_key));
|
||||
|
||||
$encrypted_key_bundle = "";
|
||||
openssl_public_encrypt($json, $encrypted_key_bundle, $pubkey);
|
||||
|
||||
$json_object = json_encode(array("aes_key" => base64_encode($encrypted_key_bundle),
|
||||
"encrypted_magic_envelope" => base64_encode($ciphertext)));
|
||||
|
||||
return $json_object;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Creates the envelope for the "fetch" endpoint and for the new format
|
||||
*
|
||||
* @param string $msg The message that is to be transmitted
|
||||
* @param array $user The record of the sender
|
||||
*
|
||||
* @return string The envelope
|
||||
*/
|
||||
|
||||
public static function build_magic_envelope($msg, $user) {
|
||||
|
||||
$b64url_data = base64url_encode($msg);
|
||||
|
@ -2678,7 +2733,12 @@ class Diaspora {
|
|||
$encoding = "base64url";
|
||||
$alg = "RSA-SHA256";
|
||||
$signable_data = $data.".".base64url_encode($type).".".base64url_encode($encoding).".".base64url_encode($alg);
|
||||
$signature = rsa_sign($signable_data, $user["prvkey"]);
|
||||
|
||||
// Fallback if the private key wasn't transmitted in the expected field
|
||||
if ($user['uprvkey'] == "")
|
||||
$user['uprvkey'] = $user['prvkey'];
|
||||
|
||||
$signature = rsa_sign($signable_data, $user["uprvkey"]);
|
||||
$sig = base64url_encode($signature);
|
||||
|
||||
$xmldata = array("me:env" => array("me:data" => $data,
|
||||
|
@ -2693,140 +2753,6 @@ class Diaspora {
|
|||
return xml::from_array($xmldata, $xml, false, $namespaces);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Creates the envelope for a public message
|
||||
*
|
||||
* @param string $msg The message that is to be transmitted
|
||||
* @param array $user The record of the sender
|
||||
* @param array $contact Target of the communication
|
||||
* @param string $prvkey The private key of the sender
|
||||
* @param string $pubkey The public key of the receiver
|
||||
*
|
||||
* @return string The envelope
|
||||
*/
|
||||
private static function build_public_message($msg, $user, $contact, $prvkey, $pubkey) {
|
||||
|
||||
logger("Message: ".$msg, LOGGER_DATA);
|
||||
|
||||
$handle = self::my_handle($user);
|
||||
|
||||
$b64url_data = base64url_encode($msg);
|
||||
|
||||
$data = str_replace(array("\n", "\r", " ", "\t"), array("", "", "", ""), $b64url_data);
|
||||
|
||||
$type = "application/xml";
|
||||
$encoding = "base64url";
|
||||
$alg = "RSA-SHA256";
|
||||
|
||||
$signable_data = $data.".".base64url_encode($type).".".base64url_encode($encoding).".".base64url_encode($alg);
|
||||
|
||||
$signature = rsa_sign($signable_data,$prvkey);
|
||||
$sig = base64url_encode($signature);
|
||||
|
||||
$xmldata = array("diaspora" => array("header" => array("author_id" => $handle),
|
||||
"me:env" => array("me:encoding" => $encoding,
|
||||
"me:alg" => $alg,
|
||||
"me:data" => $data,
|
||||
"@attributes" => array("type" => $type),
|
||||
"me:sig" => $sig)));
|
||||
|
||||
$namespaces = array("" => "https://joindiaspora.com/protocol",
|
||||
"me" => "http://salmon-protocol.org/ns/magic-env");
|
||||
|
||||
$magic_env = xml::from_array($xmldata, $xml, false, $namespaces);
|
||||
|
||||
logger("magic_env: ".$magic_env, LOGGER_DATA);
|
||||
return $magic_env;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Creates the envelope for a private message
|
||||
*
|
||||
* @param string $msg The message that is to be transmitted
|
||||
* @param array $user The record of the sender
|
||||
* @param array $contact Target of the communication
|
||||
* @param string $prvkey The private key of the sender
|
||||
* @param string $pubkey The public key of the receiver
|
||||
*
|
||||
* @return string The envelope
|
||||
*/
|
||||
private static function build_private_message($msg, $user, $contact, $prvkey, $pubkey) {
|
||||
|
||||
logger("Message: ".$msg, LOGGER_DATA);
|
||||
|
||||
// without a public key nothing will work
|
||||
|
||||
if (!$pubkey) {
|
||||
logger("pubkey missing: contact id: ".$contact["id"]);
|
||||
return false;
|
||||
}
|
||||
|
||||
$inner_aes_key = openssl_random_pseudo_bytes(32);
|
||||
$b_inner_aes_key = base64_encode($inner_aes_key);
|
||||
$inner_iv = openssl_random_pseudo_bytes(16);
|
||||
$b_inner_iv = base64_encode($inner_iv);
|
||||
|
||||
$outer_aes_key = openssl_random_pseudo_bytes(32);
|
||||
$b_outer_aes_key = base64_encode($outer_aes_key);
|
||||
$outer_iv = openssl_random_pseudo_bytes(16);
|
||||
$b_outer_iv = base64_encode($outer_iv);
|
||||
|
||||
$handle = self::my_handle($user);
|
||||
|
||||
$inner_encrypted = self::aes_encrypt($inner_aes_key, $inner_iv, $msg);
|
||||
|
||||
$b64_data = base64_encode($inner_encrypted);
|
||||
|
||||
|
||||
$b64url_data = base64url_encode($b64_data);
|
||||
$data = str_replace(array("\n", "\r", " ", "\t"), array("", "", "", ""), $b64url_data);
|
||||
|
||||
$type = "application/xml";
|
||||
$encoding = "base64url";
|
||||
$alg = "RSA-SHA256";
|
||||
|
||||
$signable_data = $data.".".base64url_encode($type).".".base64url_encode($encoding).".".base64url_encode($alg);
|
||||
|
||||
$signature = rsa_sign($signable_data,$prvkey);
|
||||
$sig = base64url_encode($signature);
|
||||
|
||||
$xmldata = array("decrypted_header" => array("iv" => $b_inner_iv,
|
||||
"aes_key" => $b_inner_aes_key,
|
||||
"author_id" => $handle));
|
||||
|
||||
$decrypted_header = xml::from_array($xmldata, $xml, true);
|
||||
|
||||
$ciphertext = self::aes_encrypt($outer_aes_key, $outer_iv, $decrypted_header);
|
||||
|
||||
$outer_json = json_encode(array("iv" => $b_outer_iv, "key" => $b_outer_aes_key));
|
||||
|
||||
$encrypted_outer_key_bundle = "";
|
||||
openssl_public_encrypt($outer_json, $encrypted_outer_key_bundle, $pubkey);
|
||||
|
||||
$b64_encrypted_outer_key_bundle = base64_encode($encrypted_outer_key_bundle);
|
||||
|
||||
logger("outer_bundle: ".$b64_encrypted_outer_key_bundle." key: ".$pubkey, LOGGER_DATA);
|
||||
|
||||
$encrypted_header_json_object = json_encode(array("aes_key" => base64_encode($encrypted_outer_key_bundle),
|
||||
"ciphertext" => base64_encode($ciphertext)));
|
||||
$cipher_json = base64_encode($encrypted_header_json_object);
|
||||
|
||||
$xmldata = array("diaspora" => array("encrypted_header" => $cipher_json,
|
||||
"me:env" => array("me:encoding" => $encoding,
|
||||
"me:alg" => $alg,
|
||||
"me:data" => $data,
|
||||
"@attributes" => array("type" => $type),
|
||||
"me:sig" => $sig)));
|
||||
|
||||
$namespaces = array("" => "https://joindiaspora.com/protocol",
|
||||
"me" => "http://salmon-protocol.org/ns/magic-env");
|
||||
|
||||
$magic_env = xml::from_array($xmldata, $xml, false, $namespaces);
|
||||
|
||||
logger("magic_env: ".$magic_env, LOGGER_DATA);
|
||||
return $magic_env;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Create the envelope for a message
|
||||
*
|
||||
|
@ -2841,14 +2767,15 @@ class Diaspora {
|
|||
*/
|
||||
private static function build_message($msg, $user, $contact, $prvkey, $pubkey, $public = false) {
|
||||
|
||||
if ($public)
|
||||
$magic_env = self::build_public_message($msg,$user,$contact,$prvkey,$pubkey);
|
||||
else
|
||||
$magic_env = self::build_private_message($msg,$user,$contact,$prvkey,$pubkey);
|
||||
// The message is put into an envelope with the sender's signature
|
||||
$envelope = self::build_magic_envelope($msg, $user);
|
||||
|
||||
// The data that will be transmitted is double encoded via "urlencode", strange ...
|
||||
$slap = "xml=".urlencode(urlencode($magic_env));
|
||||
return $slap;
|
||||
// Private messages are put into a second envelope, encrypted with the receivers public key
|
||||
if (!$public) {
|
||||
$envelope = self::encode_private_data($envelope, $user, $contact, $prvkey, $pubkey);
|
||||
}
|
||||
|
||||
return $envelope;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2874,14 +2801,14 @@ class Diaspora {
|
|||
*
|
||||
* @param array $owner the array of the item owner
|
||||
* @param array $contact Target of the communication
|
||||
* @param string $slap The message that is to be transmitted
|
||||
* @param string $envelope The message that is to be transmitted
|
||||
* @param bool $public_batch Is it a public post?
|
||||
* @param bool $queue_run Is the transmission called from the queue?
|
||||
* @param string $guid message guid
|
||||
*
|
||||
* @return int Result of the transmission
|
||||
*/
|
||||
public static function transmit($owner, $contact, $slap, $public_batch, $queue_run=false, $guid = "") {
|
||||
public static function transmit($owner, $contact, $envelope, $public_batch, $queue_run=false, $guid = "") {
|
||||
|
||||
$a = get_app();
|
||||
|
||||
|
@ -2902,7 +2829,9 @@ class Diaspora {
|
|||
$return_code = 0;
|
||||
} else {
|
||||
if (!intval(get_config("system", "diaspora_test"))) {
|
||||
post_url($dest_url."/", $slap);
|
||||
$content_type = (($public_batch) ? "application/magic-envelope+xml" : "application/json");
|
||||
|
||||
post_url($dest_url."/", $envelope, array("Content-Type: ".$content_type));
|
||||
$return_code = $a->get_curl_code();
|
||||
} else {
|
||||
logger("test_mode");
|
||||
|
@ -2918,19 +2847,19 @@ class Diaspora {
|
|||
$r = q("SELECT `id` FROM `queue` WHERE `cid` = %d AND `network` = '%s' AND `content` = '%s' AND `batch` = %d LIMIT 1",
|
||||
intval($contact["id"]),
|
||||
dbesc(NETWORK_DIASPORA),
|
||||
dbesc($slap),
|
||||
dbesc($envelope),
|
||||
intval($public_batch)
|
||||
);
|
||||
if ($r) {
|
||||
logger("add_to_queue ignored - identical item already in queue");
|
||||
} else {
|
||||
// queue message for redelivery
|
||||
add_to_queue($contact["id"], NETWORK_DIASPORA, $slap, $public_batch);
|
||||
add_to_queue($contact["id"], NETWORK_DIASPORA, $envelope, $public_batch);
|
||||
|
||||
// The message could not be delivered. We mark the contact as "dead"
|
||||
mark_for_death($contact);
|
||||
}
|
||||
} elseif (($return_code >= 200) AND ($return_code <= 299)) {
|
||||
} elseif (($return_code >= 200) && ($return_code <= 299)) {
|
||||
// We successfully delivered a message, the contact is alive
|
||||
unmark_for_death($contact);
|
||||
}
|
||||
|
@ -2949,7 +2878,8 @@ class Diaspora {
|
|||
*/
|
||||
public static function build_post_xml($type, $message) {
|
||||
|
||||
$data = array("XML" => array("post" => array($type => $message)));
|
||||
$data = array($type => $message);
|
||||
|
||||
return xml::from_array($data, $xml);
|
||||
}
|
||||
|
||||
|
@ -2977,13 +2907,13 @@ class Diaspora {
|
|||
if ($owner['uprvkey'] == "")
|
||||
$owner['uprvkey'] = $owner['prvkey'];
|
||||
|
||||
$slap = self::build_message($msg, $owner, $contact, $owner['uprvkey'], $contact['pubkey'], $public_batch);
|
||||
$envelope = self::build_message($msg, $owner, $contact, $owner['uprvkey'], $contact['pubkey'], $public_batch);
|
||||
|
||||
if ($spool) {
|
||||
add_to_queue($contact['id'], NETWORK_DIASPORA, $slap, $public_batch);
|
||||
add_to_queue($contact['id'], NETWORK_DIASPORA, $envelope, $public_batch);
|
||||
return true;
|
||||
} else
|
||||
$return_code = self::transmit($owner, $contact, $slap, $public_batch, false, $guid);
|
||||
$return_code = self::transmit($owner, $contact, $envelope, $public_batch, false, $guid);
|
||||
|
||||
logger("guid: ".$item["guid"]." result ".$return_code, LOGGER_DEBUG);
|
||||
|
||||
|
@ -2998,14 +2928,37 @@ class Diaspora {
|
|||
*
|
||||
* @return int The result of the transmission
|
||||
*/
|
||||
public static function send_share($owner,$contact) {
|
||||
public static function send_share($owner, $contact) {
|
||||
|
||||
$message = array("sender_handle" => self::my_handle($owner),
|
||||
"recipient_handle" => $contact["addr"]);
|
||||
/**
|
||||
* @todo support the different possible combinations of "following" and "sharing"
|
||||
* Currently, Diaspora only interprets the "sharing" field
|
||||
*
|
||||
* Before switching this code productive, we have to check all "send_share" calls if "rel" is set correctly
|
||||
*/
|
||||
|
||||
/*
|
||||
switch ($contact["rel"]) {
|
||||
case CONTACT_IS_FRIEND:
|
||||
$following = true;
|
||||
$sharing = true;
|
||||
case CONTACT_IS_SHARING:
|
||||
$following = false;
|
||||
$sharing = true;
|
||||
case CONTACT_IS_FOLLOWER:
|
||||
$following = true;
|
||||
$sharing = false;
|
||||
}
|
||||
*/
|
||||
|
||||
$message = array("author" => self::my_handle($owner),
|
||||
"recipient" => $contact["addr"],
|
||||
"following" => "true",
|
||||
"sharing" => "true");
|
||||
|
||||
logger("Send share ".print_r($message, true), LOGGER_DEBUG);
|
||||
|
||||
return self::build_and_transmit($owner, $contact, "request", $message);
|
||||
return self::build_and_transmit($owner, $contact, "contact", $message);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3016,15 +2969,16 @@ class Diaspora {
|
|||
*
|
||||
* @return int The result of the transmission
|
||||
*/
|
||||
public static function send_unshare($owner,$contact) {
|
||||
public static function send_unshare($owner, $contact) {
|
||||
|
||||
$message = array("post_guid" => $owner["guid"],
|
||||
"diaspora_handle" => self::my_handle($owner),
|
||||
"type" => "Person");
|
||||
$message = array("author" => self::my_handle($owner),
|
||||
"recipient" => $contact["addr"],
|
||||
"following" => "false",
|
||||
"sharing" => "false");
|
||||
|
||||
logger("Send unshare ".print_r($message, true), LOGGER_DEBUG);
|
||||
|
||||
return self::build_and_transmit($owner, $contact, "retraction", $message);
|
||||
return self::build_and_transmit($owner, $contact, "contact", $message);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3040,7 +2994,7 @@ class Diaspora {
|
|||
|
||||
// Skip if it isn't a pure repeated messages
|
||||
// Does it start with a share?
|
||||
if ((strpos($body, "[share") > 0) AND $complete)
|
||||
if ((strpos($body, "[share") > 0) && $complete)
|
||||
return(false);
|
||||
|
||||
// Does it end with a share?
|
||||
|
@ -3088,7 +3042,7 @@ class Diaspora {
|
|||
$ret= array();
|
||||
|
||||
$ret["root_handle"] = preg_replace("=https?://(.*)/u/(.*)=ism", "$2@$1", $profile);
|
||||
if (($ret["root_handle"] == $profile) OR ($ret["root_handle"] == ""))
|
||||
if (($ret["root_handle"] == $profile) || ($ret["root_handle"] == ""))
|
||||
return(false);
|
||||
|
||||
$link = "";
|
||||
|
@ -3101,7 +3055,7 @@ class Diaspora {
|
|||
$link = $matches[1];
|
||||
|
||||
$ret["root_guid"] = preg_replace("=https?://(.*)/posts/(.*)=ism", "$2", $link);
|
||||
if (($ret["root_guid"] == $link) OR (trim($ret["root_guid"]) == ""))
|
||||
if (($ret["root_guid"] == $link) || (trim($ret["root_guid"]) == ""))
|
||||
return(false);
|
||||
|
||||
return($ret);
|
||||
|
@ -3161,7 +3115,7 @@ class Diaspora {
|
|||
if ($event['start']) {
|
||||
$eventdata['start'] = datetime_convert($eventdata['timezone'], "UTC", $event['start'], $mask);
|
||||
}
|
||||
if ($event['finish'] AND !$event['nofinish']) {
|
||||
if ($event['finish'] && !$event['nofinish']) {
|
||||
$eventdata['end'] = datetime_convert($eventdata['timezone'], "UTC", $event['finish'], $mask);
|
||||
}
|
||||
if ($event['summary']) {
|
||||
|
@ -3207,14 +3161,14 @@ class Diaspora {
|
|||
$created = datetime_convert("UTC", "UTC", $item["created"], 'Y-m-d\TH:i:s\Z');
|
||||
|
||||
// Detect a share element and do a reshare
|
||||
if (!$item['private'] AND ($ret = self::is_reshare($item["body"]))) {
|
||||
$message = array("root_diaspora_id" => $ret["root_handle"],
|
||||
"root_guid" => $ret["root_guid"],
|
||||
if (!$item['private'] && ($ret = self::is_reshare($item["body"]))) {
|
||||
$message = array("author" => $myaddr,
|
||||
"guid" => $item["guid"],
|
||||
"diaspora_handle" => $myaddr,
|
||||
"public" => $public,
|
||||
"created_at" => $created,
|
||||
"provider_display_name" => $item["app"]);
|
||||
"root_author" => $ret["root_handle"],
|
||||
"root_guid" => $ret["root_guid"],
|
||||
"provider_display_name" => $item["app"],
|
||||
"public" => $public);
|
||||
|
||||
$type = "reshare";
|
||||
} else {
|
||||
|
@ -3248,16 +3202,16 @@ class Diaspora {
|
|||
$location["lng"] = $coord[1];
|
||||
}
|
||||
|
||||
$message = array("raw_message" => $body,
|
||||
"location" => $location,
|
||||
$message = array("author" => $myaddr,
|
||||
"guid" => $item["guid"],
|
||||
"diaspora_handle" => $myaddr,
|
||||
"public" => $public,
|
||||
"created_at" => $created,
|
||||
"provider_display_name" => $item["app"]);
|
||||
"public" => $public,
|
||||
"text" => $body,
|
||||
"provider_display_name" => $item["app"],
|
||||
"location" => $location);
|
||||
|
||||
// Diaspora rejects messages when they contain a location without "lat" or "lng"
|
||||
if (!isset($location["lat"]) OR !isset($location["lng"])) {
|
||||
if (!isset($location["lat"]) || !isset($location["lng"])) {
|
||||
unset($message["location"]);
|
||||
}
|
||||
|
||||
|
@ -3267,7 +3221,7 @@ class Diaspora {
|
|||
$message['event'] = $event;
|
||||
|
||||
/// @todo Once Diaspora supports it, we will remove the body
|
||||
// $message['raw_message'] = '';
|
||||
// $message['text'] = '';
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3322,12 +3276,12 @@ class Diaspora {
|
|||
$positive = "false";
|
||||
}
|
||||
|
||||
return(array("positive" => $positive,
|
||||
return(array("author" => self::my_handle($owner),
|
||||
"guid" => $item["guid"],
|
||||
"target_type" => $target_type,
|
||||
"parent_guid" => $parent["guid"],
|
||||
"author_signature" => "",
|
||||
"diaspora_handle" => self::my_handle($owner)));
|
||||
"parent_type" => $target_type,
|
||||
"positive" => $positive,
|
||||
"author_signature" => ""));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3399,12 +3353,12 @@ class Diaspora {
|
|||
$text = html_entity_decode(bb2diaspora($item["body"]));
|
||||
$created = datetime_convert("UTC", "UTC", $item["created"], 'Y-m-d\TH:i:s\Z');
|
||||
|
||||
$comment = array("guid" => $item["guid"],
|
||||
$comment = array("author" => self::my_handle($owner),
|
||||
"guid" => $item["guid"],
|
||||
"created_at" => $created,
|
||||
"parent_guid" => $parent["guid"],
|
||||
"author_signature" => "",
|
||||
"text" => $text,
|
||||
/// @todo Currently disabled until Diaspora supports it: "created_at" => $created,
|
||||
"diaspora_handle" => self::my_handle($owner));
|
||||
"author_signature" => "");
|
||||
|
||||
// Send the thread parent guid only if it is a threaded comment
|
||||
if ($item['thr-parent'] != $item['parent-uri']) {
|
||||
|
@ -3461,19 +3415,17 @@ class Diaspora {
|
|||
$signed_parts = explode(";", $signature['signed_text']);
|
||||
|
||||
if ($item["deleted"])
|
||||
$message = array("parent_author_signature" => "",
|
||||
$message = array("author" => $signature['signer'],
|
||||
"target_guid" => $signed_parts[0],
|
||||
"target_type" => $signed_parts[1],
|
||||
"sender_handle" => $signature['signer'],
|
||||
"target_author_signature" => $signature['signature']);
|
||||
"target_type" => $signed_parts[1]);
|
||||
elseif ($item['verb'] === ACTIVITY_LIKE)
|
||||
$message = array("positive" => $signed_parts[0],
|
||||
$message = array("author" => $signed_parts[4],
|
||||
"guid" => $signed_parts[1],
|
||||
"target_type" => $signed_parts[2],
|
||||
"parent_guid" => $signed_parts[3],
|
||||
"parent_author_signature" => "",
|
||||
"parent_type" => $signed_parts[2],
|
||||
"positive" => $signed_parts[0],
|
||||
"author_signature" => $signature['signature'],
|
||||
"diaspora_handle" => $signed_parts[4]);
|
||||
"parent_author_signature" => "");
|
||||
else {
|
||||
// Remove the comment guid
|
||||
$guid = array_shift($signed_parts);
|
||||
|
@ -3487,12 +3439,12 @@ class Diaspora {
|
|||
// Glue the parts together
|
||||
$text = implode(";", $signed_parts);
|
||||
|
||||
$message = array("guid" => $guid,
|
||||
$message = array("author" => $handle,
|
||||
"guid" => $guid,
|
||||
"parent_guid" => $parent_guid,
|
||||
"parent_author_signature" => "",
|
||||
"author_signature" => $signature['signature'],
|
||||
"text" => implode(";", $signed_parts),
|
||||
"diaspora_handle" => $handle);
|
||||
"author_signature" => $signature['signature'],
|
||||
"parent_author_signature" => "");
|
||||
}
|
||||
return $message;
|
||||
}
|
||||
|
@ -3532,7 +3484,7 @@ class Diaspora {
|
|||
|
||||
// Old way - is used by the internal Friendica functions
|
||||
/// @todo Change all signatur storing functions to the new format
|
||||
if ($signature['signed_text'] AND $signature['signature'] AND $signature['signer'])
|
||||
if ($signature['signed_text'] && $signature['signature'] && $signature['signer'])
|
||||
$message = self::message_from_signature($item, $signature);
|
||||
else {// New way
|
||||
$msg = json_decode($signature['signed_text'], true);
|
||||
|
@ -3541,10 +3493,12 @@ class Diaspora {
|
|||
if (is_array($msg)) {
|
||||
foreach ($msg AS $field => $data) {
|
||||
if (!$item["deleted"]) {
|
||||
if ($field == "author")
|
||||
$field = "diaspora_handle";
|
||||
if ($field == "parent_type")
|
||||
$field = "target_type";
|
||||
if ($field == "diaspora_handle") {
|
||||
$field = "author";
|
||||
}
|
||||
if ($field == "target_type") {
|
||||
$field = "parent_type";
|
||||
}
|
||||
}
|
||||
|
||||
$message[$field] = $data;
|
||||
|
@ -3575,26 +3529,12 @@ class Diaspora {
|
|||
|
||||
$itemaddr = self::handle_from_contact($item["contact-id"], $item["gcontact-id"]);
|
||||
|
||||
// Check whether the retraction is for a top-level post or whether it's a relayable
|
||||
if ($item["uri"] !== $item["parent-uri"]) {
|
||||
$msg_type = "relayable_retraction";
|
||||
$target_type = (($item["verb"] === ACTIVITY_LIKE) ? "Like" : "Comment");
|
||||
} else {
|
||||
$msg_type = "signed_retraction";
|
||||
$target_type = "StatusMessage";
|
||||
}
|
||||
$msg_type = "retraction";
|
||||
$target_type = "Post";
|
||||
|
||||
if ($relay AND ($item["uri"] !== $item["parent-uri"]))
|
||||
$signature = "parent_author_signature";
|
||||
else
|
||||
$signature = "target_author_signature";
|
||||
|
||||
$signed_text = $item["guid"].";".$target_type;
|
||||
|
||||
$message = array("target_guid" => $item['guid'],
|
||||
"target_type" => $target_type,
|
||||
"sender_handle" => $itemaddr,
|
||||
$signature => base64_encode(rsa_sign($signed_text,$owner['uprvkey'],'sha256')));
|
||||
$message = array("author" => $itemaddr,
|
||||
"target_guid" => $item['guid'],
|
||||
"target_type" => $target_type);
|
||||
|
||||
logger("Got message ".print_r($message, true), LOGGER_DEBUG);
|
||||
|
||||
|
@ -3626,40 +3566,35 @@ class Diaspora {
|
|||
$cnv = $r[0];
|
||||
|
||||
$conv = array(
|
||||
"author" => $cnv["creator"],
|
||||
"guid" => $cnv["guid"],
|
||||
"subject" => $cnv["subject"],
|
||||
"created_at" => datetime_convert("UTC", "UTC", $cnv['created'], 'Y-m-d\TH:i:s\Z'),
|
||||
"diaspora_handle" => $cnv["creator"],
|
||||
"participant_handles" => $cnv["recips"]
|
||||
"participants" => $cnv["recips"]
|
||||
);
|
||||
|
||||
$body = bb2diaspora($item["body"]);
|
||||
$created = datetime_convert("UTC", "UTC", $item["created"], 'Y-m-d\TH:i:s\Z');
|
||||
|
||||
$signed_text = $item["guid"].";".$cnv["guid"].";".$body.";".$created.";".$myaddr.";".$cnv['guid'];
|
||||
$sig = base64_encode(rsa_sign($signed_text, $owner["uprvkey"], "sha256"));
|
||||
|
||||
$msg = array(
|
||||
"author" => $myaddr,
|
||||
"guid" => $item["guid"],
|
||||
"parent_guid" => $cnv["guid"],
|
||||
"parent_author_signature" => $sig,
|
||||
"author_signature" => $sig,
|
||||
"conversation_guid" => $cnv["guid"],
|
||||
"text" => $body,
|
||||
"created_at" => $created,
|
||||
"diaspora_handle" => $myaddr,
|
||||
"conversation_guid" => $cnv["guid"]
|
||||
);
|
||||
|
||||
if ($item["reply"]) {
|
||||
$message = $msg;
|
||||
$type = "message";
|
||||
} else {
|
||||
$message = array("guid" => $cnv["guid"],
|
||||
$message = array(
|
||||
"author" => $cnv["creator"],
|
||||
"guid" => $cnv["guid"],
|
||||
"subject" => $cnv["subject"],
|
||||
"created_at" => datetime_convert("UTC", "UTC", $cnv['created'], 'Y-m-d\TH:i:s\Z'),
|
||||
"message" => $msg,
|
||||
"diaspora_handle" => $cnv["creator"],
|
||||
"participant_handles" => $cnv["recips"]);
|
||||
"participants" => $cnv["recips"],
|
||||
"message" => $msg);
|
||||
|
||||
$type = "conversation";
|
||||
}
|
||||
|
@ -3734,7 +3669,7 @@ class Diaspora {
|
|||
$tags = trim($tags);
|
||||
}
|
||||
|
||||
$message = array("diaspora_handle" => $handle,
|
||||
$message = array("author" => $handle,
|
||||
"first_name" => $first,
|
||||
"last_name" => $last,
|
||||
"image_url" => $large,
|
||||
|
@ -3745,6 +3680,7 @@ class Diaspora {
|
|||
"bio" => $about,
|
||||
"location" => $location,
|
||||
"searchable" => $searchable,
|
||||
"nsfw" => "false",
|
||||
"tag_string" => $tags);
|
||||
|
||||
foreach ($recips as $recip) {
|
||||
|
@ -3764,7 +3700,7 @@ class Diaspora {
|
|||
public static function store_like_signature($contact, $post_id) {
|
||||
|
||||
// Is the contact the owner? Then fetch the private key
|
||||
if (!$contact['self'] OR ($contact['uid'] == 0)) {
|
||||
if (!$contact['self'] || ($contact['uid'] == 0)) {
|
||||
logger("No owner post, so not storing signature", LOGGER_DEBUG);
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -47,13 +47,12 @@ function discover_poco_run(&$argv, &$argc) {
|
|||
logger('start '.$search);
|
||||
|
||||
if ($mode == 8) {
|
||||
$profile_url = base64_decode($argv[2]);
|
||||
if ($profile_url != "") {
|
||||
poco_last_updated($profile_url, true);
|
||||
if ($argv[2] != "") {
|
||||
poco_last_updated($argv[2], true);
|
||||
}
|
||||
} elseif ($mode == 7) {
|
||||
if ($argc == 6) {
|
||||
$url = base64_decode($argv[5]);
|
||||
$url = $argv[5];
|
||||
} else {
|
||||
$url = '';
|
||||
}
|
||||
|
@ -63,7 +62,7 @@ function discover_poco_run(&$argv, &$argc) {
|
|||
} elseif ($mode == 5) {
|
||||
update_server();
|
||||
} elseif ($mode == 4) {
|
||||
$server_url = base64_decode($argv[2]);
|
||||
$server_url = $argv[2];
|
||||
if ($server_url == "") {
|
||||
return;
|
||||
}
|
||||
|
@ -81,12 +80,12 @@ function discover_poco_run(&$argv, &$argc) {
|
|||
logger($result, LOGGER_DEBUG);
|
||||
} elseif ($mode == 3) {
|
||||
update_suggestions();
|
||||
} elseif (($mode == 2) AND get_config('system','poco_completion')) {
|
||||
} elseif (($mode == 2) && get_config('system','poco_completion')) {
|
||||
discover_users();
|
||||
} elseif (($mode == 1) AND ($search != "") and get_config('system','poco_local_search')) {
|
||||
} elseif (($mode == 1) && ($search != "") && get_config('system','poco_local_search')) {
|
||||
discover_directory($search);
|
||||
gs_search_user($search);
|
||||
} elseif (($mode == 0) AND ($search == "") and (get_config('system','poco_discovery') > 0)) {
|
||||
} elseif (($mode == 0) && ($search == "") && (get_config('system','poco_discovery') > 0)) {
|
||||
// Query Friendica and Hubzilla servers for their users
|
||||
poco_discover();
|
||||
|
||||
|
@ -119,7 +118,7 @@ function update_server() {
|
|||
}
|
||||
logger('Update server status for server '.$server["url"], LOGGER_DEBUG);
|
||||
|
||||
proc_run(PRIORITY_LOW, "include/discover_poco.php", "server", base64_encode($server["url"]));
|
||||
proc_run(PRIORITY_LOW, "include/discover_poco.php", "server", $server["url"]);
|
||||
|
||||
if (++$updated > 250) {
|
||||
return;
|
||||
|
@ -176,9 +175,9 @@ function discover_users() {
|
|||
$server_url = $user["server_url"];
|
||||
}
|
||||
|
||||
if ((($server_url == "") AND ($user["network"] == NETWORK_FEED)) OR $force_update OR poco_check_server($server_url, $user["network"])) {
|
||||
if ((($server_url == "") && ($user["network"] == NETWORK_FEED)) || $force_update || poco_check_server($server_url, $user["network"])) {
|
||||
logger('Check profile '.$user["url"]);
|
||||
proc_run(PRIORITY_LOW, "include/discover_poco.php", "check_profile", base64_encode($user["url"]));
|
||||
proc_run(PRIORITY_LOW, "include/discover_poco.php", "check_profile", $user["url"]);
|
||||
|
||||
if (++$checked > 100) {
|
||||
return;
|
||||
|
@ -216,7 +215,7 @@ function discover_directory($search) {
|
|||
if (dbm::is_result($exists)) {
|
||||
logger("Profile ".$jj->url." already exists (".$search.")", LOGGER_DEBUG);
|
||||
|
||||
if (($exists[0]["last_contact"] < $exists[0]["last_failure"]) AND
|
||||
if (($exists[0]["last_contact"] < $exists[0]["last_failure"]) &&
|
||||
($exists[0]["updated"] < $exists[0]["last_failure"])) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -152,7 +152,7 @@ function email_get_part($mbox,$uid,$p,$partno, $subtype) {
|
|||
if ($p->parameters)
|
||||
foreach ($p->parameters as $x)
|
||||
$params[strtolower($x->attribute)] = $x->value;
|
||||
if (isset($p->dparameters) and $p->dparameters)
|
||||
if (isset($p->dparameters) && $p->dparameters)
|
||||
foreach ($p->dparameters as $x)
|
||||
$params[strtolower($x->attribute)] = $x->value;
|
||||
|
||||
|
@ -160,7 +160,7 @@ function email_get_part($mbox,$uid,$p,$partno, $subtype) {
|
|||
// Any part with a filename is an attachment,
|
||||
// so an attached text file (type 0) is not mistaken as the message.
|
||||
|
||||
if ((isset($params['filename']) and $params['filename']) || (isset($params['name']) and $params['name'])) {
|
||||
if ((isset($params['filename']) && $params['filename']) || (isset($params['name']) && $params['name'])) {
|
||||
// filename may be given as 'Filename' or 'Name' or both
|
||||
$filename = ($params['filename'])? $params['filename'] : $params['name'];
|
||||
// filename may be encoded, so see imap_mime_header_decode()
|
||||
|
@ -191,7 +191,7 @@ function email_get_part($mbox,$uid,$p,$partno, $subtype) {
|
|||
// }
|
||||
|
||||
// SUBPART RECURSION
|
||||
if (isset($p->parts) and $p->parts) {
|
||||
if (isset($p->parts) && $p->parts) {
|
||||
$x = "";
|
||||
foreach ($p->parts as $partno0=>$p2) {
|
||||
$x .= email_get_part($mbox,$uid,$p2,$partno . '.' . ($partno0+1), $subtype); // 1.2, 1.2.1, etc.
|
||||
|
|
|
@ -99,7 +99,7 @@ function notification($params) {
|
|||
intval($parent_id),
|
||||
intval($params['uid'])
|
||||
);
|
||||
if ($p AND count($p) AND ($p[0]["ignored"])) {
|
||||
if ($p && count($p) && ($p[0]["ignored"])) {
|
||||
logger("Thread ".$parent_id." will be ignored", LOGGER_DEBUG);
|
||||
return;
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ function notification($params) {
|
|||
dbesc($params['link']),
|
||||
intval($params['uid'])
|
||||
);
|
||||
if ($p and count($p)) {
|
||||
if ($p && count($p)) {
|
||||
pop_lang();
|
||||
return;
|
||||
}
|
||||
|
@ -515,7 +515,7 @@ function notification($params) {
|
|||
|
||||
logger('sending notification email');
|
||||
|
||||
if (isset($params['parent']) AND (intval($params['parent']) != 0)) {
|
||||
if (isset($params['parent']) && (intval($params['parent']) != 0)) {
|
||||
$id_for_parent = $params['parent']."@".$hostname;
|
||||
|
||||
// Is this the first email notification for this parent item and user?
|
||||
|
@ -676,7 +676,7 @@ function check_item_notification($itemid, $uid, $defaulttype = "") {
|
|||
// Check for invalid profile urls. 13 should be the shortest possible profile length:
|
||||
// http://a.bc/d
|
||||
// Additionally check for invalid urls that would return the normalised value "http:"
|
||||
if ((strlen($profile) >= 13) AND (normalise_link($profile) != "http:")) {
|
||||
if ((strlen($profile) >= 13) && (normalise_link($profile) != "http:")) {
|
||||
if (!in_array($profile, $profiles2))
|
||||
$profiles2[] = $profile;
|
||||
|
||||
|
@ -760,11 +760,11 @@ function check_item_notification($itemid, $uid, $defaulttype = "") {
|
|||
$tagged = false;
|
||||
|
||||
foreach ($profiles AS $profile) {
|
||||
if (strpos($item[0]["tag"], "=".$profile."]") OR strpos($item[0]["body"], "=".$profile."]"))
|
||||
if (strpos($item[0]["tag"], "=".$profile."]") || strpos($item[0]["body"], "=".$profile."]"))
|
||||
$tagged = true;
|
||||
}
|
||||
|
||||
if ($item[0]["mention"] OR $tagged OR ($defaulttype == NOTIFY_TAGSELF)) {
|
||||
if ($item[0]["mention"] || $tagged || ($defaulttype == NOTIFY_TAGSELF)) {
|
||||
$params["type"] = NOTIFY_TAGSELF;
|
||||
$params["verb"] = ACTIVITY_TAG;
|
||||
}
|
||||
|
@ -776,7 +776,7 @@ function check_item_notification($itemid, $uid, $defaulttype = "") {
|
|||
LIMIT 1",
|
||||
intval($item[0]["parent"]), intval($uid));
|
||||
|
||||
if ($parent AND !isset($params["type"])) {
|
||||
if ($parent && !isset($params["type"])) {
|
||||
$params["type"] = NOTIFY_COMMENT;
|
||||
$params["verb"] = ACTIVITY_POST;
|
||||
}
|
||||
|
|
|
@ -853,18 +853,22 @@ function widget_events() {
|
|||
return;
|
||||
}
|
||||
|
||||
// Cal logged in user (test permission at foreign profile page)
|
||||
// If the $owner uid is available we know it is part of one of the profile pages (like /cal)
|
||||
// So we have to test if if it's the own profile page of the logged in user
|
||||
// or a foreign one. For foreign profile pages we need to check if the feature
|
||||
// for exporting the cal is enabled (otherwise the widget would appear for logged in users
|
||||
// on foreigen profile pages even if the widget is disabled)
|
||||
/*
|
||||
* Cal logged in user (test permission at foreign profile page)
|
||||
* If the $owner uid is available we know it is part of one of the profile pages (like /cal)
|
||||
* So we have to test if if it's the own profile page of the logged in user
|
||||
* or a foreign one. For foreign profile pages we need to check if the feature
|
||||
* for exporting the cal is enabled (otherwise the widget would appear for logged in users
|
||||
* on foreigen profile pages even if the widget is disabled)
|
||||
*/
|
||||
if (intval($owner_uid) && local_user() !== $owner_uid && ! feature_enabled($owner_uid, "export_calendar")) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If it's a kind of profile page (intval($owner_uid)) return if the user not logged in and
|
||||
// export feature isn't enabled
|
||||
/*
|
||||
* If it's a kind of profile page (intval($owner_uid)) return if the user not logged in and
|
||||
* export feature isn't enabled
|
||||
*/
|
||||
if (intval($owner_uid) && ! local_user() && ! feature_enabled($owner_uid, "export_calendar")) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -9,33 +9,66 @@ function expire_run(&$argv, &$argc){
|
|||
require_once('include/items.php');
|
||||
require_once('include/Contact.php');
|
||||
|
||||
// physically remove anything that has been deleted for more than two months
|
||||
$r = dba::p("SELECT `id` FROM `item` WHERE `deleted` AND `changed` < UTC_TIMESTAMP() - INTERVAL 60 DAY");
|
||||
if (dbm::is_result($r)) {
|
||||
load_hooks();
|
||||
|
||||
if (($argc == 2) && ($argv[1] == 'delete')) {
|
||||
logger('Delete expired items', LOGGER_DEBUG);
|
||||
// physically remove anything that has been deleted for more than two months
|
||||
$r = dba::p("SELECT `id` FROM `item` WHERE `deleted` AND `changed` < UTC_TIMESTAMP() - INTERVAL 60 DAY");
|
||||
while ($row = dba::fetch($r)) {
|
||||
dba::delete('item', array('id' => $row['id']));
|
||||
}
|
||||
dba::close($r);
|
||||
}
|
||||
|
||||
// make this optional as it could have a performance impact on large sites
|
||||
if (intval(get_config('system', 'optimize_items'))) {
|
||||
q("OPTIMIZE TABLE `item`");
|
||||
logger('Delete expired items - done', LOGGER_DEBUG);
|
||||
|
||||
// make this optional as it could have a performance impact on large sites
|
||||
if (intval(get_config('system', 'optimize_items'))) {
|
||||
q("OPTIMIZE TABLE `item`");
|
||||
}
|
||||
return;
|
||||
} elseif (($argc == 2) && (intval($argv[1]) > 0)) {
|
||||
$user = dba::select('user', array('uid', 'username', 'expire'), array('uid' => $argv[1]), array('limit' => 1));
|
||||
if (dbm::is_result($user)) {
|
||||
logger('Expire items for user '.$user['uid'].' ('.$user['username'].') - interval: '.$user['expire'], LOGGER_DEBUG);
|
||||
item_expire($user['uid'], $user['expire']);
|
||||
logger('Expire items for user '.$user['uid'].' ('.$user['username'].') - done ', LOGGER_DEBUG);
|
||||
}
|
||||
return;
|
||||
} elseif (($argc == 3) && ($argv[1] == 'hook') && is_array($a->hooks) && array_key_exists("expire", $a->hooks)) {
|
||||
foreach ($a->hooks["expire"] as $hook) {
|
||||
if ($hook[1] == $argv[2]) {
|
||||
logger("Calling expire hook '" . $hook[1] . "'", LOGGER_DEBUG);
|
||||
call_single_hook($a, $name, $hook, $data);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
logger('expire: start');
|
||||
|
||||
$r = q("SELECT `uid`, `username`, `expire` FROM `user` WHERE `expire` != 0");
|
||||
if (dbm::is_result($r)) {
|
||||
foreach ($r as $rr) {
|
||||
logger('Expire: ' . $rr['username'] . ' interval: ' . $rr['expire'], LOGGER_DEBUG);
|
||||
item_expire($rr['uid'], $rr['expire']);
|
||||
proc_run(array('priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true),
|
||||
'include/expire.php', 'delete');
|
||||
|
||||
$r = dba::p("SELECT `uid`, `username` FROM `user` WHERE `expire` != 0");
|
||||
while ($row = dba::fetch($r)) {
|
||||
logger('Calling expiry for user '.$row['uid'].' ('.$row['username'].')', LOGGER_DEBUG);
|
||||
proc_run(array('priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true),
|
||||
'include/expire.php', (int)$row['uid']);
|
||||
}
|
||||
dba::close($r);
|
||||
|
||||
logger('expire: calling hooks');
|
||||
|
||||
if (is_array($a->hooks) && array_key_exists('expire', $a->hooks)) {
|
||||
foreach ($a->hooks['expire'] as $hook) {
|
||||
logger("Calling expire hook for '" . $hook[1] . "'", LOGGER_DEBUG);
|
||||
proc_run(array('priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true),
|
||||
'include/expire.php', 'hook', $hook[1]);
|
||||
}
|
||||
}
|
||||
|
||||
load_hooks();
|
||||
|
||||
call_hooks('expire');
|
||||
logger('expire: end');
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -30,10 +30,10 @@ function update_contact($id) {
|
|||
|
||||
// make sure to not overwrite existing values with blank entries
|
||||
foreach ($ret AS $key => $val) {
|
||||
if (isset($r[0][$key]) AND ($r[0][$key] != "") AND ($val == ""))
|
||||
if (isset($r[0][$key]) && ($r[0][$key] != "") && ($val == ""))
|
||||
$ret[$key] = $r[0][$key];
|
||||
|
||||
if (isset($r[0][$key]) AND ($ret[$key] != $r[0][$key]))
|
||||
if (isset($r[0][$key]) && ($ret[$key] != $r[0][$key]))
|
||||
$update = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ function gprobe_run(&$argv, &$argc){
|
|||
if ($argc != 2) {
|
||||
return;
|
||||
}
|
||||
$url = hex2bin($argv[1]);
|
||||
$url = $argv[1];
|
||||
|
||||
$r = q("SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1",
|
||||
dbesc(normalise_link($url))
|
||||
|
@ -47,7 +47,7 @@ function gprobe_run(&$argv, &$argc){
|
|||
}
|
||||
if (dbm::is_result($r)) {
|
||||
// Check for accessibility and do a poco discovery
|
||||
if (poco_last_updated($r[0]['url'], true) AND ($r[0]["network"] == NETWORK_DFRN))
|
||||
if (poco_last_updated($r[0]['url'], true) && ($r[0]["network"] == NETWORK_DFRN))
|
||||
poco_load(0,0,$r[0]['id'], str_replace('/profile/','/poco/',$r[0]['url']));
|
||||
}
|
||||
|
||||
|
|
|
@ -320,7 +320,7 @@ function expand_groups($a,$check_dead = false, $use_gcontact = false) {
|
|||
if (dbm::is_result($r))
|
||||
foreach ($r as $rr)
|
||||
$ret[] = $rr['contact-id'];
|
||||
if ($check_dead AND !$use_gcontact) {
|
||||
if ($check_dead && !$use_gcontact) {
|
||||
require_once('include/acl_selectors.php');
|
||||
$ret = prune_deadguys($ret);
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ function node2bbcodesub(&$doc, $oldnode, $attributes, $startbb, $endbb)
|
|||
|
||||
if (strpos('*'.$startbb, '$1') > 0) {
|
||||
|
||||
if ($replace and (@$attr[$attribute] != '')) {
|
||||
if ($replace && (@$attr[$attribute] != '')) {
|
||||
|
||||
$startbb = preg_replace($value, $startbb, $attr[$attribute], -1, $count);
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ function breaklines($line, $level, $wraplength = 75)
|
|||
if ($pos == 0)
|
||||
$pos = strpos($line, ' ');
|
||||
|
||||
if (($pos > 0) and strlen($line) > $wraplen) {
|
||||
if (($pos > 0) && strlen($line) > $wraplen) {
|
||||
$newline = trim(substr($line, 0, $pos));
|
||||
if ($level > 0)
|
||||
$newline = str_repeat(">", $level).' '.$newline;
|
||||
|
@ -32,7 +32,7 @@ function breaklines($line, $level, $wraplength = 75)
|
|||
$line = substr($line, $pos+1);
|
||||
}
|
||||
|
||||
} while ((strlen($line) > $wraplen) and !($oldline == $line));
|
||||
} while ((strlen($line) > $wraplen) && !($oldline == $line));
|
||||
|
||||
if ($level > 0)
|
||||
$line = str_repeat(">", $level).' '.$line;
|
||||
|
@ -70,7 +70,7 @@ function quotelevel($message, $wraplength = 75)
|
|||
$line = substr($line, 0, $pos).substr($line, $pos+8);
|
||||
}
|
||||
|
||||
if (!$startquote or ($line != ''))
|
||||
if (!$startquote || ($line != ''))
|
||||
$newlines[] = breaklines($line, $currlevel, $wraplength);
|
||||
}
|
||||
return(implode($newlines, "\n"));
|
||||
|
@ -92,13 +92,13 @@ function collecturls($message) {
|
|||
if (strpos($treffer[1], $listitem) !== false)
|
||||
$ignore = true;
|
||||
|
||||
if ((strpos($treffer[1], "//twitter.com/") !== false) and (strpos($treffer[1], "/status/") !== false))
|
||||
if ((strpos($treffer[1], "//twitter.com/") !== false) && (strpos($treffer[1], "/status/") !== false))
|
||||
$ignore = false;
|
||||
|
||||
if ((strpos($treffer[1], "//plus.google.com/") !== false) and (strpos($treffer[1], "/posts") !== false))
|
||||
if ((strpos($treffer[1], "//plus.google.com/") !== false) && (strpos($treffer[1], "/posts") !== false))
|
||||
$ignore = false;
|
||||
|
||||
if ((strpos($treffer[1], "//plus.google.com/") !== false) and (strpos($treffer[1], "/photos") !== false))
|
||||
if ((strpos($treffer[1], "//plus.google.com/") !== false) && (strpos($treffer[1], "/photos") !== false))
|
||||
$ignore = false;
|
||||
|
||||
if (!$ignore)
|
||||
|
@ -212,7 +212,7 @@ function html2plain($html, $wraplength = 75, $compact = false)
|
|||
|
||||
$message = html_entity_decode($message, ENT_QUOTES, 'UTF-8');
|
||||
|
||||
if (!$compact AND ($message != "")) {
|
||||
if (!$compact && ($message != "")) {
|
||||
$counter = 1;
|
||||
foreach ($urls as $id=>$url)
|
||||
if ($url != "")
|
||||
|
|
|
@ -217,7 +217,7 @@ function profile_sidebar($profile, $block = 0) {
|
|||
|
||||
$profile['picdate'] = urlencode($profile['picdate']);
|
||||
|
||||
if (($profile['network'] != "") AND ($profile['network'] != NETWORK_DFRN)) {
|
||||
if (($profile['network'] != "") && ($profile['network'] != NETWORK_DFRN)) {
|
||||
$profile['network_name'] = format_network_name($profile['network'], $profile['url']);
|
||||
} else {
|
||||
$profile['network_name'] = "";
|
||||
|
@ -240,7 +240,7 @@ function profile_sidebar($profile, $block = 0) {
|
|||
}
|
||||
|
||||
// Is the local user already connected to that user?
|
||||
if ($connect AND local_user()) {
|
||||
if ($connect && local_user()) {
|
||||
if (isset($profile["url"])) {
|
||||
$profile_url = normalise_link($profile["url"]);
|
||||
} else {
|
||||
|
@ -254,19 +254,19 @@ function profile_sidebar($profile, $block = 0) {
|
|||
$connect = false;
|
||||
}
|
||||
|
||||
if ($connect AND ($profile['network'] != NETWORK_DFRN) AND !isset($profile['remoteconnect']))
|
||||
if ($connect && ($profile['network'] != NETWORK_DFRN) && !isset($profile['remoteconnect']))
|
||||
$connect = false;
|
||||
|
||||
$remoteconnect = NULL;
|
||||
if (isset($profile['remoteconnect']))
|
||||
$remoteconnect = $profile['remoteconnect'];
|
||||
|
||||
if ($connect AND ($profile['network'] == NETWORK_DFRN) AND !isset($remoteconnect))
|
||||
if ($connect && ($profile['network'] == NETWORK_DFRN) && !isset($remoteconnect))
|
||||
$subscribe_feed = t("Atom feed");
|
||||
else
|
||||
$subscribe_feed = false;
|
||||
|
||||
if (remote_user() OR (get_my_url() && $profile['unkmail'] && ($profile['uid'] != local_user()))) {
|
||||
if (remote_user() || (get_my_url() && $profile['unkmail'] && ($profile['uid'] != local_user()))) {
|
||||
$wallmessage = t('Message');
|
||||
$wallmessage_link = "wallmessage/".$profile["nickname"];
|
||||
|
||||
|
@ -379,7 +379,7 @@ function profile_sidebar($profile, $block = 0) {
|
|||
if (!$block) {
|
||||
$contact_block = contact_block();
|
||||
|
||||
if (is_array($a->profile) AND !$a->profile['hide-friends']) {
|
||||
if (is_array($a->profile) && !$a->profile['hide-friends']) {
|
||||
$r = q("SELECT `gcontact`.`updated` FROM `contact` INNER JOIN `gcontact` WHERE `gcontact`.`nurl` = `contact`.`nurl` AND `self` AND `uid` = %d LIMIT 1",
|
||||
intval($a->profile['uid']));
|
||||
if (dbm::is_result($r))
|
||||
|
@ -656,8 +656,10 @@ function advanced_profile(App $a) {
|
|||
$profile['birthday'] = array( t('Birthday:'), $val);
|
||||
|
||||
}
|
||||
|
||||
if ($age = age($a->profile['dob'],$a->profile['timezone'],'')) {
|
||||
if (!empty($a->profile['dob'])
|
||||
&& $a->profile['dob'] > '0001-01-01'
|
||||
&& $age = age($a->profile['dob'], $a->profile['timezone'], '')
|
||||
) {
|
||||
$profile['age'] = array( t('Age:'), $age );
|
||||
}
|
||||
|
||||
|
@ -888,7 +890,7 @@ function zrl_init(App $a) {
|
|||
return;
|
||||
}
|
||||
|
||||
proc_run(PRIORITY_LOW, 'include/gprobe.php', bin2hex($tmp_str));
|
||||
proc_run(PRIORITY_LOW, 'include/gprobe.php', $tmp_str);
|
||||
$arr = array('zrl' => $tmp_str, 'url' => $a->cmd);
|
||||
call_hooks('zrl_init', $arr);
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
use Friendica\App;
|
||||
use Friendica\ParseUrl;
|
||||
use Friendica\Util\Lock;
|
||||
|
||||
require_once 'include/bbcode.php';
|
||||
require_once 'include/oembed.php';
|
||||
|
@ -143,7 +144,7 @@ function title_is_body($title, $body) {
|
|||
$body = substr($body, 0, strlen($title));
|
||||
}
|
||||
|
||||
if (($title != $body) and (substr($title, -3) == "...")) {
|
||||
if (($title != $body) && (substr($title, -3) == "...")) {
|
||||
$pos = strrpos($title, "...");
|
||||
if ($pos > 0) {
|
||||
$title = substr($title, 0, $pos);
|
||||
|
@ -159,16 +160,16 @@ function add_page_info_data($data) {
|
|||
|
||||
// It maybe is a rich content, but if it does have everything that a link has,
|
||||
// then treat it that way
|
||||
if (($data["type"] == "rich") AND is_string($data["title"]) AND
|
||||
is_string($data["text"]) AND (sizeof($data["images"]) > 0)) {
|
||||
if (($data["type"] == "rich") && is_string($data["title"]) &&
|
||||
is_string($data["text"]) && (sizeof($data["images"]) > 0)) {
|
||||
$data["type"] = "link";
|
||||
}
|
||||
|
||||
if ((($data["type"] != "link") AND ($data["type"] != "video") AND ($data["type"] != "photo")) OR ($data["title"] == $data["url"])) {
|
||||
if ((($data["type"] != "link") && ($data["type"] != "video") && ($data["type"] != "photo")) || ($data["title"] == $data["url"])) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if ($no_photos AND ($data["type"] == "photo")) {
|
||||
if ($no_photos && ($data["type"] == "photo")) {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
@ -204,7 +205,7 @@ function add_page_info_data($data) {
|
|||
$preview = str_replace(array("[", "]"), array("[", "]"), htmlentities($data["images"][0]["src"], ENT_QUOTES, 'UTF-8', false));
|
||||
// if the preview picture is larger than 500 pixels then show it in a larger mode
|
||||
// But only, if the picture isn't higher than large (To prevent huge posts)
|
||||
if (($data["images"][0]["width"] >= 500) AND ($data["images"][0]["width"] >= $data["images"][0]["height"])) {
|
||||
if (($data["images"][0]["width"] >= 500) && ($data["images"][0]["width"] >= $data["images"][0]["height"])) {
|
||||
$text .= " image='".$preview."'";
|
||||
} else {
|
||||
$text .= " preview='".$preview."'";
|
||||
|
@ -214,7 +215,7 @@ function add_page_info_data($data) {
|
|||
$text .= "]".$data["text"]."[/attachment]";
|
||||
|
||||
$hashtags = "";
|
||||
if (isset($data["keywords"]) AND count($data["keywords"])) {
|
||||
if (isset($data["keywords"]) && count($data["keywords"])) {
|
||||
$hashtags = "\n";
|
||||
foreach ($data["keywords"] AS $keyword) {
|
||||
/// @todo make a positive list of allowed characters
|
||||
|
@ -237,11 +238,11 @@ function query_page_info($url, $no_photos = false, $photo = "", $keywords = fals
|
|||
|
||||
logger('fetch page info for ' . $url . ' ' . print_r($data, true), LOGGER_DEBUG);
|
||||
|
||||
if (!$keywords AND isset($data["keywords"])) {
|
||||
if (!$keywords && isset($data["keywords"])) {
|
||||
unset($data["keywords"]);
|
||||
}
|
||||
|
||||
if (($keyword_blacklist != "") AND isset($data["keywords"])) {
|
||||
if (($keyword_blacklist != "") && isset($data["keywords"])) {
|
||||
$list = explode(", ", $keyword_blacklist);
|
||||
foreach ($list AS $keyword) {
|
||||
$keyword = trim($keyword);
|
||||
|
@ -259,7 +260,7 @@ function add_page_keywords($url, $no_photos = false, $photo = "", $keywords = fa
|
|||
$data = query_page_info($url, $no_photos, $photo, $keywords, $keyword_blacklist);
|
||||
|
||||
$tags = "";
|
||||
if (isset($data["keywords"]) AND count($data["keywords"])) {
|
||||
if (isset($data["keywords"]) && count($data["keywords"])) {
|
||||
foreach ($data["keywords"] AS $keyword) {
|
||||
$hashtag = str_replace(array(" ", "+", "/", ".", "#", "'"),
|
||||
array("", "", "", "", "", ""), $keyword);
|
||||
|
@ -301,7 +302,7 @@ function add_page_info_to_body($body, $texturl = false, $no_photos = false) {
|
|||
}
|
||||
|
||||
// Convert urls without bbcode elements
|
||||
if (!$matches AND $texturl) {
|
||||
if (!$matches && $texturl) {
|
||||
preg_match("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", " ".$body, $matches);
|
||||
|
||||
// Yeah, a hack. I really hate regular expressions :)
|
||||
|
@ -315,21 +316,21 @@ function add_page_info_to_body($body, $texturl = false, $no_photos = false) {
|
|||
}
|
||||
|
||||
// Remove the link from the body if the link is attached at the end of the post
|
||||
if (isset($footer) AND (trim($footer) != "") AND (strpos($footer, $matches[1]))) {
|
||||
if (isset($footer) && (trim($footer) != "") && (strpos($footer, $matches[1]))) {
|
||||
$removedlink = trim(str_replace($matches[1], "", $body));
|
||||
if (($removedlink == "") OR strstr($body, $removedlink)) {
|
||||
if (($removedlink == "") || strstr($body, $removedlink)) {
|
||||
$body = $removedlink;
|
||||
}
|
||||
|
||||
$url = str_replace(array('/', '.'), array('\/', '\.'), $matches[1]);
|
||||
$removedlink = preg_replace("/\[url\=" . $url . "\](.*?)\[\/url\]/ism", '', $body);
|
||||
if (($removedlink == "") OR strstr($body, $removedlink)) {
|
||||
if (($removedlink == "") || strstr($body, $removedlink)) {
|
||||
$body = $removedlink;
|
||||
}
|
||||
}
|
||||
|
||||
// Add the page information to the bottom
|
||||
if (isset($footer) AND (trim($footer) != "")) {
|
||||
if (isset($footer) && (trim($footer) != "")) {
|
||||
$body .= $footer;
|
||||
}
|
||||
|
||||
|
@ -421,10 +422,10 @@ function store_conversation($arr) {
|
|||
if (in_array($arr['network'], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) {
|
||||
$conversation = array('item-uri' => $arr['uri'], 'received' => dbm::date());
|
||||
|
||||
if (isset($arr['parent-uri']) AND ($arr['parent-uri'] != $arr['uri'])) {
|
||||
if (isset($arr['parent-uri']) && ($arr['parent-uri'] != $arr['uri'])) {
|
||||
$conversation['reply-to-uri'] = $arr['parent-uri'];
|
||||
}
|
||||
if (isset($arr['thr-parent']) AND ($arr['thr-parent'] != $arr['uri'])) {
|
||||
if (isset($arr['thr-parent']) && ($arr['thr-parent'] != $arr['uri'])) {
|
||||
$conversation['reply-to-uri'] = $arr['thr-parent'];
|
||||
}
|
||||
|
||||
|
@ -444,6 +445,15 @@ function store_conversation($arr) {
|
|||
$conversation['source'] = $arr['source'];
|
||||
}
|
||||
|
||||
if (!Lock::set('store_conversation')) {
|
||||
// When using semaphores, this case never can't happen
|
||||
unset($arr['conversation-uri']);
|
||||
unset($arr['conversation-href']);
|
||||
unset($arr['protocol']);
|
||||
unset($arr['source']);
|
||||
return $arr;
|
||||
}
|
||||
|
||||
$old_conv = dba::fetch_first("SELECT `item-uri`, `reply-to-uri`, `conversation-uri`, `conversation-href`, `protocol`, `source`
|
||||
FROM `conversation` WHERE `item-uri` = ?", $conversation['item-uri']);
|
||||
if (dbm::is_result($old_conv)) {
|
||||
|
@ -453,7 +463,7 @@ function store_conversation($arr) {
|
|||
unset($old_conv['source']);
|
||||
}
|
||||
// Update structure data all the time but the source only when its from a better protocol.
|
||||
if (($old_conv['protocol'] < $conversation['protocol']) AND ($old_conv['protocol'] != 0)) {
|
||||
if (($old_conv['protocol'] < $conversation['protocol']) && ($old_conv['protocol'] != 0)) {
|
||||
unset($conversation['protocol']);
|
||||
unset($conversation['source']);
|
||||
}
|
||||
|
@ -465,6 +475,7 @@ function store_conversation($arr) {
|
|||
logger('Conversation: insert for '.$conversation['item-uri'].' (protocol '.$conversation['protocol'].') failed', LOGGER_DEBUG);
|
||||
}
|
||||
}
|
||||
Lock::remove('store_conversation');
|
||||
}
|
||||
|
||||
unset($arr['conversation-uri']);
|
||||
|
@ -503,9 +514,9 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f
|
|||
|
||||
if ($notify) {
|
||||
$guid_prefix = "";
|
||||
} elseif ((trim($arr['guid']) == "") AND (trim($arr['plink']) != "")) {
|
||||
} elseif ((trim($arr['guid']) == "") && (trim($arr['plink']) != "")) {
|
||||
$arr['guid'] = uri_to_guid($arr['plink']);
|
||||
} elseif ((trim($arr['guid']) == "") AND (trim($arr['uri']) != "")) {
|
||||
} elseif ((trim($arr['guid']) == "") && (trim($arr['uri']) != "")) {
|
||||
$arr['guid'] = uri_to_guid($arr['uri']);
|
||||
} else {
|
||||
$parsed = parse_url($arr["author-link"]);
|
||||
|
@ -653,7 +664,7 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f
|
|||
$arr['edited'] = datetime_convert();
|
||||
}
|
||||
|
||||
if (($arr['author-link'] == "") AND ($arr['owner-link'] == "")) {
|
||||
if (($arr['author-link'] == "") && ($arr['owner-link'] == "")) {
|
||||
logger("Both author-link and owner-link are empty. Called by: " . App::callstack(), LOGGER_DEBUG);
|
||||
}
|
||||
|
||||
|
@ -832,7 +843,7 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f
|
|||
$a = get_app();
|
||||
$self = normalise_link(App::get_baseurl() . '/profile/' . $u[0]['nickname']);
|
||||
logger("item_store: 'myself' is ".$self." for parent ".$parent_id." checking against ".$arr['author-link']." and ".$arr['owner-link'], LOGGER_DEBUG);
|
||||
if ((normalise_link($arr['author-link']) == $self) OR (normalise_link($arr['owner-link']) == $self)) {
|
||||
if ((normalise_link($arr['author-link']) == $self) || (normalise_link($arr['owner-link']) == $self)) {
|
||||
q("UPDATE `thread` SET `mention` = 1 WHERE `iid` = %d", intval($parent_id));
|
||||
logger("item_store: tagged thread ".$parent_id." as mention for user ".$self, LOGGER_DEBUG);
|
||||
}
|
||||
|
@ -1051,7 +1062,7 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f
|
|||
|
||||
// update the commented timestamp on the parent
|
||||
// Only update "commented" if it is really a comment
|
||||
if (($arr['verb'] == ACTIVITY_POST) OR !get_config("system", "like_no_comment")) {
|
||||
if (($arr['verb'] == ACTIVITY_POST) || !get_config("system", "like_no_comment")) {
|
||||
q("UPDATE `item` SET `commented` = '%s', `changed` = '%s' WHERE `id` = %d",
|
||||
dbesc(datetime_convert()),
|
||||
dbesc(datetime_convert()),
|
||||
|
@ -1089,7 +1100,7 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f
|
|||
* current post can be deleted if is for a community page and no mention are
|
||||
* in it.
|
||||
*/
|
||||
if (!$deleted AND !$dontcache) {
|
||||
if (!$deleted && !$dontcache) {
|
||||
|
||||
$r = q('SELECT * FROM `item` WHERE `id` = %d', intval($current_post));
|
||||
if ((dbm::is_result($r)) && (count($r) == 1)) {
|
||||
|
@ -1139,7 +1150,7 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f
|
|||
check_item_notification($current_post, $uid);
|
||||
|
||||
if ($notify) {
|
||||
proc_run(PRIORITY_HIGH, "include/notifier.php", $notify_type, $current_post);
|
||||
proc_run(array('priority' => PRIORITY_HIGH, 'dont_fork' => true), "include/notifier.php", $notify_type, $current_post);
|
||||
}
|
||||
|
||||
return $current_post;
|
||||
|
@ -1156,10 +1167,10 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f
|
|||
*/
|
||||
function item_set_last_item($arr) {
|
||||
|
||||
$update = (!$arr['private'] AND (($arr["author-link"] === $arr["owner-link"]) OR ($arr["parent-uri"] === $arr["uri"])));
|
||||
$update = (!$arr['private'] && (($arr["author-link"] === $arr["owner-link"]) || ($arr["parent-uri"] === $arr["uri"])));
|
||||
|
||||
// Is it a forum? Then we don't care about the rules from above
|
||||
if (!$update AND ($arr["network"] == NETWORK_DFRN) AND ($arr["parent-uri"] === $arr["uri"])) {
|
||||
if (!$update && ($arr["network"] == NETWORK_DFRN) && ($arr["parent-uri"] === $arr["uri"])) {
|
||||
$isforum = q("SELECT `forum` FROM `contact` WHERE `id` = %d AND `forum`",
|
||||
intval($arr['contact-id']));
|
||||
if (dbm::is_result($isforum)) {
|
||||
|
@ -1282,7 +1293,7 @@ function get_item_id($guid, $uid = 0) {
|
|||
// Does the given user have this item?
|
||||
if ($uid) {
|
||||
$r = q("SELECT `item`.`id`, `user`.`nickname` FROM `item` INNER JOIN `user` ON `user`.`uid` = `item`.`uid`
|
||||
WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
|
||||
WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 AND `item`.`moderated` = 0
|
||||
AND `item`.`guid` = '%s' AND `item`.`uid` = %d", dbesc($guid), intval($uid));
|
||||
if (dbm::is_result($r)) {
|
||||
$id = $r[0]["id"];
|
||||
|
@ -1293,7 +1304,7 @@ function get_item_id($guid, $uid = 0) {
|
|||
// Or is it anywhere on the server?
|
||||
if ($nick == "") {
|
||||
$r = q("SELECT `item`.`id`, `user`.`nickname` FROM `item` INNER JOIN `user` ON `user`.`uid` = `item`.`uid`
|
||||
WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 and `item`.`moderated` = 0
|
||||
WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 AND `item`.`moderated` = 0
|
||||
AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
|
||||
AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
|
||||
AND `item`.`private` = 0 AND `item`.`wall` = 1
|
||||
|
@ -1430,7 +1441,7 @@ function tag_deliver($uid, $item_id) {
|
|||
);
|
||||
update_thread($item_id);
|
||||
|
||||
proc_run(PRIORITY_HIGH,'include/notifier.php', 'tgroup', $item_id);
|
||||
proc_run(array('priority' => PRIORITY_HIGH, 'dont_fork' => true), 'include/notifier.php', 'tgroup', $item_id);
|
||||
|
||||
}
|
||||
|
||||
|
@ -1600,7 +1611,7 @@ function item_is_remote_self($contact, &$datarray) {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (($contact['network'] != NETWORK_FEED) AND $datarray['private']) {
|
||||
if (($contact['network'] != NETWORK_FEED) && $datarray['private']) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1701,7 +1712,7 @@ function new_follower($importer, $contact, $datarray, $item, $sharing = false) {
|
|||
intval($importer['uid'])
|
||||
);
|
||||
|
||||
if (dbm::is_result($r) AND !in_array($r[0]['page-flags'], array(PAGE_SOAPBOX, PAGE_FREELOVE))) {
|
||||
if (dbm::is_result($r) && !in_array($r[0]['page-flags'], array(PAGE_SOAPBOX, PAGE_FREELOVE))) {
|
||||
|
||||
// create notification
|
||||
$hash = random_string();
|
||||
|
@ -1741,7 +1752,7 @@ function new_follower($importer, $contact, $datarray, $item, $sharing = false) {
|
|||
));
|
||||
|
||||
}
|
||||
} elseif (dbm::is_result($r) AND in_array($r[0]['page-flags'], array(PAGE_SOAPBOX, PAGE_FREELOVE))) {
|
||||
} elseif (dbm::is_result($r) && in_array($r[0]['page-flags'], array(PAGE_SOAPBOX, PAGE_FREELOVE))) {
|
||||
$r = q("UPDATE `contact` SET `pending` = 0 WHERE `uid` = %d AND `url` = '%s' AND `pending` LIMIT 1",
|
||||
intval($importer['uid']),
|
||||
dbesc($url)
|
||||
|
@ -1803,7 +1814,7 @@ function subscribe_to_hub($url, $importer, $contact, $hubmode = 'subscribe') {
|
|||
|
||||
logger('subscribe_to_hub: ' . $hubmode . ' ' . $contact['name'] . ' to hub ' . $url . ' endpoint: ' . $push_url . ' with verifier ' . $verify_token);
|
||||
|
||||
if (!strlen($contact['hub-verify']) OR ($contact['hub-verify'] != $verify_token)) {
|
||||
if (!strlen($contact['hub-verify']) || ($contact['hub-verify'] != $verify_token)) {
|
||||
$r = q("UPDATE `contact` SET `hub-verify` = '%s' WHERE `id` = %d",
|
||||
dbesc($verify_token),
|
||||
intval($contact['id'])
|
||||
|
@ -2051,7 +2062,7 @@ function item_expire($uid, $days, $network = "", $force = false) {
|
|||
$expire_photos = get_pconfig($uid, 'expire', 'photos');
|
||||
$expire_photos = (($expire_photos === false) ? 0 : intval($expire_photos)); // default if not set: 0
|
||||
|
||||
logger('expire: # items=' . count($r). "; expire items: $expire_items, expire notes: $expire_notes, expire starred: $expire_starred, expire photos: $expire_photos");
|
||||
logger('User '.$uid.': expire: # items=' . count($r). "; expire items: $expire_items, expire notes: $expire_notes, expire starred: $expire_starred, expire photos: $expire_photos");
|
||||
|
||||
foreach ($r as $item) {
|
||||
|
||||
|
@ -2076,7 +2087,7 @@ function item_expire($uid, $days, $network = "", $force = false) {
|
|||
drop_item($item['id'], false);
|
||||
}
|
||||
|
||||
proc_run(PRIORITY_LOW, "include/notifier.php", "expire", $uid);
|
||||
proc_run(array('priority' => PRIORITY_LOW, 'dont_fork' => true), "include/notifier.php", "expire", $uid);
|
||||
|
||||
}
|
||||
|
||||
|
@ -2099,7 +2110,7 @@ function drop_items($items) {
|
|||
// multiple threads may have been deleted, send an expire notification
|
||||
|
||||
if ($uid) {
|
||||
proc_run(PRIORITY_LOW, "include/notifier.php", "expire", $uid);
|
||||
proc_run(array('priority' => PRIORITY_LOW, 'dont_fork' => true), "include/notifier.php", "expire", $uid);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2124,6 +2135,10 @@ function drop_item($id, $interactive = true) {
|
|||
|
||||
$item = $r[0];
|
||||
|
||||
if ($item['deleted']) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$owner = $item['uid'];
|
||||
|
||||
$contact_id = 0;
|
||||
|
@ -2295,7 +2310,7 @@ function drop_item($id, $interactive = true) {
|
|||
$drop_id = intval($item['id']);
|
||||
$priority = ($interactive ? PRIORITY_HIGH : PRIORITY_LOW);
|
||||
|
||||
proc_run($priority, "include/notifier.php", "drop", $drop_id);
|
||||
proc_run(array('priority' => $priority, 'dont_fork' => true), "include/notifier.php", "drop", $drop_id);
|
||||
|
||||
if (! $interactive) {
|
||||
return $owner;
|
||||
|
@ -2313,7 +2328,7 @@ function drop_item($id, $interactive = true) {
|
|||
|
||||
}
|
||||
|
||||
|
||||
/// @todo: This query seems to be really slow
|
||||
function first_post_date($uid, $wall = false) {
|
||||
$r = q("SELECT `id`, `created` FROM `item`
|
||||
WHERE `uid` = %d AND `wall` = %d AND `deleted` = 0 AND `visible` = 1 AND `moderated` = 0
|
||||
|
|
|
@ -1,80 +0,0 @@
|
|||
<?php
|
||||
|
||||
// Provide some ability to lock a PHP function so that multiple processes
|
||||
// can't run the function concurrently
|
||||
if (! function_exists('lock_function')) {
|
||||
function lock_function($fn_name, $block = true, $wait_sec = 2, $timeout = 30) {
|
||||
if ( $wait_sec == 0 )
|
||||
$wait_sec = 2; // don't let the user pick a value that's likely to crash the system
|
||||
|
||||
$got_lock = false;
|
||||
$start = time();
|
||||
|
||||
do {
|
||||
q("LOCK TABLE `locks` WRITE");
|
||||
$r = q("SELECT `locked`, `created` FROM `locks` WHERE `name` = '%s' LIMIT 1",
|
||||
dbesc($fn_name)
|
||||
);
|
||||
|
||||
if ((dbm::is_result($r)) AND (!$r[0]['locked'] OR (strtotime($r[0]['created']) < time() - 3600))) {
|
||||
q("UPDATE `locks` SET `locked` = 1, `created` = '%s' WHERE `name` = '%s'",
|
||||
dbesc(datetime_convert()),
|
||||
dbesc($fn_name)
|
||||
);
|
||||
$got_lock = true;
|
||||
}
|
||||
elseif (! dbm::is_result($r)) {
|
||||
/// @TODO the Boolean value for count($r) should be equivalent to the Boolean value of $r
|
||||
q("INSERT INTO `locks` (`name`, `created`, `locked`) VALUES ('%s', '%s', 1)",
|
||||
dbesc($fn_name),
|
||||
dbesc(datetime_convert())
|
||||
);
|
||||
$got_lock = true;
|
||||
}
|
||||
|
||||
q("UNLOCK TABLES");
|
||||
|
||||
if (($block) && (! $got_lock))
|
||||
sleep($wait_sec);
|
||||
|
||||
} while (($block) && (! $got_lock) && ((time() - $start) < $timeout));
|
||||
|
||||
logger('lock_function: function ' . $fn_name . ' with blocking = ' . $block . ' got_lock = ' . $got_lock . ' time = ' . (time() - $start), LOGGER_DEBUG);
|
||||
|
||||
return $got_lock;
|
||||
}}
|
||||
|
||||
|
||||
if (! function_exists('block_on_function_lock')) {
|
||||
function block_on_function_lock($fn_name, $wait_sec = 2, $timeout = 30) {
|
||||
if ( $wait_sec == 0 )
|
||||
$wait_sec = 2; // don't let the user pick a value that's likely to crash the system
|
||||
|
||||
$start = time();
|
||||
|
||||
do {
|
||||
$r = q("SELECT locked FROM locks WHERE name = '%s' LIMIT 1",
|
||||
dbesc($fn_name)
|
||||
);
|
||||
|
||||
if (dbm::is_result($r) && $r[0]['locked']) {
|
||||
sleep($wait_sec);
|
||||
}
|
||||
|
||||
} while (dbm::is_result($r) && $r[0]['locked'] && ((time() - $start) < $timeout));
|
||||
|
||||
return;
|
||||
}}
|
||||
|
||||
|
||||
if (! function_exists('unlock_function')) {
|
||||
function unlock_function($fn_name) {
|
||||
$r = q("UPDATE `locks` SET `locked` = 0, `created` = '%s' WHERE `name` = '%s'",
|
||||
dbesc(NULL_DATE),
|
||||
dbesc($fn_name)
|
||||
);
|
||||
|
||||
logger('unlock_function: released lock for function ' . $fn_name, LOGGER_DEBUG);
|
||||
|
||||
return;
|
||||
}}
|
|
@ -108,7 +108,7 @@ function send_message($recipient=0, $body='', $subject='', $replyto=''){
|
|||
);
|
||||
|
||||
|
||||
$r = q("SELECT * FROM `mail` WHERE `uri` = '%s' and `uid` = %d LIMIT 1",
|
||||
$r = q("SELECT * FROM `mail` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
|
||||
dbesc($uri),
|
||||
intval(local_user())
|
||||
);
|
||||
|
|
|
@ -124,7 +124,7 @@ function removesig($message)
|
|||
|
||||
// Sollte sich der Signaturtrenner innerhalb eines Quotes befinden
|
||||
// wird keine Signaturtrennung ausgefuehrt
|
||||
if (($sigpos < $quotepos) and ($sigpos != 0))
|
||||
if (($sigpos < $quotepos) && ($sigpos != 0))
|
||||
return(array('body' => $message, 'sig' => ''));
|
||||
|
||||
/// @TODO Regexp umstellen, so dass auf 1 oder kein Leerzeichen
|
||||
|
@ -135,7 +135,7 @@ function removesig($message)
|
|||
|
||||
preg_match($pattern, $message, $result);
|
||||
|
||||
if (($result[1] != '') and ($result[2] != '')) {
|
||||
if (($result[1] != '') && ($result[2] != '')) {
|
||||
$cleaned = trim($result[1])."\n";
|
||||
$sig = trim($result[2]);
|
||||
// '[hr][size=x-small][color=darkblue]'.trim($result[2]).'[/color][/size]';
|
||||
|
@ -157,8 +157,8 @@ function removelinebreak($message)
|
|||
foreach ($arrbody as $i => $line) {
|
||||
$currquotelevel = 0;
|
||||
$currline = $line;
|
||||
while ((strlen($currline)>0) and ((substr($currline, 0, 1) == '>')
|
||||
or (substr($currline, 0, 1) == ' '))) {
|
||||
while ((strlen($currline)>0) && ((substr($currline, 0, 1) == '>')
|
||||
|| (substr($currline, 0, 1) == ' '))) {
|
||||
if (substr($currline, 0, 1) == '>')
|
||||
$currquotelevel++;
|
||||
|
||||
|
@ -167,8 +167,8 @@ function removelinebreak($message)
|
|||
|
||||
$quotelevel = 0;
|
||||
$nextline = trim($arrbody[$i+1]);
|
||||
while ((strlen($nextline)>0) and ((substr($nextline, 0, 1) == '>')
|
||||
or (substr($nextline, 0, 1) == ' '))) {
|
||||
while ((strlen($nextline)>0) && ((substr($nextline, 0, 1) == '>')
|
||||
|| (substr($nextline, 0, 1) == ' '))) {
|
||||
if (substr($nextline, 0, 1) == '>')
|
||||
$quotelevel++;
|
||||
|
||||
|
@ -178,21 +178,21 @@ function removelinebreak($message)
|
|||
$len = strlen($line);
|
||||
$firstword = strpos($nextline.' ', ' ');
|
||||
|
||||
$specialchars = ((substr(trim($nextline), 0, 1) == '-') or
|
||||
(substr(trim($nextline), 0, 1) == '=') or
|
||||
(substr(trim($nextline), 0, 1) == '*') or
|
||||
(substr(trim($nextline), 0, 1) == '·') or
|
||||
(substr(trim($nextline), 0, 4) == '[url') or
|
||||
(substr(trim($nextline), 0, 5) == '[size') or
|
||||
(substr(trim($nextline), 0, 7) == 'http://') or
|
||||
$specialchars = ((substr(trim($nextline), 0, 1) == '-') ||
|
||||
(substr(trim($nextline), 0, 1) == '=') ||
|
||||
(substr(trim($nextline), 0, 1) == '*') ||
|
||||
(substr(trim($nextline), 0, 1) == '·') ||
|
||||
(substr(trim($nextline), 0, 4) == '[url') ||
|
||||
(substr(trim($nextline), 0, 5) == '[size') ||
|
||||
(substr(trim($nextline), 0, 7) == 'http://') ||
|
||||
(substr(trim($nextline), 0, 8) == 'https://'));
|
||||
|
||||
if (!$specialchars)
|
||||
$specialchars = ((substr(rtrim($line), -1) == '-') or
|
||||
(substr(rtrim($line), -1) == '=') or
|
||||
(substr(rtrim($line), -1) == '*') or
|
||||
(substr(rtrim($line), -1) == '·') or
|
||||
(substr(rtrim($line), -6) == '[/url]') or
|
||||
$specialchars = ((substr(rtrim($line), -1) == '-') ||
|
||||
(substr(rtrim($line), -1) == '=') ||
|
||||
(substr(rtrim($line), -1) == '*') ||
|
||||
(substr(rtrim($line), -1) == '·') ||
|
||||
(substr(rtrim($line), -6) == '[/url]') ||
|
||||
(substr(rtrim($line), -7) == '[/size]'));
|
||||
|
||||
//if ($specialchars)
|
||||
|
@ -202,8 +202,8 @@ function removelinebreak($message)
|
|||
if (substr($lines[$lineno], -1) != ' ')
|
||||
$lines[$lineno] .= ' ';
|
||||
|
||||
while ((strlen($line)>0) and ((substr($line, 0, 1) == '>')
|
||||
or (substr($line, 0, 1) == ' '))) {
|
||||
while ((strlen($line)>0) && ((substr($line, 0, 1) == '>')
|
||||
|| (substr($line, 0, 1) == ' '))) {
|
||||
|
||||
$line = ltrim(substr($line, 1));
|
||||
}
|
||||
|
@ -213,10 +213,10 @@ function removelinebreak($message)
|
|||
// $lines[$lineno] = $quotelevel.'-'.$len.'-'.$firstword.'-';
|
||||
|
||||
$lines[$lineno] .= $line;
|
||||
//if ((($len + $firstword < 68) and (substr($line, -1, 1) != ' '))
|
||||
// or ($quotelevel != $currquotelevel) or $specialchars)
|
||||
//if ((($len + $firstword < 68) && (substr($line, -1, 1) != ' '))
|
||||
// || ($quotelevel != $currquotelevel) || $specialchars)
|
||||
if (((substr($line, -1, 1) != ' '))
|
||||
or ($quotelevel != $currquotelevel))
|
||||
|| ($quotelevel != $currquotelevel))
|
||||
$lineno++;
|
||||
}
|
||||
return(implode("\n", $lines));
|
||||
|
|
|
@ -121,7 +121,7 @@ function nav_info(App $a)
|
|||
$nav['apps'] = array('apps', t('Apps'), '', t('Addon applications, utilities, games'));
|
||||
}
|
||||
|
||||
if (local_user() OR !get_config('system', 'local_search')) {
|
||||
if (local_user() || !get_config('system', 'local_search')) {
|
||||
$nav['search'] = array('search', t('Search'), '', t('Search site content'));
|
||||
|
||||
$nav['searchoption'] = array(
|
||||
|
|
|
@ -187,7 +187,7 @@ function z_fetch_url($url, $binary = false, &$redirects = 0, $opts = array()) {
|
|||
|
||||
$newurl = $curl_info['redirect_url'];
|
||||
|
||||
if (($new_location_info['path'] == '') AND ( $new_location_info['host'] != '')) {
|
||||
if (($new_location_info['path'] == '') && ( $new_location_info['host'] != '')) {
|
||||
$newurl = $new_location_info['scheme'] . '://' . $new_location_info['host'] . $old_location_info['path'];
|
||||
}
|
||||
|
||||
|
@ -818,8 +818,8 @@ function original_url($url, $depth = 1, $fetchbody = false) {
|
|||
if ($http_code == 0)
|
||||
return($url);
|
||||
|
||||
if ((($curl_info['http_code'] == "301") OR ($curl_info['http_code'] == "302"))
|
||||
AND (($curl_info['redirect_url'] != "") OR ($curl_info['location'] != ""))) {
|
||||
if ((($curl_info['http_code'] == "301") || ($curl_info['http_code'] == "302"))
|
||||
&& (($curl_info['redirect_url'] != "") || ($curl_info['location'] != ""))) {
|
||||
if ($curl_info['redirect_url'] != "")
|
||||
return(original_url($curl_info['redirect_url'], ++$depth, $fetchbody));
|
||||
else
|
||||
|
@ -835,7 +835,7 @@ function original_url($url, $depth = 1, $fetchbody = false) {
|
|||
return($url);
|
||||
|
||||
// if it isn't a HTML file then exit
|
||||
if (($curl_info["content_type"] != "") AND !strstr(strtolower($curl_info["content_type"]),"html"))
|
||||
if (($curl_info["content_type"] != "") && !strstr(strtolower($curl_info["content_type"]),"html"))
|
||||
return($url);
|
||||
|
||||
$stamp1 = microtime(true);
|
||||
|
@ -929,7 +929,7 @@ function json_return_and_die($x) {
|
|||
*/
|
||||
function matching_url($url1, $url2) {
|
||||
|
||||
if (($url1 == "") OR ($url2 == ""))
|
||||
if (($url1 == "") || ($url2 == ""))
|
||||
return "";
|
||||
|
||||
$url1 = normalise_link($url1);
|
||||
|
@ -938,7 +938,7 @@ function matching_url($url1, $url2) {
|
|||
$parts1 = parse_url($url1);
|
||||
$parts2 = parse_url($url2);
|
||||
|
||||
if (!isset($parts1["host"]) OR !isset($parts2["host"]))
|
||||
if (!isset($parts1["host"]) || !isset($parts2["host"]))
|
||||
return "";
|
||||
|
||||
if ($parts1["scheme"] != $parts2["scheme"])
|
||||
|
@ -967,7 +967,7 @@ function matching_url($url1, $url2) {
|
|||
if ($path1 == $path2)
|
||||
$path .= $path1."/";
|
||||
|
||||
} while (($path1 == $path2) AND ($i++ <= count($pathparts1)));
|
||||
} while (($path1 == $path2) && ($i++ <= count($pathparts1)));
|
||||
|
||||
$match .= $path;
|
||||
|
||||
|
|
|
@ -55,17 +55,6 @@ function notifier_run(&$argv, &$argc){
|
|||
return;
|
||||
}
|
||||
|
||||
// Inherit the priority
|
||||
$queue = dba::select('workerqueue', array('priority'), array('pid' => getmypid()), array('limit' => 1));
|
||||
if (dbm::is_result($queue)) {
|
||||
$priority = (int)$queue['priority'];
|
||||
logger('inherited priority: '.$priority);
|
||||
} else {
|
||||
// Normally this shouldn't happen.
|
||||
$priority = PRIORITY_HIGH;
|
||||
logger('no inherited priority! Something is wrong.');
|
||||
}
|
||||
|
||||
logger('notifier: invoked: ' . print_r($argv,true), LOGGER_DEBUG);
|
||||
|
||||
$cmd = $argv[1];
|
||||
|
@ -163,7 +152,7 @@ function notifier_run(&$argv, &$argc){
|
|||
$recipients_relocate = q("SELECT * FROM contact WHERE uid = %d AND self = 0 AND network = '%s'" , intval($uid), NETWORK_DFRN);
|
||||
} else {
|
||||
// find ancestors
|
||||
$r = q("SELECT * FROM `item` WHERE `id` = %d and visible = 1 and moderated = 0 LIMIT 1",
|
||||
$r = q("SELECT * FROM `item` WHERE `id` = %d AND visible = 1 AND moderated = 0 LIMIT 1",
|
||||
intval($item_id)
|
||||
);
|
||||
|
||||
|
@ -177,7 +166,7 @@ function notifier_run(&$argv, &$argc){
|
|||
$updated = $r[0]['edited'];
|
||||
|
||||
$items = q("SELECT `item`.*, `sign`.`signed_text`,`sign`.`signature`,`sign`.`signer`
|
||||
FROM `item` LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id` WHERE `parent` = %d and visible = 1 and moderated = 0 ORDER BY `id` ASC",
|
||||
FROM `item` LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id` WHERE `parent` = %d AND visible = 1 AND moderated = 0 ORDER BY `id` ASC",
|
||||
intval($parent_id)
|
||||
);
|
||||
|
||||
|
@ -306,13 +295,13 @@ function notifier_run(&$argv, &$argc){
|
|||
$recipients = array($parent['contact-id']);
|
||||
$recipients_followup = array($parent['contact-id']);
|
||||
|
||||
//if (!$target_item['private'] AND $target_item['wall'] AND
|
||||
if (!$target_item['private'] AND
|
||||
//if (!$target_item['private'] && $target_item['wall'] &&
|
||||
if (!$target_item['private'] &&
|
||||
(strlen($target_item['allow_cid'].$target_item['allow_gid'].
|
||||
$target_item['deny_cid'].$target_item['deny_gid']) == 0))
|
||||
$push_notify = true;
|
||||
|
||||
if (($thr_parent AND ($thr_parent[0]['network'] == NETWORK_OSTATUS)) OR ($parent['network'] == NETWORK_OSTATUS)) {
|
||||
if (($thr_parent && ($thr_parent[0]['network'] == NETWORK_OSTATUS)) || ($parent['network'] == NETWORK_OSTATUS)) {
|
||||
|
||||
$push_notify = true;
|
||||
|
||||
|
@ -359,7 +348,7 @@ function notifier_run(&$argv, &$argc){
|
|||
// a delivery fork. private groups (forum_mode == 2) do not uplink
|
||||
|
||||
if ((intval($parent['forum_mode']) == 1) && (! $top_level) && ($cmd !== 'uplink')) {
|
||||
proc_run($priority, 'include/notifier.php', 'uplink', $item_id);
|
||||
proc_run($a->queue['priority'], 'include/notifier.php', 'uplink', $item_id);
|
||||
}
|
||||
|
||||
$conversants = array();
|
||||
|
@ -396,7 +385,7 @@ function notifier_run(&$argv, &$argc){
|
|||
|
||||
// If the thread parent is OStatus then do some magic to distribute the messages.
|
||||
// We have not only to look at the parent, since it could be a Friendica thread.
|
||||
if (($thr_parent AND ($thr_parent[0]['network'] == NETWORK_OSTATUS)) OR ($parent['network'] == NETWORK_OSTATUS)) {
|
||||
if (($thr_parent && ($thr_parent[0]['network'] == NETWORK_OSTATUS)) || ($parent['network'] == NETWORK_OSTATUS)) {
|
||||
|
||||
$diaspora_delivery = false;
|
||||
|
||||
|
@ -498,7 +487,8 @@ function notifier_run(&$argv, &$argc){
|
|||
}
|
||||
logger("Deliver ".$target_item["guid"]." to ".$contact['url']." via network ".$contact['network'], LOGGER_DEBUG);
|
||||
|
||||
proc_run($priority, 'include/delivery.php', $cmd, $item_id, $contact['id']);
|
||||
proc_run(array('priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true),
|
||||
'include/delivery.php', $cmd, $item_id, (int)$contact['id']);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -529,8 +519,8 @@ function notifier_run(&$argv, &$argc){
|
|||
}
|
||||
|
||||
$r1 = q("SELECT `batch`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`name`) AS `name`, ANY_VALUE(`network`) AS `network`
|
||||
FROM `contact` WHERE `network` = '%s'
|
||||
AND `uid` = %d AND `rel` != %d AND NOT `blocked` AND NOT `pending` AND NOT `archive` GROUP BY `batch` ORDER BY rand()",
|
||||
FROM `contact` WHERE `network` = '%s' AND `batch` != ''
|
||||
AND `uid` = %d AND `rel` != %d AND NOT `blocked` AND NOT `pending` AND NOT `archive` GROUP BY `batch`",
|
||||
dbesc(NETWORK_DIASPORA),
|
||||
intval($owner['uid']),
|
||||
intval(CONTACT_IS_SHARING)
|
||||
|
@ -538,8 +528,7 @@ function notifier_run(&$argv, &$argc){
|
|||
}
|
||||
|
||||
$r2 = q("SELECT `id`, `name`,`network` FROM `contact`
|
||||
WHERE `network` in ( '%s', '%s') AND `uid` = %d AND NOT `blocked` AND NOT `pending` AND NOT `archive`
|
||||
AND `rel` != %d order by rand() ",
|
||||
WHERE `network` in ('%s', '%s') AND `uid` = %d AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND `rel` != %d",
|
||||
dbesc(NETWORK_DFRN),
|
||||
dbesc(NETWORK_MAIL2),
|
||||
intval($owner['uid']),
|
||||
|
@ -563,7 +552,8 @@ function notifier_run(&$argv, &$argc){
|
|||
|
||||
if ((! $mail) && (! $fsuggest) && (! $followup)) {
|
||||
logger('notifier: delivery agent: '.$rr['name'].' '.$rr['id'].' '.$rr['network'].' '.$target_item["guid"]);
|
||||
proc_run($priority, 'include/delivery.php', $cmd, $item_id, $rr['id']);
|
||||
proc_run(array('priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true),
|
||||
'include/delivery.php', $cmd, $item_id, (int)$rr['id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -573,7 +563,7 @@ function notifier_run(&$argv, &$argc){
|
|||
}
|
||||
|
||||
// Notify PuSH subscribers (Used for OStatus distribution of regular posts)
|
||||
if ($push_notify AND strlen($hub)) {
|
||||
if ($push_notify && strlen($hub)) {
|
||||
$hubs = explode(',', $hub);
|
||||
if (count($hubs)) {
|
||||
foreach ($hubs as $h) {
|
||||
|
@ -603,7 +593,8 @@ function notifier_run(&$argv, &$argc){
|
|||
}
|
||||
|
||||
// Handling the pubsubhubbub requests
|
||||
proc_run(PRIORITY_HIGH, 'include/pubsubpublish.php');
|
||||
proc_run(array('priority' => PRIORITY_HIGH, 'created' => $a->queue['created'], 'dont_fork' => true),
|
||||
'include/pubsubpublish.php');
|
||||
}
|
||||
|
||||
logger('notifier: calling hooks', LOGGER_DEBUG);
|
||||
|
|
|
@ -108,7 +108,7 @@ function oembed_fetch_url($embedurl, $no_rich_type = false){
|
|||
$j->embedurl = $embedurl;
|
||||
|
||||
// If fetching information doesn't work, then improve via internal functions
|
||||
if (($j->type == "error") OR ($no_rich_type AND ($j->type == "rich"))) {
|
||||
if (($j->type == "error") || ($no_rich_type && ($j->type == "rich"))) {
|
||||
$data = ParseUrl::getSiteinfoCached($embedurl, true, false);
|
||||
$j->type = $data["type"];
|
||||
|
||||
|
@ -194,7 +194,7 @@ function oembed_format_object($j){
|
|||
if (isset($j->author_name)) {
|
||||
$ret.=" (".$j->author_name.")";
|
||||
}
|
||||
} elseif (isset($j->provider_name) OR isset($j->author_name)) {
|
||||
} elseif (isset($j->provider_name) || isset($j->author_name)) {
|
||||
$embedlink = "";
|
||||
if (isset($j->provider_name)) {
|
||||
$embedlink .= $j->provider_name;
|
||||
|
|
|
@ -68,9 +68,9 @@ function onepoll_run(&$argv, &$argc){
|
|||
$contact = $contacts[0];
|
||||
|
||||
// load current friends if possible.
|
||||
if (($contact['poco'] != "") AND ($contact['success_update'] > $contact['failure_update'])) {
|
||||
$r = q("SELECT count(*) as total from glink
|
||||
where `cid` = %d and updated > UTC_TIMESTAMP() - INTERVAL 1 DAY",
|
||||
if (($contact['poco'] != "") && ($contact['success_update'] > $contact['failure_update'])) {
|
||||
$r = q("SELECT count(*) AS total FROM glink
|
||||
WHERE `cid` = %d AND updated > UTC_TIMESTAMP() - INTERVAL 1 DAY",
|
||||
intval($contact['id'])
|
||||
);
|
||||
if (dbm::is_result($r)) {
|
||||
|
@ -395,7 +395,7 @@ function onepoll_run(&$argv, &$argc){
|
|||
logger("Mail: Seen before ".$msg_uid." for ".$mailconf[0]['user']." UID: ".$importer_uid." URI: ".$datarray['uri'],LOGGER_DEBUG);
|
||||
|
||||
// Only delete when mails aren't automatically moved or deleted
|
||||
if (($mailconf[0]['action'] != 1) AND ($mailconf[0]['action'] != 3))
|
||||
if (($mailconf[0]['action'] != 1) && ($mailconf[0]['action'] != 3))
|
||||
if ($meta->deleted && ! $r[0]['deleted']) {
|
||||
q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `id` = %d",
|
||||
dbesc(datetime_convert()),
|
||||
|
@ -467,15 +467,15 @@ function onepoll_run(&$argv, &$argc){
|
|||
$datarray['created'] = datetime_convert('UTC','UTC',$meta->date);
|
||||
|
||||
// Is it a reply?
|
||||
$reply = ((substr(strtolower($datarray['title']), 0, 3) == "re:") or
|
||||
(substr(strtolower($datarray['title']), 0, 3) == "re-") or
|
||||
$reply = ((substr(strtolower($datarray['title']), 0, 3) == "re:") ||
|
||||
(substr(strtolower($datarray['title']), 0, 3) == "re-") ||
|
||||
($raw_refs != ""));
|
||||
|
||||
// Remove Reply-signs in the subject
|
||||
$datarray['title'] = RemoveReply($datarray['title']);
|
||||
|
||||
// If it seems to be a reply but a header couldn't be found take the last message with matching subject
|
||||
if (!x($datarray,'parent-uri') and $reply) {
|
||||
if (!x($datarray,'parent-uri') && $reply) {
|
||||
$r = q("SELECT `uri` , `parent-uri` FROM `item` WHERE `title` = \"%s\" AND `uid` = %d AND `network` = '%s' ORDER BY `created` DESC LIMIT 1",
|
||||
dbesc(protect_sprintf($datarray['title'])),
|
||||
intval($importer_uid),
|
||||
|
|
|
@ -54,7 +54,7 @@ class ostatus {
|
|||
$alternate = $xpath->query("atom:author/atom:link[@rel='alternate']", $context)->item(0)->attributes;
|
||||
if (is_object($alternate)) {
|
||||
foreach ($alternate AS $attributes) {
|
||||
if (($attributes->name == "href") AND ($attributes->textContent != "")) {
|
||||
if (($attributes->name == "href") && ($attributes->textContent != "")) {
|
||||
$author["author-link"] = $attributes->textContent;
|
||||
}
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ class ostatus {
|
|||
$width = $attributes->textContent;
|
||||
}
|
||||
}
|
||||
if (($width > 0) AND ($href != "")) {
|
||||
if (($width > 0) && ($href != "")) {
|
||||
$avatarlist[$width] = $href;
|
||||
}
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ class ostatus {
|
|||
$author["owner-avatar"] = $author["author-avatar"];
|
||||
|
||||
// Only update the contacts if it is an OStatus contact
|
||||
if ($r AND !$onlyfetch AND ($contact["network"] == NETWORK_OSTATUS)) {
|
||||
if ($r && !$onlyfetch && ($contact["network"] == NETWORK_OSTATUS)) {
|
||||
|
||||
// Update contact data
|
||||
|
||||
|
@ -153,8 +153,8 @@ class ostatus {
|
|||
if ($value != "")
|
||||
$contact["location"] = $value;
|
||||
|
||||
if (($contact["name"] != $r[0]["name"]) OR ($contact["nick"] != $r[0]["nick"]) OR ($contact["about"] != $r[0]["about"]) OR
|
||||
($contact["alias"] != $r[0]["alias"]) OR ($contact["location"] != $r[0]["location"])) {
|
||||
if (($contact["name"] != $r[0]["name"]) || ($contact["nick"] != $r[0]["nick"]) || ($contact["about"] != $r[0]["about"]) ||
|
||||
($contact["alias"] != $r[0]["alias"]) || ($contact["location"] != $r[0]["location"])) {
|
||||
|
||||
logger("Update contact data for contact ".$contact["id"], LOGGER_DEBUG);
|
||||
|
||||
|
@ -164,7 +164,7 @@ class ostatus {
|
|||
dbesc(datetime_convert()), intval($contact["id"]));
|
||||
}
|
||||
|
||||
if (isset($author["author-avatar"]) AND ($author["author-avatar"] != $r[0]['avatar'])) {
|
||||
if (isset($author["author-avatar"]) && ($author["author-avatar"] != $r[0]['avatar'])) {
|
||||
logger("Update profile picture for contact ".$contact["id"], LOGGER_DEBUG);
|
||||
|
||||
update_contact_avatar($author["author-avatar"], $importer["uid"], $contact["id"]);
|
||||
|
@ -354,13 +354,13 @@ class ostatus {
|
|||
$item["verb"] = $xpath->query('activity:verb/text()', $entry)->item(0)->nodeValue;
|
||||
|
||||
// Mastodon Content Warning
|
||||
if (($item["verb"] == ACTIVITY_POST) AND $xpath->evaluate('boolean(atom:summary)', $entry)) {
|
||||
if (($item["verb"] == ACTIVITY_POST) && $xpath->evaluate('boolean(atom:summary)', $entry)) {
|
||||
$clear_text = $xpath->query('atom:summary/text()', $entry)->item(0)->nodeValue;
|
||||
|
||||
$item["body"] = html2bbcode($clear_text) . '[spoiler]' . $item["body"] . '[/spoiler]';
|
||||
}
|
||||
|
||||
if (($item["object-type"] == ACTIVITY_OBJ_BOOKMARK) OR ($item["object-type"] == ACTIVITY_OBJ_EVENT)) {
|
||||
if (($item["object-type"] == ACTIVITY_OBJ_BOOKMARK) || ($item["object-type"] == ACTIVITY_OBJ_EVENT)) {
|
||||
$item["title"] = $xpath->query('atom:title/text()', $entry)->item(0)->nodeValue;
|
||||
$item["body"] = $xpath->query('atom:summary/text()', $entry)->item(0)->nodeValue;
|
||||
} elseif ($item["object-type"] == ACTIVITY_OBJ_QUESTION) {
|
||||
|
@ -469,11 +469,11 @@ class ostatus {
|
|||
foreach ($links AS $link) {
|
||||
$attribute = self::read_attributes($link);
|
||||
|
||||
if (($attribute['rel'] != "") AND ($attribute['href'] != "")) {
|
||||
if (($attribute['rel'] != "") && ($attribute['href'] != "")) {
|
||||
switch ($attribute['rel']) {
|
||||
case "alternate":
|
||||
$item["plink"] = $attribute['href'];
|
||||
if (($item["object-type"] == ACTIVITY_OBJ_QUESTION) OR
|
||||
if (($item["object-type"] == ACTIVITY_OBJ_QUESTION) ||
|
||||
($item["object-type"] == ACTIVITY_OBJ_EVENT)) {
|
||||
$item["body"] .= add_page_info($attribute['href']);
|
||||
}
|
||||
|
@ -525,7 +525,7 @@ class ostatus {
|
|||
$repeat_of = "";
|
||||
|
||||
$notice_info = $xpath->query('statusnet:notice_info', $entry);
|
||||
if ($notice_info AND ($notice_info->length > 0)) {
|
||||
if ($notice_info && ($notice_info->length > 0)) {
|
||||
foreach ($notice_info->item(0)->attributes AS $attributes) {
|
||||
if ($attributes->name == "source") {
|
||||
$item["app"] = strip_tags($attributes->textContent);
|
||||
|
@ -540,7 +540,7 @@ class ostatus {
|
|||
}
|
||||
|
||||
// Is it a repeated post?
|
||||
if (($repeat_of != "") OR ($item["verb"] == ACTIVITY_SHARE)) {
|
||||
if (($repeat_of != "") || ($item["verb"] == ACTIVITY_SHARE)) {
|
||||
$activityobjects = $xpath->query('activity:object', $entry)->item(0);
|
||||
|
||||
if (is_object($activityobjects)) {
|
||||
|
@ -550,7 +550,7 @@ class ostatus {
|
|||
$orig_uri = $xpath->query('atom:id/text()', $activityobjects)->item(0)->nodeValue;
|
||||
}
|
||||
$orig_links = $xpath->query("activity:object/atom:link[@rel='alternate']", $activityobjects);
|
||||
if ($orig_links AND ($orig_links->length > 0)) {
|
||||
if ($orig_links && ($orig_links->length > 0)) {
|
||||
foreach ($orig_links->item(0)->attributes AS $attributes) {
|
||||
if ($attributes->name == "href") {
|
||||
$orig_link = $attributes->textContent;
|
||||
|
@ -621,8 +621,8 @@ class ostatus {
|
|||
intval($importer["uid"]), dbesc($item["parent-uri"]));
|
||||
|
||||
// Only fetch missing stuff if it is a comment or reshare.
|
||||
if (in_array($item["verb"], array(ACTIVITY_POST, ACTIVITY_SHARE)) AND
|
||||
!dbm::is_result($r) AND ($related != "")) {
|
||||
if (in_array($item["verb"], array(ACTIVITY_POST, ACTIVITY_SHARE)) &&
|
||||
!dbm::is_result($r) && ($related != "")) {
|
||||
$reply_path = str_replace("/notice/", "/api/statuses/show/", $related).".atom";
|
||||
|
||||
if ($reply_path != $related) {
|
||||
|
@ -668,16 +668,16 @@ class ostatus {
|
|||
public static function convert_href($href) {
|
||||
$elements = explode(":",$href);
|
||||
|
||||
if ((count($elements) <= 2) OR ($elements[0] != "tag"))
|
||||
if ((count($elements) <= 2) || ($elements[0] != "tag"))
|
||||
return $href;
|
||||
|
||||
$server = explode(",", $elements[1]);
|
||||
$conversation = explode("=", $elements[2]);
|
||||
|
||||
if ((count($elements) == 4) AND ($elements[2] == "post"))
|
||||
if ((count($elements) == 4) && ($elements[2] == "post"))
|
||||
return "http://".$server[0]."/notice/".$elements[3];
|
||||
|
||||
if ((count($conversation) != 2) OR ($conversation[1] ==""))
|
||||
if ((count($conversation) != 2) || ($conversation[1] ==""))
|
||||
return $href;
|
||||
|
||||
if ($elements[3] == "objectType=thread")
|
||||
|
@ -703,7 +703,7 @@ class ostatus {
|
|||
}
|
||||
|
||||
// Don't poll if the interval is set negative
|
||||
if (($poll_interval < 0) AND !$override) {
|
||||
if (($poll_interval < 0) && !$override) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -720,7 +720,7 @@ class ostatus {
|
|||
}
|
||||
|
||||
|
||||
if ($last AND !$override) {
|
||||
if ($last && !$override) {
|
||||
$next = $last + ($poll_interval * 60);
|
||||
if ($next > time()) {
|
||||
logger('poll interval not reached');
|
||||
|
@ -818,7 +818,7 @@ class ostatus {
|
|||
if ($conversation_id != "") {
|
||||
$elements = explode(":", $conversation_id);
|
||||
|
||||
if ((count($elements) <= 2) OR ($elements[0] != "tag"))
|
||||
if ((count($elements) <= 2) || ($elements[0] != "tag"))
|
||||
return $conversation_id;
|
||||
}
|
||||
|
||||
|
@ -933,8 +933,8 @@ class ostatus {
|
|||
|
||||
// If the thread shouldn't be completed then store the item and go away
|
||||
// Don't do a completion on liked content
|
||||
if (((intval(get_config('system','ostatus_poll_interval')) == -2) AND (count($item) > 0)) OR
|
||||
($item["verb"] == ACTIVITY_LIKE) OR ($conversation_url == "")) {
|
||||
if (((intval(get_config('system','ostatus_poll_interval')) == -2) && (count($item) > 0)) ||
|
||||
($item["verb"] == ACTIVITY_LIKE) || ($conversation_url == "")) {
|
||||
$item_stored = item_store($item, $all_threads);
|
||||
return $item_stored;
|
||||
}
|
||||
|
@ -979,10 +979,10 @@ class ostatus {
|
|||
$conv_arr = z_fetch_url($conv."?page=".$pageno);
|
||||
|
||||
// If it is a non-ssl site and there is an error, then try ssl or vice versa
|
||||
if (!$conv_arr["success"] AND (substr($conv, 0, 7) == "http://")) {
|
||||
if (!$conv_arr["success"] && (substr($conv, 0, 7) == "http://")) {
|
||||
$conv = str_replace("http://", "https://", $conv);
|
||||
$conv_as = fetch_url($conv."?page=".$pageno);
|
||||
} elseif (!$conv_arr["success"] AND (substr($conv, 0, 8) == "https://")) {
|
||||
} elseif (!$conv_arr["success"] && (substr($conv, 0, 8) == "https://")) {
|
||||
$conv = str_replace("https://", "http://", $conv);
|
||||
$conv_as = fetch_url($conv."?page=".$pageno);
|
||||
} else
|
||||
|
@ -1057,7 +1057,7 @@ class ostatus {
|
|||
// 1. Our conversation hasn't the "real" thread starter
|
||||
// 2. This first post is a post inside our thread
|
||||
// 3. This first post is a post inside another thread
|
||||
if (($first_id != $parent["uri"]) AND ($parent["uri"] != "")) {
|
||||
if (($first_id != $parent["uri"]) && ($parent["uri"] != "")) {
|
||||
|
||||
$new_parent = true;
|
||||
|
||||
|
@ -1144,7 +1144,7 @@ class ostatus {
|
|||
}
|
||||
|
||||
// The item we are having on the system is the one that we wanted to store via the item array
|
||||
if (isset($item["uri"]) AND ($item["uri"] == $existing_message["uri"])) {
|
||||
if (isset($item["uri"]) && ($item["uri"] == $existing_message["uri"])) {
|
||||
$item = array();
|
||||
$item_stored = 0;
|
||||
}
|
||||
|
@ -1164,7 +1164,7 @@ class ostatus {
|
|||
$details = self::get_actor_details($actor, $uid, $parent["contact-id"]);
|
||||
|
||||
// Do we only want to import threads that were started by our contacts?
|
||||
if ($details["not_following"] AND $new_parent AND get_config('system','ostatus_full_threads')) {
|
||||
if ($details["not_following"] && $new_parent && get_config('system','ostatus_full_threads')) {
|
||||
logger("Don't import uri ".$first_id." because user ".$uid." doesn't follow the person ".$actor, LOGGER_DEBUG);
|
||||
continue;
|
||||
}
|
||||
|
@ -1218,7 +1218,7 @@ class ostatus {
|
|||
$arr["coord"] = trim($single_conv->location->lat." ".$single_conv->location->lon);
|
||||
|
||||
// Is it a reshared item?
|
||||
if (isset($single_conv->verb) AND ($single_conv->verb == "share") AND isset($single_conv->object)) {
|
||||
if (isset($single_conv->verb) && ($single_conv->verb == "share") && isset($single_conv->object)) {
|
||||
if (is_array($single_conv->object))
|
||||
$single_conv->object = $single_conv->object[0];
|
||||
|
||||
|
@ -1277,7 +1277,7 @@ class ostatus {
|
|||
unset($arr["coord"]);
|
||||
|
||||
// Copy fields from given item array
|
||||
if (isset($item["uri"]) AND (($item["uri"] == $arr["uri"]) OR ($item["uri"] == $single_conv->id))) {
|
||||
if (isset($item["uri"]) && (($item["uri"] == $arr["uri"]) || ($item["uri"] == $single_conv->id))) {
|
||||
logger('Use stored item array for item with URI '.$item["uri"], LOGGER_DEBUG);
|
||||
$newitem = item_store($item);
|
||||
$item = array();
|
||||
|
@ -1307,7 +1307,7 @@ class ostatus {
|
|||
}
|
||||
}
|
||||
|
||||
if (($item_stored < 0) AND (count($item) > 0)) {
|
||||
if (($item_stored < 0) && (count($item) > 0)) {
|
||||
|
||||
if (get_config('system','ostatus_full_threads')) {
|
||||
$details = self::get_actor_details($item["owner-link"], $uid, $item["contact-id"]);
|
||||
|
@ -1543,7 +1543,7 @@ class ostatus {
|
|||
break;
|
||||
}
|
||||
|
||||
if (($siteinfo["type"] != "photo") AND isset($siteinfo["image"])) {
|
||||
if (($siteinfo["type"] != "photo") && isset($siteinfo["image"])) {
|
||||
$imgdata = get_photo_info($siteinfo["image"]);
|
||||
$attributes = array("rel" => "enclosure",
|
||||
"href" => $siteinfo["image"],
|
||||
|
@ -1788,7 +1788,7 @@ class ostatus {
|
|||
*/
|
||||
private function reshare_entry($doc, $item, $owner, $repeated_guid, $toplevel) {
|
||||
|
||||
if (($item["id"] != $item["parent"]) AND (normalise_link($item["author-link"]) != normalise_link($owner["url"]))) {
|
||||
if (($item["id"] != $item["parent"]) && (normalise_link($item["author-link"]) != normalise_link($owner["url"]))) {
|
||||
logger("OStatus entry is from author ".$owner["url"]." - not from ".$item["author-link"].". Quitting.", LOGGER_DEBUG);
|
||||
}
|
||||
|
||||
|
@ -1854,7 +1854,7 @@ class ostatus {
|
|||
*/
|
||||
private function like_entry($doc, $item, $owner, $toplevel) {
|
||||
|
||||
if (($item["id"] != $item["parent"]) AND (normalise_link($item["author-link"]) != normalise_link($owner["url"]))) {
|
||||
if (($item["id"] != $item["parent"]) && (normalise_link($item["author-link"]) != normalise_link($owner["url"]))) {
|
||||
logger("OStatus entry is from author ".$owner["url"]." - not from ".$item["author-link"].". Quitting.", LOGGER_DEBUG);
|
||||
}
|
||||
|
||||
|
@ -1999,7 +1999,7 @@ class ostatus {
|
|||
*/
|
||||
private function note_entry($doc, $item, $owner, $toplevel) {
|
||||
|
||||
if (($item["id"] != $item["parent"]) AND (normalise_link($item["author-link"]) != normalise_link($owner["url"]))) {
|
||||
if (($item["id"] != $item["parent"]) && (normalise_link($item["author-link"]) != normalise_link($owner["url"]))) {
|
||||
logger("OStatus entry is from author ".$owner["url"]." - not from ".$item["author-link"].". Quitting.", LOGGER_DEBUG);
|
||||
}
|
||||
|
||||
|
@ -2080,7 +2080,7 @@ class ostatus {
|
|||
xml::add_element($doc, $entry, "link", "", array("rel" => "alternate", "type" => "text/html",
|
||||
"href" => App::get_baseurl()."/display/".$item["guid"]));
|
||||
|
||||
if ($complete AND ($item["id"] > 0))
|
||||
if ($complete && ($item["id"] > 0))
|
||||
xml::add_element($doc, $entry, "status_net", "", array("notice_id" => $item["id"]));
|
||||
|
||||
xml::add_element($doc, $entry, "activity:verb", $verb);
|
||||
|
@ -2102,7 +2102,7 @@ class ostatus {
|
|||
|
||||
$mentioned = array();
|
||||
|
||||
if (($item['parent'] != $item['id']) OR ($item['parent-uri'] !== $item['uri']) OR (($item['thr-parent'] !== '') AND ($item['thr-parent'] !== $item['uri']))) {
|
||||
if (($item['parent'] != $item['id']) || ($item['parent-uri'] !== $item['uri']) || (($item['thr-parent'] !== '') && ($item['thr-parent'] !== $item['uri']))) {
|
||||
$parent = q("SELECT `guid`, `author-link`, `owner-link` FROM `item` WHERE `id` = %d", intval($item["parent"]));
|
||||
$parent_item = (($item['thr-parent']) ? $item['thr-parent'] : $item['parent-uri']);
|
||||
|
||||
|
@ -2175,7 +2175,7 @@ class ostatus {
|
|||
$r = q("SELECT `forum`, `prv` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s'",
|
||||
intval($owner["uid"]),
|
||||
dbesc(normalise_link($mention)));
|
||||
if ($r[0]["forum"] OR $r[0]["prv"])
|
||||
if ($r[0]["forum"] || $r[0]["prv"])
|
||||
xml::add_element($doc, $entry, "link", "", array("rel" => "mentioned",
|
||||
"ostatus:object-type" => ACTIVITY_OBJ_GROUP,
|
||||
"href" => $mention));
|
||||
|
@ -2201,7 +2201,7 @@ class ostatus {
|
|||
|
||||
self::get_attachment($doc, $entry, $item);
|
||||
|
||||
if ($complete AND ($item["id"] > 0)) {
|
||||
if ($complete && ($item["id"] > 0)) {
|
||||
$app = $item["app"];
|
||||
if ($app == "")
|
||||
$app = "web";
|
||||
|
|
|
@ -91,7 +91,6 @@ function pop_lang() {
|
|||
$lang = $a->langsave;
|
||||
}
|
||||
|
||||
|
||||
// l
|
||||
|
||||
if (! function_exists('load_translation_table')) {
|
||||
|
|
|
@ -12,7 +12,7 @@ function getGps($exifCoord, $hemi) {
|
|||
$minutes = count($exifCoord) > 1 ? gps2Num($exifCoord[1]) : 0;
|
||||
$seconds = count($exifCoord) > 2 ? gps2Num($exifCoord[2]) : 0;
|
||||
|
||||
$flip = ($hemi == 'W' or $hemi == 'S') ? -1 : 1;
|
||||
$flip = ($hemi == 'W' || $hemi == 'S') ? -1 : 1;
|
||||
|
||||
return floatval($flip * ($degrees + ($minutes / 60) + ($seconds / 3600)));
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ function photo_albums($uid, $update = false) {
|
|||
|
||||
$key = "photo_albums:".$uid.":".local_user().":".remote_user();
|
||||
$albums = Cache::get($key);
|
||||
if (is_null($albums) OR $update) {
|
||||
if (is_null($albums) || $update) {
|
||||
if (!Config::get('system', 'no_count', false)) {
|
||||
/// @todo This query needs to be renewed. It is really slow
|
||||
// At this time we just store the data in the cache
|
||||
|
|
|
@ -8,7 +8,7 @@ class pidfile {
|
|||
|
||||
if (file_exists($this->_file)) {
|
||||
$pid = trim(@file_get_contents($this->_file));
|
||||
if (($pid != "") AND posix_kill($pid, 0)) {
|
||||
if (($pid != "") && posix_kill($pid, 0)) {
|
||||
$this->_running = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ function get_old_attachment_data($body) {
|
|||
|
||||
$picturedata = get_photo_info($matches[1]);
|
||||
|
||||
if (($picturedata[0] >= 500) AND ($picturedata[0] >= $picturedata[1]))
|
||||
if (($picturedata[0] >= 500) && ($picturedata[0] >= $picturedata[1]))
|
||||
$post["image"] = $matches[1];
|
||||
else
|
||||
$post["preview"] = $matches[1];
|
||||
|
@ -64,8 +64,8 @@ function get_old_attachment_data($body) {
|
|||
$post["url"] = $matches[1];
|
||||
$post["title"] = $matches[2];
|
||||
}
|
||||
if (($post["url"] == "") AND (in_array($post["type"], array("link", "video")))
|
||||
AND preg_match("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", $attacheddata, $matches)) {
|
||||
if (($post["url"] == "") && (in_array($post["type"], array("link", "video")))
|
||||
&& preg_match("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", $attacheddata, $matches)) {
|
||||
$post["url"] = $matches[1];
|
||||
}
|
||||
|
||||
|
@ -204,7 +204,7 @@ function get_attached_data($body) {
|
|||
// Workaround:
|
||||
// Sometimes photo posts to the own album are not detected at the start.
|
||||
// So we seem to cannot use the cache for these cases. That's strange.
|
||||
if (($data["type"] != "photo") AND strstr($pictures[0][1], "/photos/"))
|
||||
if (($data["type"] != "photo") && strstr($pictures[0][1], "/photos/"))
|
||||
$data = ParseUrl::getSiteinfo($pictures[0][1], true);
|
||||
|
||||
if ($data["type"] == "photo") {
|
||||
|
@ -256,7 +256,7 @@ function get_attached_data($body) {
|
|||
$post["type"] = "text";
|
||||
$post["text"] = trim($body);
|
||||
}
|
||||
} elseif (isset($post["url"]) AND ($post["type"] == "video")) {
|
||||
} elseif (isset($post["url"]) && ($post["type"] == "video")) {
|
||||
$data = ParseUrl::getSiteinfoCached($post["url"], true);
|
||||
|
||||
if (isset($data["images"][0]))
|
||||
|
@ -278,7 +278,7 @@ function shortenmsg($msg, $limit, $twitter = false) {
|
|||
if (iconv_strlen(trim($msg."\n".$line), "UTF-8") <= $limit)
|
||||
$msg = trim($msg."\n".$line);
|
||||
// Is the new message empty by now or is it a reshared message?
|
||||
elseif (($msg == "") OR (($row == 1) AND (substr($msg, 0, 4) == $recycle)))
|
||||
elseif (($msg == "") || (($row == 1) && (substr($msg, 0, 4) == $recycle)))
|
||||
$msg = iconv_substr(iconv_substr(trim($msg."\n".$line), 0, $limit, "UTF-8"), 0, -3, "UTF-8").$ellipsis;
|
||||
else
|
||||
break;
|
||||
|
@ -315,7 +315,7 @@ function plaintext(App $a, $b, $limit = 0, $includedlinks = false, $htmlmode = 2
|
|||
//$post = get_attached_data($b["body"]);
|
||||
$post = get_attached_data($body);
|
||||
|
||||
if (($b["title"] != "") AND ($post["text"] != ""))
|
||||
if (($b["title"] != "") && ($post["text"] != ""))
|
||||
$post["text"] = trim($b["title"]."\n\n".$post["text"]);
|
||||
elseif ($b["title"] != "")
|
||||
$post["text"] = trim($b["title"]);
|
||||
|
@ -329,7 +329,7 @@ function plaintext(App $a, $b, $limit = 0, $includedlinks = false, $htmlmode = 2
|
|||
|
||||
// If we post to a network with no limit we only fetch
|
||||
// an abstract exactly for this network
|
||||
if (($limit == 0) AND ($abstract == $default_abstract))
|
||||
if (($limit == 0) && ($abstract == $default_abstract))
|
||||
$abstract = "";
|
||||
|
||||
} else // Try to guess the correct target network
|
||||
|
@ -373,25 +373,25 @@ function plaintext(App $a, $b, $limit = 0, $includedlinks = false, $htmlmode = 2
|
|||
elseif ($post["type"] == "photo")
|
||||
$link = $post["image"];
|
||||
|
||||
if (($msg == "") AND isset($post["title"]))
|
||||
if (($msg == "") && isset($post["title"]))
|
||||
$msg = trim($post["title"]);
|
||||
|
||||
if (($msg == "") AND isset($post["description"]))
|
||||
if (($msg == "") && isset($post["description"]))
|
||||
$msg = trim($post["description"]);
|
||||
|
||||
// If the link is already contained in the post, then it neeedn't to be added again
|
||||
// But: if the link is beyond the limit, then it has to be added.
|
||||
if (($link != "") AND strstr($msg, $link)) {
|
||||
if (($link != "") && strstr($msg, $link)) {
|
||||
$pos = strpos($msg, $link);
|
||||
|
||||
// Will the text be shortened in the link?
|
||||
// Or is the link the last item in the post?
|
||||
if (($limit > 0) AND ($pos < $limit) AND (($pos + 23 > $limit) OR ($pos + strlen($link) == strlen($msg))))
|
||||
if (($limit > 0) && ($pos < $limit) && (($pos + 23 > $limit) || ($pos + strlen($link) == strlen($msg))))
|
||||
$msg = trim(str_replace($link, "", $msg));
|
||||
elseif (($limit == 0) OR ($pos < $limit)) {
|
||||
elseif (($limit == 0) || ($pos < $limit)) {
|
||||
// The limit has to be increased since it will be shortened - but not now
|
||||
// Only do it with Twitter (htmlmode = 8)
|
||||
if (($limit > 0) AND (strlen($link) > 23) AND ($htmlmode == 8))
|
||||
if (($limit > 0) && (strlen($link) > 23) && ($htmlmode == 8))
|
||||
$limit = $limit - 23 + strlen($link);
|
||||
|
||||
$link = "";
|
||||
|
@ -414,7 +414,7 @@ function plaintext(App $a, $b, $limit = 0, $includedlinks = false, $htmlmode = 2
|
|||
|
||||
if (iconv_strlen($msg, "UTF-8") > $limit) {
|
||||
|
||||
if (($post["type"] == "text") AND isset($post["url"]))
|
||||
if (($post["type"] == "text") && isset($post["url"]))
|
||||
$post["url"] = $b["plink"];
|
||||
elseif (!isset($post["url"])) {
|
||||
$limit = $limit - 23;
|
||||
|
|
|
@ -563,7 +563,7 @@ function theme_include($file, $root = '') {
|
|||
$root = $root . '/';
|
||||
}
|
||||
$theme_info = $a->theme_info;
|
||||
if (is_array($theme_info) AND array_key_exists('extends',$theme_info)) {
|
||||
if (is_array($theme_info) && array_key_exists('extends',$theme_info)) {
|
||||
$parent = $theme_info['extends'];
|
||||
} else {
|
||||
$parent = 'NOPATH';
|
||||
|
|
|
@ -2,13 +2,14 @@
|
|||
|
||||
use Friendica\App;
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Util\Lock;
|
||||
|
||||
if (!file_exists("boot.php") AND (sizeof($_SERVER["argv"]) != 0)) {
|
||||
if (!file_exists("boot.php") && (sizeof($_SERVER["argv"]) != 0)) {
|
||||
$directory = dirname($_SERVER["argv"][0]);
|
||||
|
||||
if (substr($directory, 0, 1) != "/")
|
||||
if (substr($directory, 0, 1) != "/") {
|
||||
$directory = $_SERVER["PWD"]."/".$directory;
|
||||
|
||||
}
|
||||
$directory = realpath($directory."/..");
|
||||
|
||||
chdir($directory);
|
||||
|
@ -17,18 +18,16 @@ if (!file_exists("boot.php") AND (sizeof($_SERVER["argv"]) != 0)) {
|
|||
require_once("boot.php");
|
||||
|
||||
function poller_run($argv, $argc){
|
||||
global $a, $db;
|
||||
global $a, $db, $poller_up_start, $poller_db_duration;
|
||||
|
||||
if (is_null($a)) {
|
||||
$a = new App(dirname(__DIR__));
|
||||
}
|
||||
$poller_up_start = microtime(true);
|
||||
|
||||
if (is_null($db)) {
|
||||
@include(".htconfig.php");
|
||||
require_once("include/dba.php");
|
||||
$db = new dba($db_host, $db_user, $db_pass, $db_data);
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
};
|
||||
$a = new App(dirname(__DIR__));
|
||||
|
||||
@include(".htconfig.php");
|
||||
require_once("include/dba.php");
|
||||
$db = new dba($db_host, $db_user, $db_pass, $db_data);
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
|
||||
Config::load();
|
||||
|
||||
|
@ -41,68 +40,147 @@ function poller_run($argv, $argc){
|
|||
|
||||
load_hooks();
|
||||
|
||||
// At first check the maximum load. We shouldn't continue with a high load
|
||||
if ($a->maxload_reached()) {
|
||||
logger('Pre check: maximum load reached, quitting.', LOGGER_DEBUG);
|
||||
return;
|
||||
}
|
||||
|
||||
// We now start the process. This is done after the load check since this could increase the load.
|
||||
$a->start_process();
|
||||
|
||||
if ($a->min_memory_reached()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (poller_max_connections_reached()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($a->maxload_reached()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (($argc <= 1) OR ($argv[1] != "no_cron")) {
|
||||
poller_run_cron();
|
||||
}
|
||||
|
||||
if ($a->max_processes_reached()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Checking the number of workers
|
||||
if (poller_too_much_workers()) {
|
||||
// Kill stale processes every 5 minutes
|
||||
$last_cleanup = Config::get('system', 'poller_last_cleaned', 0);
|
||||
if (time() > ($last_cleanup + 300)) {
|
||||
Config::set('system', 'poller_last_cleaned', time());
|
||||
poller_kill_stale_workers();
|
||||
}
|
||||
|
||||
// Count active workers and compare them with a maximum value that depends on the load
|
||||
if (poller_too_much_workers()) {
|
||||
logger('Pre check: Active worker limit reached, quitting.', LOGGER_DEBUG);
|
||||
return;
|
||||
}
|
||||
|
||||
// Do we have too few memory?
|
||||
if ($a->min_memory_reached()) {
|
||||
logger('Pre check: Memory limit reached, quitting.', LOGGER_DEBUG);
|
||||
return;
|
||||
}
|
||||
|
||||
// Possibly there are too much database connections
|
||||
if (poller_max_connections_reached()) {
|
||||
logger('Pre check: maximum connections reached, quitting.', LOGGER_DEBUG);
|
||||
return;
|
||||
}
|
||||
|
||||
// Possibly there are too much database processes that block the system
|
||||
if ($a->max_processes_reached()) {
|
||||
logger('Pre check: maximum processes reached, quitting.', LOGGER_DEBUG);
|
||||
return;
|
||||
}
|
||||
|
||||
// Now we start additional cron processes if we should do so
|
||||
if (($argc <= 1) || ($argv[1] != "no_cron")) {
|
||||
poller_run_cron();
|
||||
}
|
||||
|
||||
$starttime = time();
|
||||
|
||||
while ($r = poller_worker_process()) {
|
||||
// We fetch the next queue entry that is about to be executed
|
||||
while ($r = poller_worker_process($passing_slow)) {
|
||||
|
||||
if (!poller_claim_process($r[0])) {
|
||||
continue;
|
||||
// When we are processing jobs with a lower priority, we don't refetch new jobs
|
||||
// Otherwise fast jobs could wait behind slow ones and could be blocked.
|
||||
$refetched = $passing_slow;
|
||||
|
||||
foreach ($r AS $entry) {
|
||||
// Assure that the priority is an integer value
|
||||
$entry['priority'] = (int)$entry['priority'];
|
||||
|
||||
// The work will be done
|
||||
if (!poller_execute($entry)) {
|
||||
logger('Process execution failed, quitting.', LOGGER_DEBUG);
|
||||
return;
|
||||
}
|
||||
|
||||
// If possible we will fetch new jobs for this worker
|
||||
if (!$refetched && Lock::set('poller_worker_process', 0)) {
|
||||
$stamp = (float)microtime(true);
|
||||
$refetched = find_worker_processes($passing_slow);
|
||||
$poller_db_duration += (microtime(true) - $stamp);
|
||||
Lock::remove('poller_worker_process');
|
||||
}
|
||||
}
|
||||
|
||||
// Check free memory
|
||||
if ($a->min_memory_reached()) {
|
||||
logger('Memory limit reached, quitting.', LOGGER_DEBUG);
|
||||
return;
|
||||
// To avoid the quitting of multiple pollers only one poller at a time will execute the check
|
||||
if (Lock::set('poller_worker', 0)) {
|
||||
$stamp = (float)microtime(true);
|
||||
// Count active workers and compare them with a maximum value that depends on the load
|
||||
if (poller_too_much_workers()) {
|
||||
logger('Active worker limit reached, quitting.', LOGGER_DEBUG);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check free memory
|
||||
if ($a->min_memory_reached()) {
|
||||
logger('Memory limit reached, quitting.', LOGGER_DEBUG);
|
||||
return;
|
||||
}
|
||||
Lock::remove('poller_worker');
|
||||
$poller_db_duration += (microtime(true) - $stamp);
|
||||
}
|
||||
|
||||
// Count active workers and compare them with a maximum value that depends on the load
|
||||
if (poller_too_much_workers()) {
|
||||
logger('Active worker limit reached, quitting.', LOGGER_DEBUG);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!poller_execute($r[0])) {
|
||||
logger('Process execution failed, quitting.', LOGGER_DEBUG);
|
||||
return;
|
||||
}
|
||||
|
||||
// Quit the poller once every hour
|
||||
if (time() > ($starttime + 3600)) {
|
||||
logger('Process lifetime reachted, quitting.', LOGGER_DEBUG);
|
||||
// Quit the poller once every 5 minutes
|
||||
if (time() > ($starttime + 300)) {
|
||||
logger('Process lifetime reached, quitting.', LOGGER_DEBUG);
|
||||
return;
|
||||
}
|
||||
}
|
||||
logger("Couldn't select a workerqueue entry, quitting.", LOGGER_DEBUG);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the number of non executed entries in the worker queue
|
||||
*
|
||||
* @return integer Number of non executed entries in the worker queue
|
||||
*/
|
||||
function poller_total_entries() {
|
||||
$s = q("SELECT COUNT(*) AS `total` FROM `workerqueue` WHERE `executed` <= '%s' AND NOT `done`", dbesc(NULL_DATE));
|
||||
if (dbm::is_result($s)) {
|
||||
return $s[0]["total"];
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the highest priority in the worker queue that isn't executed
|
||||
*
|
||||
* @return integer Number of active poller processes
|
||||
*/
|
||||
function poller_highest_priority() {
|
||||
$s = q("SELECT `priority` FROM `workerqueue` WHERE `executed` <= '%s' AND NOT `done` ORDER BY `priority` LIMIT 1", dbesc(NULL_DATE));
|
||||
if (dbm::is_result($s)) {
|
||||
return $s[0]["priority"];
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns if a process with the given priority is running
|
||||
*
|
||||
* @param integer $priority The priority that should be checked
|
||||
*
|
||||
* @return integer Is there a process running with that priority?
|
||||
*/
|
||||
function poller_process_with_priority_active($priority) {
|
||||
$s = q("SELECT `id` FROM `workerqueue` WHERE `priority` <= %d AND `executed` > '%s' AND NOT `done` LIMIT 1",
|
||||
intval($priority), dbesc(NULL_DATE));
|
||||
return dbm::is_result($s);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Execute a worker entry
|
||||
*
|
||||
|
@ -111,6 +189,7 @@ function poller_run($argv, $argc){
|
|||
* @return boolean "true" if further processing should be stopped
|
||||
*/
|
||||
function poller_execute($queue) {
|
||||
global $poller_db_duration, $poller_last_update;
|
||||
|
||||
$a = get_app();
|
||||
|
||||
|
@ -151,10 +230,28 @@ function poller_execute($queue) {
|
|||
|
||||
if (function_exists($funcname)) {
|
||||
|
||||
// We constantly update the "executed" date every minute to avoid being killed too soon
|
||||
if (!isset($poller_last_update)) {
|
||||
$poller_last_update = strtotime($queue["executed"]);
|
||||
}
|
||||
|
||||
$age = (time() - $poller_last_update) / 60;
|
||||
$poller_last_update = time();
|
||||
|
||||
if ($age > 1) {
|
||||
$stamp = (float)microtime(true);
|
||||
dba::update('workerqueue', array('executed' => datetime_convert()), array('pid' => $mypid, 'done' => false));
|
||||
$poller_db_duration += (microtime(true) - $stamp);
|
||||
}
|
||||
|
||||
poller_exec_function($queue, $funcname, $argv);
|
||||
dba::delete('workerqueue', array('id' => $queue["id"]));
|
||||
|
||||
$stamp = (float)microtime(true);
|
||||
dba::update('workerqueue', array('done' => true), array('id' => $queue["id"]));
|
||||
$poller_db_duration = (microtime(true) - $stamp);
|
||||
} else {
|
||||
logger("Function ".$funcname." does not exist");
|
||||
dba::delete('workerqueue', array('id' => $queue["id"]));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -168,6 +265,7 @@ function poller_execute($queue) {
|
|||
* @param array $argv Array of values to be passed to the function
|
||||
*/
|
||||
function poller_exec_function($queue, $funcname, $argv) {
|
||||
global $poller_up_start, $poller_db_duration, $poller_lock_duration;
|
||||
|
||||
$a = get_app();
|
||||
|
||||
|
@ -198,13 +296,30 @@ function poller_exec_function($queue, $funcname, $argv) {
|
|||
// But preserve the old one for the worker
|
||||
$old_process_id = $a->process_id;
|
||||
$a->process_id = uniqid("wrk", true);
|
||||
$a->queue = $queue;
|
||||
|
||||
$up_duration = number_format(microtime(true) - $poller_up_start, 3);
|
||||
|
||||
$funcname($argv, $argc);
|
||||
|
||||
$a->process_id = $old_process_id;
|
||||
unset($a->queue);
|
||||
|
||||
$duration = number_format(microtime(true) - $stamp, 3);
|
||||
|
||||
$poller_up_start = microtime(true);
|
||||
|
||||
/* With these values we can analyze how effective the worker is.
|
||||
* The database and rest time should be low since this is the unproductive time.
|
||||
* The execution time is the productive time.
|
||||
* By changing parameters like the maximum number of workers we can check the effectivness.
|
||||
*/
|
||||
logger('DB: '.number_format($poller_db_duration, 2).
|
||||
' - Lock: '.number_format($poller_lock_duration, 2).
|
||||
' - Rest: '.number_format($up_duration - $poller_db_duration - $poller_lock_duration, 2).
|
||||
' - Execution: '.number_format($duration, 2), LOGGER_DEBUG);
|
||||
$poller_lock_duration = 0;
|
||||
|
||||
if ($duration > 3600) {
|
||||
logger("Prio ".$queue["priority"].": ".$queue["parameter"]." - longer than 1 hour (".round($duration/60, 3).")", LOGGER_DEBUG);
|
||||
} elseif ($duration > 600) {
|
||||
|
@ -226,24 +341,27 @@ function poller_exec_function($queue, $funcname, $argv) {
|
|||
$o = "\nDatabase Read:\n";
|
||||
foreach ($a->callstack["database"] AS $func => $time) {
|
||||
$time = round($time, 3);
|
||||
if ($time > 0)
|
||||
if ($time > 0) {
|
||||
$o .= $func.": ".$time."\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($a->callstack["database_write"])) {
|
||||
$o .= "\nDatabase Write:\n";
|
||||
foreach ($a->callstack["database_write"] AS $func => $time) {
|
||||
$time = round($time, 3);
|
||||
if ($time > 0)
|
||||
if ($time > 0) {
|
||||
$o .= $func.": ".$time."\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($a->callstack["network"])) {
|
||||
$o .= "\nNetwork:\n";
|
||||
foreach ($a->callstack["network"] AS $func => $time) {
|
||||
$time = round($time, 3);
|
||||
if ($time > 0)
|
||||
if ($time > 0) {
|
||||
$o .= $func.": ".$time."\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -284,27 +402,30 @@ function poller_max_connections_reached() {
|
|||
if ($max == 0) {
|
||||
// the maximum number of possible user connections can be a system variable
|
||||
$r = q("SHOW VARIABLES WHERE `variable_name` = 'max_user_connections'");
|
||||
if ($r)
|
||||
if (dbm::is_result($r)) {
|
||||
$max = $r[0]["Value"];
|
||||
|
||||
}
|
||||
// Or it can be granted. This overrides the system variable
|
||||
$r = q("SHOW GRANTS");
|
||||
if ($r)
|
||||
if (dbm::is_result($r)) {
|
||||
foreach ($r AS $grants) {
|
||||
$grant = array_pop($grants);
|
||||
if (stristr($grant, "GRANT USAGE ON"))
|
||||
if (preg_match("/WITH MAX_USER_CONNECTIONS (\d*)/", $grant, $match))
|
||||
if (stristr($grant, "GRANT USAGE ON")) {
|
||||
if (preg_match("/WITH MAX_USER_CONNECTIONS (\d*)/", $grant, $match)) {
|
||||
$max = $match[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If $max is set we will use the processlist to determine the current number of connections
|
||||
// The processlist only shows entries of the current user
|
||||
if ($max != 0) {
|
||||
$r = q("SHOW PROCESSLIST");
|
||||
if (!dbm::is_result($r))
|
||||
if (!dbm::is_result($r)) {
|
||||
return false;
|
||||
|
||||
}
|
||||
$used = count($r);
|
||||
|
||||
logger("Connection usage (user values): ".$used."/".$max, LOGGER_DEBUG);
|
||||
|
@ -320,28 +441,28 @@ function poller_max_connections_reached() {
|
|||
// We will now check for the system values.
|
||||
// This limit could be reached although the user limits are fine.
|
||||
$r = q("SHOW VARIABLES WHERE `variable_name` = 'max_connections'");
|
||||
if (!$r)
|
||||
if (!dbm::is_result($r)) {
|
||||
return false;
|
||||
|
||||
}
|
||||
$max = intval($r[0]["Value"]);
|
||||
if ($max == 0)
|
||||
if ($max == 0) {
|
||||
return false;
|
||||
|
||||
}
|
||||
$r = q("SHOW STATUS WHERE `variable_name` = 'Threads_connected'");
|
||||
if (!$r)
|
||||
if (!dbm::is_result($r)) {
|
||||
return false;
|
||||
|
||||
}
|
||||
$used = intval($r[0]["Value"]);
|
||||
if ($used == 0)
|
||||
if ($used == 0) {
|
||||
return false;
|
||||
|
||||
}
|
||||
logger("Connection usage (system values): ".$used."/".$max, LOGGER_DEBUG);
|
||||
|
||||
$level = $used / $max * 100;
|
||||
|
||||
if ($level < $maxlevel)
|
||||
if ($level < $maxlevel) {
|
||||
return false;
|
||||
|
||||
}
|
||||
logger("Maximum level (".$level."%) of system connections reached: ".$used."/".$max);
|
||||
return true;
|
||||
}
|
||||
|
@ -351,46 +472,47 @@ function poller_max_connections_reached() {
|
|||
*
|
||||
*/
|
||||
function poller_kill_stale_workers() {
|
||||
$r = q("SELECT `pid`, `executed`, `priority`, `parameter` FROM `workerqueue` WHERE `executed` > '%s'", dbesc(NULL_DATE));
|
||||
$entries = dba::p("SELECT `id`, `pid`, `executed`, `priority`, `parameter` FROM `workerqueue` WHERE `executed` > ? AND NOT `done` AND `pid` != 0 ORDER BY `priority`, `created`", NULL_DATE);
|
||||
|
||||
if (!dbm::is_result($r)) {
|
||||
// No processing here needed
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($r AS $pid) {
|
||||
if (!posix_kill($pid["pid"], 0)) {
|
||||
while ($entry = dba::fetch($entries)) {
|
||||
if (!posix_kill($entry["pid"], 0)) {
|
||||
dba::update('workerqueue', array('executed' => NULL_DATE, 'pid' => 0),
|
||||
array('pid' => $pid["pid"]));
|
||||
array('id' => $entry["id"]));
|
||||
} else {
|
||||
// Kill long running processes
|
||||
|
||||
// Check if the priority is in a valid range
|
||||
if (!in_array($pid["priority"], array(PRIORITY_CRITICAL, PRIORITY_HIGH, PRIORITY_MEDIUM, PRIORITY_LOW, PRIORITY_NEGLIGIBLE))) {
|
||||
$pid["priority"] = PRIORITY_MEDIUM;
|
||||
if (!in_array($entry["priority"], array(PRIORITY_CRITICAL, PRIORITY_HIGH, PRIORITY_MEDIUM, PRIORITY_LOW, PRIORITY_NEGLIGIBLE))) {
|
||||
$entry["priority"] = PRIORITY_MEDIUM;
|
||||
}
|
||||
|
||||
// Define the maximum durations
|
||||
$max_duration_defaults = array(PRIORITY_CRITICAL => 360, PRIORITY_HIGH => 10, PRIORITY_MEDIUM => 60, PRIORITY_LOW => 180, PRIORITY_NEGLIGIBLE => 360);
|
||||
$max_duration = $max_duration_defaults[$pid["priority"]];
|
||||
$max_duration_defaults = array(PRIORITY_CRITICAL => 720, PRIORITY_HIGH => 10, PRIORITY_MEDIUM => 60, PRIORITY_LOW => 180, PRIORITY_NEGLIGIBLE => 720);
|
||||
$max_duration = $max_duration_defaults[$entry["priority"]];
|
||||
|
||||
$argv = json_decode($pid["parameter"]);
|
||||
$argv = json_decode($entry["parameter"]);
|
||||
$argv[0] = basename($argv[0]);
|
||||
|
||||
// How long is the process already running?
|
||||
$duration = (time() - strtotime($pid["executed"])) / 60;
|
||||
$duration = (time() - strtotime($entry["executed"])) / 60;
|
||||
if ($duration > $max_duration) {
|
||||
logger("Worker process ".$pid["pid"]." (".implode(" ", $argv).") took more than ".$max_duration." minutes. It will be killed now.");
|
||||
posix_kill($pid["pid"], SIGTERM);
|
||||
logger("Worker process ".$entry["pid"]." (".implode(" ", $argv).") took more than ".$max_duration." minutes. It will be killed now.");
|
||||
posix_kill($entry["pid"], SIGTERM);
|
||||
|
||||
// We killed the stale process.
|
||||
// To avoid a blocking situation we reschedule the process at the beginning of the queue.
|
||||
// Additionally we are lowering the priority.
|
||||
// Additionally we are lowering the priority. (But not PRIORITY_CRITICAL)
|
||||
if ($entry["priority"] == PRIORITY_HIGH) {
|
||||
$new_priority = PRIORITY_MEDIUM;
|
||||
} elseif ($entry["priority"] == PRIORITY_MEDIUM) {
|
||||
$new_priority = PRIORITY_LOW;
|
||||
} elseif ($entry["priority"] != PRIORITY_CRITICAL) {
|
||||
$new_priority = PRIORITY_NEGLIGIBLE;
|
||||
}
|
||||
dba::update('workerqueue',
|
||||
array('executed' => NULL_DATE, 'created' => datetime_convert(), 'priority' => PRIORITY_NEGLIGIBLE, 'pid' => 0),
|
||||
array('pid' => $pid["pid"]));
|
||||
array('executed' => NULL_DATE, 'created' => datetime_convert(), 'priority' => $new_priority, 'pid' => 0),
|
||||
array('id' => $entry["id"]));
|
||||
} else {
|
||||
logger("Worker process ".$pid["pid"]." (".implode(" ", $argv).") now runs for ".round($duration)." of ".$max_duration." allowed minutes. That's okay.", LOGGER_DEBUG);
|
||||
logger("Worker process ".$entry["pid"]." (".implode(" ", $argv).") now runs for ".round($duration)." of ".$max_duration." allowed minutes. That's okay.", LOGGER_DEBUG);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -420,58 +542,65 @@ function poller_too_much_workers() {
|
|||
$slope = $maxworkers / pow($maxsysload, $exponent);
|
||||
$queues = ceil($slope * pow(max(0, $maxsysload - $load), $exponent));
|
||||
|
||||
// Create a list of queue entries grouped by their priority
|
||||
$listitem = array();
|
||||
if (Config::get('system', 'worker_debug')) {
|
||||
// Create a list of queue entries grouped by their priority
|
||||
$listitem = array();
|
||||
|
||||
// Adding all processes with no workerqueue entry
|
||||
$processes = dba::p("SELECT COUNT(*) AS `running` FROM `process` WHERE NOT EXISTS (SELECT id FROM `workerqueue` WHERE `workerqueue`.`pid` = `process`.`pid`)");
|
||||
if ($process = dba::fetch($processes)) {
|
||||
$listitem[0] = "0:".$process["running"];
|
||||
}
|
||||
dba::close($processes);
|
||||
|
||||
// Now adding all processes with workerqueue entries
|
||||
$entries = dba::p("SELECT COUNT(*) AS `entries`, `priority` FROM `workerqueue` GROUP BY `priority`");
|
||||
while ($entry = dba::fetch($entries)) {
|
||||
$processes = dba::p("SELECT COUNT(*) AS `running` FROM `process` INNER JOIN `workerqueue` ON `workerqueue`.`pid` = `process`.`pid` WHERE `priority` = ?", $entry["priority"]);
|
||||
// Adding all processes with no workerqueue entry
|
||||
$processes = dba::p("SELECT COUNT(*) AS `running` FROM `process` WHERE NOT EXISTS
|
||||
(SELECT id FROM `workerqueue`
|
||||
WHERE `workerqueue`.`pid` = `process`.`pid` AND NOT `done` AND `pid` != ?)", getmypid());
|
||||
if ($process = dba::fetch($processes)) {
|
||||
$listitem[$entry["priority"]] = $entry["priority"].":".$process["running"]."/".$entry["entries"];
|
||||
$listitem[0] = "0:".$process["running"];
|
||||
}
|
||||
dba::close($processes);
|
||||
|
||||
// Now adding all processes with workerqueue entries
|
||||
$entries = dba::p("SELECT COUNT(*) AS `entries`, `priority` FROM `workerqueue` WHERE NOT `done` GROUP BY `priority`");
|
||||
while ($entry = dba::fetch($entries)) {
|
||||
$processes = dba::p("SELECT COUNT(*) AS `running` FROM `process` INNER JOIN `workerqueue` ON `workerqueue`.`pid` = `process`.`pid` AND NOT `done` WHERE `priority` = ?", $entry["priority"]);
|
||||
if ($process = dba::fetch($processes)) {
|
||||
$listitem[$entry["priority"]] = $entry["priority"].":".$process["running"]."/".$entry["entries"];
|
||||
}
|
||||
dba::close($processes);
|
||||
}
|
||||
dba::close($entries);
|
||||
|
||||
$intervals = array(1, 10, 60);
|
||||
$jobs_per_minute = array();
|
||||
foreach ($intervals AS $interval) {
|
||||
$jobs = dba::p("SELECT COUNT(*) AS `jobs` FROM `workerqueue` WHERE `done` AND `executed` > UTC_TIMESTAMP() - INTERVAL ".intval($interval)." MINUTE");
|
||||
if ($job = dba::fetch($jobs)) {
|
||||
$jobs_per_minute[$interval] = number_format($job['jobs'] / $interval, 0);
|
||||
}
|
||||
dba::close($jobs);
|
||||
}
|
||||
$processlist = ' - jpm: '.implode('/', $jobs_per_minute).' ('.implode(', ', $listitem).')';
|
||||
}
|
||||
dba::close($entries);
|
||||
|
||||
$processlist = implode(', ', $listitem);
|
||||
$entries = poller_total_entries();
|
||||
|
||||
$s = q("SELECT COUNT(*) AS `total` FROM `workerqueue` WHERE `executed` <= '%s'", dbesc(NULL_DATE));
|
||||
$entries = $s[0]["total"];
|
||||
if (Config::get("system", "worker_fastlane", false) && ($queues > 0) && ($entries > 0) && ($active >= $queues)) {
|
||||
$top_priority = poller_highest_priority();
|
||||
$high_running = poller_process_with_priority_active($top_priority);
|
||||
|
||||
if (Config::get("system", "worker_fastlane", false) AND ($queues > 0) AND ($entries > 0) AND ($active >= $queues)) {
|
||||
$s = q("SELECT `priority` FROM `workerqueue` WHERE `executed` <= '%s' ORDER BY `priority` LIMIT 1", dbesc(NULL_DATE));
|
||||
$top_priority = $s[0]["priority"];
|
||||
|
||||
$s = q("SELECT `id` FROM `workerqueue` WHERE `priority` <= %d AND `executed` > '%s' LIMIT 1",
|
||||
intval($top_priority), dbesc(NULL_DATE));
|
||||
$high_running = dbm::is_result($s);
|
||||
|
||||
if (!$high_running AND ($top_priority > PRIORITY_UNDEFINED) AND ($top_priority < PRIORITY_NEGLIGIBLE)) {
|
||||
if (!$high_running && ($top_priority > PRIORITY_UNDEFINED) && ($top_priority < PRIORITY_NEGLIGIBLE)) {
|
||||
logger("There are jobs with priority ".$top_priority." waiting but none is executed. Open a fastlane.", LOGGER_DEBUG);
|
||||
$queues = $active + 1;
|
||||
}
|
||||
}
|
||||
|
||||
logger("Load: ".$load."/".$maxsysload." - processes: ".$active."/".$entries." (".$processlist.") - maximum: ".$queues."/".$maxqueues, LOGGER_DEBUG);
|
||||
logger("Load: ".$load."/".$maxsysload." - processes: ".$active."/".$entries.$processlist." - maximum: ".$queues."/".$maxqueues, LOGGER_DEBUG);
|
||||
|
||||
// Are there fewer workers running as possible? Then fork a new one.
|
||||
if (!Config::get("system", "worker_dont_fork") AND ($queues > ($active + 1)) AND ($entries > 1)) {
|
||||
if (!Config::get("system", "worker_dont_fork") && ($queues > ($active + 1)) && ($entries > 1)) {
|
||||
logger("Active workers: ".$active."/".$queues." Fork a new worker.", LOGGER_DEBUG);
|
||||
$args = array("include/poller.php", "no_cron");
|
||||
$a = get_app();
|
||||
$a->proc_run($args);
|
||||
get_app()->proc_run($args);
|
||||
}
|
||||
}
|
||||
|
||||
return($active >= $queues);
|
||||
return $active >= $queues;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -482,7 +611,7 @@ function poller_too_much_workers() {
|
|||
function poller_active_workers() {
|
||||
$workers = q("SELECT COUNT(*) AS `processes` FROM `process` WHERE `command` = 'poller.php'");
|
||||
|
||||
return($workers[0]["processes"]);
|
||||
return $workers[0]["processes"];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -500,133 +629,166 @@ function poller_passing_slow(&$highest_priority) {
|
|||
|
||||
$r = q("SELECT `priority`
|
||||
FROM `process`
|
||||
INNER JOIN `workerqueue` ON `workerqueue`.`pid` = `process`.`pid`");
|
||||
INNER JOIN `workerqueue` ON `workerqueue`.`pid` = `process`.`pid` AND NOT `done`");
|
||||
|
||||
// No active processes at all? Fine
|
||||
if (!dbm::is_result($r))
|
||||
return(false);
|
||||
|
||||
if (!dbm::is_result($r)) {
|
||||
return false;
|
||||
}
|
||||
$priorities = array();
|
||||
foreach ($r AS $line)
|
||||
foreach ($r AS $line) {
|
||||
$priorities[] = $line["priority"];
|
||||
|
||||
}
|
||||
// Should not happen
|
||||
if (count($priorities) == 0)
|
||||
return(false);
|
||||
|
||||
if (count($priorities) == 0) {
|
||||
return false;
|
||||
}
|
||||
$highest_priority = min($priorities);
|
||||
|
||||
// The highest process is already the slowest one?
|
||||
// Then we quit
|
||||
if ($highest_priority == PRIORITY_NEGLIGIBLE)
|
||||
return(false);
|
||||
|
||||
if ($highest_priority == PRIORITY_NEGLIGIBLE) {
|
||||
return false;
|
||||
}
|
||||
$high = 0;
|
||||
foreach ($priorities AS $priority)
|
||||
if ($priority == $highest_priority)
|
||||
foreach ($priorities AS $priority) {
|
||||
if ($priority == $highest_priority) {
|
||||
++$high;
|
||||
|
||||
}
|
||||
}
|
||||
logger("Highest priority: ".$highest_priority." Total processes: ".count($priorities)." Count high priority processes: ".$high, LOGGER_DEBUG);
|
||||
$passing_slow = (($high/count($priorities)) > (2/3));
|
||||
|
||||
if ($passing_slow)
|
||||
if ($passing_slow) {
|
||||
logger("Passing slower processes than priority ".$highest_priority, LOGGER_DEBUG);
|
||||
}
|
||||
return $passing_slow;
|
||||
}
|
||||
|
||||
return($passing_slow);
|
||||
/**
|
||||
* @brief Find and claim the next worker process for us
|
||||
*
|
||||
* @param boolean $passing_slow Returns if we had passed low priority processes
|
||||
* @return boolean Have we found something?
|
||||
*/
|
||||
function find_worker_processes(&$passing_slow) {
|
||||
|
||||
$mypid = getmypid();
|
||||
|
||||
// Check if we should pass some low priority process
|
||||
$highest_priority = 0;
|
||||
$found = false;
|
||||
$passing_slow = false;
|
||||
|
||||
// The higher the number of parallel workers, the more we prefetch to prevent concurring access
|
||||
// We decrease the limit with the number of entries left in the queue
|
||||
$worker_queues = Config::get("system", "worker_queues", 4);
|
||||
$queue_length = Config::get('system', 'worker_fetch_limit', $worker_queues);
|
||||
$lower_job_limit = $worker_queues * $queue_length * 2;
|
||||
$jobs = poller_total_entries();
|
||||
|
||||
// Now do some magic
|
||||
$exponent = 2;
|
||||
$slope = $queue_length / pow($lower_job_limit, $exponent);
|
||||
$limit = min($queue_length, ceil($slope * pow($jobs, $exponent)));
|
||||
|
||||
logger('Total: '.$jobs.' - Maximum: '.$queue_length.' - jobs per queue: '.$limit, LOGGER_DEBUG);
|
||||
|
||||
if (poller_passing_slow($highest_priority)) {
|
||||
// Are there waiting processes with a higher priority than the currently highest?
|
||||
$result = dba::p("SELECT `id` FROM `workerqueue`
|
||||
WHERE `executed` <= ? AND `priority` < ? AND NOT `done`
|
||||
ORDER BY `priority`, `created` LIMIT ".intval($limit),
|
||||
NULL_DATE, $highest_priority);
|
||||
|
||||
while ($id = dba::fetch($result)) {
|
||||
$ids[] = $id["id"];
|
||||
}
|
||||
dba::close($result);
|
||||
|
||||
$found = (count($ids) > 0);
|
||||
|
||||
if (!$found) {
|
||||
// Give slower processes some processing time
|
||||
$result = dba::p("SELECT `id` FROM `workerqueue`
|
||||
WHERE `executed` <= ? AND `priority` > ? AND NOT `done`
|
||||
ORDER BY `priority`, `created` LIMIT ".intval($limit),
|
||||
NULL_DATE, $highest_priority);
|
||||
|
||||
while ($id = dba::fetch($result)) {
|
||||
$ids[] = $id["id"];
|
||||
}
|
||||
dba::close($result);
|
||||
|
||||
$found = (count($ids) > 0);
|
||||
$passing_slow = $found;
|
||||
}
|
||||
}
|
||||
|
||||
// If there is no result (or we shouldn't pass lower processes) we check without priority limit
|
||||
if (!$found) {
|
||||
$result = dba::p("SELECT `id` FROM `workerqueue` WHERE `executed` <= ? AND NOT `done` ORDER BY `priority`, `created` LIMIT ".intval($limit), NULL_DATE);
|
||||
|
||||
while ($id = dba::fetch($result)) {
|
||||
$ids[] = $id["id"];
|
||||
}
|
||||
dba::close($result);
|
||||
|
||||
$found = (count($ids) > 0);
|
||||
}
|
||||
|
||||
if ($found) {
|
||||
$sql = "UPDATE `workerqueue` SET `executed` = ?, `pid` = ? WHERE `id` IN (".substr(str_repeat("?, ", count($ids)), 0, -2).") AND `pid` = 0 AND NOT `done`;";
|
||||
array_unshift($ids, datetime_convert(), $mypid);
|
||||
dba::e($sql, $ids);
|
||||
}
|
||||
|
||||
return $found;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the next worker process
|
||||
*
|
||||
* @param boolean $passing_slow Returns if we had passed low priority processes
|
||||
* @return string SQL statement
|
||||
*/
|
||||
function poller_worker_process() {
|
||||
function poller_worker_process(&$passing_slow) {
|
||||
global $poller_db_duration, $poller_lock_duration;
|
||||
|
||||
// Check if we should pass some low priority process
|
||||
$highest_priority = 0;
|
||||
$stamp = (float)microtime(true);
|
||||
|
||||
if (poller_passing_slow($highest_priority)) {
|
||||
dba::e('LOCK TABLES `workerqueue` WRITE');
|
||||
|
||||
// Are there waiting processes with a higher priority than the currently highest?
|
||||
$r = q("SELECT * FROM `workerqueue`
|
||||
WHERE `executed` <= '%s' AND `priority` < %d
|
||||
ORDER BY `priority`, `created` LIMIT 1",
|
||||
dbesc(NULL_DATE),
|
||||
intval($highest_priority));
|
||||
if (dbm::is_result($r)) {
|
||||
return $r;
|
||||
}
|
||||
// Give slower processes some processing time
|
||||
$r = q("SELECT * FROM `workerqueue`
|
||||
WHERE `executed` <= '%s' AND `priority` > %d
|
||||
ORDER BY `priority`, `created` LIMIT 1",
|
||||
dbesc(NULL_DATE),
|
||||
intval($highest_priority));
|
||||
|
||||
if (dbm::is_result($r)) {
|
||||
return $r;
|
||||
}
|
||||
} else {
|
||||
dba::e('LOCK TABLES `workerqueue` WRITE');
|
||||
// There can already be jobs for us in the queue.
|
||||
$r = q("SELECT * FROM `workerqueue` WHERE `pid` = %d AND NOT `done`", intval(getmypid()));
|
||||
if (dbm::is_result($r)) {
|
||||
$poller_db_duration += (microtime(true) - $stamp);
|
||||
return $r;
|
||||
}
|
||||
|
||||
// If there is no result (or we shouldn't pass lower processes) we check without priority limit
|
||||
if (!dbm::is_result($r)) {
|
||||
$r = q("SELECT * FROM `workerqueue` WHERE `executed` <= '%s' ORDER BY `priority`, `created` LIMIT 1", dbesc(NULL_DATE));
|
||||
$stamp = (float)microtime(true);
|
||||
if (!Lock::set('poller_worker_process')) {
|
||||
return false;
|
||||
}
|
||||
$poller_lock_duration = (microtime(true) - $stamp);
|
||||
|
||||
// We only unlock the tables here, when we got no data
|
||||
if (!dbm::is_result($r)) {
|
||||
dba::e('UNLOCK TABLES');
|
||||
$stamp = (float)microtime(true);
|
||||
$found = find_worker_processes($passing_slow);
|
||||
$poller_db_duration += (microtime(true) - $stamp);
|
||||
|
||||
Lock::remove('poller_worker_process');
|
||||
|
||||
if ($found) {
|
||||
$r = q("SELECT * FROM `workerqueue` WHERE `pid` = %d AND NOT `done`", intval(getmypid()));
|
||||
}
|
||||
|
||||
return $r;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Assigns a workerqueue entry to the current process
|
||||
*
|
||||
* When we are sure that the table locks are working correctly, we can remove the checks from here
|
||||
*
|
||||
* @param array $queue Workerqueue entry
|
||||
*
|
||||
* @return boolean "true" if the claiming was successful
|
||||
*/
|
||||
function poller_claim_process($queue) {
|
||||
$mypid = getmypid();
|
||||
|
||||
$success = dba::update('workerqueue', array('executed' => datetime_convert(), 'pid' => $mypid),
|
||||
array('id' => $queue["id"], 'pid' => 0));
|
||||
dba::e('UNLOCK TABLES');
|
||||
|
||||
if (!$success) {
|
||||
logger("Couldn't update queue entry ".$queue["id"]." - skip this execution", LOGGER_DEBUG);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Assure that there are no tasks executed twice
|
||||
$id = q("SELECT `pid`, `executed` FROM `workerqueue` WHERE `id` = %d", intval($queue["id"]));
|
||||
if (!$id) {
|
||||
logger("Queue item ".$queue["id"]." vanished - skip this execution", LOGGER_DEBUG);
|
||||
return false;
|
||||
} elseif ((strtotime($id[0]["executed"]) <= 0) OR ($id[0]["pid"] == 0)) {
|
||||
logger("Entry for queue item ".$queue["id"]." wasn't stored - skip this execution", LOGGER_DEBUG);
|
||||
return false;
|
||||
} elseif ($id[0]["pid"] != $mypid) {
|
||||
logger("Queue item ".$queue["id"]." is to be executed by process ".$id[0]["pid"]." and not by me (".$mypid.") - skip this execution", LOGGER_DEBUG);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Removes a workerqueue entry from the current process
|
||||
*/
|
||||
function poller_unclaim_process() {
|
||||
$mypid = getmypid();
|
||||
|
||||
dba::update('workerqueue', array('executed' => NULL_DATE, 'pid' => 0), array('pid' => $mypid));
|
||||
dba::update('workerqueue', array('executed' => NULL_DATE, 'pid' => 0), array('pid' => $mypid, 'done' => false));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -673,8 +835,7 @@ function call_worker_if_idle() {
|
|||
logger('Call poller', LOGGER_DEBUG);
|
||||
|
||||
$args = array("include/poller.php", "no_cron");
|
||||
$a = get_app();
|
||||
$a->proc_run($args);
|
||||
get_app()->proc_run($args);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ function post_update_1192() {
|
|||
WHERE `thread`.`gcontact-id` = 0 AND
|
||||
(`thread`.`uid` IN (SELECT `uid` from `user`) OR `thread`.`uid` = 0)");
|
||||
|
||||
if ($r AND ($r[0]["total"] == 0)) {
|
||||
if ($r && ($r[0]["total"] == 0)) {
|
||||
set_config("system", "post_update_version", 1192);
|
||||
return true;
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ function post_update_1198() {
|
|||
WHERE `thread`.`author-id` = 0 AND `thread`.`owner-id` = 0 AND
|
||||
(`thread`.`uid` IN (SELECT `uid` from `user`) OR `thread`.`uid` = 0)");
|
||||
|
||||
if ($r AND ($r[0]["total"] == 0)) {
|
||||
if ($r && ($r[0]["total"] == 0)) {
|
||||
set_config("system", "post_update_version", 1198);
|
||||
logger("Done", LOGGER_DEBUG);
|
||||
return true;
|
||||
|
@ -247,7 +247,7 @@ function post_update_1206() {
|
|||
return false;
|
||||
}
|
||||
foreach ($r AS $user) {
|
||||
if (!empty($user["lastitem_date"]) AND ($user["lastitem_date"] > $user["last-item"])) {
|
||||
if (!empty($user["lastitem_date"]) && ($user["lastitem_date"] > $user["last-item"])) {
|
||||
q("UPDATE `contact` SET `last-item` = '%s' WHERE `id` = %d",
|
||||
dbesc($user["lastitem_date"]),
|
||||
intval($user["id"]));
|
||||
|
|
|
@ -7,6 +7,7 @@ require_once('include/items.php');
|
|||
require_once('include/ostatus.php');
|
||||
|
||||
function pubsubpublish_run(&$argv, &$argc){
|
||||
global $a;
|
||||
|
||||
if ($argc > 1) {
|
||||
$pubsubpublish_id = intval($argv[1]);
|
||||
|
@ -17,7 +18,8 @@ function pubsubpublish_run(&$argv, &$argc){
|
|||
|
||||
foreach ($r as $rr) {
|
||||
logger("Publish feed to ".$rr["callback_url"], LOGGER_DEBUG);
|
||||
proc_run(PRIORITY_HIGH, 'include/pubsubpublish.php', $rr["id"]);
|
||||
proc_run(array('priority' => PRIORITY_HIGH, 'created' => $a->queue['created'], 'dont_fork' => true),
|
||||
'include/pubsubpublish.php', (int)$rr["id"]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,15 +2,15 @@
|
|||
|
||||
use Friendica\Core\Config;
|
||||
|
||||
require_once('include/queue_fn.php');
|
||||
require_once('include/dfrn.php');
|
||||
require_once("include/datetime.php");
|
||||
require_once('include/items.php');
|
||||
require_once('include/bbcode.php');
|
||||
require_once('include/socgraph.php');
|
||||
require_once('include/cache.php');
|
||||
require_once 'include/queue_fn.php';
|
||||
require_once 'include/dfrn.php';
|
||||
require_once 'include/datetime.php';
|
||||
require_once 'include/items.php';
|
||||
require_once 'include/bbcode.php';
|
||||
require_once 'include/socgraph.php';
|
||||
require_once 'include/cache.php';
|
||||
|
||||
function queue_run(&$argv, &$argc){
|
||||
function queue_run(&$argv, &$argc) {
|
||||
global $a;
|
||||
|
||||
if ($argc > 1) {
|
||||
|
@ -27,7 +27,7 @@ function queue_run(&$argv, &$argc){
|
|||
logger('queue: start');
|
||||
|
||||
// Handling the pubsubhubbub requests
|
||||
proc_run(PRIORITY_HIGH,'include/pubsubpublish.php');
|
||||
proc_run(array('priority' => PRIORITY_HIGH, 'dont_fork' => true), 'include/pubsubpublish.php');
|
||||
|
||||
$r = q("SELECT `queue`.*, `contact`.`name`, `contact`.`uid` FROM `queue`
|
||||
INNER JOIN `contact` ON `queue`.`cid` = `contact`.`id`
|
||||
|
@ -41,17 +41,18 @@ function queue_run(&$argv, &$argc){
|
|||
q("DELETE FROM `queue` WHERE `created` < UTC_TIMESTAMP() - INTERVAL 3 DAY");
|
||||
}
|
||||
|
||||
// For the first 12 hours we'll try to deliver every 15 minutes
|
||||
// After that, we'll only attempt delivery once per hour.
|
||||
|
||||
$r = q("SELECT `id` FROM `queue` WHERE ((`created` > UTC_TIMESTAMP() - INTERVAL 12 HOUR && `last` < UTC_TIMESTAMP() - INTERVAL 15 MINUTE) OR (`last` < UTC_TIMESTAMP() - INTERVAL 1 HOUR)) ORDER BY `cid`, `created`");
|
||||
/*
|
||||
* For the first 12 hours we'll try to deliver every 15 minutes
|
||||
* After that, we'll only attempt delivery once per hour.
|
||||
*/
|
||||
$r = q("SELECT `id` FROM `queue` WHERE ((`created` > UTC_TIMESTAMP() - INTERVAL 12 HOUR AND `last` < UTC_TIMESTAMP() - INTERVAL 15 MINUTE) OR (`last` < UTC_TIMESTAMP() - INTERVAL 1 HOUR)) ORDER BY `cid`, `created`");
|
||||
|
||||
call_hooks('queue_predeliver', $a, $r);
|
||||
|
||||
if (dbm::is_result($r)) {
|
||||
foreach ($r as $q_item) {
|
||||
logger('Call queue for id '.$q_item['id']);
|
||||
proc_run(PRIORITY_LOW, "include/queue.php", $q_item['id']);
|
||||
proc_run(array('priority' => PRIORITY_LOW, 'dont_fork' => true), "include/queue.php", (int)$q_item['id']);
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
@ -60,8 +61,8 @@ function queue_run(&$argv, &$argc){
|
|||
|
||||
// delivering
|
||||
|
||||
require_once('include/salmon.php');
|
||||
require_once('include/diaspora.php');
|
||||
require_once 'include/salmon.php';
|
||||
require_once 'include/diaspora.php';
|
||||
|
||||
$r = q("SELECT * FROM `queue` WHERE `id` = %d LIMIT 1",
|
||||
intval($queue_id));
|
||||
|
@ -83,7 +84,7 @@ function queue_run(&$argv, &$argc){
|
|||
|
||||
$dead = Cache::get($cachekey_deadguy.$c[0]['notify']);
|
||||
|
||||
if (!is_null($dead) AND $dead) {
|
||||
if (!is_null($dead) && $dead) {
|
||||
logger('queue: skipping known dead url: '.$c[0]['notify']);
|
||||
update_queue_time($q_item['id']);
|
||||
return;
|
||||
|
@ -101,7 +102,7 @@ function queue_run(&$argv, &$argc){
|
|||
Cache::set($cachekey_server.$server, $vital, CACHE_QUARTER_HOUR);
|
||||
}
|
||||
|
||||
if (!is_null($vital) AND !$vital) {
|
||||
if (!is_null($vital) && !$vital) {
|
||||
logger('queue: skipping dead server: '.$server);
|
||||
update_queue_time($q_item['id']);
|
||||
return;
|
||||
|
|
|
@ -10,7 +10,7 @@ function convertquote($body, $reply)
|
|||
$quoteline = $arrbody[$i];
|
||||
|
||||
while ((strlen($quoteline)>0) and ((substr($quoteline, 0, 1) == '>')
|
||||
or (substr($quoteline, 0, 1) == ' '))) {
|
||||
|| (substr($quoteline, 0, 1) == ' '))) {
|
||||
if (substr($quoteline, 0, 1) == '>')
|
||||
$quotelevel++;
|
||||
|
||||
|
|
|
@ -6,13 +6,13 @@ function auto_redir(App $a, $contact_nick) {
|
|||
|
||||
// prevent looping
|
||||
|
||||
if(x($_REQUEST,'redir') && intval($_REQUEST['redir']))
|
||||
if (x($_REQUEST,'redir') && intval($_REQUEST['redir']))
|
||||
return;
|
||||
|
||||
if((! $contact_nick) || ($contact_nick === $a->user['nickname']))
|
||||
if ((! $contact_nick) || ($contact_nick === $a->user['nickname']))
|
||||
return;
|
||||
|
||||
if(local_user()) {
|
||||
if (local_user()) {
|
||||
|
||||
// We need to find out if $contact_nick is a user on this hub, and if so, if I
|
||||
// am a contact of that user. However, that user may have other contacts with the
|
||||
|
@ -24,7 +24,7 @@ function auto_redir(App $a, $contact_nick) {
|
|||
|
||||
$baseurl = App::get_baseurl();
|
||||
$domain_st = strpos($baseurl, "://");
|
||||
if($domain_st === false)
|
||||
if ($domain_st === false)
|
||||
return;
|
||||
$baseurl = substr($baseurl, $domain_st + 3);
|
||||
$nurl = normalise_link($baseurl);
|
||||
|
@ -58,11 +58,11 @@ function auto_redir(App $a, $contact_nick) {
|
|||
|
||||
$dfrn_id = $orig_id = (($r[0]['issued-id']) ? $r[0]['issued-id'] : $r[0]['dfrn-id']);
|
||||
|
||||
if($r[0]['duplex'] && $r[0]['issued-id']) {
|
||||
if ($r[0]['duplex'] && $r[0]['issued-id']) {
|
||||
$orig_id = $r[0]['issued-id'];
|
||||
$dfrn_id = '1:' . $orig_id;
|
||||
}
|
||||
if($r[0]['duplex'] && $r[0]['dfrn-id']) {
|
||||
if ($r[0]['duplex'] && $r[0]['dfrn-id']) {
|
||||
$orig_id = $r[0]['dfrn-id'];
|
||||
$dfrn_id = '0:' . $orig_id;
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ function auto_redir(App $a, $contact_nick) {
|
|||
// ensure that we've got a valid ID. There may be some edge cases with forums and non-duplex mode
|
||||
// that may have triggered some of the "went to {profile/intro} and got an RSS feed" issues
|
||||
|
||||
if(strlen($dfrn_id) < 3)
|
||||
if (strlen($dfrn_id) < 3)
|
||||
return;
|
||||
|
||||
$sec = random_string();
|
||||
|
|
|
@ -170,11 +170,14 @@ function slapper($owner, $url, $slap) {
|
|||
}
|
||||
|
||||
logger('slapper for '.$url.' returned ' . $return_code);
|
||||
|
||||
if (! $return_code) {
|
||||
return(-1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (($return_code == 503) && (stristr($a->get_curl_headers(), 'retry-after'))) {
|
||||
return(-1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ((($return_code >= 200) && ($return_code < 300)) ? 0 : 1);
|
||||
}
|
||||
|
|
|
@ -56,58 +56,65 @@ function authenticate_success($user_record, $login_initial = false, $interactive
|
|||
|
||||
$a->user = $user_record;
|
||||
|
||||
if($interactive) {
|
||||
if ($interactive) {
|
||||
if ($a->user['login_date'] <= NULL_DATE) {
|
||||
$_SESSION['return_url'] = 'profile_photo/new';
|
||||
$a->module = 'profile_photo';
|
||||
info( t("Welcome ") . $a->user['username'] . EOL);
|
||||
info( t('Please upload a profile photo.') . EOL);
|
||||
}
|
||||
else
|
||||
} else {
|
||||
info( t("Welcome back ") . $a->user['username'] . EOL);
|
||||
}
|
||||
}
|
||||
|
||||
$member_since = strtotime($a->user['register_date']);
|
||||
if(time() < ($member_since + ( 60 * 60 * 24 * 14)))
|
||||
if (time() < ($member_since + ( 60 * 60 * 24 * 14))) {
|
||||
$_SESSION['new_member'] = true;
|
||||
else
|
||||
} else {
|
||||
$_SESSION['new_member'] = false;
|
||||
if(strlen($a->user['timezone'])) {
|
||||
}
|
||||
if (strlen($a->user['timezone'])) {
|
||||
date_default_timezone_set($a->user['timezone']);
|
||||
$a->timezone = $a->user['timezone'];
|
||||
}
|
||||
|
||||
$master_record = $a->user;
|
||||
|
||||
if((x($_SESSION,'submanage')) && intval($_SESSION['submanage'])) {
|
||||
$r = q("select * from user where uid = %d limit 1",
|
||||
if ((x($_SESSION,'submanage')) && intval($_SESSION['submanage'])) {
|
||||
$r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
|
||||
intval($_SESSION['submanage'])
|
||||
);
|
||||
if (dbm::is_result($r))
|
||||
if (dbm::is_result($r)) {
|
||||
$master_record = $r[0];
|
||||
}
|
||||
}
|
||||
|
||||
$r = q("SELECT `uid`,`username`,`nickname` FROM `user` WHERE `password` = '%s' AND `email` = '%s' AND `account_removed` = 0 ",
|
||||
dbesc($master_record['password']),
|
||||
dbesc($master_record['email'])
|
||||
);
|
||||
if (dbm::is_result($r))
|
||||
if (dbm::is_result($r)) {
|
||||
$a->identities = $r;
|
||||
else
|
||||
} else {
|
||||
$a->identities = array();
|
||||
}
|
||||
|
||||
$r = q("select `user`.`uid`, `user`.`username`, `user`.`nickname`
|
||||
from manage INNER JOIN user on manage.mid = user.uid where `user`.`account_removed` = 0
|
||||
and `manage`.`uid` = %d",
|
||||
$r = q("SELECT `user`.`uid`, `user`.`username`, `user`.`nickname`
|
||||
FROM `manage`
|
||||
INNER JOIN `user` ON `manage`.`mid` = `user`.`uid`
|
||||
WHERE `user`.`account_removed` = 0 AND `manage`.`uid` = %d",
|
||||
intval($master_record['uid'])
|
||||
);
|
||||
if (dbm::is_result($r))
|
||||
if (dbm::is_result($r)) {
|
||||
$a->identities = array_merge($a->identities,$r);
|
||||
}
|
||||
|
||||
if($login_initial)
|
||||
if ($login_initial) {
|
||||
logger('auth_identities: ' . print_r($a->identities,true), LOGGER_DEBUG);
|
||||
if($login_refresh)
|
||||
}
|
||||
if ($login_refresh) {
|
||||
logger('auth_identities refresh: ' . print_r($a->identities,true), LOGGER_DEBUG);
|
||||
}
|
||||
|
||||
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
|
||||
intval($_SESSION['uid']));
|
||||
|
@ -119,7 +126,7 @@ function authenticate_success($user_record, $login_initial = false, $interactive
|
|||
|
||||
header('X-Account-Management-Status: active; name="' . $a->user['username'] . '"; id="' . $a->user['nickname'] .'"');
|
||||
|
||||
if($login_initial || $login_refresh) {
|
||||
if ($login_initial || $login_refresh) {
|
||||
|
||||
q("UPDATE `user` SET `login_date` = '%s' WHERE `uid` = %d",
|
||||
dbesc(datetime_convert()),
|
||||
|
@ -228,7 +235,7 @@ function can_write_wall(App $a, $owner) {
|
|||
}
|
||||
|
||||
|
||||
function permissions_sql($owner_id,$remote_verified = false,$groups = null) {
|
||||
function permissions_sql($owner_id, $remote_verified = false, $groups = null) {
|
||||
|
||||
$local_user = local_user();
|
||||
$remote_user = remote_user();
|
||||
|
@ -238,7 +245,6 @@ function permissions_sql($owner_id,$remote_verified = false,$groups = null) {
|
|||
*
|
||||
* default permissions - anonymous user
|
||||
*/
|
||||
|
||||
$sql = " AND allow_cid = ''
|
||||
AND allow_gid = ''
|
||||
AND deny_cid = ''
|
||||
|
@ -249,21 +255,18 @@ function permissions_sql($owner_id,$remote_verified = false,$groups = null) {
|
|||
* Profile owner - everything is visible
|
||||
*/
|
||||
|
||||
if(($local_user) && ($local_user == $owner_id)) {
|
||||
if (($local_user) && ($local_user == $owner_id)) {
|
||||
$sql = '';
|
||||
}
|
||||
} elseif ($remote_user) {
|
||||
/*
|
||||
* Authenticated visitor. Unless pre-verified,
|
||||
* check that the contact belongs to this $owner_id
|
||||
* and load the groups the visitor belongs to.
|
||||
* If pre-verified, the caller is expected to have already
|
||||
* done this and passed the groups into this function.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Authenticated visitor. Unless pre-verified,
|
||||
* check that the contact belongs to this $owner_id
|
||||
* and load the groups the visitor belongs to.
|
||||
* If pre-verified, the caller is expected to have already
|
||||
* done this and passed the groups into this function.
|
||||
*/
|
||||
|
||||
elseif($remote_user) {
|
||||
|
||||
if(! $remote_verified) {
|
||||
if (! $remote_verified) {
|
||||
$r = q("SELECT id FROM contact WHERE id = %d AND uid = %d AND blocked = 0 LIMIT 1",
|
||||
intval($remote_user),
|
||||
intval($owner_id)
|
||||
|
@ -273,16 +276,18 @@ function permissions_sql($owner_id,$remote_verified = false,$groups = null) {
|
|||
$groups = init_groups_visitor($remote_user);
|
||||
}
|
||||
}
|
||||
if($remote_verified) {
|
||||
if ($remote_verified) {
|
||||
|
||||
$gs = '<<>>'; // should be impossible to match
|
||||
|
||||
if(is_array($groups) && count($groups)) {
|
||||
foreach($groups as $g)
|
||||
if (is_array($groups) && count($groups)) {
|
||||
foreach ($groups as $g)
|
||||
$gs .= '|<' . intval($g) . '>';
|
||||
}
|
||||
|
||||
/*$sql = sprintf(
|
||||
/*
|
||||
* @TODO old-lost code found?
|
||||
$sql = sprintf(
|
||||
" AND ( allow_cid = '' OR allow_cid REGEXP '<%d>' )
|
||||
AND ( deny_cid = '' OR NOT deny_cid REGEXP '<%d>' )
|
||||
AND ( allow_gid = '' OR allow_gid REGEXP '%s' )
|
||||
|
@ -292,7 +297,8 @@ function permissions_sql($owner_id,$remote_verified = false,$groups = null) {
|
|||
intval($remote_user),
|
||||
dbesc($gs),
|
||||
dbesc($gs)
|
||||
);*/
|
||||
);
|
||||
*/
|
||||
$sql = sprintf(
|
||||
" AND ( NOT (deny_cid REGEXP '<%d>' OR deny_gid REGEXP '%s')
|
||||
AND ( allow_cid REGEXP '<%d>' OR allow_gid REGEXP '%s' OR ( allow_cid = '' AND allow_gid = '') )
|
||||
|
@ -309,7 +315,7 @@ function permissions_sql($owner_id,$remote_verified = false,$groups = null) {
|
|||
}
|
||||
|
||||
|
||||
function item_permissions_sql($owner_id,$remote_verified = false,$groups = null) {
|
||||
function item_permissions_sql($owner_id, $remote_verified = false, $groups = null) {
|
||||
|
||||
$local_user = local_user();
|
||||
$remote_user = remote_user();
|
||||
|
@ -319,7 +325,6 @@ function item_permissions_sql($owner_id,$remote_verified = false,$groups = null)
|
|||
*
|
||||
* default permissions - anonymous user
|
||||
*/
|
||||
|
||||
$sql = " AND `item`.allow_cid = ''
|
||||
AND `item`.allow_gid = ''
|
||||
AND `item`.deny_cid = ''
|
||||
|
@ -330,22 +335,17 @@ function item_permissions_sql($owner_id,$remote_verified = false,$groups = null)
|
|||
/**
|
||||
* Profile owner - everything is visible
|
||||
*/
|
||||
|
||||
if($local_user && ($local_user == $owner_id)) {
|
||||
if ($local_user && ($local_user == $owner_id)) {
|
||||
$sql = '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Authenticated visitor. Unless pre-verified,
|
||||
* check that the contact belongs to this $owner_id
|
||||
* and load the groups the visitor belongs to.
|
||||
* If pre-verified, the caller is expected to have already
|
||||
* done this and passed the groups into this function.
|
||||
*/
|
||||
|
||||
elseif($remote_user) {
|
||||
|
||||
if(! $remote_verified) {
|
||||
} elseif ($remote_user) {
|
||||
/*
|
||||
* Authenticated visitor. Unless pre-verified,
|
||||
* check that the contact belongs to this $owner_id
|
||||
* and load the groups the visitor belongs to.
|
||||
* If pre-verified, the caller is expected to have already
|
||||
* done this and passed the groups into this function.
|
||||
*/
|
||||
if (! $remote_verified) {
|
||||
$r = q("SELECT id FROM contact WHERE id = %d AND uid = %d AND blocked = 0 LIMIT 1",
|
||||
intval($remote_user),
|
||||
intval($owner_id)
|
||||
|
@ -355,13 +355,14 @@ function item_permissions_sql($owner_id,$remote_verified = false,$groups = null)
|
|||
$groups = init_groups_visitor($remote_user);
|
||||
}
|
||||
}
|
||||
if($remote_verified) {
|
||||
if ($remote_verified) {
|
||||
|
||||
$gs = '<<>>'; // should be impossible to match
|
||||
|
||||
if(is_array($groups) && count($groups)) {
|
||||
foreach($groups as $g)
|
||||
if (is_array($groups) && count($groups)) {
|
||||
foreach ($groups as $g) {
|
||||
$gs .= '|<' . intval($g) . '>';
|
||||
}
|
||||
}
|
||||
|
||||
$sql = sprintf(
|
||||
|
@ -412,7 +413,11 @@ function get_form_security_token($typename = '') {
|
|||
}
|
||||
|
||||
function check_form_security_token($typename = '', $formname = 'form_security_token') {
|
||||
if (!x($_REQUEST, $formname)) return false;
|
||||
if (!x($_REQUEST, $formname)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/// @TODO Careful, not secured!
|
||||
$hash = $_REQUEST[$formname];
|
||||
|
||||
$max_livetime = 10800; // 3 hours
|
||||
|
@ -420,7 +425,9 @@ function check_form_security_token($typename = '', $formname = 'form_security_to
|
|||
$a = get_app();
|
||||
|
||||
$x = explode('.', $hash);
|
||||
if (time() > (IntVal($x[0]) + $max_livetime)) return false;
|
||||
if (time() > (IntVal($x[0]) + $max_livetime)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$sec_hash = hash('whirlpool', $a->user['guid'] . $a->user['prvkey'] . session_id() . $x[0] . $typename);
|
||||
|
||||
|
@ -441,7 +448,7 @@ function check_form_security_token_redirectOnErr($err_redirect, $typename = '',
|
|||
}
|
||||
function check_form_security_token_ForbiddenOnErr($typename = '', $formname = 'form_security_token') {
|
||||
if (!check_form_security_token($typename, $formname)) {
|
||||
$a = get_app();
|
||||
$a = get_app();
|
||||
logger('check_form_security_token failed: user ' . $a->user['guid'] . ' - form element ' . $typename);
|
||||
logger('check_form_security_token failed: _REQUEST data: ' . print_r($_REQUEST, true), LOGGER_DATA);
|
||||
header('HTTP/1.1 403 Forbidden');
|
||||
|
@ -454,7 +461,7 @@ function check_form_security_token_ForbiddenOnErr($typename = '', $formname = 'f
|
|||
// DFRN contact. They are *not* neccessarily unique across the entire site.
|
||||
|
||||
|
||||
if(! function_exists('init_groups_visitor')) {
|
||||
if (! function_exists('init_groups_visitor')) {
|
||||
function init_groups_visitor($contact_id) {
|
||||
$groups = array();
|
||||
$r = q("SELECT `gid` FROM `group_member`
|
||||
|
@ -462,9 +469,8 @@ function init_groups_visitor($contact_id) {
|
|||
intval($contact_id)
|
||||
);
|
||||
if (dbm::is_result($r)) {
|
||||
foreach($r as $rr)
|
||||
foreach ($r as $rr)
|
||||
$groups[] = $rr['gid'];
|
||||
}
|
||||
return $groups;
|
||||
}}
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ function ref_session_write($id, $data) {
|
|||
|
||||
$memcache = cache::memcache();
|
||||
$a = get_app();
|
||||
if (is_object($memcache) AND is_object($a)) {
|
||||
if (is_object($memcache) && is_object($a)) {
|
||||
$memcache->set($a->get_hostname().":session:".$id, $data, MEMCACHE_COMPRESSED, $expire);
|
||||
return true;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -13,7 +13,7 @@ function spool_post_run($argv, $argc) {
|
|||
|
||||
$path = get_spoolpath();
|
||||
|
||||
if (($path != '') AND is_writable($path)){
|
||||
if (($path != '') && is_writable($path)){
|
||||
if ($dh = opendir($path)) {
|
||||
while (($file = readdir($dh)) !== false) {
|
||||
|
||||
|
@ -30,7 +30,7 @@ function spool_post_run($argv, $argc) {
|
|||
}
|
||||
|
||||
// We can't read or write the file? So we don't care about it.
|
||||
if (!is_writable($fullfile) OR !is_readable($fullfile)) {
|
||||
if (!is_writable($fullfile) || !is_readable($fullfile)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ function spool_post_run($argv, $argc) {
|
|||
}
|
||||
|
||||
// Skip if it doesn't seem to be an item array
|
||||
if (!isset($arr['uid']) AND !isset($arr['uri']) AND !isset($arr['network'])) {
|
||||
if (!isset($arr['uid']) && !isset($arr['uri']) && !isset($arr['network'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ function create_tags_from_item($itemid) {
|
|||
|
||||
$tags = "";
|
||||
foreach ($taglist as $tag)
|
||||
if ((substr(trim($tag), 0, 1) == "#") OR (substr(trim($tag), 0, 1) == "@"))
|
||||
if ((substr(trim($tag), 0, 1) == "#") || (substr(trim($tag), 0, 1) == "@"))
|
||||
$tags .= " ".trim($tag);
|
||||
else
|
||||
$tags .= " #".trim($tag);
|
||||
|
@ -58,10 +58,10 @@ function create_tags_from_item($itemid) {
|
|||
|
||||
if (substr(trim($tag), 0, 1) == "#") {
|
||||
// try to ignore #039 or #1 or anything like that
|
||||
if(ctype_digit(substr(trim($tag),1)))
|
||||
if (ctype_digit(substr(trim($tag),1)))
|
||||
continue;
|
||||
// try to ignore html hex escapes, e.g. #x2317
|
||||
if((substr(trim($tag),1,1) == 'x' || substr(trim($tag),1,1) == 'X') && ctype_digit(substr(trim($tag),2)))
|
||||
if ((substr(trim($tag),1,1) == 'x' || substr(trim($tag),1,1) == 'X') && ctype_digit(substr(trim($tag),2)))
|
||||
continue;
|
||||
$type = TERM_HASHTAG;
|
||||
$term = substr($tag, 1);
|
||||
|
@ -91,7 +91,7 @@ function create_tags_from_item($itemid) {
|
|||
dbesc($link), dbesc($message["guid"]), dbesc($message["created"]), dbesc($message["received"]), intval($global));
|
||||
|
||||
// Search for mentions
|
||||
if ((substr($tag, 0, 1) == '@') AND (strpos($link, $profile_base_friendica) OR strpos($link, $profile_base_diaspora))) {
|
||||
if ((substr($tag, 0, 1) == '@') && (strpos($link, $profile_base_friendica) || strpos($link, $profile_base_diaspora))) {
|
||||
$users = q("SELECT `uid` FROM `contact` WHERE self AND (`url` = '%s' OR `nurl` = '%s')", $link, $link);
|
||||
foreach ($users AS $user) {
|
||||
if ($user["uid"] == $message["uid"]) {
|
||||
|
@ -107,9 +107,10 @@ function create_tags_from_item($itemid) {
|
|||
function create_tags_from_itemuri($itemuri, $uid) {
|
||||
$messages = q("SELECT `id` FROM `item` WHERE uri ='%s' AND uid=%d", dbesc($itemuri), intval($uid));
|
||||
|
||||
if(count($messages)) {
|
||||
foreach ($messages as $message)
|
||||
if (count($messages)) {
|
||||
foreach ($messages as $message) {
|
||||
create_tags_from_item($message["id"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ class Template implements ITemplateEngine {
|
|||
* {{ if <$var>==<val|$var> }}...[{{ else }} ...]{{ endif }}
|
||||
* {{ if <$var>!=<val|$var> }}...[{{ else }} ...]{{ endif }}
|
||||
*/
|
||||
private function _replcb_if($args) {
|
||||
private function _replcb_if ($args) {
|
||||
if (strpos($args[2], "==") > 0) {
|
||||
list($a, $b) = array_map("trim", explode("==", $args[2]));
|
||||
$a = $this->_get_var($a);
|
||||
|
@ -95,7 +95,7 @@ class Template implements ITemplateEngine {
|
|||
* {{ for <$var> as $name }}...{{ endfor }}
|
||||
* {{ for <$var> as $key=>$name }}...{{ endfor }}
|
||||
*/
|
||||
private function _replcb_for($args) {
|
||||
private function _replcb_for ($args) {
|
||||
$m = array_map('trim', explode(" as ", $args[2]));
|
||||
$x = explode("=>", $m[1]);
|
||||
if (count($x) == 1) {
|
||||
|
@ -109,14 +109,16 @@ class Template implements ITemplateEngine {
|
|||
//$vals = $this->r[$m[0]];
|
||||
$vals = $this->_get_var($m[0]);
|
||||
$ret = "";
|
||||
if (!is_array($vals))
|
||||
if (!is_array($vals)) {
|
||||
return $ret;
|
||||
}
|
||||
foreach ($vals as $k => $v) {
|
||||
$this->_push_stack();
|
||||
$r = $this->r;
|
||||
$r[$varname] = $v;
|
||||
if ($keyname != '')
|
||||
if ($keyname != '') {
|
||||
$r[$keyname] = (($k === 0) ? '0' : $k);
|
||||
}
|
||||
$ret .= $this->replace($args[3], $r);
|
||||
$this->_pop_stack();
|
||||
}
|
||||
|
|
625
include/text.php
625
include/text.php
File diff suppressed because it is too large
Load diff
|
@ -45,12 +45,12 @@ function add_shadow_thread($itemid) {
|
|||
$item = $items[0];
|
||||
|
||||
// is it already a copy?
|
||||
if (($itemid == 0) OR ($item['uid'] == 0)) {
|
||||
if (($itemid == 0) || ($item['uid'] == 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Is it a visible public post?
|
||||
if (!$item["visible"] OR $item["deleted"] OR $item["moderated"] OR $item["private"]) {
|
||||
if (!$item["visible"] || $item["deleted"] || $item["moderated"] || $item["private"]) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -86,8 +86,8 @@ function add_shadow_thread($itemid) {
|
|||
|
||||
$item = q("SELECT * FROM `item` WHERE `id` = %d", intval($itemid));
|
||||
|
||||
if (count($item) AND ($item[0]["allow_cid"] == '') AND ($item[0]["allow_gid"] == '') AND
|
||||
($item[0]["deny_cid"] == '') AND ($item[0]["deny_gid"] == '')) {
|
||||
if (count($item) && ($item[0]["allow_cid"] == '') && ($item[0]["allow_gid"] == '') &&
|
||||
($item[0]["deny_cid"] == '') && ($item[0]["deny_gid"] == '')) {
|
||||
|
||||
$r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = 0 LIMIT 1",
|
||||
dbesc($item['uri']));
|
||||
|
@ -177,29 +177,34 @@ function add_shadow_entry($itemid) {
|
|||
function update_thread_uri($itemuri, $uid) {
|
||||
$messages = q("SELECT `id` FROM `item` WHERE uri ='%s' AND uid=%d", dbesc($itemuri), intval($uid));
|
||||
|
||||
if (dbm::is_result($messages))
|
||||
foreach ($messages as $message)
|
||||
if (dbm::is_result($messages)) {
|
||||
foreach ($messages as $message) {
|
||||
update_thread($message["id"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function update_thread($itemid, $setmention = false) {
|
||||
$items = q("SELECT `uid`, `guid`, `title`, `body`, `created`, `edited`, `commented`, `received`, `changed`, `wall`, `private`, `pubmail`, `moderated`, `visible`, `spam`, `starred`, `bookmark`, `contact-id`, `gcontact-id`,
|
||||
`deleted`, `origin`, `forum_mode`, `network`, `rendered-html`, `rendered-hash` FROM `item` WHERE `id` = %d AND (`parent` = %d OR `parent` = 0) LIMIT 1", intval($itemid), intval($itemid));
|
||||
|
||||
if (!dbm::is_result($items))
|
||||
if (!dbm::is_result($items)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$item = $items[0];
|
||||
|
||||
if ($setmention)
|
||||
if ($setmention) {
|
||||
$item["mention"] = 1;
|
||||
}
|
||||
|
||||
$sql = "";
|
||||
|
||||
foreach ($item AS $field => $data)
|
||||
if (!in_array($field, array("guid", "title", "body", "rendered-html", "rendered-hash"))) {
|
||||
if ($sql != "")
|
||||
if ($sql != "") {
|
||||
$sql .= ", ";
|
||||
}
|
||||
|
||||
$sql .= "`".$field."` = '".dbesc($data)."'";
|
||||
}
|
||||
|
@ -211,8 +216,9 @@ function update_thread($itemid, $setmention = false) {
|
|||
// Updating a shadow item entry
|
||||
$items = q("SELECT `id` FROM `item` WHERE `guid` = '%s' AND `uid` = 0 LIMIT 1", dbesc($item["guid"]));
|
||||
|
||||
if (!$items)
|
||||
if (!dbm::is_result($items)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$result = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `rendered-html` = '%s', `rendered-hash` = '%s' WHERE `id` = %d",
|
||||
dbesc($item["title"]),
|
||||
|
@ -227,9 +233,11 @@ function update_thread($itemid, $setmention = false) {
|
|||
function delete_thread_uri($itemuri, $uid) {
|
||||
$messages = q("SELECT `id` FROM `item` WHERE uri ='%s' AND uid=%d", dbesc($itemuri), intval($uid));
|
||||
|
||||
if(count($messages))
|
||||
foreach ($messages as $message)
|
||||
if (dbm::is_result($messages)) {
|
||||
foreach ($messages as $message) {
|
||||
delete_thread($message["id"], $itemuri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function delete_thread($itemid, $itemuri = "") {
|
||||
|
|
|
@ -40,16 +40,16 @@ function update_gcontact_run(&$argv, &$argc) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (($data["name"] == "") AND ($r[0]['name'] != ""))
|
||||
if (($data["name"] == "") && ($r[0]['name'] != ""))
|
||||
$data["name"] = $r[0]['name'];
|
||||
|
||||
if (($data["nick"] == "") AND ($r[0]['nick'] != ""))
|
||||
if (($data["nick"] == "") && ($r[0]['nick'] != ""))
|
||||
$data["nick"] = $r[0]['nick'];
|
||||
|
||||
if (($data["addr"] == "") AND ($r[0]['addr'] != ""))
|
||||
if (($data["addr"] == "") && ($r[0]['addr'] != ""))
|
||||
$data["addr"] = $r[0]['addr'];
|
||||
|
||||
if (($data["photo"] == "") AND ($r[0]['photo'] != ""))
|
||||
if (($data["photo"] == "") && ($r[0]['photo'] != ""))
|
||||
$data["photo"] = $r[0]['photo'];
|
||||
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ class xml {
|
|||
}
|
||||
|
||||
foreach($array as $key => $value) {
|
||||
if (!isset($element) AND isset($xml)) {
|
||||
if (!isset($element) && isset($xml)) {
|
||||
$element = $xml;
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ class xml {
|
|||
}
|
||||
|
||||
$element_parts = explode(":", $key);
|
||||
if ((count($element_parts) > 1) AND isset($namespaces[$element_parts[0]])) {
|
||||
if ((count($element_parts) > 1) && isset($namespaces[$element_parts[0]])) {
|
||||
$namespace = $namespaces[$element_parts[0]];
|
||||
} elseif (isset($namespaces[""])) {
|
||||
$namespace = $namespaces[""];
|
||||
|
@ -76,18 +76,18 @@ class xml {
|
|||
}
|
||||
|
||||
// Remove undefined namespaces from the key
|
||||
if ((count($element_parts) > 1) AND is_null($namespace)) {
|
||||
if ((count($element_parts) > 1) && is_null($namespace)) {
|
||||
$key = $element_parts[1];
|
||||
}
|
||||
|
||||
if (substr($key, 0, 11) == "@attributes") {
|
||||
if (!isset($element) OR !is_array($value)) {
|
||||
if (!isset($element) || !is_array($value)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($value as $attr_key => $attr_value) {
|
||||
$element_parts = explode(":", $attr_key);
|
||||
if ((count($element_parts) > 1) AND isset($namespaces[$element_parts[0]])) {
|
||||
if ((count($element_parts) > 1) && isset($namespaces[$element_parts[0]])) {
|
||||
$namespace = $namespaces[$element_parts[0]];
|
||||
} else {
|
||||
$namespace = NULL;
|
||||
|
@ -323,7 +323,7 @@ class xml {
|
|||
|
||||
if ($type == "open") { // The starting of the tag '<tag>'
|
||||
$parent[$level-1] = &$current;
|
||||
if (!is_array($current) or (!in_array($tag, array_keys($current)))) { // Insert New tag
|
||||
if (!is_array($current) || (!in_array($tag, array_keys($current)))) { // Insert New tag
|
||||
$current[$tag] = $result;
|
||||
if ($attributes_data) {
|
||||
$current[$tag. '_attr'] = $attributes_data;
|
||||
|
|
14
index.php
14
index.php
|
@ -59,15 +59,15 @@ if (!$install) {
|
|||
|
||||
Config::load();
|
||||
|
||||
if ($a->max_processes_reached() OR $a->maxload_reached()) {
|
||||
if ($a->max_processes_reached() || $a->maxload_reached()) {
|
||||
header($_SERVER["SERVER_PROTOCOL"] . ' 503 Service Temporarily Unavailable');
|
||||
header('Retry-After: 120');
|
||||
header('Refresh: 120; url=' . App::get_baseurl() . "/" . $a->query_string);
|
||||
die("System is currently unavailable. Please try again later");
|
||||
}
|
||||
|
||||
if (get_config('system', 'force_ssl') AND ($a->get_scheme() == "http") AND
|
||||
(intval(get_config('system', 'ssl_policy')) == SSL_POLICY_FULL) AND
|
||||
if (get_config('system', 'force_ssl') && ($a->get_scheme() == "http") &&
|
||||
(intval(get_config('system', 'ssl_policy')) == SSL_POLICY_FULL) &&
|
||||
(substr(App::get_baseurl(), 0, 8) == "https://")) {
|
||||
header("HTTP/1.1 302 Moved Temporarily");
|
||||
header("Location: " . App::get_baseurl() . "/" . $a->query_string);
|
||||
|
@ -128,7 +128,7 @@ if ((x($_SESSION,'language')) && ($_SESSION['language'] !== $lang)) {
|
|||
if ((x($_GET,'zrl')) && (!$install && !$maintenance)) {
|
||||
// Only continue when the given profile link seems valid
|
||||
// Valid profile links contain a path with "/profile/" and no query parameters
|
||||
if ((parse_url($_GET['zrl'], PHP_URL_QUERY) == "") AND
|
||||
if ((parse_url($_GET['zrl'], PHP_URL_QUERY) == "") &&
|
||||
strstr(parse_url($_GET['zrl'], PHP_URL_PATH), "/profile/")) {
|
||||
$_SESSION['my_url'] = $_GET['zrl'];
|
||||
$a->query_string = preg_replace('/[\?&]zrl=(.*?)([\?&]|$)/is','',$a->query_string);
|
||||
|
@ -245,7 +245,7 @@ if (strlen($a->module)) {
|
|||
}
|
||||
|
||||
// Compatibility with the Firefox App
|
||||
if (($a->module == "users") AND ($a->cmd == "users/sign_in")) {
|
||||
if (($a->module == "users") && ($a->cmd == "users/sign_in")) {
|
||||
$a->module = "login";
|
||||
}
|
||||
|
||||
|
@ -450,7 +450,7 @@ if (!$a->theme['stylesheet']) {
|
|||
$a->page['htmlhead'] = str_replace('{{$stylesheet}}',$stylesheet,$a->page['htmlhead']);
|
||||
//$a->page['htmlhead'] = replace_macros($a->page['htmlhead'], array('$stylesheet' => $stylesheet));
|
||||
|
||||
if (isset($_GET["mode"]) AND (($_GET["mode"] == "raw") OR ($_GET["mode"] == "minimal"))) {
|
||||
if (isset($_GET["mode"]) && (($_GET["mode"] == "raw") || ($_GET["mode"] == "minimal"))) {
|
||||
$doc = new DOMDocument();
|
||||
|
||||
$target = new DOMDocument();
|
||||
|
@ -473,7 +473,7 @@ if (isset($_GET["mode"]) AND (($_GET["mode"] == "raw") OR ($_GET["mode"] == "min
|
|||
}
|
||||
}
|
||||
|
||||
if (isset($_GET["mode"]) AND ($_GET["mode"] == "raw")) {
|
||||
if (isset($_GET["mode"]) && ($_GET["mode"] == "raw")) {
|
||||
|
||||
header("Content-type: text/html; charset=utf-8");
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ use Friendica\Core\Config;
|
|||
|
||||
require_once("include/enotify.php");
|
||||
require_once("include/text.php");
|
||||
require_once('include/items.php');
|
||||
|
||||
/**
|
||||
* @brief Process send data from the admin panels subpages
|
||||
|
@ -113,6 +114,9 @@ function admin_post(App $a) {
|
|||
case 'blocklist':
|
||||
admin_page_blocklist_post($a);
|
||||
break;
|
||||
case 'deleteitem':
|
||||
admin_page_deleteitem_post($a);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -172,6 +176,7 @@ function admin_content(App $a) {
|
|||
'queue' => array("admin/queue/", t('Inspect Queue'), "queue"),
|
||||
'blocklist' => array("admin/blocklist/", t('Server Blocklist'), "blocklist"),
|
||||
'federation' => array("admin/federation/", t('Federation Statistics'), "federation"),
|
||||
'deleteitem' => array("admin/deleteitem/", t('Delete Item'), 'deleteitem'),
|
||||
);
|
||||
|
||||
/* get plugins admin page */
|
||||
|
@ -244,6 +249,9 @@ function admin_content(App $a) {
|
|||
case 'blocklist':
|
||||
$o = admin_page_blocklist($a);
|
||||
break;
|
||||
case 'deleteitem':
|
||||
$o = admin_page_deleteitem($a);
|
||||
break;
|
||||
default:
|
||||
notice(t("Item not found."));
|
||||
}
|
||||
|
@ -348,6 +356,67 @@ function admin_page_blocklist_post(App $a) {
|
|||
return; // NOTREACHED
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Subpage where the admin can delete an item from their node given the GUID
|
||||
*
|
||||
* This subpage of the admin panel offers the nodes admin to delete an item from
|
||||
* the node, given the GUID or the display URL such as http://example.com/display/123456.
|
||||
* The item will then be marked as deleted in the database and processed accordingly.
|
||||
*
|
||||
* @param App $a
|
||||
* @return string
|
||||
*/
|
||||
function admin_page_deleteitem(App $a) {
|
||||
$t = get_markup_template("admin_deleteitem.tpl");
|
||||
|
||||
return replace_macros($t, array(
|
||||
'$title' => t('Administration'),
|
||||
'$page' => t('Delete Item'),
|
||||
'$submit' => t('Delete this Item'),
|
||||
'$intro1' => t('On this page you can delete an item from your node. If the item is a top level posting, the entire thread will be deleted.'),
|
||||
'$intro2' => t('You need to know the GUID of the item. You can find it e.g. by looking at the display URL. The last part of http://example.com/display/123456 is the GUID, here 123456.'),
|
||||
'$deleteitemguid' => array('deleteitemguid', t("GUID"), '', t("The GUID of the item you want to delete."), 'required', 'autofocus'),
|
||||
'$baseurl' => App::get_baseurl(),
|
||||
'$form_security_token' => get_form_security_token("admin_deleteitem")
|
||||
));
|
||||
}
|
||||
/**
|
||||
* @brief Process send data from Admin Delete Item Page
|
||||
*
|
||||
* The GUID passed through the form should be only the GUID. But we also parse
|
||||
* URLs like the full /display URL to make the process more easy for the admin.
|
||||
*
|
||||
* @param App $a
|
||||
*/
|
||||
function admin_page_deleteitem_post(App $a) {
|
||||
if (!x($_POST['page_deleteitem_submit'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
check_form_security_token_redirectOnErr('/admin/deleteitem/', 'admin_deleteitem');
|
||||
|
||||
if (x($_POST['page_deleteitem_submit'])) {
|
||||
$guid = trim(notags($_POST['deleteitemguid']));
|
||||
// The GUID should not include a "/", so if there is one, we got an URL
|
||||
// and the last part of it is most likely the GUID.
|
||||
if (strpos($guid, '/')) {
|
||||
$guid = substr($guid, strrpos($guid, '/')+1);
|
||||
}
|
||||
// Now that we have the GUID get all IDs of the associated entries in the
|
||||
// item table of the DB and drop those items, which will also delete the
|
||||
// associated threads.
|
||||
$r = dba::select('item', array('id'), array('guid'=>$guid));
|
||||
while ($row = dba::fetch($r)) {
|
||||
drop_item($row['id'], false);
|
||||
}
|
||||
dba::close($r);
|
||||
}
|
||||
|
||||
info(t('Item marked for deletion.').EOL);
|
||||
goaway('admin/deleteitem');
|
||||
return; // NOTREACHED
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Subpage with some stats about "the federation" network
|
||||
*
|
||||
|
@ -558,11 +627,11 @@ function admin_page_summary(App $a) {
|
|||
$r = q("SELECT `page-flags`, COUNT(`uid`) AS `count` FROM `user` GROUP BY `page-flags`");
|
||||
$accounts = array(
|
||||
array(t('Normal Account'), 0),
|
||||
array(t('Soapbox Account'), 0),
|
||||
array(t('Community/Celebrity Account'), 0),
|
||||
array(t('Automatic Follower Account'), 0),
|
||||
array(t('Public Forum Account'), 0),
|
||||
array(t('Automatic Friend Account'), 0),
|
||||
array(t('Blog Account'), 0),
|
||||
array(t('Private Forum'), 0)
|
||||
array(t('Private Forum Account'), 0)
|
||||
);
|
||||
|
||||
$users=0;
|
||||
|
@ -579,7 +648,7 @@ function admin_page_summary(App $a) {
|
|||
$r = qu("SELECT COUNT(*) AS `total` FROM `queue` WHERE 1");
|
||||
$queue = (($r) ? $r[0]['total'] : 0);
|
||||
|
||||
$r = qu("SELECT COUNT(*) AS `total` FROM `workerqueue` WHERE 1");
|
||||
$r = qu("SELECT COUNT(*) AS `total` FROM `workerqueue` WHERE NOT `done`");
|
||||
$workerqueue = (($r) ? $r[0]['total'] : 0);
|
||||
|
||||
// We can do better, but this is a quick queue status
|
||||
|
@ -770,7 +839,7 @@ function admin_page_site_post(App $a) {
|
|||
$worker_frontend = ((x($_POST,'worker_frontend')) ? True : False);
|
||||
|
||||
// Has the directory url changed? If yes, then resubmit the existing profiles there
|
||||
if ($global_directory != Config::get('system', 'directory') AND ($global_directory != '')) {
|
||||
if ($global_directory != Config::get('system', 'directory') && ($global_directory != '')) {
|
||||
Config::set('system', 'directory', $global_directory);
|
||||
proc_run(PRIORITY_LOW, 'include/directory.php');
|
||||
}
|
||||
|
@ -936,7 +1005,7 @@ function admin_page_site(App $a) {
|
|||
/* Installed langs */
|
||||
$lang_choices = get_available_languages();
|
||||
|
||||
if (strlen(get_config('system','directory_submit_url')) AND
|
||||
if (strlen(get_config('system','directory_submit_url')) &&
|
||||
!strlen(get_config('system','directory'))) {
|
||||
set_config('system','directory', dirname(get_config('system','directory_submit_url')));
|
||||
del_config('system','directory_submit_url');
|
||||
|
@ -958,7 +1027,7 @@ function admin_page_site(App $a) {
|
|||
$f = basename($file);
|
||||
|
||||
// Only show allowed themes here
|
||||
if (($allowed_theme_list != '') AND !strstr($allowed_theme_list, $f)) {
|
||||
if (($allowed_theme_list != '') && !strstr($allowed_theme_list, $f)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -1183,7 +1252,7 @@ function admin_page_dbsync(App $a) {
|
|||
goaway('admin/dbsync');
|
||||
}
|
||||
|
||||
if (($a->argc > 2) AND (intval($a->argv[2]) OR ($a->argv[2] === 'check'))) {
|
||||
if (($a->argc > 2) && (intval($a->argv[2]) || ($a->argv[2] === 'check'))) {
|
||||
require_once("include/dbstructure.php");
|
||||
$retval = update_structure(false, true);
|
||||
if (!$retval) {
|
||||
|
@ -1451,8 +1520,8 @@ function admin_page_users(App $a) {
|
|||
$_setup_users = function ($e) use ($adminlist) {
|
||||
$accounts = array(
|
||||
t('Normal Account'),
|
||||
t('Soapbox Account'),
|
||||
t('Community/Celebrity Account'),
|
||||
t('Automatic Follower Account'),
|
||||
t('Public Forum Account'),
|
||||
t('Automatic Friend Account')
|
||||
);
|
||||
$e['page-flags'] = $accounts[$e['page-flags']];
|
||||
|
@ -1663,7 +1732,7 @@ function admin_page_plugins(App $a) {
|
|||
$show_plugin = true;
|
||||
|
||||
// If the addon is unsupported, then only show it, when it is enabled
|
||||
if ((strtolower($info["status"]) == "unsupported") AND !in_array($id, $a->plugins)) {
|
||||
if ((strtolower($info["status"]) == "unsupported") && !in_array($id, $a->plugins)) {
|
||||
$show_plugin = false;
|
||||
}
|
||||
|
||||
|
@ -1801,7 +1870,7 @@ function admin_page_themes(App $a) {
|
|||
$is_supported = 1-(intval(file_exists($file.'/unsupported')));
|
||||
$is_allowed = intval(in_array($f,$allowed_themes));
|
||||
|
||||
if ($is_allowed OR $is_supported OR get_config("system", "show_unsupported_themes")) {
|
||||
if ($is_allowed || $is_supported || get_config("system", "show_unsupported_themes")) {
|
||||
$themes[] = array('name' => $f, 'experimental' => $is_experimental, 'supported' => $is_supported, 'allowed' => $is_allowed);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,14 +68,14 @@ function community_content(App $a, $update = 0) {
|
|||
}
|
||||
$previousauthor = $item["author-link"];
|
||||
|
||||
if (($numposts < $maxpostperauthor) AND (sizeof($s) < $a->pager['itemspage'])) {
|
||||
if (($numposts < $maxpostperauthor) && (sizeof($s) < $a->pager['itemspage'])) {
|
||||
$s[] = $item;
|
||||
}
|
||||
}
|
||||
if ((sizeof($s) < $a->pager['itemspage'])) {
|
||||
$r = community_getitems($a->pager['start'] + ($count * $a->pager['itemspage']), $a->pager['itemspage']);
|
||||
}
|
||||
} while ((sizeof($s) < $a->pager['itemspage']) AND (++$count < 50) AND (sizeof($r) > 0));
|
||||
} while ((sizeof($s) < $a->pager['itemspage']) && (++$count < 50) && (sizeof($r) > 0));
|
||||
} else {
|
||||
$s = $r;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ function contacts_init(App $a) {
|
|||
|
||||
$contact_id = 0;
|
||||
|
||||
if((($a->argc == 2) && intval($a->argv[1])) OR (($a->argc == 3) && intval($a->argv[1]) && ($a->argv[2] == "posts"))) {
|
||||
if((($a->argc == 2) && intval($a->argv[1])) || (($a->argc == 3) && intval($a->argv[1]) && ($a->argv[2] == "posts"))) {
|
||||
$contact_id = intval($a->argv[1]);
|
||||
$r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
|
||||
intval(local_user()),
|
||||
|
@ -42,7 +42,7 @@ function contacts_init(App $a) {
|
|||
if ($contact_id) {
|
||||
$a->data['contact'] = $r[0];
|
||||
|
||||
if (($a->data['contact']['network'] != "") AND ($a->data['contact']['network'] != NETWORK_DFRN)) {
|
||||
if (($a->data['contact']['network'] != "") && ($a->data['contact']['network'] != NETWORK_DFRN)) {
|
||||
$networkname = format_network_name($a->data['contact']['network'],$a->data['contact']['url']);
|
||||
} else {
|
||||
$networkname = '';
|
||||
|
@ -266,7 +266,7 @@ function _contact_update_profile($contact_id) {
|
|||
$data = Probe::uri($r[0]["url"], "", 0, false);
|
||||
|
||||
// "Feed" or "Unknown" is mostly a sign of communication problems
|
||||
if ((in_array($data["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) AND ($data["network"] != $r[0]["network"]))
|
||||
if ((in_array($data["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) && ($data["network"] != $r[0]["network"]))
|
||||
return;
|
||||
|
||||
$updatefields = array("name", "nick", "url", "addr", "batch", "notify", "poll", "request", "confirm",
|
||||
|
@ -281,14 +281,14 @@ function _contact_update_profile($contact_id) {
|
|||
}
|
||||
|
||||
foreach($updatefields AS $field)
|
||||
if (isset($data[$field]) AND ($data[$field] != ""))
|
||||
if (isset($data[$field]) && ($data[$field] != ""))
|
||||
$update[$field] = $data[$field];
|
||||
|
||||
$update["nurl"] = normalise_link($data["url"]);
|
||||
|
||||
$query = "";
|
||||
|
||||
if (isset($data["priority"]) AND ($data["priority"] != 0))
|
||||
if (isset($data["priority"]) && ($data["priority"] != 0))
|
||||
$query = "`priority` = ".intval($data["priority"]);
|
||||
|
||||
foreach($update AS $key => $value) {
|
||||
|
@ -573,7 +573,7 @@ function contacts_content(App $a) {
|
|||
if ($contact['network'] == NETWORK_DFRN)
|
||||
$profile_select = contact_profile_assign($contact['profile-id'],(($contact['network'] !== NETWORK_DFRN) ? true : false));
|
||||
|
||||
if (in_array($contact['network'], array(NETWORK_DIASPORA, NETWORK_OSTATUS)) AND
|
||||
if (in_array($contact['network'], array(NETWORK_DIASPORA, NETWORK_OSTATUS)) &&
|
||||
($contact['rel'] == CONTACT_IS_FOLLOWER))
|
||||
$follow = App::get_baseurl(true)."/follow?url=".urlencode($contact["url"]);
|
||||
|
||||
|
|
|
@ -626,7 +626,7 @@ function dfrn_request_post(App $a) {
|
|||
);
|
||||
// NOTREACHED
|
||||
// END $network === NETWORK_DFRN
|
||||
} elseif (($network != NETWORK_PHANTOM) AND ($url != "")) {
|
||||
} elseif (($network != NETWORK_PHANTOM) && ($url != "")) {
|
||||
|
||||
/*
|
||||
*
|
||||
|
@ -693,7 +693,7 @@ function dfrn_request_content(App $a) {
|
|||
$confirm_key = (x($_GET,'confirm_key') ? $_GET['confirm_key'] : "");
|
||||
|
||||
// Checking fastlane for validity
|
||||
if (x($_SESSION, "fastlane") AND (normalise_link($_SESSION["fastlane"]) == normalise_link($dfrn_url))) {
|
||||
if (x($_SESSION, "fastlane") && (normalise_link($_SESSION["fastlane"]) == normalise_link($dfrn_url))) {
|
||||
$_POST["dfrn_url"] = $dfrn_url;
|
||||
$_POST["confirm_key"] = $confirm_key;
|
||||
$_POST["localconfirm"] = 1;
|
||||
|
@ -813,9 +813,9 @@ function dfrn_request_content(App $a) {
|
|||
|
||||
// At first look if an address was provided
|
||||
// Otherwise take the local address
|
||||
if (x($_GET,'addr') AND ($_GET['addr'] != "")) {
|
||||
if (x($_GET,'addr') && ($_GET['addr'] != "")) {
|
||||
$myaddr = hex2bin($_GET['addr']);
|
||||
} elseif (x($_GET,'address') AND ($_GET['address'] != "")) {
|
||||
} elseif (x($_GET,'address') && ($_GET['address'] != "")) {
|
||||
$myaddr = $_GET['address'];
|
||||
} elseif (local_user()) {
|
||||
if (strlen($a->path)) {
|
||||
|
|
|
@ -37,7 +37,7 @@ function dirfind_content(App $a, $prefix = "") {
|
|||
if (strpos($search,'@') === 0) {
|
||||
$search = substr($search,1);
|
||||
$header = sprintf( t('People Search - %s'), $search);
|
||||
if ((valid_email($search) AND validate_email($search)) OR
|
||||
if ((valid_email($search) && validate_email($search)) ||
|
||||
(substr(normalise_link($search), 0, 7) == "http://")) {
|
||||
$user_data = probe_url($search);
|
||||
$discover_user = (in_array($user_data["network"], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA)));
|
||||
|
@ -75,7 +75,7 @@ function dirfind_content(App $a, $prefix = "") {
|
|||
$j->results[] = $objresult;
|
||||
|
||||
// Add the contact to the global contacts if it isn't already in our system
|
||||
if (($contact["cid"] == 0) AND ($contact["zid"] == 0) AND ($contact["gid"] == 0)) {
|
||||
if (($contact["cid"] == 0) && ($contact["zid"] == 0) && ($contact["gid"] == 0)) {
|
||||
update_gcontact($user_data);
|
||||
}
|
||||
} elseif ($local) {
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
use Friendica\App;
|
||||
|
||||
require_once('include/dfrn.php');
|
||||
|
||||
function display_init(App $a) {
|
||||
|
||||
if ((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
|
||||
|
@ -11,6 +13,19 @@ function display_init(App $a) {
|
|||
$nick = (($a->argc > 1) ? $a->argv[1] : '');
|
||||
$profiledata = array();
|
||||
|
||||
if ($a->argc == 3) {
|
||||
if (substr($a->argv[2], -5) == '.atom') {
|
||||
$item_id = substr($a->argv[2], 0, -5);
|
||||
$xml = dfrn::itemFeed($item_id);
|
||||
if ($xml == '') {
|
||||
http_status_exit(500);
|
||||
}
|
||||
header("Content-type: application/atom+xml");
|
||||
echo $xml;
|
||||
killme();
|
||||
}
|
||||
}
|
||||
|
||||
// If there is only one parameter, then check if this parameter could be a guid
|
||||
if ($a->argc == 2) {
|
||||
$nick = "";
|
||||
|
@ -59,7 +74,7 @@ function display_init(App $a) {
|
|||
WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
|
||||
AND `id` = %d", $r[0]["parent"]);
|
||||
}
|
||||
if (($itemuid != local_user()) AND local_user()) {
|
||||
if (($itemuid != local_user()) && local_user()) {
|
||||
// Do we know this contact but we haven't got this item?
|
||||
// Copy the wohle thread to our local storage so that we can interact.
|
||||
// We really should change this need for the future since it scales very bad.
|
||||
|
@ -129,11 +144,11 @@ function display_fetchauthor($a, $item) {
|
|||
|
||||
// Skip if it isn't a pure repeated messages
|
||||
// Does it start with a share?
|
||||
if (!$skip AND strpos($body, "[share") > 0) {
|
||||
if (!$skip && strpos($body, "[share") > 0) {
|
||||
$skip = true;
|
||||
}
|
||||
// Does it end with a share?
|
||||
if (!$skip AND (strlen($body) > (strrpos($body, "[/share]") + 8))) {
|
||||
if (!$skip && (strlen($body) > (strrpos($body, "[/share]") + 8))) {
|
||||
$skip = true;
|
||||
}
|
||||
if (!$skip) {
|
||||
|
@ -209,9 +224,6 @@ function display_content(App $a, $update = 0) {
|
|||
|
||||
$o = '';
|
||||
|
||||
$a->page['htmlhead'] .= replace_macros(get_markup_template('display-head.tpl'), array());
|
||||
|
||||
|
||||
if ($update) {
|
||||
$nick = $_REQUEST['nick'];
|
||||
} else {
|
||||
|
@ -265,7 +277,7 @@ function display_content(App $a, $update = 0) {
|
|||
}
|
||||
}
|
||||
|
||||
if ($item_id AND !is_numeric($item_id)) {
|
||||
if ($item_id && !is_numeric($item_id)) {
|
||||
$r = qu("SELECT `id` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
|
||||
dbesc($item_id), intval($a->profile['uid']));
|
||||
if (dbm::is_result($r)) {
|
||||
|
@ -281,6 +293,16 @@ function display_content(App $a, $update = 0) {
|
|||
return;
|
||||
}
|
||||
|
||||
// We are displaying an "alternate" link if that post was public. See issue 2864
|
||||
$items = q("SELECT `id` FROM `item` WHERE `id` = %d AND NOT `private` AND `wall`", intval($item_id));
|
||||
if (dbm::is_result($items)) {
|
||||
$alternate = App::get_baseurl().'/display/'.$nick.'/'.$item_id.'.atom';
|
||||
} else {
|
||||
$alternate = '';
|
||||
}
|
||||
|
||||
$a->page['htmlhead'] .= replace_macros(get_markup_template('display-head.tpl'),
|
||||
array('$alternate' => $alternate));
|
||||
|
||||
$groups = array();
|
||||
|
||||
|
|
|
@ -436,7 +436,7 @@ function events_content(App $a) {
|
|||
$sh_checked = (($orig_event['allow_cid'] === '<' . local_user() . '>' && (! $orig_event['allow_gid']) && (! $orig_event['deny_cid']) && (! $orig_event['deny_gid'])) ? '' : ' checked="checked" ');
|
||||
}
|
||||
|
||||
if ($cid OR ($mode !== 'new')) {
|
||||
if ($cid || ($mode !== 'new')) {
|
||||
$sh_checked .= ' disabled="disabled" ';
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ require_once("include/xml.php");
|
|||
|
||||
function fetch_init(App $a) {
|
||||
|
||||
if (($a->argc != 3) OR (!in_array($a->argv[1], array("post", "status_message", "reshare")))) {
|
||||
if (($a->argc != 3) || (!in_array($a->argv[1], array("post", "status_message", "reshare")))) {
|
||||
header($_SERVER["SERVER_PROTOCOL"].' 404 '.t('Not Found'));
|
||||
killme();
|
||||
}
|
||||
|
|
|
@ -37,14 +37,14 @@ function follow_content(App $a) {
|
|||
|
||||
$ret = probe_url($url);
|
||||
|
||||
if (($ret["network"] == NETWORK_DIASPORA) AND !get_config('system','diaspora_enabled')) {
|
||||
if (($ret["network"] == NETWORK_DIASPORA) && !get_config('system','diaspora_enabled')) {
|
||||
notice( t("Diaspora support isn't enabled. Contact can't be added.") . EOL);
|
||||
$submit = "";
|
||||
//goaway($_SESSION['return_url']);
|
||||
// NOTREACHED
|
||||
}
|
||||
|
||||
if (($ret["network"] == NETWORK_OSTATUS) AND get_config('system','ostatus_disabled')) {
|
||||
if (($ret["network"] == NETWORK_OSTATUS) && get_config('system','ostatus_disabled')) {
|
||||
notice( t("OStatus support is disabled. Contact can't be added.") . EOL);
|
||||
$submit = "";
|
||||
//goaway($_SESSION['return_url']);
|
||||
|
|
26
mod/item.php
26
mod/item.php
|
@ -139,8 +139,8 @@ function item_post(App $a) {
|
|||
|
||||
// If the contact id doesn't fit with the contact, then set the contact to null
|
||||
$thrparent = q("SELECT `author-link`, `network` FROM `item` WHERE `uri` = '%s' LIMIT 1", dbesc($thr_parent));
|
||||
if (dbm::is_result($thrparent) AND ($thrparent[0]["network"] === NETWORK_OSTATUS)
|
||||
AND (normalise_link($parent_contact["url"]) != normalise_link($thrparent[0]["author-link"]))) {
|
||||
if (dbm::is_result($thrparent) && ($thrparent[0]["network"] === NETWORK_OSTATUS)
|
||||
&& (normalise_link($parent_contact["url"]) != normalise_link($thrparent[0]["author-link"]))) {
|
||||
$parent_contact = get_contact_details_by_url($thrparent[0]["author-link"]);
|
||||
|
||||
if (!isset($parent_contact["nick"])) {
|
||||
|
@ -175,7 +175,7 @@ function item_post(App $a) {
|
|||
$object = ((x($_REQUEST, 'object')) ? $_REQUEST['object'] : '');
|
||||
|
||||
// Check for multiple posts with the same message id (when the post was created via API)
|
||||
if (($message_id != '') AND ($profile_uid != 0)) {
|
||||
if (($message_id != '') && ($profile_uid != 0)) {
|
||||
$r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
|
||||
dbesc($message_id),
|
||||
intval($profile_uid)
|
||||
|
@ -309,8 +309,8 @@ function item_post(App $a) {
|
|||
|
||||
// for non native networks use the network of the original post as network of the item
|
||||
if (($parent_item['network'] != NETWORK_DIASPORA)
|
||||
AND ($parent_item['network'] != NETWORK_OSTATUS)
|
||||
AND ($network == "")) {
|
||||
&& ($parent_item['network'] != NETWORK_OSTATUS)
|
||||
&& ($network == "")) {
|
||||
$network = $parent_item['network'];
|
||||
}
|
||||
|
||||
|
@ -504,7 +504,7 @@ function item_post(App $a) {
|
|||
|
||||
$bookmark = 0;
|
||||
$data = get_attachment_data($body);
|
||||
if (preg_match_all("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism", $body, $match, PREG_SET_ORDER) OR isset($data["type"])) {
|
||||
if (preg_match_all("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism", $body, $match, PREG_SET_ORDER) || isset($data["type"])) {
|
||||
$objecttype = ACTIVITY_OBJ_BOOKMARK;
|
||||
$bookmark = 1;
|
||||
}
|
||||
|
@ -543,7 +543,7 @@ function item_post(App $a) {
|
|||
* add a statusnet style reply tag if the original post was from there
|
||||
* and we are replying, and there isn't one already
|
||||
*/
|
||||
if ($parent AND ($parent_contact['network'] == NETWORK_OSTATUS)) {
|
||||
if ($parent && ($parent_contact['network'] == NETWORK_OSTATUS)) {
|
||||
$contact = '@[url=' . $parent_contact['url'] . ']' . $parent_contact['nick'] . '[/url]';
|
||||
|
||||
if (!in_array($contact, $tags)) {
|
||||
|
@ -1226,7 +1226,7 @@ function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $n
|
|||
}
|
||||
|
||||
// select someone by attag or nick and the name passed in the current network
|
||||
if(!dbm::is_result($r) AND ($network != ""))
|
||||
if(!dbm::is_result($r) && ($network != ""))
|
||||
$r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network` FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `network` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
|
||||
dbesc($name),
|
||||
dbesc($name),
|
||||
|
@ -1235,7 +1235,7 @@ function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $n
|
|||
);
|
||||
|
||||
//select someone from this user's contacts by name in the current network
|
||||
if (!dbm::is_result($r) AND ($network != "")) {
|
||||
if (!dbm::is_result($r) && ($network != "")) {
|
||||
$r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network` FROM `contact` WHERE `name` = '%s' AND `network` = '%s' AND `uid` = %d LIMIT 1",
|
||||
dbesc($name),
|
||||
dbesc($network),
|
||||
|
@ -1262,7 +1262,7 @@ function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $n
|
|||
}
|
||||
|
||||
if (dbm::is_result($r)) {
|
||||
if (strlen($inform) AND (isset($r[0]["notify"]) OR isset($r[0]["id"]))) {
|
||||
if (strlen($inform) && (isset($r[0]["notify"]) || isset($r[0]["id"]))) {
|
||||
$inform .= ',';
|
||||
}
|
||||
|
||||
|
@ -1275,14 +1275,14 @@ function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $n
|
|||
$profile = $r[0]["url"];
|
||||
$alias = $r[0]["alias"];
|
||||
$newname = $r[0]["nick"];
|
||||
if (($newname == "") OR (($r[0]["network"] != NETWORK_OSTATUS) AND ($r[0]["network"] != NETWORK_TWITTER)
|
||||
AND ($r[0]["network"] != NETWORK_STATUSNET) AND ($r[0]["network"] != NETWORK_APPNET))) {
|
||||
if (($newname == "") || (($r[0]["network"] != NETWORK_OSTATUS) && ($r[0]["network"] != NETWORK_TWITTER)
|
||||
&& ($r[0]["network"] != NETWORK_STATUSNET) && ($r[0]["network"] != NETWORK_APPNET))) {
|
||||
$newname = $r[0]["name"];
|
||||
}
|
||||
}
|
||||
|
||||
//if there is an url for this persons profile
|
||||
if (isset($profile) AND ($newname != "")) {
|
||||
if (isset($profile) && ($newname != "")) {
|
||||
|
||||
$replaced = true;
|
||||
// create profile link
|
||||
|
|
|
@ -398,7 +398,7 @@ function network_content(App $a, $update = 0) {
|
|||
}
|
||||
set_pconfig(local_user(), 'network.view', 'net.selected', ($nets ? $nets : 'all'));
|
||||
|
||||
if(!$update AND !$rawmode) {
|
||||
if(!$update && !$rawmode) {
|
||||
$tabs = network_tabs($a);
|
||||
$o .= $tabs;
|
||||
|
||||
|
@ -459,7 +459,7 @@ function network_content(App $a, $update = 0) {
|
|||
$sql_table = "`thread`";
|
||||
$sql_parent = "`iid`";
|
||||
|
||||
if ($nouveau OR strlen($file) OR $update) {
|
||||
if ($nouveau || strlen($file) || $update) {
|
||||
$sql_table = "`item`";
|
||||
$sql_parent = "`parent`";
|
||||
$sql_post_table = " INNER JOIN `thread` ON `thread`.`iid` = `item`.`parent`";
|
||||
|
|
|
@ -25,12 +25,12 @@ function nodeinfo_init(App $a) {
|
|||
killme();
|
||||
}
|
||||
|
||||
if (($a->argc != 2) OR ($a->argv[1] != '1.0')) {
|
||||
if (($a->argc != 2) || ($a->argv[1] != '1.0')) {
|
||||
http_status_exit(404);
|
||||
killme();
|
||||
}
|
||||
|
||||
$smtp = (function_exists('imap_open') AND !Config::get('system', 'imap_disabled') AND !Config::get('system', 'dfrn_only'));
|
||||
$smtp = (function_exists('imap_open') && !Config::get('system', 'imap_disabled') && !Config::get('system', 'dfrn_only'));
|
||||
|
||||
$nodeinfo = array();
|
||||
$nodeinfo['version'] = '1.0';
|
||||
|
@ -74,7 +74,7 @@ function nodeinfo_init(App $a) {
|
|||
if (plugin_enabled('appnet')) {
|
||||
$nodeinfo['services']['inbound'][] = 'appnet';
|
||||
}
|
||||
if (plugin_enabled('appnet') OR plugin_enabled('buffer')) {
|
||||
if (plugin_enabled('appnet') || plugin_enabled('buffer')) {
|
||||
$nodeinfo['services']['outbound'][] = 'appnet';
|
||||
}
|
||||
if (plugin_enabled('blogger')) {
|
||||
|
@ -83,7 +83,7 @@ function nodeinfo_init(App $a) {
|
|||
if (plugin_enabled('dwpost')) {
|
||||
$nodeinfo['services']['outbound'][] = 'dreamwidth';
|
||||
}
|
||||
if (plugin_enabled('fbpost') OR plugin_enabled('buffer')) {
|
||||
if (plugin_enabled('fbpost') || plugin_enabled('buffer')) {
|
||||
$nodeinfo['services']['outbound'][] = 'facebook';
|
||||
}
|
||||
if (plugin_enabled('statusnet')) {
|
||||
|
@ -91,7 +91,7 @@ function nodeinfo_init(App $a) {
|
|||
$nodeinfo['services']['outbound'][] = 'gnusocial';
|
||||
}
|
||||
|
||||
if (plugin_enabled('gpluspost') OR plugin_enabled('buffer')) {
|
||||
if (plugin_enabled('gpluspost') || plugin_enabled('buffer')) {
|
||||
$nodeinfo['services']['outbound'][] = 'google';
|
||||
}
|
||||
if (plugin_enabled('ijpost')) {
|
||||
|
@ -123,7 +123,7 @@ function nodeinfo_init(App $a) {
|
|||
if (plugin_enabled('tumblr')) {
|
||||
$nodeinfo['services']['outbound'][] = 'tumblr';
|
||||
}
|
||||
if (plugin_enabled('twitter') OR plugin_enabled('buffer')) {
|
||||
if (plugin_enabled('twitter') || plugin_enabled('buffer')) {
|
||||
$nodeinfo['services']['outbound'][] = 'twitter';
|
||||
}
|
||||
if (plugin_enabled('wppost')) {
|
||||
|
@ -203,11 +203,11 @@ function nodeinfo_cron() {
|
|||
$month = time() - (30 * 24 * 60 * 60);
|
||||
|
||||
foreach ($users AS $user) {
|
||||
if ((strtotime($user['login_date']) > $halfyear) OR
|
||||
if ((strtotime($user['login_date']) > $halfyear) ||
|
||||
(strtotime($user['last-item']) > $halfyear)) {
|
||||
++$active_users_halfyear;
|
||||
}
|
||||
if ((strtotime($user['login_date']) > $month) OR
|
||||
if ((strtotime($user['login_date']) > $month) ||
|
||||
(strtotime($user['last-item']) > $month)) {
|
||||
++$active_users_monthly;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ function noscrape_init(App $a) {
|
|||
|
||||
profile_load($a,$which,$profile);
|
||||
|
||||
if (!$a->profile['net-publish'] OR $a->profile['hidewall']) {
|
||||
if (!$a->profile['net-publish'] || $a->profile['hidewall']) {
|
||||
header('Content-type: application/json; charset=utf-8');
|
||||
$json_info = array("hide" => true);
|
||||
echo json_encode($json_info);
|
||||
|
@ -42,7 +42,7 @@ function noscrape_init(App $a) {
|
|||
'tags' => $keywords
|
||||
);
|
||||
|
||||
if (is_array($a->profile) AND !$a->profile['hide-friends']) {
|
||||
if (is_array($a->profile) && !$a->profile['hide-friends']) {
|
||||
$r = q("SELECT `gcontact`.`updated` FROM `contact` INNER JOIN `gcontact` WHERE `gcontact`.`nurl` = `contact`.`nurl` AND `self` AND `uid` = %d LIMIT 1",
|
||||
intval($a->profile['uid']));
|
||||
if (dbm::is_result($r)) {
|
||||
|
|
|
@ -119,7 +119,7 @@ function photo_init(App $a) {
|
|||
intval($resolution)
|
||||
);
|
||||
|
||||
$public = (dbm::is_result($r)) AND ($r[0]['allow_cid'] == '') AND ($r[0]['allow_gid'] == '') AND ($r[0]['deny_cid'] == '') AND ($r[0]['deny_gid'] == '');
|
||||
$public = (dbm::is_result($r)) && ($r[0]['allow_cid'] == '') && ($r[0]['allow_gid'] == '') && ($r[0]['deny_cid'] == '') && ($r[0]['deny_gid'] == '');
|
||||
|
||||
if (dbm::is_result($r)) {
|
||||
$resolution = $r[0]['scale'];
|
||||
|
|
12
mod/ping.php
12
mod/ping.php
|
@ -330,10 +330,10 @@ function ping_init(App $a)
|
|||
|
||||
if (dbm::is_result($notifs)) {
|
||||
// Are the nofications called from the regular process or via the friendica app?
|
||||
$regularnotifications = (intval($_GET['uid']) AND intval($_GET['_']));
|
||||
$regularnotifications = (intval($_GET['uid']) && intval($_GET['_']));
|
||||
|
||||
foreach ($notifs as $notif) {
|
||||
if ($a->is_friendica_app() OR !$regularnotifications) {
|
||||
if ($a->is_friendica_app() || !$regularnotifications) {
|
||||
$notif['message'] = str_replace("{0}", $notif['name'], $notif['message']);
|
||||
}
|
||||
|
||||
|
@ -434,7 +434,7 @@ function ping_get_notifications($uid)
|
|||
intval($offset)
|
||||
);
|
||||
|
||||
if (!$r AND !$seen) {
|
||||
if (!$r && !$seen) {
|
||||
$seen = true;
|
||||
$seensql = "";
|
||||
$order = "DESC";
|
||||
|
@ -474,12 +474,12 @@ function ping_get_notifications($uid)
|
|||
|
||||
$notification["href"] = App::get_baseurl() . "/notify/view/" . $notification["id"];
|
||||
|
||||
if ($notification["visible"] AND !$notification["spam"] AND
|
||||
!$notification["deleted"] AND !is_array($result[$notification["parent"]])) {
|
||||
if ($notification["visible"] && !$notification["spam"] &&
|
||||
!$notification["deleted"] && !is_array($result[$notification["parent"]])) {
|
||||
$result[$notification["parent"]] = $notification;
|
||||
}
|
||||
}
|
||||
} while ((count($result) < 50) AND !$quit);
|
||||
} while ((count($result) < 50) && !$quit);
|
||||
|
||||
return($result);
|
||||
}
|
||||
|
|
16
mod/poco.php
16
mod/poco.php
|
@ -55,7 +55,7 @@ function poco_init(App $a) {
|
|||
$cid = intval($a->argv[4]);
|
||||
}
|
||||
|
||||
if (! $system_mode AND ! $global) {
|
||||
if (! $system_mode && ! $global) {
|
||||
$users = q("SELECT `user`.*,`profile`.`hide-friends` from user left join profile on `user`.`uid` = `profile`.`uid`
|
||||
where `user`.`nickname` = '%s' and `profile`.`is-default` = 1 limit 1",
|
||||
dbesc($user)
|
||||
|
@ -157,7 +157,7 @@ function poco_init(App $a) {
|
|||
if (x($_GET, 'filtered')) {
|
||||
$ret['filtered'] = false;
|
||||
}
|
||||
if (x($_GET, 'updatedSince') AND ! $global) {
|
||||
if (x($_GET, 'updatedSince') && ! $global) {
|
||||
$ret['updatedSince'] = false;
|
||||
}
|
||||
$ret['startIndex'] = (int) $startIndex;
|
||||
|
@ -207,21 +207,21 @@ function poco_init(App $a) {
|
|||
}
|
||||
}
|
||||
|
||||
if (($contact['about'] == "") AND isset($contact['pabout'])) {
|
||||
if (($contact['about'] == "") && isset($contact['pabout'])) {
|
||||
$contact['about'] = $contact['pabout'];
|
||||
}
|
||||
if ($contact['location'] == "") {
|
||||
if (isset($contact['plocation'])) {
|
||||
$contact['location'] = $contact['plocation'];
|
||||
}
|
||||
if (isset($contact['pregion']) AND ( $contact['pregion'] != "")) {
|
||||
if (isset($contact['pregion']) && ( $contact['pregion'] != "")) {
|
||||
if ($contact['location'] != "") {
|
||||
$contact['location'] .= ", ";
|
||||
}
|
||||
$contact['location'] .= $contact['pregion'];
|
||||
}
|
||||
|
||||
if (isset($contact['pcountry']) AND ( $contact['pcountry'] != "")) {
|
||||
if (isset($contact['pcountry']) && ( $contact['pcountry'] != "")) {
|
||||
if ($contact['location'] != "") {
|
||||
$contact['location'] .= ", ";
|
||||
}
|
||||
|
@ -229,10 +229,10 @@ function poco_init(App $a) {
|
|||
}
|
||||
}
|
||||
|
||||
if (($contact['gender'] == "") AND isset($contact['pgender'])) {
|
||||
if (($contact['gender'] == "") && isset($contact['pgender'])) {
|
||||
$contact['gender'] = $contact['pgender'];
|
||||
}
|
||||
if (($contact['keywords'] == "") AND isset($contact['pub_keywords'])) {
|
||||
if (($contact['keywords'] == "") && isset($contact['pub_keywords'])) {
|
||||
$contact['keywords'] = $contact['pub_keywords'];
|
||||
}
|
||||
if (isset($contact['account-type'])) {
|
||||
|
@ -306,7 +306,7 @@ function poco_init(App $a) {
|
|||
if ($entry['network'] == NETWORK_STATUSNET) {
|
||||
$entry['network'] = NETWORK_OSTATUS;
|
||||
}
|
||||
if (($entry['network'] == "") AND ($contact['self'])) {
|
||||
if (($entry['network'] == "") && ($contact['self'])) {
|
||||
$entry['network'] = NETWORK_DFRN;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,15 +48,15 @@ function proxy_init(App $a) {
|
|||
$basepath = $a->get_basepath();
|
||||
|
||||
// If the cache path isn't there, try to create it
|
||||
if (!is_dir($basepath . '/proxy') AND is_writable($basepath)) {
|
||||
if (!is_dir($basepath . '/proxy') && is_writable($basepath)) {
|
||||
mkdir($basepath . '/proxy');
|
||||
}
|
||||
|
||||
// Checking if caching into a folder in the webroot is activated and working
|
||||
$direct_cache = (is_dir($basepath . '/proxy') AND is_writable($basepath . '/proxy'));
|
||||
$direct_cache = (is_dir($basepath . '/proxy') && is_writable($basepath . '/proxy'));
|
||||
|
||||
// Look for filename in the arguments
|
||||
if ((isset($a->argv[1]) OR isset($a->argv[2]) OR isset($a->argv[3])) AND !isset($_REQUEST['url'])) {
|
||||
if ((isset($a->argv[1]) || isset($a->argv[2]) || isset($a->argv[3])) && !isset($_REQUEST['url'])) {
|
||||
if (isset($a->argv[3])) {
|
||||
$url = $a->argv[3];
|
||||
} elseif (isset($a->argv[2])) {
|
||||
|
@ -65,7 +65,7 @@ function proxy_init(App $a) {
|
|||
$url = $a->argv[1];
|
||||
}
|
||||
|
||||
if (isset($a->argv[3]) AND ($a->argv[3] == 'thumb')) {
|
||||
if (isset($a->argv[3]) && ($a->argv[3] == 'thumb')) {
|
||||
$size = 200;
|
||||
}
|
||||
|
||||
|
@ -112,7 +112,7 @@ function proxy_init(App $a) {
|
|||
$urlhash = 'pic:' . sha1($_REQUEST['url']);
|
||||
|
||||
$cachefile = get_cachefile(hash('md5', $_REQUEST['url']));
|
||||
if ($cachefile != '' AND file_exists($cachefile)) {
|
||||
if ($cachefile != '' && file_exists($cachefile)) {
|
||||
$img_str = file_get_contents($cachefile);
|
||||
$mime = image_type_to_mime_type(exif_imagetype($cachefile));
|
||||
|
||||
|
@ -140,7 +140,7 @@ function proxy_init(App $a) {
|
|||
$valid = true;
|
||||
$r = array();
|
||||
|
||||
if (!$direct_cache AND ($cachefile == '')) {
|
||||
if (!$direct_cache && ($cachefile == '')) {
|
||||
$r = qu("SELECT * FROM `photo` WHERE `resource-id` = '%s' LIMIT 1", $urlhash);
|
||||
if (dbm::is_result($r)) {
|
||||
$img_str = $r[0]['data'];
|
||||
|
@ -163,7 +163,7 @@ function proxy_init(App $a) {
|
|||
unlink($tempfile);
|
||||
|
||||
// If there is an error then return a blank image
|
||||
if ((substr($a->get_curl_code(), 0, 1) == '4') OR (!$img_str)) {
|
||||
if ((substr($a->get_curl_code(), 0, 1) == '4') || (!$img_str)) {
|
||||
$img_str = file_get_contents('images/blank.png');
|
||||
$mime = 'image/png';
|
||||
$cachefile = ''; // Clear the cachefile so that the dummy isn't stored
|
||||
|
@ -173,7 +173,7 @@ function proxy_init(App $a) {
|
|||
$img->scaleImage(10);
|
||||
$img_str = $img->imageString();
|
||||
}
|
||||
} elseif ($mime != 'image/jpeg' AND !$direct_cache AND $cachefile == '') {
|
||||
} elseif ($mime != 'image/jpeg' && !$direct_cache && $cachefile == '') {
|
||||
$image = @imagecreatefromstring($img_str);
|
||||
|
||||
if ($image === FALSE) {
|
||||
|
@ -199,7 +199,7 @@ function proxy_init(App $a) {
|
|||
|
||||
} else {
|
||||
$img = new Photo($img_str, $mime);
|
||||
if ($img->is_valid() AND !$direct_cache AND ($cachefile == '')) {
|
||||
if ($img->is_valid() && !$direct_cache && ($cachefile == '')) {
|
||||
$img->store(0, 0, $urlhash, $_REQUEST['url'], '', 100);
|
||||
}
|
||||
}
|
||||
|
@ -219,7 +219,7 @@ function proxy_init(App $a) {
|
|||
// If there is a real existing directory then put the cache file there
|
||||
// advantage: real file access is really fast
|
||||
// Otherwise write in cachefile
|
||||
if ($valid AND $direct_cache) {
|
||||
if ($valid && $direct_cache) {
|
||||
file_put_contents($basepath . '/proxy/' . proxy_url($_REQUEST['url'], true), $img_str_orig);
|
||||
if ($sizetype != '') {
|
||||
file_put_contents($basepath . '/proxy/' . proxy_url($_REQUEST['url'], true) . $sizetype, $img_str);
|
||||
|
@ -282,7 +282,7 @@ function proxy_url($url, $writemode = false, $size = '') {
|
|||
$shortpath = hash('md5', $url);
|
||||
$longpath = substr($shortpath, 0, 2);
|
||||
|
||||
if (is_dir($basepath) AND $writemode AND !is_dir($basepath . '/' . $longpath)) {
|
||||
if (is_dir($basepath) && $writemode && !is_dir($basepath . '/' . $longpath)) {
|
||||
mkdir($basepath . '/' . $longpath);
|
||||
chmod($basepath . '/' . $longpath, 0777);
|
||||
}
|
||||
|
@ -306,7 +306,7 @@ function proxy_url($url, $writemode = false, $size = '') {
|
|||
|
||||
// Too long files aren't supported by Apache
|
||||
// Writemode in combination with long files shouldn't be possible
|
||||
if ((strlen($proxypath) > 250) AND $writemode) {
|
||||
if ((strlen($proxypath) > 250) && $writemode) {
|
||||
return $shortpath;
|
||||
} elseif (strlen($proxypath) > 250) {
|
||||
return App::get_baseurl() . '/proxy/' . $shortpath . '?url=' . urlencode($url);
|
||||
|
@ -360,7 +360,7 @@ function proxy_parse_query($url) {
|
|||
function proxy_img_cb($matches) {
|
||||
// if the picture seems to be from another picture cache then take the original source
|
||||
$queryvar = proxy_parse_query($matches[2]);
|
||||
if (($queryvar['url'] != '') AND (substr($queryvar['url'], 0, 4) == 'http')) {
|
||||
if (($queryvar['url'] != '') && (substr($queryvar['url'], 0, 4) == 'http')) {
|
||||
$matches[2] = urldecode($queryvar['url']);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ require_once('include/user.php');
|
|||
|
||||
if(! function_exists('register_post')) {
|
||||
function register_post(App $a) {
|
||||
check_form_security_token_redirectOnErr('/register', 'register');
|
||||
|
||||
global $lang;
|
||||
|
||||
|
@ -83,7 +84,7 @@ function register_post(App $a) {
|
|||
}
|
||||
|
||||
// Only send a password mail when the password wasn't manually provided
|
||||
if (!x($_POST,'password1') OR !x($_POST,'confirm')) {
|
||||
if (!x($_POST,'password1') || !x($_POST,'confirm')) {
|
||||
$res = send_register_open_eml(
|
||||
$user['email'],
|
||||
$a->config['sitename'],
|
||||
|
@ -296,7 +297,7 @@ function register_content(App $a) {
|
|||
'$sitename' => $a->get_hostname(),
|
||||
'$importh' => t('Import'),
|
||||
'$importt' => t('Import your profile to this friendica instance'),
|
||||
|
||||
'$form_security_token' => get_form_security_token("register")
|
||||
));
|
||||
return $o;
|
||||
|
||||
|
|
|
@ -92,12 +92,12 @@ function search_post(App $a) {
|
|||
|
||||
function search_content(App $a) {
|
||||
|
||||
if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
|
||||
notice( t('Public access denied.') . EOL);
|
||||
if (get_config('system','block_public') && !local_user() && !remote_user()) {
|
||||
notice(t('Public access denied.') . EOL);
|
||||
return;
|
||||
}
|
||||
|
||||
if(get_config('system','local_search') AND !local_user()) {
|
||||
if (get_config('system','local_search') && !local_user() && !remote_user()) {
|
||||
http_status_exit(403,
|
||||
array("title" => t("Public access denied."),
|
||||
"description" => t("Only logged in users are permitted to perform a search.")));
|
||||
|
@ -106,7 +106,7 @@ function search_content(App $a) {
|
|||
//return;
|
||||
}
|
||||
|
||||
if (get_config('system','permit_crawling') AND !local_user()) {
|
||||
if (get_config('system','permit_crawling') && !local_user() && !remote_user()) {
|
||||
// Default values:
|
||||
// 10 requests are "free", after the 11th only a call per minute is allowed
|
||||
|
||||
|
@ -122,7 +122,7 @@ function search_content(App $a) {
|
|||
$result = Cache::get("remote_search:".$remote);
|
||||
if (!is_null($result)) {
|
||||
$resultdata = json_decode($result);
|
||||
if (($resultdata->time > (time() - $crawl_permit_period)) AND ($resultdata->accesses > $free_crawls)) {
|
||||
if (($resultdata->time > (time() - $crawl_permit_period)) && ($resultdata->accesses > $free_crawls)) {
|
||||
http_status_exit(429,
|
||||
array("title" => t("Too Many Requests"),
|
||||
"description" => t("Only one search per minute is permitted for not logged in users.")));
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue