Merge develop into 1404_reworked_autocomplete
Conflicts: include/text.php view/templates/head.tpl view/theme/duepuntozero/style.css view/theme/vier/style.css
This commit is contained in:
commit
01b02dbcaa
723 changed files with 40077 additions and 44824 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -12,7 +12,7 @@ addon
|
|||
*~
|
||||
robots.txt
|
||||
|
||||
#ignore documentation, it should be newly built
|
||||
#ignore documentation, it should be newly built
|
||||
doc/html
|
||||
|
||||
#ignore reports, should be generted with every build
|
||||
|
@ -23,7 +23,7 @@ report/
|
|||
.buildpath
|
||||
.externalToolBuilders
|
||||
.settings
|
||||
#ignore OSX .DS_Store files
|
||||
#ignore OSX .DS_Store files
|
||||
.DS_Store
|
||||
|
||||
/nbproject/private/
|
||||
|
|
139
boot.php
139
boot.php
|
@ -6,17 +6,19 @@
|
|||
|
||||
/**
|
||||
* Friendica
|
||||
*
|
||||
*
|
||||
* Friendica is a communications platform for integrated social communications
|
||||
* utilising decentralised communications and linkage to several indie social
|
||||
* projects - as well as popular mainstream providers.
|
||||
*
|
||||
*
|
||||
* Our mission is to free our friends and families from the clutches of
|
||||
* data-harvesting corporations, and pave the way to a future where social
|
||||
* communications are free and open and flow between alternate providers as
|
||||
* easily as email does today.
|
||||
*/
|
||||
|
||||
require_once('include/autoloader.php');
|
||||
|
||||
require_once('include/config.php');
|
||||
require_once('include/network.php');
|
||||
require_once('include/plugin.php');
|
||||
|
@ -28,7 +30,7 @@ require_once('include/cache.php');
|
|||
require_once('library/Mobile_Detect/Mobile_Detect.php');
|
||||
require_once('include/features.php');
|
||||
require_once('include/identity.php');
|
||||
|
||||
require_once('include/pidfile.php');
|
||||
require_once('update.php');
|
||||
require_once('include/dbstructure.php');
|
||||
|
||||
|
@ -463,11 +465,12 @@ class App {
|
|||
public $plugins;
|
||||
public $apps = array();
|
||||
public $identities;
|
||||
public $is_mobile;
|
||||
public $is_tablet;
|
||||
public $is_mobile = false;
|
||||
public $is_tablet = false;
|
||||
public $is_friendica_app;
|
||||
public $performance = array();
|
||||
public $callstack = array();
|
||||
public $theme_info = array();
|
||||
|
||||
public $nav_sel;
|
||||
|
||||
|
@ -588,15 +591,6 @@ class App {
|
|||
if(x($_SERVER,'SERVER_NAME')) {
|
||||
$this->hostname = $_SERVER['SERVER_NAME'];
|
||||
|
||||
// See bug 437 - this didn't work so disabling it
|
||||
//if(stristr($this->hostname,'xn--')) {
|
||||
// PHP or webserver may have converted idn to punycode, so
|
||||
// convert punycode back to utf-8
|
||||
// require_once('library/simplepie/idn/idna_convert.class.php');
|
||||
// $x = new idna_convert();
|
||||
// $this->hostname = $x->decode($_SERVER['SERVER_NAME']);
|
||||
//}
|
||||
|
||||
if(x($_SERVER,'SERVER_PORT') && $_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443)
|
||||
$this->hostname .= ':' . $_SERVER['SERVER_PORT'];
|
||||
/*
|
||||
|
@ -862,11 +856,11 @@ class App {
|
|||
|
||||
$shortcut_icon = get_config("system", "shortcut_icon");
|
||||
if ($shortcut_icon == "")
|
||||
$shortcut_icon = $this->get_baseurl()."/images/friendica-32.png";
|
||||
$shortcut_icon = "images/friendica-32.png";
|
||||
|
||||
$touch_icon = get_config("system", "touch_icon");
|
||||
if ($touch_icon == "")
|
||||
$touch_icon = $this->get_baseurl()."/images/friendica-128.png";
|
||||
$touch_icon = "images/friendica-128.png";
|
||||
|
||||
$tpl = get_markup_template('head.tpl');
|
||||
$this->page['htmlhead'] = replace_macros($tpl,array(
|
||||
|
@ -945,6 +939,25 @@ class App {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Removes the baseurl from an url. This avoids some mixed content problems.
|
||||
*
|
||||
* @param string $url
|
||||
*
|
||||
* @return string The cleaned url
|
||||
*/
|
||||
function remove_baseurl($url){
|
||||
|
||||
// Is the function called statically?
|
||||
if (!is_object($this))
|
||||
return(self::$a->remove_baseurl($url));
|
||||
|
||||
$url = normalise_link($url);
|
||||
$base = normalise_link($this->get_baseurl());
|
||||
$url = str_replace($base."/", "", $url);
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Register template engine class
|
||||
*
|
||||
|
@ -1034,22 +1047,42 @@ class App {
|
|||
function save_timestamp($stamp, $value) {
|
||||
$duration = (float)(microtime(true)-$stamp);
|
||||
|
||||
if (!isset($this->performance[$value])) {
|
||||
// Prevent ugly E_NOTICE
|
||||
$this->performance[$value] = 0;
|
||||
}
|
||||
|
||||
$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);
|
||||
$callstack = $this->callstack();
|
||||
|
||||
if (!isset($this->callstack[$value][$callstack])) {
|
||||
// Prevent ugly E_NOTICE
|
||||
$this->callstack[$value][$callstack] = 0;
|
||||
}
|
||||
|
||||
$this->callstack[$value][$callstack] += (float)$duration;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns a string with a callstack. Can be used for logging.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function callstack() {
|
||||
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 6);
|
||||
|
||||
// We remove the first two items from the list since they contain data that we don't need.
|
||||
array_shift($trace);
|
||||
array_shift($trace);
|
||||
|
||||
$function = array();
|
||||
$callstack = array();
|
||||
foreach ($trace AS $func)
|
||||
$function[] = $func["function"];
|
||||
|
||||
$function = implode(", ", $function);
|
||||
|
||||
$this->callstack[$value][$function] += (float)$duration;
|
||||
$callstack[] = $func["function"];
|
||||
|
||||
return implode(", ", $callstack);
|
||||
}
|
||||
|
||||
function mark_timestamp($mark) {
|
||||
|
@ -1065,6 +1098,55 @@ class App {
|
|||
return($this->is_friendica_app);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks if the maximum load is reached
|
||||
*
|
||||
* @return bool Is the load reached?
|
||||
*/
|
||||
function maxload_reached() {
|
||||
|
||||
$maxsysload = intval(get_config('system', 'maxloadavg'));
|
||||
if ($maxsysload < 1)
|
||||
$maxsysload = 50;
|
||||
|
||||
$load = current_load();
|
||||
if ($load) {
|
||||
if (intval($load) > $maxsysload) {
|
||||
logger('system: load '.$load.' too high.');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks if the process is already running
|
||||
*
|
||||
* @param string $taskname The name of the task that will be used for the name of the lockfile
|
||||
* @param string $task The path and name of the php script
|
||||
* @param int $timeout The timeout after which a task should be killed
|
||||
*
|
||||
* @return bool Is the process running?
|
||||
*/
|
||||
function is_already_running($taskname, $task = "", $timeout = 540) {
|
||||
|
||||
$lockpath = get_lockpath();
|
||||
if ($lockpath != '') {
|
||||
$pidfile = new pidfile($lockpath, $taskname);
|
||||
if ($pidfile->is_already_running()) {
|
||||
logger("Already running");
|
||||
if ($pidfile->running_time() > $timeout) {
|
||||
$pidfile->kill();
|
||||
logger("killed stale process");
|
||||
// Calling a new instance
|
||||
if ($task != "")
|
||||
proc_run('php', $task);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1416,7 +1498,7 @@ function login($register = false, $hiddens=false) {
|
|||
|
||||
$noid = get_config('system','no_openid');
|
||||
|
||||
$dest_url = $a->get_baseurl(true) . '/' . $a->query_string;
|
||||
$dest_url = $a->query_string;
|
||||
|
||||
if(local_user()) {
|
||||
$tpl = get_markup_template("logout.tpl");
|
||||
|
@ -1476,6 +1558,9 @@ function killme() {
|
|||
* @brief Redirect to another URL and terminate this process.
|
||||
*/
|
||||
function goaway($s) {
|
||||
if (!strstr(normalise_link($s), "http://"))
|
||||
$s = App::get_baseurl()."/".$s;
|
||||
|
||||
header("Location: $s");
|
||||
killme();
|
||||
}
|
||||
|
@ -1735,9 +1820,9 @@ function current_theme_url() {
|
|||
|
||||
$opts = (($a->profile_uid) ? '?f=&puid=' . $a->profile_uid : '');
|
||||
if (file_exists('view/theme/' . $t . '/style.php'))
|
||||
return($a->get_baseurl() . '/view/theme/' . $t . '/style.pcss' . $opts);
|
||||
return('view/theme/'.$t.'/style.pcss'.$opts);
|
||||
|
||||
return($a->get_baseurl() . '/view/theme/' . $t . '/style.css');
|
||||
return('view/theme/'.$t.'/style.css');
|
||||
}
|
||||
|
||||
function feed_birthday($uid,$tz) {
|
||||
|
|
33
database.sql
33
database.sql
|
@ -1,6 +1,6 @@
|
|||
-- ------------------------------------------
|
||||
-- Friendica 3.5-dev (Asparagus)
|
||||
-- DB_UPDATE_VERSION 1193
|
||||
-- DB_UPDATE_VERSION 1194
|
||||
-- ------------------------------------------
|
||||
|
||||
|
||||
|
@ -119,6 +119,7 @@ CREATE TABLE IF NOT EXISTS `contact` (
|
|||
`keywords` text NOT NULL,
|
||||
`gender` varchar(32) NOT NULL DEFAULT '',
|
||||
`attag` varchar(255) NOT NULL DEFAULT '',
|
||||
`avatar` varchar(255) NOT NULL DEFAULT '',
|
||||
`photo` text NOT NULL,
|
||||
`thumb` text NOT NULL,
|
||||
`micro` text NOT NULL,
|
||||
|
@ -200,17 +201,6 @@ CREATE TABLE IF NOT EXISTS `deliverq` (
|
|||
PRIMARY KEY(`id`)
|
||||
) DEFAULT CHARSET=utf8;
|
||||
|
||||
--
|
||||
-- TABLE dsprphotoq
|
||||
--
|
||||
CREATE TABLE IF NOT EXISTS `dsprphotoq` (
|
||||
`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,
|
||||
PRIMARY KEY(`id`)
|
||||
) DEFAULT CHARSET=utf8;
|
||||
|
||||
--
|
||||
-- TABLE event
|
||||
--
|
||||
|
@ -411,21 +401,6 @@ CREATE TABLE IF NOT EXISTS `gserver` (
|
|||
INDEX `nurl` (`nurl`)
|
||||
) DEFAULT CHARSET=utf8;
|
||||
|
||||
--
|
||||
-- TABLE guid
|
||||
--
|
||||
CREATE TABLE IF NOT EXISTS `guid` (
|
||||
`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`)
|
||||
) DEFAULT CHARSET=utf8;
|
||||
|
||||
--
|
||||
-- TABLE hook
|
||||
--
|
||||
|
@ -926,13 +901,11 @@ CREATE TABLE IF NOT EXISTS `session` (
|
|||
CREATE TABLE IF NOT EXISTS `sign` (
|
||||
`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`)
|
||||
INDEX `iid` (`iid`)
|
||||
) DEFAULT CHARSET=utf8;
|
||||
|
||||
--
|
||||
|
|
|
@ -37,10 +37,7 @@ General
|
|||
* o: Profile
|
||||
* t: Contacts
|
||||
* d: Common friends
|
||||
* b: Toggle Blocked status
|
||||
* i: Toggle Ignored status
|
||||
* v: Toggle Archive status
|
||||
* r: Repair
|
||||
* r: Advanced
|
||||
|
||||
/message
|
||||
--------
|
||||
|
|
|
@ -143,6 +143,56 @@ Map
|
|||
You can embed maps from coordinates or addresses.
|
||||
This require "openstreetmap" addon version 1.3 or newer.
|
||||
|
||||
-----------------------------------------------------------
|
||||
|
||||
Abstract for longer posts
|
||||
-------------------------
|
||||
|
||||
If you want to spread your post to several third party networks you can have the problem that these networks have (for example) a length limitation.
|
||||
(Like on Twitter)
|
||||
|
||||
Friendica is using a semi intelligent mechanism to generate a fitting abstract.
|
||||
But it can be interesting to define an own abstract that will only be displayed on the external network.
|
||||
This is done with the [abstract]-element.
|
||||
Example:
|
||||
|
||||
<pre>[abstract]Totally interesting! A must-see! Please click the link![/abstract]
|
||||
I want to tell you a really boring story that you really never wanted
|
||||
to hear.</pre>
|
||||
|
||||
Twitter would display the text "Totally interesting! A must-see! Please click the link!".
|
||||
On Friendica you would only see the text after "I want to tell you a really ..."
|
||||
|
||||
It is even possible to define abstracts for separate networks:
|
||||
|
||||
<pre>
|
||||
[abstract]Hi friends Here are my newest pictures![abstract]
|
||||
[abstract=twit]Hi my dear Twitter followers. Do you want to see my new
|
||||
pictures?[abstract]
|
||||
[abstract=apdn]Helly my dear followers on ADN. I made sone new pictures
|
||||
that I wanted to share with you.[abstract]
|
||||
Today I was in the woods and took some real cool pictures ...
|
||||
</pre>
|
||||
|
||||
For Twitter and App.net the system will use the defined abstracts.
|
||||
For other networks (e.g. when you are using the "statusnet" connector that is used to post to GNU Social) the general abstract element will be used.
|
||||
|
||||
If you use (for example) the "buffer" connector to post to Facebook or Google+ you can use this element to define an abstract for a longer blogpost that you don't want to post completely to these networks.
|
||||
|
||||
Networks like Facebook or Google+ aren't length limited.
|
||||
For this reason the [abstract] element isn't used.
|
||||
Instead you have to name the explicit network:
|
||||
|
||||
<pre>
|
||||
[abstract]These days I had a strange encounter ...[abstract]
|
||||
[abstract=goog]Helly my dear Google+ followers. You have to read my
|
||||
newest blog post![abstract]
|
||||
[abstract=face]Hello my Facebook friends. These days happened something
|
||||
really cool.[abstract]
|
||||
While taking pictures in the woods I had a really strange encounter ... </pre>
|
||||
|
||||
The [abstract] element isn't working with the native OStatus connection or with connectors where we post the HTML.
|
||||
(Like Tumblr, Wordpress or Pump.io)
|
||||
|
||||
Special
|
||||
-------
|
||||
|
@ -150,5 +200,3 @@ Special
|
|||
If you need to put literal bbcode in a message, [noparse], [nobb] or [pre] are used to escape bbcode:
|
||||
|
||||
<pre>[noparse][b]bold[/b][/noparse]</pre> : [b]bold[/b]
|
||||
|
||||
|
||||
|
|
|
@ -6,6 +6,8 @@ Bugs and Issues
|
|||
If your server has a support page, you should report any bugs/issues you encounter there first.
|
||||
Reporting to your support page before reporting to the developers makes their job easier, as they don't have to deal with bug reports that might not have anything to do with them.
|
||||
This helps us get new features faster.
|
||||
You can also contact the [friendica support forum](https://helpers.pyxis.uberspace.de/profile/helpers) and report your problem there.
|
||||
Maybe someone from another node encountered the problem as well and can help you.
|
||||
|
||||
If you're a technical user, or your site doesn't have a support page, you'll need to use the [Bug Tracker](http://bugs.friendica.com/).
|
||||
Please perform a search to see if there's already an open bug that matches yours before submitting anything.
|
||||
|
|
|
@ -57,13 +57,15 @@ All that the pages need to have is a discoverable feed using either the RSS or A
|
|||
Twitter
|
||||
---
|
||||
|
||||
To follow a Twitter member, put the URL of the Twitter member's main page into the Connect box on your [Contacts](contacts) page.
|
||||
To follow a Twitter member, the Twitter-Connector (Addon) needs to be configured on your node.
|
||||
If this is the case put the URL of the Twitter member's main page into the Connect box on your [Contacts](contacts) page.
|
||||
To reply, you must have the Twitter connector installed, and reply using your own status editor.
|
||||
Begin the message with @twitterperson replacing with the Twitter username.
|
||||
|
||||
Email
|
||||
---
|
||||
|
||||
If the php module for IMAP support is available on your server, Friendica can connect to email contacts as well.
|
||||
Configure the email connector from your [Settings](settings) page.
|
||||
Once this has been done, you may enter an email address to connect with using the Connect box on your [Contacts](contacts) page.
|
||||
They must be the sender of a message which is currently in your INBOX for the connection to succeed.
|
||||
|
|
|
@ -83,11 +83,11 @@ Ask us to find out whom to talk to about their experiences.
|
|||
Do not worry about cross-posting.
|
||||
|
||||
###Client software
|
||||
There are free software clients that do somehow work with Friendica but most of them need love and maintenance.
|
||||
Also, they were mostly made for other platforms using the GNU Social API.
|
||||
This means they lack the features that are really specific to Friendica.
|
||||
Popular clients you might want to have a look at are:
|
||||
As Friendica is using a [Twitter/GNU Social compatible API](help/api) any of the clients for those platforms should work with Friendica as well.
|
||||
Furthermore there are several client projects, especially for use with Friendica.
|
||||
If you are interested in improving those clients, please contact the developers of the clients directly.
|
||||
|
||||
* [Hotot (Linux)](http://hotot.org/) - abandoned
|
||||
* [Friendica for Android](https://github.com/max-weller/friendica-for-android) - abandoned
|
||||
* You can find more working client software in [Wikipedia](https://en.wikipedia.org/wiki/Friendica).
|
||||
* Android / CynogenMod: **Friendica for Android** [src](https://github.com/max-weller/friendica-for-android), [homepage](http://friendica.android.max-weller.de/) - abandoned
|
||||
* iOS: *currently no client*
|
||||
* SailfishOS: **Friendiy** [src](https://kirgroup.com/projects/fabrixxm/harbour-friendly) - developed by [Fabio](https://kirgroup.com/profile/fabrixxm/?tab=profile)
|
||||
* Windows: **Friendica Mobile** for Windows versions [before 8.1](http://windowsphone.com/s?appid=e3257730-c9cf-4935-9620-5261e3505c67) and [Windows 10](https://www.microsoft.com/store/apps/9nblggh0fhmn) - developed by [Gerhard Seeber](http://mozartweg.dyndns.org/friendica/profile/gerhard/?tab=profile)
|
||||
|
|
|
@ -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)
|
||||
|
|
101
doc/Plugins.md
101
doc/Plugins.md
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -11,8 +11,6 @@ Hot Keys
|
|||
Friendica traps the following keyboard events:
|
||||
|
||||
* [Pause] - Pauses "Ajax" update activity. This is the process that provides updates without reloading the page. You may wish to pause it to reduce network usage and/or as a debugging aid for javascript developers. A pause indicator will appear at the lower right hand corner of the page. Hit the [pause] key once again to resume.
|
||||
* [F8] - Displays a language selector
|
||||
|
||||
|
||||
Birthday Notifications
|
||||
---
|
||||
|
|
450
doc/api.md
450
doc/api.md
|
@ -1,12 +1,27 @@
|
|||
Friendica API
|
||||
===
|
||||
The Friendica API aims to be compatible to the [GNU Social API](http://skilledtests.com/wiki/Twitter-compatible_API) and the [Twitter API](https://dev.twitter.com/rest/public).
|
||||
The Friendica API aims to be compatible to the [GNU Social API](http://wiki.gnusocial.de/gnusocial:api) and the [Twitter API](https://dev.twitter.com/rest/public).
|
||||
|
||||
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,28 @@ 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/conversation (*; AUTH)
|
||||
It shows all direct answers (excluding the original post) to a given id.
|
||||
|
||||
#### Parameter
|
||||
* id: id of the post
|
||||
* count: Items per page (default: 20)
|
||||
* page: page number
|
||||
* since_id: minimal id
|
||||
* max_id: maximum id
|
||||
* include_entities: "true" shows entities for pictures and links (Default: false)
|
||||
|
||||
---
|
||||
### statusnet/version (*)
|
||||
|
||||
#### Unsupported parameters
|
||||
* user_id
|
||||
|
@ -507,7 +411,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 +421,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 +437,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 +477,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 +502,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 +526,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) | "<status>success</status>" (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 +790,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
209
doc/autoloader.md
Normal 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 ("\").
|
||||
|
|
@ -15,7 +15,6 @@ Database Tables
|
|||
| [contact](help/database/db_contact) | contact table |
|
||||
| [conv](help/database/db_conv) | private messages |
|
||||
| [deliverq](help/database/db_deliverq) | |
|
||||
| [dsprphotoq](help/database/db_dsprphotoq) | |
|
||||
| [event](help/database/db_event) | Events |
|
||||
| [fcontact](help/database/db_fcontact) | friend suggestion stuff |
|
||||
| [ffinder](help/database/db_ffinder) | friend suggestion stuff |
|
||||
|
@ -27,7 +26,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 |
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
Table dsprphotoq
|
||||
================
|
||||
|
||||
| Field | Description | Type | Null | Key | Default | Extra |
|
||||
|---------|------------------|------------------|------|-----|---------|----------------|
|
||||
| id | sequential ID | int(10) unsigned | NO | PRI | NULL | auto_increment |
|
||||
| uid | | int(11) | NO | | 0 | |
|
||||
| msg | | mediumtext | NO | | NULL | |
|
||||
| attempt | | tinyint(4) | NO | | 0 | |
|
||||
|
||||
Return to [database documentation](help/database)
|
|
@ -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)
|
|
@ -5,7 +5,6 @@ Table sign
|
|||
| ------------ | ------------- | ---------------- | ---- | --- | ------- | --------------- |
|
||||
| id | sequential ID | int(10) unsigned | NO | PRI | NULL | auto_increment |
|
||||
| iid | item.id | int(10) unsigned | NO | MUL | 0 | |
|
||||
| retract_iid | | int(10) unsigned | NO | MUL | 0 | |
|
||||
| signed_text | | mediumtext | NO | | NULL | |
|
||||
| signature | | text | NO | | NULL | |
|
||||
| signer | | varchar(255) | NO | | | |
|
||||
|
|
|
@ -131,8 +131,7 @@ Außerdem kann *url* die genaue url zu einer ogg Datei sein, die dann per H
|
|||
|
||||
<pre>[url]*url*[/url]</pre>
|
||||
|
||||
Wenn *url* entweder oembed oder opengraph unterstützt wird das eingebettete
|
||||
Objekt (z.B. ein Dokument von scribd) eingebunden.
|
||||
Wenn *url* entweder oembed oder opengraph unterstützt wird das eingebettete Objekt (z.B. ein Dokument von scribd) eingebunden.
|
||||
Der Titel der Seite mit einem Link zur *url* wird ebenfalls angezeigt.
|
||||
|
||||
Um eine Karte in einen Beitrag einzubinden, muss das *openstreetmap* Addon aktiviert werden. Ist dies der Fall, kann mit
|
||||
|
@ -145,11 +144,54 @@ eine Karte von [OpenStreetmap](http://openstreetmap.org) eingebettet werden. Zur
|
|||
|
||||
oder eine Adresse in obiger Form verwendet werden.
|
||||
|
||||
Zusammenfassung für längere Beiträge
|
||||
------------------------------------
|
||||
|
||||
Wenn man seine Beiträge über mehrere Netzwerke verbreiten möchte, hat man häufig das Problem, dass diese Netzwerke z.B. eine Längenbeschränkung haben.
|
||||
(Z.B. Twitter).
|
||||
|
||||
Friendica benutzt zum Erzeugen eines Anreißtextes eine halbwegs intelligente Logik.
|
||||
Es kann aber dennoch von Interesse sein, eine eigene Zusammenfassung zu erstellen, die nur auf dem Fremdnetzwerk dargestellt wird.
|
||||
Dies geschieht mit dem [abstract]-Element.
|
||||
Beispiel:
|
||||
|
||||
<pre>[abstract]Total spannend! Unbedingt diesen Link anklicken![/abstract]
|
||||
Hier erzähle ich euch eine total langweilige Geschichte, die ihr noch
|
||||
nie hören wolltet.</pre>
|
||||
|
||||
Auf Twitter würde das "Total spannend! Unbedingt diesen Link anklicken!" stehen, auf Friendica würde nur der Text nach "Hier erzähle ..." erscheinen.
|
||||
|
||||
Es ist sogar möglich, für einzelne Netzwerke eigene Zusammenfassungen zu erstellen:
|
||||
|
||||
<pre>
|
||||
[abstract]Hallo Leute, hier meine neuesten Bilder![abstract]
|
||||
[abstract=twit]Hallo Twitter-User, hier meine neuesten Bilder![abstract]
|
||||
[abstract=apdn]Hallo App.net-User, hier meine neuesten Bilder![abstract]
|
||||
Ich war heute wieder im Wald unterwegs und habe tolle Bilder geschossen ...
|
||||
</pre>
|
||||
|
||||
Für Twitter und App.net nimmt das System die entsprechenden Texte.
|
||||
Bei anderen Netzwerken, bei denen der Inhalt gekürzt wird (z.B. beim "statusnet"-Connector, der für das Posten nach GNU Social verwendet wird) wird dann die Zusammenfassung unter [abstract] verwendet.
|
||||
|
||||
Wenn man z.B. den "buffer"-Connector verwendet, um nach Facebook oder Google+ zu posten, kann man dieses Element ebenfalls verwenden, wenn man z.B. einen längeren Blogbeitrag erstellt hat, aber ihn nicht komplett in diese Netzwerke posten möchte.
|
||||
|
||||
Netzwerke wie Facebook oder Google+ sind nicht in der Postinglänge beschränkt.
|
||||
Aus diesem Grund greift nicht die [abstract]-Zusammenfassung. Stattdessen muss man das Netzwerk explizit angeben:
|
||||
|
||||
<pre>
|
||||
[abstract]Ich habe neulich wieder etwas erlebt, was ich euch mitteilen möchte.[abstract]
|
||||
[abstract=goog]Hallo meine Google+-Kreislinge. Ich habe neulich wieder
|
||||
etwas erlebt, was ich euch mitteilen möchte.[abstract]
|
||||
[abstract=face]Hallo Facebook-Freunde! Ich habe neulich wieder etwas
|
||||
erlebt, was ich euch mitteilen möchte.[abstract]
|
||||
Beim Bildermachen im Wald habe ich neulich eine interessante Person
|
||||
getroffen ... </pre>
|
||||
|
||||
Das [abstract]-Element greift nicht bei der nativen OStatus-Verbindung oder bei Connectoren, die den HTML-Text posten wie z.B. die Connectoren zu Tumblr, Wordpress oder Pump.io.
|
||||
|
||||
Spezielle Tags
|
||||
-------
|
||||
|
||||
Wenn Du über BBCode Tags in einer Nachricht schreiben möchtest, kannst Du [noparse], [nobb] oder [pre] verwenden um den BBCode Tags vor der Evaluierung zu schützen:
|
||||
|
||||
<pre>[noparse][b]fett[/b][/noparse]</pre> : [b]fett[/b]
|
||||
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -14,9 +14,6 @@ Friendica erfasst die folgenden Tastaturbefehle:
|
|||
|
||||
* [Pause] - Pausiert die Update-Aktivität via "Ajax". Das ist ein Prozess, der Updates durchführt, ohne die Seite neu zu laden. Du kannst diesen Prozess pausieren, um deine Netzwerkauslastung zu reduzieren und/oder um es in der Javascript-Programmierung zum Debuggen zu nutzen. Ein Pausenzeichen erscheint unten links im Fenster. Klicke die [Pause]-Taste ein weiteres Mal, um die Pause zu beenden.
|
||||
|
||||
* [F8] - Zeigt eine Sprachauswahl an
|
||||
|
||||
|
||||
**Geburtstagsbenachrichtigung**
|
||||
|
||||
Geburtstage erscheinen auf deiner Startseite für alle Freunde, die in den nächsten 6 Tagen Geburtstag haben.
|
||||
|
|
|
@ -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.
|
||||
|
@ -63,9 +64,6 @@ line to your .htconfig.php:
|
|||
* throttle_limit_week - Maximum number of posts that a user can send per week with the API.
|
||||
* throttle_limit_month - Maximum number of posts that a user can send per month with the API.
|
||||
* wall-to-wall_share (Boolean) - Displays forwarded posts like "wall-to-wall" posts.
|
||||
* worker (Boolean) - (Experimental) Use the worker system instead of calling several background processes. Reduces the overall load and speeds up item delivery.
|
||||
* worker_dont_fork (Boolean) - if enabled, the workers are only called from the poller process. Useful on systems that permit the use of "proc_open".
|
||||
* worker_queues - Number of parallel workers. Default value is 10 queues.
|
||||
* xrd_timeout - Timeout for fetching the XRD links. Default value is 20 seconds.
|
||||
|
||||
## service_class ##
|
||||
|
|
|
@ -129,7 +129,7 @@ function terminate_friendship($user,$self,$contact) {
|
|||
}
|
||||
elseif($contact['network'] === NETWORK_DIASPORA) {
|
||||
require_once('include/diaspora.php');
|
||||
diaspora_unshare($user,$contact);
|
||||
diaspora::send_unshare($user,$contact);
|
||||
}
|
||||
elseif($contact['network'] === NETWORK_DFRN) {
|
||||
require_once('include/dfrn.php');
|
||||
|
@ -555,60 +555,6 @@ function posts_from_gcontact($a, $gcontact_id) {
|
|||
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
|
||||
*
|
||||
|
|
190
include/ForumManager.php
Normal file
190
include/ForumManager.php
Normal file
|
@ -0,0 +1,190 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file include/ForumManager.php
|
||||
* @brief ForumManager class with its methods related to forum functionality *
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief This class handles metheods 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' => 'network?f=&cid=' . $contact['id'],
|
||||
'external_url' => 'redir/' . $contact['id'],
|
||||
'name' => $contact['name'],
|
||||
'cid' => $contact['id'],
|
||||
'selected' => $selected,
|
||||
'micro' => App::remove_baseurl(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;
|
||||
}
|
||||
|
||||
}
|
136
include/NotificationsManager.php
Normal file
136
include/NotificationsManager.php
Normal 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())
|
||||
);
|
||||
}
|
||||
}
|
|
@ -726,10 +726,11 @@ function guess_image_type($filename, $fromcurl=false) {
|
|||
* @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) {
|
||||
function update_contact_avatar($avatar,$uid,$cid, $force = false) {
|
||||
|
||||
$r = q("SELECT `avatar`, `photo`, `thumb`, `micro` FROM `contact` WHERE `id` = %d LIMIT 1", intval($cid));
|
||||
if (!$r)
|
||||
|
@ -737,7 +738,7 @@ function update_contact_avatar($avatar,$uid,$cid) {
|
|||
else
|
||||
$data = array($r[0]["photo"], $r[0]["thumb"], $r[0]["micro"]);
|
||||
|
||||
if ($r[0]["avatar"] != $avatar) {
|
||||
if (($r[0]["avatar"] != $avatar) OR $force) {
|
||||
$photos = import_profile_photo($avatar,$uid,$cid, true);
|
||||
|
||||
if ($photos) {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
require_once('library/HTML5/Parser.php');
|
||||
require_once('include/crypto.php');
|
||||
require_once('include/feed.php');
|
||||
|
||||
if(! function_exists('scrape_dfrn')) {
|
||||
function scrape_dfrn($url, $dont_probe = false) {
|
||||
|
@ -12,9 +13,25 @@ function scrape_dfrn($url, $dont_probe = false) {
|
|||
|
||||
logger('scrape_dfrn: url=' . $url);
|
||||
|
||||
// Try to fetch the data from noscrape. This is faster than parsing the HTML
|
||||
$noscrape = str_replace("/hcard/", "/noscrape/", $url);
|
||||
$noscrapejson = fetch_url($noscrape);
|
||||
$noscrapedata = array();
|
||||
if ($noscrapejson) {
|
||||
$noscrapedata = json_decode($noscrapejson, true);
|
||||
|
||||
if (is_array($noscrapedata)) {
|
||||
if ($noscrapedata["nick"] != "")
|
||||
return($noscrapedata);
|
||||
else
|
||||
unset($noscrapedata["nick"]);
|
||||
} else
|
||||
$noscrapedata = array();
|
||||
}
|
||||
|
||||
$s = fetch_url($url);
|
||||
|
||||
if(! $s)
|
||||
if (!$s)
|
||||
return $ret;
|
||||
|
||||
if (!$dont_probe) {
|
||||
|
@ -91,8 +108,7 @@ function scrape_dfrn($url, $dont_probe = false) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
return array_merge($ret, $noscrapedata);
|
||||
}}
|
||||
|
||||
|
||||
|
@ -342,7 +358,7 @@ function probe_url($url, $mode = PROBE_NORMAL, $level = 1) {
|
|||
|
||||
$result = array();
|
||||
|
||||
if(! $url)
|
||||
if (!$url)
|
||||
return $result;
|
||||
|
||||
$result = Cache::get("probe_url:".$mode.":".$url);
|
||||
|
@ -351,6 +367,7 @@ function probe_url($url, $mode = PROBE_NORMAL, $level = 1) {
|
|||
return $result;
|
||||
}
|
||||
|
||||
$original_url = $url;
|
||||
$network = null;
|
||||
$diaspora = false;
|
||||
$diaspora_base = '';
|
||||
|
@ -366,8 +383,6 @@ function probe_url($url, $mode = PROBE_NORMAL, $level = 1) {
|
|||
$network = NETWORK_TWITTER;
|
||||
}
|
||||
|
||||
// Twitter is deactivated since twitter closed its old API
|
||||
//$twitter = ((strpos($url,'twitter.com') !== false) ? true : false);
|
||||
$lastfm = ((strpos($url,'last.fm/user') !== false) ? true : false);
|
||||
|
||||
$at_addr = ((strpos($url,'@') !== false) ? true : false);
|
||||
|
@ -381,7 +396,12 @@ function probe_url($url, $mode = PROBE_NORMAL, $level = 1) {
|
|||
else
|
||||
$links = lrdd($url);
|
||||
|
||||
if(count($links)) {
|
||||
if ((count($links) == 0) AND strstr($url, "/index.php")) {
|
||||
$url = str_replace("/index.php", "", $url);
|
||||
$links = lrdd($url);
|
||||
}
|
||||
|
||||
if (count($links)) {
|
||||
$has_lrdd = true;
|
||||
|
||||
logger('probe_url: found lrdd links: ' . print_r($links,true), LOGGER_DATA);
|
||||
|
@ -428,12 +448,21 @@ function probe_url($url, $mode = PROBE_NORMAL, $level = 1) {
|
|||
// aliases, let's hope we're lucky and get one that matches the feed author-uri because
|
||||
// otherwise we're screwed.
|
||||
|
||||
$backup_alias = "";
|
||||
|
||||
foreach($links as $link) {
|
||||
if($link['@attributes']['rel'] === 'alias') {
|
||||
if(strpos($link['@attributes']['href'],'@') === false) {
|
||||
if(isset($profile)) {
|
||||
if($link['@attributes']['href'] !== $profile)
|
||||
$alias = unamp($link['@attributes']['href']);
|
||||
$alias_url = $link['@attributes']['href'];
|
||||
|
||||
if(($alias_url !== $profile) AND ($backup_alias == "") AND
|
||||
($alias_url !== str_replace("/index.php", "", $profile)))
|
||||
$backup_alias = $alias_url;
|
||||
|
||||
if(($alias_url !== $profile) AND !strstr($alias_url, "index.php") AND
|
||||
($alias_url !== str_replace("/index.php", "", $profile)))
|
||||
$alias = $alias_url;
|
||||
}
|
||||
else
|
||||
$profile = unamp($link['@attributes']['href']);
|
||||
|
@ -441,6 +470,9 @@ function probe_url($url, $mode = PROBE_NORMAL, $level = 1) {
|
|||
}
|
||||
}
|
||||
|
||||
if ($alias == "")
|
||||
$alias = $backup_alias;
|
||||
|
||||
// If the profile is different from the url then the url is abviously an alias
|
||||
if (($alias == "") AND ($profile != "") AND !$at_addr AND (normalise_link($profile) != normalise_link($url)))
|
||||
$alias = $url;
|
||||
|
@ -604,21 +636,6 @@ function probe_url($url, $mode = PROBE_NORMAL, $level = 1) {
|
|||
$vcard['nick'] = $addr_parts[0];
|
||||
}
|
||||
|
||||
/* if($twitter) {
|
||||
logger('twitter: setup');
|
||||
$tid = basename($url);
|
||||
$tapi = 'https://api.twitter.com/1/statuses/user_timeline.rss';
|
||||
if(intval($tid))
|
||||
$poll = $tapi . '?user_id=' . $tid;
|
||||
else
|
||||
$poll = $tapi . '?screen_name=' . $tid;
|
||||
$profile = 'http://twitter.com/#!/' . $tid;
|
||||
//$vcard['photo'] = 'https://api.twitter.com/1/users/profile_image/' . $tid;
|
||||
$vcard['photo'] = 'https://api.twitter.com/1/users/profile_image?screen_name=' . $tid . '&size=bigger';
|
||||
$vcard['nick'] = $tid;
|
||||
$vcard['fn'] = $tid;
|
||||
} */
|
||||
|
||||
if($lastfm) {
|
||||
$profile = $url;
|
||||
$poll = str_replace(array('www.','last.fm/'),array('','ws.audioscrobbler.com/1.0/'),$url) . '/recenttracks.rss';
|
||||
|
@ -662,85 +679,41 @@ function probe_url($url, $mode = PROBE_NORMAL, $level = 1) {
|
|||
|
||||
if(x($feedret,'photo') && (! x($vcard,'photo')))
|
||||
$vcard['photo'] = $feedret['photo'];
|
||||
require_once('library/simplepie/simplepie.inc');
|
||||
$feed = new SimplePie();
|
||||
|
||||
$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();
|
||||
|
||||
logger('probe_url: scrape_feed: headers: ' . $a->get_curl_headers(), LOGGER_DATA);
|
||||
|
||||
// Don't try and parse an empty string
|
||||
$feed->set_raw_data(($xml) ? $xml : '<?xml version="1.0" encoding="utf-8" ?><xml></xml>');
|
||||
|
||||
$feed->init();
|
||||
if($feed->error()) {
|
||||
logger('probe_url: scrape_feed: Error parsing XML: ' . $feed->error());
|
||||
if ($xml == "") {
|
||||
logger("scrape_feed: XML is empty for feed ".$poll);
|
||||
$network = NETWORK_PHANTOM;
|
||||
}
|
||||
} else {
|
||||
$data = feed_import($xml,$dummy1,$dummy2, $dummy3, true);
|
||||
|
||||
if(! x($vcard,'photo'))
|
||||
$vcard['photo'] = $feed->get_image_url();
|
||||
$author = $feed->get_author();
|
||||
if (!is_array($data)) {
|
||||
logger("scrape_feed: This doesn't seem to be a feed: ".$poll);
|
||||
$network = NETWORK_PHANTOM;
|
||||
} else {
|
||||
if (($vcard["photo"] == "") AND ($data["header"]["author-avatar"] != ""))
|
||||
$vcard["photo"] = $data["header"]["author-avatar"];
|
||||
|
||||
if($author) {
|
||||
$vcard['fn'] = unxmlify(trim($author->get_name()));
|
||||
if(! $vcard['fn'])
|
||||
$vcard['fn'] = trim(unxmlify($author->get_email()));
|
||||
if(strpos($vcard['fn'],'@') !== false)
|
||||
$vcard['fn'] = substr($vcard['fn'],0,strpos($vcard['fn'],'@'));
|
||||
if (($vcard["fn"] == "") AND ($data["header"]["author-name"] != ""))
|
||||
$vcard["fn"] = $data["header"]["author-name"];
|
||||
|
||||
$email = unxmlify($author->get_email());
|
||||
if(! $profile && $author->get_link())
|
||||
$profile = trim(unxmlify($author->get_link()));
|
||||
if(! $vcard['photo']) {
|
||||
$rawtags = $feed->get_feed_tags( SIMPLEPIE_NAMESPACE_ATOM_10, 'author');
|
||||
if($rawtags) {
|
||||
$elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10];
|
||||
if((x($elems,'link')) && ($elems['link'][0]['attribs']['']['rel'] === 'photo'))
|
||||
$vcard['photo'] = $elems['link'][0]['attribs']['']['href'];
|
||||
}
|
||||
}
|
||||
// Fetch fullname via poco:displayName
|
||||
$pocotags = $feed->get_feed_tags(SIMPLEPIE_NAMESPACE_ATOM_10, 'author');
|
||||
if ($pocotags) {
|
||||
$elems = $pocotags[0]['child']['http://portablecontacts.net/spec/1.0'];
|
||||
if (isset($elems["displayName"]))
|
||||
$vcard['fn'] = $elems["displayName"][0]["data"];
|
||||
if (isset($elems["preferredUsername"]))
|
||||
$vcard['nick'] = $elems["preferredUsername"][0]["data"];
|
||||
}
|
||||
}
|
||||
else {
|
||||
$item = $feed->get_item(0);
|
||||
if($item) {
|
||||
$author = $item->get_author();
|
||||
if($author) {
|
||||
$vcard['fn'] = trim(unxmlify($author->get_name()));
|
||||
if(! $vcard['fn'])
|
||||
$vcard['fn'] = trim(unxmlify($author->get_email()));
|
||||
if(strpos($vcard['fn'],'@') !== false)
|
||||
$vcard['fn'] = substr($vcard['fn'],0,strpos($vcard['fn'],'@'));
|
||||
$email = unxmlify($author->get_email());
|
||||
if(! $profile && $author->get_link())
|
||||
$profile = trim(unxmlify($author->get_link()));
|
||||
}
|
||||
if(! $vcard['photo']) {
|
||||
$rawmedia = $item->get_item_tags('http://search.yahoo.com/mrss/','thumbnail');
|
||||
if($rawmedia && $rawmedia[0]['attribs']['']['url'])
|
||||
$vcard['photo'] = unxmlify($rawmedia[0]['attribs']['']['url']);
|
||||
}
|
||||
if(! $vcard['photo']) {
|
||||
$rawtags = $item->get_item_tags( SIMPLEPIE_NAMESPACE_ATOM_10, 'author');
|
||||
if($rawtags) {
|
||||
$elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10];
|
||||
if((x($elems,'link')) && ($elems['link'][0]['attribs']['']['rel'] === 'photo'))
|
||||
$vcard['photo'] = $elems['link'][0]['attribs']['']['href'];
|
||||
}
|
||||
}
|
||||
if (($vcard["nick"] == "") AND ($data["header"]["author-nick"] != ""))
|
||||
$vcard["nick"] = $data["header"]["author-nick"];
|
||||
|
||||
if ($network == NETWORK_OSTATUS) {
|
||||
if ($data["header"]["author-id"] != "")
|
||||
$alias = $data["header"]["author-id"];
|
||||
|
||||
if ($data["header"]["author-link"] != "")
|
||||
$profile = $data["header"]["author-link"];
|
||||
|
||||
} elseif(!$profile AND ($data["header"]["author-link"] != "") AND !in_array($network, array("", NETWORK_FEED)))
|
||||
$profile = $data["header"]["author-link"];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -783,27 +756,9 @@ function probe_url($url, $mode = PROBE_NORMAL, $level = 1) {
|
|||
}
|
||||
}
|
||||
|
||||
if((! $vcard['photo']) && strlen($email))
|
||||
$vcard['photo'] = avatar_img($email);
|
||||
if($poll === $profile)
|
||||
$lnk = $feed->get_permalink();
|
||||
if(isset($lnk) && strlen($lnk))
|
||||
$profile = $lnk;
|
||||
|
||||
if(! $network) {
|
||||
if(! $network)
|
||||
$network = NETWORK_FEED;
|
||||
// If it is a feed, don't take the author name as feed name
|
||||
unset($vcard['fn']);
|
||||
}
|
||||
if(! (x($vcard,'fn')))
|
||||
$vcard['fn'] = notags($feed->get_title());
|
||||
if(! (x($vcard,'fn')))
|
||||
$vcard['fn'] = notags($feed->get_description());
|
||||
|
||||
if(strpos($vcard['fn'],'Twitter / ') !== false) {
|
||||
$vcard['fn'] = substr($vcard['fn'],strpos($vcard['fn'],'/')+1);
|
||||
$vcard['fn'] = trim($vcard['fn']);
|
||||
}
|
||||
if(! x($vcard,'nick')) {
|
||||
$vcard['nick'] = strtolower(notags(unxmlify($vcard['fn'])));
|
||||
if(strpos($vcard['nick'],' '))
|
||||
|
@ -816,7 +771,7 @@ function probe_url($url, $mode = PROBE_NORMAL, $level = 1) {
|
|||
|
||||
if(! x($vcard,'photo')) {
|
||||
$a = get_app();
|
||||
$vcard['photo'] = $a->get_baseurl() . '/images/person-175.jpg' ;
|
||||
$vcard['photo'] = App::get_baseurl() . '/images/person-175.jpg' ;
|
||||
}
|
||||
|
||||
if(! $profile)
|
||||
|
@ -828,18 +783,21 @@ function probe_url($url, $mode = PROBE_NORMAL, $level = 1) {
|
|||
$vcard['fn'] = $url;
|
||||
|
||||
if (($notify != "") AND ($poll != "")) {
|
||||
$baseurl = matching(normalise_link($notify), normalise_link($poll));
|
||||
$baseurl = matching_url(normalise_link($notify), normalise_link($poll));
|
||||
|
||||
$baseurl2 = matching($baseurl, normalise_link($profile));
|
||||
$baseurl2 = matching_url($baseurl, normalise_link($profile));
|
||||
if ($baseurl2 != "")
|
||||
$baseurl = $baseurl2;
|
||||
}
|
||||
|
||||
if (($baseurl == "") AND ($notify != ""))
|
||||
$baseurl = matching(normalise_link($profile), normalise_link($notify));
|
||||
$baseurl = matching_url(normalise_link($profile), normalise_link($notify));
|
||||
|
||||
if (($baseurl == "") AND ($poll != ""))
|
||||
$baseurl = matching(normalise_link($profile), normalise_link($poll));
|
||||
$baseurl = matching_url(normalise_link($profile), normalise_link($poll));
|
||||
|
||||
if (substr($baseurl, -10) == "/index.php")
|
||||
$baseurl = str_replace("/index.php", "", $baseurl);
|
||||
|
||||
$baseurl = rtrim($baseurl, "/");
|
||||
|
||||
|
@ -888,25 +846,82 @@ function probe_url($url, $mode = PROBE_NORMAL, $level = 1) {
|
|||
}
|
||||
|
||||
// Only store into the cache if the value seems to be valid
|
||||
if ($result['network'] != NETWORK_PHANTOM)
|
||||
Cache::set("probe_url:".$mode.":".$url,serialize($result), CACHE_DAY);
|
||||
if ($result['network'] != NETWORK_PHANTOM) {
|
||||
Cache::set("probe_url:".$mode.":".$original_url,serialize($result), CACHE_DAY);
|
||||
|
||||
/// @todo temporary fix - we need a real contact update function that updates only changing fields
|
||||
/// The biggest problem is the avatar picture that could have a reduced image size.
|
||||
/// It should only be updated if the existing picture isn't existing anymore.
|
||||
if (($result['network'] != NETWORK_FEED) AND ($mode == PROBE_NORMAL) AND
|
||||
$result["name"] AND $result["nick"] AND $result["url"] AND $result["addr"] AND $result["poll"])
|
||||
q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `url` = '%s', `addr` = '%s',
|
||||
`notify` = '%s', `poll` = '%s', `alias` = '%s', `success_update` = '%s'
|
||||
WHERE `nurl` = '%s' AND NOT `self` AND `uid` = 0",
|
||||
dbesc($result["name"]),
|
||||
dbesc($result["nick"]),
|
||||
dbesc($result["url"]),
|
||||
dbesc($result["addr"]),
|
||||
dbesc($result["notify"]),
|
||||
dbesc($result["poll"]),
|
||||
dbesc($result["alias"]),
|
||||
dbesc(datetime_convert()),
|
||||
dbesc(normalise_link($result['url']))
|
||||
);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function matching($part1, $part2) {
|
||||
$len = min(strlen($part1), strlen($part2));
|
||||
/**
|
||||
* @brief Find the matching part between two url
|
||||
*
|
||||
* @param string $url1
|
||||
* @param string $url2
|
||||
* @return string The matching part
|
||||
*/
|
||||
function matching_url($url1, $url2) {
|
||||
|
||||
if (($url1 == "") OR ($url2 == ""))
|
||||
return "";
|
||||
|
||||
$url1 = normalise_link($url1);
|
||||
$url2 = normalise_link($url2);
|
||||
|
||||
$parts1 = parse_url($url1);
|
||||
$parts2 = parse_url($url2);
|
||||
|
||||
if (!isset($parts1["host"]) OR !isset($parts2["host"]))
|
||||
return "";
|
||||
|
||||
if ($parts1["scheme"] != $parts2["scheme"])
|
||||
return "";
|
||||
|
||||
if ($parts1["host"] != $parts2["host"])
|
||||
return "";
|
||||
|
||||
if ($parts1["port"] != $parts2["port"])
|
||||
return "";
|
||||
|
||||
$match = $parts1["scheme"]."://".$parts1["host"];
|
||||
|
||||
if ($parts1["port"])
|
||||
$match .= ":".$parts1["port"];
|
||||
|
||||
$pathparts1 = explode("/", $parts1["path"]);
|
||||
$pathparts2 = explode("/", $parts2["path"]);
|
||||
|
||||
$match = "";
|
||||
$matching = true;
|
||||
$i = 0;
|
||||
while (($i <= $len) AND $matching) {
|
||||
if (substr($part1, $i, 1) == substr($part2, $i, 1))
|
||||
$match .= substr($part1, $i, 1);
|
||||
else
|
||||
$matching = false;
|
||||
$path = "";
|
||||
do {
|
||||
$path1 = $pathparts1[$i];
|
||||
$path2 = $pathparts2[$i];
|
||||
|
||||
$i++;
|
||||
}
|
||||
return($match);
|
||||
if ($path1 == $path2)
|
||||
$path .= $path1."/";
|
||||
|
||||
} while (($path1 == $path2) AND ($i++ <= count($pathparts1)));
|
||||
|
||||
$match .= $path;
|
||||
|
||||
return normalise_link($match);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file include/smilies.php
|
||||
* @file include/Smilies.php
|
||||
* @brief This file contains the Smilies class which contains functions to handle smiles
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -63,41 +64,41 @@ class Smilies {
|
|||
);
|
||||
|
||||
$icons = array(
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-heart.gif" alt="<3" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-brokenheart.gif" alt="</3" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-brokenheart.gif" alt="<\\3" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-smile.gif" alt=":-)" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-wink.gif" alt=";-)" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-frown.gif" alt=":-(" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-tongue-out.gif" alt=":-P" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-tongue-out.gif" alt=":-p" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-kiss.gif" alt=":-\"" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-kiss.gif" alt=":-\"" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-kiss.gif" alt=":-x" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-kiss.gif" alt=":-X" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-laughing.gif" alt=":-D" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-surprised.gif" alt="8-|" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-surprised.gif" alt="8-O" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-surprised.gif" alt=":-O" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-thumbsup.gif" alt="\\o/" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-Oo.gif" alt="o.O" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-Oo.gif" alt="O.o" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-Oo.gif" alt="o_O" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-Oo.gif" alt="O_o" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-cry.gif" alt=":\'(" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-foot-in-mouth.gif" alt=":-!" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-undecided.gif" alt=":-/" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-embarassed.gif" alt=":-[" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-cool.gif" alt="8-)" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/beer_mug.gif" alt=":beer" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/beer_mug.gif" alt=":homebrew" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/coffee.gif" alt=":coffee" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-facepalm.gif" alt=":facepalm" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/like.gif" alt=":like" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/dislike.gif" alt=":dislike" />',
|
||||
'<a href="http://friendica.com">~friendica <img class="smiley" src="' . app::get_baseurl() . '/images/friendica-16.png" alt="~friendica" /></a>',
|
||||
'<a href="http://redmatrix.me/">red<img class="smiley" src="' . app::get_baseurl() . '/images/rm-16.png" alt="red" />matrix</a>',
|
||||
'<a href="http://redmatrix.me/">red<img class="smiley" src="' . app::get_baseurl() . '/images/rm-16.png" alt="red" />matrix</a>'
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-heart.gif" alt="<3" title="<3" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-brokenheart.gif" alt="</3" title="</3" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-brokenheart.gif" alt="<\\3" title="<\\3" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-smile.gif" alt=":-)" title=":-)" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-wink.gif" alt=";-)" title=";-)" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-frown.gif" alt=":-(" title=":-(" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-tongue-out.gif" alt=":-P" title=":-P" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-tongue-out.gif" alt=":-p" title=":-P" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-kiss.gif" alt=":-\" title=":-\" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-kiss.gif" alt=":-\" title=":-\" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-kiss.gif" alt=":-x" title=":-x" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-kiss.gif" alt=":-X" title=":-X" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-laughing.gif" alt=":-D" title=":-D" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-surprised.gif" alt="8-|" title="8-|" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-surprised.gif" alt="8-O" title="8-O" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-surprised.gif" alt=":-O" title="8-O" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-thumbsup.gif" alt="\\o/" title="\\o/" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-Oo.gif" alt="o.O" title="o.O" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-Oo.gif" alt="O.o" title="O.o" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-Oo.gif" alt="o_O" title="o_O" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-Oo.gif" alt="O_o" title="O_o" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-cry.gif" alt=":\'(" title=":\'("/>',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-foot-in-mouth.gif" alt=":-!" title=":-!" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-undecided.gif" alt=":-/" title=":-/" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-embarassed.gif" alt=":-[" title=":-[" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-cool.gif" alt="8-)" title="8-)" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/beer_mug.gif" alt=":beer" title=":beer" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/beer_mug.gif" alt=":homebrew" title=":homebrew" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/coffee.gif" alt=":coffee" title=":coffee" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/smiley-facepalm.gif" alt=":facepalm" title=":facepalm" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/like.gif" alt=":like" title=":like" />',
|
||||
'<img class="smiley" src="' . app::get_baseurl() . '/images/dislike.gif" alt=":dislike" title=":dislike" />',
|
||||
'<a href="http://friendica.com">~friendica <img class="smiley" src="' . app::get_baseurl() . '/images/friendica-16.png" alt="~friendica" title="~friendica" /></a>',
|
||||
'<a href="http://redmatrix.me/">red<img class="smiley" src="' . app::get_baseurl() . '/images/rm-16.png" alt="red#" title="red#" />matrix</a>',
|
||||
'<a href="http://redmatrix.me/">red<img class="smiley" src="' . app::get_baseurl() . '/images/rm-16.png" alt="red#matrix" title="red#matrix" />matrix</a>'
|
||||
);
|
||||
|
||||
$params = array('texts' => $texts, 'icons' => $icons);
|
||||
|
|
170
include/api.php
170
include/api.php
|
@ -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','*');
|
||||
|
@ -160,10 +161,7 @@
|
|||
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
||||
logger('API_login: ' . print_r($_SERVER,true), LOGGER_DEBUG);
|
||||
header('WWW-Authenticate: Basic realm="Friendica"');
|
||||
header('HTTP/1.0 401 Unauthorized');
|
||||
die((api_error($a, 'json', "This api requires login")));
|
||||
|
||||
//die('This api requires login');
|
||||
throw new UnauthorizedException("This API requires login");
|
||||
}
|
||||
|
||||
$user = $_SERVER['PHP_AUTH_USER'];
|
||||
|
@ -215,8 +213,9 @@
|
|||
if((! $record) || (! count($record))) {
|
||||
logger('API_login failure: ' . print_r($_SERVER,true), LOGGER_DEBUG);
|
||||
header('WWW-Authenticate: Basic realm="Friendica"');
|
||||
header('HTTP/1.0 401 Unauthorized');
|
||||
die('This api requires login');
|
||||
#header('HTTP/1.0 401 Unauthorized');
|
||||
#die('This api requires login');
|
||||
throw new UnauthorizedException("This API requires login");
|
||||
}
|
||||
|
||||
authenticate_success($record); $_SESSION["allow_api"] = true;
|
||||
|
@ -250,7 +249,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";
|
||||
|
@ -330,7 +329,8 @@
|
|||
*
|
||||
* @param Api $a
|
||||
* @param string $type Return type (xml, json, rss, as)
|
||||
* @param string $error Error message
|
||||
* @param HTTPException $error Error object
|
||||
* @return strin error message formatted as $type
|
||||
*/
|
||||
function api_error(&$a, $type, $e) {
|
||||
$error = ($e->getMessage()!==""?$e->getMessage():$e->httpdesc);
|
||||
|
@ -680,6 +680,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
|
||||
*/
|
||||
|
@ -692,13 +720,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;
|
||||
|
@ -781,8 +813,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);
|
||||
|
@ -822,9 +852,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();
|
||||
|
@ -875,7 +902,8 @@
|
|||
|
||||
if ($posts_day > $throttle_day) {
|
||||
logger('Daily posting limit reached for user '.api_user(), LOGGER_DEBUG);
|
||||
die(api_error($a, $type, sprintf(t("Daily posting limit of %d posts reached. The post was rejected."), $throttle_day)));
|
||||
#die(api_error($a, $type, sprintf(t("Daily posting limit of %d posts reached. The post was rejected."), $throttle_day)));
|
||||
throw new TooManyRequestsException(sprintf(t("Daily posting limit of %d posts reached. The post was rejected."), $throttle_day));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -894,7 +922,9 @@
|
|||
|
||||
if ($posts_week > $throttle_week) {
|
||||
logger('Weekly posting limit reached for user '.api_user(), LOGGER_DEBUG);
|
||||
die(api_error($a, $type, sprintf(t("Weekly posting limit of %d posts reached. The post was rejected."), $throttle_week)));
|
||||
#die(api_error($a, $type, sprintf(t("Weekly posting limit of %d posts reached. The post was rejected."), $throttle_week)));
|
||||
throw new TooManyRequestsException(sprintf(t("Weekly posting limit of %d posts reached. The post was rejected."), $throttle_week));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -913,7 +943,8 @@
|
|||
|
||||
if ($posts_month > $throttle_month) {
|
||||
logger('Monthly posting limit reached for user '.api_user(), LOGGER_DEBUG);
|
||||
die(api_error($a, $type, sprintf(t("Monthly posting limit of %d posts reached. The post was rejected."), $throttle_month)));
|
||||
#die(api_error($a, $type, sprintf(t("Monthly posting limit of %d posts reached. The post was rejected."), $throttle_month)));
|
||||
throw new TooManyRequestsException(sprintf(t("Monthly posting limit of %d posts reached. The post was rejected."), $throttle_month));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1493,15 +1524,21 @@
|
|||
if ($max_id > 0)
|
||||
$sql_extra = ' AND `item`.`id` <= '.intval($max_id);
|
||||
|
||||
// Not sure why this query was so complicated. We should keep it here for a while,
|
||||
// just to make sure that we really don't need it.
|
||||
// FROM `item` INNER JOIN (SELECT `uri`,`parent` FROM `item` WHERE `id` = %d) AS `temp1`
|
||||
// ON (`item`.`thr-parent` = `temp1`.`uri` AND `item`.`parent` = `temp1`.`parent`)
|
||||
|
||||
$r = q("SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
|
||||
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
|
||||
`contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
|
||||
`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
|
||||
FROM `item` INNER JOIN (SELECT `uri`,`parent` FROM `item` WHERE `id` = %d) AS `temp1`
|
||||
ON (`item`.`thr-parent` = `temp1`.`uri` AND `item`.`parent` = `temp1`.`parent`), `contact`
|
||||
WHERE `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0
|
||||
AND `item`.`uid` = %d AND `item`.`verb` = '%s' AND `contact`.`id` = `item`.`contact-id`
|
||||
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
|
||||
FROM `item`
|
||||
INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
|
||||
WHERE `item`.`parent` = %d AND `item`.`visible`
|
||||
AND NOT `item`.`moderated` AND NOT `item`.`deleted`
|
||||
AND `item`.`uid` = %d AND `item`.`verb` = '%s'
|
||||
AND NOT `contact`.`blocked` AND NOT `contact`.`pending`
|
||||
AND `item`.`id`>%d $sql_extra
|
||||
ORDER BY `item`.`id` DESC LIMIT %d ,%d",
|
||||
intval($id), intval(api_user()),
|
||||
|
@ -1519,6 +1556,7 @@
|
|||
return api_apply_template("timeline", $type, $data);
|
||||
}
|
||||
api_register_func('api/conversation/show','api_conversation_show', true);
|
||||
api_register_func('api/statusnet/conversation','api_conversation_show', true);
|
||||
|
||||
|
||||
/**
|
||||
|
@ -1660,13 +1698,13 @@
|
|||
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
|
||||
`contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
|
||||
`contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
|
||||
FROM `item`, `contact`
|
||||
FROM `item` FORCE INDEX (`uid_id`), `contact`
|
||||
WHERE `item`.`uid` = %d AND `verb` = '%s'
|
||||
AND NOT (`item`.`author-link` IN ('https://%s', 'http://%s'))
|
||||
AND `item`.`visible` = 1 and `item`.`moderated` = 0 AND `item`.`deleted` = 0
|
||||
AND `item`.`visible` AND NOT `item`.`moderated` AND NOT `item`.`deleted`
|
||||
AND `contact`.`id` = `item`.`contact-id`
|
||||
AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
|
||||
AND `item`.`parent` IN (SELECT `iid` from thread where uid = %d AND `mention` AND !`ignored`)
|
||||
AND NOT `contact`.`blocked` AND NOT `contact`.`pending`
|
||||
AND `item`.`parent` IN (SELECT `iid` FROM `thread` WHERE `uid` = %d AND `mention` AND !`ignored`)
|
||||
$sql_extra
|
||||
AND `item`.`id`>%d
|
||||
ORDER BY `item`.`id` DESC LIMIT %d ,%d ",
|
||||
|
@ -1781,7 +1819,7 @@
|
|||
$action_argv_id=2;
|
||||
if ($a->argv[1]=="1.1") $action_argv_id=3;
|
||||
|
||||
if ($a->argc<=$action_argv_id) die(api_error($a, $type, t("Invalid request.")));
|
||||
if ($a->argc<=$action_argv_id) throw new BadRequestException("Invalid request.");
|
||||
$action = str_replace(".".$type,"",$a->argv[$action_argv_id]);
|
||||
if ($a->argc==$action_argv_id+2) {
|
||||
$itemid = intval($a->argv[$action_argv_id+1]);
|
||||
|
@ -2027,6 +2065,16 @@
|
|||
|
||||
$statushtml = trim(bbcode($body, false, false));
|
||||
|
||||
$search = array("<br>", "<blockquote>", "</blockquote>",
|
||||
"<h1>", "</h1>", "<h2>", "</h2>",
|
||||
"<h3>", "</h3>", "<h4>", "</h4>",
|
||||
"<h5>", "</h5>", "<h6>", "</h6>");
|
||||
$replace = array("<br>\n", "\n<blockquote>", "</blockquote>\n",
|
||||
"\n<h1>", "</h1>\n", "\n<h2>", "</h2>\n",
|
||||
"\n<h3>", "</h3>\n", "\n<h4>", "</h4>\n",
|
||||
"\n<h5>", "</h5>\n", "\n<h6>", "</h6>\n");
|
||||
$statushtml = str_replace($search, $replace, $statushtml);
|
||||
|
||||
if ($item['title'] != "")
|
||||
$statushtml = "<h4>".bbcode($item['title'])."</h4>\n".$statushtml;
|
||||
|
||||
|
@ -3386,6 +3434,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
|
||||
|
|
|
@ -5,35 +5,14 @@ require_once('include/security.php');
|
|||
require_once('include/datetime.php');
|
||||
|
||||
function nuke_session() {
|
||||
if (get_config('system', 'disable_database_session')) {
|
||||
session_unset();
|
||||
return;
|
||||
}
|
||||
|
||||
new_cookie(0); // make sure cookie is deleted on browser close, as a security measure
|
||||
|
||||
unset($_SESSION['authenticated']);
|
||||
unset($_SESSION['uid']);
|
||||
unset($_SESSION['visitor_id']);
|
||||
unset($_SESSION['administrator']);
|
||||
unset($_SESSION['cid']);
|
||||
unset($_SESSION['theme']);
|
||||
unset($_SESSION['mobile-theme']);
|
||||
unset($_SESSION['page_flags']);
|
||||
unset($_SESSION['submanage']);
|
||||
unset($_SESSION['my_url']);
|
||||
unset($_SESSION['my_address']);
|
||||
unset($_SESSION['addr']);
|
||||
unset($_SESSION['return_url']);
|
||||
|
||||
session_unset();
|
||||
}
|
||||
|
||||
|
||||
// login/logout
|
||||
|
||||
|
||||
|
||||
|
||||
if((isset($_SESSION)) && (x($_SESSION,'authenticated')) && ((! (x($_POST,'auth-params'))) || ($_POST['auth-params'] !== 'login'))) {
|
||||
|
||||
if(((x($_POST,'auth-params')) && ($_POST['auth-params'] === 'logout')) || ($a->module === 'logout')) {
|
||||
|
@ -41,6 +20,7 @@ if((isset($_SESSION)) && (x($_SESSION,'authenticated')) && ((! (x($_POST,'auth-p
|
|||
// process logout request
|
||||
call_hooks("logging_out");
|
||||
nuke_session();
|
||||
new_cookie(-1);
|
||||
info( t('Logged out.') . EOL);
|
||||
goaway(z_root());
|
||||
}
|
||||
|
@ -90,8 +70,7 @@ if((isset($_SESSION)) && (x($_SESSION,'authenticated')) && ((! (x($_POST,'auth-p
|
|||
}
|
||||
authenticate_success($r[0], false, false, $login_refresh);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
|
||||
if(isset($_SESSION)) {
|
||||
nuke_session();
|
||||
|
@ -209,13 +188,11 @@ else {
|
|||
}
|
||||
|
||||
function new_cookie($time) {
|
||||
if (!get_config('system', 'disable_database_session'))
|
||||
$old_sid = session_id();
|
||||
|
||||
session_set_cookie_params($time);
|
||||
if ($time != 0)
|
||||
$time = $time + time();
|
||||
|
||||
if (!get_config('system', 'disable_database_session')) {
|
||||
session_regenerate_id(false);
|
||||
q("UPDATE session SET sid = '%s' WHERE sid = '%s'", dbesc(session_id()), dbesc($old_sid));
|
||||
}
|
||||
$params = session_get_cookie_params();
|
||||
setcookie(session_name(), session_id(), $time, $params['path'], $params['domain'], $params['secure'], isset($params['httponly']));
|
||||
return;
|
||||
}
|
||||
|
|
69
include/autoloader.php
Normal file
69
include/autoloader.php
Normal 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();
|
413
include/autoloader/ClassLoader.php
Normal file
413
include/autoloader/ClassLoader.php
Normal 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;
|
||||
}
|
19
include/autoloader/LICENSE.composer
Normal file
19
include/autoloader/LICENSE.composer
Normal 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.
|
9
include/autoloader/autoload_classmap.php
Normal file
9
include/autoloader/autoload_classmap.php
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
// autoload_classmap.php @generated by Composer
|
||||
|
||||
$vendorDir = dirname(dirname(dirname(__FILE__)))."/library";
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
);
|
10
include/autoloader/autoload_files.php
Normal file
10
include/autoloader/autoload_files.php
Normal 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',
|
||||
);
|
10
include/autoloader/autoload_namespaces.php
Normal file
10
include/autoloader/autoload_namespaces.php
Normal 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'),
|
||||
);
|
9
include/autoloader/autoload_psr4.php
Normal file
9
include/autoloader/autoload_psr4.php
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
// autoload_psr4.php @generated by Composer
|
||||
|
||||
$vendorDir = dirname(dirname(dirname(__FILE__)))."/library";
|
||||
$baseDir = dirname($vendorDir);
|
||||
|
||||
return array(
|
||||
);
|
|
@ -311,6 +311,9 @@ function tryoembed($match){
|
|||
|
||||
$o = oembed_fetch_url($url);
|
||||
|
||||
if (!is_object($o))
|
||||
return $match[0];
|
||||
|
||||
if (isset($match[2]))
|
||||
$o->title = $match[2];
|
||||
|
||||
|
@ -858,6 +861,8 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
|
|||
$Text = preg_replace_callback("/\[nobb\](.*?)\[\/nobb\]/ism", 'bb_spacefy',$Text);
|
||||
$Text = preg_replace_callback("/\[pre\](.*?)\[\/pre\]/ism", 'bb_spacefy',$Text);
|
||||
|
||||
// Remove the abstract element. It is a non visible element.
|
||||
$Text = remove_abstract($Text);
|
||||
|
||||
// Move all spaces out of the tags
|
||||
$Text = preg_replace("/\[(\w*)\](\s*)/ism", '$2[$1]', $Text);
|
||||
|
@ -1300,4 +1305,43 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
|
|||
|
||||
return trim($Text);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Removes the "abstract" element from the text
|
||||
*
|
||||
* @param string $text The text with BBCode
|
||||
* @return string The same text - but without "abstract" element
|
||||
*/
|
||||
function remove_abstract($text) {
|
||||
$text = preg_replace("/[\s|\n]*\[abstract\].*?\[\/abstract\][\s|\n]*/ism", '', $text);
|
||||
$text = preg_replace("/[\s|\n]*\[abstract=.*?\].*?\[\/abstract][\s|\n]*/ism", '', $text);
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the value of the "abstract" element
|
||||
*
|
||||
* @param string $text The text that maybe contains the element
|
||||
* @param string $addon The addon for which the abstract is meant for
|
||||
* @return string The abstract
|
||||
*/
|
||||
function fetch_abstract($text, $addon = "") {
|
||||
$abstract = "";
|
||||
$abstracts = array();
|
||||
$addon = strtolower($addon);
|
||||
|
||||
if (preg_match_all("/\[abstract=(.*?)\](.*?)\[\/abstract\]/ism",$text, $results, PREG_SET_ORDER))
|
||||
foreach ($results AS $result)
|
||||
$abstracts[strtolower($result[1])] = $result[2];
|
||||
|
||||
if (isset($abstracts[$addon]))
|
||||
$abstract = $abstracts[$addon];
|
||||
|
||||
if ($abstract == "")
|
||||
if (preg_match("/\[abstract\](.*?)\[\/abstract\]/ism",$text, $result))
|
||||
$abstract = $result[1];
|
||||
|
||||
return $abstract;
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -99,8 +99,16 @@ function network_to_name($s, $profile = "") {
|
|||
|
||||
$networkname = str_replace($search,$replace,$s);
|
||||
|
||||
if (($s == NETWORK_DIASPORA) AND ($profile != "") AND diaspora_is_redmatrix($profile))
|
||||
$networkname = t("Redmatrix");
|
||||
if (($s == NETWORK_DIASPORA) AND ($profile != "") AND diaspora::is_redmatrix($profile)) {
|
||||
$networkname = t("Hubzilla/Redmatrix");
|
||||
|
||||
$r = q("SELECT `gserver`.`platform` FROM `gcontact`
|
||||
INNER JOIN `gserver` ON `gserver`.`nurl` = `gcontact`.`server_url`
|
||||
WHERE `gcontact`.`nurl` = '%s' AND `platform` != ''",
|
||||
dbesc(normalise_link($profile)));
|
||||
if ($r)
|
||||
$networkname = $r[0]["platform"];
|
||||
}
|
||||
|
||||
return $networkname;
|
||||
}
|
||||
|
|
|
@ -614,7 +614,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
|
|||
if(($normalised != 'mailbox') && (x($a->contacts[$normalised])))
|
||||
$profile_avatar = $a->contacts[$normalised]['thumb'];
|
||||
else
|
||||
$profile_avatar = ((strlen($item['author-avatar'])) ? $a->get_cached_avatar_image($item['author-avatar']) : $item['thumb']);
|
||||
$profile_avatar = $a->remove_baseurl(((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']));
|
||||
|
||||
$locate = array('location' => $item['location'], 'coord' => $item['coord'], 'html' => '');
|
||||
call_hooks('render_location',$locate);
|
||||
|
@ -707,8 +707,8 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
|
|||
'like' => '',
|
||||
'dislike' => '',
|
||||
'comment' => '',
|
||||
//'conv' => (($preview) ? '' : array('href'=> $a->get_baseurl($ssl_state) . '/display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))),
|
||||
'conv' => (($preview) ? '' : array('href'=> $a->get_baseurl($ssl_state) . '/display/'.$item['guid'], 'title'=> t('View in context'))),
|
||||
//'conv' => (($preview) ? '' : array('href'=> 'display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))),
|
||||
'conv' => (($preview) ? '' : array('href'=> 'display/'.$item['guid'], 'title'=> t('View in context'))),
|
||||
'previewing' => $previewing,
|
||||
'wait' => t('Please wait'),
|
||||
'thread_level' => 1,
|
||||
|
@ -868,7 +868,7 @@ function item_photo_menu($item){
|
|||
$status_link = $profile_link . "?url=status";
|
||||
$photos_link = $profile_link . "?url=photos";
|
||||
$profile_link = $profile_link . "?url=profile";
|
||||
$pm_url = $a->get_baseurl($ssl_state) . '/message/new/' . $cid;
|
||||
$pm_url = 'message/new/' . $cid;
|
||||
$zurl = '';
|
||||
}
|
||||
else {
|
||||
|
@ -882,23 +882,23 @@ function item_photo_menu($item){
|
|||
$cid = $r[0]["id"];
|
||||
|
||||
if ($r[0]["network"] == NETWORK_DIASPORA)
|
||||
$pm_url = $a->get_baseurl($ssl_state) . '/message/new/' . $cid;
|
||||
$pm_url = 'message/new/' . $cid;
|
||||
|
||||
} else
|
||||
$cid = 0;
|
||||
}
|
||||
}
|
||||
if(($cid) && (! $item['self'])) {
|
||||
$poke_link = $a->get_baseurl($ssl_state) . '/poke/?f=&c=' . $cid;
|
||||
$contact_url = $a->get_baseurl($ssl_state) . '/contacts/' . $cid;
|
||||
$posts_link = $a->get_baseurl($ssl_state) . '/contacts/' . $cid . '/posts';
|
||||
$poke_link = 'poke/?f=&c=' . $cid;
|
||||
$contact_url = 'contacts/' . $cid;
|
||||
$posts_link = 'contacts/' . $cid . '/posts';
|
||||
|
||||
$clean_url = normalise_link($item['author-link']);
|
||||
|
||||
if((local_user()) && (local_user() == $item['uid'])) {
|
||||
if(isset($a->contacts) && x($a->contacts,$clean_url)) {
|
||||
if($a->contacts[$clean_url]['network'] === NETWORK_DIASPORA) {
|
||||
$pm_url = $a->get_baseurl($ssl_state) . '/message/new/' . $cid;
|
||||
$pm_url = 'message/new/' . $cid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -921,7 +921,7 @@ function item_photo_menu($item){
|
|||
|
||||
if ((($cid == 0) OR ($a->contacts[$clean_url]['rel'] == CONTACT_IS_FOLLOWER)) AND
|
||||
in_array($item['network'], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA)))
|
||||
$menu[t("Connect/Follow")] = $a->get_baseurl($ssl_state)."/follow?url=".urlencode($item['author-link']);
|
||||
$menu[t("Connect/Follow")] = "follow?url=".urlencode($item['author-link']);
|
||||
} else
|
||||
$menu = array(t("View Profile") => $item['author-link']);
|
||||
|
||||
|
@ -980,7 +980,7 @@ function builtin_activity_puller($item, &$conv_responses) {
|
|||
if((activity_match($item['verb'], $verb)) && ($item['id'] != $item['parent'])) {
|
||||
$url = $item['author-link'];
|
||||
if((local_user()) && (local_user() == $item['uid']) && ($item['network'] === NETWORK_DFRN) && (! $item['self']) && (link_compare($item['author-link'],$item['url']))) {
|
||||
$url = z_root(true) . '/redir/' . $item['contact-id'];
|
||||
$url = 'redir/' . $item['contact-id'];
|
||||
$sparkle = ' class="sparkle" ';
|
||||
}
|
||||
else
|
||||
|
@ -1178,7 +1178,7 @@ function status_editor($a,$x, $notes_cid = 0, $popup=false) {
|
|||
|
||||
$o .= replace_macros($tpl,array(
|
||||
'$return_path' => $query_str,
|
||||
'$action' => $a->get_baseurl(true) . '/item',
|
||||
'$action' => 'item',
|
||||
'$share' => (x($x,'button') ? $x['button'] : t('Share')),
|
||||
'$upload' => t('Upload photo'),
|
||||
'$shortupload' => t('upload photo'),
|
||||
|
|
|
@ -34,22 +34,18 @@ function cron_run(&$argv, &$argc){
|
|||
require_once('include/Contact.php');
|
||||
require_once('include/email.php');
|
||||
require_once('include/socgraph.php');
|
||||
require_once('include/pidfile.php');
|
||||
require_once('mod/nodeinfo.php');
|
||||
require_once('include/post_update.php');
|
||||
|
||||
load_config('config');
|
||||
load_config('system');
|
||||
|
||||
$maxsysload = intval(get_config('system','maxloadavg'));
|
||||
if($maxsysload < 1)
|
||||
$maxsysload = 50;
|
||||
|
||||
$load = current_load();
|
||||
if($load) {
|
||||
if(intval($load) > $maxsysload) {
|
||||
logger('system: load ' . $load . ' too high. cron deferred to next scheduled run.');
|
||||
// Don't check this stuff if the function is called by the poller
|
||||
if (App::callstack() != "poller_run") {
|
||||
if (App::maxload_reached())
|
||||
return;
|
||||
if (App::is_already_running('cron', 'include/cron.php', 540))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$last = get_config('system','last_cron');
|
||||
|
@ -66,23 +62,6 @@ function cron_run(&$argv, &$argc){
|
|||
}
|
||||
}
|
||||
|
||||
$lockpath = get_lockpath();
|
||||
if ($lockpath != '') {
|
||||
$pidfile = new pidfile($lockpath, 'cron');
|
||||
if($pidfile->is_already_running()) {
|
||||
logger("cron: Already running");
|
||||
if ($pidfile->running_time() > 9*60) {
|
||||
$pidfile->kill();
|
||||
logger("cron: killed stale process");
|
||||
// Calling a new instance
|
||||
proc_run('php','include/cron.php');
|
||||
}
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
$a->set_baseurl(get_config('system','url'));
|
||||
|
||||
load_hooks();
|
||||
|
@ -93,10 +72,6 @@ function cron_run(&$argv, &$argc){
|
|||
|
||||
proc_run('php',"include/queue.php");
|
||||
|
||||
// run diaspora photo queue process in the background
|
||||
|
||||
proc_run('php',"include/dsprphotoq.php");
|
||||
|
||||
// run the process to discover global contacts in the background
|
||||
|
||||
proc_run('php',"include/discover_poco.php");
|
||||
|
@ -127,13 +102,14 @@ function cron_run(&$argv, &$argc){
|
|||
|
||||
// Check OStatus conversations
|
||||
// Check only conversations with mentions (for a longer time)
|
||||
check_conversations(true);
|
||||
ostatus::check_conversations(true);
|
||||
|
||||
// Check every conversation
|
||||
check_conversations(false);
|
||||
ostatus::check_conversations(false);
|
||||
|
||||
// Set the gcontact-id in the item table if missing
|
||||
item_set_gcontact();
|
||||
// Call possible post update functions
|
||||
// see include/post_update.php for more details
|
||||
post_update();
|
||||
|
||||
// update nodeinfo data
|
||||
nodeinfo_cron();
|
||||
|
@ -361,35 +337,37 @@ function cron_clear_cache(&$a) {
|
|||
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%
|
||||
if ($max_tablesize > 0) {
|
||||
// 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) {
|
||||
// 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 tables that are too large
|
||||
if ($table["Data_length"] > $max_tablesize)
|
||||
continue;
|
||||
|
||||
// Don't optimize empty tables
|
||||
if ($table["Data_length"] == 0)
|
||||
continue;
|
||||
// Don't optimize empty tables
|
||||
if ($table["Data_length"] == 0)
|
||||
continue;
|
||||
|
||||
// Calculate fragmentation
|
||||
$fragmentation = $table["Data_free"] / $table["Data_length"];
|
||||
// Calculate fragmentation
|
||||
$fragmentation = $table["Data_free"] / ($table["Data_length"] + $table["Index_length"]);
|
||||
|
||||
logger("Table ".$table["Name"]." - Fragmentation level: ".round($fragmentation * 100, 2), LOGGER_DEBUG);
|
||||
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;
|
||||
// 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"]));
|
||||
// So optimize it
|
||||
logger("Optimize Table ".$table["Name"], LOGGER_DEBUG);
|
||||
q("OPTIMIZE TABLE `%s`", dbesc($table["Name"]));
|
||||
}
|
||||
}
|
||||
|
||||
set_config('system','cache_last_cleared', time());
|
||||
|
@ -429,6 +407,9 @@ function cron_repair_database() {
|
|||
// 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");
|
||||
|
||||
// There was an issue where the nick vanishes from the contact table
|
||||
q("UPDATE `contact` INNER JOIN `user` ON `contact`.`uid` = `user`.`uid` SET `nick` = `nickname` WHERE `self` AND `nick`=''");
|
||||
|
||||
/// @todo
|
||||
/// - remove thread entries without item
|
||||
/// - remove sign entries without item
|
||||
|
|
|
@ -19,21 +19,16 @@ function cronhooks_run(&$argv, &$argc){
|
|||
|
||||
require_once('include/session.php');
|
||||
require_once('include/datetime.php');
|
||||
require_once('include/pidfile.php');
|
||||
|
||||
load_config('config');
|
||||
load_config('system');
|
||||
|
||||
$maxsysload = intval(get_config('system','maxloadavg'));
|
||||
if($maxsysload < 1)
|
||||
$maxsysload = 50;
|
||||
|
||||
$load = current_load();
|
||||
if($load) {
|
||||
if(intval($load) > $maxsysload) {
|
||||
logger('system: load ' . $load . ' too high. Cronhooks deferred to next scheduled run.');
|
||||
// Don't check this stuff if the function is called by the poller
|
||||
if (App::callstack() != "poller_run") {
|
||||
if (App::maxload_reached())
|
||||
return;
|
||||
if (App::is_already_running('cronhooks', 'include/cronhooks.php', 1140))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$last = get_config('system','last_cronhook');
|
||||
|
@ -50,21 +45,6 @@ function cronhooks_run(&$argv, &$argc){
|
|||
}
|
||||
}
|
||||
|
||||
$lockpath = get_lockpath();
|
||||
if ($lockpath != '') {
|
||||
$pidfile = new pidfile($lockpath, 'cronhooks');
|
||||
if($pidfile->is_already_running()) {
|
||||
logger("cronhooks: Already running");
|
||||
if ($pidfile->running_time() > 19*60) {
|
||||
$pidfile->kill();
|
||||
logger("cronhooks: killed stale process");
|
||||
// Calling a new instance
|
||||
proc_run('php','include/cronhooks.php');
|
||||
}
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$a->set_baseurl(get_config('system','url'));
|
||||
|
||||
load_hooks();
|
||||
|
|
|
@ -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(' ',' ',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 .= ' ';
|
||||
$o .= '</td>';
|
||||
$dow ++;
|
||||
if(($dow == 7) && ($d <= $l)) {
|
||||
$dow = 0;
|
||||
$o .= '</tr><tr>';
|
||||
}
|
||||
}
|
||||
if($dow)
|
||||
for($a = $dow; $a < 7; $a ++)
|
||||
$o .= '<td> </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(' ',' ',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 .= ' ';
|
||||
}
|
||||
|
||||
$o .= '</td>';
|
||||
$dow ++;
|
||||
if(($dow == 7) && ($d <= $l)) {
|
||||
$dow = 0;
|
||||
$o .= '</tr><tr>';
|
||||
}
|
||||
}
|
||||
if($dow)
|
||||
for($a = $dow; $a < 7; $a ++)
|
||||
$o .= '<td> </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']),
|
||||
|
|
|
@ -537,17 +537,6 @@ function db_definition() {
|
|||
"PRIMARY" => array("id"),
|
||||
)
|
||||
);
|
||||
$database["dsprphotoq"] = array(
|
||||
"fields" => array(
|
||||
"id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
|
||||
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
|
||||
"msg" => array("type" => "mediumtext", "not null" => "1"),
|
||||
"attempt" => array("type" => "tinyint(4)", "not null" => "1", "default" => "0"),
|
||||
),
|
||||
"indexes" => array(
|
||||
"PRIMARY" => array("id"),
|
||||
)
|
||||
);
|
||||
$database["event"] = array(
|
||||
"fields" => array(
|
||||
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
|
||||
|
@ -748,21 +737,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"),
|
||||
|
@ -1261,7 +1235,6 @@ function db_definition() {
|
|||
"fields" => array(
|
||||
"id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
|
||||
"iid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
|
||||
"retract_iid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
|
||||
"signed_text" => array("type" => "mediumtext", "not null" => "1"),
|
||||
"signature" => array("type" => "text", "not null" => "1"),
|
||||
"signer" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
|
||||
|
@ -1269,7 +1242,6 @@ function db_definition() {
|
|||
"indexes" => array(
|
||||
"PRIMARY" => array("id"),
|
||||
"iid" => array("iid"),
|
||||
"retract_iid" => array("retract_iid"),
|
||||
)
|
||||
);
|
||||
$database["spam"] = array(
|
||||
|
|
|
@ -10,11 +10,11 @@ require_once("include/dfrn.php");
|
|||
function delivery_run(&$argv, &$argc){
|
||||
global $a, $db;
|
||||
|
||||
if(is_null($a)){
|
||||
if (is_null($a)){
|
||||
$a = new App;
|
||||
}
|
||||
|
||||
if(is_null($db)) {
|
||||
if (is_null($db)) {
|
||||
@include(".htconfig.php");
|
||||
require_once("include/dba.php");
|
||||
$db = new dba($db_host, $db_user, $db_pass, $db_data);
|
||||
|
@ -32,12 +32,12 @@ function delivery_run(&$argv, &$argc){
|
|||
|
||||
load_hooks();
|
||||
|
||||
if($argc < 3)
|
||||
if ($argc < 3)
|
||||
return;
|
||||
|
||||
$a->set_baseurl(get_config('system','url'));
|
||||
|
||||
logger('delivery: invoked: ' . print_r($argv,true), LOGGER_DEBUG);
|
||||
logger('delivery: invoked: '. print_r($argv,true), LOGGER_DEBUG);
|
||||
|
||||
$cmd = $argv[1];
|
||||
$item_id = intval($argv[2]);
|
||||
|
@ -53,21 +53,12 @@ function delivery_run(&$argv, &$argc){
|
|||
dbesc($item_id),
|
||||
dbesc($contact_id)
|
||||
);
|
||||
if(! count($r)) {
|
||||
if (!count($r)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$maxsysload = intval(get_config('system','maxloadavg'));
|
||||
if($maxsysload < 1)
|
||||
$maxsysload = 50;
|
||||
|
||||
$load = current_load();
|
||||
if($load) {
|
||||
if(intval($load) > $maxsysload) {
|
||||
logger('system: load ' . $load . ' too high. Delivery deferred to next queue run.');
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (App::maxload_reached())
|
||||
return;
|
||||
|
||||
// It's ours to deliver. Remove it from the queue.
|
||||
|
||||
|
@ -77,7 +68,7 @@ function delivery_run(&$argv, &$argc){
|
|||
dbesc($contact_id)
|
||||
);
|
||||
|
||||
if((! $item_id) || (! $contact_id))
|
||||
if (!$item_id || !$contact_id)
|
||||
continue;
|
||||
|
||||
$expire = false;
|
||||
|
@ -93,20 +84,20 @@ function delivery_run(&$argv, &$argc){
|
|||
|
||||
$recipients[] = $contact_id;
|
||||
|
||||
if($cmd === 'mail') {
|
||||
if ($cmd === 'mail') {
|
||||
$normal_mode = false;
|
||||
$mail = true;
|
||||
$message = q("SELECT * FROM `mail` WHERE `id` = %d LIMIT 1",
|
||||
intval($item_id)
|
||||
);
|
||||
if(! count($message)){
|
||||
if (!count($message)){
|
||||
return;
|
||||
}
|
||||
$uid = $message[0]['uid'];
|
||||
$recipients[] = $message[0]['contact-id'];
|
||||
$item = $message[0];
|
||||
}
|
||||
elseif($cmd === 'expire') {
|
||||
elseif ($cmd === 'expire') {
|
||||
$normal_mode = false;
|
||||
$expire = true;
|
||||
$items = q("SELECT * FROM `item` WHERE `uid` = %d AND `wall` = 1
|
||||
|
@ -115,22 +106,22 @@ function delivery_run(&$argv, &$argc){
|
|||
);
|
||||
$uid = $item_id;
|
||||
$item_id = 0;
|
||||
if(! count($items))
|
||||
if (!count($items))
|
||||
continue;
|
||||
}
|
||||
elseif($cmd === 'suggest') {
|
||||
elseif ($cmd === 'suggest') {
|
||||
$normal_mode = false;
|
||||
$fsuggest = true;
|
||||
|
||||
$suggest = q("SELECT * FROM `fsuggest` WHERE `id` = %d LIMIT 1",
|
||||
intval($item_id)
|
||||
);
|
||||
if(! count($suggest))
|
||||
if (!count($suggest))
|
||||
return;
|
||||
$uid = $suggest[0]['uid'];
|
||||
$recipients[] = $suggest[0]['cid'];
|
||||
$item = $suggest[0];
|
||||
} elseif($cmd === 'relocate') {
|
||||
} elseif ($cmd === 'relocate') {
|
||||
$normal_mode = false;
|
||||
$relocate = true;
|
||||
$uid = $item_id;
|
||||
|
@ -140,7 +131,7 @@ function delivery_run(&$argv, &$argc){
|
|||
intval($item_id)
|
||||
);
|
||||
|
||||
if((! count($r)) || (! intval($r[0]['parent']))) {
|
||||
if ((!count($r)) || (!intval($r[0]['parent']))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -154,32 +145,32 @@ function delivery_run(&$argv, &$argc){
|
|||
intval($parent_id)
|
||||
);
|
||||
|
||||
if(! count($items)) {
|
||||
if (!count($items)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$icontacts = null;
|
||||
$contacts_arr = array();
|
||||
foreach($items as $item)
|
||||
if(! in_array($item['contact-id'],$contacts_arr))
|
||||
if (!in_array($item['contact-id'],$contacts_arr))
|
||||
$contacts_arr[] = intval($item['contact-id']);
|
||||
if(count($contacts_arr)) {
|
||||
if (count($contacts_arr)) {
|
||||
$str_contacts = implode(',',$contacts_arr);
|
||||
$icontacts = q("SELECT * FROM `contact`
|
||||
WHERE `id` IN ( $str_contacts ) "
|
||||
);
|
||||
}
|
||||
if( ! ($icontacts && count($icontacts)))
|
||||
if ( !($icontacts && count($icontacts)))
|
||||
continue;
|
||||
|
||||
// avoid race condition with deleting entries
|
||||
|
||||
if($items[0]['deleted']) {
|
||||
if ($items[0]['deleted']) {
|
||||
foreach($items as $item)
|
||||
$item['deleted'] = 1;
|
||||
}
|
||||
|
||||
if((count($items) == 1) && ($items[0]['uri'] === $items[0]['parent-uri'])) {
|
||||
if ((count($items) == 1) && ($items[0]['uri'] === $items[0]['parent-uri'])) {
|
||||
logger('delivery: top level post');
|
||||
$top_level = true;
|
||||
}
|
||||
|
@ -193,7 +184,7 @@ function delivery_run(&$argv, &$argc){
|
|||
intval($uid)
|
||||
);
|
||||
|
||||
if(! count($r))
|
||||
if (!count($r))
|
||||
continue;
|
||||
|
||||
$owner = $r[0];
|
||||
|
@ -202,7 +193,7 @@ function delivery_run(&$argv, &$argc){
|
|||
|
||||
$public_message = true;
|
||||
|
||||
if(! ($mail || $fsuggest || $relocate)) {
|
||||
if (!($mail || $fsuggest || $relocate)) {
|
||||
require_once('include/group.php');
|
||||
|
||||
$parent = $items[0];
|
||||
|
@ -226,7 +217,7 @@ function delivery_run(&$argv, &$argc){
|
|||
|
||||
|
||||
$localhost = $a->get_hostname();
|
||||
if(strpos($localhost,':'))
|
||||
if (strpos($localhost,':'))
|
||||
$localhost = substr($localhost,0,strpos($localhost,':'));
|
||||
|
||||
/**
|
||||
|
@ -239,20 +230,21 @@ function delivery_run(&$argv, &$argc){
|
|||
|
||||
$relay_to_owner = false;
|
||||
|
||||
if((! $top_level) && ($parent['wall'] == 0) && (! $expire) && (stristr($target_item['uri'],$localhost))) {
|
||||
if (!$top_level && ($parent['wall'] == 0) && !$expire && stristr($target_item['uri'],$localhost)) {
|
||||
$relay_to_owner = true;
|
||||
}
|
||||
|
||||
if($relay_to_owner) {
|
||||
if ($relay_to_owner) {
|
||||
logger('followup '.$target_item["guid"], LOGGER_DEBUG);
|
||||
// local followup to remote post
|
||||
$followup = true;
|
||||
}
|
||||
|
||||
if((strlen($parent['allow_cid']))
|
||||
if ((strlen($parent['allow_cid']))
|
||||
|| (strlen($parent['allow_gid']))
|
||||
|| (strlen($parent['deny_cid']))
|
||||
|| (strlen($parent['deny_gid']))) {
|
||||
|| (strlen($parent['deny_gid']))
|
||||
|| $parent["private"]) {
|
||||
$public_message = false; // private recipients, not public
|
||||
}
|
||||
|
||||
|
@ -262,10 +254,10 @@ function delivery_run(&$argv, &$argc){
|
|||
intval($contact_id)
|
||||
);
|
||||
|
||||
if(count($r))
|
||||
if (count($r))
|
||||
$contact = $r[0];
|
||||
|
||||
if($contact['self'])
|
||||
if ($contact['self'])
|
||||
continue;
|
||||
|
||||
$deliver_status = 0;
|
||||
|
@ -275,7 +267,7 @@ function delivery_run(&$argv, &$argc){
|
|||
switch($contact['network']) {
|
||||
|
||||
case NETWORK_DFRN:
|
||||
logger('notifier: '.$target_item["guid"].' dfrndelivery: ' . $contact['name']);
|
||||
logger('notifier: '.$target_item["guid"].' dfrndelivery: '.$contact['name']);
|
||||
|
||||
if ($mail) {
|
||||
$item['body'] = fix_private_photos($item['body'],$owner['uid'],null,$message[0]['contact-id']);
|
||||
|
@ -285,13 +277,13 @@ function delivery_run(&$argv, &$argc){
|
|||
q("DELETE FROM `fsuggest` WHERE `id` = %d LIMIT 1", intval($item['id']));
|
||||
} elseif ($relocate)
|
||||
$atom = dfrn::relocate($owner, $uid);
|
||||
elseif($followup) {
|
||||
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);
|
||||
if ($item['id'] == $item_id) {
|
||||
logger('followup: item: '. print_r($item,true), LOGGER_DATA);
|
||||
$msgitems[] = $item;
|
||||
}
|
||||
}
|
||||
|
@ -299,19 +291,19 @@ function delivery_run(&$argv, &$argc){
|
|||
} 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'])
|
||||
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']) {
|
||||
if ($normal_mode) {
|
||||
if ($item_id == $item['id'] || $item['id'] == $item['parent']) {
|
||||
$item["entry:comment-allow"] = true;
|
||||
$item["entry:cid"] = (($top_level) ? $contact['id'] : 0);
|
||||
$msgitems[] = $item;
|
||||
|
@ -326,15 +318,15 @@ function delivery_run(&$argv, &$argc){
|
|||
|
||||
logger('notifier entry: '.$contact["url"].' '.$target_item["guid"].' entry: '.$atom, LOGGER_DEBUG);
|
||||
|
||||
logger('notifier: ' . $atom, LOGGER_DATA);
|
||||
logger('notifier: '.$atom, LOGGER_DATA);
|
||||
$basepath = implode('/', array_slice(explode('/',$contact['url']),0,3));
|
||||
|
||||
// perform local delivery if we are on the same site
|
||||
|
||||
if(link_compare($basepath,$a->get_baseurl())) {
|
||||
if (link_compare($basepath,$a->get_baseurl())) {
|
||||
|
||||
$nickname = basename($contact['url']);
|
||||
if($contact['issued-id'])
|
||||
if ($contact['issued-id'])
|
||||
$sql_extra = sprintf(" AND `dfrn-id` = '%s' ", dbesc($contact['issued-id']));
|
||||
else
|
||||
$sql_extra = sprintf(" AND `issued-id` = '%s' ", dbesc($contact['dfrn-id']));
|
||||
|
@ -356,10 +348,10 @@ function delivery_run(&$argv, &$argc){
|
|||
dbesc($nickname)
|
||||
);
|
||||
|
||||
if($x && count($x)) {
|
||||
if ($x && count($x)) {
|
||||
$write_flag = ((($x[0]['rel']) && ($x[0]['rel'] != CONTACT_IS_SHARING)) ? true : false);
|
||||
if((($owner['page-flags'] == PAGE_COMMUNITY) || ($write_flag)) && (! $x[0]['writable'])) {
|
||||
q("update contact set writable = 1 where id = %d",
|
||||
if ((($owner['page-flags'] == PAGE_COMMUNITY) || $write_flag) && !$x[0]['writable']) {
|
||||
q("UPDATE `contact` SET `writable` = 1 WHERE `id` = %d",
|
||||
intval($x[0]['id'])
|
||||
);
|
||||
$x[0]['writable'] = 1;
|
||||
|
@ -374,19 +366,19 @@ function delivery_run(&$argv, &$argc){
|
|||
break;
|
||||
|
||||
logger('mod-delivery: local delivery');
|
||||
local_delivery($x[0],$atom);
|
||||
dfrn::import($atom, $x[0]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(! was_recently_delayed($contact['id']))
|
||||
if (!was_recently_delayed($contact['id']))
|
||||
$deliver_status = dfrn::deliver($owner,$contact,$atom);
|
||||
else
|
||||
$deliver_status = (-1);
|
||||
|
||||
logger('notifier: dfrn_delivery to '.$contact["url"].' with guid '.$target_item["guid"].' returns '.$deliver_status);
|
||||
|
||||
if($deliver_status == (-1)) {
|
||||
if ($deliver_status == (-1)) {
|
||||
logger('notifier: delivery failed: queuing message');
|
||||
add_to_queue($contact['id'],NETWORK_DFRN,$atom);
|
||||
}
|
||||
|
@ -394,9 +386,9 @@ function delivery_run(&$argv, &$argc){
|
|||
|
||||
case NETWORK_OSTATUS:
|
||||
// Do not send to otatus if we are not configured to send to public networks
|
||||
if($owner['prvnets'])
|
||||
if ($owner['prvnets'])
|
||||
break;
|
||||
if(get_config('system','ostatus_disabled') || get_config('system','dfrn_only'))
|
||||
if (get_config('system','ostatus_disabled') || get_config('system','dfrn_only'))
|
||||
break;
|
||||
|
||||
// There is currently no code here to distribute anything to OStatus.
|
||||
|
@ -406,67 +398,67 @@ function delivery_run(&$argv, &$argc){
|
|||
case NETWORK_MAIL:
|
||||
case NETWORK_MAIL2:
|
||||
|
||||
if(get_config('system','dfrn_only'))
|
||||
if (get_config('system','dfrn_only'))
|
||||
break;
|
||||
// WARNING: does not currently convert to RFC2047 header encodings, etc.
|
||||
|
||||
$addr = $contact['addr'];
|
||||
if(! strlen($addr))
|
||||
if (!strlen($addr))
|
||||
break;
|
||||
|
||||
if($cmd === 'wall-new' || $cmd === 'comment-new') {
|
||||
if ($cmd === 'wall-new' || $cmd === 'comment-new') {
|
||||
|
||||
$it = null;
|
||||
if($cmd === 'wall-new')
|
||||
if ($cmd === 'wall-new')
|
||||
$it = $items[0];
|
||||
else {
|
||||
$r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
|
||||
intval($argv[2]),
|
||||
intval($uid)
|
||||
);
|
||||
if(count($r))
|
||||
if (count($r))
|
||||
$it = $r[0];
|
||||
}
|
||||
if(! $it)
|
||||
if (!$it)
|
||||
break;
|
||||
|
||||
|
||||
$local_user = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
|
||||
intval($uid)
|
||||
);
|
||||
if(! count($local_user))
|
||||
if (!count($local_user))
|
||||
break;
|
||||
|
||||
$reply_to = '';
|
||||
$r1 = q("SELECT * FROM `mailacct` WHERE `uid` = %d LIMIT 1",
|
||||
intval($uid)
|
||||
);
|
||||
if($r1 && $r1[0]['reply_to'])
|
||||
if ($r1 && $r1[0]['reply_to'])
|
||||
$reply_to = $r1[0]['reply_to'];
|
||||
|
||||
$subject = (($it['title']) ? email_header_encode($it['title'],'UTF-8') : t("\x28no subject\x29")) ;
|
||||
|
||||
// only expose our real email address to true friends
|
||||
|
||||
if(($contact['rel'] == CONTACT_IS_FRIEND) && (! $contact['blocked'])) {
|
||||
if($reply_to) {
|
||||
if (($contact['rel'] == CONTACT_IS_FRIEND) && !$contact['blocked']) {
|
||||
if ($reply_to) {
|
||||
$headers = 'From: '.email_header_encode($local_user[0]['username'],'UTF-8').' <'.$reply_to.'>'."\n";
|
||||
$headers .= 'Sender: '.$local_user[0]['email']."\n";
|
||||
} else
|
||||
$headers = 'From: '.email_header_encode($local_user[0]['username'],'UTF-8').' <'.$local_user[0]['email'].'>'."\n";
|
||||
} else
|
||||
$headers = 'From: ' . email_header_encode($local_user[0]['username'],'UTF-8') . ' <' . t('noreply') . '@' . $a->get_hostname() . '>' . "\n";
|
||||
$headers = 'From: '. email_header_encode($local_user[0]['username'],'UTF-8') .' <'. t('noreply') .'@'.$a->get_hostname() .'>'. "\n";
|
||||
|
||||
//if($reply_to)
|
||||
// $headers .= 'Reply-to: ' . $reply_to . "\n";
|
||||
//if ($reply_to)
|
||||
// $headers .= 'Reply-to: '.$reply_to . "\n";
|
||||
|
||||
$headers .= 'Message-Id: <' . iri2msgid($it['uri']). '>' . "\n";
|
||||
$headers .= 'Message-Id: <'. iri2msgid($it['uri']).'>'. "\n";
|
||||
|
||||
//logger("Mail: uri: ".$it['uri']." parent-uri ".$it['parent-uri'], LOGGER_DEBUG);
|
||||
//logger("Mail: Data: ".print_r($it, true), LOGGER_DEBUG);
|
||||
//logger("Mail: Data: ".print_r($it, true), LOGGER_DATA);
|
||||
|
||||
if($it['uri'] !== $it['parent-uri']) {
|
||||
if ($it['uri'] !== $it['parent-uri']) {
|
||||
$headers .= "References: <".iri2msgid($it["parent-uri"]).">";
|
||||
|
||||
// If Threading is enabled, write down the correct parent
|
||||
|
@ -474,23 +466,23 @@ function delivery_run(&$argv, &$argc){
|
|||
$headers .= " <".iri2msgid($it["thr-parent"]).">";
|
||||
$headers .= "\n";
|
||||
|
||||
if(!$it['title']) {
|
||||
if (!$it['title']) {
|
||||
$r = q("SELECT `title` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
|
||||
dbesc($it['parent-uri']),
|
||||
intval($uid));
|
||||
|
||||
if(count($r) AND ($r[0]['title'] != ''))
|
||||
if (count($r) AND ($r[0]['title'] != ''))
|
||||
$subject = $r[0]['title'];
|
||||
else {
|
||||
$r = q("SELECT `title` FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d LIMIT 1",
|
||||
dbesc($it['parent-uri']),
|
||||
intval($uid));
|
||||
|
||||
if(count($r) AND ($r[0]['title'] != ''))
|
||||
if (count($r) AND ($r[0]['title'] != ''))
|
||||
$subject = $r[0]['title'];
|
||||
}
|
||||
}
|
||||
if(strncasecmp($subject,'RE:',3))
|
||||
if (strncasecmp($subject,'RE:',3))
|
||||
$subject = 'Re: '.$subject;
|
||||
}
|
||||
email_send($addr, $subject, $headers, $it);
|
||||
|
@ -498,60 +490,59 @@ function delivery_run(&$argv, &$argc){
|
|||
break;
|
||||
|
||||
case NETWORK_DIASPORA:
|
||||
if($public_message)
|
||||
$loc = 'public batch ' . $contact['batch'];
|
||||
if ($public_message)
|
||||
$loc = 'public batch '.$contact['batch'];
|
||||
else
|
||||
$loc = $contact['name'];
|
||||
|
||||
logger('delivery: diaspora batch deliver: ' . $loc);
|
||||
logger('delivery: diaspora batch deliver: '.$loc);
|
||||
|
||||
if(get_config('system','dfrn_only') || (!get_config('system','diaspora_enabled')))
|
||||
if (get_config('system','dfrn_only') || (!get_config('system','diaspora_enabled')))
|
||||
break;
|
||||
|
||||
if($mail) {
|
||||
diaspora_send_mail($item,$owner,$contact);
|
||||
if ($mail) {
|
||||
diaspora::send_mail($item,$owner,$contact);
|
||||
break;
|
||||
}
|
||||
|
||||
if(!$normal_mode)
|
||||
if (!$normal_mode)
|
||||
break;
|
||||
|
||||
if((! $contact['pubkey']) && (! $public_message))
|
||||
if (!$contact['pubkey'] && !$public_message)
|
||||
break;
|
||||
|
||||
$unsupported_activities = array(ACTIVITY_DISLIKE, ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE);
|
||||
|
||||
//don't transmit activities which are not supported by diaspora
|
||||
foreach($unsupported_activities as $act) {
|
||||
if(activity_match($target_item['verb'],$act)) {
|
||||
if (activity_match($target_item['verb'],$act)) {
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
|
||||
if(($target_item['deleted']) && (($target_item['uri'] === $target_item['parent-uri']) || $followup)) {
|
||||
if (($target_item['deleted']) && (($target_item['uri'] === $target_item['parent-uri']) || $followup)) {
|
||||
// top-level retraction
|
||||
logger('delivery: diaspora retract: ' . $loc);
|
||||
|
||||
diaspora_send_retraction($target_item,$owner,$contact,$public_message);
|
||||
logger('diaspora retract: '.$loc);
|
||||
diaspora::send_retraction($target_item,$owner,$contact,$public_message);
|
||||
break;
|
||||
} elseif($followup) {
|
||||
} elseif ($followup) {
|
||||
// send comments and likes to owner to relay
|
||||
diaspora_send_followup($target_item,$owner,$contact,$public_message);
|
||||
logger('diaspora followup: '.$loc);
|
||||
diaspora::send_followup($target_item,$owner,$contact,$public_message);
|
||||
break;
|
||||
} elseif($target_item['uri'] !== $target_item['parent-uri']) {
|
||||
} elseif ($target_item['uri'] !== $target_item['parent-uri']) {
|
||||
// we are the relay - send comments, likes and relayable_retractions to our conversants
|
||||
logger('delivery: diaspora relay: ' . $loc);
|
||||
|
||||
diaspora_send_relay($target_item,$owner,$contact,$public_message);
|
||||
logger('diaspora relay: '.$loc);
|
||||
diaspora::send_relay($target_item,$owner,$contact,$public_message);
|
||||
break;
|
||||
} elseif(($top_level) && (! $walltowall)) {
|
||||
} elseif ($top_level && !$walltowall) {
|
||||
// currently no workable solution for sending walltowall
|
||||
logger('delivery: diaspora status: ' . $loc);
|
||||
diaspora_send_status($target_item,$owner,$contact,$public_message);
|
||||
logger('diaspora status: '.$loc);
|
||||
diaspora::send_status($target_item,$owner,$contact,$public_message);
|
||||
break;
|
||||
}
|
||||
|
||||
logger('delivery: diaspora unknown mode: ' . $contact['name']);
|
||||
logger('delivery: diaspora unknown mode: '.$contact['name']);
|
||||
|
||||
break;
|
||||
|
||||
|
|
1666
include/dfrn.php
1666
include/dfrn.php
File diff suppressed because it is too large
Load diff
5922
include/diaspora.php
5922
include/diaspora.php
File diff suppressed because it is too large
Load diff
|
@ -20,22 +20,14 @@ function discover_poco_run(&$argv, &$argc){
|
|||
|
||||
require_once('include/session.php');
|
||||
require_once('include/datetime.php');
|
||||
require_once('include/pidfile.php');
|
||||
|
||||
load_config('config');
|
||||
load_config('system');
|
||||
|
||||
$maxsysload = intval(get_config('system','maxloadavg'));
|
||||
if($maxsysload < 1)
|
||||
$maxsysload = 50;
|
||||
|
||||
$load = current_load();
|
||||
if($load) {
|
||||
if(intval($load) > $maxsysload) {
|
||||
logger('system: load ' . $load . ' too high. discover_poco deferred to next scheduled run.');
|
||||
// Don't check this stuff if the function is called by the poller
|
||||
if (App::callstack() != "poller_run")
|
||||
if (App::maxload_reached())
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(($argc > 2) && ($argv[1] == "dirsearch")) {
|
||||
$search = urldecode($argv[2]);
|
||||
|
@ -50,21 +42,10 @@ function discover_poco_run(&$argv, &$argc){
|
|||
} else
|
||||
die("Unknown or missing parameter ".$argv[1]."\n");
|
||||
|
||||
$lockpath = get_lockpath();
|
||||
if ($lockpath != '') {
|
||||
$pidfile = new pidfile($lockpath, 'discover_poco'.$mode.urlencode($search));
|
||||
if($pidfile->is_already_running()) {
|
||||
logger("discover_poco: Already running");
|
||||
if ($pidfile->running_time() > 19*60) {
|
||||
$pidfile->kill();
|
||||
logger("discover_poco: killed stale process");
|
||||
// Calling a new instance
|
||||
if ($mode == 0)
|
||||
proc_run('php','include/discover_poco.php');
|
||||
}
|
||||
exit;
|
||||
}
|
||||
}
|
||||
// Don't check this stuff if the function is called by the poller
|
||||
if (App::callstack() != "poller_run")
|
||||
if (App::is_already_running('discover_poco'.$mode.urlencode($search), 'include/discover_poco.php', 1140))
|
||||
return;
|
||||
|
||||
$a->set_baseurl(get_config('system','url'));
|
||||
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
<?php
|
||||
require_once("boot.php");
|
||||
require_once('include/diaspora.php');
|
||||
|
||||
function dsprphotoq_run($argv, $argc){
|
||||
global $a, $db;
|
||||
|
||||
if(is_null($a)){
|
||||
$a = new App;
|
||||
}
|
||||
|
||||
if(is_null($db)){
|
||||
@include(".htconfig.php");
|
||||
require_once("include/dba.php");
|
||||
$db = new dba($db_host, $db_user, $db_pass, $db_data);
|
||||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
};
|
||||
|
||||
logger("diaspora photo queue: running", LOGGER_DEBUG);
|
||||
|
||||
$r = q("SELECT * FROM dsprphotoq");
|
||||
if(!$r)
|
||||
return;
|
||||
|
||||
$dphotos = $r;
|
||||
|
||||
logger("diaspora photo queue: processing " . count($dphotos) . " photos");
|
||||
|
||||
foreach($dphotos as $dphoto) {
|
||||
|
||||
$r = array();
|
||||
|
||||
if ($dphoto['uid'] == 0)
|
||||
$r[0] = array("uid" => 0, "page-flags" => PAGE_FREELOVE);
|
||||
else
|
||||
$r = q("SELECT * FROM user WHERE uid = %d",
|
||||
intval($dphoto['uid']));
|
||||
|
||||
if(!$r) {
|
||||
logger("diaspora photo queue: user " . $dphoto['uid'] . " not found");
|
||||
return;
|
||||
}
|
||||
|
||||
$ret = diaspora_dispatch($r[0],unserialize($dphoto['msg']),$dphoto['attempt']);
|
||||
q("DELETE FROM dsprphotoq WHERE id = %d",
|
||||
intval($dphoto['id'])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (array_search(__file__,get_included_files())===0){
|
||||
dsprphotoq_run($_SERVER["argv"],$_SERVER["argc"]);
|
||||
killme();
|
||||
}
|
|
@ -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>';
|
||||
|
|
116
include/feed.php
116
include/feed.php
|
@ -2,7 +2,18 @@
|
|||
require_once("include/html2bbcode.php");
|
||||
require_once("include/items.php");
|
||||
|
||||
function feed_import($xml,$importer,&$contact, &$hub) {
|
||||
/**
|
||||
* @brief Read a RSS/RDF/Atom feed and create an item entry for it
|
||||
*
|
||||
* @param string $xml The feed data
|
||||
* @param array $importer The user record of the importer
|
||||
* @param array $contact The contact record of the feed
|
||||
* @param string $hub Unused dummy value for compatibility reasons
|
||||
* @param bool $simulate If enabled, no data is imported
|
||||
*
|
||||
* @return array In simulation mode it returns the header and the first item
|
||||
*/
|
||||
function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
|
||||
|
||||
$a = get_app();
|
||||
|
||||
|
@ -14,18 +25,19 @@ function feed_import($xml,$importer,&$contact, &$hub) {
|
|||
$doc = new DOMDocument();
|
||||
@$doc->loadXML($xml);
|
||||
$xpath = new DomXPath($doc);
|
||||
$xpath->registerNamespace('atom', "http://www.w3.org/2005/Atom");
|
||||
$xpath->registerNamespace('atom', NAMESPACE_ATOM1);
|
||||
$xpath->registerNamespace('dc', "http://purl.org/dc/elements/1.1/");
|
||||
$xpath->registerNamespace('content', "http://purl.org/rss/1.0/modules/content/");
|
||||
$xpath->registerNamespace('rdf', "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
|
||||
$xpath->registerNamespace('rss', "http://purl.org/rss/1.0/");
|
||||
$xpath->registerNamespace('media', "http://search.yahoo.com/mrss/");
|
||||
$xpath->registerNamespace('poco', NAMESPACE_POCO);
|
||||
|
||||
$author = array();
|
||||
|
||||
// Is it RDF?
|
||||
if ($xpath->query('/rdf:RDF/rss:channel')->length > 0) {
|
||||
//$author["author-link"] = $xpath->evaluate('/rdf:RDF/rss:channel/rss:link/text()')->item(0)->nodeValue;
|
||||
$author["author-link"] = $xpath->evaluate('/rdf:RDF/rss:channel/rss:link/text()')->item(0)->nodeValue;
|
||||
$author["author-name"] = $xpath->evaluate('/rdf:RDF/rss:channel/rss:title/text()')->item(0)->nodeValue;
|
||||
|
||||
if ($author["author-name"] == "")
|
||||
|
@ -36,19 +48,29 @@ function feed_import($xml,$importer,&$contact, &$hub) {
|
|||
|
||||
// Is it Atom?
|
||||
if ($xpath->query('/atom:feed/atom:entry')->length > 0) {
|
||||
//$self = $xpath->query("/atom:feed/atom:link[@rel='self']")->item(0)->attributes;
|
||||
//if (is_object($self))
|
||||
// foreach($self AS $attributes)
|
||||
// if ($attributes->name == "href")
|
||||
// $author["author-link"] = $attributes->textContent;
|
||||
$alternate = $xpath->query("atom:link[@rel='alternate']")->item(0)->attributes;
|
||||
if (is_object($alternate))
|
||||
foreach($alternate AS $attributes)
|
||||
if ($attributes->name == "href")
|
||||
$author["author-link"] = $attributes->textContent;
|
||||
|
||||
//if ($author["author-link"] == "") {
|
||||
// $alternate = $xpath->query("/atom:feed/atom:link[@rel='alternate']")->item(0)->attributes;
|
||||
// if (is_object($alternate))
|
||||
// foreach($alternate AS $attributes)
|
||||
// if ($attributes->name == "href")
|
||||
// $author["author-link"] = $attributes->textContent;
|
||||
//}
|
||||
$author["author-id"] = $xpath->evaluate('/atom:feed/atom:author/atom:uri/text()')->item(0)->nodeValue;
|
||||
|
||||
if ($author["author-link"] == "")
|
||||
$author["author-link"] = $author["author-id"];
|
||||
|
||||
if ($author["author-link"] == "") {
|
||||
$self = $xpath->query("atom:link[@rel='self']")->item(0)->attributes;
|
||||
if (is_object($self))
|
||||
foreach($self AS $attributes)
|
||||
if ($attributes->name == "href")
|
||||
$author["author-link"] = $attributes->textContent;
|
||||
}
|
||||
|
||||
if ($author["author-link"] == "")
|
||||
$author["author-link"] = $xpath->evaluate('/atom:feed/atom:id/text()')->item(0)->nodeValue;
|
||||
|
||||
$author["author-avatar"] = $xpath->evaluate('/atom:feed/atom:logo/text()')->item(0)->nodeValue;
|
||||
|
||||
$author["author-name"] = $xpath->evaluate('/atom:feed/atom:title/text()')->item(0)->nodeValue;
|
||||
|
||||
|
@ -58,7 +80,13 @@ function feed_import($xml,$importer,&$contact, &$hub) {
|
|||
if ($author["author-name"] == "")
|
||||
$author["author-name"] = $xpath->evaluate('/atom:feed/atom:author/atom:name/text()')->item(0)->nodeValue;
|
||||
|
||||
//$author["author-avatar"] = $xpath->evaluate('/atom:feed/atom:logo/text()')->item(0)->nodeValue;
|
||||
$value = $xpath->evaluate('atom:author/poco:displayName/text()')->item(0)->nodeValue;
|
||||
if ($value != "")
|
||||
$author["author-name"] = $value;
|
||||
|
||||
$value = $xpath->evaluate('atom:author/poco:preferredUsername/text()')->item(0)->nodeValue;
|
||||
if ($value != "")
|
||||
$author["author-nick"] = $value;
|
||||
|
||||
$author["edited"] = $author["created"] = $xpath->query('/atom:feed/atom:updated/text()')->item(0)->nodeValue;
|
||||
|
||||
|
@ -69,9 +97,10 @@ function feed_import($xml,$importer,&$contact, &$hub) {
|
|||
|
||||
// Is it RSS?
|
||||
if ($xpath->query('/rss/channel')->length > 0) {
|
||||
//$author["author-link"] = $xpath->evaluate('/rss/channel/link/text()')->item(0)->nodeValue;
|
||||
$author["author-link"] = $xpath->evaluate('/rss/channel/link/text()')->item(0)->nodeValue;
|
||||
|
||||
$author["author-name"] = $xpath->evaluate('/rss/channel/title/text()')->item(0)->nodeValue;
|
||||
//$author["author-avatar"] = $xpath->evaluate('/rss/channel/image/url/text()')->item(0)->nodeValue;
|
||||
$author["author-avatar"] = $xpath->evaluate('/rss/channel/image/url/text()')->item(0)->nodeValue;
|
||||
|
||||
if ($author["author-name"] == "")
|
||||
$author["author-name"] = $xpath->evaluate('/rss/channel/copyright/text()')->item(0)->nodeValue;
|
||||
|
@ -86,18 +115,22 @@ function feed_import($xml,$importer,&$contact, &$hub) {
|
|||
$entries = $xpath->query('/rss/channel/item');
|
||||
}
|
||||
|
||||
//if ($author["author-link"] == "")
|
||||
if (!$simulate) {
|
||||
$author["author-link"] = $contact["url"];
|
||||
|
||||
if ($author["author-name"] == "")
|
||||
$author["author-name"] = $contact["name"];
|
||||
if ($author["author-name"] == "")
|
||||
$author["author-name"] = $contact["name"];
|
||||
|
||||
//if ($author["author-avatar"] == "")
|
||||
$author["author-avatar"] = $contact["thumb"];
|
||||
|
||||
$author["owner-link"] = $contact["url"];
|
||||
$author["owner-name"] = $contact["name"];
|
||||
$author["owner-avatar"] = $contact["thumb"];
|
||||
$author["owner-link"] = $contact["url"];
|
||||
$author["owner-name"] = $contact["name"];
|
||||
$author["owner-avatar"] = $contact["thumb"];
|
||||
|
||||
// This is no field in the item table. So we have to unset it.
|
||||
unset($author["author-nick"]);
|
||||
unset($author["author-id"]);
|
||||
}
|
||||
|
||||
$header = array();
|
||||
$header["uid"] = $importer["uid"];
|
||||
|
@ -120,6 +153,8 @@ function feed_import($xml,$importer,&$contact, &$hub) {
|
|||
if (!is_object($entries))
|
||||
return;
|
||||
|
||||
$items = array();
|
||||
|
||||
$entrylist = array();
|
||||
|
||||
foreach ($entries AS $entry)
|
||||
|
@ -201,13 +236,13 @@ function feed_import($xml,$importer,&$contact, &$hub) {
|
|||
if ($creator != "")
|
||||
$item["author-name"] = $creator;
|
||||
|
||||
//$item["object"] = $xml;
|
||||
|
||||
$r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `network` IN ('%s', '%s')",
|
||||
intval($importer["uid"]), dbesc($item["uri"]), dbesc(NETWORK_FEED), dbesc(NETWORK_DFRN));
|
||||
if ($r) {
|
||||
logger("Item with uri ".$item["uri"]." for user ".$importer["uid"]." already existed under id ".$r[0]["id"], LOGGER_DEBUG);
|
||||
continue;
|
||||
if (!$simulate) {
|
||||
$r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `network` IN ('%s', '%s')",
|
||||
intval($importer["uid"]), dbesc($item["uri"]), dbesc(NETWORK_FEED), dbesc(NETWORK_DFRN));
|
||||
if ($r) {
|
||||
logger("Item with uri ".$item["uri"]." for user ".$importer["uid"]." already existed under id ".$r[0]["id"], LOGGER_DEBUG);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
/// @TODO ?
|
||||
|
@ -272,14 +307,21 @@ function feed_import($xml,$importer,&$contact, &$hub) {
|
|||
$item["body"] = html2bbcode($body);
|
||||
}
|
||||
|
||||
logger("Stored feed: ".print_r($item, true), LOGGER_DEBUG);
|
||||
if (!$simulate) {
|
||||
logger("Stored feed: ".print_r($item, true), LOGGER_DEBUG);
|
||||
|
||||
$notify = item_is_remote_self($contact, $item);
|
||||
$id = item_store($item, false, $notify);
|
||||
$notify = item_is_remote_self($contact, $item);
|
||||
$id = item_store($item, false, $notify);
|
||||
|
||||
//print_r($item);
|
||||
logger("Feed for contact ".$contact["url"]." stored under id ".$id);
|
||||
} else
|
||||
$items[] = $item;
|
||||
|
||||
logger("Feed for contact ".$contact["url"]." stored under id ".$id);
|
||||
if ($simulate)
|
||||
break;
|
||||
}
|
||||
|
||||
if ($simulate)
|
||||
return array("header" => $author, "items" => $items);
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
require_once("include/Scrape.php");
|
||||
require_once("include/socgraph.php");
|
||||
|
||||
function update_contact($id) {
|
||||
/*
|
||||
|
@ -43,6 +44,9 @@ function update_contact($id) {
|
|||
intval($id)
|
||||
);
|
||||
|
||||
// Update the corresponding gcontact entry
|
||||
poco_last_updated($ret["url"]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -254,12 +258,10 @@ function new_contact($uid,$url,$interactive = false) {
|
|||
$contact_id = $r[0]['id'];
|
||||
$result['cid'] = $contact_id;
|
||||
|
||||
$g = q("select def_gid from user where uid = %d limit 1",
|
||||
intval($uid)
|
||||
);
|
||||
if($g && intval($g[0]['def_gid'])) {
|
||||
$def_gid = get_default_group($uid, $contact["network"]);
|
||||
if (intval($def_gid)) {
|
||||
require_once('include/group.php');
|
||||
group_add_member($uid,'',$contact_id,$g[0]['def_gid']);
|
||||
group_add_member($uid, '', $contact_id, $def_gid);
|
||||
}
|
||||
|
||||
require_once("include/Photo.php");
|
||||
|
@ -301,8 +303,8 @@ function new_contact($uid,$url,$interactive = false) {
|
|||
}
|
||||
if($contact['network'] == NETWORK_DIASPORA) {
|
||||
require_once('include/diaspora.php');
|
||||
$ret = diaspora_share($a->user,$contact);
|
||||
logger('mod_follow: diaspora_share returns: ' . $ret);
|
||||
$ret = diaspora::send_share($a->user,$contact);
|
||||
logger('share returns: '.$ret);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,185 +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)
|
||||
);
|
||||
|
||||
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
|
||||
* @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;
|
||||
}
|
|
@ -60,6 +60,8 @@ class FriendicaSmartyEngine implements ITemplateEngine {
|
|||
$template = $s;
|
||||
$s = new FriendicaSmarty();
|
||||
}
|
||||
|
||||
$r['$APP'] = get_app();
|
||||
|
||||
// "middleware": inject variables into templates
|
||||
$arr = array(
|
||||
|
|
|
@ -188,7 +188,7 @@ function group_public_members($gid) {
|
|||
}
|
||||
|
||||
|
||||
function mini_group_select($uid,$gid = 0) {
|
||||
function mini_group_select($uid,$gid = 0, $label = "") {
|
||||
|
||||
$grps = array();
|
||||
$o = '';
|
||||
|
@ -205,8 +205,11 @@ function mini_group_select($uid,$gid = 0) {
|
|||
}
|
||||
logger('groups: ' . print_r($grps,true));
|
||||
|
||||
if ($label == "")
|
||||
$label = t('Default privacy group for new contacts');
|
||||
|
||||
$o = replace_macros(get_markup_template('group_selection.tpl'), array(
|
||||
'$label' => t('Default privacy group for new contacts'),
|
||||
'$label' => $label,
|
||||
'$groups' => $grps
|
||||
));
|
||||
return $o;
|
||||
|
@ -215,7 +218,7 @@ function mini_group_select($uid,$gid = 0) {
|
|||
|
||||
/**
|
||||
* @brief Create group sidebar widget
|
||||
*
|
||||
*
|
||||
* @param string $every
|
||||
* @param string $each
|
||||
* @param string $editmode
|
||||
|
@ -234,7 +237,7 @@ function group_side($every="contacts",$each="group",$editmode = "standard", $gro
|
|||
return '';
|
||||
|
||||
$groups = array();
|
||||
|
||||
|
||||
$groups[] = array(
|
||||
'text' => t('Everybody'),
|
||||
'id' => 0,
|
||||
|
@ -255,7 +258,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 +267,7 @@ function group_side($every="contacts",$each="group",$editmode = "standard", $gro
|
|||
} else {
|
||||
$groupedit = null;
|
||||
}
|
||||
|
||||
|
||||
$groups[] = array(
|
||||
'id' => $rr['id'],
|
||||
'cid' => $cid,
|
||||
|
@ -362,17 +365,41 @@ 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the default group for a given user and network
|
||||
*
|
||||
* @param int $uid User id
|
||||
* @param string $network network name
|
||||
*
|
||||
* @return int group id
|
||||
*/
|
||||
function get_default_group($uid, $network = "") {
|
||||
|
||||
$default_group = 0;
|
||||
|
||||
if ($network == NETWORK_OSTATUS)
|
||||
$default_group = get_pconfig($uid, "ostatus", "default_group");
|
||||
|
||||
if ($default_group != 0)
|
||||
return $default_group;
|
||||
|
||||
$g = q("SELECT `def_gid` FROM `user` WHERE `uid` = %d LIMIT 1", intval($uid));
|
||||
if($g && intval($g[0]["def_gid"]))
|
||||
$default_group = $g[0]["def_gid"];
|
||||
|
||||
return $default_group;
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
@ -237,6 +237,7 @@ function profile_sidebar($profile, $block = 0) {
|
|||
if ($connect AND ($profile['network'] != NETWORK_DFRN) AND !isset($profile['remoteconnect']))
|
||||
$connect = false;
|
||||
|
||||
$remoteconnect = NULL;
|
||||
if (isset($profile['remoteconnect']))
|
||||
$remoteconnect = $profile['remoteconnect'];
|
||||
|
||||
|
@ -292,9 +293,9 @@ function profile_sidebar($profile, $block = 0) {
|
|||
// check if profile is a forum
|
||||
if((intval($profile['page-flags']) == PAGE_COMMUNITY)
|
||||
|| (intval($profile['page-flags']) == PAGE_PRVGROUP)
|
||||
|| (intval($profile['forum']))
|
||||
|| (intval($profile['prv']))
|
||||
|| (intval($profile['community'])))
|
||||
|| (isset($profile['forum']) && intval($profile['forum']))
|
||||
|| (isset($profile['prv']) && intval($profile['prv']))
|
||||
|| (isset($profile['community']) && intval($profile['community'])))
|
||||
$account_type = t('Forum');
|
||||
else
|
||||
$account_type = "";
|
||||
|
@ -332,9 +333,9 @@ function profile_sidebar($profile, $block = 0) {
|
|||
'fullname' => $profile['name'],
|
||||
'firstname' => $firstname,
|
||||
'lastname' => $lastname,
|
||||
'photo300' => $a->get_cached_avatar_image($a->get_baseurl() . '/photo/custom/300/' . $profile['uid'] . '.jpg'),
|
||||
'photo100' => $a->get_cached_avatar_image($a->get_baseurl() . '/photo/custom/100/' . $profile['uid'] . '.jpg'),
|
||||
'photo50' => $a->get_cached_avatar_image($a->get_baseurl() . '/photo/custom/50/' . $profile['uid'] . '.jpg'),
|
||||
'photo300' => $a->get_baseurl() . '/photo/custom/300/' . $profile['uid'] . '.jpg',
|
||||
'photo100' => $a->get_baseurl() . '/photo/custom/100/' . $profile['uid'] . '.jpg',
|
||||
'photo50' => $a->get_baseurl() . '/photo/custom/50/' . $profile['uid'] . '.jpg',
|
||||
);
|
||||
|
||||
if (!$block){
|
||||
|
@ -655,7 +656,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())
|
||||
|
|
2283
include/items.php
2283
include/items.php
File diff suppressed because it is too large
Load diff
153
include/like.php
153
include/like.php
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
require_once("include/diaspora.php");
|
||||
|
||||
/**
|
||||
* @brief add/remove activity to an item
|
||||
|
@ -151,9 +152,6 @@ function do_like($item_id, $verb) {
|
|||
intval($like_item['id'])
|
||||
);
|
||||
|
||||
// Save the author information for the unlike in case we need to relay to Diaspora
|
||||
store_diaspora_like_retract_sig($activity, $item, $like_item, $contact);
|
||||
|
||||
$like_item_id = $like_item['id'];
|
||||
proc_run('php',"include/notifier.php","like","$like_item_id");
|
||||
|
||||
|
@ -196,6 +194,7 @@ EOT;
|
|||
|
||||
$arr = array();
|
||||
|
||||
$arr['guid'] = get_guid(32);
|
||||
$arr['uri'] = $uri;
|
||||
$arr['uid'] = $owner_uid;
|
||||
$arr['contact-id'] = $contact['id'];
|
||||
|
@ -240,7 +239,7 @@ EOT;
|
|||
|
||||
|
||||
// Save the author information for the like in case we need to relay to Diaspora
|
||||
store_diaspora_like_sig($activity, $post_type, $contact, $post_id);
|
||||
diaspora::store_like_signature($contact, $post_id);
|
||||
|
||||
$arr['id'] = $post_id;
|
||||
|
||||
|
@ -250,149 +249,3 @@ EOT;
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function store_diaspora_like_retract_sig($activity, $item, $like_item, $contact) {
|
||||
// Note that we can only create a signature for a user of the local server. We don't have
|
||||
// a key for remote users. That is ok, because if a remote user is "unlike"ing a post, it
|
||||
// means we are the relay, and for relayable_retractions, Diaspora
|
||||
// only checks the parent_author_signature if it doesn't have to relay further
|
||||
//
|
||||
// If $item['resource-id'] exists, it means the item is a photo. Diaspora doesn't support
|
||||
// likes on photos, so don't bother.
|
||||
|
||||
$enabled = intval(get_config('system','diaspora_enabled'));
|
||||
if(! $enabled) {
|
||||
logger('mod_like: diaspora support disabled, not storing like retraction signature', LOGGER_DEBUG);
|
||||
return;
|
||||
}
|
||||
|
||||
logger('mod_like: storing diaspora like retraction signature');
|
||||
|
||||
if(($activity === ACTIVITY_LIKE) && (! $item['resource-id'])) {
|
||||
$signed_text = $like_item['guid'] . ';' . 'Like';
|
||||
|
||||
// Only works for NETWORK_DFRN
|
||||
$contact_baseurl_start = strpos($contact['url'],'://') + 3;
|
||||
$contact_baseurl_length = strpos($contact['url'],'/profile') - $contact_baseurl_start;
|
||||
$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'])
|
||||
);
|
||||
|
||||
if( $r) {
|
||||
$contact_uid = $r['uid'];
|
||||
$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[0]['prvkey'],'sha256'));
|
||||
}
|
||||
|
||||
if(! isset($authorsig))
|
||||
$authorsig = '';
|
||||
|
||||
q("insert into sign (`retract_iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ",
|
||||
intval($like_item['id']),
|
||||
dbesc($signed_text),
|
||||
dbesc($authorsig),
|
||||
dbesc($diaspora_handle)
|
||||
);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
function store_diaspora_like_sig($activity, $post_type, $contact, $post_id) {
|
||||
// Note that we can only create a signature for a user of the local server. We don't have
|
||||
// a key for remote users. That is ok, because if a remote user is "unlike"ing a post, it
|
||||
// means we are the relay, and for relayable_retractions, Diaspora
|
||||
// only checks the parent_author_signature if it doesn't have to relay further
|
||||
|
||||
$enabled = intval(get_config('system','diaspora_enabled'));
|
||||
if(! $enabled) {
|
||||
logger('mod_like: diaspora support disabled, not storing like signature', LOGGER_DEBUG);
|
||||
return;
|
||||
}
|
||||
|
||||
logger('mod_like: storing diaspora like signature');
|
||||
|
||||
if(($activity === ACTIVITY_LIKE) && ($post_type === t('status'))) {
|
||||
// Only works for NETWORK_DFRN
|
||||
$contact_baseurl_start = strpos($contact['url'],'://') + 3;
|
||||
$contact_baseurl_length = strpos($contact['url'],'/profile') - $contact_baseurl_start;
|
||||
$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'])
|
||||
);
|
||||
|
||||
if( $r) {
|
||||
$contact_uid = $r['uid'];
|
||||
$r = q("SELECT prvkey FROM user WHERE uid = %d LIMIT 1",
|
||||
intval($contact_uid)
|
||||
);
|
||||
|
||||
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)
|
||||
);
|
||||
if( $r) {
|
||||
$p = q("SELECT guid FROM `item` WHERE id = %d AND parent = %d LIMIT 1",
|
||||
intval($r[0]['parent']),
|
||||
intval($r[0]['parent'])
|
||||
);
|
||||
if( $p) {
|
||||
$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'));
|
||||
else
|
||||
$authorsig = '';
|
||||
|
||||
q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ",
|
||||
intval($post_id),
|
||||
dbesc($signed_text),
|
||||
dbesc($authorsig),
|
||||
dbesc($diaspora_handle)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ function nav_info(&$a) {
|
|||
// user info
|
||||
$r = q("SELECT micro FROM contact WHERE uid=%d AND self=1", intval($a->user['uid']));
|
||||
$userinfo = array(
|
||||
'icon' => (count($r) ? $a->get_cached_avatar_image($r[0]['micro']) : $a->get_baseurl($ssl_state)."/images/person-48.jpg"),
|
||||
'icon' => (count($r) ? $a->remove_baseurl($r[0]['micro']) : "images/person-48.jpg"),
|
||||
'name' => $a->user['username'],
|
||||
);
|
||||
|
||||
|
@ -110,7 +110,7 @@ function nav_info(&$a) {
|
|||
if(($a->config['register_policy'] == REGISTER_OPEN) && (! local_user()) && (! remote_user()))
|
||||
$nav['register'] = array('register',t('Register'), "", t('Create an account'));
|
||||
|
||||
$help_url = $a->get_baseurl($ssl_state) . '/help';
|
||||
$help_url = 'help';
|
||||
|
||||
if(! get_config('system','hide_help'))
|
||||
$nav['help'] = array($help_url, t('Help'), "", t('Help and documentation'));
|
||||
|
|
|
@ -862,64 +862,6 @@ function parse_xml_string($s,$strict = true) {
|
|||
return $x;
|
||||
}}
|
||||
|
||||
function add_fcontact($arr,$update = false) {
|
||||
|
||||
if($update) {
|
||||
$r = q("UPDATE `fcontact` SET
|
||||
`name` = '%s',
|
||||
`photo` = '%s',
|
||||
`request` = '%s',
|
||||
`nick` = '%s',
|
||||
`addr` = '%s',
|
||||
`batch` = '%s',
|
||||
`notify` = '%s',
|
||||
`poll` = '%s',
|
||||
`confirm` = '%s',
|
||||
`alias` = '%s',
|
||||
`pubkey` = '%s',
|
||||
`updated` = '%s'
|
||||
WHERE `url` = '%s' AND `network` = '%s'",
|
||||
dbesc($arr['name']),
|
||||
dbesc($arr['photo']),
|
||||
dbesc($arr['request']),
|
||||
dbesc($arr['nick']),
|
||||
dbesc($arr['addr']),
|
||||
dbesc($arr['batch']),
|
||||
dbesc($arr['notify']),
|
||||
dbesc($arr['poll']),
|
||||
dbesc($arr['confirm']),
|
||||
dbesc($arr['alias']),
|
||||
dbesc($arr['pubkey']),
|
||||
dbesc(datetime_convert()),
|
||||
dbesc($arr['url']),
|
||||
dbesc($arr['network'])
|
||||
);
|
||||
}
|
||||
else {
|
||||
$r = q("insert into fcontact ( `url`,`name`,`photo`,`request`,`nick`,`addr`,
|
||||
`batch`, `notify`,`poll`,`confirm`,`network`,`alias`,`pubkey`,`updated` )
|
||||
values('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",
|
||||
dbesc($arr['url']),
|
||||
dbesc($arr['name']),
|
||||
dbesc($arr['photo']),
|
||||
dbesc($arr['request']),
|
||||
dbesc($arr['nick']),
|
||||
dbesc($arr['addr']),
|
||||
dbesc($arr['batch']),
|
||||
dbesc($arr['notify']),
|
||||
dbesc($arr['poll']),
|
||||
dbesc($arr['confirm']),
|
||||
dbesc($arr['network']),
|
||||
dbesc($arr['alias']),
|
||||
dbesc($arr['pubkey']),
|
||||
dbesc(datetime_convert())
|
||||
);
|
||||
}
|
||||
|
||||
return $r;
|
||||
}
|
||||
|
||||
|
||||
function scale_external_images($srctext, $include_link = true, $scale_replace = false) {
|
||||
|
||||
// Suppress "view full size"
|
||||
|
|
|
@ -223,13 +223,13 @@ function notifier_run(&$argv, &$argc){
|
|||
|
||||
if(! ($mail || $fsuggest || $relocate)) {
|
||||
|
||||
$slap = ostatus_salmon($target_item,$owner);
|
||||
$slap = ostatus::salmon($target_item,$owner);
|
||||
|
||||
require_once('include/group.php');
|
||||
|
||||
$parent = $items[0];
|
||||
|
||||
$thr_parent = q("SELECT `network` FROM `item` WHERE `uri` = '%s' AND `uid` = %d",
|
||||
$thr_parent = q("SELECT `network`, `author-link`, `owner-link` FROM `item` WHERE `uri` = '%s' AND `uid` = %d",
|
||||
dbesc($target_item["thr-parent"]), intval($target_item["uid"]));
|
||||
|
||||
logger('Parent is '.$parent['network'].'. Thread parent is '.$thr_parent[0]['network'], LOGGER_DEBUG);
|
||||
|
@ -390,6 +390,20 @@ function notifier_run(&$argv, &$argc){
|
|||
|
||||
logger('Some parent is OStatus for '.$target_item["guid"], LOGGER_DEBUG);
|
||||
|
||||
// Send a salmon to the parent author
|
||||
$probed_contact = probe_url($thr_parent[0]['author-link']);
|
||||
if ($probed_contact["notify"] != "") {
|
||||
logger('Notify parent author '.$probed_contact["url"].': '.$probed_contact["notify"]);
|
||||
$url_recipients[$probed_contact["notify"]] = $probed_contact["notify"];
|
||||
}
|
||||
|
||||
// Send a salmon to the parent owner
|
||||
$probed_contact = probe_url($thr_parent[0]['owner-link']);
|
||||
if ($probed_contact["notify"] != "") {
|
||||
logger('Notify parent owner '.$probed_contact["url"].': '.$probed_contact["notify"]);
|
||||
$url_recipients[$probed_contact["notify"]] = $probed_contact["notify"];
|
||||
}
|
||||
|
||||
// Send a salmon notification to every person we mentioned in the post
|
||||
$arr = explode(',',$target_item['tag']);
|
||||
foreach($arr as $x) {
|
||||
|
@ -536,7 +550,7 @@ function notifier_run(&$argv, &$argc){
|
|||
if($public_message) {
|
||||
|
||||
if (!$followup AND $top_level)
|
||||
$r0 = diaspora_fetch_relay();
|
||||
$r0 = diaspora::relay_list();
|
||||
else
|
||||
$r0 = array();
|
||||
|
||||
|
@ -628,13 +642,6 @@ function notifier_run(&$argv, &$argc){
|
|||
proc_run('php','include/pubsubpublish.php');
|
||||
}
|
||||
|
||||
// If the item was deleted, clean up the `sign` table
|
||||
if($target_item['deleted']) {
|
||||
$r = q("DELETE FROM sign where `retract_iid` = %d",
|
||||
intval($target_item['id'])
|
||||
);
|
||||
}
|
||||
|
||||
logger('notifier: calling hooks', LOGGER_DEBUG);
|
||||
|
||||
if($normal_mode)
|
||||
|
|
|
@ -31,7 +31,6 @@ function onepoll_run(&$argv, &$argc){
|
|||
require_once('include/Contact.php');
|
||||
require_once('include/email.php');
|
||||
require_once('include/socgraph.php');
|
||||
require_once('include/pidfile.php');
|
||||
require_once('include/queue_fn.php');
|
||||
|
||||
load_config('config');
|
||||
|
@ -60,18 +59,10 @@ function onepoll_run(&$argv, &$argc){
|
|||
return;
|
||||
}
|
||||
|
||||
$lockpath = get_lockpath();
|
||||
if ($lockpath != '') {
|
||||
$pidfile = new pidfile($lockpath, 'onepoll'.$contact_id);
|
||||
if ($pidfile->is_already_running()) {
|
||||
logger("onepoll: Already running for contact ".$contact_id);
|
||||
if ($pidfile->running_time() > 9*60) {
|
||||
$pidfile->kill();
|
||||
logger("killed stale process");
|
||||
}
|
||||
exit;
|
||||
}
|
||||
}
|
||||
// Don't check this stuff if the function is called by the poller
|
||||
if (App::callstack() != "poller_run")
|
||||
if (App::is_already_running('onepoll'.$contact_id, '', 540))
|
||||
return;
|
||||
|
||||
$d = datetime_convert();
|
||||
|
||||
|
|
3166
include/ostatus.php
3166
include/ostatus.php
File diff suppressed because it is too large
Load diff
|
@ -132,7 +132,19 @@ function shortenmsg($msg, $limit, $twitter = false) {
|
|||
return($msg);
|
||||
}
|
||||
|
||||
function plaintext($a, $b, $limit = 0, $includedlinks = false, $htmlmode = 2) {
|
||||
/**
|
||||
* @brief Convert a message into plaintext for connectors to other networks
|
||||
*
|
||||
* @param App $a The application class
|
||||
* @param array $b The message array that is about to be posted
|
||||
* @param int $limit The maximum number of characters when posting to that network
|
||||
* @param bool $includedlinks Has an attached link to be included into the message?
|
||||
* @param int $htmlmode This triggers the behaviour of the bbcode conversion
|
||||
* @param string $target_network Name of the network where the post should go to.
|
||||
*
|
||||
* @return string The converted message
|
||||
*/
|
||||
function plaintext($a, $b, $limit = 0, $includedlinks = false, $htmlmode = 2, $target_network = "") {
|
||||
require_once("include/bbcode.php");
|
||||
require_once("include/html2plain.php");
|
||||
require_once("include/network.php");
|
||||
|
@ -144,6 +156,9 @@ function plaintext($a, $b, $limit = 0, $includedlinks = false, $htmlmode = 2) {
|
|||
// 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);
|
||||
|
||||
// Remove the abstract
|
||||
$body = remove_abstract($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"]);
|
||||
|
@ -154,6 +169,44 @@ function plaintext($a, $b, $limit = 0, $includedlinks = false, $htmlmode = 2) {
|
|||
elseif ($b["title"] != "")
|
||||
$post["text"] = trim($b["title"]);
|
||||
|
||||
$abstract = "";
|
||||
|
||||
// Fetch the abstract from the given target network
|
||||
if ($target_network != "") {
|
||||
$default_abstract = fetch_abstract($b["body"]);
|
||||
$abstract = fetch_abstract($b["body"], $target_network);
|
||||
|
||||
// If we post to a network with no limit we only fetch
|
||||
// an abstract exactly for this network
|
||||
if (($limit == 0) AND ($abstract == $default_abstract))
|
||||
$abstract = "";
|
||||
|
||||
} else // Try to guess the correct target network
|
||||
switch ($htmlmode) {
|
||||
case 8:
|
||||
$abstract = fetch_abstract($b["body"], NETWORK_TWITTER);
|
||||
break;
|
||||
case 7:
|
||||
$abstract = fetch_abstract($b["body"], NETWORK_STATUSNET);
|
||||
break;
|
||||
case 6:
|
||||
$abstract = fetch_abstract($b["body"], NETWORK_APPNET);
|
||||
break;
|
||||
default: // We don't know the exact target.
|
||||
// We fetch an abstract since there is a posting limit.
|
||||
if ($limit > 0)
|
||||
$abstract = fetch_abstract($b["body"]);
|
||||
}
|
||||
|
||||
if ($abstract != "") {
|
||||
$post["text"] = $abstract;
|
||||
|
||||
if ($post["type"] == "text") {
|
||||
$post["type"] = "link";
|
||||
$post["url"] = $b["plink"];
|
||||
}
|
||||
}
|
||||
|
||||
$html = bbcode($post["text"], false, false, $htmlmode);
|
||||
$msg = html2plain($html, 0, true);
|
||||
$msg = trim(html_entity_decode($msg,ENT_QUOTES,'UTF-8'));
|
||||
|
|
|
@ -26,17 +26,11 @@ function poller_run(&$argv, &$argc){
|
|||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
};
|
||||
|
||||
$load = current_load();
|
||||
if($load) {
|
||||
$maxsysload = intval(get_config('system','maxloadavg'));
|
||||
if($maxsysload < 1)
|
||||
$maxsysload = 50;
|
||||
if (poller_max_connections_reached())
|
||||
return;
|
||||
|
||||
if(intval($load) > $maxsysload) {
|
||||
logger('system: load ' . $load . ' too high. poller deferred to next scheduled run.');
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (App::maxload_reached())
|
||||
return;
|
||||
|
||||
// Checking the number of workers
|
||||
if (poller_too_much_workers(1)) {
|
||||
|
@ -65,6 +59,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;
|
||||
|
@ -117,12 +115,93 @@ 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'");
|
||||
|
||||
if (!is_array($r) || count($r) == 0) {
|
||||
// No processing here needed
|
||||
return;
|
||||
}
|
||||
|
||||
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",
|
||||
|
|
141
include/post_update.php
Normal file
141
include/post_update.php
Normal file
|
@ -0,0 +1,141 @@
|
|||
<?php
|
||||
/**
|
||||
* @file include/post_update.php
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Calls the post update functions
|
||||
*/
|
||||
function post_update() {
|
||||
|
||||
if (!post_update_1192())
|
||||
return;
|
||||
|
||||
if (!post_update_1194())
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*
|
||||
* @return bool "true" when the job is done
|
||||
*/
|
||||
function post_update_1192() {
|
||||
|
||||
// Was the script completed?
|
||||
if (get_config("system", "post_update_version") >= 1192)
|
||||
return true;
|
||||
|
||||
// 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", 1192);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 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 false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Updates the "global" field in the item table
|
||||
*
|
||||
* @return bool "true" when the job is done
|
||||
*/
|
||||
function post_update_1194() {
|
||||
|
||||
// Was the script completed?
|
||||
if (get_config("system", "post_update_version") >= 1194)
|
||||
return true;
|
||||
|
||||
logger("Start", LOGGER_DEBUG);
|
||||
|
||||
$end_id = get_config("system", "post_update_1194_end");
|
||||
if (!$end_id) {
|
||||
$r = q("SELECT `id` FROM `item` WHERE `uid` != 0 ORDER BY `id` DESC LIMIT 1");
|
||||
if ($r) {
|
||||
set_config("system", "post_update_1194_end", $r[0]["id"]);
|
||||
$end_id = get_config("system", "post_update_1194_end");
|
||||
}
|
||||
}
|
||||
|
||||
logger("End ID: ".$end_id, LOGGER_DEBUG);
|
||||
|
||||
$start_id = get_config("system", "post_update_1194_start");
|
||||
|
||||
$query1 = "SELECT `item`.`id` FROM `item` ";
|
||||
|
||||
$query2 = "INNER JOIN `item` AS `shadow` ON `item`.`uri` = `shadow`.`uri` AND `shadow`.`uid` = 0 ";
|
||||
|
||||
$query3 = "WHERE `item`.`uid` != 0 AND `item`.`id` >= %d AND `item`.`id` <= %d
|
||||
AND `item`.`visible` AND NOT `item`.`private`
|
||||
AND NOT `item`.`deleted` AND NOT `item`.`moderated`
|
||||
AND `item`.`network` IN ('%s', '%s', '%s', '')
|
||||
AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
|
||||
AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
|
||||
AND NOT `item`.`global`";
|
||||
|
||||
$r = q($query1.$query2.$query3." ORDER BY `item`.`id` LIMIT 1",
|
||||
intval($start_id), intval($end_id),
|
||||
dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS));
|
||||
if (!$r) {
|
||||
set_config("system", "post_update_version", 1194);
|
||||
logger("Update is done", LOGGER_DEBUG);
|
||||
return true;
|
||||
} else {
|
||||
set_config("system", "post_update_1194_start", $r[0]["id"]);
|
||||
$start_id = get_config("system", "post_update_1194_start");
|
||||
}
|
||||
|
||||
logger("Start ID: ".$start_id, LOGGER_DEBUG);
|
||||
|
||||
$r = q($query1.$query2.$query3." ORDER BY `item`.`id` LIMIT 1000,1",
|
||||
intval($start_id), intval($end_id),
|
||||
dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS));
|
||||
if ($r)
|
||||
$pos_id = $r[0]["id"];
|
||||
else
|
||||
$pos_id = $end_id;
|
||||
|
||||
logger("Progress: Start: ".$start_id." position: ".$pos_id." end: ".$end_id, LOGGER_DEBUG);
|
||||
|
||||
$r = q("UPDATE `item` ".$query2." SET `item`.`global` = 1 ".$query3,
|
||||
intval($start_id), intval($pos_id),
|
||||
dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS));
|
||||
|
||||
logger("Done", LOGGER_DEBUG);
|
||||
}
|
||||
?>
|
|
@ -1,96 +1,6 @@
|
|||
<?php
|
||||
|
||||
require_once('include/datetime.php');
|
||||
require_once('include/diaspora.php');
|
||||
require_once('include/queue_fn.php');
|
||||
require_once('include/Contact.php');
|
||||
|
||||
function profile_change() {
|
||||
|
||||
$a = get_app();
|
||||
|
||||
if(! local_user())
|
||||
return;
|
||||
|
||||
// $url = $a->get_baseurl() . '/profile/' . $a->user['nickname'];
|
||||
// if($url && strlen(get_config('system','directory')))
|
||||
// proc_run('php',"include/directory.php","$url");
|
||||
|
||||
$recips = q("SELECT `id`,`name`,`network`,`pubkey`,`notify` FROM `contact` WHERE `network` = '%s'
|
||||
AND `uid` = %d AND `rel` != %d ",
|
||||
dbesc(NETWORK_DIASPORA),
|
||||
intval(local_user()),
|
||||
intval(CONTACT_IS_SHARING)
|
||||
);
|
||||
if(! count($recips))
|
||||
return;
|
||||
|
||||
$r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `user`.* FROM `profile`
|
||||
INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
|
||||
WHERE `user`.`uid` = %d AND `profile`.`is-default` = 1 LIMIT 1",
|
||||
intval(local_user())
|
||||
);
|
||||
|
||||
if(! count($r))
|
||||
return;
|
||||
$profile = $r[0];
|
||||
|
||||
$handle = xmlify($a->user['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3));
|
||||
$first = xmlify(((strpos($profile['name'],' '))
|
||||
? trim(substr($profile['name'],0,strpos($profile['name'],' '))) : $profile['name']));
|
||||
$last = xmlify((($first === $profile['name']) ? '' : trim(substr($profile['name'],strlen($first)))));
|
||||
$large = xmlify($a->get_baseurl() . '/photo/custom/300/' . $profile['uid'] . '.jpg');
|
||||
$medium = xmlify($a->get_baseurl() . '/photo/custom/100/' . $profile['uid'] . '.jpg');
|
||||
$small = xmlify($a->get_baseurl() . '/photo/custom/50/' . $profile['uid'] . '.jpg');
|
||||
$searchable = xmlify((($profile['publish'] && $profile['net-publish']) ? 'true' : 'false' ));
|
||||
// $searchable = 'true';
|
||||
|
||||
if($searchable === 'true') {
|
||||
$dob = '1000-00-00';
|
||||
|
||||
if(($profile['dob']) && ($profile['dob'] != '0000-00-00'))
|
||||
$dob = ((intval($profile['dob'])) ? intval($profile['dob']) : '1000') . '-' . datetime_convert('UTC','UTC',$profile['dob'],'m-d');
|
||||
$gender = xmlify($profile['gender']);
|
||||
$about = xmlify($profile['about']);
|
||||
require_once('include/bbcode.php');
|
||||
$about = xmlify(strip_tags(bbcode($about)));
|
||||
$location = formatted_location($profile);
|
||||
$location = xmlify($location);
|
||||
$tags = '';
|
||||
if($profile['pub_keywords']) {
|
||||
$kw = str_replace(',',' ',$profile['pub_keywords']);
|
||||
$kw = str_replace(' ',' ',$kw);
|
||||
$arr = explode(' ',$profile['pub_keywords']);
|
||||
if(count($arr)) {
|
||||
for($x = 0; $x < 5; $x ++) {
|
||||
if(trim($arr[$x]))
|
||||
$tags .= '#' . trim($arr[$x]) . ' ';
|
||||
}
|
||||
}
|
||||
}
|
||||
$tags = xmlify(trim($tags));
|
||||
}
|
||||
|
||||
$tpl = get_markup_template('diaspora_profile.tpl');
|
||||
|
||||
$msg = replace_macros($tpl,array(
|
||||
'$handle' => $handle,
|
||||
'$first' => $first,
|
||||
'$last' => $last,
|
||||
'$large' => $large,
|
||||
'$medium' => $medium,
|
||||
'$small' => $small,
|
||||
'$dob' => $dob,
|
||||
'$gender' => $gender,
|
||||
'$about' => $about,
|
||||
'$location' => $location,
|
||||
'$searchable' => $searchable,
|
||||
'$tags' => $tags
|
||||
));
|
||||
logger('profile_change: ' . $msg, LOGGER_ALL);
|
||||
|
||||
foreach($recips as $recip) {
|
||||
$msgtosend = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$a->user,$recip,$a->user['prvkey'],$recip['pubkey'],false)));
|
||||
add_to_queue($recip['id'],NETWORK_DIASPORA,$msgtosend,false);
|
||||
}
|
||||
diaspora::send_profile(local_user());
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ function handle_pubsubhubbub() {
|
|||
|
||||
logger("Generate feed for user ".$rr['nickname']." - last updated ".$rr['last_update'], LOGGER_DEBUG);
|
||||
|
||||
$params = ostatus_feed($a, $rr['nickname'], $rr['last_update']);
|
||||
$params = ostatus::feed($a, $rr['nickname'], $rr['last_update']);
|
||||
$hmac_sig = hash_hmac("sha1", $params, $rr['secret']);
|
||||
|
||||
$headers = array("Content-type: application/atom+xml",
|
||||
|
@ -74,25 +74,14 @@ function pubsubpublish_run(&$argv, &$argc){
|
|||
};
|
||||
|
||||
require_once('include/items.php');
|
||||
require_once('include/pidfile.php');
|
||||
|
||||
load_config('config');
|
||||
load_config('system');
|
||||
|
||||
$lockpath = get_lockpath();
|
||||
if ($lockpath != '') {
|
||||
$pidfile = new pidfile($lockpath, 'pubsubpublish');
|
||||
if($pidfile->is_already_running()) {
|
||||
logger("Already running");
|
||||
if ($pidfile->running_time() > 9*60) {
|
||||
$pidfile->kill();
|
||||
logger("killed stale process");
|
||||
// Calling a new instance
|
||||
proc_run('php',"include/pubsubpublish.php");
|
||||
}
|
||||
// Don't check this stuff if the function is called by the poller
|
||||
if (App::callstack() != "poller_run")
|
||||
if (App::is_already_running("pubsubpublish", "include/pubsubpublish.php", 540))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$a->set_baseurl(get_config('system','url'));
|
||||
|
||||
|
|
|
@ -22,26 +22,15 @@ function queue_run(&$argv, &$argc){
|
|||
require_once("include/datetime.php");
|
||||
require_once('include/items.php');
|
||||
require_once('include/bbcode.php');
|
||||
require_once('include/pidfile.php');
|
||||
require_once('include/socgraph.php');
|
||||
|
||||
load_config('config');
|
||||
load_config('system');
|
||||
|
||||
$lockpath = get_lockpath();
|
||||
if ($lockpath != '') {
|
||||
$pidfile = new pidfile($lockpath, 'queue');
|
||||
if($pidfile->is_already_running()) {
|
||||
logger("queue: Already running");
|
||||
if ($pidfile->running_time() > 9*60) {
|
||||
$pidfile->kill();
|
||||
logger("queue: killed stale process");
|
||||
// Calling a new instance
|
||||
proc_run('php',"include/queue.php");
|
||||
}
|
||||
// Don't check this stuff if the function is called by the poller
|
||||
if (App::callstack() != "poller_run")
|
||||
if (App::is_already_running('queue', 'include/queue.php', 540))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$a->set_baseurl(get_config('system','url'));
|
||||
|
||||
|
@ -204,7 +193,7 @@ function queue_run(&$argv, &$argc){
|
|||
case NETWORK_DIASPORA:
|
||||
if($contact['notify']) {
|
||||
logger('queue: diaspora_delivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>');
|
||||
$deliver_status = diaspora_transmit($owner,$contact,$data,$public,true);
|
||||
$deliver_status = diaspora::transmit($owner,$contact,$data,$public,true);
|
||||
|
||||
if($deliver_status == (-1)) {
|
||||
update_queue_time($q_item['id']);
|
||||
|
|
|
@ -69,7 +69,6 @@ function ref_session_destroy ($id) {
|
|||
if(! function_exists('ref_session_gc')) {
|
||||
function ref_session_gc($expire) {
|
||||
q("DELETE FROM `session` WHERE `expire` < %d", dbesc(time()));
|
||||
q("OPTIMIZE TABLE `sess_data`");
|
||||
return true;
|
||||
}}
|
||||
|
||||
|
|
|
@ -10,7 +10,8 @@
|
|||
require_once('include/datetime.php');
|
||||
require_once("include/Scrape.php");
|
||||
require_once("include/html2bbcode.php");
|
||||
|
||||
require_once("include/Contact.php");
|
||||
require_once("include/Photo.php");
|
||||
|
||||
/*
|
||||
* poco_load
|
||||
|
@ -139,15 +140,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);
|
||||
|
||||
|
@ -427,7 +429,7 @@ function poco_last_updated($profile, $force = false) {
|
|||
if (($gcontacts[0]["server_url"] != "") AND ($gcontacts[0]["nick"] != "")) {
|
||||
|
||||
// Use noscrape if possible
|
||||
$server = q("SELECT `noscrape` FROM `gserver` WHERE `nurl` = '%s' AND `noscrape` != ''", dbesc(normalise_link($gcontacts[0]["server_url"])));
|
||||
$server = q("SELECT `noscrape`, `network` FROM `gserver` WHERE `nurl` = '%s' AND `noscrape` != ''", dbesc(normalise_link($gcontacts[0]["server_url"])));
|
||||
|
||||
if ($server) {
|
||||
$noscraperet = z_fetch_url($server[0]["noscrape"]."/".$gcontacts[0]["nick"]);
|
||||
|
@ -436,69 +438,47 @@ function poco_last_updated($profile, $force = false) {
|
|||
|
||||
$noscrape = json_decode($noscraperet["body"], true);
|
||||
|
||||
if (($noscrape["fn"] != "") AND ($noscrape["fn"] != $gcontacts[0]["name"]))
|
||||
q("UPDATE `gcontact` SET `name` = '%s' WHERE `nurl` = '%s'",
|
||||
dbesc($noscrape["fn"]), dbesc(normalise_link($profile)));
|
||||
if (is_array($noscrape)) {
|
||||
$contact = array("url" => $profile,
|
||||
"network" => $server[0]["network"],
|
||||
"generation" => $gcontacts[0]["generation"]);
|
||||
|
||||
if (($noscrape["photo"] != "") AND ($noscrape["photo"] != $gcontacts[0]["photo"]))
|
||||
q("UPDATE `gcontact` SET `photo` = '%s' WHERE `nurl` = '%s'",
|
||||
dbesc($noscrape["photo"]), dbesc(normalise_link($profile)));
|
||||
$contact["name"] = $noscrape["fn"];
|
||||
$contact["community"] = $noscrape["comm"];
|
||||
|
||||
if (($noscrape["updated"] != "") AND ($noscrape["updated"] != $gcontacts[0]["updated"]))
|
||||
q("UPDATE `gcontact` SET `updated` = '%s' WHERE `nurl` = '%s'",
|
||||
dbesc($noscrape["updated"]), dbesc(normalise_link($profile)));
|
||||
if (isset($noscrape["tags"])) {
|
||||
$keywords = implode(" ", $noscrape["tags"]);
|
||||
if ($keywords != "")
|
||||
$contact["keywords"] = $keywords;
|
||||
}
|
||||
|
||||
if (($noscrape["gender"] != "") AND ($noscrape["gender"] != $gcontacts[0]["gender"]))
|
||||
q("UPDATE `gcontact` SET `gender` = '%s' WHERE `nurl` = '%s'",
|
||||
dbesc($noscrape["gender"]), dbesc(normalise_link($profile)));
|
||||
$location = formatted_location($noscrape);
|
||||
if ($location)
|
||||
$contact["location"] = $location;
|
||||
|
||||
if (($noscrape["pdesc"] != "") AND ($noscrape["pdesc"] != $gcontacts[0]["about"]))
|
||||
q("UPDATE `gcontact` SET `about` = '%s' WHERE `nurl` = '%s'",
|
||||
dbesc($noscrape["pdesc"]), dbesc(normalise_link($profile)));
|
||||
$contact["notify"] = $noscrape["dfrn-notify"];
|
||||
|
||||
if (($noscrape["about"] != "") AND ($noscrape["about"] != $gcontacts[0]["about"]))
|
||||
q("UPDATE `gcontact` SET `about` = '%s' WHERE `nurl` = '%s'",
|
||||
dbesc($noscrape["about"]), dbesc(normalise_link($profile)));
|
||||
// Remove all fields that are not present in the gcontact table
|
||||
unset($noscrape["fn"]);
|
||||
unset($noscrape["key"]);
|
||||
unset($noscrape["homepage"]);
|
||||
unset($noscrape["comm"]);
|
||||
unset($noscrape["tags"]);
|
||||
unset($noscrape["locality"]);
|
||||
unset($noscrape["region"]);
|
||||
unset($noscrape["country-name"]);
|
||||
unset($noscrape["contacts"]);
|
||||
unset($noscrape["dfrn-request"]);
|
||||
unset($noscrape["dfrn-confirm"]);
|
||||
unset($noscrape["dfrn-notify"]);
|
||||
unset($noscrape["dfrn-poll"]);
|
||||
|
||||
if (isset($noscrape["comm"]) AND ($noscrape["comm"] != $gcontacts[0]["community"]))
|
||||
q("UPDATE `gcontact` SET `community` = %d WHERE `nurl` = '%s'",
|
||||
intval($noscrape["comm"]), dbesc(normalise_link($profile)));
|
||||
$contact = array_merge($contact, $noscrape);
|
||||
|
||||
if (isset($noscrape["tags"]))
|
||||
$keywords = implode(" ", $noscrape["tags"]);
|
||||
else
|
||||
$keywords = "";
|
||||
update_gcontact($contact);
|
||||
|
||||
if (($keywords != "") AND ($keywords != $gcontacts[0]["keywords"]))
|
||||
q("UPDATE `gcontact` SET `keywords` = '%s' WHERE `nurl` = '%s'",
|
||||
dbesc($keywords), dbesc(normalise_link($profile)));
|
||||
|
||||
$location = $noscrape["locality"];
|
||||
|
||||
if ($noscrape["region"] != "") {
|
||||
if ($location != "")
|
||||
$location .= ", ";
|
||||
|
||||
$location .= $noscrape["region"];
|
||||
return $noscrape["updated"];
|
||||
}
|
||||
|
||||
if ($noscrape["country-name"] != "") {
|
||||
if ($location != "")
|
||||
$location .= ", ";
|
||||
|
||||
$location .= $noscrape["country-name"];
|
||||
}
|
||||
|
||||
if (($location != "") AND ($location != $gcontacts[0]["location"]))
|
||||
q("UPDATE `gcontact` SET `location` = '%s' WHERE `nurl` = '%s'",
|
||||
dbesc($location), dbesc(normalise_link($profile)));
|
||||
|
||||
// If we got data from noscrape then mark the contact as reachable
|
||||
if (is_array($noscrape) AND count($noscrape))
|
||||
q("UPDATE `gcontact` SET `last_contact` = '%s' WHERE `nurl` = '%s'",
|
||||
dbesc(datetime_convert()), dbesc(normalise_link($profile)));
|
||||
|
||||
return $noscrape["updated"];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -533,25 +513,22 @@ function poco_last_updated($profile, $force = false) {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (($data["name"] != "") AND ($data["name"] != $gcontacts[0]["name"]))
|
||||
q("UPDATE `gcontact` SET `name` = '%s' WHERE `nurl` = '%s'",
|
||||
dbesc($data["name"]), dbesc(normalise_link($profile)));
|
||||
$contact = array("generation" => $gcontacts[0]["generation"]);
|
||||
|
||||
if (($data["nick"] != "") AND ($data["nick"] != $gcontacts[0]["nick"]))
|
||||
q("UPDATE `gcontact` SET `nick` = '%s' WHERE `nurl` = '%s'",
|
||||
dbesc($data["nick"]), dbesc(normalise_link($profile)));
|
||||
$contact = array_merge($contact, $data);
|
||||
|
||||
if (($data["addr"] != "") AND ($data["addr"] != $gcontacts[0]["connect"]))
|
||||
q("UPDATE `gcontact` SET `connect` = '%s' WHERE `nurl` = '%s'",
|
||||
dbesc($data["addr"]), dbesc(normalise_link($profile)));
|
||||
$contact["server_url"] = $data["baseurl"];
|
||||
|
||||
if (($data["photo"] != "") AND ($data["photo"] != $gcontacts[0]["photo"]))
|
||||
q("UPDATE `gcontact` SET `photo` = '%s' WHERE `nurl` = '%s'",
|
||||
dbesc($data["photo"]), dbesc(normalise_link($profile)));
|
||||
unset($contact["batch"]);
|
||||
unset($contact["poll"]);
|
||||
unset($contact["request"]);
|
||||
unset($contact["confirm"]);
|
||||
unset($contact["poco"]);
|
||||
unset($contact["priority"]);
|
||||
unset($contact["pubkey"]);
|
||||
unset($contact["baseurl"]);
|
||||
|
||||
if (($data["baseurl"] != "") AND ($data["baseurl"] != $gcontacts[0]["server_url"]))
|
||||
q("UPDATE `gcontact` SET `server_url` = '%s' WHERE `nurl` = '%s'",
|
||||
dbesc($data["baseurl"]), dbesc(normalise_link($profile)));
|
||||
update_gcontact($contact);
|
||||
|
||||
$feedret = z_fetch_url($data["poll"]);
|
||||
|
||||
|
@ -745,7 +722,8 @@ function poco_check_server($server_url, $network = "", $force = false) {
|
|||
// Will also return data for Friendica and GNU Social - but it will be overwritten later
|
||||
// The "not implemented" is a special treatment for really, really old Friendica versions
|
||||
$serverret = z_fetch_url($server_url."/api/statusnet/version.json");
|
||||
if ($serverret["success"] AND ($serverret["body"] != '{"error":"not implemented"}') AND ($serverret["body"] != '') AND (strlen($serverret["body"]) < 250)) {
|
||||
if ($serverret["success"] AND ($serverret["body"] != '{"error":"not implemented"}') AND
|
||||
($serverret["body"] != '') AND (strlen($serverret["body"]) < 30)) {
|
||||
$platform = "StatusNet";
|
||||
$version = trim($serverret["body"], '"');
|
||||
$network = NETWORK_OSTATUS;
|
||||
|
@ -753,7 +731,8 @@ function poco_check_server($server_url, $network = "", $force = false) {
|
|||
|
||||
// Test for GNU Social
|
||||
$serverret = z_fetch_url($server_url."/api/gnusocial/version.json");
|
||||
if ($serverret["success"] AND ($serverret["body"] != '{"error":"not implemented"}') AND ($serverret["body"] != '') AND (strlen($serverret["body"]) < 250)) {
|
||||
if ($serverret["success"] AND ($serverret["body"] != '{"error":"not implemented"}') AND
|
||||
($serverret["body"] != '') AND (strlen($serverret["body"]) < 30)) {
|
||||
$platform = "GNU Social";
|
||||
$version = trim($serverret["body"], '"');
|
||||
$network = NETWORK_OSTATUS;
|
||||
|
@ -880,6 +859,11 @@ function poco_check_server($server_url, $network = "", $force = false) {
|
|||
// Check again if the server exists
|
||||
$servers = q("SELECT `nurl` FROM `gserver` WHERE `nurl` = '%s'", dbesc(normalise_link($server_url)));
|
||||
|
||||
$version = strip_tags($version);
|
||||
$site_name = strip_tags($site_name);
|
||||
$info = strip_tags($info);
|
||||
$platform = strip_tags($platform);
|
||||
|
||||
if ($servers)
|
||||
q("UPDATE `gserver` SET `url` = '%s', `version` = '%s', `site_name` = '%s', `info` = '%s', `register_policy` = %d, `poco` = '%s', `noscrape` = '%s',
|
||||
`network` = '%s', `platform` = '%s', `last_contact` = '%s', `last_failure` = '%s' WHERE `nurl` = '%s'",
|
||||
|
@ -920,88 +904,6 @@ function poco_check_server($server_url, $network = "", $force = false) {
|
|||
return !$failure;
|
||||
}
|
||||
|
||||
function poco_contact_from_body($body, $created, $cid, $uid) {
|
||||
preg_replace_callback("/\[share(.*?)\].*?\[\/share\]/ism",
|
||||
function ($match) use ($created, $cid, $uid){
|
||||
return(sub_poco_from_share($match, $created, $cid, $uid));
|
||||
}, $body);
|
||||
}
|
||||
|
||||
function sub_poco_from_share($share, $created, $cid, $uid) {
|
||||
$profile = "";
|
||||
preg_match("/profile='(.*?)'/ism", $share[1], $matches);
|
||||
if ($matches[1] != "")
|
||||
$profile = $matches[1];
|
||||
|
||||
preg_match('/profile="(.*?)"/ism', $share[1], $matches);
|
||||
if ($matches[1] != "")
|
||||
$profile = $matches[1];
|
||||
|
||||
if ($profile == "")
|
||||
return;
|
||||
|
||||
logger("prepare poco_check for profile ".$profile, LOGGER_DEBUG);
|
||||
poco_check($profile, "", "", "", "", "", "", "", "", $created, 3, $cid, $uid);
|
||||
}
|
||||
|
||||
function poco_store($item) {
|
||||
|
||||
// Isn't it public?
|
||||
if ($item['private'])
|
||||
return;
|
||||
|
||||
// Or is it from a network where we don't store the global contacts?
|
||||
if (!in_array($item["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS, NETWORK_STATUSNET, "")))
|
||||
return;
|
||||
|
||||
// Is it a global copy?
|
||||
$store_gcontact = ($item["uid"] == 0);
|
||||
|
||||
// Is it a comment on a global copy?
|
||||
if (!$store_gcontact AND ($item["uri"] != $item["parent-uri"])) {
|
||||
$q = q("SELECT `id` FROM `item` WHERE `uri`='%s' AND `uid` = 0", $item["parent-uri"]);
|
||||
$store_gcontact = count($q);
|
||||
}
|
||||
|
||||
if (!$store_gcontact)
|
||||
return;
|
||||
|
||||
// "3" means: We don't know this contact directly (Maybe a reshared item)
|
||||
$generation = 3;
|
||||
$network = "";
|
||||
$profile_url = $item["author-link"];
|
||||
|
||||
// Is it a user from our server?
|
||||
$q = q("SELECT `id` FROM `contact` WHERE `self` AND `nurl` = '%s' LIMIT 1",
|
||||
dbesc(normalise_link($item["author-link"])));
|
||||
if (count($q)) {
|
||||
logger("Our user (generation 1): ".$item["author-link"], LOGGER_DEBUG);
|
||||
$generation = 1;
|
||||
$network = NETWORK_DFRN;
|
||||
} else { // Is it a contact from a user on our server?
|
||||
$q = q("SELECT `network`, `url` FROM `contact` WHERE `uid` != 0 AND `network` != ''
|
||||
AND (`nurl` = '%s' OR `alias` IN ('%s', '%s')) AND `network` != '%s' LIMIT 1",
|
||||
dbesc(normalise_link($item["author-link"])),
|
||||
dbesc(normalise_link($item["author-link"])),
|
||||
dbesc($item["author-link"]),
|
||||
dbesc(NETWORK_STATUSNET));
|
||||
if (count($q)) {
|
||||
$generation = 2;
|
||||
$network = $q[0]["network"];
|
||||
$profile_url = $q[0]["url"];
|
||||
logger("Known contact (generation 2): ".$profile_url, LOGGER_DEBUG);
|
||||
}
|
||||
}
|
||||
|
||||
if ($generation == 3)
|
||||
logger("Unknown contact (generation 3): ".$item["author-link"], LOGGER_DEBUG);
|
||||
|
||||
poco_check($profile_url, $item["author-name"], $network, $item["author-avatar"], "", "", "", "", "", $item["received"], $generation, $item["contact-id"], $item["uid"]);
|
||||
|
||||
// Maybe its a body with a shared item? Then extract a global contact from it.
|
||||
poco_contact_from_body($item["body"], $item["received"], $item["contact-id"], $item["uid"]);
|
||||
}
|
||||
|
||||
function count_common_friends($uid,$cid) {
|
||||
|
||||
$r = q("SELECT count(*) as `total`
|
||||
|
@ -1530,9 +1432,17 @@ function update_gcontact($contact) {
|
|||
unset($fields["url"]);
|
||||
unset($fields["updated"]);
|
||||
|
||||
// Bugfix: We had an error in the storing of keywords which lead to the "0"
|
||||
// This value is still transmitted via poco.
|
||||
if ($contact["keywords"] == "0")
|
||||
unset($contact["keywords"]);
|
||||
|
||||
if ($r[0]["keywords"] == "0")
|
||||
$r[0]["keywords"] = "";
|
||||
|
||||
// assign all unassigned fields from the database entry
|
||||
foreach ($fields AS $field => $data)
|
||||
if (!isset($contact[$field]))
|
||||
if (!isset($contact[$field]) OR ($contact[$field] == ""))
|
||||
$contact[$field] = $r[0][$field];
|
||||
|
||||
if ($contact["network"] == NETWORK_STATUSNET)
|
||||
|
@ -1541,20 +1451,50 @@ function update_gcontact($contact) {
|
|||
if (!isset($contact["updated"]))
|
||||
$contact["updated"] = datetime_convert();
|
||||
|
||||
if ($contact["server_url"] == "") {
|
||||
$server_url = $contact["url"];
|
||||
|
||||
$server_url = matching_url($server_url, $contact["alias"]);
|
||||
if ($server_url != "")
|
||||
$contact["server_url"] = $server_url;
|
||||
|
||||
$server_url = matching_url($server_url, $contact["photo"]);
|
||||
if ($server_url != "")
|
||||
$contact["server_url"] = $server_url;
|
||||
|
||||
$server_url = matching_url($server_url, $contact["notify"]);
|
||||
if ($server_url != "")
|
||||
$contact["server_url"] = $server_url;
|
||||
} else
|
||||
$contact["server_url"] = normalise_link($contact["server_url"]);
|
||||
|
||||
if (($contact["addr"] == "") AND ($contact["server_url"] != "") AND ($contact["nick"] != "")) {
|
||||
$hostname = str_replace("http://", "", $contact["server_url"]);
|
||||
$contact["addr"] = $contact["nick"]."@".$hostname;
|
||||
}
|
||||
|
||||
// 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"] > 0) AND ($contact["generation"] <= $r[0]["generation"])) OR ($r[0]["generation"] == 0)) {
|
||||
foreach ($fields AS $field => $data)
|
||||
if ($contact[$field] != $r[0][$field]) {
|
||||
logger("Difference for contact ".$contact["url"]." in field '".$field."'. New value: '".$contact[$field]."', old value '".$r[0][$field]."'", LOGGER_DEBUG);
|
||||
$update = true;
|
||||
}
|
||||
|
||||
if ($contact["generation"] < $r[0]["generation"])
|
||||
$update = true;
|
||||
if ($contact["generation"] < $r[0]["generation"]) {
|
||||
logger("Difference for contact ".$contact["url"]." in field 'generation'. new value: '".$contact["generation"]."', old value '".$r[0]["generation"]."'", LOGGER_DEBUG);
|
||||
$update = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($update) {
|
||||
logger("Update gcontact for ".$contact["url"]." Callstack: ".App::callstack(), LOGGER_DEBUG);
|
||||
|
||||
q("UPDATE `gcontact` SET `photo` = '%s', `name` = '%s', `nick` = '%s', `addr` = '%s', `network` = '%s',
|
||||
`birthday` = '%s', `gender` = '%s', `keywords` = %d, `hide` = %d, `nsfw` = %d,
|
||||
`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'
|
||||
|
@ -1567,6 +1507,28 @@ function update_gcontact($contact) {
|
|||
intval($contact["generation"]), dbesc($contact["updated"]),
|
||||
dbesc($contact["server_url"]), dbesc($contact["connect"]),
|
||||
dbesc(normalise_link($contact["url"])), intval($contact["generation"]));
|
||||
|
||||
|
||||
// Now update the contact entry with the user id "0" as well.
|
||||
// This is used for the shadow copies of public items.
|
||||
$r = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = 0 ORDER BY `id` LIMIT 1",
|
||||
dbesc(normalise_link($contact["url"])));
|
||||
|
||||
if ($r) {
|
||||
logger("Update shadow contact ".$r[0]["id"], LOGGER_DEBUG);
|
||||
|
||||
update_contact_avatar($contact["photo"], 0, $r[0]["id"]);
|
||||
|
||||
q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `addr` = '%s',
|
||||
`network` = '%s', `bd` = '%s', `gender` = '%s',
|
||||
`keywords` = '%s', `alias` = '%s', `url` = '%s',
|
||||
`location` = '%s', `about` = '%s'
|
||||
WHERE `id` = %d",
|
||||
dbesc($contact["name"]), dbesc($contact["nick"]), dbesc($contact["addr"]),
|
||||
dbesc($contact["network"]), dbesc($contact["birthday"]), dbesc($contact["gender"]),
|
||||
dbesc($contact["keywords"]), dbesc($contact["alias"]), dbesc($contact["url"]),
|
||||
dbesc($contact["location"]), dbesc($contact["about"]), intval($r[0]["id"]));
|
||||
}
|
||||
}
|
||||
|
||||
return $gcontact_id;
|
||||
|
@ -1580,8 +1542,10 @@ function update_gcontact($contact) {
|
|||
function update_gcontact_from_probe($url) {
|
||||
$data = probe_url($url);
|
||||
|
||||
if ($data["network"] != NETWORK_PHANTOM)
|
||||
update_gcontact($data);
|
||||
if ($data["network"] == NETWORK_PHANTOM)
|
||||
return;
|
||||
|
||||
update_gcontact($data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -23,7 +23,7 @@ function replace_macros($s,$r) {
|
|||
$a = get_app();
|
||||
|
||||
// pass $baseurl to all templates
|
||||
$r['$baseurl'] = z_root();
|
||||
$r['$baseurl'] = $a->get_baseurl();
|
||||
|
||||
|
||||
$t = $a->template_engine();
|
||||
|
@ -286,7 +286,7 @@ function paginate_data(&$a, $count=null) {
|
|||
if (($a->page_offset != "") AND !preg_match('/[?&].offset=/', $stripped))
|
||||
$stripped .= "&offset=".urlencode($a->page_offset);
|
||||
|
||||
$url = z_root() . '/' . $stripped;
|
||||
$url = $stripped;
|
||||
|
||||
$data = array();
|
||||
function _l(&$d, $name, $url, $text, $class="") {
|
||||
|
@ -924,7 +924,7 @@ function micropro($contact, $redirect = false, $class = '', $textmode = false) {
|
|||
|
||||
if($redirect) {
|
||||
$a = get_app();
|
||||
$redirect_url = z_root() . '/redir/' . $contact['id'];
|
||||
$redirect_url = 'redir/' . $contact['id'];
|
||||
if(local_user() && ($contact['uid'] == local_user()) && ($contact['network'] === NETWORK_DFRN)) {
|
||||
$redir = true;
|
||||
$url = $redirect_url;
|
||||
|
@ -965,13 +965,13 @@ if(! function_exists('search')) {
|
|||
* @param string $url search url
|
||||
* @param boolean $savedsearch show save search button
|
||||
*/
|
||||
function search($s,$id='search-box',$url='/search',$save = false, $aside = true) {
|
||||
function search($s,$id='search-box',$url='search',$save = false, $aside = true) {
|
||||
$a = get_app();
|
||||
|
||||
$values = array(
|
||||
'$s' => $s,
|
||||
'$id' => $id,
|
||||
'$action_url' => $a->get_baseurl((stristr($url,'network')) ? true : false) . $url,
|
||||
'$action_url' => $url,
|
||||
'$search_label' => t('Search'),
|
||||
'$save_label' => t('Save'),
|
||||
'$savedsearch' => feature_enabled(local_user(),'savedsearch'),
|
||||
|
@ -1152,7 +1152,7 @@ function redir_private_images($a, &$item) {
|
|||
|
||||
if((local_user() == $item['uid']) && ($item['private'] != 0) && ($item['contact-id'] != $a->contact['id']) && ($item['network'] == NETWORK_DFRN)) {
|
||||
//logger("redir_private_images: redir");
|
||||
$img_url = z_root() . '/redir?f=1&quiet=1&url=' . $mtch[1] . '&conurl=' . $item['author-link'];
|
||||
$img_url = 'redir?f=1&quiet=1&url=' . $mtch[1] . '&conurl=' . $item['author-link'];
|
||||
$item['body'] = str_replace($mtch[0], "[img]".$img_url."[/img]", $item['body']);
|
||||
}
|
||||
}
|
||||
|
@ -1268,7 +1268,7 @@ function prepare_body(&$item,$attach = false, $preview = false) {
|
|||
$mime = $mtch[3];
|
||||
|
||||
if((local_user() == $item['uid']) && ($item['contact-id'] != $a->contact['id']) && ($item['network'] == NETWORK_DFRN))
|
||||
$the_url = z_root() . '/redir/' . $item['contact-id'] . '?f=1&url=' . $mtch[1];
|
||||
$the_url = 'redir/' . $item['contact-id'] . '?f=1&url=' . $mtch[1];
|
||||
else
|
||||
$the_url = $mtch[1];
|
||||
|
||||
|
@ -1443,7 +1443,7 @@ function get_cats_and_terms($item) {
|
|||
$categories[] = array(
|
||||
'name' => xmlify(file_tag_decode($mtch[1])),
|
||||
'url' => "#",
|
||||
'removeurl' => ((local_user() == $item['uid'])?z_root() . '/filerm/' . $item['id'] . '?f=&cat=' . xmlify(file_tag_decode($mtch[1])):""),
|
||||
'removeurl' => ((local_user() == $item['uid'])?'filerm/' . $item['id'] . '?f=&cat=' . xmlify(file_tag_decode($mtch[1])):""),
|
||||
'first' => $first,
|
||||
'last' => false
|
||||
);
|
||||
|
@ -1461,7 +1461,7 @@ function get_cats_and_terms($item) {
|
|||
$folders[] = array(
|
||||
'name' => xmlify(file_tag_decode($mtch[1])),
|
||||
'url' => "#",
|
||||
'removeurl' => ((local_user() == $item['uid'])?z_root() . '/filerm/' . $item['id'] . '?f=&term=' . xmlify(file_tag_decode($mtch[1])):""),
|
||||
'removeurl' => ((local_user() == $item['uid'])?'filerm/' . $item['id'] . '?f=&term=' . xmlify(file_tag_decode($mtch[1])):""),
|
||||
'first' => $first,
|
||||
'last' => false
|
||||
);
|
||||
|
@ -1486,15 +1486,15 @@ function get_plink($item) {
|
|||
|
||||
if ($a->user['nickname'] != "") {
|
||||
$ret = array(
|
||||
//'href' => z_root()."/display/".$a->user['nickname']."/".$item['id'],
|
||||
'href' => z_root()."/display/".$item['guid'],
|
||||
'orig' => z_root()."/display/".$item['guid'],
|
||||
//'href' => "display/".$a->user['nickname']."/".$item['id'],
|
||||
'href' => "display/".$item['guid'],
|
||||
'orig' => "display/".$item['guid'],
|
||||
'title' => t('View on separate page'),
|
||||
'orig_title' => t('view on separate page'),
|
||||
);
|
||||
|
||||
if (x($item,'plink')) {
|
||||
$ret["href"] = $item['plink'];
|
||||
$ret["href"] = $a->remove_baseurl($item['plink']);
|
||||
$ret["title"] = t('link to source');
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@ function update_gcontact_run(&$argv, &$argc){
|
|||
unset($db_host, $db_user, $db_pass, $db_data);
|
||||
};
|
||||
|
||||
require_once('include/pidfile.php');
|
||||
require_once('include/Scrape.php');
|
||||
require_once("include/socgraph.php");
|
||||
|
||||
|
@ -37,18 +36,10 @@ function update_gcontact_run(&$argv, &$argc){
|
|||
return;
|
||||
}
|
||||
|
||||
$lockpath = get_lockpath();
|
||||
if ($lockpath != '') {
|
||||
$pidfile = new pidfile($lockpath, 'update_gcontact'.$contact_id);
|
||||
if ($pidfile->is_already_running()) {
|
||||
logger("update_gcontact: Already running for contact ".$contact_id);
|
||||
if ($pidfile->running_time() > 9*60) {
|
||||
$pidfile->kill();
|
||||
logger("killed stale process");
|
||||
}
|
||||
exit;
|
||||
}
|
||||
}
|
||||
// Don't check this stuff if the function is called by the poller
|
||||
if (App::callstack() != "poller_run")
|
||||
if (App::is_already_running('update_gcontact'.$contact_id, '', 540))
|
||||
return;
|
||||
|
||||
$r = q("SELECT * FROM `gcontact` WHERE `id` = %d", intval($contact_id));
|
||||
|
||||
|
|
131
include/xml.php
Normal file
131
include/xml.php
Normal file
|
@ -0,0 +1,131 @@
|
|||
<?php
|
||||
/**
|
||||
* @file include/xml.php
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief This class contain functions to work with XML data
|
||||
*
|
||||
*/
|
||||
class xml {
|
||||
/**
|
||||
* @brief Creates an XML structure out of a given array
|
||||
*
|
||||
* @param array $array The array of the XML structure that will be generated
|
||||
* @param object $xml The createdXML will be returned by reference
|
||||
* @param bool $remove_header Should the XML header be removed or not?
|
||||
* @param array $namespaces List of namespaces
|
||||
* @param bool $root - interally used parameter. Mustn't be used from outside.
|
||||
*
|
||||
* @return string The created XML
|
||||
*/
|
||||
public static function from_array($array, &$xml, $remove_header = false, $namespaces = array(), $root = true) {
|
||||
|
||||
if ($root) {
|
||||
foreach($array as $key => $value) {
|
||||
foreach ($namespaces AS $nskey => $nsvalue)
|
||||
$key .= " xmlns".($nskey == "" ? "":":").$nskey.'="'.$nsvalue.'"';
|
||||
|
||||
$root = new SimpleXMLElement("<".$key."/>");
|
||||
self::from_array($value, $root, $remove_header, $namespaces, false);
|
||||
|
||||
$dom = dom_import_simplexml($root)->ownerDocument;
|
||||
$dom->formatOutput = true;
|
||||
$xml = $dom;
|
||||
|
||||
$xml_text = $dom->saveXML();
|
||||
|
||||
if ($remove_header)
|
||||
$xml_text = trim(substr($xml_text, 21));
|
||||
|
||||
return $xml_text;
|
||||
}
|
||||
}
|
||||
|
||||
foreach($array as $key => $value) {
|
||||
if ($key == "@attributes") {
|
||||
if (!isset($element) OR !is_array($value))
|
||||
continue;
|
||||
|
||||
foreach ($value as $attr_key => $attr_value) {
|
||||
$element_parts = explode(":", $attr_key);
|
||||
if ((count($element_parts) > 1) AND isset($namespaces[$element_parts[0]]))
|
||||
$namespace = $namespaces[$element_parts[0]];
|
||||
else
|
||||
$namespace = NULL;
|
||||
|
||||
$element->addAttribute ($attr_key, $attr_value, $namespace);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$element_parts = explode(":", $key);
|
||||
if ((count($element_parts) > 1) AND isset($namespaces[$element_parts[0]]))
|
||||
$namespace = $namespaces[$element_parts[0]];
|
||||
else
|
||||
$namespace = NULL;
|
||||
|
||||
if (!is_array($value))
|
||||
$element = $xml->addChild($key, xmlify($value), $namespace);
|
||||
elseif (is_array($value)) {
|
||||
$element = $xml->addChild($key, NULL, $namespace);
|
||||
self::from_array($value, $element, $remove_header, $namespaces, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Copies an XML object
|
||||
*
|
||||
* @param object $source The XML source
|
||||
* @param object $target The XML target
|
||||
* @param string $elementname Name of the XML element of the target
|
||||
*/
|
||||
public static function copy(&$source, &$target, $elementname) {
|
||||
if (count($source->children()) == 0)
|
||||
$target->addChild($elementname, xmlify($source));
|
||||
else {
|
||||
$child = $target->addChild($elementname);
|
||||
foreach ($source->children() AS $childfield => $childentry)
|
||||
self::copy($childentry, $child, $childfield);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Create an XML element
|
||||
*
|
||||
* @param object $doc XML root
|
||||
* @param string $element XML element name
|
||||
* @param string $value XML value
|
||||
* @param array $attributes array containing the attributes
|
||||
*
|
||||
* @return object XML element object
|
||||
*/
|
||||
public static function create_element($doc, $element, $value = "", $attributes = array()) {
|
||||
$element = $doc->createElement($element, xmlify($value));
|
||||
|
||||
foreach ($attributes AS $key => $value) {
|
||||
$attribute = $doc->createAttribute($key);
|
||||
$attribute->value = xmlify($value);
|
||||
$element->appendChild($attribute);
|
||||
}
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Create an XML and append it to the parent object
|
||||
*
|
||||
* @param object $doc XML root
|
||||
* @param object $parent parent object
|
||||
* @param string $element XML element name
|
||||
* @param string $value XML value
|
||||
* @param array $attributes array containing the attributes
|
||||
*/
|
||||
public static function add_element($doc, $parent, $element, $value = "", $attributes = array()) {
|
||||
$element = self::create_element($doc, $element, $value, $attributes);
|
||||
$parent->appendChild($element);
|
||||
}
|
||||
}
|
||||
?>
|
18
index.php
18
index.php
|
@ -72,7 +72,8 @@ if(!$install) {
|
|||
(intval(get_config('system','ssl_policy')) == SSL_POLICY_FULL) AND
|
||||
(substr($a->get_baseurl(), 0, 8) == "https://")) {
|
||||
header("HTTP/1.1 302 Moved Temporarily");
|
||||
header("location: ".$a->get_baseurl()."/".$a->query_string);
|
||||
header("Location: ".$a->get_baseurl()."/".$a->query_string);
|
||||
exit();
|
||||
}
|
||||
|
||||
require_once("include/session.php");
|
||||
|
@ -371,7 +372,7 @@ $a->init_page_end();
|
|||
if(x($_SESSION,'visitor_home'))
|
||||
$homebase = $_SESSION['visitor_home'];
|
||||
elseif(local_user())
|
||||
$homebase = $a->get_baseurl() . '/profile/' . $a->user['nickname'];
|
||||
$homebase = 'profile/' . $a->user['nickname'];
|
||||
|
||||
if(isset($homebase))
|
||||
$a->page['content'] .= '<script>var homebase="' . $homebase . '" ; </script>';
|
||||
|
@ -407,15 +408,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
|
||||
|
@ -432,10 +424,10 @@ if($a->module != 'install' && $a->module != 'maintenance') {
|
|||
|
||||
if($a->is_mobile || $a->is_tablet) {
|
||||
if(isset($_SESSION['show-mobile']) && !$_SESSION['show-mobile']) {
|
||||
$link = $a->get_baseurl() . '/toggle_mobile?address=' . curPageURL();
|
||||
$link = 'toggle_mobile?address=' . curPageURL();
|
||||
}
|
||||
else {
|
||||
$link = $a->get_baseurl() . '/toggle_mobile?off=1&address=' . curPageURL();
|
||||
$link = 'toggle_mobile?off=1&address=' . curPageURL();
|
||||
}
|
||||
$a->page['footer'] = replace_macros(get_markup_template("toggle_mobile_footer.tpl"), array(
|
||||
'$toggle_link' => $link,
|
||||
|
|
215
js/acl.js
215
js/acl.js
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
@ -170,9 +170,8 @@
|
|||
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 nav-notivications-menu */
|
||||
$('#nav-notifications-menu').perfectScrollbar();
|
||||
$('aside').perfectScrollbar();
|
||||
/* enable perfect-scrollbars for different elements */
|
||||
$('#nav-notifications-menu, aside').perfectScrollbar();
|
||||
|
||||
/* nav update event */
|
||||
$('nav').bind('nav-update', function(e,data){
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -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 "
|
||||
}
|
||||
$final = rtrim($final, ', ');
|
||||
if ($final === '') return false;
|
||||
return $final;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -1,27 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Post-transform that performs validation to the name attribute; if
|
||||
* it is present with an equivalent id attribute, it is passed through;
|
||||
* otherwise validation is performed.
|
||||
*/
|
||||
class HTMLPurifier_AttrTransform_NameSync extends HTMLPurifier_AttrTransform
|
||||
{
|
||||
|
||||
public function __construct() {
|
||||
$this->idDef = new HTMLPurifier_AttrDef_HTML_ID();
|
||||
}
|
||||
|
||||
public function transform($attr, $config, $context) {
|
||||
if (!isset($attr['name'])) return $attr;
|
||||
$name = $attr['name'];
|
||||
if (isset($attr['id']) && $attr['id'] === $name) return $attr;
|
||||
$result = $this->idDef->validate($name, $config, $context);
|
||||
if ($result === false) unset($attr['name']);
|
||||
else $attr['name'] = $result;
|
||||
return $attr;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
|
@ -1,16 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Writes default type for all objects. Currently only supports flash.
|
||||
*/
|
||||
class HTMLPurifier_AttrTransform_SafeObject extends HTMLPurifier_AttrTransform
|
||||
{
|
||||
public $name = "SafeObject";
|
||||
|
||||
function transform($attr, $config, $context) {
|
||||
if (!isset($attr['type'])) $attr['type'] = 'application/x-shockwave-flash';
|
||||
return $attr;
|
||||
}
|
||||
}
|
||||
|
||||
// vim: et sw=4 sts=4
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue