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>
9 function uhremotestorage_install() {
10 register_hook('personal_xrd', 'addon/uhremotestorage/uhremotestorage.php', 'uhremotestorage_personal_xrd');
11 register_hook('plugin_settings', 'addon/uhremotestorage/uhremotestorage.php', 'uhremotestorage_settings');
12 register_hook('plugin_settings_post', 'addon/uhremotestorage/uhremotestorage.php', 'uhremotestorage_settings_post');
14 logger("installed uhremotestorage");
18 function uhremotestorage_uninstall() {
20 unregister_hook('personal_xrd', 'addon/uhremotestorage/uhremotestorage.php', 'uhremotestorage_personal_xrd');
21 unregister_hook('plugin_settings', 'addon/uhremotestorage/uhremotestorage.php', 'uhremotestorage_settings');
22 unregister_hook('plugin_settings_post', 'addon/uhremotestorage/uhremotestorage.php', 'uhremotestorage_settings_post');
24 logger("removed uhremotestorage");
27 function uhremotestorage_personal_xrd($a, &$b){
28 list($user, $host) = explode("@",$_GET['uri']);
29 $user = str_replace("acct:","",$user);
30 $r = q("SELECT uid FROM user WHERE nickname='%s'", dbesc($user));
33 $url = get_pconfig($uid,'uhremotestorage','unhoestedurl');
34 $auth = get_pconfig($uid,'uhremotestorage','unhoestedauth');
35 $api = get_pconfig($uid,'uhremotestorage','unhoestedapi');
38 $b['xml'] = str_replace(
40 "\t".'<Link rel="remoteStorage" template="'.$url.'" api="'.$api.'" auth="'.$auth.'" ></Link>'."\n</XRD>",
46 function uhremotestorage_settings_post($a, $post){
49 set_pconfig(local_user(),'uhremotestorage','unhoestedurl',$_POST['unhoestedurl']);
50 set_pconfig(local_user(),'uhremotestorage','unhoestedauth',$_POST['unhoestedauth']);
51 set_pconfig(local_user(),'uhremotestorage','unhoestedapi',$_POST['unhoestedapi']);
54 function uhremotestorage_settings($a, &$s){
58 $uid = $a->user['nickname'] ."@". $a->get_hostname();
60 $url = get_pconfig(local_user(),'uhremotestorage','unhoestedurl');
61 $auth = get_pconfig(local_user(),'uhremotestorage','unhoestedauth');
62 $api = get_pconfig(local_user(),'uhremotestorage','unhoestedapi');
67 'simple' => "simple WebDAV",
68 'CouchDB' => "CouchDB",
70 /* experimental apis */
72 $api = array_merge($api, array(
74 'tahoe-lafs' => 'tahoe-lafs',
75 'camlistore' => 'camlistore',
76 'AmazonS3' => 'AmazonS3',
77 'GoogleDocs' => 'GoogleDocs',
78 'Dropbox' => 'Dropbox',
81 $tpl = file_get_contents(dirname(__file__)."/settings.tpl");
82 $s .= replace_macros($tpl, array(
83 '$title' => 'Unhosted remote storage',
84 '$desc' => sprintf( t('Allow to use your friendika 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 ),
85 '$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>'),
86 '$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>'),
87 '$api' => array( 'unhoestedapi', t('Api'), $api, 'If your are using ownCloud, your api will be <tt>WebDAV</tt>', $arr_api),
89 '$submit' => t('Submit'),