Dotclear

Changeset 381


Ignore:
Timestamp:
03/30/08 22:31:40 (16 years ago)
Author:
sacha
Message:

Remote Latex - GIF support ; configuration page

Location:
plugins/remotelatex
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • plugins/remotelatex/_admin.php

    r363 r381  
    11<?php /* -*- tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */ 
    22/***************************************************************\ 
    3  *  This is 'Remote Latex', a plugin for Dotclear              * 
     3 *  This is 'Remote LaTeX', a plugin for Dotclear              * 
    44 *                                                             * 
    55 *  Copyright (c) 2007-2008                                    * 
     
    1010 *                                                             * 
    1111 *  You should have received a copy of the GNU General Public  * 
    12  *  License along with 'Remote Latex' (see COPYING.txt);       * 
     12 *  License along with 'Remote LaTeX' (see COPYING.txt);       * 
    1313 *  if not, write to the Free Software Foundation, Inc.,       * 
    1414 *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA    * 
    1515\***************************************************************/ 
     16 
     17$_menu['Plugins']->addItem('LaTeX','plugin.php?p=remotelatex', 
     18     null, 
     19     preg_match('/plugin.php\?p=remotelatex(&.*)?$/',$_SERVER['REQUEST_URI']), 
     20     $core->auth->check('contentadmin',$core->blog->id)); 
    1621 
    1722$core->addBehavior('coreInitWikiPost',array('remoteLatex','coreInitWikiPost')); 
     
    3439               self::getSettings($latex_server,$root_path,$root_url); 
    3540                
    36                $file_name = sprintf('%s/%s/%s.png', 
     41               $file_name = sprintf('%s/%s/%s', 
    3742                    $root_path, 
    3843                    substr($hash,0,2), 
     
    4045               ); 
    4146                
    42                $file_url = sprintf('%s/%s/%s.png', 
     47               $file_url = sprintf('%s/%s/%s', 
    4348                    $root_url, 
    4449                    substr($hash,0,2), 
     
    5863               $dist_url = $latex_server.rawurlencode($tex); 
    5964                
    60                # Get rendered PNG picture 
     65               # Get rendered PNG image 
    6166               if (netHttp::quickGet($dist_url,$file_name) === false) { 
    6267                    throw new Exception(sprintf( 
    63                          __('Unable to get Latex image from the server %s.'), 
     68                         __('Unable to get LaTeX image from the server %s.'), 
    6469                         html::escapeHTML($latex_server) 
    6570                    )); 
    6671               } 
    6772                
    68                # Verify that we got a correct PNG file 
     73               # Verify that we got a valid PNG / GIF file 
     74               $accept_sig = array( 
     75                    "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a",     # PNG 
     76                    "\x47\x49\x46\x38\x39\x61",             # GIF87a 
     77                    "\x47\x49\x46\x38\x37\x61"              # GIF89a 
     78               ); 
    6979               $signature = file_get_contents($file_name,false,null,0,8); 
    7080                
    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')); 
     81               foreach ($accept_sig as $sig) 
     82               { 
     83                    if (strncmp($signature,$sig,strlen($sig)) === 0) { 
     84                         return self::getHtml($tex,$file_url); 
     85                    } 
    7486               } 
     87                
     88               @unlink($file_name); 
     89               throw new Exception(__('File is not a valid PNG / GIF image')); 
    7590          } 
    7691          catch (Exception $e) { 
    77                # If something is wrong, Laex code is returned in plain text 
     92               # If something is wrong, LaTeX code is returned in plain text 
    7893               #$core->error->add($e->getMessage()); 
    7994               return self::getHtml($tex); 
    8095          } 
    81            
    82           return self::getHtml($tex,$file_url); 
    8396     } 
    8497      
     
    95108     } 
    96109      
    97      public static function getSettings(&$latex_server,&$root_path,&$root_url) 
     110     public static function getSettings(&$latex_server='',&$root_path='',&$root_url='') 
    98111     { 
    99112          global $core; 
    100113           
    101114          $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'; 
     115          $root_url = path::clean($core->blog->settings->public_url).'/latex-images'; 
    104116           
    105117          $latex_server = $core->blog->settings->latex_server; 
     
    111123                    $latex_server, 
    112124                    'string', 
    113                     'Latex server URL' 
     125                    'LaTeX server URL' 
    114126               ); 
    115127          } 
  • plugins/remotelatex/_define.php

    r363 r381  
    11<?php /* -*- tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */ 
    22/***************************************************************\ 
    3  *  This is 'Remote Latex', a plugin for Dotclear              * 
     3 *  This is 'Remote LaTeX', a plugin for Dotclear              * 
    44 *                                                             * 
    55 *  Copyright (c) 2007-2008                                    * 
     
    1010 *                                                             * 
    1111 *  You should have received a copy of the GNU General Public  * 
    12  *  License along with 'Remote Latex' (see COPYING.txt);       * 
     12 *  License along with 'Remote LaTeX' (see COPYING.txt);       * 
    1313 *  if not, write to the Free Software Foundation, Inc.,       * 
    1414 *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA    * 
Note: See TracChangeset for help on using the changeset viewer.

Sites map