/** * @brief Imports a directory profile. * * @param string $hash * @param array $profile * @param string $addr * @param number $ud_flags * @param number $suppress_update default 0 * @return boolean $updated if something changed */ function import_directory_profile($hash, $profile, $addr, $ud_flags = UPDATE_FLAGS_UPDATED, $suppress_update = 0) { logger('import_directory_profile', LOGGER_DEBUG); if (!$hash) { return false; } $arr = array(); $arr['xprof_hash'] = $hash; $arr['xprof_dob'] = datetime_convert('', '', $profile['birthday'], 'Y-m-d'); // !!!! check this for 0000 year $arr['xprof_age'] = $profile['age'] ? intval($profile['age']) : 0; $arr['xprof_desc'] = $profile['description'] ? htmlspecialchars($profile['description'], ENT_COMPAT, 'UTF-8', false) : ''; $arr['xprof_gender'] = $profile['gender'] ? htmlspecialchars($profile['gender'], ENT_COMPAT, 'UTF-8', false) : ''; $arr['xprof_marital'] = $profile['marital'] ? htmlspecialchars($profile['marital'], ENT_COMPAT, 'UTF-8', false) : ''; $arr['xprof_sexual'] = $profile['sexual'] ? htmlspecialchars($profile['sexual'], ENT_COMPAT, 'UTF-8', false) : ''; $arr['xprof_locale'] = $profile['locale'] ? htmlspecialchars($profile['locale'], ENT_COMPAT, 'UTF-8', false) : ''; $arr['xprof_region'] = $profile['region'] ? htmlspecialchars($profile['region'], ENT_COMPAT, 'UTF-8', false) : ''; $arr['xprof_postcode'] = $profile['postcode'] ? htmlspecialchars($profile['postcode'], ENT_COMPAT, 'UTF-8', false) : ''; $arr['xprof_country'] = $profile['country'] ? htmlspecialchars($profile['country'], ENT_COMPAT, 'UTF-8', false) : ''; $arr['xprof_about'] = $profile['about'] ? htmlspecialchars($profile['about'], ENT_COMPAT, 'UTF-8', false) : ''; $arr['xprof_homepage'] = $profile['homepage'] ? htmlspecialchars($profile['homepage'], ENT_COMPAT, 'UTF-8', false) : ''; $arr['xprof_hometown'] = $profile['hometown'] ? htmlspecialchars($profile['hometown'], ENT_COMPAT, 'UTF-8', false) : ''; $clean = array(); if (array_key_exists('keywords', $profile) and is_array($profile['keywords'])) { import_directory_keywords($hash, $profile['keywords']); foreach ($profile['keywords'] as $kw) { $kw = trim(htmlspecialchars($kw, ENT_COMPAT, 'UTF-8', false)); $kw = trim($kw, ','); $clean[] = $kw; } } $arr['xprof_keywords'] = implode(' ', $clean); // Self censored, make it so // These are not translated, so the German "erwachsenen" keyword will not censor the directory profile. Only the English form - "adult". if (in_arrayi('nsfw', $clean) || in_arrayi('adult', $clean)) { q("update xchan set xchan_selfcensored = 1 where xchan_hash = '%s'", dbesc($hash)); } $r = q("select * from xprof where xprof_hash = '%s' limit 1", dbesc($hash)); if ($arr['xprof_age'] > 150) { $arr['xprof_age'] = 150; } if ($arr['xprof_age'] < 0) { $arr['xprof_age'] = 0; } if ($r) { $update = false; foreach ($r[0] as $k => $v) { if (array_key_exists($k, $arr) && $arr[$k] != $v) { logger('import_directory_profile: update ' . $k . ' => ' . $arr[$k]); $update = true; break; } } if ($update) { q("update xprof set\n\t\t\t\txprof_desc = '%s',\n\t\t\t\txprof_dob = '%s',\n\t\t\t\txprof_age = %d,\n\t\t\t\txprof_gender = '%s',\n\t\t\t\txprof_marital = '%s',\n\t\t\t\txprof_sexual = '%s',\n\t\t\t\txprof_locale = '%s',\n\t\t\t\txprof_region = '%s',\n\t\t\t\txprof_postcode = '%s',\n\t\t\t\txprof_country = '%s',\n\t\t\t\txprof_about = '%s',\n\t\t\t\txprof_homepage = '%s',\n\t\t\t\txprof_hometown = '%s',\n\t\t\t\txprof_keywords = '%s'\n\t\t\t\twhere xprof_hash = '%s'", dbesc($arr['xprof_desc']), dbesc($arr['xprof_dob']), intval($arr['xprof_age']), dbesc($arr['xprof_gender']), dbesc($arr['xprof_marital']), dbesc($arr['xprof_sexual']), dbesc($arr['xprof_locale']), dbesc($arr['xprof_region']), dbesc($arr['xprof_postcode']), dbesc($arr['xprof_country']), dbesc($arr['xprof_about']), dbesc($arr['xprof_homepage']), dbesc($arr['xprof_hometown']), dbesc($arr['xprof_keywords']), dbesc($arr['xprof_hash'])); } } else { $update = true; logger('import_directory_profile: new profile '); q("insert into xprof (xprof_hash, xprof_desc, xprof_dob, xprof_age, xprof_gender, xprof_marital, xprof_sexual, xprof_locale, xprof_region, xprof_postcode, xprof_country, xprof_about, xprof_homepage, xprof_hometown, xprof_keywords) values ('%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s') ", dbesc($arr['xprof_hash']), dbesc($arr['xprof_desc']), dbesc($arr['xprof_dob']), intval($arr['xprof_age']), dbesc($arr['xprof_gender']), dbesc($arr['xprof_marital']), dbesc($arr['xprof_sexual']), dbesc($arr['xprof_locale']), dbesc($arr['xprof_region']), dbesc($arr['xprof_postcode']), dbesc($arr['xprof_country']), dbesc($arr['xprof_about']), dbesc($arr['xprof_homepage']), dbesc($arr['xprof_hometown']), dbesc($arr['xprof_keywords'])); } $d = array('xprof' => $arr, 'profile' => $profile, 'update' => $update); call_hooks('import_directory_profile', $d); if ($d['update'] && !$suppress_update) { update_modtime($arr['xprof_hash'], random_string() . '@' . get_app()->get_hostname(), $addr, $ud_flags); } return $d['update']; }
/** * @brief Push local channel updates to a local directory server. * * This is called from include/directory.php if a profile is to be pushed to the * directory and the local hub in this case is any kind of directory server. * * @param int $uid * @param boolean $force */ function local_dir_update($uid, $force) { logger('local_dir_update: uid: ' . $uid, LOGGER_DEBUG); $p = q("select channel.channel_hash, channel_address, channel_timezone, profile.* from profile left join channel on channel_id = uid where uid = %d and is_default = 1", intval($uid)); $profile = array(); $profile['encoding'] = 'zot'; if ($p) { $hash = $p[0]['channel_hash']; $profile['description'] = $p[0]['pdesc']; $profile['birthday'] = $p[0]['dob']; if ($age = age($p[0]['dob'], $p[0]['channel_timezone'], '')) { $profile['age'] = $age; } $profile['gender'] = $p[0]['gender']; $profile['marital'] = $p[0]['marital']; $profile['sexual'] = $p[0]['sexual']; $profile['locale'] = $p[0]['locality']; $profile['region'] = $p[0]['region']; $profile['postcode'] = $p[0]['postal_code']; $profile['country'] = $p[0]['country_name']; $profile['about'] = $p[0]['about']; $profile['homepage'] = $p[0]['homepage']; $profile['hometown'] = $p[0]['hometown']; if ($p[0]['keywords']) { $tags = array(); $k = explode(' ', $p[0]['keywords']); if ($k) { foreach ($k as $kk) { if (trim($kk)) { $tags[] = trim($kk); } } } if ($tags) { $profile['keywords'] = $tags; } } $hidden = 1 - intval($p[0]['publish']); logger('hidden: ' . $hidden); $r = q("select xchan_hidden from xchan where xchan_hash = '%s' limit 1", dbesc($p[0]['channel_hash'])); if (intval($r[0]['xchan_hidden']) != $hidden) { $r = q("update xchan set xchan_hidden = %d where xchan_hash = '%s'", intval($hidden), dbesc($p[0]['channel_hash'])); } $arr = array('channel_id' => $uid, 'hash' => $hash, 'profile' => $profile); call_hooks('local_dir_update', $arr); $address = $p[0]['channel_address'] . '@' . App::get_hostname(); if (perm_is_allowed($uid, '', 'view_profile')) { import_directory_profile($hash, $arr['profile'], $address, 0); } else { // they may have made it private $r = q("delete from xprof where xprof_hash = '%s'", dbesc($hash)); $r = q("delete from xtag where xtag_hash = '%s'", dbesc($hash)); } } $ud_hash = random_string() . '@' . App::get_hostname(); update_modtime($hash, $ud_hash, $p[0]['channel_address'] . '@' . App::get_hostname(), $force ? UPDATE_FLAGS_FORCED : UPDATE_FLAGS_UPDATED); }