1<?php 2/** 3 * action_plugin_tfslink - handles all actions for the tfs link plugin 4 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 5 * @author Thorsten Klingert <Thorsten.Klingert@gmail.com> 6 */ 7 8if(!defined('DOKU_INC')) die(); 9 10class action_plugin_tfslink extends DokuWiki_Action_Plugin { 11 12 /** 13 * Register its handlers with the DokuWiki's event controller 14 */ 15 public function register(Doku_Event_Handler $controller) { 16 $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this,'_ajax_call'); 17 } 18 19 /** 20 * handle ajax requests 21 */ 22 function _ajax_call(&$event, $param) { 23 if ($event->data !== 'tfslink') { 24 return; 25 } 26 //no other ajax call handlers needed 27 $event->stopPropagation(); 28 $event->preventDefault(); 29 30 switch($_REQUEST['req']) { 31 case 'projectcollections': 32 // list the project collections infos 33 header('Content-Type: application/json'); 34 35 $data = $this->_getProjectCollectionInfos(); 36 require_once DOKU_INC . 'inc/JSON.php'; 37 $json = new JSON(); 38 echo '' . $json->encode($data) . ''; 39 break; 40 } 41 } 42 43 /** 44 * Returns a list of all available non-default project collections 45 */ 46 private function _getProjectCollectionInfos() { 47 $data = array(); 48 $collections = $this->getConf('collections'); 49 if(!isset($collections) || !is_array($collections)) // no project collections set 50 return $data; 51 52 foreach($collections as $key => $options) 53 { 54 $keyData = array( 'title' => $key, 'baseUrl' => '', 'name' => '', 'guid' => '', 'version' => '' ); 55 if (is_array($options)){ // copy values from collection config 56 foreach(array_keys($keyData) as $confKey){ 57 if (isset($options[$confKey])) 58 $keyData[$confKey] = $options[$confKey]; 59 } 60 } 61 // add key as id 62 $keyData['id'] = $key; 63 $data[] = $keyData; 64 } 65 return $data; 66 } 67} 68