• R/O
  • SSH
  • HTTPS

y2pukiwiki: Commit


Commit MetaInfo

Revision124 (tree)
Time2010-04-19 03:19:04
Authory2katayama

Log Message

mimetexプラグインを追加

Change Summary

Incremental Difference

--- pukiwiki-1.4.7_notb_utf8/plugin/mimetex.inc.php (nonexistent)
+++ pukiwiki-1.4.7_notb_utf8/plugin/mimetex.inc.php (revision 124)
@@ -0,0 +1,106 @@
1+<?php
2+/**
3+ * Display Math Equations using mimetex.cgi
4+ *
5+ * @author sonots
6+ * @license http://www.gnu.org/licenses/gpl.html GPL v2
7+ * @link http://lsx.sourceforge.jp/?Plugin%2Fmimetex.inc.php
8+ * @version $Id: mimetex.inc.php,v 1.4 2007-04-01 06:10:21Z sonots $
9+ * @package plugin
10+ */
11+
12+if (! defined('INIT_DIR')) // if not Plus!
13+ if (file_exists(DATA_HOME . 'init/mimetex.ini.php'))
14+ include_once(DATA_HOME . 'init/mimetex.ini.php');
15+
16+defined('MIMETEX_PATH') or define('MIMETEX_PATH', 'http://www.forkosh.dreamhost.com/cgi-bin/mimetex.cgi');
17+defined('MIMETEX_CACHE') or define('MIMETEX_CACHE', 1); // 1: Use Cache Function
18+defined('MIMETEX_CACHE_DIR') or define('MIMETEX_CACHE_DIR', CACHE_DIR);
19+defined('MIMETEX_CACHE_URI') or define('MIMETEX_CACHE_URI', CACHE_DIR);
20+defined('MIMETEX_CACHE_POSTFIX') or define('MIMETEX_CACHE_POSTFIX', '.mimetex.gif');
21+
22+function plugin_mimetex_inline()
23+{
24+ $args = func_get_args();
25+ array_pop($args); // drop {};
26+ $body = call_user_func_array('plugin_mimetex_body', $args);
27+ return '<span class="mimetex">' . $body . '</span>';
28+}
29+
30+function plugin_mimetex_convert()
31+{
32+ $args = func_get_args();
33+ $body = call_user_func_array('plugin_mimetex_body', $args);
34+ return '<div class="mimetex" style="text-align:center;">' . $body . '</div>';
35+}
36+
37+
38+function plugin_mimetex_body()
39+{
40+ $args = func_get_args();
41+ $mimetex = trim(implode(",", $args));
42+
43+ // Format
44+ $mimetex = str_replace("\r", '', $mimetex); // delete carriage return
45+ $mimetex = str_replace("\n", '', $mimetex);
46+ //$mimetex = strtr($mimetex, ' ', '~'); // convert space into tex space style.
47+ //$mimetex = str_replace("\r", '\\\\', $mimetex); // convert return into tex style return
48+ if (preg_match('/Safari/', getenv('HTTP_USER_AGENT'))) {
49+ $mimetex = strtr($mimetex, '\?', '\\'); // stupid safari converts \ into ?.
50+ }
51+
52+ $cgi_uri = plugin_mimetex_cgi_uri($mimetex);
53+ if (MIMETEX_CACHE) {
54+ $cache_filename = plugin_mimetex_cache_filename($mimetex);
55+ $cache_uri = plugin_mimetex_cache_uri($mimetex);
56+ if (! file_exists($cache_filename)) {
57+ $err = plugin_mimetex_cache($cgi_uri, $cache_filename);
58+ if ($err === -1) {
59+ return 'mimetex(): mimetex cache dir '. MIMETEX_CACHE_DIR . ' does not exist or not writable. ';
60+ } elseif ($err === -2) {
61+ return 'mimetex(): mimetex cgi ' . MIMETEX_PATH . ' does not respond. ';
62+ }
63+ }
64+ $src = $cache_uri;
65+ } else {
66+ $src = $cgi_uri;
67+ }
68+ return '<img src="' . $src . '" alt="' . htmlspecialchars($mimetex) . '" />';
69+}
70+
71+function plugin_mimetex_cache_filename($str)
72+{
73+ return MIMETEX_CACHE_DIR . plugin_mimetex_cache_encode($str) . MIMETEX_CACHE_POSTFIX;
74+}
75+
76+function plugin_mimetex_cache_uri($str)
77+{
78+ return MIMETEX_CACHE_URI . plugin_mimetex_cache_encode($str) . MIMETEX_CACHE_POSTFIX;
79+}
80+
81+function plugin_mimetex_cache_encode($str)
82+{
83+ return md5(str_replace(' ', '', $str));
84+}
85+
86+function plugin_mimetex_cgi_uri($mimetex)
87+{
88+ return MIMETEX_PATH . '?' . rawurlencode($mimetex);
89+}
90+
91+function plugin_mimetex_cache($uri, $filename)
92+{
93+ $fp = fopen($uri, "rb");
94+ if ($fp === FALSE) { return -2; }
95+ $data = "";
96+ while (!feof($fp)) {
97+ $data .= fread($fp, 1000);
98+ }
99+ fclose($fp);
100+ $fp = fopen($filename, "wb");
101+ if ($fp === FALSE) { return -1; }
102+ fwrite($fp, $data);
103+ fclose($fp);
104+}
105+
106+?>
Show on old repository browser