Skip to content

Commit efc8042

Browse files
committed
v1.0.0
1 parent 1753e0a commit efc8042

15 files changed

+701
-1
lines changed

.brackets.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"jscodehints.detectedExclusions": [
3+
"/mnt/workdata/php/WP-Plugins/git/ithoughts_advanced_code_editor/submodules/ace-builds/src-min/mode-eiffel.js"
4+
]
5+
}

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "submodules/iThoughts-WordPress-Plugin-Toolbox"]
22
path = submodules/iThoughts-WordPress-Plugin-Toolbox
33
url = git@github.com:iThoughts-Informatique/iThoughts-WordPress-Plugin-Toolbox.git
4+
[submodule "submodules/ace-builds"]
5+
path = submodules/ace-builds
6+
url = git@github.com:ajaxorg/ace-builds.git

class/Admin.class.php

Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
<?php
2+
/**
3+
* @copyright 2015-2016 iThoughts Informatique
4+
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.fr.html GPLv2
5+
*/
6+
7+
namespace ithoughts\ace;
8+
9+
10+
class Admin extends \ithoughts\v1_0\Singleton{
11+
12+
public function __construct() {
13+
add_action( 'admin_init', array(&$this, "register_scripts"));
14+
add_action( 'admin_menu', array(&$this, "menu_page"));
15+
add_action( 'wp_ajax_ithoughts_ace_update_options', array(&$this, 'update_options') );
16+
}
17+
18+
public function register_scripts(){
19+
$backbone = \ithoughts\ace\Backbone::get_instance();
20+
$options = $backbone->get_options();
21+
unset($options["enable_shortcode"]);
22+
23+
wp_register_script(
24+
'ithoughts-simple-ajax',
25+
$backbone->get_base_url() . '/submodules/iThoughts-WordPress-Plugin-Toolbox/js/simple-ajax-form'.$backbone->get_minify().'.js',
26+
array('jquery-form',"ithoughts_aliases"),
27+
"1.0.0"
28+
);
29+
wp_register_script(
30+
'ithoughts-ace-admin',
31+
$backbone->get_base_url() . "/resources/ithoughts_ace_admin{$backbone->get_minify()}.js",
32+
array('ithoughts_aliases', 'ace-editor', 'ace-autocomplete'),
33+
"1.0.0"
34+
);
35+
wp_localize_script(
36+
'ithoughts-ace-admin',
37+
'ithoughts_ace',
38+
$options
39+
);
40+
wp_enqueue_script('ithoughts-ace-admin');
41+
wp_register_script(
42+
'ithoughts-ace-options',
43+
$backbone->get_base_url() . "/resources/ithoughts_ace_options{$backbone->get_minify()}.js",
44+
array('ithoughts_aliases', 'ace-editor', 'ace-autocomplete', 'ithoughts-simple-ajax'),
45+
"1.0.0"
46+
);
47+
wp_enqueue_style('ithoughts-ace');
48+
}
49+
50+
public function menu_page(){
51+
add_options_page(
52+
__("iThoughts Advanced Code Editor", 'ithoughts-advanced-code-editor' ),
53+
__("iThoughts ACE", 'ithoughts-advanced-code-editor' ),
54+
"manage_options",
55+
"ithoughts_ace",
56+
array(&$this, "options")
57+
);
58+
}
59+
60+
public function options(){
61+
$backbone = \ithoughts\ace\Backbone::get_instance();
62+
63+
$ajax = admin_url( 'admin-ajax.php' );
64+
$options = $backbone->get_options();
65+
66+
/* Add required scripts for WordPress Spoilers (AKA PostBox) */
67+
wp_enqueue_script('postbox');
68+
wp_enqueue_script('post');
69+
wp_enqueue_script('ithoughts-ace-options');
70+
71+
$optionsInputs = array(
72+
"enable_shortcode" => \ithoughts\v1_0\Toolbox::generate_input_check(
73+
"enable_shortcode",
74+
array(
75+
"radio" => false,
76+
"selected" => $options["enable_shortcode"],
77+
"options" => array(
78+
"enabled" => array(
79+
"attributes" => array(
80+
"id" => "enable_shortcode"
81+
)
82+
)
83+
)
84+
)
85+
),
86+
"theme" => \ithoughts\v1_0\Toolbox::generate_input_select(
87+
"theme",
88+
array(
89+
"selected" => $options["theme"],
90+
"options" => array(
91+
"ambiance" => array(
92+
"text" => "Ambiance"
93+
),
94+
"chaos" => array(
95+
"text" => "Chaos"
96+
),
97+
"chrome" => array(
98+
"text" => "Chrome"
99+
),
100+
"clouds" => array(
101+
"text" => "Clouds"
102+
),
103+
"clouds_midnight" => array(
104+
"text" => "Clouds Midnight"
105+
),
106+
"cobalt" => array(
107+
"text" => "Cobalt"
108+
),
109+
"crimson_editor" => array(
110+
"text" => "Crimson Editor"
111+
),
112+
"dawn" => array(
113+
"text" => "Dawn"
114+
),
115+
"dreamweaver" => array(
116+
"text" => "Dreamweaver"
117+
),
118+
"eclipse" => array(
119+
"text" => "Eclipse"
120+
),
121+
"github" => array(
122+
"text" => "Github"
123+
),
124+
"idle_fingers" => array(
125+
"text" => "Idle Fingers"
126+
),
127+
"iplastic" => array(
128+
"text" => "Iplastic"
129+
),
130+
"katzenmilch" => array(
131+
"text" => "Katzenmilch"
132+
),
133+
"kr_theme" => array(
134+
"text" => "Kr Theme"
135+
),
136+
"kuroir" => array(
137+
"text" => "Kuroir"
138+
),
139+
"merbivore" => array(
140+
"text" => "Merbivore"
141+
),
142+
"merbivore_soft" => array(
143+
"text" => "Merbivore Soft"
144+
),
145+
"mono_industrial" => array(
146+
"text" => "Mono Industrial"
147+
),
148+
"monokai" => array(
149+
"text" => "Monokai"
150+
),
151+
"pastel_on_dark" => array(
152+
"text" => "Pastel On Dark"
153+
),
154+
"solarized_dark" => array(
155+
"text" => "Solarized Dark"
156+
),
157+
"solarized_light" => array(
158+
"text" => "Solarized Light"
159+
),
160+
"sqlserver" => array(
161+
"text" => "SqlServer"
162+
),
163+
"terminal" => array(
164+
"text" => "Terminal"
165+
),
166+
"textmate" => array(
167+
"text" => "Textmate"
168+
),
169+
"tomorrow" => array(
170+
"text" => "Tomorrow"
171+
),
172+
"tomorrow_night_blue" => array(
173+
"text" => "Tomorrow Night Blue"
174+
),
175+
"tomorrow_night_bright" => array(
176+
"text" => "Tomorrow Night Bright"
177+
),
178+
"tomorrow_night_eighties" => array(
179+
"text" => "Tomorrow Night Eighties"
180+
),
181+
"tomorrow_night" => array(
182+
"text" => "Tomorrow Night"
183+
),
184+
"twilight" => array(
185+
"text" => "Twilight"
186+
),
187+
"vibrant_ink" => array(
188+
"text" => "Vibrant Ink"
189+
),
190+
"xcode" => array(
191+
"text" => "XCode"
192+
),
193+
)
194+
)
195+
),
196+
"autocompletion" => \ithoughts\v1_0\Toolbox::generate_input_check(
197+
"autocompletion[]",
198+
array(
199+
"radio" => false,
200+
"selected" => $options["autocompletion"],
201+
"options" => array(
202+
"autocompletion_ondemand" => array(
203+
),
204+
"autocompletion_live" => array(
205+
),
206+
)
207+
)
208+
),
209+
);
210+
require($backbone->get_base_path() . "/templates/options.php");
211+
}
212+
213+
public function update_options(){
214+
$backbone = \ithoughts\ace\Backbone::get_instance();
215+
$ace_options = $backbone->get_options();
216+
217+
$postValues = $_POST;
218+
$postValues['enable_shortcode'] = \ithoughts\v1_0\Toolbox::checkbox_to_bool($postValues,'enable_shortcode', "enabled");
219+
$postValues["autocompletion"] = \ithoughts\v1_0\Toolbox::checkbox_to_bool($postValues,'autocompletion', array("autocompletion_ondemand", "autocompletion_live"));
220+
221+
$outtxt = "";
222+
$valid = true;
223+
$reload = false;
224+
225+
if($backbone->set_options($postValues))
226+
$outtxt .= ('<p>' . __('Options updated', 'ithoughts-advanced-code-editor' ) . '</p>') ;
227+
else
228+
$outtxt .= ('<p>' . __('Could not update options', 'ithoughts-advanced-code-editor' ) . '</p>') ;
229+
230+
die( json_encode(array(
231+
"reload" => $reload,
232+
"text" =>$outtxt,
233+
"valid" => $valid
234+
)));
235+
}
236+
}

class/Backbone.class.php

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
<?php
2+
/**
3+
* @copyright 2015-2016 iThoughts Informatique
4+
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.fr.html GPLv2
5+
*/
6+
7+
namespace ithoughts\ace;
8+
9+
10+
class Backbone extends \ithoughts\v1_0\Backbone{
11+
12+
function __construct($plugin_base) {
13+
if(defined("WP_DEBUG") && WP_DEBUG)
14+
$this->minify = "";
15+
$this->optionsName = "ithoughts_ace";
16+
$this->base_path = $plugin_base;
17+
$this->base_class_path = $plugin_base . '/class';
18+
$this->base_lang_path = $plugin_base . '/lang';
19+
$this->base_url = plugins_url( '', dirname(__FILE__) );
20+
21+
$this->defaults = array(
22+
"enable_shortcode" => false,
23+
"theme" => "monokai",
24+
"autocompletion" => array(
25+
"autocompletion_ondemand" => true,
26+
"autocompletion_live" => true
27+
)
28+
);
29+
30+
$this->options = $this->initOptions();
31+
32+
if($this->get_option("enable_shortcode")){
33+
add_shortcode("ace_editor", array(&$this, "ace_editor_shortcode"));
34+
}
35+
36+
add_action( 'plugins_loaded', array( &$this, 'localisation') );
37+
add_action( 'init', array( &$this, 'register_scripts_and_styles' ) );
38+
39+
parent::__construct();
40+
}
41+
42+
public function ace_editor_shortcode($atts, $content = ""){
43+
wp_enqueue_script("ithougts-ace-client");
44+
wp_enqueue_style('ithoughts-ace');
45+
46+
47+
if(isset($atts["lang"]) && $atts["lang"]){
48+
$atts["data-lang"] = $atts["lang"];
49+
unset($atts["lang"]);
50+
}
51+
if(isset($atts["class"]) && $atts["class"])
52+
$atts["class"] .= "ace-editor";
53+
else
54+
$atts["class"] = "ace-editor";
55+
56+
if(!(isset($atts["id"]) && $atts["id"]))
57+
$atts["id"] = "ace_editor-".substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 15);
58+
59+
$attrsStr = \ithoughts\v1_0\Toolbox::concat_attrs($atts);
60+
return "<textarea $attrsStr>$content</textarea>";
61+
}
62+
63+
public function register_scripts_and_styles(){
64+
wp_register_script(
65+
"ace-editor",
66+
$this->get_base_url() . "/submodules/ace-builds/src-min-noconflict/ace.js",
67+
array(),
68+
"1.0.0"
69+
);
70+
wp_register_script(
71+
"ace-autocomplete",
72+
$this->get_base_url() . "/submodules/ace-builds/src-min-noconflict/ext-language_tools.js",
73+
array("ace-editor"),
74+
"1.0.0"
75+
);
76+
wp_register_style(
77+
'ithoughts-ace',
78+
$this->get_base_url() . "/resources/ithoughts_ace{$this->get_minify()}.css",
79+
array(),
80+
"1.0.0"
81+
);
82+
if($this->get_option("enable_shortcode")){
83+
wp_register_script(
84+
"ithougts-ace-client",
85+
$this->get_base_url() . "/resources/ithoughts_ace_client{$this->get_minify()}.js",
86+
array("ithoughts_aliases", "ace-autocomplete"),
87+
"1.0.0"
88+
);
89+
$opts = $this->get_options();
90+
unset($opts["enable_shortcode"]);
91+
wp_localize_script(
92+
"ithougts-ace-client",
93+
"ithoughts_ace",
94+
$opts
95+
);
96+
}
97+
}
98+
99+
private function initOptions(){
100+
$opts = array_merge($this->get_options(true), get_option( $this->optionsName, $this->get_options(true) ));
101+
return $opts;
102+
}
103+
104+
public function get_options($onlyDefaults = false){
105+
if($onlyDefaults)
106+
return $this->defaults;
107+
108+
return $this->options;
109+
}
110+
111+
public function get_option($name, $onlyDefaults = false){
112+
$arr = $this->options;
113+
if($onlyDefaults)
114+
return $this->defaults;
115+
116+
if(isset($arr[$name]))
117+
return $arr[$name];
118+
else
119+
return NULL;
120+
}
121+
122+
public function localisation(){
123+
load_plugin_textdomain( 'ithoughts-advanced-code-editor', false, plugin_basename( dirname( __FILE__ ) )."/../lang" );
124+
}
125+
}

ithoughts-advanced-code-editor.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
/*
3+
Plugin Name: iThoughts Advanced Code Editor
4+
Plugin URI:
5+
Description:
6+
Version: 1.0.0
7+
Author: Gerkin
8+
License: GPLv2 or later
9+
Text Domain: ithoughts-advanced-code-editor
10+
Domain Path: /lang
11+
*/
12+
13+
require_once( dirname(__FILE__) . '/submodules/iThoughts-WordPress-Plugin-Toolbox/class/includer.php' );
14+
require_once( dirname(__FILE__) . '/class/Backbone.class.php' );
15+
ithoughts\ace\Backbone::get_instance( dirname(__FILE__) );
16+
if(is_admin()){
17+
require_once( dirname(__FILE__) . '/class/Admin.class.php' );
18+
ithoughts\ace\Admin::get_instance();
19+
}

0 commit comments

Comments
 (0)