PageRenderTime 37ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/EE2/third_party/datetime_convert/pi.datetime_convert.php

https://bitbucket.org/cwcrawley/hippo-datetime-converter
PHP | 96 lines | 43 code | 31 blank | 22 comment | 1 complexity | 79bdd01b1f13f6117bd72a5ad55f43c7 MD5 | raw file
  1. <?php
  2. if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  3. /*
  4. =====================================================
  5. =====================================================
  6. File: pi.datetime_convert.php
  7. -----------------------------------------------------
  8. Purpose: Date Time Converter. This class an
  9. ExpressionEngine Date/Time and converts it to another
  10. language for multi-lingual sites.
  11. =====================================================
  12. A huge thanks to Joris Heyndrickx (@moonbeetle) for
  13. the EE2 conversion.
  14. =====================================================
  15. */
  16. $plugin_info = array(
  17. 'pi_name' => 'Made By Hippo Language Date/Time Convert',
  18. 'pi_version' => '1.0',
  19. 'pi_author' => 'Made By Hippo',
  20. 'pi_author_url' => 'http://www.madebyhippo.com/addon-shack/',
  21. 'pi_description' => 'Allows you to convert your EE date/time into a different language',
  22. 'pi_usage' => Datetime_convert::usage()
  23. );
  24. class Datetime_convert {
  25. var $return_data = "";
  26. // ----------------------------------------
  27. // Plugin Usage
  28. // ----------------------------------------
  29. // This function describes how the plugin is used.
  30. // Make sure and use output buffering
  31. // Thanks to Peter Siska (http://www.designchuchi.ch) for a slight tweak to the date logic.
  32. function datetime_convert()
  33. {
  34. $this->EE =& get_instance();
  35. header('Content-Type: text/html; charset=utf-8');
  36. $language=$this->EE->TMPL->fetch_param('language');
  37. $format = $this->EE->TMPL->fetch_param('format');
  38. $olddate = $this->EE->TMPL->tagdata;
  39. setlocale(LC_ALL, $language);
  40. $trans = get_html_translation_table(HTML_ENTITIES);
  41. $newdate = strtr(strftime($format,$olddate), $trans);
  42. $this->return_data = $newdate;
  43. }
  44. function usage()
  45. {
  46. ob_start();
  47. ?>
  48. Simply encapsulate your ExpressionEngine Date/Time into the following Tags :
  49. {exp:datetime_convert language="" format=""}{/exp:datetime_convert}
  50. Passing the appropriate Language reference into the LANG="" parameter.
  51. * fr_FR : French
  52. * es_ES : Spanish
  53. * nl_NL : Dutch
  54. Depending on what Locales are installed on your server. You can check this by running 'locale -a' from a console window.
  55. Passing the format that you would like the date/time returned in using the FORMAT="" parameter:
  56. Default format is usually "%A %e %B %Y", however, review http://php.net/manual/en/function.strftime.php for full details on formatting
  57. <?php
  58. $buffer = ob_get_contents();
  59. ob_end_clean();
  60. return $buffer;
  61. }
  62. /* END */
  63. }
  64. /* End of file pi.datetime_convert.php */
  65. /* Location: ./system/expressionengine/third_party/datetime_convert/pi.datetime_convert.php */