/** * Makes sure that the file is a valid template set. The file can be packed * in any of the formats supported by the Unpacker class (.tar.gz, .tar.bz2 * and .zip as of the time of writing these lines) * Returns true if the template is valid or a negative value carrying an * error code. * * @param file The file that contains the template set * @return Returns true (positive value) if template set is ok or a negative * value otherwise. */ function checkTemplateSet($file, $filePath) { // get the temporary folder $config =& Config::getConfig(); $tmpFolder = $config->getValue('temp_folder'); if ($tmpFolder[strlen($tmpFolder) - 1] != '/') { $tmpFolder .= '/'; } // get the name of the file, which we will use in many places $fileNameParts = explode('.', $file); $fileNameNoExt = $fileNameParts[0]; // create our working folder $workFolder = $tmpFolder . File::getTempName() . '/'; if (!File::createDir($workFolder, 0777)) { return TEMPLATE_SANDBOX_ERROR_CREATING_WORKING_FOLDER; } // now we can unpack the file to the temporary folder $unpacker = new Unpacker(); if (!$unpacker->unpack($filePath . $file, $workFolder)) { $this->cleanUp($workFolder . $fileNameNoExt); if (File::exists($workFolder)) { File::delete($workFolder); } return TEMPLATE_SANDBOX_ERROR_UNPACKING; } // if the file was correctly unpacked, now we will need the TemplateValidator // class to do some work for us $fileNameParts = explode('.', $file); $fileNameNoExt = $fileNameParts[0]; // we can use the checkTenmplateFolder which will do all the rest of // the work for us... $res = $this->checkTemplateFolder($fileNameNoExt, $workFolder); if ($res < 0) { //$this->cleanUp( $workFolder.$fileNameNoExt ); $this->cleanUp($workFolder); if (File::isReadable($workFolder) && File::isDir($workFolder)) { File::delete($workFolder); } return $res; } $this->cleanUp($workFolder . $fileNameNoExt); File::delete($workFolder); return true; }