home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / phpMyAdmin / libraries / Theme.class.php < prev    next >
Encoding:
PHP Script  |  2008-06-23  |  9.5 KB  |  396 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 11035 2008-01-05 13:33:05Z lem9 $
  7.  */
  8.  
  9. /**
  10.  * handles theme
  11.  *
  12.  * @todo add the possibility to make a theme depends on another theme and by default on original
  13.  * @todo make all components optional - taking missing components from 'parent' theme
  14.  * @todo make css optionally 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.      * needed because sometimes, the mtime for different themes
  63.      * is identical
  64.      * @var integer filesize for info file
  65.      * @access  protected
  66.      */
  67.     var $filesize_info = 0;
  68.  
  69.     /**
  70.      * @access  public
  71.      * @uses    PMA_Theme::getPath()
  72.      * @uses    PMA_Theme::$mtime_info
  73.      * @uses    PMA_Theme::setVersion()
  74.      * @uses    PMA_Theme::setName()
  75.      * @uses    filemtime()
  76.      * @uses    filesize()
  77.      * @uses    file_exists()
  78.      * @return  boolean     whether loading them info was successful or not
  79.      */
  80.     function loadInfo()
  81.     {
  82.         if (! file_exists($this->getPath() . '/info.inc.php')) {
  83.             return false;
  84.         }
  85.  
  86.         if ($this->mtime_info === filemtime($this->getPath() . '/info.inc.php')) {
  87.             return true;
  88.         }
  89.  
  90.         @include $this->getPath() . '/info.inc.php';
  91.  
  92.         // did it set correctly?
  93.         if (! isset($theme_name)) {
  94.             return false;
  95.         }
  96.  
  97.         $this->mtime_info = filemtime($this->getPath() . '/info.inc.php');
  98.         $this->filesize_info = filesize($this->getPath() . '/info.inc.php');
  99.  
  100.         if (isset($theme_full_version)) {
  101.             $this->setVersion($theme_full_version);
  102.         } elseif (isset($theme_generation, $theme_version)) {
  103.             $this->setVersion($theme_generation . '.' . $theme_version);
  104.         }
  105.         $this->setName($theme_name);
  106.  
  107.         return true;
  108.     }
  109.  
  110.     /**
  111.      * returns theme object loaded from given folder
  112.      * or false if theme is invalid
  113.      *
  114.      * @static
  115.      * @access  public
  116.      * @uses    PMA_Theme
  117.      * @uses    PMA_Theme::setPath()
  118.      * @uses    PMA_Theme::loadInfo()
  119.      * @uses    PMA_Theme::checkImgPath()
  120.      * @param   string  $folder path to theme
  121.      * @return  object  PMA_Theme
  122.      */
  123.     function load($folder)
  124.     {
  125.         $theme = new PMA_Theme();
  126.  
  127.         $theme->setPath($folder);
  128.  
  129.         if (! $theme->loadInfo()) {
  130.             return false;
  131.         }
  132.  
  133.         $theme->checkImgPath();
  134.  
  135.         return $theme;
  136.     }
  137.  
  138.     /**
  139.      * checks image path for existance - if not found use img from original theme
  140.      *
  141.      * @access  public
  142.      * @uses    PMA_Theme::getPath()
  143.      * @uses    PMA_Theme::setImgPath()
  144.      * @uses    PMA_Theme::getName()
  145.      * @uses    $GLOBALS['cfg']['ThemePath']
  146.      * @uses    $GLOBALS['PMA_errors']
  147.      * @uses    $GLOBALS['strThemeNoValidImgPath']
  148.      * @uses    is_dir()
  149.      * @uses    sprintf()
  150.      */
  151.     function checkImgPath()
  152.     {
  153.         if (is_dir($this->getPath() . '/img/')) {
  154.             $this->setImgPath($this->getPath() . '/img/');
  155.             return true;
  156.         } elseif (is_dir($GLOBALS['cfg']['ThemePath'] . '/original/img/')) {
  157.             $this->setImgPath($GLOBALS['cfg']['ThemePath'] . '/original/img/');
  158.             return true;
  159.         } else {
  160.             $GLOBALS['PMA_errors'][] =
  161.                 sprintf($GLOBALS['strThemeNoValidImgPath'], $this->getName());
  162.             /*
  163.             trigger_error(
  164.                 sprintf($GLOBALS['strThemeNoValidImgPath'], $this->getName()),
  165.                 E_USER_WARNING);
  166.             */
  167.             return false;
  168.         }
  169.     }
  170.  
  171.     /**
  172.      * returns path to theme
  173.      *
  174.      * @access  public
  175.      * @uses    PMA_Theme::$path    as return value
  176.      * @return  string  $path   path to theme
  177.      */
  178.     function getPath()
  179.     {
  180.         return $this->path;
  181.     }
  182.  
  183.     /**
  184.      * returns layout file
  185.      *
  186.      * @access  public
  187.      * @uses    PMA_Theme::getPath()
  188.      * @return  string  layout file
  189.      */
  190.     function getLayoutFile()
  191.     {
  192.         return $this->getPath() . '/layout.inc.php';
  193.     }
  194.  
  195.     /**
  196.      * set path to theme
  197.      *
  198.      * @access  public
  199.      * @uses    PMA_Theme::$path    to set it
  200.      * @param   string  $path   path to theme
  201.      */
  202.     function setPath($path)
  203.     {
  204.         $this->path = trim($path);
  205.     }
  206.  
  207.     /**
  208.      * sets version
  209.      *
  210.      * @access  public
  211.      * @uses    PMA_Theme::$version
  212.      * @param   string new version
  213.      */
  214.     function setVersion($version)
  215.     {
  216.         $this->version = trim($version);
  217.     }
  218.  
  219.     /**
  220.      * returns version
  221.      *
  222.      * @access  public
  223.      * @uses    PMA_Theme::$version
  224.      * @return  string  version
  225.      */
  226.     function getVersion()
  227.     {
  228.         return $this->version;
  229.     }
  230.  
  231.     /**
  232.      * checks theme version agaisnt $version
  233.      * returns true if theme version is equal or higher to $version
  234.      *
  235.      * @access  public
  236.      * @uses    version_compare()
  237.      * @uses    PMA_Theme::getVersion()
  238.      * @param   string  $version    version to compare to
  239.      * @return  boolean
  240.      */
  241.     function checkVersion($version)
  242.     {
  243.         return version_compare($this->getVersion(), $version, 'lt');
  244.     }
  245.  
  246.     /**
  247.      * sets name
  248.      *
  249.      * @access  public
  250.      * @uses    PMA_Theme::$name to set it
  251.      * @uses    trim()
  252.      * @param   string  $name   new name
  253.      */
  254.     function setName($name)
  255.     {
  256.         $this->name = trim($name);
  257.     }
  258.  
  259.     /**
  260.      * returns name
  261.      *
  262.      * @access  public
  263.      * @uses    PMA_Theme::$name    as return value
  264.      * @return  string name
  265.      */
  266.     function getName()
  267.     {
  268.         return $this->name;
  269.     }
  270.  
  271.     /**
  272.      * sets id
  273.      *
  274.      * @access  public
  275.      * @uses    PMA_Theme::$id to set it
  276.      * @param   string  $id   new id
  277.      */
  278.     function setId($id)
  279.     {
  280.         $this->id = trim($id);
  281.     }
  282.  
  283.     /**
  284.      * returns id
  285.      *
  286.      * @access  public
  287.      * @uses    PMA_Theme::$id as return value
  288.      * @return  string  id
  289.      */
  290.     function getId()
  291.     {
  292.         return $this->id;
  293.     }
  294.  
  295.     /**
  296.      * @access  public
  297.      * @uses    PMA_Theme::$img_path to set it
  298.      * @param   string  path to images for this theme
  299.      */
  300.     function setImgPath($path)
  301.     {
  302.         $this->img_path = $path;
  303.     }
  304.  
  305.     /**
  306.      * @access  public
  307.      * @uses    PMA_Theme::$img_path as retunr value
  308.      * @return  string image path for this theme
  309.      */
  310.     function getImgPath()
  311.     {
  312.         return $this->img_path;
  313.     }
  314.  
  315.     /**
  316.      * load css (send to stdout, normaly the browser)
  317.      *
  318.      * @access  public
  319.      * @uses    PMA_Theme::getPath()
  320.      * @uses    PMA_Theme::$types
  321.      * @uses    PMA_SQP_buildCssData()
  322.      * @uses    file_exists()
  323.      * @uses    in_array()
  324.      * @param   string  $type   left, right or print
  325.      */
  326.     function loadCss(&$type)
  327.     {
  328.         if (empty($type) || ! in_array($type, $this->types)) {
  329.             $type = 'left';
  330.         }
  331.  
  332.         if ($type == 'right') {
  333.             echo PMA_SQP_buildCssData();
  334.         }
  335.  
  336.         $_css_file = $this->getPath()
  337.                    . '/css/theme_' . $type . '.css.php';
  338.  
  339.         if (! file_exists($_css_file)) {
  340.             return false;
  341.         }
  342.  
  343.         if ($GLOBALS['text_dir'] === 'ltr') {
  344.             $right = 'right';
  345.             $left = 'left';
  346.         } else {
  347.             $right = 'left';
  348.             $left = 'right';
  349.         }
  350.  
  351.         include $_css_file;
  352.         return true;
  353.     }
  354.  
  355.     /**
  356.      * prints out the preview for this theme
  357.      *
  358.      * @access  public
  359.      * @uses    PMA_Theme::getName()
  360.      * @uses    PMA_Theme::getVersion()
  361.      * @uses    PMA_Theme::getId()
  362.      * @uses    PMA_Theme::getPath()
  363.      * @uses    $GLOBALS['strThemeNoPreviewAvailable']
  364.      * @uses    $GLOBALS['strTakeIt']
  365.      * @uses    PMA_generate_common_url()
  366.      * @uses    addslashes()
  367.      * @uses    file_exists()
  368.      * @uses    htmlspecialchars()
  369.      */
  370.     function printPreview()
  371.     {
  372.         echo '<div class="theme_preview">';
  373.         echo '<h2>' . htmlspecialchars($this->getName())
  374.             .' (' . htmlspecialchars($this->getVersion()) . ')</h2>'
  375.             .'<p>'
  376.             .'<a target="_top" href="index.php'
  377.             .PMA_generate_common_url(array('set_theme' => $this->getId())) . '"'
  378.             .' onclick="takeThis(\'' . addslashes($this->getId()) . '\');'
  379.             .' return false;">';
  380.         if (@file_exists($this->getPath() . '/screen.png')) {
  381.             // if screen exists then output
  382.  
  383.             echo '<img src="' . $this->getPath() . '/screen.png" border="1"'
  384.                 .' alt="' . htmlspecialchars($this->getName()) . '"'
  385.                 .' title="' . htmlspecialchars($this->getName()) . '" /><br />';
  386.         } else {
  387.             echo $GLOBALS['strThemeNoPreviewAvailable'];
  388.         }
  389.  
  390.         echo '[ <strong>' . $GLOBALS['strTakeIt'] . '</strong> ]</a>'
  391.             .'</p>'
  392.             .'</div>';
  393.     }
  394. }
  395. ?>
  396.