]> git.mxchange.org Git - friendica.git/blob - mod/profiles.php
bug in diaspora_reshare
[friendica.git] / mod / profiles.php
1 <?php
2
3
4 function profiles_post(&$a) {
5
6         if(! local_user()) {
7                 notice( t('Permission denied.') . EOL);
8                 return;
9         }
10
11         $namechanged = false;
12
13         call_hooks('profile_post', $_POST);
14
15         if(($a->argc > 1) && ($a->argv[1] !== "new") && intval($a->argv[1])) {
16                 $orig = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
17                         intval($a->argv[1]),
18                         intval(local_user())
19                 );
20                 if(! count($orig)) {
21                         notice( t('Profile not found.') . EOL);
22                         return;
23                 }
24                 $is_default = (($orig[0]['is-default']) ? 1 : 0);
25
26                 $profile_name = notags(trim($_POST['profile_name']));
27                 if(! strlen($profile_name)) {
28                         notify( t('Profile Name is required.') . EOL);
29                         return;
30                 }
31         
32                 $year = intval($_POST['year']);
33                 if($year < 1900 || $year > 2100 || $year < 0)
34                         $year = 0;
35                 $month = intval($_POST['month']);
36                         if(($month > 12) || ($month < 0))
37                                 $month = 0;
38                 $mtab = array(0,31,29,31,30,31,30,31,31,30,31,30,31);
39                 $day = intval($_POST['day']);
40                         if(($day > $mtab[$month]) || ($day < 0))
41                                 $day = 0;
42                 $dob = '0000-00-00';
43                 $dob = sprintf('%04d-%02d-%02d',$year,$month,$day);
44
45                         
46                 $name = notags(trim($_POST['name']));
47
48                 if($orig[0]['name'] != $name)
49                         $namechanged = true;
50
51                 $pdesc = notags(trim($_POST['pdesc']));
52                 $gender = notags(trim($_POST['gender']));
53                 $address = notags(trim($_POST['address']));
54                 $locality = notags(trim($_POST['locality']));
55                 $region = notags(trim($_POST['region']));
56                 $postal_code = notags(trim($_POST['postal_code']));
57                 $country_name = notags(trim($_POST['country_name']));
58                 $pub_keywords = notags(trim($_POST['pub_keywords']));
59                 $prv_keywords = notags(trim($_POST['prv_keywords']));
60                 $marital = notags(trim($_POST['marital']));
61                 if($marital != $orig[0]['marital'])
62                         $maritalchanged = true;
63
64                 $with = ((x($_POST,'with')) ? notags(trim($_POST['with'])) : '');
65
66                 // linkify the relationship target if applicable
67
68                 if(strlen($with)) {
69                         if($with != strip_tags($orig[0]['with'])) {
70                                 $prf = '';
71                                 $lookup = $with;
72                                 if(strpos($lookup,'@') === 0)
73                                         $lookup = substr($lookup,1);
74                                 $lookup = str_replace('_',' ', $lookup);
75                                 if(strpos($lookup,'@') || (strpos($lookup,'http://'))) {
76                                         $newname = $lookup;
77                                         $links = @lrdd($lookup);
78                                         if(count($links)) {
79                                                 foreach($links as $link) {
80                                                         if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
81                                         $prf = $link['@attributes']['href'];
82                                                         }
83                                                 }
84                                         }
85                                 }
86                                 else {
87                                         $newname = $lookup;
88                                         if(strstr($lookup,' ')) {
89                                                 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
90                                                         dbesc($newname),
91                                                         intval(local_user())
92                                                 );
93                                         }
94                                         else {
95                                                 $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
96                                                         dbesc($lookup),
97                                                         intval(local_user())
98                                                 );
99                                         }
100                                         if(count($r)) {
101                                                 $prf = $r[0]['url'];
102                                                 $newname = $r[0]['name'];
103                                         }
104                                 }
105         
106                                 if($prf) {
107                                         $with = str_replace($lookup,'<a href="' . $prf . '">' . $newname        . '</a>', $with);
108                                         if(strpos($with,'@') === 0)
109                                                 $with = substr($with,1);
110                                 }
111                         }
112                         else
113                                 $with = $orig[0]['with'];
114                 }
115
116                 $sexual = notags(trim($_POST['sexual']));
117                 $homepage = notags(trim($_POST['homepage']));
118                 $politic = notags(trim($_POST['politic']));
119                 $religion = notags(trim($_POST['religion']));
120
121                 $about = escape_tags(trim($_POST['about']));
122                 $interest = escape_tags(trim($_POST['interest']));
123                 $contact = escape_tags(trim($_POST['contact']));
124                 $music = escape_tags(trim($_POST['music']));
125                 $book = escape_tags(trim($_POST['book']));
126                 $tv = escape_tags(trim($_POST['tv']));
127                 $film = escape_tags(trim($_POST['film']));
128                 $romance = escape_tags(trim($_POST['romance']));
129                 $work = escape_tags(trim($_POST['work']));
130                 $education = escape_tags(trim($_POST['education']));
131                 $hide_friends = (($_POST['hide-friends'] == 1) ? 1: 0);
132
133                 $r = q("UPDATE `profile` 
134                         SET `profile-name` = '%s',
135                         `name` = '%s',
136                         `pdesc` = '%s',
137                         `gender` = '%s',
138                         `dob` = '%s',
139                         `address` = '%s',
140                         `locality` = '%s',
141                         `region` = '%s',
142                         `postal-code` = '%s',
143                         `country-name` = '%s',
144                         `marital` = '%s',
145                         `with` = '%s',
146                         `sexual` = '%s',
147                         `homepage` = '%s',
148                         `politic` = '%s',
149                         `religion` = '%s',
150                         `pub_keywords` = '%s',
151                         `prv_keywords` = '%s',
152                         `about` = '%s',
153                         `interest` = '%s',
154                         `contact` = '%s',
155                         `music` = '%s',
156                         `book` = '%s',
157                         `tv` = '%s',
158                         `film` = '%s',
159                         `romance` = '%s',
160                         `work` = '%s',
161                         `education` = '%s',
162                         `hide-friends` = %d
163                         WHERE `id` = %d AND `uid` = %d LIMIT 1",
164                         dbesc($profile_name),
165                         dbesc($name),
166                         dbesc($pdesc),
167                         dbesc($gender),
168                         dbesc($dob),
169                         dbesc($address),
170                         dbesc($locality),
171                         dbesc($region),
172                         dbesc($postal_code),
173                         dbesc($country_name),
174                         dbesc($marital),
175                         dbesc($with),
176                         dbesc($sexual),
177                         dbesc($homepage),
178                         dbesc($politic),
179                         dbesc($religion),
180                         dbesc($pub_keywords),
181                         dbesc($prv_keywords),
182                         dbesc($about),
183                         dbesc($interest),
184                         dbesc($contact),
185                         dbesc($music),
186                         dbesc($book),
187                         dbesc($tv),
188                         dbesc($film),
189                         dbesc($romance),
190                         dbesc($work),
191                         dbesc($education),
192                         intval($hide_friends),
193                         intval($a->argv[1]),
194                         intval($_SESSION['uid'])
195                 );
196
197                 if($r)
198                         info( t('Profile updated.') . EOL);
199
200
201                 if($namechanged && $is_default) {
202                         $r = q("UPDATE `contact` SET `name-date` = '%s' WHERE `self` = 1 AND `uid` = %d LIMIT 1",
203                                 dbesc(datetime_convert()),
204                                 intval(local_user())
205                         );
206                 }
207
208                 if($is_default) {
209                         // Update global directory in background
210                         $url = $_SESSION['my_url'];
211                         if($url && strlen(get_config('system','directory_submit_url')))
212                                 proc_run('php',"include/directory.php","$url");
213
214                         require_once('include/profile_update.php');
215                         profile_change();
216                 }
217         }
218 }
219
220
221
222
223 function profiles_content(&$a) {
224
225         $o = '';
226         nav_set_selected('profiles');
227
228         if(! local_user()) {
229                 notice( t('Permission denied.') . EOL);
230                 return;
231         }
232
233         if(($a->argc > 2) && ($a->argv[1] === "drop") && intval($a->argv[2])) {
234                 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is-default` = 0 LIMIT 1",
235                         intval($a->argv[2]),
236                         intval(local_user())
237                 );
238                 if(! count($r)) {
239                         notice( t('Profile not found.') . EOL);
240                         goaway($a->get_baseurl() . '/profiles');
241                         return; // NOTREACHED
242                 }
243
244                 // move every contact using this profile as their default to the user default
245
246                 $r = q("UPDATE `contact` SET `profile-id` = (SELECT `profile`.`id` AS `profile-id` FROM `profile` WHERE `profile`.`is-default` = 1 AND `profile`.`uid` = %d LIMIT 1) WHERE `profile-id` = %d AND `uid` = %d ",
247                         intval(local_user()),
248                         intval($a->argv[2]),
249                         intval(local_user())
250                 );
251                 $r = q("DELETE FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
252                         intval($a->argv[2]),
253                         intval(local_user())
254                 );
255                 if($r)
256                         info( t('Profile deleted.') . EOL);
257
258                 goaway($a->get_baseurl() . '/profiles');
259                 return; // NOTREACHED
260         }
261
262
263
264
265
266         if(($a->argc > 1) && ($a->argv[1] === 'new')) {
267
268                 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
269                         intval(local_user()));
270                 $num_profiles = count($r0);
271
272                 $name = t('Profile-') . ($num_profiles + 1);
273
274                 $r1 = q("SELECT `name`, `photo`, `thumb` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
275                         intval(local_user()));
276                 
277                 $r2 = q("INSERT INTO `profile` (`uid` , `profile-name` , `name`, `photo`, `thumb`)
278                         VALUES ( %d, '%s', '%s', '%s', '%s' )",
279                         intval(local_user()),
280                         dbesc($name),
281                         dbesc($r1[0]['name']),
282                         dbesc($r1[0]['photo']),
283                         dbesc($r1[0]['thumb'])
284                 );
285
286                 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
287                         intval(local_user()),
288                         dbesc($name)
289                 );
290
291                 info( t('New profile created.') . EOL);
292                 if(count($r3) == 1)
293                         goaway($a->get_baseurl() . '/profiles/' . $r3[0]['id']);
294                 goaway($a->get_baseurl() . '/profiles');
295         }                
296
297         if(($a->argc > 2) && ($a->argv[1] === 'clone')) {
298
299                 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
300                         intval(local_user()));
301                 $num_profiles = count($r0);
302
303                 $name = t('Profile-') . ($num_profiles + 1);
304                 $r1 = q("SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d LIMIT 1",
305                         intval(local_user()),
306                         intval($a->argv[2])
307                 );
308                 if(! count($r1)) {
309                         notice( t('Profile unavailable to clone.') . EOL);
310                         return;
311                 }
312                 unset($r1[0]['id']);
313                 $r1[0]['is-default'] = 0;
314                 $r1[0]['publish'] = 0;  
315                 $r1[0]['net-publish'] = 0;      
316                 $r1[0]['profile-name'] = dbesc($name);
317
318                 dbesc_array($r1[0]);
319
320                 $r2 = dbq("INSERT INTO `profile` (`" 
321                         . implode("`, `", array_keys($r1[0])) 
322                         . "`) VALUES ('" 
323                         . implode("', '", array_values($r1[0])) 
324                         . "')" );
325
326                 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
327                         intval(local_user()),
328                         dbesc($name)
329                 );
330                 info( t('New profile created.') . EOL);
331                 if(count($r3) == 1)
332                         goaway($a->get_baseurl() . '/profiles/' . $r3[0]['id']);
333         goaway($a->get_baseurl() . '/profiles');
334         return; // NOTREACHED
335         }                
336
337
338         if(($a->argc > 1) && (intval($a->argv[1]))) {
339                 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
340                         intval($a->argv[1]),
341                         intval(local_user())
342                 );
343                 if(! count($r)) {
344                         notice( t('Profile not found.') . EOL);
345                         return;
346                 }
347
348                 profile_load($a,$a->user['nickname'],$r[0]['id']);
349
350                 require_once('include/profile_selectors.php');
351
352                 $tpl = get_markup_template('profed_head.tpl');
353
354                 $opt_tpl = get_markup_template("profile-hide-friends.tpl");
355                 $hide_friends = replace_macros($opt_tpl,array(
356                         '$desc' => t('Hide your contact/friend list from viewers of this profile?'),
357                         '$yes_str' => t('Yes'),
358                         '$no_str' => t('No'),
359                         '$yes_selected' => (($r[0]['hide-friends']) ? " checked=\"checked\" " : ""),
360                         '$no_selected' => (($r[0]['hide-friends'] == 0) ? " checked=\"checked\" " : "")
361                 ));
362
363
364                 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
365                 $a->page['htmlhead'] .= "<script type=\"text/javascript\" src=\"js/country.js\" ></script>";
366
367                 $f = get_config('system','birthday_input_format');
368                 if(! $f)
369                         $f = 'ymd';
370
371                 $is_default = (($r[0]['is-default']) ? 1 : 0);
372                 $tpl = get_markup_template("profile_edit.tpl");
373                 $o .= replace_macros($tpl,array(
374                         '$banner' => t('Edit Profile Details'),
375                         '$submit' => t('Submit'),
376                         '$viewprof' => t('View this profile'),
377                         '$cr_prof' => t('Create a new profile using these settings'),
378                         '$cl_prof' => t('Clone this profile'),
379                         '$del_prof' => t('Delete this profile'),
380                         '$lbl_profname' => t('Profile Name:'),
381                         '$lbl_fullname' => t('Your Full Name:'),
382                         '$lbl_title' => t('Title/Description:'),
383                         '$lbl_gender' => t('Your Gender:'),
384                         '$lbl_bd' => sprintf( t("Birthday \x28%s\x29:"),datesel_format($f)),
385                         '$lbl_address' => t('Street Address:'),
386                         '$lbl_city' => t('Locality/City:'),
387                         '$lbl_zip' => t('Postal/Zip Code:'),
388                         '$lbl_country' => t('Country:'),
389                         '$lbl_region' => t('Region/State:'),
390                         '$lbl_marital' => t('<span class="heart">&hearts;</span> Marital Status:'),
391                         '$lbl_with' => t("Who: \x28if applicable\x29"),
392                         '$lbl_ex1' => t('Examples: cathy123, Cathy Williams, cathy@example.com'),
393                         '$lbl_sexual' => t('Sexual Preference:'),
394                         '$lbl_homepage' => t('Homepage URL:'),
395                         '$lbl_politic' => t('Political Views:'),
396                         '$lbl_religion' => t('Religious Views:'),
397                         '$lbl_pubkey' => t('Public Keywords:'),
398                         '$lbl_prvkey' => t('Private Keywords:'),
399                         '$lbl_ex2' => t('Example: fishing photography software'),
400                         '$lbl_pubdsc' => t("\x28Used for suggesting potential friends, can be seen by others\x29"),
401                         '$lbl_prvdsc' => t("\x28Used for searching profiles, never shown to others\x29"),
402                         '$lbl_about' => t('Tell us about yourself...'),
403                         '$lbl_hobbies' => t('Hobbies/Interests'),
404                         '$lbl_social' => t('Contact information and Social Networks'),
405                         '$lbl_music' => t('Musical interests'),
406                         '$lbl_book' => t('Books, literature'),
407                         '$lbl_tv' => t('Television'),
408                         '$lbl_film' => t('Film/dance/culture/entertainment'),
409                         '$lbl_love' => t('Love/romance'),
410                         '$lbl_work' => t('Work/employment'),
411                         '$lbl_school' => t('School/education'),
412                         '$disabled' => (($is_default) ? 'onclick="return false;" style="color: #BBBBFF;"' : ''),
413                         '$baseurl' => $a->get_baseurl(),
414                         '$profile_id' => $r[0]['id'],
415                         '$profile_name' => $r[0]['profile-name'],
416                         '$default' => (($is_default) ? '<p id="profile-edit-default-desc">' . t('This is your <strong>public</strong> profile.<br />It <strong>may</strong> be visible to anybody using the internet.') . '</p>' : ""),
417                         '$name' => $r[0]['name'],
418                         '$pdesc' => $r[0]['pdesc'],
419                         '$dob' => dob($r[0]['dob']),
420                         '$hide_friends' => $hide_friends,
421                         '$address' => $r[0]['address'],
422                         '$locality' => $r[0]['locality'],
423                         '$region' => $r[0]['region'],
424                         '$postal_code' => $r[0]['postal-code'],
425                         '$country_name' => $r[0]['country-name'],
426                         '$age' => ((intval($r[0]['dob'])) ? '(' . t('Age: ') . age($r[0]['dob'],$a->user['timezone'],$a->user['timezone']) . ')' : ''),
427                         '$gender' => gender_selector($r[0]['gender']),
428                         '$marital' => marital_selector($r[0]['marital']),
429                         '$with' => strip_tags($r[0]['with']),
430                         '$sexual' => sexpref_selector($r[0]['sexual']),
431                         '$about' => $r[0]['about'],
432                         '$homepage' => $r[0]['homepage'],
433                         '$politic' => $r[0]['politic'],
434                         '$religion' => $r[0]['religion'],
435                         '$pub_keywords' => $r[0]['pub_keywords'],
436                         '$prv_keywords' => $r[0]['prv_keywords'],
437                         '$music' => $r[0]['music'],
438                         '$book' => $r[0]['book'],
439                         '$tv' => $r[0]['tv'],
440                         '$film' => $r[0]['film'],
441                         '$interest' => $r[0]['interest'],
442                         '$romance' => $r[0]['romance'],
443                         '$work' => $r[0]['work'],
444                         '$education' => $r[0]['education'],
445                         '$contact' => $r[0]['contact']
446                 ));
447
448                 $arr = array('profile' => $r[0], 'entry' => $o);
449                 call_hooks('profile_edit', $arr);
450
451                 return $o;
452         }
453         else {
454
455                 $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
456                         local_user());
457                 if(count($r)) {
458
459                         $tpl_header = get_markup_template('profile_listing_header.tpl');
460                         $o .= replace_macros($tpl_header,array(
461                                 '$header' => t('Profiles'),
462                                 '$chg_photo' => t('Change profile photo'),
463                                 '$cr_new' => t('Create New Profile')
464                         ));
465
466
467                         $tpl = get_markup_template('profile_entry.tpl');
468
469                         foreach($r as $rr) {
470                                 $o .= replace_macros($tpl, array(
471                                         '$photo' => $rr['thumb'],
472                                         '$id' => $rr['id'],
473                                         '$alt' => t('Profile Image'),
474                                         '$profile_name' => $rr['profile-name'],
475                                         '$visible' => (($rr['is-default']) ? '<strong>' . t('visible to everybody') . '</strong>' 
476                                                 : '<a href="' . $a->get_baseurl() . '/profperm/' . $rr['id'] . '" />' . t('Edit visibility') . '</a>')
477                                 ));
478                         }
479                 }
480                 return $o;
481         }
482
483 }