initial work on obj import, rename import_profile_photo to import_xchan_photo to more accurately state its purpose.

This commit is contained in:
redmatrix 2015-09-01 22:03:10 -07:00
parent c5578d7964
commit 6cc60ba477
10 changed files with 43 additions and 30 deletions

View File

@ -325,7 +325,7 @@ function app_store($arr) {
return $ret; return $ret;
if($arr['photo'] && ! strstr($arr['photo'],z_root())) { if($arr['photo'] && ! strstr($arr['photo'],z_root())) {
$x = import_profile_photo($arr['photo'],get_observer_hash(),true); $x = import_xchan_photo($arr['photo'],get_observer_hash(),true);
$arr['photo'] = $x[1]; $arr['photo'] = $x[1];
} }
@ -378,7 +378,7 @@ function app_update($arr) {
return $ret; return $ret;
if($arr['photo'] && ! strstr($arr['photo'],z_root())) { if($arr['photo'] && ! strstr($arr['photo'],z_root())) {
$x = import_profile_photo($arr['photo'],get_observer_hash(),true); $x = import_xchan_photo($arr['photo'],get_observer_hash(),true);
$arr['photo'] = $x[1]; $arr['photo'] = $x[1];
} }

View File

@ -230,7 +230,7 @@ function xchan_store($arr) {
if(! $r) if(! $r)
return $r; return $r;
$photos = import_profile_photo($arr['photo'],$arr['hash']); $photos = import_xchan_photo($arr['photo'],$arr['hash']);
$r = q("update xchan set xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s' where xchan_hash = '%s'", $r = q("update xchan set xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s' where xchan_hash = '%s'",
dbesc(datetime_convert()), dbesc(datetime_convert()),
dbesc($photos[0]), dbesc($photos[0]),

View File

@ -1127,7 +1127,7 @@ function import_author_rss($x) {
if($r && $x['photo']) { if($r && $x['photo']) {
$photos = import_profile_photo($x['photo']['src'],$x['url']); $photos = import_xchan_photo($x['photo']['src'],$x['url']);
if($photos) { if($photos) {
/** @bug $arr is undefined in this SQL query */ /** @bug $arr is undefined in this SQL query */
@ -1172,7 +1172,7 @@ function import_author_unknown($x) {
); );
if($r && $x['photo']) { if($r && $x['photo']) {
$photos = import_profile_photo($x['photo']['src'],$x['url']); $photos = import_xchan_photo($x['photo']['src'],$x['url']);
if($photos) { if($photos) {
/** @bug $arr is undefined in this SQL query */ /** @bug $arr is undefined in this SQL query */

View File

@ -1035,7 +1035,7 @@ function discover_by_url($url,$arr = null) {
dbesc(datetime_convert()) dbesc(datetime_convert())
); );
$photos = import_profile_photo($photo,$guid); $photos = import_xchan_photo($photo,$guid);
$r = q("update xchan set xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s' where xchan_hash = '%s'", $r = q("update xchan set xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s' where xchan_hash = '%s'",
dbesc(datetime_convert()), dbesc(datetime_convert()),
dbesc($photos[0]), dbesc($photos[0]),
@ -1192,7 +1192,7 @@ function discover_by_webbie($webbie) {
dbescdate(datetime_convert()) dbescdate(datetime_convert())
); );
} }
$photos = import_profile_photo($vcard['photo'],$addr); $photos = import_xchan_photo($vcard['photo'],$addr);
$r = q("update xchan set xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s' where xchan_hash = '%s'", $r = q("update xchan set xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s' where xchan_hash = '%s'",
dbescdate(datetime_convert('UTC','UTC',$arr['photo_updated'])), dbescdate(datetime_convert('UTC','UTC',$arr['photo_updated'])),
dbesc($photos[0]), dbesc($photos[0]),

View File

@ -557,14 +557,14 @@ function guess_image_type($filename, $headers = '') {
} }
function import_profile_photo($photo,$xchan,$thing = false) { function import_xchan_photo($photo,$xchan,$thing = false) {
$a = get_app(); $a = get_app();
$flags = (($thing) ? PHOTO_THING : PHOTO_XCHAN); $flags = (($thing) ? PHOTO_THING : PHOTO_XCHAN);
$album = (($thing) ? 'Things' : 'Contact Photos'); $album = (($thing) ? 'Things' : 'Contact Photos');
logger('import_profile_photo: updating channel photo from ' . $photo . ' for ' . $xchan, LOGGER_DEBUG); logger('import_xchan_photo: updating channel photo from ' . $photo . ' for ' . $xchan, LOGGER_DEBUG);
if($thing) if($thing)
$hash = photo_new_resource(); $hash = photo_new_resource();
@ -650,7 +650,7 @@ function import_profile_photo($photo,$xchan,$thing = false) {
$micro = $a->get_baseurl() . '/photo/' . $hash . '-6'; $micro = $a->get_baseurl() . '/photo/' . $hash . '-6';
} }
else { else {
logger('import_profile_photo: invalid image from ' . $photo); logger('import_xchan_photo: invalid image from ' . $photo);
$photo_failure = true; $photo_failure = true;
} }
if($photo_failure) { if($photo_failure) {

View File

@ -235,7 +235,7 @@ function poller_run($argv, $argc){
if($r) { if($r) {
require_once('include/photo/photo_driver.php'); require_once('include/photo/photo_driver.php');
foreach($r as $rr) { foreach($r as $rr) {
$photos = import_profile_photo($rr['xchan_photo_l'],$rr['xchan_hash']); $photos = import_xchan_photo($rr['xchan_photo_l'],$rr['xchan_hash']);
$x = q("update xchan set xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s' $x = q("update xchan set xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s'
where xchan_hash = '%s'", where xchan_hash = '%s'",
dbesc($photos[0]), dbesc($photos[0]),

View File

@ -801,7 +801,7 @@ function import_xchan($arr,$ud_flags = UPDATE_FLAGS_UPDATED, $ud_arr = null) {
); );
} }
} else { } else {
$photos = import_profile_photo($arr['photo'], $xchan_hash); $photos = import_xchan_photo($arr['photo'], $xchan_hash);
} }
if ($photos) { if ($photos) {
if ($photos[4]) { if ($photos[4]) {

View File

@ -422,7 +422,7 @@ function import_post(&$a) {
require_once('include/photo/photo_driver.php'); require_once('include/photo/photo_driver.php');
$photos = import_profile_photo($xchan['xchan_photo_l'],$xchan['xchan_hash']); $photos = import_xchan_photo($xchan['xchan_photo_l'],$xchan['xchan_hash']);
if($photos[4]) if($photos[4])
$photodate = NULL_DATE; $photodate = NULL_DATE;
else else
@ -556,22 +556,35 @@ function import_post(&$a) {
ref_session_write(session_id(), serialize($_SESSION)); ref_session_write(session_id(), serialize($_SESSION));
} }
$objs = $data['obj'];
if($objs) {
foreach($objs as $obj) {
// if it's the old term format - too hard to support
if(! $obj['obj_created'])
continue;
$baseurl = $obj['obj_baseurl'];
unset($obj['obj_id']);
unset($obj['obj_baseurl']);
// This needs more work - we also need the term where otype = 6 to link with this, and the terms need to be relocated. $obj['obj_channel'] = $channel['channel_id'];
// $objs = $data['obj'];
// if($objs) {
// foreach($objs as $obj) {
// unset($obj['obj_id']);
// $obj['channel'] = $channel['channel_id'];
// dbesc_array($obj); if($baseurl && (strpos($obj['obj_url'],$baseurl . '/thing/') !== false)) {
// $r = dbq("INSERT INTO obj (`" $obj['obj_url'] = str_replace($baseurl,z_root(),$obj['obj_url']);
// . implode("`, `", array_keys($obj)) }
// . "`) VALUES ('"
// . implode("', '", array_values($obj)) if($obj['obj_imgurl']) {
// . "')" ); $x = import_xchan_photo($obj['obj_imgurl'],get_observer_hash(),true);
// } $obj['obj_imgurl'] = $x[0];
// } }
dbesc_array($obj);
$r = dbq("INSERT INTO obj (`"
. implode("`, `", array_keys($obj))
. "`) VALUES ('"
. implode("', '", array_values($obj))
. "')" );
}
}
$saved_notification_flags = notifications_off($channel['channel_id']); $saved_notification_flags = notifications_off($channel['channel_id']);

View File

@ -155,7 +155,7 @@ function openid_content(&$a) {
); );
if($r) { if($r) {
$photos = import_profile_photo($pphoto,$url); $photos = import_xchan_photo($pphoto,$url);
if($photos) { if($photos) {
$z = q("update xchan set xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', $z = q("update xchan set xchan_photo_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s',
xchan_photo_s = '%s', xchan_photo_mimetype = '%s' where xchan_hash = '%s'", xchan_photo_s = '%s', xchan_photo_mimetype = '%s' where xchan_hash = '%s'",

View File

@ -88,7 +88,7 @@ function thing_init(&$a) {
} }
$orig_record = $t[0]; $orig_record = $t[0];
if($photo != $orig_record['obj_imgurl']) { if($photo != $orig_record['obj_imgurl']) {
$arr = import_profile_photo($photo,get_observer_hash(),true); $arr = import_xchan_photo($photo,get_observer_hash(),true);
$local_photo = $arr[0]; $local_photo = $arr[0];
$local_photo_type = $arr[3]; $local_photo_type = $arr[3];
} }
@ -125,7 +125,7 @@ function thing_init(&$a) {
$local_photo = null; $local_photo = null;
if($photo) { if($photo) {
$arr = import_profile_photo($photo,get_observer_hash(),true); $arr = import_xchan_photo($photo,get_observer_hash(),true);
$local_photo = $arr[0]; $local_photo = $arr[0];
$local_photo_type = $arr[3]; $local_photo_type = $arr[3];
} }