SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/Helpers/FilesBackend.php

  1. <?php
  2. /*
  3.  * Copyright (C) 2017 Karmabunny Pty Ltd.
  4.  *
  5.  * This file is a part of SproutCMS.
  6.  *
  7.  * SproutCMS is free software: you can redistribute it and/or modify it under the terms
  8.  * of the GNU General Public License as published by the Free Software Foundation, either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * For more information, visit <http://getsproutcms.com>.
  12.  */
  13.  
  14. namespace Sprout\Helpers;
  15.  
  16. /**
  17. * Abstract class for a backend storage for the database-managed files
  18. **/
  19. abstract class FilesBackend {
  20.  
  21. /**
  22.   * Returns the relative public URL for a given file.
  23.   * Doesn't contain ROOT/ or domain. Use for content areas.
  24.   **/
  25. abstract function relUrl($filename);
  26.  
  27.  
  28. /**
  29.   * Returns the public URL for a given file, including domain.
  30.   **/
  31. abstract function absUrl($filename);
  32.  
  33.  
  34. /**
  35.   * Returns the URL for a resized image. Does not include domain.
  36.   * Size should be 'rWIDTHxHEIGHT' or 'cWIDTHxHEIGHT'.
  37.   **/
  38. abstract function resizeUrl($filename, $size);
  39.  
  40.  
  41. /**
  42.   * Returns TRUE if the file exists, and FALSE if it does not
  43.   **/
  44. abstract function exists($filename);
  45.  
  46.  
  47. /**
  48.   * Returns the size, in bytes, of the specified file
  49.   **/
  50. abstract function size($filename);
  51.  
  52.  
  53. /**
  54.   * Returns the modified time, in unix timestamp format, of the specified file
  55.   **/
  56. abstract function mtime($filename);
  57.  
  58.  
  59. /**
  60.   * Sets access and modification time of file
  61.   */
  62. abstract function touch($filename);
  63.  
  64.  
  65. /**
  66.   * Returns the size of an image, or false on failure.
  67.   *
  68.   * Output format is the same as getimagesize, but will be at a minimum:
  69.   * [0] => width, [1] => height, [2] => type
  70.   **/
  71. abstract function imageSize($filename);
  72.  
  73.  
  74. /**
  75.   * Delete a file
  76.   **/
  77. abstract function delete($filename);
  78.  
  79.  
  80. /**
  81.   * Returns all files which match the specified mask.
  82.   * I have a feeling this returns other sizes (e.g. .small) as well - which may not be ideal.
  83.   **/
  84. abstract function glob($mask);
  85.  
  86.  
  87. /**
  88.   * This is the equivalent of the php readfile function
  89.   **/
  90. abstract function readfile($filename);
  91.  
  92.  
  93. /**
  94.   * Returns file content as a string. Basically the same as file_get_contents
  95.   **/
  96. abstract function getString($filename);
  97.  
  98.  
  99. /**
  100.   * Saves file content as a string. Basically the same as file_put_contents
  101.   **/
  102. abstract function putString($filename, $content);
  103.  
  104.  
  105. /**
  106.   * Saves file content from a stream. Basically just fopen/stream_copy_to_stream/fclose
  107.   **/
  108. abstract function putStream($filename, $stream);
  109.  
  110.  
  111. /**
  112.   * Saves file content from an existing file
  113.   **/
  114. abstract function putExisting($filename, $existing);
  115.  
  116.  
  117. /**
  118.   * Create a copy of the file in a temporary directory.
  119.   * Don't forget to File::destroy_local_copy($temp_filename) when you're done!
  120.   *
  121.   * @param string $filename The file to copy into a temporary location
  122.   * @return string Temp filename or NULL on error
  123.   **/
  124. abstract function createLocalCopy($filename);
  125.  
  126.  
  127. /**
  128.   * Remove a local copy of a file
  129.   *
  130.   * @param string $temp_filename The filename returned by createLocalCopy
  131.   **/
  132. abstract function cleanupLocalCopy($temp_filename);
  133.  
  134.  
  135. /**
  136.   * Moves an uploaded file into the repository.
  137.   * Returns TRUE on success, FALSE on failure.
  138.   **/
  139. abstract function moveUpload($src, $filename);
  140.  
  141. }
  142.