From 147d7f3bbf6c785f2c1eb7cdcfaa0a47e0ee43d3 Mon Sep 17 00:00:00 2001
From: Friendika <info@friendika.com>
Date: Sun, 6 Feb 2011 15:50:50 -0800
Subject: [PATCH] theme name cleanup - rename default to loozah, provide sane
 fallbacks and change system primary theme. Provide indication on contact edit
 page of last update success/failure - can be extended later to show actual
 timestamp of last successful update.

---
 boot.php                                    |  32 +++++++++++++++++++-
 database.sql                                |   1 +
 htconfig.php                                |   4 +++
 include/poller.php                          |  16 ++++++++--
 index.php                                   |  13 +-------
 mod/contacts.php                            |  11 +++++--
 update.php                                  |   7 +++++
 view/de/htconfig.tpl                        |  10 ++++++
 view/en/htconfig.tpl                        |   4 +++
 view/fr/htconfig.tpl                        |   9 ++++++
 view/it/htconfig.tpl                        |   9 ++++++
 view/theme/clean/style.css                  |   2 +-
 view/theme/darkness/style.css               |   2 +-
 view/theme/default/dfrn.gif                 | Bin 109 -> 0 bytes
 view/theme/default/friendika16.gif          | Bin 1071 -> 0 bytes
 view/theme/duepuntozero/style.css           |   3 +-
 view/theme/goldenrod/style.css              |   2 +-
 view/theme/{default => loozah}/ff-16.jpg    | Bin
 view/theme/{default => loozah}/lock.cur     | Bin
 view/theme/{default => loozah}/login-bg.gif | Bin
 view/theme/{default => loozah}/style.css    |   4 ++-
 view/theme/shady/style.css                  |   2 +-
 view/theme/three-d/style.css                |   2 +-
 23 files changed, 107 insertions(+), 26 deletions(-)
 delete mode 100644 view/theme/default/dfrn.gif
 delete mode 100644 view/theme/default/friendika16.gif
 rename view/theme/{default => loozah}/ff-16.jpg (100%)
 rename view/theme/{default => loozah}/lock.cur (100%)
 rename view/theme/{default => loozah}/login-bg.gif (100%)
 rename view/theme/{default => loozah}/style.css (99%)

diff --git a/boot.php b/boot.php
index 4fc35be9bb..ae6d534d61 100644
--- a/boot.php
+++ b/boot.php
@@ -2,7 +2,7 @@
 
 set_time_limit(0);
 
-define ( 'BUILD_ID',               1035   );
+define ( 'BUILD_ID',               1036   );
 define ( 'FRIENDIKA_VERSION',      '2.10.0905' );
 define ( 'DFRN_PROTOCOL_VERSION',  '2.1'  );
 
@@ -2275,3 +2275,33 @@ function proc_run($cmd){
 	proc_close(proc_open($cmdline." &",array(),$foo));
 }}
 
+/*
+ * Return full URL to theme which is currently in effect.
+ * Provide a sane default if nothing is chosen or the specified theme does not exist.
+ */
+
+if(! function_exists('current_theme_url')) {
+function current_theme_url() {
+
+	$app_base_themes = array('duepuntozero', 'loozah');
+
+	$a = get_app();
+
+	$system_theme = ((isset($a->config['system']['theme'])) ? $a->config['system']['theme'] : '');
+	$theme_name = ((x($_SESSION,'theme')) ? $_SESSION['theme'] : $system_theme);
+
+	if($theme_name && file_exists('view/theme/' . $theme_name . '/style.css'))
+		return($a->get_baseurl() . '/view/theme/' . $theme_name . '/style.css'); 
+
+	foreach($app_base_themes as $t) {
+		if(file_exists('view/theme/' . $t . '/style.css'))
+			return($a->get_baseurl() . '/view/theme/' . $t . '/style.css'); 
+	}	
+
+	$fallback = glob('view/theme/*/style.css');
+	if(count($fallback))
+		return($a->get_baseurl() . $fallback[0]);
+
+	
+}}
+
diff --git a/database.sql b/database.sql
index 817fd09226..83e0e4b6f4 100644
--- a/database.sql
+++ b/database.sql
@@ -77,6 +77,7 @@ CREATE TABLE IF NOT EXISTS `contact` (
   `subhub` tinyint(1) NOT NULL DEFAULT '0',
   `hub-verify` char(255) NOT NULL,
   `last-update` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
+  `success_update` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
   `name-date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
   `uri-date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
   `avatar-date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
diff --git a/htconfig.php b/htconfig.php
index 5f5c76cbd7..fb62245d21 100644
--- a/htconfig.php
+++ b/htconfig.php
@@ -64,6 +64,10 @@ $a->config['system']['huburl'] = 'http://pubsubhubbub.appspot.com';
 
 $a->config['system']['rino_encrypt'] = true;
 
+// default system theme
+
+$a->config['system']['theme'] = 'duepuntozero';
+
 
 // Addons or plugins are configured here.
 // This is a comma seperated list of addons to enable. Example:
diff --git a/include/poller.php b/include/poller.php
index 20c84990e0..1d88fe447f 100644
--- a/include/poller.php
+++ b/include/poller.php
@@ -239,6 +239,7 @@ function poller_run($argv, $argc){
 			$xml = post_url($contact['poll'],$postvars);
 		}
 		else {
+
 			// $contact['network'] !== 'dfrn'
 
 			$xml = fetch_url($contact['poll']);
@@ -246,8 +247,14 @@ function poller_run($argv, $argc){
 
 		logger('poller: received xml : ' . $xml, LOGGER_DATA);
 
-		if(! strlen($xml))
+		if(! strstr($xml,'<?xml')) {
+			logger('poller: post_handshake: response from ' . $url . ' did not contain XML.');
+			$r = q("UPDATE `contact` SET `last-update` = '%s' WHERE `id` = %d LIMIT 1",
+				dbesc(datetime_convert()),
+				intval($contact['id'])
+			);
 			continue;
+		}
 
 		consume_feed($xml,$importer,$contact,$hub,1);
 
@@ -271,8 +278,11 @@ function poller_run($argv, $argc){
 		}
 
 
-		$r = q("UPDATE `contact` SET `last-update` = '%s' WHERE `id` = %d LIMIT 1",
-			dbesc(datetime_convert()),
+		$updated = datetime_convert();
+
+		$r = q("UPDATE `contact` SET `last-update` = '%s', `success_update` = '%s' WHERE `id` = %d LIMIT 1",
+			dbesc($updated),
+			dbesc($updated),
 			intval($contact['id'])
 		);
 
diff --git a/index.php b/index.php
index 685a76a131..5f128ebb1b 100644
--- a/index.php
+++ b/index.php
@@ -238,21 +238,10 @@ if($a->module != 'install')
 	require_once('nav.php');
 
 /**
- *
  * Build the page - now that we have all the components
- * Make sure the desired theme exists, though if the default theme doesn't exist we're stuffed.
- *
  */
 
-$default_theme = ((isset($a->config['system']['theme'])) ? $a->config['system']['theme'] : 'default');
-if((x($_SESSION,'theme')) && (! file_exists('view/theme/' . $_SESSION['theme'] . '/style.css')))
-	unset($_SESSION['theme']);
-
-$a->page['htmlhead'] = replace_macros($a->page['htmlhead'], array(
-	'$stylesheet' => $a->get_baseurl() . '/view/theme/'
-		. ((x($_SESSION,'theme')) ? $_SESSION['theme'] : $default_theme)
-		. '/style.css'
-	));
+$a->page['htmlhead'] = replace_macros($a->page['htmlhead'], array('$stylesheet' => current_theme_url()));
 
 $page    = $a->page;
 $profile = $a->profile;
diff --git a/mod/contacts.php b/mod/contacts.php
index 61d9ce3986..36f42f8e59 100644
--- a/mod/contacts.php
+++ b/mod/contacts.php
@@ -245,6 +245,13 @@ function contacts_content(&$a) {
 			$sparkle = '';
 		}
 
+		$last_update = (($r[0]['last-update'] == '0000-00-00 00:00:00') 
+				? t('Never') 
+				: datetime_convert('UTC',date_default_timezone_get(),$r[0]['last-update'],'D, j M Y, g:i A'));
+
+		if($r[0]['last-update'] !== '0000-00-00 00:00:00')
+			$last_update .= ' ' . (($r[0]['last-update'] == $r[0]['success_update']) ? t("\x28Update was successful\x29") : t("\x28Update was not successful\x29"));
+
 		$o .= replace_macros($tpl,array(
 			'$header' => t('Contact Editor'),
 			'$visit' => t('Visit $name\'s profile'),
@@ -254,9 +261,7 @@ function contacts_content(&$a) {
 			'$poll_interval' => contact_poll_interval($r[0]['priority']),
 			'$lastupdtext' => t('Last updated: '),
 			'$updpub' => t('Update public posts: '),
-			'$last_update' => (($r[0]['last-update'] == '0000-00-00 00:00:00') 
-				? t('Never') 
-				: datetime_convert('UTC',date_default_timezone_get(),$r[0]['last-update'],'D, j M Y, g:i A')),
+			'$last_update' => $last_update,
 			'$udnow' => t('Update now'),
 			'$profile_select' => contact_profile_assign($r[0]['profile-id'],(($r[0]['network'] !== 'dfrn') ? true : false)),
 			'$contact_id' => $r[0]['id'],
diff --git a/update.php b/update.php
index f909837470..2ca008cdad 100644
--- a/update.php
+++ b/update.php
@@ -342,3 +342,10 @@ function update_1034() {
 	q("DELETE FROM `item` WHERE `parent` = 0 AND `created` < UTC_TIMESTAMP() - INTERVAL 2 MINUTE");
 
 }
+
+
+function update_1035() {
+
+	q("ALTER TABLE `contact` ADD `success_update` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `last-update` ");
+
+}
\ No newline at end of file
diff --git a/view/de/htconfig.tpl b/view/de/htconfig.tpl
index c7c19bf69e..d3bb6b411e 100644
--- a/view/de/htconfig.tpl
+++ b/view/de/htconfig.tpl
@@ -62,3 +62,13 @@ $a->config['system']['huburl'] = 'http://pubsubhubbub.appspot.com';
 
 $a->config['system']['rino_encrypt'] = true;
 
+// default system theme
+
+$a->config['system']['theme'] = 'duepuntozero';
+
+// Addons or plugins are configured here.
+// This is a comma seperated list of addons to enable. Example:
+// $a->config['system']['addon'] = 'js_upload,randplace,oembed';
+
+$a->config['system']['addon'] = 'js_upload';
+
diff --git a/view/en/htconfig.tpl b/view/en/htconfig.tpl
index 0182dbe5c0..d3bb6b411e 100644
--- a/view/en/htconfig.tpl
+++ b/view/en/htconfig.tpl
@@ -62,6 +62,10 @@ $a->config['system']['huburl'] = 'http://pubsubhubbub.appspot.com';
 
 $a->config['system']['rino_encrypt'] = true;
 
+// default system theme
+
+$a->config['system']['theme'] = 'duepuntozero';
+
 // Addons or plugins are configured here.
 // This is a comma seperated list of addons to enable. Example:
 // $a->config['system']['addon'] = 'js_upload,randplace,oembed';
diff --git a/view/fr/htconfig.tpl b/view/fr/htconfig.tpl
index c7c19bf69e..d31d5a39ff 100644
--- a/view/fr/htconfig.tpl
+++ b/view/fr/htconfig.tpl
@@ -62,3 +62,12 @@ $a->config['system']['huburl'] = 'http://pubsubhubbub.appspot.com';
 
 $a->config['system']['rino_encrypt'] = true;
 
+// default system theme
+
+$a->config['system']['theme'] = 'duepuntozero';
+
+// Addons or plugins are configured here.
+// This is a comma seperated list of addons to enable. Example:
+// $a->config['system']['addon'] = 'js_upload,randplace,oembed';
+
+$a->config['system']['addon'] = 'js_upload';
diff --git a/view/it/htconfig.tpl b/view/it/htconfig.tpl
index 78e014cc17..180f7885cc 100644
--- a/view/it/htconfig.tpl
+++ b/view/it/htconfig.tpl
@@ -62,3 +62,12 @@ $a->config['system']['huburl'] = 'http://pubsubhubbub.appspot.com';
 
 $a->config['system']['rino_encrypt'] = true;
 
+// default system theme
+
+$a->config['system']['theme'] = 'duepuntozero';
+
+// Addons or plugins are configured here.
+// This is a comma seperated list of addons to enable. Example:
+// $a->config['system']['addon'] = 'js_upload,randplace,oembed';
+
+$a->config['system']['addon'] = 'js_upload';
diff --git a/view/theme/clean/style.css b/view/theme/clean/style.css
index ea8f54ddf3..4730b5c2fd 100644
--- a/view/theme/clean/style.css
+++ b/view/theme/clean/style.css
@@ -1,4 +1,4 @@
-@import url('../default/style.css');
+@import url('../loozah/style.css');
 
 footer {
 	background: #CCC;
diff --git a/view/theme/darkness/style.css b/view/theme/darkness/style.css
index 3aff559d3e..828fdd1040 100644
--- a/view/theme/darkness/style.css
+++ b/view/theme/darkness/style.css
@@ -1,4 +1,4 @@
-@import url('../default/style.css');
+@import url('../loozah/style.css');
 
 nav {
 	background: #CCC;
diff --git a/view/theme/default/dfrn.gif b/view/theme/default/dfrn.gif
deleted file mode 100644
index 104f42e51c65b05e9b12b9c48a3e892e0da30a8f..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001

literal 109
zcmZ?wbhEHb6l4%&Sjfb{!0`V+2!nv)PZmZl1||j_peRsQkb!~8t|!0g^upejIl@*A
zAEULZ-?%VEFgA$HJf4<!{p8lpD|uf!_pO`9^ja~xw?;KaCBaL}xhJtmeNl)GXO?gf
H1A{dHC@3dZ

diff --git a/view/theme/default/friendika16.gif b/view/theme/default/friendika16.gif
deleted file mode 100644
index f5321b1e5707cb0262654fec284523710dac1cc9..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001

literal 1071
zcmZY7ZA=?=90%}!@BVkaQc4Pe(rrbaMuk~2KoVJN<~A3Wi9^825SSKZz#t|9<yj*z
z9k3D+SadQT8Zt)4rXwS9JPb2nO3SJu10|Xn$|w`YTxsvFch@#}MBn+%H@_F(x1Zm!
z<B16ea-={CDgg*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ollkFux+-JP^iJ<)M
z9r@n56iggmXiF$X6TQ{%_~_K-MQ;TY@|donwsXb~_1lrwm6q%NdtQVmZ-Bi@Nhj=4
z_spLuZtqH{VKygGVNz)3SmndCh~ttVjc%48@-}4qf10>8K6NzGeCd@hGq$`}toq?<
N$B=gYV6YTu{sA)P<IVs8

diff --git a/view/theme/duepuntozero/style.css b/view/theme/duepuntozero/style.css
index c7eb56fb13..50745ac156 100644
--- a/view/theme/duepuntozero/style.css
+++ b/view/theme/duepuntozero/style.css
@@ -1210,7 +1210,8 @@ input#dfrn-url {
 	margin-top: 30px;
 }
 #contact-edit-poll-text {
-	margin-bottom: 10px;
+	margin-top: 15px;
+	margin-bottom: 5px;
 }
 
 #contact-edit-update-now {
diff --git a/view/theme/goldenrod/style.css b/view/theme/goldenrod/style.css
index a9c04a08dc..2a098e9551 100644
--- a/view/theme/goldenrod/style.css
+++ b/view/theme/goldenrod/style.css
@@ -1,4 +1,4 @@
-@import url('../default/style.css');
+@import url('../loozah/style.css');
 
 footer {
 	background: #CCC;
diff --git a/view/theme/default/ff-16.jpg b/view/theme/loozah/ff-16.jpg
similarity index 100%
rename from view/theme/default/ff-16.jpg
rename to view/theme/loozah/ff-16.jpg
diff --git a/view/theme/default/lock.cur b/view/theme/loozah/lock.cur
similarity index 100%
rename from view/theme/default/lock.cur
rename to view/theme/loozah/lock.cur
diff --git a/view/theme/default/login-bg.gif b/view/theme/loozah/login-bg.gif
similarity index 100%
rename from view/theme/default/login-bg.gif
rename to view/theme/loozah/login-bg.gif
diff --git a/view/theme/default/style.css b/view/theme/loozah/style.css
similarity index 99%
rename from view/theme/default/style.css
rename to view/theme/loozah/style.css
index 5dd0b87121..d7d735d6df 100644
--- a/view/theme/default/style.css
+++ b/view/theme/loozah/style.css
@@ -1335,8 +1335,10 @@ input#dfrn-url {
 	margin-top: 30px;
 }
 #contact-edit-poll-text {
-	margin-bottom: 10px;
+	margin-top: 15px;
+	margin-bottom: 5px;
 }
+
 #contact-edit-update-now {
 	margin-top: 15px;
 }
diff --git a/view/theme/shady/style.css b/view/theme/shady/style.css
index 0713105414..1e3e6ec401 100644
--- a/view/theme/shady/style.css
+++ b/view/theme/shady/style.css
@@ -1,4 +1,4 @@
-@import url('../default/style.css');
+@import url('../loozah/style.css');
 
 body { 
 	background: #DDDDDD;
diff --git a/view/theme/three-d/style.css b/view/theme/three-d/style.css
index e885a70d32..56d36914ee 100644
--- a/view/theme/three-d/style.css
+++ b/view/theme/three-d/style.css
@@ -1,4 +1,4 @@
-@import url('../default/style.css');
+@import url('../loozah/style.css');
 
 .error-message {
 	-moz-box-shadow: 5px 5px 5px #888888;