3 * Name: unhosted remote storage
4 * Description: Expose in user XRD the link to external user's unhosted-enabled storage
6 * Author: Fabio Comuni <http://kirgroup.com/profile/fabrixxm>
10 function uhremotestorage_install() {
11 register_hook('personal_xrd', 'addon/uhremotestorage/uhremotestorage.php', 'uhremotestorage_personal_xrd');
12 register_hook('plugin_settings', 'addon/uhremotestorage/uhremotestorage.php', 'uhremotestorage_settings');
13 register_hook('plugin_settings_post', 'addon/uhremotestorage/uhremotestorage.php', 'uhremotestorage_settings_post');
15 logger("installed uhremotestorage");
19 function uhremotestorage_uninstall() {
21 unregister_hook('personal_xrd', 'addon/uhremotestorage/uhremotestorage.php', 'uhremotestorage_personal_xrd');
22 unregister_hook('plugin_settings', 'addon/uhremotestorage/uhremotestorage.php', 'uhremotestorage_settings');
23 unregister_hook('plugin_settings_post', 'addon/uhremotestorage/uhremotestorage.php', 'uhremotestorage_settings_post');
25 logger("removed uhremotestorage");
28 function uhremotestorage_personal_xrd($a, &$b){
29 list($user, $host) = explode("@",$_GET['uri']);
30 $user = str_replace("acct:","",$user);
31 $r = q("SELECT uid FROM user WHERE nickname='%s'", dbesc($user));
34 $url = get_pconfig($uid,'uhremotestorage','unhoestedurl');
35 $auth = get_pconfig($uid,'uhremotestorage','unhoestedauth');
36 $api = get_pconfig($uid,'uhremotestorage','unhoestedapi');
39 $b['xml'] = str_replace(
41 "\t".'<Link rel="remoteStorage" template="'.$url.'" api="'.$api.'" auth="'.$auth.'" ></Link>'."\n</XRD>",
47 function uhremotestorage_settings_post($a, $post){
50 set_pconfig(local_user(),'uhremotestorage','unhoestedurl',$_POST['unhoestedurl']);
51 set_pconfig(local_user(),'uhremotestorage','unhoestedauth',$_POST['unhoestedauth']);
52 set_pconfig(local_user(),'uhremotestorage','unhoestedapi',$_POST['unhoestedapi']);
55 function uhremotestorage_settings($a, &$s){
59 $uid = $a->user['nickname'] ."@". $a->get_hostname();
61 $url = get_pconfig(local_user(),'uhremotestorage','unhoestedurl');
62 $auth = get_pconfig(local_user(),'uhremotestorage','unhoestedauth');
63 $api = get_pconfig(local_user(),'uhremotestorage','unhoestedapi');
68 'simple' => "simple WebDAV",
69 'CouchDB' => "CouchDB",
71 /* experimental apis */
73 $api = array_merge($api, array(
75 'tahoe-lafs' => 'tahoe-lafs',
76 'camlistore' => 'camlistore',
77 'AmazonS3' => 'AmazonS3',
78 'GoogleDocs' => 'GoogleDocs',
79 'Dropbox' => 'Dropbox',
82 $tpl = get_markup_template("settings.tpl", "addon/uhremotestorage/");
83 $s .= replace_macros($tpl, array(
84 '$title' => 'Unhosted remote storage',
85 '$desc' => sprintf( t('Allow to use your friendica id (%s) to connecto to external unhosted-enabled storage (like ownCloud). See <a href="http://www.w3.org/community/unhosted/wiki/RemoteStorage#WebFinger">RemoteStorage WebFinger</a>'), $uid ),
86 '$url' => array( 'unhoestedurl', t('Template URL (with {category})'), $url, 'If your are using ownCloud, your unhosted url will be like <tt>http://<i>HOST</i>/apps/remoteStorage/WebDAV.php/<i>USER</i>/remoteStorage/{category}</tt>'),
87 '$auth' => array( 'unhoestedauth', t('OAuth end-point'), $auth, 'If your are using ownCloud, your OAuth endpoint will be like <tt>http://<i>HOST</i>/apps/remoteStorage/auth.php/<i>USER</i></tt>'),
88 '$api' => array( 'unhoestedapi', t('Api'), $api, 'If your are using ownCloud, your api will be <tt>WebDAV</tt>', $arr_api),
90 '$submit' => t('Save Settings'),