Actions

Difference between revisions of "Unzip function in the Media Manager"

From Joomla! Documentation

(Added to the parent Tips and tricks category)
(Made miscellaneous improvements)
Line 1: Line 1:
I have developed a hack to had the capacity to unzip and untar files in the media manager component of Joomla! 1.5. It work like the delete function, you check the file and you click on the icon to unzip the selected file. It generate a folder with the same name of the selected file.
+
{{JVer|1.5}}
  
This hack is available [http://www.marc-dugas.fr/Blog/Blog/37-blog/62-update-de-la-fonction-de-decompression-pour-joomla-15 here]  at the end of the post. Just copy it at the root of your site. By hand it work like this.
+
I have developed a hack to add the capacity to unzip and untar files to the [[Media Manager]] component of Joomla! 1.5. It works like the delete function: you check the file and you click on the icon to unzip the selected file. It generates a folder with the same name as the selected file.
 +
 
 +
This hack is available [http://www.marc-dugas.fr/Blog/Blog/37-blog/62-update-de-la-fonction-de-decompression-pour-joomla-15 here]  at the end of the post. Just copy it at the root of your site. By hand it works like this.
  
 
Open the file administrator/component/com_media/views/media/view.html.php and after the line 106
 
Open the file administrator/component/com_media/views/media/view.html.php and after the line 106
Line 33: Line 35:
 
</source>
 
</source>
  
This add the icon button on the top of the media manager near the delete button.
+
This adds the icon button in the Media Manager toolbar (at the top, near the delete button).
Then open the file administrator/component/com_media/controllers/folder.php and add after the delete function
+
 
 +
Then open the file administrator/component/com_media/controllers/folder.php and add after the delete function:
  
 
<source lang="php">
 
<source lang="php">
Line 103: Line 106:
 
</source>
 
</source>
  
That's all. My hack use the joomla.filesystem.archive librairy of joomla 1.5 and work with zip, tar and gz extension.
+
That's all. My hack uses the joomla.filesystem.archive library of Joomla! 1.5 and works with the <code>zip</code>, <code>tar</code> and <code>gz</code> extensions.
  
 
[[Category:Tips and tricks]]
 
[[Category:Tips and tricks]]
 
[[Category:Tips and tricks 1.5]]
 
[[Category:Tips and tricks 1.5]]
 +
[[Category:Core hacks]]

Revision as of 15:47, 12 January 2011

Joomla 1.5

I have developed a hack to add the capacity to unzip and untar files to the Media Manager component of Joomla! 1.5. It works like the delete function: you check the file and you click on the icon to unzip the selected file. It generates a folder with the same name as the selected file.

This hack is available here at the end of the post. Just copy it at the root of your site. By hand it works like this.

Open the file administrator/component/com_media/views/media/view.html.php and after the line 106

    /* (...) */
    // Add a delete button
    $title = JText::_('Delete');
    $dhtml = "<a href=\"#\" onclick=\"MediaManager.submit('folder.delete')\"
      class=\"toolbar\">
                <span class=\"icon-32-delete\" title=\"$title\"
                  type=\"Custom\"></span>
                $title</a>";
    $bar->appendButton( 'Custom', $dhtml, 'delete' );
    /* (...) */

add

    /* (...) */
    // Add a Unzip button
    $title = JText::_('Unzip');
    $dhtml = "<a href=\"#\" onclick=\"MediaManager.submit('folder.unzip')\"
      class=\"toolbar\">
                <span class=\"icon-32-unarchive\" title=\"$title\"
                  type=\"Custom\"></span>
                $title</a>";
    $bar->appendButton( 'Custom', $dhtml, 'unzip' );
    /* (...) */

This adds the icon button in the Media Manager toolbar (at the top, near the delete button).

Then open the file administrator/component/com_media/controllers/folder.php and add after the delete function:

    /* (...) */
    function unzip() {
        global $mainframe;
 
        // Set FTP credentials, if given
        jimport('joomla.client.helper');
        JClientHelper::setCredentialsFromRequest('ftp');
 
        // Get some data from the request
        $tmpl    = JRequest::getCmd( 'tmpl' );
        $paths    = JRequest::getVar( 'rm', array(), '', 'array' );
        $folder = JRequest::getVar( 'folder', '', '', 'path');
 
        // Initialize variables
        $msg = array();
        $ret = true;
 
        if (count($paths)) {
            foreach ($paths as $path)
            {
                if ($path !== JFilterInput::clean($path, 'path')) {
                    JError::raiseWarning(100, JText::_('Impossible de
                      decompresser:').htmlspecialchars($path, ENT_COMPAT,
                      'UTF-8').' '.JText::_('WARNDIRNAME'));
                    continue;
                }
 
                $fullPath = JPath::clean(COM_MEDIA_BASE.DS.$folder.DS.$path);
 
                if (is_file($fullPath)) {
                    $ext = JFile::getExt(strtolower($fullPath));
                        $pathdir = $fullPath;
                        if($ext != 'gz') {
                            $pathdir = str_replace( ".".$ext, "",$pathdir);
                        }
                    else {
                        $pathdir = str_replace( ".".$ext, "",$pathdir);
                        $pathdir = str_replace( ".tar", "",$pathdir);
                    }
 
                    jimport('joomla.filesystem.*');
                    jimport('joomla.filesystem.archive');
                    JFolder::create($pathdir);
                    JFile::write($pathdir.DS."index.html", "<html>\n<body
                      bgcolor=\"#FFFFFF\">\n</body>\n</html>");
                    JArchive::extract($fullPath, $pathdir);
 
 
                } else if (is_dir($fullPath)) {
                    JError::raiseWarning(100, JText::_('Imossible de
                      decompresser:').$fullPath.' '.JText::_('Pas un fichier
                      ZIP'));
                }
            }
        }
        if ($tmpl == 'component') {
            // We are inside the iframe
            $mainframe->redirect('index.php?option=com_media&view=mediaList&
              folder='.$folder.'&tmpl=component');
        } else {
            $mainframe->redirect('index.php?option=com_media&folder='.$folder);
        }
    }
    /* (...) */

That's all. My hack uses the joomla.filesystem.archive library of Joomla! 1.5 and works with the zip, tar and gz extensions.