maio
[h2N7SspZmY.git] / lib / plugins / chart2 / syntax.php
blob1880505a8f2706b9dc60e912ed1661538f937908
1 <?php
2 /*
3 description : Display XML/SWF Charts ver.5
4 author : Ikuo Obataya
5 email : i.obataya@gmail.com
6 lastupdate : 2008-10-30
7 license : GPL 2 (http://www.gnu.org/licenses/gpl.html)
8 */
9 if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
10 require_once(DOKU_INC.'inc/init.php');
11 if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
12 require_once(DOKU_PLUGIN.'syntax.php');
14 class syntax_plugin_chart2 extends DokuWiki_Syntax_Plugin {
15 var $swfLoc = '';
16 var $swfLibLoc = '';
17 var $template = '';
18 // Constructor
19 function syntax_plugin_chart2(){
20 $this->swfLoc = DOKU_BASE.'lib/plugins/chart2/maani.us/charts';
21 $this->swfLibLoc = DOKU_BASE.'lib/plugins/chart2/maani.us/charts_library';
22 $this->setTemplate();
24 function getInfo(){
25 return array(
26 'author' => 'Ikuo Obataya',
27 'email' => 'I.Obataya@gmail.com',
28 'date' => '2008-10-30',
29 'name' => 'XML/SWF Charts Plugin',
30 'desc' => 'Create SWF Charts by www.maani.us
31 <chart2 (filename)> script </chart2>',
32 'url' => 'http://wiki.symplus.co.jp/computer/en/chart2_plugin',
35 function getType(){ return 'protected'; }
36 function getSort(){ return 916; }
37 function connectTo($mode) {$this->Lexer->addEntryPattern('<chart2(?=.*?>.*?</chart2>)',$mode,'plugin_chart2');}
38 function postConnect(){$this->Lexer->addExitPattern('</chart2>','plugin_chart2');}
40 function handle($match, $state, $pos) {
41 switch ($state) {
42 case DOKU_LEXER_ENTER : return array($state);
43 case DOKU_LEXER_UNMATCHED :return array($state,$match,$pos);
44 case DOKU_LEXER_EXIT : return array($state);
46 return array();
48 function render($mode, &$renderer, $data){
49 if ($mode!='xhtml') return;
50 global $ID;
51 global $conf;
52 @list($state, $match,$pos) = $data;
53 switch ($state) {
54 case DOKU_LEXER_ENTER:break;
55 case DOKU_LEXER_UNMATCHED:
56 $i = strpos($match,">");
57 if($att_idx<0) return array();
58 $att_str = trim(substr($match,0,$i));
59 $chart_xml = substr($match,$i+1);
61 $att = explode(" ",$att_str);
62 $tryFN = preg_replace("/({{)?([^|}]+).*(}})?/",'$2',$att[0]);
63 if(strpos($tryFN,"http")!==false){
65 * external xml file
67 $source = "xml_source=".$tryFN;
68 $idx=1;
69 }else{
71 * internal xml/data
73 $filename = mediaFN($tryFN);
74 if(is_dir($filename) || !file_exists($filename)){
75 $filename="";
76 $xml_data= strtr($chart_xml,array("\n"=>"","\t"=>""));
77 $xml_data= preg_replace("/>\s+</","><",$xml_data);
78 $source = "xml_data=".$xml_data;
79 $idx=0;
80 }else{
81 //$source = "xml_source=".ml($tryFN,"",true,"",true);
82 $source = "xml_source=/~kssilveira/site/lib/exe/fetch.php?media=".$tryFN;
83 $idx=1;
86 $width = (!empty($att[$idx])) ? $att[$idx] : $this->getConf('default_width');$idx++;
87 $height = (!empty($att[$idx])) ? $att[$idx] : $this->getConf('default_height');$idx++;
88 $oid = (!empty($att[$idx])) ? $att[$idx] : 'chart'.$pos;$idx++;
89 $bgcolor = (!empty($att[$idx])) ? $att[$idx] : $this->getConf('default_bgcolor');$idx++;
90 $align = (!empty($att[$idx])) ? $att[$idx] : '';
92 $renderer->doc.=sprintf($this->template,$width,$height,$this->swfLoc,$this->swfLoc,
93 "library_path=".$this->swfLibLoc."&".$source,$oid,$oid,$bgcolor,$align);
94 break;
95 case DOKU_LEXER_EXIT:break;
97 return true;
100 function setTemplate(){
101 $this->template = <<<EOT
102 <script language="JavaScript" type="text/javascript">
103 <!--
104 var requiredMajorVersion = 9;
105 var requiredMinorVersion = 0;
106 var requiredRevision = 45;
107 if (AC_FL_RunContent == 0 || DetectFlashVer == 0) {
108 alert("This page requires AC_RunActiveContent.js.");
109 } else {
110 var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
111 if(hasRightVersion) {
112 AC_FL_RunContent(
113 'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,45,0',
114 'width', '%s',
115 'height', '%s',
116 'movie', '%s',
117 'src', '%s',
118 'FlashVars', "%s",
119 'id', '%s',
120 'name', '%s',
121 'bgcolor', '%s',
122 'align', '%s',
123 'scale', 'noscale',
124 'salign', 'TL',
125 'wmode', 'opaque',
126 'menu', 'true',
127 'allowFullScreen', 'true',
128 'allowScriptAccess','sameDomain',
129 'quality', 'high',
130 'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
131 'play', 'true',
132 'devicefont', 'false'
134 } else {
135 var alternateContent = 'This content requires the Adobe Flash Player. '
136 + '<u><a href=http://www.macromedia.com/go/getflash/>Get Flash</a></u>.';
137 document.write(alternateContent);
141 </script>
142 <noscript><p>This content requires JavaScript.</p></noscript>
143 EOT;