]> git.mxchange.org Git - friendica.git/blob - include/profile_update.php
Merge pull request #34 from fabrixxm/master
[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_submit_url')))
16   //      proc_run('php',"include/directory.php","$url");
17
18         $recips = q("SELECT DISTINCT(`batch`), `id`, `name`,`network` FROM `contact` WHERE `network` = '%s'
19                 AND `uid` = %d AND `rel` != %d ORDER BY rand() ",
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                 LEFT 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 = $a->user['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);
38         $first = ((strpos($profile['name'],' '))
39                 ? trim(substr($profile['name'],0,strpos($profile['name'],' '))) : $profile['name']);
40         $last = (($first === $profile['name']) ? '' : trim(substr($profile['name'],strlen($first))));
41         $large = $a->get_baseurl() . '/photo/custom/300/' . $profile['uid'] . '.jpg';
42         $medium = $a->get_baseurl() . '/photo/custom/100/' . $profile['uid'] . '.jpg';
43         $small = $a->get_baseurl() . '/photo/custom/50/'  . $profile['uid'] . '.jpg';
44         $searchable = (($profile['publish'] && $profile['net-publish']) ? 'true' : 'false' );
45
46         if($searchable === 'true') {
47                 $dob = '1000-00-00';
48
49                 if(($profile['dob']) && ($profile['dob'] != '0000-00-00'))
50                         $dob = ((intval($profile['dob'])) ? intval($profile['dob']) : '1000') . '-' . datetime_convert('UTC','UTC',$profile['dob'],'m-d');
51                 $gender = $profile['gender'];
52                 $about = $profile['about'];
53                 require_once('include/bbcode.php');
54                 $about = strip_tags(bbcode($about));
55                 $location = '';
56                 if($profile['locality'])
57                         $location .= $profile['locality'];
58                 if($profile['region']) {
59                         if($location)
60                                 $location .= ', ';
61                         $location .= $profile['region'];
62                 }
63                 if($profile['country-name']) {
64                         if($location)
65                                 $location .= ', ';
66                         $location .= $profile['country-name'];
67                 }
68                 $tags = '';
69                 if($profile['pub_keywords']) {
70                         $kw = str_replace(',',' ',$profile['pub_keywords']);
71                         $kw = str_replace('  ',' ',$kw);
72                         $arr = explode(' ',$profile['pub_keywords']);
73                         if(count($arr)) {
74                                 for($x = 0; $x < 5; $x ++) {
75                                         if(trim($arr[$x]))
76                                                 $tags .= '#' . trim($arr[$x]) . ' ';
77                                 }
78                         }
79                 }
80                 $tags = trim($tags);
81         }
82
83         $tpl = get_markup_template('diaspora_profile.tpl');
84
85         $msg = replace_macros($tpl,array(
86                 '$handle' => $handle,
87                 '$first' => $first,
88                 '$last' => $last,
89                 '$large' => $large,
90                 '$medium' => $medium,
91                 '$small' => $small,
92                 '$dob' => $dob,
93                 '$gender' => $gender,
94                 '$about' => $about,
95                 '$location' => $location,
96                 '$searchable' => $searchable,
97                 '$tags' => $tags
98         ));
99         logger('profile_change: ' . $msg, LOGGER_ALL);
100
101         $msgtosend = diaspora_msg_build($msg,$a->user,null,$a->user['prvkey'],null,true);
102         foreach($recips as $recip) {
103                 add_to_queue($recip['id'],NETWORK_DIASPORA,$msgtosend,true);
104         }
105 }