Plugin Directory

Changeset 369123


Ignore:
Timestamp:
04/05/2011 03:15:05 PM (15 years ago)
Author:
knowledgeblog
Message:

Updating mathjax-latex source for 1.1 & CDN compatibility

Location:
mathjax-latex/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • mathjax-latex/trunk/mathjax-latex.php

    r343164 r369123  
    33   Plugin Name: Mathjax Latex
    44   Description: Transform latex equations in javascript using mathjax
    5    Version: 0.2
    6    Author: Phillip Lord
     5   Version: 1.0
     6   Author: Phillip Lord, Simon Cockell
    77   Author URI: http://knowledgeblog.org
    88   
    99   Copyright 2010. Phillip Lord (phillip.lord@newcastle.ac.uk)
     10   Simon Cockell (s.j.cockell@newcastle.ac.uk)
    1011   Newcastle University.
    1112   
     
    1920  function init(){
    2021    register_activation_hook(__FILE__, array(__CLASS__, 'mathjax_install'));
    21    
     22    register_deactivation_hook(__FILE__, array(__CLASS__, 'mathjax_uninstall'));
    2223    if (get_option('force_load')) {
    23    
    2424        self::$add_script = true;
    25    
    26     }
    27    
     25    }
    2826    else {
    29    
    3027        add_shortcode('mathjax',
    3128                  array(__CLASS__, 'mathjax_shortcode' ));
    32    
    33     }
    34 
     29    }
    3530    add_shortcode('nomathjax',
    3631                  array(__CLASS__, 'nomathjax_shortcode' ));
    37    
    3832    add_shortcode('latex',
    3933                  array(__CLASS__, 'latex_shortcode' ));
    40 
    4134    add_action('wp_footer',
    4235               array(__CLASS__, 'add_script'));
    43    
    4436    add_action('wp_footer',
    4537               array(__CLASS__, 'unconditional'));
    46 
    4738    if (get_option('wp_latex_enabled')) {
    4839        add_filter( 'the_content', array(__CLASS__, 'inline_to_shortcode' ) );
    4940    }
    50 
    5141    add_action('admin_menu', array(__CLASS__, 'mathjax_menu'));
    52 
    5342    add_filter('plugin_action_links', array(__CLASS__, 'mathjax_settings_link'), 9, 2 );
     43    add_action('admin_print_scripts-settings_page_mathjax-latex', array(__CLASS__, 'mathjax_admin_js'));
     44    add_action('admin_notices', array(__CLASS__, 'mathjax_warning'));
    5445  }
    5546
     
    6657        add_option('wp_latex_enabled', TRUE);
    6758    }
     59    add_option('mathjax_config', 'default');
     60    add_option('use_cdn', false);
     61  }
     62
     63  function mathjax_uninstall() {
     64    delete_option('force_load');
     65    delete_option('latex_syntax');
     66    delete_option('mathjax_location');
     67    delete_option('wp_latex_enabled');
     68    delete_option('mathjax_config');
     69    delete_option('use_cdn');
    6870  }
    6971 
     
    114116   
    115117    //initialise option for existing MathJax-LaTeX users
    116     if (!get_option('mathjax_location')) {
    117       add_option('mathjax_location', plugins_url("MathJax/MathJax.js",__FILE__));
    118     }
    119     $mathjax_location = get_option('mathjax_location');
    120 
     118    if (get_option('use_cdn')) {
     119        $mathjax_location = "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
     120    }
     121    else {
     122        if (!get_option('mathjax_location')) {
     123            add_option('mathjax_location', plugins_url("MathJax/MathJax.js",__FILE__));
     124        }
     125        if (!get_option('mathjax_config')) {
     126            add_option('mathjax_config', 'default');
     127        }
     128        $config_file = get_option('mathjax_location');
     129        $config_file = str_replace('MathJax.js', 'config/'.get_option('mathjax_config').'.js', $config_file);
     130        if (fopen($config_file, 'r')) {
     131            $mathjax_location = get_option('mathjax_location')."?config=".get_option('mathjax_config');
     132           
     133        }
     134        else {
     135            $mathjax_location = get_option('mathjax_location');
     136        }
     137
     138    }
    121139    wp_register_script( 'mathjax',
    122140                        $mathjax_location,
     
    203221            update_option('latex_syntax', $_POST['latex_syntax']);
    204222        }
    205         if ($_POST['default_disabled']) {
    206             update_option('default_disabled', true);
    207             if ($_POST['mathjax_location'] != get_option('mathjax_location')) {
    208                 update_option('mathjax_location', $_POST['mathjax_location']);
    209             }
     223        if ($_POST['use_cdn']) {
     224            update_option('use_cdn', true);
    210225        }
    211226        else {
    212             update_option('default_disabled', false);
    213             update_option('mathjax_location', plugins_url("MathJax/MathJax.js",__FILE__));
    214          }
     227            update_option('use_cdn', false);
     228            if ($_POST['default_disabled']) {
     229                update_option('default_disabled', true);
     230                if ($_POST['mathjax_location'] != get_option('mathjax_location')) {
     231                    update_option('mathjax_location', $_POST['mathjax_location']);
     232                }
     233            }
     234            else {
     235                update_option('default_disabled', false);
     236                update_option('mathjax_location', plugins_url("MathJax/MathJax.js",__FILE__));
     237            }
     238            update_option('mathjax_config', $_POST['mathjax_config']);
     239        }
    215240            //$url = plugins_url($_POST['mathjax_location']."/MathJax.js",__FILE__);
    216241            //$handle = @fopen($url,'r');
     
    270295      </tr>
    271296      <tr>
     297        <th>Use MathJax CDN Service?<br/><font size="-2">Allows use of the MathJax hosted content distribution network Javascript. By using this, you are agreeing to these <a href='http://www.mathjax.org/download/mathjax-cdn-terms-of-service/'>Terms of Service</a>.<br/>Ignore all following options.</font></th>
     298        <td><input type="checkbox" name="use_cdn" id="use_cdn" value="1" onchange="change_state()" <?php
     299            if (get_option('use_cdn')) {
     300                echo 'CHECKED';
     301            }
     302      ?>/>
     303      </tr>
     304      <tr>
    272305        <th>Override default MathJax location?</th>
    273306        <td><input type="checkbox" name="default_disabled" value="1"<?php
     
    275308                echo 'CHECKED';
    276309            }
     310            if (get_option('use_cdn')) {
     311                echo ' DISABLED';
     312            }
    277313      ?>/>
    278314      </td>
     
    280316      <tr>
    281317        <th scope="row">MathJax Javascript location<br/><font size="-2">Changes will be ignored unless above is checked.</font></th>
    282         <td><input type='textbox' name='mathjax_location' class='regular-text code' value='<?php echo get_option('mathjax_location'); ?>'/></td>
    283       </tr>
     318        <td><input type='textbox' name='mathjax_location' class='regular-text code' value='<?php echo get_option('mathjax_location'); ?>'
     319       <?php
     320            if (get_option('use_cdn')) {
     321                echo ' DISABLED';
     322            }
     323        ?>
     324        /></td>
     325      </tr>
     326      <tr>
     327        <th>Config<br/><font size='-2'>Select the config you want MathJax to use. An explaination is available in the <a href='http://www.mathjax.org/docs/1.1/options/index.html'>MathJax docs</a>.</font></th>
     328        <td>
     329        <select name='mathjax_config' <?php if (get_option('use_cdn')) echo 'DISABLED';?>>
     330        <option value='default'
     331        <?php if (get_option('mathjax_config') == 'default') echo 'SELECTED'?>
     332>default</option>
     333        <option value='Accessible'
     334        <?php if (get_option('mathjax_config') == 'Accessible') echo 'SELECTED'?>
     335>Accessible</option>
     336        <option value='TeX-AMS_HTML'
     337        <?php if (get_option('mathjax_config') == 'TeX-AMS_HTML') echo 'SELECTED'?>
     338>TeX-AMS_HTML</option>
     339        <option value='TeX-AMS-MML_HTMLorMML'
     340        <?php if (get_option('mathjax_config') == 'TeX-AMS-MML_HTMLorMML') echo 'SELECTED'?>
     341>TeX-AMS-MML_HTMLorMML</option>
     342        </select>
     343        </td>
     344      </tr>
     345
    284346      </table>
    285347      <p class="submit">
     
    290352<?php
    291353  }
     354  function mathjax_admin_js() {
     355    wp_enqueue_script('pluginscript', plugins_url('js/admin.js', __FILE__));
     356  }
     357  function mathjax_warning() {
     358    $config_file = get_option('mathjax_location');
     359    $config_file = str_replace('MathJax.js', 'config/'.get_option('mathjax_config').'.js', $config_file);
     360    if (!get_option('use_cdn')) {
     361    if (!fopen($config_file, 'r')) {
     362        echo "<div id='message' class='error'><p>It appears you are running MathJax v1.0.1, you should consider <a href='http://www.mathjax.org/download/'>upgrading to v1.1</a>, or using the <a href='http://www.mathjax.org/docs/1.1/start.html#mathjax-cdn'>MathJax Content Distribution Network</a>. See the <a href='options-general.php?page=mathjax-latex'>plugin options page</a>.</p></div>";
     363    }
     364    }
     365  }
    292366
    293367}
  • mathjax-latex/trunk/readme.txt

    r343020 r369123  
    44Tags: mathematics, math, latex, mathml, mathjax, science, res-comms, scholar, academic
    55Requires at least: 3.0
    6 Tested up to: 3.0.5
    7 Stable tag: 0.2
     6Tested up to: 3.1
     7Stable tag: 1.0
    88
    9 This plugin enables mathjax (http://www.mathjax.org) functionality for WordPress (http://www.wordpress.org).
     9This plugin enables mathjax (http://www.mathjax.org) functionality for WordPress (http://www.wordpress.org). Version 1.0 is compatible with MathJax 1.1 and the CDN.
    1010
    1111== Description ==
     
    1414This plugin adds this functionality to wordpress. The mathjax javascript is
    1515inject on-demand only to those pages which require it. This ensures that
    16 mathjax is not loaded for all pages, which will otherwise slow loading down.
     16mathjax is not loaded for all pages, which will otherwise slow loading down.
     17
     18The MathJax javascript can be delivered from your own server, or you can
     19utilise the [MathJax Content Distribution Network (CDN)]
     20(http://www.mathjax.org/docs/1.1/start.html#mathjax-cdn), which is the preferred
     21mechanism as it offers increased speed and stability over hosting the Javascript
     22and configuring the library yourself. Use of the CDN is governed by these
     23[Terms of Service](http://www.mathjax.org/download/mathjax-cdn-terms-of-service/).
    1724
    1825You may embed latex using a variety of different syntaxes. The shortcode
     
    41481. Activate the plugin through the 'Plugins' menu in WordPress
    42491. You can configure the plugin to load MathJax from a different URL to the default. See the options page.
     501. Alternatively you can use the MathJax Content Distribution Network (<http://www.mathjax.org/docs/1.1/start.html#mathjax-cdn>) to deliver the Javascript, just tick the relevant box on the options page.
    4351
    4452== Changelog ==
    4553
     54= 1.0 =
     551. Compatibility with MathJax 1.1. Load a default configuration from the MathJax distribution.
     561. Use the MathJax Content Distribution Network to deliver the javascript library. Offers improved performance and stability.
     57
     58= 0.2 =
    46591. MathJax.js can be loaded form a configurable URL. Defaults to $PLUGIN/MathJax/MathJax.js
     60
     61== Upgrade Notice ==
     62
     63= 1.0 =
     64The 1.0 release offers compatibility with MathJax 1.1, and enables use of the CDN for javascript delivery. Upgrading is strongly recommended.
    4765
    4866== Copyright ==
Note: See TracChangeset for help on using the changeset viewer.