1. <?php
  2. /**
  3. * Creates the page to display a xml code preview of your package.
  4. *
  5. * Show a preview of your new package.xml version, and check for any error.
  6. *
  7. * @category   PEAR
  8. * @package    PEAR_PackageFileManager_Frontend_Web
  9. * @author     Laurent Laville <pear@laurent-laville.org>
  10. * @copyright  2005-2006 Laurent Laville
  11. * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
  12. * @since      File available since Release 0.1.0
  13. */
  14.  
  15. /**
  16. * Creates the page to display a xml code preview of your package.
  17. *
  18. * @category   PEAR
  19. * @package    PEAR_PackageFileManager_Frontend_Web
  20. * @author     Laurent Laville <pear@laurent-laville.org>
  21. * @copyright  2005-2006 Laurent Laville
  22. * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
  23. * @since      Class available since Release 0.1.0
  24. */
  25. class PreviewPage extends TabbedPage
  26. {
  27.     /**
  28.      * Builds the current form-page.
  29.      *
  30.      * @since  0.1.0
  31.      * @access public
  32.      */
  33.     function buildForm()
  34.     {
  35.         $this->buildTabs();
  36.         // tab caption
  37.         $this->addElement('header', null, 'package.xml Preview');
  38.  
  39.         $pageName = $this->getAttribute('id');
  40.         // Checks whether the pages, before this one, are valid
  41.         $QFCvalid = $this->controller->isValid($pageName);
  42.  
  43.         if (!$QFCvalid) {
  44.             // jump to first page invalid
  45.             $pageName = $this->controller->findInvalid();
  46.             $page =& $this->controller->getPage($pageName);
  47.             return $page->handle('jump');
  48.         }
  49.  
  50.         $fe =& PEAR_PackageFileManager_Frontend::singleton();
  51.         $sess =& $fe->container();
  52.  
  53.         // Get the package.xml preview and check for errors.
  54.         $preview = $fe->buildPackageFile(true,
  55.             $sess['defaults']['exportCompatibleV1'],
  56.             $sess['defaults']['changelogOldToNew'],
  57.             $sess['defaults']['simpleOutput']
  58.         );
  59.         if (!$preview) {
  60.             // jump to the warnings page.
  61.             $page =& $this->controller->getPage('page0');
  62.             return $page->handle('jump');
  63.         }
  64.         $preview = substr($preview, strpos($preview,'<pre>&lt;?xml'));
  65.  
  66.         $available = PEAR_PackageFileManager2::isIncludeable('Text/Highlighter.php');
  67.         if ($available) {
  68.             include_once 'Text/Highlighter.php';
  69.             $hl =& Text_Highlighter::factory('XML');
  70.             $preview = str_replace(array('<pre>','</pre>'), array('', ''), $preview);
  71.             $preview = html_entity_decode($preview);
  72.             $xml = $hl->highlight($preview);
  73.         } else {
  74.             $xml = $preview;
  75.         }
  76.  
  77.         // We need a simple checkbox for the XML package v1.
  78.         $this->addElement('checkbox', 'exportCompatibleV1', 'XML version:', 'Export compatible version 1.0');
  79.  
  80.         // We need a simple checkbox for the changelog order option.
  81.         $this->addElement('checkbox', 'changelogOldToNew', 'ChangeLog order:', 'From oldest entry to newest');
  82.  
  83.         // We need a simple checkbox for the simpleoutput option.
  84.         $this->addElement('checkbox', 'simpleOutput', 'File List:', 'Human readable');
  85.  
  86.         // We need a simple static html area for the package xml structure.
  87.         $div = '<div class="autoscroll">' . $xml . '</div>';
  88.         $this->addElement('static', 'packageXML', '', $div);
  89.  
  90.         // Buttons of the wizard to do the job
  91.         $this->buildButtons(array('reset'));
  92.  
  93.         // default options
  94.         $settings = $fe->getOption(array('settings', 'pfm'), false);
  95.         $def = array(
  96.             'exportCompatibleV1' => $settings['pfm']['exportcompatiblev1'],
  97.             'changelogOldToNew'  => $settings['pfm']['changelogoldtonew'],
  98.             'simpleOutput'       => $settings['pfm']['simpleoutput']
  99.             );
  100.         $this->setDefaults($def);
  101.     }
  102. }
  103. ?>