Exemple #1
0
 /**
  * Get active plugins that does not have there requirements met.
  * returns an array with plugin-base-name=>["this"=>[required-version, supplied-version]]
  * Supplied version in this array will be "null" if there was non supplied. eg. If it was a plugin
  * that wa entierly missing.
  *
  * @return array plugin-name=>(outdatedOrMissing=>(required, supplied))[]
  */
 private static function getUnsuportedPlugins()
 {
     $activePlugins = self::getAllActivePlugins();
     $unsuported = [];
     foreach ($activePlugins as $plugin) {
         $pluginFile = $plugin->getPluginFile();
         $wpRequireFile = $plugin->getWpRequire();
         // If no wp-require file exists, assume it has all it needs
         if ($wpRequireFile === null) {
             continue;
         }
         // Init the $unsuported array for this plugin
         $unsuported[$pluginFile] = array();
         $requiredPhpVersion = $wpRequireFile->getRequiredPhpVersion();
         $requiredWpVersion = $wpRequireFile->getRequiredWpVersion();
         $requiredPlugins = $wpRequireFile->getRequiredPlugins();
         $phpComp = $requiredPhpVersion->isCompatibleWith(self::getPhpVersion());
         if (!$phpComp) {
             $unsuported[$pluginFile]["php"] = array($requiredPhpVersion, self::getPhpVersion());
         }
         $wpComp = $requiredWpVersion->isCompatibleWith(self::getWpVersion());
         if (!$wpComp) {
             $unsuported[$pluginFile]["wp"] = array($requiredWpVersion, self::getWpVersion());
         }
         $unsuported[$pluginFile]['plugins'] = array();
         foreach ($requiredPlugins as $requiredPluginFile => $requiredPluginVersion) {
             if (!self::isPluginActive($requiredPluginFile)) {
                 if (!isset($unsuported[$pluginFile]['plugins'])) {
                     $unsuported[$pluginFile]['plugins'] = array();
                 }
                 $unsuported[$pluginFile]['plugins'][$requiredPluginFile] = array($requiredPluginVersion, null);
             } else {
                 $pluginData = get_plugin_data(WPRequire::PLUGINS_DIR() . "/" . $requiredPluginFile);
                 $requiredVersion = new Version($requiredPluginVersion);
                 $suppliedVersion = new Version($pluginData["Version"]);
                 if (!$requiredVersion->isCompatibleWith($suppliedVersion)) {
                     $unsuported[$pluginFile]['plugins'][$requiredPluginFile] = array($requiredPluginVersion, new Version($pluginData["Version"]));
                 }
             }
         }
         // If this plugins plugin requirments was uphelp
         if (count($unsuported[$pluginFile]['plugins']) === 0) {
             unset($unsuported[$pluginFile]['plugins']);
         }
         // If no reasons for why this plugin is unsuported can be found
         // Remove it from the array
         if (count($unsuported[$pluginFile]) === 0) {
             unset($unsuported[$pluginFile]);
         }
     }
     return $unsuported;
 }
Exemple #2
0
 /**
  * Compare two Version objects
  * Returns -1 if $this is bigger, 0 if they are equal
  * and +1 if the $version given is bigger.
  *
  * @param Version $version The version to compare to
  *
  * @return int
  */
 public function compare(Version $version)
 {
     if ($this->getMajor() !== "*" && $version->getMajor() !== "*") {
         if ($this->getMajor() > $version->getMajor()) {
             return -1;
         }
         if ($version->getMajor() > $this->getMajor()) {
             return 1;
         }
     }
     if ($this->getMinor() !== "*" && $version->getMinor() !== "*") {
         if ($this->getMinor() > $version->getMinor()) {
             return -1;
         }
         if ($version->getMinor() > $this->getMinor()) {
             return 1;
         }
     }
     if ($this->getPatch() !== "*" && $version->getPatch() !== "*") {
         if ($this->getPatch() > $version->getPatch()) {
             return -1;
         }
         if ($version->getPatch() > $this->getPatch()) {
             return 1;
         }
     }
     if (!$this->isRC() && $version->isRC()) {
         return -1;
     }
     if ($this->isRC()) {
         if (!$version->isRC()) {
             return 1;
         }
         if ($this->getRC() === "*" || $version->getRC() === "*") {
             return 0;
         }
         if ($this->getRC() > $version->getRC()) {
             return -1;
         }
         if ($version->getRC() > $this->getRC()) {
             return 1;
         }
         return 0;
     }
     if (!$this->isBeta() && $version->isBeta()) {
         return -1;
     }
     if ($this->isBeta()) {
         if (!$version->isBeta()) {
             return 1;
         }
         if ($this->getBeta() === "*" || $version->getBeta() === "*") {
             return 0;
         }
         if ($this->getBeta() > $version->getBeta()) {
             return -1;
         }
         if ($version->getBeta() > $this->getBeta()) {
             return 1;
         }
         return 0;
     }
     if (!$this->isAlpha() && $version->isAlpha()) {
         return -1;
     }
     if ($this->isAlpha()) {
         if (!$version->isAlpha()) {
             return 1;
         }
         if ($this->getAlpha() === "*" || $version->getAlpha() === "*") {
             return 0;
         }
         if ($this->getAlpha() > $version->getAlpha()) {
             return -1;
         }
         if ($version->getAlpha() > $this->getAlpha()) {
             return 1;
         }
         return 0;
     }
     return 0;
 }