Ignore:
Timestamp:
Nov 9, 2013, 12:29:38 AM (10 years ago)
Author:
mistic100
Message:

feature 2998: Maintenance class for plugin

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/themes.class.php

    r25018 r25406  
    2222// +-----------------------------------------------------------------------+
    2323
     24/**
     25 * class DummyTheme_maintain
     26 * used when a theme uses the old procedural declaration of maintenance methods
     27 */
     28class DummyTheme_maintain extends ThemeMaintain
     29{
     30  function activate($theme_version, &$errors=array())
     31  {
     32    return $this->__call(__FUNCTION__, func_get_args());
     33  }
     34  function deactivate()
     35  {
     36    return $this->__call(__FUNCTION__, func_get_args());
     37  }
     38  function delete()
     39  {
     40    return $this->__call(__FUNCTION__, func_get_args());
     41  }
     42
     43  function __call($name, $arguments)
     44  {
     45    if (is_callable('theme_'.$name))
     46    {
     47      array_unshift($arguments, $this->theme_id);
     48      return call_user_func_array('theme_'.$name, $arguments);
     49    }
     50    return null;
     51  }
     52}
     53
     54
    2455class themes
    2556{
     
    3970      $this->db_themes_by_id[$db_theme['id']] = $db_theme;
    4071    }
     72  }
     73
     74  /**
     75   * Returns the maintain class of a theme
     76   * or build a new class with the procedural methods
     77   * @param string $theme_id
     78   */
     79  private static function build_maintain_class($theme_id)
     80  {
     81    $file_to_include = PHPWG_THEMES_PATH.'/'.$theme_id.'/admin/maintain.inc.php';
     82    $classname = $theme_id.'_maintain';
     83
     84    if (file_exists($file_to_include))
     85    {
     86      include_once($file_to_include);
     87
     88      if (class_exists($classname))
     89      {
     90        $theme_maintain = new $classname($theme_id);
     91      }
     92      else
     93      {
     94        $theme_maintain = new DummyTheme_maintain($theme_id);
     95      }
     96    }
     97    else
     98    {
     99      $theme_maintain = new DummyTheme_maintain($theme_id);
     100    }
     101
     102    return $theme_maintain;
    41103  }
    42104
     
    56118    }
    57119
    58     $file_to_include = PHPWG_THEMES_PATH.'/'.$theme_id.'/admin/maintain.inc.php';
     120    $theme_maintain = self::build_maintain_class($theme_id);
    59121
    60122    $errors = array();
     
    86148        }
    87149
    88 
    89150        if ($this->fs_themes[$theme_id]['mobile']
    90151            and !empty($conf['mobile_theme'])
     
    95156        }
    96157
    97         if (file_exists($file_to_include))
    98         {
    99           include($file_to_include);
    100           if (function_exists('theme_activate'))
    101           {
    102             theme_activate($theme_id, $this->fs_themes[$theme_id]['version'], $errors);
    103           }
    104         }
     158        $theme_maintain->activate($this->fs_themes[$theme_id]['version'], $errors);
    105159
    106160        if (empty($errors))
     
    142196
    143197          $query = '
    144 SELECT
    145     id
     198SELECT id
    146199  FROM '.THEMES_TABLE.'
    147200  WHERE id != \''.$theme_id.'\'
     
    160213        }
    161214
    162         if (file_exists($file_to_include))
    163         {
    164           include($file_to_include);
    165           if (function_exists('theme_deactivate'))
    166           {
    167             theme_deactivate($theme_id);
    168           }
    169         }
     215        $theme_maintain->deactivate();
    170216
    171217        $query = '
     
    204250        }
    205251
    206         if (file_exists($file_to_include))
    207         {
    208           include($file_to_include);
    209           if (function_exists('theme_delete'))
    210           {
    211             theme_delete($theme_id);
    212           }
    213         }
     252        $theme_maintain->delete();
    214253
    215254        deltree(PHPWG_THEMES_PATH.$theme_id, PHPWG_THEMES_PATH . 'trash');
Note: See TracChangeset for help on using the changeset viewer.