From 598baa1b32b59b187fbdc7012d23831208d0ebbd Mon Sep 17 00:00:00 2001 From: Andrew Manning Date: Sat, 21 May 2016 12:55:17 -0400 Subject: Moved git repository storage to store/[data]/git to avoid collision with a channel named git. Fixed bug where temp repo folder was never created. --- Zotlabs/Module/Admin.php | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Admin.php b/Zotlabs/Module/Admin.php index 0a167b273..42a91107d 100644 --- a/Zotlabs/Module/Admin.php +++ b/Zotlabs/Module/Admin.php @@ -1735,7 +1735,7 @@ class Admin extends \Zotlabs\Web\Controller { } else { json_return_and_die(array('message' => 'No repo name provided.', 'success' => false)); } - $extendDir = __DIR__ . '/../../store/git/sys/extend'; + $extendDir = __DIR__ . '/../../store/[data]/git/sys/extend'; $addonDir = $extendDir . '/addon'; if (!file_exists($extendDir)) { if (!mkdir($extendDir, 0770, true)) { @@ -1748,7 +1748,7 @@ class Admin extends \Zotlabs\Web\Controller { } } } - $repoDir = __DIR__ . '/../../store/git/sys/extend/addon/' . $repoName; + $repoDir = __DIR__ . '/../../store/[data]/git/sys/extend/addon/' . $repoName; if (!is_dir($repoDir)) { logger('Repo directory does not exist: ' . $repoDir); json_return_and_die(array('message' => 'Invalid addon repo.', 'success' => false)); @@ -1785,7 +1785,7 @@ class Admin extends \Zotlabs\Web\Controller { } else { json_return_and_die(array('message' => 'No repo name provided.', 'success' => false)); } - $extendDir = __DIR__ . '/../../store/git/sys/extend'; + $extendDir = __DIR__ . '/../../store/[data]/git/sys/extend'; $addonDir = $extendDir . '/addon'; if (!file_exists($extendDir)) { if (!mkdir($extendDir, 0770, true)) { @@ -1798,7 +1798,7 @@ class Admin extends \Zotlabs\Web\Controller { } } } - $repoDir = __DIR__ . '/../../store/git/sys/extend/addon/' . $repoName; + $repoDir = __DIR__ . '/../../store/[data]/git/sys/extend/addon/' . $repoName; if (!is_dir($repoDir)) { logger('Repo directory does not exist: ' . $repoDir); json_return_and_die(array('message' => 'Invalid addon repo.', 'success' => false)); @@ -1818,7 +1818,7 @@ class Admin extends \Zotlabs\Web\Controller { if (array_key_exists('repoURL', $_REQUEST)) { require __DIR__ . '/../../library/PHPGit.autoload.php'; // Load PHPGit dependencies $repoURL = $_REQUEST['repoURL']; - $extendDir = __DIR__ . '/../../store/git/sys/extend'; + $extendDir = __DIR__ . '/../../store/[data]/git/sys/extend'; $addonDir = $extendDir . '/addon'; if (!file_exists($extendDir)) { if (!mkdir($extendDir, 0770, true)) { @@ -1846,7 +1846,7 @@ class Admin extends \Zotlabs\Web\Controller { json_return_and_die(array('message' => 'Invalid git repo', 'success' => false)); } $repoDir = $addonDir . '/' . $repoName; - $tempRepoBaseDir = __DIR__ . '/../../store/git/sys/temp/'; + $tempRepoBaseDir = __DIR__ . '/../../store/[data]/git/sys/temp/'; $tempAddonDir = $tempRepoBaseDir . $repoName; if (!is_writable($addonDir) || !is_writable($tempAddonDir)) { @@ -1880,9 +1880,9 @@ class Admin extends \Zotlabs\Web\Controller { if (array_key_exists('repoURL', $_REQUEST)) { require __DIR__ . '/../../library/PHPGit.autoload.php'; // Load PHPGit dependencies $repoURL = $_REQUEST['repoURL']; - $extendDir = __DIR__ . '/../../store/git/sys/extend'; + $extendDir = __DIR__ . '/../../store/[data]/git/sys/extend'; $addonDir = $extendDir . '/addon'; - $tempAddonDir = __DIR__ . '/../../store/git/sys/temp'; + $tempAddonDir = __DIR__ . '/../../store/[data]/git/sys/temp'; if (!file_exists($extendDir)) { if (!mkdir($extendDir, 0770, true)) { logger('Error creating extend folder: ' . $extendDir); @@ -1894,6 +1894,12 @@ class Admin extends \Zotlabs\Web\Controller { } } } + if (!is_dir($tempAddonDir)) { + if (!mkdir($tempAddonDir, 0770, true)) { + logger('Error creating temp plugin repo folder: ' . $extendDir); + json_return_and_die(array('message' => 'Error creating temp plugin repo folder: ' . $extendDir, 'success' => false)); + } + } $repoName = null; if (array_key_exists('repoName', $_REQUEST) && $_REQUEST['repoName'] !== '') { $repoName = $_REQUEST['repoName']; -- cgit v1.2.3 From 7a526fa8a9934fb6f193a11815bcb03490acb2c6 Mon Sep 17 00:00:00 2001 From: Andrew Manning Date: Sat, 21 May 2016 12:58:05 -0400 Subject: Temp repo folder error message correction --- Zotlabs/Module/Admin.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Admin.php b/Zotlabs/Module/Admin.php index 42a91107d..cd6e45e9f 100644 --- a/Zotlabs/Module/Admin.php +++ b/Zotlabs/Module/Admin.php @@ -1896,8 +1896,8 @@ class Admin extends \Zotlabs\Web\Controller { } if (!is_dir($tempAddonDir)) { if (!mkdir($tempAddonDir, 0770, true)) { - logger('Error creating temp plugin repo folder: ' . $extendDir); - json_return_and_die(array('message' => 'Error creating temp plugin repo folder: ' . $extendDir, 'success' => false)); + logger('Error creating temp plugin repo folder: ' . $tempAddonDir); + json_return_and_die(array('message' => 'Error creating temp plugin repo folder: ' . $tempAddonDir, 'success' => false)); } } $repoName = null; -- cgit v1.2.3 From ed56b6e67b27900e2ff413a7781c9095aa8251a0 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Sat, 21 May 2016 18:02:14 -0700 Subject: first cut at zot-finger request signatures --- Zotlabs/Module/Probe.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Probe.php b/Zotlabs/Module/Probe.php index 79abe9819..dda792131 100644 --- a/Zotlabs/Module/Probe.php +++ b/Zotlabs/Module/Probe.php @@ -20,17 +20,17 @@ class Probe extends \Zotlabs\Web\Controller { $channel = \App::get_channel(); $addr = trim($_GET['addr']); $do_import = ((intval($_GET['import']) && is_site_admin()) ? true : false); - $res = zot_finger($addr,$channel,false); + + $j = \Zotlabs\Zot\Finger::run($addr,$channel,false); + + // $res = zot_finger($addr,$channel,false); + $o .= '
';
-			if($res['success'])
-				$j = json_decode($res['body'],true);
-			else {
+			if(! $j['success']) {
 				$o .= sprintf( t('Fetching URL returns error: %1$s'),$res['error'] . "\r\n\r\n");
 				$o .= "https connection failed. Trying again with auto failover to http.\r\n\r\n";
-				$res = zot_finger($addr,$channel,true);
-				if($res['success'])
-					$j = json_decode($res['body'],true);
-				else
+				$j = \Zotlabs\Zot\Finger::run($addr,$channel,true);
+				if(! $j['success']) 
 					$o .= sprintf( t('Fetching URL returns error: %1$s'),$res['error'] . "\r\n\r\n");
 	
 			}
-- 
cgit v1.2.3


From 1cb311cef9848178780e3fd52814bf3a64ed0556 Mon Sep 17 00:00:00 2001
From: redmatrix 
Date: Sat, 21 May 2016 18:18:33 -0700
Subject: finish updating zot_finger instances

---
 Zotlabs/Daemon/Gprobe.php   |  5 ++---
 Zotlabs/Module/Chanview.php |  9 +++------
 Zotlabs/Module/Magic.php    |  8 +++-----
 Zotlabs/Module/Mail.php     |  7 +++----
 Zotlabs/Module/Regdir.php   | 13 +++++--------
 Zotlabs/Zot/Auth.php        |  8 +++-----
 6 files changed, 19 insertions(+), 31 deletions(-)

(limited to 'Zotlabs')

diff --git a/Zotlabs/Daemon/Gprobe.php b/Zotlabs/Daemon/Gprobe.php
index 8141739be..43cce93c3 100644
--- a/Zotlabs/Daemon/Gprobe.php
+++ b/Zotlabs/Daemon/Gprobe.php
@@ -22,9 +22,8 @@ class Gprobe {
 		);
 
 		if(! $r) {
-			$x = zot_finger($url,null);
-			if($x['success']) {
-				$j = json_decode($x['body'],true);
+			$j = \Zotlabs\Zot\Finger::run($url,null);
+			if($j['success']) {
 				$y = import_xchan($j);
 			}
 		}
diff --git a/Zotlabs/Module/Chanview.php b/Zotlabs/Module/Chanview.php
index f70444816..36fbbb864 100644
--- a/Zotlabs/Module/Chanview.php
+++ b/Zotlabs/Module/Chanview.php
@@ -62,18 +62,15 @@ class Chanview extends \Zotlabs\Web\Controller {
 			}
 	
 			if($_REQUEST['address']) {
-				$ret = zot_finger($_REQUEST['address'],null);
-				if($ret['success']) {
-					$j = json_decode($ret['body'],true);
-					if($j)
-						import_xchan($j);
+				$j = \Zotlabs\Zot\Finger::run($_REQUEST['address'],null);
+				if($j['success']) {
+					import_xchan($j);
 					$r = q("select * from xchan where xchan_addr = '%s' limit 1",
 						dbesc($_REQUEST['address'])
 					);
 					if($r)
 						\App::$poi = $r[0];
 				}
-	
 			}
 		}
 	
diff --git a/Zotlabs/Module/Magic.php b/Zotlabs/Module/Magic.php
index 63db4a317..6798f72a9 100644
--- a/Zotlabs/Module/Magic.php
+++ b/Zotlabs/Module/Magic.php
@@ -47,11 +47,9 @@ class Magic extends \Zotlabs\Web\Controller {
 			 *
 			 */
 	
-			$ret = zot_finger((($addr) ? $addr : '[system]@' . $parsed['host']),null);
-			if($ret['success']) {
-				$j = json_decode($ret['body'],true);
-				if($j)
-					import_xchan($j);
+			$j = \Zotlabs\Zot\Finger::run((($addr) ? $addr : '[system]@' . $parsed['host']),null);
+			if($j['success']) {
+				import_xchan($j);
 	
 				// Now try again
 	
diff --git a/Zotlabs/Module/Mail.php b/Zotlabs/Module/Mail.php
index e6487d681..3dbfa8d71 100644
--- a/Zotlabs/Module/Mail.php
+++ b/Zotlabs/Module/Mail.php
@@ -32,17 +32,16 @@ class Mail extends \Zotlabs\Web\Controller {
 		if(! $recipient) {
 			$channel = \App::get_channel();
 	
-			$ret = zot_finger($rstr,$channel);
+			$j = \Zotlabs\Zot\Finger::run($rstr,$channel);
 	
-			if(! $ret['success']) {
+			if(! $j['success']) {
 				notice( t('Unable to lookup recipient.') . EOL);
 				return;
 			} 
-			$j = json_decode($ret['body'],true);
 	
 			logger('message_post: lookup: ' . $url . ' ' . print_r($j,true));
 	
-			if(! ($j['success'] && $j['guid'])) {
+			if(! $j['guid']) {
 				notice( t('Unable to communicate with requested channel.'));
 				return;
 			}
diff --git a/Zotlabs/Module/Regdir.php b/Zotlabs/Module/Regdir.php
index 65f8daf67..48a7cc16d 100644
--- a/Zotlabs/Module/Regdir.php
+++ b/Zotlabs/Module/Regdir.php
@@ -60,14 +60,11 @@ class Regdir extends \Zotlabs\Web\Controller {
 				json_return_and_die($result);
 			}
 	
-			$f = zot_finger('[system]@' . $m['host']);
-			if($f['success']) {
-				$j = json_decode($f['body'],true);
-				if($j['success'] && $j['guid']) {
-					$x = import_xchan($j);
-					if($x['success']) {
-						$result['success'] = true;
-					}
+			$j = \Zotlabs\Zot\Finger::run('[system]@' . $m['host']);
+			if($j['success'] && $j['guid']) {
+				$x = import_xchan($j);
+				if($x['success']) {
+					$result['success'] = true;
 				}
 			}
 	
diff --git a/Zotlabs/Zot/Auth.php b/Zotlabs/Zot/Auth.php
index f764172fa..0837be21a 100644
--- a/Zotlabs/Zot/Auth.php
+++ b/Zotlabs/Zot/Auth.php
@@ -80,11 +80,9 @@ class Auth {
 
 		if(! $x) {
 			// finger them if they can't be found.
-			$ret = zot_finger($address, null);
-			if ($ret['success']) {
-				$j = json_decode($ret['body'], true);
-				if($j)
-					import_xchan($j);
+			$j = Finger::run($address, null);
+			if ($j['success']) {
+				import_xchan($j);
 				$x = q("select * from hubloc left join xchan on xchan_hash = hubloc_hash 
 					where hubloc_addr = '%s' order by hubloc_id desc",
 					dbesc($address)
-- 
cgit v1.2.3


From 3dc131757d0a8bf3ac970ffaef0807b2e23c5729 Mon Sep 17 00:00:00 2001
From: redmatrix 
Date: Sat, 21 May 2016 18:21:04 -0700
Subject: include new finger backend

---
 Zotlabs/Zot/Finger.php | 130 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 130 insertions(+)
 create mode 100644 Zotlabs/Zot/Finger.php

(limited to 'Zotlabs')

diff --git a/Zotlabs/Zot/Finger.php b/Zotlabs/Zot/Finger.php
new file mode 100644
index 000000000..27ba6ddca
--- /dev/null
+++ b/Zotlabs/Zot/Finger.php
@@ -0,0 +1,130 @@
+ false);
+
+		self::$token = random_string();
+
+		if (strpos($webbie,'@') === false) {
+			$address = $webbie;
+			$host = App::get_hostname();
+		} else {
+			$address = substr($webbie,0,strpos($webbie,'@'));
+			$host = substr($webbie,strpos($webbie,'@')+1);
+		}
+
+		$xchan_addr = $address . '@' . $host;
+
+		if ((! $address) || (! $xchan_addr)) {
+			logger('zot_finger: no address :' . $webbie);
+			return $ret;
+		}
+
+		logger('using xchan_addr: ' . $xchan_addr, LOGGER_DATA, LOG_DEBUG);
+
+		// potential issue here; the xchan_addr points to the primary hub.
+		// The webbie we were called with may not, so it might not be found
+		// unless we query for hubloc_addr instead of xchan_addr
+
+		$r = q("select xchan.*, hubloc.* from xchan
+			left join hubloc on xchan_hash = hubloc_hash
+			where xchan_addr = '%s' and hubloc_primary = 1 limit 1",
+			dbesc($xchan_addr)
+		);
+
+		if ($r) {
+			$url = $r[0]['hubloc_url'];
+
+			if ($r[0]['hubloc_network'] && $r[0]['hubloc_network'] !== 'zot') {
+				logger('zot_finger: alternate network: ' . $webbie);
+				logger('url: '.$url.', net: '.var_export($r[0]['hubloc_network'],true), LOGGER_DATA, LOG_DEBUG);
+				return $ret;
+			}
+		} 
+		else {
+			$url = 'https://' . $host;
+		}
+
+		$rhs = '/.well-known/zot-info';
+		$https = ((strpos($url,'https://') === 0) ? true : false);
+
+		logger('zot_finger: ' . $address . ' at ' . $url, LOGGER_DEBUG);
+
+		if ($channel) {
+			$postvars = array(
+				'address'    => $address,
+				'target'     => $channel['channel_guid'],
+				'target_sig' => $channel['channel_guid_sig'],
+				'key'        => $channel['channel_pubkey'],
+				'token'      => self::$token
+			);
+
+			$result = z_post_url($url . $rhs,$postvars);
+
+			if ((! $result['success']) && ($autofallback)) {
+				if ($https) {
+					logger('zot_finger: https failed. falling back to http');
+					$result = z_post_url('http://' . $host . $rhs,$postvars);
+				}
+			}
+		} 
+		else {
+			$rhs .= '?f=&address=' . urlencode($address) . '&token=' . self::$token;
+
+			$result =  z_fetch_url($url . $rhs);
+			if ((! $result['success']) && ($autofallback)) {
+				if ($https) {
+					logger('zot_finger: https failed. falling back to http');
+					$result = z_fetch_url('http://' . $host . $rhs);
+				}
+			}
+		}
+
+		if(! $result['success']) {
+			logger('zot_finger: no results');
+			return $ret;
+		}
+
+		$x = json_decode($result['body'],true);
+		if($x) {
+			$signed_token = $x['signed_token'];
+			if($signed_token) {
+				$valid = rsa_verify(self::$token,base64url_decode($signed_token),$x['key']);
+				if(! $valid) {
+					logger('invalid signed token: ' . $url . $rhs, LOGGER_NORMAL, LOG_WARN);
+					return $ret;
+				}
+			}
+			else {
+				logger('No signed token from '  . $url . $rhs, LOGGER_NORMAL, LOG_WARN);
+				// after 2017-01-01 this will be a hard error unless you over-ride it.
+				if((time() > 1483228800) && (! get_config('system','allow_unsigned_zotfinger')))
+					return $ret;
+			}
+		}
+
+		return $x;
+	}
+
+}
\ No newline at end of file
-- 
cgit v1.2.3


From de006771c7fe92a889d759c2c75c1473c420ad47 Mon Sep 17 00:00:00 2001
From: redmatrix 
Date: Sun, 22 May 2016 16:54:30 -0700
Subject: renamed include files identity.php (channel.php) and Contact.php
 (connections.php)

---
 Zotlabs/Daemon/Cron_weekly.php     |  1 -
 Zotlabs/Daemon/Externals.php       |  2 +-
 Zotlabs/Daemon/Notifier.php        |  3 +--
 Zotlabs/Daemon/Onepoll.php         |  2 +-
 Zotlabs/Daemon/Ratenotif.php       |  1 -
 Zotlabs/Lib/ThreadStream.php       |  2 +-
 Zotlabs/Module/Admin.php           |  4 ----
 Zotlabs/Module/Blocks.php          |  2 +-
 Zotlabs/Module/Cal.php             |  2 --
 Zotlabs/Module/Chanview.php        |  2 --
 Zotlabs/Module/Connect.php         |  2 +-
 Zotlabs/Module/Connections.php     |  2 +-
 Zotlabs/Module/Connedit.php        |  3 +--
 Zotlabs/Module/Cover_photo.php     |  2 +-
 Zotlabs/Module/Display.php         |  4 ++--
 Zotlabs/Module/Editblock.php       |  2 +-
 Zotlabs/Module/Editlayout.php      |  2 +-
 Zotlabs/Module/Editwebpage.php     |  2 +-
 Zotlabs/Module/Getfile.php         |  1 -
 Zotlabs/Module/Import.php          |  4 ++--
 Zotlabs/Module/Item.php            |  2 +-
 Zotlabs/Module/Layouts.php         |  2 +-
 Zotlabs/Module/Mail.php            |  7 +------
 Zotlabs/Module/Menu.php            |  2 +-
 Zotlabs/Module/Message.php         |  2 --
 Zotlabs/Module/Network.php         |  2 +-
 Zotlabs/Module/New_channel.php     |  2 +-
 Zotlabs/Module/Oep.php             |  4 ++--
 Zotlabs/Module/Photos.php          |  2 +-
 Zotlabs/Module/Profile_photo.php   |  2 +-
 Zotlabs/Module/Profiles.php        |  4 ++--
 Zotlabs/Module/Profperm.php        |  2 +-
 Zotlabs/Module/Pubstream.php       |  2 +-
 Zotlabs/Module/Randprof.php        |  1 -
 Zotlabs/Module/Register.php        |  2 +-
 Zotlabs/Module/Removeaccount.php   | 11 +++--------
 Zotlabs/Module/Removeme.php        |  5 +----
 Zotlabs/Module/Search.php          |  2 +-
 Zotlabs/Module/Settings.php        |  2 +-
 Zotlabs/Module/Setup.php           |  2 +-
 Zotlabs/Module/Uexport.php         |  2 +-
 Zotlabs/Module/Viewconnections.php |  4 +---
 Zotlabs/Module/Wall_attach.php     |  2 +-
 Zotlabs/Module/Wall_upload.php     |  2 +-
 Zotlabs/Module/Webpages.php        |  2 +-
 Zotlabs/Zot/Finger.php             |  4 ++--
 46 files changed, 45 insertions(+), 76 deletions(-)

(limited to 'Zotlabs')

diff --git a/Zotlabs/Daemon/Cron_weekly.php b/Zotlabs/Daemon/Cron_weekly.php
index dc781ad73..1d8420947 100644
--- a/Zotlabs/Daemon/Cron_weekly.php
+++ b/Zotlabs/Daemon/Cron_weekly.php
@@ -21,7 +21,6 @@ class Cron_weekly {
 		require_once('include/hubloc.php');
 		prune_hub_reinstalls();
 	
-		require_once('include/Contact.php');
 		mark_orphan_hubsxchans();
 
 
diff --git a/Zotlabs/Daemon/Externals.php b/Zotlabs/Daemon/Externals.php
index 167b0524f..24cfe64ec 100644
--- a/Zotlabs/Daemon/Externals.php
+++ b/Zotlabs/Daemon/Externals.php
@@ -3,7 +3,7 @@
 namespace Zotlabs\Daemon;
 
 require_once('include/zot.php');
-require_once('include/identity.php');
+require_once('include/channel.php');
 
 
 class Externals {
diff --git a/Zotlabs/Daemon/Notifier.php b/Zotlabs/Daemon/Notifier.php
index 65690f8ce..590be31ee 100644
--- a/Zotlabs/Daemon/Notifier.php
+++ b/Zotlabs/Daemon/Notifier.php
@@ -72,8 +72,7 @@ require_once('include/queue_fn.php');
 require_once('include/datetime.php');
 require_once('include/items.php');
 require_once('include/bbcode.php');
-require_once('include/identity.php');
-require_once('include/Contact.php');
+require_once('include/channel.php');
 
 
 class Notifier {
diff --git a/Zotlabs/Daemon/Onepoll.php b/Zotlabs/Daemon/Onepoll.php
index 2610ad151..036a4991b 100644
--- a/Zotlabs/Daemon/Onepoll.php
+++ b/Zotlabs/Daemon/Onepoll.php
@@ -4,7 +4,7 @@ namespace Zotlabs\Daemon;
 
 require_once('include/zot.php');
 require_once('include/socgraph.php');
-require_once('include/Contact.php');
+
 
 class Onepoll {
 
diff --git a/Zotlabs/Daemon/Ratenotif.php b/Zotlabs/Daemon/Ratenotif.php
index a404273e2..1cba5e26d 100644
--- a/Zotlabs/Daemon/Ratenotif.php
+++ b/Zotlabs/Daemon/Ratenotif.php
@@ -12,7 +12,6 @@ class Ratenotif {
 
 		require_once("datetime.php");
 		require_once('include/items.php');
-		require_once('include/Contact.php');
 
 		if($argc < 3)
 			return;
diff --git a/Zotlabs/Lib/ThreadStream.php b/Zotlabs/Lib/ThreadStream.php
index 2bcf167e9..a6d4f8517 100644
--- a/Zotlabs/Lib/ThreadStream.php
+++ b/Zotlabs/Lib/ThreadStream.php
@@ -165,7 +165,7 @@ class ThreadStream {
 					$item->set_commentable(can_comment_on_post($this->observer['xchan_hash'],$item->data));
 			}
 		}
-		require_once('include/identity.php');
+		require_once('include/channel.php');
 
 		$item->set_conversation($this);
 		$this->threads[] = $item;
diff --git a/Zotlabs/Module/Admin.php b/Zotlabs/Module/Admin.php
index cd6e45e9f..172b109c8 100644
--- a/Zotlabs/Module/Admin.php
+++ b/Zotlabs/Module/Admin.php
@@ -902,7 +902,6 @@ class Admin extends \Zotlabs\Web\Controller {
 		}
 		// account delete button was submitted
 		if (x($_POST, 'page_users_delete')) {
-			require_once('include/Contact.php');
 			foreach ($users as $uid){
 				account_remove($uid, true, false);
 			}
@@ -951,7 +950,6 @@ class Admin extends \Zotlabs\Web\Controller {
 			switch (argv(2)){
 				case 'delete':
 					// delete user
-					require_once('include/Contact.php');
 					account_remove($uid,true,false);
 	
 					notice( sprintf(t("Account '%s' deleted"), $account[0]['account_email']) . EOL);
@@ -1096,7 +1094,6 @@ class Admin extends \Zotlabs\Web\Controller {
 			notice( sprintf( tt("%s channel code allowed/disallowed", "%s channels code allowed/disallowed", count($channels)), count($channels)) );
 		}
 		if (x($_POST,'page_channels_delete')){
-			require_once("include/Contact.php");
 			foreach($channels as $uid){
 				channel_remove($uid,true);
 			}
@@ -1128,7 +1125,6 @@ class Admin extends \Zotlabs\Web\Controller {
 				case "delete":{
 					check_form_security_token_redirectOnErr('/admin/channels', 'admin_channels', 't');
 					// delete channel
-					require_once("include/Contact.php");
 					channel_remove($uid,true);
 					
 					notice( sprintf(t("Channel '%s' deleted"), $channel[0]['channel_name']) . EOL);
diff --git a/Zotlabs/Module/Blocks.php b/Zotlabs/Module/Blocks.php
index ed702befb..32650a090 100644
--- a/Zotlabs/Module/Blocks.php
+++ b/Zotlabs/Module/Blocks.php
@@ -1,7 +1,7 @@
 disabled())) {
 				$r = null;
 	
-				require_once('include/identity.php');
+				require_once('include/channel.php');
 				$sys = get_sys_channel();
 				$sysid = $sys['channel_id'];
 	
@@ -233,7 +233,7 @@ class Display extends \Zotlabs\Web\Controller {
 		elseif($update && !$load) {
 			$r = null;
 	
-			require_once('include/identity.php');
+			require_once('include/channel.php');
 			$sys = get_sys_channel();
 			$sysid = $sys['channel_id'];
 	
diff --git a/Zotlabs/Module/Editblock.php b/Zotlabs/Module/Editblock.php
index a79962033..fb86557f2 100644
--- a/Zotlabs/Module/Editblock.php
+++ b/Zotlabs/Module/Editblock.php
@@ -1,7 +1,7 @@
  1) {
 			$channel = \App::get_channel();
 	
-			require_once('include/identity.php');
+			require_once('include/channel.php');
 	
 			if(argc() > 1 && intval(argv(1)) > 1900) {
 				$year = intval(argv(1));
diff --git a/Zotlabs/Module/Viewconnections.php b/Zotlabs/Module/Viewconnections.php
index a9445cdeb..d58c431e5 100644
--- a/Zotlabs/Module/Viewconnections.php
+++ b/Zotlabs/Module/Viewconnections.php
@@ -2,8 +2,6 @@
 namespace Zotlabs\Module;
 
 require_once('include/selectors.php');
-require_once('include/Contact.php');
-
 
 class Viewconnections extends \Zotlabs\Web\Controller {
 
@@ -16,7 +14,7 @@ class Viewconnections extends \Zotlabs\Web\Controller {
 			profile_load($a,argv(1));
 	}
 	
-		function get() {
+	function get() {
 	
 		if((get_config('system','block_public')) && (! local_channel()) && (! remote_channel())) {
 			notice( t('Public access denied.') . EOL);
diff --git a/Zotlabs/Module/Wall_attach.php b/Zotlabs/Module/Wall_attach.php
index 5bdecfa75..9a1019ddb 100644
--- a/Zotlabs/Module/Wall_attach.php
+++ b/Zotlabs/Module/Wall_attach.php
@@ -2,7 +2,7 @@
 namespace Zotlabs\Module;
 
 require_once('include/attach.php');
-require_once('include/identity.php');
+require_once('include/channel.php');
 require_once('include/photos.php');
 
 
diff --git a/Zotlabs/Module/Wall_upload.php b/Zotlabs/Module/Wall_upload.php
index fff3ed03a..3868cb14e 100644
--- a/Zotlabs/Module/Wall_upload.php
+++ b/Zotlabs/Module/Wall_upload.php
@@ -2,7 +2,7 @@
 namespace Zotlabs\Module;
 
 require_once('include/photo/photo_driver.php');
-require_once('include/identity.php');
+require_once('include/channel.php');
 require_once('include/photos.php');
 
 
diff --git a/Zotlabs/Module/Webpages.php b/Zotlabs/Module/Webpages.php
index d8adb55b2..bb8d454c8 100644
--- a/Zotlabs/Module/Webpages.php
+++ b/Zotlabs/Module/Webpages.php
@@ -1,7 +1,7 @@
  true) or array('success' => false);
 	 */
 
 	static public function run($webbie, $channel = null, $autofallback = true) {
@@ -108,7 +108,7 @@ class Finger {
 
 		$x = json_decode($result['body'],true);
 		if($x) {
-			$signed_token = $x['signed_token'];
+			$signed_token = ((is_array($x) && array_key_exists('signed_token',$x)) ? $x['signed_token'] : null);
 			if($signed_token) {
 				$valid = rsa_verify(self::$token,base64url_decode($signed_token),$x['key']);
 				if(! $valid) {
-- 
cgit v1.2.3


From 5e0698ba8731e7e4659a24c0ab4fa9c4a1aef173 Mon Sep 17 00:00:00 2001
From: redmatrix 
Date: Sun, 22 May 2016 17:52:30 -0700
Subject: turn the oft-repeated block_public ... check into a function
 observer_prohibited()

---
 Zotlabs/Module/Acl.php             |   2 +-
 Zotlabs/Module/Cal.php             |   9 +-
 Zotlabs/Module/Channel.php         | 550 +++++++++++++++++++------------------
 Zotlabs/Module/Directory.php       |   4 +-
 Zotlabs/Module/Display.php         |   6 +-
 Zotlabs/Module/Feed.php            |   2 +-
 Zotlabs/Module/Photos.php          |   4 +-
 Zotlabs/Module/Profile.php         |   4 +-
 Zotlabs/Module/Pubstream.php       |   2 +-
 Zotlabs/Module/Ratings.php         |   6 +-
 Zotlabs/Module/Viewconnections.php |   4 +-
 Zotlabs/Module/Zotfeed.php         |   4 +-
 12 files changed, 296 insertions(+), 301 deletions(-)

(limited to 'Zotlabs')

diff --git a/Zotlabs/Module/Acl.php b/Zotlabs/Module/Acl.php
index 5c14ab599..62ac29286 100644
--- a/Zotlabs/Module/Acl.php
+++ b/Zotlabs/Module/Acl.php
@@ -260,7 +260,7 @@ class Acl extends \Zotlabs\Web\Controller {
 	
 	//	logger('navbar_complete');
 	
-		if((get_config('system','block_public')) && (! local_channel()) && (! remote_channel())) {
+		if(observer_prohibited()) {
 			return;
 		}
 	
diff --git a/Zotlabs/Module/Cal.php b/Zotlabs/Module/Cal.php
index 602a2b5ab..a1adb30e5 100644
--- a/Zotlabs/Module/Cal.php
+++ b/Zotlabs/Module/Cal.php
@@ -11,7 +11,7 @@ require_once('include/items.php');
 class Cal extends \Zotlabs\Web\Controller {
 
 	function init() {
-		if((get_config('system','block_public')) && (! local_channel()) && (! remote_channel())) {
+		if(observer_prohibited()) {
 			return;
 		}
 	
@@ -45,13 +45,12 @@ class Cal extends \Zotlabs\Web\Controller {
 	
 	
 	
-		function get() {
+	function get() {
 	
-		if((get_config('system','block_public')) && (! local_channel()) && (! remote_channel())) {
+		if(observer_prohibited()) {
 			return;
 		}
-	
-	
+		
 		$channel = null;
 	
 		if(argc() > 1) {
diff --git a/Zotlabs/Module/Channel.php b/Zotlabs/Module/Channel.php
index f55705442..29bfcbc3c 100644
--- a/Zotlabs/Module/Channel.php
+++ b/Zotlabs/Module/Channel.php
@@ -13,353 +13,355 @@ require_once('include/PermissionDescription.php');
 
 class Channel extends \Zotlabs\Web\Controller {
 
-function init() {
-
-	$which = null;
-	if(argc() > 1)
-		$which = argv(1);
-	if(! $which) {
-		if(local_channel()) {
-			$channel = \App::get_channel();
-			if($channel && $channel['channel_address'])
-			$which = $channel['channel_address'];
+	function init() {
+
+		$which = null;
+		if(argc() > 1)
+			$which = argv(1);
+		if(! $which) {
+			if(local_channel()) {
+				$channel = \App::get_channel();
+				if($channel && $channel['channel_address'])
+				$which = $channel['channel_address'];
+			}
+		}
+		if(! $which) {
+			notice( t('You must be logged in to see this page.') . EOL );
+			return;
 		}
-	}
-	if(! $which) {
-		notice( t('You must be logged in to see this page.') . EOL );
-		return;
-	}
 
-	$profile = 0;
-	$channel = \App::get_channel();
+		$profile = 0;
+		$channel = \App::get_channel();
 
-	if((local_channel()) && (argc() > 2) && (argv(2) === 'view')) {
-		$which = $channel['channel_address'];
-		$profile = argv(1);		
-	}
+		if((local_channel()) && (argc() > 2) && (argv(2) === 'view')) {
+			$which = $channel['channel_address'];
+			$profile = argv(1);		
+		}
 
-	\App::$page['htmlhead'] .= '' . "\r\n" ;
-	\App::$page['htmlhead'] .= '' . "\r\n" ;
+		\App::$page['htmlhead'] .= '' . "\r\n" ;
+		\App::$page['htmlhead'] .= '' . "\r\n" ;
 
-// Not yet ready for prime time
-//	\App::$page['htmlhead'] .= '' . "\r\n" ;
-//	\App::$page['htmlhead'] .= '' . "\r\n" ;
+		// Not yet ready for prime time
+		//	\App::$page['htmlhead'] .= '' . "\r\n" ;
+		//	\App::$page['htmlhead'] .= '' . "\r\n" ;
 
-	// Run profile_load() here to make sure the theme is set before
-	// we start loading content
+		// Run profile_load() here to make sure the theme is set before
+		// we start loading content
 
-	profile_load($a,$which,$profile);
+		profile_load($a,$which,$profile);
 
-}
+	}
 
-function get($update = 0, $load = false) {
+	function get($update = 0, $load = false) {
 
 
-	if($load)
-		$_SESSION['loadtime'] = datetime_convert();
+		if($load)
+			$_SESSION['loadtime'] = datetime_convert();
 
-	$checkjs = new \Zotlabs\Web\CheckJS(1);
+		$checkjs = new \Zotlabs\Web\CheckJS(1);
 
-	$category = $datequery = $datequery2 = '';
+		$category = $datequery = $datequery2 = '';
 
-	$mid = ((x($_REQUEST,'mid')) ? $_REQUEST['mid'] : '');
+		$mid = ((x($_REQUEST,'mid')) ? $_REQUEST['mid'] : '');
 
-	$datequery = ((x($_GET,'dend') && is_a_date_arg($_GET['dend'])) ? notags($_GET['dend']) : '');
-	$datequery2 = ((x($_GET,'dbegin') && is_a_date_arg($_GET['dbegin'])) ? notags($_GET['dbegin']) : '');
+		$datequery = ((x($_GET,'dend') && is_a_date_arg($_GET['dend'])) ? notags($_GET['dend']) : '');
+		$datequery2 = ((x($_GET,'dbegin') && is_a_date_arg($_GET['dbegin'])) ? notags($_GET['dbegin']) : '');
 
-	if(get_config('system','block_public') && (! get_account_id()) && (! remote_channel())) {
+		if(observer_prohibited(true)) {			
 			return login();
-	}
+		}
 
-	$category = ((x($_REQUEST,'cat')) ? $_REQUEST['cat'] : '');
-	$hashtags = ((x($_REQUEST,'tag')) ? $_REQUEST['tag'] : '');
+		$category = ((x($_REQUEST,'cat')) ? $_REQUEST['cat'] : '');
+		$hashtags = ((x($_REQUEST,'tag')) ? $_REQUEST['tag'] : '');
 
-	$groups = array();
+		$groups = array();
 
-	$o = '';
+		$o = '';
 
-	if($update) {
-		// Ensure we've got a profile owner if updating.
-		\App::$profile['profile_uid'] = \App::$profile_uid = $update;
-	}
-	else {
-		if(\App::$profile['profile_uid'] == local_channel()) {
-			nav_set_selected('home');
+		if($update) {
+			// Ensure we've got a profile owner if updating.
+			\App::$profile['profile_uid'] = \App::$profile_uid = $update;
+		}
+		else {
+			if(\App::$profile['profile_uid'] == local_channel()) {
+				nav_set_selected('home');
+			}
 		}
-	}
 
-	$is_owner = (((local_channel()) && (\App::$profile['profile_uid'] == local_channel())) ? true : false);
+		$is_owner = (((local_channel()) && (\App::$profile['profile_uid'] == local_channel())) ? true : false);
 
-	$channel = \App::get_channel();
-	$observer = \App::get_observer();
-	$ob_hash = (($observer) ? $observer['xchan_hash'] : '');
+		$channel = \App::get_channel();
+		$observer = \App::get_observer();
+		$ob_hash = (($observer) ? $observer['xchan_hash'] : '');
 
-	$perms = get_all_perms(\App::$profile['profile_uid'],$ob_hash);
+		$perms = get_all_perms(\App::$profile['profile_uid'],$ob_hash);
 
-	if(! $perms['view_stream']) {
+		if(! $perms['view_stream']) {
 			// We may want to make the target of this redirect configurable
 			if($perms['view_profile']) {
 				notice( t('Insufficient permissions.  Request redirected to profile page.') . EOL);
 				goaway (z_root() . "/profile/" . \App::$profile['channel_address']);
 			}
-		notice( t('Permission denied.') . EOL);
-		return;
-	}
+			notice( t('Permission denied.') . EOL);
+			return;
+		}
 
 
-	if(! $update) {
+		if(! $update) {
 
-		$o .= profile_tabs($a, $is_owner, \App::$profile['channel_address']);
+			$o .= profile_tabs($a, $is_owner, \App::$profile['channel_address']);
 
-		$o .= common_friends_visitor_widget(\App::$profile['profile_uid']);
+			$o .= common_friends_visitor_widget(\App::$profile['profile_uid']);
 
-		if($channel && $is_owner) {
-			$channel_acl = array(
-				'allow_cid' => $channel['channel_allow_cid'], 
-				'allow_gid' => $channel['channel_allow_gid'], 
-				'deny_cid' => $channel['channel_deny_cid'], 
-				'deny_gid' => $channel['channel_deny_gid']
-			);
-		}
-		else
-			$channel_acl = array(); 
-
-
-		if($perms['post_wall']) {
-
-			$x = array(
-				'is_owner' => $is_owner,
-				'allow_location' => ((($is_owner || $observer) && (intval(get_pconfig(\App::$profile['profile_uid'],'system','use_browser_location')))) ? true : false),
-				'default_location' => (($is_owner) ? \App::$profile['channel_location'] : ''),
-				'nickname' => \App::$profile['channel_address'],
-				'lockstate' => (((strlen(\App::$profile['channel_allow_cid'])) || (strlen(\App::$profile['channel_allow_gid'])) || (strlen(\App::$profile['channel_deny_cid'])) || (strlen(\App::$profile['channel_deny_gid']))) ? 'lock' : 'unlock'),
-				'acl' => (($is_owner) ? populate_acl($channel_acl,true, \PermissionDescription::fromGlobalPermission('view_stream'), get_post_aclDialogDescription(), 'acl_dialog_post') : ''),
-				'showacl' => (($is_owner) ? 'yes' : ''),
-				'bang' => '',
-				'visitor' => (($is_owner || $observer) ? true : false),
-				'profile_uid' => \App::$profile['profile_uid'],
-				'editor_autocomplete' => true,
-				'bbco_autocomplete' => 'bbcode',
-				'bbcode' => true
-        	);
-
-        	$o .= status_editor($a,$x);
-		}
+			if($channel && $is_owner) {
+				$channel_acl = array(
+					'allow_cid' => $channel['channel_allow_cid'], 
+					'allow_gid' => $channel['channel_allow_gid'], 
+					'deny_cid' => $channel['channel_deny_cid'], 
+					'deny_gid' => $channel['channel_deny_gid']
+				);
+			}
+			else
+				$channel_acl = array(); 
+
+
+			if($perms['post_wall']) {
+
+				$x = array(
+					'is_owner' => $is_owner,
+					'allow_location' => ((($is_owner || $observer) && (intval(get_pconfig(\App::$profile['profile_uid'],'system','use_browser_location')))) ? true : false),
+					'default_location' => (($is_owner) ? \App::$profile['channel_location'] : ''),
+					'nickname' => \App::$profile['channel_address'],
+					'lockstate' => (((strlen(\App::$profile['channel_allow_cid'])) || (strlen(\App::$profile['channel_allow_gid'])) || (strlen(\App::$profile['channel_deny_cid'])) || (strlen(\App::$profile['channel_deny_gid']))) ? 'lock' : 'unlock'),
+					'acl' => (($is_owner) ? populate_acl($channel_acl,true, \PermissionDescription::fromGlobalPermission('view_stream'), get_post_aclDialogDescription(), 'acl_dialog_post') : ''),
+					'showacl' => (($is_owner) ? 'yes' : ''),
+					'bang' => '',
+					'visitor' => (($is_owner || $observer) ? true : false),
+					'profile_uid' => \App::$profile['profile_uid'],
+					'editor_autocomplete' => true,
+					'bbco_autocomplete' => 'bbcode',
+					'bbcode' => true
+        		);
+
+        		$o .= status_editor($a,$x);
+			}
 
-	}
+		}
 
 
-	/**
-	 * Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups
-	 */
+		/**
+		 * Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups
+		 */
 
-	$item_normal = item_normal();
-	$sql_extra = item_permissions_sql(\App::$profile['profile_uid']);
+		$item_normal = item_normal();
+		$sql_extra = item_permissions_sql(\App::$profile['profile_uid']);
 
-	if(get_pconfig(\App::$profile['profile_uid'],'system','channel_list_mode') && (! $mid))
-		$page_mode = 'list';
-	else
-		$page_mode = 'client';
+		if(get_pconfig(\App::$profile['profile_uid'],'system','channel_list_mode') && (! $mid))
+			$page_mode = 'list';
+		else
+			$page_mode = 'client';
 
-	$abook_uids = " and abook.abook_channel = " . intval(\App::$profile['profile_uid']) . " ";
+		$abook_uids = " and abook.abook_channel = " . intval(\App::$profile['profile_uid']) . " ";
 
-	$simple_update = (($update) ? " AND item_unseen = 1 " : '');
+		$simple_update = (($update) ? " AND item_unseen = 1 " : '');
 
-	\App::$page['htmlhead'] .= "\r\n" . '' . "\r\n";
+		\App::$page['htmlhead'] .= "\r\n" . '' . "\r\n";
 		
-	if($update && $_SESSION['loadtime'])
-		$simple_update = " AND (( item_unseen = 1 AND item.changed > '" . datetime_convert('UTC','UTC',$_SESSION['loadtime']) . "' )  OR item.changed > '" . datetime_convert('UTC','UTC',$_SESSION['loadtime']) . "' ) ";
-	if($load)
-		$simple_update = '';
-
-	if(($update) && (! $load)) {
-
-		if ($mid) {
-			$r = q("SELECT parent AS item_id from item where mid like '%s' and uid = %d $item_normal
-				AND item_wall = 1 AND item_unseen = 1 $sql_extra limit 1",
-				dbesc($mid . '%'),
-				intval(\App::$profile['profile_uid'])
-			);
-		} else {
-			$r = q("SELECT distinct parent AS `item_id`, created from item
-				left join abook on ( item.owner_xchan = abook.abook_xchan $abook_uids )
-				WHERE uid = %d $item_normal
-				AND item_wall = 1 $simple_update
-				AND (abook.abook_blocked = 0 or abook.abook_flags is null)
-				$sql_extra
-				ORDER BY created DESC",
-				intval(\App::$profile['profile_uid'])
-			);
-			$_SESSION['loadtime'] = datetime_convert();
-		}
-
-	}
-	else {
-
-		if(x($category)) {
-		        $sql_extra .= protect_sprintf(term_query('item', $category, TERM_CATEGORY));
-		}
-		if(x($hashtags)) {
-		        $sql_extra .= protect_sprintf(term_query('item', $hashtags, TERM_HASHTAG, TERM_COMMUNITYTAG));
-		}
-
-		if($datequery) {
-			$sql_extra2 .= protect_sprintf(sprintf(" AND item.created <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery))));
-		}
-		if($datequery2) {
-			$sql_extra2 .= protect_sprintf(sprintf(" AND item.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery2))));
-		}
+		if($update && $_SESSION['loadtime'])
+			$simple_update = " AND (( item_unseen = 1 AND item.changed > '" . datetime_convert('UTC','UTC',$_SESSION['loadtime']) . "' )  OR item.changed > '" . datetime_convert('UTC','UTC',$_SESSION['loadtime']) . "' ) ";
+		if($load)
+			$simple_update = '';
 
-		$itemspage = get_pconfig(local_channel(),'system','itemspage');
-		\App::set_pager_itemspage(((intval($itemspage)) ? $itemspage : 20));
-		$pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval(\App::$pager['itemspage']), intval(\App::$pager['start']));
+		if(($update) && (! $load)) {
 
-		if($load || ($checkjs->disabled())) {
-			if ($mid) {
-				$r = q("SELECT parent AS item_id from item where mid = '%s' and uid = %d $item_normal
-					AND item_wall = 1 $sql_extra limit 1",
-					dbesc($mid),
+			if($mid) {
+				$r = q("SELECT parent AS item_id from item where mid like '%s' and uid = %d $item_normal
+					AND item_wall = 1 AND item_unseen = 1 $sql_extra limit 1",
+					dbesc($mid . '%'),
 					intval(\App::$profile['profile_uid'])
 				);
-				if (! $r) {
-					notice( t('Permission denied.') . EOL);
-				}
-
-			} else {
-				$r = q("SELECT distinct id AS item_id, created FROM item 
-					left join abook on item.author_xchan = abook.abook_xchan
+			} 
+			else {
+				$r = q("SELECT distinct parent AS `item_id`, created from item
+					left join abook on ( item.owner_xchan = abook.abook_xchan $abook_uids )
 					WHERE uid = %d $item_normal
-					AND item_wall = 1 and item_thread_top = 1
-					AND (abook_blocked = 0 or abook.abook_flags is null)
-					$sql_extra $sql_extra2
-					ORDER BY created DESC $pager_sql ",
+					AND item_wall = 1 $simple_update
+					AND (abook.abook_blocked = 0 or abook.abook_flags is null)
+					$sql_extra
+					ORDER BY created DESC",
 					intval(\App::$profile['profile_uid'])
 				);
+				$_SESSION['loadtime'] = datetime_convert();
 			}
+
 		}
 		else {
-			$r = array();
-		}
-	}
 
-	if($r) {
+			if(x($category)) {
+			        $sql_extra .= protect_sprintf(term_query('item', $category, TERM_CATEGORY));
+			}
+			if(x($hashtags)) {
+			        $sql_extra .= protect_sprintf(term_query('item', $hashtags, TERM_HASHTAG, TERM_COMMUNITYTAG));
+			}
 
-		$parents_str = ids_to_querystr($r,'item_id');
- 
-		$items = q("SELECT `item`.*, `item`.`id` AS `item_id` 
-			FROM `item`
-			WHERE `item`.`uid` = %d $item_normal
-			AND `item`.`parent` IN ( %s )
-			$sql_extra ",
-			intval(\App::$profile['profile_uid']),
-			dbesc($parents_str)
-		);
-
-		xchan_query($items);
-		$items = fetch_post_tags($items, true);
-		$items = conv_sort($items,'created');
-
-		if ($load && $mid && (! count($items))) {
-			// This will happen if we don't have sufficient permissions
-			// to view the parent item (or the item itself if it is toplevel)
-			notice( t('Permission denied.') . EOL);
+			if($datequery) {
+				$sql_extra2 .= protect_sprintf(sprintf(" AND item.created <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery))));
+			}
+			if($datequery2) {
+				$sql_extra2 .= protect_sprintf(sprintf(" AND item.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery2))));
+			}
+
+			$itemspage = get_pconfig(local_channel(),'system','itemspage');
+			\App::set_pager_itemspage(((intval($itemspage)) ? $itemspage : 20));
+			$pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval(\App::$pager['itemspage']), intval(\App::$pager['start']));
+
+			if($load || ($checkjs->disabled())) {
+				if($mid) {
+					$r = q("SELECT parent AS item_id from item where mid = '%s' and uid = %d $item_normal
+						AND item_wall = 1 $sql_extra limit 1",
+						dbesc($mid),
+						intval(\App::$profile['profile_uid'])
+					);
+					if (! $r) {
+						notice( t('Permission denied.') . EOL);
+					}
+
+				} 
+				else {
+					$r = q("SELECT distinct id AS item_id, created FROM item 
+						left join abook on item.author_xchan = abook.abook_xchan
+						WHERE uid = %d $item_normal
+						AND item_wall = 1 and item_thread_top = 1
+						AND (abook_blocked = 0 or abook.abook_flags is null)
+						$sql_extra $sql_extra2
+						ORDER BY created DESC $pager_sql ",
+						intval(\App::$profile['profile_uid'])
+					);
+				}
+			}
+			else {
+				$r = array();
+			}
 		}
 
-	} else {
-		$items = array();
-	}
+		if($r) {
 
-	if((! $update) && (! $load)) {
-
-		// This is ugly, but we can't pass the profile_uid through the session to the ajax updater,
-		// because browser prefetching might change it on us. We have to deliver it with the page.
-
-		$maxheight = get_pconfig(\App::$profile['profile_uid'],'system','channel_divmore_height');
-		if(! $maxheight)
-			$maxheight = 400;
-
-		$o .= '
' . "\r\n"; - $o .= "\r\n"; - - \App::$page['htmlhead'] .= replace_macros(get_markup_template("build_query.tpl"),array( - '$baseurl' => z_root(), - '$pgtype' => 'channel', - '$uid' => ((\App::$profile['profile_uid']) ? \App::$profile['profile_uid'] : '0'), - '$gid' => '0', - '$cid' => '0', - '$cmin' => '0', - '$cmax' => '0', - '$star' => '0', - '$liked' => '0', - '$conv' => '0', - '$spam' => '0', - '$nouveau' => '0', - '$wall' => '1', - '$fh' => '0', - '$page' => ((\App::$pager['page'] != 1) ? \App::$pager['page'] : 1), - '$search' => '', - '$order' => '', - '$list' => ((x($_REQUEST,'list')) ? intval($_REQUEST['list']) : 0), - '$file' => '', - '$cats' => (($category) ? $category : ''), - '$tags' => (($hashtags) ? $hashtags : ''), - '$mid' => $mid, - '$verb' => '', - '$dend' => $datequery, - '$dbegin' => $datequery2 - )); + $parents_str = ids_to_querystr($r,'item_id'); + + $items = q("SELECT `item`.*, `item`.`id` AS `item_id` + FROM `item` + WHERE `item`.`uid` = %d $item_normal + AND `item`.`parent` IN ( %s ) + $sql_extra ", + intval(\App::$profile['profile_uid']), + dbesc($parents_str) + ); + xchan_query($items); + $items = fetch_post_tags($items, true); + $items = conv_sort($items,'created'); - } + if($load && $mid && (! count($items))) { + // This will happen if we don't have sufficient permissions + // to view the parent item (or the item itself if it is toplevel) + notice( t('Permission denied.') . EOL); + } - $update_unseen = ''; + } + else { + $items = array(); + } - if($page_mode === 'list') { + if((! $update) && (! $load)) { + + // This is ugly, but we can't pass the profile_uid through the session to the ajax updater, + // because browser prefetching might change it on us. We have to deliver it with the page. + + $maxheight = get_pconfig(\App::$profile['profile_uid'],'system','channel_divmore_height'); + if(! $maxheight) + $maxheight = 400; + + $o .= '
' . "\r\n"; + $o .= "\r\n"; + + \App::$page['htmlhead'] .= replace_macros(get_markup_template("build_query.tpl"),array( + '$baseurl' => z_root(), + '$pgtype' => 'channel', + '$uid' => ((\App::$profile['profile_uid']) ? \App::$profile['profile_uid'] : '0'), + '$gid' => '0', + '$cid' => '0', + '$cmin' => '0', + '$cmax' => '0', + '$star' => '0', + '$liked' => '0', + '$conv' => '0', + '$spam' => '0', + '$nouveau' => '0', + '$wall' => '1', + '$fh' => '0', + '$page' => ((\App::$pager['page'] != 1) ? \App::$pager['page'] : 1), + '$search' => '', + '$order' => '', + '$list' => ((x($_REQUEST,'list')) ? intval($_REQUEST['list']) : 0), + '$file' => '', + '$cats' => (($category) ? $category : ''), + '$tags' => (($hashtags) ? $hashtags : ''), + '$mid' => $mid, + '$verb' => '', + '$dend' => $datequery, + '$dbegin' => $datequery2 + )); - /** - * in "list mode", only mark the parent item and any like activities as "seen". - * We won't distinguish between comment likes and post likes. The important thing - * is that the number of unseen comments will be accurate. The SQL to separate the - * comment likes could also get somewhat hairy. - */ - if($parents_str) { - $update_unseen = " AND ( id IN ( " . dbesc($parents_str) . " )"; - $update_unseen .= " OR ( parent IN ( " . dbesc($parents_str) . " ) AND verb in ( '" . dbesc(ACTIVITY_LIKE) . "','" . dbesc(ACTIVITY_DISLIKE) . "' ))) "; - } - } - else { - if($parents_str) { - $update_unseen = " AND parent IN ( " . dbesc($parents_str) . " )"; } - } - if($is_owner && $update_unseen) { - $r = q("UPDATE item SET item_unseen = 0 where item_unseen = 1 and item_wall = 1 AND uid = %d $update_unseen", - intval(local_channel()) - ); - } + $update_unseen = ''; + if($page_mode === 'list') { - if($checkjs->disabled()) { - $o .= conversation($a,$items,'channel',$update,'traditional'); - } else { - $o .= conversation($a,$items,'channel',$update,$page_mode); - } + /** + * in "list mode", only mark the parent item and any like activities as "seen". + * We won't distinguish between comment likes and post likes. The important thing + * is that the number of unseen comments will be accurate. The SQL to separate the + * comment likes could also get somewhat hairy. + */ - if((! $update) || ($checkjs->disabled())) { - $o .= alt_pager($a,count($items)); - if ($mid && $items[0]['title']) - \App::$page['title'] = $items[0]['title'] . " - " . \App::$page['title']; - } + if($parents_str) { + $update_unseen = " AND ( id IN ( " . dbesc($parents_str) . " )"; + $update_unseen .= " OR ( parent IN ( " . dbesc($parents_str) . " ) AND verb in ( '" . dbesc(ACTIVITY_LIKE) . "','" . dbesc(ACTIVITY_DISLIKE) . "' ))) "; + } + } + else { + if($parents_str) { + $update_unseen = " AND parent IN ( " . dbesc($parents_str) . " )"; + } + } + + if($is_owner && $update_unseen) { + $r = q("UPDATE item SET item_unseen = 0 where item_unseen = 1 and item_wall = 1 AND uid = %d $update_unseen", + intval(local_channel()) + ); + } - if($mid) - $o .= '
'; - return $o; -} + if($checkjs->disabled()) { + $o .= conversation($a,$items,'channel',$update,'traditional'); + } + else { + $o .= conversation($a,$items,'channel',$update,$page_mode); + } + if((! $update) || ($checkjs->disabled())) { + $o .= alt_pager($a,count($items)); + if ($mid && $items[0]['title']) + \App::$page['title'] = $items[0]['title'] . " - " . \App::$page['title']; + } + if($mid) + $o .= '
'; + + return $o; + } } \ No newline at end of file diff --git a/Zotlabs/Module/Directory.php b/Zotlabs/Module/Directory.php index b8bac53bb..560038ffc 100644 --- a/Zotlabs/Module/Directory.php +++ b/Zotlabs/Module/Directory.php @@ -57,9 +57,9 @@ class Directory extends \Zotlabs\Web\Controller { } } - function get() { + function get() { - if((get_config('system','block_public')) && (! local_channel()) && (! remote_channel())) { + if(observer_prohibited()) { notice( t('Public access denied.') . EOL); return; } diff --git a/Zotlabs/Module/Display.php b/Zotlabs/Module/Display.php index 6e880cbb4..c1a0d84bc 100644 --- a/Zotlabs/Module/Display.php +++ b/Zotlabs/Module/Display.php @@ -7,17 +7,13 @@ class Display extends \Zotlabs\Web\Controller { function get($update = 0, $load = false) { - // logger("mod-display: update = $update load = $load"); - - $checkjs = new \Zotlabs\Web\CheckJS(1); - if($load) $_SESSION['loadtime'] = datetime_convert(); - if(intval(get_config('system','block_public')) && (! local_channel()) && (! remote_channel())) { + if(observer_prohibited()) { notice( t('Public access denied.') . EOL); return; } diff --git a/Zotlabs/Module/Feed.php b/Zotlabs/Module/Feed.php index 9d33ba2c3..47871eafb 100644 --- a/Zotlabs/Module/Feed.php +++ b/Zotlabs/Module/Feed.php @@ -31,7 +31,7 @@ class Feed extends \Zotlabs\Web\Controller { $channel = $r[0]; - if((intval(get_config('system','block_public'))) && (! get_account_id())) + if(observer_prohibited(true)) killme(); logger('mod_feed: public feed request from ' . $_SERVER['REMOTE_ADDR'] . ' for ' . $channel['channel_address']); diff --git a/Zotlabs/Module/Photos.php b/Zotlabs/Module/Photos.php index 266ac05e0..7186209ba 100644 --- a/Zotlabs/Module/Photos.php +++ b/Zotlabs/Module/Photos.php @@ -18,7 +18,7 @@ class Photos extends \Zotlabs\Web\Controller { function init() { - if((get_config('system','block_public')) && (! local_channel()) && (! remote_channel())) { + if(observer_prohibited()) { return; } @@ -518,7 +518,7 @@ class Photos extends \Zotlabs\Web\Controller { // photos/name/image/xxxxx - if((get_config('system','block_public')) && (! local_channel()) && (! remote_channel())) { + if(observer_prohibited()) { notice( t('Public access denied.') . EOL); return; } diff --git a/Zotlabs/Module/Profile.php b/Zotlabs/Module/Profile.php index 04a64fe76..8bf358bc8 100644 --- a/Zotlabs/Module/Profile.php +++ b/Zotlabs/Module/Profile.php @@ -55,8 +55,8 @@ class Profile extends \Zotlabs\Web\Controller { function get() { - if(get_config('system','block_public') && (! get_account_id()) && (! remote_channel())) { - return login(); + if(observer_prohibited(true)) { + return login(); } $groups = array(); diff --git a/Zotlabs/Module/Pubstream.php b/Zotlabs/Module/Pubstream.php index c25e04312..312be7718 100644 --- a/Zotlabs/Module/Pubstream.php +++ b/Zotlabs/Module/Pubstream.php @@ -12,7 +12,7 @@ class Pubstream extends \Zotlabs\Web\Controller { $_SESSION['loadtime'] = datetime_convert(); - if(get_config('system','block_public') && (! get_account_id()) && (! remote_channel())) { + if(observer_prohibited(true)) { return login(); } diff --git a/Zotlabs/Module/Ratings.php b/Zotlabs/Module/Ratings.php index 802bbfec2..969fb5015 100644 --- a/Zotlabs/Module/Ratings.php +++ b/Zotlabs/Module/Ratings.php @@ -8,7 +8,7 @@ class Ratings extends \Zotlabs\Web\Controller { function init() { - if((get_config('system','block_public')) && (! local_channel()) && (! remote_channel())) { + if(observer_prohibited()) { return; } @@ -80,9 +80,9 @@ class Ratings extends \Zotlabs\Web\Controller { - function get() { + function get() { - if((get_config('system','block_public')) && (! local_channel()) && (! remote_channel())) { + if(observer_prohibited()) { notice( t('Public access denied.') . EOL); return; } diff --git a/Zotlabs/Module/Viewconnections.php b/Zotlabs/Module/Viewconnections.php index d58c431e5..ea478f92a 100644 --- a/Zotlabs/Module/Viewconnections.php +++ b/Zotlabs/Module/Viewconnections.php @@ -7,7 +7,7 @@ class Viewconnections extends \Zotlabs\Web\Controller { function init() { - if((get_config('system','block_public')) && (! local_channel()) && (! remote_channel())) { + if(observer_prohibited()) { return; } if(argc() > 1) @@ -16,7 +16,7 @@ class Viewconnections extends \Zotlabs\Web\Controller { function get() { - if((get_config('system','block_public')) && (! local_channel()) && (! remote_channel())) { + if(observer_prohibited()) { notice( t('Public access denied.') . EOL); return; } diff --git a/Zotlabs/Module/Zotfeed.php b/Zotlabs/Module/Zotfeed.php index 28040149f..6b505c890 100644 --- a/Zotlabs/Module/Zotfeed.php +++ b/Zotlabs/Module/Zotfeed.php @@ -15,7 +15,7 @@ class Zotfeed extends \Zotlabs\Web\Controller { if(! $mindate) $mindate = datetime_convert('UTC','UTC', 'now - 14 days'); - if(get_config('system','block_public') && (! get_account_id()) && (! remote_channel())) { + if(observer_prohibited()) { $result['message'] = 'Public access denied'; json_return_and_die($result); } @@ -45,8 +45,6 @@ class Zotfeed extends \Zotlabs\Web\Controller { $result['messages'] = zot_feed($r[0]['channel_id'],$observer['xchan_hash'],array('mindate' => $mindate)); $result['success'] = true; json_return_and_die($result); - - } } -- cgit v1.2.3 From 2d06663490c5fd63b0ebbae141d0b2bbd5a4a8ca Mon Sep 17 00:00:00 2001 From: redmatrix Date: Sun, 22 May 2016 19:25:27 -0700 Subject: move apps to zlib --- Zotlabs/Module/Appman.php | 17 +++++++++-------- Zotlabs/Module/Apps.php | 17 +++++++++-------- 2 files changed, 18 insertions(+), 16 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Appman.php b/Zotlabs/Module/Appman.php index ba2a64f35..a200e986a 100644 --- a/Zotlabs/Module/Appman.php +++ b/Zotlabs/Module/Appman.php @@ -2,8 +2,9 @@ namespace Zotlabs\Module; -require_once('include/apps.php'); +//require_once('include/apps.php'); +use \Zotlabs\Lib as Zlib; class Appman extends \Zotlabs\Web\Controller { @@ -30,16 +31,16 @@ class Appman extends \Zotlabs\Web\Controller { 'categories' => escape_tags($_REQUEST['categories']) ); - $_REQUEST['appid'] = app_install(local_channel(),$arr); + $_REQUEST['appid'] = Zlib\Apps::app_install(local_channel(),$arr); - if(app_installed(local_channel(),$arr)) + if(Zlib\Apps::app_installed(local_channel(),$arr)) info( t('App installed.') . EOL); return; } - $papp = app_decode($_POST['papp']); + $papp = Zlib\Apps::app_decode($_POST['papp']); if(! is_array($papp)) { notice( t('Malformed app.') . EOL); @@ -47,13 +48,13 @@ class Appman extends \Zotlabs\Web\Controller { } if($_POST['install']) { - app_install(local_channel(),$papp); - if(app_installed(local_channel(),$papp)) + Zlib\Apps::app_install(local_channel(),$papp); + if(Zlib\Apps::app_installed(local_channel(),$papp)) info( t('App installed.') . EOL); } if($_POST['delete']) { - app_destroy(local_channel(),$papp); + Zlib\Apps::app_destroy(local_channel(),$papp); } if($_POST['edit']) { @@ -100,7 +101,7 @@ class Appman extends \Zotlabs\Web\Controller { } } - $embed = array('embed', t('Embed code'), app_encode($app,true),'', 'onclick="this.select();"'); + $embed = array('embed', t('Embed code'), Zlib\Apps::app_encode($app,true),'', 'onclick="this.select();"'); } diff --git a/Zotlabs/Module/Apps.php b/Zotlabs/Module/Apps.php index 33259b319..d3e8b1504 100644 --- a/Zotlabs/Module/Apps.php +++ b/Zotlabs/Module/Apps.php @@ -1,8 +1,9 @@ Date: Sun, 22 May 2016 19:26:21 -0700 Subject: add missing file --- Zotlabs/Lib/Apps.php | 659 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 659 insertions(+) create mode 100644 Zotlabs/Lib/Apps.php (limited to 'Zotlabs') diff --git a/Zotlabs/Lib/Apps.php b/Zotlabs/Lib/Apps.php new file mode 100644 index 000000000..6d2ef4e45 --- /dev/null +++ b/Zotlabs/Lib/Apps.php @@ -0,0 +1,659 @@ + $v) { + if(strpos($v,'http') === 0) + $ret[$k] = zid($v); + } + + if(array_key_exists('desc',$ret)) + $ret['desc'] = str_replace(array('\'','"'),array(''','&dquot;'),$ret['desc']); + + if(array_key_exists('target',$ret)) + $ret['target'] = str_replace(array('\'','"'),array(''','&dquot;'),$ret['target']); + + if(array_key_exists('requires',$ret)) { + $requires = explode(',',$ret['requires']); + foreach($requires as $require) { + $require = trim(strtolower($require)); + switch($require) { + case 'nologin': + if(local_channel()) + unset($ret); + break; + case 'admin': + if(! is_site_admin()) + unset($ret); + break; + case 'local_channel': + if(! local_channel()) + unset($ret); + break; + case 'public_profile': + if(! is_public_profile()) + unset($ret); + break; + case 'observer': + if(! $observer) + unset($ret); + break; + default: + if(! (local_channel() && feature_enabled(local_channel(),$require))) + unset($ret); + break; + + } + } + } + if($ret) { + if($translate) + self::translate_system_apps($ret); + return $ret; + } + return false; + } + + + static public function translate_system_apps(&$arr) { + $apps = array( + 'Site Admin' => t('Site Admin'), + 'Bug Report' => t('Bug Report'), + 'View Bookmarks' => t('View Bookmarks'), + 'My Chatrooms' => t('My Chatrooms'), + 'Connections' => t('Connections'), + 'Firefox Share' => t('Firefox Share'), + 'Remote Diagnostics' => t('Remote Diagnostics'), + 'Suggest Channels' => t('Suggest Channels'), + 'Login' => t('Login'), + 'Channel Manager' => t('Channel Manager'), + 'Grid' => t('Grid'), + 'Settings' => t('Settings'), + 'Files' => t('Files'), + 'Webpages' => t('Webpages'), + 'Channel Home' => t('Channel Home'), + 'View Profile' => t('View Profile'), + 'Photos' => t('Photos'), + 'Events' => t('Events'), + 'Directory' => t('Directory'), + 'Help' => t('Help'), + 'Mail' => t('Mail'), + 'Mood' => t('Mood'), + 'Poke' => t('Poke'), + 'Chat' => t('Chat'), + 'Search' => t('Search'), + 'Probe' => t('Probe'), + 'Suggest' => t('Suggest'), + 'Random Channel' => t('Random Channel'), + 'Invite' => t('Invite'), + 'Features' => t('Features'), + 'Language' => t('Language'), + 'Post' => t('Post'), + 'Profile Photo' => t('Profile Photo') + ); + + if(array_key_exists($arr['name'],$apps)) + $arr['name'] = $apps[$arr['name']]; + + } + + + // papp is a portable app + + static public function app_render($papp,$mode = 'view') { + + /** + * modes: + * view: normal mode for viewing an app via bbcode from a conversation or page + * provides install/update button if you're logged in locally + * list: normal mode for viewing an app on the app page + * no buttons are shown + * edit: viewing the app page in editing mode provides a delete button + */ + + $installed = false; + + if(! $papp) + return; + + if(! $papp['photo']) + $papp['photo'] = z_root() . '/' . get_default_profile_photo(80); + + $papp['papp'] = self::papp_encode($papp); + + if(! strstr($papp['url'],'://')) + $papp['url'] = z_root() . ((strpos($papp['url'],'/') === 0) ? '' : '/') . $papp['url']; + + foreach($papp as $k => $v) { + if(strpos($v,'http') === 0 && $k != 'papp') + $papp[$k] = zid($v); + if($k === 'desc') + $papp['desc'] = str_replace(array('\'','"'),array(''','&dquot;'),$papp['desc']); + + if($k === 'requires') { + $requires = explode(',',$v); + foreach($requires as $require) { + $require = trim(strtolower($require)); + switch($require) { + case 'nologin': + if(local_channel()) + return ''; + break; + case 'admin': + if(! is_site_admin()) + return ''; + break; + case 'local_channel': + if(! local_channel()) + return ''; + break; + case 'public_profile': + if(! is_public_profile()) + return ''; + break; + case 'observer': + $observer = \App::get_observer(); + if(! $observer) + return ''; + break; + default: + if(! (local_channel() && feature_enabled(local_channel(),$require))) + return ''; + break; + + } + } + } + } + + $hosturl = ''; + + if(local_channel()) { + $installed = self::app_installed(local_channel(),$papp); + $hosturl = z_root() . '/'; + } + elseif(remote_channel()) { + $observer = \App::get_observer(); + if($observer && $observer['xchan_network'] === 'zot') { + // some folks might have xchan_url redirected offsite, use the connurl + $x = parse_url($observer['xchan_connurl']); + if($x) { + $hosturl = $x['scheme'] . '://' . $x['host'] . '/'; + } + } + } + + $install_action = (($installed) ? t('Update') : t('Install')); + + return replace_macros(get_markup_template('app.tpl'),array( + '$app' => $papp, + '$hosturl' => $hosturl, + '$purchase' => (($papp['page'] && (! $installed)) ? t('Purchase') : ''), + '$install' => (($hosturl && $mode == 'view') ? $install_action : ''), + '$edit' => ((local_channel() && $installed && $mode == 'edit') ? t('Edit') : ''), + '$delete' => ((local_channel() && $installed && $mode == 'edit') ? t('Delete') : '') + )); + } + + static public function app_install($uid,$app) { + $app['uid'] = $uid; + + if(self::app_installed($uid,$app)) + $x = self::app_update($app); + else + $x = self::app_store($app); + + if($x['success']) { + $r = q("select * from app where app_id = '%s' and app_channel = %d limit 1", + dbesc($x['app_id']), + intval($uid) + ); + if($r) { + if(! $r[0]['app_system']) { + if($app['categories'] && (! $app['term'])) { + $r[0]['term'] = q("select * from term where otype = %d and oid = d", + intval(TERM_OBJ_APP), + intval($r[0]['id']) + ); + build_sync_packet($uid,array('app' => $r[0])); + } + } + } + return $x['app_id']; + } + return false; + } + + static public function app_destroy($uid,$app) { + + + if($uid && $app['guid']) { + + $x = q("select * from app where app_id = '%s' and app_channel = %d limit 1", + dbesc($app['guid']), + intval($uid) + ); + if($x) { + $x[0]['app_deleted'] = 1; + q("delete from term where otype = %d and oid = %d", + intval(TERM_OBJ_APP), + intval($x[0]['id']) + ); + if($x[0]['app_system']) { + $r = q("update app set app_deleted = 1 where app_id = '%s' and app_channel = %d", + dbesc($app['guid']), + intval($uid) + ); + } + else { + $r = q("delete from app where app_id = '%s' and app_channel = %d", + dbesc($app['guid']), + intval($uid) + ); + + // we don't sync system apps - they may be completely different on the other system + build_sync_packet($uid,array('app' => $x)); + } + } + } + } + + + static public function app_installed($uid,$app) { + + $r = q("select id from app where app_id = '%s' and app_version = '%s' and app_channel = %d limit 1", + dbesc((array_key_exists('guid',$app)) ? $app['guid'] : ''), + dbesc((array_key_exists('version',$app)) ? $app['version'] : ''), + intval($uid) + ); + return(($r) ? true : false); + + } + + + static public function app_list($uid, $deleted = false, $cat = '') { + if($deleted) + $sql_extra = " and app_deleted = 1 "; + else + $sql_extra = " and app_deleted = 0 "; + + if($cat) { + $r = q("select oid from term where otype = %d and term = '%s'", + intval(TERM_OBJ_APP), + dbesc($cat) + ); + if(! $r) + return $r; + $sql_extra .= " and app.id in ( "; + $s = ''; + foreach($r as $rr) { + if($s) + $s .= ','; + $s .= intval($rr['oid']); + } + $sql_extra .= $s . ') '; + } + + $r = q("select * from app where app_channel = %d $sql_extra order by app_name asc", + intval($uid) + ); + if($r) { + for($x = 0; $x < count($r); $x ++) { + if(! $r[$x]['app_system']) + $r[$x]['type'] = 'personal'; + $r[$x]['term'] = q("select * from term where otype = %d and oid = %d", + intval(TERM_OBJ_APP), + intval($r[$x]['id']) + ); + } + } + return($r); + } + + + static public function app_decode($s) { + $x = base64_decode(str_replace(array('
',"\r","\n",' '),array('','','',''),$s)); + return json_decode($x,true); + } + + + static public function app_store($arr) { + + // logger('app_store: ' . print_r($arr,true)); + + $darray = array(); + $ret = array('success' => false); + + $darray['app_url'] = ((x($arr,'url')) ? $arr['url'] : ''); + $darray['app_channel'] = ((x($arr,'uid')) ? $arr['uid'] : 0); + + if((! $darray['app_url']) || (! $darray['app_channel'])) + return $ret; + + if($arr['photo'] && ! strstr($arr['photo'],z_root())) { + $x = import_xchan_photo($arr['photo'],get_observer_hash(),true); + $arr['photo'] = $x[1]; + } + + + $darray['app_id'] = ((x($arr,'guid')) ? $arr['guid'] : random_string(). '.' . \App::get_hostname()); + $darray['app_sig'] = ((x($arr,'sig')) ? $arr['sig'] : ''); + $darray['app_author'] = ((x($arr,'author')) ? $arr['author'] : get_observer_hash()); + $darray['app_name'] = ((x($arr,'name')) ? escape_tags($arr['name']) : t('Unknown')); + $darray['app_desc'] = ((x($arr,'desc')) ? escape_tags($arr['desc']) : ''); + $darray['app_photo'] = ((x($arr,'photo')) ? $arr['photo'] : z_root() . '/' . get_default_profile_photo(80)); + $darray['app_version'] = ((x($arr,'version')) ? escape_tags($arr['version']) : ''); + $darray['app_addr'] = ((x($arr,'addr')) ? escape_tags($arr['addr']) : ''); + $darray['app_price'] = ((x($arr,'price')) ? escape_tags($arr['price']) : ''); + $darray['app_page'] = ((x($arr,'page')) ? escape_tags($arr['page']) : ''); + $darray['app_requires'] = ((x($arr,'requires')) ? escape_tags($arr['requires']) : ''); + $darray['app_system'] = ((x($arr,'system')) ? intval($arr['system']) : 0); + $darray['app_deleted'] = ((x($arr,'deleted')) ? intval($arr['deleted']) : 0); + + $created = datetime_convert(); + + $r = q("insert into app ( app_id, app_sig, app_author, app_name, app_desc, app_url, app_photo, app_version, app_channel, app_addr, app_price, app_page, app_requires, app_created, app_edited, app_system, app_deleted ) values ( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, %d )", + dbesc($darray['app_id']), + dbesc($darray['app_sig']), + dbesc($darray['app_author']), + dbesc($darray['app_name']), + dbesc($darray['app_desc']), + dbesc($darray['app_url']), + dbesc($darray['app_photo']), + dbesc($darray['app_version']), + intval($darray['app_channel']), + dbesc($darray['app_addr']), + dbesc($darray['app_price']), + dbesc($darray['app_page']), + dbesc($darray['app_requires']), + dbesc($created), + dbesc($created), + intval($darray['app_system']), + intval($darray['app_deleted']) + ); + if($r) { + $ret['success'] = true; + $ret['app_id'] = $darray['app_id']; + } + if($arr['categories']) { + $x = q("select id from app where app_id = '%s' and app_channel = %d limit 1", + dbesc($darray['app_id']), + intval($darray['app_channel']) + ); + $y = explode(',',$arr['categories']); + if($y) { + foreach($y as $t) { + $t = trim($t); + if($t) { + store_item_tag($darray['app_channel'],$x[0]['id'],TERM_OBJ_APP,TERM_CATEGORY,escape_tags($t),escape_tags(z_root() . '/apps/?f=&cat=' . escape_tags($t))); + } + } + } + } + + return $ret; + } + + + static public function app_update($arr) { + + $darray = array(); + $ret = array('success' => false); + + $darray['app_url'] = ((x($arr,'url')) ? $arr['url'] : ''); + $darray['app_channel'] = ((x($arr,'uid')) ? $arr['uid'] : 0); + $darray['app_id'] = ((x($arr,'guid')) ? $arr['guid'] : 0); + + if((! $darray['app_url']) || (! $darray['app_channel']) || (! $darray['app_id'])) + return $ret; + + if($arr['photo'] && ! strstr($arr['photo'],z_root())) { + $x = import_xchan_photo($arr['photo'],get_observer_hash(),true); + $arr['photo'] = $x[1]; + } + + $darray['app_sig'] = ((x($arr,'sig')) ? $arr['sig'] : ''); + $darray['app_author'] = ((x($arr,'author')) ? $arr['author'] : get_observer_hash()); + $darray['app_name'] = ((x($arr,'name')) ? escape_tags($arr['name']) : t('Unknown')); + $darray['app_desc'] = ((x($arr,'desc')) ? escape_tags($arr['desc']) : ''); + $darray['app_photo'] = ((x($arr,'photo')) ? $arr['photo'] : z_root() . '/' . get_default_profile_photo(80)); + $darray['app_version'] = ((x($arr,'version')) ? escape_tags($arr['version']) : ''); + $darray['app_addr'] = ((x($arr,'addr')) ? escape_tags($arr['addr']) : ''); + $darray['app_price'] = ((x($arr,'price')) ? escape_tags($arr['price']) : ''); + $darray['app_page'] = ((x($arr,'page')) ? escape_tags($arr['page']) : ''); + $darray['app_requires'] = ((x($arr,'requires')) ? escape_tags($arr['requires']) : ''); + $darray['app_system'] = ((x($arr,'system')) ? intval($arr['system']) : 0); + $darray['app_deleted'] = ((x($arr,'deleted')) ? intval($arr['deleted']) : 0); + + $edited = datetime_convert(); + + $r = q("update app set app_sig = '%s', app_author = '%s', app_name = '%s', app_desc = '%s', app_url = '%s', app_photo = '%s', app_version = '%s', app_addr = '%s', app_price = '%s', app_page = '%s', app_requires = '%s', app_edited = '%s', app_system = %d, app_deleted = %d where app_id = '%s' and app_channel = %d", + dbesc($darray['app_sig']), + dbesc($darray['app_author']), + dbesc($darray['app_name']), + dbesc($darray['app_desc']), + dbesc($darray['app_url']), + dbesc($darray['app_photo']), + dbesc($darray['app_version']), + dbesc($darray['app_addr']), + dbesc($darray['app_price']), + dbesc($darray['app_page']), + dbesc($darray['app_requires']), + dbesc($edited), + intval($darray['app_system']), + intval($darray['app_deleted']), + dbesc($darray['app_id']), + intval($darray['app_channel']) + ); + if($r) { + $ret['success'] = true; + $ret['app_id'] = $darray['app_id']; + } + + $x = q("select id from app where app_id = '%s' and app_channel = %d limit 1", + dbesc($darray['app_id']), + intval($darray['app_channel']) + ); + if($x) { + q("delete from term where otype = %d and oid = %d", + intval(TERM_OBJ_APP), + intval($x[0]['id']) + ); + if($arr['categories']) { + $y = explode(',',$arr['categories']); + if($y) { + foreach($y as $t) { + $t = trim($t); + if($t) { + store_item_tag($darray['app_channel'],$x[0]['id'],TERM_OBJ_APP,TERM_CATEGORY,escape_tags($t),escape_tags(z_root() . '/apps/?f=&cat=' . escape_tags($t))); + } + } + } + } + } + + return $ret; + + } + + + static public function app_encode($app,$embed = false) { + + $ret = array(); + + $ret['type'] = 'personal'; + + if($app['app_id']) + $ret['guid'] = $app['app_id']; + + if($app['app_id']) + $ret['guid'] = $app['app_id']; + + if($app['app_sig']) + $ret['sig'] = $app['app_sig']; + + if($app['app_author']) + $ret['author'] = $app['app_author']; + + if($app['app_name']) + $ret['name'] = $app['app_name']; + + if($app['app_desc']) + $ret['desc'] = $app['app_desc']; + + if($app['app_url']) + $ret['url'] = $app['app_url']; + + if($app['app_photo']) + $ret['photo'] = $app['app_photo']; + + if($app['app_version']) + $ret['version'] = $app['app_version']; + + if($app['app_addr']) + $ret['addr'] = $app['app_addr']; + + if($app['app_price']) + $ret['price'] = $app['app_price']; + + if($app['app_page']) + $ret['page'] = $app['app_page']; + + if($app['app_requires']) + $ret['requires'] = $app['app_requires']; + + if($app['app_system']) + $ret['system'] = $app['app_system']; + + if($app['app_deleted']) + $ret['deleted'] = $app['app_deleted']; + + if($app['term']) { + $s = ''; + foreach($app['term'] as $t) { + if($s) + $s .= ','; + $s .= $t['term']; + } + $ret['categories'] = $s; + } + + + if(! $embed) + return $ret; + + if(array_key_exists('categories',$ret)) + unset($ret['categories']); + + $j = json_encode($ret); + return '[app]' . chunk_split(base64_encode($j),72,"\n") . '[/app]'; + + } + + + static public function papp_encode($papp) { + return chunk_split(base64_encode(json_encode($papp)),72,"\n"); + + } + +} + + -- cgit v1.2.3 From 1aa3051e977dceb04fbe656763d8ef8a9803a571 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Sun, 22 May 2016 20:54:52 -0700 Subject: move chatroom stuff to zlib --- Zotlabs/Lib/Chatroom.php | 267 +++++++++++++++++++++++++++++++++++++++++++++ Zotlabs/Module/Chat.php | 22 ++-- Zotlabs/Module/Chatsvc.php | 12 +- 3 files changed, 286 insertions(+), 15 deletions(-) create mode 100644 Zotlabs/Lib/Chatroom.php (limited to 'Zotlabs') diff --git a/Zotlabs/Lib/Chatroom.php b/Zotlabs/Lib/Chatroom.php new file mode 100644 index 000000000..e1a9a10b3 --- /dev/null +++ b/Zotlabs/Lib/Chatroom.php @@ -0,0 +1,267 @@ + false); + + $name = trim($arr['name']); + if(! $name) { + $ret['message'] = t('Missing room name'); + return $ret; + } + + $r = q("select cr_id from chatroom where cr_uid = %d and cr_name = '%s' limit 1", + intval($channel['channel_id']), + dbesc($name) + ); + if($r) { + $ret['message'] = t('Duplicate room name'); + return $ret; + } + + $r = q("select count(cr_id) as total from chatroom where cr_aid = %d", + intval($channel['channel_account_id']) + ); + if($r) + $limit = service_class_fetch($channel['channel_id'], 'chatrooms'); + + if(($r) && ($limit !== false) && ($r[0]['total'] >= $limit)) { + $ret['message'] = upgrade_message(); + return $ret; + } + + if(! array_key_exists('expire', $arr)) + $arr['expire'] = 120; // minutes, e.g. 2 hours + + $created = datetime_convert(); + + $x = q("insert into chatroom ( cr_aid, cr_uid, cr_name, cr_created, cr_edited, cr_expire, allow_cid, allow_gid, deny_cid, deny_gid ) + values ( %d, %d , '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s' ) ", + intval($channel['channel_account_id']), + intval($channel['channel_id']), + dbesc($name), + dbesc($created), + dbesc($created), + intval($arr['expire']), + dbesc($arr['allow_cid']), + dbesc($arr['allow_gid']), + dbesc($arr['deny_cid']), + dbesc($arr['deny_gid']) + ); + + if($x) + $ret['success'] = true; + + return $ret; + } + + + static public function destroy($channel,$arr) { + + $ret = array('success' => false); + + if(intval($arr['cr_id'])) + $sql_extra = " and cr_id = " . intval($arr['cr_id']) . " "; + elseif(trim($arr['cr_name'])) + $sql_extra = " and cr_name = '" . protect_sprintf(dbesc(trim($arr['cr_name']))) . "' "; + else { + $ret['message'] = t('Invalid room specifier.'); + return $ret; + } + + $r = q("select * from chatroom where cr_uid = %d $sql_extra limit 1", + intval($channel['channel_id']) + ); + if(! $r) { + $ret['message'] = t('Invalid room specifier.'); + return $ret; + } + + build_sync_packet($channel['channel_id'],array('chatroom' => $r)); + + q("delete from chatroom where cr_id = %d", + intval($r[0]['cr_id']) + ); + if($r[0]['cr_id']) { + q("delete from chatpresence where cp_room = %d", + intval($r[0]['cr_id']) + ); + q("delete from chat where chat_room = %d", + intval($r[0]['cr_id']) + ); + } + + $ret['success'] = true; + return $ret; + } + + + static public function enter($observer_xchan, $room_id, $status, $client) { + + if(! $room_id || ! $observer_xchan) + return; + + $r = q("select * from chatroom where cr_id = %d limit 1", + intval($room_id) + ); + if(! $r) { + notice( t('Room not found.') . EOL); + return false; + } + require_once('include/security.php'); + $sql_extra = permissions_sql($r[0]['cr_uid']); + + $x = q("select * from chatroom where cr_id = %d and cr_uid = %d $sql_extra limit 1", + intval($room_id), + intval($r[0]['cr_uid']) + ); + if(! $x) { + notice( t('Permission denied.') . EOL); + return false; + } + + $limit = service_class_fetch($r[0]['cr_uid'], 'chatters_inroom'); + if($limit !== false) { + $y = q("select count(*) as total from chatpresence where cp_room = %d", + intval($room_id) + ); + if($y && $y[0]['total'] > $limit) { + notice( t('Room is full') . EOL); + return false; + } + } + + if(intval($x[0]['cr_expire'])) { + $r = q("delete from chat where created < %s - INTERVAL %s and chat_room = %d", + db_utcnow(), + db_quoteinterval( intval($x[0]['cr_expire']) . ' MINUTE' ), + intval($x[0]['cr_id']) + ); + } + + $r = q("select * from chatpresence where cp_xchan = '%s' and cp_room = %d limit 1", + dbesc($observer_xchan), + intval($room_id) + ); + if($r) { + q("update chatpresence set cp_last = '%s' where cp_id = %d and cp_client = '%s'", + dbesc(datetime_convert()), + intval($r[0]['cp_id']), + dbesc($client) + ); + return true; + } + + $r = q("insert into chatpresence ( cp_room, cp_xchan, cp_last, cp_status, cp_client ) + values ( %d, '%s', '%s', '%s', '%s' )", + intval($room_id), + dbesc($observer_xchan), + dbesc(datetime_convert()), + dbesc($status), + dbesc($client) + ); + + return $r; + } + + + function leave($observer_xchan, $room_id, $client) { + if(! $room_id || ! $observer_xchan) + return; + + $r = q("select * from chatpresence where cp_xchan = '%s' and cp_room = %d and cp_client = '%s' limit 1", + dbesc($observer_xchan), + intval($room_id), + dbesc($client) + ); + if($r) { + q("delete from chatpresence where cp_id = %d", + intval($r[0]['cp_id']) + ); + } + + return true; + } + + + static public function roomlist($uid) { + require_once('include/security.php'); + $sql_extra = permissions_sql($uid); + + $r = q("select allow_cid, allow_gid, deny_cid, deny_gid, cr_name, cr_expire, cr_id, count(cp_id) as cr_inroom from chatroom left join chatpresence on cr_id = cp_room where cr_uid = %d $sql_extra group by cr_name, cr_id order by cr_name", + intval($uid) + ); + + return $r; + } + + static public function list_count($uid) { + require_once('include/security.php'); + $sql_extra = permissions_sql($uid); + + $r = q("select count(*) as total from chatroom where cr_uid = %d $sql_extra", + intval($uid) + ); + + return $r[0]['total']; + } + + /** + * create a chat message via API. + * It is the caller's responsibility to enter the room. + */ + + static public function message($uid, $room_id, $xchan, $text) { + + $ret = array('success' => false); + + if(! $text) + return; + + $sql_extra = permissions_sql($uid); + + $r = q("select * from chatroom where cr_uid = %d and cr_id = %d $sql_extra", + intval($uid), + intval($room_id) + ); + if(! $r) + return $ret; + + $arr = array( + 'chat_room' => $room_id, + 'chat_xchan' => $xchan, + 'chat_text' => $text + ); + + call_hooks('chat_message', $arr); + + $x = q("insert into chat ( chat_room, chat_xchan, created, chat_text ) + values( %d, '%s', '%s', '%s' )", + intval($room_id), + dbesc($xchan), + dbesc(datetime_convert()), + dbesc($arr['chat_text']) + ); + + $ret['success'] = true; + return $ret; + } +} diff --git a/Zotlabs/Module/Chat.php b/Zotlabs/Module/Chat.php index 9508ed3de..d14c32b7d 100644 --- a/Zotlabs/Module/Chat.php +++ b/Zotlabs/Module/Chat.php @@ -1,9 +1,11 @@ - $room)); + Zlib\Chatroom::destroy($channel,array('cr_name' => $room)); goaway(z_root() . '/chat/' . $channel['channel_address']); } @@ -67,7 +69,7 @@ class Chat extends \Zotlabs\Web\Controller { if(intval($arr['expire']) < 0) $arr['expire'] = 0; - chatroom_create($channel,$arr); + Zlib\Chatroom::create($channel,$arr); $x = q("select * from chatroom where cr_name = '%s' and cr_uid = %d limit 1", dbesc($room), @@ -87,7 +89,7 @@ class Chat extends \Zotlabs\Web\Controller { } - function get() { + function get() { if(local_channel()) $channel = \App::get_channel(); @@ -105,7 +107,7 @@ class Chat extends \Zotlabs\Web\Controller { } if((argc() > 3) && intval(argv(2)) && (argv(3) === 'leave')) { - chatroom_leave($observer,argv(2),$_SERVER['REMOTE_ADDR']); + Zlib\Chatroom::leave($observer,argv(2),$_SERVER['REMOTE_ADDR']); goaway(z_root() . '/channel/' . argv(1)); } @@ -158,7 +160,7 @@ class Chat extends \Zotlabs\Web\Controller { $room_id = intval(argv(2)); $bookmark_link = get_bookmark_link($ob); - $x = chatroom_enter($observer,$room_id,'online',$_SERVER['REMOTE_ADDR']); + $x = Zlib\Chatroom::enter($observer,$room_id,'online',$_SERVER['REMOTE_ADDR']); if(! $x) return; $x = q("select * from chatroom where cr_id = %d and cr_uid = %d $sql_extra limit 1", @@ -238,7 +240,7 @@ class Chat extends \Zotlabs\Web\Controller { )); } - $rooms = chatroom_list(\App::$profile['profile_uid']); + $rooms = Zlib\Chatroom::roomlist(\App::$profile['profile_uid']); $o .= replace_macros(get_markup_template('chatrooms.tpl'), array( '$header' => sprintf( t('%1$s\'s Chatrooms'), \App::$profile['name']), diff --git a/Zotlabs/Module/Chatsvc.php b/Zotlabs/Module/Chatsvc.php index a9bc97301..6a28a7c4d 100644 --- a/Zotlabs/Module/Chatsvc.php +++ b/Zotlabs/Module/Chatsvc.php @@ -1,14 +1,16 @@ - false); @@ -27,7 +29,7 @@ class Chatsvc extends \Zotlabs\Web\Controller { } - function post() { + function post() { $ret = array('success' => false); @@ -65,7 +67,7 @@ class Chatsvc extends \Zotlabs\Web\Controller { json_return_and_die($ret); } - function get() { + function get() { $status = strip_tags($_REQUEST['status']); $room_id = intval(\App::$data['chat']['room_id']); -- cgit v1.2.3 From a1aa3d906159e4ad563779e5f220dddbfbd744c4 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Sun, 22 May 2016 22:08:01 -0700 Subject: Can't use "use x as y" aliases in callback function declarations --- Zotlabs/Module/Apps.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Apps.php b/Zotlabs/Module/Apps.php index d3e8b1504..4bdec4573 100644 --- a/Zotlabs/Module/Apps.php +++ b/Zotlabs/Module/Apps.php @@ -33,7 +33,7 @@ class Apps extends \Zotlabs\Web\Controller { else $syslist = Zlib\Apps::get_system_apps(true); - usort($syslist,'Zlib\\Apps::app_name_compare'); + usort($syslist,'Zotlabs\\Lib\\Apps::app_name_compare'); // logger('apps: ' . print_r($syslist,true)); -- cgit v1.2.3 From bbc71343bdfc724425927ebab404b035c65f569c Mon Sep 17 00:00:00 2001 From: redmatrix Date: Sun, 22 May 2016 22:44:13 -0700 Subject: change the signed token format. We don't folks to be able to submit random text for signing by us, as they could then use these to generate known signatures. --- Zotlabs/Zot/Finger.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Zot/Finger.php b/Zotlabs/Zot/Finger.php index 63fdd4a4c..07798fbb1 100644 --- a/Zotlabs/Zot/Finger.php +++ b/Zotlabs/Zot/Finger.php @@ -110,7 +110,7 @@ class Finger { if($x) { $signed_token = ((is_array($x) && array_key_exists('signed_token',$x)) ? $x['signed_token'] : null); if($signed_token) { - $valid = rsa_verify(self::$token,base64url_decode($signed_token),$x['key']); + $valid = rsa_verify('token.' . self::$token,base64url_decode($signed_token),$x['key']); if(! $valid) { logger('invalid signed token: ' . $url . $rhs, LOGGER_NORMAL, LOG_WARN); return $ret; -- cgit v1.2.3 From 80b422bdbe570e70adc2e55473f9e29a045722fe Mon Sep 17 00:00:00 2001 From: redmatrix Date: Mon, 23 May 2016 13:49:54 -0700 Subject: typo --- Zotlabs/Module/Connedit.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Connedit.php b/Zotlabs/Module/Connedit.php index c9b20ae14..c5c38b96a 100644 --- a/Zotlabs/Module/Connedit.php +++ b/Zotlabs/Module/Connedit.php @@ -230,7 +230,7 @@ class Connedit extends \Zotlabs\Web\Controller { if(\App::$poi && \App::$poi['abook_my_perms'] != $abook_my_perms && (! intval(\App::$poi['abook_self']))) { - \Zotlabs\Daemon\Master(array('Notifier', (($new_friend) ? 'permission_create' : 'permission_update'), $contact_id)); + \Zotlabs\Daemon\Master::Summon(array('Notifier', (($new_friend) ? 'permission_create' : 'permission_update'), $contact_id)); } if($new_friend) { -- cgit v1.2.3 From 29ba8918093166ac32ef9a727a9b71ba8e01a402 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Tue, 24 May 2016 01:25:13 -0700 Subject: moved enotify --- Zotlabs/Lib/Enotify.php | 685 ++++++++++++++++++++++++++++++++++++++++++++++++ Zotlabs/Module/Item.php | 6 +- Zotlabs/Module/Ping.php | 5 +- 3 files changed, 691 insertions(+), 5 deletions(-) create mode 100644 Zotlabs/Lib/Enotify.php (limited to 'Zotlabs') diff --git a/Zotlabs/Lib/Enotify.php b/Zotlabs/Lib/Enotify.php new file mode 100644 index 000000000..c6405dac2 --- /dev/null +++ b/Zotlabs/Lib/Enotify.php @@ -0,0 +1,685 @@ +'); + + if ($params['type'] == NOTIFY_MAIL) { + logger('notification: mail'); + $subject = sprintf( t('[Hubzilla:Notify] New mail received at %s'),$sitename); + + $preamble = sprintf( t('%1$s, %2$s sent you a new private message at %3$s.'),$recip['channel_name'], $sender['xchan_name'],$sitename); + $epreamble = sprintf( t('%1$s sent you %2$s.'),'[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]', '[zrl=$itemlink]' . t('a private message') . '[/zrl]'); + $sitelink = t('Please visit %s to view and/or reply to your private messages.'); + $tsitelink = sprintf( $sitelink, $siteurl . '/mail/' . $params['item']['id'] ); + $hsitelink = sprintf( $sitelink, '' . $sitename . ''); + $itemlink = $siteurl . '/mail/' . $params['item']['id']; + } + + if ($params['type'] == NOTIFY_COMMENT) { +// logger("notification: params = " . print_r($params, true), LOGGER_DEBUG); + + $itemlink = $params['link']; + + // ignore like/unlike activity on posts - they probably require a sepearate notification preference + + if (array_key_exists('item',$params) && (! visible_activity($params['item']))) + return; + + $parent_mid = $params['parent_mid']; + + // Check to see if there was already a notify for this post. + // If so don't create a second notification + + $p = null; + $p = q("select id from notify where link = '%s' and uid = %d limit 1", + dbesc($params['link']), + intval($recip['channel_id']) + ); + if ($p) { + logger('notification: comment already notified'); + pop_lang(); + return; + } + + + // if it's a post figure out who's post it is. + + $p = null; + + if($params['otype'] === 'item' && $parent_mid) { + $p = q("select * from item where mid = '%s' and uid = %d limit 1", + dbesc($parent_mid), + intval($recip['channel_id']) + ); + } + + xchan_query($p); + + + $item_post_type = item_post_type($p[0]); +// $private = $p[0]['item_private']; + $parent_id = $p[0]['id']; + + $parent_item = $p[0]; + + //$possess_desc = str_replace('',$possess_desc); + + // "a post" + $dest_str = sprintf(t('%1$s, %2$s commented on [zrl=%3$s]a %4$s[/zrl]'), + $recip['channel_name'], + '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]', + $itemlink, + $item_post_type); + + // "George Bull's post" + if($p) + $dest_str = sprintf(t('%1$s, %2$s commented on [zrl=%3$s]%4$s\'s %5$s[/zrl]'), + $recip['channel_name'], + '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]', + $itemlink, + $p[0]['author']['xchan_name'], + $item_post_type); + + // "your post" + if($p[0]['owner']['xchan_name'] == $p[0]['author']['xchan_name'] && intval($p[0]['item_wall'])) + $dest_str = sprintf(t('%1$s, %2$s commented on [zrl=%3$s]your %4$s[/zrl]'), + $recip['channel_name'], + '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]', + $itemlink, + $item_post_type); + + // Some mail softwares relies on subject field for threading. + // So, we cannot have different subjects for notifications of the same thread. + // Before this we have the name of the replier on the subject rendering + // differents subjects for messages on the same thread. + + $subject = sprintf( t('[Hubzilla:Notify] Comment to conversation #%1$d by %2$s'), $parent_id, $sender['xchan_name']); + $preamble = sprintf( t('%1$s, %2$s commented on an item/conversation you have been following.'), $recip['channel_name'], $sender['xchan_name']); + $epreamble = $dest_str; + + $sitelink = t('Please visit %s to view and/or reply to the conversation.'); + $tsitelink = sprintf( $sitelink, $siteurl ); + $hsitelink = sprintf( $sitelink, '' . $sitename . ''); + } + + if($params['type'] == NOTIFY_WALL) { + $subject = sprintf( t('[Hubzilla:Notify] %s posted to your profile wall') , $sender['xchan_name']); + + $preamble = sprintf( t('%1$s, %2$s posted to your profile wall at %3$s') , $recip['channel_name'], $sender['xchan_name'], $sitename); + + $epreamble = sprintf( t('%1$s, %2$s posted to [zrl=%3$s]your wall[/zrl]') , + $recip['channel_name'], + '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]', + $params['link']); + + $sitelink = t('Please visit %s to view and/or reply to the conversation.'); + $tsitelink = sprintf( $sitelink, $siteurl ); + $hsitelink = sprintf( $sitelink, '' . $sitename . ''); + $itemlink = $params['link']; + } + + if ($params['type'] == NOTIFY_TAGSELF) { + + $p = null; + $p = q("select id from notify where link = '%s' and uid = %d limit 1", + dbesc($params['link']), + intval($recip['channel_id']) + ); + if ($p) { + logger('enotify: tag: already notified about this post'); + pop_lang(); + return; + } + + $subject = sprintf( t('[Hubzilla:Notify] %s tagged you') , $sender['xchan_name']); + $preamble = sprintf( t('%1$s, %2$s tagged you at %3$s') , $recip['channel_name'], $sender['xchan_name'], $sitename); + $epreamble = sprintf( t('%1$s, %2$s [zrl=%3$s]tagged you[/zrl].') , + $recip['channel_name'], + '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]', + $params['link']); + + $sitelink = t('Please visit %s to view and/or reply to the conversation.'); + $tsitelink = sprintf( $sitelink, $siteurl ); + $hsitelink = sprintf( $sitelink, '' . $sitename . ''); + $itemlink = $params['link']; + } + + if ($params['type'] == NOTIFY_POKE) { + $subject = sprintf( t('[Hubzilla:Notify] %1$s poked you') , $sender['xchan_name']); + $preamble = sprintf( t('%1$s, %2$s poked you at %3$s') , $recip['channel_name'], $sender['xchan_name'], $sitename); + $epreamble = sprintf( t('%1$s, %2$s [zrl=%2$s]poked you[/zrl].') , + $recip['channel_name'], + '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]', + $params['link']); + + $subject = str_replace('poked', t($params['activity']), $subject); + $preamble = str_replace('poked', t($params['activity']), $preamble); + $epreamble = str_replace('poked', t($params['activity']), $epreamble); + + $sitelink = t('Please visit %s to view and/or reply to the conversation.'); + $tsitelink = sprintf( $sitelink, $siteurl ); + $hsitelink = sprintf( $sitelink, '' . $sitename . ''); + $itemlink = $params['link']; + } + + if ($params['type'] == NOTIFY_TAGSHARE) { + $subject = sprintf( t('[Hubzilla:Notify] %s tagged your post') , $sender['xchan_name']); + $preamble = sprintf( t('%1$s, %2$s tagged your post at %3$s') , $recip['channel_name'],$sender['xchan_name'], $sitename); + $epreamble = sprintf( t('%1$s, %2$s tagged [zrl=%3$s]your post[/zrl]') , + $recip['channel_name'], + '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]', + $itemlink); + + $sitelink = t('Please visit %s to view and/or reply to the conversation.'); + $tsitelink = sprintf( $sitelink, $siteurl ); + $hsitelink = sprintf( $sitelink, '' . $sitename . ''); + $itemlink = $params['link']; + } + + if ($params['type'] == NOTIFY_INTRO) { + $subject = sprintf( t('[Hubzilla:Notify] Introduction received')); + $preamble = sprintf( t('%1$s, you\'ve received an new connection request from \'%2$s\' at %3$s'), $recip['channel_name'], $sender['xchan_name'], $sitename); + $epreamble = sprintf( t('%1$s, you\'ve received [zrl=%2$s]a new connection request[/zrl] from %3$s.'), + $recip['channel_name'], + $siteurl . '/connections/ifpending', + '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]'); + $body = sprintf( t('You may visit their profile at %s'),$sender['xchan_url']); + + $sitelink = t('Please visit %s to approve or reject the connection request.'); + $tsitelink = sprintf( $sitelink, $siteurl . '/connections/ifpending'); + $hsitelink = sprintf( $sitelink, '' . $sitename . ''); + $itemlink = $params['link']; + } + + if ($params['type'] == NOTIFY_SUGGEST) { + $subject = sprintf( t('[Hubzilla:Notify] Friend suggestion received')); + $preamble = sprintf( t('%1$s, you\'ve received a friend suggestion from \'%2$s\' at %3$s'), $recip['channel_name'], $sender['xchan_name'], $sitename); + $epreamble = sprintf( t('%1$s, you\'ve received [zrl=%2$s]a friend suggestion[/zrl] for %3$s from %4$s.'), + $recip['channel_name'], + $itemlink, + '[zrl=' . $params['item']['url'] . ']' . $params['item']['name'] . '[/zrl]', + '[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]'); + + $body = t('Name:') . ' ' . $params['item']['name'] . "\n"; + $body .= t('Photo:') . ' ' . $params['item']['photo'] . "\n"; + $body .= sprintf( t('You may visit their profile at %s'),$params['item']['url']); + + $sitelink = t('Please visit %s to approve or reject the suggestion.'); + $tsitelink = sprintf( $sitelink, $siteurl ); + $hsitelink = sprintf( $sitelink, '' . $sitename . ''); + $itemlink = $params['link']; + } + + if ($params['type'] == NOTIFY_CONFIRM) { + // ? + } + + if ($params['type'] == NOTIFY_SYSTEM) { + // ? + } + + $h = array( + 'params' => $params, + 'subject' => $subject, + 'preamble' => $preamble, + 'epreamble' => $epreamble, + 'body' => $body, + 'sitelink' => $sitelink, + 'sitename' => $sitename, + 'tsitelink' => $tsitelink, + 'hsitelink' => $hsitelink, + 'itemlink' => $itemlink, + 'sender' => $sender, + 'recipient' => $recip + ); + + call_hooks('enotify', $h); + + $subject = $h['subject']; + $preamble = $h['preamble']; + $epreamble = $h['epreamble']; + $body = $h['body']; + $sitelink = $h['sitelink']; + $tsitelink = $h['tsitelink']; + $hsitelink = $h['hsitelink']; + $itemlink = $h['itemlink']; + + + require_once('include/html2bbcode.php'); + + do { + $dups = false; + $hash = random_string(); + $r = q("SELECT `id` FROM `notify` WHERE `hash` = '%s' LIMIT 1", + dbesc($hash)); + if (count($r)) + $dups = true; + } while ($dups === true); + + + $datarray = array(); + $datarray['hash'] = $hash; + $datarray['sender_hash'] = $sender['xchan_hash']; + $datarray['name'] = $sender['xchan_name']; + $datarray['url'] = $sender['xchan_url']; + $datarray['photo'] = $sender['xchan_photo_s']; + $datarray['date'] = datetime_convert(); + $datarray['aid'] = $recip['channel_account_id']; + $datarray['uid'] = $recip['channel_id']; + $datarray['link'] = $itemlink; + $datarray['parent'] = $parent_mid; + $datarray['parent_item'] = $parent_item; + $datarray['type'] = $params['type']; + $datarray['verb'] = $params['verb']; + $datarray['otype'] = $params['otype']; + $datarray['abort'] = false; + + $datarray['item'] = $params['item']; + + call_hooks('enotify_store', $datarray); + + if ($datarray['abort']) { + pop_lang(); + return; + } + + + // create notification entry in DB + $seen = 0; + + // Mark some notifications as seen right away + // Note! The notification have to be created, because they are used to send emails + // So easiest solution to hide them from Notices is to mark them as seen right away. + // Another option would be to not add them to the DB, and change how emails are handled (probably would be better that way) + $always_show_in_notices = get_pconfig($recip['channel_id'],'system','always_show_in_notices'); + if (!$always_show_in_notices) { + if (($params['type'] == NOTIFY_WALL) || ($params['type'] == NOTIFY_MAIL) || ($params['type'] == NOTIFY_INTRO)) { + $seen = 1; + } + } + + $r = q("insert into notify (hash,name,url,photo,date,aid,uid,link,parent,seen,type,verb,otype) + values('%s','%s','%s','%s','%s',%d,%d,'%s','%s',%d,%d,'%s','%s')", + dbesc($datarray['hash']), + dbesc($datarray['name']), + dbesc($datarray['url']), + dbesc($datarray['photo']), + dbesc($datarray['date']), + intval($datarray['aid']), + intval($datarray['uid']), + dbesc($datarray['link']), + dbesc($datarray['parent']), + intval($seen), + intval($datarray['type']), + dbesc($datarray['verb']), + dbesc($datarray['otype']) + ); + + $r = q("select id from notify where hash = '%s' and uid = %d limit 1", + dbesc($hash), + intval($recip['channel_id']) + ); + if ($r) { + $notify_id = $r[0]['id']; + } else { + logger('notification not found.'); + pop_lang(); + return; + } + + $itemlink = z_root() . '/notify/view/' . $notify_id; + $msg = str_replace('$itemlink',$itemlink,$epreamble); + + // wretched hack, but we don't want to duplicate all the preamble variations and we also don't want to screw up a translation + + if ((\App::$language === 'en' || (! \App::$language)) && strpos($msg,', ')) + $msg = substr($msg,strpos($msg,', ')+1); + + $r = q("update notify set msg = '%s' where id = %d and uid = %d", + dbesc($msg), + intval($notify_id), + intval($datarray['uid']) + ); + + // send email notification if notification preferences permit + + require_once('bbcode.php'); + if ((intval($recip['channel_notifyflags']) & intval($params['type'])) || $params['type'] == NOTIFY_SYSTEM) { + + logger('notification: sending notification email'); + + $hn = get_pconfig($recip['channel_id'],'system','email_notify_host'); + if($hn && (! stristr(\App::get_hostname(),$hn))) { + // this isn't the email notification host + pop_lang(); + return; + } + + $textversion = strip_tags(html_entity_decode(bbcode(stripslashes(str_replace(array("\\r", "\\n"), array( "", "\n"), $body))),ENT_QUOTES,'UTF-8')); + + $htmlversion = bbcode(stripslashes(str_replace(array("\\r","\\n"), array("","
\n"),$body))); + + + // use $_SESSION['zid_override'] to force zid() to use + // the recipient address instead of the current observer + + $_SESSION['zid_override'] = $recip['channel_address'] . '@' . \App::get_hostname(); + $_SESSION['zrl_override'] = z_root() . '/channel/' . $recip['channel_address']; + + $textversion = zidify_links($textversion); + $htmlversion = zidify_links($htmlversion); + + // unset when done to revert to normal behaviour + + unset($_SESSION['zid_override']); + unset($_SESSION['zrl_override']); + + $datarray = array(); + $datarray['banner'] = $banner; + $datarray['product'] = $product; + $datarray['preamble'] = $preamble; + $datarray['sitename'] = $sitename; + $datarray['siteurl'] = $siteurl; + $datarray['type'] = $params['type']; + $datarray['parent'] = $params['parent_mid']; + $datarray['source_name'] = $sender['xchan_name']; + $datarray['source_link'] = $sender['xchan_url']; + $datarray['source_photo'] = $sender['xchan_photo_s']; + $datarray['uid'] = $recip['channel_id']; + $datarray['username'] = $recip['channel_name']; + $datarray['hsitelink'] = $hsitelink; + $datarray['tsitelink'] = $tsitelink; + $datarray['hitemlink'] = '' . $itemlink . ''; + $datarray['titemlink'] = $itemlink; + $datarray['thanks'] = $thanks; + $datarray['site_admin'] = $site_admin; + $datarray['title'] = stripslashes($title); + $datarray['htmlversion'] = $htmlversion; + $datarray['textversion'] = $textversion; + $datarray['subject'] = $subject; + $datarray['headers'] = $additional_mail_header; + $datarray['email_secure'] = false; + + call_hooks('enotify_mail', $datarray); + + // Default to private - don't disclose message contents over insecure channels (such as email) + // Might be interesting to use GPG,PGP,S/MIME encryption instead + // but we'll save that for a clever plugin developer to implement + + $private_activity = false; + + if (! $datarray['email_secure']) { + switch ($params['type']) { + case NOTIFY_WALL: + case NOTIFY_TAGSELF: + case NOTIFY_POKE: + case NOTIFY_COMMENT: + if (! $private) + break; + $private_activity = true; + case NOTIFY_MAIL: + $datarray['textversion'] = $datarray['htmlversion'] = $datarray['title'] = ''; + $datarray['subject'] = preg_replace('/' . preg_quote(t('[Hubzilla:Notify]')) . '/','$0*',$datarray['subject']); + break; + default: + break; + } + } + + if ($private_activity + && intval(get_pconfig($datarray['uid'], 'system', 'ignore_private_notifications'))) { + + pop_lang(); + return; + } + + // load the template for private message notifications + $tpl = get_markup_template('email_notify_html.tpl'); + $email_html_body = replace_macros($tpl,array( + '$banner' => $datarray['banner'], + '$notify_icon' => \Zotlabs\Lib\System::get_notify_icon(), + '$product' => $datarray['product'], + '$preamble' => $datarray['preamble'], + '$sitename' => $datarray['sitename'], + '$siteurl' => $datarray['siteurl'], + '$source_name' => $datarray['source_name'], + '$source_link' => $datarray['source_link'], + '$source_photo' => $datarray['source_photo'], + '$username' => $datarray['to_name'], + '$hsitelink' => $datarray['hsitelink'], + '$hitemlink' => $datarray['hitemlink'], + '$thanks' => $datarray['thanks'], + '$site_admin' => $datarray['site_admin'], + '$title' => $datarray['title'], + '$htmlversion' => $datarray['htmlversion'], + )); + + // load the template for private message notifications + $tpl = get_markup_template('email_notify_text.tpl'); + $email_text_body = replace_macros($tpl, array( + '$banner' => $datarray['banner'], + '$product' => $datarray['product'], + '$preamble' => $datarray['preamble'], + '$sitename' => $datarray['sitename'], + '$siteurl' => $datarray['siteurl'], + '$source_name' => $datarray['source_name'], + '$source_link' => $datarray['source_link'], + '$source_photo' => $datarray['source_photo'], + '$username' => $datarray['to_name'], + '$tsitelink' => $datarray['tsitelink'], + '$titemlink' => $datarray['titemlink'], + '$thanks' => $datarray['thanks'], + '$site_admin' => $datarray['site_admin'], + '$title' => $datarray['title'], + '$textversion' => $datarray['textversion'], + )); + +// logger('text: ' . $email_text_body); + + // use the EmailNotification library to send the message + + self::send(array( + 'fromName' => $sender_name, + 'fromEmail' => $sender_email, + 'replyTo' => $sender_email, + 'toEmail' => $recip['account_email'], + 'messageSubject' => $datarray['subject'], + 'htmlVersion' => $email_html_body, + 'textVersion' => $email_text_body, + 'additionalMailHeader' => $datarray['headers'], + )); + } + + pop_lang(); + +} + + + /** + * @brief Send a multipart/alternative message with Text and HTML versions. + * + * @param array $params an assoziative array with: + * * \e string \b fromName name of the sender + * * \e string \b fromEmail email of the sender + * * \e string \b replyTo replyTo address to direct responses + * * \e string \b toEmail destination email address + * * \e string \b messageSubject subject of the message + * * \e string \b htmlVersion html version of the message + * * \e string \b textVersion text only version of the message + * * \e string \b additionalMailHeader additions to the smtp mail header + */ + static public function send($params) { + + $fromName = email_header_encode(html_entity_decode($params['fromName'],ENT_QUOTES,'UTF-8'),'UTF-8'); + $messageSubject = email_header_encode(html_entity_decode($params['messageSubject'],ENT_QUOTES,'UTF-8'),'UTF-8'); + + // generate a mime boundary + $mimeBoundary = rand(0, 9) . "-" + .rand(10000000000, 9999999999) . "-" + .rand(10000000000, 9999999999) . "=:" + .rand(10000, 99999); + + // generate a multipart/alternative message header + $messageHeader = + $params['additionalMailHeader'] . + "From: $fromName <{$params['fromEmail']}>\n" . + "Reply-To: $fromName <{$params['replyTo']}>\n" . + "MIME-Version: 1.0\n" . + "Content-Type: multipart/alternative; boundary=\"{$mimeBoundary}\""; + + // assemble the final multipart message body with the text and html types included + $textBody = chunk_split(base64_encode($params['textVersion'])); + $htmlBody = chunk_split(base64_encode($params['htmlVersion'])); + + $multipartMessageBody = + "--" . $mimeBoundary . "\n" . // plain text section + "Content-Type: text/plain; charset=UTF-8\n" . + "Content-Transfer-Encoding: base64\n\n" . + $textBody . "\n" . + "--" . $mimeBoundary . "\n" . // text/html section + "Content-Type: text/html; charset=UTF-8\n" . + "Content-Transfer-Encoding: base64\n\n" . + $htmlBody . "\n" . + "--" . $mimeBoundary . "--\n"; // message ending + + // send the message + $res = mail( + $params['toEmail'], // send to address + $messageSubject, // subject + $multipartMessageBody, // message body + $messageHeader // message headers + ); + logger("notification: enotify::send returns " . $res, LOGGER_DEBUG); + } + + static public function forma($item) { + + $ret = ''; + + require_once('include/conversation.php'); + + // Call localize_item with the "brief" flag to get a one line status for activities. + // This should set $item['localized'] to indicate we have a brief summary. + + localize_item($item); + + if($item_localize) { + $itemem_text = $item['localize']; + } + else { + $itemem_text = (($item['item_thread_top']) + ? t('created a new post') + : sprintf( t('commented on %s\'s post'), $item['owner']['xchan_name'])); + } + + // convert this logic into a json array just like the system notifications + + return array( + 'notify_link' => $item['llink'], + 'name' => $item['author']['xchan_name'], + 'url' => $item['author']['xchan_url'], + 'photo' => $item['author']['xchan_photo_s'], + 'when' => relative_date($item['created']), + 'class' => (intval($item['item_unseen']) ? 'notify-unseen' : 'notify-seen'), + 'message' => strip_tags(bbcode($itemem_text)) + ); + + } + +} diff --git a/Zotlabs/Module/Item.php b/Zotlabs/Module/Item.php index b4f493e5b..041939ad8 100644 --- a/Zotlabs/Module/Item.php +++ b/Zotlabs/Module/Item.php @@ -17,10 +17,10 @@ namespace Zotlabs\Module; */ require_once('include/crypto.php'); -require_once('include/enotify.php'); require_once('include/items.php'); require_once('include/attach.php'); +use \Zotlabs\Lib as Zlib; class Item extends \Zotlabs\Web\Controller { @@ -925,7 +925,7 @@ class Item extends \Zotlabs\Web\Controller { // otherwise it will happen during delivery if(($datarray['owner_xchan'] != $datarray['author_xchan']) && (intval($parent_item['item_wall']))) { - notification(array( + Zlib\Enotify::submit(array( 'type' => NOTIFY_COMMENT, 'from_xchan' => $datarray['author_xchan'], 'to_xchan' => $datarray['owner_xchan'], @@ -943,7 +943,7 @@ class Item extends \Zotlabs\Web\Controller { $parent = $post_id; if(($datarray['owner_xchan'] != $datarray['author_xchan']) && ($datarray['item_type'] == ITEM_TYPE_POST)) { - notification(array( + Zlib\Enotify::submit(array( 'type' => NOTIFY_WALL, 'from_xchan' => $datarray['author_xchan'], 'to_xchan' => $datarray['owner_xchan'], diff --git a/Zotlabs/Module/Ping.php b/Zotlabs/Module/Ping.php index bea4a08b7..f0caa4373 100644 --- a/Zotlabs/Module/Ping.php +++ b/Zotlabs/Module/Ping.php @@ -1,12 +1,13 @@ Date: Tue, 24 May 2016 16:36:55 -0700 Subject: relocate index and db --- Zotlabs/Module/Setup.php | 26 ++++--- Zotlabs/Web/WebServer.php | 191 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 205 insertions(+), 12 deletions(-) create mode 100644 Zotlabs/Web/WebServer.php (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Setup.php b/Zotlabs/Module/Setup.php index 462ccced6..b913190b1 100644 --- a/Zotlabs/Module/Setup.php +++ b/Zotlabs/Module/Setup.php @@ -82,11 +82,11 @@ class Setup extends \Zotlabs\Web\Controller { $siteurl = rtrim($siteurl,'/'); require_once('include/dba/dba_driver.php'); - unset($db); - $db = dba_factory($dbhost, $dbport, $dbuser, $dbpass, $dbdata, $dbtype, true); + + $db = \DBA::dba_factory($dbhost, $dbport, $dbuser, $dbpass, $dbdata, $dbtype, true); - if(! $db->connected) { - echo 'Database Connect failed: ' . $db->error; + if(! \DBA::$dba->connected) { + echo 'Database Connect failed: ' . DBA::$dba->error; killme(); \App::$data['db_conn_failed']=true; } @@ -138,10 +138,12 @@ class Setup extends \Zotlabs\Web\Controller { } } - // connect to db - $db = dba_factory($dbhost, $dbport, $dbuser, $dbpass, $dbdata, $dbtype, true); - - if(! $db->connected) { + if(! \DBA::$dba->connected) { + // connect to db + $db = \DBA::dba_factory($dbhost, $dbport, $dbuser, $dbpass, $dbdata, $dbtype, true); + } + + if(! \DBA::$dba->connected) { echo 'CRITICAL: DB not connected.'; killme(); } @@ -228,7 +230,7 @@ class Setup extends \Zotlabs\Web\Controller { $txt .= "
".\App::$data['db_failed'] . "
". EOL ; $db_return_text .= $txt; } - if($db && $db->connected) { + if(\DBA::$dba && \DBA::$dba->connected) { $r = q("SELECT COUNT(*) as `total` FROM `account`"); if($r && count($r) && $r[0]['total']) { $tpl = get_markup_template('install.tpl'); @@ -598,7 +600,7 @@ class Setup extends \Zotlabs\Web\Controller { if(! is_writable(TEMPLATE_BUILD_PATH) ) { $status = false; $help = t('Red uses the Smarty3 template engine to render its web views. Smarty3 compiles templates to PHP to speed up rendering.') .EOL; - $help .= sprintf( t('In order to store these compiled templates, the web server needs to have write access to the directory %s under the Red top level folder.'), TEMPLATE_BUILD_PATH) . EOL; + $help .= sprintf( t('In order to store these compiled templates, the web server needs to have write access to the directory %s under the top level web folder.'), TEMPLATE_BUILD_PATH) . EOL; $help .= t('Please ensure that the user that your web server runs as (e.g. www-data) has write access to this folder.').EOL; $help .= sprintf( t('Note: as a security measure, you should give the web server write access to %s only--not the template files (.tpl) that it contains.'), TEMPLATE_BUILD_PATH) . EOL; } @@ -698,12 +700,12 @@ class Setup extends \Zotlabs\Web\Controller { function load_database($db) { - $str = file_get_contents($db->get_install_script()); + $str = file_get_contents(\DBA::$dba->get_install_script()); $arr = explode(';',$str); $errors = false; foreach($arr as $a) { if(strlen(trim($a))) { - $r = @$db->q(trim($a)); + $r = dbq(trim($a)); if(! $r) { $errors .= t('Errors encountered creating database tables.') . $a . EOL; } diff --git a/Zotlabs/Web/WebServer.php b/Zotlabs/Web/WebServer.php new file mode 100644 index 000000000..98bf62c9a --- /dev/null +++ b/Zotlabs/Web/WebServer.php @@ -0,0 +1,191 @@ +convert(); + + \App::$timezone = ((x($default_timezone)) ? $default_timezone : 'UTC'); + date_default_timezone_set(\App::$timezone); + + + /* + * Try to open the database; + */ + + require_once('include/dba/dba_driver.php'); + + if(! \App::$install) { + $db = DBA::dba_factory($db_host, $db_port, $db_user, $db_pass, $db_data, $db_type, \App::$install); + if(! $db->connected) { + system_unavailable(); + } + + unset($db_host, $db_port, $db_user, $db_pass, $db_data, $db_type); + + /** + * Load configs from db. Overwrite configs from .htconfig.php + */ + + load_config('config'); + load_config('system'); + load_config('feature'); + + \App::$session = new Zotlabs\Web\Session(); + \App::$session->init(); + load_hooks(); + call_hooks('init_1'); + + } + + + \App::$language = get_best_language(); + load_translation_table(\App::$language,\App::$install); + + + /** + * + * Important stuff we always need to do. + * + * The order of these may be important so use caution if you think they're all + * intertwingled with no logical order and decide to sort it out. Some of the + * dependencies have changed, but at least at one time in the recent past - the + * order was critical to everything working properly + * + */ + + if(\App::$session) { + \App::$session->start(); + } + else { + session_start(); + register_shutdown_function('session_write_close'); + } + + /** + * Language was set earlier, but we can over-ride it in the session. + * We have to do it here because the session was just now opened. + */ + + if(array_key_exists('system_language',$_POST)) { + if(strlen($_POST['system_language'])) + $_SESSION['language'] = $_POST['system_language']; + else + unset($_SESSION['language']); + } + if((x($_SESSION, 'language')) && ($_SESSION['language'] !== $lang)) { + \App::$language = $_SESSION['language']; + load_translation_table(\App::$language); + } + + if((x($_GET,'zid')) && (! \App::$install)) { + \App::$query_string = strip_zids(\App::$query_string); + if(! local_channel()) { + $_SESSION['my_address'] = $_GET['zid']; + zid_init($a); + } + } + + if((x($_SESSION, 'authenticated')) || (x($_POST, 'auth-params')) || (\App::$module === 'login')) + require('include/auth.php'); + + if(! x($_SESSION, 'sysmsg')) + $_SESSION['sysmsg'] = array(); + + if(! x($_SESSION, 'sysmsg_info')) + $_SESSION['sysmsg_info'] = array(); + + /* + * check_config() is responsible for running update scripts. These automatically + * update the DB schema whenever we push a new one out. It also checks to see if + * any plugins have been added or removed and reacts accordingly. + */ + + + if(\App::$install) { + /* Allow an exception for the view module so that pcss will be interpreted during installation */ + if(\App::$module != 'view') + \App::$module = 'setup'; + } + else + check_config($a); + + nav_set_selected('nothing'); + + $Router = new Zotlabs\Web\Router($a); + + /* initialise content region */ + + if(! x(\App::$page, 'content')) + \App::$page['content'] = ''; + + call_hooks('page_content_top', \App::$page['content']); + + + $Router->Dispatch($a); + + + // If you're just visiting, let javascript take you home + + if(x($_SESSION, 'visitor_home')) { + $homebase = $_SESSION['visitor_home']; + } elseif(local_channel()) { + $homebase = z_root() . '/channel/' . \App::$channel['channel_address']; + } + + if(isset($homebase)) { + \App::$page['content'] .= ''; + } + + // now that we've been through the module content, see if the page reported + // a permission problem and if so, a 403 response would seem to be in order. + + if(stristr(implode("", $_SESSION['sysmsg']), t('Permission denied'))) { + header($_SERVER['SERVER_PROTOCOL'] . ' 403 ' . t('Permission denied.')); + } + + call_hooks('page_end', \App::$page['content']); + + construct_page($a); + + killme(); + } +} \ No newline at end of file -- cgit v1.2.3 From 516c43ba154dc43ec0ef6135fb0a9732d0185a6f Mon Sep 17 00:00:00 2001 From: redmatrix Date: Tue, 24 May 2016 17:54:45 -0700 Subject: more work associated with DBA and index.php shuffle --- Zotlabs/Module/Setup.php | 41 ++++++++--------------------------------- Zotlabs/Web/WebServer.php | 15 ++++++--------- 2 files changed, 14 insertions(+), 42 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Setup.php b/Zotlabs/Module/Setup.php index b913190b1..447f46ed6 100644 --- a/Zotlabs/Module/Setup.php +++ b/Zotlabs/Module/Setup.php @@ -12,7 +12,6 @@ namespace Zotlabs\Module; /** * @brief Initialisation for the setup module. * - * @param[in,out] App &$a */ class Setup extends \Zotlabs\Web\Controller { @@ -54,16 +53,15 @@ class Setup extends \Zotlabs\Web\Controller { /** * @brief Handle the actions of the different setup steps. * - * @param[in,out] App &$a */ - function post() { - global $db; + + function post() { switch($this->install_wizard_pass) { case 1: case 2: return; - break; // just in case return don't return :) + // implied break; case 3: $urlpath = \App::get_path(); $dbhost = trim($_POST['dbhost']); @@ -88,33 +86,9 @@ class Setup extends \Zotlabs\Web\Controller { if(! \DBA::$dba->connected) { echo 'Database Connect failed: ' . DBA::$dba->error; killme(); - \App::$data['db_conn_failed']=true; } - /*if(get_db_errno()) { - unset($db); - $db = dba_factory($dbhost, $dbport, $dbuser, $dbpass, '', true); - - if(! get_db_errno()) { - $r = q("CREATE DATABASE '%s'", - dbesc($dbdata) - ); - if($r) { - unset($db); - $db = new dba($dbhost, $dbport, $dbuser, $dbpass, $dbdata, true); - } else { - \App::$data['db_create_failed']=true; - } - } else { - \App::$data['db_conn_failed']=true; - return; - } - }*/ - //if(get_db_errno()) { - - //} - return; - break; + // implied break; case 4: $urlpath = \App::get_path(); $dbhost = notags(trim($_POST['dbhost'])); @@ -177,6 +151,8 @@ class Setup extends \Zotlabs\Web\Controller { \App::$data['db_installed'] = true; return; + // implied break; + default: break; } } @@ -193,11 +169,10 @@ class Setup extends \Zotlabs\Web\Controller { * * Depending on the state we are currently in it returns different content. * - * @param App &$a * @return string parsed HTML output */ - function get() { - global $db; + + function get() { $o = ''; $wizard_status = ''; diff --git a/Zotlabs/Web/WebServer.php b/Zotlabs/Web/WebServer.php index 98bf62c9a..5237bf667 100644 --- a/Zotlabs/Web/WebServer.php +++ b/Zotlabs/Web/WebServer.php @@ -1,19 +1,16 @@ connected) { + \DBA::dba_factory($db_host, $db_port, $db_user, $db_pass, $db_data, $db_type, \App::$install); + if(! \DBA::$dba->connected) { system_unavailable(); } @@ -69,7 +66,7 @@ class WebServer { load_config('system'); load_config('feature'); - \App::$session = new Zotlabs\Web\Session(); + \App::$session = new Session(); \App::$session->init(); load_hooks(); call_hooks('init_1'); @@ -150,7 +147,7 @@ class WebServer { nav_set_selected('nothing'); - $Router = new Zotlabs\Web\Router($a); + $Router = new Router($a); /* initialise content region */ -- cgit v1.2.3 From c37eaff26331c49a2c8754f6d49c6145863f47ca Mon Sep 17 00:00:00 2001 From: redmatrix Date: Tue, 24 May 2016 23:05:00 -0700 Subject: require token signatures in zot_refresh, also move channel specific stuff into include/channel.php from include/connections.php --- Zotlabs/Daemon/Queue.php | 1 + 1 file changed, 1 insertion(+) (limited to 'Zotlabs') diff --git a/Zotlabs/Daemon/Queue.php b/Zotlabs/Daemon/Queue.php index c247be8e4..27306589d 100644 --- a/Zotlabs/Daemon/Queue.php +++ b/Zotlabs/Daemon/Queue.php @@ -6,6 +6,7 @@ require_once('include/queue_fn.php'); require_once('include/zot.php'); class Queue { + static public function run($argc,$argv) { require_once('include/items.php'); -- cgit v1.2.3 From 929d33fb22754e8525f3054b321891335b522faa Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 25 May 2016 14:18:41 +0200 Subject: another try on #385 - replace sabres restrictive CSP with what we do in boot.php --- Zotlabs/Module/Cloud.php | 3 +++ Zotlabs/Storage/Browser.php | 1 + 2 files changed, 4 insertions(+) (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Cloud.php b/Zotlabs/Module/Cloud.php index d9b0c47d4..b691475ce 100644 --- a/Zotlabs/Module/Cloud.php +++ b/Zotlabs/Module/Cloud.php @@ -100,9 +100,12 @@ class Cloud extends \Zotlabs\Web\Controller { // require_once('\Zotlabs\Storage/QuotaPlugin.php'); // $server->addPlugin(new \Zotlabs\Storage\\QuotaPlugin($auth)); + ob_start(); // All we need to do now, is to fire up the server $server->exec(); + ob_end_flush(); + killme(); } diff --git a/Zotlabs/Storage/Browser.php b/Zotlabs/Storage/Browser.php index 3556f7f06..f875cbf33 100644 --- a/Zotlabs/Storage/Browser.php +++ b/Zotlabs/Storage/Browser.php @@ -256,6 +256,7 @@ class Browser extends DAV\Browser\Plugin { $func($a); } } + $this->server->httpResponse->setHeader('Content-Security-Policy', "script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'"); construct_page($a); } -- cgit v1.2.3 From e559f8b6a105ca38d826d5fa672d984c2b57d06b Mon Sep 17 00:00:00 2001 From: redmatrix Date: Wed, 25 May 2016 16:48:32 -0700 Subject: duplicate daemon run of cronhooks --- Zotlabs/Daemon/Poller.php | 5 ----- 1 file changed, 5 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Daemon/Poller.php b/Zotlabs/Daemon/Poller.php index 278faf3ee..75efbf8f7 100644 --- a/Zotlabs/Daemon/Poller.php +++ b/Zotlabs/Daemon/Poller.php @@ -62,11 +62,6 @@ class Poller { $d = datetime_convert(); - // TODO check to see if there are any cronhooks before wasting a process - - if(! $restart) - Master::Summon(array('Cronhooks')); - // Only poll from those with suitable relationships $abandon_sql = (($abandon_days) -- cgit v1.2.3 From 2f64684299784126bb3bc80fbe9978ec57d19a4c Mon Sep 17 00:00:00 2001 From: redmatrix Date: Wed, 25 May 2016 20:06:21 -0700 Subject: some event fixes, also change jquery-textcomplete to un-minified since the minified version appears to require a mapping file and causes a lot of server fetch errors trying to load it. --- Zotlabs/Module/Events.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Events.php b/Zotlabs/Module/Events.php index 3440e0727..2b5e239f9 100644 --- a/Zotlabs/Module/Events.php +++ b/Zotlabs/Module/Events.php @@ -232,7 +232,7 @@ class Events extends \Zotlabs\Web\Controller { } if($share) - \Zotlabs\Daemon\Master(array('Notifier','event',$item_id)); + \Zotlabs\Daemon\Master::Summon(array('Notifier','event',$item_id)); } -- cgit v1.2.3 From 9017dcd0fd904ecdf54b75ad39588db4f2e91ea6 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Thu, 26 May 2016 14:23:17 +0200 Subject: typo --- Zotlabs/Module/Ping.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Ping.php b/Zotlabs/Module/Ping.php index f0caa4373..32427b06f 100644 --- a/Zotlabs/Module/Ping.php +++ b/Zotlabs/Module/Ping.php @@ -286,7 +286,7 @@ class Ping extends \Zotlabs\Web\Controller { foreach($r as $item) { if((argv(1) === 'home') && (! intval($item['item_wall']))) continue; - $result[] = \Zotlbas\Lib\Enotify::format($item); + $result[] = \Zotlabs\Lib\Enotify::format($item); } } // logger('ping (network||home): ' . print_r($result, true), LOGGER_DATA); -- cgit v1.2.3 From 24360fd19182cad5ed29d10bb47c208bc195c232 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Thu, 26 May 2016 14:33:10 +0200 Subject: check if $addonDir is a dir to silence warning if it does not exist --- Zotlabs/Module/Admin.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Admin.php b/Zotlabs/Module/Admin.php index 172b109c8..8f15035d1 100644 --- a/Zotlabs/Module/Admin.php +++ b/Zotlabs/Module/Admin.php @@ -1421,13 +1421,15 @@ class Admin extends \Zotlabs\Web\Controller { function listAddonRepos() { $addonrepos = []; $addonDir = __DIR__ . '/../../extend/addon/'; - if ($handle = opendir($addonDir)) { - while (false !== ($entry = readdir($handle))) { - if ($entry != "." && $entry != "..") { - $addonrepos[] = $entry; + if(is_dir($addonDir)) { + if ($handle = opendir($addonDir)) { + while (false !== ($entry = readdir($handle))) { + if ($entry != "." && $entry != "..") { + $addonrepos[] = $entry; + } } + closedir($handle); } - closedir($handle); } return $addonrepos; } -- cgit v1.2.3 From 9d7abd58ac004f8df733a8187b57f6a3bfc2520e Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Thu, 26 May 2016 14:37:30 +0200 Subject: another typo --- Zotlabs/Lib/Enotify.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Lib/Enotify.php b/Zotlabs/Lib/Enotify.php index c6405dac2..ccb538ef5 100644 --- a/Zotlabs/Lib/Enotify.php +++ b/Zotlabs/Lib/Enotify.php @@ -648,7 +648,7 @@ class Enotify { logger("notification: enotify::send returns " . $res, LOGGER_DEBUG); } - static public function forma($item) { + static public function format($item) { $ret = ''; -- cgit v1.2.3 From 096fdfc61b5381bd3f7918a7c5f6004461354f32 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Thu, 26 May 2016 16:33:01 -0700 Subject: consolidate all the sys_boot functionality that is common between the web server and the cli daemon manager. Get rid of yet another global variable ($default_timezone) whilst doing so. --- Zotlabs/Web/WebServer.php | 60 +---------------------------------------------- 1 file changed, 1 insertion(+), 59 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Web/WebServer.php b/Zotlabs/Web/WebServer.php index 5237bf667..88ab4995b 100644 --- a/Zotlabs/Web/WebServer.php +++ b/Zotlabs/Web/WebServer.php @@ -13,65 +13,7 @@ class WebServer { require_once('boot.php'); - if(file_exists('.htsite.php')) - include('.htsite.php'); - - - // miniApp is a conversion object from old style .htconfig.php files - - $a = new \miniApp; - - // our central App object - - \App::init(); - - /* - * Load the configuration file which contains our DB credentials. - * Ignore errors. If the file doesn't exist or is empty, we are running in - * installation mode. - */ - - \App::$install = ((file_exists('.htconfig.php') && filesize('.htconfig.php')) ? false : true); - - @include('.htconfig.php'); - - if(! defined('UNO')) - define('UNO', 0); - - $a->convert(); - - \App::$timezone = ((x($default_timezone)) ? $default_timezone : 'UTC'); - date_default_timezone_set(\App::$timezone); - - - /* - * Try to open the database; - */ - - require_once('include/dba/dba_driver.php'); - - if(! \App::$install) { - \DBA::dba_factory($db_host, $db_port, $db_user, $db_pass, $db_data, $db_type, \App::$install); - if(! \DBA::$dba->connected) { - system_unavailable(); - } - - unset($db_host, $db_port, $db_user, $db_pass, $db_data, $db_type); - - /** - * Load configs from db. Overwrite configs from .htconfig.php - */ - - load_config('config'); - load_config('system'); - load_config('feature'); - - \App::$session = new Session(); - \App::$session->init(); - load_hooks(); - call_hooks('init_1'); - - } + sys_boot(); \App::$language = get_best_language(); -- cgit v1.2.3 From 61304d80d23bf624d9ca13319d2c6c09fdd0d70e Mon Sep 17 00:00:00 2001 From: redmatrix Date: Thu, 26 May 2016 18:45:47 -0700 Subject: track down some issues from the application logs --- Zotlabs/Zot/Finger.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Zot/Finger.php b/Zotlabs/Zot/Finger.php index 07798fbb1..229fda8bd 100644 --- a/Zotlabs/Zot/Finger.php +++ b/Zotlabs/Zot/Finger.php @@ -112,12 +112,12 @@ class Finger { if($signed_token) { $valid = rsa_verify('token.' . self::$token,base64url_decode($signed_token),$x['key']); if(! $valid) { - logger('invalid signed token: ' . $url . $rhs, LOGGER_NORMAL, LOG_WARN); + logger('invalid signed token: ' . $url . $rhs, LOGGER_NORMAL, LOG_ERR); return $ret; } } else { - logger('No signed token from ' . $url . $rhs, LOGGER_NORMAL, LOG_WARN); + logger('No signed token from ' . $url . $rhs, LOGGER_NORMAL, LOG_WARNING); // after 2017-01-01 this will be a hard error unless you over-ride it. if((time() > 1483228800) && (! get_config('system','allow_unsigned_zotfinger'))) return $ret; -- cgit v1.2.3 From 551cf8ee9413c5c57e7b71d6016466e598636900 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Thu, 26 May 2016 19:40:16 -0700 Subject: link to hubchart site for site detail on pubsites page --- Zotlabs/Module/Pubsites.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Pubsites.php b/Zotlabs/Module/Pubsites.php index 31bca5f30..0dda08e6d 100644 --- a/Zotlabs/Module/Pubsites.php +++ b/Zotlabs/Module/Pubsites.php @@ -28,9 +28,10 @@ class Pubsites extends \Zotlabs\Web\Controller { if($ret['success']) { $j = json_decode($ret['body'],true); if($j) { - $o .= ''; + $o .= '
' . t('Hub URL') . '' . t('Access Type') . '' . t('Registration Policy') . '' . t('Software') . '' . t('Ratings') . '
'; if($j['sites']) { foreach($j['sites'] as $jj) { + $m = parse_url($jj['url']); if(strpos($jj['project'],\Zotlabs\Lib\System::get_platform_name()) === false) continue; $host = strtolower(substr($jj['url'],strpos($jj['url'],'://')+3)); @@ -43,7 +44,7 @@ class Pubsites extends \Zotlabs\Web\Controller { $location = '
 '; } $urltext = str_replace(array('https://'), '', $jj['url']); - $o .= '' . $rate_links . ''; + $o .= '' . $rate_links . ''; } } -- cgit v1.2.3
' . t('Hub URL') . '' . t('Access Type') . '' . t('Registration Policy') . '' . t('Stats') . '' . t('Software') . '' . t('Ratings') . '
' . $urltext . '' . $location . '' . $jj['access'] . '' . $jj['register'] . '' . ucwords($jj['project']) . ' ' . t('View') . '
' . $urltext . '' . $location . '' . $jj['access'] . '' . $jj['register'] . '' . '' . ucwords($jj['project']) . ' ' . t('View') . '