Merge remote-tracking branch 'upstream/develop' into 1705-some-more-dba

Conflicts:
	include/uimport.php
This commit is contained in:
Michael 2017-05-13 04:13:07 +00:00
commit e884090efa
26 changed files with 1834 additions and 1816 deletions

View File

@ -5,10 +5,10 @@
use Friendica\App; use Friendica\App;
require_once('include/ForumManager.php'); require_once 'include/ForumManager.php';
require_once('include/bbcode.php'); require_once 'include/bbcode.php';
require_once("mod/proxy.php"); require_once 'mod/proxy.php';
require_once('include/cache.php'); require_once 'include/cache.php';
/** /**
* *
@ -87,7 +87,7 @@ function profile_load(App $a, $nickname, $profile = 0, $profiledata = array()) {
$theme_info_file = "view/theme/" . current_theme() . "/theme.php"; $theme_info_file = "view/theme/" . current_theme() . "/theme.php";
if (file_exists($theme_info_file)) { if (file_exists($theme_info_file)) {
require_once($theme_info_file); require_once $theme_info_file;
} }
if (! (x($a->page,'aside'))) if (! (x($a->page,'aside')))
@ -537,13 +537,13 @@ function get_birthdays() {
function get_events() { function get_events() {
require_once('include/bbcode.php'); require_once 'include/bbcode.php';
$a = get_app(); $a = get_app();
if (! local_user() || $a->is_mobile || $a->is_tablet) if (! local_user() || $a->is_mobile || $a->is_tablet) {
return $o; return $o;
}
// $mobile_detect = new Mobile_Detect(); // $mobile_detect = new Mobile_Detect();
// $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet(); // $is_mobile = $mobile_detect->isMobile() || $mobile_detect->isTablet();
@ -566,13 +566,15 @@ function get_events() {
$now = strtotime('now'); $now = strtotime('now');
$istoday = false; $istoday = false;
foreach ($r as $rr) { foreach ($r as $rr) {
if (strlen($rr['name'])) if (strlen($rr['name'])) {
$total ++; $total ++;
}
$strt = datetime_convert('UTC',$rr['convert'] ? $a->timezone : 'UTC',$rr['start'],'Y-m-d'); $strt = datetime_convert('UTC',$rr['convert'] ? $a->timezone : 'UTC',$rr['start'],'Y-m-d');
if ($strt === datetime_convert('UTC',$a->timezone,'now','Y-m-d')) if ($strt === datetime_convert('UTC',$a->timezone,'now','Y-m-d')) {
$istoday = true; $istoday = true;
} }
}
$classtoday = (($istoday) ? 'event-today' : ''); $classtoday = (($istoday) ? 'event-today' : '');
$skip = 0; $skip = 0;
@ -580,12 +582,14 @@ function get_events() {
foreach ($r as &$rr) { foreach ($r as &$rr) {
$title = strip_tags(html_entity_decode(bbcode($rr['summary']),ENT_QUOTES,'UTF-8')); $title = strip_tags(html_entity_decode(bbcode($rr['summary']),ENT_QUOTES,'UTF-8'));
if (strlen($title) > 35) if (strlen($title) > 35) {
$title = substr($title,0,32) . '... '; $title = substr($title,0,32) . '... ';
}
$description = substr(strip_tags(bbcode($rr['desc'])),0,32) . '... '; $description = substr(strip_tags(bbcode($rr['desc'])),0,32) . '... ';
if (! $description) if (! $description) {
$description = t('[No description]'); $description = t('[No description]');
}
$strt = datetime_convert('UTC',$rr['convert'] ? $a->timezone : 'UTC',$rr['start']); $strt = datetime_convert('UTC',$rr['convert'] ? $a->timezone : 'UTC',$rr['start']);
@ -632,7 +636,9 @@ function advanced_profile(App $a) {
$profile['fullname'] = array( t('Full Name:'), $a->profile['name'] ) ; $profile['fullname'] = array( t('Full Name:'), $a->profile['name'] ) ;
if ($a->profile['gender']) $profile['gender'] = array( t('Gender:'), $a->profile['gender'] ); if ($a->profile['gender']) {
$profile['gender'] = array( t('Gender:'), $a->profile['gender'] );
}
if (($a->profile['dob']) && ($a->profile['dob'] > '0001-01-01')) { if (($a->profile['dob']) && ($a->profile['dob'] > '0001-01-01')) {
$year_bd_format = t('j F, Y'); $year_bd_format = t('j F, Y');
@ -647,10 +653,13 @@ function advanced_profile(App $a) {
} }
if ($age = age($a->profile['dob'],$a->profile['timezone'],'')) $profile['age'] = array( t('Age:'), $age ); if ($age = age($a->profile['dob'],$a->profile['timezone'],'')) {
$profile['age'] = array( t('Age:'), $age );
}
if ($a->profile['marital']) {
if ($a->profile['marital']) $profile['marital'] = array( t('Status:'), $a->profile['marital']); $profile['marital'] = array( t('Status:'), $a->profile['marital']);
}
/// @TODO Maybe use x() here, plus below? /// @TODO Maybe use x() here, plus below?
if ($a->profile['with']) { if ($a->profile['with']) {
@ -855,8 +864,9 @@ function profile_tabs($a, $is_owner=False, $nickname=Null){
} }
function get_my_url() { function get_my_url() {
if (x($_SESSION,'my_url')) if (x($_SESSION, 'my_url')) {
return $_SESSION['my_url']; return $_SESSION['my_url'];
}
return false; return false;
} }
@ -869,12 +879,10 @@ function zrl_init(App $a) {
$urlparts = parse_url($tmp_str); $urlparts = parse_url($tmp_str);
$result = Cache::get("gprobe:" . $urlparts["host"]); $result = Cache::get("gprobe:" . $urlparts["host"]);
if (!is_null($result)) { if ((!is_null($result)) && (in_array($result["network"], array(NETWORK_FEED, NETWORK_PHANTOM)))) {
if (in_array($result["network"], array(NETWORK_FEED, NETWORK_PHANTOM))) {
logger("DDoS attempt detected for " . $urlparts["host"] . " by " . $_SERVER["REMOTE_ADDR"] . ". server data: " . print_r($_SERVER, true), LOGGER_DEBUG); logger("DDoS attempt detected for " . $urlparts["host"] . " by " . $_SERVER["REMOTE_ADDR"] . ". server data: " . print_r($_SERVER, true), LOGGER_DEBUG);
return; return;
} }
}
proc_run(PRIORITY_LOW, 'include/gprobe.php', bin2hex($tmp_str)); proc_run(PRIORITY_LOW, 'include/gprobe.php', bin2hex($tmp_str));
$arr = array('zrl' => $tmp_str, 'url' => $a->cmd); $arr = array('zrl' => $tmp_str, 'url' => $a->cmd);
@ -894,7 +902,7 @@ function zrl($s,$force = false) {
} }
$achar = strpos($s, '?') ? '&' : '?'; $achar = strpos($s, '?') ? '&' : '?';
$mine = get_my_url(); $mine = get_my_url();
if ($mine and ! link_compare($mine,$s)) { if ($mine && ! link_compare($mine, $s)) {
return $s . $achar . 'zrl=' . urlencode($mine); return $s . $achar . 'zrl=' . urlencode($mine);
} }
return $s; return $s;
@ -916,11 +924,9 @@ function zrl($s,$force = false) {
*/ */
function get_theme_uid() { function get_theme_uid() {
$uid = (($_REQUEST['puid']) ? intval($_REQUEST['puid']) : 0); $uid = (($_REQUEST['puid']) ? intval($_REQUEST['puid']) : 0);
if (local_user()) { if ((local_user()) && ((get_pconfig(local_user(),'system','always_my_theme')) || (! $uid))) {
if ((get_pconfig(local_user(),'system','always_my_theme')) || (! $uid)) {
return local_user(); return local_user();
} }
}
return $uid; return $uid;
} }

View File

@ -57,8 +57,9 @@ function block_on_function_lock($fn_name, $wait_sec = 2, $timeout = 30) {
dbesc($fn_name) dbesc($fn_name)
); );
if (dbm::is_result($r) && $r[0]['locked']) if (dbm::is_result($r) && $r[0]['locked']) {
sleep($wait_sec); sleep($wait_sec);
}
} while (dbm::is_result($r) && $r[0]['locked'] && ((time() - $start) < $timeout)); } while (dbm::is_result($r) && $r[0]['locked'] && ((time() - $start) < $timeout));

View File

@ -196,9 +196,8 @@ function z_fetch_url($url, $binary = false, &$redirects = 0, $opts = array()) {
if (preg_match('/(Location:|URI:)(.*?)\n/i', $header, $matches)) { if (preg_match('/(Location:|URI:)(.*?)\n/i', $header, $matches)) {
$newurl = trim(array_pop($matches)); $newurl = trim(array_pop($matches));
} }
if (strpos($newurl,'/') === 0) { if (strpos($newurl,'/') === 0) {
$newurl = $old_location_info['scheme'] . '://' . $old_location_info['host'] . $newurl; $newurl = $old_location_info["scheme"]."://".$old_location_info["host"].$newurl;
} }
if (filter_var($newurl, FILTER_VALIDATE_URL)) { if (filter_var($newurl, FILTER_VALIDATE_URL)) {
@ -342,7 +341,7 @@ function post_url($url, $params, $headers = null, &$redirects = 0, $timeout = 0)
$newurl = trim(array_pop($matches)); $newurl = trim(array_pop($matches));
if (strpos($newurl, '/') === 0) { if (strpos($newurl, '/') === 0) {
$newurl = $old_location_info['scheme'] . '://' . $old_location_info['host'] . $newurl; $newurl = $old_location_info["scheme"] . "://" . $old_location_info["host"] . $newurl;
} }
if (filter_var($newurl, FILTER_VALIDATE_URL)) { if (filter_var($newurl, FILTER_VALIDATE_URL)) {
@ -502,7 +501,6 @@ function allowed_url($url) {
$host = strtolower($h['host']); $host = strtolower($h['host']);
// always allow our own site // always allow our own site
if ($host == strtolower($_SERVER['SERVER_NAME'])) { if ($host == strtolower($_SERVER['SERVER_NAME'])) {
return true; return true;
} }
@ -563,14 +561,15 @@ function blocked_url($url) {
*/ */
function allowed_email($email) { function allowed_email($email) {
$domain = strtolower(substr($email,strpos($email,'@') + 1)); $domain = strtolower(substr($email,strpos($email,'@') + 1));
if(! $domain) if (! $domain) {
return false; return false;
}
$str_allowed = get_config('system','allowed_email'); $str_allowed = get_config('system','allowed_email');
if(! $str_allowed) if (! $str_allowed) {
return true; return true;
}
$found = false; $found = false;

View File

@ -306,7 +306,9 @@ function oembed_html2bbcode($text) {
$xattr = "@rel='oembed'";//oe_build_xpath("rel","oembed"); $xattr = "@rel='oembed'";//oe_build_xpath("rel","oembed");
foreach ($entries as $e) { foreach ($entries as $e) {
$href = $xpath->evaluate("a[$xattr]/@href", $e)->item(0)->nodeValue; $href = $xpath->evaluate("a[$xattr]/@href", $e)->item(0)->nodeValue;
if(!is_null($href)) $e->parentNode->replaceChild(new DOMText("[embed]".$href."[/embed]"), $e); if (!is_null($href)) {
$e->parentNode->replaceChild(new DOMText("[embed]".$href."[/embed]"), $e);
}
} }
return oe_get_inner_html( $dom->getElementsByTagName("body")->item(0) ); return oe_get_inner_html( $dom->getElementsByTagName("body")->item(0) );
} else { } else {

View File

@ -170,7 +170,7 @@ function onepoll_run(&$argv, &$argc){
// But this may be our first communication, so set the writable flag if it isn't set already. // But this may be our first communication, so set the writable flag if it isn't set already.
if (! intval($contact['writable'])) { if (! intval($contact['writable'])) {
q("update contact set writable = 1 where id = %d", intval($contact['id'])); q("UPDATE `contact` SET `writable` = 1 WHERE `id` = %d", intval($contact['id']));
} }
$url = $contact['poll'] . '?dfrn_id=' . $idtosend $url = $contact['poll'] . '?dfrn_id=' . $idtosend
@ -437,17 +437,19 @@ function onepoll_run(&$argv, &$argc){
if ($raw_refs) { if ($raw_refs) {
$refs_arr = explode(' ', $raw_refs); $refs_arr = explode(' ', $raw_refs);
if (count($refs_arr)) { if (count($refs_arr)) {
for($x = 0; $x < count($refs_arr); $x ++) for ($x = 0; $x < count($refs_arr); $x ++) {
$refs_arr[$x] = "'" . msgid2iri(str_replace(array('<','>',' '),array('','',''),dbesc($refs_arr[$x]))) . "'"; $refs_arr[$x] = "'" . msgid2iri(str_replace(array('<','>',' '),array('','',''),dbesc($refs_arr[$x]))) . "'";
} }
}
$qstr = implode(',',$refs_arr); $qstr = implode(',',$refs_arr);
$r = q("SELECT `uri` , `parent-uri` FROM `item` USE INDEX (`uid_uri`) WHERE `uri` IN ($qstr) AND `uid` = %d LIMIT 1", $r = q("SELECT `uri` , `parent-uri` FROM `item` USE INDEX (`uid_uri`) WHERE `uri` IN ($qstr) AND `uid` = %d LIMIT 1",
intval($importer_uid) intval($importer_uid)
); );
if (dbm::is_result($r)) if (dbm::is_result($r)) {
$datarray['parent-uri'] = $r[0]['parent-uri']; // Set the parent as the top-level item $datarray['parent-uri'] = $r[0]['parent-uri']; // Set the parent as the top-level item
//$datarray['parent-uri'] = $r[0]['uri']; //$datarray['parent-uri'] = $r[0]['uri'];
} }
}
// Decoding the header // Decoding the header
$subject = imap_mime_header_decode($meta->subject); $subject = imap_mime_header_decode($meta->subject);
@ -611,14 +613,17 @@ function onepoll_run(&$argv, &$argc){
consume_feed($xml,$importer,$contact,$hub,1,2); consume_feed($xml,$importer,$contact,$hub,1,2);
$hubmode = 'subscribe'; $hubmode = 'subscribe';
if ($contact['network'] === NETWORK_DFRN || $contact['blocked'] || $contact['readonly']) if ($contact['network'] === NETWORK_DFRN || $contact['blocked'] || $contact['readonly']) {
$hubmode = 'unsubscribe'; $hubmode = 'unsubscribe';
}
if (($contact['network'] === NETWORK_OSTATUS || $contact['network'] == NETWORK_FEED) && (! $contact['hub-verify'])) if (($contact['network'] === NETWORK_OSTATUS || $contact['network'] == NETWORK_FEED) && (! $contact['hub-verify'])) {
$hub_update = true; $hub_update = true;
}
if ($force) if ($force) {
$hub_update = true; $hub_update = true;
}
logger("Contact ".$contact['id']." returned hub: ".$hub." Network: ".$contact['network']." Relation: ".$contact['rel']." Update: ".$hub_update); logger("Contact ".$contact['id']." returned hub: ".$hub." Network: ".$contact['network']." Relation: ".$contact['rel']." Update: ".$hub_update);

View File

@ -70,6 +70,7 @@ class ostatus {
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `nurl` IN ('%s', '%s') AND `network` != '%s'", $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `nurl` IN ('%s', '%s') AND `network` != '%s'",
intval($importer["uid"]), dbesc(normalise_link($author["author-link"])), intval($importer["uid"]), dbesc(normalise_link($author["author-link"])),
dbesc(normalise_link($aliaslink)), dbesc(NETWORK_STATUSNET)); dbesc(normalise_link($aliaslink)), dbesc(NETWORK_STATUSNET));
if (dbm::is_result($r)) { if (dbm::is_result($r)) {
$contact = $r[0]; $contact = $r[0];
$author["contact-id"] = $r[0]["id"]; $author["contact-id"] = $r[0]["id"];
@ -79,6 +80,7 @@ class ostatus {
// Should not happen // Should not happen
$contact = dba::fetch_first("SELECT * FROM `contact` WHERE `uid` = ? AND `addr` = ? AND `network` != ?", $contact = dba::fetch_first("SELECT * FROM `contact` WHERE `uid` = ? AND `addr` = ? AND `network` != ?",
$importer["uid"], $addr, NETWORK_STATUSNET); $importer["uid"], $addr, NETWORK_STATUSNET);
if (dbm::is_result($contact)) { if (dbm::is_result($contact)) {
$author["contact-id"] = $contact["id"]; $author["contact-id"] = $contact["id"];
$author["author-link"] = $contact["url"]; $author["author-link"] = $contact["url"];
@ -91,22 +93,26 @@ class ostatus {
$href = ""; $href = "";
$width = 0; $width = 0;
foreach ($avatar->attributes AS $attributes) { foreach ($avatar->attributes AS $attributes) {
if ($attributes->name == "href") if ($attributes->name == "href") {
$href = $attributes->textContent; $href = $attributes->textContent;
if ($attributes->name == "width") }
if ($attributes->name == "width") {
$width = $attributes->textContent; $width = $attributes->textContent;
} }
if (($width > 0) AND ($href != "")) }
if (($width > 0) AND ($href != "")) {
$avatarlist[$width] = $href; $avatarlist[$width] = $href;
} }
}
if (count($avatarlist) > 0) { if (count($avatarlist) > 0) {
krsort($avatarlist); krsort($avatarlist);
$author["author-avatar"] = Probe::fixAvatar(current($avatarlist), $author["author-link"]); $author["author-avatar"] = Probe::fixAvatar(current($avatarlist), $author["author-link"]);
} }
$displayname = $xpath->evaluate('atom:author/poco:displayName/text()', $context)->item(0)->nodeValue; $displayname = $xpath->evaluate('atom:author/poco:displayName/text()', $context)->item(0)->nodeValue;
if ($displayname != "") if ($displayname != "") {
$author["author-name"] = $displayname; $author["author-name"] = $displayname;
}
$author["owner-name"] = $author["author-name"]; $author["owner-name"] = $author["author-name"];
$author["owner-link"] = $author["author-link"]; $author["owner-link"] = $author["author-link"];
@ -1146,6 +1152,7 @@ class ostatus {
continue; continue;
} }
/// @TODO One statment is okay (until if () )
$arr = array(); $arr = array();
$arr["network"] = $details["network"]; $arr["network"] = $details["network"];
$arr["uri"] = $single_conv->id; $arr["uri"] = $single_conv->id;

View File

@ -8,8 +8,9 @@ define("IMPORT_DEBUG", False);
function last_insert_id() { function last_insert_id() {
global $db; global $db;
if (IMPORT_DEBUG) if (IMPORT_DEBUG) {
return 1; return 1;
}
return $db->insert_id(); return $db->insert_id();
} }
@ -56,13 +57,10 @@ function db_import_assoc($table, $arr) {
$vals = implode("','", array_map('dbesc', array_values($arr))); $vals = implode("','", array_map('dbesc', array_values($arr)));
$query = "INSERT INTO `$table` (`$cols`) VALUES ('$vals')"; $query = "INSERT INTO `$table` (`$cols`) VALUES ('$vals')";
logger("uimport: $query", LOGGER_TRACE); logger("uimport: $query", LOGGER_TRACE);
if (IMPORT_DEBUG) if (IMPORT_DEBUG) {
return true; return true;
return q($query);
} }
return q($query);
function import_cleanup($newuid) {
dba::delete('user', array('uid' => $newuid));
} }
/** /**
@ -95,6 +93,7 @@ function import_account(App $a, $file) {
} }
/* /*
* @TODO Old-lost code?
// this is not required as we remove columns in json not in current db schema // this is not required as we remove columns in json not in current db schema
if ($account['schema'] != DB_UPDATE_VERSION) { if ($account['schema'] != DB_UPDATE_VERSION) {
notice(t("Error! I can't import this file: DB schema version is not compatible.")); notice(t("Error! I can't import this file: DB schema version is not compatible."));
@ -133,11 +132,11 @@ function import_account(App $a, $file) {
unset($account['user']['account_expired']); unset($account['user']['account_expired']);
unset($account['user']['account_expires_on']); unset($account['user']['account_expires_on']);
unset($account['user']['expire_notification_sent']); unset($account['user']['expire_notification_sent']);
foreach ($account['user'] as $k => &$v) { foreach ($account['user'] as $k => &$v) {
$v = str_replace($oldbaseurl, $newbaseurl, $v); $v = str_replace($oldbaseurl, $newbaseurl, $v);
} }
// import user // import user
$r = db_import_assoc('user', $account['user']); $r = db_import_assoc('user', $account['user']);
if ($r === false) { if ($r === false) {
@ -156,15 +155,16 @@ function import_account(App $a, $file) {
foreach ($account['profile'] as &$profile) { foreach ($account['profile'] as &$profile) {
foreach ($profile as $k => &$v) { foreach ($profile as $k => &$v) {
$v = str_replace($oldbaseurl, $newbaseurl, $v); $v = str_replace($oldbaseurl, $newbaseurl, $v);
foreach (array("profile", "avatar") as $k) foreach (array("profile", "avatar") as $k) {
$v = str_replace($oldbaseurl . "/photo/" . $k . "/" . $olduid . ".jpg", $newbaseurl . "/photo/" . $k . "/" . $newuid . ".jpg", $v); $v = str_replace($oldbaseurl . "/photo/" . $k . "/" . $olduid . ".jpg", $newbaseurl . "/photo/" . $k . "/" . $newuid . ".jpg", $v);
} }
}
$profile['uid'] = $newuid; $profile['uid'] = $newuid;
$r = db_import_assoc('profile', $profile); $r = db_import_assoc('profile', $profile);
if ($r === false) { if ($r === false) {
logger("uimport:insert profile " . $profile['profile-name'] . " : ERROR : " . last_error(), LOGGER_NORMAL); logger("uimport:insert profile " . $profile['profile-name'] . " : ERROR : " . last_error(), LOGGER_NORMAL);
info(t("User profile creation error")); info(t("User profile creation error"));
import_cleanup($newuid); dba::delete('user', array('uid' => $newuid));
return; return;
} }
} }
@ -174,15 +174,15 @@ function import_account(App $a, $file) {
if ($contact['uid'] == $olduid && $contact['self'] == '1') { if ($contact['uid'] == $olduid && $contact['self'] == '1') {
foreach ($contact as $k => &$v) { foreach ($contact as $k => &$v) {
$v = str_replace($oldbaseurl, $newbaseurl, $v); $v = str_replace($oldbaseurl, $newbaseurl, $v);
foreach (array("profile", "avatar", "micro") as $k) foreach (array("profile", "avatar", "micro") as $k) {
$v = str_replace($oldbaseurl . "/photo/" . $k . "/" . $olduid . ".jpg", $newbaseurl . "/photo/" . $k . "/" . $newuid . ".jpg", $v); $v = str_replace($oldbaseurl . "/photo/" . $k . "/" . $olduid . ".jpg", $newbaseurl . "/photo/" . $k . "/" . $newuid . ".jpg", $v);
} }
} }
}
if ($contact['uid'] == $olduid && $contact['self'] == '0') { if ($contact['uid'] == $olduid && $contact['self'] == '0') {
// set contacts 'avatar-date' to NULL_DATE to let poller to update urls // set contacts 'avatar-date' to NULL_DATE to let poller to update urls
$contact["avatar-date"] = NULL_DATE; $contact["avatar-date"] = NULL_DATE;
switch ($contact['network']) { switch ($contact['network']) {
case NETWORK_DFRN: case NETWORK_DFRN:
// send relocate message (below) // send relocate message (below)

View File

@ -6,6 +6,7 @@ function login_content(App $a) {
if (x($_SESSION, 'theme')) { if (x($_SESSION, 'theme')) {
unset($_SESSION['theme']); unset($_SESSION['theme']);
} }
if (x($_SESSION, 'mobile-theme')) { if (x($_SESSION, 'mobile-theme')) {
unset($_SESSION['mobile-theme']); unset($_SESSION['mobile-theme']);
} }

View File

@ -11,4 +11,3 @@
</section> </section>
</body> </body>
</html> </html>

View File

@ -59,4 +59,3 @@
</div> </div>
<div id="group-all-contacts-end"></div> <div id="group-all-contacts-end"></div>
</div> </div>

View File

@ -83,4 +83,3 @@
</li> </li>
</ul> </ul>
</div> </div>