*/ // must be run within Dokuwiki if (!defined('DOKU_INC')) die(); class syntax_plugin_daummovie extends DokuWiki_Syntax_Plugin { /** * @return string Syntax mode type */ public function getType() { return 'container'; } /** * @return string Paragraph type */ public function getPType() { return 'normal'; } /** * @return int Sort order - Low numbers go before high numbers */ public function getSort() { return 319; } /** * Connect lookup pattern to lexer. * * @param string $mode Parser mode */ public function connectTo($mode) { $this->Lexer->addSpecialPattern ('\{\{daummovie>[^}]*\}\}',$mode,'plugin_daummovie'); } /** * Handle matches of the daummovie syntax * * @param string $match The match of the syntax * @param int $state The state of the handler * @param int $pos The position in the document * @param Doku_Handler $handler The handler * @return array Data for the renderer */ public function handle($match, $state, $pos, Doku_Handler $handler){ $data = array(); $match = substr($match,12,-2); //strip markup from start and end $apikey= $this->getConf('daumapikey'); $request = 'http://apis.daum.net/contents/movie?apikey='.$apikey .'&output=json&result=3&q='.urlencode($match); for ($tries=1; $tries<10;$tries++) { $response = json_decode($this->curl($request)); if ($response->channel->item[0]->title[0]->content!=null) break; usleep(100000); } $movie=$response->channel->item[0]; $data['thumbnail'] =$movie->thumbnail[0]->content; $data['title'] =$movie->title[0]->content; $data['link'] =$movie->title[0]->link; $data['eng_title'] =$movie->eng_title[0]->content; $data['year'] =$movie->year[0]->content; $data['director'] =$this->_join2($movie->director,false); $data['nation'] =$movie->nation[0]->content; $data['grades'] =$movie->grades[0]->content; $data['genre'] =$this->_join2($movie->genre,false); $data['actor'] =$this->_join2($movie->actor,false); $data['open_info'] =$this->_join2($movie->open_info); $data['query'] = $match." (".$tries.") ".$response->code; return $data; } /** * Render xhtml output or metadata * * @param string $mode Renderer mode (supported modes: xhtml) * @param Doku_Renderer $renderer The renderer * @param array $data The data from the handler() function * @return bool If rendering was successful. */ public function render($mode, Doku_Renderer $renderer, $data) { if($mode != 'xhtml') return false; if ($data['title']==null) { $renderer->doc.="[DaumMovie: ".$data['query']."]"; $renderer->doc.= date(DATE_RFC2822); return false;} $renderer->doc.= "