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