Pārlūkot izejas kodu

se limpia la url del parametro remote_client_create_url

Guillermo Espinoza 8 gadi atpakaļ
vecāks
revīzija
958d70c929

+ 5 - 2
Resources/views/Type/remote_client_widget.html.twig

@@ -35,15 +35,18 @@
             });
         });
         </script>
-        <div>
+        <div style="width: 100%;" class="clearfix">
             <div style="width: 50%; float: left;">
                 {{ block('choice_widget') }}
             </div>
+            {% set url = remote_client_url() %}
+            {% if url != '#' %}
             <div style="width: 50%; float: left;">
-                <a href="{{ remote_client_url() }}" class="btn btn-link" target="_blank" title="{{ 'link.create_client'|trans({}, 'WebserviceBundle') }}">
+                <a href="{{ url }}" class="btn btn-link" target="_blank" title="{{ 'link.create_client'|trans({}, 'WebserviceBundle') }}">
                     <i class="fa fa-plus-circle" aria-hidden="true"></i>
                 </a>
             </div>
+            {% endif %}
         </div>
     {% endspaceless %}
 {% endblock %}

+ 8 - 2
Twig/RemoteClientExtension.php

@@ -3,6 +3,7 @@
 namespace WebserviceBundle\Twig;
 
 use WebserviceBundle\Services\Webservice;
+use WebserviceBundle\Utils\HttpUtils;
 
 class RemoteClientExtension extends \Twig_Extension
 {
@@ -54,9 +55,14 @@ class RemoteClientExtension extends \Twig_Extension
      */
     public function getClientCreateUrl()
     {
-        return $this->remoteClientCreateUrl;
+        $url = HttpUtils::cleanUrl($this->remoteClientCreateUrl);
+        if ($url == '' || filter_var($url, FILTER_VALIDATE_URL) === false) {
+            return '#';
+        }
+        
+        return $url;
     }
-
+    
     /**
      * @return string
      */

+ 30 - 0
Utils/HttpUtils.php

@@ -0,0 +1,30 @@
+<?php
+
+namespace WebserviceBundle\Utils;
+
+class HttpUtils
+{
+
+    /**
+     * @param string $url
+     * 
+     * @return string
+     */
+    public static function cleanUrl($url)
+    {
+        $parsed_url = parse_url($url);
+
+        $scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
+        $host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
+        $port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
+        $user = isset($parsed_url['user']) ? $parsed_url['user'] : '';
+        $pass = isset($parsed_url['pass']) ? ':' . $parsed_url['pass'] : '';
+        $pass = ($user || $pass) ? "$pass@" : '';
+        $path = isset($parsed_url['path']) ? '/' . implode('/', array_filter(explode('/', $parsed_url['path']))) : '';
+        $query = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : '';
+        $fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : '';
+
+        return "$scheme$user$pass$host$port$path$query$fragment";
+    }
+
+}