Utils/WikiTagUtils.php
changeset 112 14653baf4f6b
parent 77 021131fbe2c5
child 115 085ea4dbfeee
equal deleted inserted replaced
111:fef492d144f4 112:14653baf4f6b
    11 namespace IRI\Bundle\WikiTagBundle\Utils;
    11 namespace IRI\Bundle\WikiTagBundle\Utils;
    12 
    12 
    13 use IRI\Bundle\WikiTagBundle\Entity\Tag;
    13 use IRI\Bundle\WikiTagBundle\Entity\Tag;
    14 
    14 
    15 class WikiTagUtils
    15 class WikiTagUtils
    16 {
    16 {   
    17     // Constants
       
    18     private static $WIKIPEDIA_API_URL = "http://fr.wikipedia.org/w/api.php";
       
    19     private static $WIKIPEDIA_VERSION_PERMALINK_TEMPLATE = "http://fr.wikipedia.org/w/index.php?oldid=%s";
       
    20     private static $DBPEDIA_URI_TEMPLATE = "http://dbpedia.org/resource/%s";
       
    21     
       
    22     
       
    23     /**
    17     /**
    24      * Cleans the tag label
    18      * Cleans the tag label
    25      */
    19      */
    26     public static function normalizeTag($tag_label)
    20     public static function normalizeTag($tag_label)
    27     {
    21     {
   201             else{
   195             else{
   202                 $params_str .= '&'.$key.'='.$value;
   196                 $params_str .= '&'.$key.'='.$value;
   203             }
   197             }
   204         }
   198         }
   205         
   199         
   206         $url = WikiTagUtils::$WIKIPEDIA_API_URL.'?'.$params_str;
   200         //$url = WikiTagUtils::$WIKIPEDIA_API_URL.'?'.$params_str;
       
   201         //throw new \Exception($GLOBALS["kernel"]->getContainer()->getParameter("wiki_tag.url_templates"), 1, null);
       
   202         $url = $GLOBALS["kernel"]->getContainer()->getParameter("wiki_tag.url_templates")["wikipedia_api"].'?'.$params_str;
   207         
   203         
   208         $ch = curl_init();
   204         $ch = curl_init();
   209         curl_setopt($ch, CURLOPT_URL, $url);
   205         curl_setopt($ch, CURLOPT_URL, $url);
   210         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   206         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   211         // default values
   207         // default values
   269     /**
   265     /**
   270      * Builds DbPedia URI
   266      * Builds DbPedia URI
   271      */
   267      */
   272     private static function getDbpediaUri($english_label)
   268     private static function getDbpediaUri($english_label)
   273     {
   269     {
   274         return sprintf(WikiTagUtils::$DBPEDIA_URI_TEMPLATE, WikiTagUtils::urlize_for_wikipedia($english_label));
   270         return sprintf($GLOBALS["kernel"]->getContainer()->getParameter("wiki_tag.url_templates")["dbpedia"], WikiTagUtils::urlize_for_wikipedia($english_label));
   275     }
   271     }
   276     
   272     
   277     /**
   273     /**
   278      * URLencode label for wikipedia
   274      * URLencode label for wikipedia
   279      */
   275      */