template.php 6.5 KB

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