private function __export() { $sql_schema = $sql_data = NULL; require_once dirname(__FILE__) . '/lib/class.mysqldump.php'; $dump = new MySQLDump($this->_Parent->Database); $tables = array('tbl_authors', 'tbl_cache', 'tbl_entries', 'tbl_extensions', 'tbl_extensions_delegates', 'tbl_fields', 'tbl_fields_%', 'tbl_forgotpass', 'tbl_pages', 'tbl_pages_types', 'tbl_sections', 'tbl_sections_association'); ## Grab the schema foreach ($tables as $t) { $sql_schema .= $dump->export($t, MySQLDump::STRUCTURE_ONLY); } $sql_schema = str_replace('`' . $this->_Parent->Configuration->get('tbl_prefix', 'database'), '`tbl_', $sql_schema); $sql_schema = preg_replace('/AUTO_INCREMENT=\\d+/i', '', $sql_schema); $tables = array('tbl_entries', 'tbl_extensions', 'tbl_extensions_delegates', 'tbl_fields', 'tbl_pages', 'tbl_pages_types', 'tbl_sections', 'tbl_sections_association'); ## Field data and entry data schemas needs to be apart of the workspace sql dump $sql_data = $dump->export('tbl_fields_%', MySQLDump::ALL); $sql_data .= $dump->export('tbl_entries_%', MySQLDump::ALL); ## Grab the data foreach ($tables as $t) { $sql_data .= $dump->export($t, MySQLDump::DATA_ONLY); } $sql_data = str_replace('`' . $this->_Parent->Configuration->get('tbl_prefix', 'database'), '`tbl_', $sql_data); $config_string = NULL; $config = $this->_Parent->Configuration->get(); unset($config['symphony']['build']); unset($config['symphony']['cookie_prefix']); unset($config['general']['useragent']); unset($config['file']['write_mode']); unset($config['directory']['write_mode']); unset($config['database']['host']); unset($config['database']['port']); unset($config['database']['user']); unset($config['database']['password']); unset($config['database']['db']); unset($config['database']['tbl_prefix']); unset($config['region']['timezone']); foreach ($config as $group => $set) { foreach ($set as $key => $val) { $config_string .= "\t\t\$conf['" . $group . "']['" . $key . "'] = '" . $val . "';" . self::CRLF; } } $install_template = str_replace(array('<!-- BUILD -->', '<!-- VERSION -->', '<!-- ENCODED SQL SCHEMA DUMP -->', '<!-- ENCODED SQL DATA DUMP -->', '<!-- CONFIGURATION -->'), array($this->_Parent->Configuration->get('build', 'symphony'), $this->_Parent->Configuration->get('version', 'symphony'), base64_encode($sql_schema), base64_encode($sql_data), trim($config_string)), file_get_contents(dirname(__FILE__) . '/lib/installer.tpl')); $archive = new ZipArchive(); $res = $archive->open(TMP . '/install.tmp.zip', ZipArchive::CREATE); if ($res === TRUE) { $archive->addFromString('workspace/install.sql', $sql_data); } $archive->close(); header('Content-type: application/octet-stream'); header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT'); header('Content-disposition: attachment; filename=' . Lang::createFilename($this->_Parent->Configuration->get('sitename', 'general')) . '-install.zip'); header('Pragma: no-cache'); readfile(TMP . '/install.tmp.zip'); unlink(TMP . '/install.tmp.zip'); exit; }
public function processRawFieldData($data, &$status, $simulate = false, $entry_id = NULL) { $status = self::__OK__; ## Its not an array, so just retain the current data and return if (!is_array($data)) { $status = self::__OK__; // Do a simple reconstruction of the file meta information. This is a workaround for // bug which causes all meta information to be dropped return array('file' => $data, 'mimetype' => self::__sniffMIMEType($data), 'size' => filesize(WORKSPACE . $data), 'meta' => serialize(self::getMetaInfo(WORKSPACE . $data, self::__sniffMIMEType($data)))); } if ($simulate) { return; } if ($data['error'] == UPLOAD_ERR_NO_FILE || $data['error'] != UPLOAD_ERR_OK) { return; } ## Sanitize the filename $data['name'] = Lang::createFilename($data['name']); ## Resize image, if it's an image if (getimagesize($data['tmp_name'])) { try { $thumb = PhpThumbFactory::create($data['tmp_name']); } catch (Exception $e) { $message = __('There was an error while trying to resize the image <code>%1$s</code>.', array($data['name'])); $status = self::__ERROR_CUSTOM__; return; } $thumb->resize($this->get('max_width'), $this->get('max_height'))->save($data['tmp_name']); } ## Upload the new file $abs_path = DOCROOT . '/' . trim($this->get('destination'), '/'); $rel_path = str_replace('/workspace', '', $this->get('destination')); if (!General::uploadFile($abs_path, $data['name'], $data['tmp_name'], Symphony::Configuration()->get('write_mode', 'file'))) { $message = __('There was an error while trying to upload the file <code>%1$s</code> to the target directory <code>%2$s</code>.', array($data['name'], 'workspace/' . ltrim($rel_path, '/'))); $status = self::__ERROR_CUSTOM__; return; } $status = self::__OK__; $file = rtrim($rel_path, '/') . '/' . trim($data['name'], '/'); if ($entry_id) { $row = $this->Database->fetchRow(0, "SELECT * FROM `tbl_entries_data_" . $this->get('id') . "` WHERE `entry_id` = '{$entry_id}' LIMIT 1"); $existing_file = rtrim($rel_path, '/') . '/' . trim(basename($row['file']), '/'); if (strtolower($existing_file) != strtolower($file) && file_exists(WORKSPACE . $existing_file)) { General::deleteFile(WORKSPACE . $existing_file); } } ## If browser doesn't send MIME type (e.g. .flv in Safari) if (strlen(trim($data['type'])) == 0) { $data['type'] = 'unknown'; } return array('file' => $file, 'size' => $data['size'], 'mimetype' => $data['type'], 'meta' => serialize(self::getMetaInfo(WORKSPACE . $file, $data['type']))); }
public function action() { $this->_existing_file = isset($this->_context[1]) ? $this->_context[1] . '.xsl' : NULL; if (array_key_exists('save', $_POST['action']) || array_key_exists('done', $_POST['action'])) { $fields = $_POST['fields']; $this->_errors = array(); if (!isset($fields['name']) || trim($fields['name']) == '') { $this->_errors['name'] = __('Name is a required field.'); } if (!isset($fields['body']) || trim($fields['body']) == '') { $this->_errors['body'] = __('Body is a required field.'); } elseif (!General::validateXML($fields['body'], $errors, false, new XSLTProcess())) { $this->_errors['body'] = __('This document is not well formed. The following error was returned: <code>%s</code>', array($errors[0]['message'])); } $fields['name'] = Lang::createFilename($fields['name']); if (General::right($fields['name'], 4) != '.xsl') { $fields['name'] .= '.xsl'; } $file = UTILITIES . '/' . $fields['name']; ##Duplicate if ($this->_context[0] == 'edit' && ($this->_existing_file != $fields['name'] && is_file($file))) { $this->_errors['name'] = __('A Utility with that name already exists. Please choose another.'); } elseif ($this->_context[0] == 'new' && is_file($file)) { $this->_errors['name'] = __('A Utility with that name already exists. Please choose another.'); } if (empty($this->_errors)) { if ($this->_context[0] == 'new') { /** * Just before the Utility has been created * * @delegate UtilityPreCreate * @since Symphony 2.2 * @param string $context * '/blueprints/utilities/' * @param string $file * The path to the Utility file * @param string $contents * The contents of the `$fields['body']`, passed by reference */ Symphony::ExtensionManager()->notifyMembers('UtilityPreCreate', '/blueprints/utilities/', array('file' => $file, 'contents' => &$fields['body'])); } else { /** * Just before the Utility has been updated * * @delegate UtilityPreEdit * @since Symphony 2.2 * @param string $context * '/blueprints/utilities/' * @param string $file * The path to the Utility file * @param string $contents * The contents of the `$fields['body']`, passed by reference */ Symphony::ExtensionManager()->notifyMembers('UtilityPreEdit', '/blueprints/utilities/', array('file' => $file, 'contents' => &$fields['body'])); } ##Write the file if (!($write = General::writeFile($file, $fields['body'], Symphony::Configuration()->get('write_mode', 'file')))) { $this->pageAlert(__('Utility could not be written to disk. Please check permissions on <code>/workspace/utilities</code>.'), Alert::ERROR); } else { ## Remove any existing file if the filename has changed if ($this->_existing_file && $file != UTILITIES . '/' . $this->_existing_file) { General::deleteFile(UTILITIES . '/' . $this->_existing_file); } if ($this->_context[0] == 'new') { /** * Just after the Utility has been written to disk * * @delegate UtilityPostCreate * @since Symphony 2.2 * @param string $context * '/blueprints/utilities/' * @param string $file * The path to the Utility file */ Symphony::ExtensionManager()->notifyMembers('UtilityPostCreate', '/blueprints/utilities/', array('file' => $file)); } else { /** * Just after a Utility has been edited and written to disk * * @delegate UtilityPostEdit * @since Symphony 2.2 * @param string $context * '/blueprints/utilities/' * @param string $file * The path to the Utility file */ Symphony::ExtensionManager()->notifyMembers('UtilityPostEdit', '/blueprints/utilities/', array('file' => $file)); } redirect(SYMPHONY_URL . '/blueprints/utilities/edit/' . str_replace('.xsl', '', $fields['name']) . '/' . ($this->_context[0] == 'new' ? 'created' : 'saved') . '/'); } } } elseif ($this->_context[0] == 'edit' && @array_key_exists('delete', $_POST['action'])) { /** * Prior to deleting the Utility * * @delegate UtilityPreDelete * @since Symphony 2.2 * @param string $context * '/blueprints/utilities/' * @param string $file * The path to the Utility file */ Symphony::ExtensionManager()->notifyMembers('UtilityPreDelete', '/blueprints/utilities/', array('file' => $this->_existing_file)); General::deleteFile(UTILITIES . '/' . $this->_existing_file); redirect(SYMPHONY_URL . '/blueprints/components/'); } }
public function processRawFieldData($data, &$status, $simulate = false, $entry_id = NULL) { $status = self::__OK__; //fixes bug where files are deleted, but their database entries are not. if ($data === NULL) { return array('file' => NULL, 'mimetype' => NULL, 'size' => NULL, 'meta' => NULL); } // Its not an array, so just retain the current data and return if (!is_array($data)) { $status = self::__OK__; // Ensure the file exists in the `WORKSPACE` directory // @link http://symphony-cms.com/discuss/issues/view/610/ $file = WORKSPACE . preg_replace(array('%/+%', '%(^|/)\\.\\./%'), '/', $data); $result = array('file' => $data, 'mimetype' => NULL, 'size' => NULL, 'meta' => NULL); // Grab the existing entry data to preserve the MIME type and size information if (isset($entry_id) && !is_null($entry_id)) { $row = Symphony::Database()->fetchRow(0, sprintf("SELECT `file`, `mimetype`, `size`, `meta` FROM `tbl_entries_data_%d` WHERE `entry_id` = %d", $this->get('id'), $entry_id)); if (!empty($row)) { $result = $row; } } if (!file_exists($file) || !is_readable($file)) { $status = self::__INVALID_FIELDS__; return $result; } else { if (empty($result['mimetype'])) { $result['mimetype'] = function_exists('mime_content_type') ? mime_content_type($file) : 'application/octet-stream'; } if (empty($result['size'])) { $result['size'] = filesize($file); } if (empty($result['meta'])) { $result['meta'] = serialize(self::getMetaInfo($file, $result['mimetype'])); } } return $result; } if ($simulate && is_null($entry_id)) { return $data; } // Upload the new file $abs_path = DOCROOT . '/' . trim($this->get('destination'), '/'); $rel_path = str_replace('/workspace', '', $this->get('destination')); $existing_file = NULL; if (!is_null($entry_id)) { $row = Symphony::Database()->fetchRow(0, sprintf("SELECT * FROM `tbl_entries_data_%s` WHERE `entry_id` = %d LIMIT 1", $this->get('id'), $entry_id)); $existing_file = '/' . trim($row['file'], '/'); // File was removed if ($data['error'] == UPLOAD_ERR_NO_FILE && !is_null($existing_file) && is_file(WORKSPACE . $existing_file)) { General::deleteFile(WORKSPACE . $existing_file); } } if ($data['error'] == UPLOAD_ERR_NO_FILE || $data['error'] != UPLOAD_ERR_OK) { return; } // Sanitize the filename $data['name'] = Lang::createFilename($data['name']); if (!General::uploadFile($abs_path, $data['name'], $data['tmp_name'], Symphony::Configuration()->get('write_mode', 'file'))) { $message = __('There was an error while trying to upload the file <code>%1$s</code> to the target directory <code>%2$s</code>.', array($data['name'], 'workspace/' . ltrim($rel_path, '/'))); $status = self::__ERROR_CUSTOM__; return; } $status = self::__OK__; $file = rtrim($rel_path, '/') . '/' . trim($data['name'], '/'); // File has been replaced if (!is_null($existing_file) && strtolower($existing_file) != strtolower($file) && is_file(WORKSPACE . $existing_file)) { General::deleteFile(WORKSPACE . $existing_file); } // If browser doesn't send MIME type (e.g. .flv in Safari) if (strlen(trim($data['type'])) == 0) { $data['type'] = function_exists('mime_content_type') ? mime_content_type($file) : 'application/octet-stream'; } return array('file' => $file, 'size' => $data['size'], 'mimetype' => $data['type'], 'meta' => serialize(self::getMetaInfo(WORKSPACE . $file, $data['type']))); }
function checkPostFieldData($data, &$message, $entry_id = NULL) { /* UPLOAD_ERR_OK Value: 0; There is no error, the file uploaded with success. UPLOAD_ERR_INI_SIZE Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini. UPLOAD_ERR_FORM_SIZE Value: 2; The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form. UPLOAD_ERR_PARTIAL Value: 3; The uploaded file was only partially uploaded. UPLOAD_ERR_NO_FILE Value: 4; No file was uploaded. UPLOAD_ERR_NO_TMP_DIR Value: 6; Missing a temporary folder. Introduced in PHP 4.3.10 and PHP 5.0.3. UPLOAD_ERR_CANT_WRITE Value: 7; Failed to write file to disk. Introduced in PHP 5.1.0. UPLOAD_ERR_EXTENSION Value: 8; File upload stopped by extension. Introduced in PHP 5.2.0. */ // Array // ( // [name] => filename.pdf // [type] => application/pdf // [tmp_name] => /tmp/php/phpYtdlCl // [error] => 0 // [size] => 16214 // ) $message = NULL; try { $this->S3->getBucket($this->get('bucket')); } catch (Exception $e) { $message = __('The bucket %s doesn\'t exist! Please update this section.', array($this->get('bucket'))); return self::__INVALID_FIELDS__; } if (empty($data) || isset($data['error']) && $data['error'] == UPLOAD_ERR_NO_FILE) { if ($this->get('required') == 'yes') { $message = __("'%s' is a required field.", array($this->get('label'))); return self::__MISSING_FIELDS__; } return self::__OK__; } ## Its not an array, so just retain the current data and return if (!is_array($data)) { return self::__OK__; } if ($data['error'] != UPLOAD_ERR_NO_FILE && $data['error'] != UPLOAD_ERR_OK) { switch ($data['error']) { case UPLOAD_ERR_INI_SIZE: $message = __('File chosen in "%1$s" exceeds the maximum allowed upload size of %2$s specified by your host.', array($this->get('label'), is_numeric(ini_get('upload_max_filesize')) ? General::formatFilesize(ini_get('upload_max_filesize')) : ini_get('upload_max_filesize'))); break; case UPLOAD_ERR_FORM_SIZE: $message = __('File chosen in "%1$s" exceeds the maximum allowed upload size of %2$s, specified by Symphony.', array($this->get('label'), General::formatFilesize(Symphony::Configuration()->get('max_upload_size', 'admin')))); break; case UPLOAD_ERR_PARTIAL: $message = __("File chosen in '%s' was only partially uploaded due to an error.", array($this->get('label'))); break; case UPLOAD_ERR_NO_TMP_DIR: $message = __("File chosen in '%s' was only partially uploaded due to an error.", array($this->get('label'))); break; case UPLOAD_ERR_CANT_WRITE: $message = __("Uploading '%s' failed. Could not write temporary file to disk.", array($this->get('label'))); break; case UPLOAD_ERR_EXTENSION: $message = __("Uploading '%s' failed. File upload stopped by extension.", array($this->get('label'))); break; } return self::__ERROR_CUSTOM__; } ## Sanitize the filename $data['name'] = Lang::createFilename($data['name']); ## uniq the filename if ($this->get('unique_filename') == true && isset($data['name'])) { $this->getUniqueFilename($data['name']); } if ($this->get('validator') != NULL) { $rule = $this->get('validator'); if (!General::validateString($data['name'], $rule)) { $message = __("File chosen in '%s' does not match allowable file types for that field.", array($this->get('label'))); return self::__INVALID_FIELDS__; } } ## check if the file exists since we can't check directly through the s3 library, the file field is unique $row = Symphony::Database()->fetchRow(0, "SELECT * FROM `tbl_entries_data_" . $this->get('id') . "` WHERE `file`='" . $data['name'] . "'"); if (isset($row['file'])) { $message = __('A file with the name %1$s already exists at that bucket. Please rename the file first, or choose another.', array($data['name'])); return self::__INVALID_FIELDS__; } return self::__OK__; }
public function generatePDFAttachments(&$output) { $params = Frontend::Page()->_param; $dom = new DOMDocument('1.0', 'UTF-8'); $doc->formatOutput = true; $dom->loadHTML($output); if ($dom === false) { return $output; } $xpath = new DOMXPath($dom); // Copy any <link rel='stylesheet'/> or <style type='text/css'> prepend to the blocks $css = ''; $styling = $xpath->query('//link[@rel="stylesheet"] | //style[@type="text/css"]'); if ($styling->length !== 0) { foreach ($styling as $style) { $css .= $dom->saveXML($style); } } // Find anything with @data-utp attribute set to attachment $blocks = $xpath->query('//*[@data-utp = "attachment"]'); if ($blocks->length !== 0) { foreach ($blocks as $block) { // Get the content in those blocks $data = $dom->saveXML($block); // Send the block to the PDF generator, saving it in /TMP $data = $css . $data; $pdf = self::initPDF(); // output the HTML content $pdf->writeHTML($data, true, false, true, false, ''); // reset pointer to the last page $pdf->lastPage(); // get the output of the PDF as a string and save it to a file // attempt to find the filename if it's provided with @data-utp-filename if (!($filename = $xpath->evaluate('string(//@data-utp-filename)'))) { $filename = md5(sprintf('%s - %s', $params['website-name'], $params['page-title'])); } $filename = TMP . '/' . Lang::createFilename($filename) . '.pdf'; General::writeFile($filename, $pdf->Output($filename, 'S'), Symphony::Configuration()->get('write_mode', 'file')); // Replace the attachment node with <link rel='attachment' href='{path/to/file}' /> $link = $dom->createElement('link'); $link->setAttribute('rel', 'attachment'); $link->setAttribute('href', str_replace(DOCROOT, URL, $filename)); $block->parentNode->replaceChild($link, $block); } } $output = $dom->saveHTML(); }
public function action() { if (!array_key_exists('save', $_POST['action']) && !array_key_exists('done', $_POST['action'])) { return; } $fields = $_POST['fields']; $this->_errors = array(); if (!isset($fields['name']) || strlen(trim($fields['name'])) == 0) { $this->_errors['name'] = 'Name is a required field.'; } else { $filename = strtolower(Lang::createFilename($fields['name'] . '.task')); $file = realpath(MANIFEST . '/cron') . '/' . $filename; ##Duplicate if (file_exists($file)) { $this->_errors['name'] = __('A task with that name already exists. Please choose another.'); } } if (!isset($fields['command']) || strlen(trim($fields['command'])) == 0) { $this->_errors['command'] = 'Command is a required field.'; } if (!isset($fields['interval']) || strlen(trim($fields['interval'])) == 0) { $this->_errors['interval'] = 'Interval is a required field.'; } elseif (!is_numeric($fields['interval']) || (int) $fields['interval'] == 0) { $this->_errors['interval'] = 'Interval must be a positive integer value.'; } if (isset($fields['start']) && strlen(trim($fields['start'])) > 0) { $time = strtotime($fields['start']); $info = getdate($time); if ($time == false || $info == false || !checkdate($info['mon'], $info['mday'], $info['year'])) { $this->_errors['start'] = 'Start Date is invalid.'; } } if (isset($fields['finish']) && strlen(trim($fields['finish'])) > 0) { $time = strtotime($fields['finish']); $info = getdate($time); if ($time == false || $info === false || !checkdate($info['mon'], $info['mday'], $info['year'])) { $this->_errors['finish'] = 'Finish Date is invalid.'; } elseif (!isset($this->_errors['start']) && isset($fields['start']) && strlen(trim($fields['start'])) > 0) { if (strtotime($fields['finish']) <= strtotime($fields['start'])) { $this->_errors['finish'] = 'Finish Date must occur <strong>after</strong> Start Date.'; } } } if (empty($this->_errors)) { $task = new Lib\CronTask(Symphony::Database()); $task->path = $file; $task->filename = $filename; $task->name = $fields['name']; $task->command = $fields['command']; $task->setInterval($fields['interval'], $fields['interval-type']); $task->start = strlen(trim($fields['start'])) > 0 ? strtotime($fields['start']) : null; $task->finish = strlen(trim($fields['finish'])) > 0 ? strtotime($fields['finish']) : null; $task->description = $fields['description']; $task->enabled = isset($fields['enabled']) ? true : false; try { $task->save(function ($file, $data) { return General::writeFile($file, $data, Symphony::Configuration()->get('write_mode', 'file')); }); redirect(sprintf("%sedit/%s/created/", preg_replace('/new\\/$/', '', Administration::instance()->getCurrentPageURL()), $filename)); } catch (\Exception $e) { $this->pageAlert($e->getMessage()); } } }
protected function processFileUpload($key) { $value = array(); $file = $_FILES[$key]; if (empty($file) || empty($file['name']) || empty($file['tmp_name'])) { return $value; } $size = intval($file['size']); $ext = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION)); $filename = $file['name']; if ($size > self::MAX_SIZE) { throw new Exception(sprintf("File is too big: %d when the max is %d", $size, self::MAX_SIZE)); } if (!$ext || !in_array($ext, self::$EXT)) { throw new Exception(sprintf("File '%s' is not allowed. Please upload '%s' files only", $filename, implode(', ', self::$EXT))); } // unique file name $filename = time() . '-' . Lang::createFilename($file['name']); $value['file'] = self::DIR . $filename; $value['size'] = $size; // make a copy - to have the good name and ext $ret = General::uploadFile(WORKSPACE . self::DIR, $filename, $file['tmp_name'], Symphony::Configuration()->get('write_mode', 'file')); if ($ret) { return $value; } else { throw new Exception(sprintf('Could not save file `%s`. ', $filename)); } return null; }
private function __createZipArchive($config_template, $sql_schema, $sql_data) { if (!is_writable(DOCROOT . '/manifest/tmp')) { Administration::instance()->Page->pageAlert(__('Check permissions for the /manifest/tmp directory.'), Alert::ERROR); } else { $archive = new ZipArchive(); $res = $archive->open(TMP . '/ensemble.tmp.zip', ZipArchive::CREATE); if ($res === TRUE) { $this->__addFolderToArchive($archive, 'extensions', DOCROOT); $this->__addFolderToArchive($archive, 'symphony', DOCROOT); $this->__addFolderToArchive($archive, 'workspace', DOCROOT); $this->__addFolderToArchive($archive, 'install', DOCROOT); $this->__addFolderToArchive($archive, 'vendor', DOCROOT); $archive->addFromString('install/includes/config_default.php', $config_template); $archive->addFromString('install/includes/install.sql', $sql_schema); $archive->addFromString('workspace/install.sql', $sql_data); $archive->addFile(DOCROOT . '/index.php', 'index.php'); $readme_files = glob(DOCROOT . '/README.*'); if (is_array($readme_files) && !empty($readme_files)) { foreach ($readme_files as $filename) { $archive->addFile($filename, basename($filename)); } } if (is_file(DOCROOT . '/README')) { $archive->addFile(DOCROOT . '/README', 'README'); } if (is_file(DOCROOT . '/LICENCE')) { $archive->addFile(DOCROOT . '/LICENCE', 'LICENCE'); } if (is_file(DOCROOT . '/update.php')) { $archive->addFile(DOCROOT . '/update.php', 'update.php'); } // Remove logs $archive->deleteName('install/logs/install'); $archive->deleteName('install/logs/update'); } $archive->close(); header('Content-type: application/octet-stream'); header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT'); header(sprintf('Content-disposition: attachment; filename=%s-ensemble.zip', Lang::createFilename(Symphony::Configuration()->get('sitename', 'general')))); header('Pragma: no-cache'); readfile(TMP . '/ensemble.tmp.zip'); unlink(TMP . '/ensemble.tmp.zip'); exit; } }
public function processRawFieldData($data, &$status, &$message = null, $simulate = false, $entry_id = null) { $status = self::__OK__; // No file given, save empty data: if ($data === null) { return array('file' => null, 'mimetype' => null, 'size' => null, 'meta' => null); } // Its not an array, so just retain the current data and return: if (is_array($data) === false) { $file = $this->getFilePath(basename($data)); $result = array('file' => $data, 'mimetype' => null, 'size' => null, 'meta' => null); // Grab the existing entry data to preserve the MIME type and size information if (isset($entry_id)) { $row = Symphony::Database()->fetchRow(0, sprintf("SELECT `file`, `mimetype`, `size`, `meta` FROM `tbl_entries_data_%d` WHERE `entry_id` = %d", $this->get('id'), $entry_id)); if (empty($row) === false) { $result = $row; } } // Found the file, add any missing meta information: if (file_exists($file) && is_readable($file)) { if (empty($result['mimetype'])) { $result['mimetype'] = General::getMimeType($file); } if (empty($result['size'])) { $result['size'] = filesize($file); } if (empty($result['meta'])) { $result['meta'] = serialize(self::getMetaInfo($file, $result['mimetype'])); } // The file was not found, or is unreadable: } else { $message = __('The file uploaded is no longer available. Please check that it exists, and is readable.'); $status = self::__INVALID_FIELDS__; } return $result; } if ($simulate && is_null($entry_id)) { return $data; } // Check to see if the entry already has a file associated with it: if (is_null($entry_id) === false) { $row = Symphony::Database()->fetchRow(0, sprintf("SELECT *\n FROM `tbl_entries_data_%s`\n WHERE `entry_id` = %d\n LIMIT 1", $this->get('id'), $entry_id)); $existing_file = isset($row['file']) ? $this->getFilePath($row['file']) : null; // File was removed: if ($data['error'] == UPLOAD_ERR_NO_FILE && !is_null($existing_file) && is_file($existing_file)) { General::deleteFile($existing_file); } } // Do not continue on upload error: if ($data['error'] == UPLOAD_ERR_NO_FILE || $data['error'] != UPLOAD_ERR_OK) { return false; } // Where to upload the new file? $abs_path = DOCROOT . '/' . trim($this->get('destination'), '/'); $rel_path = str_replace('/workspace', '', $this->get('destination')); // Sanitize the filename $data['name'] = Lang::createFilename($data['name']); // If a file already exists, then rename the file being uploaded by // adding `_1` to the filename. If `_1` already exists, the logic // will keep adding 1 until a filename is available (#672) if (file_exists($abs_path . '/' . $data['name'])) { $extension = General::getExtension($data['name']); $new_file = substr($abs_path . '/' . $data['name'], 0, -1 - strlen($extension)); $renamed_file = $new_file; $count = 1; do { $renamed_file = $new_file . '_' . $count . '.' . $extension; $count++; } while (file_exists($renamed_file)); // Extract the name filename from `$renamed_file`. $data['name'] = str_replace($abs_path . '/', '', $renamed_file); } $file = $this->getFilePath($data['name']); // Attempt to upload the file: $uploaded = General::uploadFile($abs_path, $data['name'], $data['tmp_name'], Symphony::Configuration()->get('write_mode', 'file')); if ($uploaded === false) { $message = __('There was an error while trying to upload the file %1$s to the target directory %2$s.', array('<code>' . $data['name'] . '</code>', '<code>workspace/' . ltrim($rel_path, '/') . '</code>')); $status = self::__ERROR_CUSTOM__; return false; } // File has been replaced: if (isset($existing_file) && $existing_file !== $file && is_file($existing_file)) { General::deleteFile($existing_file); } // Get the mimetype, don't trust the browser. RE: #1609 $data['type'] = General::getMimeType($file); return array('file' => basename($file), 'size' => $data['size'], 'mimetype' => $data['type'], 'meta' => serialize(self::getMetaInfo($file, $data['type']))); }
public function __actionEdit() { $this->_existing_file = isset($this->_context[1]) ? $this->_context[1] . '.xsl' : NULL; if (array_key_exists('save', $_POST['action']) || array_key_exists('done', $_POST['action'])) { $fields = $_POST['fields']; //$this->errors = array(); if (!isset($fields['name']) || trim($fields['name']) == '') { $this->errors->name = __('Name is a required field.'); } if (!isset($fields['template']) || trim($fields['template']) == '') { $this->errors->template = __('XSLT is a required field.'); } elseif (!General::validateXML($fields['template'], $errors)) { $fragment = $this->createDocumentFragment(); $fragment->appendChild(new DOMText(__('This document is not well formed. The following error was returned: '))); $fragment->appendChild($this->createElement('code', $errors->current()->message)); $this->errors->template = $fragment; } if (!$this->errors->valid()) { $fields['name'] = Lang::createFilename($fields['name']); if (General::right($fields['name'], 4) != '.xsl') { $fields['name'] .= '.xsl'; } $file = UTILITIES . '/' . $fields['name']; // TODO: Does it really need stripslashed? Funky. $fields['template'] = stripslashes($fields['template']); ##Duplicate if ($this->_context[0] == 'edit' && ($this->_existing_file != $fields['name'] && is_file($file))) { $this->errors->name = __('A Utility with that name already exists. Please choose another.'); } elseif ($this->_context[0] == 'new' && is_file($file)) { $this->errors->name = __('A Utility with that name already exists. Please choose another.'); } elseif (!($write = General::writeFile($file, $fields['template'], Symphony::Configuration()->core()->symphony->{'file-write-mode'}))) { $this->alerts()->append(__('Utility could not be written to disk. Please check permissions on <code>/workspace/utilities</code>.'), AlertStack::SUCCESS); } else { ## Remove any existing file if the filename has changed if ($this->_existing_file && $file != UTILITIES . '/' . $this->_existing_file) { General::deleteFile(UTILITIES . '/' . $this->_existing_file); } ## FIXME: Fix this delegate ### # Delegate: Edit # Description: After saving the asset, the file path is provided. //Extension::notify('Edit', getCurrentPage(), array('file' => $file)); redirect(ADMIN_URL . '/blueprints/utilities/edit/' . str_replace('.xsl', '', $fields['name']) . '/' . ($this->_context[0] == 'new' ? 'created' : 'saved') . '/'); } } } elseif ($this->_context[0] == 'edit' && array_key_exists('delete', $_POST['action'])) { ## FIXME: Fix this delegate ### # Delegate: Delete # Description: Prior to deleting the asset file. Target file path is provided. //Extension::notify('Delete', getCurrentPage(), array('file' => WORKSPACE . '/' . $this->_existing_file_rel)); $this->__actionDelete(UTILITIES . '/' . $this->_existing_file, ADMIN_URL . '/blueprints/components/'); } }
public function processRawFieldData($data, &$status, &$message = null, $simulate = false, $entry_id = NULL) { $status = self::__OK__; //fixes bug where files are deleted, but their database entries are not. if ($data === NULL) { return array('file' => NULL, 'mimetype' => NULL, 'size' => NULL, 'meta' => NULL); } // It's not an array, so just retain the current data and return if (!is_array($data)) { // Ensure the file exists in the `WORKSPACE` directory // @link http://symphony-cms.com/discuss/issues/view/610/ $file = WORKSPACE . preg_replace(array('%/+%', '%(^|/)\\.\\./%'), '/', $data); $result = array('file' => $data, 'mimetype' => NULL, 'size' => NULL, 'meta' => NULL); // Grab the existing entry data to preserve the MIME type and size information if (isset($entry_id) && !is_null($entry_id)) { $row = Symphony::Database()->fetchRow(0, sprintf("SELECT `file`, `mimetype`, `size`, `meta` FROM `tbl_entries_data_%d` WHERE `entry_id` = %d", $this->get('id'), $entry_id)); if (!empty($row)) { $result = $row; } } if (!file_exists($file) || !is_readable($file)) { $message = __('The file uploaded is no longer available. Please check that it exists, and is readable.'); $status = self::__INVALID_FIELDS__; return $result; } else { if (empty($result['mimetype'])) { $result['mimetype'] = function_exists('mime_content_type') ? mime_content_type($file) : 'application/octet-stream'; } if (empty($result['size'])) { $result['size'] = filesize($file); } if (empty($result['meta'])) { $result['meta'] = serialize(self::getMetaInfo($file, $result['mimetype'])); } } return $result; } if ($simulate && is_null($entry_id)) { return $data; } //My special Select box alteration :P //var_dump($_POST['fields']['enhanced_upload_field'][$this->get('element_name')]['directory'],$_POST);die; //var_dump($_POST); // Upload the new file $override_path = $this->get('override') == 'yes' ? $_POST['fields']['enhanced_upload_field'][$this->get('element_name')]['directory'] : trim($this->get('destination')); $abs_path = DOCROOT . $override_path . '/'; $rel_path = str_replace('/workspace', '', $override_path); $existing_file = NULL; if (!is_null($entry_id)) { $row = Symphony::Database()->fetchRow(0, sprintf("SELECT * FROM `tbl_entries_data_%s` WHERE `entry_id` = %d LIMIT 1", $this->get('id'), $entry_id)); $existing_file = '/' . trim($row['file'], '/'); // File was removed if ($data['error'] == UPLOAD_ERR_NO_FILE && !is_null($existing_file) && is_file(WORKSPACE . $existing_file)) { General::deleteFile(WORKSPACE . $existing_file); } } if ($data['error'] == UPLOAD_ERR_NO_FILE || $data['error'] != UPLOAD_ERR_OK) { return false; } // If a file already exists, then rename the file being uploaded by // adding `_1` to the filename. If `_1` already exists, the logic // will keep adding 1 until a filename is available (#672) $new_file = $abs_path . '/' . $data['name']; if (file_exists($new_file)) { $i = 1; $extension = General::getExtension($data['name']); $renamed_file = $new_file; do { $renamed_file = General::left($new_file, -strlen($extension) - 1) . '_' . $i . '.' . $extension; $i++; } while (file_exists($renamed_file)); // Extract the name filename from `$renamed_file`. $data['name'] = str_replace($abs_path . '/', '', $renamed_file); } // Sanitize the filename $data['name'] = Lang::createFilename($data['name']); // Actually upload the file, moving it from PHP's temporary store to the desired destination if (!General::uploadFile($abs_path, $data['name'], $data['tmp_name'], Symphony::Configuration()->get('write_mode', 'file'))) { $message = __('There was an error while trying to upload the file %1$s to the target directory %2$s.', array('<code>' . $data['name'] . '</code>', '<code>workspace/' . ltrim($rel_path, '/') . '</code>')); $status = self::__ERROR_CUSTOM__; return false; } $file = rtrim($rel_path, '/') . '/' . trim($data['name'], '/'); // File has been replaced if (!is_null($existing_file) && strtolower($existing_file) != strtolower($file) && is_file(WORKSPACE . $existing_file)) { General::deleteFile(WORKSPACE . $existing_file); } // If browser doesn't send MIME type (e.g. .flv in Safari) if (strlen(trim($data['type'])) == 0) { $data['type'] = function_exists('mime_content_type') ? mime_content_type($file) : 'application/octet-stream'; } //var_dump($_POST); return array('file' => $file, 'size' => $data['size'], 'mimetype' => $data['type'], 'meta' => serialize(self::getMetaInfo(WORKSPACE . $file, $data['type']))); }
public function processRawFieldData($data, &$status, $simulate = false, $entry_id = NULL) { $status = self::__OK__; ## Its not an array, so just retain the current data and return if (!is_array($data)) { $status = self::__OK__; $file = WORKSPACE . $data; $result = array('file' => $data, 'mimetype' => NULL, 'size' => NULL, 'meta' => NULL); // Grab the existing entry data to preserve the MIME type and size information if (isset($entry_id) && !is_null($entry_id)) { $row = Symphony::Database()->fetchRow(0, sprintf("SELECT `file`, `mimetype`, `size`, `meta` FROM `tbl_entries_data_%d` WHERE `entry_id` = %d", $this->get('id'), $entry_id)); if (!empty($row)) { $result = $row; } } if (!file_exists($file) || !is_readable($file)) { $status = self::__INVALID_FIELDS__; return $result; } return $result; } if ($simulate) { return; } if (is_array($data) and isset($data['name'])) { $data['name'] = $this->getUniqueFilename($data['name']); } ## Upload the new file $abs_path = DOCROOT . '/' . trim($this->get('destination'), '/'); $rel_path = str_replace('/workspace', '', $this->get('destination')); $existing_file = NULL; if (!is_null($entry_id)) { $row = Symphony::Database()->fetchRow(0, sprintf("SELECT * FROM `tbl_entries_data_%s` WHERE `entry_id` = %d LIMIT 1", $this->get('id'), $entry_id)); $existing_file = rtrim($rel_path, '/') . '/' . trim(basename($row['file']), '/'); // File was removed if ($data['error'] == UPLOAD_ERR_NO_FILE && !is_null($existing_file) && file_exists(WORKSPACE . $existing_file)) { General::deleteFile(WORKSPACE . $existing_file); } } if ($data['error'] == UPLOAD_ERR_NO_FILE || $data['error'] != UPLOAD_ERR_OK) { return; } ## Sanitize the filename $data['name'] = Lang::createFilename($data['name']); // Do any pre-processing $meta = Image::getMetaInformation($data['tmp_name']); if ($this->get('resize_long_edge_dimension') != NULL and $meta->width > $this->get('resize_long_edge_dimension') || $meta->height > $this->get('resize_long_edge_dimension')) { try { $image = Image::load($data['tmp_name']); $dest_width = $dest_height = NULL; if ($image->Meta()->width > $image->Meta()->height) { $dest_width = $this->get('resize_long_edge_dimension'); } else { $dest_height = $this->get('resize_long_edge_dimension'); } $image->applyFilter('resize', array($dest_width, $dest_height)); $image->save($abs_path . '/' . $data['name'], 100); } catch (Exception $e) { $message = __('There was an error while trying to pre-process the file <code>%s</code>: %s.', array($data['name'], $e->getMessage())); $status = self::__ERROR_CUSTOM__; } } else { if (!General::uploadFile($abs_path, $data['name'], $data['tmp_name'], Symphony::Configuration()->get('write_mode', 'file'))) { $message = __('There was an error while trying to upload the file <code>%1$s</code> to the target directory <code>%2$s</code>.', array($data['name'], 'workspace/' . ltrim($rel_path, '/'))); $status = self::__ERROR_CUSTOM__; return; } } $status = self::__OK__; $file = rtrim($rel_path, '/') . '/' . trim($data['name'], '/'); // File has been replaced if (!is_null($existing_file) && strtolower($existing_file) != strtolower($file) && file_exists(WORKSPACE . $existing_file)) { General::deleteFile(WORKSPACE . $existing_file); } ## If browser doesn't send MIME type (e.g. .flv in Safari) if (strlen(trim($data['type'])) == 0) { $data['type'] = 'unknown'; } return array('file' => $file, 'size' => $data['size'], 'mimetype' => $data['type'], 'meta' => serialize(self::getMetaInfo(WORKSPACE . $file, $data['type']))); }
public function __get($name) { if ($name == 'handle') { return Lang::createFilename($this->about()->name); } }
function processRawFieldData($data, &$status, $simulate = false, $entry_id = NULL) { $status = self::__OK__; ## Its not an array, so just retain the current data and return if (!is_array($data)) { $status = self::__OK__; // Do a simple reconstruction of the file meta information. This is a workaround for // bug which causes all meta information to be dropped return array('file' => $data, 'mimetype' => self::__sniffMIMEType($data), 'size' => filesize(WORKSPACE . $data), 'meta' => serialize(self::getMetaInfo(WORKSPACE . $data, self::__sniffMIMEType($data)))); } if ($simulate) { return; } if ($data['error'] == UPLOAD_ERR_NO_FILE || $data['error'] != UPLOAD_ERR_OK) { return; } ## Sanitize the filename $data['name'] = Lang::createFilename($data['name']); ## Upload the new file $abs_path = DOCROOT . '/' . trim($this->get('destination'), '/'); $rel_path = str_replace('/workspace', '', $this->get('destination')); if (!General::uploadFile($abs_path, $data['name'], $data['tmp_name'], $this->_engine->Configuration->get('write_mode', 'file'))) { $message = __('There was an error while trying to upload the file <code>%1$s</code> to the target directory <code>%2$s</code>.', array($data['name'], 'workspace/' . $rel_path)); $status = self::__ERROR_CUSTOM__; return; } if ($entry_id) { $row = $this->Database->fetchRow(0, "SELECT * FROM `tbl_entries_data_" . $this->get('id') . "` WHERE `entry_id` = '{$entry_id}' LIMIT 1"); $existing_file = $abs_path . '/' . basename($row['file']); General::deleteFile($existing_file); } $status = self::__OK__; $file = rtrim($rel_path, '/') . '/' . trim($data['name'], '/'); return array('file' => $file, 'size' => $data['size'], 'mimetype' => $data['type'], 'meta' => serialize(self::getMetaInfo(WORKSPACE . $file, $data['type']))); }
function action() { $this->_existing_file = isset($this->_context[1]) ? $this->_context[1] . '.xsl' : NULL; if (array_key_exists('save', $_POST['action']) || array_key_exists('done', $_POST['action'])) { $fields = $_POST['fields']; $this->_errors = array(); if (!isset($fields['name']) || trim($fields['name']) == '') { $this->_errors['name'] = __('Name is a required field.'); } if (!isset($fields['body']) || trim($fields['body']) == '') { $this->_errors['body'] = __('Body is a required field.'); } elseif (!General::validateXML($fields['body'], $errors, false, new XSLTProcess())) { $this->_errors['body'] = __('This document is not well formed. The following error was returned: <code>%s</code>', array($errors[0]['message'])); } if (empty($this->_errors)) { $fields['name'] = Lang::createFilename($fields['name']); if (General::right($fields['name'], 4) != '.xsl') { $fields['name'] .= '.xsl'; } $file = UTILITIES . '/' . $fields['name']; ##Duplicate if ($this->_context[0] == 'edit' && ($this->_existing_file != $fields['name'] && is_file($file))) { $this->_errors['name'] = __('A Utility with that name already exists. Please choose another.'); } elseif ($this->_context[0] == 'new' && is_file($file)) { $this->_errors['name'] = __('A Utility with that name already exists. Please choose another.'); } elseif (!($write = General::writeFile($file, $fields['body'], $this->_Parent->Configuration->get('write_mode', 'file')))) { $this->pageAlert(__('Utility could not be written to disk. Please check permissions on <code>/workspace/utilities</code>.'), Alert::ERROR); } else { ## Remove any existing file if the filename has changed if ($this->_existing_file && $file != UTILITIES . '/' . $this->_existing_file) { General::deleteFile(UTILITIES . '/' . $this->_existing_file); } ## TODO: Fix me ### # Delegate: Edit # Description: After saving the asset, the file path is provided. //$ExtensionManager->notifyMembers('Edit', getCurrentPage(), array('file' => $file)); redirect(URL . '/symphony/blueprints/utilities/edit/' . str_replace('.xsl', '', $fields['name']) . '/' . ($this->_context[0] == 'new' ? 'created' : 'saved') . '/'); } } } elseif ($this->_context[0] == 'edit' && @array_key_exists('delete', $_POST['action'])) { ## TODO: Fix me ### # Delegate: Delete # Description: Prior to deleting the asset file. Target file path is provided. //$ExtensionManager->notifyMembers('Delete', getCurrentPage(), array('file' => WORKSPACE . '/' . $this->_existing_file_rel)); General::deleteFile(UTILITIES . '/' . $this->_existing_file); redirect(URL . '/symphony/blueprints/components/'); } }
public function processRawFieldData($data, &$status, &$message = null, $simulate = false, $entry_id = NULL) { $status = self::__OK__; //fixes bug where files are deleted, but their database entries are not. if ($data === NULL) { return array('file' => NULL, 'mimetype' => NULL, 'size' => NULL, 'meta' => NULL); } ## Its not an array, so just retain the current data and return (the case where we're not uploading a new file) if (!is_array($data)) { $result = array('file' => $data, 'mimetype' => NULL, 'size' => NULL, 'meta' => NULL); // Grab the existing entry data to preserve the MIME type and size information if (isset($entry_id) && !is_null($entry_id)) { $row = Symphony::Database()->fetchRow(0, sprintf("SELECT `file`, `mimetype`, `size`, `meta` FROM `tbl_entries_data_%d` WHERE `entry_id` = %d", $this->get('id'), $entry_id)); if (!empty($row)) { $result = $row; } } return $result; } if ($this->get('unique_filename') == true && isset($data['name'])) { $this->getUniqueFilename($data['name']); } // Editing an entry: Where we're uploading a new file and getting rid of the old one if (is_null($entry_id) === false) { $row = Symphony::Database()->fetchRow(0, sprintf("\r\n SELECT * FROM `tbl_entries_data_%d` WHERE `entry_id` = %d LIMIT 1\r\n ", $this->get('id'), $entry_id)); $existing_file = $row['file']; if (!is_null($existing_file) && strtolower($existing_file) != strtolower($data['file']) || $data['error'] == UPLOAD_ERR_NO_FILE && !is_null($existing_file)) { $this->s3->deleteObject($this->get('bucket'), basename($existing_file)); } } if ($data['error'] == UPLOAD_ERR_NO_FILE || $data['error'] != UPLOAD_ERR_OK) { return false; } // Sanitize the filename $data['name'] = Lang::createFilename($data['name']); ## Upload the new file $options = array('ACL' => 'public-read', 'ContentType' => $data['type']); if ($this->_driver->getCacheControl() != false) { $options['CacheControl'] = "max-age=" . $this->_driver->getCacheControl(); } try { $this->s3->putObject($this->get('bucket'), $data['name'], $data['tmp_name'], $options); } catch (Exception $e) { $status = self::__ERROR_CUSTOM__; $message = __(__('There was an error while trying to upload the file %s to the bucket %s.'), array('<code>' . $data['name'] . '</code>', '<code>' . $this->get('bucket') . '</code>')); return array('file' => NULL, 'mimetype' => NULL, 'size' => NULL, 'meta' => NULL); } $status = self::__OK__; // Get the mimetype, don't trust the browser. RE: #1609 $data['type'] = General::getMimeType($data['tmp_name']); // all we need is the path and name, the domain is abstracted depending on whether or not it has a cname return array('file' => $data['name'], 'size' => $data['size'], 'mimetype' => $data['type'], 'meta' => serialize(parent::getMetaInfo($data['tmp_name'], $data['type']))); }
private function __export() { $sql_schema = $sql_data = NULL; require_once dirname(__FILE__) . '/lib/class.mysqldump.php'; $dump = new MySQLDump(Symphony::Database()); $tables = array('tbl_authors', 'tbl_cache', 'tbl_entries', 'tbl_extensions', 'tbl_extensions_delegates', 'tbl_fields', 'tbl_fields_%', 'tbl_forgotpass', 'tbl_pages', 'tbl_pages_types', 'tbl_sections', 'tbl_sections_association'); ## Grab the schema foreach ($tables as $t) { $sql_schema .= $dump->export($t, MySQLDump::STRUCTURE_ONLY); } $sql_schema = str_replace('`' . Symphony::Configuration()->get('tbl_prefix', 'database'), '`tbl_', $sql_schema); $sql_schema = preg_replace('/AUTO_INCREMENT=\\d+/i', NULL, $sql_schema); $tables = array('tbl_entries', 'tbl_extensions', 'tbl_extensions_delegates', 'tbl_fields', 'tbl_pages', 'tbl_pages_types', 'tbl_sections', 'tbl_sections_association'); ## Field data and entry data schemas needs to be apart of the workspace sql dump $sql_data = $dump->export('tbl_fields_%', MySQLDump::ALL); $sql_data .= $dump->export('tbl_entries_%', MySQLDump::ALL); ## Grab the data foreach ($tables as $t) { $sql_data .= $dump->export($t, MySQLDump::DATA_ONLY); } $sql_data = str_replace('`' . Symphony::Configuration()->get('tbl_prefix', 'database'), '`tbl_', $sql_data); $config_string = NULL; $config = Symphony::Configuration()->get(); unset($config['symphony']['build']); unset($config['symphony']['cookie_prefix']); unset($config['general']['useragent']); unset($config['file']['write_mode']); unset($config['directory']['write_mode']); unset($config['database']['host']); unset($config['database']['port']); unset($config['database']['user']); unset($config['database']['password']); unset($config['database']['db']); unset($config['database']['tbl_prefix']); unset($config['region']['timezone']); foreach ($config as $group => $set) { foreach ($set as $key => $val) { $config_string .= "\t\t\$conf['{$group}']['{$key}'] = '{$val}';" . self::CRLF; } } $install_template = str_replace(array('<!-- VERSION -->', '<!-- CONFIGURATION -->'), array(Symphony::Configuration()->get('version', 'symphony'), trim($config_string)), file_get_contents(dirname(__FILE__) . '/lib/installer.tpl')); $archive = new ZipArchive(); $res = $archive->open(TMP . '/ensemble.tmp.zip', ZipArchive::CREATE); if ($res === TRUE) { $this->__addFolderToArchive($archive, EXTENSIONS, DOCROOT); $this->__addFolderToArchive($archive, SYMPHONY, DOCROOT); $this->__addFolderToArchive($archive, WORKSPACE, DOCROOT); $archive->addFromString('install.php', $install_template); $archive->addFromString('install.sql', $sql_schema); $archive->addFromString('workspace/install.sql', $sql_data); $archive->addFile(DOCROOT . '/index.php', 'index.php'); $readme_files = glob(DOCROOT . '/README.*'); if (is_array($readme_files) && !empty($readme_files)) { foreach ($readme_files as $filename) { $archive->addFile($filename, basename($filename)); } } if (is_file(DOCROOT . '/README')) { $archive->addFile(DOCROOT . '/README', 'README'); } if (is_file(DOCROOT . '/LICENCE')) { $archive->addFile(DOCROOT . '/LICENCE', 'LICENCE'); } if (is_file(DOCROOT . '/update.php')) { $archive->addFile(DOCROOT . '/update.php', 'update.php'); } } $archive->close(); header('Content-type: application/octet-stream'); header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT'); header(sprintf('Content-disposition: attachment; filename=%s-ensemble.zip', Lang::createFilename(Symphony::Configuration()->get('sitename', 'general')))); header('Pragma: no-cache'); readfile(TMP . '/ensemble.tmp.zip'); unlink(TMP . '/ensemble.tmp.zip'); exit; }
public function processRawFieldData($data, &$status, &$message = null, $simulate = false, $entry_id = null) { $status = self::__OK__; // No file given, save empty data: if ($data === null) { return array('file' => null, 'mimetype' => null, 'size' => null, 'meta' => null); } // Its not an array, so just retain the current data and return: if (is_array($data) === false) { // Ensure the file exists in the `WORKSPACE` directory // @link http://symphony-cms.com/discuss/issues/view/610/ $file = WORKSPACE . preg_replace(array('%/+%', '%(^|/)\\.\\./%'), '/', $data); $result = array('file' => $data, 'mimetype' => null, 'size' => null, 'meta' => null); // Grab the existing entry data to preserve the MIME type and size information if (isset($entry_id)) { $row = Symphony::Database()->fetchRow(0, sprintf("SELECT `file`, `mimetype`, `size`, `meta` FROM `tbl_entries_data_%d` WHERE `entry_id` = %d", $this->get('id'), $entry_id)); if (empty($row) === false) { $result = $row; } } // Found the file, add any missing meta information: if (file_exists($file) && is_readable($file)) { if (empty($result['mimetype'])) { $result['mimetype'] = function_exists('mime_content_type') ? mime_content_type($file) : 'application/octet-stream'; } if (empty($result['size'])) { $result['size'] = filesize($file); } if (empty($result['meta'])) { $result['meta'] = serialize(self::getMetaInfo($file, $result['mimetype'])); } } else { $message = __('The file uploaded is no longer available. Please check that it exists, and is readable.'); $status = self::__INVALID_FIELDS__; } return $result; } if ($simulate && is_null($entry_id)) { return $data; } // Check to see if the entry already has a file associated with it: if (is_null($entry_id) === false) { $row = Symphony::Database()->fetchRow(0, sprintf("SELECT * FROM `tbl_entries_data_%s` WHERE `entry_id` = %d LIMIT 1", $this->get('id'), $entry_id)); $existing_file = '/' . trim($row['file'], '/'); // File was removed: if ($data['error'] == UPLOAD_ERR_NO_FILE && !is_null($existing_file) && is_file(WORKSPACE . $existing_file)) { General::deleteFile(WORKSPACE . $existing_file); } } // Do not continue on upload error: if ($data['error'] == UPLOAD_ERR_NO_FILE || $data['error'] != UPLOAD_ERR_OK) { return false; } // Where to upload the new file? $abs_path = DOCROOT . '/' . trim($this->get('destination'), '/'); $rel_path = str_replace('/workspace', '', $this->get('destination')); // If a file already exists, then rename the file being uploaded by // adding `_1` to the filename. If `_1` already exists, the logic // will keep adding 1 until a filename is available (#672) if (file_exists($abs_path . '/' . $data['name'])) { $extension = General::getExtension($data['name']); $new_file = substr($abs_path . '/' . $data['name'], 0, -1 - strlen($extension)); $renamed_file = $new_file; $count = 1; do { $renamed_file = $new_file . '_' . $count . '.' . $extension; $count++; } while (file_exists($renamed_file)); // Extract the name filename from `$renamed_file`. $data['name'] = str_replace($abs_path . '/', '', $renamed_file); } // Sanitize the filename $data['name'] = Lang::createFilename($data['name']); $file = rtrim($rel_path, '/') . '/' . trim($data['name'], '/'); // Attempt to upload the file: $uploaded = General::uploadFile($abs_path, $data['name'], $data['tmp_name'], Symphony::Configuration()->get('write_mode', 'file')); if ($uploaded === false) { $message = __('There was an error while trying to upload the file %1$s to the target directory %2$s.', array('<code>' . $data['name'] . '</code>', '<code>workspace/' . ltrim($rel_path, '/') . '</code>')); $status = self::__ERROR_CUSTOM__; return false; } // File has been replaced: if (isset($existing_file) && strtolower($existing_file) != strtolower($file) && is_file(WORKSPACE . $existing_file)) { General::deleteFile(WORKSPACE . $existing_file); } // If browser doesn't send MIME type (e.g. .flv in Safari) if (strlen(trim($data['type'])) == 0) { $data['type'] = function_exists('mime_content_type') ? mime_content_type($file) : 'application/octet-stream'; } return array('file' => $file, 'size' => $data['size'], 'mimetype' => $data['type'], 'meta' => serialize(self::getMetaInfo(WORKSPACE . $file, $data['type']))); }