[ Index ]
 

Code source de phpMyAdmin 2.10.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/libraries/ -> Theme.class.php (source)

   1  <?php
   2  /* $Id: Theme.class.php 9902 2007-02-01 13:25:54Z cybot_tm $ */
   3  // vim: expandtab sw=4 ts=4 sts=4:
   4  
   5  class PMA_Theme {
   6      /**
   7       * @var string version
   8       */
   9      var $version = '0.0.0.0';
  10  
  11      /**
  12       * @var string name
  13       */
  14      var $name = '';
  15  
  16      /**
  17       * @var string id
  18       */
  19      var $id = '';
  20  
  21      /**
  22       * @var string
  23       */
  24      var $path = '';
  25  
  26      /**
  27       * @var string
  28       */
  29      var $img_path = '';
  30  
  31      /**
  32       * @var array   valid css types
  33       */
  34      var $types = array('left', 'right', 'print');
  35  
  36      /**
  37       * @var integer last modification time for info file
  38       */
  39      var $mtime_info = 0;
  40  
  41      function loadInfo()
  42      {
  43          if (! file_exists($this->getPath() . '/info.inc.php')) {
  44              return false;
  45          }
  46  
  47          if ($this->mtime_info === filemtime($this->getPath() . '/info.inc.php')) {
  48              return true;
  49          }
  50  
  51          @include $this->getPath() . '/info.inc.php';
  52  
  53          // did it set correctly?
  54          if (! isset($theme_name)) {
  55              return false;
  56          }
  57  
  58          $this->mtime_info = filemtime($this->getPath() . '/info.inc.php');
  59  
  60          if (isset($theme_full_version)) {
  61              $this->setVersion($theme_full_version);
  62          } elseif (isset($theme_generation, $theme_version)) {
  63              $this->setVersion($theme_generation . '.' . $theme_version);
  64          }
  65          $this->setName($theme_name);
  66  
  67          return true;
  68      }
  69  
  70      /**
  71       * returns theme object loaded from given folder
  72       * or false if theme is invalid
  73       *
  74       * @static
  75       * @param   string  path to theme
  76       * @return  object  PMA_Theme
  77       */
  78      function load($folder)
  79      {
  80  
  81          $theme = new PMA_Theme();
  82  
  83          $theme->setPath($folder);
  84  
  85          if (! $theme->loadInfo()) {
  86              return false;
  87          }
  88  
  89          $theme->checkImgPath();
  90  
  91          return $theme;
  92      }
  93  
  94      function checkImgPath()
  95      {
  96          if (is_dir($this->getPath() . '/img/')) {
  97              $this->setImgPath($this->getPath() . '/img/');
  98              return true;
  99          } elseif (is_dir($GLOBALS['cfg']['ThemePath'] . '/original/img/')) {
 100              $this->setImgPath($GLOBALS['cfg']['ThemePath'] . '/original/img/');
 101              return true;
 102          } else {
 103              $GLOBALS['PMA_errors'][] =
 104                  sprintf($GLOBALS['strThemeNoValidImgPath'], $this->getName());
 105              trigger_error(
 106                  sprintf($GLOBALS['strThemeNoValidImgPath'], $this->getName()),
 107                  E_USER_WARNING);
 108              return false;
 109          }
 110      }
 111  
 112      /**
 113       * returns path to theme
 114       * @uses    $this->$path    as return value
 115       * @return  string  $path   path to theme
 116       */
 117      function getPath()
 118      {
 119          return $this->path;
 120      }
 121  
 122      /**
 123       * returns layout file
 124       *
 125       * @return  string  layout file
 126       */
 127      function getLayoutFile()
 128      {
 129          return $this->getPath() . '/layout.inc.php';
 130      }
 131  
 132      /**
 133       * set path to theme
 134       * @uses    $this->$path    to set it
 135       * @param   string  $path   path to theme
 136       */
 137      function setPath($path)
 138      {
 139          $this->path = trim($path);
 140      }
 141  
 142      /**
 143       * sets version
 144       * @uses    $this->version
 145       * @param   string new version
 146       */
 147      function setVersion($version)
 148      {
 149          $this->version = trim($version);
 150      }
 151  
 152      /**
 153       * returns version
 154       * @uses    $this->version
 155       * @return  string  version
 156       */
 157      function getVersion()
 158      {
 159          return $this->version;
 160      }
 161  
 162      /**
 163       * checks theme version agaisnt $version
 164       * returns true if theme version is equal or higher to $version
 165       *
 166       * @uses    version_compare()
 167       * @uses    $this->getVersion()
 168       * @param   string  $version    version to compare to
 169       * @return  boolean
 170       */
 171      function checkVersion($version)
 172      {
 173          return version_compare($this->getVersion(), $version, 'lt');
 174      }
 175  
 176      /**
 177       * sets name
 178       * @param   string  $name   new name
 179       */
 180      function setName($name)
 181      {
 182          $this->name = trim($name);
 183      }
 184  
 185      /**
 186       * returns name
 187       * @return  string name
 188       */
 189      function getName()
 190      {
 191          return $this->name;
 192      }
 193  
 194      /**
 195       * sets id
 196       * @param   string  $id   new id
 197       */
 198      function setId($id)
 199      {
 200          $this->id = trim($id);
 201      }
 202  
 203      /**
 204       * returns id
 205       * @return  string id
 206       */
 207      function getId()
 208      {
 209          return $this->id;
 210      }
 211  
 212      function setImgPath($path)
 213      {
 214          $this->img_path = $path;
 215      }
 216  
 217      function getImgPath()
 218      {
 219          return $this->img_path;
 220      }
 221  
 222      /**
 223       * load css (send to stdout, normaly the browser)
 224       *
 225       * @uses    $this->getPath()
 226       * @uses    $this->types
 227       * @uses    PMA_SQP_buildCssData()
 228       * @uses    file_exists()
 229       * @uses    in_array()
 230       * @param   string  $type   left, right or print
 231       */
 232      function loadCss(&$type)
 233      {
 234          if (empty($type) || ! in_array($type, $this->types)) {
 235              $type = 'left';
 236          }
 237  
 238          if ($type == 'right') {
 239              echo PMA_SQP_buildCssData();
 240          }
 241  
 242          $_css_file = $this->getPath()
 243                     . '/css/theme_' . $type . '.css.php';
 244  
 245          if (! file_exists($_css_file)) {
 246              return false;
 247          }
 248  
 249          if ($GLOBALS['text_dir'] === 'ltr') {
 250              $right = 'right';
 251              $left = 'left';
 252          } else {
 253              $right = 'left';
 254              $left = 'right';
 255          }
 256  
 257          include $_css_file;
 258          return true;
 259      }
 260  
 261      /**
 262       * prints out the preview for this theme
 263       *
 264       * @uses    $this->getName()
 265       * @uses    $this->getVersion()
 266       * @uses    $this->getId()
 267       * @uses    $this->getPath()
 268       * @uses    $GLOBALS['strThemeNoPreviewAvailable']
 269       * @uses    $GLOBALS['strTakeIt']
 270       * @uses    PMA_generate_common_url()
 271       * @uses    addslashes()
 272       * @uses    file_exists()
 273       * @uses    htmlspecialchars()
 274       */
 275      function printPreview()
 276      {
 277          echo '<div class="theme_preview">';
 278          echo '<h2>' . htmlspecialchars($this->getName())
 279              .' (' . htmlspecialchars($this->getVersion()) . ')</h2>'
 280              .'<p>'
 281              .'<a target="_top" href="index.php'
 282              .PMA_generate_common_url(array('set_theme' => $this->getId())) . '"'
 283              .' onclick="takeThis(\'' . addslashes($this->getId()) . '\');'
 284              .' return false;">';
 285          if (@file_exists($this->getPath() . '/screen.png')) {
 286              // if screen exists then output
 287  
 288              echo '<img src="' . $this->getPath() . '/screen.png" border="1"'
 289                  .' alt="' . htmlspecialchars($this->getName()) . '"'
 290                  .' title="' . htmlspecialchars($this->getName()) . '" /><br />';
 291          } else {
 292              echo $GLOBALS['strThemeNoPreviewAvailable'];
 293          }
 294  
 295          echo '[ <strong>' . $GLOBALS['strTakeIt'] . '</strong> ]</a>'
 296              .'</p>'
 297              .'</div>';
 298      }
 299  }
 300  
 301  ?>


Généré le : Mon Nov 26 15:18:20 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics