Check if license can be activated on a given number of production and localhost sites.

@author Vova Feldman (@svovaf)
@since  2.0.0

@param int $production_count
@param int $localhost_count

@return bool
10801
function can_activate_bulk( $production_count, $localhost_count ) {
            if ( $this->is_unlimited() ) {
                return true;
            }

            /**
             * For simplicity, the logic will work as following: when given X sites to activate the license on, if it's
             * possible to activate on ALL of them, do the activation. If it's not possible to activate on ALL of them,
             * do NOT activate on any of them.
             */
            return ( $this->quota >= $this->activated + $production_count + ( $this->is_free_localhost ? 0 : $this->activated_local + $localhost_count ) );
        }
407105
private function checkHosts():bool
    {
        if (null === $this->config) {
            return (true);
        }
        $current_env = FEnv::get("framework.env");
        $ip = ToolsExceptions::getClientIp();
        $result = true;
        if ("dev" === $current_env) {
            if (property_exists($this->config, "hosts_denied_dev")) {
                $dd = $this->config->hosts_denied_dev;
                if (null !== $dd) {
                    if (false != in_array("*", $dd)) {
                        $result = false;
                    } elseif (false != in_array($ip, $dd)) {
                        $result = false;
                    }
                }
            }
            if (property_exists($this->config, "hosts_allowed_dev")) {
                $dd = $this->config->hosts_allowed_dev;
                if (null !== $dd) {
                    if (true == in_array("*", $dd) && $result) {
                        $result = true;
                    } elseif (true === in_array($ip, $dd) && false === $result) {
                        $result = true;
                    }
                }
            }
        } elseif ("prod" === $current_env) {
            if (property_exists($this->config, "hosts_denied_prod")) {
                $dd = $this->config->hosts_denied_prod;
                if (null !== $dd) {
                    if (false != in_array("*", $dd)) {
                        $result = false;
                    } elseif (false != in_array($ip, $dd)) {
                        $result = false;
                    }
                }
            }
            if (property_exists($this->config, "hosts_allowed_prod")) {
                $dd = $this->config->hosts_allowed_prod;
                if (null !== $dd) {
                    if (true == in_array("*", $dd) && $result) {
                        $result = true;
                    } elseif (true === in_array($ip, $dd) && false === $result) {
                        $result = true;
                    }
                }
            }
        }

        if (false === $result) {
            throw new Server403(new \ArrayObject(array("solution" =>
                "Add the current host to the allowed hosts list")));
        }

        return (true);
    }
535552
function is_site_activation_mode( $and_on = true ) {
            return (
                ( $this->is_on() || ! $and_on ) &&
                ( $this->is_premium() && true === $this->_storage->require_license_activation ) ||
                (
                    ( ! $this->is_registered() ||
                      ( $this->is_only_premium() && ! $this->has_features_enabled_license() ) ) &&
                    ( ! $this->is_enable_anonymous() ||
                      ( ! $this->is_anonymous() && ! $this->is_pending_activation() ) )
                )
            );
        }
73199
protected function isEnabled()
    {
        // At least one redirect must be enabled
        if (!$this->getForceWWW() && !$this->getForceSSL()) {
            return false;
        }

        // Filter by env vars
        $enabledEnvs = $this->getEnabledEnvs();
        if (is_bool($enabledEnvs)) {
            return $enabledEnvs;
        }

        // If CLI, EnabledEnvs must contain CLI
        if (Director::is_cli() && !in_array('cli', $enabledEnvs)) {
            return false;
        }

        // Check other envs
        return empty($enabledEnvs) || in_array(Director::get_environment_type(), $enabledEnvs);
    }
505890
function has_active_license() {
            return (
                is_object( $this->_license ) &&
                is_numeric( $this->_license->id ) &&
                ! $this->_license->is_expired()
            );
        }
601168
protected function canQueueSelectedSite()
    {
        if ($this->selectedSite === null) {
            return false;
        }
        $enabledIndexQueueConfigurationNames = $this->selectedSite->getSolrConfiguration()->getEnabledIndexQueueConfigurationNames();
        if (empty($enabledIndexQueueConfigurationNames)) {
            return false;
        }
        return true;
    }
1250011
public function isHostAllowed($allowedHosts)
    {
        $currentHost = $this->request->hostName;
        
        $rules = (array) $allowedHosts;
        
        foreach ($rules as $allowedHost) {
            if (StringHelper::matchWildcard($allowedHost, $currentHost)) {
                return true;
            }
        }
        
        return false;
    }
1180115
private function getProducerCount($each_studio)
    {
        $count = $each_studio->plaintext;
        preg_match('/\([0-9,]+\)/', $count, $cnt);
        $count = substr($cnt[0], 1, strlen($cnt[0]) - 2);

        return str_replace(',', '', $count);
    }
1323051
public function checkActivationStatus()
    {
        if (true == $this->builder->conf['restful']) {
            $path = ltrim(parse_url($this->url(), PHP_URL_PATH), '/');
            $rpath = ltrim(parse_url(Request::path(), PHP_URL_PATH), '/');

            if ($this->builder->conf['rest_base']) {
                $base = (is_array($this->builder->conf['rest_base'])) ? implode('|', $this->builder->conf['rest_base']) : $this->builder->conf['rest_base'];

                list($path, $rpath) = preg_replace('@^('.$base.')/@', '', [$path, $rpath], 1);
            }

            if (preg_match("@^{$path}(/.+)?\z@", $rpath)) {
                $this->activate();
            }
        } else {
            // We should consider a $strict config. If $strict then only match against fullURL.
            if ($this->url() == Request::url() || $this->url() == Request::fullUrl()) {
                $this->activate();
            }
        }
    }
7093
public function hitLimits($region, $count = 1)
	{
		foreach ($this->limits as $limit)
		{
			if ($limit->getRegion() == $region &&
				! $limit->hit($count)
			)
			{
				return false;
			}
		}

		return true;
	}
595177
public function isLocal() : bool
    {
        $host = parse_url($this->file, PHP_URL_HOST);

        // If it has not an url host
        if ($host === null) {
            // Is the string a file_id?
            if (preg_match('/^([\w\d]*[-_]*[\w\d]*)*$/', $this->file)) {
                // It is a file_id
                return false;
            }
            // It is local
            return true;
        }
            // It is an url
            return false;
    }
990495
private function is_network_level_site_specific_action() {
            if ( ! $this->_is_network_active ) {
                return false;
            }

            if ( ! fs_is_network_admin() ) {
                return false;
            }

            $blog_id = fs_request_get( 'blog_id', '' );

            return is_numeric( $blog_id ) ? $blog_id : false;
        }
357120
public function canModify()
    {
        if ( ! $this->getEnabledList()
                    ->canModify() )
        {
            return false;
        }

        $modules = $this->getModuleManager()
                        ->getModules();

        if ( ! in_array( 'Grid\MultisitePlatform', $modules ) )
        {
            return true;
        }

        return in_array( 'Grid\MultisiteCentral', $modules );
    }
846843
public function check_activation() {
		$license_data = get_option( $this->product->get_key() . '_license_data', '' );
		if ( '' === $license_data ) {
			return false;
		}

		return isset( $license_data->error ) ? ( 'no_activations_left' == $license_data->error ) : false;

	}
49881
@POST
    @Produces({MediaType.TEXT_HTML, MediaType.APPLICATION_JSON})
    @Path("/{name}")
    public Response approve(@Auth final DbCredential credential, @PathParam("name") final String name, @QueryParam(ServerAPI.APPROVED_PARAM) final BooleanParam approved){
        if(!credential.getRoles().contains(AvailableRoles.LICENSE_CHECKER)){
            throw new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED).build());
        }

        LOG.info("Got a get license request.");

        if(approved == null){
            return Response.serverError().status(HttpStatus.NOT_ACCEPTABLE_406).build();
        }

        getLicenseHandler().approveLicense(name, approved.get());
        cacheUtils.clear(CacheName.PROMOTION_REPORTS);
        return Response.ok("done").build();
    }
486389
protected function _activate_license( $background = false ) {
            $this->_logger->entrance();

            $license_id = fs_request_get( 'license_id' );

            if ( is_object( $this->_site ) &&
                 FS_Plugin_License::is_valid_id( $license_id ) &&
                 $license_id == $this->_site->license_id
            ) {
                // License is already activated.
                return;
            }

            $premium_license = FS_Plugin_License::is_valid_id( $license_id ) ?
                $this->_get_license_by_id( $license_id ) :
                $this->_get_available_premium_license();

            if ( ! is_object( $premium_license ) ) {
                return;
            }

            if ( ! is_object( $this->_site ) ) {
                // Not yet opted-in.
                $user = $this->get_current_or_network_user();
                if ( ! is_object( $user ) ) {
                    $user = self::_get_user_by_id( $premium_license->user_id );
                }

                if ( is_object( $user ) ) {
                    $this->install_with_user( $user, $premium_license->secret_key, false, false, false );
                } else {
                    $this->opt_in(
                        false,
                        false,
                        false,
                        $premium_license->secret_key
                    );

                    return;
                }
            }


            /**
             * If the premium license is already associated with the install, just
             * update the license reference (activation is not required).
             *
             * @since 1.1.9
             */
            if ( $premium_license->id == $this->_site->license_id ) {
                // License is already activated.
                $this->_update_site_license( $premium_license );
                $this->_store_account();

                return;
            }

            if ( $this->_site->user_id != $premium_license->user_id ) {
                $api_request_params = array( 'license_key' => $premium_license->secret_key );
            } else {
                $api_request_params = array();
            }

            $api     = $this->get_api_site_scope();
            $license = $api->call( "/licenses/{$premium_license->id}.json", 'put', $api_request_params );

            if ( ! $this->is_api_result_entity( $license ) ) {
                if ( ! $background ) {
                    $this->_admin_notices->add( sprintf(
                        '%s %s',
                        $this->get_text_inline( 'It looks like the license could not be activated.', 'license-activation-failed-message' ),
                        ( is_object( $license ) && isset( $license->error ) ?
                            $license->error->message :
                            sprintf( '%s<br><code>%s</code>',
                                $this->get_text_inline( 'Error received from the server:', 'server-error-message' ),
                                var_export( $license, true )
                            )
                        )
                    ),
                        $this->get_text_x_inline( 'Hmm', 'something somebody says when they are thinking about what you have just said.', 'hmm' ) . '...',
                        'error'
                    );
                }

                return;
            }

            $premium_license = new FS_Plugin_License( $license );

            // Updated site plan.
            $site = $this->get_api_site_scope()->get( '/', true );
            if ( $this->is_api_result_entity( $site ) ) {
                $this->_site = new FS_Site( $site );
            }
            $this->_update_site_license( $premium_license );

            $this->_store_account();

            if ( ! $background ) {
                $this->_admin_notices->add_sticky(
                    $this->get_text_inline( 'Your license was successfully activated.', 'license-activated-message' ) .
                    $this->get_complete_upgrade_instructions(),
                    'license_activated',
                    $this->get_text_x_inline( 'Yee-haw', 'interjection expressing joy or exuberance', 'yee-haw' ) . '!'
                );
            }

            $this->_admin_notices->remove_sticky( array(
                'trial_promotion',
                'license_expired',
            ) );
        }
594210
public function isRegistrationEnabled()
    {
        if (false === $xml = simplexml_load_string($this->get_prefs())) {
            return false;
        }

        $element = $xml->xpath('/baseprefs/caninscript');

        if (count($element) === 0) {
            return $this->databox->isRegistrationEnabled();
        }

        foreach ($element as $caninscript) {
            if (false !== (bool)(string)$caninscript) {
                return true;
            }
        }

        return false;
    }