PageRenderTime 53ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/enviar.php

https://gitlab.com/sotitrox/granada
PHP | 122 lines | 120 code | 0 blank | 2 comment | 20 complexity | ac44a048d871057507caf1e6a586a727 MD5 | raw file
  1. <?php
  2. include('recursos/estatico/librerias/Parsedown.php');
  3. require_once('recursos/estatico/librerias/conectorpump.php');
  4. require_once('sistema/configuracion.php');
  5. $url = $_POST["url"];
  6. $imagen = $_POST["radios"];
  7. $usuario = $_POST["usuario"];
  8. $titulo = stripslashes($_POST["titulo"]);
  9. $descripcion = Parsedown::instance()->parse($_POST["descripcion"]);
  10. $descripcion = str_replace('\\', '', $descripcion);
  11. $etiquetas = explode(',', str_replace(' ', '', $_POST["etiquetas"]));
  12. foreach($etiquetas as $tag) {
  13. $tags .= '#'.$tag.' ';
  14. }
  15. $host = ConectorPump::extractorPumpid($usuario, "nodo");
  16. $nombre = ConectorPump::extractorPumpid($usuario, "alias");
  17. $query = "SELECT oauth.consumer_key, oauth.consumer_secret, oauth.conexion, token.token, token.token_secret ";
  18. $query.= "FROM oauth, token WHERE servidor='$host' and user='$usuario'";
  19. $query = mysql_query($query, $con);
  20. if(!$query) {
  21. echo "Hubo un error al solicitar información a la base de datos: <br>".mysql_errno()." - ".mysql_error();
  22. exit;
  23. }
  24. $cred = mysql_fetch_array($query);
  25. $conexion = $cred["conexion"];
  26. $oauth_token = $cred["token"];
  27. $oauth_token_secret = $cred["token_secret"];
  28. $oauth_consumer_key = $cred["consumer_key"];
  29. $oauth_consumer_secret = $cred["consumer_secret"];
  30. #Guardamos opciones del usuario
  31. if($_POST['guardar']) {
  32. if(!$_POST["coleccion"]) {
  33. $array1 = array();
  34. }
  35. else {
  36. $array1 = $_POST["coleccion"];
  37. }
  38. if(!$_POST["seguidor"]) {
  39. $array2 = array();
  40. }
  41. else {
  42. $array2 = $_POST["seguidor"];
  43. }
  44. $array_opciones = array_merge($array1, $array2);
  45. $cadena = implode(';;', $array_opciones);
  46. $segundos = ConectorPump::selloTiempo();
  47. $expire = $segundos+2592000;
  48. $sc = setcookie("opciones", $cadena, $expire);
  49. if(!$sc) {
  50. echo "Necesita habilitar el uso de cookies en este sitio si desea guardar su selección de destinatarios";
  51. }
  52. }
  53. else {
  54. $segundos = ConectorPump::selloTiempo();
  55. $expire = $segundos-2592000;
  56. $sc = setcookie("opciones", '', $expire);
  57. if(!$sc) {
  58. echo "Necesita habilitar el uso de cookies en este sitio si desea guardar su selección de destinatarios";
  59. }
  60. }
  61. $cc = array();
  62. $to = array();
  63. for ($x=0;$x < count($_POST["coleccion"]); $x++) {
  64. $coleccion = $_POST["coleccion"][$x];
  65. $cccoleccion = true;
  66. $cc = array_merge($cc, array(array(
  67. 'objectType' => 'collection',
  68. 'id' => $coleccion
  69. )));
  70. }
  71. for ($x=0;$x < count($_POST["seguidor"]); $x++) {
  72. $seguidor = $_POST["seguidor"][$x];
  73. $toseguidor = true;
  74. $to = array_merge($to, array(array(
  75. 'objectType' => 'person',
  76. 'id' => $seguidor
  77. )));
  78. }
  79. if(!$imagen) {
  80. $content = $descripcion.'<br>'.$tags.'<br>Fuente: <a href="'.$url.'" target="_blank">'.$url.'</a>';
  81. }
  82. else {
  83. $content = '<p align="center"><img src="'.$imagen.'" ></p>'.$descripcion.'<br>'.$tags.'<br>Fuente: <a href="'.$url.'" target="_blank">'.$url.'</a>';
  84. }
  85. $cc = array('cc' => $cc);
  86. $to = array('to' => $to);
  87. $object = array(
  88. 'displayName' => $titulo,
  89. 'content' => $content,
  90. 'objectType' => 'note'
  91. );
  92. $posteo = array(
  93. 'verb' => 'post',
  94. 'object' => $object
  95. );
  96. if($cccoleccion) {
  97. $posteo = array_merge($posteo, $cc);
  98. }
  99. if($toseguidor) {
  100. $posteo = array_merge($posteo, $to);
  101. }
  102. #Enviamos la nota y si es pública se envía al ofirehose.
  103. $nota = ConectorPump::enviarNota($posteo, $oauth_consumer_key, $oauth_consumer_secret, $oauth_token, $oauth_token_secret, $conexion, $usuario, $cliente);
  104. if($nota[0]) {
  105. if(array_search('http://activityschema.org/collection/public', $_POST["coleccion"]) !== false) {
  106. $post = ConectorPump::pingFirehose('https://ofirehose.com/ping', $nota[0]);
  107. }
  108. $actividad = json_decode($nota[0], true);
  109. if($actividad['object']['displayName']) {
  110. $titulo = $actividad['object']['displayName'];
  111. } else {
  112. $titulo = "La Nota";
  113. }
  114. $url = $actividad['object']['url'];
  115. $mensaje = rawurlencode(base64_encode("<b><a href=".$url.">".$titulo."</a></b> ha sido escrita con éxito."));
  116. header('Location: index.php?mensaje='.$mensaje);
  117. }
  118. else {
  119. $mensaje = rawurlencode(base64_encode("Error al escribir el mensaje, intente nuevamente, si el problema persiste, contacte al administrador."));
  120. header('Location: index.php?mensaje='.$mensaje);
  121. }
  122. ?>