This commit is contained in:
zotlabs 2020-05-11 20:39:43 -07:00
parent 9c177e7477
commit 26bc1bef1d
3 changed files with 1373 additions and 1336 deletions

View file

@ -16,7 +16,7 @@ use Zotlabs\Daemon\Master;
* @brief This file defines some global constants and includes the central App class. * @brief This file defines some global constants and includes the central App class.
*/ */
define ( 'STD_VERSION', '20.05.06' ); define ( 'STD_VERSION', '20.05.12' );
define ( 'ZOT_REVISION', '6.0' ); define ( 'ZOT_REVISION', '6.0' );
define ( 'DB_UPDATE_VERSION', 1239 ); define ( 'DB_UPDATE_VERSION', 1239 );

View file

@ -4,7 +4,7 @@
* @brief Channel related functions. * @brief Channel related functions.
*/ */
use App;
use Zotlabs\Lib\Libzot; use Zotlabs\Lib\Libzot;
use Zotlabs\Lib\Libsync; use Zotlabs\Lib\Libsync;
use Zotlabs\Lib\AccessList; use Zotlabs\Lib\AccessList;
@ -1835,15 +1835,19 @@ function get_zcard_embed($channel, $observer_hash = '', $args = array()) {
* - array with channel entry * - array with channel entry
* - false if no channel with $nick was found * - false if no channel with $nick was found
*/ */
function channelx_by_nick($nick) { function channelx_by_nick($nick) {
// If we are provided a Unicode nickname convert to IDN // If we are provided a Unicode nickname convert to IDN
$nick = punify($nick); $nick = punify($nick);
// return a cached copy if there is a cached copy and it's a match // return a cached copy if there is a cached copy and it's a match.
// Also check that there is an xchan_hash to validate the App::$channel data is complete
if (App::$channel && is_array(App::$channel) && array_key_exists('channel_address',App::$channel) && App::$channel['channel_address'] === $nick) { // and that columns from both joined tables are present
if (App::$channel && is_array(App::$channel) && array_key_exists('channel_address',App::$channel)
&& array_key_exists('xchan_hash',App::$channel) && App::$channel['channel_address'] === $nick) {
return App::$channel; return App::$channel;
} }
@ -1851,7 +1855,7 @@ function channelx_by_nick($nick) {
dbesc($nick) dbesc($nick)
); );
return(($r) ? $r[0] : false); return(($r) ? array_shift($r) : false);
} }
/** /**
@ -1860,18 +1864,19 @@ function channelx_by_nick($nick) {
* @param string $hash * @param string $hash
* @return array|boolean false if channel ID not found, otherwise the channel array * @return array|boolean false if channel ID not found, otherwise the channel array
*/ */
function channelx_by_hash($hash) { function channelx_by_hash($hash) {
if (App::$channel && is_array(App::$channel) && array_key_exists('channel_hash',App::$channel) && App::$channel['channel_hash'] === $hash) { if (App::$channel && is_array(App::$channel) && array_key_exists('channel_hash',App::$channel)
&& array_key_exists('xchan_hash',App::$channel) && App::$channel['channel_hash'] === $hash) {
return App::$channel; return App::$channel;
} }
$r = q("SELECT * FROM channel left join xchan on channel_hash = xchan_hash WHERE channel_hash = '%s' and channel_removed = 0 LIMIT 1", $r = q("SELECT * FROM channel left join xchan on channel_hash = xchan_hash WHERE channel_hash = '%s' and channel_removed = 0 LIMIT 1",
dbesc($hash) dbesc($hash)
); );
return(($r) ? $r[0] : false); return(($r) ? array_shift($r) : false);
} }
@ -1881,18 +1886,19 @@ function channelx_by_hash($hash) {
* @param int $id A channel ID * @param int $id A channel ID
* @return array|boolean false if channel ID not found, otherwise the channel array * @return array|boolean false if channel ID not found, otherwise the channel array
*/ */
function channelx_by_n($id) { function channelx_by_n($id) {
if (App::$channel && is_array(App::$channel) && array_key_exists('channel_id',App::$channel) && intval(App::$channel['channel_id']) === intval($id)) { if (App::$channel && is_array(App::$channel) && array_key_exists('channel_id',App::$channel)
&& array_key_exists('xchan_hash',App::$channel) && intval(App::$channel['channel_id']) === intval($id)) {
return App::$channel; return App::$channel;
} }
$r = q("SELECT * FROM channel LEFT JOIN xchan ON channel_hash = xchan_hash WHERE channel_id = %d AND channel_removed = 0 LIMIT 1", $r = q("SELECT * FROM channel LEFT JOIN xchan ON channel_hash = xchan_hash WHERE channel_id = %d AND channel_removed = 0 LIMIT 1",
dbesc($id) dbesc($id)
); );
return(($r) ? $r[0] : false); return(($r) ? array_shift($r) : false);
} }
/** /**
@ -1901,6 +1907,7 @@ function channelx_by_n($id) {
* @param array $channel * @param array $channel
* @return string * @return string
*/ */
function channel_reddress($channel) { function channel_reddress($channel) {
if(! ($channel && array_key_exists('channel_address', $channel))) if(! ($channel && array_key_exists('channel_address', $channel)))
return ''; return '';
@ -1918,12 +1925,10 @@ function channel_reddress($channel) {
* @param int $channel_id * @param int $channel_id
* @return int * @return int
*/ */
function channel_manual_conv_update($channel_id) { function channel_manual_conv_update($channel_id) {
$x = get_pconfig($channel_id, 'system', 'manual_conversation_update'); $x = get_pconfig($channel_id, 'system', 'manual_conversation_update', get_config('system', 'manual_conversation_update', 1));
if($x === false)
$x = get_config('system', 'manual_conversation_update', 1);
return intval($x); return intval($x);
} }
@ -2047,6 +2052,7 @@ function profile_store_lowlevel($arr) {
* @param boolean $unset_session (optional) default true * @param boolean $unset_session (optional) default true
* @return boolean|array * @return boolean|array
*/ */
function account_remove($account_id, $local = true, $unset_session = true) { function account_remove($account_id, $local = true, $unset_session = true) {
logger('account_remove: ' . $account_id); logger('account_remove: ' . $account_id);
@ -2110,6 +2116,7 @@ function account_remove($account_id, $local = true, $unset_session = true) {
* @param boolean $local default true * @param boolean $local default true
* @param boolean $unset_session default false * @param boolean $unset_session default false
*/ */
function channel_remove($channel_id, $local = true, $unset_session = false) { function channel_remove($channel_id, $local = true, $unset_session = false) {
if (! $channel_id) { if (! $channel_id) {
@ -2368,10 +2375,12 @@ function anon_identity_init($reqvars) {
return $x[0]; return $x[0];
} }
function channel_url($channel) { function channel_url($channel) {
if(! is_array($channel))
// data validation - if this is wrong, log the call stack so we can find the issue
if (! is_array($channel)) {
btlogger('not a channel array'); btlogger('not a channel array');
}
return (($channel) ? z_root() . '/channel/' . $channel['channel_address'] : z_root()); return (($channel) ? z_root() . '/channel/' . $channel['channel_address'] : z_root());
} }

File diff suppressed because it is too large Load diff