/** * @brief Create a system channel - which has no account attached. * */ function create_sys_channel() { if (get_sys_channel()) { return; } // Ensure that there is a host keypair. if (!get_config('system', 'pubkey') && !get_config('system', 'prvkey')) { require_once 'include/crypto.php'; $hostkey = new_keypair(4096); set_config('system', 'pubkey', $hostkey['pubkey']); set_config('system', 'prvkey', $hostkey['prvkey']); } create_identity(array('account_id' => 'xxx', 'nickname' => 'sys', 'name' => 'System', 'pageflags' => 0, 'publish' => 0, 'system' => 1)); }
function new_channel_post(&$a) { $arr = $_POST; if (($arr['account_id'] = get_account_id()) === false) { notice(t('Permission denied.') . EOL); return; } $result = create_identity($arr); if (!$result['success']) { notice($result['message']); return; } $newuid = $result['channel']['channel_id']; change_channel($result['channel']['channel_id']); if (!strlen($next_page = get_config('system', 'workflow_channel_next'))) { $next_page = 'settings'; } goaway(z_root() . '/' . $next_page); }
function new_channel_post(&$a) { $arr = $_POST; $acc = $a->get_account(); $arr['account_id'] = get_account_id(); // prevent execution by delegated channels as well as those not logged in. // get_account_id() returns the account_id from the session. But $a->account // may point to the original authenticated account. if (!$acc || $acc['account_id'] != $arr['account_id']) { notice(t('Permission denied.') . EOL); return; } $result = create_identity($arr); if (!$result['success']) { notice($result['message']); return; } $newuid = $result['channel']['channel_id']; change_channel($result['channel']['channel_id']); if (!strlen($next_page = get_config('system', 'workflow_channel_next'))) { $next_page = 'settings'; } goaway(z_root() . '/' . $next_page); }
function auto_channel_create($account_id) { if (!$account_id) { return false; } $arr = array(); $arr['account_id'] = $account_id; $arr['name'] = get_aconfig($account_id, 'register', 'channel_name'); $arr['nickname'] = legal_webbie(get_aconfig($account_id, 'register', 'channel_address')); $arr['permissions_role'] = get_aconfig($account_id, 'register', 'permissions_role'); del_aconfig($account_id, 'register', 'channel_name'); del_aconfig($account_id, 'register', 'channel_address'); del_aconfig($account_id, 'register', 'permissions_role'); if (!$arr['name'] || !$arr['nickname']) { $x = q("select * from account where account_id = %d limit 1", intval($account_id)); if ($x) { if (!$arr['name']) { $arr['name'] = substr($x[0]['account_email'], 0, strpos($x[0]['account_email'], '@')); } if (!$arr['nickname']) { $arr['nickname'] = legal_webbie(substr($x[0]['account_email'], 0, strpos($x[0]['account_email'], '@'))); } } } if (!$arr['permissions_role']) { $arr['permissions_role'] = 'social'; } if (validate_channelname($arr['name'])) { return false; } if ($arr['nickname'] === 'sys') { $arr['nickname'] = $arr['nickname'] . mt_rand(1000, 9999); } $arr['nickname'] = check_webbie(array($arr['nickname'], $arr['nickname'] . mt_rand(1000, 9999))); return create_identity($arr); }
function import_diaspora($data) { $a = get_app(); $account = $a->get_account(); if (!$account) { return false; } $address = escape_tags($data['user']['username']); if (!$address) { notice(t('No username found in import file.') . EOL); return false; } $r = q("select * from channel where channel_address = '%s' limit 1", dbesc($address)); if ($r) { // try at most ten times to generate a unique address. $x = 0; $found_unique = false; do { $tmp = $address . mt_rand(1000, 9999); $r = q("select * from channel where channel_address = '%s' limit 1", dbesc($tmp)); if (!$r) { $address = $tmp; $found_unique = true; break; } $x++; } while ($x < 10); if (!$found_unique) { logger('import_diaspora: duplicate channel address. randomisation failed.'); notice(t('Unable to create a unique channel address. Import failed.') . EOL); return; } } $c = create_identity(array('name' => escape_tags($data['user']['name']), 'nickname' => $address, 'account_id' => $account['account_id'], 'permissions_role' => 'social')); if (!$c['success']) { return; } $channel_id = $c['channel']['channel_id']; // todo - add auto follow settings, (and strip exif in hubzilla) $location = escape_tags($data['user']['profile']['location']); if (!$location) { $location = ''; } q("update channel set channel_location = '%s' where channel_id = %d", dbesc($location), intval($channel_id)); if ($data['user']['profile']['nsfw']) { // fixme for hubzilla which doesn't use pageflags any more q("update channel set channel_pageflags = (channel_pageflags | %d) where channel_id = %d", intval(PAGE_ADULT), intval($channel_id)); } if ($data['user']['profile']['image_url']) { $p = z_fetch_url($data['user']['profile']['image_url'], true); if ($p['success']) { $rawbytes = $p['body']; $type = guess_image_type('dummyfile', $p['header']); import_channel_photo($rawbytes, $type, $c['channel']['channel_account_id'], $channel_id); } } $gender = escape_tags($data['user']['profile']['gender']); $about = diaspora2bb($data['user']['profile']['bio']); $publish = intval($data['user']['profile']['searchable']); if ($data['user']['profile']['birthday']) { $dob = datetime_convert('UTC', 'UTC', $data['user']['profile']['birthday'], 'Y-m-d'); } else { $dob = '0000-00-00'; } // we're relying on the fact that this channel was just created and will only // have the default profile currently $r = q("update profile set gender = '%s', about = '%s', dob = '%s', publish = %d where uid = %d", dbesc($gender), dbesc($about), dbesc($dob), dbesc($publish), intval($channel_id)); if ($data['user']['aspects']) { foreach ($data['user']['aspects'] as $aspect) { group_add($channel_id, escape_tags($aspect['name']), intval($aspect['contacts_visible'])); } } // now add connections and send friend requests if ($data['user']['contacts']) { foreach ($data['user']['contacts'] as $contact) { $result = new_contact($channel_id, $contact['person_diaspora_handle'], $c['channel']); if ($result['success']) { if ($contact['aspects']) { foreach ($contact['aspects'] as $aspect) { group_add_member($channel_id, $aspect['name'], $result['abook']['xchan_hash']); } } } } } // Then add items - note this can't be done until Diaspora adds guids to exported // items and comments // This will indirectly perform a refresh_all *and* update the directory proc_run('php', 'include/directory.php', $channel_id); notice(t('Import completed.') . EOL); change_channel($channel_id); goaway(z_root() . '/network'); }