2018-06-05 06:20:09 +00:00
< ? php
2018-07-31 02:25:35 +00:00
2022-02-16 04:08:28 +00:00
namespace Code\Lib ;
2018-06-05 06:20:09 +00:00
2021-12-02 22:33:36 +00:00
use App ;
2022-11-17 08:40:51 +00:00
2022-02-16 04:08:28 +00:00
use Code\Extend\Hook ;
2023-07-22 12:06:41 +00:00
use Code\Nomad\Profile ;
2022-02-16 04:08:28 +00:00
use Code\Render\Theme ;
2022-02-12 20:43:29 +00:00
2022-01-25 01:26:12 +00:00
2018-06-05 06:20:09 +00:00
require_once ( 'include/permissions.php' );
2021-12-02 23:02:31 +00:00
class Libzotdir
{
2018-06-05 06:20:09 +00:00
2021-12-02 23:02:31 +00:00
public static function get_directory_setting ( $observer , $setting )
{
2021-12-03 03:01:39 +00:00
if ( $observer ) {
2021-12-02 23:02:31 +00:00
$ret = get_xconfig ( $observer , 'directory' , $setting );
2021-12-03 03:01:39 +00:00
} else {
2021-12-02 23:02:31 +00:00
$ret = (( array_key_exists ( $setting , $_SESSION )) ? intval ( $_SESSION [ $setting ]) : false );
2021-12-03 03:01:39 +00:00
}
2018-06-05 06:20:09 +00:00
2021-12-02 23:02:31 +00:00
if ( $ret === false ) {
$ret = get_config ( 'directory' , $setting );
if ( $ret === false ) {
2022-06-21 21:35:48 +00:00
$ret = ( in_array ( $setting , [ 'globaldir' , 'covers' , 'safemode' , 'activedir' ]) ? 1 : 0 );
2021-12-02 23:02:31 +00:00
}
}
2018-06-05 06:20:09 +00:00
2021-12-03 03:01:39 +00:00
if ( $setting === 'globaldir' && intval ( get_config ( 'system' , 'localdir_hide' ))) {
2021-12-02 23:02:31 +00:00
$ret = 1 ;
2021-12-03 03:01:39 +00:00
}
2018-08-01 00:27:50 +00:00
2021-12-02 23:02:31 +00:00
return $ret ;
}
2018-06-05 06:20:09 +00:00
2021-12-02 23:02:31 +00:00
/**
* @ brief Called by the directory_sort widget .
*/
public static function dir_sort_links ()
{
2018-06-05 06:20:09 +00:00
2021-12-02 23:02:31 +00:00
$safe_mode = 1 ;
2018-06-05 06:20:09 +00:00
2021-12-02 23:02:31 +00:00
$observer = get_observer_hash ();
2018-06-05 06:20:09 +00:00
2021-12-02 23:02:31 +00:00
$safe_mode = self :: get_directory_setting ( $observer , 'safemode' );
$globaldir = self :: get_directory_setting ( $observer , 'globaldir' );
$pubforums = self :: get_directory_setting ( $observer , 'chantype' );
$activedir = self :: get_directory_setting ( $observer , 'activedir' );
2022-06-21 21:51:29 +00:00
$covers = self :: get_directory_setting ( $observer , 'covers' );
2021-04-14 03:11:33 +00:00
2021-12-02 23:02:31 +00:00
$hide_local = intval ( get_config ( 'system' , 'localdir_hide' ));
if ( $hide_local ) {
$globaldir = 1 ;
}
2018-08-01 00:27:50 +00:00
2021-12-02 23:02:31 +00:00
// Build urls without order and pubforums so it's easy to tack on the changed value
// Probably there's an easier way to do this
2018-06-05 06:20:09 +00:00
2021-12-02 23:02:31 +00:00
$directory_sort_order = get_config ( 'system' , 'directory_sort_order' );
if ( ! $directory_sort_order ) {
$directory_sort_order = 'date' ;
}
2018-06-05 06:20:09 +00:00
2021-12-02 23:02:31 +00:00
$current_order = (( $_REQUEST [ 'order' ]) ? $_REQUEST [ 'order' ] : $directory_sort_order );
$suggest = (( $_REQUEST [ 'suggest' ]) ? '&suggest=' . $_REQUEST [ 'suggest' ] : '' );
2018-06-05 06:20:09 +00:00
2021-12-02 23:02:31 +00:00
$url = 'directory?f=' ;
2018-06-05 06:20:09 +00:00
2021-12-02 23:02:31 +00:00
$tmp = array_merge ( $_GET , $_POST );
unset ( $tmp [ 'suggest' ]);
unset ( $tmp [ 'pubforums' ]);
unset ( $tmp [ 'type' ]);
unset ( $tmp [ 'global' ]);
2022-06-21 21:35:48 +00:00
unset ( $tmp [ 'covers' ]);
2021-12-02 23:02:31 +00:00
unset ( $tmp [ 'safe' ]);
unset ( $tmp [ 'active' ]);
unset ( $tmp [ 'req' ]);
unset ( $tmp [ 'f' ]);
$q = http_build_query ( $tmp );
$forumsurl = $url . (( $q ) ? '&' . $q : '' ) . $suggest ;
2018-06-05 06:20:09 +00:00
2022-02-12 20:43:29 +00:00
$o = replace_macros ( Theme :: get_template ( 'dir_sort_links.tpl' ), [
2021-12-02 23:02:31 +00:00
'$header' => t ( 'Directory Options' ),
'$forumsurl' => $forumsurl ,
2022-11-17 08:40:51 +00:00
'$safemode' => [ 'safemode' , t ( 'Safe Mode' ), $safe_mode , '' , [ t ( 'No' ), t ( 'Yes' )], ' onchange=\'window.location.href="' . $forumsurl . '&safe="+(this.checked ? 1 : 0)\'' ],
'$pubforums' => [ 'pubforums' , t ( 'Groups Only' ), (( $pubforums == 1 ) ? true : false ), '' , [ t ( 'No' ), t ( 'Yes' )], ' onchange=\'window.location.href="' . $forumsurl . '&type="+(this.checked ? 1 : 0)\'' ],
2021-12-03 03:01:39 +00:00
// '$collections' => array('collections', t('Collections Only'),(($pubforums == 2) ? true : false),'',array(t('No'), t('Yes')),' onchange=\'window.location.href="' . $forumsurl . '&type="+(this.checked ? 2 : 0)\''),
2021-12-02 23:02:31 +00:00
'$hide_local' => $hide_local ,
2022-11-17 08:40:51 +00:00
'$globaldir' => [ 'globaldir' , t ( 'This Website Only' ), 1 - intval ( $globaldir ), '' , [ t ( 'No' ), t ( 'Yes' )], ' onchange=\'window.location.href="' . $forumsurl . '&global="+(this.checked ? 0 : 1)\'' ],
'$activedir' => [ 'activedir' , t ( 'Recently Updated' ), intval ( $activedir ), '' , [ t ( 'No' ), t ( 'Yes' )], ' onchange=\'window.location.href="' . $forumsurl . '&active="+(this.checked ? 1 : 0)\'' ],
2022-06-21 21:51:29 +00:00
'$covers' => ( Config :: Get ( 'system' , 'remote_cover_photos' )) ? [ 'covers' , t ( 'Show cover photos' ), intval ( $covers ), t ( 'May slow page loading' ), [ t ( 'No' ), t ( 'Yes' )], ' onchange=\'window.location.href="' . $forumsurl . '&covers="+(this.checked ? 1 : 0)\'' ] : '' ,
2021-12-02 23:02:31 +00:00
]);
return $o ;
}
/**
* @ brief
*
* Given an update record , probe the channel , grab a zot - info packet and refresh / sync the data .
*
* Ignore updating records marked as deleted .
*
* If successful , sets ud_last in the DB to the current datetime for this
* reddress / webbie .
*
* @ param array $ud Entry from update table
*/
public static function update_directory_entry ( $ud )
{
logger ( 'update_directory_entry: ' . print_r ( $ud , true ), LOGGER_DATA );
if ( $ud [ 'ud_addr' ] && ( ! ( $ud [ 'ud_flags' ] & UPDATE_FLAGS_DELETED ))) {
$success = false ;
2022-08-28 03:41:22 +00:00
$href = Webfinger :: nomad_url ( punify ( $ud [ 'ud_addr' ]));
2021-12-02 23:02:31 +00:00
if ( $href ) {
2023-08-22 22:03:42 +00:00
$zf = Zotfinger :: post ( $href );
2021-12-02 23:02:31 +00:00
}
if ( is_array ( $zf ) && array_path_exists ( 'signature/signer' , $zf ) && $zf [ 'signature' ][ 'signer' ] === $href && intval ( $zf [ 'signature' ][ 'header_valid' ])) {
$xc = Libzot :: import_xchan ( $zf [ 'data' ], 0 , $ud );
} else {
2021-12-03 03:01:39 +00:00
q (
" update updates set ud_last = '%s' where ud_addr = '%s' " ,
2021-12-02 23:02:31 +00:00
dbesc ( datetime_convert ()),
dbesc ( $ud [ 'ud_addr' ])
);
}
}
}
/**
* @ brief Push local channel updates to a local directory server .
*
2022-02-16 04:08:28 +00:00
* This is called from Code / Daemon / Directory . php if a profile is to be pushed to the
2021-12-02 23:02:31 +00:00
* directory and the local hub in this case is any kind of directory server .
*
* @ param int $uid
* @ param bool $force
*/
public static function local_dir_update ( $uid , $force )
{
logger ( 'local_dir_update: uid: ' . $uid , LOGGER_DEBUG );
2023-07-22 12:06:41 +00:00
$valueSet = q (
2021-12-03 03:01:39 +00:00
" select channel_hash, channel_address, channel_timezone, profile.* from profile left join channel on channel_id = uid where uid = %d and is_default = 1 " ,
2021-12-02 23:02:31 +00:00
intval ( $uid )
);
2023-07-22 12:06:41 +00:00
$profile = new Profile ();
$profile -> setEncoding ( 'zot' );
if ( $valueSet ) {
$values = $valueSet [ 0 ];
$hash = $value [ 'channel_hash' ];
$profile -> setDescription ( $value [ 'pdesc' ] ? : null )
-> setBirthday ( $value [ 'dob' ] ? : null )
-> setGender ( $value [ 'gender' ] ? : null )
-> setMarital ( $value [ 'marital' ] ? : null )
-> setSexual ( $value [ 'sexual' ] ? : null )
-> setLocale ( $value [ 'locality' ] ? : null )
-> setRegion ( $value [ 'region' ] ? : null )
-> setPostcode ( $value [ 'postal_code' ]) ? : null
-> setCountry ( $value [ 'country_name' ] ? : null )
-> setAbout ( $value [ 'about' ] ? : null )
-> setHomepage ( $value [ 'homepage' ] ? : null )
-> setHometown ( $value [ 'hometown' ] ? : null );
if ( $age = age ( $value [ 'dob' ], $value [ 'channel_timezone' ], '' )) {
$profile -> setAge (( int ) $age );
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
2023-07-22 12:06:41 +00:00
if ( $value [ 'keywords' ]) {
2021-12-02 23:02:31 +00:00
$tags = [];
2023-07-22 12:06:41 +00:00
$k = explode ( ' ' , $value [ 'keywords' ]);
2021-12-03 03:01:39 +00:00
if ( $k ) {
foreach ( $k as $kk ) {
if ( trim ( $kk )) {
2021-12-02 23:02:31 +00:00
$tags [] = trim ( $kk );
2021-12-03 03:01:39 +00:00
}
}
}
2021-12-02 23:02:31 +00:00
2021-12-03 03:01:39 +00:00
if ( $tags ) {
2023-07-22 12:06:41 +00:00
$profile -> setKeywords ( $tags );
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
}
2023-07-22 12:06:41 +00:00
$hidden = ( 1 - intval ( $value [ 'publish' ]));
2021-12-02 23:02:31 +00:00
// logger('hidden: ' . $hidden);
2021-12-03 03:01:39 +00:00
$r = q (
" select xchan_hidden from xchan where xchan_hash = '%s' limit 1 " ,
2023-07-22 12:06:41 +00:00
dbesc ( $value [ 'channel_hash' ])
2021-12-02 23:02:31 +00:00
);
if ( intval ( $r [ 0 ][ 'xchan_hidden' ]) != $hidden ) {
2021-12-03 03:01:39 +00:00
$r = q (
" update xchan set xchan_hidden = %d where xchan_hash = '%s' " ,
2021-12-02 23:02:31 +00:00
intval ( $hidden ),
2023-07-22 12:06:41 +00:00
dbesc ( $value [ 'channel_hash' ])
2021-12-02 23:02:31 +00:00
);
}
2023-07-22 23:01:55 +00:00
// Caveat: for hook listeners, $profile is an instance of Code\Nomad\Profile
$arr = [ 'channel_id' => $uid , 'hash' => $hash , 'profile' => $profile ];
2022-02-12 08:50:48 +00:00
Hook :: call ( 'local_dir_update' , $arr );
2021-12-02 23:02:31 +00:00
2023-07-22 12:06:41 +00:00
$address = Channel :: get_webfinger ( $value );
2021-12-02 23:02:31 +00:00
if ( perm_is_allowed ( $uid , '' , 'view_profile' )) {
self :: import_directory_profile ( $hash , $arr [ 'profile' ], $address , 0 );
} else {
// they may have made it private
2021-12-03 03:01:39 +00:00
$r = q (
" delete from xprof where xprof_hash = '%s' " ,
2021-12-02 23:02:31 +00:00
dbesc ( $hash )
);
2021-12-03 03:01:39 +00:00
$r = q (
" delete from xtag where xtag_hash = '%s' " ,
2021-12-02 23:02:31 +00:00
dbesc ( $hash )
);
}
}
$ud_hash = random_string () . '@' . App :: get_hostname ();
2023-07-22 12:06:41 +00:00
self :: update_modtime ( $hash , $ud_hash , Channel :: get_webfinger ( $value ), (( $force ) ? UPDATE_FLAGS_FORCED : UPDATE_FLAGS_UPDATED ));
2021-12-02 23:02:31 +00:00
}
/**
* @ brief Imports a directory profile .
*
* @ param string $hash
2023-07-22 23:01:55 +00:00
* @ param Profile $nomadProfile
2021-12-02 23:02:31 +00:00
* @ param string $addr
* @ param number $ud_flags ( optional ) UPDATE_FLAGS_UPDATED
* @ param number $suppress_update ( optional ) default 0
* @ return bool $updated if something changed
*/
2023-07-22 23:01:55 +00:00
public static function import_directory_profile ( $hash , $nomadProfile , $addr , $ud_flags = UPDATE_FLAGS_UPDATED , $suppress_update = 0 )
2021-12-02 23:02:31 +00:00
{
logger ( 'import_directory_profile' , LOGGER_DEBUG );
2021-12-03 03:01:39 +00:00
if ( ! $hash ) {
2021-12-02 23:02:31 +00:00
return false ;
2021-12-03 03:01:39 +00:00
}
2023-07-22 23:01:55 +00:00
$profile = $nomadProfile -> toArray ();
2021-12-02 23:02:31 +00:00
$maxlen = get_max_import_size ();
2022-04-01 20:36:55 +00:00
if ( $maxlen && isset ( $profile [ 'about' ]) && mb_strlen ( $profile [ 'about' ]) > $maxlen ) {
2021-12-02 23:02:31 +00:00
$profile [ 'about' ] = mb_substr ( $profile [ 'about' ], 0 , $maxlen , 'UTF-8' );
}
$arr = [];
$arr [ 'xprof_hash' ] = $hash ;
2022-08-14 09:20:43 +00:00
2022-04-01 20:36:55 +00:00
$arr [ 'xprof_dob' ] = '0000-00-00' ;
2022-08-14 09:20:43 +00:00
if ( isset ( $profile [ 'birthday' ])) {
$arr [ 'xprof_dob' ] = (( $profile [ 'birthday' ] === '0000-00-00' )
? $profile [ 'birthday' ]
: datetime_convert ( '' , '' , $profile [ 'birthday' ], 'Y-m-d' )); // !!!! check this for 0000 year
}
2021-12-02 23:02:31 +00:00
$arr [ 'xprof_age' ] = ( isset ( $profile [ 'age' ]) ? intval ( $profile [ 'age' ]) : 0 );
$arr [ 'xprof_desc' ] = (( isset ( $profile [ 'description' ]) && $profile [ 'description' ]) ? htmlspecialchars ( $profile [ 'description' ], ENT_COMPAT , 'UTF-8' , false ) : '' );
$arr [ 'xprof_gender' ] = (( isset ( $profile [ 'gender' ]) && $profile [ 'gender' ]) ? htmlspecialchars ( $profile [ 'gender' ], ENT_COMPAT , 'UTF-8' , false ) : '' );
$arr [ 'xprof_marital' ] = (( isset ( $profile [ 'marital' ]) && $profile [ 'marital' ]) ? htmlspecialchars ( $profile [ 'marital' ], ENT_COMPAT , 'UTF-8' , false ) : '' );
$arr [ 'xprof_sexual' ] = (( isset ( $profile [ 'sexual' ]) && $profile [ 'sexual' ]) ? htmlspecialchars ( $profile [ 'sexual' ], ENT_COMPAT , 'UTF-8' , false ) : '' );
$arr [ 'xprof_locale' ] = (( isset ( $profile [ 'locale' ]) && $profile [ 'locale' ]) ? htmlspecialchars ( $profile [ 'locale' ], ENT_COMPAT , 'UTF-8' , false ) : '' );
$arr [ 'xprof_region' ] = (( isset ( $profile [ 'region' ]) && $profile [ 'region' ]) ? htmlspecialchars ( $profile [ 'region' ], ENT_COMPAT , 'UTF-8' , false ) : '' );
$arr [ 'xprof_postcode' ] = (( isset ( $profile [ 'postcode' ]) && $profile [ 'postcode' ]) ? htmlspecialchars ( $profile [ 'postcode' ], ENT_COMPAT , 'UTF-8' , false ) : '' );
$arr [ 'xprof_country' ] = (( isset ( $profile [ 'country' ]) && $profile [ 'country' ]) ? htmlspecialchars ( $profile [ 'country' ], ENT_COMPAT , 'UTF-8' , false ) : '' );
$arr [ 'xprof_about' ] = (( isset ( $profile [ 'about' ]) && $profile [ 'about' ]) ? htmlspecialchars ( $profile [ 'about' ], ENT_COMPAT , 'UTF-8' , false ) : '' );
$arr [ 'xprof_pronouns' ] = (( isset ( $profile [ 'pronouns' ]) && $profile [ 'pronouns' ]) ? htmlspecialchars ( $profile [ 'pronouns' ], ENT_COMPAT , 'UTF-8' , false ) : '' );
$arr [ 'xprof_homepage' ] = (( isset ( $profile [ 'homepage' ]) && $profile [ 'homepage' ]) ? htmlspecialchars ( $profile [ 'homepage' ], ENT_COMPAT , 'UTF-8' , false ) : '' );
$arr [ 'xprof_hometown' ] = (( isset ( $profile [ 'hometown' ]) && $profile [ 'hometown' ]) ? htmlspecialchars ( $profile [ 'hometown' ], ENT_COMPAT , 'UTF-8' , false ) : '' );
$clean = [];
if ( array_key_exists ( 'keywords' , $profile ) and is_array ( $profile [ 'keywords' ])) {
self :: import_directory_keywords ( $hash , $profile [ 'keywords' ]);
foreach ( $profile [ 'keywords' ] as $kw ) {
$kw = trim ( htmlspecialchars ( $kw , ENT_COMPAT , 'UTF-8' , false ));
$kw = trim ( $kw , ',' );
$clean [] = $kw ;
}
}
$arr [ 'xprof_keywords' ] = implode ( ' ' , $clean );
// Self censored, make it so
// These are not translated, so the German "erwachsenen" keyword will not censor the directory profile. Only the English form - "adult".
if ( in_arrayi ( 'nsfw' , $clean ) || in_arrayi ( 'adult' , $clean )) {
2021-12-03 03:01:39 +00:00
q (
" update xchan set xchan_selfcensored = 1 where xchan_hash = '%s' " ,
2021-12-02 23:02:31 +00:00
dbesc ( $hash )
);
}
2021-12-03 03:01:39 +00:00
$r = q (
" select * from xprof where xprof_hash = '%s' limit 1 " ,
2021-12-02 23:02:31 +00:00
dbesc ( $hash )
);
2021-12-03 03:01:39 +00:00
if ( $arr [ 'xprof_age' ] > 150 ) {
2021-12-02 23:02:31 +00:00
$arr [ 'xprof_age' ] = 150 ;
2021-12-03 03:01:39 +00:00
}
if ( $arr [ 'xprof_age' ] < 0 ) {
2021-12-02 23:02:31 +00:00
$arr [ 'xprof_age' ] = 0 ;
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
if ( $r ) {
$update = false ;
foreach ( $r [ 0 ] as $k => $v ) {
if (( array_key_exists ( $k , $arr )) && ( $arr [ $k ] != $v )) {
logger ( 'import_directory_profile: update ' . $k . ' => ' . $arr [ $k ]);
$update = true ;
break ;
}
}
if ( $update ) {
2022-06-24 01:03:49 +00:00
update_table_from_array ( 'xprof' , $arr , " xprof_hash = ' " . dbesc ( $arr [ 'xprof_hash' ]) . " ' " );
2021-12-02 23:02:31 +00:00
}
} else {
$update = true ;
logger ( 'New profile' );
2022-06-24 01:03:49 +00:00
create_table_from_array ( 'xprof' , $arr );
}
2021-12-02 23:02:31 +00:00
$d = [
'xprof' => $arr ,
'profile' => $profile ,
'update' => $update
];
/**
* @ hooks import_directory_profile
* Called when processing delivery of a profile structure from an external source ( usually for directory storage ) .
* * \e array \b xprof
* * \e array \b profile
* * \e boolean \b update
*/
2022-02-12 08:50:48 +00:00
Hook :: call ( 'import_directory_profile' , $d );
2021-12-02 23:02:31 +00:00
if (( $d [ 'update' ]) && ( ! $suppress_update )) {
self :: update_modtime ( $arr [ 'xprof_hash' ], new_uuid (), $addr , $ud_flags );
}
2021-12-03 03:01:39 +00:00
q (
" update xchan set xchan_updated = '%s' where xchan_hash = '%s' " ,
2021-12-02 23:02:31 +00:00
dbesc ( datetime_convert ()),
dbesc ( $arr [ 'xprof_hash' ])
);
return $d [ 'update' ];
}
/**
* @ brief
*
* @ param string $hash An xtag_hash
* @ param array $keywords
*/
public static function import_directory_keywords ( $hash , $keywords )
{
$existing = [];
2021-12-03 03:01:39 +00:00
$r = q (
" select * from xtag where xtag_hash = '%s' and xtag_flags = 0 " ,
2021-12-02 23:02:31 +00:00
dbesc ( $hash )
);
if ( $r ) {
2021-12-03 03:01:39 +00:00
foreach ( $r as $rr ) {
2021-12-02 23:02:31 +00:00
$existing [] = $rr [ 'xtag_term' ];
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
}
$clean = [];
foreach ( $keywords as $kw ) {
$kw = trim ( htmlspecialchars ( $kw , ENT_COMPAT , 'UTF-8' , false ));
$kw = trim ( $kw , ',' );
$clean [] = $kw ;
}
foreach ( $existing as $x ) {
2021-12-03 03:01:39 +00:00
if ( ! in_array ( $x , $clean )) {
$r = q (
" delete from xtag where xtag_hash = '%s' and xtag_term = '%s' and xtag_flags = 0 " ,
2021-12-02 23:02:31 +00:00
dbesc ( $hash ),
dbesc ( $x )
);
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
}
foreach ( $clean as $x ) {
if ( ! in_array ( $x , $existing )) {
2021-12-03 03:01:39 +00:00
$r = q (
" insert into xtag ( xtag_hash, xtag_term, xtag_flags) values ( '%s' ,'%s', 0 ) " ,
2021-12-02 23:02:31 +00:00
dbesc ( $hash ),
dbesc ( $x )
);
}
}
}
/**
* @ brief
*
* @ param string $hash
* @ param string $guid
* @ param string $addr
* @ param int $flags ( optional ) default 0
*/
public static function update_modtime ( $hash , $guid , $addr , $flags = 0 )
{
$dirmode = intval ( get_config ( 'system' , 'directory_mode' ));
2021-12-03 03:01:39 +00:00
if ( $dirmode == DIRECTORY_MODE_NORMAL ) {
2021-12-02 23:02:31 +00:00
return ;
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
if ( $flags ) {
2021-12-03 03:01:39 +00:00
q (
" insert into updates (ud_hash, ud_guid, ud_date, ud_flags, ud_addr ) values ( '%s', '%s', '%s', %d, '%s' ) " ,
2021-12-02 23:02:31 +00:00
dbesc ( $hash ),
dbesc ( $guid ),
dbesc ( datetime_convert ()),
intval ( $flags ),
dbesc ( $addr )
);
} else {
2021-12-03 03:01:39 +00:00
q (
" update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and (ud_flags & %d) = 0 " ,
2021-12-02 23:02:31 +00:00
intval ( UPDATE_FLAGS_UPDATED ),
dbesc ( $addr ),
intval ( UPDATE_FLAGS_UPDATED )
);
}
}
2021-12-03 03:01:39 +00:00
}