From 7b58de743a5b0694792e744a004a37584a3c8ccb Mon Sep 17 00:00:00 2001
From: friendica <info@friendica.com>
Date: Tue, 15 Nov 2011 23:12:56 -0800
Subject: [PATCH 01/10] add a few more sql indexes

---
 boot.php             | 2 +-
 database.sql         | 9 ++++++++-
 include/diaspora.php | 4 +++-
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/boot.php b/boot.php
index 93b8c01063..0e9472c001 100644
--- a/boot.php
+++ b/boot.php
@@ -11,7 +11,7 @@ require_once('include/cache.php');
 define ( 'FRIENDIKA_PLATFORM',     'Friendica');
 define ( 'FRIENDIKA_VERSION',      '2.3.1166' );
 define ( 'DFRN_PROTOCOL_VERSION',  '2.22'    );
-define ( 'DB_UPDATE_VERSION',      1103      );
+define ( 'DB_UPDATE_VERSION',      1104      );
 
 define ( 'EOL',                    "<br />\r\n"     );
 define ( 'ATOM_TIME',              'Y-m-d\TH:i:s\Z' );
diff --git a/database.sql b/database.sql
index 58b81b0ac5..924cc49b23 100644
--- a/database.sql
+++ b/database.sql
@@ -113,7 +113,8 @@ CREATE TABLE IF NOT EXISTS `contact` (
   KEY `issued-id` (`issued-id`),
   KEY `dfrn-id` (`dfrn-id`),
   KEY `blocked` (`blocked`),
-  KEY `readonly` (`readonly`)  
+  KEY `readonly` (`readonly`),
+  KEY `pending` (`pending`)  
 ) ENGINE=MyISAM  DEFAULT CHARSET=utf8;
 
 -- --------------------------------------------------------
@@ -245,8 +246,10 @@ CREATE TABLE IF NOT EXISTS `item` (
   KEY `origin`  (`origin`),
   KEY `last-child` (`last-child`),
   KEY `unseen` (`unseen`),
+  KEY `wall` (`wall`),
   FULLTEXT KEY `title` (`title`),
   FULLTEXT KEY `body` (`body`),
+  FULLTEXT KEY `tag` (`tag`),
   FULLTEXT KEY `allow_cid` (`allow_cid`),
   FULLTEXT KEY `allow_gid` (`allow_gid`),
   FULLTEXT KEY `deny_cid` (`deny_cid`),
@@ -441,6 +444,10 @@ CREATE TABLE IF NOT EXISTS `user` (
   PRIMARY KEY (`uid`), 
   KEY `nickname` (`nickname`),
   KEY `account_expired` (`account_expired`),
+  KEY `hidewall` (`hidewall`),
+  KEY `blockwall` (`blockwall`),
+  KEY `blocked` (`blocked`),
+  KEY `verified` (`verified`),
   KEY `login_date` (`login_date`)
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
diff --git a/include/diaspora.php b/include/diaspora.php
index ff0c0c0d79..36457655e5 100644
--- a/include/diaspora.php
+++ b/include/diaspora.php
@@ -455,7 +455,9 @@ function diaspora_request($importer,$xml) {
 				intval($importer['uid'])
 			);
 
-			if(count($self)) {
+			// they are not CONTACT_IS_FOLLOWER anymore but that's what we have in the array
+
+			if(count($self) && $contact['rel'] == CONTACT_IS_FOLLOWER) {
 
 				$arr = array();
 				$arr['uri'] = $arr['parent-uri'] = item_new_uri($a->get_hostname(), $importer['uid']); 

From 306a69b5f4b544841f312ed5c160ade19356689a Mon Sep 17 00:00:00 2001
From: friendica <info@friendica.com>
Date: Tue, 15 Nov 2011 23:14:25 -0800
Subject: [PATCH 02/10] update

---
 update.php | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/update.php b/update.php
index 362935c384..14d68ea12c 100644
--- a/update.php
+++ b/update.php
@@ -1,6 +1,6 @@
 <?php
 
-define( 'UPDATE_VERSION' , 1103 );
+define( 'UPDATE_VERSION' , 1104 );
 
 /**
  *
@@ -884,6 +884,15 @@ function update_1102() {
 }
 
 
-
+function update_1103() {
+	q("ALTER TABLE `item` ADD INDEX ( `wall` ) ");
+	q("ALTER TABLE `item` ADD FULLTEXT ( `tag` ) "); 
+	q("ALTER TABLE `contact` ADD INDEX ( `pending` ) ");
+	q("ALTER TABLE `user` ADD INDEX ( `hidewall` ) ");
+	q("ALTER TABLE `user` ADD INDEX ( `blockwall` ) ");
+	q("ALTER TABLE `user` ADD INDEX ( `blocked` ) ");
+	q("ALTER TABLE `user` ADD INDEX ( `verified` ) ");
+
+}
 
 

From ef8b5bc682b9d5b856f1d5b5ef3202ea95ed1780 Mon Sep 17 00:00:00 2001
From: Fabio Comuni <fabrix.xm@gmail.com>
Date: Wed, 16 Nov 2011 11:27:20 +0100
Subject: [PATCH 03/10] fix localize item tag

---
 include/conversation.php | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/include/conversation.php b/include/conversation.php
index 7f9627a7d8..9ac251e460 100644
--- a/include/conversation.php
+++ b/include/conversation.php
@@ -112,10 +112,9 @@ function localize_item(&$item){
 		
 		$parsedobj = parse_xml_string($xmlhead.$item['object']);
 		
-		$tag = sprintf('#[url=%s]%s[/url]', $parsedobj->link, $parsedobj->content);
+		$tag = sprintf('#[url=%s]%s[/url]', $parsedobj->id, $parsedobj->content);
 		$item['body'] = sprintf( t('%1$s tagged %2$s\'s %3$s with %4$s'), $author, $objauthor, $plink, $tag );
 		
-		
 	}
 
 }

From b4218614ed4a5652ecb5f15df9d20fc530abb4c3 Mon Sep 17 00:00:00 2001
From: friendica <info@friendica.com>
Date: Wed, 16 Nov 2011 04:15:14 -0800
Subject: [PATCH 04/10] change hide profile setting text

---
 mod/settings.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mod/settings.php b/mod/settings.php
index 6cc80e3a61..a073a5e984 100644
--- a/mod/settings.php
+++ b/mod/settings.php
@@ -644,7 +644,7 @@ function settings_content(&$a) {
 	));
 
 	$hide_wall = replace_macros($opt_tpl,array(
-			'$field' 	=> array('hidewall',  t('Hide profile details and all your messages from unknown viewers?'), $a->user['hidewall'], '', array(t('No'),t('Yes'))),
+			'$field' 	=> array('hidewall',  t('Hide your profile details from unknown viewers?'), $a->user['hidewall'], '', array(t('No'),t('Yes'))),
 
 	));
 

From ede25aabce2e25ce8134157853ff4c7f45e2f784 Mon Sep 17 00:00:00 2001
From: friendica <info@friendica.com>
Date: Wed, 16 Nov 2011 14:23:06 -0800
Subject: [PATCH 05/10] check all attribute names for validity

---
 boot.php                      |  2 +-
 library/HTML5/TreeBuilder.php | 10 +++++++---
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/boot.php b/boot.php
index 0e9472c001..7d9337b2ed 100644
--- a/boot.php
+++ b/boot.php
@@ -9,7 +9,7 @@ require_once('include/nav.php');
 require_once('include/cache.php');
 
 define ( 'FRIENDIKA_PLATFORM',     'Friendica');
-define ( 'FRIENDIKA_VERSION',      '2.3.1166' );
+define ( 'FRIENDIKA_VERSION',      '2.3.1167' );
 define ( 'DFRN_PROTOCOL_VERSION',  '2.22'    );
 define ( 'DB_UPDATE_VERSION',      1104      );
 
diff --git a/library/HTML5/TreeBuilder.php b/library/HTML5/TreeBuilder.php
index 10d446d1ea..578e73682b 100644
--- a/library/HTML5/TreeBuilder.php
+++ b/library/HTML5/TreeBuilder.php
@@ -3041,9 +3041,13 @@ class HTML5_TreeBuilder {
 
         if (!empty($token['attr'])) {
             foreach($token['attr'] as $attr) {
-				// mike@macgirvin.com 2011-10-21, stray double quotes and/or numeric tags cause everything to abort
-				$attr['name'] = str_replace('"','',$attr['name']);
-                if($attr['name'] && (!$el->hasAttribute($attr['name'])) && (! is_numeric($attr['name']))) {
+
+				// mike@macgirvin.com 2011-11-17, check attribute name for
+				// validity (ignoring extenders and combiners) as illegal chars in names
+				// causes everything to abort
+
+ 				$valid = preg_match('/^[a-zA-Z\_\:]([\-a-zA-Z0-9\_\:\.]+$)/',$attr['name'],$matches);
+                if($attr['name'] && (!$el->hasAttribute($attr['name'])) && ($valid)) {
                     $el->setAttribute($attr['name'], $attr['value']);
                 }
             }

From c9846b745dfe2a4c20ffe4e1f48bb18da3886fd4 Mon Sep 17 00:00:00 2001
From: friendica <info@friendica.com>
Date: Wed, 16 Nov 2011 17:09:58 -0800
Subject: [PATCH 06/10] allow dup tag names with different urls

---
 include/items.php | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/include/items.php b/include/items.php
index b8e258d3f0..ecf19a86ed 100644
--- a/include/items.php
+++ b/include/items.php
@@ -1469,10 +1469,11 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
 							continue;
 
 						// extract tag, if not duplicate, add to parent item
-						if($xo->content) {
-							if(! (stristr($r[0]['tag'],trim($xo->content)))) {
+						if($xo->id && $xo->content) {
+							$newtag = '#[url=' . $xo->id . ']'. $xo->content . '[/url]';
+							if(! (stristr($r[0]['tag'],$newtag))) {
 								q("UPDATE item SET tag = '%s' WHERE id = %d LIMIT 1",
-									dbesc($r[0]['tag'] . (strlen($r[0]['tag']) ? ',' : '') . '#[url=' . $xo->id . ']'. $xo->content . '[/url]'),
+									dbesc($r[0]['tag'] . (strlen($r[0]['tag']) ? ',' : '') . $newtag),
 									intval($r[0]['id'])
 								);
 							}
@@ -2011,15 +2012,17 @@ function local_delivery($importer,$data) {
 					if(($xt->type == ACTIVITY_OBJ_NOTE) && ($xt->id == $r[0]['uri'])) {
 
 						// extract tag, if not duplicate, and this user allows tags, add to parent item						
-						if($xo->content) {
 
-							if(! (stristr($r[0]['tag'],trim($xo->content)))) {
+						if($xo->id && $xo->content) {
+							$newtag = '#[url=' . $xo->id . ']'. $xo->content . '[/url]';
+
+							if(! (stristr($r[0]['tag'],$newtag))) {
 								$i = q("SELECT `blocktags` FROM `user` where `uid` = %d LIMIT 1",
 									intval($importer['importer_uid'])
 								);
 								if(count($i) && ! ($i[0]['blocktags'])) {
 									q("UPDATE item SET tag = '%s' WHERE id = %d LIMIT 1",
-										dbesc($r[0]['tag'] . (strlen($r[0]['tag']) ? ',' : '') . '#[url=' . $xo->id . ']'. $xo->content . '[/url]'),
+										dbesc($r[0]['tag'] . (strlen($r[0]['tag']) ? ',' : '') . $newtag),
 										intval($r[0]['id'])
 									);
 								}

From 02281be0c3b19bcab3ae3a96475846104af11e92 Mon Sep 17 00:00:00 2001
From: Fabio Comuni <fabrix.xm@gmail.com>
Date: Thu, 17 Nov 2011 13:40:11 +0100
Subject: [PATCH 07/10] oembed: don't try to fetch media files and add Accept
 request header to fetch_url

---
 include/network.php | 10 +++++++++-
 include/oembed.php  | 34 ++++++++++++++++++++--------------
 2 files changed, 29 insertions(+), 15 deletions(-)

diff --git a/include/network.php b/include/network.php
index a9ee3f0a54..e89eb94da2 100644
--- a/include/network.php
+++ b/include/network.php
@@ -5,7 +5,7 @@
 // results. 
 
 if(! function_exists('fetch_url')) {
-function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0) {
+function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_content=Null) {
 
 	$a = get_app();
 
@@ -14,9 +14,17 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0) {
 		return false;
 
 	@curl_setopt($ch, CURLOPT_HEADER, true);
+	
+	if (!is_null($accept_content)){
+		curl_setopt($ch,CURLOPT_HTTPHEADER, array (
+			"Accept: "+$accept_content
+		));
+	}
+	
 	@curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
 	@curl_setopt($ch, CURLOPT_USERAGENT, "Friendika");
 
+
 	if(intval($timeout)) {
 		@curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
 	}
diff --git a/include/oembed.php b/include/oembed.php
index 7c0da45940..118f7fa4a3 100644
--- a/include/oembed.php
+++ b/include/oembed.php
@@ -13,24 +13,30 @@ function oembed_replacecb($matches){
 function oembed_fetch_url($embedurl){
 	
 	$txt = Cache::get($embedurl);
+
+	$noexts = array("mp3","mp4","ogg","ogv","oga","ogm","webm");
+	$ext = pathinfo(strtolower($embedurl),PATHINFO_EXTENSION);
+	
 				
 	if(is_null($txt)){
 		$txt = "";
 		
-		// try oembed autodiscovery
-		$redirects = 0;
-		$html_text = fetch_url($embedurl, false, $redirects, 15);
-		if($html_text){
-			$dom = @DOMDocument::loadHTML($html_text);
-			if ($dom){
-				$xpath = new DOMXPath($dom);
-				$attr = "oembed";
-			
-				$xattr = oe_build_xpath("class","oembed");
-				$entries = $xpath->query("//link[@type='application/json+oembed']");
-				foreach($entries as $e){
-					$href = $e->getAttributeNode("href")->nodeValue;
-					$txt = fetch_url($href);
+		if (!in_array($ext, $noexts)){
+			// try oembed autodiscovery
+			$redirects = 0;
+			$html_text = fetch_url($embedurl, false, $redirects, 15, "text/*");
+			if($html_text){
+				$dom = @DOMDocument::loadHTML($html_text);
+				if ($dom){
+					$xpath = new DOMXPath($dom);
+					$attr = "oembed";
+				
+					$xattr = oe_build_xpath("class","oembed");
+					$entries = $xpath->query("//link[@type='application/json+oembed']");
+					foreach($entries as $e){
+						$href = $e->getAttributeNode("href")->nodeValue;
+						$txt = fetch_url($href);
+					}
 				}
 			}
 		}

From fa4742e6eec1850f1bb53e38379cf2aac650cc3b Mon Sep 17 00:00:00 2001
From: friendica <info@friendica.com>
Date: Thu, 17 Nov 2011 15:42:56 -0800
Subject: [PATCH 08/10] comment boxes not work in alternate languages

---
 boot.php  | 2 +-
 index.php | 8 ++++++--
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/boot.php b/boot.php
index 7d9337b2ed..74956e9f6a 100644
--- a/boot.php
+++ b/boot.php
@@ -9,7 +9,7 @@ require_once('include/nav.php');
 require_once('include/cache.php');
 
 define ( 'FRIENDIKA_PLATFORM',     'Friendica');
-define ( 'FRIENDIKA_VERSION',      '2.3.1167' );
+define ( 'FRIENDIKA_VERSION',      '2.3.1168' );
 define ( 'DFRN_PROTOCOL_VERSION',  '2.22'    );
 define ( 'DB_UPDATE_VERSION',      1104      );
 
diff --git a/index.php b/index.php
index 78ceb6d770..e43d7332de 100644
--- a/index.php
+++ b/index.php
@@ -75,8 +75,6 @@ $a->timezone = (($default_timezone) ? $default_timezone : 'UTC');
 
 date_default_timezone_set($a->timezone);
 
-$a->init_pagehead();
-
 session_start();
 
 /**
@@ -95,6 +93,12 @@ if((x($_SESSION,'language')) && ($_SESSION['language'] !== $lang)) {
 	load_translation_table($lang);
 }
 
+/*
+ * Create the page head after setting the language
+ *
+ */
+
+$a->init_pagehead();
 
 /**
  *

From d53db63d41d2f253c9aff806d9830167c9dd7a8d Mon Sep 17 00:00:00 2001
From: friendica <info@friendica.com>
Date: Fri, 18 Nov 2011 21:55:00 -0800
Subject: [PATCH 09/10] forum split delivery flag

---
 boot.php     | 4 ++--
 database.sql | 2 ++
 mod/item.php | 4 ++--
 update.php   | 9 ++++++++-
 4 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/boot.php b/boot.php
index 74956e9f6a..61383f0afd 100644
--- a/boot.php
+++ b/boot.php
@@ -9,9 +9,9 @@ require_once('include/nav.php');
 require_once('include/cache.php');
 
 define ( 'FRIENDIKA_PLATFORM',     'Friendica');
-define ( 'FRIENDIKA_VERSION',      '2.3.1168' );
+define ( 'FRIENDIKA_VERSION',      '2.3.1169' );
 define ( 'DFRN_PROTOCOL_VERSION',  '2.22'    );
-define ( 'DB_UPDATE_VERSION',      1104      );
+define ( 'DB_UPDATE_VERSION',      1105      );
 
 define ( 'EOL',                    "<br />\r\n"     );
 define ( 'ATOM_TIME',              'Y-m-d\TH:i:s\Z' );
diff --git a/database.sql b/database.sql
index 924cc49b23..98067d8d60 100644
--- a/database.sql
+++ b/database.sql
@@ -226,6 +226,7 @@ CREATE TABLE IF NOT EXISTS `item` (
   `unseen` tinyint(1) NOT NULL DEFAULT '1',
   `deleted` tinyint(1) NOT NULL DEFAULT '0',
   `origin` tinyint(1) NOT NULL DEFAULT '0',
+  `forum_mode` tinyint(1) NOT NULL DEFAULT '0',
   `last-child` tinyint(1) unsigned NOT NULL DEFAULT '1',
   PRIMARY KEY (`id`),
   KEY `guid` (`guid`),
@@ -244,6 +245,7 @@ CREATE TABLE IF NOT EXISTS `item` (
   KEY `starred` (`starred`),
   KEY `deleted` (`deleted`),
   KEY `origin`  (`origin`),
+  KEY `forum_mode` (`forum_mode`),
   KEY `last-child` (`last-child`),
   KEY `unseen` (`unseen`),
   KEY `wall` (`wall`),
diff --git a/mod/item.php b/mod/item.php
index ee3bdca992..145c42cec9 100644
--- a/mod/item.php
+++ b/mod/item.php
@@ -865,12 +865,12 @@ function item_post(&$a) {
 				$addr = trim($recip);
 				if(! strlen($addr))
 					continue;
-				$disclaimer = '<hr />' . sprintf( t('This message was sent to you by %s, a member of the Friendika social network.'),$a->user['username']) 
+				$disclaimer = '<hr />' . sprintf( t('This message was sent to you by %s, a member of the Friendica social network.'),$a->user['username']) 
 					. '<br />';
 				$disclaimer .= sprintf( t('You may visit them online at %s'), $a->get_baseurl() . '/profile/' . $a->user['nickname']) . EOL;
 				$disclaimer .= t('Please contact the sender by replying to this post if you do not wish to receive these messages.') . EOL; 
 
-				$subject  = '[Friendika]' . ' ' . sprintf( t('%s posted an update.'),$a->user['username']);
+				$subject  = '[Friendica]' . ' ' . sprintf( t('%s posted an update.'),$a->user['username']);
 				$headers  = 'From: ' . $a->user['username'] . ' <' . $a->user['email'] . '>' . "\n";
 				$headers .= 'MIME-Version: 1.0' . "\n";
 				$headers .= 'Content-Type: text/html; charset=UTF-8' . "\n";
diff --git a/update.php b/update.php
index 14d68ea12c..96fdec6911 100644
--- a/update.php
+++ b/update.php
@@ -1,6 +1,6 @@
 <?php
 
-define( 'UPDATE_VERSION' , 1104 );
+define( 'UPDATE_VERSION' , 1105 );
 
 /**
  *
@@ -895,4 +895,11 @@ function update_1103() {
 
 }
 
+function update_1104() {
+	q("ALTER TABLE `item` ADD `forum_mode` TINYINT( 1 ) NOT NULL DEFAULT '0' AFTER `origin` , ADD INDEX ( `forum_mode` ) ");
+
+}
+
+
+
 

From 6893df991edfe971871a5db45055b40b871a7a4f Mon Sep 17 00:00:00 2001
From: friendica <info@friendica.com>
Date: Fri, 18 Nov 2011 22:03:49 -0800
Subject: [PATCH 10/10] update user-agent string for remote http requests

---
 include/network.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/network.php b/include/network.php
index e89eb94da2..78ed240743 100644
--- a/include/network.php
+++ b/include/network.php
@@ -22,7 +22,7 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_
 	}
 	
 	@curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
-	@curl_setopt($ch, CURLOPT_USERAGENT, "Friendika");
+	@curl_setopt($ch, CURLOPT_USERAGENT, "Friendica");
 
 
 	if(intval($timeout)) {
@@ -105,7 +105,7 @@ function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0)
 	curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
 	curl_setopt($ch, CURLOPT_POST,1);
 	curl_setopt($ch, CURLOPT_POSTFIELDS,$params);
-	curl_setopt($ch, CURLOPT_USERAGENT, "Friendika");
+	curl_setopt($ch, CURLOPT_USERAGENT, "Friendica");
 
 	if(intval($timeout)) {
 		curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);