From acf26d5c63c8b3316d713ce08b397f35aae03460 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Thu, 23 Jun 2016 01:17:44 -0700 Subject: code cleanup for profile_photos --- include/photos.php | 65 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 20 deletions(-) (limited to 'include') diff --git a/include/photos.php b/include/photos.php index da6118b38..c70478146 100644 --- a/include/photos.php +++ b/include/photos.php @@ -707,40 +707,65 @@ function gps2Num($coordPart) { return floatval($parts[0]) / floatval($parts[1]); } -function profile_photo_set_profile_perms($profileid = '') { +function profile_photo_set_profile_perms($uid, $profileid = 0) { $allowcid = ''; - if (x($profileid)) { - - $r = q("SELECT photo, profile_guid, id, is_default, uid FROM profile WHERE profile.id = %d OR profile.profile_guid = '%s' LIMIT 1", intval($profileid), dbesc($profileid)); - - } else { - + if($profileid) { + $r = q("SELECT photo, profile_guid, id, is_default, uid + FROM profile WHERE uid = %d and ( profile.id = %d OR profile.profile_guid = '%s') LIMIT 1", + intval($profileid), + dbesc($profileid) + ); + } + else { logger('Resetting permissions on default-profile-photo for user'.local_channel()); - $r = q("SELECT photo, profile_guid, id, is_default, uid FROM profile WHERE profile.uid = %d AND is_default = 1 LIMIT 1", intval(local_channel()) ); //If no profile is given, we update the default profile + + $r = q("SELECT photo, profile_guid, id, is_default, uid FROM profile + WHERE profile.uid = %d AND is_default = 1 LIMIT 1", + intval($uid) + ); //If no profile is given, we update the default profile } + if(! $r) + return; $profile = $r[0]; - if(x($profile['id']) && x($profile['photo'])) { - preg_match("@\w*(?=-\d*$)@i", $profile['photo'], $resource_id); - $resource_id = $resource_id[0]; + + if($profile['id'] && $profile['photo']) { + preg_match("@\w*(?=-\d*$)@i", $profile['photo'], $resource_id); + $resource_id = $resource_id[0]; - if (intval($profile['is_default']) != 1) { - $r0 = q("SELECT channel_hash FROM channel WHERE channel_id = %d LIMIT 1", intval(local_channel()) ); - $r1 = q("SELECT abook.abook_xchan FROM abook WHERE abook_profile = '%d' ", intval($profile['id'])); //Should not be needed in future. Catches old int-profile-ids. - $r2 = q("SELECT abook.abook_xchan FROM abook WHERE abook_profile = '%s'", dbesc($profile['profile_guid'])); + if (! intval($profile['is_default'])) { + $r0 = q("SELECT channel_hash FROM channel WHERE channel_id = %d LIMIT 1", + intval($uid) + ); + //Should not be needed in future. Catches old int-profile-ids. + $r1 = q("SELECT abook.abook_xchan FROM abook WHERE abook_profile = '%d' ", + intval($profile['id']) + ); + $r2 = q("SELECT abook.abook_xchan FROM abook WHERE abook_profile = '%s'", + dbesc($profile['profile_guid']) + ); $allowcid = "<" . $r0[0]['channel_hash'] . ">"; foreach ($r1 as $entry) { $allowcid .= "<" . $entry['abook_xchan'] . ">"; } foreach ($r2 as $entry) { - $allowcid .= "<" . $entry['abook_xchan'] . ">"; - } + $allowcid .= "<" . $entry['abook_xchan'] . ">"; + } - q("UPDATE `photo` SET allow_cid = '%s' WHERE resource_id = '%s' AND uid = %d",dbesc($allowcid),dbesc($resource_id),intval($profile['uid'])); + q("UPDATE photo SET allow_cid = '%s' WHERE resource_id = '%s' AND uid = %d", + dbesc($allowcid), + dbesc($resource_id), + intval($uid) + ); - } else { - q("UPDATE `photo` SET allow_cid = '' WHERE profile = 1 AND uid = %d",intval($profile['uid'])); //Reset permissions on default profile picture to public + } + else { + //Reset permissions on default profile picture to public + q("UPDATE photo SET allow_cid = '' WHERE photo_usage = %d AND uid = %d", + intval(PHOTO_PROFILE), + intval($uid) + ); } } -- cgit v1.2.3 From e5c66d94f22d0efcdec0796872e9be81bff1bb4e Mon Sep 17 00:00:00 2001 From: redmatrix Date: Thu, 23 Jun 2016 05:18:58 -0700 Subject: relocate the cache class --- include/cache.php | 44 -------------------------------------------- include/oembed.php | 6 ++++-- include/text.php | 28 ++-------------------------- 3 files changed, 6 insertions(+), 72 deletions(-) delete mode 100644 include/cache.php (limited to 'include') diff --git a/include/cache.php b/include/cache.php deleted file mode 100644 index 4a3f453e1..000000000 --- a/include/cache.php +++ /dev/null @@ -1,44 +0,0 @@ -= 5.4 - * - * @FIXME We already have php >= 5.4 requirements, so can we remove this? - */ -if(! function_exists('hex2bin')) { -function hex2bin($s) { - if(! (is_string($s) && strlen($s))) - return ''; - - if(strlen($s) & 1) { - logger('hex2bin: illegal hex string: ' . $s); - return $s; - } - - if(! ctype_xdigit($s)) { - return($s); - } - - return(pack("H*",$s)); -}} - - // Automatic pagination. // To use, get the count of total items. // Then call App::set_pager_total($number_items); @@ -1283,7 +1259,7 @@ function normalise_link($url) { * is https and the other isn't, or if one is www.something and the other * isn't - and also ignore case differences. * - * @see normalis_link() + * @see normalise_link() * * @param string $a * @param string $b @@ -1635,7 +1611,7 @@ function prepare_text($text, $content_type = 'text/bbcode', $cache = false) { function create_export_photo_body(&$item) { if(($item['verb'] === ACTIVITY_POST) && ($item['obj_type'] === ACTIVITY_OBJ_PHOTO)) { - $j = json_decode($item['object'],true); + $j = json_decode($item['obj'],true); if($j) { $item['body'] .= "\n\n" . (($j['body']) ? $j['body'] : $j['bbcode']); $item['sig'] = ''; -- cgit v1.2.3 From b19bbf54736b83afaa26aa11ba95c7816c7f8599 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Thu, 23 Jun 2016 18:12:26 -0700 Subject: change AbConfig to use channel_id instead of channel_hash; which was a mistake in retrospect --- include/channel.php | 2 +- include/config.php | 16 ++++++++-------- include/zot.php | 5 ++--- 3 files changed, 11 insertions(+), 12 deletions(-) (limited to 'include') diff --git a/include/channel.php b/include/channel.php index a0424ee39..a7624f060 100644 --- a/include/channel.php +++ b/include/channel.php @@ -516,7 +516,7 @@ function identity_basic_export($channel_id, $items = false) { for($x = 0; $x < count($ret['abook']); $x ++) { $xchans[] = $ret['abook'][$x]['abook_chan']; - $abconfig = load_abconfig($ret['channel']['channel_hash'],$ret['abook'][$x]['abook_xchan']); + $abconfig = load_abconfig($channel_id,$ret['abook'][$x]['abook_xchan']); if($abconfig) $ret['abook'][$x]['abconfig'] = $abconfig; } diff --git a/include/config.php b/include/config.php index 65199283d..ece22793f 100644 --- a/include/config.php +++ b/include/config.php @@ -98,20 +98,20 @@ function del_aconfig($account_id, $family, $key) { } -function load_abconfig($chash,$xhash) { - Zlib\AbConfig::Load($chash,$xhash); +function load_abconfig($chan,$xhash) { + Zlib\AbConfig::Load($chan,$xhash); } -function get_abconfig($chash,$xhash,$family,$key) { - return Zlib\AbConfig::Get($chash,$xhash,$family,$key); +function get_abconfig($chan,$xhash,$family,$key) { + return Zlib\AbConfig::Get($chan,$xhash,$family,$key); } -function set_abconfig($chash,$xhash,$family,$key,$value) { - return Zlib\AbConfig::Set($chash,$xhash,$family,$key,$value); +function set_abconfig($chan,$xhash,$family,$key,$value) { + return Zlib\AbConfig::Set($chan,$xhash,$family,$key,$value); } -function del_abconfig($chash,$xhash,$family,$key) { - return Zlib\AbConfig::Delete($chash,$xhash,$family,$key); +function del_abconfig($chan,$xhash,$family,$key) { + return Zlib\AbConfig::Delete($chan,$xhash,$family,$key); } function load_iconfig(&$item) { diff --git a/include/zot.php b/include/zot.php index 2530e55bb..6dd789181 100644 --- a/include/zot.php +++ b/include/zot.php @@ -552,7 +552,7 @@ function zot_refresh($them, $channel = null, $force = false) { unset($new_connection[0]['abook_account']); unset($new_connection[0]['abook_channel']); - $abconfig = load_abconfig($channel['channel_hash'],$new_connection['abook_xchan']); + $abconfig = load_abconfig($channel['channel_id'],$new_connection['abook_xchan']); if($abconfig) $new_connection['abconfig'] = $abconfig; @@ -3335,8 +3335,7 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) { if($abconfig) { // @fixme does not handle sync of del_abconfig foreach($abconfig as $abc) { - if($abc['chan'] === $channel['channel_hash']) - set_abconfig($abc['chan'],$abc['xchan'],$abc['cat'],$abc['k'],$abc['v']); + set_abconfig($channel['channel_id'],$abc['xchan'],$abc['cat'],$abc['k'],$abc['v']); } } } -- cgit v1.2.3