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