functions.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /**
  3. * Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. /**
  9. * Prints an XSS escaped string
  10. * @param string $string the string which will be escaped and printed
  11. */
  12. function p($string) {
  13. print(OC_Util::sanitizeHTML($string));
  14. }
  15. /**
  16. * Prints an unescaped string
  17. * @param string $string the string which will be printed as it is
  18. */
  19. function print_unescaped($string) {
  20. print($string);
  21. }
  22. /**
  23. * @brief make OC_Helper::linkTo available as a simple function
  24. * @param string $app app
  25. * @param string $file file
  26. * @param array $args array with param=>value, will be appended to the returned url
  27. * @return string link to the file
  28. *
  29. * For further information have a look at OC_Helper::linkTo
  30. */
  31. function link_to( $app, $file, $args = array() ) {
  32. return OC_Helper::linkTo( $app, $file, $args );
  33. }
  34. /**
  35. * @brief make OC_Helper::imagePath available as a simple function
  36. * @param string $app app
  37. * @param string $image image
  38. * @return string link to the image
  39. *
  40. * For further information have a look at OC_Helper::imagePath
  41. */
  42. function image_path( $app, $image ) {
  43. return OC_Helper::imagePath( $app, $image );
  44. }
  45. /**
  46. * @brief make OC_Helper::mimetypeIcon available as a simple function
  47. * @param string $mimetype mimetype
  48. * @return string link to the image
  49. *
  50. * For further information have a look at OC_Helper::mimetypeIcon
  51. */
  52. function mimetype_icon( $mimetype ) {
  53. return OC_Helper::mimetypeIcon( $mimetype );
  54. }
  55. /**
  56. * @brief make OC_Helper::humanFileSize available as a simple function
  57. * @param int $bytes size in bytes
  58. * @return string size as string
  59. *
  60. * For further information have a look at OC_Helper::humanFileSize
  61. */
  62. function human_file_size( $bytes ) {
  63. return OC_Helper::humanFileSize( $bytes );
  64. }
  65. function relative_modified_date($timestamp) {
  66. $l=OC_L10N::get('lib');
  67. $timediff = time() - $timestamp;
  68. $diffminutes = round($timediff/60);
  69. $diffhours = round($diffminutes/60);
  70. $diffdays = round($diffhours/24);
  71. $diffmonths = round($diffdays/31);
  72. if($timediff < 60) { return $l->t('seconds ago'); }
  73. else if($timediff < 120) { return $l->t('1 minute ago'); }
  74. else if($timediff < 3600) { return $l->t('%d minutes ago', $diffminutes); }
  75. else if($timediff < 7200) { return $l->t('1 hour ago'); }
  76. else if($timediff < 86400) { return $l->t('%d hours ago', $diffhours); }
  77. else if((date('G')-$diffhours) > 0) { return $l->t('today'); }
  78. else if((date('G')-$diffhours) > -24) { return $l->t('yesterday'); }
  79. else if($timediff < 2678400) { return $l->t('%d days ago', $diffdays); }
  80. else if($timediff < 5184000) { return $l->t('last month'); }
  81. else if((date('n')-$diffmonths) > 0) { return $l->t('%d months ago', $diffmonths); }
  82. else if($timediff < 63113852) { return $l->t('last year'); }
  83. else { return $l->t('years ago'); }
  84. }
  85. function html_select_options($options, $selected, $params=array()) {
  86. if (!is_array($selected)) {
  87. $selected=array($selected);
  88. }
  89. if (isset($params['combine']) && $params['combine']) {
  90. $options = array_combine($options, $options);
  91. }
  92. $value_name = $label_name = false;
  93. if (isset($params['value'])) {
  94. $value_name = $params['value'];
  95. }
  96. if (isset($params['label'])) {
  97. $label_name = $params['label'];
  98. }
  99. $html = '';
  100. foreach($options as $value => $label) {
  101. if ($value_name && is_array($label)) {
  102. $value = $label[$value_name];
  103. }
  104. if ($label_name && is_array($label)) {
  105. $label = $label[$label_name];
  106. }
  107. $select = in_array($value, $selected) ? ' selected="selected"' : '';
  108. $html .= '<option value="' . OC_Util::sanitizeHTML($value) . '"' . $select . '>' . OC_Util::sanitizeHTML($label) . '</option>'."\n";
  109. }
  110. return $html;
  111. }