ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilFilePreviewRenderer.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./Services/Preview/classes/class.ilPreviewRenderer.php");
5 
15 {
21  public final function getSupportedRepositoryTypes()
22  {
23  return array("file");
24  }
25 
32  public function supports($preview)
33  {
34  // let parent check first
35  if (!parent::supports($preview))
36  return false;
37 
38  // get file extension
39  require_once("./Modules/File/classes/class.ilObjFile.php");
40  include_once './Modules/File/classes/class.ilObjFileAccess.php';
43 
44  // contains that extension?
45  return in_array($ext, $this->getSupportedFileFormats());
46  }
47 
56  public function prepareFileForExec($filepath)
57  {
58  $pos = strrpos($filepath, "/");
59  $name = $pos !== false ? substr($filepath, $pos + 1) : $filepath;
60 
61  // if the file path contains any characters that could cause problems
62  // we copy the file to a temporary file
63  $normName = preg_replace("/[^A-Za-z0-9.\- +_&]/", "", $name);
64  if ($normName != $name)
65  {
66  $tempPath = ilUtil::ilTempnam();
67  if (copy($filepath, $tempPath))
68  return $tempPath;
69  }
70 
71  return $filepath;
72  }
73 
79  public abstract function getSupportedFileFormats();
80 }
81 ?>