]> git.mxchange.org Git - friendica.git/blob - include/profile_update.php
bug in diaspora_reshare
[friendica.git] / include / profile_update.php
1 <?php
2
3 require_once('include/datetime.php');
4 require_once('include/diaspora.php');
5
6 function profile_change() {
7
8         $a = get_app();
9         
10         if(! local_user())
11                 return;
12
13 //   $url = $a->get_baseurl() . '/profile/' . $a->user['nickname'];
14  //   if($url && strlen(get_config('system','directory_submit_url')))
15   //      proc_run('php',"include/directory.php","$url");
16
17         $recips = q("SELECT DISTINCT(`batch`), `id`, `name`,`network` FROM `contact` WHERE `network` = '%s'
18                 AND `uid` = %d AND `rel` != %d ORDER BY rand() ",
19                 dbesc(NETWORK_DIASPORA),
20                 intval(local_user()),
21                 intval(CONTACT_IS_SHARING)
22         );
23         if(! count($recips))
24                 return;
25
26         $r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `user`.* FROM `profile`
27                 LEFT JOIN `user` ON `profile`.`uid` = `user`.`uid`
28                 WHERE `user`.`uid` = %d AND `profile`.`is-default` = 1 LIMIT 1",
29                 intval(local_user())
30         );
31         
32         if(! count($r))
33                 return;
34         $profile = $r[0];
35
36         $handle = $a->user['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);
37         $first = ((strpos($profile['name'],' '))
38                 ? trim(substr($profile['name'],0,strpos($profile['name'],' '))) : $profile['name']);
39         $last = (($first === $profile['name']) ? '' : trim(substr($profile['name'],strlen($first))));
40         $large = $a->get_baseurl() . '/photo/custom/300/' . $profile['uid'] . '.jpg';
41         $medium = $a->get_baseurl() . '/photo/custom/100/' . $profile['uid'] . '.jpg';
42         $small = $a->get_baseurl() . '/photo/custom/50/'  . $profile['uid'] . '.jpg';
43         $searchable = (($profile['publish'] && $profile['net-publish']) ? 'true' : 'false' );
44
45         if($searchable === 'true') {
46                 $dob = '1000-00-00';
47
48                 if(($profile['dob']) && ($profile['dob'] != '0000-00-00'))
49                         $dob = ((intval($profile['dob'])) ? intval($profile['dob']) : '1000') . '-' . datetime_convert('UTC','UTC',$profile['dob'],'m-d');
50                 $gender = $profile['gender'];
51                 $about = $profile['about'];
52                 require_once('include/bbcode.php');
53                 $about = strip_tags(bbcode($about));
54                 $location = '';
55                 if($profile['locality'])
56                         $location .= $profile['locality'];
57                 if($profile['region']) {
58                         if($location)
59                                 $location .= ', ';
60                         $location .= $profile['region'];
61                 }
62                 if($profile['country-name']) {
63                         if($location)
64                                 $location .= ', ';
65                         $location .= $profile['country-name'];
66                 }
67                 $tags = '';
68                 if($profile['pub_keywords']) {
69                         $kw = str_replace(',',' ',$profile['pub_keywords']);
70                         $kw = str_replace('  ',' ',$kw);
71                         $arr = explode(' ',$profile['pub_keywords']);
72                         if(count($arr)) {
73                                 for($x = 0; $x < 5; $x ++) {
74                                         if(trim($arr[$x]))
75                                                 $tags .= '#' . trim($arr[$x]) . ' ';
76                                 }
77                         }
78                 }
79                 $tags = trim($tags);
80         }
81
82         $tpl = get_markup_template('diaspora_profile.tpl');
83
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                 q("insert into queue (`cid`,`network`,`created`,`last`,`content`,`batch`)
104                         values(%d,'%s','%s','%s','%s',%d)",
105                         intval($recip['id']),
106                         dbesc(NETWORK_DIASPORA),
107                         dbesc(datetime_convert()),
108                         dbesc(datetime_convert()),
109                         dbesc($msgtosend),
110                         intval(1)
111                 );
112         }
113 }