Add configuration to enable curl request with proxy or any other CURLOPT
authorcavaliet
Thu, 23 Feb 2012 18:52:59 +0100
changeset 76 bb7808e180c3
parent 73 12fc4e8b6fde
child 77 021131fbe2c5
Add configuration to enable curl request with proxy or any other CURLOPT
Controller/WikiTagController.php
DependencyInjection/Configuration.php
DependencyInjection/WikiTagExtension.php
Resources/public/css/wikiTag.css
Utils/WikiTagUtils.php
--- a/Controller/WikiTagController.php	Mon Feb 20 12:09:41 2012 +0100
+++ b/Controller/WikiTagController.php	Thu Feb 23 18:52:59 2012 +0100
@@ -107,6 +107,7 @@
         }
         
         $ordered_tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOrderedTagsForDoc($id_doc);
+        //$ordered_tags = null;
         return $this->render('WikiTagBundle:WikiTag:documentTags.html.twig', array('ordered_tags' => $ordered_tags, 'doc_id' => $id_doc, 'columns' => $columns_array));
     }
 
--- a/DependencyInjection/Configuration.php	Mon Feb 20 12:09:41 2012 +0100
+++ b/DependencyInjection/Configuration.php	Thu Feb 23 18:52:59 2012 +0100
@@ -66,6 +66,12 @@
                     ->prototype('variable')
                     ->end()
                 ->end()
+                ->arrayNode('curl_options')
+                    ->treatNullLike(array())
+                    ->useAttributeAsKey('name')
+                    ->prototype('variable')
+                    ->end()
+                ->end()
             ->end();
         
         return $treeBuilder;
--- a/DependencyInjection/WikiTagExtension.php	Mon Feb 20 12:09:41 2012 +0100
+++ b/DependencyInjection/WikiTagExtension.php	Thu Feb 23 18:52:59 2012 +0100
@@ -53,5 +53,6 @@
         $container->setParameter("wiki_tag.route_for_documents_by_tag", $config['route_for_documents_by_tag']);
         $container->setParameter("wiki_tag.reactive_selectors", $config['reactive_selectors']);
         $container->setParameter("wiki_tag.document_list_profile", $config['document_list_profile']);
+        $container->setParameter("wiki_tag.curl_options", $config['curl_options']);
     }
 }
--- a/Resources/public/css/wikiTag.css	Mon Feb 20 12:09:41 2012 +0100
+++ b/Resources/public/css/wikiTag.css	Thu Feb 23 18:52:59 2012 +0100
@@ -10,6 +10,7 @@
     float: left;
     overflow: auto;
     width: 100%;
+    min-height: 300px;
 }
 #wikitag_table {
     width: 100%;
--- a/Utils/WikiTagUtils.php	Mon Feb 20 12:09:41 2012 +0100
+++ b/Utils/WikiTagUtils.php	Thu Feb 23 18:52:59 2012 +0100
@@ -200,9 +200,25 @@
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
-        //TODO: change
-        curl_setopt($ch, CURLOPT_USERAGENT, 'http://www.iri.centrepompidou.fr');
+        // default values
+        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:10.0.1) Gecko/20100101 Firefox/10.0.1');
         curl_setopt($ch, CURLOPT_TIMEOUT_MS, 5000);
+        // Set options if they are set in the config.yml file, typically for proxy configuration.
+        // Thanks to the configuration file, it will execute commands like "curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);" or "curl_setopt($ch, CURLOPT_PROXY, "xxx.yyy.zzz:PORT");"
+        $curl_options = $GLOBALS["kernel"]->getContainer()->getParameter("wiki_tag.curl_options");
+        foreach ($curl_options as $key => $value) {
+            if(strtoupper($value)=='TRUE'){
+                $value = TRUE;
+            }
+            else if (strtoupper($value)=='FALSE'){
+                $value = FALSE;
+            }
+            else if (defined($value)){
+                $value = constant($value);
+            }
+            curl_setopt($ch, constant($key), $value);
+        }
+        // end of treatment
         $res = curl_exec($ch);
         $curl_errno = curl_errno($ch);
         $curl_error = curl_error($ch);