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

View file

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

View file

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

View file

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