Joomla文档中文翻译 - 如何为Joomla的媒体管理器增加解压缩功能
如需转载,请注明官方英文文档及本人译文的出处,谢谢。查看官方英文文档: Unzip function in the Media Manager
本文将展示如何为Joomla 1.5以上版本中的媒体管理器增加解压缩的功能。这个功能的流程是这样的——选中某压缩包文件,点击“解压”功能的图标,文件被解压缩,生成与压缩包文件同名的文件夹。
找到下面这个文件并打开:
Joomla根路径/administrator/component/com_media/views/media/view.html.php
在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 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' ); /* (...) */
这段代码的作用是在媒体管理器中“删除”按钮的旁边增加一个新的“解压缩”按钮。
接下来找到下面这个文件并打开:
Joomla根路径/administrator/component/com_media/controllers/folder.php
与之前的过程类似,找到对应着“删除”功能的代码,在后面添加如下代码,以增加“解压缩”功能:
/* (...) */ 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); } } /* (...) */
搞定;该方法使用到了joomla.filesystem.archive librairy,适用于zip,tar,gz这些文件格式。
译者:viiiix.com
| Next > |
|---|
