set('addons', $this->Amo->addonTypes); } /** * Add new or new version of an add-on * @param int $id */ function add($id = 0) { $this->layout = 'developers'; $this->set('addonTypes', $this->Amo->addonTypes); //Step 2: Parse uploaded file and if correct, display addon-wide information form if (isset($this->data['Addon']['add_step1'])) { //Check for model validation first (in step 1, this is just addon type) if (!$this->Addon->validates($this->data)) { $this->validateErrors(); $this->set('fileError', ''); $this->render('add_step1'); die(); } //Check for file upload errors if ($this->data['Addon']['file']['error'] !== 0) { $this->Addon->invalidate('file'); $fileErrors = array('1' => 'Exceeds maximum upload size', '2' => 'Exceeds maximum upload size', '3' => 'Incomplete transfer', '4' => 'No file uploaded' ); $fileError = $fileErrors[$this->data['Addon']['file']['error']]; $this->set('fileError', $fileError); $this->render('add_step1'); die(); } $fileName = $this->data['Addon']['file']['name']; $fileExtension = substr($fileName, strrpos($fileName, '.')); $allowedExtensions = array('.xpi', '.jar', '.src'); //Check for file extenion match if (!in_array($fileExtension, $allowedExtensions)) { $this->Addon->invalidate('file'); $this->set('fileError', 'Disallowed file extension ('.$fileExtension.')'); $this->render('add_step1'); die(); } echo('test'); //Move temporary file to repository $uploadedFile = $this->data['Addon']['file']['tmp_name']; $tempLocation = REPO_PATH.'/temp/'.$fileName; if (move_uploaded_file($uploadedFile, $tempLocation)) { $uploadedFile = $tempLocation; chmod($uploadedFile, 0644); } else { $this->Addon->invalidate('file'); $this->set('fileError', 'Could not move file'); $this->render('add_step1'); die(); } //Search plugins do not have install.rdf to parse if ($this->Amo->addonTypes[$this->data['Addon']['addontype_id']] != 'Search Plugin') { //Find install.rdf in the package and get contents $manifestExists = false; if ($zip = @zip_open($uploadedFile)) { while ($zipEntry = zip_read($zip)) { if (zip_entry_name($zipEntry) == 'install.rdf') { $manifestExists = true; if (zip_entry_open($zip, $zipEntry, 'r')) { $fileContents = zip_entry_read($zipEntry, zip_entry_filesize($zipEntry)); zip_entry_close($zipEntry); } } } zip_close($zip); } //Make sure install.rdf is there if ($manifestExists !== true) { $this->Addon->invalidate('file'); $this->set('fileError', 'No install.rdf present'); $this->render('add_step1'); die(); } //Use Rdf Component to parse install.rdf $manifestData = $this->Rdf->parseInstallManifest($fileContents); //If the result is a string, it is an error message if (!is_array($manifestData)) { $this->Addon->invalidate('file'); $this->set('fileError', 'The following error occurred while parsing install.rdf: '.$manifestData); $this->render('add_step1'); die(); } //Check if install.rdf has an updateURL if (isset($manifestData['updateURL'])) { $this->Addon->invalidate('file'); $this->set('fileError', 'Add-ons cannot use an external updateURL. Please remove this from install.rdf and try again.'); $this->render('add_step1'); die(); } //Check the GUID if (!isset($manifestData['id']) || !preg_match('/^(\{[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\}|[a-z0-9-\._]*\@[a-z0-9-\._]+)$/i', $manifestData['id'])) { $this->Addon->invalidate('file'); $this->set('fileError', 'The ID of this add-on is invalid or not set.'); $this->render('add_step1'); die(); } //Make sure version has no spaces if (!isset($manifestData['version']) || preg_match('/.*\s.*/', $manifestData['version'])) { $this->Addon->invalidate('file'); $this->set('fileError', 'The version of this add-on is invalid or not set. Versions cannot contain spaces.'); $this->render('add_step1'); die(); } //These are arrays by locale $addonNames = $manifestData['name']; $addonDesc = $manifestData['description']; //If adding a new version to existing addon, check author $existing = $this->Addon->findAllByGuid($manifestData['id']); } //If it is a search plugin, read the .src file else { } $this->render('add_step2'); } elseif (isset($this->data['Addon']['add_step2'])) { $this->render('add_step3'); } elseif (isset($this->data['Addon']['add_step3'])) { $this->render('add_step4'); } //Step 1: Add-on type and file upload else { if ($id != 0) { //updating add-on } $this->set('fileError', ''); $this->render('add_step1'); } } /** * Manage an add-on * @param int $id */ function manage($id) { } /** * Edit add-on * @param int $id */ function edit($id) { } /** * Edit a version * @param int $id */ function editVersion($id) { } } ?>