-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsimterm-core.php
More file actions
88 lines (77 loc) · 3.34 KB
/
simterm-core.php
File metadata and controls
88 lines (77 loc) · 3.34 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
require_once('simterm-settings.php');
require_once('simterm-line.php');
class SimTerm
{
protected $settings;
function __construct()
{
/* Inicialización básica de mi plugin
(la que no tiene que ver con WordPress) */
$this->settings = SimTermSettings::getInstance();
}
function settings()
{
return $this->settings;
}
function simterm_shortcode($atts, $content="")
{
$_lines = preg_split("/\r\n|\n|\r/", trim($content));
if (count($_lines)==0)
return;
add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'));
wp_enqueue_script('simterm-showyourterms', plugins_url('js/show-your-terms.min.js',__FILE__), array(), '20160705', true);
wp_enqueue_script('simterm-launcher', plugins_url('js/simterm.js',__FILE__), array('simterm-showyourterms'), '20160705', true);
wp_enqueue_style('simterm-showyourtermscss', plugins_url('css/show-your-terms.min.css', __FILE__), array(), '20160705', 'all');
wp_enqueue_style('simterm-extracss', plugins_url('css/simterm.css', __FILE__), array(), '20160705', 'all');
$data=array('lines'=> array());
$commandPrep = get_option('simterm-command-prepend');
$typePrep = get_option('simterm-type-prepend');
$defaultDelay = get_option('simterm-default-delay');
$lastLineDelay = get_option('simterm-last-delay-time');
$defaultTheme = get_option('simterm-default-theme');
$plainOutputDelay = get_option('simterm-output-delay-time');
$defaultTypingSpeed = get_option('simterm-typing-speed');
$filters = array();
if (get_option('simterm-transform-chars'))
$filters[] = array($this, 'fixDashes');
$data['theme'] = ( (isset($atts['theme'])) && ($this->settings()->validTheme($atts['theme'])) )?$atts['theme']:$defaultTheme;
$data['title'] = (isset($atts['title']))?$atts['title']:get_option('simterm-window-title');
$data['statusbar'] = (isset($atts['statusbar']))?bool_from_str($atts['statusbar']):get_option('simterm-window-statusbar');
$data['animated'] = (isset($atts['animated']))?bool_from_str($atts['animated']):get_option('simterm-default-animated');
$lines = array();
foreach ($_lines as $l)
{
/* Replace strip_tags for preg_replace. strip_tags removes orphan < symbols and they're often
used in terminals. */
/* This expression must leave orphan <, > but supports sort <input >output and things like that. */
$l = trim(preg_replace( '/<[^<>\s]+(\s+[^<>\s]+)*?>/', '', $l));
if (empty($l))
continue;
$lines[] = $l;
}
$lineCount = count($lines);
for ($i = 0; $i<$lineCount; ++$i)
{
$linedata = array();
$thisline = new SimTermLine($lines[$i], $commandPrep, $typePrep, ($i<$lineCount-1)?$defaultDelay:$lastLineDelay, $defaultTypingSpeed);
$data['lines'][] = $thisline->getData($filters);
}
/* One more loop to fix delays */
for ($i = 0; $i<$lineCount-1; ++$i)
{
if ( ($data['lines'][$i]['type'] == 'line') && ($data['lines'][$i+1]['type'] == 'line') && (!$data['lines'][$i]['customDelay']) )
$data['lines'][$i]['delay'] = $plainOutputDelay;
}
return SimTermView::render('live/syt', array('data' => $data));
}
function fixDashes($content)
{
$content = str_replace( '–' , '--' , $content );
$content = str_replace( '—' , '---' , $content );
$content = str_replace( '<' , '<' , $content );
$content = str_replace( '>' , '>' , $content );
$content = str_replace (' ', ' ', $content);
return $content;
}
};