|
|
@ -3,11 +3,35 @@ |
|
|
|
// Bootstrap |
|
|
|
// Bootstrap |
|
|
|
require_once __DIR__ . '/../../config/bootstrap.php'; |
|
|
|
require_once __DIR__ . '/../../config/bootstrap.php'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Init Debug |
|
|
|
|
|
|
|
$debug = |
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
'time' => [ |
|
|
|
|
|
|
|
'ISO8601' => date('c'), |
|
|
|
|
|
|
|
'total' => microtime(true), |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
'memory' => |
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
'start' => memory_get_usage(), |
|
|
|
|
|
|
|
'total' => 0, |
|
|
|
|
|
|
|
'peaks' => 0 |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
'exception' => [] |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
// Define response |
|
|
|
// Define response |
|
|
|
$response = |
|
|
|
$response = |
|
|
|
[ |
|
|
|
[ |
|
|
|
'status' => false, |
|
|
|
'status' => false, |
|
|
|
'message' => _('Request failed') |
|
|
|
'message' => _('Internal server error'), |
|
|
|
|
|
|
|
'data' => [ |
|
|
|
|
|
|
|
'user' => [], |
|
|
|
|
|
|
|
'magnet' => [], |
|
|
|
|
|
|
|
'magnetDownload' => [], |
|
|
|
|
|
|
|
'magnetComment' => [], |
|
|
|
|
|
|
|
'magnetView' => [], |
|
|
|
|
|
|
|
'magnetStar' => [], |
|
|
|
|
|
|
|
] |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
// Init connections whitelist |
|
|
|
// Init connections whitelist |
|
|
@ -16,16 +40,8 @@ $connectionWhiteList = []; |
|
|
|
foreach (json_decode(file_get_contents(__DIR__ . '/../../config/nodes.json')) as $node) |
|
|
|
foreach (json_decode(file_get_contents(__DIR__ . '/../../config/nodes.json')) as $node) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Skip non-condition addresses |
|
|
|
// Skip non-condition addresses |
|
|
|
$error = []; |
|
|
|
if (!Valid::url($node->manifest)) |
|
|
|
|
|
|
|
|
|
|
|
if (!Valid::url($node->manifest, $error)) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
$response = |
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
'status' => false, |
|
|
|
|
|
|
|
'message' => $error |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -44,6 +60,8 @@ foreach (json_decode(file_get_contents(__DIR__ . '/../../config/nodes.json')) as |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// API import enabled |
|
|
|
// API import enabled |
|
|
|
|
|
|
|
$error = []; |
|
|
|
|
|
|
|
|
|
|
|
if (!API_IMPORT_ENABLED) |
|
|
|
if (!API_IMPORT_ENABLED) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$response = |
|
|
|
$response = |
|
|
@ -59,17 +77,17 @@ else if (!API_IMPORT_PUSH_ENABLED) |
|
|
|
$response = |
|
|
|
$response = |
|
|
|
[ |
|
|
|
[ |
|
|
|
'status' => false, |
|
|
|
'status' => false, |
|
|
|
'message' => _('Push API disabled') |
|
|
|
'message' => _('Push API import disabled') |
|
|
|
]; |
|
|
|
]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Yggdrasil connections only |
|
|
|
// Yggdrasil connections only |
|
|
|
else if (!Valid::host($_SERVER['REMOTE_ADDR'])) |
|
|
|
else if (!Valid::host($_SERVER['REMOTE_ADDR'], $error)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$response = |
|
|
|
$response = |
|
|
|
[ |
|
|
|
[ |
|
|
|
'status' => false, |
|
|
|
'status' => false, |
|
|
|
'message' => _('Yggdrasil connection required for this action') |
|
|
|
'message' => $error |
|
|
|
]; |
|
|
|
]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -80,7 +98,7 @@ else if (!in_array($_SERVER['REMOTE_ADDR'], $connectionWhiteList)) |
|
|
|
[ |
|
|
|
[ |
|
|
|
'status' => false, |
|
|
|
'status' => false, |
|
|
|
'message' => sprintf( |
|
|
|
'message' => sprintf( |
|
|
|
_('Access denied for host "%s"'), |
|
|
|
_('Push API access denied for host "%s"'), |
|
|
|
$_SERVER['REMOTE_ADDR'] |
|
|
|
$_SERVER['REMOTE_ADDR'] |
|
|
|
) |
|
|
|
) |
|
|
|
]; |
|
|
|
]; |
|
|
@ -92,45 +110,54 @@ else if (!$userId = $db->initUserId($_SERVER['REMOTE_ADDR'], USER_DEFAULT_APPROV |
|
|
|
$response = |
|
|
|
$response = |
|
|
|
[ |
|
|
|
[ |
|
|
|
'status' => false, |
|
|
|
'status' => false, |
|
|
|
'message' => _('Could not init user session') |
|
|
|
'message' => _('Could not init user session for this connection') |
|
|
|
]; |
|
|
|
]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Get user |
|
|
|
// Validate required fields |
|
|
|
else if (!$user = $db->getUser($userId)) |
|
|
|
else if (empty($_POST['data'])) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$response = |
|
|
|
$response = |
|
|
|
[ |
|
|
|
[ |
|
|
|
'status' => false, |
|
|
|
'status' => false, |
|
|
|
'message' => _('Could not init user info') |
|
|
|
'message' => _('Request protocol invalid') |
|
|
|
]; |
|
|
|
]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Validate required fields |
|
|
|
// Validate required fields |
|
|
|
else if (empty($_POST)) |
|
|
|
else if (false === $data = json_decode($_POST['data'])) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$response = |
|
|
|
$response = |
|
|
|
[ |
|
|
|
[ |
|
|
|
'status' => false, |
|
|
|
'status' => false, |
|
|
|
'message' => _('Import data required') |
|
|
|
'message' => _('Could not decode data requested') |
|
|
|
]; |
|
|
|
]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Import begin |
|
|
|
// Import begin |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
$response = |
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
'status' => true, |
|
|
|
|
|
|
|
'message' => sprintf( |
|
|
|
|
|
|
|
_('Connection for "%s" established'), |
|
|
|
|
|
|
|
$_SERVER['REMOTE_ADDR'] |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
// Init alias registry |
|
|
|
// Init alias registry |
|
|
|
$aliasUserId = []; |
|
|
|
$aliasUserId = []; |
|
|
|
$aliasMagnetId = []; |
|
|
|
$aliasMagnetId = []; |
|
|
|
|
|
|
|
|
|
|
|
// Process request |
|
|
|
try { |
|
|
|
foreach ((object) $_POST as $field => $remote) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
try |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// Transaction begin |
|
|
|
// Transaction begin |
|
|
|
$db->beginTransaction(); |
|
|
|
$db->beginTransaction(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Process request |
|
|
|
|
|
|
|
foreach ((object) $data as $field => $remote) |
|
|
|
|
|
|
|
{ |
|
|
|
// Process alias fields |
|
|
|
// Process alias fields |
|
|
|
switch ($field) |
|
|
|
switch ($field) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -138,7 +165,7 @@ else |
|
|
|
|
|
|
|
|
|
|
|
if (!API_IMPORT_USERS_ENABLED) |
|
|
|
if (!API_IMPORT_USERS_ENABLED) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$response = [ |
|
|
|
$response['user'][] = [ |
|
|
|
'status' => false, |
|
|
|
'status' => false, |
|
|
|
'message' => _('Users import disabled on this node. Related content skipped.') |
|
|
|
'message' => _('Users import disabled on this node. Related content skipped.') |
|
|
|
]; |
|
|
|
]; |
|
|
@ -151,9 +178,13 @@ else |
|
|
|
|
|
|
|
|
|
|
|
if (!Valid::user($remote, $error)) |
|
|
|
if (!Valid::user($remote, $error)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$response = [ |
|
|
|
$response['user'][] = [ |
|
|
|
'status' => false, |
|
|
|
'status' => false, |
|
|
|
'message' => $error |
|
|
|
'message' => sprintf( |
|
|
|
|
|
|
|
_('User data mismatch protocol with error: %s data: %s'), |
|
|
|
|
|
|
|
print_r($error, true), |
|
|
|
|
|
|
|
print_r($remote, true) |
|
|
|
|
|
|
|
), |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
continue 2; |
|
|
|
continue 2; |
|
|
@ -162,9 +193,12 @@ else |
|
|
|
// Skip import on user approved required |
|
|
|
// Skip import on user approved required |
|
|
|
if (API_IMPORT_USERS_APPROVED_ONLY && !$remote->approved) |
|
|
|
if (API_IMPORT_USERS_APPROVED_ONLY && !$remote->approved) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$response = [ |
|
|
|
$response['user'][] = [ |
|
|
|
'status' => false, |
|
|
|
'status' => false, |
|
|
|
'message' => _('This host accept approved users only') |
|
|
|
'message' => sprintf( |
|
|
|
|
|
|
|
_('Node accepting approved users only: %s'), |
|
|
|
|
|
|
|
print_r($remote, true) |
|
|
|
|
|
|
|
), |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
continue 2; |
|
|
|
continue 2; |
|
|
@ -175,14 +209,28 @@ else |
|
|
|
USER_AUTO_APPROVE_ON_IMPORT_APPROVED ? $remote->approved : USER_DEFAULT_APPROVED, |
|
|
|
USER_AUTO_APPROVE_ON_IMPORT_APPROVED ? $remote->approved : USER_DEFAULT_APPROVED, |
|
|
|
$remote->timeAdded))) |
|
|
|
$remote->timeAdded))) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$response = [ |
|
|
|
$response['user'][] = [ |
|
|
|
'status' => false, |
|
|
|
'status' => false, |
|
|
|
'message' => _('Could not init user') |
|
|
|
'message' => sprintf( |
|
|
|
|
|
|
|
_('Could not init user profile: %s'), |
|
|
|
|
|
|
|
print_r($remote, true) |
|
|
|
|
|
|
|
), |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
continue 2; |
|
|
|
continue 2; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$response['user'][] = [ |
|
|
|
|
|
|
|
'status' => true, |
|
|
|
|
|
|
|
'message' => sprintf( |
|
|
|
|
|
|
|
_('User profile successfully associated with ID "%s"'), |
|
|
|
|
|
|
|
$local->userId |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Register user alias |
|
|
|
// Register user alias |
|
|
|
$aliasUserId[$remote->userId] = $local->userId; |
|
|
|
$aliasUserId[$remote->userId] = $local->userId; |
|
|
|
|
|
|
|
|
|
|
@ -193,6 +241,14 @@ else |
|
|
|
$local->userId, |
|
|
|
$local->userId, |
|
|
|
$remote->timeAdded |
|
|
|
$remote->timeAdded |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$response['user'][] = [ |
|
|
|
|
|
|
|
'status' => true, |
|
|
|
|
|
|
|
'message' => sprintf( |
|
|
|
|
|
|
|
_('Field "timeAdded" changed to newer value for user ID "%s"'), |
|
|
|
|
|
|
|
$local->userId |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Update user info if newer |
|
|
|
// Update user info if newer |
|
|
@ -204,6 +260,14 @@ else |
|
|
|
$remote->timeUpdated |
|
|
|
$remote->timeUpdated |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$response['user'][] = [ |
|
|
|
|
|
|
|
'status' => true, |
|
|
|
|
|
|
|
'message' => sprintf( |
|
|
|
|
|
|
|
_('Field "timeUpdated" changed to newer value for user ID "%s"'), |
|
|
|
|
|
|
|
$local->userId |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
// Update approved for existing user |
|
|
|
// Update approved for existing user |
|
|
|
if (USER_AUTO_APPROVE_ON_IMPORT_APPROVED && $local->approved !== $remote->approved && $remote->approved) |
|
|
|
if (USER_AUTO_APPROVE_ON_IMPORT_APPROVED && $local->approved !== $remote->approved && $remote->approved) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -212,6 +276,14 @@ else |
|
|
|
$remote->approved, |
|
|
|
$remote->approved, |
|
|
|
$remote->timeUpdated |
|
|
|
$remote->timeUpdated |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$response['user'][] = [ |
|
|
|
|
|
|
|
'status' => true, |
|
|
|
|
|
|
|
'message' => sprintf( |
|
|
|
|
|
|
|
_('Field "approved" changed to newer value for user ID "%s"'), |
|
|
|
|
|
|
|
$local->userId |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Set public as received remotely |
|
|
|
// Set public as received remotely |
|
|
@ -222,20 +294,23 @@ else |
|
|
|
true, |
|
|
|
true, |
|
|
|
$remote->timeUpdated |
|
|
|
$remote->timeUpdated |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$response = [ |
|
|
|
$response['user'][] = [ |
|
|
|
'status' => true, |
|
|
|
'status' => true, |
|
|
|
'message' => _('User registered') |
|
|
|
'message' => sprintf( |
|
|
|
|
|
|
|
_('Field "public" changed to newer value for user ID "%s"'), |
|
|
|
|
|
|
|
$local->userId |
|
|
|
|
|
|
|
) |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'magnet': |
|
|
|
case 'magnet': |
|
|
|
|
|
|
|
|
|
|
|
if (!API_IMPORT_MAGNETS_ENABLED) |
|
|
|
if (!API_IMPORT_MAGNETS_ENABLED) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$response = [ |
|
|
|
$response['magnet'][] = [ |
|
|
|
'status' => false, |
|
|
|
'status' => false, |
|
|
|
'message' => _('Magnets import disabled on this node. Related content skipped.') |
|
|
|
'message' => _('Magnets import disabled on this node. Related content skipped.') |
|
|
|
]; |
|
|
|
]; |
|
|
@ -248,9 +323,13 @@ else |
|
|
|
|
|
|
|
|
|
|
|
if (!Valid::magnet($remote, $error)) |
|
|
|
if (!Valid::magnet($remote, $error)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$response = [ |
|
|
|
$response['magnet'][] = [ |
|
|
|
'status' => false, |
|
|
|
'status' => false, |
|
|
|
'message' => $error |
|
|
|
'message' => sprintf( |
|
|
|
|
|
|
|
_('Magnet data mismatch protocol with error: %s data: %s'), |
|
|
|
|
|
|
|
print_r($error, true), |
|
|
|
|
|
|
|
print_r($remote, true) |
|
|
|
|
|
|
|
), |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
continue 2; |
|
|
|
continue 2; |
|
|
@ -259,9 +338,12 @@ else |
|
|
|
// User local alias required |
|
|
|
// User local alias required |
|
|
|
if (!isset($aliasUserId[$remote->userId])) |
|
|
|
if (!isset($aliasUserId[$remote->userId])) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$response = [ |
|
|
|
$response['magnet'][] = [ |
|
|
|
'status' => false, |
|
|
|
'status' => false, |
|
|
|
'message' => _('User data required for this action') |
|
|
|
'message' => sprintf( |
|
|
|
|
|
|
|
_('User data relation not found for magnet: %s'), |
|
|
|
|
|
|
|
print_r($remote, true) |
|
|
|
|
|
|
|
), |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
continue 2; |
|
|
|
continue 2; |
|
|
@ -270,18 +352,31 @@ else |
|
|
|
// Skip import on magnet approved required |
|
|
|
// Skip import on magnet approved required |
|
|
|
if (API_IMPORT_MAGNETS_APPROVED_ONLY && !$remote->approved) |
|
|
|
if (API_IMPORT_MAGNETS_APPROVED_ONLY && !$remote->approved) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$response = [ |
|
|
|
$response['magnet'][] = [ |
|
|
|
'status' => false, |
|
|
|
'status' => false, |
|
|
|
'message' => _('Node accept approved magnets only') |
|
|
|
'message' => sprintf( |
|
|
|
|
|
|
|
_('Node accepting approved magnets only: %s'), |
|
|
|
|
|
|
|
print_r($remote, true) |
|
|
|
|
|
|
|
), |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
continue 2; |
|
|
|
continue 2; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Add new magnet if not exist by timestamp added for this user |
|
|
|
/// Add new magnet if not exist by timestamp added for this user |
|
|
|
if (!$local = $db->findMagnet($aliasUserId[$remote->userId], $remote->timeAdded)) |
|
|
|
if ($local = $db->findMagnet($aliasUserId[$remote->userId], $remote->timeAdded)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$local = $db->getMagnet( |
|
|
|
$response['magnet'][] = [ |
|
|
|
|
|
|
|
'status' => true, |
|
|
|
|
|
|
|
'message' => sprintf( |
|
|
|
|
|
|
|
_('Magnet successfully associated with ID "%s"'), |
|
|
|
|
|
|
|
$local->magnetId |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Add and init new magnet if not exist |
|
|
|
|
|
|
|
else if ($local = $db->getMagnet( |
|
|
|
$db->addMagnet( |
|
|
|
$db->addMagnet( |
|
|
|
$aliasUserId[$remote->userId], |
|
|
|
$aliasUserId[$remote->userId], |
|
|
|
$remote->xl, |
|
|
|
$remote->xl, |
|
|
@ -293,7 +388,29 @@ else |
|
|
|
MAGNET_AUTO_APPROVE_ON_IMPORT_APPROVED ? $remote->approved : MAGNET_DEFAULT_APPROVED, |
|
|
|
MAGNET_AUTO_APPROVE_ON_IMPORT_APPROVED ? $remote->approved : MAGNET_DEFAULT_APPROVED, |
|
|
|
$remote->timeAdded |
|
|
|
$remote->timeAdded |
|
|
|
) |
|
|
|
) |
|
|
|
); |
|
|
|
) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$response['magnet'][] = [ |
|
|
|
|
|
|
|
'status' => true, |
|
|
|
|
|
|
|
'message' => sprintf( |
|
|
|
|
|
|
|
_('Magnet successfully synced with ID "%s"'), |
|
|
|
|
|
|
|
$local->magnetId |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$response['magnet'][] = [ |
|
|
|
|
|
|
|
'status' => false, |
|
|
|
|
|
|
|
'message' => sprintf( |
|
|
|
|
|
|
|
_('Could not init magnet: %s'), |
|
|
|
|
|
|
|
$remote |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
continue 2; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Add magnet alias for this host |
|
|
|
/// Add magnet alias for this host |
|
|
@ -306,6 +423,14 @@ else |
|
|
|
$local->magnetId, |
|
|
|
$local->magnetId, |
|
|
|
$remote->timeAdded |
|
|
|
$remote->timeAdded |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$response['magnet'][] = [ |
|
|
|
|
|
|
|
'status' => true, |
|
|
|
|
|
|
|
'message' => sprintf( |
|
|
|
|
|
|
|
_('Field "timeAdded" changed to newer value for magnet ID "%s"'), |
|
|
|
|
|
|
|
$local->magnetId |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Update info if remote newer |
|
|
|
/// Update info if remote newer |
|
|
@ -387,6 +512,8 @@ else |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// kt |
|
|
|
// kt |
|
|
|
|
|
|
|
$db->deleteMagnetToKeywordTopicByMagnetId($local->magnetId); |
|
|
|
|
|
|
|
|
|
|
|
foreach ($remote->kt as $kt) |
|
|
|
foreach ($remote->kt as $kt) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$db->initMagnetToKeywordTopicId( |
|
|
|
$db->initMagnetToKeywordTopicId( |
|
|
@ -396,6 +523,8 @@ else |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// tr |
|
|
|
// tr |
|
|
|
|
|
|
|
$db->deleteMagnetToAddressTrackerByMagnetId($local->magnetId); |
|
|
|
|
|
|
|
|
|
|
|
foreach ($remote->tr as $tr) |
|
|
|
foreach ($remote->tr as $tr) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if ($url = Yggverse\Parser\Url::parse($xs)) |
|
|
|
if ($url = Yggverse\Parser\Url::parse($xs)) |
|
|
@ -413,6 +542,8 @@ else |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// as |
|
|
|
// as |
|
|
|
|
|
|
|
$db->deleteMagnetToAcceptableSourceByMagnetId($local->magnetId); |
|
|
|
|
|
|
|
|
|
|
|
foreach ($remote->as as $as) |
|
|
|
foreach ($remote->as as $as) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if ($url = Yggverse\Parser\Url::parse($xs)) |
|
|
|
if ($url = Yggverse\Parser\Url::parse($xs)) |
|
|
@ -430,6 +561,8 @@ else |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// xs |
|
|
|
// xs |
|
|
|
|
|
|
|
$db->deleteMagnetToExactSourceByMagnetId($local->magnetId); |
|
|
|
|
|
|
|
|
|
|
|
foreach ($remote->xs as $xs) |
|
|
|
foreach ($remote->xs as $xs) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if ($url = Yggverse\Parser\Url::parse($xs)) |
|
|
|
if ($url = Yggverse\Parser\Url::parse($xs)) |
|
|
@ -445,19 +578,22 @@ else |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$response = [ |
|
|
|
$response['magnet'][] = [ |
|
|
|
'status' => true, |
|
|
|
'status' => true, |
|
|
|
'message' => _('Magnet registered') |
|
|
|
'message' => sprintf( |
|
|
|
|
|
|
|
_('Magnet fields updated to newer version for magnet ID "%s"'), |
|
|
|
|
|
|
|
$local->magnetId |
|
|
|
|
|
|
|
) |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'magnetComment': |
|
|
|
case 'magnetComment': |
|
|
|
|
|
|
|
|
|
|
|
if (!API_IMPORT_MAGNET_COMMENTS_ENABLED) |
|
|
|
if (!API_IMPORT_MAGNET_COMMENTS_ENABLED) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$response = [ |
|
|
|
$response['magnetComment'][] = [ |
|
|
|
'status' => false, |
|
|
|
'status' => false, |
|
|
|
'message' => _('Magnet comments import disabled on this node') |
|
|
|
'message' => _('Magnet comments import disabled on this node') |
|
|
|
]; |
|
|
|
]; |
|
|
@ -465,46 +601,51 @@ else |
|
|
|
continue 2; |
|
|
|
continue 2; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Validate remote fields |
|
|
|
// Validate |
|
|
|
$error = []; |
|
|
|
$error = []; |
|
|
|
|
|
|
|
|
|
|
|
if (!Valid::magnetComment($remote, $error)) |
|
|
|
if (!Valid::magnetComment($remote, $error)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$response = [ |
|
|
|
$response['magnetComment'][] = [ |
|
|
|
'status' => false, |
|
|
|
'status' => false, |
|
|
|
'message' => $error |
|
|
|
'message' => sprintf( |
|
|
|
|
|
|
|
_('Magnet comment data mismatch protocol with error: %s data: %s'), |
|
|
|
|
|
|
|
print_r($error, true), |
|
|
|
|
|
|
|
print_r($remote, true) |
|
|
|
|
|
|
|
), |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
continue 2; |
|
|
|
continue 2; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// User local alias required |
|
|
|
// Skip import on magnet approved required |
|
|
|
if (!isset($aliasUserId[$remote->userId]) || !isset($aliasMagnetId[$remote->magnetId])) |
|
|
|
if (API_IMPORT_MAGNET_COMMENTS_APPROVED_ONLY && !$remote->approved) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$response = [ |
|
|
|
$response['magnetComment'][] = [ |
|
|
|
'status' => false, |
|
|
|
'status' => false, |
|
|
|
'message' => _('User and magnet data required for magnet comments import') |
|
|
|
'message' => sprintf( |
|
|
|
|
|
|
|
_('Node accepting approved magnet comments only: %s'), |
|
|
|
|
|
|
|
print_r($remote, true) |
|
|
|
|
|
|
|
), |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
continue 2; |
|
|
|
continue 2; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Skip import on magnet approved required |
|
|
|
// User local alias required |
|
|
|
if (API_IMPORT_MAGNET_COMMENTS_APPROVED_ONLY && !$remote->approved) |
|
|
|
if (!isset($aliasUserId[$remote->userId]) || !isset($aliasMagnetId[$remote->magnetId])) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$response = [ |
|
|
|
$response['magnetComment'][] = [ |
|
|
|
'status' => false, |
|
|
|
'status' => false, |
|
|
|
'message' => _('Node accept approved magnet comments only') |
|
|
|
'message' => sprintf( |
|
|
|
|
|
|
|
_('Magnet comment data relation not found for: %s'), |
|
|
|
|
|
|
|
print_r($remote, true) |
|
|
|
|
|
|
|
), |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
continue 2; |
|
|
|
continue 2; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Add new magnet comment if not exist by timestamp added for this user |
|
|
|
|
|
|
|
if (!$db->findMagnetComment($aliasMagnetId[$remote->magnetId], |
|
|
|
|
|
|
|
$aliasUserId[$remote->userId], |
|
|
|
|
|
|
|
$remote->timeAdded)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// Parent comment provided |
|
|
|
// Parent comment provided |
|
|
|
if (is_int($remote->magnetCommentIdParent)) |
|
|
|
if (is_int($remote->magnetCommentIdParent)) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -516,21 +657,37 @@ else |
|
|
|
$localMagnetCommentIdParent = null; |
|
|
|
$localMagnetCommentIdParent = null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$db->addMagnetComment( |
|
|
|
// Magnet comment exists by timestamp added for this user |
|
|
|
$aliasMagnetId[$remoteMagnetComment->magnetId], |
|
|
|
if ($local = $db->findMagnetComment($aliasMagnetId[$remote->magnetId], |
|
|
|
$aliasUserId[$remoteMagnetComment->userId], |
|
|
|
$aliasUserId[$remote->userId], |
|
|
|
|
|
|
|
$remote->timeAdded)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$response['magnetComment'][] = [ |
|
|
|
|
|
|
|
'status' => true, |
|
|
|
|
|
|
|
'message' => sprintf( |
|
|
|
|
|
|
|
_('Magnet comment successfully associated with ID "%s"'), |
|
|
|
|
|
|
|
$local->magnetCommentId |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Magnet comment exists by timestamp added for this user, register new one |
|
|
|
|
|
|
|
else if ($magnetCommentId = $db->addMagnetComment($aliasMagnetId[$remote->magnetId], |
|
|
|
|
|
|
|
$aliasUserId[$remote->userId], |
|
|
|
$localMagnetCommentIdParent, |
|
|
|
$localMagnetCommentIdParent, |
|
|
|
$remote->value, |
|
|
|
$remote->value, |
|
|
|
$remote->approved, |
|
|
|
$remote->approved, |
|
|
|
true, |
|
|
|
true, |
|
|
|
$remote->timeAdded |
|
|
|
$remote->timeAdded)) |
|
|
|
); |
|
|
|
{ |
|
|
|
} |
|
|
|
$response['magnetComment'][] = [ |
|
|
|
|
|
|
|
|
|
|
|
$response = [ |
|
|
|
|
|
|
|
'status' => true, |
|
|
|
'status' => true, |
|
|
|
'message' => _('Magnet comment registered') |
|
|
|
'message' => sprintf( |
|
|
|
|
|
|
|
_('Magnet comment successfully synced with ID "%s"'), |
|
|
|
|
|
|
|
$magnetCommentId |
|
|
|
|
|
|
|
) |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'magnetDownload': |
|
|
|
case 'magnetDownload': |
|
|
@ -538,7 +695,7 @@ else |
|
|
|
// Magnet downloads |
|
|
|
// Magnet downloads |
|
|
|
if (!API_IMPORT_MAGNET_DOWNLOADS_ENABLED) |
|
|
|
if (!API_IMPORT_MAGNET_DOWNLOADS_ENABLED) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$response = [ |
|
|
|
$response['magnetDownload'][] = [ |
|
|
|
'status' => false, |
|
|
|
'status' => false, |
|
|
|
'message' => _('Magnet downloads import disabled on this node') |
|
|
|
'message' => _('Magnet downloads import disabled on this node') |
|
|
|
]; |
|
|
|
]; |
|
|
@ -551,9 +708,13 @@ else |
|
|
|
|
|
|
|
|
|
|
|
if (!Valid::magnetDownload($remote, $error)) |
|
|
|
if (!Valid::magnetDownload($remote, $error)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$response = [ |
|
|
|
$response['magnetDownload'][] = [ |
|
|
|
'status' => false, |
|
|
|
'status' => false, |
|
|
|
'message' => $error, |
|
|
|
'message' => sprintf( |
|
|
|
|
|
|
|
_('Magnet download data mismatch protocol with error: %s data: %s'), |
|
|
|
|
|
|
|
print_r($error, true), |
|
|
|
|
|
|
|
print_r($remote, true) |
|
|
|
|
|
|
|
), |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
continue 2; |
|
|
|
continue 2; |
|
|
@ -562,37 +723,51 @@ else |
|
|
|
// User local alias required |
|
|
|
// User local alias required |
|
|
|
if (!isset($aliasUserId[$remote->userId]) || !isset($aliasMagnetId[$remote->magnetId])) |
|
|
|
if (!isset($aliasUserId[$remote->userId]) || !isset($aliasMagnetId[$remote->magnetId])) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$response = [ |
|
|
|
$response['magnetDownload'][] = [ |
|
|
|
'status' => false, |
|
|
|
'status' => false, |
|
|
|
'message' => _('User and magnet data required for magnet downloads import') |
|
|
|
'message' => sprintf( |
|
|
|
|
|
|
|
_('Magnet download data relation not found for: %s'), |
|
|
|
|
|
|
|
print_r($remote, true) |
|
|
|
|
|
|
|
), |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
continue 2; |
|
|
|
continue 2; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Add new magnet download if not exist by timestamp added for this user |
|
|
|
// Magnet download exists by timestamp added for this user |
|
|
|
if (!$db->findMagnetDownload($aliasMagnetId[$remote->magnetId], |
|
|
|
if ($local = $db->findMagnetDownload($aliasMagnetId[$remote->magnetId], |
|
|
|
$aliasUserId[$remote->userId], |
|
|
|
$aliasUserId[$remote->userId], |
|
|
|
$remote->timeAdded)) |
|
|
|
$remote->timeAdded)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$db->addMagnetDownload( |
|
|
|
$response['magnetDownload'][] = [ |
|
|
|
$aliasMagnetId[$remote->magnetId], |
|
|
|
'status' => true, |
|
|
|
$aliasUserId[$remote->userId], |
|
|
|
'message' => sprintf( |
|
|
|
$remote->timeAdded |
|
|
|
_('Magnet download successfully associated with ID "%s"'), |
|
|
|
); |
|
|
|
$local->magnetDownloadId |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$response = [ |
|
|
|
// Magnet download exists by timestamp added for this user, register new one |
|
|
|
|
|
|
|
else if ($magnetDownloadId = $db->addMagnetDownload($aliasMagnetId[$remote->magnetId], |
|
|
|
|
|
|
|
$aliasUserId[$remote->userId], |
|
|
|
|
|
|
|
$remote->timeAdded)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$response['magnetDownload'][] = [ |
|
|
|
'status' => true, |
|
|
|
'status' => true, |
|
|
|
'message' => _('Magnet download registered') |
|
|
|
'message' => sprintf( |
|
|
|
|
|
|
|
_('Magnet download successfully synced with ID "%s"'), |
|
|
|
|
|
|
|
$magnetDownloadId |
|
|
|
|
|
|
|
) |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'magnetStar': |
|
|
|
case 'magnetStar': |
|
|
|
|
|
|
|
|
|
|
|
if (!API_IMPORT_MAGNET_STARS_ENABLED) |
|
|
|
if (!API_IMPORT_MAGNET_STARS_ENABLED) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$response = [ |
|
|
|
$response['magnetStar'][] = [ |
|
|
|
'status' => false, |
|
|
|
'status' => false, |
|
|
|
'message' => _('Magnet stars import disabled on this node') |
|
|
|
'message' => _('Magnet stars import disabled on this node') |
|
|
|
]; |
|
|
|
]; |
|
|
@ -605,9 +780,13 @@ else |
|
|
|
|
|
|
|
|
|
|
|
if (!Valid::magnetStar($remote, $error)) |
|
|
|
if (!Valid::magnetStar($remote, $error)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$response = [ |
|
|
|
$response['magnetStar'][] = [ |
|
|
|
'status' => false, |
|
|
|
'status' => false, |
|
|
|
'message' => $error |
|
|
|
'message' => sprintf( |
|
|
|
|
|
|
|
_('Magnet star data mismatch protocol with error: %s data: %s'), |
|
|
|
|
|
|
|
print_r($error, true), |
|
|
|
|
|
|
|
print_r($remote, true) |
|
|
|
|
|
|
|
), |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
continue 2; |
|
|
|
continue 2; |
|
|
@ -616,38 +795,52 @@ else |
|
|
|
// User local alias required |
|
|
|
// User local alias required |
|
|
|
if (!isset($aliasUserId[$remote->userId]) || !isset($aliasMagnetId[$remote->magnetId])) |
|
|
|
if (!isset($aliasUserId[$remote->userId]) || !isset($aliasMagnetId[$remote->magnetId])) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$response = [ |
|
|
|
$response['magnetStar'][] = [ |
|
|
|
'status' => false, |
|
|
|
'status' => false, |
|
|
|
'message' => _('User and magnet data required for magnet stars import') |
|
|
|
'message' => sprintf( |
|
|
|
|
|
|
|
_('Magnet star data relation not found for: %s'), |
|
|
|
|
|
|
|
print_r($remote, true) |
|
|
|
|
|
|
|
), |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
continue 2; |
|
|
|
continue 2; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Add new magnet star if not exist by timestamp added for this user |
|
|
|
// Magnet star exists by timestamp added for this user |
|
|
|
if (!$db->findMagnetStar($aliasMagnetId[$remote->magnetId], |
|
|
|
if ($local = $db->findMagnetStar($aliasMagnetId[$remote->magnetId], |
|
|
|
$aliasUserId[$remote->userId], |
|
|
|
$aliasUserId[$remote->userId], |
|
|
|
$remote->timeAdded)) |
|
|
|
$remote->timeAdded)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$db->addMagnetStar( |
|
|
|
$response['magnetStar'][] = [ |
|
|
|
$aliasMagnetId[$remote->magnetId], |
|
|
|
'status' => true, |
|
|
|
$aliasUserId[$remote->userId], |
|
|
|
'message' => sprintf( |
|
|
|
$remote->value, |
|
|
|
_('Magnet star successfully associated with ID "%s"'), |
|
|
|
$remote->timeAdded |
|
|
|
$local->magnetStarId |
|
|
|
); |
|
|
|
) |
|
|
|
|
|
|
|
]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$response = [ |
|
|
|
// Magnet star exists by timestamp added for this user, register new one |
|
|
|
|
|
|
|
else if ($magnetStarId = $db->addMagnetStar($aliasMagnetId[$remote->magnetId], |
|
|
|
|
|
|
|
$aliasUserId[$remote->userId], |
|
|
|
|
|
|
|
$remote->value, |
|
|
|
|
|
|
|
$remote->timeAdded)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$response['magnetStar'][] = [ |
|
|
|
'status' => true, |
|
|
|
'status' => true, |
|
|
|
'message' => _('Magnet star registered') |
|
|
|
'message' => sprintf( |
|
|
|
|
|
|
|
_('Magnet star successfully synced with ID "%s"'), |
|
|
|
|
|
|
|
$magnetStarId |
|
|
|
|
|
|
|
) |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'magnetView': |
|
|
|
case 'magnetView': |
|
|
|
|
|
|
|
|
|
|
|
if (!API_IMPORT_MAGNET_VIEWS_ENABLED) |
|
|
|
if (!API_IMPORT_MAGNET_VIEWS_ENABLED) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$response = [ |
|
|
|
$response['magnetView'][] = [ |
|
|
|
'status' => false, |
|
|
|
'status' => false, |
|
|
|
'message' => _('Magnet views import disabled on this node') |
|
|
|
'message' => _('Magnet views import disabled on this node') |
|
|
|
]; |
|
|
|
]; |
|
|
@ -660,9 +853,13 @@ else |
|
|
|
|
|
|
|
|
|
|
|
if (!Valid::magnetView($remote, $error)) |
|
|
|
if (!Valid::magnetView($remote, $error)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$response = [ |
|
|
|
$response['magnetView'][] = [ |
|
|
|
'status' => false, |
|
|
|
'status' => false, |
|
|
|
'message' => $error |
|
|
|
'message' => sprintf( |
|
|
|
|
|
|
|
_('Magnet view data mismatch protocol with error: %s data: %s'), |
|
|
|
|
|
|
|
print_r($error, true), |
|
|
|
|
|
|
|
print_r($remote, true) |
|
|
|
|
|
|
|
), |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
continue 2; |
|
|
|
continue 2; |
|
|
@ -671,54 +868,100 @@ else |
|
|
|
// User local alias required |
|
|
|
// User local alias required |
|
|
|
if (!isset($aliasUserId[$remote->userId]) || !isset($aliasMagnetId[$remote->magnetId])) |
|
|
|
if (!isset($aliasUserId[$remote->userId]) || !isset($aliasMagnetId[$remote->magnetId])) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$response = [ |
|
|
|
$response['magnetView'][] = [ |
|
|
|
'status' => false, |
|
|
|
'status' => false, |
|
|
|
'message' => _('User and magnet data required for magnet views import') |
|
|
|
'message' => sprintf( |
|
|
|
|
|
|
|
_('Magnet view data relation not found for: %s'), |
|
|
|
|
|
|
|
print_r($remote, true) |
|
|
|
|
|
|
|
), |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
continue 2; |
|
|
|
continue 2; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Add new magnet view if not exist by timestamp added for this user |
|
|
|
// Magnet view exists by timestamp added for this user |
|
|
|
if (!$db->findMagnetView($aliasMagnetId[$remote->magnetId], |
|
|
|
if ($local = $db->findMagnetView($aliasMagnetId[$remote->magnetId], |
|
|
|
$aliasUserId[$remote->userId], |
|
|
|
$aliasUserId[$remote->userId], |
|
|
|
$remote->timeAdded)) |
|
|
|
$remote->timeAdded)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$db->addMagnetView( |
|
|
|
$response['magnetView'][] = [ |
|
|
|
$aliasMagnetId[$remote->magnetId], |
|
|
|
'status' => true, |
|
|
|
$aliasUserId[$remote->userId], |
|
|
|
'message' => sprintf( |
|
|
|
$remote->timeAdded |
|
|
|
_('Magnet view successfully associated with ID "%s"'), |
|
|
|
); |
|
|
|
$local->magnetViewId |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$response = [ |
|
|
|
// Magnet view exists by timestamp added for this user, register new one |
|
|
|
|
|
|
|
else if ($magnetViewId = $db->addMagnetView($aliasMagnetId[$remote->magnetId], |
|
|
|
|
|
|
|
$aliasUserId[$remote->userId], |
|
|
|
|
|
|
|
$remote->timeAdded)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$response['magnetView'][] = [ |
|
|
|
'status' => true, |
|
|
|
'status' => true, |
|
|
|
'message' => _('Magnet view registered') |
|
|
|
'message' => sprintf( |
|
|
|
|
|
|
|
_('Magnet view successfully synced with ID "%s"'), |
|
|
|
|
|
|
|
$magnetViewId |
|
|
|
|
|
|
|
) |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
|
|
|
|
|
|
|
|
|
$response = |
|
|
|
$response[$field][] = |
|
|
|
[ |
|
|
|
[ |
|
|
|
'status' => false, |
|
|
|
'status' => false, |
|
|
|
'message' => _('Data field not supported') |
|
|
|
'message' => _('Field "%s" not supported by protocol') |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
continue 2; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$db->commit(); |
|
|
|
$db->commit(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
catch (EXception $error) |
|
|
|
catch (Exception $error) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
$debug['exception'][] = print_r($error, true); |
|
|
|
|
|
|
|
|
|
|
|
$db->rollBack(); |
|
|
|
$db->rollBack(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$response = |
|
|
|
// Debug log |
|
|
|
|
|
|
|
if (LOG_API_PUSH_ENABLED) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
@mkdir(LOG_DIRECTORY, 0770, true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($handle = fopen(LOG_DIRECTORY . '/' . LOG_API_PUSH_FILENAME, 'a+')) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$debug['time']['total'] = microtime(true) - $debug['time']['total']; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$debug['memory']['total'] = memory_get_usage() - $debug['memory']['start']; |
|
|
|
|
|
|
|
$debug['memory']['peaks'] = memory_get_peak_usage(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$debug['db']['total']['select'] = $db->getDebug()->query->select->total; |
|
|
|
|
|
|
|
$debug['db']['total']['insert'] = $db->getDebug()->query->insert->total; |
|
|
|
|
|
|
|
$debug['db']['total']['update'] = $db->getDebug()->query->update->total; |
|
|
|
|
|
|
|
$debug['db']['total']['delete'] = $db->getDebug()->query->delete->total; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fwrite( |
|
|
|
|
|
|
|
$handle, |
|
|
|
|
|
|
|
print_r( |
|
|
|
[ |
|
|
|
[ |
|
|
|
'status' => false, |
|
|
|
'response' => $response, |
|
|
|
'message' => $error |
|
|
|
'debug' => $debug |
|
|
|
]; |
|
|
|
], |
|
|
|
} |
|
|
|
true |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fclose($handle); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
chmod(LOG_DIRECTORY . '/' . LOG_API_PUSH_FILENAME, 0770); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|