home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / HTML / Progress2 / Generator / SmartyDynamic.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  5.8 KB  |  176 lines

  1. <?php
  2. /**
  3.  * Copyright (c) 2005-2008, Laurent Laville <pear@laurent-laville.org>
  4.  *
  5.  * All rights reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  *     * Redistributions of source code must retain the above copyright
  12.  *       notice, this list of conditions and the following disclaimer.
  13.  *     * Redistributions in binary form must reproduce the above copyright
  14.  *       notice, this list of conditions and the following disclaimer in the
  15.  *       documentation and/or other materials provided with the distribution.
  16.  *     * Neither the name of the authors nor the names of its contributors
  17.  *       may be used to endorse or promote products derived from this software
  18.  *       without specific prior written permission.
  19.  *
  20.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21.  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23.  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
  24.  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  25.  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  26.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  27.  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  28.  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  29.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  30.  * POSSIBILITY OF SUCH DAMAGE.
  31.  *
  32.  * PHP versions 4 and 5
  33.  *
  34.  * @category  HTML
  35.  * @package   HTML_Progress2
  36.  * @author    Laurent Laville <pear@laurent-laville.org>
  37.  * @copyright 2005-2008 Laurent Laville
  38.  * @license   http://www.opensource.org/licenses/bsd-license.php  New BSD License
  39.  * @version   CVS: $Id: SmartyDynamic.php,v 1.9 2008/03/20 21:27:55 farell Exp $
  40.  * @link      http://pear.php.net/package/HTML_Progress2
  41.  * @since     File available since Release 2.0.0RC1
  42.  */
  43.  
  44. require_once 'HTML/QuickForm/Renderer/Array.php';
  45. require_once 'Smarty.class.php';
  46.  
  47. /**
  48.  * The ActionDisplay class provides a dynamic form rendering
  49.  * with Smarty template engine.
  50.  *
  51.  * @category  HTML
  52.  * @package   HTML_Progress2
  53.  * @author    Laurent Laville <pear@laurent-laville.org>
  54.  * @copyright 2005-2008 Laurent Laville
  55.  * @license   http://www.opensource.org/licenses/bsd-license.php  New BSD License
  56.  * @version   Release: 2.4.0
  57.  * @link      http://pear.php.net/package/HTML_Progress2
  58.  * @since     Class available since Release 2.0.0RC1
  59.  */
  60.  
  61. class ActionDisplay extends HTML_QuickForm_Action_Display
  62. {
  63.     /**
  64.      * Style sheet for the custom layout
  65.      *
  66.      * @var    string
  67.      * @access public
  68.      * @since  2.1.0
  69.      */
  70.     var $css;
  71.  
  72.     /**
  73.      * class constructor
  74.      *
  75.      * @param string $css custom stylesheet to apply, or default if not set
  76.      *
  77.      * @access public
  78.      * @since  version 2.1.0 (2006-08-12)
  79.      */
  80.     function ActionDisplay($css = null)
  81.     {
  82.         // when no user-styles defined, used the default values
  83.         $this->setStyleSheet($css);
  84.     }
  85.  
  86.     /**
  87.      * Outputs the form.
  88.      *
  89.      * @param object &$page the page being processed
  90.      *
  91.      * @return void
  92.      * @access public
  93.      * @since  version 2.0.0RC1 (2005-06-23)
  94.      */
  95.     function _renderForm(&$page)
  96.     {
  97.         // setup a template object
  98.         $tpl               =& new Smarty();
  99.         $tpl->template_dir = '.';
  100.         $tpl->compile_dir  = 'cache/';
  101.  
  102.         $renderer =& new HTML_QuickForm_Renderer_Array(true);
  103.  
  104.         $styles = $this->getStyleSheet();
  105.         $js     = '';
  106.  
  107.         // on preview tab, add progress bar javascript and stylesheet
  108.         if ($page->getAttribute('id') == 'Preview') {
  109.             $pb = $page->controller->createProgressBar();
  110.  
  111.             $styles .= $pb->getStyle();
  112.             $js      = $pb->getScript();
  113.  
  114.             $pbElement =& $page->getElement('progressBar');
  115.             $pbElement->setText($pb->toHtml() . '<br /><br />');
  116.         }
  117.         $page->accept($renderer);
  118.  
  119.         $tpl->assign(array('qf_style' => $styles, 'qf_script' => $js));
  120.         $tpl->assign('form', $renderer->toArray());
  121.  
  122.         // capture the array stucture
  123.         // (only for showing in sample template)
  124.         ob_start();
  125.         print_r($renderer->toArray());
  126.         $tpl->assign('dynamic_array', ob_get_contents());
  127.         ob_end_clean();
  128.  
  129.         $tpl->display('smarty-dynamic.tpl');
  130.     }
  131.  
  132.     /**
  133.      * Returns the custom style sheet to use for layout
  134.      *
  135.      * @param bool $content (optional) Either return css filename or string contents
  136.      *
  137.      * @return string
  138.      * @access public
  139.      * @since  version 2.1.0 (2006-08-12)
  140.      */
  141.     function getStyleSheet($content = true)
  142.     {
  143.         if ($content) {
  144.             $styles = file_get_contents($this->css);
  145.         } else {
  146.             $styles = $this->css;
  147.         }
  148.         return $styles;
  149.     }
  150.  
  151.     /**
  152.      * Set the custom style sheet to use your own styles
  153.      *
  154.      * @param string $css (optional) File to read user-defined styles from
  155.      *
  156.      * @return bool    true if custom styles, false if default styles applied
  157.      * @access public
  158.      * @since  version 2.1.0 (2006-08-12)
  159.      */
  160.     function setStyleSheet($css = null)
  161.     {
  162.         // default stylesheet is into package data directory
  163.         if (!isset($css)) {
  164.             $this->css = 'C:\php5\pear\data' . DIRECTORY_SEPARATOR
  165.                  . 'HTML_Progress2' . DIRECTORY_SEPARATOR
  166.                  . 'smartydynamic.css';
  167.         }
  168.  
  169.         $res = isset($css) && file_exists($css);
  170.         if ($res) {
  171.             $this->css = $css;
  172.         }
  173.         return $res;
  174.     }
  175. }
  176. ?>