示例#1
0
 /**
  *   determines the mime-type for the given file
  *   @static
  *   @param  string  The file name
  *   @return string  The MIME type or FALSE in the case of an error
  */
 function getMimeType($strFile)
 {
     //MIME_Type doesn't return the right type for directories
     //The underlying functions MIME_Type used don't return it right,
     //so there is no chance to fix MIME_Type itself
     if (file_exists($strFile) && is_dir($strFile) || substr($strFile, -1) == '/') {
         return 'inode/directory';
     }
     $strMime = MIME_Type::autoDetect($strFile);
     if (!PEAR::isError($strMime)) {
         return $strMime;
     }
     //determine by extension | as MIME_TYPE doesn't support this, I have to do this myself
     $strExtension = Gtk_FileDrop::getFileExtension($strFile);
     switch ($strExtension) {
         case '.txt':
             $strType = 'text/plain';
             break;
         case '.gif':
             $strType = 'image/gif';
             break;
         case '.jpg':
         case '.jpeg':
             $strType = 'image/jpg';
             break;
         case '.png':
             $strType = 'image/png';
             break;
         case '.xml':
             $strType = 'text/xml';
             break;
         case '.htm':
         case '.html':
             $strType = 'text/html';
             break;
         default:
             $strType = false;
             break;
     }
     return $strType;
 }
示例#2
0
 /**
  * Creates the page for displaying the package file manager
  * options that relate to the entire package, regardless of
  * the release.
  *
  * Package options are those such as: base install directory,
  * the license, the package name, etc.
  *
  * @return array
  * @access private
  */
 function _createPackagePage()
 {
     // Create some containers.
     $mainVBox =& new GtkVBox();
     // Create the hbox for the file selection.
     $packageDirHBox =& new GtkHBox();
     // We need an entries for the file.
     $packageDirEntry =& new GtkEntry();
     $packageDirButton =& new GtkButton('Select');
     // Allow users to drop files in the entry box if possible.
     @(include_once 'Gtk/FileDrop.php');
     if (class_exists('Gtk_FileDrop')) {
         Gtk_FileDrop::attach($packageDirEntry, array('inode/directory'));
     }
     // Create the file selection.
     $packageDirFS =& new GtkFileSelection('Package Directory');
     $packageDirFS->set_position(GTK_WIN_POS_CENTER);
     // Set the default path to the pear directory.
     require_once 'PEAR/Config.php';
     $pearConfig =& new PEAR_Config();
     $packageDirFS->set_filename($pearConfig->get('php_dir'));
     // Make the ok button set the entry value.
     $okButton = $packageDirFS->ok_button;
     $okButton->connect_object('clicked', array(&$this, '_setPackageDirEntry'), $packageDirEntry, $packageDirFS);
     // Make the cancel button hide the selection.
     $cancelButton = $packageDirFS->cancel_button;
     $cancelButton->connect_object('clicked', array(&$packageDirFS, 'hide'));
     // Make the button show the file selection.
     $packageDirButton->connect_object('clicked', array(&$packageDirFS, 'show'));
     // Pack the package file directory pieces.
     $packageDirLabel =& new GtkLabel('Package File Directory');
     $packageDirLabel->set_usize(140, -1);
     $packageDirLabel->set_alignment(0, 0.5);
     $packageDirHBox->pack_start($packageDirLabel, false, false, 3);
     $packageDirHBox->pack_start($packageDirEntry, false, false, 3);
     $packageDirHBox->pack_start($packageDirButton, false, false, 3);
     // We need an entry for the package name.
     $packageNameEntry =& new GtkEntry();
     $packageNameBox =& new GtkHBox();
     $packageNameLabel =& new GtkLabel('Package Name');
     $packageNameLabel->set_usize(140, -1);
     $packageNameLabel->set_alignment(0, 0.5);
     $packageNameBox->pack_start($packageNameLabel, false, false, 3);
     $packageNameBox->pack_start($packageNameEntry, false, false, 3);
     // We need a simple entry box for the base install directory.
     $baseEntry =& new GtkEntry();
     $baseBox =& new GtkHBox();
     $baseLabel =& new GtkLabel('Base Install Dir');
     $baseLabel->set_usize(140, -1);
     $baseLabel->set_alignment(0, 0.5);
     $baseBox->pack_start($baseLabel, false, false, 3);
     $baseBox->pack_start($baseEntry, false, false, 3);
     // We need an entry for the summary.
     $summaryEntry =& new GtkEntry();
     $summaryBox =& new GtkHBox();
     $summaryLabel =& new GtkLabel('Package Summary');
     $summaryLabel->set_usize(140, -1);
     $summaryLabel->set_alignment(0, 0.5);
     $summaryBox->pack_start($summaryLabel, false, false, 3);
     $summaryBox->pack_start($summaryEntry, false, false, 3);
     // We need a text area for the description.
     $descriptionText =& new GtkText();
     $descriptionBox =& new GtkVBox();
     $descriptionLabel =& new GtkLabel('Package Description');
     $descriptionLabel->set_usize(140, -1);
     $descriptionLabel->set_alignment(0, 0.5);
     $descriptionText->set_editable(true);
     $descriptionText->set_line_wrap(true);
     $descriptionText->set_word_wrap(true);
     $descriptionText->set_usize(-1, 100);
     $descriptionBox->pack_start($descriptionLabel, false, false, 3);
     $descriptionBox->pack_start($descriptionText, true, true, 3);
     // We need a button to do the work.
     $submitButton =& new GtkButton('Submit');
     $submitButton->connect_object('clicked', array(&$this, '_setPackageOptions'), $packageDirEntry, $packageNameEntry, $baseEntry, $summaryEntry, $descriptionText);
     $submitBox =& new GtkHBox();
     $submitBox->pack_end($submitButton, false, false, 5);
     // Import the options if there is a package.xml file
     // in the package directory.
     $packageDirEntry->connect('changed', array(&$this, '_importPackageOptions'), $packageNameEntry, $baseEntry, $summaryEntry, $descriptionText);
     // Pack everything away.
     $mainVBox->pack_start($packageDirHBox, false, false, 3);
     $mainVBox->pack_start($packageNameBox, false, false, 3);
     $mainVBox->pack_start($baseBox, false, false, 3);
     $mainVBox->pack_start($summaryBox, false, false, 3);
     $mainVBox->pack_start($descriptionBox, true, true, 3);
     $mainVBox->pack_start($submitBox, false, false, 3);
     return array(&$mainVBox, new GtkLabel('Package'));
 }