template.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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 Georg Ehrke <georg@ownCloud.com>
  7. * @author Jan-Christoph Borchardt <hey@jancborchardt.net>
  8. * @author Joas Schilling <nickvergessen@owncloud.com>
  9. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  10. * @author Morris Jobke <hey@morrisjobke.de>
  11. * @author Robin McCorkell <rmccorkell@karoshi.org.uk>
  12. * @author Thomas Müller <thomas.mueller@tmit.eu>
  13. * @author Vincent Petry <pvince81@owncloud.com>
  14. *
  15. * @copyright Copyright (c) 2015, ownCloud, Inc.
  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 OC_Helper::imagePath
  46. * @deprecated 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 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 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 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 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 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 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 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. class Template extends \OC_Template {
  126. /**
  127. * Make OC_Helper::imagePath available as a simple function
  128. *
  129. * @see OC_Helper::imagePath
  130. *
  131. * @param string $app
  132. * @param string $image
  133. * @return string to the image
  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. */
  144. public static function mimetype_icon($mimetype) {
  145. return \mimetype_icon($mimetype);
  146. }
  147. /**
  148. * Make preview_icon available as a simple function
  149. *
  150. * @param string $path path to file
  151. * @return string to the preview of the image
  152. */
  153. public static function preview_icon($path) {
  154. return \preview_icon($path);
  155. }
  156. /**
  157. * Make publicpreview_icon available as a simple function
  158. * Returns the path to the preview of the image.
  159. *
  160. * @param string $path of file
  161. * @param string $token
  162. * @return string link to the preview
  163. */
  164. public static function publicPreview_icon($path, $token) {
  165. return \publicPreview_icon($path, $token);
  166. }
  167. /**
  168. * Make OC_Helper::humanFileSize available as a simple function
  169. * Example: 2048 to 2 kB.
  170. *
  171. * @param int $bytes in bytes
  172. * @return string size as string
  173. */
  174. public static function human_file_size($bytes) {
  175. return \human_file_size($bytes);
  176. }
  177. /**
  178. * Return the relative date in relation to today. Returns something like "last hour" or "two month ago"
  179. *
  180. * @param int $timestamp unix timestamp
  181. * @param boolean $dateOnly
  182. * @return string human readable interpretation of the timestamp
  183. */
  184. public static function relative_modified_date($timestamp, $dateOnly = false) {
  185. return \relative_modified_date($timestamp, null, $dateOnly);
  186. }
  187. /**
  188. * Generate html code for an options block.
  189. *
  190. * @param array $options the options
  191. * @param mixed $selected which one is selected?
  192. * @param array $params the parameters
  193. * @return string html options
  194. */
  195. public static function html_select_options($options, $selected, $params=array()) {
  196. return \html_select_options($options, $selected, $params);
  197. }
  198. }