]> git.mxchange.org Git - friendica.git/blob - include/profile_update.php
Poco fields now moved to the header, function to create formatted location string
[friendica.git] / include / profile_update.php
1 <?php
2
3 require_once('include/datetime.php');
4 require_once('include/diaspora.php');
5 require_once('include/queue_fn.php');
6 require_once('include/Contact.php');
7
8 function profile_change() {
9
10         $a = get_app();
11
12         if(! local_user())
13                 return;
14
15 //   $url = $a->get_baseurl() . '/profile/' . $a->user['nickname'];
16 //   if($url && strlen(get_config('system','directory')))
17 //      proc_run('php',"include/directory.php","$url");
18
19         $recips = q("SELECT `id`,`name`,`network`,`pubkey`,`notify` FROM `contact` WHERE `network` = '%s'
20                 AND `uid` = %d AND `rel` != %d ",
21                 dbesc(NETWORK_DIASPORA),
22                 intval(local_user()),
23                 intval(CONTACT_IS_SHARING)
24         );
25         if(! count($recips))
26                 return;
27
28         $r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `user`.* FROM `profile`
29                 INNER JOIN `user` ON `profile`.`uid` = `user`.`uid`
30                 WHERE `user`.`uid` = %d AND `profile`.`is-default` = 1 LIMIT 1",
31                 intval(local_user())
32         );
33
34         if(! count($r))
35                 return;
36         $profile = $r[0];
37
38         $handle = xmlify($a->user['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3));
39         $first = xmlify(((strpos($profile['name'],' '))
40                 ? trim(substr($profile['name'],0,strpos($profile['name'],' '))) : $profile['name']));
41         $last = xmlify((($first === $profile['name']) ? '' : trim(substr($profile['name'],strlen($first)))));
42         $large = xmlify($a->get_baseurl() . '/photo/custom/300/' . $profile['uid'] . '.jpg');
43         $medium = xmlify($a->get_baseurl() . '/photo/custom/100/' . $profile['uid'] . '.jpg');
44         $small = xmlify($a->get_baseurl() . '/photo/custom/50/'  . $profile['uid'] . '.jpg');
45         $searchable = xmlify((($profile['publish'] && $profile['net-publish']) ? 'true' : 'false' ));
46 //      $searchable = 'true';
47
48         if($searchable === 'true') {
49                 $dob = '1000-00-00';
50
51                 if(($profile['dob']) && ($profile['dob'] != '0000-00-00'))
52                         $dob = ((intval($profile['dob'])) ? intval($profile['dob']) : '1000') . '-' . datetime_convert('UTC','UTC',$profile['dob'],'m-d');
53                 $gender = xmlify($profile['gender']);
54                 $about = xmlify($profile['about']);
55                 require_once('include/bbcode.php');
56                 $about = xmlify(strip_tags(bbcode($about)));
57                 $location = formatted_location($profile);
58                 $location = xmlify($location);
59                 $tags = '';
60                 if($profile['pub_keywords']) {
61                         $kw = str_replace(',',' ',$profile['pub_keywords']);
62                         $kw = str_replace('  ',' ',$kw);
63                         $arr = explode(' ',$profile['pub_keywords']);
64                         if(count($arr)) {
65                                 for($x = 0; $x < 5; $x ++) {
66                                         if(trim($arr[$x]))
67                                                 $tags .= '#' . trim($arr[$x]) . ' ';
68                                 }
69                         }
70                 }
71                 $tags = xmlify(trim($tags));
72         }
73
74         $tpl = get_markup_template('diaspora_profile.tpl');
75
76         $msg = replace_macros($tpl,array(
77                 '$handle' => $handle,
78                 '$first' => $first,
79                 '$last' => $last,
80                 '$large' => $large,
81                 '$medium' => $medium,
82                 '$small' => $small,
83                 '$dob' => $dob,
84                 '$gender' => $gender,
85                 '$about' => $about,
86                 '$location' => $location,
87                 '$searchable' => $searchable,
88                 '$tags' => $tags
89         ));
90         logger('profile_change: ' . $msg, LOGGER_ALL);
91
92         foreach($recips as $recip) {
93                 $msgtosend = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$a->user,$recip,$a->user['prvkey'],$recip['pubkey'],false)));
94                 add_to_queue($recip['id'],NETWORK_DIASPORA,$msgtosend,false);
95         }
96 }