diff options
author | Andrew Manning <tamanning@zoho.com> | 2016-05-27 06:35:15 -0400 |
---|---|---|
committer | Andrew Manning <tamanning@zoho.com> | 2016-05-27 06:35:15 -0400 |
commit | d554681174084e1715dfae4c21af9f6edcbad59e (patch) | |
tree | eb585cce4ebe24d663b2e7eab28a62da612efec1 /Zotlabs | |
parent | e00b8a70829213a4333a53a097c2c498d529f5d6 (diff) | |
parent | 551cf8ee9413c5c57e7b71d6016466e598636900 (diff) | |
download | volse-hubzilla-d554681174084e1715dfae4c21af9f6edcbad59e.tar.gz volse-hubzilla-d554681174084e1715dfae4c21af9f6edcbad59e.tar.bz2 volse-hubzilla-d554681174084e1715dfae4c21af9f6edcbad59e.zip |
Merge remote-tracking branch 'upstream/dev' into wiki
Diffstat (limited to 'Zotlabs')
73 files changed, 2333 insertions, 517 deletions
diff --git a/Zotlabs/Daemon/Cron_weekly.php b/Zotlabs/Daemon/Cron_weekly.php index dc781ad73..1d8420947 100644 --- a/Zotlabs/Daemon/Cron_weekly.php +++ b/Zotlabs/Daemon/Cron_weekly.php @@ -21,7 +21,6 @@ class Cron_weekly { require_once('include/hubloc.php'); prune_hub_reinstalls(); - require_once('include/Contact.php'); mark_orphan_hubsxchans(); diff --git a/Zotlabs/Daemon/Externals.php b/Zotlabs/Daemon/Externals.php index 167b0524f..24cfe64ec 100644 --- a/Zotlabs/Daemon/Externals.php +++ b/Zotlabs/Daemon/Externals.php @@ -3,7 +3,7 @@ namespace Zotlabs\Daemon; require_once('include/zot.php'); -require_once('include/identity.php'); +require_once('include/channel.php'); class Externals { diff --git a/Zotlabs/Daemon/Gprobe.php b/Zotlabs/Daemon/Gprobe.php index 8141739be..43cce93c3 100644 --- a/Zotlabs/Daemon/Gprobe.php +++ b/Zotlabs/Daemon/Gprobe.php @@ -22,9 +22,8 @@ class Gprobe { ); if(! $r) { - $x = zot_finger($url,null); - if($x['success']) { - $j = json_decode($x['body'],true); + $j = \Zotlabs\Zot\Finger::run($url,null); + if($j['success']) { $y = import_xchan($j); } } diff --git a/Zotlabs/Daemon/Notifier.php b/Zotlabs/Daemon/Notifier.php index 65690f8ce..590be31ee 100644 --- a/Zotlabs/Daemon/Notifier.php +++ b/Zotlabs/Daemon/Notifier.php @@ -72,8 +72,7 @@ require_once('include/queue_fn.php'); require_once('include/datetime.php'); require_once('include/items.php'); require_once('include/bbcode.php'); -require_once('include/identity.php'); -require_once('include/Contact.php'); +require_once('include/channel.php'); class Notifier { diff --git a/Zotlabs/Daemon/Onepoll.php b/Zotlabs/Daemon/Onepoll.php index 2610ad151..036a4991b 100644 --- a/Zotlabs/Daemon/Onepoll.php +++ b/Zotlabs/Daemon/Onepoll.php @@ -4,7 +4,7 @@ namespace Zotlabs\Daemon; require_once('include/zot.php'); require_once('include/socgraph.php'); -require_once('include/Contact.php'); + class Onepoll { diff --git a/Zotlabs/Daemon/Poller.php b/Zotlabs/Daemon/Poller.php index 278faf3ee..75efbf8f7 100644 --- a/Zotlabs/Daemon/Poller.php +++ b/Zotlabs/Daemon/Poller.php @@ -62,11 +62,6 @@ class Poller { $d = datetime_convert(); - // TODO check to see if there are any cronhooks before wasting a process - - if(! $restart) - Master::Summon(array('Cronhooks')); - // Only poll from those with suitable relationships $abandon_sql = (($abandon_days) diff --git a/Zotlabs/Daemon/Queue.php b/Zotlabs/Daemon/Queue.php index c247be8e4..27306589d 100644 --- a/Zotlabs/Daemon/Queue.php +++ b/Zotlabs/Daemon/Queue.php @@ -6,6 +6,7 @@ require_once('include/queue_fn.php'); require_once('include/zot.php'); class Queue { + static public function run($argc,$argv) { require_once('include/items.php'); diff --git a/Zotlabs/Daemon/Ratenotif.php b/Zotlabs/Daemon/Ratenotif.php index a404273e2..1cba5e26d 100644 --- a/Zotlabs/Daemon/Ratenotif.php +++ b/Zotlabs/Daemon/Ratenotif.php @@ -12,7 +12,6 @@ class Ratenotif { require_once("datetime.php"); require_once('include/items.php'); - require_once('include/Contact.php'); if($argc < 3) return; diff --git a/Zotlabs/Lib/Apps.php b/Zotlabs/Lib/Apps.php new file mode 100644 index 000000000..6d2ef4e45 --- /dev/null +++ b/Zotlabs/Lib/Apps.php @@ -0,0 +1,659 @@ +<?php /** @file */ + +namespace Zotlabs\Lib; + +/** + * Apps + * + */ + +require_once('include/plugin.php'); +require_once('include/channel.php'); + + +class Apps { + + static public 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 = self::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 = self::parse_app_description($f,$translate); + if($x) { + $ret[] = $x; + } + } + } + } + + return $ret; + + } + + + static public 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 = self::get_system_apps(false); + if($apps) { + foreach($apps as $app) { + $app['uid'] = local_channel(); + $app['guid'] = hash('whirlpool',$app['name']); + $app['system'] = 1; + self::app_install(local_channel(),$app); + } + } + set_pconfig(local_channel(),'system','apps_installed',1); + } + + + static public function app_name_compare($a,$b) { + return strcmp($a['name'],$b['name']); + } + + + static public 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(''','&dquot;'),$ret['desc']); + + if(array_key_exists('target',$ret)) + $ret['target'] = str_replace(array('\'','"'),array(''','&dquot;'),$ret['target']); + + if(array_key_exists('requires',$ret)) { + $requires = explode(',',$ret['requires']); + foreach($requires as $require) { + $require = trim(strtolower($require)); + switch($require) { + case 'nologin': + if(local_channel()) + unset($ret); + break; + case 'admin': + if(! is_site_admin()) + unset($ret); + break; + case 'local_channel': + if(! local_channel()) + unset($ret); + break; + case 'public_profile': + if(! is_public_profile()) + unset($ret); + break; + case 'observer': + if(! $observer) + unset($ret); + break; + default: + if(! (local_channel() && feature_enabled(local_channel(),$require))) + unset($ret); + break; + + } + } + } + if($ret) { + if($translate) + self::translate_system_apps($ret); + return $ret; + } + return false; + } + + + static public function translate_system_apps(&$arr) { + $apps = array( + 'Site Admin' => t('Site Admin'), + 'Bug Report' => t('Bug Report'), + 'View Bookmarks' => t('View Bookmarks'), + 'My Chatrooms' => t('My Chatrooms'), + 'Connections' => t('Connections'), + 'Firefox Share' => t('Firefox Share'), + 'Remote Diagnostics' => t('Remote Diagnostics'), + 'Suggest Channels' => t('Suggest Channels'), + 'Login' => t('Login'), + 'Channel Manager' => t('Channel Manager'), + 'Grid' => t('Grid'), + 'Settings' => t('Settings'), + 'Files' => t('Files'), + 'Webpages' => t('Webpages'), + 'Channel Home' => t('Channel Home'), + 'View Profile' => t('View Profile'), + 'Photos' => t('Photos'), + 'Events' => t('Events'), + 'Directory' => t('Directory'), + 'Help' => t('Help'), + 'Mail' => t('Mail'), + 'Mood' => t('Mood'), + 'Poke' => t('Poke'), + 'Chat' => t('Chat'), + 'Search' => t('Search'), + 'Probe' => t('Probe'), + 'Suggest' => t('Suggest'), + 'Random Channel' => t('Random Channel'), + 'Invite' => t('Invite'), + 'Features' => t('Features'), + 'Language' => t('Language'), + 'Post' => t('Post'), + 'Profile Photo' => t('Profile Photo') + ); + + if(array_key_exists($arr['name'],$apps)) + $arr['name'] = $apps[$arr['name']]; + + } + + + // papp is a portable app + + static public function app_render($papp,$mode = 'view') { + + /** + * modes: + * view: normal mode for viewing an app via bbcode from a conversation or page + * provides install/update button if you're logged in locally + * list: normal mode for viewing an app on the app page + * no buttons are shown + * edit: viewing the app page in editing mode provides a delete button + */ + + $installed = false; + + if(! $papp) + return; + + if(! $papp['photo']) + $papp['photo'] = z_root() . '/' . get_default_profile_photo(80); + + $papp['papp'] = self::papp_encode($papp); + + if(! strstr($papp['url'],'://')) + $papp['url'] = z_root() . ((strpos($papp['url'],'/') === 0) ? '' : '/') . $papp['url']; + + foreach($papp as $k => $v) { + if(strpos($v,'http') === 0 && $k != 'papp') + $papp[$k] = zid($v); + if($k === 'desc') + $papp['desc'] = str_replace(array('\'','"'),array(''','&dquot;'),$papp['desc']); + + if($k === 'requires') { + $requires = explode(',',$v); + foreach($requires as $require) { + $require = trim(strtolower($require)); + switch($require) { + case 'nologin': + if(local_channel()) + return ''; + break; + case 'admin': + if(! is_site_admin()) + return ''; + break; + case 'local_channel': + if(! local_channel()) + return ''; + break; + case 'public_profile': + if(! is_public_profile()) + return ''; + break; + case 'observer': + $observer = \App::get_observer(); + if(! $observer) + return ''; + break; + default: + if(! (local_channel() && feature_enabled(local_channel(),$require))) + return ''; + break; + + } + } + } + } + + $hosturl = ''; + + if(local_channel()) { + $installed = self::app_installed(local_channel(),$papp); + $hosturl = z_root() . '/'; + } + elseif(remote_channel()) { + $observer = \App::get_observer(); + if($observer && $observer['xchan_network'] === 'zot') { + // some folks might have xchan_url redirected offsite, use the connurl + $x = parse_url($observer['xchan_connurl']); + if($x) { + $hosturl = $x['scheme'] . '://' . $x['host'] . '/'; + } + } + } + + $install_action = (($installed) ? t('Update') : t('Install')); + + return replace_macros(get_markup_template('app.tpl'),array( + '$app' => $papp, + '$hosturl' => $hosturl, + '$purchase' => (($papp['page'] && (! $installed)) ? t('Purchase') : ''), + '$install' => (($hosturl && $mode == 'view') ? $install_action : ''), + '$edit' => ((local_channel() && $installed && $mode == 'edit') ? t('Edit') : ''), + '$delete' => ((local_channel() && $installed && $mode == 'edit') ? t('Delete') : '') + )); + } + + static public function app_install($uid,$app) { + $app['uid'] = $uid; + + if(self::app_installed($uid,$app)) + $x = self::app_update($app); + else + $x = self::app_store($app); + + if($x['success']) { + $r = q("select * from app where app_id = '%s' and app_channel = %d limit 1", + dbesc($x['app_id']), + intval($uid) + ); + if($r) { + if(! $r[0]['app_system']) { + if($app['categories'] && (! $app['term'])) { + $r[0]['term'] = q("select * from term where otype = %d and oid = d", + intval(TERM_OBJ_APP), + intval($r[0]['id']) + ); + build_sync_packet($uid,array('app' => $r[0])); + } + } + } + return $x['app_id']; + } + return false; + } + + static public function app_destroy($uid,$app) { + + + if($uid && $app['guid']) { + + $x = q("select * from app where app_id = '%s' and app_channel = %d limit 1", + dbesc($app['guid']), + intval($uid) + ); + if($x) { + $x[0]['app_deleted'] = 1; + q("delete from term where otype = %d and oid = %d", + intval(TERM_OBJ_APP), + intval($x[0]['id']) + ); + if($x[0]['app_system']) { + $r = q("update app set app_deleted = 1 where app_id = '%s' and app_channel = %d", + dbesc($app['guid']), + intval($uid) + ); + } + else { + $r = q("delete from app where app_id = '%s' and app_channel = %d", + dbesc($app['guid']), + intval($uid) + ); + + // we don't sync system apps - they may be completely different on the other system + build_sync_packet($uid,array('app' => $x)); + } + } + } + } + + + static public function app_installed($uid,$app) { + + $r = q("select id from app where app_id = '%s' and app_version = '%s' and app_channel = %d limit 1", + dbesc((array_key_exists('guid',$app)) ? $app['guid'] : ''), + dbesc((array_key_exists('version',$app)) ? $app['version'] : ''), + intval($uid) + ); + return(($r) ? true : false); + + } + + + static public function app_list($uid, $deleted = false, $cat = '') { + if($deleted) + $sql_extra = " and app_deleted = 1 "; + else + $sql_extra = " and app_deleted = 0 "; + + if($cat) { + $r = q("select oid from term where otype = %d and term = '%s'", + intval(TERM_OBJ_APP), + dbesc($cat) + ); + if(! $r) + return $r; + $sql_extra .= " and app.id in ( "; + $s = ''; + foreach($r as $rr) { + if($s) + $s .= ','; + $s .= intval($rr['oid']); + } + $sql_extra .= $s . ') '; + } + + $r = q("select * from app where app_channel = %d $sql_extra order by app_name asc", + intval($uid) + ); + if($r) { + for($x = 0; $x < count($r); $x ++) { + if(! $r[$x]['app_system']) + $r[$x]['type'] = 'personal'; + $r[$x]['term'] = q("select * from term where otype = %d and oid = %d", + intval(TERM_OBJ_APP), + intval($r[$x]['id']) + ); + } + } + return($r); + } + + + static public function app_decode($s) { + $x = base64_decode(str_replace(array('<br />',"\r","\n",' '),array('','','',''),$s)); + return json_decode($x,true); + } + + + static public function app_store($arr) { + + // logger('app_store: ' . print_r($arr,true)); + + $darray = array(); + $ret = array('success' => false); + + $darray['app_url'] = ((x($arr,'url')) ? $arr['url'] : ''); + $darray['app_channel'] = ((x($arr,'uid')) ? $arr['uid'] : 0); + + if((! $darray['app_url']) || (! $darray['app_channel'])) + return $ret; + + if($arr['photo'] && ! strstr($arr['photo'],z_root())) { + $x = import_xchan_photo($arr['photo'],get_observer_hash(),true); + $arr['photo'] = $x[1]; + } + + + $darray['app_id'] = ((x($arr,'guid')) ? $arr['guid'] : random_string(). '.' . \App::get_hostname()); + $darray['app_sig'] = ((x($arr,'sig')) ? $arr['sig'] : ''); + $darray['app_author'] = ((x($arr,'author')) ? $arr['author'] : get_observer_hash()); + $darray['app_name'] = ((x($arr,'name')) ? escape_tags($arr['name']) : t('Unknown')); + $darray['app_desc'] = ((x($arr,'desc')) ? escape_tags($arr['desc']) : ''); + $darray['app_photo'] = ((x($arr,'photo')) ? $arr['photo'] : z_root() . '/' . get_default_profile_photo(80)); + $darray['app_version'] = ((x($arr,'version')) ? escape_tags($arr['version']) : ''); + $darray['app_addr'] = ((x($arr,'addr')) ? escape_tags($arr['addr']) : ''); + $darray['app_price'] = ((x($arr,'price')) ? escape_tags($arr['price']) : ''); + $darray['app_page'] = ((x($arr,'page')) ? escape_tags($arr['page']) : ''); + $darray['app_requires'] = ((x($arr,'requires')) ? escape_tags($arr['requires']) : ''); + $darray['app_system'] = ((x($arr,'system')) ? intval($arr['system']) : 0); + $darray['app_deleted'] = ((x($arr,'deleted')) ? intval($arr['deleted']) : 0); + + $created = datetime_convert(); + + $r = q("insert into app ( app_id, app_sig, app_author, app_name, app_desc, app_url, app_photo, app_version, app_channel, app_addr, app_price, app_page, app_requires, app_created, app_edited, app_system, app_deleted ) values ( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, %d )", + dbesc($darray['app_id']), + dbesc($darray['app_sig']), + dbesc($darray['app_author']), + dbesc($darray['app_name']), + dbesc($darray['app_desc']), + dbesc($darray['app_url']), + dbesc($darray['app_photo']), + dbesc($darray['app_version']), + intval($darray['app_channel']), + dbesc($darray['app_addr']), + dbesc($darray['app_price']), + dbesc($darray['app_page']), + dbesc($darray['app_requires']), + dbesc($created), + dbesc($created), + intval($darray['app_system']), + intval($darray['app_deleted']) + ); + if($r) { + $ret['success'] = true; + $ret['app_id'] = $darray['app_id']; + } + if($arr['categories']) { + $x = q("select id from app where app_id = '%s' and app_channel = %d limit 1", + dbesc($darray['app_id']), + intval($darray['app_channel']) + ); + $y = explode(',',$arr['categories']); + if($y) { + foreach($y as $t) { + $t = trim($t); + if($t) { + store_item_tag($darray['app_channel'],$x[0]['id'],TERM_OBJ_APP,TERM_CATEGORY,escape_tags($t),escape_tags(z_root() . '/apps/?f=&cat=' . escape_tags($t))); + } + } + } + } + + return $ret; + } + + + static public function app_update($arr) { + + $darray = array(); + $ret = array('success' => false); + + $darray['app_url'] = ((x($arr,'url')) ? $arr['url'] : ''); + $darray['app_channel'] = ((x($arr,'uid')) ? $arr['uid'] : 0); + $darray['app_id'] = ((x($arr,'guid')) ? $arr['guid'] : 0); + + if((! $darray['app_url']) || (! $darray['app_channel']) || (! $darray['app_id'])) + return $ret; + + if($arr['photo'] && ! strstr($arr['photo'],z_root())) { + $x = import_xchan_photo($arr['photo'],get_observer_hash(),true); + $arr['photo'] = $x[1]; + } + + $darray['app_sig'] = ((x($arr,'sig')) ? $arr['sig'] : ''); + $darray['app_author'] = ((x($arr,'author')) ? $arr['author'] : get_observer_hash()); + $darray['app_name'] = ((x($arr,'name')) ? escape_tags($arr['name']) : t('Unknown')); + $darray['app_desc'] = ((x($arr,'desc')) ? escape_tags($arr['desc']) : ''); + $darray['app_photo'] = ((x($arr,'photo')) ? $arr['photo'] : z_root() . '/' . get_default_profile_photo(80)); + $darray['app_version'] = ((x($arr,'version')) ? escape_tags($arr['version']) : ''); + $darray['app_addr'] = ((x($arr,'addr')) ? escape_tags($arr['addr']) : ''); + $darray['app_price'] = ((x($arr,'price')) ? escape_tags($arr['price']) : ''); + $darray['app_page'] = ((x($arr,'page')) ? escape_tags($arr['page']) : ''); + $darray['app_requires'] = ((x($arr,'requires')) ? escape_tags($arr['requires']) : ''); + $darray['app_system'] = ((x($arr,'system')) ? intval($arr['system']) : 0); + $darray['app_deleted'] = ((x($arr,'deleted')) ? intval($arr['deleted']) : 0); + + $edited = datetime_convert(); + + $r = q("update app set app_sig = '%s', app_author = '%s', app_name = '%s', app_desc = '%s', app_url = '%s', app_photo = '%s', app_version = '%s', app_addr = '%s', app_price = '%s', app_page = '%s', app_requires = '%s', app_edited = '%s', app_system = %d, app_deleted = %d where app_id = '%s' and app_channel = %d", + dbesc($darray['app_sig']), + dbesc($darray['app_author']), + dbesc($darray['app_name']), + dbesc($darray['app_desc']), + dbesc($darray['app_url']), + dbesc($darray['app_photo']), + dbesc($darray['app_version']), + dbesc($darray['app_addr']), + dbesc($darray['app_price']), + dbesc($darray['app_page']), + dbesc($darray['app_requires']), + dbesc($edited), + intval($darray['app_system']), + intval($darray['app_deleted']), + dbesc($darray['app_id']), + intval($darray['app_channel']) + ); + if($r) { + $ret['success'] = true; + $ret['app_id'] = $darray['app_id']; + } + + $x = q("select id from app where app_id = '%s' and app_channel = %d limit 1", + dbesc($darray['app_id']), + intval($darray['app_channel']) + ); + if($x) { + q("delete from term where otype = %d and oid = %d", + intval(TERM_OBJ_APP), + intval($x[0]['id']) + ); + if($arr['categories']) { + $y = explode(',',$arr['categories']); + if($y) { + foreach($y as $t) { + $t = trim($t); + if($t) { + store_item_tag($darray['app_channel'],$x[0]['id'],TERM_OBJ_APP,TERM_CATEGORY,escape_tags($t),escape_tags(z_root() . '/apps/?f=&cat=' . escape_tags($t))); + } + } + } + } + } + + return $ret; + + } + + + static public function app_encode($app,$embed = false) { + + $ret = array(); + + $ret['type'] = 'personal'; + + if($app['app_id']) + $ret['guid'] = $app['app_id']; + + if($app['app_id']) + $ret['guid'] = $app['app_id']; + + if($app['app_sig']) + $ret['sig'] = $app['app_sig']; + + if($app['app_author']) + $ret['author'] = $app['app_author']; + + if($app['app_name']) + $ret['name'] = $app['app_name']; + + if($app['app_desc']) + $ret['desc'] = $app['app_desc']; + + if($app['app_url']) + $ret['url'] = $app['app_url']; + + if($app['app_photo']) + $ret['photo'] = $app['app_photo']; + + if($app['app_version']) + $ret['version'] = $app['app_version']; + + if($app['app_addr']) + $ret['addr'] = $app['app_addr']; + + if($app['app_price']) + $ret['price'] = $app['app_price']; + + if($app['app_page']) + $ret['page'] = $app['app_page']; + + if($app['app_requires']) + $ret['requires'] = $app['app_requires']; + + if($app['app_system']) + $ret['system'] = $app['app_system']; + + if($app['app_deleted']) + $ret['deleted'] = $app['app_deleted']; + + if($app['term']) { + $s = ''; + foreach($app['term'] as $t) { + if($s) + $s .= ','; + $s .= $t['term']; + } + $ret['categories'] = $s; + } + + + if(! $embed) + return $ret; + + if(array_key_exists('categories',$ret)) + unset($ret['categories']); + + $j = json_encode($ret); + return '[app]' . chunk_split(base64_encode($j),72,"\n") . '[/app]'; + + } + + + static public function papp_encode($papp) { + return chunk_split(base64_encode(json_encode($papp)),72,"\n"); + + } + +} + + diff --git a/Zotlabs/Lib/Chatroom.php b/Zotlabs/Lib/Chatroom.php new file mode 100644 index 000000000..e1a9a10b3 --- /dev/null +++ b/Zotlabs/Lib/Chatroom.php @@ -0,0 +1,267 @@ +<?php +namespace Zotlabs\Lib; + +/** + * @brief Chat related functions. + */ + + + +class Chatroom { + /** + * @brief Creates a chatroom. + * + * @param array $channel + * @param array $arr + * @return An associative array containing: + * - success: A boolean + * - message: (optional) A string + */ + + static public function 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; + } + + + static public function destroy($channel,$arr) { + + $ret = array('success' => false); + + if(intval($arr['cr_id'])) + $sql_extra = " and cr_id = " . intval($arr['cr_id']) . " "; + elseif(trim($arr['cr_name'])) + $sql_extra = " and cr_name = '" . protect_sprintf(dbesc(trim($arr['cr_name']))) . "' "; + else { + $ret['message'] = t('Invalid room specifier.'); + return $ret; + } + + $r = q("select * from chatroom where cr_uid = %d $sql_extra limit 1", + intval($channel['channel_id']) + ); + if(! $r) { + $ret['message'] = t('Invalid room specifier.'); + return $ret; + } + + build_sync_packet($channel['channel_id'],array('chatroom' => $r)); + + q("delete from chatroom where cr_id = %d", + intval($r[0]['cr_id']) + ); + if($r[0]['cr_id']) { + q("delete from chatpresence where cp_room = %d", + intval($r[0]['cr_id']) + ); + q("delete from chat where chat_room = %d", + intval($r[0]['cr_id']) + ); + } + + $ret['success'] = true; + return $ret; + } + + + static public function enter($observer_xchan, $room_id, $status, $client) { + + if(! $room_id || ! $observer_xchan) + return; + + $r = q("select * from chatroom where cr_id = %d limit 1", + intval($room_id) + ); + if(! $r) { + notice( t('Room not found.') . EOL); + return false; + } + require_once('include/security.php'); + $sql_extra = permissions_sql($r[0]['cr_uid']); + + $x = q("select * from chatroom where cr_id = %d and cr_uid = %d $sql_extra limit 1", + intval($room_id), + intval($r[0]['cr_uid']) + ); + if(! $x) { + notice( t('Permission denied.') . EOL); + return false; + } + + $limit = service_class_fetch($r[0]['cr_uid'], 'chatters_inroom'); + if($limit !== false) { + $y = q("select count(*) as total from chatpresence where cp_room = %d", + intval($room_id) + ); + if($y && $y[0]['total'] > $limit) { + notice( t('Room is full') . EOL); + return false; + } + } + + if(intval($x[0]['cr_expire'])) { + $r = q("delete from chat where created < %s - INTERVAL %s and chat_room = %d", + db_utcnow(), + db_quoteinterval( intval($x[0]['cr_expire']) . ' MINUTE' ), + intval($x[0]['cr_id']) + ); + } + + $r = q("select * from chatpresence where cp_xchan = '%s' and cp_room = %d limit 1", + dbesc($observer_xchan), + intval($room_id) + ); + if($r) { + q("update chatpresence set cp_last = '%s' where cp_id = %d and cp_client = '%s'", + dbesc(datetime_convert()), + intval($r[0]['cp_id']), + dbesc($client) + ); + return true; + } + + $r = q("insert into chatpresence ( cp_room, cp_xchan, cp_last, cp_status, cp_client ) + values ( %d, '%s', '%s', '%s', '%s' )", + intval($room_id), + dbesc($observer_xchan), + dbesc(datetime_convert()), + dbesc($status), + dbesc($client) + ); + + return $r; + } + + + function leave($observer_xchan, $room_id, $client) { + if(! $room_id || ! $observer_xchan) + return; + + $r = q("select * from chatpresence where cp_xchan = '%s' and cp_room = %d and cp_client = '%s' limit 1", + dbesc($observer_xchan), + intval($room_id), + dbesc($client) + ); + if($r) { + q("delete from chatpresence where cp_id = %d", + intval($r[0]['cp_id']) + ); + } + + return true; + } + + + static public function roomlist($uid) { + require_once('include/security.php'); + $sql_extra = permissions_sql($uid); + + $r = q("select allow_cid, allow_gid, deny_cid, deny_gid, cr_name, cr_expire, cr_id, count(cp_id) as cr_inroom from chatroom left join chatpresence on cr_id = cp_room where cr_uid = %d $sql_extra group by cr_name, cr_id order by cr_name", + intval($uid) + ); + + return $r; + } + + static public function list_count($uid) { + require_once('include/security.php'); + $sql_extra = permissions_sql($uid); + + $r = q("select count(*) as total from chatroom where cr_uid = %d $sql_extra", + intval($uid) + ); + + return $r[0]['total']; + } + + /** + * create a chat message via API. + * It is the caller's responsibility to enter the room. + */ + + static public function message($uid, $room_id, $xchan, $text) { + + $ret = array('success' => false); + + if(! $text) + return; + + $sql_extra = permissions_sql($uid); + + $r = q("select * from chatroom where cr_uid = %d and cr_id = %d $sql_extra", + intval($uid), + intval($room_id) + ); + if(! $r) + return $ret; + + $arr = array( + 'chat_room' => $room_id, + 'chat_xchan' => $xchan, + 'chat_text' => $text + ); + + call_hooks('chat_message', $arr); + + $x = q("insert into chat ( chat_room, chat_xchan, created, chat_text ) + values( %d, '%s', '%s', '%s' )", + intval($room_id), + dbesc($xchan), + dbesc(datetime_convert()), + dbesc($arr['chat_text']) + ); + + $ret['success'] = true; + return $ret; + } +} diff --git a/Zotlabs/Lib/Enotify.php b/Zotlabs/Lib/Enotify.php new file mode 100644 index 000000000..ccb538ef5 --- /dev/null +++ b/Zotlabs/Lib/Enotify.php @@ -0,0 +1,685 @@ +<?php + +namespace Zotlabs\Lib; + +/** + * @brief File with functions and a class for generating system and email notifications. + */ + + +class Enotify { + + /** + * @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 + */ + + + static public function submit($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)); + + 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 + + self::send(array( + 'fromName' => $sender_name, + 'fromEmail' => $sender_email, + 'replyTo' => $sender_email, + 'toEmail' => $recip['account_email'], + 'messageSubject' => $datarray['subject'], + 'htmlVersion' => $email_html_body, + 'textVersion' => $email_text_body, + 'additionalMailHeader' => $datarray['headers'], + )); + } + + pop_lang(); + +} + + + /** + * @brief Send a multipart/alternative message with Text and HTML versions. + * + * @param array $params an assoziative array with: + * * \e string \b fromName name of the sender + * * \e string \b fromEmail email of the sender + * * \e string \b replyTo replyTo address to direct responses + * * \e string \b toEmail destination email address + * * \e string \b messageSubject subject of the message + * * \e string \b htmlVersion html version of the message + * * \e string \b textVersion text only version of the message + * * \e string \b additionalMailHeader additions to the smtp mail header + */ + static public function send($params) { + + $fromName = email_header_encode(html_entity_decode($params['fromName'],ENT_QUOTES,'UTF-8'),'UTF-8'); + $messageSubject = email_header_encode(html_entity_decode($params['messageSubject'],ENT_QUOTES,'UTF-8'),'UTF-8'); + + // generate a mime boundary + $mimeBoundary = rand(0, 9) . "-" + .rand(10000000000, 9999999999) . "-" + .rand(10000000000, 9999999999) . "=:" + .rand(10000, 99999); + + // generate a multipart/alternative message header + $messageHeader = + $params['additionalMailHeader'] . + "From: $fromName <{$params['fromEmail']}>\n" . + "Reply-To: $fromName <{$params['replyTo']}>\n" . + "MIME-Version: 1.0\n" . + "Content-Type: multipart/alternative; boundary=\"{$mimeBoundary}\""; + + // assemble the final multipart message body with the text and html types included + $textBody = chunk_split(base64_encode($params['textVersion'])); + $htmlBody = chunk_split(base64_encode($params['htmlVersion'])); + + $multipartMessageBody = + "--" . $mimeBoundary . "\n" . // plain text section + "Content-Type: text/plain; charset=UTF-8\n" . + "Content-Transfer-Encoding: base64\n\n" . + $textBody . "\n" . + "--" . $mimeBoundary . "\n" . // text/html section + "Content-Type: text/html; charset=UTF-8\n" . + "Content-Transfer-Encoding: base64\n\n" . + $htmlBody . "\n" . + "--" . $mimeBoundary . "--\n"; // message ending + + // send the message + $res = mail( + $params['toEmail'], // send to address + $messageSubject, // subject + $multipartMessageBody, // message body + $messageHeader // message headers + ); + logger("notification: enotify::send returns " . $res, LOGGER_DEBUG); + } + + static public function format($item) { + + $ret = ''; + + require_once('include/conversation.php'); + + // Call localize_item with the "brief" flag to get a one line status for activities. + // This should set $item['localized'] to indicate we have a brief summary. + + localize_item($item); + + if($item_localize) { + $itemem_text = $item['localize']; + } + else { + $itemem_text = (($item['item_thread_top']) + ? t('created a new post') + : sprintf( t('commented on %s\'s post'), $item['owner']['xchan_name'])); + } + + // convert this logic into a json array just like the system notifications + + return array( + 'notify_link' => $item['llink'], + 'name' => $item['author']['xchan_name'], + 'url' => $item['author']['xchan_url'], + 'photo' => $item['author']['xchan_photo_s'], + 'when' => relative_date($item['created']), + 'class' => (intval($item['item_unseen']) ? 'notify-unseen' : 'notify-seen'), + 'message' => strip_tags(bbcode($itemem_text)) + ); + + } + +} diff --git a/Zotlabs/Lib/ThreadStream.php b/Zotlabs/Lib/ThreadStream.php index 2bcf167e9..a6d4f8517 100644 --- a/Zotlabs/Lib/ThreadStream.php +++ b/Zotlabs/Lib/ThreadStream.php @@ -165,7 +165,7 @@ class ThreadStream { $item->set_commentable(can_comment_on_post($this->observer['xchan_hash'],$item->data)); } } - require_once('include/identity.php'); + require_once('include/channel.php'); $item->set_conversation($this); $this->threads[] = $item; diff --git a/Zotlabs/Module/Acl.php b/Zotlabs/Module/Acl.php index 5c14ab599..62ac29286 100644 --- a/Zotlabs/Module/Acl.php +++ b/Zotlabs/Module/Acl.php @@ -260,7 +260,7 @@ class Acl extends \Zotlabs\Web\Controller { // logger('navbar_complete'); - if((get_config('system','block_public')) && (! local_channel()) && (! remote_channel())) { + if(observer_prohibited()) { return; } diff --git a/Zotlabs/Module/Admin.php b/Zotlabs/Module/Admin.php index 0a167b273..8f15035d1 100644 --- a/Zotlabs/Module/Admin.php +++ b/Zotlabs/Module/Admin.php @@ -902,7 +902,6 @@ class Admin extends \Zotlabs\Web\Controller { } // account delete button was submitted if (x($_POST, 'page_users_delete')) { - require_once('include/Contact.php'); foreach ($users as $uid){ account_remove($uid, true, false); } @@ -951,7 +950,6 @@ class Admin extends \Zotlabs\Web\Controller { switch (argv(2)){ case 'delete': // delete user - require_once('include/Contact.php'); account_remove($uid,true,false); notice( sprintf(t("Account '%s' deleted"), $account[0]['account_email']) . EOL); @@ -1096,7 +1094,6 @@ class Admin extends \Zotlabs\Web\Controller { notice( sprintf( tt("%s channel code allowed/disallowed", "%s channels code allowed/disallowed", count($channels)), count($channels)) ); } if (x($_POST,'page_channels_delete')){ - require_once("include/Contact.php"); foreach($channels as $uid){ channel_remove($uid,true); } @@ -1128,7 +1125,6 @@ class Admin extends \Zotlabs\Web\Controller { case "delete":{ check_form_security_token_redirectOnErr('/admin/channels', 'admin_channels', 't'); // delete channel - require_once("include/Contact.php"); channel_remove($uid,true); notice( sprintf(t("Channel '%s' deleted"), $channel[0]['channel_name']) . EOL); @@ -1425,13 +1421,15 @@ class Admin extends \Zotlabs\Web\Controller { function listAddonRepos() { $addonrepos = []; $addonDir = __DIR__ . '/../../extend/addon/'; - if ($handle = opendir($addonDir)) { - while (false !== ($entry = readdir($handle))) { - if ($entry != "." && $entry != "..") { - $addonrepos[] = $entry; + if(is_dir($addonDir)) { + if ($handle = opendir($addonDir)) { + while (false !== ($entry = readdir($handle))) { + if ($entry != "." && $entry != "..") { + $addonrepos[] = $entry; + } } + closedir($handle); } - closedir($handle); } return $addonrepos; } @@ -1735,7 +1733,7 @@ class Admin extends \Zotlabs\Web\Controller { } else { json_return_and_die(array('message' => 'No repo name provided.', 'success' => false)); } - $extendDir = __DIR__ . '/../../store/git/sys/extend'; + $extendDir = __DIR__ . '/../../store/[data]/git/sys/extend'; $addonDir = $extendDir . '/addon'; if (!file_exists($extendDir)) { if (!mkdir($extendDir, 0770, true)) { @@ -1748,7 +1746,7 @@ class Admin extends \Zotlabs\Web\Controller { } } } - $repoDir = __DIR__ . '/../../store/git/sys/extend/addon/' . $repoName; + $repoDir = __DIR__ . '/../../store/[data]/git/sys/extend/addon/' . $repoName; if (!is_dir($repoDir)) { logger('Repo directory does not exist: ' . $repoDir); json_return_and_die(array('message' => 'Invalid addon repo.', 'success' => false)); @@ -1785,7 +1783,7 @@ class Admin extends \Zotlabs\Web\Controller { } else { json_return_and_die(array('message' => 'No repo name provided.', 'success' => false)); } - $extendDir = __DIR__ . '/../../store/git/sys/extend'; + $extendDir = __DIR__ . '/../../store/[data]/git/sys/extend'; $addonDir = $extendDir . '/addon'; if (!file_exists($extendDir)) { if (!mkdir($extendDir, 0770, true)) { @@ -1798,7 +1796,7 @@ class Admin extends \Zotlabs\Web\Controller { } } } - $repoDir = __DIR__ . '/../../store/git/sys/extend/addon/' . $repoName; + $repoDir = __DIR__ . '/../../store/[data]/git/sys/extend/addon/' . $repoName; if (!is_dir($repoDir)) { logger('Repo directory does not exist: ' . $repoDir); json_return_and_die(array('message' => 'Invalid addon repo.', 'success' => false)); @@ -1818,7 +1816,7 @@ class Admin extends \Zotlabs\Web\Controller { if (array_key_exists('repoURL', $_REQUEST)) { require __DIR__ . '/../../library/PHPGit.autoload.php'; // Load PHPGit dependencies $repoURL = $_REQUEST['repoURL']; - $extendDir = __DIR__ . '/../../store/git/sys/extend'; + $extendDir = __DIR__ . '/../../store/[data]/git/sys/extend'; $addonDir = $extendDir . '/addon'; if (!file_exists($extendDir)) { if (!mkdir($extendDir, 0770, true)) { @@ -1846,7 +1844,7 @@ class Admin extends \Zotlabs\Web\Controller { json_return_and_die(array('message' => 'Invalid git repo', 'success' => false)); } $repoDir = $addonDir . '/' . $repoName; - $tempRepoBaseDir = __DIR__ . '/../../store/git/sys/temp/'; + $tempRepoBaseDir = __DIR__ . '/../../store/[data]/git/sys/temp/'; $tempAddonDir = $tempRepoBaseDir . $repoName; if (!is_writable($addonDir) || !is_writable($tempAddonDir)) { @@ -1880,9 +1878,9 @@ class Admin extends \Zotlabs\Web\Controller { if (array_key_exists('repoURL', $_REQUEST)) { require __DIR__ . '/../../library/PHPGit.autoload.php'; // Load PHPGit dependencies $repoURL = $_REQUEST['repoURL']; - $extendDir = __DIR__ . '/../../store/git/sys/extend'; + $extendDir = __DIR__ . '/../../store/[data]/git/sys/extend'; $addonDir = $extendDir . '/addon'; - $tempAddonDir = __DIR__ . '/../../store/git/sys/temp'; + $tempAddonDir = __DIR__ . '/../../store/[data]/git/sys/temp'; if (!file_exists($extendDir)) { if (!mkdir($extendDir, 0770, true)) { logger('Error creating extend folder: ' . $extendDir); @@ -1894,6 +1892,12 @@ class Admin extends \Zotlabs\Web\Controller { } } } + if (!is_dir($tempAddonDir)) { + if (!mkdir($tempAddonDir, 0770, true)) { + logger('Error creating temp plugin repo folder: ' . $tempAddonDir); + json_return_and_die(array('message' => 'Error creating temp plugin repo folder: ' . $tempAddonDir, 'success' => false)); + } + } $repoName = null; if (array_key_exists('repoName', $_REQUEST) && $_REQUEST['repoName'] !== '') { $repoName = $_REQUEST['repoName']; diff --git a/Zotlabs/Module/Appman.php b/Zotlabs/Module/Appman.php index ba2a64f35..a200e986a 100644 --- a/Zotlabs/Module/Appman.php +++ b/Zotlabs/Module/Appman.php @@ -2,8 +2,9 @@ namespace Zotlabs\Module; -require_once('include/apps.php'); +//require_once('include/apps.php'); +use \Zotlabs\Lib as Zlib; class Appman extends \Zotlabs\Web\Controller { @@ -30,16 +31,16 @@ class Appman extends \Zotlabs\Web\Controller { 'categories' => escape_tags($_REQUEST['categories']) ); - $_REQUEST['appid'] = app_install(local_channel(),$arr); + $_REQUEST['appid'] = Zlib\Apps::app_install(local_channel(),$arr); - if(app_installed(local_channel(),$arr)) + if(Zlib\Apps::app_installed(local_channel(),$arr)) info( t('App installed.') . EOL); return; } - $papp = app_decode($_POST['papp']); + $papp = Zlib\Apps::app_decode($_POST['papp']); if(! is_array($papp)) { notice( t('Malformed app.') . EOL); @@ -47,13 +48,13 @@ class Appman extends \Zotlabs\Web\Controller { } if($_POST['install']) { - app_install(local_channel(),$papp); - if(app_installed(local_channel(),$papp)) + Zlib\Apps::app_install(local_channel(),$papp); + if(Zlib\Apps::app_installed(local_channel(),$papp)) info( t('App installed.') . EOL); } if($_POST['delete']) { - app_destroy(local_channel(),$papp); + Zlib\Apps::app_destroy(local_channel(),$papp); } if($_POST['edit']) { @@ -100,7 +101,7 @@ class Appman extends \Zotlabs\Web\Controller { } } - $embed = array('embed', t('Embed code'), app_encode($app,true),'', 'onclick="this.select();"'); + $embed = array('embed', t('Embed code'), Zlib\Apps::app_encode($app,true),'', 'onclick="this.select();"'); } diff --git a/Zotlabs/Module/Apps.php b/Zotlabs/Module/Apps.php index 33259b319..4bdec4573 100644 --- a/Zotlabs/Module/Apps.php +++ b/Zotlabs/Module/Apps.php @@ -1,8 +1,9 @@ <?php namespace Zotlabs\Module; -require_once('include/apps.php'); +//require_once('include/apps.php'); +use \Zotlabs\Lib as Zlib; class Apps extends \Zotlabs\Web\Controller { @@ -19,25 +20,25 @@ class Apps extends \Zotlabs\Web\Controller { if(local_channel()) { - import_system_apps(); + Zlib\Apps::import_system_apps(); $syslist = array(); - $list = app_list(local_channel(), false, $_GET['cat']); + $list = Zlib\Apps::app_list(local_channel(), false, $_GET['cat']); if($list) { foreach($list as $x) { - $syslist[] = app_encode($x); + $syslist[] = Zlib\Apps::app_encode($x); } } - translate_system_apps($syslist); + Zlib\Apps::translate_system_apps($syslist); } else - $syslist = get_system_apps(true); + $syslist = Zlib\Apps::get_system_apps(true); - usort($syslist,'app_name_compare'); + usort($syslist,'Zotlabs\\Lib\\Apps::app_name_compare'); // logger('apps: ' . print_r($syslist,true)); foreach($syslist as $app) { - $apps[] = app_render($app,$mode); + $apps[] = Zlib\Apps::app_render($app,$mode); } return replace_macros(get_markup_template('myapps.tpl'), array( diff --git a/Zotlabs/Module/Blocks.php b/Zotlabs/Module/Blocks.php index ed702befb..32650a090 100644 --- a/Zotlabs/Module/Blocks.php +++ b/Zotlabs/Module/Blocks.php @@ -1,7 +1,7 @@ <?php namespace Zotlabs\Module; -require_once('include/identity.php'); +require_once('include/channel.php'); require_once('include/conversation.php'); require_once('include/acl_selectors.php'); diff --git a/Zotlabs/Module/Cal.php b/Zotlabs/Module/Cal.php index 958ce5aa6..a1adb30e5 100644 --- a/Zotlabs/Module/Cal.php +++ b/Zotlabs/Module/Cal.php @@ -6,14 +6,12 @@ require_once('include/bbcode.php'); require_once('include/datetime.php'); require_once('include/event.php'); require_once('include/items.php'); -require_once('include/Contact.php'); - class Cal extends \Zotlabs\Web\Controller { function init() { - if((get_config('system','block_public')) && (! local_channel()) && (! remote_channel())) { + if(observer_prohibited()) { return; } @@ -47,13 +45,12 @@ class Cal extends \Zotlabs\Web\Controller { - function get() { + function get() { - if((get_config('system','block_public')) && (! local_channel()) && (! remote_channel())) { + if(observer_prohibited()) { return; } - - + $channel = null; if(argc() > 1) { diff --git a/Zotlabs/Module/Channel.php b/Zotlabs/Module/Channel.php index f55705442..29bfcbc3c 100644 --- a/Zotlabs/Module/Channel.php +++ b/Zotlabs/Module/Channel.php @@ -13,353 +13,355 @@ require_once('include/PermissionDescription.php'); class Channel extends \Zotlabs\Web\Controller { -function init() { - - $which = null; - if(argc() > 1) - $which = argv(1); - if(! $which) { - if(local_channel()) { - $channel = \App::get_channel(); - if($channel && $channel['channel_address']) - $which = $channel['channel_address']; + function init() { + + $which = null; + if(argc() > 1) + $which = argv(1); + if(! $which) { + if(local_channel()) { + $channel = \App::get_channel(); + if($channel && $channel['channel_address']) + $which = $channel['channel_address']; + } + } + if(! $which) { + notice( t('You must be logged in to see this page.') . EOL ); + return; } - } - if(! $which) { - notice( t('You must be logged in to see this page.') . EOL ); - return; - } - $profile = 0; - $channel = \App::get_channel(); + $profile = 0; + $channel = \App::get_channel(); - if((local_channel()) && (argc() > 2) && (argv(2) === 'view')) { - $which = $channel['channel_address']; - $profile = argv(1); - } + if((local_channel()) && (argc() > 2) && (argv(2) === 'view')) { + $which = $channel['channel_address']; + $profile = argv(1); + } - \App::$page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" title="' . t('Posts and comments') . '" href="' . z_root() . '/feed/' . $which . '" />' . "\r\n" ; - \App::$page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" title="' . t('Only posts') . '" href="' . z_root() . '/feed/' . $which . '?top=1" />' . "\r\n" ; + \App::$page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" title="' . t('Posts and comments') . '" href="' . z_root() . '/feed/' . $which . '" />' . "\r\n" ; + \App::$page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" title="' . t('Only posts') . '" href="' . z_root() . '/feed/' . $which . '?top=1" />' . "\r\n" ; -// Not yet ready for prime time -// \App::$page['htmlhead'] .= '<link rel="openid.server" href="' . z_root() . '/id/' . $which .'?f=" />' . "\r\n" ; -// \App::$page['htmlhead'] .= '<link rel="openid.delegate" href="' . z_root() . '/channel/' . $which .'" />' . "\r\n" ; + // Not yet ready for prime time + // \App::$page['htmlhead'] .= '<link rel="openid.server" href="' . z_root() . '/id/' . $which .'?f=" />' . "\r\n" ; + // \App::$page['htmlhead'] .= '<link rel="openid.delegate" href="' . z_root() . '/channel/' . $which .'" />' . "\r\n" ; - // Run profile_load() here to make sure the theme is set before - // we start loading content + // Run profile_load() here to make sure the theme is set before + // we start loading content - profile_load($a,$which,$profile); + profile_load($a,$which,$profile); -} + } -function get($update = 0, $load = false) { + function get($update = 0, $load = false) { - if($load) - $_SESSION['loadtime'] = datetime_convert(); + if($load) + $_SESSION['loadtime'] = datetime_convert(); - $checkjs = new \Zotlabs\Web\CheckJS(1); + $checkjs = new \Zotlabs\Web\CheckJS(1); - $category = $datequery = $datequery2 = ''; + $category = $datequery = $datequery2 = ''; - $mid = ((x($_REQUEST,'mid')) ? $_REQUEST['mid'] : ''); + $mid = ((x($_REQUEST,'mid')) ? $_REQUEST['mid'] : ''); - $datequery = ((x($_GET,'dend') && is_a_date_arg($_GET['dend'])) ? notags($_GET['dend']) : ''); - $datequery2 = ((x($_GET,'dbegin') && is_a_date_arg($_GET['dbegin'])) ? notags($_GET['dbegin']) : ''); + $datequery = ((x($_GET,'dend') && is_a_date_arg($_GET['dend'])) ? notags($_GET['dend']) : ''); + $datequery2 = ((x($_GET,'dbegin') && is_a_date_arg($_GET['dbegin'])) ? notags($_GET['dbegin']) : ''); - if(get_config('system','block_public') && (! get_account_id()) && (! remote_channel())) { + if(observer_prohibited(true)) { return login(); - } + } - $category = ((x($_REQUEST,'cat')) ? $_REQUEST['cat'] : ''); - $hashtags = ((x($_REQUEST,'tag')) ? $_REQUEST['tag'] : ''); + $category = ((x($_REQUEST,'cat')) ? $_REQUEST['cat'] : ''); + $hashtags = ((x($_REQUEST,'tag')) ? $_REQUEST['tag'] : ''); - $groups = array(); + $groups = array(); - $o = ''; + $o = ''; - if($update) { - // Ensure we've got a profile owner if updating. - \App::$profile['profile_uid'] = \App::$profile_uid = $update; - } - else { - if(\App::$profile['profile_uid'] == local_channel()) { - nav_set_selected('home'); + if($update) { + // Ensure we've got a profile owner if updating. + \App::$profile['profile_uid'] = \App::$profile_uid = $update; + } + else { + if(\App::$profile['profile_uid'] == local_channel()) { + nav_set_selected('home'); + } } - } - $is_owner = (((local_channel()) && (\App::$profile['profile_uid'] == local_channel())) ? true : false); + $is_owner = (((local_channel()) && (\App::$profile['profile_uid'] == local_channel())) ? true : false); - $channel = \App::get_channel(); - $observer = \App::get_observer(); - $ob_hash = (($observer) ? $observer['xchan_hash'] : ''); + $channel = \App::get_channel(); + $observer = \App::get_observer(); + $ob_hash = (($observer) ? $observer['xchan_hash'] : ''); - $perms = get_all_perms(\App::$profile['profile_uid'],$ob_hash); + $perms = get_all_perms(\App::$profile['profile_uid'],$ob_hash); - if(! $perms['view_stream']) { + if(! $perms['view_stream']) { // We may want to make the target of this redirect configurable if($perms['view_profile']) { notice( t('Insufficient permissions. Request redirected to profile page.') . EOL); goaway (z_root() . "/profile/" . \App::$profile['channel_address']); } - notice( t('Permission denied.') . EOL); - return; - } + notice( t('Permission denied.') . EOL); + return; + } - if(! $update) { + if(! $update) { - $o .= profile_tabs($a, $is_owner, \App::$profile['channel_address']); + $o .= profile_tabs($a, $is_owner, \App::$profile['channel_address']); - $o .= common_friends_visitor_widget(\App::$profile['profile_uid']); + $o .= common_friends_visitor_widget(\App::$profile['profile_uid']); - if($channel && $is_owner) { - $channel_acl = array( - 'allow_cid' => $channel['channel_allow_cid'], - 'allow_gid' => $channel['channel_allow_gid'], - 'deny_cid' => $channel['channel_deny_cid'], - 'deny_gid' => $channel['channel_deny_gid'] - ); - } - else - $channel_acl = array(); - - - if($perms['post_wall']) { - - $x = array( - 'is_owner' => $is_owner, - 'allow_location' => ((($is_owner || $observer) && (intval(get_pconfig(\App::$profile['profile_uid'],'system','use_browser_location')))) ? true : false), - 'default_location' => (($is_owner) ? \App::$profile['channel_location'] : ''), - 'nickname' => \App::$profile['channel_address'], - 'lockstate' => (((strlen(\App::$profile['channel_allow_cid'])) || (strlen(\App::$profile['channel_allow_gid'])) || (strlen(\App::$profile['channel_deny_cid'])) || (strlen(\App::$profile['channel_deny_gid']))) ? 'lock' : 'unlock'), - 'acl' => (($is_owner) ? populate_acl($channel_acl,true, \PermissionDescription::fromGlobalPermission('view_stream'), get_post_aclDialogDescription(), 'acl_dialog_post') : ''), - 'showacl' => (($is_owner) ? 'yes' : ''), - 'bang' => '', - 'visitor' => (($is_owner || $observer) ? true : false), - 'profile_uid' => \App::$profile['profile_uid'], - 'editor_autocomplete' => true, - 'bbco_autocomplete' => 'bbcode', - 'bbcode' => true - ); - - $o .= status_editor($a,$x); - } + if($channel && $is_owner) { + $channel_acl = array( + 'allow_cid' => $channel['channel_allow_cid'], + 'allow_gid' => $channel['channel_allow_gid'], + 'deny_cid' => $channel['channel_deny_cid'], + 'deny_gid' => $channel['channel_deny_gid'] + ); + } + else + $channel_acl = array(); + + + if($perms['post_wall']) { + + $x = array( + 'is_owner' => $is_owner, + 'allow_location' => ((($is_owner || $observer) && (intval(get_pconfig(\App::$profile['profile_uid'],'system','use_browser_location')))) ? true : false), + 'default_location' => (($is_owner) ? \App::$profile['channel_location'] : ''), + 'nickname' => \App::$profile['channel_address'], + 'lockstate' => (((strlen(\App::$profile['channel_allow_cid'])) || (strlen(\App::$profile['channel_allow_gid'])) || (strlen(\App::$profile['channel_deny_cid'])) || (strlen(\App::$profile['channel_deny_gid']))) ? 'lock' : 'unlock'), + 'acl' => (($is_owner) ? populate_acl($channel_acl,true, \PermissionDescription::fromGlobalPermission('view_stream'), get_post_aclDialogDescription(), 'acl_dialog_post') : ''), + 'showacl' => (($is_owner) ? 'yes' : ''), + 'bang' => '', + 'visitor' => (($is_owner || $observer) ? true : false), + 'profile_uid' => \App::$profile['profile_uid'], + 'editor_autocomplete' => true, + 'bbco_autocomplete' => 'bbcode', + 'bbcode' => true + ); + + $o .= status_editor($a,$x); + } - } + } - /** - * Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups - */ + /** + * Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups + */ - $item_normal = item_normal(); - $sql_extra = item_permissions_sql(\App::$profile['profile_uid']); + $item_normal = item_normal(); + $sql_extra = item_permissions_sql(\App::$profile['profile_uid']); - if(get_pconfig(\App::$profile['profile_uid'],'system','channel_list_mode') && (! $mid)) - $page_mode = 'list'; - else - $page_mode = 'client'; + if(get_pconfig(\App::$profile['profile_uid'],'system','channel_list_mode') && (! $mid)) + $page_mode = 'list'; + else + $page_mode = 'client'; - $abook_uids = " and abook.abook_channel = " . intval(\App::$profile['profile_uid']) . " "; + $abook_uids = " and abook.abook_channel = " . intval(\App::$profile['profile_uid']) . " "; - $simple_update = (($update) ? " AND item_unseen = 1 " : ''); + $simple_update = (($update) ? " AND item_unseen = 1 " : ''); - \App::$page['htmlhead'] .= "\r\n" . '<link rel="alternate" type="application/json+oembed" href="' . z_root() . '/oep?f=&url=' . urlencode(z_root() . '/' . \App::$query_string) . '" title="oembed" />' . "\r\n"; + \App::$page['htmlhead'] .= "\r\n" . '<link rel="alternate" type="application/json+oembed" href="' . z_root() . '/oep?f=&url=' . urlencode(z_root() . '/' . \App::$query_string) . '" title="oembed" />' . "\r\n"; - if($update && $_SESSION['loadtime']) - $simple_update = " AND (( item_unseen = 1 AND item.changed > '" . datetime_convert('UTC','UTC',$_SESSION['loadtime']) . "' ) OR item.changed > '" . datetime_convert('UTC','UTC',$_SESSION['loadtime']) . "' ) "; - if($load) - $simple_update = ''; - - if(($update) && (! $load)) { - - if ($mid) { - $r = q("SELECT parent AS item_id from item where mid like '%s' and uid = %d $item_normal - AND item_wall = 1 AND item_unseen = 1 $sql_extra limit 1", - dbesc($mid . '%'), - intval(\App::$profile['profile_uid']) - ); - } else { - $r = q("SELECT distinct parent AS `item_id`, created from item - left join abook on ( item.owner_xchan = abook.abook_xchan $abook_uids ) - WHERE uid = %d $item_normal - AND item_wall = 1 $simple_update - AND (abook.abook_blocked = 0 or abook.abook_flags is null) - $sql_extra - ORDER BY created DESC", - intval(\App::$profile['profile_uid']) - ); - $_SESSION['loadtime'] = datetime_convert(); - } - - } - else { - - if(x($category)) { - $sql_extra .= protect_sprintf(term_query('item', $category, TERM_CATEGORY)); - } - if(x($hashtags)) { - $sql_extra .= protect_sprintf(term_query('item', $hashtags, TERM_HASHTAG, TERM_COMMUNITYTAG)); - } - - if($datequery) { - $sql_extra2 .= protect_sprintf(sprintf(" AND item.created <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery)))); - } - if($datequery2) { - $sql_extra2 .= protect_sprintf(sprintf(" AND item.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery2)))); - } + if($update && $_SESSION['loadtime']) + $simple_update = " AND (( item_unseen = 1 AND item.changed > '" . datetime_convert('UTC','UTC',$_SESSION['loadtime']) . "' ) OR item.changed > '" . datetime_convert('UTC','UTC',$_SESSION['loadtime']) . "' ) "; + if($load) + $simple_update = ''; - $itemspage = get_pconfig(local_channel(),'system','itemspage'); - \App::set_pager_itemspage(((intval($itemspage)) ? $itemspage : 20)); - $pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval(\App::$pager['itemspage']), intval(\App::$pager['start'])); + if(($update) && (! $load)) { - if($load || ($checkjs->disabled())) { - if ($mid) { - $r = q("SELECT parent AS item_id from item where mid = '%s' and uid = %d $item_normal - AND item_wall = 1 $sql_extra limit 1", - dbesc($mid), + if($mid) { + $r = q("SELECT parent AS item_id from item where mid like '%s' and uid = %d $item_normal + AND item_wall = 1 AND item_unseen = 1 $sql_extra limit 1", + dbesc($mid . '%'), intval(\App::$profile['profile_uid']) ); - if (! $r) { - notice( t('Permission denied.') . EOL); - } - - } else { - $r = q("SELECT distinct id AS item_id, created FROM item - left join abook on item.author_xchan = abook.abook_xchan + } + else { + $r = q("SELECT distinct parent AS `item_id`, created from item + left join abook on ( item.owner_xchan = abook.abook_xchan $abook_uids ) WHERE uid = %d $item_normal - AND item_wall = 1 and item_thread_top = 1 - AND (abook_blocked = 0 or abook.abook_flags is null) - $sql_extra $sql_extra2 - ORDER BY created DESC $pager_sql ", + AND item_wall = 1 $simple_update + AND (abook.abook_blocked = 0 or abook.abook_flags is null) + $sql_extra + ORDER BY created DESC", intval(\App::$profile['profile_uid']) ); + $_SESSION['loadtime'] = datetime_convert(); } + } else { - $r = array(); - } - } - if($r) { + if(x($category)) { + $sql_extra .= protect_sprintf(term_query('item', $category, TERM_CATEGORY)); + } + if(x($hashtags)) { + $sql_extra .= protect_sprintf(term_query('item', $hashtags, TERM_HASHTAG, TERM_COMMUNITYTAG)); + } - $parents_str = ids_to_querystr($r,'item_id'); - - $items = q("SELECT `item`.*, `item`.`id` AS `item_id` - FROM `item` - WHERE `item`.`uid` = %d $item_normal - AND `item`.`parent` IN ( %s ) - $sql_extra ", - intval(\App::$profile['profile_uid']), - dbesc($parents_str) - ); - - xchan_query($items); - $items = fetch_post_tags($items, true); - $items = conv_sort($items,'created'); - - if ($load && $mid && (! count($items))) { - // This will happen if we don't have sufficient permissions - // to view the parent item (or the item itself if it is toplevel) - notice( t('Permission denied.') . EOL); + if($datequery) { + $sql_extra2 .= protect_sprintf(sprintf(" AND item.created <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery)))); + } + if($datequery2) { + $sql_extra2 .= protect_sprintf(sprintf(" AND item.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery2)))); + } + + $itemspage = get_pconfig(local_channel(),'system','itemspage'); + \App::set_pager_itemspage(((intval($itemspage)) ? $itemspage : 20)); + $pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval(\App::$pager['itemspage']), intval(\App::$pager['start'])); + + if($load || ($checkjs->disabled())) { + if($mid) { + $r = q("SELECT parent AS item_id from item where mid = '%s' and uid = %d $item_normal + AND item_wall = 1 $sql_extra limit 1", + dbesc($mid), + intval(\App::$profile['profile_uid']) + ); + if (! $r) { + notice( t('Permission denied.') . EOL); + } + + } + else { + $r = q("SELECT distinct id AS item_id, created FROM item + left join abook on item.author_xchan = abook.abook_xchan + WHERE uid = %d $item_normal + AND item_wall = 1 and item_thread_top = 1 + AND (abook_blocked = 0 or abook.abook_flags is null) + $sql_extra $sql_extra2 + ORDER BY created DESC $pager_sql ", + intval(\App::$profile['profile_uid']) + ); + } + } + else { + $r = array(); + } } - } else { - $items = array(); - } + if($r) { - if((! $update) && (! $load)) { - - // This is ugly, but we can't pass the profile_uid through the session to the ajax updater, - // because browser prefetching might change it on us. We have to deliver it with the page. - - $maxheight = get_pconfig(\App::$profile['profile_uid'],'system','channel_divmore_height'); - if(! $maxheight) - $maxheight = 400; - - $o .= '<div id="live-channel"></div>' . "\r\n"; - $o .= "<script> var profile_uid = " . \App::$profile['profile_uid'] - . "; var netargs = '?f='; var profile_page = " . \App::$pager['page'] - . "; divmore_height = " . intval($maxheight) . "; </script>\r\n"; - - \App::$page['htmlhead'] .= replace_macros(get_markup_template("build_query.tpl"),array( - '$baseurl' => z_root(), - '$pgtype' => 'channel', - '$uid' => ((\App::$profile['profile_uid']) ? \App::$profile['profile_uid'] : '0'), - '$gid' => '0', - '$cid' => '0', - '$cmin' => '0', - '$cmax' => '0', - '$star' => '0', - '$liked' => '0', - '$conv' => '0', - '$spam' => '0', - '$nouveau' => '0', - '$wall' => '1', - '$fh' => '0', - '$page' => ((\App::$pager['page'] != 1) ? \App::$pager['page'] : 1), - '$search' => '', - '$order' => '', - '$list' => ((x($_REQUEST,'list')) ? intval($_REQUEST['list']) : 0), - '$file' => '', - '$cats' => (($category) ? $category : ''), - '$tags' => (($hashtags) ? $hashtags : ''), - '$mid' => $mid, - '$verb' => '', - '$dend' => $datequery, - '$dbegin' => $datequery2 - )); + $parents_str = ids_to_querystr($r,'item_id'); + + $items = q("SELECT `item`.*, `item`.`id` AS `item_id` + FROM `item` + WHERE `item`.`uid` = %d $item_normal + AND `item`.`parent` IN ( %s ) + $sql_extra ", + intval(\App::$profile['profile_uid']), + dbesc($parents_str) + ); + xchan_query($items); + $items = fetch_post_tags($items, true); + $items = conv_sort($items,'created'); - } + if($load && $mid && (! count($items))) { + // This will happen if we don't have sufficient permissions + // to view the parent item (or the item itself if it is toplevel) + notice( t('Permission denied.') . EOL); + } - $update_unseen = ''; + } + else { + $items = array(); + } - if($page_mode === 'list') { + if((! $update) && (! $load)) { + + // This is ugly, but we can't pass the profile_uid through the session to the ajax updater, + // because browser prefetching might change it on us. We have to deliver it with the page. + + $maxheight = get_pconfig(\App::$profile['profile_uid'],'system','channel_divmore_height'); + if(! $maxheight) + $maxheight = 400; + + $o .= '<div id="live-channel"></div>' . "\r\n"; + $o .= "<script> var profile_uid = " . \App::$profile['profile_uid'] + . "; var netargs = '?f='; var profile_page = " . \App::$pager['page'] + . "; divmore_height = " . intval($maxheight) . "; </script>\r\n"; + + \App::$page['htmlhead'] .= replace_macros(get_markup_template("build_query.tpl"),array( + '$baseurl' => z_root(), + '$pgtype' => 'channel', + '$uid' => ((\App::$profile['profile_uid']) ? \App::$profile['profile_uid'] : '0'), + '$gid' => '0', + '$cid' => '0', + '$cmin' => '0', + '$cmax' => '0', + '$star' => '0', + '$liked' => '0', + '$conv' => '0', + '$spam' => '0', + '$nouveau' => '0', + '$wall' => '1', + '$fh' => '0', + '$page' => ((\App::$pager['page'] != 1) ? \App::$pager['page'] : 1), + '$search' => '', + '$order' => '', + '$list' => ((x($_REQUEST,'list')) ? intval($_REQUEST['list']) : 0), + '$file' => '', + '$cats' => (($category) ? $category : ''), + '$tags' => (($hashtags) ? $hashtags : ''), + '$mid' => $mid, + '$verb' => '', + '$dend' => $datequery, + '$dbegin' => $datequery2 + )); - /** - * in "list mode", only mark the parent item and any like activities as "seen". - * We won't distinguish between comment likes and post likes. The important thing - * is that the number of unseen comments will be accurate. The SQL to separate the - * comment likes could also get somewhat hairy. - */ - if($parents_str) { - $update_unseen = " AND ( id IN ( " . dbesc($parents_str) . " )"; - $update_unseen .= " OR ( parent IN ( " . dbesc($parents_str) . " ) AND verb in ( '" . dbesc(ACTIVITY_LIKE) . "','" . dbesc(ACTIVITY_DISLIKE) . "' ))) "; - } - } - else { - if($parents_str) { - $update_unseen = " AND parent IN ( " . dbesc($parents_str) . " )"; } - } - if($is_owner && $update_unseen) { - $r = q("UPDATE item SET item_unseen = 0 where item_unseen = 1 and item_wall = 1 AND uid = %d $update_unseen", - intval(local_channel()) - ); - } + $update_unseen = ''; + if($page_mode === 'list') { - if($checkjs->disabled()) { - $o .= conversation($a,$items,'channel',$update,'traditional'); - } else { - $o .= conversation($a,$items,'channel',$update,$page_mode); - } + /** + * in "list mode", only mark the parent item and any like activities as "seen". + * We won't distinguish between comment likes and post likes. The important thing + * is that the number of unseen comments will be accurate. The SQL to separate the + * comment likes could also get somewhat hairy. + */ - if((! $update) || ($checkjs->disabled())) { - $o .= alt_pager($a,count($items)); - if ($mid && $items[0]['title']) - \App::$page['title'] = $items[0]['title'] . " - " . \App::$page['title']; - } + if($parents_str) { + $update_unseen = " AND ( id IN ( " . dbesc($parents_str) . " )"; + $update_unseen .= " OR ( parent IN ( " . dbesc($parents_str) . " ) AND verb in ( '" . dbesc(ACTIVITY_LIKE) . "','" . dbesc(ACTIVITY_DISLIKE) . "' ))) "; + } + } + else { + if($parents_str) { + $update_unseen = " AND parent IN ( " . dbesc($parents_str) . " )"; + } + } + + if($is_owner && $update_unseen) { + $r = q("UPDATE item SET item_unseen = 0 where item_unseen = 1 and item_wall = 1 AND uid = %d $update_unseen", + intval(local_channel()) + ); + } - if($mid) - $o .= '<div id="content-complete"></div>'; - return $o; -} + if($checkjs->disabled()) { + $o .= conversation($a,$items,'channel',$update,'traditional'); + } + else { + $o .= conversation($a,$items,'channel',$update,$page_mode); + } + if((! $update) || ($checkjs->disabled())) { + $o .= alt_pager($a,count($items)); + if ($mid && $items[0]['title']) + \App::$page['title'] = $items[0]['title'] . " - " . \App::$page['title']; + } + if($mid) + $o .= '<div id="content-complete"></div>'; + + return $o; + } }
\ No newline at end of file diff --git a/Zotlabs/Module/Chanview.php b/Zotlabs/Module/Chanview.php index f70444816..c6dd07eb7 100644 --- a/Zotlabs/Module/Chanview.php +++ b/Zotlabs/Module/Chanview.php @@ -1,10 +1,8 @@ <?php namespace Zotlabs\Module; -require_once('include/Contact.php'); require_once('include/zot.php'); - class Chanview extends \Zotlabs\Web\Controller { function get() { @@ -62,18 +60,15 @@ class Chanview extends \Zotlabs\Web\Controller { } if($_REQUEST['address']) { - $ret = zot_finger($_REQUEST['address'],null); - if($ret['success']) { - $j = json_decode($ret['body'],true); - if($j) - import_xchan($j); + $j = \Zotlabs\Zot\Finger::run($_REQUEST['address'],null); + if($j['success']) { + import_xchan($j); $r = q("select * from xchan where xchan_addr = '%s' limit 1", dbesc($_REQUEST['address']) ); if($r) \App::$poi = $r[0]; } - } } diff --git a/Zotlabs/Module/Chat.php b/Zotlabs/Module/Chat.php index 9508ed3de..d14c32b7d 100644 --- a/Zotlabs/Module/Chat.php +++ b/Zotlabs/Module/Chat.php @@ -1,9 +1,11 @@ -<?php -namespace Zotlabs\Module; /** @file */ +<?php /** @file */ + +namespace Zotlabs\Module; + -require_once('include/chat.php'); require_once('include/bookmarks.php'); +use \Zotlabs\Lib as Zlib; class Chat extends \Zotlabs\Web\Controller { @@ -41,7 +43,7 @@ class Chat extends \Zotlabs\Web\Controller { } - function post() { + function post() { if($_POST['room_name']) $room = strip_tags(trim($_POST['room_name'])); @@ -54,7 +56,7 @@ class Chat extends \Zotlabs\Web\Controller { if($_POST['action'] === 'drop') { logger('delete chatroom'); - chatroom_destroy($channel,array('cr_name' => $room)); + Zlib\Chatroom::destroy($channel,array('cr_name' => $room)); goaway(z_root() . '/chat/' . $channel['channel_address']); } @@ -67,7 +69,7 @@ class Chat extends \Zotlabs\Web\Controller { if(intval($arr['expire']) < 0) $arr['expire'] = 0; - chatroom_create($channel,$arr); + Zlib\Chatroom::create($channel,$arr); $x = q("select * from chatroom where cr_name = '%s' and cr_uid = %d limit 1", dbesc($room), @@ -87,7 +89,7 @@ class Chat extends \Zotlabs\Web\Controller { } - function get() { + function get() { if(local_channel()) $channel = \App::get_channel(); @@ -105,7 +107,7 @@ class Chat extends \Zotlabs\Web\Controller { } if((argc() > 3) && intval(argv(2)) && (argv(3) === 'leave')) { - chatroom_leave($observer,argv(2),$_SERVER['REMOTE_ADDR']); + Zlib\Chatroom::leave($observer,argv(2),$_SERVER['REMOTE_ADDR']); goaway(z_root() . '/channel/' . argv(1)); } @@ -158,7 +160,7 @@ class Chat extends \Zotlabs\Web\Controller { $room_id = intval(argv(2)); $bookmark_link = get_bookmark_link($ob); - $x = chatroom_enter($observer,$room_id,'online',$_SERVER['REMOTE_ADDR']); + $x = Zlib\Chatroom::enter($observer,$room_id,'online',$_SERVER['REMOTE_ADDR']); if(! $x) return; $x = q("select * from chatroom where cr_id = %d and cr_uid = %d $sql_extra limit 1", @@ -238,7 +240,7 @@ class Chat extends \Zotlabs\Web\Controller { )); } - $rooms = chatroom_list(\App::$profile['profile_uid']); + $rooms = Zlib\Chatroom::roomlist(\App::$profile['profile_uid']); $o .= replace_macros(get_markup_template('chatrooms.tpl'), array( '$header' => sprintf( t('%1$s\'s Chatrooms'), \App::$profile['name']), diff --git a/Zotlabs/Module/Chatsvc.php b/Zotlabs/Module/Chatsvc.php index a9bc97301..6a28a7c4d 100644 --- a/Zotlabs/Module/Chatsvc.php +++ b/Zotlabs/Module/Chatsvc.php @@ -1,14 +1,16 @@ -<?php -namespace Zotlabs\Module; /** @file */ +<?php /** @file */ + +namespace Zotlabs\Module; require_once('include/security.php'); +use \Zotlabs\Lib as Zlib; class Chatsvc extends \Zotlabs\Web\Controller { function init() { - //logger('chatsvc'); + //logger('chatsvc'); $ret = array('success' => false); @@ -27,7 +29,7 @@ class Chatsvc extends \Zotlabs\Web\Controller { } - function post() { + function post() { $ret = array('success' => false); @@ -65,7 +67,7 @@ class Chatsvc extends \Zotlabs\Web\Controller { json_return_and_die($ret); } - function get() { + function get() { $status = strip_tags($_REQUEST['status']); $room_id = intval(\App::$data['chat']['room_id']); diff --git a/Zotlabs/Module/Cloud.php b/Zotlabs/Module/Cloud.php index d9b0c47d4..b691475ce 100644 --- a/Zotlabs/Module/Cloud.php +++ b/Zotlabs/Module/Cloud.php @@ -100,9 +100,12 @@ class Cloud extends \Zotlabs\Web\Controller { // require_once('\Zotlabs\Storage/QuotaPlugin.php'); // $server->addPlugin(new \Zotlabs\Storage\\QuotaPlugin($auth)); + ob_start(); // All we need to do now, is to fire up the server $server->exec(); + ob_end_flush(); + killme(); } diff --git a/Zotlabs/Module/Connect.php b/Zotlabs/Module/Connect.php index 382abf370..f68e0baac 100644 --- a/Zotlabs/Module/Connect.php +++ b/Zotlabs/Module/Connect.php @@ -2,7 +2,7 @@ namespace Zotlabs\Module; /** @file */ -require_once('include/Contact.php'); + require_once('include/contact_widgets.php'); require_once('include/items.php'); diff --git a/Zotlabs/Module/Connections.php b/Zotlabs/Module/Connections.php index ebf8ff8e6..a412d16ae 100644 --- a/Zotlabs/Module/Connections.php +++ b/Zotlabs/Module/Connections.php @@ -1,7 +1,7 @@ <?php namespace Zotlabs\Module; -require_once('include/Contact.php'); + require_once('include/socgraph.php'); require_once('include/selectors.php'); require_once('include/group.php'); diff --git a/Zotlabs/Module/Connedit.php b/Zotlabs/Module/Connedit.php index 8bf4ac9b4..c5c38b96a 100644 --- a/Zotlabs/Module/Connedit.php +++ b/Zotlabs/Module/Connedit.php @@ -7,7 +7,7 @@ namespace Zotlabs\Module; * */ -require_once('include/Contact.php'); + require_once('include/socgraph.php'); require_once('include/selectors.php'); require_once('include/group.php'); @@ -230,7 +230,7 @@ class Connedit extends \Zotlabs\Web\Controller { if(\App::$poi && \App::$poi['abook_my_perms'] != $abook_my_perms && (! intval(\App::$poi['abook_self']))) { - \Zotlabs\Daemon\Master(array('Notifier', (($new_friend) ? 'permission_create' : 'permission_update'), $contact_id)); + \Zotlabs\Daemon\Master::Summon(array('Notifier', (($new_friend) ? 'permission_create' : 'permission_update'), $contact_id)); } if($new_friend) { @@ -485,7 +485,6 @@ class Connedit extends \Zotlabs\Web\Controller { if($cmd === 'drop') { - require_once('include/Contact.php'); // FIXME // We need to send either a purge or a refresh packet to the other side (the channel being unfriended). diff --git a/Zotlabs/Module/Cover_photo.php b/Zotlabs/Module/Cover_photo.php index aafc1bdb0..2e53696ff 100644 --- a/Zotlabs/Module/Cover_photo.php +++ b/Zotlabs/Module/Cover_photo.php @@ -8,7 +8,7 @@ namespace Zotlabs\Module; */ require_once('include/photo/photo_driver.php'); -require_once('include/identity.php'); +require_once('include/channel.php'); diff --git a/Zotlabs/Module/Directory.php b/Zotlabs/Module/Directory.php index b8bac53bb..560038ffc 100644 --- a/Zotlabs/Module/Directory.php +++ b/Zotlabs/Module/Directory.php @@ -57,9 +57,9 @@ class Directory extends \Zotlabs\Web\Controller { } } - function get() { + function get() { - if((get_config('system','block_public')) && (! local_channel()) && (! remote_channel())) { + if(observer_prohibited()) { notice( t('Public access denied.') . EOL); return; } diff --git a/Zotlabs/Module/Display.php b/Zotlabs/Module/Display.php index 2a5a04a2a..c1a0d84bc 100644 --- a/Zotlabs/Module/Display.php +++ b/Zotlabs/Module/Display.php @@ -7,17 +7,13 @@ class Display extends \Zotlabs\Web\Controller { function get($update = 0, $load = false) { - // logger("mod-display: update = $update load = $load"); - - $checkjs = new \Zotlabs\Web\CheckJS(1); - if($load) $_SESSION['loadtime'] = datetime_convert(); - if(intval(get_config('system','block_public')) && (! local_channel()) && (! remote_channel())) { + if(observer_prohibited()) { notice( t('Public access denied.') . EOL); return; } @@ -185,7 +181,7 @@ class Display extends \Zotlabs\Web\Controller { if($load || ($checkjs->disabled())) { $r = null; - require_once('include/identity.php'); + require_once('include/channel.php'); $sys = get_sys_channel(); $sysid = $sys['channel_id']; @@ -233,7 +229,7 @@ class Display extends \Zotlabs\Web\Controller { elseif($update && !$load) { $r = null; - require_once('include/identity.php'); + require_once('include/channel.php'); $sys = get_sys_channel(); $sysid = $sys['channel_id']; diff --git a/Zotlabs/Module/Editblock.php b/Zotlabs/Module/Editblock.php index a79962033..fb86557f2 100644 --- a/Zotlabs/Module/Editblock.php +++ b/Zotlabs/Module/Editblock.php @@ -1,7 +1,7 @@ <?php namespace Zotlabs\Module; -require_once('include/identity.php'); +require_once('include/channel.php'); require_once('include/acl_selectors.php'); require_once('include/conversation.php'); diff --git a/Zotlabs/Module/Editlayout.php b/Zotlabs/Module/Editlayout.php index c5b50235a..5028882d2 100644 --- a/Zotlabs/Module/Editlayout.php +++ b/Zotlabs/Module/Editlayout.php @@ -1,7 +1,7 @@ <?php namespace Zotlabs\Module; -require_once('include/identity.php'); +require_once('include/channel.php'); require_once('include/acl_selectors.php'); require_once('include/conversation.php'); diff --git a/Zotlabs/Module/Editwebpage.php b/Zotlabs/Module/Editwebpage.php index c2346c53b..1b5c320a0 100644 --- a/Zotlabs/Module/Editwebpage.php +++ b/Zotlabs/Module/Editwebpage.php @@ -1,7 +1,7 @@ <?php namespace Zotlabs\Module; -require_once('include/identity.php'); +require_once('include/channel.php'); require_once('include/acl_selectors.php'); require_once('include/conversation.php'); require_once('include/PermissionDescription.php'); diff --git a/Zotlabs/Module/Events.php b/Zotlabs/Module/Events.php index 3440e0727..2b5e239f9 100644 --- a/Zotlabs/Module/Events.php +++ b/Zotlabs/Module/Events.php @@ -232,7 +232,7 @@ class Events extends \Zotlabs\Web\Controller { } if($share) - \Zotlabs\Daemon\Master(array('Notifier','event',$item_id)); + \Zotlabs\Daemon\Master::Summon(array('Notifier','event',$item_id)); } diff --git a/Zotlabs/Module/Feed.php b/Zotlabs/Module/Feed.php index 9d33ba2c3..47871eafb 100644 --- a/Zotlabs/Module/Feed.php +++ b/Zotlabs/Module/Feed.php @@ -31,7 +31,7 @@ class Feed extends \Zotlabs\Web\Controller { $channel = $r[0]; - if((intval(get_config('system','block_public'))) && (! get_account_id())) + if(observer_prohibited(true)) killme(); logger('mod_feed: public feed request from ' . $_SERVER['REMOTE_ADDR'] . ' for ' . $channel['channel_address']); diff --git a/Zotlabs/Module/Getfile.php b/Zotlabs/Module/Getfile.php index 6999e77e8..09d761887 100644 --- a/Zotlabs/Module/Getfile.php +++ b/Zotlabs/Module/Getfile.php @@ -21,7 +21,6 @@ namespace Zotlabs\Module; -require_once('include/Contact.php'); require_once('include/attach.php'); diff --git a/Zotlabs/Module/Import.php b/Zotlabs/Module/Import.php index 4e99155fb..57ced22a3 100644 --- a/Zotlabs/Module/Import.php +++ b/Zotlabs/Module/Import.php @@ -4,9 +4,9 @@ namespace Zotlabs\Module; // Import a channel, either by direct file upload or via // connection to original server. -require_once('include/Contact.php'); + require_once('include/zot.php'); -require_once('include/identity.php'); +require_once('include/channel.php'); require_once('include/import.php'); diff --git a/Zotlabs/Module/Item.php b/Zotlabs/Module/Item.php index ff8510ade..041939ad8 100644 --- a/Zotlabs/Module/Item.php +++ b/Zotlabs/Module/Item.php @@ -17,10 +17,10 @@ namespace Zotlabs\Module; */ require_once('include/crypto.php'); -require_once('include/enotify.php'); require_once('include/items.php'); require_once('include/attach.php'); +use \Zotlabs\Lib as Zlib; class Item extends \Zotlabs\Web\Controller { @@ -56,7 +56,7 @@ class Item extends \Zotlabs\Web\Controller { $remote_xchan = $remote_observer = false; $profile_uid = ((x($_REQUEST,'profile_uid')) ? intval($_REQUEST['profile_uid']) : 0); - require_once('include/identity.php'); + require_once('include/channel.php'); $sys = get_sys_channel(); if($sys && $profile_uid && ($sys['channel_id'] == $profile_uid) && is_site_admin()) { $uid = intval($sys['channel_id']); @@ -925,7 +925,7 @@ class Item extends \Zotlabs\Web\Controller { // otherwise it will happen during delivery if(($datarray['owner_xchan'] != $datarray['author_xchan']) && (intval($parent_item['item_wall']))) { - notification(array( + Zlib\Enotify::submit(array( 'type' => NOTIFY_COMMENT, 'from_xchan' => $datarray['author_xchan'], 'to_xchan' => $datarray['owner_xchan'], @@ -943,7 +943,7 @@ class Item extends \Zotlabs\Web\Controller { $parent = $post_id; if(($datarray['owner_xchan'] != $datarray['author_xchan']) && ($datarray['item_type'] == ITEM_TYPE_POST)) { - notification(array( + Zlib\Enotify::submit(array( 'type' => NOTIFY_WALL, 'from_xchan' => $datarray['author_xchan'], 'to_xchan' => $datarray['owner_xchan'], diff --git a/Zotlabs/Module/Layouts.php b/Zotlabs/Module/Layouts.php index 8a7207fc2..9b9fc22f3 100644 --- a/Zotlabs/Module/Layouts.php +++ b/Zotlabs/Module/Layouts.php @@ -1,7 +1,7 @@ <?php namespace Zotlabs\Module; -require_once('include/identity.php'); +require_once('include/channel.php'); require_once('include/conversation.php'); require_once('include/acl_selectors.php'); diff --git a/Zotlabs/Module/Magic.php b/Zotlabs/Module/Magic.php index 63db4a317..6798f72a9 100644 --- a/Zotlabs/Module/Magic.php +++ b/Zotlabs/Module/Magic.php @@ -47,11 +47,9 @@ class Magic extends \Zotlabs\Web\Controller { * */ - $ret = zot_finger((($addr) ? $addr : '[system]@' . $parsed['host']),null); - if($ret['success']) { - $j = json_decode($ret['body'],true); - if($j) - import_xchan($j); + $j = \Zotlabs\Zot\Finger::run((($addr) ? $addr : '[system]@' . $parsed['host']),null); + if($j['success']) { + import_xchan($j); // Now try again diff --git a/Zotlabs/Module/Mail.php b/Zotlabs/Module/Mail.php index e6487d681..aae7585c4 100644 --- a/Zotlabs/Module/Mail.php +++ b/Zotlabs/Module/Mail.php @@ -5,7 +5,7 @@ require_once('include/acl_selectors.php'); require_once('include/message.php'); require_once('include/zot.php'); require_once("include/bbcode.php"); -require_once('include/Contact.php'); + @@ -32,17 +32,16 @@ class Mail extends \Zotlabs\Web\Controller { if(! $recipient) { $channel = \App::get_channel(); - $ret = zot_finger($rstr,$channel); + $j = \Zotlabs\Zot\Finger::run($rstr,$channel); - if(! $ret['success']) { + if(! $j['success']) { notice( t('Unable to lookup recipient.') . EOL); return; } - $j = json_decode($ret['body'],true); logger('message_post: lookup: ' . $url . ' ' . print_r($j,true)); - if(! ($j['success'] && $j['guid'])) { + if(! $j['guid']) { notice( t('Unable to communicate with requested channel.')); return; } @@ -306,11 +305,6 @@ class Mail extends \Zotlabs\Web\Controller { else \App::$poi = $messages[0]['to']; - // require_once('include/Contact.php'); - - // \App::set_widget('mail_conversant',vcard_from_xchan(\App::$poi,$get_observer_hash,'mail')); - - $tpl = get_markup_template('msg-header.tpl'); \App::$page['htmlhead'] .= replace_macros($tpl, array( diff --git a/Zotlabs/Module/Menu.php b/Zotlabs/Module/Menu.php index 9ada63911..e98053f8c 100644 --- a/Zotlabs/Module/Menu.php +++ b/Zotlabs/Module/Menu.php @@ -2,7 +2,7 @@ namespace Zotlabs\Module; require_once('include/menu.php'); -require_once('include/identity.php'); +require_once('include/channel.php'); class Menu extends \Zotlabs\Web\Controller { diff --git a/Zotlabs/Module/Message.php b/Zotlabs/Module/Message.php index 58a138899..ea2127a1d 100644 --- a/Zotlabs/Module/Message.php +++ b/Zotlabs/Module/Message.php @@ -5,8 +5,6 @@ require_once('include/acl_selectors.php'); require_once('include/message.php'); require_once('include/zot.php'); require_once("include/bbcode.php"); -require_once('include/Contact.php'); - class Message extends \Zotlabs\Web\Controller { diff --git a/Zotlabs/Module/Network.php b/Zotlabs/Module/Network.php index c88258a78..238df3593 100644 --- a/Zotlabs/Module/Network.php +++ b/Zotlabs/Module/Network.php @@ -385,7 +385,7 @@ class Network extends \Zotlabs\Web\Controller { $abook_uids = " and abook.abook_channel = " . local_channel() . " "; if($firehose && (! get_config('system','disable_discover_tab'))) { - require_once('include/identity.php'); + require_once('include/channel.php'); $sys = get_sys_channel(); $uids = " and item.uid = " . intval($sys['channel_id']) . " "; \App::$data['firehose'] = intval($sys['channel_id']); diff --git a/Zotlabs/Module/New_channel.php b/Zotlabs/Module/New_channel.php index 3dca1b0b4..30d7c83c6 100644 --- a/Zotlabs/Module/New_channel.php +++ b/Zotlabs/Module/New_channel.php @@ -1,7 +1,7 @@ <?php namespace Zotlabs\Module; -require_once('include/identity.php'); +require_once('include/channel.php'); require_once('include/permissions.php'); diff --git a/Zotlabs/Module/Oep.php b/Zotlabs/Module/Oep.php index 638ea7e2d..89824fc7e 100644 --- a/Zotlabs/Module/Oep.php +++ b/Zotlabs/Module/Oep.php @@ -181,8 +181,8 @@ class Oep extends \Zotlabs\Web\Controller { function oep_profile_reply($args) { - require_once('include/identity.php'); - require_once('include/Contact.php'); + require_once('include/channel.php'); + $url = $args['url']; if(preg_match('#//(.*?)/(.*?)/(.*?)(/|\?|&|$)#',$url,$matches)) { diff --git a/Zotlabs/Module/Photos.php b/Zotlabs/Module/Photos.php index 1659350a5..7186209ba 100644 --- a/Zotlabs/Module/Photos.php +++ b/Zotlabs/Module/Photos.php @@ -1,12 +1,12 @@ <?php namespace Zotlabs\Module; + require_once('include/photo/photo_driver.php'); require_once('include/photos.php'); require_once('include/items.php'); require_once('include/acl_selectors.php'); require_once('include/bbcode.php'); require_once('include/security.php'); -require_once('include/Contact.php'); require_once('include/attach.php'); require_once('include/text.php'); require_once('include/PermissionDescription.php'); @@ -18,7 +18,7 @@ class Photos extends \Zotlabs\Web\Controller { function init() { - if((get_config('system','block_public')) && (! local_channel()) && (! remote_channel())) { + if(observer_prohibited()) { return; } @@ -518,7 +518,7 @@ class Photos extends \Zotlabs\Web\Controller { // photos/name/image/xxxxx - if((get_config('system','block_public')) && (! local_channel()) && (! remote_channel())) { + if(observer_prohibited()) { notice( t('Public access denied.') . EOL); return; } diff --git a/Zotlabs/Module/Ping.php b/Zotlabs/Module/Ping.php index bea4a08b7..32427b06f 100644 --- a/Zotlabs/Module/Ping.php +++ b/Zotlabs/Module/Ping.php @@ -1,12 +1,13 @@ <?php namespace Zotlabs\Module; + /** * @file mod/ping.php * */ require_once('include/bbcode.php'); -require_once('include/notify.php'); + /** * @brief do several updates when pinged. @@ -285,7 +286,7 @@ class Ping extends \Zotlabs\Web\Controller { foreach($r as $item) { if((argv(1) === 'home') && (! intval($item['item_wall']))) continue; - $result[] = format_notification($item); + $result[] = \Zotlabs\Lib\Enotify::format($item); } } // logger('ping (network||home): ' . print_r($result, true), LOGGER_DATA); diff --git a/Zotlabs/Module/Probe.php b/Zotlabs/Module/Probe.php index 79abe9819..dda792131 100644 --- a/Zotlabs/Module/Probe.php +++ b/Zotlabs/Module/Probe.php @@ -20,17 +20,17 @@ class Probe extends \Zotlabs\Web\Controller { $channel = \App::get_channel(); $addr = trim($_GET['addr']); $do_import = ((intval($_GET['import']) && is_site_admin()) ? true : false); - $res = zot_finger($addr,$channel,false); + + $j = \Zotlabs\Zot\Finger::run($addr,$channel,false); + + // $res = zot_finger($addr,$channel,false); + $o .= '<pre>'; - if($res['success']) - $j = json_decode($res['body'],true); - else { + if(! $j['success']) { $o .= sprintf( t('Fetching URL returns error: %1$s'),$res['error'] . "\r\n\r\n"); $o .= "<strong>https connection failed. Trying again with auto failover to http.</strong>\r\n\r\n"; - $res = zot_finger($addr,$channel,true); - if($res['success']) - $j = json_decode($res['body'],true); - else + $j = \Zotlabs\Zot\Finger::run($addr,$channel,true); + if(! $j['success']) $o .= sprintf( t('Fetching URL returns error: %1$s'),$res['error'] . "\r\n\r\n"); } diff --git a/Zotlabs/Module/Profile.php b/Zotlabs/Module/Profile.php index 04a64fe76..8bf358bc8 100644 --- a/Zotlabs/Module/Profile.php +++ b/Zotlabs/Module/Profile.php @@ -55,8 +55,8 @@ class Profile extends \Zotlabs\Web\Controller { function get() { - if(get_config('system','block_public') && (! get_account_id()) && (! remote_channel())) { - return login(); + if(observer_prohibited(true)) { + return login(); } $groups = array(); diff --git a/Zotlabs/Module/Profile_photo.php b/Zotlabs/Module/Profile_photo.php index efcc7bece..a8cf3cbee 100644 --- a/Zotlabs/Module/Profile_photo.php +++ b/Zotlabs/Module/Profile_photo.php @@ -9,7 +9,7 @@ namespace Zotlabs\Module; require_once('include/photo/photo_driver.php'); require_once('include/photos.php'); -require_once('include/identity.php'); +require_once('include/channel.php'); /* @brief Function for sync'ing permissions of profile-photos and their profile * diff --git a/Zotlabs/Module/Profiles.php b/Zotlabs/Module/Profiles.php index e899abb3f..54780499b 100644 --- a/Zotlabs/Module/Profiles.php +++ b/Zotlabs/Module/Profiles.php @@ -1,7 +1,7 @@ <?php namespace Zotlabs\Module; -require_once('include/identity.php'); +require_once('include/channel.php'); require_once('include/selectors.php'); @@ -602,7 +602,7 @@ class Profiles extends \Zotlabs\Web\Controller { return; } - require_once('include/identity.php'); + require_once('include/channel.php'); $profile_fields_basic = get_profile_fields_basic(); $profile_fields_advanced = get_profile_fields_advanced(); diff --git a/Zotlabs/Module/Profperm.php b/Zotlabs/Module/Profperm.php index 94267aaac..33e9d1ece 100644 --- a/Zotlabs/Module/Profperm.php +++ b/Zotlabs/Module/Profperm.php @@ -1,7 +1,7 @@ <?php namespace Zotlabs\Module; -require_once('include/Contact.php'); + require_once('include/photos.php'); diff --git a/Zotlabs/Module/Pubsites.php b/Zotlabs/Module/Pubsites.php index 31bca5f30..0dda08e6d 100644 --- a/Zotlabs/Module/Pubsites.php +++ b/Zotlabs/Module/Pubsites.php @@ -28,9 +28,10 @@ class Pubsites extends \Zotlabs\Web\Controller { if($ret['success']) { $j = json_decode($ret['body'],true); if($j) { - $o .= '<table class="table table-striped table-hover"><tr><td>' . t('Hub URL') . '</td><td>' . t('Access Type') . '</td><td>' . t('Registration Policy') . '</td><td>' . t('Software') . '</td><td colspan="2">' . t('Ratings') . '</td></tr>'; + $o .= '<table class="table table-striped table-hover"><tr><td>' . t('Hub URL') . '</td><td>' . t('Access Type') . '</td><td>' . t('Registration Policy') . '</td><td>' . t('Stats') . '</td><td>' . t('Software') . '</td><td colspan="2">' . t('Ratings') . '</td></tr>'; if($j['sites']) { foreach($j['sites'] as $jj) { + $m = parse_url($jj['url']); if(strpos($jj['project'],\Zotlabs\Lib\System::get_platform_name()) === false) continue; $host = strtolower(substr($jj['url'],strpos($jj['url'],'://')+3)); @@ -43,7 +44,7 @@ class Pubsites extends \Zotlabs\Web\Controller { $location = '<br /> '; } $urltext = str_replace(array('https://'), '', $jj['url']); - $o .= '<tr><td><a href="'. (($jj['sellpage']) ? $jj['sellpage'] : $jj['url'] . '/register' ) . '" ><i class="fa fa-link"></i> ' . $urltext . '</a>' . $location . '</td><td>' . $jj['access'] . '</td><td>' . $jj['register'] . '</td><td>' . ucwords($jj['project']) . '</td><td><a href="ratings/' . $host . '" class="btn-btn-default"><i class="fa fa-eye"></i> ' . t('View') . '</a></td>' . $rate_links . '</tr>'; + $o .= '<tr><td><a href="'. (($jj['sellpage']) ? $jj['sellpage'] : $jj['url'] . '/register' ) . '" ><i class="fa fa-link"></i> ' . $urltext . '</a>' . $location . '</td><td>' . $jj['access'] . '</td><td>' . $jj['register'] . '</td><td>' . '<a target="stats" href="https://hubchart-tarine.rhcloud.com/hub.jsp?hubFqdn=' . $m['host'] . '"><i class="fa fa-area-chart"></i></a></td><td>' . ucwords($jj['project']) . '</td><td><a href="ratings/' . $host . '" class="btn-btn-default"><i class="fa fa-eye"></i> ' . t('View') . '</a></td>' . $rate_links . '</tr>'; } } diff --git a/Zotlabs/Module/Pubstream.php b/Zotlabs/Module/Pubstream.php index adc16e6e6..312be7718 100644 --- a/Zotlabs/Module/Pubstream.php +++ b/Zotlabs/Module/Pubstream.php @@ -12,7 +12,7 @@ class Pubstream extends \Zotlabs\Web\Controller { $_SESSION['loadtime'] = datetime_convert(); - if(get_config('system','block_public') && (! get_account_id()) && (! remote_channel())) { + if(observer_prohibited(true)) { return login(); } @@ -71,7 +71,7 @@ class Pubstream extends \Zotlabs\Web\Controller { $pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval(\App::$pager['itemspage']), intval(\App::$pager['start'])); } - require_once('include/identity.php'); + require_once('include/channel.php'); require_once('include/security.php'); if(get_config('system','site_firehose')) { diff --git a/Zotlabs/Module/Randprof.php b/Zotlabs/Module/Randprof.php index 86b25c22a..dc2e925fe 100644 --- a/Zotlabs/Module/Randprof.php +++ b/Zotlabs/Module/Randprof.php @@ -6,7 +6,6 @@ namespace Zotlabs\Module; class Randprof extends \Zotlabs\Web\Controller { function init() { - require_once('include/Contact.php'); $x = random_profile(); if($x) goaway(chanlink_url($x)); diff --git a/Zotlabs/Module/Ratings.php b/Zotlabs/Module/Ratings.php index 802bbfec2..969fb5015 100644 --- a/Zotlabs/Module/Ratings.php +++ b/Zotlabs/Module/Ratings.php @@ -8,7 +8,7 @@ class Ratings extends \Zotlabs\Web\Controller { function init() { - if((get_config('system','block_public')) && (! local_channel()) && (! remote_channel())) { + if(observer_prohibited()) { return; } @@ -80,9 +80,9 @@ class Ratings extends \Zotlabs\Web\Controller { - function get() { + function get() { - if((get_config('system','block_public')) && (! local_channel()) && (! remote_channel())) { + if(observer_prohibited()) { notice( t('Public access denied.') . EOL); return; } diff --git a/Zotlabs/Module/Regdir.php b/Zotlabs/Module/Regdir.php index 65f8daf67..48a7cc16d 100644 --- a/Zotlabs/Module/Regdir.php +++ b/Zotlabs/Module/Regdir.php @@ -60,14 +60,11 @@ class Regdir extends \Zotlabs\Web\Controller { json_return_and_die($result); } - $f = zot_finger('[system]@' . $m['host']); - if($f['success']) { - $j = json_decode($f['body'],true); - if($j['success'] && $j['guid']) { - $x = import_xchan($j); - if($x['success']) { - $result['success'] = true; - } + $j = \Zotlabs\Zot\Finger::run('[system]@' . $m['host']); + if($j['success'] && $j['guid']) { + $x = import_xchan($j); + if($x['success']) { + $result['success'] = true; } } diff --git a/Zotlabs/Module/Register.php b/Zotlabs/Module/Register.php index ca3f33238..7cd1ee501 100644 --- a/Zotlabs/Module/Register.php +++ b/Zotlabs/Module/Register.php @@ -1,7 +1,7 @@ <?php namespace Zotlabs\Module; -require_once('include/identity.php'); +require_once('include/channel.php'); class Register extends \Zotlabs\Web\Controller { diff --git a/Zotlabs/Module/Removeaccount.php b/Zotlabs/Module/Removeaccount.php index da496dfad..39e06bb7f 100644 --- a/Zotlabs/Module/Removeaccount.php +++ b/Zotlabs/Module/Removeaccount.php @@ -36,17 +36,12 @@ class Removeaccount extends \Zotlabs\Web\Controller { } } - require_once('include/Contact.php'); - $global_remove = intval($_POST['global']); - account_remove($account_id,true); - + account_remove($account_id, 1 - $global_remove); } - - - - function get() { + + function get() { if(! local_channel()) goaway(z_root()); diff --git a/Zotlabs/Module/Removeme.php b/Zotlabs/Module/Removeme.php index 9b634672a..e611d8112 100644 --- a/Zotlabs/Module/Removeme.php +++ b/Zotlabs/Module/Removeme.php @@ -35,8 +35,6 @@ class Removeme extends \Zotlabs\Web\Controller { } } - require_once('include/Contact.php'); - $global_remove = intval($_POST['global']); channel_remove(local_channel(),1 - $global_remove,true); @@ -44,8 +42,7 @@ class Removeme extends \Zotlabs\Web\Controller { } - - function get() { + function get() { if(! local_channel()) goaway(z_root()); diff --git a/Zotlabs/Module/Search.php b/Zotlabs/Module/Search.php index 9941ebbd2..fcc2506fc 100644 --- a/Zotlabs/Module/Search.php +++ b/Zotlabs/Module/Search.php @@ -139,7 +139,7 @@ class Search extends \Zotlabs\Web\Controller { $item_normal = item_normal(); $pub_sql = public_permissions_sql($observer_hash); - require_once('include/identity.php'); + require_once('include/channel.php'); $sys = get_sys_channel(); diff --git a/Zotlabs/Module/Settings.php b/Zotlabs/Module/Settings.php index 32ef89f68..5687ce84b 100644 --- a/Zotlabs/Module/Settings.php +++ b/Zotlabs/Module/Settings.php @@ -483,7 +483,7 @@ class Settings extends \Zotlabs\Web\Controller { if($username != $channel['channel_name']) { $name_change = true; - require_once('include/identity.php'); + require_once('include/channel.php'); $err = validate_channelname($username); if($err) { notice($err); diff --git a/Zotlabs/Module/Setup.php b/Zotlabs/Module/Setup.php index f8c14951b..447f46ed6 100644 --- a/Zotlabs/Module/Setup.php +++ b/Zotlabs/Module/Setup.php @@ -12,7 +12,6 @@ namespace Zotlabs\Module; /** * @brief Initialisation for the setup module. * - * @param[in,out] App &$a */ class Setup extends \Zotlabs\Web\Controller { @@ -54,16 +53,15 @@ class Setup extends \Zotlabs\Web\Controller { /** * @brief Handle the actions of the different setup steps. * - * @param[in,out] App &$a */ - function post() { - global $db; + + function post() { switch($this->install_wizard_pass) { case 1: case 2: return; - break; // just in case return don't return :) + // implied break; case 3: $urlpath = \App::get_path(); $dbhost = trim($_POST['dbhost']); @@ -82,39 +80,15 @@ class Setup extends \Zotlabs\Web\Controller { $siteurl = rtrim($siteurl,'/'); require_once('include/dba/dba_driver.php'); - unset($db); - $db = dba_factory($dbhost, $dbport, $dbuser, $dbpass, $dbdata, $dbtype, true); + + $db = \DBA::dba_factory($dbhost, $dbport, $dbuser, $dbpass, $dbdata, $dbtype, true); - if(! $db->connected) { - echo 'Database Connect failed: ' . $db->error; + if(! \DBA::$dba->connected) { + echo 'Database Connect failed: ' . DBA::$dba->error; killme(); - \App::$data['db_conn_failed']=true; } - /*if(get_db_errno()) { - unset($db); - $db = dba_factory($dbhost, $dbport, $dbuser, $dbpass, '', true); - - if(! get_db_errno()) { - $r = q("CREATE DATABASE '%s'", - dbesc($dbdata) - ); - if($r) { - unset($db); - $db = new dba($dbhost, $dbport, $dbuser, $dbpass, $dbdata, true); - } else { - \App::$data['db_create_failed']=true; - } - } else { - \App::$data['db_conn_failed']=true; - return; - } - }*/ - //if(get_db_errno()) { - - //} - return; - break; + // implied break; case 4: $urlpath = \App::get_path(); $dbhost = notags(trim($_POST['dbhost'])); @@ -138,10 +112,12 @@ class Setup extends \Zotlabs\Web\Controller { } } - // connect to db - $db = dba_factory($dbhost, $dbport, $dbuser, $dbpass, $dbdata, $dbtype, true); - - if(! $db->connected) { + if(! \DBA::$dba->connected) { + // connect to db + $db = \DBA::dba_factory($dbhost, $dbport, $dbuser, $dbpass, $dbdata, $dbtype, true); + } + + if(! \DBA::$dba->connected) { echo 'CRITICAL: DB not connected.'; killme(); } @@ -175,6 +151,8 @@ class Setup extends \Zotlabs\Web\Controller { \App::$data['db_installed'] = true; return; + // implied break; + default: break; } } @@ -191,11 +169,10 @@ class Setup extends \Zotlabs\Web\Controller { * * Depending on the state we are currently in it returns different content. * - * @param App &$a * @return string parsed HTML output */ - function get() { - global $db; + + function get() { $o = ''; $wizard_status = ''; @@ -228,7 +205,7 @@ class Setup extends \Zotlabs\Web\Controller { $txt .= "<pre>".\App::$data['db_failed'] . "</pre>". EOL ; $db_return_text .= $txt; } - if($db && $db->connected) { + if(\DBA::$dba && \DBA::$dba->connected) { $r = q("SELECT COUNT(*) as `total` FROM `account`"); if($r && count($r) && $r[0]['total']) { $tpl = get_markup_template('install.tpl'); @@ -598,7 +575,7 @@ class Setup extends \Zotlabs\Web\Controller { if(! is_writable(TEMPLATE_BUILD_PATH) ) { $status = false; $help = t('Red uses the Smarty3 template engine to render its web views. Smarty3 compiles templates to PHP to speed up rendering.') .EOL; - $help .= sprintf( t('In order to store these compiled templates, the web server needs to have write access to the directory %s under the Red top level folder.'), TEMPLATE_BUILD_PATH) . EOL; + $help .= sprintf( t('In order to store these compiled templates, the web server needs to have write access to the directory %s under the top level web folder.'), TEMPLATE_BUILD_PATH) . EOL; $help .= t('Please ensure that the user that your web server runs as (e.g. www-data) has write access to this folder.').EOL; $help .= sprintf( t('Note: as a security measure, you should give the web server write access to %s only--not the template files (.tpl) that it contains.'), TEMPLATE_BUILD_PATH) . EOL; } @@ -698,12 +675,12 @@ class Setup extends \Zotlabs\Web\Controller { function load_database($db) { - $str = file_get_contents($db->get_install_script()); + $str = file_get_contents(\DBA::$dba->get_install_script()); $arr = explode(';',$str); $errors = false; foreach($arr as $a) { if(strlen(trim($a))) { - $r = @$db->q(trim($a)); + $r = dbq(trim($a)); if(! $r) { $errors .= t('Errors encountered creating database tables.') . $a . EOL; } @@ -734,7 +711,7 @@ class Setup extends \Zotlabs\Web\Controller { set_config('system','curl_ssl_ciphers','ALL:!eNULL'); // Create a system channel - require_once ('include/identity.php'); + require_once ('include/channel.php'); create_sys_channel(); $baseurl = z_root(); diff --git a/Zotlabs/Module/Uexport.php b/Zotlabs/Module/Uexport.php index ada7e0986..d48f96d76 100644 --- a/Zotlabs/Module/Uexport.php +++ b/Zotlabs/Module/Uexport.php @@ -11,7 +11,7 @@ class Uexport extends \Zotlabs\Web\Controller { if(argc() > 1) { $channel = \App::get_channel(); - require_once('include/identity.php'); + require_once('include/channel.php'); if(argc() > 1 && intval(argv(1)) > 1900) { $year = intval(argv(1)); diff --git a/Zotlabs/Module/Viewconnections.php b/Zotlabs/Module/Viewconnections.php index a9445cdeb..ea478f92a 100644 --- a/Zotlabs/Module/Viewconnections.php +++ b/Zotlabs/Module/Viewconnections.php @@ -2,23 +2,21 @@ namespace Zotlabs\Module; require_once('include/selectors.php'); -require_once('include/Contact.php'); - class Viewconnections extends \Zotlabs\Web\Controller { function init() { - if((get_config('system','block_public')) && (! local_channel()) && (! remote_channel())) { + if(observer_prohibited()) { return; } if(argc() > 1) profile_load($a,argv(1)); } - function get() { + function get() { - if((get_config('system','block_public')) && (! local_channel()) && (! remote_channel())) { + if(observer_prohibited()) { notice( t('Public access denied.') . EOL); return; } diff --git a/Zotlabs/Module/Wall_attach.php b/Zotlabs/Module/Wall_attach.php index 5bdecfa75..9a1019ddb 100644 --- a/Zotlabs/Module/Wall_attach.php +++ b/Zotlabs/Module/Wall_attach.php @@ -2,7 +2,7 @@ namespace Zotlabs\Module; require_once('include/attach.php'); -require_once('include/identity.php'); +require_once('include/channel.php'); require_once('include/photos.php'); diff --git a/Zotlabs/Module/Wall_upload.php b/Zotlabs/Module/Wall_upload.php index fff3ed03a..3868cb14e 100644 --- a/Zotlabs/Module/Wall_upload.php +++ b/Zotlabs/Module/Wall_upload.php @@ -2,7 +2,7 @@ namespace Zotlabs\Module; require_once('include/photo/photo_driver.php'); -require_once('include/identity.php'); +require_once('include/channel.php'); require_once('include/photos.php'); diff --git a/Zotlabs/Module/Webpages.php b/Zotlabs/Module/Webpages.php index d8adb55b2..bb8d454c8 100644 --- a/Zotlabs/Module/Webpages.php +++ b/Zotlabs/Module/Webpages.php @@ -1,7 +1,7 @@ <?php namespace Zotlabs\Module; -require_once('include/identity.php'); +require_once('include/channel.php'); require_once('include/conversation.php'); require_once('include/acl_selectors.php'); require_once('include/PermissionDescription.php'); diff --git a/Zotlabs/Module/Zotfeed.php b/Zotlabs/Module/Zotfeed.php index 28040149f..6b505c890 100644 --- a/Zotlabs/Module/Zotfeed.php +++ b/Zotlabs/Module/Zotfeed.php @@ -15,7 +15,7 @@ class Zotfeed extends \Zotlabs\Web\Controller { if(! $mindate) $mindate = datetime_convert('UTC','UTC', 'now - 14 days'); - if(get_config('system','block_public') && (! get_account_id()) && (! remote_channel())) { + if(observer_prohibited()) { $result['message'] = 'Public access denied'; json_return_and_die($result); } @@ -45,8 +45,6 @@ class Zotfeed extends \Zotlabs\Web\Controller { $result['messages'] = zot_feed($r[0]['channel_id'],$observer['xchan_hash'],array('mindate' => $mindate)); $result['success'] = true; json_return_and_die($result); - - } } diff --git a/Zotlabs/Storage/Browser.php b/Zotlabs/Storage/Browser.php index 3556f7f06..f875cbf33 100644 --- a/Zotlabs/Storage/Browser.php +++ b/Zotlabs/Storage/Browser.php @@ -256,6 +256,7 @@ class Browser extends DAV\Browser\Plugin { $func($a); } } + $this->server->httpResponse->setHeader('Content-Security-Policy', "script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'"); construct_page($a); } diff --git a/Zotlabs/Web/WebServer.php b/Zotlabs/Web/WebServer.php new file mode 100644 index 000000000..88ab4995b --- /dev/null +++ b/Zotlabs/Web/WebServer.php @@ -0,0 +1,130 @@ +<?php /** @file */ + +namespace Zotlabs\Web; + +class WebServer { + + public function run() { + + + /* + * Bootstrap the application, load configuration, load modules, load theme, etc. + */ + + require_once('boot.php'); + + sys_boot(); + + + \App::$language = get_best_language(); + load_translation_table(\App::$language,\App::$install); + + + /** + * + * Important stuff we always need to do. + * + * The order of these may be important so use caution if you think they're all + * intertwingled with no logical order and decide to sort it out. Some of the + * dependencies have changed, but at least at one time in the recent past - the + * order was critical to everything working properly + * + */ + + if(\App::$session) { + \App::$session->start(); + } + else { + session_start(); + register_shutdown_function('session_write_close'); + } + + /** + * Language was set earlier, but we can over-ride it in the session. + * We have to do it here because the session was just now opened. + */ + + if(array_key_exists('system_language',$_POST)) { + if(strlen($_POST['system_language'])) + $_SESSION['language'] = $_POST['system_language']; + else + unset($_SESSION['language']); + } + if((x($_SESSION, 'language')) && ($_SESSION['language'] !== $lang)) { + \App::$language = $_SESSION['language']; + load_translation_table(\App::$language); + } + + if((x($_GET,'zid')) && (! \App::$install)) { + \App::$query_string = strip_zids(\App::$query_string); + if(! local_channel()) { + $_SESSION['my_address'] = $_GET['zid']; + zid_init($a); + } + } + + if((x($_SESSION, 'authenticated')) || (x($_POST, 'auth-params')) || (\App::$module === 'login')) + require('include/auth.php'); + + if(! x($_SESSION, 'sysmsg')) + $_SESSION['sysmsg'] = array(); + + if(! x($_SESSION, 'sysmsg_info')) + $_SESSION['sysmsg_info'] = array(); + + /* + * check_config() is responsible for running update scripts. These automatically + * update the DB schema whenever we push a new one out. It also checks to see if + * any plugins have been added or removed and reacts accordingly. + */ + + + if(\App::$install) { + /* Allow an exception for the view module so that pcss will be interpreted during installation */ + if(\App::$module != 'view') + \App::$module = 'setup'; + } + else + check_config($a); + + nav_set_selected('nothing'); + + $Router = new Router($a); + + /* initialise content region */ + + if(! x(\App::$page, 'content')) + \App::$page['content'] = ''; + + call_hooks('page_content_top', \App::$page['content']); + + + $Router->Dispatch($a); + + + // If you're just visiting, let javascript take you home + + if(x($_SESSION, 'visitor_home')) { + $homebase = $_SESSION['visitor_home']; + } elseif(local_channel()) { + $homebase = z_root() . '/channel/' . \App::$channel['channel_address']; + } + + if(isset($homebase)) { + \App::$page['content'] .= '<script>var homebase = "' . $homebase . '";</script>'; + } + + // now that we've been through the module content, see if the page reported + // a permission problem and if so, a 403 response would seem to be in order. + + if(stristr(implode("", $_SESSION['sysmsg']), t('Permission denied'))) { + header($_SERVER['SERVER_PROTOCOL'] . ' 403 ' . t('Permission denied.')); + } + + call_hooks('page_end', \App::$page['content']); + + construct_page($a); + + killme(); + } +}
\ No newline at end of file diff --git a/Zotlabs/Zot/Auth.php b/Zotlabs/Zot/Auth.php index f764172fa..0837be21a 100644 --- a/Zotlabs/Zot/Auth.php +++ b/Zotlabs/Zot/Auth.php @@ -80,11 +80,9 @@ class Auth { if(! $x) { // finger them if they can't be found. - $ret = zot_finger($address, null); - if ($ret['success']) { - $j = json_decode($ret['body'], true); - if($j) - import_xchan($j); + $j = Finger::run($address, null); + if ($j['success']) { + import_xchan($j); $x = q("select * from hubloc left join xchan on xchan_hash = hubloc_hash where hubloc_addr = '%s' order by hubloc_id desc", dbesc($address) diff --git a/Zotlabs/Zot/Finger.php b/Zotlabs/Zot/Finger.php new file mode 100644 index 000000000..229fda8bd --- /dev/null +++ b/Zotlabs/Zot/Finger.php @@ -0,0 +1,130 @@ +<?php + +namespace Zotlabs\Zot; + + +class Finger { + + static private $token; + + /** + * @brief Look up information about channel. + * + * @param string $webbie + * does not have to be host qualified e.g. 'foo' is treated as 'foo\@thishub' + * @param array $channel + * (optional), if supplied permissions will be enumerated specifically for $channel + * @param boolean $autofallback + * fallback/failover to http if https connection cannot be established. Default is true. + * + * @return zotinfo array (with 'success' => true) or array('success' => false); + */ + + static public function run($webbie, $channel = null, $autofallback = true) { + + $ret = array('success' => false); + + self::$token = random_string(); + + if (strpos($webbie,'@') === false) { + $address = $webbie; + $host = App::get_hostname(); + } else { + $address = substr($webbie,0,strpos($webbie,'@')); + $host = substr($webbie,strpos($webbie,'@')+1); + } + + $xchan_addr = $address . '@' . $host; + + if ((! $address) || (! $xchan_addr)) { + logger('zot_finger: no address :' . $webbie); + return $ret; + } + + logger('using xchan_addr: ' . $xchan_addr, LOGGER_DATA, LOG_DEBUG); + + // potential issue here; the xchan_addr points to the primary hub. + // The webbie we were called with may not, so it might not be found + // unless we query for hubloc_addr instead of xchan_addr + + $r = q("select xchan.*, hubloc.* from xchan + left join hubloc on xchan_hash = hubloc_hash + where xchan_addr = '%s' and hubloc_primary = 1 limit 1", + dbesc($xchan_addr) + ); + + if ($r) { + $url = $r[0]['hubloc_url']; + + if ($r[0]['hubloc_network'] && $r[0]['hubloc_network'] !== 'zot') { + logger('zot_finger: alternate network: ' . $webbie); + logger('url: '.$url.', net: '.var_export($r[0]['hubloc_network'],true), LOGGER_DATA, LOG_DEBUG); + return $ret; + } + } + else { + $url = 'https://' . $host; + } + + $rhs = '/.well-known/zot-info'; + $https = ((strpos($url,'https://') === 0) ? true : false); + + logger('zot_finger: ' . $address . ' at ' . $url, LOGGER_DEBUG); + + if ($channel) { + $postvars = array( + 'address' => $address, + 'target' => $channel['channel_guid'], + 'target_sig' => $channel['channel_guid_sig'], + 'key' => $channel['channel_pubkey'], + 'token' => self::$token + ); + + $result = z_post_url($url . $rhs,$postvars); + + if ((! $result['success']) && ($autofallback)) { + if ($https) { + logger('zot_finger: https failed. falling back to http'); + $result = z_post_url('http://' . $host . $rhs,$postvars); + } + } + } + else { + $rhs .= '?f=&address=' . urlencode($address) . '&token=' . self::$token; + + $result = z_fetch_url($url . $rhs); + if ((! $result['success']) && ($autofallback)) { + if ($https) { + logger('zot_finger: https failed. falling back to http'); + $result = z_fetch_url('http://' . $host . $rhs); + } + } + } + + if(! $result['success']) { + logger('zot_finger: no results'); + return $ret; + } + + $x = json_decode($result['body'],true); + if($x) { + $signed_token = ((is_array($x) && array_key_exists('signed_token',$x)) ? $x['signed_token'] : null); + if($signed_token) { + $valid = rsa_verify('token.' . self::$token,base64url_decode($signed_token),$x['key']); + if(! $valid) { + logger('invalid signed token: ' . $url . $rhs, LOGGER_NORMAL, LOG_ERR); + return $ret; + } + } + 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 $ret; + } + } + + return $x; + } + +}
\ No newline at end of file |