1<?php 2/** 3 * The syntax plugin to handle <project-file> tags 4 * 5 */ 6 7require_once(dirname(__FILE__).'/../conf.php'); 8require_once(dirname(__FILE__).'/../lib/layout.php'); 9require_once(dirname(__FILE__).'/../lib/file_definition.php'); 10require_once(dirname(__FILE__).'/../lib/project.php'); 11require_once DOKU_PLUGIN . 'syntax.php'; 12require_once DOKU_INC . 'inc/common.php'; 13 14class syntax_plugin_projects_projectfile extends DokuWiki_Syntax_Plugin { 15 // the current project-file 16 private $project_file = NULL; 17 /** 18 * return some info 19 */ 20 function getInfo(){ 21 return array( 22 'author' => 'Junling Ma', 23 'email' => 'junlingm@gmail.com', 24 'date' => '2011-11-24', 25 'name' => 'Project-file Plugin', 26 'desc' => 'display the header of project files', 27 'url' => 'http://www.math.uvic.ca/~jma' 28 ); 29 } 30 31 function getType() { 32 return 'substition'; 33 } 34 35 function getPType() { 36 return 'block'; 37 } 38 39 function getSort() { 40 return 1; 41 } 42 43 function connectTo($mode) { 44 $this->Lexer->addSpecialPattern('<' . PROJECTS_TAG . ' .*?/>', 45 $mode, 'plugin_projects_projectfile'); 46 } 47 48 /** 49 * Handle the match 50 */ 51 function handle($match, $state, $pos, &$handler) { 52 set_media_file_revision_limit($this->getConf('media file revision limit')); 53 if ($state != DOKU_LEXER_SPECIAL) return NULL; 54 global $ID; 55 $path = explode(":", $ID); 56 $name = array_pop($path); 57 $this->project_file = FileDefinition::parse($name, $match); 58 $this->project_file->position = $pos; 59 $this->project_file->end = $pos + strlen($match) - 1; 60 return $this->project_file; 61 } 62 63 /** 64 * Create output 65 */ 66 function render($mode, &$renderer, $file) { 67 if ($file == NULL) return; 68 switch ($mode) { 69 case 'metadata' : 70 if (is_array($data)) return; 71 global $ID; 72 $renderer->meta['ProjectFile'] = $file; 73 if ($file->attribute('highlight')) 74 $renderer->persistent['ProjectFile:highlight'] = $file->attribute('highlight'); 75 break; 76 case 'xhtml' : 77 $this->render_xhtml($renderer, $file); 78 break; 79 } 80 } 81 82 private function render_xhtml(&$renderer, $file) { 83 global $version_file; 84 global $changelog; 85 global $ID; 86 if (auth_quickaclcheck($ID) == AUTH_ADMIN && $this->getConf('check updates')) { 87 include(dirname(__FILE__).'/../version.php'); 88 $new_version = file_get_contents($version_file); 89 if (strcmp($new_version, $version) > 0) 90 msg('A new version ' . $new_version . 91 ' of the projects plugin is available. See the <a href="' 92 . $changelog . '">change log</a>'); 93 if (!$file) return; 94 } 95 $project = Project::project(NULL, true); 96 $renderer->nocache(); 97 switch ($file->type()) { 98 case SOURCE: 99 $layout = new ProjectFileLayout($project, $ID, $file); 100 break; 101 case TARGET: 102 $layout = new TargetLayout($project, $ID, $file); 103 break; 104 case CROSSLINK: 105 $layout = new CrosslinkLayout($project, $ID, $file); 106 break; 107 } 108 $layout->render($renderer); 109 } 110 111} 112?>