1<?php 2/** 3 * DokuWiki Plugin asana (Syntax Component) 4 * 5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html 6 * @author pierre Viloutreix <pierre@elonet.fr> 7 */ 8 9//include "/home/pedro/elonet/asana_dokuwiki/asana/remote/APILink.php"; 10include "./lib/plugins/asana/remote/APILink.php"; 11 12// must be run within Dokuwiki 13if (!defined('DOKU_INC')) die(); 14 15class syntax_plugin_asana_AsanaSyntax extends DokuWiki_Syntax_Plugin { 16 17 var $asana; 18 19 20 function getType() { return 'protected';} 21 function getAllowedTypes() { return array('container','substition','protected','disabled','formatting','paragraphs'); } 22 function getPType() { return 'normal';} 23 24 /** 25 * @return int Sort order - Low numbers go before high numbers 26 */ 27 public function getSort() { 28 return 196; 29 } 30 31 /** 32 * Connect lookup pattern to lexer. 33 * 34 * @param string $mode Parser mode 35 */ 36 // [[projects=[.*,]* ]?[tags=[.*,]* ]?[assignees=[.*,]* ]?] 37 //[.*,]* 38 public function connectTo($mode) { 39 $this->Lexer->addEntryPattern("\[asana :",$mode,'plugin_asana_AsanaSyntax'); 40 } 41 42 public function postConnect() { 43 $this->Lexer->addExitPattern('\]','plugin_asana_AsanaSyntax'); 44 } 45 46 /** 47 * Handle matches of the asana syntax 48 * 49 * @param string $match The match of the syntax 50 * @param int $state The state of the handler 51 * @param int $pos The position in the document 52 * @param Doku_Handler $handler The handler 53 * @return array Data for the renderer 54 */ 55 public function handle($match, $state, $pos, Doku_Handler &$handler){ 56 57 58 if($state == DOKU_LEXER_ENTER){ 59 60 $this->asana = new remote_plugin_asana_APILink(); 61 return $this->asana->connect(); 62 } 63 if($state == DOKU_LEXER_EXIT){ 64 return $this->asana->render_user(); 65 } 66 67 if($state == DOKU_LEXER_UNMATCHED){ 68 69 $attributs = preg_split('/[,]+/',$match); 70 foreach($attributs as $attr){ 71 if(strstr($attr,"workspace=")){ 72 $functionAddFilter= 'changeWorkspace'; 73 } 74 if(strstr($attr,"projects=")){ 75 $functionAddFilter = 'addProjectFilter'; 76 } 77 if(strstr($attr,"tags=")){ 78 $functionAddFilter = 'addTagFilter'; 79 } 80 if(strstr($attr,"assignees=")){ 81 $functionAddFilter = 'addAssigneeFilter'; 82 } 83 if(strstr($attr,"strings=")){ 84 $functionAddFilter = 'AddStringFilter'; 85 } 86 $filter = substr( $attr , strpos( $attr , "=" )+1 ); 87 if($filter != " " and $filter != ""){ 88 if($this->asana->$functionAddFilter($filter)==0){ 89 if($functionAddFilter == 'changeWorkspace'){ 90 return '<p>Le nom de workspace : '.$filter.' est inconnu.</p>'; 91 } 92 if($functionAddFilter =='addProjectFilter'){ 93 return '<p>Le nom de projet : '.$filter.' est inconnu.</p>'; 94 } 95 if($functionAddFilter =='addTagFilter'){ 96 return '<p>Le nom de tag : '.$filter.' est inconnu.</p>'; 97 } 98 if($functionAddFilter =='addAssigneeFilter'){ 99 return '<p>Le nom de l\'assignée : '.$filter.' est inconnu.</p>'; 100 } 101 } 102 } 103 } 104 } 105 106 } 107 108 109 /** 110 * Render xhtml output or metadata 111 * 112 * @param string $mode Renderer mode (supported modes: xhtml) 113 * @param Doku_Renderer $renderer The renderer 114 * @param array $data The data from the handler() function 115 * @return bool If rendering was successful. 116 */ 117 public function render($mode, Doku_Renderer &$renderer, $data) { 118 $renderer->doc .=$data; 119 return true; 120 } 121} 122 123// vim:ts=4:sw=4:et: 124