-
Notifications
You must be signed in to change notification settings - Fork 131
/
automattic-latex-wpcom.php
67 lines (54 loc) · 1.54 KB
/
automattic-latex-wpcom.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/**
*
* This plugin is forked from the original WP Latex (c) Sidney Markowitz, Automattic, Inc.
* It modifies the plugin to work with Pressbooks, strips unwanted features, adds others — activated at the network level
*
* @see https://github.com/wp-plugins/wp-latex
*/
class Automattic_Latex_WPCOM {
var $latex;
var $bg_hex;
var $fg_hex;
var $size;
var $zoom = 1;
var $url;
var $error;
function __construct( $latex, $bg_hex = 'ffffff', $fg_hex = '000000', $size = 0 ) {
$this->latex = (string) $latex;
$this->bg_hex = $this->sanitize_hex( $bg_hex );
$this->fg_hex = $this->sanitize_hex( $fg_hex );
$this->size = (int) $size;
}
function set_zoom( $zoom ) {
$this->zoom = $zoom;
}
function sanitize_hex( $color ) {
if ( 'transparent' == $color )
return 'T';
// Fix for 3 letter hex codes
if ( 3 == strlen( $color ) )
$color = $color[0] . $color[0] . $color[1] . $color[1]. $color[2] . $color[2];
$color = substr( preg_replace( '/[^0-9a-f]/i', '', (string) $color ), 0, 6 );
if ( 6 > $l = strlen( $color ) )
$color .= str_repeat('0', 6 - $l );
return $color;
}
function wrapper( $wrapper = false ) {}
function url() {
if ( ! empty( $_GET['pb-latex-zoom'] ) ) {
$this->zoom = (int) $_GET['pb-latex-zoom'];
}
$this->url = add_query_arg(
urlencode_deep( array(
'latex' => $this->latex,
'bg' => $this->bg_hex,
'fg' => $this->fg_hex,
's' => $this->size,
'zoom' => $this->zoom,
) ),
( is_ssl() ? 'https' : 'http' ) . '://s0.wp.com/latex.php'
);
return $this->url;
}
}