home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 February (DVD) / PCWorld_2008-02_DVD.iso / v cisle / PHP / PHP.exe / xampp-win32-1.6.5-installer.exe / phpMyAdmin / libraries / Theme.class.php < prev    next >
Encoding:
PHP Script  |  2007-12-20  |  9.2 KB  |  385 lines

  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4.  * hold PMA_Theme class
  5.  *
  6.  * @version $Id: Theme.class.php 10137 2007-03-19 17:55:39Z cybot_tm $
  7.  */
  8.  
  9. /**
  10.  * handles theme
  11.  *
  12.  * @todo add the possibility to make a theme depends on another theme and by default on orignal
  13.  * @todo make all components optional - taking missing compnents from 'parent' theme
  14.  * @todo make css optionaly replacing 'parent' css or extending it (by appending at the end)
  15.  * @todo add an optional global css file - which will be used for both frames
  16.  *
  17.  */
  18. class PMA_Theme {
  19.     /**
  20.      * @var string theme version
  21.      * @access  protected
  22.      */
  23.     var $version = '0.0.0.0';
  24.  
  25.     /**
  26.      * @var string theme name
  27.      * @access  protected
  28.      */
  29.     var $name = '';
  30.  
  31.     /**
  32.      * @var string theme id
  33.      * @access  protected
  34.      */
  35.     var $id = '';
  36.  
  37.     /**
  38.      * @var string theme path
  39.      * @access  protected
  40.      */
  41.     var $path = '';
  42.  
  43.     /**
  44.      * @var string image path
  45.      * @access  protected
  46.      */
  47.     var $img_path = '';
  48.  
  49.     /**
  50.      * @var array   valid css types
  51.      * @access  protected
  52.      */
  53.     var $types = array('left', 'right', 'print');
  54.  
  55.     /**
  56.      * @var integer last modification time for info file
  57.      * @access  protected
  58.      */
  59.     var $mtime_info = 0;
  60.  
  61.     /**
  62.      * @access  public
  63.      * @uses    PMA_Theme::getPath()
  64.      * @uses    PMA_Theme::$mtime_info
  65.      * @uses    PMA_Theme::setVersion()
  66.      * @uses    PMA_Theme::setName()
  67.      * @uses    filemtime()
  68.      * @uses    file_exists()
  69.      * @return  boolean     whether loading them info was successful or not
  70.      */
  71.     function loadInfo()
  72.     {
  73.         if (! file_exists($this->getPath() . '/info.inc.php')) {
  74.             return false;
  75.         }
  76.  
  77.         if ($this->mtime_info === filemtime($this->getPath() . '/info.inc.php')) {
  78.             return true;
  79.         }
  80.  
  81.         @include $this->getPath() . '/info.inc.php';
  82.  
  83.         // did it set correctly?
  84.         if (! isset($theme_name)) {
  85.             return false;
  86.         }
  87.  
  88.         $this->mtime_info = filemtime($this->getPath() . '/info.inc.php');
  89.  
  90.         if (isset($theme_full_version)) {
  91.             $this->setVersion($theme_full_version);
  92.         } elseif (isset($theme_generation, $theme_version)) {
  93.             $this->setVersion($theme_generation . '.' . $theme_version);
  94.         }
  95.         $this->setName($theme_name);
  96.  
  97.         return true;
  98.     }
  99.  
  100.     /**
  101.      * returns theme object loaded from given folder
  102.      * or false if theme is invalid
  103.      *
  104.      * @static
  105.      * @access  public
  106.      * @uses    PMA_Theme
  107.      * @uses    PMA_Theme::setPath()
  108.      * @uses    PMA_Theme::loadInfo()
  109.      * @uses    PMA_Theme::checkImgPath()
  110.      * @param   string  $folder path to theme
  111.      * @return  object  PMA_Theme
  112.      */
  113.     function load($folder)
  114.     {
  115.         $theme = new PMA_Theme();
  116.  
  117.         $theme->setPath($folder);
  118.  
  119.         if (! $theme->loadInfo()) {
  120.             return false;
  121.         }
  122.  
  123.         $theme->checkImgPath();
  124.  
  125.         return $theme;
  126.     }
  127.  
  128.     /**
  129.      * checks image path for existance - if not found use img from original theme
  130.      *
  131.      * @access  public
  132.      * @uses    PMA_Theme::getPath()
  133.      * @uses    PMA_Theme::setImgPath()
  134.      * @uses    PMA_Theme::getName()
  135.      * @uses    $GLOBALS['cfg']['ThemePath']
  136.      * @uses    $GLOBALS['PMA_errors']
  137.      * @uses    $GLOBALS['strThemeNoValidImgPath']
  138.      * @uses    is_dir()
  139.      * @uses    sprintf()
  140.      */
  141.     function checkImgPath()
  142.     {
  143.         if (is_dir($this->getPath() . '/img/')) {
  144.             $this->setImgPath($this->getPath() . '/img/');
  145.             return true;
  146.         } elseif (is_dir($GLOBALS['cfg']['ThemePath'] . '/original/img/')) {
  147.             $this->setImgPath($GLOBALS['cfg']['ThemePath'] . '/original/img/');
  148.             return true;
  149.         } else {
  150.             $GLOBALS['PMA_errors'][] =
  151.                 sprintf($GLOBALS['strThemeNoValidImgPath'], $this->getName());
  152.             /*
  153.             trigger_error(
  154.                 sprintf($GLOBALS['strThemeNoValidImgPath'], $this->getName()),
  155.                 E_USER_WARNING);
  156.             */
  157.             return false;
  158.         }
  159.     }
  160.  
  161.     /**
  162.      * returns path to theme
  163.      *
  164.      * @access  public
  165.      * @uses    PMA_Theme::$path    as return value
  166.      * @return  string  $path   path to theme
  167.      */
  168.     function getPath()
  169.     {
  170.         return $this->path;
  171.     }
  172.  
  173.     /**
  174.      * returns layout file
  175.      *
  176.      * @access  public
  177.      * @uses    PMA_Theme::getPath()
  178.      * @return  string  layout file
  179.      */
  180.     function getLayoutFile()
  181.     {
  182.         return $this->getPath() . '/layout.inc.php';
  183.     }
  184.  
  185.     /**
  186.      * set path to theme
  187.      *
  188.      * @access  public
  189.      * @uses    PMA_Theme::$path    to set it
  190.      * @param   string  $path   path to theme
  191.      */
  192.     function setPath($path)
  193.     {
  194.         $this->path = trim($path);
  195.     }
  196.  
  197.     /**
  198.      * sets version
  199.      *
  200.      * @access  public
  201.      * @uses    PMA_Theme::$version
  202.      * @param   string new version
  203.      */
  204.     function setVersion($version)
  205.     {
  206.         $this->version = trim($version);
  207.     }
  208.  
  209.     /**
  210.      * returns version
  211.      *
  212.      * @access  public
  213.      * @uses    PMA_Theme::$version
  214.      * @return  string  version
  215.      */
  216.     function getVersion()
  217.     {
  218.         return $this->version;
  219.     }
  220.  
  221.     /**
  222.      * checks theme version agaisnt $version
  223.      * returns true if theme version is equal or higher to $version
  224.      *
  225.      * @access  public
  226.      * @uses    version_compare()
  227.      * @uses    PMA_Theme::getVersion()
  228.      * @param   string  $version    version to compare to
  229.      * @return  boolean
  230.      */
  231.     function checkVersion($version)
  232.     {
  233.         return version_compare($this->getVersion(), $version, 'lt');
  234.     }
  235.  
  236.     /**
  237.      * sets name
  238.      *
  239.      * @access  public
  240.      * @uses    PMA_Theme::$name to set it
  241.      * @uses    trim()
  242.      * @param   string  $name   new name
  243.      */
  244.     function setName($name)
  245.     {
  246.         $this->name = trim($name);
  247.     }
  248.  
  249.     /**
  250.      * returns name
  251.      *
  252.      * @access  public
  253.      * @uses    PMA_Theme::$name    as return value
  254.      * @return  string name
  255.      */
  256.     function getName()
  257.     {
  258.         return $this->name;
  259.     }
  260.  
  261.     /**
  262.      * sets id
  263.      *
  264.      * @access  public
  265.      * @uses    PMA_Theme::$id to set it
  266.      * @param   string  $id   new id
  267.      */
  268.     function setId($id)
  269.     {
  270.         $this->id = trim($id);
  271.     }
  272.  
  273.     /**
  274.      * returns id
  275.      *
  276.      * @access  public
  277.      * @uses    PMA_Theme::$id as return value
  278.      * @return  string  id
  279.      */
  280.     function getId()
  281.     {
  282.         return $this->id;
  283.     }
  284.  
  285.     /**
  286.      * @access  public
  287.      * @uses    PMA_Theme::$img_path to set it
  288.      * @param   string  path to images for this theme
  289.      */
  290.     function setImgPath($path)
  291.     {
  292.         $this->img_path = $path;
  293.     }
  294.  
  295.     /**
  296.      * @access  public
  297.      * @uses    PMA_Theme::$img_path as retunr value
  298.      * @return  string image path for this theme
  299.      */
  300.     function getImgPath()
  301.     {
  302.         return $this->img_path;
  303.     }
  304.  
  305.     /**
  306.      * load css (send to stdout, normaly the browser)
  307.      *
  308.      * @access  public
  309.      * @uses    PMA_Theme::getPath()
  310.      * @uses    PMA_Theme::$types
  311.      * @uses    PMA_SQP_buildCssData()
  312.      * @uses    file_exists()
  313.      * @uses    in_array()
  314.      * @param   string  $type   left, right or print
  315.      */
  316.     function loadCss(&$type)
  317.     {
  318.         if (empty($type) || ! in_array($type, $this->types)) {
  319.             $type = 'left';
  320.         }
  321.  
  322.         if ($type == 'right') {
  323.             echo PMA_SQP_buildCssData();
  324.         }
  325.  
  326.         $_css_file = $this->getPath()
  327.                    . '/css/theme_' . $type . '.css.php';
  328.  
  329.         if (! file_exists($_css_file)) {
  330.             return false;
  331.         }
  332.  
  333.         if ($GLOBALS['text_dir'] === 'ltr') {
  334.             $right = 'right';
  335.             $left = 'left';
  336.         } else {
  337.             $right = 'left';
  338.             $left = 'right';
  339.         }
  340.  
  341.         include $_css_file;
  342.         return true;
  343.     }
  344.  
  345.     /**
  346.      * prints out the preview for this theme
  347.      *
  348.      * @access  public
  349.      * @uses    PMA_Theme::getName()
  350.      * @uses    PMA_Theme::getVersion()
  351.      * @uses    PMA_Theme::getId()
  352.      * @uses    PMA_Theme::getPath()
  353.      * @uses    $GLOBALS['strThemeNoPreviewAvailable']
  354.      * @uses    $GLOBALS['strTakeIt']
  355.      * @uses    PMA_generate_common_url()
  356.      * @uses    addslashes()
  357.      * @uses    file_exists()
  358.      * @uses    htmlspecialchars()
  359.      */
  360.     function printPreview()
  361.     {
  362.         echo '<div class="theme_preview">';
  363.         echo '<h2>' . htmlspecialchars($this->getName())
  364.             .' (' . htmlspecialchars($this->getVersion()) . ')</h2>'
  365.             .'<p>'
  366.             .'<a target="_top" href="index.php'
  367.             .PMA_generate_common_url(array('set_theme' => $this->getId())) . '"'
  368.             .' onclick="takeThis(\'' . addslashes($this->getId()) . '\');'
  369.             .' return false;">';
  370.         if (@file_exists($this->getPath() . '/screen.png')) {
  371.             // if screen exists then output
  372.  
  373.             echo '<img src="' . $this->getPath() . '/screen.png" border="1"'
  374.                 .' alt="' . htmlspecialchars($this->getName()) . '"'
  375.                 .' title="' . htmlspecialchars($this->getName()) . '" /><br />';
  376.         } else {
  377.             echo $GLOBALS['strThemeNoPreviewAvailable'];
  378.         }
  379.  
  380.         echo '[ <strong>' . $GLOBALS['strTakeIt'] . '</strong> ]</a>'
  381.             .'</p>'
  382.             .'</div>';
  383.     }
  384. }
  385. ?>