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+ }
0 commit comments