function.localfiletype.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * Smarty function to get a localized file type
  4. *
  5. * @author Christopher Han <xiphux@gmail.com>
  6. * @copyright Copyright (c) 2012 Christopher Han
  7. * @package GitPHP
  8. * @subpackage Smarty
  9. *
  10. * @param array $params param array
  11. * @param Smarty_Internal_Template $template smarty template
  12. */
  13. function smarty_function_localfiletype($params, Smarty_Internal_Template $template)
  14. {
  15. if (empty($params['type'])) {
  16. trigger_error("localfiletype: missing 'type' parameter");
  17. return;
  18. }
  19. $type = $params['type'];
  20. $resource = $template->getTemplateVars('resource');
  21. $output = null;
  22. switch ($type) {
  23. case GitPHP_FilesystemObject::FileType:
  24. if ($resource)
  25. $output = $resource->translate('file');
  26. else
  27. $output = 'file';
  28. break;
  29. case GitPHP_FilesystemObject::SymlinkType:
  30. if ($resource)
  31. $output = $resource->translate('symlink');
  32. else
  33. $output = 'symlink';
  34. break;
  35. case GitPHP_FilesystemObject::DirectoryType:
  36. if ($resource)
  37. $output = $resource->translate('directory');
  38. else
  39. $output = 'directory';
  40. break;
  41. default:
  42. if ($resource)
  43. $output = $resource->translate('unknown');
  44. else
  45. $output = 'unknown';
  46. break;
  47. }
  48. if (!empty($params['assign']))
  49. $template->assign($params['assign'], $output);
  50. else
  51. return $output;
  52. }