} elseif ((isset($itemInfo['status']) and $itemInfo['status'] == 'p' && !$tikilib->user_has_perm_on_object($user, $itemInfo['trackerId'], 'tracker', 'tiki_p_view_trackers_pending')) || (isset($itemInfo['status']) and $itemInfo['status'] == 'c' && !$tikilib->user_has_perm_on_object($user, $itemInfo['trackerId'], 'tracker', 'tiki_p_view_trackers_closed')) || ($tiki_p_admin_trackers != 'y' && !$tikilib->user_has_perm_on_object($user, $itemInfo['trackerId'], 'tracker', 'tiki_p_view_trackers')) || ($tiki_p_admin_trackers != 'y' && !$tikilib->user_has_perm_on_object($user, $itemInfo['trackerId'], 'tracker', 'tiki_p_tracker_view_attachments')) ) { $smarty->assign('errortype', 401); $smarty->assign('msg', tra('Permission denied')); $smarty->display('error.tpl'); die; } $trklib->add_item_attachment_hit($_REQUEST["attId"]); if ( empty($info['filetype']) || $info['filetype'] == 'application/x-octetstream' || $info['filetype'] == 'application/octet-stream' ) { include_once('lib/mime/mimelib.php'); $info['filetype'] = tiki_get_mime($info['filename'], 'application/octet-stream'); } $type = &$info["filetype"]; $file = &$info["filename"]; $content = &$info["data"]; session_write_close(); //print("File:$file<br />"); //die; header("Content-type: $type"); if (isset($_REQUEST["display"])) { //die; header("Content-Disposition: inline; filename=\"".urlencode($file)."\""); } else { header("Content-Disposition: attachment; filename=\"$file\""); }
function process_batch_file_upload($galleryId, $file, $user, $description) { global $fgal_match_regex; global $fgal_nmatch_regex; global $fgal_use_db; global $fgal_use_dir; include_once 'lib/pclzip.lib.php'; include_once 'lib/mime/mimelib.php'; $archive = new PclZip($file); $archive->extract('temp'); $files = array(); $h = opendir("temp"); $gal_info = $this->get_file_gallery_info($galleryId); while (($file = readdir($h)) !== false) { if ($file != '.' && $file != '..' && is_file("temp/{$file}") && $file != 'license.txt') { $files[] = $file; // check filters $upl = 1; if (!empty($fgal_match_regex)) { if (!preg_match("/{$fgal_match_regex}/", $file, $reqs)) { $upl = 0; } } if (!empty($fgal_nmatch_regex)) { if (preg_match("/{$fgal_nmatch_regex}/", $file, $reqs)) { $upl = 0; } } $fp = fopen('temp/' . $file, "rb"); $data = ''; $fhash = ''; if ($fgal_use_db == 'n') { $fhash = md5($name = $file); @($fw = fopen($fgal_use_dir . $fhash, "wb")); if (!$fw) { $smarty->assign('msg', tra('Cannot write to this file:') . $fhash); $smarty->display("error.tpl"); die; } } while (!feof($fp)) { if ($fgal_use_db == 'y') { $data .= fread($fp, 8192 * 16); } else { $data = fread($fp, 8192 * 16); fwrite($fw, $data); } } fclose($fp); if ($fgal_use_db == 'n') { fclose($fw); $data = ''; } $size = filesize('temp/' . $file); $name = $file; $type = tiki_get_mime('temp/' . $file); $fileId = $this->insert_file($galleryId, $name, $description, $name, $data, $size, $type, $user, $fhash); unlink('temp/' . $file); } } closedir($h); }
function process_batch_file_upload($galleryId, $file, $user, $description) { global $prefs; include_once 'lib/pclzip.lib.php'; include_once 'lib/mime/mimelib.php'; $extract_dir = 'temp/' . basename($file) . '/'; mkdir($extract_dir); $archive = new PclZip($file); $archive->extract($extract_dir); unlink($file); $files = array(); $h = opendir($extract_dir); $gal_info = $this->get_file_gallery_info($galleryId); if ($podCastGallery = $this->isPodCastGallery($galleryId, $gal_info)) { $savedir = $prefs['fgal_podcast_dir']; } else { $savedir = $prefs['fgal_use_dir']; } while (($file = readdir($h)) !== false) { if ($file != '.' && $file != '..' && is_file($extract_dir . '/' . $file)) { $files[] = $file; // check filters $upl = 1; if (!empty($prefs['fgal_match_regex'])) { if (!preg_match('/' . $prefs['fgal_match_regex'] . '/', $file, $reqs)) { $upl = 0; } } if (!empty($prefs['fgal_nmatch_regex'])) { if (preg_match('/' . $prefs['fgal_nmatch_regex'] . '/', $file, $reqs)) { $upl = 0; } } if (!($fp = fopen($extract_dir . $file, "rb"))) { $smarty->assign('msg', tra('Cannot open this file:') . "temp/{$file}"); $smarty->display("error.tpl"); die; } $data = ''; $fhash = ''; if ($prefs['fgal_use_db'] == 'n' || $podCastGallery) { $fhash = md5($name = $file); @($fw = fopen($savedir . $fhash, "wb")); if (!$fw) { $smarty->assign('msg', tra('Cannot write to this file:') . $fhash); $smarty->display("error.tpl"); die; } } while (!feof($fp)) { if ($prefs['fgal_use_db'] == 'y' && !$podCastGallery) { $data .= fread($fp, 8192 * 16); } else { $data = fread($fp, 8192 * 16); fwrite($fw, $data); } } fclose($fp); if ($prefs['fgal_use_db'] == 'n' || $podCastGallery) { fclose($fw); $data = ''; } $size = filesize($extract_dir . $file); $name = $file; $type = tiki_get_mime($extract_dir . $file); $fileId = $this->insert_file($galleryId, $name, $description, $name, $data, $size, $type, $user, $fhash); unlink($extract_dir . $file); } } closedir($h); rmdir($extract_dir); }
function moveWikiUpToFgal($page_info, $fgalId, &$errors, &$feedbacks) { global $user; $tikilib = TikiLib::lib('tiki'); include_once 'lib/mime/mimelib.php'; $argumentParser = new WikiParser_PluginArgumentParser(); $files = array(); if (strpos($page_info['data'], 'img/wiki_up') === false) { return; } $matches = WikiParser_PluginMatcher::match($page_info['data']); foreach ($matches as $match) { $modif = false; $plugin_name = $match->getName(); if ($plugin_name == 'img') { $arguments = $argumentParser->parse($match->getArguments()); $newArgs = array(); foreach ($arguments as $key => $val) { if ($key == 'src') { if (false === ($data = @file_get_contents($val))) { $errors[] = tra('Cannot open this file:') . ' ' . $val . ' ' . tra('Page:') . ' ' . $page_info['pageName']; continue; } $name = preg_replace('|.*/([^/]*)|', '$1', $val); $fileId = $this->insert_file($fgalId, $name, 'Used in ' . $page_info['pageName'], $name, $data, strlen($data), tiki_get_mime($name, 'application/octet-stream', $val), $user, '', 'wiki_up conversion'); if (empty($fileId)) { $errors[] = tra('Cannot upload this file') . ' ' . $val . ' ' . tra('Page:') . ' ' . $page_info['pageName']; continue; } else { $files[] = $val; $modif = true; $newArgs[] = 'fileId="' . $fileId . '"'; } } else { $newArgs[] = "{$key}=\"{$val}\""; } } if ($modif) { $match->replaceWith('{img ' . implode(' ', $newArgs) . '}'); } } } if (!empty($files)) { $tikilib->update_page($page_info['pageName'], $matches->getText(), 'wiki_up conversion', $user, $tikilib->get_ip_address()); foreach ($files as $file) { unlink($file); } $feedbacks[] = $page_info['pageName']; } }
function tiki_get_mime_sub($filename) { $filesplit = preg_split("#/+#", tiki_get_mime($filename)); return $filesplit["1"]; }
protected function setResourceContents($path, $content) { global $user, $prefs; global $filegallib; require_once('lib/filegals/filegallib.php'); if (empty($path) || substr($path, -1, 1) == '/') { print_debug("\nsetResourceContents failed empty path or directory\n"); return false; } if (($objectId = $filegallib->get_objectid_from_virtual_path($path)) === false) { print_debug("\nCreateResouce new $path\n"); return $this->_createResource($path, $content); } if ($objectId['type'] != 'file') { print_debug("\nsetResourceContents failed : destination is not a file\n"); return false; } include_once('lib/mime/mimelib.php'); $name = basename($path); if (empty($content)) $content = ''; if ($prefs['fgal_use_db'] === 'n') { $fhash = md5($name); do { $fhash = md5(uniqid($fhash)); } while (file_exists($this->root . '/' . $fhash)); $mime = tiki_get_mime($name, 'application/octet-stream', $this->root . '/' . $fhash); } else { $fhash = ''; $mime = tiki_get_mime_from_content($content, 'application/octet-stream', $name); } print_debug("setResourceContents : $path/$fhash \n"); $fileInfo = $filegallib->get_file_info($objectId['id'], false, false); $filegalInfo = $filegallib->get_file_gallery_info($fileInfo['galleryId']); if ($prefs['fgal_use_db'] === 'n' && @file_put_contents($this->root . '/' . $fhash, $content) === false) { return false; } $fileId = $filegallib->replace_file( $objectId['id'], $fileInfo['name'], $fileInfo['description'], $fileInfo['filename'], $content, @strlen($content), $mime, $user, $fhash, '', $filegalInfo, true ); print_debug("setResourceContents: fileId = $fileId end \n"); return $fileId; }