template.php 5.9 KB

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