aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/Import/import_diaspora.php1
-rw-r--r--include/account.php5
-rw-r--r--include/acl_selectors.php5
-rw-r--r--include/activities.php1
-rw-r--r--include/api.php5
-rw-r--r--include/apps.php658
-rw-r--r--include/bb2diaspora.php2
-rw-r--r--include/bbcode.php9
-rw-r--r--include/channel.php (renamed from include/identity.php)31
-rw-r--r--include/chat.php262
-rw-r--r--include/cli_startup.php32
-rw-r--r--include/config.php16
-rw-r--r--include/connections.php (renamed from include/Contact.php)27
-rw-r--r--include/contact_widgets.php8
-rw-r--r--include/conversation.php14
-rw-r--r--include/crypto.php14
-rw-r--r--include/datetime.php1
-rwxr-xr-xinclude/dba/dba_driver.php182
-rw-r--r--include/dir_fns.php8
-rw-r--r--include/enotify.php652
-rw-r--r--include/event.php59
-rw-r--r--include/feedutils.php1
-rw-r--r--include/follow.php7
-rw-r--r--include/help.php2
-rwxr-xr-xinclude/items.php17
-rw-r--r--include/language.php6
-rw-r--r--include/network.php15
-rw-r--r--include/notify.php37
-rwxr-xr-xinclude/oembed.php2
-rw-r--r--include/photo/photo_driver.php6
-rw-r--r--include/photos.php2
-rwxr-xr-xinclude/plugin.php11
-rw-r--r--include/socgraph.php10
-rw-r--r--include/text.php66
-rw-r--r--include/widgets.php17
-rw-r--r--include/zot.php47
36 files changed, 285 insertions, 1953 deletions
diff --git a/include/Import/import_diaspora.php b/include/Import/import_diaspora.php
index a94e73395..b664badf1 100644
--- a/include/Import/import_diaspora.php
+++ b/include/Import/import_diaspora.php
@@ -6,7 +6,6 @@ require_once('include/follow.php');
require_once('include/photo/photo_driver.php');
function import_diaspora($data) {
- $a = get_app();
$account = App::get_account();
if(! $account)
diff --git a/include/account.php b/include/account.php
index 5998609d4..a442f3073 100644
--- a/include/account.php
+++ b/include/account.php
@@ -11,7 +11,7 @@ require_once('include/text.php');
require_once('include/language.php');
require_once('include/datetime.php');
require_once('include/crypto.php');
-require_once('include/identity.php');
+require_once('include/channel.php');
function check_account_email($email) {
@@ -656,7 +656,8 @@ function account_service_class_allows($aid, $property, $usage = false) {
* @todo Should we merge this with account_service_class_fetch()?
*/
function service_class_fetch($uid, $property) {
- $a = get_app();
+
+
if($uid == local_channel()) {
$service_class = App::$account['account_service_class'];
}
diff --git a/include/acl_selectors.php b/include/acl_selectors.php
index 886574714..54ea0304b 100644
--- a/include/acl_selectors.php
+++ b/include/acl_selectors.php
@@ -11,8 +11,6 @@ require_once("include/PermissionDescription.php");
function group_select($selname,$selclass,$preselected = false,$size = 4) {
- $a = get_app();
-
$o = '';
$o .= "<select name=\"{$selname}[]\" id=\"$selclass\" class=\"$selclass\" multiple=\"multiple\" size=\"$size\" >\r\n";
@@ -51,7 +49,6 @@ function group_select($selname,$selclass,$preselected = false,$size = 4) {
/* MicMee 20130114 function contact_selector no longer in use, sql table contact does no longer exist
function contact_selector($selname, $selclass, $preselected = false, $options) {
- $a = get_app();
$mutual = false;
$networks = null;
@@ -157,7 +154,6 @@ function contact_selector($selname, $selclass, $preselected = false, $options) {
function contact_select($selname, $selclass, $preselected = false, $size = 4, $privmail = false, $celeb = false, $privatenet = false, $tabindex = null) {
- $a = get_app();
$o = '';
@@ -270,7 +266,6 @@ function populate_acl($defaults = null,$show_jotnets = true, $emptyACL_descripti
$o = replace_macros($tpl, array(
'$showall' => $showall_caption,
'$onlyme' => t('Only me'),
- '$add_others' => t('Add others'),
'$showallOrigin' => $showall_origin,
'$showallIcon' => $showall_icon,
'$select_label' => t('Who can see this?'),
diff --git a/include/activities.php b/include/activities.php
index 7b9aa9963..3271db993 100644
--- a/include/activities.php
+++ b/include/activities.php
@@ -1,7 +1,6 @@
<?php /** @file */
function profile_activity($changed, $value) {
- $a = get_app();
if(! local_channel() || ! is_array($changed) || ! count($changed))
return;
diff --git a/include/api.php b/include/api.php
index 4a462d1e8..af5a22a74 100644
--- a/include/api.php
+++ b/include/api.php
@@ -451,8 +451,6 @@ require_once('include/api_auth.php');
*/
function api_apply_template($templatename, $type, $data){
- $a = get_app();
-
switch($type){
case "atom":
case "rss":
@@ -514,7 +512,7 @@ require_once('include/api_auth.php');
return false;
}
- require_once('include/identity.php');
+ require_once('include/channel.php');
json_return_and_die(identity_basic_export(api_user(),(($_REQUEST['posts']) ? intval($_REQUEST['posts']) : 0 )));
}
@@ -1904,7 +1902,6 @@ require_once('include/api_auth.php');
//logger('api_format_items: ' . print_r($user_info,true));
- $a = get_app();
$ret = array();
if(! $r)
diff --git a/include/apps.php b/include/apps.php
deleted file mode 100644
index 7439be6d4..000000000
--- a/include/apps.php
+++ /dev/null
@@ -1,658 +0,0 @@
-<?php /** @file */
-
-/**
- * apps
- *
- */
-
-require_once('include/plugin.php');
-require_once('include/identity.php');
-
-function get_system_apps($translate = true) {
-
- $ret = array();
- if(is_dir('apps'))
- $files = glob('apps/*.apd');
- else
- $files = glob('app/*.apd');
- if($files) {
- foreach($files as $f) {
- $x = parse_app_description($f,$translate);
- if($x) {
- $ret[] = $x;
- }
- }
- }
- $files = glob('addon/*/*.apd');
- if($files) {
- foreach($files as $f) {
- $n = basename($f,'.apd');
- if(plugin_is_installed($n)) {
- $x = parse_app_description($f,$translate);
- if($x) {
- $ret[] = $x;
- }
- }
- }
- }
-
- return $ret;
-
-}
-
-
-function import_system_apps() {
- if(! local_channel())
- return;
-
- // Eventually we want to look at modification dates and update system apps.
-
- $installed = get_pconfig(local_channel(),'system','apps_installed');
- if($installed)
- return;
- $apps = get_system_apps(false);
- if($apps) {
- foreach($apps as $app) {
- $app['uid'] = local_channel();
- $app['guid'] = hash('whirlpool',$app['name']);
- $app['system'] = 1;
- app_install(local_channel(),$app);
- }
- }
- set_pconfig(local_channel(),'system','apps_installed',1);
-}
-
-
-
-
-function app_name_compare($a,$b) {
- return strcmp($a['name'],$b['name']);
-}
-
-
-function parse_app_description($f,$translate = true) {
- $ret = array();
-
- $baseurl = z_root();
- $channel = App::get_channel();
- $address = (($channel) ? $channel['channel_address'] : '');
-
- //future expansion
-
- $observer = App::get_observer();
-
-
- $lines = @file($f);
- if($lines) {
- foreach($lines as $x) {
- if(preg_match('/^([a-zA-Z].*?):(.*?)$/ism',$x,$matches)) {
- $ret[$matches[1]] = trim(str_replace(array('$baseurl','$nick'),array($baseurl,$address),$matches[2]));
- }
- }
- }
-
-
- if(! $ret['photo'])
- $ret['photo'] = $baseurl . '/' . get_default_profile_photo(80);
-
- $ret['type'] = 'system';
-
- foreach($ret as $k => $v) {
- if(strpos($v,'http') === 0)
- $ret[$k] = zid($v);
- }
-
- if(array_key_exists('desc',$ret))
- $ret['desc'] = str_replace(array('\'','"'),array('&#39;','&dquot;'),$ret['desc']);
-
- if(array_key_exists('target',$ret))
- $ret['target'] = str_replace(array('\'','"'),array('&#39;','&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)
- translate_system_apps($ret);
- return $ret;
- }
- return false;
-}
-
-
-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
-
-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'] = 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('&#39;','&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 = 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') : '')
- ));
-}
-
-
-function app_install($uid,$app) {
- $app['uid'] = $uid;
-
- if(app_installed($uid,$app))
- $x = app_update($app);
- else
- $x = 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;
-}
-
-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));
- }
- }
- }
-}
-
-
-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);
-
-}
-
-
-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);
-}
-
-
-function app_decode($s) {
- $x = base64_decode(str_replace(array('<br />',"\r","\n",' '),array('','','',''),$s));
- return json_decode($x,true);
-}
-
-
-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;
-}
-
-
-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;
-
-}
-
-
-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]';
-
-}
-
-
-function papp_encode($papp) {
- return chunk_split(base64_encode(json_encode($papp)),72,"\n");
-
-}
-
-
diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php
index 9167cb5ad..c7d0e56b1 100644
--- a/include/bb2diaspora.php
+++ b/include/bb2diaspora.php
@@ -479,8 +479,6 @@ function unescape_underscores_in_links($m) {
function format_event_diaspora($ev) {
- $a = get_app();
-
if(! ((is_array($ev)) && count($ev)))
return '';
diff --git a/include/bbcode.php b/include/bbcode.php
index fd2d2f97a..f47dc6f2e 100644
--- a/include/bbcode.php
+++ b/include/bbcode.php
@@ -165,11 +165,10 @@ function bb_parse_crypt($match) {
}
function bb_parse_app($match) {
- require_once('include/apps.php');
- $app = app_decode($match[1]);
+ $app = Zotlabs\Lib\Apps::app_decode($match[1]);
if ($app)
- return app_render($app);
+ return Zotlabs\Lib\Apps::app_render($app);
}
function bb_parse_element($match) {
@@ -276,7 +275,6 @@ function bb_location($match) {
* @return string HTML iframe with content of $match[1]
*/
function bb_iframe($match) {
- $a = get_app();
$sandbox = ((strpos($match[1], App::get_hostname())) ? ' sandbox="allow-scripts" ' : '');
@@ -450,8 +448,6 @@ function bb_sanitize_style($input) {
function bb_observer($Text) {
- $a = get_app();
-
$observer = App::get_observer();
if ((strpos($Text,'[/observer]') !== false) || (strpos($Text,'[/rpost]') !== false)) {
@@ -985,6 +981,7 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false)
$Text = preg_replace("/\[event\-summary\](.*?)\[\/event\-summary\]/ism",'',$Text);
$Text = preg_replace("/\[event\-description\](.*?)\[\/event\-description\]/ism",'',$Text);
$Text = preg_replace("/\[event\-finish\](.*?)\[\/event\-finish\]/ism",'',$Text);
+ $Text = preg_replace("/\[event\-id\](.*?)\[\/event\-id\]/ism",'',$Text);
$Text = preg_replace("/\[event\-location\](.*?)\[\/event\-location\]/ism",'',$Text);
$Text = preg_replace("/\[event\-adjust\](.*?)\[\/event\-adjust\]/ism",'',$Text);
diff --git a/include/identity.php b/include/channel.php
index 4ef1105ea..35084741f 100644
--- a/include/identity.php
+++ b/include/channel.php
@@ -1,6 +1,6 @@
<?php
/**
- * @file include/identity.php
+ * @file include/channel.php
*/
require_once('include/zot.php');
@@ -847,7 +847,7 @@ function profile_load(&$a, $nickname, $profile = '') {
$extra_fields = array();
- require_once('include/identity.php');
+ require_once('include/channel.php');
$profile_fields_basic = get_profile_fields_basic();
$profile_fields_advanced = get_profile_fields_advanced();
@@ -1004,8 +1004,6 @@ function profile_sidebar($profile, $block = 0, $show_connect = true, $zcard = fa
call_hooks('profile_sidebar_enter', $profile);
- require_once('include/Contact.php');
-
if($show_connect) {
// This will return an empty string if we're already connected.
@@ -1569,7 +1567,7 @@ function get_online_status($nick) {
$ret = array('result' => false);
- if(get_config('system','block_public') && ! local_channel() && ! remote_channel())
+ if(observer_prohibited())
return $ret;
$r = q("select channel_id, channel_hash from channel where channel_address = '%s' limit 1",
@@ -1947,3 +1945,26 @@ function get_zcard_embed($channel,$observer_hash = '',$args = array()) {
return $o;
}
+
+
+function channelx_by_nick($nick) {
+ $r = q("SELECT * FROM channel left join xchan on channel_hash = xchan_hash WHERE channel_address = '%s' and channel_removed = 0 LIMIT 1",
+ dbesc($nick)
+ );
+ return(($r) ? $r[0] : false);
+}
+
+function channelx_by_hash($hash) {
+ $r = q("SELECT * FROM channel left join xchan on channel_hash = xchan_hash WHERE channel_hash = '%s' and channel_removed = 0 LIMIT 1",
+ dbesc($hash)
+ );
+ return(($r) ? $r[0] : false);
+}
+
+function channelx_by_n($id) {
+ $r = q("SELECT * FROM channel left join xchan on channel_hash = xchan_hash WHERE channel_id = %d and channel_removed = 0 LIMIT 1",
+ dbesc($id)
+ );
+ return(($r) ? $r[0] : false);
+}
+
diff --git a/include/chat.php b/include/chat.php
deleted file mode 100644
index 604402045..000000000
--- a/include/chat.php
+++ /dev/null
@@ -1,262 +0,0 @@
-<?php
-/**
- * @file include/chat.php
- * @brief Chat related functions.
- */
-
-
-/**
- * @brief Creates a chatroom.
- *
- * @param array $channel
- * @param array $arr
- * @return An associative array containing:
- * - success: A boolean
- * - message: (optional) A string
- */
-function chatroom_create($channel, $arr) {
-
- $ret = array('success' => 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;
-}
-
-
-function chatroom_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;
-}
-
-
-function chatroom_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 chatroom_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;
-}
-
-
-function chatroom_list($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;
-}
-
-function chatroom_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.
- */
-
-function chat_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/include/cli_startup.php b/include/cli_startup.php
index a33f7acb0..a4c1f629a 100644
--- a/include/cli_startup.php
+++ b/include/cli_startup.php
@@ -6,37 +6,7 @@ require_once('boot.php');
function cli_startup() {
- global $a, $db, $default_timezone;
-
- if(is_null($a)) {
- $a = new miniApp;
- }
-
- App::init();
-
- if(is_null($db)) {
- @include(".htconfig.php");
-
- $a->convert();
-
- if(! defined('UNO'))
- define('UNO', 0);
-
- App::$timezone = ((x($default_timezone)) ? $default_timezone : 'UTC');
- date_default_timezone_set(App::$timezone);
-
- require_once('include/dba/dba_driver.php');
- $db = dba_factory($db_host, $db_port, $db_user, $db_pass, $db_data, $db_type);
- unset($db_host, $db_port, $db_user, $db_pass, $db_data, $db_type);
- };
-
- App::$session = new Zotlabs\Web\Session();
- App::$session->init();
-
- load_config('system');
-
+ sys_boot();
App::set_baseurl(get_config('system','baseurl'));
- load_hooks();
-
} \ No newline at end of file
diff --git a/include/config.php b/include/config.php
index 12768f4da..3017c3865 100644
--- a/include/config.php
+++ b/include/config.php
@@ -44,7 +44,6 @@
* The category of the configuration value
*/
function load_config($family) {
- global $a;
if(! array_key_exists($family, App::$config))
App::$config[$family] = array();
@@ -81,7 +80,6 @@ function load_config($family) {
* @return mixed Return value or false on error or if not set
*/
function get_config($family, $key) {
- global $a;
if((! array_key_exists($family, App::$config)) || (! array_key_exists('config_loaded', App::$config[$family])))
load_config($family);
@@ -110,6 +108,7 @@ function get_config($family, $key) {
* The configuration key to query
* @return mixed
*/
+
function get_config_from_storage($family, $key) {
$ret = q("SELECT * FROM config WHERE cat = '%s' AND k = '%s' LIMIT 1",
dbesc($family),
@@ -135,7 +134,6 @@ function get_config_from_storage($family, $key) {
* Return the set value, or false if the database update failed
*/
function set_config($family, $key, $value) {
- global $a;
// manage array value
$dbvalue = ((is_array($value)) ? serialize($value) : $value);
@@ -180,7 +178,7 @@ function set_config($family, $key, $value) {
* @return mixed
*/
function del_config($family, $key) {
- global $a;
+
$ret = false;
if(array_key_exists($family, App::$config) && array_key_exists($key, App::$config[$family]))
@@ -204,7 +202,6 @@ function del_config($family, $key) {
* @return void|false Nothing or false if $uid is false
*/
function load_pconfig($uid) {
- global $a;
if($uid === false)
return false;
@@ -249,7 +246,6 @@ function load_pconfig($uid) {
*/
function get_pconfig($uid, $family, $key, $instore = false) {
// logger('include/config.php: get_pconfig() deprecated instore param used', LOGGER_DEBUG);
- global $a;
if($uid === false)
return false;
@@ -285,7 +281,6 @@ function get_pconfig($uid, $family, $key, $instore = false) {
* @return mixed Stored $value or false
*/
function set_pconfig($uid, $family, $key, $value) {
- global $a;
// this catches subtle errors where this function has been called
// with local_channel() when not logged in (which returns false)
@@ -372,7 +367,7 @@ function set_pconfig($uid, $family, $key, $value) {
* @return mixed
*/
function del_pconfig($uid, $family, $key) {
- global $a;
+
$ret = false;
if (x(App::$config[$uid][$family], $key))
@@ -398,7 +393,6 @@ function del_pconfig($uid, $family, $key) {
* @return void|false Returns false if xchan is not set
*/
function load_xconfig($xchan) {
- global $a;
if(! $xchan)
return false;
@@ -441,7 +435,6 @@ function load_xconfig($xchan) {
* @return mixed Stored $value or false if it does not exist
*/
function get_xconfig($xchan, $family, $key) {
- global $a;
if(! $xchan)
return false;
@@ -477,7 +470,6 @@ function get_xconfig($xchan, $family, $key) {
* @return mixed Stored $value or false
*/
function set_xconfig($xchan, $family, $key, $value) {
- global $a;
// manage array value
$dbvalue = ((is_array($value)) ? serialize($value) : $value);
@@ -530,7 +522,7 @@ function set_xconfig($xchan, $family, $key, $value) {
* @return mixed
*/
function del_xconfig($xchan, $family, $key) {
- global $a;
+
$ret = false;
if(x(App::$config[$xchan][$family], $key))
diff --git a/include/Contact.php b/include/connections.php
index e50670a89..d18383fad 100644
--- a/include/Contact.php
+++ b/include/connections.php
@@ -48,32 +48,9 @@ function abook_self($channel_id) {
return(($r) ? $r[0] : array());
}
-function channelx_by_nick($nick) {
- $r = q("SELECT * FROM channel left join xchan on channel_hash = xchan_hash WHERE channel_address = '%s' and channel_removed = 0 LIMIT 1",
- dbesc($nick)
- );
- return(($r) ? $r[0] : false);
-}
-
-function channelx_by_hash($hash) {
- $r = q("SELECT * FROM channel left join xchan on channel_hash = xchan_hash WHERE channel_hash = '%s' and channel_removed = 0 LIMIT 1",
- dbesc($hash)
- );
- return(($r) ? $r[0] : false);
-}
-
-function channelx_by_n($id) {
- $r = q("SELECT * FROM channel left join xchan on channel_hash = xchan_hash WHERE channel_id = %d and channel_removed = 0 LIMIT 1",
- dbesc($id)
- );
- return(($r) ? $r[0] : false);
-}
-
function vcard_from_xchan($xchan, $observer = null, $mode = '') {
- $a = get_app();
-
if(! $xchan) {
if(App::$poi) {
$xchan = App::$poi;
@@ -198,7 +175,7 @@ function account_remove($account_id,$local = true,$unset_session=true) {
// Don't let anybody nuke the only admin account.
- $r = q("select account_id from account where (account_roles & %d)>0",
+ $r = q("select account_id from account where (account_roles & %d) > 0",
intval(ACCOUNT_ROLE_ADMIN)
);
@@ -267,7 +244,7 @@ function channel_remove($channel_id, $local = true, $unset_session=false) {
if(! $channel_id)
return;
- $a = get_app();
+
logger('Removing channel: ' . $channel_id);
logger('channel_remove: local only: ' . intval($local));
diff --git a/include/contact_widgets.php b/include/contact_widgets.php
index e62d57aa2..14d26e257 100644
--- a/include/contact_widgets.php
+++ b/include/contact_widgets.php
@@ -3,9 +3,6 @@
function findpeople_widget() {
- require_once('include/Contact.php');
-
- $a = get_app();
if(get_config('system','invitation_only')) {
$x = get_pconfig(local_channel(),'system','invites_remaining');
@@ -37,7 +34,6 @@ function findpeople_widget() {
function fileas_widget($baseurl,$selected = '') {
- $a = get_app();
if(! local_channel())
return '';
@@ -65,8 +61,6 @@ function fileas_widget($baseurl,$selected = '') {
}
function categories_widget($baseurl,$selected = '') {
-
- $a = get_app();
if(! feature_enabled(App::$profile['profile_uid'],'categories'))
return '';
@@ -108,8 +102,6 @@ function categories_widget($baseurl,$selected = '') {
function common_friends_visitor_widget($profile_uid) {
- $a = get_app();
-
if(local_channel() == $profile_uid)
return;
diff --git a/include/conversation.php b/include/conversation.php
index fca07a91d..dabe2ca93 100644
--- a/include/conversation.php
+++ b/include/conversation.php
@@ -858,8 +858,6 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $
function best_link_url($item) {
- $a = get_app();
-
$best_url = '';
$sparkle = false;
@@ -888,7 +886,7 @@ function best_link_url($item) {
function item_photo_menu($item){
- $a = get_app();
+
$contact = null;
$ssl_state = false;
@@ -1107,7 +1105,6 @@ function status_editor($a, $x, $popup = false) {
$o = '';
- require_once('include/Contact.php');
$c = channelx_by_n($x['profile_uid']);
if($c && $c['channel_moved'])
return $o;
@@ -1160,7 +1157,7 @@ function status_editor($a, $x, $popup = false) {
$layoutselect = '<input type="hidden" name="layout_mid" value="' . $layout . '" />';
if(array_key_exists('channel_select',$x) && $x['channel_select']) {
- require_once('include/identity.php');
+ require_once('include/channel.php');
$id_select = identity_selector();
}
else
@@ -1409,7 +1406,7 @@ function render_location_default($item) {
function prepare_page($item) {
- $a = get_app();
+
$naked = 1;
// $naked = ((get_pconfig($item['uid'],'system','nakedpage')) ? 1 : 0);
$observer = App::get_observer();
@@ -1443,7 +1440,7 @@ function prepare_page($item) {
function network_tabs() {
- $a = get_app();
+
$no_active='';
$starred_active = '';
$new_active = '';
@@ -1659,8 +1656,7 @@ function profile_tabs($a, $is_owner = false, $nickname = null){
if ($p['chat'] && feature_enabled($uid,'ajaxchat')) {
- require_once('include/chat.php');
- $has_chats = chatroom_list_count($uid);
+ $has_chats = Zotlabs\Lib\Chatroom::list_count($uid);
if ($has_chats) {
$tabs[] = array(
'label' => t('Chatrooms'),
diff --git a/include/crypto.php b/include/crypto.php
index d636c6848..42aa45b72 100644
--- a/include/crypto.php
+++ b/include/crypto.php
@@ -46,27 +46,29 @@ function pkcs5_unpad($text)
}
function AES256CBC_encrypt($data,$key,$iv) {
- if(get_config('system','openssl_encrypt')) {
- return openssl_encrypt($data,'aes-256-cbc',str_pad($key,32,"\0"),OPENSSL_RAW_DATA,str_pad($iv,16,"\0"));
- }
+
+ return openssl_encrypt($data,'aes-256-cbc',str_pad($key,32,"\0"),OPENSSL_RAW_DATA,str_pad($iv,16,"\0"));
+
+/* deprecated in php 7.1
return mcrypt_encrypt(
MCRYPT_RIJNDAEL_128,
str_pad($key,32,"\0"),
pkcs5_pad($data,16),
MCRYPT_MODE_CBC,
str_pad($iv,16,"\0"));
+*/
}
function AES256CBC_decrypt($data,$key,$iv) {
- if(get_config('system','openssl_encrypt')) {
- return openssl_decrypt($data,'aes-256-cbc',str_pad($key,32,"\0"),OPENSSL_RAW_DATA,str_pad($iv,16,"\0"));
- }
+ return openssl_decrypt($data,'aes-256-cbc',str_pad($key,32,"\0"),OPENSSL_RAW_DATA,str_pad($iv,16,"\0"));
+/* deprecated in php 7.1
return pkcs5_unpad(mcrypt_decrypt(
MCRYPT_RIJNDAEL_128,
str_pad($key,32,"\0"),
$data,
MCRYPT_MODE_CBC,
str_pad($iv,16,"\0")));
+*/
}
function crypto_encapsulate($data,$pubkey,$alg='aes256cbc') {
diff --git a/include/datetime.php b/include/datetime.php
index 83fb49d04..bf58866e9 100644
--- a/include/datetime.php
+++ b/include/datetime.php
@@ -119,7 +119,6 @@ function datetime_convert($from = 'UTC', $to = 'UTC', $s = 'now', $fmt = "Y-m-d
* @return string
*/
function dob($dob) {
- $a = get_app();
list($year, $month, $day) = sscanf($dob, '%4d-%2d-%2d');
$f = get_config('system', 'birthday_input_format');
diff --git a/include/dba/dba_driver.php b/include/dba/dba_driver.php
index e15e107a8..0ab5830ed 100755
--- a/include/dba/dba_driver.php
+++ b/include/dba/dba_driver.php
@@ -1,66 +1,78 @@
<?php
-/**
- * @file dba_driver.php
- * @brief some database related functions and abstract driver class.
- *
- * This file contains the abstract database driver class dba_driver and some
- * functions for working with databases.
- */
-/**
- * @brief Returns the database driver object.
- *
- * If available it will use PHP's mysqli otherwise mysql driver.
- *
- * @param string $server DB server name
- * @param string $port DB port
- * @param string $user DB username
- * @param string $pass DB password
- * @param string $db database name
- * @param string $dbtype 0 for mysql, 1 for postgres
- * @param bool $install Defaults to false
- * @return null|dba_driver A database driver object (dba_mysql|dba_mysqli) or null if no driver found.
- */
-function dba_factory($server, $port,$user,$pass,$db,$dbtype,$install = false) {
- $dba = null;
-
- $dbtype = intval($dbtype);
- $set_port = $port;
-
- if($dbtype == DBTYPE_POSTGRES) {
- require_once('include/dba/dba_postgres.php');
- if(is_null($port)) $set_port = 5432;
- $dba = new dba_postgres($server, $set_port, $user, $pass, $db, $install);
- } else {
-
-// Highly experimental at the present time.
-// require_once('include/dba/dba_pdo.php');
-// $dba = new dba_pdo($server, $set_port,$user,$pass,$db,$install);
-// }
-
- if(class_exists('mysqli')) {
- if (is_null($port)) $set_port = ini_get("mysqli.default_port");
- require_once('include/dba/dba_mysqli.php');
- $dba = new dba_mysqli($server, $set_port,$user,$pass,$db,$install);
+class DBA {
+
+ /**
+ * @file dba_driver.php
+ * @brief some database related functions and abstract driver class.
+ *
+ * This file contains the abstract database driver class dba_driver and some
+ * functions for working with databases.
+ */
+
+ static public $dba = null;
+ static public $dbtype = null;
+
+
+ /**
+ * @brief Returns the database driver object.
+ *
+ * If available it will use PHP's mysqli otherwise mysql driver.
+ *
+ * @param string $server DB server name
+ * @param string $port DB port
+ * @param string $user DB username
+ * @param string $pass DB password
+ * @param string $db database name
+ * @param string $dbtype 0 for mysql, 1 for postgres
+ * @param bool $install Defaults to false
+ * @return null|dba_driver A database driver object (dba_mysql|dba_mysqli) or null if no driver found.
+ */
+
+ static public function dba_factory($server, $port,$user,$pass,$db,$dbtype,$install = false) {
+
+ self::$dba = null;
+
+ self::$dbtype = intval($dbtype);
+ $set_port = $port;
+
+ if(self::$dbtype == DBTYPE_POSTGRES) {
+ require_once('include/dba/dba_postgres.php');
+ if(is_null($port)) $set_port = 5432;
+ self::$dba = new dba_postgres($server, $set_port, $user, $pass, $db, $install);
+ }
+ else {
+
+// Highly experimental at the present time.
+// require_once('include/dba/dba_pdo.php');
+// self::$dba = new dba_pdo($server, $set_port,$user,$pass,$db,$install);
+// }
+
+ if(class_exists('mysqli')) {
+ if (is_null($port)) $set_port = ini_get("mysqli.default_port");
+ require_once('include/dba/dba_mysqli.php');
+ self::$dba = new dba_mysqli($server, $set_port,$user,$pass,$db,$install);
+ }
}
- }
- // Until we have a proper PDO driver, store the DB connection parameters for
- // plugins/addons which use PDO natively (such as cdav). This is wasteful as
- // it opens a separate connection to the DB, but saves a lot of effort re-writing
- // third-party interfaces that are working and well tested.
+ // Until we have a proper PDO driver, store the DB connection parameters for
+ // plugins/addons which use PDO natively (such as cdav). This is wasteful as
+ // it opens a separate connection to the DB, but saves a lot of effort re-writing
+ // third-party interfaces that are working and well tested.
- if(is_object($dba) && $dba->connected) {
- $dns = (($dbtype == DBTYPE_POSTGRES) ? 'postgres' : 'mysql')
- . ':host=' . $server . (is_null($port) ? '' : ';port=' . $port)
- . ';dbname=' . $db;
- $dba->pdo_set(array($dns,$user,$pass));
+ if(is_object(self::$dba) && self::$dba->connected) {
+ $dns = ((self::$dbtype == DBTYPE_POSTGRES) ? 'postgres' : 'mysql')
+ . ':host=' . $server . (is_null($port) ? '' : ';port=' . $port)
+ . ';dbname=' . $db;
+ self::$dba->pdo_set(array($dns,$user,$pass));
+ }
+
+ define('NULL_DATE', self::$dba->get_null_date());
+ define('ACTIVE_DBTYPE', self::$dbtype);
+ return self::$dba;
}
- define('NULL_DATE', $dba->get_null_date());
- define('ACTIVE_DBTYPE', $dbtype);
- return $dba;
}
/**
@@ -232,8 +244,8 @@ function printable($s) {
function dbg($state) {
global $db;
- if($db)
- $db->dbg($state);
+ if(\DBA::$dba)
+ \DBA::$dba->dbg($state);
}
/**
@@ -247,21 +259,18 @@ function dbg($state) {
* @return Return an escaped string of the value to pass to a DB query.
*/
function dbesc($str) {
- global $db;
- if($db && $db->connected)
- return($db->escape($str));
+ if(\DBA::$dba && \DBA::$dba->connected)
+ return(\DBA::$dba->escape($str));
else
return(str_replace("'", "\\'", $str));
}
function dbescbin($str) {
- global $db;
- return $db->escapebin($str);
+ return \DBA::$dba->escapebin($str);
}
function dbunescbin($str) {
- global $db;
- return $db->unescapebin($str);
+ return \DBA::$dba->unescapebin($str);
}
function dbescdate($date) {
@@ -274,36 +283,25 @@ function dbescdate($date) {
}
function db_quoteinterval($txt) {
- global $db;
- return $db->quote_interval($txt);
+ return \DBA::$dba->quote_interval($txt);
}
function dbesc_identifier($str) {
- global $db;
- return $db->escape_identifier($str);
+ return \DBA::$dba->escape_identifier($str);
}
function db_utcnow() {
- global $db;
- return $db->utcnow();
+ return \DBA::$dba->utcnow();
}
function db_optimizetable($table) {
- global $db;
- $db->optimize_table($table);
+ \DBA::$dba->optimize_table($table);
}
function db_concat($fld, $sep) {
- global $db;
- return $db->concat($fld, $sep);
+ return \DBA::$dba->concat($fld, $sep);
}
-// Function: q($sql,$args);
-// Description: execute SQL query with printf style args.
-// Example: $r = q("SELECT * FROM `%s` WHERE `uid` = %d",
-// 'user', 1);
-
-
/**
* @brief Execute a SQL query with printf style args.
*
@@ -319,13 +317,13 @@ function db_concat($fld, $sep) {
* @param string $sql The SQL query to execute
* @return bool|array
*/
+
function q($sql) {
- global $db;
$args = func_get_args();
unset($args[0]);
- if($db && $db->connected) {
+ if(\DBA::$dba && \DBA::$dba->connected) {
$stmt = vsprintf($sql, $args);
if($stmt === false) {
if(version_compare(PHP_VERSION, '5.4.0') >= 0)
@@ -334,13 +332,14 @@ function q($sql) {
else
db_logger('dba: vsprintf error: ' . print_r(debug_backtrace(), true),LOGGER_NORMAL,LOG_CRIT);
}
- return $db->q($stmt);
+ return \DBA::$dba->q($stmt);
}
/*
* This will happen occasionally trying to store the
* session data after abnormal program termination
*/
+
db_logger('dba: no database: ' . print_r($args,true),LOGGER_NORMAL,LOG_CRIT);
return false;
@@ -354,10 +353,9 @@ function q($sql) {
* @param string $sql The SQL query to execute
*/
function dbq($sql) {
- global $db;
- if($db && $db->connected)
- $ret = $db->q($sql);
+ if(\DBA::$dba && \DBA::$dba->connected)
+ $ret = \DBA::$dba->q($sql);
else
$ret = false;
@@ -418,13 +416,13 @@ function db_getfunc($f) {
// The logger function may make DB calls internally to query the system logging parameters.
// This can cause a recursion if database debugging is enabled.
-// So this function preserves the current database debugging state and then turns it off while
-// doing the logger() call
+// So this function preserves the current database debugging state and then turns it off
+// temporarily while doing the logger() call
function db_logger($s,$level = LOGGER_NORMAL,$syslog = LOG_INFO) {
- global $db;
- $saved = $db->debug;
- $db->debug = false;
+
+ $saved = \DBA::$dba->debug;
+ \DBA::$dba->debug = false;
logger($s,$level,$syslog);
- $db->debug = $saved;
+ \DBA::$dba->debug = $saved;
} \ No newline at end of file
diff --git a/include/dir_fns.php b/include/dir_fns.php
index 1c3149081..9f1be1a42 100644
--- a/include/dir_fns.php
+++ b/include/dir_fns.php
@@ -69,9 +69,8 @@ function check_upstream_directory() {
if ($directory) {
$h = parse_url($directory);
if ($h) {
- $x = zot_finger('[system]@' . $h['host']);
- if ($x['success']) {
- $j = json_decode($x['body'], true);
+ $j = Zotlabs\Zot\Finger::run('[system]@' . $h['host']);
+ if ($j['success']) {
if (array_key_exists('site', $j) && array_key_exists('directory_mode', $j['site'])) {
if ($j['site']['directory_mode'] === 'normal') {
$isadir = false;
@@ -95,6 +94,9 @@ function get_directory_setting($observer, $setting) {
if($ret === false)
$ret = get_config('directory', $setting);
+
+ // 'safemode' is the default if there is no observer or no established preference.
+
if($setting == 'safemode' && $ret === false)
$ret = 1;
diff --git a/include/enotify.php b/include/enotify.php
deleted file mode 100644
index bd8698606..000000000
--- a/include/enotify.php
+++ /dev/null
@@ -1,652 +0,0 @@
-<?php
-/**
- * @file include/enotify.php
- *
- * @brief File with functions and a class for email notifications.
- */
-
-/**
- * @brief
- *
- * @param array $params an assoziative array with:
- * * \e string \b from_xchan sender xchan hash
- * * \e string \b to_xchan recipient xchan hash
- * * \e array \b item an assoziative array
- * * \e int \b type one of the NOTIFY_* constants from boot.php
- * * \e string \b link
- * * \e string \b parent_mid
- * * \e string \b otype
- * * \e string \b verb
- * * \e string \b activity
- */
-function notification($params) {
-
- logger('notification: entry', LOGGER_DEBUG);
-
- // throw a small amount of entropy into the system to breakup duplicates arriving at the same precise instant.
- usleep(mt_rand(0, 10000));
-
- $a = get_app();
-
-
- if ($params['from_xchan']) {
- $x = q("select * from xchan where xchan_hash = '%s' limit 1",
- dbesc($params['from_xchan'])
- );
- }
- if ($params['to_xchan']) {
- $y = q("select channel.*, account.* from channel left join account on channel_account_id = account_id
- where channel_hash = '%s' and channel_removed = 0 limit 1",
- dbesc($params['to_xchan'])
- );
- }
- if ($x & $y) {
- $sender = $x[0];
- $recip = $y[0];
- } else {
- logger('notification: no sender or recipient.');
- logger('sender: ' . $params['from_xchan']);
- logger('recip: ' . $params['to_xchan']);
- return;
- }
-
- // from here on everything is in the recipients language
-
- push_lang($recip['account_language']); // should probably have a channel language
-
- $banner = t('$Projectname Notification');
- $product = t('$projectname'); // PLATFORM_NAME;
- $siteurl = z_root();
- $thanks = t('Thank You,');
- $sitename = get_config('system','sitename');
- $site_admin = sprintf( t('%s Administrator'), $sitename);
-
- $sender_name = $product;
- $hostname = App::get_hostname();
- if(strpos($hostname,':'))
- $hostname = substr($hostname,0,strpos($hostname,':'));
-
- // Do not translate 'noreply' as it must be a legal 7-bit email address
- $sender_email = 'noreply' . '@' . $hostname;
-
- $additional_mail_header = "";
-
- if (array_key_exists('item', $params)) {
- require_once('include/conversation.php');
- // if it's a normal item...
- if (array_key_exists('verb', $params['item'])) {
- // localize_item() alters the original item so make a copy first
- $i = $params['item'];
- logger('calling localize');
- localize_item($i);
- $title = $i['title'];
- $body = $i['body'];
- $private = (($i['item_private']) || intval($i['item_obscured']));
- }
- else {
- $title = $params['item']['title'];
- $body = $params['item']['body'];
- }
- } else {
- $title = $body = '';
- }
-
-
- // e.g. "your post", "David's photo", etc.
- $possess_desc = t('%s <!item_type!>');
-
- 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, '<a href="' . $siteurl . '/mail/' . $params['item']['id'] . '">' . $sitename . '</a>');
- $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('<!item_type!>',$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, '<a href="' . $siteurl . '">' . $sitename . '</a>');
- }
-
- 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, '<a href="' . $siteurl . '">' . $sitename . '</a>');
- $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, '<a href="' . $siteurl . '">' . $sitename . '</a>');
- $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, '<a href="' . $siteurl . '">' . $sitename . '</a>');
- $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, '<a href="' . $siteurl . '">' . $sitename . '</a>');
- $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, '<a href="' . $siteurl . '/connections/ifpending">' . $sitename . '</a>');
- $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, '<a href="' . $siteurl . '">' . $sitename . '</a>');
- $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("","<br />\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'] = '<a href="' . $itemlink . '">' . $itemlink . '</a>';
- $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
-
- enotify::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 A class for sending email notifications.
- *
- * @fixme Class names start mostly with capital letter to distinguish them easier.
- */
-class enotify {
- /**
- * @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);
- }
-}
diff --git a/include/event.php b/include/event.php
index 29ca5bb79..db67dac64 100644
--- a/include/event.php
+++ b/include/event.php
@@ -175,6 +175,9 @@ function format_event_bbcode($ev) {
if($ev['location'])
$o .= '[event-location]' . $ev['location'] . '[/event-location]';
+ if($ev['event_hash'])
+ $o .= '[event-id]' . $ev['event_hash'] . '[/event-id]';
+
if($ev['adjust'])
$o .= '[event-adjust]' . $ev['adjust'] . '[/event-adjust]';
@@ -212,6 +215,9 @@ function bbtoevent($s) {
if(preg_match("/\[event\-location\](.*?)\[\/event\-location\]/is",$s,$match))
$ev['location'] = $match[1];
$match = '';
+ if(preg_match("/\[event\-id\](.*?)\[\/event\-id\]/is",$s,$match))
+ $ev['event_hash'] = $match[1];
+ $match = '';
if(preg_match("/\[event\-adjust\](.*?)\[\/event\-adjust\]/is",$s,$match))
$ev['adjust'] = $match[1];
if(array_key_exists('start',$ev)) {
@@ -278,34 +284,41 @@ function event_store_event($arr) {
else
$arr['event_status_date'] = NULL_DATE;
- // Existing event being modified
- if($arr['id'] || $arr['event_hash']) {
+ $existing_event = null;
- // has the event actually changed?
+ if($arr['event_hash']) {
+ $r = q("SELECT * FROM event WHERE event_hash = '%s' AND uid = %d LIMIT 1",
+ dbesc($arr['event_hash']),
+ intval($arr['uid'])
+ );
+ if($r) {
+ $existing_event = $r[0];
+ }
+ }
- if($arr['event_hash']) {
- $r = q("SELECT * FROM event WHERE event_hash = '%s' AND uid = %d LIMIT 1",
- dbesc($arr['event_hash']),
- intval($arr['uid'])
- );
+ if($arr['id']) {
+ $r = q("SELECT * FROM event WHERE id = %d AND uid = %d LIMIT 1",
+ intval($arr['id']),
+ intval($arr['uid'])
+ );
+ if($r) {
+ $existing_event = $r[0];
}
else {
- $r = q("SELECT * FROM event WHERE id = %d AND uid = %d LIMIT 1",
- intval($arr['id']),
- intval($arr['uid'])
- );
+ return false;
}
+ }
- if(! $r)
- return false;
- if($r[0]['edited'] === $arr['edited']) {
- // Nothing has changed. Return the ID.
- return $r[0];
+ if($existing_event) {
+
+ if($existing_event['edited'] >= $arr['edited']) {
+ // Nothing has changed.
+ return $existing_event;
}
- $hash = $r[0]['event_hash'];
+ $hash = $existing_event['event_hash'];
// The event changed. Update it.
@@ -350,7 +363,7 @@ function event_store_event($arr) {
dbesc($arr['allow_gid']),
dbesc($arr['deny_cid']),
dbesc($arr['deny_gid']),
- intval($r[0]['id']),
+ intval($existing_event['id']),
intval($arr['uid'])
);
} else {
@@ -360,6 +373,8 @@ function event_store_event($arr) {
if(array_key_exists('external_id',$arr))
$hash = $arr['external_id'];
+ elseif(array_key_exists('event_hash',$arr))
+ $hash = $arr['event_hash'];
else
$hash = random_string() . '@' . App::get_hostname();
@@ -436,7 +451,7 @@ function event_addtocal($item_id, $uid) {
// is this an edit?
- if($item['resource_type'] === 'event') {
+ if($item['resource_type'] === 'event' && (! $ev['event_hash'])) {
$ev['event_hash'] = $item['resource_id'];
}
@@ -472,7 +487,6 @@ function event_addtocal($item_id, $uid) {
if($z) {
build_sync_packet($channel['channel_id'],array('event_item' => array(encode_item($sync_item[0],true)),'event' => $z));
}
-
return true;
}
}
@@ -764,6 +778,9 @@ function event_store_item($arr, $event) {
$prefix = '';
// $birthday = false;
+ if(($event) && array_key_exists('event_hash',$event) && (! array_key_exists('event_hash',$arr)))
+ $arr['event_hash'] = $event['event_hash'];
+
if($event['type'] === 'birthday') {
if(! is_sys_channel($arr['uid']))
$prefix = t('This event has been added to your calendar.');
diff --git a/include/feedutils.php b/include/feedutils.php
index 700198ff8..f370c540a 100644
--- a/include/feedutils.php
+++ b/include/feedutils.php
@@ -1087,7 +1087,6 @@ function update_feed_item($uid,$datarray) {
function handle_feed($uid,$abook_id,$url) {
- require_once('include/Contact.php');
$channel = channelx_by_n($uid);
if(! $channel)
return;
diff --git a/include/follow.php b/include/follow.php
index e4f7e8557..0c3973175 100644
--- a/include/follow.php
+++ b/include/follow.php
@@ -17,7 +17,6 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
$result = array('success' => false,'message' => '');
- $a = get_app();
$is_red = false;
$is_http = ((strpos($url,'://') !== false) ? true : false);
@@ -56,11 +55,11 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
if($arr['channel']['success'])
$ret = $arr['channel'];
elseif(! $is_http)
- $ret = zot_finger($url,$channel);
+ $ret = Zotlabs\Zot\Finger::run($url,$channel);
- if($ret && $ret['success']) {
+ if($ret && is_array($ret) && $ret['success']) {
$is_red = true;
- $j = json_decode($ret['body'],true);
+ $j = $ret;
}
$my_perms = get_channel_default_perms($uid);
diff --git a/include/help.php b/include/help.php
index 13473164d..5518eeb70 100644
--- a/include/help.php
+++ b/include/help.php
@@ -24,8 +24,6 @@ function find_doc_file($s) {
function search_doc_files($s) {
- $a = get_app();
-
$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']));
diff --git a/include/items.php b/include/items.php
index a25be72b3..a60c10bdd 100755
--- a/include/items.php
+++ b/include/items.php
@@ -6,6 +6,8 @@
// uncertain if this line is needed and why
use Sabre\HTTP\URLUtil;
+use Zotlabs\Lib as Zlib;
+
require_once('include/bbcode.php');
require_once('include/oembed.php');
require_once('include/crypto.php');
@@ -77,7 +79,7 @@ function collect_recipients($item, &$private_envelope) {
// by the directives in $item['public_policy'].
$private_envelope = false;
- require_once('include/identity.php');
+ require_once('include/channel.php');
//$sys = get_sys_channel();
if(array_key_exists('public_policy',$item) && $item['public_policy'] !== 'self') {
@@ -2284,8 +2286,8 @@ function send_status_notifications($post_id,$item) {
if(! $notify)
return;
- require_once('include/enotify.php');
- notification(array(
+
+ Zlib\Enotify::submit(array(
'type' => NOTIFY_COMMENT,
'from_xchan' => $item['author_xchan'],
'to_xchan' => $r[0]['channel_hash'],
@@ -2378,8 +2380,7 @@ function tag_deliver($uid, $item_id) {
$verb = urldecode(substr($item['verb'],strpos($item['verb'],'#')+1));
if($poke_notify) {
- require_once('include/enotify.php');
- notification(array(
+ Zlib\Enotify::submit(array(
'to_xchan' => $u[0]['channel_hash'],
'from_xchan' => $item['author_xchan'],
'type' => NOTIFY_POKE,
@@ -2544,8 +2545,7 @@ function tag_deliver($uid, $item_id) {
* Kill two birds with one stone. As long as we're here, send a mention notification.
*/
- require_once('include/enotify.php');
- notification(array(
+ Zlib\Enotify::submit(array(
'to_xchan' => $u[0]['channel_hash'],
'from_xchan' => $item['author_xchan'],
'type' => NOTIFY_TAGSELF,
@@ -3046,7 +3046,6 @@ function mail_store($arr) {
);
}
else {
- require_once('include/enotify.php');
$notif_params = array(
'from_xchan' => $arr['from_xchan'],
@@ -3057,7 +3056,7 @@ function mail_store($arr) {
'otype' => 'mail'
);
- notification($notif_params);
+ Zlib\Enotify::submit($notif_params);
}
call_hooks('post_mail_end',$arr);
diff --git a/include/language.php b/include/language.php
index 14139e90c..238c23028 100644
--- a/include/language.php
+++ b/include/language.php
@@ -82,13 +82,11 @@ function get_best_language() {
if($arr['preferred'] !== 'unset')
return $arr['preferred'];
- $a = get_app();
return ((isset(App::$config['system']['language'])) ? App::$config['system']['language'] : 'en');
}
function push_lang($language) {
- global $a;
App::$langsave = App::$language;
@@ -104,7 +102,6 @@ function push_lang($language) {
}
function pop_lang() {
- global $a;
if(App::$language === App::$langsave)
return;
@@ -124,7 +121,6 @@ function pop_lang() {
* @param boolean $install (optional) default false
*/
function load_translation_table($lang, $install = false) {
- global $a;
App::$strings = array();
@@ -170,7 +166,6 @@ function load_translation_table($lang, $install = false) {
*
*/
function t($s, $ctx = '') {
- global $a;
$cs = $ctx ? '__ctx:' . $ctx . '__ ' . $s : $s;
if (x(App::$strings, $cs)) {
@@ -205,7 +200,6 @@ function translate_projectname($s) {
* @return string
*/
function tt($singular, $plural, $count, $ctx = ''){
- $a = get_app();
$cs = $ctx ? "__ctx:" . $ctx . "__ " . $singular : $singular;
if (x(App::$strings,$cs)) {
diff --git a/include/network.php b/include/network.php
index 3e5263d3e..dd266f5d1 100644
--- a/include/network.php
+++ b/include/network.php
@@ -595,8 +595,6 @@ function parse_xml_string($s,$strict = true) {
function scale_external_images($s, $include_link = true, $scale_replace = false) {
- $a = get_app();
-
// Picture addresses can contain special characters
$s = htmlspecialchars_decode($s, ENT_COMPAT);
@@ -1618,8 +1616,6 @@ function fetch_xrd_links($url) {
function scrape_vcard($url) {
- $a = get_app();
-
$ret = array();
logger('scrape_vcard: url=' . $url);
@@ -1699,8 +1695,6 @@ function scrape_vcard($url) {
function scrape_feed($url) {
- $a = get_app();
-
$ret = array();
$level = 0;
$x = z_fetch_url($url,false,$level,array('novalidate' => true));
@@ -1819,8 +1813,6 @@ function service_plink($contact, $guid) {
function format_and_send_email($sender,$xchan,$item) {
- require_once('include/enotify.php');
-
$title = $item['title'];
$body = $item['body'];
@@ -1885,7 +1877,7 @@ function format_and_send_email($sender,$xchan,$item) {
// use the EmailNotification library to send the message
- enotify::send(array(
+ Zotlabs\Lib\Enotify::send(array(
'fromName' => $product,
'fromEmail' => $sender_email,
'replyTo' => $sender_email,
@@ -1940,9 +1932,6 @@ function do_delivery($deliveries) {
function get_site_info() {
- global $db;
- global $a;
-
$register_policy = Array('REGISTER_CLOSED', 'REGISTER_APPROVE', 'REGISTER_OPEN');
$directory_mode = Array('DIRECTORY_MODE_NORMAL', 'DIRECTORY_MODE_PRIMARY', 'DIRECTORY_MODE_SECONDARY', 256 => 'DIRECTORY_MODE_STANDALONE');
@@ -2042,7 +2031,7 @@ function get_site_info() {
'admin' => $admin,
'site_name' => (($site_name) ? $site_name : ''),
'platform' => Zotlabs\Lib\System::get_platform_name(),
- 'dbdriver' => $db->getdriver(),
+ 'dbdriver' => DBA::$dba->getdriver(),
'lastpoll' => get_config('system','lastpoll'),
'info' => (($site_info) ? $site_info : ''),
'channels_total' => $channels_total_stat,
diff --git a/include/notify.php b/include/notify.php
deleted file mode 100644
index 2b032b56b..000000000
--- a/include/notify.php
+++ /dev/null
@@ -1,37 +0,0 @@
-<?php /** @file */
-
-
-function format_notification($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/include/oembed.php b/include/oembed.php
index 1e5c51172..08363e488 100755
--- a/include/oembed.php
+++ b/include/oembed.php
@@ -227,7 +227,7 @@ function oembed_fetch_url($embedurl){
}
function oembed_format_object($j){
- $a = get_app();
+
$embedurl = $j->embedurl;
// logger('format: ' . print_r($j,true));
diff --git a/include/photo/photo_driver.php b/include/photo/photo_driver.php
index 3bea54fd4..e57a9165a 100644
--- a/include/photo/photo_driver.php
+++ b/include/photo/photo_driver.php
@@ -521,7 +521,7 @@ function guess_image_type($filename, $headers = '') {
logger('Photo: guess_image_type: '.$filename . ($headers?' from curl headers':''), LOGGER_DEBUG);
$type = null;
if ($headers) {
- $a = get_app();
+
$hdrs=array();
$h = explode("\n",$headers);
foreach ($h as $l) {
@@ -580,8 +580,6 @@ function guess_image_type($filename, $headers = '') {
function import_xchan_photo($photo,$xchan,$thing = false) {
- $a = get_app();
-
$flags = (($thing) ? PHOTO_THING : PHOTO_XCHAN);
$album = (($thing) ? 'Things' : 'Contact Photos');
@@ -703,8 +701,6 @@ function import_xchan_photo($photo,$xchan,$thing = false) {
function import_channel_photo($photo,$type,$aid,$uid) {
- $a = get_app();
-
logger('import_channel_photo: importing channel photo for ' . $uid, LOGGER_DEBUG);
$hash = photo_new_resource();
diff --git a/include/photos.php b/include/photos.php
index d8d3d102c..c333a4d04 100644
--- a/include/photos.php
+++ b/include/photos.php
@@ -19,8 +19,6 @@ require_once('include/text.php');
*/
function photo_upload($channel, $observer, $args) {
- $a = get_app();
-
$ret = array('success' => false);
$channel_id = $channel['channel_id'];
$account_id = $channel['channel_account_id'];
diff --git a/include/plugin.php b/include/plugin.php
index 0466360bb..6c108fcc5 100755
--- a/include/plugin.php
+++ b/include/plugin.php
@@ -500,7 +500,7 @@ function get_theme_info($theme){
* @return string
*/
function get_theme_screenshot($theme) {
- $a = get_app();
+
$exts = array('.png', '.jpg');
foreach($exts as $ext) {
if(file_exists('view/theme/' . $theme . '/img/screenshot' . $ext))
@@ -521,7 +521,7 @@ function head_add_css($src, $media = 'screen') {
}
function head_remove_css($src, $media = 'screen') {
- $a = get_app();
+
$index = array_search(array($src, $media), App::$css_sources);
if ($index !== false)
unset(App::$css_sources[$index]);
@@ -592,7 +592,7 @@ function head_add_js($src) {
}
function head_remove_js($src) {
- $a = get_app();
+
$index = array_search($src, App::$js_sources);
if($index !== false)
unset(App::$js_sources[$index]);
@@ -633,7 +633,6 @@ function format_js_if_exists($source) {
function theme_include($file, $root = '') {
- $a = get_app();
// Make sure $root ends with a slash / if it's not blank
if($root !== '' && $root[strlen($root)-1] !== '/')
@@ -671,7 +670,7 @@ function theme_include($file, $root = '') {
function get_intltext_template($s, $root = '') {
- $a = get_app();
+
$t = App::template_engine();
$template = $t->get_intltext_template($s, $root);
@@ -680,7 +679,7 @@ function get_intltext_template($s, $root = '') {
function get_markup_template($s, $root = '') {
- $a = get_app();
+
$t = App::template_engine();
$template = $t->get_markup_template($s, $root);
return $template;
diff --git a/include/socgraph.php b/include/socgraph.php
index 1b1bccf20..4cb5600ec 100644
--- a/include/socgraph.php
+++ b/include/socgraph.php
@@ -152,11 +152,9 @@ function poco_load($xchan = '', $url = null) {
if(($x !== false) && (! count($x))) {
if($address) {
if($network === 'zot') {
- $z = zot_finger($address,null);
- if($z['success']) {
- $j = json_decode($z['body'],true);
- if($j)
- import_xchan($j);
+ $j = Zotlabs\Zot\Finger::run($address,null);
+ if($j['success']) {
+ import_xchan($j);
}
$x = q("select xchan_hash from xchan where xchan_hash = '%s' limit 1",
dbesc($hash)
@@ -404,7 +402,7 @@ function poco($a,$extended = false) {
$system_mode = false;
- if(intval(get_config('system','block_public')) && (! local_channel()) && (! remote_channel())) {
+ if(observer_prohibited()) {
logger('mod_poco: block_public');
http_status_exit(401);
}
diff --git a/include/text.php b/include/text.php
index df6dac056..375a89d3f 100644
--- a/include/text.php
+++ b/include/text.php
@@ -20,7 +20,6 @@ define('RANDOM_STRING_TEXT', 0x01 );
* @return string substituted string
*/
function replace_macros($s, $r) {
- $a = get_app();
$arr = array('template' => $s, 'params' => $r);
call_hooks('replace_macros', $arr);
@@ -96,7 +95,6 @@ function z_input_filter($channel_id,$s,$type = 'text/bbcode') {
if($type == 'application/x-pdl')
return escape_tags($s);
- $a = get_app();
if(App::$is_sys) {
return $s;
}
@@ -324,6 +322,15 @@ function autoname($len) {
function xmlify($str) {
$buffer = '';
+ if(is_array($str)) {
+
+ // allow to fall through so we ge a PHP error, as the log statement will
+ // probably get lost in the noise unless we're specifically looking for it.
+
+ btlogger('xmlify called with array: ' . print_r($str,true), LOGGER_NORMAL, LOG_WARNING);
+ }
+
+
$len = mb_strlen($str);
for($x = 0; $x < $len; $x ++) {
$char = mb_substr($str,$x,1);
@@ -567,21 +574,25 @@ function attribute_contains($attr, $s) {
*/
function logger($msg, $level = LOGGER_NORMAL, $priority = LOG_INFO) {
- // turn off logger in install mode
- global $a;
- global $db;
-
- if((App::$module == 'install') || (! ($db && $db->connected)))
- return;
- $debugging = get_config('system', 'debugging');
- $loglevel = intval(get_config('system', 'loglevel'));
- $logfile = get_config('system', 'logfile');
+ if(App::$module == 'setup' && is_writable('install.log')) {
+ $debugging = true;
+ $logfile = 'install.log';
+ $loglevel = LOGGER_ALL;
+ }
+ else {
+ $debugging = get_config('system', 'debugging');
+ $loglevel = intval(get_config('system', 'loglevel'));
+ $logfile = get_config('system', 'logfile');
+ }
if((! $debugging) || (! $logfile) || ($level > $loglevel))
return;
$where = '';
+
+ // We require > 5.4 but leave the version check so that install issues (including version) can be logged
+
if(version_compare(PHP_VERSION, '5.4.0') >= 0) {
$stack = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
$where = basename($stack[0]['file']) . ':' . $stack[0]['line'] . ':' . $stack[1]['function'] . ': ';
@@ -590,7 +601,8 @@ function logger($msg, $level = LOGGER_NORMAL, $priority = LOG_INFO) {
$s = datetime_convert() . ':' . log_priority_str($priority) . ':' . session_id() . ':' . $where . $msg . PHP_EOL;
$pluginfo = array('filename' => $logfile, 'loglevel' => $level, 'message' => $s,'priority' => $priority, 'logged' => false);
- call_hooks('logger',$pluginfo);
+ if(! (App::$module == 'setup'))
+ call_hooks('logger',$pluginfo);
if(! $pluginfo['logged'])
@file_put_contents($pluginfo['filename'], $pluginfo['message'], FILE_APPEND);
@@ -648,11 +660,10 @@ function log_priority_str($priority) {
* @param int $level A log level.
*/
function dlogger($msg, $level = 0) {
+
// turn off logger in install mode
- global $a;
- global $db;
- if((App::$module == 'install') || (! ($db && $db->connected)))
+ if(App::$module == 'setup')
return;
$debugging = get_config('system','debugging');
@@ -810,7 +821,6 @@ function get_mentions($item,$tags) {
function contact_block() {
$o = '';
- $a = get_app();
if(! App::$profile['uid'])
return;
@@ -923,7 +933,7 @@ function micropro($contact, $redirect = false, $class = '', $textmode = false) {
function search($s,$id='search-box',$url='/search',$save = false) {
- $a = get_app();
+
return replace_macros(get_markup_template('searchbox.tpl'),array(
'$s' => $s,
'$id' => $id,
@@ -1068,7 +1078,7 @@ function get_mood_verbs() {
// Function to list all smilies, both internal and from addons
// Returns array with keys 'texts' and 'icons'
function list_smilies() {
- $a = get_app();
+
$texts = array(
'&lt;3',
'&lt;/3',
@@ -1101,10 +1111,8 @@ function list_smilies() {
':coffee',
':facepalm',
':like',
- ':dislike',
- 'red#matrix',
- 'red#',
- 'r#'
+ ':dislike'
+
);
$icons = array(
@@ -1140,9 +1148,6 @@ function list_smilies() {
'<img class="smiley" src="' . z_root() . '/images/smiley-facepalm.gif" alt=":facepalm" />',
'<img class="smiley" src="' . z_root() . '/images/like.gif" alt=":like" />',
'<img class="smiley" src="' . z_root() . '/images/dislike.gif" alt=":dislike" />',
- '<a href="http://getzot.com"><strong>red<img class="smiley bb_rm-logo" src="' . z_root() . '/images/rm-32.png" alt="' . urlencode('red#matrix') . '" />matrix</strong></a>',
- '<a href="http://getzot.com"><strong>red<img class="smiley bb_rm-logo" src="' . z_root() . '/images/rm-32.png" alt="' . urlencode('red#') . '" />matrix</strong></a>',
- '<a href="http://getzot.com"><strong>red<img class="smiley bb_rm-logo" src="' . z_root() . '/images/rm-32.png" alt="r#" />matrix</strong></a>'
);
@@ -1213,7 +1218,7 @@ function smile_unshield($m) {
* @param array $x
*/
function preg_heart($x) {
- $a = get_app();
+
if (strlen($x[1]) == 1)
return $x[0];
@@ -1319,7 +1324,7 @@ function theme_attachments(&$item) {
$title = t('Size') . ' ' . (($r['length']) ? userReadableSize($r['length']) : t('unknown'));
- require_once('include/identity.php');
+ require_once('include/channel.php');
if(is_foreigner($item['author_xchan']))
$url = $r['href'];
else
@@ -1486,7 +1491,6 @@ function format_event($jobject) {
}
function prepare_body(&$item,$attach = false) {
- require_once('include/identity.php');
call_hooks('prepare_body_init', $item);
@@ -1716,7 +1720,6 @@ function feed_hublinks() {
/* return atom link elements for salmon endpoints */
function feed_salmonlinks($nick) {
- $a = get_app();
$salmon = '<link rel="salmon" href="' . xmlify(z_root() . '/salmon/' . $nick) . '" />' . "\n" ;
@@ -1784,7 +1787,7 @@ function mimetype_select($channel_id, $current = 'text/bbcode') {
'application/x-pdl'
);
- $a = get_app();
+
if(App::$is_sys) {
$x[] = 'application/x-php';
}
@@ -1817,7 +1820,6 @@ function mimetype_select($channel_id, $current = 'text/bbcode') {
function lang_selector() {
- global $a;
$langs = glob('view/*/hstrings.php');
@@ -2261,7 +2263,7 @@ function design_tools() {
$sys = false;
if(App::$is_sys && is_site_admin()) {
- require_once('include/identity.php');
+ require_once('include/channel.php');
$channel = get_sys_channel();
$sys = true;
}
diff --git a/include/widgets.php b/include/widgets.php
index cff58d225..1cc6dfc28 100644
--- a/include/widgets.php
+++ b/include/widgets.php
@@ -8,17 +8,17 @@
require_once('include/dir_fns.php');
require_once('include/contact_widgets.php');
require_once('include/attach.php');
-require_once('include/Contact.php');
+
function widget_profile($args) {
- $block = (((get_config('system', 'block_public')) && (! local_channel()) && (! remote_channel())) ? true : false);
+ $block = observer_prohibited();
return profile_sidebar(App::$profile, $block, true);
}
function widget_zcard($args) {
- $block = (((get_config('system', 'block_public')) && (! local_channel()) && (! remote_channel())) ? true : false);
+ $block = observer_prohibited();
$channel = channelx_by_n(App::$profile_uid);
return get_zcard($channel,get_observer_hash(),array('width' => 875));
}
@@ -369,7 +369,7 @@ function widget_fullprofile($arr) {
if(! App::$profile['profile_uid'])
return;
- $block = (((get_config('system', 'block_public')) && (! local_channel()) && (! remote_channel())) ? true : false);
+ $block = observer_prohibited();
return profile_sidebar(App::$profile, $block);
}
@@ -379,7 +379,7 @@ function widget_shortprofile($arr) {
if(! App::$profile['profile_uid'])
return;
- $block = (((get_config('system', 'block_public')) && (! local_channel()) && (! remote_channel())) ? true : false);
+ $block = observer_prohibited();
return profile_sidebar(App::$profile, $block, true, true);
}
@@ -771,7 +771,6 @@ function widget_eventstools($arr) {
}
function widget_design_tools($arr) {
- $a = get_app();
// mod menu doesn't load a profile. For any modules which load a profile, check it.
// otherwise local_channel() is sufficient for permissions.
@@ -806,7 +805,6 @@ function widget_photo_albums($arr) {
function widget_vcard($arr) {
- require_once ('include/Contact.php');
return vcard_from_xchan('', App::get_observer());
}
@@ -835,8 +833,7 @@ function widget_menu_preview($arr) {
function widget_chatroom_list($arr) {
- require_once("include/chat.php");
- $r = chatroom_list(App::$profile['profile_uid']);
+ $r = Zotlabs\Lib\Chatroom::roomlist(App::$profile['profile_uid']);
if($r) {
return replace_macros(get_markup_template('chatroomlist.tpl'), array(
@@ -1085,7 +1082,7 @@ function widget_photo($arr) {
function widget_cover_photo($arr) {
- require_once('include/identity.php');
+ require_once('include/channel.php');
$o = '';
if(App::$module == 'channel' && $_REQUEST['mid'])
diff --git a/include/zot.php b/include/zot.php
index 54a3fe640..ecfbfa128 100644
--- a/include/zot.php
+++ b/include/zot.php
@@ -329,8 +329,12 @@ function zot_refresh($them, $channel = null, $force = false) {
return false;
}
+ $token = random_string();
+
$postvars = array();
+ $postvars['token'] = $token;
+
if($channel) {
$postvars['target'] = $channel['channel_guid'];
$postvars['target_sig'] = $channel['channel_guid_sig'];
@@ -343,11 +347,13 @@ function zot_refresh($them, $channel = null, $force = false) {
$postvars['guid_hash'] = $them['xchan_hash'];
if (array_key_exists('xchan_guid',$them) && $them['xchan_guid']
&& array_key_exists('xchan_guid_sig',$them) && $them['xchan_guid_sig']) {
-
$postvars['guid'] = $them['xchan_guid'];
$postvars['guid_sig'] = $them['xchan_guid_sig'];
+
}
+ $token = random_string();
+
$rhs = '/.well-known/zot-info';
$result = z_post_url($url . $rhs,$postvars);
@@ -363,6 +369,22 @@ function zot_refresh($them, $channel = null, $force = false) {
return false;
}
+ $signed_token = ((is_array($j) && array_key_exists('signed_token',$j)) ? $j['signed_token'] : null);
+ if($signed_token) {
+ $valid = rsa_verify('token.' . $token,base64url_decode($signed_token),$j['key']);
+ if(! $valid) {
+ logger('invalid signed token: ' . $url . $rhs, LOGGER_NORMAL, LOG_ERR);
+ return false;
+ }
+ }
+ else {
+ 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 false;
+ }
+ }
+
$x = import_xchan($j, (($force) ? UPDATE_FLAGS_FORCED : UPDATE_FLAGS_UPDATED));
if(! $x['success'])
@@ -505,8 +527,7 @@ function zot_refresh($them, $channel = null, $force = false) {
if($new_connection) {
if($new_perms != $previous_perms)
Zotlabs\Daemon\Master::Summon(array('Notifier','permission_create',$new_connection[0]['abook_id']));
- require_once('include/enotify.php');
- notification(array(
+ Zotlabs\Lib\Enotify::submit(array(
'type' => NOTIFY_INTRO,
'from_xchan' => $x['hash'],
'to_xchan' => $channel['channel_hash'],
@@ -1332,7 +1353,7 @@ function zot_import($arr, $sender_url) {
*/
function public_recips($msg) {
- require_once('include/identity.php');
+ require_once('include/channel.php');
$check_mentions = false;
$include_sys = false;
@@ -1494,7 +1515,7 @@ function public_recips($msg) {
/**
* @brief
*
- * This is the second part of public_recipes().
+ * This is the second part of public_recips().
* We'll find all the channels willing to accept public posts from us, then
* match them against the sender privacy scope and see who in that list that
* the sender is allowing.
@@ -2945,8 +2966,6 @@ function build_sync_packet($uid = 0, $packet = null, $groups_changed = false) {
if(UNO)
return;
- $a = get_app();
-
logger('build_sync_packet');
if($packet)
@@ -3222,7 +3241,6 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) {
$clean = array();
if($abook['abook_xchan'] && $abook['entry_deleted']) {
logger('process_channel_sync_delivery: removing abook entry for ' . $abook['abook_xchan']);
- require_once('include/Contact.php');
$r = q("select abook_id, abook_feed from abook where abook_xchan = '%s' and abook_channel = %d and abook_self = 0 limit 1",
dbesc($abook['abook_xchan']),
@@ -3672,6 +3690,8 @@ function zotinfo($arr) {
$zsig = ((x($arr,'target_sig')) ? $arr['target_sig'] : '');
$zkey = ((x($arr,'key')) ? $arr['key'] : '');
$mindate = ((x($arr,'mindate')) ? $arr['mindate'] : '');
+ $token = ((x($arr,'token')) ? $arr['token'] : '');
+
$feed = ((x($arr,'feed')) ? intval($arr['feed']) : 0);
if($ztarget) {
@@ -3816,6 +3836,10 @@ function zotinfo($arr) {
// Communication details
+ if($token)
+ $ret['signed_token'] = base64url_encode(rsa_sign('token.' . $token,$e['channel_prvkey']));
+
+
$ret['guid'] = $e['xchan_guid'];
$ret['guid_sig'] = $e['xchan_guid_sig'];
$ret['key'] = $e['xchan_pubkey'];
@@ -3920,7 +3944,7 @@ function zotinfo($arr) {
$ret['site']['accounts'] = account_total();
- require_once('include/identity.php');
+ require_once('include/channel.php');
$ret['site']['channels'] = channel_total();
@@ -3928,8 +3952,6 @@ function zotinfo($arr) {
$ret['site']['admin'] = get_config('system','admin_email');
- $a = get_app();
-
$visible_plugins = array();
if(is_array(App::$plugins) && count(App::$plugins)) {
$r = q("select * from addon where hidden = 0");
@@ -3944,7 +3966,7 @@ function zotinfo($arr) {
$ret['site']['sellpage'] = get_config('system','sellpage');
$ret['site']['location'] = get_config('system','site_location');
$ret['site']['realm'] = get_directory_realm();
- $ret['site']['project'] = Zotlabs\Lib\System::get_platform_name() . Zotlabs\Lib\System::get_server_role();
+ $ret['site']['project'] = Zotlabs\Lib\System::get_platform_name() . ' ' . Zotlabs\Lib\System::get_server_role();
}
@@ -4415,7 +4437,6 @@ function zot_reply_purge($sender,$recipients) {
$arr = $sender;
$sender_hash = make_xchan_hash($arr['guid'],$arr['guid_sig']);
- require_once('include/Contact.php');
remove_all_xchan_resources($sender_hash);
$ret['success'] = true;