1
0
Fork 0

Merge branch 'develop' of github.com:friendica/friendica into rewrites/coding-convention-split2-4-2

Fixed some stuff:
- converted some files from DOS to Uni* (CRLF -> LF)
- removed trailing white-spaces

Signed-off-by: Roland Häder <roland@mxchange.org>
This commit is contained in:
Roland Häder 2017-05-11 14:54:26 +02:00
commit 7a9456d5ac
No known key found for this signature in database
GPG key ID: B72F8185C6C7BD78
350 changed files with 19367 additions and 16093 deletions

1194
boot.php

File diff suppressed because it is too large Load diff

6
composer.lock generated
View file

@ -226,10 +226,10 @@
},
{
"name": "pear-pear.php.net/PEAR",
"version": "1.10.3",
"version": "1.10.4",
"dist": {
"type": "file",
"url": "https://pear.php.net/get/PEAR-1.10.3.tgz",
"url": "https://pear.php.net/get/PEAR-1.10.4.tgz",
"reference": null,
"shasum": null
},
@ -247,7 +247,7 @@
"pear-pear.php.net/pear_frontend_web": "<=0.4.0.0"
},
"replace": {
"pear-pear/pear": "== 1.10.3.0"
"pear-pear/pear": "== 1.10.4.0"
},
"type": "pear-library",
"autoload": {

View file

@ -1,6 +1,6 @@
-- ------------------------------------------
-- Friendica 3.5.2-dev (Asparagus)
-- DB_UPDATE_VERSION 1219
-- DB_UPDATE_VERSION 1221
-- ------------------------------------------
@ -174,13 +174,13 @@ CREATE TABLE IF NOT EXISTS `contact` (
`fetch_further_information` tinyint(1) NOT NULL DEFAULT 0,
`ffi_keyword_blacklist` text,
PRIMARY KEY(`id`),
INDEX `uid_name` (`uid`,`name`),
INDEX `uid_name` (`uid`,`name`(190)),
INDEX `self_uid` (`self`,`uid`),
INDEX `alias_uid` (`alias`(32),`uid`),
INDEX `pending_uid` (`pending`,`uid`),
INDEX `blocked_uid` (`blocked`,`uid`),
INDEX `uid_rel_network_poll` (`uid`,`rel`,`network`,`poll`(64),`archive`),
INDEX `uid_network_batch` (`uid`,`network`,`batch`(64)),
INDEX `uid_rel_network_poll` (`uid`,`rel`,`network`(4),`poll`(64),`archive`),
INDEX `uid_network_batch` (`uid`,`network`(4),`batch`(64)),
INDEX `addr_uid` (`addr`(32),`uid`),
INDEX `nurl_uid` (`nurl`(32),`uid`),
INDEX `nick_uid` (`nick`(32),`uid`),
@ -204,6 +204,21 @@ CREATE TABLE IF NOT EXISTS `conv` (
INDEX `uid` (`uid`)
) DEFAULT COLLATE utf8mb4_general_ci;
--
-- TABLE conversation
--
CREATE TABLE IF NOT EXISTS `conversation` (
`item-uri` varbinary(255) NOT NULL,
`reply-to-uri` varbinary(255) NOT NULL DEFAULT '',
`conversation-uri` varbinary(255) NOT NULL DEFAULT '',
`conversation-href` varbinary(255) NOT NULL DEFAULT '',
`protocol` tinyint(1) unsigned NOT NULL DEFAULT 0,
`source` mediumtext,
`received` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
PRIMARY KEY(`item-uri`),
INDEX `conversation-uri` (`conversation-uri`)
) DEFAULT COLLATE utf8mb4_general_ci;
--
-- TABLE event
--
@ -344,7 +359,7 @@ CREATE TABLE IF NOT EXISTS `gcontact` (
INDEX `name` (`name`(64)),
INDEX `nick` (`nick`(32)),
INDEX `addr` (`addr`(64)),
INDEX `hide_network_updated` (`hide`,`network`,`updated`),
INDEX `hide_network_updated` (`hide`,`network`(4),`updated`),
INDEX `updated` (`updated`)
) DEFAULT COLLATE utf8mb4_general_ci;
@ -523,22 +538,22 @@ CREATE TABLE IF NOT EXISTS `item` (
INDEX `uid_contactid_id` (`uid`,`contact-id`,`id`),
INDEX `uid_created` (`uid`,`created`),
INDEX `uid_unseen_contactid` (`uid`,`unseen`,`contact-id`),
INDEX `uid_network_received` (`uid`,`network`,`received`),
INDEX `uid_network_commented` (`uid`,`network`,`commented`),
INDEX `uid_thrparent` (`uid`,`thr-parent`),
INDEX `uid_parenturi` (`uid`,`parent-uri`),
INDEX `uid_network_received` (`uid`,`network`(4),`received`),
INDEX `uid_network_commented` (`uid`,`network`(4),`commented`),
INDEX `uid_thrparent` (`uid`,`thr-parent`(190)),
INDEX `uid_parenturi` (`uid`,`parent-uri`(190)),
INDEX `uid_contactid_created` (`uid`,`contact-id`,`created`),
INDEX `authorid_created` (`author-id`,`created`),
INDEX `uid_uri` (`uid`,`uri`),
INDEX `uid_uri` (`uid`,`uri`(190)),
INDEX `resource-id` (`resource-id`),
INDEX `contactid_allowcid_allowpid_denycid_denygid` (`contact-id`,`allow_cid`(10),`allow_gid`(10),`deny_cid`(10),`deny_gid`(10)),
INDEX `uid_type_changed` (`uid`,`type`,`changed`),
INDEX `contactid_verb` (`contact-id`,`verb`),
INDEX `uid_type_changed` (`uid`,`type`(190),`changed`),
INDEX `contactid_verb` (`contact-id`,`verb`(190)),
INDEX `deleted_changed` (`deleted`,`changed`),
INDEX `uid_wall_changed` (`uid`,`wall`,`changed`),
INDEX `uid_eventid` (`uid`,`event-id`),
INDEX `uid_authorlink` (`uid`,`author-link`),
INDEX `uid_ownerlink` (`uid`,`owner-link`)
INDEX `uid_authorlink` (`uid`,`author-link`(190)),
INDEX `uid_ownerlink` (`uid`,`owner-link`(190))
) DEFAULT COLLATE utf8mb4_general_ci;
--
@ -652,7 +667,7 @@ CREATE TABLE IF NOT EXISTS `notify` (
INDEX `hash_uid` (`hash`,`uid`),
INDEX `seen_uid_date` (`seen`,`uid`,`date`),
INDEX `uid_date` (`uid`,`date`),
INDEX `uid_type_link` (`uid`,`type`,`link`)
INDEX `uid_type_link` (`uid`,`type`,`link`(190))
) DEFAULT COLLATE utf8mb4_general_ci;
--
@ -963,7 +978,7 @@ CREATE TABLE IF NOT EXISTS `term` (
`aid` int(10) unsigned NOT NULL DEFAULT 0,
`uid` int(10) unsigned NOT NULL DEFAULT 0,
PRIMARY KEY(`tid`),
INDEX `oid_otype_type_term` (`oid`,`otype`,`type`,`term`),
INDEX `oid_otype_type_term` (`oid`,`otype`,`type`,`term`(32)),
INDEX `uid_otype_type_term_global_created` (`uid`,`otype`,`type`,`term`(32),`global`,`created`),
INDEX `uid_otype_type_url` (`uid`,`otype`,`type`,`url`(64)),
INDEX `guid` (`guid`(64))

View file

@ -113,3 +113,8 @@ For Composer, this would be:
````
$> COMPOSER_HOME=/var/tmp/composer sudo -u [web user] util/composer.phar [mode]
````
## Related
* [Class autoloading](help/autoloader)
* [How To Move Classes to `src`](help/Developer-How-To-Move-Classes-to-src)

View file

@ -0,0 +1,108 @@
How To Move Classes to `src`
==============
* [Home](help)
* [Developer Intro](help/Developers-Intro)
Friendica uses [Composer](help/Composer) to manage autoloading.
This means that all the PHP class files moved to the `src` folder will be [automatically included](help/autoloader) when the class it defines is first used in the flow.
This is an improvement over the current `require` usage since files will be included on an actual usage basis instead of the presence of a `require` call.
However, there are a significant number of items to check when moving a class file from the `include` folder to the `src` folder, and this page is there to list them.
## Decide the namespace
This isn't the most technical decision of them all, but it has long lasting consequences as it will be the name that will be used to refer to this class from now on.
There is [a shared Ethercalc sheet](https://ethercalc.org/friendica_classes) to suggest namespace/class names that lists all the already moved class files for inspiration.
A few pointers though:
* `Friendica` is the base namespace for all classes in the `src` folder
* Namespaces match the directory structure, with `Friendica` namespace being the base `src` directory. The `Config` class set in the `Friendica\Core` namespace is expected to be found at `src/Core/Config.php`.
* Namespaces can help group classes with a similar purpose or relevant to a particular feature
When you're done deciding the namespace, it's time to use it.
Let's say we choose `Friendica\Core` for the `Config` class.
## Use the namespace
To declare the namespace, the file `src/Core/Config.php` must start with the following statement:
````php
namespace Friendica\Core;
````
From now on, the `Config` class can be referred to as `Friendica\Core\Config`, however it isn't very practical, especially when the class was previously used as `Config`.
Thankfully, PHP provides namespace shortcuts through `use`.
This language construct just provides a different naming scheme for a namespace or a class, but doesn't trigger the autoload mechanism on its own.
Here are the different ways you can use `use`:
````php
// No use
$config = new Friendica\Core\Config();
````
````php
// Namespace shortcut
use Friendica\Core;
$config = new Core\Config();
````
````php
// Class name shortcut
use Friendica\Core\Config;
$config = new Config();
````
````php
// Aliasing
use Friendica\Core\Config as Cfg;
$config = new Cfg();
````
Whatever the style chosen, a repository-wide search has to be done to find all the class name usage and either use the fully-qualified class name (including the namespace) or add a `use` statement at the start of each relevant file.
## Escape non-namespace classes
The class file you just moved is now in the `Friendica` namespace, but it probably isn't the case for all the classes referenced in this file.
Since we added a `namespace Friendica\Core;` to the file, all the class names still declared in `include` will be implicitly understood as `Friendica\Core\ClassName`, which is rarely what we expect.
To avoid `Class Friendica\Core\ClassName not found` errors, all the `include`-declared class names have to be prepended with a `\`, it tells the autoloader not to look for the class in the namespace but in the global space where non-namespaced classes are set.
If there are only a handful of references to a single non-namespaced class, just prepending `\` is enough. However, if there are many instance, we can use `use` again.
````php
namespace Friendica\Core;
...
if (\dbm::is_result($r)) {
...
}
````
````php
namespace Friendica\Core;
use \dbm;
if (dbm::is_result($r)) {
...
}
````
## Remove any useless `require`
Now that you successfully moved your class to the autoloaded `src` folder, there's no need to include this file anywhere in the app ever again.
Please remove all the `require_once` mentions of the former file, as they will provoke a Fatal Error even if the class isn't used.
## Miscellaneous tips
When you are done with moving the class, please run `php util/typo.php` from the Friendica base directory to check for obvious mistakes.
Howevever, this tool isn't bullet-proof, and a staging install of Friendica is recommended to test your class move without impairing your production server if you host one.
Most of Friendica processes are run in the background, so make sure to turn on your debug log to check for errors that wouldn't show up while simply browsing Friendica.
Check the class file for any magic constant `__FILE__` or `__DIR__`, as their value changed since you moved the class in the file tree.
Most of the time it's used for debugging purposes but there can be instances where it's used to create cache folders for example.
## Related
* [Class autoloading](help/autoloader)
* [Using Composer](help/Composer)

View file

@ -52,7 +52,9 @@ Friendica uses [Composer](https://getcomposer.org) to manage dependencies librar
It's a command-line tool that downloads required libraries into the `vendor` folder and makes any namespaced class in `src` available through the whole application through `boot.php`.
* [Class autoloading](help/autoloader)
* [Using Composer](help/Composer)
* [How To Move Classes to `src`](help/Developer-How-To-Move-Classes-to-src)
###Coding standards

View file

@ -36,21 +36,25 @@ Friendica Documentation and Resources
**Developer Manual**
* [Where to get started?](help/Developers-Intro)
* [Help on Github](help/Github)
* [Help on Vagrant](help/Vagrant)
* [How to translate Friendica](help/translations)
* [Bugs and Issues](help/Bugs-and-Issues)
* [Plugin Development](help/Plugins)
* [Theme Development](help/themes)
* [Smarty 3 Templates](help/smarty3-templates)
* [Protocol Documentation](help/Protocol)
* [Database schema documantation](help/database)
* [Class Autoloading](help/autoloader)
* [Using Composer](help/Composer)
* [Code - Reference(Doxygen generated - sets cookies)](doc/html/)
* [Twitter/GNU Social API Functions](help/api)
* [Get started](help/Developers-Intro)
* Set up development environment
* [Help on Github](help/Github)
* [Help on Vagrant](help/Vagrant)
* [Bugs and Issues](help/Bugs-and-Issues)
* Code structure
* [Plugin Development](help/Plugins)
* [Theme Development](help/themes)
* [Smarty 3 Templates](help/smarty3-templates)
* How To
* [Translate Friendica](help/translations)
* [Use Composer](help/Composer)
* [Move classes to `src`](help/Developer-How-To-Move-Classes-to-src)
* Reference
* [Twitter/GNU Social API Functions](help/api)
* [Code (Doxygen generated - sets cookies)](doc/html/)
* [Protocol Documentation](help/Protocol)
* [Database schema documantation](help/database)
* [Class Autoloading](help/autoloader)
**External Resources**

View file

@ -28,7 +28,7 @@ Requirements
* Apache with mod-rewrite enabled and "Options All" so you can use a local .htaccess file
* PHP 5.4+.
* PHP *command line* access with register_argc_argv set to true in the php.ini file
* curl, gd, mysql, hash and openssl extensions
* Curl, GD, PDO, MySQLi, hash and OpenSSL extensions
* some form of email server or email gateway such that PHP mail() works
* Mysql 5.5.3+ or an equivalant alternative for MySQL (MariaDB, Percona Server etc.)
* the ability to schedule jobs with cron (Linux/Mac) or Scheduled Tasks (Windows) (Note: other options are presented in Section 7 of this document.)

View file

@ -242,6 +242,12 @@ The receiving end might be off-line, there might be a high system load and so on
Don't panic!
Friendica will not queue messages for all time but will sort out *dead* nodes automatically after a while and remove messages from the queue then.
## Server Blocklist
This page allows to block all communications (inbound and outbound) with a specific domain name.
Each blocked domain entry requires a reason that will be displayed on the [friendica](/friendica) page.
Matching is exact, blocking a domain doesn't block subdomains.
## Federation Statistics
The federation statistics page gives you a short summery of the nodes/servers/pods of the decentralized social network federation your node knows.

1889
doc/api.md

File diff suppressed because it is too large Load diff

View file

@ -1,192 +1,197 @@
Autoloader with Composer
==========
* [Home](help)
* [Developer Intro](help/Developers-Intro)
Friendica uses [Composer](https://getcomposer.org) to manage dependencies libraries and the class autoloader both for libraries and namespaced Friendica classes.
It's a command-line tool that downloads required libraries into the `vendor` folder and makes any namespaced class in `src` available through the whole application through `boot.php`.
* [Using Composer](help/Composer)
## A quick introduction to class autoloading
The autoloader dynamically includes the file defining a class when it is first referenced, either by instantiating an object or simply making sure that it is available, without the need to explicitly use "require_once".
Once it is set up you don't have to directly use it, you can directly use any class that is covered by the autoloader (currently `vendor` and `src`)
Under the hood, Composer registers a callback with [`spl_autoload_register()`](http://php.net/manual/en/function.spl-autoload-register.php) that receives a class name as an argument and includes the corresponding class definition file.
For more info about PHP autoloading, please refer to the [official PHP documentation](http://php.net/manual/en/language.oop5.autoload.php).
### Example
Let's say you have a PHP file in `src/` that define a very useful class:
```php
// src/ItemsManager.php
<?php
namespace \Friendica;
class ItemsManager {
public function getAll() { ... }
public function getByID($id) { ... }
}
```
The class `ItemsManager` has been declared in the `Friendica` namespace.
Namespaces are useful to keep classes separated and avoid names conflicts (could be that a library you want to use also defines a class named `ItemsManager`, but as long as it is in another namespace, you don't have any problem)
Let's say now that you need to load some items in a view, maybe in a fictional `mod/network.php`.
In order for the Composer autoloader to work, it must first be included. In Friendica this is already done at the top of `boot.php`, with `require_once('vendor/autoload.php');`.
The code will be something like:
```php
// mod/network.php
<?php
function network_content(App $a) {
$itemsmanager = new \Friendica\ItemsManager();
$items = $itemsmanager->getAll();
// pass $items to template
// return result
}
```
That's a quite simple example, but look: no `require()`!
If you need to use a class, you can simply use it and you don't need to do anything else.
Going further: now we have a bunch of `*Manager` classes that cause some code duplication, let's define a `BaseManager` class, where we move all common code between all managers:
```php
// src/BaseManager.php
<?php
namespace \Friendica;
class BaseManager {
public function thatFunctionEveryManagerUses() { ... }
}
```
and then let's change the ItemsManager class to use this code
```php
// src/ItemsManager.php
<?php
namespace \Friendica;
class ItemsManager extends BaseManager {
public function getAll() { ... }
public function getByID($id) { ... }
}
```
Even though we didn't explicitly include the `src/BaseManager.php` file, the autoloader will when this class is first defined, because it is referenced as a parent class.
It works with the "BaseManager" example here and it works when we need to call static methods:
```php
// src/Dfrn.php
<?php
namespace \Friendica;
class Dfrn {
public static function mail($item, $owner) { ... }
}
```
```php
// mod/mail.php
<?php
mail_post($a){
...
\Friendica\dfrn::mail($item, $owner);
...
}
```
If your code is in same namespace as the class you need, you don't need to prepend it:
```php
// include/delivery.php
<?php
namespace \Friendica;
// this is the same content of current include/delivery.php,
// but has been declared to be in "Friendica" namespace
[...]
switch($contact['network']) {
case NETWORK_DFRN:
if ($mail) {
$item['body'] = ...
$atom = Dfrn::mail($item, $owner);
} elseif ($fsuggest) {
$atom = Dfrn::fsuggest($item, $owner);
q("DELETE FROM `fsuggest` WHERE `id` = %d LIMIT 1", intval($item['id']));
} elseif ($relocate)
$atom = Dfrn::relocate($owner, $uid);
[...]
```
This is the current code of `include/delivery.php`, and since the code is declared to be in the "Friendica" namespace, you don't need to write it when you need to use the "Dfrn" class.
But if you want to use classes from another library, you need to use the full namespace, e.g.
```php
// src/Diaspora.php
<?php
namespace \Friendica;
class Diaspora {
public function md2bbcode() {
$html = \Michelf\MarkdownExtra::defaultTransform($text);
}
}
```
if you use that class in many places of the code and you don't want to write the full path to the class every time, you can use the "use" PHP keyword
```php
// src/Diaspora.php
<?php
namespace \Friendica;
use \Michelf\MarkdownExtra;
class Diaspora {
public function md2bbcode() {
$html = MarkdownExtra::defaultTransform($text);
}
}
```
Note that namespaces are like paths in filesystem, separated by "\", with the first "\" being the global scope.
You can go deeper if you want to, like:
```
// src/Network/Dfrn.php
<?php
namespace \Friendica\Network;
class Dfrn {
}
```
Please note that the location of the file defining the class must be placed in the appropriate sub-folders of `src` if the namespace isn't plain `\Friendica`.
or
```
// src/Dba/Mysql
<?php
namespace \Friendica\Dba;
class Mysql {
}
```
So you can think of namespaces as folders in a Unix file system, with global scope as the root ("\").
Autoloader with Composer
==========
* [Home](help)
* [Developer Intro](help/Developers-Intro)
Friendica uses [Composer](https://getcomposer.org) to manage dependencies libraries and the class autoloader both for libraries and namespaced Friendica classes.
It's a command-line tool that downloads required libraries into the `vendor` folder and makes any namespaced class in `src` available through the whole application through `boot.php`.
* [Using Composer](help/Composer)
## A quick introduction to class autoloading
The autoloader dynamically includes the file defining a class when it is first referenced, either by instantiating an object or simply making sure that it is available, without the need to explicitly use "require_once".
Once it is set up you don't have to directly use it, you can directly use any class that is covered by the autoloader (currently `vendor` and `src`)
Under the hood, Composer registers a callback with [`spl_autoload_register()`](http://php.net/manual/en/function.spl-autoload-register.php) that receives a class name as an argument and includes the corresponding class definition file.
For more info about PHP autoloading, please refer to the [official PHP documentation](http://php.net/manual/en/language.oop5.autoload.php).
### Example
Let's say you have a PHP file in `src/` that define a very useful class:
```php
// src/ItemsManager.php
<?php
namespace Friendica;
class ItemsManager {
public function getAll() { ... }
public function getByID($id) { ... }
}
```
The class `ItemsManager` has been declared in the `Friendica` namespace.
Namespaces are useful to keep classes separated and avoid names conflicts (could be that a library you want to use also defines a class named `ItemsManager`, but as long as it is in another namespace, you don't have any problem)
Let's say now that you need to load some items in a view, maybe in a fictional `mod/network.php`.
In order for the Composer autoloader to work, it must first be included. In Friendica this is already done at the top of `boot.php`, with `require_once('vendor/autoload.php');`.
The code will be something like:
```php
// mod/network.php
<?php
function network_content(App $a) {
$itemsmanager = new Friendica\ItemsManager();
$items = $itemsmanager->getAll();
// pass $items to template
// return result
}
```
That's a quite simple example, but look: no `require()`!
If you need to use a class, you can simply use it and you don't need to do anything else.
Going further: now we have a bunch of `*Manager` classes that cause some code duplication, let's define a `BaseManager` class, where we move all common code between all managers:
```php
// src/BaseManager.php
<?php
namespace Friendica;
class BaseManager {
public function thatFunctionEveryManagerUses() { ... }
}
```
and then let's change the ItemsManager class to use this code
```php
// src/ItemsManager.php
<?php
namespace Friendica;
class ItemsManager extends BaseManager {
public function getAll() { ... }
public function getByID($id) { ... }
}
```
Even though we didn't explicitly include the `src/BaseManager.php` file, the autoloader will when this class is first defined, because it is referenced as a parent class.
It works with the "BaseManager" example here and it works when we need to call static methods:
```php
// src/Dfrn.php
<?php
namespace Friendica;
class Dfrn {
public static function mail($item, $owner) { ... }
}
```
```php
// mod/mail.php
<?php
mail_post($a){
...
Friendica\dfrn::mail($item, $owner);
...
}
```
If your code is in same namespace as the class you need, you don't need to prepend it:
```php
// include/delivery.php
<?php
namespace Friendica;
// this is the same content of current include/delivery.php,
// but has been declared to be in "Friendica" namespace
[...]
switch($contact['network']) {
case NETWORK_DFRN:
if ($mail) {
$item['body'] = ...
$atom = Dfrn::mail($item, $owner);
} elseif ($fsuggest) {
$atom = Dfrn::fsuggest($item, $owner);
q("DELETE FROM `fsuggest` WHERE `id` = %d LIMIT 1", intval($item['id']));
} elseif ($relocate)
$atom = Dfrn::relocate($owner, $uid);
[...]
```
This is the current code of `include/delivery.php`, and since the code is declared to be in the "Friendica" namespace, you don't need to write it when you need to use the "Dfrn" class.
But if you want to use classes from another library, you need to use the full namespace, e.g.
```php
// src/Diaspora.php
<?php
namespace Friendica;
class Diaspora {
public function md2bbcode() {
$html = \Michelf\MarkdownExtra::defaultTransform($text);
}
}
```
if you use that class in many places of the code and you don't want to write the full path to the class every time, you can use the "use" PHP keyword
```php
// src/Diaspora.php
<?php
namespace Friendica;
use \Michelf\MarkdownExtra;
class Diaspora {
public function md2bbcode() {
$html = MarkdownExtra::defaultTransform($text);
}
}
```
Note that namespaces are like paths in filesystem, separated by "\", with the first "\" being the global scope.
You can go deeper if you want to, like:
```
// src/Network/Dfrn.php
<?php
namespace Friendica\Network;
class Dfrn {
}
```
Please note that the location of the file defining the class must be placed in the appropriate sub-folders of `src` if the namespace isn't plain `Friendica`.
or
```
// src/Dba/Mysql
<?php
namespace Friendica\Dba;
class Mysql {
}
```
So you can think of namespaces as folders in a Unix file system, with global scope as the root ("\").
## Related
* [Using Composer](help/Composer)
* [How To Move Classes to `src`](help/Developer-How-To-Move-Classes-to-src)

View file

@ -14,6 +14,7 @@ Database Tables
| [config](help/database/db_config) | main configuration storage |
| [contact](help/database/db_contact) | contact table |
| [conv](help/database/db_conv) | private messages |
| [conversation](help/database/db_conversation) | Raw data and structure information for messages |
| [event](help/database/db_event) | Events |
| [fcontact](help/database/db_fcontact) | friend suggestion stuff |
| [ffinder](help/database/db_ffinder) | friend suggestion stuff |

View file

@ -0,0 +1,14 @@
Table conversation
==================
| Field | Description | Type | Null | Key | Default | Extra |
|-------------------| ---------------------------------- |---------------------|------|-----|---------------------|----------------|
| item-uri | URI of the item | varbinary(255) | NO | PRI | NULL | |
| reply-to-uri | URI to which this item is a reply | varbinary(255) | NO | | | |
| conversation-uri | GNU Social conversation URI | varbinary(255) | NO | | | |
| conversation-href | GNU Social conversation link | varbinary(255) | NO | | | |
| protocol | The protocol of the item | tinyint(1) unsigned | NO | | 0 | |
| source | Original source | mediumtext | NO | | | |
| received | Receiving date | datetime | NO | | 0001-01-01 | |
Return to [database documentation](help/database)

View file

@ -24,7 +24,7 @@ Wir planen, diese Einschränkung in einer zukünftigen Version zu beheben.
- Apache mit einer aktiverten mod-rewrite-Funktion und dem Eintrag "Options All", so dass du die lokale .htaccess-Datei nutzen kannst
- PHP 5.2+. Je neuer, desto besser. Du benötigst 5.3 für die Authentifizierung untereinander. In einer Windows-Umgebung arbeitet die Version 5.2+ möglicherweise nicht, da die Funktion dns_get_record() erst ab Version 5.3 verfügbar ist.
- PHP *Kommandozeilen*-Zugang mit register_argc_argv auf "true" gesetzt in der php.ini-Datei
- curl, gd, mysql und openssl-Erweiterung
- Curl, GD, PDO, MySQLi und OpenSSL-Erweiterung
- etwas in der Art eines Email-Servers oder eines Gateways wie PHP mail()
- Mysql 5.x
- die Möglichkeit, wiederkehrende Aufgaben mit cron (Linux/Mac) oder "Scheduled Tasks" einzustellen (Windows) [Beachte: andere Optionen sind in Abschnitt 7 dieser Dokumentation zu finden]

View file

@ -2,7 +2,7 @@
* [Zur Startseite der Hilfe](help)
Wenn du der Administrator einer Friendica Instanz bist, hast du Zugriff auf das so genannte **Admin Panel** in dem du die Friendica Instanz konfigurieren kannst,
Wenn du der Administrator einer Friendica-Instanz bist, hast du Zugriff auf das so genannte **Admin Panel** in dem du die Friendica-Instanz konfigurieren kannst,
Auf der Startseite des Admin Panels werden die Informationen zu der Instanz zusammengefasst.
Die erste Zahl gibt die Anzahl von Nachrichten an, die nicht zugestellt werden konnten.
@ -22,7 +22,7 @@ Die Unterabschnitte des Admin Panels kannst du in der Seitenleiste auswählen.
## Seite
In diesem Bereich des Admin Panels findest du die Hauptkonfiguration deiner Friendica Instanz.
In diesem Bereich des Admin Panels findest du die Hauptkonfiguration deiner Friendica-Instanz.
Er ist in mehrere Unterabschnitte aufgeteilt, wobei die Grundeinstellungen oben auf der Seite zu finden sind.
Da die meisten Konfigurationsoptionen einen Hilfstext im Admin Panel haben, kann und will dieser Artikel nicht alle Einstellungen abdecken.
@ -130,7 +130,7 @@ Dieses Feature kann z.B. dafür genutzt werden Blogbeiträge zu spiegeln.
In der Grundeinstellung ist es nicht aktiviert, da es zusätzliche Last auf dem Server verursachen kann.
Außerdem könnte es durch Nutzer als Spam Verteiler missbraucht werden.
Als Administrator der Friendica Instanz kannst du diese Einstellungen ansonsten nur direkt in der Datenbank vornehmen.
Als Administrator der Friendica-Instanz kannst du diese Einstellungen ansonsten nur direkt in der Datenbank vornehmen.
Bevor du das tust solltest du sicherstellen, dass du ein Backup der Datenbank hast und genau weißt was die Änderungen an der Datenbank bewirken, die du vornehmen willst.
### Erweitert
@ -183,7 +183,7 @@ Dadurch werden dann die Aufgaben aktiviert, die der cron Job sonst aktivieren w
## Nutzer
In diesem Abschnitt des Admin Panels kannst du die Nutzer deiner Friendica Instanz moderieren.
In diesem Abschnitt des Admin Panels kannst du die Nutzer deiner Friendica-Instanz moderieren.
Solltest du für **Registrierungsmethode** die Einstellung "Bedarf Zustimmung" gewählt haben, werden hier zu Beginn der Seite neue Registrationen aufgelistet.
Als Administrator kannst du hier die Registration akzeptieren oder ablehnen.
@ -202,12 +202,12 @@ Sie müssen in das `/addon` Verzeichnis kopiert werden.
Auf der Seite wird eine Liste der verfügbaren Erweiterungen angezeigt.
Neben den Namen der Erweiterungen wird ein Indikator angezeigt, der anzeigt ob das Addon gerade aktiviert ist oder nicht.
Wenn du die Erweiterungen aktualisiert die du auf deiner Friendica Instanz nutzt könnte es sein, dass sie neu geladen werden müssen, damit die Änderungen aktiviert werden.
Wenn du die Erweiterungen aktualisiert die du auf deiner Friendica-Instanz nutzt könnte es sein, dass sie neu geladen werden müssen, damit die Änderungen aktiviert werden.
Um diesen Prozess zu vereinfachen gibt es am Anfang der Seite einen Button um alle aktiven Plugins neu zu laden.
## Themen
Der Bereich zur Kontrolle der auf der Friendica Instanz verfügbaren Themen funktioniert analog zum Plugins Bereich.
Der Bereich zur Kontrolle der auf der Friendica-Instanz verfügbaren Themen funktioniert analog zum Plugins Bereich.
Jedes Theme hat eine extra Seite auf der der aktuelle Status, ein Bildschirmfoto des Themes, zusätzliche Informationen und eventuelle Einstellungen des Themes zu finden sind.
Genau wie Erweiterungen können Themes in der Übersichtsliste oder der Theme-Seite aktiviert bzw. deaktiviert werden.
Um ein Standardtheme für die Instanz zu wählen, benutze bitte die *Seiten* Bereich des Admin Panels.
@ -238,6 +238,12 @@ Aber keine Panik!
Friendica wird die Beiträge nicht für alle Zeiten in der Warteschlange behalten.
Nach einiger Zeit werden Knoten als inaktiv identifiziert und Nachrichten an Nutzer dieser Knoten aus der Warteschlange gelöscht.
## Server Blockliste
Auf dieser Seite des Admin Panels können Administratoren einer Friendica-Instanz die komplette Kommunikation (eingehend und ausgehend) mit bestimmten Domains unterbinden.
Für jede dieser Blockierungen muss ein Grund angegeben werden, welcher auf der Informationsseite [friendica](/friendica) angezeigt wird.
Der Abgleich der Domainnamen ist exakt, Subdomains werden nicht automatisch ebenfalls blockiert.
## Federation Statistik
Deine Instanz ist ein Teil eines Netzwerks von Servern dezentraler sozialer Netzwerke, der sogenannten **Federation**.
@ -258,7 +264,7 @@ Wenn du das dennoch tun musste und die Standardeinstellungen des Apache Servers
Solltest du einen anderen Webserver verwenden, solltest du sicherstellen, dass der Zugrif zu Dateien mit diesen Endungen nicht möglich ist.
Es gibt fünf Level der Ausführlichkeit mit denen Friendica arbeitet: Normal, Trace, Debug, Data und All.
Normalerweise solltest du für den Betrieb deiner Friendica Instanz keine Logs benötigen.
Normalerweise solltest du für den Betrieb deiner Friendica-Instanz keine Logs benötigen.
Wenn du versuchst einem Problem auf den Grund zu gehen, solltest du das "DEBUG" Level wählen.
Mit dem "All" Level schreibt Friendica alles in die Logdatei.
Die Datenmenge der geloggten Daten kann relativ schnell anwachsen, deshalb empfehlen wir das Anlegen von Protokollen nur zu aktivieren wenn es unbedingt nötig ist.

View file

@ -1,5 +1,8 @@
<?php
use Friendica\App;
use Friendica\Network\Probe;
// Included here for completeness, but this is a very dangerous operation.
// It is the caller's responsibility to confirm the requestor's intent and
// authorisation to do this.
@ -89,11 +92,11 @@ function terminate_friendship($user,$self,$contact) {
/// @TODO Get rid of this, include/datetime.php should care about it by itself
$a = get_app();
require_once('include/datetime.php');
require_once 'include/datetime.php';
if ($contact['network'] === NETWORK_OSTATUS) {
require_once('include/ostatus.php');
require_once 'include/ostatus.php';
// create an unfollow slap
$item = array();
@ -102,14 +105,14 @@ function terminate_friendship($user,$self,$contact) {
$slap = ostatus::salmon($item, $user);
if ((x($contact,'notify')) && (strlen($contact['notify']))) {
require_once('include/salmon.php');
require_once 'include/salmon.php';
slapper($user,$contact['notify'],$slap);
}
} elseif ($contact['network'] === NETWORK_DIASPORA) {
require_once('include/diaspora.php');
require_once 'include/diaspora.php';
Diaspora::send_unshare($user,$contact);
} elseif ($contact['network'] === NETWORK_DFRN) {
require_once('include/dfrn.php');
require_once 'include/dfrn.php';
dfrn::deliver($user,$contact,'placeholder', 1);
}
@ -361,7 +364,6 @@ function get_contact_details_by_addr($addr, $uid = -1) {
dbesc($addr));
if (!dbm::is_result($r)) {
require_once('include/Probe.php');
$data = Probe::uri($addr);
$profile = get_contact_details_by_url($data['url'], $uid);
@ -587,7 +589,6 @@ function get_contact($url, $uid = 0, $no_update = false) {
return 0;
}
require_once('include/Probe.php');
$data = Probe::uri($url);
// Last try in gcontact for unsupported networks
@ -704,7 +705,7 @@ function get_contact($url, $uid = 0, $no_update = false) {
*/
function posts_from_gcontact(App $a, $gcontact_id) {
require_once('include/conversation.php');
require_once 'include/conversation.php';
// There are no posts with "uid = 0" with connector networks
// This speeds up the query a lot
@ -743,7 +744,7 @@ function posts_from_gcontact(App $a, $gcontact_id) {
*/
function posts_from_contact_url(App $a, $contact_url) {
require_once('include/conversation.php');
require_once 'include/conversation.php';
// There are no posts with "uid = 0" with connector networks
// This speeds up the query a lot
@ -852,4 +853,3 @@ function account_type($contact) {
return $account_type;
}
?>

View file

@ -81,4 +81,3 @@ class Emailer {
return $res;
}
}
?>

View file

@ -1,5 +1,7 @@
<?php
use Friendica\App;
/**
* @file include/ForumManager.php
* @brief ForumManager class with its methods related to forum functionality *

View file

@ -4,9 +4,10 @@
* @brief Methods for read and write notifications from/to database
* or for formatting notifications
*/
require_once('include/html2plain.php');
require_once("include/datetime.php");
require_once("include/bbcode.php");
require_once 'include/html2plain.php';
require_once 'include/probe.php';
require_once 'include/datetime.php';
require_once 'include/bbcode.php';
/**
* @brief Methods for read and write notifications from/to database
@ -24,7 +25,7 @@ class NotificationsManager {
*
* @param array $notes array of note arrays from db
* @return array Copy of input array with added properties
*
*
* Set some extra properties to note array from db:
* - timestamp as int in default TZ
* - date_rel : relative date string
@ -143,8 +144,7 @@ class NotificationsManager {
/**
* @brief List of pages for the Notifications TabBar
*
* @param app $a The
*
* @return array with with notifications TabBar data
*/
public function getTabs() {
@ -191,7 +191,7 @@ class NotificationsManager {
/**
* @brief Format the notification query in an usable array
*
*
* @param array $notifs The array from the db query
* @param string $ident The notifications identifier (e.g. network)
* @return array
@ -360,7 +360,7 @@ class NotificationsManager {
}
/**
* @brief Total number of network notifications
* @brief Total number of network notifications
* @param int|string $seen
* If 0 only include notifications into the query
* which aren't marked as "seen"
@ -388,13 +388,13 @@ class NotificationsManager {
/**
* @brief Get network notifications
*
*
* @param int|string $seen
* If 0 only include notifications into the query
* which aren't marked as "seen"
* @param int $start Start the query at this point
* @param int $limit Maximum number of query results
*
*
* @return array with
* string 'ident' => Notification identifier
* int 'total' => Total number of available network notifications
@ -436,7 +436,7 @@ class NotificationsManager {
}
/**
* @brief Total number of system notifications
* @brief Total number of system notifications
* @param int|string $seen
* If 0 only include notifications into the query
* which aren't marked as "seen"
@ -460,13 +460,13 @@ class NotificationsManager {
/**
* @brief Get system notifications
*
*
* @param int|string $seen
* If 0 only include notifications into the query
* which aren't marked as "seen"
* @param int $start Start the query at this point
* @param int $limit Maximum number of query results
*
*
* @return array with
* string 'ident' => Notification identifier
* int 'total' => Total number of available system notifications
@ -502,7 +502,7 @@ class NotificationsManager {
/**
* @brief Addional SQL query string for the personal notifications
*
*
* @return string The additional sql query
*/
private function _personal_sql_extra() {
@ -520,7 +520,7 @@ class NotificationsManager {
}
/**
* @brief Total number of personal notifications
* @brief Total number of personal notifications
* @param int|string $seen
* If 0 only include notifications into the query
* which aren't marked as "seen"
@ -550,13 +550,13 @@ class NotificationsManager {
/**
* @brief Get personal notifications
*
*
* @param int|string $seen
* If 0 only include notifications into the query
* which aren't marked as "seen"
* @param int $start Start the query at this point
* @param int $limit Maximum number of query results
*
*
* @return array with
* string 'ident' => Notification identifier
* int 'total' => Total number of available personal notifications
@ -573,13 +573,13 @@ class NotificationsManager {
$sql_seen = " AND `item`.`unseen` = 1 ";
$r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, `item`.`unseen`,
`item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` AS `object`,
`pitem`.`author-name` AS `pname`, `pitem`.`author-link` AS `plink`, `pitem`.`guid` AS `pguid`
`item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` AS `object`,
`pitem`.`author-name` AS `pname`, `pitem`.`author-link` AS `plink`, `pitem`.`guid` AS `pguid`
FROM `item` INNER JOIN `item` AS `pitem` ON `pitem`.`id`=`item`.`parent`
WHERE `item`.`visible` = 1
$sql_extra
$sql_seen
AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0
AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0
ORDER BY `item`.`created` DESC LIMIT %d, %d " ,
intval(local_user()),
intval($start),
@ -588,7 +588,7 @@ class NotificationsManager {
if (dbm::is_result($r))
$notifs = $this->formatNotifs($r, $ident);
$arr = array (
'notifications' => $notifs,
'ident' => $ident,
@ -599,7 +599,7 @@ class NotificationsManager {
}
/**
* @brief Total number of home notifications
* @brief Total number of home notifications
* @param int|string $seen
* If 0 only include notifications into the query
* which aren't marked as "seen"
@ -626,13 +626,13 @@ class NotificationsManager {
/**
* @brief Get home notifications
*
*
* @param int|string $seen
* If 0 only include notifications into the query
* which aren't marked as "seen"
* @param int $start Start the query at this point
* @param int $limit Maximum number of query results
*
*
* @return array with
* string 'ident' => Notification identifier
* int 'total' => Total number of available home notifications
@ -673,7 +673,7 @@ class NotificationsManager {
}
/**
* @brief Total number of introductions
* @brief Total number of introductions
* @param bool $all
* If false only include introductions into the query
* which aren't marked as ignored
@ -698,13 +698,13 @@ class NotificationsManager {
/**
* @brief Get introductions
*
*
* @param bool $all
* If false only include introductions into the query
* which aren't marked as ignored
* @param int $start Start the query at this point
* @param int $limit Maximum number of query results
*
*
* @return array with
* string 'ident' => Notification identifier
* int 'total' => Total number of available introductions
@ -749,7 +749,7 @@ class NotificationsManager {
/**
* @brief Format the notification query in an usable array
*
*
* @param array $intros The array from the db query
* @return array with the introductions
*/

View file

@ -4,6 +4,8 @@
* @brief This file contains the Photo class for image processing
*/
use Friendica\App;
require_once("include/photos.php");
class Photo {
@ -68,7 +70,9 @@ class Photo {
$this->image->destroy();
return;
}
imagedestroy($this->image);
if (is_resource($this->image)) {
imagedestroy($this->image);
}
}
}
@ -324,6 +328,7 @@ class Photo {
return;
}
// if script dies at this point check memory_limit setting in php.ini
$this->image = imagerotate($this->image,$degrees,0);
$this->width = imagesx($this->image);
$this->height = imagesy($this->image);
@ -620,7 +625,7 @@ class Photo {
public function store($uid, $cid, $rid, $filename, $album, $scale, $profile = 0, $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '') {
public function store($uid, $cid, $rid, $filename, $album, $scale, $profile = 0, $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '', $desc = '') {
$r = q("SELECT `guid` FROM `photo` WHERE `resource-id` = '%s' AND `guid` != '' LIMIT 1",
dbesc($rid)
@ -657,7 +662,8 @@ class Photo {
`allow_cid` = '%s',
`allow_gid` = '%s',
`deny_cid` = '%s',
`deny_gid` = '%s'
`deny_gid` = '%s',
`desc` = '%s'
WHERE `id` = %d",
intval($uid),
@ -679,12 +685,13 @@ class Photo {
dbesc($allow_gid),
dbesc($deny_cid),
dbesc($deny_gid),
dbesc($desc),
intval($x[0]['id'])
);
} else {
$r = q("INSERT INTO `photo`
(`uid`, `contact-id`, `guid`, `resource-id`, `created`, `edited`, `filename`, type, `album`, `height`, `width`, `datasize`, `data`, `scale`, `profile`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`)
VALUES (%d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, '%s', %d, %d, '%s', '%s', '%s', '%s')",
(`uid`, `contact-id`, `guid`, `resource-id`, `created`, `edited`, `filename`, type, `album`, `height`, `width`, `datasize`, `data`, `scale`, `profile`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`, `desc`)
VALUES (%d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, '%s', %d, %d, '%s', '%s', '%s', '%s', '%s')",
intval($uid),
intval($cid),
dbesc($guid),
@ -703,7 +710,8 @@ class Photo {
dbesc($allow_cid),
dbesc($allow_gid),
dbesc($deny_cid),
dbesc($deny_gid)
dbesc($deny_gid),
dbesc($desc)
);
}

View file

@ -5,6 +5,8 @@
* @brief This file contains the Smilies class which contains functions to handle smiles
*/
use Friendica\App;
/**
* This class contains functions to handle smiles
*/
@ -13,13 +15,13 @@ class Smilies {
/**
* @brief Function to list all smilies
*
*
* Get an array of all smilies, both internal and from addons.
*
*
* @return array
* 'texts' => smilie shortcut
* 'icons' => icon in html
*
*
* @hook smilie ('texts' => smilies texts array, 'icons' => smilies html array)
*/
public static function get_list() {
@ -64,41 +66,41 @@ class Smilies {
);
$icons = array(
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-heart.gif" alt="&lt;3" title="&lt;3" />',
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-brokenheart.gif" alt="&lt;/3" title="&lt;/3" />',
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-brokenheart.gif" alt="&lt;\\3" title="&lt;\\3" />',
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-smile.gif" alt=":-)" title=":-)" />',
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-wink.gif" alt=";-)" title=";-)" />',
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-frown.gif" alt=":-(" title=":-(" />',
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-tongue-out.gif" alt=":-P" title=":-P" />',
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-tongue-out.gif" alt=":-p" title=":-P" />',
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-kiss.gif" alt=":-\" title=":-\" />',
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-kiss.gif" alt=":-\" title=":-\" />',
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-kiss.gif" alt=":-x" title=":-x" />',
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-kiss.gif" alt=":-X" title=":-X" />',
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-laughing.gif" alt=":-D" title=":-D" />',
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-surprised.gif" alt="8-|" title="8-|" />',
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-surprised.gif" alt="8-O" title="8-O" />',
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-surprised.gif" alt=":-O" title="8-O" />',
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-thumbsup.gif" alt="\\o/" title="\\o/" />',
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-Oo.gif" alt="o.O" title="o.O" />',
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-Oo.gif" alt="O.o" title="O.o" />',
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-Oo.gif" alt="o_O" title="o_O" />',
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-Oo.gif" alt="O_o" title="O_o" />',
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-cry.gif" alt=":\'(" title=":\'("/>',
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-foot-in-mouth.gif" alt=":-!" title=":-!" />',
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-undecided.gif" alt=":-/" title=":-/" />',
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-embarassed.gif" alt=":-[" title=":-[" />',
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-cool.gif" alt="8-)" title="8-)" />',
'<img class="smiley" src="' . app::get_baseurl() . '/images/beer_mug.gif" alt=":beer" title=":beer" />',
'<img class="smiley" src="' . app::get_baseurl() . '/images/beer_mug.gif" alt=":homebrew" title=":homebrew" />',
'<img class="smiley" src="' . app::get_baseurl() . '/images/coffee.gif" alt=":coffee" title=":coffee" />',
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-facepalm.gif" alt=":facepalm" title=":facepalm" />',
'<img class="smiley" src="' . app::get_baseurl() . '/images/like.gif" alt=":like" title=":like" />',
'<img class="smiley" src="' . app::get_baseurl() . '/images/dislike.gif" alt=":dislike" title=":dislike" />',
'<a href="http://friendica.com">~friendica <img class="smiley" src="' . app::get_baseurl() . '/images/friendica-16.png" alt="~friendica" title="~friendica" /></a>',
'<a href="http://redmatrix.me/">red<img class="smiley" src="' . app::get_baseurl() . '/images/rm-16.png" alt="red#" title="red#" />matrix</a>',
'<a href="http://redmatrix.me/">red<img class="smiley" src="' . app::get_baseurl() . '/images/rm-16.png" alt="red#matrix" title="red#matrix" />matrix</a>'
'<img class="smiley" src="' . App::get_baseurl() . '/images/smiley-heart.gif" alt="&lt;3" title="&lt;3" />',
'<img class="smiley" src="' . App::get_baseurl() . '/images/smiley-brokenheart.gif" alt="&lt;/3" title="&lt;/3" />',
'<img class="smiley" src="' . App::get_baseurl() . '/images/smiley-brokenheart.gif" alt="&lt;\\3" title="&lt;\\3" />',
'<img class="smiley" src="' . App::get_baseurl() . '/images/smiley-smile.gif" alt=":-)" title=":-)" />',
'<img class="smiley" src="' . App::get_baseurl() . '/images/smiley-wink.gif" alt=";-)" title=";-)" />',
'<img class="smiley" src="' . App::get_baseurl() . '/images/smiley-frown.gif" alt=":-(" title=":-(" />',
'<img class="smiley" src="' . App::get_baseurl() . '/images/smiley-tongue-out.gif" alt=":-P" title=":-P" />',
'<img class="smiley" src="' . App::get_baseurl() . '/images/smiley-tongue-out.gif" alt=":-p" title=":-P" />',
'<img class="smiley" src="' . App::get_baseurl() . '/images/smiley-kiss.gif" alt=":-\" title=":-\" />',
'<img class="smiley" src="' . App::get_baseurl() . '/images/smiley-kiss.gif" alt=":-\" title=":-\" />',
'<img class="smiley" src="' . App::get_baseurl() . '/images/smiley-kiss.gif" alt=":-x" title=":-x" />',
'<img class="smiley" src="' . App::get_baseurl() . '/images/smiley-kiss.gif" alt=":-X" title=":-X" />',
'<img class="smiley" src="' . App::get_baseurl() . '/images/smiley-laughing.gif" alt=":-D" title=":-D" />',
'<img class="smiley" src="' . App::get_baseurl() . '/images/smiley-surprised.gif" alt="8-|" title="8-|" />',
'<img class="smiley" src="' . App::get_baseurl() . '/images/smiley-surprised.gif" alt="8-O" title="8-O" />',
'<img class="smiley" src="' . App::get_baseurl() . '/images/smiley-surprised.gif" alt=":-O" title="8-O" />',
'<img class="smiley" src="' . App::get_baseurl() . '/images/smiley-thumbsup.gif" alt="\\o/" title="\\o/" />',
'<img class="smiley" src="' . App::get_baseurl() . '/images/smiley-Oo.gif" alt="o.O" title="o.O" />',
'<img class="smiley" src="' . App::get_baseurl() . '/images/smiley-Oo.gif" alt="O.o" title="O.o" />',
'<img class="smiley" src="' . App::get_baseurl() . '/images/smiley-Oo.gif" alt="o_O" title="o_O" />',
'<img class="smiley" src="' . App::get_baseurl() . '/images/smiley-Oo.gif" alt="O_o" title="O_o" />',
'<img class="smiley" src="' . App::get_baseurl() . '/images/smiley-cry.gif" alt=":\'(" title=":\'("/>',
'<img class="smiley" src="' . App::get_baseurl() . '/images/smiley-foot-in-mouth.gif" alt=":-!" title=":-!" />',
'<img class="smiley" src="' . App::get_baseurl() . '/images/smiley-undecided.gif" alt=":-/" title=":-/" />',
'<img class="smiley" src="' . App::get_baseurl() . '/images/smiley-embarassed.gif" alt=":-[" title=":-[" />',
'<img class="smiley" src="' . App::get_baseurl() . '/images/smiley-cool.gif" alt="8-)" title="8-)" />',
'<img class="smiley" src="' . App::get_baseurl() . '/images/beer_mug.gif" alt=":beer" title=":beer" />',
'<img class="smiley" src="' . App::get_baseurl() . '/images/beer_mug.gif" alt=":homebrew" title=":homebrew" />',
'<img class="smiley" src="' . App::get_baseurl() . '/images/coffee.gif" alt=":coffee" title=":coffee" />',
'<img class="smiley" src="' . App::get_baseurl() . '/images/smiley-facepalm.gif" alt=":facepalm" title=":facepalm" />',
'<img class="smiley" src="' . App::get_baseurl() . '/images/like.gif" alt=":like" title=":like" />',
'<img class="smiley" src="' . App::get_baseurl() . '/images/dislike.gif" alt=":dislike" title=":dislike" />',
'<a href="http://friendica.com">~friendica <img class="smiley" src="' . App::get_baseurl() . '/images/friendica-16.png" alt="~friendica" title="~friendica" /></a>',
'<a href="http://redmatrix.me/">red<img class="smiley" src="' . App::get_baseurl() . '/images/rm-16.png" alt="red#" title="red#" />matrix</a>',
'<a href="http://redmatrix.me/">red<img class="smiley" src="' . App::get_baseurl() . '/images/rm-16.png" alt="red#matrix" title="red#matrix" />matrix</a>'
);
$params = array('texts' => $texts, 'icons' => $icons);
@ -121,7 +123,7 @@ class Smilies {
*
* @param string $s
* @param boolean $sample
*
*
* @return string HML Output of the Smilie
*/
public static function replace($s, $sample = false) {
@ -166,7 +168,7 @@ class Smilies {
*
* @param string $x
* @return string HTML Output
*
*
* @todo: Rework because it doesn't work correctly
*/
private function preg_heart($x) {
@ -174,7 +176,7 @@ class Smilies {
return $x[0];
$t = '';
for($cnt = 0; $cnt < strlen($x[1]); $cnt ++)
$t .= '<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-heart.gif" alt="&lt;3" />';
$t .= '<img class="smiley" src="' . App::get_baseurl() . '/images/smiley-heart.gif" alt="&lt;3" />';
$r = str_replace($x[0],$t,$x[0]);
return $r;
}

View file

@ -4,6 +4,8 @@
* @file include/acl_selectors.php
*/
use Friendica\App;
require_once "include/contact_selectors.php";
require_once "include/contact_widgets.php";
require_once "include/DirSearch.php";
@ -543,7 +545,7 @@ function acl_lookup(App $a, $out_type = 'json') {
if ($type == '') {
$r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, `forum`, `prv` FROM `contact`
$r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, `addr`, `forum`, `prv` FROM `contact`
WHERE `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND `notify` != ''
AND NOT (`network` IN ('%s', '%s'))
$sql_extra2
@ -552,7 +554,7 @@ function acl_lookup(App $a, $out_type = 'json') {
dbesc(NETWORK_OSTATUS), dbesc(NETWORK_STATUSNET)
);
} elseif ($type == 'c') {
$r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, `forum`, `prv` FROM `contact`
$r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, `addr`, `forum`, `prv` FROM `contact`
WHERE `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `pending` AND NOT `archive` AND `notify` != ''
AND NOT (`network` IN ('%s'))
$sql_extra2
@ -562,7 +564,7 @@ function acl_lookup(App $a, $out_type = 'json') {
);
}
elseif ($type == 'm') {
$r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag` FROM `contact`
$r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, `addr` FROM `contact`
WHERE `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `pending` AND NOT `archive`
AND `network` IN ('%s','%s','%s')
$sql_extra2
@ -573,7 +575,7 @@ function acl_lookup(App $a, $out_type = 'json') {
dbesc(NETWORK_DIASPORA)
);
} elseif ($type == 'a') {
$r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, `forum`, `prv` FROM `contact`
$r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, `addr`, `forum`, `prv` FROM `contact`
WHERE `uid` = %d AND `pending` = 0
$sql_extra2
ORDER BY `name` ASC ",
@ -617,6 +619,7 @@ function acl_lookup(App $a, $out_type = 'json') {
'network' => $g['network'],
'link' => $g['url'],
'nick' => htmlentities(($g['attag']) ? $g['attag'] : $g['nick']),
'addr' => htmlentities(($g['addr']) ? $g['addr'] : $g['url']),
'forum' => ((x($g, 'forum') || x($g, 'prv')) ? 1 : 0),
);
}
@ -661,6 +664,7 @@ function acl_lookup(App $a, $out_type = 'json') {
'network' => $contact['network'],
'link' => $contact['url'],
'nick' => htmlentities($contact['nick'] ? : $contact['addr']),
'addr' => htmlentities(($contact['addr']) ? $contact['addr'] : $contact['url']),
'forum' => $contact['forum']
);
}

View file

@ -6,7 +6,8 @@
* @todo Automatically detect if incoming data is HTML or BBCode
*/
use \Friendica\Core\Config;
use Friendica\App;
use Friendica\Core\Config;
require_once 'include/HTTPExceptions.php';
require_once 'include/bbcode.php';
@ -525,6 +526,15 @@ $called_api = null;
}
}
if (is_null($user) && x($_GET, 'profileurl')) {
$user = dbesc(normalise_link($_GET['profileurl']));
$nick = $user;
$extra_query = "AND `contact`.`nurl` = '%s' ";
if (api_user() !== false) {
$extra_query .= "AND `contact`.`uid`=".intval(api_user());
}
}
if (is_null($user) AND ($a->argc > (count($called_api) - 1)) AND (count($called_api) > 0)) {
$argid = count($called_api);
list($user, $null) = explode(".", $a->argv[$argid]);
@ -1400,6 +1410,7 @@ $called_api = null;
/// @TODO move to top of file or somewhere better
api_register_func('api/users/show','api_users_show');
api_register_func('api/externalprofile/show','api_users_show');
function api_users_search($type) {
@ -3276,14 +3287,117 @@ $called_api = null;
api_register_func('api/oauth/request_token', 'api_oauth_request_token', false);
api_register_func('api/oauth/access_token', 'api_oauth_access_token', false);
/**
* @brief delete a complete photoalbum with all containing photos from database through api
*
* @param string $type Known types are 'atom', 'rss', 'xml' and 'json'
* @return string
*/
function api_fr_photoalbum_delete($type) {
if (api_user() === false) {
throw new ForbiddenException();
}
// input params
$album = (x($_REQUEST,'album') ? $_REQUEST['album'] : "");
// we do not allow calls without album string
if ($album == "") {
throw new BadRequestException("no albumname specified");
}
// check if album is existing
$r = q("SELECT DISTINCT `resource-id` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
intval(api_user()),
dbesc($album));
if (!dbm::is_result($r))
throw new BadRequestException("album not available");
// function for setting the items to "deleted = 1" which ensures that comments, likes etc. are not shown anymore
// to the user and the contacts of the users (drop_items() performs the federation of the deletion to other networks
foreach ($r as $rr) {
$photo_item = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `resource-id` = '%s' AND `type` = 'photo'",
intval(local_user()),
dbesc($rr['resource-id'])
);
if (!dbm::is_result($photo_item)) {
throw new InternalServerErrorException("problem with deleting items occured");
}
drop_item($photo_item[0]['id'],false);
}
// now let's delete all photos from the album
$result = q("DELETE FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
intval(api_user()),
dbesc($album));
// return success of deletion or error message
if ($result) {
$answer = array('result' => 'deleted', 'message' => 'album `' . $album . '` with all containing photos has been deleted.');
return api_format_data("photoalbum_delete", $type, array('$result' => $answer));
} else {
throw new InternalServerErrorException("unknown error - deleting from database failed");
}
}
/**
* @brief update the name of the album for all photos of an album
*
* @param string $type Known types are 'atom', 'rss', 'xml' and 'json'
* @return string
*/
function api_fr_photoalbum_update($type) {
if (api_user() === false) {
throw new ForbiddenException();
}
// input params
$album = (x($_REQUEST,'album') ? $_REQUEST['album'] : "");
$album_new = (x($_REQUEST,'album_new') ? $_REQUEST['album_new'] : "");
// we do not allow calls without album string
if ($album == "") {
throw new BadRequestException("no albumname specified");
}
if ($album_new == "") {
throw new BadRequestException("no new albumname specified");
}
// check if album is existing
$r = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
intval(api_user()),
dbesc($album));
if (!dbm::is_result($r)) {
throw new BadRequestException("album not available");
}
// now let's update all photos to the albumname
$result = q("UPDATE `photo` SET `album` = '%s' WHERE `uid` = %d AND `album` = '%s'",
dbesc($album_new),
intval(api_user()),
dbesc($album));
// return success of updating or error message
if ($result) {
$answer = array('result' => 'updated', 'message' => 'album `' . $album . '` with all containing photos has been renamed to `' . $album_new . '`.');
return api_format_data("photoalbum_update", $type, array('$result' => $answer));
} else {
throw new InternalServerErrorException("unknown error - updating in database failed");
}
}
/**
* @brief list all photos of the authenticated user
*
* @param string $type Known types are 'atom', 'rss', 'xml' and 'json'
* @return string
*/
function api_fr_photos_list($type) {
if (api_user() === false) {
throw new ForbiddenException();
}
$r = q("SELECT `resource-id`, MAX(`scale`) AS `scale`, `album`, `filename`, `type`
FROM `photo`
WHERE `uid` = %d AND `album` != 'Contact Photos' GROUP BY `resource-id`, `album`, `filename`, `type`",
$r = q("SELECT `resource-id`, MAX(scale) AS `scale`, `album`, `filename`, `type`, MAX(`created`) AS `created`,
MAX(`edited`) AS `edited`, MAX(`desc`) AS `desc` FROM `photo`
WHERE `uid` = %d AND `album` != 'Contact Photos' GROUP BY `resource-id`",
intval(local_user())
);
$typetoext = array(
@ -3291,7 +3405,7 @@ $called_api = null;
'image/png' => 'png',
'image/gif' => 'gif'
);
$data = array('photo' => array());
$data = array('photo'=>array());
if (dbm::is_result($r)) {
foreach ($r as $rr) {
$photo = array();
@ -3300,6 +3414,9 @@ $called_api = null;
$photo['filename'] = $rr['filename'];
$photo['type'] = $rr['type'];
$thumb = App::get_baseurl() . "/photo/" . $rr['resource-id'] . "-" . $rr['scale'] . "." . $typetoext[$rr['type']];
$photo['created'] = $rr['created'];
$photo['edited'] = $rr['edited'];
$photo['desc'] = $rr['desc'];
if ($type == "xml") {
$data['photo'][] = array("@attributes" => $photo, "1" => $thumb);
@ -3312,26 +3429,563 @@ $called_api = null;
return api_format_data("photos", $type, $data);
}
/**
* @brief upload a new photo or change an existing photo
*
* @param string $type Known types are 'atom', 'rss', 'xml' and 'json'
* @return string
*/
function api_fr_photo_create_update($type) {
if (api_user() === false) {
throw new ForbiddenException();
}
// input params
$photo_id = (x($_REQUEST, 'photo_id') ? $_REQUEST['photo_id'] : null);
$desc = (x($_REQUEST, 'desc') ? $_REQUEST['desc'] : (array_key_exists('desc', $_REQUEST) ? "" : null)); // extra check necessary to distinguish between 'not provided' and 'empty string'
$album = (x($_REQUEST,'album') ? $_REQUEST['album'] : null);
$album_new = (x($_REQUEST,'album_new') ? $_REQUEST['album_new'] : null);
$allow_cid = (x($_REQUEST, 'allow_cid') ? $_REQUEST['allow_cid'] : (array_key_exists('allow_cid', $_REQUEST) ? " " : null));
$deny_cid = (x($_REQUEST, 'deny_cid') ? $_REQUEST['deny_cid'] : (array_key_exists('deny_cid', $_REQUEST) ? " " : null));
$allow_gid = (x($_REQUEST, 'allow_gid') ? $_REQUEST['allow_gid'] : (array_key_exists('allow_gid', $_REQUEST) ? " " : null));
$deny_gid = (x($_REQUEST, 'deny_gid') ? $_REQUEST['deny_gid'] : (array_key_exists('deny_gid', $_REQUEST) ? " " : null));
$visibility = (x($_REQUEST, 'visibility') ? (($_REQUEST['visibility'] == "true" || $_REQUEST['visibility'] == 1) ? true : false) : false);
// do several checks on input parameters
// we do not allow calls without album string
if ($album == null) {
throw new BadRequestException("no albumname specified");
}
// if photo_id == null --> we are uploading a new photo
if ($photo_id == null) {
$mode = "create";
// error if no media posted in create-mode
if (!x($_FILES,'media')) {
// Output error
throw new BadRequestException("no media data submitted");
}
// album_new will be ignored in create-mode
$album_new = "";
} else {
$mode = "update";
// check if photo is existing in database
$r = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' AND `album` = '%s'",
intval(api_user()),
dbesc($photo_id),
dbesc($album));
if (!dbm::is_result($r)) {
throw new BadRequestException("photo not available");
}
}
// checks on acl strings provided by clients
$acl_input_error = false;
$acl_input_error |= check_acl_input($allow_cid);
$acl_input_error |= check_acl_input($deny_cid);
$acl_input_error |= check_acl_input($allow_gid);
$acl_input_error |= check_acl_input($deny_gid);
if ($acl_input_error) {
throw new BadRequestException("acl data invalid");
}
// now let's upload the new media in create-mode
if ($mode == "create") {
$media = $_FILES['media'];
$data = save_media_to_database("photo", $media, $type, $album, trim($allow_cid), trim($deny_cid), trim($allow_gid), trim($deny_gid), $desc, $visibility);
// return success of updating or error message
if (!is_null($data)) {
return api_format_data("photo_create", $type, $data);
} else {
throw new InternalServerErrorException("unknown error - uploading photo failed, see Friendica log for more information");
}
}
// now let's do the changes in update-mode
if ($mode == "update") {
$sql_extra = "";
if (!is_null($desc)) {
$sql_extra .= (($sql_extra != "") ? " ," : "") . "`desc` = '$desc'";
}
if (!is_null($album_new)) {
$sql_extra .= (($sql_extra != "") ? " ," : "") . "`album` = '$album_new'";
}
if (!is_null($allow_cid)) {
$allow_cid = trim($allow_cid);
$sql_extra .= (($sql_extra != "") ? " ," : "") . "`allow_cid` = '$allow_cid'";
}
if (!is_null($deny_cid)) {
$deny_cid = trim($deny_cid);
$sql_extra .= (($sql_extra != "") ? " ," : "") . "`deny_cid` = '$deny_cid'";
}
if (!is_null($allow_gid)) {
$allow_gid = trim($allow_gid);
$sql_extra .= (($sql_extra != "") ? " ," : "") . "`allow_gid` = '$allow_gid'";
}
if (!is_null($deny_gid)) {
$deny_gid = trim($deny_gid);
$sql_extra .= (($sql_extra != "") ? " ," : "") . "`deny_gid` = '$deny_gid'";
}
$result = false;
if ($sql_extra != "") {
$nothingtodo = false;
$result = q("UPDATE `photo` SET %s, `edited`='%s' WHERE `uid` = %d AND `resource-id` = '%s' AND `album` = '%s'",
$sql_extra,
datetime_convert(), // update edited timestamp
intval(api_user()),
dbesc($photo_id),
dbesc($album));
} else {
$nothingtodo = true;
}
if (x($_FILES,'media')) {
$nothingtodo = false;
$media = $_FILES['media'];
$data = save_media_to_database("photo", $media, $type, $album, $allow_cid, $deny_cid, $allow_gid, $deny_gid, $desc, 0, $visibility, $photo_id);
if (!is_null($data)) {
return api_format_data("photo_update", $type, $data);
}
}
// return success of updating or error message
if ($result) {
$answer = array('result' => 'updated', 'message' => 'Image id `' . $photo_id . '` has been updated.');
return api_format_data("photo_update", $type, array('$result' => $answer));
} else {
if ($nothingtodo) {
$answer = array('result' => 'cancelled', 'message' => 'Nothing to update for image id `' . $photo_id . '`.');
return api_format_data("photo_update", $type, array('$result' => $answer));
}
throw new InternalServerErrorException("unknown error - update photo entry in database failed");
}
}
throw new InternalServerErrorException("unknown error - this error on uploading or updating a photo should never happen");
}
/**
* @brief delete a single photo from the database through api
*
* @param string $type Known types are 'atom', 'rss', 'xml' and 'json'
* @return string
*/
function api_fr_photo_delete($type) {
if (api_user() === false) {
throw new ForbiddenException();
}
// input params
$photo_id = (x($_REQUEST, 'photo_id') ? $_REQUEST['photo_id'] : null);
// do several checks on input parameters
// we do not allow calls without photo id
if ($photo_id == null) {
throw new BadRequestException("no photo_id specified");
}
// check if photo is existing in database
$r = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
intval(api_user()),
dbesc($photo_id)
);
if (!dbm::is_result($r)) {
throw new BadRequestException("photo not available");
}
// now we can perform on the deletion of the photo
$result = q("DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
intval(api_user()),
dbesc($photo_id));
// return success of deletion or error message
if ($result) {
// retrieve the id of the parent element (the photo element)
$photo_item = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `resource-id` = '%s' AND `type` = 'photo'",
intval(local_user()),
dbesc($photo_id)
);
if (!dbm::is_result($photo_item)) {
throw new InternalServerErrorException("problem with deleting items occured");
}
// function for setting the items to "deleted = 1" which ensures that comments, likes etc. are not shown anymore
// to the user and the contacts of the users (drop_items() do all the necessary magic to avoid orphans in database and federate deletion)
drop_item($photo_item[0]['id'], false);
$answer = array('result' => 'deleted', 'message' => 'photo with id `' . $photo_id . '` has been deleted from server.');
return api_format_data("photo_delete", $type, array('$result' => $answer));
} else {
throw new InternalServerErrorException("unknown error on deleting photo from database table");
}
}
/**
* @brief returns the details of a specified photo id, if scale is given, returns the photo data in base 64
*
* @param string $type Known types are 'atom', 'rss', 'xml' and 'json'
* @return string
*/
function api_fr_photo_detail($type) {
if (api_user() === false) {
throw new ForbiddenException();
} elseif (!x($_REQUEST, 'photo_id')) {
}
if (!x($_REQUEST, 'photo_id')) {
throw new BadRequestException("No photo id.");
}
$scale = (x($_REQUEST, 'scale') ? intval($_REQUEST['scale']) : false);
$scale_sql = ($scale === false ? "" : sprintf("AND `scale`=%d",intval($scale)));
$data_sql = ($scale === false ? "" : "ANY_VALUE(`data`) AS data`,");
$photo_id = $_REQUEST['photo_id'];
$r = q("SELECT %s ANY_VALUE(`resource-id`) AS `resource-id`, ANY_VALUE(`created`) AS `created`,
ANY_VALUE(`edited`) AS `edited`, ANY_VALUE(`title`) AS `title`, ANY_VALUE(`desc`) AS `desc`,
ANY_VALUE(`album`) AS `album`, ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`type`) AS `type`,
ANY_VALUE(`height`) AS `height`, ANY_VALUE(`width`) AS `width`, ANY_VALUE(`datasize`) AS `datasize`,
ANY_VALUE(`profile`) AS `profile`, min(`scale`) as minscale, max(`scale`) as maxscale
FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' %s",
// prepare json/xml output with data from database for the requested photo
$data = prepare_photo_data($type, $scale, $photo_id);
return api_format_data("photo_detail", $type, $data);
}
/**
* @brief updates the profile image for the user (either a specified profile or the default profile)
*
* @param string $type Known types are 'atom', 'rss', 'xml' and 'json'
* @return string
*/
function api_account_update_profile_image($type) {
if (api_user() === false) {
throw new ForbiddenException();
}
// input params
$profileid = (x($_REQUEST, 'profile_id') ? $_REQUEST['profile_id'] : 0);
// error if image data is missing
if (!x($_FILES, 'image')) {
throw new BadRequestException("no media data submitted");
}
// check if specified profile id is valid
if ($profileid != 0) {
$r = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `id` = %d",
intval(api_user()),
intval($profileid));
// error message if specified profile id is not in database
if (!dbm::is_result($r)) {
throw new BadRequestException("profile_id not available");
}
$is_default_profile = $r['profile'];
} else {
$is_default_profile = 1;
}
// get mediadata from image or media (Twitter call api/account/update_profile_image provides image)
$media = null;
if (x($_FILES, 'image')) {
$media = $_FILES['image'];
} elseif (x($_FILES, 'media')) {
$media = $_FILES['media'];
}
// save new profile image
$data = save_media_to_database("profileimage", $media, $type, t('Profile Photos'), "", "", "", "", "", $is_default_profile);
// get filetype
if (is_array($media['type'])) {
$filetype = $media['type'][0];
} else {
$filetype = $media['type'];
}
if ($filetype == "image/jpeg") {
$fileext = "jpg";
} elseif ($filetype == "image/png") {
$fileext = "png";
}
// change specified profile or all profiles to the new resource-id
if ($is_default_profile) {
$r = q("UPDATE `photo` SET `profile` = 0 WHERE `profile` = 1 AND `resource-id` != '%s' AND `uid` = %d",
dbesc($data['photo']['id']),
intval(local_user())
);
$r = q("UPDATE `contact` SET `photo` = '%s', `thumb` = '%s', `micro` = '%s' WHERE `self` AND `uid` = %d",
dbesc(App::get_baseurl() . '/photo/' . $data['photo']['id'] . '-4.' . $fileext),
dbesc(App::get_baseurl() . '/photo/' . $data['photo']['id'] . '-5.' . $fileext),
dbesc(App::get_baseurl() . '/photo/' . $data['photo']['id'] . '-6.' . $fileext),
intval(local_user())
);
} else {
$r = q("UPDATE `profile` SET `photo` = '%s', `thumb` = '%s' WHERE `id` = %d AND `uid` = %d",
dbesc(App::get_baseurl() . '/photo/' . $data['photo']['id'] . '-4.' . $filetype),
dbesc(App::get_baseurl() . '/photo/' . $data['photo']['id'] . '-5.' . $filetype),
intval($_REQUEST['profile']),
intval(local_user())
);
}
// we'll set the updated profile-photo timestamp even if it isn't the default profile,
// so that browsers will do a cache update unconditionally
$r = q("UPDATE `contact` SET `avatar-date` = '%s' WHERE `self` = 1 AND `uid` = %d",
dbesc(datetime_convert()),
intval(local_user())
);
// Update global directory in background
//$user = api_get_user(get_app());
$url = App::get_baseurl() . '/profile/' . get_app()->user['nickname'];
if ($url && strlen(get_config('system', 'directory'))) {
proc_run(PRIORITY_LOW, "include/directory.php", $url);
}
require_once 'include/profile_update.php';
profile_change();
// output for client
if ($data) {
return api_account_verify_credentials($type);
} else {
// SaveMediaToDatabase failed for some reason
throw new InternalServerErrorException("image upload failed");
}
}
// place api-register for photoalbum calls before 'api/friendica/photo', otherwise this function is never reached
api_register_func('api/friendica/photoalbum/delete', 'api_fr_photoalbum_delete', true, API_METHOD_DELETE);
api_register_func('api/friendica/photoalbum/update', 'api_fr_photoalbum_update', true, API_METHOD_POST);
api_register_func('api/friendica/photos/list', 'api_fr_photos_list', true);
api_register_func('api/friendica/photo/create', 'api_fr_photo_create_update', true, API_METHOD_POST);
api_register_func('api/friendica/photo/update', 'api_fr_photo_create_update', true, API_METHOD_POST);
api_register_func('api/friendica/photo/delete', 'api_fr_photo_delete', true, API_METHOD_DELETE);
api_register_func('api/friendica/photo', 'api_fr_photo_detail', true);
api_register_func('api/account/update_profile_image', 'api_account_update_profile_image', true, API_METHOD_POST);
function check_acl_input($acl_string) {
if ($acl_string == null || $acl_string == " ") {
return false;
}
$contact_not_found = false;
// split <x><y><z> into array of cid's
preg_match_all("/<[A-Za-z0-9]+>/", $acl_string, $array);
// check for each cid if it is available on server
$cid_array = $array[0];
foreach ($cid_array as $cid) {
$cid = str_replace("<", "", $cid);
$cid = str_replace(">", "", $cid);
$contact = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d",
intval($cid),
intval(api_user()));
$contact_not_found |= !dbm::is_result($contact);
}
return $contact_not_found;
}
function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $deny_cid, $allow_gid, $deny_gid, $desc, $profile = 0, $visibility = false, $photo_id = null) {
$visitor = 0;
$src = "";
$filetype = "";
$filename = "";
$filesize = 0;
if (is_array($media)) {
if (is_array($media['tmp_name'])) {
$src = $media['tmp_name'][0];
} else {
$src = $media['tmp_name'];
}
if (is_array($media['name'])) {
$filename = basename($media['name'][0]);
} else {
$filename = basename($media['name']);
}
if (is_array($media['size'])) {
$filesize = intval($media['size'][0]);
} else {
$filesize = intval($media['size']);
}
if (is_array($media['type'])) {
$filetype = $media['type'][0];
} else {
$filetype = $media['type'];
}
}
if ($filetype == "") {
$filetype=guess_image_type($filename);
}
$imagedata = getimagesize($src);
if ($imagedata) {
$filetype = $imagedata['mime'];
}
logger("File upload src: " . $src . " - filename: " . $filename .
" - size: " . $filesize . " - type: " . $filetype, LOGGER_DEBUG);
// check if there was a php upload error
if ($filesize == 0 && $media['error'] == 1) {
throw new InternalServerErrorException("image size exceeds PHP config settings, file was rejected by server");
}
// check against max upload size within Friendica instance
$maximagesize = get_config('system', 'maximagesize');
if (($maximagesize) && ($filesize > $maximagesize)) {
$formattedBytes = formatBytes($maximagesize);
throw new InternalServerErrorException("image size exceeds Friendica config setting (uploaded size: $formattedBytes)");
}
// create Photo instance with the data of the image
$imagedata = @file_get_contents($src);
$ph = new Photo($imagedata, $filetype);
if (! $ph->is_valid()) {
throw new InternalServerErrorException("unable to process image data");
}
// check orientation of image
$ph->orient($src);
@unlink($src);
// check max length of images on server
$max_length = get_config('system', 'max_image_length');
if (! $max_length) {
$max_length = MAX_IMAGE_LENGTH;
}
if ($max_length > 0) {
$ph->scaleImage($max_length);
logger("File upload: Scaling picture to new size " . $max_length, LOGGER_DEBUG);
}
$width = $ph->getWidth();
$height = $ph->getHeight();
// create a new resource-id if not already provided
$hash = ($photo_id == null) ? photo_new_resource() : $photo_id;
if ($mediatype == "photo") {
// upload normal image (scales 0, 1, 2)
logger("photo upload: starting new photo upload", LOGGER_DEBUG);
$r =$ph->store(local_user(), $visitor, $hash, $filename, $album, 0, 0, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
if (! $r) {
logger("photo upload: image upload with scale 0 (original size) failed");
}
if($width > 640 || $height > 640) {
$ph->scaleImage(640);
$r = $ph->store(local_user(),$visitor, $hash, $filename, $album, 1, 0, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
if (! $r) {
logger("photo upload: image upload with scale 1 (640x640) failed");
}
}
if ($width > 320 || $height > 320) {
$ph->scaleImage(320);
$r = $ph->store(local_user(), $visitor, $hash, $filename, $album, 2, 0, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
if (! $r) {
logger("photo upload: image upload with scale 2 (320x320) failed");
}
}
logger("photo upload: new photo upload ended", LOGGER_DEBUG);
} elseif ($mediatype == "profileimage") {
// upload profile image (scales 4, 5, 6)
logger("photo upload: starting new profile image upload", LOGGER_DEBUG);
if ($width > 175 || $height > 175) {
$ph->scaleImage(175);
$r = $ph->store(local_user(),$visitor, $hash, $filename, $album, 4, $profile, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
if (! $r) {
logger("photo upload: profile image upload with scale 4 (175x175) failed");
}
}
if ($width > 80 || $height > 80) {
$ph->scaleImage(80);
$r = $ph->store(local_user(),$visitor, $hash, $filename, $album, 5, $profile, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
if (! $r) {
logger("photo upload: profile image upload with scale 5 (80x80) failed");
}
}
if ($width > 48 || $height > 48) {
$ph->scaleImage(48);
$r = $ph->store(local_user(), $visitor, $hash, $filename, $album, 6, $profile, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
if (! $r) {
logger("photo upload: profile image upload with scale 6 (48x48) failed");
}
}
$ph->__destruct();
logger("photo upload: new profile image upload ended", LOGGER_DEBUG);
}
if ($r) {
// create entry in 'item'-table on new uploads to enable users to comment/like/dislike the photo
if ($photo_id == null && $mediatype == "photo") {
post_photo_item($hash, $allow_cid, $deny_cid, $allow_gid, $deny_gid, $filetype, $visibility);
}
// on success return image data in json/xml format (like /api/friendica/photo does when no scale is given)
return prepare_photo_data($type, false, $hash);
} else {
throw new InternalServerErrorException("image upload failed");
}
}
function post_photo_item($hash, $allow_cid, $deny_cid, $allow_gid, $deny_gid, $filetype, $visibility = false) {
// get data about the api authenticated user
$uri = item_new_uri(get_app()->get_hostname(), intval(api_user()));
$owner_record = q("SELECT * FROM `contact` WHERE `uid`= %d AND `self` LIMIT 1", intval(api_user()));
$arr = array();
$arr['guid'] = get_guid(32);
$arr['uid'] = intval(api_user());
$arr['uri'] = $uri;
$arr['parent-uri'] = $uri;
$arr['type'] = 'photo';
$arr['wall'] = 1;
$arr['resource-id'] = $hash;
$arr['contact-id'] = $owner_record[0]['id'];
$arr['owner-name'] = $owner_record[0]['name'];
$arr['owner-link'] = $owner_record[0]['url'];
$arr['owner-avatar'] = $owner_record[0]['thumb'];
$arr['author-name'] = $owner_record[0]['name'];
$arr['author-link'] = $owner_record[0]['url'];
$arr['author-avatar'] = $owner_record[0]['thumb'];
$arr['title'] = "";
$arr['allow_cid'] = $allow_cid;
$arr['allow_gid'] = $allow_gid;
$arr['deny_cid'] = $deny_cid;
$arr['deny_gid'] = $deny_gid;
$arr['last-child'] = 1;
$arr['visible'] = $visibility;
$arr['origin'] = 1;
$typetoext = array(
'image/jpeg' => 'jpg',
'image/png' => 'png',
'image/gif' => 'gif'
);
// adds link to the thumbnail scale photo
$arr['body'] = '[url=' . App::get_baseurl() . '/photos/' . $owner_record[0]['name'] . '/image/' . $hash . ']'
. '[img]' . App::get_baseurl() . '/photo/' . $hash . '-' . "2" . '.'. $typetoext[$filetype] . '[/img]'
. '[/url]';
// do the magic for storing the item in the database and trigger the federation to other contacts
item_store($arr);
}
function prepare_photo_data($type, $scale, $photo_id) {
$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
// clients needs to convert this in their way for further processing
$r = q("SELECT %s `resource-id`, `created`, `edited`, `title`, `desc`, `album`, `filename`,
`type`, `height`, `width`, `datasize`, `profile`, `allow_cid`, `deny_cid`, `allow_gid`, `deny_gid`,
MIN(`scale`) AS `minscale`, MAX(`scale`) AS `maxscale`
FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' %s GROUP BY `resource-id`",
$data_sql,
intval(local_user()),
dbesc($_REQUEST['photo_id']),
dbesc($photo_id),
$scale_sql
);
@ -3341,6 +3995,7 @@ $called_api = null;
'image/gif' => 'gif'
);
// prepare output data for photo
if (dbm::is_result($r)) {
$data = array('photo' => $r[0]);
$data['photo']['id'] = $data['photo']['resource-id'];
@ -3353,13 +4008,16 @@ $called_api = null;
$data['photo']['links'] = array();
for ($k = intval($data['photo']['minscale']); $k <= intval($data['photo']['maxscale']); $k++) {
$data['photo']['links'][$k . ":link"]["@attributes"] = array("type" => $data['photo']['type'],
"scale" => $k,
"href" => App::get_baseurl() . "/photo/" . $data['photo']['resource-id'] . "-" . $k . "." . $typetoext[$data['photo']['type']]);
"scale" => $k,
"href" => App::get_baseurl() . "/photo/" . $data['photo']['resource-id'] . "-" . $k . "." . $typetoext[$data['photo']['type']]);
}
} else {
$data['photo']['link'] = array();
// when we have profile images we could have only scales from 4 to 6, but index of array always needs to start with 0
$i = 0;
for ($k = intval($data['photo']['minscale']); $k <= intval($data['photo']['maxscale']); $k++) {
$data['photo']['link'][$k] = App::get_baseurl() . "/photo/" . $data['photo']['resource-id'] . "-" . $k . "." . $typetoext[$data['photo']['type']];
$data['photo']['link'][$i] = App::get_baseurl() . "/photo/" . $data['photo']['resource-id'] . "-" . $k . "." . $typetoext[$data['photo']['type']];
$i++;
}
}
unset($data['photo']['resource-id']);
@ -3370,13 +4028,54 @@ $called_api = null;
throw new NotFoundException();
}
return api_format_data("photo_detail", $type, $data);
// retrieve item element for getting activities (like, dislike etc.) related to photo
$item = q("SELECT * FROM `item` WHERE `uid` = %d AND `resource-id` = '%s' AND `type` = 'photo'",
intval(local_user()),
dbesc($photo_id)
);
$data['photo']['friendica_activities'] = api_format_items_activities($item[0], $type);
// retrieve comments on photo
$r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
`contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
`contact`.`id` AS `cid`
FROM `item`
STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND `contact`.`uid` = `item`.`uid`
AND (NOT `contact`.`blocked` OR `contact`.`pending`)
WHERE `item`.`parent` = %d AND `item`.`visible`
AND NOT `item`.`moderated` AND NOT `item`.`deleted`
AND `item`.`uid` = %d AND (`item`.`verb`='%s' OR `type`='photo')",
intval($item[0]['parent']),
intval(api_user()),
dbesc(ACTIVITY_POST)
);
// prepare output of comments
$commentData = api_format_items($r, api_get_user(get_app()), false, $type);
$comments = array();
if ($type == "xml") {
$k = 0;
foreach ($commentData as $comment) {
$comments[$k++ . ":comment"] = $comment;
}
} else {
foreach ($commentData as $comment) {
$comments[] = $comment;
}
}
$data['photo']['friendica_comments'] = $comments;
// include info if rights on photo and rights on item are mismatching
$rights_mismatch = $data['photo']['allow_cid'] != $item[0]['allow_cid'] ||
$data['photo']['deny_cid'] != $item[0]['deny_cid'] ||
$data['photo']['allow_gid'] != $item[0]['allow_gid'] ||
$data['photo']['deny_cid'] != $item[0]['deny_cid'];
$data['photo']['rights_mismatch'] = $rights_mismatch;
return $data;
}
api_register_func('api/friendica/photos/list', 'api_fr_photos_list', true);
api_register_func('api/friendica/photo', 'api_fr_photo_detail', true);
/**
* similar as /mod/redir.php
@ -4299,7 +4998,6 @@ friendships/exists
friendships/show
account/update_location
account/update_profile_background_image
account/update_profile_image
blocks/create
blocks/destroy
friendica/profile/update

View file

@ -1,6 +1,7 @@
<?php
use \Friendica\Core\Config;
use Friendica\App;
use Friendica\Core\Config;
require_once('include/security.php');
require_once('include/datetime.php');

View file

@ -32,6 +32,8 @@
*
*/
use Friendica\App;
if (sizeof($_SERVER["argv"]) == 0)
die();
@ -47,8 +49,9 @@ require_once("boot.php");
global $a, $db;
if (is_null($a))
$a = new App;
if (is_null($a)) {
$a = new App(dirname(__DIR__));
}
if (is_null($db)) {
@include(".htconfig.php");
@ -332,4 +335,3 @@ class exAuth {
fclose($this->rLogFile);
}
}
?>

View file

@ -1,12 +1,15 @@
<?php
use Friendica\App;
use Friendica\Network\Probe;
use League\HTMLToMarkdown\HtmlConverter;
require_once "include/oembed.php";
require_once "include/event.php";
require_once "library/markdown.php";
require_once "include/html2bbcode.php";
require_once "include/bbcode.php";
require_once 'include/oembed.php';
require_once 'include/event.php';
require_once 'library/markdown.php';
require_once 'include/html2bbcode.php';
require_once 'include/bbcode.php';
/**
* @brief Callback function to replace a Diaspora style mention in a mention for Friendica

View file

@ -1,5 +1,7 @@
<?php
use \Friendica\Core\Config;
use Friendica\App;
use Friendica\Core\Config;
require_once 'include/oembed.php';
require_once 'include/event.php';
@ -53,18 +55,7 @@ function bb_attachment($Text, $simplehtml = false, $tryoembed = true) {
}
if ($simplehtml == 7) {
$title2 = $data["title"];
$test1 = trim(html_entity_decode($data["text"],ENT_QUOTES,'UTF-8'));
$test2 = trim(html_entity_decode($data["title"],ENT_QUOTES,'UTF-8'));
// If the link description is similar to the text above then don't add the link description
if (($data["title"] != "") AND ((strpos($test1,$test2) !== false) OR
(similar_text($test1,$test2) / strlen($data["title"])) > 0.9)) {
$title2 = $data["url"];
}
$text = sprintf('<a href="%s" title="%s" class="attachment" rel="nofollow external">%s</a><br />',
$data["url"], $data["title"], $title2);
$text = style_url_for_mastodon($data["url"]);
} elseif (($simplehtml != 4) AND ($simplehtml != 0)) {
$text = sprintf('<a href="%s" target="_blank">%s</a><br>', $data["url"], $data["title"]);
} else {
@ -168,6 +159,54 @@ function cleancss($input) {
return $cleaned;
}
/**
* @brief Converts [url] BBCodes in a format that looks fine on Mastodon. (callback function)
* @param array $match Array with the matching values
* @return string reformatted link including HTML codes
*/
function bb_style_url($match) {
$url = $match[1];
if (isset($match[2]) AND ($match[1] != $match[2])) {
return $match[0];
}
$parts = parse_url($url);
if (!isset($parts['scheme'])) {
return $match[0];
}
return style_url_for_mastodon($url);
}
/**
* @brief Converts [url] BBCodes in a format that looks fine on Mastodon and GNU Social.
* @param string $url URL that is about to be reformatted
* @return string reformatted link including HTML codes
*/
function style_url_for_mastodon($url) {
$styled_url = $url;
$parts = parse_url($url);
$scheme = $parts['scheme'].'://';
$styled_url = str_replace($scheme, '', $styled_url);
$html = '<a href="%s" class="attachment" rel="nofollow noopener" target="_blank">'.
'<span class="invisible">%s</span>';
if (strlen($styled_url) > 30) {
$html .= '<span class="ellipsis">%s</span>'.
'<span class="invisible">%s</span></a>';
$ellipsis = substr($styled_url, 0, 30);
$rest = substr($styled_url, 30);
return sprintf($html, $url, $scheme, $ellipsis, $rest);
} else {
$html .= '%s</a>';
return sprintf($html, $url, $scheme, $styled_url);
}
}
function stripcode_br_cb($s) {
return '[code]' . str_replace('<br />', '', $s[1]) . '[/code]';
}
@ -940,7 +979,14 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = fa
// if the HTML is used to generate plain text, then don't do this search, but replace all URL of that kind to text
// if ($simplehtml != 7) {
if (!$forplaintext) {
$Text = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1<a href="$2" target="_blank">$2</a>', $Text);
if ($simplehtml != 7) {
$Text = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1<a href="$2" target="_blank">$2</a>', $Text);
} else {
$Text = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1[url]$2[/url]', $Text);
$Text = preg_replace_callback("/\[url\]([$URLSearchString]*)\[\/url\]/ism", 'bb_style_url', $Text);
$Text = preg_replace_callback("/\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[\/url\]/ism", 'bb_style_url', $Text);
}
} else {
$Text = preg_replace("(\[url\]([$URLSearchString]*)\[\/url\])ism", " $1 ", $Text);
$Text = preg_replace_callback("&\[url=([^\[\]]*)\]\[img\](.*)\[\/img\]\[\/url\]&Usi", 'bb_RemovePictureLinks', $Text);

View file

@ -5,8 +5,8 @@
* @brief Class for storing data for a short time
*/
use \Friendica\Core\Config;
use \Friendica\Core\PConfig;
use Friendica\Core\Config;
use Friendica\Core\PConfig;
class Cache {
/**
@ -121,9 +121,9 @@ class Cache {
/**
* @brief Put data in the cache according to the key
*
*
* The input $value can have multiple formats.
*
*
* @param string $key The key to the cached data
* @param mixed $valie The value that is about to be stored
* @param integer $duration The cache lifespan

View file

@ -1,6 +1,7 @@
<?php /** @file */
use \Friendica\Core\Config;
use Friendica\App;
use Friendica\Core\Config;
require_once('boot.php');
@ -11,7 +12,7 @@ function cli_startup() {
global $a, $db;
if (is_null($a)) {
$a = new App;
$a = new App(dirname(__DIR__));
}
if (is_null($db)) {

View file

@ -1,7 +1,7 @@
<?php
/**
* @file include/config.php
*
*
* @brief (Deprecated) Arbitrary configuration storage
* Note:
* Please do not store booleans - convert to 0/1 integer values
@ -12,8 +12,8 @@
* configurations need to be fixed as of 10/08/2011.
*/
use \Friendica\Core\Config;
use \Friendica\Core\PConfig;
use Friendica\Core\Config;
use Friendica\Core\PConfig;
/**
* @brief (Deprecated) Loads all configuration values of family into a cached storage.

View file

@ -1,5 +1,7 @@
<?php
use Friendica\App;
function follow_widget($value = "") {
return replace_macros(get_markup_template('follow.tpl'), array(

View file

@ -1,9 +1,10 @@
<?php
use Friendica\App;
require_once "include/bbcode.php";
require_once "include/acl_selectors.php";
/*
* Note: the code in 'item_extract_images' and 'item_redir_and_replace_images'
* is identical to the code in mod/message.php for 'item_extract_images' and

View file

@ -17,4 +17,3 @@ function create_shadowentry_run($argv, $argc) {
add_shadow_entry($message_id);
}
?>

View file

@ -1,5 +1,6 @@
<?php
use \Friendica\Core\Config;
use Friendica\Core\Config;
function cron_run(&$argv, &$argc){
global $a;

View file

@ -1,6 +1,6 @@
<?php
use \Friendica\Core\Config;
use Friendica\Core\Config;
function cronhooks_run(&$argv, &$argc) {
global $a;

View file

@ -1,17 +1,19 @@
<?php
use \Friendica\Core\Config;
use Friendica\App;
use Friendica\Core\Config;
use Friendica\Network\Probe;
function cronjobs_run(&$argv, &$argc){
global $a;
require_once('include/datetime.php');
require_once('include/ostatus.php');
require_once('include/post_update.php');
require_once('mod/nodeinfo.php');
require_once('include/photos.php');
require_once('include/user.php');
require_once('include/socgraph.php');
require_once('include/Probe.php');
require_once 'include/datetime.php';
require_once 'include/ostatus.php';
require_once 'include/post_update.php';
require_once 'mod/nodeinfo.php';
require_once 'include/photos.php';
require_once 'include/user.php';
require_once 'include/socgraph.php';
// No parameter set? So return
if ($argc <= 1) {

View file

@ -4,7 +4,7 @@
* @brief Some functions for date and time related tasks.
*/
use \Friendica\Core\Config;
use Friendica\Core\Config;
/**
* @brief Two-level sort for timezones.
@ -34,7 +34,7 @@ function timezone_cmp($a, $b) {
/**
* @brief Emit a timezone selector grouped (primarily) by continent
*
*
* @param string $current Timezone
* @return string Parsed HTML output
*/
@ -81,17 +81,17 @@ function select_timezone($current = 'America/Los_Angeles') {
/**
* @brief Generating a Timezone selector
*
*
* Return a select using 'field_select_raw' template, with timezones
* groupped (primarily) by continent
* arguments follow convetion as other field_* template array:
* 'name', 'label', $value, 'help'
*
*
* @param string $name Name of the selector
* @param string $label Label for the selector
* @param string $current Timezone
* @param string $help Help text
*
*
* @return string Parsed HTML
*/
function field_timezone($name='timezone', $label='', $current = 'America/Los_Angeles', $help){
@ -114,7 +114,7 @@ function field_timezone($name='timezone', $label='', $current = 'America/Los_Ang
* @param string $s Some parseable date/time string
* @param string $fmt Output format recognised from php's DateTime class
* http://www.php.net/manual/en/datetime.format.php
*
*
* @return string Formatted date according to given format
*/
function datetime_convert($from = 'UTC', $to = 'UTC', $s = 'now', $fmt = "Y-m-d H:i:s") {
@ -212,7 +212,7 @@ function dob($dob) {
/**
* @brief Returns a date selector
*
*
* @param string $format
* Format string, e.g. 'ymd' or 'mdy'. Not currently supported
* @param string $min
@ -223,7 +223,7 @@ function dob($dob) {
* Unix timestamp of default date
* @param string $id
* ID and name of datetimepicker (defaults to "datetimepicker")
*
*
* @return string Parsed HTML output.
*/
function datesel($format, $min, $max, $default, $id = 'datepicker') {
@ -232,7 +232,7 @@ function datesel($format, $min, $max, $default, $id = 'datepicker') {
/**
* @brief Returns a time selector
*
*
* @param string $format
* Format string, e.g. 'ymd' or 'mdy'. Not currently supported
* @param $h
@ -241,7 +241,7 @@ function datesel($format, $min, $max, $default, $id = 'datepicker') {
* Already selected minute
* @param string $id
* ID and name of datetimepicker (defaults to "timepicker")
*
*
* @return string Parsed HTML output.
*/
function timesel($format, $h, $m, $id = 'timepicker') {
@ -270,7 +270,7 @@ function timesel($format, $h, $m, $id = 'timepicker') {
* @param $maxfrom
* set maximum date from picker with id $maxfrom (none by default)
* @param bool $required default false
*
*
* @return string Parsed HTML output.
*
* @todo Once browser support is better this could probably be replaced with
@ -417,7 +417,7 @@ function relative_date($posted_date, $format = null) {
* @param string $dob Date of Birth
* @param string $owner_tz (optional) Timezone of the person of interest
* @param string $viewer_tz (optional) Timezone of the person viewing
*
*
* @return int Age in years
*/
function age($dob, $owner_tz = '', $viewer_tz = '') {
@ -452,7 +452,7 @@ function age($dob, $owner_tz = '', $viewer_tz = '') {
*
* @param int $y Year
* @param int $m Month (1=January, 12=December)
*
*
* @return int Number of days in the given month
*/
function get_dim($y, $m) {
@ -477,7 +477,7 @@ function get_dim($y, $m) {
*
* @param int $y Year
* @param int $m Month (1=January, 12=December)
*
*
* @return string day 0 = Sunday through 6 = Saturday
*/
function get_first_dim($y,$m) {
@ -498,7 +498,7 @@ function get_first_dim($y,$m) {
* @param int $m Month
* @param bool $links (default false)
* @param string $class
*
*
* @return string
*
* @todo Provide (prev,next) links, define class variations for different size calendars

View file

@ -10,6 +10,7 @@ require_once('include/datetime.php');
* When logging, all binary info is converted to text and html entities are escaped so that
* the debugging stream is safe to view within both terminals and web pages.
*
* This class is for the low level database stuff that does driver specific things.
*/
class dba {
@ -21,12 +22,23 @@ class dba {
public $connected = false;
public $error = false;
private $_server_info = '';
private static $dbo;
private static $relation = array();
function __construct($server, $user, $pass, $db, $install = false) {
function __construct($serveraddr, $user, $pass, $db, $install = false) {
$a = get_app();
$stamp1 = microtime(true);
$serveraddr = trim($serveraddr);
$serverdata = explode(':', $serveraddr);
$server = $serverdata[0];
if (count($serverdata) > 1) {
$port = trim($serverdata[1]);
}
$server = trim($server);
$user = trim($user);
$pass = trim($pass);
@ -52,6 +64,11 @@ class dba {
if (class_exists('\PDO') && in_array('mysql', PDO::getAvailableDrivers())) {
$this->driver = 'pdo';
$connect = "mysql:host=".$server.";dbname=".$db;
if (isset($port)) {
$connect .= ";port=".$port;
}
if (isset($a->config["system"]["db_charset"])) {
$connect .= ";charset=".$a->config["system"]["db_charset"];
}
@ -61,7 +78,7 @@ class dba {
}
} elseif (class_exists('mysqli')) {
$this->driver = 'mysqli';
$this->db = @new mysqli($server,$user,$pass,$db);
$this->db = @new mysqli($server, $user, $pass, $db, $port);
if (!mysqli_connect_errno()) {
$this->connected = true;
@ -71,8 +88,8 @@ class dba {
}
} elseif (function_exists('mysql_connect')) {
$this->driver = 'mysql';
$this->db = mysql_connect($server,$user,$pass);
if ($this->db && mysql_select_db($db,$this->db)) {
$this->db = mysql_connect($serveraddr, $user, $pass);
if ($this->db && mysql_select_db($db, $this->db)) {
$this->connected = true;
if (isset($a->config["system"]["db_charset"])) {
@ -93,6 +110,8 @@ class dba {
}
}
$a->save_timestamp($stamp1, "network");
self::$dbo = $this;
}
/**
@ -131,30 +150,6 @@ class dba {
return $r[0]['db'];
}
/**
* @brief Returns the number of rows
*
* @return integer
*/
public function num_rows() {
if (!$this->result) {
return 0;
}
switch ($this->driver) {
case 'pdo':
$rows = $this->result->rowCount();
break;
case 'mysqli':
$rows = $this->result->num_rows;
break;
case 'mysql':
$rows = mysql_num_rows($this->result);
break;
}
return $rows;
}
/**
* @brief Analyze a database query and log this if some conditions are met.
*
@ -249,7 +244,7 @@ class dba {
break;
}
$stamp2 = microtime(true);
$duration = (float)($stamp2-$stamp1);
$duration = (float)($stamp2 - $stamp1);
$a->save_timestamp($stamp1, "database");
@ -379,41 +374,6 @@ class dba {
return($r);
}
public function qfetch() {
$x = false;
if ($this->result) {
switch ($this->driver) {
case 'pdo':
$x = $this->result->fetch(PDO::FETCH_ASSOC);
break;
case 'mysqli':
$x = $this->result->fetch_array(MYSQLI_ASSOC);
break;
case 'mysql':
$x = mysql_fetch_array($this->result, MYSQL_ASSOC);
break;
}
}
return($x);
}
public function qclose() {
if ($this->result) {
switch ($this->driver) {
case 'pdo':
$this->result->closeCursor();
break;
case 'mysqli':
$this->result->free_result();
break;
case 'mysql':
mysql_free_result($this->result);
break;
}
}
}
public function dbg($dbg) {
$this->debug = $dbg;
}
@ -497,6 +457,656 @@ class dba {
}
return $sql;
}
/**
* @brief Replaces the ? placeholders with the parameters in the $args array
*
* @param string $sql SQL query
* @param array $args The parameters that are to replace the ? placeholders
* @return string The replaced SQL query
*/
static private function replace_parameters($sql, $args) {
$offset = 0;
foreach ($args AS $param => $value) {
if (is_int($args[$param]) OR is_float($args[$param])) {
$replace = intval($args[$param]);
} else {
$replace = "'".self::$dbo->escape($args[$param])."'";
}
$pos = strpos($sql, '?', $offset);
if ($pos !== false) {
$sql = substr_replace($sql, $replace, $pos, 1);
}
$offset = $pos + strlen($replace);
}
return $sql;
}
/**
* @brief Executes a prepared statement that returns data
* @usage Example: $r = p("SELECT * FROM `item` WHERE `guid` = ?", $guid);
* @param string $sql SQL statement
* @return object statement object
*/
static public function p($sql) {
$a = get_app();
$stamp1 = microtime(true);
$args = func_get_args();
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]))) {
$params = $args[1];
} else {
$params = $args;
}
// Renumber the array keys to be sure that they fit
$i = 0;
$args = array();
foreach ($params AS $param) {
$args[++$i] = $param;
}
if (!self::$dbo OR !self::$dbo->connected) {
return false;
}
if (substr_count($sql, '?') != count($args)) {
// Question: Should we continue or stop the query here?
logger('Parameter mismatch. Query "'.$sql.'" - Parameters '.print_r($args, true), LOGGER_DEBUG);
}
$sql = self::$dbo->any_value_fallback($sql);
if (x($a->config,'system') && x($a->config['system'], 'db_callstack')) {
$sql = "/*".$a->callstack()." */ ".$sql;
}
self::$dbo->error = '';
self::$dbo->errorno = 0;
switch (self::$dbo->driver) {
case 'pdo':
if (!$stmt = self::$dbo->db->prepare($sql)) {
$errorInfo = self::$dbo->db->errorInfo();
self::$dbo->error = $errorInfo[2];
self::$dbo->errorno = $errorInfo[1];
$retval = false;
break;
}
foreach ($args AS $param => $value) {
$stmt->bindParam($param, $args[$param]);
}
if (!$stmt->execute()) {
$errorInfo = $stmt->errorInfo();
self::$dbo->error = $errorInfo[2];
self::$dbo->errorno = $errorInfo[1];
$retval = false;
} else {
$retval = $stmt;
}
break;
case 'mysqli':
$stmt = self::$dbo->db->stmt_init();
if (!$stmt->prepare($sql)) {
self::$dbo->error = $stmt->error;
self::$dbo->errorno = $stmt->errno;
$retval = false;
break;
}
$params = '';
$values = array();
foreach ($args AS $param => $value) {
if (is_int($args[$param])) {
$params .= 'i';
} elseif (is_float($args[$param])) {
$params .= 'd';
} elseif (is_string($args[$param])) {
$params .= 's';
} else {
$params .= 'b';
}
$values[] = &$args[$param];
}
if (count($values) > 0) {
array_unshift($values, $params);
call_user_func_array(array($stmt, 'bind_param'), $values);
}
if (!$stmt->execute()) {
self::$dbo->error = self::$dbo->db->error;
self::$dbo->errorno = self::$dbo->db->errno;
$retval = false;
} else {
$stmt->store_result();
$retval = $stmt;
}
break;
case 'mysql':
// For the old "mysql" functions we cannot use prepared statements
$retval = mysql_query(self::replace_parameters($sql, $args), self::$dbo->db);
if (mysql_errno(self::$dbo->db)) {
self::$dbo->error = mysql_error(self::$dbo->db);
self::$dbo->errorno = mysql_errno(self::$dbo->db);
}
break;
}
if (self::$dbo->errorno != 0) {
logger('DB Error '.self::$dbo->errorno.': '.self::$dbo->error."\n".self::replace_parameters($sql, $args));
}
$a->save_timestamp($stamp1, 'database');
if (x($a->config,'system') && x($a->config['system'], 'db_log')) {
$stamp2 = microtime(true);
$duration = (float)($stamp2 - $stamp1);
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(self::replace_parameters($sql, $args), 0, 2000)."\n", FILE_APPEND);
}
}
return $retval;
}
/**
* @brief Executes a prepared statement like UPDATE or INSERT that doesn't return data
*
* @param string $sql SQL statement
* @return boolean Was the query successfull? False is returned only if an error occurred
*/
static public function e($sql) {
$a = get_app();
$stamp = microtime(true);
$args = func_get_args();
$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);
$a->save_timestamp($stamp, "database_write");
return $retval;
}
/**
* @brief Check if data exists
*
* @param string $sql SQL statement
* @return boolean Are there rows for that query?
*/
static public function exists($sql) {
$args = func_get_args();
$stmt = call_user_func_array('self::p', $args);
if (is_bool($stmt)) {
$retval = $stmt;
} else {
$retval = (self::num_rows($stmt) > 0);
}
self::close($stmt);
return $retval;
}
/**
* @brief Fetches the first row
*
* @param string $sql SQL statement
* @return array first row of query
*/
static public function fetch_first($sql) {
$args = func_get_args();
$stmt = call_user_func_array('self::p', $args);
if (is_bool($stmt)) {
$retval = $stmt;
} else {
$retval = self::fetch($stmt);
}
self::close($stmt);
return $retval;
}
/**
* @brief Returns the number of rows of a statement
*
* @param object Statement object
* @return int Number of rows
*/
static public function num_rows($stmt) {
switch (self::$dbo->driver) {
case 'pdo':
return $stmt->rowCount();
case 'mysqli':
return $stmt->num_rows;
case 'mysql':
return mysql_num_rows($stmt);
}
return 0;
}
/**
* @brief Fetch a single row
*
* @param object $stmt statement object
* @return array current row
*/
static public function fetch($stmt) {
if (!is_object($stmt)) {
return false;
}
switch (self::$dbo->driver) {
case 'pdo':
return $stmt->fetch(PDO::FETCH_ASSOC);
case 'mysqli':
// This code works, but is slow
// Bind the result to a result array
$cols = array();
$cols_num = array();
for ($x = 0; $x < $stmt->field_count; $x++) {
$cols[] = &$cols_num[$x];
}
call_user_func_array(array($stmt, 'bind_result'), $cols);
if (!$stmt->fetch()) {
return false;
}
// The slow part:
// We need to get the field names for the array keys
// It seems that there is no better way to do this.
$result = $stmt->result_metadata();
$fields = $result->fetch_fields();
$columns = array();
foreach ($cols_num AS $param => $col) {
$columns[$fields[$param]->name] = $col;
}
return $columns;
case 'mysql':
return mysql_fetch_array(self::$dbo->result, MYSQL_ASSOC);
}
}
/**
* @brief Insert a row into a table
*
* @param string $table Table name
* @param array $param parameter array
*
* @return boolean was the insert successfull?
*/
static public function insert($table, $param) {
$sql = "INSERT INTO `".self::$dbo->escape($table)."` (`".implode("`, `", array_keys($param))."`) VALUES (".
substr(str_repeat("?, ", count($param)), 0, -2).");";
return self::e($sql, $param);
}
/**
* @brief Build the array with the table relations
*
* The array is build from the database definitions in dbstructure.php
*
* This process must only be started once, since the value is cached.
*/
static private function build_relation_data() {
$definition = db_definition();
foreach ($definition AS $table => $structure) {
foreach ($structure['fields'] AS $field => $field_struct) {
if (isset($field_struct['relation'])) {
foreach ($field_struct['relation'] AS $rel_table => $rel_field) {
self::$relation[$rel_table][$rel_field][$table][] = $field;
}
}
}
}
}
/**
* @brief Insert a row into a table
*
* @param string $table Table name
* @param array $param parameter array
* @param boolean $in_commit Internal use: Only do a commit after the last delete
* @param array $callstack Internal use: prevent endless loops
*
* @return boolean|array was the delete successfull? When $in_commit is set: deletion data
*/
static public function delete($table, $param, $in_commit = false, &$callstack = array()) {
$commands = array();
// Create a key for the loop prevention
$key = $table.':'.implode(':', array_keys($param)).':'.implode(':', $param);
// We quit when this key already exists in the callstack.
if (isset($callstack[$key])) {
return $commands;
}
$callstack[$key] = true;
$table = self::$dbo->escape($table);
$commands[$key] = array('table' => $table, 'param' => $param);
// To speed up the whole process we cache the table relations
if (count(self::$relation) == 0) {
self::build_relation_data();
}
// Is there a relation entry for the table?
if (isset(self::$relation[$table])) {
// We only allow a simple "one field" relation.
$field = array_keys(self::$relation[$table])[0];
$rel_def = array_values(self::$relation[$table])[0];
// Create a key for preventing double queries
$qkey = $field.'-'.$table.':'.implode(':', array_keys($param)).':'.implode(':', $param);
// 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])) {
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);
$commands = array_merge($commands, $retval);
}
}
// We quit when this key already exists in the callstack.
} elseif (!isset($callstack[$qkey])) {
$callstack[$qkey] = true;
// Fetch all rows that are to be deleted
$sql = "SELECT ".self::$dbo->escape($field)." FROM `".$table."` WHERE `".
implode("` = ? AND `", array_keys($param))."` = ?";
$data = self::p($sql, $param);
while ($row = self::fetch($data)) {
// Now we accumulate the delete commands
$retval = self::delete($table, array($field => $row[$field]), true, $callstack);
$commands = array_merge($commands, $retval);
}
// Since we had split the delete command we don't need the original command anymore
unset($commands[$key]);
}
}
if (!$in_commit) {
// Now we finalize the process
self::p("COMMIT");
self::p("START TRANSACTION");
$compacted = array();
$counter = array();
foreach ($commands AS $command) {
if (count($command['param']) > 1) {
$sql = "DELETE FROM `".$command['table']."` WHERE `".
implode("` = ? AND `", array_keys($command['param']))."` = ?";
logger(dba::replace_parameters($sql, $command['param']), LOGGER_DATA);
if (!self::e($sql, $command['param'])) {
self::p("ROLLBACK");
return false;
}
} else {
$key_table = $command['table'];
$key_param = array_keys($command['param'])[0];
$value = array_values($command['param'])[0];
// Split the SQL queries in chunks of 100 values
// We do the $i stuff here to make the code better readable
$i = $counter[$key_table][$key_param];
if (count($compacted[$key_table][$key_param][$i]) > 100) {
++$i;
}
$compacted[$key_table][$key_param][$i][$value] = $value;
$counter[$key_table][$key_param] = $i;
}
}
foreach ($compacted AS $table => $values) {
foreach ($values AS $field => $field_value_list) {
foreach ($field_value_list AS $field_values) {
$sql = "DELETE FROM `".$table."` WHERE `".$field."` IN (".
substr(str_repeat("?, ", count($field_values)), 0, -2).");";
logger(dba::replace_parameters($sql, $field_values), LOGGER_DATA);
if (!self::e($sql, $field_values)) {
self::p("ROLLBACK");
return false;
}
}
}
}
self::p("COMMIT");
return true;
}
return $commands;
}
/**
* @brief Updates rows
*
* Updates rows in the database. When $old_fields is set to an array,
* the system will only do an update if the fields in that array changed.
*
* Attention:
* Only the values in $old_fields are compared.
* This is an intentional behaviour.
*
* Example:
* We include the timestamp field in $fields but not in $old_fields.
* Then the row will only get the new timestamp when the other fields had changed.
*
* When $old_fields is set to a boolean value the system will do this compare itself.
* When $old_fields is set to "true" the system will do an insert if the row doesn't exists.
*
* Attention:
* Only set $old_fields to a boolean value when you are sure that you will update a single row.
* When you set $old_fields to "true" then $fields must contain all relevant fields!
*
* @param string $table Table name
* @param array $fields contains the fields that are updated
* @param array $condition condition array with the key values
* @param array|boolean $old_fields array with the old field values that are about to be replaced
*
* @return boolean was the update successfull?
*/
static public function update($table, $fields, $condition, $old_fields = array()) {
/** @todo We may use MySQL specific functions here:
* INSERT INTO `config` (`cat`, `k`, `v`) VALUES ('%s', '%s', '%s') ON DUPLICATE KEY UPDATE `v` = '%s'"
* But I think that it doesn't make sense here.
*/
$table = self::$dbo->escape($table);
if (is_bool($old_fields)) {
$sql = "SELECT * FROM `".$table."` WHERE `".
implode("` = ? AND `", array_keys($condition))."` = ? LIMIT 1";
$params = array();
foreach ($condition AS $value) {
$params[] = $value;
}
$do_insert = $old_fields;
$old_fields = self::fetch_first($sql, $params);
if (is_bool($old_fields)) {
if ($do_insert) {
return self::insert($table, $fields);
}
$old_fields = array();
}
}
$do_update = (count($old_fields) == 0);
foreach ($old_fields AS $fieldname => $content) {
if (isset($fields[$fieldname])) {
if ($fields[$fieldname] == $content) {
unset($fields[$fieldname]);
} else {
$do_update = true;
}
}
}
if (!$do_update OR (count($fields) == 0)) {
return true;
}
$sql = "UPDATE `".$table."` SET `".
implode("` = ?, `", array_keys($fields))."` = ? WHERE `".
implode("` = ? AND `", array_keys($condition))."` = ?";
$params = array();
foreach ($fields AS $value) {
$params[] = $value;
}
foreach ($condition AS $value) {
$params[] = $value;
}
return self::e($sql, $params);
}
/**
* @brief Select rows from a table
*
* @param string $table Table name
* @param array $fields array of selected fields
* @param array $condition array of fields for condition
* @param array $params array of several parameters
*
* @return boolean|object If "limit" is equal "1" only a single row is returned, else a query object is returned
*
* Example:
* $table = "item";
* $fields = array("id", "uri", "uid", "network");
* $condition = array("uid" => 1, "network" => 'dspr');
* $params = array("order" => array("id", "received" => true), "limit" => 1);
*
* $data = dba::select($table, $fields, $condition, $params);
*/
static public function select($table, $fields = array(), $condition = array(), $params = array()) {
if ($table == '') {
return false;
}
if (count($fields) > 0) {
$select_fields = "`".implode("`, `", array_values($fields))."`";
} else {
$select_fields = "*";
}
if (count($condition) > 0) {
$condition_string = " WHERE `".implode("` = ? AND `", array_keys($condition))."` = ?";
} else {
$condition_string = "";
}
$param_string = '';
$single_row = false;
if (isset($params['order'])) {
$param_string .= " ORDER BY ";
foreach ($params['order'] AS $fields => $order) {
if (!is_int($fields)) {
$param_string .= "`".$fields."` ".($order ? "DESC" : "ASC").", ";
} else {
$param_string .= "`".$order."`, ";
}
}
$param_string = substr($param_string, 0, -2);
}
if (isset($params['limit'])) {
if (is_int($params['limit'])) {
$param_string .= " LIMIT ".$params['limit'];
$single_row =($params['limit'] == 1);
}
}
$sql = "SELECT ".$select_fields." FROM `".$table."`".$condition_string.$param_string;
$result = self::p($sql, $condition);
if (is_bool($result) OR !$single_row) {
return $result;
} else {
$row = self::fetch($result);
self::close($result);
return $row;
}
}
/**
* @brief Closes the current statement
*
* @param object $stmt statement object
* @return boolean was the close successfull?
*/
static public function close($stmt) {
if (!is_object($stmt)) {
return false;
}
switch (self::$dbo->driver) {
case 'pdo':
return $stmt->closeCursor();
case 'mysqli':
return $stmt->free_result();
return $stmt->close();
case 'mysql':
return mysql_free_result($stmt);
}
}
}
function printable($s) {

View file

@ -4,7 +4,7 @@
* @brief The script is called from time to time to clean the database entries and remove orphaned data.
*/
use \Friendica\Core\Config;
use Friendica\Core\Config;
function dbclean_run(&$argv, &$argc) {
if (!Config::get('system', 'dbclean', false)) {
@ -43,96 +43,103 @@ function remove_orphans($stage = 0) {
if (($stage == 1) OR ($stage == 0)) {
logger("Deleting old global item entries from item table without user copy");
if ($db->q("SELECT `id` FROM `item` WHERE `uid` = 0
$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 LIMIT ".intval($limit), true)) {
$count = $db->num_rows();
AND `received` < UTC_TIMESTAMP() - INTERVAL 90 DAY LIMIT ".intval($limit));
$count = dba::num_rows($r);
if ($count > 0) {
logger("found global item orphans: ".$count);
while ($orphan = $db->qfetch()) {
while ($orphan = dba::fetch($r)) {
q("DELETE FROM `item` WHERE `id` = %d", intval($orphan["id"]));
}
}
$db->qclose();
dba::close($r);
logger("Done deleting old global item entries from item table without user copy");
}
if (($stage == 2) OR ($stage == 0)) {
logger("Deleting items without parents");
if ($db->q("SELECT `id` FROM `item` WHERE NOT EXISTS (SELECT `id` FROM `item` AS `i` WHERE `item`.`parent` = `i`.`id`) LIMIT ".intval($limit), true)) {
$count = $db->num_rows();
$r = dba::p("SELECT `id` FROM `item` WHERE NOT EXISTS (SELECT `id` FROM `item` AS `i` WHERE `item`.`parent` = `i`.`id`) LIMIT ".intval($limit));
$count = dba::num_rows($r);
if ($count > 0) {
logger("found item orphans without parents: ".$count);
while ($orphan = $db->qfetch()) {
while ($orphan = dba::fetch($r)) {
q("DELETE FROM `item` WHERE `id` = %d", intval($orphan["id"]));
}
}
$db->qclose();
dba::close($r);
logger("Done deleting items without parents");
}
if (($stage == 3) OR ($stage == 0)) {
logger("Deleting orphaned data from thread table");
if ($db->q("SELECT `iid` FROM `thread` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`parent` = `thread`.`iid`) LIMIT ".intval($limit), true)) {
$count = $db->num_rows();
$r = dba::p("SELECT `iid` FROM `thread` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`parent` = `thread`.`iid`) LIMIT ".intval($limit));
$count = dba::num_rows($r);
if ($count > 0) {
logger("found thread orphans: ".$count);
while ($orphan = $db->qfetch()) {
while ($orphan = dba::fetch($r)) {
q("DELETE FROM `thread` WHERE `iid` = %d", intval($orphan["iid"]));
}
}
$db->qclose();
dba::close($r);
logger("Done deleting orphaned data from thread table");
}
if (($stage == 4) OR ($stage == 0)) {
logger("Deleting orphaned data from notify table");
if ($db->q("SELECT `iid` FROM `notify` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`id` = `notify`.`iid`) LIMIT ".intval($limit), true)) {
$count = $db->num_rows();
$r = dba::p("SELECT `iid` FROM `notify` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`id` = `notify`.`iid`) LIMIT ".intval($limit));
$count = dba::num_rows($r);
if ($count > 0) {
logger("found notify orphans: ".$count);
while ($orphan = $db->qfetch()) {
while ($orphan = dba::fetch($r)) {
q("DELETE FROM `notify` WHERE `iid` = %d", intval($orphan["iid"]));
}
}
$db->qclose();
dba::close($r);
logger("Done deleting orphaned data from notify table");
}
if (($stage == 5) OR ($stage == 0)) {
logger("Deleting orphaned data from notify-threads table");
if ($db->q("SELECT `id` FROM `notify-threads` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`parent` = `notify-threads`.`master-parent-item`) LIMIT ".intval($limit), true)) {
$count = $db->num_rows();
$r = dba::p("SELECT `id` FROM `notify-threads` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`parent` = `notify-threads`.`master-parent-item`) LIMIT ".intval($limit));
$count = dba::num_rows($r);
if ($count > 0) {
logger("found notify-threads orphans: ".$count);
while ($orphan = $db->qfetch()) {
while ($orphan = dba::fetch($r)) {
q("DELETE FROM `notify-threads` WHERE `id` = %d", intval($orphan["id"]));
}
}
$db->qclose();
dba::close($r);
logger("Done deleting orphaned data from notify-threads table");
}
if (($stage == 6) OR ($stage == 0)) {
logger("Deleting orphaned data from sign table");
if ($db->q("SELECT `iid` FROM `sign` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`id` = `sign`.`iid`) LIMIT ".intval($limit), true)) {
$count = $db->num_rows();
$r = dba::p("SELECT `iid` FROM `sign` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`id` = `sign`.`iid`) LIMIT ".intval($limit));
$count = dba::num_rows($r);
if ($count > 0) {
logger("found sign orphans: ".$count);
while ($orphan = $db->qfetch()) {
while ($orphan = dba::fetch($r)) {
q("DELETE FROM `sign` WHERE `iid` = %d", intval($orphan["iid"]));
}
}
$db->qclose();
dba::close($r);
logger("Done deleting orphaned data from sign table");
}
if (($stage == 7) OR ($stage == 0)) {
logger("Deleting orphaned data from term table");
if ($db->q("SELECT `oid` FROM `term` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`id` = `term`.`oid`) LIMIT ".intval($limit), true)) {
$count = $db->num_rows();
$r = dba::p("SELECT `oid` FROM `term` WHERE NOT EXISTS (SELECT `id` FROM `item` WHERE `item`.`id` = `term`.`oid`) LIMIT ".intval($limit));
$count = dba::num_rows($r);
if ($count > 0) {
logger("found term orphans: ".$count);
while ($orphan = $db->qfetch()) {
while ($orphan = dba::fetch($r)) {
q("DELETE FROM `term` WHERE `oid` = %d", intval($orphan["oid"]));
}
}
$db->qclose();
dba::close($r);
logger("Done deleting orphaned data from term table");
}
@ -142,4 +149,3 @@ function remove_orphans($stage = 0) {
}
}
?>

View file

@ -2,6 +2,7 @@
/**
* @brief This class contain functions for the database management
*
* This class contains functions that doesn't need to know if pdo, mysqli or whatever is used.
*/
class dbm {
/**
@ -47,6 +48,11 @@ class dbm {
if (is_bool($array)) {
return $array;
}
if (is_object($array)) {
return true;
}
return (is_array($array) && count($array) > 0);
}
@ -104,4 +110,3 @@ class dbm {
return date('Y-m-d H:i:s', $timestamp);
}
}
?>

View file

@ -1,19 +1,45 @@
<?php
use \Friendica\Core\Config;
use Friendica\App;
use Friendica\Core\Config;
require_once("boot.php");
require_once("include/text.php");
define('NEW_UPDATE_ROUTINE_VERSION', 1170);
/*
* Converts all tables from MyISAM to InnoDB
*/
function convert_to_innodb() {
global $db;
$r = q("SELECT `TABLE_NAME` FROM `information_schema`.`tables` WHERE `engine` = 'MyISAM' AND `table_schema` = '%s'",
dbesc($db->database_name()));
if (!dbm::is_result($r)) {
echo t('There are no tables on MyISAM.')."\n";
return;
}
foreach ($r AS $table) {
$sql = sprintf("ALTER TABLE `%s` engine=InnoDB;", dbesc($table['TABLE_NAME']));
echo $sql."\n";
$result = @$db->q($sql);
if (!dbm::is_result($result)) {
print_update_error($db, $sql);
}
}
}
/*
* send the email and do what is needed to do on update fails
*
* @param update_id (int) number of failed update
* @param error_message (str) error message
*/
function update_fail($update_id, $error_message){
function update_fail($update_id, $error_message) {
//send the administrators an e-mail
$admin_mail_list = "'".implode("','", array_map(dbesc, explode(",", str_replace(" ", "", $a->config['admin_email']))))."'";
$adminlist = q("SELECT uid, language, email FROM user WHERE email IN (%s)",
@ -95,10 +121,6 @@ function table_structure($table) {
if (dbm::is_result($indexes))
foreach ($indexes AS $index) {
if ($index["Index_type"] == "FULLTEXT") {
continue;
}
if ($index['Key_name'] != 'PRIMARY' && $index['Non_unique'] == '0' && !isset($indexdata[$index["Key_name"]])) {
$indexdata[$index["Key_name"]] = array('UNIQUE');
}
@ -279,6 +301,9 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
// Compare the field definition
$field_definition = $database[$name]["fields"][$fieldname];
// Remove the relation data that is used for the referential integrity
unset($parameters['relation']);
// We change the collation after the indexes had been changed.
// This is done to avoid index length problems.
// So here we always ensure that there is no need to change it.
@ -374,6 +399,14 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
$sql3 .= ";";
}
$field_list = '';
if ($is_unique && $ignore == '') {
foreach ($structure['fields'] AS $fieldname => $parameters) {
$field_list .= 'ANY_VALUE(`' . $fieldname . '`),';
}
$field_list = rtrim($field_list, ',');
}
if ($verbose) {
// Ensure index conversion to unique removes duplicates
if ($is_unique) {
@ -390,7 +423,7 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
if ($ignore != "") {
echo "SET session old_alter_table=0;\n";
} else {
echo "INSERT INTO `".$temp_name."` SELECT * FROM `".$name."`".$group_by.";\n";
echo "INSERT INTO `".$temp_name."` SELECT ".$field_list." FROM `".$name."`".$group_by.";\n";
echo "DROP TABLE `".$name."`;\n";
echo "RENAME TABLE `".$temp_name."` TO `".$name."`;\n";
}
@ -421,7 +454,7 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
if ($ignore != "") {
$db->q("SET session old_alter_table=0;");
} else {
$r = $db->q("INSERT INTO `".$temp_name."` SELECT * FROM `".$name."`".$group_by.";");
$r = $db->q("INSERT INTO `".$temp_name."` SELECT ".$field_list." FROM `".$name."`".$group_by.";");
if (!dbm::is_result($r)) {
$errors .= print_update_error($db, $sql3);
return $errors;
@ -460,7 +493,7 @@ function db_field_command($parameters, $create = true) {
if ($parameters["not null"])
$fieldstruct .= " NOT NULL";
if (isset($parameters["default"])){
if (isset($parameters["default"])) {
if (strpos(strtolower($parameters["type"]),"int")!==false) {
$fieldstruct .= " DEFAULT ".$parameters["default"];
} else {
@ -487,7 +520,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') and $field['primary']!='') {
$primary_keys[] = $fieldname;
}
}
@ -606,7 +639,7 @@ function db_definition() {
$database["attach"] = array(
"fields" => array(
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"hash" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
"filename" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"filetype" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
@ -626,7 +659,7 @@ function db_definition() {
$database["auth_codes"] = array(
"fields" => array(
"id" => array("type" => "varchar(40)", "not null" => "1", "primary" => "1"),
"client_id" => array("type" => "varchar(20)", "not null" => "1", "default" => ""),
"client_id" => array("type" => "varchar(20)", "not null" => "1", "default" => "", "relation" => array("clients" => "client_id")),
"redirect_uri" => array("type" => "varchar(200)", "not null" => "1", "default" => ""),
"expires" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"scope" => array("type" => "varchar(250)", "not null" => "1", "default" => ""),
@ -667,7 +700,7 @@ function db_definition() {
"redirect_uri" => array("type" => "varchar(200)", "not null" => "1", "default" => ""),
"name" => array("type" => "text"),
"icon" => array("type" => "text"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
),
"indexes" => array(
"PRIMARY" => array("client_id"),
@ -688,7 +721,7 @@ function db_definition() {
$database["contact"] = array(
"fields" => array(
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
"self" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
"remote_self" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
@ -777,7 +810,7 @@ function db_definition() {
"id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"guid" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
"recips" => array("type" => "text"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"creator" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
"updated" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
@ -788,12 +821,27 @@ function db_definition() {
"uid" => array("uid"),
)
);
$database["conversation"] = array(
"fields" => array(
"item-uri" => array("type" => "varbinary(255)", "not null" => "1", "primary" => "1"),
"reply-to-uri" => array("type" => "varbinary(255)", "not null" => "1", "default" => ""),
"conversation-uri" => array("type" => "varbinary(255)", "not null" => "1", "default" => ""),
"conversation-href" => array("type" => "varbinary(255)", "not null" => "1", "default" => ""),
"protocol" => array("type" => "tinyint(1) unsigned", "not null" => "1", "default" => "0"),
"source" => array("type" => "mediumtext"),
"received" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
),
"indexes" => array(
"PRIMARY" => array("item-uri"),
"conversation-uri" => array("conversation-uri"),
)
);
$database["event"] = array(
"fields" => array(
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"guid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"cid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"cid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
"uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
"edited" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
@ -839,15 +887,15 @@ function db_definition() {
"indexes" => array(
"PRIMARY" => array("id"),
"addr" => array("addr(32)"),
"url" => array("url"),
"url" => array("UNIQUE", "url(190)"),
)
);
$database["ffinder"] = array(
"fields" => array(
"id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
"cid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
"fid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
"uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"cid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
"fid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("fcontact" => "id")),
),
"indexes" => array(
"PRIMARY" => array("id"),
@ -868,8 +916,8 @@ function db_definition() {
$database["fsuggest"] = array(
"fields" => array(
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"cid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"cid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
"name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"request" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
@ -884,8 +932,8 @@ function db_definition() {
$database["gcign"] = array(
"fields" => array(
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"gcid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"gcid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("gcontact" => "id")),
),
"indexes" => array(
"PRIMARY" => array("id"),
@ -924,7 +972,7 @@ function db_definition() {
),
"indexes" => array(
"PRIMARY" => array("id"),
"nurl" => array("nurl(64)"),
"nurl" => array("UNIQUE", "nurl(190)"),
"name" => array("name(64)"),
"nick" => array("nick(32)"),
"addr" => array("addr(64)"),
@ -935,10 +983,10 @@ function db_definition() {
$database["glink"] = array(
"fields" => array(
"id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"cid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"gcid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"zcid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"cid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"gcid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("gcontact" => "id")),
"zcid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("gcontact" => "id")),
"updated" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
),
"indexes" => array(
@ -950,7 +998,7 @@ function db_definition() {
$database["group"] = array(
"fields" => array(
"id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
"uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"visible" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
"deleted" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
"name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
@ -963,9 +1011,9 @@ function db_definition() {
$database["group_member"] = array(
"fields" => array(
"id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
"gid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
"contact-id" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
"uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"gid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("group" => "id")),
"contact-id" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
),
"indexes" => array(
"PRIMARY" => array("id"),
@ -994,7 +1042,7 @@ function db_definition() {
),
"indexes" => array(
"PRIMARY" => array("id"),
"nurl" => array("nurl(32)"),
"nurl" => array("UNIQUE", "nurl(190)"),
)
);
$database["hook"] = array(
@ -1013,9 +1061,9 @@ function db_definition() {
$database["intro"] = array(
"fields" => array(
"id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
"fid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"contact-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"fid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("fcontact" => "id")),
"contact-id" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
"knowyou" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
"duplex" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
"note" => array("type" => "text"),
@ -1030,16 +1078,16 @@ function db_definition() {
);
$database["item"] = array(
"fields" => array(
"id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "relation" => array("thread" => "iid")),
"guid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
"contact-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"gcontact-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
"uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"contact-id" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
"gcontact-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0", "relation" => array("gcontact" => "id")),
"type" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"wall" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
"gravity" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
"parent" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
"parent" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("item" => "id")),
"parent-uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"extid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"thr-parent" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
@ -1048,11 +1096,11 @@ function db_definition() {
"commented" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
"received" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
"changed" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
"owner-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"owner-id" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
"owner-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"owner-link" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"owner-avatar" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"author-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"author-id" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
"author-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"author-link" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"author-avatar" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
@ -1067,7 +1115,7 @@ function db_definition() {
"postopts" => array("type" => "text"),
"plink" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"resource-id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"event-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"event-id" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("event" => "id")),
"tag" => array("type" => "mediumtext"),
"attach" => array("type" => "mediumtext"),
"inform" => array("type" => "mediumtext"),
@ -1113,6 +1161,7 @@ function db_definition() {
"uid_parenturi" => array("uid","parent-uri(190)"),
"uid_contactid_created" => array("uid","contact-id","created"),
"authorid_created" => array("author-id","created"),
"ownerid" => array("owner-id"),
"uid_uri" => array("uid", "uri(190)"),
"resource-id" => array("resource-id"),
"contactid_allowcid_allowpid_denycid_denygid" => array("contact-id","allow_cid(10)","allow_gid(10)","deny_cid(10)","deny_gid(10)"), //
@ -1128,8 +1177,8 @@ function db_definition() {
$database["item_id"] = array(
"fields" => array(
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"iid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"iid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("item" => "id")),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"sid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"service" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
),
@ -1155,13 +1204,13 @@ function db_definition() {
$database["mail"] = array(
"fields" => array(
"id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
"uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"guid" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
"from-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"from-photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"from-url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"contact-id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"convid" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
"contact-id" => array("type" => "varchar(255)", "not null" => "1", "default" => "", "relation" => array("contact" => "id")),
"convid" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0", "relation" => array("conv" => "id")),
"title" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"body" => array("type" => "mediumtext"),
"seen" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
@ -1178,12 +1227,13 @@ function db_definition() {
"convid" => array("convid"),
"uri" => array("uri(64)"),
"parent-uri" => array("parent-uri(64)"),
"contactid" => array("contact-id"),
)
);
$database["mailacct"] = array(
"fields" => array(
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"server" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"port" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"ssltype" => array("type" => "varchar(16)", "not null" => "1", "default" => ""),
@ -1203,8 +1253,8 @@ function db_definition() {
$database["manage"] = array(
"fields" => array(
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"mid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"mid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
),
"indexes" => array(
"PRIMARY" => array("id"),
@ -1221,10 +1271,10 @@ function db_definition() {
"photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"date" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
"msg" => array("type" => "mediumtext"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"link" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"iid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"parent" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"iid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("item" => "id")),
"parent" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("item" => "id")),
"seen" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
"verb" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"otype" => array("type" => "varchar(16)", "not null" => "1", "default" => ""),
@ -1242,10 +1292,10 @@ function db_definition() {
$database["notify-threads"] = array(
"fields" => array(
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"notify-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"master-parent-item" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
"notify-id" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("notify" => "id")),
"master-parent-item" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("item" => "id")),
"parent-item" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
"receiver-uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"receiver-uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
),
"indexes" => array(
"PRIMARY" => array("id"),
@ -1278,7 +1328,7 @@ function db_definition() {
$database["pconfig"] = array(
"fields" => array(
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"cat" => array("type" => "varbinary(255)", "not null" => "1", "default" => ""),
"k" => array("type" => "varbinary(255)", "not null" => "1", "default" => ""),
"v" => array("type" => "mediumtext"),
@ -1291,8 +1341,8 @@ function db_definition() {
$database["photo"] = array(
"fields" => array(
"id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
"contact-id" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
"uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"contact-id" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
"guid" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
"resource-id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
@ -1315,6 +1365,7 @@ function db_definition() {
),
"indexes" => array(
"PRIMARY" => array("id"),
"contactid" => array("contact-id"),
"uid_contactid" => array("uid", "contact-id"),
"uid_profile" => array("uid", "profile"),
"uid_album_scale_created" => array("uid", "album(32)", "scale", "created"),
@ -1325,7 +1376,7 @@ function db_definition() {
$database["poll"] = array(
"fields" => array(
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"q0" => array("type" => "text"),
"q1" => array("type" => "text"),
"q2" => array("type" => "text"),
@ -1345,7 +1396,7 @@ function db_definition() {
$database["poll_result"] = array(
"fields" => array(
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"poll_id" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"poll_id" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("poll" => "id")),
"choice" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
),
"indexes" => array(
@ -1368,7 +1419,7 @@ function db_definition() {
$database["profile"] = array(
"fields" => array(
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"profile-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"is-default" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
"hide-friends" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
@ -1418,8 +1469,8 @@ function db_definition() {
$database["profile_check"] = array(
"fields" => array(
"id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
"cid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
"uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"cid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
"dfrn_id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"sec" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"expire" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
@ -1431,7 +1482,7 @@ function db_definition() {
$database["push_subscriber"] = array(
"fields" => array(
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"callback_url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"topic" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"nickname" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
@ -1446,7 +1497,7 @@ function db_definition() {
$database["queue"] = array(
"fields" => array(
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"cid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"cid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
"network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
"created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
"last" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
@ -1467,7 +1518,7 @@ function db_definition() {
"id" => array("type" => "int(11) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"hash" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
"uid" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
"uid" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"password" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"language" => array("type" => "varchar(16)", "not null" => "1", "default" => ""),
"note" => array("type" => "text"),
@ -1479,7 +1530,7 @@ function db_definition() {
$database["search"] = array(
"fields" => array(
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"term" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
),
"indexes" => array(
@ -1503,7 +1554,7 @@ function db_definition() {
$database["sign"] = array(
"fields" => array(
"id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"iid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
"iid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("item" => "id")),
"signed_text" => array("type" => "mediumtext"),
"signature" => array("type" => "text"),
"signer" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
@ -1516,7 +1567,7 @@ function db_definition() {
$database["spam"] = array(
"fields" => array(
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"spam" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"ham" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"term" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
@ -1533,7 +1584,7 @@ function db_definition() {
$database["term"] = array(
"fields" => array(
"tid" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"oid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
"oid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("item" => "id")),
"otype" => array("type" => "tinyint(3) unsigned", "not null" => "1", "default" => "0"),
"type" => array("type" => "tinyint(3) unsigned", "not null" => "1", "default" => "0"),
"term" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
@ -1543,7 +1594,7 @@ function db_definition() {
"received" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
"global" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
"aid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
"uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
"uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
),
"indexes" => array(
"PRIMARY" => array("tid"),
@ -1555,12 +1606,12 @@ function db_definition() {
);
$database["thread"] = array(
"fields" => array(
"iid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "primary" => "1"),
"uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
"contact-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
"gcontact-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
"owner-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
"author-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"),
"iid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "primary" => "1", "relation" => array("item" => "id")),
"uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"contact-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
"gcontact-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0", "relation" => array("gcontact" => "id")),
"owner-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
"author-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
"created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
"edited" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
"commented" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
@ -1588,6 +1639,9 @@ function db_definition() {
"uid_network_created" => array("uid","network","created"),
"uid_contactid_commented" => array("uid","contact-id","commented"),
"uid_contactid_created" => array("uid","contact-id","created"),
"contactid" => array("contact-id"),
"ownerid" => array("owner-id"),
"authorid" => array("author-id"),
"uid_created" => array("uid","created"),
"uid_commented" => array("uid","commented"),
"uid_wall_created" => array("uid","wall","created"),
@ -1597,10 +1651,10 @@ function db_definition() {
"fields" => array(
"id" => array("type" => "varchar(40)", "not null" => "1", "primary" => "1"),
"secret" => array("type" => "text"),
"client_id" => array("type" => "varchar(20)", "not null" => "1", "default" => ""),
"client_id" => array("type" => "varchar(20)", "not null" => "1", "default" => "", "relation" => array("clients" => "client_id")),
"expires" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"scope" => array("type" => "varchar(200)", "not null" => "1", "default" => ""),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
),
"indexes" => array(
"PRIMARY" => array("id"),
@ -1691,8 +1745,8 @@ function db_definition() {
function dbstructure_run(&$argv, &$argc) {
global $a, $db;
if (is_null($a)){
$a = new App;
if (is_null($a)) {
$a = new App(dirname(__DIR__));
}
if (is_null($db)) {
@ -1730,6 +1784,9 @@ function dbstructure_run(&$argv, &$argc) {
case "dumpsql":
print_structure(db_definition());
return;
case "toinnodb":
convert_to_innodb();
return;
}
}
@ -1741,11 +1798,12 @@ function dbstructure_run(&$argv, &$argc) {
echo "dryrun show database update schema queries without running them\n";
echo "update update database schema\n";
echo "dumpsql dump database schema\n";
echo "toinnodb convert all tables from MyISAM to InnoDB\n";
return;
}
if (array_search(__file__,get_included_files())===0){
if (array_search(__file__,get_included_files())===0) {
dbstructure_run($_SERVER["argv"],$_SERVER["argc"]);
killme();
}

View file

@ -1,6 +1,6 @@
<?php
use \Friendica\Core\Config;
use Friendica\Core\Config;
function dbupdate_run(&$argv, &$argc) {
global $a;

View file

@ -1,21 +1,22 @@
<?php
use \Friendica\Core\Config;
use Friendica\App;
use Friendica\Core\Config;
require_once('include/queue_fn.php');
require_once('include/html2plain.php');
require_once('include/Scrape.php');
require_once('include/diaspora.php');
require_once('include/ostatus.php');
require_once('include/dfrn.php');
require_once 'include/queue_fn.php';
require_once 'include/html2plain.php';
require_once 'include/probe.php';
require_once 'include/diaspora.php';
require_once 'include/ostatus.php';
require_once 'include/dfrn.php';
function delivery_run(&$argv, &$argc){
global $a;
require_once('include/datetime.php');
require_once('include/items.php');
require_once('include/bbcode.php');
require_once('include/email.php');
require_once 'include/datetime.php';
require_once 'include/items.php';
require_once 'include/bbcode.php';
require_once 'include/email.php';
if ($argc < 3) {
return;
@ -165,7 +166,7 @@ function delivery_run(&$argv, &$argc){
$public_message = true;
if (!($mail || $fsuggest || $relocate)) {
require_once('include/group.php');
require_once 'include/group.php';
$parent = $items[0];

View file

@ -7,6 +7,8 @@
* https://github.com/friendica/friendica/blob/master/spec/dfrn2.pdf
*/
use Friendica\App;
require_once("include/Contact.php");
require_once("include/ostatus.php");
require_once("include/enotify.php");
@ -370,7 +372,7 @@ class dfrn {
$ext = Photo::supportedTypes();
foreach ($rp as $p) {
$photos[$p['scale']] = app::get_baseurl().'/photo/'.$p['resource-id'].'-'.$p['scale'].'.'.$ext[$p['type']];
$photos[$p['scale']] = App::get_baseurl().'/photo/'.$p['resource-id'].'-'.$p['scale'].'.'.$ext[$p['type']];
}
unset($rp, $ext);
@ -431,7 +433,7 @@ class dfrn {
$root->setAttribute("xmlns:ostatus", NAMESPACE_OSTATUS);
$root->setAttribute("xmlns:statusnet", NAMESPACE_STATUSNET);
xml::add_element($doc, $root, "id", app::get_baseurl()."/profile/".$owner["nick"]);
xml::add_element($doc, $root, "id", App::get_baseurl()."/profile/".$owner["nick"]);
xml::add_element($doc, $root, "title", $owner["name"]);
$attributes = array("uri" => "https://friendi.ca", "version" => FRIENDICA_VERSION."-".DB_UPDATE_VERSION);
@ -448,13 +450,13 @@ class dfrn {
// DFRN itself doesn't uses this. But maybe someone else wants to subscribe to the public feed.
ostatus::hublinks($doc, $root);
$attributes = array("rel" => "salmon", "href" => app::get_baseurl()."/salmon/".$owner["nick"]);
$attributes = array("rel" => "salmon", "href" => App::get_baseurl()."/salmon/".$owner["nick"]);
xml::add_element($doc, $root, "link", "", $attributes);
$attributes = array("rel" => "http://salmon-protocol.org/ns/salmon-replies", "href" => app::get_baseurl()."/salmon/".$owner["nick"]);
$attributes = array("rel" => "http://salmon-protocol.org/ns/salmon-replies", "href" => App::get_baseurl()."/salmon/".$owner["nick"]);
xml::add_element($doc, $root, "link", "", $attributes);
$attributes = array("rel" => "http://salmon-protocol.org/ns/salmon-mention", "href" => app::get_baseurl()."/salmon/".$owner["nick"]);
$attributes = array("rel" => "http://salmon-protocol.org/ns/salmon-mention", "href" => App::get_baseurl()."/salmon/".$owner["nick"]);
xml::add_element($doc, $root, "link", "", $attributes);
}
@ -511,7 +513,7 @@ class dfrn {
}
xml::add_element($doc, $author, "name", $owner["name"], $attributes);
xml::add_element($doc, $author, "uri", app::get_baseurl().'/profile/'.$owner["nickname"], $attributes);
xml::add_element($doc, $author, "uri", App::get_baseurl().'/profile/'.$owner["nickname"], $attributes);
xml::add_element($doc, $author, "dfrn:handle", $owner["addr"], $attributes);
$attributes = array("rel" => "photo", "type" => "image/jpeg",
@ -812,11 +814,33 @@ class dfrn {
$parent = q("SELECT `guid` FROM `item` WHERE `id` = %d", intval($item["parent"]));
$parent_item = (($item['thr-parent']) ? $item['thr-parent'] : $item['parent-uri']);
$attributes = array("ref" => $parent_item, "type" => "text/html",
"href" => app::get_baseurl().'/display/'.$parent[0]['guid'],
"href" => App::get_baseurl().'/display/'.$parent[0]['guid'],
"dfrn:diaspora_guid" => $parent[0]['guid']);
xml::add_element($doc, $entry, "thr:in-reply-to", "", $attributes);
}
// Add conversation data. This is used for OStatus
$conversation_href = App::get_baseurl()."/display/".$owner["nick"]."/".$item["parent"];
$conversation_uri = $conversation_href;
if (isset($parent_item)) {
$r = dba::fetch_first("SELECT `conversation-uri`, `conversation-href` FROM `conversation` WHERE `item-uri` = ?", $item['parent-uri']);
if (dbm::is_result($r)) {
if ($r['conversation-uri'] != '') {
$conversation_uri = $r['conversation-uri'];
}
if ($r['conversation-href'] != '') {
$conversation_href = $r['conversation-href'];
}
}
}
$attributes = array(
"href" => $conversation_href,
"ref" => $conversation_uri);
xml::add_element($doc, $entry, "ostatus:conversation", $conversation_uri, $attributes);
xml::add_element($doc, $entry, "id", $item["uri"]);
xml::add_element($doc, $entry, "title", $item["title"]);
@ -832,7 +856,7 @@ class dfrn {
// We save this value in "plink". Maybe we should read it from there as well?
xml::add_element($doc, $entry, "link", "", array("rel" => "alternate", "type" => "text/html",
"href" => app::get_baseurl()."/display/".$item["guid"]));
"href" => App::get_baseurl()."/display/".$item["guid"]));
// "comment-allow" is some old fashioned stuff for old Friendica versions.
// It is included in the rewritten code for completeness
@ -2209,12 +2233,16 @@ class dfrn {
* @param array $importer Record of the importer user mixed with contact of the content
* @todo Add type-hints
*/
private static function process_entry($header, $xpath, $entry, $importer) {
private static function process_entry($header, $xpath, $entry, $importer, $xml) {
logger("Processing entries");
$item = $header;
$item["protocol"] = PROTOCOL_DFRN;
$item["source"] = $xml;
// Get the uri
$item["uri"] = $xpath->query("atom:id/text()", $entry)->item(0)->nodeValue;
@ -2373,6 +2401,20 @@ class dfrn {
self::parse_links($links, $item);
}
$item['conversation-uri'] = $xpath->query('ostatus:conversation/text()', $entry)->item(0)->nodeValue;
$conv = $xpath->query('ostatus:conversation', $entry);
if (is_object($conv->item(0))) {
foreach ($conv->item(0)->attributes AS $attributes) {
if ($attributes->name == "ref") {
$item['conversation-uri'] = $attributes->textContent;
}
if ($attributes->name == "href") {
$item['conversation-href'] = $attributes->textContent;
}
}
}
// Is it a reply or a top level posting?
$item["parent-uri"] = $item["uri"];
@ -2801,7 +2843,7 @@ class dfrn {
if (!$sort_by_date) {
$entries = $xpath->query("/atom:feed/atom:entry");
foreach ($entries AS $entry) {
self::process_entry($header, $xpath, $entry, $importer);
self::process_entry($header, $xpath, $entry, $importer, $xml);
}
} else {
$newentries = array();
@ -2815,7 +2857,7 @@ class dfrn {
ksort($newentries);
foreach ($newentries AS $entry) {
self::process_entry($header, $xpath, $entry, $importer);
self::process_entry($header, $xpath, $entry, $importer, $xml);
}
}
logger("Import done for user " . $importer["uid"] . " from contact " . $importer["id"], LOGGER_DEBUG);

View file

@ -8,11 +8,12 @@
* This will change in the future.
*/
use \Friendica\Core\Config;
use Friendica\App;
use Friendica\Core\Config;
require_once 'include/items.php';
require_once 'include/bb2diaspora.php';
require_once 'include/Scrape.php';
require_once 'include/probe.php';
require_once 'include/Contact.php';
require_once 'include/Photo.php';
require_once 'include/socgraph.php';
@ -187,7 +188,80 @@ class Diaspora {
}
/**
* @brief: Decodes incoming Diaspora message
* @brief: Decodes incoming Diaspora message in the new format
*
* @param array $importer Array of the importer user
* @param string $raw raw post message
*
* @return array
* 'message' -> decoded Diaspora XML message
* 'author' -> author diaspora handle
* 'key' -> author public key (converted to pkcs#8)
*/
public static function decode_raw($importer, $raw) {
$data = json_decode($raw);
// Is it a private post? Then decrypt the outer Salmon
if (is_object($data)) {
$encrypted_aes_key_bundle = base64_decode($data->aes_key);
$ciphertext = base64_decode($data->encrypted_magic_envelope);
$outer_key_bundle = '';
@openssl_private_decrypt($encrypted_aes_key_bundle, $outer_key_bundle, $importer['prvkey']);
$j_outer_key_bundle = json_decode($outer_key_bundle);
if (!is_object($j_outer_key_bundle)) {
logger('Outer Salmon did not verify. Discarding.');
http_status_exit(400);
}
$outer_iv = base64_decode($j_outer_key_bundle->iv);
$outer_key = base64_decode($j_outer_key_bundle->key);
$xml = diaspora::aes_decrypt($outer_key, $outer_iv, $ciphertext);
} else {
$xml = $raw;
}
$basedom = parse_xml_string($xml);
if (!is_object($basedom)) {
logger('Received data does not seem to be an XML. Discarding.');
http_status_exit(400);
}
$base = $basedom->children(NAMESPACE_SALMON_ME);
// Not sure if this cleaning is needed
$data = str_replace(array(" ", "\t", "\r", "\n"), array("", "", "", ""), $base->data);
// Build the signed data
$type = $base->data[0]->attributes()->type[0];
$encoding = $base->encoding;
$alg = $base->alg;
$signed_data = $data.'.'.base64url_encode($type).'.'.base64url_encode($encoding).'.'.base64url_encode($alg);
// This is the signature
$signature = base64url_decode($base->sig);
// Get the senders' public key
$key_id = $base->sig[0]->attributes()->key_id[0];
$author_addr = base64_decode($key_id);
$key = diaspora::key($author_addr);
$verify = rsa_verify($signed_data, $signature, $key);
if (!$verify) {
logger('Message did not verify. Discarding.');
http_status_exit(400);
}
return array('message' => (string)base64url_decode($base->data),
'author' => unxmlify($author_addr),
'key' => (string)$key);
}
/**
* @brief: Decodes incoming Diaspora message in the deprecated format
*
* @param array $importer Array of the importer user
* @param string $xml urldecoded Diaspora salmon
@ -202,9 +276,10 @@ class Diaspora {
$public = false;
$basedom = parse_xml_string($xml);
if (!is_object($basedom))
if (!is_object($basedom)) {
logger("XML is not parseable.");
return false;
}
$children = $basedom->children('https://joindiaspora.com/protocol');
if ($children->header) {
@ -333,6 +408,24 @@ class Diaspora {
return false;
}
if (!($postdata = self::valid_posting($msg))) {
logger("Invalid posting");
return false;
}
$fields = $postdata['fields'];
// Is it a an action (comment, like, ...) for our own post?
if (isset($fields->parent_guid) AND !$postdata["relayed"]) {
$guid = notags(unxmlify($fields->parent_guid));
$importer = self::importer_for_guid($guid);
if (is_array($importer)) {
logger("delivering to origin: ".$importer["name"]);
$message_id = self::dispatch($importer, $msg, $fields);
return $message_id;
}
}
// Now distribute it to the followers
$r = q("SELECT `user`.* FROM `user` WHERE `user`.`uid` IN
(SELECT `contact`.`uid` FROM `contact` WHERE `contact`.`network` = '%s' AND `contact`.`addr` = '%s')
@ -344,18 +437,14 @@ class Diaspora {
if (dbm::is_result($r)) {
foreach ($r as $rr) {
logger("delivering to: ".$rr["username"]);
self::dispatch($rr,$msg);
self::dispatch($rr, $msg, $fields);
}
} elseif (!Config::get('system', 'relay_subscribe', false)) {
logger("Unwanted message from ".$msg["author"]." send by ".$_SERVER["REMOTE_ADDR"]." with ".$_SERVER["HTTP_USER_AGENT"].": ".print_r($msg, true), LOGGER_DEBUG);
} else {
$social_relay = (bool)Config::get('system', 'relay_subscribe', false);
// Use a dummy importer to import the data for the public copy
if ($social_relay) {
$importer = array("uid" => 0, "page-flags" => PAGE_FREELOVE);
$message_id = self::dispatch($importer,$msg);
} else {
logger("Unwanted message from ".$msg["author"]." send by ".$_SERVER["REMOTE_ADDR"]." with ".$_SERVER["HTTP_USER_AGENT"].": ".print_r($msg, true), LOGGER_DEBUG);
}
$importer = array("uid" => 0, "page-flags" => PAGE_FREELOVE);
$message_id = self::dispatch($importer, $msg, $fields);
}
return $message_id;
@ -366,18 +455,23 @@ class Diaspora {
*
* @param array $importer Array of the importer user
* @param array $msg The post that will be dispatched
* @param object $fields SimpleXML object that contains the message
*
* @return int The message id of the generated message, "true" or "false" if there was an error
*/
public static function dispatch($importer, $msg) {
public static function dispatch($importer, $msg, $fields = null) {
// The sender is the handle of the contact that sent the message.
// This will often be different with relayed messages (for example "like" and "comment")
$sender = $msg["author"];
if (!self::valid_posting($msg, $fields)) {
logger("Invalid posting");
return false;
// This is only needed for private postings since this is already done for public ones before
if (is_null($fields)) {
if (!($postdata = self::valid_posting($msg))) {
logger("Invalid posting");
return false;
}
$fields = $postdata['fields'];
}
$type = $fields->getName();
@ -439,11 +533,10 @@ class Diaspora {
* It also does the conversion between the old and the new diaspora format.
*
* @param array $msg Array with the XML, the sender handle and the sender signature
* @param object $fields SimpleXML object that contains the posting when it is valid
*
* @return bool Is the posting valid?
* @return bool|array If the posting is valid then an array with an SimpleXML object is returned
*/
private static function valid_posting($msg, &$fields) {
private static function valid_posting($msg) {
$data = parse_xml_string($msg["message"], false);
@ -484,32 +577,38 @@ class Diaspora {
foreach ($element->children() AS $fieldname => $entry) {
if ($oldXML) {
// Translation for the old XML structure
if ($fieldname == "diaspora_handle")
if ($fieldname == "diaspora_handle") {
$fieldname = "author";
if ($fieldname == "participant_handles")
$fieldname = "participants";
if (in_array($type, array("like", "participation"))) {
if ($fieldname == "target_type")
$fieldname = "parent_type";
}
if ($fieldname == "sender_handle")
if ($fieldname == "participant_handles") {
$fieldname = "participants";
}
if (in_array($type, array("like", "participation"))) {
if ($fieldname == "target_type") {
$fieldname = "parent_type";
}
}
if ($fieldname == "sender_handle") {
$fieldname = "author";
if ($fieldname == "recipient_handle")
}
if ($fieldname == "recipient_handle") {
$fieldname = "recipient";
if ($fieldname == "root_diaspora_id")
}
if ($fieldname == "root_diaspora_id") {
$fieldname = "root_author";
}
if ($type == "status_message") {
if ($fieldname == "raw_message") {
$fieldname = "text";
}
}
if ($type == "retraction") {
if ($fieldname == "post_guid")
if ($fieldname == "post_guid") {
$fieldname = "target_guid";
if ($fieldname == "type")
}
if ($fieldname == "type") {
$fieldname = "target_type";
}
}
}
@ -538,9 +637,9 @@ class Diaspora {
}
// Only some message types have signatures. So we quit here for the other types.
if (!in_array($type, array("comment", "message", "like")))
return true;
if (!in_array($type, array("comment", "like"))) {
return array("fields" => $fields, "relayed" => false);
}
// No author_signature? This is a must, so we quit.
if (!isset($author_signature)) {
logger("No author signature for type ".$type." - Message: ".$msg["message"], LOGGER_DEBUG);
@ -548,12 +647,16 @@ class Diaspora {
}
if (isset($parent_author_signature)) {
$relayed = true;
$key = self::key($msg["author"]);
if (!rsa_verify($signed_data, $parent_author_signature, $key, "sha256")) {
logger("No valid parent author signature for parent author ".$msg["author"]. " in type ".$type." - signed data: ".$signed_data." - Message: ".$msg["message"]." - Signature ".$parent_author_signature, LOGGER_DEBUG);
return false;
}
} else {
$relayed = false;
}
$key = self::key($fields->author);
@ -561,8 +664,9 @@ class Diaspora {
if (!rsa_verify($signed_data, $author_signature, $key, "sha256")) {
logger("No valid author signature for author ".$fields->author. " in type ".$type." - signed data: ".$signed_data." - Message: ".$msg["message"]." - Signature ".$author_signature, LOGGER_DEBUG);
return false;
} else
return true;
} else {
return array("fields" => $fields, "relayed" => $relayed);
}
}
/**
@ -591,7 +695,7 @@ class Diaspora {
*
* @return array the queried data
*/
private static function person_by_handle($handle) {
public static function person_by_handle($handle) {
$r = q("SELECT * FROM `fcontact` WHERE `network` = '%s' AND `addr` = '%s' LIMIT 1",
dbesc(NETWORK_DIASPORA),
@ -828,17 +932,20 @@ class Diaspora {
logger("defining user ".$contact["nick"]." as friend");
}
if (($contact["blocked"]) || ($contact["readonly"]) || ($contact["archive"]))
// We don't seem to like that person
if ($contact["blocked"] || $contact["readonly"] || $contact["archive"]) {
return false;
if ($contact["rel"] == CONTACT_IS_SHARING || $contact["rel"] == CONTACT_IS_FRIEND)
// We are following this person? Then it is okay
} elseif (($contact["rel"] == CONTACT_IS_SHARING) || ($contact["rel"] == CONTACT_IS_FRIEND)) {
return true;
if ($contact["rel"] == CONTACT_IS_FOLLOWER)
if (($importer["page-flags"] == PAGE_COMMUNITY) OR $is_comment)
return true;
// Messages for the global users are always accepted
if ($importer["uid"] == 0)
// Is it a post to a community? That's good
} elseif (($contact["rel"] == CONTACT_IS_FOLLOWER) && ($importer["page-flags"] == PAGE_COMMUNITY)) {
return true;
}
// Messages for the global users and comments are always accepted
if (($importer["uid"] == 0) || $is_comment) {
return true;
}
return false;
}
@ -856,7 +963,12 @@ class Diaspora {
$contact = self::contact_by_handle($importer["uid"], $handle);
if (!$contact) {
logger("A Contact for handle ".$handle." and user ".$importer["uid"]." was not found");
return false;
// If a contact isn't found, we accept it anyway if it is a comment
if ($is_comment) {
return $importer;
} else {
return false;
}
}
if (!self::post_allow($importer, $contact, $is_comment)) {
@ -1111,9 +1223,9 @@ class Diaspora {
$cid = $r[0]["id"];
$network = $r[0]["network"];
// We are receiving content from a user that is about to be terminated
// We are receiving content from a user that possibly is about to be terminated
// This means the user is vital, so we remove a possible termination date.
unmark_for_death($contact);
unmark_for_death($r[0]);
} else {
$cid = $contact["id"];
$network = NETWORK_DIASPORA;
@ -1227,6 +1339,26 @@ class Diaspora {
}
}
/**
* @brief Find the best importer for a comment, like, ...
*
* @param string $guid The guid of the item
*
* @return array|boolean the origin owner of that post - or false
*/
private static function importer_for_guid($guid) {
$item = dba::fetch_first("SELECT `uid` FROM `item` WHERE `origin` AND `guid` = ? LIMIT 1", $guid);
if (dbm::is_result($item)) {
logger("Found user ".$item['uid']." as owner of item ".$guid, LOGGER_DEBUG);
$contact = dba::fetch_first("SELECT * FROM `contact` WHERE `self` AND `uid` = ?", $item['uid']);
if (dbm::is_result($contact)) {
return $contact;
}
}
return false;
}
/**
* @brief Processes an incoming comment
*
@ -1238,10 +1370,10 @@ class Diaspora {
* @return int The message id of the generated comment or "false" if there was an error
*/
private static function receive_comment($importer, $sender, $data, $xml) {
$author = notags(unxmlify($data->author));
$guid = notags(unxmlify($data->guid));
$parent_guid = notags(unxmlify($data->parent_guid));
$text = unxmlify($data->text);
$author = notags(unxmlify($data->author));
if (isset($data->created_at)) {
$created_at = datetime_convert("UTC", "UTC", notags(unxmlify($data->created_at)));
@ -1308,7 +1440,9 @@ class Diaspora {
}
$datarray["object-type"] = ACTIVITY_OBJ_COMMENT;
$datarray["object"] = $xml;
$datarray["protocol"] = PROTOCOL_DIASPORA;
$datarray["source"] = $xml;
$datarray["changed"] = $datarray["created"] = $datarray["edited"] = $created_at;
@ -1354,16 +1488,9 @@ class Diaspora {
* @return bool "true" if it was successful
*/
private static function receive_conversation_message($importer, $contact, $data, $msg, $mesg, $conversation) {
$author = notags(unxmlify($data->author));
$guid = notags(unxmlify($data->guid));
$subject = notags(unxmlify($data->subject));
$author = notags(unxmlify($data->author));
$msg_guid = notags(unxmlify($mesg->guid));
$msg_parent_guid = notags(unxmlify($mesg->parent_guid));
$msg_parent_author_signature = notags(unxmlify($mesg->parent_author_signature));
$msg_author_signature = notags(unxmlify($mesg->author_signature));
$msg_text = unxmlify($mesg->text);
$msg_created_at = datetime_convert("UTC", "UTC", notags(unxmlify($mesg->created_at)));
// "diaspora_handle" is the element name from the old version
// "author" is the element name from the new version
@ -1375,7 +1502,10 @@ class Diaspora {
return false;
}
$msg_guid = notags(unxmlify($mesg->guid));
$msg_conversation_guid = notags(unxmlify($mesg->conversation_guid));
$msg_text = unxmlify($mesg->text);
$msg_created_at = datetime_convert("UTC", "UTC", notags(unxmlify($mesg->created_at)));
if ($msg_conversation_guid != $guid) {
logger("message conversation guid does not belong to the current conversation.");
@ -1385,44 +1515,11 @@ class Diaspora {
$body = diaspora2bb($msg_text);
$message_uri = $msg_author.":".$msg_guid;
$author_signed_data = $msg_guid.";".$msg_parent_guid.";".$msg_text.";".unxmlify($mesg->created_at).";".$msg_author.";".$msg_conversation_guid;
$person = self::person_by_handle($msg_author);
$author_signature = base64_decode($msg_author_signature);
if (strcasecmp($msg_author,$msg["author"]) == 0) {
$person = $contact;
$key = $msg["key"];
} else {
$person = self::person_by_handle($msg_author);
if (is_array($person) && x($person, "pubkey")) {
$key = $person["pubkey"];
} else {
logger("unable to find author details");
return false;
}
}
if (!rsa_verify($author_signed_data, $author_signature, $key, "sha256")) {
logger("verification failed.");
return false;
}
if ($msg_parent_author_signature) {
$owner_signed_data = $msg_guid.";".$msg_parent_guid.";".$msg_text.";".unxmlify($mesg->created_at).";".$msg_author.";".$msg_conversation_guid;
$parent_author_signature = base64_decode($msg_parent_author_signature);
$key = $msg["key"];
if (!rsa_verify($owner_signed_data, $parent_author_signature, $key, "sha256")) {
logger("owner verification failed.");
return false;
}
}
$r = q("SELECT `id` FROM `mail` WHERE `uri` = '%s' LIMIT 1",
dbesc($message_uri)
$r = q("SELECT `id` FROM `mail` WHERE `guid` = '%s' AND `uid` = %d LIMIT 1",
dbesc($msg_guid),
intval($importer["uid"])
);
if (dbm::is_result($r)) {
logger("duplicate message already delivered.", LOGGER_DEBUG);
@ -1479,10 +1576,10 @@ class Diaspora {
* @return bool Success
*/
private static function receive_conversation($importer, $msg, $data) {
$author = notags(unxmlify($data->author));
$guid = notags(unxmlify($data->guid));
$subject = notags(unxmlify($data->subject));
$created_at = datetime_convert("UTC", "UTC", notags(unxmlify($data->created_at)));
$author = notags(unxmlify($data->author));
$participants = notags(unxmlify($data->participants));
$messages = $data->message;
@ -1587,11 +1684,11 @@ class Diaspora {
* @return int The message id of the generated like or "false" if there was an error
*/
private static function receive_like($importer, $sender, $data) {
$positive = notags(unxmlify($data->positive));
$guid = notags(unxmlify($data->guid));
$parent_type = notags(unxmlify($data->parent_type));
$parent_guid = notags(unxmlify($data->parent_guid));
$author = notags(unxmlify($data->author));
$guid = notags(unxmlify($data->guid));
$parent_guid = notags(unxmlify($data->parent_guid));
$parent_type = notags(unxmlify($data->parent_type));
$positive = notags(unxmlify($data->positive));
// likes on comments aren't supported by Diaspora - only on posts
// But maybe this will be supported in the future, so we will accept it.
@ -1628,6 +1725,8 @@ class Diaspora {
$datarray = array();
$datarray["protocol"] = PROTOCOL_DIASPORA;
$datarray["uid"] = $importer["uid"];
$datarray["contact-id"] = $author_contact["cid"];
$datarray["network"] = $author_contact["network"];
@ -1684,12 +1783,11 @@ class Diaspora {
* @return bool Success?
*/
private static function receive_message($importer, $data) {
$author = notags(unxmlify($data->author));
$guid = notags(unxmlify($data->guid));
$parent_guid = notags(unxmlify($data->parent_guid));
$conversation_guid = notags(unxmlify($data->conversation_guid));
$text = unxmlify($data->text);
$created_at = datetime_convert("UTC", "UTC", notags(unxmlify($data->created_at)));
$author = notags(unxmlify($data->author));
$conversation_guid = notags(unxmlify($data->conversation_guid));
$contact = self::allowed_contact_by_handle($importer, $author, true);
if (!$contact) {
@ -1717,8 +1815,8 @@ class Diaspora {
return false;
}
$r = q("SELECT `id` FROM `mail` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
dbesc($message_uri),
$r = q("SELECT `id` FROM `mail` WHERE `guid` = '%s' AND `uid` = %d LIMIT 1",
dbesc($guid),
intval($importer["uid"])
);
if (dbm::is_result($r)) {
@ -1744,7 +1842,7 @@ class Diaspora {
0,
1,
dbesc($message_uri),
dbesc($author.":".$parent_guid),
dbesc($author.":".$conversation["guid"]),
dbesc($created_at)
);
@ -1813,9 +1911,9 @@ class Diaspora {
$name = unxmlify($data->first_name).((strlen($data->last_name)) ? " ".unxmlify($data->last_name) : "");
$image_url = unxmlify($data->image_url);
$birthday = unxmlify($data->birthday);
$location = diaspora2bb(unxmlify($data->location));
$about = diaspora2bb(unxmlify($data->bio));
$gender = unxmlify($data->gender);
$about = diaspora2bb(unxmlify($data->bio));
$location = diaspora2bb(unxmlify($data->location));
$searchable = (unxmlify($data->searchable) == "true");
$nsfw = (unxmlify($data->nsfw) == "true");
$tags = unxmlify($data->tag_string);
@ -1919,6 +2017,7 @@ class Diaspora {
if ($self && $contact["rel"] == CONTACT_IS_FOLLOWER) {
$arr = array();
$arr["protocol"] = PROTOCOL_DIASPORA;
$arr["uri"] = $arr["parent-uri"] = item_new_uri($a->get_hostname(), $importer["uid"]);
$arr["uid"] = $importer["uid"];
$arr["contact-id"] = $self[0]["id"];
@ -2234,12 +2333,13 @@ class Diaspora {
* @return int the message id
*/
private static function receive_reshare($importer, $data, $xml) {
$author = notags(unxmlify($data->author));
$guid = notags(unxmlify($data->guid));
$created_at = datetime_convert("UTC", "UTC", notags(unxmlify($data->created_at)));
$root_author = notags(unxmlify($data->root_author));
$root_guid = notags(unxmlify($data->root_guid));
$guid = notags(unxmlify($data->guid));
$author = notags(unxmlify($data->author));
/// @todo handle unprocessed property "provider_display_name"
$public = notags(unxmlify($data->public));
$created_at = datetime_convert("UTC", "UTC", notags(unxmlify($data->created_at)));
$contact = self::allowed_contact_by_handle($importer, $author, false);
if (!$contact) {
@ -2278,7 +2378,8 @@ class Diaspora {
$datarray["verb"] = ACTIVITY_POST;
$datarray["gravity"] = GRAVITY_PARENT;
$datarray["object"] = $xml;
$datarray["protocol"] = PROTOCOL_DIASPORA;
$datarray["source"] = $xml;
$prefix = share_header($original_item["author-name"], $original_item["author-link"], $original_item["author-avatar"],
$original_item["guid"], $original_item["created"], $orig_url);
@ -2313,9 +2414,9 @@ class Diaspora {
* @return bool success
*/
private static function item_retraction($importer, $contact, $data) {
$target_type = notags(unxmlify($data->target_type));
$target_guid = notags(unxmlify($data->target_guid));
$author = notags(unxmlify($data->author));
$target_guid = notags(unxmlify($data->target_guid));
$target_type = notags(unxmlify($data->target_type));
$person = self::person_by_handle($author);
if (!is_array($person)) {
@ -2323,11 +2424,16 @@ class Diaspora {
return false;
}
if (!isset($contact["url"])) {
$contact["url"] = $person["url"];
}
$r = q("SELECT `id`, `parent`, `parent-uri`, `author-link` FROM `item` WHERE `guid` = '%s' AND `uid` = %d AND NOT `file` LIKE '%%[%%' LIMIT 1",
dbesc($target_guid),
intval($importer["uid"])
);
if (!$r) {
logger("Target guid ".$target_guid." was not found for user ".$importer["uid"]);
return false;
}
@ -2373,7 +2479,7 @@ class Diaspora {
$target_type = notags(unxmlify($data->target_type));
$contact = self::contact_by_handle($importer["uid"], $sender);
if (!$contact) {
if (!$contact AND (in_array($target_type, array("Contact", "Person")))) {
logger("cannot find contact for sender: ".$sender." and user ".$importer["uid"]);
return false;
}
@ -2386,7 +2492,7 @@ class Diaspora {
case "Post": // "Post" will be supported in a future version
case "Reshare":
case "StatusMessage":
return self::item_retraction($importer, $contact, $data);;
return self::item_retraction($importer, $contact, $data);
case "Contact":
case "Person":
@ -2412,19 +2518,13 @@ class Diaspora {
* @return int The message id of the newly created item
*/
private static function receive_status_message($importer, $data, $xml) {
$raw_message = unxmlify($data->raw_message);
$guid = notags(unxmlify($data->guid));
$author = notags(unxmlify($data->author));
$public = notags(unxmlify($data->public));
$guid = notags(unxmlify($data->guid));
$created_at = datetime_convert("UTC", "UTC", notags(unxmlify($data->created_at)));
$public = notags(unxmlify($data->public));
$text = unxmlify($data->text);
$provider_display_name = notags(unxmlify($data->provider_display_name));
/// @todo enable support for polls
//if ($data->poll) {
// foreach ($data->poll AS $poll)
// print_r($poll);
// die("poll!\n");
//}
$contact = self::allowed_contact_by_handle($importer, $author, false);
if (!$contact) {
return false;
@ -2442,7 +2542,7 @@ class Diaspora {
}
}
$body = diaspora2bb($raw_message);
$body = diaspora2bb($text);
$datarray = array();
@ -2463,6 +2563,15 @@ class Diaspora {
}
}
/// @todo enable support for polls
//if ($data->poll) {
// foreach ($data->poll AS $poll)
// print_r($poll);
// die("poll!\n");
//}
/// @todo enable support for events
$datarray["uid"] = $importer["uid"];
$datarray["contact-id"] = $contact["id"];
$datarray["network"] = NETWORK_DIASPORA;
@ -2481,7 +2590,8 @@ class Diaspora {
$datarray["verb"] = ACTIVITY_POST;
$datarray["gravity"] = GRAVITY_PARENT;
$datarray["object"] = $xml;
$datarray["protocol"] = PROTOCOL_DIASPORA;
$datarray["source"] = $xml;
$datarray["body"] = self::replace_people_guid($body, $contact["url"]);
@ -3711,4 +3821,3 @@ class Diaspora {
return true;
}
}
?>

View file

@ -1,9 +1,9 @@
<?php
/// @TODO no longer used?
use \Friendica\Core\Config;
use Friendica\Core\Config;
function directory_run(&$argv, &$argc){
$dir = get_config('system', 'directory');
$dir = Config::get('system', 'directory');
if (!strlen($dir)) {
return;

View file

@ -1,9 +1,10 @@
<?php
use \Friendica\Core\Config;
use Friendica\Core\Config;
require_once('include/socgraph.php');
require_once('include/datetime.php');
require_once 'include/probe.php';
require_once 'include/socgraph.php';
require_once 'include/datetime.php';
function discover_poco_run(&$argv, &$argc) {

View file

@ -1,4 +1,7 @@
<?php
use Friendica\App;
require_once('include/Emailer.php');
require_once('include/email.php');
require_once('include/bbcode.php');

View file

@ -4,6 +4,8 @@
* @brief functions specific to event handling
*/
use Friendica\App;
require_once 'include/bbcode.php';
require_once 'include/map.php';
require_once 'include/datetime.php';
@ -81,74 +83,6 @@ function format_event_html($ev, $simple = false) {
return $o;
}
/*
@TODO old-lost code found?
function parse_event($h) {
require_once('include/Scrape.php');
require_once('include/html2bbcode');
$h = '<html><body>' . $h . '</body></html>';
$ret = array();
try {
$dom = HTML5_Parser::parse($h);
} catch (DOMException $e) {
logger('parse_event: parse error: ' . $e);
}
if (! $dom)
return $ret;
$items = $dom->getElementsByTagName('*');
foreach ($items as $item) {
if (attribute_contains($item->getAttribute('class'), 'vevent')) {
$level2 = $item->getElementsByTagName('*');
foreach ($level2 as $x) {
if (attribute_contains($x->getAttribute('class'),'dtstart') && $x->getAttribute('title')) {
$ret['start'] = $x->getAttribute('title');
if (! strpos($ret['start'],'Z'))
$ret['adjust'] = true;
}
if (attribute_contains($x->getAttribute('class'),'dtend') && $x->getAttribute('title'))
$ret['finish'] = $x->getAttribute('title');
if (attribute_contains($x->getAttribute('class'),'description'))
$ret['desc'] = $x->textContent;
if (attribute_contains($x->getAttribute('class'),'location'))
$ret['location'] = $x->textContent;
}
}
}
// sanitise
if ((x($ret,'desc')) && ((strpos($ret['desc'],'<') !== false) || (strpos($ret['desc'],'>') !== false))) {
$config = HTMLPurifier_Config::createDefault();
$config->set('Cache.DefinitionImpl', null);
$purifier = new HTMLPurifier($config);
$ret['desc'] = html2bbcode($purifier->purify($ret['desc']));
}
if ((x($ret,'location')) && ((strpos($ret['location'],'<') !== false) || (strpos($ret['location'],'>') !== false))) {
$config = HTMLPurifier_Config::createDefault();
$config->set('Cache.DefinitionImpl', null);
$purifier = new HTMLPurifier($config);
$ret['location'] = html2bbcode($purifier->purify($ret['location']));
}
if (x($ret,'start'))
$ret['start'] = datetime_convert('UTC','UTC',$ret['start']);
if (x($ret,'finish'))
$ret['finish'] = datetime_convert('UTC','UTC',$ret['finish']);
return $ret;
}
*/
function format_event_bbcode($ev) {
$o = '';
@ -535,7 +469,7 @@ function get_event_strings() {
*
* @param array $dates Array of possibly duplicated events
* @return array Cleaned events
*
*
* @todo We should replace this with a separate update function if there is some time left
*/
function event_remove_duplicates($dates) {

View file

@ -1,6 +1,6 @@
<?php
use \Friendica\Core\Config;
use Friendica\Core\Config;
function expire_run(&$argv, &$argc){
global $a;

View file

@ -366,4 +366,3 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
return array("header" => $author, "items" => $items);
}
}
?>

View file

@ -47,4 +47,3 @@ function update_files_for_items() {
create_files_from_item($message["id"]);
}
}
?>

View file

@ -1,11 +1,14 @@
<?php
require_once("include/Scrape.php");
require_once("include/socgraph.php");
require_once('include/group.php');
require_once('include/salmon.php');
require_once('include/ostatus.php');
require_once("include/Photo.php");
require_once('include/diaspora.php');
use Friendica\App;
require_once 'include/probe.php';
require_once 'include/socgraph.php';
require_once 'include/group.php';
require_once 'include/salmon.php';
require_once 'include/ostatus.php';
require_once 'include/Photo.php';
require_once 'include/diaspora.php';
function update_contact($id) {
/*
@ -82,6 +85,11 @@ function new_contact($uid,$url,$interactive = false) {
return $result;
}
if (blocked_url($url)) {
$result['message'] = t('Blocked domain');
return $result;
}
if (! $url) {
$result['message'] = t('Connect URL missing.');
return $result;

View file

@ -1,10 +1,10 @@
<?php
use \Friendica\Core\Config;
use Friendica\Core\Config;
require_once('include/Scrape.php');
require_once('include/socgraph.php');
require_once('include/datetime.php');
require_once 'include/probe.php';
require_once 'include/socgraph.php';
require_once 'include/datetime.php';
function gprobe_run(&$argv, &$argc){
if ($argc != 2) {

View file

@ -325,4 +325,3 @@ function html2bbcode($message)
return $message;
}
?>

View file

@ -233,4 +233,3 @@ function html2plain($html, $wraplength = 75, $compact = false)
return(trim($message));
}
?>

View file

@ -3,6 +3,8 @@
* @file include/identity.php
*/
use Friendica\App;
require_once 'include/ForumManager.php';
require_once 'include/bbcode.php';
require_once 'mod/proxy.php';

View file

@ -4,7 +4,8 @@
* @file include/items.php
*/
use \Friendica\ParseUrl;
use Friendica\App;
use Friendica\ParseUrl;
require_once 'include/bbcode.php';
require_once 'include/oembed.php';
@ -339,7 +340,7 @@ function add_page_info_to_body($body, $texturl = false, $no_photos = false) {
* Adds a "lang" specification in a "postopts" element of given $arr,
* if possible and not already present.
* Expects "body" element to exist in $arr.
*
*
* @todo Add a parameter to request forcing override
*/
function item_add_language_opt(&$arr) {
@ -410,7 +411,70 @@ function uri_to_guid($uri, $host = "") {
return $guid_prefix.$host_hash;
}
/// @TODO Maybe $arr must be called-by-reference? This function modifies it
/**
* @brief Store the conversation data
*
* @param array $arr Item array with conversation data
* @return array Item array with removed conversation data
*/
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'])) {
$conversation['reply-to-uri'] = $arr['parent-uri'];
}
if (isset($arr['thr-parent']) AND ($arr['thr-parent'] != $arr['uri'])) {
$conversation['reply-to-uri'] = $arr['thr-parent'];
}
if (isset($arr['conversation-uri'])) {
$conversation['conversation-uri'] = $arr['conversation-uri'];
}
if (isset($arr['conversation-href'])) {
$conversation['conversation-href'] = $arr['conversation-href'];
}
if (isset($arr['protocol'])) {
$conversation['protocol'] = $arr['protocol'];
}
if (isset($arr['source'])) {
$conversation['source'] = $arr['source'];
}
$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)) {
// Don't update when only the source has changed.
// Only do this when there had been no source before.
if ($old_conv['source'] != '') {
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)) {
unset($conversation['protocol']);
unset($conversation['source']);
}
if (!dba::update('conversation', $conversation, array('item-uri' => $conversation['item-uri']), $old_conv)) {
logger('Conversation: update for '.$conversation['item-uri'].' from '.$conv['protocol'].' to '.$conversation['protocol'].' failed', LOGGER_DEBUG);
}
} else {
if (!dba::insert('conversation', $conversation)) {
logger('Conversation: insert for '.$conversation['item-uri'].' (protocol '.$conversation['protocol'].') failed', LOGGER_DEBUG);
}
}
}
unset($arr['conversation-uri']);
unset($arr['conversation-href']);
unset($arr['protocol']);
unset($arr['source']);
return $arr;
}
/// @TODO add type-hint array
function item_store($arr, $force_parent = false, $notify = false, $dontcache = false) {
@ -423,6 +487,7 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f
$arr['origin'] = 1;
$arr['last-child'] = 1;
$arr['network'] = NETWORK_DFRN;
$arr['protocol'] = PROTOCOL_DFRN;
// We have to avoid duplicates. So we create the GUID in form of a hash of the plink or uri.
// In difference to the call to "uri_to_guid" several lines below we add the hash of our own host.
@ -436,6 +501,9 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f
}
}
// Store conversation data
$arr = store_conversation($arr);
/*
* If a Diaspora signature structure was passed in, pull it out of the
* item array and set it aside for later storage.
@ -690,6 +758,7 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f
item_body_set_hashtags($arr);
$arr['thr-parent'] = $arr['parent-uri'];
if ($arr['parent-uri'] === $arr['uri']) {
$parent_id = 0;
$parent_deleted = 0;

View file

@ -1,4 +1,7 @@
<?php
use Friendica\App;
require_once("include/diaspora.php");
/**

View file

@ -1,9 +1,8 @@
<?php
// send a private message
// send a private message
use Friendica\App;
function send_message($recipient=0, $body='', $subject='', $replyto=''){
@ -175,7 +174,7 @@ function send_wallmessage($recipient='', $body='', $subject='', $replyto=''){
$convid = 0;
$reply = false;
require_once('include/Scrape.php');
require_once 'include/probe.php';
$me = probe_url($replyto);

View file

@ -187,7 +187,7 @@ function removelinebreak($message)
(substr(trim($nextline), 0, 7) == 'http://') or
(substr(trim($nextline), 0, 8) == 'https://'));
if (!$specialchars)
if (!$specialchars)
$specialchars = ((substr(rtrim($line), -1) == '-') or
(substr(rtrim($line), -1) == '=') or
(substr(rtrim($line), -1) == '*') or
@ -222,4 +222,3 @@ function removelinebreak($message)
return(implode("\n", $lines));
}
?>

View file

@ -1,5 +1,7 @@
<?php
use Friendica\App;
function nav(App $a) {
/*
@ -86,9 +88,9 @@ function nav_info(App $a)
$nav['usermenu'][] = array('notes/', t('Personal notes'), '', t('Your personal notes'));
// user info
$r = q("SELECT `micro` FROM `contact` WHERE `uid` = %d AND `self` = 1", intval($a->user['uid']));
$r = dba::select('contact', array('micro'), array('uid' => $a->user['uid'], 'self' => true), array('limit' => 1));
$userinfo = array(
'icon' => (dbm::is_result($r) ? $a->remove_baseurl($r[0]['micro']) : 'images/person-48.jpg'),
'icon' => (dbm::is_result($r) ? $a->remove_baseurl($r['micro']) : 'images/person-48.jpg'),
'name' => $a->user['username'],
);
} else {

View file

@ -4,10 +4,11 @@
* @file include/network.php
*/
use \Friendica\Core\Config;
use Friendica\App;
use Friendica\Core\Config;
use Friendica\Network\Probe;
require_once("include/xml.php");
require_once('include/Probe.php');
/**
* @brief Curl wrapper
@ -62,23 +63,27 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_
* string 'header' => HTTP headers
* string 'body' => fetched content
*/
function z_fetch_url($url,$binary = false, &$redirects = 0, $opts=array()) {
$ret = array('return_code' => 0, 'success' => false, 'header' => "", 'body' => "");
function z_fetch_url($url, $binary = false, &$redirects = 0, $opts = array()) {
$ret = array('return_code' => 0, 'success' => false, 'header' => '', 'body' => '');
$stamp1 = microtime(true);
$a = get_app();
if (blocked_url($url)) {
logger('z_fetch_url: domain of ' . $url . ' is blocked', LOGGER_DATA);
return $ret;
}
$ch = @curl_init($url);
if (($redirects > 8) || (! $ch)) {
if (($redirects > 8) || (!$ch)) {
return $ret;
}
@curl_setopt($ch, CURLOPT_HEADER, true);
if (x($opts,"cookiejar")) {
if (x($opts, "cookiejar")) {
curl_setopt($ch, CURLOPT_COOKIEJAR, $opts["cookiejar"]);
curl_setopt($ch, CURLOPT_COOKIEFILE, $opts["cookiejar"]);
}
@ -87,52 +92,61 @@ function z_fetch_url($url,$binary = false, &$redirects = 0, $opts=array()) {
// @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
// @curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
if (x($opts,'accept_content')){
curl_setopt($ch,CURLOPT_HTTPHEADER, array (
"Accept: " . $opts['accept_content']
if (x($opts, 'accept_content')) {
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept: ' . $opts['accept_content']
));
}
@curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@curl_setopt($ch, CURLOPT_USERAGENT, $a->get_useragent());
$range = intval(Config::get('system', 'curl_range_bytes', 0));
if ($range > 0) {
@curl_setopt($ch, CURLOPT_RANGE, '0-'.$range);
@curl_setopt($ch, CURLOPT_RANGE, '0-' . $range);
}
if (x($opts,'headers')){
if (x($opts, 'headers')) {
@curl_setopt($ch, CURLOPT_HTTPHEADER, $opts['headers']);
}
if (x($opts,'nobody')){
if (x($opts, 'nobody')) {
@curl_setopt($ch, CURLOPT_NOBODY, $opts['nobody']);
}
if (x($opts,'timeout')){
if (x($opts, 'timeout')) {
@curl_setopt($ch, CURLOPT_TIMEOUT, $opts['timeout']);
} else {
$curl_time = intval(get_config('system','curl_timeout'));
$curl_time = intval(get_config('system', 'curl_timeout'));
@curl_setopt($ch, CURLOPT_TIMEOUT, (($curl_time !== false) ? $curl_time : 60));
}
// by default we will allow self-signed certs
// but you can override this
$check_cert = get_config('system','verifyssl');
$check_cert = get_config('system', 'verifyssl');
@curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, (($check_cert) ? true : false));
if ($check_cert) {
@curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
}
$prx = get_config('system','proxy');
if (strlen($prx)) {
$proxy = get_config('system', 'proxy');
if (strlen($proxy)) {
@curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
@curl_setopt($ch, CURLOPT_PROXY, $prx);
$prxusr = @get_config('system','proxyuser');
if (strlen($prxusr))
@curl_setopt($ch, CURLOPT_PROXYUSERPWD, $prxusr);
@curl_setopt($ch, CURLOPT_PROXY, $proxy);
$proxyuser = @get_config('system', 'proxyuser');
if (strlen($proxyuser)) {
@curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyuser);
}
}
if ($binary) {
@curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
}
if ($binary)
@curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$a->set_curl_code(0);
@ -140,8 +154,9 @@ function z_fetch_url($url,$binary = false, &$redirects = 0, $opts=array()) {
// if it throws any errors.
$s = @curl_exec($ch);
if (curl_errno($ch) !== CURLE_OK) {
logger('fetch_url error fetching '.$url.': '.curl_error($ch), LOGGER_NORMAL);
logger('fetch_url error fetching ' . $url . ': ' . curl_error($ch), LOGGER_NORMAL);
}
$ret['errno'] = curl_errno($ch);
@ -150,16 +165,16 @@ function z_fetch_url($url,$binary = false, &$redirects = 0, $opts=array()) {
$curl_info = @curl_getinfo($ch);
$http_code = $curl_info['http_code'];
logger('fetch_url '.$url.': '.$http_code." ".$s, LOGGER_DATA);
logger('fetch_url ' . $url . ': ' . $http_code . " " . $s, LOGGER_DATA);
$header = '';
// Pull out multiple headers, e.g. proxy and continuation headers
// allow for HTTP/2.x without fixing code
while (preg_match('/^HTTP\/[1-2].+? [1-5][0-9][0-9]/',$base)) {
$chunk = substr($base,0,strpos($base,"\r\n\r\n")+4);
while (preg_match('/^HTTP\/[1-2].+? [1-5][0-9][0-9]/', $base)) {
$chunk = substr($base, 0, strpos($base,"\r\n\r\n") + 4);
$header .= $chunk;
$base = substr($base,strlen($chunk));
$base = substr($base, strlen($chunk));
}
$a->set_curl_code($http_code);
@ -167,92 +182,100 @@ function z_fetch_url($url,$binary = false, &$redirects = 0, $opts=array()) {
$a->set_curl_headers($header);
if ($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307) {
$new_location_info = @parse_url($curl_info["redirect_url"]);
$old_location_info = @parse_url($curl_info["url"]);
$new_location_info = @parse_url($curl_info['redirect_url']);
$old_location_info = @parse_url($curl_info['url']);
$newurl = $curl_info["redirect_url"];
$newurl = $curl_info['redirect_url'];
if (($new_location_info["path"] == "") AND ($new_location_info["host"] != ""))
$newurl = $new_location_info["scheme"]."://".$new_location_info["host"].$old_location_info["path"];
if (($new_location_info['path'] == '') AND ( $new_location_info['host'] != '')) {
$newurl = $new_location_info['scheme'] . '://' . $new_location_info['host'] . $old_location_info['path'];
}
$matches = array();
if (preg_match('/(Location:|URI:)(.*?)\n/i', $header, $matches)) {
$newurl = trim(array_pop($matches));
}
if (strpos($newurl,'/') === 0)
if (strpos($newurl,'/') === 0) {
$newurl = $old_location_info["scheme"]."://".$old_location_info["host"].$newurl;
}
if (filter_var($newurl, FILTER_VALIDATE_URL)) {
$redirects++;
@curl_close($ch);
return z_fetch_url($newurl,$binary, $redirects, $opts);
return z_fetch_url($newurl, $binary, $redirects, $opts);
}
}
$a->set_curl_code($http_code);
$a->set_curl_content_type($curl_info['content_type']);
$body = substr($s,strlen($header));
$body = substr($s, strlen($header));
$rc = intval($http_code);
$ret['return_code'] = $rc;
$ret['success'] = (($rc >= 200 && $rc <= 299) ? true : false);
$ret['redirect_url'] = $url;
if (! $ret['success']) {
if (!$ret['success']) {
$ret['error'] = curl_error($ch);
$ret['debug'] = $curl_info;
logger('z_fetch_url: error: ' . $url . ': ' . $ret['error'], LOGGER_DEBUG);
logger('z_fetch_url: debug: ' . print_r($curl_info,true), LOGGER_DATA);
logger('z_fetch_url: debug: ' . print_r($curl_info, true), LOGGER_DATA);
}
$ret['body'] = substr($s,strlen($header));
$ret['body'] = substr($s, strlen($header));
$ret['header'] = $header;
if (x($opts,'debug')) {
if (x($opts, 'debug')) {
$ret['debug'] = $curl_info;
}
@curl_close($ch);
$a->save_timestamp($stamp1, "network");
$a->save_timestamp($stamp1, 'network');
return($ret);
}
// post request to $url. $params is an array of post variables.
/**
* @brief Post request to $url
* @brief Send POST request to $url
*
* @param string $url URL to post
* @param mixed $params
* @param mixed $params array of POST variables
* @param string $headers HTTP headers
* @param integer $redirects Recursion counter for internal use - default = 0
* @param integer $timeout The timeout in seconds, default system config value or 60 seconds
*
* @return string The content
*/
function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0) {
function post_url($url, $params, $headers = null, &$redirects = 0, $timeout = 0) {
$stamp1 = microtime(true);
if (blocked_url($url)) {
logger('post_url: domain of ' . $url . ' is blocked', LOGGER_DATA);
return false;
}
$a = get_app();
$ch = curl_init($url);
if (($redirects > 8) || (! $ch))
return false;
logger("post_url: start ".$url, LOGGER_DATA);
if (($redirects > 8) || (!$ch)) {
return false;
}
logger('post_url: start ' . $url, LOGGER_DATA);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$params);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_USERAGENT, $a->get_useragent());
if (intval($timeout)) {
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
}
else {
$curl_time = intval(get_config('system','curl_timeout'));
} else {
$curl_time = intval(get_config('system', 'curl_timeout'));
curl_setopt($ch, CURLOPT_TIMEOUT, (($curl_time !== false) ? $curl_time : 60));
}
@ -265,21 +288,27 @@ function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0)
}
}
}
if ($headers)
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$check_cert = get_config('system','verifyssl');
if ($headers) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
$check_cert = get_config('system', 'verifyssl');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, (($check_cert) ? true : false));
if ($check_cert) {
@curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
}
$prx = get_config('system','proxy');
if (strlen($prx)) {
$proxy = get_config('system', 'proxy');
if (strlen($proxy)) {
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($ch, CURLOPT_PROXY, $prx);
$prxusr = get_config('system','proxyuser');
if (strlen($prxusr))
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $prxusr);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
$proxyuser = get_config('system', 'proxyuser');
if (strlen($proxyuser)) {
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyuser);
}
}
$a->set_curl_code(0);
@ -293,44 +322,48 @@ function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0)
$curl_info = curl_getinfo($ch);
$http_code = $curl_info['http_code'];
logger("post_url: result ".$http_code." - ".$url, LOGGER_DATA);
logger('post_url: result ' . $http_code . ' - ' . $url, LOGGER_DATA);
$header = '';
// Pull out multiple headers, e.g. proxy and continuation headers
// allow for HTTP/2.x without fixing code
while (preg_match('/^HTTP\/[1-2].+? [1-5][0-9][0-9]/',$base)) {
$chunk = substr($base,0,strpos($base,"\r\n\r\n")+4);
while (preg_match('/^HTTP\/[1-2].+? [1-5][0-9][0-9]/', $base)) {
$chunk = substr($base, 0, strpos($base, "\r\n\r\n") + 4);
$header .= $chunk;
$base = substr($base,strlen($chunk));
$base = substr($base, strlen($chunk));
}
if ($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307) {
$matches = array();
preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches);
$newurl = trim(array_pop($matches));
if (strpos($newurl,'/') === 0)
if (strpos($newurl, '/') === 0) {
$newurl = $old_location_info["scheme"] . "://" . $old_location_info["host"] . $newurl;
}
if (filter_var($newurl, FILTER_VALIDATE_URL)) {
$redirects++;
logger("post_url: redirect ".$url." to ".$newurl);
return post_url($newurl,$params, $headers, $redirects, $timeout);
//return fetch_url($newurl,false,$redirects,$timeout);
logger('post_url: redirect ' . $url . ' to ' . $newurl);
return post_url($newurl, $params, $headers, $redirects, $timeout);
}
}
$a->set_curl_code($http_code);
$body = substr($s,strlen($header));
$body = substr($s, strlen($header));
$a->set_curl_headers($header);
curl_close($ch);
$a->save_timestamp($stamp1, "network");
$a->save_timestamp($stamp1, 'network');
logger("post_url: end ".$url, LOGGER_DATA);
logger('post_url: end ' . $url, LOGGER_DATA);
return($body);
return $body;
}
// Generic XML return
@ -458,26 +491,27 @@ function allowed_url($url) {
return false;
}
$str_allowed = get_config('system','allowed_sites');
if (! $str_allowed)
$str_allowed = Config::get('system', 'allowed_sites');
if (! $str_allowed) {
return true;
}
$found = false;
$host = strtolower($h['host']);
// always allow our own site
if ($host == strtolower($_SERVER['SERVER_NAME']))
if ($host == strtolower($_SERVER['SERVER_NAME'])) {
return true;
}
$fnmatch = function_exists('fnmatch');
$allowed = explode(',',$str_allowed);
$allowed = explode(',', $str_allowed);
if (count($allowed)) {
foreach ($allowed as $a) {
$pat = strtolower(trim($a));
if (($fnmatch && fnmatch($pat,$host)) || ($pat == $host)) {
if (($fnmatch && fnmatch($pat, $host)) || ($pat == $host)) {
$found = true;
break;
}
@ -486,6 +520,36 @@ function allowed_url($url) {
return $found;
}
/**
* Checks if the provided url domain is on the domain blocklist.
* Returns true if it is or malformed URL, false if not.
*
* @param string $url The url to check the domain from
* @return boolean
*/
function blocked_url($url) {
$h = @parse_url($url);
if (! $h) {
return true;
}
$domain_blocklist = Config::get('system', 'blocklist', array());
if (! $domain_blocklist) {
return false;
}
$host = strtolower($h['host']);
foreach ($domain_blocklist as $domain_block) {
if (strtolower($domain_block['domain']) == $host) {
return true;
}
}
return false;
}
/**
* @brief Check if email address is allowed to register here.
*
@ -659,22 +723,7 @@ function fix_contact_ssl_policy(&$contact,$new_policy) {
}
if ($ssl_changed) {
q("UPDATE `contact` SET
`url` = '%s',
`request` = '%s',
`notify` = '%s',
`poll` = '%s',
`confirm` = '%s',
`poco` = '%s'
WHERE `id` = %d LIMIT 1",
dbesc($contact['url']),
dbesc($contact['request']),
dbesc($contact['notify']),
dbesc($contact['poll']),
dbesc($contact['confirm']),
dbesc($contact['poco']),
intval($contact['id'])
);
dba::update('contact', $contact, array('id' => $contact['id']));
}
}

View file

@ -1,13 +1,14 @@
<?php
use \Friendica\Core\Config;
use Friendica\App;
use Friendica\Core\Config;
require_once('include/queue_fn.php');
require_once('include/html2plain.php');
require_once('include/Scrape.php');
require_once('include/diaspora.php');
require_once('include/ostatus.php');
require_once('include/salmon.php');
require_once 'include/queue_fn.php';
require_once 'include/html2plain.php';
require_once 'include/probe.php';
require_once 'include/diaspora.php';
require_once 'include/ostatus.php';
require_once 'include/salmon.php';
/*
* This file was at one time responsible for doing all deliveries, but this caused
@ -45,10 +46,10 @@ require_once('include/salmon.php');
function notifier_run(&$argv, &$argc){
global $a;
require_once('include/datetime.php');
require_once('include/items.php');
require_once('include/bbcode.php');
require_once('include/email.php');
require_once 'include/datetime.php';
require_once 'include/items.php';
require_once 'include/bbcode.php';
require_once 'include/email.php';
if ($argc < 3) {
return;
@ -138,7 +139,7 @@ function notifier_run(&$argv, &$argc){
if (!$r) {
return;
}
require_once('include/Contact.php');
require_once 'include/Contact.php';
foreach ($r as $contact) {
terminate_friendship($user, $self, $contact);
}
@ -222,7 +223,7 @@ function notifier_run(&$argv, &$argc){
$slap = ostatus::salmon($target_item,$owner);
require_once('include/group.php');
require_once 'include/group.php';
$parent = $items[0];

View file

@ -5,6 +5,8 @@
*
*/
use Friendica\App;
define('REQUEST_TOKEN_DURATION', 300);
define('ACCESS_TOKEN_DURATION', 31536000);
@ -61,13 +63,13 @@ class FKOAuthDataStore extends OAuthDataStore {
logger(__function__.":".$consumer.", ". $callback);
$key = $this->gen_token();
$sec = $this->gen_token();
if ($consumer->key){
$k = $consumer->key;
} else {
$k = $consumer;
}
$r = q("INSERT INTO tokens (id, secret, client_id, scope, expires) VALUES ('%s','%s','%s','%s', UNIX_TIMESTAMP()+%d)",
dbesc($key),
dbesc($sec),
@ -80,19 +82,19 @@ class FKOAuthDataStore extends OAuthDataStore {
function new_access_token($token, $consumer, $verifier = null) {
logger(__function__.":".$token.", ". $consumer.", ". $verifier);
// return a new access token attached to this consumer
// for the user associated with this token if the request token
// is authorized
// should also invalidate the request token
$ret=Null;
// get user for this verifier
$uverifier = get_config("oauth", $verifier);
logger(__function__.":".$verifier.",".$uverifier);
if (is_null($verifier) || ($uverifier!==false)){
$key = $this->gen_token();
$sec = $this->gen_token();
$r = q("INSERT INTO tokens (id, secret, client_id, scope, expires, uid) VALUES ('%s','%s','%s','%s', UNIX_TIMESTAMP()+%d, %d)",
@ -103,13 +105,13 @@ class FKOAuthDataStore extends OAuthDataStore {
intval(ACCESS_TOKEN_DURATION),
intval($uverifier));
if ($r)
$ret = new OAuthToken($key,$sec);
$ret = new OAuthToken($key,$sec);
}
q("DELETE FROM tokens WHERE id='%s'", $token->key);
if (!is_null($ret) && $uverifier!==false){
del_config("oauth", $verifier);
/* $apps = get_pconfig($uverifier, "oauth", "apps");
@ -117,9 +119,9 @@ class FKOAuthDataStore extends OAuthDataStore {
$apps[] = $consumer->key;
set_pconfig($uverifier, "oauth", "apps", $apps);*/
}
return $ret;
}
}
@ -172,9 +174,9 @@ class FKOAuth1 extends OAuthServer {
intval($_SESSION['uid'])
);
call_hooks('logged_in', $a->user);
call_hooks('logged_in', $a->user);
}
}
/*
class FKOAuth2 extends OAuth2 {
@ -190,13 +192,13 @@ class FKOAuth2 extends OAuth2 {
dbesc($client_secret),
dbesc($redirect_uri)
);
return $r;
}
protected function checkClientCredentials($client_id, $client_secret = NULL) {
$client_secret = $this->db_secret($client_secret);
$r = q("SELECT pw FROM clients WHERE client_id = '%s'",
dbesc($client_id));
@ -218,21 +220,21 @@ class FKOAuth2 extends OAuth2 {
protected function getAccessToken($oauth_token) {
$r = q("SELECT client_id, expires, scope FROM tokens WHERE id = '%s'",
dbesc($oauth_token));
if (dbm::is_result($r))
return $r[0];
return null;
}
protected function setAccessToken($oauth_token, $client_id, $expires, $scope = NULL) {
$r = q("INSERT INTO tokens (id, client_id, expires, scope) VALUES ('%s', '%s', %d, '%s')",
dbesc($oauth_token),
dbesc($client_id),
intval($expires),
dbesc($scope));
return $r;
}
@ -246,23 +248,23 @@ class FKOAuth2 extends OAuth2 {
protected function getAuthCode($code) {
$r = q("SELECT id, client_id, redirect_uri, expires, scope FROM auth_codes WHERE id = '%s'",
dbesc($code));
if (dbm::is_result($r))
return $r[0];
return null;
}
protected function setAuthCode($code, $client_id, $redirect_uri, $expires, $scope = NULL) {
$r = q("INSERT INTO auth_codes
(id, client_id, redirect_uri, expires, scope) VALUES
$r = q("INSERT INTO auth_codes
(id, client_id, redirect_uri, expires, scope) VALUES
('%s', '%s', '%s', %d, '%s')",
dbesc($code),
dbesc($client_id),
dbesc($redirect_uri),
intval($expires),
dbesc($scope));
return $r;
}
return $r;
}
}
*/

View file

@ -4,8 +4,9 @@
* @file include/oembed.php
*/
use \Friendica\ParseUrl;
use \Friendica\Core\Config;
use Friendica\App;
use Friendica\ParseUrl;
use Friendica\Core\Config;
function oembed_replacecb($matches){
$embedurl=$matches[1];

View file

@ -1,6 +1,6 @@
<?php
use \Friendica\Core\Config;
use Friendica\Core\Config;
require_once('include/follow.php');

View file

@ -3,20 +3,24 @@
* @file include/ostatus.php
*/
require_once("include/Contact.php");
require_once("include/threads.php");
require_once("include/html2bbcode.php");
require_once("include/bbcode.php");
require_once("include/items.php");
require_once("mod/share.php");
require_once("include/enotify.php");
require_once("include/socgraph.php");
require_once("include/Photo.php");
require_once("include/Scrape.php");
require_once("include/follow.php");
require_once("include/api.php");
require_once("mod/proxy.php");
require_once("include/xml.php");
use Friendica\App;
use Friendica\Core\Config;
use Friendica\Network\Probe;
require_once 'include/Contact.php';
require_once 'include/threads.php';
require_once 'include/html2bbcode.php';
require_once 'include/bbcode.php';
require_once 'include/items.php';
require_once 'mod/share.php';
require_once 'include/enotify.php';
require_once 'include/socgraph.php';
require_once 'include/Photo.php';
require_once 'include/probe.php';
require_once 'include/follow.php';
require_once 'include/api.php';
require_once 'mod/proxy.php';
require_once 'include/xml.php';
/**
* @brief This class contain functions for the OStatus protocol
@ -27,42 +31,6 @@ class ostatus {
const OSTATUS_DEFAULT_POLL_TIMEFRAME = 1440; // given in minutes
const OSTATUS_DEFAULT_POLL_TIMEFRAME_MENTIONS = 14400; // given in minutes
/**
* @brief Mix two paths together to possibly fix missing parts
*
* @param string $avatar Path to the avatar
* @param string $base Another path that is hopefully complete
*
* @return string fixed avatar path
*/
public static function fix_avatar($avatar, $base) {
$base_parts = parse_url($base);
// Remove all parts that could create a problem
unset($base_parts['path']);
unset($base_parts['query']);
unset($base_parts['fragment']);
$avatar_parts = parse_url($avatar);
// Now we mix them
$parts = array_merge($base_parts, $avatar_parts);
// And put them together again
$scheme = isset($parts['scheme']) ? $parts['scheme'] . '://' : '';
$host = isset($parts['host']) ? $parts['host'] : '';
$port = isset($parts['port']) ? ':' . $parts['port'] : '';
$path = isset($parts['path']) ? $parts['path'] : '';
$query = isset($parts['query']) ? '?' . $parts['query'] : '';
$fragment = isset($parts['fragment']) ? '#' . $parts['fragment'] : '';
$fixed = $scheme.$host.$port.$path.$query.$fragment;
logger('Base: '.$base.' - Avatar: '.$avatar.' - Fixed: '.$fixed, LOGGER_DATA);
return $fixed;
}
/**
* @brief Fetches author data
*
@ -79,26 +47,44 @@ class ostatus {
$author = array();
$author["author-link"] = $xpath->evaluate('atom:author/atom:uri/text()', $context)->item(0)->nodeValue;
$author["author-name"] = $xpath->evaluate('atom:author/atom:name/text()', $context)->item(0)->nodeValue;
$addr = $xpath->evaluate('atom:author/atom:email/text()', $context)->item(0)->nodeValue;
$aliaslink = $author["author-link"];
$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") {
foreach ($alternate AS $attributes) {
if (($attributes->name == "href") AND ($attributes->textContent != "")) {
$author["author-link"] = $attributes->textContent;
}
}
}
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `nurl` IN ('%s', '%s') AND `network` != '%s'",
intval($importer["uid"]), dbesc(normalise_link($author["author-link"])),
dbesc(normalise_link($aliaslink)), dbesc(NETWORK_STATUSNET));
if (dbm::is_result($r)) {
$contact = $r[0];
$author["contact-id"] = $r[0]["id"];
} else {
$author["contact-id"] = $contact["id"];
$author["contact-id"] = $contact["id"];
if ($author["author-link"] != "") {
if ($aliaslink == "") {
$aliaslink = $author["author-link"];
}
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `nurl` IN ('%s', '%s') AND `network` != '%s'",
intval($importer["uid"]), dbesc(normalise_link($author["author-link"])),
dbesc(normalise_link($aliaslink)), dbesc(NETWORK_STATUSNET));
if (dbm::is_result($r)) {
$contact = $r[0];
$author["contact-id"] = $r[0]["id"];
$author["author-link"] = $r[0]["url"];
}
} elseif ($addr != "") {
// Should not happen
$contact = dba::fetch_first("SELECT * FROM `contact` WHERE `uid` = ? AND `addr` = ? AND `network` != ?",
$importer["uid"], $addr, NETWORK_STATUSNET);
if (dbm::is_result($contact)) {
$author["contact-id"] = $contact["id"];
$author["author-link"] = $contact["url"];
}
}
$avatarlist = array();
@ -120,7 +106,7 @@ class ostatus {
}
if (count($avatarlist) > 0) {
krsort($avatarlist);
$author["author-avatar"] = self::fix_avatar(current($avatarlist), $author["author-link"]);
$author["author-avatar"] = Probe::fixAvatar(current($avatarlist), $author["author-link"]);
}
$displayname = $xpath->evaluate('atom:author/poco:displayName/text()', $context)->item(0)->nodeValue;
@ -320,8 +306,10 @@ class ostatus {
if ($first_child == "feed") {
$entries = $xpath->query('/atom:feed/atom:entry');
$header["protocol"] = PROTOCOL_OSTATUS_FEED;
} else {
$entries = $xpath->query('/atom:entry');
$header["protocol"] = PROTOCOL_OSTATUS_SALMON;
}
$conversation = "";
$conversationlist = array();
@ -378,7 +366,7 @@ class ostatus {
} elseif ($item["object-type"] == ACTIVITY_OBJ_QUESTION) {
$item["title"] = $xpath->query('atom:title/text()', $entry)->item(0)->nodeValue;
}
$item["object"] = $xml;
$item["source"] = $xml;
/// @TODO
/// Delete a message
@ -426,6 +414,19 @@ class ostatus {
$item["created"] = $xpath->query('atom:published/text()', $entry)->item(0)->nodeValue;
$item["edited"] = $xpath->query('atom:updated/text()', $entry)->item(0)->nodeValue;
$conversation = $xpath->query('ostatus:conversation/text()', $entry)->item(0)->nodeValue;
$item['conversation-uri'] = $conversation;
$conv = $xpath->query('ostatus:conversation', $entry);
if (is_object($conv->item(0))) {
foreach ($conv->item(0)->attributes AS $attributes) {
if ($attributes->name == "ref") {
$item['conversation-uri'] = $attributes->textContent;
}
if ($attributes->name == "href") {
$item['conversation-href'] = $attributes->textContent;
}
}
}
$related = "";
@ -479,6 +480,10 @@ class ostatus {
break;
case "ostatus:conversation":
$conversation = $attribute['href'];
$item['conversation-href'] = $conversation;
if (!isset($item['conversation-uri'])) {
$item['conversation-uri'] = $item['conversation-href'];
}
break;
case "enclosure":
$enclosure = $attribute['href'];
@ -905,6 +910,8 @@ class ostatus {
($item["verb"] == ACTIVITY_LIKE) OR ($conversation_url == "")) {
$item_stored = item_store($item, $all_threads);
return $item_stored;
} elseif (count($item) > 0) {
$item = store_conversation($item);
}
// Get the parent
@ -1162,13 +1169,17 @@ class ostatus {
$arr["owner-name"] = $single_conv->actor->portablecontacts_net->displayName;
$arr["owner-link"] = $actor;
$arr["owner-avatar"] = self::fix_avatar($single_conv->actor->image->url, $arr["owner-link"]);
$arr["owner-avatar"] = Probe::fixAvatar($single_conv->actor->image->url, $arr["owner-link"]);
$arr["author-name"] = $arr["owner-name"];
$arr["author-link"] = $arr["owner-link"];
$arr["author-avatar"] = $arr["owner-avatar"];
$arr["body"] = add_page_info_to_body(html2bbcode($single_conv->content));
if (isset($single_conv->status_net->conversation)) {
$arr['conversation-uri'] = $single_conv->status_net->conversation;
}
if (isset($single_conv->status_net->notice_info->source))
$arr["app"] = strip_tags($single_conv->status_net->notice_info->source);
elseif (isset($single_conv->statusnet->notice_info->source))
@ -1181,7 +1192,9 @@ class ostatus {
$arr["app"] = "OStatus";
$arr["object"] = json_encode($single_conv);
$arr["source"] = json_encode($single_conv);
$arr["protocol"] = PROTOCOL_GS_CONVERSATION;
$arr["verb"] = $parent["verb"];
$arr["visible"] = $parent["visible"];
$arr["location"] = $single_conv->location->displayName;
@ -1221,7 +1234,7 @@ class ostatus {
$arr["author-name"] = $single_conv->object->actor->contact->displayName;
}
$arr["author-link"] = $single_conv->object->actor->url;
$arr["author-avatar"] = self::fix_avatar($single_conv->object->actor->image->url, $arr["author-link"]);
$arr["author-avatar"] = Probe::fixAvatar($single_conv->object->actor->image->url, $arr["author-link"]);
$arr["app"] = $single_conv->object->provider->displayName."#";
//$arr["verb"] = $single_conv->object->verb;
@ -1413,6 +1426,7 @@ class ostatus {
$root->setAttribute("xmlns:poco", NAMESPACE_POCO);
$root->setAttribute("xmlns:ostatus", NAMESPACE_OSTATUS);
$root->setAttribute("xmlns:statusnet", NAMESPACE_STATUSNET);
$root->setAttribute("xmlns:mastodon", NAMESPACE_MASTODON);
$attributes = array("uri" => "https://friendi.ca", "version" => FRIENDICA_VERSION."-".DB_UPDATE_VERSION);
xml::add_element($doc, $root, "generator", FRIENDICA_PLATFORM, $attributes);
@ -1551,14 +1565,16 @@ class ostatus {
*/
private function add_author($doc, $owner) {
$r = q("SELECT `homepage` FROM `profile` WHERE `uid` = %d AND `is-default` LIMIT 1", intval($owner["uid"]));
$r = q("SELECT `homepage`, `publish` FROM `profile` WHERE `uid` = %d AND `is-default` LIMIT 1", intval($owner["uid"]));
if ($r)
$profile = $r[0];
$author = $doc->createElement("author");
xml::add_element($doc, $author, "id", $owner["url"]);
xml::add_element($doc, $author, "activity:object-type", ACTIVITY_OBJ_PERSON);
xml::add_element($doc, $author, "uri", $owner["url"]);
xml::add_element($doc, $author, "name", $owner["name"]);
xml::add_element($doc, $author, "name", $owner["nick"]);
xml::add_element($doc, $author, "email", $owner["addr"]);
xml::add_element($doc, $author, "summary", bbcode($owner["about"], false, false, 7));
$attributes = array("rel" => "alternate", "type" => "text/html", "href" => $owner["url"]);
@ -1605,6 +1621,9 @@ class ostatus {
xml::add_element($doc, $author, "statusnet:profile_info", "", array("local_id" => $owner["uid"]));
}
if ($profile["publish"]) {
xml::add_element($doc, $author, "mastodon:scope", "public");
}
return $author;
}
@ -1778,7 +1797,7 @@ class ostatus {
self::entry_content($doc, $as_object, $repeated_item, $owner, "", "", false);
$author = self::add_author($doc, $contact);
$as_object->appendChild($author);
$as_object->appendChild($author);
$as_object2 = $doc->createElement("activity:object");
@ -2000,6 +2019,7 @@ class ostatus {
$entry->setAttribute("xmlns:poco", NAMESPACE_POCO);
$entry->setAttribute("xmlns:ostatus", NAMESPACE_OSTATUS);
$entry->setAttribute("xmlns:statusnet", NAMESPACE_STATUSNET);
$entry->setAttribute("xmlns:mastodon", NAMESPACE_MASTODON);
$author = self::add_author($doc, $owner);
$entry->appendChild($author);
@ -2066,39 +2086,54 @@ class ostatus {
$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']);
$attributes = array(
"ref" => $parent_item,
"type" => "text/html",
"href" => App::get_baseurl()."/display/".$parent[0]["guid"]);
xml::add_element($doc, $entry, "thr:in-reply-to", "", $attributes);
$attributes = array(
"rel" => "related",
"href" => App::get_baseurl()."/display/".$parent[0]["guid"]);
xml::add_element($doc, $entry, "link", "", $attributes);
$mentioned[$parent[0]["author-link"]] = $parent[0]["author-link"];
$mentioned[$parent[0]["owner-link"]] = $parent[0]["owner-link"];
$thrparent = q("SELECT `guid`, `author-link`, `owner-link` FROM `item` WHERE `uid` = %d AND `uri` = '%s'",
$thrparent = q("SELECT `guid`, `author-link`, `owner-link`, `plink` FROM `item` WHERE `uid` = %d AND `uri` = '%s'",
intval($owner["uid"]),
dbesc($parent_item));
if ($thrparent) {
$mentioned[$thrparent[0]["author-link"]] = $thrparent[0]["author-link"];
$mentioned[$thrparent[0]["owner-link"]] = $thrparent[0]["owner-link"];
$parent_plink = $thrparent[0]["plink"];
} else {
$mentioned[$parent[0]["author-link"]] = $parent[0]["author-link"];
$mentioned[$parent[0]["owner-link"]] = $parent[0]["owner-link"];
$parent_plink = App::get_baseurl()."/display/".$parent[0]["guid"];
}
$attributes = array(
"ref" => $parent_item,
"href" => $parent_plink);
xml::add_element($doc, $entry, "thr:in-reply-to", "", $attributes);
$attributes = array(
"rel" => "related",
"href" => $parent_plink);
xml::add_element($doc, $entry, "link", "", $attributes);
}
if (intval($item["parent"]) > 0) {
$conversation = App::get_baseurl()."/display/".$owner["nick"]."/".$item["parent"];
xml::add_element($doc, $entry, "link", "", array("rel" => "ostatus:conversation", "href" => $conversation));
$conversation_href = App::get_baseurl()."/display/".$owner["nick"]."/".$item["parent"];
$conversation_uri = $conversation_href;
if (isset($parent_item)) {
$r = dba::fetch_first("SELECT `conversation-uri`, `conversation-href` FROM `conversation` WHERE `item-uri` = ?", $parent_item);
if (dbm::is_result($r)) {
if ($r['conversation-uri'] != '') {
$conversation_uri = $r['conversation-uri'];
}
if ($r['conversation-href'] != '') {
$conversation_href = $r['conversation-href'];
}
}
}
xml::add_element($doc, $entry, "link", "", array("rel" => "ostatus:conversation", "href" => $conversation_href));
$attributes = array(
"href" => $conversation,
"href" => $conversation_href,
"local_id" => $item["parent"],
"ref" => $conversation);
"ref" => $conversation_uri);
xml::add_element($doc, $entry, "ostatus:conversation", $conversation, $attributes);
xml::add_element($doc, $entry, "ostatus:conversation", $conversation_uri, $attributes);
}
$tags = item_getfeedtags($item);
@ -2136,6 +2171,7 @@ class ostatus {
xml::add_element($doc, $entry, "link", "", array("rel" => "mentioned",
"ostatus:object-type" => "http://activitystrea.ms/schema/1.0/collection",
"href" => "http://activityschema.org/collection/public"));
xml::add_element($doc, $entry, "mastodon:scope", "public");
}
if(count($tags))
@ -2165,7 +2201,7 @@ class ostatus {
/**
* @brief Creates the XML feed for a given nickname
*
* @param app $a The application class
* @param App $a The application class
* @param string $owner_nick Nickname of the feed owner
* @param string $last_update Date of the last update
*
@ -2227,6 +2263,9 @@ class ostatus {
$root = self::add_header($doc, $owner);
foreach ($items AS $item) {
if (Config::get('system', 'ostatus_debug')) {
$item['body'] .= '🍼';
}
$entry = self::entry($doc, $item, $owner);
$root->appendChild($entry);
}
@ -2247,6 +2286,10 @@ class ostatus {
$doc = new DOMDocument('1.0', 'utf-8');
$doc->formatOutput = true;
if (Config::get('system', 'ostatus_debug')) {
$item['body'] .= '🐟';
}
$entry = self::entry($doc, $item, $owner, true);
$doc->appendChild($entry);
@ -2254,4 +2297,3 @@ class ostatus {
return(trim($doc->saveXML()));
}
}
?>

View file

@ -10,7 +10,7 @@
*
*/
use \Friendica\Core\Config;
use Friendica\Core\Config;
require_once("include/dba.php");

View file

@ -4,8 +4,8 @@
* @brief Functions related to photo handling.
*/
use \Friendica\Core\Config;
use \Friendica\Core\PConfig;
use Friendica\Core\Config;
use Friendica\Core\PConfig;
function getGps($exifCoord, $hemi) {
$degrees = count($exifCoord) > 0 ? gps2Num($exifCoord[0]) : 0;

View file

@ -38,4 +38,3 @@ class pidfile {
return(posix_kill(file_get_contents($this->_file), SIGTERM));
}
}
?>

View file

@ -4,7 +4,8 @@
* @file include/plaintext.php
*/
use \Friendica\ParseUrl;
use Friendica\App;
use Friendica\ParseUrl;
require_once("include/Photo.php");
require_once("include/bbcode.php");
@ -431,4 +432,3 @@ function plaintext(App $a, $b, $limit = 0, $includedlinks = false, $htmlmode = 2
return($post);
}
?>

View file

@ -1,10 +1,11 @@
<?php
/**
* @file include/plugin.php
*
*
* @brief Some functions to handle addons and themes.
*/
use Friendica\App;
/**
* @brief uninstalls an addon.
@ -164,7 +165,7 @@ function register_hook($hook,$file,$function,$priority=0) {
/**
* @brief unregisters a hook.
*
*
* @param string $hook the name of the hook
* @param string $file the name of the file that hooks into
* @param string $function the name of the function that the hook called
@ -325,7 +326,7 @@ function get_plugin_info($plugin){
/**
* @brief Parse theme comment in search of theme infos.
*
*
* like
* \code
* ..* Name: My Theme
@ -545,11 +546,11 @@ function upgrade_bool_message($bbcode = false) {
/**
* @brief Get the full path to relevant theme files by filename
*
*
* This function search in the theme directory (and if not present in global theme directory)
* if there is a directory with the file extension and for a file with the given
* filename.
*
* filename.
*
* @param string $file Filename
* @param string $root Full root path
* @return string Path to the file or empty string if the file isn't found

View file

@ -1,4 +1,8 @@
<?php
use Friendica\App;
use Friendica\Core\Config;
if (!file_exists("boot.php") AND (sizeof($_SERVER["argv"]) != 0)) {
$directory = dirname($_SERVER["argv"][0]);
@ -10,15 +14,13 @@ if (!file_exists("boot.php") AND (sizeof($_SERVER["argv"]) != 0)) {
chdir($directory);
}
use \Friendica\Core\Config;
require_once("boot.php");
function poller_run($argv, $argc){
global $a, $db;
if(is_null($a)) {
$a = new App;
if (is_null($a)) {
$a = new App(dirname(__DIR__));
}
if(is_null($db)) {
@ -41,6 +43,10 @@ function poller_run($argv, $argc){
$a->start_process();
if ($a->min_memory_reached()) {
return;
}
if (poller_max_connections_reached()) {
return;
}
@ -67,6 +73,11 @@ function poller_run($argv, $argc){
while ($r = poller_worker_process()) {
// Check free memory
if ($a->min_memory_reached()) {
return;
}
// Count active workers and compare them with a maximum value that depends on the load
if (poller_too_much_workers()) {
return;
@ -80,7 +91,6 @@ function poller_run($argv, $argc){
if (time() > ($starttime + 3600))
return;
}
}
/**
@ -678,4 +688,3 @@ if (array_search(__file__,get_included_files())===0){
killme();
}
?>

View file

@ -258,5 +258,3 @@ function post_update_1206() {
logger("Done", LOGGER_DEBUG);
return true;
}
?>

View file

@ -1,14 +1,6 @@
<?php
require_once('include/Probe.php');
/**
*
* Probe a network address to discover what kind of protocols we need to communicate with it.
*
* Warning: this function is a bit touchy and there are some subtle dependencies within the logic flow.
* Edit with care.
*
*/
use Friendica\Network\Probe;
/**
*
@ -18,16 +10,30 @@ require_once('include/Probe.php');
* of network.
*
*/
define('PROBE_NORMAL', 0);
define('PROBE_DIASPORA', 1);
function probe_url($url, $mode = PROBE_NORMAL, $level = 1) {
/**
* @brief Probes a network address to discover what kind of protocols we need to communicate with it.
*
* Warning: this function is a bit touchy and there are some subtle dependencies within the logic flow.
* Edit with care.
*
* @deprecated Use Friendica\Network\Probe instead
*
* @see Friendica\Network\Probe::uri()
*
* @param string $url Any URI
* @param int $mode One of the PROBE_* constants
* @return array Same data array returned by Friendica\Network\Probe::uri()
*/
function probe_url($url, $mode = PROBE_NORMAL) {
if ($mode == PROBE_DIASPORA)
if ($mode == PROBE_DIASPORA) {
$network = NETWORK_DIASPORA;
else
$network = "";
} else {
$network = '';
}
$data = Probe::uri($url, $network);

View file

@ -1,5 +1,7 @@
<?php
use \Friendica\Core\Config;
use Friendica\App;
use Friendica\Core\Config;
require_once('include/items.php');
require_once('include/ostatus.php');
@ -33,6 +35,9 @@ function handle_pubsubhubbub($id) {
else
$rr = $r[0];
/// @todo Check server status with poco_check_server()
// Before this can be done we need a way to safely detect the server url.
logger("Generate feed of user ".$rr['nickname']." to ".$rr['callback_url']." - last updated ".$rr['last_update'], LOGGER_DEBUG);
$params = ostatus::feed($a, $rr['nickname'], $rr['last_update']);

View file

@ -1,6 +1,6 @@
<?php
use \Friendica\Core\Config;
use Friendica\Core\Config;
require_once('include/queue_fn.php');
require_once('include/dfrn.php');

View file

@ -129,4 +129,3 @@ function removetofu($message)
return($message);
}
?>

View file

@ -1,5 +1,7 @@
<?php
use Friendica\App;
function auto_redir(App $a, $contact_nick) {
// prevent looping

View file

@ -4,7 +4,7 @@
* @brief Removes orphaned data from deleted contacts
*/
use \Friendica\Core\Config;
use Friendica\Core\Config;
function remove_contact_run($argv, $argc) {
if ($argc != 2) {
@ -14,19 +14,11 @@ function remove_contact_run($argv, $argc) {
$id = intval($argv[1]);
// Only delete if the contact doesn't exist (anymore)
$r = q("SELECT `id` FROM `contact` WHERE `id` = %d", intval($id));
$r = dba::select('contact', array('id'), array('id' => $id), array('limit' => 1));
if (dbm::is_result($r)) {
return;
}
q("DELETE FROM `item` WHERE `contact-id` = %d", intval($id));
q("DELETE FROM `photo` WHERE `contact-id` = %d", intval($id));
q("DELETE FROM `mail` WHERE `contact-id` = %d", intval($id));
q("DELETE FROM `event` WHERE `cid` = %d", intval($id));
q("DELETE FROM `queue` WHERE `cid` = %d", intval($id));
// Now we delete all the depending table entries
dba::delete('contact', array('id' => $id));
}
?>

View file

@ -1,7 +1,8 @@
<?php
require_once('include/crypto.php');
require_once('include/Probe.php');
use Friendica\Network\Probe;
require_once 'include/crypto.php';
function get_salmon_key($uri, $keyhash) {
$ret = array();

View file

@ -1,5 +1,7 @@
<?php
use Friendica\App;
/**
* @brief Calculate the hash that is needed for the "Friendica" cookie
*

View file

@ -1,6 +1,7 @@
<?php
use \Friendica\Core\Config;
use Friendica\App;
use Friendica\Core\Config;
require_once("boot.php");
require_once("include/threads.php");
@ -9,7 +10,7 @@ function shadowupdate_run(&$argv, &$argc){
global $a, $db;
if (is_null($a)) {
$a = new App;
$a = new App(dirname(__DIR__));
}
if (is_null($db)) {

View file

@ -1,20 +1,22 @@
<?php
/**
* @file include/socgraph.php
*
*
* @todo Move GNU Social URL schemata (http://server.tld/user/number) to http://server.tld/username
* @todo Fetch profile data from profile page for Redmatrix users
* @todo Detect if it is a forum
*/
use \Friendica\Core\Config;
use Friendica\App;
use Friendica\Core\Config;
use Friendica\Network\Probe;
require_once('include/datetime.php');
require_once("include/Scrape.php");
require_once("include/network.php");
require_once("include/html2bbcode.php");
require_once("include/Contact.php");
require_once("include/Photo.php");
require_once 'include/datetime.php';
require_once 'include/probe.php';
require_once 'include/network.php';
require_once 'include/html2bbcode.php';
require_once 'include/Contact.php';
require_once 'include/Photo.php';
/**
* @brief Fetch POCO data
@ -1008,6 +1010,7 @@ function poco_check_server($server_url, $network = "", $force = false) {
if (dbm::is_result($servers) AND ($orig_server_url == $server_url) AND
($serverret['errno'] == CURLE_OPERATION_TIMEDOUT)) {
logger("Connection to server ".$server_url." timed out.", LOGGER_DEBUG);
dba::p("UPDATE `gserver` SET `last_failure` = ? WHERE `nurl` = ?", datetime_convert(), normalise_link($server_url));
return false;
}
@ -1022,6 +1025,7 @@ function poco_check_server($server_url, $network = "", $force = false) {
// Quit if there is a timeout
if ($serverret['errno'] == CURLE_OPERATION_TIMEDOUT) {
logger("Connection to server ".$server_url." timed out.", LOGGER_DEBUG);
dba::p("UPDATE `gserver` SET `last_failure` = ? WHERE `nurl` = ?", datetime_convert(), normalise_link($server_url));
return false;
}
@ -1031,12 +1035,10 @@ function poco_check_server($server_url, $network = "", $force = false) {
if (!$serverret["success"] OR ($serverret["body"] == "") OR (sizeof($xmlobj) == 0) OR !is_object($xmlobj)) {
// Workaround for bad configured servers (known nginx problem)
if (!in_array($serverret["debug"]["http_code"], array("403", "404"))) {
$last_failure = datetime_convert();
$failure = true;
}
$possible_failure = true;
} elseif ($network == NETWORK_DIASPORA)
$last_contact = datetime_convert();
}
// If the server has no possible failure we reset the cached data
if (!$possible_failure) {
@ -1054,8 +1056,6 @@ function poco_check_server($server_url, $network = "", $force = false) {
$data = json_decode($serverret["body"]);
if (isset($data->totalResults)) {
$poco = $server_url."/poco";
$last_contact = datetime_convert();
$server = poco_detect_poco_data($data);
if ($server) {
$platform = $server['platform'];
@ -1072,7 +1072,6 @@ function poco_check_server($server_url, $network = "", $force = false) {
$serverret = z_fetch_url($server_url);
if (!$serverret["success"] OR ($serverret["body"] == "")) {
$last_failure = datetime_convert();
$failure = true;
} else {
$server = poco_detect_server_type($serverret["body"]);
@ -1081,7 +1080,6 @@ function poco_check_server($server_url, $network = "", $force = false) {
$network = $server['network'];
$version = $server['version'];
$site_name = $server['site_name'];
$last_contact = datetime_convert();
}
$lines = explode("\n",$serverret["header"]);
@ -1095,15 +1093,11 @@ function poco_check_server($server_url, $network = "", $force = false) {
$network = NETWORK_DIASPORA;
$versionparts = explode("-", $version);
$version = $versionparts[0];
$last_contact = datetime_convert();
}
if(stristr($line,'Server: Mastodon')) {
$platform = "Mastodon";
$network = NETWORK_OSTATUS;
// Mastodon doesn't reveal version numbers
$version = "";
$last_contact = datetime_convert();
}
}
}
@ -1122,7 +1116,6 @@ function poco_check_server($server_url, $network = "", $force = false) {
$version = str_replace(chr(239).chr(187).chr(191), "", $serverret["body"]);
$version = trim($version, '"');
$network = NETWORK_OSTATUS;
$last_contact = datetime_convert();
}
// Test for GNU Social
@ -1134,7 +1127,19 @@ function poco_check_server($server_url, $network = "", $force = false) {
$version = str_replace(chr(239).chr(187).chr(191), "", $serverret["body"]);
$version = trim($version, '"');
$network = NETWORK_OSTATUS;
$last_contact = datetime_convert();
}
// Test for Mastodon
$serverret = z_fetch_url($server_url."/api/v1/instance");
if ($serverret["success"] AND ($serverret["body"] != '')) {
$data = json_decode($serverret["body"]);
if (isset($data->version)) {
$platform = "Mastodon";
$version = $data->version;
$site_name = $data->title;
$info = $data->description;
$network = NETWORK_OSTATUS;
}
}
}
@ -1144,8 +1149,6 @@ function poco_check_server($server_url, $network = "", $force = false) {
if ($serverret["success"]) {
$data = json_decode($serverret["body"]);
if (isset($data->site->server)) {
$last_contact = datetime_convert();
if (isset($data->site->platform)) {
$platform = $data->site->platform->PLATFORM_NAME;
$version = $data->site->platform->STD_VERSION;
@ -1192,7 +1195,6 @@ function poco_check_server($server_url, $network = "", $force = false) {
}
}
// Query statistics.json. Optional package for Diaspora, Friendica and Redmatrix
if (!$failure) {
$serverret = z_fetch_url($server_url."/statistics.json");
@ -1220,9 +1222,6 @@ function poco_check_server($server_url, $network = "", $force = false) {
} else {
$register_policy = REGISTER_CLOSED;
}
if (isset($data->version))
$last_contact = datetime_convert();
}
}
@ -1247,8 +1246,6 @@ function poco_check_server($server_url, $network = "", $force = false) {
if (isset($server['site_name'])) {
$site_name = $server['site_name'];
}
$last_contact = datetime_convert();
}
}
@ -1264,7 +1261,6 @@ function poco_check_server($server_url, $network = "", $force = false) {
$data = json_decode($serverret["body"]);
if (isset($data->version)) {
$last_contact = datetime_convert();
$network = NETWORK_DFRN;
$noscrape = $data->no_scrape_url;
@ -1290,13 +1286,14 @@ function poco_check_server($server_url, $network = "", $force = false) {
}
if ($possible_failure AND !$failure) {
$last_failure = datetime_convert();
$failure = true;
}
if ($failure) {
$last_contact = $orig_last_contact;
$last_failure = datetime_convert();
} else {
$last_contact = datetime_convert();
$last_failure = $orig_last_failure;
}
@ -1430,7 +1427,7 @@ function common_friends_zcid($uid,$zcid,$start = 0, $limit = 9999,$shuffle = fal
$r = q("SELECT `gcontact`.*
FROM `glink` INNER JOIN `gcontact` on `glink`.`gcid` = `gcontact`.`id`
where `glink`.`zcid` = %d
and `gcontact`.`nurl` in (select nurl from contact where uid = %d and self = 0 and blocked = 0 and hidden = 0 )
and `gcontact`.`nurl` in (select nurl from contact where uid = %d and self = 0 and blocked = 0 and hidden = 0 )
$sql_extra limit %d, %d",
intval($zcid),
intval($uid),
@ -2345,4 +2342,3 @@ function poco_serverlist() {
}
return $r;
}
?>

View file

@ -4,7 +4,7 @@
* @brief Posts items that wer spooled because they couldn't be posted.
*/
use \Friendica\Core\Config;
use Friendica\Core\Config;
require_once("include/items.php");
@ -55,4 +55,3 @@ function spool_post_run($argv, $argc) {
}
}
}
?>

View file

@ -1,4 +1,7 @@
<?php
use Friendica\App;
function create_tags_from_item($itemid) {
$profile_base = App::get_baseurl();
$profile_data = parse_url($profile_base);
@ -111,12 +114,11 @@ function create_tags_from_itemuri($itemuri, $uid) {
}
function update_items() {
global $db;
$messages = $db->q("SELECT `oid`,`item`.`guid`, `item`.`created`, `item`.`received` FROM `term` INNER JOIN `item` ON `item`.`id`=`term`.`oid` WHERE `term`.`otype` = 1 AND `term`.`guid` = ''", true);
$messages = dba::p("SELECT `oid`,`item`.`guid`, `item`.`created`, `item`.`received` FROM `term` INNER JOIN `item` ON `item`.`id`=`term`.`oid` WHERE `term`.`otype` = 1 AND `term`.`guid` = ''");
logger("fetched messages: ".count($messages));
while ($message = $db->qfetch()) {
logger("fetched messages: ".dba::num_rows($messages));
while ($message = dba::fetch($messages)) {
if ($message["uid"] == 0) {
$global = true;
@ -135,15 +137,14 @@ function update_items() {
intval($global), intval(TERM_OBJ_POST), intval($message["oid"]));
}
$db->qclose();
dba::close($messages);
$messages = $db->q("SELECT `guid` FROM `item` WHERE `uid` = 0", true);
$messages = dba::p("SELECT `guid` FROM `item` WHERE `uid` = 0");
logger("fetched messages: ".count($messages));
while ($message = $db->qfetch()) {
logger("fetched messages: ".dba::num_rows($messages));
while ($message = dba::fetch(messages)) {
q("UPDATE `item` SET `global` = 1 WHERE `guid` = '%s'", dbesc($message["guid"]));
}
$db->qclose();
dba::close($messages);
}
?>

View file

@ -1,12 +1,13 @@
<?php
use Friendica\App;
require_once("include/template_processor.php");
require_once("include/friendica_smarty.php");
require_once("include/Smilies.php");
require_once("include/map.php");
require_once("mod/proxy.php");
if(! function_exists('replace_macros')) {
/**
* This is our template processor
@ -753,6 +754,72 @@ function logger($msg, $level = 0) {
$a->save_timestamp($stamp1, "file");
}}
/**
* @brief An alternative logger for development.
* Works largely as logger() but allows developers
* to isolate particular elements they are targetting
* personally without background noise
*
* log levels:
* LOGGER_NORMAL (default)
* LOGGER_TRACE
* LOGGER_DEBUG
* LOGGER_DATA
* LOGGER_ALL
*
* @global App $a
* @global dba $db
* @global array $LOGGER_LEVELS
* @param string $msg
* @param int $level
*/
function dlogger($msg, $level = 0) {
$a = get_app();
global $db;
// turn off logger in install mode
if (
$a->module == 'install'
|| ! ($db && $db->connected)
) {
return;
}
$logfile = get_config('system','dlogfile');
if (! $logfile) {
return;
}
if (count($LOGGER_LEVELS) == 0) {
foreach (get_defined_constants() as $k => $v) {
if (substr($k, 0, 7) == "LOGGER_") {
$LOGGER_LEVELS[$v] = substr($k, 7, 7);
}
}
}
$process_id = session_id();
if ($process_id == '') {
$process_id = get_app()->process_id;
}
$callers = debug_backtrace();
$logline = sprintf("%s@\t%s:\t%s:\t%s\t%s\t%s\n",
datetime_convert(),
$process_id,
basename($callers[0]['file']),
$callers[0]['line'],
$callers[1]['function'],
$msg
);
$stamp1 = microtime(true);
@file_put_contents($logfile, $logline, FILE_APPEND);
$a->save_timestamp($stamp1, "file");
}
if(! function_exists('activity_match')) {
/**

View file

@ -1,4 +1,7 @@
<?php
use Friendica\App;
function add_thread($itemid, $onlyshadow = false) {
$items = q("SELECT `uid`, `created`, `edited`, `commented`, `received`, `changed`, `wall`, `private`, `pubmail`,
`moderated`, `visible`, `spam`, `starred`, `bookmark`, `contact-id`, `gcontact-id`,
@ -251,19 +254,17 @@ function delete_thread($itemid, $itemuri = "") {
}
function update_threads() {
global $db;
logger("update_threads: start");
$messages = $db->q("SELECT `id` FROM `item` WHERE `id` = `parent`", true);
$messages = dba::p("SELECT `id` FROM `item` WHERE `id` = `parent`");
logger("update_threads: fetched messages: ".count($messages));
logger("update_threads: fetched messages: ".dba::num_rows($messages));
while ($message = $db->qfetch()) {
while ($message = dba::fetch($messages)) {
add_thread($message["id"]);
add_shadow_thread($message["id"]);
}
$db->qclose();
dba::close($messages);
}
function update_threads_mention() {
@ -283,18 +284,15 @@ function update_threads_mention() {
function update_shadow_copy() {
global $db;
logger("start");
$messages = $db->q(sprintf("SELECT `iid` FROM `thread` WHERE `uid` != 0 AND `network` IN ('', '%s', '%s', '%s')
AND `visible` AND NOT `deleted` AND NOT `moderated` AND NOT `private` ORDER BY `created`",
NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS), true);
$messages = dba::p("SELECT `iid` FROM `thread` WHERE `uid` != 0 AND `network` IN ('', ?, ?, ?)
AND `visible` AND NOT `deleted` AND NOT `moderated` AND NOT `private` ORDER BY `created`",
NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS);
logger("fetched messages: ".count($messages));
while ($message = $db->qfetch())
logger("fetched messages: ".dba::num_rows($messages));
while ($message = dba::fetch($messages))
add_shadow_thread($message["iid"]);
$db->qclose();
dba::close($messages);
}
?>

View file

@ -1,291 +1,293 @@
<?php
/**
* import account file exported from mod/uexport
* args:
* $a App Friendica App Class
* $file Array array from $_FILES
*/
require_once("include/Photo.php");
define("IMPORT_DEBUG", False);
function last_insert_id() {
global $db;
if (IMPORT_DEBUG)
return 1;
return $db->insert_id();
}
function last_error() {
global $db;
return $db->error;
}
/**
* Remove columns from array $arr that aren't in table $table
*
* @param string $table Table name
* @param array &$arr Column=>Value array from json (by ref)
*/
function check_cols($table, &$arr) {
$query = sprintf("SHOW COLUMNS IN `%s`", dbesc($table));
logger("uimport: $query", LOGGER_DEBUG);
$r = q($query);
$tcols = array();
// get a plain array of column names
foreach ($r as $tcol) {
$tcols[] = $tcol['Field'];
}
// remove inexistent columns
foreach ($arr as $icol => $ival) {
if (!in_array($icol, $tcols)) {
unset($arr[$icol]);
}
}
}
/**
* Import data into table $table
*
* @param string $table Table name
* @param array $arr Column=>Value array from json
*/
function db_import_assoc($table, $arr) {
if (isset($arr['id']))
unset($arr['id']);
check_cols($table, $arr);
$cols = implode("`,`", array_map('dbesc', array_keys($arr)));
$vals = implode("','", array_map('dbesc', array_values($arr)));
$query = "INSERT INTO `$table` (`$cols`) VALUES ('$vals')";
logger("uimport: $query", LOGGER_TRACE);
if (IMPORT_DEBUG)
return true;
return q($query);
}
function import_cleanup($newuid) {
q("DELETE FROM `user` WHERE uid = %d", $newuid);
q("DELETE FROM `contact` WHERE uid = %d", $newuid);
q("DELETE FROM `profile` WHERE uid = %d", $newuid);
q("DELETE FROM `photo` WHERE uid = %d", $newuid);
q("DELETE FROM `group` WHERE uid = %d", $newuid);
q("DELETE FROM `group_member` WHERE uid = %d", $newuid);
q("DELETE FROM `pconfig` WHERE uid = %d", $newuid);
}
function import_account(App $a, $file) {
logger("Start user import from " . $file['tmp_name']);
/*
STEPS
1. checks
2. replace old baseurl with new baseurl
3. import data (look at user id and contacts id)
4. archive non-dfrn contacts
5. send message to dfrn contacts
*/
$account = json_decode(file_get_contents($file['tmp_name']), true);
if ($account === null) {
notice(t("Error decoding account file"));
return;
}
if (!x($account, 'version')) {
notice(t("Error! No version data in file! This is not a Friendica account file?"));
return;
}
/*
// this is not required as we remove columns in json not in current db schema
if ($account['schema'] != DB_UPDATE_VERSION) {
notice(t("Error! I can't import this file: DB schema version is not compatible."));
return;
}
*/
// check for username
$r = q("SELECT uid FROM user WHERE nickname='%s'", $account['user']['nickname']);
if ($r === false) {
logger("uimport:check nickname : ERROR : " . last_error(), LOGGER_NORMAL);
notice(t('Error! Cannot check nickname'));
return;
}
if (dbm::is_result($r) > 0) {
notice(sprintf(t("User '%s' already exists on this server!"), $account['user']['nickname']));
return;
}
// check if username matches deleted account
$r = q("SELECT id FROM userd WHERE username='%s'", $account['user']['nickname']);
if ($r === false) {
logger("uimport:check nickname : ERROR : " . last_error(), LOGGER_NORMAL);
notice(t('Error! Cannot check nickname'));
return;
}
if (dbm::is_result($r) > 0) {
notice(sprintf(t("User '%s' already exists on this server!"), $account['user']['nickname']));
return;
}
$oldbaseurl = $account['baseurl'];
$newbaseurl = App::get_baseurl();
$olduid = $account['user']['uid'];
unset($account['user']['uid']);
unset($account['user']['account_expired']);
unset($account['user']['account_expires_on']);
unset($account['user']['expire_notification_sent']);
foreach ($account['user'] as $k => &$v) {
$v = str_replace($oldbaseurl, $newbaseurl, $v);
}
// import user
$r = db_import_assoc('user', $account['user']);
if ($r === false) {
//echo "<pre>"; var_dump($r, $query, mysql_error()); killme();
logger("uimport:insert user : ERROR : " . last_error(), LOGGER_NORMAL);
notice(t("User creation error"));
return;
}
$newuid = last_insert_id();
//~ $newuid = 1;
// Generate a new guid for the account. Otherwise there will be problems with diaspora
q("UPDATE `user` SET `guid` = '%s' WHERE `uid` = %d",
dbesc(generate_user_guid()), intval($newuid));
foreach ($account['profile'] as &$profile) {
foreach ($profile as $k => &$v) {
$v = str_replace($oldbaseurl, $newbaseurl, $v);
foreach (array("profile", "avatar") as $k)
$v = str_replace($oldbaseurl . "/photo/" . $k . "/" . $olduid . ".jpg", $newbaseurl . "/photo/" . $k . "/" . $newuid . ".jpg", $v);
}
$profile['uid'] = $newuid;
$r = db_import_assoc('profile', $profile);
if ($r === false) {
logger("uimport:insert profile " . $profile['profile-name'] . " : ERROR : " . last_error(), LOGGER_NORMAL);
info(t("User profile creation error"));
import_cleanup($newuid);
return;
}
}
$errorcount = 0;
foreach ($account['contact'] as &$contact) {
if ($contact['uid'] == $olduid && $contact['self'] == '1') {
foreach ($contact as $k => &$v) {
$v = str_replace($oldbaseurl, $newbaseurl, $v);
foreach (array("profile", "avatar", "micro") as $k)
$v = str_replace($oldbaseurl . "/photo/" . $k . "/" . $olduid . ".jpg", $newbaseurl . "/photo/" . $k . "/" . $newuid . ".jpg", $v);
}
}
if ($contact['uid'] == $olduid && $contact['self'] == '0') {
// set contacts 'avatar-date' to NULL_DATE to let poller to update urls
$contact["avatar-date"] = NULL_DATE;
switch ($contact['network']) {
case NETWORK_DFRN:
// send relocate message (below)
break;
case NETWORK_ZOT:
/// @TODO handle zot network
break;
case NETWORK_MAIL2:
/// @TODO ?
break;
case NETWORK_FEED:
case NETWORK_MAIL:
// Nothing to do
break;
default:
// archive other contacts
$contact['archive'] = "1";
}
}
$contact['uid'] = $newuid;
$r = db_import_assoc('contact', $contact);
if ($r === false) {
logger("uimport:insert contact " . $contact['nick'] . "," . $contact['network'] . " : ERROR : " . last_error(), LOGGER_NORMAL);
$errorcount++;
} else {
$contact['newid'] = last_insert_id();
}
}
if ($errorcount > 0) {
notice(sprintf(tt("%d contact not imported", "%d contacts not imported", $errorcount), $errorcount));
}
foreach ($account['group'] as &$group) {
$group['uid'] = $newuid;
$r = db_import_assoc('group', $group);
if ($r === false) {
logger("uimport:insert group " . $group['name'] . " : ERROR : " . last_error(), LOGGER_NORMAL);
} else {
$group['newid'] = last_insert_id();
}
}
foreach ($account['group_member'] as &$group_member) {
$group_member['uid'] = $newuid;
$import = 0;
foreach ($account['group'] as $group) {
if ($group['id'] == $group_member['gid'] && isset($group['newid'])) {
$group_member['gid'] = $group['newid'];
$import++;
break;
}
}
foreach ($account['contact'] as $contact) {
if ($contact['id'] == $group_member['contact-id'] && isset($contact['newid'])) {
$group_member['contact-id'] = $contact['newid'];
$import++;
break;
}
}
if ($import == 2) {
$r = db_import_assoc('group_member', $group_member);
if ($r === false) {
logger("uimport:insert group member " . $group_member['id'] . " : ERROR : " . last_error(), LOGGER_NORMAL);
}
}
}
foreach ($account['photo'] as &$photo) {
$photo['uid'] = $newuid;
$photo['data'] = hex2bin($photo['data']);
$p = new Photo($photo['data'], $photo['type']);
$r = $p->store(
$photo['uid'], $photo['contact-id'], //0
$photo['resource-id'], $photo['filename'], $photo['album'], $photo['scale'], $photo['profile'], //1
$photo['allow_cid'], $photo['allow_gid'], $photo['deny_cid'], $photo['deny_gid']
);
if ($r === false) {
logger("uimport:insert photo " . $photo['resource-id'] . "," . $photo['scale'] . " : ERROR : " . last_error(), LOGGER_NORMAL);
}
}
foreach ($account['pconfig'] as &$pconfig) {
$pconfig['uid'] = $newuid;
$r = db_import_assoc('pconfig', $pconfig);
if ($r === false) {
logger("uimport:insert pconfig " . $pconfig['id'] . " : ERROR : " . last_error(), LOGGER_NORMAL);
}
}
// send relocate messages
proc_run(PRIORITY_HIGH, 'include/notifier.php', 'relocate', $newuid);
info(t("Done. You can now login with your username and password"));
goaway(App::get_baseurl() . "/login");
}
<?php
use Friendica\App;
require_once("include/Photo.php");
define("IMPORT_DEBUG", False);
function last_insert_id() {
global $db;
if (IMPORT_DEBUG) {
return 1;
}
return $db->insert_id();
}
function last_error() {
global $db;
return $db->error;
}
/**
* Remove columns from array $arr that aren't in table $table
*
* @param string $table Table name
* @param array &$arr Column=>Value array from json (by ref)
*/
function check_cols($table, &$arr) {
$query = sprintf("SHOW COLUMNS IN `%s`", dbesc($table));
logger("uimport: $query", LOGGER_DEBUG);
$r = q($query);
$tcols = array();
// get a plain array of column names
foreach ($r as $tcol) {
$tcols[] = $tcol['Field'];
}
// remove inexistent columns
foreach ($arr as $icol => $ival) {
if (!in_array($icol, $tcols)) {
unset($arr[$icol]);
}
}
}
/**
* Import data into table $table
*
* @param string $table Table name
* @param array $arr Column=>Value array from json
*/
function db_import_assoc($table, $arr) {
if (isset($arr['id']))
unset($arr['id']);
check_cols($table, $arr);
$cols = implode("`,`", array_map('dbesc', array_keys($arr)));
$vals = implode("','", array_map('dbesc', array_values($arr)));
$query = "INSERT INTO `$table` (`$cols`) VALUES ('$vals')";
logger("uimport: $query", LOGGER_TRACE);
if (IMPORT_DEBUG) {
return true;
}
return q($query);
}
function import_cleanup($newuid) {
q("DELETE FROM `user` WHERE uid = %d", $newuid);
q("DELETE FROM `contact` WHERE uid = %d", $newuid);
q("DELETE FROM `profile` WHERE uid = %d", $newuid);
q("DELETE FROM `photo` WHERE uid = %d", $newuid);
q("DELETE FROM `group` WHERE uid = %d", $newuid);
q("DELETE FROM `group_member` WHERE uid = %d", $newuid);
q("DELETE FROM `pconfig` WHERE uid = %d", $newuid);
}
/**
* @brief Import account file exported from mod/uexport
*
* @param App $a Friendica App Class
* @param array $file array from $_FILES
*/
function import_account(App $a, $file) {
logger("Start user import from " . $file['tmp_name']);
/*
STEPS
1. checks
2. replace old baseurl with new baseurl
3. import data (look at user id and contacts id)
4. archive non-dfrn contacts
5. send message to dfrn contacts
*/
$account = json_decode(file_get_contents($file['tmp_name']), true);
if ($account === null) {
notice(t("Error decoding account file"));
return;
}
if (!x($account, 'version')) {
notice(t("Error! No version data in file! This is not a Friendica account file?"));
return;
}
/*
* @TODO Old-lost code?
// this is not required as we remove columns in json not in current db schema
if ($account['schema'] != DB_UPDATE_VERSION) {
notice(t("Error! I can't import this file: DB schema version is not compatible."));
return;
}
*/
// check for username
$r = q("SELECT uid FROM user WHERE nickname='%s'", $account['user']['nickname']);
if ($r === false) {
logger("uimport:check nickname : ERROR : " . last_error(), LOGGER_NORMAL);
notice(t('Error! Cannot check nickname'));
return;
}
if (dbm::is_result($r) > 0) {
notice(sprintf(t("User '%s' already exists on this server!"), $account['user']['nickname']));
return;
}
// check if username matches deleted account
$r = q("SELECT id FROM userd WHERE username='%s'", $account['user']['nickname']);
if ($r === false) {
logger("uimport:check nickname : ERROR : " . last_error(), LOGGER_NORMAL);
notice(t('Error! Cannot check nickname'));
return;
}
if (dbm::is_result($r) > 0) {
notice(sprintf(t("User '%s' already exists on this server!"), $account['user']['nickname']));
return;
}
$oldbaseurl = $account['baseurl'];
$newbaseurl = App::get_baseurl();
$olduid = $account['user']['uid'];
unset($account['user']['uid']);
unset($account['user']['account_expired']);
unset($account['user']['account_expires_on']);
unset($account['user']['expire_notification_sent']);
foreach ($account['user'] as $k => &$v) {
$v = str_replace($oldbaseurl, $newbaseurl, $v);
}
// import user
$r = db_import_assoc('user', $account['user']);
if ($r === false) {
//echo "<pre>"; var_dump($r, $query, mysql_error()); killme();
logger("uimport:insert user : ERROR : " . last_error(), LOGGER_NORMAL);
notice(t("User creation error"));
return;
}
$newuid = last_insert_id();
//~ $newuid = 1;
// Generate a new guid for the account. Otherwise there will be problems with diaspora
q("UPDATE `user` SET `guid` = '%s' WHERE `uid` = %d",
dbesc(generate_user_guid()), intval($newuid));
foreach ($account['profile'] as &$profile) {
foreach ($profile as $k => &$v) {
$v = str_replace($oldbaseurl, $newbaseurl, $v);
foreach (array("profile", "avatar") as $k) {
$v = str_replace($oldbaseurl . "/photo/" . $k . "/" . $olduid . ".jpg", $newbaseurl . "/photo/" . $k . "/" . $newuid . ".jpg", $v);
}
}
$profile['uid'] = $newuid;
$r = db_import_assoc('profile', $profile);
if ($r === false) {
logger("uimport:insert profile " . $profile['profile-name'] . " : ERROR : " . last_error(), LOGGER_NORMAL);
info(t("User profile creation error"));
import_cleanup($newuid);
return;
}
}
$errorcount = 0;
foreach ($account['contact'] as &$contact) {
if ($contact['uid'] == $olduid && $contact['self'] == '1') {
foreach ($contact as $k => &$v) {
$v = str_replace($oldbaseurl, $newbaseurl, $v);
foreach (array("profile", "avatar", "micro") as $k) {
$v = str_replace($oldbaseurl . "/photo/" . $k . "/" . $olduid . ".jpg", $newbaseurl . "/photo/" . $k . "/" . $newuid . ".jpg", $v);
}
}
}
if ($contact['uid'] == $olduid && $contact['self'] == '0') {
// set contacts 'avatar-date' to NULL_DATE to let poller to update urls
$contact["avatar-date"] = NULL_DATE;
switch ($contact['network']) {
case NETWORK_DFRN:
// send relocate message (below)
break;
case NETWORK_ZOT:
/// @TODO handle zot network
break;
case NETWORK_MAIL2:
/// @TODO ?
break;
case NETWORK_FEED:
case NETWORK_MAIL:
// Nothing to do
break;
default:
// archive other contacts
$contact['archive'] = "1";
}
}
$contact['uid'] = $newuid;
$r = db_import_assoc('contact', $contact);
if ($r === false) {
logger("uimport:insert contact " . $contact['nick'] . "," . $contact['network'] . " : ERROR : " . last_error(), LOGGER_NORMAL);
$errorcount++;
} else {
$contact['newid'] = last_insert_id();
}
}
if ($errorcount > 0) {
notice(sprintf(tt("%d contact not imported", "%d contacts not imported", $errorcount), $errorcount));
}
foreach ($account['group'] as &$group) {
$group['uid'] = $newuid;
$r = db_import_assoc('group', $group);
if ($r === false) {
logger("uimport:insert group " . $group['name'] . " : ERROR : " . last_error(), LOGGER_NORMAL);
} else {
$group['newid'] = last_insert_id();
}
}
foreach ($account['group_member'] as &$group_member) {
$group_member['uid'] = $newuid;
$import = 0;
foreach ($account['group'] as $group) {
if ($group['id'] == $group_member['gid'] && isset($group['newid'])) {
$group_member['gid'] = $group['newid'];
$import++;
break;
}
}
foreach ($account['contact'] as $contact) {
if ($contact['id'] == $group_member['contact-id'] && isset($contact['newid'])) {
$group_member['contact-id'] = $contact['newid'];
$import++;
break;
}
}
if ($import == 2) {
$r = db_import_assoc('group_member', $group_member);
if ($r === false) {
logger("uimport:insert group member " . $group_member['id'] . " : ERROR : " . last_error(), LOGGER_NORMAL);
}
}
}
foreach ($account['photo'] as &$photo) {
$photo['uid'] = $newuid;
$photo['data'] = hex2bin($photo['data']);
$p = new Photo($photo['data'], $photo['type']);
$r = $p->store(
$photo['uid'], $photo['contact-id'], //0
$photo['resource-id'], $photo['filename'], $photo['album'], $photo['scale'], $photo['profile'], //1
$photo['allow_cid'], $photo['allow_gid'], $photo['deny_cid'], $photo['deny_gid']
);
if ($r === false) {
logger("uimport:insert photo " . $photo['resource-id'] . "," . $photo['scale'] . " : ERROR : " . last_error(), LOGGER_NORMAL);
}
}
foreach ($account['pconfig'] as &$pconfig) {
$pconfig['uid'] = $newuid;
$r = db_import_assoc('pconfig', $pconfig);
if ($r === false) {
logger("uimport:insert pconfig " . $pconfig['id'] . " : ERROR : " . last_error(), LOGGER_NORMAL);
}
}
// send relocate messages
proc_run(PRIORITY_HIGH, 'include/notifier.php', 'relocate', $newuid);
info(t("Done. You can now login with your username and password"));
goaway(App::get_baseurl() . "/login");
}

View file

@ -1,11 +1,11 @@
<?php
use \Friendica\Core\Config;
use Friendica\Core\Config;
function update_gcontact_run(&$argv, &$argc) {
global $a;
require_once 'include/Scrape.php';
require_once 'include/probe.php';
require_once 'include/socgraph.php';
logger('update_gcontact: start');

View file

@ -13,12 +13,13 @@
*
*/
use \Friendica\Core\Config;
use Friendica\App;
use Friendica\Core\Config;
require_once('boot.php');
require_once('object/BaseObject.php');
require_once 'boot.php';
require_once 'object/BaseObject.php';
$a = new App;
$a = new App(__DIR__);
BaseObject::set_app($a);
// We assume that the index.php is called by a frontend process
@ -73,7 +74,7 @@ if (!$install) {
exit();
}
require_once("include/session.php");
require_once 'include/session.php';
load_hooks();
call_hooks('init_1');
@ -112,9 +113,11 @@ if (!$a->is_backend()) {
*/
if (x($_SESSION,'authenticated') && !x($_SESSION,'language')) {
// we didn't loaded user data yet, but we need user language
$r = q("SELECT language FROM user WHERE uid=%d", intval($_SESSION['uid']));
$r = dba::select('user', array('language'), array('uid' => $_SESSION['uid']), array('limit' => 1));
$_SESSION['language'] = $lang;
if (dbm::is_result($r)) $_SESSION['language'] = $r[0]['language'];
if (dbm::is_result($r)) {
$_SESSION['language'] = $r['language'];
}
}
if ((x($_SESSION,'language')) && ($_SESSION['language'] !== $lang)) {
@ -174,6 +177,10 @@ if (! x($_SESSION,'sysmsg_info')) {
$_SESSION['sysmsg_info'] = array();
}
// Array for informations about last received items
if (! x($_SESSION,'last_updated')) {
$_SESSION['last_updated'] = array();
}
/*
* check_config() is responsible for running update scripts. These automatically
* update the DB schema whenever we push a new one out. It also checks to see if
@ -482,7 +489,7 @@ header("X-Friendica-Version: " . FRIENDICA_VERSION);
header("Content-type: text/html; charset=utf-8");
/*
* We use $_GET["mode"] for special page templates. So we will check if we have
* We use $_GET["mode"] for special page templates. So we will check if we have
* to load another page template than the default one.
* The page templates are located in /view/php/ or in the theme directory.
*/

View file

@ -78,22 +78,26 @@ function contact_format(item) {
}
function editor_replace(item) {
if(typeof item.replace !== 'undefined') {
if (typeof item.replace !== 'undefined') {
return '$1$2' + item.replace;
}
if (typeof item.addr !== 'undefined') {
return '$1$2' + item.addr + ' ';
}
// $2 ensures that prefix (@,@!) is preserved
var id = item.id;
// don't add the id if it is empty (the id empty eg. if there are unknow contacts in thread)
if(id.length < 1)
if (id.length < 1) {
return '$1$2' + item.nick.replace(' ', '') + ' ';
}
// 16 chars of hash should be enough. Full hash could be used if it can be done in a visually appealing way.
// 16 chars is also the minimum length in the backend (otherwise it's interpreted as a local id).
if(id.length > 16)
if (id.length > 16) {
id = item.id.substring(0,16);
}
return '$1$2' + item.nick.replace(' ', '') + '+' + id + ' ';
}

View file

@ -1,6 +1,7 @@
<?php
use \Friendica\Core\Config;
use Friendica\App;
use Friendica\Core\Config;
require_once("mod/hostxrd.php");
require_once("mod/nodeinfo.php");

View file

@ -1,6 +1,8 @@
<?php
require_once('include/Scrape.php');
use Friendica\App;
require_once 'include/probe.php';
function acctlink_init(App $a) {

View file

@ -1,6 +1,8 @@
<?php
/* ACL selector json backend */
use Friendica\App;
require_once 'include/acl_selectors.php';
function acl_init(App $a) {

View file

@ -6,7 +6,8 @@
* @brief Friendica admin
*/
use \Friendica\Core\Config;
use Friendica\App;
use Friendica\Core\Config;
require_once("include/enotify.php");
require_once("include/text.php");
@ -109,6 +110,9 @@ function admin_post(App $a) {
case 'dbsync':
admin_page_dbsync_post($a);
break;
case 'blocklist':
admin_page_blocklist_post($a);
break;
}
}
@ -166,6 +170,7 @@ function admin_content(App $a) {
'features' => array("admin/features/", t("Additional features") , "features"),
'dbsync' => array("admin/dbsync/", t('DB updates'), "dbsync"),
'queue' => array("admin/queue/", t('Inspect Queue'), "queue"),
'blocklist' => array("admin/blocklist/", t('Server Blocklist'), "blocklist"),
'federation' => array("admin/federation/", t('Federation Statistics'), "federation"),
);
@ -236,6 +241,9 @@ function admin_content(App $a) {
case 'federation':
$o = admin_page_federation($a);
break;
case 'blocklist':
$o = admin_page_blocklist($a);
break;
default:
notice(t("Item not found."));
}
@ -252,6 +260,94 @@ function admin_content(App $a) {
}
}
/**
* @brief Subpage to modify the server wide block list via the admin panel.
*
* This function generates the subpage of the admin panel to allow the
* modification of the node wide block/black list to block entire
* remote servers from communication with this node. The page allows
* adding, removing and editing of entries from the blocklist.
*
* @param App $a
* @return string
*/
function admin_page_blocklist(App $a) {
$blocklist = Config::get('system', 'blocklist');
$blocklistform = array();
if (is_array($blocklist)) {
foreach($blocklist as $id => $b) {
$blocklistform[] = array(
'domain' => array("domain[$id]", t('Blocked domain'), $b['domain'], '', t('The blocked domain'), 'required', '', ''),
'reason' => array("reason[$id]", t("Reason for the block"), $b['reason'], t('The reason why you blocked this domain.').'('.$b['domain'].')', 'required', '', ''),
'delete' => array("delete[$id]", t("Delete domain").' ('.$b['domain'].')', False , t("Check to delete this entry from the blocklist"))
);
}
}
$t = get_markup_template("admin_blocklist.tpl");
return replace_macros($t, array(
'$title' => t('Administration'),
'$page' => t('Server Blocklist'),
'$intro' => t('This page can be used to define a black list of servers from the federated network that are not allowed to interact with your node. For all entered domains you should also give a reason why you have blocked the remote server.'),
'$public' => t('The list of blocked servers will be made publically available on the /friendica page so that your users and people investigating communication problems can find the reason easily.'),
'$addtitle' => t('Add new entry to block list'),
'$newdomain' => array('newentry_domain', t('Server Domain'), '', t('The domain of the new server to add to the block list. Do not include the protocol.'), 'required', '', ''),
'$newreason' => array('newentry_reason', t('Block reason'), '', t('The reason why you blocked this domain.'), 'required', '', ''),
'$submit' => t('Add Entry'),
'$savechanges' => t('Save changes to the blocklist'),
'$currenttitle' => t('Current Entries in the Blocklist'),
'$thurl' => t('Blocked domain'),
'$threason' => t('Reason for the block'),
'$delentry' => t('Delete entry from blocklist'),
'$entries' => $blocklistform,
'$baseurl' => App::get_baseurl(true),
'$confirm_delete' => t('Delete entry from blocklist?'),
'$form_security_token' => get_form_security_token("admin_blocklist")
));
}
/**
* @brief Process send data from Admin Blocklist Page
*
* @param App $a
*/
function admin_page_blocklist_post(App $a) {
if (!x($_POST,"page_blocklist_save") && (!x($_POST['page_blocklist_edit']))) {
return;
}
check_form_security_token_redirectOnErr('/admin/blocklist', 'admin_blocklist');
if (x($_POST['page_blocklist_save'])) {
// Add new item to blocklist
$blocklist = get_config('system', 'blocklist');
$blocklist[] = array(
'domain' => notags(trim($_POST['newentry_domain'])),
'reason' => notags(trim($_POST['newentry_reason']))
);
Config::set('system', 'blocklist', $blocklist);
info(t('Server added to blocklist.').EOL);
} else {
// Edit the entries from blocklist
$blocklist = array();
foreach ($_POST['domain'] as $id => $domain) {
// Trimming whitespaces as well as any lingering slashes
$domain = notags(trim($domain, "\x00..\x1F/"));
$reason = notags(trim($_POST['reason'][$id]));
if (!x($_POST['delete'][$id])) {
$blocklist[] = array(
'domain' => $domain,
'reason' => $reason
);
}
}
Config::set('system', 'blocklist', $blocklist);
info(t('Site blocklist updated.').EOL);
}
goaway('admin/blocklist');
return; // NOTREACHED
}
/**
* @brief Subpage with some stats about "the federation" network
*
@ -447,7 +543,7 @@ function admin_page_summary(App $a) {
$warningtext = array();
if (dbm::is_result($r)) {
$showwarning = true;
$warningtext[] = sprintf(t('Your DB still runs with MyISAM tables. You should change the engine type to InnoDB. As Friendica will use InnoDB only features in the future, you should change this! See <a href="%s">here</a> for a guide that may be helpful converting the table engines. You may also use the <tt>convert_innodb.sql</tt> in the <tt>/util</tt> directory of your Friendica installation.<br />'), 'https://dev.mysql.com/doc/refman/5.7/en/converting-tables-to-innodb.html');
$warningtext[] = sprintf(t('Your DB still runs with MyISAM tables. You should change the engine type to InnoDB. As Friendica will use InnoDB only features in the future, you should change this! See <a href="%s">here</a> for a guide that may be helpful converting the table engines. You may also use the command <tt>php include/dbstructure.php toinnodb</tt> of your Friendica installation for an automatic conversion.<br />'), 'https://dev.mysql.com/doc/refman/5.7/en/converting-tables-to-innodb.html');
}
// 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
@ -636,6 +732,7 @@ function admin_page_site_post(App $a) {
$timeout = ((x($_POST,'timeout')) ? intval(trim($_POST['timeout'])) : 60);
$maxloadavg = ((x($_POST,'maxloadavg')) ? intval(trim($_POST['maxloadavg'])) : 50);
$maxloadavg_frontend = ((x($_POST,'maxloadavg_frontend')) ? intval(trim($_POST['maxloadavg_frontend'])) : 50);
$min_memory = ((x($_POST,'min_memory')) ? intval(trim($_POST['min_memory'])) : 0);
$optimize_max_tablesize = ((x($_POST,'optimize_max_tablesize')) ? intval(trim($_POST['optimize_max_tablesize'])): 100);
$optimize_fragmentation = ((x($_POST,'optimize_fragmentation')) ? intval(trim($_POST['optimize_fragmentation'])): 30);
$poco_completion = ((x($_POST,'poco_completion')) ? intval(trim($_POST['poco_completion'])) : false);
@ -721,6 +818,7 @@ function admin_page_site_post(App $a) {
set_config('system','ssl_policy',$ssl_policy);
set_config('system','maxloadavg',$maxloadavg);
set_config('system','maxloadavg_frontend',$maxloadavg_frontend);
set_config('system','min_memory',$min_memory);
set_config('system','optimize_max_tablesize',$optimize_max_tablesize);
set_config('system','optimize_fragmentation',$optimize_fragmentation);
set_config('system','poco_completion',$poco_completion);
@ -1018,6 +1116,7 @@ function admin_page_site(App $a) {
'$timeout' => array('timeout', t("Network timeout"), (x(get_config('system','curl_timeout'))?get_config('system','curl_timeout'):60), t("Value is in seconds. Set to 0 for unlimited (not recommended).")),
'$maxloadavg' => array('maxloadavg', t("Maximum Load Average"), ((intval(get_config('system','maxloadavg')) > 0)?get_config('system','maxloadavg'):50), t("Maximum system load before delivery and poll processes are deferred - default 50.")),
'$maxloadavg_frontend' => array('maxloadavg_frontend', t("Maximum Load Average (Frontend)"), ((intval(get_config('system','maxloadavg_frontend')) > 0)?get_config('system','maxloadavg_frontend'):50), t("Maximum system load before the frontend quits service - default 50.")),
'$min_memory' => array('min_memory', t("Minimal Memory"), ((intval(get_config('system','min_memory')) > 0)?get_config('system','min_memory'):0), t("Minimal free memory in MB for the poller. Needs access to /proc/meminfo - default 0 (deactivated).")),
'$optimize_max_tablesize'=> array('optimize_max_tablesize', t("Maximum table size for optimization"), $optimize_max_tablesize, t("Maximum table size (in MB) for the automatic optimization - default 100 MB. Enter -1 to disable it.")),
'$optimize_fragmentation'=> array('optimize_fragmentation', t("Minimum level of fragmentation"), ((intval(get_config('system','optimize_fragmentation')) > 0)?get_config('system','optimize_fragmentation'):30), t("Minimum fragmenation level to start the automatic optimization - default value is 30%.")),

View file

@ -1,5 +1,7 @@
<?php
use Friendica\App;
require_once('include/socgraph.php');
require_once('include/Contact.php');
require_once('include/contact_selectors.php');

View file

@ -1,8 +1,9 @@
<?php
use Friendica\App;
function amcd_content(App $a) {
//header("Content-type: text/json");
echo <<< EOT
echo <<< JSON
{
"version":1,
"sessionstatus":{
@ -44,6 +45,6 @@ echo <<< EOT
}
}
}
EOT;
killme();
JSON;
killme();
}

View file

@ -1,5 +1,7 @@
<?php
use Friendica\App;
require_once('include/api.php');
function oauth_get_client($request){
@ -106,8 +108,6 @@ function api_content(App $a) {
'$no' => t('No'),
));
//echo "<pre>"; var_dump($app); killme();
return $o;
}

Some files were not shown because too many files have changed in this diff Show more