Changeset 363
- Timestamp:
- 03/22/08 17:14:52 (16 years ago)
- Location:
- plugins/remotelatex
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/remotelatex/_admin.php
r270 r363 1 <?php 1 <?php /* -*- tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */ 2 2 /***************************************************************\ 3 * This is RemoteLatex, a plugin for DotClear.*3 * This is 'Remote Latex', a plugin for Dotclear * 4 4 * * 5 * Copyright (c) 2007 6 * Oleksandr Syenchuk 5 * Copyright (c) 2007-2008 * 6 * Oleksandr Syenchuk and contributors. * 7 7 * * 8 8 * This is an open source software, distributed under the GNU * … … 10 10 * * 11 11 * You should have received a copy of the GNU General Public * 12 * License along with RemoteLatex (see COPYING.txt);*12 * License along with 'Remote Latex' (see COPYING.txt); * 13 13 * if not, write to the Free Software Foundation, Inc., * 14 14 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 15 15 \***************************************************************/ 16 17 # WARNING :18 # RemoteLatex is distributed in the hope that it will be useful,19 # but WITHOUT ANY WARRANTY; without even the implied warranty of20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the21 # GNU General Public License for more details.22 16 23 17 $core->addBehavior('coreInitWikiPost',array('remoteLatex','coreInitWikiPost')); … … 27 21 public static function coreInitWikiPost(&$wiki2xhtml) 28 22 { 29 $wiki2xhtml->registerFunction('macro: latex',23 $wiki2xhtml->registerFunction('macro:math', 30 24 array('remoteLatex','render')); 31 25 } 32 26 33 public static function render($tex te,$args)27 public static function render($tex,$args) 34 28 { 35 $texte = rawurlencode($texte); 36 $texServer = 'http://math.spip.org/tex.php?'; 37 return '<img src="'.$texServer.$texte.'" />'; 29 global $core; 30 31 $hash = md5($tex = trim($tex)); 32 33 try { 34 self::getSettings($latex_server,$root_path,$root_url); 35 36 $file_name = sprintf('%s/%s/%s.png', 37 $root_path, 38 substr($hash,0,2), 39 $hash 40 ); 41 42 $file_url = sprintf('%s/%s/%s.png', 43 $root_url, 44 substr($hash,0,2), 45 $hash 46 ); 47 48 if (file_exists($file_name)) { 49 return self::getHtml($tex,$file_url); 50 } 51 52 # File doesn't exist : we need create one 53 54 if (!is_dir(dirname($file_name))) { 55 files::makeDir(dirname($file_name),true); 56 } 57 58 $dist_url = $latex_server.rawurlencode($tex); 59 60 # Get rendered PNG picture 61 if (netHttp::quickGet($dist_url,$file_name) === false) { 62 throw new Exception(sprintf( 63 __('Unable to get Latex image from the server %s.'), 64 html::escapeHTML($latex_server) 65 )); 66 } 67 68 # Verify that we got a correct PNG file 69 $signature = file_get_contents($file_name,false,null,0,8); 70 71 if ($signature != "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a") { 72 @unlink($file_name); 73 throw new Exception(__('File is not a valid PNG image')); 74 } 75 } 76 catch (Exception $e) { 77 # If something is wrong, Laex code is returned in plain text 78 #$core->error->add($e->getMessage()); 79 return self::getHtml($tex); 80 } 81 82 return self::getHtml($tex,$file_url); 83 } 84 85 public static function getHtml($tex,$file_url=null) 86 { 87 $tex = html::escapeHTML($tex); 88 89 if ($file_url) { 90 return '<img src="'.$file_url.'" alt="'.$tex.'" />'; 91 } 92 else { 93 return '<pre>'.$tex.'</pre>'; 94 } 95 } 96 97 public static function getSettings(&$latex_server,&$root_path,&$root_url) 98 { 99 global $core; 100 101 $root_path = path::real($core->blog->public_path).'/latex-images'; 102 $root_url = $core->blog->host. 103 path::clean($core->blog->settings->public_url).'/latex-images'; 104 105 $latex_server = $core->blog->settings->latex_server; 106 if ($latex_server === null) { 107 $latex_server = 'http://math.spip.org/tex.php?'; 108 $core->blog->settings->setNamespace('latex'); 109 $core->blog->settings->put( 110 'latex_server', 111 $latex_server, 112 'string', 113 'Latex server URL' 114 ); 115 } 38 116 } 39 117 } -
plugins/remotelatex/_define.php
r270 r363 1 1 <?php /* -*- tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */ 2 2 /***************************************************************\ 3 * This is 'Remote Latex', a plugin for Dotclear 2*3 * This is 'Remote Latex', a plugin for Dotclear * 4 4 * * 5 * Copyright (c) 2007 5 * Copyright (c) 2007-2008 * 6 6 * Oleksandr Syenchuk and contributors. * 7 7 * * … … 15 15 \***************************************************************/ 16 16 17 # WARNING : 18 # Remote Latex is distributed in the hope that it will be useful, 19 # but WITHOUT ANY WARRANTY; without even the implied warranty of 20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 # GNU General Public License for more details. 22 17 23 $this->registerModule( 18 24 /* Name */ "Remote Latex", 19 /* Description*/ "Latex render for Dotclear",25 /* Description*/ "Latex rendering for Dotclear", 20 26 /* Author */ "Oleksandr Syenchuk", 21 /* Version */ ' 0.1',27 /* Version */ '1.0', 22 28 /* Permissions */ 'usage,contentadmin' 23 29 );
Note: See TracChangeset
for help on using the changeset viewer.