]> git.mxchange.org Git - friendica.git/blob - mod/crepair.php
Update ForumManager.php - small correction
[friendica.git] / mod / crepair.php
1 <?php
2 require_once("include/contact_selectors.php");
3 require_once("mod/contacts.php");
4
5 if(! function_exists('crepair_init')) {
6 function crepair_init(&$a) {
7         if(! local_user())
8                 return;
9
10         $contact_id = 0;
11
12         if(($a->argc == 2) && intval($a->argv[1])) {
13                 $contact_id = intval($a->argv[1]);
14                 $r = q("SELECT * FROM `contact` WHERE `uid` = %d and `id` = %d LIMIT 1",
15                         intval(local_user()),
16                         intval($contact_id)
17                 );
18                 if(! count($r)) {
19                         $contact_id = 0;
20                 }
21         }
22
23         if(! x($a->page,'aside'))
24                 $a->page['aside'] = '';
25
26         if($contact_id) {
27                 $a->data['contact'] = $r[0];
28                 $contact = $r[0];
29                 profile_load($a, "", 0, get_contact_details_by_url($contact["url"]));
30         }
31 }
32 }
33
34 if(! function_exists('crepair_post')) {
35 function crepair_post(&$a) {
36         if(! local_user())
37                 return;
38
39         $cid = (($a->argc > 1) ? intval($a->argv[1]) : 0);
40
41         if($cid) {
42                 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
43                         intval($cid),
44                         intval(local_user())
45                 );
46         }
47
48         if(! count($r))
49                 return;
50
51         $contact = $r[0];
52
53         $name    = ((x($_POST,'name')) ? $_POST['name'] : $contact['name']);
54         $nick    = ((x($_POST,'nick')) ? $_POST['nick'] : '');
55         $url     = ((x($_POST,'url')) ? $_POST['url'] : '');
56         $request = ((x($_POST,'request')) ? $_POST['request'] : '');
57         $confirm = ((x($_POST,'confirm')) ? $_POST['confirm'] : '');
58         $notify  = ((x($_POST,'notify')) ? $_POST['notify'] : '');
59         $poll    = ((x($_POST,'poll')) ? $_POST['poll'] : '');
60         $attag   = ((x($_POST,'attag')) ? $_POST['attag'] : '');
61         $photo   = ((x($_POST,'photo')) ? $_POST['photo'] : '');
62         $remote_self = ((x($_POST,'remote_self')) ? $_POST['remote_self'] : false);
63         $nurl    = normalise_link($url);
64
65         $r = q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `url` = '%s', `nurl` = '%s', `request` = '%s', `confirm` = '%s', `notify` = '%s', `poll` = '%s', `attag` = '%s' , `remote_self` = %d
66                 WHERE `id` = %d AND `uid` = %d",
67                 dbesc($name),
68                 dbesc($nick),
69                 dbesc($url),
70                 dbesc($nurl),
71                 dbesc($request),
72                 dbesc($confirm),
73                 dbesc($notify),
74                 dbesc($poll),
75                 dbesc($attag),
76                 intval($remote_self),
77                 intval($contact['id']),
78                 local_user()
79         );
80
81         if($photo) {
82                 logger('mod-crepair: updating photo from ' . $photo);
83                 require_once("include/Photo.php");
84
85                 update_contact_avatar($photo,local_user(),$contact['id']);
86         }
87
88         if($r)
89                 info( t('Contact settings applied.') . EOL);
90         else
91                 notice( t('Contact update failed.') . EOL);
92
93
94         return;
95 }
96 }
97
98 if(! function_exists('crepair_content')) {
99 function crepair_content(&$a) {
100
101         if(! local_user()) {
102                 notice( t('Permission denied.') . EOL);
103                 return;
104         }
105
106         $cid = (($a->argc > 1) ? intval($a->argv[1]) : 0);
107
108         if($cid) {
109                 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
110                         intval($cid),
111                         intval(local_user())
112                 );
113         }
114
115         if(! count($r)) {
116                 notice( t('Contact not found.') . EOL);
117                 return;
118         }
119
120         $contact = $r[0];
121
122         $warning = t('<strong>WARNING: This is highly advanced</strong> and if you enter incorrect information your communications with this contact may stop working.');
123         $info = t('Please use your browser \'Back\' button <strong>now</strong> if you are uncertain what to do on this page.');
124
125         $returnaddr = "contacts/$cid";
126
127         $allow_remote_self = get_config('system','allow_users_remote_self');
128
129         // Disable remote self for everything except feeds.
130         // There is an issue when you repeat an item from maybe twitter and you got comments from friendica and twitter
131         // Problem is, you couldn't reply to both networks.
132         if (!in_array($contact['network'], array(NETWORK_FEED, NETWORK_DFRN, NETWORK_DIASPORA)))
133                 $allow_remote_self = false;
134
135         if ($contact['network'] == NETWORK_FEED)
136                 $remote_self_options = array('0'=>t('No mirroring'), '1'=>t('Mirror as forwarded posting'), '2'=>t('Mirror as my own posting'));
137         else
138                 $remote_self_options = array('0'=>t('No mirroring'), '2'=>t('Mirror as my own posting'));
139
140         $update_profile = in_array($contact['network'], array(NETWORK_DFRN, NETWORK_DSPR, NETWORK_OSTATUS));
141
142         $tab_str = contacts_tab($a, $contact['id'], 5);
143
144
145         $tpl = get_markup_template('crepair.tpl');
146         $o .= replace_macros($tpl, array(
147                 //'$title'      => t('Repair Contact Settings'),
148                 '$tab_str'      => $tab_str,
149                 '$warning'      => $warning,
150                 '$info'         => $info,
151                 '$returnaddr'   => $returnaddr,
152                 '$return'       => t('Return to contact editor'),
153                 '$update_profile' => update_profile,
154                 '$udprofilenow' => t('Refetch contact data'),
155                 '$label_name' => t('Name'),
156                 '$label_nick' => t('Account Nickname'),
157                 '$label_attag' => t('@Tagname - overrides Name/Nickname'),
158                 '$label_url' => t('Account URL'),
159                 '$label_request' => t('Friend Request URL'),
160                 '$label_confirm' => t('Friend Confirm URL'),
161                 '$label_notify' => t('Notification Endpoint URL'),
162                 '$label_poll' => t('Poll/Feed URL'),
163                 '$label_photo' => t('New photo from this URL'),
164                 '$label_remote_self' => t('Remote Self'),
165                 '$allow_remote_self' => $allow_remote_self,
166                 '$remote_self' => array('remote_self',
167                                         t('Mirror postings from this contact'),
168                                         $contact['remote_self'],
169                                         t('Mark this contact as remote_self, this will cause friendica to repost new entries from this contact.'),
170                                         $remote_self_options
171                                 ),
172                 '$contact_name' => htmlentities($contact['name']),
173                 '$contact_nick' => htmlentities($contact['nick']),
174                 '$contact_id'   => $contact['id'],
175                 '$contact_url'  => $contact['url'],
176                 '$request'      => $contact['request'],
177                 '$confirm'      => $contact['confirm'],
178                 '$notify'       => $contact['notify'],
179                 '$poll'         => $contact['poll'],
180                 '$contact_attag'  => $contact['attag'],
181                 '$lbl_submit'   => t('Submit')
182         ));
183
184         return $o;
185 }
186 }