function uexport_init(&$a) { if (!local_user()) { killme(); } require_once "mod/settings.php"; settings_init($a); /* $tabs = array( array( 'label' => t('Account settings'), 'url' => $a->get_baseurl(true).'/settings', 'selected' => '', ), array( 'label' => t('Display settings'), 'url' => $a->get_baseurl(true).'/settings/display', 'selected' =>'', ), array( 'label' => t('Connector settings'), 'url' => $a->get_baseurl(true).'/settings/connectors', 'selected' => '', ), array( 'label' => t('Plugin settings'), 'url' => $a->get_baseurl(true).'/settings/addon', 'selected' => '', ), array( 'label' => t('Connected apps'), 'url' => $a->get_baseurl(true) . '/settings/oauth', 'selected' => '', ), array( 'label' => t('Export personal data'), 'url' => $a->get_baseurl(true) . '/uexport', 'selected' => 'active' ), array( 'label' => t('Remove account'), 'url' => $a->get_baseurl(true) . '/removeme', 'selected' => '' ) ); $tabtpl = get_markup_template("generic_links_widget.tpl"); $a->page['aside'] = replace_macros($tabtpl, array( '$title' => t('Settings'), '$class' => 'settings-widget', '$items' => $tabs, )); */ }
function removeme_content(&$a) { if (!local_user()) { goaway(z_root()); } $hash = random_string(); require_once "mod/settings.php"; settings_init($a); $_SESSION['remove_account_verify'] = $hash; $tpl = get_markup_template('removeme.tpl'); $o .= replace_macros($tpl, array('$basedir' => $a->get_baseurl(), '$hash' => $hash, '$title' => t('Remove My Account'), '$desc' => t('This will completely remove your account. Once this has been done it is not recoverable.'), '$passwd' => t('Please enter your password for verification:'), '$submit' => t('Remove My Account'))); return $o; }
function pumpio_content(&$a) { if (!local_user()) { notice(t('Permission denied.') . EOL); return ''; } require_once "mod/settings.php"; settings_init($a); if (isset($a->argv[1])) { switch ($a->argv[1]) { case "connect": $o = pumpio_connect($a); break; default: $o = print_r($a->argv, true); break; } } else { $o = pumpio_connect($a); } return $o; }
function delegate_content(&$a) { if (!local_user()) { notice(t('Permission denied.') . EOL); return; } if ($a->argc > 2 && $a->argv[1] === 'add' && intval($a->argv[2])) { // delegated admins can view but not change delegation permissions if (x($_SESSION, 'submanage') && intval($_SESSION['submanage'])) { goaway($a->get_baseurl() . '/delegate'); } $id = $a->argv[2]; $r = q("select `nickname` from user where uid = %d limit 1", intval($id)); if (count($r)) { $r = q("select id from contact where uid = %d and nurl = '%s' limit 1", intval(local_user()), dbesc(normalise_link($a->get_baseurl() . '/profile/' . $r[0]['nickname']))); if (count($r)) { q("insert into manage ( uid, mid ) values ( %d , %d ) ", intval($a->argv[2]), intval(local_user())); } } goaway($a->get_baseurl() . '/delegate'); } if ($a->argc > 2 && $a->argv[1] === 'remove' && intval($a->argv[2])) { // delegated admins can view but not change delegation permissions if (x($_SESSION, 'submanage') && intval($_SESSION['submanage'])) { goaway($a->get_baseurl() . '/delegate'); } q("delete from manage where uid = %d and mid = %d limit 1", intval($a->argv[2]), intval(local_user())); goaway($a->get_baseurl() . '/delegate'); } $full_managers = array(); // These people can manage this account/page with full privilege $r = q("SELECT * FROM `user` WHERE `email` = '%s' AND `password` = '%s' ", dbesc($a->user['email']), dbesc($a->user['password'])); if (count($r)) { $full_managers = $r; } $delegates = array(); // find everybody that currently has delegated management to this account/page $r = q("select * from user where uid in ( select uid from manage where mid = %d ) ", intval(local_user())); if (count($r)) { $delegates = $r; } $uids = array(); if (count($full_managers)) { foreach ($full_managers as $rr) { $uids[] = $rr['uid']; } } if (count($delegates)) { foreach ($delegates as $rr) { $uids[] = $rr['uid']; } } // find every contact who might be a candidate for delegation $r = q("select nurl from contact where substring_index(contact.nurl,'/',3) = '%s' \n\t\tand contact.uid = %d and contact.self = 0 and network = '%s' ", dbesc(normalise_link($a->get_baseurl())), intval(local_user()), dbesc(NETWORK_DFRN)); if (!count($r)) { notice(t('No potential page delegates located.') . EOL); return; } $nicknames = array(); if (count($r)) { foreach ($r as $rr) { $nicknames[] = "'" . dbesc(basename($rr['nurl'])) . "'"; } } $potentials = array(); $nicks = implode(',', $nicknames); // get user records for all potential page delegates who are not already delegates or managers $r = q("select `uid`, `username`, `nickname` from user where nickname in ( {$nicks} )"); if (count($r)) { foreach ($r as $rr) { if (!in_array($rr['uid'], $uids)) { $potentials[] = $rr; } } } require_once "mod/settings.php"; settings_init($a); $o = replace_macros(get_markup_template('delegate.tpl'), array('$header' => t('Delegate Page Management'), '$base' => $a->get_baseurl(), '$desc' => t('Delegates are able to manage all aspects of this account/page except for basic account settings. Please do not delegate your personal account to anybody that you do not trust completely.'), '$head_managers' => t('Existing Page Managers'), '$managers' => $full_managers, '$head_delegates' => t('Existing Page Delegates'), '$delegates' => $delegates, '$head_potentials' => t('Potential Delegates'), '$potentials' => $potentials, '$remove' => t('Remove'), '$add' => t('Add'), '$none' => t('No entries.'))); return $o; }
/** * @param App $a * @return string */ function fbpost_content(&$a) { if (!local_user()) { notice(t('Permission denied.') . EOL); return ''; } if (!service_class_allows(local_user(), 'facebook_connect')) { notice(t('Permission denied.') . EOL); return upgrade_bool_message(); } if ($a->argc > 1 && $a->argv[1] === 'remove') { del_pconfig(local_user(), 'facebook', 'post'); info(t('Facebook Post disabled') . EOL); } require_once "mod/settings.php"; settings_init($a); $o = ''; $accounts = array(); $fb_installed = false; if (get_pconfig(local_user(), 'facebook', 'post')) { $access_token = get_pconfig(local_user(), 'facebook', 'access_token'); if ($access_token) { // fetching the list of accounts to check, if facebook is working // The value is needed several lines below. $url = 'https://graph.facebook.com/me/accounts'; $s = fetch_url($url . "?access_token=" . $access_token, false, $redirects, 10); if ($s) { $accounts = json_decode($s); if (isset($accounts->data)) { $fb_installed = true; } } // I'm not totally sure, if this above will work in every situation, // So this old code will be called as well. if (!$fb_installed) { $url = "https://graph.facebook.com/me/feed"; $s = fetch_url($url . "?access_token=" . $access_token . "&limit=1", false, $redirects, 10); if ($s) { $j = json_decode($s); if (isset($j->data)) { $fb_installed = true; } } } } } $appid = get_config('facebook', 'appid'); if (!$appid) { notice(t('Facebook API key is missing.') . EOL); return ''; } $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/fbpost/fbpost.css' . '" media="all" />' . "\r\n"; $result = q("SELECT `installed` FROM `addon` WHERE `name` = 'fbsync' AND `installed`"); $fbsync = count($result) > 0; if ($fbsync) { $title = t('Facebook Import/Export/Mirror'); } else { $title = t('Facebook Export/Mirror'); } $o .= '<img class="connector" src="images/facebook.png" /><h3 class="connector">' . $title . '</h3>'; if (!$fb_installed) { $o .= '<div id="fbpost-enable-wrapper">'; //read_stream,publish_stream,manage_pages,photo_upload,user_groups,offline_access //export_stream,read_stream,publish_stream,manage_pages,photo_upload,user_groups,publish_actions,user_friends,share_item,video_upload,status_update $o .= '<a href="https://www.facebook.com/dialog/oauth?client_id=' . $appid . '&redirect_uri=' . $a->get_baseurl() . '/fbpost/' . $a->user['nickname'] . '&scope=publish_actions,publish_pages,user_posts,user_photos,user_status,user_videos,manage_pages,user_managed_groups">' . t('Install Facebook Post connector for this account.') . '</a>'; $o .= '</div>'; } if ($fb_installed) { $o .= '<div id="fbpost-disable-wrapper">'; $o .= '<a href="' . $a->get_baseurl() . '/fbpost/remove' . '">' . t('Remove Facebook Post connector') . '</a></div>'; $o .= '<div id="fbpost-enable-wrapper">'; //export_stream,read_stream,publish_stream,manage_pages,photo_upload,user_groups,publish_actions,user_friends,share_item,video_upload,status_update $o .= '<a href="https://www.facebook.com/dialog/oauth?client_id=' . $appid . '&redirect_uri=' . $a->get_baseurl() . '/fbpost/' . $a->user['nickname'] . '&scope=publish_actions,publish_pages,user_posts,user_photos,user_status,user_videos,manage_pages,user_managed_groups">' . t('Re-authenticate [This is necessary whenever your Facebook password is changed.]') . '</a>'; $o .= '</div>'; $o .= '<div id="fbpost-post-default-form">'; $o .= '<form action="fbpost" method="post" >'; $post_by_default = get_pconfig(local_user(), 'facebook', 'post_by_default'); $checked = $post_by_default ? ' checked="checked" ' : ''; $o .= '<input type="checkbox" name="post_by_default" value="1"' . $checked . '/>' . ' ' . t('Post to Facebook by default') . EOL; $suppress_view_on_friendica = get_pconfig(local_user(), 'facebook', 'suppress_view_on_friendica'); $checked = $suppress_view_on_friendica ? ' checked="checked" ' : ''; $o .= '<input type="checkbox" name="suppress_view_on_friendica" value="1"' . $checked . '/>' . ' ' . t('Suppress "View on friendica"') . EOL; $mirror_posts = get_pconfig(local_user(), 'facebook', 'mirror_posts'); $checked = $mirror_posts ? ' checked="checked" ' : ''; $o .= '<input type="checkbox" name="mirror_posts" value="1"' . $checked . '/>' . ' ' . t('Mirror wall posts from facebook to friendica.') . EOL; // List all pages $post_to_page = get_pconfig(local_user(), 'facebook', 'post_to_page'); $page_access_token = get_pconfig(local_user(), 'facebook', 'page_access_token'); $fb_token = get_pconfig($a->user['uid'], 'facebook', 'access_token'); //$url = 'https://graph.facebook.com/me/accounts'; //$x = fetch_url($url."?access_token=".$fb_token, false, $redirects, 10); //$accounts = json_decode($x); $o .= t("Post to page/group:") . "<select name='post_to_page'>"; if (intval($post_to_page) == 0) { $o .= "<option value='0-0' selected>" . t('None') . "</option>"; } else { $o .= "<option value='0-0'>" . t('None') . "</option>"; } foreach ($accounts->data as $account) { if (is_array($account->perms)) { if ($post_to_page == $account->id) { $o .= "<option value='" . $account->id . "-" . $account->access_token . "' selected>" . $account->name . "</option>"; } else { $o .= "<option value='" . $account->id . "-" . $account->access_token . "'>" . $account->name . "</option>"; } } } $url = 'https://graph.facebook.com/me/groups'; $x = fetch_url($url . "?access_token=" . $fb_token, false, $redirects, 10); $groups = json_decode($x); foreach ($groups->data as $group) { if ($post_to_page == $group->id) { $o .= "<option value='" . $group->id . "-0' selected>" . $group->name . "</option>"; } else { $o .= "<option value='" . $group->id . "-0'>" . $group->name . "</option>"; } } $o .= "</select>"; if ($fbsync) { $o .= '<div class="clear"></div>'; $sync_enabled = get_pconfig(local_user(), 'fbsync', 'sync'); $checked = $sync_enabled ? ' checked="checked" ' : ''; $o .= '<input type="checkbox" name="fbsync" value="1"' . $checked . '/>' . ' ' . t('Import Facebook newsfeed.') . EOL; $create_user = get_pconfig(local_user(), 'fbsync', 'create_user'); $checked = $create_user ? ' checked="checked" ' : ''; $o .= '<input type="checkbox" name="create_user" value="1"' . $checked . '/>' . ' ' . t('Automatically create contacts.') . EOL; } $o .= '<p><input type="submit" name="submit" value="' . t('Save Settings') . '" /></form></div>'; } return $o; }