Show
Ignore:
Timestamp:
06/27/08 20:44:04 (5 months ago)
Author:
arthus
Message:

Made suggestr plugin use Yahoo tag extractor

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • plugins/suggestr/trunk/suggestr.plugin.php

    r634 r647  
    2323     
    2424    public function action_ajax_tag_suggest( $handler ) { 
    25         $count= 10; 
    2625        $text= $handler->handler_vars['text']; 
    27         $tags= array('lol', 'cool', 'lorem', 'ipsum', 'mipsum', 'ripwik', 'tiktk', 'likarick', 'dialect',); 
    28         $message= _t('No tag suggestions could be found'); 
     26        $tags= array(); 
     27         
     28        $tags = $this->fetch_yahoo_tags($text); 
    2929         
    3030        $tags = serialize($tags); 
     
    3232        $tags = unserialize($tags); 
    3333         
    34         $message= sprintf( '%d tag ' . _n( _t( 'suggestion'), _t( 'suggestions' ), $count ) . ' could be found.', $count ); 
     34        $count = count($tags); 
     35         
     36        if($count == 0) { 
     37            $message= _t('No tag suggestions could be found'); 
     38        } else { 
     39            $message= sprintf( '%d tag ' . _n( _t( 'suggestion'), _t( 'suggestions' ), $count ) . ' could be found.', $count ); 
     40        } 
    3541         
    3642        echo json_encode(array('count' => $count, 'tags' => $tags, 'message' => $message));      
     43    } 
     44     
     45    public function fetch_yahoo_tags( $text ) { 
     46        $appID = 'UZuNQnrV34En.c9itu77sQrdjp.FQU81t8azZeE5YmWjRkP9wVlPg.CPIc8eLZT68GI-'; 
     47        $context = $text; 
     48         
     49        $request = new RemoteRequest('http://search.yahooapis.com/ContentAnalysisService/V1/termExtraction', 'POST'); 
     50        $request->set_params(array( 
     51            'appid' => $appID, 
     52            'context' => $context 
     53        )); 
     54        $request->execute(); 
     55         
     56        $response = $request->get_response_body(); 
     57         
     58        $xml = new SimpleXMLElement($response); 
     59         
     60        $tags= array(); 
     61         
     62        foreach($xml->Result as $tag) { 
     63            $tags[] = strval($tag); 
     64        } 
     65         
     66        return $tags; 
     67         
    3768    } 
    3869