]> git.mxchange.org Git - friendica-addons.git/blob - uhremotestorage/uhremotestorage.php
Additional work for PR 3778
[friendica-addons.git] / uhremotestorage / uhremotestorage.php
1 <?php
2 /**
3  * Name: unhosted remote storage
4  * Description: Expose in user XRD the link to external user's unhosted-enabled storage
5  * Version: 1.0
6  * Author: Fabio Comuni <http://kirgroup.com/profile/fabrixxm>
7  * Status: Unsupported
8  */
9  
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');
14
15         logger("installed uhremotestorage");
16 }
17
18
19 function uhremotestorage_uninstall() {
20
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');
24
25         logger("removed uhremotestorage");
26 }
27
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));
32         $uid = $r[0]['uid'];
33         
34         $url = get_pconfig($uid,'uhremotestorage','unhoestedurl');
35         $auth = get_pconfig($uid,'uhremotestorage','unhoestedauth');
36         $api = get_pconfig($uid,'uhremotestorage','unhoestedapi');
37         
38         if ($url){
39                 $b['xml'] = str_replace(
40                         '</XRD>', 
41                         "\t".'<Link rel="remoteStorage" template="'.$url.'" api="'.$api.'" auth="'.$auth.'" ></Link>'."\n</XRD>",
42                         $b['xml']
43                 );
44         }
45 }
46
47 function uhremotestorage_settings_post($a, $post){
48         if(! local_user())
49                 return;
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']);
53 }
54
55 function uhremotestorage_settings($a, &$s){
56         if(! local_user())
57                 return;
58         
59         $uid = $a->user['nickname'] ."@". $a->get_hostname();
60         
61         $url = get_pconfig(local_user(),'uhremotestorage','unhoestedurl');
62         $auth = get_pconfig(local_user(),'uhremotestorage','unhoestedauth');
63         $api = get_pconfig(local_user(),'uhremotestorage','unhoestedapi');
64         
65         
66         $arr_api = array(
67                 'WebDAV' => "WebDAV",
68                 'simple' => "simple WebDAV",
69                 'CouchDB' => "CouchDB",
70         );
71         /* experimental apis */
72         /*
73         $api = array_merge($api, array(
74                 'git' => "git",
75                 'tahoe-lafs' => 'tahoe-lafs',
76                 'camlistore' => 'camlistore',
77                 'AmazonS3' => 'AmazonS3',
78                 'GoogleDocs' => 'GoogleDocs',
79                 'Dropbox' => 'Dropbox',
80         );
81         */
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),
89                 
90                 '$submit' => t('Save Settings'),
91         ));
92         
93 }