Merge remote-tracking branch 'upstream/develop' into 1601-api-statuses-lookup

This commit is contained in:
Michael Vogel 2016-02-14 21:04:59 +01:00
commit 92007a1438
615 changed files with 37187 additions and 22266 deletions

View File

@ -4,42 +4,32 @@ Friendica translations
Translation Process
-------------------
The strings used in the UI of Friendica is translated at [Transifex] [1] and then
included in the git repository at github. If you want to help with translation
for any language, be it correcting terms or translating friendica to a
currently not supported language, please register an account at transifex.com
and contact the friendica translation team there.
The strings used in the UI of Friendica is translated at [Transifex] [1] and then included in the git repository at github.
If you want to help with translation for any language, be it correcting terms or translating friendica to a currently not supported language, please register an account at transifex.com and contact the friendica translation team there.
Translating friendica is simple. Just use the online tool at transifex. If you
don't want to deal with git & co. that is fine, we check the status of the
translations regularly and import them into the source tree at github so that
others can use them.
Translating friendica is simple.
Just use the online tool at transifex.
If you don't want to deal with git & co. that is fine, we check the status of the translations regularly and import them into the source tree at github so that others can use them.
We do not include every translation from transifex in the source tree to avoid
a scattered and disturbed overall experience. As an uneducated guess we have a
lower limit of 50% translated strings before we include the language (for the
core message.po file, addon translation will be included once all strings of
an addon are translated. This limit is judging only by the amount of translated
strings under the assumption that the most prominent strings for the UI will be
translated first by a translation team. If you feel your translation useable
before this limit, please contact us and we will probably include your teams
work in the source tree.
We do not include every translation from transifex in the source tree to avoid a scattered and disturbed overall experience.
As an uneducated guess we have a lower limit of 50% translated strings before we include the language (for the core messages.po file, addont translation will be included once all strings of an addon are translated.
This limit is judging only by the amount of translated strings under the assumption that the most prominent strings for the UI will be translated first by a translation team.
If you feel your translation useable before this limit, please contact us and we will probably include your teams work in the source tree.
If you want to get your work into the source tree yourself, feel free to do so
and contact us with and question that arises. The process is simple and
friendica ships with all the tools necessary.
If you want to help translating, please concentrate on the core messages.po file first.
We will only include translations with a sufficient translated messages.po file.
Translations of addons will only be included, when the core file is included as well.
If you want to get your work into the source tree yourself, feel free to do so and contact us with and question that arises.
The process is simple and friendica ships with all the tools necessary.
The location of the translated files in the source tree is
/view/LNG-CODE/
where LNG-CODE is the language code used, e.g. de for German or fr for French.
For the email templates (the *.tpl files) just place them into the directory
and you are done. The translated strings come as a "message.po" file from
transifex which needs to be translated into the PHP file friendica uses. To do
so, place the file in the directory mentioned above and use the "po2php"
utility from the util directory of your friendica installation.
The translated strings come as a "message.po" file from transifex which needs to be translated into the PHP file friendica uses.
To do so, place the file in the directory mentioned above and use the "po2php" utility from the util directory of your friendica installation.
Assuming you want to convert the German localization which is placed in
view/de/message.po you would do the following.
Assuming you want to convert the German localization which is placed in view/de/message.po you would do the following.
1. Navigate at the command prompt to the base directory of your
friendica installation
@ -51,11 +41,11 @@ view/de/message.po you would do the following.
The output of the script will be placed at view/de/strings.php where
friendica is expecting it, so you can test your translation immediately.
3. Visit your friendica page to check if it still works in the language you
just translated. If not try to find the error, most likely PHP will give
you a hint in the log/warnings.about the error.
For debugging you can also try to "run" the file with PHP. This should
not give any output if the file is ok but might give a hint for
searching the bug in the file.
@ -69,30 +59,10 @@ view/de/message.po you would do the following.
Utilities
---------
Additional to the po2php script there are some more utilities for translation
in the "util" directory of the friendica source tree. If you only want to
translate friendica into another language you won't need any of these tools most
likely but it gives you an idea how the translation process of friendica
works.
Additional to the po2php script there are some more utilities for translation in the "util" directory of the friendica source tree.
If you only want to translate friendica into another language you wont need any of these tools most likely but it gives you an idea how the translation process of friendica works.
For further information see the utils/README file.
Known Problems
--------------
Friendica uses the language setting of the visitors browser to determain the
language for the UI. Most of the time this works, but there are some known
quirks.
One is that some browsers, like Safari, do the setting to "de-de" but friendica
only has a "de" localisation. A workaround would be to add a symbolic link
from
$friendica/view/de-de
pointing to
$friendica/view/de
Links
-----
[1]: https://www.transifex.com/projects/p/friendica/

View File

@ -17,6 +17,8 @@
* easily as email does today.
*/
require_once('include/autoloader.php');
require_once('include/config.php');
require_once('include/network.php');
require_once('include/plugin.php');
@ -36,7 +38,7 @@ define ( 'FRIENDICA_PLATFORM', 'Friendica');
define ( 'FRIENDICA_CODENAME', 'Asparagus');
define ( 'FRIENDICA_VERSION', '3.5-dev' );
define ( 'DFRN_PROTOCOL_VERSION', '2.23' );
define ( 'DB_UPDATE_VERSION', 1191 );
define ( 'DB_UPDATE_VERSION', 1194 );
/**
* @brief Constant with a HTML line break.
@ -467,6 +469,7 @@ class App {
public $is_tablet;
public $is_friendica_app;
public $performance = array();
public $callstack = array();
public $nav_sel;
@ -529,6 +532,8 @@ class App {
private $cached_profile_image;
private $cached_profile_picdate;
private static $a;
/**
* @brief App constructor.
*/
@ -554,6 +559,12 @@ class App {
$this->performance["marktime"] = 0;
$this->performance["markstart"] = microtime(true);
$this->callstack["database"] = array();
$this->callstack["network"] = array();
$this->callstack["file"] = array();
$this->callstack["rendering"] = array();
$this->callstack["parser"] = array();
$this->config = array();
$this->page = array();
$this->pager= array();
@ -703,6 +714,8 @@ class App {
}
}
self::$a = $this;
}
function get_basepath() {
@ -727,6 +740,10 @@ class App {
function get_baseurl($ssl = false) {
// Is the function called statically?
if (!is_object($this))
return(self::$a->get_baseurl($ssl));
$scheme = $this->scheme;
if((x($this->config,'system')) && (x($this->config['system'],'ssl_policy'))) {
@ -903,6 +920,10 @@ class App {
}
function get_cached_avatar_image($avatar_image){
return $avatar_image;
// The following code is deactivated. It doesn't seem to make any sense and it slows down the system.
/*
if($this->cached_profile_image[$avatar_image])
return $this->cached_profile_image[$avatar_image];
@ -922,6 +943,7 @@ class App {
}
}
return $this->cached_profile_image[$avatar_image];
*/
}
@ -1016,6 +1038,20 @@ class App {
$this->performance[$value] += (float)$duration;
$this->performance["marktime"] += (float)$duration;
// Trace the different functions with their timestamps
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 5);
array_shift($trace);
$function = array();
foreach ($trace AS $func)
$function[] = $func["function"];
$function = implode(", ", $function);
$this->callstack[$value][$function] += (float)$duration;
}
function mark_timestamp($mark) {

View File

@ -1,6 +1,6 @@
-- ------------------------------------------
-- Friendica 3.4.2 (Lily of the valley)
-- DB_UPDATE_VERSION 1190
-- Friendica 3.5-dev (Asparagus)
-- DB_UPDATE_VERSION 1193
-- ------------------------------------------
@ -8,20 +8,21 @@
-- TABLE addon
--
CREATE TABLE IF NOT EXISTS `addon` (
`id` int(11) NOT NULL auto_increment PRIMARY KEY,
`id` int(11) NOT NULL auto_increment,
`name` varchar(255) NOT NULL DEFAULT '',
`version` varchar(255) NOT NULL DEFAULT '',
`installed` tinyint(1) NOT NULL DEFAULT 0,
`hidden` tinyint(1) NOT NULL DEFAULT 0,
`timestamp` bigint(20) NOT NULL DEFAULT 0,
`plugin_admin` tinyint(1) NOT NULL DEFAULT 0
`plugin_admin` tinyint(1) NOT NULL DEFAULT 0,
PRIMARY KEY(`id`)
) DEFAULT CHARSET=utf8;
--
-- TABLE attach
--
CREATE TABLE IF NOT EXISTS `attach` (
`id` int(11) NOT NULL auto_increment PRIMARY KEY,
`id` int(11) NOT NULL auto_increment,
`uid` int(11) NOT NULL DEFAULT 0,
`hash` varchar(64) NOT NULL DEFAULT '',
`filename` varchar(255) NOT NULL DEFAULT '',
@ -33,28 +34,31 @@ CREATE TABLE IF NOT EXISTS `attach` (
`allow_cid` mediumtext NOT NULL,
`allow_gid` mediumtext NOT NULL,
`deny_cid` mediumtext NOT NULL,
`deny_gid` mediumtext NOT NULL
`deny_gid` mediumtext NOT NULL,
PRIMARY KEY(`id`)
) DEFAULT CHARSET=utf8;
--
-- TABLE auth_codes
--
CREATE TABLE IF NOT EXISTS `auth_codes` (
`id` varchar(40) NOT NULL PRIMARY KEY,
`id` varchar(40) NOT NULL,
`client_id` varchar(20) NOT NULL DEFAULT '',
`redirect_uri` varchar(200) NOT NULL DEFAULT '',
`expires` int(11) NOT NULL DEFAULT 0,
`scope` varchar(250) NOT NULL DEFAULT ''
`scope` varchar(250) NOT NULL DEFAULT '',
PRIMARY KEY(`id`)
) DEFAULT CHARSET=utf8;
--
-- TABLE cache
--
CREATE TABLE IF NOT EXISTS `cache` (
`k` varchar(255) NOT NULL PRIMARY KEY,
`k` varchar(255) NOT NULL,
`v` text NOT NULL,
`expire_mode` int(11) NOT NULL DEFAULT 0,
`updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY(`k`),
INDEX `updated` (`updated`)
) DEFAULT CHARSET=utf8;
@ -62,34 +66,37 @@ CREATE TABLE IF NOT EXISTS `cache` (
-- TABLE challenge
--
CREATE TABLE IF NOT EXISTS `challenge` (
`id` int(10) unsigned NOT NULL auto_increment PRIMARY KEY,
`id` int(10) unsigned NOT NULL auto_increment,
`challenge` varchar(255) NOT NULL DEFAULT '',
`dfrn-id` varchar(255) NOT NULL DEFAULT '',
`expire` int(11) NOT NULL DEFAULT 0,
`type` varchar(255) NOT NULL DEFAULT '',
`last_update` varchar(255) NOT NULL DEFAULT ''
`last_update` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY(`id`)
) DEFAULT CHARSET=utf8;
--
-- TABLE clients
--
CREATE TABLE IF NOT EXISTS `clients` (
`client_id` varchar(20) NOT NULL PRIMARY KEY,
`client_id` varchar(20) NOT NULL,
`pw` varchar(20) NOT NULL DEFAULT '',
`redirect_uri` varchar(200) NOT NULL DEFAULT '',
`name` text,
`icon` text,
`uid` int(11) NOT NULL DEFAULT 0
`uid` int(11) NOT NULL DEFAULT 0,
PRIMARY KEY(`client_id`)
) DEFAULT CHARSET=utf8;
--
-- TABLE config
--
CREATE TABLE IF NOT EXISTS `config` (
`id` int(10) unsigned NOT NULL auto_increment PRIMARY KEY,
`id` int(10) unsigned NOT NULL auto_increment,
`cat` varchar(255) NOT NULL DEFAULT '',
`k` varchar(255) NOT NULL DEFAULT '',
`v` text NOT NULL,
PRIMARY KEY(`id`),
INDEX `cat_k` (`cat`(30),`k`(30))
) DEFAULT CHARSET=utf8;
@ -97,7 +104,7 @@ CREATE TABLE IF NOT EXISTS `config` (
-- TABLE contact
--
CREATE TABLE IF NOT EXISTS `contact` (
`id` int(11) NOT NULL auto_increment PRIMARY KEY,
`id` int(11) NOT NULL auto_increment,
`uid` int(11) NOT NULL DEFAULT 0,
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`self` tinyint(1) NOT NULL DEFAULT 0,
@ -162,6 +169,7 @@ CREATE TABLE IF NOT EXISTS `contact` (
`notify_new_posts` tinyint(1) NOT NULL DEFAULT 0,
`fetch_further_information` tinyint(1) NOT NULL DEFAULT 0,
`ffi_keyword_blacklist` mediumtext NOT NULL,
PRIMARY KEY(`id`),
INDEX `uid` (`uid`)
) DEFAULT CHARSET=utf8;
@ -169,7 +177,7 @@ CREATE TABLE IF NOT EXISTS `contact` (
-- TABLE conv
--
CREATE TABLE IF NOT EXISTS `conv` (
`id` int(10) unsigned NOT NULL auto_increment PRIMARY KEY,
`id` int(10) unsigned NOT NULL auto_increment,
`guid` varchar(64) NOT NULL DEFAULT '',
`recips` mediumtext NOT NULL,
`uid` int(11) NOT NULL DEFAULT 0,
@ -177,6 +185,7 @@ CREATE TABLE IF NOT EXISTS `conv` (
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`subject` mediumtext NOT NULL,
PRIMARY KEY(`id`),
INDEX `uid` (`uid`)
) DEFAULT CHARSET=utf8;
@ -184,27 +193,29 @@ CREATE TABLE IF NOT EXISTS `conv` (
-- TABLE deliverq
--
CREATE TABLE IF NOT EXISTS `deliverq` (
`id` int(10) unsigned NOT NULL auto_increment PRIMARY KEY,
`id` int(10) unsigned NOT NULL auto_increment,
`cmd` varchar(32) NOT NULL DEFAULT '',
`item` int(11) NOT NULL DEFAULT 0,
`contact` int(11) NOT NULL DEFAULT 0
`contact` int(11) NOT NULL DEFAULT 0,
PRIMARY KEY(`id`)
) DEFAULT CHARSET=utf8;
--
-- TABLE dsprphotoq
--
CREATE TABLE IF NOT EXISTS `dsprphotoq` (
`id` int(10) unsigned NOT NULL auto_increment PRIMARY KEY,
`id` int(10) unsigned NOT NULL auto_increment,
`uid` int(11) NOT NULL DEFAULT 0,
`msg` mediumtext NOT NULL,
`attempt` tinyint(4) NOT NULL DEFAULT 0
`attempt` tinyint(4) NOT NULL DEFAULT 0,
PRIMARY KEY(`id`)
) DEFAULT CHARSET=utf8;
--
-- TABLE event
--
CREATE TABLE IF NOT EXISTS `event` (
`id` int(11) NOT NULL auto_increment PRIMARY KEY,
`id` int(11) NOT NULL auto_increment,
`uid` int(11) NOT NULL DEFAULT 0,
`cid` int(11) NOT NULL DEFAULT 0,
`uri` varchar(255) NOT NULL DEFAULT '',
@ -223,6 +234,7 @@ CREATE TABLE IF NOT EXISTS `event` (
`allow_gid` mediumtext NOT NULL,
`deny_cid` mediumtext NOT NULL,
`deny_gid` mediumtext NOT NULL,
PRIMARY KEY(`id`),
INDEX `uid` (`uid`)
) DEFAULT CHARSET=utf8;
@ -230,7 +242,7 @@ CREATE TABLE IF NOT EXISTS `event` (
-- TABLE fcontact
--
CREATE TABLE IF NOT EXISTS `fcontact` (
`id` int(10) unsigned NOT NULL auto_increment PRIMARY KEY,
`id` int(10) unsigned NOT NULL auto_increment,
`url` varchar(255) NOT NULL DEFAULT '',
`name` varchar(255) NOT NULL DEFAULT '',
`photo` varchar(255) NOT NULL DEFAULT '',
@ -246,6 +258,7 @@ CREATE TABLE IF NOT EXISTS `fcontact` (
`alias` varchar(255) NOT NULL DEFAULT '',
`pubkey` text NOT NULL,
`updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY(`id`),
INDEX `addr` (`addr`)
) DEFAULT CHARSET=utf8;
@ -253,20 +266,22 @@ CREATE TABLE IF NOT EXISTS `fcontact` (
-- TABLE ffinder
--
CREATE TABLE IF NOT EXISTS `ffinder` (
`id` int(10) unsigned NOT NULL auto_increment PRIMARY KEY,
`id` int(10) unsigned NOT NULL auto_increment,
`uid` int(10) unsigned NOT NULL DEFAULT 0,
`cid` int(10) unsigned NOT NULL DEFAULT 0,
`fid` int(10) unsigned NOT NULL DEFAULT 0
`fid` int(10) unsigned NOT NULL DEFAULT 0,
PRIMARY KEY(`id`)
) DEFAULT CHARSET=utf8;
--
-- TABLE fserver
--
CREATE TABLE IF NOT EXISTS `fserver` (
`id` int(11) NOT NULL auto_increment PRIMARY KEY,
`id` int(11) NOT NULL auto_increment,
`server` varchar(255) NOT NULL DEFAULT '',
`posturl` varchar(255) NOT NULL DEFAULT '',
`key` text NOT NULL,
PRIMARY KEY(`id`),
INDEX `server` (`server`)
) DEFAULT CHARSET=utf8;
@ -274,7 +289,7 @@ CREATE TABLE IF NOT EXISTS `fserver` (
-- TABLE fsuggest
--
CREATE TABLE IF NOT EXISTS `fsuggest` (
`id` int(11) NOT NULL auto_increment PRIMARY KEY,
`id` int(11) NOT NULL auto_increment,
`uid` int(11) NOT NULL DEFAULT 0,
`cid` int(11) NOT NULL DEFAULT 0,
`name` varchar(255) NOT NULL DEFAULT '',
@ -282,16 +297,18 @@ CREATE TABLE IF NOT EXISTS `fsuggest` (
`request` varchar(255) NOT NULL DEFAULT '',
`photo` varchar(255) NOT NULL DEFAULT '',
`note` text NOT NULL,
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00'
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY(`id`)
) DEFAULT CHARSET=utf8;
--
-- TABLE gcign
--
CREATE TABLE IF NOT EXISTS `gcign` (
`id` int(11) NOT NULL auto_increment PRIMARY KEY,
`id` int(11) NOT NULL auto_increment,
`uid` int(11) NOT NULL DEFAULT 0,
`gcid` int(11) NOT NULL DEFAULT 0,
PRIMARY KEY(`id`),
INDEX `uid` (`uid`),
INDEX `gcid` (`gcid`)
) DEFAULT CHARSET=utf8;
@ -300,7 +317,7 @@ CREATE TABLE IF NOT EXISTS `gcign` (
-- TABLE gcontact
--
CREATE TABLE IF NOT EXISTS `gcontact` (
`id` int(10) unsigned NOT NULL auto_increment PRIMARY KEY,
`id` int(10) unsigned NOT NULL auto_increment,
`name` varchar(255) NOT NULL DEFAULT '',
`nick` varchar(255) NOT NULL DEFAULT '',
`url` varchar(255) NOT NULL DEFAULT '',
@ -315,11 +332,17 @@ CREATE TABLE IF NOT EXISTS `gcontact` (
`about` text NOT NULL,
`keywords` text NOT NULL,
`gender` varchar(32) NOT NULL DEFAULT '',
`birthday` varchar(32) NOT NULL DEFAULT '0000-00-00',
`community` tinyint(1) NOT NULL DEFAULT 0,
`hide` tinyint(1) NOT NULL DEFAULT 0,
`nsfw` tinyint(1) NOT NULL DEFAULT 0,
`network` varchar(255) NOT NULL DEFAULT '',
`addr` varchar(255) NOT NULL DEFAULT '',
`notify` text NOT NULL,
`alias` varchar(255) NOT NULL DEFAULT '',
`generation` tinyint(3) NOT NULL DEFAULT 0,
`server_url` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY(`id`),
INDEX `nurl` (`nurl`),
INDEX `updated` (`updated`)
) DEFAULT CHARSET=utf8;
@ -328,12 +351,13 @@ CREATE TABLE IF NOT EXISTS `gcontact` (
-- TABLE glink
--
CREATE TABLE IF NOT EXISTS `glink` (
`id` int(10) unsigned NOT NULL auto_increment PRIMARY KEY,
`id` int(10) unsigned NOT NULL auto_increment,
`cid` int(11) NOT NULL DEFAULT 0,
`uid` int(11) NOT NULL DEFAULT 0,
`gcid` int(11) NOT NULL DEFAULT 0,
`zcid` int(11) NOT NULL DEFAULT 0,
`updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY(`id`),
INDEX `cid_uid_gcid_zcid` (`cid`,`uid`,`gcid`,`zcid`),
INDEX `gcid` (`gcid`),
INDEX `zcid` (`zcid`)
@ -343,11 +367,12 @@ CREATE TABLE IF NOT EXISTS `glink` (
-- TABLE group
--
CREATE TABLE IF NOT EXISTS `group` (
`id` int(10) unsigned NOT NULL auto_increment PRIMARY KEY,
`id` int(10) unsigned NOT NULL auto_increment,
`uid` int(10) unsigned NOT NULL DEFAULT 0,
`visible` tinyint(1) NOT NULL DEFAULT 0,
`deleted` tinyint(1) NOT NULL DEFAULT 0,
`name` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY(`id`),
INDEX `uid` (`uid`)
) DEFAULT CHARSET=utf8;
@ -355,10 +380,11 @@ CREATE TABLE IF NOT EXISTS `group` (
-- TABLE group_member
--
CREATE TABLE IF NOT EXISTS `group_member` (
`id` int(10) unsigned NOT NULL auto_increment PRIMARY KEY,
`id` int(10) unsigned NOT NULL auto_increment,
`uid` int(10) unsigned NOT NULL DEFAULT 0,
`gid` int(10) unsigned NOT NULL DEFAULT 0,
`contact-id` int(10) unsigned NOT NULL DEFAULT 0,
PRIMARY KEY(`id`),
INDEX `uid_gid_contactid` (`uid`,`gid`,`contact-id`)
) DEFAULT CHARSET=utf8;
@ -366,7 +392,7 @@ CREATE TABLE IF NOT EXISTS `group_member` (
-- TABLE gserver
--
CREATE TABLE IF NOT EXISTS `gserver` (
`id` int(10) unsigned NOT NULL auto_increment PRIMARY KEY,
`id` int(10) unsigned NOT NULL auto_increment,
`url` varchar(255) NOT NULL DEFAULT '',
`nurl` varchar(255) NOT NULL DEFAULT '',
`version` varchar(255) NOT NULL DEFAULT '',
@ -381,6 +407,7 @@ CREATE TABLE IF NOT EXISTS `gserver` (
`last_poco_query` datetime DEFAULT '0000-00-00 00:00:00',
`last_contact` datetime DEFAULT '0000-00-00 00:00:00',
`last_failure` datetime DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY(`id`),
INDEX `nurl` (`nurl`)
) DEFAULT CHARSET=utf8;
@ -388,11 +415,12 @@ CREATE TABLE IF NOT EXISTS `gserver` (
-- TABLE guid
--
CREATE TABLE IF NOT EXISTS `guid` (
`id` int(10) unsigned NOT NULL auto_increment PRIMARY KEY,
`id` int(10) unsigned NOT NULL auto_increment,
`guid` varchar(255) NOT NULL DEFAULT '',
`plink` varchar(255) NOT NULL DEFAULT '',
`uri` varchar(255) NOT NULL DEFAULT '',
`network` varchar(32) NOT NULL DEFAULT '',
PRIMARY KEY(`id`),
INDEX `guid` (`guid`),
INDEX `plink` (`plink`),
INDEX `uri` (`uri`)
@ -402,11 +430,12 @@ CREATE TABLE IF NOT EXISTS `guid` (
-- TABLE hook
--
CREATE TABLE IF NOT EXISTS `hook` (
`id` int(11) NOT NULL auto_increment PRIMARY KEY,
`id` int(11) NOT NULL auto_increment,
`hook` varchar(255) NOT NULL DEFAULT '',
`file` varchar(255) NOT NULL DEFAULT '',
`function` varchar(255) NOT NULL DEFAULT '',
`priority` int(11) unsigned NOT NULL DEFAULT 0,
PRIMARY KEY(`id`),
INDEX `hook_file_function` (`hook`(30),`file`(60),`function`(30))
) DEFAULT CHARSET=utf8;
@ -414,7 +443,7 @@ CREATE TABLE IF NOT EXISTS `hook` (
-- TABLE intro
--
CREATE TABLE IF NOT EXISTS `intro` (
`id` int(10) unsigned NOT NULL auto_increment PRIMARY KEY,
`id` int(10) unsigned NOT NULL auto_increment,
`uid` int(10) unsigned NOT NULL DEFAULT 0,
`fid` int(11) NOT NULL DEFAULT 0,
`contact-id` int(11) NOT NULL DEFAULT 0,
@ -424,18 +453,20 @@ CREATE TABLE IF NOT EXISTS `intro` (
`hash` varchar(255) NOT NULL DEFAULT '',
`datetime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`blocked` tinyint(1) NOT NULL DEFAULT 1,
`ignore` tinyint(1) NOT NULL DEFAULT 0
`ignore` tinyint(1) NOT NULL DEFAULT 0,
PRIMARY KEY(`id`)
) DEFAULT CHARSET=utf8;
--
-- TABLE item
--
CREATE TABLE IF NOT EXISTS `item` (
`id` int(10) unsigned NOT NULL auto_increment PRIMARY KEY,
`id` int(10) unsigned NOT NULL auto_increment,
`guid` varchar(255) NOT NULL DEFAULT '',
`uri` varchar(255) NOT NULL DEFAULT '',
`uid` int(10) unsigned NOT NULL DEFAULT 0,
`contact-id` int(11) NOT NULL DEFAULT 0,
`gcontact-id` int(11) unsigned NOT NULL DEFAULT 0,
`type` varchar(255) NOT NULL DEFAULT '',
`wall` tinyint(1) NOT NULL DEFAULT 0,
`gravity` tinyint(1) NOT NULL DEFAULT 0,
@ -493,6 +524,7 @@ CREATE TABLE IF NOT EXISTS `item` (
`rendered-hash` varchar(32) NOT NULL DEFAULT '',
`rendered-html` mediumtext NOT NULL,
`global` tinyint(1) NOT NULL DEFAULT 0,
PRIMARY KEY(`id`),
INDEX `guid` (`guid`),
INDEX `uri` (`uri`),
INDEX `parent` (`parent`),
@ -509,6 +541,7 @@ CREATE TABLE IF NOT EXISTS `item` (
INDEX `uid_thrparent` (`uid`,`thr-parent`),
INDEX `uid_parenturi` (`uid`,`parent-uri`),
INDEX `uid_contactid_created` (`uid`,`contact-id`,`created`),
INDEX `gcontactid_uid_created` (`gcontact-id`,`uid`,`created`),
INDEX `wall_body` (`wall`,`body`(6)),
INDEX `uid_visible_moderated_created` (`uid`,`visible`,`moderated`,`created`),
INDEX `uid_uri` (`uid`,`uri`),
@ -531,11 +564,12 @@ CREATE TABLE IF NOT EXISTS `item` (
-- TABLE item_id
--
CREATE TABLE IF NOT EXISTS `item_id` (
`id` int(11) NOT NULL auto_increment PRIMARY KEY,
`id` int(11) NOT NULL auto_increment,
`iid` int(11) NOT NULL DEFAULT 0,
`uid` int(11) NOT NULL DEFAULT 0,
`sid` varchar(255) NOT NULL DEFAULT '',
`service` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY(`id`),
INDEX `uid` (`uid`),
INDEX `sid` (`sid`),
INDEX `service` (`service`),
@ -546,17 +580,18 @@ CREATE TABLE IF NOT EXISTS `item_id` (
-- TABLE locks
--
CREATE TABLE IF NOT EXISTS `locks` (
`id` int(11) NOT NULL auto_increment PRIMARY KEY,
`id` int(11) NOT NULL auto_increment,
`name` varchar(128) NOT NULL DEFAULT '',
`locked` tinyint(1) NOT NULL DEFAULT 0,
`created` datetime DEFAULT '0000-00-00 00:00:00'
`created` datetime DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY(`id`)
) DEFAULT CHARSET=utf8;
--
-- TABLE mail
--
CREATE TABLE IF NOT EXISTS `mail` (
`id` int(10) unsigned NOT NULL auto_increment PRIMARY KEY,
`id` int(10) unsigned NOT NULL auto_increment,
`uid` int(10) unsigned NOT NULL DEFAULT 0,
`guid` varchar(64) NOT NULL DEFAULT '',
`from-name` varchar(255) NOT NULL DEFAULT '',
@ -573,6 +608,7 @@ CREATE TABLE IF NOT EXISTS `mail` (
`uri` varchar(255) NOT NULL DEFAULT '',
`parent-uri` varchar(255) NOT NULL DEFAULT '',
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY(`id`),
INDEX `uid` (`uid`),
INDEX `guid` (`guid`),
INDEX `convid` (`convid`),
@ -585,7 +621,7 @@ CREATE TABLE IF NOT EXISTS `mail` (
-- TABLE mailacct
--
CREATE TABLE IF NOT EXISTS `mailacct` (
`id` int(11) NOT NULL auto_increment PRIMARY KEY,
`id` int(11) NOT NULL auto_increment,
`uid` int(11) NOT NULL DEFAULT 0,
`server` varchar(255) NOT NULL DEFAULT '',
`port` int(11) NOT NULL DEFAULT 0,
@ -597,16 +633,18 @@ CREATE TABLE IF NOT EXISTS `mailacct` (
`action` int(11) NOT NULL DEFAULT 0,
`movetofolder` varchar(255) NOT NULL DEFAULT '',
`pubmail` tinyint(1) NOT NULL DEFAULT 0,
`last_check` datetime NOT NULL DEFAULT '0000-00-00 00:00:00'
`last_check` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY(`id`)
) DEFAULT CHARSET=utf8;
--
-- TABLE manage
--
CREATE TABLE IF NOT EXISTS `manage` (
`id` int(11) NOT NULL auto_increment PRIMARY KEY,
`id` int(11) NOT NULL auto_increment,
`uid` int(11) NOT NULL DEFAULT 0,
`mid` int(11) NOT NULL DEFAULT 0,
PRIMARY KEY(`id`),
INDEX `uid_mid` (`uid`,`mid`)
) DEFAULT CHARSET=utf8;
@ -614,7 +652,7 @@ CREATE TABLE IF NOT EXISTS `manage` (
-- TABLE notify
--
CREATE TABLE IF NOT EXISTS `notify` (
`id` int(11) NOT NULL auto_increment PRIMARY KEY,
`id` int(11) NOT NULL auto_increment,
`hash` varchar(64) NOT NULL DEFAULT '',
`type` int(11) NOT NULL DEFAULT 0,
`name` varchar(255) NOT NULL DEFAULT '',
@ -629,6 +667,7 @@ CREATE TABLE IF NOT EXISTS `notify` (
`seen` tinyint(1) NOT NULL DEFAULT 0,
`verb` varchar(255) NOT NULL DEFAULT '',
`otype` varchar(16) NOT NULL DEFAULT '',
PRIMARY KEY(`id`),
INDEX `uid` (`uid`)
) DEFAULT CHARSET=utf8;
@ -636,24 +675,50 @@ CREATE TABLE IF NOT EXISTS `notify` (
-- TABLE notify-threads
--
CREATE TABLE IF NOT EXISTS `notify-threads` (
`id` int(11) NOT NULL auto_increment PRIMARY KEY,
`id` int(11) NOT NULL auto_increment,
`notify-id` int(11) NOT NULL DEFAULT 0,
`master-parent-item` int(10) unsigned NOT NULL DEFAULT 0,
`parent-item` int(10) unsigned NOT NULL DEFAULT 0,
`receiver-uid` int(11) NOT NULL DEFAULT 0,
PRIMARY KEY(`id`),
INDEX `master-parent-item` (`master-parent-item`),
INDEX `receiver-uid` (`receiver-uid`)
) DEFAULT CHARSET=utf8;
--
-- TABLE oembed
--
CREATE TABLE IF NOT EXISTS `oembed` (
`url` varchar(255) NOT NULL,
`content` text NOT NULL,
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY(`url`),
INDEX `created` (`created`)
) DEFAULT CHARSET=utf8;
--
-- TABLE parsed_url
--
CREATE TABLE IF NOT EXISTS `parsed_url` (
`url` varchar(255) NOT NULL,
`guessing` tinyint(1) NOT NULL DEFAULT 0,
`oembed` tinyint(1) NOT NULL DEFAULT 0,
`content` text NOT NULL,
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY(`url`,`guessing`,`oembed`),
INDEX `created` (`created`)
) DEFAULT CHARSET=utf8;
--
-- TABLE pconfig
--
CREATE TABLE IF NOT EXISTS `pconfig` (
`id` int(11) NOT NULL auto_increment PRIMARY KEY,
`id` int(11) NOT NULL auto_increment,
`uid` int(11) NOT NULL DEFAULT 0,
`cat` varchar(255) NOT NULL DEFAULT '',
`k` varchar(255) NOT NULL DEFAULT '',
`v` mediumtext NOT NULL,
PRIMARY KEY(`id`),
INDEX `uid_cat_k` (`uid`,`cat`(30),`k`(30))
) DEFAULT CHARSET=utf8;
@ -661,7 +726,7 @@ CREATE TABLE IF NOT EXISTS `pconfig` (
-- TABLE photo
--
CREATE TABLE IF NOT EXISTS `photo` (
`id` int(10) unsigned NOT NULL auto_increment PRIMARY KEY,
`id` int(10) unsigned NOT NULL auto_increment,
`uid` int(10) unsigned NOT NULL DEFAULT 0,
`contact-id` int(10) unsigned NOT NULL DEFAULT 0,
`guid` varchar(64) NOT NULL DEFAULT '',
@ -683,6 +748,7 @@ CREATE TABLE IF NOT EXISTS `photo` (
`allow_gid` mediumtext NOT NULL,
`deny_cid` mediumtext NOT NULL,
`deny_gid` mediumtext NOT NULL,
PRIMARY KEY(`id`),
INDEX `uid` (`uid`),
INDEX `resource-id` (`resource-id`),
INDEX `guid` (`guid`)
@ -692,7 +758,7 @@ CREATE TABLE IF NOT EXISTS `photo` (
-- TABLE poll
--
CREATE TABLE IF NOT EXISTS `poll` (
`id` int(11) NOT NULL auto_increment PRIMARY KEY,
`id` int(11) NOT NULL auto_increment,
`uid` int(11) NOT NULL DEFAULT 0,
`q0` mediumtext NOT NULL,
`q1` mediumtext NOT NULL,
@ -704,6 +770,7 @@ CREATE TABLE IF NOT EXISTS `poll` (
`q7` mediumtext NOT NULL,
`q8` mediumtext NOT NULL,
`q9` mediumtext NOT NULL,
PRIMARY KEY(`id`),
INDEX `uid` (`uid`)
) DEFAULT CHARSET=utf8;
@ -711,9 +778,10 @@ CREATE TABLE IF NOT EXISTS `poll` (
-- TABLE poll_result
--
CREATE TABLE IF NOT EXISTS `poll_result` (
`id` int(11) NOT NULL auto_increment PRIMARY KEY,
`id` int(11) NOT NULL auto_increment,
`poll_id` int(11) NOT NULL DEFAULT 0,
`choice` int(11) NOT NULL DEFAULT 0,
PRIMARY KEY(`id`),
INDEX `poll_id` (`poll_id`),
INDEX `choice` (`choice`)
) DEFAULT CHARSET=utf8;
@ -722,7 +790,7 @@ CREATE TABLE IF NOT EXISTS `poll_result` (
-- TABLE profile
--
CREATE TABLE IF NOT EXISTS `profile` (
`id` int(11) NOT NULL auto_increment PRIMARY KEY,
`id` int(11) NOT NULL auto_increment,
`uid` int(11) NOT NULL DEFAULT 0,
`profile-name` varchar(255) NOT NULL DEFAULT '',
`is-default` tinyint(1) NOT NULL DEFAULT 0,
@ -763,6 +831,7 @@ CREATE TABLE IF NOT EXISTS `profile` (
`thumb` varchar(255) NOT NULL DEFAULT '',
`publish` tinyint(1) NOT NULL DEFAULT 0,
`net-publish` tinyint(1) NOT NULL DEFAULT 0,
PRIMARY KEY(`id`),
INDEX `hometown` (`hometown`)
) DEFAULT CHARSET=utf8;
@ -770,39 +839,42 @@ CREATE TABLE IF NOT EXISTS `profile` (
-- TABLE profile_check
--
CREATE TABLE IF NOT EXISTS `profile_check` (
`id` int(10) unsigned NOT NULL auto_increment PRIMARY KEY,
`id` int(10) unsigned NOT NULL auto_increment,
`uid` int(10) unsigned NOT NULL DEFAULT 0,
`cid` int(10) unsigned NOT NULL DEFAULT 0,
`dfrn_id` varchar(255) NOT NULL DEFAULT '',
`sec` varchar(255) NOT NULL DEFAULT '',
`expire` int(11) NOT NULL DEFAULT 0
`expire` int(11) NOT NULL DEFAULT 0,
PRIMARY KEY(`id`)
) DEFAULT CHARSET=utf8;
--
-- TABLE push_subscriber
--
CREATE TABLE IF NOT EXISTS `push_subscriber` (
`id` int(11) NOT NULL auto_increment PRIMARY KEY,
`id` int(11) NOT NULL auto_increment,
`uid` int(11) NOT NULL DEFAULT 0,
`callback_url` varchar(255) NOT NULL DEFAULT '',
`topic` varchar(255) NOT NULL DEFAULT '',
`nickname` varchar(255) NOT NULL DEFAULT '',
`push` int(11) NOT NULL DEFAULT 0,
`last_update` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`secret` varchar(255) NOT NULL DEFAULT ''
`secret` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY(`id`)
) DEFAULT CHARSET=utf8;
--
-- TABLE queue
--
CREATE TABLE IF NOT EXISTS `queue` (
`id` int(11) NOT NULL auto_increment PRIMARY KEY,
`id` int(11) NOT NULL auto_increment,
`cid` int(11) NOT NULL DEFAULT 0,
`network` varchar(32) NOT NULL DEFAULT '',
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`last` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`content` mediumtext NOT NULL,
`batch` tinyint(1) NOT NULL DEFAULT 0,
PRIMARY KEY(`id`),
INDEX `cid` (`cid`),
INDEX `created` (`created`),
INDEX `last` (`last`),
@ -814,21 +886,23 @@ CREATE TABLE IF NOT EXISTS `queue` (
-- TABLE register
--
CREATE TABLE IF NOT EXISTS `register` (
`id` int(11) unsigned NOT NULL auto_increment PRIMARY KEY,
`id` int(11) unsigned NOT NULL auto_increment,
`hash` varchar(255) NOT NULL DEFAULT '',
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`uid` int(11) unsigned NOT NULL DEFAULT 0,
`password` varchar(255) NOT NULL DEFAULT '',
`language` varchar(16) NOT NULL DEFAULT ''
`language` varchar(16) NOT NULL DEFAULT '',
PRIMARY KEY(`id`)
) DEFAULT CHARSET=utf8;
--
-- TABLE search
--
CREATE TABLE IF NOT EXISTS `search` (
`id` int(11) NOT NULL auto_increment PRIMARY KEY,
`id` int(11) NOT NULL auto_increment,
`uid` int(11) NOT NULL DEFAULT 0,
`term` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY(`id`),
INDEX `uid` (`uid`),
INDEX `term` (`term`)
) DEFAULT CHARSET=utf8;
@ -837,10 +911,11 @@ CREATE TABLE IF NOT EXISTS `search` (
-- TABLE session
--
CREATE TABLE IF NOT EXISTS `session` (
`id` bigint(20) unsigned NOT NULL auto_increment PRIMARY KEY,
`id` bigint(20) unsigned NOT NULL auto_increment,
`sid` varchar(255) NOT NULL DEFAULT '',
`data` text NOT NULL,
`expire` int(10) unsigned NOT NULL DEFAULT 0,
PRIMARY KEY(`id`),
INDEX `sid` (`sid`),
INDEX `expire` (`expire`)
) DEFAULT CHARSET=utf8;
@ -849,12 +924,13 @@ CREATE TABLE IF NOT EXISTS `session` (
-- TABLE sign
--
CREATE TABLE IF NOT EXISTS `sign` (
`id` int(10) unsigned NOT NULL auto_increment PRIMARY KEY,
`id` int(10) unsigned NOT NULL auto_increment,
`iid` int(10) unsigned NOT NULL DEFAULT 0,
`retract_iid` int(10) unsigned NOT NULL DEFAULT 0,
`signed_text` mediumtext NOT NULL,
`signature` text NOT NULL,
`signer` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY(`id`),
INDEX `iid` (`iid`),
INDEX `retract_iid` (`retract_iid`)
) DEFAULT CHARSET=utf8;
@ -863,12 +939,13 @@ CREATE TABLE IF NOT EXISTS `sign` (
-- TABLE spam
--
CREATE TABLE IF NOT EXISTS `spam` (
`id` int(11) NOT NULL auto_increment PRIMARY KEY,
`id` int(11) NOT NULL auto_increment,
`uid` int(11) NOT NULL DEFAULT 0,
`spam` int(11) NOT NULL DEFAULT 0,
`ham` int(11) NOT NULL DEFAULT 0,
`term` varchar(255) NOT NULL DEFAULT '',
`date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY(`id`),
INDEX `uid` (`uid`),
INDEX `spam` (`spam`),
INDEX `ham` (`ham`),
@ -879,7 +956,7 @@ CREATE TABLE IF NOT EXISTS `spam` (
-- TABLE term
--
CREATE TABLE IF NOT EXISTS `term` (
`tid` int(10) unsigned NOT NULL auto_increment PRIMARY KEY,
`tid` int(10) unsigned NOT NULL auto_increment,
`oid` int(10) unsigned NOT NULL DEFAULT 0,
`otype` tinyint(3) unsigned NOT NULL DEFAULT 0,
`type` tinyint(3) unsigned NOT NULL DEFAULT 0,
@ -891,6 +968,7 @@ CREATE TABLE IF NOT EXISTS `term` (
`global` tinyint(1) NOT NULL DEFAULT 0,
`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 `uid_term_tid` (`uid`,`term`,`tid`),
INDEX `type_term` (`type`,`term`),
@ -903,9 +981,10 @@ CREATE TABLE IF NOT EXISTS `term` (
-- TABLE thread
--
CREATE TABLE IF NOT EXISTS `thread` (
`iid` int(10) unsigned NOT NULL DEFAULT 0 PRIMARY KEY,
`iid` int(10) unsigned NOT NULL DEFAULT 0,
`uid` int(10) unsigned NOT NULL DEFAULT 0,
`contact-id` int(11) unsigned NOT NULL DEFAULT 0,
`gcontact-id` int(11) unsigned NOT NULL DEFAULT 0,
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`edited` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`commented` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
@ -926,12 +1005,15 @@ CREATE TABLE IF NOT EXISTS `thread` (
`forum_mode` tinyint(1) NOT NULL DEFAULT 0,
`mention` tinyint(1) NOT NULL DEFAULT 0,
`network` varchar(32) NOT NULL DEFAULT '',
PRIMARY KEY(`iid`),
INDEX `created` (`created`),
INDEX `commented` (`commented`),
INDEX `uid_network_commented` (`uid`,`network`,`commented`),
INDEX `uid_network_created` (`uid`,`network`,`created`),
INDEX `uid_contactid_commented` (`uid`,`contact-id`,`commented`),
INDEX `uid_contactid_created` (`uid`,`contact-id`,`created`),
INDEX `uid_gcontactid_commented` (`uid`,`gcontact-id`,`commented`),
INDEX `uid_gcontactid_created` (`uid`,`gcontact-id`,`created`),
INDEX `wall_private_received` (`wall`,`private`,`received`),
INDEX `uid_created` (`uid`,`created`),
INDEX `uid_commented` (`uid`,`commented`)
@ -941,33 +1023,20 @@ CREATE TABLE IF NOT EXISTS `thread` (
-- TABLE tokens
--
CREATE TABLE IF NOT EXISTS `tokens` (
`id` varchar(40) NOT NULL PRIMARY KEY,
`id` varchar(40) NOT NULL,
`secret` text NOT NULL,
`client_id` varchar(20) NOT NULL DEFAULT '',
`expires` int(11) NOT NULL DEFAULT 0,
`scope` varchar(200) NOT NULL DEFAULT '',
`uid` int(11) NOT NULL DEFAULT 0
) DEFAULT CHARSET=utf8;
--
-- TABLE unique_contacts
--
CREATE TABLE IF NOT EXISTS `unique_contacts` (
`id` int(11) NOT NULL auto_increment PRIMARY KEY,
`url` varchar(255) NOT NULL DEFAULT '',
`nick` varchar(255) NOT NULL DEFAULT '',
`name` varchar(255) NOT NULL DEFAULT '',
`avatar` varchar(255) NOT NULL DEFAULT '',
`location` varchar(255) NOT NULL DEFAULT '',
`about` text NOT NULL,
INDEX `url` (`url`)
`uid` int(11) NOT NULL DEFAULT 0,
PRIMARY KEY(`id`)
) DEFAULT CHARSET=utf8;
--
-- TABLE user
--
CREATE TABLE IF NOT EXISTS `user` (
`uid` int(11) NOT NULL auto_increment PRIMARY KEY,
`uid` int(11) NOT NULL auto_increment,
`guid` varchar(64) NOT NULL DEFAULT '',
`username` varchar(255) NOT NULL DEFAULT '',
`password` varchar(255) NOT NULL DEFAULT '',
@ -1009,6 +1078,7 @@ CREATE TABLE IF NOT EXISTS `user` (
`deny_cid` mediumtext NOT NULL,
`deny_gid` mediumtext NOT NULL,
`openidserver` text NOT NULL,
PRIMARY KEY(`uid`),
INDEX `nickname` (`nickname`)
) DEFAULT CHARSET=utf8;
@ -1016,8 +1086,9 @@ CREATE TABLE IF NOT EXISTS `user` (
-- TABLE userd
--
CREATE TABLE IF NOT EXISTS `userd` (
`id` int(11) NOT NULL auto_increment PRIMARY KEY,
`id` int(11) NOT NULL auto_increment,
`username` varchar(255) NOT NULL,
PRIMARY KEY(`id`),
INDEX `username` (`username`)
) DEFAULT CHARSET=utf8;
@ -1025,12 +1096,13 @@ CREATE TABLE IF NOT EXISTS `userd` (
-- TABLE workerqueue
--
CREATE TABLE IF NOT EXISTS `workerqueue` (
`id` int(11) NOT NULL auto_increment PRIMARY KEY,
`id` int(11) NOT NULL auto_increment,
`parameter` text NOT NULL,
`priority` tinyint(3) unsigned NOT NULL DEFAULT 0,
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`pid` int(11) NOT NULL DEFAULT 0,
`executed` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY(`id`),
INDEX `created` (`created`)
) DEFAULT CHARSET=utf8;

View File

@ -53,9 +53,12 @@ Posting to Community forums
If you are a member of a community forum, you may post to the forum by including an @-tag in the post mentioning the forum.
For example @bicycle would send my post to all members of the group "bicycle" in addition to the normal recipients.
If your post is private you must also explicitly include the group in the post permissions (to allow the forum "contact" to see the post) **and** mention it in a tag (which redistributes the post to the forum members).
If you mention a forum (you are a member of) in a new posting, the posting will be distributed to all members of the forum, regardless of your privacy settings for the posting.
Also, if the forum is a public forum, your posting will be public for the all internet users.
If your post is private you must also explicitly include the group in the post permissions (to allow the forum "contact" to see the post) **and** mention it in a tag (which redistributes the post to the forum members).
Posting privately to a public forum, will result in your posting being displayed on the forum wall, but not on yours.
You may also post to a community forum by posting a "wall-to-wall" post using secure cross-site authentication.
You may also post to a community forum by posting a "wall-to-wall" post using secure cross-site authentication.
Comments which are relayed to community forums will be relayed back to the original post creator.
Mentioning the forum with an @-tag in a comment does not relay the message, as distribution is controlled entirely by the original post creator.

View File

@ -47,8 +47,10 @@ Friendica Documentation and Resources
* [Theme Development](help/themes)
* [Smarty 3 Templates](help/smarty3-templates)
* [Database schema documantation](help/database)
* [Class Autoloading](help/autoloader)
* [Code - Reference(Doxygen generated - sets cookies)](doc/html/)
**External Resources**
* [Main Website](http://friendica.com)

View File

@ -1,5 +1,7 @@
Friendica Addon/Plugin development
==========================
==============
* [Home](help)
Please see the sample addon 'randplace' for a working example of using some of these features.
Addons work by intercepting event hooks - which must be registered.
@ -16,12 +18,12 @@ Future extensions may provide for "setup" amd "remove".
Plugins should contain a comment block with the four following parameters:
/*
* Name: My Great Plugin
* Description: This is what my plugin does. It's really cool
* Version: 1.0
* Author: John Q. Public <john@myfriendicasite.com>
*/
/*
* Name: My Great Plugin
* Description: This is what my plugin does. It's really cool.
* Version: 1.0
* Author: John Q. Public <john@myfriendicasite.com>
*/
Register your plugin hooks during installation.
@ -45,7 +47,7 @@ Your hook callback functions will be called with at least one and possibly two a
If you wish to make changes to the calling data, you must declare them as reference variables (with '&') during function declaration.
###$a
#### $a
$a is the Friendica 'App' class.
It contains a wealth of information about the current state of Friendica:
@ -56,13 +58,13 @@ It contains a wealth of information about the current state of Friendica:
It is recommeded you call this '$a' to match its usage elsewhere.
###$b
#### $b
$b can be called anything you like.
This is information specific to the hook currently being processed, and generally contains information that is being immediately processed or acted on that you can use, display, or alter.
Remember to declare it with '&' if you wish to alter it.
Modules
--------
---
Plugins/addons may also act as "modules" and intercept all page requests for a given URL path.
In order for a plugin to act as a module it needs to define a function "plugin_name_module()" which takes no arguments and needs not do anything.
@ -72,15 +74,15 @@ These are parsed into an array $a->argv, with a corresponding $a->argc indicatin
So http://my.web.site/plugin/arg1/arg2 would look for a module named "plugin" and pass its module functions the $a App structure (which is available to many components).
This will include:
$a->argc = 3
$a->argv = array(0 => 'plugin', 1 => 'arg1', 2 => 'arg2');
$a->argc = 3
$a->argv = array(0 => 'plugin', 1 => 'arg1', 2 => 'arg2');
Your module functions will often contain the function plugin_name_content(&$a), which defines and returns the page body content.
They may also contain plugin_name_post(&$a) which is called before the _content function and typically handles the results of POST forms.
You may also have plugin_name_init(&$a) which is called very early on and often does module initialisation.
Templates
----------
---
If your plugin needs some template, you can use the Friendica template system.
Friendica uses [smarty3](http://www.smarty.net/) as a template engine.
@ -104,140 +106,140 @@ See also the wiki page [Quick Template Guide](https://github.com/friendica/frien
Current hooks
-------------
###'authenticate'
### 'authenticate'
'authenticate' is called when a user attempts to login.
$b is an array containing:
'username' => the supplied username
'password' => the supplied password
'username' => the supplied username
'password' => the supplied password
'authenticated' => set this to non-zero to authenticate the user.
'user_record' => successful authentication must also return a valid user record from the database
###'logged_in'
### 'logged_in'
'logged_in' is called after a user has successfully logged in.
$b contains the $a->user array.
###'display_item'
### 'display_item'
'display_item' is called when formatting a post for display.
$b is an array:
'item' => The item (array) details pulled from the database
'output' => the (string) HTML representation of this item prior to adding it to the page
###'post_local'
### 'post_local'
* called when a status post or comment is entered on the local system
* $b is the item array of the information to be stored in the database
* Please note: body contents are bbcode - not HTML
###'post_local_end'
### 'post_local_end'
* called when a local status post or comment has been stored on the local system
* $b is the item array of the information which has just been stored in the database
* Please note: body contents are bbcode - not HTML
###'post_remote'
### 'post_remote'
* called when receiving a post from another source. This may also be used to post local activity or system generated messages.
* $b is the item array of information to be stored in the database and the item body is bbcode.
###'settings_form'
### 'settings_form'
* called when generating the HTML for the user Settings page
* $b is the (string) HTML of the settings page before the final '</form>' tag.
###'settings_post'
### 'settings_post'
* called when the Settings pages are submitted
* $b is the $_POST array
###'plugin_settings'
### 'plugin_settings'
* called when generating the HTML for the addon settings page
* $b is the (string) HTML of the addon settings page before the final '</form>' tag.
###'plugin_settings_post'
### 'plugin_settings_post'
* called when the Addon Settings pages are submitted
* $b is the $_POST array
###'profile_post'
### 'profile_post'
* called when posting a profile page
* $b is the $_POST array
###'profile_edit'
### 'profile_edit'
'profile_edit' is called prior to output of profile edit page.
$b is an array containing:
'profile' => profile (array) record from the database
'entry' => the (string) HTML of the generated entry
###'profile_advanced'
### 'profile_advanced'
* called when the HTML is generated for the 'Advanced profile', corresponding to the 'Profile' tab within a person's profile page
* $b is the (string) HTML representation of the generated profile
* The profile array details are in $a->profile.
###'directory_item'
### 'directory_item'
'directory_item' is called from the Directory page when formatting an item for display.
$b is an array:
'contact' => contact (array) record for the person from the database
'entry' => the (string) HTML of the generated entry
###'profile_sidebar_enter'
### 'profile_sidebar_enter'
* called prior to generating the sidebar "short" profile for a page
* $b is the person's profile array
###'profile_sidebar'
### 'profile_sidebar'
'profile_sidebar is called when generating the sidebar "short" profile for a page.
$b is an array:
'profile' => profile (array) record for the person from the database
'entry' => the (string) HTML of the generated entry
###'contact_block_end'
### 'contact_block_end'
is called when formatting the block of contacts/friends on a profile sidebar has completed.
$b is an array:
'contacts' => array of contacts
'output' => the (string) generated HTML of the contact block
###'bbcode'
### 'bbcode'
* called during conversion of bbcode to html
* $b is a string converted text
###'html2bbcode'
### 'html2bbcode'
* called during conversion of html to bbcode (e.g. remote message posting)
* $b is a string converted text
###'page_header'
### 'page_header'
* called after building the page navigation section
* $b is a string HTML of nav region
###'personal_xrd'
### 'personal_xrd'
'personal_xrd' is called prior to output of personal XRD file.
$b is an array:
'user' => the user record for the person
'xml' => the complete XML to be output
###'home_content'
### 'home_content'
* called prior to output home page content, shown to unlogged users
* $b is (string) HTML of section region
###'contact_edit'
### 'contact_edit'
is called when editing contact details on an individual from the Contacts page.
$b is an array:
'contact' => contact record (array) of target contact
'output' => the (string) generated HTML of the contact edit page
###'contact_edit_post'
### 'contact_edit_post'
* called when posting the contact edit page.
* $b is the $_POST array
###'init_1'
### 'init_1'
* called just after DB has been opened and before session start
* $b is not used or passed
###'page_end'
### 'page_end'
* called after HTML content functions have completed
* $b is (string) HTML of content div
###'avatar_lookup'
### 'avatar_lookup'
'avatar_lookup' is called when looking up the avatar.
$b is an array:
@ -245,11 +247,11 @@ $b is an array:
'email' => email to look up the avatar for
'url' => the (string) generated URL of the avatar
###'emailer_send_prepare'
### 'emailer_send_prepare'
'emailer_send_prepare' called from Emailer::send() before building the mime message.
$b is an array, params to Emailer::send()
'fromName' => name of the sender
'fromName' => name of the sender
'fromEmail' => email fo the sender
'replyTo' => replyTo address to direct responses
'toEmail' => destination email address
@ -258,20 +260,20 @@ $b is an array, params to Emailer::send()
'textVersion' => text only version of the message
'additionalMailHeader' => additions to the smtp mail header
###'emailer_send'
### 'emailer_send'
is called before calling PHP's mail().
$b is an array, params to mail()
'to'
'subject'
'to'
'subject'
'body'
'headers'
###'nav_info'
### 'nav_info'
is called after the navigational menu is build in include/nav.php.
$b is an array containing $nav from nav.php.
###'template_vars'
### 'template_vars'
is called before vars are passed to the template engine to render the page.
The registered function can add,change or remove variables passed to template.
$b is an array with:
@ -463,4 +465,3 @@ mod/cb.php: call_hooks('cb_afterpost');
mod/cb.php: call_hooks('cb_content', $o);
mod/directory.php: call_hooks('directory_item', $arr);

View File

@ -90,8 +90,8 @@ If you run your own server, upload the files and check out the Mozilla wiki link
Let's encrypt
---
If you run your own server and you control your name server, the "Let's encrypt" initiative might become an interesting alternative.
Their offer is not ready, yet.
If you run your own server, the "Let's encrypt" initiative might become an interesting alternative.
Their offer is in public beta right now.
Check out [their website](https://letsencrypt.org/) for status updates.
Web server settings

View File

@ -24,6 +24,9 @@ You are not required to provide the year.
System settings
---
**Settings should be done in the admin panel** (/admin).
Those settings found in the database, will always override the settings added to the ``.htconfig.php`` file.
###Language
Please see util/README for information on creating language translations.
@ -219,6 +222,8 @@ LOGGER_DEBUG will show a good deal of information about system activity but will
You may also select LOGGER_ALL but due to the volume of information we recommend only enabling this when you are tracking down a specific problem.
Other log levels are possible but are not being used at the present time.
Please be aware that turning on the logging can fill up the disk space on your server relatively quick.
You should take preventions with e.g. [logrotate](https://en.wikipedia.org/wiki/Log_rotation) or similar tools.
###PHP error logging
@ -237,4 +242,6 @@ The vast majority of issues reported at these levels are completely harmless.
Please report to the developers any errors you encounter in the logs using the recommended settings above.
They generally indicate issues which need to be resolved.
If you encounter a blank (white) page when using the application, view the PHP logs - as this almost always indicates an error has occurred.
If you encounter a blank (white) page when using the application, view the PHP logs - as this almost always indicates an error has occurred.
*Note*: PHP logging cannot be activated from the admin panel but has to be configured from the ``.htconfig.php`` file.

View File

@ -21,11 +21,22 @@ You can tag a person on a different network or one that is **not in your social
* @mike@macgirvin.com - This is called a "remote mention" and can only be an email-style locator, not a web URL.
Unless their system blocks unsolicited "mentions", the person tagged will likely receive a "Mention" post/activity or become a direct participant in the conversation in the case of public posts. Please note that Friendica blocks incoming "mentions" from people with no relationship to you. This is a spam prevention measure.
Unless their system blocks unsolicited "mentions", the person tagged will likely receive a "Mention" post/activity or become a direct participant in the conversation in the case of public posts.
Friendica blocks incoming “mentions” from people with no relationship to you.
The exception is an ongiong conversation started from a contact of both you and the 3rd person or a conversation in a forum where you are a member of.
This is a spam prevention measure.
Remote mentions are delivered using the OStatus protocol. This protocol is used by Friendica and GNU Social and several other systems, but is not currently implemented in Diaspora.
Remote mentions are delivered using the OStatus protocol.
This protocol is used by Friendica and GNU Social and several other systems, but is not currently implemented in Diaspora.
As the OStatus protocol allows this Friendica user can be @-mentioned by users from platforms using this protocol in conversations if the "Enable OStatus support" is activated on the Friendica node.
These @-mentions wont be blocked, even if there is no relationship between the sender and the receiver of the message.
Friendica makes no distinction between people and groups for the purpose of tagging. (Some other networks use !group to indicate a group.)
Friendica makes no distinction between people and forums for the purpose of tagging.
(Some other networks use !forum to indicate a forum.)
If you sort your contacts into groups, you cannot @-mention these groups.
But you can select the group in the access control when creating a new posting, to allow (or disallow) a certain group of people to see the posting.
See [Groups and Privacy](help/Groups-and-Privacy) for more details about grouping your contacts.
**Topical Tags**

View File

@ -7,6 +7,21 @@ Please refer to the linked documentation for further information.
## Implemented API calls
### General
#### HTTP Method
API endpoints can restrict the method used to request them.
Using an invalid method results in HTTP error 405 "Method Not Allowed".
In this document, the required method is listed after the endpoint name. "*" means every method can be used.
#### Auth
Friendica supports basic http auth and OAuth 1 to authenticate the user to the api.
OAuth settings can be added by the user in web UI under /settings/oauth/
In this document, endpoints which requires auth are marked with "AUTH" after endpoint name
#### Unsupported parameters
* cursor: Not implemented in GNU Social
* trim_user: Not implemented in GNU Social
@ -38,9 +53,9 @@ Error body is
json:
```
{
"error": "Specific error message",
"request": "API path requested",
"code": "HTTP error code"
"error": "Specific error message",
"request": "API path requested",
"code": "HTTP error code"
}
```
@ -54,19 +69,20 @@ xml:
```
---
### account/rate_limit_status
### account/rate_limit_status (*; AUTH)
---
### account/verify_credentials
### account/verify_credentials (*; AUTH)
#### Parameters
* skip_status: Don't show the "status" field. (Default: false)
* include_entities: "true" shows entities for pictures and links (Default: false)
---
### conversation/show
### conversation/show (*; AUTH)
Unofficial Twitter command. It shows all direct answers (excluding the original post) to a given id.
#### Parameters
#### Parameter
* id: id of the post
* count: Items per page (default: 20)
* page: page number
@ -80,7 +96,7 @@ Unofficial Twitter command. It shows all direct answers (excluding the original
* contributor_details
---
### direct_messages
### direct_messages (*; AUTH)
#### Parameters
* count: Items per page (default: 20)
* page: page number
@ -93,7 +109,7 @@ Unofficial Twitter command. It shows all direct answers (excluding the original
* skip_status
---
### direct_messages/all
### direct_messages/all (*; AUTH)
#### Parameters
* count: Items per page (default: 20)
* page: page number
@ -102,7 +118,7 @@ Unofficial Twitter command. It shows all direct answers (excluding the original
* getText: Defines the format of the status field. Can be "html" or "plain"
---
### direct_messages/conversation
### direct_messages/conversation (*; AUTH)
Shows all direct messages of a conversation
#### Parameters
* count: Items per page (default: 20)
@ -113,7 +129,7 @@ Shows all direct messages of a conversation
* uri: URI of the conversation
---
### direct_messages/new
### direct_messages/new (POST,PUT; AUTH)
#### Parameters
* user_id: id of the user
* screen_name: screen name (for technical reasons, this value is not unique!)
@ -122,7 +138,7 @@ Shows all direct messages of a conversation
* title: Title of the direct message
---
### direct_messages/sent
### direct_messages/sent (*; AUTH)
#### Parameters
* count: Items per page (default: 20)
* page: page number
@ -132,7 +148,7 @@ Shows all direct messages of a conversation
* include_entities: "true" shows entities for pictures and links (Default: false)
---
### favorites
### favorites (*; AUTH)
#### Parameters
* count: Items per page (default: 20)
* page: page number
@ -144,22 +160,23 @@ Shows all direct messages of a conversation
* user_id
* screen_name
Favorites aren't displayed to other users, so "user_id" and "screen_name". So setting this value will result in an empty array.
Favorites aren't displayed to other users, so "user_id" and "screen_name" are unsupported.
Set this values will result in an empty array.
---
### favorites/create
### favorites/create (POST,PUT; AUTH)
#### Parameters
* id
* include_entities: "true" shows entities for pictures and links (Default: false)
---
### favorites/destroy
### favorites/destroy (POST,DELETE; AUTH)
#### Parameters
* id
* include_entities: "true" shows entities for pictures and links (Default: false)
---
### followers/ids
### followers/ids (*; AUTH)
#### Parameters
* stringify_ids: Should the id numbers be sent as text (true) or number (false)? (default: false)
@ -171,139 +188,7 @@ Favorites aren't displayed to other users, so "user_id" and "screen_name". So se
Friendica doesn't allow showing followers of other users.
---
### friendica/activity/<verb>
#### parameters
* id: item id
Add or remove an activity from an item.
'verb' can be one of:
- like
- dislike
- attendyes
- attendno
- attendmaybe
To remove an activity, prepend the verb with "un", eg. "unlike" or "undislike"
Attend verbs disable eachother: that means that if "attendyes" was added to an item, adding "attendno" remove previous "attendyes".
Attend verbs should be used only with event-related items (there is no check at the moment)
#### Return values
On success:
json
```"ok"```
xml
```<ok>true</ok>```
On error:
HTTP 400 BadRequest
---
### friendica/photo
#### Parameters
* photo_id: Resource id of a photo.
* scale: (optional) scale value of the photo
Returns data of a picture with the given resource.
If 'scale' isn't provided, returned data include full url to each scale of the photo.
If 'scale' is set, returned data include image data base64 encoded.
possibile scale value are:
0: original or max size by server settings
1: image with or height at <= 640
2: image with or height at <= 320
3: thumbnail 160x160
4: Profile image at 175x175
5: Profile image at 80x80
6: Profile image at 48x48
An image used as profile image has only scale 4-6, other images only 0-3
#### Return values
json
```
{
"id": "photo id"
"created": "date(YYYY-MM-GG HH:MM:SS)",
"edited": "date(YYYY-MM-GG HH:MM:SS)",
"title": "photo title",
"desc": "photo description",
"album": "album name",
"filename": "original file name",
"type": "mime type",
"height": "number",
"width": "number",
"profile": "1 if is profile photo",
"link": {
"<scale>": "url to image"
...
},
// if 'scale' is set
"datasize": "size in byte",
"data": "base64 encoded image data"
}
```
xml
```
<photo>
<id>photo id</id>
<created>date(YYYY-MM-GG HH:MM:SS)</created>
<edited>date(YYYY-MM-GG HH:MM:SS)</edited>
<title>photo title</title>
<desc>photo description</desc>
<album>album name</album>
<filename>original file name</filename>
<type>mime type</type>
<height>number</height>
<width>number</width>
<profile>1 if is profile photo</profile>
<links type="array">
<link type="mime type" scale="scale number" href="image url"/>
...
</links>
</photo>
```
---
### friendica/photos/list
Returns a list of all photo resources of the logged in user.
#### Return values
json
```
[
{
id: "resource_id",
album: "album name",
filename: "original file name",
type: "image mime type",
thumb: "url to thumb sized image"
},
...
]
```
xml
```
<photos type="array">
<photo id="resource_id"
album="album name"
filename="original file name"
type="image mime type">
"url to thumb sized image"
</photo>
...
</photos>
```
---
### friends/ids
### friends/ids (*; AUTH)
#### Parameters
* stringify_ids: Should the id numbers be sent as text (true) or number (false)? (default: false)
@ -315,15 +200,15 @@ xml
Friendica doesn't allow showing friends of other users.
---
### help/test
### help/test (*)
---
### media/upload
### media/upload (POST,PUT; AUTH)
#### Parameters
* media: image data
---
### oauth/request_token
### oauth/request_token (*)
#### Parameters
* oauth_callback
@ -331,7 +216,7 @@ Friendica doesn't allow showing friends of other users.
* x_auth_access_type
---
### oauth/access_token
### oauth/access_token (*)
#### Parameters
* oauth_verifier
@ -341,7 +226,7 @@ Friendica doesn't allow showing friends of other users.
* x_auth_mode
---
### statuses/destroy
### statuses/destroy (POST,DELETE; AUTH)
#### Parameters
* id: message number
* include_entities: "true" shows entities for pictures and links (Default: false)
@ -350,15 +235,21 @@ Friendica doesn't allow showing friends of other users.
* trim_user
---
### statuses/followers
### statuses/followers (*; AUTH)
#### Parameters
* include_entities: "true" shows entities for pictures and links (Default: false)
---
### statuses/friends
### statuses/friends (*; AUTH)
#### Parameters
* include_entities: "true" shows entities for pictures and links (Default: false)
---
### statuses/friends_timeline
### statuses/friends_timeline (*; AUTH)
#### Parameters
* count: Items per page (default: 20)
* page: page number
@ -374,7 +265,7 @@ Friendica doesn't allow showing friends of other users.
* contributor_details
---
### statuses/home_timeline
### statuses/home_timeline (*; AUTH)
#### Parameters
* count: Items per page (default: 20)
* page: page number
@ -390,7 +281,7 @@ Friendica doesn't allow showing friends of other users.
* contributor_details
---
### statuses/mentions
### statuses/mentions (*; AUTH)
#### Parameters
* count: Items per page (default: 20)
* page: page number
@ -404,7 +295,7 @@ Friendica doesn't allow showing friends of other users.
* contributor_details
---
### statuses/public_timeline
### statuses/public_timeline (*; AUTH)
#### Parameters
* count: Items per page (default: 20)
* page: page number
@ -418,7 +309,7 @@ Friendica doesn't allow showing friends of other users.
* trim_user
---
### statuses/replies
### statuses/replies (*; AUTH)
#### Parameters
* count: Items per page (default: 20)
* page: page number
@ -432,7 +323,7 @@ Friendica doesn't allow showing friends of other users.
* contributor_details
---
### statuses/retweet
### statuses/retweet (POST,PUT; AUTH)
#### Parameters
* id: message number
* include_entities: "true" shows entities for pictures and links (Default: false)
@ -441,7 +332,7 @@ Friendica doesn't allow showing friends of other users.
* trim_user
---
### statuses/show
### statuses/show (*; AUTH)
#### Parameters
* id: message number
* conversation: if set to "1" show all messages of the conversation with the given id
@ -476,7 +367,7 @@ Friendica doesn't allow showing friends of other users.
* display_coordinates
---
### statuses/user_timeline
### statuses/user_timeline (*; AUTH)
#### Parameters
* user_id: id of the user
* screen_name: screen name (for technical reasons, this value is not unique!)
@ -489,15 +380,16 @@ Friendica doesn't allow showing friends of other users.
* include_entities: "true" shows entities for pictures and links (Default: false)
#### Unsupported parameters
* include_rts
* trim_user
* contributor_details
---
### statusnet/config
### statusnet/config (*)
---
### statusnet/version
### statusnet/version (*)
#### Unsupported parameters
* user_id
@ -507,7 +399,7 @@ Friendica doesn't allow showing friends of other users.
Friendica doesn't allow showing followers of other users.
---
### users/search
### users/search (*)
#### Parameters
* q: name of the user
@ -517,7 +409,7 @@ Friendica doesn't allow showing followers of other users.
* include_entities
---
### users/show
### users/show (*)
#### Parameters
* user_id: id of the user
* screen_name: screen name (for technical reasons, this value is not unique!)
@ -533,8 +425,39 @@ Friendica doesn't allow showing friends of other users.
## Implemented API calls (not compatible with other APIs)
---
### friendica/group_show
### friendica/activity/<verb>
#### parameters
* id: item id
Add or remove an activity from an item.
'verb' can be one of:
- like
- dislike
- attendyes
- attendno
- attendmaybe
To remove an activity, prepend the verb with "un", eg. "unlike" or "undislike"
Attend verbs disable eachother: that means that if "attendyes" was added to an item, adding "attendno" remove previous "attendyes".
Attend verbs should be used only with event-related items (there is no check at the moment)
#### Return values
On success:
json
```"ok"```
xml
```<ok>true</ok>```
On error:
HTTP 400 BadRequest
---
### friendica/group_show (*; AUTH)
Return all or a specified group of the user with the containing contacts as array.
#### Parameters
@ -542,22 +465,23 @@ Return all or a specified group of the user with the containing contacts as arra
#### Return values
Array of:
* name: name of the group
* gid: id of the group
* user: array of group members (return from api_get_user() function for each member)
---
### friendica/group_delete
### friendica/group_delete (POST,DELETE; AUTH)
delete the specified group of contacts; API call need to include the correct gid AND name of the group to be deleted.
---
### Parameters
#### Parameters
* gid: id of the group to be deleted
* name: name of the group to be deleted
#### Return values
Array of:
* success: true if successfully deleted
* gid: gid of the deleted group
* name: name of the deleted group
@ -566,19 +490,22 @@ Array of:
---
### friendica/group_create
### friendica/group_create (POST,PUT; AUTH)
Create the group with the posted array of contacts as members.
#### Parameters
* name: name of the group to be created
#### POST data
JSON data as Array like the result of „users/group_show“:
JSON data as Array like the result of "users/group_show":
* gid
* name
* array of users
#### Return values
Array of:
* success: true if successfully created or reactivated
* gid: gid of the created group
* name: name of the created group
@ -587,26 +514,175 @@ Array of:
---
### friendica/group_update
### friendica/group_update (POST)
Update the group with the posted array of contacts as members (post all members of the group to the call; function will remove members not posted).
#### Parameters
* gid: id of the group to be changed
* name: name of the group to be changed
#### POST data
JSON data as array like the result of „users/group_show“:
* gid
* name
* array of users
#### Return values
Array of:
* success: true if successfully updated
* gid: gid of the changed group
* name: name of the changed group
* status: „missing user“ | „ok“
* wrong users: array of users, which were not available in the contact table
---
### friendica/notifications (GET)
Return last 50 notification for current user, ordered by date with unseen item on top
#### Parameters
none
#### Return values
Array of:
* id: id of the note
* type: type of notification as int (see NOTIFY_* constants in boot.php)
* name: full name of the contact subject of the note
* url: contact's profile url
* photo: contact's profile photo
* date: datetime string of the note
* timestamp: timestamp of the node
* date_rel: relative date of the note (eg. "1 hour ago")
* msg: note message in bbcode
* msg_html: note message in html
* msg_plain: note message in plain text
* link: link to note
* seen: seen state: 0 or 1
---
### friendica/notifications/seen (POST)
Set note as seen, returns item object if possible
#### Parameters
id: id of the note to set seen
#### Return values
If the note is linked to an item, the item is returned, just like one of the "statuses/*_timeline" api.
If the note is not linked to an item, a success status is returned:
* "success" (json) | "&lt;status&gt;success&lt;/status&gt;" (xml)
---
### friendica/photo (*; AUTH)
#### Parameters
* photo_id: Resource id of a photo.
* scale: (optional) scale value of the photo
Returns data of a picture with the given resource.
If 'scale' isn't provided, returned data include full url to each scale of the photo.
If 'scale' is set, returned data include image data base64 encoded.
possibile scale value are:
* 0: original or max size by server settings
* 1: image with or height at <= 640
* 2: image with or height at <= 320
* 3: thumbnail 160x160
* 4: Profile image at 175x175
* 5: Profile image at 80x80
* 6: Profile image at 48x48
An image used as profile image has only scale 4-6, other images only 0-3
#### Return values
json
```
{
"id": "photo id"
"created": "date(YYYY-MM-GG HH:MM:SS)",
"edited": "date(YYYY-MM-GG HH:MM:SS)",
"title": "photo title",
"desc": "photo description",
"album": "album name",
"filename": "original file name",
"type": "mime type",
"height": "number",
"width": "number",
"profile": "1 if is profile photo",
"link": {
"<scale>": "url to image"
...
},
// if 'scale' is set
"datasize": "size in byte",
"data": "base64 encoded image data"
}
```
xml
```
<photo>
<id>photo id</id>
<created>date(YYYY-MM-GG HH:MM:SS)</created>
<edited>date(YYYY-MM-GG HH:MM:SS)</edited>
<title>photo title</title>
<desc>photo description</desc>
<album>album name</album>
<filename>original file name</filename>
<type>mime type</type>
<height>number</height>
<width>number</width>
<profile>1 if is profile photo</profile>
<links type="array">
<link type="mime type" scale="scale number" href="image url"/>
...
</links>
</photo>
```
---
### friendica/photos/list (*; AUTH)
Returns a list of all photo resources of the logged in user.
#### Return values
json
```
[
{
id: "resource_id",
album: "album name",
filename: "original file name",
type: "image mime type",
thumb: "url to thumb sized image"
},
...
]
```
xml
```
<photos type="array">
<photo id="resource_id"
album="album name"
filename="original file name"
type="image mime type">
"url to thumb sized image"
</photo>
...
</photos>
```
---
## Not Implemented API calls
The following API calls are implemented in GNU Social but not in Friendica: (incomplete)
@ -702,13 +778,13 @@ The following API calls from the Twitter API aren't implemented neither in Frien
### BASH / cURL
Betamax has documentated some example API usage from a [bash script](https://en.wikipedia.org/wiki/Bash_(Unix_shell) employing [curl](https://en.wikipedia.org/wiki/CURL) (see [his posting](https://betamax65.de/display/betamax65/43539)).
/usr/bin/curl -u USER:PASS https://YOUR.FRIENDICA.TLD/api/statuses/update.xml -d source="some source id" -d status="the status you want to post"
/usr/bin/curl -u USER:PASS https://YOUR.FRIENDICA.TLD/api/statuses/update.xml -d source="some source id" -d status="the status you want to post"
### Python
The [RSStoFriedika](https://github.com/pafcu/RSStoFriendika) code can be used as an example of how to use the API with python. The lines for posting are located at [line 21](https://github.com/pafcu/RSStoFriendika/blob/master/RSStoFriendika.py#L21) and following.
def tweet(server, message, group_allow=None):
url = server + '/api/statuses/update'
urllib2.urlopen(url, urllib.urlencode({'status': message,'group_allow[]':group_allow}, doseq=True))
def tweet(server, message, group_allow=None):
url = server + '/api/statuses/update'
urllib2.urlopen(url, urllib.urlencode({'status': message,'group_allow[]':group_allow}, doseq=True))
There is also a [module for python 3](https://bitbucket.org/tobiasd/python-friendica) for using the API.

209
doc/autoloader.md Normal file
View File

@ -0,0 +1,209 @@
Autoloader
==========
* [Home](help)
There is some initial support to class autoloading in Friendica core.
The autoloader code is in `include/autoloader.php`.
It's derived from composer autoloader code.
Namespaces and Classes are mapped to folders and files in `library/`,
and the map must be updated by hand, because we don't use composer yet.
The mapping is defined by files in `include/autoloader/` folder.
Currently, only HTMLPurifier library is loaded using autoloader.
## A quick introdution to class autoloading
The autoloader it's a way for php to automagically include the file that define a class when the class is first used, without the need to use "require_once" every time.
Once is setup you don't have to use it in any way. You need a class? you use the class.
At his basic is a function passed to the "spl_autoload_register()" function, which receive as argument the class name the script want and is it job to include the correct php file where that class is defined.
The best source for documentation is [php site](http://php.net/manual/en/language.oop5.autoload.php).
One example, based on fictional friendica code.
Let's say you have a php file in "include/" that define a very useful class:
```
file: include/ItemsManager.php
<?php
namespace \Friendica;
class ItemsManager {
public function getAll() { ... }
public function getByID($id) { ... }
}
```
The class "ItemsManager" has been declared in "Friendica" namespace.
Namespaces are useful to keep things separated and avoid names clash (could be that a library you want to use defines a class named "ItemsManager", but as long as is in another namespace, you don't have any problem)
If we were using composer, we had configured it with path where to find the classes of "Friendica" namespace, and then the composer script will generate the autoloader machinery for us.
As we don't use composer, we need check that the autoloader knows the Friendica namespace.
So in "include/autoloader/autoload_psr4.php" there should be something like
```
$vendorDir = dirname(dirname(dirname(__FILE__)))."/library";
$baseDir = dirname($vendorDir);
return array(
"Friendica" => array($baseDir."/include");
);
```
That tells the autoloader code to look for files that defines classes in "Friendica" namespace under "include/" folder. (And btw, that's why the file has the same name as the class it defines.)
*note*: The structure of files in "include/autoloader/" has been copied from the code generated by composer, to ease the work of enable autoloader for external libraries under "library/"
Let's say now that you need to load some items in a view, maybe in a fictional "mod/network.php".
Somewere at the start of the scripts, the autoloader was initialized. In Friendica is done at the top of "boot.php", with "require_once('include/autoloader.php');".
The code will be something like:
```
file: mod/network.php
<?php
function network_content(&$a) {
$itemsmanager = new \Friendica\ItemsManager();
$items = $itemsmanager->getAll();
// pass $items to template
// return result
}
```
That's a quite simple example, but look: no "require()"!
You need to use a class, you use the class and you don't need to do anything more.
Going further: now we have a bunch of "*Manager" classes that cause some code duplication, let's define a BaseManager class, where to move all code in common between all managers:
```
file: include/BaseManager.php
<?php
namespace \Friendica;
class BaseManager {
public function thatFunctionEveryManagerUses() { ... }
}
```
and then let's change the ItemsManager class to use this code
```
file: include/ItemsManager.php
<?php
namespace \Friendica;
class ItemsManager extends BaseManager {
public function getAll() { ... }
public function getByID($id) { ... }
}
```
The autoloader don't mind what you need the class for. You need a class, you get the class.
It works with the "BaseManager" example here, it works when we need to call static methods on a class:
```
file: include/dfrn.php
<?php
namespace \Friendica;
class dfrn {
public static function mail($item, $owner) { ... }
}
```
```
file: 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:
```
file: 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 real "include/delivery.php" unchanged, but as the code is declared to be in "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
namespace \Frienidca;
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 everytime, you can use the "use" php keyword
```
<?php
namespace \Frienidca;
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 more deep if you want to, like:
```
<?php
namespace \Friendica\Network;
class DFRN {
}
```
or
```
<?php
namespace \Friendica\DBA;
class MySQL {
}
```
So you can think of namespaces as folders in a unix filesystem, with global scope as the root ("\").

View File

@ -27,7 +27,6 @@ Database Tables
| [group](help/database/db_group) | privacy groups, group info |
| [group_member](help/database/db_group_member) | privacy groups, member info |
| [gserver](help/database/db_gserver) | |
| [guid](help/database/db_guid) | |
| [hook](help/database/db_hook) | plugin hook registry |
| [intro](help/database/db_intro) | |
| [item](help/database/db_item) | all posts |
@ -38,6 +37,8 @@ Database Tables
| [manage](help/database/db_manage) | table of accounts that can "su" each other |
| [notify](help/database/db_notify) | notifications |
| [notify-threads](help/database/db_notify-threads) | |
| [oembed](help/database/db_oembed) | cache for OEmbed queries |
| [parsed_url](help/database/db_parsed_url) | cache for "parse_url" queries |
| [pconfig](help/database/db_pconfig) | personal (per user) configuration storage |
| [photo](help/database/db_photo) | photo storage |
| [poll](help/database/db_poll) | data for polls |
@ -54,7 +55,6 @@ Database Tables
| [term](help/database/db_term) | item taxonomy (categories, tags, etc.) table |
| [thread](help/database/db_thread) | |
| [tokens](help/database/db_tokens) | OAuth usage |
| [unique_contacts](help/database/db_unique_contacts) | |
| [user](help/database/db_user) | local user table |
| [userd](help/database/db_userd) | |
| [workerqueue](help/database/db_workerqueue) | |

View File

@ -18,9 +18,14 @@ Table gcontact
| about | | text | NO | | NULL | |
| keywords | puplic keywords (interests) | text | NO | | NULL | |
| gender | | varchar(32) | NO | | | |
| birthday | | varchar(32) | NO | | 0000-00-00 | |
| community | 1 if contact is forum account | tinyint(1) | NO | | 0 | |
| hide | 1 = should be hidden from search | tinyint(1) | NO | | 0 | |
| nsfw | 1 = contact posts nsfw content | tinyint(1) | NO | | 0 | |
| network | social network protocol | varchar(255) | NO | | | |
| addr | | varchar(255) | NO | | | |
| notify | | text | NO | | | |
| alias | | varchar(255) | NO | | | |
| generation | | tinyint(3) | NO | | 0 | |
| server_url | baseurl of the contacts server | varchar(255) | NO | | | |

View File

@ -1,12 +0,0 @@
Table guid
==========
| Field | Description | Type | Null | Key | Default | Extra |
|---------|------------------|------------------|------|-----|---------|----------------|
| id | sequential ID | int(10) unsigned | NO | PRI | NULL | auto_increment |
| guid | | varchar(255) | NO | MUL | | |
| plink | | varchar(255) | NO | MUL | | |
| uri | | varchar(255) | NO | MUL | | |
| network | | varchar(32) | NO | | | |
Return to [database documentation](help/database)

View File

@ -8,6 +8,7 @@ Table item
| uri | | varchar(255) | NO | MUL | | |
| uid | user.id which owns this copy of the item | int(10) unsigned | NO | MUL | 0 | |
| contact-id | contact.id | int(11) | NO | MUL | 0 | |
| gcontact-id | ID of the global contact | int(11) | NO | MUL | 0 | |
| type | | varchar(255) | NO | | | |
| wall | This item was posted to the wall of uid | tinyint(1) | NO | MUL | 0 | |
| gravity | | tinyint(1) | NO | | 0 | |

10
doc/database/db_oembed.md Normal file
View File

@ -0,0 +1,10 @@
Table oembed
============
| Field | Description | Type | Null | Key | Default | Extra |
| ------------ | ---------------------------------- | ------------ | ---- | --- | ------------------- | ----- |
| url | page url | varchar(255) | NO | PRI | NULL | |
| content | OEmbed data of the page | text | NO | | NULL | |
| created | datetime of creation | datetime | NO | MUL | 0000-00-00 00:00:00 | |
Return to [database documentation](help/database)

View File

@ -0,0 +1,12 @@
Table parsed_url
================
| Field | Description | Type | Null | Key | Default | Extra |
| ------------ | ---------------------------------- | ------------ | ---- | --- | ------------------- | ----- |
| url | page url | varchar(255) | NO | PRI | NULL | |
| guessing | is the "guessing" mode active? | tinyint(1) | NO | PRI | 0 | |
| oembed | is the data the result of oembed? | tinyint(1) | NO | PRI | 0 | |
| content | page data | text | NO | | NULL | |
| created | datetime of creation | datetime | NO | MUL | 0000-00-00 00:00:00 | |
Return to [database documentation](help/database)

View File

@ -1,30 +1,31 @@
Table thread
============
| Field | Description | Type | Null | Key | Default | Extra |
|------------|------------------|------------------|------|-----|---------------------|-------|
| iid | sequential ID | int(10) unsigned | NO | PRI | 0 | |
| uid | | int(10) unsigned | NO | MUL | 0 | |
| contact-id | | int(11) unsigned | NO | | 0 | |
| created | | datetime | NO | MUL | 0000-00-00 00:00:00 | |
| edited | | datetime | NO | | 0000-00-00 00:00:00 | |
| commented | | datetime | NO | MUL | 0000-00-00 00:00:00 | |
| received | | datetime | NO | | 0000-00-00 00:00:00 | |
| changed | | datetime | NO | | 0000-00-00 00:00:00 | |
| wall | | tinyint(1) | NO | MUL | 0 | |
| private | | tinyint(1) | NO | | 0 | |
| pubmail | | tinyint(1) | NO | | 0 | |
| moderated | | tinyint(1) | NO | | 0 | |
| visible | | tinyint(1) | NO | | 0 | |
| spam | | tinyint(1) | NO | | 0 | |
| starred | | tinyint(1) | NO | | 0 | |
| ignored | | tinyint(1) | NO | | 0 | |
| bookmark | | tinyint(1) | NO | | 0 | |
| unseen | | tinyint(1) | NO | | 1 | |
| deleted | | tinyint(1) | NO | | 0 | |
| origin | | tinyint(1) | NO | | 0 | |
| forum_mode | | tinyint(1) | NO | | 0 | |
| mention | | tinyint(1) | NO | | 0 | |
| network | | varchar(32) | NO | | | |
| Field | Description | Type | Null | Key | Default | Extra |
|-------------|------------------|------------------|------|-----|---------------------|-------|
| iid | sequential ID | int(10) unsigned | NO | PRI | 0 | |
| uid | | int(10) unsigned | NO | MUL | 0 | |
| contact-id | | int(11) unsigned | NO | | 0 | |
| gcontact-id | Global Contact | int(11) unsigned | NO | | 0 | |
| created | | datetime | NO | MUL | 0000-00-00 00:00:00 | |
| edited | | datetime | NO | | 0000-00-00 00:00:00 | |
| commented | | datetime | NO | MUL | 0000-00-00 00:00:00 | |
| received | | datetime | NO | | 0000-00-00 00:00:00 | |
| changed | | datetime | NO | | 0000-00-00 00:00:00 | |
| wall | | tinyint(1) | NO | MUL | 0 | |
| private | | tinyint(1) | NO | | 0 | |
| pubmail | | tinyint(1) | NO | | 0 | |
| moderated | | tinyint(1) | NO | | 0 | |
| visible | | tinyint(1) | NO | | 0 | |
| spam | | tinyint(1) | NO | | 0 | |
| starred | | tinyint(1) | NO | | 0 | |
| ignored | | tinyint(1) | NO | | 0 | |
| bookmark | | tinyint(1) | NO | | 0 | |
| unseen | | tinyint(1) | NO | | 1 | |
| deleted | | tinyint(1) | NO | | 0 | |
| origin | | tinyint(1) | NO | | 0 | |
| forum_mode | | tinyint(1) | NO | | 0 | |
| mention | | tinyint(1) | NO | | 0 | |
| network | | varchar(32) | NO | | | |
Return to [database documentation](help/database)

View File

@ -1,14 +0,0 @@
Table unique_contacts
=====================
| Field | Description | Type | Null | Key | Default | Extra |
|----------|------------------|--------------|------|-----|---------|----------------|
| id | sequential ID | int(11) | NO | PRI | NULL | auto_increment |
| url | | varchar(255) | NO | MUL | | |
| nick | | varchar(255) | NO | | | |
| name | | varchar(255) | NO | | | |
| avatar | | varchar(255) | NO | | | |
| location | | varchar(255) | NO | | | |
| about | | text | NO | | NULL | |
Return to [database documentation](help/database)

View File

@ -1,27 +1,28 @@
**Friendica Addon/Plugin-Entwicklung**
Friendica Addon/Plugin-Entwicklung
==============
* [Zur Startseite der Hilfe](help)
Bitte schau dir das Beispiel-Addon "randplace" für ein funktionierendes Beispiel für manche der hier aufgeführten Funktionen an.
Das Facebook-Addon bietet ein Beispiel dafür, die "addon"- und "module"-Funktion gemeinsam zu integrieren.
Addons arbeiten, indem sie Event Hooks abfangen. Module arbeiten, indem bestimmte Seitenanfragen (durch den URL-Pfad) abgefangen werden
Bitte schau dir das Beispiel-Addon "randplace" für ein funktionierendes Beispiel für manche der hier aufgeführten Funktionen an.
Das Facebook-Addon bietet ein Beispiel dafür, die "addon"- und "module"-Funktion gemeinsam zu integrieren.
Addons arbeiten, indem sie Event Hooks abfangen.
Module arbeiten, indem bestimmte Seitenanfragen (durch den URL-Pfad) abgefangen werden.
Plugin-Namen können keine Leerstellen oder andere Interpunktionen enthalten und werden als Datei- und Funktionsnamen genutzt.
Du kannst einen lesbaren Namen im Kommentarblock eintragen.
Jedes Addon muss beides beinhalten - eine Installations- und eine Deinstallationsfunktion, die auf dem Addon-/Plugin-Namen basieren; z.B. "plugin1name_install()".
Diese beiden Funktionen haben keine Argumente und sind dafür verantwortlich, Event Hooks zu registrieren und abzumelden (unregistering), die dein Plugin benötigt.
Die Installations- und Deinstallationsfunktionfunktionen werden auch ausgeführt (z.B. neu installiert), wenn sich das Plugin nach der Installation ändert - somit sollte deine Deinstallationsfunktion keine Daten zerstört und deine Installationsfunktion sollte bestehende Daten berücksichtigen.
Plugin-Namen können keine Leerstellen oder andere Interpunktionen enthalten und werden als Datei- und Funktionsnamen genutzt.
Du kannst einen lesbaren Namen im Kommentarblock eintragen.
Jedes Addon muss beides beinhalten - eine Installations- und eine Deinstallationsfunktion, die auf dem Addon-/Plugin-Namen basieren; z.B. "plugin1name_install()".
Diese beiden Funktionen haben keine Argumente und sind dafür verantwortlich, Event Hooks zu registrieren und abzumelden (unregistering), die dein Plugin benötigt.
Die Installations- und Deinstallationsfunktionfunktionen werden auch ausgeführt (z.B. neu installiert), wenn sich das Plugin nach der Installation ändert - somit sollte deine Deinstallationsfunktion keine Daten zerstört und deine Installationsfunktion sollte bestehende Daten berücksichtigen.
Zukünftige Extensions werden möglicherweise "Setup" und "Entfernen" anbieten.
Plugins sollten einen Kommentarblock mit den folgenden vier Parametern enthalten:
/*
* Name: My Great Plugin
* Description: This is what my plugin does. It's really cool
* Version: 1.0
* Author: John Q. Public <john@myfriendicasite.com>
*/
/*
* Name: My Great Plugin
* Description: This is what my plugin does. It's really cool.
* Version: 1.0
* Author: John Q. Public <john@myfriendicasite.com>
*/
Registriere deine Plugin-Hooks während der Installation.
@ -29,45 +30,50 @@ Registriere deine Plugin-Hooks während der Installation.
$hookname ist ein String und entspricht einem bekannten Friendica-Hook.
$file steht für den Pfadnamen, der relativ zum Top-Level-Friendicaverzeichnis liegt.
$file steht für den Pfadnamen, der relativ zum Top-Level-Friendicaverzeichnis liegt.
Das *sollte* "addon/plugin_name/plugin_name.php' sein.
$function ist ein String und der Name der Funktion, die ausgeführt wird, wenn der Hook aufgerufen wird.
Argumente
---
Deine Hook-Callback-Funktion wird mit mindestens einem und bis zu zwei Argumenten aufgerufen
function myhook_function(&$a, &$b) {
}
Wenn du Änderungen an den aufgerufenen Daten vornehmen willst, musst du diese als Referenzvariable (mit "&") während der Funktionsdeklaration deklarieren.
Wenn du Änderungen an den aufgerufenen Daten vornehmen willst, musst du diese als Referenzvariable (mit "&") während der Funktionsdeklaration deklarieren.
$a ist die Friendica "App"-Klasse, die eine Menge an Informationen über den aktuellen Friendica-Status beinhaltet, u.a. welche Module genutzt werden, Konfigurationsinformationen, Inhalte der Seite zum Zeitpunkt des Hook-Aufrufs.
Es ist empfohlen, diese Funktion "$a" zu nennen, um seine Nutzung an den Gebrauch an anderer Stelle anzugleichen.
$a ist die Friendica "App"-Klasse, die eine Menge an Informationen über den aktuellen Friendica-Status beinhaltet, u.a. welche Module genutzt werden, Konfigurationsinformationen, Inhalte der Seite zum Zeitpunkt des Hook-Aufrufs.
Es ist empfohlen, diese Funktion "$a" zu nennen, um seine Nutzung an den Gebrauch an anderer Stelle anzugleichen.
$b kann frei benannt werden.
Diese Information ist speziell auf den Hook bezogen, der aktuell bearbeitet wird, und beinhaltet normalerweise Daten, die du sofort nutzen, anzeigen oder bearbeiten kannst.
Achte darauf, diese mit "&" zu deklarieren, wenn du sie bearbeiten willst.
$b kann frei benannt werden.
Diese Information ist speziell auf den Hook bezogen, der aktuell bearbeitet wird, und beinhaltet normalerweise Daten, die du sofort nutzen, anzeigen oder bearbeiten kannst.
Achte darauf, diese mit "&" zu deklarieren, wenn du sie bearbeiten willst.
**Module**
Module
---
Plugins/Addons können auch als "Module" agieren und alle Seitenanfragen für eine bestimte URL abfangen.
Um ein Plugin als Modul zu nutzen, ist es nötig, die Funktion "plugin_name_module()" zu definieren, die keine Argumente benötigt und nichts weiter machen muss.
Plugins/Addons können auch als "Module" agieren und alle Seitenanfragen für eine bestimte URL abfangen.
Um ein Plugin als Modul zu nutzen, ist es nötig, die Funktion "plugin_name_module()" zu definieren, die keine Argumente benötigt und nichts weiter machen muss.
Wenn diese Funktion existiert, wirst du nun alle Seitenanfragen für "http://my.web.site/plugin_name" erhalten - mit allen URL-Komponenten als zusätzliche Argumente.
Diese werden in ein Array $a->argv geparst und stimmen mit $a->argc überein, wobei sie die Anzahl der URL-Komponenten abbilden.
So würde http://my.web.site/plugin/arg1/arg2 nach einem Modul "plugin" suchen und seiner Modulfunktion die $a-App-Strukur übergeben (dies ist für viele Komponenten verfügbar). Das umfasst:
Wenn diese Funktion existiert, wirst du nun alle Seitenanfragen für "http://example.com/plugin_name" erhalten - mit allen URL-Komponenten als zusätzliche Argumente.
Diese werden in ein Array $a->argv geparst und stimmen mit $a->argc überein, wobei sie die Anzahl der URL-Komponenten abbilden.
So würde http://example.com/plugin/arg1/arg2 nach einem Modul "plugin" suchen und seiner Modulfunktion die $a-App-Strukur übergeben (dies ist für viele Komponenten verfügbar). Das umfasst:
$a->argc = 3
$a->argv = array(0 => 'plugin', 1 => 'arg1', 2 => 'arg2');
$a->argc = 3
$a->argv = array(0 => 'plugin', 1 => 'arg1', 2 => 'arg2');
Deine Modulfunktionen umfassen oft die Funktion plugin_name_content(&$a), welche den Seiteninhalt definiert und zurückgibt.
Sie können auch plugin_name_post(&$a) umfassen, welches vor der content-Funktion aufgerufen wird und normalerweise die Resultate der POST-Formulare handhabt.
Deine Modulfunktionen umfassen oft die Funktion plugin_name_content(&$a), welche den Seiteninhalt definiert und zurückgibt.
Sie können auch plugin_name_post(&$a) umfassen, welches vor der content-Funktion aufgerufen wird und normalerweise die Resultate der POST-Formulare handhabt.
Du kannst ebenso plugin_name_init(&$a) nutzen, was oft frühzeitig aufgerufen wird und das Modul initialisert.
**Derzeitige Hooks:**
Derzeitige Hooks
---
**'authenticate'** - wird aufgerufen, wenn sich der User einloggt.
$b ist ein Array
@ -180,6 +186,9 @@ Du kannst ebenso plugin_name_init(&$a) nutzen, was oft frühzeitig aufgerufen wi
- wird aufgerufen nachdem in include/nav,php der Inhalt des Navigations Menüs erzeugt wurde.
- $b ist ein Array, das $nav wiederspiegelt.
Komplette Liste der Hook-Callbacks
---
Eine komplette Liste aller Hook-Callbacks mit den zugehörigen Dateien (am 14-Feb-2012 generiert): Bitte schau in die Quellcodes für Details zu Hooks, die oben nicht dokumentiert sind.
boot.php: call_hooks('login_hook',$o);
@ -204,7 +213,7 @@ include/text.php: call_hooks('contact_block_end', $arr);
include/text.php: call_hooks('smilie', $s);
include/text.php: call_hooks('prepare_body_init', $item);
include/text.php: call_hooks('prepare_body_init', $item);
include/text.php: call_hooks('prepare_body', $prep_arr);
@ -359,4 +368,3 @@ mod/cb.php: call_hooks('cb_afterpost');
mod/cb.php: call_hooks('cb_content', $o);
mod/directory.php: call_hooks('directory_item', $arr);

View File

@ -34,6 +34,7 @@ line to your .htconfig.php:
* like_no_comment (Boolean) - Don't update the "commented" value of an item when it is liked.
* local_block (Boolean) - Used in conjunction with "block_public".
* local_search (Boolean) - Blocks the search for not logged in users to prevent crawlers from blocking your system.
* max_connections - The poller process isn't started when 3/4 of the possible database connections are used. When the system can't detect the maximum numbers of connection then this value can be used.
* max_contact_queue - Default value is 500.
* max_batch_queue - Default value is 1000.
* no_oembed (Boolean) - Don't use OEmbed to fetch more information about a link.

View File

@ -4,42 +4,32 @@ Friendica translations
Translation Process
-------------------
The strings used in the UI of Friendica is translated at [Transifex] [1] and then
included in the git repository at github. If you want to help with translation
for any language, be it correcting terms or translating friendica to a
currently not supported language, please register an account at transifex.com
and contact the friendica translation team there.
The strings used in the UI of Friendica is translated at [Transifex] [1] and then included in the git repository at github.
If you want to help with translation for any language, be it correcting terms or translating friendica to a currently not supported language, please register an account at transifex.com and contact the friendica translation team there.
Translating friendica is simple. Just use the online tool at transifex. If you
don't want to deal with git & co. that is fine, we check the status of the
translations regularly and import them into the source tree at github so that
others can use them.
Translating friendica is simple.
Just use the online tool at transifex.
If you don't want to deal with git & co. that is fine, we check the status of the translations regularly and import them into the source tree at github so that others can use them.
We do not include every translation from transifex in the source tree to avoid
a scattered and disturbed overall experience. As an uneducated guess we have a
lower limit of 50% translated strings before we include the language (for the
core message.po file, addont translation will be included once all strings of
an addon are translated. This limit is judging only by the amount of translated
strings under the assumption that the most prominent strings for the UI will be
translated first by a translation team. If you feel your translation useable
before this limit, please contact us and we will probably include your teams
work in the source tree.
We do not include every translation from transifex in the source tree to avoid a scattered and disturbed overall experience.
As an uneducated guess we have a lower limit of 50% translated strings before we include the language (for the core messages.po file, addont translation will be included once all strings of an addon are translated.
This limit is judging only by the amount of translated strings under the assumption that the most prominent strings for the UI will be translated first by a translation team.
If you feel your translation useable before this limit, please contact us and we will probably include your teams work in the source tree.
If you want to get your work into the source tree yourself, feel free to do so
and contact us with and question that arises. The process is simple and
friendica ships with all the tools necessary.
If you want to help translating, please concentrate on the core messages.po file first.
We will only include translations with a sufficient translated messages.po file.
Translations of addons will only be included, when the core file is included as well.
If you want to get your work into the source tree yourself, feel free to do so and contact us with and question that arises.
The process is simple and friendica ships with all the tools necessary.
The location of the translated files in the source tree is
/view/LNG-CODE/
where LNG-CODE is the language code used, e.g. de for German or fr for French.
For the email templates (the *.tpl files) just place them into the directory
and you are done. The translated strings come as a "message.po" file from
transifex which needs to be translated into the PHP file friendica uses. To do
so, place the file in the directory mentioned above and use the "po2php"
utility from the util directory of your friendica installation.
The translated strings come as a "message.po" file from transifex which needs to be translated into the PHP file friendica uses.
To do so, place the file in the directory mentioned above and use the "po2php" utility from the util directory of your friendica installation.
Assuming you want to convert the German localization which is placed in
view/de/message.po you would do the following.
Assuming you want to convert the German localization which is placed in view/de/message.po you would do the following.
1. Navigate at the command prompt to the base directory of your
friendica installation
@ -47,15 +37,15 @@ view/de/message.po you would do the following.
2. Execute the po2php script, which will place the translation
in the strings.php file that is used by friendica.
$> php util/po2php.php view/de/message.po
$> php util/po2php.php view/de/messages.po
The output of the script will be placed at view/de/strings.php where
froemdoca os expecting it, so you can test your translation mmediately.
friendica is expecting it, so you can test your translation immediately.
3. Visit your friendica page to check if it still works in the language you
just translated. If not try to find the error, most likely PHP will give
you a hint in the log/warnings.about the error.
For debugging you can also try to "run" the file with PHP. This should
not give any output if the file is ok but might give a hint for
searching the bug in the file.
@ -69,27 +59,10 @@ view/de/message.po you would do the following.
Utilities
---------
Additional to the po2php script there are some more utilities for translation
in the "util" directory of the friendica source tree. If you only want to
translate friendica into another language you wont need any of these tools most
likely but it gives you an idea how the translation process of friendica
works.
Additional to the po2php script there are some more utilities for translation in the "util" directory of the friendica source tree.
If you only want to translate friendica into another language you wont need any of these tools most likely but it gives you an idea how the translation process of friendica works.
For further information see the utils/README file.
Known Problems
--------------
Friendica uses the language setting of the visitors browser to determain the
language for the UI. Most of the time this works, but there are some known
quirks.
One is that some browsers, like Safari, do the setting to "de-de" but friendica
only has a "de" localisation. A workaround would be to add a symbolic link
from
$friendica/view/de-de
pointing to
$friendica/view/de
[1]: https://www.transifex.com/projects/p/friendica/

View File

@ -1657,35 +1657,6 @@ LOCK TABLES `tokens` WRITE;
/*!40000 ALTER TABLE `tokens` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `unique_contacts`
--
DROP TABLE IF EXISTS `unique_contacts`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `unique_contacts` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`url` varchar(255) NOT NULL DEFAULT '',
`nick` varchar(255) NOT NULL DEFAULT '',
`name` varchar(255) NOT NULL DEFAULT '',
`avatar` varchar(255) NOT NULL DEFAULT '',
`location` varchar(255) NOT NULL DEFAULT '',
`about` text NOT NULL,
PRIMARY KEY (`id`),
KEY `url` (`url`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `unique_contacts`
--
LOCK TABLES `unique_contacts` WRITE;
/*!40000 ALTER TABLE `unique_contacts` DISABLE KEYS */;
/*!40000 ALTER TABLE `unique_contacts` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `user`
--

View File

@ -57,7 +57,7 @@ $a->config['system']['huburl'] = '[internal]';
// allowed themes (change this from admin panel after installation)
$a->config['system']['allowed_themes'] = 'dispy,quattro,vier,darkzero,duepuntozero,greenzero,purplezero,slackr,diabook';
$a->config['system']['allowed_themes'] = 'quattro,vier,duepuntozero';
// default system theme

View File

@ -132,8 +132,8 @@ function terminate_friendship($user,$self,$contact) {
diaspora_unshare($user,$contact);
}
elseif($contact['network'] === NETWORK_DFRN) {
require_once('include/items.php');
dfrn_deliver($user,$contact,'placeholder', 1);
require_once('include/dfrn.php');
dfrn::deliver($user,$contact,'placeholder', 1);
}
}
@ -205,60 +205,49 @@ function get_contact_details_by_url($url, $uid = -1) {
if ((($profile["addr"] == "") OR ($profile["name"] == "")) AND
in_array($profile["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS)))
proc_run('php',"include/update_gcontact.php", $profile["gid"]);
} else {
$r = q("SELECT `url`, `name`, `nick`, `avatar` AS `photo`, `location`, `about` FROM `unique_contacts` WHERE `url` = '%s'",
dbesc(normalise_link($url)));
if (count($r)) {
$profile = $r[0];
$profile["keywords"] = "";
$profile["gender"] = "";
$profile["community"] = false;
$profile["network"] = "";
$profile["addr"] = "";
}
}
// Fetching further contact data from the contact table
$r = q("SELECT `id`, `uid`, `url`, `network`, `name`, `nick`, `addr`, `location`, `about`, `keywords`, `gender`, `photo`, `addr`, `forum`, `prv`, `bd` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `network` = '%s'",
$r = q("SELECT `id`, `uid`, `url`, `network`, `name`, `nick`, `addr`, `location`, `about`, `keywords`, `gender`, `photo`, `thumb`, `addr`, `forum`, `prv`, `bd`, `self` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `network` IN ('%s', '')",
dbesc(normalise_link($url)), intval($uid), dbesc($profile["network"]));
if (!count($r))
$r = q("SELECT `id`, `uid`, `url`, `network`, `name`, `nick`, `addr`, `location`, `about`, `keywords`, `gender`, `photo`, `addr`, `forum`, `prv`, `bd` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d",
if (!count($r) AND !isset($profile))
$r = q("SELECT `id`, `uid`, `url`, `network`, `name`, `nick`, `addr`, `location`, `about`, `keywords`, `gender`, `photo`, `thumb`, `addr`, `forum`, `prv`, `bd`, `self` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d",
dbesc(normalise_link($url)), intval($uid));
if (!count($r))
$r = q("SELECT `id`, `uid`, `url`, `network`, `name`, `nick`, `addr`, `location`, `about`, `keywords`, `gender`, `photo`, `addr`, `forum`, `prv`, `bd` FROM `contact` WHERE `nurl` = '%s' AND `uid` = 0",
if (!count($r) AND !isset($profile))
$r = q("SELECT `id`, `uid`, `url`, `network`, `name`, `nick`, `addr`, `location`, `about`, `keywords`, `gender`, `photo`, `thumb`, `addr`, `forum`, `prv`, `bd` FROM `contact` WHERE `nurl` = '%s' AND `uid` = 0",
dbesc(normalise_link($url)));
if ($r) {
if (isset($r[0]["url"]) AND $r[0]["url"])
if (!isset($profile["url"]) AND $r[0]["url"])
$profile["url"] = $r[0]["url"];
if (isset($r[0]["name"]) AND $r[0]["name"])
if (!isset($profile["name"]) AND $r[0]["name"])
$profile["name"] = $r[0]["name"];
if (isset($r[0]["nick"]) AND $r[0]["nick"] AND ($profile["nick"] == ""))
if (!isset($profile["nick"]) AND $r[0]["nick"])
$profile["nick"] = $r[0]["nick"];
if (isset($r[0]["addr"]) AND $r[0]["addr"] AND ($profile["addr"] == ""))
if (!isset($profile["addr"]) AND $r[0]["addr"])
$profile["addr"] = $r[0]["addr"];
if (isset($r[0]["photo"]) AND $r[0]["photo"])
if ((!isset($profile["photo"]) OR $r[0]["self"]) AND $r[0]["photo"])
$profile["photo"] = $r[0]["photo"];
if (isset($r[0]["location"]) AND $r[0]["location"])
if (!isset($profile["location"]) AND $r[0]["location"])
$profile["location"] = $r[0]["location"];
if (isset($r[0]["about"]) AND $r[0]["about"])
if (!isset($profile["about"]) AND $r[0]["about"])
$profile["about"] = $r[0]["about"];
if (isset($r[0]["keywords"]) AND $r[0]["keywords"])
if (!isset($profile["keywords"]) AND $r[0]["keywords"])
$profile["keywords"] = $r[0]["keywords"];
if (isset($r[0]["gender"]) AND $r[0]["gender"])
if (!isset($profile["gender"]) AND $r[0]["gender"])
$profile["gender"] = $r[0]["gender"];
if (isset($r[0]["forum"]) OR isset($r[0]["prv"]))
$profile["community"] = ($r[0]["forum"] OR $r[0]["prv"]);
if (isset($r[0]["network"]) AND $r[0]["network"])
if (!isset($profile["network"]) AND $r[0]["network"])
$profile["network"] = $r[0]["network"];
if (isset($r[0]["addr"]) AND $r[0]["addr"])
if (!isset($profile["addr"]) AND $r[0]["addr"])
$profile["addr"] = $r[0]["addr"];
if (isset($r[0]["bd"]) AND $r[0]["bd"])
if (!isset($profile["bd"]) AND $r[0]["bd"])
$profile["bd"] = $r[0]["bd"];
if (isset($r[0]["thumb"]))
$profile["thumb"] = $r[0]["thumb"];
if ($r[0]["uid"] == 0)
$profile["cid"] = 0;
else
@ -415,6 +404,7 @@ function get_contact($url, $uid = 0) {
$contactid = 0;
// is it an address in the format user@server.tld?
/// @todo use gcontact and/or the addr field for a lookup
if (!strstr($url, "http") OR strstr($url, "@")) {
$data = probe_url($url);
$url = $data["url"];
@ -422,12 +412,12 @@ function get_contact($url, $uid = 0) {
return 0;
}
$contact = q("SELECT `id`, `avatar-date` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d",
$contact = q("SELECT `id`, `avatar-date` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d ORDER BY `id` LIMIT 2",
dbesc(normalise_link($url)),
intval($uid));
if (!$contact)
$contact = q("SELECT `id`, `avatar-date` FROM `contact` WHERE `alias` IN ('%s', '%s') AND `uid` = %d",
$contact = q("SELECT `id`, `avatar-date` FROM `contact` WHERE `alias` IN ('%s', '%s') AND `uid` = %d ORDER BY `id` LIMIT 1",
dbesc($url),
dbesc(normalise_link($url)),
intval($uid));
@ -451,9 +441,7 @@ function get_contact($url, $uid = 0) {
if (!in_array($data["network"], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA)))
return 0;
// tempory programming. Can be deleted after 2015-02-07
if (($data["alias"] == "") AND (normalise_link($data["url"]) != normalise_link($url)))
$data["alias"] = normalise_link($url);
$url = $data["url"];
if ($contactid == 0) {
q("INSERT INTO `contact` (`uid`, `created`, `url`, `nurl`, `addr`, `alias`, `notify`, `poll`,
@ -482,7 +470,7 @@ function get_contact($url, $uid = 0) {
dbesc($data["poco"])
);
$contact = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d",
$contact = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d ORDER BY `id` LIMIT 2",
dbesc(normalise_link($data["url"])),
intval($uid));
if (!$contact)
@ -491,25 +479,217 @@ function get_contact($url, $uid = 0) {
$contactid = $contact[0]["id"];
}
if ((count($contact) > 1) AND ($uid == 0) AND ($contactid != 0) AND ($url != ""))
q("DELETE FROM `contact` WHERE `nurl` = '%s' AND `id` != %d",
dbesc(normalise_link($url)),
intval($contactid));
require_once("Photo.php");
$photos = import_profile_photo($data["photo"],$uid,$contactid);
update_contact_avatar($data["photo"],$uid,$contactid);
q("UPDATE `contact` SET `photo` = '%s', `thumb` = '%s', `micro` = '%s',
`addr` = '%s', `alias` = '%s', `name` = '%s', `nick` = '%s',
`name-date` = '%s', `uri-date` = '%s', `avatar-date` = '%s' WHERE `id` = %d",
dbesc($photos[0]),
dbesc($photos[1]),
dbesc($photos[2]),
q("UPDATE `contact` SET `addr` = '%s', `alias` = '%s', `name` = '%s', `nick` = '%s',
`name-date` = '%s', `uri-date` = '%s' WHERE `id` = %d",
dbesc($data["addr"]),
dbesc($data["alias"]),
dbesc($data["name"]),
dbesc($data["nick"]),
dbesc(datetime_convert()),
dbesc(datetime_convert()),
dbesc(datetime_convert()),
intval($contactid)
);
return $contactid;
}
/**
* @brief Returns posts from a given gcontact
*
* @param App $a argv application class
* @param int $gcontact_id Global contact
*
* @return string posts in HTML
*/
function posts_from_gcontact($a, $gcontact_id) {
require_once('include/conversation.php');
// There are no posts with "uid = 0" with connector networks
// This speeds up the query a lot
$r = q("SELECT `network` FROM `gcontact` WHERE `id` = %d", dbesc($gcontact_id));
if (in_array($r[0]["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS, "")))
$sql = "(`item`.`uid` = 0 OR (`item`.`uid` = %d AND `item`.`private`))";
else
$sql = "`item`.`uid` = %d";
if(get_config('system', 'old_pager')) {
$r = q("SELECT COUNT(*) AS `total` FROM `item`
WHERE `gcontact-id` = %d and $sql",
intval($gcontact_id),
intval(local_user()));
$a->set_pager_total($r[0]['total']);
}
$r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`,
`author-name` AS `name`, `owner-avatar` AS `photo`,
`owner-link` AS `url`, `owner-avatar` AS `thumb`
FROM `item` FORCE INDEX (`gcontactid_uid_created`)
WHERE `gcontact-id` = %d AND $sql AND
NOT `deleted` AND NOT `moderated` AND `visible`
ORDER BY `item`.`created` DESC LIMIT %d, %d",
intval($gcontact_id),
intval(local_user()),
intval($a->pager['start']),
intval($a->pager['itemspage'])
);
$o = conversation($a,$r,'community',false);
if(!get_config('system', 'old_pager')) {
$o .= alt_pager($a,count($r));
} else {
$o .= paginate($a);
}
return $o;
}
/**
* @brief set the gcontact-id in all item entries
*
* This job has to be started multiple times until all entries are set.
* It isn't started in the update function since it would consume too much time and can be done in the background.
*/
function item_set_gcontact() {
define ('POST_UPDATE_VERSION', 1192);
// Was the script completed?
if (get_config("system", "post_update_version") >= POST_UPDATE_VERSION)
return;
// Check if the first step is done (Setting "gcontact-id" in the item table)
$r = q("SELECT `author-link`, `author-name`, `author-avatar`, `uid`, `network` FROM `item` WHERE `gcontact-id` = 0 LIMIT 1000");
if (!$r) {
// Are there unfinished entries in the thread table?
$r = q("SELECT COUNT(*) AS `total` FROM `thread`
INNER JOIN `item` ON `item`.`id` =`thread`.`iid`
WHERE `thread`.`gcontact-id` = 0 AND
(`thread`.`uid` IN (SELECT `uid` from `user`) OR `thread`.`uid` = 0)");
if ($r AND ($r[0]["total"] == 0)) {
set_config("system", "post_update_version", POST_UPDATE_VERSION);
return false;
}
// Update the thread table from the item table
q("UPDATE `thread` INNER JOIN `item` ON `item`.`id`=`thread`.`iid`
SET `thread`.`gcontact-id` = `item`.`gcontact-id`
WHERE `thread`.`gcontact-id` = 0 AND
(`thread`.`uid` IN (SELECT `uid` from `user`) OR `thread`.`uid` = 0)");
return false;
}
$item_arr = array();
foreach ($r AS $item) {
$index = $item["author-link"]."-".$item["uid"];
$item_arr[$index] = array("author-link" => $item["author-link"],
"uid" => $item["uid"],
"network" => $item["network"]);
}
// Set the "gcontact-id" in the item table and add a new gcontact entry if needed
foreach($item_arr AS $item) {
$gcontact_id = get_gcontact_id(array("url" => $item['author-link'], "network" => $item['network'],
"photo" => $item['author-avatar'], "name" => $item['author-name']));
q("UPDATE `item` SET `gcontact-id` = %d WHERE `uid` = %d AND `author-link` = '%s' AND `gcontact-id` = 0",
intval($gcontact_id), intval($item["uid"]), dbesc($item["author-link"]));
}
return true;
}
/**
* @brief Returns posts from a given contact
*
* @param App $a argv application class
* @param int $contact_id contact
*
* @return string posts in HTML
*/
function posts_from_contact($a, $contact_id) {
require_once('include/conversation.php');
$r = q("SELECT `url` FROM `contact` WHERE `id` = %d", intval($contact_id));
if (!$r)
return false;
$contact = $r[0];
if(get_config('system', 'old_pager')) {
$r = q("SELECT COUNT(*) AS `total` FROM `item`
WHERE `item`.`uid` = %d AND `author-link` IN ('%s', '%s')",
intval(local_user()),
dbesc(str_replace("https://", "http://", $contact["url"])),
dbesc(str_replace("http://", "https://", $contact["url"])));
$a->set_pager_total($r[0]['total']);
}
$r = q("SELECT `item`.`uri`, `item`.*, `item`.`id` AS `item_id`,
`author-name` AS `name`, `owner-avatar` AS `photo`,
`owner-link` AS `url`, `owner-avatar` AS `thumb`
FROM `item` FORCE INDEX (`uid_contactid_created`)
WHERE `item`.`uid` = %d AND `contact-id` = %d
AND `author-link` IN ('%s', '%s')
AND NOT `deleted` AND NOT `moderated` AND `visible`
ORDER BY `item`.`created` DESC LIMIT %d, %d",
intval(local_user()),
intval($contact_id),
dbesc(str_replace("https://", "http://", $contact["url"])),
dbesc(str_replace("http://", "https://", $contact["url"])),
intval($a->pager['start']),
intval($a->pager['itemspage'])
);
$o .= conversation($a,$r,'community',false);
if(!get_config('system', 'old_pager'))
$o .= alt_pager($a,count($r));
else
$o .= paginate($a);
return $o;
}
/**
* @brief Returns a formatted location string from the given profile array
*
* @param array $profile Profile array (Generated from the "profile" table)
*
* @return string Location string
*/
function formatted_location($profile) {
$location = '';
if($profile['locality'])
$location .= $profile['locality'];
if($profile['region'] AND ($profile['locality'] != $profile['region'])) {
if($location)
$location .= ', ';
$location .= $profile['region'];
}
if($profile['country-name']) {
if($location)
$location .= ', ';
$location .= $profile['country-name'];
}
return $location;
}
?>

190
include/ForumManager.php Normal file
View File

@ -0,0 +1,190 @@
<?php
/**
* @file include/forum.php
* @brief Functions related to forum functionality *
*/
/**
* @brief This class handles functions related to the forum functionality
*/
class ForumManager {
/**
* @brief Function to list all forums a user is connected with
*
* @param int $uid of the profile owner
* @param boolean $showhidden
* Show frorums which are not hidden
* @param boolean $lastitem
* Sort by lastitem
* @param boolean $showprivate
* Show private groups
*
* @returns array
* 'url' => forum url
* 'name' => forum name
* 'id' => number of the key from the array
* 'micro' => contact photo in format micro
*/
public static function get_list($uid, $showhidden = true, $lastitem, $showprivate = false) {
$forumlist = array();
$order = (($showhidden) ? '' : ' AND NOT `hidden` ');
$order .= (($lastitem) ? ' ORDER BY `last-item` DESC ' : ' ORDER BY `name` ASC ');
$select = '`forum` ';
if ($showprivate) {
$select = '(`forum` OR `prv`)';
}
$contacts = q("SELECT `contact`.`id`, `contact`.`url`, `contact`.`name`, `contact`.`micro` FROM `contact`
WHERE `network`= 'dfrn' AND $select AND `uid` = %d
AND NOT `blocked` AND NOT `hidden` AND NOT `pending` AND NOT `archive`
AND `success_update` > `failure_update`
$order ",
intval($uid)
);
if (!$contacts)
return($forumlist);
foreach($contacts as $contact) {
$forumlist[] = array(
'url' => $contact['url'],
'name' => $contact['name'],
'id' => $contact['id'],
'micro' => $contact['micro'],
);
}
return($forumlist);
}
/**
* @brief Forumlist widget
*
* Sidebar widget to show subcribed friendica forums. If activated
* in the settings, it appears at the notwork page sidebar
*
* @param int $uid The ID of the User
* @param int $cid
* The contact id which is used to mark a forum as "selected"
* @return string
*/
public static function widget($uid,$cid = 0) {
if(! intval(feature_enabled(local_user(),'forumlist_widget')))
return;
$o = '';
//sort by last updated item
$lastitem = true;
$contacts = self::get_list($uid,true,$lastitem, true);
$total = count($contacts);
$visible_forums = 10;
if(count($contacts)) {
$id = 0;
foreach($contacts as $contact) {
$selected = (($cid == $contact['id']) ? ' forum-selected' : '');
$entry = array(
'url' => z_root() . '/network?f=&cid=' . $contact['id'],
'external_url' => z_root() . '/redir/' . $contact['id'],
'name' => $contact['name'],
'cid' => $contact['id'],
'selected' => $selected,
'micro' => proxy_url($contact['micro'], false, PROXY_SIZE_MICRO),
'id' => ++$id,
);
$entries[] = $entry;
}
$tpl = get_markup_template('widget_forumlist.tpl');
$o .= replace_macros($tpl,array(
'$title' => t('Forums'),
'$forums' => $entries,
'$link_desc' => t('External link to forum'),
'$total' => $total,
'$visible_forums' => $visible_forums,
'$showmore' => t('show more'),
));
}
return $o;
}
/**
* @brief Format forumlist as contact block
*
* This function is used to show the forumlist in
* the advanced profile.
*
* @param int $uid The ID of the User
* @return string
*
*/
public static function profile_advanced($uid) {
$profile = intval(feature_enabled($uid,'forumlist_profile'));
if(! $profile)
return;
$o = '';
// place holder in case somebody wants configurability
$show_total = 9999;
//don't sort by last updated item
$lastitem = false;
$contacts = self::get_list($uid,false,$lastitem,false);
$total_shown = 0;
foreach($contacts as $contact) {
$forumlist .= micropro($contact,false,'forumlist-profile-advanced');
$total_shown ++;
if($total_shown == $show_total)
break;
}
if(count($contacts) > 0)
$o .= $forumlist;
return $o;
}
/**
* @brief count unread forum items
*
* Count unread items of connected forums and private groups
*
* @return array
* 'id' => contact id
* 'name' => contact/forum name
* 'count' => counted unseen forum items
*
*/
public static function count_unseen_items() {
$r = q("SELECT `contact`.`id`, `contact`.`name`, COUNT(*) AS `count` FROM `item`
INNER JOIN `contact` ON `item`.`contact-id` = `contact`.`id`
WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted` AND `item`.`unseen`
AND `contact`.`network`= 'dfrn' AND (`contact`.`forum` OR `contact`.`prv`)
AND NOT `contact`.`blocked` AND NOT `contact`.`hidden`
AND NOT `contact`.`pending` AND NOT `contact`.`archive`
AND `contact`.`success_update` > `failure_update`
GROUP BY `contact`.`id` ",
intval(local_user())
);
return $r;
}
}

View File

@ -0,0 +1,136 @@
<?php
/**
* @file include/NotificationsManager.php
*/
require_once('include/html2plain.php');
require_once("include/datetime.php");
require_once("include/bbcode.php");
/**
* @brief Read and write notifications from/to database
*/
class NotificationsManager {
private $a;
public function __construct() {
$this->a = get_app();
}
/**
* @brief set some extra note properties
*
* @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
* - msg_html: message as html string
* - msg_plain: message as plain text string
*/
private function _set_extra($notes) {
$rets = array();
foreach($notes as $n) {
$local_time = datetime_convert('UTC',date_default_timezone_get(),$n['date']);
$n['timestamp'] = strtotime($local_time);
$n['date_rel'] = relative_date($n['date']);
$n['msg_html'] = bbcode($n['msg'], false, false, false, false);
$n['msg_plain'] = explode("\n",trim(html2plain($n['msg_html'], 0)))[0];
$rets[] = $n;
}
return $rets;
}
/**
* @brief get all notifications for local_user()
*
* @param array $filter optional Array "column name"=>value: filter query by columns values
* @param string $order optional Space separated list of column to sort by. prepend name with "+" to sort ASC, "-" to sort DESC. Default to "-date"
* @param string $limit optional Query limits
*
* @return array of results or false on errors
*/
public function getAll($filter = array(), $order="-date", $limit="") {
$filter_str = array();
$filter_sql = "";
foreach($filter as $column => $value) {
$filter_str[] = sprintf("`%s` = '%s'", $column, dbesc($value));
}
if (count($filter_str)>0) {
$filter_sql = "AND ".implode(" AND ", $filter_str);
}
$aOrder = explode(" ", $order);
$asOrder = array();
foreach($aOrder as $o) {
$dir = "asc";
if ($o[0]==="-") {
$dir = "desc";
$o = substr($o,1);
}
if ($o[0]==="+") {
$dir = "asc";
$o = substr($o,1);
}
$asOrder[] = "$o $dir";
}
$order_sql = implode(", ", $asOrder);
if ($limit!="") $limit = " LIMIT ".$limit;
$r = q("SELECT * FROM `notify` WHERE `uid` = %d $filter_sql ORDER BY $order_sql $limit",
intval(local_user())
);
if ($r!==false && count($r)>0) return $this->_set_extra($r);
return false;
}
/**
* @brief get one note for local_user() by $id value
*
* @param int $id
* @return array note values or null if not found
*/
public function getByID($id) {
$r = q("SELECT * FROM `notify` WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($id),
intval(local_user())
);
if($r!==false && count($r)>0) {
return $this->_set_extra($r)[0];
}
return null;
}
/**
* @brief set seen state of $note of local_user()
*
* @param array $note
* @param bool $seen optional true or false, default true
* @return bool true on success, false on errors
*/
public function setSeen($note, $seen = true) {
return q("UPDATE `notify` SET `seen` = %d WHERE ( `link` = '%s' OR ( `parent` != 0 AND `parent` = %d AND `otype` = '%s' )) AND `uid` = %d",
intval($seen),
dbesc($note['link']),
intval($note['parent']),
dbesc($note['otype']),
intval(local_user())
);
}
/**
* @brief set seen state of all notifications of local_user()
*
* @param bool $seen optional true or false. default true
* @return bool true on success, false on error
*/
public function setAllSeen($seen = true) {
return q("UPDATE `notify` SET `seen` = %d WHERE `uid` = %d",
intval($seen),
intval(local_user())
);
}
}

View File

@ -720,65 +720,101 @@ function guess_image_type($filename, $fromcurl=false) {
}
function import_profile_photo($photo,$uid,$cid) {
/**
* @brief Updates the avatar links in a contact only if needed
*
* @param string $avatar Link to avatar picture
* @param int $uid User id of contact owner
* @param int $cid Contact id
* @param bool $force force picture update
*
* @return array Returns array of the different avatar sizes
*/
function update_contact_avatar($avatar,$uid,$cid, $force = false) {
$a = get_app();
$r = q("SELECT `avatar`, `photo`, `thumb`, `micro` FROM `contact` WHERE `id` = %d LIMIT 1", intval($cid));
if (!$r)
return false;
else
$data = array($r[0]["photo"], $r[0]["thumb"], $r[0]["micro"]);
$r = q("select `resource-id` from photo where `uid` = %d and `contact-id` = %d and `scale` = 4 and `album` = 'Contact Photos' limit 1",
intval($uid),
intval($cid)
);
if(count($r) && strlen($r[0]['resource-id'])) {
$hash = $r[0]['resource-id'];
}
else {
$hash = photo_new_resource();
}
if (($r[0]["avatar"] != $avatar) OR $force) {
$photos = import_profile_photo($avatar,$uid,$cid, true);
$photo_failure = false;
if ($photos) {
q("UPDATE `contact` SET `avatar` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' WHERE `id` = %d",
dbesc($avatar), dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]),
dbesc(datetime_convert()), intval($cid));
return $photos;
}
}
$filename = basename($photo);
$img_str = fetch_url($photo,true);
return $data;
}
$type = guess_image_type($photo,true);
$img = new Photo($img_str, $type);
if($img->is_valid()) {
function import_profile_photo($photo,$uid,$cid, $quit_on_error = false) {
$img->scaleImageSquare(175);
$a = get_app();
$r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 4 );
$r = q("select `resource-id` from photo where `uid` = %d and `contact-id` = %d and `scale` = 4 and `album` = 'Contact Photos' limit 1",
intval($uid),
intval($cid)
);
if(count($r) && strlen($r[0]['resource-id'])) {
$hash = $r[0]['resource-id'];
} else {
$hash = photo_new_resource();
}
if($r === false)
$photo_failure = true;
$photo_failure = false;
$img->scaleImage(80);
$filename = basename($photo);
$img_str = fetch_url($photo,true);
$r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 5 );
if ($quit_on_error AND ($img_str == ""))
return false;
if($r === false)
$photo_failure = true;
$type = guess_image_type($photo,true);
$img = new Photo($img_str, $type);
if($img->is_valid()) {
$img->scaleImage(48);
$img->scaleImageSquare(175);
$r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 6 );
$r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 4 );
if($r === false)
$photo_failure = true;
if($r === false)
$photo_failure = true;
$photo = $a->get_baseurl() . '/photo/' . $hash . '-4.' . $img->getExt();
$thumb = $a->get_baseurl() . '/photo/' . $hash . '-5.' . $img->getExt();
$micro = $a->get_baseurl() . '/photo/' . $hash . '-6.' . $img->getExt();
}
else
$photo_failure = true;
$img->scaleImage(80);
if($photo_failure) {
$photo = $a->get_baseurl() . '/images/person-175.jpg';
$thumb = $a->get_baseurl() . '/images/person-80.jpg';
$micro = $a->get_baseurl() . '/images/person-48.jpg';
}
$r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 5 );
return(array($photo,$thumb,$micro));
if($r === false)
$photo_failure = true;
$img->scaleImage(48);
$r = $img->store($uid, $cid, $hash, $filename, 'Contact Photos', 6 );
if($r === false)
$photo_failure = true;
$photo = $a->get_baseurl() . '/photo/' . $hash . '-4.' . $img->getExt();
$thumb = $a->get_baseurl() . '/photo/' . $hash . '-5.' . $img->getExt();
$micro = $a->get_baseurl() . '/photo/' . $hash . '-6.' . $img->getExt();
} else
$photo_failure = true;
if($photo_failure AND $quit_on_error)
return false;
if($photo_failure) {
$photo = $a->get_baseurl() . '/images/person-175.jpg';
$thumb = $a->get_baseurl() . '/images/person-80.jpg';
$micro = $a->get_baseurl() . '/images/person-48.jpg';
}
return(array($photo,$thumb,$micro));
}
@ -792,15 +828,19 @@ function get_photo_info($url) {
$filesize = strlen($img_str);
$tempfile = tempnam(get_temppath(), "cache");
if (function_exists("getimagesizefromstring"))
$data = getimagesizefromstring($img_str);
else {
$tempfile = tempnam(get_temppath(), "cache");
$a = get_app();
$stamp1 = microtime(true);
file_put_contents($tempfile, $img_str);
$a->save_timestamp($stamp1, "file");
$a = get_app();
$stamp1 = microtime(true);
file_put_contents($tempfile, $img_str);
$a->save_timestamp($stamp1, "file");
$data = getimagesize($tempfile);
unlink($tempfile);
$data = getimagesize($tempfile);
unlink($tempfile);
}
if ($data)
$data["size"] = $filesize;

View File

@ -235,7 +235,9 @@ function scrape_feed($url) {
$a = get_app();
$ret = array();
$s = fetch_url($url);
$cookiejar = tempnam(get_temppath(), 'cookiejar-scrape-feed-');
$s = fetch_url($url, false, $redirects, 0, Null, $cookiejar);
unlink($cookiejar);
$headers = $a->get_curl_headers();
$code = $a->get_curl_code();
@ -559,10 +561,11 @@ function probe_url($url, $mode = PROBE_NORMAL, $level = 1) {
$pubkey = $hcard_key;
}
}
if($diaspora && $diaspora_base && $diaspora_guid) {
if($mode == PROBE_DIASPORA || ! $notify) {
$notify = $diaspora_base . 'receive/users/' . $diaspora_guid;
$diaspora_notify = $diaspora_base.'receive/users/'.$diaspora_guid;
if($mode == PROBE_DIASPORA || ! $notify || ($notify == $diaspora_notify)) {
$notify = $diaspora_notify;
$batch = $diaspora_base . 'receive/public' ;
}
if(strpos($url,'@'))
@ -661,7 +664,9 @@ function probe_url($url, $mode = PROBE_NORMAL, $level = 1) {
$vcard['photo'] = $feedret['photo'];
require_once('library/simplepie/simplepie.inc');
$feed = new SimplePie();
$xml = fetch_url($poll);
$cookiejar = tempnam(get_temppath(), 'cookiejar-scrape-feed-');
$xml = fetch_url($poll, false, $redirects, 0, Null, $cookiejar);
unlink($cookiejar);
logger('probe_url: fetch feed: ' . $poll . ' returns: ' . $xml, LOGGER_DATA);
$a = get_app();

View File

@ -20,7 +20,7 @@ function group_select($selname,$selclass,$preselected = false,$size = 4) {
$o .= "<select name=\"{$selname}[]\" id=\"$selclass\" class=\"$selclass\" multiple=\"multiple\" size=\"$size\" >\r\n";
$r = q("SELECT * FROM `group` WHERE `deleted` = 0 AND `uid` = %d ORDER BY `name` ASC",
$r = q("SELECT `id`, `name` FROM `group` WHERE NOT `deleted` AND `uid` = %d ORDER BY `name` ASC",
intval(local_user())
);
@ -309,7 +309,7 @@ function populate_acl($user = null, $show_jotnets = false) {
$pubmail_enabled = false;
if(! $mail_disabled) {
$r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
$r = q("SELECT `pubmail` FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
intval(local_user())
);
if(count($r)) {
@ -407,7 +407,7 @@ function acl_lookup(&$a, $out_type = 'json') {
$search = $_REQUEST['query'];
}
// logger("Searching for ".$search." - type ".$type, LOGGER_DEBUG);
logger("Searching for ".$search." - type ".$type, LOGGER_DEBUG);
if ($search!=""){
$sql_extra = "AND `name` LIKE '%%".dbesc($search)."%%'";
@ -503,7 +503,7 @@ function acl_lookup(&$a, $out_type = 'json') {
}
}
if ($type=='' || $type=='c'){
if ($type==''){
$r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, forum FROM `contact`
WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 AND `notify` != ''
@ -514,6 +514,17 @@ function acl_lookup(&$a, $out_type = 'json') {
dbesc(NETWORK_OSTATUS), dbesc(NETWORK_STATUSNET)
);
}
elseif ($type=='c'){
$r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag`, forum FROM `contact`
WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0 AND `notify` != ''
AND NOT (`network` IN ('%s'))
$sql_extra2
ORDER BY `name` ASC ",
intval(local_user()),
dbesc(NETWORK_STATUSNET)
);
}
elseif($type == 'm') {
$r = q("SELECT `id`, `name`, `nick`, `micro`, `network`, `url`, `attag` FROM `contact`
WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `archive` = 0

View File

@ -23,6 +23,7 @@
require_once('include/message.php');
require_once('include/group.php');
require_once('include/like.php');
require_once('include/NotificationsManager.php');
define('API_METHOD_ANY','*');
@ -250,7 +251,7 @@
*/
function api_call(&$a){
GLOBAL $API, $called_api;
$type="json";
if (strpos($a->query_string, ".xml")>0) $type="xml";
if (strpos($a->query_string, ".json")>0) $type="json";
@ -394,7 +395,7 @@
* Contact url or False if contact id is unknown
*/
function api_unique_id_to_url($id){
$r = q("SELECT `url` FROM `unique_contacts` WHERE `id`=%d LIMIT 1",
$r = q("SELECT `url` FROM `gcontact` WHERE `id`=%d LIMIT 1",
intval($id));
if ($r)
return ($r[0]["url"]);
@ -504,9 +505,7 @@
$r = array();
if ($url != "")
$r = q("SELECT * FROM `unique_contacts` WHERE `url`='%s' LIMIT 1", $url);
elseif ($nick != "")
$r = q("SELECT * FROM `unique_contacts` WHERE `nick`='%s' LIMIT 1", $nick);
$r = q("SELECT * FROM `gcontact` WHERE `nurl`='%s' LIMIT 1", dbesc(normalise_link($url)));
if ($r) {
// If no nick where given, extract it from the address
@ -518,14 +517,14 @@
'id_str' => (string) $r[0]["id"],
'name' => $r[0]["name"],
'screen_name' => (($r[0]['nick']) ? $r[0]['nick'] : $r[0]['name']),
'location' => NULL,
'description' => NULL,
'location' => $r[0]["location"],
'description' => $r[0]["about"],
'url' => $r[0]["url"],
'protected' => false,
'followers_count' => 0,
'friends_count' => 0,
'listed_count' => 0,
'created_at' => api_date(0),
'created_at' => api_date($r[0]["created"]),
'favourites_count' => 0,
'utc_offset' => 0,
'time_zone' => 'UTC',
@ -536,8 +535,8 @@
'contributors_enabled' => false,
'is_translator' => false,
'is_translation_enabled' => false,
'profile_image_url' => $r[0]["avatar"],
'profile_image_url_https' => $r[0]["avatar"],
'profile_image_url' => $r[0]["photo"],
'profile_image_url_https' => $r[0]["photo"],
'following' => false,
'follow_request_sent' => false,
'notifications' => false,
@ -547,7 +546,7 @@
'uid' => 0,
'cid' => 0,
'self' => 0,
'network' => '',
'network' => $r[0]["network"],
);
return $ret;
@ -618,22 +617,14 @@
$uinfo[0]['nick'] = api_get_nick($uinfo[0]["url"]);
}
// Fetching unique id
$r = q("SELECT id FROM `unique_contacts` WHERE `url`='%s' LIMIT 1", dbesc(normalise_link($uinfo[0]['url'])));
// If not there, then add it
if (count($r) == 0) {
q("INSERT INTO `unique_contacts` (`url`, `name`, `nick`, `avatar`) VALUES ('%s', '%s', '%s', '%s')",
dbesc(normalise_link($uinfo[0]['url'])), dbesc($uinfo[0]['name']),dbesc($uinfo[0]['nick']), dbesc($uinfo[0]['micro']));
$r = q("SELECT `id` FROM `unique_contacts` WHERE `url`='%s' LIMIT 1", dbesc(normalise_link($uinfo[0]['url'])));
}
$network_name = network_to_name($uinfo[0]['network'], $uinfo[0]['url']);
$gcontact_id = get_gcontact_id(array("url" => $uinfo[0]['url'], "network" => $uinfo[0]['network'],
"photo" => $uinfo[0]['micro'], "name" => $uinfo[0]['name']));
$ret = Array(
'id' => intval($r[0]['id']),
'id_str' => (string) intval($r[0]['id']),
'id' => intval($gcontact_id),
'id_str' => (string) intval($gcontact_id),
'name' => (($uinfo[0]['name']) ? $uinfo[0]['name'] : $uinfo[0]['nick']),
'screen_name' => (($uinfo[0]['nick']) ? $uinfo[0]['nick'] : $uinfo[0]['name']),
'location' => ($usr) ? $usr[0]['default-location'] : $network_name,
@ -667,45 +658,12 @@
function api_item_get_user(&$a, $item) {
$author = q("SELECT * FROM `unique_contacts` WHERE `url`='%s' LIMIT 1",
dbesc(normalise_link($item['author-link'])));
// Make sure that there is an entry in the global contacts for author and owner
get_gcontact_id(array("url" => $item['author-link'], "network" => $item['network'],
"photo" => $item['author-avatar'], "name" => $item['author-name']));
if (count($author) == 0) {
q("INSERT INTO `unique_contacts` (`url`, `name`, `avatar`) VALUES ('%s', '%s', '%s')",
dbesc(normalise_link($item["author-link"])), dbesc($item["author-name"]), dbesc($item["author-avatar"]));
$author = q("SELECT `id` FROM `unique_contacts` WHERE `url`='%s' LIMIT 1",
dbesc(normalise_link($item['author-link'])));
} else if ($item["author-link"].$item["author-name"] != $author[0]["url"].$author[0]["name"]) {
$r = q("SELECT `id` FROM `unique_contacts` WHERE `name` = '%s' AND `avatar` = '%s' AND url = '%s'",
dbesc($item["author-name"]), dbesc($item["author-avatar"]),
dbesc(normalise_link($item["author-link"])));
if (!$r)
q("UPDATE `unique_contacts` SET `name` = '%s', `avatar` = '%s' WHERE `url` = '%s'",
dbesc($item["author-name"]), dbesc($item["author-avatar"]),
dbesc(normalise_link($item["author-link"])));
}
$owner = q("SELECT `id` FROM `unique_contacts` WHERE `url`='%s' LIMIT 1",
dbesc(normalise_link($item['owner-link'])));
if (count($owner) == 0) {
q("INSERT INTO `unique_contacts` (`url`, `name`, `avatar`) VALUES ('%s', '%s', '%s')",
dbesc(normalise_link($item["owner-link"])), dbesc($item["owner-name"]), dbesc($item["owner-avatar"]));
$owner = q("SELECT `id` FROM `unique_contacts` WHERE `url`='%s' LIMIT 1",
dbesc(normalise_link($item['owner-link'])));
} else if ($item["owner-link"].$item["owner-name"] != $owner[0]["url"].$owner[0]["name"]) {
$r = q("SELECT `id` FROM `unique_contacts` WHERE `name` = '%s' AND `avatar` = '%s' AND url = '%s'",
dbesc($item["owner-name"]), dbesc($item["owner-avatar"]),
dbesc(normalise_link($item["owner-link"])));
if (!$r)
q("UPDATE `unique_contacts` SET `name` = '%s', `avatar` = '%s' WHERE `url` = '%s'",
dbesc($item["owner-name"]), dbesc($item["owner-avatar"]),
dbesc(normalise_link($item["owner-link"])));
}
get_gcontact_id(array("url" => $item['owner-link'], "network" => $item['network'],
"photo" => $item['owner-avatar'], "name" => $item['owner-name']));
// Comments in threads may appear as wall-to-wall postings.
// So only take the owner at the top posting.
@ -724,6 +682,34 @@
}
/**
* @brief transform $data array in xml without a template
*
* @param array $data
* @return string xml string
*/
function api_array_to_xml($data, $ename="") {
$attrs="";
$childs="";
if (count($data)==1 && !is_array($data[0])) {
$ename = array_keys($data)[0];
$v = $data[$ename];
return "<$ename>$v</$ename>";
}
foreach($data as $k=>$v) {
$k=trim($k,'$');
if (!is_array($v)) {
$attrs .= sprintf('%s="%s" ', $k, $v);
} else {
if (is_numeric($k)) $k=trim($ename,'s');
$childs.=api_array_to_xml($v, $k);
}
}
$res = $childs;
if ($ename!="") $res = "<$ename $attrs>$res</$ename>";
return $res;
}
/**
* load api $templatename for $type and replace $data array
*/
@ -736,13 +722,17 @@
case "rss":
case "xml":
$data = array_xmlify($data);
$tpl = get_markup_template("api_".$templatename."_".$type.".tpl");
if(! $tpl) {
header ("Content-Type: text/xml");
echo '<?xml version="1.0" encoding="UTF-8"?>'."\n".'<status><error>not implemented</error></status>';
killme();
if ($templatename==="<auto>") {
$ret = api_array_to_xml($data);
} else {
$tpl = get_markup_template("api_".$templatename."_".$type.".tpl");
if(! $tpl) {
header ("Content-Type: text/xml");
echo '<?xml version="1.0" encoding="UTF-8"?>'."\n".'<status><error>not implemented</error></status>';
killme();
}
$ret = replace_macros($tpl, $data);
}
$ret = replace_macros($tpl, $data);
break;
case "json":
$ret = $data;
@ -825,8 +815,6 @@
if((strpos($txt,'<') !== false) || (strpos($txt,'>') !== false)) {
require_once('library/HTMLPurifier.auto.php');
$txt = html2bb_video($txt);
$config = HTMLPurifier_Config::createDefault();
$config->set('Cache.DefinitionImpl', null);
@ -866,9 +854,6 @@
if(requestdata('htmlstatus')) {
$txt = requestdata('htmlstatus');
if((strpos($txt,'<') !== false) || (strpos($txt,'>') !== false)) {
require_once('library/HTMLPurifier.auto.php');
$txt = html2bb_video($txt);
$config = HTMLPurifier_Config::createDefault();
@ -1074,7 +1059,7 @@
$in_reply_to_status_id= intval($lastwall['parent']);
$in_reply_to_status_id_str = (string) intval($lastwall['parent']);
$r = q("SELECT * FROM `unique_contacts` WHERE `url` = '%s'", dbesc(normalise_link($lastwall['item-author'])));
$r = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s'", dbesc(normalise_link($lastwall['item-author'])));
if ($r) {
if ($r[0]['nick'] == "")
$r[0]['nick'] = api_get_nick($r[0]["url"]);
@ -1196,7 +1181,7 @@
$in_reply_to_status_id = intval($lastwall['parent']);
$in_reply_to_status_id_str = (string) intval($lastwall['parent']);
$r = q("SELECT * FROM `unique_contacts` WHERE `url` = '%s'", dbesc(normalise_link($reply[0]['item-author'])));
$r = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s'", dbesc(normalise_link($reply[0]['item-author'])));
if ($r) {
if ($r[0]['nick'] == "")
$r[0]['nick'] = api_get_nick($r[0]["url"]);
@ -1257,9 +1242,9 @@
$userlist = array();
if (isset($_GET["q"])) {
$r = q("SELECT id FROM `unique_contacts` WHERE `name`='%s'", dbesc($_GET["q"]));
$r = q("SELECT id FROM `gcontact` WHERE `name`='%s'", dbesc($_GET["q"]));
if (!count($r))
$r = q("SELECT `id` FROM `unique_contacts` WHERE `nick`='%s'", dbesc($_GET["q"]));
$r = q("SELECT `id` FROM `gcontact` WHERE `nick`='%s'", dbesc($_GET["q"]));
if (count($r)) {
foreach ($r AS $user) {
@ -1595,6 +1580,8 @@
WHERE `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0
AND `contact`.`id` = `item`.`contact-id`
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
AND NOT `item`.`private` AND `item`.`allow_cid` = '' AND `item`.`allow`.`gid` = ''
AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
$sql_extra
AND `item`.`id`=%d",
intval($id)
@ -1623,7 +1610,8 @@
$_REQUEST["source"] = api_source();
item_post($a);
}
} else
throw new ForbiddenException();
// this should output the last post (the one we just posted).
$called_api = null;
@ -2342,7 +2330,7 @@
intval(api_user()),
intval($in_reply_to_status_id));
if ($r) {
$r = q("SELECT * FROM `unique_contacts` WHERE `url` = '%s'", dbesc(normalise_link($r[0]['author-link'])));
$r = q("SELECT * FROM `gcontact` WHERE `url` = '%s'", dbesc(normalise_link($r[0]['author-link'])));
if ($r) {
if ($r[0]['nick'] == "")
@ -2598,7 +2586,7 @@
$stringify_ids = (x($_REQUEST,'stringify_ids')?$_REQUEST['stringify_ids']:false);
$r = q("SELECT `unique_contacts`.`id` FROM `contact`, `unique_contacts` WHERE `contact`.`nurl` = `unique_contacts`.`url` AND `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `pending` $sql_extra",
$r = q("SELECT `gcontact`.`id` FROM `contact`, `gcontact` WHERE `contact`.`nurl` = `gcontact`.`nurl` AND `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `pending` $sql_extra",
intval(api_user())
);
@ -3096,11 +3084,8 @@
//}
if ($nick != "") {
q("UPDATE `unique_contacts` SET `nick` = '%s' WHERE `nick` != '%s' AND url = '%s'",
dbesc($nick), dbesc($nick), dbesc(normalise_link($profile)));
if ($nick != "")
return($nick);
}
return(false);
}
@ -3431,6 +3416,64 @@
api_register_func('api/friendica/activity/unattendno', 'api_friendica_activity', true, API_METHOD_POST);
api_register_func('api/friendica/activity/unattendmaybe', 'api_friendica_activity', true, API_METHOD_POST);
/**
* @brief Returns notifications
*
* @param App $a
* @param string $type Known types are 'atom', 'rss', 'xml' and 'json'
* @return string
*/
function api_friendica_notification(&$a, $type) {
if (api_user()===false) throw new ForbiddenException();
if ($a->argc!==3) throw new BadRequestException("Invalid argument count");
$nm = new NotificationsManager();
$notes = $nm->getAll(array(), "+seen -date", 50);
return api_apply_template("<auto>", $type, array('$notes' => $notes));
}
/**
* @brief Set notification as seen and returns associated item (if possible)
*
* POST request with 'id' param as notification id
*
* @param App $a
* @param string $type Known types are 'atom', 'rss', 'xml' and 'json'
* @return string
*/
function api_friendica_notification_seen(&$a, $type){
if (api_user()===false) throw new ForbiddenException();
if ($a->argc!==4) throw new BadRequestException("Invalid argument count");
$id = (x($_REQUEST, 'id') ? intval($_REQUEST['id']) : 0);
$nm = new NotificationsManager();
$note = $nm->getByID($id);
if (is_null($note)) throw new BadRequestException("Invalid argument");
$nm->setSeen($note);
if ($note['otype']=='item') {
// would be really better with an ItemsManager and $im->getByID() :-P
$r = q("SELECT * FROM `item` WHERE `id`=%d AND `uid`=%d",
intval($note['iid']),
intval(local_user())
);
if ($r!==false) {
// we found the item, return it to the user
$user_info = api_get_user($a);
$ret = api_format_items($r,$user_info);
$data = array('$statuses' => $ret);
return api_apply_template("timeline", $type, $data);
}
// the item can't be found, but we set the note as seen, so we count this as a success
}
return api_apply_template('<auto>', $type, array('status' => "success"));
}
api_register_func('api/friendica/notification/seen', 'api_friendica_notification_seen', true, API_METHOD_POST);
api_register_func('api/friendica/notification', 'api_friendica_notification', true, API_METHOD_GET);
/*
To.Do:
[pagename] => api/1.1/statuses/lookup.json

69
include/autoloader.php Normal file
View File

@ -0,0 +1,69 @@
<?php
/**
* @file include/autoloader.php
*/
/**
* @brief composer-derived autoloader init
**/
class FriendicaAutoloaderInit
{
private static $loader;
public static function loadClassLoader($class)
{
if ('Composer\Autoload\ClassLoader' === $class) {
require __DIR__ . '/autoloader/ClassLoader.php';
}
}
public static function getLoader()
{
if (null !== self::$loader) {
return self::$loader;
}
spl_autoload_register(array('FriendicaAutoloaderInit', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('FriendicaAutoloaderInit', 'loadClassLoader'));
// library
$map = require __DIR__ . '/autoloader/autoload_namespaces.php';
foreach ($map as $namespace => $path) {
$loader->set($namespace, $path);
}
$map = require __DIR__ . '/autoloader/autoload_psr4.php';
foreach ($map as $namespace => $path) {
$loader->setPsr4($namespace, $path);
}
$classMap = require __DIR__ . '/autoloader/autoload_classmap.php';
if ($classMap) {
$loader->addClassMap($classMap);
}
$loader->register(true);
$includeFiles = require __DIR__ . '/autoloader/autoload_files.php';
foreach ($includeFiles as $fileIdentifier => $file) {
friendicaRequire($fileIdentifier, $file);
}
return $loader;
}
}
function friendicaRequire($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
require $file;
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
}
}
return FriendicaAutoloaderInit::getLoader();

View File

@ -0,0 +1,413 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE.composer
* file that was distributed with this source code.
*/
namespace Composer\Autoload;
/**
* ClassLoader implements a PSR-0 class loader
*
* See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md
*
* $loader = new \Composer\Autoload\ClassLoader();
*
* // register classes with namespaces
* $loader->add('Symfony\Component', __DIR__.'/component');
* $loader->add('Symfony', __DIR__.'/framework');
*
* // activate the autoloader
* $loader->register();
*
* // to enable searching the include path (eg. for PEAR packages)
* $loader->setUseIncludePath(true);
*
* In this example, if you try to use a class in the Symfony\Component
* namespace or one of its children (Symfony\Component\Console for instance),
* the autoloader will first look for the class under the component/
* directory, and it will then fallback to the framework/ directory if not
* found before giving up.
*
* This class is loosely based on the Symfony UniversalClassLoader.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class ClassLoader
{
// PSR-4
private $prefixLengthsPsr4 = array();
private $prefixDirsPsr4 = array();
private $fallbackDirsPsr4 = array();
// PSR-0
private $prefixesPsr0 = array();
private $fallbackDirsPsr0 = array();
private $useIncludePath = false;
private $classMap = array();
private $classMapAuthoritative = false;
public function getPrefixes()
{
if (!empty($this->prefixesPsr0)) {
return call_user_func_array('array_merge', $this->prefixesPsr0);
}
return array();
}
public function getPrefixesPsr4()
{
return $this->prefixDirsPsr4;
}
public function getFallbackDirs()
{
return $this->fallbackDirsPsr0;
}
public function getFallbackDirsPsr4()
{
return $this->fallbackDirsPsr4;
}
public function getClassMap()
{
return $this->classMap;
}
/**
* @param array $classMap Class to filename map
*/
public function addClassMap(array $classMap)
{
if ($this->classMap) {
$this->classMap = array_merge($this->classMap, $classMap);
} else {
$this->classMap = $classMap;
}
}
/**
* Registers a set of PSR-0 directories for a given prefix, either
* appending or prepending to the ones previously set for this prefix.
*
* @param string $prefix The prefix
* @param array|string $paths The PSR-0 root directories
* @param bool $prepend Whether to prepend the directories
*/
public function add($prefix, $paths, $prepend = false)
{
if (!$prefix) {
if ($prepend) {
$this->fallbackDirsPsr0 = array_merge(
(array) $paths,
$this->fallbackDirsPsr0
);
} else {
$this->fallbackDirsPsr0 = array_merge(
$this->fallbackDirsPsr0,
(array) $paths
);
}
return;
}
$first = $prefix[0];
if (!isset($this->prefixesPsr0[$first][$prefix])) {
$this->prefixesPsr0[$first][$prefix] = (array) $paths;
return;
}
if ($prepend) {
$this->prefixesPsr0[$first][$prefix] = array_merge(
(array) $paths,
$this->prefixesPsr0[$first][$prefix]
);
} else {
$this->prefixesPsr0[$first][$prefix] = array_merge(
$this->prefixesPsr0[$first][$prefix],
(array) $paths
);
}
}
/**
* Registers a set of PSR-4 directories for a given namespace, either
* appending or prepending to the ones previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param array|string $paths The PSR-0 base directories
* @param bool $prepend Whether to prepend the directories
*
* @throws \InvalidArgumentException
*/
public function addPsr4($prefix, $paths, $prepend = false)
{
if (!$prefix) {
// Register directories for the root namespace.
if ($prepend) {
$this->fallbackDirsPsr4 = array_merge(
(array) $paths,
$this->fallbackDirsPsr4
);
} else {
$this->fallbackDirsPsr4 = array_merge(
$this->fallbackDirsPsr4,
(array) $paths
);
}
} elseif (!isset($this->prefixDirsPsr4[$prefix])) {
// Register directories for a new namespace.
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1]) {
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
$this->prefixDirsPsr4[$prefix] = (array) $paths;
} elseif ($prepend) {
// Prepend directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
(array) $paths,
$this->prefixDirsPsr4[$prefix]
);
} else {
// Append directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
$this->prefixDirsPsr4[$prefix],
(array) $paths
);
}
}
/**
* Registers a set of PSR-0 directories for a given prefix,
* replacing any others previously set for this prefix.
*
* @param string $prefix The prefix
* @param array|string $paths The PSR-0 base directories
*/
public function set($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr0 = (array) $paths;
} else {
$this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
}
}
/**
* Registers a set of PSR-4 directories for a given namespace,
* replacing any others previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param array|string $paths The PSR-4 base directories
*
* @throws \InvalidArgumentException
*/
public function setPsr4($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr4 = (array) $paths;
} else {
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1]) {
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
$this->prefixDirsPsr4[$prefix] = (array) $paths;
}
}
/**
* Turns on searching the include path for class files.
*
* @param bool $useIncludePath
*/
public function setUseIncludePath($useIncludePath)
{
$this->useIncludePath = $useIncludePath;
}
/**
* Can be used to check if the autoloader uses the include path to check
* for classes.
*
* @return bool
*/
public function getUseIncludePath()
{
return $this->useIncludePath;
}
/**
* Turns off searching the prefix and fallback directories for classes
* that have not been registered with the class map.
*
* @param bool $classMapAuthoritative
*/
public function setClassMapAuthoritative($classMapAuthoritative)
{
$this->classMapAuthoritative = $classMapAuthoritative;
}
/**
* Should class lookup fail if not found in the current class map?
*
* @return bool
*/
public function isClassMapAuthoritative()
{
return $this->classMapAuthoritative;
}
/**
* Registers this instance as an autoloader.
*
* @param bool $prepend Whether to prepend the autoloader or not
*/
public function register($prepend = false)
{
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
}
/**
* Unregisters this instance as an autoloader.
*/
public function unregister()
{
spl_autoload_unregister(array($this, 'loadClass'));
}
/**
* Loads the given class or interface.
*
* @param string $class The name of the class
* @return bool|null True if loaded, null otherwise
*/
public function loadClass($class)
{
if ($file = $this->findFile($class)) {
includeFile($file);
return true;
}
}
/**
* Finds the path to the file where the class is defined.
*
* @param string $class The name of the class
*
* @return string|false The path if found, false otherwise
*/
public function findFile($class)
{
// work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731
if ('\\' == $class[0]) {
$class = substr($class, 1);
}
// class map lookup
if (isset($this->classMap[$class])) {
return $this->classMap[$class];
}
if ($this->classMapAuthoritative) {
return false;
}
$file = $this->findFileWithExtension($class, '.php');
// Search for Hack files if we are running on HHVM
if ($file === null && defined('HHVM_VERSION')) {
$file = $this->findFileWithExtension($class, '.hh');
}
if ($file === null) {
// Remember that this class does not exist.
return $this->classMap[$class] = false;
}
return $file;
}
private function findFileWithExtension($class, $ext)
{
// PSR-4 lookup
$logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
$first = $class[0];
if (isset($this->prefixLengthsPsr4[$first])) {
foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) {
if (0 === strpos($class, $prefix)) {
foreach ($this->prefixDirsPsr4[$prefix] as $dir) {
if (is_file($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) {
return $file;
}
}
}
}
}
// PSR-4 fallback dirs
foreach ($this->fallbackDirsPsr4 as $dir) {
if (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
return $file;
}
}
// PSR-0 lookup
if (false !== $pos = strrpos($class, '\\')) {
// namespaced class name
$logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
. strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
} else {
// PEAR-like class name
$logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
}
if (isset($this->prefixesPsr0[$first])) {
foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
if (0 === strpos($class, $prefix)) {
foreach ($dirs as $dir) {
if (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
}
}
}
// PSR-0 fallback dirs
foreach ($this->fallbackDirsPsr0 as $dir) {
if (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
// PSR-0 include paths.
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
return $file;
}
}
}
/**
* Scope isolated include.
*
* Prevents access to $this/self from included files.
*/
function includeFile($file)
{
include $file;
}

View File

@ -0,0 +1,19 @@
Copyright (c) 2015 Nils Adermann, Jordi Boggiano
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the Software), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, andor sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@ -0,0 +1,9 @@
<?php
// autoload_classmap.php @generated by Composer
$vendorDir = dirname(dirname(dirname(__FILE__)))."/library";
$baseDir = dirname($vendorDir);
return array(
);

View File

@ -0,0 +1,10 @@
<?php
// autoload_files.php @generated by Composer
$vendorDir = dirname(dirname(dirname(__FILE__)))."/library";
$baseDir = dirname($vendorDir);
return array(
'2cffec82183ee1cea088009cef9a6fc3' => $vendorDir . '/ezyang/htmlpurifier/library/HTMLPurifier.composer.php',
);

View File

@ -0,0 +1,10 @@
<?php
// autoload_namespaces.php @generated by Composer
$vendorDir = dirname(dirname(dirname(__FILE__)))."/library";
$baseDir = dirname($vendorDir);
return array(
'HTMLPurifier' => array($vendorDir . '/ezyang/htmlpurifier/library'),
);

View File

@ -0,0 +1,9 @@
<?php
// autoload_psr4.php @generated by Composer
$vendorDir = dirname(dirname(dirname(__FILE__)))."/library";
$baseDir = dirname($vendorDir);
return array(
);

View File

@ -3,6 +3,7 @@ require_once("include/oembed.php");
require_once('include/event.php');
require_once('include/map.php');
require_once('mod/proxy.php');
require_once('include/Contact.php');
function bb_PictureCacheExt($matches) {
if (strpos($matches[3], "data:image/") === 0)
@ -541,8 +542,23 @@ function bb_ShareAttributes($share, $simplehtml) {
$reldate = (($posted) ? " " . relative_date($posted) : '');
}
$userid = GetProfileUsername($profile,$author, false);
$userid_compact = GetProfileUsername($profile,$author, true);
$data = get_contact_details_by_url($profile);
if (isset($data["name"]) AND isset($data["addr"]))
$userid_compact = $data["name"]." (".$data["addr"].")";
else
$userid_compact = GetProfileUsername($profile,$author, true);
if (isset($data["addr"]))
$userid = $data["addr"];
else
$userid = GetProfileUsername($profile,$author, false);
if (isset($data["name"]))
$author = $data["name"];
if (isset($data["photo"]))
$avatar = $data["photo"];
$preshare = trim($share[1]);

View File

@ -19,7 +19,7 @@ if(! function_exists('load_config')) {
function load_config($family) {
global $a;
$r = q("SELECT * FROM `config` WHERE `cat` = '%s'", dbesc($family));
$r = q("SELECT `v`, `k` FROM `config` WHERE `cat` = '%s'", dbesc($family));
if(count($r)) {
foreach($r as $rr) {
$k = $rr['k'];
@ -170,7 +170,7 @@ function set_config($family,$key,$value) {
if(! function_exists('load_pconfig')) {
function load_pconfig($uid,$family) {
global $a;
$r = q("SELECT * FROM `pconfig` WHERE `cat` = '%s' AND `uid` = %d",
$r = q("SELECT `v`,`k` FROM `pconfig` WHERE `cat` = '%s' AND `uid` = %d",
dbesc($family),
intval($uid)
);

View File

@ -811,16 +811,16 @@ function best_link_url($item,&$sparkle,$ssl_state = false) {
if((local_user()) && (local_user() == $item['uid'])) {
if(isset($a->contacts) && x($a->contacts,$clean_url)) {
if($a->contacts[$clean_url]['network'] === NETWORK_DFRN) {
$best_url = $a->get_baseurl($ssl_state) . '/redir/' . $a->contacts[$clean_url]['id'];
$best_url = 'redir/'.$a->contacts[$clean_url]['id'];
$sparkle = true;
} else
$best_url = $a->contacts[$clean_url]['url'];
}
} elseif (local_user()) {
$r = q("SELECT `id`, `network` FROM `contact` WHERE `network` = '%s' AND `uid` = %d AND `nurl` = '%s'",
$r = q("SELECT `id` FROM `contact` WHERE `network` = '%s' AND `uid` = %d AND `nurl` = '%s' LIMIT 1",
dbesc(NETWORK_DFRN), intval(local_user()), dbesc(normalise_link($clean_url)));
if ($r) {
$best_url = $a->get_baseurl($ssl_state).'/redir/'.$r[0]['id'];
$best_url = 'redir/'.$r[0]['id'];
$sparkle = true;
}
}
@ -876,7 +876,7 @@ function item_photo_menu($item){
if(local_user() && local_user() == $item['uid'] && link_compare($item['url'],$item['author-link'])) {
$cid = $item['contact-id'];
} else {
$r = q("SELECT `id`, `network` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' ORDER BY `uid` DESC LIMIT 1",
$r = q("SELECT `id`, `network` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' LIMIT 1",
intval(local_user()), dbesc(normalise_link($item['author-link'])));
if ($r) {
$cid = $r[0]["id"];

View File

@ -30,7 +30,6 @@ function cron_run(&$argv, &$argc){
require_once('include/session.php');
require_once('include/datetime.php');
require_once('library/simplepie/simplepie.inc');
require_once('include/items.php');
require_once('include/Contact.php');
require_once('include/email.php');
@ -133,9 +132,8 @@ function cron_run(&$argv, &$argc){
// Check every conversation
check_conversations(false);
// Follow your friends from your legacy OStatus account
// Doesn't work
// ostatus_check_follow_friends();
// Set the gcontact-id in the item table if missing
item_set_gcontact();
// update nodeinfo data
nodeinfo_cron();
@ -159,75 +157,14 @@ function cron_run(&$argv, &$argc){
proc_run('php','include/expire.php');
}
$last = get_config('system','cache_last_cleared');
// Clear cache entries
cron_clear_cache($a);
if($last) {
$next = $last + (3600); // Once per hour
$clear_cache = ($next <= time());
} else
$clear_cache = true;
// Repair missing Diaspora values in contacts
cron_repair_diaspora($a);
if ($clear_cache) {
// clear old cache
Cache::clear();
// clear old item cache files
clear_cache();
// clear cache for photos
clear_cache($a->get_basepath(), $a->get_basepath()."/photo");
// clear smarty cache
clear_cache($a->get_basepath()."/view/smarty3/compiled", $a->get_basepath()."/view/smarty3/compiled");
// clear cache for image proxy
if (!get_config("system", "proxy_disabled")) {
clear_cache($a->get_basepath(), $a->get_basepath()."/proxy");
$cachetime = get_config('system','proxy_cache_time');
if (!$cachetime) $cachetime = PROXY_DEFAULT_TIME;
q('DELETE FROM `photo` WHERE `uid` = 0 AND `resource-id` LIKE "pic:%%" AND `created` < NOW() - INTERVAL %d SECOND', $cachetime);
}
// Maximum table size in megabyte
$max_tablesize = intval(get_config('system','optimize_max_tablesize')) * 1000000;
if ($max_tablesize == 0)
$max_tablesize = 100 * 1000000; // Default are 100 MB
// Minimum fragmentation level in percent
$fragmentation_level = intval(get_config('system','optimize_fragmentation')) / 100;
if ($fragmentation_level == 0)
$fragmentation_level = 0.3; // Default value is 30%
// Optimize some tables that need to be optimized
$r = q("SHOW TABLE STATUS");
foreach($r as $table) {
// Don't optimize tables that are too large
if ($table["Data_length"] > $max_tablesize)
continue;
// Don't optimize empty tables
if ($table["Data_length"] == 0)
continue;
// Calculate fragmentation
$fragmentation = $table["Data_free"] / $table["Data_length"];
logger("Table ".$table["Name"]." - Fragmentation level: ".round($fragmentation * 100, 2), LOGGER_DEBUG);
// Don't optimize tables that needn't to be optimized
if ($fragmentation < $fragmentation_level)
continue;
// So optimize it
logger("Optimize Table ".$table["Name"], LOGGER_DEBUG);
q("OPTIMIZE TABLE `%s`", dbesc($table["Name"]));
}
set_config('system','cache_last_cleared', time());
}
// Repair entries in the database
cron_repair_database();
$manual_id = 0;
$generation = 0;
@ -373,6 +310,132 @@ function cron_run(&$argv, &$argc){
return;
}
/**
* @brief Clear cache entries
*
* @param App $a
*/
function cron_clear_cache(&$a) {
$last = get_config('system','cache_last_cleared');
if($last) {
$next = $last + (3600); // Once per hour
$clear_cache = ($next <= time());
} else
$clear_cache = true;
if (!$clear_cache)
return;
// clear old cache
Cache::clear();
// clear old item cache files
clear_cache();
// clear cache for photos
clear_cache($a->get_basepath(), $a->get_basepath()."/photo");
// clear smarty cache
clear_cache($a->get_basepath()."/view/smarty3/compiled", $a->get_basepath()."/view/smarty3/compiled");
// clear cache for image proxy
if (!get_config("system", "proxy_disabled")) {
clear_cache($a->get_basepath(), $a->get_basepath()."/proxy");
$cachetime = get_config('system','proxy_cache_time');
if (!$cachetime) $cachetime = PROXY_DEFAULT_TIME;
q('DELETE FROM `photo` WHERE `uid` = 0 AND `resource-id` LIKE "pic:%%" AND `created` < NOW() - INTERVAL %d SECOND', $cachetime);
}
// Delete the cached OEmbed entries that are older than one year
q("DELETE FROM `oembed` WHERE `created` < NOW() - INTERVAL 1 YEAR");
// Delete the cached "parse_url" entries that are older than one year
q("DELETE FROM `parsed_url` WHERE `created` < NOW() - INTERVAL 1 YEAR");
// Maximum table size in megabyte
$max_tablesize = intval(get_config('system','optimize_max_tablesize')) * 1000000;
if ($max_tablesize == 0)
$max_tablesize = 100 * 1000000; // Default are 100 MB
// Minimum fragmentation level in percent
$fragmentation_level = intval(get_config('system','optimize_fragmentation')) / 100;
if ($fragmentation_level == 0)
$fragmentation_level = 0.3; // Default value is 30%
// Optimize some tables that need to be optimized
$r = q("SHOW TABLE STATUS");
foreach($r as $table) {
// Don't optimize tables that are too large
if ($table["Data_length"] > $max_tablesize)
continue;
// Don't optimize empty tables
if ($table["Data_length"] == 0)
continue;
// Calculate fragmentation
$fragmentation = $table["Data_free"] / $table["Data_length"];
logger("Table ".$table["Name"]." - Fragmentation level: ".round($fragmentation * 100, 2), LOGGER_DEBUG);
// Don't optimize tables that needn't to be optimized
if ($fragmentation < $fragmentation_level)
continue;
// So optimize it
logger("Optimize Table ".$table["Name"], LOGGER_DEBUG);
q("OPTIMIZE TABLE `%s`", dbesc($table["Name"]));
}
set_config('system','cache_last_cleared', time());
}
/**
* @brief Repair missing values in Diaspora contacts
*
* @param App $a
*/
function cron_repair_diaspora(&$a) {
$r = q("SELECT `id`, `url` FROM `contact`
WHERE `network` = '%s' AND (`batch` = '' OR `notify` = '' OR `poll` = '' OR pubkey = '')
ORDER BY RAND() LIMIT 50", dbesc(NETWORK_DIASPORA));
if ($r) {
foreach ($r AS $contact) {
if (poco_reachable($contact["url"])) {
$data = probe_url($contact["url"]);
if ($data["network"] == NETWORK_DIASPORA) {
logger("Repair contact ".$contact["id"]." ".$contact["url"], LOGGER_DEBUG);
q("UPDATE `contact` SET `batch` = '%s', `notify` = '%s', `poll` = '%s', pubkey = '%s' WHERE `id` = %d",
dbesc($data["batch"]), dbesc($data["notify"]), dbesc($data["poll"]), dbesc($data["pubkey"]),
intval($contact["id"]));
}
}
}
}
}
/**
* @brief Do some repairs in database entries
*
*/
function cron_repair_database() {
// Set the parent if it wasn't set. (Shouldn't happen - but does sometimes)
// This call is very "cheap" so we can do it at any time without a problem
q("UPDATE `item` INNER JOIN `item` AS `parent` ON `parent`.`uri` = `item`.`parent-uri` AND `parent`.`uid` = `item`.`uid` SET `item`.`parent` = `parent`.`id` WHERE `item`.`parent` = 0");
/// @todo
/// - remove thread entries without item
/// - remove sign entries without item
/// - remove children when parent got lost
/// - set contact-id in item when not present
}
if (array_search(__file__,get_included_files())===0){
cron_run($_SERVER["argv"],$_SERVER["argc"]);
killme();

View File

@ -1,8 +1,17 @@
<?php
/**
* @file include/datetime.php
* @brief Some functions for date and time related tasks.
*/
// two-level sort for timezones.
if(! function_exists('timezone_cmp')) {
/**
* @brief Two-level sort for timezones.
*
* @param string $a
* @param string $b
* @return int
*/
function timezone_cmp($a, $b) {
if(strstr($a,'/') && strstr($b,'/')) {
if ( t($a) == t($b)) return 0;
@ -11,11 +20,16 @@ function timezone_cmp($a, $b) {
if(strstr($a,'/')) return -1;
if(strstr($b,'/')) return 1;
if ( t($a) == t($b)) return 0;
return ( t($a) < t($b)) ? -1 : 1;
}}
// emit a timezone selector grouped (primarily) by continent
if(! function_exists('select_timezone')) {
return ( t($a) < t($b)) ? -1 : 1;
}
/**
* @brief Emit a timezone selector grouped (primarily) by continent
*
* @param string $current Timezone
* @return string Parsed HTML output
*/
function select_timezone($current = 'America/Los_Angeles') {
$timezone_identifiers = DateTimeZone::listIdentifiers();
@ -52,13 +66,25 @@ function select_timezone($current = 'America/Los_Angeles') {
}
$o .= '</optgroup></select>';
return $o;
}}
}
// 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'
if (!function_exists('field_timezone')){
/**
* @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){
$options = select_timezone($current);
$options = str_replace('<select id="timezone_select" name="timezone">','', $options);
@ -69,15 +95,19 @@ function field_timezone($name='timezone', $label='', $current = 'America/Los_Ang
'$field' => array($name, $label, $current, $help, $options),
));
}}
}
// General purpose date parse/convert function.
// $from = source timezone
// $to = dest timezone
// $s = some parseable date/time string
// $fmt = output format
if(! function_exists('datetime_convert')) {
/**
* @brief General purpose date parse/convert function.
*
* @param string $from Source timezone
* @param string $to Dest timezone
* @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") {
// Defaults to UTC if nothing is set, but throws an exception if set to empty string.
@ -123,14 +153,20 @@ function datetime_convert($from = 'UTC', $to = 'UTC', $s = 'now', $fmt = "Y-m-d
}
$d->setTimeZone($to_obj);
return($d->format($fmt));
}}
}
// wrapper for date selector, tailored for use in birthday fields
/**
* @brief Wrapper for date selector, tailored for use in birthday fields.
*
* @param string $dob Date of Birth
* @return string
*/
function dob($dob) {
list($year,$month,$day) = sscanf($dob,'%4d-%2d-%2d');
$f = get_config('system','birthday_input_format');
if(! $f)
$f = 'ymd';
@ -138,62 +174,69 @@ function dob($dob) {
$value = '';
else
$value = (($year) ? datetime_convert('UTC','UTC',$dob,'Y-m-d') : datetime_convert('UTC','UTC',$dob,'m-d'));
$o = '<input type="text" name="dob" value="' . $value . '" placeholder="' . t('YYYY-MM-DD or MM-DD') . '" />';
// if ($dob && $dob != '0000-00-00')
// $o = datesel($f,mktime(0,0,0,0,0,1900),mktime(),mktime(0,0,0,$month,$day,$year),'dob');
// else
// $o = datesel($f,mktime(0,0,0,0,0,1900),mktime(),false,'dob');
return $o;
}
/**
* returns a date selector
* @param $format
* format string, e.g. 'ymd' or 'mdy'. Not currently supported
* @param $min
* unix timestamp of minimum date
* @param $max
* unix timestap of maximum date
* @param $default
* unix timestamp of default date
* @param $id
* id and name of datetimepicker (defaults to "datetimepicker")
* @brief Returns a date selector
*
* @param string $format
* Format string, e.g. 'ymd' or 'mdy'. Not currently supported
* @param string $min
* Unix timestamp of minimum date
* @param string $max
* Unix timestap of maximum date
* @param string $default
* Unix timestamp of default date
* @param string $id
* ID and name of datetimepicker (defaults to "datetimepicker")
*
* @return string Parsed HTML output.
*/
if(! function_exists('datesel')) {
function datesel($format, $min, $max, $default, $id = 'datepicker') {
return datetimesel($format,$min,$max,$default,$id,true,false, '','');
}}
}
/**
* returns a time selector
* @param $format
* format string, e.g. 'ymd' or 'mdy'. Not currently supported
* @brief Returns a time selector
*
* @param string $format
* Format string, e.g. 'ymd' or 'mdy'. Not currently supported
* @param $h
* already selected hour
* Already selected hour
* @param $m
* already selected minute
* @param $id
* id and name of datetimepicker (defaults to "timepicker")
* Already selected minute
* @param string $id
* ID and name of datetimepicker (defaults to "timepicker")
*
* @return string Parsed HTML output.
*/
if(! function_exists('timesel')) {
function timesel($format, $h, $m, $id='timepicker') {
return datetimesel($format,new DateTime(),new DateTime(),new DateTime("$h:$m"),$id,false,true);
}}
}
/**
* @brief Returns a datetime selector.
*
* @param $format
* @param string $format
* format string, e.g. 'ymd' or 'mdy'. Not currently supported
* @param $min
* @param string $min
* unix timestamp of minimum date
* @param $max
* @param string $max
* unix timestap of maximum date
* @param $default
* @param string $default
* unix timestamp of default date
* @param string $id
* id and name of datetimepicker (defaults to "datetimepicker")
* @param boolean $pickdate
* @param bool $pickdate
* true to show date picker (default)
* @param boolean $picktime
* true to show time picker (default)
@ -201,17 +244,15 @@ function timesel($format, $h, $m, $id='timepicker') {
* set minimum date from picker with id $minfrom (none by default)
* @param $maxfrom
* set maximum date from picker with id $maxfrom (none by default)
* @param boolean $required default false
* @param bool $required default false
*
* @return string Parsed HTML output.
*
* @todo Once browser support is better this could probably be replaced with
* native HTML5 date picker.
*/
if(! function_exists('datetimesel')) {
function datetimesel($format, $min, $max, $default, $id = 'datetimepicker', $pickdate = true, $picktime = true, $minfrom = '', $maxfrom = '', $required = false) {
$a = get_app();
// First day of the week (0 = Sunday)
$firstDay = get_pconfig(local_user(),'system','first_day_of_week');
if ($firstDay === false) $firstDay=0;
@ -224,43 +265,58 @@ function datetimesel($format, $min, $max, $default, $id = 'datetimepicker', $pic
$o = '';
$dateformat = '';
if($pickdate) $dateformat .= 'Y-m-d';
if($pickdate && $picktime) $dateformat .= ' ';
if($picktime) $dateformat .= 'H:i';
$minjs = $min ? ",minDate: new Date({$min->getTimestamp()}*1000), yearStart: " . $min->format('Y') : '';
$maxjs = $max ? ",maxDate: new Date({$max->getTimestamp()}*1000), yearEnd: " . $max->format('Y') : '';
$input_text = $default ? 'value="' . date($dateformat, $default->getTimestamp()) . '"' : '';
$defaultdatejs = $default ? ",defaultDate: new Date({$default->getTimestamp()}*1000)" : '';
$pickers = '';
if(!$pickdate) $pickers .= ',datepicker: false';
if(!$picktime) $pickers .= ',timepicker: false';
$extra_js = '';
$pickers .= ",dayOfWeekStart: ".$firstDay.",lang:'".$lang."'";
if($minfrom != '')
$extra_js .= "\$('#$minfrom').data('xdsoft_datetimepicker').setOptions({onChangeDateTime: function (currentDateTime) { \$('#$id').data('xdsoft_datetimepicker').setOptions({minDate: currentDateTime})}})";
if($maxfrom != '')
$extra_js .= "\$('#$maxfrom').data('xdsoft_datetimepicker').setOptions({onChangeDateTime: function (currentDateTime) { \$('#$id').data('xdsoft_datetimepicker').setOptions({maxDate: currentDateTime})}})";
$readable_format = $dateformat;
$readable_format = str_replace('Y','yyyy',$readable_format);
$readable_format = str_replace('m','mm',$readable_format);
$readable_format = str_replace('d','dd',$readable_format);
$readable_format = str_replace('H','HH',$readable_format);
$readable_format = str_replace('i','MM',$readable_format);
$o .= "<div class='date'><input type='text' placeholder='$readable_format' name='$id' id='$id' $input_text />";
$o .= '</div>';
$o .= "<script type='text/javascript'>";
$o .= "\$(function () {var picker = \$('#$id').datetimepicker({step:5,format:'$dateformat' $minjs $maxjs $pickers $defaultdatejs}); $extra_js})";
$o .= "</script>";
return $o;
}}
}
// implements "3 seconds ago" etc.
// based on $posted_date, (UTC).
// Results relative to current timezone
// Limited to range of timestamps
if(! function_exists('relative_date')) {
/**
* @brief Returns a relative date string.
*
* Implements "3 seconds ago" etc.
* Based on $posted_date, (UTC).
* Results relative to current timezone.
* Limited to range of timestamps.
*
* @param string $posted_date
* @param string $format (optional) Parsed with sprintf()
* <tt>%1$d %2$s ago</tt>, e.g. 22 hours ago, 1 minute ago
*
* @return string with relative date
*/
function relative_date($posted_date,$format = null) {
$localtime = datetime_convert('UTC',date_default_timezone_get(),$posted_date);
@ -300,23 +356,33 @@ function relative_date($posted_date,$format = null) {
// translators - e.g. 22 hours ago, 1 minute ago
if(! $format)
$format = t('%1$d %2$s ago');
return sprintf( $format,$r, (($r == 1) ? $str[0] : $str[1]));
}
}
}}
// Returns age in years, given a date of birth,
// the timezone of the person whose date of birth is provided,
// and the timezone of the person viewing the result.
// Why? Bear with me. Let's say I live in Mittagong, Australia, and my
// birthday is on New Year's. You live in San Bruno, California.
// When exactly are you going to see my age increase?
// A: 5:00 AM Dec 31 San Bruno time. That's precisely when I start
// celebrating and become a year older. If you wish me happy birthday
// on January 1 (San Bruno time), you'll be a day late.
}
}
}
/**
* @brief Returns timezone correct age in years.
*
* Returns the age in years, given a date of birth, the timezone of the person
* whose date of birth is provided, and the timezone of the person viewing the
* result.
*
* Why? Bear with me. Let's say I live in Mittagong, Australia, and my birthday
* is on New Year's. You live in San Bruno, California.
* When exactly are you going to see my age increase?
*
* A: 5:00 AM Dec 31 San Bruno time. That's precisely when I start celebrating
* and become a year older. If you wish me happy birthday on January 1
* (San Bruno time), you'll be a day late.
*
* @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 = '') {
if(! intval($dob))
return 0;
@ -333,64 +399,79 @@ function age($dob,$owner_tz = '',$viewer_tz = '') {
if(($curr_month < $month) || (($curr_month == $month) && ($curr_day < $day)))
$year_diff--;
return $year_diff;
}
// Get days in month
// get_dim($year, $month);
// returns number of days.
// $month[1] = 'January';
// to match human usage.
if(! function_exists('get_dim')) {
/**
* @brief Get days of a month in a given year.
*
* Returns number of days in the month of the given year.
* $m = 1 is 'January' to match human usage.
*
* @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) {
$dim = array( 0,
31, 28, 31, 30, 31, 30,
31, 31, 30, 31, 30, 31);
if($m != 2)
return $dim[$m];
if(((($y % 4) == 0) && (($y % 100) != 0)) || (($y % 400) == 0))
return 29;
return $dim[2];
}}
$dim = array( 0,
31, 28, 31, 30, 31, 30,
31, 31, 30, 31, 30, 31);
if($m != 2)
return $dim[$m];
// Returns the first day in month for a given month, year
// get_first_dim($year,$month)
// returns 0 = Sunday through 6 = Saturday
// Months start at 1.
if(((($y % 4) == 0) && (($y % 100) != 0)) || (($y % 400) == 0))
return 29;
if(! function_exists('get_first_dim')) {
return $dim[2];
}
/**
* @brief Returns the first day in month for a given month, year.
*
* Months start at 1.
*
* @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) {
$d = sprintf('%04d-%02d-01 00:00', intval($y), intval($m));
return datetime_convert('UTC','UTC',$d,'w');
}}
$d = sprintf('%04d-%02d-01 00:00', intval($y), intval($m));
// output a calendar for the given month, year.
// if $links are provided (array), e.g. $links[12] => 'http://mylink' ,
// date 12 will be linked appropriately. Today's date is also noted by
// altering td class.
// Months count from 1.
return datetime_convert('UTC','UTC',$d,'w');
}
/// @TODO Provide (prev,next) links, define class variations for different size calendars
if(! function_exists('cal')) {
/**
* @brief Output a calendar for the given month, year.
*
* If $links are provided (array), e.g. $links[12] => 'http://mylink' ,
* date 12 will be linked appropriately. Today's date is also noted by
* altering td class.
* Months count from 1.
*
* @param int $y Year
* @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
*/
function cal($y = 0,$m = 0, $links = false, $class='') {
// month table - start at 1 to match human usage.
$mtab = array(' ',
'January','February','March',
'April','May','June',
'July','August','September',
'October','November','December'
'January','February','March',
'April','May','June',
'July','August','September',
'October','November','December'
);
$thisyear = datetime_convert('UTC',date_default_timezone_get(),'now','Y');
@ -400,54 +481,63 @@ function cal($y = 0,$m = 0, $links = false, $class='') {
if(! $m)
$m = intval($thismonth);
$dn = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
$f = get_first_dim($y,$m);
$l = get_dim($y,$m);
$d = 1;
$dow = 0;
$started = false;
$dn = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
$f = get_first_dim($y,$m);
$l = get_dim($y,$m);
$d = 1;
$dow = 0;
$started = false;
if(($y == $thisyear) && ($m == $thismonth))
$tddate = intval(datetime_convert('UTC',date_default_timezone_get(),'now','j'));
if(($y == $thisyear) && ($m == $thismonth))
$tddate = intval(datetime_convert('UTC',date_default_timezone_get(),'now','j'));
$str_month = day_translate($mtab[$m]);
$o = '<table class="calendar' . $class . '">';
$o .= "<caption>$str_month $y</caption><tr>";
for($a = 0; $a < 7; $a ++)
$o .= '<th>' . mb_substr(day_translate($dn[$a]),0,3,'UTF-8') . '</th>';
$o .= '</tr><tr>';
$o = '<table class="calendar' . $class . '">';
$o .= "<caption>$str_month $y</caption><tr>";
for($a = 0; $a < 7; $a ++)
$o .= '<th>' . mb_substr(day_translate($dn[$a]),0,3,'UTF-8') . '</th>';
while($d <= $l) {
if(($dow == $f) && (! $started))
$started = true;
$today = (((isset($tddate)) && ($tddate == $d)) ? "class=\"today\" " : '');
$o .= "<td $today>";
$day = str_replace(' ','&nbsp;',sprintf('%2.2d', $d));
if($started) {
if(is_array($links) && isset($links[$d]))
$o .= "<a href=\"{$links[$d]}\">$day</a>";
else
$o .= $day;
$d ++;
}
else
$o .= '&nbsp;';
$o .= '</td>';
$dow ++;
if(($dow == 7) && ($d <= $l)) {
$dow = 0;
$o .= '</tr><tr>';
}
}
if($dow)
for($a = $dow; $a < 7; $a ++)
$o .= '<td>&nbsp;</td>';
$o .= '</tr></table>'."\r\n";
$o .= '</tr><tr>';
return $o;
}}
while($d <= $l) {
if(($dow == $f) && (! $started))
$started = true;
$today = (((isset($tddate)) && ($tddate == $d)) ? "class=\"today\" " : '');
$o .= "<td $today>";
$day = str_replace(' ','&nbsp;',sprintf('%2.2d', $d));
if($started) {
if(is_array($links) && isset($links[$d]))
$o .= "<a href=\"{$links[$d]}\">$day</a>";
else
$o .= $day;
$d ++;
} else {
$o .= '&nbsp;';
}
$o .= '</td>';
$dow ++;
if(($dow == 7) && ($d <= $l)) {
$dow = 0;
$o .= '</tr><tr>';
}
}
if($dow)
for($a = $dow; $a < 7; $a ++)
$o .= '<td>&nbsp;</td>';
$o .= '</tr></table>'."\r\n";
return $o;
}
/**
* @brief Create a birthday event.
*
* Update the year and the birthday.
*/
function update_contact_birthdays() {
// This only handles foreign or alien networks where a birthday has been provided.
@ -474,8 +564,6 @@ function update_contact_birthdays() {
$bdtext = sprintf( t('%s\'s birthday'), $rr['name']);
$bdtext2 = sprintf( t('Happy Birthday %s'), ' [url=' . $rr['url'] . ']' . $rr['name'] . '[/url]') ;
$r = q("INSERT INTO `event` (`uid`,`cid`,`created`,`edited`,`start`,`finish`,`summary`,`desc`,`type`,`adjust`)
VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d' ) ",
intval($rr['uid']),

View File

@ -453,6 +453,7 @@ function db_definition() {
"keywords" => array("type" => "text", "not null" => "1"),
"gender" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
"attag" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"avatar" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"photo" => array("type" => "text", "not null" => "1"),
"thumb" => array("type" => "text", "not null" => "1"),
"micro" => array("type" => "text", "not null" => "1"),
@ -666,9 +667,14 @@ function db_definition() {
"about" => array("type" => "text", "not null" => "1"),
"keywords" => array("type" => "text", "not null" => "1"),
"gender" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
"birthday" => array("type" => "varchar(32)", "not null" => "1", "default" => "0000-00-00"),
"community" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
"hide" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
"nsfw" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
"network" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"addr" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"notify" => array("type" => "text", "not null" => "1"),
"alias" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"generation" => array("type" => "tinyint(3)", "not null" => "1", "default" => "0"),
"server_url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
),
@ -742,21 +748,6 @@ function db_definition() {
"nurl" => array("nurl"),
)
);
$database["guid"] = array(
"fields" => array(
"id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"guid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"plink" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
),
"indexes" => array(
"PRIMARY" => array("id"),
"guid" => array("guid"),
"plink" => array("plink"),
"uri" => array("uri"),
)
);
$database["hook"] = array(
"fields" => array(
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
@ -795,6 +786,7 @@ function db_definition() {
"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"),
"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"),
@ -871,6 +863,7 @@ function db_definition() {
"uid_thrparent" => array("uid","thr-parent"),
"uid_parenturi" => array("uid","parent-uri"),
"uid_contactid_created" => array("uid","contact-id","created"),
"gcontactid_uid_created" => array("gcontact-id","uid","created"),
"wall_body" => array("wall","body(6)"),
"uid_visible_moderated_created" => array("uid","visible","moderated","created"),
"uid_uri" => array("uid","uri"),
@ -1014,6 +1007,30 @@ function db_definition() {
"receiver-uid" => array("receiver-uid"),
)
);
$database["oembed"] = array(
"fields" => array(
"url" => array("type" => "varchar(255)", "not null" => "1", "primary" => "1"),
"content" => array("type" => "text", "not null" => "1"),
"created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
),
"indexes" => array(
"PRIMARY" => array("url"),
"created" => array("created"),
)
);
$database["parsed_url"] = array(
"fields" => array(
"url" => array("type" => "varchar(255)", "not null" => "1", "primary" => "1"),
"guessing" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0", "primary" => "1"),
"oembed" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0", "primary" => "1"),
"content" => array("type" => "text", "not null" => "1"),
"created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
),
"indexes" => array(
"PRIMARY" => array("url", "guessing", "oembed"),
"created" => array("created"),
)
);
$database["pconfig"] = array(
"fields" => array(
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
@ -1287,6 +1304,7 @@ function db_definition() {
"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"),
"created" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
"edited" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
"commented" => array("type" => "datetime", "not null" => "1", "default" => "0000-00-00 00:00:00"),
@ -1316,6 +1334,8 @@ 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"),
"uid_gcontactid_commented" => array("uid","gcontact-id","commented"),
"uid_gcontactid_created" => array("uid","gcontact-id","created"),
"wall_private_received" => array("wall","private","received"),
"uid_created" => array("uid","created"),
"uid_commented" => array("uid","commented"),
@ -1334,21 +1354,6 @@ function db_definition() {
"PRIMARY" => array("id"),
)
);
$database["unique_contacts"] = array(
"fields" => array(
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"nick" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"avatar" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"location" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"about" => array("type" => "text", "not null" => "1"),
),
"indexes" => array(
"PRIMARY" => array("id"),
"url" => array("url"),
)
);
$database["user"] = array(
"fields" => array(
"uid" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),

View File

@ -5,6 +5,7 @@ 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");
function delivery_run(&$argv, &$argc){
global $a, $db;
@ -264,8 +265,6 @@ function delivery_run(&$argv, &$argc){
if(count($r))
$contact = $r[0];
$hubxml = feed_hublinks();
if($contact['self'])
continue;
@ -278,138 +277,54 @@ function delivery_run(&$argv, &$argc){
case NETWORK_DFRN:
logger('notifier: '.$target_item["guid"].' dfrndelivery: ' . $contact['name']);
$feed_template = get_markup_template('atom_feed.tpl');
$mail_template = get_markup_template('atom_mail.tpl');
$atom = '';
$birthday = feed_birthday($owner['uid'],$owner['timezone']);
if(strlen($birthday))
$birthday = '<dfrn:birthday>' . xmlify($birthday) . '</dfrn:birthday>';
$atom .= replace_macros($feed_template, array(
'$version' => xmlify(FRIENDICA_VERSION),
'$feed_id' => xmlify($a->get_baseurl() . '/profile/' . $owner['nickname'] ),
'$feed_title' => xmlify($owner['name']),
'$feed_updated' => xmlify(datetime_convert('UTC', 'UTC', $updated . '+00:00' , ATOM_TIME)) ,
'$hub' => $hubxml,
'$salmon' => '', // private feed, we don't use salmon here
'$name' => xmlify($owner['name']),
'$profile_page' => xmlify($owner['url']),
'$photo' => xmlify($owner['photo']),
'$thumb' => xmlify($owner['thumb']),
'$picdate' => xmlify(datetime_convert('UTC','UTC',$owner['avatar-date'] . '+00:00' , ATOM_TIME)) ,
'$uridate' => xmlify(datetime_convert('UTC','UTC',$owner['uri-date'] . '+00:00' , ATOM_TIME)) ,
'$namdate' => xmlify(datetime_convert('UTC','UTC',$owner['name-date'] . '+00:00' , ATOM_TIME)) ,
'$birthday' => $birthday,
'$community' => (($owner['page-flags'] == PAGE_COMMUNITY) ? '<dfrn:community>1</dfrn:community>' : '')
));
if($mail) {
$public_message = false; // mail is not public
$body = fix_private_photos($item['body'],$owner['uid'],null,$message[0]['contact-id']);
$atom .= replace_macros($mail_template, array(
'$name' => xmlify($owner['name']),
'$profile_page' => xmlify($owner['url']),
'$thumb' => xmlify($owner['thumb']),
'$item_id' => xmlify($item['uri']),
'$subject' => xmlify($item['title']),
'$created' => xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00' , ATOM_TIME)),
'$content' => xmlify($body),
'$parent_id' => xmlify($item['parent-uri'])
));
} elseif($fsuggest) {
$public_message = false; // suggestions are not public
$sugg_template = get_markup_template('atom_suggest.tpl');
$atom .= replace_macros($sugg_template, array(
'$name' => xmlify($item['name']),
'$url' => xmlify($item['url']),
'$photo' => xmlify($item['photo']),
'$request' => xmlify($item['request']),
'$note' => xmlify($item['note'])
));
// We don't need this any more
q("DELETE FROM `fsuggest` WHERE `id` = %d LIMIT 1",
intval($item['id'])
);
} elseif($relocate) {
$public_message = false; // suggestions are not public
$sugg_template = get_markup_template('atom_relocate.tpl');
/* get site pubkey. this could be a new installation with no site keys*/
$pubkey = get_config('system','site_pubkey');
if(! $pubkey) {
$res = new_keypair(1024);
set_config('system','site_prvkey', $res['prvkey']);
set_config('system','site_pubkey', $res['pubkey']);
}
$rp = q("SELECT `resource-id` , `scale`, type FROM `photo`
WHERE `profile` = 1 AND `uid` = %d ORDER BY scale;", $uid);
$photos = array();
$ext = Photo::supportedTypes();
foreach($rp as $p){
$photos[$p['scale']] = $a->get_baseurl().'/photo/'.$p['resource-id'].'-'.$p['scale'].'.'.$ext[$p['type']];
}
unset($rp, $ext);
$atom .= replace_macros($sugg_template, array(
'$name' => xmlify($owner['name']),
'$photo' => xmlify($photos[4]),
'$thumb' => xmlify($photos[5]),
'$micro' => xmlify($photos[6]),
'$url' => xmlify($owner['url']),
'$request' => xmlify($owner['request']),
'$confirm' => xmlify($owner['confirm']),
'$notify' => xmlify($owner['notify']),
'$poll' => xmlify($owner['poll']),
'$sitepubkey' => xmlify(get_config('system','site_pubkey')),
//'$pubkey' => xmlify($owner['pubkey']),
//'$prvkey' => xmlify($owner['prvkey']),
));
unset($photos);
} elseif($followup) {
if ($mail) {
$item['body'] = fix_private_photos($item['body'],$owner['uid'],null,$message[0]['contact-id']);
$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);
elseif($followup) {
$msgitems = array();
foreach($items as $item) { // there is only one item
if(! $item['parent'])
if(!$item['parent'])
continue;
if($item['id'] == $item_id) {
logger('followup: item: ' . print_r($item,true), LOGGER_DATA);
$atom .= atom_entry($item,'text',null,$owner,false);
$msgitems[] = $item;
}
}
$atom = dfrn::entries($msgitems,$owner);
} else {
$msgitems = array();
foreach($items as $item) {
if(! $item['parent'])
if(!$item['parent'])
continue;
// private emails may be in included in public conversations. Filter them.
if(($public_message) && $item['private'] == 1)
if(($public_message) && $item['private'])
continue;
$item_contact = get_item_contact($item,$icontacts);
if(! $item_contact)
if(!$item_contact)
continue;
if($normal_mode) {
if($item_id == $item['id'] || $item['id'] == $item['parent'])
$atom .= atom_entry($item,'text',null,$owner,true,(($top_level) ? $contact['id'] : 0));
} else
$atom .= atom_entry($item,'text',null,$owner,true);
if($item_id == $item['id'] || $item['id'] == $item['parent']) {
$item["entry:comment-allow"] = true;
$item["entry:cid"] = (($top_level) ? $contact['id'] : 0);
$msgitems[] = $item;
}
} else {
$item["entry:comment-allow"] = true;
$msgitems[] = $item;
}
}
$atom = dfrn::entries($msgitems,$owner);
}
$atom .= '</feed>' . "\r\n";
logger('notifier: '.$contact["url"].' '.$target_item["guid"].' entry: '.$atom, LOGGER_DEBUG);
logger('notifier entry: '.$contact["url"].' '.$target_item["guid"].' entry: '.$atom, LOGGER_DEBUG);
logger('notifier: ' . $atom, LOGGER_DATA);
$basepath = implode('/', array_slice(explode('/',$contact['url']),0,3));
@ -458,15 +373,14 @@ function delivery_run(&$argv, &$argc){
if (($x[0]['page-flags'] == PAGE_SOAPBOX) AND $top_level)
break;
require_once('library/simplepie/simplepie.inc');
logger('mod-delivery: local delivery');
local_delivery($x[0],$atom);
dfrn::import($atom, $x[0]);
break;
}
}
if(! was_recently_delayed($contact['id']))
$deliver_status = dfrn_deliver($owner,$contact,$atom);
$deliver_status = dfrn::deliver($owner,$contact,$atom);
else
$deliver_status = (-1);

2422
include/dfrn.php Normal file

File diff suppressed because it is too large Load Diff

View File

@ -14,6 +14,7 @@ require_once('include/queue_fn.php');
require_once('include/lock.php');
require_once('include/threads.php');
require_once('mod/share.php');
require_once('include/enotify.php');
function diaspora_dispatch_public($msg) {
@ -728,7 +729,7 @@ function diaspora_request($importer,$xml) {
require_once('include/Photo.php');
$photos = import_profile_photo($contact_record['photo'],$importer['uid'],$contact_record['id']);
update_contact_avatar($contact_record['photo'],$importer['uid'],$contact_record['id']);
// technically they are sharing with us (CONTACT_IS_SHARING),
// but if our page-type is PAGE_COMMUNITY or PAGE_SOAPBOX
@ -739,26 +740,17 @@ function diaspora_request($importer,$xml) {
else
$new_relation = CONTACT_IS_FOLLOWER;
$r = q("UPDATE `contact` SET
`photo` = '%s',
`thumb` = '%s',
`micro` = '%s',
`rel` = %d,
$r = q("UPDATE `contact` SET `rel` = %d,
`name-date` = '%s',
`uri-date` = '%s',
`avatar-date` = '%s',
`blocked` = 0,
`pending` = 0,
`writable` = 1
WHERE `id` = %d
",
dbesc($photos[0]),
dbesc($photos[1]),
dbesc($photos[2]),
intval($new_relation),
dbesc(datetime_convert()),
dbesc(datetime_convert()),
dbesc(datetime_convert()),
intval($contact_record['id'])
);
@ -826,6 +818,23 @@ function diaspora_plink($addr, $guid) {
return 'https://'.substr($addr,strpos($addr,'@')+1).'/posts/'.$guid;
}
function diaspora_repair_signature($signature, $handle = "", $level = 1) {
if ($signature == "")
return($signature);
if (base64_encode(base64_decode(base64_decode($signature))) == base64_decode($signature)) {
$signature = base64_decode($signature);
logger("Repaired double encoded signature from Diaspora/Hubzilla handle ".$handle." - level ".$level, LOGGER_DEBUG);
// Do a recursive call to be able to fix even multiple levels
if ($level < 10)
$signature = diaspora_repair_signature($signature, $handle, ++$level);
}
return($signature);
}
function diaspora_post($importer,$xml,$msg) {
$a = get_app();
@ -1565,62 +1574,22 @@ function diaspora_comment($importer,$xml,$msg) {
//);
//}
if(($parent_item['origin']) && (! $parent_author_signature)) {
// If we are the origin of the parent we store the original signature and notify our followers
if($parent_item['origin']) {
$author_signature_base64 = base64_encode($author_signature);
$author_signature_base64 = diaspora_repair_signature($author_signature_base64, $diaspora_handle);
q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ",
intval($message_id),
dbesc($signed_data),
dbesc(base64_encode($author_signature)),
dbesc($author_signature_base64),
dbesc($diaspora_handle)
);
// if the message isn't already being relayed, notify others
// the existence of parent_author_signature means the parent_author or owner
// is already relaying.
// notify others
proc_run('php','include/notifier.php','comment-import',$message_id);
}
$myconv = q("SELECT `author-link`, `author-avatar`, `parent` FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d AND `parent` != 0 AND `deleted` = 0 ",
dbesc($parent_item['uri']),
intval($importer['uid'])
);
if(count($myconv)) {
$importer_url = $a->get_baseurl() . '/profile/' . $importer['nickname'];
foreach($myconv as $conv) {
// now if we find a match, it means we're in this conversation
if(! link_compare($conv['author-link'],$importer_url))
continue;
require_once('include/enotify.php');
$conv_parent = $conv['parent'];
notification(array(
'type' => NOTIFY_COMMENT,
'notify_flags' => $importer['notify-flags'],
'language' => $importer['language'],
'to_name' => $importer['username'],
'to_email' => $importer['email'],
'uid' => $importer['uid'],
'item' => $datarray,
'link' => $a->get_baseurl().'/display/'.urlencode($datarray['guid']),
'source_name' => $datarray['author-name'],
'source_link' => $datarray['author-link'],
'source_photo' => $datarray['author-avatar'],
'verb' => ACTIVITY_POST,
'otype' => 'item',
'parent' => $conv_parent,
'parent_uri' => $parent_uri
));
// only send one notification
break;
}
}
return;
}
@ -1775,7 +1744,6 @@ function diaspora_conversation($importer,$xml,$msg) {
intval($conversation['id'])
);
require_once('include/enotify.php');
notification(array(
'type' => NOTIFY_MAIL,
'notify_flags' => $importer['notify-flags'],
@ -1973,11 +1941,15 @@ function diaspora_photo($importer,$xml,$msg,$attempt=1) {
array($remote_photo_name, 'scaled_full_' . $remote_photo_name));
if(strpos($parent_item['body'],$link_text) === false) {
$parent_item['body'] = $link_text . $parent_item['body'];
$r = q("UPDATE `item` SET `body` = '%s', `visible` = 1 WHERE `id` = %d AND `uid` = %d",
dbesc($link_text . $parent_item['body']),
dbesc($parent_item['body']),
intval($parent_item['id']),
intval($parent_item['uid'])
);
put_item_in_cache($parent_item, true);
update_thread($parent_item['id']);
}
@ -2222,21 +2194,21 @@ EOT;
// );
//}
if(! $parent_author_signature) {
// If we are the origin of the parent we store the original signature and notify our followers
if($parent_item['origin']) {
$author_signature_base64 = base64_encode($author_signature);
$author_signature_base64 = diaspora_repair_signature($author_signature_base64, $diaspora_handle);
q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ",
intval($message_id),
dbesc($signed_data),
dbesc(base64_encode($author_signature)),
dbesc($author_signature_base64),
dbesc($diaspora_handle)
);
}
// if the message isn't already being relayed, notify others
// the existence of parent_author_signature means the parent_author or owner
// is already relaying. The parent_item['origin'] indicates the message was created on our system
if(($parent_item['origin']) && (! $parent_author_signature))
// notify others
proc_run('php','include/notifier.php','comment-import',$message_id);
}
return;
}
@ -2332,8 +2304,7 @@ function diaspora_signed_retraction($importer,$xml,$msg) {
return;
}
}
else {
} else {
$sig_decode = base64_decode($sig);
@ -2367,7 +2338,7 @@ function diaspora_signed_retraction($importer,$xml,$msg) {
intval($r[0]['parent'])
);
if(count($p)) {
if(($p[0]['origin']) && (! $parent_author_signature)) {
if($p[0]['origin']) {
q("insert into sign (`retract_iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ",
$r[0]['id'],
dbesc($signed_data),
@ -2407,10 +2378,10 @@ function diaspora_profile($importer,$xml,$msg) {
if(! $contact)
return;
if($contact['blocked']) {
logger('diaspora_post: Ignoring this author.');
return 202;
}
//if($contact['blocked']) {
// logger('diaspora_post: Ignoring this author.');
// return 202;
//}
$name = unxmlify($xml->first_name) . ((strlen($xml->last_name)) ? ' ' . unxmlify($xml->last_name) : '');
$image_url = unxmlify($xml->image_url);
@ -2418,6 +2389,8 @@ function diaspora_profile($importer,$xml,$msg) {
$location = diaspora2bb(unxmlify($xml->location));
$about = diaspora2bb(unxmlify($xml->bio));
$gender = unxmlify($xml->gender);
$searchable = (unxmlify($xml->searchable) == "true");
$nsfw = (unxmlify($xml->nsfw) == "true");
$tags = unxmlify($xml->tag_string);
$tags = explode("#", $tags);
@ -2432,6 +2405,8 @@ function diaspora_profile($importer,$xml,$msg) {
$keywords = implode(", ", $keywords);
$handle_parts = explode("@", $diaspora_handle);
$nick = $handle_parts[0];
if($name === '') {
$name = $handle_parts[0];
}
@ -2448,7 +2423,7 @@ function diaspora_profile($importer,$xml,$msg) {
require_once('include/Photo.php');
$images = import_profile_photo($image_url,$importer['uid'],$contact['id']);
update_contact_avatar($image_url,$importer['uid'],$contact['id']);
// Generic birthday. We don't know the timezone. The year is irrelevant.
@ -2466,12 +2441,11 @@ function diaspora_profile($importer,$xml,$msg) {
/// @TODO Update name on item['author-name'] if the name changed. See consume_feed()
/// (Not doing this currently because D* protocol is scheduled for revision soon).
$r = q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' , `bd` = '%s', `location` = '%s', `about` = '%s', `keywords` = '%s', `gender` = '%s' WHERE `id` = %d AND `uid` = %d",
$r = q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `addr` = '%s', `name-date` = '%s', `bd` = '%s',
`location` = '%s', `about` = '%s', `keywords` = '%s', `gender` = '%s' WHERE `id` = %d AND `uid` = %d",
dbesc($name),
dbesc(datetime_convert()),
dbesc($images[0]),
dbesc($images[1]),
dbesc($images[2]),
dbesc($nick),
dbesc($diaspora_handle),
dbesc(datetime_convert()),
dbesc($birthday),
dbesc($location),
@ -2482,26 +2456,17 @@ function diaspora_profile($importer,$xml,$msg) {
intval($importer['uid'])
);
if (unxmlify($xml->searchable) == "true") {
if ($searchable) {
require_once('include/socgraph.php');
poco_check($contact['url'], $name, NETWORK_DIASPORA, $images[0], $about, $location, $gender, $keywords, "",
poco_check($contact['url'], $name, NETWORK_DIASPORA, $image_url, $about, $location, $gender, $keywords, "",
datetime_convert(), 2, $contact['id'], $importer['uid']);
}
$profileurl = "";
$author = q("SELECT * FROM `unique_contacts` WHERE `url`='%s' LIMIT 1",
dbesc(normalise_link($contact['url'])));
if (count($author) == 0) {
q("INSERT INTO `unique_contacts` (`url`, `name`, `avatar`, `location`, `about`) VALUES ('%s', '%s', '%s', '%s', '%s')",
dbesc(normalise_link($contact['url'])), dbesc($name), dbesc($location), dbesc($about), dbesc($images[0]));
$author = q("SELECT id FROM unique_contacts WHERE url='%s' LIMIT 1",
dbesc(normalise_link($contact['url'])));
} else if (normalise_link($contact['url']).$name.$location.$about != normalise_link($author[0]["url"]).$author[0]["name"].$author[0]["location"].$author[0]["about"]) {
q("UPDATE unique_contacts SET name = '%s', avatar = '%s', `location` = '%s', `about` = '%s' WHERE url = '%s'",
dbesc($name), dbesc($images[0]), dbesc($location), dbesc($about), dbesc(normalise_link($contact['url'])));
}
update_gcontact(array("url" => $contact['url'], "network" => NETWORK_DIASPORA, "generation" => 2,
"photo" => $image_url, "name" => $name, "location" => $location,
"about" => $about, "birthday" => $birthday, "gender" => $gender,
"addr" => $diaspora_handle, "nick" => $nick, "keywords" => $keywords,
"hide" => !$searchable, "nsfw" => $nsfw));
/* if($r) {
if($oldphotos) {
@ -2643,11 +2608,12 @@ function diaspora_send_status($item,$owner,$contact,$public_batch = false) {
}
logger('diaspora_send_status: '.$owner['username'].' -> '.$contact['name'].' base message: '.$msg, LOGGER_DATA);
logger('send guid '.$item['guid'], LOGGER_DEBUG);
$slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch)));
//$slap = 'xml=' . urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch));
$return_code = diaspora_transmit($owner,$contact,$slap,$public_batch);
$return_code = diaspora_transmit($owner,$contact,$slap,$public_batch,false,$item['guid']);
logger('diaspora_send_status: guid: '.$item['guid'].' result '.$return_code, LOGGER_DEBUG);
@ -2758,10 +2724,12 @@ function diaspora_send_images($item,$owner,$contact,$images,$public_batch = fals
logger('diaspora_send_photo: base message: ' . $msg, LOGGER_DATA);
logger('send guid '.$r[0]['guid'], LOGGER_DEBUG);
$slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch)));
//$slap = 'xml=' . urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch));
diaspora_transmit($owner,$contact,$slap,$public_batch);
diaspora_transmit($owner,$contact,$slap,$public_batch,false,$r[0]['guid']);
}
}
@ -2815,7 +2783,7 @@ function diaspora_send_followup($item,$owner,$contact,$public_batch = false) {
// sign it
if($like)
$signed_text = $item['guid'] . ';' . $target_type . ';' . $parent['guid'] . ';' . $positive . ';' . $myaddr;
$signed_text = $positive . ';' . $item['guid'] . ';' . $target_type . ';' . $parent['guid'] . ';' . $myaddr;
else
$signed_text = $item['guid'] . ';' . $parent['guid'] . ';' . $text . ';' . $myaddr;
@ -2832,11 +2800,12 @@ function diaspora_send_followup($item,$owner,$contact,$public_batch = false) {
));
logger('diaspora_followup: base message: ' . $msg, LOGGER_DATA);
logger('send guid '.$item['guid'], LOGGER_DEBUG);
$slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch)));
//$slap = 'xml=' . urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch));
return(diaspora_transmit($owner,$contact,$slap,$public_batch));
return(diaspora_transmit($owner,$contact,$slap,$public_batch,false,$item['guid']));
}
@ -2847,9 +2816,6 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) {
$myaddr = $owner['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);
// $theiraddr = $contact['addr'];
$body = $item['body'];
$text = html_entity_decode(bb2diaspora($body));
// Diaspora doesn't support threaded comments, but some
// versions of Diaspora (i.e. Diaspora-pistos) support
// likes on comments
@ -2900,61 +2866,53 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) {
// fetch the original signature if the relayable was created by a Diaspora
// or DFRN user. Relayables for other networks are not supported.
/* $r = q("select * from sign where " . $sql_sign_id . " = %d limit 1",
$r = q("SELECT `signed_text`, `signature`, `signer` FROM `sign` WHERE " . $sql_sign_id . " = %d LIMIT 1",
intval($item['id'])
);
if(count($r)) {
if(count($r)) {
$orig_sign = $r[0];
$signed_text = $orig_sign['signed_text'];
$authorsig = $orig_sign['signature'];
$handle = $orig_sign['signer'];
// Split the signed text
$signed_parts = explode(";", $signed_text);
// Remove the parent guid
array_shift($signed_parts);
// Remove the comment guid
array_shift($signed_parts);
// Remove the handle
array_pop($signed_parts);
// Glue the parts together
$text = implode(";", $signed_parts);
}
else {
// This part is meant for cases where we don't have the signatur. (Which shouldn't happen with posts from Diaspora and Friendica)
// This means that the comment won't be accepted by newer Diaspora servers
// Author signature information (for likes, comments, and retractions of likes or comments,
// whether from Diaspora or Friendica) must be placed in the `sign` table before this
// function is called
logger('diaspora_send_relay: original author signature not found, cannot send relayable');
return;
}*/
$body = $item['body'];
$text = html_entity_decode(bb2diaspora($body));
/* Since the author signature is only checked by the parent, not by the relay recipients,
* I think it may not be necessary for us to do so much work to preserve all the original
* signatures. The important thing that Diaspora DOES need is the original creator's handle.
* Let's just generate that and forget about all the original author signature stuff.
*
* Note: this might be more of an problem if we want to support likes on comments for older
* versions of Diaspora (diaspora-pistos), but since there are a number of problems with
* doing that, let's ignore it for now.
*
* Currently, only DFRN contacts are supported. StatusNet shouldn't be hard, but it hasn't
* been done yet
*/
$handle = diaspora_handle_from_contact($item['contact-id']);
if(! $handle)
return;
$handle = diaspora_handle_from_contact($item['contact-id']);
if(! $handle)
return;
if($relay_retract)
$signed_text = $item['guid'] . ';' . $target_type;
elseif($like)
$signed_text = $item['guid'] . ';' . $target_type . ';' . $parent['guid'] . ';' . $positive . ';' . $handle;
else
$signed_text = $item['guid'] . ';' . $parent['guid'] . ';' . $text . ';' . $handle;
if($relay_retract)
$sender_signed_text = $item['guid'] . ';' . $target_type;
elseif($like)
$sender_signed_text = $item['guid'] . ';' . $target_type . ';' . $parent['guid'] . ';' . $positive . ';' . $handle;
else
$sender_signed_text = $item['guid'] . ';' . $parent['guid'] . ';' . $text . ';' . $handle;
$authorsig = base64_encode(rsa_sign($signed_text,$owner['uprvkey'],'sha256'));
}
// Sign the relayable with the top-level owner's signature
//
// We'll use the $sender_signed_text that we just created, instead of the $signed_text
// stored in the database, because that provides the best chance that Diaspora will
// be able to reconstruct the signed text the same way we did. This is particularly a
// concern for the comment, whose signed text includes the text of the comment. The
// smallest change in the text of the comment, including removing whitespace, will
// make the signature verification fail. Since we translate from BB code to Diaspora's
// markup at the top of this function, which is AFTER we placed the original $signed_text
// in the database, it's hazardous to trust the original $signed_text.
$parentauthorsig = base64_encode(rsa_sign($sender_signed_text,$owner['uprvkey'],'sha256'));
$parentauthorsig = base64_encode(rsa_sign($signed_text,$owner['uprvkey'],'sha256'));
$msg = replace_macros($tpl,array(
'$guid' => xmlify($item['guid']),
@ -2968,12 +2926,12 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) {
));
logger('diaspora_send_relay: base message: ' . $msg, LOGGER_DATA);
logger('send guid '.$item['guid'], LOGGER_DEBUG);
$slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch)));
//$slap = 'xml=' . urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch));
return(diaspora_transmit($owner,$contact,$slap,$public_batch));
return(diaspora_transmit($owner,$contact,$slap,$public_batch,false,$item['guid']));
}
@ -3005,10 +2963,12 @@ function diaspora_send_retraction($item,$owner,$contact,$public_batch = false) {
'$signature' => xmlify(base64_encode(rsa_sign($signed_text,$owner['uprvkey'],'sha256')))
));
logger('send guid '.$item['guid'], LOGGER_DEBUG);
$slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch)));
//$slap = 'xml=' . urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch));
return(diaspora_transmit($owner,$contact,$slap,$public_batch));
return(diaspora_transmit($owner,$contact,$slap,$public_batch,false,$item['guid']));
}
function diaspora_send_mail($item,$owner,$contact) {
@ -3065,16 +3025,17 @@ function diaspora_send_mail($item,$owner,$contact) {
}
logger('diaspora_conversation: ' . print_r($xmsg,true), LOGGER_DATA);
logger('send guid '.$item['guid'], LOGGER_DEBUG);
$slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($xmsg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],false)));
//$slap = 'xml=' . urlencode(diaspora_msg_build($xmsg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],false));
return(diaspora_transmit($owner,$contact,$slap,false));
return(diaspora_transmit($owner,$contact,$slap,false,false,$item['guid']));
}
function diaspora_transmit($owner,$contact,$slap,$public_batch,$queue_run=false) {
function diaspora_transmit($owner,$contact,$slap,$public_batch,$queue_run=false,$guid = "") {
$enabled = intval(get_config('system','diaspora_enabled'));
if(! $enabled) {
@ -3087,9 +3048,9 @@ function diaspora_transmit($owner,$contact,$slap,$public_batch,$queue_run=false)
if(! $dest_url) {
logger('diaspora_transmit: no url for contact: ' . $contact['id'] . ' batch mode =' . $public_batch);
return 0;
}
}
logger('diaspora_transmit: ' . $logid . ' ' . $dest_url);
logger('diaspora_transmit: '.$logid.'-'.$guid.' '.$dest_url);
if( (! $queue_run) && (was_recently_delayed($contact['id'])) ) {
$return_code = 0;
@ -3104,7 +3065,7 @@ function diaspora_transmit($owner,$contact,$slap,$public_batch,$queue_run=false)
}
}
logger('diaspora_transmit: ' . $logid . ' returns: ' . $return_code);
logger('diaspora_transmit: '.$logid.'-'.$guid.' returns: '.$return_code);
if((! $return_code) || (($return_code == 503) && (stristr($a->get_curl_headers(),'retry-after')))) {
logger('diaspora_transmit: queue message');

View File

@ -76,11 +76,18 @@ function discover_poco_run(&$argv, &$argc){
update_suggestions();
elseif (($mode == 2) AND get_config('system','poco_completion'))
discover_users();
elseif (($mode == 1) AND ($search != "") and get_config('system','poco_local_search'))
elseif (($mode == 1) AND ($search != "") and get_config('system','poco_local_search')) {
discover_directory($search);
elseif (($mode == 0) AND ($search == "") and (get_config('system','poco_discovery') > 0))
gs_search_user($search);
} elseif (($mode == 0) AND ($search == "") and (get_config('system','poco_discovery') > 0)) {
// Query Friendica and Hubzilla servers for their users
poco_discover();
// Query GNU Social servers for their users ("statistics" addon has to be enabled on the GS server)
if (!get_config('system','ostatus_disabled'))
gs_discover();
}
logger('end '.$search);
return;
@ -128,7 +135,7 @@ function discover_users() {
else
$server_url = poco_detect_server($user["url"]);
if (poco_check_server($server_url, $gcontacts[0]["network"])) {
if (($server_url == "") OR poco_check_server($server_url, $gcontacts[0]["network"])) {
logger('Check user '.$user["url"]);
poco_last_updated($user["url"], true);
@ -191,6 +198,36 @@ function discover_directory($search) {
Cache::set("dirsearch:".$search, time(), CACHE_DAY);
}
/**
* @brief Search for GNU Social user with gstools.org
*
* @param str $search User name
*/
function gs_search_user($search) {
$a = get_app();
$url = "http://gstools.org/api/users_search/".urlencode($search);
$result = z_fetch_url($url);
if (!$result["success"])
return false;
$contacts = json_decode($result["body"]);
if ($contacts->status == 'ERROR')
return false;
foreach($contacts->data AS $user) {
$contact = probe_url($user->site_address."/".$user->name);
if ($contact["network"] != NETWORK_PHANTOM) {
$contact["about"] = $user->description;
update_gcontact($contact);
}
}
}
if (array_search(__file__,get_included_files())===0){
discover_poco_run($_SERVER["argv"],$_SERVER["argc"]);
killme();

View File

@ -633,4 +633,129 @@ function notification($params) {
}
/**
* @brief Checks for item related notifications and sends them
*
* @param int $itemid ID of the item for which the check should be done
* @param int $uid User ID
* @param str $defaulttype (Optional) Forces a notification with this type.
*/
function check_item_notification($itemid, $uid, $defaulttype = "") {
$notification_data = array("uid" => $uid, "profiles" => array());
call_hooks('check_item_notification', $notification_data);
$profiles = $notification_data["profiles"];
$user = q("SELECT `notify-flags`, `language`, `username`, `email` FROM `user` WHERE `uid` = %d", intval($uid));
if (!$user)
return false;
$owner = q("SELECT `id`, `url` FROM `contact` WHERE `self` AND `uid` = %d LIMIT 1", intval($uid));
if (!$owner)
return false;
$profiles[] = $owner[0]["url"];
$profiles2 = array();
foreach ($profiles AS $profile) {
$profiles2[] = normalise_link($profile);
$profiles2[] = str_replace("http://", "https://", normalise_link($profile));
}
$profiles = $profiles2;
$profile_list = "";
foreach ($profiles AS $profile) {
if ($profile_list != "")
$profile_list .= "', '";
$profile_list .= dbesc($profile);
}
$profile_list = "'".$profile_list."'";
// Only act if it is a "real" post
// We need the additional check for the "local_profile" because of mixed situations on connector networks
$item = q("SELECT `id`, `mention`, `tag`,`parent`, `title`, `body`, `author-name`, `author-link`, `author-avatar`, `guid`,
`parent-uri`, `uri`, `contact-id`
FROM `item` WHERE `id` = %d AND `verb` IN ('%s', '') AND `type` != 'activity' AND
NOT (`author-link` IN ($profile_list)) LIMIT 1",
intval($itemid), dbesc(ACTIVITY_POST));
if (!$item)
return false;
// Generate the notification array
$params = array();
$params["uid"] = $uid;
$params["notify_flags"] = $user[0]["notify-flags"];
$params["language"] = $user[0]["language"];
$params["to_name"] = $user[0]["username"];
$params["to_email"] = $user[0]["email"];
$params["item"] = $item[0];
$params["parent"] = $item[0]["parent"];
$params["link"] = App::get_baseurl().'/display/'.urlencode($item[0]["guid"]);
$params["otype"] = 'item';
$params["source_name"] = $item[0]["author-name"];
$params["source_link"] = $item[0]["author-link"];
$params["source_photo"] = $item[0]["author-avatar"];
if ($item[0]["parent-uri"] === $item[0]["uri"]) {
// Send a notification for every new post?
$r = q("SELECT `notify_new_posts` FROM `contact` WHERE `id` = %d AND `uid` = %d AND `notify_new_posts` LIMIT 1",
intval($item[0]['contact-id']),
intval($uid)
);
$send_notification = count($r);
if (!$send_notification) {
$tags = q("SELECT `url` FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` = %d AND `uid` = %d",
intval(TERM_OBJ_POST), intval($itemid), intval(TERM_MENTION), intval($uid));
if (count($tags)) {
foreach ($tags AS $tag) {
$r = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d AND `notify_new_posts`",
normalise_link($tag["url"]), intval($uid));
if (count($r))
$send_notification = true;
}
}
}
if ($send_notification) {
$params["type"] = NOTIFY_SHARE;
$params["verb"] = ACTIVITY_TAG;
}
}
// Is the user mentioned in this post?
$tagged = false;
foreach ($profiles AS $profile) {
if (strpos($item[0]["tag"], "=".$profile."]") OR strpos($item[0]["body"], "=".$profile."]"))
$tagged = true;
}
if ($item[0]["mention"] OR $tagged OR ($defaulttype == NOTIFY_TAGSELF)) {
$params["type"] = NOTIFY_TAGSELF;
$params["verb"] = ACTIVITY_TAG;
}
// Is it a post that the user had started or where he interacted?
$parent = q("SELECT `thread`.`iid` FROM `thread` INNER JOIN `item` ON `item`.`parent` = `thread`.`iid`
WHERE `thread`.`iid` = %d AND `thread`.`uid` = %d AND NOT `thread`.`ignored` AND
(`thread`.`mention` OR `item`.`author-link` IN ($profile_list))
LIMIT 1",
intval($item[0]["parent"]), intval($uid));
if ($parent AND !isset($params["type"])) {
$params["type"] = NOTIFY_COMMENT;
$params["verb"] = ACTIVITY_POST;
}
if (isset($params["type"]))
notification($params);
}
?>

View File

@ -61,7 +61,7 @@ function format_event_html($ev, $simple = false) {
. bbcode($ev['location'])
. '</span></p>' . "\r\n";
if (strpos($ev['location'], "[map")===False) {
if (strpos($ev['location'], "[map") !== False) {
$map = generate_named_map($ev['location']);
if ($map!==$ev['location']) $o.=$map;
}
@ -76,7 +76,6 @@ function format_event_html($ev, $simple = false) {
function parse_event($h) {
require_once('include/Scrape.php');
require_once('library/HTMLPurifier.auto.php');
require_once('include/html2bbcode');
$h = '<html><body>' . $h . '</body></html>';

View File

@ -18,7 +18,6 @@ function expire_run(&$argv, &$argc){
require_once('include/session.php');
require_once('include/datetime.php');
require_once('library/simplepie/simplepie.inc');
require_once('include/items.php');
require_once('include/Contact.php');

View File

@ -1,23 +1,25 @@
<?php
/**
* @file include/features.php *
* @file include/features.php
* @brief Features management
*/
/**
* @brief check if feature is enabled
*
* return boolean
* @return boolean
*/
function feature_enabled($uid,$feature) {
//return true;
$x = get_pconfig($uid,'feature',$feature);
$x = get_config('feature_lock',$feature);
if($x === false) {
$x = get_config('feature',$feature);
if($x === false)
$x = get_feature_default($feature);
$x = get_pconfig($uid,'feature',$feature);
if($x === false) {
$x = get_config('feature',$feature);
if($x === false)
$x = get_feature_default($feature);
}
}
$arr = array('uid' => $uid, 'feature' => $feature, 'enabled' => $x);
call_hooks('feature_enabled',$arr);
@ -42,14 +44,17 @@ function get_feature_default($feature) {
}
/**
* @ brief get a list of all available features
* @brief Get a list of all available features
*
* The array includes the setting group, the setting name,
* explainations for the setting and if it's enabled or disabled
* by default
*
* @param bool $filtered True removes any locked features
*
* @return array
*/
function get_features() {
function get_features($filtered = true) {
$arr = array(
@ -57,56 +62,78 @@ function get_features() {
'general' => array(
t('General Features'),
//array('expire', t('Content Expiration'), t('Remove old posts/comments after a period of time')),
array('multi_profiles', t('Multiple Profiles'), t('Ability to create multiple profiles'),false),
array('photo_location', t('Photo Location'), t('Photo metadata is normally stripped. This extracts the location (if present) prior to stripping metadata and links it to a map.'),false),
array('multi_profiles', t('Multiple Profiles'), t('Ability to create multiple profiles'), false, get_config('feature_lock','multi_profiles')),
array('photo_location', t('Photo Location'), t('Photo metadata is normally stripped. This extracts the location (if present) prior to stripping metadata and links it to a map.'), false, get_config('feature_lock','photo_location')),
),
// Post composition
'composition' => array(
t('Post Composition Features'),
array('richtext', t('Richtext Editor'), t('Enable richtext editor'),false),
array('preview', t('Post Preview'), t('Allow previewing posts and comments before publishing them'),false),
array('aclautomention', t('Auto-mention Forums'), t('Add/remove mention when a fourm page is selected/deselected in ACL window.'),false),
array('richtext', t('Richtext Editor'), t('Enable richtext editor'), false, get_config('feature_lock','richtext')),
array('preview', t('Post Preview'), t('Allow previewing posts and comments before publishing them'), false, get_config('feature_lock','preview')),
array('aclautomention', t('Auto-mention Forums'), t('Add/remove mention when a fourm page is selected/deselected in ACL window.'), false, get_config('feature_lock','aclautomention')),
),
// Network sidebar widgets
'widgets' => array(
t('Network Sidebar Widgets'),
array('archives', t('Search by Date'), t('Ability to select posts by date ranges'),false),
array('forumlist_widget', t('List Forums'), t('Enable widget to display the forums your are connected with'),true),
array('groups', t('Group Filter'), t('Enable widget to display Network posts only from selected group'),false),
array('networks', t('Network Filter'), t('Enable widget to display Network posts only from selected network'),false),
array('savedsearch', t('Saved Searches'), t('Save search terms for re-use'),false),
array('archives', t('Search by Date'), t('Ability to select posts by date ranges'), false, get_config('feature_lock','archives')),
array('forumlist_widget', t('List Forums'), t('Enable widget to display the forums your are connected with'), true, get_config('feature_lock','forumlist_widget')),
array('groups', t('Group Filter'), t('Enable widget to display Network posts only from selected group'), false, get_config('feature_lock','groups')),
array('networks', t('Network Filter'), t('Enable widget to display Network posts only from selected network'), false, get_config('feature_lock','networks')),
array('savedsearch', t('Saved Searches'), t('Save search terms for re-use'), false, get_config('feature_lock','savedsearch')),
),
// Network tabs
'net_tabs' => array(
t('Network Tabs'),
array('personal_tab', t('Network Personal Tab'), t('Enable tab to display only Network posts that you\'ve interacted on'),false),
array('new_tab', t('Network New Tab'), t('Enable tab to display only new Network posts (from the last 12 hours)'),false),
array('link_tab', t('Network Shared Links Tab'), t('Enable tab to display only Network posts with links in them'),false),
array('personal_tab', t('Network Personal Tab'), t('Enable tab to display only Network posts that you\'ve interacted on'), false, get_config('feature_lock','personal_tab')),
array('new_tab', t('Network New Tab'), t('Enable tab to display only new Network posts (from the last 12 hours)'), false, get_config('feature_lock','new_tab')),
array('link_tab', t('Network Shared Links Tab'), t('Enable tab to display only Network posts with links in them'), false, get_config('feature_lock','link_tab')),
),
// Item tools
'tools' => array(
t('Post/Comment Tools'),
array('multi_delete', t('Multiple Deletion'), t('Select and delete multiple posts/comments at once'),false),
array('edit_posts', t('Edit Sent Posts'), t('Edit and correct posts and comments after sending'),false),
array('commtag', t('Tagging'), t('Ability to tag existing posts'),false),
array('categories', t('Post Categories'), t('Add categories to your posts'),false),
array('filing', t('Saved Folders'), t('Ability to file posts under folders'),false),
array('dislike', t('Dislike Posts'), t('Ability to dislike posts/comments')),
array('star_posts', t('Star Posts'), t('Ability to mark special posts with a star indicator'),false),
array('ignore_posts', t('Mute Post Notifications'), t('Ability to mute notifications for a thread'),false),
array('multi_delete', t('Multiple Deletion'), t('Select and delete multiple posts/comments at once'), false, get_config('feature_lock','multi_delete')),
array('edit_posts', t('Edit Sent Posts'), t('Edit and correct posts and comments after sending'), false, get_config('feature_lock','edit_posts')),
array('commtag', t('Tagging'), t('Ability to tag existing posts'), false, get_config('feature_lock','commtag')),
array('categories', t('Post Categories'), t('Add categories to your posts'), false, get_config('feature_lock','categories')),
array('filing', t('Saved Folders'), t('Ability to file posts under folders'), false, get_config('feature_lock','filing')),
array('dislike', t('Dislike Posts'), t('Ability to dislike posts/comments'), false, get_config('feature_lock','dislike')),
array('star_posts', t('Star Posts'), t('Ability to mark special posts with a star indicator'), false, get_config('feature_lock','star_posts')),
array('ignore_posts', t('Mute Post Notifications'), t('Ability to mute notifications for a thread'), false, get_config('feature_lock','ignore_posts')),
),
// Advanced Profile Settings
'advanced_profile' => array(
t('Advanced Profile Settings'),
array('forumlist_profile', t('List Forums'), t('Show visitors public community forums at the Advanced Profile Page'),false),
array('forumlist_profile', t('List Forums'), t('Show visitors public community forums at the Advanced Profile Page'), false, get_config('feature_lock','forumlist_profile')),
),
);
// removed any locked features and remove the entire category if this makes it empty
if($filtered) {
foreach($arr as $k => $x) {
$has_items = false;
$kquantity = count($arr[$k]);
for($y = 0; $y < $kquantity; $y ++) {
if(is_array($arr[$k][$y])) {
if($arr[$k][$y][4] === false) {
$has_items = true;
}
else {
unset($arr[$k][$y]);
}
}
}
if(! $has_items) {
unset($arr[$k]);
}
}
}
call_hooks('get_features',$arr);
return $arr;
}

View File

@ -264,24 +264,8 @@ function new_contact($uid,$url,$interactive = false) {
require_once("include/Photo.php");
$photos = import_profile_photo($ret['photo'],$uid,$contact_id);
$r = q("UPDATE `contact` SET `photo` = '%s',
`thumb` = '%s',
`micro` = '%s',
`name-date` = '%s',
`uri-date` = '%s',
`avatar-date` = '%s'
WHERE `id` = %d",
dbesc($photos[0]),
dbesc($photos[1]),
dbesc($photos[2]),
dbesc(datetime_convert()),
dbesc(datetime_convert()),
dbesc(datetime_convert()),
intval($contact_id)
);
// Update the avatar
update_contact_avatar($ret['photo'],$uid,$contact_id);
// pull feed and consume it, which should subscribe to the hub.

View File

@ -1,182 +0,0 @@
<?php
/**
* @file include/forums.php
* @brief Functions related to forum functionality *
*/
/**
* @brief Function to list all forums a user is connected with
*
* @param int $uid of the profile owner
* @param boolean $showhidden
* Show frorums which are not hidden
* @param boolean $lastitem
* Sort by lastitem
* @param boolean $showprivate
* Show private groups
*
* @returns array
* 'url' => forum url
* 'name' => forum name
* 'id' => number of the key from the array
* 'micro' => contact photo in format micro
*/
function get_forumlist($uid, $showhidden = true, $lastitem, $showprivate = false) {
$forumlist = array();
$order = (($showhidden) ? '' : ' AND NOT `hidden` ');
$order .= (($lastitem) ? ' ORDER BY `last-item` DESC ' : ' ORDER BY `name` ASC ');
$select = '`forum` ';
if ($showprivate) {
$select = '(`forum` OR `prv`)';
}
$contacts = q("SELECT `contact`.`id`, `contact`.`url`, `contact`.`name`, `contact`.`micro` FROM `contact`
WHERE `network`= 'dfrn' AND $select AND `uid` = %d
AND NOT `blocked` AND NOT `hidden` AND NOT `pending` AND NOT `archive`
AND `success_update` > `failure_update`
$order ",
intval($uid)
);
foreach($contacts as $contact) {
$forumlist[] = array(
'url' => $contact['url'],
'name' => $contact['name'],
'id' => $contact['id'],
'micro' => $contact['micro'],
);
}
return($forumlist);
}
/**
* @brief Forumlist widget
*
* Sidebar widget to show subcribed friendica forums. If activated
* in the settings, it appears at the notwork page sidebar
*
* @param int $uid
* @param int $cid
* The contact id which is used to mark a forum as "selected"
* @return string
*/
function widget_forumlist($uid,$cid = 0) {
if(! intval(feature_enabled(local_user(),'forumlist_widget')))
return;
$o = '';
//sort by last updated item
$lastitem = true;
$contacts = get_forumlist($uid,true,$lastitem, true);
$total = count($contacts);
$visible_forums = 10;
if(count($contacts)) {
$id = 0;
foreach($contacts as $contact) {
$selected = (($cid == $contact['id']) ? ' forum-selected' : '');
$entry = array(
'url' => z_root() . '/network?f=&cid=' . $contact['id'],
'external_url' => z_root() . '/redir/' . $contact['id'],
'name' => $contact['name'],
'cid' => $contact['id'],
'selected' => $selected,
'micro' => proxy_url($contact['micro'], false, PROXY_SIZE_MICRO),
'id' => ++$id,
);
$entries[] = $entry;
}
$tpl = get_markup_template('widget_forumlist.tpl');
$o .= replace_macros($tpl,array(
'$title' => t('Forums'),
'$forums' => $entries,
'$link_desc' => t('External link to forum'),
'$total' => $total,
'$visible_forums' => $visible_forums,
'$showmore' => t('show more'),
));
}
return $o;
}
/**
* @brief Format forumlist as contact block
*
* This function is used to show the forumlist in
* the advanced profile.
*
* @param int $uid
* @return string
*
*/
function forumlist_profile_advanced($uid) {
$profile = intval(feature_enabled($uid,'forumlist_profile'));
if(! $profile)
return;
$o = '';
// place holder in case somebody wants configurability
$show_total = 9999;
//don't sort by last updated item
$lastitem = false;
$contacts = get_forumlist($uid,false,$lastitem,false);
$total_shown = 0;
foreach($contacts as $contact) {
$forumlist .= micropro($contact,false,'forumlist-profile-advanced');
$total_shown ++;
if($total_shown == $show_total)
break;
}
if(count($contacts) > 0)
$o .= $forumlist;
return $o;
}
/**
* @brief count unread forum items
*
* Count unread items of connected forums and private groups
*
* @return array
* 'id' => contact id
* 'name' => contact/forum name
* 'count' => counted unseen forum items
*
*/
function forums_count_unseen() {
$r = q("SELECT `contact`.`id`, `contact`.`name`, COUNT(*) AS `count` FROM `item`
INNER JOIN `contact` ON `item`.`contact-id` = `contact`.`id`
WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted` AND `item`.`unseen`
AND `contact`.`network`= 'dfrn' AND (`contact`.`forum` OR `contact`.`prv`)
AND NOT `contact`.`blocked` AND NOT `contact`.`hidden`
AND NOT `contact`.`pending` AND NOT `contact`.`archive`
AND `contact`.`success_update` > `failure_update`
GROUP BY `contact`.`id` ",
intval(local_user())
);
return $r;
}

View File

@ -60,6 +60,8 @@ class FriendicaSmartyEngine implements ITemplateEngine {
$template = $s;
$s = new FriendicaSmarty();
}
$r['$APP'] = get_app();
// "middleware": inject variables into templates
$arr = array(

View File

@ -33,7 +33,7 @@ function gprobe_run(&$argv, &$argc){
$url = hex2bin($argv[1]);
$r = q("select * from gcontact where nurl = '%s' limit 1",
$r = q("SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1",
dbesc(normalise_link($url))
);
@ -58,21 +58,16 @@ function gprobe_run(&$argv, &$argc){
if (is_null($result))
Cache::set("gprobe:".$urlparts["host"],serialize($arr));
if(count($arr) && x($arr,'network') && $arr['network'] === NETWORK_DFRN) {
q("insert into `gcontact` (`name`,`url`,`nurl`,`photo`)
values ( '%s', '%s', '%s', '%s') ",
dbesc($arr['name']),
dbesc($arr['url']),
dbesc(normalise_link($arr['url'])),
dbesc($arr['photo'])
);
}
$r = q("select * from gcontact where nurl = '%s' limit 1",
if (!in_array($result["network"], array(NETWORK_FEED, NETWORK_PHANTOM)))
update_gcontact($arr);
$r = q("SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1",
dbesc(normalise_link($url))
);
}
if(count($r))
poco_load(0,0,$r[0]['id'], str_replace('/profile/','/poco/',$r[0]['url']));
if ($r[0]["network"] == NETWORK_DFRN)
poco_load(0,0,$r[0]['id'], str_replace('/profile/','/poco/',$r[0]['url']));
logger("gprobe end for ".normalise_link($url), LOGGER_DEBUG);
return;

View File

@ -215,7 +215,7 @@ function mini_group_select($uid,$gid = 0) {
/**
* @brief Create group sidebar widget
*
*
* @param string $every
* @param string $each
* @param string $editmode
@ -234,7 +234,7 @@ function group_side($every="contacts",$each="group",$editmode = "standard", $gro
return '';
$groups = array();
$groups[] = array(
'text' => t('Everybody'),
'id' => 0,
@ -255,7 +255,7 @@ function group_side($every="contacts",$each="group",$editmode = "standard", $gro
if(count($r)) {
foreach($r as $rr) {
$selected = (($group_id == $rr['id']) ? ' group-selected' : '');
if ($editmode == "full") {
$groupedit = array(
'href' => "group/".$rr['id'],
@ -264,7 +264,7 @@ function group_side($every="contacts",$each="group",$editmode = "standard", $gro
} else {
$groupedit = null;
}
$groups[] = array(
'id' => $rr['id'],
'cid' => $cid,
@ -297,17 +297,26 @@ function group_side($every="contacts",$each="group",$editmode = "standard", $gro
return $o;
}
function expand_groups($a,$check_dead = false) {
function expand_groups($a,$check_dead = false, $use_gcontact = false) {
if(! (is_array($a) && count($a)))
return array();
$groups = implode(',', $a);
$groups = dbesc($groups);
$r = q("SELECT `contact-id` FROM `group_member` WHERE `gid` IN ( $groups )");
if ($use_gcontact)
$r = q("SELECT `gcontact`.`id` AS `contact-id` FROM `group_member`
INNER JOIN `contact` ON `contact`.`id` = `group_member`.`contact-id`
INNER JOIN `gcontact` ON `gcontact`.`nurl` = `contact`.`nurl`
WHERE `gid` IN ($groups)");
else
$r = q("SELECT `contact-id` FROM `group_member` WHERE `gid` IN ( $groups )");
$ret = array();
if(count($r))
foreach($r as $rr)
$ret[] = $rr['contact-id'];
if($check_dead) {
if($check_dead AND !$use_gcontact) {
require_once('include/acl_selectors.php');
$ret = prune_deadguys($ret);
}
@ -353,17 +362,16 @@ function groups_containing($uid,$c) {
*/
function groups_count_unseen() {
$r = q("SELECT `group`.`id`, `group`.`name`, COUNT(`item`.`id`) AS `count` FROM `group`, `group_member`, `item`
WHERE `group`.`uid` = %d
AND `item`.`uid` = %d
AND `item`.`unseen` AND `item`.`visible`
AND NOT `item`.`deleted`
AND `item`.`contact-id` = `group_member`.`contact-id`
AND `group_member`.`gid` = `group`.`id`
GROUP BY `group`.`id` ",
$r = q("SELECT `group`.`id`, `group`.`name`,
(SELECT COUNT(*) FROM `item`
WHERE `uid` = %d AND `unseen` AND
`contact-id` IN (SELECT `contact-id` FROM `group_member`
WHERE `group_member`.`gid` = `group`.`id` AND `group_member`.`uid` = %d)) AS `count`
FROM `group` WHERE `group`.`uid` = %d;",
intval(local_user()),
intval(local_user()),
intval(local_user())
);
return $r;
}
}

View File

@ -3,7 +3,7 @@
* @file include/identity.php
*/
require_once('include/forums.php');
require_once('include/ForumManager.php');
require_once('include/bbcode.php');
require_once("mod/proxy.php");
@ -300,6 +300,7 @@ function profile_sidebar($profile, $block = 0) {
$account_type = "";
if((x($profile,'address') == 1)
|| (x($profile,'location') == 1)
|| (x($profile,'locality') == 1)
|| (x($profile,'region') == 1)
|| (x($profile,'postal-code') == 1)
@ -368,6 +369,8 @@ function profile_sidebar($profile, $block = 0) {
if (isset($p["address"]))
$p["address"] = bbcode($p["address"]);
else
$p["address"] = bbcode($p["location"]);
if (isset($p["photo"]))
$p["photo"] = proxy_url($p["photo"], false, PROXY_SIZE_SMALL);
@ -652,7 +655,7 @@ function advanced_profile(&$a) {
//show subcribed forum if it is enabled in the usersettings
if (feature_enabled($uid,'forumlist_profile')) {
$profile['forumlist'] = array( t('Forums:'), forumlist_profile_advanced($uid));
$profile['forumlist'] = array( t('Forums:'), ForumManager::profile_advanced($uid));
}
if ($a->profile['uid'] == local_user())

File diff suppressed because it is too large Load Diff

View File

@ -279,6 +279,9 @@ function store_diaspora_like_retract_sig($activity, $item, $like_item, $contact)
$contact_baseurl = substr($contact['url'], $contact_baseurl_start, $contact_baseurl_length);
$diaspora_handle = $contact['nick'] . '@' . $contact_baseurl;
// This code could never had worked (the return values form the queries were used in a wrong way.
// Additionally it is needlessly complicated. Either the contact is owner or not. And we have this data already.
/*
// Get contact's private key if he's a user of the local Friendica server
$r = q("SELECT `contact`.`uid` FROM `contact` WHERE `url` = '%s' AND `self` = 1 LIMIT 1",
dbesc($contact['url'])
@ -289,9 +292,15 @@ function store_diaspora_like_retract_sig($activity, $item, $like_item, $contact)
$r = q("SELECT prvkey FROM user WHERE uid = %d LIMIT 1",
intval($contact_uid)
);
*/
// Is the contact the owner? Then fetch the private key
if ($contact['self'] AND ($contact['uid'] > 0)) {
$r = q("SELECT prvkey FROM user WHERE uid = %d LIMIT 1",
intval($contact['uid'])
);
if( $r)
$authorsig = base64_encode(rsa_sign($signed_text,$r['prvkey'],'sha256'));
if($r)
$authorsig = base64_encode(rsa_sign($signed_text,$r[0]['prvkey'],'sha256'));
}
if(! isset($authorsig))
@ -329,6 +338,10 @@ function store_diaspora_like_sig($activity, $post_type, $contact, $post_id) {
$contact_baseurl = substr($contact['url'], $contact_baseurl_start, $contact_baseurl_length);
$diaspora_handle = $contact['nick'] . '@' . $contact_baseurl;
// This code could never had worked (the return values form the queries were used in a wrong way.
// Additionally it is needlessly complicated. Either the contact is owner or not. And we have this data already.
/*
// Get contact's private key if he's a user of the local Friendica server
$r = q("SELECT `contact`.`uid` FROM `contact` WHERE `url` = '%s' AND `self` = 1 LIMIT 1",
dbesc($contact['url'])
@ -343,6 +356,17 @@ function store_diaspora_like_sig($activity, $post_type, $contact, $post_id) {
if( $r)
$contact_uprvkey = $r['prvkey'];
}
*/
// Is the contact the owner? Then fetch the private key
if ($contact['self'] AND ($contact['uid'] > 0)) {
$r = q("SELECT prvkey FROM user WHERE uid = %d LIMIT 1",
intval($contact['uid'])
);
if($r)
$contact_uprvkey = $r[0]['prvkey'];
}
$r = q("SELECT guid, parent FROM `item` WHERE id = %d LIMIT 1",
intval($post_id)
@ -353,7 +377,7 @@ function store_diaspora_like_sig($activity, $post_type, $contact, $post_id) {
intval($r[0]['parent'])
);
if( $p) {
$signed_text = $r[0]['guid'] . ';Post;' . $p[0]['guid'] . ';true;' . $diaspora_handle;
$signed_text = 'true;'.$r[0]['guid'].';Post;'.$p[0]['guid'].';'.$diaspora_handle;
if(isset($contact_uprvkey))
$authorsig = base64_encode(rsa_sign($signed_text,$contact_uprvkey,'sha256'));

View File

@ -42,6 +42,7 @@ if(!function_exists('z_fetch_url')){
* @return array an assoziative array with:
* * \e int \b return_code => HTTP return code or 0 if timeout or failure
* * \e boolean \b success => boolean true (if HTTP 2xx result) or false
* * \e string \b redirect_url => in case of redirect, content was finally retrieved from this URL
* * \e string \b header => HTTP headers
* * \e string \b body => fetched content
*/
@ -116,6 +117,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);
}
$base = $s;
$curl_info = @curl_getinfo($ch);
@ -133,6 +137,10 @@ function z_fetch_url($url,$binary = false, &$redirects = 0, $opts=array()) {
$base = substr($base,strlen($chunk));
}
$a->set_curl_code($http_code);
$a->set_curl_content_type($curl_info['content_type']);
$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"]);
@ -160,13 +168,13 @@ function z_fetch_url($url,$binary = false, &$redirects = 0, $opts=array()) {
$a->set_curl_content_type($curl_info['content_type']);
$body = substr($s,strlen($header));
$a->set_curl_headers($header);
$rc = intval($http_code);
$ret['return_code'] = $rc;
$ret['success'] = (($rc >= 200 && $rc <= 299) ? true : false);
$ret['redirect_url'] = $url;
if(! $ret['success']) {
$ret['error'] = curl_error($ch);
$ret['debug'] = $curl_info;
@ -1246,6 +1254,9 @@ function original_url($url, $depth=1, $fetchbody = false) {
$a->save_timestamp($stamp1, "network");
if ($http_code == 0)
return($url);
if ((($curl_info['http_code'] == "301") OR ($curl_info['http_code'] == "302"))
AND (($curl_info['redirect_url'] != "") OR ($curl_info['location'] != ""))) {
if ($curl_info['redirect_url'] != "")

View File

@ -535,7 +535,7 @@ function notifier_run(&$argv, &$argc){
if($public_message) {
if (!$followup)
if (!$followup AND $top_level)
$r0 = diaspora_fetch_relay();
else
$r0 = array();

View File

@ -13,7 +13,13 @@ function oembed_fetch_url($embedurl, $no_rich_type = false){
$a = get_app();
$txt = Cache::get($a->videowidth . $embedurl);
$r = q("SELECT * FROM `oembed` WHERE `url` = '%s'",
dbesc(normalise_link($embedurl)));
if ($r)
$txt = $r[0]["content"];
else
$txt = Cache::get($a->videowidth . $embedurl);
// These media files should now be caught in bbcode.php
// left here as a fallback in case this is called from another source
@ -66,8 +72,14 @@ function oembed_fetch_url($embedurl, $no_rich_type = false){
if ($txt[0]!="{")
$txt='{"type":"error"}';
else //save in cache
else { //save in cache
$j = json_decode($txt);
if ($j->type != "error")
q("INSERT INTO `oembed` (`url`, `content`, `created`) VALUES ('%s', '%s', '%s')",
dbesc(normalise_link($embedurl)), dbesc($txt), dbesc(datetime_convert()));
Cache::set($a->videowidth . $embedurl,$txt, CACHE_DAY);
}
}
$j = json_decode($txt);
@ -85,7 +97,7 @@ function oembed_fetch_url($embedurl, $no_rich_type = false){
// If fetching information doesn't work, then improve via internal functions
if (($j->type == "error") OR ($no_rich_type AND ($j->type == "rich"))) {
require_once("mod/parse_url.php");
$data = parseurl_getsiteinfo($embedurl, true, false);
$data = parseurl_getsiteinfo_cached($embedurl, true, false);
$j->type = $data["type"];
if ($j->type == "photo") {

View File

@ -27,7 +27,6 @@ function onepoll_run(&$argv, &$argc){
require_once('include/session.php');
require_once('include/datetime.php');
require_once('library/simplepie/simplepie.inc');
require_once('include/items.php');
require_once('include/Contact.php');
require_once('include/email.php');
@ -335,7 +334,9 @@ function onepoll_run(&$argv, &$argc){
if($contact['rel'] == CONTACT_IS_FOLLOWER || $contact['blocked'] || $contact['readonly'])
return;
$xml = fetch_url($contact['poll']);
$cookiejar = tempnam(get_temppath(), 'cookiejar-onepoll-');
$xml = fetch_url($contact['poll'], false, $redirects, 0, Null, $cookiejar);
unlink($cookiejar);
}
elseif($contact['network'] === NETWORK_MAIL || $contact['network'] === NETWORK_MAIL2) {

View File

@ -17,15 +17,6 @@ define('OSTATUS_DEFAULT_POLL_INTERVAL', 30); // given in minutes
define('OSTATUS_DEFAULT_POLL_TIMEFRAME', 1440); // given in minutes
define('OSTATUS_DEFAULT_POLL_TIMEFRAME_MENTIONS', 14400); // given in minutes
define("NS_ATOM", "http://www.w3.org/2005/Atom");
define("NS_THR", "http://purl.org/syndication/thread/1.0");
define("NS_GEORSS", "http://www.georss.org/georss");
define("NS_ACTIVITY", "http://activitystrea.ms/spec/1.0/");
define("NS_MEDIA", "http://purl.org/syndication/atommedia");
define("NS_POCO", "http://portablecontacts.net/spec/1.0");
define("NS_OSTATUS", "http://ostatus.org/schema/1.0");
define("NS_STATUSNET", "http://status.net/schema/api/1/");
function ostatus_check_follow_friends() {
$r = q("SELECT `uid`,`v` FROM `pconfig` WHERE `cat`='system' AND `k`='ostatus_legacy_contact' AND `v` != ''");
@ -127,47 +118,57 @@ function ostatus_fetchauthor($xpath, $context, $importer, &$contact, $onlyfetch)
$author["owner-link"] = $author["author-link"];
$author["owner-avatar"] = $author["author-avatar"];
if ($r AND !$onlyfetch) {
// Only update the contacts if it is an OStatus contact
if ($r AND !$onlyfetch AND ($contact["network"] == NETWORK_OSTATUS)) {
// Update contact data
$update_contact = ($r[0]['name-date'] < datetime_convert('','','now -12 hours'));
if ($update_contact) {
$value = $xpath->query("atom:link[@rel='salmon']", $context)->item(0)->nodeValue;
if ($value != "")
$contact["notify"] = $value;
$value = $xpath->evaluate('atom:author/uri/text()', $context)->item(0)->nodeValue;
if ($value != "")
$contact["alias"] = $value;
$value = $xpath->evaluate('atom:author/poco:displayName/text()', $context)->item(0)->nodeValue;
if ($value != "")
$contact["name"] = $value;
$value = $xpath->evaluate('atom:author/poco:preferredUsername/text()', $context)->item(0)->nodeValue;
if ($value != "")
$contact["nick"] = $value;
$value = $xpath->evaluate('atom:author/poco:note/text()', $context)->item(0)->nodeValue;
if ($value != "")
$contact["about"] = html2bbcode($value);
$value = $xpath->evaluate('atom:author/poco:address/poco:formatted/text()', $context)->item(0)->nodeValue;
if ($value != "")
$contact["location"] = $value;
if (($contact["name"] != $r[0]["name"]) OR ($contact["nick"] != $r[0]["nick"]) OR ($contact["about"] != $r[0]["about"]) OR ($contact["location"] != $r[0]["location"])) {
logger("Update contact data for contact ".$contact["id"], LOGGER_DEBUG);
$value = $xpath->evaluate('atom:author/poco:displayName/text()', $context)->item(0)->nodeValue;
if ($value != "")
$contact["name"] = $value;
$value = $xpath->evaluate('atom:author/poco:preferredUsername/text()', $context)->item(0)->nodeValue;
if ($value != "")
$contact["nick"] = $value;
$value = $xpath->evaluate('atom:author/poco:note/text()', $context)->item(0)->nodeValue;
if ($value != "")
$contact["about"] = html2bbcode($value);
$value = $xpath->evaluate('atom:author/poco:address/poco:formatted/text()', $context)->item(0)->nodeValue;
if ($value != "")
$contact["location"] = $value;
q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `about` = '%s', `location` = '%s', `name-date` = '%s' WHERE `id` = %d AND `network` = '%s'",
q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `about` = '%s', `location` = '%s', `name-date` = '%s' WHERE `id` = %d",
dbesc($contact["name"]), dbesc($contact["nick"]), dbesc($contact["about"]), dbesc($contact["location"]),
dbesc(datetime_convert()), intval($contact["id"]), dbesc(NETWORK_OSTATUS));
dbesc(datetime_convert()), intval($contact["id"]));
poco_check($contact["url"], $contact["name"], $contact["network"], $author["author-avatar"], $contact["about"], $contact["location"],
"", "", "", datetime_convert(), 2, $contact["id"], $contact["uid"]);
"", "", "", datetime_convert(), 2, $contact["id"], $contact["uid"]);
}
$update_photo = ($r[0]['avatar-date'] < datetime_convert('','','now -12 hours'));
if ($update_photo AND isset($author["author-avatar"])) {
if (isset($author["author-avatar"]) AND ($author["author-avatar"] != $r[0]['avatar'])) {
logger("Update profile picture for contact ".$contact["id"], LOGGER_DEBUG);
$photos = import_profile_photo($author["author-avatar"], $importer["uid"], $contact["id"]);
q("UPDATE `contact` SET `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' WHERE `id` = %d AND `network` = '%s'",
dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]),
dbesc(datetime_convert()), intval($contact["id"]), dbesc(NETWORK_OSTATUS));
update_contact_avatar($author["author-avatar"], $importer["uid"], $contact["id"]);
}
/// @todo Add the "addr" field
$contact["generation"] = 2;
$contact["photo"] = $author["author-avatar"];
update_gcontact($contact);
}
return($author);
@ -183,14 +184,14 @@ function ostatus_salmon_author($xml, $importer) {
@$doc->loadXML($xml);
$xpath = new DomXPath($doc);
$xpath->registerNamespace('atom', "http://www.w3.org/2005/Atom");
$xpath->registerNamespace('thr', "http://purl.org/syndication/thread/1.0");
$xpath->registerNamespace('georss', "http://www.georss.org/georss");
$xpath->registerNamespace('activity', "http://activitystrea.ms/spec/1.0/");
$xpath->registerNamespace('media', "http://purl.org/syndication/atommedia");
$xpath->registerNamespace('poco', "http://portablecontacts.net/spec/1.0");
$xpath->registerNamespace('ostatus', "http://ostatus.org/schema/1.0");
$xpath->registerNamespace('statusnet', "http://status.net/schema/api/1/");
$xpath->registerNamespace('atom', NAMESPACE_ATOM1);
$xpath->registerNamespace('thr', NAMESPACE_THREAD);
$xpath->registerNamespace('georss', NAMESPACE_GEORSS);
$xpath->registerNamespace('activity', NAMESPACE_ACTIVITY);
$xpath->registerNamespace('media', NAMESPACE_MEDIA);
$xpath->registerNamespace('poco', NAMESPACE_POCO);
$xpath->registerNamespace('ostatus', NAMESPACE_OSTATUS);
$xpath->registerNamespace('statusnet', NAMESPACE_STATUSNET);
$entries = $xpath->query('/atom:entry');
@ -214,14 +215,14 @@ function ostatus_import($xml,$importer,&$contact, &$hub) {
@$doc->loadXML($xml);
$xpath = new DomXPath($doc);
$xpath->registerNamespace('atom', "http://www.w3.org/2005/Atom");
$xpath->registerNamespace('thr', "http://purl.org/syndication/thread/1.0");
$xpath->registerNamespace('georss', "http://www.georss.org/georss");
$xpath->registerNamespace('activity', "http://activitystrea.ms/spec/1.0/");
$xpath->registerNamespace('media', "http://purl.org/syndication/atommedia");
$xpath->registerNamespace('poco', "http://portablecontacts.net/spec/1.0");
$xpath->registerNamespace('ostatus', "http://ostatus.org/schema/1.0");
$xpath->registerNamespace('statusnet', "http://status.net/schema/api/1/");
$xpath->registerNamespace('atom', NAMESPACE_ATOM1);
$xpath->registerNamespace('thr', NAMESPACE_THREAD);
$xpath->registerNamespace('georss', NAMESPACE_GEORSS);
$xpath->registerNamespace('activity', NAMESPACE_ACTIVITY);
$xpath->registerNamespace('media', NAMESPACE_MEDIA);
$xpath->registerNamespace('poco', NAMESPACE_POCO);
$xpath->registerNamespace('ostatus', NAMESPACE_OSTATUS);
$xpath->registerNamespace('statusnet', NAMESPACE_STATUSNET);
$gub = "";
$hub_attributes = $xpath->query("/atom:feed/atom:link[@rel='hub']")->item(0)->attributes;
@ -546,29 +547,6 @@ function ostatus_import($xml,$importer,&$contact, &$hub) {
}
logger("Item was stored with id ".$item_id, LOGGER_DEBUG);
$item["id"] = $item_id;
if ($mention) {
$u = q("SELECT `notify-flags`, `language`, `username`, `email` FROM user WHERE uid = %d LIMIT 1", intval($item['uid']));
$r = q("SELECT `parent` FROM `item` WHERE `id` = %d", intval($item_id));
notification(array(
'type' => NOTIFY_TAGSELF,
'notify_flags' => $u[0]["notify-flags"],
'language' => $u[0]["language"],
'to_name' => $u[0]["username"],
'to_email' => $u[0]["email"],
'uid' => $item["uid"],
'item' => $item,
'link' => $a->get_baseurl().'/display/'.urlencode(get_item_guid($item_id)),
'source_name' => $item["author-name"],
'source_link' => $item["author-link"],
'source_photo' => $item["author-avatar"],
'verb' => ACTIVITY_TAG,
'otype' => 'item',
'parent' => $r[0]["parent"]
));
}
}
}
@ -1013,28 +991,6 @@ function ostatus_completion($conversation_url, $uid, $item = array()) {
// Add the conversation entry (but don't fetch the whole conversation)
ostatus_store_conversation($newitem, $conversation_url);
if ($mention) {
$u = q("SELECT `notify-flags`, `language`, `username`, `email` FROM user WHERE uid = %d LIMIT 1", intval($uid));
$r = q("SELECT `parent` FROM `item` WHERE `id` = %d", intval($newitem));
notification(array(
'type' => NOTIFY_TAGSELF,
'notify_flags' => $u[0]["notify-flags"],
'language' => $u[0]["language"],
'to_name' => $u[0]["username"],
'to_email' => $u[0]["email"],
'uid' => $uid,
'item' => $arr,
'link' => $a->get_baseurl().'/display/'.urlencode(get_item_guid($newitem)),
'source_name' => $arr["author-name"],
'source_link' => $arr["author-link"],
'source_photo' => $arr["author-avatar"],
'verb' => ACTIVITY_TAG,
'otype' => 'item',
'parent' => $r[0]["parent"]
));
}
// If the newly created item is the top item then change the parent settings of the thread
// This shouldn't happen anymore. This is supposed to be absolote.
if ($arr["uri"] == $first_id) {
@ -1109,7 +1065,7 @@ function get_reshared_guid($item) {
return $guid;
}
function xml_add_element($doc, $parent, $element, $value = "", $attributes = array()) {
function xml_create_element($doc, $element, $value = "", $attributes = array()) {
$element = $doc->createElement($element, xmlify($value));
foreach ($attributes AS $key => $value) {
@ -1117,7 +1073,11 @@ function xml_add_element($doc, $parent, $element, $value = "", $attributes = arr
$attribute->value = xmlify($value);
$element->appendChild($attribute);
}
return $element;
}
function xml_add_element($doc, $parent, $element, $value = "", $attributes = array()) {
$element = xml_create_element($doc, $element, $value, $attributes);
$parent->appendChild($element);
}
@ -1151,16 +1111,16 @@ function ostatus_format_picture_post($body) {
function ostatus_add_header($doc, $owner) {
$a = get_app();
$root = $doc->createElementNS(NS_ATOM, 'feed');
$root = $doc->createElementNS(NAMESPACE_ATOM1, 'feed');
$doc->appendChild($root);
$root->setAttribute("xmlns:thr", NS_THR);
$root->setAttribute("xmlns:georss", NS_GEORSS);
$root->setAttribute("xmlns:activity", NS_ACTIVITY);
$root->setAttribute("xmlns:media", NS_MEDIA);
$root->setAttribute("xmlns:poco", NS_POCO);
$root->setAttribute("xmlns:ostatus", NS_OSTATUS);
$root->setAttribute("xmlns:statusnet", NS_STATUSNET);
$root->setAttribute("xmlns:thr", NAMESPACE_THREAD);
$root->setAttribute("xmlns:georss", NAMESPACE_GEORSS);
$root->setAttribute("xmlns:activity", NAMESPACE_ACTIVITY);
$root->setAttribute("xmlns:media", NAMESPACE_MEDIA);
$root->setAttribute("xmlns:poco", NAMESPACE_POCO);
$root->setAttribute("xmlns:ostatus", NAMESPACE_OSTATUS);
$root->setAttribute("xmlns:statusnet", NAMESPACE_STATUSNET);
$attributes = array("uri" => "https://friendi.ca", "version" => FRIENDICA_VERSION."-".DB_UPDATE_VERSION);
xml_add_element($doc, $root, "generator", FRIENDICA_PLATFORM, $attributes);
@ -1352,6 +1312,10 @@ function ostatus_add_author($doc, $owner) {
function ostatus_entry($doc, $item, $owner, $toplevel = false, $repeat = false) {
$a = get_app();
if (($item["id"] != $item["parent"]) AND (normalise_link($item["author-link"]) != normalise_link($owner["url"]))) {
logger("OStatus entry is from author ".$owner["url"]." - not from ".$item["author-link"].". Quitting.", LOGGER_DEBUG);
}
$is_repeat = false;
/* if (!$repeat) {
@ -1374,15 +1338,15 @@ function ostatus_entry($doc, $item, $owner, $toplevel = false, $repeat = false)
$entry = $doc->createElement("activity:object");
$title = sprintf("New note by %s", $owner["nick"]);
} else {
$entry = $doc->createElementNS(NS_ATOM, "entry");
$entry = $doc->createElementNS(NAMESPACE_ATOM1, "entry");
$entry->setAttribute("xmlns:thr", NS_THR);
$entry->setAttribute("xmlns:georss", NS_GEORSS);
$entry->setAttribute("xmlns:activity", NS_ACTIVITY);
$entry->setAttribute("xmlns:media", NS_MEDIA);
$entry->setAttribute("xmlns:poco", NS_POCO);
$entry->setAttribute("xmlns:ostatus", NS_OSTATUS);
$entry->setAttribute("xmlns:statusnet", NS_STATUSNET);
$entry->setAttribute("xmlns:thr", NAMESPACE_THREAD);
$entry->setAttribute("xmlns:georss", NAMESPACE_GEORSS);
$entry->setAttribute("xmlns:activity", NAMESPACE_ACTIVITY);
$entry->setAttribute("xmlns:media", NAMESPACE_MEDIA);
$entry->setAttribute("xmlns:poco", NAMESPACE_POCO);
$entry->setAttribute("xmlns:ostatus", NAMESPACE_OSTATUS);
$entry->setAttribute("xmlns:statusnet", NAMESPACE_STATUSNET);
$author = ostatus_add_author($doc, $owner);
$entry->appendChild($author);
@ -1447,9 +1411,12 @@ function ostatus_entry($doc, $item, $owner, $toplevel = false, $repeat = false)
$repeated_owner["about"] = "";
$repeated_owner["uid"] = 0;
$r =q("SELECT * FROM `unique_contacts` WHERE `url` = '%s'", normalise_link($repeated_item["author-link"]));
// Fetch the missing data from the global contacts
$r =q("SELECT * FROM `gcontact` WHERE `nurl` = '%s'", normalise_link($repeated_item["author-link"]));
if ($r) {
$repeated_owner["nick"] = $r[0]["nick"];
if ($r[0]["nick"] != "")
$repeated_owner["nick"] = $r[0]["nick"];
$repeated_owner["location"] = $r[0]["location"];
$repeated_owner["about"] = $r[0]["about"];
}

View File

@ -90,6 +90,14 @@ function get_attached_data($body) {
$post["text"] = $body;
}
}
if (preg_match_all("(\[url\]([$URLSearchString]*)\[\/url\])ism", $body, $links, PREG_SET_ORDER)) {
if (count($links) == 1) {
$post["type"] = "text";
$post["url"] = $links[0][1];
$post["text"] = $body;
}
}
if (!isset($post["type"])) {
$post["type"] = "text";
$post["text"] = trim($body);
@ -129,9 +137,17 @@ function plaintext($a, $b, $limit = 0, $includedlinks = false, $htmlmode = 2) {
require_once("include/html2plain.php");
require_once("include/network.php");
// Remove the hash tags
$URLSearchString = "^\[\]";
$body = preg_replace("/([#@])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$1$3', $b["body"]);
// Add an URL element if the text contains a raw link
$body = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1[url]$2[/url]', $body);
// At first look at data that is attached via "type-..." stuff
// This will hopefully replaced with a dedicated bbcode later
$post = get_attached_data($b["body"]);
//$post = get_attached_data($b["body"]);
$post = get_attached_data($body);
if (($b["title"] != "") AND ($post["text"] != ""))
$post["text"] = trim($b["title"]."\n\n".$post["text"]);
@ -146,6 +162,8 @@ function plaintext($a, $b, $limit = 0, $includedlinks = false, $htmlmode = 2) {
if ($includedlinks) {
if ($post["type"] == "link")
$link = $post["url"];
elseif ($post["type"] == "text")
$link = $post["url"];
elseif ($post["type"] == "video")
$link = $post["url"];
elseif ($post["type"] == "photo")
@ -161,8 +179,22 @@ function plaintext($a, $b, $limit = 0, $includedlinks = false, $htmlmode = 2) {
// But: if the link is beyond the limit, then it has to be added.
if (($link != "") AND strstr($msg, $link)) {
$pos = strpos($msg, $link);
if (($limit == 0) OR ($pos < $limit))
// Will the text be shortened in the link?
// Or is the link the last item in the post?
if (($limit > 0) AND ($pos < $limit) AND (($pos + 23 > $limit) OR ($pos + strlen($link) == strlen($msg))))
$msg = trim(str_replace($link, "", $msg));
elseif (($limit == 0) OR ($pos < $limit)) {
// The limit has to be increased since it will be shortened - but not now
// Only do it with Twitter (htmlmode = 8)
if (($limit > 0) AND (strlen($link) > 23) AND ($htmlmode == 8))
$limit = $limit - 23 + strlen($link);
$link = "";
if ($post["type"] == "text")
unset($post["url"]);
}
}
}
@ -178,7 +210,9 @@ function plaintext($a, $b, $limit = 0, $includedlinks = false, $htmlmode = 2) {
if (iconv_strlen($msg, "UTF-8") > $limit) {
if (!isset($post["url"])) {
if (($post["type"] == "text") AND isset($post["url"]))
$post["url"] = $b["plink"];
elseif (!isset($post["url"])) {
$limit = $limit - 23;
$post["url"] = $b["plink"];
} elseif (strpos($b["body"], "[share") !== false)

View File

@ -26,6 +26,9 @@ function poller_run(&$argv, &$argc){
unset($db_host, $db_user, $db_pass, $db_data);
};
if (poller_max_connections_reached())
return;
$load = current_load();
if($load) {
$maxsysload = intval(get_config('system','maxloadavg'));
@ -39,8 +42,10 @@ function poller_run(&$argv, &$argc){
}
// Checking the number of workers
if (poller_too_much_workers(1))
if (poller_too_much_workers(1)) {
poller_kill_stale_workers();
return;
}
if(($argc <= 1) OR ($argv[1] != "no_cron")) {
// Run the cron job that calls all other jobs
@ -50,16 +55,7 @@ function poller_run(&$argv, &$argc){
proc_run("php","include/cronhooks.php");
// Cleaning dead processes
$r = q("SELECT DISTINCT(`pid`) FROM `workerqueue` WHERE `executed` != '0000-00-00 00:00:00'");
foreach($r AS $pid)
if (!posix_kill($pid["pid"], 0))
q("UPDATE `workerqueue` SET `executed` = '0000-00-00 00:00:00', `pid` = 0 WHERE `pid` = %d",
intval($pid["pid"]));
else {
/// @TODO Kill long running processes
/// But: Update processes (like the database update) mustn't be killed
}
poller_kill_stale_workers();
} else
// Sleep four seconds before checking for running processes again to avoid having too many workers
sleep(4);
@ -72,6 +68,10 @@ function poller_run(&$argv, &$argc){
while ($r = q("SELECT * FROM `workerqueue` WHERE `executed` = '0000-00-00 00:00:00' ORDER BY `created` LIMIT 1")) {
// Constantly check the number of available database connections to let the frontend be accessible at any time
if (poller_max_connections_reached())
return;
// Count active workers and compare them with a maximum value that depends on the load
if (poller_too_much_workers(3))
return;
@ -124,6 +124,107 @@ function poller_run(&$argv, &$argc){
}
/**
* @brief Checks if the number of database connections has reached a critical limit.
*
* @return bool Are more than 3/4 of the maximum connections used?
*/
function poller_max_connections_reached() {
// Fetch the max value from the config. This is needed when the system cannot detect the correct value by itself.
$max = get_config("system", "max_connections");
if ($max == 0) {
// the maximum number of possible user connections can be a system variable
$r = q("SHOW VARIABLES WHERE `variable_name` = 'max_user_connections'");
if ($r)
$max = $r[0]["Value"];
// Or it can be granted. This overrides the system variable
$r = q("SHOW GRANTS");
if ($r)
foreach ($r AS $grants) {
$grant = array_pop($grants);
if (stristr($grant, "GRANT USAGE ON"))
if (preg_match("/WITH MAX_USER_CONNECTIONS (\d*)/", $grant, $match))
$max = $match[1];
}
}
// If $max is set we will use the processlist to determine the current number of connections
// The processlist only shows entries of the current user
if ($max != 0) {
$r = q("SHOW PROCESSLIST");
if (!$r)
return false;
$used = count($r);
logger("Connection usage (user values): ".$used."/".$max, LOGGER_DEBUG);
$level = $used / $max;
if ($level >= (3/4)) {
logger("Maximum level (3/4) of user connections reached: ".$used."/".$max);
return true;
}
}
// We will now check for the system values.
// This limit could be reached although the user limits are fine.
$r = q("SHOW VARIABLES WHERE `variable_name` = 'max_connections'");
if (!$r)
return false;
$max = intval($r[0]["Value"]);
if ($max == 0)
return false;
$r = q("SHOW STATUS WHERE `variable_name` = 'Threads_connected'");
if (!$r)
return false;
$used = intval($r[0]["Value"]);
if ($used == 0)
return false;
logger("Connection usage (system values): ".$used."/".$max, LOGGER_DEBUG);
$level = $used / $max;
if ($level < (3/4))
return false;
logger("Maximum level (3/4) of system connections reached: ".$used."/".$max);
return true;
}
/**
* @brief fix the queue entry if the worker process died
*
*/
function poller_kill_stale_workers() {
$r = q("SELECT `pid`, `executed` FROM `workerqueue` WHERE `executed` != '0000-00-00 00:00:00'");
foreach($r AS $pid)
if (!posix_kill($pid["pid"], 0))
q("UPDATE `workerqueue` SET `executed` = '0000-00-00 00:00:00', `pid` = 0 WHERE `pid` = %d",
intval($pid["pid"]));
else {
// Kill long running processes
$duration = (time() - strtotime($pid["executed"])) / 60;
if ($duration > 180) {
logger("Worker process ".$pid["pid"]." took more than 3 hours. It will be killed now.");
posix_kill($pid["pid"], SIGTERM);
// Question: If a process is stale: Should we remove it or should we reschedule it?
// By now we rescheduling it. It's maybe not the wisest decision?
q("UPDATE `workerqueue` SET `executed` = '0000-00-00 00:00:00', `pid` = 0 WHERE `pid` = %d",
intval($pid["pid"]));
} else
logger("Worker process ".$pid["pid"]." now runs for ".round($duration)." minutes. That's okay.", LOGGER_DEBUG);
}
}
function poller_too_much_workers($stage) {
$queues = get_config("system", "worker_queues");

View File

@ -3,6 +3,7 @@
require_once('include/datetime.php');
require_once('include/diaspora.php');
require_once('include/queue_fn.php');
require_once('include/Contact.php');
function profile_change() {
@ -53,19 +54,7 @@ function profile_change() {
$about = xmlify($profile['about']);
require_once('include/bbcode.php');
$about = xmlify(strip_tags(bbcode($about)));
$location = '';
if($profile['locality'])
$location .= $profile['locality'];
if($profile['region']) {
if($location)
$location .= ', ';
$location .= $profile['region'];
}
if($profile['country-name']) {
if($location)
$location .= ', ';
$location .= $profile['country-name'];
}
$location = formatted_location($profile);
$location = xmlify($location);
$tags = '';
if($profile['pub_keywords']) {

View File

@ -1,6 +1,7 @@
<?php
require_once("boot.php");
require_once('include/queue_fn.php');
require_once('include/dfrn.php');
function queue_run(&$argv, &$argc){
global $a, $db;
@ -52,6 +53,8 @@ function queue_run(&$argv, &$argc){
$queue_id = 0;
$deadguys = array();
$deadservers = array();
$serverlist = array();
logger('queue: start');
@ -95,7 +98,7 @@ function queue_run(&$argv, &$argc){
// For the first 12 hours we'll try to deliver every 15 minutes
// After that, we'll only attempt delivery once per hour.
$r = q("SELECT `id` FROM `queue` WHERE (( `created` > UTC_TIMESTAMP() - INTERVAL 12 HOUR && `last` < UTC_TIMESTAMP() - INTERVAL 15 MINUTE ) OR ( `last` < UTC_TIMESTAMP() - INTERVAL 1 HOUR ))");
$r = q("SELECT `id` FROM `queue` WHERE ((`created` > UTC_TIMESTAMP() - INTERVAL 12 HOUR && `last` < UTC_TIMESTAMP() - INTERVAL 15 MINUTE) OR (`last` < UTC_TIMESTAMP() - INTERVAL 1 HOUR)) ORDER BY `cid`, `created`");
}
if(! $r){
return;
@ -116,7 +119,7 @@ function queue_run(&$argv, &$argc){
// so check again if this entry still needs processing
if($queue_id) {
$qi = q("select * from queue where `id` = %d limit 1",
$qi = q("SELECT * FROM `queue` WHERE `id` = %d LIMIT 1",
intval($queue_id)
);
}
@ -142,8 +145,18 @@ function queue_run(&$argv, &$argc){
continue;
}
if (!poco_reachable($c[0]['url'])) {
logger('queue: skipping probably dead url: ' . $c[0]['url']);
$server = poco_detect_server($c[0]['url']);
if (($server != "") AND !in_array($server, $serverlist)) {
logger("Check server ".$server." (".$c[0]["network"].")");
if (!poco_check_server($server, $c[0]["network"], true))
$deadservers[] = $server;
$serverlist[] = $server;
}
if (($server != "") AND in_array($server, $deadservers)) {
logger('queue: skipping known dead server: '.$server);
update_queue_time($q_item['id']);
continue;
}
@ -166,37 +179,39 @@ function queue_run(&$argv, &$argc){
switch($contact['network']) {
case NETWORK_DFRN:
logger('queue: dfrndelivery: item ' . $q_item['id'] . ' for ' . $contact['name']);
$deliver_status = dfrn_deliver($owner,$contact,$data);
logger('queue: dfrndelivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>');
$deliver_status = dfrn::deliver($owner,$contact,$data);
if($deliver_status == (-1)) {
update_queue_time($q_item['id']);
$deadguys[] = $contact['notify'];
}
else {
} else
remove_queue_item($q_item['id']);
}
break;
case NETWORK_OSTATUS:
if($contact['notify']) {
logger('queue: slapdelivery: item ' . $q_item['id'] . ' for ' . $contact['name']);
logger('queue: slapdelivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>');
$deliver_status = slapper($owner,$contact['notify'],$data);
if($deliver_status == (-1))
if($deliver_status == (-1)) {
update_queue_time($q_item['id']);
else
$deadguys[] = $contact['notify'];
} else
remove_queue_item($q_item['id']);
}
break;
case NETWORK_DIASPORA:
if($contact['notify']) {
logger('queue: diaspora_delivery: item ' . $q_item['id'] . ' for ' . $contact['name']);
logger('queue: diaspora_delivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>');
$deliver_status = diaspora_transmit($owner,$contact,$data,$public,true);
if($deliver_status == (-1))
if($deliver_status == (-1)) {
update_queue_time($q_item['id']);
else
$deadguys[] = $contact['notify'];
} else
remove_queue_item($q_item['id']);
}
break;
@ -212,6 +227,7 @@ function queue_run(&$argv, &$argc){
break;
}
logger('Deliver status '.$deliver_status.' for item '.$q_item['id'].' to '.$contact['name'].' <'.$contact['url'].'>');
}
return;

View File

@ -1,261 +0,0 @@
<?php
/* update friendica */
define('APIBASE', 'http://github.com/api/v2/');
define('F9KREPO', 'friendica/friendica');
$up_totalfiles = 0;
$up_countfiles = 0;
$up_lastp = -1;
function checkUpdate(){
$r = fetch_url( APIBASE."json/repos/show/".F9KREPO."/tags" );
$tags = json_decode($r);
$tag = 0.0;
foreach ($tags->tags as $i=>$v){
$i = (float)$i;
if ($i>$tag) $tag=$i;
}
if ($tag==0.0) return false;
$f = fetch_url("https://raw.github.com/".F9KREPO."/".$tag."/boot.php","r");
preg_match("|'FRIENDICA_VERSION', *'([^']*)'|", $f, $m);
$version = $m[1];
$lv = explode(".", FRIENDICA_VERSION);
$rv = explode(".",$version);
foreach($lv as $i=>$v){
if ((int)$lv[$i] < (int)$rv[$i]) {
return array($tag, $version, "https://github.com/friendica/friendica/zipball/".$tag);
break;
}
}
return false;
}
function canWeWrite(){
$bd = dirname(dirname(__file__));
return is_writable( $bd."/boot.php" );
}
function out($txt){ echo "§".$txt."§"; ob_end_flush(); flush();}
function up_count($path){
$file_count = 0;
$dir_handle = opendir($path);
if (!$dir_handle) return -1;
while ($file = readdir($dir_handle)) {
if ($file == '.' || $file == '..') continue;
$file_count++;
if (is_dir($path . $file)){
$file_count += up_count($path . $file . DIRECTORY_SEPARATOR);
}
}
closedir($dir_handle);
return $file_count;
}
function up_unzip($file, $folder="/tmp"){
$folder.="/";
$zip = zip_open($file);
if ($zip) {
while ($zip_entry = zip_read($zip)) {
$zip_entry_name = zip_entry_name($zip_entry);
if (substr($zip_entry_name,strlen($zip_entry_name)-1,1)=="/"){
mkdir($folder.$zip_entry_name,0777, true);
} else {
$fp = fopen($folder.$zip_entry_name, "w");
if (zip_entry_open($zip, $zip_entry, "r")) {
$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
fwrite($fp,"$buf");
zip_entry_close($zip_entry);
fclose($fp);
}
}
}
zip_close($zip);
}
}
/**
* Walk recoursively in a folder and call a callback function on every
* dir entry.
* args:
* $dir string base dir to walk
* $callback function callback function
* $sort int 0: ascending, 1: descending
* $cb_argv any extra value passed to callback
*
* callback signature:
* function name($fn, $dir [, $argv])
* $fn string full dir entry name
* $dir string start dir path
* $argv any user value to callback
*
*/
function up_walktree($dir, $callback=Null, $sort=0, $cb_argv=Null , $startdir=Null){
if (is_null($callback)) return;
if (is_null($startdir)) $startdir = $dir;
$res = scandir($dir, $sort);
foreach($res as $i=>$v){
if ($v!="." && $v!=".."){
$fn = $dir."/".$v;
if ($sort==0) $callback($fn, $startdir, $cb_argv);
if (is_dir($fn)) up_walktree($fn, $callback, $sort, $cb_argv, $startdir);
if ($sort==1) $callback($fn, $startdir, $cb_argv);
}
}
}
function up_copy($fn, $dir){
global $up_countfiles, $up_totalfiles, $up_lastp;
$up_countfiles++; $prc=(int)(((float)$up_countfiles/(float)$up_totalfiles)*100);
if (strpos($fn, ".gitignore")>-1 || strpos($fn, ".htaccess")>-1) return;
$ddest = dirname(dirname(__file__));
$fd = str_replace($dir, $ddest, $fn);
if (is_dir($fn) && !is_dir($fd)) {
$re=mkdir($fd,0777,true);
}
if (!is_dir($fn)){
$re=copy($fn, $fd);
}
if ($re===false) {
out("ERROR. Abort.");
killme();
}
out("copy@Copy@$prc%");
}
function up_ftp($fn, $dir, $argv){
global $up_countfiles, $up_totalfiles, $up_lastp;
$up_countfiles++; $prc=(int)(((float)$up_countfiles/(float)$up_totalfiles)*100);
if (strpos($fn, ".gitignore")>-1 || strpos($fn, ".htaccess")>-1) return;
list($ddest, $conn_id) = $argv;
$l = strlen($ddest)-1;
if (substr($ddest,$l,1)=="/") $ddest = substr($ddest,0,$l);
$fd = str_replace($dir, $ddest, $fn);
if (is_dir($fn)){
if (ftp_nlist($conn_id, $fd)===false) {
$ret = ftp_mkdir($conn_id, $fd);
} else {
$ret=true;
}
} else {
$ret = ftp_put($conn_id, $fd, $fn, FTP_BINARY);
}
if (!$ret) {
out("ERROR. Abort.");
killme();
}
out("copy@Copy@$prc%");
}
function up_rm($fn, $dir){
if (is_dir($fn)){
rmdir($fn);
} else {
unlink($fn);
}
}
function up_dlfile($url, $file) {
$in = fopen ($url, "r");
$out = fopen ($file, "w");
$fs = filesize($url);
if (!$in || !$out) return false;
$s=0; $count=0;
while (!feof ($in)) {
$line = fgets ($in, 1024);
fwrite( $out, $line);
$count++; $s += strlen($line);
if ($count==50){
$count=0;
$sp=$s/1024.0; $ex="Kb";
if ($sp>1024) { $sp=$sp/1024; $ex="Mb"; }
if ($sp>1024) { $sp=$sp/1024; $ex="Gb"; }
$sp = ((int)($sp*100))/100;
out("dwl@Download@".$sp.$ex);
}
}
fclose($in);
return true;
}
function doUpdate($remotefile, $ftpdata=false){
global $up_totalfiles;
$localtmpfile = tempnam("/tmp", "fk");
out("dwl@Download@starting...");
$rt= up_dlfile($remotefile, $localtmpfile);
if ($rt==false || filesize($localtmpfile)==0){
out("dwl@Download@ERROR.");
unlink($localtmpfile);
return;
}
out("dwl@Download@Ok.");
out("unzip@Unzip@");
$tmpdirname = $localfile."ex";
mkdir($tmpdirname);
up_unzip($localtmpfile, $tmpdirname);
$basedir = glob($tmpdirname."/*"); $basedir=$basedir[0];
out ("unzip@Unzip@Ok.");
$up_totalfiles = up_count($basedir."/");
if (canWeWrite()){
out("copy@Copy@");
up_walktree($basedir, 'up_copy');
}
if ($ftpdata!==false && is_array($ftpdata) && $ftpdata['ftphost']!="" ){
out("ftpcon@Connect to FTP@");
$conn_id = ftp_connect($ftpdata['ftphost']);
$login_result = ftp_login($conn_id, $ftpdata['ftpuser'], $ftpdata['ftppwd']);
if ((!$conn_id) || (!$login_result)) {
out("ftpcon@Connect to FTP@FAILED");
up_clean($tmpdirname, $localtmpfile);
return;
} else {
out("ftpcon@Connect to FTP@Ok.");
}
out("copy@Copy@");
up_walktree($basedir, 'up_ftp', 0, array( $ftpdata['ftppath'], $conn_id));
ftp_close($conn_id);
}
up_clean($tmpdirname, $localtmpfile);
}
function up_clean($tmpdirname, $localtmpfile){
out("clean@Clean up@");
unlink($localtmpfile);
up_walktree($tmpdirname, 'up_rm', 1);
rmdir($tmpdirname);
out("clean@Clean up@Ok.");
}

View File

@ -139,15 +139,16 @@ function poco_load($cid,$uid = 0,$zcid = 0,$url = null) {
poco_check($profile_url, $name, $network, $profile_photo, $about, $location, $gender, $keywords, $connect_url, $updated, $generation, $cid, $uid, $zcid);
// Update the Friendica contacts. Diaspora is doing it via a message. (See include/diaspora.php)
if (($location != "") OR ($about != "") OR ($keywords != "") OR ($gender != ""))
q("UPDATE `contact` SET `location` = '%s', `about` = '%s', `keywords` = '%s', `gender` = '%s'
WHERE `nurl` = '%s' AND NOT `self` AND `network` = '%s'",
dbesc($location),
dbesc($about),
dbesc($keywords),
dbesc($gender),
dbesc(normalise_link($profile_url)),
dbesc(NETWORK_DFRN));
// Deactivated because we now update Friendica contacts in dfrn.php
//if (($location != "") OR ($about != "") OR ($keywords != "") OR ($gender != ""))
// q("UPDATE `contact` SET `location` = '%s', `about` = '%s', `keywords` = '%s', `gender` = '%s'
// WHERE `nurl` = '%s' AND NOT `self` AND `network` = '%s'",
// dbesc($location),
// dbesc($about),
// dbesc($keywords),
// dbesc($gender),
// dbesc(normalise_link($profile_url)),
// dbesc(NETWORK_DFRN));
}
logger("poco_load: loaded $total entries",LOGGER_DEBUG);
@ -227,6 +228,8 @@ function poco_check($profile_url, $name, $network, $profile_photo, $about, $loca
$server_url = $x[0]["server_url"];
$nick = $x[0]["nick"];
$addr = $x[0]["addr"];
$alias = $x[0]["alias"];
$notify = $x[0]["notify"];
} else {
$created = "0000-00-00 00:00:00";
$server_url = "";
@ -234,6 +237,8 @@ function poco_check($profile_url, $name, $network, $profile_photo, $about, $loca
$urlparts = parse_url($profile_url);
$nick = end(explode("/", $urlparts["path"]));
$addr = "";
$alias = "";
$notify = "";
}
if ((($network == "") OR ($name == "") OR ($addr == "") OR ($profile_photo == "") OR ($server_url == "") OR $alternate)
@ -246,6 +251,8 @@ function poco_check($profile_url, $name, $network, $profile_photo, $about, $loca
$name = $data["name"];
$nick = $data["nick"];
$addr = $data["addr"];
$alias = $data["alias"];
$notify = $data["notify"];
$profile_url = $data["url"];
$profile_photo = $data["photo"];
$server_url = $data["baseurl"];
@ -283,76 +290,25 @@ function poco_check($profile_url, $name, $network, $profile_photo, $about, $loca
poco_check_server($server_url, $network);
if(count($x)) {
$gcid = $x[0]['id'];
$gcontact = array("url" => $profile_url,
"addr" => $addr,
"alias" => $alias,
"name" => $name,
"network" => $network,
"photo" => $profile_photo,
"about" => $about,
"location" => $location,
"gender" => $gender,
"keywords" => $keywords,
"server_url" => $server_url,
"connect" => $connect_url,
"notify" => $notify,
"updated" => $updated,
"generation" => $generation);
if (($location == "") AND ($x[0]['location'] != ""))
$location = $x[0]['location'];
$gcid = update_gcontact($gcontact);
if (($about == "") AND ($x[0]['about'] != ""))
$about = $x[0]['about'];
if (($gender == "") AND ($x[0]['gender'] != ""))
$gender = $x[0]['gender'];
if (($keywords == "") AND ($x[0]['keywords'] != ""))
$keywords = $x[0]['keywords'];
if (($addr == "") AND ($x[0]['addr'] != ""))
$addr = $x[0]['addr'];
if (($generation == 0) AND ($x[0]['generation'] > 0))
$generation = $x[0]['generation'];
if($x[0]['name'] != $name || $x[0]['photo'] != $profile_photo || $x[0]['updated'] < $updated) {
q("UPDATE `gcontact` SET `name` = '%s', `addr` = '%s', `network` = '%s', `photo` = '%s', `connect` = '%s', `url` = '%s', `server_url` = '%s',
`updated` = '%s', `location` = '%s', `about` = '%s', `keywords` = '%s', `gender` = '%s', `generation` = %d
WHERE (`generation` >= %d OR `generation` = 0) AND `nurl` = '%s'",
dbesc($name),
dbesc($addr),
dbesc($network),
dbesc($profile_photo),
dbesc($connect_url),
dbesc($profile_url),
dbesc($server_url),
dbesc($updated),
dbesc($location),
dbesc($about),
dbesc($keywords),
dbesc($gender),
intval($generation),
intval($generation),
dbesc(normalise_link($profile_url))
);
}
} else {
q("INSERT INTO `gcontact` (`name`, `nick`, `addr`, `network`, `url`, `nurl`, `photo`, `connect`, `server_url`, `created`, `updated`, `location`, `about`, `keywords`, `gender`, `generation`)
VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d)",
dbesc($name),
dbesc($nick),
dbesc($addr),
dbesc($network),
dbesc($profile_url),
dbesc(normalise_link($profile_url)),
dbesc($profile_photo),
dbesc($connect_url),
dbesc($server_url),
dbesc(datetime_convert()),
dbesc($updated),
dbesc($location),
dbesc($about),
dbesc($keywords),
dbesc($gender),
intval($generation)
);
$x = q("SELECT * FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1",
dbesc(normalise_link($profile_url))
);
if(count($x))
$gcid = $x[0]['id'];
}
if(! $gcid)
if(!$gcid)
return $gcid;
$r = q("SELECT * FROM `glink` WHERE `cid` = %d AND `uid` = %d AND `gcid` = %d AND `zcid` = %d LIMIT 1",
@ -379,13 +335,6 @@ function poco_check($profile_url, $name, $network, $profile_photo, $about, $loca
);
}
// For unknown reasons there are sometimes duplicates
q("DELETE FROM `gcontact` WHERE `nurl` = '%s' AND `id` != %d AND
NOT EXISTS (SELECT `gcid` FROM `glink` WHERE `gcid` = `gcontact`.`id`)",
dbesc(normalise_link($profile_url)),
intval($gcid)
);
return $gcid;
}
@ -698,6 +647,10 @@ function poco_to_boolean($val) {
function poco_check_server($server_url, $network = "", $force = false) {
// Unify the server address
$server_url = trim($server_url, "/");
$server_url = str_replace("/index.php", "", $server_url);
if ($server_url == "")
return false;
@ -769,17 +722,23 @@ function poco_check_server($server_url, $network = "", $force = false) {
// Test for Diaspora
$serverret = z_fetch_url($server_url);
$lines = explode("\n",$serverret["header"]);
if(count($lines))
foreach($lines as $line) {
$line = trim($line);
if(stristr($line,'X-Diaspora-Version:')) {
$platform = "Diaspora";
$version = trim(str_replace("X-Diaspora-Version:", "", $line));
$version = trim(str_replace("x-diaspora-version:", "", $version));
$network = NETWORK_DIASPORA;
if (!$serverret["success"] OR ($serverret["body"] == ""))
$failure = true;
else {
$lines = explode("\n",$serverret["header"]);
if(count($lines))
foreach($lines as $line) {
$line = trim($line);
if(stristr($line,'X-Diaspora-Version:')) {
$platform = "Diaspora";
$version = trim(str_replace("X-Diaspora-Version:", "", $line));
$version = trim(str_replace("x-diaspora-version:", "", $version));
$network = NETWORK_DIASPORA;
$versionparts = explode("-", $version);
$version = $versionparts[0];
}
}
}
}
}
if (!$failure) {
@ -1290,18 +1249,30 @@ function poco_discover_federation() {
return;
}
// Discover Friendica, Hubzilla and Diaspora servers
$serverdata = fetch_url("http://the-federation.info/pods.json");
if (!$serverdata)
return;
if ($serverdata) {
$servers = json_decode($serverdata);
$servers = json_decode($serverdata);
foreach($servers->pods AS $server)
poco_check_server("https://".$server->host);
}
foreach($servers->pods AS $server)
poco_check_server("https://".$server->host);
// Discover GNU Social Servers
if (!get_config('system','ostatus_disabled')) {
$serverdata = "http://gstools.org/api/get_open_instances/";
$result = z_fetch_url($serverdata);
if ($result["success"]) {
$servers = json_decode($result["body"]);
foreach($servers->data AS $server)
poco_check_server($server->instance_address);
}
}
set_config('poco','last_federation_discovery', time());
}
function poco_discover($complete = false) {
@ -1481,4 +1452,214 @@ function poco_discover_server($data, $default_generation = 0) {
}
return $success;
}
/**
* @brief Fetch the gcontact id, add an entry if not existed
*
* @param arr $contact contact array
* @return bool|int Returns false if not found, integer if contact was found
*/
function get_gcontact_id($contact) {
$gcontact_id = 0;
if ($contact["network"] == NETWORK_STATUSNET)
$contact["network"] = NETWORK_OSTATUS;
$r = q("SELECT `id` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 2",
dbesc(normalise_link($contact["url"])));
if ($r)
$gcontact_id = $r[0]["id"];
else {
q("INSERT INTO `gcontact` (`name`, `nick`, `addr` , `network`, `url`, `nurl`, `photo`, `created`, `updated`, `location`, `about`, `generation`)
VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d)",
dbesc($contact["name"]),
dbesc($contact["nick"]),
dbesc($contact["addr"]),
dbesc($contact["network"]),
dbesc($contact["url"]),
dbesc(normalise_link($contact["url"])),
dbesc($contact["photo"]),
dbesc(datetime_convert()),
dbesc(datetime_convert()),
dbesc($contact["location"]),
dbesc($contact["about"]),
intval($contact["generation"])
);
$r = q("SELECT `id` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 2",
dbesc(normalise_link($contact["url"])));
if ($r)
$gcontact_id = $r[0]["id"];
}
if ((count($r) > 1) AND ($gcontact_id > 0) AND ($contact["url"] != ""))
q("DELETE FROM `gcontact` WHERE `nurl` = '%s' AND `id` != %d",
dbesc(normalise_link($contact["url"])),
intval($gcontact_id));
return $gcontact_id;
}
/**
* @brief Updates the gcontact table from a given array
*
* @param arr $contact contact array
* @return bool|int Returns false if not found, integer if contact was found
*/
function update_gcontact($contact) {
/// @todo update contact table as well
$gcontact_id = get_gcontact_id($contact);
if (!$gcontact_id)
return false;
$r = q("SELECT `name`, `nick`, `photo`, `location`, `about`, `addr`, `generation`, `birthday`, `gender`, `keywords`,
`hide`, `nsfw`, `network`, `alias`, `notify`, `server_url`, `connect`, `updated`, `url`
FROM `gcontact` WHERE `id` = %d LIMIT 1",
intval($gcontact_id));
// Get all field names
$fields = array();
foreach ($r[0] AS $field => $data)
$fields[$field] = $data;
unset($fields["url"]);
unset($fields["updated"]);
// assign all unassigned fields from the database entry
foreach ($fields AS $field => $data)
if (!isset($contact[$field]))
$contact[$field] = $r[0][$field];
if ($contact["network"] == NETWORK_STATUSNET)
$contact["network"] = NETWORK_OSTATUS;
if (!isset($contact["updated"]))
$contact["updated"] = datetime_convert();
// Check if any field changed
$update = false;
unset($fields["generation"]);
foreach ($fields AS $field => $data)
if ($contact[$field] != $r[0][$field])
$update = true;
if ($contact["generation"] < $r[0]["generation"])
$update = true;
if ($update) {
q("UPDATE `gcontact` SET `photo` = '%s', `name` = '%s', `nick` = '%s', `addr` = '%s', `network` = '%s',
`birthday` = '%s', `gender` = '%s', `keywords` = '%s', `hide` = %d, `nsfw` = %d,
`alias` = '%s', `notify` = '%s', `url` = '%s',
`location` = '%s', `about` = '%s', `generation` = %d, `updated` = '%s',
`server_url` = '%s', `connect` = '%s'
WHERE `nurl` = '%s' AND (`generation` = 0 OR `generation` >= %d)",
dbesc($contact["photo"]), dbesc($contact["name"]), dbesc($contact["nick"]),
dbesc($contact["addr"]), dbesc($contact["network"]), dbesc($contact["birthday"]),
dbesc($contact["gender"]), dbesc($contact["keywords"]), intval($contact["hide"]),
intval($contact["nsfw"]), dbesc($contact["alias"]), dbesc($contact["notify"]),
dbesc($contact["url"]), dbesc($contact["location"]), dbesc($contact["about"]),
intval($contact["generation"]), dbesc($contact["updated"]),
dbesc($contact["server_url"]), dbesc($contact["connect"]),
dbesc(normalise_link($contact["url"])), intval($contact["generation"]));
}
return $gcontact_id;
}
/**
* @brief Updates the gcontact entry from probe
*
* @param str $url profile link
*/
function update_gcontact_from_probe($url) {
$data = probe_url($url);
if ($data["network"] != NETWORK_PHANTOM)
update_gcontact($data);
}
/**
* @brief Fetches users of given GNU Social server
*
* If the "Statistics" plugin is enabled (See http://gstools.org/ for details) we query user data with this.
*
* @param str $server Server address
*/
function gs_fetch_users($server) {
logger("Fetching users from GNU Social server ".$server, LOGGER_DEBUG);
$a = get_app();
$url = $server."/main/statistics";
$result = z_fetch_url($url);
if (!$result["success"])
return false;
$statistics = json_decode($result["body"]);
if (is_object($statistics->config)) {
if ($statistics->config->instance_with_ssl)
$server = "https://";
else
$server = "http://";
$server .= $statistics->config->instance_address;
$hostname = $statistics->config->instance_address;
} else {
if ($statistics->instance_with_ssl)
$server = "https://";
else
$server = "http://";
$server .= $statistics->instance_address;
$hostname = $statistics->instance_address;
}
if (is_object($statistics->users))
foreach ($statistics->users AS $nick => $user) {
$profile_url = $server."/".$user->nickname;
$contact = array("url" => $profile_url,
"name" => $user->fullname,
"addr" => $user->nickname."@".$hostname,
"nick" => $user->nickname,
"about" => $user->bio,
"network" => NETWORK_OSTATUS,
"photo" => $a->get_baseurl()."/images/person-175.jpg");
get_gcontact_id($contact);
}
}
/**
* @brief Asking GNU Social server on a regular base for their user data
*
*/
function gs_discover() {
$requery_days = intval(get_config("system", "poco_requery_days"));
$last_update = date("c", time() - (60 * 60 * 24 * $requery_days));
$r = q("SELECT `nurl`, `url` FROM `gserver` WHERE `last_contact` >= `last_failure` AND `network` = '%s' AND `last_poco_query` < '%s' ORDER BY RAND() LIMIT 5",
dbesc(NETWORK_OSTATUS), dbesc($last_update));
if (!$r)
return;
foreach ($r AS $server) {
gs_fetch_users($server["url"]);
q("UPDATE `gserver` SET `last_poco_query` = '%s' WHERE `nurl` = '%s'", dbesc(datetime_convert()), dbesc($server["nurl"]));
}
}
?>

View File

@ -20,10 +20,10 @@ function replace_macros($s,$r) {
$stamp1 = microtime(true);
$a = get_app();
// pass $baseurl to all templates
$r['$baseurl'] = z_root();
$r['$baseurl'] = $a->get_baseurl();
$t = $a->template_engine();
try {
@ -829,35 +829,6 @@ function qp($s) {
return str_replace ("%","=",rawurlencode($s));
}}
if(! function_exists('get_mentions')) {
/**
* @param array $item
* @return string html for mentions #FIXME: remove html
*/
function get_mentions($item) {
$o = '';
if(! strlen($item['tag']))
return $o;
$arr = explode(',',$item['tag']);
foreach($arr as $x) {
$matches = null;
if(preg_match('/@\[url=([^\]]*)\]/',$x,$matches)) {
$o .= "\t\t" . '<link rel="ostatus:attention" href="' . $matches[1] . '" />' . "\r\n";
$o .= "\t\t" . '<link rel="mentioned" href="' . $matches[1] . '" />' . "\r\n";
}
}
if (!$item['private']) {
$o .= "\t\t".'<link rel="ostatus:attention" href="http://activityschema.org/collection/public"/>'."\r\n";
$o .= "\t\t".'<link rel="mentioned" href="http://activityschema.org/collection/public"/>'."\r\n";
}
return $o;
}}
if(! function_exists('contact_block')) {
/**
* Get html for contact block.
@ -895,9 +866,9 @@ function contact_block() {
$micropro = Null;
} else {
$r = q("SELECT * FROM `contact`
WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0
AND `hidden` = 0 AND `archive` = 0
$r = q("SELECT `id`, `uid`, `addr`, `url`, `name`, `micro`, `network` FROM `contact`
WHERE `uid` = %d AND NOT `self` AND NOT `blocked` AND NOT `pending`
AND NOT `hidden` AND NOT `archive`
AND `network` IN ('%s', '%s', '%s') ORDER BY RAND() LIMIT %d",
intval($a->profile['uid']),
dbesc(NETWORK_DFRN),
@ -1415,7 +1386,14 @@ function prepare_body(&$item,$attach = false, $preview = false) {
$item['hashtags'] = $hashtags;
$item['mentions'] = $mentions;
put_item_in_cache($item, true);
// Update the cached values if there is no "zrl=..." on the links
$update = (!local_user() and !remote_user() and ($item["uid"] == 0));
// Or update it if the current viewer is the intented viewer
if (($item["uid"] == local_user()) AND ($item["uid"] != 0))
$update = true;
put_item_in_cache($item, $update);
$s = $item["rendered-html"];
$prep_arr = array('item' => $item, 'html' => $s, 'preview' => $preview);
@ -1526,7 +1504,7 @@ function prepare_body(&$item,$attach = false, $preview = false) {
$pos = strpos($s, $spoilersearch);
$rnd = random_string(8);
$spoilerreplace = '<br /> <span id="spoiler-wrap-'.$rnd.'" style="white-space:nowrap;" class="fakelink" onclick="openClose(\'spoiler-'.$rnd.'\');">'.sprintf(t('Click to open/close')).'</span>'.
$spoilerreplace = '<br /> <span id="spoiler-wrap-'.$rnd.'" class="spoiler-wrap fakelink" onclick="openClose(\'spoiler-'.$rnd.'\');">'.sprintf(t('Click to open/close')).'</span>'.
'<blockquote class="spoiler" id="spoiler-'.$rnd.'" style="display: none;">';
$s = substr($s, 0, $pos).$spoilerreplace.substr($s, $pos+strlen($spoilersearch));
}
@ -1538,7 +1516,7 @@ function prepare_body(&$item,$attach = false, $preview = false) {
$pos = strpos($s, $authorsearch);
$rnd = random_string(8);
$authorreplace = '<br /> <span id="author-wrap-'.$rnd.'" style="white-space:nowrap;" class="fakelink" onclick="openClose(\'author-'.$rnd.'\');">'.sprintf(t('Click to open/close')).'</span>'.
$authorreplace = '<br /> <span id="author-wrap-'.$rnd.'" class="author-wrap fakelink" onclick="openClose(\'author-'.$rnd.'\');">'.sprintf(t('Click to open/close')).'</span>'.
'<blockquote class="author" id="author-'.$rnd.'" style="display: block;">';
$s = substr($s, 0, $pos).$authorreplace.substr($s, $pos+strlen($authorsearch));
}
@ -1650,54 +1628,6 @@ function get_cats_and_terms($item) {
return array($categories, $folders);
}
if(! function_exists('feed_hublinks')) {
/**
* return atom link elements for all of our hubs
* @return string hub link xml elements
*/
function feed_hublinks() {
$a = get_app();
$hub = get_config('system','huburl');
$hubxml = '';
if(strlen($hub)) {
$hubs = explode(',', $hub);
if(count($hubs)) {
foreach($hubs as $h) {
$h = trim($h);
if(! strlen($h))
continue;
if ($h === '[internal]')
$h = z_root() . '/pubsubhubbub';
$hubxml .= '<link rel="hub" href="' . xmlify($h) . '" />' . "\n" ;
}
}
}
return $hubxml;
}}
if(! function_exists('feed_salmonlinks')) {
/**
* return atom link elements for salmon endpoints
* @param string $nick user nickname
* @return string salmon link xml elements
*/
function feed_salmonlinks($nick) {
$a = get_app();
$salmon = '<link rel="salmon" href="' . xmlify(z_root() . '/salmon/' . $nick) . '" />' . "\n" ;
// old style links that status.net still needed as of 12/2010
$salmon .= ' <link rel="http://salmon-protocol.org/ns/salmon-replies" href="' . xmlify(z_root() . '/salmon/' . $nick) . '" />' . "\n" ;
$salmon .= ' <link rel="http://salmon-protocol.org/ns/salmon-mention" href="' . xmlify(z_root() . '/salmon/' . $nick) . '" />' . "\n" ;
return $salmon;
}}
if(! function_exists('get_plink')) {
/**
* get private link for item

View File

@ -1,6 +1,6 @@
<?php
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`,
$items = q("SELECT `uid`, `created`, `edited`, `commented`, `received`, `changed`, `wall`, `private`, `pubmail`, `moderated`, `visible`, `spam`, `starred`, `bookmark`, `contact-id`, `gcontact-id`,
`deleted`, `origin`, `forum_mode`, `mention`, `network` FROM `item` WHERE `id` = %d AND (`parent` = %d OR `parent` = 0) LIMIT 1", intval($itemid), intval($itemid));
if (!$items)
@ -66,6 +66,7 @@ function add_thread($itemid, $onlyshadow = false) {
unset($item[0]['id']);
$item[0]['uid'] = 0;
$item[0]['origin'] = 0;
$item[0]['contact-id'] = get_contact($item[0]['author-link'], 0);
$public_shadow = item_store($item[0], false, false, true);
@ -111,8 +112,8 @@ function update_thread_uri($itemuri, $uid) {
}
function update_thread($itemid, $setmention = false) {
$items = q("SELECT `uid`, `guid`, `title`, `body`, `created`, `edited`, `commented`, `received`, `changed`, `wall`, `private`, `pubmail`, `moderated`, `visible`, `spam`, `starred`, `bookmark`, `contact-id`,
`deleted`, `origin`, `forum_mode`, `network` FROM `item` WHERE `id` = %d AND (`parent` = %d OR `parent` = 0) LIMIT 1", intval($itemid), intval($itemid));
$items = q("SELECT `uid`, `guid`, `title`, `body`, `created`, `edited`, `commented`, `received`, `changed`, `wall`, `private`, `pubmail`, `moderated`, `visible`, `spam`, `starred`, `bookmark`, `contact-id`, `gcontact-id`,
`deleted`, `origin`, `forum_mode`, `network`, `rendered-html`, `rendered-hash` FROM `item` WHERE `id` = %d AND (`parent` = %d OR `parent` = 0) LIMIT 1", intval($itemid), intval($itemid));
if (!$items)
return;
@ -125,7 +126,7 @@ function update_thread($itemid, $setmention = false) {
$sql = "";
foreach ($item AS $field => $data)
if (!in_array($field, array("guid", "title", "body"))) {
if (!in_array($field, array("guid", "title", "body", "rendered-html", "rendered-hash"))) {
if ($sql != "")
$sql .= ", ";
@ -142,9 +143,11 @@ function update_thread($itemid, $setmention = false) {
if (!$items)
return;
$result = q("UPDATE `item` SET `title` = '%s', `body` = '%s' WHERE `id` = %d",
$result = q("UPDATE `item` SET `title` = '%s', `body` = '%s', `rendered-html` = '%s', `rendered-hash` = '%s' WHERE `id` = %d",
dbesc($item["title"]),
dbesc($item["body"]),
dbesc($item["rendered-html"]),
dbesc($item["rendered-hash"]),
intval($items[0]["id"])
);
logger("Updating public shadow for post ".$items[0]["id"]." - guid ".$item["guid"]." Result: ".print_r($result, true), LOGGER_DEBUG);

View File

@ -407,15 +407,6 @@ if(x($_SESSION,'sysmsg_info')) {
call_hooks('page_end', $a->page['content']);
/**
*
* Add a place for the pause/resume Ajax indicator
*
*/
$a->page['content'] .= '<div id="pause"></div>';
/**
*
* Add the navigation (menu) template
@ -556,6 +547,7 @@ EOT;
$page = $a->page;
$profile = $a->profile;
header("X-Friendica-Version: ".FRIENDICA_VERSION);
header("Content-type: text/html; charset=utf-8");

215
js/acl.js
View File

@ -1,49 +1,56 @@
function ACL(backend_url, preset, automention){
that = this;
function ACL(backend_url, preset, automention, is_mobile){
that.url = backend_url;
that.automention = automention;
this.url = backend_url;
this.automention = automention;
this.is_mobile = is_mobile;
that.kp_timer = null;
this.kp_timer = null;
if (preset==undefined) preset = [];
that.allow_cid = (preset[0] || []);
that.allow_gid = (preset[1] || []);
that.deny_cid = (preset[2] || []);
that.deny_gid = (preset[3] || []);
that.group_uids = [];
that.nw = 4; //items per row. should be calulated from #acl-list.width
that.list_content = $("#acl-list-content");
that.item_tpl = unescape($(".acl-list-item[rel=acl-template]").html());
that.showall = $("#acl-showall");
this.allow_cid = (preset[0] || []);
this.allow_gid = (preset[1] || []);
this.deny_cid = (preset[2] || []);
this.deny_gid = (preset[3] || []);
this.group_uids = [];
if (preset.length==0) that.showall.addClass("selected");
if (this.is_mobile) {
this.nw = 1;
} else {
this.nw = 4;
}
this.list_content = $("#acl-list-content");
this.item_tpl = unescape($(".acl-list-item[rel=acl-template]").html());
this.showall = $("#acl-showall");
if (preset.length==0) this.showall.addClass("selected");
/*events*/
that.showall.click(that.on_showall);
$(document).on("click", ".acl-button-show", that.on_button_show);
$(document).on("click", ".acl-button-hide", that.on_button_hide);
$("#acl-search").keypress(that.on_search);
$("#acl-wrapper").parents("form").submit(that.on_submit);
this.showall.click(this.on_showall.bind(this));
$(document).on("click", ".acl-button-show", this.on_button_show.bind(this));
$(document).on("click", ".acl-button-hide", this.on_button_hide.bind(this));
$("#acl-search").keypress(this.on_search.bind(this));
$("#acl-wrapper").parents("form").submit(this.on_submit.bind(this));
/* add/remove mentions */
that.element = $("#profile-jot-text");
that.htmlelm = that.element.get()[0];
this.element = $("#profile-jot-text");
this.htmlelm = this.element.get()[0];
/* startup! */
that.get(0,100);
this.get(0,100);
}
ACL.prototype.remove_mention = function(id) {
if (!that.automention) return;
var nick = that.data[id].nick;
if (!this.automention) return;
var nick = this.data[id].nick;
var searchText = "@"+nick+"+"+id+" ";
if (tinyMCE.activeEditor===null) {
start = that.element.val().indexOf(searchText);
start = this.element.val().indexOf(searchText);
if ( start<0) return;
end = start+searchText.length;
that.element.setSelection(start,end).replaceSelectedText('').collapseSelection(false);
this.element.setSelection(start,end).replaceSelectedText('').collapseSelection(false);
} else {
start = tinyMCE.activeEditor.getContent({format : 'raw'}).search( searchText );
if ( start<0 ) return;
@ -54,12 +61,12 @@ ACL.prototype.remove_mention = function(id) {
}
ACL.prototype.add_mention = function(id) {
if (!that.automention) return;
var nick = that.data[id].nick;
if (!this.automention) return;
var nick = this.data[id].nick;
var searchText = "@"+nick+"+"+id+" ";
if (tinyMCE.activeEditor===null) {
if ( that.element.val().indexOf( searchText) >= 0 ) return;
that.element.val( searchText + that.element.val() );
if ( this.element.val().indexOf( searchText) >= 0 ) return;
this.element.val( searchText + this.element.val() );
} else {
if ( tinyMCE.activeEditor.getContent({format : 'raw'}).search(searchText) >= 0 ) return;
tinyMCE.activeEditor.dom.add(tinyMCE.activeEditor.getBody(), 'dummy', {}, searchText);
@ -68,46 +75,46 @@ ACL.prototype.add_mention = function(id) {
ACL.prototype.on_submit = function(){
aclfileds = $("#acl-fields").html("");
$(that.allow_gid).each(function(i,v){
$(this.allow_gid).each(function(i,v){
aclfileds.append("<input type='hidden' name='group_allow[]' value='"+v+"'>");
});
$(that.allow_cid).each(function(i,v){
$(this.allow_cid).each(function(i,v){
aclfileds.append("<input type='hidden' name='contact_allow[]' value='"+v+"'>");
});
$(that.deny_gid).each(function(i,v){
$(this.deny_gid).each(function(i,v){
aclfileds.append("<input type='hidden' name='group_deny[]' value='"+v+"'>");
});
$(that.deny_cid).each(function(i,v){
$(this.deny_cid).each(function(i,v){
aclfileds.append("<input type='hidden' name='contact_deny[]' value='"+v+"'>");
});
}
ACL.prototype.search = function(){
var srcstr = $("#acl-search").val();
that.list_content.html("");
that.get(0,100, srcstr);
this.list_content.html("");
this.get(0,100, srcstr);
}
ACL.prototype.on_search = function(event){
if (that.kp_timer) clearTimeout(that.kp_timer);
that.kp_timer = setTimeout( that.search, 1000);
if (this.kp_timer) clearTimeout(this.kp_timer);
this.kp_timer = setTimeout( this.search.bind(this), 1000);
}
ACL.prototype.on_showall = function(event){
event.preventDefault()
event.stopPropagation();
if (that.showall.hasClass("selected")){
if (this.showall.hasClass("selected")){
return false;
}
that.showall.addClass("selected");
this.showall.addClass("selected");
that.allow_cid = [];
that.allow_gid = [];
that.deny_cid = [];
that.deny_gid = [];
this.allow_cid = [];
this.allow_gid = [];
this.deny_cid = [];
this.deny_gid = [];
that.update_view();
this.update_view();
return false;
}
@ -116,12 +123,8 @@ ACL.prototype.on_button_show = function(event){
event.preventDefault()
event.stopImmediatePropagation()
event.stopPropagation();
/*that.showall.removeClass("selected");
$(this).siblings(".acl-button-hide").removeClass("selected");
$(this).toggleClass("selected");*/
that.set_allow($(this).parent().attr('id'));
this.set_allow($(event.target).parent().attr('id'));
return false;
}
@ -130,11 +133,7 @@ ACL.prototype.on_button_hide = function(event){
event.stopImmediatePropagation()
event.stopPropagation();
/*that.showall.removeClass("selected");
$(this).siblings(".acl-button-show").removeClass("selected");
$(this).toggleClass("selected");*/
that.set_deny($(this).parent().attr('id'));
this.set_deny($(event.target).parent().attr('id'));
return false;
}
@ -145,25 +144,25 @@ ACL.prototype.set_allow = function(itemid){
switch(type){
case "g":
if (that.allow_gid.indexOf(id)<0){
that.allow_gid.push(id)
if (this.allow_gid.indexOf(id)<0){
this.allow_gid.push(id)
}else {
that.allow_gid.remove(id);
this.allow_gid.remove(id);
}
if (that.deny_gid.indexOf(id)>=0) that.deny_gid.remove(id);
if (this.deny_gid.indexOf(id)>=0) this.deny_gid.remove(id);
break;
case "c":
if (that.allow_cid.indexOf(id)<0){
that.allow_cid.push(id)
if (that.data[id].forum=="1") that.add_mention(id);
if (this.allow_cid.indexOf(id)<0){
this.allow_cid.push(id)
if (this.data[id].forum=="1") this.add_mention(id);
} else {
that.allow_cid.remove(id);
if (that.data[id].forum=="1") that.remove_mention(id);
this.allow_cid.remove(id);
if (this.data[id].forum=="1") this.remove_mention(id);
}
if (that.deny_cid.indexOf(id)>=0) that.deny_cid.remove(id);
if (this.deny_cid.indexOf(id)>=0) this.deny_cid.remove(id);
break;
}
that.update_view();
this.update_view();
}
ACL.prototype.set_deny = function(itemid){
@ -172,34 +171,34 @@ ACL.prototype.set_deny = function(itemid){
switch(type){
case "g":
if (that.deny_gid.indexOf(id)<0){
that.deny_gid.push(id)
if (this.deny_gid.indexOf(id)<0){
this.deny_gid.push(id)
} else {
that.deny_gid.remove(id);
this.deny_gid.remove(id);
}
if (that.allow_gid.indexOf(id)>=0) that.allow_gid.remove(id);
if (this.allow_gid.indexOf(id)>=0) this.allow_gid.remove(id);
break;
case "c":
if (that.data[id].forum=="1") that.remove_mention(id);
if (that.deny_cid.indexOf(id)<0){
that.deny_cid.push(id)
if (this.data[id].forum=="1") this.remove_mention(id);
if (this.deny_cid.indexOf(id)<0){
this.deny_cid.push(id)
} else {
that.deny_cid.remove(id);
this.deny_cid.remove(id);
}
if (that.allow_cid.indexOf(id)>=0) that.allow_cid.remove(id);
if (this.allow_cid.indexOf(id)>=0) this.allow_cid.remove(id);
break;
}
that.update_view();
this.update_view();
}
ACL.prototype.is_show_all = function() {
return (that.allow_gid.length==0 && that.allow_cid.length==0 &&
that.deny_gid.length==0 && that.deny_cid.length==0);
return (this.allow_gid.length==0 && this.allow_cid.length==0 &&
this.deny_gid.length==0 && this.deny_cid.length==0);
}
ACL.prototype.update_view = function(){
if (this.is_show_all()){
that.showall.addClass("selected");
this.showall.addClass("selected");
/* jot acl */
$('#jot-perms-icon').removeClass('lock').addClass('unlock');
$('#jot-public').show();
@ -209,7 +208,7 @@ ACL.prototype.update_view = function(){
}
} else {
that.showall.removeClass("selected");
this.showall.removeClass("selected");
/* jot acl */
$('#jot-perms-icon').removeClass('unlock').addClass('lock');
$('#jot-public').hide();
@ -220,29 +219,29 @@ ACL.prototype.update_view = function(){
$(this).removeClass("groupshow grouphide");
});
$("#acl-list-content .acl-list-item").each(function(){
itemid = $(this).attr('id');
$("#acl-list-content .acl-list-item").each(function(index, element){
itemid = $(element).attr('id');
type = itemid[0];
id = parseInt(itemid.substr(1));
btshow = $(this).children(".acl-button-show").removeClass("selected");
bthide = $(this).children(".acl-button-hide").removeClass("selected");
btshow = $(element).children(".acl-button-show").removeClass("selected");
bthide = $(element).children(".acl-button-hide").removeClass("selected");
switch(type){
case "g":
var uclass = "";
if (that.allow_gid.indexOf(id)>=0){
if (this.allow_gid.indexOf(id)>=0){
btshow.addClass("selected");
bthide.removeClass("selected");
uclass="groupshow";
}
if (that.deny_gid.indexOf(id)>=0){
if (this.deny_gid.indexOf(id)>=0){
btshow.removeClass("selected");
bthide.addClass("selected");
uclass="grouphide";
}
$(that.group_uids[id]).each(function(i,v) {
$(this.group_uids[id]).each(function(i,v) {
if(uclass == "grouphide")
$("#c"+v).removeClass("groupshow");
if(uclass != "") {
@ -257,17 +256,17 @@ ACL.prototype.update_view = function(){
break;
case "c":
if (that.allow_cid.indexOf(id)>=0){
if (this.allow_cid.indexOf(id)>=0){
btshow.addClass("selected");
bthide.removeClass("selected");
}
if (that.deny_cid.indexOf(id)>=0){
if (this.deny_cid.indexOf(id)>=0){
btshow.removeClass("selected");
bthide.addClass("selected");
}
}
});
}.bind(this));
}
@ -281,30 +280,30 @@ ACL.prototype.get = function(start,count, search){
$.ajax({
type:'POST',
url: that.url,
url: this.url,
data: postdata,
dataType: 'json',
success:that.populate
success:this.populate.bind(this)
});
}
ACL.prototype.populate = function(data){
var height = Math.ceil(data.tot / that.nw) * 42;
that.list_content.height(height);
that.data = {};
$(data.items).each(function(){
html = "<div class='acl-list-item {4} {5} type{2}' title='{6}' id='{2}{3}'>"+that.item_tpl+"</div>";
html = html.format(this.photo, this.name, this.type, this.id, (this.forum=='1'?'forum':''), this.network, this.link);
if (this.uids!=undefined) that.group_uids[this.id] = this.uids;
//console.log(html);
that.list_content.append(html);
that.data[this.id] = this;
});
$(".acl-list-item img[data-src]", that.list_content).each(function(i, el){
var height = Math.ceil(data.tot / this.nw) * 42;
this.list_content.height(height);
this.data = {};
$(data.items).each(function(index, item){
html = "<div class='acl-list-item {4} {5} type{2}' title='{6}' id='{2}{3}'>"+this.item_tpl+"</div>";
html = html.format(item.photo, item.name, item.type, item.id, (item.forum=='1'?'forum':''), item.network, item.link);
if (item.uids!=undefined) this.group_uids[item.id] = item.uids;
this.list_content.append(html);
this.data[item.id] = item;
}.bind(this));
$(".acl-list-item img[data-src]", this.list_content).each(function(i, el){
// Add src attribute for images with a data-src attribute
$(el).attr('src', $(el).data("src"));
});
that.update_view();
this.update_view();
}

View File

@ -9,7 +9,7 @@
if (h==ch) {
return;
}
console.log("_resizeIframe", obj, desth, ch);
//console.log("_resizeIframe", obj, desth, ch);
if (desth!=ch) {
setTimeout(_resizeIframe, 500, obj, ch);
} else {
@ -147,6 +147,7 @@
} else {
last_popup_menu = menu;
last_popup_button = parent;
$('#nav-notifications-menu').perfectScrollbar('update');
}
return false;
});
@ -159,7 +160,9 @@
'inline' : true,
'transition' : 'elastic'
});
$("a.ajax-popupbox").colorbox({
'transition' : 'elastic'
});
/* notifications template */
var notifications_tpl= unescape($("#nav-notifications-template[rel=template]").html());
@ -167,6 +170,9 @@
var notifications_mark = unescape($('<div>').append( $("#nav-notifications-mark-all").clone() ).html()); //outerHtml hack
var notifications_empty = unescape($("#nav-notifications-menu").html());
/* enable perfect-scrollbars for different elements */
$('#nav-notifications-menu, aside').perfectScrollbar();
/* nav update event */
$('nav').bind('nav-update', function(e,data){
var invalid = $(data).find('invalid').text();
@ -311,6 +317,9 @@
$.jGrowl(text, { sticky: false, theme: 'info', life: 5000 });
});
/* update the js scrollbars */
$('#nav-notifications-menu').perfectScrollbar('update');
});
NavUpdate();

11
library/Chart.js-1.0.2/Chart.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,7 @@
Copyright (c) 2013-2015 Nick Downie
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -0,0 +1,20 @@
# Chart.js
[![Build Status](https://travis-ci.org/nnnick/Chart.js.svg?branch=master)](https://travis-ci.org/nnnick/Chart.js) [![Code Climate](https://codeclimate.com/github/nnnick/Chart.js/badges/gpa.svg)](https://codeclimate.com/github/nnnick/Chart.js)
*Simple HTML5 Charts using the canvas element* [chartjs.org](http://www.chartjs.org)
## Documentation
You can find documentation at [chartjs.org/docs](http://www.chartjs.org/docs/). The markdown files that build the site are available under `/docs`. Please note - in some of the json examples of configuration you might notice some liquid tags - this is just for the generating the site html, please disregard.
## Bugs, issues and contributing
Before submitting an issue or a pull request to the project, please take a moment to look over the [contributing guidelines](https://github.com/nnnick/Chart.js/blob/master/CONTRIBUTING.md) first.
For support using Chart.js, please post questions with the [`chartjs` tag on Stack Overflow](http://stackoverflow.com/questions/tagged/chartjs).
## License
Chart.js is available under the [MIT license](http://opensource.org/licenses/MIT).

View File

@ -1,21 +0,0 @@
<?php
class HTMLPurifier_AttrDef_CSS_AlphaValue extends HTMLPurifier_AttrDef_CSS_Number
{
public function __construct() {
parent::__construct(false); // opacity is non-negative, but we will clamp it
}
public function validate($number, $config, $context) {
$result = parent::validate($number, $config, $context);
if ($result === false) return $result;
$float = (float) $result;
if ($float < 0.0) $result = '0';
if ($float > 1.0) $result = '1';
return $result;
}
}
// vim: et sw=4 sts=4

View File

@ -1,28 +0,0 @@
<?php
/**
* Decorator which enables CSS properties to be disabled for specific elements.
*/
class HTMLPurifier_AttrDef_CSS_DenyElementDecorator extends HTMLPurifier_AttrDef
{
public $def, $element;
/**
* @param $def Definition to wrap
* @param $element Element to deny
*/
public function __construct($def, $element) {
$this->def = $def;
$this->element = $element;
}
/**
* Checks if CurrentToken is set and equal to $this->element
*/
public function validate($string, $config, $context) {
$token = $context->get('CurrentToken', true);
if ($token && $token->name == $this->element) return false;
return $this->def->validate($string, $config, $context);
}
}
// vim: et sw=4 sts=4

View File

@ -1,72 +0,0 @@
<?php
/**
* Validates a font family list according to CSS spec
* @todo whitelisting allowed fonts would be nice
*/
class HTMLPurifier_AttrDef_CSS_FontFamily extends HTMLPurifier_AttrDef
{
public function validate($string, $config, $context) {
static $generic_names = array(
'serif' => true,
'sans-serif' => true,
'monospace' => true,
'fantasy' => true,
'cursive' => true
);
// assume that no font names contain commas in them
$fonts = explode(',', $string);
$final = '';
foreach($fonts as $font) {
$font = trim($font);
if ($font === '') continue;
// match a generic name
if (isset($generic_names[$font])) {
$final .= $font . ', ';
continue;
}
// match a quoted name
if ($font[0] === '"' || $font[0] === "'") {
$length = strlen($font);
if ($length <= 2) continue;
$quote = $font[0];
if ($font[$length - 1] !== $quote) continue;
$font = substr($font, 1, $length - 2);
}
$font = $this->expandCSSEscape($font);
// $font is a pure representation of the font name
if (ctype_alnum($font) && $font !== '') {
// very simple font, allow it in unharmed
$final .= $font . ', ';
continue;
}
// bugger out on whitespace. form feed (0C) really
// shouldn't show up regardless
$font = str_replace(array("\n", "\t", "\r", "\x0C"), ' ', $font);
// These ugly transforms don't pose a security
// risk (as \\ and \" might). We could try to be clever and
// use single-quote wrapping when there is a double quote
// present, but I have choosen not to implement that.
// (warning: this code relies on the selection of quotation
// mark below)
$font = str_replace('\\', '\\5C ', $font);
$font = str_replace('"', '\\22 ', $font);
// complicated font, requires quoting
$final .= "\"$font\", "; // note that this will later get turned into &quot;
}
$final = rtrim($final, ', ');
if ($final === '') return false;
return $final;
}
}
// vim: et sw=4 sts=4

View File

@ -1,47 +0,0 @@
<?php
/**
* Represents a Length as defined by CSS.
*/
class HTMLPurifier_AttrDef_CSS_Length extends HTMLPurifier_AttrDef
{
protected $min, $max;
/**
* @param HTMLPurifier_Length $max Minimum length, or null for no bound. String is also acceptable.
* @param HTMLPurifier_Length $max Maximum length, or null for no bound. String is also acceptable.
*/
public function __construct($min = null, $max = null) {
$this->min = $min !== null ? HTMLPurifier_Length::make($min) : null;
$this->max = $max !== null ? HTMLPurifier_Length::make($max) : null;
}
public function validate($string, $config, $context) {
$string = $this->parseCDATA($string);
// Optimizations
if ($string === '') return false;
if ($string === '0') return '0';
if (strlen($string) === 1) return false;
$length = HTMLPurifier_Length::make($string);
if (!$length->isValid()) return false;
if ($this->min) {
$c = $length->compareTo($this->min);
if ($c === false) return false;
if ($c < 0) return false;
}
if ($this->max) {
$c = $length->compareTo($this->max);
if ($c === false) return false;
if ($c > 0) return false;
}
return $length->toString();
}
}
// vim: et sw=4 sts=4

View File

@ -1,78 +0,0 @@
<?php
/**
* Validates shorthand CSS property list-style.
* @warning Does not support url tokens that have internal spaces.
*/
class HTMLPurifier_AttrDef_CSS_ListStyle extends HTMLPurifier_AttrDef
{
/**
* Local copy of component validators.
* @note See HTMLPurifier_AttrDef_CSS_Font::$info for a similar impl.
*/
protected $info;
public function __construct($config) {
$def = $config->getCSSDefinition();
$this->info['list-style-type'] = $def->info['list-style-type'];
$this->info['list-style-position'] = $def->info['list-style-position'];
$this->info['list-style-image'] = $def->info['list-style-image'];
}
public function validate($string, $config, $context) {
// regular pre-processing
$string = $this->parseCDATA($string);
if ($string === '') return false;
// assumes URI doesn't have spaces in it
$bits = explode(' ', strtolower($string)); // bits to process
$caught = array();
$caught['type'] = false;
$caught['position'] = false;
$caught['image'] = false;
$i = 0; // number of catches
$none = false;
foreach ($bits as $bit) {
if ($i >= 3) return; // optimization bit
if ($bit === '') continue;
foreach ($caught as $key => $status) {
if ($status !== false) continue;
$r = $this->info['list-style-' . $key]->validate($bit, $config, $context);
if ($r === false) continue;
if ($r === 'none') {
if ($none) continue;
else $none = true;
if ($key == 'image') continue;
}
$caught[$key] = $r;
$i++;
break;
}
}
if (!$i) return false;
$ret = array();
// construct type
if ($caught['type']) $ret[] = $caught['type'];
// construct image
if ($caught['image']) $ret[] = $caught['image'];
// construct position
if ($caught['position']) $ret[] = $caught['position'];
if (empty($ret)) return false;
return implode(' ', $ret);
}
}
// vim: et sw=4 sts=4

View File

@ -1,40 +0,0 @@
<?php
/**
* Validates a Percentage as defined by the CSS spec.
*/
class HTMLPurifier_AttrDef_CSS_Percentage extends HTMLPurifier_AttrDef
{
/**
* Instance of HTMLPurifier_AttrDef_CSS_Number to defer number validation
*/
protected $number_def;
/**
* @param Bool indicating whether to forbid negative values
*/
public function __construct($non_negative = false) {
$this->number_def = new HTMLPurifier_AttrDef_CSS_Number($non_negative);
}
public function validate($string, $config, $context) {
$string = $this->parseCDATA($string);
if ($string === '') return false;
$length = strlen($string);
if ($length === 1) return false;
if ($string[$length - 1] !== '%') return false;
$number = substr($string, 0, $length - 1);
$number = $this->number_def->validate($number, $config, $context);
if ($number === false) return false;
return "$number%";
}
}
// vim: et sw=4 sts=4

View File

@ -1,28 +0,0 @@
<?php
/**
* Validates a boolean attribute
*/
class HTMLPurifier_AttrDef_HTML_Bool extends HTMLPurifier_AttrDef
{
protected $name;
public $minimized = true;
public function __construct($name = false) {$this->name = $name;}
public function validate($string, $config, $context) {
if (empty($string)) return false;
return $this->name;
}
/**
* @param $string Name of attribute
*/
public function make($string) {
return new HTMLPurifier_AttrDef_HTML_Bool($string);
}
}
// vim: et sw=4 sts=4

View File

@ -1,32 +0,0 @@
<?php
/**
* Validates a color according to the HTML spec.
*/
class HTMLPurifier_AttrDef_HTML_Color extends HTMLPurifier_AttrDef
{
public function validate($string, $config, $context) {
static $colors = null;
if ($colors === null) $colors = $config->get('Core.ColorKeywords');
$string = trim($string);
if (empty($string)) return false;
if (isset($colors[$string])) return $colors[$string];
if ($string[0] === '#') $hex = substr($string, 1);
else $hex = $string;
$length = strlen($hex);
if ($length !== 3 && $length !== 6) return false;
if (!ctype_xdigit($hex)) return false;
if ($length === 3) $hex = $hex[0].$hex[0].$hex[1].$hex[1].$hex[2].$hex[2];
return "#$hex";
}
}
// vim: et sw=4 sts=4

View File

@ -1,21 +0,0 @@
<?php
/**
* Special-case enum attribute definition that lazy loads allowed frame targets
*/
class HTMLPurifier_AttrDef_HTML_FrameTarget extends HTMLPurifier_AttrDef_Enum
{
public $valid_values = false; // uninitialized value
protected $case_sensitive = false;
public function __construct() {}
public function validate($string, $config, $context) {
if ($this->valid_values === false) $this->valid_values = $config->get('Attr.AllowedFrameTargets');
return parent::validate($string, $config, $context);
}
}
// vim: et sw=4 sts=4

View File

@ -1,70 +0,0 @@
<?php
/**
* Validates the HTML attribute ID.
* @warning Even though this is the id processor, it
* will ignore the directive Attr:IDBlacklist, since it will only
* go according to the ID accumulator. Since the accumulator is
* automatically generated, it will have already absorbed the
* blacklist. If you're hacking around, make sure you use load()!
*/
class HTMLPurifier_AttrDef_HTML_ID extends HTMLPurifier_AttrDef
{
// ref functionality disabled, since we also have to verify
// whether or not the ID it refers to exists
public function validate($id, $config, $context) {
if (!$config->get('Attr.EnableID')) return false;
$id = trim($id); // trim it first
if ($id === '') return false;
$prefix = $config->get('Attr.IDPrefix');
if ($prefix !== '') {
$prefix .= $config->get('Attr.IDPrefixLocal');
// prevent re-appending the prefix
if (strpos($id, $prefix) !== 0) $id = $prefix . $id;
} elseif ($config->get('Attr.IDPrefixLocal') !== '') {
trigger_error('%Attr.IDPrefixLocal cannot be used unless '.
'%Attr.IDPrefix is set', E_USER_WARNING);
}
//if (!$this->ref) {
$id_accumulator =& $context->get('IDAccumulator');
if (isset($id_accumulator->ids[$id])) return false;
//}
// we purposely avoid using regex, hopefully this is faster
if (ctype_alpha($id)) {
$result = true;
} else {
if (!ctype_alpha(@$id[0])) return false;
$trim = trim( // primitive style of regexps, I suppose
$id,
'A..Za..z0..9:-._'
);
$result = ($trim === '');
}
$regexp = $config->get('Attr.IDBlacklistRegexp');
if ($regexp && preg_match($regexp, $id)) {
return false;
}
if (/*!$this->ref && */$result) $id_accumulator->add($id);
// if no change was made to the ID, return the result
// else, return the new id if stripping whitespace made it
// valid, or return false.
return $result ? $id : false;
}
}
// vim: et sw=4 sts=4

View File

@ -1,41 +0,0 @@
<?php
/**
* Validates the HTML type length (not to be confused with CSS's length).
*
* This accepts integer pixels or percentages as lengths for certain
* HTML attributes.
*/
class HTMLPurifier_AttrDef_HTML_Length extends HTMLPurifier_AttrDef_HTML_Pixels
{
public function validate($string, $config, $context) {
$string = trim($string);
if ($string === '') return false;
$parent_result = parent::validate($string, $config, $context);
if ($parent_result !== false) return $parent_result;
$length = strlen($string);
$last_char = $string[$length - 1];
if ($last_char !== '%') return false;
$points = substr($string, 0, $length - 1);
if (!is_numeric($points)) return false;
$points = (int) $points;
if ($points < 0) return '0%';
if ($points > 100) return '100%';
return ((string) $points) . '%';
}
}
// vim: et sw=4 sts=4

View File

@ -1,41 +0,0 @@
<?php
/**
* Validates a MultiLength as defined by the HTML spec.
*
* A multilength is either a integer (pixel count), a percentage, or
* a relative number.
*/
class HTMLPurifier_AttrDef_HTML_MultiLength extends HTMLPurifier_AttrDef_HTML_Length
{
public function validate($string, $config, $context) {
$string = trim($string);
if ($string === '') return false;
$parent_result = parent::validate($string, $config, $context);
if ($parent_result !== false) return $parent_result;
$length = strlen($string);
$last_char = $string[$length - 1];
if ($last_char !== '*') return false;
$int = substr($string, 0, $length - 1);
if ($int == '') return '*';
if (!is_numeric($int)) return false;
$int = (int) $int;
if ($int < 0) return false;
if ($int == 0) return '0';
if ($int == 1) return '*';
return ((string) $int) . '*';
}
}
// vim: et sw=4 sts=4

View File

@ -1,48 +0,0 @@
<?php
/**
* Validates an integer representation of pixels according to the HTML spec.
*/
class HTMLPurifier_AttrDef_HTML_Pixels extends HTMLPurifier_AttrDef
{
protected $max;
public function __construct($max = null) {
$this->max = $max;
}
public function validate($string, $config, $context) {
$string = trim($string);
if ($string === '0') return $string;
if ($string === '') return false;
$length = strlen($string);
if (substr($string, $length - 2) == 'px') {
$string = substr($string, 0, $length - 2);
}
if (!is_numeric($string)) return false;
$int = (int) $string;
if ($int < 0) return '0';
// upper-bound value, extremely high values can
// crash operating systems, see <http://ha.ckers.org/imagecrash.html>
// WARNING, above link WILL crash you if you're using Windows
if ($this->max !== null && $int > $this->max) return (string) $this->max;
return (string) $int;
}
public function make($string) {
if ($string === '') $max = null;
else $max = (int) $string;
$class = get_class($this);
return new $class($max);
}
}
// vim: et sw=4 sts=4

View File

@ -1,15 +0,0 @@
<?php
/**
* Validates arbitrary text according to the HTML spec.
*/
class HTMLPurifier_AttrDef_Text extends HTMLPurifier_AttrDef
{
public function validate($string, $config, $context) {
return $this->parseCDATA($string);
}
}
// vim: et sw=4 sts=4

View File

@ -1,62 +0,0 @@
<?php
/**
* Validates a host according to the IPv4, IPv6 and DNS (future) specifications.
*/
class HTMLPurifier_AttrDef_URI_Host extends HTMLPurifier_AttrDef
{
/**
* Instance of HTMLPurifier_AttrDef_URI_IPv4 sub-validator
*/
protected $ipv4;
/**
* Instance of HTMLPurifier_AttrDef_URI_IPv6 sub-validator
*/
protected $ipv6;
public function __construct() {
$this->ipv4 = new HTMLPurifier_AttrDef_URI_IPv4();
$this->ipv6 = new HTMLPurifier_AttrDef_URI_IPv6();
}
public function validate($string, $config, $context) {
$length = strlen($string);
if ($string === '') return '';
if ($length > 1 && $string[0] === '[' && $string[$length-1] === ']') {
//IPv6
$ip = substr($string, 1, $length - 2);
$valid = $this->ipv6->validate($ip, $config, $context);
if ($valid === false) return false;
return '['. $valid . ']';
}
// need to do checks on unusual encodings too
$ipv4 = $this->ipv4->validate($string, $config, $context);
if ($ipv4 !== false) return $ipv4;
// A regular domain name.
// This breaks I18N domain names, but we don't have proper IRI support,
// so force users to insert Punycode. If there's complaining we'll
// try to fix things into an international friendly form.
// The productions describing this are:
$a = '[a-z]'; // alpha
$an = '[a-z0-9]'; // alphanum
$and = '[a-z0-9-]'; // alphanum | "-"
// domainlabel = alphanum | alphanum *( alphanum | "-" ) alphanum
$domainlabel = "$an($and*$an)?";
// toplabel = alpha | alpha *( alphanum | "-" ) alphanum
$toplabel = "$a($and*$an)?";
// hostname = *( domainlabel "." ) toplabel [ "." ]
$match = preg_match("/^($domainlabel\.)*$toplabel\.?$/i", $string);
if (!$match) return false;
return $string;
}
}
// vim: et sw=4 sts=4

View File

@ -1,99 +0,0 @@
<?php
/**
* Validates an IPv6 address.
* @author Feyd @ forums.devnetwork.net (public domain)
* @note This function requires brackets to have been removed from address
* in URI.
*/
class HTMLPurifier_AttrDef_URI_IPv6 extends HTMLPurifier_AttrDef_URI_IPv4
{
public function validate($aIP, $config, $context) {
if (!$this->ip4) $this->_loadRegex();
$original = $aIP;
$hex = '[0-9a-fA-F]';
$blk = '(?:' . $hex . '{1,4})';
$pre = '(?:/(?:12[0-8]|1[0-1][0-9]|[1-9][0-9]|[0-9]))'; // /0 - /128
// prefix check
if (strpos($aIP, '/') !== false)
{
if (preg_match('#' . $pre . '$#s', $aIP, $find))
{
$aIP = substr($aIP, 0, 0-strlen($find[0]));
unset($find);
}
else
{
return false;
}
}
// IPv4-compatiblity check
if (preg_match('#(?<=:'.')' . $this->ip4 . '$#s', $aIP, $find))
{
$aIP = substr($aIP, 0, 0-strlen($find[0]));
$ip = explode('.', $find[0]);
$ip = array_map('dechex', $ip);
$aIP .= $ip[0] . $ip[1] . ':' . $ip[2] . $ip[3];
unset($find, $ip);
}
// compression check
$aIP = explode('::', $aIP);
$c = count($aIP);
if ($c > 2)
{
return false;
}
elseif ($c == 2)
{
list($first, $second) = $aIP;
$first = explode(':', $first);
$second = explode(':', $second);
if (count($first) + count($second) > 8)
{
return false;
}
while(count($first) < 8)
{
array_push($first, '0');
}
array_splice($first, 8 - count($second), 8, $second);
$aIP = $first;
unset($first,$second);
}
else
{
$aIP = explode(':', $aIP[0]);
}
$c = count($aIP);
if ($c != 8)
{
return false;
}
// All the pieces should be 16-bit hex strings. Are they?
foreach ($aIP as $piece)
{
if (!preg_match('#^[0-9a-fA-F]{4}$#s', sprintf('%04s', $piece)))
{
return false;
}
}
return $original;
}
}
// vim: et sw=4 sts=4

View File

@ -1,36 +0,0 @@
<?php
/**
* Pre-transform that changes converts a boolean attribute to fixed CSS
*/
class HTMLPurifier_AttrTransform_BoolToCSS extends HTMLPurifier_AttrTransform {
/**
* Name of boolean attribute that is trigger
*/
protected $attr;
/**
* CSS declarations to add to style, needs trailing semicolon
*/
protected $css;
/**
* @param $attr string attribute name to convert from
* @param $css string CSS declarations to add to style (needs semicolon)
*/
public function __construct($attr, $css) {
$this->attr = $attr;
$this->css = $css;
}
public function transform($attr, $config, $context) {
if (!isset($attr[$this->attr])) return $attr;
unset($attr[$this->attr]);
$this->prependCSS($attr, $this->css);
return $attr;
}
}
// vim: et sw=4 sts=4

View File

@ -1,58 +0,0 @@
<?php
/**
* Generic pre-transform that converts an attribute with a fixed number of
* values (enumerated) to CSS.
*/
class HTMLPurifier_AttrTransform_EnumToCSS extends HTMLPurifier_AttrTransform {
/**
* Name of attribute to transform from
*/
protected $attr;
/**
* Lookup array of attribute values to CSS
*/
protected $enumToCSS = array();
/**
* Case sensitivity of the matching
* @warning Currently can only be guaranteed to work with ASCII
* values.
*/
protected $caseSensitive = false;
/**
* @param $attr String attribute name to transform from
* @param $enumToCSS Lookup array of attribute values to CSS
* @param $case_sensitive Boolean case sensitivity indicator, default false
*/
public function __construct($attr, $enum_to_css, $case_sensitive = false) {
$this->attr = $attr;
$this->enumToCSS = $enum_to_css;
$this->caseSensitive = (bool) $case_sensitive;
}
public function transform($attr, $config, $context) {
if (!isset($attr[$this->attr])) return $attr;
$value = trim($attr[$this->attr]);
unset($attr[$this->attr]);
if (!$this->caseSensitive) $value = strtolower($value);
if (!isset($this->enumToCSS[$value])) {
return $attr;
}
$this->prependCSS($attr, $this->enumToCSS[$value]);
return $attr;
}
}
// vim: et sw=4 sts=4

View File

@ -1,27 +0,0 @@
<?php
/**
* Class for handling width/height length attribute transformations to CSS
*/
class HTMLPurifier_AttrTransform_Length extends HTMLPurifier_AttrTransform
{
protected $name;
protected $cssName;
public function __construct($name, $css_name = null) {
$this->name = $name;
$this->cssName = $css_name ? $css_name : $name;
}
public function transform($attr, $config, $context) {
if (!isset($attr[$this->name])) return $attr;
$length = $this->confiscateAttr($attr, $this->name);
if(ctype_digit($length)) $length .= 'px';
$this->prependCSS($attr, $this->cssName . ":$length;");
return $attr;
}
}
// vim: et sw=4 sts=4

View File

@ -1,21 +0,0 @@
<?php
/**
* Pre-transform that changes deprecated name attribute to ID if necessary
*/
class HTMLPurifier_AttrTransform_Name extends HTMLPurifier_AttrTransform
{
public function transform($attr, $config, $context) {
// Abort early if we're using relaxed definition of name
if ($config->get('HTML.Attr.Name.UseCDATA')) return $attr;
if (!isset($attr['name'])) return $attr;
$id = $this->confiscateAttr($attr, 'name');
if ( isset($attr['id'])) return $attr;
$attr['id'] = $id;
return $attr;
}
}
// vim: et sw=4 sts=4

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