* @package mahara * @subpackage export * @author Catalyst IT Ltd * @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later * @copyright For copyright information on Mahara, please see the README file distributed with this software. * */ define('INTERNAL', 1); require dirname(dirname(__FILE__)) . '/init.php'; require_once get_config('docroot') . '/lib/htmloutput.php'; // Download the export file if it's been generated if ($exportfile = $SESSION->get('exportfile')) { $SESSION->set('exportdata', ''); $SESSION->set('exportfile', ''); require_once 'file.php'; serve_file($exportfile, basename($exportfile), 'application/x-zip', array('lifetime' => 0, 'forcedownload' => true)); exit; } if (function_exists('apache_setenv')) { // Turn off gzip if it's on, because it prevents output from being flushed apache_setenv('no-gzip', 1); } if (!($exportdata = $SESSION->get('exportdata'))) { redirect('/export/index.php'); } $SESSION->set('exportdata', ''); $stylesheets = array_reverse($THEME->get_url('style/style.css', true)); print_export_head($stylesheets); flush(); /** * Outputs enough HTML to make a pretty error message in the iframe
$fileinloggedinmenu = $file->get('institution') == 'mahara'; // check if users are allowed to access files in subfolders if (!get_config('sitefilesaccess')) { $fileinloggedinmenu = $fileinloggedinmenu && $file->get('parent') == null; } $fileinloggedinmenu = $fileinloggedinmenu && $USER->is_logged_in(); $fileinloggedinmenu = $fileinloggedinmenu && record_exists('site_menu', 'file', $fileid, 'public', 0); if (!$fileinloggedinmenu) { // Alternatively, if you own the file or you are an admin, it should always work if (!$USER->can_view_artefact($file)) { // Check for images sitting in visible forum posts $visibleinpost = false; if ($postid && $file instanceof ArtefactTypeImage) { safe_require('interaction', 'forum'); $visibleinpost = PluginInteractionForum::can_see_attached_file($file, $postid); } if (!$visibleinpost) { throw new AccessDeniedException(get_string('accessdenied', 'error')); } } } } } $path = $file->get_path($size); $title = $file->download_title(); if ($contenttype = $file->override_content_type()) { $options['overridecontenttype'] = $contenttype; } $options['owner'] = $file->get('owner'); serve_file($path, $title, $file->get('filetype'), $options);
function page_serve_resource($args) { $obj = $args['obj']; if (array_pop(expl('.', $obj['name'])) != 'page') { return false; } $pn = array_shift(expl('.', $obj['name'])); if (!empty($obj['page-background-file'])) { $fn = CONTENT_DIR . '/' . $pn . '/shared/' . $obj['page-background-file']; if (isset($obj['page-background-mime'])) { $mime = $obj['page-background-mime']; } else { $mime = ''; } serve_file($fn, false, $mime); } // if everything fails return false; }
function video_serve_resource($args) { $obj = $args['obj']; if (!isset($obj['type']) || $obj['type'] != 'video') { return false; } if (!empty($obj['video-file'])) { $pn = array_shift(expl('.', $obj['name'])); if (empty($obj['video-file-mime'])) { $obj['video-file-mime'] = ''; } serve_file(CONTENT_DIR . '/' . $pn . '/shared/' . $obj['video-file'], $args['dl'], $obj['video-file-mime']); } return false; }
* * @package mahara * @subpackage skin * @author Gregor Anzelj * @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later * @copyright For copyright information on Mahara, please see the README file distributed with this software. * @copyright (C) 2010-2013 Gregor Anzelj <*****@*****.**> * */ define('INTERNAL', 1); define('PUBLIC', 1); require dirname(dirname(__FILE__)) . '/init.php'; require_once 'file.php'; if (!get_config('skins')) { throw new FeatureNotEnabledException(); } $family = param_variable('family'); $variant = param_variable('variant'); $format = param_variable('format'); if (!in_array($format, array('EOT', 'SVG', 'TTF', 'WOFF'))) { throw new NotFoundException(); } $fontrec = get_record('skin_fonts', 'title', $family); if (!$fontrec || !($variantlist = unserialize($fontrec->variants)) || !isset($variantlist[$variant]) || !isset($variantlist[$variant][$format])) { throw new NotFoundException(); } $filename = $variantlist[$variant][$format]; $fontpath = get_config('dataroot') . 'skins/fonts/' . $fontrec->name . '/' . $filename; $options = array('forcedownload' => true); serve_file($fontpath, $filename, pathinfo($fontpath, PATHINFO_EXTENSION), $options);
/** * implements serve_resource */ function image_serve_resource($args) { $obj = $args['obj']; if (!isset($obj['type']) || $obj['type'] != 'image') { return false; } // we don't have to care about symlinks here as they are being resolved // before this hook is called $pn = array_shift(expl('.', $obj['name'])); if (!empty($obj['image-resized-file']) && !$args['dl']) { // we have a resized file and don't want to download the original $fn = CONTENT_DIR . '/' . $pn . '/shared/' . $obj['image-resized-file']; $ext = filext($fn); if ($ext == 'jpg' || $ext == 'jpeg') { serve_file($fn, false, 'image/jpeg'); } else { if ($ext == 'png') { serve_file($fn, false, 'image/png'); } else { log_msg('warn', 'image_serve_resource: unsupported image-resized-file ' . quot($fn)); } } // if we're still alive it means that the resized file has not been // found log_msg('warn', 'image_serve_resource: could not serve image-resized-file ' . quot($fn) . ', falling back to original'); $need_auth = false; } elseif (empty($obj['image-resized-file'])) { // we don't have a resized file $need_auth = false; } else { // we really want to download the original $need_auth = true; } if (!empty($obj['image-file'])) { // we have the original file if ($need_auth && !is_auth()) { // require authentication prompt_auth(true); } if (empty($obj['image-file-mime'])) { $obj['image-file-mime'] = ''; } serve_file(CONTENT_DIR . '/' . $pn . '/shared/' . $obj['image-file'], $args['dl'], $obj['image-file-mime']); } // if everything fails return false; }
} } else { throw new SystemException(get_string('phpzipneeded', 'artefact.file')); } } else { $folderinfo = get_record('artefact', 'id', $folderid); if (empty($folderinfo)) { throw new NotFoundException(); } if (function_exists('zip_open')) { $folder = artefact_instance_from_id($folderinfo->id); if (can_download_artefact($folder)) { $zip = new ZipArchive(); $foldername = $folderinfo->title; $filename = 'directory-' . $USER->get('id') . '-' . $foldername . '-' . time() . '.zip'; $filepath = get_config('dataroot') . 'temp/' . $filename; if ($zip->open($filepath, ZIPARCHIVE::CREATE) !== true) { throw new NotFoundException(); } $files = zip_process_directory($zip, $folderid, $folderinfo->title . '/'); zip_write_contents($zip, $filepath, $files); $zip->close(); $downloadname = zip_filename_from($foldername); serve_file($filepath, $downloadname, 'application/zip', $options); } else { throw new AccessDeniedException(get_string('accessdenied', 'error')); } } else { throw new SystemException(get_string('phpzipneeded', 'artefact.file')); } }
function bulkexport_submit(Pieform $form, $values) { global $SESSION; $usernames = array(); // Read in the usernames explicitly specified foreach (explode("\n", $values['usernames']) as $username) { $username = trim($username); if (!empty($username)) { $usernames[] = $username; } } if (empty($usernames) and !empty($values['authinstance'])) { // Export all users from the selected institution $rs = get_recordset_select('usr', 'authinstance = ? AND deleted = 0', array($values['authinstance']), '', 'username'); while ($record = $rs->FetchRow()) { $usernames[] = $record['username']; } } safe_require('export', 'leap'); $listing = array(); $files = array(); $exportcount = 0; $exporterrors = array(); $num_users = count($usernames); foreach ($usernames as $username) { if (!($exportcount % 25)) { set_progress_info('bulkexport', $exportcount, $num_users, get_string('validating', 'admin')); } $user = new User(); try { $user->find_by_username($username); } catch (AuthUnknownUserException $e) { continue; // Skip non-existent users } $exporter = new PluginExportLeap($user, PluginExport::EXPORT_ALL_VIEWS_COLLECTIONS, PluginExport::EXPORT_ALL_ARTEFACTS); try { $zipfile = $exporter->export(); } catch (Exception $e) { $exporterrors[] = $username; continue; } $listing[] = array($username, $zipfile); $files[] = $exporter->get('exportdir') . $zipfile; $exportcount++; } if (!($zipfile = create_zipfile($listing, $files))) { export_iframe_die(get_string('bulkexportempty', 'admin')); } log_info("Exported {$exportcount} users to {$zipfile}"); if (!empty($exporterrors)) { $SESSION->add_error_msg(get_string('couldnotexportusers', 'admin', implode(', ', $exporterrors))); } // Store the filename in the session, and redirect the iframe to it to trigger // the download. Here it would be nice to trigger the download for everyone, // but alas this is not possible for people without javascript. $SESSION->set('exportfile', $zipfile); set_progress_done('bulkexport', array('redirect' => get_config('wwwroot') . 'admin/users/bulkexport.php')); // Download the export file once it has been generated require_once 'file.php'; serve_file($zipfile, basename($zipfile), 'application/x-zip', array('lifetime' => 0, 'forcedownload' => true)); // TODO: delete the zipfile (and temporary files) once it's been downloaded }
require 'init.php'; require_once 'file.php'; $type = param_alpha('type', null); if ($type == 'sitemap') { if (!get_config('generatesitemap')) { throw new NotFoundException(get_string('filenotfound')); } if ($name = param_alphanumext('name', null)) { if (!preg_match('/^sitemap_[a-z0-9_]+\\.xml(\\.gz)?$/', $name, $m)) { throw new NotFoundException(get_string('filenotfound')); } $mimetype = empty($m[1]) ? 'text/xml' : 'application/gzip'; } else { $name = 'sitemap_index.xml'; $mimetype = 'text/xml'; } $path = get_config('dataroot') . 'sitemaps/' . $name; } else { $data = $SESSION->get('downloadfile'); if (!$USER->is_logged_in() || empty($data) || empty($data['file'])) { throw new NotFoundException(get_string('filenotfound')); } $path = get_config('dataroot') . 'export/' . $USER->get('id') . '/' . $data['file']; $name = $data['name']; $mimetype = $data['mimetype']; } if (!file_exists($path)) { throw new NotFoundException(get_string('filenotfound')); } serve_file($path, $name, $mimetype);
function download_serve_resource($args) { $obj = $args['obj']; if (!isset($obj['type']) || $obj['type'] != 'download') { return false; } $a = expl('.', $obj['name']); // serve the resource only when it's public or we're logged in (i.e. editing) if (isset($obj['download-public']) && $obj['download-public'] == 'public' || is_auth()) { serve_file(CONTENT_DIR . '/' . $a[0] . '/shared/' . $obj['download-file'], $args['dl'], $obj['download-file-mime']); } else { if (!is_auth()) { prompt_auth(true); } } }