3 function profile_init(&$a) {
8 notice( t('No profile') . EOL );
14 if((local_user()) && ($a->argc > 2) && ($a->argv[2] === 'view')) {
15 $which = $a->user['nickname'];
16 $profile = $a->argv[1];
19 profile_load($a,$which,$profile);
21 if((x($a->profile,'page-flags')) && ($a->profile['page-flags'] & PAGE_COMMUNITY)) {
22 $a->page['htmlhead'] .= '<meta name="friendika.community" content="true" />';
24 if(x($a->profile,'openidserver'))
25 $a->page['htmlhead'] .= '<link rel="openid.server" href="' . $a->profile['openidserver'] . '" />' . "\r\n";
26 if(x($a->profile,'openid')) {
27 $delegate = ((strstr($a->profile['openid'],'://')) ? $a->profile['openid'] : 'http://' . $a->profile['openid']);
28 $a->page['htmlhead'] .= '<link rel="openid.delegate" href="' . $delegate . '" />' . "\r\n";
31 $keywords = ((x($a->profile,'pub_keywords')) ? $a->profile['pub_keywords'] : '');
32 $keywords = str_replace(array(',',' ',',,'),array(' ',',',','),$keywords);
34 $a->page['htmlhead'] .= '<meta name="keywords" content="' . $keywords . '" />' . "\r\n" ;
36 $a->page['htmlhead'] .= '<meta name="dfrn-global-visibility" content="' . (($a->profile['net-publish']) ? 'true' : 'false') . '" />' . "\r\n" ;
37 $a->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $a->get_baseurl() . '/dfrn_poll/' . $which .'" />' . "\r\n" ;
38 $uri = urlencode('acct:' . $a->profile['nickname'] . '@' . $a->get_hostname() . (($a->path) ? '/' . $a->path : ''));
39 $a->page['htmlhead'] .= '<link rel="lrdd" type="application/xrd+xml" href="' . $a->get_baseurl() . '/xrd/?uri=' . $uri . '" />' . "\r\n";
40 header('Link: <' . $a->get_baseurl() . '/xrd/?uri=' . $uri . '>; rel="lrdd"; type="application/xrd+xml"', false);
42 $dfrn_pages = array('request', 'confirm', 'notify', 'poll');
43 foreach($dfrn_pages as $dfrn)
44 $a->page['htmlhead'] .= "<link rel=\"dfrn-{$dfrn}\" href=\"".$a->get_baseurl()."/dfrn_{$dfrn}/{$which}\" />\r\n";
49 function profile_content(&$a, $update = 0) {
51 require_once("include/bbcode.php");
52 require_once('include/security.php');
60 // Ensure we've got a profile owner if updating.
61 $a->profile['profile_uid'] = $update;
64 if($a->profile['profile_uid'] == local_user())
65 $o .= '<script> $(document).ready(function() { $(\'#nav-home-link\').addClass(\'nav-selected\'); });</script>';
69 $remote_contact = false;
72 $contact_id = $_SESSION['visitor_id'];
73 $groups = init_groups_visitor($contact_id);
74 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
76 intval($a->profile['profile_uid'])
80 $remote_contact = true;
84 if(! $remote_contact) {
86 $contact_id = $_SESSION['cid'];
87 $contact = $a->contact;
91 $is_owner = ((local_user()) && (local_user() == $a->profile['profile_uid']) ? true : false);
95 $tab = notags(trim($_GET['tab']));
97 $tpl = load_view_file('view/profile_tabs.tpl');
99 $o .= replace_macros($tpl,array(
100 '$url' => $a->get_baseurl() . '/' . $a->cmd,
101 '$phototab' => $a->get_baseurl() . '/photos/' . $a->profile['nickname']
105 if($tab === 'profile') {
106 $profile_lang = get_config('system','language');
108 $profile_lang = 'en';
109 if(file_exists("view/$profile_lang/profile_advanced.php"))
110 require_once("view/$profile_lang/profile_advanced.php");
112 require_once('view/profile_advanced.php');
114 call_hooks('profile_advanced',$o);
119 $commpage = (($a->profile['page-flags'] == PAGE_COMMUNITY) ? true : false);
120 $commvisitor = (($commpage && $remote_contact == true) ? true : false);
122 $celeb = ((($a->profile['page-flags'] == PAGE_SOAPBOX) || ($a->profile['page-flags'] == PAGE_COMMUNITY)) ? true : false);
124 if(can_write_wall($a,$a->profile['profile_uid'])) {
126 $geotag = ((($is_owner || $commvisitor) && $a->profile['allow_location']) ? load_view_file('view/jot_geotag.tpl') : '');
128 $tpl = load_view_file('view/jot-header.tpl');
130 $a->page['htmlhead'] .= replace_macros($tpl, array(
131 '$baseurl' => $a->get_baseurl(),
132 '$geotag' => $geotag,
133 '$nickname' => $a->profile['nickname']
136 require_once('include/acl_selectors.php');
138 $tpl = load_view_file('view/jot.tpl');
140 if(is_array($a->user) && ((strlen($a->user['allow_cid'])) || (strlen($a->user['allow_gid'])) || (strlen($a->user['deny_cid'])) || (strlen($a->user['deny_gid']))))
143 $lockstate = 'unlock';
147 call_hooks('jot_tool', $jotplugins);
149 call_hooks('jot_networks', $jotnets);
151 $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
153 $o .= replace_macros($tpl,array(
154 '$baseurl' => $a->get_baseurl(),
156 '$share' => t('Share'),
157 '$upload' => t('Upload photo'),
158 '$weblink' => t('Insert web link'),
159 '$youtube' => t('Insert YouTube video'),
160 '$video' => t('Insert Vorbis [.ogg] video'),
161 '$audio' => t('Insert Vorbis [.ogg] audio'),
162 '$setloc' => t('Set your location'),
163 '$noloc' => t('Clear browser location'),
164 '$wait' => t('Please wait'),
165 '$permset' => t('Permission settings'),
168 '$defloc' => (($is_owner) ? $a->user['default-location'] : ''),
169 '$return_path' => $a->cmd,
170 '$visitor' => (($is_owner || $commvisitor) ? 'block' : 'none'),
171 '$lockstate' => $lockstate,
172 '$emailcc' => t('CC: email addresses'),
173 '$jotnets' => $jotnets,
174 '$emtitle' => t('Example: bob@example.com, mary@example.com'),
176 '$acl' => (($is_owner) ? populate_acl($a->user, $celeb) : ''),
177 '$profile_uid' => $a->profile['profile_uid']
181 // This is ugly, but we can't pass the profile_uid through the session to the ajax updater,
182 // because browser prefetching might change it on us. We have to deliver it with the page.
184 if($tab === 'posts') {
185 $o .= '<div id="live-profile"></div>' . "\r\n";
186 $o .= "<script> var profile_uid = " . $a->profile['profile_uid']
187 . "; var netargs = ''; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
191 // Construct permissions
193 // default permissions - anonymous user
195 $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' ";
197 // Profile owner - everything is visible
202 // Oh - while we're here... reset the Unseen messages
204 $r = q("UPDATE `item` SET `unseen` = 0
205 WHERE `type` != 'remote' AND `unseen` = 1 AND `uid` = %d",
206 intval($_SESSION['uid'])
211 // authenticated visitor - here lie dragons
212 // If $remotecontact is true, we know that not only is this a remotely authenticated
213 // person, but that it is *our* contact, which is important in multi-user mode.
215 elseif($remote_contact) {
216 $gs = '<<>>'; // should be impossible to match
218 foreach($groups as $g)
219 $gs .= '|<' . intval($g) . '>';
221 $sql_extra = sprintf(
222 " AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' )
223 AND ( `deny_cid` = '' OR NOT `deny_cid` REGEXP '<%d>' )
224 AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
225 AND ( `deny_gid` = '' OR NOT `deny_gid` REGEXP '%s') ",
227 intval($_SESSION['visitor_id']),
228 intval($_SESSION['visitor_id']),
234 $r = q("SELECT COUNT(*) AS `total`
235 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
236 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
237 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
238 AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` AND `wall` = 1 )
240 intval($a->profile['profile_uid'])
245 $a->set_pager_total($r[0]['total']);
247 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
248 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`, `contact`.`rel`,
249 `contact`.`thumb`, `contact`.`self`,
250 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
251 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
252 WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
253 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
254 AND `item`.`parent` IN ( SELECT `parent` FROM `item` WHERE `id` = `parent` AND `wall` = 1 )
256 ORDER BY `parent` DESC, `gravity` ASC, `id` ASC LIMIT %d ,%d ",
257 intval($a->profile['profile_uid']),
258 intval($a->pager['start']),
259 intval($a->pager['itemspage'])
264 if($is_owner && ! $update)
265 $o .= get_birthdays();
267 $cmnt_tpl = load_view_file('view/comment_item.tpl');
269 $like_tpl = load_view_file('view/like.tpl');
270 $noshare_tpl = load_view_file('view/like_noshare.tpl');
272 $tpl = load_view_file('view/wall_item.tpl');
274 $droptpl = load_view_file('view/wall_item_drop.tpl');
275 $fakedrop = load_view_file('view/wall_fake_drop.tpl');
278 $return_url = $_SESSION['return_url'];
280 $return_url = $_SESSION['return_url'] = $a->cmd;
285 if($r !== false && count($r)) {
287 foreach($r as $item) {
288 like_puller($a,$item,$alike,'like');
289 like_puller($a,$item,$dlike,'dislike');
292 foreach($r as $item) {
300 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
302 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE)))
303 && ($item['id'] != $item['parent']))
306 $lock = ((($item['private']) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
307 || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
308 ? '<div class="wall-item-lock"><img src="images/lock_icon.gif" class="lockview" alt="' . t('Private Message') . '" onclick="lockview(event,' . $item['id'] . ');" /></div>'
309 : '<div class="wall-item-lock"></div>');
311 if(can_write_wall($a,$a->profile['profile_uid'])) {
312 if($item['id'] == $item['parent']) {
313 $likebuttons = replace_macros((($item['private']) ? $noshare_tpl : $like_tpl),array(
314 '$id' => $item['id'],
315 '$likethis' => t("I like this \x28toggle\x29"),
316 '$nolike' => t("I don't like this \x28toggle\x29"),
317 '$share' => t('Share'),
318 '$wait' => t('Please wait')
321 if($item['last-child']) {
322 $comment = replace_macros($cmnt_tpl,array(
323 '$return_path' => '',
324 '$jsreload' => '', // $_SESSION['return_url'],
325 '$type' => 'wall-comment',
326 '$id' => $item['item_id'],
327 '$parent' => $item['parent'],
328 '$profile_uid' => $a->profile['profile_uid'],
329 '$mylink' => $contact['url'],
330 '$mytitle' => t('This is you'),
331 '$myphoto' => $contact['thumb'],
338 $profile_url = $item['url'];
340 // This is my profile page but I'm not the author of this post/comment. If it's somebody that's a fan or mutual friend,
341 // I can go directly to their profile as an authenticated guest.
343 if(local_user() && ($item['contact-uid'] == $_SESSION['uid'])
344 && ($item['network'] === 'dfrn') && (! $item['self'] )) {
345 $profile_url = $redirect_url;
346 $sparkle = ' sparkle';
353 if((local_user()) && ($a->profile['profile_uid'] == local_user()) && ($item['id'] == $item['parent']) && (intval($item['wall']) == 1))
354 $edpost = '<a class="editpost" href="' . $a->get_baseurl() . '/editpost/' . $item['id'] . '" title="' . t('Edit') . '"><img src="images/pencil.gif" /></a>';
357 // We would prefer to use our own avatar link for this item because the one in the author-avatar might reference a
358 // remote site (which could be down). We will use author-avatar if we haven't got something stored locally.
359 // We use this same logic block in mod/network.php to determine it this is a third party post and we don't have any
360 // local contact info at all. In this module you should never encounter a third-party author, but we still will do
361 // the right thing if you ever do.
363 $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
365 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
366 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
368 $profile_link = $profile_url;
373 if(($item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
376 $drop = replace_macros((($dropping)? $droptpl : $fakedrop), array('$id' => $item['id'], '$delete' => t('Delete')));
379 $like = ((isset($alike[$item['id']])) ? format_like($alike[$item['id']],$alike[$item['id'] . '-l'],'like',$item['id']) : '');
380 $dislike = ((isset($dlike[$item['id']])) ? format_like($dlike[$item['id']],$dlike[$item['id'] . '-l'],'dislike',$item['id']) : '');
381 $location = (($item['location']) ? '<a target="map" title="' . $item['location'] . '" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : '');
382 $coord = (($item['coord']) ? '<a target="map" title="' . $item['coord'] . '" href="http://maps.google.com/?q=' . urlencode($item['coord']) . '">' . $item['coord'] . '</a>' : '');
385 $location .= '<br /><span class="smalltext">(' . $coord . ')</span>';
387 $location = '<span class="smalltext">' . $coord . '</span>';
390 $indent = (($item['parent'] != $item['item_id']) ? ' comment' : '');
392 if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0)
395 $tmp_item = replace_macros($template,array(
396 '$id' => $item['item_id'],
397 '$linktitle' => t('View $name\'s profile'),
398 '$profile_url' => $profile_link,
399 '$name' => $profile_name,
400 '$thumb' => $profile_avatar,
401 '$sparkle' => $sparkle,
402 '$title' => $item['title'],
403 '$body' => smilies(bbcode($item['body'])),
404 '$ago' => relative_date($item['created']),
406 '$location' => $location,
407 '$indent' => $indent,
408 '$plink' => get_plink($item),
409 '$edpost' => $edpost,
412 '$vote' => $likebuttons,
413 '$dislike' => $dislike,
414 '$comment' => $comment
417 $arr = array('item' => $item, 'output' => $tmp_item);
418 call_hooks('display_item', $arr);
420 $o .= $arr['output'];
430 $o .= '<div class="cc-license">' . t('Shared content is covered by the <a href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0</a> license.') . '</div>';