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