示例#1
0
 function install_action()
 {
     $mainframe =& JFactory::getApplication();
     $database =& JFactory::getDBO();
     jimport('joomla.utilities.error');
     jimport('joomla.filesystem.file');
     jimport('joomla.filesystem.folder');
     jimport('joomla.filesystem.archive');
     $files = $_FILES;
     if (is_array($files) && !empty($files)) {
         //the file has been uploaded
         $file = $files['file'];
         $filename = $file['name'];
         $exten = explode(".", $filename);
         if ($exten[count($exten) - 1] == 'zip') {
             $path = JPATH_BASE . DS . 'cache';
             $uploadedfile = JFile::upload($file['tmp_name'], $path . DS . $filename);
             if (!$uploadedfile) {
                 JError::raiseWarning(100, "UPLAOD FAILED" . ": " . $file['error']);
                 $mainframe->redirect("index.php?option=com_chronoforms");
             } else {
                 $zipper =& JArchive::getAdapter('zip');
                 if ($zipper->extract($path . DS . $filename, $path . DS . $exten[0])) {
                     //we could extract the file, copy
                     if (JFolder::copy($path . DS . $exten[0] . DS, JPATH_SITE . DS . "administrator" . DS . "components" . DS . "com_chronoforms" . DS . "form_actions" . DS, '', true) === true) {
                         $mainframe->redirect("index.php?option=com_chronoforms", "Action installed successfully.");
                     } else {
                         JError::raiseWarning(100, "Couldn't copy to the destination folder.");
                         $mainframe->redirect("index.php?option=com_chronoforms");
                     }
                 } else {
                     //failed
                     JError::raiseWarning(100, "Couldn't extract the file provided.");
                     $mainframe->redirect("index.php?option=com_chronoforms");
                 }
             }
         } else {
             //wrong file extension
             JError::raiseWarning(100, "The file uploaded was not a Chronoforms V4 action installer file.");
             $mainframe->redirect("index.php?option=com_chronoforms");
         }
     } else {
         //no file, render the upload page
         HTML_Admin_ChronoForms::install_action();
     }
 }