You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.5 KiB

  1. <?php
  2. /**
  3. * @file WidgetCommon.php
  4. * This file is part of MOVIM.
  5. *
  6. * @brief The widgets commons methods.
  7. *
  8. * @author Timothée Jaussoin <edhelas@gmail.com>
  9. *
  10. * @date 08 march 2012
  11. *
  12. * Copyright (C)2010 MOVIM Project
  13. *
  14. * See COPYING for licensing information.
  15. *
  16. */
  17. class WidgetCommon extends WidgetBase {
  18. function ajaxShowPosition($pos)
  19. {
  20. list($lat,$lon) = explode(',', $pos);
  21. $pos = json_decode(
  22. file_get_contents('http://nominatim.openstreetmap.org/reverse?format=json&lat='.$lat.'&lon='.$lon.'&zoom=27&addressdetails=1')
  23. );
  24. RPC::call('movim_fill', 'postpublishlocation' , (string)$pos->display_name);
  25. RPC::commit();
  26. }
  27. function ajaxPublishItem($server, $node, $form)
  28. {
  29. $content = $form['content'];
  30. $title = $form['title'];
  31. $geo = false;
  32. if(isset($form['latlonpos']) && $form['latlonpos'] != '') {
  33. list($lat,$lon) = explode(',', $form['latlonpos']);
  34. $pos = json_decode(
  35. file_get_contents('http://nominatim.openstreetmap.org/reverse?format=json&lat='.$lat.'&lon='.$lon.'&zoom=27&addressdetails=1')
  36. );
  37. $geo = array(
  38. 'latitude' => (string)$pos->lat,
  39. 'longitude' => (string)$pos->lon,
  40. 'altitude' => (string)$pos->alt,
  41. 'country' => (string)$pos->address->country,
  42. 'countrycode' => (string)$pos->address->country_code,
  43. 'region' => (string)$pos->address->county,
  44. 'postalcode' => (string)$pos->address->postcode,
  45. 'locality' => (string)$pos->address->city,
  46. 'street' => (string)$pos->address->path,
  47. 'building' => (string)$pos->address->building,
  48. 'text' => (string)$pos->display_name,
  49. 'uri' => ''//'http://www.openstreetmap.org/'.urlencode('?lat='.(string)$pos->lat.'&lon='.(string)$pos->lon.'&zoom=10')
  50. );
  51. }
  52. if($content != '') {
  53. $content = Markdown::defaultTransform($content);
  54. $p = new PostPublish;
  55. $p->setFrom($this->user->getLogin())
  56. ->setTo($server)
  57. ->setNode($node)
  58. ->setLocation($geo)
  59. ->setTitle($title)
  60. ->setContentHtml(rawurldecode($content))
  61. ->enableComments()
  62. ->request();
  63. }
  64. }
  65. }