Line endings are converted to unix style

This commit is contained in:
Michael 2018-02-09 03:49:49 +00:00
parent 164f4f7cdf
commit 15a857e411
35 changed files with 1484 additions and 1484 deletions

View file

@ -1,67 +1,67 @@
{ {
"name": "friendica/friendica", "name": "friendica/friendica",
"description": "A decentralized social network part of The Federation", "description": "A decentralized social network part of The Federation",
"type": "project", "type": "project",
"keywords": [ "keywords": [
"social network", "social network",
"dfrn", "dfrn",
"ostatus", "ostatus",
"diaspora" "diaspora"
], ],
"license": "AGPL-3.0+", "license": "AGPL-3.0+",
"support": { "support": {
"issues": "https://github.com/friendica/friendica/issues" "issues": "https://github.com/friendica/friendica/issues"
}, },
"require": { "require": {
"php": ">5.6", "php": ">5.6",
"ext-xml": "*", "ext-xml": "*",
"ezyang/htmlpurifier": "~4.7.0", "ezyang/htmlpurifier": "~4.7.0",
"league/html-to-markdown": "~4.4.1", "league/html-to-markdown": "~4.4.1",
"lightopenid/lightopenid": "dev-master", "lightopenid/lightopenid": "dev-master",
"michelf/php-markdown": "^1.7", "michelf/php-markdown": "^1.7",
"mobiledetect/mobiledetectlib": "2.8.*", "mobiledetect/mobiledetectlib": "2.8.*",
"paragonie/random_compat": "^2.0", "paragonie/random_compat": "^2.0",
"pear/Text_LanguageDetect": "1.*", "pear/Text_LanguageDetect": "1.*",
"pear/Text_Highlighter": "dev-master", "pear/Text_Highlighter": "dev-master",
"smarty/smarty": "^3.1", "smarty/smarty": "^3.1",
"fxp/composer-asset-plugin": "~1.3", "fxp/composer-asset-plugin": "~1.3",
"bower-asset/base64": "^1.0", "bower-asset/base64": "^1.0",
"bower-asset/Chart-js": "^2.7", "bower-asset/Chart-js": "^2.7",
"bower-asset/perfect-scrollbar": "^0.6", "bower-asset/perfect-scrollbar": "^0.6",
"npm-asset/jquery": "^2.0", "npm-asset/jquery": "^2.0",
"npm-asset/jquery-colorbox": "^1.6", "npm-asset/jquery-colorbox": "^1.6",
"npm-asset/jquery-datetimepicker": "^2.4.0", "npm-asset/jquery-datetimepicker": "^2.4.0",
"npm-asset/jgrowl": "^1.4", "npm-asset/jgrowl": "^1.4",
"npm-asset/fullcalendar": "^3.0.1" "npm-asset/fullcalendar": "^3.0.1"
}, },
"repositories": [ "repositories": [
{ {
"type": "vcs", "type": "vcs",
"url": "https://github.com/pear/Text_Highlighter" "url": "https://github.com/pear/Text_Highlighter"
} }
], ],
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"Friendica\\": "src/" "Friendica\\": "src/"
}, },
"psr-0": { "psr-0": {
"": "library/" "": "library/"
} }
}, },
"config": { "config": {
"autoloader-suffix": "Friendica", "autoloader-suffix": "Friendica",
"optimize-autoloader": true, "optimize-autoloader": true,
"preferred-install": "dist", "preferred-install": "dist",
"fxp-asset": { "fxp-asset": {
"installer-paths": { "installer-paths": {
"npm-asset-library": "vendor/asset", "npm-asset-library": "vendor/asset",
"bower-asset-library": "vendor/asset" "bower-asset-library": "vendor/asset"
} }
} }
}, },
"archive": { "archive": {
"exclude": [ "exclude": [
"log", "cache", "/photo", "/proxy" "log", "cache", "/photo", "/proxy"
] ]
} }
} }

View file

@ -1,60 +1,60 @@
<?php <?php
namespace Friendica; namespace Friendica;
/** /**
* All modules in Friendica should extend BaseModule, although not all modules * All modules in Friendica should extend BaseModule, although not all modules
* need to extend all the methods described here * need to extend all the methods described here
* *
* @author Hypolite Petovan mrpetovan@gmail.com * @author Hypolite Petovan mrpetovan@gmail.com
*/ */
abstract class BaseModule extends BaseObject abstract class BaseModule extends BaseObject
{ {
/** /**
* @brief Initialization method common to both content() and post() * @brief Initialization method common to both content() and post()
* *
* Extend this method if you need to do any shared processing before both * Extend this method if you need to do any shared processing before both
* content() or post() * content() or post()
*/ */
public static function init() public static function init()
{ {
} }
/** /**
* @brief Module GET method to display any content * @brief Module GET method to display any content
* *
* Extend this method if the module is supposed to return any display * Extend this method if the module is supposed to return any display
* through a GET request. It can be an HTML page through templating or a * through a GET request. It can be an HTML page through templating or a
* XML feed or a JSON output. * XML feed or a JSON output.
* *
* @return string * @return string
*/ */
public static function content() public static function content()
{ {
$o = ''; $o = '';
return $o; return $o;
} }
/** /**
* @brief Module POST method to process submitted data * @brief Module POST method to process submitted data
* *
* Extend this method if the module is supposed to process POST requests. * Extend this method if the module is supposed to process POST requests.
* Doesn't display any content * Doesn't display any content
*/ */
public static function post() public static function post()
{ {
// goaway('module'); // goaway('module');
} }
/** /**
* @brief Called after post() * @brief Called after post()
* *
* Unknown purpose * Unknown purpose
*/ */
public static function afterpost() public static function afterpost()
{ {
} }
} }

View file

@ -1,39 +1,39 @@
<?php <?php
/** /**
* @file src/Content/Text/Markdown.php * @file src/Content/Text/Markdown.php
*/ */
namespace Friendica\Content\Text; namespace Friendica\Content\Text;
use Friendica\BaseObject; use Friendica\BaseObject;
use Michelf\MarkdownExtra; use Michelf\MarkdownExtra;
/** /**
* Friendica-specific usage of Markdown * Friendica-specific usage of Markdown
* *
* @author Hypolite Petovan <mrpetovan@gmail.com> * @author Hypolite Petovan <mrpetovan@gmail.com>
*/ */
class Markdown extends BaseObject class Markdown extends BaseObject
{ {
/** /**
* Converts a Markdown string into HTML. The hardwrap parameter maximizes * Converts a Markdown string into HTML. The hardwrap parameter maximizes
* compatibility with Diaspora in spite of the Markdown standard. * compatibility with Diaspora in spite of the Markdown standard.
* *
* @brief Converts a Markdown string into HTML * @brief Converts a Markdown string into HTML
* @param string $text * @param string $text
* @param bool $hardwrap * @param bool $hardwrap
* @return string * @return string
*/ */
public static function convert($text, $hardwrap = true) { public static function convert($text, $hardwrap = true) {
$stamp1 = microtime(true); $stamp1 = microtime(true);
$MarkdownParser = new MarkdownExtra(); $MarkdownParser = new MarkdownExtra();
$MarkdownParser->hard_wrap = $hardwrap; $MarkdownParser->hard_wrap = $hardwrap;
$html = $MarkdownParser->transform($text); $html = $MarkdownParser->transform($text);
self::getApp()->save_timestamp($stamp1, "parser"); self::getApp()->save_timestamp($stamp1, "parser");
return $html; return $html;
} }
} }

View file

@ -1,162 +1,162 @@
<?php <?php
/* /*
* @file src/Content/Widget/TagCloud.php * @file src/Content/Widget/TagCloud.php
*/ */
namespace Friendica\Content\Widget; namespace Friendica\Content\Widget;
use dba; use dba;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Database\DBM; use Friendica\Database\DBM;
require_once 'include/dba.php'; require_once 'include/dba.php';
require_once 'include/security.php'; require_once 'include/security.php';
/** /**
* TagCloud widget * TagCloud widget
* *
* @author Rabuzarus * @author Rabuzarus
*/ */
class TagCloud class TagCloud
{ {
/** /**
* Construct a tag/term cloud block for an user. * Construct a tag/term cloud block for an user.
* *
* @brief Construct a tag/term cloud block for an user. * @brief Construct a tag/term cloud block for an user.
* @param int $uid The user ID. * @param int $uid The user ID.
* @param int $count Max number of displayed tags/terms. * @param int $count Max number of displayed tags/terms.
* @param int $owner_id The contact ID of the owner of the tagged items. * @param int $owner_id The contact ID of the owner of the tagged items.
* @param string $flags Special item flags. * @param string $flags Special item flags.
* @param int $type The tag/term type. * @param int $type The tag/term type.
* *
* @return string HTML formatted output. * @return string HTML formatted output.
*/ */
public static function getHTML($uid, $count = 0, $owner_id = 0, $flags = '', $type = TERM_HASHTAG) public static function getHTML($uid, $count = 0, $owner_id = 0, $flags = '', $type = TERM_HASHTAG)
{ {
$o = ''; $o = '';
$r = self::tagadelic($uid, $count, $owner_id, $flags, $type); $r = self::tagadelic($uid, $count, $owner_id, $flags, $type);
if (count($r)) { if (count($r)) {
$contact = dba::selectFirst('contact', ['url'], ['uid' => $uid, 'self' => true]); $contact = dba::selectFirst('contact', ['url'], ['uid' => $uid, 'self' => true]);
$url = System::removedBaseUrl($contact['url']); $url = System::removedBaseUrl($contact['url']);
foreach ($r as $rr) { foreach ($r as $rr) {
$tag['level'] = $rr[2]; $tag['level'] = $rr[2];
$tag['url'] = $url . '?tag=' . urlencode($rr[0]); $tag['url'] = $url . '?tag=' . urlencode($rr[0]);
$tag['name'] = $rr[0]; $tag['name'] = $rr[0];
$tags[] = $tag; $tags[] = $tag;
} }
$tpl = get_markup_template('tagblock_widget.tpl'); $tpl = get_markup_template('tagblock_widget.tpl');
$o = replace_macros($tpl, [ $o = replace_macros($tpl, [
'$title' => L10n::t('Tags'), '$title' => L10n::t('Tags'),
'$tags' => $tags '$tags' => $tags
]); ]);
} }
return $o; return $o;
} }
/** /**
* Get alphabetical sorted array of used tags/terms of an user including * Get alphabetical sorted array of used tags/terms of an user including
* a weighting by frequency of use. * a weighting by frequency of use.
* *
* @brief Get alphabetical sorted array of used tags/terms of an user including * @brief Get alphabetical sorted array of used tags/terms of an user including
* a weighting by frequency of use. * a weighting by frequency of use.
* @param int $uid The user ID. * @param int $uid The user ID.
* @param int $count Max number of displayed tags/terms. * @param int $count Max number of displayed tags/terms.
* @param int $owner_id The contact id of the owner of the tagged items. * @param int $owner_id The contact id of the owner of the tagged items.
* @param string $flags Special item flags. * @param string $flags Special item flags.
* @param int $type The tag/term type. * @param int $type The tag/term type.
* *
* @return arr Alphabetical sorted array of used tags of an user. * @return arr Alphabetical sorted array of used tags of an user.
*/ */
private static function tagadelic($uid, $count = 0, $owner_id = 0, $flags = '', $type = TERM_HASHTAG) private static function tagadelic($uid, $count = 0, $owner_id = 0, $flags = '', $type = TERM_HASHTAG)
{ {
$item_condition = item_condition(); $item_condition = item_condition();
$sql_options = item_permissions_sql($uid); $sql_options = item_permissions_sql($uid);
$limit = $count ? sprintf('LIMIT %d', intval($count)) : ''; $limit = $count ? sprintf('LIMIT %d', intval($count)) : '';
if ($flags) { if ($flags) {
if ($flags === 'wall') { if ($flags === 'wall') {
$sql_options .= ' AND `item`.`wall` '; $sql_options .= ' AND `item`.`wall` ';
} }
} }
if ($owner_id) { if ($owner_id) {
$sql_options .= ' AND `item`.`owner-id` = ' . intval($owner_id) . ' '; $sql_options .= ' AND `item`.`owner-id` = ' . intval($owner_id) . ' ';
} }
// Fetch tags // Fetch tags
$r = dba::p("SELECT `term`, COUNT(`term`) AS `total` FROM `term` $r = dba::p("SELECT `term`, COUNT(`term`) AS `total` FROM `term`
LEFT JOIN `item` ON `term`.`oid` = `item`.`id` LEFT JOIN `item` ON `term`.`oid` = `item`.`id`
WHERE `term`.`uid` = ? AND `term`.`type` = ? WHERE `term`.`uid` = ? AND `term`.`type` = ?
AND `term`.`otype` = ? AND `term`.`otype` = ?
AND $item_condition $sql_options AND $item_condition $sql_options
GROUP BY `term` ORDER BY `total` DESC $limit", GROUP BY `term` ORDER BY `total` DESC $limit",
$uid, $uid,
$type, $type,
TERM_OBJ_POST TERM_OBJ_POST
); );
if (!DBM::is_result($r)) { if (!DBM::is_result($r)) {
return []; return [];
} }
return self::tagCalc($r); return self::tagCalc($r);
} }
/** /**
* Calculate weighting of tags according to the frequency of use. * Calculate weighting of tags according to the frequency of use.
* *
* @brief Calculate weighting of tags according to the frequency of use. * @brief Calculate weighting of tags according to the frequency of use.
* @param array $arr Array of tags/terms with tag/term name and total count of use. * @param array $arr Array of tags/terms with tag/term name and total count of use.
* @return array Alphabetical sorted array of used tags/terms of an user. * @return array Alphabetical sorted array of used tags/terms of an user.
*/ */
private static function tagCalc($arr) private static function tagCalc($arr)
{ {
$tags = []; $tags = [];
$min = 1e9; $min = 1e9;
$max = -1e9; $max = -1e9;
$x = 0; $x = 0;
if (!$arr) { if (!$arr) {
return []; return [];
} }
foreach ($arr as $rr) { foreach ($arr as $rr) {
$tags[$x][0] = $rr['term']; $tags[$x][0] = $rr['term'];
$tags[$x][1] = log($rr['total']); $tags[$x][1] = log($rr['total']);
$tags[$x][2] = 0; $tags[$x][2] = 0;
$min = min($min, $tags[$x][1]); $min = min($min, $tags[$x][1]);
$max = max($max, $tags[$x][1]); $max = max($max, $tags[$x][1]);
$x ++; $x ++;
} }
usort($tags, 'self::tagsSort'); usort($tags, 'self::tagsSort');
$range = max(.01, $max - $min) * 1.0001; $range = max(.01, $max - $min) * 1.0001;
for ($x = 0; $x < count($tags); $x ++) { for ($x = 0; $x < count($tags); $x ++) {
$tags[$x][2] = 1 + floor(9 * ($tags[$x][1] - $min) / $range); $tags[$x][2] = 1 + floor(9 * ($tags[$x][1] - $min) / $range);
} }
return $tags; return $tags;
} }
/** /**
* Compare function to sort tags/terms alphabetically. * Compare function to sort tags/terms alphabetically.
* *
* @brief Compare function to sort tags/terms alphabetically. * @brief Compare function to sort tags/terms alphabetically.
* @param type $a * @param type $a
* @param type $b * @param type $b
* *
* @return int * @return int
*/ */
private static function tagsSort($a, $b) private static function tagsSort($a, $b)
{ {
if (strtolower($a[0]) == strtolower($b[0])) { if (strtolower($a[0]) == strtolower($b[0])) {
return 0; return 0;
} }
return ((strtolower($a[0]) < strtolower($b[0])) ? -1 : 1); return ((strtolower($a[0]) < strtolower($b[0])) ? -1 : 1);
} }
} }

View file

@ -1,57 +1,57 @@
<?php <?php
/** /**
* @file src/Core/Session.php * @file src/Core/Session.php
*/ */
namespace Friendica\Core; namespace Friendica\Core;
use Friendica\Core\Session\DatabaseSessionHandler; use Friendica\Core\Session\DatabaseSessionHandler;
use Friendica\Core\Session\MemcacheSessionHandler; use Friendica\Core\Session\MemcacheSessionHandler;
/** /**
* High-level Session service class * High-level Session service class
* *
* @author Hypolite Petovan <mrpetovan@gmail.com> * @author Hypolite Petovan <mrpetovan@gmail.com>
*/ */
class Session class Session
{ {
public static $exists = false; public static $exists = false;
public static $expire = 180000; public static $expire = 180000;
public static function init() public static function init()
{ {
ini_set('session.gc_probability', 50); ini_set('session.gc_probability', 50);
ini_set('session.use_only_cookies', 1); ini_set('session.use_only_cookies', 1);
ini_set('session.cookie_httponly', 1); ini_set('session.cookie_httponly', 1);
if (Config::get('system', 'ssl_policy') == SSL_POLICY_FULL) { if (Config::get('system', 'ssl_policy') == SSL_POLICY_FULL) {
ini_set('session.cookie_secure', 1); ini_set('session.cookie_secure', 1);
} }
if (!Config::get('system', 'disable_database_session')) { if (!Config::get('system', 'disable_database_session')) {
$memcache = Cache::memcache(); $memcache = Cache::memcache();
if (is_object($memcache)) { if (is_object($memcache)) {
$SessionHandler = new MemcacheSessionHandler($memcache); $SessionHandler = new MemcacheSessionHandler($memcache);
} else { } else {
$SessionHandler = new DatabaseSessionHandler(); $SessionHandler = new DatabaseSessionHandler();
} }
session_set_save_handler($SessionHandler); session_set_save_handler($SessionHandler);
} }
} }
public static function exists($name) public static function exists($name)
{ {
return isset($_SESSION[$name]); return isset($_SESSION[$name]);
} }
public static function get($name) public static function get($name)
{ {
return defaults($_SESSION, $name, null); return defaults($_SESSION, $name, null);
} }
public static function set($name, $value) public static function set($name, $value)
{ {
$_SESSION[$name] = $value; $_SESSION[$name] = $value;
} }
} }

View file

@ -1,95 +1,95 @@
<?php <?php
namespace Friendica\Core\Session; namespace Friendica\Core\Session;
use Friendica\BaseObject; use Friendica\BaseObject;
use Friendica\Core\Session; use Friendica\Core\Session;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use SessionHandlerInterface; use SessionHandlerInterface;
use dba; use dba;
require_once 'boot.php'; require_once 'boot.php';
require_once 'include/dba.php'; require_once 'include/dba.php';
require_once 'include/text.php'; require_once 'include/text.php';
/** /**
* SessionHandler using database * SessionHandler using database
* *
* @author Hypolite Petovan <mrpetovan@gmail.com> * @author Hypolite Petovan <mrpetovan@gmail.com>
*/ */
class DatabaseSessionHandler extends BaseObject implements SessionHandlerInterface class DatabaseSessionHandler extends BaseObject implements SessionHandlerInterface
{ {
public function open($save_path, $session_name) public function open($save_path, $session_name)
{ {
return true; return true;
} }
public function read($session_id) public function read($session_id)
{ {
if (!x($session_id)) { if (!x($session_id)) {
return ''; return '';
} }
$session = dba::selectFirst('session', ['data'], ['sid' => $session_id]); $session = dba::selectFirst('session', ['data'], ['sid' => $session_id]);
if (DBM::is_result($session)) { if (DBM::is_result($session)) {
Session::$exists = true; Session::$exists = true;
return $session['data']; return $session['data'];
} }
logger("no data for session $session_id", LOGGER_TRACE); logger("no data for session $session_id", LOGGER_TRACE);
return ''; return '';
} }
/** /**
* @brief Standard PHP session write callback * @brief Standard PHP session write callback
* *
* This callback updates the DB-stored session data and/or the expiration depending * This callback updates the DB-stored session data and/or the expiration depending
* on the case. Uses the Session::expire global for existing session, 5 minutes * on the case. Uses the Session::expire global for existing session, 5 minutes
* for newly created session. * for newly created session.
* *
* @param string $session_id Session ID with format: [a-z0-9]{26} * @param string $session_id Session ID with format: [a-z0-9]{26}
* @param string $session_data Serialized session data * @param string $session_data Serialized session data
* @return boolean Returns false if parameters are missing, true otherwise * @return boolean Returns false if parameters are missing, true otherwise
*/ */
public function write($session_id, $session_data) public function write($session_id, $session_data)
{ {
if (!$session_id) { if (!$session_id) {
return false; return false;
} }
if (!$session_data) { if (!$session_data) {
return true; return true;
} }
$expire = time() + Session::$expire; $expire = time() + Session::$expire;
$default_expire = time() + 300; $default_expire = time() + 300;
if (Session::$exists) { if (Session::$exists) {
$fields = ['data' => $session_data, 'expire' => $expire]; $fields = ['data' => $session_data, 'expire' => $expire];
$condition = ["`sid` = ? AND (`data` != ? OR `expire` != ?)", $session_id, $session_data, $expire]; $condition = ["`sid` = ? AND (`data` != ? OR `expire` != ?)", $session_id, $session_data, $expire];
dba::update('session', $fields, $condition); dba::update('session', $fields, $condition);
} else { } else {
$fields = ['sid' => $session_id, 'expire' => $default_expire, 'data' => $session_data]; $fields = ['sid' => $session_id, 'expire' => $default_expire, 'data' => $session_data];
dba::insert('session', $fields); dba::insert('session', $fields);
} }
return true; return true;
} }
public function close() public function close()
{ {
return true; return true;
} }
public function destroy($id) public function destroy($id)
{ {
dba::delete('session', ['sid' => $id]); dba::delete('session', ['sid' => $id]);
return true; return true;
} }
public function gc($maxlifetime) public function gc($maxlifetime)
{ {
dba::delete('session', ["`expire` < ?", time()]); dba::delete('session', ["`expire` < ?", time()]);
return true; return true;
} }
} }

View file

@ -1,102 +1,102 @@
<?php <?php
namespace Friendica\Core\Session; namespace Friendica\Core\Session;
use Friendica\BaseObject; use Friendica\BaseObject;
use Friendica\Core\Session; use Friendica\Core\Session;
use SessionHandlerInterface; use SessionHandlerInterface;
use Memcache; use Memcache;
require_once 'boot.php'; require_once 'boot.php';
require_once 'include/text.php'; require_once 'include/text.php';
/** /**
* SessionHandler using Memcache * SessionHandler using Memcache
* *
* @author Hypolite Petovan <mrpetovan@gmail.com> * @author Hypolite Petovan <mrpetovan@gmail.com>
*/ */
class MemcacheSessionHandler extends BaseObject implements SessionHandlerInterface class MemcacheSessionHandler extends BaseObject implements SessionHandlerInterface
{ {
/** /**
* @var Memcache * @var Memcache
*/ */
private $memcache = null; private $memcache = null;
/** /**
* *
* @param Memcache $memcache * @param Memcache $memcache
*/ */
public function __construct(Memcache $memcache) public function __construct(Memcache $memcache)
{ {
$this->memcache = $memcache; $this->memcache = $memcache;
} }
public function open($save_path, $session_name) public function open($save_path, $session_name)
{ {
return true; return true;
} }
public function read($session_id) public function read($session_id)
{ {
if (!x($session_id)) { if (!x($session_id)) {
return ''; return '';
} }
$data = $this->memcache->get(self::getApp()->get_hostname() . ":session:" . $session_id); $data = $this->memcache->get(self::getApp()->get_hostname() . ":session:" . $session_id);
if (!is_bool($data)) { if (!is_bool($data)) {
Session::$exists = true; Session::$exists = true;
return $data; return $data;
} }
logger("no data for session $session_id", LOGGER_TRACE); logger("no data for session $session_id", LOGGER_TRACE);
return ''; return '';
} }
/** /**
* @brief Standard PHP session write callback * @brief Standard PHP session write callback
* *
* This callback updates the stored session data and/or the expiration depending * This callback updates the stored session data and/or the expiration depending
* on the case. Uses the Session::expire for existing session, 5 minutes * on the case. Uses the Session::expire for existing session, 5 minutes
* for newly created session. * for newly created session.
* *
* @param string $session_id Session ID with format: [a-z0-9]{26} * @param string $session_id Session ID with format: [a-z0-9]{26}
* @param string $session_data Serialized session data * @param string $session_data Serialized session data
* @return boolean Returns false if parameters are missing, true otherwise * @return boolean Returns false if parameters are missing, true otherwise
*/ */
public function write($session_id, $session_data) public function write($session_id, $session_data)
{ {
if (!$session_id) { if (!$session_id) {
return false; return false;
} }
if (!$session_data) { if (!$session_data) {
return true; return true;
} }
$expire = time() + Session::$expire; $expire = time() + Session::$expire;
$this->memcache->set( $this->memcache->set(
self::getApp()->get_hostname() . ":session:" . $session_id, self::getApp()->get_hostname() . ":session:" . $session_id,
$session_data, $session_data,
MEMCACHE_COMPRESSED, MEMCACHE_COMPRESSED,
$expire $expire
); );
return true; return true;
} }
public function close() public function close()
{ {
return true; return true;
} }
public function destroy($id) public function destroy($id)
{ {
$this->memcache->delete(self::getApp()->get_hostname() . ":session:" . $id); $this->memcache->delete(self::getApp()->get_hostname() . ":session:" . $id);
return true; return true;
} }
public function gc($maxlifetime) public function gc($maxlifetime)
{ {
return true; return true;
} }
} }

View file

@ -1,189 +1,189 @@
<?php <?php
/** /**
* @file src/Core/Theme.php * @file src/Core/Theme.php
*/ */
namespace Friendica\Core; namespace Friendica\Core;
use Friendica\Core\System; use Friendica\Core\System;
require_once 'boot.php'; require_once 'boot.php';
/** /**
* Some functions to handle themes * Some functions to handle themes
*/ */
class Theme class Theme
{ {
/** /**
* @brief Parse theme comment in search of theme infos. * @brief Parse theme comment in search of theme infos.
* *
* like * like
* \code * \code
* ..* Name: My Theme * ..* Name: My Theme
* * Description: My Cool Theme * * Description: My Cool Theme
* . * Version: 1.2.3 * . * Version: 1.2.3
* * Author: John <profile url> * * Author: John <profile url>
* * Maintainer: Jane <profile url> * * Maintainer: Jane <profile url>
* * * *
* \endcode * \endcode
* @param string $theme the name of the theme * @param string $theme the name of the theme
* @return array * @return array
*/ */
public static function getInfo($theme) public static function getInfo($theme)
{ {
$info=[ $info=[
'name' => $theme, 'name' => $theme,
'description' => "", 'description' => "",
'author' => [], 'author' => [],
'maintainer' => [], 'maintainer' => [],
'version' => "", 'version' => "",
'credits' => "", 'credits' => "",
'experimental' => false, 'experimental' => false,
'unsupported' => false 'unsupported' => false
]; ];
if (file_exists("view/theme/$theme/experimental")) if (file_exists("view/theme/$theme/experimental"))
$info['experimental'] = true; $info['experimental'] = true;
if (file_exists("view/theme/$theme/unsupported")) if (file_exists("view/theme/$theme/unsupported"))
$info['unsupported'] = true; $info['unsupported'] = true;
if (!is_file("view/theme/$theme/theme.php")) return $info; if (!is_file("view/theme/$theme/theme.php")) return $info;
$a = get_app(); $a = get_app();
$stamp1 = microtime(true); $stamp1 = microtime(true);
$f = file_get_contents("view/theme/$theme/theme.php"); $f = file_get_contents("view/theme/$theme/theme.php");
$a->save_timestamp($stamp1, "file"); $a->save_timestamp($stamp1, "file");
$r = preg_match("|/\*.*\*/|msU", $f, $m); $r = preg_match("|/\*.*\*/|msU", $f, $m);
if ($r) { if ($r) {
$ll = explode("\n", $m[0]); $ll = explode("\n", $m[0]);
foreach ( $ll as $l ) { foreach ( $ll as $l ) {
$l = trim($l,"\t\n\r */"); $l = trim($l,"\t\n\r */");
if ($l != "") { if ($l != "") {
list($k, $v) = array_map("trim", explode(":", $l, 2)); list($k, $v) = array_map("trim", explode(":", $l, 2));
$k= strtolower($k); $k= strtolower($k);
if ($k == "author") { if ($k == "author") {
$r=preg_match("|([^<]+)<([^>]+)>|", $v, $m); $r=preg_match("|([^<]+)<([^>]+)>|", $v, $m);
if ($r) { if ($r) {
$info['author'][] = ['name'=>$m[1], 'link'=>$m[2]]; $info['author'][] = ['name'=>$m[1], 'link'=>$m[2]];
} else { } else {
$info['author'][] = ['name'=>$v]; $info['author'][] = ['name'=>$v];
} }
} elseif ($k == "maintainer") { } elseif ($k == "maintainer") {
$r=preg_match("|([^<]+)<([^>]+)>|", $v, $m); $r=preg_match("|([^<]+)<([^>]+)>|", $v, $m);
if ($r) { if ($r) {
$info['maintainer'][] = ['name'=>$m[1], 'link'=>$m[2]]; $info['maintainer'][] = ['name'=>$m[1], 'link'=>$m[2]];
} else { } else {
$info['maintainer'][] = ['name'=>$v]; $info['maintainer'][] = ['name'=>$v];
} }
} else { } else {
if (array_key_exists($k, $info)) { if (array_key_exists($k, $info)) {
$info[$k] = $v; $info[$k] = $v;
} }
} }
} }
} }
} }
return $info; return $info;
} }
/** /**
* @brief Returns the theme's screenshot. * @brief Returns the theme's screenshot.
* *
* The screenshot is expected as view/theme/$theme/screenshot.[png|jpg]. * The screenshot is expected as view/theme/$theme/screenshot.[png|jpg].
* *
* @param sring $theme The name of the theme * @param sring $theme The name of the theme
* @return string * @return string
*/ */
public static function getScreenshot($theme) public static function getScreenshot($theme)
{ {
$exts = ['.png','.jpg']; $exts = ['.png','.jpg'];
foreach ($exts as $ext) { foreach ($exts as $ext) {
if (file_exists('view/theme/' . $theme . '/screenshot' . $ext)) { if (file_exists('view/theme/' . $theme . '/screenshot' . $ext)) {
return(System::baseUrl() . '/view/theme/' . $theme . '/screenshot' . $ext); return(System::baseUrl() . '/view/theme/' . $theme . '/screenshot' . $ext);
} }
} }
return(System::baseUrl() . '/images/blank.png'); return(System::baseUrl() . '/images/blank.png');
} }
// install and uninstall theme // install and uninstall theme
public static function uninstall($theme) public static function uninstall($theme)
{ {
logger("Addons: uninstalling theme " . $theme); logger("Addons: uninstalling theme " . $theme);
include_once("view/theme/$theme/theme.php"); include_once("view/theme/$theme/theme.php");
if (function_exists("{$theme}_uninstall")) { if (function_exists("{$theme}_uninstall")) {
$func = "{$theme}_uninstall"; $func = "{$theme}_uninstall";
$func(); $func();
} }
} }
public static function install($theme) public static function install($theme)
{ {
// silently fail if theme was removed // silently fail if theme was removed
if (! file_exists("view/theme/$theme/theme.php")) { if (! file_exists("view/theme/$theme/theme.php")) {
return false; return false;
} }
logger("Addons: installing theme $theme"); logger("Addons: installing theme $theme");
include_once("view/theme/$theme/theme.php"); include_once("view/theme/$theme/theme.php");
if (function_exists("{$theme}_install")) { if (function_exists("{$theme}_install")) {
$func = "{$theme}_install"; $func = "{$theme}_install";
$func(); $func();
return true; return true;
} else { } else {
logger("Addons: FAILED installing theme $theme"); logger("Addons: FAILED installing theme $theme");
return false; return false;
} }
} }
/** /**
* @brief Get the full path to relevant theme files by filename * @brief Get the full path to relevant theme files by filename
* *
* This function search in the theme directory (and if not present in global theme directory) * This function search in the theme directory (and if not present in global theme directory)
* if there is a directory with the file extension and for a file with the given * if there is a directory with the file extension and for a file with the given
* filename. * filename.
* *
* @param string $file Filename * @param string $file Filename
* @param string $root Full root path * @param string $root Full root path
* @return string Path to the file or empty string if the file isn't found * @return string Path to the file or empty string if the file isn't found
*/ */
public static function getPathForFile($file, $root = '') public static function getPathForFile($file, $root = '')
{ {
$file = basename($file); $file = basename($file);
// Make sure $root ends with a slash / if it's not blank // Make sure $root ends with a slash / if it's not blank
if ($root !== '' && $root[strlen($root)-1] !== '/') { if ($root !== '' && $root[strlen($root)-1] !== '/') {
$root = $root . '/'; $root = $root . '/';
} }
$theme_info = get_app()->theme_info; $theme_info = get_app()->theme_info;
if (is_array($theme_info) && array_key_exists('extends',$theme_info)) { if (is_array($theme_info) && array_key_exists('extends',$theme_info)) {
$parent = $theme_info['extends']; $parent = $theme_info['extends'];
} else { } else {
$parent = 'NOPATH'; $parent = 'NOPATH';
} }
$theme = current_theme(); $theme = current_theme();
$thname = $theme; $thname = $theme;
$ext = substr($file,strrpos($file,'.')+1); $ext = substr($file,strrpos($file,'.')+1);
$paths = [ $paths = [
"{$root}view/theme/$thname/$ext/$file", "{$root}view/theme/$thname/$ext/$file",
"{$root}view/theme/$parent/$ext/$file", "{$root}view/theme/$parent/$ext/$file",
"{$root}view/$ext/$file", "{$root}view/$ext/$file",
]; ];
foreach ($paths as $p) { foreach ($paths as $p) {
// strpos() is faster than strstr when checking if one string is in another (http://php.net/manual/en/function.strstr.php) // strpos() is faster than strstr when checking if one string is in another (http://php.net/manual/en/function.strstr.php)
if (strpos($p,'NOPATH') !== false) { if (strpos($p,'NOPATH') !== false) {
continue; continue;
} elseif (file_exists($p)) { } elseif (file_exists($p)) {
return $p; return $p;
} }
} }
return ''; return '';
} }
} }

View file

@ -1,273 +1,273 @@
<?php <?php
/** /**
* @file src/Database/PostUpdate.php * @file src/Database/PostUpdate.php
*/ */
namespace Friendica\Database; namespace Friendica\Database;
use Friendica\Core\Config; use Friendica\Core\Config;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\GContact; use Friendica\Model\GContact;
use dba; use dba;
require_once 'include/dba.php'; require_once 'include/dba.php';
/** /**
* Post update functions * Post update functions
*/ */
class PostUpdate class PostUpdate
{ {
/** /**
* @brief Calls the post update functions * @brief Calls the post update functions
*/ */
public static function update() public static function update()
{ {
if (!self::update1192()) { if (!self::update1192()) {
return; return;
} }
if (!self::update1194()) { if (!self::update1194()) {
return; return;
} }
if (!self::update1198()) { if (!self::update1198()) {
return; return;
} }
if (!self::update1206()) { if (!self::update1206()) {
return; return;
} }
} }
/** /**
* @brief set the gcontact-id in all item entries * @brief set the gcontact-id in all item entries
* *
* This job has to be started multiple times until all entries are set. * 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. * 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 * @return bool "true" when the job is done
*/ */
private static function update1192() private static function update1192()
{ {
// Was the script completed? // Was the script completed?
if (Config::get("system", "post_update_version") >= 1192) { if (Config::get("system", "post_update_version") >= 1192) {
return true; return true;
} }
// Check if the first step is done (Setting "gcontact-id" in the item table) // Check if the first step is done (Setting "gcontact-id" in the item table)
$r = dba::select('item', ['author-link', 'author-name', 'author-avatar', 'uid', 'network'], ['gcontact-id' => 0], ['limit' => 1000]); $r = dba::select('item', ['author-link', 'author-name', 'author-avatar', 'uid', 'network'], ['gcontact-id' => 0], ['limit' => 1000]);
if (!$r) { if (!$r) {
// Are there unfinished entries in the thread table? // Are there unfinished entries in the thread table?
$r = q("SELECT COUNT(*) AS `total` FROM `thread` $r = q("SELECT COUNT(*) AS `total` FROM `thread`
INNER JOIN `item` ON `item`.`id` =`thread`.`iid` INNER JOIN `item` ON `item`.`id` =`thread`.`iid`
WHERE `thread`.`gcontact-id` = 0 AND WHERE `thread`.`gcontact-id` = 0 AND
(`thread`.`uid` IN (SELECT `uid` from `user`) OR `thread`.`uid` = 0)"); (`thread`.`uid` IN (SELECT `uid` from `user`) OR `thread`.`uid` = 0)");
if ($r && ($r[0]["total"] == 0)) { if ($r && ($r[0]["total"] == 0)) {
Config::set("system", "post_update_version", 1192); Config::set("system", "post_update_version", 1192);
return true; return true;
} }
// Update the thread table from the item table // Update the thread table from the item table
q("UPDATE `thread` INNER JOIN `item` ON `item`.`id`=`thread`.`iid` q("UPDATE `thread` INNER JOIN `item` ON `item`.`id`=`thread`.`iid`
SET `thread`.`gcontact-id` = `item`.`gcontact-id` SET `thread`.`gcontact-id` = `item`.`gcontact-id`
WHERE `thread`.`gcontact-id` = 0 AND WHERE `thread`.`gcontact-id` = 0 AND
(`thread`.`uid` IN (SELECT `uid` from `user`) OR `thread`.`uid` = 0)"); (`thread`.`uid` IN (SELECT `uid` from `user`) OR `thread`.`uid` = 0)");
return false; return false;
} }
$item_arr = []; $item_arr = [];
foreach ($r as $item) { foreach ($r as $item) {
$index = $item["author-link"]."-".$item["uid"]; $index = $item["author-link"]."-".$item["uid"];
$item_arr[$index] = ["author-link" => $item["author-link"], $item_arr[$index] = ["author-link" => $item["author-link"],
"uid" => $item["uid"], "uid" => $item["uid"],
"network" => $item["network"]]; "network" => $item["network"]];
} }
// Set the "gcontact-id" in the item table and add a new gcontact entry if needed // Set the "gcontact-id" in the item table and add a new gcontact entry if needed
foreach ($item_arr as $item) { foreach ($item_arr as $item) {
$gcontact_id = GContact::getId(["url" => $item['author-link'], "network" => $item['network'], $gcontact_id = GContact::getId(["url" => $item['author-link'], "network" => $item['network'],
"photo" => $item['author-avatar'], "name" => $item['author-name']]); "photo" => $item['author-avatar'], "name" => $item['author-name']]);
dba::update('item', ['gcontact-id' => $gcontact_id], ['uid' => $item['uid'], 'author-link' => $item['author-link'], 'gcontact-id' => 0]); dba::update('item', ['gcontact-id' => $gcontact_id], ['uid' => $item['uid'], 'author-link' => $item['author-link'], 'gcontact-id' => 0]);
} }
return false; return false;
} }
/** /**
* @brief Updates the "global" field in the item table * @brief Updates the "global" field in the item table
* *
* @return bool "true" when the job is done * @return bool "true" when the job is done
*/ */
private static function update1194() private static function update1194()
{ {
// Was the script completed? // Was the script completed?
if (Config::get("system", "post_update_version") >= 1194) { if (Config::get("system", "post_update_version") >= 1194) {
return true; return true;
} }
logger("Start", LOGGER_DEBUG); logger("Start", LOGGER_DEBUG);
$end_id = Config::get("system", "post_update_1194_end"); $end_id = Config::get("system", "post_update_1194_end");
if (!$end_id) { if (!$end_id) {
$r = q("SELECT `id` FROM `item` WHERE `uid` != 0 ORDER BY `id` DESC LIMIT 1"); $r = q("SELECT `id` FROM `item` WHERE `uid` != 0 ORDER BY `id` DESC LIMIT 1");
if ($r) { if ($r) {
Config::set("system", "post_update_1194_end", $r[0]["id"]); Config::set("system", "post_update_1194_end", $r[0]["id"]);
$end_id = Config::get("system", "post_update_1194_end"); $end_id = Config::get("system", "post_update_1194_end");
} }
} }
logger("End ID: ".$end_id, LOGGER_DEBUG); logger("End ID: ".$end_id, LOGGER_DEBUG);
$start_id = Config::get("system", "post_update_1194_start"); $start_id = Config::get("system", "post_update_1194_start");
$query1 = "SELECT `item`.`id` FROM `item` "; $query1 = "SELECT `item`.`id` FROM `item` ";
$query2 = "INNER JOIN `item` AS `shadow` ON `item`.`uri` = `shadow`.`uri` AND `shadow`.`uid` = 0 "; $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 $query3 = "WHERE `item`.`uid` != 0 AND `item`.`id` >= %d AND `item`.`id` <= %d
AND `item`.`visible` AND NOT `item`.`private` AND `item`.`visible` AND NOT `item`.`private`
AND NOT `item`.`deleted` AND NOT `item`.`moderated` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
AND `item`.`network` IN ('%s', '%s', '%s', '') AND `item`.`network` IN ('%s', '%s', '%s', '')
AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
AND NOT `item`.`global`"; AND NOT `item`.`global`";
$r = q($query1.$query2.$query3." ORDER BY `item`.`id` LIMIT 1", $r = q($query1.$query2.$query3." ORDER BY `item`.`id` LIMIT 1",
intval($start_id), intval($end_id), intval($start_id), intval($end_id),
dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS)); dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS));
if (!$r) { if (!$r) {
Config::set("system", "post_update_version", 1194); Config::set("system", "post_update_version", 1194);
logger("Update is done", LOGGER_DEBUG); logger("Update is done", LOGGER_DEBUG);
return true; return true;
} else { } else {
Config::set("system", "post_update_1194_start", $r[0]["id"]); Config::set("system", "post_update_1194_start", $r[0]["id"]);
$start_id = Config::get("system", "post_update_1194_start"); $start_id = Config::get("system", "post_update_1194_start");
} }
logger("Start ID: ".$start_id, LOGGER_DEBUG); logger("Start ID: ".$start_id, LOGGER_DEBUG);
$r = q($query1.$query2.$query3." ORDER BY `item`.`id` LIMIT 1000,1", $r = q($query1.$query2.$query3." ORDER BY `item`.`id` LIMIT 1000,1",
intval($start_id), intval($end_id), intval($start_id), intval($end_id),
dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS)); dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS));
if ($r) if ($r)
$pos_id = $r[0]["id"]; $pos_id = $r[0]["id"];
else else
$pos_id = $end_id; $pos_id = $end_id;
logger("Progress: Start: ".$start_id." position: ".$pos_id." end: ".$end_id, LOGGER_DEBUG); logger("Progress: Start: ".$start_id." position: ".$pos_id." end: ".$end_id, LOGGER_DEBUG);
q("UPDATE `item` ".$query2." SET `item`.`global` = 1 ".$query3, q("UPDATE `item` ".$query2." SET `item`.`global` = 1 ".$query3,
intval($start_id), intval($pos_id), intval($start_id), intval($pos_id),
dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS)); dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS));
logger("Done", LOGGER_DEBUG); logger("Done", LOGGER_DEBUG);
} }
/** /**
* @brief set the author-id and owner-id in all item entries * @brief set the author-id and owner-id in all item entries
* *
* This job has to be started multiple times until all entries are set. * 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. * 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 * @return bool "true" when the job is done
*/ */
private static function update1198() private static function update1198()
{ {
// Was the script completed? // Was the script completed?
if (Config::get("system", "post_update_version") >= 1198) { if (Config::get("system", "post_update_version") >= 1198) {
return true; return true;
} }
logger("Start", LOGGER_DEBUG); logger("Start", LOGGER_DEBUG);
// Check if the first step is done (Setting "author-id" and "owner-id" in the item table) // Check if the first step is done (Setting "author-id" and "owner-id" in the item table)
$r = dba::select('item', ['author-link', 'owner-link', 'uid'], ['author-id' => 0, 'owner-id' => 0], ['limit' => 1000]); $r = dba::select('item', ['author-link', 'owner-link', 'uid'], ['author-id' => 0, 'owner-id' => 0], ['limit' => 1000]);
if (!$r) { if (!$r) {
// Are there unfinished entries in the thread table? // Are there unfinished entries in the thread table?
$r = q("SELECT COUNT(*) AS `total` FROM `thread` $r = q("SELECT COUNT(*) AS `total` FROM `thread`
INNER JOIN `item` ON `item`.`id` =`thread`.`iid` INNER JOIN `item` ON `item`.`id` =`thread`.`iid`
WHERE `thread`.`author-id` = 0 AND `thread`.`owner-id` = 0 AND WHERE `thread`.`author-id` = 0 AND `thread`.`owner-id` = 0 AND
(`thread`.`uid` IN (SELECT `uid` from `user`) OR `thread`.`uid` = 0)"); (`thread`.`uid` IN (SELECT `uid` from `user`) OR `thread`.`uid` = 0)");
if ($r && ($r[0]["total"] == 0)) { if ($r && ($r[0]["total"] == 0)) {
Config::set("system", "post_update_version", 1198); Config::set("system", "post_update_version", 1198);
logger("Done", LOGGER_DEBUG); logger("Done", LOGGER_DEBUG);
return true; return true;
} }
// Update the thread table from the item table // Update the thread table from the item table
$r = q("UPDATE `thread` INNER JOIN `item` ON `item`.`id`=`thread`.`iid` $r = q("UPDATE `thread` INNER JOIN `item` ON `item`.`id`=`thread`.`iid`
SET `thread`.`author-id` = `item`.`author-id`, SET `thread`.`author-id` = `item`.`author-id`,
`thread`.`owner-id` = `item`.`owner-id` `thread`.`owner-id` = `item`.`owner-id`
WHERE `thread`.`author-id` = 0 AND `thread`.`owner-id` = 0 AND WHERE `thread`.`author-id` = 0 AND `thread`.`owner-id` = 0 AND
(`thread`.`uid` IN (SELECT `uid` from `user`) OR `thread`.`uid` = 0)"); (`thread`.`uid` IN (SELECT `uid` from `user`) OR `thread`.`uid` = 0)");
logger("Updated threads", LOGGER_DEBUG); logger("Updated threads", LOGGER_DEBUG);
if (DBM::is_result($r)) { if (DBM::is_result($r)) {
Config::set("system", "post_update_version", 1198); Config::set("system", "post_update_version", 1198);
logger("Done", LOGGER_DEBUG); logger("Done", LOGGER_DEBUG);
return true; return true;
} }
return false; return false;
} }
logger("Query done", LOGGER_DEBUG); logger("Query done", LOGGER_DEBUG);
$item_arr = []; $item_arr = [];
foreach ($r as $item) { foreach ($r as $item) {
$index = $item["author-link"]."-".$item["owner-link"]."-".$item["uid"]; $index = $item["author-link"]."-".$item["owner-link"]."-".$item["uid"];
$item_arr[$index] = ["author-link" => $item["author-link"], $item_arr[$index] = ["author-link" => $item["author-link"],
"owner-link" => $item["owner-link"], "owner-link" => $item["owner-link"],
"uid" => $item["uid"]]; "uid" => $item["uid"]];
} }
// Set the "gcontact-id" in the item table and add a new gcontact entry if needed // Set the "gcontact-id" in the item table and add a new gcontact entry if needed
foreach ($item_arr as $item) { foreach ($item_arr as $item) {
$author_id = Contact::getIdForURL($item["author-link"], 0); $author_id = Contact::getIdForURL($item["author-link"], 0);
$owner_id = Contact::getIdForURL($item["owner-link"], 0); $owner_id = Contact::getIdForURL($item["owner-link"], 0);
if ($author_id == 0) if ($author_id == 0)
$author_id = -1; $author_id = -1;
if ($owner_id == 0) if ($owner_id == 0)
$owner_id = -1; $owner_id = -1;
dba::update('item', ['author-id' => $author_id, 'owner-id' => $owner_id], ['uid' => $item['uid'], 'author-link' => $item['author-link'], 'owner-link' => $item['owner-link'], 'author-id' => 0, 'owner-id' => 0]); dba::update('item', ['author-id' => $author_id, 'owner-id' => $owner_id], ['uid' => $item['uid'], 'author-link' => $item['author-link'], 'owner-link' => $item['owner-link'], 'author-id' => 0, 'owner-id' => 0]);
} }
logger("Updated items", LOGGER_DEBUG); logger("Updated items", LOGGER_DEBUG);
return false; return false;
} }
/** /**
* @brief update the "last-item" field in the "self" contact * @brief update the "last-item" field in the "self" contact
* *
* This field avoids cost intensive calls in the admin panel and in "nodeinfo" * This field avoids cost intensive calls in the admin panel and in "nodeinfo"
* *
* @return bool "true" when the job is done * @return bool "true" when the job is done
*/ */
private static function update1206() private static function update1206()
{ {
// Was the script completed? // Was the script completed?
if (Config::get("system", "post_update_version") >= 1206) { if (Config::get("system", "post_update_version") >= 1206) {
return true; return true;
} }
logger("Start", LOGGER_DEBUG); logger("Start", LOGGER_DEBUG);
$r = q("SELECT `contact`.`id`, `contact`.`last-item`, $r = q("SELECT `contact`.`id`, `contact`.`last-item`,
(SELECT MAX(`changed`) FROM `item` USE INDEX (`uid_wall_changed`) WHERE `wall` AND `uid` = `user`.`uid`) AS `lastitem_date` (SELECT MAX(`changed`) FROM `item` USE INDEX (`uid_wall_changed`) WHERE `wall` AND `uid` = `user`.`uid`) AS `lastitem_date`
FROM `user` FROM `user`
INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`"); INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`");
if (!DBM::is_result($r)) { if (!DBM::is_result($r)) {
return false; return false;
} }
foreach ($r as $user) { foreach ($r as $user) {
if (!empty($user["lastitem_date"]) && ($user["lastitem_date"] > $user["last-item"])) { if (!empty($user["lastitem_date"]) && ($user["lastitem_date"] > $user["last-item"])) {
dba::update('contact', ['last-item' => $user['lastitem_date']], ['id' => $user['id']]); dba::update('contact', ['last-item' => $user['lastitem_date']], ['id' => $user['id']]);
} }
} }
Config::set("system", "post_update_version", 1206); Config::set("system", "post_update_version", 1206);
logger("Done", LOGGER_DEBUG); logger("Done", LOGGER_DEBUG);
return true; return true;
} }
} }

View file

@ -1,60 +1,60 @@
<?php <?php
namespace Friendica\Module; namespace Friendica\Module;
use Friendica\BaseModule; use Friendica\BaseModule;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Protocol\OStatus; use Friendica\Protocol\OStatus;
/** /**
* Provides public Atom feeds * Provides public Atom feeds
* *
* Currently supported: * Currently supported:
* - /feed/[nickname]/ => posts * - /feed/[nickname]/ => posts
* - /feed/[nickname]/posts => posts * - /feed/[nickname]/posts => posts
* - /feed/[nickname]/comments => comments * - /feed/[nickname]/comments => comments
* - /feed/[nickname]/replies => comments * - /feed/[nickname]/replies => comments
* - /feed/[nickname]/activity => activity * - /feed/[nickname]/activity => activity
* *
* The nocache GET parameter is provided mainly for debug purposes, requires auth * The nocache GET parameter is provided mainly for debug purposes, requires auth
* *
* @brief Provides public Atom feeds * @brief Provides public Atom feeds
* *
* @author Hypolite Petovan <mrpetovan@gmail.com> * @author Hypolite Petovan <mrpetovan@gmail.com>
*/ */
class Feed extends BaseModule class Feed extends BaseModule
{ {
public static function content() public static function content()
{ {
$a = self::getApp(); $a = self::getApp();
$last_update = x($_GET, 'last_update') ? $_GET['last_update'] : ''; $last_update = x($_GET, 'last_update') ? $_GET['last_update'] : '';
$nocache = x($_GET, 'nocache') && local_user(); $nocache = x($_GET, 'nocache') && local_user();
if ($a->argc < 2) { if ($a->argc < 2) {
System::httpExit(400); System::httpExit(400);
} }
$type = null; $type = null;
if ($a->argc > 2) { if ($a->argc > 2) {
$type = $a->argv[2]; $type = $a->argv[2];
} }
switch ($type) { switch ($type) {
case 'posts': case 'posts':
case 'comments': case 'comments':
case 'activity': case 'activity':
break; break;
case 'replies': case 'replies':
$type = 'comments'; $type = 'comments';
break; break;
default: default:
$type = 'posts'; $type = 'posts';
} }
$nickname = $a->argv[1]; $nickname = $a->argv[1];
header("Content-type: application/atom+xml"); header("Content-type: application/atom+xml");
echo OStatus::feed($nickname, $last_update, 10, $type, $nocache); echo OStatus::feed($nickname, $last_update, 10, $type, $nocache);
killme(); killme();
} }
} }

View file

@ -1,31 +1,31 @@
<?php <?php
/** /**
* @file src/Module/Logout.php * @file src/Module/Logout.php
*/ */
namespace Friendica\Module; namespace Friendica\Module;
use Friendica\BaseModule; use Friendica\BaseModule;
use Friendica\Core\Addon; use Friendica\Core\Addon;
use Friendica\Core\L10n; use Friendica\Core\L10n;
require_once 'boot.php'; require_once 'boot.php';
require_once 'include/security.php'; require_once 'include/security.php';
/** /**
* Logout module * Logout module
* *
* @author Hypolite Petovan mrpetovan@gmail.com * @author Hypolite Petovan mrpetovan@gmail.com
*/ */
class Logout extends BaseModule class Logout extends BaseModule
{ {
/** /**
* @brief Process logout requests * @brief Process logout requests
*/ */
public static function init() public static function init()
{ {
Addon::callHooks("logging_out"); Addon::callHooks("logging_out");
nuke_session(); nuke_session();
info(L10n::t('Logged out.') . EOL); info(L10n::t('Logged out.') . EOL);
goaway(self::getApp()->get_baseurl()); goaway(self::getApp()->get_baseurl());
} }
} }

View file

@ -1,53 +1,53 @@
<?php <?php
namespace Friendica\Module; namespace Friendica\Module;
use Friendica\BaseModule; use Friendica\BaseModule;
use Friendica\Content; use Friendica\Content;
/** /**
* Oembed module * Oembed module
* *
* Displays stored embed content based on a base64 hash of a remote URL * Displays stored embed content based on a base64 hash of a remote URL
* *
* Example: /oembed/aHR0cHM6Ly9... * Example: /oembed/aHR0cHM6Ly9...
* *
* @author Hypolite Petovan <mrpetovan@gmail.com> * @author Hypolite Petovan <mrpetovan@gmail.com>
*/ */
class Oembed extends BaseModule class Oembed extends BaseModule
{ {
public static function content() public static function content()
{ {
$a = self::getApp(); $a = self::getApp();
// Unused form: /oembed/b2h?url=... // Unused form: /oembed/b2h?url=...
if ($a->argv[1] == 'b2h') { if ($a->argv[1] == 'b2h') {
$url = ["", trim(hex2bin($_REQUEST['url']))]; $url = ["", trim(hex2bin($_REQUEST['url']))];
echo Content\OEmbed::replaceCallback($url); echo Content\OEmbed::replaceCallback($url);
killme(); killme();
} }
// Unused form: /oembed/h2b?text=... // Unused form: /oembed/h2b?text=...
if ($a->argv[1] == 'h2b') { if ($a->argv[1] == 'h2b') {
$text = trim(hex2bin($_REQUEST['text'])); $text = trim(hex2bin($_REQUEST['text']));
echo Content\OEmbed::HTML2BBCode($text); echo Content\OEmbed::HTML2BBCode($text);
killme(); killme();
} }
if ($a->argc == 2) { if ($a->argc == 2) {
echo '<html><body>'; echo '<html><body>';
$url = base64url_decode($a->argv[1]); $url = base64url_decode($a->argv[1]);
$j = Content\OEmbed::fetchURL($url); $j = Content\OEmbed::fetchURL($url);
// workaround for media.ccc.de (and any other endpoint that return size 0) // workaround for media.ccc.de (and any other endpoint that return size 0)
if (substr($j->html, 0, 7) == "<iframe" && strstr($j->html, 'width="0"')) { if (substr($j->html, 0, 7) == "<iframe" && strstr($j->html, 'width="0"')) {
$j->html = '<style>html,body{margin:0;padding:0;} iframe{width:100%;height:100%;}</style>' . $j->html; $j->html = '<style>html,body{margin:0;padding:0;} iframe{width:100%;height:100%;}</style>' . $j->html;
$j->html = str_replace('width="0"', '', $j->html); $j->html = str_replace('width="0"', '', $j->html);
$j->html = str_replace('height="0"', '', $j->html); $j->html = str_replace('height="0"', '', $j->html);
} }
echo $j->html; echo $j->html;
echo '</body></html>'; echo '</body></html>';
} }
killme(); killme();
} }
} }

View file

@ -1,27 +1,27 @@
<?php <?php
/** /**
* Throwable exceptions to return HTTP status code * Throwable exceptions to return HTTP status code
* *
* This list of Exception has be extracted from * This list of Exception has be extracted from
* here http://racksburg.com/choosing-an-http-status-code/ * here http://racksburg.com/choosing-an-http-status-code/
*/ */
namespace Friendica\Network; namespace Friendica\Network;
use Exception; use Exception;
class HTTPException extends Exception class HTTPException extends Exception
{ {
var $httpcode = 200; var $httpcode = 200;
var $httpdesc = ""; var $httpdesc = "";
public function __construct($message = '', $code = 0, Exception $previous = null) public function __construct($message = '', $code = 0, Exception $previous = null)
{ {
if ($this->httpdesc == '') { if ($this->httpdesc == '') {
$classname = str_replace('Exception', '', str_replace('Friendica\Network\HTTPException\\', '', get_class($this))); $classname = str_replace('Exception', '', str_replace('Friendica\Network\HTTPException\\', '', get_class($this)));
$this->httpdesc = preg_replace("|([a-z])([A-Z])|",'$1 $2', $classname); $this->httpdesc = preg_replace("|([a-z])([A-Z])|",'$1 $2', $classname);
} }
parent::__construct($message, $code, $previous); parent::__construct($message, $code, $previous);
} }
} }

View file

@ -1,10 +1,10 @@
<?php <?php
namespace Friendica\Network\HTTPException; namespace Friendica\Network\HTTPException;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
class BadGatewayException extends HTTPException class BadGatewayException extends HTTPException
{ {
var $httpcode = 502; var $httpcode = 502;
} }

View file

@ -1,10 +1,10 @@
<?php <?php
namespace Friendica\Network\HTTPException; namespace Friendica\Network\HTTPException;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
class BadRequestException extends HTTPException class BadRequestException extends HTTPException
{ {
var $httpcode = 400; var $httpcode = 400;
} }

View file

@ -1,10 +1,10 @@
<?php <?php
namespace Friendica\Network\HTTPException; namespace Friendica\Network\HTTPException;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
class ConflictException extends HTTPException class ConflictException extends HTTPException
{ {
var $httpcode = 409; var $httpcode = 409;
} }

View file

@ -1,10 +1,10 @@
<?php <?php
namespace Friendica\Network\HTTPException; namespace Friendica\Network\HTTPException;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
class ExpectationFailedException extends HTTPException class ExpectationFailedException extends HTTPException
{ {
var $httpcode = 417; var $httpcode = 417;
} }

View file

@ -1,10 +1,10 @@
<?php <?php
namespace Friendica\Network\HTTPException; namespace Friendica\Network\HTTPException;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
class ForbiddenException extends HTTPException class ForbiddenException extends HTTPException
{ {
var $httpcode = 403; var $httpcode = 403;
} }

View file

@ -1,10 +1,10 @@
<?php <?php
namespace Friendica\Network\HTTPException; namespace Friendica\Network\HTTPException;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
class GatewayTimeoutException extends HTTPException class GatewayTimeoutException extends HTTPException
{ {
var $httpcode = 504; var $httpcode = 504;
} }

View file

@ -1,10 +1,10 @@
<?php <?php
namespace Friendica\Network\HTTPException; namespace Friendica\Network\HTTPException;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
class GoneException extends HTTPException class GoneException extends HTTPException
{ {
var $httpcode = 410; var $httpcode = 410;
} }

View file

@ -1,11 +1,11 @@
<?php <?php
namespace Friendica\Network\HTTPException; namespace Friendica\Network\HTTPException;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
class ImATeapotException extends HTTPException class ImATeapotException extends HTTPException
{ {
var $httpcode = 418; var $httpcode = 418;
var $httpdesc = "I'm A Teapot"; var $httpdesc = "I'm A Teapot";
} }

View file

@ -1,10 +1,10 @@
<?php <?php
namespace Friendica\Network\HTTPException; namespace Friendica\Network\HTTPException;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
class InternalServerErrorException extends HTTPException class InternalServerErrorException extends HTTPException
{ {
var $httpcode = 500; var $httpcode = 500;
} }

View file

@ -1,10 +1,10 @@
<?php <?php
namespace Friendica\Network\HTTPException; namespace Friendica\Network\HTTPException;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
class LenghtRequiredException extends HTTPException class LenghtRequiredException extends HTTPException
{ {
var $httpcode = 411; var $httpcode = 411;
} }

View file

@ -1,10 +1,10 @@
<?php <?php
namespace Friendica\Network\HTTPException; namespace Friendica\Network\HTTPException;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
class MethodNotAllowedException extends HTTPException class MethodNotAllowedException extends HTTPException
{ {
var $httpcode = 405; var $httpcode = 405;
} }

View file

@ -1,10 +1,10 @@
<?php <?php
namespace Friendica\Network\HTTPException; namespace Friendica\Network\HTTPException;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
class NonAcceptableException extends HTTPException class NonAcceptableException extends HTTPException
{ {
var $httpcode = 406; var $httpcode = 406;
} }

View file

@ -1,9 +1,9 @@
<?php <?php
namespace Friendica\Network\HTTPException; namespace Friendica\Network\HTTPException;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
class NotFoundException extends HTTPException { class NotFoundException extends HTTPException {
var $httpcode = 404; var $httpcode = 404;
} }

View file

@ -1,10 +1,10 @@
<?php <?php
namespace Friendica\Network\HTTPException; namespace Friendica\Network\HTTPException;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
class NotImplementedException extends HTTPException class NotImplementedException extends HTTPException
{ {
var $httpcode = 501; var $httpcode = 501;
} }

View file

@ -1,10 +1,10 @@
<?php <?php
namespace Friendica\Network\HTTPException; namespace Friendica\Network\HTTPException;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
class PreconditionFailedException extends HTTPException class PreconditionFailedException extends HTTPException
{ {
var $httpcode = 412; var $httpcode = 412;
} }

View file

@ -1,10 +1,10 @@
<?php <?php
namespace Friendica\Network\HTTPException; namespace Friendica\Network\HTTPException;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
class ServiceUnavaiableException extends HTTPException class ServiceUnavaiableException extends HTTPException
{ {
var $httpcode = 503; var $httpcode = 503;
} }

View file

@ -1,10 +1,10 @@
<?php <?php
namespace Friendica\Network\HTTPException; namespace Friendica\Network\HTTPException;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
class TooManyRequestsException extends HTTPException class TooManyRequestsException extends HTTPException
{ {
var $httpcode = 429; var $httpcode = 429;
} }

View file

@ -1,10 +1,10 @@
<?php <?php
namespace Friendica\Network\HTTPException; namespace Friendica\Network\HTTPException;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
class UnauthorizedException extends HTTPException class UnauthorizedException extends HTTPException
{ {
var $httpcode = 401; var $httpcode = 401;
} }

View file

@ -1,10 +1,10 @@
<?php <?php
namespace Friendica\Network\HTTPException; namespace Friendica\Network\HTTPException;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
class UnprocessableEntityException extends HTTPException class UnprocessableEntityException extends HTTPException
{ {
var $httpcode = 422; var $httpcode = 422;
} }

View file

@ -1,10 +1,10 @@
<?php <?php
namespace Friendica\Network\HTTPException; namespace Friendica\Network\HTTPException;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
class UnsupportedMediaTypeException extends HTTPException class UnsupportedMediaTypeException extends HTTPException
{ {
var $httpcode = 415; var $httpcode = 415;
} }

View file

@ -1,56 +1,56 @@
<?php <?php
/** /**
* @file src/Render/FriendicaSmarty.php * @file src/Render/FriendicaSmarty.php
*/ */
namespace Friendica\Render; namespace Friendica\Render;
use Smarty; use Smarty;
/** /**
* Friendica extension of the Smarty3 template engine * Friendica extension of the Smarty3 template engine
* *
* @author Hypolite Petovan <mrpetovan@gmail.com> * @author Hypolite Petovan <mrpetovan@gmail.com>
*/ */
class FriendicaSmarty extends Smarty class FriendicaSmarty extends Smarty
{ {
const SMARTY3_TEMPLATE_FOLDER = 'templates'; const SMARTY3_TEMPLATE_FOLDER = 'templates';
public $filename; public $filename;
function __construct() function __construct()
{ {
parent::__construct(); parent::__construct();
$a = get_app(); $a = get_app();
$theme = current_theme(); $theme = current_theme();
// setTemplateDir can be set to an array, which Smarty will parse in order. // setTemplateDir can be set to an array, which Smarty will parse in order.
// The order is thus very important here // The order is thus very important here
$template_dirs = ['theme' => "view/theme/$theme/" . self::SMARTY3_TEMPLATE_FOLDER . "/"]; $template_dirs = ['theme' => "view/theme/$theme/" . self::SMARTY3_TEMPLATE_FOLDER . "/"];
if (x($a->theme_info, "extends")) { if (x($a->theme_info, "extends")) {
$template_dirs = $template_dirs + ['extends' => "view/theme/" . $a->theme_info["extends"] . "/" . self::SMARTY3_TEMPLATE_FOLDER . "/"]; $template_dirs = $template_dirs + ['extends' => "view/theme/" . $a->theme_info["extends"] . "/" . self::SMARTY3_TEMPLATE_FOLDER . "/"];
} }
$template_dirs = $template_dirs + ['base' => "view/" . self::SMARTY3_TEMPLATE_FOLDER . "/"]; $template_dirs = $template_dirs + ['base' => "view/" . self::SMARTY3_TEMPLATE_FOLDER . "/"];
$this->setTemplateDir($template_dirs); $this->setTemplateDir($template_dirs);
$this->setCompileDir('view/smarty3/compiled/'); $this->setCompileDir('view/smarty3/compiled/');
$this->setConfigDir('view/smarty3/config/'); $this->setConfigDir('view/smarty3/config/');
$this->setCacheDir('view/smarty3/cache/'); $this->setCacheDir('view/smarty3/cache/');
$this->left_delimiter = $a->get_template_ldelim('smarty3'); $this->left_delimiter = $a->get_template_ldelim('smarty3');
$this->right_delimiter = $a->get_template_rdelim('smarty3'); $this->right_delimiter = $a->get_template_rdelim('smarty3');
// Don't report errors so verbosely // Don't report errors so verbosely
$this->error_reporting = E_ALL & ~E_NOTICE; $this->error_reporting = E_ALL & ~E_NOTICE;
} }
function parsed($template = '') function parsed($template = '')
{ {
if ($template) { if ($template) {
return $this->fetch('string:' . $template); return $this->fetch('string:' . $template);
} }
return $this->fetch('file:' . $this->filename); return $this->fetch('file:' . $this->filename);
} }
} }

View file

@ -1,15 +1,15 @@
<?php <?php
/** /**
* @file src/Render/ITemplateEngine.php * @file src/Render/ITemplateEngine.php
*/ */
namespace Friendica\Render; namespace Friendica\Render;
/** /**
* Interface for template engines * Interface for template engines
*/ */
interface ITemplateEngine interface ITemplateEngine
{ {
public function replaceMacros($s, $v); public function replaceMacros($s, $v);
public function getTemplateFile($file, $root = ''); public function getTemplateFile($file, $root = '');
} }