Is the plugin ready to be used?.

@return bool|string Returns true on success, a string detailing the error otherwise
492404
public function is_ready() {
        if (empty($this->pathtopython)) {
            $settingurl = new \moodle_url('/admin/settings.php', array('section' => 'systempaths'));
            return get_string('pythonpathnotdefined', 'mlbackend_python', $settingurl->out());
        }

        // Check the installed pip package version.
        $cmd = "{$this->pathtopython} -m moodlemlbackend.version";

        $output = null;
        $exitcode = null;
        // Execute it sending the standard error to $output.
        $result = exec($cmd . ' 2>&1', $output, $exitcode);

        $vercheck = self::check_pip_package_version($result);

        if ($vercheck === 0) {
            return true;
        }

        if ($exitcode != 0) {
            return get_string('pythonpackagenotinstalled', 'mlbackend_python', $cmd);
        }

        if ($result) {
            $a = [
                'installed' => $result,
                'required' => self::REQUIRED_PIP_PACKAGE_VERSION,
            ];

            if ($vercheck < 0) {
                return get_string('packageinstalledshouldbe', 'mlbackend_python', $a);

            } else if ($vercheck > 0) {
                return get_string('packageinstalledtoohigh', 'mlbackend_python', $a);
            }
        }

        return get_string('pythonpackagenotinstalled', 'mlbackend_python', $cmd);
    }
295710
public function isValid() {
		
		$params = $this -> getParameters();
		$file 	= $this -> getFile();

		if(false === isset($params[0])) {
			return trigger_error(sprintf('Missing argument 1 for %s', __METHOD__), E_USER_ERROR);
		}

		if(false === ('-' . intval($params[0]) == '-' . $params[0])) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($params[0])), E_USER_ERROR);
		}

		if(false === isset($params[1])) {
			return trigger_error(sprintf('Missing argument 2 for %s', __METHOD__), E_USER_ERROR);
		}

		if(false === ('-' . intval($params[1]) == '-' . $params[1])) {
			return trigger_error(sprintf('Argument 2 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($params[1])), E_USER_ERROR);
		}

		$size = @filesize($file['tmp_name']);

		if(true === is_int($size)) {

			if($size >= $params[0] && $size <= $params[1]) {
				return true;
			}
		}

		return false;
	}
32692
public function isSupported()
    {
        $mixer   = $this->getMixer();
        $request = $mixer->getRequest();

        // Support HTML GET requests and also form submits (so we can render errors on POST)
        if(($request->isFormSubmit() || $request->isGet()) && $request->getFormat() == 'html' && !$request->isAjax()) {
            return parent::isSupported();
        }

        return false;
    }
1289580
protected function maybeCheck()
    {
        if ($this->checked) {
            return; // Done.
        }
        $this->checked = true;

        if (!$this->App->Config->§conflicts['§plugins']
            && !$this->App->Config->§conflicts['§themes']) {
            return; // Nothing to do; we can stop here.
        }
        if (($is_front_or_ajax = !$this->Wp->is_admin || $this->c::isAjax())
                && $this->lastOkTime() > $this->outdated_check_time) {
            return; // Had a successfull check recently.
        }
        $all_active_plugin_slugs     = $this->s::allActivePlugins();
        $network_active_plugin_slugs = $this->Wp->is_multisite ? $this->s::networkActivePlugins() : [];
        $all_active_theme_slugs      = array_unique([$this->Wp->template, $this->Wp->stylesheet]);

        $conflicting_plugin_slugs   = array_keys($this->App->Config->§conflicts['§plugins']);
        $conflicting_theme_slugs    = array_keys($this->App->Config->§conflicts['§themes']);
        $deactivatable_plugin_slugs = array_keys($this->App->Config->§conflicts['§deactivatable_plugins']);

        foreach ($all_active_plugin_slugs as $_active_plugin_basename => $_active_plugin_slug) {
            if ($_active_plugin_slug === $this->App->base_dir_basename && $this->App->Config->§specs['§type'] === 'plugin') {
                continue; // Sanity check. Cannot depend on self of the same type.
            } elseif (!in_array($_active_plugin_slug, $conflicting_plugin_slugs, true)) {
                continue; // Not a conflicting plugin.
            }
            $_conflicting_plugin_basename = &$_active_plugin_basename;
            $_conflicting_plugin_slug     = &$_active_plugin_slug;

            if ($this->Wp->is_admin && !defined('WP_UNINSTALL_PLUGIN') && in_array($_conflicting_plugin_slug, $deactivatable_plugin_slugs, true)
                && (!$this->Wp->is_multisite || !in_array($_conflicting_plugin_slug, $network_active_plugin_slugs, true))) {
                // ↑ Note that we do not deactivate network-wide plugins, as that could impact other sites.

                // Add it to the deactivatable array and enqueue automatic deactivation of this plugin.
                $this->deactivatable_plugins[$_conflicting_plugin_slug] = $this->App->Config->§conflicts['§deactivatable_plugins'][$_conflicting_plugin_slug];

                add_action('admin_init', function () use ($_conflicting_plugin_basename) {
                    deactivate_plugins($_conflicting_plugin_basename, false, false);
                }, -10000); // With a very early priority.
            } else {
                $this->plugins[$_conflicting_plugin_slug] = $this->App->Config->§conflicts['§plugins'][$_conflicting_plugin_slug];
            }
        } // unset($_active_plugin_basename, $_active_plugin_slug, $_conflicting_plugin_basename, $_conflicting_plugin_slug);

        foreach ($all_active_theme_slugs as $_active_theme_slug) { // Note that one of these could be empty.
            if ($_active_theme_slug === $this->App->base_dir_basename && $this->App->Config->§specs['§type'] === 'theme') {
                continue; // Sanity check. Cannot depend on self of the same type.
            }
            if ($_active_theme_slug && $conflicting_theme_slugs && in_array($_active_theme_slug, $conflicting_theme_slugs, true)) {
                $_conflicting_theme_slug                = &$_active_theme_slug;
                $this->themes[$_conflicting_theme_slug] = $this->App->Config->§conflicts['§themes'][$_conflicting_theme_slug];
            }
        } // unset($_active_theme_slug, $_conflicting_theme_slug); // Housekeeping.

        $conflicts_exist = $this->exist(); // Conflicts exist?

        if ($is_front_or_ajax && !$conflicts_exist) {
            $this->lastOkTime(time());
        } elseif ($conflicts_exist) {
            $this->lastOkTime(0);
            $this->maybeNotify();
        }
    }
630815
public function validate()
	{
		try
		{
			Yaml\Yaml::parse($this->data);

		} catch(\Exception $e)
		{
			return false;
		}

		return true;
	}
1164893
public function isPreparedStatementUsed()
    {
        if ($this->executeMode === self::QUERY_MODE_AUTO) {
            // Mysqli doesn't support client side prepared statement emulation
            if ($this->getAdapter()->getDriver() instanceof ZendMysqliDriver) {
                return false;
            }

            // By default, we use PDO prepared statement emulation
            return true;
        }

        if ($this->executeMode === self::QUERY_MODE_PREPARED) {
            return true;
        }

        return false;
    }
1190906
protected function prepare(): bool
    {
        if ($this->processTitle && 'Darwin' !== \PHP_OS) {
            if (\function_exists('cli_set_process_title')) {
                \cli_set_process_title($this->processTitle);
            } elseif (\function_exists('setproctitle')) {
                \setproctitle($this->processTitle);
            }

            if ($error = \error_get_last()) {
                throw new \RuntimeException($error['message']);
            }
        }

        return $this->validateInput();
    }
259285
public function isValid() {
		
		$params = $this -> getParameters();
		$file 	= $this -> getFile();

		if(false === isset($params[0])) {
			return trigger_error(sprintf('Missing argument 1 for %s', __METHOD__), E_USER_ERROR);
		}

		if(false === ('-' . intval($params[0]) == '-' . $params[0])) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($params[0])), E_USER_ERROR);
		}

		$dimensions = @getimagesize($file['tmp_name']);

		if(true === is_array($dimensions)) {

			if($dimensions[0] >= $params[0]) {
				return true;
			}
		}

		return false;
	}
1239734
public function isValid()
    {
        $response = call_user_func_array($this->userFunction, array(
            &$this->field
        ));

        if ($response === true) {
            return true;
        }

        if (is_string($response)) {
            $this->setErrorMessage($response);
        }

        return false;
    }
150489
public function process()
    {

        if ($this->plugin->request()->has('_flush')) {

            if ($this->flushCache($this->plugin->request()->get('_flush'))) {

                $this->attributes['alertClass'] = 'success';
                $this->attributes['messages'] = array(
                    '&#10004; ' . $this->plugin->config()->get('plugin.namespace') . ' ' . ucwords($this->plugin->request()->get('_flush')) . ' flushed successfully.'
                );
                //Refresh Data
            } else {

                $this->attributes['alertClass'] = 'error';
                $this->attributes['messages'] = array(
                    '&#9888; ' . $this->plugin->config()->get('plugin.namespace') . ' ' . ucwords($this->plugin->request()->get('_flush'))
                    .' could not be flushed.  The file(s) may not exist; If they exist, check directory structure, permissions and config paths.'
                );
            }

            $this->data();
        }

    }
271129
protected function validate_files_layout() {

        if (!is_array($this->extractfiles) or count($this->extractfiles) < 4) {
            // We need the English language pack with the name of the plugin at least.
            $this->add_message(self::ERROR, 'filesnumber');
            return false;
        }

        foreach ($this->extractfiles as $filerelname => $filestatus) {
            if ($filestatus !== true) {
                $this->add_message(self::ERROR, 'filestatus', array('file' => $filerelname, 'status' => $filestatus));
                return false;
            }
        }

        foreach (array_keys($this->extractfiles) as $filerelname) {
            if (!file_exists($this->extractdir.'/'.$filerelname)) {
                $this->add_message(self::ERROR, 'filenotexists', array('file' => $filerelname));
                return false;
            }
        }

        foreach (array_keys($this->extractfiles) as $filerelname) {
            $matches = array();
            if (!preg_match("#^([^/]+)/#", $filerelname, $matches)
                    or (!is_null($this->rootdir) and $this->rootdir !== $matches[1])) {
                $this->add_message(self::ERROR, 'onedir');
                return false;
            }
            $this->rootdir = $matches[1];
        }

        if ($this->rootdir !== clean_param($this->rootdir, PARAM_PLUGIN)) {
            $this->add_message(self::ERROR, 'rootdirinvalid', $this->rootdir);
            return false;
        } else {
            $this->add_message(self::INFO, 'rootdir', $this->rootdir);
        }

        return is_dir($this->extractdir.'/'.$this->rootdir);
    }
949762
public static function isPluginAvailable($plugin)
    {
        $plugin = ucfirst($plugin);
        $dirs = self::path(self::get('atomik.dirs.plugins'));
        if (self::findFile("$plugin.php", $dirs) === false) {
            return self::findFile($plugin, $dirs) !== false;
        }
        return true;
    }
176826
public function isValid() {

		$params = $this -> getParameters();

		if(false === isset($params[0])) {
			return trigger_error(sprintf('Missing argument 1 for %s', __METHOD__), E_USER_ERROR);
		}

		if(false === is_string($params[0])) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($params[0])), E_USER_ERROR);
		}

		foreach($this -> getValues() as $fieldname => $value) {

			if($fieldname == $params[0]) {
				return $value == $this -> getValue();
			}
		}

		return true;
	}
227876
function validate() {

		// Is this an ODT?
		if ( ! $this->isOdt( $this->outputPath ) ) {

			$this->logError( \Pressbooks\Utility\get_contents( $this->logfile ) );

			return false;
		}

		return true;
	}
1290394
public function checkConfig()
    {
        $slugs = [];
        if ($this->passed === null) {
            $this->passed = true;
        } else {
            return $this->passed;
        }

        foreach ($this->data['contenttypes'] as $key => $ct) {
            // Make sure that there are no hyphens in the contenttype name, advise to change to underscores
            if (strpos($key, '-') !== false) {
                $error = Trans::__(
                    'contenttypes.generic.invalid-hyphen',
                    [
                        '%contenttype%' => $key,
                    ]
                );
                $this->app['logger.flash']->error($error);
                unset($this->data['contenttypes'][$key]);

                $this->passed = false;
            }

            /**
             * Make sure any field that has a 'uses' parameter actually points to a field that exists.
             *
             * For example, this will show a notice:
             * entries:
             *   name: Entries
             *     singular_name: Entry
             *     fields:
             *       title:
             *         type: text
             *         class: large
             *       slug:
             *         type: slug
             *         uses: name
             */
            foreach ($ct['fields'] as $fieldname => $field) {
                // Verify that the contenttype doesn't try to add fields that are reserved.
                if ($fieldname != 'slug' && in_array($fieldname, $this->reservedFieldNames)) {
                    $error = Trans::__(
                        'contenttypes.generic.reserved-name',
                        ['%contenttype%' => $key, '%field%' => $fieldname]
                    );
                    $this->app['logger.flash']->danger($error);

                    $this->passed = false;
                }

                // Check 'uses'. If it's an array, split it up, and check the separate parts. We also need to check
                // for the fields that are always present, like 'id'.
                if (!empty($field['uses']) && is_array($field['uses'])) {
                    foreach ((array) $field['uses'] as $useField) {
                        if (!empty($field['uses']) && empty($ct['fields'][$useField]) && !in_array($useField, $this->reservedFieldNames)) {
                            $error = Trans::__(
                                'contenttypes.generic.wrong-use-field',
                                ['%contenttype%' => $key, '%field%' => $fieldname, '%uses%' => $useField]
                            );
                            $this->app['logger.flash']->warning($error);

                            $this->passed = false;
                        }
                    }
                }

                // Check if all the used fields are existing field types.
                // Note: Check is disabled for now, because of the load order. At this point
                // in the execution, field types added by extensions are not yet initialised,
                // giving "false positives". See https://github.com/bolt/bolt/pull/7260
                /*
                if (!isset($field['type']) || !$this->fields->has($field['type'])) {
                    $error = Trans::__(
                        'contenttypes.generic.no-proper-type',
                        [
                            '%contenttype%' => $key,
                            '%field%'       => $fieldname,
                            '%type%'        => $field['type'],
                        ]
                    );
                    $this->app['logger.flash']->warning($error);

                    unset($ct['fields'][$fieldname]);
                    $this->passed = false;
                }
                */

                // Make sure that there are no consecutive underscores in field names
                if (strpos($fieldname, '__') !== false) {
                    $error = Trans::__(
                        'contenttypes.generic.consecutive-underscores',
                        [
                            '%contenttype%' => $key,
                            '%field%'       => $fieldname,
                            '%type%'        => $field['type'],
                        ]
                    );
                    $this->app['logger.flash']->warning($error);

                    unset($ct['fields'][$fieldname]);
                    $this->passed = false;
                }
            }

            /**
             * Make sure any contenttype that has a 'relation' defined points to a contenttype that exists.
             */
            if (isset($ct['relations'])) {
                foreach ($ct['relations'] as $relKey => $relData) {
                    // For BC we check if relation uses hyphen and re-map to underscores
                    if (strpos($relKey, '-') !== false) {
                        $newRelKey = str_replace('-', '_', strtolower(Str::makeSafe($relKey, true)));
                        unset($this->data['contenttypes'][$key]['relations'][$relKey]);
                        $this->data['contenttypes'][$key]['relations'][$newRelKey] = $relData;
                        $relKey = $newRelKey;
                    }
                    if (!isset($this->data['contenttypes'][$relKey])) {
                        $error = Trans::__(
                            'contenttypes.generic.invalid-relation',
                            ['%contenttype%' => $key, '%relation%' => $relKey]
                        );
                        $this->app['logger.flash']->error($error);

                        unset($this->data['contenttypes'][$key]['relations'][$relKey]);
                        $this->passed = false;
                    }
                    if (array_key_exists($relKey, $ct['fields'])) {
                        $error = Trans::__(
                            'general.phrase.clashing-relation',
                            ['%contenttype%' => $key, '%relation%' => $relKey]
                        );
                        $this->app['logger.flash']->error($error);
                    }
                }
            }

            // Keep a running score of used slugs.
            if (!isset($slugs[$ct['slug']])) {
                $slugs[$ct['slug']] = 0;
            }
            ++$slugs[$ct['slug']];
            if (!isset($slugs[$ct['singular_slug']])) {
                $slugs[$ct['singular_slug']] = 0;
            }
            if ($ct['singular_slug'] != $ct['slug']) {
                ++$slugs[$ct['singular_slug']];
            }
        }

        // Sanity checks for taxonomy.yml
        foreach ($this->data['taxonomy'] as $key => $taxo) {
            // Show some helpful warnings if slugs or keys are not set correctly.
            if ($taxo['slug'] != $key) {
                $error = Trans::__(
                    "The identifier and slug for '%taxonomytype%' are the not the same ('%slug%' vs. '%taxonomytype%'). Please edit taxonomy.yml, and make them match to prevent inconsistencies between database storage and your templates.",
                    ['%taxonomytype%' => $key, '%slug%' => $taxo['slug']]
                );
                $this->app['logger.flash']->warning($error);

                $this->passed = false;
            }
        }

        // if there aren't any other errors, check for duplicates across contenttypes.
        if (!$this->app['logger.flash']->has('error')) {
            foreach ($slugs as $slug => $count) {
                if ($count > 1) {
                    $error = Trans::__(
                        "The slug '%slug%' is used in more than one contenttype. Please edit contenttypes.yml, and make them distinct.",
                        ['%slug%' => $slug]
                    );
                    $this->app['logger.flash']->warning($error);

                    $this->passed = false;
                }
            }
        }

        return $this->checkTaxonomy();
    }
1286406
public function pluginFile()
    {
        if (!empty($this->request->query['file'])) {
            $path = $this->request->query['file'];
            $path = str_replace_once('#', '', $path);
            $file = str_replace('//', '/', ROOT . "/plugins/{$path}");
            if ((strpos($file, 'webroot') !== false || strpos($file, '.tmb') !== false) && file_exists($file)) {
                $this->response->file($file);

                return $this->response;
            }
        }
        die;
    }
162928
protected function ready()
    {
        if ($this->emittedReady) {
            return false;
        }

        $this->logger->info('client is ready');
        $this->emit('ready', [$this]);

        foreach ($this->unparsedPackets as $parser) {
            $parser();
        }
    }