@author Leo Fajardo (@leorw)

@param bool|null $use_network_level_storage

@return bool
960722
private function should_send_keepalive_update( $use_network_level_storage = null ) {
            $keepalive_timestamp = $this->_storage->get( 'keepalive_timestamp', 0, $use_network_level_storage );

            if ( $keepalive_timestamp < ( time() - WP_FS__TIME_WEEK_IN_SEC ) ) {
                // If updated more than 7 days ago, trigger a keepalive and update the time it was triggered.
                return true;
            } else {
                // If updated 7 days ago or less, "flip a coin", if the value is 7 trigger a keepalive and update the last time it was triggered.
                return ( 7 == rand( 1, 7 ) );
            }
        }
378861
private function can_delete( $network ) {

		// Bail if main network.
		if ( is_main_network( $network->id ) ) {
			return false;
		}

		// Bail if current network.
		if ( get_current_network_id() === $network->id ) {
			return false;
		}

		return current_user_can( 'delete_network', $network->id );
	}
84296
function migrate_to_network() {
            if ( ! $this->_is_multisite ) {
                return;
            }

            $updated = false;

            if ( ! isset( self::$_NETWORK_OPTIONS_MAP ) ) {
                self::load_network_options_map();
            }

            foreach ( self::$_NETWORK_OPTIONS_MAP as $option => $storage_level ) {
                if ( ! $this->is_multisite_option( $option ) ) {
                    continue;
                }

                if ( isset( $this->_storage->{$option} ) && ! isset( $this->_network_storage->{$option} ) ) {
                    // Migrate option to the network storage.
                    $this->_network_storage->store( $option, $this->_storage->{$option}, false );

                    /**
                     * Remove the option from site level storage.
                     *
                     * IMPORTANT:
                     *      The line below is intentionally commented since we want to preserve the option
                     *      on the site storage level for "downgrade compatibility". Basically, if the user
                     *      will downgrade to an older version of the plugin with the prev storage structure,
                     *      it will continue working.
                     *
                     * @todo After a few releases we can remove this.
                     */
//                    $this->_storage->remove($option, false);

                    $updated = true;
                }
            }

            if ( ! $updated ) {
                return;
            }

            // Update network level storage.
            $this->_network_storage->save();
//            $this->_storage->save();
        }
704899
public function checkIpIsVietnamobile($use_ha_proxy = FALSE)
    {
        try {
            $network = Repository\DataRepository::getData('vn_telco_ip_gateway');
            if ($this->useFullGateway === TRUE) {
                // $this->debug->debug(__FUNCTION__, 'Use Full List IP Gateway');
                $network = Repository\DataRepository::getData('vn_telco_ip_gateway_full_list');
            }
            // $this->debug->debug(__FUNCTION__, 'Network: ' . json_encode($network));
            $ipObject = new Ip($this->options);
            $ipObject->setHaProxy($use_ha_proxy);
            $currentIp = $ipObject->getIpAddress();
            $this->debug->info(__FUNCTION__, 'currentIp' . json_encode($currentIp));
            if ($currentIp === FALSE || $currentIp === NULL) {
                $this->debug->error(__FUNCTION__, 'IP Invalid');

                return FALSE;
            }
            if (strpos(',', $currentIp)) {
                $listConnectIp = explode(',', $currentIp);
            } else {
                $listConnectIp = [$currentIp];
            }
            $networkV4Range = $network[self::VIETNAMOBILE]['network_range'];
            $networkV6Range = $network[self::VIETNAMOBILE]['network_v6_range'];
//            $this->debug->debug(__FUNCTION__, 'networkV4Range => ' . json_encode($networkV4Range));
//            $this->debug->debug(__FUNCTION__, 'networkV6Range => ' . json_encode($networkV6Range));
            foreach ($listConnectIp as $IP) {
                if (empty(trim($IP)) || $IP == FALSE) {
                    return FALSE;
                }
                if (is_array($networkV4Range) && count($networkV4Range) > 0) {
                    foreach ($networkV4Range as $rangeV4) {
                        $rangeV4 = trim($rangeV4);
                        if (empty($rangeV4)) {
                            return FALSE;
                        } else {
                            $checkIpInRange = $ipObject->ipInRange(trim($IP), trim($rangeV4));
                            if ($checkIpInRange === TRUE) {
                                return TRUE;
                            }
                        }
                    }
                }
                if (is_array($networkV6Range) && count($networkV6Range) > 0 && $ipObject->ipValidateV6($IP)) {
                    foreach ($networkV6Range as $rangeV6) {
                        $rangeV6 = trim($rangeV6);
                        if (empty($rangeV6)) {
                            return FALSE;
                        } else {
                            $checkIpInRange = $ipObject->ipInRange(trim($IP), trim($rangeV6));
                            if ($checkIpInRange === TRUE) {
                                return TRUE;
                            }
                        }
                    }
                }
            }

            return FALSE;
        }
        catch (\Exception $e) {
            $message = 'Error File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Code: ' . $e->getCode() . ' - Message: ' . $e->getMessage();
            $this->debug->error(__FUNCTION__, $message);

            return NULL;
        }
    }
276629
public function Caching($Caching = NULL) {
      if (!is_null($Caching))
         $this->UseCaching = (bool)$Caching;
      return $this->UseCaching;
   }
288276
public function isStorageOk()
    {

        $storage = storage_path() . '/sde/' . $this->json->version . '/';
        $this->info('Storage path is: ' . $storage);

        if (File::isWritable(storage_path())) {

            // Check that the path exists
            if (! File::exists($storage))
                File::makeDirectory($storage, 0755, true);

            // Set the storage path
            $this->storage_path = $storage;

            return true;

        }

        return false;
    }
618905
public function exists($storage_name, $key = null)
    {
        // No app found = false
        if (!isset($this->storage[$storage_name])) {
            return false;
        }

        // app found and no key requested? true
        if (!isset($key)) {
            return true;
        }

        // key requested and found? true
        return isset($this->storage[$storage_name]->{$key}) && !empty($this->storage[$storage_name]->{$key});
    }
205919
protected function checkStoragePermission()
    {
        Session::checkServicePermission(
            Verbs::POST, $this->storageService, trim($this->storageFolder, '/'), Session::getRequestor()
        );
    }
728725
public static function hasLevel(int $level=null) :bool {
		// if we have said level
		return self::$_account ? 
			self::getAccount()->hasLevel($level) : false;
	}
602239
public function is($mode, $nick, $chan)
    {
        $userMode = $this->storage->getUserMode($nick, $chan);

        if ($userMode) {
            return ($userMode & $mode) != 0;
        } else {
            return false;
        }
    }
105614
public function save($cascade = null, $use_transaction = false)
	{
		if ($this->frozen())
		{
			return false;
		}

		if ($use_transaction)
		{
			$db = \Database_Connection::instance(static::connection(true));
			$db->start_transaction();
		}

		try
		{
			$this->observe('before_save');

			$this->freeze();
			foreach($this->relations() as $rel_name => $rel)
			{
				if (array_key_exists($rel_name, $this->_reset_relations))
				{
					if (method_exists($rel, 'delete_related'))
					{
						$rel->delete_related($this);
						$this->_original_relations[$rel_name] = $rel->singular ? null : array();
					}
					else
					{
						if (empty($this->_original_relations[$rel_name]))
						{
							$data = $rel->get($this);
							if (is_array($data))
							{
								$this->_original_relations[$rel_name] = array();
								foreach ($data as $obj)
								{
									$this->_original_relations[$rel_name][] = $obj ? $obj->implode_pk($obj) : null;
								}
							}
							else
							{
								$this->_original_relations[$rel_name] = $data ? $data->implode_pk($data) : null;
							}
						}
					}
					unset($this->_reset_relations[$rel_name]);
				}
				if (array_key_exists($rel_name, $this->_data_relations))
				{
					$rel->save($this, $this->{$rel_name},
						array_key_exists($rel_name, $this->_original_relations) ? $this->_original_relations[$rel_name] : null,
						false, is_array($cascade) ? in_array($rel_name, $cascade) : $cascade
					);
				}
			}
			$this->unfreeze();

			// Insert or update
			$return = $this->_is_new ? $this->create() : $this->update();

			$this->freeze();
			foreach($this->relations() as $rel_name => $rel)
			{
				if (array_key_exists($rel_name, $this->_data_relations))
				{
					$rel->save($this, $this->{$rel_name},
						array_key_exists($rel_name, $this->_original_relations) ? $this->_original_relations[$rel_name] : null,
						true, is_array($cascade) ? in_array($rel_name, $cascade) : $cascade
					);
				}
			}
			$this->unfreeze();

			$this->_update_original();

			$this->observe('after_save');

			$use_transaction and $db->commit_transaction();
		}
		catch (\Exception $e)
		{
			$use_transaction and $db->rollback_transaction();
			throw $e;
		}

		return $return;
	}
47675
public function canDisplayIsSourced($access_level = null){
		if(!$this->gedcomrecord->canShow($access_level)) return false;
		if($access_level === null )
		    $access_level = \Fisharebest\Webtrees\Auth::accessLevel($this->gedcomrecord->getTree());

		$global_facts = Globals::getGlobalFacts();
		if (isset($global_facts['SOUR'])) {
			return $global_facts['SOUR'] >= $access_level;
		}

		return true;
	}
435029
public function rollBack($levels = null): bool
    {
        $this->__tRollBack($levels);
        if(null === $levels)
        {
            return $this->instance->rollback();
        }
        else
        {
            $this->exec('ROLLBACK TO P' . ($this->getTransactionLevels()));
            return true;
        }
    }
813190
public function close()
    {
        if ($this->closed) {
            return false;
        }
        $this->closed = true;
        if ($this->fdCacheKey !== null) {
            FileSystem::$fdCache->invalidate($this->fdCacheKey);
        }
        if ($this->fd === null) {
            return false;
        }

        if (!FileSystem::$supported) {
            fclose($this->fd);
            return false;
        }
        $r = eio_close($this->fd, EIO_PRI_MAX);
        $this->fd = null;
        return $r;
    }
3662
function clear( $network_level_or_blog_id = null, $flush = false ) {
            if ( ! $this->_is_multisite ||
                 false === $network_level_or_blog_id ||
                 is_null( $network_level_or_blog_id ) ||
                 is_numeric( $network_level_or_blog_id )
            ) {
                $site_options = $this->get_site_options( $network_level_or_blog_id );
                $site_options->clear( $flush );
            }

            if ( $this->_is_multisite &&
                 ( true === $network_level_or_blog_id || is_null( $network_level_or_blog_id ) )
            ) {
                $this->_network_options->clear( $flush );
            }
        }
319052
public function useCache()
    {
        if (is_callable($this->get_cache_callback)
            && is_callable($this->set_cache_callback)
            && is_callable($this->delete_cache_callback)) {
            return true;
        }

        return false;
    }
256663
public function has($name, $checkAbstractFactories = true, $usePeeringServiceManagers = false)
    {
        if (is_string($name) && $this->container->has($name)) {
            return true;
        } elseif (parent::has($name, $checkAbstractFactories, $usePeeringServiceManagers)) {
            return true;
        }

        return false;
    }