]> git.mxchange.org Git - friendica-addons.git/blob - uhremotestorage/uhremotestorage.php
85d6b13e8c34186c60a8775686d65eb4a6715af1
[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  */
8  
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');
13
14         logger("installed uhremotestorage");
15 }
16
17
18 function uhremotestorage_uninstall() {
19
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');
23
24         logger("removed uhremotestorage");
25 }
26
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));
31         $uid = $r[0]['uid'];
32         
33         $url = get_pconfig($uid,'uhremotestorage','unhoestedurl');
34         $auth = get_pconfig($uid,'uhremotestorage','unhoestedauth');
35         $api = get_pconfig($uid,'uhremotestorage','unhoestedapi');
36         
37         if ($url){
38                 $b['xml'] = str_replace(
39                         '</XRD>', 
40                         "\t".'<Link rel="remoteStorage" template="'.$url.'" api="'.$api.'" auth="'.$auth.'" ></Link>'."\n</XRD>",
41                         $b['xml']
42                 );
43         }
44 }
45
46 function uhremotestorage_settings_post($a, $post){
47         if(! local_user())
48                 return;
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']);
52 }
53
54 function uhremotestorage_settings($a, &$s){
55         if(! local_user())
56                 return;
57         
58         $uid = $a->user['nickname'] ."@". $a->get_hostname();
59         
60         $url = get_pconfig(local_user(),'uhremotestorage','unhoestedurl');
61         $auth = get_pconfig(local_user(),'uhremotestorage','unhoestedauth');
62         $api = get_pconfig(local_user(),'uhremotestorage','unhoestedapi');
63         
64         
65         $arr_api = array(
66                 'WebDAV' => "WebDAV",
67                 'simple' => "simple WebDAV",
68                 'CouchDB' => "CouchDB",
69         );
70         /* experimental apis */
71         /*
72         $api = array_merge($api, array(
73                 'git' => "git",
74                 'tahoe-lafs' => 'tahoe-lafs',
75                 'camlistore' => 'camlistore',
76                 'AmazonS3' => 'AmazonS3',
77                 'GoogleDocs' => 'GoogleDocs',
78                 'Dropbox' => 'Dropbox',
79         );
80         */
81         $tpl = get_markup_template("settings.tpl", "addon/uhremotestorage/");
82         $s .= replace_macros($tpl, array(
83                 '$title' => 'Unhosted remote storage',
84                 '$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 ),
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),
88                 
89                 '$submit' => t('Submit'),
90         ));
91         
92 }