forked from florincatalin/AddScriptPluginTypesetter
- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathEdit.php
More file actions
Latest commit
142 lines (115 loc) · 4.35 KB
/
Copy pathEdit.php
File metadata and controls
142 lines (115 loc) · 4.35 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
/**
*
* AddScript plugin for Typesetter CMS
* Authors: Florin-Cătălin Tofan, Jürgen Krausz
* Copyright (c) 2019 Florin-Cătălin Tofan
* License: MIT
*
*/
namespaceAddon\AddScript;
defined('is_running') ordie('Not an entry point...');
class Edit extends \Addon\AddScript\Common
{
staticfunctionNewSections($links){
global$addonRelativeCode;
foreach( $linksas$key => $link ){
$match = is_array($link[0]) ? implode('-', $link[0]) : $link[0];
if( $match == self::$sectionType ){
$links[$key][1] = $addonRelativeCode . '/icons/ui-icon.png';
break;
}
}
return$links;
}
staticfunctionToggleClass($section_data, $class, $toggle=true) {
if( empty($section_data['attributes']['class']) ){
if( $toggle ){
$section_data['attributes'] = array( 'class' => $class );
return$section_data;
}
}
$classes = array();
if( !empty($section_data['attributes']['class']) ){
$classes = explode('', $section_data['attributes']['class']);
}
$classes = array_map('trim', $classes);
if( $toggle && !in_array($class, $classes) ){
$classes[] = $class;
}
if( !$toggle && in_array($class, $classes) ){
$key = array_search($class, $classes);
unset($classes[$key]);
}
$section_data['attributes']['class'] = implode('', $classes);
return$section_data;
}
staticfunctionGetDefaultContent($default_content, $type) {
if( $type != self::$sectionType ){
return$default_content;
}
$section = array();
$section['content'] = '<!-- AddScript Section -->';
$section['script_type'] = 'js'; // 'js' | 'jQuery' | 'url' | 'raw'
$section['script_attrs'] = array(); // [['async'] [,'defer']]
$section['linked_to'] = array(); // [[global script id(s)]]
$section['script'] = '';
$section['gp_label'] = 'AddScript';
$section['gp_color'] = '#777';
return$section;
}
staticfunctionSaveSection($return, $section, $type) {
global$page;
if( $type != self::$sectionType ){
return$return;
}
$section_data = $page->file_sections[$section];
$section_data['script_type'] = trim($_POST['script_type']);
$section_data['script'] = trim($_POST['script']);
if( !empty($_POST['script_attrs']) ){
$section_data['script_attrs'] = $_POST['script_attrs'];
}else{
unset($section_data['script_attrs']);
}
if( !empty($_POST['linked_to']) ){
$section_data['linked_to'] = $_POST['linked_to'];
}else{
unset($section_data['linked_to']);
}
$section_data = self::ToggleClass($section_data, 'addscript-section-empty', false);
$section_data = self::ToggleClass($section_data, 'addscript-section-raw-output', false);
if( empty($section_data['script']) ){
$section_data['content'] = '<!-- EMPTY AddScript Section -->';
$section_data = self::ToggleClass($section_data, 'addscript-section-empty', true);
}elseif( $section_data['script_type'] == 'raw' ){
$section_data = self::ToggleClass($section_data, 'addscript-section-raw-output', true);
}else{
$section_data['content'] = '<!-- AddScript Section -->';
}
$page->file_sections[$section] = $section_data;
returntrue;
}
staticfunctionInlineEdit_Scripts($scripts, $type) {
global$addonRelativeCode, $addonFolderName;;
if( $type != self::$sectionType ){
return$scripts;
}
self::GetTranslations();
echo"\n" . 'AddScript_i18n = ' . json_encode(self::$i18n) . ';' . "\n";
self::GetGlobalScripts();
echo"\n" . 'AddScript_globalScripts = ' . json_encode(self::$global_scripts) . ';' . "\n";
$addonBasePath = (strpos($addonRelativeCode, 'addons/') > 0)
? '/addons/' . $addonFolderName
: '/data/_addoncode/' . $addonFolderName;
echo"\n" . 'AddScript_base = "' . $addonBasePath . '";' . "\n";
$scripts[] = $addonRelativeCode . '/thirdparty/codemirror/lib/codemirror.min.js';
$scripts[] = $addonRelativeCode . '/thirdparty/codemirror/mode/xml/xml.min.js';
$scripts[] = $addonRelativeCode . '/thirdparty/codemirror/mode/javascript/javascript.min.js';
$scripts[] = $addonRelativeCode . '/thirdparty/codemirror/mode/css/css.min.js';
$scripts[] = $addonRelativeCode . '/thirdparty/codemirror/mode/htmlmixed/htmlmixed.min.js';
$scripts[] = $addonRelativeCode . '/thirdparty/codemirror/addon/display/placeholder.min.js';
$scripts[] = $addonRelativeCode . '/thirdparty/codemirror/addon/show-invisibles/show-invisibles.js';
$scripts[] = $addonRelativeCode . '/js/edit.js';
return$scripts;
}
}