]> git.mxchange.org Git - friendica.git/blob - mod/profiles.php
mistpark 2.0 infrasturcture lands
[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         if(($a->argc > 1) && ($a->argv[1] != "new") && intval($a->argv[1])) {
14                 $orig = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
15                         intval($a->argv[1]),
16                         intval($_SESSION['uid'])
17                 );
18                 if(! count($orig)) {
19                         notice( t('Profile not found.') . EOL);
20                         return;
21                 }
22                 $is_default = (($orig[0]['is-default']) ? 1 : 0);
23
24                 $profile_name = notags(trim($_POST['profile_name']));
25                 if(! strlen($profile_name)) {
26                         notify( t('Profile Name is required.') . EOL);
27                         return;
28                 }
29         
30                 $year = intval($_POST['year']);
31                 if($year < 1900 || $year > 2100 || $year < 0)
32                         $year = 0;
33                 $month = intval($_POST['month']);
34                         if(($month > 12) || ($month < 0))
35                                 $month = 0;
36                 $mtab = array(0,31,29,31,30,31,30,31,31,30,31,30,31);
37                 $day = intval($_POST['day']);
38                         if(($day > $mtab[$month]) || ($day < 0))
39                                 $day = 0;
40                 $dob = '0000-00-00';
41                 $dob = sprintf('%04d-%02d-%02d',$year,$month,$day);
42
43                         
44                 $name = notags(trim($_POST['name']));
45
46                 if($orig[0]['name'] != $name)
47                         $namechanged = true;
48
49                 $gender = notags(trim($_POST['gender']));
50                 $address = notags(trim($_POST['address']));
51                 $locality = notags(trim($_POST['locality']));
52                 $region = notags(trim($_POST['region']));
53                 $postal_code = notags(trim($_POST['postal_code']));
54                 $country_name = notags(trim($_POST['country_name']));
55
56                 $marital = notags(trim($_POST['marital']));
57                 if($marital != $orig[0]['marital'])
58                         $maritalchanged = true;
59
60                 $sexual = notags(trim($_POST['sexual']));
61                 $homepage = notags(trim($_POST['homepage']));
62                 $politic = notags(trim($_POST['politic']));
63                 $religion = notags(trim($_POST['religion']));
64
65                 $about = escape_tags(trim($_POST['about']));
66                 $interest = escape_tags(trim($_POST['interest']));
67                 $contact = escape_tags(trim($_POST['contact']));
68                 $music = escape_tags(trim($_POST['music']));
69                 $book = escape_tags(trim($_POST['book']));
70                 $tv = escape_tags(trim($_POST['tv']));
71                 $film = escape_tags(trim($_POST['film']));
72                 $romance = escape_tags(trim($_POST['romance']));
73                 $work = escape_tags(trim($_POST['work']));
74                 $education = escape_tags(trim($_POST['education']));
75                 $hide_friends = (($_POST['hide-friends'] == 1) ? 1: 0);
76
77
78                 $r = q("UPDATE `profile` 
79                         SET `profile-name` = '%s',
80                         `name` = '%s',
81                         `gender` = '%s',
82                         `dob` = '%s',
83                         `address` = '%s',
84                         `locality` = '%s',
85                         `region` = '%s',
86                         `postal-code` = '%s',
87                         `country-name` = '%s',
88                         `marital` = '%s',
89                         `sexual` = '%s',
90                         `homepage` = '%s',
91                         `politic` = '%s',
92                         `religion` = '%s',
93                         `about` = '%s',
94                         `interest` = '%s',
95                         `contact` = '%s',
96                         `music` = '%s',
97                         `book` = '%s',
98                         `tv` = '%s',
99                         `film` = '%s',
100                         `romance` = '%s',
101                         `work` = '%s',
102                         `education` = '%s',
103                         `hide-friends` = %d
104                         WHERE `id` = %d AND `uid` = %d LIMIT 1",
105                         dbesc($profile_name),
106                         dbesc($name),
107                         dbesc($gender),
108                         dbesc($dob),
109                         dbesc($address),
110                         dbesc($locality),
111                         dbesc($region),
112                         dbesc($postal_code),
113                         dbesc($country_name),
114                         dbesc($marital),
115                         dbesc($sexual),
116                         dbesc($homepage),
117                         dbesc($politic),
118                         dbesc($religion),
119                         dbesc($about),
120                         dbesc($interest),
121                         dbesc($contact),
122                         dbesc($music),
123                         dbesc($book),
124                         dbesc($tv),
125                         dbesc($film),
126                         dbesc($romance),
127                         dbesc($work),
128                         dbesc($education),
129                         intval($hide_friends),
130                         intval($a->argv[1]),
131                         intval($_SESSION['uid'])
132                 );
133
134                 if($r)
135                         notice( t('Profile updated.') . EOL);
136
137
138                 if($namechanged && $is_default) {
139                         $r = q("UPDATE `contact` SET `name-date` = '%s' WHERE `self` = 1 AND `uid` = %d LIMIT 1",
140                                 dbesc(datetime_convert()),
141                                 intval($_SESSION['uid'])
142                         );
143                 }
144
145                 if($is_default) {
146                         // Update global directory in background
147                         $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
148                         $url = $_SESSION['my_url'];
149                         if($url && strlen(get_config('system','directory_submit_url')))
150                                 proc_close(proc_open("\"$php_path\" \"include/directory.php\" \"$url\" &",
151                                         array(),$foo));
152                 }
153         }
154 }
155
156
157
158
159 function profiles_content(&$a) {
160         if(! local_user()) {
161                 notice( t('Permission denied.') . EOL);
162                 return;
163         }
164
165         if(($a->argc > 2) && ($a->argv[1] == "drop") && intval($a->argv[2])) {
166                 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is-default` = 0 AND `self` = 0 LIMIT 1",
167                         intval($a->argv[2]),
168                         intval($_SESSION['uid'])
169                 );
170                 if(! count($r)) {
171                         notice( t('Profile not found.') . EOL);
172                         goaway($a->get_baseurl() . '/profiles');
173                         return; // NOTREACHED
174                 }
175
176                 // move every contact using this profile as their default to the user default
177
178                 $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 ",
179                         intval($_SESSION['uid']),
180                         intval($a->argv[2]),
181                         intval($_SESSION['uid'])
182                 );
183                 $r = q("DELETE FROM `profile` WHERE `id` = %d LIMIT 1",
184                         intval($a->argv[2])
185                 );
186                 if($r)
187                         notice( t('Profile deleted.') . EOL);
188
189                 goaway($a->get_baseurl() . '/profiles');
190                 return; // NOTREACHED
191         }
192
193
194
195
196
197         if(($a->argc > 1) && ($a->argv[1] == 'new')) {
198
199                 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
200                         intval($_SESSION['uid']));
201                 $num_profiles = count($r0);
202
203                 $name = t('Profile-') . ($num_profiles + 1);
204
205                 $r1 = q("SELECT `name`, `photo`, `thumb` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
206                         intval($_SESSION['uid']));
207                 
208                 $r2 = q("INSERT INTO `profile` (`uid` , `profile-name` , `name`, `photo`, `thumb`)
209                         VALUES ( %d, '%s', '%s', '%s', '%s' )",
210                         intval($_SESSION['uid']),
211                         dbesc($name),
212                         dbesc($r1[0]['name']),
213                         dbesc($r1[0]['photo']),
214                         dbesc($ra[0]['thumb'])
215                 );
216
217                 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
218                         intval($_SESSION['uid']),
219                         dbesc($name)
220                 );
221                 notice( t('New profile created.') . EOL);
222                 if(count($r3) == 1)
223                         goaway($a->get_baseurl() . '/profiles/' . $r3[0]['id']);
224                 goaway($a->get_baseurl() . '/profiles');
225         }                
226
227         if(($a->argc > 2) && ($a->argv[1] == 'clone')) {
228
229                 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
230                         intval($_SESSION['uid']));
231                 $num_profiles = count($r0);
232
233                 $name = t('Profile-') . ($num_profiles + 1);
234                 $r1 = q("SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d LIMIT 1",
235                         intval($_SESSION['uid']),
236                         intval($a->argv[2])
237                 );
238                 if(! count($r1)) {
239                         notice( t('Profile unavailable to clone.') . EOL);
240                         return;
241                 }
242                 unset($r1[0]['id']);
243                 $r1[0]['is-default'] = 0;
244                 $r1[0]['publish'] = 0;  
245                 $r1[0]['net-publish'] = 0;      
246                 $r1[0]['profile-name'] = dbesc($name);
247
248                 dbesc_array($r1[0]);
249
250                 $r2 = q("INSERT INTO `profile` (`" 
251                         . implode("`, `", array_keys($r1[0])) 
252                         . "`) VALUES ('" 
253                         . implode("', '", array_values($r1[0])) 
254                         . "')" );
255
256                 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
257                         intval($_SESSION['uid']),
258                         dbesc($name)
259                 );
260                 notice( t('New profile created.') . EOL);
261                 if(count($r3) == 1)
262                         goaway($a->get_baseurl() . '/profiles/' . $r3[0]['id']);
263         goaway($a->get_baseurl() . '/profiles');
264         return; // NOTREACHED
265         }                
266
267
268         if(intval($a->argv[1])) {
269                 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
270                         intval($a->argv[1]),
271                         intval($_SESSION['uid'])
272                 );
273                 if(! count($r)) {
274                         notice( t('Profile not found.') . EOL);
275                         return;
276                 }
277
278                 require_once('mod/profile.php');
279                 profile_load($a,$a->user['nickname'],$r[0]['id']);
280
281                 require_once('view/profile_selectors.php');
282
283                 $tpl = file_get_contents('view/profed_head.tpl');
284
285                 $opt_tpl = file_get_contents("view/profile-hide-friends.tpl");
286                 $hide_friends = replace_macros($opt_tpl,array(
287                         '$yes_selected' => (($r[0]['hide-friends']) ? " checked=\"checked\" " : ""),
288                         '$no_selected' => (($r[0]['hide-friends'] == 0) ? " checked=\"checked\" " : "")
289                 ));
290
291
292                 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
293                 $a->page['htmlhead'] .= "<script type=\"text/javascript\" src=\"include/country.js\" ></script>";
294
295
296
297         
298
299                 $is_default = (($r[0]['is-default']) ? 1 : 0);
300                 $tpl = file_get_contents("view/profile_edit.tpl");
301                 $o .= replace_macros($tpl,array(
302                         '$disabled' => (($is_default) ? 'onclick="return false;" style="color: #BBBBFF;"' : ''),
303                         '$baseurl' => $a->get_baseurl(),
304                         '$profile_id' => $r[0]['id'],
305                         '$profile_name' => $r[0]['profile-name'],
306                         '$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>' : ""),
307                         '$name' => $r[0]['name'],
308                         '$dob' => dob($r[0]['dob']),
309                         '$hide_friends' => $hide_friends,
310                         '$address' => $r[0]['address'],
311                         '$locality' => $r[0]['locality'],
312                         '$region' => $r[0]['region'],
313                         '$postal_code' => $r[0]['postal-code'],
314                         '$country_name' => $r[0]['country-name'],
315                         '$age' => ((intval($r[0]['dob'])) ? '(' . t('Age: ') . age($r[0]['dob'],$a->user['timezone'],$a->user['timezone']) . ')' : ''),
316                         '$gender' => gender_selector($r[0]['gender']),
317                         '$marital' => marital_selector($r[0]['marital']),
318                         '$sexual' => sexpref_selector($r[0]['sexual']),
319                         '$about' => $r[0]['about'],
320                         '$homepage' => $r[0]['homepage'],
321                         '$politic' => $r[0]['politic'],
322                         '$religion' => $r[0]['religion'],
323                         '$music' => $r[0]['music'],
324                         '$book' => $r[0]['book'],
325                         '$tv' => $r[0]['tv'],
326                         '$film' => $r[0]['film'],
327                         '$interest' => $r[0]['interest'],
328                         '$romance' => $r[0]['romance'],
329                         '$work' => $r[0]['work'],
330                         '$education' => $r[0]['education'],
331                         '$contact' => $r[0]['contact']
332                 ));
333
334                 return $o;
335
336
337         }
338         else {
339
340                 $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
341                         $_SESSION['uid']);
342                 if(count($r)) {
343
344                         $o .= file_get_contents('view/profile_listing_header.tpl');
345                         $tpl_default = file_get_contents('view/profile_entry_default.tpl');
346                         $tpl = file_get_contents('view/profile_entry.tpl');
347
348                         foreach($r as $rr) {
349                                 $template = (($rr['is-default']) ? $tpl_default : $tpl);
350                                 $o .= replace_macros($template, array(
351                                         '$photo' => $rr['thumb'],
352                                         '$id' => $rr['id'],
353                                         '$profile_name' => $rr['profile-name']
354                                 ));
355                         }
356                 }
357                 return $o;
358         }
359
360 }