diff options
Diffstat (limited to 'site/app/controllers/files_controller.php')
-rw-r--r-- | site/app/controllers/files_controller.php | 81 |
1 files changed, 53 insertions, 28 deletions
diff --git a/site/app/controllers/files_controller.php b/site/app/controllers/files_controller.php index 837779c..da78b3c 100644 --- a/site/app/controllers/files_controller.php +++ b/site/app/controllers/files_controller.php @@ -84,6 +84,8 @@ class FilesController extends AppController return; } + $addontype = $addon['Addon']['addontype_id']; + $startfile = 'install.rdf'; $path = REPO_PATH.'/'.$this->Addon->id.'/'.$file['File']['filename']; if (!file_exists($path)) { @@ -98,45 +100,53 @@ class FilesController extends AppController //If a specific file is requested, show it if (!empty($_GET['view'])) { - $this->_view($path, $_GET['view']); + $this->_view($path, $_GET['view'], $addontype); return; } - - $zip = new Archive_Zip($path); - $contents = $zip->listContent(); $files = array(); - foreach ($contents as $content) { - $isJar = false; - if (substr($content['filename'], strrpos($content['filename'], '.')) == '.jar') { - $content['folder'] = 1; - $isJar = true; - } + if ($addontype === ADDON_SEARCH) { + $startfile = $file['File']['filename']; + $this->Filebrowser->buildContentsArray($startfile, false, false, $files); + } else { + $zip = new Archive_Zip($path); + $contents = $zip->listContent(); - $this->Filebrowser->buildContentsArray($content['filename'], $content['folder'], false, $files); + foreach ($contents as $content) { + $isJar = false; - if ($isJar == true) { - $filename = substr($content['filename'], strrpos($content['filename'], '/')); - $jarfile = $zip->extract(array('extract_as_string' => true, 'by_name' => array($content['filename']))); + if (substr($content['filename'], strrpos($content['filename'], '.')) == '.jar') { + $content['folder'] = 1; + $isJar = true; + } - //write a .jar file with the .jar contents to extract in a new Archive_Zip - //I spent a long time trying to figure out an easier way, but no such luck - $jarcontents = $this->Filebrowser->getJarContents(REPO_PATH.'/temp'.$filename, $jarfile[0]['content']); + $this->Filebrowser->buildContentsArray($content['filename'], $content['folder'], false, $files); - foreach ($jarcontents as $jarcontent) { - $this->Filebrowser->buildContentsArray($content['filename'].'/'.$jarcontent['filename'], $jarcontent['folder'], false, $files); - } + if ($isJar == true) { + $filename = substr($content['filename'], strrpos($content['filename'], '/')); + $jarfile = $zip->extract(array('extract_as_string' => true, 'by_name' => array($content['filename']))); + + //write a .jar file with the .jar contents to extract in a new Archive_Zip + //I spent a long time trying to figure out an easier way, but no such luck + $jarcontents = $this->Filebrowser->getJarContents(REPO_PATH.'/temp'.$filename, $jarfile[0]['content']); + + foreach ($jarcontents as $jarcontent) { + $this->Filebrowser->buildContentsArray($content['filename'].'/'.$jarcontent['filename'], $jarcontent['folder'], false, $files); + } + } } } $this->publish('id', $file_id); - $this->publish('contents', $contents); $this->publish('files', $files); $this->publish('version', $file['Version']['id']); $this->publish('addon', $this->Addon->id); + $this->publish('addonname', $addon['Translation']['name']['string']); $this->publish('review', $review); + $this->publish('addontype', $addontype); + $this->publish('startfile', $startfile); $this->render('browse', 'ajax'); } @@ -145,9 +155,10 @@ class FilesController extends AppController * @param string $path the package * @param string $file the file */ - function _view($path, $file) { + function _view($path, $file, $addontype) { $file = html_entity_decode(urldecode($file), ENT_QUOTES, 'UTF-8'); - $contents = $this->_get_contents($path, $file); + $contents = $this->_get_contents($path, $file, $addontype); + if (is_bool($contents) && $contents == false) { $this->flash(_('error_file_notfound'), '/'); return; @@ -186,6 +197,7 @@ class FilesController extends AppController return; } + $addontype = $addon['Addon']['addontype_id']; $path = REPO_PATH.'/'.$this->Addon->id.'/'.$file['File']['filename']; if (!file_exists($path)) { @@ -196,7 +208,7 @@ class FilesController extends AppController if (!empty($_GET['compare'])) { $public_path = REPO_PATH.'/'.$this->Addon->id.'/'.$public_file['File'][0]['filename']; $sandbox_path = REPO_PATH.'/'.$this->Addon->id.'/'.$sandbox_file['File']['filename']; - $this->_compare($sandbox_path, $public_path, html_entity_decode($_GET['compare'], ENT_QUOTES, 'UTF-8')); + $this->_compare($sandbox_path, $public_path, html_entity_decode($_GET['compare'], ENT_QUOTES, 'UTF-8'), $addontype); return; } @@ -269,12 +281,13 @@ class FilesController extends AppController $this->publish('addon', $this->Addon->id); $this->publish('review', 1); $this->publish('is_diff', true); + $this->publish('startfile', 'install.rdf'); $this->render('browse', 'ajax'); } - function _compare($sandbox_path, $public_path, $file) { - $sandbox_contents = $this->_get_contents($sandbox_path, $file); - $public_contents = $this->_get_contents($public_path, $file); + function _compare($sandbox_path, $public_path, $file, $addontype) { + $sandbox_contents = $this->_get_contents($sandbox_path, $file, $addontype); + $public_contents = $this->_get_contents($public_path, $file, $addontype); $diff = ""; if ($sandbox_contents === false) { @@ -387,9 +400,21 @@ class FilesController extends AppController $this->render('view', 'ajax'); } - function _get_contents($path, $file) { + /* $path must refer to a file that exists */ + function _get_contents($path, $file, $addontype) { $this->Amo->clean($path); + // Search engine. Safe to output directly + if ($addontype === ADDON_SEARCH) { + // We have to make sure that the file in $path and $file match. + // Otherwise we reproduce bug 461253 + if (substr($path, -(strlen($file))) == $file) { + return file_get_contents($path); + } else { + return false; + } + } + if (preg_match("/^(.+\.jar)\/(.+)$/is", $file, $matches)) { $file = $matches[1]; $jarfile = $matches[2]; |