-# Disable LF normalization for all files\r
-* -text
\ No newline at end of file
+# Disable LF normalization for all files
+* -text
-favicon.*\r
-.htconfig.php\r
-.htpreconfig.php\r
-\#*\r
-include/jquery-1.4.2.min.js\r
-*.log\r
-*.out\r
-*.version*\r
-favicon.*\r
-home.html\r
-addon\r
-*.orig\r
-*~\r
-robots.txt\r
-\r
-#ignore documentation, it should be newly built\r
-doc/html\r
-\r
-#ignore reports, should be generted with every build\r
-report/\r
-\r
-#ignore config files from eclipse, we don't want IDE files in our repository\r
-.project\r
-.buildpath\r
-.externalToolBuilders\r
-.settings\r
-#ignore OSX .DS_Store files\r
-.DS_Store\r
-\r
-/nbproject/private/\r
-\r
-#ignore smarty cache\r
-/view/smarty3/compiled/\r
-\r
-#ignore cache folders\r
-/privacy_image_cache/\r
-/photo/\r
-/proxy/\r
-nbproject\r
-\r
-#ignore vagrant dir\r
-.vagrant/\r
-\r
-#ignore local folder\r
-/local/\r
-\r
-#ignore config files from Visual Studio\r
-/.vs/\r
-/php_friendica.phpproj\r
-/php_friendica.sln\r
-/php_friendica.phpproj.user\r
-\r
-#ignore things from transifex-client\r
-venv/\r
-\r
-#ignore Composer dependencies\r
-/vendor\r
-/view/asset\r
-\r
-#ignore config files from JetBrains\r
-/.idea\r
+favicon.*
+.htconfig.php
+.htpreconfig.php
+\#*
+include/jquery-1.4.2.min.js
+*.log
+*.out
+*.version*
+favicon.*
+home.html
+addon
+*~
+robots.txt
+
+#ignore documentation, it should be newly built
+doc/html
+
+#ignore reports, should be generted with every build
+report/
+
+#ignore config files from eclipse, we don't want IDE files in our repository
+.project
+.buildpath
+.externalToolBuilders
+.settings
+
+#ignore OSX .DS_Store files
+.DS_Store
+
+#ignore NetBeans IDE's private files (at least)
+/nbproject/private/
+
+#ignore smarty cache
+/view/smarty3/compiled/
+
+#ignore cache folders
+/privacy_image_cache/
+/photo/
+/proxy/
+nbproject
+
+#ignore vagrant dir
+.vagrant/
+
+#ignore local folder
+/local/
+
+#ignore config files from Visual Studio
+/.vs/
+/php_friendica.phpproj
+/php_friendica.sln
+/php_friendica.phpproj.user
+
+#ignore things from transifex-client
+venv/
+
+#ignore all in 'vendor' as `utils/composer.phar install` will bring it back
+vendor/*
+
+#ignore config files from JetBrains
+/.idea
+
+#ignore addons/ directory
+addons/
#AddHandler php53-cgi .php
<FilesMatch "\.(out|log)$">
- <IfModule authz_host_module>
+ <IfModule authz_host_module>
#Apache 2.4
Require all denied
</IfModule>
RewriteRule ^(.*)$ index.php?pagename=$1 [E=REMOTE_USER:%{HTTP:Authorization},L,QSA]
</IfModule>
-
}
$directory = realpath($directory."/..");
-@include($directory."/.htconfig.php");
+include $directory."/.htconfig.php";
if (!isset($pidfile)) {
die('Please specify a pid file in the variable $pidfile in the .htconfig.php. For example:'."\n".
$adminlist = explode(",", str_replace(" ", "", $a->config['admin_email']));
//if(local_user() && x($a->user,'email') && x($a->config,'admin_email') && ($a->user['email'] === $a->config['admin_email']))
+ /// @TODO This if() + 2 returns can be shrinked into one return
if (local_user() && x($a->user, 'email') && x($a->config, 'admin_email') && in_array($a->user['email'], $adminlist)) {
return true;
}
{
$rn = '';
for ($i = 0; $i < $digits; $i++) {
- /// @TODO rand() is different to mt_rand() and maybe lesser "random"
+ /// @TODO Avoid rand/mt_rand, when it comes to cryptography, they are generating predictable (seedable) numbers.
$rn .= rand(0, 9);
}
return $rn;
$server = "https://dir.friendica.social";
}
- return($server);
+ return $server;
}
function get_temppath()
$cache = get_itemcachepath();
if ((!$cache) || (!is_dir($cache))) {
- return("");
+ return "";
}
$subfolder = $cache . "/" . substr($file, 0, 2);
}
}
- /// @TODO no need to put braces here
return $cachepath;
}
return "";
}
-
if (!function_exists('exif_imagetype')) {
function exif_imagetype($file)
{
}
// Simply return flag
- return ($valid);
+ return $valid;
}
function current_load()
$db_pass = 'db_password';
$db_data = 'database_name';
+Sollten alle der folgenden Environment-Variablen gesetzt sein, wird Friendica diese anstatt der vorher konfigurierten Werte nutzen.
+
+ MYSQL_HOST
+ MYSQL_PORT
+ MYSQL_USERNAME
+ MYSQL_PASSWORD
+ MYSQL_DATABASE
+
## Administratoren
Du kannst einen, oder mehrere Accounts, zu Administratoren machen.
If you need to specify a port to access the database, you can do so by appending ":portnumber" to the db_host variable.
$db_host = 'your.mysqlhost.com:123456';
+
+If all of the following environment variables are set, Friendica will use them instead of the previously configured variables for the db:
+
+ MYSQL_HOST
+ MYSQL_PORT
+ MYSQL_USERNAME
+ MYSQL_PASSWORD
+ MYSQL_DATABASE
*
* @return string The XML data
*/
-function api_create_xml($data, $root_element)
+function api_create_xml(array $data, $root_element)
{
$childname = key($data);
$data2 = array_pop($data);
$i = 1;
foreach ($data2 as $item) {
- $data4[$i++.":".$childname] = $item;
+ $data4[$i++ . ":" . $childname] = $item;
}
$data2 = $data4;
throw new InternalServerErrorException("unknown error - this error on uploading or updating a photo should never happen");
}
-
/**
* @brief delete a single photo from the database through api
*
} else {
throw new InternalServerErrorException('Unsupported filetype');
}
+
// change specified profile or all profiles to the new resource-id
if ($is_default_profile) {
$condition = ["`profile` AND `resource-id` != ? AND `uid` = ?", $data['photo']['id'], api_user()];
Contact::updateSelfFromUserID(api_user(), true);
// Update global directory in background
- //$user = api_get_user(get_app());
$url = System::baseUrl() . '/profile/' . get_app()->user['nickname'];
if ($url && strlen(Config::get('system', 'directory'))) {
Worker::add(PRIORITY_LOW, "Directory", $url);
/**
*
- * @param string $Text
+ * @param string $text
*
* @return string
*/
-function api_clean_plain_items($Text)
+function api_clean_plain_items($text)
{
$include_entities = strtolower(x($_REQUEST, 'include_entities') ? $_REQUEST['include_entities'] : "false");
- $Text = BBCode::cleanPictureLinks($Text);
+ $text = BBCode::cleanPictureLinks($text);
$URLSearchString = "^\[\]";
- $Text = preg_replace("/([!#@])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$1$3', $Text);
+ $text = preg_replace("/([!#@])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$1$3', $text);
if ($include_entities == "true") {
- $Text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '[url=$1]$1[/url]', $Text);
+ $text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '[url=$1]$1[/url]', $text);
}
// Simplify "attachment" element
- $Text = api_clean_attachments($Text);
+ $text = api_clean_attachments($text);
- return($Text);
+ return $text;
}
/**
$item['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $item['contact-id']);
}
- /// @Separted ???
+ /// @TODO Separted ???
$xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
if (activity_match($item['verb'], ACTIVITY_LIKE)
|| activity_match($item['verb'], ACTIVITY_DISLIKE)
if (activity_match($item['verb'], ACTIVITY_LIKE)) {
$bodyverb = L10n::t('%1$s likes %2$s\'s %3$s');
- }
- elseif (activity_match($item['verb'], ACTIVITY_DISLIKE)) {
+ } elseif (activity_match($item['verb'], ACTIVITY_DISLIKE)) {
$bodyverb = L10n::t('%1$s doesn\'t like %2$s\'s %3$s');
- }
- elseif (activity_match($item['verb'], ACTIVITY_ATTEND)) {
+ } elseif (activity_match($item['verb'], ACTIVITY_ATTEND)) {
$bodyverb = L10n::t('%1$s attends %2$s\'s %3$s');
- }
- elseif (activity_match($item['verb'], ACTIVITY_ATTENDNO)) {
+ } elseif (activity_match($item['verb'], ACTIVITY_ATTENDNO)) {
$bodyverb = L10n::t('%1$s doesn\'t attend %2$s\'s %3$s');
- }
- elseif (activity_match($item['verb'], ACTIVITY_ATTENDMAYBE)) {
+ } elseif (activity_match($item['verb'], ACTIVITY_ATTENDMAYBE)) {
$bodyverb = L10n::t('%1$s attends maybe %2$s\'s %3$s');
}
- $item['body'] = sprintf($bodyverb, $author, $objauthor, $plink);
+ $item['body'] = sprintf($bodyverb, $author, $objauthor, $plink);
}
+
if (activity_match($item['verb'], ACTIVITY_FRIEND)) {
if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) return;
$item['body'] = L10n::t('%1$s tagged %2$s\'s %3$s with %4$s', $author, $objauthor, $plink, $tag );
}
- if (activity_match($item['verb'], ACTIVITY_FAVORITE)) {
+ if (activity_match($item['verb'], ACTIVITY_FAVORITE)) {
if ($item['object-type'] == "") {
return;
}
}
}
- if (activity_match($item['verb'], ACTIVITY_FOLLOW) && $item['object-type'] === ACTIVITY_OBJ_NOTE) {
- if (!($item['self'] && ($item['uid'] == local_user()))) {
- return false;
- }
+ // @TODO below if() block can be rewritten to a single line: $isVisible = allConditionsHere;
+ if (activity_match($item['verb'], ACTIVITY_FOLLOW) && $item['object-type'] === ACTIVITY_OBJ_NOTE && empty($item['self']) && $item['uid'] == local_user()) {
+ return false;
}
return true;
$url = '<a href="'. $url . '"'. $sparkle .'>' . htmlentities($item['author-name']) . '</a>';
- if (!$item['thr-parent']) {
+ if (!x($item, 'thr-parent')) {
$item['thr-parent'] = $item['parent-uri'];
}
return strcmp($b['commented'], $a['commented']);
}
-/// @TODO Add type-hint
-function render_location_dummy($item) {
- if ($item['location'] != "") {
+function render_location_dummy(array $item) {
+ if (x($item, 'location') && !empty($item['location'])) {
return $item['location'];
}
- if ($item['coord'] != "") {
+ if (x($item, 'coord') && !empty($item['coord'])) {
return $item['coord'];
}
}
-/// @TODO Add type-hint
-function get_responses($conv_responses, $response_verbs, $ob, $item) {
+function get_responses(array $conv_responses, array $response_verbs, $ob, array $item) {
$ret = [];
foreach ($response_verbs as $v) {
$ret[$v] = [];
function subscribe_to_hub($url, $importer, $contact, $hubmode = 'subscribe') {
$a = get_app();
+ $r = null;
if (is_array($importer)) {
$r = q("SELECT `nickname` FROM `user` WHERE `uid` = %d LIMIT 1",
return false;
}
+/// @TODO $groups should be array
function permissions_sql($owner_id, $remote_verified = false, $groups = null)
{
$local_user = local_user();
*/
if ($local_user && $local_user == $owner_id) {
$sql = '';
+ /**
+ * Authenticated visitor. Unless pre-verified,
+ * check that the contact belongs to this $owner_id
+ * and load the groups the visitor belongs to.
+ * If pre-verified, the caller is expected to have already
+ * done this and passed the groups into this function.
+ */
} elseif ($remote_user) {
/*
* Authenticated visitor. Unless pre-verified,
if ($remote_verified) {
$gs = '<<>>'; // should be impossible to match
- if (is_array($groups) && count($groups)) {
- foreach ($groups as $g)
+ if (is_array($groups)) {
+ foreach ($groups as $g) {
$gs .= '|<' . intval($g) . '>';
+ }
}
$sql = sprintf(
break;
}
}
+
if (substr($word, -1) == 'q') {
$word = substr($word, 0, -1);
}
if (is_array($p)) {
$tmp = $p;
} else {
- $tmp = explode(',',$p);
+ $tmp = explode(',', $p);
}
if (is_array($tmp)) {
$r = preg_match_all("/\[video\](.*?)\[\/video\]/ism",$s,$matches,PREG_SET_ORDER);
if ($r) {
foreach ($matches as $mtch) {
- if ((stristr($mtch[1],'youtube')) || (stristr($mtch[1],'youtu.be')))
- $s = str_replace($mtch[0],'[youtube]' . $mtch[1] . '[/youtube]',$s);
- elseif (stristr($mtch[1],'vimeo'))
- $s = str_replace($mtch[0],'[vimeo]' . $mtch[1] . '[/vimeo]',$s);
+ if ((stristr($mtch[1], 'youtube')) || (stristr($mtch[1], 'youtu.be'))) {
+ $s = str_replace($mtch[0], '[youtube]' . $mtch[1] . '[/youtube]', $s);
+ } elseif (stristr($mtch[1], 'vimeo')) {
+ $s = str_replace($mtch[0], '[vimeo]' . $mtch[1] . '[/vimeo]', $s);
+ }
}
}
return $s;
}
// ex. given music,video return <music><video> or [music][video]
-function file_tag_list_to_file($list,$type = 'file') {
+function file_tag_list_to_file($list, $type = 'file') {
$tag_list = '';
if (strlen($list)) {
$list_array = explode(",",$list);
}
// ex. given <music><video>[friends], return music,video or friends
-function file_tag_file_to_list($file,$type = 'file') {
+function file_tag_file_to_list($file, $type = 'file') {
$matches = false;
$list = '';
if ($type == 'file') {
if (!intval($uid)) {
return false;
- }
- if ($file_old == $file_new) {
+ } elseif ($file_old == $file_new) {
return true;
}
$check_new_tags = explode(",",file_tag_file_to_list($file_new,$type));
foreach ($check_new_tags as $tag) {
- if (! stristr($saved,$lbracket . file_tag_encode($tag) . $rbracket))
+ if (! stristr($saved,$lbracket . file_tag_encode($tag) . $rbracket)) {
$new_tags[] = $tag;
+ }
}
$filetags_updated .= file_tag_list_to_file(implode(",",$new_tags),$type);
$check_deleted_tags = explode(",",file_tag_file_to_list($file_old,$type));
foreach ($check_deleted_tags as $tag) {
- if (! stristr($file_new,$lbracket . file_tag_encode($tag) . $rbracket))
+ if (! stristr($file_new,$lbracket . file_tag_encode($tag) . $rbracket)) {
$deleted_tags[] = $tag;
+ }
}
foreach ($deleted_tags as $key => $tag) {
return str_replace('%', '%%', $s);
}
-
+/// @TODO Rewrite this
function is_a_date_arg($s) {
$i = intval($s);
+
if ($i > 1900) {
$y = date('Y');
+
if ($i <= $y + 1 && strpos($s, '-') == 4) {
- $m = intval(substr($s,5));
- if ($m > 0 && $m <= 12)
+ $m = intval(substr($s, 5));
+
+ if ($m > 0 && $m <= 12) {
return true;
+ }
}
}
+
return false;
}
preg_match("|^" . $chr . "*|", $lines[$k], $m);
$count = strlen($m[0]);
}
+
for ($k = 0; $k < count($lines); $k++) {
$lines[$k] = preg_replace("|^" . $chr . "{" . $count . "}|", "", $lines[$k]);
}
case 'addons':
if ($a->argc > 2 &&
is_file("addon/" . $a->argv[2] . "/" . $a->argv[2] . ".php")) {
- @include_once("addon/" . $a->argv[2] . "/" . $a->argv[2] . ".php");
+ include_once "addon/" . $a->argv[2] . "/" . $a->argv[2] . ".php";
if (function_exists($a->argv[2] . '_addon_admin_post')) {
$func = $a->argv[2] . '_addon_admin_post';
$func($a);
$upds = implode(", ", $upd);
$r = q("UPDATE %s SET %s;", $table_name, $upds);
+
if (!DBM::is_result($r)) {
notice("Failed updating '$table_name': " . dba::errorMessage());
goaway('admin/site');
$user_names = [];
$user_names['---'] = L10n::t('Multi user instance');
$users = q("SELECT `username`, `nickname` FROM `user`");
+
foreach ($users as $user) {
$user_names[$user['nickname']] = $user['username'];
}
/* Banner */
$banner = Config::get('system', 'banner');
+
if ($banner == false) {
$banner = '<a href="https://friendi.ca"><img id="logo-img" src="images/friendica-32.png" alt="logo" /></a><span id="logo-text"><a href="https://friendi.ca">Friendica</a></span>';
}
+
$banner = htmlspecialchars($banner);
$info = Config::get('config', 'info');
$info = htmlspecialchars($info);
if ($a->argc > 2 && intval($a->argv[2])) {
require_once 'update.php';
+
$func = 'update_' . intval($a->argv[2]);
+
if (function_exists($func)) {
$retval = $func();
+
if ($retval === UPDATE_FAILED) {
$o .= L10n::t("Executing %s failed with error: %s", $func, $retval);
} elseif ($retval === UPDATE_SUCCESS) {
$o .= L10n::t('There was no additional update function %s that needed to be called.', $func) . "<br />";
Config::set('database', $func, 'success');
}
+
return $o;
}
$failed = [];
$r = q("SELECT `k`, `v` FROM `config` WHERE `cat` = 'database' ");
+
if (DBM::is_result($r)) {
foreach ($r as $rr) {
$upd = intval(substr($rr['k'], 7));
$failed[] = $upd;
}
}
+
if (!count($failed)) {
$o = replace_macros(get_markup_template('structure_check.tpl'), [
'$base' => System::baseUrl(true),
$e['page-flags-raw'] = $e['page-flags'];
$e['page-flags'] = $page_types[$e['page-flags']];
- $e['account-type-raw'] = ($e['page_flags_raw']==0) ? $e['account-type'] : -1;
- $e['account-type'] = ($e['page_flags_raw']==0) ? $account_types[$e['account-type']] : "";
+ $e['account-type-raw'] = ($e['page_flags_raw'] == 0) ? $e['account-type'] : -1;
+ $e['account-type'] = ($e['page_flags_raw'] == 0) ? $account_types[$e['account-type']] : "";
$e['register_date'] = Temporal::getRelativeDate($e['register_date']);
$e['login_date'] = Temporal::getRelativeDate($e['login_date']);
$admin_form = "";
if (in_array($addon, $a->addons_admin)) {
- @require_once("addon/$addon/$addon.php");
+ require_once "addon/$addon/$addon.php";
$func = $addon . '_addon_admin';
$func($a, $admin_form);
}
}
$readme = null;
+
if (is_file("view/theme/$theme/README.md")) {
$readme = Markdown::convert(file_get_contents("view/theme/$theme/README.md"), false);
} elseif (is_file("view/theme/$theme/README")) {
if (x($_REQUEST, 'location')) {$orig_event['location'] = $_REQUEST['location'];}
if (x($_REQUEST, 'start')) {$orig_event['start'] = $_REQUEST['start'];}
if (x($_REQUEST, 'finish')) {$orig_event['finish'] = $_REQUEST['finish'];}
+ if (x($_REQUEST,'finish')) $orig_event['finish'] = $_REQUEST['finish'];
$n_checked = ((x($orig_event) && $orig_event['nofinish']) ? ' checked="checked" ' : '');
$a_checked = ((x($orig_event) && $orig_event['adjust']) ? ' checked="checked" ' : '');
$prevlink = '';
$nextlink = '';
- /// @todo This query is totally bad, the whole functionality has to be changed
- // The query leads to a really intense used index.
- // By now we hide it if someone wants to.
+ /*
+ * @todo This query is totally bad, the whole functionality has to be changed
+ * The query leads to a really intense used index.
+ * By now we hide it if someone wants to.
+ */
if (!Config::get('system', 'no_count', false)) {
$order_field = defaults($_GET, 'order', '');
if ($order_field === 'posted') {
}
}
- if (count($ph) == 1)
+ if (count($ph) == 1) {
$hires = $lores = $ph[0];
+ }
+
if (count($ph) > 1) {
if ($ph[1]['scale'] == 2) {
// original is 640 or less, we can display it directly
}
$album_link = 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
+
$tools = null;
$lock = null;
]);
}
- if ($prevlink)
+ if ($prevlink) {
$prevlink = [$prevlink, '<div class="icon prev"></div>'] ;
+ }
$photo = [
'href' => 'photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
$twist = false;
foreach ($r as $rr) {
//hide profile photos to others
- if (!$is_owner && !remote_user() && ($rr['album'] == L10n::t('Profile Photos')))
+ if (!$is_owner && !remote_user() && ($rr['album'] == L10n::t('Profile Photos'))) {
continue;
+ }
$twist = !$twist;
echo json_encode($ret);
killme();
}
+
if ($a->argc > 1 && $a->argv[1] === '@global') {
// List of all profiles that this server recently had data from
$global = true;
function share_init(App $a) {
$post_id = (($a->argc > 1) ? intval($a->argv[1]) : 0);
+
if (!$post_id || !local_user()) {
killme();
}
WHERE `item`.`id` = %d LIMIT 1",
intval($post_id)
);
+
if (!DBM::is_result($r) || ($r[0]['private'] == 1)) {
killme();
}
+
if (strpos($r[0]['body'], "[/share]") !== false) {
$pos = strpos($r[0]['body'], "[share");
$o = substr($r[0]['body'], $pos);
} else {
$o = share_header($r[0]['author-name'], $r[0]['author-link'], $r[0]['author-avatar'], $r[0]['guid'], $r[0]['created'], $r[0]['plink']);
- if ($r[0]['title'])
+ if ($r[0]['title']) {
$o .= '[b]'.$r[0]['title'].'[/b]'."\n";
+ }
+
$o .= $r[0]['body'];
- $o.= "[/share]";
+ $o .= "[/share]";
}
echo $o;
killme();
}
+/// @TODO Rewrite to handle over whole record array
function share_header($author, $profile, $avatar, $guid, $posted, $link) {
- $header = "[share author='".str_replace(["'", "[", "]"], ["'", "[", "]"], $author).
- "' profile='".str_replace(["'", "[", "]"], ["'", "[", "]"], $profile).
- "' avatar='".str_replace(["'", "[", "]"], ["'", "[", "]"], $avatar);
+ $header = "[share author='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $author).
+ "' profile='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $profile).
+ "' avatar='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $avatar);
if ($guid) {
- $header .= "' guid='".str_replace(["'", "[", "]"], ["'", "[", "]"], $guid);
+ $header .= "' guid='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $guid);
}
+
if ($posted) {
- $header .= "' posted='".str_replace(["'", "[", "]"], ["'", "[", "]"], $posted);
+ $header .= "' posted='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $posted);
}
- $header .= "' link='".str_replace(["'", "[", "]"], ["'", "[", "]"], $link)."']";
+
+ $header .= "' link='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $link)."']";
return $header;
}
WHERE `contact`.`self` = 1 AND `contact`.`uid` = %d LIMIT 1",
intval($owner_uid)
);
- if (DBM::is_result($r))
+
+ if (DBM::is_result($r)) {
$owner = $r[0];
+ }
if (! $owner) {
logger('like: no owner');
return;
}
- if (! $remote_owner)
+ if (! $remote_owner) {
$remote_owner = $owner;
-
+ }
$contact = null;
// This represents the person posting
intval($_SESSION['visitor_id']),
intval($owner_uid)
);
- if (DBM::is_result($r))
+
+ if (DBM::is_result($r)) {
$contact = $r[0];
+ }
}
if (! $contact) {
return;
}
$term_objtype = ($item['resource-id'] ? TERM_OBJ_PHOTO : TERM_OBJ_POST);
- $t = q("SELECT count(tid) as tcount FROM term WHERE oid=%d AND term='%s'",
- intval($item['id']),
- dbesc($term)
- );
- if((! $blocktags) && $t[0]['tcount']==0 ) {
+
+ $t = q("SELECT count(tid) as tcount FROM term WHERE oid=%d AND term='%s'",
+ intval($item['id']),
+ dbesc($term)
+ );
+
+ if ((!$blocktags) && $t[0]['tcount'] == 0 ) {
q("INSERT INTO term (oid, otype, type, term, url, uid) VALUE (%d, %d, %d, '%s', '%s', %d)",
intval($item['id']),
$term_objtype,
// if the original post is on this site, update it.
- $r = q("select `tag`,`id`,`uid` from item where `origin` = 1 AND `uri` = '%s' LIMIT 1",
+ $r = q("SELECT `tag`,`id`,`uid` FROM `item` WHERE `origin`=1 AND `uri`='%s' LIMIT 1",
dbesc($item['uri'])
);
+
if (DBM::is_result($r)) {
- $x = q("SELECT `blocktags` FROM `user` WHERE `uid` = %d limit 1",
+ $x = q("SELECT `blocktags` FROM `user` WHERE `uid`=%d LIMIT 1",
intval($r[0]['uid'])
);
- $t = q("SELECT count(tid) as tcount FROM term WHERE oid=%d AND term='%s'",
+ $t = q("SELECT COUNT(`tid`) AS `tcount` FROM `term` WHERE `oid`=%d AND `term`='%s'",
intval($r[0]['id']),
dbesc($term)
);
- if(count($x) && !$x[0]['blocktags'] && $t[0]['tcount']==0){
- q("INSERT INTO term (oid, otype, type, term, url, uid) VALUE (%d, %d, %d, '%s', '%s', %d)",
- intval($r[0]['id']),
- $term_objtype,
- TERM_HASHTAG,
- dbesc($term),
- dbesc(System::baseUrl() . '/search?tag=' . $term),
- intval($owner_uid)
- );
+
+ if (DBM::is_result($x) && !$x[0]['blocktags'] && $t[0]['tcount'] == 0){
+ q("INSERT INTO term (`oid`, `otype`, `type`, `term`, `url`, `uid`) VALUE (%d, %d, %d, '%s', '%s', %d)",
+ intval($r[0]['id']),
+ $term_objtype,
+ TERM_HASHTAG,
+ dbesc($term),
+ dbesc(System::baseUrl() . '/search?tag=' . $term),
+ intval($owner_uid)
+ );
}
}
+++ /dev/null
-sample-Lighttpd.config
-sample-nginx.config
-
- Sample configuration files to use Friendica with Lighttpd
- or Nginx. Pleas check software documentation to know how modify
- these examples to make them work on your server.
-
-
-sample-systemd.timer
-sample-systemd.service
-
- Sample systemd unit files to start worker.php periodically.
-
- Please place them in the correct location for your system,
- typically this is /etc/systemd/system/friendicaworker.timer
- and /etc/systemd/system/friendicaworker.service.
- Please report problems and improvements to
- !helpers@forum.friendi.ca and @utzer@social.yl.ms or open an
- issue in Github (https://github.com/friendica/friendica/issues).
- This is for usage of systemd instead of cron to start the worker.php
- periodically, the solution is work-in-progress and can surely be improved.
-
-home.css
-home.html
-
- Example files to customize the landing page of your Friendica node.
- The home.html file contains the text of the page, the home.css file
- the style information. The login box will be added according to the
- other system settings.
- Both files have to be placed in the base directory of your Friendica
- installation to be used for the landing page.
--- /dev/null
+sample-Lighttpd.config
+sample-nginx.config
+
+ Sample configuration files to use Friendica with Lighttpd
+ or Nginx. Pleas check software documentation to know how modify
+ these examples to make them work on your server.
+
+
+sample-systemd.timer
+sample-systemd.service
+
+ Sample systemd unit files to start worker.php periodically.
+
+ Please place them in the correct location for your system,
+ typically this is /etc/systemd/system/friendicaworker.timer
+ and /etc/systemd/system/friendicaworker.service.
+ Please report problems and improvements to
+ !helpers@forum.friendi.ca and @utzer@social.yl.ms or open an
+ issue in Github (https://github.com/friendica/friendica/issues).
+ This is for usage of systemd instead of cron to start the worker.php
+ periodically, the solution is work-in-progress and can surely be improved.
+
+home.css
+home.html
+
+ Example files to customize the landing page of your Friendica node.
+ The home.html file contains the text of the page, the home.css file
+ the style information. The login box will be added according to the
+ other system settings.
+ Both files have to be placed in the base directory of your Friendica
+ installation to be used for the landing page.
self::$driver = new Cache\MemcachedCacheDriver($memcached_hosts);
break;
+ case 'redis':
+ $redis_host = Config::get('system', 'redis_host', '127.0.0.1');
+ $redis_port = Config::get('system', 'redis_port', 6379);
+
+ self::$driver = new Cache\RedisCacheDriver($redis_host, $redis_port);
+ break;
default:
self::$driver = new Cache\DatabaseCacheDriver();
}
--- /dev/null
+<?php
+
+namespace Friendica\Core\Cache;
+
+use Friendica\BaseObject;
+use Friendica\Core\Cache;
+
+/**
+ * Redis Cache Driver. This driver is based on Memcache driver
+ *
+ * @author Hypolite Petovan <mrpetovan@gmail.com>
+ * @author Roland Haeder <roland@mxchange.org>
+ */
+class RedisCacheDriver extends BaseObject implements ICacheDriver
+{
+ /**
+ * @var Redis
+ */
+ private $redis;
+
+ public function __construct($redis_host, $redis_port)
+ {
+ if (!class_exists('Redis', false)) {
+ throw new \Exception('Redis class isn\'t available');
+ }
+
+ $this->redis = new \Redis();
+
+ if (!$this->redis->connect($redis_host, $redis_port)) {
+ throw new \Exception('Expected Redis server at ' . $redis_host . ':' . $redis_port . ' isn\'t available');
+ }
+ }
+
+ public function get($key)
+ {
+ $return = null;
+
+ // We fetch with the hostname as key to avoid problems with other applications
+ $cached = $this->redis->get(self::getApp()->get_hostname() . ':' . $key);
+
+ // @see http://php.net/manual/en/redis.get.php#84275
+ if (is_bool($cached) || is_double($cached) || is_long($cached)) {
+ return $return;
+ }
+
+ $value = @unserialize($cached);
+
+ // Only return a value if the serialized value is valid.
+ // We also check if the db entry is a serialized
+ // boolean 'false' value (which we want to return).
+ if ($cached === serialize(false) || $value !== false) {
+ $return = $value;
+ }
+
+ return $return;
+ }
+
+ public function set($key, $value, $duration = Cache::MONTH)
+ {
+ // We store with the hostname as key to avoid problems with other applications
+ return $this->redis->set(
+ self::getApp()->get_hostname() . ":" . $key,
+ serialize($value),
+ time() + $duration
+ );
+ }
+
+ public function delete($key)
+ {
+ return $this->redis->delete($key);
+ }
+
+ public function clear()
+ {
+ return true;
+ }
+}
public static function init($uid)
{
- $a = self::getApp();
-
- if (isset($a->config['system']['config_adapter']) && $a->config['system']['config_adapter'] == 'preload') {
+ if (Config::get('system', 'config_adapter') == 'preload') {
self::$adapter = new Config\PreloadPConfigAdapter($uid);
} else {
self::$adapter = new Config\JITPConfigAdapter($uid);
logger("Load: ".$load."/".$maxsysload." - processes: ".$active."/".$entries.$processlist." - maximum: ".$queues."/".$maxqueues, LOGGER_DEBUG);
// Are there fewer workers running as possible? Then fork a new one.
- if (!Config::get("system", "worker_dont_fork") && ($queues > ($active + 1)) && ($entries > 1)) {
+ if (!Config::get("system", "worker_dont_fork", false) && ($queues > ($active + 1)) && ($entries > 1)) {
logger("Active workers: ".$active."/".$queues." Fork a new worker.", LOGGER_DEBUG);
self::spawnWorker();
}
}
$priority = PRIORITY_MEDIUM;
- $dont_fork = Config::get("system", "worker_dont_fork");
+ $dont_fork = Config::get("system", "worker_dont_fork", false);
$created = DateTimeFormat::utcNow();
$run_parameter = array_shift($args);
/**
* @brief Format an item array with event data to HTML.
*
- * @param arr $item Array with item and event data.
+ * @param array $item Array with item and event data.
* @return string HTML output.
*/
- public static function getItemHTML($item) {
+ public static function getItemHTML(array $item) {
$same_date = false;
$finish = false;
}
// Is this a shadow entry?
- if ($item['uid'] == 0)
+ if ($item['uid'] == 0) {
return;
+ }
// Is there a shadow parent?
if (!dba::exists('item', ['uri' => $item['parent-uri'], 'uid' => 0])) {
// If this was a comment to a Diaspora post we don't get our comment back.
// This means that we have to distribute the comment by ourselves.
- if ($origin) {
- if (dba::exists('item', ['id' => $parent, 'network' => NETWORK_DIASPORA])) {
- self::distribute($public_shadow);
- }
+ if ($origin && dba::exists('item', ['id' => $parent, 'network' => NETWORK_DIASPORA])) {
+ self::distribute($public_shadow);
}
}
*/
private static function addLanguageInPostopts(&$item)
{
+ $postopts = "";
+
if (!empty($item['postopts'])) {
if (strstr($item['postopts'], 'lang=')) {
// do not override
return;
}
$postopts = $item['postopts'];
- } else {
- $postopts = "";
}
$naked_body = Text\BBCode::toPlaintext($item['body'], false);
* @param array $owner Owner record
*
* @return string DFRN entries
- * @todo Add type-hints
+ * @todo Find proper type-hints
*/
public static function entries($items, $owner)
{
$root->appendChild($entry);
}
- return(trim($doc->saveXML()));
+ return trim($doc->saveXML());
}
/**
}
}
-
-
// default permissions - anonymous user
$sql_extra = " AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' ";
);
if (! DBM::is_result($r)) {
+ logger(sprintf('No contact found for nickname=%d', $owner_nick), LOGGER_WARNING);
killme();
}
);
if (! DBM::is_result($r)) {
+ logger(sprintf('No contact found for uid=%d', $owner_id), LOGGER_WARNING);
killme();
}
$groups = Group::getIdsByContactId($contact['id']);
if (count($groups)) {
- for ($x = 0; $x < count($groups); $x ++)
+ for ($x = 0; $x < count($groups); $x ++) {
$groups[$x] = '<' . intval($groups[$x]) . '>' ;
+ }
+
$gs = implode('|', $groups);
} else {
$gs = '<<>>' ; // Impossible to match
//$sql_extra .= file_tag_file_query('item',$category,'category');
}
- if ($public_feed) {
- if (! $converse) {
- $sql_extra .= " AND `contact`.`self` = 1 ";
- }
+ if ($public_feed && ! $converse) {
+ $sql_extra .= " AND `contact`.`self` = 1 ";
}
$check_date = DateTimeFormat::utc($last_update);
* @param array $owner Owner record
*
* @return string DFRN mail
- * @todo Add type-hints
+ * @todo Find proper type-hints
*/
public static function mail($item, $owner)
{
$root->appendChild($mail);
- return(trim($doc->saveXML()));
+ return trim($doc->saveXML());
}
/**
* @param array $owner Owner record
*
* @return string DFRN suggestions
- * @todo Add type-hints
+ * @todo Find proper type-hints
*/
public static function fsuggest($item, $owner)
{
$root->appendChild($suggest);
- return(trim($doc->saveXML()));
+ return trim($doc->saveXML());
}
/**
* @param int $uid User ID
*
* @return string DFRN relocations
- * @todo Add type-hints
+ * @todo Find proper type-hints
*/
public static function relocate($owner, $uid)
{
$photos[$p['scale']] = System::baseUrl().'/photo/'.$p['resource-id'].'-'.$p['scale'].'.'.$ext[$p['type']];
}
- unset($rp, $ext);
$doc = new DOMDocument('1.0', 'utf-8');
$doc->formatOutput = true;
$root->appendChild($relocate);
- return(trim($doc->saveXML()));
+ return trim($doc->saveXML());
}
/**
* @param bool $public Is it a header for public posts?
*
* @return object XML root object
- * @todo Add type-hints
+ * @todo Find proper type-hints
*/
private static function addHeader($doc, $owner, $authorelement, $alternatelink = "", $public = false)
{
* @param boolean $public boolean
*
* @return object XML author object
- * @todo Add type-hints
+ * @todo Find proper type-hints
*/
private static function addAuthor($doc, $owner, $authorelement, $public)
{
* @param array $item Item elements
*
* @return object XML author object
- * @todo Add type-hints
+ * @todo Find proper type-hints
*/
private static function addEntryAuthor($doc, $element, $contact_url, $item)
{
* @param string $activity activity value
*
* @return object XML activity object
- * @todo Add type-hints
+ * @todo Find proper type-hints
*/
private static function createActivity($doc, $element, $activity)
{
if (!$r) {
return false;
}
+
if ($r->type) {
XML::addElement($doc, $entry, "activity:object-type", $r->type);
}
+
if ($r->id) {
XML::addElement($doc, $entry, "id", $r->id);
}
+
if ($r->title) {
XML::addElement($doc, $entry, "title", $r->title);
}
* @param array $item Item element
*
* @return object XML attachment object
- * @todo Add type-hints
+ * @todo Find proper type-hints
*/
private static function getAttachment($doc, $root, $item)
{
* @param bool $single If set, the entry is created as an XML document with a single "entry" element
*
* @return object XML entry object
- * @todo Add type-hints
+ * @todo Find proper type-hints
*/
- private static function entry($doc, $type, $item, $owner, $comment = false, $cid = 0, $single = false)
+ private static function entry($doc, $type, array $item, array $owner, $comment = false, $cid = 0, $single = false)
{
$mentioned = [];
$htmlbody = $body;
if ($item['title'] != "") {
- $htmlbody = "[b]".$item['title']."[/b]\n\n".$htmlbody;
+ $htmlbody = "[b]" . $item['title'] . "[/b]\n\n" . $htmlbody;
}
$htmlbody = BBCode::convert($htmlbody, false, 7);
$tags = Item::getFeedTags($item);
+ /// @TODO Combine this with similar below if() block?
if (count($tags)) {
foreach ($tags as $t) {
if (($type != 'html') || ($t[0] != "@")) {
$postvars['dissolve'] = '1';
}
-
if ((($contact['rel']) && ($contact['rel'] != CONTACT_IS_SHARING) && (! $contact['blocked'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) {
$postvars['data'] = $atom;
$postvars['perm'] = 'rw';
// Until now we aren't serving different sizes - but maybe later
$avatarlist = [];
/// @todo check if "avatar" or "photo" would be the best field in the specification
- $avatars = $xpath->query($element."/atom:link[@rel='avatar']", $context);
+ $avatars = $xpath->query($element . "/atom:link[@rel='avatar']", $context);
foreach ($avatars as $avatar) {
$href = "";
$width = 0;
foreach ($avatar->attributes as $attributes) {
- /// @TODO Rewrite these similar if () to one switch
+ /// @TODO Rewrite these similar if() to one switch
if ($attributes->name == "href") {
$href = $attributes->textContent;
}
$avatarlist[$width] = $href;
}
}
+
if (count($avatarlist) > 0) {
krsort($avatarlist);
$author["avatar"] = current($avatarlist);
$condition = ["(`id` = ?) OR (`nurl` = ?)", $importer["id"], normalise_link($old["url"])];
dba::update('contact', $fields, $condition);
+ // @TODO No dba:update here?
+ dba::update('contact', $fields, $condition);
+
Contact::updateAvatar($relocate["avatar"], $importer["importer_uid"], $importer["id"], true);
logger('Contacts are updated.');
if (self::updateContent($current, $item, $importer, $entrytype)) {
logger("Item ".$item["uri"]." was updated.", LOGGER_DEBUG);
} else {
- logger("Item ".$item["uri"]." already existed.", LOGGER_DEBUG);
+ logger("Item " . $item["uri"] . " already existed.", LOGGER_DEBUG);
}
return;
}
{
logger("Processing deletions");
$uri = null;
+
foreach ($deletion->attributes as $attributes) {
if ($attributes->name == "ref") {
$uri = $attributes->textContent;
* @param bool $complete default true
* @return void
*/
- private static function entryFooter($doc, $entry, $item, $owner, $complete = true)
+ private static function entryFooter($doc, $entry, array $item, array $owner, $complete = true)
{
$mentioned = [];
if (isset($parent_item)) {
$r = dba::fetch_first("SELECT `conversation-uri`, `conversation-href` FROM `conversation` WHERE `item-uri` = ?", $parent_item);
+
if (DBM::is_result($r)) {
if ($r['conversation-uri'] != '') {
$conversation_uri = $r['conversation-uri'];
}
if ($owner['account-type'] == ACCOUNT_TYPE_COMMUNITY) {
- XML::addElement($doc, $entry, "link", "", ["rel" => "mentioned",
- "ostatus:object-type" => "http://activitystrea.ms/schema/1.0/group",
- "href" => $owner['url']]);
+ XML::addElement($doc, $entry, "link", "", [
+ "rel" => "mentioned",
+ "ostatus:object-type" => "http://activitystrea.ms/schema/1.0/group",
+ "href" => $owner['url']
+ ]);
}
if (!$item["private"]) {
$version = $data->version;
$site_name = $data->site_name;
$info = $data->info;
- $register_policy_str = $data->register_policy;
+ $register_policy = constant($data->register_policy);
$platform = $data->platform;
-
- switch ($register_policy_str) {
- case "REGISTER_CLOSED":
- $register_policy = REGISTER_CLOSED;
- break;
- case "REGISTER_APPROVE":
- $register_policy = REGISTER_APPROVE;
- break;
- case "REGISTER_OPEN":
- $register_policy = REGISTER_OPEN;
- break;
- }
}
}
}