From e0045a43e22082e0a47fd57288105a21311e911a Mon Sep 17 00:00:00 2001
From: Mike Macgirvin <mike@macgirvin.com>
Date: Thu, 19 Aug 2010 04:59:31 -0700
Subject: [PATCH] mongo checkin, global directory, redir rework, location
 basics

---
 boot.php                     |  30 ++++++++++-
 database.sql                 |   3 +-
 htconfig.php                 |  10 +++-
 images/mapicon.gif           | Bin 0 -> 1042 bytes
 images/youtube_icon.gif      | Bin 0 -> 924 bytes
 include/directory.php        |  28 ++++++++++
 include/main.js              |  87 +++++++++++++++++++++++++++++++
 include/nav.php              |   2 +-
 include/notifier.php         |   2 +-
 include/poller.php           |   2 +-
 include/security.php         |   7 ++-
 mod/contacts.php             |   4 +-
 mod/dfrn_poll.php            |   2 +-
 mod/directory.php            |   2 +
 mod/network.php              |   6 ++-
 mod/photos.php               |   5 +-
 mod/profile.php              |  18 ++++---
 mod/profiles.php             |  63 +++++++++++++++--------
 mod/redir.php                |   8 +--
 view/directory_header.tpl    |   2 +
 view/head.tpl                |  96 -----------------------------------
 view/htconfig.tpl            |   4 ++
 view/profile-in-netdir.tpl   |  16 ++++++
 view/profile_edit.tpl        |   2 +
 view/theme/default/style.css |   8 ++-
 view/wall_item.tpl           |   1 +
 view/wallwall_item.tpl       |   2 +
 27 files changed, 266 insertions(+), 144 deletions(-)
 create mode 100644 images/mapicon.gif
 create mode 100644 images/youtube_icon.gif
 create mode 100644 include/directory.php
 create mode 100644 view/profile-in-netdir.tpl

diff --git a/boot.php b/boot.php
index eae44c6729..17eccd138f 100644
--- a/boot.php
+++ b/boot.php
@@ -170,6 +170,8 @@ function system_unavailable() {
 if(! function_exists('check_config')) {
 function check_config(&$a) {
 
+	load_config('system');
+
 	$build = get_config('system','build');
 	if(! x($build))
 		$build = set_config('system','build',BUILD_ID);
@@ -560,19 +562,45 @@ function sanitise_acl(&$item) {
 		unset($item);
 }}
 
+if(! function_exists('load_config')) {
+function load_config($family) {
+	global $a;
+	$r = q("SELECT * FROM `config` WHERE `cat` = '%s'",
+		dbesc($family)
+	);
+	if(count($r)) {
+		foreach($r as $rr) {
+			$k = $rr['k'];
+			$a->config[$family][$k] = $rr['v'];
+		}
+	}
+}}
+
+
+
 if(! function_exists('get_config')) {
 function get_config($family,$key) {
+	global $a;
+	if(isset($a->config[$family][$key]))
+		return $a->config[$family][$key];
+
 	$ret = q("SELECT `v` FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
 		dbesc($family),
 		dbesc($key)
 	);
-	if(count($ret))
+	if(count($ret)) {
+		$a->config[$family][$key] = $ret[0]['v'];
 		return $ret[0]['v'];
+	}
 	return false;
 }}
 
 if(! function_exists('set_config')) {
 function set_config($family,$key,$value) {
+
+	global $a;
+	$a->config[$family][$key] = $value;
+
 	if(get_config($family,$key) === false) {
 		$ret = q("INSERT INTO `config` ( `cat`, `k`, `v` ) VALUES ( '%s', '%s', '%s' ) ",
 			dbesc($family),
diff --git a/database.sql b/database.sql
index 886c4b3b6d..1809f4703b 100644
--- a/database.sql
+++ b/database.sql
@@ -264,7 +264,7 @@ CREATE TABLE IF NOT EXISTS `profile` (
   `region` char(255) NOT NULL,
   `postal-code` char(32) NOT NULL,
   `country-name` char(255) NOT NULL,
-  `gender` char(8) NOT NULL,
+  `gender` char(32) NOT NULL,
   `marital` char(255) NOT NULL,
   `sexual` char(255) NOT NULL,
   `politic` char(255) NOT NULL,
@@ -284,6 +284,7 @@ CREATE TABLE IF NOT EXISTS `profile` (
   `photo` char(255) NOT NULL,
   `thumb` char(255) NOT NULL,
   `publish` tinyint(1) NOT NULL DEFAULT '0',
+  `net-publish` tinyint(1) NOT NULL DEFAULT '0',
   PRIMARY KEY (`id`)
 ) ENGINE=MyISAM  DEFAULT CHARSET=utf8;
 
diff --git a/htconfig.php b/htconfig.php
index e9c2db3507..0c365579cb 100644
--- a/htconfig.php
+++ b/htconfig.php
@@ -30,4 +30,12 @@ $a->config['admin_email'] = '';
 
 // Maximum size of an imported message, 0 is unlimited (but our database 'text' element is limited to 65535).
 
-$a->config['max_import_size'] = 10000;
\ No newline at end of file
+$a->config['max_import_size'] = 10000;
+
+// Location of PHP command line processor
+
+$a->config['php_path'] = 'php';
+
+// Location of global directory submission page. 
+
+$a->config['system']['directory_submit_url'] = 'http://dir.dfrn.org/submit';
diff --git a/images/mapicon.gif b/images/mapicon.gif
new file mode 100644
index 0000000000000000000000000000000000000000..dd20c209b57992ee4dc1b2babacb43708f8915e4
GIT binary patch
literal 1042
zcmd_p3r`aV007|Ak*ttzb50U4V~Uf=h`J@ivX=`}23Cn0!-7Hyj{(sZ<9JwFFaot|
zM;(LX;iJVOur?9pWoeJ3EffZ{)a$kMfB^^B2Lh$jOA#uy&{Kbh-+%ZL=<(lupSca#
z1}t^}F$o;nF*fZOCx%`eL+8f+#?MbGxO(<NL27Yn3ac=Kot#^BhE<oB!%t>aGg#pH
z3pZ0Q*5Al3$tt*$R@9Ko7Nv3}860sM_kK#rgOrk%EUqY*dz-}-^NK3duSm15NKW&V
zIc3d%REW;rfRb-Qm#&G5d3A-??&a~N=L9P7D#)l*aRrhx!QITiwZ+2ri`9zDpqv9L
zOKX*R4Z}jPxwIa-UfWsLpvV{NFH7`%si9mp#+M<LvXMq<M}uszwr!-bZAjE<xYzwu
z+&$XXsc7tmYZaJ8jx@>Pj&5aZkG{1BY41_DC{6!B`VQsj<6cCpwnDv{X7%(#)mWR_
zB3B!gYCY690`(8dwdSq?6dHJ{8Zyd<vA$uWX2hh_VJaQ^$gm9QXEg>?W0-jYFa0|@
z(PjK!1>-u{tU+u;#!0;qRhS7KGCnY7H<?VZ8SS&U5VOf*v8X0j4CA;3oq#88@U(qu
zYQ{L@f-&Mh498~ii8<%=oNXL;>TTX}+%;pJx8YXUu|8#YT5S%@;k4WB=(9D;Gaoij
zIOZ27mNp!VOH)qow9B{PB4(d&EV?|_=l;1Dew-keUl4YJ#NDLLO*-6uf*{;0t1s79
zS3PSUkH_nMwf@@c^Z7P6H#hv7{&&dtP`Ec>OAtT;`+>LKod75VKnCszi3I>^WEGXM
zeo0&YF&G`b0{$K_SoYZ$+3vvzI4t^>xZL_}^^xm`*gxm+lHwD?6Hg>ke)=VLwDs_V
zxO2Rhvbw0F(K~(+?2a@^Pc<Fv4YkCbh=@Gk5ALtX`BZkY5$Iy}Fvpr`ANd3CWW^)l
z$7>ekDZ=Hzun))(s&{+BU!T*G&(tsv1tFmUBrSlBKCB6jqH{LBS))+EU@{NeJ<qJ)
zx9cz)Jzcjih#I){*O2@orm$+~*GcG>FZXKuqjm{a|J3s01l!a2u^GC(L)3`uIsR9B
Yj%q7}B!i)A(r*3m6J1L>l>+?u1_rLn#{d8T

literal 0
HcmV?d00001

diff --git a/images/youtube_icon.gif b/images/youtube_icon.gif
new file mode 100644
index 0000000000000000000000000000000000000000..987b82bfdd51c2c191c97fe6c19948c9aa0ff230
GIT binary patch
literal 924
zcmZ?wbhEHb6krfw_|5<VhCy?JiuYz)a`Z$AOxb&HZHwi(IZ@~S|9{WG@P5kw@6YG_
z=ivBnY5BjU=l{~B|JSblf9%-*W9R-~yY~P6`~Rb0Gz5ln2<U)v04Ogoa5OS#%SZ$$
zIy7=|2y3};I50M}3JA(E6kK3nU=)?J3)#WI(9|a>m=Sa1<6<`!7MDq1A`U7Y>ts|q
z6=KoYcy_i$;WeL*%}(d$S=RpB61lMP{2~rTg9Zo3L%vIR7K9ZvT+j?$9JtX>^w$<f
emKI*6kctBhtFE$STwWD=dcm^`^M#q17_0&L0~#j)

literal 0
HcmV?d00001

diff --git a/include/directory.php b/include/directory.php
new file mode 100644
index 0000000000..5f835dc4bf
--- /dev/null
+++ b/include/directory.php
@@ -0,0 +1,28 @@
+<?php
+
+	require_once("boot.php");
+
+	$a = new App;
+
+	@include(".htconfig.php");
+	require_once("dba.php");
+	$db = new dba($db_host, $db_user, $db_pass, $db_data);
+		unset($db_host, $db_user, $db_pass, $db_data);
+
+
+	if($argc != 2)
+		exit;
+
+	load_config('system');
+
+	$a->set_baseurl(get_config('system','url'));
+
+	$dir = get_config('system','directory_submit_url');
+
+	if(! strlen($dir))
+		exit;
+
+	fetch_url($dir . '?url=' . bin2hex($argv[1]));
+
+	exit;
+
diff --git a/include/main.js b/include/main.js
index f1c6cee12e..c136488dd4 100644
--- a/include/main.js
+++ b/include/main.js
@@ -31,3 +31,90 @@
 		}
 	}
 
+	var src = null;
+	var prev = null;
+	var livetime = null;
+	var msie = false;
+
+	$(document).ready(function() {
+		$.ajaxSetup({cache: false});
+		msie = $.browser.msie ;
+ 		NavUpdate(); 
+
+
+
+	});
+
+	function NavUpdate() {
+
+		if($('#live-network').length) { src = 'network'; liveUpdate(); }
+		if($('#live-profile').length) { src = 'profile'; liveUpdate(); }
+
+		$.get("ping",function(data) {
+			$(data).find('result').each(function() {
+				var net = $(this).find('net').text();
+				if(net == 0) { net = ''; }
+				$('#net-update').html(net);
+				var home = $(this).find('home').text();
+				if(home == 0) { home = ''; }
+				$('#home-update').html(home);
+				var mail = $(this).find('mail').text();
+				if(mail == 0) { mail = ''; }
+				$('#mail-update').html(mail);
+				var intro = $(this).find('intro').text();
+				if(intro == 0) { intro = ''; }
+				$('#notify-update').html(intro);
+			});
+		}) ;
+		setTimeout(NavUpdate,30000);
+
+	}
+
+	function liveUpdate() {
+		if(src == null) { return; }
+		if($('.comment-edit-text-full').length) {
+			livetime = setTimeout(liveUpdate, 10000);
+			return;
+		}
+		prev = 'live-' + src;
+
+		$.get('update_' + src + '?msie=' + ((msie) ? 1 : 0),function(data) {
+			$('.wall-item-outside-wrapper',data).each(function() {
+				var ident = $(this).attr('id');
+				if($('#' + ident).length == 0) { 
+                                        $('img',this).each(function() {
+                                                $(this).attr('src',$(this).attr('dst'));
+                                        });
+					$('#' + prev).after($(this));
+				}
+				else { 
+
+					$('#' + ident + ' ' + '.wall-item-ago').replaceWith($(this).find('.wall-item-ago')); 
+					$('#' + ident + ' ' + '.wall-item-comment-wrapper').replaceWith($(this).find('.wall-item-comment-wrapper'));
+                                        $('#' + ident + ' ' + '.my-comment-photo').each(function() {
+                                                $(this).attr('src',$(this).attr('dst'));
+                                        });
+
+
+				}
+				prev = ident; 
+			});
+		});
+
+	}
+
+	function confirmDelete() { 
+		return confirm("Delete this item?");
+	}
+
+	function imgbright(node) {
+		$(node).attr("src",$(node).attr("src").replace('hide','show'));
+		$(node).css('width',24);
+		$(node).css('height',24);
+	}
+
+	function imgdull(node) {
+		$(node).attr("src",$(node).attr("src").replace('show','hide'));
+		$(node).css('width',16);
+		$(node).css('height',16);
+	}
diff --git a/include/nav.php b/include/nav.php
index 2e59ad2ac4..4833ed7db5 100644
--- a/include/nav.php
+++ b/include/nav.php
@@ -12,7 +12,7 @@ if(x($_SESSION['uid'])) {
 		$a->page['nav'] .= '<a id="nav-register-link" class="nav-commlink" href="register" >' 
 			. t('Register') . "</a>\r\n";
 
-	$a->page['nav'] .= '<a id="nav-directory-link" class="nav-link" href="directory">' . t('Site Directory') . "</a>\r\n";
+	$a->page['nav'] .= '<a id="nav-directory-link" class="nav-link" href="directory">' . t('Directory') . "</a>\r\n";
 
 	if(x($_SESSION,'uid')) {
 
diff --git a/include/notifier.php b/include/notifier.php
index 149ce765cb..ff18dd9b4f 100644
--- a/include/notifier.php
+++ b/include/notifier.php
@@ -8,7 +8,7 @@
 
 	@include(".htconfig.php");
 	require_once("dba.php");
-	$db = new dba($db_host, $db_user, $db_pass, $db_data, $install);
+	$db = new dba($db_host, $db_user, $db_pass, $db_data);
 		unset($db_host, $db_user, $db_pass, $db_data);
 
 	require_once("session.php");
diff --git a/include/poller.php b/include/poller.php
index 1a323971f1..fcd74fd69b 100644
--- a/include/poller.php
+++ b/include/poller.php
@@ -7,7 +7,7 @@ $a = new App;
 
 @include('.htconfig.php');
 require_once('dba.php');
-$db = new dba($db_host, $db_user, $db_pass, $db_data, $install);
+$db = new dba($db_host, $db_user, $db_pass, $db_data);
 	unset($db_host, $db_user, $db_pass, $db_data);
 
 require_once('session.php');
diff --git a/include/security.php b/include/security.php
index a71391dbac..29334549b1 100644
--- a/include/security.php
+++ b/include/security.php
@@ -6,9 +6,12 @@ function can_write_wall(&$a,$owner) {
         if((local_user()) && ($_SESSION['uid'] == $owner))
                 return true;
 
-        $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `id` = %d AND `blocked` = 0 AND `pending` = 0 LIMIT 1",
+        $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `id` = %d AND `blocked` = 0 AND `pending` = 0 
+		AND `readonly` = 0  AND `rel` IN ( %d , %d ) LIMIT 1",
                 intval($owner),
-                intval($_SESSION['visitor_id'])
+                intval($_SESSION['visitor_id']),
+		intval(DIRECTION_OUT),
+		intval(DIRECTION_BOTH)
         );
         if(count($r))
                 return true;
diff --git a/mod/contacts.php b/mod/contacts.php
index 45c0040c8f..7baeb3e14e 100644
--- a/mod/contacts.php
+++ b/mod/contacts.php
@@ -201,7 +201,7 @@ function contacts_content(&$a) {
 			'$name' => $r[0]['name'],
 			'$dir_icon' => $dir_icon,
 			'$alt_text' => $alt_text,
-			'$url' => (($direction != DIRECTION_IN) ? "redir/{$r[0]['id']}" : $r[0]['url'] )
+			'$url' => (($direction != DIRECTION_OUT) ? "redir/{$r[0]['id']}" : $r[0]['url'] )
 
 		));
 
@@ -296,7 +296,7 @@ function contacts_content(&$a) {
 				'$dir_icon' => $dir_icon,
 				'$thumb' => $rr['thumb'], 
 				'$name' => $rr['name'],
-				'$url' => (($direction != DIRECTION_IN) ? "redir/{$rr['id']}" : $rr['url'] )
+				'$url' => (($direction != DIRECTION_OUT) ? "redir/{$rr['id']}" : $rr['url'] )
 			));
 		}
 		$o .= '<div id="contact-edit-end"></div>';
diff --git a/mod/dfrn_poll.php b/mod/dfrn_poll.php
index d0b915acf0..c627c2b418 100644
--- a/mod/dfrn_poll.php
+++ b/mod/dfrn_poll.php
@@ -25,7 +25,7 @@ function dfrn_poll_init(&$a) {
 
 		$r = q("SELECT `contact`.*, `user`.`nickname` 
 			FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
-			WHERE `issued-id` = '%s' LIMIT 1",
+			WHERE `dfrn-id` = '%s' LIMIT 1",
 			dbesc($dfrn_id));
 		if(count($r)) {
 			$s = fetch_url($r[0]['poll'] . '?dfrn_id=' . $dfrn_id . '&type=profile-check');
diff --git a/mod/directory.php b/mod/directory.php
index 8b7f34c415..9cce167605 100644
--- a/mod/directory.php
+++ b/mod/directory.php
@@ -9,6 +9,8 @@ function directory_content(&$a) {
 
 	$tpl .= file_get_contents('view/directory_header.tpl');
 
+	
+
 	$o .= replace_macros($tpl, array(
 		'$search' => $search,
 		'$finding' => (strlen($search) ? '<h4>' . t('Finding: ') . "'" . $search . "'" . '</h4>' : "")
diff --git a/mod/network.php b/mod/network.php
index 982c381f2b..027248bdd3 100644
--- a/mod/network.php
+++ b/mod/network.php
@@ -148,7 +148,8 @@ function network_content(&$a, $update = false) {
 					$template = $wallwall;
 					$commentww = 'ww';
 					// If it is our contact, use a friendly redirect link
-					if($item['owner-link'] == $item['url'])
+					if(($item['owner-link'] == $item['url']) && ($item['rel'] == DIRECTION_IN || $item['rel'] == DIRECTION_BOTH))
+						$owner_url = $redirect_url;
 						$owner_url = $redirect_url;
 
 				}
@@ -179,7 +180,7 @@ function network_content(&$a, $update = false) {
 
 
 	
-			if(($item['contact-uid'] == $_SESSION['uid']) && (strlen($item['dfrn-id'])) && (! $item['self'] ))
+			if(($item['contact-uid'] == $_SESSION['uid']) && ($item['rel] == DIRECTION_IN || $item['rel'] == DIRECTION_BOTH) && (! $item['self'] ))
 				$profile_url = $redirect_url;
 
 			$photo = $item['photo'];
@@ -211,6 +212,7 @@ function network_content(&$a, $update = false) {
 				'$title' => $item['title'],
 				'$body' => bbcode($item['body']),
 				'$ago' => relative_date($item['created']),
+				'$location' => (($item['location']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : ''),
 				'$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
 				'$owner_url' => $owner_url,
 				'$owner_photo' => $owner_photo,
diff --git a/mod/photos.php b/mod/photos.php
index 3f86075750..81f3614b33 100644
--- a/mod/photos.php
+++ b/mod/photos.php
@@ -766,10 +766,9 @@ function photos_content(&$a) {
 
 					$profile_url = $item['url'];
 
-
-					if(local_user() && ($item['contact-uid'] == $_SESSION['uid']) && (strlen($item['dfrn-id'])) && (! $item['self'] ))
+					if(local_user() && ($item['contact-uid'] == $_SESSION['uid']) 
+						&& ($item['rel'] == DIRECTION_IN || $item['rel'] == DIRECTION_BOTH) && (! $item['self'] ))
 						$profile_url = $redirect_url;
-
  
 					$profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
 					$profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
diff --git a/mod/profile.php b/mod/profile.php
index 119b523a68..808ceedb8e 100644
--- a/mod/profile.php
+++ b/mod/profile.php
@@ -64,9 +64,11 @@ function profile_init(&$a) {
 		$profile = $a->argv[1];		
 	}
 	profile_load($a,$which,$profile);
-        $a->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $a->get_baseurl() . '/dfrn_poll/' . $which .'" />';
+        $a->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $a->get_baseurl() . '/dfrn_poll/' . $which .'" />' . "\r\n" ;
 
-	$a->page['htmlhead'] .= "<meta name=\"dfrn-template\" content=\"" . $a->get_baseurl() . "/profile/%s" . "\" />\r\n";
+        $a->page['htmlhead'] .= '<meta name="dfrn-template" content="' . $a->get_baseurl() . "/profile/%s" . '" />' . "\r\n" ;
+        $a->page['htmlhead'] .= '<meta name="dfrn-global-visibility" content="' . (($a->profile['net-publish']) ? 'true' : 'false') . '" />' . "\r\n" ;
+  
 	
 	$dfrn_pages = array('request', 'confirm', 'notify', 'poll');
 	foreach($dfrn_pages as $dfrn)
@@ -99,9 +101,11 @@ function profile_content(&$a, $update = false) {
 		if(count($r))
 			$contact = $r[0];
 	}
-	if(local_user()) {
-		$contact_id = $_SESSION['cid'];
-		$contact = $a->contact;
+	else {
+		if(local_user()) {
+			$contact_id = $_SESSION['cid'];
+			$contact = $a->contact;
+		}
 	}
 
 	if($update) {
@@ -261,7 +265,8 @@ function profile_content(&$a, $update = false) {
 			// This is my profile but I'm not the author of this post/comment. If it's somebody that's a fan or mutual friend,
 			// I can go directly to their profile as an authenticated guest.
 
-			if(local_user() && ($item['contact-uid'] == $_SESSION['uid']) && (strlen($item['dfrn-id'])) && (! $item['self'] ))
+			if(local_user() && ($item['contact-uid'] == $_SESSION['uid']) 
+				&& ($item['rel'] == DIRECTION_IN || $item['rel'] == DIRECTION_BOTH) && (! $item['self'] ))
 				$profile_url = $redirect_url;
 
 			// FIXME tryng to solve the mishmash of profile photos. 
@@ -294,6 +299,7 @@ function profile_content(&$a, $update = false) {
 				'$title' => $item['title'],
 				'$body' => bbcode($item['body']),
 				'$ago' => relative_date($item['created']),
+				'$location' => (($item['location']) ? '<a target="map" href="http://maps.google.com/?q=' . urlencode($item['location']) . '">' . $item['location'] . '</a>' : ''),
 				'$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
 				'$drop' => $drop,
 				'$comment' => $comment
diff --git a/mod/profiles.php b/mod/profiles.php
index 850a4b8ce4..71e037718e 100644
--- a/mod/profiles.php
+++ b/mod/profiles.php
@@ -4,7 +4,7 @@
 function profiles_post(&$a) {
 
 	if(! local_user()) {
-		notice( "Permission denied." . EOL);
+		notice( t('Permission denied.') . EOL);
 		return;
 	}
 
@@ -16,14 +16,14 @@ function profiles_post(&$a) {
 			intval($_SESSION['uid'])
 		);
 		if(! count($orig)) {
-			$_SESSION['sysmsg'] .= "Profile not found." . EOL;
+			notice( t('Profile not found.') . EOL);
 			return;
 		}
 		$is_default = (($orig[0]['is-default']) ? 1 : 0);
 
 		$profile_name = notags(trim($_POST['profile_name']));
 		if(! strlen($profile_name)) {
-			$a->$_SESSION['sysmsg'] .= "Profile Name is required." . EOL;
+			notify( t('Profile Name is required.') . EOL);
 			return;
 		}
 	
@@ -74,6 +74,9 @@ function profiles_post(&$a) {
 		$education = escape_tags(trim($_POST['education']));
 		if(x($_POST,'profile_in_directory'))
 			$publish = (($_POST['profile_in_directory'] == 1) ? 1: 0);
+		if(x($_POST,'profile_in_netdirectory'))
+			$net_publish = (($_POST['profile_in_netdirectory'] == 1) ? 1: 0);
+
 
 		$r = q("UPDATE `profile` 
 			SET `profile-name` = '%s',
@@ -130,14 +133,15 @@ function profiles_post(&$a) {
 		);
 
 		if($r)
-			$_SESSION['sysmsg'] .= "Profile updated." . EOL;
+			notice( t('Profile updated.') . EOL);
 
 
 		if($is_default) {
 			$r = q("UPDATE `profile` 
-			SET `publish` = %d
+			SET `publish` = %d, `net-publish` = %d
 			WHERE `id` = %d AND `uid` = %d LIMIT 1",
 			intval($publish),
+			intval($net_publish),
 			intval($a->argv[1]),
 			intval($_SESSION['uid'])
 
@@ -149,11 +153,15 @@ function profiles_post(&$a) {
 				intval($_SESSION['uid'])
 			);
 		}
-
+		if($is_default) {
+			// Update global directory in background
+			$php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
+			$url = $_SESSION['my_url'];
+			if($url && strlen(get_config('system','directory_submit_url')))
+				proc_close(proc_open("\"$php_path\" \"include/directory.php\" \"$url\" &",
+					array(),$foo));
+		}
 	}
-
-
-
 }
 
 
@@ -161,7 +169,7 @@ function profiles_post(&$a) {
 
 function profiles_content(&$a) {
 	if(! local_user()) {
-		$_SESSION['sysmsg'] .= "Unauthorised." . EOL;
+		notice( t('Permission denied.') . EOL);
 		return;
 	}
 
@@ -171,7 +179,7 @@ function profiles_content(&$a) {
 			intval($_SESSION['uid'])
 		);
 		if(! count($r)) {
-			$_SESSION['sysmsg'] .= "Profile not found." . EOL;
+			notice( t('Profile not found.') . EOL);
 			goaway($a->get_baseurl() . '/profiles');
 			return; // NOTREACHED
 		}
@@ -187,7 +195,7 @@ function profiles_content(&$a) {
 			intval($a->argv[2])
 		);
 		if($r)
-			notice("Profile deleted." . EOL);
+			notice( t('Profile deleted.') . EOL);
 
 		goaway($a->get_baseurl() . '/profiles');
 		return; // NOTREACHED
@@ -203,7 +211,7 @@ function profiles_content(&$a) {
 			intval($_SESSION['uid']));
 		$num_profiles = count($r0);
 
-		$name = "Profile-" . ($num_profiles + 1);
+		$name = t('Profile-') . ($num_profiles + 1);
 
 		$r1 = q("SELECT `name`, `photo`, `thumb` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
 			intval($_SESSION['uid']));
@@ -221,7 +229,7 @@ function profiles_content(&$a) {
 			intval($_SESSION['uid']),
 			dbesc($name)
 		);
-		$_SESSION['sysmsg'] .= "New profile created." . EOL;
+		notice( t('New profile created.') . EOL);
 		if(count($r3) == 1)
 			goaway($a->get_baseurl() . '/profiles/' . $r3[0]['id']);
 		goaway($a->get_baseurl() . '/profiles');
@@ -233,13 +241,13 @@ function profiles_content(&$a) {
 			intval($_SESSION['uid']));
 		$num_profiles = count($r0);
 
-		$name = "Profile-" . ($num_profiles + 1);
+		$name = t('Profile-') . ($num_profiles + 1);
 		$r1 = q("SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d LIMIT 1",
 			intval($_SESSION['uid']),
 			intval($a->argv[2])
 		);
 		if(! count($r1)) {
-			notice("Profile unavailable to clone." . EOL);
+			notice( t('Profile unavailable to clone.') . EOL);
 			return;
 		}
 		unset($r1[0]['id']);
@@ -259,7 +267,7 @@ function profiles_content(&$a) {
 			intval($_SESSION['uid']),
 			dbesc($name)
 		);
-		$_SESSION['sysmsg'] .= "New profile created." . EOL;
+		notice( t('New profile created.') . EOL);
 		if(count($r3) == 1)
 			goaway($a->get_baseurl() . '/profiles/' . $r3[0]['id']);
 	goaway($a->get_baseurl() . '/profiles');
@@ -273,7 +281,7 @@ function profiles_content(&$a) {
 			intval($_SESSION['uid'])
 		);
 		if(! count($r)) {
-			$_SESSION['sysmsg'] .= "Profile not found." . EOL;
+			notice( t('Profile not found.') . EOL);
 			return;
 		}
 
@@ -289,6 +297,18 @@ function profiles_content(&$a) {
 			'$no_selected' => (($r[0]['publish'] == 0) ? " checked=\"checked\" " : "")
 		));
 
+		if(strlen(get_config('system','directory_submit_url'))) {
+			$opt_tpl = file_get_contents("view/profile-in-netdir.tpl");
+
+			$profile_in_net_dir = replace_macros($opt_tpl,array(
+				'$yes_selected' => (($r[0]['net-publish']) ? " checked=\"checked\" " : ""),
+				'$no_selected' => (($r[0]['net-publish'] == 0) ? " checked=\"checked\" " : "")
+			));
+		}
+		else
+			$profile_in_net_dir = '';
+
+
 		$opt_tpl = file_get_contents("view/profile-hide-friends.tpl");
 		$hide_friends = replace_macros($opt_tpl,array(
 			'$yes_selected' => (($r[0]['hide-friends']) ? " checked=\"checked\" " : ""),
@@ -310,7 +330,7 @@ function profiles_content(&$a) {
 			'$baseurl' => $a->get_baseurl(),
 			'$profile_id' => $r[0]['id'],
 			'$profile_name' => $r[0]['profile-name'],
-			'$default' => (($is_default) ? "<p id=\"profile-edit-default-desc\">This is your <strong>public</strong> profile.<br />It <strong>may</strong> be visible to anybody using the internet.</p>" : ""),
+			'$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>' : ""),
 			'$name' => $r[0]['name'],
 			'$dob' => dob($r[0]['dob']),
 			'$hide_friends' => $hide_friends,
@@ -319,7 +339,7 @@ function profiles_content(&$a) {
 			'$region' => $r[0]['region'],
 			'$postal_code' => $r[0]['postal-code'],
 			'$country_name' => $r[0]['country-name'],
-			'$age' => ((intval($r[0]['dob'])) ? '(Age: '. age($r[0]['dob'],$a->user['timezone'],$a->user['timezone']) . ')' : ''),
+			'$age' => ((intval($r[0]['dob'])) ? '(' . t('Age: ') . age($r[0]['dob'],$a->user['timezone'],$a->user['timezone']) . ')' : ''),
 			'$gender' => gender_selector($r[0]['gender']),
 			'$marital' => marital_selector($r[0]['marital']),
 			'$sexual' => sexpref_selector($r[0]['sexual']),
@@ -336,7 +356,8 @@ function profiles_content(&$a) {
 			'$work' => $r[0]['work'],
 			'$education' => $r[0]['education'],
 			'$contact' => $r[0]['contact'],
-			'$profile_in_dir' => (($is_default) ? $profile_in_dir : '')
+			'$profile_in_dir' => (($is_default) ? $profile_in_dir : ''),
+			'$profile_in_net_dir' => (($is_default) ? $profile_in_net_dir : '')
 		));
 
 		return $o;
diff --git a/mod/redir.php b/mod/redir.php
index ee15a18d4b..ea1aec6e90 100644
--- a/mod/redir.php
+++ b/mod/redir.php
@@ -4,7 +4,7 @@ function redir_init(&$a) {
 
 	if((! local_user()) || (! ($a->argc == 2)) || (! intval($a->argv[1])))
 		goaway($a->get_baseurl());
-	$r = q("SELECT `dfrn-id`, `poll` FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
+	$r = q("SELECT `issued-id`, `poll` FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
 		intval($a->argv[1]),
 		intval($_SESSION['uid']));
 	if(! count($r))
@@ -12,9 +12,9 @@ function redir_init(&$a) {
 	q("INSERT INTO `profile_check` ( `uid`, `dfrn_id`, `expire`)
 		VALUES( %d, '%s', %d )",
 		intval($_SESSION['uid']),
-		dbesc($r[0]['dfrn-id']),
-		intval(time() + 30));
-	goaway ($r[0]['poll'] . '?dfrn_id=' . $r[0]['dfrn-id'] . '&type=profile');
+		dbesc($r[0]['issued-id']),
+		intval(time() + 45));
+	goaway ($r[0]['poll'] . '?dfrn_id=' . $r[0]['issued-id'] . '&type=profile');
 
 	
 	
diff --git a/view/directory_header.tpl b/view/directory_header.tpl
index 8fc1d2cfcc..c4217ac488 100644
--- a/view/directory_header.tpl
+++ b/view/directory_header.tpl
@@ -1,5 +1,7 @@
 <h1>Site Directory</h1>
 
+<ul><li><div id="global-directory-link"><a href="http://dir.dfrn.org">Global Community Directory</a></div></li></ul>
+
 $finding
 
 <div id="directory-search-wrapper">
diff --git a/view/head.tpl b/view/head.tpl
index d3c17d9262..dd6162f09e 100644
--- a/view/head.tpl
+++ b/view/head.tpl
@@ -8,100 +8,4 @@
 <script type="text/javascript" src="$baseurl/include/jquery.js" ></script>
 <script type="text/javascript" src="$baseurl/include/main.js" ></script>
 
-<script type="text/javascript">
-
-	var src = null;
-	var prev = null;
-	var livetime = null;
-	var msie = false;
-
-	$(document).ready(function() {
-		$.ajaxSetup({cache: false});
-		msie = $.browser.msie ;
- 		NavUpdate(); 
-
-
-
-	});
-
-	function NavUpdate() {
-
-		if($('#live-network').length) { src = 'network'; liveUpdate(); }
-		if($('#live-profile').length) { src = 'profile'; liveUpdate(); }
-
-		$.get("ping",function(data) {
-			$(data).find('result').each(function() {
-				var net = $(this).find('net').text();
-				if(net == 0) { net = ''; }
-				$('#net-update').html(net);
-				var home = $(this).find('home').text();
-				if(home == 0) { home = ''; }
-				$('#home-update').html(home);
-				var mail = $(this).find('mail').text();
-				if(mail == 0) { mail = ''; }
-				$('#mail-update').html(mail);
-				var intro = $(this).find('intro').text();
-				if(intro == 0) { intro = ''; }
-				$('#notify-update').html(intro);
-			});
-		}) ;
-		setTimeout(NavUpdate,30000);
-
-	}
-
-	function liveUpdate() {
-		if(src == null) { return; }
-		if($('.comment-edit-text-full').length) {
-			livetime = setTimeout(liveUpdate, 10000);
-			return;
-		}
-		prev = 'live-' + src;
-
-		$.get('update_' + src + '?msie=' + ((msie) ? 1 : 0),function(data) {
-			$('.wall-item-outside-wrapper',data).each(function() {
-				var ident = $(this).attr('id');
-				if($('#' + ident).length == 0) { 
-                                        $('img',this).each(function() {
-                                                $(this).attr('src',$(this).attr('dst'));
-                                        });
-					$('#' + prev).after($(this));
-				}
-				else { 
-
-					$('#' + ident + ' ' + '.wall-item-ago').replaceWith($(this).find('.wall-item-ago')); 
-					$('#' + ident + ' ' + '.wall-item-comment-wrapper').replaceWith($(this).find('.wall-item-comment-wrapper'));
-                                        $('#' + ident + ' ' + '.my-comment-photo').each(function() {
-                                                $(this).attr('src',$(this).attr('dst'));
-                                        });
-
-
-				}
-				prev = ident; 
-			});
-		});
-
-	}
-
-	function confirmDelete() { 
-		return confirm("Delete this item?");
-	}
-
-	function imgbright(node) {
-		$(node).attr("src",$(node).attr("src").replace('hide','show'));
-		$(node).css('width',24);
-		$(node).css('height',24);
-	}
-
-	function imgdull(node) {
-		$(node).attr("src",$(node).attr("src").replace('show','hide'));
-		$(node).css('width',16);
-		$(node).css('height',16);
-	}
-
-
-
-
-
-
-</script>
 
diff --git a/view/htconfig.tpl b/view/htconfig.tpl
index f555ace831..42c32da2e7 100644
--- a/view/htconfig.tpl
+++ b/view/htconfig.tpl
@@ -42,3 +42,7 @@ $a->config['max_import_size'] = 65535;
 // Location of PHP command line processor
 
 $a->config['php_path'] = '$phpath';
+
+// Location of global directory submission page.
+
+$a->config['system']['directory_submit_url'] = 'http://dir.dfrn.org/submit';
\ No newline at end of file
diff --git a/view/profile-in-netdir.tpl b/view/profile-in-netdir.tpl
new file mode 100644
index 0000000000..d5a320a3f9
--- /dev/null
+++ b/view/profile-in-netdir.tpl
@@ -0,0 +1,16 @@
+<p id="profile-in-directory">
+Publish this profile in global social directory? 
+</p>
+
+		<div id="profile-in-netdir-yes-wrapper">
+		<label id="profile-in-netdir-yes-label" for="profile-in-netdir-yes">Yes</label>
+		<input type="radio" name="profile_in_netdirectory" id="profile-in-netdir-yes" $yes_selected value="1" />
+
+		<div id="profile-in-netdir-break" ></div>	
+		</div>
+		<div id="profile-in-netdir-no-wrapper">
+		<label id="profile-in-netdir-no-label" for="profile-in-netdir-no">No</label>
+		<input type="radio" name="profile_in_netdirectory" id="profile-in-netdir-no" $no_selected value="0"  />
+
+		<div id="profile-in-netdir-end"></div>
+		</div>
diff --git a/view/profile_edit.tpl b/view/profile_edit.tpl
index 44ca3922b8..a28471325f 100644
--- a/view/profile_edit.tpl
+++ b/view/profile_edit.tpl
@@ -44,6 +44,8 @@ $dob $age
 
 $profile_in_dir
 
+$profile_in_net_dir
+
 $hide_friends
 
 <div class="profile-edit-submit-wrapper" >
diff --git a/view/theme/default/style.css b/view/theme/default/style.css
index 59ec1dd1e8..4c386afa61 100644
--- a/view/theme/default/style.css
+++ b/view/theme/default/style.css
@@ -501,6 +501,8 @@ input#dfrn-url {
 #profile-edit-religion,
 #profile-in-dir-yes,
 #profile-in-dir-no,
+#profile-in-netdir-yes,
+#profile-in-netdir-no,
 #hide-friends-yes,
 #hide-friends-no {
 	float: left;
@@ -509,6 +511,8 @@ input#dfrn-url {
 
 #profile-in-dir-yes-label, 
 #profile-in-dir-no-label,
+#profile-in-netdir-yes-label, 
+#profile-in-netdir-no-label,
 #hide-friends-yes-label,
 #hide-friends-no-label {
 	margin-left: 125px;
@@ -537,6 +541,8 @@ input#dfrn-url {
 #profile-edit-homepage-end,
 #profile-in-dir-break, 
 #profile-in-dir-end,
+#profile-in-netdir-break, 
+#profile-in-netdir-end,
 #hide-friends-break,
 #hide-friends-end {
 	clear: both;
@@ -829,7 +835,7 @@ input#dfrn-url {
 }
 
 #directory-search-wrapper {
-	margin-left: 350px;
+	margin-top: 20px;
 	margin-right: 20px;
 	margin-bottom: 50px;
 }
diff --git a/view/wall_item.tpl b/view/wall_item.tpl
index 84d0f28791..c646bbee33 100644
--- a/view/wall_item.tpl
+++ b/view/wall_item.tpl
@@ -8,6 +8,7 @@
 		<div class="wall-item-wrapper" id="wall-item-wrapper-$id" >
 			<a href="$profile_url" title="View $name's profile" class="wall-item-name-link"><span class="wall-item-name" id="wall-item-name-$id" >$name</span></a>
 			<div class="wall-item-ago"  id="wall-item-ago-$id">$ago</div>
+			<div class="wall-item-location" id="wall-item-location-$id">$location</div>
 		</div>
 		<div class="wall-item-content" id="wall-item-content-$id" >
 			<div class="wall-item-title" id="wall-item-title-$id">$title</div>
diff --git a/view/wallwall_item.tpl b/view/wallwall_item.tpl
index 4704c0c7c7..30970f6aea 100644
--- a/view/wallwall_item.tpl
+++ b/view/wallwall_item.tpl
@@ -11,6 +11,8 @@
 	<div class="wall-item-wrapper" id="wall-item-wrapper-$id" >
 		<a href="$profile_url" title="View $name's profile" class="wall-item-name-link"><span class="wall-item-name" id="wall-item-name-$id" >$name</span></a> to <a href="$owner_url" title="View $owner_name's profile" class="wall-item-name-link"><span class="wall-item-name" id="wall-item-ownername-$id">$owner_name</span></a> via Wall-To-Wall:<br />
 		<div class="wall-item-ago"  id="wall-item-ago-$id">$ago</div>
+		<div class="wall-item-location" id="wall-item-location-$id">$location</div>
+
 	</div>
 	<div class="wall-item-content" id="wall-item-content-$id" >
 		<div class="wall-item-title" id="wall-item-title-$id">$title</div>