Displaying the latest version of a plugin in the admin screen

Feed 5 posts, 3 voices

Aug 11, 2008 11:18
Avatar
458 posts

Hi Philippe, (and those interested)

I've created a small patch for Frog which allows Frog to check what the latest version number is for a given plugin. This can offcourse be expanded upon later. It could probably also do with some caching and such.

The system consists of: 1. a small XML file containing plugin information. (see below) 2. an addition to the plugin's index.php file. (see below) 3. a new function for the backend Plugin class. (see below) 4. a small addition to the admin screen. (see below)

The addition makes use of the SimpleXML API that became available with PHP5.

iIt's tiny but If you want to have an actual patch, I can make that aswell, I'll just have to retrieve the latest SVN version of Frog first.

Example XML file hosted somewhere by the plugin developer: <?xml version="1.0" encoding="iso-8859-1"?> <frog-plugins> <frog-plugin> <id>tinymce</id> <version>2.0.0</version> <status>development</status> </frog-plugin> </frog-plugins>

Note: it doesn't do anything yet with the status field, but this could allow us in future to tell the difference between a development version and a stable version of the plugin.

Example of additional entry needed in plugin's index.php file: 'update_url' => 'http://www.vanderkleijn.net/public/downloads/plugins/tinymce/update.xml',

Function ADDED to /frog/app/backend/models/Plugin.php /** * Check the file mentioned as update_url for the latest plugin version available. * * @param plugin string A plugin object. * * @return string The latest version number or 'n/a' when latest version couldn't be determined. */ static function checkLatest($plugin) { if ( ! isset($plugin->update_url) || ! $xml = simplexml_load_file($plugin->update_url)){ return 'unknown'; } foreach($xml as $node){ if ($plugin->id == $node->id) if ($plugin->version == $node->version) return 'latest'; else return $node->version; } return 'error'; }

ADDED to the /frog/app/backend/views/setting/index.php file: In the table "plugins" THEAD section, add the following right after the Version entry <th class="latest"><?php echo __('Latest'); ?></th>

In the table "plugins" TBODY section, add the following right after the version entry <td class="latest"><?php echo Plugin::checkLatest($plugin); ?></td>

 
Aug 11, 2008 11:18
Avatar
458 posts

I hate markdown.... :-(

 
Aug 11, 2008 11:22
Avatar
458 posts

Second attempt, hopefully with correct code blocks...

Hi Philippe, (and those interested)

I've created a small patch for Frog which allows Frog to check what the latest version number is for a given plugin. This can offcourse be expanded upon later. It could probably also do with some caching and such.

The system consists of:

  1. a small XML file containing plugin information. (see below)
  2. an addition to the plugin's index.php file. (see below)
  3. a new function for the backend Plugin class. (see below)
  4. a small addition to the admin screen. (see below)

The addition makes use of the SimpleXML API that became available with PHP5.

iIt's tiny but If you want to have an actual patch, I can make that aswell, I'll just have to retrieve the latest SVN version of Frog first.

Example XML file hosted somewhere by the plugin developer:

      <?xml version="1.0" encoding="iso-8859-1"?>
      <frog-plugins>
          <frog-plugin>
              <id>tinymce</id>
              <version>2.0.0</version>
              <status>development</status>
          </frog-plugin>
      </frog-plugins>

Note: it doesn't do anything yet with the status field, but this could allow us in future to tell the difference between a development version and a stable version of the plugin.

Example of additional entry needed in plugin's index.php file:

      'update_url'  => 'http://www.vanderkleijn.net/public/downloads/plugins/tinymce/update.xml',

Function ADDED to /frog/app/backend/models/Plugin.php

      /**
       * Check the file mentioned as update_url for the latest plugin version available.
       *
       * @param plugin     string A plugin object.
       *
       * @return           string The latest version number or 'n/a' when latest version couldn't be determined.
       */
      static function checkLatest($plugin)
      {
          if ( ! isset($plugin->update_url) || ! $xml = simplexml_load_file($plugin->update_url)){
              return 'unknown';
          }
          foreach($xml as $node){
              if ($plugin->id == $node->id)
                  if ($plugin->version == $node->version)
                      return 'latest';
                  else
                      return $node->version;
          }
          return 'error';
      }

ADDED to the /frog/app/backend/views/setting/index.php file: In the table "plugins" THEAD section, add the following right after the Version entry

    <th class="latest"><?php echo __('Latest'); ?></th>

In the table "plugins" TBODY section, add the following right after the version entry

    <td class="latest"><?php echo Plugin::checkLatest($plugin); ?></td>
 
Aug 11, 2008 11:36
Avatar
458 posts

Sorry, in the checkLatest function this:

  return $node->version;

should be:

  return (string) $node->version;

To make it conform with the comment belonging to the function. grins sheepishly

 
Aug 11, 2008 11:55
Avatar
963 posts

This would be a great addition, it seems to me. For those who want to keep their plugins current, anyway!

 
Aug 11, 2008 11:55
Avatar
277 posts

I really like it, good addition.