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