Template.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bart Visscher <bartv@thisnet.nl>
  6. * @author Frank Karlitschek <frank@karlitschek.de>
  7. * @author Georg Ehrke <georg@owncloud.com>
  8. * @author Jan-Christoph Borchardt <hey@jancborchardt.net>
  9. * @author Joas Schilling <coding@schilljs.com>
  10. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  11. * @author Morris Jobke <hey@morrisjobke.de>
  12. * @author Robin McCorkell <robin@mccorkell.me.uk>
  13. * @author Thomas Müller <thomas.mueller@tmit.eu>
  14. * @author Vincent Petry <pvince81@owncloud.com>
  15. *
  16. * @license AGPL-3.0
  17. *
  18. * This code is free software: you can redistribute it and/or modify
  19. * it under the terms of the GNU Affero General Public License, version 3,
  20. * as published by the Free Software Foundation.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU Affero General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU Affero General Public License, version 3,
  28. * along with this program. If not, see <http://www.gnu.org/licenses/>
  29. *
  30. */
  31. /**
  32. * Public interface of ownCloud for apps to use.
  33. * Template Class
  34. *
  35. */
  36. // use OCP namespace for all classes that are considered public.
  37. // This means that they should be used by apps instead of the internal ownCloud classes
  38. namespace OCP;
  39. /**
  40. * Make OC_Helper::imagePath available as a simple function
  41. * @param string $app
  42. * @param string $image
  43. * @return string to the image
  44. *
  45. * @see \OCP\IURLGenerator::imagePath
  46. * @deprecated 8.0.0 Use \OCP\Template::image_path() instead
  47. */
  48. function image_path( $app, $image ) {
  49. return(\image_path( $app, $image ));
  50. }
  51. /**
  52. * Make OC_Helper::mimetypeIcon available as a simple function
  53. * @param string $mimetype
  54. * @return string to the image of this file type.
  55. * @deprecated 8.0.0 Use \OCP\Template::mimetype_icon() instead
  56. */
  57. function mimetype_icon( $mimetype ) {
  58. return(\mimetype_icon( $mimetype ));
  59. }
  60. /**
  61. * Make preview_icon available as a simple function
  62. * @param string $path path to file
  63. * @return string to the preview of the image
  64. * @deprecated 8.0.0 Use \OCP\Template::preview_icon() instead
  65. */
  66. function preview_icon( $path ) {
  67. return(\preview_icon( $path ));
  68. }
  69. /**
  70. * Make publicpreview_icon available as a simple function
  71. * Returns the path to the preview of the image.
  72. * @param string $path of file
  73. * @param string $token
  74. * @return string link to the preview
  75. * @deprecated 8.0.0 Use \OCP\Template::publicPreview_icon() instead
  76. */
  77. function publicPreview_icon ( $path, $token ) {
  78. return(\publicPreview_icon( $path, $token ));
  79. }
  80. /**
  81. * Make OC_Helper::humanFileSize available as a simple function
  82. * Example: 2048 to 2 kB.
  83. * @param int $bytes in bytes
  84. * @return string size as string
  85. * @deprecated 8.0.0 Use \OCP\Template::human_file_size() instead
  86. */
  87. function human_file_size( $bytes ) {
  88. return(\human_file_size( $bytes ));
  89. }
  90. /**
  91. * Return the relative date in relation to today. Returns something like "last hour" or "two month ago"
  92. * @param int $timestamp unix timestamp
  93. * @param boolean $dateOnly
  94. * @return \OC_L10N_String human readable interpretation of the timestamp
  95. *
  96. * @deprecated 8.0.0 Use \OCP\Template::relative_modified_date() instead
  97. */
  98. function relative_modified_date( $timestamp, $dateOnly = false ) {
  99. return(\relative_modified_date($timestamp, null, $dateOnly));
  100. }
  101. /**
  102. * Return a human readable outout for a file size.
  103. * @param integer $bytes size of a file in byte
  104. * @return string human readable interpretation of a file size
  105. * @deprecated 8.0.0 Use \OCP\Template::human_file_size() instead
  106. */
  107. function simple_file_size($bytes) {
  108. return(\human_file_size($bytes));
  109. }
  110. /**
  111. * Generate html code for an options block.
  112. * @param array $options the options
  113. * @param mixed $selected which one is selected?
  114. * @param array $params the parameters
  115. * @return string html options
  116. * @deprecated 8.0.0 Use \OCP\Template::html_select_options() instead
  117. */
  118. function html_select_options($options, $selected, $params=array()) {
  119. return(\html_select_options($options, $selected, $params));
  120. }
  121. /**
  122. * This class provides the template system for owncloud. You can use it to load
  123. * specific templates, add data and generate the html code
  124. *
  125. * @since 8.0.0
  126. */
  127. class Template extends \OC_Template {
  128. /**
  129. * Make OC_Helper::imagePath available as a simple function
  130. *
  131. * @see \OCP\IURLGenerator::imagePath
  132. *
  133. * @param string $app
  134. * @param string $image
  135. * @return string to the image
  136. * @since 8.0.0
  137. */
  138. public static function image_path($app, $image) {
  139. return \image_path($app, $image);
  140. }
  141. /**
  142. * Make OC_Helper::mimetypeIcon available as a simple function
  143. *
  144. * @param string $mimetype
  145. * @return string to the image of this file type.
  146. * @since 8.0.0
  147. */
  148. public static function mimetype_icon($mimetype) {
  149. return \mimetype_icon($mimetype);
  150. }
  151. /**
  152. * Make preview_icon available as a simple function
  153. *
  154. * @param string $path path to file
  155. * @return string to the preview of the image
  156. * @since 8.0.0
  157. */
  158. public static function preview_icon($path) {
  159. return \preview_icon($path);
  160. }
  161. /**
  162. * Make publicpreview_icon available as a simple function
  163. * Returns the path to the preview of the image.
  164. *
  165. * @param string $path of file
  166. * @param string $token
  167. * @return string link to the preview
  168. * @since 8.0.0
  169. */
  170. public static function publicPreview_icon($path, $token) {
  171. return \publicPreview_icon($path, $token);
  172. }
  173. /**
  174. * Make OC_Helper::humanFileSize available as a simple function
  175. * Example: 2048 to 2 kB.
  176. *
  177. * @param int $bytes in bytes
  178. * @return string size as string
  179. * @since 8.0.0
  180. */
  181. public static function human_file_size($bytes) {
  182. return \human_file_size($bytes);
  183. }
  184. /**
  185. * Return the relative date in relation to today. Returns something like "last hour" or "two month ago"
  186. *
  187. * @param int $timestamp unix timestamp
  188. * @param boolean $dateOnly
  189. * @return string human readable interpretation of the timestamp
  190. * @since 8.0.0
  191. */
  192. public static function relative_modified_date($timestamp, $dateOnly = false) {
  193. return \relative_modified_date($timestamp, null, $dateOnly);
  194. }
  195. /**
  196. * Generate html code for an options block.
  197. *
  198. * @param array $options the options
  199. * @param mixed $selected which one is selected?
  200. * @param array $params the parameters
  201. * @return string html options
  202. * @since 8.0.0
  203. */
  204. public static function html_select_options($options, $selected, $params=array()) {
  205. return \html_select_options($options, $selected, $params);
  206. }
  207. }