aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Zotlabs/Lib')
-rw-r--r--Zotlabs/Lib/Apps.php9
-rw-r--r--Zotlabs/Lib/DB_Upgrade.php134
-rw-r--r--Zotlabs/Lib/Enotify.php45
-rw-r--r--Zotlabs/Lib/Share.php141
4 files changed, 239 insertions, 90 deletions
diff --git a/Zotlabs/Lib/Apps.php b/Zotlabs/Lib/Apps.php
index d2a307fd5..f91dc8e49 100644
--- a/Zotlabs/Lib/Apps.php
+++ b/Zotlabs/Lib/Apps.php
@@ -119,6 +119,7 @@ class Apps {
static public function parse_app_description($f,$translate = true) {
+
$ret = array();
$baseurl = z_root();
@@ -194,6 +195,10 @@ class Apps {
if(! is_public_profile())
unset($ret);
break;
+ case 'public_stream':
+ if(! can_view_public_stream())
+ unset($ret);
+ break;
case 'observer':
if(! $observer)
unset($ret);
@@ -346,6 +351,10 @@ class Apps {
if(! is_public_profile())
return '';
break;
+ case 'public_stream':
+ if(! can_view_public_stream())
+ return '';
+ break;
case 'observer':
$observer = \App::get_observer();
if(! $observer)
diff --git a/Zotlabs/Lib/DB_Upgrade.php b/Zotlabs/Lib/DB_Upgrade.php
index 8f0488f6f..4038a2d53 100644
--- a/Zotlabs/Lib/DB_Upgrade.php
+++ b/Zotlabs/Lib/DB_Upgrade.php
@@ -10,22 +10,12 @@ class DB_Upgrade {
function __construct($db_revision) {
- $platform_name = System::get_platform_name();
+ $this->config_name = 'db_version';
+ $this->func_prefix = '_';
- $update_file = 'install/' . $platform_name . '/update.php';
- if(! file_exists($update_file)) {
- $update_file = 'install/update.php';
- $this->config_name = 'db_version';
- $this->func_prefix = 'update_r';
- }
- else {
- $this->config_name = $platform_name . '_db_version';
- $this->func_prefix = $platform_name . '_update_';
- }
-
- $build = get_config('system', $this->config_name, 0);
+ $build = get_config('system', 'db_version', 0);
if(! intval($build))
- $build = set_config('system', $this->config_name, $db_revision);
+ $build = set_config('system', 'db_version', $db_revision);
if($build == $db_revision) {
// Nothing to be done.
@@ -40,82 +30,78 @@ class DB_Upgrade {
$current = intval($db_revision);
- if(($stored < $current) && file_exists($update_file)) {
+ if($stored < $current) {
- Config::Load('database');
+ // The last update we performed was $stored.
+ // Start at $stored + 1 and continue until we have completed $current
- // We're reporting a different version than what is currently installed.
- // Run any existing update scripts to bring the database up to current.
-
- require_once($update_file);
+ for($x = $stored + 1; $x <= $current; $x ++) {
+ $s = '_' . $x;
+ $cls = '\\Zotlabs\Update\\' . $s ;
+ if(! class_exists($cls)) {
+ return;
+ }
- // make sure that boot.php and update.php are the same release, we might be
- // updating from git right this very second and the correct version of the update.php
- // file may not be here yet. This can happen on a very busy site.
+ // There could be a lot of processes running or about to run.
+ // We want exactly one process to run the update command.
+ // So store the fact that we're taking responsibility
+ // after first checking to see if somebody else already has.
- if($db_revision == UPDATE_VERSION) {
- for($x = $stored; $x < $current; $x ++) {
- $func = $this->func_prefix . $x;
- if(function_exists($func)) {
- // There could be a lot of processes running or about to run.
- // We want exactly one process to run the update command.
- // So store the fact that we're taking responsibility
- // after first checking to see if somebody else already has.
+ // If the update fails or times-out completely you may need to
+ // delete the config entry to try again.
- // If the update fails or times-out completely you may need to
- // delete the config entry to try again.
+ Config::Load('database');
- if(get_config('database', $func))
- break;
- set_config('database',$func, '1');
- // call the specific update
+ if(get_config('database', $s))
+ break;
+ set_config('database',$s, '1');
+
- $retval = $func();
- if($retval) {
+ $c = new $cls();
+ $retval = $c->run();
- // Prevent sending hundreds of thousands of emails by creating
- // a lockfile.
+ if($retval != UPDATE_SUCCESS) {
- $lockfile = 'store/[data]/mailsent';
+ // Prevent sending hundreds of thousands of emails by creating
+ // a lockfile.
- if ((file_exists($lockfile)) && (filemtime($lockfile) > (time() - 86400)))
- return;
- @unlink($lockfile);
- //send the administrator an e-mail
- file_put_contents($lockfile, $x);
-
- $r = q("select account_language from account where account_email = '%s' limit 1",
- dbesc(\App::$config['system']['admin_email'])
- );
- push_lang(($r) ? $r[0]['account_language'] : 'en');
+ $lockfile = 'store/[data]/mailsent';
- z_mail(
+ if ((file_exists($lockfile)) && (filemtime($lockfile) > (time() - 86400)))
+ return;
+ @unlink($lockfile);
+ //send the administrator an e-mail
+ file_put_contents($lockfile, $x);
+
+ $r = q("select account_language from account where account_email = '%s' limit 1",
+ dbesc(\App::$config['system']['admin_email'])
+ );
+ push_lang(($r) ? $r[0]['account_language'] : 'en');
+ z_mail(
+ [
+ 'toEmail' => \App::$config['system']['admin_email'],
+ 'messageSubject' => sprintf( t('Update Error at %s'), z_root()),
+ 'textVersion' => replace_macros(get_intltext_template('update_fail_eml.tpl'),
[
- 'toEmail' => \App::$config['system']['admin_email'],
- 'messageSubject' => sprintf( t('Update Error at %s'), z_root()),
- 'textVersion' => replace_macros(get_intltext_template('update_fail_eml.tpl'),
- [
- '$sitename' => \App::$config['system']['sitename'],
- '$siteurl' => z_root(),
- '$update' => $x,
- '$error' => sprintf( t('Update %s failed. See error logs.'), $x)
- ]
- )
+ '$sitename' => \App::$config['system']['sitename'],
+ '$siteurl' => z_root(),
+ '$update' => $x,
+ '$error' => sprintf( t('Update %s failed. See error logs.'), $x)
]
- );
-
- //try the logger
- logger('CRITICAL: Update Failed: ' . $x);
- pop_lang();
- }
- else {
- set_config('database',$func, 'success');
- }
- }
+ )
+ ]
+ );
+
+ //try the logger
+ logger('CRITICAL: Update Failed: ' . $x);
+ pop_lang();
+ }
+ else {
+ set_config('database',$s, 'success');
}
- set_config('system', $this->config_name, $db_revision);
}
}
+ set_config('system', 'db_version', $db_revision);
}
}
} \ No newline at end of file
diff --git a/Zotlabs/Lib/Enotify.php b/Zotlabs/Lib/Enotify.php
index 5cf4ec31d..c5bc706c2 100644
--- a/Zotlabs/Lib/Enotify.php
+++ b/Zotlabs/Lib/Enotify.php
@@ -112,6 +112,8 @@ class Enotify {
}
+ $always_show_in_notices = get_pconfig($recip['channel_id'],'system','always_show_in_notices');
+
// e.g. "your post", "David's photo", etc.
$possess_desc = t('%s <!item_type!>');
@@ -128,18 +130,28 @@ class Enotify {
}
if ($params['type'] == NOTIFY_COMMENT) {
-// logger("notification: params = " . print_r($params, true), LOGGER_DEBUG);
+ //logger("notification: params = " . print_r($params, true), LOGGER_DEBUG);
$moderated = (($params['item']['item_blocked'] == ITEM_MODERATED) ? true : false);
$itemlink = $params['link'];
- // ignore like/unlike activity on posts - they probably require a separate notification preference
+ $action = 'commented on';
+
+ if(array_key_exists('item',$params) && in_array($params['item']['verb'], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) {
+
+ if(! $always_show_in_notices) {
+ logger('notification: not a visible activity. Ignoring.');
+ pop_lang();
+ return;
+ }
+
+ if(activity_match($params['verb'], ACTIVITY_LIKE))
+ $action = 'liked';
+
+ if(activity_match($params['verb'], ACTIVITY_DISLIKE))
+ $action = 'disliked';
- if (array_key_exists('item',$params) && (! visible_activity($params['item']))) {
- logger('notification: not a visible activity. Ignoring.');
- pop_lang();
- return;
}
$parent_mid = $params['parent_mid'];
@@ -181,26 +193,29 @@ class Enotify {
//$possess_desc = str_replace('<!item_type!>',$possess_desc);
// "a post"
- $dest_str = sprintf(t('%1$s, %2$s commented on [zrl=%3$s]a %4$s[/zrl]'),
+ $dest_str = sprintf(t('%1$s, %2$s %3$s [zrl=%4$s]a %5$s[/zrl]'),
$recip['channel_name'],
'[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]',
+ $action,
$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]'),
+ $dest_str = sprintf(t('%1$s, %2$s %3$s [zrl=%4$s]%5$s\'s %6$s[/zrl]'),
$recip['channel_name'],
'[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]',
+ $action,
$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]'),
+ $dest_str = sprintf(t('%1$s, %2$s %3$s [zrl=%4$s]your %5$s[/zrl]'),
$recip['channel_name'],
'[zrl=' . $sender['xchan_url'] . ']' . $sender['xchan_name'] . '[/zrl]',
+ $action,
$itemlink,
$item_post_type);
@@ -231,12 +246,12 @@ class Enotify {
$itemlink = $params['link'];
- // ignore like/unlike activity on posts - they probably require a separate notification preference
-
if (array_key_exists('item',$params) && (! activity_match($params['item']['verb'],ACTIVITY_LIKE))) {
- logger('notification: not a like activity. Ignoring.');
- pop_lang();
- return;
+ if(! $always_show_in_notices) {
+ logger('notification: not a visible activity. Ignoring.');
+ pop_lang();
+ return;
+ }
}
$parent_mid = $params['parent_mid'];
@@ -496,8 +511,6 @@ class Enotify {
// 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;
diff --git a/Zotlabs/Lib/Share.php b/Zotlabs/Lib/Share.php
new file mode 100644
index 000000000..b5341e662
--- /dev/null
+++ b/Zotlabs/Lib/Share.php
@@ -0,0 +1,141 @@
+<?php
+
+namespace Zotlabs\Lib;
+
+
+class Share {
+
+ private $item = null;
+
+
+ public function __construct($post_id) {
+
+ if(! $post_id)
+ return;
+
+ if(! (local_channel() || remote_channel()))
+ return;
+
+ $r = q("SELECT * from item left join xchan on author_xchan = xchan_hash WHERE id = %d LIMIT 1",
+ intval($post_id)
+ );
+ if(! $r)
+ return;
+
+ if(($r[0]['item_private']) && ($r[0]['xchan_network'] !== 'rss'))
+ return;
+
+ $sql_extra = item_permissions_sql($r[0]['uid']);
+
+ $r = q("select * from item where id = %d $sql_extra",
+ intval($post_id)
+ );
+ if(! $r)
+ return;
+
+ if($r[0]['mimetype'] !== 'text/bbcode')
+ return;
+
+ /** @FIXME eventually we want to post remotely via rpost on your home site */
+ // When that works remove this next bit:
+
+ if(! local_channel())
+ return;
+
+ xchan_query($r);
+
+ $this->item = $r[0];
+ return;
+ }
+
+ public function obj() {
+ $obj = [];
+
+ if(! $this->item)
+ return $obj;
+
+ $obj['type'] = $this->item['obj_type'];
+ $obj['id'] = $this->item['mid'];
+ $obj['content'] = $this->item['body'];
+ $obj['content_type'] = $this->item['mimetype'];
+ $obj['title'] = $this->item['title'];
+ $obj['created'] = $this->item['created'];
+ $obj['edited'] = $this->item['edited'];
+ $obj['author'] = [
+ 'name' => $this->item['author']['xchan_name'],
+ 'address' => $this->item['author']['xchan_addr'],
+ 'network' => $this->item['author']['xchan_network'],
+ 'link' => [
+ [
+ 'rel' => 'alternate',
+ 'type' => 'text/html',
+ 'href' => $this->item['author']['xchan_url']
+ ],
+ [
+ 'rel' => 'photo',
+ 'type' => $this->item['author']['xchan_photo_mimetype'],
+ 'href' => $this->item['author']['xchan_photo_m']
+ ]
+ ]
+ ];
+
+ $obj['owner'] = [
+ 'name' => $this->item['owner']['xchan_name'],
+ 'address' => $this->item['owner']['xchan_addr'],
+ 'network' => $this->item['owner']['xchan_network'],
+ 'link' => [
+ [
+ 'rel' => 'alternate',
+ 'type' => 'text/html',
+ 'href' => $this->item['owner']['xchan_url']
+ ],
+ [
+ 'rel' => 'photo',
+ 'type' => $this->item['owner']['xchan_photo_mimetype'],
+ 'href' => $this->item['owner']['xchan_photo_m']
+ ]
+ ]
+ ];
+
+ $obj['link'] = [
+ 'rel' => 'alternate',
+ 'type' => 'text/html',
+ 'href' => $this->item['plink']
+ ];
+
+ return $obj;
+ }
+
+ public function bbcode() {
+ $bb = NULL_STR;
+
+ if(! $this->item)
+ return $bb;
+
+ $is_photo = (($this->item['obj_type'] === ACTIVITY_OBJ_PHOTO) ? true : false);
+ if($is_photo) {
+ $object = json_decode($this->item['obj'],true);
+ $photo_bb = $object['body'];
+ }
+
+ if (strpos($this->item['body'], "[/share]") !== false) {
+ $pos = strpos($this->item['body'], "[share");
+ $bb = substr($this->item['body'], $pos);
+ } else {
+ $bb = "[share author='".urlencode($this->item['author']['xchan_name']).
+ "' profile='".$this->item['author']['xchan_url'] .
+ "' avatar='".$this->item['author']['xchan_photo_s'].
+ "' link='".$this->item['plink'].
+ "' posted='".$this->item['created'].
+ "' message_id='".$this->item['mid']."']";
+ if($this->item['title'])
+ $bb .= '[b]'.$this->item['title'].'[/b]'."\r\n";
+ $bb .= (($is_photo) ? $photo_bb . "\r\n" . $this->item['body'] : $this->item['body']);
+ $bb .= "[/share]";
+ }
+
+ return $bb;
+
+ }
+
+} \ No newline at end of file